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_TAG" 62 63MINGW_GCC= 64if [ "$HOST_TAG" == "linux-x86" ] ; then 65 find_program MINGW_GCC i586-mingw32msvc-gcc 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 76TOOLCHAIN_SRCDIR= 77register_var_option "--toolchain-src-dir=<path>" TOOLCHAIN_SRCDIR "Use toolchain sources from <path>" 78 79extract_parameters "$@" 80 81# Print a warning and ask the user if he really wants to do that ! 82# 83if [ "$FORCE" = "no" -a "$INCREMENTAL" = "no" ] ; then 84 echo "IMPORTANT WARNING !!" 85 echo "" 86 echo "This script is used to generate an NDK release package from scratch" 87 echo "for the following host platforms: $HOST_SYSTEMS" 88 echo "" 89 echo "This process is EXTREMELY LONG and may take SEVERAL HOURS on a dual-core" 90 echo "machine. If you plan to do that often, please read docs/DEVELOPMENT.TXT" 91 echo "that provides instructions on how to do that more easily." 92 echo "" 93 echo "Are you sure you want to do that [y/N] " 94 read YESNO 95 case "$YESNO" in 96 y|Y|yes|YES) 97 ;; 98 *) 99 echo "Aborting !" 100 exit 0 101 esac 102fi 103 104PROGRAM_PARAMETERS= 105PROGRAM_DESCRIPTION=\ 106"This script is used to generate an NDK release package from scratch. 107 108This process is EXTREMELY LONG and consists in the following steps: 109 110 - downloading toolchain sources from the Internet 111 - patching them appropriately (if needed) 112 - rebuilding the toolchain binaries for the host system 113 - rebuilding the platforms and samples directories from ../development/ndk 114 - packaging everything into a host-specific archive 115 116This can take several hours on a dual-core machine, even assuming a very 117nice Internet connection and plenty of RAM and disk space. 118 119Note that on Linux, if you have the 'mingw32' package installed, the script 120will also automatically generate a windows release package. You can prevent 121that by using the --platforms option. 122 123IMPORTANT: 124 If you intend to package NDK releases often, please read the 125 file named docs/DEVELOPMENT.TXT which provides ways to do that 126 more quickly, by preparing toolchain binary tarballs that can be 127 reused for each package operation. This will save you hours of 128 your time compared to using this script! 129" 130 131# Create directory where everything will be performed. 132RELEASE_DIR=$NDK_TMPDIR/release-$RELEASE 133if [ "$INCREMENTAL" = "no" ] ; then 134 rm -rf $RELEASE_DIR && mkdir -p $RELEASE_DIR 135else 136 if [ ! -d "$RELEASE_DIR" ] ; then 137 echo "ERROR: Can't make incremental, missing release dir: $RELEASE_DIR" 138 exit 1 139 fi 140fi 141 142 143# 144# Timestamp management 145TIMESTAMP_DIR="$RELEASE_DIR/timestamps" 146mkdir -p "$TIMESTAMP_DIR" 147if [ "$INCREMENTAL" = "no" ] ; then 148 run rm -rf "$TIMESTAMP_DIR/*" 149fi 150 151timestamp_set () 152{ 153 touch "$TIMESTAMP_DIR/$1" 154} 155 156timestamp_clear () 157{ 158 rm -f "$TIMESTAMP_DIR/$1" 159} 160 161timestamp_check () 162{ 163 if [ -f "$TIMESTAMP_DIR/$1" ] ; then 164 return 1 165 else 166 return 0 167 fi 168} 169 170# Step 1, If needed, download toolchain sources into a temporary directory 171if [ -n "$TOOLCHAIN_SRCDIR" ] ; then 172 dump "Using toolchain source directory: $TOOLCHAIN_SRCDIR" 173 timestamp_set toolchain-download-sources 174else 175 if timestamp_check toolchain-download-sources; then 176 dump "Downloading toolchain sources..." 177 TOOLCHAIN_SRCDIR="$RELEASE_DIR/toolchain-src" 178 log "Using toolchain source directory: $TOOLCHAIN_SRCDIR" 179 $ANDROID_NDK_ROOT/build/tools/download-toolchain-sources.sh "$TOOLCHAIN_SRCDIR" 180 if [ "$?" != 0 ] ; then 181 dump "ERROR: Could not download toolchain sources" 182 exit 1 183 fi 184 timestamp_set toolchain-download-sources 185 timestamp_clear build-prebuilts 186 timestamp_clear build-host-prebuilts 187 timestamp_clear build-darwin-prebuilts 188 timestamp_clear build-mingw-prebuilts 189 fi 190fi 191 192# Step 2, build the host toolchain binaries and package them 193if timestamp_check build-prebuilts; then 194 PREBUILT_DIR="$RELEASE_DIR/prebuilt" 195 if timestamp_check build-host-prebuilts; then 196 dump "Building host toolchain binaries..." 197 $ANDROID_NDK_ROOT/build/tools/rebuild-all-prebuilt.sh --toolchain-src-dir="$TOOLCHAIN_SRCDIR" --package-dir="$PREBUILT_DIR" --build-dir="$RELEASE_DIR/build" 198 fail_panic "Can't build $HOST_SYSTEM binaries." 199 timestamp_set build-host-prebuilts 200 fi 201 if [ -n "$DARWIN_SSH" ] ; then 202 if timestamp_check build-darwin-prebuilts; then 203 dump "Building Darwin prebuilts through ssh to $DARWIN_SSH..." 204 $ANDROID_NDK_ROOT/build/tools/rebuild-all-prebuilt.sh --toolchain-src-dir="$TOOLCHAIN_SRCDIR" --package-dir="$PREBUILT_DIR" --darwin-ssh="$DARWIN_SSH" 205 fail_panic "Can't build Darwin binaries!" 206 timestamp_set build-darwin-prebuilts 207 fi 208 fi 209 if [ -n "$MINGW_GCC" ] ; then 210 if timestamp_check build-mingw-prebuilts; then 211 dump "Building windows toolchain binaries..." 212 $ANDROID_NDK_ROOT/build/tools/rebuild-all-prebuilt.sh --toolchain-src-dir="$TOOLCHAIN_SRCDIR" --package-dir="$PREBUILT_DIR" --build-dir="$RELEASE_DIR/build-mingw" --mingw 213 fail_panic "Can't build windows binaries." 214 timestamp_set build-mingw-prebuilt 215 fi 216 fi 217 timestamp_set build-prebuilts 218 timestamp_clear make-packages 219fi 220 221# Step 3, package a release with everything 222if timestamp_check make-packages; then 223 dump "Generating NDK release packages" 224 $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" 225 if [ $? != 0 ] ; then 226 dump "ERROR: Can't generate proper release packages." 227 exit 1 228 fi 229 timestamp_set make-packages 230fi 231 232dump "All clear. Good work! See $OUT_DIR" 233