• 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#
18# This script is used internally to re-build the toolchains and NDK.
19# This is an engineer's tool... definitely not a production tool. Don't expect it to be
20# flawelss... at least at this revision.
21
22# Revamp of the 'ndk-buil.sh' based on feedback and NDK build
23# processes used by Google to generate the NDK>
24
25# Comment out the remote Mac OS X builds as it is currently
26# non-functional due to a change in AOSP
27# 3592767ce5ca9431eea728370c99d97aadb0800e
28
29# include common function and variable definitions
30. `dirname $0`/prebuilt-common.sh
31PROGDIR=`dirname $0`
32PROGDIR=`cd $PROGDIR && pwd`
33
34
35# Name of this NDK release
36OPTION_NDK_RELEASE=`date +%Y%m%d`
37register_var_option "--release=<rel_name>" OPTION_NDK_RELEASE "Version of release"
38
39# Should we only Build for Linux platform?
40OPTION_QUICK_BUILD="no"
41register_var_option "--quick" OPTION_QUICK_BUILD "Only build the Linux basics"
42
43ARCHS=$(find_ndk_unknown_archs)
44ARCHS="$DEFAULT_ARCHS $ARCHS"
45register_var_option "--arch=<arch>" ARCHS "Specify target architectures"
46
47# List of toolchains to package
48GCC_VERSION_LIST="default" # it's arch defined by default so use default keyword
49register_var_option "--gcc-version-list=<vers>" GCC_VERSION_LIST "List of GCC release versions"
50
51LLVM_VERSION_LIST=$DEFAULT_LLVM_VERSION_LIST
52register_var_option "--llvm-version-list=<vers>" LLVM_VERSION_LIST "List of LLVM release versions"
53
54OPTION_SRC_DIR=
55register_var_option "--toolchain-src-dir=<path>" OPTION_SRC_DIR "Select toolchain source directory"
56
57OPTION_TRY_64=
58register_try64_option
59
60OPTION_ALSO_64=
61register_option "--also-64" do_ALSO_64 "Also build 64-bit host toolchain"
62do_ALSO_64 () { OPTION_ALSO_64=" --also-64"; }
63
64OPTION_SEPARATE_64=
65register_option "--separate-64" do_SEPARATE_64 "Separate 64-bit host toolchain to its own package"
66do_SEPARATE_64 ()
67{
68    if [ "$TRY64" = "yes" ]; then
69        echo "ERROR: You cannot use both --try-64 and --separate-64 at the same time."
70        exit 1
71    fi
72    OPTION_SEPARATE_64=" --separate-64";
73}
74# # Name of the Mac OS Build host
75# MAC_BUILD_HOST="macdroid"
76# register_var_option "--mac-host=<name>" MAC_BUILD_HOST "Hostname of the Mac OS X system"
77
78PROGRAM_PARAMETERS=""
79PROGRAM_DESCRIPTION=\
80"Generate the NDK toolchain package."
81
82extract_parameters "$@"
83
84if [ "$TRY64" = "yes" ]; then
85    OPTION_TRY_64=" --try-64"
86fi
87
88TOP=$PWD
89TODAY=`date '+%Y%m%d'`
90PACKAGE_DIR=$TOP/ndk-release-$TODAY
91HOST_OS=`uname -s | tr '[:upper:]' '[:lower:]'`
92# Set the list of Build Targets based on this Host OS
93case "$HOST_OS" in
94linux )
95    # Build for Local Linux and Cross-compile for Windows (MINGW)
96    if [ "$OPTION_QUICK_BUILD" = "yes" ]; then
97       BUILD_TARGET_PLATFORMS="linux-x86"
98    else
99       BUILD_TARGET_PLATFORMS="linux-x86 windows"
100    fi
101    ;;
102darwin )
103    # Build for Local Mac OS X
104    BUILD_TARGET_PLATFORMS="darwin-x86"
105    ;;
106esac
107
108#export ANDROID_NDK_ROOT=$TOP/ndk
109#export PATH=$PATH:$ANDROID_NDK_ROOT/build/tools
110export VERBOSE=--verbose
111
112# If BUILD_NUM_CPUS is not already defined in your environment,
113# define it as the double of HOST_NUM_CPUS. This is used to
114# run make commands in parallel, as in 'make -j$BUILD_NUM_CPUS'
115#
116if [ -z "$BUILD_NUM_CPUS" ] ; then
117    if [ -e /proc/cpuinfo ] ; then
118        HOST_NUM_CPUS=`cat /proc/cpuinfo | grep -c processor`
119        export BUILD_NUM_CPUS=$(($HOST_NUM_CPUS * 2 * 8 / 10))
120    elif [ -e /usr/sbin/sysctl ] ; then
121        HOST_NUM_CPUS=`/usr/sbin/sysctl -n hw.ncpu`
122        export BUILD_NUM_CPUS=$(($HOST_NUM_CPUS * 2 * 8 / 10))
123    else
124        export BUILD_NUM_CPUS=1
125        echo "WARNING: Could not find Host Number CPUs; defaulting to BUILD_NUM_CPUS=${BUILD_NUM_CPUS}"
126    fi
127fi
128
129# CLEAN
130rm -rf /tmp/ndk-$USER/{build,tmp}
131
132
133#######################################
134# Get the Toolchain sources
135#######################################
136
137# Create a sha1 for any additional patches
138PATCHES_SHA1=""
139if [ -d "$PROGDIR/toolchain-patches" ]
140then
141    PATCHES_SHA1=`( find $PROGDIR/toolchain-patches -type f -print ) | \
142        sort -f | xargs cat | git hash-object --stdin | cut -c1-7`
143    PATCHES_SHA1="+${PATCHES_SHA1}"
144fi
145
146echo
147echo "Checking for Toolchain sources"
148if [ -z "$OPTION_SRC_DIR" ]
149then
150    OPTION_SRC_DIR=/tmp/ndk-$USER/src/android-ndk-src-${TOOLCHAIN_GIT_DATE}${PATCHES_SHA1}
151fi
152if [ ! -d $OPTION_SRC_DIR ]
153then
154    echo "  Downloading Toolchain sources"
155    mkdir -p `dirname $OPTION_SRC_DIR`
156    logfile="$TOP/download-toolchain-sources.log"
157    rotate_log $logfile
158    $PROGDIR/download-toolchain-sources.sh $OPTION_SRC_DIR \
159        > $logfile 2>&1
160    fail_panic "Could not download toolchain sources!"
161else
162    echo "  Found existing $OPTION_SRC_DIR"
163fi
164
165# Build the platform
166echo
167echo "Build the ndk/platforms directory"
168logfile="$TOP/gen-platforms.log"
169rotate_log $logfile
170$PROGDIR/gen-platforms.sh \
171    $VERBOSE \
172    --arch=$(spaces_to_commas $ARCHS)  \
173    --minimal \
174    --fast-copy > $logfile 2>&1
175fail_panic "gen-platforms.sh failed. Logfile in $logfile"
176
177logfile="$TOP/rebuild-all.log"
178rotate_log $logfile
179
180# Rebuild all prebuilts for archs and platforms
181for TARGET_PLATFORM in ${BUILD_TARGET_PLATFORMS}
182do
183    # Set the Arch specific variables
184    case "$TARGET_PLATFORM" in
185    linux-x86 )
186        TARGET_PLATFORM_OS="Linux"
187        TARGET_PLATFORM_FLAGS="--systems=$TARGET_PLATFORM"
188        ;;
189    windows )
190        TARGET_PLATFORM_OS="Windows"
191        TARGET_PLATFORM_FLAGS="--systems=$TARGET_PLATFORM"
192        # Skip this Target Platform in Quick Build Mode
193        if [ "$OPTION_QUICK_BUILD" = "yes" ]; then break ; fi
194        ;;
195    darwin-x86 )
196        TARGET_PLATFORM_OS="Mac OS X"
197        TARGET_PLATFORM_FLAGS=""
198#        TARGET_PLATFORM_FLAGS="--darwin-ssh=$MAC_BUILD_HOST"
199#        # Skip this Target Platform in Quick Build Mode
200#        if [ "$OPTION_QUICK_BUILD" = "yes" ]; then break ; fi
201        ;;
202    esac
203
204    # Rebuilt all prebuilts for the arch type
205    echo
206    echo "Rebuilding the toolchain and prebuilt tarballs for $TARGET_PLATFORM_OS"
207    cd $TOP
208    $PROGDIR/rebuild-all-prebuilt.sh \
209        --arch=$(spaces_to_commas $ARCHS)  \
210        --package-dir=$PACKAGE_DIR \
211        --gcc-version-list="$GCC_VERSION_LIST" \
212        --llvm-version-list="$LLVM_VERSION_LIST" \
213        $MPFR_VERSION $GDB_VERSION $BINUTILS_VERSION \
214        $TARGET_PLATFORM_FLAGS \
215        $VERBOSE \
216        $OPTION_TRY_64 \
217        $OPTION_ALSO_64 \
218        $OPTION_SRC_DIR >> $logfile 2>&1
219    fail_panic "rebuild-all-prebuilt.sh failed. Logfile in $logfile"
220done # with TARGET_PLATFORM
221
222ALL_SYSTEMS=`echo ${BUILD_TARGET_PLATFORMS}`
223
224echo
225echo "Building the NDK release"
226cd $TOP
227logfile="$TOP/package-release.log"
228rotate_log $logfile
229$PROGDIR/package-release.sh \
230    --prebuilt-dir=$PACKAGE_DIR \
231    --systems="$ALL_SYSTEMS" \
232    --out-dir=$PACKAGE_DIR \
233    --arch=$(spaces_to_commas $ARCHS)  \
234    --gcc-version-list="$GCC_VERSION_LIST" \
235    --llvm-version-list="$LLVM_VERSION_LIST" \
236    --prefix=android-ndk-${OPTION_NDK_RELEASE} \
237    $OPTION_TRY_64 \
238    $OPTION_SEPARATE_64 \
239    $VERBOSE > $logfile 2>&1
240fail_panic "package-release.sh failed. Logfile in $logfile"
241
242echo
243echo "Packaging the NDK Toolchain sources"
244NDK_TOOLCHAIN_PKG=${PACKAGE_DIR}/toolchain-src.tar.bz2
245(cd $OPTION_SRC_DIR && tar cjf $NDK_TOOLCHAIN_PKG .)
246fail_panic "Could not package NDK Toolchain sources!"
247
248exit 0
249
250