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