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