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. $NDK_BUILDTOOLS_PATH/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_canadian_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_abi_configure_build
63prepare_host_build
64
65TMP_SRCDIR=$NDK_TMPDIR/src
66
67# We need to copy the sources to a temporary directory because
68# the build system will modify some documentation files in the
69# source directory. Sigh...
70log "Copying sources to temporary directory: $TMP_SRCDIR"
71mkdir -p "$TMP_SRCDIR" && copy_directory "$GNUMAKE_SRCDIR" "$TMP_SRCDIR"
72fail_panic "Could not copy GNU Make sources to: $TMP_SRCDIR"
73
74BUILD_DIR=$NDK_TMPDIR/build
75
76CONFIGURE_FLAGS="--disable-nls --disable-rpath"
77if [ "$MINGW" = "yes" ]; then
78    # Required for a proper mingw cross compile
79    CONFIGURE_FLAGS=$CONFIGURE_FLAGS" --host=i586-pc-mingw32"
80fi
81
82if [ "$DARWIN" = "yes" ]; then
83    # Required for a proper darwin cross compile
84    CONFIGURE_FLAGS=$CONFIGURE_FLAGS" --host=$ABI_CONFIGURE_HOST"
85fi
86
87log "Configuring the build"
88mkdir -p $BUILD_DIR && rm -rf $BUILD_DIR/*
89prepare_canadian_toolchain $BUILD_DIR
90cd $BUILD_DIR &&
91CFLAGS=$HOST_CFLAGS" -O2 -s" &&
92export CC CFLAGS &&
93run $TMP_SRCDIR/configure $CONFIGURE_FLAGS --build=$ABI_CONFIGURE_BUILD
94fail_panic "Failed to configure the make-$GNUMAKE_VERSION build!"
95
96log "Building make"
97run $GNUMAKE -j $NUM_JOBS
98fail_panic "Failed to build the make-$GNUMAKE_VERSION executable!"
99
100log "Copying executable to prebuilt location"
101run mkdir -p $(dirname "$OUT") && cp $(get_host_exec_name make) $OUT
102fail_panic "Could not copy executable to: $OUT"
103
104if [ "$PACKAGE_DIR" ]; then
105    ARCHIVE=ndk-make-$HOST_TAG.tar.bz2
106    dump "Packaging: $ARCHIVE"
107    mkdir -p "$PACKAGE_DIR" &&
108    pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" "$SUBDIR"
109    fail_panic "Could not package archive: $PACKAGE_DIR/$ARCHIVE"
110fi
111
112log "Cleaning up"
113rm -rf $BUILD_DIR $TMP_SRCDIR
114
115log "Done."
116