]> git.proxmox.com Git - mirror_qemu.git/blame - configure
Partially revert "build: -no-pie is no functional linker flag"
[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
34 mkdir build
35 touch $MARKER
36
37 cat > GNUmakefile <<'EOF'
38# This file is auto-generated by configure to support in-source tree
39# 'make' command invocation
40
41ifeq ($(MAKECMDGOALS),)
42recurse: all
43endif
44
45.NOTPARALLEL: %
46%: force
47 @echo 'changing dir to build for $(MAKE) "$(MAKECMDGOALS)"...'
48 @$(MAKE) -C build -f Makefile $(MAKECMDGOALS)
49 @if test "$(MAKECMDGOALS)" = "distclean" && \
50 test -e build/auto-created-by-configure ; \
51 then \
52 rm -rf build GNUmakefile ; \
53 fi
54force: ;
55.PHONY: force
56GNUmakefile: ;
57
58EOF
59 cd build
60 exec $source_path/configure "$@"
61fi
62
8cd05ab6
PM
63# Temporary directory used for files created while
64# configure runs. Since it is in the build directory
65# we can safely blow away any previous version of it
66# (and we need not jump through hoops to try to delete
67# it when configure exits.)
68TMPDIR1="config-temp"
69rm -rf "${TMPDIR1}"
70mkdir -p "${TMPDIR1}"
71if [ $? -ne 0 ]; then
72 echo "ERROR: failed to create temporary directory"
73 exit 1
7d13299d
FB
74fi
75
8cd05ab6
PM
76TMPB="qemu-conf"
77TMPC="${TMPDIR1}/${TMPB}.c"
66518bf6 78TMPO="${TMPDIR1}/${TMPB}.o"
9c83ffd8 79TMPCXX="${TMPDIR1}/${TMPB}.cxx"
8cd05ab6 80TMPE="${TMPDIR1}/${TMPB}.exe"
26fffe29 81TMPTXT="${TMPDIR1}/${TMPB}.txt"
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
PM
87printf "# Configured with:" >> config.log
88printf " '%s'" "$0" "$@" >> config.log
89echo >> config.log
b48e3611
PM
90echo "#" >> config.log
91
835af899
PB
92quote_sh() {
93 printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
94}
95
d880a3ba
PB
96print_error() {
97 (echo
76ad07a4
PM
98 echo "ERROR: $1"
99 while test -n "$2"; do
100 echo " $2"
101 shift
102 done
d880a3ba
PB
103 echo) >&2
104}
105
106error_exit() {
107 print_error "$@"
76ad07a4
PM
108 exit 1
109}
110
9c83ffd8
PM
111do_compiler() {
112 # Run the compiler, capturing its output to the log. First argument
113 # is compiler binary to execute.
630d86b7 114 compiler="$1"
9c83ffd8 115 shift
8bbe05d7
IJ
116 if test -n "$BASH_VERSION"; then eval '
117 echo >>config.log "
118funcs: ${FUNCNAME[*]}
119lines: ${BASH_LINENO[*]}"
120 '; fi
9c83ffd8
PM
121 echo $compiler "$@" >> config.log
122 $compiler "$@" >> config.log 2>&1 || return $?
8dc38a78
PM
123 # Test passed. If this is an --enable-werror build, rerun
124 # the test with -Werror and bail out if it fails. This
125 # makes warning-generating-errors in configure test code
126 # obvious to developers.
127 if test "$werror" != "yes"; then
128 return 0
129 fi
130 # Don't bother rerunning the compile if we were already using -Werror
131 case "$*" in
132 *-Werror*)
133 return 0
134 ;;
135 esac
9c83ffd8
PM
136 echo $compiler -Werror "$@" >> config.log
137 $compiler -Werror "$@" >> config.log 2>&1 && return $?
76ad07a4
PM
138 error_exit "configure test passed without -Werror but failed with -Werror." \
139 "This is probably a bug in the configure script. The failing command" \
140 "will be at the bottom of config.log." \
141 "You can run configure with --disable-werror to bypass this check."
8dc38a78
PM
142}
143
9c83ffd8 144do_cc() {
4dba2789 145 do_compiler "$cc" $CPU_CFLAGS "$@"
9c83ffd8
PM
146}
147
148do_cxx() {
4dba2789 149 do_compiler "$cxx" $CPU_CFLAGS "$@"
9c83ffd8
PM
150}
151
00849b92
RH
152# Append $2 to the variable named $1, with space separation
153add_to() {
154 eval $1=\${$1:+\"\$$1 \"}\$2
155}
156
9c83ffd8
PM
157update_cxxflags() {
158 # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
159 # options which some versions of GCC's C++ compiler complain about
160 # because they only make sense for C programs.
53422040 161 QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
8a9d3d56 162 CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
9c83ffd8
PM
163 for arg in $QEMU_CFLAGS; do
164 case $arg in
165 -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
166 -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
167 ;;
168 *)
169 QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
170 ;;
171 esac
172 done
173}
174
52166aa0 175compile_object() {
fd0e6053 176 local_cflags="$1"
5770e8af 177 do_cc $CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
52166aa0
JQ
178}
179
180compile_prog() {
181 local_cflags="$1"
182 local_ldflags="$2"
5770e8af
PB
183 do_cc $CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
184 $LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
52166aa0
JQ
185}
186
11568d6d
PB
187# symbolically link $1 to $2. Portable version of "ln -sf".
188symlink() {
72b8b5a1 189 rm -rf "$2"
ec5b06d7 190 mkdir -p "$(dirname "$2")"
72b8b5a1 191 ln -s "$1" "$2"
11568d6d
PB
192}
193
0dba6195
LM
194# check whether a command is available to this shell (may be either an
195# executable or a builtin)
196has() {
197 type "$1" >/dev/null 2>&1
198}
199
0a01d76f 200version_ge () {
2df52b9b
AB
201 local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
202 local_ver2=$(echo "$2" | tr . ' ')
0a01d76f
MAL
203 while true; do
204 set x $local_ver1
205 local_first=${2-0}
c44a33e2
SG
206 # 'shift 2' if $2 is set, or 'shift' if $2 is not set
207 shift ${2:+2}
0a01d76f
MAL
208 local_ver1=$*
209 set x $local_ver2
210 # the second argument finished, the first must be greater or equal
211 test $# = 1 && return 0
212 test $local_first -lt $2 && return 1
213 test $local_first -gt $2 && return 0
c44a33e2 214 shift ${2:+2}
0a01d76f
MAL
215 local_ver2=$*
216 done
217}
218
3b6b7550
PB
219glob() {
220 eval test -z '"${1#'"$2"'}"'
221}
222
e9a3591f
CB
223ld_has() {
224 $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
225}
226
4ace32e2
AO
227if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
228then
229 error_exit "main directory cannot contain spaces nor colons"
230fi
231
14211825 232# default parameters
2ff6b91e 233cpu=""
a31a8642 234iasl="iasl"
1e43adfc 235interp_prefix="/usr/gnemul/qemu-%M"
43ce4dfe 236static="no"
3812c0c4 237cross_compile="no"
7d13299d 238cross_prefix=""
87430d5b 239audio_drv_list="default"
b64ec4e4
FZ
240block_drv_rw_whitelist=""
241block_drv_ro_whitelist=""
e5f05f8c 242block_drv_whitelist_tools="no"
e49d021e 243host_cc="cc"
957f1f99 244libs_qga=""
5bc62e01 245debug_info="yes"
cdad781d 246lto="false"
63678e17 247stack_protector=""
1e4f6065 248safe_stack=""
afc3a8f9 249use_containers="yes"
f2385398 250gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
ac0df51d 251
92712822
DB
252if test -e "$source_path/.git"
253then
7d7dbf9d 254 git_submodules_action="update"
92712822 255else
7d7dbf9d 256 git_submodules_action="ignore"
92712822 257fi
2d652f24
PB
258
259git_submodules="ui/keycodemapdb"
cc84d63a 260git="git"
ac0df51d 261
afb63ebd
SW
262# Don't accept a target_list environment variable.
263unset target_list
447e133f 264unset target_list_exclude
377529c0
PB
265
266# Default value for a variable defining feature "foo".
267# * foo="no" feature will only be used if --enable-foo arg is given
268# * foo="" feature will be searched for, and if found, will be used
269# unless --disable-foo is given
270# * foo="yes" this value will only be set by --enable-foo flag.
271# feature will searched for,
272# if not found, configure exits with error
273#
274# Always add --enable-foo and --disable-foo command line args.
275# Distributions want to ensure that several features are compiled in, and it
276# is impossible without a --enable-foo that exits if a feature is not found.
277
c87ea116
AB
278default_feature=""
279# parse CC options second
280for opt do
281 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
282 case "$opt" in
283 --without-default-features)
284 default_feature="no"
285 ;;
286 esac
287done
288
c87ea116 289xen_ctrl_version="$default_feature"
c87ea116 290xfs="$default_feature"
c87ea116 291membarrier="$default_feature"
0848f8ac 292vhost_kernel="$default_feature"
c87ea116
AB
293vhost_net="$default_feature"
294vhost_crypto="$default_feature"
295vhost_scsi="$default_feature"
296vhost_vsock="$default_feature"
d88618f7 297vhost_user="no"
c87ea116 298vhost_user_fs="$default_feature"
0848f8ac 299vhost_vdpa="$default_feature"
c87ea116
AB
300rdma="$default_feature"
301pvrdma="$default_feature"
377529c0
PB
302gprof="no"
303debug_tcg="no"
377529c0 304debug="no"
247724cb 305sanitizers="no"
0aebab04 306tsan="no"
c87ea116 307fortify_source="$default_feature"
377529c0 308strip_opt="yes"
377529c0 309mingw32="no"
1d728c39 310gcov="no"
c7328271 311EXESUF=""
17969268 312modules="no"
bd83c861 313module_upgrades="no"
377529c0 314prefix="/usr/local"
10ff82d1 315qemu_suffix="qemu"
377529c0
PB
316bsd="no"
317linux="no"
318solaris="no"
319profiler="no"
377529c0
PB
320softmmu="yes"
321linux_user="no"
377529c0 322bsd_user="no"
377529c0 323pkgversion=""
40d6444e 324pie=""
3556c233 325qom_cast_debug="yes"
baf86d6b 326trace_backends="log"
377529c0 327trace_file="trace"
c87ea116 328opengl="$default_feature"
5dd89908 329cpuid_h="no"
c87ea116 330avx2_opt="$default_feature"
c87ea116 331guest_agent="$default_feature"
d9840e25 332guest_agent_with_vss="no"
50cbebb9 333guest_agent_ntddscsi="no"
c87ea116 334vss_win32_sdk="$default_feature"
d9840e25 335win_sdk="no"
c87ea116 336want_tools="$default_feature"
519175a2 337coroutine=""
c87ea116 338coroutine_pool="$default_feature"
7d992e4d 339debug_stack_usage="no"
f0d92b56 340crypto_afalg="no"
a1c5e949 341tls_priority="NORMAL"
c87ea116
AB
342tpm="$default_feature"
343libssh="$default_feature"
344live_block_migration=${default_feature:-yes}
345numa="$default_feature"
c87ea116
AB
346replication=${default_feature:-yes}
347bochs=${default_feature:-yes}
348cloop=${default_feature:-yes}
349dmg=${default_feature:-yes}
350qcow1=${default_feature:-yes}
351vdi=${default_feature:-yes}
352vvfat=${default_feature:-yes}
353qed=${default_feature:-yes}
354parallels=${default_feature:-yes}
ba59fb77 355debug_mutex="no"
ba4dd2aa 356plugins="$default_feature"
b767d257 357rng_none="no"
c87ea116 358secret_keyring="$default_feature"
a5665051 359meson=""
3b4da132 360meson_args=""
48328880 361ninja=""
3b4da132 362gio="$default_feature"
a5665051 363skip_meson=no
b8e0c493 364slirp_smbd="$default_feature"
377529c0 365
3b4da132
PB
366# The following Meson options are handled manually (still they
367# are included in the automatically generated help message)
368
369# 1. Track which submodules are needed
370capstone="auto"
371fdt="auto"
372slirp="auto"
373
374# 2. Support --with/--without option
375default_devices="true"
376
377# 3. Automatically enable/disable other options
378tcg="enabled"
379cfi="false"
380
381# 4. Detection partly done in configure
382xen=${default_feature:+disabled}
898be3e0 383
c87ea116 384# parse CC options second
ac0df51d 385for opt do
89138857 386 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
ac0df51d
AL
387 case "$opt" in
388 --cross-prefix=*) cross_prefix="$optarg"
3812c0c4 389 cross_compile="yes"
ac0df51d 390 ;;
3d8df640 391 --cc=*) CC="$optarg"
ac0df51d 392 ;;
83f73fce
TS
393 --cxx=*) CXX="$optarg"
394 ;;
2ff6b91e
JQ
395 --cpu=*) cpu="$optarg"
396 ;;
de385287 397 --extra-cflags=*) QEMU_CFLAGS="$QEMU_CFLAGS $optarg"
db5adeaa 398 QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
e2a2ed06 399 ;;
11cde1c8 400 --extra-cxxflags=*) QEMU_CXXFLAGS="$QEMU_CXXFLAGS $optarg"
11cde1c8 401 ;;
db5adeaa 402 --extra-ldflags=*) QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
f9943cd5 403 EXTRA_LDFLAGS="$optarg"
e2a2ed06 404 ;;
5bc62e01
GH
405 --enable-debug-info) debug_info="yes"
406 ;;
407 --disable-debug-info) debug_info="no"
408 ;;
d75402b5
AB
409 --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
410 ;;
d422b2bc
AB
411 --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-flags-}; cc_arch=${cc_arch%%=*}
412 eval "cross_cc_cflags_${cc_arch}=\$optarg"
2038f8c8 413 cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
d422b2bc 414 ;;
d75402b5 415 --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
2038f8c8 416 cc_archs="$cc_archs $cc_arch"
d75402b5 417 eval "cross_cc_${cc_arch}=\$optarg"
2038f8c8 418 cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
d75402b5 419 ;;
ac0df51d
AL
420 esac
421done
ac0df51d
AL
422# OS specific
423# Using uname is really, really broken. Once we have the right set of checks
93148aa5 424# we can eliminate its usage altogether.
ac0df51d 425
e49d021e
PM
426# Preferred compiler:
427# ${CC} (if set)
428# ${cross_prefix}gcc (if cross-prefix specified)
429# system compiler
430if test -z "${CC}${cross_prefix}"; then
431 cc="$host_cc"
432else
433 cc="${CC-${cross_prefix}gcc}"
434fi
435
83f73fce
TS
436if test -z "${CXX}${cross_prefix}"; then
437 cxx="c++"
438else
439 cxx="${CXX-${cross_prefix}g++}"
440fi
441
b3198cc2 442ar="${AR-${cross_prefix}ar}"
cdbd727c 443as="${AS-${cross_prefix}as}"
5f6f0e27 444ccas="${CCAS-$cc}"
3dd46c78 445cpp="${CPP-$cc -E}"
b3198cc2
SY
446objcopy="${OBJCOPY-${cross_prefix}objcopy}"
447ld="${LD-${cross_prefix}ld}"
9f81aeb5 448ranlib="${RANLIB-${cross_prefix}ranlib}"
4852ee95 449nm="${NM-${cross_prefix}nm}"
b3198cc2
SY
450strip="${STRIP-${cross_prefix}strip}"
451windres="${WINDRES-${cross_prefix}windres}"
17884d7b
ST
452pkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
453query_pkg_config() {
454 "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
455}
456pkg_config=query_pkg_config
47c03744 457sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
ac0df51d 458
be17dc90 459# default flags for all hosts
2d31515b
PM
460# We use -fwrapv to tell the compiler that we require a C dialect where
461# left shift of signed integers is well defined and has the expected
462# 2s-complement style results. (Both clang and gcc agree that it
463# provides these semantics.)
086d5f75
PB
464QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv $QEMU_CFLAGS"
465QEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
c95e3080 466QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
be17dc90 467QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
5770e8af
PB
468
469# Flags that are needed during configure but later taken care of by Meson
8a9d3d56 470CONFIGURE_CFLAGS="-std=gnu11 -Wall"
5770e8af 471CONFIGURE_LDFLAGS=
086d5f75 472
be17dc90 473
ac0df51d
AL
474check_define() {
475cat > $TMPC <<EOF
476#if !defined($1)
fd786e1a 477#error $1 not defined
ac0df51d
AL
478#endif
479int main(void) { return 0; }
480EOF
52166aa0 481 compile_object
ac0df51d
AL
482}
483
307119e7
GH
484check_include() {
485cat > $TMPC <<EOF
486#include <$1>
487int main(void) { return 0; }
488EOF
489 compile_object
490}
491
93b25869
JS
492write_c_skeleton() {
493 cat > $TMPC <<EOF
494int main(void) { return 0; }
495EOF
496}
497
bbea4050
PM
498if check_define __linux__ ; then
499 targetos="Linux"
500elif check_define _WIN32 ; then
501 targetos='MINGW32'
502elif check_define __OpenBSD__ ; then
503 targetos='OpenBSD'
504elif check_define __sun__ ; then
505 targetos='SunOS'
506elif check_define __HAIKU__ ; then
507 targetos='Haiku'
951fedfc
PM
508elif check_define __FreeBSD__ ; then
509 targetos='FreeBSD'
510elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
511 targetos='GNU/kFreeBSD'
512elif check_define __DragonFly__ ; then
513 targetos='DragonFly'
514elif check_define __NetBSD__; then
515 targetos='NetBSD'
516elif check_define __APPLE__; then
517 targetos='Darwin'
bbea4050 518else
951fedfc
PM
519 # This is a fatal error, but don't report it yet, because we
520 # might be going to just print the --help text, or it might
521 # be the result of a missing compiler.
522 targetos='bogus'
bbea4050
PM
523fi
524
525# Some host OSes need non-standard checks for which CPU to use.
526# Note that these checks are broken for cross-compilation: if you're
527# cross-compiling to one of these OSes then you'll need to specify
528# the correct CPU with the --cpu option.
529case $targetos in
bbea4050 530SunOS)
89138857 531 # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
bbea4050
PM
532 if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
533 cpu="x86_64"
534 fi
535esac
536
2ff6b91e
JQ
537if test ! -z "$cpu" ; then
538 # command line argument
539 :
540elif check_define __i386__ ; then
ac0df51d
AL
541 cpu="i386"
542elif check_define __x86_64__ ; then
c72b26ec
RH
543 if check_define __ILP32__ ; then
544 cpu="x32"
545 else
546 cpu="x86_64"
547 fi
3aa9bd6c 548elif check_define __sparc__ ; then
3aa9bd6c
BS
549 if check_define __arch64__ ; then
550 cpu="sparc64"
551 else
552 cpu="sparc"
553 fi
fdf7ed96 554elif check_define _ARCH_PPC ; then
555 if check_define _ARCH_PPC64 ; then
f8378acc
RH
556 if check_define _LITTLE_ENDIAN ; then
557 cpu="ppc64le"
558 else
559 cpu="ppc64"
560 fi
fdf7ed96 561 else
562 cpu="ppc"
563 fi
afa05235
AJ
564elif check_define __mips__ ; then
565 cpu="mips"
d66ed0ea
AJ
566elif check_define __s390__ ; then
567 if check_define __s390x__ ; then
568 cpu="s390x"
569 else
570 cpu="s390"
571 fi
c4f80543
AF
572elif check_define __riscv ; then
573 if check_define _LP64 ; then
574 cpu="riscv64"
575 else
576 cpu="riscv32"
577 fi
21d89f84
PM
578elif check_define __arm__ ; then
579 cpu="arm"
1f080313
CF
580elif check_define __aarch64__ ; then
581 cpu="aarch64"
ac0df51d 582else
89138857 583 cpu=$(uname -m)
ac0df51d
AL
584fi
585
359bc95d
PM
586ARCH=
587# Normalise host CPU name and set ARCH.
588# Note that this case should only have supported host CPUs, not guests.
7d13299d 589case "$cpu" in
ee35e968 590 ppc|ppc64|s390x|sparc64|x32|riscv32|riscv64)
898be3e0 591 ;;
f8378acc
RH
592 ppc64le)
593 ARCH="ppc64"
f8378acc 594 ;;
7d13299d 595 i386|i486|i586|i686|i86pc|BePC)
97a847bc 596 cpu="i386"
7d13299d 597 ;;
aaa5fa14
AJ
598 x86_64|amd64)
599 cpu="x86_64"
600 ;;
21d89f84
PM
601 armv*b|armv*l|arm)
602 cpu="arm"
7d13299d 603 ;;
1f080313
CF
604 aarch64)
605 cpu="aarch64"
606 ;;
afa05235
AJ
607 mips*)
608 cpu="mips"
609 ;;
3142255c 610 sparc|sun4[cdmuv])
ae228531
FB
611 cpu="sparc"
612 ;;
7d13299d 613 *)
359bc95d
PM
614 # This will result in either an error or falling back to TCI later
615 ARCH=unknown
7d13299d
FB
616 ;;
617esac
359bc95d
PM
618if test -z "$ARCH"; then
619 ARCH="$cpu"
620fi
e2d52ad3 621
7d13299d 622# OS specific
0dbfc675 623
7d13299d 624case $targetos in
67b915a5 625MINGW32*)
0dbfc675 626 mingw32="yes"
898be3e0 627 supported_os="yes"
9b8e4298 628 plugins="no"
fb648e9c 629 pie="no"
67b915a5 630;;
5c40d2bd 631GNU/kFreeBSD)
a167ba50 632 bsd="yes"
5c40d2bd 633;;
7d3505c5 634FreeBSD)
0dbfc675 635 bsd="yes"
e2a74729 636 bsd_user="yes"
0db4a067 637 make="${MAKE-gmake}"
f01576f1 638 # needed for kinfo_getvmmap(3) in libutil.h
7d3505c5 639;;
c5e97233 640DragonFly)
0dbfc675 641 bsd="yes"
0db4a067 642 make="${MAKE-gmake}"
c5e97233 643;;
7d3505c5 644NetBSD)
0dbfc675 645 bsd="yes"
0db4a067 646 make="${MAKE-gmake}"
7d3505c5
FB
647;;
648OpenBSD)
0dbfc675 649 bsd="yes"
0db4a067 650 make="${MAKE-gmake}"
7d3505c5 651;;
83fb7adf 652Darwin)
0dbfc675
JQ
653 bsd="yes"
654 darwin="yes"
a0b7cf6b
PM
655 # Disable attempts to use ObjectiveC features in os/object.h since they
656 # won't work when we're compiling with gcc as a C compiler.
657 QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
83fb7adf 658;;
ec530c81 659SunOS)
0dbfc675 660 solaris="yes"
0db4a067 661 make="${MAKE-gmake}"
e2d8830e 662 smbd="${SMBD-/usr/sfw/sbin/smbd}"
d741429a
BS
663# needed for CMSG_ macros in sys/socket.h
664 QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
665# needed for TIOCWIN* defines in termios.h
666 QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
86b2bd93 667;;
179cf400
AF
668Haiku)
669 haiku="yes"
b8ee198d
RZ
670 pie="no"
671 QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
179cf400 672;;
898be3e0 673Linux)
0dbfc675
JQ
674 linux="yes"
675 linux_user="yes"
c87ea116 676 vhost_user=${default_feature:-yes}
898be3e0 677;;
7d13299d
FB
678esac
679
0db4a067 680: ${make=${MAKE-make}}
b6daf4d3 681
faf44142
DB
682# We prefer python 3.x. A bare 'python' is traditionally
683# python 2.x, but some distros have it as python 3.x, so
ddf90699 684# we check that too
faf44142 685python=
0a01d76f 686explicit_python=no
ddf90699 687for binary in "${PYTHON-python3}" python
faf44142
DB
688do
689 if has "$binary"
690 then
95c5f2de 691 python=$(command -v "$binary")
faf44142
DB
692 break
693 fi
694done
903458c8 695
903458c8 696
39d87c8c
AB
697# Check for ancillary tools used in testing
698genisoimage=
3df437c7 699for binary in genisoimage mkisofs
39d87c8c
AB
700do
701 if has $binary
702 then
703 genisoimage=$(command -v "$binary")
704 break
705 fi
706done
707
3c4a4d0d
PM
708# Default objcc to clang if available, otherwise use CC
709if has clang; then
710 objcc=clang
711else
712 objcc="$cc"
713fi
714
3457a3f8 715if test "$mingw32" = "yes" ; then
3457a3f8 716 EXESUF=".exe"
78e9d4ad 717 # MinGW needs -mthreads for TLS and macro _MT.
5770e8af 718 CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
93b25869 719 write_c_skeleton;
d17f305a 720 prefix="/qemu"
77433a5f 721 qemu_suffix=""
105fad6b 722 libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi -lnetapi32 $libs_qga"
3457a3f8
JQ
723fi
724
487fefdb 725werror=""
85aa5189 726
61d63097
PB
727. $source_path/scripts/meson-buildoptions.sh
728
729meson_options=
730meson_option_parse() {
731 meson_options="$meson_options $(_meson_option_parse "$@")"
732 if test $? -eq 1; then
733 echo "ERROR: unknown option $1"
734 echo "Try '$0 --help' for more information"
735 exit 1
736 fi
737}
738
7d13299d 739for opt do
89138857 740 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
7d13299d 741 case "$opt" in
2efc3265
FB
742 --help|-h) show_help=yes
743 ;;
99123e13
MF
744 --version|-V) exec cat $source_path/VERSION
745 ;;
b1a550a0 746 --prefix=*) prefix="$optarg"
7d13299d 747 ;;
b1a550a0 748 --interp-prefix=*) interp_prefix="$optarg"
32ce6337 749 ;;
ac0df51d 750 --cross-prefix=*)
7d13299d 751 ;;
ac0df51d 752 --cc=*)
7d13299d 753 ;;
b1a550a0 754 --host-cc=*) host_cc="$optarg"
83469015 755 ;;
83f73fce
TS
756 --cxx=*)
757 ;;
e007dbec
MT
758 --iasl=*) iasl="$optarg"
759 ;;
3c4a4d0d
PM
760 --objcc=*) objcc="$optarg"
761 ;;
b1a550a0 762 --make=*) make="$optarg"
7d13299d 763 ;;
b6daf4d3 764 --install=*)
6a882643 765 ;;
0a01d76f 766 --python=*) python="$optarg" ; explicit_python=yes
c886edfb 767 ;;
2eb054c2
PM
768 --sphinx-build=*) sphinx_build="$optarg"
769 ;;
a5665051
PB
770 --skip-meson) skip_meson=yes
771 ;;
772 --meson=*) meson="$optarg"
773 ;;
48328880
PB
774 --ninja=*) ninja="$optarg"
775 ;;
e2d8830e
BS
776 --smbd=*) smbd="$optarg"
777 ;;
e2a2ed06 778 --extra-cflags=*)
7d13299d 779 ;;
11cde1c8
BD
780 --extra-cxxflags=*)
781 ;;
e2a2ed06 782 --extra-ldflags=*)
7d13299d 783 ;;
5bc62e01
GH
784 --enable-debug-info)
785 ;;
786 --disable-debug-info)
787 ;;
d75402b5
AB
788 --cross-cc-*)
789 ;;
17969268
FZ
790 --enable-modules)
791 modules="yes"
3aa88b31
SH
792 ;;
793 --disable-modules)
794 modules="no"
17969268 795 ;;
bd83c861
CE
796 --disable-module-upgrades) module_upgrades="no"
797 ;;
798 --enable-module-upgrades) module_upgrades="yes"
799 ;;
2ff6b91e 800 --cpu=*)
7d13299d 801 ;;
b1a550a0 802 --target-list=*) target_list="$optarg"
447e133f
AB
803 if test "$target_list_exclude"; then
804 error_exit "Can't mix --target-list with --target-list-exclude"
805 fi
806 ;;
807 --target-list-exclude=*) target_list_exclude="$optarg"
808 if test "$target_list"; then
809 error_exit "Can't mix --target-list-exclude with --target-list"
810 fi
de83cd02 811 ;;
74242e0f 812 --with-trace-file=*) trace_file="$optarg"
9410b56c 813 ;;
7bc3ca7f 814 --with-default-devices) default_devices="true"
f3494749 815 ;;
7bc3ca7f 816 --without-default-devices) default_devices="false"
f3494749 817 ;;
d1d5e9ee
AB
818 --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
819 ;;
820 --with-devices-*) device_arch=${opt#--with-devices-};
821 device_arch=${device_arch%%=*}
822 cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
823 if test -f "$cf"; then
824 device_archs="$device_archs $device_arch"
825 eval "devices_${device_arch}=\$optarg"
826 else
827 error_exit "File $cf does not exist"
828 fi
829 ;;
c87ea116
AB
830 --without-default-features) # processed above
831 ;;
7d13299d
FB
832 --enable-gprof) gprof="yes"
833 ;;
1d728c39
BS
834 --enable-gcov) gcov="yes"
835 ;;
79427693
LM
836 --static)
837 static="yes"
17884d7b 838 QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
43ce4dfe 839 ;;
0b24e75f
PB
840 --mandir=*) mandir="$optarg"
841 ;;
842 --bindir=*) bindir="$optarg"
843 ;;
3aa5d2be
AL
844 --libdir=*) libdir="$optarg"
845 ;;
8bf188aa
MT
846 --libexecdir=*) libexecdir="$optarg"
847 ;;
0f94d6da
AL
848 --includedir=*) includedir="$optarg"
849 ;;
528ae5b8 850 --datadir=*) datadir="$optarg"
0b24e75f 851 ;;
77433a5f 852 --with-suffix=*) qemu_suffix="$optarg"
023d3d67 853 ;;
c6502638 854 --docdir=*) docdir="$optarg"
0b24e75f 855 ;;
fe0038be
PB
856 --localedir=*) localedir="$optarg"
857 ;;
ca2fb938 858 --sysconfdir=*) sysconfdir="$optarg"
07381cc1 859 ;;
785c23ae
LC
860 --localstatedir=*) local_statedir="$optarg"
861 ;;
3d5eecab
GH
862 --firmwarepath=*) firmwarepath="$optarg"
863 ;;
181ce1d0
OH
864 --host=*|--build=*|\
865 --disable-dependency-tracking|\
785c23ae 866 --sbindir=*|--sharedstatedir=*|\
fe0038be 867 --oldincludedir=*|--datarootdir=*|--infodir=*|\
023ddd74
MF
868 --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
869 # These switches are silently ignored, for compatibility with
870 # autoconf-generated configure scripts. This allows QEMU's
871 # configure to be used by RPM and similar macros that set
872 # lots of directory switches by default.
873 ;;
3556c233
PB
874 --disable-qom-cast-debug) qom_cast_debug="no"
875 ;;
876 --enable-qom-cast-debug) qom_cast_debug="yes"
877 ;;
0c58ac1c 878 --audio-drv-list=*) audio_drv_list="$optarg"
102a52e4 879 ;;
89138857 880 --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
b64ec4e4 881 ;;
89138857 882 --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
eb852011 883 ;;
e5f05f8c
KW
884 --enable-block-drv-whitelist-in-tools) block_drv_whitelist_tools="yes"
885 ;;
886 --disable-block-drv-whitelist-in-tools) block_drv_whitelist_tools="no"
887 ;;
f8393946
AJ
888 --enable-debug-tcg) debug_tcg="yes"
889 ;;
890 --disable-debug-tcg) debug_tcg="no"
891 ;;
f3d08ee6
PB
892 --enable-debug)
893 # Enable debugging options that aren't excessively noisy
894 debug_tcg="yes"
1fcc6d42 895 debug_mutex="yes"
f3d08ee6
PB
896 debug="yes"
897 strip_opt="no"
b553a042 898 fortify_source="no"
f3d08ee6 899 ;;
247724cb
MAL
900 --enable-sanitizers) sanitizers="yes"
901 ;;
902 --disable-sanitizers) sanitizers="no"
903 ;;
0aebab04
LY
904 --enable-tsan) tsan="yes"
905 ;;
906 --disable-tsan) tsan="no"
907 ;;
1625af87
AL
908 --disable-strip) strip_opt="no"
909 ;;
4d34a86b 910 --disable-slirp) slirp="disabled"
1d14ffa9 911 ;;
fd6fc214
PB
912 --enable-slirp) slirp="enabled"
913 ;;
4d34a86b 914 --enable-slirp=git) slirp="internal"
7c57bdd8 915 ;;
03a3c0b3 916 --enable-slirp=*) slirp="$optarg"
675b9b53 917 ;;
1badb709 918 --disable-xen) xen="disabled"
e37630ca 919 ;;
1badb709 920 --enable-xen) xen="enabled"
fc321b4b 921 ;;
1badb709 922 --disable-tcg) tcg="disabled"
d1a14257 923 plugins="no"
b3f6ea7e 924 ;;
1badb709 925 --enable-tcg) tcg="enabled"
b3f6ea7e 926 ;;
05c2a3e7
FB
927 --enable-profiler) profiler="yes"
928 ;;
cad25d69 929 --disable-system) softmmu="no"
0a8e90f4 930 ;;
cad25d69 931 --enable-system) softmmu="yes"
0a8e90f4 932 ;;
0953a80f
ZA
933 --disable-user)
934 linux_user="no" ;
935 bsd_user="no" ;
0953a80f
ZA
936 ;;
937 --enable-user) ;;
831b7825 938 --disable-linux-user) linux_user="no"
0a8e90f4 939 ;;
831b7825
TS
940 --enable-linux-user) linux_user="yes"
941 ;;
84778508
BS
942 --disable-bsd-user) bsd_user="no"
943 ;;
944 --enable-bsd-user) bsd_user="yes"
945 ;;
40d6444e 946 --enable-pie) pie="yes"
34005a00 947 ;;
40d6444e 948 --disable-pie) pie="no"
34005a00 949 ;;
85aa5189
FB
950 --enable-werror) werror="yes"
951 ;;
952 --disable-werror) werror="no"
953 ;;
cdad781d
DB
954 --enable-lto) lto="true"
955 ;;
956 --disable-lto) lto="false"
957 ;;
63678e17
SN
958 --enable-stack-protector) stack_protector="yes"
959 ;;
960 --disable-stack-protector) stack_protector="no"
961 ;;
1e4f6065
DB
962 --enable-safe-stack) safe_stack="yes"
963 ;;
964 --disable-safe-stack) safe_stack="no"
965 ;;
9e62ba48
DB
966 --enable-cfi)
967 cfi="true";
968 lto="true";
969 ;;
970 --disable-cfi) cfi="false"
971 ;;
fbb4121d 972 --disable-fdt) fdt="disabled"
2df87df7 973 ;;
fbb4121d
PB
974 --enable-fdt) fdt="enabled"
975 ;;
976 --enable-fdt=git) fdt="internal"
977 ;;
03a3c0b3 978 --enable-fdt=*) fdt="$optarg"
2df87df7 979 ;;
a40161cb
PB
980 --disable-membarrier) membarrier="no"
981 ;;
982 --enable-membarrier) membarrier="yes"
983 ;;
7e563bfb 984 --with-pkgversion=*) pkgversion="$optarg"
4a19f1ec 985 ;;
519175a2
AB
986 --with-coroutine=*) coroutine="$optarg"
987 ;;
70c60c08
SH
988 --disable-coroutine-pool) coroutine_pool="no"
989 ;;
990 --enable-coroutine-pool) coroutine_pool="yes"
991 ;;
7d992e4d
PL
992 --enable-debug-stack-usage) debug_stack_usage="yes"
993 ;;
f0d92b56
LM
994 --enable-crypto-afalg) crypto_afalg="yes"
995 ;;
996 --disable-crypto-afalg) crypto_afalg="no"
997 ;;
d5970055
MT
998 --disable-vhost-net) vhost_net="no"
999 ;;
1000 --enable-vhost-net) vhost_net="yes"
1001 ;;
042cea27
GA
1002 --disable-vhost-crypto) vhost_crypto="no"
1003 ;;
299e6f19 1004 --enable-vhost-crypto) vhost_crypto="yes"
042cea27 1005 ;;
5e9be92d
NB
1006 --disable-vhost-scsi) vhost_scsi="no"
1007 ;;
1008 --enable-vhost-scsi) vhost_scsi="yes"
1009 ;;
fc0b9b0e
SH
1010 --disable-vhost-vsock) vhost_vsock="no"
1011 ;;
1012 --enable-vhost-vsock) vhost_vsock="yes"
1013 ;;
98fc1ada
DDAG
1014 --disable-vhost-user-fs) vhost_user_fs="no"
1015 ;;
1016 --enable-vhost-user-fs) vhost_user_fs="yes"
1017 ;;
da076ffe 1018 --disable-opengl) opengl="no"
20ff075b 1019 ;;
da076ffe 1020 --enable-opengl) opengl="yes"
20ff075b 1021 ;;
8c84cf11
ST
1022 --disable-xfsctl) xfs="no"
1023 ;;
1024 --enable-xfsctl) xfs="yes"
1025 ;;
1ffb3bbb 1026 --disable-zlib-test)
1ece9905 1027 ;;
d138cee9
MR
1028 --enable-guest-agent) guest_agent="yes"
1029 ;;
1030 --disable-guest-agent) guest_agent="no"
1031 ;;
d9840e25
TS
1032 --with-vss-sdk) vss_win32_sdk=""
1033 ;;
1034 --with-vss-sdk=*) vss_win32_sdk="$optarg"
1035 ;;
1036 --without-vss-sdk) vss_win32_sdk="no"
1037 ;;
1038 --with-win-sdk) win_sdk=""
1039 ;;
1040 --with-win-sdk=*) win_sdk="$optarg"
1041 ;;
1042 --without-win-sdk) win_sdk="no"
1043 ;;
4b1c11fd
DB
1044 --enable-tools) want_tools="yes"
1045 ;;
1046 --disable-tools) want_tools="no"
1047 ;;
86583a07
LM
1048 --disable-avx2) avx2_opt="no"
1049 ;;
1050 --enable-avx2) avx2_opt="yes"
1051 ;;
6b8cd447
RH
1052 --disable-avx512f) avx512f_opt="no"
1053 ;;
1054 --enable-avx512f) avx512f_opt="yes"
1055 ;;
52b53c04
FZ
1056 --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
1057 echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
583f6e7b 1058 ;;
cb6414df
FZ
1059 --enable-vhdx|--disable-vhdx)
1060 echo "$0: $opt is obsolete, VHDX driver is always built" >&2
1061 ;;
315d3184
FZ
1062 --enable-uuid|--disable-uuid)
1063 echo "$0: $opt is obsolete, UUID support is always built" >&2
1064 ;;
a1c5e949
DB
1065 --tls-priority=*) tls_priority="$optarg"
1066 ;;
2da776db
MH
1067 --enable-rdma) rdma="yes"
1068 ;;
1069 --disable-rdma) rdma="no"
1070 ;;
21ab34c9
MA
1071 --enable-pvrdma) pvrdma="yes"
1072 ;;
1073 --disable-pvrdma) pvrdma="no"
1074 ;;
e91c793c
CR
1075 --disable-tpm) tpm="no"
1076 ;;
ab214c29
SB
1077 --enable-tpm) tpm="yes"
1078 ;;
b10d49d7 1079 --disable-libssh) libssh="no"
0a12ec87 1080 ;;
b10d49d7 1081 --enable-libssh) libssh="yes"
0a12ec87 1082 ;;
ed1701c6
DDAG
1083 --disable-live-block-migration) live_block_migration="no"
1084 ;;
1085 --enable-live-block-migration) live_block_migration="yes"
1086 ;;
a99d57bb
WG
1087 --disable-numa) numa="no"
1088 ;;
1089 --enable-numa) numa="yes"
1090 ;;
a6b1d4c0
CX
1091 --disable-replication) replication="no"
1092 ;;
1093 --enable-replication) replication="yes"
1094 ;;
2f740136
JC
1095 --disable-bochs) bochs="no"
1096 ;;
1097 --enable-bochs) bochs="yes"
1098 ;;
1099 --disable-cloop) cloop="no"
1100 ;;
1101 --enable-cloop) cloop="yes"
1102 ;;
1103 --disable-dmg) dmg="no"
1104 ;;
1105 --enable-dmg) dmg="yes"
1106 ;;
1107 --disable-qcow1) qcow1="no"
1108 ;;
1109 --enable-qcow1) qcow1="yes"
1110 ;;
1111 --disable-vdi) vdi="no"
1112 ;;
1113 --enable-vdi) vdi="yes"
1114 ;;
1115 --disable-vvfat) vvfat="no"
1116 ;;
1117 --enable-vvfat) vvfat="yes"
1118 ;;
1119 --disable-qed) qed="no"
1120 ;;
1121 --enable-qed) qed="yes"
1122 ;;
1123 --disable-parallels) parallels="no"
1124 ;;
1125 --enable-parallels) parallels="yes"
1126 ;;
e6a74868
MAL
1127 --disable-vhost-user) vhost_user="no"
1128 ;;
299e6f19
PB
1129 --enable-vhost-user) vhost_user="yes"
1130 ;;
108a6481
CL
1131 --disable-vhost-vdpa) vhost_vdpa="no"
1132 ;;
1133 --enable-vhost-vdpa) vhost_vdpa="yes"
1134 ;;
299e6f19
PB
1135 --disable-vhost-kernel) vhost_kernel="no"
1136 ;;
1137 --enable-vhost-kernel) vhost_kernel="yes"
e6a74868 1138 ;;
8b18cdbf 1139 --disable-capstone) capstone="disabled"
8ca80760 1140 ;;
8b18cdbf 1141 --enable-capstone) capstone="enabled"
8ca80760 1142 ;;
8b18cdbf 1143 --enable-capstone=git) capstone="internal"
e219c499 1144 ;;
03a3c0b3 1145 --enable-capstone=*) capstone="$optarg"
e219c499 1146 ;;
cc84d63a
DB
1147 --with-git=*) git="$optarg"
1148 ;;
7d7dbf9d
DS
1149 --with-git-submodules=*)
1150 git_submodules_action="$optarg"
f62bbee5 1151 ;;
ba59fb77
PB
1152 --enable-debug-mutex) debug_mutex=yes
1153 ;;
1154 --disable-debug-mutex) debug_mutex=no
1155 ;;
9b8e4298
AB
1156 --enable-plugins) if test "$mingw32" = "yes"; then
1157 error_exit "TCG plugins not currently supported on Windows platforms"
1158 else
1159 plugins="yes"
1160 fi
40e8c6f4
AB
1161 ;;
1162 --disable-plugins) plugins="no"
1163 ;;
afc3a8f9
AB
1164 --enable-containers) use_containers="yes"
1165 ;;
1166 --disable-containers) use_containers="no"
1167 ;;
f48e590a
AB
1168 --gdb=*) gdb_bin="$optarg"
1169 ;;
b767d257
MMG
1170 --enable-rng-none) rng_none=yes
1171 ;;
1172 --disable-rng-none) rng_none=no
1173 ;;
54e7aac0
AK
1174 --enable-keyring) secret_keyring="yes"
1175 ;;
1176 --disable-keyring) secret_keyring="no"
1177 ;;
20cf7b8e
DP
1178 --enable-gio) gio=yes
1179 ;;
1180 --disable-gio) gio=no
1181 ;;
b8e0c493
JD
1182 --enable-slirp-smbd) slirp_smbd=yes
1183 ;;
1184 --disable-slirp-smbd) slirp_smbd=no
1185 ;;
3b4da132
PB
1186 # backwards compatibility options
1187 --enable-trace-backend=*) meson_option_parse "--enable-trace-backends=$optarg" "$optarg"
1188 ;;
1189 --disable-blobs) meson_option_parse --disable-install-blobs ""
1190 ;;
1191 --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
1192 ;;
1193 --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
1194 ;;
1195 # everything else has the same name in configure and meson
61d63097
PB
1196 --enable-* | --disable-*) meson_option_parse "$opt" "$optarg"
1197 ;;
2d2ad6d0
FZ
1198 *)
1199 echo "ERROR: unknown option $opt"
1200 echo "Try '$0 --help' for more information"
1201 exit 1
7f1559c6 1202 ;;
7d13299d
FB
1203 esac
1204done
1205
d1a14257
AB
1206# test for any invalid configuration combinations
1207if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
1208 error_exit "Can't enable plugins on non-TCG builds"
1209fi
1210
7d7dbf9d
DS
1211case $git_submodules_action in
1212 update|validate)
1213 if test ! -e "$source_path/.git"; then
1214 echo "ERROR: cannot $git_submodules_action git submodules without .git"
1215 exit 1
1216 fi
1217 ;;
1218 ignore)
b80fd281
PB
1219 if ! test -f "$source_path/ui/keycodemapdb/README"
1220 then
1221 echo
1222 echo "ERROR: missing GIT submodules"
1223 echo
1224 if test -e "$source_path/.git"; then
1225 echo "--with-git-submodules=ignore specified but submodules were not"
1226 echo "checked out. Please initialize and update submodules."
1227 else
1228 echo "This is not a GIT checkout but module content appears to"
1229 echo "be missing. Do not use 'git archive' or GitHub download links"
1230 echo "to acquire QEMU source archives. Non-GIT builds are only"
1231 echo "supported with source archives linked from:"
1232 echo
1233 echo " https://www.qemu.org/download/#source"
1234 echo
1235 echo "Developers working with GIT can use scripts/archive-source.sh"
1236 echo "if they need to create valid source archives."
1237 fi
1238 echo
1239 exit 1
1240 fi
7d7dbf9d
DS
1241 ;;
1242 *)
1243 echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
1244 exit 1
1245 ;;
1246esac
1247
22a87800
MAL
1248libdir="${libdir:-$prefix/lib}"
1249libexecdir="${libexecdir:-$prefix/libexec}"
1250includedir="${includedir:-$prefix/include}"
1251
1252if test "$mingw32" = "yes" ; then
15588a62 1253 bindir="${bindir:-$prefix}"
22a87800 1254else
22a87800 1255 bindir="${bindir:-$prefix/bin}"
22a87800 1256fi
15588a62
JW
1257mandir="${mandir:-$prefix/share/man}"
1258datadir="${datadir:-$prefix/share}"
1259docdir="${docdir:-$prefix/share/doc}"
1260sysconfdir="${sysconfdir:-$prefix/etc}"
1261local_statedir="${local_statedir:-$prefix/var}"
16bf7a33
PB
1262firmwarepath="${firmwarepath:-$datadir/qemu-firmware}"
1263localedir="${localedir:-$datadir/locale}"
22a87800 1264
40293e58 1265case "$cpu" in
e3608d66
RH
1266 ppc)
1267 CPU_CFLAGS="-m32"
db5adeaa 1268 QEMU_LDFLAGS="-m32 $QEMU_LDFLAGS"
e3608d66
RH
1269 ;;
1270 ppc64)
1271 CPU_CFLAGS="-m64"
db5adeaa 1272 QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
e3608d66 1273 ;;
9b9c37c3 1274 sparc)
f1079bb8 1275 CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc"
db5adeaa 1276 QEMU_LDFLAGS="-m32 -mv8plus $QEMU_LDFLAGS"
3142255c 1277 ;;
ed968ff1 1278 sparc64)
79f3b12f 1279 CPU_CFLAGS="-m64 -mcpu=ultrasparc"
db5adeaa 1280 QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
3142255c 1281 ;;
76d83bde 1282 s390)
061cdd81 1283 CPU_CFLAGS="-m31"
db5adeaa 1284 QEMU_LDFLAGS="-m31 $QEMU_LDFLAGS"
28d7cc49
RH
1285 ;;
1286 s390x)
061cdd81 1287 CPU_CFLAGS="-m64"
db5adeaa 1288 QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
76d83bde 1289 ;;
40293e58 1290 i386)
79f3b12f 1291 CPU_CFLAGS="-m32"
db5adeaa 1292 QEMU_LDFLAGS="-m32 $QEMU_LDFLAGS"
40293e58
FB
1293 ;;
1294 x86_64)
7ebee43e
RH
1295 # ??? Only extremely old AMD cpus do not have cmpxchg16b.
1296 # If we truly care, we should simply detect this case at
1297 # runtime and generate the fallback to serial emulation.
1298 CPU_CFLAGS="-m64 -mcx16"
db5adeaa 1299 QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
d2fbca94 1300 ;;
c72b26ec
RH
1301 x32)
1302 CPU_CFLAGS="-mx32"
db5adeaa 1303 QEMU_LDFLAGS="-mx32 $QEMU_LDFLAGS"
c72b26ec 1304 ;;
30163d89 1305 # No special flags required for other host CPUs
3142255c
BS
1306esac
1307
9557af9c
AB
1308if eval test -z "\${cross_cc_$cpu}"; then
1309 eval "cross_cc_${cpu}=\$cc"
1310 cross_cc_vars="$cross_cc_vars cross_cc_${cpu}"
1311fi
79f3b12f 1312
affc88cc
PM
1313# For user-mode emulation the host arch has to be one we explicitly
1314# support, even if we're using TCI.
1315if [ "$ARCH" = "unknown" ]; then
1316 bsd_user="no"
1317 linux_user="no"
1318fi
1319
60e0df25 1320default_target_list=""
43692239 1321deprecated_targets_list=ppc64abi32-linux-user
fdb75aef 1322deprecated_features=""
6e92f823
PM
1323mak_wilds=""
1324
1325if [ "$softmmu" = "yes" ]; then
812b31d3 1326 mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
60e0df25 1327fi
6e92f823 1328if [ "$linux_user" = "yes" ]; then
812b31d3 1329 mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
60e0df25 1330fi
6e92f823 1331if [ "$bsd_user" = "yes" ]; then
812b31d3 1332 mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
60e0df25
PM
1333fi
1334
3a5ae4a9
AB
1335# If the user doesn't explicitly specify a deprecated target we will
1336# skip it.
1337if test -z "$target_list"; then
1338 if test -z "$target_list_exclude"; then
1339 target_list_exclude="$deprecated_targets_list"
1340 else
1341 target_list_exclude="$target_list_exclude,$deprecated_targets_list"
1342 fi
2d838d9b
AB
1343fi
1344
2d838d9b
AB
1345for config in $mak_wilds; do
1346 target="$(basename "$config" .mak)"
98db9a06 1347 if echo "$target_list_exclude" | grep -vq "$target"; then
2d838d9b
AB
1348 default_target_list="${default_target_list} $target"
1349 fi
1350done
6e92f823 1351
af5db58e
PB
1352if test x"$show_help" = x"yes" ; then
1353cat << EOF
1354
1355Usage: configure [options]
1356Options: [defaults in brackets after descriptions]
1357
08fb77ed
SW
1358Standard options:
1359 --help print this message
1360 --prefix=PREFIX install in PREFIX [$prefix]
1361 --interp-prefix=PREFIX where to find shared libraries, etc.
1362 use %M for cpu name [$interp_prefix]
2deca810 1363 --target-list=LIST set target list (default: build all non-deprecated)
08fb77ed
SW
1364$(echo Available targets: $default_target_list | \
1365 fold -s -w 53 | sed -e 's/^/ /')
2deca810
AB
1366$(echo Deprecated targets: $deprecated_targets_list | \
1367 fold -s -w 53 | sed -e 's/^/ /')
447e133f 1368 --target-list-exclude=LIST exclude a set of targets from the default target-list
08fb77ed
SW
1369
1370Advanced options (experts only):
3812c0c4 1371 --cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
08fb77ed
SW
1372 --cc=CC use C compiler CC [$cc]
1373 --iasl=IASL use ACPI compiler IASL [$iasl]
1374 --host-cc=CC use C compiler CC [$host_cc] for code run at
1375 build time
1376 --cxx=CXX use C++ compiler CXX [$cxx]
1377 --objcc=OBJCC use Objective-C compiler OBJCC [$objcc]
1378 --extra-cflags=CFLAGS append extra C compiler flags QEMU_CFLAGS
11cde1c8 1379 --extra-cxxflags=CXXFLAGS append extra C++ compiler flags QEMU_CXXFLAGS
08fb77ed 1380 --extra-ldflags=LDFLAGS append extra linker flags LDFLAGS
d75402b5 1381 --cross-cc-ARCH=CC use compiler when building ARCH guest test cases
d422b2bc 1382 --cross-cc-flags-ARCH= use compiler flags when building ARCH guest tests
08fb77ed 1383 --make=MAKE use specified make [$make]
08fb77ed 1384 --python=PYTHON use specified python [$python]
2eb054c2 1385 --sphinx-build=SPHINX use specified sphinx-build [$sphinx_build]
a5665051 1386 --meson=MESON use specified meson [$meson]
48328880 1387 --ninja=NINJA use specified ninja [$ninja]
08fb77ed 1388 --smbd=SMBD use specified smbd [$smbd]
db1b5f13 1389 --with-git=GIT use specified git [$git]
7d7dbf9d
DS
1390 --with-git-submodules=update update git submodules (default if .git dir exists)
1391 --with-git-submodules=validate fail if git submodules are not up to date
1392 --with-git-submodules=ignore do not update or check git submodules (default if no .git dir)
08fb77ed
SW
1393 --static enable static build [$static]
1394 --mandir=PATH install man pages in PATH
10ff82d1 1395 --datadir=PATH install firmware in PATH/$qemu_suffix
fe0038be 1396 --localedir=PATH install translation in PATH/$qemu_suffix
10ff82d1 1397 --docdir=PATH install documentation in PATH/$qemu_suffix
08fb77ed
SW
1398 --bindir=PATH install binaries in PATH
1399 --libdir=PATH install libraries in PATH
db1b5f13 1400 --libexecdir=PATH install helper binaries in PATH
10ff82d1 1401 --sysconfdir=PATH install config in PATH/$qemu_suffix
08fb77ed 1402 --localstatedir=PATH install local state in PATH (set at runtime on win32)
3d5eecab 1403 --firmwarepath=PATH search PATH for firmware files
13336606 1404 --efi-aarch64=PATH PATH of efi file to use for aarch64 VMs.
ca8c0909 1405 --with-suffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
db1b5f13 1406 --with-pkgversion=VERS use specified string as sub-version of the package
c035c8d6
PB
1407 --without-default-features default all --enable-* options to "disabled"
1408 --without-default-devices do not include any device that is not needed to
1409 start the emulator (only use if you are including
d1d5e9ee
AB
1410 desired devices in configs/devices/)
1411 --with-devices-ARCH=NAME override default configs/devices
08fb77ed 1412 --enable-debug enable common debug build options
247724cb 1413 --enable-sanitizers enable default sanitizers
0aebab04 1414 --enable-tsan enable thread sanitizer
08fb77ed
SW
1415 --disable-strip disable stripping binaries
1416 --disable-werror disable compilation abort on warning
63678e17 1417 --disable-stack-protector disable compiler-provided stack protection
87430d5b 1418 --audio-drv-list=LIST set audio drivers list
08fb77ed
SW
1419 --block-drv-whitelist=L Same as --block-drv-rw-whitelist=L
1420 --block-drv-rw-whitelist=L
1421 set block driver read-write whitelist
e5f05f8c 1422 (by default affects only QEMU, not tools like qemu-img)
08fb77ed
SW
1423 --block-drv-ro-whitelist=L
1424 set block driver read-only whitelist
e5f05f8c
KW
1425 (by default affects only QEMU, not tools like qemu-img)
1426 --enable-block-drv-whitelist-in-tools
1427 use block whitelist also in tools instead of only QEMU
08fb77ed
SW
1428 --with-trace-file=NAME Full PATH,NAME of file to store traces
1429 Default:trace-<pid>
c23f23b9 1430 --cpu=CPU Build for host CPU [$cpu]
08fb77ed 1431 --with-coroutine=BACKEND coroutine backend. Supported options:
33c53c54 1432 ucontext, sigaltstack, windows
08fb77ed 1433 --enable-gcov enable test coverage analysis with gcov
c23f23b9
MT
1434 --with-vss-sdk=SDK-path enable Windows VSS support in QEMU Guest Agent
1435 --with-win-sdk=SDK-path path to Windows Platform SDK (to build VSS .tlb)
a1c5e949 1436 --tls-priority default TLS protocol/cipher priority string
c12d66aa
LM
1437 --enable-gprof QEMU profiling with gprof
1438 --enable-profiler profiler support
c12d66aa
LM
1439 --enable-debug-stack-usage
1440 track the maximum stack usage of stacks created by qemu_alloc_stack
40e8c6f4
AB
1441 --enable-plugins
1442 enable plugins via shared library loading
afc3a8f9 1443 --disable-containers don't use containers for cross-building
f48e590a 1444 --gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
61d63097
PB
1445EOF
1446 meson_options_help
1447cat << EOF
c23f23b9
MT
1448 system all system emulation targets
1449 user supported user emulation targets
1450 linux-user all linux usermode emulation targets
1451 bsd-user all BSD usermode emulation targets
c23f23b9 1452 guest-agent build the QEMU Guest Agent
c23f23b9 1453 pie Position Independent Executables
21e709aa 1454 modules modules support (non-Windows)
bd83c861 1455 module-upgrades try to load modules from alternate paths for upgrades
c23f23b9
MT
1456 debug-tcg TCG debugging (default is disabled)
1457 debug-info debugging information
cdad781d 1458 lto Enable Link-Time Optimization.
1e4f6065
DB
1459 safe-stack SafeStack Stack Smash Protection. Depends on
1460 clang/llvm >= 3.7 and requires coroutine backend ucontext.
a40161cb 1461 membarrier membarrier system call (for Linux 4.14+ or Windows)
21ab34c9
MA
1462 rdma Enable RDMA-based migration
1463 pvrdma Enable PVRDMA support
299e6f19
PB
1464 vhost-net vhost-net kernel acceleration support
1465 vhost-vsock virtio sockets device support
1466 vhost-scsi vhost-scsi kernel target support
1467 vhost-crypto vhost-user-crypto backend support
1468 vhost-kernel vhost kernel backend support
1469 vhost-user vhost-user backend support
108a6481 1470 vhost-vdpa vhost-vdpa kernel backend support
ed1701c6 1471 live-block-migration Block migration in the main migration stream
c23f23b9 1472 coroutine-pool coroutine freelist (better performance)
c23f23b9 1473 tpm TPM support
b10d49d7 1474 libssh ssh block device support
c23f23b9 1475 numa libnuma support
86583a07 1476 avx2 AVX2 optimization support
6b8cd447 1477 avx512f AVX512F optimization support
a6b1d4c0 1478 replication replication support
c12d66aa 1479 opengl opengl support
c12d66aa
LM
1480 xfsctl xfsctl support
1481 qom-cast-debug cast debugging support
8de73fa8 1482 tools build qemu-io, qemu-nbd and qemu-img tools
2f740136
JC
1483 bochs bochs image format support
1484 cloop cloop image format support
1485 dmg dmg image format support
1486 qcow1 qcow v1 image format support
1487 vdi vdi image format support
1488 vvfat vvfat image format support
1489 qed qed image format support
1490 parallels parallels image format support
f0d92b56 1491 crypto-afalg Linux AF_ALG crypto backend driver
ba59fb77 1492 debug-mutex mutex debugging support
b767d257 1493 rng-none dummy RNG, avoid using /dev/(u)random and getrandom()
20cf7b8e 1494 gio libgio support
b8e0c493 1495 slirp-smbd use smbd (at path --smbd=*) in slirp networking
08fb77ed
SW
1496
1497NOTE: The object files are built at the place where configure is launched
af5db58e 1498EOF
2d2ad6d0 1499exit 0
af5db58e
PB
1500fi
1501
9c790242 1502# Remove old dependency files to make sure that they get properly regenerated
bb768f71 1503rm -f */config-devices.mak.d
9c790242 1504
faf44142
DB
1505if test -z "$python"
1506then
1507 error_exit "Python not found. Use --python=/path/to/python"
c53eeaf7 1508fi
8e2c76bd
RB
1509if ! has "$make"
1510then
1511 error_exit "GNU make ($make) not found"
1512fi
c53eeaf7
SH
1513
1514# Note that if the Python conditional here evaluates True we will exit
1515# with status 1 which is a shell 'false' value.
1b11f28d
TH
1516if ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then
1517 error_exit "Cannot use '$python', Python >= 3.6 is required." \
c53eeaf7
SH
1518 "Use --python=/path/to/python to specify a supported Python."
1519fi
1520
755ee70f 1521# Preserve python version since some functionality is dependent on it
406ab2f3 1522python_version=$($python -c 'import sys; print("%d.%d.%d" % (sys.version_info[0], sys.version_info[1], sys.version_info[2]))' 2>/dev/null)
755ee70f 1523
c53eeaf7
SH
1524# Suppress writing compiled files
1525python="$python -B"
1526
0a01d76f 1527if test -z "$meson"; then
654d6b04 1528 if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.59.2; then
0a01d76f 1529 meson=meson
7d7dbf9d 1530 elif test $git_submodules_action != 'ignore' ; then
0a01d76f
MAL
1531 meson=git
1532 elif test -e "${source_path}/meson/meson.py" ; then
1533 meson=internal
1534 else
1535 if test "$explicit_python" = yes; then
1536 error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
1537 else
1538 error_exit "Meson not found. Use --meson=/path/to/meson"
1539 fi
1540 fi
1541else
1542 # Meson uses its own Python interpreter to invoke other Python scripts,
1543 # but the user wants to use the one they specified with --python.
1544 #
1545 # We do not want to override the distro Python interpreter (and sometimes
1546 # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
1547 # just require --meson=git|internal together with --python.
1548 if test "$explicit_python" = yes; then
1549 case "$meson" in
1550 git | internal) ;;
1551 *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
1552 esac
1553 fi
a5665051 1554fi
a5665051 1555
0a01d76f
MAL
1556if test "$meson" = git; then
1557 git_submodules="${git_submodules} meson"
a5665051 1558fi
0a01d76f
MAL
1559
1560case "$meson" in
1561 git | internal)
0a01d76f
MAL
1562 meson="$python ${source_path}/meson/meson.py"
1563 ;;
84ec0c24 1564 *) meson=$(command -v "$meson") ;;
0a01d76f
MAL
1565esac
1566
09e93326 1567# Probe for ninja
48328880
PB
1568
1569if test -z "$ninja"; then
1570 for c in ninja ninja-build samu; do
1571 if has $c; then
1572 ninja=$(command -v "$c")
1573 break
1574 fi
1575 done
09e93326
PB
1576 if test -z "$ninja"; then
1577 error_exit "Cannot find Ninja"
1578 fi
48328880 1579fi
a5665051 1580
9aae6e54
DHB
1581# Check that the C compiler works. Doing this here before testing
1582# the host CPU ensures that we had a valid CC to autodetect the
1583# $cpu var (and we should bail right here if that's not the case).
1584# It also allows the help message to be printed without a CC.
1585write_c_skeleton;
1586if compile_object ; then
1587 : C compiler works ok
1588else
1589 error_exit "\"$cc\" either does not exist or does not work"
1590fi
1591if ! compile_prog ; then
1592 error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
1593fi
1594
9c83ffd8
PM
1595# Consult white-list to determine whether to enable werror
1596# by default. Only enable by default for git builds
9c83ffd8 1597if test -z "$werror" ; then
7d7dbf9d 1598 if test "$git_submodules_action" != "ignore" && \
e633a5c6 1599 { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
9c83ffd8
PM
1600 werror="yes"
1601 else
1602 werror="no"
1603 fi
1604fi
1605
975ff037 1606if test "$targetos" = "bogus"; then
fb59dabd
PM
1607 # Now that we know that we're not printing the help and that
1608 # the compiler works (so the results of the check_defines we used
1609 # to identify the OS are reliable), if we didn't recognize the
1610 # host OS we should stop now.
951fedfc 1611 error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
fb59dabd
PM
1612fi
1613
efc6c070
TH
1614# Check whether the compiler matches our minimum requirements:
1615cat > $TMPC << EOF
1616#if defined(__clang_major__) && defined(__clang_minor__)
1617# ifdef __apple_build_version__
2a85a08c
DB
1618# if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
1619# error You need at least XCode Clang v10.0 to compile QEMU
efc6c070
TH
1620# endif
1621# else
2a85a08c
DB
1622# if __clang_major__ < 6 || (__clang_major__ == 6 && __clang_minor__ < 0)
1623# error You need at least Clang v6.0 to compile QEMU
efc6c070
TH
1624# endif
1625# endif
1626#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
3830df5f 1627# if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
1628# error You need at least GCC v7.4.0 to compile QEMU
efc6c070
TH
1629# endif
1630#else
1631# error You either need GCC or Clang to compiler QEMU
1632#endif
1633int main (void) { return 0; }
1634EOF
1635if ! compile_prog "" "" ; then
3830df5f 1636 error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
efc6c070
TH
1637fi
1638
00849b92
RH
1639# Accumulate -Wfoo and -Wno-bar separately.
1640# We will list all of the enable flags first, and the disable flags second.
1641# Note that we do not add -Werror, because that would enable it for all
1642# configure tests. If a configure test failed due to -Werror this would
1643# just silently disable some features, so it's too error prone.
1644
1645warn_flags=
1646add_to warn_flags -Wold-style-declaration
1647add_to warn_flags -Wold-style-definition
1648add_to warn_flags -Wtype-limits
1649add_to warn_flags -Wformat-security
1650add_to warn_flags -Wformat-y2k
1651add_to warn_flags -Winit-self
1652add_to warn_flags -Wignored-qualifiers
1653add_to warn_flags -Wempty-body
1654add_to warn_flags -Wnested-externs
1655add_to warn_flags -Wendif-labels
1656add_to warn_flags -Wexpansion-to-defined
0a2ebce9 1657add_to warn_flags -Wimplicit-fallthrough=2
00849b92
RH
1658
1659nowarn_flags=
1660add_to nowarn_flags -Wno-initializer-overrides
1661add_to nowarn_flags -Wno-missing-include-dirs
1662add_to nowarn_flags -Wno-shift-negative-value
1663add_to nowarn_flags -Wno-string-plus-int
1664add_to nowarn_flags -Wno-typedef-redefinition
aabab967 1665add_to nowarn_flags -Wno-tautological-type-limit-compare
bac8d222 1666add_to nowarn_flags -Wno-psabi
00849b92
RH
1667
1668gcc_flags="$warn_flags $nowarn_flags"
93b25869
JS
1669
1670cc_has_warning_flag() {
1671 write_c_skeleton;
1672
a1d29d6c
PM
1673 # Use the positive sense of the flag when testing for -Wno-wombat
1674 # support (gcc will happily accept the -Wno- form of unknown
1675 # warning options).
93b25869
JS
1676 optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
1677 compile_prog "-Werror $optflag" ""
1678}
1679
1680for flag in $gcc_flags; do
1681 if cc_has_warning_flag $flag ; then
1682 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
8d05095c
PB
1683 fi
1684done
1685
3b463a3f 1686if test "$stack_protector" != "no"; then
fccd35a0
RR
1687 cat > $TMPC << EOF
1688int main(int argc, char *argv[])
1689{
1690 char arr[64], *p = arr, *c = argv[0];
1691 while (*c) {
1692 *p++ = *c++;
1693 }
1694 return 0;
1695}
1696EOF
63678e17 1697 gcc_flags="-fstack-protector-strong -fstack-protector-all"
3b463a3f 1698 sp_on=0
63678e17 1699 for flag in $gcc_flags; do
590e5dd9
PM
1700 # We need to check both a compile and a link, since some compiler
1701 # setups fail only on a .c->.o compile and some only at link time
086d5f75 1702 if compile_object "-Werror $flag" &&
590e5dd9 1703 compile_prog "-Werror $flag" ""; then
63678e17 1704 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
db5adeaa 1705 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
3b463a3f 1706 sp_on=1
63678e17
SN
1707 break
1708 fi
1709 done
3b463a3f
MR
1710 if test "$stack_protector" = yes; then
1711 if test $sp_on = 0; then
1712 error_exit "Stack protector not supported"
1713 fi
1714 fi
37746c5e
MAL
1715fi
1716
20bc94a2
PB
1717# Disable -Wmissing-braces on older compilers that warn even for
1718# the "universal" C zero initializer {0}.
1719cat > $TMPC << EOF
1720struct {
1721 int a[2];
1722} x = {0};
1723EOF
1724if compile_object "-Werror" "" ; then
1725 :
1726else
1727 QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
1728fi
1729
21e709aa
MAL
1730# Our module code doesn't support Windows
1731if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
1732 error_exit "Modules are not available for Windows"
1733fi
1734
bd83c861
CE
1735# module_upgrades is only reasonable if modules are enabled
1736if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
1737 error_exit "Can't enable module-upgrades as Modules are not enabled"
1738fi
1739
5f2453ac 1740# Static linking is not possible with plugins, modules or PIE
40d6444e 1741if test "$static" = "yes" ; then
aa0d1f44
PB
1742 if test "$modules" = "yes" ; then
1743 error_exit "static and modules are mutually incompatible"
1744 fi
5f2453ac
AB
1745 if test "$plugins" = "yes"; then
1746 error_exit "static and plugins are mutually incompatible"
ba4dd2aa
AB
1747 else
1748 plugins="no"
5f2453ac 1749 fi
40d6444e
AK
1750fi
1751
768b7855
EC
1752# Unconditional check for compiler __thread support
1753 cat > $TMPC << EOF
1754static __thread int tls_var;
1755int main(void) { return tls_var; }
1756EOF
1757
1758if ! compile_prog "-Werror" "" ; then
1759 error_exit "Your compiler does not support the __thread specifier for " \
1760 "Thread-Local Storage (TLS). Please upgrade to a version that does."
1761fi
1762
b2634124 1763cat > $TMPC << EOF
21d4a791
AK
1764
1765#ifdef __linux__
1766# define THREAD __thread
1767#else
1768# define THREAD
1769#endif
21d4a791 1770static THREAD int tls_var;
21d4a791 1771int main(void) { return tls_var; }
40d6444e 1772EOF
412aeacd 1773
ffd205ef
JC
1774# Check we support -fno-pie and -no-pie first; we will need the former for
1775# building ROMs, and both for everything if --disable-pie is passed.
b2634124
RH
1776if compile_prog "-Werror -fno-pie" "-no-pie"; then
1777 CFLAGS_NOPIE="-fno-pie"
ffd205ef 1778 LDFLAGS_NOPIE="-no-pie"
b2634124
RH
1779fi
1780
12781462 1781if test "$static" = "yes"; then
eca7a8e6 1782 if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
5770e8af 1783 CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
12781462
RH
1784 QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
1785 pie="yes"
1786 elif test "$pie" = "yes"; then
1787 error_exit "-static-pie not available due to missing toolchain support"
1788 else
1789 QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
1790 pie="no"
1791 fi
1792elif test "$pie" = "no"; then
5770e8af 1793 CONFIGURE_CFLAGS="$CFLAGS_NOPIE $CONFIGURE_CFLAGS"
ffd205ef 1794 CONFIGURE_LDFLAGS="$LDFLAGS_NOPIE $CONFIGURE_LDFLAGS"
eca7a8e6 1795elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
5770e8af
PB
1796 CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
1797 CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
2c674109
RH
1798 pie="yes"
1799elif test "$pie" = "yes"; then
1800 error_exit "PIE not available due to missing toolchain support"
1801else
1802 echo "Disabling PIE due to missing toolchain support"
1803 pie="no"
40d6444e
AK
1804fi
1805
e6cbd751
RH
1806# Detect support for PT_GNU_RELRO + DT_BIND_NOW.
1807# The combination is known as "full relro", because .got.plt is read-only too.
1808if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1809 QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
1810fi
1811
09dada40
PB
1812##########################################
1813# __sync_fetch_and_and requires at least -march=i486. Many toolchains
1814# use i686 as default anyway, but for those that don't, an explicit
1815# specification is necessary
1816
1817if test "$cpu" = "i386"; then
1818 cat > $TMPC << EOF
1819static int sfaa(int *ptr)
1820{
1821 return __sync_fetch_and_and(ptr, 0);
1822}
1823
1824int main(void)
1825{
1826 int val = 42;
1405b629 1827 val = __sync_val_compare_and_swap(&val, 0, 1);
09dada40
PB
1828 sfaa(&val);
1829 return val;
1830}
1831EOF
1832 if ! compile_prog "" "" ; then
1833 QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
1834 fi
1835fi
1836
56267b62
PMD
1837if test "$tcg" = "enabled"; then
1838 git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
1839 git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
1840fi
1841
afb63ebd 1842if test -z "${target_list+xxx}" ; then
fdb75aef 1843 default_targets=yes
d880a3ba 1844 for target in $default_target_list; do
fdb75aef 1845 target_list="$target_list $target"
d880a3ba
PB
1846 done
1847 target_list="${target_list# }"
121afa9e 1848else
fdb75aef 1849 default_targets=no
89138857 1850 target_list=$(echo "$target_list" | sed -e 's/,/ /g')
d880a3ba
PB
1851 for target in $target_list; do
1852 # Check that we recognised the target name; this allows a more
1853 # friendly error message than if we let it fall through.
1854 case " $default_target_list " in
1855 *" $target "*)
1856 ;;
1857 *)
1858 error_exit "Unknown target name '$target'"
1859 ;;
1860 esac
d880a3ba 1861 done
121afa9e 1862fi
25b48338 1863
fdb75aef
PB
1864for target in $target_list; do
1865 # if a deprecated target is enabled we note it here
1866 if echo "$deprecated_targets_list" | grep -q "$target"; then
1867 add_to deprecated_features $target
1868 fi
1869done
1870
f55fe278
PB
1871# see if system emulation was really requested
1872case " $target_list " in
1873 *"-softmmu "*) softmmu=yes
1874 ;;
1875 *) softmmu=no
1876 ;;
1877esac
5327cf48 1878
249247c9
JQ
1879feature_not_found() {
1880 feature=$1
21684af0 1881 remedy=$2
249247c9 1882
76ad07a4 1883 error_exit "User requested feature $feature" \
21684af0
SS
1884 "configure was not able to find it." \
1885 "$remedy"
249247c9
JQ
1886}
1887
7d13299d
FB
1888# ---
1889# big/little endian test
1890cat > $TMPC << EOF
659eb157 1891#include <stdio.h>
61cc919f
MF
1892short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
1893short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
659eb157
TH
1894int main(int argc, char *argv[])
1895{
1896 return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
7d13299d
FB
1897}
1898EOF
1899
659eb157
TH
1900if compile_prog ; then
1901 if strings -a $TMPE | grep -q BiGeNdIaN ; then
61cc919f 1902 bigendian="yes"
659eb157 1903 elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
61cc919f
MF
1904 bigendian="no"
1905 else
1906 echo big/little test failed
659eb157 1907 exit 1
21d89f84 1908 fi
61cc919f
MF
1909else
1910 echo big/little test failed
659eb157 1911 exit 1
7d13299d
FB
1912fi
1913
e10ee3f5
PMD
1914##########################################
1915# system tools
1916if test -z "$want_tools"; then
1917 if test "$softmmu" = "no"; then
1918 want_tools=no
1919 else
1920 want_tools=yes
1921 fi
1922fi
1923
015a33bd
GA
1924##########################################
1925# L2TPV3 probe
1926
1927cat > $TMPC <<EOF
1928#include <sys/socket.h>
bff6cb72 1929#include <linux/ip.h>
015a33bd
GA
1930int main(void) { return sizeof(struct mmsghdr); }
1931EOF
1932if compile_prog "" "" ; then
1933 l2tpv3=yes
1934else
1935 l2tpv3=no
1936fi
1937
299e6f19
PB
1938#########################################
1939# vhost interdependencies and host support
1940
1941# vhost backends
d88618f7
SH
1942if test "$vhost_user" = "yes" && test "$linux" != "yes"; then
1943 error_exit "vhost-user is only available on Linux"
299e6f19 1944fi
108a6481
CL
1945test "$vhost_vdpa" = "" && vhost_vdpa=$linux
1946if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
1947 error_exit "vhost-vdpa is only available on Linux"
1948fi
299e6f19
PB
1949test "$vhost_kernel" = "" && vhost_kernel=$linux
1950if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
1951 error_exit "vhost-kernel is only available on Linux"
1952fi
1953
1954# vhost-kernel devices
1955test "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
1956if test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
1957 error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
1958fi
1959test "$vhost_vsock" = "" && vhost_vsock=$vhost_kernel
1960if test "$vhost_vsock" = "yes" && test "$vhost_kernel" != "yes"; then
1961 error_exit "--enable-vhost-vsock requires --enable-vhost-kernel"
1962fi
1963
1964# vhost-user backends
1965test "$vhost_net_user" = "" && vhost_net_user=$vhost_user
1966if test "$vhost_net_user" = "yes" && test "$vhost_user" = "no"; then
1967 error_exit "--enable-vhost-net-user requires --enable-vhost-user"
1968fi
1969test "$vhost_crypto" = "" && vhost_crypto=$vhost_user
1970if test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
1971 error_exit "--enable-vhost-crypto requires --enable-vhost-user"
1972fi
98fc1ada
DDAG
1973test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
1974if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
1975 error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
1976fi
108a6481
CL
1977#vhost-vdpa backends
1978test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa
1979if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then
1980 error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa"
1981fi
299e6f19 1982
40bc0ca9 1983# OR the vhost-kernel, vhost-vdpa and vhost-user values for simplicity
299e6f19
PB
1984if test "$vhost_net" = ""; then
1985 test "$vhost_net_user" = "yes" && vhost_net=yes
40bc0ca9 1986 test "$vhost_net_vdpa" = "yes" && vhost_net=yes
299e6f19
PB
1987 test "$vhost_kernel" = "yes" && vhost_net=yes
1988fi
1989
779ab5e3
SW
1990##########################################
1991# pkg-config probe
1992
1993if ! has "$pkg_config_exe"; then
76ad07a4 1994 error_exit "pkg-config binary '$pkg_config_exe' not found"
779ab5e3
SW
1995fi
1996
b0a47e79
JQ
1997##########################################
1998# NPTL probe
1999
24cb36a6 2000if test "$linux_user" = "yes"; then
b0a47e79 2001 cat > $TMPC <<EOF
bd0c5661 2002#include <sched.h>
30813cea 2003#include <linux/futex.h>
182eacc0 2004int main(void) {
bd0c5661
PB
2005#if !defined(CLONE_SETTLS) || !defined(FUTEX_WAIT)
2006#error bork
2007#endif
182eacc0 2008 return 0;
bd0c5661
PB
2009}
2010EOF
24cb36a6 2011 if ! compile_object ; then
21684af0 2012 feature_not_found "nptl" "Install glibc and linux kernel headers."
b0a47e79 2013 fi
bd0c5661
PB
2014fi
2015
e37630ca
AL
2016##########################################
2017# xen probe
2018
1badb709 2019if test "$xen" != "disabled" ; then
c1cdd9d5
JG
2020 # Check whether Xen library path is specified via --extra-ldflags to avoid
2021 # overriding this setting with pkg-config output. If not, try pkg-config
2022 # to obtain all needed flags.
2023
2024 if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \
2025 $pkg_config --exists xencontrol ; then
2026 xen_ctrl_version="$(printf '%d%02d%02d' \
2027 $($pkg_config --modversion xencontrol | sed 's/\./ /g') )"
1badb709 2028 xen=enabled
5b6a8f43 2029 xen_pc="xencontrol xenstore xenforeignmemory xengnttab"
c1cdd9d5 2030 xen_pc="$xen_pc xenevtchn xendevicemodel"
58ea9a7a
AP
2031 if $pkg_config --exists xentoolcore; then
2032 xen_pc="$xen_pc xentoolcore"
2033 fi
582ea95f
MAL
2034 xen_cflags="$($pkg_config --cflags $xen_pc)"
2035 xen_libs="$($pkg_config --libs $xen_pc)"
c1cdd9d5 2036 else
d5b93ddf 2037
5b6a8f43 2038 xen_libs="-lxenstore -lxenctrl"
d9506cab 2039 xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
50ced5b3 2040
c1cdd9d5
JG
2041 # First we test whether Xen headers and libraries are available.
2042 # If no, we are done and there is no Xen support.
2043 # If yes, more tests are run to detect the Xen version.
2044
2045 # Xen (any)
2046 cat > $TMPC <<EOF
e37630ca 2047#include <xenctrl.h>
50ced5b3
SW
2048int main(void) {
2049 return 0;
2050}
2051EOF
c1cdd9d5
JG
2052 if ! compile_prog "" "$xen_libs" ; then
2053 # Xen not found
1badb709 2054 if test "$xen" = "enabled" ; then
c1cdd9d5
JG
2055 feature_not_found "xen" "Install xen devel"
2056 fi
1badb709 2057 xen=disabled
50ced5b3 2058
c1cdd9d5
JG
2059 # Xen unstable
2060 elif
2061 cat > $TMPC <<EOF &&
2cbf8903
RL
2062#undef XC_WANT_COMPAT_DEVICEMODEL_API
2063#define __XEN_TOOLS__
2064#include <xendevicemodel.h>
d3c49ebb 2065#include <xenforeignmemory.h>
2cbf8903
RL
2066int main(void) {
2067 xendevicemodel_handle *xd;
d3c49ebb 2068 xenforeignmemory_handle *xfmem;
2cbf8903
RL
2069
2070 xd = xendevicemodel_open(0, 0);
2071 xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);
2072
d3c49ebb
PD
2073 xfmem = xenforeignmemory_open(0, 0);
2074 xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);
2075
2cbf8903
RL
2076 return 0;
2077}
2078EOF
2079 compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
2080 then
2081 xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
2082 xen_ctrl_version=41100
1badb709 2083 xen=enabled
2cbf8903
RL
2084 elif
2085 cat > $TMPC <<EOF &&
5ba3d756
ID
2086#undef XC_WANT_COMPAT_MAP_FOREIGN_API
2087#include <xenforeignmemory.h>
58ea9a7a 2088#include <xentoolcore.h>
5ba3d756
ID
2089int main(void) {
2090 xenforeignmemory_handle *xfmem;
2091
2092 xfmem = xenforeignmemory_open(0, 0);
2093 xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
58ea9a7a 2094 xentoolcore_restrict_all(0);
5ba3d756
ID
2095
2096 return 0;
2097}
2098EOF
58ea9a7a 2099 compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
5ba3d756 2100 then
58ea9a7a 2101 xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
5ba3d756 2102 xen_ctrl_version=41000
1badb709 2103 xen=enabled
5ba3d756
ID
2104 elif
2105 cat > $TMPC <<EOF &&
da8090cc
PD
2106#undef XC_WANT_COMPAT_DEVICEMODEL_API
2107#define __XEN_TOOLS__
2108#include <xendevicemodel.h>
2109int main(void) {
2110 xendevicemodel_handle *xd;
2111
2112 xd = xendevicemodel_open(0, 0);
2113 xendevicemodel_close(xd);
50ced5b3 2114
da8090cc
PD
2115 return 0;
2116}
2117EOF
c1cdd9d5
JG
2118 compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs"
2119 then
2120 xen_stable_libs="-lxendevicemodel $xen_stable_libs"
2121 xen_ctrl_version=40900
1badb709 2122 xen=enabled
c1cdd9d5
JG
2123 elif
2124 cat > $TMPC <<EOF &&
b6eb9b45
PS
2125/*
2126 * If we have stable libs the we don't want the libxc compat
2127 * layers, regardless of what CFLAGS we may have been given.
2128 *
2129 * Also, check if xengnttab_grant_copy_segment_t is defined and
2130 * grant copy operation is implemented.
2131 */
2132#undef XC_WANT_COMPAT_EVTCHN_API
2133#undef XC_WANT_COMPAT_GNTTAB_API
2134#undef XC_WANT_COMPAT_MAP_FOREIGN_API
2135#include <xenctrl.h>
2136#include <xenstore.h>
2137#include <xenevtchn.h>
2138#include <xengnttab.h>
2139#include <xenforeignmemory.h>
2140#include <stdint.h>
2141#include <xen/hvm/hvm_info_table.h>
2142#if !defined(HVM_MAX_VCPUS)
2143# error HVM_MAX_VCPUS not defined
2144#endif
2145int main(void) {
2146 xc_interface *xc = NULL;
2147 xenforeignmemory_handle *xfmem;
2148 xenevtchn_handle *xe;
2149 xengnttab_handle *xg;
b6eb9b45
PS
2150 xengnttab_grant_copy_segment_t* seg = NULL;
2151
2152 xs_daemon_open();
2153
2154 xc = xc_interface_open(0, 0, 0);
2155 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2156 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2157 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2158 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
b6eb9b45
PS
2159
2160 xfmem = xenforeignmemory_open(0, 0);
2161 xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2162
2163 xe = xenevtchn_open(0, 0);
2164 xenevtchn_fd(xe);
2165
2166 xg = xengnttab_open(0, 0);
2167 xengnttab_grant_copy(xg, 0, seg);
2168
2169 return 0;
2170}
2171EOF
c1cdd9d5
JG
2172 compile_prog "" "$xen_libs $xen_stable_libs"
2173 then
2174 xen_ctrl_version=40800
1badb709 2175 xen=enabled
c1cdd9d5
JG
2176 elif
2177 cat > $TMPC <<EOF &&
5eeb39c2
IC
2178/*
2179 * If we have stable libs the we don't want the libxc compat
2180 * layers, regardless of what CFLAGS we may have been given.
2181 */
2182#undef XC_WANT_COMPAT_EVTCHN_API
2183#undef XC_WANT_COMPAT_GNTTAB_API
2184#undef XC_WANT_COMPAT_MAP_FOREIGN_API
2185#include <xenctrl.h>
2186#include <xenstore.h>
2187#include <xenevtchn.h>
2188#include <xengnttab.h>
2189#include <xenforeignmemory.h>
2190#include <stdint.h>
2191#include <xen/hvm/hvm_info_table.h>
2192#if !defined(HVM_MAX_VCPUS)
2193# error HVM_MAX_VCPUS not defined
2194#endif
2195int main(void) {
2196 xc_interface *xc = NULL;
2197 xenforeignmemory_handle *xfmem;
2198 xenevtchn_handle *xe;
2199 xengnttab_handle *xg;
5eeb39c2
IC
2200
2201 xs_daemon_open();
2202
2203 xc = xc_interface_open(0, 0, 0);
2204 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2205 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2206 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2207 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
5eeb39c2
IC
2208
2209 xfmem = xenforeignmemory_open(0, 0);
2210 xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2211
2212 xe = xenevtchn_open(0, 0);
2213 xenevtchn_fd(xe);
2214
2215 xg = xengnttab_open(0, 0);
2216 xengnttab_map_grant_ref(xg, 0, 0, 0);
2217
2218 return 0;
2219}
2220EOF
c1cdd9d5
JG
2221 compile_prog "" "$xen_libs $xen_stable_libs"
2222 then
2223 xen_ctrl_version=40701
1badb709 2224 xen=enabled
c1cdd9d5
JG
2225
2226 # Xen 4.6
2227 elif
2228 cat > $TMPC <<EOF &&
cdadde39 2229#include <xenctrl.h>
e108a3c1 2230#include <xenstore.h>
d5b93ddf
AP
2231#include <stdint.h>
2232#include <xen/hvm/hvm_info_table.h>
2233#if !defined(HVM_MAX_VCPUS)
2234# error HVM_MAX_VCPUS not defined
2235#endif
d8b441a3
JB
2236int main(void) {
2237 xc_interface *xc;
2238 xs_daemon_open();
2239 xc = xc_interface_open(0, 0, 0);
2240 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2241 xc_gnttab_open(NULL, 0);
2242 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2243 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2244 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
20a544c7 2245 xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
d8b441a3
JB
2246 return 0;
2247}
2248EOF
c1cdd9d5
JG
2249 compile_prog "" "$xen_libs"
2250 then
2251 xen_ctrl_version=40600
1badb709 2252 xen=enabled
c1cdd9d5
JG
2253
2254 # Xen 4.5
2255 elif
2256 cat > $TMPC <<EOF &&
d8b441a3
JB
2257#include <xenctrl.h>
2258#include <xenstore.h>
2259#include <stdint.h>
2260#include <xen/hvm/hvm_info_table.h>
2261#if !defined(HVM_MAX_VCPUS)
2262# error HVM_MAX_VCPUS not defined
2263#endif
3996e85c
PD
2264int main(void) {
2265 xc_interface *xc;
2266 xs_daemon_open();
2267 xc = xc_interface_open(0, 0, 0);
2268 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2269 xc_gnttab_open(NULL, 0);
2270 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2271 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2272 xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
2273 return 0;
2274}
2275EOF
c1cdd9d5
JG
2276 compile_prog "" "$xen_libs"
2277 then
2278 xen_ctrl_version=40500
1badb709 2279 xen=enabled
3996e85c 2280
c1cdd9d5
JG
2281 elif
2282 cat > $TMPC <<EOF &&
3996e85c
PD
2283#include <xenctrl.h>
2284#include <xenstore.h>
2285#include <stdint.h>
2286#include <xen/hvm/hvm_info_table.h>
2287#if !defined(HVM_MAX_VCPUS)
2288# error HVM_MAX_VCPUS not defined
2289#endif
8688e065
SS
2290int main(void) {
2291 xc_interface *xc;
2292 xs_daemon_open();
2293 xc = xc_interface_open(0, 0, 0);
2294 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2295 xc_gnttab_open(NULL, 0);
2296 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2297 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2298 return 0;
2299}
2300EOF
c1cdd9d5
JG
2301 compile_prog "" "$xen_libs"
2302 then
2303 xen_ctrl_version=40200
1badb709 2304 xen=enabled
8688e065 2305
c1cdd9d5 2306 else
1badb709 2307 if test "$xen" = "enabled" ; then
c1cdd9d5
JG
2308 feature_not_found "xen (unsupported version)" \
2309 "Install a supported xen (xen 4.2 or newer)"
2310 fi
1badb709 2311 xen=disabled
fc321b4b 2312 fi
d5b93ddf 2313
1badb709 2314 if test "$xen" = enabled; then
c1cdd9d5 2315 if test $xen_ctrl_version -ge 40701 ; then
582ea95f 2316 xen_libs="$xen_libs $xen_stable_libs "
c1cdd9d5 2317 fi
5eeb39c2 2318 fi
d5b93ddf 2319 fi
e37630ca
AL
2320fi
2321
2da776db
MH
2322##########################################
2323# RDMA needs OpenFabrics libraries
2324if test "$rdma" != "no" ; then
2325 cat > $TMPC <<EOF
2326#include <rdma/rdma_cma.h>
2327int main(void) { return 0; }
2328EOF
ef6d4ccd 2329 rdma_libs="-lrdmacm -libverbs -libumad"
2da776db
MH
2330 if compile_prog "" "$rdma_libs" ; then
2331 rdma="yes"
2da776db
MH
2332 else
2333 if test "$rdma" = "yes" ; then
2334 error_exit \
ef6d4ccd 2335 " OpenFabrics librdmacm/libibverbs/libibumad not present." \
2da776db 2336 " Your options:" \
ef6d4ccd 2337 " (1) Fast: Install infiniband packages (devel) from your distro." \
2da776db
MH
2338 " (2) Cleanest: Install libraries from www.openfabrics.org" \
2339 " (3) Also: Install softiwarp if you don't have RDMA hardware"
2340 fi
2341 rdma="no"
2342 fi
2343fi
2344
21ab34c9
MA
2345##########################################
2346# PVRDMA detection
2347
2348cat > $TMPC <<EOF &&
2349#include <sys/mman.h>
2350
2351int
2352main(void)
2353{
2354 char buf = 0;
2355 void *addr = &buf;
2356 addr = mremap(addr, 0, 1, MREMAP_MAYMOVE | MREMAP_FIXED);
2357
2358 return 0;
2359}
2360EOF
2361
2362if test "$rdma" = "yes" ; then
2363 case "$pvrdma" in
2364 "")
2365 if compile_prog "" ""; then
2366 pvrdma="yes"
2367 else
2368 pvrdma="no"
2369 fi
2370 ;;
2371 "yes")
2372 if ! compile_prog "" ""; then
2373 error_exit "PVRDMA is not supported since mremap is not implemented"
2374 fi
2375 pvrdma="yes"
2376 ;;
2377 "no")
2378 pvrdma="no"
2379 ;;
2380 esac
2381else
2382 if test "$pvrdma" = "yes" ; then
2383 error_exit "PVRDMA requires rdma suppport"
2384 fi
2385 pvrdma="no"
2386fi
95c6bff3 2387
ee108585
YS
2388# Let's see if enhanced reg_mr is supported
2389if test "$pvrdma" = "yes" ; then
2390
2391cat > $TMPC <<EOF &&
2392#include <infiniband/verbs.h>
2393
2394int
2395main(void)
2396{
2397 struct ibv_mr *mr;
2398 struct ibv_pd *pd = NULL;
2399 size_t length = 10;
2400 uint64_t iova = 0;
2401 int access = 0;
2402 void *addr = NULL;
2403
2404 mr = ibv_reg_mr_iova(pd, addr, length, iova, access);
2405
2406 ibv_dereg_mr(mr);
2407
2408 return 0;
2409}
2410EOF
2411 if ! compile_prog "" "-libverbs"; then
2412 QEMU_CFLAGS="$QEMU_CFLAGS -DLEGACY_RDMA_REG_MR"
2413 fi
2414fi
2415
ee682d27 2416##########################################
c1bb86cd 2417# xfsctl() probe, used for file-posix.c
dce512de
CH
2418if test "$xfs" != "no" ; then
2419 cat > $TMPC << EOF
ffc41d10 2420#include <stddef.h> /* NULL */
dce512de
CH
2421#include <xfs/xfs.h>
2422int main(void)
2423{
2424 xfsctl(NULL, 0, 0, NULL);
2425 return 0;
2426}
2427EOF
2428 if compile_prog "" "" ; then
2429 xfs="yes"
2430 else
2431 if test "$xfs" = "yes" ; then
e3a6e0da 2432 feature_not_found "xfs" "Install xfsprogs/xfslibs devel"
dce512de
CH
2433 fi
2434 xfs=no
2435 fi
2436fi
2437
ba4dd2aa
AB
2438##########################################
2439# plugin linker support probe
2440
2441if test "$plugins" != "no"; then
2442
2443 #########################################
2444 # See if --dynamic-list is supported by the linker
2445
2446 ld_dynamic_list="no"
2447 cat > $TMPTXT <<EOF
2448{
2449 foo;
2450};
2451EOF
2452
2453 cat > $TMPC <<EOF
2454#include <stdio.h>
2455void foo(void);
2456
2457void foo(void)
2458{
2459 printf("foo\n");
2460}
2461
2462int main(void)
2463{
2464 foo();
2465 return 0;
2466}
2467EOF
2468
2469 if compile_prog "" "-Wl,--dynamic-list=$TMPTXT" ; then
2470 ld_dynamic_list="yes"
2471 fi
2472
2473 #########################################
2474 # See if -exported_symbols_list is supported by the linker
2475
2476 ld_exported_symbols_list="no"
2477 cat > $TMPTXT <<EOF
2478 _foo
2479EOF
2480
2481 if compile_prog "" "-Wl,-exported_symbols_list,$TMPTXT" ; then
2482 ld_exported_symbols_list="yes"
2483 fi
2484
2485 if test "$ld_dynamic_list" = "no" &&
2486 test "$ld_exported_symbols_list" = "no" ; then
2487 if test "$plugins" = "yes"; then
2488 error_exit \
2489 "Plugin support requires dynamic linking and specifying a set of symbols " \
2490 "that are exported to plugins. Unfortunately your linker doesn't " \
2491 "support the flag (--dynamic-list or -exported_symbols_list) used " \
2492 "for this purpose."
2493 else
2494 plugins="no"
2495 fi
2496 else
2497 plugins="yes"
2498 fi
2499fi
2500
e18df141
AL
2501##########################################
2502# glib support probe
a52d28af 2503
b4c6036f 2504glib_req_ver=2.56
aa0d1f44
PB
2505glib_modules=gthread-2.0
2506if test "$modules" = yes; then
a88afc64 2507 glib_modules="$glib_modules gmodule-export-2.0"
b906acac
PB
2508elif test "$plugins" = "yes"; then
2509 glib_modules="$glib_modules gmodule-no-export-2.0"
54cb65d8 2510fi
e26110cf 2511
aa0d1f44 2512for i in $glib_modules; do
e26110cf 2513 if $pkg_config --atleast-version=$glib_req_ver $i; then
89138857
SW
2514 glib_cflags=$($pkg_config --cflags $i)
2515 glib_libs=$($pkg_config --libs $i)
e26110cf
FZ
2516 else
2517 error_exit "glib-$glib_req_ver $i is required to compile QEMU"
2518 fi
2519done
2520
215b0c2f
PB
2521# This workaround is required due to a bug in pkg-config file for glib as it
2522# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
2523
2524if test "$static" = yes && test "$mingw32" = yes; then
2525 glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
2526fi
2527
20cf7b8e
DP
2528if ! test "$gio" = "no"; then
2529 pass=no
2530 if $pkg_config --atleast-version=$glib_req_ver gio-2.0; then
2531 gio_cflags=$($pkg_config --cflags gio-2.0)
2532 gio_libs=$($pkg_config --libs gio-2.0)
2533 gdbus_codegen=$($pkg_config --variable=gdbus_codegen gio-2.0)
5ecfb76c 2534 if ! has "$gdbus_codegen"; then
20cf7b8e
DP
2535 gdbus_codegen=
2536 fi
2537 # Check that the libraries actually work -- Ubuntu 18.04 ships
2538 # with pkg-config --static --libs data for gio-2.0 that is missing
2539 # -lblkid and will give a link error.
2540 cat > $TMPC <<EOF
13ceae66
PM
2541#include <gio/gio.h>
2542int main(void)
2543{
2544 g_dbus_proxy_new_sync(0, 0, 0, 0, 0, 0, 0, 0);
2545 return 0;
2546}
2547EOF
20cf7b8e
DP
2548 if compile_prog "$gio_cflags" "$gio_libs" ; then
2549 pass=yes
2550 else
2551 pass=no
2552 fi
2553
2554 if test "$pass" = "yes" &&
2555 $pkg_config --atleast-version=$glib_req_ver gio-unix-2.0; then
2556 gio_cflags="$gio_cflags $($pkg_config --cflags gio-unix-2.0)"
2557 gio_libs="$gio_libs $($pkg_config --libs gio-unix-2.0)"
2558 fi
76346b62 2559 fi
f876b765 2560
20cf7b8e
DP
2561 if test "$pass" = "no"; then
2562 if test "$gio" = "yes"; then
2563 feature_not_found "gio" "Install libgio >= 2.0"
2564 else
2565 gio=no
2566 fi
2567 else
2568 gio=yes
2569 fi
25a97a56
MAL
2570fi
2571
977a82ab
DB
2572# Sanity check that the current size_t matches the
2573# size that glib thinks it should be. This catches
2574# problems on multi-arch where people try to build
2575# 32-bit QEMU while pointing at 64-bit glib headers
2576cat > $TMPC <<EOF
2577#include <glib.h>
2578#include <unistd.h>
2579
2580#define QEMU_BUILD_BUG_ON(x) \
2581 typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
2582
2583int main(void) {
2584 QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
2585 return 0;
2586}
2587EOF
2588
215b0c2f 2589if ! compile_prog "$glib_cflags" "$glib_libs" ; then
977a82ab
DB
2590 error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
2591 "You probably need to set PKG_CONFIG_LIBDIR"\
2592 "to point to the right pkg-config files for your"\
2593 "build target"
2594fi
2595
9bda600b
EB
2596# Silence clang warnings triggered by glib < 2.57.2
2597cat > $TMPC << EOF
2598#include <glib.h>
2599typedef struct Foo {
2600 int i;
2601} Foo;
2602static void foo_free(Foo *f)
2603{
2604 g_free(f);
2605}
2606G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free);
2607int main(void) { return 0; }
2608EOF
2609if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
2610 if cc_has_warning_flag "-Wno-unused-function"; then
2611 glib_cflags="$glib_cflags -Wno-unused-function"
5770e8af 2612 CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
9bda600b
EB
2613 fi
2614fi
2615
e26110cf
FZ
2616##########################################
2617# SHA command probe for modules
2618if test "$modules" = yes; then
2619 shacmd_probe="sha1sum sha1 shasum"
2620 for c in $shacmd_probe; do
8ccefb91 2621 if has $c; then
e26110cf
FZ
2622 shacmd="$c"
2623 break
2624 fi
2625 done
2626 if test "$shacmd" = ""; then
2627 error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
2628 fi
e18df141
AL
2629fi
2630
0a12ec87 2631##########################################
b10d49d7
PT
2632# libssh probe
2633if test "$libssh" != "no" ; then
b4c10fc6 2634 if $pkg_config --exists "libssh >= 0.8.7"; then
b10d49d7
PT
2635 libssh_cflags=$($pkg_config libssh --cflags)
2636 libssh_libs=$($pkg_config libssh --libs)
2637 libssh=yes
0a12ec87 2638 else
b10d49d7
PT
2639 if test "$libssh" = "yes" ; then
2640 error_exit "libssh required for --enable-libssh"
0a12ec87 2641 fi
b10d49d7 2642 libssh=no
0a12ec87
RJ
2643 fi
2644fi
2645
3b8acc11 2646##########################################
7aaa6a16 2647# TPM emulation is only on POSIX
3b8acc11 2648
7aaa6a16
PB
2649if test "$tpm" = ""; then
2650 if test "$mingw32" = "yes"; then
2651 tpm=no
2652 else
2653 tpm=yes
2654 fi
2655elif test "$tpm" = "yes"; then
2656 if test "$mingw32" = "yes" ; then
2657 error_exit "TPM emulation only available on POSIX systems"
2658 fi
3b8acc11
PB
2659fi
2660
f652e6af
AJ
2661##########################################
2662# fdt probe
d599938a 2663
fbb4121d
PB
2664case "$fdt" in
2665 auto | enabled | internal)
2666 # Simpler to always update submodule, even if not needed.
2d652f24 2667 git_submodules="${git_submodules} dtc"
fbb4121d
PB
2668 ;;
2669esac
f652e6af 2670
20ff075b 2671##########################################
9d49bcf6 2672# opengl probe (for sdl2, gtk)
b1546f32 2673
da076ffe 2674if test "$opengl" != "no" ; then
bc6a3565
AO
2675 epoxy=no
2676 if $pkg_config epoxy; then
2677 cat > $TMPC << EOF
2678#include <epoxy/egl.h>
2679int main(void) { return 0; }
2680EOF
2681 if compile_prog "" "" ; then
2682 epoxy=yes
2683 fi
2684 fi
2685
2686 if test "$epoxy" = "yes" ; then
2687 opengl_cflags="$($pkg_config --cflags epoxy)"
2688 opengl_libs="$($pkg_config --libs epoxy)"
da076ffe 2689 opengl=yes
20ff075b 2690 else
da076ffe 2691 if test "$opengl" = "yes" ; then
bc6a3565 2692 feature_not_found "opengl" "Please install epoxy with EGL"
20ff075b 2693 fi
f676c67e 2694 opengl_cflags=""
da076ffe
GH
2695 opengl_libs=""
2696 opengl=no
20ff075b
MW
2697 fi
2698fi
2699
a99d57bb
WG
2700##########################################
2701# libnuma probe
2702
2703if test "$numa" != "no" ; then
2704 cat > $TMPC << EOF
2705#include <numa.h>
2706int main(void) { return numa_available(); }
2707EOF
2708
2709 if compile_prog "" "-lnuma" ; then
2710 numa=yes
ab318051 2711 numa_libs="-lnuma"
a99d57bb
WG
2712 else
2713 if test "$numa" = "yes" ; then
2714 feature_not_found "numa" "install numactl devel"
2715 fi
2716 numa=no
2717 fi
2718fi
2719
955727d2
CT
2720# check for usbfs
2721have_usbfs=no
2722if test "$linux_user" = "yes"; then
96566d09
TP
2723 cat > $TMPC << EOF
2724#include <linux/usbdevice_fs.h>
2725
2726#ifndef USBDEVFS_GET_CAPABILITIES
2727#error "USBDEVFS_GET_CAPABILITIES undefined"
2728#endif
2729
2730#ifndef USBDEVFS_DISCONNECT_CLAIM
2731#error "USBDEVFS_DISCONNECT_CLAIM undefined"
2732#endif
2733
2734int main(void)
2735{
2736 return 0;
2737}
2738EOF
2739 if compile_prog "" ""; then
955727d2
CT
2740 have_usbfs=yes
2741 fi
955727d2 2742fi
751bcc39 2743
d9840e25
TS
2744##########################################
2745# check if we have VSS SDK headers for win
2746
e633a5c6
EB
2747if test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
2748 test "$vss_win32_sdk" != "no" ; then
d9840e25 2749 case "$vss_win32_sdk" in
690604f6 2750 "") vss_win32_include="-isystem $source_path" ;;
d9840e25
TS
2751 *\ *) # The SDK is installed in "Program Files" by default, but we cannot
2752 # handle path with spaces. So we symlink the headers into ".sdk/vss".
690604f6 2753 vss_win32_include="-isystem $source_path/.sdk/vss"
d9840e25
TS
2754 symlink "$vss_win32_sdk/inc" "$source_path/.sdk/vss/inc"
2755 ;;
690604f6 2756 *) vss_win32_include="-isystem $vss_win32_sdk"
d9840e25
TS
2757 esac
2758 cat > $TMPC << EOF
2759#define __MIDL_user_allocate_free_DEFINED__
2760#include <inc/win2003/vss.h>
2761int main(void) { return VSS_CTX_BACKUP; }
2762EOF
2763 if compile_prog "$vss_win32_include" "" ; then
2764 guest_agent_with_vss="yes"
2765 QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
315d3184 2766 libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++ -Wl,--enable-stdcall-fixup $libs_qga"
f33ca81f 2767 qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb"
d9840e25
TS
2768 else
2769 if test "$vss_win32_sdk" != "" ; then
2770 echo "ERROR: Please download and install Microsoft VSS SDK:"
2771 echo "ERROR: http://www.microsoft.com/en-us/download/details.aspx?id=23490"
2772 echo "ERROR: On POSIX-systems, you can extract the SDK headers by:"
2773 echo "ERROR: scripts/extract-vsssdk-headers setup.exe"
2774 echo "ERROR: The headers are extracted in the directory \`inc'."
2775 feature_not_found "VSS support"
2776 fi
2777 guest_agent_with_vss="no"
2778 fi
2779fi
2780
2781##########################################
2782# lookup Windows platform SDK (if not specified)
2783# The SDK is needed only to build .tlb (type library) file of guest agent
2784# VSS provider from the source. It is usually unnecessary because the
2785# pre-compiled .tlb file is included.
2786
e633a5c6
EB
2787if test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
2788 test "$guest_agent_with_vss" = "yes" ; then
d9840e25
TS
2789 if test -z "$win_sdk"; then
2790 programfiles="$PROGRAMFILES"
2791 test -n "$PROGRAMW6432" && programfiles="$PROGRAMW6432"
2792 if test -n "$programfiles"; then
2793 win_sdk=$(ls -d "$programfiles/Microsoft SDKs/Windows/v"* | tail -1) 2>/dev/null
2794 else
2795 feature_not_found "Windows SDK"
2796 fi
2797 elif test "$win_sdk" = "no"; then
2798 win_sdk=""
2799 fi
2800fi
2801
50cbebb9
MR
2802##########################################
2803# check if mingw environment provides a recent ntddscsi.h
e633a5c6 2804if test "$mingw32" = "yes" && test "$guest_agent" != "no"; then
50cbebb9
MR
2805 cat > $TMPC << EOF
2806#include <windows.h>
2807#include <ntddscsi.h>
2808int main(void) {
2809#if !defined(IOCTL_SCSI_GET_ADDRESS)
2810#error Missing required ioctl definitions
2811#endif
2812 SCSI_ADDRESS addr = { .Lun = 0, .TargetId = 0, .PathId = 0 };
2813 return addr.Lun;
2814}
2815EOF
2816 if compile_prog "" "" ; then
2817 guest_agent_ntddscsi=yes
996b9cdc 2818 libs_qga="-lsetupapi -lcfgmgr32 $libs_qga"
50cbebb9
MR
2819 fi
2820fi
2821
8ca80760
RH
2822##########################################
2823# capstone
2824
e219c499 2825case "$capstone" in
8b18cdbf
RH
2826 auto | enabled | internal)
2827 # Simpler to always update submodule, even if not needed.
2d652f24 2828 git_submodules="${git_submodules} capstone"
e219c499
RH
2829 ;;
2830esac
8ca80760 2831
023367e6 2832##########################################
519175a2 2833# check and set a backend for coroutine
d0e2fce5 2834
7c2acc70 2835# We prefer ucontext, but it's not always possible. The fallback
33c53c54
DB
2836# is sigcontext. On Windows the only valid backend is the Windows
2837# specific one.
7c2acc70
PM
2838
2839ucontext_works=no
2840if test "$darwin" != "yes"; then
2841 cat > $TMPC << EOF
d0e2fce5 2842#include <ucontext.h>
cdf84806
PM
2843#ifdef __stub_makecontext
2844#error Ignoring glibc stub makecontext which will always fail
2845#endif
75cafad7 2846int main(void) { makecontext(0, 0, 0); return 0; }
d0e2fce5 2847EOF
7c2acc70
PM
2848 if compile_prog "" "" ; then
2849 ucontext_works=yes
2850 fi
2851fi
2852
2853if test "$coroutine" = ""; then
2854 if test "$mingw32" = "yes"; then
2855 coroutine=win32
2856 elif test "$ucontext_works" = "yes"; then
2857 coroutine=ucontext
2858 else
2859 coroutine=sigaltstack
d0e2fce5 2860 fi
519175a2 2861else
7c2acc70
PM
2862 case $coroutine in
2863 windows)
2864 if test "$mingw32" != "yes"; then
2865 error_exit "'windows' coroutine backend only valid for Windows"
2866 fi
2867 # Unfortunately the user visible backend name doesn't match the
2868 # coroutine-*.c filename for this case, so we have to adjust it here.
2869 coroutine=win32
2870 ;;
2871 ucontext)
2872 if test "$ucontext_works" != "yes"; then
2873 feature_not_found "ucontext"
2874 fi
2875 ;;
33c53c54 2876 sigaltstack)
7c2acc70
PM
2877 if test "$mingw32" = "yes"; then
2878 error_exit "only the 'windows' coroutine backend is valid for Windows"
2879 fi
2880 ;;
2881 *)
2882 error_exit "unknown coroutine backend $coroutine"
2883 ;;
2884 esac
d0e2fce5
AK
2885fi
2886
70c60c08 2887if test "$coroutine_pool" = ""; then
33c53c54 2888 coroutine_pool=yes
70c60c08
SH
2889fi
2890
7d992e4d 2891if test "$debug_stack_usage" = "yes"; then
7d992e4d
PL
2892 if test "$coroutine_pool" = "yes"; then
2893 echo "WARN: disabling coroutine pool for stack usage debugging"
2894 coroutine_pool=no
2895 fi
2896fi
2897
1e4f6065
DB
2898##################################################
2899# SafeStack
2900
2901
2902if test "$safe_stack" = "yes"; then
2903cat > $TMPC << EOF
2904int main(int argc, char *argv[])
2905{
2906#if ! __has_feature(safe_stack)
2907#error SafeStack Disabled
2908#endif
2909 return 0;
2910}
2911EOF
2912 flag="-fsanitize=safe-stack"
2913 # Check that safe-stack is supported and enabled.
2914 if compile_prog "-Werror $flag" "$flag"; then
2915 # Flag needed both at compilation and at linking
2916 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2917 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
2918 else
2919 error_exit "SafeStack not supported by your compiler"
2920 fi
2921 if test "$coroutine" != "ucontext"; then
2922 error_exit "SafeStack is only supported by the coroutine backend ucontext"
2923 fi
2924else
2925cat > $TMPC << EOF
2926int main(int argc, char *argv[])
2927{
2928#if defined(__has_feature)
2929#if __has_feature(safe_stack)
2930#error SafeStack Enabled
2931#endif
2932#endif
2933 return 0;
2934}
2935EOF
2936if test "$safe_stack" = "no"; then
2937 # Make sure that safe-stack is disabled
2938 if ! compile_prog "-Werror" ""; then
2939 # SafeStack was already enabled, try to explicitly remove the feature
2940 flag="-fno-sanitize=safe-stack"
2941 if ! compile_prog "-Werror $flag" "$flag"; then
2942 error_exit "Configure cannot disable SafeStack"
2943 fi
2944 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2945 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
2946 fi
2947else # "$safe_stack" = ""
2948 # Set safe_stack to yes or no based on pre-existing flags
2949 if compile_prog "-Werror" ""; then
2950 safe_stack="no"
2951 else
2952 safe_stack="yes"
2953 if test "$coroutine" != "ucontext"; then
2954 error_exit "SafeStack is only supported by the coroutine backend ucontext"
2955 fi
2956 fi
2957fi
2958fi
7d992e4d 2959
76a347e1
RH
2960########################################
2961# check if cpuid.h is usable.
2962
76a347e1
RH
2963cat > $TMPC << EOF
2964#include <cpuid.h>
2965int main(void) {
774d566c
PM
2966 unsigned a, b, c, d;
2967 int max = __get_cpuid_max(0, 0);
2968
2969 if (max >= 1) {
2970 __cpuid(1, a, b, c, d);
2971 }
2972
2973 if (max >= 7) {
2974 __cpuid_count(7, 0, a, b, c, d);
2975 }
2976
2977 return 0;
76a347e1
RH
2978}
2979EOF
2980if compile_prog "" "" ; then
2981 cpuid_h=yes
2982fi
2983
5dd89908
RH
2984##########################################
2985# avx2 optimization requirement check
2986#
2987# There is no point enabling this if cpuid.h is not usable,
2988# since we won't be able to select the new routines.
2989
e633a5c6 2990if test "$cpuid_h" = "yes" && test "$avx2_opt" != "no"; then
5dd89908
RH
2991 cat > $TMPC << EOF
2992#pragma GCC push_options
2993#pragma GCC target("avx2")
2994#include <cpuid.h>
2995#include <immintrin.h>
2996static int bar(void *a) {
2997 __m256i x = *(__m256i *)a;
2998 return _mm256_testz_si256(x, x);
2999}
3000int main(int argc, char *argv[]) { return bar(argv[0]); }
3001EOF
5b945f23 3002 if compile_object "-Werror" ; then
5dd89908 3003 avx2_opt="yes"
86583a07
LM
3004 else
3005 avx2_opt="no"
5dd89908
RH
3006 fi
3007fi
3008
6b8cd447
RH
3009##########################################
3010# avx512f optimization requirement check
3011#
3012# There is no point enabling this if cpuid.h is not usable,
3013# since we won't be able to select the new routines.
3014# by default, it is turned off.
3015# if user explicitly want to enable it, check environment
3016
3017if test "$cpuid_h" = "yes" && test "$avx512f_opt" = "yes"; then
3018 cat > $TMPC << EOF
3019#pragma GCC push_options
3020#pragma GCC target("avx512f")
3021#include <cpuid.h>
3022#include <immintrin.h>
3023static int bar(void *a) {
3024 __m512i x = *(__m512i *)a;
3025 return _mm512_test_epi64_mask(x, x);
3026}
3027int main(int argc, char *argv[])
3028{
3029 return bar(argv[0]);
3030}
3031EOF
5b945f23 3032 if ! compile_object "-Werror" ; then
6b8cd447
RH
3033 avx512f_opt="no"
3034 fi
3035else
3036 avx512f_opt="no"
3037fi
3038
f540166b
RH
3039########################################
3040# check if __[u]int128_t is usable.
3041
3042int128=no
3043cat > $TMPC << EOF
3044__int128_t a;
3045__uint128_t b;
3046int main (void) {
3047 a = a + b;
3048 b = a * b;
464e3671 3049 a = a * a;
f540166b
RH
3050 return 0;
3051}
3052EOF
3053if compile_prog "" "" ; then
3054 int128=yes
3055fi
76a347e1 3056
7ebee43e
RH
3057#########################################
3058# See if 128-bit atomic operations are supported.
3059
3060atomic128=no
3061if test "$int128" = "yes"; then
3062 cat > $TMPC << EOF
3063int main(void)
3064{
3065 unsigned __int128 x = 0, y = 0;
bceac547
TH
3066 y = __atomic_load(&x, 0);
3067 __atomic_store(&x, y, 0);
3068 __atomic_compare_exchange(&x, &y, x, 0, 0, 0);
7ebee43e
RH
3069 return 0;
3070}
3071EOF
3072 if compile_prog "" "" ; then
3073 atomic128=yes
3074 fi
3075fi
3076
e6cd4bb5 3077cmpxchg128=no
e633a5c6 3078if test "$int128" = yes && test "$atomic128" = no; then
e6cd4bb5
RH
3079 cat > $TMPC << EOF
3080int main(void)
3081{
3082 unsigned __int128 x = 0, y = 0;
3083 __sync_val_compare_and_swap_16(&x, y, x);
3084 return 0;
3085}
3086EOF
3087 if compile_prog "" "" ; then
3088 cmpxchg128=yes
3089 fi
3090fi
3091
fd0e6053
JS
3092########################################
3093# check if ccache is interfering with
3094# semantic analysis of macros
3095
5e4dfd3d 3096unset CCACHE_CPP2
fd0e6053
JS
3097ccache_cpp2=no
3098cat > $TMPC << EOF
3099static const int Z = 1;
3100#define fn() ({ Z; })
3101#define TAUT(X) ((X) == Z)
3102#define PAREN(X, Y) (X == Y)
3103#define ID(X) (X)
3104int main(int argc, char *argv[])
3105{
3106 int x = 0, y = 0;
3107 x = ID(x);
3108 x = fn();
3109 fn();
3110 if (PAREN(x, y)) return 0;
3111 if (TAUT(Z)) return 0;
3112 return 0;
3113}
3114EOF
3115
3116if ! compile_object "-Werror"; then
3117 ccache_cpp2=yes
3118fi
3119
b553a042
JS
3120#################################################
3121# clang does not support glibc + FORTIFY_SOURCE.
3122
3123if test "$fortify_source" != "no"; then
3124 if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
3125 fortify_source="no";
e189091f 3126 elif test -n "$cxx" && has $cxx &&
cfcc7c14 3127 echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
b553a042
JS
3128 fortify_source="no";
3129 else
3130 fortify_source="yes"
3131 fi
3132fi
3133
a40161cb
PB
3134##########################################
3135# check for usable membarrier system call
3136if test "$membarrier" = "yes"; then
3137 have_membarrier=no
3138 if test "$mingw32" = "yes" ; then
3139 have_membarrier=yes
3140 elif test "$linux" = "yes" ; then
3141 cat > $TMPC << EOF
3142 #include <linux/membarrier.h>
3143 #include <sys/syscall.h>
3144 #include <unistd.h>
3145 #include <stdlib.h>
3146 int main(void) {
3147 syscall(__NR_membarrier, MEMBARRIER_CMD_QUERY, 0);
3148 syscall(__NR_membarrier, MEMBARRIER_CMD_SHARED, 0);
3149 exit(0);
3150 }
3151EOF
3152 if compile_prog "" "" ; then
3153 have_membarrier=yes
3154 fi
3155 fi
3156 if test "$have_membarrier" = "no"; then
3157 feature_not_found "membarrier" "membarrier system call not available"
3158 fi
3159else
3160 # Do not enable it by default even for Mingw32, because it doesn't
3161 # work on Wine.
3162 membarrier=no
3163fi
3164
f0d92b56
LM
3165##########################################
3166# check for usable AF_ALG environment
4f67366e 3167have_afalg=no
f0d92b56
LM
3168cat > $TMPC << EOF
3169#include <errno.h>
3170#include <sys/types.h>
3171#include <sys/socket.h>
3172#include <linux/if_alg.h>
3173int main(void) {
3174 int sock;
3175 sock = socket(AF_ALG, SOCK_SEQPACKET, 0);
3176 return sock;
3177}
3178EOF
3179if compile_prog "" "" ; then
3180 have_afalg=yes
3181fi
3182if test "$crypto_afalg" = "yes"
3183then
3184 if test "$have_afalg" != "yes"
3185 then
3186 error_exit "AF_ALG requested but could not be detected"
3187 fi
3188fi
3189
3190
247724cb
MAL
3191##########################################
3192# checks for sanitizers
3193
247724cb
MAL
3194have_asan=no
3195have_ubsan=no
d83414e1
MAL
3196have_asan_iface_h=no
3197have_asan_iface_fiber=no
247724cb
MAL
3198
3199if test "$sanitizers" = "yes" ; then
b9f44da2 3200 write_c_skeleton
247724cb
MAL
3201 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
3202 have_asan=yes
3203 fi
b9f44da2
MAL
3204
3205 # we could use a simple skeleton for flags checks, but this also
3206 # detect the static linking issue of ubsan, see also:
3207 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
3208 cat > $TMPC << EOF
3209#include <stdlib.h>
3210int main(void) {
3211 void *tmp = malloc(10);
f2dfe54c
LB
3212 if (tmp != NULL) {
3213 return *(int *)(tmp + 2);
3214 }
d1abf3fc 3215 return 1;
b9f44da2
MAL
3216}
3217EOF
247724cb
MAL
3218 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
3219 have_ubsan=yes
3220 fi
d83414e1
MAL
3221
3222 if check_include "sanitizer/asan_interface.h" ; then
3223 have_asan_iface_h=yes
3224 fi
3225
3226 cat > $TMPC << EOF
3227#include <sanitizer/asan_interface.h>
3228int main(void) {
3229 __sanitizer_start_switch_fiber(0, 0, 0);
3230 return 0;
3231}
3232EOF
3233 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
3234 have_asan_iface_fiber=yes
3235 fi
247724cb
MAL
3236fi
3237
0aebab04
LY
3238# Thread sanitizer is, for now, much noisier than the other sanitizers;
3239# keep it separate until that is not the case.
3240if test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
3241 error_exit "TSAN is not supported with other sanitiziers."
3242fi
3243have_tsan=no
3244have_tsan_iface_fiber=no
3245if test "$tsan" = "yes" ; then
3246 write_c_skeleton
3247 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
3248 have_tsan=yes
3249 fi
3250 cat > $TMPC << EOF
3251#include <sanitizer/tsan_interface.h>
3252int main(void) {
3253 __tsan_create_fiber(0);
3254 return 0;
3255}
3256EOF
3257 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
3258 have_tsan_iface_fiber=yes
3259 fi
3260fi
3261
675b9b53
MAL
3262##########################################
3263# check for slirp
3264
3265case "$slirp" in
4d34a86b
PB
3266 auto | enabled | internal)
3267 # Simpler to always update submodule, even if not needed.
2d652f24 3268 git_submodules="${git_submodules} slirp"
675b9b53
MAL
3269 ;;
3270esac
3271
b8e0c493
JD
3272# Check for slirp smbd dupport
3273: ${smbd=${SMBD-/usr/sbin/smbd}}
3274if test "$slirp_smbd" != "no" ; then
3275 if test "$mingw32" = "yes" ; then
3276 if test "$slirp_smbd" = "yes" ; then
3277 error_exit "Host smbd not supported on this platform."
3278 fi
3279 slirp_smbd=no
3280 else
3281 slirp_smbd=yes
3282 fi
3283fi
3284
54e7aac0
AK
3285##########################################
3286# check for usable __NR_keyctl syscall
3287
3288if test "$linux" = "yes" ; then
3289
3290 have_keyring=no
3291 cat > $TMPC << EOF
3292#include <errno.h>
3293#include <asm/unistd.h>
3294#include <linux/keyctl.h>
3295#include <unistd.h>
3296int main(void) {
3297 return syscall(__NR_keyctl, KEYCTL_READ, 0, NULL, NULL, 0);
3298}
3299EOF
3300 if compile_prog "" "" ; then
3301 have_keyring=yes
3302 fi
3303fi
3304if test "$secret_keyring" != "no"
3305then
b418d265 3306 if test "$have_keyring" = "yes"
54e7aac0
AK
3307 then
3308 secret_keyring=yes
3309 else
3310 if test "$secret_keyring" = "yes"
3311 then
3312 error_exit "syscall __NR_keyctl requested, \
3313but not implemented on your system"
3314 else
3315 secret_keyring=no
3316 fi
3317 fi
3318fi
3319
7e24e92a 3320##########################################
e86ecd4b
JQ
3321# End of CC checks
3322# After here, no more $cc or $ld runs
3323
d83414e1
MAL
3324write_c_skeleton
3325
1d728c39 3326if test "$gcov" = "yes" ; then
bf0e56a3 3327 :
b553a042 3328elif test "$fortify_source" = "yes" ; then
086d5f75
PB
3329 QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
3330 debug=no
3331fi
086d5f75
PB
3332
3333case "$ARCH" in
3334alpha)
3335 # Ensure there's only a single GP
3336 QEMU_CFLAGS="-msmall-data $QEMU_CFLAGS"
3337;;
3338esac
3339
3340if test "$gprof" = "yes" ; then
3341 QEMU_CFLAGS="-p $QEMU_CFLAGS"
3342 QEMU_LDFLAGS="-p $QEMU_LDFLAGS"
3343fi
a316e378 3344
247724cb 3345if test "$have_asan" = "yes"; then
db5adeaa
PB
3346 QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
3347 QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
d83414e1
MAL
3348 if test "$have_asan_iface_h" = "no" ; then
3349 echo "ASAN build enabled, but ASAN header missing." \
3350 "Without code annotation, the report may be inferior."
3351 elif test "$have_asan_iface_fiber" = "no" ; then
3352 echo "ASAN build enabled, but ASAN header is too old." \
3353 "Without code annotation, the report may be inferior."
3354 fi
247724cb 3355fi
0aebab04
LY
3356if test "$have_tsan" = "yes" ; then
3357 if test "$have_tsan_iface_fiber" = "yes" ; then
3358 QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
3359 QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
3360 else
3361 error_exit "Cannot enable TSAN due to missing fiber annotation interface."
3362 fi
3363elif test "$tsan" = "yes" ; then
3364 error_exit "Cannot enable TSAN due to missing sanitize thread interface."
3365fi
247724cb 3366if test "$have_ubsan" = "yes"; then
db5adeaa
PB
3367 QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
3368 QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
247724cb
MAL
3369fi
3370
3efac6eb 3371##########################################
3efac6eb 3372
0aebab04
LY
3373# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
3374if test "$solaris" = "no" && test "$tsan" = "no"; then
e86ecd4b 3375 if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
db5adeaa 3376 QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
e86ecd4b
JQ
3377 fi
3378fi
3379
952afb71
BS
3380# Use ASLR, no-SEH and DEP if available
3381if test "$mingw32" = "yes" ; then
cb8baa77
MCA
3382 flags="--no-seh --nxcompat"
3383
3384 # Disable ASLR for debug builds to allow debugging with gdb
3385 if test "$debug" = "no" ; then
3386 flags="--dynamicbase $flags"
3387 fi
3388
3389 for flag in $flags; do
e9a3591f 3390 if ld_has $flag ; then
db5adeaa 3391 QEMU_LDFLAGS="-Wl,$flag $QEMU_LDFLAGS"
952afb71
BS
3392 fi
3393 done
3394fi
3395
9d6bc27b
MR
3396# Probe for guest agent support/options
3397
e8ef31a3 3398if [ "$guest_agent" != "no" ]; then
a5125905
LV
3399 if [ "$softmmu" = no -a "$want_tools" = no ] ; then
3400 guest_agent=no
3401 elif [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" -o "$mingw32" = "yes" ] ; then
e8ef31a3
MT
3402 guest_agent=yes
3403 elif [ "$guest_agent" != yes ]; then
3404 guest_agent=no
3405 else
3406 error_exit "Guest agent is not supported on this platform"
ca35f780 3407 fi
00c705fb 3408fi
ca35f780 3409
b846ab7c 3410# Guest agent Windows MSI package
9d6bc27b 3411
b846ab7c
PB
3412if test "$QEMU_GA_MANUFACTURER" = ""; then
3413 QEMU_GA_MANUFACTURER=QEMU
9d6bc27b 3414fi
b846ab7c
PB
3415if test "$QEMU_GA_DISTRO" = ""; then
3416 QEMU_GA_DISTRO=Linux
9d6bc27b 3417fi
b846ab7c
PB
3418if test "$QEMU_GA_VERSION" = ""; then
3419 QEMU_GA_VERSION=$(cat $source_path/VERSION)
3420fi
3421
3422QEMU_GA_MSI_MINGW_DLL_PATH="$($pkg_config --variable=prefix glib-2.0)/bin"
9d6bc27b 3423
ca35f780
PB
3424# Mac OS X ships with a broken assembler
3425roms=
e633a5c6
EB
3426if { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \
3427 test "$targetos" != "Darwin" && test "$targetos" != "SunOS" && \
7000a12e 3428 test "$targetos" != "Haiku" && test "$softmmu" = yes ; then
e57218b6 3429 # Different host OS linkers have different ideas about the name of the ELF
c65d5e4e
BS
3430 # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
3431 # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
3432 for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
e57218b6
PM
3433 if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
3434 ld_i386_emulation="$emu"
3435 roms="optionrom"
3436 break
3437 fi
3438 done
ca35f780 3439fi
ca35f780 3440
2e33c3f8 3441# Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
a5b2afd5 3442# or -march=z10 (which is the lowest architecture level that Clang supports)
9933c305 3443if test "$cpu" = "s390x" ; then
2e33c3f8 3444 write_c_skeleton
a5b2afd5
TH
3445 compile_prog "-march=z900" ""
3446 has_z900=$?
3af448b3 3447 if [ $has_z900 = 0 ] || compile_object "-march=z10 -msoft-float -Werror"; then
a5b2afd5
TH
3448 if [ $has_z900 != 0 ]; then
3449 echo "WARNING: Your compiler does not support the z900!"
3450 echo " The s390-ccw bios will only work with guest CPUs >= z10."
3451 fi
2e33c3f8 3452 roms="$roms s390-ccw"
1ef6bfc2
PMD
3453 # SLOF is required for building the s390-ccw firmware on s390x,
3454 # since it is using the libnet code from SLOF for network booting.
2d652f24 3455 git_submodules="${git_submodules} roms/SLOF"
2e33c3f8 3456 fi
9933c305
CB
3457fi
3458
11cde1c8
BD
3459# Check that the C++ compiler exists and works with the C compiler.
3460# All the QEMU_CXXFLAGS are based on QEMU_CFLAGS. Keep this at the end to don't miss any other that could be added.
3461if has $cxx; then
3462 cat > $TMPC <<EOF
3463int c_function(void);
3464int main(void) { return c_function(); }
3465EOF
3466
3467 compile_object
3468
3469 cat > $TMPCXX <<EOF
3470extern "C" {
3471 int c_function(void);
3472}
3473int c_function(void) { return 42; }
3474EOF
3475
3476 update_cxxflags
3477
5770e8af 3478 if do_cxx $CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
11cde1c8
BD
3479 # C++ compiler $cxx works ok with C compiler $cc
3480 :
3481 else
3482 echo "C++ compiler $cxx does not work with C compiler $cc"
3483 echo "Disabling C++ specific optional code"
3484 cxx=
3485 fi
3486else
3487 echo "No C++ compiler available; disabling C++ specific optional code"
3488 cxx=
3489fi
3490
7d7dbf9d
DS
3491if !(GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
3492 exit 1
5d91a2ed 3493fi
5d91a2ed 3494
98ec69ac 3495config_host_mak="config-host.mak"
98ec69ac 3496
98ec69ac 3497echo "# Automatically generated by configure - do not modify" > $config_host_mak
98ec69ac 3498echo >> $config_host_mak
98ec69ac 3499
e6c3b0f7 3500echo all: >> $config_host_mak
cc84d63a 3501echo "GIT=$git" >> $config_host_mak
aef45d51 3502echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
7d7dbf9d 3503echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
804edf29 3504
98ec69ac 3505echo "ARCH=$ARCH" >> $config_host_mak
727e5283 3506
f8393946 3507if test "$debug_tcg" = "yes" ; then
2358a494 3508 echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
f8393946 3509fi
1625af87 3510if test "$strip_opt" = "yes" ; then
52ba784d 3511 echo "STRIP=${strip}" >> $config_host_mak
1625af87 3512fi
67b915a5 3513if test "$mingw32" = "yes" ; then
98ec69ac 3514 echo "CONFIG_WIN32=y" >> $config_host_mak
d9840e25
TS
3515 if test "$guest_agent_with_vss" = "yes" ; then
3516 echo "CONFIG_QGA_VSS=y" >> $config_host_mak
f33ca81f 3517 echo "QGA_VSS_PROVIDER=$qga_vss_provider" >> $config_host_mak
d9840e25
TS
3518 echo "WIN_SDK=\"$win_sdk\"" >> $config_host_mak
3519 fi
50cbebb9 3520 if test "$guest_agent_ntddscsi" = "yes" ; then
76dc75ca 3521 echo "CONFIG_QGA_NTDDSCSI=y" >> $config_host_mak
50cbebb9 3522 fi
b846ab7c
PB
3523 echo "QEMU_GA_MSI_MINGW_DLL_PATH=${QEMU_GA_MSI_MINGW_DLL_PATH}" >> $config_host_mak
3524 echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
3525 echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
3526 echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
210fa556 3527else
35f4df27 3528 echo "CONFIG_POSIX=y" >> $config_host_mak
dffcb71c
MM
3529fi
3530
3531if test "$linux" = "yes" ; then
3532 echo "CONFIG_LINUX=y" >> $config_host_mak
67b915a5 3533fi
128ab2ff 3534
83fb7adf 3535if test "$darwin" = "yes" ; then
98ec69ac 3536 echo "CONFIG_DARWIN=y" >> $config_host_mak
83fb7adf 3537fi
b29fe3ed 3538
ec530c81 3539if test "$solaris" = "yes" ; then
98ec69ac 3540 echo "CONFIG_SOLARIS=y" >> $config_host_mak
ec530c81 3541fi
179cf400
AF
3542if test "$haiku" = "yes" ; then
3543 echo "CONFIG_HAIKU=y" >> $config_host_mak
3544fi
97a847bc 3545if test "$static" = "yes" ; then
98ec69ac 3546 echo "CONFIG_STATIC=y" >> $config_host_mak
7d13299d 3547fi
1ba16968 3548if test "$profiler" = "yes" ; then
2358a494 3549 echo "CONFIG_PROFILER=y" >> $config_host_mak
05c2a3e7 3550fi
c932ce31
PB
3551if test "$want_tools" = "yes" ; then
3552 echo "CONFIG_TOOLS=y" >> $config_host_mak
3553fi
f15bff25
PB
3554if test "$guest_agent" = "yes" ; then
3555 echo "CONFIG_GUEST_AGENT=y" >> $config_host_mak
3556fi
b8e0c493
JD
3557if test "$slirp_smbd" = "yes" ; then
3558 echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak
3559 echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
3560fi
015a33bd
GA
3561if test "$l2tpv3" = "yes" ; then
3562 echo "CONFIG_L2TPV3=y" >> $config_host_mak
3563fi
4cc600d2
PB
3564if test "$gprof" = "yes" ; then
3565 echo "CONFIG_GPROF=y" >> $config_host_mak
3566fi
b64ec4e4
FZ
3567echo "CONFIG_BDRV_RW_WHITELIST=$block_drv_rw_whitelist" >> $config_host_mak
3568echo "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
e5f05f8c
KW
3569if test "$block_drv_whitelist_tools" = "yes" ; then
3570 echo "CONFIG_BDRV_WHITELIST_TOOLS=y" >> $config_host_mak
3571fi
dce512de
CH
3572if test "$xfs" = "yes" ; then
3573 echo "CONFIG_XFS=y" >> $config_host_mak
3574fi
89138857 3575qemu_version=$(head $source_path/VERSION)
2358a494 3576echo "PKGVERSION=$pkgversion" >>$config_host_mak
98ec69ac 3577echo "SRC_PATH=$source_path" >> $config_host_mak
2b1f35b9 3578echo "TARGET_DIRS=$target_list" >> $config_host_mak
17969268 3579if test "$modules" = "yes"; then
e26110cf
FZ
3580 # $shacmd can generate a hash started with digit, which the compiler doesn't
3581 # like as an symbol. So prefix it with an underscore
89138857 3582 echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
17969268
FZ
3583 echo "CONFIG_MODULES=y" >> $config_host_mak
3584fi
bd83c861
CE
3585if test "$module_upgrades" = "yes"; then
3586 echo "CONFIG_MODULE_UPGRADES=y" >> $config_host_mak
3587fi
955727d2
CT
3588if test "$have_usbfs" = "yes" ; then
3589 echo "CONFIG_USBFS=y" >> $config_host_mak
3590fi
f876b765
MAL
3591if test "$gio" = "yes" ; then
3592 echo "CONFIG_GIO=y" >> $config_host_mak
3593 echo "GIO_CFLAGS=$gio_cflags" >> $config_host_mak
3594 echo "GIO_LIBS=$gio_libs" >> $config_host_mak
5ecfb76c
PB
3595fi
3596if test "$gdbus_codegen" != "" ; then
25a97a56 3597 echo "GDBUS_CODEGEN=$gdbus_codegen" >> $config_host_mak
f876b765 3598fi
a1c5e949 3599echo "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak
277abf15 3600
1badb709 3601if test "$xen" = "enabled" ; then
6dbd588a 3602 echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
d5b93ddf 3603 echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
582ea95f
MAL
3604 echo "XEN_CFLAGS=$xen_cflags" >> $config_host_mak
3605 echo "XEN_LIBS=$xen_libs" >> $config_host_mak
e37630ca 3606fi
5e9be92d
NB
3607if test "$vhost_scsi" = "yes" ; then
3608 echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
3609fi
af3bba76
PB
3610if test "$vhost_net" = "yes" ; then
3611 echo "CONFIG_VHOST_NET=y" >> $config_host_mak
3612fi
3613if test "$vhost_net_user" = "yes" ; then
56f41de7 3614 echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak
03ce5744 3615fi
108a6481
CL
3616if test "$vhost_net_vdpa" = "yes" ; then
3617 echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak
3618fi
042cea27
GA
3619if test "$vhost_crypto" = "yes" ; then
3620 echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
3621fi
fc0b9b0e
SH
3622if test "$vhost_vsock" = "yes" ; then
3623 echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
5fe97d88
SG
3624 if test "$vhost_user" = "yes" ; then
3625 echo "CONFIG_VHOST_USER_VSOCK=y" >> $config_host_mak
3626 fi
fc0b9b0e 3627fi
299e6f19
PB
3628if test "$vhost_kernel" = "yes" ; then
3629 echo "CONFIG_VHOST_KERNEL=y" >> $config_host_mak
3630fi
e6a74868
MAL
3631if test "$vhost_user" = "yes" ; then
3632 echo "CONFIG_VHOST_USER=y" >> $config_host_mak
3633fi
108a6481
CL
3634if test "$vhost_vdpa" = "yes" ; then
3635 echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
3636fi
98fc1ada
DDAG
3637if test "$vhost_user_fs" = "yes" ; then
3638 echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak
3639fi
a40161cb
PB
3640if test "$membarrier" = "yes" ; then
3641 echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
3642fi
e5b46549
RH
3643if test "$tcg" = "enabled" -a "$tcg_interpreter" = "true" ; then
3644 echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
3645fi
58d3f3ff 3646
da076ffe
GH
3647if test "$opengl" = "yes" ; then
3648 echo "CONFIG_OPENGL=y" >> $config_host_mak
de2d3005 3649 echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
da076ffe 3650 echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
20ff075b
MW
3651fi
3652
99f2dbd3
LL
3653if test "$avx2_opt" = "yes" ; then
3654 echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
3655fi
3656
6b8cd447
RH
3657if test "$avx512f_opt" = "yes" ; then
3658 echo "CONFIG_AVX512F_OPT=y" >> $config_host_mak
3659fi
3660
83fb7adf 3661# XXX: suppress that
7d3505c5 3662if [ "$bsd" = "yes" ] ; then
2358a494 3663 echo "CONFIG_BSD=y" >> $config_host_mak
7d3505c5
FB
3664fi
3665
3556c233
PB
3666if test "$qom_cast_debug" = "yes" ; then
3667 echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak
3668fi
d0e2fce5 3669
7c2acc70 3670echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
70c60c08
SH
3671if test "$coroutine_pool" = "yes" ; then
3672 echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
3673else
3674 echo "CONFIG_COROUTINE_POOL=0" >> $config_host_mak
3675fi
20ff6c80 3676
7d992e4d
PL
3677if test "$debug_stack_usage" = "yes" ; then
3678 echo "CONFIG_DEBUG_STACK_USAGE=y" >> $config_host_mak
3679fi
3680
f0d92b56
LM
3681if test "$crypto_afalg" = "yes" ; then
3682 echo "CONFIG_AF_ALG=y" >> $config_host_mak
3683fi
3684
d83414e1
MAL
3685if test "$have_asan_iface_fiber" = "yes" ; then
3686 echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
3687fi
3688
0aebab04
LY
3689if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
3690 echo "CONFIG_TSAN=y" >> $config_host_mak
3691fi
3692
76a347e1
RH
3693if test "$cpuid_h" = "yes" ; then
3694 echo "CONFIG_CPUID_H=y" >> $config_host_mak
3695fi
3696
f540166b
RH
3697if test "$int128" = "yes" ; then
3698 echo "CONFIG_INT128=y" >> $config_host_mak
3699fi
3700
7ebee43e
RH
3701if test "$atomic128" = "yes" ; then
3702 echo "CONFIG_ATOMIC128=y" >> $config_host_mak
3703fi
3704
e6cd4bb5
RH
3705if test "$cmpxchg128" = "yes" ; then
3706 echo "CONFIG_CMPXCHG128=y" >> $config_host_mak
3707fi
3708
b10d49d7 3709if test "$libssh" = "yes" ; then
484e2cc7 3710 echo "CONFIG_LIBSSH=y" >> $config_host_mak
b10d49d7
PT
3711 echo "LIBSSH_CFLAGS=$libssh_cflags" >> $config_host_mak
3712 echo "LIBSSH_LIBS=$libssh_libs" >> $config_host_mak
0a12ec87
RJ
3713fi
3714
ed1701c6
DDAG
3715if test "$live_block_migration" = "yes" ; then
3716 echo "CONFIG_LIVE_BLOCK_MIGRATION=y" >> $config_host_mak
3717fi
3718
3b8acc11 3719if test "$tpm" = "yes"; then
3cae16db 3720 echo 'CONFIG_TPM=y' >> $config_host_mak
3b8acc11
PB
3721fi
3722
2da776db
MH
3723if test "$rdma" = "yes" ; then
3724 echo "CONFIG_RDMA=y" >> $config_host_mak
392fb643 3725 echo "RDMA_LIBS=$rdma_libs" >> $config_host_mak
2da776db
MH
3726fi
3727
21ab34c9
MA
3728if test "$pvrdma" = "yes" ; then
3729 echo "CONFIG_PVRDMA=y" >> $config_host_mak
3730fi
3731
a6b1d4c0
CX
3732if test "$replication" = "yes" ; then
3733 echo "CONFIG_REPLICATION=y" >> $config_host_mak
3734fi
3735
ba59fb77
PB
3736if test "$debug_mutex" = "yes" ; then
3737 echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak
3738fi
e0580342 3739
2f740136
JC
3740if test "$bochs" = "yes" ; then
3741 echo "CONFIG_BOCHS=y" >> $config_host_mak
3742fi
3743if test "$cloop" = "yes" ; then
3744 echo "CONFIG_CLOOP=y" >> $config_host_mak
3745fi
3746if test "$dmg" = "yes" ; then
3747 echo "CONFIG_DMG=y" >> $config_host_mak
3748fi
3749if test "$qcow1" = "yes" ; then
3750 echo "CONFIG_QCOW1=y" >> $config_host_mak
3751fi
3752if test "$vdi" = "yes" ; then
3753 echo "CONFIG_VDI=y" >> $config_host_mak
3754fi
3755if test "$vvfat" = "yes" ; then
3756 echo "CONFIG_VVFAT=y" >> $config_host_mak
3757fi
3758if test "$qed" = "yes" ; then
3759 echo "CONFIG_QED=y" >> $config_host_mak
3760fi
3761if test "$parallels" = "yes" ; then
3762 echo "CONFIG_PARALLELS=y" >> $config_host_mak
3763fi
2f740136 3764
40e8c6f4
AB
3765if test "$plugins" = "yes" ; then
3766 echo "CONFIG_PLUGIN=y" >> $config_host_mak
26fffe29
EC
3767 # Copy the export object list to the build dir
3768 if test "$ld_dynamic_list" = "yes" ; then
3769 echo "CONFIG_HAS_LD_DYNAMIC_LIST=yes" >> $config_host_mak
3770 ld_symbols=qemu-plugins-ld.symbols
3771 cp "$source_path/plugins/qemu-plugins.symbols" $ld_symbols
3772 elif test "$ld_exported_symbols_list" = "yes" ; then
3773 echo "CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST=yes" >> $config_host_mak
3774 ld64_symbols=qemu-plugins-ld64.symbols
3775 echo "# Automatically generated by configure - do not modify" > $ld64_symbols
3776 grep 'qemu_' "$source_path/plugins/qemu-plugins.symbols" | sed 's/;//g' | \
3777 sed -E 's/^[[:space:]]*(.*)/_\1/' >> $ld64_symbols
3778 else
3779 error_exit \
3780 "If \$plugins=yes, either \$ld_dynamic_list or " \
3781 "\$ld_exported_symbols_list should have been set to 'yes'."
3782 fi
40e8c6f4
AB
3783fi
3784
b1863ccc
AB
3785if test -n "$gdb_bin"; then
3786 gdb_version=$($gdb_bin --version | head -n 1)
d6a66c81 3787 if version_ge ${gdb_version##* } 9.1; then
b1863ccc
AB
3788 echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
3789 fi
f48e590a
AB
3790fi
3791
54e7aac0
AK
3792if test "$secret_keyring" = "yes" ; then
3793 echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak
3794fi
3795
98ec69ac 3796echo "ROMS=$roms" >> $config_host_mak
804edf29 3797echo "MAKE=$make" >> $config_host_mak
c886edfb 3798echo "PYTHON=$python" >> $config_host_mak
39d87c8c 3799echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
a5665051 3800echo "MESON=$meson" >> $config_host_mak
09e93326 3801echo "NINJA=$ninja" >> $config_host_mak
804edf29 3802echo "CC=$cc" >> $config_host_mak
433de74c 3803echo "HOST_CC=$host_cc" >> $config_host_mak
a31a8642 3804if $iasl -h > /dev/null 2>&1; then
859aef02 3805 echo "CONFIG_IASL=$iasl" >> $config_host_mak
a31a8642 3806fi
804edf29 3807echo "AR=$ar" >> $config_host_mak
cdbd727c 3808echo "AS=$as" >> $config_host_mak
5f6f0e27 3809echo "CCAS=$ccas" >> $config_host_mak
3dd46c78 3810echo "CPP=$cpp" >> $config_host_mak
804edf29
JQ
3811echo "OBJCOPY=$objcopy" >> $config_host_mak
3812echo "LD=$ld" >> $config_host_mak
46eef33b 3813echo "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
a558ee17 3814echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
11cde1c8 3815echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
a81df1b6
PB
3816echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
3817echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
8a99e9a3 3818echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
e57218b6 3819echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
804edf29 3820echo "EXESUF=$EXESUF" >> $config_host_mak
f15bff25 3821echo "LIBS_QGA=$libs_qga" >> $config_host_mak
804edf29 3822
b767d257
MMG
3823if test "$rng_none" = "yes"; then
3824 echo "CONFIG_RNG_NONE=y" >> $config_host_mak
3825fi
3826
6efd7517
PM
3827# use included Linux headers
3828if test "$linux" = "yes" ; then
a307beb6 3829 mkdir -p linux-headers
6efd7517 3830 case "$cpu" in
c72b26ec 3831 i386|x86_64|x32)
08312a63 3832 linux_arch=x86
6efd7517 3833 ;;
f8378acc 3834 ppc|ppc64|ppc64le)
08312a63 3835 linux_arch=powerpc
6efd7517
PM
3836 ;;
3837 s390x)
08312a63
PM
3838 linux_arch=s390
3839 ;;
1f080313
CF
3840 aarch64)
3841 linux_arch=arm64
3842 ;;
222e7d11
SL
3843 mips64)
3844 linux_arch=mips
3845 ;;
08312a63
PM
3846 *)
3847 # For most CPUs the kernel architecture name and QEMU CPU name match.
3848 linux_arch="$cpu"
6efd7517
PM
3849 ;;
3850 esac
08312a63
PM
3851 # For non-KVM architectures we will not have asm headers
3852 if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
3853 symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
3854 fi
6efd7517
PM
3855fi
3856
1d14ffa9 3857for target in $target_list; do
fdb75aef
PB
3858 target_dir="$target"
3859 target_name=$(echo $target | cut -d '-' -f 1)
3860 mkdir -p $target_dir
3861 case $target in
3862 *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
3863 *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
3864 esac
3865done
7d13299d 3866
765686d6 3867echo "CONFIG_QEMU_INTERP_PREFIX=$interp_prefix" | sed 's/%M/@0@/' >> $config_host_mak
fdb75aef
PB
3868if test "$default_targets" = "yes"; then
3869 echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
3870fi
a540f158 3871
a99d57bb
WG
3872if test "$numa" = "yes"; then
3873 echo "CONFIG_NUMA=y" >> $config_host_mak
ab318051 3874 echo "NUMA_LIBS=$numa_libs" >> $config_host_mak
a99d57bb
WG
3875fi
3876
fd0e6053
JS
3877if test "$ccache_cpp2" = "yes"; then
3878 echo "export CCACHE_CPP2=y" >> $config_host_mak
3879fi
3880
1e4f6065
DB
3881if test "$safe_stack" = "yes"; then
3882 echo "CONFIG_SAFESTACK=y" >> $config_host_mak
3883fi
3884
e29e5c6e
PM
3885# If we're using a separate build tree, set it up now.
3886# DIRS are directories which we simply mkdir in the build tree;
3887# LINKS are things to symlink back into the source tree
3888# (these can be both files and directories).
3889# Caution: do not add files or directories here using wildcards. This
3890# will result in problems later if a new file matching the wildcard is
3891# added to the source tree -- nothing will cause configure to be rerun
3892# so the build tree will be missing the link back to the new file, and
3893# tests might fail. Prefer to keep the relevant files in their own
3894# directory and symlink the directory instead.
09db9b9d
GH
3895# UNLINK is used to remove symlinks from older development versions
3896# that might get into the way when doing "git update" without doing
3897# a "make distclean" in between.
9d49bcf6 3898DIRS="tests tests/tcg tests/qapi-schema tests/qtest/libqos"
1cf4323e 3899DIRS="$DIRS tests/qtest tests/qemu-iotests tests/vm tests/fp tests/qgraph"
b855f8d1 3900DIRS="$DIRS docs docs/interop fsdev scsi"
744a928c 3901DIRS="$DIRS pc-bios/optionrom pc-bios/s390-ccw"
8db2a4fd 3902DIRS="$DIRS roms/seabios"
c17a386b 3903DIRS="$DIRS contrib/plugins/"
2038f8c8 3904LINKS="Makefile"
3941996b 3905LINKS="$LINKS tests/tcg/Makefile.target"
ddcf607f 3906LINKS="$LINKS pc-bios/optionrom/Makefile"
e29e5c6e 3907LINKS="$LINKS pc-bios/s390-ccw/Makefile"
8db2a4fd 3908LINKS="$LINKS roms/seabios/Makefile"
e29e5c6e
PM
3909LINKS="$LINKS pc-bios/qemu-icon.bmp"
3910LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
39950353
PM
3911LINKS="$LINKS tests/acceptance tests/data"
3912LINKS="$LINKS tests/qemu-iotests/check"
8f8fd9ed 3913LINKS="$LINKS python"
c17a386b 3914LINKS="$LINKS contrib/plugins/Makefile "
09db9b9d 3915UNLINK="pc-bios/keymaps"
753d11f2
RH
3916for bios_file in \
3917 $source_path/pc-bios/*.bin \
3a631b8e 3918 $source_path/pc-bios/*.elf \
225a9ab8 3919 $source_path/pc-bios/*.lid \
753d11f2
RH
3920 $source_path/pc-bios/*.rom \
3921 $source_path/pc-bios/*.dtb \
e89e33e1 3922 $source_path/pc-bios/*.img \
753d11f2 3923 $source_path/pc-bios/openbios-* \
4e73c781 3924 $source_path/pc-bios/u-boot.* \
26ce90fd 3925 $source_path/pc-bios/edk2-*.fd.bz2 \
cd946e5c
JA
3926 $source_path/pc-bios/palcode-* \
3927 $source_path/pc-bios/qemu_vga.ndrv
3928
753d11f2 3929do
e29e5c6e 3930 LINKS="$LINKS pc-bios/$(basename $bios_file)"
d1807a4f
PB
3931done
3932mkdir -p $DIRS
e29e5c6e 3933for f in $LINKS ; do
0f4d8894 3934 if [ -e "$source_path/$f" ]; then
f9245e10
PM
3935 symlink "$source_path/$f" "$f"
3936 fi
d1807a4f 3937done
09db9b9d
GH
3938for f in $UNLINK ; do
3939 if [ -L "$f" ]; then
3940 rm -f "$f"
3941 fi
3942done
1ad2134f 3943
2038f8c8
PB
3944(for i in $cross_cc_vars; do
3945 export $i
3946done
de6d7e6b 3947export target_list source_path use_containers ARCH
2038f8c8
PB
3948$source_path/tests/tcg/configure.sh)
3949
c34ebfdc 3950# temporary config to build submodules
8db2a4fd 3951for rom in seabios; do
c34ebfdc 3952 config_mak=roms/$rom/config.mak
37116c89 3953 echo "# Automatically generated by configure - do not modify" > $config_mak
c34ebfdc 3954 echo "SRC_PATH=$source_path/roms/$rom" >> $config_mak
cdbd727c 3955 echo "AS=$as" >> $config_mak
5f6f0e27 3956 echo "CCAS=$ccas" >> $config_mak
c34ebfdc
AL
3957 echo "CC=$cc" >> $config_mak
3958 echo "BCC=bcc" >> $config_mak
3dd46c78 3959 echo "CPP=$cpp" >> $config_mak
c34ebfdc 3960 echo "OBJCOPY=objcopy" >> $config_mak
a31a8642 3961 echo "IASL=$iasl" >> $config_mak
c34ebfdc 3962 echo "LD=$ld" >> $config_mak
9f81aeb5 3963 echo "RANLIB=$ranlib" >> $config_mak
c34ebfdc
AL
3964done
3965
a5665051 3966if test "$skip_meson" = no; then
d77e90fa
PB
3967 cross="config-meson.cross.new"
3968 meson_quote() {
47b30835 3969 echo "'$(echo $* | sed "s/ /','/g")'"
d77e90fa
PB
3970 }
3971
3972 echo "# Automatically generated by configure - do not modify" > $cross
3973 echo "[properties]" >> $cross
d1d5e9ee
AB
3974
3975 # unroll any custom device configs
11bdcfcd
AB
3976 for a in $device_archs; do
3977 eval "c=\$devices_${a}"
3978 echo "${a}-softmmu = '$c'" >> $cross
3979 done
d1d5e9ee 3980
d77e90fa
PB
3981 test -z "$cxx" && echo "link_language = 'c'" >> $cross
3982 echo "[built-in options]" >> $cross
3983 echo "c_args = [${CFLAGS:+$(meson_quote $CFLAGS)}]" >> $cross
3984 echo "cpp_args = [${CXXFLAGS:+$(meson_quote $CXXFLAGS)}]" >> $cross
3985 echo "c_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross
3986 echo "cpp_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross
3987 echo "[binaries]" >> $cross
4dba2789
PB
3988 echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
3989 test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
3990 test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
d77e90fa
PB
3991 echo "ar = [$(meson_quote $ar)]" >> $cross
3992 echo "nm = [$(meson_quote $nm)]" >> $cross
3993 echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
3994 echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
3995 if has $sdl2_config; then
3996 echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
3997 fi
3998 echo "strip = [$(meson_quote $strip)]" >> $cross
3999 echo "windres = [$(meson_quote $windres)]" >> $cross
4000 if test "$cross_compile" = "yes"; then
fc929892 4001 cross_arg="--cross-file config-meson.cross"
fc929892
MAL
4002 echo "[host_machine]" >> $cross
4003 if test "$mingw32" = "yes" ; then
4004 echo "system = 'windows'" >> $cross
fc929892 4005 fi
853b4baf
TH
4006 if test "$linux" = "yes" ; then
4007 echo "system = 'linux'" >> $cross
4008 fi
0ca321ea
JD
4009 if test "$darwin" = "yes" ; then
4010 echo "system = 'darwin'" >> $cross
4011 fi
fc929892 4012 case "$ARCH" in
f6bca9df 4013 i386)
fc929892
MAL
4014 echo "cpu_family = 'x86'" >> $cross
4015 ;;
f8bb7e1c 4016 x86_64|x32)
f6bca9df
JD
4017 echo "cpu_family = 'x86_64'" >> $cross
4018 ;;
fc929892
MAL
4019 ppc64le)
4020 echo "cpu_family = 'ppc64'" >> $cross
4021 ;;
4022 *)
4023 echo "cpu_family = '$ARCH'" >> $cross
4024 ;;
4025 esac
4026 echo "cpu = '$cpu'" >> $cross
4027 if test "$bigendian" = "yes" ; then
4028 echo "endian = 'big'" >> $cross
4029 else
4030 echo "endian = 'little'" >> $cross
4031 fi
d77e90fa 4032 else
fc929892 4033 cross_arg="--native-file config-meson.cross"
d77e90fa
PB
4034 fi
4035 mv $cross config-meson.cross
fc929892 4036
d77e90fa 4037 rm -rf meson-private meson-info meson-logs
61d63097
PB
4038 run_meson() {
4039 NINJA=$ninja $meson setup \
d17f305a
PB
4040 --prefix "$prefix" \
4041 --libdir "$libdir" \
4042 --libexecdir "$libexecdir" \
4043 --bindir "$bindir" \
4044 --includedir "$includedir" \
4045 --datadir "$datadir" \
4046 --mandir "$mandir" \
4047 --sysconfdir "$sysconfdir" \
16bf7a33 4048 --localedir "$localedir" \
d17f305a 4049 --localstatedir "$local_statedir" \
3b4da132
PB
4050 -Daudio_drv_list=$audio_drv_list \
4051 -Ddefault_devices=$default_devices \
d17f305a 4052 -Ddocdir="$docdir" \
16bf7a33 4053 -Dqemu_firmwarepath="$firmwarepath" \
73f3aa37 4054 -Dqemu_suffix="$qemu_suffix" \
3b4da132
PB
4055 -Dsphinx_build="$sphinx_build" \
4056 -Dtrace_file="$trace_file" \
a5665051
PB
4057 -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) \
4058 -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo false; fi) \
4059 -Dwerror=$(if test "$werror" = yes; then echo true; else echo false; fi) \
4060 -Dstrip=$(if test "$strip_opt" = yes; then echo true; else echo false; fi) \
da6d48b9 4061 -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \
bf0e56a3 4062 -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
3b4da132
PB
4063 -Db_lto=$lto -Dcfi=$cfi -Dtcg=$tcg -Dxen=$xen \
4064 -Dcapstone=$capstone -Dfdt=$fdt -Dslirp=$slirp \
537b7248 4065 $(test -n "${LIB_FUZZING_ENGINE+xxx}" && echo "-Dfuzzing_engine=$LIB_FUZZING_ENGINE") \
332008e0 4066 $(if test "$default_feature" = no; then echo "-Dauto_features=disabled"; fi) \
61d63097
PB
4067 "$@" $cross_arg "$PWD" "$source_path"
4068 }
4069 eval run_meson $meson_options
d77e90fa
PB
4070 if test "$?" -ne 0 ; then
4071 error_exit "meson setup failed"
4072 fi
699d3884
PB
4073else
4074 if test -f meson-private/cmd_line.txt; then
4075 # Adjust old command line options whose type was changed
4076 # Avoids having to use "setup --wipe" when Meson is upgraded
4077 perl -i -ne '
4078 s/^gettext = true$/gettext = auto/;
4079 s/^gettext = false$/gettext = disabled/;
654d6b04 4080 /^b_staticpic/ && next;
699d3884
PB
4081 print;' meson-private/cmd_line.txt
4082 fi
a5665051
PB
4083fi
4084
2d838d9b
AB
4085if test -n "${deprecated_features}"; then
4086 echo "Warning, deprecated features enabled."
a476b216 4087 echo "Please see docs/about/deprecated.rst"
2d838d9b
AB
4088 echo " features: ${deprecated_features}"
4089fi
4090
e0447a83
TH
4091# Create list of config switches that should be poisoned in common code...
4092# but filter out CONFIG_TCG and CONFIG_USER_ONLY which are special.
54b0306e
TH
4093target_configs_h=$(ls *-config-devices.h *-config-target.h 2>/dev/null)
4094if test -n "$target_configs_h" ; then
4095 sed -n -e '/CONFIG_TCG/d' -e '/CONFIG_USER_ONLY/d' \
4096 -e '/^#define / { s///; s/ .*//; s/^/#pragma GCC poison /p; }' \
4097 $target_configs_h | sort -u > config-poison.h
4098else
4099 :> config-poison.h
4100fi
e0447a83 4101
dc655404
MT
4102# Save the configure command line for later reuse.
4103cat <<EOD >config.status
4104#!/bin/sh
4105# Generated by configure.
4106# Run this file to recreate the current configuration.
4107# Compiler output produced by configure, useful for debugging
4108# configure, is in config.log if it exists.
4109EOD
e811da7f
DB
4110
4111preserve_env() {
4112 envname=$1
4113
4114 eval envval=\$$envname
4115
4116 if test -n "$envval"
4117 then
4118 echo "$envname='$envval'" >> config.status
4119 echo "export $envname" >> config.status
4120 else
4121 echo "unset $envname" >> config.status
4122 fi
4123}
4124
4125# Preserve various env variables that influence what
4126# features/build target configure will detect
4127preserve_env AR
4128preserve_env AS
4129preserve_env CC
4130preserve_env CPP
4131preserve_env CXX
4132preserve_env INSTALL
4133preserve_env LD
4134preserve_env LD_LIBRARY_PATH
4135preserve_env LIBTOOL
4136preserve_env MAKE
4137preserve_env NM
4138preserve_env OBJCOPY
4139preserve_env PATH
4140preserve_env PKG_CONFIG
4141preserve_env PKG_CONFIG_LIBDIR
4142preserve_env PKG_CONFIG_PATH
4143preserve_env PYTHON
e811da7f
DB
4144preserve_env SDL2_CONFIG
4145preserve_env SMBD
4146preserve_env STRIP
4147preserve_env WINDRES
4148
dc655404 4149printf "exec" >>config.status
a5665051 4150for i in "$0" "$@"; do
835af899 4151 test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
a5665051 4152done
cf7cc929 4153echo ' "$@"' >>config.status
dc655404
MT
4154chmod +x config.status
4155
8cd05ab6 4156rm -r "$TMPDIR1"