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