#!/bin/sh # # this script is used to rebuild the Android emulator from sources # in the current directory. It also contains logic to speed up the # rebuild if it detects that you're using the Android build system # # in this case, it will use prebuilt binaries for the compiler, # the audio library and the SDL library. You can disable this # by using the --no-prebuilt-libs and --cc= options # # # here's the list of environment variables you can define before # calling this script to control it (besides options): # # # first, let's see which system we're running this on cd `dirname $0` # source common functions definitions . android/build/common.sh # Parse options OPTION_TARGETS="" OPTION_DEBUG=no OPTION_IGNORE_AUDIO=no OPTION_NO_PREBUILTS=no OPTION_TRY_64=no OPTION_HELP=no OPTION_DEBUG=no OPTION_STATIC=no if [ -z "$CC" ] ; then CC=gcc fi for opt do optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` case "$opt" in --help|-h|-\?) OPTION_HELP=yes ;; --verbose) if [ "$VERBOSE" = "yes" ] ; then VERBOSE2=yes else VERBOSE=yes fi ;; --debug) OPTION_DEBUG=yes ;; --install=*) OPTION_TARGETS="$OPTION_TARGETS $optarg"; ;; --sdl-config=*) SDL_CONFIG=$optarg ;; --cc=*) CC="$optarg" ; HOSTCC=$CC ;; --no-strip) OPTION_NO_STRIP=yes ;; --debug) OPTION_DEBUG=yes ;; --ignore-audio) OPTION_IGNORE_AUDIO=yes ;; --no-prebuilts) OPTION_NO_PREBUILTS=yes ;; --try-64) OPTION_TRY_64=yes ;; --static) OPTION_STATIC=yes ;; *) echo "unknown option '$opt', use --help" exit 1 esac done # Print the help message # if [ "$OPTION_HELP" = "yes" ] ; then cat << EOF Usage: rebuild.sh [options] Options: [defaults in brackets after descriptions] EOF echo "Standard options:" echo " --help print this message" echo " --install=FILEPATH copy emulator executable to FILEPATH [$TARGETS]" echo " --cc=PATH specify C compiler [$CC]" echo " --sdl-config=FILE use specific sdl-config script [$SDL_CONFIG]" echo " --no-strip do not strip emulator executable" echo " --debug enable debug (-O0 -g) build" echo " --ignore-audio ignore audio messages (may build sound-less emulator)" echo " --no-prebuilts do not use prebuilt libraries and compiler" echo " --try-64 try to build a 64-bit executable (may crash)" echo " --static build a completely static executable" echo " --verbose verbose configuration" echo " --debug build debug version of the emulator" echo "" exit 1 fi # we only support generating 32-bit binaris on 64-bit systems. # And we may need to add a -Wa,--32 to CFLAGS to let the assembler # generate 32-bit binaries on Linux x86_64. # if [ "$OPTION_TRY_64" != "yes" ] ; then force_32bit_binaries fi # Are we running in the Android build system ? check_android_build # Adjust a few things when we're building within the Android build # system: # - locate prebuilt directory # - locate and use prebuilt libraries # - copy the new binary to the correct location # if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then IN_ANDROID_BUILD=no fi if [ "$IN_ANDROID_BUILD" = "yes" ] ; then locate_android_prebuilt # use ccache if USE_CCACHE is defined and the corresponding # binary is available. # # note: located in PREBUILT/ccache/ccache in the new tree layout # located in PREBUILT/ccache in the old one # if [ -n "$USE_CCACHE" ] ; then CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE" if [ ! -f $CCACHE ] ; then CCACHE="$ANDROID_PREBUILT/ccache$EXE" fi if [ -f $CCACHE ] ; then CC="$CCACHE $CC" fi log "Prebuilt : CCACHE=$CCACHE" fi # if the user didn't specify an sdl-config script, get the prebuilt one if [ -z "$SDL_CONFIG" -a "$OPTION_NO_PREBUILTS" = "no" ] ; then # always use our own static libSDL by default SDL_CONFIG=$ANDROID_PREBUILT/sdl/bin/sdl-config log "Prebuilt : SDL_CONFIG=$SDL_CONFIG" fi # finally ensure that our new binary is copied to the 'out' # subdirectory as 'emulator' HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES) if [ -n "$HOST_BIN" ] ; then OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE" log "Targets : TARGETS=$OPTION_TARGETS" fi # find the Android SDK Tools revision number TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties if [ -f $TOOLS_PROPS ] ; then ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null` log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION" else log "Tools : Could not locate $TOOLS_PROPS !?" fi fi # IN_ANDROID_BUILD = no # we can build the emulator with Cygwin, so enable it enable_cygwin setup_toolchain ### ### SDL Probe ### # if the user didn't specify a sdl-config script, get the prebuilt one if [ -z "$SDL_CONFIG" -a "$OPTION_NO_PREBUILTS" = "no" ] ; then # try to find one from our git repository SDL_CONFIG=../sdl/out/$OS/bin/sdl-config if [ -f $SDL_CONFIG ] ; then log "Prebuilt : SDL_CONFIG=$SDL_CONFIG" else echo "WARNING: YOU SHOULD USE THE --sdl-config OPTION" SDL_CONFIG= fi fi # For now, we require an external libSDL library, if SDL_CONFIG is not # defined, try to grab it from the environment # if [ -z "$SDL_CONFIG" ] ; then SDL_CONFIG=`which sdl-config` if [ $? != 0 ] ; then echo "Please ensure that you have the emulator's patched libSDL" echo "built somewhere and point to its sdl-config script either" echo "with the SDL_CONFIG env. variable, or the --sdl-config=