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