blob: bb0901172022f83507eb60616f1a07cb195c1b78 [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
David 'Digit' Turnera96cc262014-05-12 21:28:34 +020023OPTION_OUT_DIR=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080024OPTION_HELP=no
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080025OPTION_STATIC=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070026OPTION_MINGW=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080027
David 'Digit' Turner1af82152014-03-03 20:41:37 +010028GLES_DIR=
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +020029GLES_SUPPORT=no
30GLES_PROBE=yes
31
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +010032PCBIOS_PROBE=yes
33
David 'Digit' Turnere3650682010-12-22 14:44:19 +010034HOST_CC=${CC:-gcc}
35OPTION_CC=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080036
37for opt do
38 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
39 case "$opt" in
40 --help|-h|-\?) OPTION_HELP=yes
41 ;;
42 --verbose)
43 if [ "$VERBOSE" = "yes" ] ; then
44 VERBOSE2=yes
45 else
46 VERBOSE=yes
47 fi
48 ;;
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +020049 --debug) OPTION_DEBUG=yes
50 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +020051 --install=*) OPTION_TARGETS="$OPTION_TARGETS $optarg";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080052 ;;
53 --sdl-config=*) SDL_CONFIG=$optarg
54 ;;
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070055 --mingw) OPTION_MINGW=yes
56 ;;
David 'Digit' Turnere3650682010-12-22 14:44:19 +010057 --cc=*) OPTION_CC="$optarg"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080058 ;;
59 --no-strip) OPTION_NO_STRIP=yes
60 ;;
David 'Digit' Turnera96cc262014-05-12 21:28:34 +020061 --out-dir=*) OPTION_OUT_DIR=$optarg
62 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080063 --ignore-audio) OPTION_IGNORE_AUDIO=yes
64 ;;
65 --no-prebuilts) OPTION_NO_PREBUILTS=yes
66 ;;
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080067 --static) OPTION_STATIC=yes
68 ;;
David 'Digit' Turner1af82152014-03-03 20:41:37 +010069 --gles-dir=*) GLES_DIR=$optarg
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +020070 ;;
71 --no-gles) GLES_PROBE=no
72 ;;
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +010073 --no-pcbios) PCBIOS_PROBE=no
74 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080075 *)
76 echo "unknown option '$opt', use --help"
77 exit 1
78 esac
79done
80
81# Print the help message
82#
83if [ "$OPTION_HELP" = "yes" ] ; then
84 cat << EOF
85
86Usage: rebuild.sh [options]
87Options: [defaults in brackets after descriptions]
88EOF
89 echo "Standard options:"
90 echo " --help print this message"
91 echo " --install=FILEPATH copy emulator executable to FILEPATH [$TARGETS]"
David 'Digit' Turnere3650682010-12-22 14:44:19 +010092 echo " --cc=PATH specify C compiler [$HOST_CC]"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080093 echo " --sdl-config=FILE use specific sdl-config script [$SDL_CONFIG]"
94 echo " --no-strip do not strip emulator executable"
95 echo " --debug enable debug (-O0 -g) build"
96 echo " --ignore-audio ignore audio messages (may build sound-less emulator)"
97 echo " --no-prebuilts do not use prebuilt libraries and compiler"
David 'Digit' Turnera96cc262014-05-12 21:28:34 +020098 echo " --out-dir=<path> use specific output directory [objs/]"
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070099 echo " --mingw build Windows executable on Linux"
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800100 echo " --static build a completely static executable"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800101 echo " --verbose verbose configuration"
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200102 echo " --debug build debug version of the emulator"
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100103 echo " --gles-dir=PATH specify path to GLES host emulation sources [auto-detected]"
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200104 echo " --no-gles disable GLES emulation support"
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100105 echo " --no-pcbios disable copying of PC Bios files"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800106 echo ""
107 exit 1
108fi
109
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700110# On Linux, try to use our prebuilt toolchain to generate binaries
David 'Digit' Turner52ffef32014-04-28 11:20:47 +0200111# that are compatible with Ubuntu 10.4
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700112if [ -z "$CC" -a -z "$OPTION_CC" -a "$HOST_OS" = linux ] ; then
David 'Digit' Turner52ffef32014-04-28 11:20:47 +0200113 PREBUILTS_HOST_GCC=$(dirname $0)/../../prebuilts/gcc/linux-x86/host
David 'Digit' Turner295ef3d2014-04-30 11:02:03 +0200114 # NOTE: GCC 4.8 is currently disabled because this breaks MIPS emulation
115 # For some odd reason. Remove the 'DISABLED_' prefix below to re-enable it,
116 # e.g. once the MIPS backend has been updated to a more recent version.
117 # This only affects Linux emulator binaries.
118 PROBE_HOST_CC=$PREBUILTS_HOST_GCC/DISABLED_x86_64-linux-glibc2.11-4.8/bin/x86_64-linux-gcc
David 'Digit' Turner52ffef32014-04-28 11:20:47 +0200119 if [ ! -f "$PROBE_HOST_CC" ]; then
120 PROBE_HOST_CC=$PREBUILTS_HOST_GCC/x86_64-linux-glibc2.11-4.6/bin/x86_64-linux-gcc
121 if [ ! -f "$PROBE_HOST_CC" ] ; then
122 PROBE_HOST_CC=$(dirname $0)/../../prebuilts/tools/gcc-sdk/gcc
123 fi
Andrew Hsieh7db680c2014-03-13 04:18:13 -0700124 fi
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100125 if [ -f "$PROBE_HOST_CC" ] ; then
126 echo "Using prebuilt toolchain: $PROBE_HOST_CC"
127 CC="$PROBE_HOST_CC"
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100128 fi
129fi
130
David 'Digit' Turnerba313e02011-02-09 16:01:53 +0100131if [ -n "$OPTION_CC" ]; then
132 echo "Using specified C compiler: $OPTION_CC"
133 CC="$OPTION_CC"
134fi
135
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700136if [ -z "$CC" ]; then
137 CC=$HOST_CC
138fi
139
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100140# By default, generate 32-bit binaries, the Makefile have targets that
141# generate 64-bit ones by using -m64 on the command-line.
142force_32bit_binaries
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800143
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200144case $OS in
145 linux-*)
146 TARGET_DLL_SUFFIX=.so
147 ;;
148 darwin-*)
149 TARGET_DLL_SUFFIX=.dylib
150 ;;
151 windows*)
152 TARGET_DLL_SUFFIX=.dll
153esac
154
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700155TARGET_OS=$OS
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100156
157setup_toolchain
158
159BUILD_AR=$AR
160BUILD_CC=$CC
161BUILD_CXX=$CC
162BUILD_LD=$LD
163BUILD_AR=$AR
164BUILD_CFLAGS=$CFLAGS
165BUILD_CXXFLAGS=$CXXFLAGS
166BUILD_LDFLAGS=$LDFLAGS
167
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200168if [ "$OPTION_MINGW" = "yes" ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700169 enable_linux_mingw
170 TARGET_OS=windows
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200171 TARGET_DLL_SUFFIX=.dll
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700172else
173 enable_cygwin
174fi
175
David 'Digit' Turnera96cc262014-05-12 21:28:34 +0200176if [ "$OPTION_OUT_DIR" ]; then
177 OUT_DIR="$OPTION_OUT_DIR"
178 mkdir -p "$OUT_DIR" || panic "Could not create output directory: $OUT_DIR"
179else
180 OUT_DIR=objs
181 log "Auto-config: --out-dir=objs"
182fi
183
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200184# Are we running in the Android build system ?
185check_android_build
186
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800187
188# Adjust a few things when we're building within the Android build
189# system:
190# - locate prebuilt directory
191# - locate and use prebuilt libraries
192# - copy the new binary to the correct location
193#
194if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then
195 IN_ANDROID_BUILD=no
196fi
197
198if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200199 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800200
201 # use ccache if USE_CCACHE is defined and the corresponding
202 # binary is available.
203 #
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800204 if [ -n "$USE_CCACHE" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200205 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800206 if [ ! -f $CCACHE ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700207 CCACHE="$ANDROID_PREBUILTS/ccache/ccache$EXE"
208 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800209 fi
210
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800211 # finally ensure that our new binary is copied to the 'out'
212 # subdirectory as 'emulator'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200213 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200214 if [ "$TARGET_OS" = "windows" ]; then
215 HOST_BIN=$(echo $HOST_BIN | sed "s%$OS/bin%windows/bin%")
216 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800217 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200218 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
219 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800220 fi
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800221
222 # find the Android SDK Tools revision number
223 TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties
224 if [ -f $TOOLS_PROPS ] ; then
225 ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null`
226 log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION"
227 else
228 log "Tools : Could not locate $TOOLS_PROPS !?"
229 fi
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700230else
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100231 if [ "$USE_CCACHE" != 0 ]; then
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100232 CCACHE=$(which ccache 2>/dev/null)
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100233 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800234fi # IN_ANDROID_BUILD = no
235
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100236if [ -n "$CCACHE" -a -f "$CCACHE" ] ; then
237 CC="$CCACHE $CC"
238 log "Prebuilt : CCACHE=$CCACHE"
239else
240 log "Prebuilt : CCACHE can't be found"
241 CCACHE=
242fi
243
244# Try to find the GLES emulation headers and libraries automatically
245if [ "$GLES_PROBE" = "yes" ]; then
246 GLES_SUPPORT=yes
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100247 if [ -z "$GLES_DIR" ]; then
248 GLES_DIR=../../sdk/emulator/opengl
249 log2 "GLES : Probing source dir: $GLES_DIR"
250 if [ ! -d "$GLES_DIR" ]; then
251 GLES_DIR=../opengl
252 log2 "GLES : Probing source dir: $GLES_DIR"
253 if [ ! -d "$GLES_DIR" ]; then
254 GLES_DIR=
255 fi
256 fi
257 if [ -z "$GLES_DIR" ]; then
258 echo "GLES : Could not find GPU emulation sources!"
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100259 GLES_SUPPORT=no
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100260 else
261 echo "GLES : Found GPU emulation sources: $GLES_DIR"
262 GLES_SUPPORT=yes
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100263 fi
264 fi
265fi
266
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100267if [ "$PCBIOS_PROBE" = "yes" ]; then
268 PCBIOS_DIR=$(dirname "$0")/../../prebuilts/qemu-kernel/x86/pc-bios
269 if [ ! -d "$PCBIOS_DIR" ]; then
270 log2 "PC Bios : Probing $PCBIOS_DIR (missing)"
271 PCBIOS_DIR=../pc-bios
272 fi
273 log2 "PC Bios : Probing $PCBIOS_DIR"
274 if [ ! -d "$PCBIOS_DIR" ]; then
275 log "PC Bios : Could not find prebuilts directory."
276 else
David 'Digit' Turnera96cc262014-05-12 21:28:34 +0200277 mkdir -p $OUT_DIR/lib/pc-bios
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100278 for BIOS_FILE in bios.bin vgabios-cirrus.bin; do
279 log "PC Bios : Copying $BIOS_FILE"
David 'Digit' Turnera96cc262014-05-12 21:28:34 +0200280 cp -f $PCBIOS_DIR/$BIOS_FILE $OUT_DIR/lib/pc-bios/$BIOS_FILE
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100281 done
282 fi
283fi
284
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100285# For OS X, detect the location of the SDK to use.
286if [ "$HOST_OS" = darwin ]; then
287 OSX_VERSION=$(sw_vers -productVersion)
288 OSX_SDK_SUPPORTED="10.6 10.7 10.8"
289 OSX_SDK_INSTALLED_LIST=$(xcodebuild -showsdks 2>/dev/null | grep macosx | sed -e "s/.*macosx//g" | sort -n)
290 if [ -z "$OSX_SDK_INSTALLED_LIST" ]; then
291 echo "ERROR: Please install XCode on this machine!"
292 exit 1
293 fi
294 log "OSX: Installed SDKs: $OSX_SDK_INSTALLED_LIST"
295
296 OSX_SDK_VERSION=$(echo "$OSX_SDK_INSTALLED_LIST" | tr ' ' '\n' | head -1)
297 log "OSX: Using SDK version $OSX_SDK_VERSION"
298
299 XCODE_PATH=$(xcode-select -print-path 2>/dev/null)
300 log "OSX: XCode path: $XCODE_PATH"
301
302 OSX_SDK_ROOT=$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk
303 log "OSX: Looking for $OSX_SDK_ROOT"
304 if [ ! -d "$OSX_SDK_ROOT" ]; then
305 OSX_SDK_ROOT=/Developer/SDKs/MaxOSX${OSX_SDK_VERSION}.sdk
306 log "OSX: Looking for $OSX_SDK_ROOT"
307 if [ ! -d "$OSX_SDK_ROOT" ]; then
308 echo "ERROR: Could not find SDK $OSX_SDK_VERSION at $OSX_SDK_ROOT"
309 exit 1
310 fi
311 fi
312 echo "OSX SDK : Found at $OSX_SDK_ROOT"
313fi
314
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200315# we can build the emulator with Cygwin, so enable it
316enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800317
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200318setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800319
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800320###
321### SDL Probe
322###
323
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700324if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200325
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700326 # check that we can link statically with the library.
327 #
328 SDL_CFLAGS=`$SDL_CONFIG --cflags`
329 SDL_LIBS=`$SDL_CONFIG --static-libs`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800330
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700331 # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
Deepanshu Guptabb761912013-05-28 16:36:40 -0700332 # since they break recent Mingw releases
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700333 SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800334
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700335 log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
336 log "SDL-probe : SDL_LIBS = $SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800337
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800338
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700339 EXTRA_CFLAGS="$SDL_CFLAGS"
340 EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800341
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700342 case "$OS" in
343 freebsd-*)
344 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread"
345 ;;
346 esac
Alexey Tarasov08823222009-09-01 02:07:51 +1100347
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700348 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800349#include <SDL.h>
350#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200351int main( int argc, char** argv ) {
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200352 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800353}
354EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700355 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200356
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700357 if [ $SDL_LINKING != "yes" ] ; then
358 echo "You provided an explicit sdl-config script, but the corresponding library"
359 echo "cannot be statically linked with the Android emulator directly."
360 echo "Error message:"
361 cat $TMPL
362 clean_exit
363 fi
364 log "SDL-probe : static linking ok"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800365
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700366 # now, let's check that the SDL library has the special functions
367 # we added to our own sources
368 #
369 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800370#include <SDL.h>
371#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200372int main( int argc, char** argv ) {
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700373 int x, y;
374 SDL_Rect r;
375 SDL_WM_GetPos(&x, &y);
376 SDL_WM_SetPos(x, y);
377 SDL_WM_GetMonitorDPI(&x, &y);
378 SDL_WM_GetMonitorRect(&r);
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200379 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800380}
381EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700382 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200383
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700384 if [ $SDL_LINKING != "yes" ] ; then
385 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
386 echo "corresponding library doesn't have the patches required to link"
387 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
388 echo "sources bundled with the emulator instead"
389 echo "Error:"
390 cat $TMPL
391 clean_exit
392 fi
393
394 log "SDL-probe : extra features ok"
395 clean_temp
396
397 EXTRA_CFLAGS=
398 EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800399fi
400
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800401###
402### Audio subsystems probes
403###
404PROBE_COREAUDIO=no
405PROBE_ALSA=no
406PROBE_OSS=no
407PROBE_ESD=no
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700408PROBE_PULSEAUDIO=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800409PROBE_WINAUDIO=no
410
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700411case "$TARGET_OS" in
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800412 darwin*) PROBE_COREAUDIO=yes;
413 ;;
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700414 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800415 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100416 freebsd-*) PROBE_OSS=yes;
417 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800418 windows) PROBE_WINAUDIO=yes
419 ;;
420esac
421
422ORG_CFLAGS=$CFLAGS
423ORG_LDFLAGS=$LDFLAGS
424
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200425if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then
426PROBE_ESD_ESD=no
427PROBE_ALSA=no
428PROBE_PULSEAUDIO=no
429fi
430
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700431# Probe a system library
432#
433# $1: Variable name (e.g. PROBE_ESD)
434# $2: Library name (e.g. "Alsa")
435# $3: Path to source file for probe program (e.g. android/config/check-alsa.c)
436# $4: Package name (e.g. libasound-dev)
437#
438probe_system_library ()
439{
440 if [ `var_value $1` = yes ] ; then
441 CFLAGS="$ORG_CFLAGS"
442 LDFLAGS="$ORG_LDFLAGS -ldl"
443 cp -f android/config/check-esd.c $TMPC
David 'Digit' Turnera7ef1ac2010-12-10 22:33:51 +0100444 compile
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700445 if [ $? = 0 ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200446 log "AudioProbe : $2 seems to be usable on this system"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700447 else
448 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200449 echo "The $2 development files do not seem to be installed on this system"
450 echo "Are you missing the $4 package ?"
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100451 echo "You can ignore this error with --ignore-audio, otherwise correct"
452 echo "the issue(s) below and try again:"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700453 cat $TMPL
454 clean_exit
455 fi
456 eval $1=no
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200457 log "AudioProbe : $2 seems to be UNUSABLE on this system !!"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800458 fi
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100459 clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800460 fi
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700461}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800462
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700463probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev
464probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev
465probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800466
467CFLAGS=$ORG_CFLAGS
468LDFLAGS=$ORG_LDFLAGS
469
470# create the objs directory that is going to contain all generated files
471# including the configuration ones
472#
David 'Digit' Turnera96cc262014-05-12 21:28:34 +0200473mkdir -p $OUT_DIR
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800474
475###
476### Compiler probe
477###
478
479####
480#### Host system probe
481####
482
483# because the previous version could be read-only
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100484clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800485
486# check host endianess
487#
488HOST_BIGENDIAN=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700489if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800490cat > $TMPC << EOF
491#include <inttypes.h>
492int main(int argc, char ** argv){
493 volatile uint32_t i=0x01234567;
Marcus Comstedt17d31322010-10-05 21:54:12 +0200494 return (*((uint8_t*)(&i))) == 0x01;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800495}
496EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200497feature_run_exec HOST_BIGENDIAN
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700498fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800499
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800500# check whether we have <byteswap.h>
501#
David Turnerb8fec3e2010-09-09 18:15:23 +0200502feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
503feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
504feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
David Turner80dd1262010-09-09 18:04:49 +0200505
David 'Digit' Turner7891dd32014-04-28 10:59:47 +0200506# check for Mingw version.
507MINGW_VERSION=
508if [ "$TARGET_OS" = "windows" ]; then
509log "Mingw : Probing for GCC version."
510GCC_VERSION=$($CC -v 2>&1 | awk '$1 == "gcc" && $2 == "version" { print $3; }')
511GCC_MAJOR=$(echo "$GCC_VERSION" | cut -f1 -d.)
512GCC_MINOR=$(echo "$GCC_VERSION" | cut -f2 -d.)
513log "Mingw : Found GCC version $GCC_MAJOR.$GCC_MINOR [$GCC_VERSION]"
514MINGW_GCC_VERSION=$(( $GCC_MAJOR * 100 + $GCC_MINOR ))
515fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800516# Build the config.make file
517#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200518
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100519case $OS in
520 windows)
521 HOST_EXEEXT=.exe
522 HOST_DLLEXT=.dll
523 ;;
524 darwin)
525 HOST_EXEEXT=
526 HOST_DLLEXT=.dylib
527 ;;
528 *)
529 HOST_EXEEXT=
530 HOST_DLLEXT=
531 ;;
532esac
533
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200534case $TARGET_OS in
535 windows)
536 TARGET_EXEEXT=.exe
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100537 TARGET_DLLEXT=.dll
538 ;;
539 darwin)
540 TARGET_EXEXT=
541 TARGET_DLLEXT=.dylib
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200542 ;;
543 *)
544 TARGET_EXEEXT=
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100545 TARGET_DLLEXT=.so
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200546 ;;
547esac
548
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100549# Strip executables and shared libraries unless --debug is used.
David 'Digit' Turner3e3ff5a2014-03-14 11:20:10 +0100550if [ "$OPTION_DEBUG" != "yes" -a "$OPTION_NO_STRIP" != "yes" ]; then
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100551 case $HOST_OS in
552 darwin)
553 LDFLAGS="$LDFLAGS -Wl,-S"
554 ;;
555 *)
556 LDFLAGS="$LDFLAGS -Wl,--strip-all"
557 ;;
558 esac
559fi
560
David 'Digit' Turnera96cc262014-05-12 21:28:34 +0200561create_config_mk "$OUT_DIR"
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700562echo "" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700563echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200564echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100565echo "HOST_DLLEXT := $TARGET_DLLEXT" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700566echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700567echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200568
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100569echo "" >> $config_mk
570echo "BUILD_OS := $HOST_OS" >> $config_mk
571echo "BUILD_ARCH := $HOST_ARCH" >> $config_mk
572echo "BUILD_EXEEXT := $HOST_EXEEXT" >> $config_mk
573echo "BUILD_DLLEXT := $HOST_DLLEXT" >> $config_mk
574echo "BUILD_AR := $BUILD_AR" >> $config_mk
575echo "BUILD_CC := $BUILD_CC" >> $config_mk
576echo "BUILD_CXX := $BUILD_CXX" >> $config_mk
577echo "BUILD_LD := $BUILD_LD" >> $config_mk
578echo "BUILD_CFLAGS := $BUILD_CFLAGS" >> $config_mk
579echo "BUILD_LDFLAGS := $BUILD_LDFLAGS" >> $config_mk
580
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800581PWD=`pwd`
582echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700583if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200584echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700585fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800586echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
587echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
588echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
589echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
590echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700591echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800592echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200593if [ $OPTION_DEBUG = yes ] ; then
594 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
595fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800596if [ $OPTION_STATIC = yes ] ; then
597 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
598fi
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100599if [ "$GLES_SUPPORT" = "yes" ]; then
600 echo "EMULATOR_BUILD_EMUGL := true" >> $config_mk
601 echo "EMULATOR_EMUGL_SOURCES_DIR := $GLES_DIR" >> $config_mk
602fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800603
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800604if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
605 echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
606fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800607
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700608if [ "$OPTION_MINGW" = "yes" ] ; then
609 echo "" >> $config_mk
610 echo "USE_MINGW := 1" >> $config_mk
611 echo "HOST_OS := windows" >> $config_mk
David 'Digit' Turner7891dd32014-04-28 10:59:47 +0200612 echo "HOST_MINGW_VERSION := $MINGW_GCC_VERSION" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700613fi
614
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100615if [ "$HOST_OS" = "darwin" ]; then
616 echo "mac_sdk_root := $OSX_SDK_ROOT" >> $config_mk
617 echo "mac_sdk_version := $OSX_SDK_VERSION" >> $config_mk
618fi
619
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800620# Build the config-host.h file
621#
David 'Digit' Turnera96cc262014-05-12 21:28:34 +0200622config_h=$OUT_DIR/config-host.h
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100623cat > $config_h <<EOF
624/* This file was autogenerated by '$PROGNAME' */
625
626#define CONFIG_QEMU_SHAREDIR "/usr/local/share/qemu"
627
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100628EOF
629
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800630if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200631 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
632fi
633if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
634 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800635fi
David Turner80dd1262010-09-09 18:04:49 +0200636if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
637 echo "#define CONFIG_FNMATCH 1" >> $config_h
638fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800639echo "#define CONFIG_GDBSTUB 1" >> $config_h
640echo "#define CONFIG_SLIRP 1" >> $config_h
641echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200642echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700643
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200644case "$TARGET_OS" in
645 windows)
646 echo "#define CONFIG_WIN32 1" >> $config_h
647 ;;
648 *)
649 echo "#define CONFIG_POSIX 1" >> $config_h
650 ;;
651esac
652
653case "$TARGET_OS" in
654 linux-*)
655 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
656 ;;
657esac
658
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700659# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700660case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700661 linux-*)
662 echo "#define CONFIG_FDATASYNC 1" >> $config_h
663 ;;
664esac
665
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200666case "$TARGET_OS" in
667 linux-*|darwin-*)
668 echo "#define CONFIG_MADVISE 1" >> $config_h
669 ;;
670esac
671
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800672# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700673if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800674 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
675fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700676echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
677echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800678case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200679 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800680 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200681 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800682 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200683 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800684 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200685 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800686 ;;
687esac
Marcus Comstedt17d31322010-10-05 21:54:12 +0200688if [ "$HOST_BIGENDIAN" = "1" ] ; then
689 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
690fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200691BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700692case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200693 linux-*) CONFIG_OS=LINUX
694 ;;
695 darwin-*) CONFIG_OS=DARWIN
696 BSD=1
697 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100698 freebsd-*) CONFIG_OS=FREEBSD
699 BSD=1
700 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200701 windows*) CONFIG_OS=WIN32
702 ;;
703 *) CONFIG_OS=$OS
704esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700705
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800706if [ "$OPTION_STATIC" = "yes" ] ; then
707 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
708 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
709fi
710
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700711case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700712 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800713 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700714 ;;
715esac
716
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200717echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
718if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700719 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200720 echo "#define O_LARGEFILE 0" >> $config_h
721 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
722fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700723
David 'Digit' Turner494b1292014-02-05 15:02:04 +0100724case "$TARGET_OS" in
725 linux-*)
726 echo "#define CONFIG_SIGNALFD 1" >> $config_h
727 ;;
728esac
729
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700730echo "#define CONFIG_ANDROID 1" >> $config_h
731
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800732log "Generate : $config_h"
733
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100734# Generate the QAPI headers and sources from qapi-schema.json
735# Ideally, this would be done in our Makefiles, but as far as I
736# understand, the platform build doesn't support a single tool
737# that generates several sources files, nor the standalone one.
738export PYTHONDONTWRITEBYTECODE=1
739AUTOGENERATED_DIR=qapi-auto-generated
740python scripts/qapi-types.py qapi.types --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
741python scripts/qapi-visit.py --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
742python scripts/qapi-commands.py --output-dir=$AUTOGENERATED_DIR -m < qapi-schema.json
743log "Generate : $AUTOGENERATED_DIR"
744
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100745clean_temp
746
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800747echo "Ready to go. Type 'make' to build emulator"