blob: 42fe51d8a6cd9b76adc492c5622776114f476d22 [file] [log] [blame]
David 'Digit' Turner46be4872009-06-04 16:07:01 +02001#!/bin/sh
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08002#
3# this script is used to rebuild the Android emulator from sources
4# in the current directory. It also contains logic to speed up the
5# rebuild if it detects that you're using the Android build system
6#
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08007# here's the list of environment variables you can define before
8# calling this script to control it (besides options):
9#
10#
11
12# first, let's see which system we're running this on
13cd `dirname $0`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080014
David 'Digit' Turner46be4872009-06-04 16:07:01 +020015# source common functions definitions
16. android/build/common.sh
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080017
18# Parse options
19OPTION_TARGETS=""
20OPTION_DEBUG=no
21OPTION_IGNORE_AUDIO=no
22OPTION_NO_PREBUILTS=no
David 'Digit' Turnera96cc262014-05-12 21:28:34 +020023OPTION_OUT_DIR=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080024OPTION_HELP=no
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080025OPTION_STATIC=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070026OPTION_MINGW=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080027
David 'Digit' Turner1af82152014-03-03 20:41:37 +010028GLES_DIR=
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +020029GLES_SUPPORT=no
30GLES_PROBE=yes
31
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +010032PCBIOS_PROBE=yes
33
David 'Digit' Turnere3650682010-12-22 14:44:19 +010034HOST_CC=${CC:-gcc}
35OPTION_CC=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080036
37for opt do
38 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
39 case "$opt" in
40 --help|-h|-\?) OPTION_HELP=yes
41 ;;
42 --verbose)
43 if [ "$VERBOSE" = "yes" ] ; then
44 VERBOSE2=yes
45 else
46 VERBOSE=yes
47 fi
48 ;;
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +020049 --debug) OPTION_DEBUG=yes
50 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +020051 --install=*) OPTION_TARGETS="$OPTION_TARGETS $optarg";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080052 ;;
53 --sdl-config=*) SDL_CONFIG=$optarg
54 ;;
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070055 --mingw) OPTION_MINGW=yes
56 ;;
David 'Digit' Turnere3650682010-12-22 14:44:19 +010057 --cc=*) OPTION_CC="$optarg"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080058 ;;
59 --no-strip) OPTION_NO_STRIP=yes
60 ;;
David 'Digit' Turnera96cc262014-05-12 21:28:34 +020061 --out-dir=*) OPTION_OUT_DIR=$optarg
62 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080063 --ignore-audio) OPTION_IGNORE_AUDIO=yes
64 ;;
65 --no-prebuilts) OPTION_NO_PREBUILTS=yes
66 ;;
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080067 --static) OPTION_STATIC=yes
68 ;;
David 'Digit' Turner1af82152014-03-03 20:41:37 +010069 --gles-dir=*) GLES_DIR=$optarg
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +020070 ;;
71 --no-gles) GLES_PROBE=no
72 ;;
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +010073 --no-pcbios) PCBIOS_PROBE=no
74 ;;
David 'Digit' Turner9f86acc2014-05-13 11:22:12 +020075 --no-tests)
76 # Ignore this option, only used by android-rebuild.sh
77 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080078 *)
79 echo "unknown option '$opt', use --help"
80 exit 1
81 esac
82done
83
84# Print the help message
85#
86if [ "$OPTION_HELP" = "yes" ] ; then
87 cat << EOF
88
89Usage: rebuild.sh [options]
90Options: [defaults in brackets after descriptions]
91EOF
92 echo "Standard options:"
93 echo " --help print this message"
94 echo " --install=FILEPATH copy emulator executable to FILEPATH [$TARGETS]"
David 'Digit' Turnere3650682010-12-22 14:44:19 +010095 echo " --cc=PATH specify C compiler [$HOST_CC]"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080096 echo " --sdl-config=FILE use specific sdl-config script [$SDL_CONFIG]"
97 echo " --no-strip do not strip emulator executable"
98 echo " --debug enable debug (-O0 -g) build"
99 echo " --ignore-audio ignore audio messages (may build sound-less emulator)"
100 echo " --no-prebuilts do not use prebuilt libraries and compiler"
David 'Digit' Turnera96cc262014-05-12 21:28:34 +0200101 echo " --out-dir=<path> use specific output directory [objs/]"
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700102 echo " --mingw build Windows executable on Linux"
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800103 echo " --static build a completely static executable"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800104 echo " --verbose verbose configuration"
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200105 echo " --debug build debug version of the emulator"
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100106 echo " --gles-dir=PATH specify path to GLES host emulation sources [auto-detected]"
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200107 echo " --no-gles disable GLES emulation support"
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100108 echo " --no-pcbios disable copying of PC Bios files"
David 'Digit' Turner9f86acc2014-05-13 11:22:12 +0200109 echo " --no-tests don't run unit test suite"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800110 echo ""
111 exit 1
112fi
113
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700114# On Linux, try to use our prebuilt toolchain to generate binaries
David 'Digit' Turner52ffef32014-04-28 11:20:47 +0200115# that are compatible with Ubuntu 10.4
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700116if [ -z "$CC" -a -z "$OPTION_CC" -a "$HOST_OS" = linux ] ; then
David 'Digit' Turner52ffef32014-04-28 11:20:47 +0200117 PREBUILTS_HOST_GCC=$(dirname $0)/../../prebuilts/gcc/linux-x86/host
David 'Digit' Turner295ef3d2014-04-30 11:02:03 +0200118 # NOTE: GCC 4.8 is currently disabled because this breaks MIPS emulation
119 # For some odd reason. Remove the 'DISABLED_' prefix below to re-enable it,
120 # e.g. once the MIPS backend has been updated to a more recent version.
121 # This only affects Linux emulator binaries.
122 PROBE_HOST_CC=$PREBUILTS_HOST_GCC/DISABLED_x86_64-linux-glibc2.11-4.8/bin/x86_64-linux-gcc
David 'Digit' Turner52ffef32014-04-28 11:20:47 +0200123 if [ ! -f "$PROBE_HOST_CC" ]; then
124 PROBE_HOST_CC=$PREBUILTS_HOST_GCC/x86_64-linux-glibc2.11-4.6/bin/x86_64-linux-gcc
125 if [ ! -f "$PROBE_HOST_CC" ] ; then
126 PROBE_HOST_CC=$(dirname $0)/../../prebuilts/tools/gcc-sdk/gcc
127 fi
Andrew Hsieh7db680c2014-03-13 04:18:13 -0700128 fi
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100129 if [ -f "$PROBE_HOST_CC" ] ; then
130 echo "Using prebuilt toolchain: $PROBE_HOST_CC"
131 CC="$PROBE_HOST_CC"
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100132 fi
133fi
134
David 'Digit' Turnerba313e02011-02-09 16:01:53 +0100135if [ -n "$OPTION_CC" ]; then
136 echo "Using specified C compiler: $OPTION_CC"
137 CC="$OPTION_CC"
138fi
139
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700140if [ -z "$CC" ]; then
141 CC=$HOST_CC
142fi
143
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100144# By default, generate 32-bit binaries, the Makefile have targets that
145# generate 64-bit ones by using -m64 on the command-line.
146force_32bit_binaries
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800147
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200148case $OS in
149 linux-*)
150 TARGET_DLL_SUFFIX=.so
151 ;;
152 darwin-*)
153 TARGET_DLL_SUFFIX=.dylib
154 ;;
155 windows*)
156 TARGET_DLL_SUFFIX=.dll
157esac
158
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700159TARGET_OS=$OS
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100160
161setup_toolchain
162
163BUILD_AR=$AR
164BUILD_CC=$CC
165BUILD_CXX=$CC
166BUILD_LD=$LD
167BUILD_AR=$AR
168BUILD_CFLAGS=$CFLAGS
169BUILD_CXXFLAGS=$CXXFLAGS
170BUILD_LDFLAGS=$LDFLAGS
171
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200172if [ "$OPTION_MINGW" = "yes" ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700173 enable_linux_mingw
174 TARGET_OS=windows
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200175 TARGET_DLL_SUFFIX=.dll
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700176else
177 enable_cygwin
178fi
179
David 'Digit' Turnera96cc262014-05-12 21:28:34 +0200180if [ "$OPTION_OUT_DIR" ]; then
181 OUT_DIR="$OPTION_OUT_DIR"
182 mkdir -p "$OUT_DIR" || panic "Could not create output directory: $OUT_DIR"
183else
184 OUT_DIR=objs
185 log "Auto-config: --out-dir=objs"
186fi
187
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200188# Are we running in the Android build system ?
189check_android_build
190
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800191
192# Adjust a few things when we're building within the Android build
193# system:
194# - locate prebuilt directory
195# - locate and use prebuilt libraries
196# - copy the new binary to the correct location
197#
198if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then
199 IN_ANDROID_BUILD=no
200fi
201
202if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200203 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800204
205 # use ccache if USE_CCACHE is defined and the corresponding
206 # binary is available.
207 #
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800208 if [ -n "$USE_CCACHE" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200209 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800210 if [ ! -f $CCACHE ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700211 CCACHE="$ANDROID_PREBUILTS/ccache/ccache$EXE"
212 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800213 fi
214
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800215 # finally ensure that our new binary is copied to the 'out'
216 # subdirectory as 'emulator'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200217 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200218 if [ "$TARGET_OS" = "windows" ]; then
219 HOST_BIN=$(echo $HOST_BIN | sed "s%$OS/bin%windows/bin%")
220 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800221 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200222 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
223 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800224 fi
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800225
226 # find the Android SDK Tools revision number
227 TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties
228 if [ -f $TOOLS_PROPS ] ; then
229 ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null`
230 log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION"
231 else
232 log "Tools : Could not locate $TOOLS_PROPS !?"
233 fi
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700234else
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100235 if [ "$USE_CCACHE" != 0 ]; then
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100236 CCACHE=$(which ccache 2>/dev/null)
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100237 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800238fi # IN_ANDROID_BUILD = no
239
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100240if [ -n "$CCACHE" -a -f "$CCACHE" ] ; then
241 CC="$CCACHE $CC"
242 log "Prebuilt : CCACHE=$CCACHE"
243else
244 log "Prebuilt : CCACHE can't be found"
245 CCACHE=
246fi
247
248# Try to find the GLES emulation headers and libraries automatically
249if [ "$GLES_PROBE" = "yes" ]; then
250 GLES_SUPPORT=yes
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100251 if [ -z "$GLES_DIR" ]; then
252 GLES_DIR=../../sdk/emulator/opengl
253 log2 "GLES : Probing source dir: $GLES_DIR"
254 if [ ! -d "$GLES_DIR" ]; then
255 GLES_DIR=../opengl
256 log2 "GLES : Probing source dir: $GLES_DIR"
257 if [ ! -d "$GLES_DIR" ]; then
258 GLES_DIR=
259 fi
260 fi
261 if [ -z "$GLES_DIR" ]; then
262 echo "GLES : Could not find GPU emulation sources!"
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100263 GLES_SUPPORT=no
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100264 else
265 echo "GLES : Found GPU emulation sources: $GLES_DIR"
266 GLES_SUPPORT=yes
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100267 fi
268 fi
269fi
270
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100271if [ "$PCBIOS_PROBE" = "yes" ]; then
272 PCBIOS_DIR=$(dirname "$0")/../../prebuilts/qemu-kernel/x86/pc-bios
273 if [ ! -d "$PCBIOS_DIR" ]; then
274 log2 "PC Bios : Probing $PCBIOS_DIR (missing)"
275 PCBIOS_DIR=../pc-bios
276 fi
277 log2 "PC Bios : Probing $PCBIOS_DIR"
278 if [ ! -d "$PCBIOS_DIR" ]; then
279 log "PC Bios : Could not find prebuilts directory."
280 else
David 'Digit' Turnera96cc262014-05-12 21:28:34 +0200281 mkdir -p $OUT_DIR/lib/pc-bios
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100282 for BIOS_FILE in bios.bin vgabios-cirrus.bin; do
283 log "PC Bios : Copying $BIOS_FILE"
David 'Digit' Turnera96cc262014-05-12 21:28:34 +0200284 cp -f $PCBIOS_DIR/$BIOS_FILE $OUT_DIR/lib/pc-bios/$BIOS_FILE
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100285 done
286 fi
287fi
288
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100289# For OS X, detect the location of the SDK to use.
290if [ "$HOST_OS" = darwin ]; then
291 OSX_VERSION=$(sw_vers -productVersion)
292 OSX_SDK_SUPPORTED="10.6 10.7 10.8"
293 OSX_SDK_INSTALLED_LIST=$(xcodebuild -showsdks 2>/dev/null | grep macosx | sed -e "s/.*macosx//g" | sort -n)
294 if [ -z "$OSX_SDK_INSTALLED_LIST" ]; then
295 echo "ERROR: Please install XCode on this machine!"
296 exit 1
297 fi
298 log "OSX: Installed SDKs: $OSX_SDK_INSTALLED_LIST"
299
300 OSX_SDK_VERSION=$(echo "$OSX_SDK_INSTALLED_LIST" | tr ' ' '\n' | head -1)
301 log "OSX: Using SDK version $OSX_SDK_VERSION"
302
303 XCODE_PATH=$(xcode-select -print-path 2>/dev/null)
304 log "OSX: XCode path: $XCODE_PATH"
305
306 OSX_SDK_ROOT=$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk
307 log "OSX: Looking for $OSX_SDK_ROOT"
308 if [ ! -d "$OSX_SDK_ROOT" ]; then
309 OSX_SDK_ROOT=/Developer/SDKs/MaxOSX${OSX_SDK_VERSION}.sdk
310 log "OSX: Looking for $OSX_SDK_ROOT"
311 if [ ! -d "$OSX_SDK_ROOT" ]; then
312 echo "ERROR: Could not find SDK $OSX_SDK_VERSION at $OSX_SDK_ROOT"
313 exit 1
314 fi
315 fi
316 echo "OSX SDK : Found at $OSX_SDK_ROOT"
317fi
318
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200319# we can build the emulator with Cygwin, so enable it
320enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800321
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200322setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800323
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800324###
325### SDL Probe
326###
327
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700328if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200329
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700330 # check that we can link statically with the library.
331 #
332 SDL_CFLAGS=`$SDL_CONFIG --cflags`
333 SDL_LIBS=`$SDL_CONFIG --static-libs`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800334
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700335 # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
Deepanshu Guptabb761912013-05-28 16:36:40 -0700336 # since they break recent Mingw releases
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700337 SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800338
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700339 log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
340 log "SDL-probe : SDL_LIBS = $SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800341
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800342
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700343 EXTRA_CFLAGS="$SDL_CFLAGS"
344 EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800345
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700346 case "$OS" in
347 freebsd-*)
348 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread"
349 ;;
350 esac
Alexey Tarasov08823222009-09-01 02:07:51 +1100351
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700352 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800353#include <SDL.h>
354#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200355int main( int argc, char** argv ) {
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200356 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800357}
358EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700359 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200360
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700361 if [ $SDL_LINKING != "yes" ] ; then
362 echo "You provided an explicit sdl-config script, but the corresponding library"
363 echo "cannot be statically linked with the Android emulator directly."
364 echo "Error message:"
365 cat $TMPL
366 clean_exit
367 fi
368 log "SDL-probe : static linking ok"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800369
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700370 # now, let's check that the SDL library has the special functions
371 # we added to our own sources
372 #
373 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800374#include <SDL.h>
375#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200376int main( int argc, char** argv ) {
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700377 int x, y;
378 SDL_Rect r;
379 SDL_WM_GetPos(&x, &y);
380 SDL_WM_SetPos(x, y);
381 SDL_WM_GetMonitorDPI(&x, &y);
382 SDL_WM_GetMonitorRect(&r);
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200383 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800384}
385EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700386 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200387
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700388 if [ $SDL_LINKING != "yes" ] ; then
389 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
390 echo "corresponding library doesn't have the patches required to link"
391 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
392 echo "sources bundled with the emulator instead"
393 echo "Error:"
394 cat $TMPL
395 clean_exit
396 fi
397
398 log "SDL-probe : extra features ok"
399 clean_temp
400
401 EXTRA_CFLAGS=
402 EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800403fi
404
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800405###
406### Audio subsystems probes
407###
408PROBE_COREAUDIO=no
409PROBE_ALSA=no
410PROBE_OSS=no
411PROBE_ESD=no
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700412PROBE_PULSEAUDIO=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800413PROBE_WINAUDIO=no
414
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700415case "$TARGET_OS" in
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800416 darwin*) PROBE_COREAUDIO=yes;
417 ;;
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700418 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800419 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100420 freebsd-*) PROBE_OSS=yes;
421 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800422 windows) PROBE_WINAUDIO=yes
423 ;;
424esac
425
426ORG_CFLAGS=$CFLAGS
427ORG_LDFLAGS=$LDFLAGS
428
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200429if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then
430PROBE_ESD_ESD=no
431PROBE_ALSA=no
432PROBE_PULSEAUDIO=no
433fi
434
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700435# Probe a system library
436#
437# $1: Variable name (e.g. PROBE_ESD)
438# $2: Library name (e.g. "Alsa")
439# $3: Path to source file for probe program (e.g. android/config/check-alsa.c)
440# $4: Package name (e.g. libasound-dev)
441#
442probe_system_library ()
443{
444 if [ `var_value $1` = yes ] ; then
445 CFLAGS="$ORG_CFLAGS"
446 LDFLAGS="$ORG_LDFLAGS -ldl"
447 cp -f android/config/check-esd.c $TMPC
David 'Digit' Turnera7ef1ac2010-12-10 22:33:51 +0100448 compile
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700449 if [ $? = 0 ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200450 log "AudioProbe : $2 seems to be usable on this system"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700451 else
452 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200453 echo "The $2 development files do not seem to be installed on this system"
454 echo "Are you missing the $4 package ?"
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100455 echo "You can ignore this error with --ignore-audio, otherwise correct"
456 echo "the issue(s) below and try again:"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700457 cat $TMPL
458 clean_exit
459 fi
460 eval $1=no
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200461 log "AudioProbe : $2 seems to be UNUSABLE on this system !!"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800462 fi
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100463 clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800464 fi
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700465}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800466
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700467probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev
468probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev
469probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800470
471CFLAGS=$ORG_CFLAGS
472LDFLAGS=$ORG_LDFLAGS
473
474# create the objs directory that is going to contain all generated files
475# including the configuration ones
476#
David 'Digit' Turnera96cc262014-05-12 21:28:34 +0200477mkdir -p $OUT_DIR
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800478
479###
480### Compiler probe
481###
482
483####
484#### Host system probe
485####
486
487# because the previous version could be read-only
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100488clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800489
490# check host endianess
491#
492HOST_BIGENDIAN=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700493if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800494cat > $TMPC << EOF
495#include <inttypes.h>
496int main(int argc, char ** argv){
497 volatile uint32_t i=0x01234567;
Marcus Comstedt17d31322010-10-05 21:54:12 +0200498 return (*((uint8_t*)(&i))) == 0x01;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800499}
500EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200501feature_run_exec HOST_BIGENDIAN
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700502fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800503
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800504# check whether we have <byteswap.h>
505#
David Turnerb8fec3e2010-09-09 18:15:23 +0200506feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
507feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
508feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
David Turner80dd1262010-09-09 18:04:49 +0200509
David 'Digit' Turner7891dd32014-04-28 10:59:47 +0200510# check for Mingw version.
511MINGW_VERSION=
512if [ "$TARGET_OS" = "windows" ]; then
513log "Mingw : Probing for GCC version."
514GCC_VERSION=$($CC -v 2>&1 | awk '$1 == "gcc" && $2 == "version" { print $3; }')
515GCC_MAJOR=$(echo "$GCC_VERSION" | cut -f1 -d.)
516GCC_MINOR=$(echo "$GCC_VERSION" | cut -f2 -d.)
517log "Mingw : Found GCC version $GCC_MAJOR.$GCC_MINOR [$GCC_VERSION]"
518MINGW_GCC_VERSION=$(( $GCC_MAJOR * 100 + $GCC_MINOR ))
519fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800520# Build the config.make file
521#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200522
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100523case $OS in
524 windows)
525 HOST_EXEEXT=.exe
526 HOST_DLLEXT=.dll
527 ;;
528 darwin)
529 HOST_EXEEXT=
530 HOST_DLLEXT=.dylib
531 ;;
532 *)
533 HOST_EXEEXT=
534 HOST_DLLEXT=
535 ;;
536esac
537
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200538case $TARGET_OS in
539 windows)
540 TARGET_EXEEXT=.exe
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100541 TARGET_DLLEXT=.dll
542 ;;
543 darwin)
544 TARGET_EXEXT=
545 TARGET_DLLEXT=.dylib
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200546 ;;
547 *)
548 TARGET_EXEEXT=
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100549 TARGET_DLLEXT=.so
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200550 ;;
551esac
552
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100553# Strip executables and shared libraries unless --debug is used.
David 'Digit' Turner3e3ff5a2014-03-14 11:20:10 +0100554if [ "$OPTION_DEBUG" != "yes" -a "$OPTION_NO_STRIP" != "yes" ]; then
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100555 case $HOST_OS in
556 darwin)
557 LDFLAGS="$LDFLAGS -Wl,-S"
558 ;;
559 *)
560 LDFLAGS="$LDFLAGS -Wl,--strip-all"
561 ;;
562 esac
563fi
564
David 'Digit' Turnera96cc262014-05-12 21:28:34 +0200565create_config_mk "$OUT_DIR"
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700566echo "" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700567echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200568echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100569echo "HOST_DLLEXT := $TARGET_DLLEXT" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700570echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700571echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200572
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100573echo "" >> $config_mk
574echo "BUILD_OS := $HOST_OS" >> $config_mk
575echo "BUILD_ARCH := $HOST_ARCH" >> $config_mk
576echo "BUILD_EXEEXT := $HOST_EXEEXT" >> $config_mk
577echo "BUILD_DLLEXT := $HOST_DLLEXT" >> $config_mk
578echo "BUILD_AR := $BUILD_AR" >> $config_mk
579echo "BUILD_CC := $BUILD_CC" >> $config_mk
580echo "BUILD_CXX := $BUILD_CXX" >> $config_mk
581echo "BUILD_LD := $BUILD_LD" >> $config_mk
582echo "BUILD_CFLAGS := $BUILD_CFLAGS" >> $config_mk
583echo "BUILD_LDFLAGS := $BUILD_LDFLAGS" >> $config_mk
584
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800585PWD=`pwd`
586echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700587if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200588echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700589fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800590echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
591echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
592echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
593echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
594echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700595echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800596echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200597if [ $OPTION_DEBUG = yes ] ; then
598 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
599fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800600if [ $OPTION_STATIC = yes ] ; then
601 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
602fi
David 'Digit' Turner1af82152014-03-03 20:41:37 +0100603if [ "$GLES_SUPPORT" = "yes" ]; then
604 echo "EMULATOR_BUILD_EMUGL := true" >> $config_mk
605 echo "EMULATOR_EMUGL_SOURCES_DIR := $GLES_DIR" >> $config_mk
606fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800607
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800608if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
609 echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
610fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800611
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700612if [ "$OPTION_MINGW" = "yes" ] ; then
613 echo "" >> $config_mk
614 echo "USE_MINGW := 1" >> $config_mk
615 echo "HOST_OS := windows" >> $config_mk
David 'Digit' Turner7891dd32014-04-28 10:59:47 +0200616 echo "HOST_MINGW_VERSION := $MINGW_GCC_VERSION" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700617fi
618
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100619if [ "$HOST_OS" = "darwin" ]; then
620 echo "mac_sdk_root := $OSX_SDK_ROOT" >> $config_mk
621 echo "mac_sdk_version := $OSX_SDK_VERSION" >> $config_mk
622fi
623
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800624# Build the config-host.h file
625#
David 'Digit' Turnera96cc262014-05-12 21:28:34 +0200626config_h=$OUT_DIR/config-host.h
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100627cat > $config_h <<EOF
628/* This file was autogenerated by '$PROGNAME' */
629
630#define CONFIG_QEMU_SHAREDIR "/usr/local/share/qemu"
631
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100632EOF
633
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800634if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200635 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
636fi
637if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
638 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800639fi
David Turner80dd1262010-09-09 18:04:49 +0200640if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
641 echo "#define CONFIG_FNMATCH 1" >> $config_h
642fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800643echo "#define CONFIG_GDBSTUB 1" >> $config_h
644echo "#define CONFIG_SLIRP 1" >> $config_h
645echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200646echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700647
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200648case "$TARGET_OS" in
649 windows)
650 echo "#define CONFIG_WIN32 1" >> $config_h
651 ;;
652 *)
653 echo "#define CONFIG_POSIX 1" >> $config_h
654 ;;
655esac
656
657case "$TARGET_OS" in
658 linux-*)
659 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
660 ;;
661esac
662
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700663# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700664case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700665 linux-*)
666 echo "#define CONFIG_FDATASYNC 1" >> $config_h
667 ;;
668esac
669
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200670case "$TARGET_OS" in
671 linux-*|darwin-*)
672 echo "#define CONFIG_MADVISE 1" >> $config_h
673 ;;
674esac
675
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800676# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700677if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800678 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
679fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700680echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
681echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800682case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200683 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800684 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200685 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800686 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200687 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800688 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200689 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800690 ;;
691esac
Marcus Comstedt17d31322010-10-05 21:54:12 +0200692if [ "$HOST_BIGENDIAN" = "1" ] ; then
693 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
694fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200695BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700696case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200697 linux-*) CONFIG_OS=LINUX
698 ;;
699 darwin-*) CONFIG_OS=DARWIN
700 BSD=1
701 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100702 freebsd-*) CONFIG_OS=FREEBSD
703 BSD=1
704 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200705 windows*) CONFIG_OS=WIN32
706 ;;
707 *) CONFIG_OS=$OS
708esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700709
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800710if [ "$OPTION_STATIC" = "yes" ] ; then
711 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
712 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
713fi
714
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700715case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700716 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800717 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700718 ;;
719esac
720
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200721echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
722if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700723 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200724 echo "#define O_LARGEFILE 0" >> $config_h
725 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
726fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700727
David 'Digit' Turner494b1292014-02-05 15:02:04 +0100728case "$TARGET_OS" in
729 linux-*)
730 echo "#define CONFIG_SIGNALFD 1" >> $config_h
731 ;;
732esac
733
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700734echo "#define CONFIG_ANDROID 1" >> $config_h
735
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800736log "Generate : $config_h"
737
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100738# Generate the QAPI headers and sources from qapi-schema.json
739# Ideally, this would be done in our Makefiles, but as far as I
740# understand, the platform build doesn't support a single tool
741# that generates several sources files, nor the standalone one.
742export PYTHONDONTWRITEBYTECODE=1
743AUTOGENERATED_DIR=qapi-auto-generated
744python scripts/qapi-types.py qapi.types --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
745python scripts/qapi-visit.py --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
746python scripts/qapi-commands.py --output-dir=$AUTOGENERATED_DIR -m < qapi-schema.json
747log "Generate : $AUTOGENERATED_DIR"
748
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100749clean_temp
750
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800751echo "Ready to go. Type 'make' to build emulator"