android-configure.sh revision c00d702076d1c3f5d0c33f522d0743593c0c3cd4
1#!/bin/sh 2# 3# this script is used to rebuild the Android emulator from sources 4# in the current directory. It also contains logic to speed up the 5# rebuild if it detects that you're using the Android build system 6# 7# in this case, it will use prebuilt binaries for the compiler, 8# the audio library and the SDL library. You can disable this 9# by using the --no-prebuilt-libs and --cc=<compiler> options 10# 11# 12# here's the list of environment variables you can define before 13# calling this script to control it (besides options): 14# 15# 16 17# first, let's see which system we're running this on 18cd `dirname $0` 19 20# source common functions definitions 21. android/build/common.sh 22 23# Parse options 24OPTION_TARGETS="" 25OPTION_DEBUG=no 26OPTION_IGNORE_AUDIO=no 27OPTION_NO_PREBUILTS=no 28OPTION_TRY_64=no 29OPTION_HELP=no 30OPTION_DEBUG=no 31 32if [ -z "$CC" ] ; then 33 CC=gcc 34fi 35 36for opt do 37 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` 38 case "$opt" in 39 --help|-h|-\?) OPTION_HELP=yes 40 ;; 41 --verbose) 42 if [ "$VERBOSE" = "yes" ] ; then 43 VERBOSE2=yes 44 else 45 VERBOSE=yes 46 fi 47 ;; 48 --debug) OPTION_DEBUG=yes 49 ;; 50 --install=*) OPTION_TARGETS="$OPTION_TARGETS $optarg"; 51 ;; 52 --sdl-config=*) SDL_CONFIG=$optarg 53 ;; 54 --cc=*) CC="$optarg" ; HOSTCC=$CC 55 ;; 56 --no-strip) OPTION_NO_STRIP=yes 57 ;; 58 --debug) OPTION_DEBUG=yes 59 ;; 60 --ignore-audio) OPTION_IGNORE_AUDIO=yes 61 ;; 62 --no-prebuilts) OPTION_NO_PREBUILTS=yes 63 ;; 64 --try-64) OPTION_TRY_64=yes 65 ;; 66 *) 67 echo "unknown option '$opt', use --help" 68 exit 1 69 esac 70done 71 72# Print the help message 73# 74if [ "$OPTION_HELP" = "yes" ] ; then 75 cat << EOF 76 77Usage: rebuild.sh [options] 78Options: [defaults in brackets after descriptions] 79EOF 80 echo "Standard options:" 81 echo " --help print this message" 82 echo " --install=FILEPATH copy emulator executable to FILEPATH [$TARGETS]" 83 echo " --cc=PATH specify C compiler [$CC]" 84 echo " --sdl-config=FILE use specific sdl-config script [$SDL_CONFIG]" 85 echo " --no-strip do not strip emulator executable" 86 echo " --debug enable debug (-O0 -g) build" 87 echo " --ignore-audio ignore audio messages (may build sound-less emulator)" 88 echo " --no-prebuilts do not use prebuilt libraries and compiler" 89 echo " --try-64 try to build a 64-bit executable (may crash)" 90 echo " --verbose verbose configuration" 91 echo " --debug build debug version of the emulator" 92 echo "" 93 exit 1 94fi 95 96# we only support generating 32-bit binaris on 64-bit systems. 97# And we may need to add a -Wa,--32 to CFLAGS to let the assembler 98# generate 32-bit binaries on Linux x86_64. 99# 100if [ "$OPTION_TRY_64" != "yes" ] ; then 101 force_32bit_binaries 102fi 103 104# Are we running in the Android build system ? 105check_android_build 106 107 108# Adjust a few things when we're building within the Android build 109# system: 110# - locate prebuilt directory 111# - locate and use prebuilt libraries 112# - copy the new binary to the correct location 113# 114if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then 115 IN_ANDROID_BUILD=no 116fi 117 118if [ "$IN_ANDROID_BUILD" = "yes" ] ; then 119 locate_android_prebuilt 120 121 # use ccache if USE_CCACHE is defined and the corresponding 122 # binary is available. 123 # 124 # note: located in PREBUILT/ccache/ccache in the new tree layout 125 # located in PREBUILT/ccache in the old one 126 # 127 if [ -n "$USE_CCACHE" ] ; then 128 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE" 129 if [ ! -f $CCACHE ] ; then 130 CCACHE="$ANDROID_PREBUILT/ccache$EXE" 131 fi 132 if [ -f $CCACHE ] ; then 133 CC="$CCACHE $CC" 134 fi 135 log "Prebuilt : CCACHE=$CCACHE" 136 fi 137 138 # if the user didn't specify an sdl-config script, get the prebuilt one 139 if [ -z "$SDL_CONFIG" -a "$OPTION_NO_PREBUILTS" = "no" ] ; then 140 # always use our own static libSDL by default 141 SDL_CONFIG=$ANDROID_PREBUILT/sdl/bin/sdl-config 142 log "Prebuilt : SDL_CONFIG=$SDL_CONFIG" 143 fi 144 145 # finally ensure that our new binary is copied to the 'out' 146 # subdirectory as 'emulator' 147 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES) 148 if [ -n "$HOST_BIN" ] ; then 149 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE" 150 log "Targets : TARGETS=$OPTION_TARGETS" 151 fi 152fi # IN_ANDROID_BUILD = no 153 154 155# we can build the emulator with Cygwin, so enable it 156enable_cygwin 157 158setup_toolchain 159 160### 161### SDL Probe 162### 163 164# if the user didn't specify a sdl-config script, get the prebuilt one 165if [ -z "$SDL_CONFIG" -a "$OPTION_NO_PREBUILTS" = "no" ] ; then 166 # try to find one from our git repository 167 SDL_CONFIG=../sdl/out/$OS/bin/sdl-config 168 if [ -f $SDL_CONFIG ] ; then 169 log "Prebuilt : SDL_CONFIG=$SDL_CONFIG" 170 else 171 echo "WARNING: YOU SHOULD USE THE --sdl-config OPTION" 172 SDL_CONFIG= 173 fi 174fi 175 176# For now, we require an external libSDL library, if SDL_CONFIG is not 177# defined, try to grab it from the environment 178# 179if [ -z "$SDL_CONFIG" ] ; then 180 SDL_CONFIG=`which sdl-config` 181 if [ $? != 0 ] ; then 182 echo "Please ensure that you have the emulator's patched libSDL" 183 echo "built somewhere and point to its sdl-config script either" 184 echo "with the SDL_CONFIG env. variable, or the --sdl-config=<script>" 185 echo "option." 186 clean_exit 187 fi 188fi 189 190# check that we can link statically with the library. 191# 192SDL_CFLAGS=`$SDL_CONFIG --cflags` 193SDL_LIBS=`$SDL_CONFIG --static-libs` 194 195# quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags 196# since they break recent Mingw releases 197SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g` 198 199log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS" 200log "SDL-probe : SDL_LIBS = $SDL_LIBS" 201 202 203EXTRA_CFLAGS="$SDL_CFLAGS" 204EXTRA_LDFLAGS="$SDL_LIBS" 205 206case "$OS" in 207 freebsd-*) 208 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread" 209 ;; 210esac 211 212cat > $TMPC << EOF 213#include <SDL.h> 214#undef main 215int main( int argc, char** argv ) { 216 return SDL_Init (SDL_INIT_VIDEO); 217} 218EOF 219feature_check_link SDL_LINKING 220 221if [ $SDL_LINKING != "yes" ] ; then 222 echo "You provided an explicit sdl-config script, but the corresponding library" 223 echo "cannot be statically linked with the Android emulator directly." 224 echo "Error message:" 225 cat $TMPL 226 clean_exit 227fi 228log "SDL-probe : static linking ok" 229 230# now, let's check that the SDL library has the special functions 231# we added to our own sources 232# 233cat > $TMPC << EOF 234#include <SDL.h> 235#undef main 236int main( int argc, char** argv ) { 237 int x, y; 238 SDL_Rect r; 239 SDL_WM_GetPos(&x, &y); 240 SDL_WM_SetPos(x, y); 241 SDL_WM_GetMonitorDPI(&x, &y); 242 SDL_WM_GetMonitorRect(&r); 243 return SDL_Init (SDL_INIT_VIDEO); 244} 245EOF 246feature_check_link SDL_LINKING 247 248if [ $SDL_LINKING != "yes" ] ; then 249 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the" 250 echo "corresponding library doesn't have the patches required to link" 251 echo "with the Android emulator. Unsetting SDL_CONFIG will use the" 252 echo "sources bundled with the emulator instead" 253 echo "Error:" 254 cat $TMPL 255 clean_exit 256fi 257 258log "SDL-probe : extra features ok" 259clean_temp 260 261EXTRA_CFLAGS= 262EXTRA_LDFLAGS= 263 264### 265### Audio subsystems probes 266### 267PROBE_COREAUDIO=no 268PROBE_ALSA=no 269PROBE_OSS=no 270PROBE_ESD=no 271PROBE_WINAUDIO=no 272 273case "$OS" in 274 darwin*) PROBE_COREAUDIO=yes; 275 ;; 276 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; 277 ;; 278 freebsd-*) PROBE_OSS=yes; 279 ;; 280 windows) PROBE_WINAUDIO=yes 281 ;; 282esac 283 284ORG_CFLAGS=$CFLAGS 285ORG_LDFLAGS=$LDFLAGS 286 287if [ "$PROBE_ESD" = yes ] ; then 288 CFLAGS="$ORG_CFLAGS" 289 LDFLAGS="$ORG_LDFLAGS -ldl" 290 cp -f android/config/check-esd.c $TMPC 291 compile && link && $TMPE 292 if [ $? = 0 ] ; then 293 log "AudioProbe : ESD seems to be usable on this system" 294 else 295 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then 296 echo "the EsounD development files do not seem to be installed on this system" 297 echo "Are you missing the libesd-dev package ?" 298 echo "Correct the errors below and try again:" 299 cat $TMPL 300 clean_exit 301 fi 302 PROBE_ESD=no 303 log "AudioProbe : ESD seems to be UNUSABLE on this system !!" 304 fi 305fi 306 307if [ "$PROBE_ALSA" = yes ] ; then 308 CFLAGS="$ORG_CFLAGS" 309 LDFLAGS="$ORG_CFLAGS -ldl" 310 cp -f android/config/check-alsa.c $TMPC 311 compile && link && $TMPE 312 if [ $? = 0 ] ; then 313 log "AudioProbe : ALSA seems to be usable on this system" 314 else 315 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then 316 echo "the ALSA development files do not seem to be installed on this system" 317 echo "Are you missing the libasound-dev package ?" 318 echo "Correct the erros below and try again" 319 cat $TMPL 320 clean_exit 321 fi 322 PROBE_ALSA=no 323 log "AudioProbe : ALSA seems to be UNUSABLE on this system !!" 324 fi 325fi 326 327CFLAGS=$ORG_CFLAGS 328LDFLAGS=$ORG_LDFLAGS 329 330# create the objs directory that is going to contain all generated files 331# including the configuration ones 332# 333mkdir -p objs 334 335### 336### Compiler probe 337### 338 339#### 340#### Host system probe 341#### 342 343# because the previous version could be read-only 344rm -f $TMPC 345 346# check host endianess 347# 348HOST_BIGENDIAN=no 349cat > $TMPC << EOF 350#include <inttypes.h> 351int main(int argc, char ** argv){ 352 volatile uint32_t i=0x01234567; 353 return (*((uint8_t*)(&i))) == 0x67; 354} 355EOF 356feature_run_exec HOST_BIGENDIAN 357 358# check size of host long bits 359cat > $TMPC << EOF 360int main(void) { 361 return sizeof(void*)*8; 362} 363EOF 364feature_run_exec HOST_LONGBITS 365 366# check whether we have <byteswap.h> 367# 368feature_check_header HAVE_BYTESWAP_H "<byteswap.h>" 369 370# Build the config.make file 371# 372 373create_config_mk 374 375PWD=`pwd` 376echo "TARGET_ARCH := arm" >> $config_mk 377echo "SRC_PATH := $PWD" >> $config_mk 378echo "SDL_CONFIG := $SDL_CONFIG" >> $config_mk 379echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk 380echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk 381echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk 382echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk 383echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk 384echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk 385if [ $OPTION_DEBUG = yes ] ; then 386 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk 387fi 388 389# Build the config-host.h file 390# 391config_h=objs/config-host.h 392echo "/* This file was autogenerated by '$PROGNAME' */" > $config_h 393echo "#define CONFIG_QEMU_SHAREDIR \"/usr/local/share/qemu\"" >> $config_h 394echo "#define HOST_LONG_BITS $HOST_LONGBITS" >> $config_h 395if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then 396 echo "#define HAVE_BYTESWAP_H 1" >> $config_h 397fi 398echo "#define CONFIG_GDBSTUB 1" >> $config_h 399echo "#define CONFIG_SLIRP 1" >> $config_h 400echo "#define CONFIG_SKINS 1" >> $config_h 401echo "#define CONFIG_TRACE 1" >> $config_h 402# the -nand-limits options can only work on non-windows systems 403if [ "$OS" != "windows" ] ; then 404 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h 405fi 406echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h 407echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h 408case "$CPU" in 409 x86) CONFIG_CPU=I386 410 ;; 411 ppc) CONFIG_CPU=PPC 412 ;; 413 x86_64) CONFIG_CPU=X86_64 414 ;; 415 *) CONFIG_CPU=$CPU 416 ;; 417esac 418echo "#define HOST_$CONFIG_CPU 1" >> $config_h 419BSD=0 420case "$OS" in 421 linux-*) CONFIG_OS=LINUX 422 ;; 423 darwin-*) CONFIG_OS=DARWIN 424 BSD=1 425 ;; 426 freebsd-*) CONFIG_OS=FREEBSD 427 BSD=1 428 ;; 429 windows*) CONFIG_OS=WIN32 430 ;; 431 *) CONFIG_OS=$OS 432esac 433 434case $OS in 435 linux-*|darwin-*) 436 echo "#define HAVE_IOVEC 1" >> $config_h 437 ;; 438esac 439 440echo "#define CONFIG_$CONFIG_OS 1" >> $config_h 441if [ $BSD = 1 ] ; then 442 echo "#define _BSD 1" >> $config_h 443 echo "#define O_LARGEFILE 0" >> $config_h 444 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h 445fi 446 447log "Generate : $config_h" 448 449echo "Ready to go. Type 'make' to build emulator" 450