1 #!/bin/sh 2 # 3 # Copyright (C) 2009-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 package complete Android NDK release packages. 18 # 19 # You will need prebuilt toolchain binary tarballs or a previous 20 # NDK release package to do that. 21 # 22 # See make-release.sh if you want to make a new release completely from 23 # scratch. 24 # 25 26 . `dirname $0`/prebuilt-common.sh 27 28 NDK_ROOT_DIR="$ANDROID_NDK_ROOT" 29 30 # the list of platforms / API levels we want to package in 31 # this release. This can be overriden with the --platforms 32 # option, see below. 33 # 34 PLATFORMS="$API_LEVELS" 35 36 # the default release name (use today's date) 37 RELEASE=`date +%Y%m%d` 38 register_var_option "--release=<name>" RELEASE "Specify release name" 39 40 # the directory containing all prebuilts 41 PREBUILT_DIR= 42 register_var_option "--prebuilt-dir=<path>" PREBUILT_DIR "Specify prebuilt directory" 43 44 # a prebuilt NDK archive (.zip file). empty means don't use any 45 PREBUILT_NDK= 46 register_var_option "--prebuilt-ndk=<file>" PREBUILT_NDK "Specify prebuilt ndk package" 47 48 # the list of supported host development systems 49 SYSTEMS="linux-x86 darwin-x86 windows" 50 register_var_option "--systems=<list>" SYSTEMS "Specify host systems" 51 52 # set to 'yes' if we should use 'git ls-files' to list the files to 53 # be copied into the archive. 54 NO_GIT=no 55 register_var_option "--no-git" NO_GIT "Don't use git to list input files, take all of them." 56 57 # set of toolchain prebuilts we need to package 58 TOOLCHAINS="arm-eabi-4.4.0 arm-linux-androideabi-4.4.3" 59 register_var_option "--toolchains=<list>" TOOLCHAINS "Specify list of toolchains." 60 61 # set of platforms to package (all by default) 62 register_var_option "--platforms=<list>" PLATFORMS "Specify API levels" 63 64 # the package prefix 65 PREFIX=android-ndk 66 register_var_option "--prefix=<name>" PREFIX "Specify package prefix" 67 68 # default location for generated packages 69 OUT_DIR=/tmp/ndk-release 70 OPTION_OUT_DIR= 71 register_var_option "--out-dir=<path>" OPTION_OUT_DIR "Specify output package directory" "$OUT_DIR" 72 73 # Find the location of the platforms root directory 74 DEVELOPMENT_ROOT=`dirname $ANDROID_NDK_ROOT`/development/ndk 75 register_var_option "--development-root=<path>" DEVELOPMENT_ROOT "Specify platforms/samples directory" 76 77 PROGRAM_PARAMETERS= 78 PROGRAM_DESCRIPTION=\ 79 "Package a new set of release packages for the Android NDK. 80 81 You will need to have generated one or more prebuilt binary tarballs 82 with the build/tools/rebuild-all-prebuilts.sh script. These files should 83 be named like <toolname>-<system>.tar.bz2, where <toolname> is an arbitrary 84 tool name, and <system> is one of: $SYSTEMS 85 86 Use the --prebuilt-dir=<path> option to build release packages from the 87 binary tarballs stored in <path>. 88 89 Alternatively, you can use --prebuilt-ndk=<file> where <file> is the path 90 to a previous NDK release package. It will be used to extract the toolchain 91 binaries and copy them to your new release. Only use this for experimental 92 package releases. 93 94 The generated release packages will be stored in a temporary directory that 95 will be printed at the end of the generation process. 96 " 97 98 extract_parameters "$@" 99 100 # Check the prebuilt path 101 # 102 if [ -n "$PREBUILT_NDK" -a -n "$PREBUILT_DIR" ] ; then 103 echo "ERROR: You cannot use both --prebuilt-ndk and --prebuilt-dir at the same time." 104 exit 1 105 fi 106 107 if [ -z "$PREBUILT_DIR" -a -z "$PREBUILT_NDK" ] ; then 108 echo "ERROR: You must use one of --prebuilt-dir or --prebuilt-ndk. See --help for details." 109 exit 1 110 fi 111 112 # Check the option directory. 113 if [ -n "$OPTION_OUT_DIR" ] ; then 114 OUT_DIR="$OPTION_OUT_DIR" 115 mkdir -p $OUT_DIR 116 if [ $? != 0 ] ; then 117 echo "ERROR: Could not create output directory: $OUT_DIR" 118 exit 1 119 fi 120 else 121 rm -rf $OUT_DIR && mkdir -p $OUT_DIR 122 fi 123 124 # Handle the prebuilt binaries now 125 # 126 if [ -n "$PREBUILT_DIR" ] ; then 127 if [ ! -d "$PREBUILT_DIR" ] ; then 128 echo "ERROR: the --prebuilt-dir argument is not a directory: $PREBUILT_DIR" 129 exit 1 130 fi 131 if [ -z "$SYSTEMS" ] ; then 132 echo "ERROR: Your systems list is empty, use --systems=LIST to specify a different one." 133 exit 1 134 fi 135 # Check the toolchain prebuilts 136 # 137 for TC in $TOOLCHAINS; do 138 for SYS in $SYSTEMS; do 139 if [ ! -f "$PREBUILT_DIR/$TC-$SYS.tar.bz2" ] ; then 140 echo "ERROR: Missing prebuilt file $TC-$SYS.tar.bz2 in: $PREBUILT_DIR" 141 exit 1 142 fi 143 done 144 if [ ! -f "$PREBUILT_DIR/$TC-gdbserver.tar.bz2" ] ; then 145 echo "ERROR: Missing prebuilt file $TC-gdbserver.tar.bz2 in: $PREBUILT_DIR" 146 exit 1 147 fi 148 done 149 else 150 if [ ! -f "$PREBUILT_NDK" ] ; then 151 echo "ERROR: the --prebuilt-ndk argument is not a file: $PREBUILT_NDK" 152 exit 1 153 fi 154 # Check that the name ends with the proper host tag 155 HOST_NDK_SUFFIX="$HOST_TAG.zip" 156 echo "$PREBUILT_NDK" | grep -q "$HOST_NDK_SUFFIX" 157 fail_panic "The name of the prebuilt NDK must end in $HOST_NDK_SUFFIX" 158 SYSTEMS=$HOST_TAG 159 fi 160 161 # The list of git files to copy into the archives 162 if [ "$NO_GIT" != "yes" ] ; then 163 echo "Collecting sources from git (use --no-git to copy all files instead)." 164 GIT_FILES=`cd $NDK_ROOT_DIR && git ls-files` 165 else 166 echo "Collecting all sources files under tree." 167 # Cleanup everything that is likely to not be part of the final NDK 168 # i.e. generated files... 169 rm -rf $NDK_ROOT_DIR/samples/*/obj 170 rm -rf $NDK_ROOT_DIR/samples/*/libs 171 # Get all files under the NDK root 172 GIT_FILES=`cd $NDK_ROOT_DIR && find .` 173 GIT_FILES=`echo $GIT_FILES | sed -e "s!\./!!g"` 174 fi 175 176 # temporary directory used for packaging 177 TMPDIR=/tmp/ndk-release 178 179 RELEASE_PREFIX=$PREFIX-$RELEASE 180 181 # ensure that the generated files are ug+rx 182 umask 0022 183 184 rm -rf $TMPDIR && mkdir -p $TMPDIR 185 186 echo "$TOOLCHAINS" | tr ' ' '\n' | grep -q x86 187 if [ $? = 0 ] ; then 188 TRY_X86=yes 189 else 190 TRY_X86=no 191 fi 192 193 # first create the reference ndk directory from the git reference 194 echo "Creating reference from source files" 195 REFERENCE=$TMPDIR/reference && rm -rf $REFERENCE/* && 196 copy_file_list "$NDK_ROOT_DIR" "$REFERENCE" "$GIT_FILES" && 197 rm -f $REFERENCE/Android.mk 198 fail_panic "Could not create reference. Aborting." 199 200 # copy platform and sample files 201 echo "Copying platform and sample files" 202 FLAGS="--src-dir=$DEVELOPMENT_ROOT --dst-dir=$REFERENCE" 203 if [ "$VERBOSE2" = "yes" ] ; then 204 FLAGS="$FLAGS --verbose" 205 fi 206 PLATFORM_FLAGS= 207 if [ -n "$PLATFORMS" ] ; then 208 $NDK_ROOT_DIR/build/tools/build-platforms.sh $FLAGS --platform="$PLATFORMS" 209 else 210 $NDK_ROOT_DIR/build/tools/build-platforms.sh $FLAGS $PLATFORM_FLAGS 211 fi 212 fail_panic "Could not copy platform files. Aborting." 213 214 # Remove leftovers, just in case... 215 rm -rf $REFERENCE/samples/*/{obj,libs,build.xml,local.properties,Android.mk} && 216 rm -rf $REFERENCE/tests/build/*/{obj,libs} && 217 rm -rf $REFERENCE/tests/device/*/{obj,libs} 218 219 # copy sources files 220 if [ -d $DEVELOPMENT_ROOT/sources ] ; then 221 echo "Copying NDK sources files" 222 copy_file_list "$DEVELOPMENT_ROOT" "$REFERENCE" "sources" 223 fail_panic "Could not copy sources. Aborting." 224 fi 225 226 # create a release file named 'RELEASE.TXT' containing the release 227 # name. This is used by the build script to detect whether you're 228 # invoking the NDK from a release package or from the development 229 # tree. 230 # 231 echo "$RELEASE" > $REFERENCE/RELEASE.TXT 232 233 # Remove un-needed files 234 rm -f $REFERENCE/CleanSpec.mk 235 236 # Unpack a prebuilt into the destination directory ($DSTDIR) 237 # $1: prebuilt name, relative to $PREBUILT_DIR 238 unpack_prebuilt () 239 { 240 local PREBUILT=$1 241 echo "Unpacking $PREBUILT" 242 if [ -f "$PREBUILT_DIR/$PREBUILT" ] ; then 243 unpack_archive "$PREBUILT_DIR/$PREBUILT" "$DSTDIR" 244 fail_panic "Could not unpack prebuilt $PREBUILT. Aborting." 245 else 246 echo "WARNING: Could not find $PREBUILT in $PREBUILT_DIR" 247 fi 248 } 249 250 # Special handling for libsupcxx, that's because the files are 251 # stored under toolchains/<name>/prebuilt/linux-x86/arm-linux-androideabi/ 252 # and we need to unpack them under toolchains/<name>/prebuilt/<system>/arm-linux-androideabi/ 253 # if we are not on linux-x86 254 # $1: prebuilt name, relative to $PREBUILT_DIR 255 unpack_libsupcxx () 256 { 257 if [ $SYSTEM = linux-x86 ] ; then 258 unpack_prebuilt $1 259 return 260 fi 261 local PREBUILT=$1 262 echo "Unpacking $PREBUILT" 263 if [ -f "$PREBUILT_DIR/$PREBUILT" ] ; then 264 TMPUNPACKDIR=`random_temp_directory` 265 unpack_archive "$PREBUILT_DIR/$PREBUILT" "$TMPUNPACKDIR" 266 fail_panic "Could not unpack prebuilt $PREBUILT. Aborting." 267 (cd $TMPUNPACKDIR/toolchains/*/prebuilt && mv linux-x86 $SYSTEM) 268 fail_panic "Could not rename temp directory to $SYSTEM" 269 copy_directory $TMPUNPACKDIR "$DSTDIR" 270 rm -rf $TMPUNPACKDIR 271 else 272 echo "WARNING: Could not find $PREBUILT in $PREBUILT_DIR" 273 fi 274 } 275 276 # $1: Source directory relative to 277 copy_prebuilt () 278 { 279 local SUBDIR="$1" 280 if [ -d "$1" ] ; then 281 echo "Copying: $SUBDIR" 282 copy_directory "$SUBDIR" "$DSTDIR/$2" 283 else 284 echo "Ignored: $SUBDIR" 285 fi 286 } 287 288 # now, for each system, create a package 289 # 290 for SYSTEM in $SYSTEMS; do 291 echo "Preparing package for system $SYSTEM." 292 BIN_RELEASE=$RELEASE_PREFIX-$SYSTEM 293 DSTDIR=$TMPDIR/$RELEASE_PREFIX 294 rm -rf $DSTDIR && 295 copy_file_list "$REFERENCE" "$DSTDIR" "*" 296 fail_panic "Could not copy reference. Aborting." 297 298 if [ -n "$PREBUILT_NDK" ] ; then 299 echo "Unpacking prebuilt toolchains from $PREBUILT_NDK" 300 UNZIP_DIR=$TMPDIR/prev-ndk 301 rm -rf $UNZIP_DIR && mkdir -p $UNZIP_DIR 302 fail_panic "Could not create temporary directory: $UNZIP_DIR" 303 unpack_archive "$PREBUILT_NDK" "$UNZIP_DIR" 304 fail_panic "Could not unzip NDK package $PREBUILT_NDK" 305 cd $UNZIP_DIR/android-ndk-* && cp -rP toolchains/* $DSTDIR/toolchains/ 306 fail_panic "Could not copy toolchain files from $PREBUILT_NDK" 307 308 if [ -d "$DSTDIR/$STLPORT_SUBDIR" ] ; then 309 STLPORT_ABIS="armeabi armeabi-v7a x86" 310 cd $UNZIP_DIR/android-ndk-* 311 for STL_ABI in $STLPORT_ABIS; do 312 copy_prebuilt "$STLPORT_SUBDIR/libs/$STL_ABI" "$STLPORT_SUBDIR/libs" 313 done 314 copy_prebuilt "$GNUSTL_SUBDIR/include" "$GNUSTL_SUBDIR" 315 for STL_ABI in $STLPORT_ABIS; do 316 copy_prebuilt "$GNUSTL_SUBDIR/libs/$STL_ABI" "$GNUSTL_SUBDIR/libs" 317 done 318 else 319 echo "WARNING: Could not find STLport source tree!" 320 fi 321 else 322 for TC in $TOOLCHAINS; do 323 unpack_prebuilt $TC-$SYSTEM.tar.bz2 324 echo "Removing sysroot for $TC" 325 rm -rf $DSTDIR/toolchains/$TC/prebuilt/$SYSTEM/sysroot 326 unpack_prebuilt $TC-gdbserver.tar.bz2 327 done 328 unpack_libsupcxx gnu-libsupc++-armeabi.tar.bz2 329 unpack_libsupcxx gnu-libsupc++-armeabi-v7a.tar.bz2 330 if [ "$TRY_X86" = "yes" ] ; then 331 unpack_libsupcxx gnu-libsupc++-x86.tar.bz2 332 fi 333 unpack_prebuilt stlport-libs-armeabi.tar.bz2 334 unpack_prebuilt stlport-libs-armeabi-v7a.tar.bz2 335 if [ "$TRY_X86" = "yes" ] ; then 336 unpack_prebuilt stlport-prebuilt-x86.tar.bz2 337 fi 338 unpack_prebuilt gnu-libstdc++-headers.tar.bz2 339 unpack_prebuilt gnu-libstdc++-libs-armeabi.tar.bz2 340 unpack_prebuilt gnu-libstdc++-libs-armeabi-v7a.tar.bz2 341 if [ "$TRY_X86" = "yes" ] ; then 342 unpack_prebuilt gnu-libstdc++-libs-x86.tar.bz2 343 fi 344 fi 345 346 # Create an archive for the final package. Extension depends on the 347 # host system. 348 case "$SYSTEM" in 349 windows) 350 ARCHIVE="$BIN_RELEASE.zip" 351 ;; 352 *) 353 ARCHIVE="$BIN_RELEASE.tar.bz2" 354 ;; 355 esac 356 echo "Creating $ARCHIVE" 357 pack_archive "$OUT_DIR/$ARCHIVE" "$TMPDIR" "$RELEASE_PREFIX" 358 fail_panic "Could not create archive: $OUT_DIR/$ARCHIVE" 359 # chmod a+r $TMPDIR/$ARCHIVE 360 done 361 362 echo "Cleaning up." 363 rm -rf $TMPDIR/reference 364 rm -rf $TMPDIR/prev-ndk 365 366 echo "Done, please see packages in $OUT_DIR:" 367 ls -l $OUT_DIR 368