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 awk 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 awk tool used by the NDK."
     26 
     27 register_try64_option
     28 register_canadian_option
     29 register_jobs_option
     30 
     31 NDK_DIR=$ANDROID_NDK_ROOT
     32 register_var_option "--ndk-dir=<path>" NDK_DIR "Specify NDK install directory"
     33 
     34 PACKAGE_DIR=
     35 register_var_option "--package-dir=<path>" PACKAGE_DIR "Archive to package directory"
     36 
     37 GNUMAKE=make
     38 register_var_option "--make=<path>" GNUMAKE "Specify GNU Make program"
     39 
     40 extract_parameters "$@"
     41 
     42 SUBDIR=$(get_prebuilt_host_exec awk)
     43 OUT=$NDK_DIR/$SUBDIR
     44 
     45 AWK_VERSION=20071023
     46 AWK_SRCDIR=$ANDROID_NDK_ROOT/sources/host-tools/nawk-$AWK_VERSION
     47 if [ ! -d "$AWK_SRCDIR" ]; then
     48     echo "ERROR: Can't find nawk-$AWK_VERSION source tree: $AWK_SRCDIR"
     49     exit 1
     50 fi
     51 
     52 log "Using sources from: $AWK_SRCDIR"
     53 
     54 prepare_host_build
     55 
     56 BUILD_DIR=$NDK_TMPDIR
     57 BUILD_MINGW=
     58 if [ "$MINGW" = "yes" ]; then
     59   BUILD_MINGW=yes
     60 fi
     61 if [ "$TRY64" = "yes" ]; then
     62   BUILD_TRY64=yes
     63 fi
     64 V=0
     65 if [ "$VERBOSE2" = "yes" ]; then
     66   V=1
     67 fi
     68 
     69 log "Configuring the build"
     70 mkdir -p $BUILD_DIR && rm -rf $BUILD_DIR/*
     71 prepare_canadian_toolchain $BUILD_DIR
     72 log "Building $HOST_TAG awk"
     73 export HOST_CC="$CC" &&
     74 export CFLAGS=$HOST_CFLAGS" -O2 -s" &&
     75 export LDFLAGS=$HOST_LDFLAGS &&
     76 export NATIVE_CC="gcc" &&
     77 export NATIVE_CFLAGS=" -O2 -s -I$BUILD_DIR -I." &&
     78 export NATIVE_LDFLAGS= &&
     79 run $GNUMAKE \
     80     -C "$AWK_SRCDIR" \
     81     -j $NUM_JOBS \
     82     BUILD_DIR="$BUILD_DIR" \
     83     MINGW="$BUILD_MINGW" \
     84     TRY64="$BUILD_TRY64" \
     85     V="$V"
     86 fail_panic "Failed to build the awk-$AWK_VERSION executable!"
     87 
     88 log "Copying executable to prebuilt location"
     89 run mkdir -p $(dirname "$OUT") && cp "$BUILD_DIR/$(get_host_exec_name ndk-awk)" "$OUT"
     90 fail_panic "Could not copy executable to: $OUT"
     91 
     92 if [ "$PACKAGE_DIR" ]; then
     93     ARCHIVE=ndk-awk-$HOST_TAG.tar.bz2
     94     dump "Packaging: $ARCHIVE"
     95     mkdir -p "$PACKAGE_DIR" &&
     96     pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" "$SUBDIR"
     97     fail_panic "Could not package archive: $PACKAGE_DIR/$ARCHIVE"
     98 fi
     99 
    100 log "Cleaning up"
    101 rm -rf $BUILD_DIR
    102 
    103 log "Done."
    104 
    105