blob: e79ce1b81b42c404892d559b2807f6a2d3cbf87e [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
110 PROBE_HOST_CC=$PREBUILTS_HOST_GCC/x86_64-linux-glibc2.11-4.8/bin/x86_64-linux-gcc
111 if [ ! -f "$PROBE_HOST_CC" ]; then
112 PROBE_HOST_CC=$PREBUILTS_HOST_GCC/x86_64-linux-glibc2.11-4.6/bin/x86_64-linux-gcc
113 if [ ! -f "$PROBE_HOST_CC" ] ; then
114 PROBE_HOST_CC=$(dirname $0)/../../prebuilts/tools/gcc-sdk/gcc
115 fi
Andrew Hsieh7db680c2014-03-13 04:18:13 -0700116 fi
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100117 if [ -f "$PROBE_HOST_CC" ] ; then
118 echo "Using prebuilt toolchain: $PROBE_HOST_CC"
119 CC="$PROBE_HOST_CC"
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100120 fi
121fi
122
David 'Digit' Turnerba313e02011-02-09 16:01:53 +0100123if [ -n "$OPTION_CC" ]; then
124 echo "Using specified C compiler: $OPTION_CC"
125 CC="$OPTION_CC"
126fi
127
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700128if [ -z "$CC" ]; then
129 CC=$HOST_CC
130fi
131
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100132# By default, generate 32-bit binaries, the Makefile have targets that
133# generate 64-bit ones by using -m64 on the command-line.
134force_32bit_binaries
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800135
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200136case $OS in
137 linux-*)
138 TARGET_DLL_SUFFIX=.so
139 ;;
140 darwin-*)
141 TARGET_DLL_SUFFIX=.dylib
142 ;;
143 windows*)
144 TARGET_DLL_SUFFIX=.dll
145esac
146
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700147TARGET_OS=$OS
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100148
149setup_toolchain
150
151BUILD_AR=$AR
152BUILD_CC=$CC
153BUILD_CXX=$CC
154BUILD_LD=$LD
155BUILD_AR=$AR
156BUILD_CFLAGS=$CFLAGS
157BUILD_CXXFLAGS=$CXXFLAGS
158BUILD_LDFLAGS=$LDFLAGS
159
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200160if [ "$OPTION_MINGW" = "yes" ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700161 enable_linux_mingw
162 TARGET_OS=windows
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200163 TARGET_DLL_SUFFIX=.dll
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700164else
165 enable_cygwin
166fi
167
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200168# Are we running in the Android build system ?
169check_android_build
170
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800171
172# Adjust a few things when we're building within the Android build
173# system:
174# - locate prebuilt directory
175# - locate and use prebuilt libraries
176# - copy the new binary to the correct location
177#
178if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then
179 IN_ANDROID_BUILD=no
180fi
181
182if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200183 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800184
185 # use ccache if USE_CCACHE is defined and the corresponding
186 # binary is available.
187 #
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800188 if [ -n "$USE_CCACHE" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200189 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800190 if [ ! -f $CCACHE ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700191 CCACHE="$ANDROID_PREBUILTS/ccache/ccache$EXE"
192 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800193 fi
194
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800195 # finally ensure that our new binary is copied to the 'out'
196 # subdirectory as 'emulator'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200197 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200198 if [ "$TARGET_OS" = "windows" ]; then
199 HOST_BIN=$(echo $HOST_BIN | sed "s%$OS/bin%windows/bin%")
200 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800201 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200202 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
203 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800204 fi
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800205
206 # find the Android SDK Tools revision number
207 TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties
208 if [ -f $TOOLS_PROPS ] ; then
209 ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null`
210 log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION"
211 else
212 log "Tools : Could not locate $TOOLS_PROPS !?"
213 fi
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700214else
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100215 if [ "$USE_CCACHE" != 0 ]; then
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100216 CCACHE=$(which ccache 2>/dev/null)
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100217 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800218fi # IN_ANDROID_BUILD = no
219
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100220if [ -n "$CCACHE" -a -f "$CCACHE" ] ; then
221 CC="$CCACHE $CC"
222 log "Prebuilt : CCACHE=$CCACHE"
223else
224 log "Prebuilt : CCACHE can't be found"
225 CCACHE=
226fi
227
228# Try to find the GLES emulation headers and libraries automatically
229if [ "$GLES_PROBE" = "yes" ]; then
230 GLES_SUPPORT=yes
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100231 if [ -z "$GLES_DIR" ]; then
232 GLES_DIR=../../sdk/emulator/opengl
233 log2 "GLES : Probing source dir: $GLES_DIR"
234 if [ ! -d "$GLES_DIR" ]; then
235 GLES_DIR=../opengl
236 log2 "GLES : Probing source dir: $GLES_DIR"
237 if [ ! -d "$GLES_DIR" ]; then
238 GLES_DIR=
239 fi
240 fi
241 if [ -z "$GLES_DIR" ]; then
242 echo "GLES : Could not find GPU emulation sources!"
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100243 GLES_SUPPORT=no
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100244 else
245 echo "GLES : Found GPU emulation sources: $GLES_DIR"
246 GLES_SUPPORT=yes
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100247 fi
248 fi
249fi
250
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100251if [ "$PCBIOS_PROBE" = "yes" ]; then
252 PCBIOS_DIR=$(dirname "$0")/../../prebuilts/qemu-kernel/x86/pc-bios
253 if [ ! -d "$PCBIOS_DIR" ]; then
254 log2 "PC Bios : Probing $PCBIOS_DIR (missing)"
255 PCBIOS_DIR=../pc-bios
256 fi
257 log2 "PC Bios : Probing $PCBIOS_DIR"
258 if [ ! -d "$PCBIOS_DIR" ]; then
259 log "PC Bios : Could not find prebuilts directory."
260 else
261 mkdir -p objs/lib/pc-bios
262 for BIOS_FILE in bios.bin vgabios-cirrus.bin; do
263 log "PC Bios : Copying $BIOS_FILE"
264 cp -f $PCBIOS_DIR/$BIOS_FILE objs/lib/pc-bios/$BIOS_FILE
265 done
266 fi
267fi
268
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100269# For OS X, detect the location of the SDK to use.
270if [ "$HOST_OS" = darwin ]; then
271 OSX_VERSION=$(sw_vers -productVersion)
272 OSX_SDK_SUPPORTED="10.6 10.7 10.8"
273 OSX_SDK_INSTALLED_LIST=$(xcodebuild -showsdks 2>/dev/null | grep macosx | sed -e "s/.*macosx//g" | sort -n)
274 if [ -z "$OSX_SDK_INSTALLED_LIST" ]; then
275 echo "ERROR: Please install XCode on this machine!"
276 exit 1
277 fi
278 log "OSX: Installed SDKs: $OSX_SDK_INSTALLED_LIST"
279
280 OSX_SDK_VERSION=$(echo "$OSX_SDK_INSTALLED_LIST" | tr ' ' '\n' | head -1)
281 log "OSX: Using SDK version $OSX_SDK_VERSION"
282
283 XCODE_PATH=$(xcode-select -print-path 2>/dev/null)
284 log "OSX: XCode path: $XCODE_PATH"
285
286 OSX_SDK_ROOT=$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk
287 log "OSX: Looking for $OSX_SDK_ROOT"
288 if [ ! -d "$OSX_SDK_ROOT" ]; then
289 OSX_SDK_ROOT=/Developer/SDKs/MaxOSX${OSX_SDK_VERSION}.sdk
290 log "OSX: Looking for $OSX_SDK_ROOT"
291 if [ ! -d "$OSX_SDK_ROOT" ]; then
292 echo "ERROR: Could not find SDK $OSX_SDK_VERSION at $OSX_SDK_ROOT"
293 exit 1
294 fi
295 fi
296 echo "OSX SDK : Found at $OSX_SDK_ROOT"
297fi
298
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200299# we can build the emulator with Cygwin, so enable it
300enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800301
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200302setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800303
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800304###
305### SDL Probe
306###
307
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700308if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200309
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700310 # check that we can link statically with the library.
311 #
312 SDL_CFLAGS=`$SDL_CONFIG --cflags`
313 SDL_LIBS=`$SDL_CONFIG --static-libs`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800314
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700315 # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
Deepanshu Guptabb761912013-05-28 16:36:40 -0700316 # since they break recent Mingw releases
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700317 SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800318
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700319 log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
320 log "SDL-probe : SDL_LIBS = $SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800321
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800322
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700323 EXTRA_CFLAGS="$SDL_CFLAGS"
324 EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800325
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700326 case "$OS" in
327 freebsd-*)
328 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread"
329 ;;
330 esac
Alexey Tarasov08823222009-09-01 02:07:51 +1100331
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700332 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800333#include <SDL.h>
334#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200335int main( int argc, char** argv ) {
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200336 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800337}
338EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700339 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200340
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700341 if [ $SDL_LINKING != "yes" ] ; then
342 echo "You provided an explicit sdl-config script, but the corresponding library"
343 echo "cannot be statically linked with the Android emulator directly."
344 echo "Error message:"
345 cat $TMPL
346 clean_exit
347 fi
348 log "SDL-probe : static linking ok"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800349
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700350 # now, let's check that the SDL library has the special functions
351 # we added to our own sources
352 #
353 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800354#include <SDL.h>
355#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200356int main( int argc, char** argv ) {
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700357 int x, y;
358 SDL_Rect r;
359 SDL_WM_GetPos(&x, &y);
360 SDL_WM_SetPos(x, y);
361 SDL_WM_GetMonitorDPI(&x, &y);
362 SDL_WM_GetMonitorRect(&r);
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200363 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800364}
365EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700366 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200367
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700368 if [ $SDL_LINKING != "yes" ] ; then
369 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
370 echo "corresponding library doesn't have the patches required to link"
371 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
372 echo "sources bundled with the emulator instead"
373 echo "Error:"
374 cat $TMPL
375 clean_exit
376 fi
377
378 log "SDL-probe : extra features ok"
379 clean_temp
380
381 EXTRA_CFLAGS=
382 EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800383fi
384
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800385###
386### Audio subsystems probes
387###
388PROBE_COREAUDIO=no
389PROBE_ALSA=no
390PROBE_OSS=no
391PROBE_ESD=no
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700392PROBE_PULSEAUDIO=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800393PROBE_WINAUDIO=no
394
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700395case "$TARGET_OS" in
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800396 darwin*) PROBE_COREAUDIO=yes;
397 ;;
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700398 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800399 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100400 freebsd-*) PROBE_OSS=yes;
401 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800402 windows) PROBE_WINAUDIO=yes
403 ;;
404esac
405
406ORG_CFLAGS=$CFLAGS
407ORG_LDFLAGS=$LDFLAGS
408
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200409if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then
410PROBE_ESD_ESD=no
411PROBE_ALSA=no
412PROBE_PULSEAUDIO=no
413fi
414
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700415# Probe a system library
416#
417# $1: Variable name (e.g. PROBE_ESD)
418# $2: Library name (e.g. "Alsa")
419# $3: Path to source file for probe program (e.g. android/config/check-alsa.c)
420# $4: Package name (e.g. libasound-dev)
421#
422probe_system_library ()
423{
424 if [ `var_value $1` = yes ] ; then
425 CFLAGS="$ORG_CFLAGS"
426 LDFLAGS="$ORG_LDFLAGS -ldl"
427 cp -f android/config/check-esd.c $TMPC
David 'Digit' Turnera7ef1ac2010-12-10 22:33:51 +0100428 compile
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700429 if [ $? = 0 ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200430 log "AudioProbe : $2 seems to be usable on this system"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700431 else
432 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200433 echo "The $2 development files do not seem to be installed on this system"
434 echo "Are you missing the $4 package ?"
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100435 echo "You can ignore this error with --ignore-audio, otherwise correct"
436 echo "the issue(s) below and try again:"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700437 cat $TMPL
438 clean_exit
439 fi
440 eval $1=no
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200441 log "AudioProbe : $2 seems to be UNUSABLE on this system !!"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800442 fi
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100443 clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800444 fi
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700445}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800446
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700447probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev
448probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev
449probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800450
451CFLAGS=$ORG_CFLAGS
452LDFLAGS=$ORG_LDFLAGS
453
454# create the objs directory that is going to contain all generated files
455# including the configuration ones
456#
457mkdir -p objs
458
459###
460### Compiler probe
461###
462
463####
464#### Host system probe
465####
466
467# because the previous version could be read-only
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100468clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800469
470# check host endianess
471#
472HOST_BIGENDIAN=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700473if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800474cat > $TMPC << EOF
475#include <inttypes.h>
476int main(int argc, char ** argv){
477 volatile uint32_t i=0x01234567;
Marcus Comstedt17d31322010-10-05 21:54:12 +0200478 return (*((uint8_t*)(&i))) == 0x01;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800479}
480EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200481feature_run_exec HOST_BIGENDIAN
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700482fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800483
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800484# check whether we have <byteswap.h>
485#
David Turnerb8fec3e2010-09-09 18:15:23 +0200486feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
487feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
488feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
David Turner80dd1262010-09-09 18:04:49 +0200489
David 'Digit' Turner7891dd32014-04-28 10:59:47 +0200490# check for Mingw version.
491MINGW_VERSION=
492if [ "$TARGET_OS" = "windows" ]; then
493log "Mingw : Probing for GCC version."
494GCC_VERSION=$($CC -v 2>&1 | awk '$1 == "gcc" && $2 == "version" { print $3; }')
495GCC_MAJOR=$(echo "$GCC_VERSION" | cut -f1 -d.)
496GCC_MINOR=$(echo "$GCC_VERSION" | cut -f2 -d.)
497log "Mingw : Found GCC version $GCC_MAJOR.$GCC_MINOR [$GCC_VERSION]"
498MINGW_GCC_VERSION=$(( $GCC_MAJOR * 100 + $GCC_MINOR ))
499fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800500# Build the config.make file
501#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200502
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100503case $OS in
504 windows)
505 HOST_EXEEXT=.exe
506 HOST_DLLEXT=.dll
507 ;;
508 darwin)
509 HOST_EXEEXT=
510 HOST_DLLEXT=.dylib
511 ;;
512 *)
513 HOST_EXEEXT=
514 HOST_DLLEXT=
515 ;;
516esac
517
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200518case $TARGET_OS in
519 windows)
520 TARGET_EXEEXT=.exe
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100521 TARGET_DLLEXT=.dll
522 ;;
523 darwin)
524 TARGET_EXEXT=
525 TARGET_DLLEXT=.dylib
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200526 ;;
527 *)
528 TARGET_EXEEXT=
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100529 TARGET_DLLEXT=.so
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200530 ;;
531esac
532
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100533# Strip executables and shared libraries unless --debug is used.
David 'Digit' Turner3e3ff5a2014-03-14 11:20:10 +0100534if [ "$OPTION_DEBUG" != "yes" -a "$OPTION_NO_STRIP" != "yes" ]; then
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100535 case $HOST_OS in
536 darwin)
537 LDFLAGS="$LDFLAGS -Wl,-S"
538 ;;
539 *)
540 LDFLAGS="$LDFLAGS -Wl,--strip-all"
541 ;;
542 esac
543fi
544
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200545create_config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700546echo "" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700547echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200548echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100549echo "HOST_DLLEXT := $TARGET_DLLEXT" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700550echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700551echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200552
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100553echo "" >> $config_mk
554echo "BUILD_OS := $HOST_OS" >> $config_mk
555echo "BUILD_ARCH := $HOST_ARCH" >> $config_mk
556echo "BUILD_EXEEXT := $HOST_EXEEXT" >> $config_mk
557echo "BUILD_DLLEXT := $HOST_DLLEXT" >> $config_mk
558echo "BUILD_AR := $BUILD_AR" >> $config_mk
559echo "BUILD_CC := $BUILD_CC" >> $config_mk
560echo "BUILD_CXX := $BUILD_CXX" >> $config_mk
561echo "BUILD_LD := $BUILD_LD" >> $config_mk
562echo "BUILD_CFLAGS := $BUILD_CFLAGS" >> $config_mk
563echo "BUILD_LDFLAGS := $BUILD_LDFLAGS" >> $config_mk
564
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800565PWD=`pwd`
566echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700567if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200568echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700569fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800570echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
571echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
572echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
573echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
574echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700575echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800576echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200577if [ $OPTION_DEBUG = yes ] ; then
578 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
579fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800580if [ $OPTION_STATIC = yes ] ; then
581 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
582fi
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100583if [ "$GLES_SUPPORT" = "yes" ]; then
584 echo "EMULATOR_BUILD_EMUGL := true" >> $config_mk
585 echo "EMULATOR_EMUGL_SOURCES_DIR := $GLES_DIR" >> $config_mk
586fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800587
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800588if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
589 echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
590fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800591
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700592if [ "$OPTION_MINGW" = "yes" ] ; then
593 echo "" >> $config_mk
594 echo "USE_MINGW := 1" >> $config_mk
595 echo "HOST_OS := windows" >> $config_mk
David 'Digit' Turner7891dd32014-04-28 10:59:47 +0200596 echo "HOST_MINGW_VERSION := $MINGW_GCC_VERSION" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700597fi
598
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100599if [ "$HOST_OS" = "darwin" ]; then
600 echo "mac_sdk_root := $OSX_SDK_ROOT" >> $config_mk
601 echo "mac_sdk_version := $OSX_SDK_VERSION" >> $config_mk
602fi
603
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800604# Build the config-host.h file
605#
606config_h=objs/config-host.h
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100607cat > $config_h <<EOF
608/* This file was autogenerated by '$PROGNAME' */
609
610#define CONFIG_QEMU_SHAREDIR "/usr/local/share/qemu"
611
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100612EOF
613
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800614if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200615 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
616fi
617if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
618 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800619fi
David Turner80dd1262010-09-09 18:04:49 +0200620if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
621 echo "#define CONFIG_FNMATCH 1" >> $config_h
622fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800623echo "#define CONFIG_GDBSTUB 1" >> $config_h
624echo "#define CONFIG_SLIRP 1" >> $config_h
625echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200626echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700627
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200628case "$TARGET_OS" in
629 windows)
630 echo "#define CONFIG_WIN32 1" >> $config_h
631 ;;
632 *)
633 echo "#define CONFIG_POSIX 1" >> $config_h
634 ;;
635esac
636
637case "$TARGET_OS" in
638 linux-*)
639 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
640 ;;
641esac
642
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700643# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700644case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700645 linux-*)
646 echo "#define CONFIG_FDATASYNC 1" >> $config_h
647 ;;
648esac
649
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200650case "$TARGET_OS" in
651 linux-*|darwin-*)
652 echo "#define CONFIG_MADVISE 1" >> $config_h
653 ;;
654esac
655
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800656# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700657if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800658 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
659fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700660echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
661echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800662case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200663 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800664 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200665 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800666 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200667 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800668 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200669 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800670 ;;
671esac
Marcus Comstedt17d31322010-10-05 21:54:12 +0200672if [ "$HOST_BIGENDIAN" = "1" ] ; then
673 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
674fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200675BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700676case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200677 linux-*) CONFIG_OS=LINUX
678 ;;
679 darwin-*) CONFIG_OS=DARWIN
680 BSD=1
681 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100682 freebsd-*) CONFIG_OS=FREEBSD
683 BSD=1
684 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200685 windows*) CONFIG_OS=WIN32
686 ;;
687 *) CONFIG_OS=$OS
688esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700689
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800690if [ "$OPTION_STATIC" = "yes" ] ; then
691 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
692 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
693fi
694
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700695case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700696 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800697 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700698 ;;
699esac
700
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200701echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
702if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700703 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200704 echo "#define O_LARGEFILE 0" >> $config_h
705 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
706fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700707
David 'Digit' Turner494b1292014-02-05 15:02:04 +0100708case "$TARGET_OS" in
709 linux-*)
710 echo "#define CONFIG_SIGNALFD 1" >> $config_h
711 ;;
712esac
713
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700714echo "#define CONFIG_ANDROID 1" >> $config_h
715
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800716log "Generate : $config_h"
717
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100718# Generate the QAPI headers and sources from qapi-schema.json
719# Ideally, this would be done in our Makefiles, but as far as I
720# understand, the platform build doesn't support a single tool
721# that generates several sources files, nor the standalone one.
722export PYTHONDONTWRITEBYTECODE=1
723AUTOGENERATED_DIR=qapi-auto-generated
724python scripts/qapi-types.py qapi.types --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
725python scripts/qapi-visit.py --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
726python scripts/qapi-commands.py --output-dir=$AUTOGENERATED_DIR -m < qapi-schema.json
727log "Generate : $AUTOGENERATED_DIR"
728
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100729clean_temp
730
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800731echo "Ready to go. Type 'make' to build emulator"