blob: 8abfd521875493a654f55e02a7387f45ef860da8 [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' Turner0c8c8852011-08-24 13:26:58 +020027GLES_LIBS=
28GLES_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' Turner0c8c8852011-08-24 13:26:58 +020066 --gles-libs=*) GLES_LIBS=$optarg
67 GLES_SUPPORT=yes
68 ;;
69 --no-gles) GLES_PROBE=no
70 ;;
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +010071 --no-pcbios) PCBIOS_PROBE=no
72 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080073 *)
74 echo "unknown option '$opt', use --help"
75 exit 1
76 esac
77done
78
79# Print the help message
80#
81if [ "$OPTION_HELP" = "yes" ] ; then
82 cat << EOF
83
84Usage: rebuild.sh [options]
85Options: [defaults in brackets after descriptions]
86EOF
87 echo "Standard options:"
88 echo " --help print this message"
89 echo " --install=FILEPATH copy emulator executable to FILEPATH [$TARGETS]"
David 'Digit' Turnere3650682010-12-22 14:44:19 +010090 echo " --cc=PATH specify C compiler [$HOST_CC]"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080091 echo " --sdl-config=FILE use specific sdl-config script [$SDL_CONFIG]"
92 echo " --no-strip do not strip emulator executable"
93 echo " --debug enable debug (-O0 -g) build"
94 echo " --ignore-audio ignore audio messages (may build sound-less emulator)"
95 echo " --no-prebuilts do not use prebuilt libraries and compiler"
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070096 echo " --mingw build Windows executable on Linux"
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080097 echo " --static build a completely static executable"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080098 echo " --verbose verbose configuration"
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +020099 echo " --debug build debug version of the emulator"
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200100 echo " --gles-libs=PATH specify path to GLES emulation host libraries"
101 echo " --no-gles disable GLES emulation support"
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100102 echo " --no-pcbios disable copying of PC Bios files"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800103 echo ""
104 exit 1
105fi
106
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700107# On Linux, try to use our prebuilt toolchain to generate binaries
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100108# that are compatible with Ubuntu 8.04
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700109if [ -z "$CC" -a -z "$OPTION_CC" -a "$HOST_OS" = linux ] ; then
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100110 PROBE_HOST_CC=`dirname $0`/../../prebuilts/tools/gcc-sdk/gcc
111 if [ -f "$PROBE_HOST_CC" ] ; then
112 echo "Using prebuilt toolchain: $PROBE_HOST_CC"
113 CC="$PROBE_HOST_CC"
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100114 fi
115fi
116
David 'Digit' Turnerba313e02011-02-09 16:01:53 +0100117if [ -n "$OPTION_CC" ]; then
118 echo "Using specified C compiler: $OPTION_CC"
119 CC="$OPTION_CC"
120fi
121
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700122if [ -z "$CC" ]; then
123 CC=$HOST_CC
124fi
125
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100126# By default, generate 32-bit binaries, the Makefile have targets that
127# generate 64-bit ones by using -m64 on the command-line.
128force_32bit_binaries
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800129
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200130case $OS in
131 linux-*)
132 TARGET_DLL_SUFFIX=.so
133 ;;
134 darwin-*)
135 TARGET_DLL_SUFFIX=.dylib
136 ;;
137 windows*)
138 TARGET_DLL_SUFFIX=.dll
139esac
140
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700141TARGET_OS=$OS
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200142if [ "$OPTION_MINGW" = "yes" ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700143 enable_linux_mingw
144 TARGET_OS=windows
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200145 TARGET_DLL_SUFFIX=.dll
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700146else
147 enable_cygwin
148fi
149
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200150# Are we running in the Android build system ?
151check_android_build
152
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800153
154# Adjust a few things when we're building within the Android build
155# system:
156# - locate prebuilt directory
157# - locate and use prebuilt libraries
158# - copy the new binary to the correct location
159#
160if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then
161 IN_ANDROID_BUILD=no
162fi
163
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200164# This is the list of static and shared host libraries we need to link
165# against in order to support OpenGLES emulation properly. Note that in
166# the case of a standalone build, we will find these libraries inside the
167# platform build tree and copy them into objs/lib/ automatically, unless
168# you use --gles-libs to point explicitely to a different directory.
169#
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100170GLES_SHARED_LIBRARIES="\
171 libOpenglRender \
172 libGLES_CM_translator \
173 libGLES_V2_translator \
174 libEGL_translator"
175
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100176if [ "$OPTION_MINGW" != "yes" ]; then
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100177 # There are no 64-bit libraries for Windows yet!
178 GLES_SHARED_LIBRARIES="$GLES_SHARED_LIBRARIES \
179 lib64OpenglRender \
180 lib64GLES_CM_translator \
181 lib64GLES_V2_translator \
182 lib64EGL_translator"
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700183fi
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200184
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800185if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200186 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800187
188 # use ccache if USE_CCACHE is defined and the corresponding
189 # binary is available.
190 #
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800191 if [ -n "$USE_CCACHE" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200192 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800193 if [ ! -f $CCACHE ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700194 CCACHE="$ANDROID_PREBUILTS/ccache/ccache$EXE"
195 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800196 fi
197
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800198 # finally ensure that our new binary is copied to the 'out'
199 # subdirectory as 'emulator'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200200 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200201 if [ "$TARGET_OS" = "windows" ]; then
202 HOST_BIN=$(echo $HOST_BIN | sed "s%$OS/bin%windows/bin%")
203 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800204 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200205 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
206 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800207 fi
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800208
209 # find the Android SDK Tools revision number
210 TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties
211 if [ -f $TOOLS_PROPS ] ; then
212 ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null`
213 log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION"
214 else
215 log "Tools : Could not locate $TOOLS_PROPS !?"
216 fi
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200217
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100218 GLES_PROBE_LIB_DIR=$(dirname "$HOST_BIN")/lib
219 case $GLES_PROBE_LIB_DIR in
220 */windows/lib)
221 GLES_PROBE_LIB_DIR=${GLES_PROBE_LIB_DIR%%/windows/lib}/windows-x86/lib
222 ;;
223 esac
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700224else
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100225 if [ "$USE_CCACHE" != 0 ]; then
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100226 CCACHE=$(which ccache 2>/dev/null)
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100227 fi
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100228 GLES_PROBE_OS=$TARGET_OS
229 if [ "$GLES_PROBE_OS" = "windows" ]; then
230 GLES_PROBE_OS=windows-x86
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700231 fi
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100232 GLES_PROBE_LIB_DIR=../../out/host/$GLES_PROBE_OS/lib
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800233fi # IN_ANDROID_BUILD = no
234
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100235if [ -n "$CCACHE" -a -f "$CCACHE" ] ; then
236 CC="$CCACHE $CC"
237 log "Prebuilt : CCACHE=$CCACHE"
238else
239 log "Prebuilt : CCACHE can't be found"
240 CCACHE=
241fi
242
243# Try to find the GLES emulation headers and libraries automatically
244if [ "$GLES_PROBE" = "yes" ]; then
245 GLES_SUPPORT=yes
246 if [ -z "$GLES_LIBS" ]; then
247 log "GLES : Probing for host libraries"
248 GLES_LIBS=$GLES_PROBE_LIB_DIR
249 if [ -d "$GLES_LIBS" ]; then
250 echo "GLES : Libs in $GLES_LIBS"
251 else
252 echo "Warning: Could nof find OpenGLES emulation libraries in: $GLES_LIBS"
253 GLES_SUPPORT=no
254 fi
255 fi
256fi
257
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200258if [ "$GLES_SUPPORT" = "yes" ]; then
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200259 mkdir -p objs/lib
260
261 for lib in $GLES_SHARED_LIBRARIES; do
262 GLES_LIB=$GLES_LIBS/${lib}$TARGET_DLL_SUFFIX
263 if [ ! -f "$GLES_LIB" ]; then
264 echo "ERROR: Missing OpenGLES emulation host library: $GLES_LIB"
265 echo "Please fix this by using --gles-libs to point to the right directory!"
266 if [ "$IN_ANDROID_BUILD" = "true" ]; then
267 echo "You might also be missing the library because you forgot to rebuild the whole platform!"
268 fi
269 exit 1
270 fi
271 cp $GLES_LIB objs/lib
272 if [ $? != 0 ]; then
273 echo "ERROR: Could not find required OpenGLES emulation library: $GLES_LIB"
274 exit 1
275 else
276 log "GLES : Copying $GLES_LIB"
277 fi
278 done
279fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800280
David 'Digit' Turner5a0063f2014-02-28 15:33:14 +0100281if [ "$PCBIOS_PROBE" = "yes" ]; then
282 PCBIOS_DIR=$(dirname "$0")/../../prebuilts/qemu-kernel/x86/pc-bios
283 if [ ! -d "$PCBIOS_DIR" ]; then
284 log2 "PC Bios : Probing $PCBIOS_DIR (missing)"
285 PCBIOS_DIR=../pc-bios
286 fi
287 log2 "PC Bios : Probing $PCBIOS_DIR"
288 if [ ! -d "$PCBIOS_DIR" ]; then
289 log "PC Bios : Could not find prebuilts directory."
290 else
291 mkdir -p objs/lib/pc-bios
292 for BIOS_FILE in bios.bin vgabios-cirrus.bin; do
293 log "PC Bios : Copying $BIOS_FILE"
294 cp -f $PCBIOS_DIR/$BIOS_FILE objs/lib/pc-bios/$BIOS_FILE
295 done
296 fi
297fi
298
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100299# For OS X, detect the location of the SDK to use.
300if [ "$HOST_OS" = darwin ]; then
301 OSX_VERSION=$(sw_vers -productVersion)
302 OSX_SDK_SUPPORTED="10.6 10.7 10.8"
303 OSX_SDK_INSTALLED_LIST=$(xcodebuild -showsdks 2>/dev/null | grep macosx | sed -e "s/.*macosx//g" | sort -n)
304 if [ -z "$OSX_SDK_INSTALLED_LIST" ]; then
305 echo "ERROR: Please install XCode on this machine!"
306 exit 1
307 fi
308 log "OSX: Installed SDKs: $OSX_SDK_INSTALLED_LIST"
309
310 OSX_SDK_VERSION=$(echo "$OSX_SDK_INSTALLED_LIST" | tr ' ' '\n' | head -1)
311 log "OSX: Using SDK version $OSX_SDK_VERSION"
312
313 XCODE_PATH=$(xcode-select -print-path 2>/dev/null)
314 log "OSX: XCode path: $XCODE_PATH"
315
316 OSX_SDK_ROOT=$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk
317 log "OSX: Looking for $OSX_SDK_ROOT"
318 if [ ! -d "$OSX_SDK_ROOT" ]; then
319 OSX_SDK_ROOT=/Developer/SDKs/MaxOSX${OSX_SDK_VERSION}.sdk
320 log "OSX: Looking for $OSX_SDK_ROOT"
321 if [ ! -d "$OSX_SDK_ROOT" ]; then
322 echo "ERROR: Could not find SDK $OSX_SDK_VERSION at $OSX_SDK_ROOT"
323 exit 1
324 fi
325 fi
326 echo "OSX SDK : Found at $OSX_SDK_ROOT"
327fi
328
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200329# we can build the emulator with Cygwin, so enable it
330enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800331
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200332setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800333
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800334###
335### SDL Probe
336###
337
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700338if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200339
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700340 # check that we can link statically with the library.
341 #
342 SDL_CFLAGS=`$SDL_CONFIG --cflags`
343 SDL_LIBS=`$SDL_CONFIG --static-libs`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800344
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700345 # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
Deepanshu Guptabb761912013-05-28 16:36:40 -0700346 # since they break recent Mingw releases
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700347 SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800348
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700349 log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
350 log "SDL-probe : SDL_LIBS = $SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800351
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800352
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700353 EXTRA_CFLAGS="$SDL_CFLAGS"
354 EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800355
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700356 case "$OS" in
357 freebsd-*)
358 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread"
359 ;;
360 esac
Alexey Tarasov08823222009-09-01 02:07:51 +1100361
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700362 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800363#include <SDL.h>
364#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200365int main( int argc, char** argv ) {
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200366 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800367}
368EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700369 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200370
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700371 if [ $SDL_LINKING != "yes" ] ; then
372 echo "You provided an explicit sdl-config script, but the corresponding library"
373 echo "cannot be statically linked with the Android emulator directly."
374 echo "Error message:"
375 cat $TMPL
376 clean_exit
377 fi
378 log "SDL-probe : static linking ok"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800379
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700380 # now, let's check that the SDL library has the special functions
381 # we added to our own sources
382 #
383 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800384#include <SDL.h>
385#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200386int main( int argc, char** argv ) {
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700387 int x, y;
388 SDL_Rect r;
389 SDL_WM_GetPos(&x, &y);
390 SDL_WM_SetPos(x, y);
391 SDL_WM_GetMonitorDPI(&x, &y);
392 SDL_WM_GetMonitorRect(&r);
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200393 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800394}
395EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700396 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200397
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700398 if [ $SDL_LINKING != "yes" ] ; then
399 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
400 echo "corresponding library doesn't have the patches required to link"
401 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
402 echo "sources bundled with the emulator instead"
403 echo "Error:"
404 cat $TMPL
405 clean_exit
406 fi
407
408 log "SDL-probe : extra features ok"
409 clean_temp
410
411 EXTRA_CFLAGS=
412 EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800413fi
414
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800415###
416### Audio subsystems probes
417###
418PROBE_COREAUDIO=no
419PROBE_ALSA=no
420PROBE_OSS=no
421PROBE_ESD=no
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700422PROBE_PULSEAUDIO=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800423PROBE_WINAUDIO=no
424
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700425case "$TARGET_OS" in
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800426 darwin*) PROBE_COREAUDIO=yes;
427 ;;
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700428 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800429 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100430 freebsd-*) PROBE_OSS=yes;
431 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800432 windows) PROBE_WINAUDIO=yes
433 ;;
434esac
435
436ORG_CFLAGS=$CFLAGS
437ORG_LDFLAGS=$LDFLAGS
438
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200439if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then
440PROBE_ESD_ESD=no
441PROBE_ALSA=no
442PROBE_PULSEAUDIO=no
443fi
444
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700445# Probe a system library
446#
447# $1: Variable name (e.g. PROBE_ESD)
448# $2: Library name (e.g. "Alsa")
449# $3: Path to source file for probe program (e.g. android/config/check-alsa.c)
450# $4: Package name (e.g. libasound-dev)
451#
452probe_system_library ()
453{
454 if [ `var_value $1` = yes ] ; then
455 CFLAGS="$ORG_CFLAGS"
456 LDFLAGS="$ORG_LDFLAGS -ldl"
457 cp -f android/config/check-esd.c $TMPC
David 'Digit' Turnera7ef1ac2010-12-10 22:33:51 +0100458 compile
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700459 if [ $? = 0 ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200460 log "AudioProbe : $2 seems to be usable on this system"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700461 else
462 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200463 echo "The $2 development files do not seem to be installed on this system"
464 echo "Are you missing the $4 package ?"
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100465 echo "You can ignore this error with --ignore-audio, otherwise correct"
466 echo "the issue(s) below and try again:"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700467 cat $TMPL
468 clean_exit
469 fi
470 eval $1=no
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200471 log "AudioProbe : $2 seems to be UNUSABLE on this system !!"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800472 fi
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100473 clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800474 fi
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700475}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800476
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700477probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev
478probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev
479probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800480
481CFLAGS=$ORG_CFLAGS
482LDFLAGS=$ORG_LDFLAGS
483
484# create the objs directory that is going to contain all generated files
485# including the configuration ones
486#
487mkdir -p objs
488
489###
490### Compiler probe
491###
492
493####
494#### Host system probe
495####
496
497# because the previous version could be read-only
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100498clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800499
500# check host endianess
501#
502HOST_BIGENDIAN=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700503if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800504cat > $TMPC << EOF
505#include <inttypes.h>
506int main(int argc, char ** argv){
507 volatile uint32_t i=0x01234567;
Marcus Comstedt17d31322010-10-05 21:54:12 +0200508 return (*((uint8_t*)(&i))) == 0x01;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800509}
510EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200511feature_run_exec HOST_BIGENDIAN
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700512fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800513
514# check size of host long bits
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700515HOST_LONGBITS=32
516if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800517cat > $TMPC << EOF
518int main(void) {
519 return sizeof(void*)*8;
520}
521EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200522feature_run_exec HOST_LONGBITS
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700523fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800524
525# check whether we have <byteswap.h>
526#
David Turnerb8fec3e2010-09-09 18:15:23 +0200527feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
528feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
529feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
David Turner80dd1262010-09-09 18:04:49 +0200530
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800531# Build the config.make file
532#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200533
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200534case $TARGET_OS in
535 windows)
536 TARGET_EXEEXT=.exe
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100537 TARGET_DLLEXT=.dll
538 ;;
539 darwin)
540 TARGET_EXEXT=
541 TARGET_DLLEXT=.dylib
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200542 ;;
543 *)
544 TARGET_EXEEXT=
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100545 TARGET_DLLEXT=.so
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200546 ;;
547esac
548
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100549# Strip executables and shared libraries unless --debug is used.
550if [ "$OPTION_DEBUG" != "yes" ]; then
551 case $HOST_OS in
552 darwin)
553 LDFLAGS="$LDFLAGS -Wl,-S"
554 ;;
555 *)
556 LDFLAGS="$LDFLAGS -Wl,--strip-all"
557 ;;
558 esac
559fi
560
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200561create_config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700562echo "" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700563echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200564echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk
David 'Digit' Turneraf061c52014-02-28 23:33:54 +0100565echo "HOST_DLLEXT := $TARGET_DLLEXT" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700566echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700567echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200568
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800569PWD=`pwd`
570echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700571if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200572echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700573fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800574echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
575echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
576echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
577echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
578echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700579echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800580echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200581if [ $OPTION_DEBUG = yes ] ; then
582 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
583fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800584if [ $OPTION_STATIC = yes ] ; then
585 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
586fi
587
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
596fi
597
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100598if [ "$HOST_OS" = "darwin" ]; then
599 echo "mac_sdk_root := $OSX_SDK_ROOT" >> $config_mk
600 echo "mac_sdk_version := $OSX_SDK_VERSION" >> $config_mk
601fi
602
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800603# Build the config-host.h file
604#
605config_h=objs/config-host.h
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100606cat > $config_h <<EOF
607/* This file was autogenerated by '$PROGNAME' */
608
609#define CONFIG_QEMU_SHAREDIR "/usr/local/share/qemu"
610
611#if defined(__x86_64__)
612#define HOST_X86_64 1
613#define HOST_LONG_BITS 64
614#elif defined(__i386__)
615#define HOST_I386 1
616#define HOST_LONG_BITS 32
617#else
618#error Unknown architecture for codegen
619#endif
620
621EOF
622
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800623if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200624 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
625fi
626if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
627 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800628fi
David Turner80dd1262010-09-09 18:04:49 +0200629if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
630 echo "#define CONFIG_FNMATCH 1" >> $config_h
631fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800632echo "#define CONFIG_GDBSTUB 1" >> $config_h
633echo "#define CONFIG_SLIRP 1" >> $config_h
634echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200635echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700636
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200637case "$TARGET_OS" in
638 windows)
639 echo "#define CONFIG_WIN32 1" >> $config_h
640 ;;
641 *)
642 echo "#define CONFIG_POSIX 1" >> $config_h
643 ;;
644esac
645
646case "$TARGET_OS" in
647 linux-*)
648 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
649 ;;
650esac
651
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700652# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700653case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700654 linux-*)
655 echo "#define CONFIG_FDATASYNC 1" >> $config_h
656 ;;
657esac
658
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200659case "$TARGET_OS" in
660 linux-*|darwin-*)
661 echo "#define CONFIG_MADVISE 1" >> $config_h
662 ;;
663esac
664
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800665# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700666if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800667 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
668fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700669echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
670echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800671case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200672 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800673 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200674 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800675 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200676 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800677 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200678 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800679 ;;
680esac
Marcus Comstedt17d31322010-10-05 21:54:12 +0200681if [ "$HOST_BIGENDIAN" = "1" ] ; then
682 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
683fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200684BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700685case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200686 linux-*) CONFIG_OS=LINUX
687 ;;
688 darwin-*) CONFIG_OS=DARWIN
689 BSD=1
690 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100691 freebsd-*) CONFIG_OS=FREEBSD
692 BSD=1
693 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200694 windows*) CONFIG_OS=WIN32
695 ;;
696 *) CONFIG_OS=$OS
697esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700698
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800699if [ "$OPTION_STATIC" = "yes" ] ; then
700 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
701 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
702fi
703
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700704case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700705 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800706 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700707 ;;
708esac
709
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200710echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
711if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700712 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200713 echo "#define O_LARGEFILE 0" >> $config_h
714 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
715fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700716
David 'Digit' Turner494b1292014-02-05 15:02:04 +0100717case "$TARGET_OS" in
718 linux-*)
719 echo "#define CONFIG_SIGNALFD 1" >> $config_h
720 ;;
721esac
722
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700723echo "#define CONFIG_ANDROID 1" >> $config_h
724
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800725log "Generate : $config_h"
726
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100727# Generate the QAPI headers and sources from qapi-schema.json
728# Ideally, this would be done in our Makefiles, but as far as I
729# understand, the platform build doesn't support a single tool
730# that generates several sources files, nor the standalone one.
731export PYTHONDONTWRITEBYTECODE=1
732AUTOGENERATED_DIR=qapi-auto-generated
733python scripts/qapi-types.py qapi.types --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
734python scripts/qapi-visit.py --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
735python scripts/qapi-commands.py --output-dir=$AUTOGENERATED_DIR -m < qapi-schema.json
736log "Generate : $AUTOGENERATED_DIR"
737
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100738clean_temp
739
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800740echo "Ready to go. Type 'make' to build emulator"