1#!/bin/sh 2# 3# Copyright (C) 2010 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# This script is used to build an NDK release package *from* scratch !! 18# While handy, this is *not* the best way to generate NDK release packages. 19# See docs/DEVELOPMENT.TXT for details. 20# 21 22. `dirname $0`/prebuilt-common.sh 23 24force_32bit_binaries 25 26# The default release name (use today's date) 27RELEASE=`date +%Y%m%d` 28register_var_option "--release=<name>" RELEASE "Specify release name" 29 30# The package prefix 31PREFIX=android-ndk 32register_var_option "--prefix=<name>" PREFIX "Specify package prefix" 33 34# Find the location of the platforms root directory 35DEVELOPMENT_ROOT=`dirname $ANDROID_NDK_ROOT`/development/ndk 36register_var_option "--development=<path>" DEVELOPMENT_ROOT "Path to development/ndk directory" 37 38# Default location for final packages 39OUT_DIR=/tmp/ndk-$USER/release 40register_var_option "--out-dir=<path>" OUT_DIR "Path to output directory" 41 42# Force the build 43FORCE=no 44register_var_option "--force" FORCE "Force build (do not ask initial question)" 45 46# Use --incremental to implement incremental release builds. 47# This is only useful to debug this script or the ones it calls. 48INCREMENTAL=no 49register_var_option "--incremental" INCREMENTAL "Enable incremental packaging (debug only)." 50 51DARWIN_SSH= 52if [ "$HOST_OS" = "linux" ] ; then 53register_var_option "--darwin-ssh=<hostname>" DARWIN_SSH "Specify Darwin hostname to ssh to for the build." 54fi 55 56# Determine the host platforms we can build for. 57# This is the current host platform, and eventually windows if 58# we are on Linux and have the mingw32 compiler installed and 59# in our path. 60# 61HOST_SYSTEMS="$HOST_TAG32" 62 63MINGW_GCC= 64if [ "$HOST_TAG" == "linux-x86" ] ; then 65 find_mingw_toolchain 66 if [ -n "$MINGW_GCC" ] ; then 67 HOST_SYSTEMS="$HOST_SYSTEMS,windows" 68 fi 69fi 70if [ -n "$DARWIN_SSH" ] ; then 71 HOST_SYSTEMS="$HOST_SYSTEMS,darwin-x86" 72fi 73 74register_var_option "--systems=<list>" HOST_SYSTEMS "List of host systems to build for" 75 76# Check if windows is specified w/o linux-x86 77if [ "$HOST_SYSTEMS" != "${HOST_SYSTEMS%windows*}" ] ; then 78 if [ -z "$MINGW_GCC" ]; then 79 echo "ERROR: Can't find mingw tool with --systems=windows" 80 exit 1 81 fi 82 if [ "$HOST_SYSTEMS" = "${HOST_SYSTEMS%linux-x86*}" ] ; then 83 echo "ERROR: Can't specify --systems=windows w/o also specifying linux-x86" 84 exit 1 85 fi 86fi 87HOST_SYSTEMS_FLAGS="--systems=$HOST_SYSTEMS" 88# Filter out darwin-x86 in $HOST_SYSTEMS_FLAGS, because 89# 1) On linux, cross-compiling is done via "--darwin-ssh". Keeping darwin-x86 in --systems list 90# actually disable --darwin-ssh later on. 91# 2) On MacOSX, darwin-x86 is the default, no need to be explicit. 92# 93HOST_SYSTEMS_FLAGS=$(echo "$HOST_SYSTEMS_FLAGS" | sed -e 's/darwin-x86//') 94 95TOOLCHAIN_SRCDIR= 96register_var_option "--toolchain-src-dir=<path>" TOOLCHAIN_SRCDIR "Use toolchain sources from <path>" 97 98extract_parameters "$@" 99 100# Print a warning and ask the user if he really wants to do that ! 101# 102if [ "$FORCE" = "no" -a "$INCREMENTAL" = "no" ] ; then 103 echo "IMPORTANT WARNING !!" 104 echo "" 105 echo "This script is used to generate an NDK release package from scratch" 106 echo "for the following host platforms: $HOST_SYSTEMS" 107 echo "" 108 echo "This process is EXTREMELY LONG and may take SEVERAL HOURS on a dual-core" 109 echo "machine. If you plan to do that often, please read docs/DEVELOPMENT.TXT" 110 echo "that provides instructions on how to do that more easily." 111 echo "" 112 echo "Are you sure you want to do that [y/N] " 113 read YESNO 114 case "$YESNO" in 115 y|Y|yes|YES) 116 ;; 117 *) 118 echo "Aborting !" 119 exit 0 120 esac 121fi 122 123PROGRAM_PARAMETERS= 124PROGRAM_DESCRIPTION=\ 125"This script is used to generate an NDK release package from scratch. 126 127This process is EXTREMELY LONG and consists in the following steps: 128 129 - downloading toolchain sources from the Internet 130 - patching them appropriately (if needed) 131 - rebuilding the toolchain binaries for the host system 132 - rebuilding the platforms and samples directories from ../development/ndk 133 - packaging everything into a host-specific archive 134 135This can take several hours on a dual-core machine, even assuming a very 136nice Internet connection and plenty of RAM and disk space. 137 138Note that on Linux, if you have the 'mingw32' package installed, the script 139will also automatically generate a windows release package. You can prevent 140that by using the --platforms option. 141 142IMPORTANT: 143 If you intend to package NDK releases often, please read the 144 file named docs/DEVELOPMENT.TXT which provides ways to do that 145 more quickly, by preparing toolchain binary tarballs that can be 146 reused for each package operation. This will save you hours of 147 your time compared to using this script! 148" 149 150# Create directory where everything will be performed. 151RELEASE_DIR=$NDK_TMPDIR/release-$RELEASE 152unset NDK_TMPDIR # prevent later script from reusing/removing it 153if [ "$INCREMENTAL" = "no" ] ; then 154 rm -rf $RELEASE_DIR && mkdir -p $RELEASE_DIR 155else 156 if [ ! -d "$RELEASE_DIR" ] ; then 157 echo "ERROR: Can't make incremental, missing release dir: $RELEASE_DIR" 158 exit 1 159 fi 160fi 161 162 163# 164# Timestamp management 165TIMESTAMP_DIR="$RELEASE_DIR/timestamps" 166mkdir -p "$TIMESTAMP_DIR" 167if [ "$INCREMENTAL" = "no" ] ; then 168 run rm -rf "$TIMESTAMP_DIR/*" 169fi 170 171timestamp_set () 172{ 173 touch "$TIMESTAMP_DIR/$1" 174} 175 176timestamp_clear () 177{ 178 rm -f "$TIMESTAMP_DIR/$1" 179} 180 181timestamp_check () 182{ 183 if [ -f "$TIMESTAMP_DIR/$1" ] ; then 184 return 1 185 else 186 return 0 187 fi 188} 189 190# Step 1, If needed, download toolchain sources into a temporary directory 191if [ -n "$TOOLCHAIN_SRCDIR" ] ; then 192 dump "Using toolchain source directory: $TOOLCHAIN_SRCDIR" 193 timestamp_set toolchain-download-sources 194else 195 if timestamp_check toolchain-download-sources; then 196 dump "Downloading toolchain sources..." 197 TOOLCHAIN_SRCDIR="$RELEASE_DIR/toolchain-src" 198 log "Using toolchain source directory: $TOOLCHAIN_SRCDIR" 199 run $ANDROID_NDK_ROOT/build/tools/download-toolchain-sources.sh "$TOOLCHAIN_SRCDIR" 200 if [ "$?" != 0 ] ; then 201 dump "ERROR: Could not download toolchain sources" 202 exit 1 203 fi 204 timestamp_set toolchain-download-sources 205 timestamp_clear build-prebuilts 206 timestamp_clear build-host-prebuilts 207 timestamp_clear build-darwin-prebuilts 208 timestamp_clear build-mingw-prebuilts 209 fi 210fi 211 212# Step 2, build the host toolchain binaries and package them 213if timestamp_check build-prebuilts; then 214 PREBUILT_DIR="$RELEASE_DIR/prebuilt" 215 if timestamp_check build-host-prebuilts; then 216 dump "Building host toolchain binaries..." 217 run $ANDROID_NDK_ROOT/build/tools/rebuild-all-prebuilt.sh --package-dir="$PREBUILT_DIR" --build-dir="$RELEASE_DIR/build" "$TOOLCHAIN_SRCDIR" "$HOST_SYSTEMS_FLAGS" 218 fail_panic "Can't build $HOST_SYSTEM binaries." 219 timestamp_set build-host-prebuilts 220 fi 221 if [ -n "$DARWIN_SSH" ] ; then 222 if timestamp_check build-darwin-prebuilts; then 223 dump "Building Darwin prebuilts through ssh to $DARWIN_SSH..." 224 run $ANDROID_NDK_ROOT/build/tools/rebuild-all-prebuilt.sh --package-dir="$PREBUILT_DIR" --darwin-ssh="$DARWIN_SSH" "$TOOLCHAIN_SRCDIR" 225 fail_panic "Can't build Darwin binaries!" 226 timestamp_set build-darwin-prebuilts 227 fi 228 fi 229 timestamp_set build-prebuilts 230 timestamp_clear make-packages 231fi 232 233# Step 3, package a release with everything 234if timestamp_check make-packages; then 235 dump "Generating NDK release packages" 236 run $ANDROID_NDK_ROOT/build/tools/package-release.sh --release=$RELEASE --prefix=$PREFIX --out-dir="$OUT_DIR" --prebuilt-dir="$PREBUILT_DIR" --systems="$HOST_SYSTEMS" --development-root="$DEVELOPMENT_ROOT" 237 if [ $? != 0 ] ; then 238 dump "ERROR: Can't generate proper release packages." 239 exit 1 240 fi 241 timestamp_set make-packages 242fi 243 244dump "All clear. Good work! See $OUT_DIR" 245