blob: bfda5e2da9c0240495e03a39088087bc798afeab [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#
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08007# here's the list of environment variables you can define before
8# calling this script to control it (besides options):
9#
10#
11
12# first, let's see which system we're running this on
13cd `dirname $0`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080014
David 'Digit' Turner46be4872009-06-04 16:07:01 +020015# source common functions definitions
16. android/build/common.sh
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080017
18# Parse options
19OPTION_TARGETS=""
20OPTION_DEBUG=no
21OPTION_IGNORE_AUDIO=no
22OPTION_NO_PREBUILTS=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080023OPTION_HELP=no
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080024OPTION_STATIC=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070025OPTION_MINGW=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080026
David 'Digit' Turner1af82152014-03-03 20:41:37 +010027GLES_DIR=
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +020028GLES_SUPPORT=no
29GLES_PROBE=yes
30
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +010031PCBIOS_PROBE=yes
32
David 'Digit' Turnere3650682010-12-22 14:44:19 +010033HOST_CC=${CC:-gcc}
34OPTION_CC=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080035
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 ;;
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070054 --mingw) OPTION_MINGW=yes
55 ;;
David 'Digit' Turnere3650682010-12-22 14:44:19 +010056 --cc=*) OPTION_CC="$optarg"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080057 ;;
58 --no-strip) OPTION_NO_STRIP=yes
59 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080060 --ignore-audio) OPTION_IGNORE_AUDIO=yes
61 ;;
62 --no-prebuilts) OPTION_NO_PREBUILTS=yes
63 ;;
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080064 --static) OPTION_STATIC=yes
65 ;;
David 'Digit' Turner1af82152014-03-03 20:41:37 +010066 --gles-dir=*) GLES_DIR=$optarg
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +020067 ;;
68 --no-gles) GLES_PROBE=no
69 ;;
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +010070 --no-pcbios) PCBIOS_PROBE=no
71 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080072 *)
73 echo "unknown option '$opt', use --help"
74 exit 1
75 esac
76done
77
78# Print the help message
79#
80if [ "$OPTION_HELP" = "yes" ] ; then
81 cat << EOF
82
83Usage: rebuild.sh [options]
84Options: [defaults in brackets after descriptions]
85EOF
86 echo "Standard options:"
87 echo " --help print this message"
88 echo " --install=FILEPATH copy emulator executable to FILEPATH [$TARGETS]"
David 'Digit' Turnere3650682010-12-22 14:44:19 +010089 echo " --cc=PATH specify C compiler [$HOST_CC]"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080090 echo " --sdl-config=FILE use specific sdl-config script [$SDL_CONFIG]"
91 echo " --no-strip do not strip emulator executable"
92 echo " --debug enable debug (-O0 -g) build"
93 echo " --ignore-audio ignore audio messages (may build sound-less emulator)"
94 echo " --no-prebuilts do not use prebuilt libraries and compiler"
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070095 echo " --mingw build Windows executable on Linux"
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080096 echo " --static build a completely static executable"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080097 echo " --verbose verbose configuration"
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +020098 echo " --debug build debug version of the emulator"
David 'Digit' Turner1af82152014-03-03 20:41:37 +010099 echo " --gles-dir=PATH specify path to GLES host emulation sources [auto-detected]"
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200100 echo " --no-gles disable GLES emulation support"
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100101 echo " --no-pcbios disable copying of PC Bios files"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800102 echo ""
103 exit 1
104fi
105
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700106# On Linux, try to use our prebuilt toolchain to generate binaries
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100107# that are compatible with Ubuntu 8.04
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700108if [ -z "$CC" -a -z "$OPTION_CC" -a "$HOST_OS" = linux ] ; then
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100109 PROBE_HOST_CC=`dirname $0`/../../prebuilts/tools/gcc-sdk/gcc
110 if [ -f "$PROBE_HOST_CC" ] ; then
111 echo "Using prebuilt toolchain: $PROBE_HOST_CC"
112 CC="$PROBE_HOST_CC"
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100113 fi
114fi
115
David 'Digit' Turnerba313e02011-02-09 16:01:53 +0100116if [ -n "$OPTION_CC" ]; then
117 echo "Using specified C compiler: $OPTION_CC"
118 CC="$OPTION_CC"
119fi
120
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700121if [ -z "$CC" ]; then
122 CC=$HOST_CC
123fi
124
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100125# By default, generate 32-bit binaries, the Makefile have targets that
126# generate 64-bit ones by using -m64 on the command-line.
127force_32bit_binaries
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800128
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200129case $OS in
130 linux-*)
131 TARGET_DLL_SUFFIX=.so
132 ;;
133 darwin-*)
134 TARGET_DLL_SUFFIX=.dylib
135 ;;
136 windows*)
137 TARGET_DLL_SUFFIX=.dll
138esac
139
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700140TARGET_OS=$OS
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100141
142setup_toolchain
143
144BUILD_AR=$AR
145BUILD_CC=$CC
146BUILD_CXX=$CC
147BUILD_LD=$LD
148BUILD_AR=$AR
149BUILD_CFLAGS=$CFLAGS
150BUILD_CXXFLAGS=$CXXFLAGS
151BUILD_LDFLAGS=$LDFLAGS
152
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200153if [ "$OPTION_MINGW" = "yes" ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700154 enable_linux_mingw
155 TARGET_OS=windows
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200156 TARGET_DLL_SUFFIX=.dll
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700157else
158 enable_cygwin
159fi
160
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200161# Are we running in the Android build system ?
162check_android_build
163
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800164
165# Adjust a few things when we're building within the Android build
166# system:
167# - locate prebuilt directory
168# - locate and use prebuilt libraries
169# - copy the new binary to the correct location
170#
171if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then
172 IN_ANDROID_BUILD=no
173fi
174
175if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200176 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800177
178 # use ccache if USE_CCACHE is defined and the corresponding
179 # binary is available.
180 #
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800181 if [ -n "$USE_CCACHE" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200182 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800183 if [ ! -f $CCACHE ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700184 CCACHE="$ANDROID_PREBUILTS/ccache/ccache$EXE"
185 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800186 fi
187
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800188 # finally ensure that our new binary is copied to the 'out'
189 # subdirectory as 'emulator'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200190 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200191 if [ "$TARGET_OS" = "windows" ]; then
192 HOST_BIN=$(echo $HOST_BIN | sed "s%$OS/bin%windows/bin%")
193 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800194 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200195 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
196 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800197 fi
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800198
199 # find the Android SDK Tools revision number
200 TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties
201 if [ -f $TOOLS_PROPS ] ; then
202 ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null`
203 log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION"
204 else
205 log "Tools : Could not locate $TOOLS_PROPS !?"
206 fi
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700207else
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100208 if [ "$USE_CCACHE" != 0 ]; then
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100209 CCACHE=$(which ccache 2>/dev/null)
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100210 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800211fi # IN_ANDROID_BUILD = no
212
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100213if [ -n "$CCACHE" -a -f "$CCACHE" ] ; then
214 CC="$CCACHE $CC"
215 log "Prebuilt : CCACHE=$CCACHE"
216else
217 log "Prebuilt : CCACHE can't be found"
218 CCACHE=
219fi
220
221# Try to find the GLES emulation headers and libraries automatically
222if [ "$GLES_PROBE" = "yes" ]; then
223 GLES_SUPPORT=yes
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100224 if [ -z "$GLES_DIR" ]; then
225 GLES_DIR=../../sdk/emulator/opengl
226 log2 "GLES : Probing source dir: $GLES_DIR"
227 if [ ! -d "$GLES_DIR" ]; then
228 GLES_DIR=../opengl
229 log2 "GLES : Probing source dir: $GLES_DIR"
230 if [ ! -d "$GLES_DIR" ]; then
231 GLES_DIR=
232 fi
233 fi
234 if [ -z "$GLES_DIR" ]; then
235 echo "GLES : Could not find GPU emulation sources!"
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100236 GLES_SUPPORT=no
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100237 else
238 echo "GLES : Found GPU emulation sources: $GLES_DIR"
239 GLES_SUPPORT=yes
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100240 fi
241 fi
242fi
243
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100244if [ "$PCBIOS_PROBE" = "yes" ]; then
245 PCBIOS_DIR=$(dirname "$0")/../../prebuilts/qemu-kernel/x86/pc-bios
246 if [ ! -d "$PCBIOS_DIR" ]; then
247 log2 "PC Bios : Probing $PCBIOS_DIR (missing)"
248 PCBIOS_DIR=../pc-bios
249 fi
250 log2 "PC Bios : Probing $PCBIOS_DIR"
251 if [ ! -d "$PCBIOS_DIR" ]; then
252 log "PC Bios : Could not find prebuilts directory."
253 else
254 mkdir -p objs/lib/pc-bios
255 for BIOS_FILE in bios.bin vgabios-cirrus.bin; do
256 log "PC Bios : Copying $BIOS_FILE"
257 cp -f $PCBIOS_DIR/$BIOS_FILE objs/lib/pc-bios/$BIOS_FILE
258 done
259 fi
260fi
261
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100262# For OS X, detect the location of the SDK to use.
263if [ "$HOST_OS" = darwin ]; then
264 OSX_VERSION=$(sw_vers -productVersion)
265 OSX_SDK_SUPPORTED="10.6 10.7 10.8"
266 OSX_SDK_INSTALLED_LIST=$(xcodebuild -showsdks 2>/dev/null | grep macosx | sed -e "s/.*macosx//g" | sort -n)
267 if [ -z "$OSX_SDK_INSTALLED_LIST" ]; then
268 echo "ERROR: Please install XCode on this machine!"
269 exit 1
270 fi
271 log "OSX: Installed SDKs: $OSX_SDK_INSTALLED_LIST"
272
273 OSX_SDK_VERSION=$(echo "$OSX_SDK_INSTALLED_LIST" | tr ' ' '\n' | head -1)
274 log "OSX: Using SDK version $OSX_SDK_VERSION"
275
276 XCODE_PATH=$(xcode-select -print-path 2>/dev/null)
277 log "OSX: XCode path: $XCODE_PATH"
278
279 OSX_SDK_ROOT=$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk
280 log "OSX: Looking for $OSX_SDK_ROOT"
281 if [ ! -d "$OSX_SDK_ROOT" ]; then
282 OSX_SDK_ROOT=/Developer/SDKs/MaxOSX${OSX_SDK_VERSION}.sdk
283 log "OSX: Looking for $OSX_SDK_ROOT"
284 if [ ! -d "$OSX_SDK_ROOT" ]; then
285 echo "ERROR: Could not find SDK $OSX_SDK_VERSION at $OSX_SDK_ROOT"
286 exit 1
287 fi
288 fi
289 echo "OSX SDK : Found at $OSX_SDK_ROOT"
290fi
291
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200292# we can build the emulator with Cygwin, so enable it
293enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800294
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200295setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800296
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800297###
298### SDL Probe
299###
300
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700301if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200302
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700303 # check that we can link statically with the library.
304 #
305 SDL_CFLAGS=`$SDL_CONFIG --cflags`
306 SDL_LIBS=`$SDL_CONFIG --static-libs`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800307
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700308 # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
Deepanshu Guptabb761912013-05-28 16:36:40 -0700309 # since they break recent Mingw releases
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700310 SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800311
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700312 log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
313 log "SDL-probe : SDL_LIBS = $SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800314
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800315
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700316 EXTRA_CFLAGS="$SDL_CFLAGS"
317 EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800318
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700319 case "$OS" in
320 freebsd-*)
321 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread"
322 ;;
323 esac
Alexey Tarasov08823222009-09-01 02:07:51 +1100324
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700325 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800326#include <SDL.h>
327#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200328int main( int argc, char** argv ) {
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200329 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800330}
331EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700332 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200333
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700334 if [ $SDL_LINKING != "yes" ] ; then
335 echo "You provided an explicit sdl-config script, but the corresponding library"
336 echo "cannot be statically linked with the Android emulator directly."
337 echo "Error message:"
338 cat $TMPL
339 clean_exit
340 fi
341 log "SDL-probe : static linking ok"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800342
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700343 # now, let's check that the SDL library has the special functions
344 # we added to our own sources
345 #
346 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800347#include <SDL.h>
348#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200349int main( int argc, char** argv ) {
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700350 int x, y;
351 SDL_Rect r;
352 SDL_WM_GetPos(&x, &y);
353 SDL_WM_SetPos(x, y);
354 SDL_WM_GetMonitorDPI(&x, &y);
355 SDL_WM_GetMonitorRect(&r);
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200356 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800357}
358EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700359 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200360
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700361 if [ $SDL_LINKING != "yes" ] ; then
362 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
363 echo "corresponding library doesn't have the patches required to link"
364 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
365 echo "sources bundled with the emulator instead"
366 echo "Error:"
367 cat $TMPL
368 clean_exit
369 fi
370
371 log "SDL-probe : extra features ok"
372 clean_temp
373
374 EXTRA_CFLAGS=
375 EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800376fi
377
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800378###
379### Audio subsystems probes
380###
381PROBE_COREAUDIO=no
382PROBE_ALSA=no
383PROBE_OSS=no
384PROBE_ESD=no
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700385PROBE_PULSEAUDIO=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800386PROBE_WINAUDIO=no
387
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700388case "$TARGET_OS" in
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800389 darwin*) PROBE_COREAUDIO=yes;
390 ;;
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700391 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800392 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100393 freebsd-*) PROBE_OSS=yes;
394 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800395 windows) PROBE_WINAUDIO=yes
396 ;;
397esac
398
399ORG_CFLAGS=$CFLAGS
400ORG_LDFLAGS=$LDFLAGS
401
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200402if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then
403PROBE_ESD_ESD=no
404PROBE_ALSA=no
405PROBE_PULSEAUDIO=no
406fi
407
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700408# Probe a system library
409#
410# $1: Variable name (e.g. PROBE_ESD)
411# $2: Library name (e.g. "Alsa")
412# $3: Path to source file for probe program (e.g. android/config/check-alsa.c)
413# $4: Package name (e.g. libasound-dev)
414#
415probe_system_library ()
416{
417 if [ `var_value $1` = yes ] ; then
418 CFLAGS="$ORG_CFLAGS"
419 LDFLAGS="$ORG_LDFLAGS -ldl"
420 cp -f android/config/check-esd.c $TMPC
David 'Digit' Turnera7ef1ac2010-12-10 22:33:51 +0100421 compile
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700422 if [ $? = 0 ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200423 log "AudioProbe : $2 seems to be usable on this system"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700424 else
425 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200426 echo "The $2 development files do not seem to be installed on this system"
427 echo "Are you missing the $4 package ?"
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100428 echo "You can ignore this error with --ignore-audio, otherwise correct"
429 echo "the issue(s) below and try again:"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700430 cat $TMPL
431 clean_exit
432 fi
433 eval $1=no
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200434 log "AudioProbe : $2 seems to be UNUSABLE on this system !!"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800435 fi
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100436 clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800437 fi
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700438}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800439
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700440probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev
441probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev
442probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800443
444CFLAGS=$ORG_CFLAGS
445LDFLAGS=$ORG_LDFLAGS
446
447# create the objs directory that is going to contain all generated files
448# including the configuration ones
449#
450mkdir -p objs
451
452###
453### Compiler probe
454###
455
456####
457#### Host system probe
458####
459
460# because the previous version could be read-only
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100461clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800462
463# check host endianess
464#
465HOST_BIGENDIAN=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700466if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800467cat > $TMPC << EOF
468#include <inttypes.h>
469int main(int argc, char ** argv){
470 volatile uint32_t i=0x01234567;
Marcus Comstedt17d31322010-10-05 21:54:12 +0200471 return (*((uint8_t*)(&i))) == 0x01;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800472}
473EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200474feature_run_exec HOST_BIGENDIAN
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700475fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800476
477# check size of host long bits
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700478HOST_LONGBITS=32
479if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800480cat > $TMPC << EOF
481int main(void) {
482 return sizeof(void*)*8;
483}
484EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200485feature_run_exec HOST_LONGBITS
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700486fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800487
488# check whether we have <byteswap.h>
489#
David Turnerb8fec3e2010-09-09 18:15:23 +0200490feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
491feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
492feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
David Turner80dd1262010-09-09 18:04:49 +0200493
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800494# Build the config.make file
495#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200496
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100497case $OS in
498 windows)
499 HOST_EXEEXT=.exe
500 HOST_DLLEXT=.dll
501 ;;
502 darwin)
503 HOST_EXEEXT=
504 HOST_DLLEXT=.dylib
505 ;;
506 *)
507 HOST_EXEEXT=
508 HOST_DLLEXT=
509 ;;
510esac
511
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200512case $TARGET_OS in
513 windows)
514 TARGET_EXEEXT=.exe
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100515 TARGET_DLLEXT=.dll
516 ;;
517 darwin)
518 TARGET_EXEXT=
519 TARGET_DLLEXT=.dylib
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200520 ;;
521 *)
522 TARGET_EXEEXT=
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100523 TARGET_DLLEXT=.so
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200524 ;;
525esac
526
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100527# Strip executables and shared libraries unless --debug is used.
528if [ "$OPTION_DEBUG" != "yes" ]; then
529 case $HOST_OS in
530 darwin)
531 LDFLAGS="$LDFLAGS -Wl,-S"
532 ;;
533 *)
534 LDFLAGS="$LDFLAGS -Wl,--strip-all"
535 ;;
536 esac
537fi
538
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200539create_config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700540echo "" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700541echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200542echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100543echo "HOST_DLLEXT := $TARGET_DLLEXT" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700544echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700545echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200546
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100547echo "" >> $config_mk
548echo "BUILD_OS := $HOST_OS" >> $config_mk
549echo "BUILD_ARCH := $HOST_ARCH" >> $config_mk
550echo "BUILD_EXEEXT := $HOST_EXEEXT" >> $config_mk
551echo "BUILD_DLLEXT := $HOST_DLLEXT" >> $config_mk
552echo "BUILD_AR := $BUILD_AR" >> $config_mk
553echo "BUILD_CC := $BUILD_CC" >> $config_mk
554echo "BUILD_CXX := $BUILD_CXX" >> $config_mk
555echo "BUILD_LD := $BUILD_LD" >> $config_mk
556echo "BUILD_CFLAGS := $BUILD_CFLAGS" >> $config_mk
557echo "BUILD_LDFLAGS := $BUILD_LDFLAGS" >> $config_mk
558
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800559PWD=`pwd`
560echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700561if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200562echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700563fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800564echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
565echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
566echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
567echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
568echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700569echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800570echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200571if [ $OPTION_DEBUG = yes ] ; then
572 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
573fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800574if [ $OPTION_STATIC = yes ] ; then
575 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
576fi
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100577if [ "$GLES_SUPPORT" = "yes" ]; then
578 echo "EMULATOR_BUILD_EMUGL := true" >> $config_mk
579 echo "EMULATOR_EMUGL_SOURCES_DIR := $GLES_DIR" >> $config_mk
580fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800581
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800582if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
583 echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
584fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800585
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700586if [ "$OPTION_MINGW" = "yes" ] ; then
587 echo "" >> $config_mk
588 echo "USE_MINGW := 1" >> $config_mk
589 echo "HOST_OS := windows" >> $config_mk
590fi
591
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100592if [ "$HOST_OS" = "darwin" ]; then
593 echo "mac_sdk_root := $OSX_SDK_ROOT" >> $config_mk
594 echo "mac_sdk_version := $OSX_SDK_VERSION" >> $config_mk
595fi
596
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800597# Build the config-host.h file
598#
599config_h=objs/config-host.h
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100600cat > $config_h <<EOF
601/* This file was autogenerated by '$PROGNAME' */
602
603#define CONFIG_QEMU_SHAREDIR "/usr/local/share/qemu"
604
605#if defined(__x86_64__)
606#define HOST_X86_64 1
607#define HOST_LONG_BITS 64
608#elif defined(__i386__)
609#define HOST_I386 1
610#define HOST_LONG_BITS 32
611#else
612#error Unknown architecture for codegen
613#endif
614
615EOF
616
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800617if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200618 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
619fi
620if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
621 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800622fi
David Turner80dd1262010-09-09 18:04:49 +0200623if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
624 echo "#define CONFIG_FNMATCH 1" >> $config_h
625fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800626echo "#define CONFIG_GDBSTUB 1" >> $config_h
627echo "#define CONFIG_SLIRP 1" >> $config_h
628echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200629echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700630
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200631case "$TARGET_OS" in
632 windows)
633 echo "#define CONFIG_WIN32 1" >> $config_h
634 ;;
635 *)
636 echo "#define CONFIG_POSIX 1" >> $config_h
637 ;;
638esac
639
640case "$TARGET_OS" in
641 linux-*)
642 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
643 ;;
644esac
645
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700646# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700647case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700648 linux-*)
649 echo "#define CONFIG_FDATASYNC 1" >> $config_h
650 ;;
651esac
652
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200653case "$TARGET_OS" in
654 linux-*|darwin-*)
655 echo "#define CONFIG_MADVISE 1" >> $config_h
656 ;;
657esac
658
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800659# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700660if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800661 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
662fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700663echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
664echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800665case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200666 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800667 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200668 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800669 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200670 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800671 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200672 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800673 ;;
674esac
Marcus Comstedt17d31322010-10-05 21:54:12 +0200675if [ "$HOST_BIGENDIAN" = "1" ] ; then
676 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
677fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200678BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700679case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200680 linux-*) CONFIG_OS=LINUX
681 ;;
682 darwin-*) CONFIG_OS=DARWIN
683 BSD=1
684 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100685 freebsd-*) CONFIG_OS=FREEBSD
686 BSD=1
687 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200688 windows*) CONFIG_OS=WIN32
689 ;;
690 *) CONFIG_OS=$OS
691esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700692
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800693if [ "$OPTION_STATIC" = "yes" ] ; then
694 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
695 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
696fi
697
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700698case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700699 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800700 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700701 ;;
702esac
703
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200704echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
705if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700706 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200707 echo "#define O_LARGEFILE 0" >> $config_h
708 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
709fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700710
David 'Digit' Turner494b1292014-02-05 15:02:04 +0100711case "$TARGET_OS" in
712 linux-*)
713 echo "#define CONFIG_SIGNALFD 1" >> $config_h
714 ;;
715esac
716
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700717echo "#define CONFIG_ANDROID 1" >> $config_h
718
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800719log "Generate : $config_h"
720
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100721# Generate the QAPI headers and sources from qapi-schema.json
722# Ideally, this would be done in our Makefiles, but as far as I
723# understand, the platform build doesn't support a single tool
724# that generates several sources files, nor the standalone one.
725export PYTHONDONTWRITEBYTECODE=1
726AUTOGENERATED_DIR=qapi-auto-generated
727python scripts/qapi-types.py qapi.types --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
728python scripts/qapi-visit.py --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
729python scripts/qapi-commands.py --output-dir=$AUTOGENERATED_DIR -m < qapi-schema.json
730log "Generate : $AUTOGENERATED_DIR"
731
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100732clean_temp
733
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800734echo "Ready to go. Type 'make' to build emulator"