1#!/bin/sh 2# 3# Copyright (C) 2009 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 complete Android NDK release packages 18# from the git repository and a set of prebuilt cross-toolchain tarballs 19# 20 21# location of the root ndk directory. we assume this script is under build/tools 22NDK_ROOT_DIR=`dirname $0`/../.. 23NDK_ROOT_DIR=`cd $NDK_ROOT_DIR && pwd` 24 25. $NDK_ROOT_DIR/build/core/ndk-common.sh 26force_32bit_binaries 27 28# the default release name (use today's date) 29RELEASE=`date +%Y%m%d` 30 31# the package prefix 32PREFIX=android-ndk 33 34# the directory containing the prebuilt toolchain tarballs 35PREBUILT_DIR= 36 37# the prefix of prebuilt toolchain tarballs in $PREBUILT_DIR 38PREBUILT_PREFIX=android-ndk-prebuilt-20090323 39 40# the list of supported host development systems 41PREBUILT_SYSTEMS="linux-x86 darwin-x86 windows" 42 43# a prebuilt NDK archive (.zip file). empty means don't use any 44PREBUILT_NDK= 45 46# set to 'yes' if we should use 'git ls-files' to list the files to 47# be copied into the archive. 48USE_GIT_FILES=yes 49 50OPTION_HELP=no 51 52for opt do 53 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` 54 case "$opt" in 55 --help|-h|-\?) OPTION_HELP=yes 56 ;; 57 --verbose) 58 if [ "$VERBOSE" = "yes" ] ; then 59 VERBOSE2=yes 60 else 61 VERBOSE=yes 62 fi 63 ;; 64 --release=*) RELEASE=$optarg 65 ;; 66 --prefix=*) PREFIX=$optarg 67 ;; 68 --prebuilt-ndk=*) PREBUILT_NDK=$optarg 69 ;; 70 --prebuilt-prefix=*) PREBUILT_PREFIX=$optarg 71 ;; 72 --prebuilt-path=*) PREBUILT_DIR=$optarg 73 ;; 74 --systems=*) PREBUILT_SYSTEMS=$optarg 75 ;; 76 --no-git) USE_GIT_FILES=no 77 ;; 78 *) 79 echo "unknown option '$opt', use --help" 80 exit 1 81 esac 82done 83 84if [ $OPTION_HELP = yes ] ; then 85 echo "Usage: make-release.sh [options]" 86 echo "" 87 echo "Package a new set of release packages for the Android NDK." 88 echo "You will need to specify the path of a directory containing" 89 echo "prebuilt toolchain tarballs with the --prebuilt-path option." 90 echo "" 91 echo "Alternatively, you can specify an existing NDK release package" 92 echo "with the --prebuilt-ndk option." 93 echo "" 94 echo "Options: [defaults in brackets after descriptions]" 95 echo "" 96 echo " --help Print this help message" 97 echo " --prefix=PREFIX Package prefix name [$PREFIX]" 98 echo " --release=NAME Specify release name [$RELEASE]" 99 echo " --systems=SYSTEMS List of host system packages [$PREBUILT_SYSTEMS]" 100 echo " --prebuilt-ndk=FILE Specify a previous NDK package [$PREBUILT_NDK]" 101 echo " --prebuilt-path=PATH Location of prebuilt binary tarballs [$PREBUILT_DIR]" 102 echo " --prebuilt-prefix=PREFIX Prefix of prebuilt binary tarballs [$PREBUILT_PREFIX]" 103 echo " --no-git Don't use git to list input files, take all of them." 104 echo "" 105 exit 1 106fi 107 108# Check the prebuilt path 109# 110if [ -n "$PREBUILD_NDK" -a -n "$PREBUILT_DIR" ] ; then 111 echo "ERROR: You cannot use both --prebuilt-ndk and --prebuilt-path at the same time." 112 exit 1 113fi 114 115if [ -z "$PREBUILT_DIR" -a -z "$PREBUILT_NDK" ] ; then 116 echo "ERROR: You must use --prebuilt-path=PATH to specify the path of prebuilt binary tarballs." 117 echo " Or --prebuilt-ndk=FILE to specify an existing NDK release archive." 118 exit 1 119fi 120 121if [ -n "$PREBUILT_DIR" ] ; then 122 if [ ! -d "$PREBUILT_DIR" ] ; then 123 echo "ERROR: the --prebuilt-path argument is not a directory path: $PREBUILT_DIR" 124 exit 1 125 fi 126 if [ -z "$PREBUILT_PREFIX" ] ; then 127 echo "ERROR: Your prebuilt prefix is empty; use --prebuilt-prefix=PREFIX." 128 exit 1 129 fi 130 if [ -z "$PREBUILT_SYSTEMS" ] ; then 131 echo "ERROR: Your systems list is empty, use --system=LIST to specify a different one." 132 exit 1 133 fi 134 # Check the systems 135 # 136 for SYS in $PREBUILT_SYSTEMS; do 137 if [ ! -f $PREBUILT_DIR/$PREBUILT_PREFIX-$SYS.tar.bz2 ] ; then 138 echo "ERROR: It seems there is no prebuilt binary tarball for the '$SYS' system" 139 echo "Please check the content of $PREBUILT_DIR for a file named $PREBUILT_PREFIX-$SYS.tar.bz2." 140 exit 1 141 fi 142 done 143else 144 if [ ! -f "$PREBUILT_NDK" ] ; then 145 echo "ERROR: the --prebuilt-ndk argument is not a file: $PREBUILT_NDK" 146 exit 1 147 fi 148 # Check that the name ends with the proper host tag 149 HOST_NDK_SUFFIX="$HOST_TAG.zip" 150 echo "$PREBUILT_NDK" | grep -q "$HOST_NDK_SUFFIX" 151 if [ $? != 0 ] ; then 152 echo "ERROR: the name of the prebuilt NDK must end in $HOST_NDK_SUFFIX" 153 exit 1 154 fi 155 PREBUILT_SYSTEMS=$HOST_TAG 156fi 157 158# The list of git files to copy into the archives 159if [ "$USE_GIT_FILES" = "yes" ] ; then 160 echo "Collecting sources from git (use --no-git to copy all files instead)." 161 GIT_FILES=`cd $NDK_ROOT_DIR && git ls-files` 162else 163 echo "Collecting all sources files under tree." 164 # Cleanup everything that is likely to not be part of the final NDK 165 # i.e. generated files... 166 rm -rf $NDK_ROOT_DIR/out 167 rm -rf $NDK_ROOT_DIR/apps/*/project/libs/armeabi 168 # Get all files under the NDK root 169 GIT_FILES=`cd $NDK_ROOT_DIR && find .` 170 GIT_FILES=`echo $GIT_FILES | sed -e "s!\./!!g"` 171fi 172 173# temporary directory used for packaging 174TMPDIR=/tmp/ndk-release 175 176RELEASE_PREFIX=$PREFIX-$RELEASE 177 178rm -rf $TMPDIR && mkdir -p $TMPDIR 179 180# first create the reference ndk directory from the git reference 181echo "Creating reference from source files" 182REFERENCE=$TMPDIR/reference && 183mkdir -p $REFERENCE && 184(cd $NDK_ROOT_DIR && tar cf - $GIT_FILES) | (cd $REFERENCE && tar xf -) && 185rm -f $REFERENCE/Android.mk 186if [ $? != 0 ] ; then 187 echo "Could not create reference. Aborting." 188 exit 2 189fi 190 191# now, for each system, create a package 192# 193for SYSTEM in $PREBUILT_SYSTEMS; do 194 echo "Preparing package for system $SYSTEM." 195 BIN_RELEASE=$RELEASE_PREFIX-$SYSTEM 196 PREBUILT=$PREBUILT_DIR/$PREBUILT_PREFIX-$SYSTEM 197 DSTDIR=$TMPDIR/$RELEASE_PREFIX 198 rm -rf $DSTDIR && mkdir -p $DSTDIR && 199 cp -rp $REFERENCE/* $DSTDIR 200 if [ $? != 0 ] ; then 201 echo "Could not copy reference. Aborting." 202 exit 2 203 fi 204 205 if [ -n "$PREBUILT_NDK" ] ; then 206 echo "Unpacking prebuilt toolchain from $PREBUILT_NDK" 207 UNZIP_DIR=$TMPDIR/prev-ndk 208 rm -rf $UNZIP_DIR && mkdir -p $UNZIP_DIR 209 if [ $? != 0 ] ; then 210 echo "Could not create temporary directory: $UNZIP_DIR" 211 exit 1 212 fi 213 cd $UNZIP_DIR && unzip -q $PREBUILT_NDK 1>/dev/null 2>&1 214 if [ $? != 0 ] ; then 215 echo "ERROR: Could not unzip NDK package $PREBUILT_NDK" 216 exit 1 217 fi 218 cd android-ndk-* && cp -rP build/prebuilt $DSTDIR/build 219 else 220 echo "Unpacking $PREBUILT.tar.bz2" 221 (cd $DSTDIR && tar xjf $PREBUILT.tar.bz2) 2>/dev/null 1>&2 222 if [ $? != 0 ] ; then 223 echo "Could not unpack prebuilt for system $SYSTEM. Aborting." 224 exit 1 225 fi 226 fi 227 228 ARCHIVE=$BIN_RELEASE.zip 229 echo "Creating $ARCHIVE" 230 (cd $TMPDIR && zip -9qr $ARCHIVE $RELEASE_PREFIX && rm -rf $DSTDIR) 2>/dev/null 1>&2 231 if [ $? != 0 ] ; then 232 echo "Could not create zip archive. Aborting." 233 exit 1 234 fi 235 236 chmod a+r $TMPDIR/$ARCHIVE 237done 238 239echo "Cleaning up." 240rm -rf $TMPDIR/reference 241rm -rf $TMPDIR/prev-ndk 242 243echo "Done, please see packages in $TMPDIR:" 244ls -l $TMPDIR 245