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# 22PROGDIR=$(dirname $0) 23. $NDK_BUILDTOOLS_PATH/prebuilt-common.sh 24 25PROGRAM_PARAMETERS="" 26PROGRAM_DESCRIPTION=\ 27"This script is used to rebuild the host ndk-depends binary program." 28 29register_jobs_option 30 31OPTION_BUILD_DIR= 32BUILD_DIR= 33register_var_option "--build-dir=<path>" BUILD_DIR "Specify build directory" 34 35NDK_DIR=$ANDROID_NDK_ROOT 36register_var_option "--ndk-dir=<path>" NDK_DIR "Place binary in NDK installation path" 37 38GNUMAKE= 39register_var_option "--make=<path>" GNUMAKE "Specify GNU Make program" 40 41DEBUG= 42register_var_option "--debug" DEBUG "Build debug version" 43 44SRC_DIR= 45register_var_option "--src-dir=<path>" SRC_DIR "Specify binutils source dir. Must be set for --with-libbfd" 46 47PACKAGE_DIR= 48register_var_option "--package-dir=<path>" PACKAGE_DIR "Archive binary into specific directory" 49 50register_canadian_option 51register_try64_option 52 53extract_parameters "$@" 54 55prepare_abi_configure_build 56prepare_host_build 57 58# Choose a build directory if not specified by --build-dir 59if [ -z "$BUILD_DIR" ]; then 60 BUILD_DIR=$NDK_TMPDIR/build-ndk-depends 61 log "Auto-config: --build-dir=$BUILD_DIR" 62else 63 OPTION_BUILD_DIR="yes" 64fi 65 66rm -rf $BUILD_DIR 67mkdir -p $BUILD_DIR 68 69prepare_canadian_toolchain $BUILD_DIR 70 71CFLAGS=$HOST_CFLAGS" -O2 -s -ffunction-sections -fdata-sections" 72LDFLAGS=$HOST_LDFLAGS 73EXTRA_CONFIG= 74 75if [ "$HOST_OS" != "darwin" -a "$DARWIN" != "yes" ]; then 76 LDFLAGS=$LDFLAGS" -Wl,-gc-sections" 77else 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" 80fi 81 82NAME=$(get_host_exec_name ndk-depends) 83INSTALL_ROOT=$(mktemp -d $NDK_TMPDIR/ndk-depends-XXXXXX) 84INSTALL_SUBDIR=host-tools/bin 85INSTALL_PATH=$INSTALL_ROOT/$INSTALL_SUBDIR 86OUT=$INSTALL_PATH/$NAME 87mkdir $INSTALL_PATH 88 89# GNU Make 90if [ -z "$GNUMAKE" ]; then 91 GNUMAKE=make 92 log "Auto-config: --make=$GNUMAKE" 93fi 94 95if [ "$PACKAGE_DIR" ]; then 96 mkdir -p "$PACKAGE_DIR" 97 fail_panic "Could not create package directory: $PACKAGE_DIR" 98fi 99 100# Create output directory 101mkdir -p $(dirname $OUT) 102if [ $? != 0 ]; then 103 echo "ERROR: Could not create output directory: $(dirname $OUT)" 104 exit 1 105fi 106 107SRCDIR=$ANDROID_NDK_ROOT/sources/host-tools/ndk-depends 108 109export CFLAGS LDFLAGS 110run $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 118if [ $? != 0 ]; then 119 echo "ERROR: Could not build host program!" 120 exit 1 121fi 122 123if [ "$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" 128fi 129 130if [ "$OPTION_BUILD_DIR" != "yes" ]; then 131 log "Cleaning up..." 132 rm -rf $BUILD_DIR 133else 134 log "Don't forget to cleanup: $BUILD_DIR" 135fi 136 137log "Done!" 138exit 0 139