• 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
39The output will be placed in appropriate sub-directories of
40<ndk>/$STLPORT_SUBDIR, but you can override this with the --out-dir=<path>
41option.
42"
43
44PACKAGE_DIR=
45register_var_option "--package-dir=<path>" PACKAGE_DIR "Put prebuilt tarballs into <path>."
46
47NDK_DIR=
48register_var_option "--ndk-dir=<path>" NDK_DIR "Specify NDK root path for the build."
49
50BUILD_DIR=
51OPTION_BUILD_DIR=
52register_var_option "--build-dir=<path>" OPTION_BUILD_DIR "Specify temporary build dir."
53
54OUT_DIR=
55register_var_option "--out-dir=<path>" OUT_DIR "Specify output directory directly."
56
57ABIS="$PREBUILT_ABIS"
58register_var_option "--abis=<list>" ABIS "Specify list of target ABIs."
59
60NO_MAKEFILE=
61register_var_option "--no-makefile" NO_MAKEFILE "Do not use makefile to speed-up build"
62
63register_jobs_option
64
65extract_parameters "$@"
66
67ABIS=$(commas_to_spaces $ABIS)
68
69# Handle NDK_DIR
70if [ -z "$NDK_DIR" ] ; then
71    NDK_DIR=$ANDROID_NDK_ROOT
72    log "Auto-config: --ndk-dir=$NDK_DIR"
73else
74    if [ ! -d "$NDK_DIR" ] ; then
75        echo "ERROR: NDK directory does not exists: $NDK_DIR"
76        exit 1
77    fi
78fi
79
80if [ -z "$OPTION_BUILD_DIR" ]; then
81    BUILD_DIR=$NDK_TMPDIR/build-stlport
82else
83    BUILD_DIR=$OPTION_BUILD_DIR
84fi
85mkdir -p "$BUILD_DIR"
86fail_panic "Could not create build directory: $BUILD_DIR"
87
88GABIXX_SRCDIR=$ANDROID_NDK_ROOT/$GABIXX_SUBDIR
89GABIXX_CFLAGS="-fPIC -O2 -DANDROID -D__ANDROID__ -I$GABIXX_SRCDIR/include"
90GABIXX_CXXFLAGS="-fno-exceptions -frtti"
91GABIXX_SOURCES=$(cd $ANDROID_NDK_ROOT/$GABIXX_SUBDIR && ls src/*.cc)
92GABIXX_LDFLAGS=
93
94# Location of the STLPort source tree
95STLPORT_SRCDIR=$ANDROID_NDK_ROOT/$STLPORT_SUBDIR
96STLPORT_CFLAGS="-DGNU_SOURCE -fPIC -O2 -I$STLPORT_SRCDIR/stlport -DANDROID -D__ANDROID__"
97STLPORT_CFLAGS=$STLPORT_CFLAGS" -I$ANDROID_NDK_ROOT/$GABIXX_SUBDIR/include"
98STLPORT_CXXFLAGS="-fuse-cxa-atexit -fno-exceptions -frtti"
99STLPORT_SOURCES=\
100"src/dll_main.cpp \
101src/fstream.cpp \
102src/strstream.cpp \
103src/sstream.cpp \
104src/ios.cpp \
105src/stdio_streambuf.cpp \
106src/istream.cpp \
107src/ostream.cpp \
108src/iostream.cpp \
109src/codecvt.cpp \
110src/collate.cpp \
111src/ctype.cpp \
112src/monetary.cpp \
113src/num_get.cpp \
114src/num_put.cpp \
115src/num_get_float.cpp \
116src/num_put_float.cpp \
117src/numpunct.cpp \
118src/time_facets.cpp \
119src/messages.cpp \
120src/locale.cpp \
121src/locale_impl.cpp \
122src/locale_catalog.cpp \
123src/facets_byname.cpp \
124src/complex.cpp \
125src/complex_io.cpp \
126src/complex_trig.cpp \
127src/string.cpp \
128src/bitset.cpp \
129src/allocators.cpp \
130src/c_locale.c \
131src/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#
137if [ -z "$NO_MAKEFILE" ]; then
138    MAKEFILE=$BUILD_DIR/Makefile
139else
140    MAKEFILE=
141fi
142
143build_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
185for ABI in $ABIS; do
186    build_stlport_libs_for_abi $ABI "$BUILD_DIR/$ABI"
187done
188
189# If needed, package files into tarballs
190if [ -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
202fi
203
204if [ -z "$OPTION_BUILD_DIR" ]; then
205    log "Cleaning up..."
206    rm -rf $BUILD_DIR
207else
208    log "Don't forget to cleanup: $BUILD_DIR"
209fi
210
211log "Done!"
212