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