blob: 59ec9b46196550946472ab25c91846b3a805e958 [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
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +020030OPTION_DEBUG=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080031
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 ;;
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +020048 --debug) OPTION_DEBUG=yes
49 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +020050 --install=*) OPTION_TARGETS="$OPTION_TARGETS $optarg";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080051 ;;
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"
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +020091 echo " --debug build debug version of the emulator"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080092 echo ""
93 exit 1
94fi
95
David 'Digit' Turner46be4872009-06-04 16:07:01 +020096# 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
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800103
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200104# Are we running in the Android build system ?
105check_android_build
106
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800107
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
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200119 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800120
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
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200128 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800129 if [ ! -f $CCACHE ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200130 CCACHE="$ANDROID_PREBUILT/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800131 fi
132 if [ -f $CCACHE ] ; then
133 CC="$CCACHE $CC"
134 fi
135 log "Prebuilt : CCACHE=$CCACHE"
136 fi
137
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200138 # if the user didn't specify an sdl-config script, get the prebuilt one
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800139 if [ -z "$SDL_CONFIG" -a "$OPTION_NO_PREBUILTS" = "no" ] ; then
140 # always use our own static libSDL by default
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200141 SDL_CONFIG=$ANDROID_PREBUILT/sdl/bin/sdl-config
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800142 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'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200147 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800148 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200149 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
150 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800151 fi
152fi # IN_ANDROID_BUILD = no
153
154
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200155# we can build the emulator with Cygwin, so enable it
156enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800157
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200158setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800159
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800160###
161### SDL Probe
162###
163
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200164# 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
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800176# 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."
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200186 clean_exit
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800187 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
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800202
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200203EXTRA_CFLAGS="$SDL_CFLAGS"
204EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800205
206cat > $TMPC << EOF
207#include <SDL.h>
208#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200209int main( int argc, char** argv ) {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800210 return SDL_Init (SDL_INIT_VIDEO);
211}
212EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200213feature_check_link SDL_LINKING
214
215if [ $SDL_LINKING != "yes" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800216 echo "You provided an explicit sdl-config script, but the corresponding library"
217 echo "cannot be statically linked with the Android emulator directly."
218 echo "Error message:"
219 cat $TMPL
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200220 clean_exit
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800221fi
222log "SDL-probe : static linking ok"
223
224# now, let's check that the SDL library has the special functions
225# we added to our own sources
226#
227cat > $TMPC << EOF
228#include <SDL.h>
229#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200230int main( int argc, char** argv ) {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800231 int x, y;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200232 SDL_Rect r;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800233 SDL_WM_GetPos(&x, &y);
234 SDL_WM_SetPos(x, y);
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200235 SDL_WM_GetMonitorDPI(&x, &y);
236 SDL_WM_GetMonitorRect(&r);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800237 return SDL_Init (SDL_INIT_VIDEO);
238}
239EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200240feature_check_link SDL_LINKING
241
242if [ $SDL_LINKING != "yes" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800243 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
244 echo "corresponding library doesn't have the patches required to link"
245 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
246 echo "sources bundled with the emulator instead"
247 echo "Error:"
248 cat $TMPL
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200249 clean_exit
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800250fi
251
252log "SDL-probe : extra features ok"
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200253clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800254
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200255EXTRA_CFLAGS=
256EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800257
258###
259### Audio subsystems probes
260###
261PROBE_COREAUDIO=no
262PROBE_ALSA=no
263PROBE_OSS=no
264PROBE_ESD=no
265PROBE_WINAUDIO=no
266
267case "$OS" in
268 darwin*) PROBE_COREAUDIO=yes;
269 ;;
270 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes;
271 ;;
272 windows) PROBE_WINAUDIO=yes
273 ;;
274esac
275
276ORG_CFLAGS=$CFLAGS
277ORG_LDFLAGS=$LDFLAGS
278
279if [ "$PROBE_ESD" = yes ] ; then
280 CFLAGS="$ORG_CFLAGS"
281 LDFLAGS="$ORG_LDFLAGS -ldl"
282 cp -f android/config/check-esd.c $TMPC
283 compile && link && $TMPE
284 if [ $? = 0 ] ; then
285 log "AudioProbe : ESD seems to be usable on this system"
286 else
287 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
288 echo "the EsounD development files do not seem to be installed on this system"
289 echo "Are you missing the libesd-dev package ?"
290 echo "Correct the errors below and try again:"
291 cat $TMPL
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200292 clean_exit
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800293 fi
294 PROBE_ESD=no
295 log "AudioProbe : ESD seems to be UNUSABLE on this system !!"
296 fi
297fi
298
299if [ "$PROBE_ALSA" = yes ] ; then
300 CFLAGS="$ORG_CFLAGS"
301 LDFLAGS="$ORG_CFLAGS -ldl"
302 cp -f android/config/check-alsa.c $TMPC
303 compile && link && $TMPE
304 if [ $? = 0 ] ; then
305 log "AudioProbe : ALSA seems to be usable on this system"
306 else
307 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
308 echo "the ALSA development files do not seem to be installed on this system"
309 echo "Are you missing the libasound-dev package ?"
310 echo "Correct the erros below and try again"
311 cat $TMPL
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200312 clean_exit
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800313 fi
314 PROBE_ALSA=no
315 log "AudioProbe : ALSA seems to be UNUSABLE on this system !!"
316 fi
317fi
318
319CFLAGS=$ORG_CFLAGS
320LDFLAGS=$ORG_LDFLAGS
321
322# create the objs directory that is going to contain all generated files
323# including the configuration ones
324#
325mkdir -p objs
326
327###
328### Compiler probe
329###
330
331####
332#### Host system probe
333####
334
335# because the previous version could be read-only
336rm -f $TMPC
337
338# check host endianess
339#
340HOST_BIGENDIAN=no
341cat > $TMPC << EOF
342#include <inttypes.h>
343int main(int argc, char ** argv){
344 volatile uint32_t i=0x01234567;
345 return (*((uint8_t*)(&i))) == 0x67;
346}
347EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200348feature_run_exec HOST_BIGENDIAN
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800349
350# check size of host long bits
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800351cat > $TMPC << EOF
352int main(void) {
353 return sizeof(void*)*8;
354}
355EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200356feature_run_exec HOST_LONGBITS
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800357
358# check whether we have <byteswap.h>
359#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200360feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800361
362# Build the config.make file
363#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200364
365create_config_mk
366
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800367PWD=`pwd`
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200368echo "TARGET_ARCH := arm" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800369echo "SRC_PATH := $PWD" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800370echo "SDL_CONFIG := $SDL_CONFIG" >> $config_mk
371echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
372echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
373echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
374echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
375echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800376echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200377if [ $OPTION_DEBUG = yes ] ; then
378 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
379fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800380
381# Build the config-host.h file
382#
383config_h=objs/config-host.h
384echo "/* This file was autogenerated by '$PROGNAME' */" > $config_h
385echo "#define CONFIG_QEMU_SHAREDIR \"/usr/local/share/qemu\"" >> $config_h
386echo "#define HOST_LONG_BITS $HOST_LONGBITS" >> $config_h
387if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
388 echo "#define HAVE_BYTESWAP_H 1" >> $config_h
389fi
390echo "#define CONFIG_GDBSTUB 1" >> $config_h
391echo "#define CONFIG_SLIRP 1" >> $config_h
392echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200393echo "#define CONFIG_TRACE 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800394# the -nand-limits options can only work on non-windows systems
395if [ "$OS" != "windows" ] ; then
396 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
397fi
398echo "#define QEMU_VERSION \"0.8.2\"" >> $config_h
399case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200400 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800401 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200402 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800403 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200404 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800405 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200406 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800407 ;;
408esac
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200409echo "#define HOST_$CONFIG_CPU 1" >> $config_h
410BSD=0
411case "$OS" in
412 linux-*) CONFIG_OS=LINUX
413 ;;
414 darwin-*) CONFIG_OS=DARWIN
415 BSD=1
416 ;;
417 windows*) CONFIG_OS=WIN32
418 ;;
419 *) CONFIG_OS=$OS
420esac
421echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
422if [ $BSD = 1 ] ; then
423 echo "#define _BSD 1" >> $config_h
424 echo "#define O_LARGEFILE 0" >> $config_h
425 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
426fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800427log "Generate : $config_h"
428
429echo "Ready to go. Type 'make' to build emulator"