]> git.proxmox.com Git - mirror_qemu.git/blame - configure
tests/docker: use debian-all-test-cross for hppa
[mirror_qemu.git] / configure
CommitLineData
7d13299d
FB
1#!/bin/sh
2#
3ef693a0 3# qemu configure script (c) 2003 Fabrice Bellard
7d13299d 4#
8cd05ab6 5
99519e67 6# Unset some variables known to interfere with behavior of common tools,
5b507233
PB
7# just as autoconf does. Unlike autoconf, we assume that unset exists.
8unset CLICOLOR_FORCE GREP_OPTIONS BASH_ENV ENV MAIL MAILPATH CDPATH
99519e67 9
5e4dfd3d
JS
10# Don't allow CCACHE, if present, to use cached results of compile tests!
11export CCACHE_RECACHE=yes
12
dedad027
DB
13# make source path absolute
14source_path=$(cd "$(dirname -- "$0")"; pwd)
15
16if test "$PWD" = "$source_path"
17then
18 echo "Using './build' as the directory for build output"
19
20 MARKER=build/auto-created-by-configure
21
22 if test -e build
23 then
24 if test -f $MARKER
25 then
26 rm -rf build
27 else
28 echo "ERROR: ./build dir already exists and was not previously created by configure"
29 exit 1
30 fi
31 fi
32
f160a5b2
DB
33 if ! mkdir build || ! touch $MARKER
34 then
35 echo "ERROR: Could not create ./build directory. Check the permissions on"
36 echo "your source directory, or try doing an out-of-tree build."
37 exit 1
38 fi
dedad027
DB
39
40 cat > GNUmakefile <<'EOF'
41# This file is auto-generated by configure to support in-source tree
42# 'make' command invocation
43
44ifeq ($(MAKECMDGOALS),)
45recurse: all
46endif
47
48.NOTPARALLEL: %
49%: force
50 @echo 'changing dir to build for $(MAKE) "$(MAKECMDGOALS)"...'
51 @$(MAKE) -C build -f Makefile $(MAKECMDGOALS)
52 @if test "$(MAKECMDGOALS)" = "distclean" && \
53 test -e build/auto-created-by-configure ; \
54 then \
55 rm -rf build GNUmakefile ; \
56 fi
57force: ;
58.PHONY: force
59GNUmakefile: ;
60
61EOF
62 cd build
64708615 63 exec "$source_path/configure" "$@"
dedad027
DB
64fi
65
8cd05ab6
PM
66# Temporary directory used for files created while
67# configure runs. Since it is in the build directory
68# we can safely blow away any previous version of it
69# (and we need not jump through hoops to try to delete
70# it when configure exits.)
71TMPDIR1="config-temp"
72rm -rf "${TMPDIR1}"
563661c0 73if ! mkdir -p "${TMPDIR1}"; then
8cd05ab6
PM
74 echo "ERROR: failed to create temporary directory"
75 exit 1
7d13299d
FB
76fi
77
8cd05ab6
PM
78TMPB="qemu-conf"
79TMPC="${TMPDIR1}/${TMPB}.c"
66518bf6 80TMPO="${TMPDIR1}/${TMPB}.o"
8cd05ab6 81TMPE="${TMPDIR1}/${TMPB}.exe"
7d13299d 82
da1d85e3 83rm -f config.log
9ac81bbb 84
b48e3611
PM
85# Print a helpful header at the top of config.log
86echo "# QEMU configure log $(date)" >> config.log
979ae168 87printf "# Configured with:" >> config.log
7f788779
AB
88# repeat the invocation to log and stdout for CI
89invoke=$(printf " '%s'" "$0" "$@")
90test -n "$GITLAB_CI" && echo "configuring with: $invoke"
91{ echo "$invoke"; echo; echo "#"; } >> config.log
b48e3611 92
835af899
PB
93quote_sh() {
94 printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
95}
96
050b4398 97error_exit() {
d880a3ba 98 (echo
76ad07a4
PM
99 echo "ERROR: $1"
100 while test -n "$2"; do
101 echo " $2"
102 shift
103 done
d880a3ba 104 echo) >&2
76ad07a4
PM
105 exit 1
106}
107
9c83ffd8 108do_compiler() {
cd362def
PB
109 # Run the compiler, capturing its output to the log. First argument
110 # is compiler binary to execute.
b3b5472d 111 compiler="$1"
cd362def
PB
112 shift
113 if test -n "$BASH_VERSION"; then eval '
114 echo >>config.log "
115funcs: ${FUNCNAME[*]}
116lines: ${BASH_LINENO[*]}"
117 '; fi
118 echo $compiler "$@" >> config.log
119 $compiler "$@" >> config.log 2>&1 || return $?
120}
121
9c83ffd8 122do_cc() {
d0016b86 123 do_compiler "$cc" $CPU_CFLAGS "$@"
9c83ffd8
PM
124}
125
52166aa0 126compile_object() {
fd0e6053 127 local_cflags="$1"
a988b4c5 128 do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -c -o $TMPO $TMPC
52166aa0
JQ
129}
130
131compile_prog() {
132 local_cflags="$1"
133 local_ldflags="$2"
a988b4c5
PB
134 do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -o $TMPE $TMPC \
135 $LDFLAGS $EXTRA_LDFLAGS $local_ldflags
52166aa0
JQ
136}
137
11568d6d
PB
138# symbolically link $1 to $2. Portable version of "ln -sf".
139symlink() {
72b8b5a1 140 rm -rf "$2"
ec5b06d7 141 mkdir -p "$(dirname "$2")"
72b8b5a1 142 ln -s "$1" "$2"
11568d6d
PB
143}
144
0dba6195
LM
145# check whether a command is available to this shell (may be either an
146# executable or a builtin)
147has() {
148 type "$1" >/dev/null 2>&1
149}
150
0a01d76f 151version_ge () {
2df52b9b
AB
152 local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
153 local_ver2=$(echo "$2" | tr . ' ')
0a01d76f
MAL
154 while true; do
155 set x $local_ver1
156 local_first=${2-0}
c44a33e2
SG
157 # 'shift 2' if $2 is set, or 'shift' if $2 is not set
158 shift ${2:+2}
0a01d76f
MAL
159 local_ver1=$*
160 set x $local_ver2
161 # the second argument finished, the first must be greater or equal
162 test $# = 1 && return 0
163 test $local_first -lt $2 && return 1
164 test $local_first -gt $2 && return 0
c44a33e2 165 shift ${2:+2}
0a01d76f
MAL
166 local_ver2=$*
167 done
168}
169
4ace32e2
AO
170if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
171then
172 error_exit "main directory cannot contain spaces nor colons"
173fi
174
13cf376c
PB
175# parse CC options first; some compiler tests are used to establish
176# some defaults, based on the host environment
177
14211825 178# default parameters
42ede11a 179container_engine="auto"
2ff6b91e 180cpu=""
3812c0c4 181cross_compile="no"
7d13299d 182cross_prefix=""
e49d021e 183host_cc="cc"
13cf376c
PB
184EXTRA_CFLAGS=""
185EXTRA_CXXFLAGS=""
186EXTRA_OBJCFLAGS=""
187EXTRA_LDFLAGS=""
377529c0
PB
188
189# Default value for a variable defining feature "foo".
190# * foo="no" feature will only be used if --enable-foo arg is given
191# * foo="" feature will be searched for, and if found, will be used
192# unless --disable-foo is given
193# * foo="yes" this value will only be set by --enable-foo flag.
194# feature will searched for,
195# if not found, configure exits with error
196#
197# Always add --enable-foo and --disable-foo command line args.
198# Distributions want to ensure that several features are compiled in, and it
199# is impossible without a --enable-foo that exits if a feature is not found.
c87ea116 200default_feature=""
3b4da132 201
ac0df51d 202for opt do
89138857 203 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
ac0df51d
AL
204 case "$opt" in
205 --cross-prefix=*) cross_prefix="$optarg"
3812c0c4 206 cross_compile="yes"
ac0df51d 207 ;;
3d8df640 208 --cc=*) CC="$optarg"
ac0df51d 209 ;;
83f73fce
TS
210 --cxx=*) CXX="$optarg"
211 ;;
c0c34c91
PM
212 --objcc=*) objcc="$optarg"
213 ;;
2ff6b91e
JQ
214 --cpu=*) cpu="$optarg"
215 ;;
a2866660
PB
216 --extra-cflags=*)
217 EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
218 EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
e910c7d9 219 EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
a2866660
PB
220 ;;
221 --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
11cde1c8 222 ;;
e910c7d9
PMD
223 --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
224 ;;
a2866660 225 --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
e2a2ed06 226 ;;
d75402b5
AB
227 --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
228 ;;
479ca4cc 229 --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
d422b2bc
AB
230 eval "cross_cc_cflags_${cc_arch}=\$optarg"
231 ;;
d75402b5
AB
232 --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
233 eval "cross_cc_${cc_arch}=\$optarg"
234 ;;
5adb43be
PB
235 --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-prefix-FOO option"
236 ;;
237 --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
238 eval "cross_prefix_${cc_arch}=\$optarg"
239 ;;
13cf376c
PB
240 --without-default-features) default_feature="no"
241 ;;
ac0df51d
AL
242 esac
243done
ac0df51d 244
bafe78ad 245default_cflags='-O2 -g'
6f3ae23b 246git_submodules_action="update"
13cf376c
PB
247docs="auto"
248EXESUF=""
24f9c07a 249system="yes"
13cf376c
PB
250linux_user=""
251bsd_user=""
252plugins="$default_feature"
2a5919ab 253subdirs=""
13cf376c
PB
254ninja=""
255python=
ac4ccac7 256download="enabled"
13cf376c 257skip_meson=no
13cf376c
PB
258use_containers="yes"
259gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
260gdb_arches=""
13cf376c
PB
261
262# Don't accept a target_list environment variable.
263unset target_list
264unset target_list_exclude
265
266# The following Meson options are handled manually (still they
267# are included in the automatically generated help message)
2019cabf 268# because they automatically enable/disable other options
13cf376c
PB
269tcg="auto"
270cfi="false"
271
2019cabf
PB
272# Meson has PIE as a boolean rather than enabled/disabled/auto,
273# and we also need to check for -static-pie before Meson runs
274# which requires knowing whether --static is enabled.
13cf376c
PB
275pie=""
276static="no"
277
e49d021e
PM
278# Preferred compiler:
279# ${CC} (if set)
280# ${cross_prefix}gcc (if cross-prefix specified)
281# system compiler
282if test -z "${CC}${cross_prefix}"; then
3c7ee49b 283 cc="cc"
e49d021e
PM
284else
285 cc="${CC-${cross_prefix}gcc}"
286fi
287
83f73fce
TS
288if test -z "${CXX}${cross_prefix}"; then
289 cxx="c++"
290else
291 cxx="${CXX-${cross_prefix}g++}"
292fi
293
c0c34c91
PM
294# Preferred ObjC compiler:
295# $objcc (if set, i.e. via --objcc option)
296# ${cross_prefix}clang (if cross-prefix specified)
297# clang (if available)
298# $cc
299if test -z "${objcc}${cross_prefix}"; then
300 if has clang; then
301 objcc=clang
302 else
303 objcc="$cc"
304 fi
305else
306 objcc="${objcc-${cross_prefix}clang}"
307fi
308
b3198cc2 309ar="${AR-${cross_prefix}ar}"
cdbd727c 310as="${AS-${cross_prefix}as}"
5f6f0e27 311ccas="${CCAS-$cc}"
b3198cc2
SY
312objcopy="${OBJCOPY-${cross_prefix}objcopy}"
313ld="${LD-${cross_prefix}ld}"
9f81aeb5 314ranlib="${RANLIB-${cross_prefix}ranlib}"
4852ee95 315nm="${NM-${cross_prefix}nm}"
b3198cc2 316strip="${STRIP-${cross_prefix}strip}"
158bb224 317widl="${WIDL-${cross_prefix}widl}"
b3198cc2 318windres="${WINDRES-${cross_prefix}windres}"
f9f0e617 319windmc="${WINDMC-${cross_prefix}windmc}"
877c5567 320pkg_config="${PKG_CONFIG-${cross_prefix}pkg-config}"
47c03744 321sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
ac0df51d 322
ac0df51d
AL
323check_define() {
324cat > $TMPC <<EOF
325#if !defined($1)
fd786e1a 326#error $1 not defined
ac0df51d
AL
327#endif
328int main(void) { return 0; }
329EOF
52166aa0 330 compile_object
ac0df51d
AL
331}
332
93b25869
JS
333write_c_skeleton() {
334 cat > $TMPC <<EOF
335int main(void) { return 0; }
336EOF
337}
338
bbea4050 339if check_define __linux__ ; then
ba7c60c2 340 targetos=linux
bbea4050 341elif check_define _WIN32 ; then
ba7c60c2 342 targetos=windows
bbea4050 343elif check_define __OpenBSD__ ; then
ba7c60c2 344 targetos=openbsd
bbea4050 345elif check_define __sun__ ; then
ba7c60c2 346 targetos=sunos
bbea4050 347elif check_define __HAIKU__ ; then
ba7c60c2 348 targetos=haiku
951fedfc 349elif check_define __FreeBSD__ ; then
ba7c60c2 350 targetos=freebsd
951fedfc 351elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
ba7c60c2 352 targetos=gnu/kfreebsd
951fedfc 353elif check_define __DragonFly__ ; then
ba7c60c2 354 targetos=dragonfly
951fedfc 355elif check_define __NetBSD__; then
ba7c60c2 356 targetos=netbsd
951fedfc 357elif check_define __APPLE__; then
ba7c60c2 358 targetos=darwin
bbea4050 359else
951fedfc
PM
360 # This is a fatal error, but don't report it yet, because we
361 # might be going to just print the --help text, or it might
362 # be the result of a missing compiler.
ba7c60c2 363 targetos=bogus
bbea4050
PM
364fi
365
2ff6b91e
JQ
366if test ! -z "$cpu" ; then
367 # command line argument
368 :
369elif check_define __i386__ ; then
ac0df51d
AL
370 cpu="i386"
371elif check_define __x86_64__ ; then
c72b26ec
RH
372 if check_define __ILP32__ ; then
373 cpu="x32"
374 else
375 cpu="x86_64"
376 fi
3aa9bd6c 377elif check_define __sparc__ ; then
3aa9bd6c
BS
378 if check_define __arch64__ ; then
379 cpu="sparc64"
380 else
381 cpu="sparc"
382 fi
fdf7ed96 383elif check_define _ARCH_PPC ; then
384 if check_define _ARCH_PPC64 ; then
f8378acc
RH
385 if check_define _LITTLE_ENDIAN ; then
386 cpu="ppc64le"
387 else
388 cpu="ppc64"
389 fi
fdf7ed96 390 else
391 cpu="ppc"
392 fi
afa05235
AJ
393elif check_define __mips__ ; then
394 cpu="mips"
d66ed0ea
AJ
395elif check_define __s390__ ; then
396 if check_define __s390x__ ; then
397 cpu="s390x"
398 else
399 cpu="s390"
400 fi
c4f80543 401elif check_define __riscv ; then
e3e477c3
PMD
402 if check_define _LP64 ; then
403 cpu="riscv64"
404 else
405 cpu="riscv32"
406 fi
21d89f84
PM
407elif check_define __arm__ ; then
408 cpu="arm"
1f080313
CF
409elif check_define __aarch64__ ; then
410 cpu="aarch64"
dfcf900b
WX
411elif check_define __loongarch64 ; then
412 cpu="loongarch64"
ac0df51d 413else
f9c77801
PB
414 # Using uname is really broken, but it is just a fallback for architectures
415 # that are going to use TCI anyway
89138857 416 cpu=$(uname -m)
f9c77801 417 echo "WARNING: unrecognized host CPU, proceeding with 'uname -m' output '$cpu'"
ac0df51d
AL
418fi
419
971fac27
PB
420# Normalise host CPU name to the values used by Meson cross files and in source
421# directories, and set multilib cflags. The canonicalization isn't really
422# necessary, because the architectures that we check for should not hit the
423# 'uname -m' case, but better safe than sorry in case --cpu= is used.
424#
359bc95d 425# Note that this case should only have supported host CPUs, not guests.
971fac27
PB
426# Please keep it sorted and synchronized with meson.build's host_arch.
427host_arch=
428linux_arch=
7d13299d 429case "$cpu" in
971fac27
PB
430 aarch64)
431 host_arch=aarch64
432 linux_arch=arm64
433 ;;
434
e4da0e39 435 armv*b|armv*l|arm)
971fac27
PB
436 cpu=arm
437 host_arch=arm
438 linux_arch=arm
439 ;;
e4da0e39 440
f9c77801 441 i386|i486|i586|i686)
97a847bc 442 cpu="i386"
971fac27
PB
443 host_arch=i386
444 linux_arch=x86
445 CPU_CFLAGS="-m32"
446 ;;
e4da0e39 447
971fac27
PB
448 loongarch*)
449 cpu=loongarch64
450 host_arch=loongarch64
451 ;;
452
453 mips64*)
454 cpu=mips64
455 host_arch=mips
456 linux_arch=mips
457 ;;
afa05235 458 mips*)
971fac27
PB
459 cpu=mips
460 host_arch=mips
461 linux_arch=mips
462 ;;
e4da0e39
PB
463
464 ppc)
971fac27
PB
465 host_arch=ppc
466 linux_arch=powerpc
467 CPU_CFLAGS="-m32"
468 ;;
e4da0e39 469 ppc64)
971fac27
PB
470 host_arch=ppc64
471 linux_arch=powerpc
472 CPU_CFLAGS="-m64 -mbig-endian"
473 ;;
e4da0e39 474 ppc64le)
971fac27
PB
475 cpu=ppc64
476 host_arch=ppc64
477 linux_arch=powerpc
478 CPU_CFLAGS="-m64 -mlittle-endian"
479 ;;
480
481 riscv32 | riscv64)
482 host_arch=riscv
483 linux_arch=riscv
484 ;;
e4da0e39
PB
485
486 s390)
971fac27
PB
487 linux_arch=s390
488 CPU_CFLAGS="-m31"
489 ;;
e4da0e39 490 s390x)
971fac27
PB
491 host_arch=s390x
492 linux_arch=s390
493 CPU_CFLAGS="-m64"
494 ;;
e4da0e39 495
3142255c 496 sparc|sun4[cdmuv])
971fac27
PB
497 cpu=sparc
498 CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc"
499 ;;
e4da0e39 500 sparc64)
971fac27
PB
501 host_arch=sparc64
502 CPU_CFLAGS="-m64 -mcpu=ultrasparc"
503 ;;
504
505 x32)
506 cpu="x86_64"
507 host_arch=x86_64
508 linux_arch=x86
509 CPU_CFLAGS="-mx32"
510 ;;
511 x86_64|amd64)
512 cpu="x86_64"
513 host_arch=x86_64
514 linux_arch=x86
515 # ??? Only extremely old AMD cpus do not have cmpxchg16b.
516 # If we truly care, we should simply detect this case at
517 # runtime and generate the fallback to serial emulation.
518 CPU_CFLAGS="-m64 -mcx16"
519 ;;
7d13299d 520esac
e2d52ad3 521
971fac27
PB
522if test -n "$host_arch" && {
523 ! test -d "$source_path/linux-user/include/host/$host_arch" ||
524 ! test -d "$source_path/common-user/host/$host_arch"; }; then
525 error_exit "linux-user/include/host/$host_arch does not exist." \
526 "This is a bug in the configure script, please report it."
527fi
528if test -n "$linux_arch" && ! test -d "$source_path/linux-headers/asm-$linux_arch"; then
529 error_exit "linux-headers/asm-$linux_arch does not exist." \
530 "This is a bug in the configure script, please report it."
531fi
532
fee6d412 533check_py_version() {
ca056f44 534 # We require python >= 3.8.
fee6d412 535 # NB: a True python conditional creates a non-zero return code (Failure)
ca056f44 536 "$1" -c 'import sys; sys.exit(sys.version_info < (3,8))'
fee6d412
JS
537}
538
fee6d412
JS
539first_python=
540if test -z "${PYTHON}"; then
fee6d412
JS
541 # A bare 'python' is traditionally python 2.x, but some distros
542 # have it as python 3.x, so check in both places.
19a39e27
JS
543 for binary in python3 python python3.12 python3.11 \
544 python3.10 python3.9 python3.8; do
fee6d412
JS
545 if has "$binary"; then
546 python=$(command -v "$binary")
547 if check_py_version "$python"; then
548 # This one is good.
549 first_python=
550 break
551 else
552 first_python=$python
553 fi
554 fi
555 done
556else
557 # Same as above, but only check the environment variable.
558 has "${PYTHON}" || error_exit "The PYTHON environment variable does not point to an executable"
559 python=$(command -v "$PYTHON")
fee6d412
JS
560 if check_py_version "$python"; then
561 # This one is good.
562 first_python=
563 else
564 first_python=$first_python
faf44142 565 fi
fee6d412 566fi
903458c8 567
39d87c8c
AB
568# Check for ancillary tools used in testing
569genisoimage=
3df437c7 570for binary in genisoimage mkisofs
39d87c8c
AB
571do
572 if has $binary
573 then
574 genisoimage=$(command -v "$binary")
575 break
576 fi
577done
578
80100e26 579if test "$targetos" = "windows" ; then
3457a3f8 580 EXESUF=".exe"
3457a3f8
JQ
581fi
582
8154f5e6
AO
583meson_option_build_array() {
584 printf '['
c5cfdaba 585 (if test "$targetos" = windows; then
8154f5e6
AO
586 IFS=\;
587 else
588 IFS=:
589 fi
590 for e in $1; do
65842b03
PM
591 printf '"""'
592 # backslash escape any '\' and '"' characters
593 printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g'
594 printf '""",'
8154f5e6
AO
595 done)
596 printf ']\n'
597}
598
64708615 599. "$source_path/scripts/meson-buildoptions.sh"
61d63097
PB
600
601meson_options=
c54b59ee 602meson_option_add() {
ae22ae65
PB
603 local arg
604 for arg; do
605 meson_options="$meson_options $(quote_sh "$arg")"
606 done
c54b59ee 607}
61d63097
PB
608meson_option_parse() {
609 meson_options="$meson_options $(_meson_option_parse "$@")"
610 if test $? -eq 1; then
611 echo "ERROR: unknown option $1"
612 echo "Try '$0 --help' for more information"
613 exit 1
614 fi
615}
616
c36dd41b
PB
617meson_add_machine_file() {
618 if test "$cross_compile" = "yes"; then
619 meson_option_add --cross-file "$1"
620 else
621 meson_option_add --native-file "$1"
622 fi
623}
624
7d13299d 625for opt do
89138857 626 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
7d13299d 627 case "$opt" in
2efc3265
FB
628 --help|-h) show_help=yes
629 ;;
64708615 630 --version|-V) exec cat "$source_path/VERSION"
99123e13 631 ;;
ac0df51d 632 --cross-prefix=*)
7d13299d 633 ;;
ac0df51d 634 --cc=*)
7d13299d 635 ;;
b1a550a0 636 --host-cc=*) host_cc="$optarg"
83469015 637 ;;
83f73fce
TS
638 --cxx=*)
639 ;;
c0c34c91 640 --objcc=*)
3c4a4d0d 641 ;;
b17bbf83 642 --make=*)
7d13299d 643 ;;
b6daf4d3 644 --install=*)
6a882643 645 ;;
81e2b198 646 --python=*) python="$optarg"
c886edfb 647 ;;
a5665051
PB
648 --skip-meson) skip_meson=yes
649 ;;
48328880
PB
650 --ninja=*) ninja="$optarg"
651 ;;
e2a2ed06 652 --extra-cflags=*)
7d13299d 653 ;;
11cde1c8
BD
654 --extra-cxxflags=*)
655 ;;
e910c7d9
PMD
656 --extra-objcflags=*)
657 ;;
e2a2ed06 658 --extra-ldflags=*)
7d13299d 659 ;;
28609749 660 --cross-cc-*)
5bc62e01 661 ;;
5adb43be
PB
662 --cross-prefix-*)
663 ;;
6b0cedcd
JS
664 --enable-docs) docs=enabled
665 ;;
666 --disable-docs) docs=disabled
667 ;;
2ff6b91e 668 --cpu=*)
7d13299d 669 ;;
b1a550a0 670 --target-list=*) target_list="$optarg"
447e133f
AB
671 if test "$target_list_exclude"; then
672 error_exit "Can't mix --target-list with --target-list-exclude"
673 fi
674 ;;
675 --target-list-exclude=*) target_list_exclude="$optarg"
676 if test "$target_list"; then
677 error_exit "Can't mix --target-list-exclude with --target-list"
678 fi
de83cd02 679 ;;
c54b59ee 680 --with-default-devices) meson_option_add -Ddefault_devices=true
f3494749 681 ;;
c54b59ee 682 --without-default-devices) meson_option_add -Ddefault_devices=false
f3494749 683 ;;
d1d5e9ee
AB
684 --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
685 ;;
686 --with-devices-*) device_arch=${opt#--with-devices-};
687 device_arch=${device_arch%%=*}
688 cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
689 if test -f "$cf"; then
690 device_archs="$device_archs $device_arch"
691 eval "devices_${device_arch}=\$optarg"
692 else
693 error_exit "File $cf does not exist"
694 fi
695 ;;
c87ea116
AB
696 --without-default-features) # processed above
697 ;;
877c5567 698 --static) static="yes"
43ce4dfe 699 ;;
181ce1d0
OH
700 --host=*|--build=*|\
701 --disable-dependency-tracking|\
785c23ae 702 --sbindir=*|--sharedstatedir=*|\
fe0038be 703 --oldincludedir=*|--datarootdir=*|--infodir=*|\
023ddd74
MF
704 --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
705 # These switches are silently ignored, for compatibility with
706 # autoconf-generated configure scripts. This allows QEMU's
707 # configure to be used by RPM and similar macros that set
708 # lots of directory switches by default.
709 ;;
f3d08ee6
PB
710 --enable-debug)
711 # Enable debugging options that aren't excessively noisy
1d558c90 712 meson_option_parse --enable-debug-tcg ""
58a2e3f5 713 meson_option_parse --enable-debug-graph-lock ""
c55cf6ab 714 meson_option_parse --enable-debug-mutex ""
c54b59ee 715 meson_option_add -Doptimization=0
bafe78ad 716 default_cflags='-O0 -g'
0aebab04 717 ;;
1badb709 718 --disable-tcg) tcg="disabled"
b3f6ea7e 719 ;;
1badb709 720 --enable-tcg) tcg="enabled"
b3f6ea7e 721 ;;
24f9c07a 722 --disable-system) system="no"
0a8e90f4 723 ;;
24f9c07a 724 --enable-system) system="yes"
0a8e90f4 725 ;;
0953a80f
ZA
726 --disable-user)
727 linux_user="no" ;
728 bsd_user="no" ;
0953a80f
ZA
729 ;;
730 --enable-user) ;;
831b7825 731 --disable-linux-user) linux_user="no"
0a8e90f4 732 ;;
831b7825
TS
733 --enable-linux-user) linux_user="yes"
734 ;;
84778508
BS
735 --disable-bsd-user) bsd_user="no"
736 ;;
737 --enable-bsd-user) bsd_user="yes"
738 ;;
40d6444e 739 --enable-pie) pie="yes"
34005a00 740 ;;
40d6444e 741 --disable-pie) pie="no"
34005a00 742 ;;
ae22ae65 743 --enable-cfi) cfi=true
9e62ba48 744 ;;
ae22ae65 745 --disable-cfi) cfi=false
9e62ba48 746 ;;
6f3ae23b 747 --disable-download) download="disabled"; git_submodules_action=validate;
f62bbee5 748 ;;
6f3ae23b 749 --enable-download) download="enabled"; git_submodules_action=update;
0c5f3dcb 750 ;;
39fb3cfc 751 --enable-plugins) plugins="yes"
40e8c6f4
AB
752 ;;
753 --disable-plugins) plugins="no"
754 ;;
afc3a8f9
AB
755 --enable-containers) use_containers="yes"
756 ;;
757 --disable-containers) use_containers="no"
758 ;;
42ede11a
AB
759 --container-engine=*) container_engine="$optarg"
760 ;;
f48e590a
AB
761 --gdb=*) gdb_bin="$optarg"
762 ;;
3b4da132 763 # everything else has the same name in configure and meson
4fda6011 764 --*) meson_option_parse "$opt" "$optarg"
7f1559c6 765 ;;
ff136d2a
DB
766 # Pass through -Dxxxx options to meson
767 -D*) meson_options="$meson_options $opt"
768 ;;
7d13299d
FB
769 esac
770done
771
6f3ae23b
PB
772if ! test -e "$source_path/.git"
773then
8edddaa2 774 git_submodules_action="validate"
6f3ae23b
PB
775fi
776
2019cabf 777if ! test -f "$source_path/subprojects/keycodemapdb/README" \
c06b1571 778 && test "$download" = disabled
2019cabf
PB
779then
780 echo
781 echo "ERROR: missing subprojects"
782 echo
783 if test -e "$source_path/.git"; then
784 echo "--disable-download specified but subprojects were not"
785 echo 'checked out. Please invoke "meson subprojects download"'
786 echo "before configuring QEMU, or remove --disable-download"
787 echo "from the command line."
788 else
789 echo "This is not a GIT checkout but subproject content appears to"
790 echo "be missing. Do not use 'git archive' or GitHub download links"
791 echo "to acquire QEMU source archives. Non-GIT builds are only"
792 echo "supported with source archives linked from:"
793 echo
794 echo " https://www.qemu.org/download/#source"
795 echo
796 echo "Developers working with GIT can use scripts/archive-source.sh"
797 echo "if they need to create valid source archives."
798 fi
799 echo
800 exit 1
801fi
802
60e0df25 803default_target_list=""
6e92f823
PM
804mak_wilds=""
805
473cd070
PB
806if [ -n "$host_arch" ] && [ -d "$source_path/common-user/host/$host_arch" ]; then
807 if [ "$linux_user" != no ]; then
808 if [ "$targetos" = linux ]; then
809 linux_user=yes
810 elif [ "$linux_user" = yes ]; then
811 error_exit "linux-user not supported on this architecture"
812 fi
813 if [ "$linux_user" = "yes" ]; then
814 mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
815 fi
b915a2f1 816 fi
473cd070
PB
817 if [ "$bsd_user" != no ]; then
818 if [ "$bsd_user" = "" ]; then
819 test $targetos = freebsd && bsd_user=yes
820 fi
821 if [ "$bsd_user" = yes ] && ! [ -d "$source_path/bsd-user/$targetos" ]; then
822 error_exit "bsd-user not supported on this host OS"
823 fi
824 if [ "$bsd_user" = "yes" ]; then
825 mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
826 fi
b915a2f1 827 fi
473cd070
PB
828else
829 if [ "$linux_user" = yes ] || [ "$bsd_user" = yes ]; then
830 error_exit "user mode emulation not supported on this architecture"
b915a2f1
PB
831 fi
832fi
24f9c07a 833if [ "$system" = "yes" ]; then
812b31d3 834 mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
60e0df25 835fi
60e0df25 836
2d838d9b
AB
837for config in $mak_wilds; do
838 target="$(basename "$config" .mak)"
98db9a06 839 if echo "$target_list_exclude" | grep -vq "$target"; then
2d838d9b
AB
840 default_target_list="${default_target_list} $target"
841 fi
842done
6e92f823 843
af5db58e
PB
844if test x"$show_help" = x"yes" ; then
845cat << EOF
846
847Usage: configure [options]
848Options: [defaults in brackets after descriptions]
849
08fb77ed
SW
850Standard options:
851 --help print this message
74154d7e 852 --target-list=LIST set target list (default: build all)
08fb77ed
SW
853$(echo Available targets: $default_target_list | \
854 fold -s -w 53 | sed -e 's/^/ /')
447e133f 855 --target-list-exclude=LIST exclude a set of targets from the default target-list
08fb77ed
SW
856
857Advanced options (experts only):
ff136d2a 858 -Dmesonoptname=val passthrough option to meson unmodified
3812c0c4 859 --cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
08fb77ed 860 --cc=CC use C compiler CC [$cc]
3c7ee49b
PB
861 --host-cc=CC when cross compiling, use C compiler CC for code run
862 at build time [$host_cc]
08fb77ed
SW
863 --cxx=CXX use C++ compiler CXX [$cxx]
864 --objcc=OBJCC use Objective-C compiler OBJCC [$objcc]
a2866660
PB
865 --extra-cflags=CFLAGS append extra C compiler flags CFLAGS
866 --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
e910c7d9 867 --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
08fb77ed 868 --extra-ldflags=LDFLAGS append extra linker flags LDFLAGS
d75402b5 869 --cross-cc-ARCH=CC use compiler when building ARCH guest test cases
479ca4cc 870 --cross-cc-cflags-ARCH= use compiler flags when building ARCH guest tests
5adb43be 871 --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
08fb77ed 872 --python=PYTHON use specified python [$python]
48328880 873 --ninja=NINJA use specified ninja [$ninja]
08fb77ed 874 --static enable static build [$static]
c035c8d6
PB
875 --without-default-features default all --enable-* options to "disabled"
876 --without-default-devices do not include any device that is not needed to
877 start the emulator (only use if you are including
d1d5e9ee
AB
878 desired devices in configs/devices/)
879 --with-devices-ARCH=NAME override default configs/devices
08fb77ed 880 --enable-debug enable common debug build options
c23f23b9 881 --cpu=CPU Build for host CPU [$cpu]
afc3a8f9 882 --disable-containers don't use containers for cross-building
42ede11a 883 --container-engine=TYPE which container engine to use [$container_engine]
f48e590a 884 --gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
61d63097
PB
885EOF
886 meson_options_help
887cat << EOF
c23f23b9
MT
888 system all system emulation targets
889 user supported user emulation targets
890 linux-user all linux usermode emulation targets
891 bsd-user all BSD usermode emulation targets
c23f23b9 892 pie Position Independent Executables
08fb77ed
SW
893
894NOTE: The object files are built at the place where configure is launched
af5db58e 895EOF
2d2ad6d0 896exit 0
af5db58e
PB
897fi
898
9c790242 899# Remove old dependency files to make sure that they get properly regenerated
002d8c13 900rm -f ./*/config-devices.mak.d
9c790242 901
faf44142
DB
902if test -z "$python"
903then
fee6d412
JS
904 # If first_python is set, there was a binary somewhere even though
905 # it was not suitable. Use it for the error message.
906 if test -n "$first_python"; then
761f241c 907 error_exit "Cannot use '$first_python', Python >= 3.8 is required." \
fee6d412
JS
908 "Use --python=/path/to/python to specify a supported Python."
909 else
910 error_exit "Python not found. Use --python=/path/to/python"
911 fi
c53eeaf7 912fi
fee6d412 913
fee6d412 914if ! check_py_version "$python"; then
ca056f44 915 error_exit "Cannot use '$python', Python >= 3.8 is required." \
e46b82a0
JS
916 "Use --python=/path/to/python to specify a supported Python." \
917 "Maybe try:" \
918 " openSUSE Leap 15.3+: zypper install python39" \
919 " CentOS 8: dnf install python38"
c53eeaf7
SH
920fi
921
81e2b198
JS
922# Resolve PATH
923python="$(command -v "$python")"
81e2b198
JS
924
925# Create a Python virtual environment using our configured python.
926# The stdout of this script will be the location of a symlink that
927# points to the configured Python.
928# Entry point scripts for pip, meson, and sphinx are generated if those
929# packages are present.
930
931# Defaults assumed for now:
932# - venv is cleared if it exists already;
933# - venv is allowed to use system packages;
0c5f3dcb
JS
934# - all setup can be performed offline;
935# - missing packages may be fetched from PyPI,
ac4ccac7 936# unless --disable-download is passed.
81e2b198
JS
937# - pip is not installed into the venv when possible,
938# but ensurepip is called as a fallback when necessary.
939
940echo "python determined to be '$python'"
941echo "python version: $($python --version)"
942
943python="$($python -B "${source_path}/python/scripts/mkvenv.py" create pyvenv)"
944if test "$?" -ne 0 ; then
945 error_exit "python venv creation failed"
946fi
947
948# Suppress writing compiled files
949python="$python -B"
6f6652eb 950mkvenv="$python ${source_path}/python/scripts/mkvenv.py"
462a6567 951
edc21078
PB
952# Finish preparing the virtual environment using vendored .whl files
953
954if $python -c 'import sys; sys.exit(sys.version_info >= (3,11))'; then
955 $mkvenv ensure --dir "${source_path}/python/wheels" \
956 'tomli>=1.2.0' || exit 1
957fi
c853c4d0
PB
958$mkvenv ensuregroup --dir "${source_path}/python/wheels" \
959 ${source_path}/pythondeps.toml meson || exit 1
a5665051 960
66e2c6cb
JS
961# At this point, we expect Meson to be installed and available.
962# We expect mkvenv or pip to have created pyvenv/bin/meson for us.
963# We ignore PATH completely here: we want to use the venv's Meson
964# *exclusively*.
0a01d76f 965
66e2c6cb 966meson="$(cd pyvenv/bin; pwd)/meson"
0a01d76f 967
6f6652eb
JS
968# Conditionally ensure Sphinx is installed.
969
0c5f3dcb 970mkvenv_flags=""
ac4ccac7 971if test "$download" = "enabled" -a "$docs" = "enabled" ; then
0c5f3dcb
JS
972 mkvenv_flags="--online"
973fi
974
6f6652eb 975if test "$docs" != "disabled" ; then
c853c4d0 976 if ! $mkvenv ensuregroup \
0c5f3dcb 977 $mkvenv_flags \
c853c4d0 978 ${source_path}/pythondeps.toml docs;
6f6652eb
JS
979 then
980 if test "$docs" = "enabled" ; then
981 exit 1
982 fi
983 echo "Sphinx not found/usable, disabling docs."
984 docs=disabled
985 else
986 docs=enabled
987 fi
988fi
989
09e93326 990# Probe for ninja
48328880
PB
991
992if test -z "$ninja"; then
993 for c in ninja ninja-build samu; do
994 if has $c; then
995 ninja=$(command -v "$c")
996 break
997 fi
998 done
09e93326
PB
999 if test -z "$ninja"; then
1000 error_exit "Cannot find Ninja"
1001 fi
48328880 1002fi
a5665051 1003
975ff037 1004if test "$targetos" = "bogus"; then
fb59dabd
PM
1005 # Now that we know that we're not printing the help and that
1006 # the compiler works (so the results of the check_defines we used
1007 # to identify the OS are reliable), if we didn't recognize the
1008 # host OS we should stop now.
951fedfc 1009 error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
fb59dabd
PM
1010fi
1011
39fb3cfc
PB
1012# test for any invalid configuration combinations
1013if test "$targetos" = "windows"; then
1014 if test "$plugins" = "yes"; then
1015 error_exit "TCG plugins not currently supported on Windows platforms"
1016 fi
1017 plugins="no"
1018fi
1019if test "$tcg" = "disabled" ; then
1020 if test "$plugins" = "yes"; then
1021 error_exit "Can't enable plugins on non-TCG builds"
1022 fi
1023 plugins="no"
1024fi
40d6444e 1025if test "$static" = "yes" ; then
5f2453ac
AB
1026 if test "$plugins" = "yes"; then
1027 error_exit "static and plugins are mutually incompatible"
1028 fi
39fb3cfc 1029 plugins="no"
40d6444e 1030fi
39fb3cfc
PB
1031if test "$plugins" != "no"; then
1032 plugins=yes
2a5919ab
PB
1033 subdirs="$subdirs contrib/plugins"
1034fi
40d6444e 1035
b2634124 1036cat > $TMPC << EOF
21d4a791
AK
1037
1038#ifdef __linux__
1039# define THREAD __thread
1040#else
1041# define THREAD
1042#endif
21d4a791 1043static THREAD int tls_var;
21d4a791 1044int main(void) { return tls_var; }
40d6444e 1045EOF
412aeacd 1046
2e938a9a
PB
1047if test "$targetos" = windows || test "$targetos" = haiku; then
1048 if test "$pie" = "yes"; then
1049 error_exit "PIE not available due to missing OS support"
1050 fi
1051 pie=no
1052fi
1053
1054if test "$pie" != "no"; then
1055 if test "$static" = "yes"; then
1056 pie_ldflags=-static-pie
12781462 1057 else
2e938a9a 1058 pie_ldflags=-pie
12781462 1059 fi
2e938a9a 1060 if compile_prog "-Werror -fPIE -DPIE" "$pie_ldflags"; then
a988b4c5
PB
1061 pie="yes"
1062 elif test "$pie" = "yes"; then
2e938a9a 1063 error_exit "-static-pie not available due to missing toolchain support"
a988b4c5
PB
1064 else
1065 echo "Disabling PIE due to missing toolchain support"
1066 pie="no"
b9eae9ef 1067 fi
40d6444e
AK
1068fi
1069
09dada40 1070##########################################
09dada40 1071
afb63ebd 1072if test -z "${target_list+xxx}" ; then
fdb75aef 1073 default_targets=yes
d880a3ba 1074 for target in $default_target_list; do
fdb75aef 1075 target_list="$target_list $target"
d880a3ba
PB
1076 done
1077 target_list="${target_list# }"
121afa9e 1078else
fdb75aef 1079 default_targets=no
89138857 1080 target_list=$(echo "$target_list" | sed -e 's/,/ /g')
d880a3ba
PB
1081 for target in $target_list; do
1082 # Check that we recognised the target name; this allows a more
1083 # friendly error message than if we let it fall through.
1084 case " $default_target_list " in
1085 *" $target "*)
1086 ;;
1087 *)
1088 error_exit "Unknown target name '$target'"
1089 ;;
1090 esac
d880a3ba 1091 done
121afa9e 1092fi
25b48338 1093
7630156d
PMD
1094if test "$tcg" = "auto"; then
1095 if test -z "$target_list"; then
1096 tcg="disabled"
1097 else
1098 tcg="enabled"
1099 fi
1100fi
1101
a47dd5c5
PB
1102#########################################
1103# gdb test
1104
1105if test -n "$gdb_bin"; then
1106 gdb_version=$($gdb_bin --version | head -n 1)
1107 if version_ge ${gdb_version##* } 9.1; then
1108 gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
1109 else
1110 gdb_bin=""
1111 fi
1112fi
1113
33ab5f24 1114##########################################
7d13299d
FB
1115# big/little endian test
1116cat > $TMPC << EOF
33ab5f24
MP
1117#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1118# error LITTLE
1119#endif
1120int main(void) { return 0; }
7d13299d
FB
1121EOF
1122
33ab5f24
MP
1123if ! compile_prog ; then
1124 bigendian="no"
61cc919f 1125else
33ab5f24
MP
1126 cat > $TMPC << EOF
1127#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
1128# error BIG
1129#endif
1130int main(void) { return 0; }
1131EOF
1132
1133 if ! compile_prog ; then
1134 bigendian="yes"
1135 else
61cc919f 1136 echo big/little test failed
659eb157 1137 exit 1
33ab5f24 1138 fi
7d13299d
FB
1139fi
1140
cd362def
PB
1141##########################################
1142# functions to probe cross compilers
1143
1144container="no"
60f999b7 1145runc=""
47fdc8fb 1146if test $use_containers = "yes" && (has "docker" || has "podman"); then
42ede11a 1147 case $($python "$source_path"/tests/docker/docker.py --engine "$container_engine" probe) in
c4575b59
PB
1148 *docker) container=docker ;;
1149 podman) container=podman ;;
1150 no) container=no ;;
1151 esac
a3e28f81
PB
1152 if test "$container" != "no"; then
1153 docker_py="$python $source_path/tests/docker/docker.py --engine $container"
42ede11a 1154 runc=$container
a3e28f81 1155 fi
cd362def
PB
1156fi
1157
1158# cross compilers defaults, can be overridden with --cross-cc-ARCH
5adb43be
PB
1159: ${cross_prefix_aarch64="aarch64-linux-gnu-"}
1160: ${cross_prefix_aarch64_be="$cross_prefix_aarch64"}
1161: ${cross_prefix_alpha="alpha-linux-gnu-"}
1162: ${cross_prefix_arm="arm-linux-gnueabihf-"}
1163: ${cross_prefix_armeb="$cross_prefix_arm"}
1164: ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
34bb43b0 1165: ${cross_prefix_loongarch64="loongarch64-unknown-linux-gnu-"}
5adb43be
PB
1166: ${cross_prefix_hppa="hppa-linux-gnu-"}
1167: ${cross_prefix_i386="i686-linux-gnu-"}
1168: ${cross_prefix_m68k="m68k-linux-gnu-"}
1169: ${cross_prefix_microblaze="microblaze-linux-musl-"}
1170: ${cross_prefix_mips64el="mips64el-linux-gnuabi64-"}
1171: ${cross_prefix_mips64="mips64-linux-gnuabi64-"}
1172: ${cross_prefix_mipsel="mipsel-linux-gnu-"}
1173: ${cross_prefix_mips="mips-linux-gnu-"}
1174: ${cross_prefix_nios2="nios2-linux-gnu-"}
1175: ${cross_prefix_ppc="powerpc-linux-gnu-"}
1176: ${cross_prefix_ppc64="powerpc64-linux-gnu-"}
1177: ${cross_prefix_ppc64le="$cross_prefix_ppc64"}
1178: ${cross_prefix_riscv64="riscv64-linux-gnu-"}
1179: ${cross_prefix_s390x="s390x-linux-gnu-"}
1180: ${cross_prefix_sh4="sh4-linux-gnu-"}
1181: ${cross_prefix_sparc64="sparc64-linux-gnu-"}
1182: ${cross_prefix_sparc="$cross_prefix_sparc64"}
a3d3de8e 1183: ${cross_prefix_tricore="tricore-"}
5adb43be
PB
1184: ${cross_prefix_x86_64="x86_64-linux-gnu-"}
1185
cd362def
PB
1186: ${cross_cc_aarch64_be="$cross_cc_aarch64"}
1187: ${cross_cc_cflags_aarch64_be="-mbig-endian"}
46af66ed 1188: ${cross_cc_armeb="$cross_cc_arm"}
cd362def
PB
1189: ${cross_cc_cflags_armeb="-mbig-endian"}
1190: ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
fc2622f6 1191: ${cross_cc_cflags_hexagon="-mv73 -O2 -static"}
cd362def 1192: ${cross_cc_cflags_i386="-m32"}
d44f2f96 1193: ${cross_cc_cflags_ppc="-m32 -mbig-endian"}
cd362def
PB
1194: ${cross_cc_cflags_ppc64="-m64 -mbig-endian"}
1195: ${cross_cc_ppc64le="$cross_cc_ppc64"}
1196: ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"}
cd362def 1197: ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
46af66ed
PB
1198: ${cross_cc_sparc="$cross_cc_sparc64"}
1199: ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
cd362def
PB
1200: ${cross_cc_cflags_x86_64="-m64"}
1201
5adb43be 1202compute_target_variable() {
92e288fc 1203 eval "$2="
5adb43be
PB
1204 if eval test -n "\"\${cross_prefix_$1}\""; then
1205 if eval has "\"\${cross_prefix_$1}\$3\""; then
1206 eval "$2=\"\${cross_prefix_$1}\$3\""
1207 fi
1208 fi
1209}
cd362def 1210
35fd22b0
PB
1211have_target() {
1212 for i; do
1213 case " $target_list " in
1214 *" $i "*) return 0;;
1215 *) ;;
1216 esac
1217 done
1218 return 1
1219}
1220
52f08dea
PB
1221# probe_target_compiler TARGET
1222#
1223# Look for a compiler for the given target, either native or cross.
1224# Set variables target_* if a compiler is found, and container_cross_*
1225# if a Docker-based cross-compiler image is known for the target.
1226# Set got_cross_cc to yes/no depending on whether a non-container-based
1227# compiler was found.
1228#
1229# If TARGET is a user-mode emulation target, also set build_static to
1230# "y" if static linking is possible.
1231#
cd362def
PB
1232probe_target_compiler() {
1233 # reset all output variables
92e288fc 1234 got_cross_cc=no
cd362def
PB
1235 container_image=
1236 container_hosts=
1237 container_cross_cc=
87eb014c 1238 container_cross_ar=
cd362def
PB
1239 container_cross_as=
1240 container_cross_ld=
87eb014c
PB
1241 container_cross_nm=
1242 container_cross_objcopy=
1243 container_cross_ranlib=
1244 container_cross_strip=
cd362def 1245
52f08dea
PB
1246 target_arch=${1%%-*}
1247 case $target_arch in
cd362def
PB
1248 aarch64) container_hosts="x86_64 aarch64" ;;
1249 alpha) container_hosts=x86_64 ;;
1250 arm) container_hosts="x86_64 aarch64" ;;
1251 cris) container_hosts=x86_64 ;;
1252 hexagon) container_hosts=x86_64 ;;
1253 hppa) container_hosts=x86_64 ;;
1254 i386) container_hosts=x86_64 ;;
b70ec50b 1255 loongarch64) container_hosts=x86_64 ;;
cd362def
PB
1256 m68k) container_hosts=x86_64 ;;
1257 microblaze) container_hosts=x86_64 ;;
1258 mips64el) container_hosts=x86_64 ;;
1259 mips64) container_hosts=x86_64 ;;
1260 mipsel) container_hosts=x86_64 ;;
1261 mips) container_hosts=x86_64 ;;
1262 nios2) container_hosts=x86_64 ;;
1263 ppc) container_hosts=x86_64 ;;
1264 ppc64|ppc64le) container_hosts=x86_64 ;;
1265 riscv64) container_hosts=x86_64 ;;
1266 s390x) container_hosts=x86_64 ;;
1267 sh4) container_hosts=x86_64 ;;
1268 sparc64) container_hosts=x86_64 ;;
1269 tricore) container_hosts=x86_64 ;;
a04f3372 1270 x86_64) container_hosts="aarch64 ppc64le x86_64" ;;
cd362def
PB
1271 xtensa*) container_hosts=x86_64 ;;
1272 esac
1273
1274 for host in $container_hosts; do
1275 test "$container" != no || continue
1276 test "$host" = "$cpu" || continue
52f08dea 1277 case $target_arch in
cd362def
PB
1278 aarch64)
1279 # We don't have any bigendian build tools so we only use this for AArch64
1280 container_image=debian-arm64-cross
5adb43be 1281 container_cross_prefix=aarch64-linux-gnu-
e0f89512 1282 container_cross_cc=${container_cross_prefix}gcc
cd362def 1283 ;;
d004e27b
AB
1284 alpha)
1285 container_image=debian-legacy-test-cross
1286 container_cross_prefix=alpha-linux-gnu-
1287 container_cross_cc=${container_cross_prefix}gcc
1288 ;;
cd362def
PB
1289 arm)
1290 # We don't have any bigendian build tools so we only use this for ARM
1291 container_image=debian-armhf-cross
5adb43be 1292 container_cross_prefix=arm-linux-gnueabihf-
cd362def
PB
1293 ;;
1294 cris)
1295 container_image=fedora-cris-cross
5adb43be 1296 container_cross_prefix=cris-linux-gnu-
cd362def
PB
1297 ;;
1298 hexagon)
1299 container_image=debian-hexagon-cross
5adb43be
PB
1300 container_cross_prefix=hexagon-unknown-linux-musl-
1301 container_cross_cc=${container_cross_prefix}clang
cd362def 1302 ;;
95f5bf95
AB
1303 hppa)
1304 container_image=debian-all-test-cross
1305 container_cross_prefix=hppa-linux-gnu-
1306 container_cross_cc=${container_cross_prefix}gcc
1307 ;;
cd362def
PB
1308 i386)
1309 container_image=fedora-i386-cross
5adb43be 1310 container_cross_prefix=
cd362def 1311 ;;
b70ec50b
RH
1312 loongarch64)
1313 container_image=debian-loongarch-cross
1314 container_cross_prefix=loongarch64-unknown-linux-gnu-
1315 ;;
cd362def
PB
1316 microblaze)
1317 container_image=debian-microblaze-cross
5adb43be 1318 container_cross_prefix=microblaze-linux-musl-
cd362def
PB
1319 ;;
1320 mips64el)
1321 container_image=debian-mips64el-cross
5adb43be 1322 container_cross_prefix=mips64el-linux-gnuabi64-
cd362def
PB
1323 ;;
1324 mips64)
1325 container_image=debian-mips64-cross
5adb43be 1326 container_cross_prefix=mips64-linux-gnuabi64-
cd362def 1327 ;;
cd362def
PB
1328 nios2)
1329 container_image=debian-nios2-cross
5adb43be 1330 container_cross_prefix=nios2-linux-gnu-
cd362def
PB
1331 ;;
1332 ppc)
eb4cb4ed 1333 container_image=debian-all-test-cross
5adb43be 1334 container_cross_prefix=powerpc-linux-gnu-
e0f89512 1335 container_cross_cc=${container_cross_prefix}gcc
cd362def
PB
1336 ;;
1337 ppc64|ppc64le)
eb4cb4ed 1338 container_image=debian-all-test-cross
705c881f 1339 container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu-
cd362def 1340 ;;
4e76d98a
AB
1341 sh4)
1342 container_image=debian-legacy-test-cross
1343 container_cross_prefix=sh4-linux-gnu-
1344 ;;
cd362def
PB
1345 tricore)
1346 container_image=debian-tricore-cross
5adb43be 1347 container_cross_prefix=tricore-
cd362def
PB
1348 ;;
1349 x86_64)
1350 container_image=debian-amd64-cross
5adb43be 1351 container_cross_prefix=x86_64-linux-gnu-
cd362def
PB
1352 ;;
1353 xtensa*)
cd362def
PB
1354 container_image=debian-xtensa-cross
1355
1356 # default to the dc232b cpu
5adb43be 1357 container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
cd362def 1358 ;;
17599573
PB
1359 *)
1360 # Debian and GNU architecture names usually match
1361 container_image=debian-$target_arch-cross
1362 container_cross_prefix=$target_arch-linux-gnu-
1363 ;;
cd362def 1364 esac
5adb43be 1365 : ${container_cross_cc:=${container_cross_prefix}gcc}
87eb014c 1366 : ${container_cross_ar:=${container_cross_prefix}ar}
5adb43be
PB
1367 : ${container_cross_as:=${container_cross_prefix}as}
1368 : ${container_cross_ld:=${container_cross_prefix}ld}
87eb014c
PB
1369 : ${container_cross_nm:=${container_cross_prefix}nm}
1370 : ${container_cross_objcopy:=${container_cross_prefix}objcopy}
1371 : ${container_cross_ranlib:=${container_cross_prefix}ranlib}
1372 : ${container_cross_strip:=${container_cross_prefix}strip}
cd362def
PB
1373 done
1374
92e288fc 1375 try=cross
52f08dea 1376 case "$target_arch:$cpu" in
26e72533
PB
1377 aarch64_be:aarch64 | \
1378 armeb:arm | \
640aabc8 1379 i386:x86_64 | \
26e72533 1380 mips*:mips64 | \
d44f2f96 1381 ppc*:ppc64 | \
26e72533 1382 sparc:sparc64 | \
640aabc8 1383 "$cpu:$cpu")
92e288fc 1384 try='native cross' ;;
640aabc8 1385 esac
92e288fc 1386 eval "target_cflags=\${cross_cc_cflags_$target_arch}"
b3b5472d
PM
1387 for thistry in $try; do
1388 case $thistry in
92e288fc
PB
1389 native)
1390 target_cc=$cc
1391 target_ccas=$ccas
1392 target_ar=$ar
1393 target_as=$as
1394 target_ld=$ld
1395 target_nm=$nm
1396 target_objcopy=$objcopy
1397 target_ranlib=$ranlib
1398 target_strip=$strip
1399 ;;
1400 cross)
1401 target_cc=
1402 if eval test -n "\"\${cross_cc_$target_arch}\""; then
1403 if eval has "\"\${cross_cc_$target_arch}\""; then
1404 eval "target_cc=\"\${cross_cc_$target_arch}\""
1405 fi
1406 else
1407 compute_target_variable $target_arch target_cc gcc
1408 fi
1409 target_ccas=$target_cc
1410 compute_target_variable $target_arch target_ar ar
1411 compute_target_variable $target_arch target_as as
1412 compute_target_variable $target_arch target_ld ld
1413 compute_target_variable $target_arch target_nm nm
1414 compute_target_variable $target_arch target_objcopy objcopy
1415 compute_target_variable $target_arch target_ranlib ranlib
1416 compute_target_variable $target_arch target_strip strip
1417 ;;
1418 esac
1419
1420 if test -n "$target_cc"; then
1421 case $target_arch in
1422 i386|x86_64)
1423 if $target_cc --version | grep -qi "clang"; then
1424 continue
1425 fi
1426 ;;
1427 esac
1428 elif test -n "$target_as" && test -n "$target_ld"; then
1429 # Special handling for assembler only targets
1430 case $target in
1431 tricore-softmmu)
1432 build_static=
1433 got_cross_cc=yes
1434 break
1435 ;;
1436 *)
1437 continue
1438 ;;
1439 esac
1440 else
1441 continue
1442 fi
1443
1444 write_c_skeleton
1445 case $1 in
1446 *-softmmu)
1447 if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC &&
1448 do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then
1449 got_cross_cc=yes
1450 break
1451 fi
1452 ;;
1453 *)
1454 if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC -static ; then
1455 build_static=y
1456 got_cross_cc=yes
1457 break
1458 fi
1459 if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC ; then
1460 build_static=
1461 got_cross_cc=yes
1462 break
2ad60f6f
PB
1463 fi
1464 ;;
1465 esac
92e288fc
PB
1466 done
1467 if test $got_cross_cc != yes; then
1468 build_static=
1469 target_cc=
1470 target_ccas=
92e288fc
PB
1471 target_ar=
1472 target_as=
1473 target_ld=
1474 target_nm=
1475 target_objcopy=
1476 target_ranlib=
1477 target_strip=
2ad60f6f 1478 fi
fde10960 1479 test -n "$target_cc"
cd362def
PB
1480}
1481
1482write_target_makefile() {
e81785ab 1483 echo "EXTRA_CFLAGS=$target_cflags"
0825cae0
PB
1484 if test -z "$target_cc" && test -z "$target_as"; then
1485 test -z "$container_image" && error_exit "Internal error: could not find cross compiler for $1?"
1486 echo "$1: docker-image-$container_image" >> Makefile.prereqs
1487 if test -n "$container_cross_cc"; then
1488 echo "CC=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
1489 echo "CCAS=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
1490 fi
1491 echo "AR=$docker_py cc --cc $container_cross_ar -i qemu/$container_image -s $source_path --"
1492 echo "AS=$docker_py cc --cc $container_cross_as -i qemu/$container_image -s $source_path --"
1493 echo "LD=$docker_py cc --cc $container_cross_ld -i qemu/$container_image -s $source_path --"
1494 echo "NM=$docker_py cc --cc $container_cross_nm -i qemu/$container_image -s $source_path --"
1495 echo "OBJCOPY=$docker_py cc --cc $container_cross_objcopy -i qemu/$container_image -s $source_path --"
1496 echo "RANLIB=$docker_py cc --cc $container_cross_ranlib -i qemu/$container_image -s $source_path --"
1497 echo "STRIP=$docker_py cc --cc $container_cross_strip -i qemu/$container_image -s $source_path --"
1498 else
1499 if test -n "$target_cc"; then
1500 echo "CC=$target_cc"
1501 echo "CCAS=$target_ccas"
1502 fi
1503 if test -n "$target_ar"; then
1504 echo "AR=$target_ar"
1505 fi
1506 if test -n "$target_as"; then
1507 echo "AS=$target_as"
1508 fi
1509 if test -n "$target_ld"; then
1510 echo "LD=$target_ld"
1511 fi
1512 if test -n "$target_nm"; then
1513 echo "NM=$target_nm"
1514 fi
1515 if test -n "$target_objcopy"; then
1516 echo "OBJCOPY=$target_objcopy"
1517 fi
1518 if test -n "$target_ranlib"; then
1519 echo "RANLIB=$target_ranlib"
1520 fi
1521 if test -n "$target_strip"; then
1522 echo "STRIP=$target_strip"
1523 fi
cd362def 1524 fi
cd362def
PB
1525}
1526
33ab4787
PB
1527#######################################
1528# cross-compiled firmware targets
1529
ad388845
PB
1530# Set up build tree symlinks that point back into the source tree
1531# (these can be both files and directories).
1532# Caution: avoid adding files or directories here using wildcards. This
1533# will result in problems later if a new file matching the wildcard is
1534# added to the source tree -- nothing will cause configure to be rerun
1535# so the build tree will be missing the link back to the new file, and
1536# tests might fail. Prefer to keep the relevant files in their own
1537# directory and symlink the directory instead.
1538LINKS="Makefile"
201aa17e 1539LINKS="$LINKS docs/config"
ad388845
PB
1540LINKS="$LINKS pc-bios/optionrom/Makefile"
1541LINKS="$LINKS pc-bios/s390-ccw/Makefile"
d695918f 1542LINKS="$LINKS pc-bios/vof/Makefile"
ad388845
PB
1543LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
1544LINKS="$LINKS tests/avocado tests/data"
1545LINKS="$LINKS tests/qemu-iotests/check"
1546LINKS="$LINKS python"
1547LINKS="$LINKS contrib/plugins/Makefile "
1548for f in $LINKS ; do
1549 if [ -e "$source_path/$f" ]; then
ad388845
PB
1550 symlink "$source_path/$f" "$f"
1551 fi
1552done
1553
b898bf28
PB
1554echo "# Automatically generated by configure - do not modify" > Makefile.prereqs
1555
ca35f780 1556# Mac OS X ships with a broken assembler
35fd22b0
PB
1557if have_target i386-softmmu x86_64-softmmu && \
1558 test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
1559 test "$targetos" != "haiku" && \
61cbb356 1560 probe_target_compiler i386-softmmu; then
2a5919ab 1561 subdirs="$subdirs pc-bios/optionrom"
7089977a
PB
1562 config_mak=pc-bios/optionrom/config.mak
1563 echo "# Automatically generated by configure - do not modify" > $config_mak
1564 echo "TOPSRC_DIR=$source_path" >> $config_mak
fde10960 1565 write_target_makefile >> $config_mak
ca35f780 1566fi
ca35f780 1567
35fd22b0
PB
1568if have_target ppc-softmmu ppc64-softmmu && \
1569 probe_target_compiler ppc-softmmu; then
2a5919ab 1570 subdirs="$subdirs pc-bios/vof"
d695918f
PB
1571 config_mak=pc-bios/vof/config.mak
1572 echo "# Automatically generated by configure - do not modify" > $config_mak
1573 echo "SRC_DIR=$source_path/pc-bios/vof" >> $config_mak
fde10960 1574 write_target_makefile >> $config_mak
d695918f
PB
1575fi
1576
9ffed426
PB
1577# Only build s390-ccw bios if the compiler has -march=z900 or -march=z10
1578# (which is the lowest architecture level that Clang supports)
b11f9bd9
PB
1579if have_target s390x-softmmu && probe_target_compiler s390x-softmmu && \
1580 GIT=git "$source_path/scripts/git-submodule.sh" "$git_submodules_action" roms/SLOF >> config.log 2>&1; then
fde10960
AB
1581 write_c_skeleton
1582 do_compiler "$target_cc" $target_cc_cflags -march=z900 -o $TMPO -c $TMPC
1583 has_z900=$?
1584 if [ $has_z900 = 0 ] || do_compiler "$target_cc" $target_cc_cflags -march=z10 -msoft-float -Werror -o $TMPO -c $TMPC; then
1585 if [ $has_z900 != 0 ]; then
1586 echo "WARNING: Your compiler does not support the z900!"
1587 echo " The s390-ccw bios will only work with guest CPUs >= z10."
a5b2afd5 1588 fi
2a5919ab 1589 subdirs="$subdirs pc-bios/s390-ccw"
9ffed426
PB
1590 config_mak=pc-bios/s390-ccw/config-host.mak
1591 echo "# Automatically generated by configure - do not modify" > $config_mak
1592 echo "SRC_PATH=$source_path/pc-bios/s390-ccw" >> $config_mak
b11f9bd9 1593 echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_mak
fde10960 1594 write_target_makefile >> $config_mak
2e33c3f8 1595 fi
9933c305
CB
1596fi
1597
9ffed426
PB
1598#######################################
1599# generate config-host.mak
1600
98ec69ac 1601config_host_mak="config-host.mak"
98ec69ac 1602
98ec69ac 1603echo "# Automatically generated by configure - do not modify" > $config_host_mak
98ec69ac 1604echo >> $config_host_mak
98ec69ac 1605
e6c3b0f7 1606echo all: >> $config_host_mak
804edf29 1607
98ec69ac 1608echo "SRC_PATH=$source_path" >> $config_host_mak
2b1f35b9 1609echo "TARGET_DIRS=$target_list" >> $config_host_mak
a47dd5c5 1610echo "GDB=$gdb_bin" >> $config_host_mak
c4575b59 1611if test "$container" != no; then
60f999b7 1612 echo "RUNC=$runc" >> $config_host_mak
c4575b59 1613fi
2a5919ab 1614echo "SUBDIRS=$subdirs" >> $config_host_mak
c886edfb 1615echo "PYTHON=$python" >> $config_host_mak
39d87c8c 1616echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
a5665051 1617echo "MESON=$meson" >> $config_host_mak
09e93326 1618echo "NINJA=$ninja" >> $config_host_mak
804edf29 1619echo "EXESUF=$EXESUF" >> $config_host_mak
804edf29 1620
971fac27 1621# use included Linux headers for KVM architectures
80100e26 1622if test "$targetos" = "linux" && test -n "$linux_arch"; then
971fac27 1623 symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
6efd7517
PM
1624fi
1625
1d14ffa9 1626for target in $target_list; do
fdb75aef 1627 target_dir="$target"
57a93f16 1628 target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
fdb75aef
PB
1629 case $target in
1630 *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
1631 *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
1632 esac
1633done
7d13299d 1634
fdb75aef
PB
1635if test "$default_targets" = "yes"; then
1636 echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
1637fi
a540f158 1638
bafe78ad
PB
1639# contrib/plugins configuration
1640echo "# Automatically generated by configure - do not modify" > contrib/plugins/$config_host_mak
1641echo "SRC_PATH=$source_path/contrib/plugins" >> contrib/plugins/$config_host_mak
1642echo "PKG_CONFIG=${pkg_config}" >> contrib/plugins/$config_host_mak
1643echo "CC=$cc $CPU_CFLAGS" >> contrib/plugins/$config_host_mak
1644echo "CFLAGS=${CFLAGS-$default_cflags} $EXTRA_CFLAGS" >> contrib/plugins/$config_host_mak
1645if test "$targetos" = darwin; then
1646 echo "CONFIG_DARWIN=y" >> contrib/plugins/$config_host_mak
1647fi
1648
cd362def 1649# tests/tcg configuration
b898bf28 1650(config_host_mak=tests/tcg/config-host.mak
d674342e 1651mkdir -p tests/tcg
cd362def
PB
1652echo "# Automatically generated by configure - do not modify" > $config_host_mak
1653echo "SRC_PATH=$source_path" >> $config_host_mak
cd362def
PB
1654
1655tcg_tests_targets=
1656for target in $target_list; do
1657 arch=${target%%-*}
1658
cd362def 1659 case $target in
c48a5c47 1660 xtensa*-linux-user)
24f9c07a 1661 # the toolchain is not complete with headers, only build system tests
c48a5c47
PB
1662 continue
1663 ;;
cd362def 1664 *-softmmu)
64708615 1665 test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || continue
cd362def
PB
1666 qemu="qemu-system-$arch"
1667 ;;
1668 *-linux-user|*-bsd-user)
1669 qemu="qemu-$arch"
1670 ;;
1671 esac
1672
fde10960 1673 if probe_target_compiler $target || test -n "$container_image"; then
0825cae0 1674 test -n "$container_image" && build_static=y
d674342e 1675 mkdir -p "tests/tcg/$target"
c7022a70 1676 config_target_mak=tests/tcg/$target/config-target.mak
d674342e 1677 ln -sf "$source_path/tests/tcg/Makefile.target" "tests/tcg/$target/Makefile"
c7022a70
PB
1678 echo "# Automatically generated by configure - do not modify" > "$config_target_mak"
1679 echo "TARGET_NAME=$arch" >> "$config_target_mak"
a3e28f81 1680 echo "TARGET=$target" >> "$config_target_mak"
c7022a70 1681 write_target_makefile "build-tcg-tests-$target" >> "$config_target_mak"
15b273f8 1682 echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
c7022a70 1683 echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
bcbc36a9
AB
1684
1685 # will GDB work with these binaries?
1686 if test "${gdb_arches#*$arch}" != "$gdb_arches"; then
a47dd5c5 1687 echo "GDB=$gdb_bin" >> $config_target_mak
bcbc36a9
AB
1688 fi
1689
b898bf28 1690 echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs
cd362def
PB
1691 tcg_tests_targets="$tcg_tests_targets $target"
1692 fi
2038f8c8 1693done
c0031d38
FR
1694
1695if test "$tcg" = "enabled"; then
1696 echo "TCG_TESTS_TARGETS=$tcg_tests_targets" >> config-host.mak
1697fi
1698)
2038f8c8 1699
a5665051 1700if test "$skip_meson" = no; then
d77e90fa
PB
1701 cross="config-meson.cross.new"
1702 meson_quote() {
ac7ebcc5 1703 test $# = 0 && return
47b30835 1704 echo "'$(echo $* | sed "s/ /','/g")'"
d77e90fa
PB
1705 }
1706
1707 echo "# Automatically generated by configure - do not modify" > $cross
1708 echo "[properties]" >> $cross
d1d5e9ee
AB
1709
1710 # unroll any custom device configs
11bdcfcd
AB
1711 for a in $device_archs; do
1712 eval "c=\$devices_${a}"
1713 echo "${a}-softmmu = '$c'" >> $cross
1714 done
d1d5e9ee 1715
d77e90fa 1716 echo "[built-in options]" >> $cross
a2866660
PB
1717 echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
1718 echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
e910c7d9 1719 test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
a2866660
PB
1720 echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
1721 echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
090a188c
PB
1722
1723 # Only enable by default for git builds and on select OSes
1724 echo "# environment defaults, can still be overridden on " >> $cross
1725 echo "# the command line" >> $cross
1726 if test -e "$source_path/.git" && \
1727 { test "$targetos" = linux || test "$targetos" = "windows"; }; then
1728 echo 'werror = true' >> $cross
1729 fi
1730 echo "[project options]" >> $cross
1731 if test "$SMBD" != ''; then
1732 echo "smbd = $(meson_quote "$SMBD")" >> $cross
1733 fi
e20d68aa
PB
1734 if test "${QEMU_GA_MANUFACTURER}" != ''; then
1735 echo "qemu_ga_manufacturer = $(meson_quote "${QEMU_GA_MANUFACTURER}")" >> $cross
1736 fi
1737 if test "${QEMU_GA_DISTRO}" != ''; then
1738 echo "qemu_ga_distro = $(meson_quote "${QEMU_GA_DISTRO}")" >> $cross
1739 fi
1740 if test "${QEMU_GA_VERSION}" != ''; then
1741 echo "qemu_ga_version = $(meson_quote "${QEMU_GA_VERSION}")" >> $cross
1742 fi
090a188c
PB
1743
1744 echo >> $cross
d77e90fa 1745 echo "[binaries]" >> $cross
4dba2789
PB
1746 echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
1747 test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
1748 test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
d77e90fa
PB
1749 echo "ar = [$(meson_quote $ar)]" >> $cross
1750 echo "nm = [$(meson_quote $nm)]" >> $cross
877c5567 1751 echo "pkgconfig = [$(meson_quote $pkg_config)]" >> $cross
52814898 1752 echo "pkg-config = [$(meson_quote $pkg_config)]" >> $cross
d77e90fa
PB
1753 echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
1754 if has $sdl2_config; then
1755 echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
1756 fi
1757 echo "strip = [$(meson_quote $strip)]" >> $cross
158bb224 1758 echo "widl = [$(meson_quote $widl)]" >> $cross
d77e90fa 1759 echo "windres = [$(meson_quote $windres)]" >> $cross
f9f0e617 1760 echo "windmc = [$(meson_quote $windmc)]" >> $cross
d77e90fa 1761 if test "$cross_compile" = "yes"; then
fc929892 1762 echo "[host_machine]" >> $cross
ba7c60c2 1763 echo "system = '$targetos'" >> $cross
823eb013 1764 case "$cpu" in
f6bca9df 1765 i386)
fc929892
MAL
1766 echo "cpu_family = 'x86'" >> $cross
1767 ;;
fc929892 1768 *)
823eb013 1769 echo "cpu_family = '$cpu'" >> $cross
fc929892
MAL
1770 ;;
1771 esac
1772 echo "cpu = '$cpu'" >> $cross
1773 if test "$bigendian" = "yes" ; then
1774 echo "endian = 'big'" >> $cross
1775 else
1776 echo "endian = 'little'" >> $cross
1777 fi
3c7ee49b
PB
1778
1779 native="config-meson.native.new"
1780 echo "# Automatically generated by configure - do not modify" > $native
1781 echo "[binaries]" >> $native
1782 echo "c = [$(meson_quote $host_cc)]" >> $native
1783 mv $native config-meson.native
c36dd41b
PB
1784 meson_option_add --native-file
1785 meson_option_add config-meson.native
d77e90fa
PB
1786 fi
1787 mv $cross config-meson.cross
c36dd41b
PB
1788 meson_add_machine_file config-meson.cross
1789 if test -f "$source_path/configs/meson/$targetos.txt"; then
1790 meson_add_machine_file $source_path/configs/meson/$targetos.txt
1791 fi
fc929892 1792
d77e90fa 1793 rm -rf meson-private meson-info meson-logs
0a31e3a0 1794
ac4ccac7 1795 test "$download" = "disabled" && meson_option_add "--wrap-mode=nodownload"
0a31e3a0 1796 test "$default_feature" = no && meson_option_add -Dauto_features=disabled
a0cbd2e8 1797 test "$static" = yes && meson_option_add -Dprefer_static=true
0a31e3a0 1798 test "$pie" = no && meson_option_add -Db_pie=false
0a31e3a0
PB
1799
1800 # QEMU options
ae22ae65 1801 test "$cfi" != false && meson_option_add "-Dcfi=$cfi" "-Db_lto=$cfi"
6b0cedcd 1802 test "$docs" != auto && meson_option_add "-Ddocs=$docs"
0a31e3a0 1803 test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
2c13c574 1804 test "$plugins" = yes && meson_option_add "-Dplugins=true"
0a31e3a0 1805 test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
61d63097 1806 run_meson() {
c36dd41b 1807 NINJA=$ninja $meson setup "$@" "$PWD" "$source_path"
61d63097
PB
1808 }
1809 eval run_meson $meson_options
d77e90fa
PB
1810 if test "$?" -ne 0 ; then
1811 error_exit "meson setup failed"
1812 fi
6c5f893d 1813 echo "$meson" > build.ninja.stamp
973038db
PB
1814else
1815 if test -f meson-private/cmd_line.txt; then
1816 # Adjust old command line options that were removed
1817 # sed -i is not portable
1818 perl -i -ne '
1819 /^sphinx_build/ && next;
1820 print;' meson-private/cmd_line.txt
1821 fi
a5665051
PB
1822fi
1823
dc655404
MT
1824# Save the configure command line for later reuse.
1825cat <<EOD >config.status
1826#!/bin/sh
1827# Generated by configure.
1828# Run this file to recreate the current configuration.
1829# Compiler output produced by configure, useful for debugging
1830# configure, is in config.log if it exists.
1831EOD
e811da7f
DB
1832
1833preserve_env() {
1834 envname=$1
1835
1836 eval envval=\$$envname
1837
1838 if test -n "$envval"
1839 then
1840 echo "$envname='$envval'" >> config.status
1841 echo "export $envname" >> config.status
1842 else
1843 echo "unset $envname" >> config.status
1844 fi
1845}
1846
1847# Preserve various env variables that influence what
1848# features/build target configure will detect
1849preserve_env AR
1850preserve_env AS
1851preserve_env CC
8009da03 1852preserve_env CFLAGS
e811da7f 1853preserve_env CXX
8009da03 1854preserve_env CXXFLAGS
e811da7f 1855preserve_env LD
8009da03 1856preserve_env LDFLAGS
e811da7f 1857preserve_env LD_LIBRARY_PATH
e811da7f 1858preserve_env NM
b5569e5b 1859preserve_env OBJCFLAGS
e811da7f
DB
1860preserve_env OBJCOPY
1861preserve_env PATH
1862preserve_env PKG_CONFIG
1863preserve_env PKG_CONFIG_LIBDIR
1864preserve_env PKG_CONFIG_PATH
1865preserve_env PYTHON
954ed68f
PB
1866preserve_env QEMU_GA_MANUFACTURER
1867preserve_env QEMU_GA_DISTRO
1868preserve_env QEMU_GA_VERSION
e811da7f
DB
1869preserve_env SDL2_CONFIG
1870preserve_env SMBD
1871preserve_env STRIP
158bb224 1872preserve_env WIDL
e811da7f 1873preserve_env WINDRES
f9f0e617 1874preserve_env WINDMC
e811da7f 1875
dc655404 1876printf "exec" >>config.status
a5665051 1877for i in "$0" "$@"; do
835af899 1878 test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
a5665051 1879done
cf7cc929 1880echo ' "$@"' >>config.status
dc655404
MT
1881chmod +x config.status
1882
8cd05ab6 1883rm -r "$TMPDIR1"