blob: 83bf7c0490e3d8562951c770f5d100571c08c6c2 [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_INCLUDE=
28GLES_LIBS=
29GLES_SUPPORT=no
30GLES_PROBE=yes
31
David 'Digit' Turnere3650682010-12-22 14:44:19 +010032HOST_CC=${CC:-gcc}
33OPTION_CC=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080034
35for opt do
36 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
37 case "$opt" in
38 --help|-h|-\?) OPTION_HELP=yes
39 ;;
40 --verbose)
41 if [ "$VERBOSE" = "yes" ] ; then
42 VERBOSE2=yes
43 else
44 VERBOSE=yes
45 fi
46 ;;
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +020047 --debug) OPTION_DEBUG=yes
48 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +020049 --install=*) OPTION_TARGETS="$OPTION_TARGETS $optarg";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080050 ;;
51 --sdl-config=*) SDL_CONFIG=$optarg
52 ;;
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070053 --mingw) OPTION_MINGW=yes
54 ;;
David 'Digit' Turnere3650682010-12-22 14:44:19 +010055 --cc=*) OPTION_CC="$optarg"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080056 ;;
57 --no-strip) OPTION_NO_STRIP=yes
58 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080059 --ignore-audio) OPTION_IGNORE_AUDIO=yes
60 ;;
61 --no-prebuilts) OPTION_NO_PREBUILTS=yes
62 ;;
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080063 --static) OPTION_STATIC=yes
64 ;;
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +020065 --gles-include=*) GLES_INCLUDE=$optarg
66 GLES_SUPPORT=yes
67 ;;
68 --gles-libs=*) GLES_LIBS=$optarg
69 GLES_SUPPORT=yes
70 ;;
71 --no-gles) GLES_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-include=PATH specify path to GLES emulation headers"
101 echo " --gles-libs=PATH specify path to GLES emulation host libraries"
102 echo " --no-gles disable GLES emulation support"
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
110 HOST_CC=`dirname $0`/../../prebuilts/tools/gcc-sdk/gcc
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100111 if [ -f "$HOST_CC" ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700112 echo "Using prebuilt toolchain: $HOST_CC"
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100113 CC="$HOST_CC"
114 fi
115fi
116
David 'Digit' Turnerba313e02011-02-09 16:01:53 +0100117echo "OPTION_CC='$OPTION_CC'"
118if [ -n "$OPTION_CC" ]; then
119 echo "Using specified C compiler: $OPTION_CC"
120 CC="$OPTION_CC"
121fi
122
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700123if [ -z "$CC" ]; then
124 CC=$HOST_CC
125fi
126
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100127# By default, generate 32-bit binaries, the Makefile have targets that
128# generate 64-bit ones by using -m64 on the command-line.
129force_32bit_binaries
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800130
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200131case $OS in
132 linux-*)
133 TARGET_DLL_SUFFIX=.so
134 ;;
135 darwin-*)
136 TARGET_DLL_SUFFIX=.dylib
137 ;;
138 windows*)
139 TARGET_DLL_SUFFIX=.dll
140esac
141
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700142TARGET_OS=$OS
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200143if [ "$OPTION_MINGW" = "yes" ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700144 enable_linux_mingw
145 TARGET_OS=windows
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200146 TARGET_DLL_SUFFIX=.dll
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700147else
148 enable_cygwin
149fi
150
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200151# Are we running in the Android build system ?
152check_android_build
153
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800154
155# Adjust a few things when we're building within the Android build
156# system:
157# - locate prebuilt directory
158# - locate and use prebuilt libraries
159# - copy the new binary to the correct location
160#
161if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then
162 IN_ANDROID_BUILD=no
163fi
164
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200165# This is the list of static and shared host libraries we need to link
166# against in order to support OpenGLES emulation properly. Note that in
167# the case of a standalone build, we will find these libraries inside the
168# platform build tree and copy them into objs/lib/ automatically, unless
169# you use --gles-libs to point explicitely to a different directory.
170#
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100171GLES_SHARED_LIBRARIES="\
172 libOpenglRender \
173 libGLES_CM_translator \
174 libGLES_V2_translator \
175 libEGL_translator"
176
177if [ "$OPTION_MINGW" != "true" ]; then
178 # There are no 64-bit libraries for Windows yet!
179 GLES_SHARED_LIBRARIES="$GLES_SHARED_LIBRARIES \
180 lib64OpenglRender \
181 lib64GLES_CM_translator \
182 lib64GLES_V2_translator \
183 lib64EGL_translator"
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700184fi
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200185
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800186if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200187 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800188
189 # use ccache if USE_CCACHE is defined and the corresponding
190 # binary is available.
191 #
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800192 if [ -n "$USE_CCACHE" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200193 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800194 if [ ! -f $CCACHE ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700195 CCACHE="$ANDROID_PREBUILTS/ccache/ccache$EXE"
196 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800197 if [ -f $CCACHE ] ; then
198 CC="$CCACHE $CC"
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700199 log "Prebuilt : CCACHE=$CCACHE"
200 else
201 log "Prebuilt : CCACHE can't be found"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800202 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800203 fi
204
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800205 # finally ensure that our new binary is copied to the 'out'
206 # subdirectory as 'emulator'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200207 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200208 if [ "$TARGET_OS" = "windows" ]; then
209 HOST_BIN=$(echo $HOST_BIN | sed "s%$OS/bin%windows/bin%")
210 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800211 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200212 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
213 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800214 fi
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800215
216 # find the Android SDK Tools revision number
217 TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties
218 if [ -f $TOOLS_PROPS ] ; then
219 ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null`
220 log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION"
221 else
222 log "Tools : Could not locate $TOOLS_PROPS !?"
223 fi
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200224
225 # Try to find the GLES emulation headers and libraries automatically
226 if [ "$GLES_PROBE" = "yes" ]; then
227 GLES_SUPPORT=yes
228 if [ -z "$GLES_INCLUDE" ]; then
229 log "GLES : Probing for headers"
Jesse Hall183e9272012-04-26 15:13:27 -0700230 GLES_INCLUDE=$ANDROID_TOP/sdk/emulator/opengl/host/include
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200231 if [ -d "$GLES_INCLUDE" ]; then
232 log "GLES : Headers in $GLES_INCLUDE"
233 else
234 echo "Warning: Could not find OpenGLES emulation include dir: $GLES_INCLUDE"
235 echo "Disabling GLES emulation from this build!"
236 GLES_SUPPORT=no
237 fi
238 fi
239 if [ -z "$GLES_LIBS" ]; then
240 log "GLES : Probing for host libraries"
241 GLES_LIBS=$(dirname "$HOST_BIN")/lib
242 if [ -d "$GLES_LIBS" ]; then
243 echo "GLES : Libs in $GLES_LIBS"
244 else
245 echo "Warning: Could nof find OpenGLES emulation libraries in: $GLES_LIBS"
246 echo "Disabling GLES emulation from this build!"
247 GLES_SUPPORT=no
248 fi
249 fi
250 fi
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700251else
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100252 if [ -n "$USE_CCACHE" ]; then
253 CCACHE=$(which ccache 2>/dev/null)
254 if [ -n "$CCACHE" -a -f "$CCACHE" ] ; then
255 CC="$CCACHE $CC"
256 log "Prebuilt : CCACHE=$CCACHE"
257 else
258 log "Prebuilt : CCACHE can't be found"
259 fi
260 fi
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700261 if [ "$GLES_PROBE" = "yes" ]; then
262 GLES_SUPPORT=yes
263 if [ -z "$GLES_INCLUDE" ]; then
264 log "GLES : Probing for headers"
265 GLES_INCLUDE=../../sdk/emulator/opengl/host/include
266 if [ -d "$GLES_INCLUDE" ]; then
267 log "GLES : Headers in $GLES_INCLUDE"
268 else
269 echo "Warning: Could not find OpenGLES emulation include dir: $GLES_INCLUDE"
270 echo "Disabling GLES emulation from this build!"
271 GLES_SUPPORT=no
272 fi
273 fi
274 if [ -z "$GLES_LIBS" ]; then
275 log "GLES : Probing for host libraries"
276 GLES_LIBS=../../out/host/$OS/lib
277 if [ -d "$GLES_LIBS" ]; then
278 echo "GLES : Libs in $GLES_LIBS"
279 else
280 echo "Warning: Could nof find OpenGLES emulation libraries in: $GLES_LIBS"
281 echo "Disabling GLES emulation from this build!"
282 GLES_SUPPORT=no
283 fi
284 fi
285 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800286fi # IN_ANDROID_BUILD = no
287
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200288if [ "$GLES_SUPPORT" = "yes" ]; then
289 if [ -z "$GLES_INCLUDE" -o -z "$GLES_LIBS" ]; then
290 echo "ERROR: You must use both --gles-include and --gles-libs at the same time!"
291 echo " Or use --no-gles to disable its support from this build."
292 exit 1
293 fi
294
295 GLES_HEADER=$GLES_INCLUDE/libOpenglRender/render_api.h
296 if [ ! -f "$GLES_HEADER" ]; then
297 echo "ERROR: Missing OpenGLES emulation header file: $GLES_HEADER"
298 echo "Please fix this by using --gles-include to point to the right directory!"
299 exit 1
300 fi
301
302 mkdir -p objs/lib
303
304 for lib in $GLES_SHARED_LIBRARIES; do
305 GLES_LIB=$GLES_LIBS/${lib}$TARGET_DLL_SUFFIX
306 if [ ! -f "$GLES_LIB" ]; then
307 echo "ERROR: Missing OpenGLES emulation host library: $GLES_LIB"
308 echo "Please fix this by using --gles-libs to point to the right directory!"
309 if [ "$IN_ANDROID_BUILD" = "true" ]; then
310 echo "You might also be missing the library because you forgot to rebuild the whole platform!"
311 fi
312 exit 1
313 fi
314 cp $GLES_LIB objs/lib
315 if [ $? != 0 ]; then
316 echo "ERROR: Could not find required OpenGLES emulation library: $GLES_LIB"
317 exit 1
318 else
319 log "GLES : Copying $GLES_LIB"
320 fi
321 done
322fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800323
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100324# For OS X, detect the location of the SDK to use.
325if [ "$HOST_OS" = darwin ]; then
326 OSX_VERSION=$(sw_vers -productVersion)
327 OSX_SDK_SUPPORTED="10.6 10.7 10.8"
328 OSX_SDK_INSTALLED_LIST=$(xcodebuild -showsdks 2>/dev/null | grep macosx | sed -e "s/.*macosx//g" | sort -n)
329 if [ -z "$OSX_SDK_INSTALLED_LIST" ]; then
330 echo "ERROR: Please install XCode on this machine!"
331 exit 1
332 fi
333 log "OSX: Installed SDKs: $OSX_SDK_INSTALLED_LIST"
334
335 OSX_SDK_VERSION=$(echo "$OSX_SDK_INSTALLED_LIST" | tr ' ' '\n' | head -1)
336 log "OSX: Using SDK version $OSX_SDK_VERSION"
337
338 XCODE_PATH=$(xcode-select -print-path 2>/dev/null)
339 log "OSX: XCode path: $XCODE_PATH"
340
341 OSX_SDK_ROOT=$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk
342 log "OSX: Looking for $OSX_SDK_ROOT"
343 if [ ! -d "$OSX_SDK_ROOT" ]; then
344 OSX_SDK_ROOT=/Developer/SDKs/MaxOSX${OSX_SDK_VERSION}.sdk
345 log "OSX: Looking for $OSX_SDK_ROOT"
346 if [ ! -d "$OSX_SDK_ROOT" ]; then
347 echo "ERROR: Could not find SDK $OSX_SDK_VERSION at $OSX_SDK_ROOT"
348 exit 1
349 fi
350 fi
351 echo "OSX SDK : Found at $OSX_SDK_ROOT"
352fi
353
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200354# we can build the emulator with Cygwin, so enable it
355enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800356
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200357setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800358
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800359###
360### SDL Probe
361###
362
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700363if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200364
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700365 # check that we can link statically with the library.
366 #
367 SDL_CFLAGS=`$SDL_CONFIG --cflags`
368 SDL_LIBS=`$SDL_CONFIG --static-libs`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800369
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700370 # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
Deepanshu Guptabb761912013-05-28 16:36:40 -0700371 # since they break recent Mingw releases
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700372 SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800373
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700374 log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
375 log "SDL-probe : SDL_LIBS = $SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800376
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800377
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700378 EXTRA_CFLAGS="$SDL_CFLAGS"
379 EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800380
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700381 case "$OS" in
382 freebsd-*)
383 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread"
384 ;;
385 esac
Alexey Tarasov08823222009-09-01 02:07:51 +1100386
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700387 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800388#include <SDL.h>
389#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200390int main( int argc, char** argv ) {
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200391 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800392}
393EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700394 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200395
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700396 if [ $SDL_LINKING != "yes" ] ; then
397 echo "You provided an explicit sdl-config script, but the corresponding library"
398 echo "cannot be statically linked with the Android emulator directly."
399 echo "Error message:"
400 cat $TMPL
401 clean_exit
402 fi
403 log "SDL-probe : static linking ok"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800404
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700405 # now, let's check that the SDL library has the special functions
406 # we added to our own sources
407 #
408 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800409#include <SDL.h>
410#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200411int main( int argc, char** argv ) {
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700412 int x, y;
413 SDL_Rect r;
414 SDL_WM_GetPos(&x, &y);
415 SDL_WM_SetPos(x, y);
416 SDL_WM_GetMonitorDPI(&x, &y);
417 SDL_WM_GetMonitorRect(&r);
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200418 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800419}
420EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700421 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200422
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700423 if [ $SDL_LINKING != "yes" ] ; then
424 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
425 echo "corresponding library doesn't have the patches required to link"
426 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
427 echo "sources bundled with the emulator instead"
428 echo "Error:"
429 cat $TMPL
430 clean_exit
431 fi
432
433 log "SDL-probe : extra features ok"
434 clean_temp
435
436 EXTRA_CFLAGS=
437 EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800438fi
439
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800440###
441### Audio subsystems probes
442###
443PROBE_COREAUDIO=no
444PROBE_ALSA=no
445PROBE_OSS=no
446PROBE_ESD=no
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700447PROBE_PULSEAUDIO=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800448PROBE_WINAUDIO=no
449
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700450case "$TARGET_OS" in
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800451 darwin*) PROBE_COREAUDIO=yes;
452 ;;
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700453 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800454 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100455 freebsd-*) PROBE_OSS=yes;
456 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800457 windows) PROBE_WINAUDIO=yes
458 ;;
459esac
460
461ORG_CFLAGS=$CFLAGS
462ORG_LDFLAGS=$LDFLAGS
463
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200464if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then
465PROBE_ESD_ESD=no
466PROBE_ALSA=no
467PROBE_PULSEAUDIO=no
468fi
469
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700470# Probe a system library
471#
472# $1: Variable name (e.g. PROBE_ESD)
473# $2: Library name (e.g. "Alsa")
474# $3: Path to source file for probe program (e.g. android/config/check-alsa.c)
475# $4: Package name (e.g. libasound-dev)
476#
477probe_system_library ()
478{
479 if [ `var_value $1` = yes ] ; then
480 CFLAGS="$ORG_CFLAGS"
481 LDFLAGS="$ORG_LDFLAGS -ldl"
482 cp -f android/config/check-esd.c $TMPC
David 'Digit' Turnera7ef1ac2010-12-10 22:33:51 +0100483 compile
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700484 if [ $? = 0 ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200485 log "AudioProbe : $2 seems to be usable on this system"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700486 else
487 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200488 echo "The $2 development files do not seem to be installed on this system"
489 echo "Are you missing the $4 package ?"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700490 echo "Correct the errors below and try again:"
491 cat $TMPL
492 clean_exit
493 fi
494 eval $1=no
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200495 log "AudioProbe : $2 seems to be UNUSABLE on this system !!"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800496 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800497 fi
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700498}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800499
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700500probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev
501probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev
502probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800503
504CFLAGS=$ORG_CFLAGS
505LDFLAGS=$ORG_LDFLAGS
506
507# create the objs directory that is going to contain all generated files
508# including the configuration ones
509#
510mkdir -p objs
511
512###
513### Compiler probe
514###
515
516####
517#### Host system probe
518####
519
520# because the previous version could be read-only
521rm -f $TMPC
522
523# check host endianess
524#
525HOST_BIGENDIAN=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700526if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800527cat > $TMPC << EOF
528#include <inttypes.h>
529int main(int argc, char ** argv){
530 volatile uint32_t i=0x01234567;
Marcus Comstedt17d31322010-10-05 21:54:12 +0200531 return (*((uint8_t*)(&i))) == 0x01;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800532}
533EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200534feature_run_exec HOST_BIGENDIAN
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700535fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800536
537# check size of host long bits
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700538HOST_LONGBITS=32
539if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800540cat > $TMPC << EOF
541int main(void) {
542 return sizeof(void*)*8;
543}
544EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200545feature_run_exec HOST_LONGBITS
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700546fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800547
548# check whether we have <byteswap.h>
549#
David Turnerb8fec3e2010-09-09 18:15:23 +0200550feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
551feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
552feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
David Turner80dd1262010-09-09 18:04:49 +0200553
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800554# Build the config.make file
555#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200556
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200557case $TARGET_OS in
558 windows)
559 TARGET_EXEEXT=.exe
560 ;;
561 *)
562 TARGET_EXEEXT=
563 ;;
564esac
565
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200566create_config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700567echo "" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700568echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200569echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $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
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800573PWD=`pwd`
574echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700575if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200576echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700577fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800578echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
579echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
580echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
581echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
582echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700583echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800584echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200585if [ $OPTION_DEBUG = yes ] ; then
586 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
587fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800588if [ $OPTION_STATIC = yes ] ; then
589 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
590fi
591
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800592if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
593 echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
594fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800595
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700596if [ "$OPTION_MINGW" = "yes" ] ; then
597 echo "" >> $config_mk
598 echo "USE_MINGW := 1" >> $config_mk
599 echo "HOST_OS := windows" >> $config_mk
600fi
601
David 'Digit' Turner58c33ad2014-01-19 17:29:40 +0100602if [ "$GLES_SUPPORT" = "yes" -a "$GLES_INCLUDE" -a "$GLES_LIBS" ]; then
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200603 echo "QEMU_OPENGLES_INCLUDE := $GLES_INCLUDE" >> $config_mk
604 echo "QEMU_OPENGLES_LIBS := $GLES_LIBS" >> $config_mk
605fi
606
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100607if [ "$HOST_OS" = "darwin" ]; then
608 echo "mac_sdk_root := $OSX_SDK_ROOT" >> $config_mk
609 echo "mac_sdk_version := $OSX_SDK_VERSION" >> $config_mk
610fi
611
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800612# Build the config-host.h file
613#
614config_h=objs/config-host.h
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100615cat > $config_h <<EOF
616/* This file was autogenerated by '$PROGNAME' */
617
618#define CONFIG_QEMU_SHAREDIR "/usr/local/share/qemu"
619
620#if defined(__x86_64__)
621#define HOST_X86_64 1
622#define HOST_LONG_BITS 64
623#elif defined(__i386__)
624#define HOST_I386 1
625#define HOST_LONG_BITS 32
626#else
627#error Unknown architecture for codegen
628#endif
629
630EOF
631
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800632if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200633 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
634fi
635if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
636 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800637fi
David Turner80dd1262010-09-09 18:04:49 +0200638if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
639 echo "#define CONFIG_FNMATCH 1" >> $config_h
640fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800641echo "#define CONFIG_GDBSTUB 1" >> $config_h
642echo "#define CONFIG_SLIRP 1" >> $config_h
643echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200644echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700645
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200646case "$TARGET_OS" in
647 windows)
648 echo "#define CONFIG_WIN32 1" >> $config_h
649 ;;
650 *)
651 echo "#define CONFIG_POSIX 1" >> $config_h
652 ;;
653esac
654
655case "$TARGET_OS" in
656 linux-*)
657 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
658 ;;
659esac
660
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700661# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700662case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700663 linux-*)
664 echo "#define CONFIG_FDATASYNC 1" >> $config_h
665 ;;
666esac
667
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200668case "$TARGET_OS" in
669 linux-*|darwin-*)
670 echo "#define CONFIG_MADVISE 1" >> $config_h
671 ;;
672esac
673
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800674# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700675if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800676 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
677fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700678echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
679echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800680case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200681 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800682 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200683 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800684 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200685 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800686 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200687 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800688 ;;
689esac
Marcus Comstedt17d31322010-10-05 21:54:12 +0200690if [ "$HOST_BIGENDIAN" = "1" ] ; then
691 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
692fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200693BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700694case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200695 linux-*) CONFIG_OS=LINUX
696 ;;
697 darwin-*) CONFIG_OS=DARWIN
698 BSD=1
699 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100700 freebsd-*) CONFIG_OS=FREEBSD
701 BSD=1
702 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200703 windows*) CONFIG_OS=WIN32
704 ;;
705 *) CONFIG_OS=$OS
706esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700707
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800708if [ "$OPTION_STATIC" = "yes" ] ; then
709 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
710 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
711fi
712
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700713case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700714 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800715 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700716 ;;
717esac
718
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200719echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
720if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700721 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200722 echo "#define O_LARGEFILE 0" >> $config_h
723 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
724fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700725
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700726echo "#define CONFIG_ANDROID 1" >> $config_h
727
David 'Digit' Turner58c33ad2014-01-19 17:29:40 +0100728if [ "$GLES_SUPPORT" = "yes" ]; then
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200729 echo "#define CONFIG_ANDROID_OPENGLES 1" >> $config_h
730fi
731
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800732log "Generate : $config_h"
733
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100734# Generate the QAPI headers and sources from qapi-schema.json
735# Ideally, this would be done in our Makefiles, but as far as I
736# understand, the platform build doesn't support a single tool
737# that generates several sources files, nor the standalone one.
738export PYTHONDONTWRITEBYTECODE=1
739AUTOGENERATED_DIR=qapi-auto-generated
740python scripts/qapi-types.py qapi.types --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
741python scripts/qapi-visit.py --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
742python scripts/qapi-commands.py --output-dir=$AUTOGENERATED_DIR -m < qapi-schema.json
743log "Generate : $AUTOGENERATED_DIR"
744
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800745echo "Ready to go. Type 'make' to build emulator"