• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 script is used to rebuild the host 'ndk-stack' tool from the
18# sources under sources/host-tools/ndk-stack.
19#
20# Note: The tool is installed under prebuilt/$HOST_TAG/bin/ndk-stack
21#       by default.
22#
23PROGDIR=$(dirname $0)
24. $PROGDIR/prebuilt-common.sh
25
26PROGRAM_PARAMETERS=""
27PROGRAM_DESCRIPTION=\
28"This script is used to rebuild the host ndk-stack binary program."
29
30register_jobs_option
31
32BUILD_DIR=
33register_var_option "--build-dir=<path>" BUILD_DIR "Specify build directory"
34
35NDK_DIR=$ANDROID_NDK_ROOT
36register_var_option "--ndk-dir=<path>" NDK_DIR "Place binary in NDK installation path"
37
38GNUMAKE=
39register_var_option "--make=<path>" GNUMAKE "Specify GNU Make program"
40
41DEBUG=
42register_var_option "--debug" DEBUG "Build debug version"
43
44PACKAGE_DIR=
45register_var_option "--package-dir=<path>" PACKAGE_DIR "Archive binary into specific directory"
46
47register_mingw_option
48register_try64_option
49
50extract_parameters "$@"
51
52prepare_host_build
53
54# Choose a build directory if not specified by --build-dir
55if [ -z "$BUILD_DIR" ]; then
56    BUILD_DIR=$NDK_TMPDIR/build-ndk-stack
57    log "Auto-config: --build-dir=$BUILD_DIR"
58fi
59prepare_mingw_toolchain $BUILD_DIR
60
61OUT=$NDK_DIR/$(get_host_exec_name ndk-stack)
62
63# GNU Make
64if [ -z "$GNUMAKE" ]; then
65    GNUMAKE=make
66    log "Auto-config: --make=$GNUMAKE"
67fi
68
69if [ "$PACKAGE_DIR" ]; then
70    mkdir -p "$PACKAGE_DIR"
71    fail_panic "Could not create package directory: $PACKAGE_DIR"
72fi
73
74PROGNAME=ndk-stack
75if [ "$MINGW" = "yes" ]; then
76    PROGNAME=$PROGNAME.exe
77fi
78
79# Create output directory
80mkdir -p $(dirname $OUT)
81if [ $? != 0 ]; then
82    echo "ERROR: Could not create output directory: $(dirname $OUT)"
83    exit 1
84fi
85
86SRCDIR=$ANDROID_NDK_ROOT/sources/host-tools/ndk-stack
87
88# Let's roll
89run $GNUMAKE -C $SRCDIR -f $SRCDIR/GNUMakefile \
90    -B -j$NUM_JOBS \
91    PROGNAME="$OUT" \
92    BUILD_DIR="$BUILD_DIR" \
93    CC="$CXX" CXX="$CXX" \
94    STRIP="$STRIP" \
95    DEBUG=$DEBUG
96
97if [ $? != 0 ]; then
98    echo "ERROR: Could not build host program!"
99    exit 1
100fi
101
102if [ "$PACKAGE_DIR" ]; then
103    ARCHIVE=ndk-stack-$HOST_TAG.tar.bz2
104    SUBDIR=$(get_host_exec_name ndk-stack $HOST_TAG)
105    dump "Packaging: $ARCHIVE"
106    pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" "$SUBDIR"
107    fail_panic "Could not create package: $PACKAGE_DIR/$ARCHIVE from $OUT"
108fi
109
110log "Done!"
111exit 0
112