Bring arm_mangle_type back, but use it for HF name mangling only.
[llvm-gcc-4.2.git] / build_gcc
blob9a4756679107c06aed9395c69d8c0a53fd15d221
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 else
147 # Use bootstrap SDK if it is available.
148 if [ -d /Developer/SDKs/Extra ]; then
149 ARM_SYSROOT=/Developer/SDKs/Extra
150 else
151 ARM_SYSROOT=/
153 ARM_PLATFORM=/
154 ARM_TOOLROOT=/
157 ARM_CONFIGFLAGS="$ARM_CONFIGFLAGS --with-build-sysroot=\"$ARM_SYSROOT\""
159 # If it's being built for iPhoneOS, assume the llvmCore bits are under
160 # iPhoneOS platform directory.
161 if [ "x$RC_ProjectName" = "xllvmgcc42_Embedded" ]; then
162 LLVMCORE_PATH="${ARM_PLATFORM}${LLVMCORE_PATH}"
163 DEST_ROOT="${ARM_PLATFORM}${DEST_ROOT}"
166 # If building an ARM target, check that the required directories exist
167 # and query the libSystem arm slices to determine which multilibs we should
168 # build.
169 if echo $TARGETS | grep arm; then
170 if [ ! -d $ARM_SYSROOT ]; then
171 echo "Error: cannot find ARM SDK to build ARM target"
172 exit 1
174 if [ ! -d $ARM_TOOLROOT ]; then
175 echo "Error: $ARM_TOOLROOT directory is not installed"
176 exit 1
178 if [ "x$ARM_MULTILIB_ARCHS" = "x" ] ; then
179 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/ $//'`
181 if [ "x$ARM_MULTILIB_ARCHS" == "x" ] ; then
182 echo "Error: missing ARM slices in $ARM_SYSROOT"
183 exit 1
184 else
185 export ARM_MULTILIB_ARCHS
188 # APPLE LOCAL end ARM
190 # LLVM LOCAL begin
191 # If the user has CC set in their environment unset it now
192 unset CC
193 # LLVM LOCAL end
195 ########################################
196 # Run the build.
198 # Create the source tree we'll actually use to build, deleting
199 # tcl since it doesn't actually build properly in a cross environment
200 # and we don't really need it.
201 SRC_DIR=$DIR/src
202 rm -rf $SRC_DIR || exit 1
203 mkdir $SRC_DIR || exit 1
204 ln -s $ORIG_SRC_DIR/* $SRC_DIR/ || exit 1
205 rm -rf $SRC_DIR/tcl $SRC_DIR/expect $SRC_DIR/dejagnu || exit 1
206 # Also remove libstdc++ since it is built from a separate project.
207 # LLVM LOCAL: The following line was commented out; uncomment it.
208 rm -rf $SRC_DIR/libstdc++-v3 || exit 1
209 # Clean out old specs files
210 rm -f /usr/lib/gcc/*/4.0.0/specs
212 # These are the configure and build flags that are used.
213 # LLVM LOCAL begin
214 if [ "x$LLVM_DEBUG" == "x" ]; then
215 CHECKING_FLAGS="--disable-checking --enable-werror"
216 else
217 CHECKING_FLAGS="--enable-checking"
220 CONFIGFLAGS="$CHECKING_FLAGS \
221 --prefix=$DEST_ROOT \
222 --mandir=\${prefix}/share/man \
223 --enable-languages=$LANGUAGES \
224 --program-prefix=llvm- \
225 --program-transform-name=/^[cg][^.-]*$/s/$/-$MAJ_VERS/ \
226 --with-slibdir=/usr/lib \
227 --build=$BUILD-apple-darwin$DARWIN_VERS"
229 if [ "$ENABLE_LLVM" == true ]; then
230 CONFIGFLAGS="$CONFIGFLAGS --enable-llvm=$LLVMCORE_PATH"
232 # LLVM LOCAL end
234 # Figure out how many make processes to run.
235 SYSCTL=`sysctl -n hw.activecpu`
237 # hw.activecpu only available in 10.2.6 and later
238 if [ -z "$SYSCTL" ]; then
239 SYSCTL=`sysctl -n hw.ncpu`
242 # sysctl -n hw.* does not work when invoked via B&I chroot /BuildRoot.
243 # Builders can default to 2, since even if they are single processor,
244 # nothing else is running on the machine.
245 if [ -z "$SYSCTL" ]; then
246 SYSCTL=2
249 # The $LOCAL_MAKEFLAGS variable can be used to override $MAKEFLAGS.
250 MAKEFLAGS=${LOCAL_MAKEFLAGS-"-j $SYSCTL"}
252 BUILD_CXX=0
253 for lang in `echo $LANGUAGES | sed 's/,/ /g'`; do
254 if [ $lang = "c++" -o $lang = "obj-c++" ]; then
255 BUILD_CXX=1
256 break
258 done
260 # Unset this, because GCC uses this variable in its makefiles
261 unset LANGUAGES
263 # LLVM LOCAL begin
264 if [ "$ENABLE_LLVM" == true ]; then
265 # Indicate the llvm-gcc is being built "Apple style".
266 MAKEFLAGS="$MAKEFLAGS BUILD_LLVM_APPLE_STYLE=1"
267 # Build llvm-gcc in 'dylib mode'.
268 MAKEFLAGS="$MAKEFLAGS BUILD_LLVM_INTO_A_DYLIB=1"
269 MAKEFLAGS="$MAKEFLAGS LLVM_VERSION_INFO=$LLVM_SUBMIT_VERSION"
271 # LLVM LOCAL end
273 # If the user has set CC or CXX, respect their wishes. If not,
274 # compile with LLVM-GCC/LLVM-G++ if available; if LLVM is not
275 # available, fall back to usual GCC/G++ default.
276 savedPATH=$PATH ; PATH="/Developer/usr/bin:$PATH"
277 XTMPCC=$(which llvm-gcc)
278 if [ x$CC = x -a x$XTMPCC != x ] ; then export CC=$XTMPCC forcedCC=1 ; fi
279 XTMPCC=$(which llvm-g++)
280 if [ x$CXX = x -a x$XTMPCC != x ] ; then export CXX=$XTMPCC forcedCXX=1 ; fi
281 PATH=$savedPATH
282 unset XTMPCC savedPATH
284 # Build the native GCC. Do this even if the user didn't ask for it
285 # because it'll be needed for the bootstrap.
286 mkdir -p $DIR/obj-$BUILD-$BUILD $DIR/dst-$BUILD-$BUILD || exit 1
287 cd $DIR/obj-$BUILD-$BUILD || exit 1
288 if [ \! -f Makefile ]; then
289 $SRC_DIR/configure $bootstrap $CONFIGFLAGS $NON_ARM_CONFIGFLAGS \
290 --host=$BUILD-apple-darwin$DARWIN_VERS \
291 --target=$BUILD-apple-darwin$DARWIN_VERS || exit 1
294 # Unset RC_DEBUG_OPTIONS because it causes the bootstrap to fail.
295 # Also keep unset for cross compilers so that the cross built libraries are
296 # comparable to the native built libraries.
297 unset RC_DEBUG_OPTIONS
298 make $MAKEFLAGS CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
299 make $MAKEFLAGS html CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
300 make $MAKEFLAGS DESTDIR=$DIR/dst-$BUILD-$BUILD install-gcc install-target \
301 CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
303 # Now that we've built a native compiler, un-kludge these so that
304 # subsequent cross-hosted compilers can be found normally.
305 if [ x$forcedCC != x ] ; then unset CC forcedCC ; fi
306 if [ x$forcedCXX != x ] ; then unset CXX forcedCXX ; fi
308 # Add the compiler we just built to the path, giving it appropriate names.
309 # LLVM LOCAL begin Support for non /usr $DEST_ROOT
310 D=$DIR/dst-$BUILD-$BUILD$DEST_ROOT/bin
311 ln -f $D/llvm-gcc $D/gcc || exit 1
312 ln -f $D/gcc $D/$BUILD-apple-darwin$DARWIN_VERS-gcc || exit 1
313 PATH=$DIR/dst-$BUILD-$BUILD$DEST_ROOT/bin:$PATH
314 # LLVM LOCAL end Support for non /usr $DEST_ROOT
316 # The cross-tools' build process expects to find certain programs
317 # under names like 'i386-apple-darwin$DARWIN_VERS-ar'; so make them.
318 # Annoyingly, ranlib changes behaviour depending on what you call it,
319 # so we have to use a shell script for indirection, grrr.
320 rm -rf $DIR/bin || exit 1
321 mkdir $DIR/bin || exit 1
322 for prog in ar nm ranlib strip lipo ld ; do
323 for t in `echo $TARGETS $HOSTS | sort -u`; do
324 P=$DIR/bin/${t}-apple-darwin$DARWIN_VERS-${prog}
325 # APPLE LOCAL begin toolroot
326 if [ $t = "arm" ]; then
327 toolroot=$ARM_TOOLROOT
328 else
329 toolroot=
331 # APPLE LOCAL end toolroot
332 echo '#!/bin/sh' > $P || exit 1
333 # APPLE LOCAL insert toolroot below
334 echo 'exec '${toolroot}'/usr/bin/'${prog}' "$@"' >> $P || exit 1
335 chmod a+x $P || exit 1
336 done
337 done
338 for t in `echo $1 $2 | sort -u`; do
339 gt=`echo $t | $TRANSLATE_ARCH`
340 P=$DIR/bin/${gt}-apple-darwin$DARWIN_VERS-as
341 # APPLE LOCAL begin toolroot
342 if [ $gt = "arm" ]; then
343 toolroot=$ARM_TOOLROOT
344 else
345 toolroot=
347 # APPLE LOCAL end toolroot
348 echo '#!/bin/sh' > $P || exit 1
350 # APPLE LOCAL insert toolroot below
351 echo 'for a; do case $a in -arch) exec '${toolroot}'/usr/bin/as "$@";; esac; done' >> $P || exit 1
352 echo 'exec '${toolroot}'/usr/bin/as -arch '${t}' "$@"' >> $P || exit 1
353 chmod a+x $P || exit 1
354 done
355 PATH=$DIR/bin:$PATH
357 # Determine which cross-compilers we should build. If our build architecture is
358 # one of our hosts, add all of the targets to the list.
359 if echo $HOSTS | grep $BUILD
360 then
361 CROSS_TARGETS=`echo $TARGETS $HOSTS | tr ' ' '\n' | sort -u`
362 else
363 CROSS_TARGETS="$HOSTS"
366 # Build the cross-compilers, using the compiler we just built.
367 for t in $CROSS_TARGETS ; do
368 if [ $t != $BUILD ] ; then
369 mkdir -p $DIR/obj-$BUILD-$t $DIR/dst-$BUILD-$t || exit 1
370 cd $DIR/obj-$BUILD-$t || exit 1
371 if [ \! -f Makefile ]; then
372 # APPLE LOCAL begin ARM ARM_CONFIGFLAGS
373 T_CONFIGFLAGS="$CONFIGFLAGS --enable-werror-always \
374 --program-prefix=$t-apple-darwin$DARWIN_VERS- \
375 --host=$BUILD-apple-darwin$DARWIN_VERS \
376 --target=$t-apple-darwin$DARWIN_VERS"
377 if [ $t = 'arm' ] ; then
378 # Explicitly set AS_FOR_TARGET and LD_FOR_TARGET to avoid picking up
379 # older versions from the gcc installed in /usr. Radar 7230843.
380 AS_FOR_TARGET=$DIR/bin/${t}-apple-darwin$DARWIN_VERS-as \
381 LD_FOR_TARGET=$DIR/bin/${t}-apple-darwin$DARWIN_VERS-ld \
382 $SRC_DIR/configure $T_CONFIGFLAGS $ARM_CONFIGFLAGS || exit 1
383 else
384 $SRC_DIR/configure $T_CONFIGFLAGS $NON_ARM_CONFIGFLAGS || exit 1
386 # APPLE LOCAL end ARM ARM_CONFIGFLAGS
388 make $MAKEFLAGS all CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
389 make $MAKEFLAGS DESTDIR=$DIR/dst-$BUILD-$t install-gcc install-target \
390 CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
392 # Add the compiler we just built to the path.
393 # LLVM LOCAL Support for non /usr $DEST_ROOT
394 PATH=$DIR/dst-$BUILD-$t/$DEST_ROOT/bin:$PATH
396 done
398 # Rearrange various libraries, for no really good reason.
399 for t in $CROSS_TARGETS ; do
400 DT=$DIR/dst-$BUILD-$t
401 # LLVM LOCAL Support for non /usr $DEST_ROOT
402 D=`echo $DT/$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS`
403 mv $D/static/libgcc.a $D/libgcc_static.a || exit 1
404 mv $D/kext/libgcc.a $D/libcc_kext.a || exit 1
405 rm -r $D/static $D/kext || exit 1
406 # glue together kext64 stuff
407 if [ -e $D/kext64/libgcc.a ]; then
408 libtool -static $D/{kext64/libgcc.a,libcc_kext.a} -o $D/libcc_kext1.a 2>&1 | grep -v 'has no symbols'
409 mv $D/libcc_kext1.a $D/libcc_kext.a
410 rm -rf $D/kext64
412 done
414 # Build the cross-hosted compilers.
415 for h in $HOSTS ; do
416 if [ $h != $BUILD ] ; then
417 for t in $TARGETS ; do
418 mkdir -p $DIR/obj-$h-$t $DIR/dst-$h-$t || exit 1
419 cd $DIR/obj-$h-$t || exit 1
420 if [ $h = $t ] ; then
422 else
423 pp=$t-apple-darwin$DARWIN_VERS-
426 if [ \! -f Makefile ]; then
427 # APPLE LOCAL begin ARM ARM_CONFIGFLAGS
428 T_CONFIGFLAGS="$CONFIGFLAGS --program-prefix=$pp \
429 --host=$h-apple-darwin$DARWIN_VERS \
430 --target=$t-apple-darwin$DARWIN_VERS"
431 if [ $t = 'arm' ] && [ $h != 'arm' ] ; then
432 T_CONFIGFLAGS="$T_CONFIGFLAGS $ARM_CONFIGFLAGS"
433 else
434 T_CONFIGFLAGS="$T_CONFIGFLAGS $NON_ARM_CONFIGFLAGS"
436 $SRC_DIR/configure $T_CONFIGFLAGS || exit 1
437 # APPLE LOCAL end ARM ARM_CONFIGFLAGS
440 # For ARM, we need to make sure it picks up the ARM_TOOLROOT versions
441 # of the linker and cctools.
442 if [ $t = 'arm' ] ; then
443 ORIG_COMPILER_PATH=$COMPILER_PATH
444 export COMPILER_PATH=$ARM_TOOLROOT/usr/bin:$COMPILER_PATH
447 if [ $h = $t ] ; then
448 make $MAKEFLAGS all CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
449 make $MAKEFLAGS DESTDIR=$DIR/dst-$h-$t install-gcc install-target \
450 CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
451 else
452 make $MAKEFLAGS all-gcc CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
453 make $MAKEFLAGS DESTDIR=$DIR/dst-$h-$t install-gcc \
454 CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" || exit 1
457 if [ $t = 'arm' ] ; then
458 export COMPILER_PATH=$ORIG_COMPILER_PATH
459 unset ORIG_COMPILER_PATH
461 done
463 done
465 ########################################
466 # Construct the actual destination root, by copying stuff from
467 # $DIR/dst-* to $DEST_DIR, with occasional 'lipo' commands.
469 cd $DEST_DIR || exit 1
471 # Clean out DEST_DIR in case -noclean was passed to buildit.
472 rm -rf * || exit 1
474 # LLVM LOCAL begin Don't install HTML docs.
475 if [ "$ENABLE_LLVM" == false ]; then
476 # HTML documentation
477 HTMLDIR="/Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.DeveloperTools.docset/Contents/Resources/Documents/documentation/DeveloperTools"
478 mkdir -p ".$HTMLDIR" || exit 1
479 cp -Rp $DIR/obj-$BUILD-$BUILD/gcc/HTML/* ".$HTMLDIR/" || exit 1
481 # LLVM LOCAL end Don't install docs.
483 # Manual pages
484 mkdir -p .$DEST_ROOT/share || exit 1
485 cp -Rp $DIR/dst-$BUILD-$BUILD$DEST_ROOT/share/man .$DEST_ROOT/share/ \
486 || exit 1
487 # exclude fsf-funding.7 gfdl.7 gpl.7 as they are currently built in
488 # the gcc project
489 rm -rf .$DEST_ROOT/share/man/man7
491 # libexec
492 cd $DIR/dst-$BUILD-$BUILD$DEST_ROOT/libexec/gcc/$BUILD-apple-darwin$DARWIN_VERS/$VERS \
493 || exit 1
494 LIBEXEC_FILES=`find . -type f -print || exit 1`
495 LIBEXEC_DIRS=`find . -type d -print || exit 1`
496 cd $DEST_DIR || exit 1
497 for t in $TARGETS ; do
498 DL=$DEST_ROOT/libexec/gcc/$t-apple-darwin$DARWIN_VERS/$VERS
499 for d in $LIBEXEC_DIRS ; do
500 mkdir -p .$DL/$d || exit 1
501 done
502 for f in $LIBEXEC_FILES ; do
503 # LLVM LOCAL
504 if file $DIR/dst-*-$t$DL/$f | grep -q -E 'Mach-O (executable|dynamically linked shared library)' ; then
505 lipo -output .$DL/$f -create $DIR/dst-*-$t$DL/$f || exit 1
506 else
507 cp -p $DIR/dst-$BUILD-$t$DL/$f .$DL/$f || exit 1
509 done
510 # LLVM LOCAL begin fix broken link
511 ln -s ../../../../../bin/as .$DL/as
512 ln -s ../../../../../bin/ld .$DL/ld
513 # LLVM LOCAL end fix broken link
514 done
516 # bin
517 # The native drivers ('native' is different in different architectures).
518 # LLVM LOCAL begin
519 mkdir .$DEST_ROOT/bin
520 cpp_files=`ls $DIR/dst-*$DEST_ROOT/bin/{llvm-cpp,cpp-$MAJ_VERS} 2>/dev/null`
521 lipo -output .$DEST_ROOT/bin/llvm-cpp-$MAJ_VERS -create $cpp_files || exit 1
522 # LLVM LOCAL end
524 # gcov, which is special only because it gets built multiple times and lipo
525 # will complain if we try to add two architectures into the same output.
526 TARG0=`echo $TARGETS | cut -d ' ' -f 1`
527 lipo -output .$DEST_ROOT/bin/gcov-$MAJ_VERS -create \
528 $DIR/dst-*-$TARG0$DEST_ROOT/bin/*gcov* || exit 1
529 # The fully-named drivers, which have the same target on every host.
530 for t in $TARGETS ; do
531 # LLVM LOCAL build_gcc bug with non-/usr $DEST_ROOT
532 lipo -output .$DEST_ROOT/bin/$t-apple-darwin$DARWIN_VERS-llvm-gcc-$MAJ_VERS -create \
533 $DIR/dst-*-$t/$DEST_ROOT/bin/$t-apple-darwin$DARWIN_VERS-gcc-$VERS || exit 1
534 # LLVM LOCAL build_gcc bug with non-/usr $DEST_ROOT
535 lipo -output .$DEST_ROOT/bin/$t-apple-darwin$DARWIN_VERS-llvm-g++-$MAJ_VERS -create \
536 $DIR/dst-*-$t/$DEST_ROOT/bin/$t-apple-darwin$DARWIN_VERS-*g++* || exit 1
537 done
539 # lib
540 mkdir -p .$DEST_ROOT/lib/gcc || exit 1
541 for t in $TARGETS ; do
542 # LLVM LOCAL build_gcc bug with non-/usr $DEST_ROOT
543 cp -Rp $DIR/dst-$BUILD-$t/$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS \
544 .$DEST_ROOT/lib/gcc || exit 1
545 done
547 # APPLE LOCAL begin native compiler support
548 # libgomp is not built for ARM
549 LIBGOMP_TARGETS=`echo $TARGETS | sed -E -e 's/(^|[[:space:]])arm($|[[:space:]])/ /'`
550 LIBGOMP_HOSTS=`echo $HOSTS | $OMIT_X86_64 | sed -E -e 's/(^|[[:space:]])arm($|[[:space:]])/ /'`
552 # And copy libgomp stuff by hand...
553 for t in $LIBGOMP_TARGETS ; do
554 for h in $LIBGOMP_HOSTS ; do
555 if [ $h = $t ] ; then
556 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/libgomp.a \
557 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/ || exit 1
558 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/libgomp.spec \
559 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/ || exit 1
560 if [ $h = 'powerpc' ] ; then
561 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/ppc64/libgomp.a \
562 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/ppc64/
563 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/ppc64/libgomp.spec \
564 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/ppc64/
565 elif [ $h = 'i686' ] ; then
566 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/x86_64/libgomp.a \
567 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/x86_64/ || exit 1
568 cp -p $DIR/dst-$h-$t$DEST_ROOT/lib/x86_64/libgomp.spec \
569 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/x86_64/ || exit 1
572 done
573 done
574 # APPLE LOCAL end native compiler support
576 if [ $BUILD_CXX -eq 1 ]; then
577 for t in $TARGETS ; do
578 if [ "$t" == 'arm' ] ; then
579 cp -p $ARM_SYSROOT/usr/lib/libstdc++.6.dylib \
580 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/libstdc++.dylib \
581 || exit 1
582 else
583 cp -p /usr/lib/libstdc++.6.dylib \
584 .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/libstdc++.dylib \
585 || exit 1
587 # LLVM LOCAL
588 # strip -x -c .$DEST_ROOT/lib/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/libstdc++.dylib || exit 1
589 done
592 # include
593 HEADERPATH=$DEST_ROOT/include/gcc/darwin/$MAJ_VERS
594 mkdir -p .$HEADERPATH || exit 1
596 # Some headers are installed from more-hdrs/. They all share
597 # one common feature: they shouldn't be installed here. Sometimes,
598 # they should be part of FSF GCC and installed from there; sometimes,
599 # they should be installed by some completely different package; sometimes,
600 # they only exist for codewarrior compatibility and codewarrior should provide
601 # its own. We take care not to install the headers if Libc is already
602 # providing them.
603 cd $SRC_DIR/more-hdrs
604 for h in `echo *.h` ; do
605 if [ ! -f /usr/include/$h -o -L /usr/include/$h ] ; then
606 cp -R $h $DEST_DIR$HEADERPATH/$h || exit 1
607 for t in $TARGETS ; do
608 THEADERPATH=$DEST_DIR$DEST_ROOT/lib/gcc/${t}-apple-darwin$DARWIN_VERS/$VERS/include
609 [ -f $THEADERPATH/$h ] || \
610 ln -s ../../../../../include/gcc/darwin/$MAJ_VERS/$h $THEADERPATH/$h || \
611 exit 1
612 done
614 done
616 # Add extra man page symlinks for 'c++' and for arch-specific names.
617 MDIR=$DEST_DIR$DEST_ROOT/share/man/man1
618 if [ $BUILD_CXX -eq 1 ]; then
619 # LLVM LOCAL
620 ln -f $MDIR/llvm-g++.1 $MDIR/llvm-c++.1 || exit 1
622 for t in $TARGETS ; do
623 # LLVM LOCAL begin
624 ln -f $MDIR/llvm-gcc.1 $MDIR/$t-apple-darwin$DARWIN_VERS-llvm-gcc.1 \
625 || exit 1
626 if [ $BUILD_CXX -eq 1 ]; then
627 ln -f $MDIR/llvm-g++.1 $MDIR/$t-apple-darwin$DARWIN_VERS-llvm-g++.1 \
628 || exit 1
630 # LLVM LOCAL end
631 done
633 # LLVM LOCAL begin
634 # Compress manpages
635 gzip -f $MDIR/*
637 if [ "x$RC_ProjectName" = "xllvmgcc42_Embedded" ]; then
638 MAN1_DIR=${DEST_DIR}${ARM_PLATFORM}/Developer/usr/share/man/man1
639 else
640 MAN1_DIR=$DEST_DIR/Developer/usr/share/man/man1
642 mkdir -p ${MAN1_DIR}
643 cp $ORIG_SRC_DIR/gcc/doc/llvm-gcc.1 ${MAN1_DIR}/llvm-gcc.1
644 cp $ORIG_SRC_DIR/gcc/doc/llvm-gcc.1 ${MAN1_DIR}/llvm-g++.1
645 gzip -f ${MAN1_DIR}/llvm-gcc.1
646 gzip -f ${MAN1_DIR}/llvm-g++.1
647 # LLVM LOCAL end
649 # Build driver-driver using fully-named drivers
650 for h in $HOSTS ; do
651 # LLVM LOCAL begin
652 $h-apple-darwin$DARWIN_VERS-gcc \
653 $ORIG_SRC_DIR/driverdriver.c \
654 -DPDN="\"-apple-darwin$DARWIN_VERS-llvm-gcc-$MAJ_VERS\"" \
655 -DIL="\"$DEST_ROOT/bin/\"" -I $ORIG_SRC_DIR/include \
656 -I $ORIG_SRC_DIR/gcc -I $ORIG_SRC_DIR/gcc/config \
657 -liberty -L$DIR/dst-$BUILD-$h$DEST_ROOT/lib/ \
658 -L$DIR/dst-$BUILD-$h$DEST_ROOT/$h-apple-darwin$DARWIN_VERS/lib/ \
659 -L$DIR/obj-$h-$BUILD/libiberty/ \
660 -o $DEST_DIR/$DEST_ROOT/bin/tmp-$h-llvm-gcc-$MAJ_VERS || exit 1
662 if [ $BUILD_CXX -eq 1 ]; then
663 $h-apple-darwin$DARWIN_VERS-gcc \
664 $ORIG_SRC_DIR/driverdriver.c \
665 -DPDN="\"-apple-darwin$DARWIN_VERS-llvm-g++-$MAJ_VERS\"" \
666 -DIL="\"$DEST_ROOT/bin/\"" -I $ORIG_SRC_DIR/include \
667 -I $ORIG_SRC_DIR/gcc -I $ORIG_SRC_DIR/gcc/config \
668 -liberty -L$DIR/dst-$BUILD-$h$DEST_ROOT/lib/ \
669 -L$DIR/dst-$BUILD-$h$DEST_ROOT/$h-apple-darwin$DARWIN_VERS/lib/ \
670 -L$DIR/obj-$h-$BUILD/libiberty/ \
671 -o $DEST_DIR/$DEST_ROOT/bin/tmp-$h-llvm-g++-$MAJ_VERS || exit 1
673 # LLVM LOCAL end
674 done
676 # LLVM LOCAL begin
677 lipo -output $DEST_DIR/$DEST_ROOT/bin/llvm-gcc-$MAJ_VERS -create \
678 $DEST_DIR/$DEST_ROOT/bin/tmp-*-llvm-gcc-$MAJ_VERS || exit 1
679 rm $DEST_DIR/$DEST_ROOT/bin/tmp-*-llvm-gcc-$MAJ_VERS || exit 1
681 if [ $BUILD_CXX -eq 1 ]; then
682 lipo -output $DEST_DIR/$DEST_ROOT/bin/llvm-g++-$MAJ_VERS -create \
683 $DEST_DIR/$DEST_ROOT/bin/tmp-*-llvm-g++-$MAJ_VERS || exit 1
684 ln -f $DEST_DIR/$DEST_ROOT/bin/llvm-g++-$MAJ_VERS $DEST_DIR/$DEST_ROOT/bin/llvm-c++-$MAJ_VERS || exit 1
685 rm $DEST_DIR/$DEST_ROOT/bin/tmp-*-llvm-g++-$MAJ_VERS || exit 1
687 # LLVM LOCAL end
689 ########################################
690 # Create SYM_DIR with information required for debugging.
692 cd $SYM_DIR || exit 1
694 # Clean out SYM_DIR in case -noclean was passed to buildit.
695 rm -rf * || exit 1
697 # Generate .dSYM files
698 find $DEST_DIR -perm -0111 \! -name fixinc.sh \
699 \! -name mkheaders -type f -print | xargs -n 1 -P ${SYSCTL} dsymutil
701 # Save .dSYM files and .a archives
702 cd $DEST_DIR || exit 1
703 find . \( -path \*.dSYM/\* -or -name \*.a \) -print \
704 | cpio -pdml $SYM_DIR || exit 1
705 # Save source files.
706 mkdir $SYM_DIR/src || exit 1
707 cd $DIR || exit 1
708 find obj-* -name \*.\[chy\] -print | cpio -pdml $SYM_DIR/src || exit 1
710 ########################################
711 # Remove debugging information from DEST_DIR.
713 if [ "x$LLVM_DEBUG" != "x1" ]; then
714 # LLVM LOCAL begin - don't strip dSYM objects
715 find $DEST_DIR -perm -0111 \! -path '*DWARF*' \! -name \*.dylib \
716 \! -name fixinc.sh \! -name mkheaders \! -name libstdc++.dylib \
717 -type f -print \
718 | xargs strip || exit 1
719 # LLVM LOCAL begin - Strip with -Sx instead of -SX
720 find $DEST_DIR \! -path '*DWARF*' \( -name \*.a -or -name \*.dylib \) \
721 \! -name libgcc_s.10.*.dylib \! -name libstdc++.dylib -type f \
722 -print \
723 | xargs strip -SX || exit 1
724 # LLVM LOCAL end - Strip with -Sx instead of -SX
725 find $DEST_DIR \! -path '*DWARF*' -name \*.a -type f -print \
726 | xargs ranlib || exit 1
727 # LLVM LOCAL end - don't strip dSYM objects
730 # LLVM LOCAL begin
731 # Set up the llvm-gcc/llvm-g++ symlinks.
733 # LLVM_BIN_DIR - This is the place where llvm-gcc/llvm-g++ symlinks get installed.
734 LLVM_BIN_DIR=$DEST_ROOT/../bin
736 mkdir -p $DEST_DIR$LLVM_BIN_DIR
737 cd $DEST_DIR$LLVM_BIN_DIR
738 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-gcc-$MAJ_VERS llvm-gcc-$MAJ_VERS || exit 1
739 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-g++-$MAJ_VERS llvm-g++-$MAJ_VERS || exit 1
740 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-cpp-$MAJ_VERS llvm-cpp-$MAJ_VERS || exit 1
741 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-gcc-$MAJ_VERS llvm-gcc || exit 1
742 ln -s -f ../llvm-gcc-$MAJ_VERS/bin/llvm-g++-$MAJ_VERS llvm-g++ || exit 1
744 # FIXME: This is a hack to get things working.
745 for t in $TARGETS ; do
746 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
747 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
748 done
750 # Copy one of the libllvmgcc.dylib's up to libexec/gcc.
751 cp $DEST_DIR/$DEST_ROOT/libexec/gcc/$BUILD-apple-darwin$DARWIN_VERS/$VERS/libllvmgcc.dylib \
752 $DEST_DIR/$DEST_ROOT/libexec/gcc/
754 # Replace the installed ones with symlinks to the common one.
755 for t in $TARGETS ; do
756 cd $DEST_DIR/$DEST_ROOT/libexec/gcc/$t-apple-darwin$DARWIN_VERS/$VERS/
757 rm libllvmgcc.dylib
758 ln -s ../../libllvmgcc.dylib
759 done
761 if [ "x$RC_ProjectName" == "xllvmgcc42_Embedded" ]; then
762 if [ "x$LLVM_BUILT_ROOTS" == "x" ]; then
763 mkdir -p $DEST_DIR${ARM_PLATFORM}/usr/bin
764 cd $DEST_DIR${ARM_PLATFORM}/usr/bin
765 ln -s ${ARM_PLATFORM}/Developer/usr/bin/llvm-gcc-4.2 llvm-gcc-4.2
766 ln -s ${ARM_PLATFORM}/Developer/usr/bin/llvm-g++-4.2 llvm-g++-4.2
768 else
769 if [ "x$LLVM_BUILT_ROOTS" == "x" ]; then
770 mkdir -p $DEST_DIR/usr/bin
771 cd $DEST_DIR/usr/bin
772 ln -s /Developer/usr/bin/llvm-gcc-4.2 llvm-gcc-4.2
773 ln -s /Developer/usr/bin/llvm-g++-4.2 llvm-g++-4.2
777 # Remove unwind.h from the install directory for > 10.6
778 if [ $DARWIN_VERS -gt 10 ]; then
779 find $DEST_DIR -name "unwind.h" -print | xargs rm || exit 1
782 # LLVM LOCAL end
784 find $DEST_DIR -name \*.dSYM -print | xargs rm -r || exit 1
785 chgrp -h -R wheel $DEST_DIR
786 chgrp -R wheel $DEST_DIR
788 # Done!
789 exit 0