blob: 5ebb99efceb696b2ce283786a4792d42e958e519 [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
106 HOST_CC=`dirname $0`/../../prebuilts/tools/gcc-sdk/gcc
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100107 if [ -f "$HOST_CC" ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700108 echo "Using prebuilt toolchain: $HOST_CC"
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100109 CC="$HOST_CC"
110 fi
111fi
112
David 'Digit' Turnerba313e02011-02-09 16:01:53 +0100113echo "OPTION_CC='$OPTION_CC'"
114if [ -n "$OPTION_CC" ]; then
115 echo "Using specified C compiler: $OPTION_CC"
116 CC="$OPTION_CC"
117fi
118
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700119if [ -z "$CC" ]; then
120 CC=$HOST_CC
121fi
122
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100123# By default, generate 32-bit binaries, the Makefile have targets that
124# generate 64-bit ones by using -m64 on the command-line.
125force_32bit_binaries
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800126
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200127case $OS in
128 linux-*)
129 TARGET_DLL_SUFFIX=.so
130 ;;
131 darwin-*)
132 TARGET_DLL_SUFFIX=.dylib
133 ;;
134 windows*)
135 TARGET_DLL_SUFFIX=.dll
136esac
137
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700138TARGET_OS=$OS
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200139if [ "$OPTION_MINGW" = "yes" ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700140 enable_linux_mingw
141 TARGET_OS=windows
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200142 TARGET_DLL_SUFFIX=.dll
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700143else
144 enable_cygwin
145fi
146
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200147# Are we running in the Android build system ?
148check_android_build
149
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800150
151# Adjust a few things when we're building within the Android build
152# system:
153# - locate prebuilt directory
154# - locate and use prebuilt libraries
155# - copy the new binary to the correct location
156#
157if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then
158 IN_ANDROID_BUILD=no
159fi
160
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200161# This is the list of static and shared host libraries we need to link
162# against in order to support OpenGLES emulation properly. Note that in
163# the case of a standalone build, we will find these libraries inside the
164# platform build tree and copy them into objs/lib/ automatically, unless
165# you use --gles-libs to point explicitely to a different directory.
166#
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100167GLES_SHARED_LIBRARIES="\
168 libOpenglRender \
169 libGLES_CM_translator \
170 libGLES_V2_translator \
171 libEGL_translator"
172
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100173if [ "$OPTION_MINGW" != "yes" ]; then
David 'Digit' Turnerf6f50072014-01-14 14:39:13 +0100174 # There are no 64-bit libraries for Windows yet!
175 GLES_SHARED_LIBRARIES="$GLES_SHARED_LIBRARIES \
176 lib64OpenglRender \
177 lib64GLES_CM_translator \
178 lib64GLES_V2_translator \
179 lib64EGL_translator"
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700180fi
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200181
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800182if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200183 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800184
185 # use ccache if USE_CCACHE is defined and the corresponding
186 # binary is available.
187 #
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800188 if [ -n "$USE_CCACHE" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200189 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800190 if [ ! -f $CCACHE ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700191 CCACHE="$ANDROID_PREBUILTS/ccache/ccache$EXE"
192 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800193 fi
194
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800195 # finally ensure that our new binary is copied to the 'out'
196 # subdirectory as 'emulator'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200197 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200198 if [ "$TARGET_OS" = "windows" ]; then
199 HOST_BIN=$(echo $HOST_BIN | sed "s%$OS/bin%windows/bin%")
200 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800201 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200202 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
203 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800204 fi
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800205
206 # find the Android SDK Tools revision number
207 TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties
208 if [ -f $TOOLS_PROPS ] ; then
209 ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null`
210 log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION"
211 else
212 log "Tools : Could not locate $TOOLS_PROPS !?"
213 fi
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200214
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100215 GLES_PROBE_LIB_DIR=$(dirname "$HOST_BIN")/lib
216 case $GLES_PROBE_LIB_DIR in
217 */windows/lib)
218 GLES_PROBE_LIB_DIR=${GLES_PROBE_LIB_DIR%%/windows/lib}/windows-x86/lib
219 ;;
220 esac
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700221else
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100222 if [ -n "$USE_CCACHE" ]; then
223 CCACHE=$(which ccache 2>/dev/null)
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100224 fi
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100225 GLES_PROBE_OS=$TARGET_OS
226 if [ "$GLES_PROBE_OS" = "windows" ]; then
227 GLES_PROBE_OS=windows-x86
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700228 fi
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100229 GLES_PROBE_LIB_DIR=../../out/host/$GLES_PROBE_OS/lib
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800230fi # IN_ANDROID_BUILD = no
231
David 'Digit' Turner6aff02b2014-02-18 12:45:57 +0100232if [ -n "$CCACHE" -a -f "$CCACHE" ] ; then
233 CC="$CCACHE $CC"
234 log "Prebuilt : CCACHE=$CCACHE"
235else
236 log "Prebuilt : CCACHE can't be found"
237 CCACHE=
238fi
239
240# Try to find the GLES emulation headers and libraries automatically
241if [ "$GLES_PROBE" = "yes" ]; then
242 GLES_SUPPORT=yes
243 if [ -z "$GLES_LIBS" ]; then
244 log "GLES : Probing for host libraries"
245 GLES_LIBS=$GLES_PROBE_LIB_DIR
246 if [ -d "$GLES_LIBS" ]; then
247 echo "GLES : Libs in $GLES_LIBS"
248 else
249 echo "Warning: Could nof find OpenGLES emulation libraries in: $GLES_LIBS"
250 GLES_SUPPORT=no
251 fi
252 fi
253fi
254
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200255if [ "$GLES_SUPPORT" = "yes" ]; then
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200256 mkdir -p objs/lib
257
258 for lib in $GLES_SHARED_LIBRARIES; do
259 GLES_LIB=$GLES_LIBS/${lib}$TARGET_DLL_SUFFIX
260 if [ ! -f "$GLES_LIB" ]; then
261 echo "ERROR: Missing OpenGLES emulation host library: $GLES_LIB"
262 echo "Please fix this by using --gles-libs to point to the right directory!"
263 if [ "$IN_ANDROID_BUILD" = "true" ]; then
264 echo "You might also be missing the library because you forgot to rebuild the whole platform!"
265 fi
266 exit 1
267 fi
268 cp $GLES_LIB objs/lib
269 if [ $? != 0 ]; then
270 echo "ERROR: Could not find required OpenGLES emulation library: $GLES_LIB"
271 exit 1
272 else
273 log "GLES : Copying $GLES_LIB"
274 fi
275 done
276fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800277
David 'Digit' Turnera07421f2014-01-18 14:26:43 +0100278# For OS X, detect the location of the SDK to use.
279if [ "$HOST_OS" = darwin ]; then
280 OSX_VERSION=$(sw_vers -productVersion)
281 OSX_SDK_SUPPORTED="10.6 10.7 10.8"
282 OSX_SDK_INSTALLED_LIST=$(xcodebuild -showsdks 2>/dev/null | grep macosx | sed -e "s/.*macosx//g" | sort -n)
283 if [ -z "$OSX_SDK_INSTALLED_LIST" ]; then
284 echo "ERROR: Please install XCode on this machine!"
285 exit 1
286 fi
287 log "OSX: Installed SDKs: $OSX_SDK_INSTALLED_LIST"
288
289 OSX_SDK_VERSION=$(echo "$OSX_SDK_INSTALLED_LIST" | tr ' ' '\n' | head -1)
290 log "OSX: Using SDK version $OSX_SDK_VERSION"
291
292 XCODE_PATH=$(xcode-select -print-path 2>/dev/null)
293 log "OSX: XCode path: $XCODE_PATH"
294
295 OSX_SDK_ROOT=$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk
296 log "OSX: Looking for $OSX_SDK_ROOT"
297 if [ ! -d "$OSX_SDK_ROOT" ]; then
298 OSX_SDK_ROOT=/Developer/SDKs/MaxOSX${OSX_SDK_VERSION}.sdk
299 log "OSX: Looking for $OSX_SDK_ROOT"
300 if [ ! -d "$OSX_SDK_ROOT" ]; then
301 echo "ERROR: Could not find SDK $OSX_SDK_VERSION at $OSX_SDK_ROOT"
302 exit 1
303 fi
304 fi
305 echo "OSX SDK : Found at $OSX_SDK_ROOT"
306fi
307
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200308# we can build the emulator with Cygwin, so enable it
309enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800310
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200311setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800312
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800313###
314### SDL Probe
315###
316
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700317if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200318
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700319 # check that we can link statically with the library.
320 #
321 SDL_CFLAGS=`$SDL_CONFIG --cflags`
322 SDL_LIBS=`$SDL_CONFIG --static-libs`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800323
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700324 # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
Deepanshu Guptabb761912013-05-28 16:36:40 -0700325 # since they break recent Mingw releases
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700326 SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800327
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700328 log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
329 log "SDL-probe : SDL_LIBS = $SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800330
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800331
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700332 EXTRA_CFLAGS="$SDL_CFLAGS"
333 EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800334
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700335 case "$OS" in
336 freebsd-*)
337 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread"
338 ;;
339 esac
Alexey Tarasov08823222009-09-01 02:07:51 +1100340
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700341 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800342#include <SDL.h>
343#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200344int main( int argc, char** argv ) {
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200345 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800346}
347EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700348 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200349
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700350 if [ $SDL_LINKING != "yes" ] ; then
351 echo "You provided an explicit sdl-config script, but the corresponding library"
352 echo "cannot be statically linked with the Android emulator directly."
353 echo "Error message:"
354 cat $TMPL
355 clean_exit
356 fi
357 log "SDL-probe : static linking ok"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800358
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700359 # now, let's check that the SDL library has the special functions
360 # we added to our own sources
361 #
362 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800363#include <SDL.h>
364#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200365int main( int argc, char** argv ) {
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700366 int x, y;
367 SDL_Rect r;
368 SDL_WM_GetPos(&x, &y);
369 SDL_WM_SetPos(x, y);
370 SDL_WM_GetMonitorDPI(&x, &y);
371 SDL_WM_GetMonitorRect(&r);
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200372 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800373}
374EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700375 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200376
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700377 if [ $SDL_LINKING != "yes" ] ; then
378 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
379 echo "corresponding library doesn't have the patches required to link"
380 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
381 echo "sources bundled with the emulator instead"
382 echo "Error:"
383 cat $TMPL
384 clean_exit
385 fi
386
387 log "SDL-probe : extra features ok"
388 clean_temp
389
390 EXTRA_CFLAGS=
391 EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800392fi
393
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800394###
395### Audio subsystems probes
396###
397PROBE_COREAUDIO=no
398PROBE_ALSA=no
399PROBE_OSS=no
400PROBE_ESD=no
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700401PROBE_PULSEAUDIO=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800402PROBE_WINAUDIO=no
403
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700404case "$TARGET_OS" in
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800405 darwin*) PROBE_COREAUDIO=yes;
406 ;;
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700407 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800408 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100409 freebsd-*) PROBE_OSS=yes;
410 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800411 windows) PROBE_WINAUDIO=yes
412 ;;
413esac
414
415ORG_CFLAGS=$CFLAGS
416ORG_LDFLAGS=$LDFLAGS
417
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200418if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then
419PROBE_ESD_ESD=no
420PROBE_ALSA=no
421PROBE_PULSEAUDIO=no
422fi
423
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700424# Probe a system library
425#
426# $1: Variable name (e.g. PROBE_ESD)
427# $2: Library name (e.g. "Alsa")
428# $3: Path to source file for probe program (e.g. android/config/check-alsa.c)
429# $4: Package name (e.g. libasound-dev)
430#
431probe_system_library ()
432{
433 if [ `var_value $1` = yes ] ; then
434 CFLAGS="$ORG_CFLAGS"
435 LDFLAGS="$ORG_LDFLAGS -ldl"
436 cp -f android/config/check-esd.c $TMPC
David 'Digit' Turnera7ef1ac2010-12-10 22:33:51 +0100437 compile
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700438 if [ $? = 0 ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200439 log "AudioProbe : $2 seems to be usable on this system"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700440 else
441 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200442 echo "The $2 development files do not seem to be installed on this system"
443 echo "Are you missing the $4 package ?"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700444 echo "Correct the errors below and try again:"
445 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"