blob: 7a94ec2f2596e190854b6a43d458eaea28edd430 [file] [log] [blame]
David 'Digit' Turner46be4872009-06-04 16:07:01 +02001#!/bin/sh
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08002#
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`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080019
David 'Digit' Turner46be4872009-06-04 16:07:01 +020020# source common functions definitions
21. android/build/common.sh
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080022
23# Parse options
24OPTION_TARGETS=""
25OPTION_DEBUG=no
26OPTION_IGNORE_AUDIO=no
27OPTION_NO_PREBUILTS=no
28OPTION_TRY_64=no
29OPTION_HELP=no
30
31if [ -z "$CC" ] ; then
32 CC=gcc
33fi
34
35for opt do
36 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
37 case "$opt" in
38 --help|-h|-\?) OPTION_HELP=yes
39 ;;
40 --verbose)
41 if [ "$VERBOSE" = "yes" ] ; then
42 VERBOSE2=yes
43 else
44 VERBOSE=yes
45 fi
46 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +020047 --install=*) OPTION_TARGETS="$OPTION_TARGETS $optarg";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080048 ;;
49 --sdl-config=*) SDL_CONFIG=$optarg
50 ;;
51 --cc=*) CC="$optarg" ; HOSTCC=$CC
52 ;;
53 --no-strip) OPTION_NO_STRIP=yes
54 ;;
55 --debug) OPTION_DEBUG=yes
56 ;;
57 --ignore-audio) OPTION_IGNORE_AUDIO=yes
58 ;;
59 --no-prebuilts) OPTION_NO_PREBUILTS=yes
60 ;;
61 --try-64) OPTION_TRY_64=yes
62 ;;
63 *)
64 echo "unknown option '$opt', use --help"
65 exit 1
66 esac
67done
68
69# Print the help message
70#
71if [ "$OPTION_HELP" = "yes" ] ; then
72 cat << EOF
73
74Usage: rebuild.sh [options]
75Options: [defaults in brackets after descriptions]
76EOF
77 echo "Standard options:"
78 echo " --help print this message"
79 echo " --install=FILEPATH copy emulator executable to FILEPATH [$TARGETS]"
80 echo " --cc=PATH specify C compiler [$CC]"
81 echo " --sdl-config=FILE use specific sdl-config script [$SDL_CONFIG]"
82 echo " --no-strip do not strip emulator executable"
83 echo " --debug enable debug (-O0 -g) build"
84 echo " --ignore-audio ignore audio messages (may build sound-less emulator)"
85 echo " --no-prebuilts do not use prebuilt libraries and compiler"
86 echo " --try-64 try to build a 64-bit executable (may crash)"
87 echo " --verbose verbose configuration"
88 echo ""
89 exit 1
90fi
91
David 'Digit' Turner46be4872009-06-04 16:07:01 +020092# we only support generating 32-bit binaris on 64-bit systems.
93# And we may need to add a -Wa,--32 to CFLAGS to let the assembler
94# generate 32-bit binaries on Linux x86_64.
95#
96if [ "$OPTION_TRY_64" != "yes" ] ; then
97 force_32bit_binaries
98fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080099
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200100# Are we running in the Android build system ?
101check_android_build
102
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800103
104# Adjust a few things when we're building within the Android build
105# system:
106# - locate prebuilt directory
107# - locate and use prebuilt libraries
108# - copy the new binary to the correct location
109#
110if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then
111 IN_ANDROID_BUILD=no
112fi
113
114if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200115 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800116
117 # use ccache if USE_CCACHE is defined and the corresponding
118 # binary is available.
119 #
120 # note: located in PREBUILT/ccache/ccache in the new tree layout
121 # located in PREBUILT/ccache in the old one
122 #
123 if [ -n "$USE_CCACHE" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200124 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800125 if [ ! -f $CCACHE ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200126 CCACHE="$ANDROID_PREBUILT/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800127 fi
128 if [ -f $CCACHE ] ; then
129 CC="$CCACHE $CC"
130 fi
131 log "Prebuilt : CCACHE=$CCACHE"
132 fi
133
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200134 # if the user didn't specify an sdl-config script, get the prebuilt one
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800135 if [ -z "$SDL_CONFIG" -a "$OPTION_NO_PREBUILTS" = "no" ] ; then
136 # always use our own static libSDL by default
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200137 SDL_CONFIG=$ANDROID_PREBUILT/sdl/bin/sdl-config
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800138 log "Prebuilt : SDL_CONFIG=$SDL_CONFIG"
139 fi
140
141 # finally ensure that our new binary is copied to the 'out'
142 # subdirectory as 'emulator'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200143 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800144 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200145 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
146 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800147 fi
148fi # IN_ANDROID_BUILD = no
149
150
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200151# we can build the emulator with Cygwin, so enable it
152enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800153
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200154setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800155
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800156###
157### SDL Probe
158###
159
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200160# if the user didn't specify a sdl-config script, get the prebuilt one
161if [ -z "$SDL_CONFIG" -a "$OPTION_NO_PREBUILTS" = "no" ] ; then
162 # try to find one from our git repository
163 SDL_CONFIG=../sdl/out/$OS/bin/sdl-config
164 if [ -f $SDL_CONFIG ] ; then
165 log "Prebuilt : SDL_CONFIG=$SDL_CONFIG"
166 else
167 echo "WARNING: YOU SHOULD USE THE --sdl-config OPTION"
168 SDL_CONFIG=
169 fi
170fi
171
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800172# For now, we require an external libSDL library, if SDL_CONFIG is not
173# defined, try to grab it from the environment
174#
175if [ -z "$SDL_CONFIG" ] ; then
176 SDL_CONFIG=`which sdl-config`
177 if [ $? != 0 ] ; then
178 echo "Please ensure that you have the emulator's patched libSDL"
179 echo "built somewhere and point to its sdl-config script either"
180 echo "with the SDL_CONFIG env. variable, or the --sdl-config=<script>"
181 echo "option."
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200182 clean_exit
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800183 fi
184fi
185
186# check that we can link statically with the library.
187#
188SDL_CFLAGS=`$SDL_CONFIG --cflags`
189SDL_LIBS=`$SDL_CONFIG --static-libs`
190
191# quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
192# since they break recent Mingw releases
193SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
194
195log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
196log "SDL-probe : SDL_LIBS = $SDL_LIBS"
197
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800198
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200199EXTRA_CFLAGS="$SDL_CFLAGS"
200EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800201
202cat > $TMPC << EOF
203#include <SDL.h>
204#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200205int main( int argc, char** argv ) {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800206 return SDL_Init (SDL_INIT_VIDEO);
207}
208EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200209feature_check_link SDL_LINKING
210
211if [ $SDL_LINKING != "yes" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800212 echo "You provided an explicit sdl-config script, but the corresponding library"
213 echo "cannot be statically linked with the Android emulator directly."
214 echo "Error message:"
215 cat $TMPL
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200216 clean_exit
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800217fi
218log "SDL-probe : static linking ok"
219
220# now, let's check that the SDL library has the special functions
221# we added to our own sources
222#
223cat > $TMPC << EOF
224#include <SDL.h>
225#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200226int main( int argc, char** argv ) {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800227 int x, y;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200228 SDL_Rect r;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800229 SDL_WM_GetPos(&x, &y);
230 SDL_WM_SetPos(x, y);
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200231 SDL_WM_GetMonitorDPI(&x, &y);
232 SDL_WM_GetMonitorRect(&r);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800233 return SDL_Init (SDL_INIT_VIDEO);
234}
235EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200236feature_check_link SDL_LINKING
237
238if [ $SDL_LINKING != "yes" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800239 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
240 echo "corresponding library doesn't have the patches required to link"
241 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
242 echo "sources bundled with the emulator instead"
243 echo "Error:"
244 cat $TMPL
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200245 clean_exit
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800246fi
247
248log "SDL-probe : extra features ok"
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200249clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800250
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200251EXTRA_CFLAGS=
252EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800253
254###
255### Audio subsystems probes
256###
257PROBE_COREAUDIO=no
258PROBE_ALSA=no
259PROBE_OSS=no
260PROBE_ESD=no
261PROBE_WINAUDIO=no
262
263case "$OS" in
264 darwin*) PROBE_COREAUDIO=yes;
265 ;;
266 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes;
267 ;;
268 windows) PROBE_WINAUDIO=yes
269 ;;
270esac
271
272ORG_CFLAGS=$CFLAGS
273ORG_LDFLAGS=$LDFLAGS
274
275if [ "$PROBE_ESD" = yes ] ; then
276 CFLAGS="$ORG_CFLAGS"
277 LDFLAGS="$ORG_LDFLAGS -ldl"
278 cp -f android/config/check-esd.c $TMPC
279 compile && link && $TMPE
280 if [ $? = 0 ] ; then
281 log "AudioProbe : ESD seems to be usable on this system"
282 else
283 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
284 echo "the EsounD development files do not seem to be installed on this system"
285 echo "Are you missing the libesd-dev package ?"
286 echo "Correct the errors below and try again:"
287 cat $TMPL
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200288 clean_exit
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800289 fi
290 PROBE_ESD=no
291 log "AudioProbe : ESD seems to be UNUSABLE on this system !!"
292 fi
293fi
294
295if [ "$PROBE_ALSA" = yes ] ; then
296 CFLAGS="$ORG_CFLAGS"
297 LDFLAGS="$ORG_CFLAGS -ldl"
298 cp -f android/config/check-alsa.c $TMPC
299 compile && link && $TMPE
300 if [ $? = 0 ] ; then
301 log "AudioProbe : ALSA seems to be usable on this system"
302 else
303 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
304 echo "the ALSA development files do not seem to be installed on this system"
305 echo "Are you missing the libasound-dev package ?"
306 echo "Correct the erros below and try again"
307 cat $TMPL
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200308 clean_exit
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800309 fi
310 PROBE_ALSA=no
311 log "AudioProbe : ALSA seems to be UNUSABLE on this system !!"
312 fi
313fi
314
315CFLAGS=$ORG_CFLAGS
316LDFLAGS=$ORG_LDFLAGS
317
318# create the objs directory that is going to contain all generated files
319# including the configuration ones
320#
321mkdir -p objs
322
323###
324### Compiler probe
325###
326
327####
328#### Host system probe
329####
330
331# because the previous version could be read-only
332rm -f $TMPC
333
334# check host endianess
335#
336HOST_BIGENDIAN=no
337cat > $TMPC << EOF
338#include <inttypes.h>
339int main(int argc, char ** argv){
340 volatile uint32_t i=0x01234567;
341 return (*((uint8_t*)(&i))) == 0x67;
342}
343EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200344feature_run_exec HOST_BIGENDIAN
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800345
346# check size of host long bits
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800347cat > $TMPC << EOF
348int main(void) {
349 return sizeof(void*)*8;
350}
351EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200352feature_run_exec HOST_LONGBITS
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800353
354# check whether we have <byteswap.h>
355#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200356feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800357
358# Build the config.make file
359#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200360
361create_config_mk
362
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800363PWD=`pwd`
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200364echo "TARGET_ARCH := arm" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800365echo "SRC_PATH := $PWD" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800366echo "SDL_CONFIG := $SDL_CONFIG" >> $config_mk
367echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
368echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
369echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
370echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
371echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800372echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800373
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800374
375# Build the config-host.h file
376#
377config_h=objs/config-host.h
378echo "/* This file was autogenerated by '$PROGNAME' */" > $config_h
379echo "#define CONFIG_QEMU_SHAREDIR \"/usr/local/share/qemu\"" >> $config_h
380echo "#define HOST_LONG_BITS $HOST_LONGBITS" >> $config_h
381if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
382 echo "#define HAVE_BYTESWAP_H 1" >> $config_h
383fi
384echo "#define CONFIG_GDBSTUB 1" >> $config_h
385echo "#define CONFIG_SLIRP 1" >> $config_h
386echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200387echo "#define CONFIG_TRACE 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800388# the -nand-limits options can only work on non-windows systems
389if [ "$OS" != "windows" ] ; then
390 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
391fi
392echo "#define QEMU_VERSION \"0.8.2\"" >> $config_h
393case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200394 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800395 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200396 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800397 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200398 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800399 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200400 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800401 ;;
402esac
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200403echo "#define HOST_$CONFIG_CPU 1" >> $config_h
404BSD=0
405case "$OS" in
406 linux-*) CONFIG_OS=LINUX
407 ;;
408 darwin-*) CONFIG_OS=DARWIN
409 BSD=1
410 ;;
411 windows*) CONFIG_OS=WIN32
412 ;;
413 *) CONFIG_OS=$OS
414esac
415echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
416if [ $BSD = 1 ] ; then
417 echo "#define _BSD 1" >> $config_h
418 echo "#define O_LARGEFILE 0" >> $config_h
419 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
420fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800421log "Generate : $config_h"
422
423echo "Ready to go. Type 'make' to build emulator"