3 # Copyright (C) 2010 The Android Open Source Project
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 # This tool is used when packaging a new release, or when developing
20 # the NDK itself. It will populate DST ($NDK/platforms by default)
21 # with the content of SRC ($NDK/../development/ndk/platforms/ by default).
23 # The idea is that the content of $SRC/android-N/ only contains stuff
24 # that is relevant to API level N, and not contain anything that is already
25 # provided by API level N-1, N-2, etc..
27 # More precisely, for each architecture A:
28 # $SRC/android-N/include --> $DST/android-N/arch-A/usr/include
29 # $SRC/android-N/arch-A/include --> $DST/android-N/arch-A/usr/include
30 # $SRC/android-N/arch-A/lib --> $DST/android-N/arch-A/usr/lib
32 # For backwards compatibility:
33 # $SRC/android-N/arch-A/usr/include --> $DST/android-N/arch-A/usr/include
34 # $SRC/android-N/arch-A/usr/lib --> $DST/android-N/arch-A/usr/lib
36 # Repeat after that for N+1, N+2, etc..
39 . `dirname $0`/../core/ndk-common.sh
41 # Return the list of platform supported from $1/platforms
42 # as a single space-separated list of levels. (e.g. "3 4 5 8 9")
43 # $1: source directory
44 extract_platforms_from ()
47 (cd "$1/platforms" && ls -d android-*) | sed -e "s!android-!!" | tr '\n' ' '
53 # Remove trailing path of a path
55 remove_trailing_slash () {
56 echo $1 | sed -e 's!/$!!g'
59 # Reverse a file path directory
62 # foo/bar/zoo -> ../..
66 path=`remove_trailing_slash $1`
68 if [ "$path" != "." ] ; then
69 for item in `echo "$path" | tr '/' ' '`; do
73 echo `echo $cur | sed -e 's!/.$!!g'`
79 if [ "$rr" != "$2" ] ; then
80 echo "ERROR: reverse_path '$1' -> '$rr' (expected '$2')"
85 test_reverse_path ./ .
86 test_reverse_path foo ..
87 test_reverse_path foo/ ..
88 test_reverse_path foo/bar ../..
89 test_reverse_path foo/bar/ ../..
90 test_reverse_path foo/bar/zoo ../../..
91 test_reverse_path foo/bar/zoo/ ../../..
93 SRCDIR="../development/ndk"
94 DSTDIR="$ANDROID_NDK_ROOT"
97 PLATFORMS=`extract_platforms_from "$SRCDIR"`
104 OPTION_NO_SYMLINKS=no
110 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
112 --help|-h|-\?) OPTION_HELP=yes
115 if [ "$VERBOSE" = "yes" ] ; then
122 OPTION_SRCDIR="$optarg"
125 OPTION_DSTDIR="$optarg"
128 OPTION_PLATFORM=$optarg
134 OPTION_NO_SAMPLES=yes
137 OPTION_NO_SYMLINKS=yes
140 echo "unknown option '$opt', use --help"
145 if [ $OPTION_HELP = "yes" ] ; then
146 echo "Collect files from an Android NDK development tree and assemble"
147 echo "the platform files appropriately into a final release structure."
151 echo " --help Print this message"
152 echo " --verbose Enable verbose messages"
153 echo " --src-dir=<path> Source directory for development platform files [$SRCDIR]"
154 echo " --dst-dir=<path> Destination directory [$DSTDIR]"
155 echo " --platform=<list> Space-separated list of API levels [$PLATFORMS]"
156 echo " --abi=<list> Space-separated list of ABIs [$ABIS]"
157 echo " --no-samples Ignore samples"
158 echo " --no-symlinks Don't create symlinks, copy files instead"
163 if [ -n "$OPTION_SRCDIR" ] ; then
164 SRCDIR="$OPTION_SRCDIR";
165 if [ ! -d "$SRCDIR" ] ; then
166 echo "ERROR: Source directory $SRCDIR does not exist !"
169 if [ ! -d "$SRCDIR/platforms/android-3" ] ; then
170 echo "ERROR: Invalid source directory: $SRCDIR"
171 echo "Please make sure it contains platforms/android-3 etc..."
175 SRCDIR=`dirname $ANDROID_NDK_ROOT`/development/ndk
176 log "Using source directory: $SRCDIR"
179 if [ -n "$OPTION_PLATFORM" ] ; then
180 PLATFORMS="$OPTION_PLATFORM"
182 # Build the list from the content of SRCDIR
183 PLATFORMS=`extract_platforms_from "$SRCDIR"`
184 log "Using platforms: $PLATFORMS"
188 if [ -n "$OPTION_DSTDIR" ] ; then
189 DSTDIR="$OPTION_DSTDIR"
191 log "Using destination directory: $DSTDIR"
194 if [ -n "$OPTION_ABI" ] ; then
198 log "Checking source platforms."
199 for PLATFORM in $PLATFORMS; do
200 DIR="$SRCDIR/platforms/android-$PLATFORM"
201 if [ ! -d $DIR ] ; then
202 echo "ERROR: Directory missing: $DIR"
203 echo "Please check your --platform=<list> option and try again."
210 log "Checking source platform ABIs."
215 for PLATFORM in $PLATFORMS; do
217 DIR="$SRCDIR/platforms/android-$PLATFORM/arch-$ABI"
218 if [ -d $DIR ] ; then
227 CHECK=`var_value CHECK_$ABI`
228 log " $ABI check: $CHECK"
229 if [ "$CHECK" = no ] ; then
230 if [ -z "$BAD_ABIS" ] ; then
233 BAD_ABIS="$BAD_ABIS $ABI"
238 if [ -n "$BAD_ABIS" ] ; then
239 echo "ERROR: Source directory doesn't support these ABIs: $BAD_ABIS"
243 # $1: source directory (relative to $SRCDIR)
244 # $2: destination directory (relative to $DSTDIR)
245 # $3: description of directory contents (e.g. "sysroot" or "samples")
246 copy_src_directory ()
248 local SDIR="$SRCDIR/$1"
249 local DDIR="$DSTDIR/$2"
250 if [ -d "$SDIR" ] ; then
251 log "Copying $3 from \$SRC/$1 to \$DST/$2."
252 mkdir -p "$DDIR" && (cd "$SDIR" && tar chf - *) | (tar xf - -C "$DDIR")
253 if [ $? != 0 ] ; then
254 echo "ERROR: Could not copy $3 directory $SDIR into $DDIR !"
260 # Create a symlink-copy of directory $1 into $2
261 # This function is recursive.
263 # $1: source directory (relative to $SRCDIR)
264 # $2: destination directory (relative to $DSTDIR)
265 symlink_src_directory ()
267 mkdir -p "$DSTDIR/$2"
268 local files=`cd $DSTDIR/$1 && ls -1p | grep -v -e '.*/'`
269 local subdirs=`cd $DSTDIR/$1 && ls -1p | grep -e '.*/' | sed -e 's!/$!!g'`
270 local file subdir rev
271 rev=`reverse_path $1`
272 for file in $files; do
273 ln -s $rev/$1/$file $DSTDIR/$2/$file
275 for subdir in $subdirs; do
276 symlink_src_directory $1/$subdir $2/$subdir
280 # Copy platform sysroot and samples into your destination
283 # $SRC/android-$PLATFORM/include --> $DST/platforms/android-$PLATFORM/arch-$ABI/usr/include
284 # $SRC/android-$PLATFORM/arch-$ABI/include --> $DST/platforms/android-$PLATFORM/arch-$ABI/usr/include
286 # $SRC/android-$PLATFORM/arch-$ABI/usr/include --> $DST/platforms/android-$PLATFORM/arch-$ABI/usr/include
290 # $SRC/android-$PLATFORM/arch-$ABI/usr --> $DST/platforms/android-$PLATFORM/arch-$ABI/usr
291 # $SRC/android-$PLATFORM/samples --> $DST/samples
293 rm -rf $DSTDIR/platforms && mkdir -p $DSTDIR/platforms
295 for PLATFORM in $PLATFORMS; do
296 NEW_PLATFORM=platforms/android-$PLATFORM
297 PLATFORM_SRC=$NEW_PLATFORM
298 PLATFORM_DST=$NEW_PLATFORM
299 dump "Copying android-$PLATFORM platform files"
300 if [ -n "$PREV_PLATFORM_DST" ] ; then
301 if [ "$OPTION_NO_SYMLINKS" = "yes" ] ; then
302 log "Copying \$DST/$PREV_PLATFORM_DST to \$DST/$PLATFORM_DST"
303 #cp -r $DSTDIR/$PREV_PLATFORM_DST $DSTDIR/$PLATFORM_DST
304 copy_directory "$DSTDIR/$PREV_PLATFORM_DST" "$DSTDIR/$PLATFORM_DST"
306 log "Symlink-copying \$DST/$PREV_PLATFORM_DST to \$DST/$PLATFORM_DST"
307 symlink_src_directory $PREV_PLATFORM_DST $PLATFORM_DST
309 if [ $? != 0 ] ; then
310 echo "ERROR: Could not copy previous sysroot to $DSTDIR/$NEW_PLATFORM"
315 SYSROOT=arch-$ABI/usr
316 log "Copy $ABI sysroot files from \$SRC/android-$PLATFORM over \$DST/android-$PLATFORM/arch-$ABI"
317 copy_src_directory $PLATFORM_SRC/include $PLATFORM_DST/$SYSROOT/include "sysroot headers"
318 copy_src_directory $PLATFORM_SRC/arch-$ABI/include $PLATFORM_DST/$SYSROOT/include "sysroot headers"
319 copy_src_directory $PLATFORM_SRC/arch-$ABI/lib $PLATFORM_DST/$SYSROOT/lib "sysroot libs"
320 copy_src_directory $PLATFORM_SRC/$SYSROOT $PLATFORM_DST/$SYSROOT "sysroot"
322 PREV_PLATFORM_DST=$PLATFORM_DST
325 if [ "$OPTION_NO_SAMPLES" = no ] ; then
326 # Copy platform samples and generic samples into your destination
328 # $SRC/samples/ --> $DST/samples/
329 # $SRC/android-$PLATFORM/samples/ --> $DST/samples
331 dump "Copying generic samples"
332 rm -rf $DSTDIR/samples && mkdir -p $DSTDIR/samples
333 copy_src_directory samples samples samples
335 for PLATFORM in $PLATFORMS; do
336 dump "Copy android-$PLATFORM samples"
337 # $SRC/platform-$PLATFORM/samples --> $DST/samples
338 copy_src_directory platforms/android-$PLATFORM/samples samples samples
341 # Cleanup generated files in samples
342 rm -rf "$DSTDIR/samples/*/obj"
343 rm -rf "$DSTDIR/samples/*/libs"