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.
17 # This shell script is used to rebuild the prebuilt STLport binaries from
18 # their sources. It requires a working NDK installation.
21 # include common function and variable definitions
22 . `dirname $0`/prebuilt-common.sh
24 # Location of the test project we use to force the rebuild.
25 # This is relative to the current NDK directory.
26 PROJECT_SUBDIR=tests/build/prebuild-stlport
31 "Rebuild the prebuilt STLport binaries for the Android NDK.
33 This script is called when packaging a new NDK release. It will simply
34 rebuild the STLport static and shared libraries from sources by using
35 the dummy project under $PROJECT_SUBDIR and a valid NDK installation.
37 By default, this will try with the current NDK directory, unless
38 you use the --ndk-dir=<path> option.
40 The output will be placed in appropriate sub-directories of
41 <ndk>/$STLPORT_SUBDIR, but you can override this with the --out-dir=<path>
45 RELEASE=`date +%Y%m%d`
46 PACKAGE_DIR=/tmp/ndk-prebuilt/prebuilt-$RELEASE
47 register_var_option "--package-dir=<path>" PACKAGE_DIR "Put prebuilt tarballs into <path>."
50 register_var_option "--ndk-dir=<path>" NDK_DIR "Don't package, put the files in target NDK dir."
53 register_var_option "--toolchain-pkg=<path>" TOOLCHAIN_PKG "Use specific toolchain prebuilt package."
57 register_var_option "--build-dir=<path>" OPTION_BUILD_DIR "Specify temporary build dir."
60 register_var_option "--out-dir=<path>" OUT_DIR "Specify output directory directly."
63 register_var_option "--abis=<list>" ABIS "Specify list of target ABIs."
65 extract_parameters "$@"
67 if [ -n "$PACKAGE_DIR" -a -n "$NDK_DIR" ] ; then
68 echo "ERROR: You cannot use both --package-dir and --ndk-dir at the same time!"
72 if [ -n "$TOOLCHAIN_PKG" ] ; then
73 if [ ! -f "$TOOLCHAIN_PKG" ] ; then
74 dump "ERROR: Your toolchain package does not exist: $TOOLCHAIN_PKG"
77 case "$TOOLCHAIN_PKG" in
81 dump "ERROR: Toolchain package is not .tar.bz2 archive: $TOOLCHAIN_PKG"
86 if [ -z "$NDK_DIR" ] ; then
87 mkdir -p "$PACKAGE_DIR"
89 echo "ERROR: Could not create directory: $PACKAGE_DIR"
92 NDK_DIR=/tmp/ndk-toolchain/ndk-prebuilt-$$
94 dump "Copying NDK files to temporary dir: $NDK_DIR"
95 run cp -rf $ANDROID_NDK_ROOT/* $NDK_DIR/
96 if [ -n "$TOOLCHAIN_PKG" ] ; then
97 dump "Extracting prebuilt toolchain binaries."
98 unpack_archive "$TOOLCHAIN_PKG" "$NDK_DIR"
101 if [ ! -d "$NDK_DIR" ] ; then
102 echo "ERROR: NDK directory does not exists: $NDK_DIR"
111 log "Using NDK root: $NDK_DIR"
113 BUILD_DIR="$OPTION_BUILD_DIR"
114 if [ -n "$BUILD_DIR" ] ; then
115 log "Using temporary build dir: $BUILD_DIR"
117 BUILD_DIR=`random_temp_directory`
118 log "Using random build dir: $BUILD_DIR"
120 mkdir -p "$BUILD_DIR"
122 if [ -z "$OUT_DIR" ] ; then
123 OUT_DIR=$NDK_DIR/$STLPORT_SUBDIR
124 log "Using default output dir: $OUT_DIR"
126 log "Using usr output dir: $OUT_DIR"
130 # Now build the fake project
132 # NOTE: We take the build project from this NDK's tree, not from
133 # the alternative one specified with --ndk=<dir>
135 PROJECT_DIR="$ANDROID_NDK_ROOT/$PROJECT_SUBDIR"
136 if [ ! -d $PROJECT_DIR ] ; then
137 dump "ERROR: Missing required project: $PROJECT_SUBDIR"
141 # cleanup required to avoid problems with stale dependency files
142 rm -rf "$PROJECT_DIR/libs"
143 rm -rf "$PROJECT_DIR/obj"
145 LIBRARIES="libstlport_static.a libstlport_shared.so"
148 dump "Building $ABI STLport binaries..."
149 (run cd "$PROJECT_SUBDIR" && run "$NDK_DIR"/ndk-build -B APP_ABI=$ABI -j$BUILD_JOBS STLPORT_FORCE_REBUILD=true)
150 if [ $? != 0 ] ; then
151 dump "ERROR: Could not build $ABI STLport binaries!!"
155 if [ -z "$PACKAGE_DIR" ] ; then
156 # Copy files to target NDK
157 SRCDIR="$PROJECT_SUBDIR/obj/local/$ABI"
158 DSTDIR="$OUT_DIR/libs/$ABI"
159 copy_file_list "$SRCDIR" "$DSTDIR" "$LIBRARIES"
163 # If needed, package files into tarballs
164 if [ -n "$PACKAGE_DIR" ] ; then
167 for LIB in $LIBRARIES; do
168 SRCDIR="$PROJECT_SUBDIR/obj/local/$ABI"
169 DSTDIR="$STLPORT_SUBDIR/libs/$ABI"
170 copy_file_list "$SRCDIR" "$NDK_DIR/$DSTDIR" "$LIB"
171 log "Installing: $DSTDIR/$LIB"
172 FILES="$FILES $DSTDIR/$LIB"
174 PACKAGE="$PACKAGE_DIR/stlport-libs-$ABI.tar.bz2"
175 pack_archive "$PACKAGE" "$NDK_DIR" "$FILES"
176 fail_panic "Could not package $ABI STLport binaries!"
177 dump "Packaging: $PACKAGE"
181 if [ -n "$PACKAGE_DIR" ] ; then
182 dump "Cleaning up..."