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_mingw_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_host_build
     63 
     64 TMP_SRCDIR=$NDK_TMPDIR/src
     65 
     66 # We need to copy the sources to a temporary directory because
     67 # the build system will modify some documentation files in the
     68 # source directory. Sigh...
     69 log "Copying sources to temporary directory: $TMP_SRCDIR"
     70 mkdir -p "$TMP_SRCDIR" && copy_directory "$GNUMAKE_SRCDIR" "$TMP_SRCDIR"
     71 fail_panic "Could not copy GNU Make sources to: $TMP_SRCDIR"
     72 
     73 BUILD_DIR=$NDK_TMPDIR/build
     74 
     75 CONFIGURE_FLAGS="--disable-nls --disable-rpath"
     76 if [ "$MINGW" = "yes" ]; then
     77     # Required for a proper mingw compile
     78     CONFIGURE_FLAGS=$CONFIGURE_FLAGS" --host=i586-pc-mingw32"
     79 fi
     80 
     81 log "Configuring the build"
     82 mkdir -p $BUILD_DIR && rm -rf $BUILD_DIR/*
     83 cd $BUILD_DIR &&
     84 CFLAGS=$HOST_CFLAGS" -O2 -s" &&
     85 export CC CFLAGS &&
     86 run $TMP_SRCDIR/configure $CONFIGURE_FLAGS
     87 fail_panic "Failed to configure the sed-$GNUMAKE_VERSION build!"
     88 
     89 log "Building make"
     90 run $GNUMAKE -j $NUM_JOBS
     91 fail_panic "Failed to build the sed-$GNUMAKE_VERSION executable!"
     92 
     93 log "Copying executable to prebuilt location"
     94 run mkdir -p $(dirname "$OUT") && cp $(get_host_exec_name make) $OUT
     95 fail_panic "Could not copy executable to: $OUT"
     96 
     97 if [ "$PACKAGE_DIR" ]; then
     98     ARCHIVE=ndk-make-$HOST_TAG.tar.bz2
     99     dump "Packaging: $ARCHIVE"
    100     mkdir -p "$PACKAGE_DIR" &&
    101     pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" "$SUBDIR"
    102     fail_panic "Could not package archive: $PACKAGE_DIR/$ARCHIVE"
    103 fi
    104 
    105 log "Cleaning up"
    106 rm -rf $BUILD_DIR $TMP_SRCDIR
    107 
    108 log "Done."
    109