blob: 12ed9424509cd43a75f9729236b8dbe6b06750c4 [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' Turnere3650682010-12-22 14:44:19 +010031HOST_CC=${CC:-gcc}
32OPTION_CC=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080033
34for opt do
35 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
36 case "$opt" in
37 --help|-h|-\?) OPTION_HELP=yes
38 ;;
39 --verbose)
40 if [ "$VERBOSE" = "yes" ] ; then
41 VERBOSE2=yes
42 else
43 VERBOSE=yes
44 fi
45 ;;
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +020046 --debug) OPTION_DEBUG=yes
47 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +020048 --install=*) OPTION_TARGETS="$OPTION_TARGETS $optarg";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080049 ;;
50 --sdl-config=*) SDL_CONFIG=$optarg
51 ;;
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070052 --mingw) OPTION_MINGW=yes
53 ;;
David 'Digit' Turnere3650682010-12-22 14:44:19 +010054 --cc=*) OPTION_CC="$optarg"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080055 ;;
56 --no-strip) OPTION_NO_STRIP=yes
57 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080058 --ignore-audio) OPTION_IGNORE_AUDIO=yes
59 ;;
60 --no-prebuilts) OPTION_NO_PREBUILTS=yes
61 ;;
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080062 --static) OPTION_STATIC=yes
63 ;;
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +020064 --gles-libs=*) GLES_LIBS=$optarg
65 GLES_SUPPORT=yes
66 ;;
67 --no-gles) GLES_PROBE=no
68 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080069 *)
70 echo "unknown option '$opt', use --help"
71 exit 1
72 esac
73done
74
75# Print the help message
76#
77if [ "$OPTION_HELP" = "yes" ] ; then
78 cat << EOF
79
80Usage: rebuild.sh [options]
81Options: [defaults in brackets after descriptions]
82EOF
83 echo "Standard options:"
84 echo " --help print this message"
85 echo " --install=FILEPATH copy emulator executable to FILEPATH [$TARGETS]"
David 'Digit' Turnere3650682010-12-22 14:44:19 +010086 echo " --cc=PATH specify C compiler [$HOST_CC]"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080087 echo " --sdl-config=FILE use specific sdl-config script [$SDL_CONFIG]"
88 echo " --no-strip do not strip emulator executable"
89 echo " --debug enable debug (-O0 -g) build"
90 echo " --ignore-audio ignore audio messages (may build sound-less emulator)"
91 echo " --no-prebuilts do not use prebuilt libraries and compiler"
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070092 echo " --mingw build Windows executable on Linux"
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080093 echo " --static build a completely static executable"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080094 echo " --verbose verbose configuration"
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +020095 echo " --debug build debug version of the emulator"
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +020096 echo " --gles-include=PATH specify path to GLES emulation headers"
97 echo " --gles-libs=PATH specify path to GLES emulation host libraries"
98 echo " --no-gles disable GLES emulation support"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080099 echo ""
100 exit 1
101fi
102
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700103# On Linux, try to use our prebuilt toolchain to generate binaries
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100104# that are compatible with Ubuntu 8.04
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700105if [ -z "$CC" -a -z "$OPTION_CC" -a "$HOST_OS" = linux ] ; then
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100106 PROBE_HOST_CC=`dirname $0`/../../prebuilts/tools/gcc-sdk/gcc
107 if [ -f "$PROBE_HOST_CC" ] ; then
108 echo "Using prebuilt toolchain: $PROBE_HOST_CC"
109 CC="$PROBE_HOST_CC"
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100110 fi
111fi
112
David 'Digit' Turnerba313e02011-02-09 16:01:53 +0100113if [ -n "$OPTION_CC" ]; then
114 echo "Using specified C compiler: $OPTION_CC"
115 CC="$OPTION_CC"
116fi
117
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700118if [ -z "$CC" ]; then
119 CC=$HOST_CC
120fi
121
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100122# By default, generate 32-bit binaries, the Makefile have targets that
123# generate 64-bit ones by using -m64 on the command-line.
124force_32bit_binaries
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800125
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200126case $OS in
127 linux-*)
128 TARGET_DLL_SUFFIX=.so
129 ;;
130 darwin-*)
131 TARGET_DLL_SUFFIX=.dylib
132 ;;
133 windows*)
134 TARGET_DLL_SUFFIX=.dll
135esac
136
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700137TARGET_OS=$OS
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200138if [ "$OPTION_MINGW" = "yes" ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700139 enable_linux_mingw
140 TARGET_OS=windows
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200141 TARGET_DLL_SUFFIX=.dll
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700142else
143 enable_cygwin
144fi
145
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200146# Are we running in the Android build system ?
147check_android_build
148
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800149
150# Adjust a few things when we're building within the Android build
151# system:
152# - locate prebuilt directory
153# - locate and use prebuilt libraries
154# - copy the new binary to the correct location
155#
156if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then
157 IN_ANDROID_BUILD=no
158fi
159
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200160# This is the list of static and shared host libraries we need to link
161# against in order to support OpenGLES emulation properly. Note that in
162# the case of a standalone build, we will find these libraries inside the
163# platform build tree and copy them into objs/lib/ automatically, unless
164# you use --gles-libs to point explicitely to a different directory.
165#
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100166GLES_SHARED_LIBRARIES="\
167 libOpenglRender \
168 libGLES_CM_translator \
169 libGLES_V2_translator \
170 libEGL_translator"
171
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100172if [ "$OPTION_MINGW" != "yes" ]; then
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100173 # There are no 64-bit libraries for Windows yet!
174 GLES_SHARED_LIBRARIES="$GLES_SHARED_LIBRARIES \
175 lib64OpenglRender \
176 lib64GLES_CM_translator \
177 lib64GLES_V2_translator \
178 lib64EGL_translator"
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700179fi
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200180
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800181if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200182 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800183
184 # use ccache if USE_CCACHE is defined and the corresponding
185 # binary is available.
186 #
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800187 if [ -n "$USE_CCACHE" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200188 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800189 if [ ! -f $CCACHE ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700190 CCACHE="$ANDROID_PREBUILTS/ccache/ccache$EXE"
191 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800192 fi
193
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800194 # finally ensure that our new binary is copied to the 'out'
195 # subdirectory as 'emulator'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200196 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200197 if [ "$TARGET_OS" = "windows" ]; then
198 HOST_BIN=$(echo $HOST_BIN | sed "s%$OS/bin%windows/bin%")
199 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800200 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200201 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
202 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800203 fi
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800204
205 # find the Android SDK Tools revision number
206 TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties
207 if [ -f $TOOLS_PROPS ] ; then
208 ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null`
209 log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION"
210 else
211 log "Tools : Could not locate $TOOLS_PROPS !?"
212 fi
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200213
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100214 GLES_PROBE_LIB_DIR=$(dirname "$HOST_BIN")/lib
215 case $GLES_PROBE_LIB_DIR in
216 */windows/lib)
217 GLES_PROBE_LIB_DIR=${GLES_PROBE_LIB_DIR%%/windows/lib}/windows-x86/lib
218 ;;
219 esac
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700220else
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100221 if [ -n "$USE_CCACHE" ]; then
222 CCACHE=$(which ccache 2>/dev/null)
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100223 fi
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100224 GLES_PROBE_OS=$TARGET_OS
225 if [ "$GLES_PROBE_OS" = "windows" ]; then
226 GLES_PROBE_OS=windows-x86
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700227 fi
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100228 GLES_PROBE_LIB_DIR=../../out/host/$GLES_PROBE_OS/lib
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800229fi # IN_ANDROID_BUILD = no
230
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100231if [ -n "$CCACHE" -a -f "$CCACHE" ] ; then
232 CC="$CCACHE $CC"
233 log "Prebuilt : CCACHE=$CCACHE"
234else
235 log "Prebuilt : CCACHE can't be found"
236 CCACHE=
237fi
238
239# Try to find the GLES emulation headers and libraries automatically
240if [ "$GLES_PROBE" = "yes" ]; then
241 GLES_SUPPORT=yes
242 if [ -z "$GLES_LIBS" ]; then
243 log "GLES : Probing for host libraries"
244 GLES_LIBS=$GLES_PROBE_LIB_DIR
245 if [ -d "$GLES_LIBS" ]; then
246 echo "GLES : Libs in $GLES_LIBS"
247 else
248 echo "Warning: Could nof find OpenGLES emulation libraries in: $GLES_LIBS"
249 GLES_SUPPORT=no
250 fi
251 fi
252fi
253
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200254if [ "$GLES_SUPPORT" = "yes" ]; then
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200255 mkdir -p objs/lib
256
257 for lib in $GLES_SHARED_LIBRARIES; do
258 GLES_LIB=$GLES_LIBS/${lib}$TARGET_DLL_SUFFIX
259 if [ ! -f "$GLES_LIB" ]; then
260 echo "ERROR: Missing OpenGLES emulation host library: $GLES_LIB"
261 echo "Please fix this by using --gles-libs to point to the right directory!"
262 if [ "$IN_ANDROID_BUILD" = "true" ]; then
263 echo "You might also be missing the library because you forgot to rebuild the whole platform!"
264 fi
265 exit 1
266 fi
267 cp $GLES_LIB objs/lib
268 if [ $? != 0 ]; then
269 echo "ERROR: Could not find required OpenGLES emulation library: $GLES_LIB"
270 exit 1
271 else
272 log "GLES : Copying $GLES_LIB"
273 fi
274 done
275fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800276
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100277# For OS X, detect the location of the SDK to use.
278if [ "$HOST_OS" = darwin ]; then
279 OSX_VERSION=$(sw_vers -productVersion)
280 OSX_SDK_SUPPORTED="10.6 10.7 10.8"
281 OSX_SDK_INSTALLED_LIST=$(xcodebuild -showsdks 2>/dev/null | grep macosx | sed -e "s/.*macosx//g" | sort -n)
282 if [ -z "$OSX_SDK_INSTALLED_LIST" ]; then
283 echo "ERROR: Please install XCode on this machine!"
284 exit 1
285 fi
286 log "OSX: Installed SDKs: $OSX_SDK_INSTALLED_LIST"
287
288 OSX_SDK_VERSION=$(echo "$OSX_SDK_INSTALLED_LIST" | tr ' ' '\n' | head -1)
289 log "OSX: Using SDK version $OSX_SDK_VERSION"
290
291 XCODE_PATH=$(xcode-select -print-path 2>/dev/null)
292 log "OSX: XCode path: $XCODE_PATH"
293
294 OSX_SDK_ROOT=$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk
295 log "OSX: Looking for $OSX_SDK_ROOT"
296 if [ ! -d "$OSX_SDK_ROOT" ]; then
297 OSX_SDK_ROOT=/Developer/SDKs/MaxOSX${OSX_SDK_VERSION}.sdk
298 log "OSX: Looking for $OSX_SDK_ROOT"
299 if [ ! -d "$OSX_SDK_ROOT" ]; then
300 echo "ERROR: Could not find SDK $OSX_SDK_VERSION at $OSX_SDK_ROOT"
301 exit 1
302 fi
303 fi
304 echo "OSX SDK : Found at $OSX_SDK_ROOT"
305fi
306
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200307# we can build the emulator with Cygwin, so enable it
308enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800309
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200310setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800311
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800312###
313### SDL Probe
314###
315
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700316if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200317
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700318 # check that we can link statically with the library.
319 #
320 SDL_CFLAGS=`$SDL_CONFIG --cflags`
321 SDL_LIBS=`$SDL_CONFIG --static-libs`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800322
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700323 # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
Deepanshu Guptabb761912013-05-28 16:36:40 -0700324 # since they break recent Mingw releases
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700325 SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800326
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700327 log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
328 log "SDL-probe : SDL_LIBS = $SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800329
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800330
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700331 EXTRA_CFLAGS="$SDL_CFLAGS"
332 EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800333
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700334 case "$OS" in
335 freebsd-*)
336 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread"
337 ;;
338 esac
Alexey Tarasov08823222009-09-01 02:07:51 +1100339
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700340 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800341#include <SDL.h>
342#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200343int main( int argc, char** argv ) {
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200344 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800345}
346EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700347 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200348
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700349 if [ $SDL_LINKING != "yes" ] ; then
350 echo "You provided an explicit sdl-config script, but the corresponding library"
351 echo "cannot be statically linked with the Android emulator directly."
352 echo "Error message:"
353 cat $TMPL
354 clean_exit
355 fi
356 log "SDL-probe : static linking ok"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800357
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700358 # now, let's check that the SDL library has the special functions
359 # we added to our own sources
360 #
361 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800362#include <SDL.h>
363#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200364int main( int argc, char** argv ) {
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700365 int x, y;
366 SDL_Rect r;
367 SDL_WM_GetPos(&x, &y);
368 SDL_WM_SetPos(x, y);
369 SDL_WM_GetMonitorDPI(&x, &y);
370 SDL_WM_GetMonitorRect(&r);
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200371 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800372}
373EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700374 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200375
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700376 if [ $SDL_LINKING != "yes" ] ; then
377 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
378 echo "corresponding library doesn't have the patches required to link"
379 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
380 echo "sources bundled with the emulator instead"
381 echo "Error:"
382 cat $TMPL
383 clean_exit
384 fi
385
386 log "SDL-probe : extra features ok"
387 clean_temp
388
389 EXTRA_CFLAGS=
390 EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800391fi
392
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800393###
394### Audio subsystems probes
395###
396PROBE_COREAUDIO=no
397PROBE_ALSA=no
398PROBE_OSS=no
399PROBE_ESD=no
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700400PROBE_PULSEAUDIO=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800401PROBE_WINAUDIO=no
402
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700403case "$TARGET_OS" in
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800404 darwin*) PROBE_COREAUDIO=yes;
405 ;;
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700406 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800407 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100408 freebsd-*) PROBE_OSS=yes;
409 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800410 windows) PROBE_WINAUDIO=yes
411 ;;
412esac
413
414ORG_CFLAGS=$CFLAGS
415ORG_LDFLAGS=$LDFLAGS
416
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200417if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then
418PROBE_ESD_ESD=no
419PROBE_ALSA=no
420PROBE_PULSEAUDIO=no
421fi
422
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700423# Probe a system library
424#
425# $1: Variable name (e.g. PROBE_ESD)
426# $2: Library name (e.g. "Alsa")
427# $3: Path to source file for probe program (e.g. android/config/check-alsa.c)
428# $4: Package name (e.g. libasound-dev)
429#
430probe_system_library ()
431{
432 if [ `var_value $1` = yes ] ; then
433 CFLAGS="$ORG_CFLAGS"
434 LDFLAGS="$ORG_LDFLAGS -ldl"
435 cp -f android/config/check-esd.c $TMPC
David 'Digit' Turnera7ef1ac2010-12-10 22:33:51 +0100436 compile
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700437 if [ $? = 0 ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200438 log "AudioProbe : $2 seems to be usable on this system"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700439 else
440 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200441 echo "The $2 development files do not seem to be installed on this system"
442 echo "Are you missing the $4 package ?"
David 'Digit' Turnera10b3162014-02-18 15:36:05 +0100443 echo "You can ignore this error with --ignore-audio, otherwise correct"
444 echo "the issue(s) below and try again:"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700445 cat $TMPL
446 clean_exit
447 fi
448 eval $1=no
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200449 log "AudioProbe : $2 seems to be UNUSABLE on this system !!"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800450 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800451 fi
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700452}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800453
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700454probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev
455probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev
456probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800457
458CFLAGS=$ORG_CFLAGS
459LDFLAGS=$ORG_LDFLAGS
460
461# create the objs directory that is going to contain all generated files
462# including the configuration ones
463#
464mkdir -p objs
465
466###
467### Compiler probe
468###
469
470####
471#### Host system probe
472####
473
474# because the previous version could be read-only
475rm -f $TMPC
476
477# check host endianess
478#
479HOST_BIGENDIAN=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700480if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800481cat > $TMPC << EOF
482#include <inttypes.h>
483int main(int argc, char ** argv){
484 volatile uint32_t i=0x01234567;
Marcus Comstedt17d31322010-10-05 21:54:12 +0200485 return (*((uint8_t*)(&i))) == 0x01;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800486}
487EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200488feature_run_exec HOST_BIGENDIAN
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700489fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800490
491# check size of host long bits
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700492HOST_LONGBITS=32
493if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800494cat > $TMPC << EOF
495int main(void) {
496 return sizeof(void*)*8;
497}
498EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200499feature_run_exec HOST_LONGBITS
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700500fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800501
502# check whether we have <byteswap.h>
503#
David Turnerb8fec3e2010-09-09 18:15:23 +0200504feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
505feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
506feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
David Turner80dd1262010-09-09 18:04:49 +0200507
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800508# Build the config.make file
509#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200510
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200511case $TARGET_OS in
512 windows)
513 TARGET_EXEEXT=.exe
514 ;;
515 *)
516 TARGET_EXEEXT=
517 ;;
518esac
519
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200520create_config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700521echo "" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700522echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200523echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700524echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700525echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200526
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800527PWD=`pwd`
528echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700529if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200530echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700531fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800532echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
533echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
534echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
535echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
536echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700537echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800538echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200539if [ $OPTION_DEBUG = yes ] ; then
540 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
541fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800542if [ $OPTION_STATIC = yes ] ; then
543 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
544fi
545
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800546if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
547 echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
548fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800549
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700550if [ "$OPTION_MINGW" = "yes" ] ; then
551 echo "" >> $config_mk
552 echo "USE_MINGW := 1" >> $config_mk
553 echo "HOST_OS := windows" >> $config_mk
554fi
555
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100556if [ "$HOST_OS" = "darwin" ]; then
557 echo "mac_sdk_root := $OSX_SDK_ROOT" >> $config_mk
558 echo "mac_sdk_version := $OSX_SDK_VERSION" >> $config_mk
559fi
560
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800561# Build the config-host.h file
562#
563config_h=objs/config-host.h
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100564cat > $config_h <<EOF
565/* This file was autogenerated by '$PROGNAME' */
566
567#define CONFIG_QEMU_SHAREDIR "/usr/local/share/qemu"
568
569#if defined(__x86_64__)
570#define HOST_X86_64 1
571#define HOST_LONG_BITS 64
572#elif defined(__i386__)
573#define HOST_I386 1
574#define HOST_LONG_BITS 32
575#else
576#error Unknown architecture for codegen
577#endif
578
579EOF
580
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800581if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200582 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
583fi
584if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
585 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800586fi
David Turner80dd1262010-09-09 18:04:49 +0200587if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
588 echo "#define CONFIG_FNMATCH 1" >> $config_h
589fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800590echo "#define CONFIG_GDBSTUB 1" >> $config_h
591echo "#define CONFIG_SLIRP 1" >> $config_h
592echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200593echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700594
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200595case "$TARGET_OS" in
596 windows)
597 echo "#define CONFIG_WIN32 1" >> $config_h
598 ;;
599 *)
600 echo "#define CONFIG_POSIX 1" >> $config_h
601 ;;
602esac
603
604case "$TARGET_OS" in
605 linux-*)
606 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
607 ;;
608esac
609
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700610# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700611case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700612 linux-*)
613 echo "#define CONFIG_FDATASYNC 1" >> $config_h
614 ;;
615esac
616
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200617case "$TARGET_OS" in
618 linux-*|darwin-*)
619 echo "#define CONFIG_MADVISE 1" >> $config_h
620 ;;
621esac
622
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800623# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700624if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800625 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
626fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700627echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
628echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800629case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200630 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800631 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200632 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800633 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200634 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800635 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200636 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800637 ;;
638esac
Marcus Comstedt17d31322010-10-05 21:54:12 +0200639if [ "$HOST_BIGENDIAN" = "1" ] ; then
640 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
641fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200642BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700643case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200644 linux-*) CONFIG_OS=LINUX
645 ;;
646 darwin-*) CONFIG_OS=DARWIN
647 BSD=1
648 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100649 freebsd-*) CONFIG_OS=FREEBSD
650 BSD=1
651 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200652 windows*) CONFIG_OS=WIN32
653 ;;
654 *) CONFIG_OS=$OS
655esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700656
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800657if [ "$OPTION_STATIC" = "yes" ] ; then
658 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
659 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
660fi
661
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700662case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700663 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800664 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700665 ;;
666esac
667
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200668echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
669if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700670 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200671 echo "#define O_LARGEFILE 0" >> $config_h
672 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
673fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700674
David 'Digit' Turner494b1292014-02-05 15:02:04 +0100675case "$TARGET_OS" in
676 linux-*)
677 echo "#define CONFIG_SIGNALFD 1" >> $config_h
678 ;;
679esac
680
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700681echo "#define CONFIG_ANDROID 1" >> $config_h
682
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800683log "Generate : $config_h"
684
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100685# Generate the QAPI headers and sources from qapi-schema.json
686# Ideally, this would be done in our Makefiles, but as far as I
687# understand, the platform build doesn't support a single tool
688# that generates several sources files, nor the standalone one.
689export PYTHONDONTWRITEBYTECODE=1
690AUTOGENERATED_DIR=qapi-auto-generated
691python scripts/qapi-types.py qapi.types --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
692python scripts/qapi-visit.py --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
693python scripts/qapi-commands.py --output-dir=$AUTOGENERATED_DIR -m < qapi-schema.json
694log "Generate : $AUTOGENERATED_DIR"
695
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800696echo "Ready to go. Type 'make' to build emulator"