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