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 43# List of toolchains to package 44OPTION_TOOLCHAINS="$DEFAULT_ARCH_TOOLCHAIN_NAME_arm,$DEFAULT_ARCH_TOOLCHAIN_NAME_x86,$DEFAULT_ARCH_TOOLCHAIN_NAME_mips" 45register_var_option "--toolchains=<toolchain[,toolchain]>" OPTION_TOOLCHAINS "Toolchain(s) to package" 46 47# # Name of the Mac OS Build host 48# MAC_BUILD_HOST="macdroid" 49# register_var_option "--mac-host=<name>" MAC_BUILD_HOST "Hostname of the Mac OS X system" 50 51PROGRAM_PARAMETERS="" 52PROGRAM_DESCRIPTION=\ 53"Generate the NDK toolchain package." 54 55extract_parameters "$@" 56 57TOP=$PWD 58TODAY=`date '+%Y%m%d'` 59PACKAGE_DIR=$TOP/ndk-release-$TODAY 60HOST_OS=`uname -s | tr '[:upper:]' '[:lower:]'` 61# Set the list of Build Targets based on this Host OS 62case "$HOST_OS" in 63linux ) 64 # Build for Local Linux and Cross-compile for Windows (MINGW) 65 if [ "$OPTION_QUICK_BUILD" = "yes" ]; then 66 BUILD_TARGET_PLATFORMS="linux-x86" 67 else 68 BUILD_TARGET_PLATFORMS="linux-x86 windows" 69 fi 70 ;; 71darwin ) 72 # Build for Local Mac OS X 73 BUILD_TARGET_PLATFORMS="darwin-x86" 74 ;; 75esac 76 77#export ANDROID_NDK_ROOT=$TOP/ndk 78#export PATH=$PATH:$ANDROID_NDK_ROOT/build/tools 79export VERBOSE=--verbose 80 81# If BUILD_NUM_CPUS is not already defined in your environment, 82# define it as the double of HOST_NUM_CPUS. This is used to 83# run make commands in parallel, as in 'make -j$BUILD_NUM_CPUS' 84# 85if [ -z "$BUILD_NUM_CPUS" ] ; then 86 if [ -e /proc/cpuinfo ] ; then 87 HOST_NUM_CPUS=`cat /proc/cpuinfo | grep -c processor` 88 export BUILD_NUM_CPUS=$(($HOST_NUM_CPUS * 2 * 8 / 10)) 89 elif [ -e /usr/sbin/sysctl ] ; then 90 HOST_NUM_CPUS=`/usr/sbin/sysctl -n hw.ncpu` 91 export BUILD_NUM_CPUS=$(($HOST_NUM_CPUS * 2 * 8 / 10)) 92 else 93 export BUILD_NUM_CPUS=1 94 echo "WARNING: Could not find Host Number CPUs; defaulting to BUILD_NUM_CPUS=${BUILD_NUM_CPUS}" 95 fi 96fi 97 98# CLEAN 99rm -rf /tmp/ndk-$USER/{build,tmp} 100 101 102####################################### 103# Get the Toolchain sources 104####################################### 105 106# Create a sha1 for any additional patches 107PATCHES_SHA1="" 108if [ -d "$PROGDIR/toolchain-patches" ] 109then 110 PATCHES_SHA1=`( find $PROGDIR/toolchain-patches -type f -print ) | \ 111 sort -f | xargs cat | git hash-object --stdin | cut -c1-7` 112 PATCHES_SHA1="+${PATCHES_SHA1}" 113fi 114 115echo 116echo "Checking for Toolchain sources" 117NDK_SRC_DIR=/tmp/ndk-$USER/src/android-ndk-src-${TOOLCHAIN_GIT_DATE}${PATCHES_SHA1} 118if [ ! -d $NDK_SRC_DIR ] 119then 120 echo " Downloading Toolchain sources" 121 mkdir -p `dirname $NDK_SRC_DIR` 122 logfile="$TOP/download-toolchain-sources.log" 123 rotate_log $logfile 124 $PROGDIR/download-toolchain-sources.sh $NDK_SRC_DIR \ 125 > $logfile 2>&1 126 fail_panic "Could not download toolchain sources!" 127else 128 echo " Found existing $NDK_SRC_DIR" 129fi 130 131 132ARCHS="arm x86 mips" 133for ARCH in $ARCHS 134do 135 # Set the Arch specific variables 136 case "$ARCH" in 137 arm ) 138 PRODUCT=generic 139 140 unset MPFR_VERSION 141 unset GDB_VERSION 142 unset BINUTILS_VERSION 143 ;; 144 x86|mips ) 145 PRODUCT=generic_$ARCH 146 ;; 147 esac 148 149 150 # Ensure we have a Product output for the NDK build 151 export ANDROID_PRODUCT_OUT=$TOP/out/target/product/$PRODUCT 152 if [ ! -d $ANDROID_PRODUCT_OUT ]; then 153 echo >&2 Rebuild for $PRODUCT first... or change PRODUCT in $0. 154 exit 1 155 fi 156done # with ARCH 157 158# Build the platform 159echo 160echo "Build the ndk/platforms directory" 161logfile="$TOP/build-platforms.log" 162rotate_log $logfile 163$PROGDIR/gen-platforms.sh \ 164 $VERBOSE \ 165 --arch=$(spaces_to_commas $ARCHS) \ 166 --minimal \ 167 --fast-copy > $logfile 2>&1 168fail_panic "build-platforms.sh failed. Logfile in $logfile" 169 170logfile="$TOP/rebuild-all.log" 171rotate_log $logfile 172 173# Rebuild all prebuilts for archs and platforms 174for TARGET_PLATFORM in ${BUILD_TARGET_PLATFORMS} 175do 176 # Set the Arch specific variables 177 case "$TARGET_PLATFORM" in 178 linux-x86 ) 179 TARGET_PLATFORM_OS="Linux" 180 TARGET_PLATFORM_FLAGS="--systems=$TARGET_PLATFORM" 181 ;; 182 windows ) 183 TARGET_PLATFORM_OS="Windows" 184 TARGET_PLATFORM_FLAGS="--systems=$TARGET_PLATFORM" 185 # Skip this Target Platform in Quick Build Mode 186 if [ "$OPTION_QUICK_BUILD" = "yes" ]; then break ; fi 187 ;; 188 darwin-x86 ) 189 TARGET_PLATFORM_OS="Mac OS X" 190 TARGET_PLATFORM_FLAGS="" 191# TARGET_PLATFORM_FLAGS="--darwin-ssh=$MAC_BUILD_HOST" 192# # Skip this Target Platform in Quick Build Mode 193# if [ "$OPTION_QUICK_BUILD" = "yes" ]; then break ; fi 194 ;; 195 esac 196 197 # Rebuilt all prebuilts for the arch type 198 echo 199 echo "Rebuilding the toolchain and prebuilt tarballs for $TARGET_PLATFORM_OS" 200 cd $TOP 201 $PROGDIR/rebuild-all-prebuilt.sh \ 202 --arch=$(spaces_to_commas $ARCHS) \ 203 --package-dir=$PACKAGE_DIR \ 204 $MPFR_VERSION $GDB_VERSION $BINUTILS_VERSION \ 205 $TARGET_PLATFORM_FLAGS \ 206 $VERBOSE \ 207 $NDK_SRC_DIR >> $logfile 2>&1 208 fail_panic "rebuild-all-prebuilt.sh failed. Logfile in $logfile" 209done # with TARGET_PLATFORM 210 211ALL_SYSTEMS=`echo ${BUILD_TARGET_PLATFORMS}` 212 213echo 214echo "Building the NDK release" 215cd $TOP 216logfile="$TOP/package-release.log" 217rotate_log $logfile 218$PROGDIR/package-release.sh \ 219 --prebuilt-dir=$PACKAGE_DIR \ 220 --systems="$ALL_SYSTEMS" \ 221 --out-dir=$PACKAGE_DIR \ 222 --arch=$(spaces_to_commas $ARCHS) \ 223 --prefix=android-ndk-${OPTION_NDK_RELEASE} \ 224 --no-git \ 225 $VERBOSE > $logfile 2>&1 226fail_panic "package-release.sh failed. Logfile in $logfile" 227 228echo 229echo "Packaging the NDK Toolchain sources" 230NDK_TOOLCHAIN_PKG=${PACKAGE_DIR}/toolchain-src.tar.bz2 231(cd $NDK_SRC_DIR && tar cjf $NDK_TOOLCHAIN_PKG .) 232fail_panic "Could not package NDK Toolchain sources!" 233 234exit 0 235 236