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