Home | History | Annotate | Download | only in tools
      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 # Build the host version of the make executable and place it
     18 # at the right location
     19 
     20 PROGDIR=$(dirname $0)
     21 . $PROGDIR/prebuilt-common.sh
     22 
     23 PROGRAM_PARAMETERS=""
     24 PROGRAM_DESCRIPTION=\
     25 "Rebuild the host GNU Make tool used by the NDK."
     26 
     27 NDK_DIR=$ANDROID_NDK_ROOT
     28 register_var_option "--ndk-dir=<path>" NDK_DIR "Install to specific NDK directory"
     29 
     30 register_try64_option
     31 register_canadian_option
     32 register_jobs_option
     33 
     34 OUT=
     35 CUSTOM_OUT=
     36 register_option "--out=<file>" do_out "Specify output executable path" "$OUT"
     37 do_out () { CUSTOM_OUT=true; OUT=$1; }
     38 
     39 GNUMAKE=make
     40 register_var_option "--make=<path>" GNUMAKE "Specify GNU Make program for the build"
     41 
     42 PACKAGE_DIR=
     43 register_var_option "--package-dir=<path>" PACKAGE_DIR "Archive binaries into package directory"
     44 
     45 extract_parameters "$@"
     46 
     47 if [ -z "$CUSTOM_OUT" ]; then
     48     SUBDIR=$(get_prebuilt_host_exec make)
     49     OUT=$NDK_DIR/$SUBDIR
     50     log "Auto-config: --out=$OUT"
     51 fi
     52 
     53 GNUMAKE_VERSION=3.81
     54 GNUMAKE_SRCDIR=$ANDROID_NDK_ROOT/sources/host-tools/make-$GNUMAKE_VERSION
     55 if [ ! -d "$GNUMAKE_SRCDIR" ]; then
     56     echo "ERROR: Can't find make-$GNUMAKE_VERSION source tree: $GNUMAKE_SRCDIR"
     57     exit 1
     58 fi
     59 
     60 log "Using sources from: $GNUMAKE_SRCDIR"
     61 
     62 prepare_abi_configure_build
     63 prepare_host_build
     64 
     65 TMP_SRCDIR=$NDK_TMPDIR/src
     66 
     67 # We need to copy the sources to a temporary directory because
     68 # the build system will modify some documentation files in the
     69 # source directory. Sigh...
     70 log "Copying sources to temporary directory: $TMP_SRCDIR"
     71 mkdir -p "$TMP_SRCDIR" && copy_directory "$GNUMAKE_SRCDIR" "$TMP_SRCDIR"
     72 fail_panic "Could not copy GNU Make sources to: $TMP_SRCDIR"
     73 
     74 BUILD_DIR=$NDK_TMPDIR/build
     75 
     76 CONFIGURE_FLAGS="--disable-nls --disable-rpath"
     77 if [ "$MINGW" = "yes" ]; then
     78     # Required for a proper mingw cross compile
     79     CONFIGURE_FLAGS=$CONFIGURE_FLAGS" --host=i586-pc-mingw32"
     80 fi
     81 
     82 if [ "$DARWIN" = "yes" ]; then
     83     # Required for a proper darwin cross compile
     84     CONFIGURE_FLAGS=$CONFIGURE_FLAGS" --host=$ABI_CONFIGURE_HOST"
     85 fi
     86 
     87 log "Configuring the build"
     88 mkdir -p $BUILD_DIR && rm -rf $BUILD_DIR/*
     89 prepare_canadian_toolchain $BUILD_DIR
     90 cd $BUILD_DIR &&
     91 CFLAGS=$HOST_CFLAGS" -O2 -s" &&
     92 export CC CFLAGS &&
     93 run $TMP_SRCDIR/configure $CONFIGURE_FLAGS --build=$ABI_CONFIGURE_BUILD
     94 fail_panic "Failed to configure the make-$GNUMAKE_VERSION build!"
     95 
     96 log "Building make"
     97 run $GNUMAKE -j $NUM_JOBS
     98 fail_panic "Failed to build the make-$GNUMAKE_VERSION executable!"
     99 
    100 log "Copying executable to prebuilt location"
    101 run mkdir -p $(dirname "$OUT") && cp $(get_host_exec_name make) $OUT
    102 fail_panic "Could not copy executable to: $OUT"
    103 
    104 if [ "$PACKAGE_DIR" ]; then
    105     ARCHIVE=ndk-make-$HOST_TAG.tar.bz2
    106     dump "Packaging: $ARCHIVE"
    107     mkdir -p "$PACKAGE_DIR" &&
    108     pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" "$SUBDIR"
    109     fail_panic "Could not package archive: $PACKAGE_DIR/$ARCHIVE"
    110 fi
    111 
    112 log "Cleaning up"
    113 rm -rf $BUILD_DIR $TMP_SRCDIR
    114 
    115 log "Done."
    116