OSDN Git Service

original
[gb-231r1-is01/GB_2.3_IS01.git] / ndk / build / tools / build-stlport.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 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 shell script is used to rebuild the prebuilt STLport binaries from
18 #  their sources. It requires a working NDK installation.
19 #
20
21 # include common function and variable definitions
22 . `dirname $0`/prebuilt-common.sh
23
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
27
28 PROGRAM_PARAMETERS=""
29
30 PROGRAM_DESCRIPTION=\
31 "Rebuild the prebuilt STLport binaries for the Android NDK.
32
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.
36
37 By default, this will try with the current NDK directory, unless
38 you use the --ndk-dir=<path> option.
39
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>
42 option.
43 "
44
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>."
48
49 NDK_DIR=
50 register_var_option "--ndk-dir=<path>" NDK_DIR "Don't package, put the files in target NDK dir."
51
52 TOOLCHAIN_PKG=
53 register_var_option "--toolchain-pkg=<path>" TOOLCHAIN_PKG "Use specific toolchain prebuilt package."
54
55 BUILD_DIR=
56 OPTION_BUILD_DIR=
57 register_var_option "--build-dir=<path>" OPTION_BUILD_DIR "Specify temporary build dir."
58
59 OUT_DIR=
60 register_var_option "--out-dir=<path>" OUT_DIR "Specify output directory directly."
61
62 ABIS="$STLPORT_ABIS"
63 register_var_option "--abis=<list>" ABIS "Specify list of target ABIs."
64
65 extract_parameters "$@"
66
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!"
69     exit 1
70 fi
71
72 if [ -n "$TOOLCHAIN_PKG" ] ; then
73     if [ ! -f "$TOOLCHAIN_PKG" ] ; then
74         dump "ERROR: Your toolchain package does not exist: $TOOLCHAIN_PKG"
75         exit 1
76     fi
77     case "$TOOLCHAIN_PKG" in
78         *.tar.bz2)
79             ;;
80         *)
81             dump "ERROR: Toolchain package is not .tar.bz2 archive: $TOOLCHAIN_PKG"
82             exit 1
83     esac
84 fi
85
86 if [ -z "$NDK_DIR" ] ; then
87     mkdir -p "$PACKAGE_DIR"
88     if [ $? != 0 ] ; then
89         echo "ERROR: Could not create directory: $PACKAGE_DIR"
90         exit 1
91     fi
92     NDK_DIR=/tmp/ndk-toolchain/ndk-prebuilt-$$
93     mkdir -p $NDK_DIR &&
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"
99     fi
100 else
101     if [ ! -d "$NDK_DIR" ] ; then
102         echo "ERROR: NDK directory does not exists: $NDK_DIR"
103         exit 1
104     fi
105     PACKAGE_DIR=
106 fi
107
108 #
109 # Setup our paths
110 #
111 log "Using NDK root: $NDK_DIR"
112
113 BUILD_DIR="$OPTION_BUILD_DIR"
114 if [ -n "$BUILD_DIR" ] ; then
115     log "Using temporary build dir: $BUILD_DIR"
116 else
117     BUILD_DIR=`random_temp_directory`
118     log "Using random build dir: $BUILD_DIR"
119 fi
120 mkdir -p "$BUILD_DIR"
121
122 if [ -z "$OUT_DIR" ] ; then
123     OUT_DIR=$NDK_DIR/$STLPORT_SUBDIR
124     log "Using default output dir: $OUT_DIR"
125 else
126     log "Using usr output dir: $OUT_DIR"
127 fi
128
129 #
130 # Now build the fake project
131 #
132 # NOTE: We take the build project from this NDK's tree, not from
133 #        the alternative one specified with --ndk=<dir>
134 #
135 PROJECT_DIR="$ANDROID_NDK_ROOT/$PROJECT_SUBDIR"
136 if [ ! -d $PROJECT_DIR ] ; then
137     dump "ERROR: Missing required project: $PROJECT_SUBDIR"
138     exit 1
139 fi
140
141 # cleanup required to avoid problems with stale dependency files
142 rm -rf "$PROJECT_DIR/libs"
143 rm -rf "$PROJECT_DIR/obj"
144
145 LIBRARIES="libstlport_static.a libstlport_shared.so"
146
147 for ABI in $ABIS; do
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!!"
152         exit 1
153     fi
154
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"
160     fi
161 done
162
163 # If needed, package files into tarballs
164 if [ -n "$PACKAGE_DIR" ] ; then
165     for ABI in $ABIS; do
166         FILES=""
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"
173         done
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"
178     done
179 fi
180
181 if [ -n "$PACKAGE_DIR" ] ; then
182     dump "Cleaning up..."
183     rm -rf $NDK_DIR
184 fi
185
186 dump "Done!"