#!/bin/sh # # Copyright (C) 2012 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # This shell script is used to rebuild the llvm and clang binaries # for the Android NDK. # # include common function and variable definitions . `dirname $0`/prebuilt-common.sh PROGRAM_PARAMETERS=" " PROGRAM_DESCRIPTION=\ "Rebuild the LLVM prebuilt binaries for the Android NDK. Where is the location of toolchain sources, is the top-level NDK installation path and is the name of the toolchain to use (e.g. llvm-3.2)." RELEASE=`date +%Y%m%d` BUILD_OUT=/tmp/ndk-$USER/build/toolchain OPTION_BUILD_OUT= register_var_option "--build-out=" OPTION_BUILD_OUT "Set temporary build directory" # Note: platform API level 9 or higher is needed for proper C++ support PLATFORM=$DEFAULT_PLATFORM register_var_option "--platform=" PLATFORM "Specify platform name" GMP_VERSION=$DEFAULT_GMP_VERSION register_var_option "--gmp-version=" GMP_VERSION "Specify gmp version" PACKAGE_DIR= register_var_option "--package-dir=" PACKAGE_DIR "Create archive tarball in specific directory" WINE=wine register_var_option "--wine=" WINE "WINE needed to run llvm-config.exe for building mclinker with --mingw" POLLY=no do_polly_option () { POLLY=yes; } register_option "--with-polly" do_polly_option "Enable Polyhedral optimizations for LLVM" CHECK=no do_check_option () { CHECK=yes; } register_option "--check" do_check_option "Check LLVM" register_jobs_option register_canadian_option register_try64_option extract_parameters "$@" prepare_canadian_toolchain /tmp/ndk-$USER/build fix_option BUILD_OUT "$OPTION_BUILD_OUT" "build directory" setup_default_log_file $BUILD_OUT/config.log set_parameters () { SRC_DIR=`cd $1; pwd` NDK_DIR=`cd $2; pwd` TOOLCHAIN="$3" # Check source directory # if [ -z "$SRC_DIR" ] ; then echo "ERROR: Missing source directory parameter. See --help for details." exit 1 fi if [ ! -d "$SRC_DIR/$TOOLCHAIN/llvm" ] ; then echo "ERROR: Source directory does not contain llvm sources: $SRC_DIR/$TOOLCHAIN/llvm" exit 1 fi if [ -e "$SRC_DIR/$TOOLCHAIN/llvm/tools/polly" -a ! -h "$SRC_DIR/$TOOLCHAIN/llvm/tools/polly" ] ; then echo "ERROR: polly, if exist, needs to be a symbolic link: $SRC_DIR/$TOOLCHAIN/llvm/tools/polly" exit 1 fi GMP_SOURCE=$SRC_DIR/gmp/gmp-$GMP_VERSION.tar.bz2 if [ ! -f "$GMP_SOURCE" ] ; then echo "ERROR: Source directory does not contain gmp: $GMP_SOURCE" exit 1 fi log "Using source directory: $SRC_DIR" # Check NDK installation directory # if [ -z "$NDK_DIR" ] ; then echo "ERROR: Missing NDK directory parameter. See --help for details." exit 1 fi if [ ! -d "$NDK_DIR" ] ; then mkdir -p $NDK_DIR if [ $? != 0 ] ; then echo "ERROR: Could not create target NDK installation path: $NDK_DIR" exit 1 fi fi log "Using NDK directory: $NDK_DIR" # Check toolchain name # if [ -z "$TOOLCHAIN" ] ; then echo "ERROR: Missing toolchain name parameter. See --help for details." exit 1 fi } set_parameters $PARAMETERS prepare_target_build if [ "$PACKAGE_DIR" ]; then mkdir -p "$PACKAGE_DIR" fail_panic "Could not create package directory: $PACKAGE_DIR" fi set_toolchain_ndk $NDK_DIR $TOOLCHAIN if [ "$MINGW" != "yes" -a "$DARWIN" != "yes" ] ; then dump "Using C compiler: $CC" dump "Using C++ compiler: $CXX" fi rm -rf $BUILD_OUT mkdir -p $BUILD_OUT MAKE_FLAGS= if [ "$VERBOSE" = "yes" ]; then MAKE_FLAGS="VERBOSE=1" fi TOOLCHAIN_BUILD_PREFIX=$BUILD_OUT/prefix ARCH=$HOST_ARCH # Note that the following 2 flags only apply for BUILD_CC in canadian cross build CFLAGS_FOR_BUILD="-O2 -I$TOOLCHAIN_BUILD_PREFIX/include" LDFLAGS_FOR_BUILD="-L$TOOLCHAIN_BUILD_PREFIX/lib" # Eliminate dependency on libgcc_s_sjlj-1.dll and libstdc++-6.dll on cross builds if [ "$DARWIN" = "yes" -o "$MINGW" = "yes" ]; then LDFLAGS_FOR_BUILD=$LDFLAGS_FOR_BUILD" -static-libgcc -static-libstdc++" fi CFLAGS="$CFLAGS $CFLAGS_FOR_BUILD $HOST_CFLAGS" CXXFLAGS="$CXXFLAGS $CFLAGS_FOR_BUILD $HOST_CFLAGS" # polly doesn't look at CFLAGS ! LDFLAGS="$LDFLAGS $LDFLAGS_FOR_BUILD $HOST_LDFLAGS" export CC CXX CFLAGS CXXFLAGS LDFLAGS CFLAGS_FOR_BUILD LDFLAGS_FOR_BUILD REQUIRES_RTTI=1 ARCH if [ "$DARWIN" = "yes" ]; then # To stop /usr/bin/install -s calls strip on darwin binary export KEEP_SYMBOLS=1 # Disable polly for now POLLY=no fi if [ "$POLLY" = "yes" -a ! -d "$SRC_DIR/$TOOLCHAIN/polly" ] ; then dump "Disable polly because $SRC_DIR/$TOOLCHAIN/polly doesn't exist" POLLY=no fi EXTRA_CONFIG_FLAGS= rm -rf $SRC_DIR/$TOOLCHAIN/llvm/tools/polly if [ "$POLLY" = "yes" ]; then # crate symbolic link ln -s ../../polly $SRC_DIR/$TOOLCHAIN/llvm/tools # build polly dependencies unpack_archive "$GMP_SOURCE" "$BUILD_OUT" fail_panic "Couldn't unpack $SRC_DIR/gmp/gmp-$GMP_VERSION to $BUILD_OUT" GMP_BUILD_OUT=$BUILD_OUT/gmp-$GMP_VERSION cd $GMP_BUILD_OUT fail_panic "Couldn't cd into gmp build path: $GMP_BUILD_OUT" OLD_ABI="${ABI}" export ABI=$HOST_GMP_ABI # needed to build 32-bit on 64-bit host run ./configure \ --prefix=$TOOLCHAIN_BUILD_PREFIX \ --host=$ABI_CONFIGURE_HOST \ --build=$ABI_CONFIGURE_BUILD \ --disable-shared \ --disable-nls \ --enable-cxx fail_panic "Couldn't configure gmp" run make -j$NUM_JOBS fail_panic "Couldn't compile gmp" run make install fail_panic "Couldn't install gmp to $TOOLCHAIN_BUILD_PREFIX" ABI="$OLD_ABI" CLOOG_BUILD_OUT=$BUILD_OUT/cloog mkdir -p $CLOOG_BUILD_OUT && cd $CLOOG_BUILD_OUT fail_panic "Couldn't create cloog build path: $CLOOG_BUILD_OUT" run $SRC_DIR/$TOOLCHAIN/llvm/tools/polly/utils/cloog_src/configure \ --prefix=$TOOLCHAIN_BUILD_PREFIX \ --host=$ABI_CONFIGURE_HOST \ --build=$ABI_CONFIGURE_BUILD \ --with-gmp-prefix=$TOOLCHAIN_BUILD_PREFIX \ --disable-shared \ --disable-nls fail_panic "Couldn't configure cloog" run make -j$NUM_JOBS fail_panic "Couldn't compile cloog" run make install fail_panic "Couldn't install cloog to $TOOLCHAIN_BUILD_PREFIX" EXTRA_CONFIG_FLAGS="--with-cloog=$TOOLCHAIN_BUILD_PREFIX --with-isl=$TOOLCHAIN_BUILD_PREFIX" # Allow text relocs when linking LLVMPolly.dylib against statically linked libgmp.a if [ "$HOST_TAG32" = "darwin-x86" -o "$DARWIN" = "yes" ]; then # -a "$HOST_ARCH" = "x86" LDFLAGS="$LDFLAGS -read_only_relocs suppress" export LDFLAGS fi fi # POLLY = yes # configure the toolchain dump "Configure: $TOOLCHAIN toolchain build" LLVM_BUILD_OUT=$BUILD_OUT/llvm mkdir -p $LLVM_BUILD_OUT && cd $LLVM_BUILD_OUT fail_panic "Couldn't cd into llvm build path: $LLVM_BUILD_OUT" run $SRC_DIR/$TOOLCHAIN/llvm/configure \ --prefix=$TOOLCHAIN_BUILD_PREFIX \ --host=$ABI_CONFIGURE_HOST \ --build=$ABI_CONFIGURE_BUILD \ --with-bug-report-url=$DEFAULT_ISSUE_TRACKER_URL \ --enable-targets=arm,mips,x86 \ --enable-optimized \ --with-binutils-include=$SRC_DIR/binutils/binutils-$DEFAULT_BINUTILS_VERSION/include \ $EXTRA_CONFIG_FLAGS fail_panic "Couldn't configure llvm toolchain" # build llvm/clang dump "Building : llvm toolchain [this can take a long time]." cd $LLVM_BUILD_OUT run make -j$NUM_JOBS $MAKE_FLAGS fail_panic "Couldn't compile llvm toolchain" if [ "$CHECK" = "yes" -a "$MINGW" != "yes" -a "$DARWIN" != "yes" ] ; then # run the regression test dump "Running : llvm toolchain regression test" cd $LLVM_BUILD_OUT run make check-all fail_warning "Couldn't pass all llvm regression test" # change to fail_panic later if [ "$POLLY" = "yes" ]; then dump "Running : polly toolchain regression test" cd $LLVM_BUILD_OUT run make polly-test -C tools/polly/test fail_warning "Couldn't pass all polly regression test" # change to fail_panic later fi fi # install the toolchain to its final location dump "Install : llvm toolchain binaries" cd $LLVM_BUILD_OUT && run make install $MAKE_FLAGS fail_panic "Couldn't install llvm toolchain to $TOOLCHAIN_BUILD_PREFIX" # create llvm-config wrapper if needed. # llvm-config is invoked by other llvm projects (eg. mclinker/configure) # to figure out flags and libs dependencies. Unfortunately in canadian-build # llvm-config[.exe] may not run directly. Create a wrapper. LLVM_CONFIG=llvm-config if [ "$MINGW" = "yes" ] ; then LLVM_CONFIG=llvm-config.sh cat > $TOOLCHAIN_BUILD_PREFIX/bin/$LLVM_CONFIG < "${ANALYZER}" < "${ANALYZER}++" < "${ANALYZER}.cmd" < "${ANALYZER}++.cmd" <