blob: d9ca152cad995d2c56bc5de60b49f91e5d0c8391 [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
David 'Digit' Turner6cf45c12014-01-08 07:18:35 +0100256 if [ -n "$USE_CCACHE" ]; then
257 CCACHE=$(which ccache 2>/dev/null)
258 if [ -n "$CCACHE" -a -f "$CCACHE" ] ; then
259 CC="$CCACHE $CC"
260 log "Prebuilt : CCACHE=$CCACHE"
261 else
262 log "Prebuilt : CCACHE can't be found"
263 fi
264 fi
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700265 if [ "$GLES_PROBE" = "yes" ]; then
266 GLES_SUPPORT=yes
267 if [ -z "$GLES_INCLUDE" ]; then
268 log "GLES : Probing for headers"
269 GLES_INCLUDE=../../sdk/emulator/opengl/host/include
270 if [ -d "$GLES_INCLUDE" ]; then
271 log "GLES : Headers in $GLES_INCLUDE"
272 else
273 echo "Warning: Could not find OpenGLES emulation include dir: $GLES_INCLUDE"
274 echo "Disabling GLES emulation from this build!"
275 GLES_SUPPORT=no
276 fi
277 fi
278 if [ -z "$GLES_LIBS" ]; then
279 log "GLES : Probing for host libraries"
280 GLES_LIBS=../../out/host/$OS/lib
281 if [ -d "$GLES_LIBS" ]; then
282 echo "GLES : Libs in $GLES_LIBS"
283 else
284 echo "Warning: Could nof find OpenGLES emulation libraries in: $GLES_LIBS"
285 echo "Disabling GLES emulation from this build!"
286 GLES_SUPPORT=no
287 fi
288 fi
289 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800290fi # IN_ANDROID_BUILD = no
291
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200292if [ "$GLES_SUPPORT" = "yes" ]; then
293 if [ -z "$GLES_INCLUDE" -o -z "$GLES_LIBS" ]; then
294 echo "ERROR: You must use both --gles-include and --gles-libs at the same time!"
295 echo " Or use --no-gles to disable its support from this build."
296 exit 1
297 fi
298
299 GLES_HEADER=$GLES_INCLUDE/libOpenglRender/render_api.h
300 if [ ! -f "$GLES_HEADER" ]; then
301 echo "ERROR: Missing OpenGLES emulation header file: $GLES_HEADER"
302 echo "Please fix this by using --gles-include to point to the right directory!"
303 exit 1
304 fi
305
306 mkdir -p objs/lib
307
308 for lib in $GLES_SHARED_LIBRARIES; do
309 GLES_LIB=$GLES_LIBS/${lib}$TARGET_DLL_SUFFIX
310 if [ ! -f "$GLES_LIB" ]; then
311 echo "ERROR: Missing OpenGLES emulation host library: $GLES_LIB"
312 echo "Please fix this by using --gles-libs to point to the right directory!"
313 if [ "$IN_ANDROID_BUILD" = "true" ]; then
314 echo "You might also be missing the library because you forgot to rebuild the whole platform!"
315 fi
316 exit 1
317 fi
318 cp $GLES_LIB objs/lib
319 if [ $? != 0 ]; then
320 echo "ERROR: Could not find required OpenGLES emulation library: $GLES_LIB"
321 exit 1
322 else
323 log "GLES : Copying $GLES_LIB"
324 fi
325 done
326fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800327
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200328# we can build the emulator with Cygwin, so enable it
329enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800330
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200331setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800332
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800333###
334### SDL Probe
335###
336
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700337if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200338
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700339 # check that we can link statically with the library.
340 #
341 SDL_CFLAGS=`$SDL_CONFIG --cflags`
342 SDL_LIBS=`$SDL_CONFIG --static-libs`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800343
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700344 # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
Deepanshu Guptabb761912013-05-28 16:36:40 -0700345 # since they break recent Mingw releases
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700346 SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800347
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700348 log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
349 log "SDL-probe : SDL_LIBS = $SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800350
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800351
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700352 EXTRA_CFLAGS="$SDL_CFLAGS"
353 EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800354
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700355 case "$OS" in
356 freebsd-*)
357 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread"
358 ;;
359 esac
Alexey Tarasov08823222009-09-01 02:07:51 +1100360
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700361 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' Turner81f74292010-10-14 18:29:45 +0200365 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800366}
367EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700368 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200369
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700370 if [ $SDL_LINKING != "yes" ] ; then
371 echo "You provided an explicit sdl-config script, but the corresponding library"
372 echo "cannot be statically linked with the Android emulator directly."
373 echo "Error message:"
374 cat $TMPL
375 clean_exit
376 fi
377 log "SDL-probe : static linking ok"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800378
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700379 # now, let's check that the SDL library has the special functions
380 # we added to our own sources
381 #
382 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800383#include <SDL.h>
384#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200385int main( int argc, char** argv ) {
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700386 int x, y;
387 SDL_Rect r;
388 SDL_WM_GetPos(&x, &y);
389 SDL_WM_SetPos(x, y);
390 SDL_WM_GetMonitorDPI(&x, &y);
391 SDL_WM_GetMonitorRect(&r);
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200392 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800393}
394EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700395 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200396
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700397 if [ $SDL_LINKING != "yes" ] ; then
398 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
399 echo "corresponding library doesn't have the patches required to link"
400 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
401 echo "sources bundled with the emulator instead"
402 echo "Error:"
403 cat $TMPL
404 clean_exit
405 fi
406
407 log "SDL-probe : extra features ok"
408 clean_temp
409
410 EXTRA_CFLAGS=
411 EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800412fi
413
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800414###
415### Audio subsystems probes
416###
417PROBE_COREAUDIO=no
418PROBE_ALSA=no
419PROBE_OSS=no
420PROBE_ESD=no
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700421PROBE_PULSEAUDIO=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800422PROBE_WINAUDIO=no
423
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700424case "$TARGET_OS" in
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800425 darwin*) PROBE_COREAUDIO=yes;
426 ;;
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700427 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800428 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100429 freebsd-*) PROBE_OSS=yes;
430 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800431 windows) PROBE_WINAUDIO=yes
432 ;;
433esac
434
435ORG_CFLAGS=$CFLAGS
436ORG_LDFLAGS=$LDFLAGS
437
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200438if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then
439PROBE_ESD_ESD=no
440PROBE_ALSA=no
441PROBE_PULSEAUDIO=no
442fi
443
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700444# Probe a system library
445#
446# $1: Variable name (e.g. PROBE_ESD)
447# $2: Library name (e.g. "Alsa")
448# $3: Path to source file for probe program (e.g. android/config/check-alsa.c)
449# $4: Package name (e.g. libasound-dev)
450#
451probe_system_library ()
452{
453 if [ `var_value $1` = yes ] ; then
454 CFLAGS="$ORG_CFLAGS"
455 LDFLAGS="$ORG_LDFLAGS -ldl"
456 cp -f android/config/check-esd.c $TMPC
David 'Digit' Turnera7ef1ac2010-12-10 22:33:51 +0100457 compile
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700458 if [ $? = 0 ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200459 log "AudioProbe : $2 seems to be usable on this system"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700460 else
461 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200462 echo "The $2 development files do not seem to be installed on this system"
463 echo "Are you missing the $4 package ?"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700464 echo "Correct the errors below and try again:"
465 cat $TMPL
466 clean_exit
467 fi
468 eval $1=no
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200469 log "AudioProbe : $2 seems to be UNUSABLE on this system !!"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800470 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800471 fi
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700472}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800473
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700474probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev
475probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev
476probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800477
478CFLAGS=$ORG_CFLAGS
479LDFLAGS=$ORG_LDFLAGS
480
481# create the objs directory that is going to contain all generated files
482# including the configuration ones
483#
484mkdir -p objs
485
486###
487### Compiler probe
488###
489
490####
491#### Host system probe
492####
493
494# because the previous version could be read-only
495rm -f $TMPC
496
497# check host endianess
498#
499HOST_BIGENDIAN=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700500if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800501cat > $TMPC << EOF
502#include <inttypes.h>
503int main(int argc, char ** argv){
504 volatile uint32_t i=0x01234567;
Marcus Comstedt17d31322010-10-05 21:54:12 +0200505 return (*((uint8_t*)(&i))) == 0x01;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800506}
507EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200508feature_run_exec HOST_BIGENDIAN
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700509fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800510
511# check size of host long bits
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700512HOST_LONGBITS=32
513if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800514cat > $TMPC << EOF
515int main(void) {
516 return sizeof(void*)*8;
517}
518EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200519feature_run_exec HOST_LONGBITS
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700520fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800521
522# check whether we have <byteswap.h>
523#
David Turnerb8fec3e2010-09-09 18:15:23 +0200524feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
525feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
526feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
David Turner80dd1262010-09-09 18:04:49 +0200527
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800528# Build the config.make file
529#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200530
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200531case $TARGET_OS in
532 windows)
533 TARGET_EXEEXT=.exe
534 ;;
535 *)
536 TARGET_EXEEXT=
537 ;;
538esac
539
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200540create_config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700541echo "" >> $config_mk
Jun Nakajima334ab472011-02-02 23:49:59 -0800542if [ $TARGET_ARCH = arm ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700543echo "TARGET_ARCH := arm" >> $config_mk
Jun Nakajima334ab472011-02-02 23:49:59 -0800544fi
545
546if [ $TARGET_ARCH = x86 ] ; then
547echo "TARGET_ARCH := x86" >> $config_mk
548fi
549
Bhanu Chetlapalli741dc132012-05-08 17:16:03 -0700550if [ $TARGET_ARCH = mips ] ; then
551echo "TARGET_ARCH := mips" >> $config_mk
552fi
553
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700554echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200555echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700556echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700557echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200558
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800559PWD=`pwd`
560echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700561if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200562echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700563fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800564echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
565echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
566echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
567echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
568echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700569echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800570echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200571if [ $OPTION_DEBUG = yes ] ; then
572 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
573fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800574if [ $OPTION_STATIC = yes ] ; then
575 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
576fi
577
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800578if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
579 echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
580fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800581
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700582if [ "$OPTION_MINGW" = "yes" ] ; then
583 echo "" >> $config_mk
584 echo "USE_MINGW := 1" >> $config_mk
585 echo "HOST_OS := windows" >> $config_mk
586fi
587
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200588if [ "$GLES_INCLUDE" -a "$GLES_LIBS" ]; then
589 echo "QEMU_OPENGLES_INCLUDE := $GLES_INCLUDE" >> $config_mk
590 echo "QEMU_OPENGLES_LIBS := $GLES_LIBS" >> $config_mk
591fi
592
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800593# Build the config-host.h file
594#
595config_h=objs/config-host.h
596echo "/* This file was autogenerated by '$PROGNAME' */" > $config_h
597echo "#define CONFIG_QEMU_SHAREDIR \"/usr/local/share/qemu\"" >> $config_h
598echo "#define HOST_LONG_BITS $HOST_LONGBITS" >> $config_h
599if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200600 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
601fi
602if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
603 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800604fi
David Turner80dd1262010-09-09 18:04:49 +0200605if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
606 echo "#define CONFIG_FNMATCH 1" >> $config_h
607fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800608echo "#define CONFIG_GDBSTUB 1" >> $config_h
609echo "#define CONFIG_SLIRP 1" >> $config_h
610echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200611echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700612
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200613case "$TARGET_OS" in
614 windows)
615 echo "#define CONFIG_WIN32 1" >> $config_h
616 ;;
617 *)
618 echo "#define CONFIG_POSIX 1" >> $config_h
619 ;;
620esac
621
622case "$TARGET_OS" in
623 linux-*)
624 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
625 ;;
626esac
627
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700628# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700629case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700630 linux-*)
631 echo "#define CONFIG_FDATASYNC 1" >> $config_h
632 ;;
633esac
634
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200635case "$TARGET_OS" in
636 linux-*|darwin-*)
637 echo "#define CONFIG_MADVISE 1" >> $config_h
638 ;;
639esac
640
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800641# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700642if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800643 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
644fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700645echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
646echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800647case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200648 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800649 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200650 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800651 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200652 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800653 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200654 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800655 ;;
656esac
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200657echo "#define HOST_$CONFIG_CPU 1" >> $config_h
Marcus Comstedt17d31322010-10-05 21:54:12 +0200658if [ "$HOST_BIGENDIAN" = "1" ] ; then
659 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
660fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200661BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700662case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200663 linux-*) CONFIG_OS=LINUX
664 ;;
665 darwin-*) CONFIG_OS=DARWIN
666 BSD=1
667 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100668 freebsd-*) CONFIG_OS=FREEBSD
669 BSD=1
670 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200671 windows*) CONFIG_OS=WIN32
672 ;;
673 *) CONFIG_OS=$OS
674esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700675
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800676if [ "$OPTION_STATIC" = "yes" ] ; then
677 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
678 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
679fi
680
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700681case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700682 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800683 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700684 ;;
685esac
686
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200687echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
688if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700689 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200690 echo "#define O_LARGEFILE 0" >> $config_h
691 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
692fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700693
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700694echo "#define CONFIG_ANDROID 1" >> $config_h
695
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200696if [ "$GLES_INCLUDE" -a "$GLES_LIBS" ]; then
697 echo "#define CONFIG_ANDROID_OPENGLES 1" >> $config_h
698fi
699
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800700log "Generate : $config_h"
701
702echo "Ready to go. Type 'make' to build emulator"