Added build script for build on x86_64-apple-darwin10 of cross llvm-gcc for i686...
[llvm-gcc-4.2.git] / build_gcc
blob9221669b2e246d1af25665094a8559972bfe1258
1 #!/bin/sh
2 # APPLE LOCAL file B&I
4 set -x
6 # -arch arguments are different than configure arguments. We need to
7 # translate them.
9 TRANSLATE_ARCH="sed -e s/ppc/powerpc/ -e s/i386/i686/ -e s/armv6/arm/"
10 OMIT_X86_64="sed -e s/x86_64//"
12 # Build GCC the "Apple way".
13 # Parameters:
15 # The first parameter is a space-separated list of the architectures
16 # the compilers will run on. For instance, "ppc i386". If the
17 # current machine isn't in the list, it will (effectively) be added.
18 HOSTS=`echo $1 | $TRANSLATE_ARCH `
20 # The second parameter is a space-separated list of the architectures the
21 # compilers will generate code for. If the current machine isn't in
22 # the list, a compiler for it will get built anyway, but won't be
23 # installed.
24 TARGETS=`echo $2 | $TRANSLATE_ARCH | $OMIT_X86_64 | sed -e s,\\',,g`
26 # The GNU makefile target ('bootstrap' by default).
27 BOOTSTRAP=${BOOTSTRAP-bootstrap}
28 if [ "$BOOTSTRAP" != bootstrap ]; then
29 bootstrap=--disable-bootstrap
32 # Language front-ends to build. This also affects
33 # whether the C++ driver and driver-driver are installed
34 LANGUAGES=${LANGUAGES-c,objc,c++,obj-c++}
36 # The B&I build script (~rc/bin/buildit) accepts an '-othercflags'
37 # command-line flag, and captures the argument to that flag in
38 # $RC_NONARCH_CFLAGS (and mysteriously prepends '-pipe' thereto).
39 # We will allow this to override the default $CFLAGS and $CXXFLAGS.
41 # LLVM LOCAL begin
42 if [ "x$LLVM_DEBUG" == "x" ]; then
43 CFLAGS="-g -O2 ${RC_NONARCH_CFLAGS/-pipe/}"
44 else
45 CFLAGS="-g"
47 # LLVM LOCAL end
49 # This isn't a parameter; it is the architecture of the current machine.
50 BUILD=`arch | $TRANSLATE_ARCH`
52 # The third parameter is the path to the compiler sources. There should
53 # be a shell script named 'configure' in this directory. This script
54 # makes a copy...
55 ORIG_SRC_DIR="$3"
57 # The fourth parameter is the location where the compiler will be installed,
58 # normally "/usr". You can move it once it's built, so this mostly controls
59 # the layout of $DEST_DIR.
60 DEST_ROOT="$4"
62 # The fifth parameter is the place where the compiler will be copied once
63 # it's built.
64 DEST_DIR="$5"
66 # The sixth parameter is a directory in which to place information (like
67 # unstripped executables and generated source files) helpful in debugging
68 # the resulting compiler.
69 SYM_DIR="$6"
71 # LLVM LOCAL begin
72 # The seventh parameter is a yes/no that indicates whether libLTO.dylib
73 # should be installed from LLVMCORE_PATH.
74 INSTALL_LIBLTO="$7"
76 # The eighth parameter is a yes/no that indicates whether assertions should be
77 # enabled in the LLVM libs/tools.
78 LLVM_ASSERTIONS="$8"
80 # The nineth parameter indicates llvmCore location.
81 LLVMCORE_PATH="$9"
83 # The tenth parameter is the version number of the submission, e.g. 1007.
84 LLVM_SUBMIT_VERSION="${10}"
86 # The eleventh parameter is the subversion number of the submission, e.g. 03.
87 LLVM_SUBMIT_SUBVERSION="${11}"
89 ENABLE_LLVM=true
91 # LLVM LOCAL end
93 # The current working directory is where the build will happen.
94 # It may already contain a partial result of an interrupted build,
95 # in which case this script will continue where it left off.
96 DIR=`pwd`
98 # This isn't a parameter; it's the version of the compiler that we're
99 # about to build. It's included in the names of various files and
100 # directories in the installed image.
101 VERS=`cat $ORIG_SRC_DIR/gcc/BASE-VER`
102 if [ -z "$VERS" ]; then
103 exit 1
106 # This isn't a parameter either, it's the major version of the compiler
107 # to be built. It's VERS but only up to the second '.' (if there is one).
108 MAJ_VERS=`echo $VERS | sed 's/\([0-9]*\.[0-9]*\)[.-].*/\1/'`
110 # This is the libstdc++ version to use.
111 LIBSTDCXX_VERSION=4.2.1
112 # LLVM LOCAL begin
113 # DO NOT USE $DEST_ROOT to check LIBSTDCXX_VERSION here. Directly use /usr here.
114 # $DEST_ROOT is /Developer for llvm-gcc
115 if [ ! -d "/usr/include/c++/$LIBSTDCXX_VERSION" ]; then
116 LIBSTDCXX_VERSION=4.0.0
118 NON_ARM_CONFIGFLAGS="--with-gxx-include-dir=/usr/include/c++/$LIBSTDCXX_VERSION"
119 # LLVM LOCAL end
121 DARWIN_VERS=`uname -r | sed 's/\..*//'`
122 echo DARWIN_VERS = $DARWIN_VERS
124 # APPLE LOCAL begin ARM
125 ARM_LIBSTDCXX_VERSION=4.2.1
126 ARM_CONFIGFLAGS="--with-gxx-include-dir=/usr/include/c++/$ARM_LIBSTDCXX_VERSION"
128 if [ -n "$ARM_SDK" ]; then
129 ARM_SYSROOT=`xcodebuild -version -sdk $ARM_SDK Path`
130 else
131 # Use bootstrap SDK if it is available.
132 # FIXME: This can be removed once all builds set ARM_SDK.
133 if [ -d /Developer/SDKs/Extra ]; then
134 ARM_SYSROOT=/Developer/SDKs/Extra
135 else
136 ARM_SYSROOT=/
139 ARM_CONFIGFLAGS="$ARM_CONFIGFLAGS --with-build-sysroot=\"$ARM_SYSROOT\""
141 # If building an ARM target, check that the required directories exist
142 # and query the libSystem arm slices to determine which multilibs we should
143 # build.
144 if echo $TARGETS | grep arm; then
145 if [ ! -d $ARM_SYSROOT ]; then
146 echo "Error: cannot find ARM SDK to build ARM target"
147 exit 1
149 if [ "x$ARM_MULTILIB_ARCHS" = "x" ] ; then
150 ARM_MULTILIB_ARCHS=`/usr/bin/lipo -info $ARM_SYSROOT/usr/lib/libSystem.dylib | cut -d':' -f 3 | sed -e 's/x86_64//' -e 's/i386//' -e 's/ppc7400//' -e 's/ppc64//' -e 's/^ *//' -e 's/ $//'`
152 if [ "x$ARM_MULTILIB_ARCHS" == "x" ] ; then
153 echo "Error: missing ARM slices in $ARM_SYSROOT"
154 exit 1
155 else
156 export ARM_MULTILIB_ARCHS
159 # APPLE LOCAL end ARM
161 # LLVM LOCAL begin
162 # If the user has CC set in their environment unset it now
163 unset CC
164 # LLVM LOCAL end
166 ########################################
167 # Run the build.
169 # Create the source tree we'll actually use to build, deleting
170 # tcl since it doesn't actually build properly in a cross environment
171 # and we don't really need it.
172 SRC_DIR=$DIR/src
173 rm -rf $SRC_DIR || exit 1
174 mkdir $SRC_DIR || exit 1
175 ln -s $ORIG_SRC_DIR/* $SRC_DIR/ || exit 1
176 rm -rf $SRC_DIR/tcl $SRC_DIR/expect $SRC_DIR/dejagnu || exit 1
177 # Also remove libstdc++ since it is built from a separate project.
178 # LLVM LOCAL: The following line was commented out; uncomment it.
179 rm -rf $SRC_DIR/libstdc++-v3 || exit 1
180 # Clean out old specs files
181 rm -f /usr/lib/gcc/*/4.0.0/specs
183 # These are the configure and build flags that are used.
184 # LLVM LOCAL begin
185 if [ "x$LLVM_DEBUG" == "x" ]; then
186 CHECKING_FLAGS="--disable-checking --enable-werror"
187 else
188 CHECKING_FLAGS="--enable-checking"
191 CONFIGFLAGS="$CHECKING_FLAGS \
192 --prefix=$DEST_ROOT \
193 --mandir=\${prefix}/share/man \
194 --enable-languages=$LANGUAGES \
195 --program-prefix=llvm- \
196 --program-transform-name=/^[cg][^.-]*$/s/$/-$MAJ_VERS/ \
197 --with-slibdir=/usr/lib \
198 --build=$BUILD-apple-darwin$DARWIN_VERS"
200 if [ "$ENABLE_LLVM" == true ]; then
201 CONFIGFLAGS="$CONFIGFLAGS --enable-llvm=$LLVMCORE_PATH"
203 # LLVM LOCAL end
205 # Figure out how many make processes to run.
206 SYSCTL=`sysctl -n hw.activecpu`
208 # hw.activecpu only available in 10.2.6 and later
209 if [ -z "$SYSCTL" ]; then
210 SYSCTL=`sysctl -n hw.ncpu`
213 # sysctl -n hw.* does not work when invoked via B&I chroot /BuildRoot.
214 # Builders can default to 2, since even if they are single processor,
215 # nothing else is running on the machine.
216 if [ -z "$SYSCTL" ]; then
217 SYSCTL=2
220 # The $LOCAL_MAKEFLAGS variable can be used to override $MAKEFLAGS.
221 MAKEFLAGS=${LOCAL_MAKEFLAGS-"-j $SYSCTL"}
223 BUILD_CXX=0
224 for lang in `echo $LANGUAGES | sed 's/,/ /g'`; do
225 if [ $lang = "c++" -o $lang = "obj-c++" ]; then
226 BUILD_CXX=1
227 break
229 done
231 # Unset this, because GCC uses this variable in its makefiles
232 unset LANGUAGES
234 # LLVM LOCAL begin
235 if [ "$ENABLE_LLVM" == true ]; then
236 # Indicate the llvm-gcc is being built "Apple style".
237 MAKEFLAGS="$MAKEFLAGS BUILD_LLVM_APPLE_STYLE=1"
238 # Build llvm-gcc in 'dylib mode'.
239 MAKEFLAGS="$MAKEFLAGS BUILD_LLVM_INTO_A_DYLIB=1"
240 MAKEFLAGS="$MAKEFLAGS LLVM_VERSION_INFO=$LLVM_SUBMIT_VERSION"
242 # LLVM LOCAL end
244 # If the user has set CC or CXX, respect their wishes. If not,
245 # compile with LLVM-GCC/LLVM-G++ if available; if LLVM is not
246 # available, fall back to usual GCC/G++ default.
247 savedPATH=$PATH ; PATH="/Developer/usr/bin:$PATH"
248 XTMPCC=$(which llvm-gcc)
249 if [ x$CC = x -a x$XTMPCC != x ] ; then export CC=$XTMPCC forcedCC=1 ; fi
250 XTMPCC=$(which llvm-g++)
251 if [ x$CXX = x -a x$XTMPCC != x ] ; then export CXX=$XTMPCC forcedCXX=1 ; fi
252 PATH=$savedPATH
253 unset XTMPCC savedPATH
255 # Build the native GCC. Do this even if the user didn't ask for it
256 # because it'll be needed for the bootstrap.
257 mkdir -p $DIR/obj-$BUILD-$BUILD $DIR/dst-$BUILD-$BUILD || exit 1
258 cd $DIR/obj-$BUILD-$BUILD || exit 1
259 if [ \! -f Makefile ]; then
260 $SRC_DIR/configure $bootstrap $CONFIGFLAGS $NON_ARM_CONFIGFLAGS \
261 --host=$BUILD-apple-darwin$DARWIN_VERS \
262 --target=$BUILD-apple-darwin$DARWIN_VERS || exit 1
265 # Unset RC_DEBUG_OPTIONS because it causes the bootstrap to fail.
266 # Also keep unset for cross compilers so that the cross built libraries are
267 # comparable to the native built libraries.
268 unset RC_DEBUG_OPTIONS
269 make $MAKEFLAGS CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
270 make $MAKEFLAGS html CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
271 make $MAKEFLAGS DESTDIR=$DIR/dst-$BUILD-$BUILD install-gcc install-target \
272 CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
274 # Now that we've built a native compiler, un-kludge these so that
275 # subsequent cross-hosted compilers can be found normally.
276 if [ x$forcedCC != x ] ; then unset CC forcedCC ; fi
277 if [ x$forcedCXX != x ] ; then unset CXX forcedCXX ; fi
279 # Add the compiler we just built to the path, giving it appropriate names.
280 # LLVM LOCAL begin Support for non /usr $DEST_ROOT
281 D=$DIR/dst-$BUILD-$BUILD$DEST_ROOT/bin
282 ln -f $D/llvm-gcc $D/gcc || exit 1
283 ln -f $D/gcc $D/$BUILD-apple-darwin$DARWIN_VERS-gcc || exit 1
284 PATH=$DIR/dst-$BUILD-$BUILD$DEST_ROOT/bin:$PATH
285 # LLVM LOCAL end Support for non /usr $DEST_ROOT
287 # The cross-tools' build process expects to find certain programs
288 # under names like 'i386-apple-darwin$DARWIN_VERS-ar'; so make them.
289 # Annoyingly, ranlib changes behaviour depending on what you call it,
290 # so we have to use a shell script for indirection, grrr.
291 rm -rf $DIR/bin || exit 1
292 mkdir $DIR/bin || exit 1
293 for prog in ar nm ranlib strip lipo ld ; do
294 for t in `echo $TARGETS $HOSTS | tr ' ' '\n' | sort -u`; do
295 P=$DIR/bin/${t}-apple-darwin$DARWIN_VERS-${prog}
296 # Use the specified ARM_SDK for arm, but otherwise force the SDK to / for
297 # now, since SDKROOT may be set to an SDK that does not include support
298 # for all the targets being built (i.e., ppc).
299 if [ "$t" = "arm" -a -n "$ARM_SDK" ]; then
300 sdkoption="-sdk $ARM_SDK"
301 else
302 sdkoption="-sdk /"
304 progpath=`xcrun $sdkoption -find $prog`
305 echo '#!/bin/sh' > $P || exit 1
306 echo 'exec '${progpath}' "$@"' >> $P || exit 1
307 chmod a+x $P || exit 1
308 done
309 done
310 # The "as" script adds a default "-arch" option. Iterate over the lists of
311 # untranslated HOSTS and TARGETS in $1 and $2 so those names can be used as
312 # the arguments for "-arch" in the scripts.
313 for t in `echo $1 $2 | tr ' ' '\n' | sort -u`; do
314 gt=`echo $t | $TRANSLATE_ARCH`
315 P=$DIR/bin/${gt}-apple-darwin$DARWIN_VERS-as
316 if [ "$gt" = "arm" -a -n "$ARM_SDK" ]; then
317 sdkoption="-sdk $ARM_SDK"
318 else
319 sdkoption="-sdk /"
321 progpath=`xcrun $sdkoption -find as`
322 echo '#!/bin/sh' > $P || exit 1
323 echo 'for a; do case $a in -arch) exec '${progpath}' "$@";; esac; done' >> $P || exit 1
324 echo 'exec '${progpath}' -arch '${t}' "$@"' >> $P || exit 1
325 chmod a+x $P || exit 1
326 done
327 PATH=$DIR/bin:$PATH
329 # Determine which cross-compilers we should build. If our build architecture is
330 # one of our hosts, add all of the targets to the list.
331 if echo $HOSTS | grep $BUILD
332 then
333 CROSS_TARGETS=`echo $TARGETS $HOSTS | tr ' ' '\n' | sort -u`
334 else
335 CROSS_TARGETS="$HOSTS"
338 # Build the cross-compilers, using the compiler we just built.
339 for t in $CROSS_TARGETS ; do
340 if [ $t != $BUILD ] ; then
341 mkdir -p $DIR/obj-$BUILD-$t $DIR/dst-$BUILD-$t || exit 1
342 cd $DIR/obj-$BUILD-$t || exit 1
343 if [ \! -f Makefile ]; then
344 # APPLE LOCAL begin ARM ARM_CONFIGFLAGS
345 T_CONFIGFLAGS="$CONFIGFLAGS --enable-werror-always \
346 --program-prefix=$t-apple-darwin$DARWIN_VERS- \
347 --host=$BUILD-apple-darwin$DARWIN_VERS \
348 --target=$t-apple-darwin$DARWIN_VERS"
349 if [ $t = 'arm' ] ; then
350 # Explicitly set AS_FOR_TARGET and LD_FOR_TARGET to avoid picking up
351 # older versions from the gcc installed in /usr. Radar 7230843.
352 AS_FOR_TARGET=$DIR/bin/${t}-apple-darwin$DARWIN_VERS-as \
353 LD_FOR_TARGET=$DIR/bin/${t}-apple-darwin$DARWIN_VERS-ld \
354 $SRC_DIR/configure $T_CONFIGFLAGS $ARM_CONFIGFLAGS || exit 1
355 else
356 $SRC_DIR/configure $T_CONFIGFLAGS $NON_ARM_CONFIGFLAGS || exit 1
358 # APPLE LOCAL end ARM ARM_CONFIGFLAGS
360 make $MAKEFLAGS all CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
361 make $MAKEFLAGS DESTDIR=$DIR/dst-$BUILD-$t install-gcc install-target \
362 CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
364 # Add the compiler we just built to the path.
365 # LLVM LOCAL Support for non /usr $DEST_ROOT
366 PATH=$DIR/dst-$BUILD-$t/$DEST_ROOT/bin:$PATH
368 done
370 # Rearrange various libraries, for no really good reason.
371 for t in $CROSS_TARGETS ; do
372 DT=$DIR/dst-$BUILD-$t
373 # LLVM LOCAL Support for non /usr $DEST_ROOT
374 D=`echo $DT/$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS`
375 mv $D/static/libgcc.a $D/libgcc_static.a || exit 1
376 mv $D/kext/libgcc.a $D/libcc_kext.a || exit 1
377 rm -r $D/static $D/kext || exit 1
378 # glue together kext64 stuff
379 if [ -e $D/kext64/libgcc.a ]; then
380 libtool -static $D/{kext64/libgcc.a,libcc_kext.a} -o $D/libcc_kext1.a 2>&1 | grep -v 'has no symbols'
381 mv $D/libcc_kext1.a $D/libcc_kext.a
382 rm -rf $D/kext64
384 done
386 # Build the cross-hosted compilers.
387 for h in $HOSTS ; do
388 if [ $h != $BUILD ] ; then
389 for t in $TARGETS ; do
390 mkdir -p $DIR/obj-$h-$t $DIR/dst-$h-$t || exit 1
391 cd $DIR/obj-$h-$t || exit 1
392 if [ $h = $t ] ; then
394 else
395 pp=$t-apple-darwin$DARWIN_VERS-
398 if [ \! -f Makefile ]; then
399 # APPLE LOCAL begin ARM ARM_CONFIGFLAGS
400 T_CONFIGFLAGS="$CONFIGFLAGS --program-prefix=$pp \
401 --host=$h-apple-darwin$DARWIN_VERS \
402 --target=$t-apple-darwin$DARWIN_VERS"
403 if [ $t = 'arm' ] && [ $h != 'arm' ] ; then
404 T_CONFIGFLAGS="$T_CONFIGFLAGS $ARM_CONFIGFLAGS"
405 else
406 T_CONFIGFLAGS="$T_CONFIGFLAGS $NON_ARM_CONFIGFLAGS"
408 $SRC_DIR/configure $T_CONFIGFLAGS || exit 1
409 # APPLE LOCAL end ARM ARM_CONFIGFLAGS
412 # For ARM, we need to make sure it picks up the correct versions
413 # of the linker and cctools.
414 if [ $t = 'arm' ] ; then
415 if [ -n "$ARM_SDK" ]; then
416 sdkoption="-sdk $ARM_SDK"
417 else
418 sdkoption="-sdk /"
420 progpath=`xcrun $sdkoption -find ld`
421 comppath=`dirname $progpath`
422 ORIG_COMPILER_PATH=$COMPILER_PATH
423 export COMPILER_PATH=$comppath:$COMPILER_PATH
426 if [ $h = $t ] ; then
427 make $MAKEFLAGS all CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
428 make $MAKEFLAGS DESTDIR=$DIR/dst-$h-$t install-gcc install-target \
429 CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
430 else
431 make $MAKEFLAGS all-gcc CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
432 make $MAKEFLAGS DESTDIR=$DIR/dst-$h-$t install-gcc \
433 CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
436 if [ $t = 'arm' ] ; then
437 export COMPILER_PATH=$ORIG_COMPILER_PATH
438 unset ORIG_COMPILER_PATH
440 done
442 done
444 ########################################
445 # Construct the actual destination root, by copying stuff from
446 # $DIR/dst-* to $DEST_DIR, with occasional 'lipo' commands.
448 cd $DEST_DIR || exit 1
450 # Clean out DEST_DIR in case -noclean was passed to buildit.
451 rm -rf * || exit 1
453 # LLVM LOCAL begin Don't install HTML docs.
454 if [ "$ENABLE_LLVM" == false ]; then
455 # HTML documentation
456 HTMLDIR="/Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.DeveloperTools.docset/Contents/Resources/Documents/documentation/DeveloperTools"
457 mkdir -p ".$HTMLDIR" || exit 1
458 cp -Rp $DIR/obj-$BUILD-$BUILD/gcc/HTML/* ".$HTMLDIR/" || exit 1
460 # LLVM LOCAL end Don't install docs.
462 # Manual pages
463 mkdir -p .$DEST_ROOT/share || exit 1
464 cp -Rp $DIR/dst-$BUILD-$BUILD$DEST_ROOT/share/man .$DEST_ROOT/share/ \
465 || exit 1
466 # exclude fsf-funding.7 gfdl.7 gpl.7 as they are currently built in
467 # the gcc project
468 rm -rf .$DEST_ROOT/share/man/man7
470 # libexec
471 cd $DIR/dst-$BUILD-$BUILD$DEST_ROOT/libexec/gcc/$BUILD-apple-darwin$DARWIN_VERS/$VERS \
472 || exit 1
473 LIBEXEC_FILES=`find . -type f -print || exit 1`
474 LIBEXEC_DIRS=`find . -type d -print || exit 1`
475 cd $DEST_DIR || exit 1
476 for t in $TARGETS ; do
477 DL=$DEST_ROOT/libexec/gcc/$t-apple-darwin$DARWIN_VERS/$VERS
478 for d in $LIBEXEC_DIRS ; do
479 mkdir -p .$DL/$d || exit 1
480 done
481 for f in $LIBEXEC_FILES ; do
482 # LLVM LOCAL
483 if file $DIR/dst-*-$t$DL/$f | grep -q -E 'Mach-O (executable|dynamically linked shared library)' ; then
484 lipo -output .$DL/$f -create $DIR/dst-*-$t$DL/$f || exit 1
485 else
486 cp -p $DIR/dst-$BUILD-$t$DL/$f .$DL/$f || exit 1
488 done
489 # LLVM LOCAL begin fix broken link
490 ln -s ../../../../../bin/as .$DL/as
491 ln -s ../../../../../bin/ld .$DL/ld
492 # LLVM LOCAL end fix broken link
493 done
495 # bin
496 # The native drivers ('native' is different in different architectures).
497 # LLVM LOCAL begin
498 mkdir .$DEST_ROOT/bin
499 cpp_files=`ls $DIR/dst-*$DEST_ROOT/bin/{llvm-cpp,cpp-$MAJ_VERS} 2>/dev/null`
500 lipo -output .$DEST_ROOT/bin/llvm-cpp-$MAJ_VERS -create $cpp_files || exit 1
501 # LLVM LOCAL end
503 # gcov, which is special only because it gets built multiple times and lipo
504 # will complain if we try to add two architectures into the same output.
505 TARG0=`echo $TARGETS | cut -d ' ' -f 1`
506 lipo -output .$DEST_ROOT/bin/gcov-$MAJ_VERS -create \
507 $DIR/dst-*-$TARG0$DEST_ROOT/bin/*gcov* || exit 1
508 # The fully-named drivers, which have the same target on every host.
509 for t in $TARGETS ; do
510 # LLVM LOCAL build_gcc bug with non-/usr $DEST_ROOT
511 lipo -output .$DEST_ROOT/bin/$t-apple-darwin$DARWIN_VERS-llvm-gcc-$MAJ_VERS -create \
512 $DIR/dst-*-$t/$DEST_ROOT/bin/$t-apple-darwin$DARWIN_VERS-gcc-$VERS || exit 1
513 # LLVM LOCAL build_gcc bug with non-/usr $DEST_ROOT
514 lipo -output .$DEST_ROOT/bin/$t-apple-darwin$DARWIN_VERS-llvm-g++-$MAJ_VERS -create \
515 $DIR/dst-*-$t/$DEST_ROOT/bin/$t-apple-darwin$DARWIN_VERS-*g++* || exit 1
516 done
518 # lib
519 mkdir -p .$DEST_ROOT/lib/gcc || exit 1
520 for t in $TARGETS ; do
521 # LLVM LOCAL build_gcc bug with non-/usr $DEST_ROOT
522 cp -Rp $DIR/dst-$BUILD-$t/$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS \
523 .$DEST_ROOT/lib/gcc || exit 1
524 done
526 # APPLE LOCAL begin native compiler support
527 # libgomp is not built for ARM
528 LIBGOMP_TARGETS=`echo $TARGETS | sed -E -e 's/(^|[[:space:]])arm($|[[:space:]])/ /'`
529 LIBGOMP_HOSTS=`echo $HOSTS | $OMIT_X86_64 | sed -E -e 's/(^|[[:space:]])arm($|[[:space:]])/ /'`
531 # And copy libgomp stuff by hand...
532 for t in $LIBGOMP_TARGETS ; do
533 for h in $LIBGOMP_HOSTS ; do
534 if [ $h = $t ] ; then
535 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/libgomp.a \
536 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/ || exit 1
537 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/libgomp.spec \
538 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/ || exit 1
539 if [ $h = 'powerpc' ] ; then
540 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/ppc64/libgomp.a \
541 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/ppc64/
542 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/ppc64/libgomp.spec \
543 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/ppc64/
544 elif [ $h = 'i686' ] ; then
545 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/x86_64/libgomp.a \
546 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/x86_64/ || exit 1
547 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/x86_64/libgomp.spec \
548 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/x86_64/ || exit 1
551 done
552 done
553 # APPLE LOCAL end native compiler support
555 # LLVM LOCAL remove libstdc++ copying
558 # include
559 HEADERPATH=$DEST_ROOT/include/gcc/darwin/$MAJ_VERS
560 mkdir -p .$HEADERPATH || exit 1
562 # Some headers are installed from more-hdrs/. They all share
563 # one common feature: they shouldn't be installed here. Sometimes,
564 # they should be part of FSF GCC and installed from there; sometimes,
565 # they should be installed by some completely different package; sometimes,
566 # they only exist for codewarrior compatibility and codewarrior should provide
567 # its own. We take care not to install the headers if Libc is already
568 # providing them.
569 cd $SRC_DIR/more-hdrs
570 for h in `echo *.h` ; do
571 if [ ! -f /usr/include/$h -o -L /usr/include/$h ] ; then
572 cp -R $h $DEST_DIR$HEADERPATH/$h || exit 1
573 for t in $TARGETS ; do
574 THEADERPATH=$DEST_DIR$DEST_ROOT/lib/gcc/${t}-apple-darwin$DARWIN_VERS/$VERS/include
575 [ -f $THEADERPATH/$h ] || \
576 ln -s ../../../../../include/gcc/darwin/$MAJ_VERS/$h $THEADERPATH/$h || \
577 exit 1
578 done
580 done
582 # Add extra man page symlinks for 'c++' and for arch-specific names.
583 MDIR=$DEST_DIR$DEST_ROOT/share/man/man1
584 if [ $BUILD_CXX -eq 1 ]; then
585 # LLVM LOCAL
586 ln -f $MDIR/llvm-g++.1 $MDIR/llvm-c++.1 || exit 1
588 for t in $TARGETS ; do
589 # LLVM LOCAL begin
590 ln -f $MDIR/llvm-gcc.1 $MDIR/$t-apple-darwin$DARWIN_VERS-llvm-gcc.1 \
591 || exit 1
592 if [ $BUILD_CXX -eq 1 ]; then
593 ln -f $MDIR/llvm-g++.1 $MDIR/$t-apple-darwin$DARWIN_VERS-llvm-g++.1 \
594 || exit 1
596 # LLVM LOCAL end
597 done
599 # LLVM LOCAL begin
600 # Compress manpages
601 gzip -f $MDIR/*
603 MAN1_DIR=$DEST_DIR/Developer/usr/share/man/man1
604 mkdir -p ${MAN1_DIR}
605 cp $ORIG_SRC_DIR/gcc/doc/llvm-gcc.1 ${MAN1_DIR}/llvm-gcc.1
606 cp $ORIG_SRC_DIR/gcc/doc/llvm-gcc.1 ${MAN1_DIR}/llvm-g++.1
607 gzip -f ${MAN1_DIR}/llvm-gcc.1
608 gzip -f ${MAN1_DIR}/llvm-g++.1
609 # LLVM LOCAL end
611 # Build driver-driver using fully-named drivers
612 for h in $HOSTS ; do
613 # LLVM LOCAL begin
614 $h-apple-darwin$DARWIN_VERS-gcc \
615 $ORIG_SRC_DIR/driverdriver.c \
616 -DPDN="\"-apple-darwin$DARWIN_VERS-llvm-gcc-$MAJ_VERS\"" \
617 -DIL="\"$DEST_ROOT/bin/\"" -I $ORIG_SRC_DIR/include \
618 -I $ORIG_SRC_DIR/gcc -I $ORIG_SRC_DIR/gcc/config \
619 -liberty -L$DIR/dst-$BUILD-$h$DEST_ROOT/lib/ \
620 -L$DIR/dst-$BUILD-$h$DEST_ROOT/$h-apple-darwin$DARWIN_VERS/lib/ \
621 -L$DIR/obj-$h-$BUILD/libiberty/ \
622 -o $DEST_DIR/$DEST_ROOT/bin/tmp-$h-llvm-gcc-$MAJ_VERS || exit 1
624 if [ $BUILD_CXX -eq 1 ]; then
625 $h-apple-darwin$DARWIN_VERS-gcc \
626 $ORIG_SRC_DIR/driverdriver.c \
627 -DPDN="\"-apple-darwin$DARWIN_VERS-llvm-g++-$MAJ_VERS\"" \
628 -DIL="\"$DEST_ROOT/bin/\"" -I $ORIG_SRC_DIR/include \
629 -I $ORIG_SRC_DIR/gcc -I $ORIG_SRC_DIR/gcc/config \
630 -liberty -L$DIR/dst-$BUILD-$h$DEST_ROOT/lib/ \
631 -L$DIR/dst-$BUILD-$h$DEST_ROOT/$h-apple-darwin$DARWIN_VERS/lib/ \
632 -L$DIR/obj-$h-$BUILD/libiberty/ \
633 -o $DEST_DIR/$DEST_ROOT/bin/tmp-$h-llvm-g++-$MAJ_VERS || exit 1
635 # LLVM LOCAL end
636 done
638 # LLVM LOCAL begin
639 lipo -output $DEST_DIR/$DEST_ROOT/bin/llvm-gcc-$MAJ_VERS -create \
640 $DEST_DIR/$DEST_ROOT/bin/tmp-*-llvm-gcc-$MAJ_VERS || exit 1
641 rm $DEST_DIR/$DEST_ROOT/bin/tmp-*-llvm-gcc-$MAJ_VERS || exit 1
643 if [ $BUILD_CXX -eq 1 ]; then
644 lipo -output $DEST_DIR/$DEST_ROOT/bin/llvm-g++-$MAJ_VERS -create \
645 $DEST_DIR/$DEST_ROOT/bin/tmp-*-llvm-g++-$MAJ_VERS || exit 1
646 ln -f $DEST_DIR/$DEST_ROOT/bin/llvm-g++-$MAJ_VERS $DEST_DIR/$DEST_ROOT/bin/llvm-c++-$MAJ_VERS || exit 1
647 rm $DEST_DIR/$DEST_ROOT/bin/tmp-*-llvm-g++-$MAJ_VERS || exit 1
649 # LLVM LOCAL end
651 ########################################
652 # Create SYM_DIR with information required for debugging.
654 cd $SYM_DIR || exit 1
656 # Clean out SYM_DIR in case -noclean was passed to buildit.
657 rm -rf * || exit 1
659 # Generate .dSYM files
660 find $DEST_DIR -perm -0111 \! -name fixinc.sh \
661 \! -name mkheaders -type f -print | xargs -n 1 -P ${SYSCTL} dsymutil
663 # Save .dSYM files and .a archives
664 cd $DEST_DIR || exit 1
665 find . \( -path \*.dSYM/\* -or -name \*.a \) -print \
666 | cpio -pdml $SYM_DIR || exit 1
667 # Save source files.
668 mkdir $SYM_DIR/src || exit 1
669 cd $DIR || exit 1
670 find obj-* -name \*.\[chy\] -print | cpio -pdml $SYM_DIR/src || exit 1
672 ########################################
673 # Remove debugging information from DEST_DIR.
675 if [ "x$LLVM_DEBUG" != "x1" ]; then
676 # LLVM LOCAL begin - don't strip dSYM objects
677 find $DEST_DIR -perm -0111 \! -path '*DWARF*' \! -name \*.dylib \
678 \! -name fixinc.sh \! -name mkheaders \! -name libstdc++.dylib \
679 -type f -print \
680 | xargs strip || exit 1
681 # LLVM LOCAL begin - Strip with -Sx instead of -SX
682 find $DEST_DIR \! -path '*DWARF*' \( -name \*.a -or -name \*.dylib \) \
683 \! -name libgcc_s.10.*.dylib \! -name libstdc++.dylib -type f \
684 -print \
685 | xargs strip -SX || exit 1
686 # LLVM LOCAL end - Strip with -Sx instead of -SX
687 find $DEST_DIR \! -path '*DWARF*' -name \*.a -type f -print \
688 | xargs ranlib || exit 1
689 # LLVM LOCAL end - don't strip dSYM objects
692 # LLVM LOCAL begin
693 # Set up the llvm-gcc/llvm-g++ symlinks.
695 # LLVM_BIN_DIR - This is the place where llvm-gcc/llvm-g++ symlinks get installed.
696 LLVM_BIN_DIR=$DEST_ROOT/../bin
698 mkdir -p $DEST_DIR$LLVM_BIN_DIR
699 cd $DEST_DIR$LLVM_BIN_DIR
700 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-gcc-$MAJ_VERS llvm-gcc-$MAJ_VERS || exit 1
701 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-g++-$MAJ_VERS llvm-g++-$MAJ_VERS || exit 1
702 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-cpp-$MAJ_VERS llvm-cpp-$MAJ_VERS || exit 1
703 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-gcc-$MAJ_VERS llvm-gcc || exit 1
704 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-g++-$MAJ_VERS llvm-g++ || exit 1
706 # FIXME: This is a hack to get things working.
707 for t in $TARGETS ; do
708 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/$t-apple-darwin$DARWIN_VERS-llvm-gcc-$MAJ_VERS $t-apple-darwin$DARWIN_VERS-llvm-gcc-$MAJ_VERS || exit 1
709 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/$t-apple-darwin$DARWIN_VERS-llvm-g++-$MAJ_VERS $t-apple-darwin$DARWIN_VERS-llvm-g++-$MAJ_VERS || exit 1
710 done
712 # Copy one of the libllvmgcc.dylib's up to libexec/gcc.
713 cp $DEST_DIR/$DEST_ROOT/libexec/gcc/$BUILD-apple-darwin$DARWIN_VERS/$VERS/libllvmgcc.dylib \
714 $DEST_DIR/$DEST_ROOT/libexec/gcc/
716 # Replace the installed ones with symlinks to the common one.
717 for t in $TARGETS ; do
718 cd $DEST_DIR/$DEST_ROOT/libexec/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/
719 rm libllvmgcc.dylib
720 ln -s ../../libllvmgcc.dylib
721 done
723 # Backward compatibility: Allow LLVM_BUILT_ROOTS instead of DISABLE_USR_LINKS.
724 if [ "x$LLVM_BUILT_ROOTS" != "x" ]; then
725 DISABLE_USR_LINKS=1
727 # Roots built by B&I, need to include sym links in /usr/bin and /usr/lib
728 # because B&I sets XCODE_DEVELOPER_USR_PATH=/. Otherwise, we don't want those
729 # sym links.
730 if [ "x$DISABLE_USR_LINKS" == "x" ]; then
731 mkdir -p $DEST_DIR/usr/bin
732 cd $DEST_DIR/usr/bin
733 ln -s ../../Developer/usr/bin/llvm-gcc-4.2 llvm-gcc-4.2
734 ln -s ../../Developer/usr/bin/llvm-g++-4.2 llvm-g++-4.2
737 # Remove unwind.h from the install directory for > 10.6
738 if [ $DARWIN_VERS -gt 10 ]; then
739 find $DEST_DIR -name "unwind.h" -print | xargs rm || exit 1
742 # Install libLTO.dylib
743 if [ "$INSTALL_LIBLTO" == yes ]; then
744 LTO=$LLVMCORE_PATH/lib/libLTO.dylib
745 if [ ! -r $LTO ]; then
746 LTO=$LLVMCORE_PATH/../lib/libLTO.dylib
747 if [ ! -r $LTO ]; then
748 echo "Error: llvmCore installation is missing libLTO.dylib"
749 exit 1
752 mkdir -p $DEST_DIR/Developer/usr/lib
753 cp $LTO $DEST_DIR/Developer/usr/lib/libLTO.dylib
754 strip -S $DEST_DIR/Developer/usr/lib/libLTO.dylib
756 if [ "x$DISABLE_USR_LINKS" == "x" ]; then
757 # Add a symlink in /usr/lib for B&I.
758 mkdir -p $DEST_DIR/usr/lib/
759 cd $DEST_DIR/usr/lib && \
760 ln -s ../../Developer/usr/lib/libLTO.dylib ./libLTO.dylib
764 # LLVM LOCAL end
766 find $DEST_DIR -name \*.dSYM -print | xargs rm -r || exit 1
767 chgrp -h -R wheel $DEST_DIR
768 chgrp -R wheel $DEST_DIR
770 # Done!
771 exit 0