This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 149
/
android-configure.sh
executable file
·913 lines (809 loc) · 24 KB
/
android-configure.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
#!/bin/sh
#
# this script is used to rebuild the Android emulator from sources
# in the current directory. It also contains logic to speed up the
# rebuild if it detects that you're using the Android build system
#
# here's the list of environment variables you can define before
# calling this script to control it (besides options):
#
#
# first, let's see which system we're running this on
cd `dirname $0`
PROGNAME=`basename $0`
PROGDIR=`dirname $0`
## Logging support
##
VERBOSE=yes
VERBOSE2=no
panic () {
echo "ERROR: $@"
exit 1
}
log () {
if [ "$VERBOSE" = "yes" ] ; then
echo "$1"
fi
}
log2 () {
if [ "$VERBOSE2" = "yes" ] ; then
echo "$1"
fi
}
## Normalize OS and CPU
##
BUILD_ARCH=$(uname -m)
case "$BUILD_ARCH" in
i?86) BUILD_ARCH=x86
;;
x86_64|amd64) BUILD_ARCH=x86_64
;;
*) panic "$BUILD_ARCH builds are not supported!"
;;
esac
log2 "BUILD_ARCH=$BUILD_ARCH"
# at this point, the supported values for CPU are:
# x86
# x86_64
#
# other values may be possible but haven't been tested
#
EXE=""
OS=`uname -s`
case "$OS" in
Darwin)
OS=darwin-$BUILD_ARCH
;;
Linux)
# note that building 32-bit binaries on x86_64 is handled later
OS=linux-$BUILD_ARCH
;;
FreeBSD)
OS=freebsd-$BUILD_ARCH
;;
CYGWIN*|*_NT-*)
panic "Please build Windows binaries on Linux with --mingw option."
;;
esac
log2 "OS=$OS"
log2 "EXE=$EXE"
# at this point, the value of OS should be one of the following:
# linux-x86
# linux-x86_64
# darwin-x86
# darwin-x86_64
#
# other values may be possible but have not been tested
# define HOST_OS as $OS without any cpu-specific suffix
#
case $OS in
linux-*) HOST_OS=linux
;;
darwin-*) HOST_OS=darwin
;;
freebsd-*) HOST_OS=freebsd
;;
*) HOST_OS=$OS
esac
HOST_ARCH=$BUILD_ARCH
HOST_TAG=$HOST_OS-$HOST_ARCH
#### Toolchain support
####
WINDRES=
# Various probes are going to need to run a small C program
TMPC=/tmp/android-$$-test.c
TMPO=/tmp/android-$$-test.o
TMPE=/tmp/android-$$-test$EXE
TMPL=/tmp/android-$$-test.log
# cleanup temporary files
clean_temp () {
rm -f $TMPC $TMPO $TMPL $TMPE
}
# cleanup temp files then exit with an error
clean_exit () {
clean_temp
exit 1
}
# this function should be called to enforce the build of 32-bit binaries on 64-bit systems
# that support it.
FORCE_32BIT=no
force_32bit_binaries () {
if [ $BUILD_ARCH = x86_64 ] ; then
FORCE_32BIT=yes
case $OS in
linux-x86_64) OS=linux-x86 ;;
darwin-x86_64) OS=darwin-x86 ;;
freebsd-x86_64) OS=freebsd-x86 ;;
esac
HOST_ARCH=x86
BUILD_ARCH=x86
HOST_TAG=$HOST_OS-$HOST_ARCH
log "Check32Bits: Forcing generation of 32-bit binaries."
fi
}
# this function will setup the compiler and linker and check that they work as advertized
# note that you should call 'force_32bit_binaries' before this one if you want it to work
# as advertized.
#
setup_toolchain () {
if [ -z "$CC" ] ; then
CC=gcc
fi
# check that we can compile a trivial C program with this compiler
cat > $TMPC <<EOF
int main(void) {}
EOF
if [ $FORCE_32BIT = yes ] ; then
CFLAGS="$CFLAGS -m32"
LDFLAGS="$LDFLAGS -m32"
compile
if [ $? != 0 ] ; then
# sometimes, we need to also tell the assembler to generate 32-bit binaries
# this is highly dependent on your GCC installation (and no, we can't set
# this flag all the time)
CFLAGS="$CFLAGS -Wa,--32"
fi
fi
compile
if [ $? != 0 ] ; then
echo "your C compiler doesn't seem to work: $CC"
cat $TMPL
clean_exit
fi
log "CC : compiler check ok ($CC)"
CC_VER=`$CC --version`
log "CC_VER : $CC_VER"
# check that we can link the trivial program into an executable
if [ -z "$LD" ] ; then
LD=$CC
fi
link
if [ $? != 0 ] ; then
echo "your linker doesn't seem to work:"
cat $TMPL
clean_exit
fi
log "LD : linker check ok ($LD)"
if [ -z "$AR" ]; then
AR=ar
fi
log "AR : archiver ($AR)"
clean_temp
}
# try to compile the current source file in $TMPC into an object
# stores the error log into $TMPL
#
compile () {
log2 "Object : $CC -o $TMPO -c $CFLAGS $TMPC"
$CC -o $TMPO -c $CFLAGS $TMPC 2> $TMPL
}
# try to link the recently built file into an executable. error log in $TMPL
#
link() {
log2 "Link : $LD -o $TMPE $TMPO $LDFLAGS"
$LD -o $TMPE $TMPO $LDFLAGS 2> $TMPL
}
## Feature test support
##
# check that a given C header file exists on the host system
# $1: variable name which will be set to "yes" or "no" depending on result
# $2: header name
#
# you can define EXTRA_CFLAGS for extra C compiler flags
# for convenience, this variable will be unset by the function.
#
feature_check_header () {
local result_ch OLD_CFLAGS
log2 "HeaderCheck: $2"
echo "#include $2" > $TMPC
cat >> $TMPC <<EOF
int main(void) { return 0; }
EOF
OLD_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS $EXTRA_CFLAGS"
compile
if [ $? != 0 ]; then
result_ch=no
else
result_ch=yes
fi
log "HeaderCheck: $2 [$result_ch]"
EXTRA_CFLAGS=
CFLAGS=$OLD_CFLAGS
eval $1=$result_ch
clean_temp
}
# Find pattern $1 in string $2
# This is to be used in if statements as in:
#
# if pattern_match <pattern> <string>; then
# ...
# fi
#
pattern_match () {
echo "$2" | grep -q -E -e "$1"
}
# Find if a given shell program is available.
# We need to take care of the fact that the 'which <foo>' command
# may return either an empty string (Linux) or something like
# "no <foo> in ..." (Darwin). Also, we need to redirect stderr
# to /dev/null for Cygwin
#
# $1: variable name
# $2: program name
#
# Result: set $1 to the full path of the corresponding command
# or to the empty/undefined string if not available
#
find_program () {
local PROG
PROG=`which $2 2>/dev/null || true`
if [ -n "$PROG" ] ; then
if pattern_match '^no ' "$PROG"; then
PROG=
fi
fi
eval $1="$PROG"
}
# Default value of --ui option.
UI_DEFAULT=sdl2
# Parse options
OPTION_DEBUG=no
OPTION_IGNORE_AUDIO=no
OPTION_AOSP_PREBUILTS_DIR=
OPTION_OUT_DIR=
OPTION_HELP=no
OPTION_STRIP=no
OPTION_MINGW=no
OPTION_UI=
GLES_SUPPORT=no
PCBIOS_PROBE=yes
HOST_CC=${CC:-gcc}
OPTION_CC=
AOSP_PREBUILTS_DIR=$(dirname "$0")/../../prebuilts
if [ -d "$AOSP_PREBUILTS_DIR" ]; then
AOSP_PREBUILTS_DIR=$(cd "$AOSP_PREBUILTS_DIR" && pwd -P 2>/dev/null)
else
AOSP_PREBUILTS_DIR=
fi
for opt do
optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
case "$opt" in
--help|-h|-\?) OPTION_HELP=yes
;;
--verbose)
if [ "$VERBOSE" = "yes" ] ; then
VERBOSE2=yes
else
VERBOSE=yes
fi
;;
--verbosity=*)
if [ "$optarg" -gt 1 ]; then
VERBOSE=yes
if [ "$optarg" -gt 2 ]; then
VERBOSE2=yes
fi
fi
;;
--debug) OPTION_DEBUG=yes
;;
--mingw) OPTION_MINGW=yes
;;
--cc=*) OPTION_CC="$optarg"
;;
--strip) OPTION_STRIP=yes
;;
--no-strip) OPTION_STRIP=no
;;
--out-dir=*) OPTION_OUT_DIR=$optarg
;;
--aosp-prebuilts-dir=*) OPTION_AOSP_PREBUILTS_DIR=$optarg
;;
--build-qemu-android) true # Ignored, used by android-rebuild.sh only.
;;
--no-pcbios) PCBIOS_PROBE=no
;;
--no-tests)
# Ignore this option, only used by android-rebuild.sh
;;
--ui=sdl2) OPTION_UI=sdl2
;;
--ui=qt) OPTION_UI=qt
;;
--ui=*) echo "Unknown --ui value, try one of: sdl2 qt"
;;
*)
echo "unknown option '$opt', use --help"
exit 1
esac
done
# Print the help message
#
if [ "$OPTION_HELP" = "yes" ] ; then
cat << EOF
Usage: rebuild.sh [options]
Options: [defaults in brackets after descriptions]
EOF
echo "Standard options:"
echo " --help Print this message"
echo " --cc=PATH Specify C compiler [$HOST_CC]"
echo " --strip Strip emulator executables."
echo " --no-strip Do not strip emulator executables (default)."
echo " --debug Enable debug (-O0 -g) build"
echo " --ui=sdl2 Use SDL2-based UI backend (default)."
echo " --ui=qt Use Qt-based UI backend."
echo " --aosp-prebuilts-dir=<path> Use specific prebuilt toolchain root directory [$AOSP_PREBUILTS_DIR]"
echo " --out-dir=<path> Use specific output directory [objs/]"
echo " --mingw Build Windows executable on Linux"
echo " --verbose Verbose configuration"
echo " --debug Build debug version of the emulator"
echo " --no-pcbios Disable copying of PC Bios files"
echo " --no-tests Don't run unit test suite"
if [ "$IN_ANDROID_REBUILD_SH" ]; then
echo " --build-qemu-android Also build qemu-android binaries"
fi
echo ""
exit 1
fi
if [ "$OPTION_AOSP_PREBUILTS_DIR" ]; then
if [ ! -d "$OPTION_AOSP_PREBUILTS_DIR"/gcc -a \
! -d "$OPTION_AOSP_PREBUILTS_DIR"/clang ]; then
echo "ERROR: Prebuilts directory does not exist: $OPTION_AOSP_PREBUILTS_DIR/gcc"
exit 1
fi
AOSP_PREBUILTS_DIR=$OPTION_AOSP_PREBUILTS_DIR
fi
if [ -z "$OPTION_UI" ]; then
OPTION_UI=$UI_DEFAULT
log "Auto-config: --ui=$OPTION_UI"
fi
if [ "$OPTION_OUT_DIR" ]; then
OUT_DIR="$OPTION_OUT_DIR"
mkdir -p "$OUT_DIR" || panic "Could not create output directory: $OUT_DIR"
else
OUT_DIR=objs
log "Auto-config: --out-dir=objs"
fi
# For OS X, detect the location of the SDK to use.
# NOTE: This must happen before probing the host toolchain, because our
# prebuilt Clang one depends on runtime object files like crt1.10.6.o
# provided by the XCode SDK.
if [ "$HOST_OS" = darwin ]; then
OSX_VERSION=$(sw_vers -productVersion)
OSX_SDK_SUPPORTED="10.8 10.7 10.6" # in order of preference
OSX_SDK_INSTALLED_LIST=$(xcodebuild -showsdks 2>/dev/null | \
grep macosx | sed -e "s/.*macosx//g" | sort -n | tr '\n' ' ')
if [ -z "$OSX_SDK_INSTALLED_LIST" ]; then
echo "ERROR: Please install XCode on this machine!"
exit 1
fi
log "OSX: Installed SDKs: $OSX_SDK_INSTALLED_LIST"
OSX_SDK_VERSION=
# compare each SDK version supported with each SDK version installed
for SUPPORTED_VERSION in $OSX_SDK_SUPPORTED; do
for INSTALLED_VERSION in $OSX_SDK_INSTALLED_LIST; do
if [ "$SUPPORTED_VERSION" = "$INSTALLED_VERSION" ]; then
# use the first match found
OSX_SDK_VERSION=$INSTALLED_VERSION
break
fi
done
if [ "$OSX_SDK_VERSION" ]; then
break
fi
done
if [ "$OSX_SDK_VERSION" ]; then
log "OSX: Using SDK version $OSX_SDK_VERSION"
else
echo "ERROR: Only OSX SDK $OSX_SDK_SUPPORTED are supported and this machine has $OSX_SDK_VERSION."
echo "Please install Xcode 5 on this machine (If you have Xcode 6 installed, downgrade to Xcode 5)"
exit 1
fi
XCODE_PATH=$(xcode-select -print-path 2>/dev/null)
log "OSX: XCode path: $XCODE_PATH"
OSX_SDK_ROOT=$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk
log "OSX: Looking for $OSX_SDK_ROOT"
if [ ! -d "$OSX_SDK_ROOT" ]; then
OSX_SDK_ROOT=/Developer/SDKs/MacOSX${OSX_SDK_VERSION}.sdk
log "OSX: Looking for $OSX_SDK_ROOT"
if [ ! -d "$OSX_SDK_ROOT" ]; then
echo "ERROR: Could not find SDK $OSX_SDK_VERSION at $OSX_SDK_ROOT"
exit 1
fi
fi
echo "OSX SDK : Found at $OSX_SDK_ROOT"
fi
CCACHE=
if [ "$USE_CCACHE" != 0 ]; then
CCACHE=$(which ccache 2>/dev/null || true)
fi
if [ -n "$CCACHE" -a -f "$CCACHE" ]; then
if [ "$HOST_OS" == "darwin" -a "$OPTION_DEBUG" == "yes" ]; then
# http://llvm.org/bugs/show_bug.cgi?id=20297
# ccache works for mingw/gdb, therefore probably works for gcc/gdb
log "Prebuilt : CCACHE disabled for OSX debug builds"
CCACHE=
else
log "Prebuilt : CCACHE=$CCACHE"
fi
else
log "Prebuilt : CCACHE can't be found"
CCACHE=
fi
# On Linux, try to use our prebuilt toolchain to generate binaries
# that are compatible with Ubuntu 10.4
if [ -z "$CC" -a -z "$OPTION_CC" ] ; then
GEN_SDK=$PROGDIR/android/scripts/gen-android-sdk-toolchain.sh
GEN_SDK_FLAGS=
if [ "$CCACHE" ]; then
GEN_SDK_FLAGS="$GEN_SDK_FLAGS --ccache=$CCACHE"
else
GEN_SDK_FLAGS="$GEN_SDK_FLAGS --no-ccache"
fi
GEN_SDK_FLAGS="$GEN_SDK_FLAGS --aosp-dir=$AOSP_PREBUILTS_DIR/.."
$GEN_SDK $GEN_SDK_FLAGS $OUT_DIR/toolchain || panic "Cannot generate SDK toolchain!"
BINPREFIX=$($GEN_SDK $GEN_SDK_FLAGS --print=binprefix $OUT_DIR/toolchain)
CC="$OUT_DIR/toolchain/${BINPREFIX}gcc"
AR="$OUT_DIR/toolchain/${BINPREFIX}ar"
LD=$CC
fi
if [ -n "$OPTION_CC" ]; then
echo "Using specified C compiler: $OPTION_CC"
CC="$OPTION_CC"
fi
if [ -z "$CC" ]; then
CC=$HOST_CC
fi
# By default, generate 32-bit binaries, the Makefile have targets that
# generate 64-bit ones by using -m64 on the command-line.
force_32bit_binaries
setup_toolchain
BUILD_AR=$AR
BUILD_CC=$CC
BUILD_CXX=$CC
BUILD_LD=$LD
BUILD_CFLAGS=$CFLAGS
BUILD_CXXFLAGS=$CXXFLAGS
BUILD_LDFLAGS=$LDFLAGS
if [ "$OPTION_MINGW" = "yes" ] ; then
# Are we on Linux ?
log "Mingw : Checking for Linux host"
if [ "$HOST_OS" != "linux" ] ; then
echo "Sorry, but mingw compilation is only supported on Linux !"
exit 1
fi
# Do we have our prebuilt mingw64 toolchain?
log "Mingw : Looking for prebuilt mingw64 toolchain."
MINGW_DIR=$PROGDIR/../../prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8
MINGW_CC=
if [ -d "$MINGW_DIR" ]; then
MINGW_PREFIX=$MINGW_DIR/bin/x86_64-w64-mingw32
find_program MINGW_CC "$MINGW_PREFIX-gcc"
fi
if [ -z "$MINGW_CC" ]; then
log "Mingw : Looking for mingw64 toolchain."
MINGW_PREFIX=x86_64-w64-mingw32
find_program MINGW_CC $MINGW_PREFIX-gcc
fi
if [ -z "$MINGW_CC" ]; then
echo "ERROR: It looks like no Mingw64 toolchain is available!"
echo "Please install x86_64-w64-mingw32 package !"
exit 1
fi
log2 "Mingw : Found $MINGW_CC"
CC=$MINGW_CC
if [ "$CCACHE" ]; then
CC="$CCACHE $CC"
fi
LD=$MINGW_CC
WINDRES=$MINGW_PREFIX-windres
AR=$MINGW_PREFIX-ar
HOST_OS=windows
HOST_TAG=$HOST_OS-$HOST_ARCH
fi
# Try to find the GLES emulation headers and libraries automatically
GLES_DIR=distrib/android-emugl
if [ ! -d "$GLES_DIR" ]; then
panic "GLES : Could not find GPU emulation sources!: $GLES_DIR"
else
echo "GLES : Found GPU emulation sources: $GLES_DIR"
fi
if [ "$PCBIOS_PROBE" = "yes" ]; then
PCBIOS_DIR=$AOSP_PREBUILTS_DIR/qemu-kernel/x86/pc-bios
if [ ! -d "$PCBIOS_DIR" ]; then
log2 "PC Bios : Probing $PCBIOS_DIR (missing)"
PCBIOS_DIR=../pc-bios
fi
log2 "PC Bios : Probing $PCBIOS_DIR"
if [ ! -d "$PCBIOS_DIR" ]; then
log "PC Bios : Could not find prebuilts directory."
else
mkdir -p $OUT_DIR/lib/pc-bios
for BIOS_FILE in bios.bin vgabios-cirrus.bin bios-256k.bin efi-virtio.rom kvmvapic.bin linuxboot.bin; do
log "PC Bios : Copying $BIOS_FILE"
cp -f $PCBIOS_DIR/$BIOS_FILE $OUT_DIR/lib/pc-bios/$BIOS_FILE
done
fi
fi
setup_toolchain
###
### Audio subsystems probes
###
PROBE_COREAUDIO=no
PROBE_ALSA=no
PROBE_OSS=no
PROBE_ESD=no
PROBE_PULSEAUDIO=no
PROBE_WINAUDIO=no
case "$HOST_OS" in
darwin) PROBE_COREAUDIO=yes;
;;
linux) PROBE_ALSA=yes; PROBE_OSS=yes; PROBE_ESD=yes; PROBE_PULSEAUDIO=yes;
;;
freebsd) PROBE_OSS=yes;
;;
windows) PROBE_WINAUDIO=yes
;;
esac
###
### Qt probe
###
QT_PREBUILTS_DIR=
if [ "$OPTION_UI" = "qt" ]; then
QT_PREBUILTS_DIR=$AOSP_PREBUILTS_DIR/android-emulator-build/qt
if [ -d "$QT_PREBUILTS_DIR" ]; then
log "Qt prebuilts dir: $QT_PREBUILTS_DIR"
else
panic "Missing Qt prebuilts directory: $QT_PREBUILTS_DIR"
fi
fi
###
### e2fsprogs probe
###
E2FSPROGS_PREBUILTS_DIR=
if true; then
E2FSPROGS_PREBUILTS_DIR=$AOSP_PREBUILTS_DIR/android-emulator-build/e2fsprogs
if [ -d "$E2FSPROGS_PREBUILTS_DIR" ]; then
log "e2fsprogs prebuilts dir: $E2FSPROGS_PREBUILTS_DIR"
else
echo "WARNING: Missing e2fsprogs prebuilts directory: $E2FSPROGS_PREBUILTS_DIR"
fi
fi
# create the objs directory that is going to contain all generated files
# including the configuration ones
#
mkdir -p $OUT_DIR
###
### Compiler probe
###
####
#### Host system probe
####
# because the previous version could be read-only
clean_temp
# check whether we have <byteswap.h>
#
feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"
# check for Mingw version.
MINGW_VERSION=
if [ "$HOST_OS" = "windows" ]; then
log "Mingw : Probing for GCC version."
GCC_VERSION=$($CC -v 2>&1 | awk '$1 == "gcc" && $2 == "version" { print $3; }')
GCC_MAJOR=$(echo "$GCC_VERSION" | cut -f1 -d.)
GCC_MINOR=$(echo "$GCC_VERSION" | cut -f2 -d.)
log "Mingw : Found GCC version $GCC_MAJOR.$GCC_MINOR [$GCC_VERSION]"
MINGW_GCC_VERSION=$(( $GCC_MAJOR * 100 + $GCC_MINOR ))
fi
# Build the config.make file
#
case $OS in
windows)
BUILD_EXEEXT=.exe
BUILD_DLLEXT=.dll
;;
darwin)
BUILD_EXEEXT=
BUILD_DLLEXT=.dylib
;;
*)
BUILD_EXEEXT=
BUILD_DLLEXT=
;;
esac
case $HOST_OS in
windows)
HOST_EXEEXT=.exe
HOST_DLLEXT=.dll
;;
darwin)
HOST_EXEXT=
HOST_DLLEXT=.dylib
;;
*)
HOST_EXEEXT=
HOST_DLLEXT=.so
;;
esac
# Strip executables and shared libraries when needed.
if [ "$OPTION_DEBUG" != "yes" -a "$OPTION_STRIP" = "yes" ]; then
case $HOST_OS in
darwin)
LDFLAGS="$LDFLAGS -Wl,-S"
;;
*)
LDFLAGS="$LDFLAGS -Wl,--strip-all"
;;
esac
fi
# Re-create the configuration file
config_mk=$OUT_DIR/config.make
config_dir=$(dirname $config_mk)
mkdir -p "$config_dir" 2> $TMPL
if [ $? != 0 ] ; then
echo "Can't create directory for build config file: $config_dir"
cat $TMPL
clean_exit
fi
log "Generate : $config_mk"
echo "# This file was autogenerated by $PROGNAME. Do not edit !" > $config_mk
echo "HOST_OS := $HOST_OS" >> $config_mk
echo "HOST_ARCH := $HOST_ARCH" >> $config_mk
echo "HOST_CC := $CC" >> $config_mk
echo "HOST_CXX := $CXX" >> $config_mk
echo "HOST_LD := $LD" >> $config_mk
echo "HOST_AR := $AR" >> $config_mk
echo "HOST_WINDRES:= $WINDRES" >> $config_mk
echo "OBJS_DIR := $OUT_DIR" >> $config_mk
echo "" >> $config_mk
echo "HOST_PREBUILT_TAG := $HOST_TAG" >> $config_mk
echo "HOST_EXEEXT := $HOST_EXEEXT" >> $config_mk
echo "HOST_DLLEXT := $HOST_DLLEXT" >> $config_mk
echo "PREBUILT := $ANDROID_PREBUILT" >> $config_mk
echo "PREBUILTS := $ANDROID_PREBUILTS" >> $config_mk
echo "" >> $config_mk
echo "BUILD_EXEEXT := $BUILD_EXEEXT" >> $config_mk
echo "BUILD_DLLEXT := $BUILD_DLLEXT" >> $config_mk
echo "BUILD_AR := $BUILD_AR" >> $config_mk
echo "BUILD_CC := $BUILD_CC" >> $config_mk
echo "BUILD_CXX := $BUILD_CXX" >> $config_mk
echo "BUILD_LD := $BUILD_LD" >> $config_mk
echo "BUILD_CFLAGS := $BUILD_CFLAGS" >> $config_mk
echo "BUILD_LDFLAGS := $BUILD_LDFLAGS" >> $config_mk
PWD=`pwd`
echo "SRC_PATH := $PWD" >> $config_mk
echo "CONFIG_COREAUDIO := $PROBE_COREAUDIO" >> $config_mk
echo "CONFIG_WINAUDIO := $PROBE_WINAUDIO" >> $config_mk
echo "CONFIG_ESD := $PROBE_ESD" >> $config_mk
echo "CONFIG_ALSA := $PROBE_ALSA" >> $config_mk
echo "CONFIG_OSS := $PROBE_OSS" >> $config_mk
echo "CONFIG_PULSEAUDIO := $PROBE_PULSEAUDIO" >> $config_mk
if [ "$QT_PREBUILTS_DIR" ]; then
echo "QT_PREBUILTS_DIR := $QT_PREBUILTS_DIR" >> $config_mk
echo "EMULATOR_USE_SDL2 := false" >> $config_mk
echo "EMULATOR_USE_QT := true" >> $config_mk
else
echo "EMULATOR_USE_SDL2 := true" >> $config_mk
echo "EMULATOR_USE_QT := false" >> $config_mk
fi
if [ $OPTION_DEBUG = yes ] ; then
echo "BUILD_DEBUG_EMULATOR := true" >> $config_mk
fi
echo "EMULATOR_BUILD_EMUGL := true" >> $config_mk
echo "EMULATOR_EMUGL_SOURCES_DIR := $GLES_DIR" >> $config_mk
if [ -n "$ANDROID_SDK_TOOLS_REVISION" ] ; then
echo "ANDROID_SDK_TOOLS_REVISION := $ANDROID_SDK_TOOLS_REVISION" >> $config_mk
fi
if [ "$OPTION_MINGW" = "yes" ] ; then
echo "" >> $config_mk
echo "USE_MINGW := 1" >> $config_mk
echo "HOST_OS := windows" >> $config_mk
echo "HOST_MINGW_VERSION := $MINGW_GCC_VERSION" >> $config_mk
fi
if [ "$HOST_OS" = "darwin" ]; then
echo "mac_sdk_root := $OSX_SDK_ROOT" >> $config_mk
echo "mac_sdk_version := $OSX_SDK_VERSION" >> $config_mk
fi
# Build the config-host.h file
#
config_h=$OUT_DIR/config-host.h
cat > $config_h <<EOF
/* This file was autogenerated by '$PROGNAME' */
#define CONFIG_QEMU_SHAREDIR "/usr/local/share/qemu"
EOF
if [ "$HAVE_BYTESWAP_H" = "yes" ] ; then
echo "#define CONFIG_BYTESWAP_H 1" >> $config_h
fi
if [ "$HAVE_MACHINE_BYTESWAP_H" = "yes" ] ; then
echo "#define CONFIG_MACHINE_BSWAP_H 1" >> $config_h
fi
if [ "$HAVE_FNMATCH_H" = "yes" ] ; then
echo "#define CONFIG_FNMATCH 1" >> $config_h
fi
echo "#define CONFIG_GDBSTUB 1" >> $config_h
echo "#define CONFIG_SLIRP 1" >> $config_h
echo "#define CONFIG_SKINS 1" >> $config_h
echo "#define CONFIG_TRACE 1" >> $config_h
if [ "$QT_PREBUILTS_DIR" ]; then
echo "#define CONFIG_QT 1" >> $config_h
echo "#undef CONFIG_SDL" >> $config_h
else
echo "#undef CONFIG_QT" >> $config_mk
echo "#define CONFIG_SDL 1" >> $config_h
fi
case "$HOST_OS" in
windows)
echo "#define CONFIG_WIN32 1" >> $config_h
;;
*)
echo "#define CONFIG_POSIX 1" >> $config_h
;;
esac
case "$HOST_OS" in
linux)
echo "#define CONFIG_KVM_GS_RESTORE 1" >> $config_h
;;
esac
# only Linux has fdatasync()
case "$HOST_OS" in
linux)
echo "#define CONFIG_FDATASYNC 1" >> $config_h
;;
esac
case "$HOST_OS" in
linux|darwin)
echo "#define CONFIG_MADVISE 1" >> $config_h
;;
esac
# the -nand-limits options can only work on non-windows systems
if [ "$HOST_OS" != "windows" ] ; then
echo "#define CONFIG_NAND_LIMITS 1" >> $config_h
fi
echo "#define QEMU_VERSION \"0.10.50\"" >> $config_h
echo "#define QEMU_PKGVERSION \"Android\"" >> $config_h
BSD=0
case "$HOST_OS" in
linux) CONFIG_OS=LINUX
;;
darwin) CONFIG_OS=DARWIN
BSD=1
;;
freebsd) CONFIG_OS=FREEBSD
BSD=1
;;
windows) CONFIG_OS=WIN32
;;
*) CONFIG_OS=$HOST_OS
esac
case $HOST_OS in
linux|darwin)
echo "#define CONFIG_IOVEC 1" >> $config_h
;;
esac
echo "#define CONFIG_$CONFIG_OS 1" >> $config_h
if [ $BSD = 1 ] ; then
echo "#define CONFIG_BSD 1" >> $config_h
echo "#define O_LARGEFILE 0" >> $config_h
echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
fi
case "$HOST_OS" in
linux)
echo "#define CONFIG_SIGNALFD 1" >> $config_h
;;
esac
echo "#define CONFIG_ANDROID 1" >> $config_h
log "Generate : $config_h"
# Generate the QAPI headers and sources from qapi-schema.json
# Ideally, this would be done in our Makefiles, but as far as I
# understand, the platform build doesn't support a single tool
# that generates several sources files, nor the standalone one.
export PYTHONDONTWRITEBYTECODE=1
AUTOGENERATED_DIR=qapi-auto-generated
python scripts/qapi-types.py qapi.types --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
python scripts/qapi-visit.py --output-dir=$AUTOGENERATED_DIR -b < qapi-schema.json
python scripts/qapi-commands.py --output-dir=$AUTOGENERATED_DIR -m < qapi-schema.json
log "Generate : $AUTOGENERATED_DIR"
clean_temp
echo "Ready to go. Type 'make' to build emulator"