blob: 1f2c4d1339d5d4c718751669f61477839e66e291 [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' Turnerd2c08522014-02-26 15:45:47 +0100221 if [ "$USE_CCACHE" != 0 ]; then
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100222 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
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100451 clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800452 fi
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700453}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800454
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700455probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev
456probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev
457probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800458
459CFLAGS=$ORG_CFLAGS
460LDFLAGS=$ORG_LDFLAGS
461
462# create the objs directory that is going to contain all generated files
463# including the configuration ones
464#
465mkdir -p objs
466
467###
468### Compiler probe
469###
470
471####
472#### Host system probe
473####
474
475# because the previous version could be read-only
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100476clean_temp
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800477
478# check host endianess
479#
480HOST_BIGENDIAN=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700481if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800482cat > $TMPC << EOF
483#include <inttypes.h>
484int main(int argc, char ** argv){
485 volatile uint32_t i=0x01234567;
Marcus Comstedt17d31322010-10-05 21:54:12 +0200486 return (*((uint8_t*)(&i))) == 0x01;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800487}
488EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200489feature_run_exec HOST_BIGENDIAN
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700490fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800491
492# check size of host long bits
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700493HOST_LONGBITS=32
494if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800495cat > $TMPC << EOF
496int main(void) {
497 return sizeof(void*)*8;
498}
499EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200500feature_run_exec HOST_LONGBITS
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700501fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800502
503# check whether we have <byteswap.h>
504#
David Turnerb8fec3e2010-09-09 18:15:23 +0200505feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
506feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
507feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
David Turner80dd1262010-09-09 18:04:49 +0200508
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800509# Build the config.make file
510#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200511
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200512case $TARGET_OS in
513 windows)
514 TARGET_EXEEXT=.exe
515 ;;
516 *)
517 TARGET_EXEEXT=
518 ;;
519esac
520
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100521# Strip executables and shared libraries unless --debug is used.
522if [ "$OPTION_DEBUG" != "yes" ]; then
523 case $HOST_OS in
524 darwin)
525 LDFLAGS="$LDFLAGS -Wl,-S"
526 ;;
527 *)
528 LDFLAGS="$LDFLAGS -Wl,--strip-all"
529 ;;
530 esac
531fi
532
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200533create_config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700534echo "" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700535echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200536echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700537echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700538echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200539
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800540PWD=`pwd`
541echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700542if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200543echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700544fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800545echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
546echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
547echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
548echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
549echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700550echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800551echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200552if [ $OPTION_DEBUG = yes ] ; then
553 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
554fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800555if [ $OPTION_STATIC = yes ] ; then
556 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
557fi
558
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800559if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
560 echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
561fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800562
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700563if [ "$OPTION_MINGW" = "yes" ] ; then
564 echo "" >> $config_mk
565 echo "USE_MINGW := 1" >> $config_mk
566 echo "HOST_OS := windows" >> $config_mk
567fi
568
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100569if [ "$HOST_OS" = "darwin" ]; then
570 echo "mac_sdk_root := $OSX_SDK_ROOT" >> $config_mk
571 echo "mac_sdk_version := $OSX_SDK_VERSION" >> $config_mk
572fi
573
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800574# Build the config-host.h file
575#
576config_h=objs/config-host.h
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100577cat > $config_h <<EOF
578/* This file was autogenerated by '$PROGNAME' */
579
580#define CONFIG_QEMU_SHAREDIR "/usr/local/share/qemu"
581
582#if defined(__x86_64__)
583#define HOST_X86_64 1
584#define HOST_LONG_BITS 64
585#elif defined(__i386__)
586#define HOST_I386 1
587#define HOST_LONG_BITS 32
588#else
589#error Unknown architecture for codegen
590#endif
591
592EOF
593
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800594if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200595 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
596fi
597if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
598 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800599fi
David Turner80dd1262010-09-09 18:04:49 +0200600if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
601 echo "#define CONFIG_FNMATCH 1" >> $config_h
602fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800603echo "#define CONFIG_GDBSTUB 1" >> $config_h
604echo "#define CONFIG_SLIRP 1" >> $config_h
605echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200606echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700607
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200608case "$TARGET_OS" in
609 windows)
610 echo "#define CONFIG_WIN32 1" >> $config_h
611 ;;
612 *)
613 echo "#define CONFIG_POSIX 1" >> $config_h
614 ;;
615esac
616
617case "$TARGET_OS" in
618 linux-*)
619 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
620 ;;
621esac
622
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700623# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700624case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700625 linux-*)
626 echo "#define CONFIG_FDATASYNC 1" >> $config_h
627 ;;
628esac
629
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200630case "$TARGET_OS" in
631 linux-*|darwin-*)
632 echo "#define CONFIG_MADVISE 1" >> $config_h
633 ;;
634esac
635
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800636# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700637if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800638 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
639fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700640echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
641echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800642case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200643 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800644 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200645 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800646 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200647 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800648 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200649 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800650 ;;
651esac
Marcus Comstedt17d31322010-10-05 21:54:12 +0200652if [ "$HOST_BIGENDIAN" = "1" ] ; then
653 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
654fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200655BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700656case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200657 linux-*) CONFIG_OS=LINUX
658 ;;
659 darwin-*) CONFIG_OS=DARWIN
660 BSD=1
661 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100662 freebsd-*) CONFIG_OS=FREEBSD
663 BSD=1
664 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200665 windows*) CONFIG_OS=WIN32
666 ;;
667 *) CONFIG_OS=$OS
668esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700669
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800670if [ "$OPTION_STATIC" = "yes" ] ; then
671 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
672 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
673fi
674
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700675case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700676 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800677 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700678 ;;
679esac
680
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200681echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
682if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700683 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200684 echo "#define O_LARGEFILE 0" >> $config_h
685 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
686fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700687
David 'Digit' Turner494b1292014-02-05 15:02:04 +0100688case "$TARGET_OS" in
689 linux-*)
690 echo "#define CONFIG_SIGNALFD 1" >> $config_h
691 ;;
692esac
693
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700694echo "#define CONFIG_ANDROID 1" >> $config_h
695
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800696log "Generate : $config_h"
697
David 'Digit' Turner910aea92014-01-15 16:53:38 +0100698# Generate the QAPI headers and sources from qapi-schema.json
699# Ideally, this would be done in our Makefiles, but as far as I
700# understand, the platform build doesn't support a single tool
701# that generates several sources files, nor the standalone one.
702export PYTHONDONTWRITEBYTECODE=1
703AUTOGENERATED_DIR=qapi-auto-generated
704python scripts/qapi-types.py qapi.types --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
705python scripts/qapi-visit.py --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
706python scripts/qapi-commands.py --output-dir=$AUTOGENERATED_DIR -m < qapi-schema.json
707log "Generate : $AUTOGENERATED_DIR"
708
David 'Digit' Turnerd2c08522014-02-26 15:45:47 +0100709clean_temp
710
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800711echo "Ready to go. Type 'make' to build emulator"