• 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# Build the host version of the make executable and place it
18# at the right location
19
20PROGDIR=$(dirname $0)
21. $PROGDIR/prebuilt-common.sh
22
23PROGRAM_PARAMETERS=""
24PROGRAM_DESCRIPTION=\
25"Rebuild the host GNU Make tool used by the NDK."
26
27NDK_DIR=$ANDROID_NDK_ROOT
28register_var_option "--ndk-dir=<path>" NDK_DIR "Install to specific NDK directory"
29
30register_try64_option
31register_mingw_option
32register_jobs_option
33
34OUT=
35CUSTOM_OUT=
36register_option "--out=<file>" do_out "Specify output executable path" "$OUT"
37do_out () { CUSTOM_OUT=true; OUT=$1; }
38
39GNUMAKE=make
40register_var_option "--make=<path>" GNUMAKE "Specify GNU Make program for the build"
41
42PACKAGE_DIR=
43register_var_option "--package-dir=<path>" PACKAGE_DIR "Archive binaries into package directory"
44
45extract_parameters "$@"
46
47if [ -z "$CUSTOM_OUT" ]; then
48    SUBDIR=$(get_prebuilt_host_exec make)
49    OUT=$NDK_DIR/$SUBDIR
50    log "Auto-config: --out=$OUT"
51fi
52
53GNUMAKE_VERSION=3.81
54GNUMAKE_SRCDIR=$ANDROID_NDK_ROOT/sources/host-tools/make-$GNUMAKE_VERSION
55if [ ! -d "$GNUMAKE_SRCDIR" ]; then
56    echo "ERROR: Can't find make-$GNUMAKE_VERSION source tree: $GNUMAKE_SRCDIR"
57    exit 1
58fi
59
60log "Using sources from: $GNUMAKE_SRCDIR"
61
62prepare_host_build
63
64TMP_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...
69log "Copying sources to temporary directory: $TMP_SRCDIR"
70mkdir -p "$TMP_SRCDIR" && copy_directory "$GNUMAKE_SRCDIR" "$TMP_SRCDIR"
71fail_panic "Could not copy GNU Make sources to: $TMP_SRCDIR"
72
73BUILD_DIR=$NDK_TMPDIR/build
74
75CONFIGURE_FLAGS="--disable-nls --disable-rpath"
76if [ "$MINGW" = "yes" ]; then
77    # Required for a proper mingw compile
78    CONFIGURE_FLAGS=$CONFIGURE_FLAGS" --host=i586-pc-mingw32"
79fi
80
81log "Configuring the build"
82mkdir -p $BUILD_DIR && rm -rf $BUILD_DIR/*
83cd $BUILD_DIR &&
84CFLAGS=$HOST_CFLAGS" -O2 -s" &&
85export CC CFLAGS &&
86run $TMP_SRCDIR/configure $CONFIGURE_FLAGS
87fail_panic "Failed to configure the sed-$GNUMAKE_VERSION build!"
88
89log "Building make"
90run $GNUMAKE -j $NUM_JOBS
91fail_panic "Failed to build the sed-$GNUMAKE_VERSION executable!"
92
93log "Copying executable to prebuilt location"
94run mkdir -p $(dirname "$OUT") && cp $(get_host_exec_name make) $OUT
95fail_panic "Could not copy executable to: $OUT"
96
97if [ "$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"
103fi
104
105log "Cleaning up"
106rm -rf $BUILD_DIR $TMP_SRCDIR
107
108log "Done."
109