blob: d28209a7ae42531b8105ef29870b799997c263a8 [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
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800480# check whether we have <byteswap.h>
481#
David Turnerb8fec3e2010-09-09 18:15:23 +0200482feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
483feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
484feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
David Turner80dd1262010-09-09 18:04:49 +0200485
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800486# Build the config.make file
487#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200488
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100489case $OS in
490 windows)
491 HOST_EXEEXT=.exe
492 HOST_DLLEXT=.dll
493 ;;
494 darwin)
495 HOST_EXEEXT=
496 HOST_DLLEXT=.dylib
497 ;;
498 *)
499 HOST_EXEEXT=
500 HOST_DLLEXT=
501 ;;
502esac
503
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200504case $TARGET_OS in
505 windows)
506 TARGET_EXEEXT=.exe
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100507 TARGET_DLLEXT=.dll
508 ;;
509 darwin)
510 TARGET_EXEXT=
511 TARGET_DLLEXT=.dylib
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200512 ;;
513 *)
514 TARGET_EXEEXT=
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100515 TARGET_DLLEXT=.so
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200516 ;;
517esac
518
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100519# Strip executables and shared libraries unless --debug is used.
David 'Digit' Turner3e3ff5a2014-03-14 11:20:10 +0100520if [ "$OPTION_DEBUG" != "yes" -a "$OPTION_NO_STRIP" != "yes" ]; then
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100521 case $HOST_OS in
522 darwin)
523 LDFLAGS="$LDFLAGS -Wl,-S"
524 ;;
525 *)
526 LDFLAGS="$LDFLAGS -Wl,--strip-all"
527 ;;
528 esac
529fi
530
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200531create_config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700532echo "" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700533echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200534echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100535echo "HOST_DLLEXT := $TARGET_DLLEXT" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700536echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700537echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200538
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100539echo "" >> $config_mk
540echo "BUILD_OS := $HOST_OS" >> $config_mk
541echo "BUILD_ARCH := $HOST_ARCH" >> $config_mk
542echo "BUILD_EXEEXT := $HOST_EXEEXT" >> $config_mk
543echo "BUILD_DLLEXT := $HOST_DLLEXT" >> $config_mk
544echo "BUILD_AR := $BUILD_AR" >> $config_mk
545echo "BUILD_CC := $BUILD_CC" >> $config_mk
546echo "BUILD_CXX := $BUILD_CXX" >> $config_mk
547echo "BUILD_LD := $BUILD_LD" >> $config_mk
548echo "BUILD_CFLAGS := $BUILD_CFLAGS" >> $config_mk
549echo "BUILD_LDFLAGS := $BUILD_LDFLAGS" >> $config_mk
550
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800551PWD=`pwd`
552echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700553if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200554echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700555fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800556echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
557echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
558echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
559echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
560echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700561echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800562echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200563if [ $OPTION_DEBUG = yes ] ; then
564 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
565fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800566if [ $OPTION_STATIC = yes ] ; then
567 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
568fi
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100569if [ "$GLES_SUPPORT" = "yes" ]; then
570 echo "EMULATOR_BUILD_EMUGL := true" >> $config_mk
571 echo "EMULATOR_EMUGL_SOURCES_DIR := $GLES_DIR" >> $config_mk
572fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800573
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800574if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
575 echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
576fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800577
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700578if [ "$OPTION_MINGW" = "yes" ] ; then
579 echo "" >> $config_mk
580 echo "USE_MINGW := 1" >> $config_mk
581 echo "HOST_OS := windows" >> $config_mk
582fi
583
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100584if [ "$HOST_OS" = "darwin" ]; then
585 echo "mac_sdk_root := $OSX_SDK_ROOT" >> $config_mk
586 echo "mac_sdk_version := $OSX_SDK_VERSION" >> $config_mk
587fi
588
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800589# Build the config-host.h file
590#
591config_h=objs/config-host.h
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100592cat > $config_h <<EOF
593/* This file was autogenerated by '$PROGNAME' */
594
595#define CONFIG_QEMU_SHAREDIR "/usr/local/share/qemu"
596
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100597EOF
598
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800599if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200600 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
601fi
602if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
603 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800604fi
David Turner80dd1262010-09-09 18:04:49 +0200605if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
606 echo "#define CONFIG_FNMATCH 1" >> $config_h
607fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800608echo "#define CONFIG_GDBSTUB 1" >> $config_h
609echo "#define CONFIG_SLIRP 1" >> $config_h
610echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200611echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700612
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200613case "$TARGET_OS" in
614 windows)
615 echo "#define CONFIG_WIN32 1" >> $config_h
616 ;;
617 *)
618 echo "#define CONFIG_POSIX 1" >> $config_h
619 ;;
620esac
621
622case "$TARGET_OS" in
623 linux-*)
624 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
625 ;;
626esac
627
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700628# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700629case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700630 linux-*)
631 echo "#define CONFIG_FDATASYNC 1" >> $config_h
632 ;;
633esac
634
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200635case "$TARGET_OS" in
636 linux-*|darwin-*)
637 echo "#define CONFIG_MADVISE 1" >> $config_h
638 ;;
639esac
640
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800641# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700642if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800643 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
644fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700645echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
646echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800647case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200648 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800649 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200650 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800651 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200652 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800653 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200654 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800655 ;;
656esac
Marcus Comstedt17d31322010-10-05 21:54:12 +0200657if [ "$HOST_BIGENDIAN" = "1" ] ; then
658 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
659fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200660BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700661case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200662 linux-*) CONFIG_OS=LINUX
663 ;;
664 darwin-*) CONFIG_OS=DARWIN
665 BSD=1
666 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100667 freebsd-*) CONFIG_OS=FREEBSD
668 BSD=1
669 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200670 windows*) CONFIG_OS=WIN32
671 ;;
672 *) CONFIG_OS=$OS
673esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700674
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800675if [ "$OPTION_STATIC" = "yes" ] ; then
676 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
677 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
678fi
679
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700680case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700681 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800682 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700683 ;;
684esac
685
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200686echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
687if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700688 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200689 echo "#define O_LARGEFILE 0" >> $config_h
690 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
691fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700692
David 'Digit' Turner494b1292014-02-05 15:02:04 +0100693case "$TARGET_OS" in
694 linux-*)
695 echo "#define CONFIG_SIGNALFD 1" >> $config_h
696 ;;
697esac
698
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700699echo "#define CONFIG_ANDROID 1" >> $config_h
700
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800701log "Generate : $config_h"
702
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100703# Generate the QAPI headers and sources from qapi-schema.json
704# Ideally, this would be done in our Makefiles, but as far as I
705# understand, the platform build doesn't support a single tool
706# that generates several sources files, nor the standalone one.
707export PYTHONDONTWRITEBYTECODE=1
708AUTOGENERATED_DIR=qapi-auto-generated
709python scripts/qapi-types.py qapi.types --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
710python scripts/qapi-visit.py --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
711python scripts/qapi-commands.py --output-dir=$AUTOGENERATED_DIR -m < qapi-schema.json
712log "Generate : $AUTOGENERATED_DIR"
713
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100714clean_temp
715
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800716echo "Ready to go. Type 'make' to build emulator"