1 #!/bin/sh 2 # 3 # Copyright (C) 2011 The Android Open Source Project 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 # This script is used to rebuild the host 'ndk-depends' tool. 18 # 19 # Note: The tool is installed under prebuilt/$HOST_TAG/bin/ndk-depends 20 # by default. 21 # 22 PROGDIR=$(dirname $0) 23 . $NDK_BUILDTOOLS_PATH/prebuilt-common.sh 24 25 PROGRAM_PARAMETERS="" 26 PROGRAM_DESCRIPTION=\ 27 "This script is used to rebuild the host ndk-depends binary program." 28 29 register_jobs_option 30 31 OPTION_BUILD_DIR= 32 BUILD_DIR= 33 register_var_option "--build-dir=<path>" BUILD_DIR "Specify build directory" 34 35 NDK_DIR=$ANDROID_NDK_ROOT 36 register_var_option "--ndk-dir=<path>" NDK_DIR "Place binary in NDK installation path" 37 38 GNUMAKE= 39 register_var_option "--make=<path>" GNUMAKE "Specify GNU Make program" 40 41 DEBUG= 42 register_var_option "--debug" DEBUG "Build debug version" 43 44 SRC_DIR= 45 register_var_option "--src-dir=<path>" SRC_DIR "Specify binutils source dir. Must be set for --with-libbfd" 46 47 PACKAGE_DIR= 48 register_var_option "--package-dir=<path>" PACKAGE_DIR "Archive binary into specific directory" 49 50 register_canadian_option 51 register_try64_option 52 53 extract_parameters "$@" 54 55 prepare_abi_configure_build 56 prepare_host_build 57 58 # Choose a build directory if not specified by --build-dir 59 if [ -z "$BUILD_DIR" ]; then 60 BUILD_DIR=$NDK_TMPDIR/build-ndk-depends 61 log "Auto-config: --build-dir=$BUILD_DIR" 62 else 63 OPTION_BUILD_DIR="yes" 64 fi 65 66 rm -rf $BUILD_DIR 67 mkdir -p $BUILD_DIR 68 69 prepare_canadian_toolchain $BUILD_DIR 70 71 CFLAGS=$HOST_CFLAGS" -O2 -s -ffunction-sections -fdata-sections" 72 LDFLAGS=$HOST_LDFLAGS 73 EXTRA_CONFIG= 74 75 if [ "$HOST_OS" != "darwin" -a "$DARWIN" != "yes" ]; then 76 LDFLAGS=$LDFLAGS" -Wl,-gc-sections" 77 else 78 # In darwin libbfd has to be built with some *linux* target or it won't understand ELF 79 EXTRA_CONFIG="-target=arm-linux-androideabi" 80 fi 81 82 NAME=$(get_host_exec_name ndk-depends) 83 INSTALL_ROOT=$(mktemp -d $NDK_TMPDIR/ndk-depends-XXXXXX) 84 INSTALL_SUBDIR=host-tools/bin 85 INSTALL_PATH=$INSTALL_ROOT/$INSTALL_SUBDIR 86 OUT=$INSTALL_PATH/$NAME 87 mkdir $INSTALL_PATH 88 89 # GNU Make 90 if [ -z "$GNUMAKE" ]; then 91 GNUMAKE=make 92 log "Auto-config: --make=$GNUMAKE" 93 fi 94 95 if [ "$PACKAGE_DIR" ]; then 96 mkdir -p "$PACKAGE_DIR" 97 fail_panic "Could not create package directory: $PACKAGE_DIR" 98 fi 99 100 # Create output directory 101 mkdir -p $(dirname $OUT) 102 if [ $? != 0 ]; then 103 echo "ERROR: Could not create output directory: $(dirname $OUT)" 104 exit 1 105 fi 106 107 SRCDIR=$ANDROID_NDK_ROOT/sources/host-tools/ndk-depends 108 109 export CFLAGS LDFLAGS 110 run $GNUMAKE -C $SRCDIR -f $SRCDIR/GNUmakefile \ 111 -B -j$NUM_JOBS \ 112 PROGNAME="$OUT" \ 113 BUILD_DIR="$BUILD_DIR" \ 114 CC="$CC" CXX="$CXX" \ 115 STRIP="$STRIP" \ 116 DEBUG=$DEBUG 117 118 if [ $? != 0 ]; then 119 echo "ERROR: Could not build host program!" 120 exit 1 121 fi 122 123 if [ "$PACKAGE_DIR" ]; then 124 ARCHIVE=ndk-depends-$HOST_TAG.tar.bz2 125 dump "Packaging: $ARCHIVE" 126 pack_archive "$PACKAGE_DIR/$ARCHIVE" "$INSTALL_ROOT" "$INSTALL_SUBDIR" 127 fail_panic "Could not create package: $PACKAGE_DIR/$ARCHIVE from $OUT" 128 fi 129 130 if [ "$OPTION_BUILD_DIR" != "yes" ]; then 131 log "Cleaning up..." 132 rm -rf $BUILD_DIR 133 else 134 log "Don't forget to cleanup: $BUILD_DIR" 135 fi 136 137 log "Done!" 138 exit 0 139