blob: bfc8e3fce6e65a5e451892e47df95a603b5781c7 [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
23OPTION_TRY_64=no
24OPTION_HELP=no
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080025OPTION_STATIC=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070026OPTION_MINGW=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080027
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +020028GLES_INCLUDE=
29GLES_LIBS=
30GLES_SUPPORT=no
31GLES_PROBE=yes
32
David 'Digit' Turnere3650682010-12-22 14:44:19 +010033HOST_CC=${CC:-gcc}
34OPTION_CC=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080035
David 'Digit' Turner5b2e7c42011-02-07 18:51:07 +010036TARGET_ARCH=arm
37
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080038for opt do
39 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
40 case "$opt" in
41 --help|-h|-\?) OPTION_HELP=yes
42 ;;
43 --verbose)
44 if [ "$VERBOSE" = "yes" ] ; then
45 VERBOSE2=yes
46 else
47 VERBOSE=yes
48 fi
49 ;;
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +020050 --debug) OPTION_DEBUG=yes
51 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +020052 --install=*) OPTION_TARGETS="$OPTION_TARGETS $optarg";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080053 ;;
54 --sdl-config=*) SDL_CONFIG=$optarg
55 ;;
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070056 --mingw) OPTION_MINGW=yes
57 ;;
David 'Digit' Turnere3650682010-12-22 14:44:19 +010058 --cc=*) OPTION_CC="$optarg"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080059 ;;
60 --no-strip) OPTION_NO_STRIP=yes
61 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080062 --ignore-audio) OPTION_IGNORE_AUDIO=yes
63 ;;
64 --no-prebuilts) OPTION_NO_PREBUILTS=yes
65 ;;
66 --try-64) OPTION_TRY_64=yes
67 ;;
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080068 --static) OPTION_STATIC=yes
69 ;;
David 'Digit' Turner5b2e7c42011-02-07 18:51:07 +010070 --arch=*) TARGET_ARCH=$optarg
71 ;;
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +020072 --gles-include=*) GLES_INCLUDE=$optarg
73 GLES_SUPPORT=yes
74 ;;
75 --gles-libs=*) GLES_LIBS=$optarg
76 GLES_SUPPORT=yes
77 ;;
78 --no-gles) GLES_PROBE=no
79 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080080 *)
81 echo "unknown option '$opt', use --help"
82 exit 1
83 esac
84done
85
86# Print the help message
87#
88if [ "$OPTION_HELP" = "yes" ] ; then
89 cat << EOF
90
91Usage: rebuild.sh [options]
92Options: [defaults in brackets after descriptions]
93EOF
94 echo "Standard options:"
95 echo " --help print this message"
96 echo " --install=FILEPATH copy emulator executable to FILEPATH [$TARGETS]"
David 'Digit' Turnere3650682010-12-22 14:44:19 +010097 echo " --cc=PATH specify C compiler [$HOST_CC]"
David 'Digit' Turner5b2e7c42011-02-07 18:51:07 +010098 echo " --arch=ARM specify target architecture [$TARGET_ARCH]"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080099 echo " --sdl-config=FILE use specific sdl-config script [$SDL_CONFIG]"
100 echo " --no-strip do not strip emulator executable"
101 echo " --debug enable debug (-O0 -g) build"
102 echo " --ignore-audio ignore audio messages (may build sound-less emulator)"
103 echo " --no-prebuilts do not use prebuilt libraries and compiler"
104 echo " --try-64 try to build a 64-bit executable (may crash)"
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700105 echo " --mingw build Windows executable on Linux"
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800106 echo " --static build a completely static executable"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800107 echo " --verbose verbose configuration"
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200108 echo " --debug build debug version of the emulator"
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200109 echo " --gles-include=PATH specify path to GLES emulation headers"
110 echo " --gles-libs=PATH specify path to GLES emulation host libraries"
111 echo " --no-gles disable GLES emulation support"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800112 echo ""
113 exit 1
114fi
115
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700116# On Linux, try to use our prebuilt toolchain to generate binaries
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100117# that are compatible with Ubuntu 8.04
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700118if [ -z "$CC" -a -z "$OPTION_CC" -a "$HOST_OS" = linux ] ; then
119 HOST_CC=`dirname $0`/../../prebuilts/tools/gcc-sdk/gcc
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100120 if [ -f "$HOST_CC" ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700121 echo "Using prebuilt toolchain: $HOST_CC"
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100122 CC="$HOST_CC"
123 fi
124fi
125
David 'Digit' Turnerba313e02011-02-09 16:01:53 +0100126echo "OPTION_CC='$OPTION_CC'"
127if [ -n "$OPTION_CC" ]; then
128 echo "Using specified C compiler: $OPTION_CC"
129 CC="$OPTION_CC"
130fi
131
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700132if [ -z "$CC" ]; then
133 CC=$HOST_CC
134fi
135
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200136# we only support generating 32-bit binaris on 64-bit systems.
137# And we may need to add a -Wa,--32 to CFLAGS to let the assembler
138# generate 32-bit binaries on Linux x86_64.
139#
140if [ "$OPTION_TRY_64" != "yes" ] ; then
141 force_32bit_binaries
142fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800143
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200144case $OS in
145 linux-*)
146 TARGET_DLL_SUFFIX=.so
147 ;;
148 darwin-*)
149 TARGET_DLL_SUFFIX=.dylib
150 ;;
151 windows*)
152 TARGET_DLL_SUFFIX=.dll
153esac
154
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700155TARGET_OS=$OS
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200156if [ "$OPTION_MINGW" = "yes" ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700157 enable_linux_mingw
158 TARGET_OS=windows
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200159 TARGET_DLL_SUFFIX=.dll
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700160else
161 enable_cygwin
162fi
163
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200164# Are we running in the Android build system ?
165check_android_build
166
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800167
168# Adjust a few things when we're building within the Android build
169# system:
170# - locate prebuilt directory
171# - locate and use prebuilt libraries
172# - copy the new binary to the correct location
173#
174if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then
175 IN_ANDROID_BUILD=no
176fi
177
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200178# This is the list of static and shared host libraries we need to link
179# against in order to support OpenGLES emulation properly. Note that in
180# the case of a standalone build, we will find these libraries inside the
181# platform build tree and copy them into objs/lib/ automatically, unless
182# you use --gles-libs to point explicitely to a different directory.
183#
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700184if [ "$OPTION_TRY_64" != "yes" ] ; then
185 GLES_SHARED_LIBRARIES="libOpenglRender libGLES_CM_translator libGLES_V2_translator libEGL_translator"
186else
187 GLES_SHARED_LIBRARIES="lib64OpenglRender lib64GLES_CM_translator lib64GLES_V2_translator lib64EGL_translator"
188fi
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200189
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800190if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200191 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800192
193 # use ccache if USE_CCACHE is defined and the corresponding
194 # binary is available.
195 #
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800196 if [ -n "$USE_CCACHE" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200197 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800198 if [ ! -f $CCACHE ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700199 CCACHE="$ANDROID_PREBUILTS/ccache/ccache$EXE"
200 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800201 if [ -f $CCACHE ] ; then
202 CC="$CCACHE $CC"
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700203 log "Prebuilt : CCACHE=$CCACHE"
204 else
205 log "Prebuilt : CCACHE can't be found"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800206 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800207 fi
208
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800209 # finally ensure that our new binary is copied to the 'out'
210 # subdirectory as 'emulator'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200211 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200212 if [ "$TARGET_OS" = "windows" ]; then
213 HOST_BIN=$(echo $HOST_BIN | sed "s%$OS/bin%windows/bin%")
214 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800215 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200216 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
217 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800218 fi
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800219
220 # find the Android SDK Tools revision number
221 TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties
222 if [ -f $TOOLS_PROPS ] ; then
223 ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null`
224 log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION"
225 else
226 log "Tools : Could not locate $TOOLS_PROPS !?"
227 fi
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200228
229 # Try to find the GLES emulation headers and libraries automatically
230 if [ "$GLES_PROBE" = "yes" ]; then
231 GLES_SUPPORT=yes
232 if [ -z "$GLES_INCLUDE" ]; then
233 log "GLES : Probing for headers"
Jesse Hall183e9272012-04-26 15:13:27 -0700234 GLES_INCLUDE=$ANDROID_TOP/sdk/emulator/opengl/host/include
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200235 if [ -d "$GLES_INCLUDE" ]; then
236 log "GLES : Headers in $GLES_INCLUDE"
237 else
238 echo "Warning: Could not find OpenGLES emulation include dir: $GLES_INCLUDE"
239 echo "Disabling GLES emulation from this build!"
240 GLES_SUPPORT=no
241 fi
242 fi
243 if [ -z "$GLES_LIBS" ]; then
244 log "GLES : Probing for host libraries"
245 GLES_LIBS=$(dirname "$HOST_BIN")/lib
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 echo "Disabling GLES emulation from this build!"
251 GLES_SUPPORT=no
252 fi
253 fi
254 fi
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700255else
256 if [ "$GLES_PROBE" = "yes" ]; then
257 GLES_SUPPORT=yes
258 if [ -z "$GLES_INCLUDE" ]; then
259 log "GLES : Probing for headers"
260 GLES_INCLUDE=../../sdk/emulator/opengl/host/include
261 if [ -d "$GLES_INCLUDE" ]; then
262 log "GLES : Headers in $GLES_INCLUDE"
263 else
264 echo "Warning: Could not find OpenGLES emulation include dir: $GLES_INCLUDE"
265 echo "Disabling GLES emulation from this build!"
266 GLES_SUPPORT=no
267 fi
268 fi
269 if [ -z "$GLES_LIBS" ]; then
270 log "GLES : Probing for host libraries"
271 GLES_LIBS=../../out/host/$OS/lib
272 if [ -d "$GLES_LIBS" ]; then
273 echo "GLES : Libs in $GLES_LIBS"
274 else
275 echo "Warning: Could nof find OpenGLES emulation libraries in: $GLES_LIBS"
276 echo "Disabling GLES emulation from this build!"
277 GLES_SUPPORT=no
278 fi
279 fi
280 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800281fi # IN_ANDROID_BUILD = no
282
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200283if [ "$GLES_SUPPORT" = "yes" ]; then
284 if [ -z "$GLES_INCLUDE" -o -z "$GLES_LIBS" ]; then
285 echo "ERROR: You must use both --gles-include and --gles-libs at the same time!"
286 echo " Or use --no-gles to disable its support from this build."
287 exit 1
288 fi
289
290 GLES_HEADER=$GLES_INCLUDE/libOpenglRender/render_api.h
291 if [ ! -f "$GLES_HEADER" ]; then
292 echo "ERROR: Missing OpenGLES emulation header file: $GLES_HEADER"
293 echo "Please fix this by using --gles-include to point to the right directory!"
294 exit 1
295 fi
296
297 mkdir -p objs/lib
298
299 for lib in $GLES_SHARED_LIBRARIES; do
300 GLES_LIB=$GLES_LIBS/${lib}$TARGET_DLL_SUFFIX
301 if [ ! -f "$GLES_LIB" ]; then
302 echo "ERROR: Missing OpenGLES emulation host library: $GLES_LIB"
303 echo "Please fix this by using --gles-libs to point to the right directory!"
304 if [ "$IN_ANDROID_BUILD" = "true" ]; then
305 echo "You might also be missing the library because you forgot to rebuild the whole platform!"
306 fi
307 exit 1
308 fi
309 cp $GLES_LIB objs/lib
310 if [ $? != 0 ]; then
311 echo "ERROR: Could not find required OpenGLES emulation library: $GLES_LIB"
312 exit 1
313 else
314 log "GLES : Copying $GLES_LIB"
315 fi
316 done
317fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800318
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200319# we can build the emulator with Cygwin, so enable it
320enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800321
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200322setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800323
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800324###
325### SDL Probe
326###
327
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700328if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200329
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700330 # check that we can link statically with the library.
331 #
332 SDL_CFLAGS=`$SDL_CONFIG --cflags`
333 SDL_LIBS=`$SDL_CONFIG --static-libs`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800334
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700335 # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
Deepanshu Guptabb761912013-05-28 16:36:40 -0700336 # since they break recent Mingw releases
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700337 SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800338
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700339 log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
340 log "SDL-probe : SDL_LIBS = $SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800341
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800342
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700343 EXTRA_CFLAGS="$SDL_CFLAGS"
344 EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800345
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700346 case "$OS" in
347 freebsd-*)
348 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread"
349 ;;
350 esac
Alexey Tarasov08823222009-09-01 02:07:51 +1100351
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700352 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800353#include <SDL.h>
354#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200355int main( int argc, char** argv ) {
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200356 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800357}
358EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700359 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200360
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700361 if [ $SDL_LINKING != "yes" ] ; then
362 echo "You provided an explicit sdl-config script, but the corresponding library"
363 echo "cannot be statically linked with the Android emulator directly."
364 echo "Error message:"
365 cat $TMPL
366 clean_exit
367 fi
368 log "SDL-probe : static linking ok"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800369
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700370 # now, let's check that the SDL library has the special functions
371 # we added to our own sources
372 #
373 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800374#include <SDL.h>
375#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200376int main( int argc, char** argv ) {
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700377 int x, y;
378 SDL_Rect r;
379 SDL_WM_GetPos(&x, &y);
380 SDL_WM_SetPos(x, y);
381 SDL_WM_GetMonitorDPI(&x, &y);
382 SDL_WM_GetMonitorRect(&r);
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200383 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800384}
385EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700386 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200387
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700388 if [ $SDL_LINKING != "yes" ] ; then
389 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
390 echo "corresponding library doesn't have the patches required to link"
391 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
392 echo "sources bundled with the emulator instead"
393 echo "Error:"
394 cat $TMPL
395 clean_exit
396 fi
397
398 log "SDL-probe : extra features ok"
399 clean_temp
400
401 EXTRA_CFLAGS=
402 EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800403fi
404
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800405###
406### Audio subsystems probes
407###
408PROBE_COREAUDIO=no
409PROBE_ALSA=no
410PROBE_OSS=no
411PROBE_ESD=no
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700412PROBE_PULSEAUDIO=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800413PROBE_WINAUDIO=no
414
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700415case "$TARGET_OS" in
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800416 darwin*) PROBE_COREAUDIO=yes;
417 ;;
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700418 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800419 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100420 freebsd-*) PROBE_OSS=yes;
421 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800422 windows) PROBE_WINAUDIO=yes
423 ;;
424esac
425
426ORG_CFLAGS=$CFLAGS
427ORG_LDFLAGS=$LDFLAGS
428
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200429if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then
430PROBE_ESD_ESD=no
431PROBE_ALSA=no
432PROBE_PULSEAUDIO=no
433fi
434
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700435# Probe a system library
436#
437# $1: Variable name (e.g. PROBE_ESD)
438# $2: Library name (e.g. "Alsa")
439# $3: Path to source file for probe program (e.g. android/config/check-alsa.c)
440# $4: Package name (e.g. libasound-dev)
441#
442probe_system_library ()
443{
444 if [ `var_value $1` = yes ] ; then
445 CFLAGS="$ORG_CFLAGS"
446 LDFLAGS="$ORG_LDFLAGS -ldl"
447 cp -f android/config/check-esd.c $TMPC
David 'Digit' Turnera7ef1ac2010-12-10 22:33:51 +0100448 compile
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700449 if [ $? = 0 ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200450 log "AudioProbe : $2 seems to be usable on this system"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700451 else
452 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200453 echo "The $2 development files do not seem to be installed on this system"
454 echo "Are you missing the $4 package ?"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700455 echo "Correct the errors below and try again:"
456 cat $TMPL
457 clean_exit
458 fi
459 eval $1=no
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200460 log "AudioProbe : $2 seems to be UNUSABLE on this system !!"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800461 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800462 fi
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700463}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800464
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700465probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev
466probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev
467probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800468
469CFLAGS=$ORG_CFLAGS
470LDFLAGS=$ORG_LDFLAGS
471
472# create the objs directory that is going to contain all generated files
473# including the configuration ones
474#
475mkdir -p objs
476
477###
478### Compiler probe
479###
480
481####
482#### Host system probe
483####
484
485# because the previous version could be read-only
486rm -f $TMPC
487
488# check host endianess
489#
490HOST_BIGENDIAN=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700491if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800492cat > $TMPC << EOF
493#include <inttypes.h>
494int main(int argc, char ** argv){
495 volatile uint32_t i=0x01234567;
Marcus Comstedt17d31322010-10-05 21:54:12 +0200496 return (*((uint8_t*)(&i))) == 0x01;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800497}
498EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200499feature_run_exec HOST_BIGENDIAN
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700500fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800501
502# check size of host long bits
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700503HOST_LONGBITS=32
504if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800505cat > $TMPC << EOF
506int main(void) {
507 return sizeof(void*)*8;
508}
509EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200510feature_run_exec HOST_LONGBITS
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700511fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800512
513# check whether we have <byteswap.h>
514#
David Turnerb8fec3e2010-09-09 18:15:23 +0200515feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
516feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
517feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
David Turner80dd1262010-09-09 18:04:49 +0200518
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800519# Build the config.make file
520#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200521
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200522case $TARGET_OS in
523 windows)
524 TARGET_EXEEXT=.exe
525 ;;
526 *)
527 TARGET_EXEEXT=
528 ;;
529esac
530
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200531create_config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700532echo "" >> $config_mk
Jun Nakajima334ab472011-02-02 23:49:59 -0800533if [ $TARGET_ARCH = arm ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700534echo "TARGET_ARCH := arm" >> $config_mk
Jun Nakajima334ab472011-02-02 23:49:59 -0800535fi
536
537if [ $TARGET_ARCH = x86 ] ; then
538echo "TARGET_ARCH := x86" >> $config_mk
539fi
540
Bhanu Chetlapalli741dc132012-05-08 17:16:03 -0700541if [ $TARGET_ARCH = mips ] ; then
542echo "TARGET_ARCH := mips" >> $config_mk
543fi
544
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700545echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200546echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700547echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700548echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200549
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800550PWD=`pwd`
551echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700552if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200553echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700554fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800555echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
556echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
557echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
558echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
559echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700560echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800561echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200562if [ $OPTION_DEBUG = yes ] ; then
563 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
564fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800565if [ $OPTION_STATIC = yes ] ; then
566 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
567fi
568
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800569if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
570 echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
571fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800572
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700573if [ "$OPTION_MINGW" = "yes" ] ; then
574 echo "" >> $config_mk
575 echo "USE_MINGW := 1" >> $config_mk
576 echo "HOST_OS := windows" >> $config_mk
577fi
578
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200579if [ "$GLES_INCLUDE" -a "$GLES_LIBS" ]; then
580 echo "QEMU_OPENGLES_INCLUDE := $GLES_INCLUDE" >> $config_mk
581 echo "QEMU_OPENGLES_LIBS := $GLES_LIBS" >> $config_mk
582fi
583
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800584# Build the config-host.h file
585#
586config_h=objs/config-host.h
587echo "/* This file was autogenerated by '$PROGNAME' */" > $config_h
588echo "#define CONFIG_QEMU_SHAREDIR \"/usr/local/share/qemu\"" >> $config_h
589echo "#define HOST_LONG_BITS $HOST_LONGBITS" >> $config_h
590if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200591 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
592fi
593if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
594 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800595fi
David Turner80dd1262010-09-09 18:04:49 +0200596if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
597 echo "#define CONFIG_FNMATCH 1" >> $config_h
598fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800599echo "#define CONFIG_GDBSTUB 1" >> $config_h
600echo "#define CONFIG_SLIRP 1" >> $config_h
601echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200602echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700603
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200604case "$TARGET_OS" in
605 windows)
606 echo "#define CONFIG_WIN32 1" >> $config_h
607 ;;
608 *)
609 echo "#define CONFIG_POSIX 1" >> $config_h
610 ;;
611esac
612
613case "$TARGET_OS" in
614 linux-*)
615 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
616 ;;
617esac
618
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700619# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700620case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700621 linux-*)
622 echo "#define CONFIG_FDATASYNC 1" >> $config_h
623 ;;
624esac
625
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200626case "$TARGET_OS" in
627 linux-*|darwin-*)
628 echo "#define CONFIG_MADVISE 1" >> $config_h
629 ;;
630esac
631
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800632# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700633if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800634 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
635fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700636echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
637echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800638case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200639 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800640 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200641 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800642 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200643 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800644 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200645 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800646 ;;
647esac
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200648echo "#define HOST_$CONFIG_CPU 1" >> $config_h
Marcus Comstedt17d31322010-10-05 21:54:12 +0200649if [ "$HOST_BIGENDIAN" = "1" ] ; then
650 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
651fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200652BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700653case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200654 linux-*) CONFIG_OS=LINUX
655 ;;
656 darwin-*) CONFIG_OS=DARWIN
657 BSD=1
658 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100659 freebsd-*) CONFIG_OS=FREEBSD
660 BSD=1
661 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200662 windows*) CONFIG_OS=WIN32
663 ;;
664 *) CONFIG_OS=$OS
665esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700666
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800667if [ "$OPTION_STATIC" = "yes" ] ; then
668 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
669 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
670fi
671
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700672case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700673 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800674 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700675 ;;
676esac
677
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200678echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
679if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700680 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200681 echo "#define O_LARGEFILE 0" >> $config_h
682 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
683fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700684
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700685echo "#define CONFIG_ANDROID 1" >> $config_h
686
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200687if [ "$GLES_INCLUDE" -a "$GLES_LIBS" ]; then
688 echo "#define CONFIG_ANDROID_OPENGLES 1" >> $config_h
689fi
690
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800691log "Generate : $config_h"
692
693echo "Ready to go. Type 'make' to build emulator"