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 . `dirname $0`/builder-funcs.sh 24 25 PROGRAM_PARAMETERS="" 26 27 PROGRAM_DESCRIPTION=\ 28 "Rebuild the prebuilt STLport binaries for the Android NDK. 29 30 This script is called when packaging a new NDK release. It will simply 31 rebuild the STLport static and shared libraries from sources. 32 33 This requires a temporary NDK installation containing platforms and 34 toolchain binaries for all target architectures. 35 36 By default, this will try with the current NDK directory, unless 37 you use the --ndk-dir=<path> option. 38 39 The output will be placed in appropriate sub-directories of 40 <ndk>/$STLPORT_SUBDIR, but you can override this with the --out-dir=<path> 41 option. 42 " 43 44 PACKAGE_DIR= 45 register_var_option "--package-dir=<path>" PACKAGE_DIR "Put prebuilt tarballs into <path>." 46 47 NDK_DIR= 48 register_var_option "--ndk-dir=<path>" NDK_DIR "Specify NDK root path for the build." 49 50 BUILD_DIR= 51 OPTION_BUILD_DIR= 52 register_var_option "--build-dir=<path>" OPTION_BUILD_DIR "Specify temporary build dir." 53 54 OUT_DIR= 55 register_var_option "--out-dir=<path>" OUT_DIR "Specify output directory directly." 56 57 ABIS="$PREBUILT_ABIS" 58 register_var_option "--abis=<list>" ABIS "Specify list of target ABIs." 59 60 NO_MAKEFILE= 61 register_var_option "--no-makefile" NO_MAKEFILE "Do not use makefile to speed-up build" 62 63 register_jobs_option 64 65 extract_parameters "$@" 66 67 ABIS=$(commas_to_spaces $ABIS) 68 69 # Handle NDK_DIR 70 if [ -z "$NDK_DIR" ] ; then 71 NDK_DIR=$ANDROID_NDK_ROOT 72 log "Auto-config: --ndk-dir=$NDK_DIR" 73 else 74 if [ ! -d "$NDK_DIR" ] ; then 75 echo "ERROR: NDK directory does not exists: $NDK_DIR" 76 exit 1 77 fi 78 fi 79 80 if [ -z "$OPTION_BUILD_DIR" ]; then 81 BUILD_DIR=$NDK_TMPDIR/build-stlport 82 else 83 BUILD_DIR=$OPTION_BUILD_DIR 84 fi 85 mkdir -p "$BUILD_DIR" 86 fail_panic "Could not create build directory: $BUILD_DIR" 87 88 GABIXX_SRCDIR=$ANDROID_NDK_ROOT/$GABIXX_SUBDIR 89 GABIXX_CFLAGS="-fPIC -O2 -DANDROID -D__ANDROID__ -I$GABIXX_SRCDIR/include" 90 GABIXX_CXXFLAGS="-fno-exceptions -frtti" 91 GABIXX_SOURCES=$(cd $ANDROID_NDK_ROOT/$GABIXX_SUBDIR && ls src/*.cc) 92 GABIXX_LDFLAGS= 93 94 # Location of the STLPort source tree 95 STLPORT_SRCDIR=$ANDROID_NDK_ROOT/$STLPORT_SUBDIR 96 STLPORT_CFLAGS="-DGNU_SOURCE -fPIC -O2 -I$STLPORT_SRCDIR/stlport -DANDROID -D__ANDROID__" 97 STLPORT_CFLAGS=$STLPORT_CFLAGS" -I$ANDROID_NDK_ROOT/$GABIXX_SUBDIR/include" 98 STLPORT_CXXFLAGS="-fuse-cxa-atexit -fno-exceptions -frtti" 99 STLPORT_SOURCES=\ 100 "src/dll_main.cpp \ 101 src/fstream.cpp \ 102 src/strstream.cpp \ 103 src/sstream.cpp \ 104 src/ios.cpp \ 105 src/stdio_streambuf.cpp \ 106 src/istream.cpp \ 107 src/ostream.cpp \ 108 src/iostream.cpp \ 109 src/codecvt.cpp \ 110 src/collate.cpp \ 111 src/ctype.cpp \ 112 src/monetary.cpp \ 113 src/num_get.cpp \ 114 src/num_put.cpp \ 115 src/num_get_float.cpp \ 116 src/num_put_float.cpp \ 117 src/numpunct.cpp \ 118 src/time_facets.cpp \ 119 src/messages.cpp \ 120 src/locale.cpp \ 121 src/locale_impl.cpp \ 122 src/locale_catalog.cpp \ 123 src/facets_byname.cpp \ 124 src/complex.cpp \ 125 src/complex_io.cpp \ 126 src/complex_trig.cpp \ 127 src/string.cpp \ 128 src/bitset.cpp \ 129 src/allocators.cpp \ 130 src/c_locale.c \ 131 src/cxa.c" 132 133 # If the --no-makefile flag is not used, we're going to put all build 134 # commands in a temporary Makefile that we will be able to invoke with 135 # -j$NUM_JOBS to build stuff in parallel. 136 # 137 if [ -z "$NO_MAKEFILE" ]; then 138 MAKEFILE=$BUILD_DIR/Makefile 139 else 140 MAKEFILE= 141 fi 142 143 build_stlport_libs_for_abi () 144 { 145 local ARCH BINPREFIX SYSROOT 146 local ABI=$1 147 local BUILDDIR="$2" 148 local DSTDIR="$3" 149 local SRC OBJ OBJECTS CFLAGS CXXFLAGS 150 151 mkdir -p "$BUILDDIR" 152 153 # If the output directory is not specified, use default location 154 if [ -z "$DSTDIR" ]; then 155 DSTDIR=$NDK_DIR/$STLPORT_SUBDIR/libs/$ABI 156 fi 157 158 mkdir -p "$DSTDIR" 159 160 builder_begin_android $ABI "$BUILDDIR" "$MAKEFILE" 161 162 builder_set_dstdir "$DSTDIR" 163 164 builder_set_srcdir "$GABIXX_SRCDIR" 165 builder_cflags "$GABIXX_CFLAGS" 166 builder_cxxflags "$GABIXX_CXXFLAGS" 167 builder_ldflags "$GABIXX_LDFLAGS" 168 builder_sources $GABIXX_SOURCES 169 170 builder_set_srcdir "$STLPORT_SRCDIR" 171 builder_reset_cflags 172 builder_cflags "$STLPORT_CFLAGS" 173 builder_reset_cxxflags 174 builder_cxxflags "$STLPORT_CXXFLAGS" 175 builder_sources $STLPORT_SOURCES 176 177 log "Building $DSTDIR/libstlport_static.a" 178 builder_static_library libstlport_static 179 180 log "Building $DSTDIR/libstlport_shared.so" 181 builder_shared_library libstlport_shared 182 builder_end 183 } 184 185 for ABI in $ABIS; do 186 build_stlport_libs_for_abi $ABI "$BUILD_DIR/$ABI" 187 done 188 189 # If needed, package files into tarballs 190 if [ -n "$PACKAGE_DIR" ] ; then 191 for ABI in $ABIS; do 192 FILES="" 193 for LIB in libstlport_static.a libstlport_shared.so; do 194 FILES="$FILES $STLPORT_SUBDIR/libs/$ABI/$LIB" 195 done 196 PACKAGE="$PACKAGE_DIR/stlport-libs-$ABI.tar.bz2" 197 log "Packaging: $PACKAGE" 198 pack_archive "$PACKAGE" "$NDK_DIR" "$FILES" 199 fail_panic "Could not package $ABI STLport binaries!" 200 dump "Packaging: $PACKAGE" 201 done 202 fi 203 204 if [ -z "$OPTION_BUILD_DIR" ]; then 205 log "Cleaning up..." 206 rm -rf $BUILD_DIR 207 else 208 log "Don't forget to cleanup: $BUILD_DIR" 209 fi 210 211 log "Done!" 212