make-release.sh revision ea573da2c3f1a8379f4344d023035fdf795c768d
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 prefix of prebuilt toolchain tarballs
35PREBUILT_PREFIX=
36
37# the list of supported host development systems
38PREBUILT_SYSTEMS="linux-x86 darwin-x86 windows"
39
40# a prebuilt NDK archive (.zip file). empty means don't use any
41PREBUILT_NDK=
42
43# default location for generated packages
44OUT_DIR=/tmp/ndk-release
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
50# set of platforms to package (all by default)
51PLATFORMS=
52
53# Find the location of the platforms root directory
54DEVELOPMENT_ROOT=`dirname $NDK_ROOT_DIR`/development/ndk
55
56OPTION_HELP=no
57OPTION_OUT_DIR=
58
59for opt do
60  optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
61  case "$opt" in
62  --help|-h|-\?) OPTION_HELP=yes
63  ;;
64  --verbose)
65    if [ "$VERBOSE" = "yes" ] ; then
66        VERBOSE2=yes
67    else
68        VERBOSE=yes
69    fi
70  ;;
71  --release=*) RELEASE=$optarg
72  ;;
73  --prefix=*) PREFIX=$optarg
74  ;;
75  --prebuilt-ndk=*) PREBUILT_NDK=$optarg
76  ;;
77  --prebuilt-prefix=*) PREBUILT_PREFIX=$optarg
78  ;;
79  --systems=*) PREBUILT_SYSTEMS=$optarg
80  ;;
81  --platforms=*) PLATFORMS=$optarg
82  ;;
83  --no-git) USE_GIT_FILES=no
84  ;;
85  --development-root=*) DEVELOPMENT_ROOT=$optarg
86  ;;
87  --out-dir=*) OPTION_OUT_DIR=$optarg
88  ;;
89  *)
90    echo "unknown option '$opt', use --help"
91    exit 1
92  esac
93done
94
95if [ $OPTION_HELP = yes ] ; then
96    echo "Usage: make-release.sh [options]"
97    echo ""
98    echo "Package a new set of release packages for the Android NDK."
99    echo ""
100    echo "You will need to have generated one or more prebuilt toolchain tarballs"
101    echo "with the build/tools/build-toolchain.sh script. These files should be"
102    echo "named like <prefix>-<system>.tar.bz2, where <prefix> is an arbitrary"
103    echo "prefix and <system> is one of: $PREBUILT_SYSTEMS"
104    echo ""
105    echo "Use the --prebuilt-prefix=<path>/<prefix> option to build release"
106    echo "packages from these tarballs."
107    echo ""
108    echo "Alternatively, you can use --prebuilt-ndk=<file> where <file> is the"
109    echo "path to a previous official NDK release package. It will be used to"
110    echo "extract the toolchain binaries and copy them to your new release."
111    echo "Only use this for experimental release packages!"
112    echo ""
113    echo "The generated release packages will be stored in a temporary directory"
114    echo "that will be printed at the end of the generation process."
115    echo ""
116    echo "Options: [defaults in brackets after descriptions]"
117    echo ""
118    echo "  --help                    Print this help message"
119    echo "  --prefix=PREFIX           Release package prefix name [$PREFIX]"
120    echo "  --release=NAME            Specify release name [$RELEASE]"
121    echo "  --prebuilt-prefix=PREFIX  Prefix of prebuilt binary tarballs [$PREBUILT_PREFIX]"
122    echo "  --prebuilt-ndk=FILE       Specify a previous NDK package [$PREBUILT_NDK]"
123    echo "  --systems=SYSTEMS         List of host system packages [$PREBUILT_SYSTEMS]"
124    echo "  --platforms=PLATFORMS     List of platforms to include [all]"
125    echo "  --no-git                  Don't use git to list input files, take all of them."
126    echo "  --development-root=PATH   Specify platforms/samples directory [$DEVELOPMENT_ROOT]"
127    echo "  --out-dir=PATH            Specify output package directory [$OUT_DIR]"
128    echo ""
129    exit 1
130fi
131
132# Check the prebuilt path
133#
134if [ -n "$PREBUILD_NDK" -a -n "$PREBUILT_PREFIX" ] ; then
135    echo "ERROR: You cannot use both --prebuilt-ndk and --prebuilt-prefix at the same time."
136    exit 1
137fi
138
139if [ -z "$PREBUILT_PREFIX" -a -z "$PREBUILT_NDK" ] ; then
140    echo "ERROR: You must use one of --prebuilt-prefix or --prebuilt-ndk. See --help for details."
141    exit 1
142fi
143
144if [ -n "$OPTION_OUT_DIR" ] ; then
145    OUT_DIR="$OPTION_OUT_DIR"
146    if [ ! -d $OUT_DIR ] ; then
147        mkdir -p $OUT_DIR
148        if [ $? != 0 ] ; then
149            echo "ERROR: Could not create output directory: $OUT_DIR"
150            exit 1
151        fi
152    fi
153else
154    rm -rf $OUT_DIR && mkdir -p $OUT_DIR
155fi
156
157if [ -n "$PREBUILT_PREFIX" ] ; then
158    if [ -d "$PREBUILT_PREFIX" ] ; then
159        echo "ERROR: the --prebuilt-prefix argument must not be a direct directory path: $PREBUILT_PREFIX."
160        exit 1
161    fi
162    PREBUILT_DIR=`dirname $PREBUILT_PREFIX`
163    if [ ! -d "$PREBUILT_DIR" ] ; then
164        echo "ERROR: the --prebuilt-prefix argument does not point to a directory: $PREBUILT_DIR"
165        exit 1
166    fi
167    if [ -z "$PREBUILT_SYSTEMS" ] ; then
168        echo "ERROR: Your systems list is empty, use --system=LIST to specify a different one."
169        exit 1
170    fi
171    # Check the systems
172    #
173    for SYS in $PREBUILT_SYSTEMS; do
174        if [ ! -f $PREBUILT_PREFIX-$SYS.tar.bz2 ] ; then
175            echo "ERROR: It seems there is no prebuilt binary tarball for the '$SYS' system"
176            echo "Please check the content of $PREBUILT_DIR for a file named $PREBUILT_PREFIX-$SYS.tar.bz2."
177            exit 1
178        fi
179    done
180else
181    if [ ! -f "$PREBUILT_NDK" ] ; then
182        echo "ERROR: the --prebuilt-ndk argument is not a file: $PREBUILT_NDK"
183        exit 1
184    fi
185    # Check that the name ends with the proper host tag
186    HOST_NDK_SUFFIX="$HOST_TAG.zip"
187    echo "$PREBUILT_NDK" | grep -q "$HOST_NDK_SUFFIX"
188    if [ $? != 0 ] ; then
189        echo "ERROR: the name of the prebuilt NDK must end in $HOST_NDK_SUFFIX"
190        exit 1
191    fi
192    PREBUILT_SYSTEMS=$HOST_TAG
193fi
194
195# The list of git files to copy into the archives
196if [ "$USE_GIT_FILES" = "yes" ] ; then
197    echo "Collecting sources from git (use --no-git to copy all files instead)."
198    GIT_FILES=`cd $NDK_ROOT_DIR && git ls-files`
199else
200    echo "Collecting all sources files under tree."
201    # Cleanup everything that is likely to not be part of the final NDK
202    # i.e. generated files...
203    rm -rf $NDK_ROOT_DIR/samples/*/obj
204    rm -rf $NDK_ROOT_DIR/samples/*/libs
205    # Get all files under the NDK root
206    GIT_FILES=`cd $NDK_ROOT_DIR && find .`
207    GIT_FILES=`echo $GIT_FILES | sed -e "s!\./!!g"`
208fi
209
210# temporary directory used for packaging
211TMPDIR=/tmp/ndk-release
212
213RELEASE_PREFIX=$PREFIX-$RELEASE
214
215# ensure that the generated files are ug+rx
216umask 0022
217
218rm -rf $TMPDIR && mkdir -p $TMPDIR
219
220# first create the reference ndk directory from the git reference
221echo "Creating reference from source files"
222REFERENCE=$TMPDIR/reference &&
223mkdir -p $REFERENCE &&
224(cd $NDK_ROOT_DIR && tar cf - $GIT_FILES) | (cd $REFERENCE && tar xf -) &&
225rm -f $REFERENCE/Android.mk
226if [ $? != 0 ] ; then
227    echo "Could not create reference. Aborting."
228    exit 2
229fi
230
231# copy platform and sample files
232echo "Copying platform and sample files"
233FLAGS="--src-dir=$DEVELOPMENT_ROOT --dst-dir=$REFERENCE"
234if [ "$VERBOSE2" = "yes" ] ; then
235  FLAGS="$FLAGS --verbose"
236fi
237PLATFORM_FLAGS=
238if [ -n "$PLATFORMS" ] ; then
239    $NDK_ROOT_DIR/build/tools/build-platforms.sh $FLAGS --platform="$PLATFORMS"
240else
241    $NDK_ROOT_DIR/build/tools/build-platforms.sh $FLAGS $PLATFORM_FLAGS
242fi
243if [ $? != 0 ] ; then
244    echo "Could not copy platform files. Aborting."
245    exit 2
246fi
247
248# copy sources files
249if [ -d $DEVELOPMENT_ROOT/sources ] ; then
250    echo "Copying NDK sources files"
251    (cd $DEVELOPMENT_ROOT && tar cf - sources) | (cd $REFERENCE && tar xf -)
252    if [ $? != 0 ] ; then
253        echo "Could not copy sources. Aborting."
254        exit 2
255    fi
256fi
257
258# create a release file named 'RELEASE.TXT' containing the release
259# name. This is used by the build script to detect whether you're
260# invoking the NDK from a release package or from the development
261# tree.
262#
263echo "$RELEASE" > $REFERENCE/RELEASE.TXT
264
265# Remove un-needed files
266rm -f $REFERENCE/CleanSpec.mk
267
268# now, for each system, create a package
269#
270for SYSTEM in $PREBUILT_SYSTEMS; do
271    echo "Preparing package for system $SYSTEM."
272    BIN_RELEASE=$RELEASE_PREFIX-$SYSTEM
273    PREBUILT=$PREBUILT_PREFIX-$SYSTEM
274    DSTDIR=$TMPDIR/$RELEASE_PREFIX
275    rm -rf $DSTDIR && mkdir -p $DSTDIR &&
276    cp -rp $REFERENCE/* $DSTDIR
277    if [ $? != 0 ] ; then
278        echo "Could not copy reference. Aborting."
279        exit 2
280    fi
281
282    if [ -n "$PREBUILT_NDK" ] ; then
283        echo "Unpacking prebuilt toolchain from $PREBUILT_NDK"
284        UNZIP_DIR=$TMPDIR/prev-ndk
285        rm -rf $UNZIP_DIR && mkdir -p $UNZIP_DIR
286        if [ $? != 0 ] ; then
287            echo "Could not create temporary directory: $UNZIP_DIR"
288            exit 1
289        fi
290        cd $UNZIP_DIR && unzip -q $PREBUILT_NDK 1>/dev/null 2>&1
291        if [ $? != 0 ] ; then
292            echo "ERROR: Could not unzip NDK package $PREBUILT_NDK"
293            exit 1
294        fi
295        cd android-ndk-* && cp -rP build/prebuilt $DSTDIR/build
296    else
297        echo "Unpacking $PREBUILT.tar.bz2"
298        (cd $DSTDIR && tar xjf $PREBUILT.tar.bz2) 2>/dev/null 1>&2
299        if [ $? != 0 ] ; then
300            echo "Could not unpack prebuilt for system $SYSTEM. Aborting."
301            exit 1
302        fi
303    fi
304
305    ARCHIVE=$BIN_RELEASE.zip
306    echo "Creating $ARCHIVE"
307    (cd $TMPDIR && zip -9qr $OUT_DIR/$ARCHIVE $RELEASE_PREFIX && rm -rf $DSTDIR) 2>/dev/null 1>&2
308    if [ $? != 0 ] ; then
309        echo "Could not create zip archive. Aborting."
310        exit 1
311    fi
312
313#    chmod a+r $TMPDIR/$ARCHIVE
314done
315
316echo "Cleaning up."
317rm -rf $TMPDIR/reference
318rm -rf $TMPDIR/prev-ndk
319
320echo "Done, please see packages in $OUT_DIR:"
321ls -l $OUT_DIR
322