+# Build the LLVM tree universal.
+mkdir -p $DIR/obj-llvm || exit 1
+cd $DIR/obj-llvm || exit 1
+
+if [ "$ARM_HOSTED_BUILD" = yes ]; then
+ # The cross-tools' build process expects to find an existing cross toolchain
+ # under names like 'arm-apple-darwin$DARWIN_VERS-as'; so make them.
+ rm -rf $DIR/bin || exit 1
+ mkdir $DIR/bin || exit 1
+ for prog in ar nm ranlib strip lipo ld as ; do
+ P=$DIR/bin/arm-apple-darwin$DARWIN_VERS-${prog}
+ T=`xcrun -sdk $SDKROOT -find ${prog}`
+ ln -s $T $DIR/bin/$prog
+ echo '#!/bin/sh' > $P || exit 1
+ echo 'exec '$T' "$@"' >> $P || exit 1
+ chmod a+x $P || exit 1
+ done
+ # Set up the links for clang.
+ for prog in clang clang++ ; do
+ P=$DIR/bin/arm-apple-darwin$DARWIN_VERS-${prog}
+ T=`xcrun -sdk $SDKROOT -find ${prog}`
+ ln -s $T $DIR/bin/$prog
+ echo '#!/bin/sh' > $P || exit 1
+ echo 'exec '$T' -arch armv7 -isysroot '${SDKROOT}' "$@"' >> $P || exit 1
+ chmod a+x $P || exit 1
+ done
+
+ PATH=$DIR/bin:$PATH
+
+ unset SDKROOT && \
+ $SRC_DIR/configure $COMMON_CONFIGURE_OPTS \
+ --enable-targets=arm \
+ --host=arm-apple-darwin10 \
+ --target=arm-apple-darwin10 \
+ --build=i686-apple-darwin10 \
+ --program-prefix="" \
+ || exit 1
+
+ if [ -n "$IPHONEOS_DEPLOYMENT_TARGET" ]; then
+ COMMON_MAKEFLAGS="$COMMON_MAKEFLAGS \
+ DEPLOYMENT_TARGET=-mios-version-min=$IPHONEOS_DEPLOYMENT_TARGET"
+ fi
+
+ make $JOBS_FLAG $COMMON_MAKEFLAGS SDKROOT= UNIVERSAL_ARCH="$HOSTS" \
+ CXXFLAGS="-DLLVM_VERSION_INFO='\" Apple Build #$LLVM_VERSION\"'"
+ if [ $? != 0 ] ; then
+ echo "error: LLVM 'make' failed!"
+ exit 1
+ fi
+
+else
+# not $ARM_HOSTED_BUILD
+
+ export CC=`xcrun -find clang`
+ export CXX=`xcrun -find clang++`
+
+ if [ "$IOS_SIM_BUILD" = yes ]; then
+ # Use a non-standard "darwin_sim" host triple to trigger a cross-build.
+ configure_opts="--enable-targets=x86 --host=i686-apple-darwin_sim \
+ --build=i686-apple-darwin10"
+ if [ -n "$IPHONEOS_DEPLOYMENT_TARGET" ]; then
+ COMMON_MAKEFLAGS="$COMMON_MAKEFLAGS \
+ DEPLOYMENT_TARGET=-mios-simulator-version-min=$IPHONEOS_DEPLOYMENT_TARGET"
+ fi
+ else
+ configure_opts="--enable-targets=arm,x86"
+ if [ -n "$MACOSX_DEPLOYMENT_TARGET" ]; then
+ COMMON_MAKEFLAGS="$COMMON_MAKEFLAGS \
+ DEPLOYMENT_TARGET=-mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
+ fi
+ fi
+
+ if [ $SDKROOT ]; then
+ CPPFLAGS="$CPPFLAGS -isysroot $SDKROOT"
+ fi
+ for host in $HOSTS; do :; done
+ CPPFLAGS="$CPPFLAGS -arch $host"
+
+ $SRC_DIR/configure $COMMON_CONFIGURE_OPTS $configure_opts \
+ --program-prefix="" \
+ CPPFLAGS="$CPPFLAGS" \
+ || exit 1
+
+ make $JOBS_FLAG $COMMON_MAKEFLAGS UNIVERSAL_ARCH="$HOSTS" \
+ CXXFLAGS="-DLLVM_VERSION_INFO='\" Apple Build #$LLVM_VERSION\"'"
+ if [ $? != 0 ] ; then
+ echo "error: LLVM 'make' failed!"
+ exit 1
+ fi
+fi