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