llvm.org GIT mirror llvm / 6902e84
Initial commit of files that support building LLVM the "Apple" way. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43929 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 11 years ago
2 changed file(s) with 327 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 # LLVM LOCAL file build machinery
1 # LLVM Compiler Makefile for use by buildit.
2 #
3 # This makefile is intended only for use with B&I buildit. For "normal" builds
4 # use the conventional top-level makefile.
5 #
6 # You can specify TARGETS=ppc (or i386) on the buildit command line to limit the
7 # build to just one target. The default is for ppc and i386. The compiler
8 # targetted at this host gets built anyway, but not installed unless it's listed
9 # in TARGETS.
10
11 # Include the set of standard Apple makefile definitions.
12 ifndef CoreOSMakefiles
13 CoreOSMakefiles = $(MAKEFILEPATH)/CoreOS
14 endif
15 include $(CoreOSMakefiles)/Standard/Standard.make
16
17 # Enable Apple extensions to (gnu)make.
18 USE_APPLE_PB_SUPPORT = all
19
20 RC_ARCHS := ppc i386
21 HOSTS = $(RC_ARCHS)
22 targets = echo $(RC_ARCHS)
23 TARGETS := $(shell $(targets))
24
25 SRCROOT = .
26
27 SRC = $(shell cd $(SRCROOT) && pwd | sed s,/private,,)
28 OBJROOT = $(SRC)/obj
29 SYMROOT = $(OBJROOT)/../sym
30 DSTROOT = $(OBJROOT)/../dst
31
32 #######################################################################
33
34 PREFIX = /usr/local
35
36 # Unless assertions are forced on in the GMAKE command line, disable them.
37 ifdef ENABLE_ASSERTIONS
38 LLVM_ASSERTIONS := yes
39 else
40 LLVM_ASSERTIONS := no
41 endif
42
43 ifndef RC_ProjectSourceVersion
44 RC_ProjectSourceVersion = 9999
45 endif
46
47 ifndef RC_ProjectSourceSubversion
48 RC_ProjectSourceSubversion = 01
49 endif
50
51 install: $(OBJROOT) $(SYMROOT) $(DSTROOT)
52 cd $(OBJROOT) && \
53 $(SRC)/build_llvm "$(RC_ARCHS)" "$(TARGETS)" \
54 $(SRC) $(PREFIX) $(DSTROOT) $(SYMROOT) \
55 $(RC_ProjectSourceVersion) $(RC_ProjectSourceSubversion) \
56 $(LLVM_ASSERTIONS)
57
58 # installhdrs does nothing, because the headers aren't useful until
59 # the compiler is installed.
60 installhdrs:
61
62 # We build and install in one shell script.
63 build:
64
65 installsrc:
66 @echo
67 @echo ++++++++++++++++++++++
68 @echo + Installing sources +
69 @echo ++++++++++++++++++++++
70 @echo
71 if [ $(SRCROOT) != . ]; then \
72 $(PAX) -rw . $(SRCROOT); \
73 fi
74 find -d "$(SRCROOT)" \( -type d -a -name .svn -o \
75 -type f -a -name .DS_Store -o \
76 -name \*~ -o -name .\#\* \) \
77 -exec rm -rf {} \;
78
79 #######################################################################
80
81 clean:
82 @echo
83 @echo ++++++++++++
84 @echo + Cleaning +
85 @echo ++++++++++++
86 @echo
87 @if [ -d $(OBJROOT) -a "$(OBJROOT)" != / ]; then \
88 echo '*** DELETING ' $(OBJROOT); \
89 rm -rf $(OBJROOT); \
90 fi
91 @if [ -d $(SYMROOT) -a "$(SYMROOT)" != / ]; then \
92 echo '*** DELETING ' $(SYMROOT); \
93 rm -rf $(SYMROOT); \
94 fi
95 @if [ -d $(DSTROOT) -a "$(DSTROOT)" != / ]; then \
96 echo '*** DELETING ' $(DSTROOT); \
97 rm -rf $(DSTROOT); \
98 fi
99
100 #######################################################################
101
102 $(OBJROOT) $(SYMROOT) $(DSTROOT):
103 mkdir -p $@
104
105 .PHONY: install installsrc clean
0 #!/bin/sh
1 # LLVM LOCAL file B&I
2
3 set -x
4
5 # -arch arguments are different than configure arguments. We need to
6 # translate them.
7
8 TRANSLATE_ARCH="sed -e s/ppc/powerpc/ -e s/i386/i686/"
9
10 # Build LLVM the "Apple way".
11 # Parameters:
12
13 # The first parameter is a space-separated list of the architectures the
14 # compilers will run on. For instance, "ppc i386". If the current machine
15 # isn't in the list, it will (effectively) be added.
16 HOSTS=`echo $1 | $TRANSLATE_ARCH `
17
18 # The second parameter is a space-separated list of the architectures the
19 # compilers will generate code for. If the current machine isn't in the list, a
20 # compiler for it will get built anyway, but won't be installed.
21 TARGETS=`echo $2 | $TRANSLATE_ARCH`
22
23 # The third parameter is the path to the compiler sources. There should be a
24 # shell script named 'configure' in this directory. This script makes a copy...
25 ORIG_SRC_DIR="$3"
26
27 # The fourth parameter is the location where the LLVM will be installed. You can
28 # move it once it's built, so this mostly controls the layout of $DEST_DIR.
29 DEST_ROOT="$4"
30
31 # The fifth parameter is the place where the compiler will be copied once it's
32 # built.
33 DEST_DIR="$5"
34
35 # The sixth parameter is a directory in which to place information (like
36 # unstripped executables and generated source files) helpful in debugging the
37 # resulting compiler.
38 SYM_DIR="$6"
39
40 # The seventh parameter is the version number of the submission, e.g. 1007.
41 LLVM_SUBMIT_VERSION="$7"
42
43 # The eighth parameter is the subversion number of the submission, e.g. 03.
44 LLVM_SUBMIT_SUBVERSION="$8"
45
46 # The nineth parameter is a yes/no that indicates whether assertions should be
47 # enabled in the LLVM libs/tools.
48 LLVM_ASSERTIONS="$9"
49
50 # The current working directory is where the build will happen. It may already
51 # contain a partial result of an interrupted build, in which case this script
52 # will continue where it left off.
53 DIR=`pwd`
54
55 DARWIN_VERS=`uname -r | sed 's/\..*//'`
56 echo DARWIN_VERS = $DARWIN_VERS
57
58 # If the user has CC set in their environment unset it now
59 unset CC
60
61 # The B&I build srcript (~rc/bin/buildit) accepts an '-othercflags' command-line
62 # flag, and captures the argument to that flag in $RC_NONARCH_CFLAGS (and
63 # mysteriously prepends '-pipe' thereto). We will allow this to override the
64 # default $CFLAGS and $CXXFLAGS.
65
66 if [ "x$LLVM_DEBUG" == "x" ]; then
67 CFLAGS="-g -O2 ${RC_NONARCH_CFLAGS/-pipe/}"
68 OPTIMIZE_OPTS="ENABLE_OPTIMIZED=1"
69 else
70 CFLAGS="-g"
71 OPTIMIZE_OPTS=
72 fi
73
74 ################################################################################
75 # Run the build.
76
77 # Create the source tree we'll actually use to build, deleting
78 # tcl since it doesn't actually build properly in a cross environment
79 # and we don't really need it.
80 SRC_DIR=$DIR/src
81 rm -rf $SRC_DIR || exit 1
82 mkdir $SRC_DIR || exit 1
83 ln -s $ORIG_SRC_DIR/* $SRC_DIR/ || exit 1
84
85 # Build the LLVM tree universal.
86 mkdir -p $DIR/obj-llvm || exit 1
87 cd $DIR/obj-llvm || exit 1
88
89 if [ \! -f Makefile.config ]; then
90 $SRC_DIR/llvm/configure --prefix=$DEST_DIR$DEST_ROOT \
91 --enable-targets=x86,powerpc --enable-assertions=$LLVM_ASSERTIONS \
92 || exit 1
93 fi
94
95 if [ "x$LLVM_SUBMIT_SUBVERSION" = "x00" -o "x$LLVM_SUBMIT_SUBVERSION" = "x0" ]; then
96 LLVM_VERSION="$LLVM_SUBMIT_VERSION"
97 else
98 LLVM_VERSION="$LLVM_SUBMIT_VERSION-$LLVM_SUBMIT_SUBVERSION"
99 fi
100
101 # Note: Don't pass -jN here. Building universal already has parallelism and we
102 # don't want to make the builders hit swap by firing off too many gcc's at the
103 # same time.
104 make $OPTIMIZE_OPTS UNIVERSAL=1 UNIVERSAL_ARCH="$LLVM_ARCHS" \
105 CXXFLAGS="-DLLVM_VERSION_INFO='\" Apple Build #$LLVM_VERSION\"'"
106
107 if ! test $? == 0 ; then
108 echo "error: LLVM 'make' failed!"
109 exit 1
110 fi
111
112 # Figure out how many make processes to run.
113 SYSCTL=`sysctl -n hw.activecpu`
114
115 # hw.activecpu only available in 10.2.6 and later
116 if [ -z "$SYSCTL" ]; then
117 SYSCTL=`sysctl -n hw.ncpu`
118 fi
119
120 # sysctl -n hw.* does not work when invoked via B&I chroot /BuildRoot. Builders
121 # can default to 2, since even if they are single processor, nothing else is
122 # running on the machine.
123 if [ -z "$SYSCTL" ]; then
124 SYSCTL=2
125 fi
126
127 ################################################################################
128 # Construct the actual destination root, by copying stuff from $DIR/dst-* to
129 # $DEST_DIR, with occasional 'lipo' commands.
130
131 cd $DEST_DIR || exit 1
132
133 # Clean out DEST_DIR in case -noclean was passed to buildit.
134 rm -rf * || exit 1
135
136 cd $DIR/obj-llvm || exit 1
137
138 # Install the tree into the destination directory.
139 make $LOCAL_MAKEFLAGS $OPTIMIZE_OPTS UNIVERSAL=1 OPTIMIZE_OPTION='-O2' install
140
141 if ! test $? == 0 ; then
142 echo "error: LLVM 'make install' failed!"
143 exit 1
144 fi
145
146 # Install Version.h
147 if [ "x$LLVM_SUBMIT_SUBVERSION" = "x00" -o "x$LLVM_SUBMIT_SUBVERSION" = "x0" ]; then
148 RC_ProjectSourceSubversion=0
149 else
150 case "$LLVM_SUBMIT_SUBVERSION" in
151 01) RC_ProjectSourceSubversion=1 ;;
152 02) RC_ProjectSourceSubversion=2 ;;
153 03) RC_ProjectSourceSubversion=3 ;;
154 04) RC_ProjectSourceSubversion=4 ;;
155 05) RC_ProjectSourceSubversion=5 ;;
156 06) RC_ProjectSourceSubversion=6 ;;
157 07) RC_ProjectSourceSubversion=7 ;;
158 08) RC_ProjectSourceSubversion=8 ;;
159 09) RC_ProjectSourceSubversion=9 ;;
160 *) RC_ProjectSourceSubversion=$LLVM_SUBMIT_SUBVERSION ;;
161 esac
162 fi
163
164 echo "#define LLVM_VERSION ${RC_ProjectSourceVersion}" > $DEST_DIR$DEST_ROOT/include/llvm/Version.h
165 echo "#define LLVM_MINOR_VERSION ${RC_ProjectSourceSubversion}" >> $DEST_DIR$DEST_ROOT/include/llvm/Version.h
166
167 # Strip local symbols from llvm libraries.
168 strip -S $DEST_DIR$DEST_ROOT/lib/*.[oa]
169 strip -Sx $DEST_DIR$DEST_ROOT/lib/*.so
170
171 # Remove .dir files
172 cd $DEST_DIR$DEST_ROOT
173 rm bin/.dir etc/llvm/.dir lib/.dir
174
175 # Remove PPC64 fat slices.
176 cd $DEST_DIR$DEST_ROOT/bin
177
178 if [ $MACOSX_DEPLOYMENT_TARGET = "10.4" ]; then
179 find . -perm 755 -type f -exec lipo -extract ppc -extract i386 {} -output {} \;
180 else
181 find . -perm 755 -type f -exec lipo -extract ppc7400 -extract i386 {} -output {} \;
182 fi
183
184 cd $DEST_DIR$DEST_ROOT
185 lipo -extract ppc -extract i386 lib/LLVMlto.0.0.0.so -output lib/LLVMlto.0.0.0.so
186
187 ################################################################################
188 # Create SYM_DIR with information required for debugging.
189
190 cd $SYM_DIR || exit 1
191
192 # Clean out SYM_DIR in case -noclean was passed to buildit.
193 rm -rf * || exit 1
194
195 # Generate .dSYM files
196 find $DEST_DIR -perm -0111 -type f -print | xargs -n 1 -P ${SYSCTL} dsymutil
197
198 # Save .dSYM files and .a archives
199 cd $DEST_DIR || exit 1
200 find . \( -path \*.dSYM/\* -or -name \*.a \) -print \
201 | cpio -pdml $SYM_DIR || exit 1
202
203 # Save source files.
204 mkdir $SYM_DIR/src || exit 1
205 cd $DIR || exit 1
206 find obj-* -name \*.\[chy\] -o -name \*.cpp -print \
207 | cpio -pdml $SYM_DIR/src || exit 1
208
209 ################################################################################
210 # Remove debugging information from DEST_DIR.
211
212 find $DEST_DIR -name \*.a -print | xargs ranlib || exit 1
213 find $DEST_DIR -name \*.dSYM -print | xargs rm -r || exit 1
214 chgrp -h -R wheel $DEST_DIR
215 chgrp -R wheel $DEST_DIR
216
217 ################################################################################
218 # w00t! Done!
219
220 exit 0