blob: 1c1ab0ac11ad501681c88f75be81e3a92e8da56d [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
Andrew Hsieh7db680c2014-03-13 04:18:13 -0700109 PROBE_HOST_CC=`dirname $0`/../../prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/bin/x86_64-linux-gcc
110 if [ ! -f "$PROBE_HOST_CC" ] ; then
111 PROBE_HOST_CC=`dirname $0`/../../prebuilts/tools/gcc-sdk/gcc
112 fi
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100113 if [ -f "$PROBE_HOST_CC" ] ; then
114 echo "Using prebuilt toolchain: $PROBE_HOST_CC"
115 CC="$PROBE_HOST_CC"
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100116 fi
117fi
118
David 'Digit' Turnerba313e02011-02-09 16:01:53 +0100119if [ -n "$OPTION_CC" ]; then
120 echo "Using specified C compiler: $OPTION_CC"
121 CC="$OPTION_CC"
122fi
123
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700124if [ -z "$CC" ]; then
125 CC=$HOST_CC
126fi
127
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100128# By default, generate 32-bit binaries, the Makefile have targets that
129# generate 64-bit ones by using -m64 on the command-line.
130force_32bit_binaries
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800131
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200132case $OS in
133 linux-*)
134 TARGET_DLL_SUFFIX=.so
135 ;;
136 darwin-*)
137 TARGET_DLL_SUFFIX=.dylib
138 ;;
139 windows*)
140 TARGET_DLL_SUFFIX=.dll
141esac
142
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700143TARGET_OS=$OS
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100144
145setup_toolchain
146
147BUILD_AR=$AR
148BUILD_CC=$CC
149BUILD_CXX=$CC
150BUILD_LD=$LD
151BUILD_AR=$AR
152BUILD_CFLAGS=$CFLAGS
153BUILD_CXXFLAGS=$CXXFLAGS
154BUILD_LDFLAGS=$LDFLAGS
155
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200156if [ "$OPTION_MINGW" = "yes" ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700157 enable_linux_mingw
158 TARGET_OS=windows
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200159 TARGET_DLL_SUFFIX=.dll
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700160else
161 enable_cygwin
162fi
163
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200164# Are we running in the Android build system ?
165check_android_build
166
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800167
168# Adjust a few things when we're building within the Android build
169# system:
170# - locate prebuilt directory
171# - locate and use prebuilt libraries
172# - copy the new binary to the correct location
173#
174if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then
175 IN_ANDROID_BUILD=no
176fi
177
178if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200179 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800180
181 # use ccache if USE_CCACHE is defined and the corresponding
182 # binary is available.
183 #
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800184 if [ -n "$USE_CCACHE" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200185 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800186 if [ ! -f $CCACHE ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700187 CCACHE="$ANDROID_PREBUILTS/ccache/ccache$EXE"
188 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800189 fi
190
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800191 # finally ensure that our new binary is copied to the 'out'
192 # subdirectory as 'emulator'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200193 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200194 if [ "$TARGET_OS" = "windows" ]; then
195 HOST_BIN=$(echo $HOST_BIN | sed "s%$OS/bin%windows/bin%")
196 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800197 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200198 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
199 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800200 fi
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800201
202 # find the Android SDK Tools revision number
203 TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties
204 if [ -f $TOOLS_PROPS ] ; then
205 ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null`
206 log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION"
207 else
208 log "Tools : Could not locate $TOOLS_PROPS !?"
209 fi
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700210else
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100211 if [ "$USE_CCACHE" != 0 ]; then
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100212 CCACHE=$(which ccache 2>/dev/null)
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100213 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800214fi # IN_ANDROID_BUILD = no
215
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100216if [ -n "$CCACHE" -a -f "$CCACHE" ] ; then
217 CC="$CCACHE $CC"
218 log "Prebuilt : CCACHE=$CCACHE"
219else
220 log "Prebuilt : CCACHE can't be found"
221 CCACHE=
222fi
223
224# Try to find the GLES emulation headers and libraries automatically
225if [ "$GLES_PROBE" = "yes" ]; then
226 GLES_SUPPORT=yes
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100227 if [ -z "$GLES_DIR" ]; then
228 GLES_DIR=../../sdk/emulator/opengl
229 log2 "GLES : Probing source dir: $GLES_DIR"
230 if [ ! -d "$GLES_DIR" ]; then
231 GLES_DIR=../opengl
232 log2 "GLES : Probing source dir: $GLES_DIR"
233 if [ ! -d "$GLES_DIR" ]; then
234 GLES_DIR=
235 fi
236 fi
237 if [ -z "$GLES_DIR" ]; then
238 echo "GLES : Could not find GPU emulation sources!"
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100239 GLES_SUPPORT=no
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100240 else
241 echo "GLES : Found GPU emulation sources: $GLES_DIR"
242 GLES_SUPPORT=yes
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100243 fi
244 fi
245fi
246
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100247if [ "$PCBIOS_PROBE" = "yes" ]; then
248 PCBIOS_DIR=$(dirname "$0")/../../prebuilts/qemu-kernel/x86/pc-bios
249 if [ ! -d "$PCBIOS_DIR" ]; then
250 log2 "PC Bios : Probing $PCBIOS_DIR (missing)"
251 PCBIOS_DIR=../pc-bios
252 fi
253 log2 "PC Bios : Probing $PCBIOS_DIR"
254 if [ ! -d "$PCBIOS_DIR" ]; then
255 log "PC Bios : Could not find prebuilts directory."
256 else
257 mkdir -p objs/lib/pc-bios
258 for BIOS_FILE in bios.bin vgabios-cirrus.bin; do
259 log "PC Bios : Copying $BIOS_FILE"
260 cp -f $PCBIOS_DIR/$BIOS_FILE objs/lib/pc-bios/$BIOS_FILE
261 done
262 fi
263fi
264
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100265# For OS X, detect the location of the SDK to use.
266if [ "$HOST_OS" = darwin ]; then
267 OSX_VERSION=$(sw_vers -productVersion)
268 OSX_SDK_SUPPORTED="10.6 10.7 10.8"
269 OSX_SDK_INSTALLED_LIST=$(xcodebuild -showsdks 2>/dev/null | grep macosx | sed -e "s/.*macosx//g" | sort -n)
270 if [ -z "$OSX_SDK_INSTALLED_LIST" ]; then
271 echo "ERROR: Please install XCode on this machine!"
272 exit 1
273 fi
274 log "OSX: Installed SDKs: $OSX_SDK_INSTALLED_LIST"
275
276 OSX_SDK_VERSION=$(echo "$OSX_SDK_INSTALLED_LIST" | tr ' ' '\n' | head -1)
277 log "OSX: Using SDK version $OSX_SDK_VERSION"
278
279 XCODE_PATH=$(xcode-select -print-path 2>/dev/null)
280 log "OSX: XCode path: $XCODE_PATH"
281
282 OSX_SDK_ROOT=$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk
283 log "OSX: Looking for $OSX_SDK_ROOT"
284 if [ ! -d "$OSX_SDK_ROOT" ]; then
285 OSX_SDK_ROOT=/Developer/SDKs/MaxOSX${OSX_SDK_VERSION}.sdk
286 log "OSX: Looking for $OSX_SDK_ROOT"
287 if [ ! -d "$OSX_SDK_ROOT" ]; then
288 echo "ERROR: Could not find SDK $OSX_SDK_VERSION at $OSX_SDK_ROOT"
289 exit 1
290 fi
291 fi
292 echo "OSX SDK : Found at $OSX_SDK_ROOT"
293fi
294
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200295# we can build the emulator with Cygwin, so enable it
296enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800297
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200298setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800299
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800300###
301### SDL Probe
302###
303
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700304if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200305
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700306 # check that we can link statically with the library.
307 #
308 SDL_CFLAGS=`$SDL_CONFIG --cflags`
309 SDL_LIBS=`$SDL_CONFIG --static-libs`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800310
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700311 # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
Deepanshu Guptabb761912013-05-28 16:36:40 -0700312 # since they break recent Mingw releases
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700313 SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800314
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700315 log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
316 log "SDL-probe : SDL_LIBS = $SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800317
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800318
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700319 EXTRA_CFLAGS="$SDL_CFLAGS"
320 EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800321
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700322 case "$OS" in
323 freebsd-*)
324 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread"
325 ;;
326 esac
Alexey Tarasov08823222009-09-01 02:07:51 +1100327
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700328 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800329#include <SDL.h>
330#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200331int main( int argc, char** argv ) {
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200332 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800333}
334EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700335 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200336
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700337 if [ $SDL_LINKING != "yes" ] ; then
338 echo "You provided an explicit sdl-config script, but the corresponding library"
339 echo "cannot be statically linked with the Android emulator directly."
340 echo "Error message:"
341 cat $TMPL
342 clean_exit
343 fi
344 log "SDL-probe : static linking ok"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800345
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700346 # now, let's check that the SDL library has the special functions
347 # we added to our own sources
348 #
349 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800350#include <SDL.h>
351#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200352int main( int argc, char** argv ) {
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700353 int x, y;
354 SDL_Rect r;
355 SDL_WM_GetPos(&x, &y);
356 SDL_WM_SetPos(x, y);
357 SDL_WM_GetMonitorDPI(&x, &y);
358 SDL_WM_GetMonitorRect(&r);
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200359 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800360}
361EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700362 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200363
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700364 if [ $SDL_LINKING != "yes" ] ; then
365 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
366 echo "corresponding library doesn't have the patches required to link"
367 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
368 echo "sources bundled with the emulator instead"
369 echo "Error:"
370 cat $TMPL
371 clean_exit
372 fi
373
374 log "SDL-probe : extra features ok"
375 clean_temp
376
377 EXTRA_CFLAGS=
378 EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800379fi
380
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800381###
382### Audio subsystems probes
383###
384PROBE_COREAUDIO=no
385PROBE_ALSA=no
386PROBE_OSS=no
387PROBE_ESD=no
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700388PROBE_PULSEAUDIO=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800389PROBE_WINAUDIO=no
390
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700391case "$TARGET_OS" in
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800392 darwin*) PROBE_COREAUDIO=yes;
393 ;;
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700394 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800395 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100396 freebsd-*) PROBE_OSS=yes;
397 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800398 windows) PROBE_WINAUDIO=yes
399 ;;
400esac
401
402ORG_CFLAGS=$CFLAGS
403ORG_LDFLAGS=$LDFLAGS
404
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200405if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then
406PROBE_ESD_ESD=no
407PROBE_ALSA=no
408PROBE_PULSEAUDIO=no
409fi
410
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700411# Probe a system library
412#
413# $1: Variable name (e.g. PROBE_ESD)
414# $2: Library name (e.g. "Alsa")
415# $3: Path to source file for probe program (e.g. android/config/check-alsa.c)
416# $4: Package name (e.g. libasound-dev)
417#
418probe_system_library ()
419{
420 if [ `var_value $1` = yes ] ; then
421 CFLAGS="$ORG_CFLAGS"
422 LDFLAGS="$ORG_LDFLAGS -ldl"
423 cp -f android/config/check-esd.c $TMPC
David 'Digit' Turnera7ef1ac2010-12-10 22:33:51 +0100424 compile
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700425 if [ $? = 0 ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200426 log "AudioProbe : $2 seems to be usable on this system"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700427 else
428 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200429 echo "The $2 development files do not seem to be installed on this system"
430 echo "Are you missing the $4 package ?"
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100431 echo "You can ignore this error with --ignore-audio, otherwise correct"
432 echo "the issue(s) below and try again:"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700433 cat $TMPL
434 clean_exit
435 fi
436 eval $1=no
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200437 log "AudioProbe : $2 seems to be UNUSABLE on this system !!"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800438 fi
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100439 clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800440 fi
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700441}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800442
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700443probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev
444probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev
445probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800446
447CFLAGS=$ORG_CFLAGS
448LDFLAGS=$ORG_LDFLAGS
449
450# create the objs directory that is going to contain all generated files
451# including the configuration ones
452#
453mkdir -p objs
454
455###
456### Compiler probe
457###
458
459####
460#### Host system probe
461####
462
463# because the previous version could be read-only
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100464clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800465
466# check host endianess
467#
468HOST_BIGENDIAN=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700469if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800470cat > $TMPC << EOF
471#include <inttypes.h>
472int main(int argc, char ** argv){
473 volatile uint32_t i=0x01234567;
Marcus Comstedt17d31322010-10-05 21:54:12 +0200474 return (*((uint8_t*)(&i))) == 0x01;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800475}
476EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200477feature_run_exec HOST_BIGENDIAN
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700478fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800479
480# check size of host long bits
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700481HOST_LONGBITS=32
482if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800483cat > $TMPC << EOF
484int main(void) {
485 return sizeof(void*)*8;
486}
487EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200488feature_run_exec HOST_LONGBITS
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700489fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800490
491# check whether we have <byteswap.h>
492#
David Turnerb8fec3e2010-09-09 18:15:23 +0200493feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
494feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
495feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
David Turner80dd1262010-09-09 18:04:49 +0200496
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800497# Build the config.make file
498#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200499
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100500case $OS in
501 windows)
502 HOST_EXEEXT=.exe
503 HOST_DLLEXT=.dll
504 ;;
505 darwin)
506 HOST_EXEEXT=
507 HOST_DLLEXT=.dylib
508 ;;
509 *)
510 HOST_EXEEXT=
511 HOST_DLLEXT=
512 ;;
513esac
514
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200515case $TARGET_OS in
516 windows)
517 TARGET_EXEEXT=.exe
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100518 TARGET_DLLEXT=.dll
519 ;;
520 darwin)
521 TARGET_EXEXT=
522 TARGET_DLLEXT=.dylib
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200523 ;;
524 *)
525 TARGET_EXEEXT=
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100526 TARGET_DLLEXT=.so
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200527 ;;
528esac
529
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100530# Strip executables and shared libraries unless --debug is used.
531if [ "$OPTION_DEBUG" != "yes" ]; then
532 case $HOST_OS in
533 darwin)
534 LDFLAGS="$LDFLAGS -Wl,-S"
535 ;;
536 *)
537 LDFLAGS="$LDFLAGS -Wl,--strip-all"
538 ;;
539 esac
540fi
541
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200542create_config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700543echo "" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700544echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200545echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100546echo "HOST_DLLEXT := $TARGET_DLLEXT" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700547echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700548echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200549
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100550echo "" >> $config_mk
551echo "BUILD_OS := $HOST_OS" >> $config_mk
552echo "BUILD_ARCH := $HOST_ARCH" >> $config_mk
553echo "BUILD_EXEEXT := $HOST_EXEEXT" >> $config_mk
554echo "BUILD_DLLEXT := $HOST_DLLEXT" >> $config_mk
555echo "BUILD_AR := $BUILD_AR" >> $config_mk
556echo "BUILD_CC := $BUILD_CC" >> $config_mk
557echo "BUILD_CXX := $BUILD_CXX" >> $config_mk
558echo "BUILD_LD := $BUILD_LD" >> $config_mk
559echo "BUILD_CFLAGS := $BUILD_CFLAGS" >> $config_mk
560echo "BUILD_LDFLAGS := $BUILD_LDFLAGS" >> $config_mk
561
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800562PWD=`pwd`
563echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700564if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200565echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700566fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800567echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
568echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
569echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
570echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
571echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700572echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800573echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200574if [ $OPTION_DEBUG = yes ] ; then
575 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
576fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800577if [ $OPTION_STATIC = yes ] ; then
578 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
579fi
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100580if [ "$GLES_SUPPORT" = "yes" ]; then
581 echo "EMULATOR_BUILD_EMUGL := true" >> $config_mk
582 echo "EMULATOR_EMUGL_SOURCES_DIR := $GLES_DIR" >> $config_mk
583fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800584
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800585if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
586 echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
587fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800588
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700589if [ "$OPTION_MINGW" = "yes" ] ; then
590 echo "" >> $config_mk
591 echo "USE_MINGW := 1" >> $config_mk
592 echo "HOST_OS := windows" >> $config_mk
593fi
594
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100595if [ "$HOST_OS" = "darwin" ]; then
596 echo "mac_sdk_root := $OSX_SDK_ROOT" >> $config_mk
597 echo "mac_sdk_version := $OSX_SDK_VERSION" >> $config_mk
598fi
599
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800600# Build the config-host.h file
601#
602config_h=objs/config-host.h
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100603cat > $config_h <<EOF
604/* This file was autogenerated by '$PROGNAME' */
605
606#define CONFIG_QEMU_SHAREDIR "/usr/local/share/qemu"
607
608#if defined(__x86_64__)
609#define HOST_X86_64 1
610#define HOST_LONG_BITS 64
611#elif defined(__i386__)
612#define HOST_I386 1
613#define HOST_LONG_BITS 32
614#else
615#error Unknown architecture for codegen
616#endif
617
618EOF
619
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800620if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200621 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
622fi
623if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
624 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800625fi
David Turner80dd1262010-09-09 18:04:49 +0200626if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
627 echo "#define CONFIG_FNMATCH 1" >> $config_h
628fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800629echo "#define CONFIG_GDBSTUB 1" >> $config_h
630echo "#define CONFIG_SLIRP 1" >> $config_h
631echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200632echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700633
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200634case "$TARGET_OS" in
635 windows)
636 echo "#define CONFIG_WIN32 1" >> $config_h
637 ;;
638 *)
639 echo "#define CONFIG_POSIX 1" >> $config_h
640 ;;
641esac
642
643case "$TARGET_OS" in
644 linux-*)
645 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
646 ;;
647esac
648
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700649# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700650case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700651 linux-*)
652 echo "#define CONFIG_FDATASYNC 1" >> $config_h
653 ;;
654esac
655
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200656case "$TARGET_OS" in
657 linux-*|darwin-*)
658 echo "#define CONFIG_MADVISE 1" >> $config_h
659 ;;
660esac
661
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800662# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700663if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800664 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
665fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700666echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
667echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800668case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200669 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800670 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200671 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800672 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200673 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800674 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200675 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800676 ;;
677esac
Marcus Comstedt17d31322010-10-05 21:54:12 +0200678if [ "$HOST_BIGENDIAN" = "1" ] ; then
679 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
680fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200681BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700682case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200683 linux-*) CONFIG_OS=LINUX
684 ;;
685 darwin-*) CONFIG_OS=DARWIN
686 BSD=1
687 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100688 freebsd-*) CONFIG_OS=FREEBSD
689 BSD=1
690 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200691 windows*) CONFIG_OS=WIN32
692 ;;
693 *) CONFIG_OS=$OS
694esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700695
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800696if [ "$OPTION_STATIC" = "yes" ] ; then
697 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
698 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
699fi
700
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700701case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700702 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800703 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700704 ;;
705esac
706
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200707echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
708if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700709 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200710 echo "#define O_LARGEFILE 0" >> $config_h
711 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
712fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700713
David 'Digit' Turner494b1292014-02-05 15:02:04 +0100714case "$TARGET_OS" in
715 linux-*)
716 echo "#define CONFIG_SIGNALFD 1" >> $config_h
717 ;;
718esac
719
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700720echo "#define CONFIG_ANDROID 1" >> $config_h
721
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800722log "Generate : $config_h"
723
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100724# Generate the QAPI headers and sources from qapi-schema.json
725# Ideally, this would be done in our Makefiles, but as far as I
726# understand, the platform build doesn't support a single tool
727# that generates several sources files, nor the standalone one.
728export PYTHONDONTWRITEBYTECODE=1
729AUTOGENERATED_DIR=qapi-auto-generated
730python scripts/qapi-types.py qapi.types --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
731python scripts/qapi-visit.py --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
732python scripts/qapi-commands.py --output-dir=$AUTOGENERATED_DIR -m < qapi-schema.json
733log "Generate : $AUTOGENERATED_DIR"
734
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100735clean_temp
736
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800737echo "Ready to go. Type 'make' to build emulator"