David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 1 | #!/bin/sh |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 2 | # |
| 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 Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 7 | # 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 |
| 13 | cd `dirname $0` |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 14 | |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 15 | # source common functions definitions |
| 16 | . android/build/common.sh |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 17 | |
| 18 | # Parse options |
| 19 | OPTION_TARGETS="" |
| 20 | OPTION_DEBUG=no |
| 21 | OPTION_IGNORE_AUDIO=no |
| 22 | OPTION_NO_PREBUILTS=no |
| 23 | OPTION_TRY_64=no |
| 24 | OPTION_HELP=no |
David 'Digit' Turner | d68b487 | 2009-07-24 16:33:05 +0200 | [diff] [blame] | 25 | OPTION_DEBUG=no |
David 'Digit' Turner | ab873b7 | 2010-03-08 18:33:50 -0800 | [diff] [blame] | 26 | OPTION_STATIC=no |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 27 | OPTION_MINGW=no |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 28 | |
David 'Digit' Turner | e365068 | 2010-12-22 14:44:19 +0100 | [diff] [blame] | 29 | HOST_CC=${CC:-gcc} |
| 30 | OPTION_CC= |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 31 | |
David 'Digit' Turner | 5b2e7c4 | 2011-02-07 18:51:07 +0100 | [diff] [blame] | 32 | TARGET_ARCH=arm |
| 33 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 34 | for opt do |
| 35 | optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` |
| 36 | case "$opt" in |
| 37 | --help|-h|-\?) OPTION_HELP=yes |
| 38 | ;; |
| 39 | --verbose) |
| 40 | if [ "$VERBOSE" = "yes" ] ; then |
| 41 | VERBOSE2=yes |
| 42 | else |
| 43 | VERBOSE=yes |
| 44 | fi |
| 45 | ;; |
David 'Digit' Turner | d68b487 | 2009-07-24 16:33:05 +0200 | [diff] [blame] | 46 | --debug) OPTION_DEBUG=yes |
| 47 | ;; |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 48 | --install=*) OPTION_TARGETS="$OPTION_TARGETS $optarg"; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 49 | ;; |
| 50 | --sdl-config=*) SDL_CONFIG=$optarg |
| 51 | ;; |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 52 | --mingw) OPTION_MINGW=yes |
| 53 | ;; |
David 'Digit' Turner | e365068 | 2010-12-22 14:44:19 +0100 | [diff] [blame] | 54 | --cc=*) OPTION_CC="$optarg" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 55 | ;; |
| 56 | --no-strip) OPTION_NO_STRIP=yes |
| 57 | ;; |
| 58 | --debug) OPTION_DEBUG=yes |
| 59 | ;; |
| 60 | --ignore-audio) OPTION_IGNORE_AUDIO=yes |
| 61 | ;; |
| 62 | --no-prebuilts) OPTION_NO_PREBUILTS=yes |
| 63 | ;; |
| 64 | --try-64) OPTION_TRY_64=yes |
| 65 | ;; |
David 'Digit' Turner | ab873b7 | 2010-03-08 18:33:50 -0800 | [diff] [blame] | 66 | --static) OPTION_STATIC=yes |
| 67 | ;; |
David 'Digit' Turner | 5b2e7c4 | 2011-02-07 18:51:07 +0100 | [diff] [blame] | 68 | --arch=*) TARGET_ARCH=$optarg |
| 69 | ;; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 70 | *) |
| 71 | echo "unknown option '$opt', use --help" |
| 72 | exit 1 |
| 73 | esac |
| 74 | done |
| 75 | |
| 76 | # Print the help message |
| 77 | # |
| 78 | if [ "$OPTION_HELP" = "yes" ] ; then |
| 79 | cat << EOF |
| 80 | |
| 81 | Usage: rebuild.sh [options] |
| 82 | Options: [defaults in brackets after descriptions] |
| 83 | EOF |
| 84 | echo "Standard options:" |
| 85 | echo " --help print this message" |
| 86 | echo " --install=FILEPATH copy emulator executable to FILEPATH [$TARGETS]" |
David 'Digit' Turner | e365068 | 2010-12-22 14:44:19 +0100 | [diff] [blame] | 87 | echo " --cc=PATH specify C compiler [$HOST_CC]" |
David 'Digit' Turner | 5b2e7c4 | 2011-02-07 18:51:07 +0100 | [diff] [blame] | 88 | echo " --arch=ARM specify target architecture [$TARGET_ARCH]" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 89 | echo " --sdl-config=FILE use specific sdl-config script [$SDL_CONFIG]" |
| 90 | echo " --no-strip do not strip emulator executable" |
| 91 | echo " --debug enable debug (-O0 -g) build" |
| 92 | echo " --ignore-audio ignore audio messages (may build sound-less emulator)" |
| 93 | echo " --no-prebuilts do not use prebuilt libraries and compiler" |
| 94 | echo " --try-64 try to build a 64-bit executable (may crash)" |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 95 | echo " --mingw build Windows executable on Linux" |
David 'Digit' Turner | ab873b7 | 2010-03-08 18:33:50 -0800 | [diff] [blame] | 96 | echo " --static build a completely static executable" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 97 | echo " --verbose verbose configuration" |
David 'Digit' Turner | d68b487 | 2009-07-24 16:33:05 +0200 | [diff] [blame] | 98 | echo " --debug build debug version of the emulator" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 99 | echo "" |
| 100 | exit 1 |
| 101 | fi |
| 102 | |
David 'Digit' Turner | e365068 | 2010-12-22 14:44:19 +0100 | [diff] [blame] | 103 | # On Linux, try to use our 32-bit prebuilt toolchain to generate binaries |
| 104 | # that are compatible with Ubuntu 8.04 |
| 105 | if [ -z "$CC" -a -z "$OPTION_CC" -a "$HOST_OS" = linux -a "$OPTION_TRY_64" != "yes" ] ; then |
| 106 | HOST_CC=`dirname $0`/../../prebuilt/linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/bin/i686-linux-gcc |
| 107 | if [ -f "$HOST_CC" ] ; then |
| 108 | echo "Using prebuilt 32-bit toolchain: $HOST_CC" |
| 109 | CC="$HOST_CC" |
| 110 | fi |
| 111 | fi |
| 112 | |
David 'Digit' Turner | ba313e0 | 2011-02-09 16:01:53 +0100 | [diff] [blame^] | 113 | echo "OPTION_CC='$OPTION_CC'" |
| 114 | if [ -n "$OPTION_CC" ]; then |
| 115 | echo "Using specified C compiler: $OPTION_CC" |
| 116 | CC="$OPTION_CC" |
| 117 | fi |
| 118 | |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 119 | # we only support generating 32-bit binaris on 64-bit systems. |
| 120 | # And we may need to add a -Wa,--32 to CFLAGS to let the assembler |
| 121 | # generate 32-bit binaries on Linux x86_64. |
| 122 | # |
| 123 | if [ "$OPTION_TRY_64" != "yes" ] ; then |
| 124 | force_32bit_binaries |
| 125 | fi |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 126 | |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 127 | TARGET_OS=$OS |
| 128 | if [ "$OPTION_MINGW" == "yes" ] ; then |
| 129 | enable_linux_mingw |
| 130 | TARGET_OS=windows |
| 131 | else |
| 132 | enable_cygwin |
| 133 | fi |
| 134 | |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 135 | # Are we running in the Android build system ? |
| 136 | check_android_build |
| 137 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 138 | |
| 139 | # Adjust a few things when we're building within the Android build |
| 140 | # system: |
| 141 | # - locate prebuilt directory |
| 142 | # - locate and use prebuilt libraries |
| 143 | # - copy the new binary to the correct location |
| 144 | # |
| 145 | if [ "$OPTION_NO_PREBUILTS" = "yes" ] ; then |
| 146 | IN_ANDROID_BUILD=no |
| 147 | fi |
| 148 | |
| 149 | if [ "$IN_ANDROID_BUILD" = "yes" ] ; then |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 150 | locate_android_prebuilt |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 151 | |
| 152 | # use ccache if USE_CCACHE is defined and the corresponding |
| 153 | # binary is available. |
| 154 | # |
| 155 | # note: located in PREBUILT/ccache/ccache in the new tree layout |
| 156 | # located in PREBUILT/ccache in the old one |
| 157 | # |
| 158 | if [ -n "$USE_CCACHE" ] ; then |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 159 | CCACHE="$ANDROID_PREBUILT/ccache/ccache$EXE" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 160 | if [ ! -f $CCACHE ] ; then |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 161 | CCACHE="$ANDROID_PREBUILT/ccache$EXE" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 162 | fi |
| 163 | if [ -f $CCACHE ] ; then |
| 164 | CC="$CCACHE $CC" |
| 165 | fi |
| 166 | log "Prebuilt : CCACHE=$CCACHE" |
| 167 | fi |
| 168 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 169 | # finally ensure that our new binary is copied to the 'out' |
| 170 | # subdirectory as 'emulator' |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 171 | HOST_BIN=$(get_android_abs_build_var HOST_OUT_EXECUTABLES) |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 172 | if [ -n "$HOST_BIN" ] ; then |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 173 | OPTION_TARGETS="$OPTION_TARGETS $HOST_BIN/emulator$EXE" |
| 174 | log "Targets : TARGETS=$OPTION_TARGETS" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 175 | fi |
David 'Digit' Turner | a383d02 | 2009-12-03 13:50:00 -0800 | [diff] [blame] | 176 | |
| 177 | # find the Android SDK Tools revision number |
| 178 | TOOLS_PROPS=$ANDROID_TOP/sdk/files/tools_source.properties |
| 179 | if [ -f $TOOLS_PROPS ] ; then |
| 180 | ANDROID_SDK_TOOLS_REVISION=`awk -F= '/Pkg.Revision/ { print $2; }' $TOOLS_PROPS 2> /dev/null` |
| 181 | log "Tools : Found tools revision number $ANDROID_SDK_TOOLS_REVISION" |
| 182 | else |
| 183 | log "Tools : Could not locate $TOOLS_PROPS !?" |
| 184 | fi |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 185 | fi # IN_ANDROID_BUILD = no |
| 186 | |
| 187 | |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 188 | # we can build the emulator with Cygwin, so enable it |
| 189 | enable_cygwin |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 190 | |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 191 | setup_toolchain |
The Android Open Source Project | 92c7311 | 2009-03-05 14:34:31 -0800 | [diff] [blame] | 192 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 193 | ### |
| 194 | ### SDL Probe |
| 195 | ### |
| 196 | |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 197 | if [ -n "$SDL_CONFIG" ] ; then |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 198 | |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 199 | # check that we can link statically with the library. |
| 200 | # |
| 201 | SDL_CFLAGS=`$SDL_CONFIG --cflags` |
| 202 | SDL_LIBS=`$SDL_CONFIG --static-libs` |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 203 | |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 204 | # quick hack, remove the -D_GNU_SOURCE=1 of some SDL Cflags |
| 205 | # since they break recent Mingw releases |
| 206 | SDL_CFLAGS=`echo $SDL_CFLAGS | sed -e s/-D_GNU_SOURCE=1//g` |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 207 | |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 208 | log "SDL-probe : SDL_CFLAGS = $SDL_CFLAGS" |
| 209 | log "SDL-probe : SDL_LIBS = $SDL_LIBS" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 210 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 211 | |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 212 | EXTRA_CFLAGS="$SDL_CFLAGS" |
| 213 | EXTRA_LDFLAGS="$SDL_LIBS" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 214 | |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 215 | case "$OS" in |
| 216 | freebsd-*) |
| 217 | EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm -lpthread" |
| 218 | ;; |
| 219 | esac |
Alexey Tarasov | 0882322 | 2009-09-01 02:07:51 +1100 | [diff] [blame] | 220 | |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 221 | cat > $TMPC << EOF |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 222 | #include <SDL.h> |
| 223 | #undef main |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 224 | int main( int argc, char** argv ) { |
David 'Digit' Turner | 81f7429 | 2010-10-14 18:29:45 +0200 | [diff] [blame] | 225 | return SDL_Init (SDL_INIT_VIDEO); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 226 | } |
| 227 | EOF |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 228 | feature_check_link SDL_LINKING |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 229 | |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 230 | if [ $SDL_LINKING != "yes" ] ; then |
| 231 | echo "You provided an explicit sdl-config script, but the corresponding library" |
| 232 | echo "cannot be statically linked with the Android emulator directly." |
| 233 | echo "Error message:" |
| 234 | cat $TMPL |
| 235 | clean_exit |
| 236 | fi |
| 237 | log "SDL-probe : static linking ok" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 238 | |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 239 | # now, let's check that the SDL library has the special functions |
| 240 | # we added to our own sources |
| 241 | # |
| 242 | cat > $TMPC << EOF |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 243 | #include <SDL.h> |
| 244 | #undef main |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 245 | int main( int argc, char** argv ) { |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 246 | int x, y; |
| 247 | SDL_Rect r; |
| 248 | SDL_WM_GetPos(&x, &y); |
| 249 | SDL_WM_SetPos(x, y); |
| 250 | SDL_WM_GetMonitorDPI(&x, &y); |
| 251 | SDL_WM_GetMonitorRect(&r); |
David 'Digit' Turner | 81f7429 | 2010-10-14 18:29:45 +0200 | [diff] [blame] | 252 | return SDL_Init (SDL_INIT_VIDEO); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 253 | } |
| 254 | EOF |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 255 | feature_check_link SDL_LINKING |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 256 | |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 257 | if [ $SDL_LINKING != "yes" ] ; then |
| 258 | echo "You provided an explicit sdl-config script in SDL_CONFIG, but the" |
| 259 | echo "corresponding library doesn't have the patches required to link" |
| 260 | echo "with the Android emulator. Unsetting SDL_CONFIG will use the" |
| 261 | echo "sources bundled with the emulator instead" |
| 262 | echo "Error:" |
| 263 | cat $TMPL |
| 264 | clean_exit |
| 265 | fi |
| 266 | |
| 267 | log "SDL-probe : extra features ok" |
| 268 | clean_temp |
| 269 | |
| 270 | EXTRA_CFLAGS= |
| 271 | EXTRA_LDFLAGS= |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 272 | fi |
| 273 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 274 | ### |
| 275 | ### Audio subsystems probes |
| 276 | ### |
| 277 | PROBE_COREAUDIO=no |
| 278 | PROBE_ALSA=no |
| 279 | PROBE_OSS=no |
| 280 | PROBE_ESD=no |
David 'Digit' Turner | 415a4b1 | 2010-07-28 12:20:14 -0700 | [diff] [blame] | 281 | PROBE_PULSEAUDIO=no |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 282 | PROBE_WINAUDIO=no |
| 283 | |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 284 | case "$TARGET_OS" in |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 285 | darwin*) PROBE_COREAUDIO=yes; |
| 286 | ;; |
David 'Digit' Turner | 415a4b1 | 2010-07-28 12:20:14 -0700 | [diff] [blame] | 287 | linux-*) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 288 | ;; |
Alexey Tarasov | 0882322 | 2009-09-01 02:07:51 +1100 | [diff] [blame] | 289 | freebsd-*) PROBE_OSS=yes; |
| 290 | ;; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 291 | windows) PROBE_WINAUDIO=yes |
| 292 | ;; |
| 293 | esac |
| 294 | |
| 295 | ORG_CFLAGS=$CFLAGS |
| 296 | ORG_LDFLAGS=$LDFLAGS |
| 297 | |
David 'Digit' Turner | 80bc5c8 | 2010-10-20 19:04:51 +0200 | [diff] [blame] | 298 | if [ "$OPTION_IGNORE_AUDIO" = "yes" ] ; then |
| 299 | PROBE_ESD_ESD=no |
| 300 | PROBE_ALSA=no |
| 301 | PROBE_PULSEAUDIO=no |
| 302 | fi |
| 303 | |
David 'Digit' Turner | 415a4b1 | 2010-07-28 12:20:14 -0700 | [diff] [blame] | 304 | # Probe a system library |
| 305 | # |
| 306 | # $1: Variable name (e.g. PROBE_ESD) |
| 307 | # $2: Library name (e.g. "Alsa") |
| 308 | # $3: Path to source file for probe program (e.g. android/config/check-alsa.c) |
| 309 | # $4: Package name (e.g. libasound-dev) |
| 310 | # |
| 311 | probe_system_library () |
| 312 | { |
| 313 | if [ `var_value $1` = yes ] ; then |
| 314 | CFLAGS="$ORG_CFLAGS" |
| 315 | LDFLAGS="$ORG_LDFLAGS -ldl" |
| 316 | cp -f android/config/check-esd.c $TMPC |
David 'Digit' Turner | a7ef1ac | 2010-12-10 22:33:51 +0100 | [diff] [blame] | 317 | compile |
David 'Digit' Turner | 415a4b1 | 2010-07-28 12:20:14 -0700 | [diff] [blame] | 318 | if [ $? = 0 ] ; then |
David 'Digit' Turner | 80bc5c8 | 2010-10-20 19:04:51 +0200 | [diff] [blame] | 319 | log "AudioProbe : $2 seems to be usable on this system" |
David 'Digit' Turner | 415a4b1 | 2010-07-28 12:20:14 -0700 | [diff] [blame] | 320 | else |
| 321 | if [ "$OPTION_IGNORE_AUDIO" = no ] ; then |
David 'Digit' Turner | 80bc5c8 | 2010-10-20 19:04:51 +0200 | [diff] [blame] | 322 | echo "The $2 development files do not seem to be installed on this system" |
| 323 | echo "Are you missing the $4 package ?" |
David 'Digit' Turner | 415a4b1 | 2010-07-28 12:20:14 -0700 | [diff] [blame] | 324 | echo "Correct the errors below and try again:" |
| 325 | cat $TMPL |
| 326 | clean_exit |
| 327 | fi |
| 328 | eval $1=no |
David 'Digit' Turner | 80bc5c8 | 2010-10-20 19:04:51 +0200 | [diff] [blame] | 329 | log "AudioProbe : $2 seems to be UNUSABLE on this system !!" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 330 | fi |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 331 | fi |
David 'Digit' Turner | 415a4b1 | 2010-07-28 12:20:14 -0700 | [diff] [blame] | 332 | } |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 333 | |
David 'Digit' Turner | 415a4b1 | 2010-07-28 12:20:14 -0700 | [diff] [blame] | 334 | probe_system_library PROBE_ESD ESounD android/config/check-esd.c libesd-dev |
| 335 | probe_system_library PROBE_ALSA Alsa android/config/check-alsa.c libasound-dev |
| 336 | probe_system_library PROBE_PULSEAUDIO PulseAudio android/config/check-pulseaudio.c libpulse-dev |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 337 | |
| 338 | CFLAGS=$ORG_CFLAGS |
| 339 | LDFLAGS=$ORG_LDFLAGS |
| 340 | |
| 341 | # create the objs directory that is going to contain all generated files |
| 342 | # including the configuration ones |
| 343 | # |
| 344 | mkdir -p objs |
| 345 | |
| 346 | ### |
| 347 | ### Compiler probe |
| 348 | ### |
| 349 | |
| 350 | #### |
| 351 | #### Host system probe |
| 352 | #### |
| 353 | |
| 354 | # because the previous version could be read-only |
| 355 | rm -f $TMPC |
| 356 | |
| 357 | # check host endianess |
| 358 | # |
| 359 | HOST_BIGENDIAN=no |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 360 | if [ "$TARGET_OS" = "$OS" ] ; then |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 361 | cat > $TMPC << EOF |
| 362 | #include <inttypes.h> |
| 363 | int main(int argc, char ** argv){ |
| 364 | volatile uint32_t i=0x01234567; |
Marcus Comstedt | 17d3132 | 2010-10-05 21:54:12 +0200 | [diff] [blame] | 365 | return (*((uint8_t*)(&i))) == 0x01; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 366 | } |
| 367 | EOF |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 368 | feature_run_exec HOST_BIGENDIAN |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 369 | fi |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 370 | |
| 371 | # check size of host long bits |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 372 | HOST_LONGBITS=32 |
| 373 | if [ "$TARGET_OS" = "$OS" ] ; then |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 374 | cat > $TMPC << EOF |
| 375 | int main(void) { |
| 376 | return sizeof(void*)*8; |
| 377 | } |
| 378 | EOF |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 379 | feature_run_exec HOST_LONGBITS |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 380 | fi |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 381 | |
| 382 | # check whether we have <byteswap.h> |
| 383 | # |
David Turner | b8fec3e | 2010-09-09 18:15:23 +0200 | [diff] [blame] | 384 | feature_check_header HAVE_BYTESWAP_H "<byteswap.h>" |
| 385 | feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>" |
| 386 | feature_check_header HAVE_FNMATCH_H "<fnmatch.h>" |
David Turner | 80dd126 | 2010-09-09 18:04:49 +0200 | [diff] [blame] | 387 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 388 | # Build the config.make file |
| 389 | # |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 390 | |
David 'Digit' Turner | 81f7429 | 2010-10-14 18:29:45 +0200 | [diff] [blame] | 391 | case $TARGET_OS in |
| 392 | windows) |
| 393 | TARGET_EXEEXT=.exe |
| 394 | ;; |
| 395 | *) |
| 396 | TARGET_EXEEXT= |
| 397 | ;; |
| 398 | esac |
| 399 | |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 400 | create_config_mk |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 401 | echo "" >> $config_mk |
Jun Nakajima | 334ab47 | 2011-02-02 23:49:59 -0800 | [diff] [blame] | 402 | if [ $TARGET_ARCH = arm ] ; then |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 403 | echo "TARGET_ARCH := arm" >> $config_mk |
Jun Nakajima | 334ab47 | 2011-02-02 23:49:59 -0800 | [diff] [blame] | 404 | fi |
| 405 | |
| 406 | if [ $TARGET_ARCH = x86 ] ; then |
| 407 | echo "TARGET_ARCH := x86" >> $config_mk |
| 408 | fi |
| 409 | |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 410 | echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk |
David 'Digit' Turner | 81f7429 | 2010-10-14 18:29:45 +0200 | [diff] [blame] | 411 | echo "HOST_EXEEXT := $TARGET_EXEEXT" >> $config_mk |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 412 | echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 413 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 414 | PWD=`pwd` |
| 415 | echo "SRC_PATH := $PWD" >> $config_mk |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 416 | if [ -n "$SDL_CONFIG" ] ; then |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 417 | echo "SDL_CONFIG := $SDL_CONFIG" >> $config_mk |
David 'Digit' Turner | 34d1651 | 2010-05-18 17:02:33 -0700 | [diff] [blame] | 418 | fi |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 419 | echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk |
| 420 | echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk |
| 421 | echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk |
| 422 | echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk |
| 423 | echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk |
David 'Digit' Turner | 415a4b1 | 2010-07-28 12:20:14 -0700 | [diff] [blame] | 424 | echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 425 | echo "BUILD_STANDALONE_EMULATOR := true" >> $config_mk |
David 'Digit' Turner | d68b487 | 2009-07-24 16:33:05 +0200 | [diff] [blame] | 426 | if [ $OPTION_DEBUG = yes ] ; then |
| 427 | echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk |
| 428 | fi |
David 'Digit' Turner | ab873b7 | 2010-03-08 18:33:50 -0800 | [diff] [blame] | 429 | if [ $OPTION_STATIC = yes ] ; then |
| 430 | echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk |
| 431 | fi |
| 432 | |
David 'Digit' Turner | a383d02 | 2009-12-03 13:50:00 -0800 | [diff] [blame] | 433 | if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then |
| 434 | echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk |
| 435 | fi |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 436 | |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 437 | if [ "$OPTION_MINGW" = "yes" ] ; then |
| 438 | echo "" >> $config_mk |
| 439 | echo "USE_MINGW := 1" >> $config_mk |
| 440 | echo "HOST_OS := windows" >> $config_mk |
| 441 | fi |
| 442 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 443 | # Build the config-host.h file |
| 444 | # |
| 445 | config_h=objs/config-host.h |
| 446 | echo "/* This file was autogenerated by '$PROGNAME' */" > $config_h |
| 447 | echo "#define CONFIG_QEMU_SHAREDIR \"/usr/local/share/qemu\"" >> $config_h |
| 448 | echo "#define HOST_LONG_BITS $HOST_LONGBITS" >> $config_h |
| 449 | if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then |
David Turner | b8fec3e | 2010-09-09 18:15:23 +0200 | [diff] [blame] | 450 | echo "#define CONFIG_BYTESWAP_H 1" >> $config_h |
| 451 | fi |
| 452 | if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then |
| 453 | echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 454 | fi |
David Turner | 80dd126 | 2010-09-09 18:04:49 +0200 | [diff] [blame] | 455 | if [ "$HAVE_FNMATCH_H" = "yes" ] ; then |
| 456 | echo "#define CONFIG_FNMATCH 1" >> $config_h |
| 457 | fi |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 458 | echo "#define CONFIG_GDBSTUB 1" >> $config_h |
| 459 | echo "#define CONFIG_SLIRP 1" >> $config_h |
| 460 | echo "#define CONFIG_SKINS 1" >> $config_h |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 461 | echo "#define CONFIG_TRACE 1" >> $config_h |
David 'Digit' Turner | fd3b1a0 | 2010-05-10 23:47:54 -0700 | [diff] [blame] | 462 | |
| 463 | # only Linux has fdatasync() |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 464 | case "$TARGET_OS" in |
David 'Digit' Turner | fd3b1a0 | 2010-05-10 23:47:54 -0700 | [diff] [blame] | 465 | linux-*) |
| 466 | echo "#define CONFIG_FDATASYNC 1" >> $config_h |
| 467 | ;; |
| 468 | esac |
| 469 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 470 | # the -nand-limits options can only work on non-windows systems |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 471 | if [ "$TARGET_OS" != "windows" ] ; then |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 472 | echo "#define CONFIG_NAND_LIMITS 1" >> $config_h |
| 473 | fi |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 474 | echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h |
| 475 | echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 476 | case "$CPU" in |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 477 | x86) CONFIG_CPU=I386 |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 478 | ;; |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 479 | ppc) CONFIG_CPU=PPC |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 480 | ;; |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 481 | x86_64) CONFIG_CPU=X86_64 |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 482 | ;; |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 483 | *) CONFIG_CPU=$CPU |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 484 | ;; |
| 485 | esac |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 486 | echo "#define HOST_$CONFIG_CPU 1" >> $config_h |
Marcus Comstedt | 17d3132 | 2010-10-05 21:54:12 +0200 | [diff] [blame] | 487 | if [ "$HOST_BIGENDIAN" = "1" ] ; then |
| 488 | echo "#define HOST_WORDS_BIGENDIAN 1" >> $config_h |
| 489 | fi |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 490 | BSD=0 |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 491 | case "$TARGET_OS" in |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 492 | linux-*) CONFIG_OS=LINUX |
| 493 | ;; |
| 494 | darwin-*) CONFIG_OS=DARWIN |
| 495 | BSD=1 |
| 496 | ;; |
Alexey Tarasov | 0882322 | 2009-09-01 02:07:51 +1100 | [diff] [blame] | 497 | freebsd-*) CONFIG_OS=FREEBSD |
| 498 | BSD=1 |
| 499 | ;; |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 500 | windows*) CONFIG_OS=WIN32 |
| 501 | ;; |
| 502 | *) CONFIG_OS=$OS |
| 503 | esac |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 504 | |
David 'Digit' Turner | ab873b7 | 2010-03-08 18:33:50 -0800 | [diff] [blame] | 505 | if [ "$OPTION_STATIC" = "yes" ] ; then |
| 506 | echo "CONFIG_STATIC_EXECUTABLE := true" >> $config_mk |
| 507 | echo "#define CONFIG_STATIC_EXECUTABLE 1" >> $config_h |
| 508 | fi |
| 509 | |
David 'Digit' Turner | 377eb2c | 2010-05-20 15:16:28 -0700 | [diff] [blame] | 510 | case $TARGET_OS in |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 511 | linux-*|darwin-*) |
David 'Digit' Turner | 3d66dc7 | 2010-01-27 18:18:41 -0800 | [diff] [blame] | 512 | echo "#define CONFIG_IOVEC 1" >> $config_h |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 513 | ;; |
| 514 | esac |
| 515 | |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 516 | echo "#define CONFIG_$CONFIG_OS 1" >> $config_h |
| 517 | if [ $BSD = 1 ] ; then |
David 'Digit' Turner | 2c538c8 | 2010-05-10 16:48:20 -0700 | [diff] [blame] | 518 | echo "#define CONFIG_BSD 1" >> $config_h |
David 'Digit' Turner | 46be487 | 2009-06-04 16:07:01 +0200 | [diff] [blame] | 519 | echo "#define O_LARGEFILE 0" >> $config_h |
| 520 | echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h |
| 521 | fi |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 522 | |
David 'Digit' Turner | e92bc56 | 2010-09-07 06:21:25 -0700 | [diff] [blame] | 523 | echo "#define CONFIG_ANDROID 1" >> $config_h |
| 524 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 525 | log "Generate : $config_h" |
| 526 | |
| 527 | echo "Ready to go. Type 'make' to build emulator" |