Mike Stump pointed out that I can't use autoconf 2.61 here;
[llvm-gcc-4.2.git] / build_gcc
blobe4d08e20afdbc722118157e12e8379cca074f20e
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 true/false indicating whether LLVM should be enabled
73 # or not.
74 ENABLE_LLVM="$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 # LLVM LOCAL end
91 # The current working directory is where the build will happen.
92 # It may already contain a partial result of an interrupted build,
93 # in which case this script will continue where it left off.
94 DIR=`pwd`
96 # This isn't a parameter; it's the version of the compiler that we're
97 # about to build. It's included in the names of various files and
98 # directories in the installed image.
99 VERS=`cat $ORIG_SRC_DIR/gcc/BASE-VER`
100 if [ -z "$VERS" ]; then
101 exit 1
104 # This isn't a parameter either, it's the major version of the compiler
105 # to be built. It's VERS but only up to the second '.' (if there is one).
106 MAJ_VERS=`echo $VERS | sed 's/\([0-9]*\.[0-9]*\)[.-].*/\1/'`
108 # This is the libstdc++ version to use.
109 LIBSTDCXX_VERSION=4.2.1
110 # LLVM LOCAL begin
111 # DO NOT USE $DEST_ROOT to check LIBSTDCXX_VERSION here. Directly use /usr here.
112 # $DEST_ROOT is /Developer for llvm-gcc
113 if [ ! -d "/usr/include/c++/$LIBSTDCXX_VERSION" ]; then
114 LIBSTDCXX_VERSION=4.0.0
116 NON_ARM_CONFIGFLAGS="--with-gxx-include-dir=/usr/include/c++/$LIBSTDCXX_VERSION"
117 # LLVM LOCAL end
119 DARWIN_VERS=`uname -r | sed 's/\..*//'`
120 echo DARWIN_VERS = $DARWIN_VERS
122 # APPLE LOCAL begin ARM
123 ARM_LIBSTDCXX_VERSION=4.2.1
124 ARM_CONFIGFLAGS="--with-gxx-include-dir=/usr/include/c++/$ARM_LIBSTDCXX_VERSION"
126 if [ -n "$ARM_SDK" ]; then
128 ARM_PLATFORM=`xcodebuild -version -sdk $ARM_SDK PlatformPath`
129 ARM_SYSROOT=`xcodebuild -version -sdk $ARM_SDK Path`
130 ARM_TOOLROOT=$ARM_PLATFORM/Developer
132 elif [ "x$RC_TARGET_CONFIG" = "xiPhone" ]; then
134 # If the build target is iPhone, use the iPhone SDK as the build sysroot
135 # and use the tools from the iPhone platform directory. FIXME: This is a
136 # temporary fallback for builds where ARM_SDK is not set. It can be removed,
137 # along with the following bootstrap SDK fallback, when ARM_SDK is set for
138 # all builds.
139 ARM_PLATFORM=/Developer/Platforms/iPhoneOS.platform
140 ARM_IPHONE_SDK=iPhoneOS${IPHONEOS_DEPLOYMENT_TARGET}.Internal.sdk
142 ARM_SYSROOT=$ARM_PLATFORM/Developer/SDKs/$ARM_IPHONE_SDK
143 ARM_TOOLROOT=$ARM_PLATFORM/Developer
145 # If it's being built for iPhoneOS, assume the llvmCore bits are under
146 # iPhoneOS platform directory.
147 if [ "x$RC_ProjectName" = "xllvmgcc42_Embedded" ]; then
148 LLVMCORE_PATH="${ARM_PLATFORM}${LLVMCORE_PATH}"
149 DEST_ROOT="${ARM_PLATFORM}${DEST_ROOT}"
151 else
153 # Use bootstrap SDK if it is available.
154 if [ -d /Developer/SDKs/Extra ]; then
155 ARM_SYSROOT=/Developer/SDKs/Extra
156 else
157 ARM_SYSROOT=/
159 ARM_TOOLROOT=/
162 ARM_CONFIGFLAGS="$ARM_CONFIGFLAGS --with-build-sysroot=\"$ARM_SYSROOT\""
164 # If building an ARM target, check that the required directories exist
165 # and query the libSystem arm slices to determine which multilibs we should
166 # build.
167 if echo $TARGETS | grep arm; then
168 if [ ! -d $ARM_SYSROOT ]; then
169 echo "Error: cannot find ARM SDK to build ARM target"
170 exit 1
172 if [ ! -d $ARM_TOOLROOT ]; then
173 echo "Error: $ARM_TOOLROOT directory is not installed"
174 exit 1
176 if [ "x$ARM_MULTILIB_ARCHS" = "x" ] ; then
177 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/ $//'`
179 if [ "x$ARM_MULTILIB_ARCHS" == "x" ] ; then
180 echo "Error: missing ARM slices in $ARM_SYSROOT"
181 exit 1
182 else
183 export ARM_MULTILIB_ARCHS
186 # APPLE LOCAL end ARM
188 # LLVM LOCAL begin
189 # If the user has CC set in their environment unset it now
190 unset CC
191 # LLVM LOCAL end
193 ########################################
194 # Run the build.
196 # Create the source tree we'll actually use to build, deleting
197 # tcl since it doesn't actually build properly in a cross environment
198 # and we don't really need it.
199 SRC_DIR=$DIR/src
200 rm -rf $SRC_DIR || exit 1
201 mkdir $SRC_DIR || exit 1
202 ln -s $ORIG_SRC_DIR/* $SRC_DIR/ || exit 1
203 rm -rf $SRC_DIR/tcl $SRC_DIR/expect $SRC_DIR/dejagnu || exit 1
204 # Also remove libstdc++ since it is built from a separate project.
205 # LLVM LOCAL: The following line was commented out; uncomment it.
206 rm -rf $SRC_DIR/libstdc++-v3 || exit 1
207 # Clean out old specs files
208 rm -f /usr/lib/gcc/*/4.0.0/specs
210 # These are the configure and build flags that are used.
211 # LLVM LOCAL begin
212 if [ "x$LLVM_DEBUG" == "x" ]; then
213 CHECKING_FLAGS="--disable-checking --enable-werror"
214 else
215 CHECKING_FLAGS="--enable-checking"
218 CONFIGFLAGS="$CHECKING_FLAGS \
219 --prefix=$DEST_ROOT \
220 --mandir=\${prefix}/share/man \
221 --enable-languages=$LANGUAGES \
222 --program-prefix=llvm- \
223 --program-transform-name=/^[cg][^.-]*$/s/$/-$MAJ_VERS/ \
224 --with-slibdir=/usr/lib \
225 --build=$BUILD-apple-darwin$DARWIN_VERS"
227 if [ "$ENABLE_LLVM" == true ]; then
228 CONFIGFLAGS="$CONFIGFLAGS --enable-llvm=$LLVMCORE_PATH"
230 # LLVM LOCAL end
232 # Figure out how many make processes to run.
233 SYSCTL=`sysctl -n hw.activecpu`
235 # hw.activecpu only available in 10.2.6 and later
236 if [ -z "$SYSCTL" ]; then
237 SYSCTL=`sysctl -n hw.ncpu`
240 # sysctl -n hw.* does not work when invoked via B&I chroot /BuildRoot.
241 # Builders can default to 2, since even if they are single processor,
242 # nothing else is running on the machine.
243 if [ -z "$SYSCTL" ]; then
244 SYSCTL=2
247 # The $LOCAL_MAKEFLAGS variable can be used to override $MAKEFLAGS.
248 MAKEFLAGS=${LOCAL_MAKEFLAGS-"-j $SYSCTL"}
250 BUILD_CXX=0
251 for lang in `echo $LANGUAGES | sed 's/,/ /g'`; do
252 if [ $lang = "c++" -o $lang = "obj-c++" ]; then
253 BUILD_CXX=1
254 break
256 done
258 # Unset this, because GCC uses this variable in its makefiles
259 unset LANGUAGES
261 # LLVM LOCAL begin
262 if [ "$ENABLE_LLVM" == true ]; then
263 # Indicate the llvm-gcc is being built "Apple style".
264 MAKEFLAGS="$MAKEFLAGS BUILD_LLVM_APPLE_STYLE=1"
265 # Build llvm-gcc in 'dylib mode'.
266 MAKEFLAGS="$MAKEFLAGS BUILD_LLVM_INTO_A_DYLIB=1"
267 MAKEFLAGS="$MAKEFLAGS LLVM_VERSION_INFO=$LLVM_SUBMIT_VERSION"
269 # LLVM LOCAL end
271 # If the user has set CC or CXX, respect their wishes. If not,
272 # compile with LLVM-GCC/LLVM-G++ if available; if LLVM is not
273 # available, fall back to usual GCC/G++ default.
274 savedPATH=$PATH ; PATH="/Developer/usr/bin:$PATH"
275 XTMPCC=$(which llvm-gcc)
276 if [ x$CC = x -a x$XTMPCC != x ] ; then export CC=$XTMPCC forcedCC=1 ; fi
277 XTMPCC=$(which llvm-g++)
278 if [ x$CXX = x -a x$XTMPCC != x ] ; then export CXX=$XTMPCC forcedCXX=1 ; fi
279 PATH=$savedPATH
280 unset XTMPCC savedPATH
282 # Build the native GCC. Do this even if the user didn't ask for it
283 # because it'll be needed for the bootstrap.
284 mkdir -p $DIR/obj-$BUILD-$BUILD $DIR/dst-$BUILD-$BUILD || exit 1
285 cd $DIR/obj-$BUILD-$BUILD || exit 1
286 if [ \! -f Makefile ]; then
287 $SRC_DIR/configure $bootstrap $CONFIGFLAGS $NON_ARM_CONFIGFLAGS \
288 --host=$BUILD-apple-darwin$DARWIN_VERS \
289 --target=$BUILD-apple-darwin$DARWIN_VERS || exit 1
292 # Unset RC_DEBUG_OPTIONS because it causes the bootstrap to fail.
293 # Also keep unset for cross compilers so that the cross built libraries are
294 # comparable to the native built libraries.
295 unset RC_DEBUG_OPTIONS
296 make $MAKEFLAGS CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
297 make $MAKEFLAGS html CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
298 make $MAKEFLAGS DESTDIR=$DIR/dst-$BUILD-$BUILD install-gcc install-target \
299 CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
301 # Now that we've built a native compiler, un-kludge these so that
302 # subsequent cross-hosted compilers can be found normally.
303 if [ x$forcedCC != x ] ; then unset CC forcedCC ; fi
304 if [ x$forcedCXX != x ] ; then unset CXX forcedCXX ; fi
306 # Add the compiler we just built to the path, giving it appropriate names.
307 # LLVM LOCAL begin Support for non /usr $DEST_ROOT
308 D=$DIR/dst-$BUILD-$BUILD$DEST_ROOT/bin
309 ln -f $D/llvm-gcc $D/gcc || exit 1
310 ln -f $D/gcc $D/$BUILD-apple-darwin$DARWIN_VERS-gcc || exit 1
311 PATH=$DIR/dst-$BUILD-$BUILD$DEST_ROOT/bin:$PATH
312 # LLVM LOCAL end Support for non /usr $DEST_ROOT
314 # The cross-tools' build process expects to find certain programs
315 # under names like 'i386-apple-darwin$DARWIN_VERS-ar'; so make them.
316 # Annoyingly, ranlib changes behaviour depending on what you call it,
317 # so we have to use a shell script for indirection, grrr.
318 rm -rf $DIR/bin || exit 1
319 mkdir $DIR/bin || exit 1
320 for prog in ar nm ranlib strip lipo ld ; do
321 for t in `echo $TARGETS $HOSTS | sort -u`; do
322 P=$DIR/bin/${t}-apple-darwin$DARWIN_VERS-${prog}
323 # APPLE LOCAL begin toolroot
324 if [ $t = "arm" ]; then
325 toolroot=$ARM_TOOLROOT
326 else
327 toolroot=
329 # APPLE LOCAL end toolroot
330 echo '#!/bin/sh' > $P || exit 1
331 # APPLE LOCAL insert toolroot below
332 echo 'exec '${toolroot}'/usr/bin/'${prog}' "$@"' >> $P || exit 1
333 chmod a+x $P || exit 1
334 done
335 done
336 for t in `echo $1 $2 | sort -u`; do
337 gt=`echo $t | $TRANSLATE_ARCH`
338 P=$DIR/bin/${gt}-apple-darwin$DARWIN_VERS-as
339 # APPLE LOCAL begin toolroot
340 if [ $gt = "arm" ]; then
341 toolroot=$ARM_TOOLROOT
342 else
343 toolroot=
345 # APPLE LOCAL end toolroot
346 echo '#!/bin/sh' > $P || exit 1
348 # APPLE LOCAL insert toolroot below
349 echo 'for a; do case $a in -arch) exec '${toolroot}'/usr/bin/as "$@";; esac; done' >> $P || exit 1
350 echo 'exec '${toolroot}'/usr/bin/as -arch '${t}' "$@"' >> $P || exit 1
351 chmod a+x $P || exit 1
352 done
353 PATH=$DIR/bin:$PATH
355 # Determine which cross-compilers we should build. If our build architecture is
356 # one of our hosts, add all of the targets to the list.
357 if echo $HOSTS | grep $BUILD
358 then
359 CROSS_TARGETS=`echo $TARGETS $HOSTS | tr ' ' '\n' | sort -u`
360 else
361 CROSS_TARGETS="$HOSTS"
364 # Build the cross-compilers, using the compiler we just built.
365 for t in $CROSS_TARGETS ; do
366 if [ $t != $BUILD ] ; then
367 mkdir -p $DIR/obj-$BUILD-$t $DIR/dst-$BUILD-$t || exit 1
368 cd $DIR/obj-$BUILD-$t || exit 1
369 if [ \! -f Makefile ]; then
370 # APPLE LOCAL begin ARM ARM_CONFIGFLAGS
371 T_CONFIGFLAGS="$CONFIGFLAGS --enable-werror-always \
372 --program-prefix=$t-apple-darwin$DARWIN_VERS- \
373 --host=$BUILD-apple-darwin$DARWIN_VERS \
374 --target=$t-apple-darwin$DARWIN_VERS"
375 if [ $t = 'arm' ] ; then
376 # Explicitly set AS_FOR_TARGET and LD_FOR_TARGET to avoid picking up
377 # older versions from the gcc installed in /usr. Radar 7230843.
378 AS_FOR_TARGET=$DIR/bin/${t}-apple-darwin$DARWIN_VERS-as \
379 LD_FOR_TARGET=$DIR/bin/${t}-apple-darwin$DARWIN_VERS-ld \
380 $SRC_DIR/configure $T_CONFIGFLAGS $ARM_CONFIGFLAGS || exit 1
381 else
382 $SRC_DIR/configure $T_CONFIGFLAGS $NON_ARM_CONFIGFLAGS || exit 1
384 # APPLE LOCAL end ARM ARM_CONFIGFLAGS
386 make $MAKEFLAGS all CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
387 make $MAKEFLAGS DESTDIR=$DIR/dst-$BUILD-$t install-gcc install-target \
388 CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
390 # Add the compiler we just built to the path.
391 # LLVM LOCAL Support for non /usr $DEST_ROOT
392 PATH=$DIR/dst-$BUILD-$t/$DEST_ROOT/bin:$PATH
394 done
396 # Rearrange various libraries, for no really good reason.
397 for t in $CROSS_TARGETS ; do
398 DT=$DIR/dst-$BUILD-$t
399 # LLVM LOCAL Support for non /usr $DEST_ROOT
400 D=`echo $DT/$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS`
401 mv $D/static/libgcc.a $D/libgcc_static.a || exit 1
402 mv $D/kext/libgcc.a $D/libcc_kext.a || exit 1
403 rm -r $D/static $D/kext || exit 1
404 # glue together kext64 stuff
405 if [ -e $D/kext64/libgcc.a ]; then
406 libtool -static $D/{kext64/libgcc.a,libcc_kext.a} -o $D/libcc_kext1.a 2>&1 | grep -v 'has no symbols'
407 mv $D/libcc_kext1.a $D/libcc_kext.a
408 rm -rf $D/kext64
410 done
412 # Build the cross-hosted compilers.
413 for h in $HOSTS ; do
414 if [ $h != $BUILD ] ; then
415 for t in $TARGETS ; do
416 mkdir -p $DIR/obj-$h-$t $DIR/dst-$h-$t || exit 1
417 cd $DIR/obj-$h-$t || exit 1
418 if [ $h = $t ] ; then
420 else
421 pp=$t-apple-darwin$DARWIN_VERS-
424 if [ \! -f Makefile ]; then
425 # APPLE LOCAL begin ARM ARM_CONFIGFLAGS
426 T_CONFIGFLAGS="$CONFIGFLAGS --program-prefix=$pp \
427 --host=$h-apple-darwin$DARWIN_VERS \
428 --target=$t-apple-darwin$DARWIN_VERS"
429 if [ $t = 'arm' ] && [ $h != 'arm' ] ; then
430 T_CONFIGFLAGS="$T_CONFIGFLAGS $ARM_CONFIGFLAGS"
431 else
432 T_CONFIGFLAGS="$T_CONFIGFLAGS $NON_ARM_CONFIGFLAGS"
434 $SRC_DIR/configure $T_CONFIGFLAGS || exit 1
435 # APPLE LOCAL end ARM ARM_CONFIGFLAGS
438 # For ARM, we need to make sure it picks up the ARM_TOOLROOT versions
439 # of the linker and cctools.
440 if [ $t = 'arm' ] ; then
441 ORIG_COMPILER_PATH=$COMPILER_PATH
442 export COMPILER_PATH=$ARM_TOOLROOT/usr/bin:$COMPILER_PATH
445 if [ $h = $t ] ; then
446 make $MAKEFLAGS all CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
447 make $MAKEFLAGS DESTDIR=$DIR/dst-$h-$t install-gcc install-target \
448 CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
449 else
450 make $MAKEFLAGS all-gcc CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
451 make $MAKEFLAGS DESTDIR=$DIR/dst-$h-$t install-gcc \
452 CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
455 if [ $t = 'arm' ] ; then
456 export COMPILER_PATH=$ORIG_COMPILER_PATH
457 unset ORIG_COMPILER_PATH
459 done
461 done
463 ########################################
464 # Construct the actual destination root, by copying stuff from
465 # $DIR/dst-* to $DEST_DIR, with occasional 'lipo' commands.
467 cd $DEST_DIR || exit 1
469 # Clean out DEST_DIR in case -noclean was passed to buildit.
470 rm -rf * || exit 1
472 # LLVM LOCAL begin Don't install HTML docs.
473 if [ "$ENABLE_LLVM" == false ]; then
474 # HTML documentation
475 HTMLDIR="/Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.DeveloperTools.docset/Contents/Resources/Documents/documentation/DeveloperTools"
476 mkdir -p ".$HTMLDIR" || exit 1
477 cp -Rp $DIR/obj-$BUILD-$BUILD/gcc/HTML/* ".$HTMLDIR/" || exit 1
479 # LLVM LOCAL end Don't install docs.
481 # Manual pages
482 mkdir -p .$DEST_ROOT/share || exit 1
483 cp -Rp $DIR/dst-$BUILD-$BUILD$DEST_ROOT/share/man .$DEST_ROOT/share/ \
484 || exit 1
485 # exclude fsf-funding.7 gfdl.7 gpl.7 as they are currently built in
486 # the gcc project
487 rm -rf .$DEST_ROOT/share/man/man7
489 # libexec
490 cd $DIR/dst-$BUILD-$BUILD$DEST_ROOT/libexec/gcc/$BUILD-apple-darwin$DARWIN_VERS/$VERS \
491 || exit 1
492 LIBEXEC_FILES=`find . -type f -print || exit 1`
493 LIBEXEC_DIRS=`find . -type d -print || exit 1`
494 cd $DEST_DIR || exit 1
495 for t in $TARGETS ; do
496 DL=$DEST_ROOT/libexec/gcc/$t-apple-darwin$DARWIN_VERS/$VERS
497 for d in $LIBEXEC_DIRS ; do
498 mkdir -p .$DL/$d || exit 1
499 done
500 for f in $LIBEXEC_FILES ; do
501 # LLVM LOCAL
502 if file $DIR/dst-*-$t$DL/$f | grep -q -E 'Mach-O (executable|dynamically linked shared library)' ; then
503 lipo -output .$DL/$f -create $DIR/dst-*-$t$DL/$f || exit 1
504 else
505 cp -p $DIR/dst-$BUILD-$t$DL/$f .$DL/$f || exit 1
507 done
508 # LLVM LOCAL begin fix broken link
509 ln -s ../../../../../bin/as .$DL/as
510 ln -s ../../../../../bin/ld .$DL/ld
511 # LLVM LOCAL end fix broken link
512 done
514 # bin
515 # The native drivers ('native' is different in different architectures).
516 # LLVM LOCAL begin
517 mkdir .$DEST_ROOT/bin
518 cpp_files=`ls $DIR/dst-*$DEST_ROOT/bin/{llvm-cpp,cpp-$MAJ_VERS} 2>/dev/null`
519 lipo -output .$DEST_ROOT/bin/llvm-cpp-$MAJ_VERS -create $cpp_files || exit 1
520 # LLVM LOCAL end
522 # gcov, which is special only because it gets built multiple times and lipo
523 # will complain if we try to add two architectures into the same output.
524 TARG0=`echo $TARGETS | cut -d ' ' -f 1`
525 lipo -output .$DEST_ROOT/bin/gcov-$MAJ_VERS -create \
526 $DIR/dst-*-$TARG0$DEST_ROOT/bin/*gcov* || exit 1
527 # The fully-named drivers, which have the same target on every host.
528 for t in $TARGETS ; do
529 # LLVM LOCAL build_gcc bug with non-/usr $DEST_ROOT
530 lipo -output .$DEST_ROOT/bin/$t-apple-darwin$DARWIN_VERS-llvm-gcc-$MAJ_VERS -create \
531 $DIR/dst-*-$t/$DEST_ROOT/bin/$t-apple-darwin$DARWIN_VERS-gcc-$VERS || exit 1
532 # LLVM LOCAL build_gcc bug with non-/usr $DEST_ROOT
533 lipo -output .$DEST_ROOT/bin/$t-apple-darwin$DARWIN_VERS-llvm-g++-$MAJ_VERS -create \
534 $DIR/dst-*-$t/$DEST_ROOT/bin/$t-apple-darwin$DARWIN_VERS-*g++* || exit 1
535 done
537 # lib
538 mkdir -p .$DEST_ROOT/lib/gcc || exit 1
539 for t in $TARGETS ; do
540 # LLVM LOCAL build_gcc bug with non-/usr $DEST_ROOT
541 cp -Rp $DIR/dst-$BUILD-$t/$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS \
542 .$DEST_ROOT/lib/gcc || exit 1
543 done
545 # APPLE LOCAL begin native compiler support
546 # libgomp is not built for ARM
547 LIBGOMP_TARGETS=`echo $TARGETS | sed -E -e 's/(^|[[:space:]])arm($|[[:space:]])/ /'`
548 LIBGOMP_HOSTS=`echo $HOSTS | $OMIT_X86_64 | sed -E -e 's/(^|[[:space:]])arm($|[[:space:]])/ /'`
550 # And copy libgomp stuff by hand...
551 for t in $LIBGOMP_TARGETS ; do
552 for h in $LIBGOMP_HOSTS ; do
553 if [ $h = $t ] ; then
554 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/libgomp.a \
555 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/ || exit 1
556 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/libgomp.spec \
557 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/ || exit 1
558 if [ $h = 'powerpc' ] ; then
559 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/ppc64/libgomp.a \
560 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/ppc64/
561 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/ppc64/libgomp.spec \
562 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/ppc64/
563 elif [ $h = 'i686' ] ; then
564 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/x86_64/libgomp.a \
565 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/x86_64/ || exit 1
566 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/x86_64/libgomp.spec \
567 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/x86_64/ || exit 1
570 done
571 done
572 # APPLE LOCAL end native compiler support
574 if [ $BUILD_CXX -eq 1 ]; then
575 for t in $TARGETS ; do
576 if [ "$t" == 'arm' ] ; then
577 cp -p $ARM_SYSROOT/usr/lib/libstdc++.6.dylib \
578 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/libstdc++.dylib \
579 || exit 1
580 else
581 cp -p /usr/lib/libstdc++.6.dylib \
582 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/libstdc++.dylib \
583 || exit 1
585 # LLVM LOCAL
586 # strip -x -c .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/libstdc++.dylib || exit 1
587 done
590 # include
591 HEADERPATH=$DEST_ROOT/include/gcc/darwin/$MAJ_VERS
592 mkdir -p .$HEADERPATH || exit 1
594 # Some headers are installed from more-hdrs/. They all share
595 # one common feature: they shouldn't be installed here. Sometimes,
596 # they should be part of FSF GCC and installed from there; sometimes,
597 # they should be installed by some completely different package; sometimes,
598 # they only exist for codewarrior compatibility and codewarrior should provide
599 # its own. We take care not to install the headers if Libc is already
600 # providing them.
601 cd $SRC_DIR/more-hdrs
602 for h in `echo *.h` ; do
603 if [ ! -f /usr/include/$h -o -L /usr/include/$h ] ; then
604 cp -R $h $DEST_DIR$HEADERPATH/$h || exit 1
605 for t in $TARGETS ; do
606 THEADERPATH=$DEST_DIR$DEST_ROOT/lib/gcc/${t}-apple-darwin$DARWIN_VERS/$VERS/include
607 [ -f $THEADERPATH/$h ] || \
608 ln -s ../../../../../include/gcc/darwin/$MAJ_VERS/$h $THEADERPATH/$h || \
609 exit 1
610 done
612 done
614 # Add extra man page symlinks for 'c++' and for arch-specific names.
615 MDIR=$DEST_DIR$DEST_ROOT/share/man/man1
616 if [ $BUILD_CXX -eq 1 ]; then
617 # LLVM LOCAL
618 ln -f $MDIR/llvm-g++.1 $MDIR/llvm-c++.1 || exit 1
620 for t in $TARGETS ; do
621 # LLVM LOCAL begin
622 ln -f $MDIR/llvm-gcc.1 $MDIR/$t-apple-darwin$DARWIN_VERS-llvm-gcc.1 \
623 || exit 1
624 if [ $BUILD_CXX -eq 1 ]; then
625 ln -f $MDIR/llvm-g++.1 $MDIR/$t-apple-darwin$DARWIN_VERS-llvm-g++.1 \
626 || exit 1
628 # LLVM LOCAL end
629 done
631 # LLVM LOCAL begin
632 # Compress manpages
633 gzip -f $MDIR/*
635 if [ "x$RC_ProjectName" = "xllvmgcc42_Embedded" ]; then
636 MAN1_DIR=${DEST_DIR}${ARM_PLATFORM}/Developer/usr/share/man/man1
637 else
638 MAN1_DIR=$DEST_DIR/Developer/usr/share/man/man1
640 mkdir -p ${MAN1_DIR}
641 cp $ORIG_SRC_DIR/gcc/doc/llvm-gcc.1 ${MAN1_DIR}/llvm-gcc.1
642 cp $ORIG_SRC_DIR/gcc/doc/llvm-gcc.1 ${MAN1_DIR}/llvm-g++.1
643 gzip -f ${MAN1_DIR}/llvm-gcc.1
644 gzip -f ${MAN1_DIR}/llvm-g++.1
645 # LLVM LOCAL end
647 # Build driver-driver using fully-named drivers
648 for h in $HOSTS ; do
649 # LLVM LOCAL begin
650 $h-apple-darwin$DARWIN_VERS-gcc \
651 $ORIG_SRC_DIR/driverdriver.c \
652 -DPDN="\"-apple-darwin$DARWIN_VERS-llvm-gcc-$MAJ_VERS\"" \
653 -DIL="\"$DEST_ROOT/bin/\"" -I $ORIG_SRC_DIR/include \
654 -I $ORIG_SRC_DIR/gcc -I $ORIG_SRC_DIR/gcc/config \
655 -liberty -L$DIR/dst-$BUILD-$h$DEST_ROOT/lib/ \
656 -L$DIR/dst-$BUILD-$h$DEST_ROOT/$h-apple-darwin$DARWIN_VERS/lib/ \
657 -L$DIR/obj-$h-$BUILD/libiberty/ \
658 -o $DEST_DIR/$DEST_ROOT/bin/tmp-$h-llvm-gcc-$MAJ_VERS || exit 1
660 if [ $BUILD_CXX -eq 1 ]; then
661 $h-apple-darwin$DARWIN_VERS-gcc \
662 $ORIG_SRC_DIR/driverdriver.c \
663 -DPDN="\"-apple-darwin$DARWIN_VERS-llvm-g++-$MAJ_VERS\"" \
664 -DIL="\"$DEST_ROOT/bin/\"" -I $ORIG_SRC_DIR/include \
665 -I $ORIG_SRC_DIR/gcc -I $ORIG_SRC_DIR/gcc/config \
666 -liberty -L$DIR/dst-$BUILD-$h$DEST_ROOT/lib/ \
667 -L$DIR/dst-$BUILD-$h$DEST_ROOT/$h-apple-darwin$DARWIN_VERS/lib/ \
668 -L$DIR/obj-$h-$BUILD/libiberty/ \
669 -o $DEST_DIR/$DEST_ROOT/bin/tmp-$h-llvm-g++-$MAJ_VERS || exit 1
671 # LLVM LOCAL end
672 done
674 # LLVM LOCAL begin
675 lipo -output $DEST_DIR/$DEST_ROOT/bin/llvm-gcc-$MAJ_VERS -create \
676 $DEST_DIR/$DEST_ROOT/bin/tmp-*-llvm-gcc-$MAJ_VERS || exit 1
677 rm $DEST_DIR/$DEST_ROOT/bin/tmp-*-llvm-gcc-$MAJ_VERS || exit 1
679 if [ $BUILD_CXX -eq 1 ]; then
680 lipo -output $DEST_DIR/$DEST_ROOT/bin/llvm-g++-$MAJ_VERS -create \
681 $DEST_DIR/$DEST_ROOT/bin/tmp-*-llvm-g++-$MAJ_VERS || exit 1
682 ln -f $DEST_DIR/$DEST_ROOT/bin/llvm-g++-$MAJ_VERS $DEST_DIR/$DEST_ROOT/bin/llvm-c++-$MAJ_VERS || exit 1
683 rm $DEST_DIR/$DEST_ROOT/bin/tmp-*-llvm-g++-$MAJ_VERS || exit 1
685 # LLVM LOCAL end
687 ########################################
688 # Create SYM_DIR with information required for debugging.
690 cd $SYM_DIR || exit 1
692 # Clean out SYM_DIR in case -noclean was passed to buildit.
693 rm -rf * || exit 1
695 # Generate .dSYM files
696 find $DEST_DIR -perm -0111 \! -name fixinc.sh \
697 \! -name mkheaders -type f -print | xargs -n 1 -P ${SYSCTL} dsymutil
699 # Save .dSYM files and .a archives
700 cd $DEST_DIR || exit 1
701 find . \( -path \*.dSYM/\* -or -name \*.a \) -print \
702 | cpio -pdml $SYM_DIR || exit 1
703 # Save source files.
704 mkdir $SYM_DIR/src || exit 1
705 cd $DIR || exit 1
706 find obj-* -name \*.\[chy\] -print | cpio -pdml $SYM_DIR/src || exit 1
708 ########################################
709 # Remove debugging information from DEST_DIR.
711 if [ "x$LLVM_DEBUG" != "x1" ]; then
712 # LLVM LOCAL begin - don't strip dSYM objects
713 find $DEST_DIR -perm -0111 \! -path '*DWARF*' \! -name \*.dylib \
714 \! -name fixinc.sh \! -name mkheaders \! -name libstdc++.dylib \
715 -type f -print \
716 | xargs strip || exit 1
717 # LLVM LOCAL begin - Strip with -Sx instead of -SX
718 find $DEST_DIR \! -path '*DWARF*' \( -name \*.a -or -name \*.dylib \) \
719 \! -name libgcc_s.10.*.dylib \! -name libstdc++.dylib -type f \
720 -print \
721 | xargs strip -SX || exit 1
722 # LLVM LOCAL end - Strip with -Sx instead of -SX
723 find $DEST_DIR \! -path '*DWARF*' -name \*.a -type f -print \
724 | xargs ranlib || exit 1
725 # LLVM LOCAL end - don't strip dSYM objects
728 # LLVM LOCAL begin
729 # Set up the llvm-gcc/llvm-g++ symlinks.
731 # LLVM_BIN_DIR - This is the place where llvm-gcc/llvm-g++ symlinks get installed.
732 LLVM_BIN_DIR=$DEST_ROOT/../bin
734 mkdir -p $DEST_DIR$LLVM_BIN_DIR
735 cd $DEST_DIR$LLVM_BIN_DIR
736 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-gcc-$MAJ_VERS llvm-gcc-$MAJ_VERS || exit 1
737 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-g++-$MAJ_VERS llvm-g++-$MAJ_VERS || exit 1
738 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-cpp-$MAJ_VERS llvm-cpp-$MAJ_VERS || exit 1
739 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-gcc-$MAJ_VERS llvm-gcc || exit 1
740 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-g++-$MAJ_VERS llvm-g++ || exit 1
742 # FIXME: This is a hack to get things working.
743 for t in $TARGETS ; do
744 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
745 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
746 done
748 # Copy one of the libllvmgcc.dylib's up to libexec/gcc.
749 cp $DEST_DIR/$DEST_ROOT/libexec/gcc/$BUILD-apple-darwin$DARWIN_VERS/$VERS/libllvmgcc.dylib \
750 $DEST_DIR/$DEST_ROOT/libexec/gcc/
752 # Replace the installed ones with symlinks to the common one.
753 for t in $TARGETS ; do
754 cd $DEST_DIR/$DEST_ROOT/libexec/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/
755 rm libllvmgcc.dylib
756 ln -s ../../libllvmgcc.dylib
757 done
759 if [ "x$RC_ProjectName" == "xllvmgcc42_Embedded" ]; then
760 if [ "x$LLVM_BUILT_ROOTS" == "x" ]; then
761 mkdir -p $DEST_DIR${ARM_PLATFORM}/usr/bin
762 cd $DEST_DIR${ARM_PLATFORM}/usr/bin
763 ln -s ${ARM_PLATFORM}/Developer/usr/bin/llvm-gcc-4.2 llvm-gcc-4.2
764 ln -s ${ARM_PLATFORM}/Developer/usr/bin/llvm-g++-4.2 llvm-g++-4.2
766 else
767 if [ "x$LLVM_BUILT_ROOTS" == "x" ]; then
768 mkdir -p $DEST_DIR/usr/bin
769 cd $DEST_DIR/usr/bin
770 ln -s /Developer/usr/bin/llvm-gcc-4.2 llvm-gcc-4.2
771 ln -s /Developer/usr/bin/llvm-g++-4.2 llvm-g++-4.2
774 # LLVM LOCAL end
776 find $DEST_DIR -name \*.dSYM -print | xargs rm -r || exit 1
777 chgrp -h -R wheel $DEST_DIR
778 chgrp -R wheel $DEST_DIR
780 # Done!
781 exit 0