1 #!/bin/sh 2 # 3 # Copyright (C) 2011 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 GAbi++ 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 GAbi++ binaries for the Android NDK. 29 30 This script is called when packaging a new NDK release. It will simply 31 rebuild the GAbi++ 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>/$GABIXX_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-gabi++ 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 # Location of the GAbi++ source tree 89 GABIXX_SRCDIR=$ANDROID_NDK_ROOT/$GABIXX_SUBDIR 90 91 # Compiler flags we want to use 92 GABIXX_CFLAGS="-fPIC -O2 -DANDROID -D__ANDROID__" 93 GABIXX_CFLAGS=$GABIXX_CFLAGS" -I$GABIXX_SRCDIR/include" 94 GABIXX_CXXFLAGS="-fuse-cxa-atexit -fno-exceptions -frtti" 95 GABIXX_LDFLAGS= 96 97 # List of sources to compile 98 GABIXX_SOURCES=$(cd $GABIXX_SRCDIR && ls src/*.cc) 99 100 # If the --no-makefile flag is not used, we're going to put all build 101 # commands in a temporary Makefile that we will be able to invoke with 102 # -j$NUM_JOBS to build stuff in parallel. 103 # 104 if [ -z "$NO_MAKEFILE" ]; then 105 MAKEFILE=$BUILD_DIR/Makefile 106 else 107 MAKEFILE= 108 fi 109 110 build_gabixx_libs_for_abi () 111 { 112 local ARCH BINPREFIX 113 local ABI=$1 114 local BUILDDIR="$2" 115 local DSTDIR="$3" 116 local SRC OBJ OBJECTS CFLAGS CXXFLAGS 117 118 mkdir -p "$BUILDDIR" 119 120 # If the output directory is not specified, use default location 121 if [ -z "$DSTDIR" ]; then 122 DSTDIR=$NDK_DIR/$GABIXX_SUBDIR/libs/$ABI 123 fi 124 125 mkdir -p "$DSTDIR" 126 127 builder_begin_android $ABI "$BUILDDIR" "$MAKEFILE" 128 builder_set_srcdir "$GABIXX_SRCDIR" 129 builder_set_dstdir "$DSTDIR" 130 131 builder_cflags "$GABIXX_CFLAGS" 132 builder_cxxflags "$GABIXX_CXXFLAGS" 133 builder_ldflags "$GABIXX_LDFLAGS" 134 builder_sources $GABIXX_SOURCES 135 136 log "Building $DSTDIR/libgabi++_static.a" 137 builder_static_library libgabi++_static 138 139 log "Building $DSTDIR/libgabi++_shared.so" 140 builder_shared_library libgabi++_shared 141 builder_end 142 } 143 144 for ABI in $ABIS; do 145 build_gabixx_libs_for_abi $ABI "$BUILD_DIR/$ABI" 146 done 147 148 # If needed, package files into tarballs 149 if [ -n "$PACKAGE_DIR" ] ; then 150 for ABI in $ABIS; do 151 FILES="" 152 for LIB in libgabi++_static.a libgabi++_shared.so; do 153 FILES="$FILES $GABIXX_SUBDIR/libs/$ABI/$LIB" 154 done 155 PACKAGE="$PACKAGE_DIR/gabixx-libs-$ABI.tar.bz2" 156 log "Packaging: $PACKAGE" 157 pack_archive "$PACKAGE" "$NDK_DIR" "$FILES" 158 fail_panic "Could not package $ABI GAbi++ binaries!" 159 dump "Packaging: $PACKAGE" 160 done 161 fi 162 163 if [ -z "$OPTION_BUILD_DIR" ]; then 164 log "Cleaning up..." 165 rm -rf $BUILD_DIR 166 else 167 log "Don't forget to cleanup: $BUILD_DIR" 168 fi 169 170 log "Done!" 171