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