blob: 9510ece9bbcdf86bd0cf17161d2558ad3d0104e9 [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' Turnerd68b4872009-07-24 16:33:05 +020025OPTION_DEBUG=no
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080026OPTION_STATIC=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070027OPTION_MINGW=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080028
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +020029GLES_INCLUDE=
30GLES_LIBS=
31GLES_SUPPORT=no
32GLES_PROBE=yes
33
David 'Digit' Turnere3650682010-12-22 14:44:19 +010034HOST_CC=${CC:-gcc}
35OPTION_CC=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080036
David 'Digit' Turner5b2e7c42011-02-07 18:51:07 +010037TARGET_ARCH=arm
38
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080039for opt do
40 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
41 case "$opt" in
42 --help|-h|-\?) OPTION_HELP=yes
43 ;;
44 --verbose)
45 if [ "$VERBOSE" = "yes" ] ; then
46 VERBOSE2=yes
47 else
48 VERBOSE=yes
49 fi
50 ;;
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +020051 --debug) OPTION_DEBUG=yes
52 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +020053 --install=*) OPTION_TARGETS="$OPTION_TARGETS $optarg";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080054 ;;
55 --sdl-config=*) SDL_CONFIG=$optarg
56 ;;
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -070057 --mingw) OPTION_MINGW=yes
58 ;;
David 'Digit' Turnere3650682010-12-22 14:44:19 +010059 --cc=*) OPTION_CC="$optarg"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080060 ;;
61 --no-strip) OPTION_NO_STRIP=yes
62 ;;
63 --debug) OPTION_DEBUG=yes
64 ;;
65 --ignore-audio) OPTION_IGNORE_AUDIO=yes
66 ;;
67 --no-prebuilts) OPTION_NO_PREBUILTS=yes
68 ;;
69 --try-64) OPTION_TRY_64=yes
70 ;;
David 'Digit' Turnerab873b72010-03-08 18:33:50 -080071 --static) OPTION_STATIC=yes
72 ;;
David 'Digit' Turner5b2e7c42011-02-07 18:51:07 +010073 --arch=*) TARGET_ARCH=$optarg
74 ;;
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +020075 --gles-include=*) GLES_INCLUDE=$optarg
76 GLES_SUPPORT=yes
77 ;;
78 --gles-libs=*) GLES_LIBS=$optarg
79 GLES_SUPPORT=yes
80 ;;
81 --no-gles) GLES_PROBE=no
82 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080083 *)
84 echo "unknown option '$opt', use --help"
85 exit 1
86 esac
87done
88
89# Print the help message
90#
91if [ "$OPTION_HELP" = "yes" ] ; then
92 cat << EOF
93
94Usage: rebuild.sh [options]
95Options: [defaults in brackets after descriptions]
96EOF
97 echo "Standard options:"
98 echo " --help print this message"
99 echo " --install=FILEPATH copy emulator executable to FILEPATH [$TARGETS]"
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100100 echo " --cc=PATH specify C compiler [$HOST_CC]"
David 'Digit' Turner5b2e7c42011-02-07 18:51:07 +0100101 echo " --arch=ARM specify target architecture [$TARGET_ARCH]"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800102 echo " --sdl-config=FILE use specific sdl-config script [$SDL_CONFIG]"
103 echo " --no-strip do not strip emulator executable"
104 echo " --debug enable debug (-O0 -g) build"
105 echo " --ignore-audio ignore audio messages (may build sound-less emulator)"
106 echo " --no-prebuilts do not use prebuilt libraries and compiler"
107 echo " --try-64 try to build a 64-bit executable (may crash)"
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700108 echo " --mingw build Windows executable on Linux"
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800109 echo " --static build a completely static executable"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800110 echo " --verbose verbose configuration"
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200111 echo " --debug build debug version of the emulator"
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200112 echo " --gles-include=PATH specify path to GLES emulation headers"
113 echo " --gles-libs=PATH specify path to GLES emulation host libraries"
114 echo " --no-gles disable GLES emulation support"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800115 echo ""
116 exit 1
117fi
118
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700119# On Linux, try to use our prebuilt toolchain to generate binaries
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100120# that are compatible with Ubuntu 8.04
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700121if [ -z "$CC" -a -z "$OPTION_CC" -a "$HOST_OS" = linux ] ; then
122 HOST_CC=`dirname $0`/../../prebuilts/tools/gcc-sdk/gcc
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100123 if [ -f "$HOST_CC" ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700124 echo "Using prebuilt toolchain: $HOST_CC"
David 'Digit' Turnere3650682010-12-22 14:44:19 +0100125 CC="$HOST_CC"
126 fi
127fi
128
David 'Digit' Turnerba313e02011-02-09 16:01:53 +0100129echo "OPTION_CC='$OPTION_CC'"
130if [ -n "$OPTION_CC" ]; then
131 echo "Using specified C compiler: $OPTION_CC"
132 CC="$OPTION_CC"
133fi
134
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700135if [ -z "$CC" ]; then
136 CC=$HOST_CC
137fi
138
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200139# we only support generating 32-bit binaris on 64-bit systems.
140# And we may need to add a -Wa,--32 to CFLAGS to let the assembler
141# generate 32-bit binaries on Linux x86_64.
142#
143if [ "$OPTION_TRY_64" != "yes" ] ; then
144 force_32bit_binaries
145fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800146
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200147case $OS in
148 linux-*)
149 TARGET_DLL_SUFFIX=.so
150 ;;
151 darwin-*)
152 TARGET_DLL_SUFFIX=.dylib
153 ;;
154 windows*)
155 TARGET_DLL_SUFFIX=.dll
156esac
157
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700158TARGET_OS=$OS
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200159if [ "$OPTION_MINGW" = "yes" ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700160 enable_linux_mingw
161 TARGET_OS=windows
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200162 TARGET_DLL_SUFFIX=.dll
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700163else
164 enable_cygwin
165fi
166
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200167# Are we running in the Android build system ?
168check_android_build
169
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800170
171# Adjust a few things when we're building within the Android build
172# system:
173# - locate prebuilt directory
174# - locate and use prebuilt libraries
175# - copy the new binary to the correct location
176#
177if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then
178 IN_ANDROID_BUILD=no
179fi
180
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200181# This is the list of static and shared host libraries we need to link
182# against in order to support OpenGLES emulation properly. Note that in
183# the case of a standalone build, we will find these libraries inside the
184# platform build tree and copy them into objs/lib/ automatically, unless
185# you use --gles-libs to point explicitely to a different directory.
186#
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700187if [ "$OPTION_TRY_64" != "yes" ] ; then
188 GLES_SHARED_LIBRARIES="libOpenglRender libGLES_CM_translator libGLES_V2_translator libEGL_translator"
189else
190 GLES_SHARED_LIBRARIES="lib64OpenglRender lib64GLES_CM_translator lib64GLES_V2_translator lib64EGL_translator"
191fi
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200192
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800193if [ "$IN_ANDROID_BUILD" = "yes" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200194 locate_android_prebuilt
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800195
196 # use ccache if USE_CCACHE is defined and the corresponding
197 # binary is available.
198 #
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800199 if [ -n "$USE_CCACHE" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200200 CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800201 if [ ! -f $CCACHE ] ; then
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700202 CCACHE="$ANDROID_PREBUILTS/ccache/ccache$EXE"
203 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800204 if [ -f $CCACHE ] ; then
205 CC="$CCACHE $CC"
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700206 log "Prebuilt : CCACHE=$CCACHE"
207 else
208 log "Prebuilt : CCACHE can't be found"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800209 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800210 fi
211
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800212 # finally ensure that our new binary is copied to the 'out'
213 # subdirectory as 'emulator'
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200214 HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES)
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200215 if [ "$TARGET_OS" = "windows" ]; then
216 HOST_BIN=$(echo $HOST_BIN | sed "s%$OS/bin%windows/bin%")
217 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800218 if [ -n "$HOST_BIN" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200219 OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE"
220 log "Targets : TARGETS=$OPTION_TARGETS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800221 fi
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800222
223 # find the Android SDK Tools revision number
224 TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties
225 if [ -f $TOOLS_PROPS ] ; then
226 ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null`
227 log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION"
228 else
229 log "Tools : Could not locate $TOOLS_PROPS !?"
230 fi
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200231
232 # Try to find the GLES emulation headers and libraries automatically
233 if [ "$GLES_PROBE" = "yes" ]; then
234 GLES_SUPPORT=yes
235 if [ -z "$GLES_INCLUDE" ]; then
236 log "GLES : Probing for headers"
Jesse Hall183e9272012-04-26 15:13:27 -0700237 GLES_INCLUDE=$ANDROID_TOP/sdk/emulator/opengl/host/include
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200238 if [ -d "$GLES_INCLUDE" ]; then
239 log "GLES : Headers in $GLES_INCLUDE"
240 else
241 echo "Warning: Could not find OpenGLES emulation include dir: $GLES_INCLUDE"
242 echo "Disabling GLES emulation from this build!"
243 GLES_SUPPORT=no
244 fi
245 fi
246 if [ -z "$GLES_LIBS" ]; then
247 log "GLES : Probing for host libraries"
248 GLES_LIBS=$(dirname "$HOST_BIN")/lib
249 if [ -d "$GLES_LIBS" ]; then
250 echo "GLES : Libs in $GLES_LIBS"
251 else
252 echo "Warning: Could nof find OpenGLES emulation libraries in: $GLES_LIBS"
253 echo "Disabling GLES emulation from this build!"
254 GLES_SUPPORT=no
255 fi
256 fi
257 fi
Vladimir Chtchetkine2c4c30e2012-05-11 06:56:43 -0700258else
259 if [ "$GLES_PROBE" = "yes" ]; then
260 GLES_SUPPORT=yes
261 if [ -z "$GLES_INCLUDE" ]; then
262 log "GLES : Probing for headers"
263 GLES_INCLUDE=../../sdk/emulator/opengl/host/include
264 if [ -d "$GLES_INCLUDE" ]; then
265 log "GLES : Headers in $GLES_INCLUDE"
266 else
267 echo "Warning: Could not find OpenGLES emulation include dir: $GLES_INCLUDE"
268 echo "Disabling GLES emulation from this build!"
269 GLES_SUPPORT=no
270 fi
271 fi
272 if [ -z "$GLES_LIBS" ]; then
273 log "GLES : Probing for host libraries"
274 GLES_LIBS=../../out/host/$OS/lib
275 if [ -d "$GLES_LIBS" ]; then
276 echo "GLES : Libs in $GLES_LIBS"
277 else
278 echo "Warning: Could nof find OpenGLES emulation libraries in: $GLES_LIBS"
279 echo "Disabling GLES emulation from this build!"
280 GLES_SUPPORT=no
281 fi
282 fi
283 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800284fi # IN_ANDROID_BUILD = no
285
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200286if [ "$GLES_SUPPORT" = "yes" ]; then
287 if [ -z "$GLES_INCLUDE" -o -z "$GLES_LIBS" ]; then
288 echo "ERROR: You must use both --gles-include and --gles-libs at the same time!"
289 echo " Or use --no-gles to disable its support from this build."
290 exit 1
291 fi
292
293 GLES_HEADER=$GLES_INCLUDE/libOpenglRender/render_api.h
294 if [ ! -f "$GLES_HEADER" ]; then
295 echo "ERROR: Missing OpenGLES emulation header file: $GLES_HEADER"
296 echo "Please fix this by using --gles-include to point to the right directory!"
297 exit 1
298 fi
299
300 mkdir -p objs/lib
301
302 for lib in $GLES_SHARED_LIBRARIES; do
303 GLES_LIB=$GLES_LIBS/${lib}$TARGET_DLL_SUFFIX
304 if [ ! -f "$GLES_LIB" ]; then
305 echo "ERROR: Missing OpenGLES emulation host library: $GLES_LIB"
306 echo "Please fix this by using --gles-libs to point to the right directory!"
307 if [ "$IN_ANDROID_BUILD" = "true" ]; then
308 echo "You might also be missing the library because you forgot to rebuild the whole platform!"
309 fi
310 exit 1
311 fi
312 cp $GLES_LIB objs/lib
313 if [ $? != 0 ]; then
314 echo "ERROR: Could not find required OpenGLES emulation library: $GLES_LIB"
315 exit 1
316 else
317 log "GLES : Copying $GLES_LIB"
318 fi
319 done
320fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800321
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200322# we can build the emulator with Cygwin, so enable it
323enable_cygwin
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800324
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200325setup_toolchain
The Android Open Source Project92c73112009-03-05 14:34:31 -0800326
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800327###
328### SDL Probe
329###
330
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700331if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200332
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700333 # check that we can link statically with the library.
334 #
335 SDL_CFLAGS=`$SDL_CONFIG --cflags`
336 SDL_LIBS=`$SDL_CONFIG --static-libs`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800337
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700338 # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags
David 'Digit' Turner826b9852011-06-01 15:28:14 +02003397 # since they break recent Mingw releases
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700340 SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g`
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800341
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700342 log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS"
343 log "SDL-probe : SDL_LIBS = $SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800344
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800345
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700346 EXTRA_CFLAGS="$SDL_CFLAGS"
347 EXTRA_LDFLAGS="$SDL_LIBS"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800348
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700349 case "$OS" in
350 freebsd-*)
351 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread"
352 ;;
353 esac
Alexey Tarasov08823222009-09-01 02:07:51 +1100354
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700355 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800356#include <SDL.h>
357#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200358int main( int argc, char** argv ) {
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200359 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800360}
361EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700362 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200363
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700364 if [ $SDL_LINKING != "yes" ] ; then
365 echo "You provided an explicit sdl-config script, but the corresponding library"
366 echo "cannot be statically linked with the Android emulator directly."
367 echo "Error message:"
368 cat $TMPL
369 clean_exit
370 fi
371 log "SDL-probe : static linking ok"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800372
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700373 # now, let's check that the SDL library has the special functions
374 # we added to our own sources
375 #
376 cat > $TMPC << EOF
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800377#include <SDL.h>
378#undef main
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200379int main( int argc, char** argv ) {
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700380 int x, y;
381 SDL_Rect r;
382 SDL_WM_GetPos(&x, &y);
383 SDL_WM_SetPos(x, y);
384 SDL_WM_GetMonitorDPI(&x, &y);
385 SDL_WM_GetMonitorRect(&r);
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200386 return SDL_Init (SDL_INIT_VIDEO);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800387}
388EOF
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700389 feature_check_link SDL_LINKING
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200390
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700391 if [ $SDL_LINKING != "yes" ] ; then
392 echo "You provided an explicit sdl-config script in SDL_CONFIG, but the"
393 echo "corresponding library doesn't have the patches required to link"
394 echo "with the Android emulator. Unsetting SDL_CONFIG will use the"
395 echo "sources bundled with the emulator instead"
396 echo "Error:"
397 cat $TMPL
398 clean_exit
399 fi
400
401 log "SDL-probe : extra features ok"
402 clean_temp
403
404 EXTRA_CFLAGS=
405 EXTRA_LDFLAGS=
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800406fi
407
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800408###
409### Audio subsystems probes
410###
411PROBE_COREAUDIO=no
412PROBE_ALSA=no
413PROBE_OSS=no
414PROBE_ESD=no
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700415PROBE_PULSEAUDIO=no
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800416PROBE_WINAUDIO=no
417
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700418case "$TARGET_OS" in
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800419 darwin*) PROBE_COREAUDIO=yes;
420 ;;
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700421 linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800422 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100423 freebsd-*) PROBE_OSS=yes;
424 ;;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800425 windows) PROBE_WINAUDIO=yes
426 ;;
427esac
428
429ORG_CFLAGS=$CFLAGS
430ORG_LDFLAGS=$LDFLAGS
431
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200432if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then
433PROBE_ESD_ESD=no
434PROBE_ALSA=no
435PROBE_PULSEAUDIO=no
436fi
437
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700438# Probe a system library
439#
440# $1: Variable name (e.g. PROBE_ESD)
441# $2: Library name (e.g. "Alsa")
442# $3: Path to source file for probe program (e.g. android/config/check-alsa.c)
443# $4: Package name (e.g. libasound-dev)
444#
445probe_system_library ()
446{
447 if [ `var_value $1` = yes ] ; then
448 CFLAGS="$ORG_CFLAGS"
449 LDFLAGS="$ORG_LDFLAGS -ldl"
450 cp -f android/config/check-esd.c $TMPC
David 'Digit' Turnera7ef1ac2010-12-10 22:33:51 +0100451 compile
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700452 if [ $? = 0 ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200453 log "AudioProbe : $2 seems to be usable on this system"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700454 else
455 if [ "$OPTION_IGNORE_AUDIO" = no ] ; then
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200456 echo "The $2 development files do not seem to be installed on this system"
457 echo "Are you missing the $4 package ?"
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700458 echo "Correct the errors below and try again:"
459 cat $TMPL
460 clean_exit
461 fi
462 eval $1=no
David 'Digit' Turner80bc5c82010-10-20 19:04:51 +0200463 log "AudioProbe : $2 seems to be UNUSABLE on this system !!"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800464 fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800465 fi
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700466}
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800467
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700468probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev
469probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev
470probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800471
472CFLAGS=$ORG_CFLAGS
473LDFLAGS=$ORG_LDFLAGS
474
475# create the objs directory that is going to contain all generated files
476# including the configuration ones
477#
478mkdir -p objs
479
480###
481### Compiler probe
482###
483
484####
485#### Host system probe
486####
487
488# because the previous version could be read-only
489rm -f $TMPC
490
491# check host endianess
492#
493HOST_BIGENDIAN=no
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700494if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800495cat > $TMPC << EOF
496#include <inttypes.h>
497int main(int argc, char ** argv){
498 volatile uint32_t i=0x01234567;
Marcus Comstedt17d31322010-10-05 21:54:12 +0200499 return (*((uint8_t*)(&i))) == 0x01;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800500}
501EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200502feature_run_exec HOST_BIGENDIAN
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700503fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800504
505# check size of host long bits
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700506HOST_LONGBITS=32
507if [ "$TARGET_OS" = "$OS" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800508cat > $TMPC << EOF
509int main(void) {
510 return sizeof(void*)*8;
511}
512EOF
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200513feature_run_exec HOST_LONGBITS
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700514fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800515
516# check whether we have <byteswap.h>
517#
David Turnerb8fec3e2010-09-09 18:15:23 +0200518feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
519feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
520feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
David Turner80dd1262010-09-09 18:04:49 +0200521
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800522# Build the config.make file
523#
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200524
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200525case $TARGET_OS in
526 windows)
527 TARGET_EXEEXT=.exe
528 ;;
529 *)
530 TARGET_EXEEXT=
531 ;;
532esac
533
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200534create_config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700535echo "" >> $config_mk
Jun Nakajima334ab472011-02-02 23:49:59 -0800536if [ $TARGET_ARCH = arm ] ; then
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700537echo "TARGET_ARCH := arm" >> $config_mk
Jun Nakajima334ab472011-02-02 23:49:59 -0800538fi
539
540if [ $TARGET_ARCH = x86 ] ; then
541echo "TARGET_ARCH := x86" >> $config_mk
542fi
543
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700544echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
David 'Digit' Turner81f74292010-10-14 18:29:45 +0200545echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700546echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700547echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200548
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800549PWD=`pwd`
550echo "SRC_PATH := $PWD" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700551if [ -n "$SDL_CONFIG" ] ; then
David 'Digit' Turnera4026682011-08-24 12:54:01 +0200552echo "QEMU_SDL_CONFIG := $SDL_CONFIG" >> $config_mk
David 'Digit' Turner34d16512010-05-18 17:02:33 -0700553fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800554echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
555echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
556echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
557echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
558echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
David 'Digit' Turner415a4b12010-07-28 12:20:14 -0700559echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800560echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk
David 'Digit' Turnerd68b4872009-07-24 16:33:05 +0200561if [ $OPTION_DEBUG = yes ] ; then
562 echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
563fi
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800564if [ $OPTION_STATIC = yes ] ; then
565 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
566fi
567
David 'Digit' Turnera383d022009-12-03 13:50:00 -0800568if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
569 echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
570fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800571
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700572if [ "$OPTION_MINGW" = "yes" ] ; then
573 echo "" >> $config_mk
574 echo "USE_MINGW := 1" >> $config_mk
575 echo "HOST_OS := windows" >> $config_mk
576fi
577
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200578if [ "$GLES_INCLUDE" -a "$GLES_LIBS" ]; then
579 echo "QEMU_OPENGLES_INCLUDE := $GLES_INCLUDE" >> $config_mk
580 echo "QEMU_OPENGLES_LIBS := $GLES_LIBS" >> $config_mk
581fi
582
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800583# Build the config-host.h file
584#
585config_h=objs/config-host.h
586echo "/* This file was autogenerated by '$PROGNAME' */" > $config_h
587echo "#define CONFIG_QEMU_SHAREDIR \"/usr/local/share/qemu\"" >> $config_h
588echo "#define HOST_LONG_BITS $HOST_LONGBITS" >> $config_h
589if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
David Turnerb8fec3e2010-09-09 18:15:23 +0200590 echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
591fi
592if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
593 echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800594fi
David Turner80dd1262010-09-09 18:04:49 +0200595if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
596 echo "#define CONFIG_FNMATCH 1" >> $config_h
597fi
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800598echo "#define CONFIG_GDBSTUB 1" >> $config_h
599echo "#define CONFIG_SLIRP 1" >> $config_h
600echo "#define CONFIG_SKINS 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200601echo "#define CONFIG_TRACE 1" >> $config_h
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700602
David 'Digit' Turner826b9852011-06-01 15:28:14 +0200603case "$TARGET_OS" in
604 windows)
605 echo "#define CONFIG_WIN32 1" >> $config_h
606 ;;
607 *)
608 echo "#define CONFIG_POSIX 1" >> $config_h
609 ;;
610esac
611
612case "$TARGET_OS" in
613 linux-*)
614 echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
615 ;;
616esac
617
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700618# only Linux has fdatasync()
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700619case "$TARGET_OS" in
David 'Digit' Turnerfd3b1a02010-05-10 23:47:54 -0700620 linux-*)
621 echo "#define CONFIG_FDATASYNC 1" >> $config_h
622 ;;
623esac
624
David 'Digit' Turner280afa02011-05-11 17:37:44 +0200625case "$TARGET_OS" in
626 linux-*|darwin-*)
627 echo "#define CONFIG_MADVISE 1" >> $config_h
628 ;;
629esac
630
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800631# the -nand-limits options can only work on non-windows systems
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700632if [ "$TARGET_OS" != "windows" ] ; then
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800633 echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
634fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700635echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
636echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800637case "$CPU" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200638 x86) CONFIG_CPU=I386
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800639 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200640 ppc) CONFIG_CPU=PPC
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800641 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200642 x86_64) CONFIG_CPU=X86_64
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800643 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200644 *) CONFIG_CPU=$CPU
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800645 ;;
646esac
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200647echo "#define HOST_$CONFIG_CPU 1" >> $config_h
Marcus Comstedt17d31322010-10-05 21:54:12 +0200648if [ "$HOST_BIGENDIAN" = "1" ] ; then
649 echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h
650fi
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200651BSD=0
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700652case "$TARGET_OS" in
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200653 linux-*) CONFIG_OS=LINUX
654 ;;
655 darwin-*) CONFIG_OS=DARWIN
656 BSD=1
657 ;;
Alexey Tarasov08823222009-09-01 02:07:51 +1100658 freebsd-*) CONFIG_OS=FREEBSD
659 BSD=1
660 ;;
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200661 windows*) CONFIG_OS=WIN32
662 ;;
663 *) CONFIG_OS=$OS
664esac
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700665
David 'Digit' Turnerab873b72010-03-08 18:33:50 -0800666if [ "$OPTION_STATIC" = "yes" ] ; then
667 echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk
668 echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h
669fi
670
David 'Digit' Turner377eb2c2010-05-20 15:16:28 -0700671case $TARGET_OS in
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700672 linux-*|darwin-*)
David 'Digit' Turner3d66dc72010-01-27 18:18:41 -0800673 echo "#define CONFIG_IOVEC 1" >> $config_h
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700674 ;;
675esac
676
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200677echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
678if [ $BSD = 1 ] ; then
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700679 echo "#define CONFIG_BSD 1" >> $config_h
David 'Digit' Turner46be4872009-06-04 16:07:01 +0200680 echo "#define O_LARGEFILE 0" >> $config_h
681 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
682fi
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700683
David 'Digit' Turnere92bc562010-09-07 06:21:25 -0700684echo "#define CONFIG_ANDROID 1" >> $config_h
685
David 'Digit' Turner0c8c8852011-08-24 13:26:58 +0200686if [ "$GLES_INCLUDE" -a "$GLES_LIBS" ]; then
687 echo "#define CONFIG_ANDROID_OPENGLES 1" >> $config_h
688fi
689
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800690log "Generate : $config_h"
691
692echo "Ready to go. Type 'make' to build emulator"