Home | History | Annotate | Download | only in toolbox
      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 shell script is used to rebuild the toolbox programs which sources
     18 #  are under $NDK/sources/host-tools/toolbox
     19 #
     20 
     21 # include common function and variable definitions
     22 . $NDK_BUILDTOOLS_PATH/prebuilt-common.sh
     23 . $NDK_BUILDTOOLS_PATH/builder-funcs.sh
     24 
     25 PROGRAM_PARAMETERS=""
     26 
     27 PROGRAM_DESCRIPTION=\
     28 "Rebuild the prebuilt host toolbox binaries for the Android NDK.
     29 
     30 These are simple command-line programs used by the NDK build script.
     31 
     32 By default, this will try to place the binaries inside the current NDK
     33 directory, unless you use the --ndk-dir=<path> option.
     34 "
     35 
     36 PACKAGE_DIR=
     37 register_var_option "--package-dir=<path>" PACKAGE_DIR "Put prebuilt tarballs into <path>."
     38 
     39 NDK_DIR=
     40 register_var_option "--ndk-dir=<path>" NDK_DIR "Specify NDK root path for the build."
     41 
     42 BUILD_DIR=
     43 OPTION_BUILD_DIR=
     44 register_var_option "--build-dir=<path>" OPTION_BUILD_DIR "Specify temporary build dir."
     45 
     46 NO_MAKEFILE=
     47 register_var_option "--no-makefile" NO_MAKEFILE "Do not use makefile to speed-up build"
     48 
     49 PACKAGE_DIR=
     50 register_var_option "--package-dir=<path>" PACKAGE_DIR "Archive binaries into package directory"
     51 
     52 register_jobs_option
     53 register_try64_option
     54 
     55 extract_parameters "$@"
     56 
     57 # Handle NDK_DIR
     58 if [ -z "$NDK_DIR" ] ; then
     59     NDK_DIR=$ANDROID_NDK_ROOT
     60     log "Auto-config: --ndk-dir=$NDK_DIR"
     61 else
     62     if [ ! -d "$NDK_DIR" ] ; then
     63         echo "ERROR: NDK directory does not exists: $NDK_DIR"
     64         exit 1
     65     fi
     66 fi
     67 
     68 if [ -z "$OPTION_BUILD_DIR" ]; then
     69     BUILD_DIR=$NDK_TMPDIR/build-toolbox
     70     log "Auto-config: --build-dir=$BUILD_DIR"
     71     rm -rf $BUILD_DIR/* && mkdir -p $BUILD_DIR
     72 else
     73     BUILD_DIR=$OPTION_BUILD_DIR
     74 fi
     75 mkdir -p "$BUILD_DIR"
     76 fail_panic "Could not create build directory: $BUILD_DIR"
     77 
     78 if [ -z "$NO_MAKEFILE" ]; then
     79     MAKEFILE=$BUILD_DIR/Makefile
     80 else
     81     MAKEFILE=
     82 fi
     83 
     84 TOOLBOX_SRCDIR=$ANDROID_NDK_ROOT/sources/host-tools/toolbox
     85 
     86 BUILD_WINDOWS_SOURCES=yes
     87 
     88 if [ "$BUILD_WINDOWS_SOURCES" ]; then
     89     ORIGINAL_HOST_TAG=$HOST_TAG
     90     MINGW=yes
     91     handle_canadian_build
     92     prepare_canadian_toolchain $BUILD_DIR
     93 
     94     SUBDIR=$(get_prebuilt_install_prefix $HOST_TAG)/bin
     95     DSTDIR=$NDK_DIR/$SUBDIR
     96     mkdir -p "$DSTDIR"
     97     fail_panic "Could not create destination directory: $DSTDIR"
     98 
     99     # Build echo.exe
    100     HOST_TAG=$ORIGINAL_HOST_TAG
    101     builder_begin_host "$BUILD_DIR" "$MAKEFILE"
    102     builder_set_srcdir "$TOOLBOX_SRCDIR"
    103     builder_set_dstdir "$DSTDIR"
    104     builder_sources echo_win.c
    105     builder_host_executable echo
    106     builder_end
    107 
    108     # Build cmp.exe
    109     HOST_TAG=$ORIGINAL_HOST_TAG
    110     builder_begin_host "$BUILD_DIR" "$MAKEFILE"
    111     builder_set_srcdir "$TOOLBOX_SRCDIR"
    112     builder_set_dstdir "$DSTDIR"
    113     builder_sources cmp_win.c
    114     builder_host_executable cmp
    115     builder_end
    116 
    117     if [ "$PACKAGE_DIR" ]; then
    118         ARCHIVE=toolbox-$HOST_TAG.tar.bz2
    119         dump "Packaging : $ARCHIVE"
    120         pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" "$SUBDIR/echo.exe" "$SUBDIR/cmp.exe"
    121         fail_panic "Could not package toolbox binaires"
    122     fi
    123 fi
    124