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