]> git.proxmox.com Git - mirror_qemu.git/blame - configure
9p: darwin: Handle struct dirent differences
[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"
7d13299d 81
da1d85e3 82rm -f config.log
9ac81bbb 83
b48e3611
PM
84# Print a helpful header at the top of config.log
85echo "# QEMU configure log $(date)" >> config.log
979ae168
PM
86printf "# Configured with:" >> config.log
87printf " '%s'" "$0" "$@" >> config.log
88echo >> config.log
b48e3611
PM
89echo "#" >> config.log
90
835af899
PB
91quote_sh() {
92 printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
93}
94
d880a3ba
PB
95print_error() {
96 (echo
76ad07a4
PM
97 echo "ERROR: $1"
98 while test -n "$2"; do
99 echo " $2"
100 shift
101 done
d880a3ba
PB
102 echo) >&2
103}
104
105error_exit() {
106 print_error "$@"
76ad07a4
PM
107 exit 1
108}
109
9c83ffd8
PM
110do_compiler() {
111 # Run the compiler, capturing its output to the log. First argument
112 # is compiler binary to execute.
630d86b7 113 compiler="$1"
9c83ffd8 114 shift
8bbe05d7
IJ
115 if test -n "$BASH_VERSION"; then eval '
116 echo >>config.log "
117funcs: ${FUNCNAME[*]}
118lines: ${BASH_LINENO[*]}"
119 '; fi
9c83ffd8
PM
120 echo $compiler "$@" >> config.log
121 $compiler "$@" >> config.log 2>&1 || return $?
8dc38a78
PM
122 # Test passed. If this is an --enable-werror build, rerun
123 # the test with -Werror and bail out if it fails. This
124 # makes warning-generating-errors in configure test code
125 # obvious to developers.
126 if test "$werror" != "yes"; then
127 return 0
128 fi
129 # Don't bother rerunning the compile if we were already using -Werror
130 case "$*" in
131 *-Werror*)
132 return 0
133 ;;
134 esac
9c83ffd8
PM
135 echo $compiler -Werror "$@" >> config.log
136 $compiler -Werror "$@" >> config.log 2>&1 && return $?
76ad07a4
PM
137 error_exit "configure test passed without -Werror but failed with -Werror." \
138 "This is probably a bug in the configure script. The failing command" \
139 "will be at the bottom of config.log." \
140 "You can run configure with --disable-werror to bypass this check."
8dc38a78
PM
141}
142
9c83ffd8 143do_cc() {
4dba2789 144 do_compiler "$cc" $CPU_CFLAGS "$@"
9c83ffd8
PM
145}
146
147do_cxx() {
4dba2789 148 do_compiler "$cxx" $CPU_CFLAGS "$@"
9c83ffd8
PM
149}
150
00849b92
RH
151# Append $2 to the variable named $1, with space separation
152add_to() {
153 eval $1=\${$1:+\"\$$1 \"}\$2
154}
155
9c83ffd8
PM
156update_cxxflags() {
157 # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
158 # options which some versions of GCC's C++ compiler complain about
159 # because they only make sense for C programs.
de38c0cc 160 QEMU_CXXFLAGS="-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
8a9d3d56 161 CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
9c83ffd8
PM
162 for arg in $QEMU_CFLAGS; do
163 case $arg in
164 -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
165 -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
166 ;;
167 *)
168 QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
169 ;;
170 esac
171 done
172}
173
52166aa0 174compile_object() {
fd0e6053 175 local_cflags="$1"
a2866660 176 do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
52166aa0
JQ
177}
178
179compile_prog() {
180 local_cflags="$1"
181 local_ldflags="$2"
a2866660
PB
182 do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
183 $LDFLAGS $EXTRA_LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
52166aa0
JQ
184}
185
11568d6d
PB
186# symbolically link $1 to $2. Portable version of "ln -sf".
187symlink() {
72b8b5a1 188 rm -rf "$2"
ec5b06d7 189 mkdir -p "$(dirname "$2")"
72b8b5a1 190 ln -s "$1" "$2"
11568d6d
PB
191}
192
0dba6195
LM
193# check whether a command is available to this shell (may be either an
194# executable or a builtin)
195has() {
196 type "$1" >/dev/null 2>&1
197}
198
0a01d76f 199version_ge () {
2df52b9b
AB
200 local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
201 local_ver2=$(echo "$2" | tr . ' ')
0a01d76f
MAL
202 while true; do
203 set x $local_ver1
204 local_first=${2-0}
c44a33e2
SG
205 # 'shift 2' if $2 is set, or 'shift' if $2 is not set
206 shift ${2:+2}
0a01d76f
MAL
207 local_ver1=$*
208 set x $local_ver2
209 # the second argument finished, the first must be greater or equal
210 test $# = 1 && return 0
211 test $local_first -lt $2 && return 1
212 test $local_first -gt $2 && return 0
c44a33e2 213 shift ${2:+2}
0a01d76f
MAL
214 local_ver2=$*
215 done
216}
217
3b6b7550
PB
218glob() {
219 eval test -z '"${1#'"$2"'}"'
220}
221
e9a3591f
CB
222ld_has() {
223 $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
224}
225
4ace32e2
AO
226if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
227then
228 error_exit "main directory cannot contain spaces nor colons"
229fi
230
14211825 231# default parameters
2ff6b91e 232cpu=""
a31a8642 233iasl="iasl"
1e43adfc 234interp_prefix="/usr/gnemul/qemu-%M"
43ce4dfe 235static="no"
3812c0c4 236cross_compile="no"
7d13299d 237cross_prefix=""
87430d5b 238audio_drv_list="default"
b64ec4e4
FZ
239block_drv_rw_whitelist=""
240block_drv_ro_whitelist=""
e49d021e 241host_cc="cc"
5bc62e01 242debug_info="yes"
cdad781d 243lto="false"
63678e17 244stack_protector=""
1e4f6065 245safe_stack=""
afc3a8f9 246use_containers="yes"
f2385398 247gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
ac0df51d 248
92712822
DB
249if test -e "$source_path/.git"
250then
7d7dbf9d 251 git_submodules_action="update"
92712822 252else
7d7dbf9d 253 git_submodules_action="ignore"
92712822 254fi
2d652f24
PB
255
256git_submodules="ui/keycodemapdb"
cc84d63a 257git="git"
ac0df51d 258
afb63ebd
SW
259# Don't accept a target_list environment variable.
260unset target_list
447e133f 261unset target_list_exclude
377529c0
PB
262
263# Default value for a variable defining feature "foo".
264# * foo="no" feature will only be used if --enable-foo arg is given
265# * foo="" feature will be searched for, and if found, will be used
266# unless --disable-foo is given
267# * foo="yes" this value will only be set by --enable-foo flag.
268# feature will searched for,
269# if not found, configure exits with error
270#
271# Always add --enable-foo and --disable-foo command line args.
272# Distributions want to ensure that several features are compiled in, and it
273# is impossible without a --enable-foo that exits if a feature is not found.
274
c87ea116
AB
275default_feature=""
276# parse CC options second
277for opt do
278 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
279 case "$opt" in
280 --without-default-features)
281 default_feature="no"
282 ;;
283 esac
284done
285
a2866660
PB
286EXTRA_CFLAGS=""
287EXTRA_CXXFLAGS=""
288EXTRA_LDFLAGS=""
289
c87ea116 290xen_ctrl_version="$default_feature"
0848f8ac 291vhost_kernel="$default_feature"
c87ea116
AB
292vhost_net="$default_feature"
293vhost_crypto="$default_feature"
294vhost_scsi="$default_feature"
295vhost_vsock="$default_feature"
d88618f7 296vhost_user="no"
c87ea116 297vhost_user_fs="$default_feature"
0848f8ac 298vhost_vdpa="$default_feature"
c87ea116
AB
299rdma="$default_feature"
300pvrdma="$default_feature"
377529c0 301debug_tcg="no"
377529c0 302debug="no"
247724cb 303sanitizers="no"
0aebab04 304tsan="no"
c87ea116 305fortify_source="$default_feature"
1d728c39 306gcov="no"
c7328271 307EXESUF=""
17969268 308modules="no"
bd83c861 309module_upgrades="no"
377529c0 310prefix="/usr/local"
10ff82d1 311qemu_suffix="qemu"
377529c0 312softmmu="yes"
b915a2f1
PB
313linux_user=""
314bsd_user=""
377529c0 315pkgversion=""
40d6444e 316pie=""
baf86d6b 317trace_backends="log"
377529c0 318trace_file="trace"
c87ea116 319opengl="$default_feature"
519175a2 320coroutine=""
a1c5e949 321tls_priority="NORMAL"
ba4dd2aa 322plugins="$default_feature"
c87ea116 323secret_keyring="$default_feature"
a5665051 324meson=""
3b4da132 325meson_args=""
48328880 326ninja=""
3b4da132 327gio="$default_feature"
a5665051 328skip_meson=no
377529c0 329
3b4da132
PB
330# The following Meson options are handled manually (still they
331# are included in the automatically generated help message)
332
333# 1. Track which submodules are needed
0577e84d
TH
334if test "$default_feature" = no ; then
335 capstone="disabled"
336 slirp="disabled"
337else
338 capstone="auto"
339 slirp="auto"
340fi
3b4da132 341fdt="auto"
3b4da132
PB
342
343# 2. Support --with/--without option
344default_devices="true"
345
346# 3. Automatically enable/disable other options
347tcg="enabled"
348cfi="false"
349
350# 4. Detection partly done in configure
351xen=${default_feature:+disabled}
898be3e0 352
c87ea116 353# parse CC options second
ac0df51d 354for opt do
89138857 355 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
ac0df51d
AL
356 case "$opt" in
357 --cross-prefix=*) cross_prefix="$optarg"
3812c0c4 358 cross_compile="yes"
ac0df51d 359 ;;
3d8df640 360 --cc=*) CC="$optarg"
ac0df51d 361 ;;
83f73fce
TS
362 --cxx=*) CXX="$optarg"
363 ;;
2ff6b91e
JQ
364 --cpu=*) cpu="$optarg"
365 ;;
a2866660
PB
366 --extra-cflags=*)
367 EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
368 EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
369 ;;
370 --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
11cde1c8 371 ;;
a2866660 372 --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
e2a2ed06 373 ;;
5bc62e01
GH
374 --enable-debug-info) debug_info="yes"
375 ;;
376 --disable-debug-info) debug_info="no"
377 ;;
d75402b5
AB
378 --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
379 ;;
479ca4cc 380 --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
d422b2bc 381 eval "cross_cc_cflags_${cc_arch}=\$optarg"
2038f8c8 382 cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
d422b2bc 383 ;;
d75402b5 384 --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
2038f8c8 385 cc_archs="$cc_archs $cc_arch"
d75402b5 386 eval "cross_cc_${cc_arch}=\$optarg"
2038f8c8 387 cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
d75402b5 388 ;;
ac0df51d
AL
389 esac
390done
ac0df51d
AL
391# OS specific
392# Using uname is really, really broken. Once we have the right set of checks
93148aa5 393# we can eliminate its usage altogether.
ac0df51d 394
e49d021e
PM
395# Preferred compiler:
396# ${CC} (if set)
397# ${cross_prefix}gcc (if cross-prefix specified)
398# system compiler
399if test -z "${CC}${cross_prefix}"; then
400 cc="$host_cc"
401else
402 cc="${CC-${cross_prefix}gcc}"
403fi
404
83f73fce
TS
405if test -z "${CXX}${cross_prefix}"; then
406 cxx="c++"
407else
408 cxx="${CXX-${cross_prefix}g++}"
409fi
410
b3198cc2 411ar="${AR-${cross_prefix}ar}"
cdbd727c 412as="${AS-${cross_prefix}as}"
5f6f0e27 413ccas="${CCAS-$cc}"
3dd46c78 414cpp="${CPP-$cc -E}"
b3198cc2
SY
415objcopy="${OBJCOPY-${cross_prefix}objcopy}"
416ld="${LD-${cross_prefix}ld}"
9f81aeb5 417ranlib="${RANLIB-${cross_prefix}ranlib}"
4852ee95 418nm="${NM-${cross_prefix}nm}"
35acbb30 419smbd="$SMBD"
b3198cc2
SY
420strip="${STRIP-${cross_prefix}strip}"
421windres="${WINDRES-${cross_prefix}windres}"
17884d7b
ST
422pkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
423query_pkg_config() {
424 "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
425}
426pkg_config=query_pkg_config
47c03744 427sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
ac0df51d 428
be17dc90 429# default flags for all hosts
2d31515b
PM
430# We use -fwrapv to tell the compiler that we require a C dialect where
431# left shift of signed integers is well defined and has the expected
432# 2s-complement style results. (Both clang and gcc agree that it
433# provides these semantics.)
de38c0cc 434QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
086d5f75 435QEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
c95e3080 436QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
be17dc90 437QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
5770e8af 438
de38c0cc
PB
439QEMU_LDFLAGS=
440
5770e8af 441# Flags that are needed during configure but later taken care of by Meson
8a9d3d56 442CONFIGURE_CFLAGS="-std=gnu11 -Wall"
5770e8af 443CONFIGURE_LDFLAGS=
086d5f75 444
be17dc90 445
ac0df51d
AL
446check_define() {
447cat > $TMPC <<EOF
448#if !defined($1)
fd786e1a 449#error $1 not defined
ac0df51d
AL
450#endif
451int main(void) { return 0; }
452EOF
52166aa0 453 compile_object
ac0df51d
AL
454}
455
307119e7
GH
456check_include() {
457cat > $TMPC <<EOF
458#include <$1>
459int main(void) { return 0; }
460EOF
461 compile_object
462}
463
93b25869
JS
464write_c_skeleton() {
465 cat > $TMPC <<EOF
466int main(void) { return 0; }
467EOF
468}
469
bbea4050 470if check_define __linux__ ; then
ba7c60c2 471 targetos=linux
bbea4050 472elif check_define _WIN32 ; then
ba7c60c2 473 targetos=windows
bbea4050 474elif check_define __OpenBSD__ ; then
ba7c60c2 475 targetos=openbsd
bbea4050 476elif check_define __sun__ ; then
ba7c60c2 477 targetos=sunos
bbea4050 478elif check_define __HAIKU__ ; then
ba7c60c2 479 targetos=haiku
951fedfc 480elif check_define __FreeBSD__ ; then
ba7c60c2 481 targetos=freebsd
951fedfc 482elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
ba7c60c2 483 targetos=gnu/kfreebsd
951fedfc 484elif check_define __DragonFly__ ; then
ba7c60c2 485 targetos=dragonfly
951fedfc 486elif check_define __NetBSD__; then
ba7c60c2 487 targetos=netbsd
951fedfc 488elif check_define __APPLE__; then
ba7c60c2 489 targetos=darwin
bbea4050 490else
951fedfc
PM
491 # This is a fatal error, but don't report it yet, because we
492 # might be going to just print the --help text, or it might
493 # be the result of a missing compiler.
ba7c60c2 494 targetos=bogus
bbea4050
PM
495fi
496
65eff01b
PB
497# OS specific
498
3b0d8643
PB
499mingw32="no"
500bsd="no"
501linux="no"
502solaris="no"
bbea4050 503case $targetos in
65eff01b
PB
504windows)
505 mingw32="yes"
506 plugins="no"
507 pie="no"
508;;
509gnu/kfreebsd)
510 bsd="yes"
511;;
512freebsd)
513 bsd="yes"
65eff01b
PB
514 make="${MAKE-gmake}"
515 # needed for kinfo_getvmmap(3) in libutil.h
516;;
517dragonfly)
518 bsd="yes"
519 make="${MAKE-gmake}"
520;;
521netbsd)
522 bsd="yes"
523 make="${MAKE-gmake}"
524;;
525openbsd)
526 bsd="yes"
527 make="${MAKE-gmake}"
528;;
529darwin)
530 bsd="yes"
531 darwin="yes"
532 # Disable attempts to use ObjectiveC features in os/object.h since they
533 # won't work when we're compiling with gcc as a C compiler.
534 QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
535;;
ba7c60c2 536sunos)
65eff01b
PB
537 solaris="yes"
538 make="${MAKE-gmake}"
65eff01b
PB
539# needed for CMSG_ macros in sys/socket.h
540 QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
541# needed for TIOCWIN* defines in termios.h
542 QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
89138857 543 # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
65eff01b
PB
544 # Note that this check is broken for cross-compilation: if you're
545 # cross-compiling to one of these OSes then you'll need to specify
546 # the correct CPU with the --cpu option.
bbea4050
PM
547 if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
548 cpu="x86_64"
549 fi
65eff01b
PB
550;;
551haiku)
552 pie="no"
553 QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
554;;
555linux)
556 linux="yes"
65eff01b
PB
557 vhost_user=${default_feature:-yes}
558;;
bbea4050
PM
559esac
560
2ff6b91e
JQ
561if test ! -z "$cpu" ; then
562 # command line argument
563 :
564elif check_define __i386__ ; then
ac0df51d
AL
565 cpu="i386"
566elif check_define __x86_64__ ; then
c72b26ec
RH
567 if check_define __ILP32__ ; then
568 cpu="x32"
569 else
570 cpu="x86_64"
571 fi
3aa9bd6c 572elif check_define __sparc__ ; then
3aa9bd6c
BS
573 if check_define __arch64__ ; then
574 cpu="sparc64"
575 else
576 cpu="sparc"
577 fi
fdf7ed96 578elif check_define _ARCH_PPC ; then
579 if check_define _ARCH_PPC64 ; then
f8378acc
RH
580 if check_define _LITTLE_ENDIAN ; then
581 cpu="ppc64le"
582 else
583 cpu="ppc64"
584 fi
fdf7ed96 585 else
586 cpu="ppc"
587 fi
afa05235
AJ
588elif check_define __mips__ ; then
589 cpu="mips"
d66ed0ea
AJ
590elif check_define __s390__ ; then
591 if check_define __s390x__ ; then
592 cpu="s390x"
593 else
594 cpu="s390"
595 fi
c4f80543 596elif check_define __riscv ; then
ba0e7333 597 cpu="riscv"
21d89f84
PM
598elif check_define __arm__ ; then
599 cpu="arm"
1f080313
CF
600elif check_define __aarch64__ ; then
601 cpu="aarch64"
dfcf900b
WX
602elif check_define __loongarch64 ; then
603 cpu="loongarch64"
ac0df51d 604else
89138857 605 cpu=$(uname -m)
ac0df51d
AL
606fi
607
823eb013 608# Normalise host CPU name, set multilib cflags
359bc95d 609# Note that this case should only have supported host CPUs, not guests.
7d13299d 610case "$cpu" in
e4da0e39
PB
611 armv*b|armv*l|arm)
612 cpu="arm" ;;
613
7d13299d 614 i386|i486|i586|i686|i86pc|BePC)
97a847bc 615 cpu="i386"
e4da0e39
PB
616 CPU_CFLAGS="-m32" ;;
617 x32)
4da270be 618 cpu="x86_64"
e4da0e39 619 CPU_CFLAGS="-mx32" ;;
aaa5fa14
AJ
620 x86_64|amd64)
621 cpu="x86_64"
e4da0e39
PB
622 # ??? Only extremely old AMD cpus do not have cmpxchg16b.
623 # If we truly care, we should simply detect this case at
624 # runtime and generate the fallback to serial emulation.
625 CPU_CFLAGS="-m64 -mcx16" ;;
626
afa05235 627 mips*)
e4da0e39
PB
628 cpu="mips" ;;
629
630 ppc)
631 CPU_CFLAGS="-m32" ;;
632 ppc64)
ced5cfff 633 CPU_CFLAGS="-m64 -mbig-endian" ;;
e4da0e39 634 ppc64le)
d8ff892d 635 cpu="ppc64"
ced5cfff 636 CPU_CFLAGS="-m64 -mlittle-endian" ;;
e4da0e39
PB
637
638 s390)
823eb013 639 CPU_CFLAGS="-m31" ;;
e4da0e39
PB
640 s390x)
641 CPU_CFLAGS="-m64" ;;
642
3142255c 643 sparc|sun4[cdmuv])
ae228531 644 cpu="sparc"
e4da0e39
PB
645 CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
646 sparc64)
647 CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
7d13299d 648esac
e2d52ad3 649
0db4a067 650: ${make=${MAKE-make}}
b6daf4d3 651
faf44142
DB
652# We prefer python 3.x. A bare 'python' is traditionally
653# python 2.x, but some distros have it as python 3.x, so
ddf90699 654# we check that too
faf44142 655python=
0a01d76f 656explicit_python=no
ddf90699 657for binary in "${PYTHON-python3}" python
faf44142
DB
658do
659 if has "$binary"
660 then
95c5f2de 661 python=$(command -v "$binary")
faf44142
DB
662 break
663 fi
664done
903458c8 665
903458c8 666
39d87c8c
AB
667# Check for ancillary tools used in testing
668genisoimage=
3df437c7 669for binary in genisoimage mkisofs
39d87c8c
AB
670do
671 if has $binary
672 then
673 genisoimage=$(command -v "$binary")
674 break
675 fi
676done
677
3c4a4d0d
PM
678# Default objcc to clang if available, otherwise use CC
679if has clang; then
680 objcc=clang
681else
682 objcc="$cc"
683fi
684
3457a3f8 685if test "$mingw32" = "yes" ; then
3457a3f8 686 EXESUF=".exe"
78e9d4ad 687 # MinGW needs -mthreads for TLS and macro _MT.
5770e8af 688 CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
93b25869 689 write_c_skeleton;
d17f305a 690 prefix="/qemu"
77433a5f 691 qemu_suffix=""
3457a3f8
JQ
692fi
693
487fefdb 694werror=""
85aa5189 695
61d63097
PB
696. $source_path/scripts/meson-buildoptions.sh
697
698meson_options=
699meson_option_parse() {
700 meson_options="$meson_options $(_meson_option_parse "$@")"
701 if test $? -eq 1; then
702 echo "ERROR: unknown option $1"
703 echo "Try '$0 --help' for more information"
704 exit 1
705 fi
706}
707
7d13299d 708for opt do
89138857 709 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
7d13299d 710 case "$opt" in
2efc3265
FB
711 --help|-h) show_help=yes
712 ;;
99123e13
MF
713 --version|-V) exec cat $source_path/VERSION
714 ;;
b1a550a0 715 --prefix=*) prefix="$optarg"
7d13299d 716 ;;
b1a550a0 717 --interp-prefix=*) interp_prefix="$optarg"
32ce6337 718 ;;
ac0df51d 719 --cross-prefix=*)
7d13299d 720 ;;
ac0df51d 721 --cc=*)
7d13299d 722 ;;
b1a550a0 723 --host-cc=*) host_cc="$optarg"
83469015 724 ;;
83f73fce
TS
725 --cxx=*)
726 ;;
e007dbec
MT
727 --iasl=*) iasl="$optarg"
728 ;;
3c4a4d0d
PM
729 --objcc=*) objcc="$optarg"
730 ;;
b1a550a0 731 --make=*) make="$optarg"
7d13299d 732 ;;
b6daf4d3 733 --install=*)
6a882643 734 ;;
0a01d76f 735 --python=*) python="$optarg" ; explicit_python=yes
c886edfb 736 ;;
2eb054c2
PM
737 --sphinx-build=*) sphinx_build="$optarg"
738 ;;
a5665051
PB
739 --skip-meson) skip_meson=yes
740 ;;
741 --meson=*) meson="$optarg"
742 ;;
48328880
PB
743 --ninja=*) ninja="$optarg"
744 ;;
e2d8830e
BS
745 --smbd=*) smbd="$optarg"
746 ;;
e2a2ed06 747 --extra-cflags=*)
7d13299d 748 ;;
11cde1c8
BD
749 --extra-cxxflags=*)
750 ;;
e2a2ed06 751 --extra-ldflags=*)
7d13299d 752 ;;
5bc62e01
GH
753 --enable-debug-info)
754 ;;
755 --disable-debug-info)
756 ;;
d75402b5
AB
757 --cross-cc-*)
758 ;;
17969268
FZ
759 --enable-modules)
760 modules="yes"
3aa88b31
SH
761 ;;
762 --disable-modules)
763 modules="no"
17969268 764 ;;
bd83c861
CE
765 --disable-module-upgrades) module_upgrades="no"
766 ;;
767 --enable-module-upgrades) module_upgrades="yes"
768 ;;
2ff6b91e 769 --cpu=*)
7d13299d 770 ;;
b1a550a0 771 --target-list=*) target_list="$optarg"
447e133f
AB
772 if test "$target_list_exclude"; then
773 error_exit "Can't mix --target-list with --target-list-exclude"
774 fi
775 ;;
776 --target-list-exclude=*) target_list_exclude="$optarg"
777 if test "$target_list"; then
778 error_exit "Can't mix --target-list-exclude with --target-list"
779 fi
de83cd02 780 ;;
74242e0f 781 --with-trace-file=*) trace_file="$optarg"
9410b56c 782 ;;
7bc3ca7f 783 --with-default-devices) default_devices="true"
f3494749 784 ;;
7bc3ca7f 785 --without-default-devices) default_devices="false"
f3494749 786 ;;
d1d5e9ee
AB
787 --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
788 ;;
789 --with-devices-*) device_arch=${opt#--with-devices-};
790 device_arch=${device_arch%%=*}
791 cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
792 if test -f "$cf"; then
793 device_archs="$device_archs $device_arch"
794 eval "devices_${device_arch}=\$optarg"
795 else
796 error_exit "File $cf does not exist"
797 fi
798 ;;
c87ea116
AB
799 --without-default-features) # processed above
800 ;;
1d728c39
BS
801 --enable-gcov) gcov="yes"
802 ;;
79427693
LM
803 --static)
804 static="yes"
17884d7b 805 QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
43ce4dfe 806 ;;
0b24e75f
PB
807 --mandir=*) mandir="$optarg"
808 ;;
809 --bindir=*) bindir="$optarg"
810 ;;
3aa5d2be
AL
811 --libdir=*) libdir="$optarg"
812 ;;
8bf188aa
MT
813 --libexecdir=*) libexecdir="$optarg"
814 ;;
0f94d6da
AL
815 --includedir=*) includedir="$optarg"
816 ;;
528ae5b8 817 --datadir=*) datadir="$optarg"
0b24e75f 818 ;;
77433a5f 819 --with-suffix=*) qemu_suffix="$optarg"
023d3d67 820 ;;
c6502638 821 --docdir=*) docdir="$optarg"
0b24e75f 822 ;;
fe0038be
PB
823 --localedir=*) localedir="$optarg"
824 ;;
ca2fb938 825 --sysconfdir=*) sysconfdir="$optarg"
07381cc1 826 ;;
785c23ae
LC
827 --localstatedir=*) local_statedir="$optarg"
828 ;;
3d5eecab
GH
829 --firmwarepath=*) firmwarepath="$optarg"
830 ;;
181ce1d0
OH
831 --host=*|--build=*|\
832 --disable-dependency-tracking|\
785c23ae 833 --sbindir=*|--sharedstatedir=*|\
fe0038be 834 --oldincludedir=*|--datarootdir=*|--infodir=*|\
023ddd74
MF
835 --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
836 # These switches are silently ignored, for compatibility with
837 # autoconf-generated configure scripts. This allows QEMU's
838 # configure to be used by RPM and similar macros that set
839 # lots of directory switches by default.
840 ;;
0c58ac1c 841 --audio-drv-list=*) audio_drv_list="$optarg"
102a52e4 842 ;;
89138857 843 --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
b64ec4e4 844 ;;
89138857 845 --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
eb852011 846 ;;
f8393946
AJ
847 --enable-debug-tcg) debug_tcg="yes"
848 ;;
849 --disable-debug-tcg) debug_tcg="no"
850 ;;
f3d08ee6
PB
851 --enable-debug)
852 # Enable debugging options that aren't excessively noisy
853 debug_tcg="yes"
c55cf6ab 854 meson_option_parse --enable-debug-mutex ""
f3d08ee6 855 debug="yes"
b553a042 856 fortify_source="no"
f3d08ee6 857 ;;
247724cb
MAL
858 --enable-sanitizers) sanitizers="yes"
859 ;;
860 --disable-sanitizers) sanitizers="no"
861 ;;
0aebab04
LY
862 --enable-tsan) tsan="yes"
863 ;;
864 --disable-tsan) tsan="no"
865 ;;
4d34a86b 866 --disable-slirp) slirp="disabled"
1d14ffa9 867 ;;
fd6fc214
PB
868 --enable-slirp) slirp="enabled"
869 ;;
4d34a86b 870 --enable-slirp=git) slirp="internal"
7c57bdd8 871 ;;
03a3c0b3 872 --enable-slirp=*) slirp="$optarg"
675b9b53 873 ;;
1badb709 874 --disable-xen) xen="disabled"
e37630ca 875 ;;
1badb709 876 --enable-xen) xen="enabled"
fc321b4b 877 ;;
1badb709 878 --disable-tcg) tcg="disabled"
d1a14257 879 plugins="no"
b3f6ea7e 880 ;;
1badb709 881 --enable-tcg) tcg="enabled"
b3f6ea7e 882 ;;
cad25d69 883 --disable-system) softmmu="no"
0a8e90f4 884 ;;
cad25d69 885 --enable-system) softmmu="yes"
0a8e90f4 886 ;;
0953a80f
ZA
887 --disable-user)
888 linux_user="no" ;
889 bsd_user="no" ;
0953a80f
ZA
890 ;;
891 --enable-user) ;;
831b7825 892 --disable-linux-user) linux_user="no"
0a8e90f4 893 ;;
831b7825
TS
894 --enable-linux-user) linux_user="yes"
895 ;;
84778508
BS
896 --disable-bsd-user) bsd_user="no"
897 ;;
898 --enable-bsd-user) bsd_user="yes"
899 ;;
40d6444e 900 --enable-pie) pie="yes"
34005a00 901 ;;
40d6444e 902 --disable-pie) pie="no"
34005a00 903 ;;
85aa5189
FB
904 --enable-werror) werror="yes"
905 ;;
906 --disable-werror) werror="no"
907 ;;
cdad781d
DB
908 --enable-lto) lto="true"
909 ;;
910 --disable-lto) lto="false"
911 ;;
63678e17
SN
912 --enable-stack-protector) stack_protector="yes"
913 ;;
914 --disable-stack-protector) stack_protector="no"
915 ;;
1e4f6065
DB
916 --enable-safe-stack) safe_stack="yes"
917 ;;
918 --disable-safe-stack) safe_stack="no"
919 ;;
9e62ba48
DB
920 --enable-cfi)
921 cfi="true";
922 lto="true";
923 ;;
924 --disable-cfi) cfi="false"
925 ;;
fbb4121d 926 --disable-fdt) fdt="disabled"
2df87df7 927 ;;
fbb4121d
PB
928 --enable-fdt) fdt="enabled"
929 ;;
930 --enable-fdt=git) fdt="internal"
931 ;;
03a3c0b3 932 --enable-fdt=*) fdt="$optarg"
2df87df7 933 ;;
7e563bfb 934 --with-pkgversion=*) pkgversion="$optarg"
4a19f1ec 935 ;;
519175a2
AB
936 --with-coroutine=*) coroutine="$optarg"
937 ;;
d5970055
MT
938 --disable-vhost-net) vhost_net="no"
939 ;;
940 --enable-vhost-net) vhost_net="yes"
941 ;;
042cea27
GA
942 --disable-vhost-crypto) vhost_crypto="no"
943 ;;
299e6f19 944 --enable-vhost-crypto) vhost_crypto="yes"
042cea27 945 ;;
5e9be92d
NB
946 --disable-vhost-scsi) vhost_scsi="no"
947 ;;
948 --enable-vhost-scsi) vhost_scsi="yes"
949 ;;
fc0b9b0e
SH
950 --disable-vhost-vsock) vhost_vsock="no"
951 ;;
952 --enable-vhost-vsock) vhost_vsock="yes"
953 ;;
98fc1ada
DDAG
954 --disable-vhost-user-fs) vhost_user_fs="no"
955 ;;
956 --enable-vhost-user-fs) vhost_user_fs="yes"
957 ;;
da076ffe 958 --disable-opengl) opengl="no"
20ff075b 959 ;;
da076ffe 960 --enable-opengl) opengl="yes"
20ff075b 961 ;;
1ffb3bbb 962 --disable-zlib-test)
1ece9905 963 ;;
52b53c04
FZ
964 --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
965 echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
583f6e7b 966 ;;
cb6414df
FZ
967 --enable-vhdx|--disable-vhdx)
968 echo "$0: $opt is obsolete, VHDX driver is always built" >&2
969 ;;
315d3184
FZ
970 --enable-uuid|--disable-uuid)
971 echo "$0: $opt is obsolete, UUID support is always built" >&2
972 ;;
a1c5e949
DB
973 --tls-priority=*) tls_priority="$optarg"
974 ;;
2da776db
MH
975 --enable-rdma) rdma="yes"
976 ;;
977 --disable-rdma) rdma="no"
978 ;;
21ab34c9
MA
979 --enable-pvrdma) pvrdma="yes"
980 ;;
981 --disable-pvrdma) pvrdma="no"
982 ;;
e6a74868
MAL
983 --disable-vhost-user) vhost_user="no"
984 ;;
299e6f19
PB
985 --enable-vhost-user) vhost_user="yes"
986 ;;
108a6481
CL
987 --disable-vhost-vdpa) vhost_vdpa="no"
988 ;;
989 --enable-vhost-vdpa) vhost_vdpa="yes"
990 ;;
299e6f19
PB
991 --disable-vhost-kernel) vhost_kernel="no"
992 ;;
993 --enable-vhost-kernel) vhost_kernel="yes"
e6a74868 994 ;;
8b18cdbf 995 --disable-capstone) capstone="disabled"
8ca80760 996 ;;
8b18cdbf 997 --enable-capstone) capstone="enabled"
8ca80760 998 ;;
8b18cdbf 999 --enable-capstone=git) capstone="internal"
e219c499 1000 ;;
03a3c0b3 1001 --enable-capstone=*) capstone="$optarg"
e219c499 1002 ;;
cc84d63a
DB
1003 --with-git=*) git="$optarg"
1004 ;;
7d7dbf9d
DS
1005 --with-git-submodules=*)
1006 git_submodules_action="$optarg"
f62bbee5 1007 ;;
9b8e4298
AB
1008 --enable-plugins) if test "$mingw32" = "yes"; then
1009 error_exit "TCG plugins not currently supported on Windows platforms"
1010 else
1011 plugins="yes"
1012 fi
40e8c6f4
AB
1013 ;;
1014 --disable-plugins) plugins="no"
1015 ;;
afc3a8f9
AB
1016 --enable-containers) use_containers="yes"
1017 ;;
1018 --disable-containers) use_containers="no"
1019 ;;
f48e590a
AB
1020 --gdb=*) gdb_bin="$optarg"
1021 ;;
54e7aac0
AK
1022 --enable-keyring) secret_keyring="yes"
1023 ;;
1024 --disable-keyring) secret_keyring="no"
1025 ;;
20cf7b8e
DP
1026 --enable-gio) gio=yes
1027 ;;
1028 --disable-gio) gio=no
1029 ;;
3b4da132
PB
1030 # backwards compatibility options
1031 --enable-trace-backend=*) meson_option_parse "--enable-trace-backends=$optarg" "$optarg"
1032 ;;
1033 --disable-blobs) meson_option_parse --disable-install-blobs ""
1034 ;;
1035 --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
1036 ;;
1037 --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
1038 ;;
1039 # everything else has the same name in configure and meson
61d63097
PB
1040 --enable-* | --disable-*) meson_option_parse "$opt" "$optarg"
1041 ;;
2d2ad6d0
FZ
1042 *)
1043 echo "ERROR: unknown option $opt"
1044 echo "Try '$0 --help' for more information"
1045 exit 1
7f1559c6 1046 ;;
7d13299d
FB
1047 esac
1048done
1049
d1a14257
AB
1050# test for any invalid configuration combinations
1051if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
1052 error_exit "Can't enable plugins on non-TCG builds"
1053fi
1054
7d7dbf9d
DS
1055case $git_submodules_action in
1056 update|validate)
1057 if test ! -e "$source_path/.git"; then
1058 echo "ERROR: cannot $git_submodules_action git submodules without .git"
1059 exit 1
1060 fi
1061 ;;
1062 ignore)
b80fd281
PB
1063 if ! test -f "$source_path/ui/keycodemapdb/README"
1064 then
1065 echo
1066 echo "ERROR: missing GIT submodules"
1067 echo
1068 if test -e "$source_path/.git"; then
1069 echo "--with-git-submodules=ignore specified but submodules were not"
1070 echo "checked out. Please initialize and update submodules."
1071 else
1072 echo "This is not a GIT checkout but module content appears to"
1073 echo "be missing. Do not use 'git archive' or GitHub download links"
1074 echo "to acquire QEMU source archives. Non-GIT builds are only"
1075 echo "supported with source archives linked from:"
1076 echo
1077 echo " https://www.qemu.org/download/#source"
1078 echo
1079 echo "Developers working with GIT can use scripts/archive-source.sh"
1080 echo "if they need to create valid source archives."
1081 fi
1082 echo
1083 exit 1
1084 fi
7d7dbf9d
DS
1085 ;;
1086 *)
1087 echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
1088 exit 1
1089 ;;
1090esac
1091
22a87800
MAL
1092libdir="${libdir:-$prefix/lib}"
1093libexecdir="${libexecdir:-$prefix/libexec}"
1094includedir="${includedir:-$prefix/include}"
1095
1096if test "$mingw32" = "yes" ; then
15588a62 1097 bindir="${bindir:-$prefix}"
22a87800 1098else
22a87800 1099 bindir="${bindir:-$prefix/bin}"
22a87800 1100fi
15588a62
JW
1101mandir="${mandir:-$prefix/share/man}"
1102datadir="${datadir:-$prefix/share}"
1103docdir="${docdir:-$prefix/share/doc}"
1104sysconfdir="${sysconfdir:-$prefix/etc}"
1105local_statedir="${local_statedir:-$prefix/var}"
16bf7a33
PB
1106firmwarepath="${firmwarepath:-$datadir/qemu-firmware}"
1107localedir="${localedir:-$datadir/locale}"
22a87800 1108
9557af9c
AB
1109if eval test -z "\${cross_cc_$cpu}"; then
1110 eval "cross_cc_${cpu}=\$cc"
1111 cross_cc_vars="$cross_cc_vars cross_cc_${cpu}"
1112fi
79f3b12f 1113
60e0df25 1114default_target_list=""
6e92f823
PM
1115mak_wilds=""
1116
b915a2f1
PB
1117if [ "$linux_user" != no ]; then
1118 if [ "$targetos" = linux ] && [ -d $source_path/linux-user/include/host/$cpu ]; then
1119 linux_user=yes
1120 elif [ "$linux_user" = yes ]; then
1121 error_exit "linux-user not supported on this architecture"
1122 fi
1123fi
1124if [ "$bsd_user" != no ]; then
1125 if [ "$bsd_user" = "" ]; then
1126 test $targetos = freebsd && bsd_user=yes
1127 fi
1128 if [ "$bsd_user" = yes ] && ! [ -d $source_path/bsd-user/$targetos ]; then
1129 error_exit "bsd-user not supported on this host OS"
1130 fi
1131fi
6e92f823 1132if [ "$softmmu" = "yes" ]; then
812b31d3 1133 mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
60e0df25 1134fi
6e92f823 1135if [ "$linux_user" = "yes" ]; then
812b31d3 1136 mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
60e0df25 1137fi
6e92f823 1138if [ "$bsd_user" = "yes" ]; then
812b31d3 1139 mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
60e0df25
PM
1140fi
1141
2d838d9b
AB
1142for config in $mak_wilds; do
1143 target="$(basename "$config" .mak)"
98db9a06 1144 if echo "$target_list_exclude" | grep -vq "$target"; then
2d838d9b
AB
1145 default_target_list="${default_target_list} $target"
1146 fi
1147done
6e92f823 1148
af5db58e
PB
1149if test x"$show_help" = x"yes" ; then
1150cat << EOF
1151
1152Usage: configure [options]
1153Options: [defaults in brackets after descriptions]
1154
08fb77ed
SW
1155Standard options:
1156 --help print this message
1157 --prefix=PREFIX install in PREFIX [$prefix]
1158 --interp-prefix=PREFIX where to find shared libraries, etc.
1159 use %M for cpu name [$interp_prefix]
74154d7e 1160 --target-list=LIST set target list (default: build all)
08fb77ed
SW
1161$(echo Available targets: $default_target_list | \
1162 fold -s -w 53 | sed -e 's/^/ /')
447e133f 1163 --target-list-exclude=LIST exclude a set of targets from the default target-list
08fb77ed
SW
1164
1165Advanced options (experts only):
3812c0c4 1166 --cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
08fb77ed
SW
1167 --cc=CC use C compiler CC [$cc]
1168 --iasl=IASL use ACPI compiler IASL [$iasl]
1169 --host-cc=CC use C compiler CC [$host_cc] for code run at
1170 build time
1171 --cxx=CXX use C++ compiler CXX [$cxx]
1172 --objcc=OBJCC use Objective-C compiler OBJCC [$objcc]
a2866660
PB
1173 --extra-cflags=CFLAGS append extra C compiler flags CFLAGS
1174 --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
08fb77ed 1175 --extra-ldflags=LDFLAGS append extra linker flags LDFLAGS
d75402b5 1176 --cross-cc-ARCH=CC use compiler when building ARCH guest test cases
479ca4cc 1177 --cross-cc-cflags-ARCH= use compiler flags when building ARCH guest tests
08fb77ed 1178 --make=MAKE use specified make [$make]
08fb77ed 1179 --python=PYTHON use specified python [$python]
2eb054c2 1180 --sphinx-build=SPHINX use specified sphinx-build [$sphinx_build]
a5665051 1181 --meson=MESON use specified meson [$meson]
48328880 1182 --ninja=NINJA use specified ninja [$ninja]
08fb77ed 1183 --smbd=SMBD use specified smbd [$smbd]
db1b5f13 1184 --with-git=GIT use specified git [$git]
7d7dbf9d
DS
1185 --with-git-submodules=update update git submodules (default if .git dir exists)
1186 --with-git-submodules=validate fail if git submodules are not up to date
1187 --with-git-submodules=ignore do not update or check git submodules (default if no .git dir)
08fb77ed
SW
1188 --static enable static build [$static]
1189 --mandir=PATH install man pages in PATH
10ff82d1 1190 --datadir=PATH install firmware in PATH/$qemu_suffix
fe0038be 1191 --localedir=PATH install translation in PATH/$qemu_suffix
10ff82d1 1192 --docdir=PATH install documentation in PATH/$qemu_suffix
08fb77ed
SW
1193 --bindir=PATH install binaries in PATH
1194 --libdir=PATH install libraries in PATH
db1b5f13 1195 --libexecdir=PATH install helper binaries in PATH
10ff82d1 1196 --sysconfdir=PATH install config in PATH/$qemu_suffix
08fb77ed 1197 --localstatedir=PATH install local state in PATH (set at runtime on win32)
3d5eecab 1198 --firmwarepath=PATH search PATH for firmware files
13336606 1199 --efi-aarch64=PATH PATH of efi file to use for aarch64 VMs.
ca8c0909 1200 --with-suffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
db1b5f13 1201 --with-pkgversion=VERS use specified string as sub-version of the package
c035c8d6
PB
1202 --without-default-features default all --enable-* options to "disabled"
1203 --without-default-devices do not include any device that is not needed to
1204 start the emulator (only use if you are including
d1d5e9ee
AB
1205 desired devices in configs/devices/)
1206 --with-devices-ARCH=NAME override default configs/devices
08fb77ed 1207 --enable-debug enable common debug build options
247724cb 1208 --enable-sanitizers enable default sanitizers
0aebab04 1209 --enable-tsan enable thread sanitizer
08fb77ed 1210 --disable-werror disable compilation abort on warning
63678e17 1211 --disable-stack-protector disable compiler-provided stack protection
16bfbc70 1212 --audio-drv-list=LIST set audio drivers to try if -audiodev is not used
08fb77ed
SW
1213 --block-drv-whitelist=L Same as --block-drv-rw-whitelist=L
1214 --block-drv-rw-whitelist=L
1215 set block driver read-write whitelist
e5f05f8c 1216 (by default affects only QEMU, not tools like qemu-img)
08fb77ed
SW
1217 --block-drv-ro-whitelist=L
1218 set block driver read-only whitelist
e5f05f8c 1219 (by default affects only QEMU, not tools like qemu-img)
08fb77ed
SW
1220 --with-trace-file=NAME Full PATH,NAME of file to store traces
1221 Default:trace-<pid>
c23f23b9 1222 --cpu=CPU Build for host CPU [$cpu]
08fb77ed 1223 --with-coroutine=BACKEND coroutine backend. Supported options:
33c53c54 1224 ucontext, sigaltstack, windows
08fb77ed 1225 --enable-gcov enable test coverage analysis with gcov
a1c5e949 1226 --tls-priority default TLS protocol/cipher priority string
40e8c6f4
AB
1227 --enable-plugins
1228 enable plugins via shared library loading
afc3a8f9 1229 --disable-containers don't use containers for cross-building
f48e590a 1230 --gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
61d63097
PB
1231EOF
1232 meson_options_help
1233cat << EOF
c23f23b9
MT
1234 system all system emulation targets
1235 user supported user emulation targets
1236 linux-user all linux usermode emulation targets
1237 bsd-user all BSD usermode emulation targets
c23f23b9 1238 pie Position Independent Executables
21e709aa 1239 modules modules support (non-Windows)
bd83c861 1240 module-upgrades try to load modules from alternate paths for upgrades
c23f23b9
MT
1241 debug-tcg TCG debugging (default is disabled)
1242 debug-info debugging information
cdad781d 1243 lto Enable Link-Time Optimization.
1e4f6065
DB
1244 safe-stack SafeStack Stack Smash Protection. Depends on
1245 clang/llvm >= 3.7 and requires coroutine backend ucontext.
21ab34c9
MA
1246 rdma Enable RDMA-based migration
1247 pvrdma Enable PVRDMA support
299e6f19
PB
1248 vhost-net vhost-net kernel acceleration support
1249 vhost-vsock virtio sockets device support
1250 vhost-scsi vhost-scsi kernel target support
1251 vhost-crypto vhost-user-crypto backend support
1252 vhost-kernel vhost kernel backend support
1253 vhost-user vhost-user backend support
108a6481 1254 vhost-vdpa vhost-vdpa kernel backend support
c12d66aa 1255 opengl opengl support
20cf7b8e 1256 gio libgio support
08fb77ed
SW
1257
1258NOTE: The object files are built at the place where configure is launched
af5db58e 1259EOF
2d2ad6d0 1260exit 0
af5db58e
PB
1261fi
1262
9c790242 1263# Remove old dependency files to make sure that they get properly regenerated
bb768f71 1264rm -f */config-devices.mak.d
9c790242 1265
faf44142
DB
1266if test -z "$python"
1267then
1268 error_exit "Python not found. Use --python=/path/to/python"
c53eeaf7 1269fi
8e2c76bd
RB
1270if ! has "$make"
1271then
1272 error_exit "GNU make ($make) not found"
1273fi
c53eeaf7
SH
1274
1275# Note that if the Python conditional here evaluates True we will exit
1276# with status 1 which is a shell 'false' value.
1b11f28d
TH
1277if ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then
1278 error_exit "Cannot use '$python', Python >= 3.6 is required." \
c53eeaf7
SH
1279 "Use --python=/path/to/python to specify a supported Python."
1280fi
1281
755ee70f 1282# Preserve python version since some functionality is dependent on it
406ab2f3 1283python_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 1284
c53eeaf7
SH
1285# Suppress writing compiled files
1286python="$python -B"
1287
0a01d76f 1288if test -z "$meson"; then
6638cae5 1289 if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.59.3; then
0a01d76f 1290 meson=meson
7d7dbf9d 1291 elif test $git_submodules_action != 'ignore' ; then
0a01d76f
MAL
1292 meson=git
1293 elif test -e "${source_path}/meson/meson.py" ; then
1294 meson=internal
1295 else
1296 if test "$explicit_python" = yes; then
1297 error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
1298 else
1299 error_exit "Meson not found. Use --meson=/path/to/meson"
1300 fi
1301 fi
1302else
1303 # Meson uses its own Python interpreter to invoke other Python scripts,
1304 # but the user wants to use the one they specified with --python.
1305 #
1306 # We do not want to override the distro Python interpreter (and sometimes
1307 # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
1308 # just require --meson=git|internal together with --python.
1309 if test "$explicit_python" = yes; then
1310 case "$meson" in
1311 git | internal) ;;
1312 *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
1313 esac
1314 fi
a5665051 1315fi
a5665051 1316
0a01d76f
MAL
1317if test "$meson" = git; then
1318 git_submodules="${git_submodules} meson"
a5665051 1319fi
0a01d76f
MAL
1320
1321case "$meson" in
1322 git | internal)
0a01d76f
MAL
1323 meson="$python ${source_path}/meson/meson.py"
1324 ;;
84ec0c24 1325 *) meson=$(command -v "$meson") ;;
0a01d76f
MAL
1326esac
1327
09e93326 1328# Probe for ninja
48328880
PB
1329
1330if test -z "$ninja"; then
1331 for c in ninja ninja-build samu; do
1332 if has $c; then
1333 ninja=$(command -v "$c")
1334 break
1335 fi
1336 done
09e93326
PB
1337 if test -z "$ninja"; then
1338 error_exit "Cannot find Ninja"
1339 fi
48328880 1340fi
a5665051 1341
9aae6e54
DHB
1342# Check that the C compiler works. Doing this here before testing
1343# the host CPU ensures that we had a valid CC to autodetect the
1344# $cpu var (and we should bail right here if that's not the case).
1345# It also allows the help message to be printed without a CC.
1346write_c_skeleton;
1347if compile_object ; then
1348 : C compiler works ok
1349else
1350 error_exit "\"$cc\" either does not exist or does not work"
1351fi
1352if ! compile_prog ; then
1353 error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
1354fi
1355
9c83ffd8
PM
1356# Consult white-list to determine whether to enable werror
1357# by default. Only enable by default for git builds
9c83ffd8 1358if test -z "$werror" ; then
7d7dbf9d 1359 if test "$git_submodules_action" != "ignore" && \
e633a5c6 1360 { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
9c83ffd8
PM
1361 werror="yes"
1362 else
1363 werror="no"
1364 fi
1365fi
1366
975ff037 1367if test "$targetos" = "bogus"; then
fb59dabd
PM
1368 # Now that we know that we're not printing the help and that
1369 # the compiler works (so the results of the check_defines we used
1370 # to identify the OS are reliable), if we didn't recognize the
1371 # host OS we should stop now.
951fedfc 1372 error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
fb59dabd
PM
1373fi
1374
efc6c070
TH
1375# Check whether the compiler matches our minimum requirements:
1376cat > $TMPC << EOF
1377#if defined(__clang_major__) && defined(__clang_minor__)
1378# ifdef __apple_build_version__
2a85a08c
DB
1379# if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
1380# error You need at least XCode Clang v10.0 to compile QEMU
efc6c070
TH
1381# endif
1382# else
2a85a08c
DB
1383# if __clang_major__ < 6 || (__clang_major__ == 6 && __clang_minor__ < 0)
1384# error You need at least Clang v6.0 to compile QEMU
efc6c070
TH
1385# endif
1386# endif
1387#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
3830df5f 1388# if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
1389# error You need at least GCC v7.4.0 to compile QEMU
efc6c070
TH
1390# endif
1391#else
1392# error You either need GCC or Clang to compiler QEMU
1393#endif
1394int main (void) { return 0; }
1395EOF
1396if ! compile_prog "" "" ; then
3830df5f 1397 error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
efc6c070
TH
1398fi
1399
00849b92
RH
1400# Accumulate -Wfoo and -Wno-bar separately.
1401# We will list all of the enable flags first, and the disable flags second.
1402# Note that we do not add -Werror, because that would enable it for all
1403# configure tests. If a configure test failed due to -Werror this would
1404# just silently disable some features, so it's too error prone.
1405
1406warn_flags=
1407add_to warn_flags -Wold-style-declaration
1408add_to warn_flags -Wold-style-definition
1409add_to warn_flags -Wtype-limits
1410add_to warn_flags -Wformat-security
1411add_to warn_flags -Wformat-y2k
1412add_to warn_flags -Winit-self
1413add_to warn_flags -Wignored-qualifiers
1414add_to warn_flags -Wempty-body
1415add_to warn_flags -Wnested-externs
1416add_to warn_flags -Wendif-labels
1417add_to warn_flags -Wexpansion-to-defined
0a2ebce9 1418add_to warn_flags -Wimplicit-fallthrough=2
00849b92
RH
1419
1420nowarn_flags=
1421add_to nowarn_flags -Wno-initializer-overrides
1422add_to nowarn_flags -Wno-missing-include-dirs
1423add_to nowarn_flags -Wno-shift-negative-value
1424add_to nowarn_flags -Wno-string-plus-int
1425add_to nowarn_flags -Wno-typedef-redefinition
aabab967 1426add_to nowarn_flags -Wno-tautological-type-limit-compare
bac8d222 1427add_to nowarn_flags -Wno-psabi
00849b92
RH
1428
1429gcc_flags="$warn_flags $nowarn_flags"
93b25869
JS
1430
1431cc_has_warning_flag() {
1432 write_c_skeleton;
1433
a1d29d6c
PM
1434 # Use the positive sense of the flag when testing for -Wno-wombat
1435 # support (gcc will happily accept the -Wno- form of unknown
1436 # warning options).
93b25869
JS
1437 optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
1438 compile_prog "-Werror $optflag" ""
1439}
1440
1441for flag in $gcc_flags; do
1442 if cc_has_warning_flag $flag ; then
1443 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
8d05095c
PB
1444 fi
1445done
1446
3b463a3f 1447if test "$stack_protector" != "no"; then
fccd35a0
RR
1448 cat > $TMPC << EOF
1449int main(int argc, char *argv[])
1450{
1451 char arr[64], *p = arr, *c = argv[0];
1452 while (*c) {
1453 *p++ = *c++;
1454 }
1455 return 0;
1456}
1457EOF
63678e17 1458 gcc_flags="-fstack-protector-strong -fstack-protector-all"
3b463a3f 1459 sp_on=0
63678e17 1460 for flag in $gcc_flags; do
590e5dd9
PM
1461 # We need to check both a compile and a link, since some compiler
1462 # setups fail only on a .c->.o compile and some only at link time
086d5f75 1463 if compile_object "-Werror $flag" &&
590e5dd9 1464 compile_prog "-Werror $flag" ""; then
63678e17 1465 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
db5adeaa 1466 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
3b463a3f 1467 sp_on=1
63678e17
SN
1468 break
1469 fi
1470 done
3b463a3f
MR
1471 if test "$stack_protector" = yes; then
1472 if test $sp_on = 0; then
1473 error_exit "Stack protector not supported"
1474 fi
1475 fi
37746c5e
MAL
1476fi
1477
20bc94a2
PB
1478# Disable -Wmissing-braces on older compilers that warn even for
1479# the "universal" C zero initializer {0}.
1480cat > $TMPC << EOF
1481struct {
1482 int a[2];
1483} x = {0};
1484EOF
1485if compile_object "-Werror" "" ; then
1486 :
1487else
1488 QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
1489fi
1490
21e709aa
MAL
1491# Our module code doesn't support Windows
1492if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
1493 error_exit "Modules are not available for Windows"
1494fi
1495
bd83c861
CE
1496# module_upgrades is only reasonable if modules are enabled
1497if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
1498 error_exit "Can't enable module-upgrades as Modules are not enabled"
1499fi
1500
5f2453ac 1501# Static linking is not possible with plugins, modules or PIE
40d6444e 1502if test "$static" = "yes" ; then
aa0d1f44
PB
1503 if test "$modules" = "yes" ; then
1504 error_exit "static and modules are mutually incompatible"
1505 fi
5f2453ac
AB
1506 if test "$plugins" = "yes"; then
1507 error_exit "static and plugins are mutually incompatible"
ba4dd2aa
AB
1508 else
1509 plugins="no"
5f2453ac 1510 fi
40d6444e 1511fi
37650689 1512test "$plugins" = "" && plugins=yes
40d6444e 1513
b2634124 1514cat > $TMPC << EOF
21d4a791
AK
1515
1516#ifdef __linux__
1517# define THREAD __thread
1518#else
1519# define THREAD
1520#endif
21d4a791 1521static THREAD int tls_var;
21d4a791 1522int main(void) { return tls_var; }
40d6444e 1523EOF
412aeacd 1524
ffd205ef
JC
1525# Check we support -fno-pie and -no-pie first; we will need the former for
1526# building ROMs, and both for everything if --disable-pie is passed.
b2634124
RH
1527if compile_prog "-Werror -fno-pie" "-no-pie"; then
1528 CFLAGS_NOPIE="-fno-pie"
ffd205ef 1529 LDFLAGS_NOPIE="-no-pie"
b2634124
RH
1530fi
1531
12781462 1532if test "$static" = "yes"; then
eca7a8e6 1533 if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
5770e8af 1534 CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
12781462
RH
1535 QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
1536 pie="yes"
1537 elif test "$pie" = "yes"; then
1538 error_exit "-static-pie not available due to missing toolchain support"
1539 else
1540 QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
1541 pie="no"
1542 fi
1543elif test "$pie" = "no"; then
5770e8af 1544 CONFIGURE_CFLAGS="$CFLAGS_NOPIE $CONFIGURE_CFLAGS"
ffd205ef 1545 CONFIGURE_LDFLAGS="$LDFLAGS_NOPIE $CONFIGURE_LDFLAGS"
eca7a8e6 1546elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
5770e8af
PB
1547 CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
1548 CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
2c674109
RH
1549 pie="yes"
1550elif test "$pie" = "yes"; then
1551 error_exit "PIE not available due to missing toolchain support"
1552else
1553 echo "Disabling PIE due to missing toolchain support"
1554 pie="no"
40d6444e
AK
1555fi
1556
e6cbd751
RH
1557# Detect support for PT_GNU_RELRO + DT_BIND_NOW.
1558# The combination is known as "full relro", because .got.plt is read-only too.
1559if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1560 QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
1561fi
1562
09dada40
PB
1563##########################################
1564# __sync_fetch_and_and requires at least -march=i486. Many toolchains
1565# use i686 as default anyway, but for those that don't, an explicit
1566# specification is necessary
1567
1568if test "$cpu" = "i386"; then
1569 cat > $TMPC << EOF
1570static int sfaa(int *ptr)
1571{
1572 return __sync_fetch_and_and(ptr, 0);
1573}
1574
1575int main(void)
1576{
1577 int val = 42;
1405b629 1578 val = __sync_val_compare_and_swap(&val, 0, 1);
09dada40
PB
1579 sfaa(&val);
1580 return val;
1581}
1582EOF
1583 if ! compile_prog "" "" ; then
1584 QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
1585 fi
1586fi
1587
56267b62
PMD
1588if test "$tcg" = "enabled"; then
1589 git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
1590 git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
1591fi
1592
afb63ebd 1593if test -z "${target_list+xxx}" ; then
fdb75aef 1594 default_targets=yes
d880a3ba 1595 for target in $default_target_list; do
fdb75aef 1596 target_list="$target_list $target"
d880a3ba
PB
1597 done
1598 target_list="${target_list# }"
121afa9e 1599else
fdb75aef 1600 default_targets=no
89138857 1601 target_list=$(echo "$target_list" | sed -e 's/,/ /g')
d880a3ba
PB
1602 for target in $target_list; do
1603 # Check that we recognised the target name; this allows a more
1604 # friendly error message than if we let it fall through.
1605 case " $default_target_list " in
1606 *" $target "*)
1607 ;;
1608 *)
1609 error_exit "Unknown target name '$target'"
1610 ;;
1611 esac
d880a3ba 1612 done
121afa9e 1613fi
25b48338 1614
f55fe278
PB
1615# see if system emulation was really requested
1616case " $target_list " in
1617 *"-softmmu "*) softmmu=yes
1618 ;;
1619 *) softmmu=no
1620 ;;
1621esac
5327cf48 1622
249247c9
JQ
1623feature_not_found() {
1624 feature=$1
21684af0 1625 remedy=$2
249247c9 1626
76ad07a4 1627 error_exit "User requested feature $feature" \
21684af0
SS
1628 "configure was not able to find it." \
1629 "$remedy"
249247c9
JQ
1630}
1631
7d13299d
FB
1632# ---
1633# big/little endian test
1634cat > $TMPC << EOF
659eb157 1635#include <stdio.h>
61cc919f
MF
1636short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
1637short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
659eb157
TH
1638int main(int argc, char *argv[])
1639{
1640 return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
7d13299d
FB
1641}
1642EOF
1643
659eb157
TH
1644if compile_prog ; then
1645 if strings -a $TMPE | grep -q BiGeNdIaN ; then
61cc919f 1646 bigendian="yes"
659eb157 1647 elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
61cc919f
MF
1648 bigendian="no"
1649 else
1650 echo big/little test failed
659eb157 1651 exit 1
21d89f84 1652 fi
61cc919f
MF
1653else
1654 echo big/little test failed
659eb157 1655 exit 1
7d13299d
FB
1656fi
1657
299e6f19
PB
1658#########################################
1659# vhost interdependencies and host support
1660
1661# vhost backends
d88618f7
SH
1662if test "$vhost_user" = "yes" && test "$linux" != "yes"; then
1663 error_exit "vhost-user is only available on Linux"
299e6f19 1664fi
108a6481
CL
1665test "$vhost_vdpa" = "" && vhost_vdpa=$linux
1666if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
1667 error_exit "vhost-vdpa is only available on Linux"
1668fi
299e6f19
PB
1669test "$vhost_kernel" = "" && vhost_kernel=$linux
1670if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
1671 error_exit "vhost-kernel is only available on Linux"
1672fi
1673
1674# vhost-kernel devices
1675test "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
1676if test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
1677 error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
1678fi
1679test "$vhost_vsock" = "" && vhost_vsock=$vhost_kernel
1680if test "$vhost_vsock" = "yes" && test "$vhost_kernel" != "yes"; then
1681 error_exit "--enable-vhost-vsock requires --enable-vhost-kernel"
1682fi
1683
1684# vhost-user backends
1685test "$vhost_net_user" = "" && vhost_net_user=$vhost_user
1686if test "$vhost_net_user" = "yes" && test "$vhost_user" = "no"; then
1687 error_exit "--enable-vhost-net-user requires --enable-vhost-user"
1688fi
1689test "$vhost_crypto" = "" && vhost_crypto=$vhost_user
1690if test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
1691 error_exit "--enable-vhost-crypto requires --enable-vhost-user"
1692fi
98fc1ada
DDAG
1693test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
1694if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
1695 error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
1696fi
108a6481
CL
1697#vhost-vdpa backends
1698test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa
1699if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then
1700 error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa"
1701fi
299e6f19 1702
40bc0ca9 1703# OR the vhost-kernel, vhost-vdpa and vhost-user values for simplicity
299e6f19
PB
1704if test "$vhost_net" = ""; then
1705 test "$vhost_net_user" = "yes" && vhost_net=yes
40bc0ca9 1706 test "$vhost_net_vdpa" = "yes" && vhost_net=yes
299e6f19
PB
1707 test "$vhost_kernel" = "yes" && vhost_net=yes
1708fi
1709
779ab5e3
SW
1710##########################################
1711# pkg-config probe
1712
1713if ! has "$pkg_config_exe"; then
76ad07a4 1714 error_exit "pkg-config binary '$pkg_config_exe' not found"
779ab5e3
SW
1715fi
1716
e37630ca
AL
1717##########################################
1718# xen probe
1719
1badb709 1720if test "$xen" != "disabled" ; then
c1cdd9d5
JG
1721 # Check whether Xen library path is specified via --extra-ldflags to avoid
1722 # overriding this setting with pkg-config output. If not, try pkg-config
1723 # to obtain all needed flags.
1724
1725 if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \
1726 $pkg_config --exists xencontrol ; then
1727 xen_ctrl_version="$(printf '%d%02d%02d' \
1728 $($pkg_config --modversion xencontrol | sed 's/\./ /g') )"
1badb709 1729 xen=enabled
5b6a8f43 1730 xen_pc="xencontrol xenstore xenforeignmemory xengnttab"
c1cdd9d5 1731 xen_pc="$xen_pc xenevtchn xendevicemodel"
58ea9a7a
AP
1732 if $pkg_config --exists xentoolcore; then
1733 xen_pc="$xen_pc xentoolcore"
1734 fi
582ea95f
MAL
1735 xen_cflags="$($pkg_config --cflags $xen_pc)"
1736 xen_libs="$($pkg_config --libs $xen_pc)"
c1cdd9d5 1737 else
d5b93ddf 1738
5b6a8f43 1739 xen_libs="-lxenstore -lxenctrl"
d9506cab 1740 xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
50ced5b3 1741
c1cdd9d5
JG
1742 # First we test whether Xen headers and libraries are available.
1743 # If no, we are done and there is no Xen support.
1744 # If yes, more tests are run to detect the Xen version.
1745
1746 # Xen (any)
1747 cat > $TMPC <<EOF
e37630ca 1748#include <xenctrl.h>
50ced5b3
SW
1749int main(void) {
1750 return 0;
1751}
1752EOF
c1cdd9d5
JG
1753 if ! compile_prog "" "$xen_libs" ; then
1754 # Xen not found
1badb709 1755 if test "$xen" = "enabled" ; then
c1cdd9d5
JG
1756 feature_not_found "xen" "Install xen devel"
1757 fi
1badb709 1758 xen=disabled
50ced5b3 1759
c1cdd9d5
JG
1760 # Xen unstable
1761 elif
1762 cat > $TMPC <<EOF &&
2cbf8903
RL
1763#undef XC_WANT_COMPAT_DEVICEMODEL_API
1764#define __XEN_TOOLS__
1765#include <xendevicemodel.h>
d3c49ebb 1766#include <xenforeignmemory.h>
2cbf8903
RL
1767int main(void) {
1768 xendevicemodel_handle *xd;
d3c49ebb 1769 xenforeignmemory_handle *xfmem;
2cbf8903
RL
1770
1771 xd = xendevicemodel_open(0, 0);
1772 xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);
1773
d3c49ebb
PD
1774 xfmem = xenforeignmemory_open(0, 0);
1775 xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);
1776
2cbf8903
RL
1777 return 0;
1778}
1779EOF
1780 compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
1781 then
1782 xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
1783 xen_ctrl_version=41100
1badb709 1784 xen=enabled
2cbf8903
RL
1785 elif
1786 cat > $TMPC <<EOF &&
5ba3d756
ID
1787#undef XC_WANT_COMPAT_MAP_FOREIGN_API
1788#include <xenforeignmemory.h>
58ea9a7a 1789#include <xentoolcore.h>
5ba3d756
ID
1790int main(void) {
1791 xenforeignmemory_handle *xfmem;
1792
1793 xfmem = xenforeignmemory_open(0, 0);
1794 xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
58ea9a7a 1795 xentoolcore_restrict_all(0);
5ba3d756
ID
1796
1797 return 0;
1798}
1799EOF
58ea9a7a 1800 compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
5ba3d756 1801 then
58ea9a7a 1802 xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
5ba3d756 1803 xen_ctrl_version=41000
1badb709 1804 xen=enabled
5ba3d756
ID
1805 elif
1806 cat > $TMPC <<EOF &&
da8090cc
PD
1807#undef XC_WANT_COMPAT_DEVICEMODEL_API
1808#define __XEN_TOOLS__
1809#include <xendevicemodel.h>
1810int main(void) {
1811 xendevicemodel_handle *xd;
1812
1813 xd = xendevicemodel_open(0, 0);
1814 xendevicemodel_close(xd);
50ced5b3 1815
da8090cc
PD
1816 return 0;
1817}
1818EOF
c1cdd9d5
JG
1819 compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs"
1820 then
1821 xen_stable_libs="-lxendevicemodel $xen_stable_libs"
1822 xen_ctrl_version=40900
1badb709 1823 xen=enabled
c1cdd9d5
JG
1824 elif
1825 cat > $TMPC <<EOF &&
b6eb9b45
PS
1826/*
1827 * If we have stable libs the we don't want the libxc compat
1828 * layers, regardless of what CFLAGS we may have been given.
1829 *
1830 * Also, check if xengnttab_grant_copy_segment_t is defined and
1831 * grant copy operation is implemented.
1832 */
1833#undef XC_WANT_COMPAT_EVTCHN_API
1834#undef XC_WANT_COMPAT_GNTTAB_API
1835#undef XC_WANT_COMPAT_MAP_FOREIGN_API
1836#include <xenctrl.h>
1837#include <xenstore.h>
1838#include <xenevtchn.h>
1839#include <xengnttab.h>
1840#include <xenforeignmemory.h>
1841#include <stdint.h>
1842#include <xen/hvm/hvm_info_table.h>
1843#if !defined(HVM_MAX_VCPUS)
1844# error HVM_MAX_VCPUS not defined
1845#endif
1846int main(void) {
1847 xc_interface *xc = NULL;
1848 xenforeignmemory_handle *xfmem;
1849 xenevtchn_handle *xe;
1850 xengnttab_handle *xg;
b6eb9b45
PS
1851 xengnttab_grant_copy_segment_t* seg = NULL;
1852
1853 xs_daemon_open();
1854
1855 xc = xc_interface_open(0, 0, 0);
1856 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1857 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
1858 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
1859 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
b6eb9b45
PS
1860
1861 xfmem = xenforeignmemory_open(0, 0);
1862 xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
1863
1864 xe = xenevtchn_open(0, 0);
1865 xenevtchn_fd(xe);
1866
1867 xg = xengnttab_open(0, 0);
1868 xengnttab_grant_copy(xg, 0, seg);
1869
1870 return 0;
1871}
1872EOF
c1cdd9d5
JG
1873 compile_prog "" "$xen_libs $xen_stable_libs"
1874 then
1875 xen_ctrl_version=40800
1badb709 1876 xen=enabled
c1cdd9d5
JG
1877 elif
1878 cat > $TMPC <<EOF &&
5eeb39c2
IC
1879/*
1880 * If we have stable libs the we don't want the libxc compat
1881 * layers, regardless of what CFLAGS we may have been given.
1882 */
1883#undef XC_WANT_COMPAT_EVTCHN_API
1884#undef XC_WANT_COMPAT_GNTTAB_API
1885#undef XC_WANT_COMPAT_MAP_FOREIGN_API
1886#include <xenctrl.h>
1887#include <xenstore.h>
1888#include <xenevtchn.h>
1889#include <xengnttab.h>
1890#include <xenforeignmemory.h>
1891#include <stdint.h>
1892#include <xen/hvm/hvm_info_table.h>
1893#if !defined(HVM_MAX_VCPUS)
1894# error HVM_MAX_VCPUS not defined
1895#endif
1896int main(void) {
1897 xc_interface *xc = NULL;
1898 xenforeignmemory_handle *xfmem;
1899 xenevtchn_handle *xe;
1900 xengnttab_handle *xg;
5eeb39c2
IC
1901
1902 xs_daemon_open();
1903
1904 xc = xc_interface_open(0, 0, 0);
1905 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1906 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
1907 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
1908 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
5eeb39c2
IC
1909
1910 xfmem = xenforeignmemory_open(0, 0);
1911 xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
1912
1913 xe = xenevtchn_open(0, 0);
1914 xenevtchn_fd(xe);
1915
1916 xg = xengnttab_open(0, 0);
1917 xengnttab_map_grant_ref(xg, 0, 0, 0);
1918
1919 return 0;
1920}
1921EOF
c1cdd9d5
JG
1922 compile_prog "" "$xen_libs $xen_stable_libs"
1923 then
1924 xen_ctrl_version=40701
1badb709 1925 xen=enabled
c1cdd9d5
JG
1926
1927 # Xen 4.6
1928 elif
1929 cat > $TMPC <<EOF &&
cdadde39 1930#include <xenctrl.h>
e108a3c1 1931#include <xenstore.h>
d5b93ddf
AP
1932#include <stdint.h>
1933#include <xen/hvm/hvm_info_table.h>
1934#if !defined(HVM_MAX_VCPUS)
1935# error HVM_MAX_VCPUS not defined
1936#endif
d8b441a3
JB
1937int main(void) {
1938 xc_interface *xc;
1939 xs_daemon_open();
1940 xc = xc_interface_open(0, 0, 0);
1941 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1942 xc_gnttab_open(NULL, 0);
1943 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
1944 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
1945 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
20a544c7 1946 xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
d8b441a3
JB
1947 return 0;
1948}
1949EOF
c1cdd9d5
JG
1950 compile_prog "" "$xen_libs"
1951 then
1952 xen_ctrl_version=40600
1badb709 1953 xen=enabled
c1cdd9d5
JG
1954
1955 # Xen 4.5
1956 elif
1957 cat > $TMPC <<EOF &&
d8b441a3
JB
1958#include <xenctrl.h>
1959#include <xenstore.h>
1960#include <stdint.h>
1961#include <xen/hvm/hvm_info_table.h>
1962#if !defined(HVM_MAX_VCPUS)
1963# error HVM_MAX_VCPUS not defined
1964#endif
3996e85c
PD
1965int main(void) {
1966 xc_interface *xc;
1967 xs_daemon_open();
1968 xc = xc_interface_open(0, 0, 0);
1969 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1970 xc_gnttab_open(NULL, 0);
1971 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
1972 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
1973 xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
1974 return 0;
1975}
1976EOF
c1cdd9d5
JG
1977 compile_prog "" "$xen_libs"
1978 then
1979 xen_ctrl_version=40500
1badb709 1980 xen=enabled
3996e85c 1981
c1cdd9d5
JG
1982 elif
1983 cat > $TMPC <<EOF &&
3996e85c
PD
1984#include <xenctrl.h>
1985#include <xenstore.h>
1986#include <stdint.h>
1987#include <xen/hvm/hvm_info_table.h>
1988#if !defined(HVM_MAX_VCPUS)
1989# error HVM_MAX_VCPUS not defined
1990#endif
8688e065
SS
1991int main(void) {
1992 xc_interface *xc;
1993 xs_daemon_open();
1994 xc = xc_interface_open(0, 0, 0);
1995 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1996 xc_gnttab_open(NULL, 0);
1997 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
1998 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
1999 return 0;
2000}
2001EOF
c1cdd9d5
JG
2002 compile_prog "" "$xen_libs"
2003 then
2004 xen_ctrl_version=40200
1badb709 2005 xen=enabled
8688e065 2006
c1cdd9d5 2007 else
1badb709 2008 if test "$xen" = "enabled" ; then
c1cdd9d5
JG
2009 feature_not_found "xen (unsupported version)" \
2010 "Install a supported xen (xen 4.2 or newer)"
2011 fi
1badb709 2012 xen=disabled
fc321b4b 2013 fi
d5b93ddf 2014
1badb709 2015 if test "$xen" = enabled; then
c1cdd9d5 2016 if test $xen_ctrl_version -ge 40701 ; then
582ea95f 2017 xen_libs="$xen_libs $xen_stable_libs "
c1cdd9d5 2018 fi
5eeb39c2 2019 fi
d5b93ddf 2020 fi
e37630ca
AL
2021fi
2022
2da776db
MH
2023##########################################
2024# RDMA needs OpenFabrics libraries
2025if test "$rdma" != "no" ; then
2026 cat > $TMPC <<EOF
2027#include <rdma/rdma_cma.h>
2028int main(void) { return 0; }
2029EOF
ef6d4ccd 2030 rdma_libs="-lrdmacm -libverbs -libumad"
2da776db
MH
2031 if compile_prog "" "$rdma_libs" ; then
2032 rdma="yes"
2da776db
MH
2033 else
2034 if test "$rdma" = "yes" ; then
2035 error_exit \
ef6d4ccd 2036 " OpenFabrics librdmacm/libibverbs/libibumad not present." \
2da776db 2037 " Your options:" \
ef6d4ccd 2038 " (1) Fast: Install infiniband packages (devel) from your distro." \
2da776db
MH
2039 " (2) Cleanest: Install libraries from www.openfabrics.org" \
2040 " (3) Also: Install softiwarp if you don't have RDMA hardware"
2041 fi
2042 rdma="no"
2043 fi
2044fi
2045
21ab34c9
MA
2046##########################################
2047# PVRDMA detection
2048
2049cat > $TMPC <<EOF &&
2050#include <sys/mman.h>
2051
2052int
2053main(void)
2054{
2055 char buf = 0;
2056 void *addr = &buf;
2057 addr = mremap(addr, 0, 1, MREMAP_MAYMOVE | MREMAP_FIXED);
2058
2059 return 0;
2060}
2061EOF
2062
2063if test "$rdma" = "yes" ; then
2064 case "$pvrdma" in
2065 "")
2066 if compile_prog "" ""; then
2067 pvrdma="yes"
2068 else
2069 pvrdma="no"
2070 fi
2071 ;;
2072 "yes")
2073 if ! compile_prog "" ""; then
2074 error_exit "PVRDMA is not supported since mremap is not implemented"
2075 fi
2076 pvrdma="yes"
2077 ;;
2078 "no")
2079 pvrdma="no"
2080 ;;
2081 esac
2082else
2083 if test "$pvrdma" = "yes" ; then
2084 error_exit "PVRDMA requires rdma suppport"
2085 fi
2086 pvrdma="no"
2087fi
95c6bff3 2088
ee108585
YS
2089# Let's see if enhanced reg_mr is supported
2090if test "$pvrdma" = "yes" ; then
2091
2092cat > $TMPC <<EOF &&
2093#include <infiniband/verbs.h>
2094
2095int
2096main(void)
2097{
2098 struct ibv_mr *mr;
2099 struct ibv_pd *pd = NULL;
2100 size_t length = 10;
2101 uint64_t iova = 0;
2102 int access = 0;
2103 void *addr = NULL;
2104
2105 mr = ibv_reg_mr_iova(pd, addr, length, iova, access);
2106
2107 ibv_dereg_mr(mr);
2108
2109 return 0;
2110}
2111EOF
2112 if ! compile_prog "" "-libverbs"; then
2113 QEMU_CFLAGS="$QEMU_CFLAGS -DLEGACY_RDMA_REG_MR"
2114 fi
2115fi
2116
e18df141
AL
2117##########################################
2118# glib support probe
a52d28af 2119
b4c6036f 2120glib_req_ver=2.56
aa0d1f44
PB
2121glib_modules=gthread-2.0
2122if test "$modules" = yes; then
a88afc64 2123 glib_modules="$glib_modules gmodule-export-2.0"
b906acac
PB
2124elif test "$plugins" = "yes"; then
2125 glib_modules="$glib_modules gmodule-no-export-2.0"
54cb65d8 2126fi
e26110cf 2127
aa0d1f44 2128for i in $glib_modules; do
e26110cf 2129 if $pkg_config --atleast-version=$glib_req_ver $i; then
89138857
SW
2130 glib_cflags=$($pkg_config --cflags $i)
2131 glib_libs=$($pkg_config --libs $i)
e26110cf
FZ
2132 else
2133 error_exit "glib-$glib_req_ver $i is required to compile QEMU"
2134 fi
2135done
2136
215b0c2f
PB
2137# This workaround is required due to a bug in pkg-config file for glib as it
2138# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
2139
2140if test "$static" = yes && test "$mingw32" = yes; then
2141 glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
2142fi
2143
20cf7b8e
DP
2144if ! test "$gio" = "no"; then
2145 pass=no
2146 if $pkg_config --atleast-version=$glib_req_ver gio-2.0; then
2147 gio_cflags=$($pkg_config --cflags gio-2.0)
2148 gio_libs=$($pkg_config --libs gio-2.0)
2149 gdbus_codegen=$($pkg_config --variable=gdbus_codegen gio-2.0)
5ecfb76c 2150 if ! has "$gdbus_codegen"; then
20cf7b8e
DP
2151 gdbus_codegen=
2152 fi
2153 # Check that the libraries actually work -- Ubuntu 18.04 ships
2154 # with pkg-config --static --libs data for gio-2.0 that is missing
2155 # -lblkid and will give a link error.
2156 cat > $TMPC <<EOF
13ceae66
PM
2157#include <gio/gio.h>
2158int main(void)
2159{
2160 g_dbus_proxy_new_sync(0, 0, 0, 0, 0, 0, 0, 0);
2161 return 0;
2162}
2163EOF
20cf7b8e
DP
2164 if compile_prog "$gio_cflags" "$gio_libs" ; then
2165 pass=yes
2166 else
2167 pass=no
2168 fi
2169
2170 if test "$pass" = "yes" &&
2171 $pkg_config --atleast-version=$glib_req_ver gio-unix-2.0; then
2172 gio_cflags="$gio_cflags $($pkg_config --cflags gio-unix-2.0)"
2173 gio_libs="$gio_libs $($pkg_config --libs gio-unix-2.0)"
2174 fi
76346b62 2175 fi
f876b765 2176
20cf7b8e
DP
2177 if test "$pass" = "no"; then
2178 if test "$gio" = "yes"; then
2179 feature_not_found "gio" "Install libgio >= 2.0"
2180 else
2181 gio=no
2182 fi
2183 else
2184 gio=yes
2185 fi
25a97a56
MAL
2186fi
2187
977a82ab
DB
2188# Sanity check that the current size_t matches the
2189# size that glib thinks it should be. This catches
2190# problems on multi-arch where people try to build
2191# 32-bit QEMU while pointing at 64-bit glib headers
2192cat > $TMPC <<EOF
2193#include <glib.h>
2194#include <unistd.h>
2195
2196#define QEMU_BUILD_BUG_ON(x) \
2197 typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
2198
2199int main(void) {
2200 QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
2201 return 0;
2202}
2203EOF
2204
215b0c2f 2205if ! compile_prog "$glib_cflags" "$glib_libs" ; then
977a82ab
DB
2206 error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
2207 "You probably need to set PKG_CONFIG_LIBDIR"\
2208 "to point to the right pkg-config files for your"\
2209 "build target"
2210fi
2211
9bda600b
EB
2212# Silence clang warnings triggered by glib < 2.57.2
2213cat > $TMPC << EOF
2214#include <glib.h>
2215typedef struct Foo {
2216 int i;
2217} Foo;
2218static void foo_free(Foo *f)
2219{
2220 g_free(f);
2221}
2222G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free);
2223int main(void) { return 0; }
2224EOF
2225if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
2226 if cc_has_warning_flag "-Wno-unused-function"; then
2227 glib_cflags="$glib_cflags -Wno-unused-function"
5770e8af 2228 CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
9bda600b
EB
2229 fi
2230fi
2231
e26110cf
FZ
2232##########################################
2233# SHA command probe for modules
2234if test "$modules" = yes; then
2235 shacmd_probe="sha1sum sha1 shasum"
2236 for c in $shacmd_probe; do
8ccefb91 2237 if has $c; then
e26110cf
FZ
2238 shacmd="$c"
2239 break
2240 fi
2241 done
2242 if test "$shacmd" = ""; then
2243 error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
2244 fi
e18df141
AL
2245fi
2246
f652e6af
AJ
2247##########################################
2248# fdt probe
d599938a 2249
fbb4121d
PB
2250case "$fdt" in
2251 auto | enabled | internal)
2252 # Simpler to always update submodule, even if not needed.
2d652f24 2253 git_submodules="${git_submodules} dtc"
fbb4121d
PB
2254 ;;
2255esac
f652e6af 2256
20ff075b 2257##########################################
9d49bcf6 2258# opengl probe (for sdl2, gtk)
b1546f32 2259
da076ffe 2260if test "$opengl" != "no" ; then
bc6a3565
AO
2261 epoxy=no
2262 if $pkg_config epoxy; then
2263 cat > $TMPC << EOF
2264#include <epoxy/egl.h>
2265int main(void) { return 0; }
2266EOF
2267 if compile_prog "" "" ; then
2268 epoxy=yes
2269 fi
2270 fi
2271
2272 if test "$epoxy" = "yes" ; then
2273 opengl_cflags="$($pkg_config --cflags epoxy)"
2274 opengl_libs="$($pkg_config --libs epoxy)"
da076ffe 2275 opengl=yes
20ff075b 2276 else
da076ffe 2277 if test "$opengl" = "yes" ; then
bc6a3565 2278 feature_not_found "opengl" "Please install epoxy with EGL"
20ff075b 2279 fi
f676c67e 2280 opengl_cflags=""
da076ffe
GH
2281 opengl_libs=""
2282 opengl=no
20ff075b
MW
2283 fi
2284fi
2285
955727d2
CT
2286# check for usbfs
2287have_usbfs=no
2288if test "$linux_user" = "yes"; then
96566d09
TP
2289 cat > $TMPC << EOF
2290#include <linux/usbdevice_fs.h>
2291
2292#ifndef USBDEVFS_GET_CAPABILITIES
2293#error "USBDEVFS_GET_CAPABILITIES undefined"
2294#endif
2295
2296#ifndef USBDEVFS_DISCONNECT_CLAIM
2297#error "USBDEVFS_DISCONNECT_CLAIM undefined"
2298#endif
2299
2300int main(void)
2301{
2302 return 0;
2303}
2304EOF
2305 if compile_prog "" ""; then
955727d2
CT
2306 have_usbfs=yes
2307 fi
955727d2 2308fi
751bcc39 2309
8ca80760
RH
2310##########################################
2311# capstone
2312
e219c499 2313case "$capstone" in
8b18cdbf
RH
2314 auto | enabled | internal)
2315 # Simpler to always update submodule, even if not needed.
2d652f24 2316 git_submodules="${git_submodules} capstone"
e219c499
RH
2317 ;;
2318esac
8ca80760 2319
023367e6 2320##########################################
519175a2 2321# check and set a backend for coroutine
d0e2fce5 2322
7c2acc70 2323# We prefer ucontext, but it's not always possible. The fallback
33c53c54
DB
2324# is sigcontext. On Windows the only valid backend is the Windows
2325# specific one.
7c2acc70
PM
2326
2327ucontext_works=no
2328if test "$darwin" != "yes"; then
2329 cat > $TMPC << EOF
d0e2fce5 2330#include <ucontext.h>
cdf84806
PM
2331#ifdef __stub_makecontext
2332#error Ignoring glibc stub makecontext which will always fail
2333#endif
75cafad7 2334int main(void) { makecontext(0, 0, 0); return 0; }
d0e2fce5 2335EOF
7c2acc70
PM
2336 if compile_prog "" "" ; then
2337 ucontext_works=yes
2338 fi
2339fi
2340
2341if test "$coroutine" = ""; then
2342 if test "$mingw32" = "yes"; then
2343 coroutine=win32
2344 elif test "$ucontext_works" = "yes"; then
2345 coroutine=ucontext
2346 else
2347 coroutine=sigaltstack
d0e2fce5 2348 fi
519175a2 2349else
7c2acc70
PM
2350 case $coroutine in
2351 windows)
2352 if test "$mingw32" != "yes"; then
2353 error_exit "'windows' coroutine backend only valid for Windows"
2354 fi
2355 # Unfortunately the user visible backend name doesn't match the
2356 # coroutine-*.c filename for this case, so we have to adjust it here.
2357 coroutine=win32
2358 ;;
2359 ucontext)
2360 if test "$ucontext_works" != "yes"; then
2361 feature_not_found "ucontext"
2362 fi
2363 ;;
33c53c54 2364 sigaltstack)
7c2acc70
PM
2365 if test "$mingw32" = "yes"; then
2366 error_exit "only the 'windows' coroutine backend is valid for Windows"
2367 fi
2368 ;;
2369 *)
2370 error_exit "unknown coroutine backend $coroutine"
2371 ;;
2372 esac
d0e2fce5
AK
2373fi
2374
1e4f6065
DB
2375##################################################
2376# SafeStack
2377
2378
2379if test "$safe_stack" = "yes"; then
2380cat > $TMPC << EOF
2381int main(int argc, char *argv[])
2382{
2383#if ! __has_feature(safe_stack)
2384#error SafeStack Disabled
2385#endif
2386 return 0;
2387}
2388EOF
2389 flag="-fsanitize=safe-stack"
2390 # Check that safe-stack is supported and enabled.
2391 if compile_prog "-Werror $flag" "$flag"; then
2392 # Flag needed both at compilation and at linking
2393 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2394 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
2395 else
2396 error_exit "SafeStack not supported by your compiler"
2397 fi
2398 if test "$coroutine" != "ucontext"; then
2399 error_exit "SafeStack is only supported by the coroutine backend ucontext"
2400 fi
2401else
2402cat > $TMPC << EOF
2403int main(int argc, char *argv[])
2404{
2405#if defined(__has_feature)
2406#if __has_feature(safe_stack)
2407#error SafeStack Enabled
2408#endif
2409#endif
2410 return 0;
2411}
2412EOF
2413if test "$safe_stack" = "no"; then
2414 # Make sure that safe-stack is disabled
2415 if ! compile_prog "-Werror" ""; then
2416 # SafeStack was already enabled, try to explicitly remove the feature
2417 flag="-fno-sanitize=safe-stack"
2418 if ! compile_prog "-Werror $flag" "$flag"; then
2419 error_exit "Configure cannot disable SafeStack"
2420 fi
2421 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2422 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
2423 fi
2424else # "$safe_stack" = ""
2425 # Set safe_stack to yes or no based on pre-existing flags
2426 if compile_prog "-Werror" ""; then
2427 safe_stack="no"
2428 else
2429 safe_stack="yes"
2430 if test "$coroutine" != "ucontext"; then
2431 error_exit "SafeStack is only supported by the coroutine backend ucontext"
2432 fi
2433 fi
2434fi
2435fi
7d992e4d 2436
f540166b
RH
2437########################################
2438# check if __[u]int128_t is usable.
2439
2440int128=no
2441cat > $TMPC << EOF
2442__int128_t a;
2443__uint128_t b;
2444int main (void) {
2445 a = a + b;
2446 b = a * b;
464e3671 2447 a = a * a;
f540166b
RH
2448 return 0;
2449}
2450EOF
2451if compile_prog "" "" ; then
2452 int128=yes
2453fi
76a347e1 2454
7ebee43e
RH
2455#########################################
2456# See if 128-bit atomic operations are supported.
2457
2458atomic128=no
2459if test "$int128" = "yes"; then
2460 cat > $TMPC << EOF
2461int main(void)
2462{
2463 unsigned __int128 x = 0, y = 0;
bceac547
TH
2464 y = __atomic_load(&x, 0);
2465 __atomic_store(&x, y, 0);
2466 __atomic_compare_exchange(&x, &y, x, 0, 0, 0);
7ebee43e
RH
2467 return 0;
2468}
2469EOF
2470 if compile_prog "" "" ; then
2471 atomic128=yes
2472 fi
2473fi
2474
e6cd4bb5 2475cmpxchg128=no
e633a5c6 2476if test "$int128" = yes && test "$atomic128" = no; then
e6cd4bb5
RH
2477 cat > $TMPC << EOF
2478int main(void)
2479{
2480 unsigned __int128 x = 0, y = 0;
2481 __sync_val_compare_and_swap_16(&x, y, x);
2482 return 0;
2483}
2484EOF
2485 if compile_prog "" "" ; then
2486 cmpxchg128=yes
2487 fi
2488fi
2489
fd0e6053
JS
2490########################################
2491# check if ccache is interfering with
2492# semantic analysis of macros
2493
5e4dfd3d 2494unset CCACHE_CPP2
fd0e6053
JS
2495ccache_cpp2=no
2496cat > $TMPC << EOF
2497static const int Z = 1;
2498#define fn() ({ Z; })
2499#define TAUT(X) ((X) == Z)
2500#define PAREN(X, Y) (X == Y)
2501#define ID(X) (X)
2502int main(int argc, char *argv[])
2503{
2504 int x = 0, y = 0;
2505 x = ID(x);
2506 x = fn();
2507 fn();
2508 if (PAREN(x, y)) return 0;
2509 if (TAUT(Z)) return 0;
2510 return 0;
2511}
2512EOF
2513
2514if ! compile_object "-Werror"; then
2515 ccache_cpp2=yes
2516fi
2517
b553a042
JS
2518#################################################
2519# clang does not support glibc + FORTIFY_SOURCE.
2520
2521if test "$fortify_source" != "no"; then
2522 if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
2523 fortify_source="no";
e189091f 2524 elif test -n "$cxx" && has $cxx &&
cfcc7c14 2525 echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
b553a042
JS
2526 fortify_source="no";
2527 else
2528 fortify_source="yes"
2529 fi
2530fi
2531
247724cb
MAL
2532##########################################
2533# checks for sanitizers
2534
247724cb
MAL
2535have_asan=no
2536have_ubsan=no
d83414e1
MAL
2537have_asan_iface_h=no
2538have_asan_iface_fiber=no
247724cb
MAL
2539
2540if test "$sanitizers" = "yes" ; then
b9f44da2 2541 write_c_skeleton
247724cb
MAL
2542 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
2543 have_asan=yes
2544 fi
b9f44da2
MAL
2545
2546 # we could use a simple skeleton for flags checks, but this also
2547 # detect the static linking issue of ubsan, see also:
2548 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
2549 cat > $TMPC << EOF
2550#include <stdlib.h>
2551int main(void) {
2552 void *tmp = malloc(10);
f2dfe54c
LB
2553 if (tmp != NULL) {
2554 return *(int *)(tmp + 2);
2555 }
d1abf3fc 2556 return 1;
b9f44da2
MAL
2557}
2558EOF
247724cb
MAL
2559 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
2560 have_ubsan=yes
2561 fi
d83414e1
MAL
2562
2563 if check_include "sanitizer/asan_interface.h" ; then
2564 have_asan_iface_h=yes
2565 fi
2566
2567 cat > $TMPC << EOF
2568#include <sanitizer/asan_interface.h>
2569int main(void) {
2570 __sanitizer_start_switch_fiber(0, 0, 0);
2571 return 0;
2572}
2573EOF
2574 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
2575 have_asan_iface_fiber=yes
2576 fi
247724cb
MAL
2577fi
2578
0aebab04
LY
2579# Thread sanitizer is, for now, much noisier than the other sanitizers;
2580# keep it separate until that is not the case.
2581if test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
2582 error_exit "TSAN is not supported with other sanitiziers."
2583fi
2584have_tsan=no
2585have_tsan_iface_fiber=no
2586if test "$tsan" = "yes" ; then
2587 write_c_skeleton
2588 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
2589 have_tsan=yes
2590 fi
2591 cat > $TMPC << EOF
2592#include <sanitizer/tsan_interface.h>
2593int main(void) {
2594 __tsan_create_fiber(0);
2595 return 0;
2596}
2597EOF
2598 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
2599 have_tsan_iface_fiber=yes
2600 fi
2601fi
2602
675b9b53
MAL
2603##########################################
2604# check for slirp
2605
2606case "$slirp" in
4d34a86b
PB
2607 auto | enabled | internal)
2608 # Simpler to always update submodule, even if not needed.
2d652f24 2609 git_submodules="${git_submodules} slirp"
675b9b53
MAL
2610 ;;
2611esac
2612
54e7aac0
AK
2613##########################################
2614# check for usable __NR_keyctl syscall
2615
2616if test "$linux" = "yes" ; then
2617
2618 have_keyring=no
2619 cat > $TMPC << EOF
2620#include <errno.h>
2621#include <asm/unistd.h>
2622#include <linux/keyctl.h>
2623#include <unistd.h>
2624int main(void) {
2625 return syscall(__NR_keyctl, KEYCTL_READ, 0, NULL, NULL, 0);
2626}
2627EOF
2628 if compile_prog "" "" ; then
2629 have_keyring=yes
2630 fi
2631fi
2632if test "$secret_keyring" != "no"
2633then
b418d265 2634 if test "$have_keyring" = "yes"
54e7aac0
AK
2635 then
2636 secret_keyring=yes
2637 else
2638 if test "$secret_keyring" = "yes"
2639 then
2640 error_exit "syscall __NR_keyctl requested, \
2641but not implemented on your system"
2642 else
2643 secret_keyring=no
2644 fi
2645 fi
2646fi
2647
7e24e92a 2648##########################################
e86ecd4b
JQ
2649# End of CC checks
2650# After here, no more $cc or $ld runs
2651
d83414e1
MAL
2652write_c_skeleton
2653
1d728c39 2654if test "$gcov" = "yes" ; then
bf0e56a3 2655 :
b553a042 2656elif test "$fortify_source" = "yes" ; then
086d5f75
PB
2657 QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
2658 debug=no
2659fi
086d5f75
PB
2660
2661case "$ARCH" in
2662alpha)
2663 # Ensure there's only a single GP
2664 QEMU_CFLAGS="-msmall-data $QEMU_CFLAGS"
2665;;
2666esac
2667
247724cb 2668if test "$have_asan" = "yes"; then
db5adeaa
PB
2669 QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
2670 QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
d83414e1
MAL
2671 if test "$have_asan_iface_h" = "no" ; then
2672 echo "ASAN build enabled, but ASAN header missing." \
2673 "Without code annotation, the report may be inferior."
2674 elif test "$have_asan_iface_fiber" = "no" ; then
2675 echo "ASAN build enabled, but ASAN header is too old." \
2676 "Without code annotation, the report may be inferior."
2677 fi
247724cb 2678fi
0aebab04
LY
2679if test "$have_tsan" = "yes" ; then
2680 if test "$have_tsan_iface_fiber" = "yes" ; then
2681 QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
2682 QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
2683 else
2684 error_exit "Cannot enable TSAN due to missing fiber annotation interface."
2685 fi
2686elif test "$tsan" = "yes" ; then
2687 error_exit "Cannot enable TSAN due to missing sanitize thread interface."
2688fi
247724cb 2689if test "$have_ubsan" = "yes"; then
db5adeaa
PB
2690 QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
2691 QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
247724cb
MAL
2692fi
2693
3efac6eb 2694##########################################
3efac6eb 2695
0aebab04
LY
2696# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
2697if test "$solaris" = "no" && test "$tsan" = "no"; then
e86ecd4b 2698 if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
db5adeaa 2699 QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
e86ecd4b
JQ
2700 fi
2701fi
2702
952afb71
BS
2703# Use ASLR, no-SEH and DEP if available
2704if test "$mingw32" = "yes" ; then
cb8baa77
MCA
2705 flags="--no-seh --nxcompat"
2706
2707 # Disable ASLR for debug builds to allow debugging with gdb
2708 if test "$debug" = "no" ; then
2709 flags="--dynamicbase $flags"
2710 fi
2711
2712 for flag in $flags; do
e9a3591f 2713 if ld_has $flag ; then
db5adeaa 2714 QEMU_LDFLAGS="-Wl,$flag $QEMU_LDFLAGS"
952afb71
BS
2715 fi
2716 done
2717fi
2718
b846ab7c 2719# Guest agent Windows MSI package
9d6bc27b 2720
b846ab7c
PB
2721if test "$QEMU_GA_MANUFACTURER" = ""; then
2722 QEMU_GA_MANUFACTURER=QEMU
9d6bc27b 2723fi
b846ab7c
PB
2724if test "$QEMU_GA_DISTRO" = ""; then
2725 QEMU_GA_DISTRO=Linux
9d6bc27b 2726fi
b846ab7c
PB
2727if test "$QEMU_GA_VERSION" = ""; then
2728 QEMU_GA_VERSION=$(cat $source_path/VERSION)
2729fi
2730
2731QEMU_GA_MSI_MINGW_DLL_PATH="$($pkg_config --variable=prefix glib-2.0)/bin"
9d6bc27b 2732
ca35f780
PB
2733# Mac OS X ships with a broken assembler
2734roms=
e633a5c6 2735if { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \
ba7c60c2
PB
2736 test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
2737 test "$targetos" != "haiku" && test "$softmmu" = yes ; then
e57218b6 2738 # Different host OS linkers have different ideas about the name of the ELF
c65d5e4e
BS
2739 # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
2740 # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
2741 for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
e57218b6
PM
2742 if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
2743 ld_i386_emulation="$emu"
2744 roms="optionrom"
2745 break
2746 fi
2747 done
ca35f780 2748fi
ca35f780 2749
2e33c3f8 2750# Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
a5b2afd5 2751# or -march=z10 (which is the lowest architecture level that Clang supports)
9933c305 2752if test "$cpu" = "s390x" ; then
2e33c3f8 2753 write_c_skeleton
a5b2afd5
TH
2754 compile_prog "-march=z900" ""
2755 has_z900=$?
3af448b3 2756 if [ $has_z900 = 0 ] || compile_object "-march=z10 -msoft-float -Werror"; then
a5b2afd5
TH
2757 if [ $has_z900 != 0 ]; then
2758 echo "WARNING: Your compiler does not support the z900!"
2759 echo " The s390-ccw bios will only work with guest CPUs >= z10."
2760 fi
2e33c3f8 2761 roms="$roms s390-ccw"
1ef6bfc2
PMD
2762 # SLOF is required for building the s390-ccw firmware on s390x,
2763 # since it is using the libnet code from SLOF for network booting.
2d652f24 2764 git_submodules="${git_submodules} roms/SLOF"
2e33c3f8 2765 fi
9933c305
CB
2766fi
2767
11cde1c8
BD
2768# Check that the C++ compiler exists and works with the C compiler.
2769# All the QEMU_CXXFLAGS are based on QEMU_CFLAGS. Keep this at the end to don't miss any other that could be added.
2770if has $cxx; then
2771 cat > $TMPC <<EOF
2772int c_function(void);
2773int main(void) { return c_function(); }
2774EOF
2775
2776 compile_object
2777
2778 cat > $TMPCXX <<EOF
2779extern "C" {
2780 int c_function(void);
2781}
2782int c_function(void) { return 42; }
2783EOF
2784
2785 update_cxxflags
2786
a2866660 2787 if do_cxx $CXXFLAGS $EXTRA_CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
11cde1c8
BD
2788 # C++ compiler $cxx works ok with C compiler $cc
2789 :
2790 else
2791 echo "C++ compiler $cxx does not work with C compiler $cc"
2792 echo "Disabling C++ specific optional code"
2793 cxx=
2794 fi
2795else
2796 echo "No C++ compiler available; disabling C++ specific optional code"
2797 cxx=
2798fi
2799
7d7dbf9d
DS
2800if !(GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
2801 exit 1
5d91a2ed 2802fi
5d91a2ed 2803
98ec69ac 2804config_host_mak="config-host.mak"
98ec69ac 2805
98ec69ac 2806echo "# Automatically generated by configure - do not modify" > $config_host_mak
98ec69ac 2807echo >> $config_host_mak
98ec69ac 2808
e6c3b0f7 2809echo all: >> $config_host_mak
cc84d63a 2810echo "GIT=$git" >> $config_host_mak
aef45d51 2811echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
7d7dbf9d 2812echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
804edf29 2813
f8393946 2814if test "$debug_tcg" = "yes" ; then
2358a494 2815 echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
f8393946 2816fi
67b915a5 2817if test "$mingw32" = "yes" ; then
98ec69ac 2818 echo "CONFIG_WIN32=y" >> $config_host_mak
b846ab7c
PB
2819 echo "QEMU_GA_MSI_MINGW_DLL_PATH=${QEMU_GA_MSI_MINGW_DLL_PATH}" >> $config_host_mak
2820 echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
2821 echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
2822 echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
210fa556 2823else
35f4df27 2824 echo "CONFIG_POSIX=y" >> $config_host_mak
dffcb71c
MM
2825fi
2826
2827if test "$linux" = "yes" ; then
2828 echo "CONFIG_LINUX=y" >> $config_host_mak
67b915a5 2829fi
128ab2ff 2830
83fb7adf 2831if test "$darwin" = "yes" ; then
98ec69ac 2832 echo "CONFIG_DARWIN=y" >> $config_host_mak
83fb7adf 2833fi
b29fe3ed 2834
ec530c81 2835if test "$solaris" = "yes" ; then
98ec69ac 2836 echo "CONFIG_SOLARIS=y" >> $config_host_mak
ec530c81 2837fi
97a847bc 2838if test "$static" = "yes" ; then
98ec69ac 2839 echo "CONFIG_STATIC=y" >> $config_host_mak
7d13299d 2840fi
b64ec4e4
FZ
2841echo "CONFIG_BDRV_RW_WHITELIST=$block_drv_rw_whitelist" >> $config_host_mak
2842echo "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
89138857 2843qemu_version=$(head $source_path/VERSION)
2358a494 2844echo "PKGVERSION=$pkgversion" >>$config_host_mak
98ec69ac 2845echo "SRC_PATH=$source_path" >> $config_host_mak
2b1f35b9 2846echo "TARGET_DIRS=$target_list" >> $config_host_mak
17969268 2847if test "$modules" = "yes"; then
e26110cf
FZ
2848 # $shacmd can generate a hash started with digit, which the compiler doesn't
2849 # like as an symbol. So prefix it with an underscore
89138857 2850 echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
17969268
FZ
2851 echo "CONFIG_MODULES=y" >> $config_host_mak
2852fi
bd83c861
CE
2853if test "$module_upgrades" = "yes"; then
2854 echo "CONFIG_MODULE_UPGRADES=y" >> $config_host_mak
2855fi
955727d2
CT
2856if test "$have_usbfs" = "yes" ; then
2857 echo "CONFIG_USBFS=y" >> $config_host_mak
2858fi
f876b765
MAL
2859if test "$gio" = "yes" ; then
2860 echo "CONFIG_GIO=y" >> $config_host_mak
2861 echo "GIO_CFLAGS=$gio_cflags" >> $config_host_mak
2862 echo "GIO_LIBS=$gio_libs" >> $config_host_mak
5ecfb76c
PB
2863fi
2864if test "$gdbus_codegen" != "" ; then
25a97a56 2865 echo "GDBUS_CODEGEN=$gdbus_codegen" >> $config_host_mak
f876b765 2866fi
a1c5e949 2867echo "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak
277abf15 2868
1badb709 2869if test "$xen" = "enabled" ; then
6dbd588a 2870 echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
d5b93ddf 2871 echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
582ea95f
MAL
2872 echo "XEN_CFLAGS=$xen_cflags" >> $config_host_mak
2873 echo "XEN_LIBS=$xen_libs" >> $config_host_mak
e37630ca 2874fi
5e9be92d
NB
2875if test "$vhost_scsi" = "yes" ; then
2876 echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
2877fi
af3bba76
PB
2878if test "$vhost_net" = "yes" ; then
2879 echo "CONFIG_VHOST_NET=y" >> $config_host_mak
2880fi
2881if test "$vhost_net_user" = "yes" ; then
56f41de7 2882 echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak
03ce5744 2883fi
108a6481
CL
2884if test "$vhost_net_vdpa" = "yes" ; then
2885 echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak
2886fi
042cea27
GA
2887if test "$vhost_crypto" = "yes" ; then
2888 echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
2889fi
fc0b9b0e
SH
2890if test "$vhost_vsock" = "yes" ; then
2891 echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
5fe97d88
SG
2892 if test "$vhost_user" = "yes" ; then
2893 echo "CONFIG_VHOST_USER_VSOCK=y" >> $config_host_mak
2894 fi
fc0b9b0e 2895fi
299e6f19
PB
2896if test "$vhost_kernel" = "yes" ; then
2897 echo "CONFIG_VHOST_KERNEL=y" >> $config_host_mak
2898fi
e6a74868
MAL
2899if test "$vhost_user" = "yes" ; then
2900 echo "CONFIG_VHOST_USER=y" >> $config_host_mak
2901fi
108a6481
CL
2902if test "$vhost_vdpa" = "yes" ; then
2903 echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
2904fi
98fc1ada
DDAG
2905if test "$vhost_user_fs" = "yes" ; then
2906 echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak
2907fi
e5b46549
RH
2908if test "$tcg" = "enabled" -a "$tcg_interpreter" = "true" ; then
2909 echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
2910fi
58d3f3ff 2911
da076ffe
GH
2912if test "$opengl" = "yes" ; then
2913 echo "CONFIG_OPENGL=y" >> $config_host_mak
de2d3005 2914 echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
da076ffe 2915 echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
20ff075b
MW
2916fi
2917
83fb7adf 2918# XXX: suppress that
7d3505c5 2919if [ "$bsd" = "yes" ] ; then
2358a494 2920 echo "CONFIG_BSD=y" >> $config_host_mak
7d3505c5
FB
2921fi
2922
7c2acc70 2923echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
7d992e4d 2924
d83414e1
MAL
2925if test "$have_asan_iface_fiber" = "yes" ; then
2926 echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
2927fi
2928
0aebab04
LY
2929if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
2930 echo "CONFIG_TSAN=y" >> $config_host_mak
2931fi
2932
f540166b
RH
2933if test "$int128" = "yes" ; then
2934 echo "CONFIG_INT128=y" >> $config_host_mak
2935fi
2936
7ebee43e
RH
2937if test "$atomic128" = "yes" ; then
2938 echo "CONFIG_ATOMIC128=y" >> $config_host_mak
2939fi
2940
e6cd4bb5
RH
2941if test "$cmpxchg128" = "yes" ; then
2942 echo "CONFIG_CMPXCHG128=y" >> $config_host_mak
2943fi
2944
2da776db
MH
2945if test "$rdma" = "yes" ; then
2946 echo "CONFIG_RDMA=y" >> $config_host_mak
392fb643 2947 echo "RDMA_LIBS=$rdma_libs" >> $config_host_mak
2da776db
MH
2948fi
2949
21ab34c9
MA
2950if test "$pvrdma" = "yes" ; then
2951 echo "CONFIG_PVRDMA=y" >> $config_host_mak
2952fi
2953
40e8c6f4
AB
2954if test "$plugins" = "yes" ; then
2955 echo "CONFIG_PLUGIN=y" >> $config_host_mak
40e8c6f4
AB
2956fi
2957
b1863ccc
AB
2958if test -n "$gdb_bin"; then
2959 gdb_version=$($gdb_bin --version | head -n 1)
d6a66c81 2960 if version_ge ${gdb_version##* } 9.1; then
b1863ccc
AB
2961 echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
2962 fi
f48e590a
AB
2963fi
2964
54e7aac0
AK
2965if test "$secret_keyring" = "yes" ; then
2966 echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak
2967fi
2968
98ec69ac 2969echo "ROMS=$roms" >> $config_host_mak
804edf29 2970echo "MAKE=$make" >> $config_host_mak
c886edfb 2971echo "PYTHON=$python" >> $config_host_mak
39d87c8c 2972echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
a5665051 2973echo "MESON=$meson" >> $config_host_mak
09e93326 2974echo "NINJA=$ninja" >> $config_host_mak
804edf29 2975echo "CC=$cc" >> $config_host_mak
433de74c 2976echo "HOST_CC=$host_cc" >> $config_host_mak
804edf29 2977echo "AR=$ar" >> $config_host_mak
cdbd727c 2978echo "AS=$as" >> $config_host_mak
5f6f0e27 2979echo "CCAS=$ccas" >> $config_host_mak
3dd46c78 2980echo "CPP=$cpp" >> $config_host_mak
804edf29
JQ
2981echo "OBJCOPY=$objcopy" >> $config_host_mak
2982echo "LD=$ld" >> $config_host_mak
46eef33b 2983echo "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
a558ee17 2984echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
11cde1c8 2985echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
a81df1b6
PB
2986echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
2987echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
d83acfd0 2988echo "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak
8a99e9a3 2989echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
e57218b6 2990echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
a70248db 2991echo "STRIP=$strip" >> $config_host_mak
804edf29 2992echo "EXESUF=$EXESUF" >> $config_host_mak
804edf29 2993
6efd7517
PM
2994# use included Linux headers
2995if test "$linux" = "yes" ; then
a307beb6 2996 mkdir -p linux-headers
6efd7517 2997 case "$cpu" in
4da270be 2998 i386|x86_64)
08312a63 2999 linux_arch=x86
6efd7517 3000 ;;
d8ff892d 3001 ppc|ppc64)
08312a63 3002 linux_arch=powerpc
6efd7517
PM
3003 ;;
3004 s390x)
08312a63
PM
3005 linux_arch=s390
3006 ;;
1f080313
CF
3007 aarch64)
3008 linux_arch=arm64
3009 ;;
dfcf900b
WX
3010 loongarch*)
3011 linux_arch=loongarch
3012 ;;
222e7d11
SL
3013 mips64)
3014 linux_arch=mips
3015 ;;
08312a63
PM
3016 *)
3017 # For most CPUs the kernel architecture name and QEMU CPU name match.
3018 linux_arch="$cpu"
6efd7517
PM
3019 ;;
3020 esac
08312a63
PM
3021 # For non-KVM architectures we will not have asm headers
3022 if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
3023 symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
3024 fi
6efd7517
PM
3025fi
3026
1d14ffa9 3027for target in $target_list; do
fdb75aef 3028 target_dir="$target"
57a93f16 3029 target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
fdb75aef
PB
3030 mkdir -p $target_dir
3031 case $target in
3032 *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
3033 *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
3034 esac
3035done
7d13299d 3036
765686d6 3037echo "CONFIG_QEMU_INTERP_PREFIX=$interp_prefix" | sed 's/%M/@0@/' >> $config_host_mak
fdb75aef
PB
3038if test "$default_targets" = "yes"; then
3039 echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
3040fi
a540f158 3041
fd0e6053
JS
3042if test "$ccache_cpp2" = "yes"; then
3043 echo "export CCACHE_CPP2=y" >> $config_host_mak
3044fi
3045
1e4f6065
DB
3046if test "$safe_stack" = "yes"; then
3047 echo "CONFIG_SAFESTACK=y" >> $config_host_mak
3048fi
3049
e29e5c6e 3050# If we're using a separate build tree, set it up now.
e29e5c6e
PM
3051# LINKS are things to symlink back into the source tree
3052# (these can be both files and directories).
3053# Caution: do not add files or directories here using wildcards. This
3054# will result in problems later if a new file matching the wildcard is
3055# added to the source tree -- nothing will cause configure to be rerun
3056# so the build tree will be missing the link back to the new file, and
3057# tests might fail. Prefer to keep the relevant files in their own
3058# directory and symlink the directory instead.
2038f8c8 3059LINKS="Makefile"
3941996b 3060LINKS="$LINKS tests/tcg/Makefile.target"
ddcf607f 3061LINKS="$LINKS pc-bios/optionrom/Makefile"
e29e5c6e 3062LINKS="$LINKS pc-bios/s390-ccw/Makefile"
8db2a4fd 3063LINKS="$LINKS roms/seabios/Makefile"
e29e5c6e
PM
3064LINKS="$LINKS pc-bios/qemu-icon.bmp"
3065LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
bbbd9b6e 3066LINKS="$LINKS tests/avocado tests/data"
39950353 3067LINKS="$LINKS tests/qemu-iotests/check"
8f8fd9ed 3068LINKS="$LINKS python"
c17a386b 3069LINKS="$LINKS contrib/plugins/Makefile "
753d11f2
RH
3070for bios_file in \
3071 $source_path/pc-bios/*.bin \
3a631b8e 3072 $source_path/pc-bios/*.elf \
225a9ab8 3073 $source_path/pc-bios/*.lid \
753d11f2
RH
3074 $source_path/pc-bios/*.rom \
3075 $source_path/pc-bios/*.dtb \
e89e33e1 3076 $source_path/pc-bios/*.img \
753d11f2 3077 $source_path/pc-bios/openbios-* \
4e73c781 3078 $source_path/pc-bios/u-boot.* \
cd946e5c
JA
3079 $source_path/pc-bios/palcode-* \
3080 $source_path/pc-bios/qemu_vga.ndrv
3081
753d11f2 3082do
e29e5c6e 3083 LINKS="$LINKS pc-bios/$(basename $bios_file)"
d1807a4f 3084done
e29e5c6e 3085for f in $LINKS ; do
0f4d8894 3086 if [ -e "$source_path/$f" ]; then
5dce7b8d 3087 mkdir -p `dirname ./$f`
f9245e10
PM
3088 symlink "$source_path/$f" "$f"
3089 fi
d1807a4f 3090done
1ad2134f 3091
2038f8c8
PB
3092(for i in $cross_cc_vars; do
3093 export $i
3094done
fd0f79d7 3095export target_list source_path use_containers cpu
2038f8c8
PB
3096$source_path/tests/tcg/configure.sh)
3097
c34ebfdc 3098# temporary config to build submodules
bb7cb3ad
PB
3099if test -f $source_path/roms/seabios/Makefile; then
3100 for rom in seabios; do
c34ebfdc 3101 config_mak=roms/$rom/config.mak
37116c89 3102 echo "# Automatically generated by configure - do not modify" > $config_mak
c34ebfdc 3103 echo "SRC_PATH=$source_path/roms/$rom" >> $config_mak
cdbd727c 3104 echo "AS=$as" >> $config_mak
5f6f0e27 3105 echo "CCAS=$ccas" >> $config_mak
c34ebfdc
AL
3106 echo "CC=$cc" >> $config_mak
3107 echo "BCC=bcc" >> $config_mak
3dd46c78 3108 echo "CPP=$cpp" >> $config_mak
c34ebfdc 3109 echo "OBJCOPY=objcopy" >> $config_mak
a31a8642 3110 echo "IASL=$iasl" >> $config_mak
c34ebfdc 3111 echo "LD=$ld" >> $config_mak
9f81aeb5 3112 echo "RANLIB=$ranlib" >> $config_mak
bb7cb3ad
PB
3113 done
3114fi
c34ebfdc 3115
98409991
HK
3116config_mak=pc-bios/optionrom/config.mak
3117echo "# Automatically generated by configure - do not modify" > $config_mak
3118echo "TOPSRC_DIR=$source_path" >> $config_mak
3119
a5665051 3120if test "$skip_meson" = no; then
d77e90fa
PB
3121 cross="config-meson.cross.new"
3122 meson_quote() {
ac7ebcc5 3123 test $# = 0 && return
47b30835 3124 echo "'$(echo $* | sed "s/ /','/g")'"
d77e90fa
PB
3125 }
3126
3127 echo "# Automatically generated by configure - do not modify" > $cross
3128 echo "[properties]" >> $cross
d1d5e9ee
AB
3129
3130 # unroll any custom device configs
11bdcfcd
AB
3131 for a in $device_archs; do
3132 eval "c=\$devices_${a}"
3133 echo "${a}-softmmu = '$c'" >> $cross
3134 done
d1d5e9ee 3135
d77e90fa
PB
3136 test -z "$cxx" && echo "link_language = 'c'" >> $cross
3137 echo "[built-in options]" >> $cross
a2866660
PB
3138 echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
3139 echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
3140 echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
3141 echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
d77e90fa 3142 echo "[binaries]" >> $cross
4dba2789
PB
3143 echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
3144 test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
3145 test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
d77e90fa
PB
3146 echo "ar = [$(meson_quote $ar)]" >> $cross
3147 echo "nm = [$(meson_quote $nm)]" >> $cross
3148 echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
3149 echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
3150 if has $sdl2_config; then
3151 echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
3152 fi
3153 echo "strip = [$(meson_quote $strip)]" >> $cross
3154 echo "windres = [$(meson_quote $windres)]" >> $cross
3155 if test "$cross_compile" = "yes"; then
fc929892 3156 cross_arg="--cross-file config-meson.cross"
fc929892 3157 echo "[host_machine]" >> $cross
ba7c60c2 3158 echo "system = '$targetos'" >> $cross
823eb013 3159 case "$cpu" in
f6bca9df 3160 i386)
fc929892
MAL
3161 echo "cpu_family = 'x86'" >> $cross
3162 ;;
fc929892 3163 *)
823eb013 3164 echo "cpu_family = '$cpu'" >> $cross
fc929892
MAL
3165 ;;
3166 esac
3167 echo "cpu = '$cpu'" >> $cross
3168 if test "$bigendian" = "yes" ; then
3169 echo "endian = 'big'" >> $cross
3170 else
3171 echo "endian = 'little'" >> $cross
3172 fi
d77e90fa 3173 else
fc929892 3174 cross_arg="--native-file config-meson.cross"
d77e90fa
PB
3175 fi
3176 mv $cross config-meson.cross
fc929892 3177
d77e90fa 3178 rm -rf meson-private meson-info meson-logs
61d63097
PB
3179 run_meson() {
3180 NINJA=$ninja $meson setup \
d17f305a
PB
3181 --prefix "$prefix" \
3182 --libdir "$libdir" \
3183 --libexecdir "$libexecdir" \
3184 --bindir "$bindir" \
3185 --includedir "$includedir" \
3186 --datadir "$datadir" \
3187 --mandir "$mandir" \
3188 --sysconfdir "$sysconfdir" \
16bf7a33 3189 --localedir "$localedir" \
d17f305a 3190 --localstatedir "$local_statedir" \
3b4da132
PB
3191 -Daudio_drv_list=$audio_drv_list \
3192 -Ddefault_devices=$default_devices \
d17f305a 3193 -Ddocdir="$docdir" \
5dc4618e 3194 -Diasl="$($iasl -h >/dev/null 2>&1 && printf %s "$iasl")" \
16bf7a33 3195 -Dqemu_firmwarepath="$firmwarepath" \
73f3aa37 3196 -Dqemu_suffix="$qemu_suffix" \
35acbb30 3197 -Dsmbd="$smbd" \
3b4da132
PB
3198 -Dsphinx_build="$sphinx_build" \
3199 -Dtrace_file="$trace_file" \
a5665051
PB
3200 -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) \
3201 -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo false; fi) \
3202 -Dwerror=$(if test "$werror" = yes; then echo true; else echo false; fi) \
da6d48b9 3203 -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \
bf0e56a3 3204 -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
3b4da132
PB
3205 -Db_lto=$lto -Dcfi=$cfi -Dtcg=$tcg -Dxen=$xen \
3206 -Dcapstone=$capstone -Dfdt=$fdt -Dslirp=$slirp \
537b7248 3207 $(test -n "${LIB_FUZZING_ENGINE+xxx}" && echo "-Dfuzzing_engine=$LIB_FUZZING_ENGINE") \
332008e0 3208 $(if test "$default_feature" = no; then echo "-Dauto_features=disabled"; fi) \
61d63097
PB
3209 "$@" $cross_arg "$PWD" "$source_path"
3210 }
3211 eval run_meson $meson_options
d77e90fa
PB
3212 if test "$?" -ne 0 ; then
3213 error_exit "meson setup failed"
3214 fi
699d3884
PB
3215else
3216 if test -f meson-private/cmd_line.txt; then
3217 # Adjust old command line options whose type was changed
3218 # Avoids having to use "setup --wipe" when Meson is upgraded
3219 perl -i -ne '
3220 s/^gettext = true$/gettext = auto/;
3221 s/^gettext = false$/gettext = disabled/;
654d6b04 3222 /^b_staticpic/ && next;
699d3884
PB
3223 print;' meson-private/cmd_line.txt
3224 fi
a5665051
PB
3225fi
3226
dc655404
MT
3227# Save the configure command line for later reuse.
3228cat <<EOD >config.status
3229#!/bin/sh
3230# Generated by configure.
3231# Run this file to recreate the current configuration.
3232# Compiler output produced by configure, useful for debugging
3233# configure, is in config.log if it exists.
3234EOD
e811da7f
DB
3235
3236preserve_env() {
3237 envname=$1
3238
3239 eval envval=\$$envname
3240
3241 if test -n "$envval"
3242 then
3243 echo "$envname='$envval'" >> config.status
3244 echo "export $envname" >> config.status
3245 else
3246 echo "unset $envname" >> config.status
3247 fi
3248}
3249
3250# Preserve various env variables that influence what
3251# features/build target configure will detect
3252preserve_env AR
3253preserve_env AS
3254preserve_env CC
3255preserve_env CPP
8009da03 3256preserve_env CFLAGS
e811da7f 3257preserve_env CXX
8009da03 3258preserve_env CXXFLAGS
e811da7f
DB
3259preserve_env INSTALL
3260preserve_env LD
8009da03 3261preserve_env LDFLAGS
e811da7f
DB
3262preserve_env LD_LIBRARY_PATH
3263preserve_env LIBTOOL
3264preserve_env MAKE
3265preserve_env NM
3266preserve_env OBJCOPY
3267preserve_env PATH
3268preserve_env PKG_CONFIG
3269preserve_env PKG_CONFIG_LIBDIR
3270preserve_env PKG_CONFIG_PATH
3271preserve_env PYTHON
e811da7f
DB
3272preserve_env SDL2_CONFIG
3273preserve_env SMBD
3274preserve_env STRIP
3275preserve_env WINDRES
3276
dc655404 3277printf "exec" >>config.status
a5665051 3278for i in "$0" "$@"; do
835af899 3279 test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
a5665051 3280done
cf7cc929 3281echo ' "$@"' >>config.status
dc655404
MT
3282chmod +x config.status
3283
8cd05ab6 3284rm -r "$TMPDIR1"