blob: 64f2f9661e24a2cf38c3e9e147a6dd5d0ec146f3 [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' Turner52ffef32014-04-28 11:20:47 +0200107# that are compatible with Ubuntu 10.4
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700108if [ -z "$CC" -a -z "$OPTION_CC" -a "$HOST_OS" = linux ] ; then
David 'Digit' Turner52ffef32014-04-28 11:20:47 +0200109 PREBUILTS_HOST_GCC=$(dirname $0)/../../prebuilts/gcc/linux-x86/host
David 'Digit' Turner295ef3d2014-04-30 11:02:03 +0200110 # NOTE: GCC 4.8 is currently disabled because this breaks MIPS emulation
111 # For some odd reason. Remove the 'DISABLED_' prefix below to re-enable it,
112 # e.g. once the MIPS backend has been updated to a more recent version.
113 # This only affects Linux emulator binaries.
114 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 +0200115 if [ ! -f "$PROBE_HOST_CC" ]; then
116 PROBE_HOST_CC=$PREBUILTS_HOST_GCC/x86_64-linux-glibc2.11-4.6/bin/x86_64-linux-gcc
117 if [ ! -f "$PROBE_HOST_CC" ] ; then
118 PROBE_HOST_CC=$(dirname $0)/../../prebuilts/tools/gcc-sdk/gcc
119 fi
Andrew Hsieh7db680c2014-03-13 04:18:13 -0700120 fi
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100121 if [ -f "$PROBE_HOST_CC" ] ; then
122 echo "Using prebuilt toolchain: $PROBE_HOST_CC"
123 CC="$PROBE_HOST_CC"
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100124 fi
125fi
126
David 'Digit' Turnerba313e02011-02-09 16:01:53 +0100127if [ -n "$OPTION_CC" ]; then
128 echo "Using specified C compiler: $OPTION_CC"
129 CC="$OPTION_CC"
130fi
131
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700132if [ -z "$CC" ]; then
133 CC=$HOST_CC
134fi
135
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100136# By default, generate 32-bit binaries, the Makefile have targets that
137# generate 64-bit ones by using -m64 on the command-line.
138force_32bit_binaries
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800139
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200140case $OS in
141 linux-*)
142 TARGET_DLL_SUFFIX=.so
143 ;;
144 darwin-*)
145 TARGET_DLL_SUFFIX=.dylib
146 ;;
147 windows*)
148 TARGET_DLL_SUFFIX=.dll
149esac
150
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700151TARGET_OS=$OS
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100152
153setup_toolchain
154
155BUILD_AR=$AR
156BUILD_CC=$CC
157BUILD_CXX=$CC
158BUILD_LD=$LD
159BUILD_AR=$AR
160BUILD_CFLAGS=$CFLAGS
161BUILD_CXXFLAGS=$CXXFLAGS
162BUILD_LDFLAGS=$LDFLAGS
163
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200164if [ "$OPTION_MINGW" = "yes" ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700165 enable_linux_mingw
166 TARGET_OS=windows
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200167 TARGET_DLL_SUFFIX=.dll
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700168else
169 enable_cygwin
170fi
171
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200172# Are we running in the Android build system ?
173check_android_build
174
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800175
176# Adjust a few things when we're building within the Android build
177# system:
178# - locate prebuilt directory
179# - locate and use prebuilt libraries
180# - copy the new binary to the correct location
181#
182if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then
183 IN_ANDROID_BUILD=no
184fi
185
186if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200187 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800188
189 # use ccache if USE_CCACHE is defined and the corresponding
190 # binary is available.
191 #
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800192 if [ -n "$USE_CCACHE" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200193 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800194 if [ ! -f $CCACHE ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700195 CCACHE="$ANDROID_PREBUILTS/ccache/ccache$EXE"
196 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800197 fi
198
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800199 # finally ensure that our new binary is copied to the 'out'
200 # subdirectory as 'emulator'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200201 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200202 if [ "$TARGET_OS" = "windows" ]; then
203 HOST_BIN=$(echo $HOST_BIN | sed "s%$OS/bin%windows/bin%")
204 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800205 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200206 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
207 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800208 fi
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800209
210 # find the Android SDK Tools revision number
211 TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties
212 if [ -f $TOOLS_PROPS ] ; then
213 ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null`
214 log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION"
215 else
216 log "Tools : Could not locate $TOOLS_PROPS !?"
217 fi
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700218else
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100219 if [ "$USE_CCACHE" != 0 ]; then
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100220 CCACHE=$(which ccache 2>/dev/null)
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100221 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800222fi # IN_ANDROID_BUILD = no
223
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100224if [ -n "$CCACHE" -a -f "$CCACHE" ] ; then
225 CC="$CCACHE $CC"
226 log "Prebuilt : CCACHE=$CCACHE"
227else
228 log "Prebuilt : CCACHE can't be found"
229 CCACHE=
230fi
231
232# Try to find the GLES emulation headers and libraries automatically
233if [ "$GLES_PROBE" = "yes" ]; then
234 GLES_SUPPORT=yes
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100235 if [ -z "$GLES_DIR" ]; then
236 GLES_DIR=../../sdk/emulator/opengl
237 log2 "GLES : Probing source dir: $GLES_DIR"
238 if [ ! -d "$GLES_DIR" ]; then
239 GLES_DIR=../opengl
240 log2 "GLES : Probing source dir: $GLES_DIR"
241 if [ ! -d "$GLES_DIR" ]; then
242 GLES_DIR=
243 fi
244 fi
245 if [ -z "$GLES_DIR" ]; then
246 echo "GLES : Could not find GPU emulation sources!"
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100247 GLES_SUPPORT=no
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100248 else
249 echo "GLES : Found GPU emulation sources: $GLES_DIR"
250 GLES_SUPPORT=yes
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100251 fi
252 fi
253fi
254
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100255if [ "$PCBIOS_PROBE" = "yes" ]; then
256 PCBIOS_DIR=$(dirname "$0")/../../prebuilts/qemu-kernel/x86/pc-bios
257 if [ ! -d "$PCBIOS_DIR" ]; then
258 log2 "PC Bios : Probing $PCBIOS_DIR (missing)"
259 PCBIOS_DIR=../pc-bios
260 fi
261 log2 "PC Bios : Probing $PCBIOS_DIR"
262 if [ ! -d "$PCBIOS_DIR" ]; then
263 log "PC Bios : Could not find prebuilts directory."
264 else
265 mkdir -p objs/lib/pc-bios
266 for BIOS_FILE in bios.bin vgabios-cirrus.bin; do
267 log "PC Bios : Copying $BIOS_FILE"
268 cp -f $PCBIOS_DIR/$BIOS_FILE objs/lib/pc-bios/$BIOS_FILE
269 done
270 fi
271fi
272
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100273# For OS X, detect the location of the SDK to use.
274if [ "$HOST_OS" = darwin ]; then
275 OSX_VERSION=$(sw_vers -productVersion)
276 OSX_SDK_SUPPORTED="10.6 10.7 10.8"
277 OSX_SDK_INSTALLED_LIST=$(xcodebuild -showsdks 2>/dev/null | grep macosx | sed -e "s/.*macosx//g" | sort -n)
278 if [ -z "$OSX_SDK_INSTALLED_LIST" ]; then
279 echo "ERROR: Please install XCode on this machine!"
280 exit 1
281 fi
282 log "OSX: Installed SDKs: $OSX_SDK_INSTALLED_LIST"
283
284 OSX_SDK_VERSION=$(echo "$OSX_SDK_INSTALLED_LIST" | tr ' ' '\n' | head -1)
285 log "OSX: Using SDK version $OSX_SDK_VERSION"
286
287 XCODE_PATH=$(xcode-select -print-path 2>/dev/null)
288 log "OSX: XCode path: $XCODE_PATH"
289
290 OSX_SDK_ROOT=$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk
291 log "OSX: Looking for $OSX_SDK_ROOT"
292 if [ ! -d "$OSX_SDK_ROOT" ]; then
293 OSX_SDK_ROOT=/Developer/SDKs/MaxOSX${OSX_SDK_VERSION}.sdk
294 log "OSX: Looking for $OSX_SDK_ROOT"
295 if [ ! -d "$OSX_SDK_ROOT" ]; then
296 echo "ERROR: Could not find SDK $OSX_SDK_VERSION at $OSX_SDK_ROOT"
297 exit 1
298 fi
299 fi
300 echo "OSX SDK : Found at $OSX_SDK_ROOT"
301fi
302
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200303# we can build the emulator with Cygwin, so enable it
304enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800305
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200306setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800307
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800308###
309### SDL Probe
310###
311
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700312if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200313
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700314 # check that we can link statically with the library.
315 #
316 SDL_CFLAGS=`$SDL_CONFIG --cflags`
317 SDL_LIBS=`$SDL_CONFIG --static-libs`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800318
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700319 # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
Deepanshu Guptabb761912013-05-28 16:36:40 -0700320 # since they break recent Mingw releases
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700321 SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800322
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700323 log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
324 log "SDL-probe : SDL_LIBS = $SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800325
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800326
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700327 EXTRA_CFLAGS="$SDL_CFLAGS"
328 EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800329
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700330 case "$OS" in
331 freebsd-*)
332 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread"
333 ;;
334 esac
Alexey Tarasov08823222009-09-01 02:07:51 +1100335
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700336 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800337#include <SDL.h>
338#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200339int main( int argc, char** argv ) {
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200340 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800341}
342EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700343 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200344
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700345 if [ $SDL_LINKING != "yes" ] ; then
346 echo "You provided an explicit sdl-config script, but the corresponding library"
347 echo "cannot be statically linked with the Android emulator directly."
348 echo "Error message:"
349 cat $TMPL
350 clean_exit
351 fi
352 log "SDL-probe : static linking ok"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800353
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700354 # now, let's check that the SDL library has the special functions
355 # we added to our own sources
356 #
357 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800358#include <SDL.h>
359#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200360int main( int argc, char** argv ) {
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700361 int x, y;
362 SDL_Rect r;
363 SDL_WM_GetPos(&x, &y);
364 SDL_WM_SetPos(x, y);
365 SDL_WM_GetMonitorDPI(&x, &y);
366 SDL_WM_GetMonitorRect(&r);
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200367 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800368}
369EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700370 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200371
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700372 if [ $SDL_LINKING != "yes" ] ; then
373 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
374 echo "corresponding library doesn't have the patches required to link"
375 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
376 echo "sources bundled with the emulator instead"
377 echo "Error:"
378 cat $TMPL
379 clean_exit
380 fi
381
382 log "SDL-probe : extra features ok"
383 clean_temp
384
385 EXTRA_CFLAGS=
386 EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800387fi
388
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800389###
390### Audio subsystems probes
391###
392PROBE_COREAUDIO=no
393PROBE_ALSA=no
394PROBE_OSS=no
395PROBE_ESD=no
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700396PROBE_PULSEAUDIO=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800397PROBE_WINAUDIO=no
398
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700399case "$TARGET_OS" in
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800400 darwin*) PROBE_COREAUDIO=yes;
401 ;;
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700402 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800403 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100404 freebsd-*) PROBE_OSS=yes;
405 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800406 windows) PROBE_WINAUDIO=yes
407 ;;
408esac
409
410ORG_CFLAGS=$CFLAGS
411ORG_LDFLAGS=$LDFLAGS
412
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200413if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then
414PROBE_ESD_ESD=no
415PROBE_ALSA=no
416PROBE_PULSEAUDIO=no
417fi
418
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700419# Probe a system library
420#
421# $1: Variable name (e.g. PROBE_ESD)
422# $2: Library name (e.g. "Alsa")
423# $3: Path to source file for probe program (e.g. android/config/check-alsa.c)
424# $4: Package name (e.g. libasound-dev)
425#
426probe_system_library ()
427{
428 if [ `var_value $1` = yes ] ; then
429 CFLAGS="$ORG_CFLAGS"
430 LDFLAGS="$ORG_LDFLAGS -ldl"
431 cp -f android/config/check-esd.c $TMPC
David 'Digit' Turnera7ef1ac2010-12-10 22:33:51 +0100432 compile
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700433 if [ $? = 0 ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200434 log "AudioProbe : $2 seems to be usable on this system"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700435 else
436 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200437 echo "The $2 development files do not seem to be installed on this system"
438 echo "Are you missing the $4 package ?"
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100439 echo "You can ignore this error with --ignore-audio, otherwise correct"
440 echo "the issue(s) below and try again:"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700441 cat $TMPL
442 clean_exit
443 fi
444 eval $1=no
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200445 log "AudioProbe : $2 seems to be UNUSABLE on this system !!"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800446 fi
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100447 clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800448 fi
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700449}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800450
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700451probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev
452probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev
453probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800454
455CFLAGS=$ORG_CFLAGS
456LDFLAGS=$ORG_LDFLAGS
457
458# create the objs directory that is going to contain all generated files
459# including the configuration ones
460#
461mkdir -p objs
462
463###
464### Compiler probe
465###
466
467####
468#### Host system probe
469####
470
471# because the previous version could be read-only
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100472clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800473
474# check host endianess
475#
476HOST_BIGENDIAN=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700477if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800478cat > $TMPC << EOF
479#include <inttypes.h>
480int main(int argc, char ** argv){
481 volatile uint32_t i=0x01234567;
Marcus Comstedt17d31322010-10-05 21:54:12 +0200482 return (*((uint8_t*)(&i))) == 0x01;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800483}
484EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200485feature_run_exec HOST_BIGENDIAN
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700486fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800487
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800488# 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
David 'Digit' Turner7891dd32014-04-28 10:59:47 +0200494# check for Mingw version.
495MINGW_VERSION=
496if [ "$TARGET_OS" = "windows" ]; then
497log "Mingw : Probing for GCC version."
498GCC_VERSION=$($CC -v 2>&1 | awk '$1 == "gcc" && $2 == "version" { print $3; }')
499GCC_MAJOR=$(echo "$GCC_VERSION" | cut -f1 -d.)
500GCC_MINOR=$(echo "$GCC_VERSION" | cut -f2 -d.)
501log "Mingw : Found GCC version $GCC_MAJOR.$GCC_MINOR [$GCC_VERSION]"
502MINGW_GCC_VERSION=$(( $GCC_MAJOR * 100 + $GCC_MINOR ))
503fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800504# Build the config.make file
505#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200506
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100507case $OS in
508 windows)
509 HOST_EXEEXT=.exe
510 HOST_DLLEXT=.dll
511 ;;
512 darwin)
513 HOST_EXEEXT=
514 HOST_DLLEXT=.dylib
515 ;;
516 *)
517 HOST_EXEEXT=
518 HOST_DLLEXT=
519 ;;
520esac
521
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200522case $TARGET_OS in
523 windows)
524 TARGET_EXEEXT=.exe
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100525 TARGET_DLLEXT=.dll
526 ;;
527 darwin)
528 TARGET_EXEXT=
529 TARGET_DLLEXT=.dylib
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200530 ;;
531 *)
532 TARGET_EXEEXT=
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100533 TARGET_DLLEXT=.so
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200534 ;;
535esac
536
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100537# Strip executables and shared libraries unless --debug is used.
David 'Digit' Turner3e3ff5a2014-03-14 11:20:10 +0100538if [ "$OPTION_DEBUG" != "yes" -a "$OPTION_NO_STRIP" != "yes" ]; then
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100539 case $HOST_OS in
540 darwin)
541 LDFLAGS="$LDFLAGS -Wl,-S"
542 ;;
543 *)
544 LDFLAGS="$LDFLAGS -Wl,--strip-all"
545 ;;
546 esac
547fi
548
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200549create_config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700550echo "" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700551echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200552echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100553echo "HOST_DLLEXT := $TARGET_DLLEXT" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700554echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700555echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200556
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100557echo "" >> $config_mk
558echo "BUILD_OS := $HOST_OS" >> $config_mk
559echo "BUILD_ARCH := $HOST_ARCH" >> $config_mk
560echo "BUILD_EXEEXT := $HOST_EXEEXT" >> $config_mk
561echo "BUILD_DLLEXT := $HOST_DLLEXT" >> $config_mk
562echo "BUILD_AR := $BUILD_AR" >> $config_mk
563echo "BUILD_CC := $BUILD_CC" >> $config_mk
564echo "BUILD_CXX := $BUILD_CXX" >> $config_mk
565echo "BUILD_LD := $BUILD_LD" >> $config_mk
566echo "BUILD_CFLAGS := $BUILD_CFLAGS" >> $config_mk
567echo "BUILD_LDFLAGS := $BUILD_LDFLAGS" >> $config_mk
568
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800569PWD=`pwd`
570echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700571if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200572echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700573fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800574echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
575echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
576echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
577echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
578echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700579echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800580echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200581if [ $OPTION_DEBUG = yes ] ; then
582 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
583fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800584if [ $OPTION_STATIC = yes ] ; then
585 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
586fi
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100587if [ "$GLES_SUPPORT" = "yes" ]; then
588 echo "EMULATOR_BUILD_EMUGL := true" >> $config_mk
589 echo "EMULATOR_EMUGL_SOURCES_DIR := $GLES_DIR" >> $config_mk
590fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800591
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800592if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
593 echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
594fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800595
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700596if [ "$OPTION_MINGW" = "yes" ] ; then
597 echo "" >> $config_mk
598 echo "USE_MINGW := 1" >> $config_mk
599 echo "HOST_OS := windows" >> $config_mk
David 'Digit' Turner7891dd32014-04-28 10:59:47 +0200600 echo "HOST_MINGW_VERSION := $MINGW_GCC_VERSION" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700601fi
602
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100603if [ "$HOST_OS" = "darwin" ]; then
604 echo "mac_sdk_root := $OSX_SDK_ROOT" >> $config_mk
605 echo "mac_sdk_version := $OSX_SDK_VERSION" >> $config_mk
606fi
607
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800608# Build the config-host.h file
609#
610config_h=objs/config-host.h
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100611cat > $config_h <<EOF
612/* This file was autogenerated by '$PROGNAME' */
613
614#define CONFIG_QEMU_SHAREDIR "/usr/local/share/qemu"
615
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100616EOF
617
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800618if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200619 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
620fi
621if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
622 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800623fi
David Turner80dd1262010-09-09 18:04:49 +0200624if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
625 echo "#define CONFIG_FNMATCH 1" >> $config_h
626fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800627echo "#define CONFIG_GDBSTUB 1" >> $config_h
628echo "#define CONFIG_SLIRP 1" >> $config_h
629echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200630echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700631
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200632case "$TARGET_OS" in
633 windows)
634 echo "#define CONFIG_WIN32 1" >> $config_h
635 ;;
636 *)
637 echo "#define CONFIG_POSIX 1" >> $config_h
638 ;;
639esac
640
641case "$TARGET_OS" in
642 linux-*)
643 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
644 ;;
645esac
646
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700647# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700648case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700649 linux-*)
650 echo "#define CONFIG_FDATASYNC 1" >> $config_h
651 ;;
652esac
653
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200654case "$TARGET_OS" in
655 linux-*|darwin-*)
656 echo "#define CONFIG_MADVISE 1" >> $config_h
657 ;;
658esac
659
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800660# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700661if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800662 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
663fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700664echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
665echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800666case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200667 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800668 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200669 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800670 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200671 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800672 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200673 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800674 ;;
675esac
Marcus Comstedt17d31322010-10-05 21:54:12 +0200676if [ "$HOST_BIGENDIAN" = "1" ] ; then
677 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
678fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200679BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700680case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200681 linux-*) CONFIG_OS=LINUX
682 ;;
683 darwin-*) CONFIG_OS=DARWIN
684 BSD=1
685 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100686 freebsd-*) CONFIG_OS=FREEBSD
687 BSD=1
688 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200689 windows*) CONFIG_OS=WIN32
690 ;;
691 *) CONFIG_OS=$OS
692esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700693
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800694if [ "$OPTION_STATIC" = "yes" ] ; then
695 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
696 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
697fi
698
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700699case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700700 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800701 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700702 ;;
703esac
704
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200705echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
706if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700707 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200708 echo "#define O_LARGEFILE 0" >> $config_h
709 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
710fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700711
David 'Digit' Turner494b1292014-02-05 15:02:04 +0100712case "$TARGET_OS" in
713 linux-*)
714 echo "#define CONFIG_SIGNALFD 1" >> $config_h
715 ;;
716esac
717
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700718echo "#define CONFIG_ANDROID 1" >> $config_h
719
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800720log "Generate : $config_h"
721
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100722# Generate the QAPI headers and sources from qapi-schema.json
723# Ideally, this would be done in our Makefiles, but as far as I
724# understand, the platform build doesn't support a single tool
725# that generates several sources files, nor the standalone one.
726export PYTHONDONTWRITEBYTECODE=1
727AUTOGENERATED_DIR=qapi-auto-generated
728python scripts/qapi-types.py qapi.types --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
729python scripts/qapi-visit.py --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
730python scripts/qapi-commands.py --output-dir=$AUTOGENERATED_DIR -m < qapi-schema.json
731log "Generate : $AUTOGENERATED_DIR"
732
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100733clean_temp
734
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800735echo "Ready to go. Type 'make' to build emulator"