net/vhost-user: Fix device compatibility check
[qemu.git] / configure
blob039467c04b16d142d38affdc3f9701d190588197
1 #!/bin/sh
3 # qemu configure script (c) 2003 Fabrice Bellard
6 # Unset some variables known to interfere with behavior of common tools,
7 # just as autoconf does.
8 CLICOLOR_FORCE= GREP_OPTIONS=
9 unset CLICOLOR_FORCE GREP_OPTIONS
11 # Don't allow CCACHE, if present, to use cached results of compile tests!
12 export CCACHE_RECACHE=yes
14 # make source path absolute
15 source_path=$(cd "$(dirname -- "$0")"; pwd)
17 if test "$PWD" = "$source_path"
18 then
19 echo "Using './build' as the directory for build output"
21 MARKER=build/auto-created-by-configure
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
34 mkdir build
35 touch $MARKER
37 cat > GNUmakefile <<'EOF'
38 # This file is auto-generated by configure to support in-source tree
39 # 'make' command invocation
41 ifeq ($(MAKECMDGOALS),)
42 recurse: all
43 endif
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 ; \
54 force: ;
55 .PHONY: force
56 GNUmakefile: ;
58 EOF
59 cd build
60 exec $source_path/configure "$@"
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.)
68 TMPDIR1="config-temp"
69 rm -rf "${TMPDIR1}"
70 mkdir -p "${TMPDIR1}"
71 if [ $? -ne 0 ]; then
72 echo "ERROR: failed to create temporary directory"
73 exit 1
76 TMPB="qemu-conf"
77 TMPC="${TMPDIR1}/${TMPB}.c"
78 TMPO="${TMPDIR1}/${TMPB}.o"
79 TMPCXX="${TMPDIR1}/${TMPB}.cxx"
80 TMPE="${TMPDIR1}/${TMPB}.exe"
81 TMPTXT="${TMPDIR1}/${TMPB}.txt"
83 rm -f config.log
85 # Print a helpful header at the top of config.log
86 echo "# QEMU configure log $(date)" >> config.log
87 printf "# Configured with:" >> config.log
88 printf " '%s'" "$0" "$@" >> config.log
89 echo >> config.log
90 echo "#" >> config.log
92 quote_sh() {
93 printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
96 print_error() {
97 (echo
98 echo "ERROR: $1"
99 while test -n "$2"; do
100 echo " $2"
101 shift
102 done
103 echo) >&2
106 error_exit() {
107 print_error "$@"
108 exit 1
111 do_compiler() {
112 # Run the compiler, capturing its output to the log. First argument
113 # is compiler binary to execute.
114 compiler="$1"
115 shift
116 if test -n "$BASH_VERSION"; then eval '
117 echo >>config.log "
118 funcs: ${FUNCNAME[*]}
119 lines: ${BASH_LINENO[*]}"
120 '; fi
121 echo $compiler "$@" >> config.log
122 $compiler "$@" >> config.log 2>&1 || return $?
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
130 # Don't bother rerunning the compile if we were already using -Werror
131 case "$*" in
132 *-Werror*)
133 return 0
135 esac
136 echo $compiler -Werror "$@" >> config.log
137 $compiler -Werror "$@" >> config.log 2>&1 && return $?
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."
144 do_cc() {
145 do_compiler "$cc" $CPU_CFLAGS "$@"
148 do_cxx() {
149 do_compiler "$cxx" $CPU_CFLAGS "$@"
152 # Append $2 to the variable named $1, with space separation
153 add_to() {
154 eval $1=\${$1:+\"\$$1 \"}\$2
157 update_cxxflags() {
158 # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
159 # options which some versions of GCC's C++ compiler complain about
160 # because they only make sense for C programs.
161 QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
162 CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
163 for arg in $QEMU_CFLAGS; do
164 case $arg in
165 -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
166 -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
169 QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
171 esac
172 done
175 compile_object() {
176 local_cflags="$1"
177 do_cc $CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
180 compile_prog() {
181 local_cflags="$1"
182 local_ldflags="$2"
183 do_cc $CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
184 $LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
187 # symbolically link $1 to $2. Portable version of "ln -sf".
188 symlink() {
189 rm -rf "$2"
190 mkdir -p "$(dirname "$2")"
191 ln -s "$1" "$2"
194 # check whether a command is available to this shell (may be either an
195 # executable or a builtin)
196 has() {
197 type "$1" >/dev/null 2>&1
200 version_ge () {
201 local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
202 local_ver2=$(echo "$2" | tr . ' ')
203 while true; do
204 set x $local_ver1
205 local_first=${2-0}
206 # 'shift 2' if $2 is set, or 'shift' if $2 is not set
207 shift ${2:+2}
208 local_ver1=$*
209 set x $local_ver2
210 # the second argument finished, the first must be greater or equal
211 test $# = 1 && return 0
212 test $local_first -lt $2 && return 1
213 test $local_first -gt $2 && return 0
214 shift ${2:+2}
215 local_ver2=$*
216 done
219 glob() {
220 eval test -z '"${1#'"$2"'}"'
223 ld_has() {
224 $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
227 if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
228 then
229 error_exit "main directory cannot contain spaces nor colons"
232 # default parameters
233 cpu=""
234 iasl="iasl"
235 interp_prefix="/usr/gnemul/qemu-%M"
236 static="no"
237 cross_compile="no"
238 cross_prefix=""
239 audio_drv_list="default"
240 block_drv_rw_whitelist=""
241 block_drv_ro_whitelist=""
242 block_drv_whitelist_tools="no"
243 host_cc="cc"
244 libs_qga=""
245 debug_info="yes"
246 lto="false"
247 stack_protector=""
248 safe_stack=""
249 use_containers="yes"
250 gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
252 if test -e "$source_path/.git"
253 then
254 git_submodules_action="update"
255 else
256 git_submodules_action="ignore"
259 git_submodules="ui/keycodemapdb"
260 git="git"
262 # Don't accept a target_list environment variable.
263 unset target_list
264 unset target_list_exclude
266 # Default value for a variable defining feature "foo".
267 # * foo="no" feature will only be used if --enable-foo arg is given
268 # * foo="" feature will be searched for, and if found, will be used
269 # unless --disable-foo is given
270 # * foo="yes" this value will only be set by --enable-foo flag.
271 # feature will searched for,
272 # if not found, configure exits with error
274 # Always add --enable-foo and --disable-foo command line args.
275 # Distributions want to ensure that several features are compiled in, and it
276 # is impossible without a --enable-foo that exits if a feature is not found.
278 default_feature=""
279 # parse CC options second
280 for opt do
281 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
282 case "$opt" in
283 --without-default-features)
284 default_feature="no"
286 esac
287 done
289 xen_ctrl_version="$default_feature"
290 xfs="$default_feature"
291 membarrier="$default_feature"
292 vhost_kernel="$default_feature"
293 vhost_net="$default_feature"
294 vhost_crypto="$default_feature"
295 vhost_scsi="$default_feature"
296 vhost_vsock="$default_feature"
297 vhost_user="no"
298 vhost_user_fs="$default_feature"
299 vhost_vdpa="$default_feature"
300 rdma="$default_feature"
301 pvrdma="$default_feature"
302 gprof="no"
303 debug_tcg="no"
304 debug="no"
305 sanitizers="no"
306 tsan="no"
307 fortify_source="$default_feature"
308 strip_opt="yes"
309 mingw32="no"
310 gcov="no"
311 EXESUF=""
312 modules="no"
313 module_upgrades="no"
314 prefix="/usr/local"
315 qemu_suffix="qemu"
316 bsd="no"
317 linux="no"
318 solaris="no"
319 profiler="no"
320 softmmu="yes"
321 linux_user="no"
322 bsd_user="no"
323 pkgversion=""
324 pie=""
325 qom_cast_debug="yes"
326 trace_backends="log"
327 trace_file="trace"
328 opengl="$default_feature"
329 cpuid_h="no"
330 avx2_opt="$default_feature"
331 guest_agent="$default_feature"
332 guest_agent_with_vss="no"
333 guest_agent_ntddscsi="no"
334 vss_win32_sdk="$default_feature"
335 win_sdk="no"
336 want_tools="$default_feature"
337 coroutine=""
338 coroutine_pool="$default_feature"
339 debug_stack_usage="no"
340 crypto_afalg="no"
341 tls_priority="NORMAL"
342 tpm="$default_feature"
343 libssh="$default_feature"
344 live_block_migration=${default_feature:-yes}
345 numa="$default_feature"
346 replication=${default_feature:-yes}
347 bochs=${default_feature:-yes}
348 cloop=${default_feature:-yes}
349 dmg=${default_feature:-yes}
350 qcow1=${default_feature:-yes}
351 vdi=${default_feature:-yes}
352 vvfat=${default_feature:-yes}
353 qed=${default_feature:-yes}
354 parallels=${default_feature:-yes}
355 debug_mutex="no"
356 plugins="$default_feature"
357 rng_none="no"
358 secret_keyring="$default_feature"
359 meson=""
360 meson_args=""
361 ninja=""
362 gio="$default_feature"
363 skip_meson=no
364 slirp_smbd="$default_feature"
366 # The following Meson options are handled manually (still they
367 # are included in the automatically generated help message)
369 # 1. Track which submodules are needed
370 capstone="auto"
371 fdt="auto"
372 slirp="auto"
374 # 2. Support --with/--without option
375 default_devices="true"
377 # 3. Automatically enable/disable other options
378 tcg="enabled"
379 cfi="false"
381 # 4. Detection partly done in configure
382 xen=${default_feature:+disabled}
384 # parse CC options second
385 for opt do
386 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
387 case "$opt" in
388 --cross-prefix=*) cross_prefix="$optarg"
389 cross_compile="yes"
391 --cc=*) CC="$optarg"
393 --cxx=*) CXX="$optarg"
395 --cpu=*) cpu="$optarg"
397 --extra-cflags=*) QEMU_CFLAGS="$QEMU_CFLAGS $optarg"
398 QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
400 --extra-cxxflags=*) QEMU_CXXFLAGS="$QEMU_CXXFLAGS $optarg"
402 --extra-ldflags=*) QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
403 EXTRA_LDFLAGS="$optarg"
405 --enable-debug-info) debug_info="yes"
407 --disable-debug-info) debug_info="no"
409 --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
411 --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-flags-}; cc_arch=${cc_arch%%=*}
412 eval "cross_cc_cflags_${cc_arch}=\$optarg"
413 cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
415 --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
416 cc_archs="$cc_archs $cc_arch"
417 eval "cross_cc_${cc_arch}=\$optarg"
418 cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
420 esac
421 done
422 # OS specific
423 # Using uname is really, really broken. Once we have the right set of checks
424 # we can eliminate its usage altogether.
426 # Preferred compiler:
427 # ${CC} (if set)
428 # ${cross_prefix}gcc (if cross-prefix specified)
429 # system compiler
430 if test -z "${CC}${cross_prefix}"; then
431 cc="$host_cc"
432 else
433 cc="${CC-${cross_prefix}gcc}"
436 if test -z "${CXX}${cross_prefix}"; then
437 cxx="c++"
438 else
439 cxx="${CXX-${cross_prefix}g++}"
442 ar="${AR-${cross_prefix}ar}"
443 as="${AS-${cross_prefix}as}"
444 ccas="${CCAS-$cc}"
445 cpp="${CPP-$cc -E}"
446 objcopy="${OBJCOPY-${cross_prefix}objcopy}"
447 ld="${LD-${cross_prefix}ld}"
448 ranlib="${RANLIB-${cross_prefix}ranlib}"
449 nm="${NM-${cross_prefix}nm}"
450 strip="${STRIP-${cross_prefix}strip}"
451 windres="${WINDRES-${cross_prefix}windres}"
452 pkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
453 query_pkg_config() {
454 "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
456 pkg_config=query_pkg_config
457 sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
459 # default flags for all hosts
460 # We use -fwrapv to tell the compiler that we require a C dialect where
461 # left shift of signed integers is well defined and has the expected
462 # 2s-complement style results. (Both clang and gcc agree that it
463 # provides these semantics.)
464 QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv $QEMU_CFLAGS"
465 QEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
466 QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
467 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
469 # Flags that are needed during configure but later taken care of by Meson
470 CONFIGURE_CFLAGS="-std=gnu11 -Wall"
471 CONFIGURE_LDFLAGS=
474 check_define() {
475 cat > $TMPC <<EOF
476 #if !defined($1)
477 #error $1 not defined
478 #endif
479 int main(void) { return 0; }
481 compile_object
484 check_include() {
485 cat > $TMPC <<EOF
486 #include <$1>
487 int main(void) { return 0; }
489 compile_object
492 write_c_skeleton() {
493 cat > $TMPC <<EOF
494 int main(void) { return 0; }
498 if check_define __linux__ ; then
499 targetos="Linux"
500 elif check_define _WIN32 ; then
501 targetos='MINGW32'
502 elif check_define __OpenBSD__ ; then
503 targetos='OpenBSD'
504 elif check_define __sun__ ; then
505 targetos='SunOS'
506 elif check_define __HAIKU__ ; then
507 targetos='Haiku'
508 elif check_define __FreeBSD__ ; then
509 targetos='FreeBSD'
510 elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
511 targetos='GNU/kFreeBSD'
512 elif check_define __DragonFly__ ; then
513 targetos='DragonFly'
514 elif check_define __NetBSD__; then
515 targetos='NetBSD'
516 elif check_define __APPLE__; then
517 targetos='Darwin'
518 else
519 # This is a fatal error, but don't report it yet, because we
520 # might be going to just print the --help text, or it might
521 # be the result of a missing compiler.
522 targetos='bogus'
525 # Some host OSes need non-standard checks for which CPU to use.
526 # Note that these checks are broken for cross-compilation: if you're
527 # cross-compiling to one of these OSes then you'll need to specify
528 # the correct CPU with the --cpu option.
529 case $targetos in
530 SunOS)
531 # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
532 if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
533 cpu="x86_64"
535 esac
537 if test ! -z "$cpu" ; then
538 # command line argument
540 elif check_define __i386__ ; then
541 cpu="i386"
542 elif check_define __x86_64__ ; then
543 if check_define __ILP32__ ; then
544 cpu="x32"
545 else
546 cpu="x86_64"
548 elif check_define __sparc__ ; then
549 if check_define __arch64__ ; then
550 cpu="sparc64"
551 else
552 cpu="sparc"
554 elif check_define _ARCH_PPC ; then
555 if check_define _ARCH_PPC64 ; then
556 if check_define _LITTLE_ENDIAN ; then
557 cpu="ppc64le"
558 else
559 cpu="ppc64"
561 else
562 cpu="ppc"
564 elif check_define __mips__ ; then
565 cpu="mips"
566 elif check_define __s390__ ; then
567 if check_define __s390x__ ; then
568 cpu="s390x"
569 else
570 cpu="s390"
572 elif check_define __riscv ; then
573 if check_define _LP64 ; then
574 cpu="riscv64"
575 else
576 cpu="riscv32"
578 elif check_define __arm__ ; then
579 cpu="arm"
580 elif check_define __aarch64__ ; then
581 cpu="aarch64"
582 else
583 cpu=$(uname -m)
586 ARCH=
587 # Normalise host CPU name and set ARCH.
588 # Note that this case should only have supported host CPUs, not guests.
589 case "$cpu" in
590 ppc|ppc64|s390x|sparc64|x32|riscv32|riscv64)
592 ppc64le)
593 ARCH="ppc64"
595 i386|i486|i586|i686|i86pc|BePC)
596 cpu="i386"
598 x86_64|amd64)
599 cpu="x86_64"
601 armv*b|armv*l|arm)
602 cpu="arm"
604 aarch64)
605 cpu="aarch64"
607 mips*)
608 cpu="mips"
610 sparc|sun4[cdmuv])
611 cpu="sparc"
614 # This will result in either an error or falling back to TCI later
615 ARCH=unknown
617 esac
618 if test -z "$ARCH"; then
619 ARCH="$cpu"
622 # OS specific
624 case $targetos in
625 MINGW32*)
626 mingw32="yes"
627 supported_os="yes"
628 plugins="no"
629 pie="no"
631 GNU/kFreeBSD)
632 bsd="yes"
634 FreeBSD)
635 bsd="yes"
636 bsd_user="yes"
637 make="${MAKE-gmake}"
638 # needed for kinfo_getvmmap(3) in libutil.h
640 DragonFly)
641 bsd="yes"
642 make="${MAKE-gmake}"
644 NetBSD)
645 bsd="yes"
646 make="${MAKE-gmake}"
648 OpenBSD)
649 bsd="yes"
650 make="${MAKE-gmake}"
652 Darwin)
653 bsd="yes"
654 darwin="yes"
655 # Disable attempts to use ObjectiveC features in os/object.h since they
656 # won't work when we're compiling with gcc as a C compiler.
657 QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
659 SunOS)
660 solaris="yes"
661 make="${MAKE-gmake}"
662 smbd="${SMBD-/usr/sfw/sbin/smbd}"
663 # needed for CMSG_ macros in sys/socket.h
664 QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
665 # needed for TIOCWIN* defines in termios.h
666 QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
668 Haiku)
669 haiku="yes"
670 pie="no"
671 QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
673 Linux)
674 linux="yes"
675 linux_user="yes"
676 vhost_user=${default_feature:-yes}
678 esac
680 : ${make=${MAKE-make}}
682 # We prefer python 3.x. A bare 'python' is traditionally
683 # python 2.x, but some distros have it as python 3.x, so
684 # we check that too
685 python=
686 explicit_python=no
687 for binary in "${PYTHON-python3}" python
689 if has "$binary"
690 then
691 python=$(command -v "$binary")
692 break
694 done
697 # Check for ancillary tools used in testing
698 genisoimage=
699 for binary in genisoimage mkisofs
701 if has $binary
702 then
703 genisoimage=$(command -v "$binary")
704 break
706 done
708 # Default objcc to clang if available, otherwise use CC
709 if has clang; then
710 objcc=clang
711 else
712 objcc="$cc"
715 if test "$mingw32" = "yes" ; then
716 EXESUF=".exe"
717 # MinGW needs -mthreads for TLS and macro _MT.
718 CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
719 write_c_skeleton;
720 prefix="/qemu"
721 qemu_suffix=""
722 libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi -lnetapi32 $libs_qga"
725 werror=""
727 . $source_path/scripts/meson-buildoptions.sh
729 meson_options=
730 meson_option_parse() {
731 meson_options="$meson_options $(_meson_option_parse "$@")"
732 if test $? -eq 1; then
733 echo "ERROR: unknown option $1"
734 echo "Try '$0 --help' for more information"
735 exit 1
739 for opt do
740 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
741 case "$opt" in
742 --help|-h) show_help=yes
744 --version|-V) exec cat $source_path/VERSION
746 --prefix=*) prefix="$optarg"
748 --interp-prefix=*) interp_prefix="$optarg"
750 --cross-prefix=*)
752 --cc=*)
754 --host-cc=*) host_cc="$optarg"
756 --cxx=*)
758 --iasl=*) iasl="$optarg"
760 --objcc=*) objcc="$optarg"
762 --make=*) make="$optarg"
764 --install=*)
766 --python=*) python="$optarg" ; explicit_python=yes
768 --sphinx-build=*) sphinx_build="$optarg"
770 --skip-meson) skip_meson=yes
772 --meson=*) meson="$optarg"
774 --ninja=*) ninja="$optarg"
776 --smbd=*) smbd="$optarg"
778 --extra-cflags=*)
780 --extra-cxxflags=*)
782 --extra-ldflags=*)
784 --enable-debug-info)
786 --disable-debug-info)
788 --cross-cc-*)
790 --enable-modules)
791 modules="yes"
793 --disable-modules)
794 modules="no"
796 --disable-module-upgrades) module_upgrades="no"
798 --enable-module-upgrades) module_upgrades="yes"
800 --cpu=*)
802 --target-list=*) target_list="$optarg"
803 if test "$target_list_exclude"; then
804 error_exit "Can't mix --target-list with --target-list-exclude"
807 --target-list-exclude=*) target_list_exclude="$optarg"
808 if test "$target_list"; then
809 error_exit "Can't mix --target-list-exclude with --target-list"
812 --with-trace-file=*) trace_file="$optarg"
814 --with-default-devices) default_devices="true"
816 --without-default-devices) default_devices="false"
818 --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
820 --with-devices-*) device_arch=${opt#--with-devices-};
821 device_arch=${device_arch%%=*}
822 cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
823 if test -f "$cf"; then
824 device_archs="$device_archs $device_arch"
825 eval "devices_${device_arch}=\$optarg"
826 else
827 error_exit "File $cf does not exist"
830 --without-default-features) # processed above
832 --enable-gprof) gprof="yes"
834 --enable-gcov) gcov="yes"
836 --static)
837 static="yes"
838 QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
840 --mandir=*) mandir="$optarg"
842 --bindir=*) bindir="$optarg"
844 --libdir=*) libdir="$optarg"
846 --libexecdir=*) libexecdir="$optarg"
848 --includedir=*) includedir="$optarg"
850 --datadir=*) datadir="$optarg"
852 --with-suffix=*) qemu_suffix="$optarg"
854 --docdir=*) docdir="$optarg"
856 --localedir=*) localedir="$optarg"
858 --sysconfdir=*) sysconfdir="$optarg"
860 --localstatedir=*) local_statedir="$optarg"
862 --firmwarepath=*) firmwarepath="$optarg"
864 --host=*|--build=*|\
865 --disable-dependency-tracking|\
866 --sbindir=*|--sharedstatedir=*|\
867 --oldincludedir=*|--datarootdir=*|--infodir=*|\
868 --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
869 # These switches are silently ignored, for compatibility with
870 # autoconf-generated configure scripts. This allows QEMU's
871 # configure to be used by RPM and similar macros that set
872 # lots of directory switches by default.
874 --disable-qom-cast-debug) qom_cast_debug="no"
876 --enable-qom-cast-debug) qom_cast_debug="yes"
878 --audio-drv-list=*) audio_drv_list="$optarg"
880 --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
882 --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
884 --enable-block-drv-whitelist-in-tools) block_drv_whitelist_tools="yes"
886 --disable-block-drv-whitelist-in-tools) block_drv_whitelist_tools="no"
888 --enable-debug-tcg) debug_tcg="yes"
890 --disable-debug-tcg) debug_tcg="no"
892 --enable-debug)
893 # Enable debugging options that aren't excessively noisy
894 debug_tcg="yes"
895 debug_mutex="yes"
896 debug="yes"
897 strip_opt="no"
898 fortify_source="no"
900 --enable-sanitizers) sanitizers="yes"
902 --disable-sanitizers) sanitizers="no"
904 --enable-tsan) tsan="yes"
906 --disable-tsan) tsan="no"
908 --disable-strip) strip_opt="no"
910 --disable-slirp) slirp="disabled"
912 --enable-slirp) slirp="enabled"
914 --enable-slirp=git) slirp="internal"
916 --enable-slirp=*) slirp="$optarg"
918 --disable-xen) xen="disabled"
920 --enable-xen) xen="enabled"
922 --disable-tcg) tcg="disabled"
923 plugins="no"
925 --enable-tcg) tcg="enabled"
927 --enable-profiler) profiler="yes"
929 --disable-system) softmmu="no"
931 --enable-system) softmmu="yes"
933 --disable-user)
934 linux_user="no" ;
935 bsd_user="no" ;
937 --enable-user) ;;
938 --disable-linux-user) linux_user="no"
940 --enable-linux-user) linux_user="yes"
942 --disable-bsd-user) bsd_user="no"
944 --enable-bsd-user) bsd_user="yes"
946 --enable-pie) pie="yes"
948 --disable-pie) pie="no"
950 --enable-werror) werror="yes"
952 --disable-werror) werror="no"
954 --enable-lto) lto="true"
956 --disable-lto) lto="false"
958 --enable-stack-protector) stack_protector="yes"
960 --disable-stack-protector) stack_protector="no"
962 --enable-safe-stack) safe_stack="yes"
964 --disable-safe-stack) safe_stack="no"
966 --enable-cfi)
967 cfi="true";
968 lto="true";
970 --disable-cfi) cfi="false"
972 --disable-fdt) fdt="disabled"
974 --enable-fdt) fdt="enabled"
976 --enable-fdt=git) fdt="internal"
978 --enable-fdt=*) fdt="$optarg"
980 --disable-membarrier) membarrier="no"
982 --enable-membarrier) membarrier="yes"
984 --with-pkgversion=*) pkgversion="$optarg"
986 --with-coroutine=*) coroutine="$optarg"
988 --disable-coroutine-pool) coroutine_pool="no"
990 --enable-coroutine-pool) coroutine_pool="yes"
992 --enable-debug-stack-usage) debug_stack_usage="yes"
994 --enable-crypto-afalg) crypto_afalg="yes"
996 --disable-crypto-afalg) crypto_afalg="no"
998 --disable-vhost-net) vhost_net="no"
1000 --enable-vhost-net) vhost_net="yes"
1002 --disable-vhost-crypto) vhost_crypto="no"
1004 --enable-vhost-crypto) vhost_crypto="yes"
1006 --disable-vhost-scsi) vhost_scsi="no"
1008 --enable-vhost-scsi) vhost_scsi="yes"
1010 --disable-vhost-vsock) vhost_vsock="no"
1012 --enable-vhost-vsock) vhost_vsock="yes"
1014 --disable-vhost-user-fs) vhost_user_fs="no"
1016 --enable-vhost-user-fs) vhost_user_fs="yes"
1018 --disable-opengl) opengl="no"
1020 --enable-opengl) opengl="yes"
1022 --disable-xfsctl) xfs="no"
1024 --enable-xfsctl) xfs="yes"
1026 --disable-zlib-test)
1028 --enable-guest-agent) guest_agent="yes"
1030 --disable-guest-agent) guest_agent="no"
1032 --with-vss-sdk) vss_win32_sdk=""
1034 --with-vss-sdk=*) vss_win32_sdk="$optarg"
1036 --without-vss-sdk) vss_win32_sdk="no"
1038 --with-win-sdk) win_sdk=""
1040 --with-win-sdk=*) win_sdk="$optarg"
1042 --without-win-sdk) win_sdk="no"
1044 --enable-tools) want_tools="yes"
1046 --disable-tools) want_tools="no"
1048 --disable-avx2) avx2_opt="no"
1050 --enable-avx2) avx2_opt="yes"
1052 --disable-avx512f) avx512f_opt="no"
1054 --enable-avx512f) avx512f_opt="yes"
1056 --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
1057 echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
1059 --enable-vhdx|--disable-vhdx)
1060 echo "$0: $opt is obsolete, VHDX driver is always built" >&2
1062 --enable-uuid|--disable-uuid)
1063 echo "$0: $opt is obsolete, UUID support is always built" >&2
1065 --tls-priority=*) tls_priority="$optarg"
1067 --enable-rdma) rdma="yes"
1069 --disable-rdma) rdma="no"
1071 --enable-pvrdma) pvrdma="yes"
1073 --disable-pvrdma) pvrdma="no"
1075 --disable-tpm) tpm="no"
1077 --enable-tpm) tpm="yes"
1079 --disable-libssh) libssh="no"
1081 --enable-libssh) libssh="yes"
1083 --disable-live-block-migration) live_block_migration="no"
1085 --enable-live-block-migration) live_block_migration="yes"
1087 --disable-numa) numa="no"
1089 --enable-numa) numa="yes"
1091 --disable-replication) replication="no"
1093 --enable-replication) replication="yes"
1095 --disable-bochs) bochs="no"
1097 --enable-bochs) bochs="yes"
1099 --disable-cloop) cloop="no"
1101 --enable-cloop) cloop="yes"
1103 --disable-dmg) dmg="no"
1105 --enable-dmg) dmg="yes"
1107 --disable-qcow1) qcow1="no"
1109 --enable-qcow1) qcow1="yes"
1111 --disable-vdi) vdi="no"
1113 --enable-vdi) vdi="yes"
1115 --disable-vvfat) vvfat="no"
1117 --enable-vvfat) vvfat="yes"
1119 --disable-qed) qed="no"
1121 --enable-qed) qed="yes"
1123 --disable-parallels) parallels="no"
1125 --enable-parallels) parallels="yes"
1127 --disable-vhost-user) vhost_user="no"
1129 --enable-vhost-user) vhost_user="yes"
1131 --disable-vhost-vdpa) vhost_vdpa="no"
1133 --enable-vhost-vdpa) vhost_vdpa="yes"
1135 --disable-vhost-kernel) vhost_kernel="no"
1137 --enable-vhost-kernel) vhost_kernel="yes"
1139 --disable-capstone) capstone="disabled"
1141 --enable-capstone) capstone="enabled"
1143 --enable-capstone=git) capstone="internal"
1145 --enable-capstone=*) capstone="$optarg"
1147 --with-git=*) git="$optarg"
1149 --with-git-submodules=*)
1150 git_submodules_action="$optarg"
1152 --enable-debug-mutex) debug_mutex=yes
1154 --disable-debug-mutex) debug_mutex=no
1156 --enable-plugins) if test "$mingw32" = "yes"; then
1157 error_exit "TCG plugins not currently supported on Windows platforms"
1158 else
1159 plugins="yes"
1162 --disable-plugins) plugins="no"
1164 --enable-containers) use_containers="yes"
1166 --disable-containers) use_containers="no"
1168 --gdb=*) gdb_bin="$optarg"
1170 --enable-rng-none) rng_none=yes
1172 --disable-rng-none) rng_none=no
1174 --enable-keyring) secret_keyring="yes"
1176 --disable-keyring) secret_keyring="no"
1178 --enable-gio) gio=yes
1180 --disable-gio) gio=no
1182 --enable-slirp-smbd) slirp_smbd=yes
1184 --disable-slirp-smbd) slirp_smbd=no
1186 # backwards compatibility options
1187 --enable-trace-backend=*) meson_option_parse "--enable-trace-backends=$optarg" "$optarg"
1189 --disable-blobs) meson_option_parse --disable-install-blobs ""
1191 --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
1193 --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
1195 # everything else has the same name in configure and meson
1196 --enable-* | --disable-*) meson_option_parse "$opt" "$optarg"
1199 echo "ERROR: unknown option $opt"
1200 echo "Try '$0 --help' for more information"
1201 exit 1
1203 esac
1204 done
1206 # test for any invalid configuration combinations
1207 if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
1208 error_exit "Can't enable plugins on non-TCG builds"
1211 case $git_submodules_action in
1212 update|validate)
1213 if test ! -e "$source_path/.git"; then
1214 echo "ERROR: cannot $git_submodules_action git submodules without .git"
1215 exit 1
1218 ignore)
1219 if ! test -f "$source_path/ui/keycodemapdb/README"
1220 then
1221 echo
1222 echo "ERROR: missing GIT submodules"
1223 echo
1224 if test -e "$source_path/.git"; then
1225 echo "--with-git-submodules=ignore specified but submodules were not"
1226 echo "checked out. Please initialize and update submodules."
1227 else
1228 echo "This is not a GIT checkout but module content appears to"
1229 echo "be missing. Do not use 'git archive' or GitHub download links"
1230 echo "to acquire QEMU source archives. Non-GIT builds are only"
1231 echo "supported with source archives linked from:"
1232 echo
1233 echo " https://www.qemu.org/download/#source"
1234 echo
1235 echo "Developers working with GIT can use scripts/archive-source.sh"
1236 echo "if they need to create valid source archives."
1238 echo
1239 exit 1
1243 echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
1244 exit 1
1246 esac
1248 libdir="${libdir:-$prefix/lib}"
1249 libexecdir="${libexecdir:-$prefix/libexec}"
1250 includedir="${includedir:-$prefix/include}"
1252 if test "$mingw32" = "yes" ; then
1253 bindir="${bindir:-$prefix}"
1254 else
1255 bindir="${bindir:-$prefix/bin}"
1257 mandir="${mandir:-$prefix/share/man}"
1258 datadir="${datadir:-$prefix/share}"
1259 docdir="${docdir:-$prefix/share/doc}"
1260 sysconfdir="${sysconfdir:-$prefix/etc}"
1261 local_statedir="${local_statedir:-$prefix/var}"
1262 firmwarepath="${firmwarepath:-$datadir/qemu-firmware}"
1263 localedir="${localedir:-$datadir/locale}"
1265 case "$cpu" in
1266 ppc)
1267 CPU_CFLAGS="-m32"
1268 QEMU_LDFLAGS="-m32 $QEMU_LDFLAGS"
1270 ppc64)
1271 CPU_CFLAGS="-m64"
1272 QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1274 sparc)
1275 CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc"
1276 QEMU_LDFLAGS="-m32 -mv8plus $QEMU_LDFLAGS"
1278 sparc64)
1279 CPU_CFLAGS="-m64 -mcpu=ultrasparc"
1280 QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1282 s390)
1283 CPU_CFLAGS="-m31"
1284 QEMU_LDFLAGS="-m31 $QEMU_LDFLAGS"
1286 s390x)
1287 CPU_CFLAGS="-m64"
1288 QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1290 i386)
1291 CPU_CFLAGS="-m32"
1292 QEMU_LDFLAGS="-m32 $QEMU_LDFLAGS"
1294 x86_64)
1295 # ??? Only extremely old AMD cpus do not have cmpxchg16b.
1296 # If we truly care, we should simply detect this case at
1297 # runtime and generate the fallback to serial emulation.
1298 CPU_CFLAGS="-m64 -mcx16"
1299 QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1301 x32)
1302 CPU_CFLAGS="-mx32"
1303 QEMU_LDFLAGS="-mx32 $QEMU_LDFLAGS"
1305 # No special flags required for other host CPUs
1306 esac
1308 if eval test -z "\${cross_cc_$cpu}"; then
1309 eval "cross_cc_${cpu}=\$cc"
1310 cross_cc_vars="$cross_cc_vars cross_cc_${cpu}"
1313 # For user-mode emulation the host arch has to be one we explicitly
1314 # support, even if we're using TCI.
1315 if [ "$ARCH" = "unknown" ]; then
1316 bsd_user="no"
1317 linux_user="no"
1320 default_target_list=""
1321 deprecated_targets_list=ppc64abi32-linux-user
1322 deprecated_features=""
1323 mak_wilds=""
1325 if [ "$softmmu" = "yes" ]; then
1326 mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
1328 if [ "$linux_user" = "yes" ]; then
1329 mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
1331 if [ "$bsd_user" = "yes" ]; then
1332 mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
1335 # If the user doesn't explicitly specify a deprecated target we will
1336 # skip it.
1337 if test -z "$target_list"; then
1338 if test -z "$target_list_exclude"; then
1339 target_list_exclude="$deprecated_targets_list"
1340 else
1341 target_list_exclude="$target_list_exclude,$deprecated_targets_list"
1345 for config in $mak_wilds; do
1346 target="$(basename "$config" .mak)"
1347 if echo "$target_list_exclude" | grep -vq "$target"; then
1348 default_target_list="${default_target_list} $target"
1350 done
1352 if test x"$show_help" = x"yes" ; then
1353 cat << EOF
1355 Usage: configure [options]
1356 Options: [defaults in brackets after descriptions]
1358 Standard options:
1359 --help print this message
1360 --prefix=PREFIX install in PREFIX [$prefix]
1361 --interp-prefix=PREFIX where to find shared libraries, etc.
1362 use %M for cpu name [$interp_prefix]
1363 --target-list=LIST set target list (default: build all non-deprecated)
1364 $(echo Available targets: $default_target_list | \
1365 fold -s -w 53 | sed -e 's/^/ /')
1366 $(echo Deprecated targets: $deprecated_targets_list | \
1367 fold -s -w 53 | sed -e 's/^/ /')
1368 --target-list-exclude=LIST exclude a set of targets from the default target-list
1370 Advanced options (experts only):
1371 --cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
1372 --cc=CC use C compiler CC [$cc]
1373 --iasl=IASL use ACPI compiler IASL [$iasl]
1374 --host-cc=CC use C compiler CC [$host_cc] for code run at
1375 build time
1376 --cxx=CXX use C++ compiler CXX [$cxx]
1377 --objcc=OBJCC use Objective-C compiler OBJCC [$objcc]
1378 --extra-cflags=CFLAGS append extra C compiler flags QEMU_CFLAGS
1379 --extra-cxxflags=CXXFLAGS append extra C++ compiler flags QEMU_CXXFLAGS
1380 --extra-ldflags=LDFLAGS append extra linker flags LDFLAGS
1381 --cross-cc-ARCH=CC use compiler when building ARCH guest test cases
1382 --cross-cc-flags-ARCH= use compiler flags when building ARCH guest tests
1383 --make=MAKE use specified make [$make]
1384 --python=PYTHON use specified python [$python]
1385 --sphinx-build=SPHINX use specified sphinx-build [$sphinx_build]
1386 --meson=MESON use specified meson [$meson]
1387 --ninja=NINJA use specified ninja [$ninja]
1388 --smbd=SMBD use specified smbd [$smbd]
1389 --with-git=GIT use specified git [$git]
1390 --with-git-submodules=update update git submodules (default if .git dir exists)
1391 --with-git-submodules=validate fail if git submodules are not up to date
1392 --with-git-submodules=ignore do not update or check git submodules (default if no .git dir)
1393 --static enable static build [$static]
1394 --mandir=PATH install man pages in PATH
1395 --datadir=PATH install firmware in PATH/$qemu_suffix
1396 --localedir=PATH install translation in PATH/$qemu_suffix
1397 --docdir=PATH install documentation in PATH/$qemu_suffix
1398 --bindir=PATH install binaries in PATH
1399 --libdir=PATH install libraries in PATH
1400 --libexecdir=PATH install helper binaries in PATH
1401 --sysconfdir=PATH install config in PATH/$qemu_suffix
1402 --localstatedir=PATH install local state in PATH (set at runtime on win32)
1403 --firmwarepath=PATH search PATH for firmware files
1404 --efi-aarch64=PATH PATH of efi file to use for aarch64 VMs.
1405 --with-suffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
1406 --with-pkgversion=VERS use specified string as sub-version of the package
1407 --without-default-features default all --enable-* options to "disabled"
1408 --without-default-devices do not include any device that is not needed to
1409 start the emulator (only use if you are including
1410 desired devices in configs/devices/)
1411 --with-devices-ARCH=NAME override default configs/devices
1412 --enable-debug enable common debug build options
1413 --enable-sanitizers enable default sanitizers
1414 --enable-tsan enable thread sanitizer
1415 --disable-strip disable stripping binaries
1416 --disable-werror disable compilation abort on warning
1417 --disable-stack-protector disable compiler-provided stack protection
1418 --audio-drv-list=LIST set audio drivers list
1419 --block-drv-whitelist=L Same as --block-drv-rw-whitelist=L
1420 --block-drv-rw-whitelist=L
1421 set block driver read-write whitelist
1422 (by default affects only QEMU, not tools like qemu-img)
1423 --block-drv-ro-whitelist=L
1424 set block driver read-only whitelist
1425 (by default affects only QEMU, not tools like qemu-img)
1426 --enable-block-drv-whitelist-in-tools
1427 use block whitelist also in tools instead of only QEMU
1428 --with-trace-file=NAME Full PATH,NAME of file to store traces
1429 Default:trace-<pid>
1430 --cpu=CPU Build for host CPU [$cpu]
1431 --with-coroutine=BACKEND coroutine backend. Supported options:
1432 ucontext, sigaltstack, windows
1433 --enable-gcov enable test coverage analysis with gcov
1434 --with-vss-sdk=SDK-path enable Windows VSS support in QEMU Guest Agent
1435 --with-win-sdk=SDK-path path to Windows Platform SDK (to build VSS .tlb)
1436 --tls-priority default TLS protocol/cipher priority string
1437 --enable-gprof QEMU profiling with gprof
1438 --enable-profiler profiler support
1439 --enable-debug-stack-usage
1440 track the maximum stack usage of stacks created by qemu_alloc_stack
1441 --enable-plugins
1442 enable plugins via shared library loading
1443 --disable-containers don't use containers for cross-building
1444 --gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
1446 meson_options_help
1447 cat << EOF
1448 system all system emulation targets
1449 user supported user emulation targets
1450 linux-user all linux usermode emulation targets
1451 bsd-user all BSD usermode emulation targets
1452 guest-agent build the QEMU Guest Agent
1453 pie Position Independent Executables
1454 modules modules support (non-Windows)
1455 module-upgrades try to load modules from alternate paths for upgrades
1456 debug-tcg TCG debugging (default is disabled)
1457 debug-info debugging information
1458 lto Enable Link-Time Optimization.
1459 safe-stack SafeStack Stack Smash Protection. Depends on
1460 clang/llvm >= 3.7 and requires coroutine backend ucontext.
1461 membarrier membarrier system call (for Linux 4.14+ or Windows)
1462 rdma Enable RDMA-based migration
1463 pvrdma Enable PVRDMA support
1464 vhost-net vhost-net kernel acceleration support
1465 vhost-vsock virtio sockets device support
1466 vhost-scsi vhost-scsi kernel target support
1467 vhost-crypto vhost-user-crypto backend support
1468 vhost-kernel vhost kernel backend support
1469 vhost-user vhost-user backend support
1470 vhost-vdpa vhost-vdpa kernel backend support
1471 live-block-migration Block migration in the main migration stream
1472 coroutine-pool coroutine freelist (better performance)
1473 tpm TPM support
1474 libssh ssh block device support
1475 numa libnuma support
1476 avx2 AVX2 optimization support
1477 avx512f AVX512F optimization support
1478 replication replication support
1479 opengl opengl support
1480 xfsctl xfsctl support
1481 qom-cast-debug cast debugging support
1482 tools build qemu-io, qemu-nbd and qemu-img tools
1483 bochs bochs image format support
1484 cloop cloop image format support
1485 dmg dmg image format support
1486 qcow1 qcow v1 image format support
1487 vdi vdi image format support
1488 vvfat vvfat image format support
1489 qed qed image format support
1490 parallels parallels image format support
1491 crypto-afalg Linux AF_ALG crypto backend driver
1492 debug-mutex mutex debugging support
1493 rng-none dummy RNG, avoid using /dev/(u)random and getrandom()
1494 gio libgio support
1495 slirp-smbd use smbd (at path --smbd=*) in slirp networking
1497 NOTE: The object files are built at the place where configure is launched
1499 exit 0
1502 # Remove old dependency files to make sure that they get properly regenerated
1503 rm -f */config-devices.mak.d
1505 if test -z "$python"
1506 then
1507 error_exit "Python not found. Use --python=/path/to/python"
1509 if ! has "$make"
1510 then
1511 error_exit "GNU make ($make) not found"
1514 # Note that if the Python conditional here evaluates True we will exit
1515 # with status 1 which is a shell 'false' value.
1516 if ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then
1517 error_exit "Cannot use '$python', Python >= 3.6 is required." \
1518 "Use --python=/path/to/python to specify a supported Python."
1521 # Preserve python version since some functionality is dependent on it
1522 python_version=$($python -c 'import sys; print("%d.%d.%d" % (sys.version_info[0], sys.version_info[1], sys.version_info[2]))' 2>/dev/null)
1524 # Suppress writing compiled files
1525 python="$python -B"
1527 if test -z "$meson"; then
1528 if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.59.2; then
1529 meson=meson
1530 elif test $git_submodules_action != 'ignore' ; then
1531 meson=git
1532 elif test -e "${source_path}/meson/meson.py" ; then
1533 meson=internal
1534 else
1535 if test "$explicit_python" = yes; then
1536 error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
1537 else
1538 error_exit "Meson not found. Use --meson=/path/to/meson"
1541 else
1542 # Meson uses its own Python interpreter to invoke other Python scripts,
1543 # but the user wants to use the one they specified with --python.
1545 # We do not want to override the distro Python interpreter (and sometimes
1546 # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
1547 # just require --meson=git|internal together with --python.
1548 if test "$explicit_python" = yes; then
1549 case "$meson" in
1550 git | internal) ;;
1551 *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
1552 esac
1556 if test "$meson" = git; then
1557 git_submodules="${git_submodules} meson"
1560 case "$meson" in
1561 git | internal)
1562 meson="$python ${source_path}/meson/meson.py"
1564 *) meson=$(command -v "$meson") ;;
1565 esac
1567 # Probe for ninja
1569 if test -z "$ninja"; then
1570 for c in ninja ninja-build samu; do
1571 if has $c; then
1572 ninja=$(command -v "$c")
1573 break
1575 done
1576 if test -z "$ninja"; then
1577 error_exit "Cannot find Ninja"
1581 # Check that the C compiler works. Doing this here before testing
1582 # the host CPU ensures that we had a valid CC to autodetect the
1583 # $cpu var (and we should bail right here if that's not the case).
1584 # It also allows the help message to be printed without a CC.
1585 write_c_skeleton;
1586 if compile_object ; then
1587 : C compiler works ok
1588 else
1589 error_exit "\"$cc\" either does not exist or does not work"
1591 if ! compile_prog ; then
1592 error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
1595 # Consult white-list to determine whether to enable werror
1596 # by default. Only enable by default for git builds
1597 if test -z "$werror" ; then
1598 if test "$git_submodules_action" != "ignore" && \
1599 { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
1600 werror="yes"
1601 else
1602 werror="no"
1606 if test "$targetos" = "bogus"; then
1607 # Now that we know that we're not printing the help and that
1608 # the compiler works (so the results of the check_defines we used
1609 # to identify the OS are reliable), if we didn't recognize the
1610 # host OS we should stop now.
1611 error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1614 # Check whether the compiler matches our minimum requirements:
1615 cat > $TMPC << EOF
1616 #if defined(__clang_major__) && defined(__clang_minor__)
1617 # ifdef __apple_build_version__
1618 # if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
1619 # error You need at least XCode Clang v10.0 to compile QEMU
1620 # endif
1621 # else
1622 # if __clang_major__ < 6 || (__clang_major__ == 6 && __clang_minor__ < 0)
1623 # error You need at least Clang v6.0 to compile QEMU
1624 # endif
1625 # endif
1626 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
1627 # if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
1628 # error You need at least GCC v7.4.0 to compile QEMU
1629 # endif
1630 #else
1631 # error You either need GCC or Clang to compiler QEMU
1632 #endif
1633 int main (void) { return 0; }
1635 if ! compile_prog "" "" ; then
1636 error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
1639 # Accumulate -Wfoo and -Wno-bar separately.
1640 # We will list all of the enable flags first, and the disable flags second.
1641 # Note that we do not add -Werror, because that would enable it for all
1642 # configure tests. If a configure test failed due to -Werror this would
1643 # just silently disable some features, so it's too error prone.
1645 warn_flags=
1646 add_to warn_flags -Wold-style-declaration
1647 add_to warn_flags -Wold-style-definition
1648 add_to warn_flags -Wtype-limits
1649 add_to warn_flags -Wformat-security
1650 add_to warn_flags -Wformat-y2k
1651 add_to warn_flags -Winit-self
1652 add_to warn_flags -Wignored-qualifiers
1653 add_to warn_flags -Wempty-body
1654 add_to warn_flags -Wnested-externs
1655 add_to warn_flags -Wendif-labels
1656 add_to warn_flags -Wexpansion-to-defined
1657 add_to warn_flags -Wimplicit-fallthrough=2
1659 nowarn_flags=
1660 add_to nowarn_flags -Wno-initializer-overrides
1661 add_to nowarn_flags -Wno-missing-include-dirs
1662 add_to nowarn_flags -Wno-shift-negative-value
1663 add_to nowarn_flags -Wno-string-plus-int
1664 add_to nowarn_flags -Wno-typedef-redefinition
1665 add_to nowarn_flags -Wno-tautological-type-limit-compare
1666 add_to nowarn_flags -Wno-psabi
1668 gcc_flags="$warn_flags $nowarn_flags"
1670 cc_has_warning_flag() {
1671 write_c_skeleton;
1673 # Use the positive sense of the flag when testing for -Wno-wombat
1674 # support (gcc will happily accept the -Wno- form of unknown
1675 # warning options).
1676 optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
1677 compile_prog "-Werror $optflag" ""
1680 for flag in $gcc_flags; do
1681 if cc_has_warning_flag $flag ; then
1682 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1684 done
1686 if test "$stack_protector" != "no"; then
1687 cat > $TMPC << EOF
1688 int main(int argc, char *argv[])
1690 char arr[64], *p = arr, *c = argv[0];
1691 while (*c) {
1692 *p++ = *c++;
1694 return 0;
1697 gcc_flags="-fstack-protector-strong -fstack-protector-all"
1698 sp_on=0
1699 for flag in $gcc_flags; do
1700 # We need to check both a compile and a link, since some compiler
1701 # setups fail only on a .c->.o compile and some only at link time
1702 if compile_object "-Werror $flag" &&
1703 compile_prog "-Werror $flag" ""; then
1704 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1705 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
1706 sp_on=1
1707 break
1709 done
1710 if test "$stack_protector" = yes; then
1711 if test $sp_on = 0; then
1712 error_exit "Stack protector not supported"
1717 # Disable -Wmissing-braces on older compilers that warn even for
1718 # the "universal" C zero initializer {0}.
1719 cat > $TMPC << EOF
1720 struct {
1721 int a[2];
1722 } x = {0};
1724 if compile_object "-Werror" "" ; then
1726 else
1727 QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
1730 # Our module code doesn't support Windows
1731 if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
1732 error_exit "Modules are not available for Windows"
1735 # module_upgrades is only reasonable if modules are enabled
1736 if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
1737 error_exit "Can't enable module-upgrades as Modules are not enabled"
1740 # Static linking is not possible with plugins, modules or PIE
1741 if test "$static" = "yes" ; then
1742 if test "$modules" = "yes" ; then
1743 error_exit "static and modules are mutually incompatible"
1745 if test "$plugins" = "yes"; then
1746 error_exit "static and plugins are mutually incompatible"
1747 else
1748 plugins="no"
1752 # Unconditional check for compiler __thread support
1753 cat > $TMPC << EOF
1754 static __thread int tls_var;
1755 int main(void) { return tls_var; }
1758 if ! compile_prog "-Werror" "" ; then
1759 error_exit "Your compiler does not support the __thread specifier for " \
1760 "Thread-Local Storage (TLS). Please upgrade to a version that does."
1763 cat > $TMPC << EOF
1765 #ifdef __linux__
1766 # define THREAD __thread
1767 #else
1768 # define THREAD
1769 #endif
1770 static THREAD int tls_var;
1771 int main(void) { return tls_var; }
1774 # Check we support --no-pie first; we will need this for building ROMs.
1775 if compile_prog "-Werror -fno-pie" "-no-pie"; then
1776 CFLAGS_NOPIE="-fno-pie"
1779 if test "$static" = "yes"; then
1780 if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
1781 CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
1782 QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
1783 pie="yes"
1784 elif test "$pie" = "yes"; then
1785 error_exit "-static-pie not available due to missing toolchain support"
1786 else
1787 QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
1788 pie="no"
1790 elif test "$pie" = "no"; then
1791 CONFIGURE_CFLAGS="$CFLAGS_NOPIE $CONFIGURE_CFLAGS"
1792 elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
1793 CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
1794 CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
1795 pie="yes"
1796 elif test "$pie" = "yes"; then
1797 error_exit "PIE not available due to missing toolchain support"
1798 else
1799 echo "Disabling PIE due to missing toolchain support"
1800 pie="no"
1803 # Detect support for PT_GNU_RELRO + DT_BIND_NOW.
1804 # The combination is known as "full relro", because .got.plt is read-only too.
1805 if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1806 QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
1809 ##########################################
1810 # __sync_fetch_and_and requires at least -march=i486. Many toolchains
1811 # use i686 as default anyway, but for those that don't, an explicit
1812 # specification is necessary
1814 if test "$cpu" = "i386"; then
1815 cat > $TMPC << EOF
1816 static int sfaa(int *ptr)
1818 return __sync_fetch_and_and(ptr, 0);
1821 int main(void)
1823 int val = 42;
1824 val = __sync_val_compare_and_swap(&val, 0, 1);
1825 sfaa(&val);
1826 return val;
1829 if ! compile_prog "" "" ; then
1830 QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
1834 if test "$tcg" = "enabled"; then
1835 git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
1836 git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
1839 if test -z "${target_list+xxx}" ; then
1840 default_targets=yes
1841 for target in $default_target_list; do
1842 target_list="$target_list $target"
1843 done
1844 target_list="${target_list# }"
1845 else
1846 default_targets=no
1847 target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1848 for target in $target_list; do
1849 # Check that we recognised the target name; this allows a more
1850 # friendly error message than if we let it fall through.
1851 case " $default_target_list " in
1852 *" $target "*)
1855 error_exit "Unknown target name '$target'"
1857 esac
1858 done
1861 for target in $target_list; do
1862 # if a deprecated target is enabled we note it here
1863 if echo "$deprecated_targets_list" | grep -q "$target"; then
1864 add_to deprecated_features $target
1866 done
1868 # see if system emulation was really requested
1869 case " $target_list " in
1870 *"-softmmu "*) softmmu=yes
1872 *) softmmu=no
1874 esac
1876 feature_not_found() {
1877 feature=$1
1878 remedy=$2
1880 error_exit "User requested feature $feature" \
1881 "configure was not able to find it." \
1882 "$remedy"
1885 # ---
1886 # big/little endian test
1887 cat > $TMPC << EOF
1888 #include <stdio.h>
1889 short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
1890 short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
1891 int main(int argc, char *argv[])
1893 return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
1897 if compile_prog ; then
1898 if strings -a $TMPE | grep -q BiGeNdIaN ; then
1899 bigendian="yes"
1900 elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
1901 bigendian="no"
1902 else
1903 echo big/little test failed
1904 exit 1
1906 else
1907 echo big/little test failed
1908 exit 1
1911 ##########################################
1912 # system tools
1913 if test -z "$want_tools"; then
1914 if test "$softmmu" = "no"; then
1915 want_tools=no
1916 else
1917 want_tools=yes
1921 ##########################################
1922 # L2TPV3 probe
1924 cat > $TMPC <<EOF
1925 #include <sys/socket.h>
1926 #include <linux/ip.h>
1927 int main(void) { return sizeof(struct mmsghdr); }
1929 if compile_prog "" "" ; then
1930 l2tpv3=yes
1931 else
1932 l2tpv3=no
1935 #########################################
1936 # vhost interdependencies and host support
1938 # vhost backends
1939 if test "$vhost_user" = "yes" && test "$linux" != "yes"; then
1940 error_exit "vhost-user is only available on Linux"
1942 test "$vhost_vdpa" = "" && vhost_vdpa=$linux
1943 if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
1944 error_exit "vhost-vdpa is only available on Linux"
1946 test "$vhost_kernel" = "" && vhost_kernel=$linux
1947 if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
1948 error_exit "vhost-kernel is only available on Linux"
1951 # vhost-kernel devices
1952 test "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
1953 if test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
1954 error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
1956 test "$vhost_vsock" = "" && vhost_vsock=$vhost_kernel
1957 if test "$vhost_vsock" = "yes" && test "$vhost_kernel" != "yes"; then
1958 error_exit "--enable-vhost-vsock requires --enable-vhost-kernel"
1961 # vhost-user backends
1962 test "$vhost_net_user" = "" && vhost_net_user=$vhost_user
1963 if test "$vhost_net_user" = "yes" && test "$vhost_user" = "no"; then
1964 error_exit "--enable-vhost-net-user requires --enable-vhost-user"
1966 test "$vhost_crypto" = "" && vhost_crypto=$vhost_user
1967 if test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
1968 error_exit "--enable-vhost-crypto requires --enable-vhost-user"
1970 test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
1971 if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
1972 error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
1974 #vhost-vdpa backends
1975 test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa
1976 if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then
1977 error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa"
1980 # OR the vhost-kernel, vhost-vdpa and vhost-user values for simplicity
1981 if test "$vhost_net" = ""; then
1982 test "$vhost_net_user" = "yes" && vhost_net=yes
1983 test "$vhost_net_vdpa" = "yes" && vhost_net=yes
1984 test "$vhost_kernel" = "yes" && vhost_net=yes
1987 ##########################################
1988 # pkg-config probe
1990 if ! has "$pkg_config_exe"; then
1991 error_exit "pkg-config binary '$pkg_config_exe' not found"
1994 ##########################################
1995 # NPTL probe
1997 if test "$linux_user" = "yes"; then
1998 cat > $TMPC <<EOF
1999 #include <sched.h>
2000 #include <linux/futex.h>
2001 int main(void) {
2002 #if !defined(CLONE_SETTLS) || !defined(FUTEX_WAIT)
2003 #error bork
2004 #endif
2005 return 0;
2008 if ! compile_object ; then
2009 feature_not_found "nptl" "Install glibc and linux kernel headers."
2013 ##########################################
2014 # xen probe
2016 if test "$xen" != "disabled" ; then
2017 # Check whether Xen library path is specified via --extra-ldflags to avoid
2018 # overriding this setting with pkg-config output. If not, try pkg-config
2019 # to obtain all needed flags.
2021 if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \
2022 $pkg_config --exists xencontrol ; then
2023 xen_ctrl_version="$(printf '%d%02d%02d' \
2024 $($pkg_config --modversion xencontrol | sed 's/\./ /g') )"
2025 xen=enabled
2026 xen_pc="xencontrol xenstore xenforeignmemory xengnttab"
2027 xen_pc="$xen_pc xenevtchn xendevicemodel"
2028 if $pkg_config --exists xentoolcore; then
2029 xen_pc="$xen_pc xentoolcore"
2031 xen_cflags="$($pkg_config --cflags $xen_pc)"
2032 xen_libs="$($pkg_config --libs $xen_pc)"
2033 else
2035 xen_libs="-lxenstore -lxenctrl"
2036 xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
2038 # First we test whether Xen headers and libraries are available.
2039 # If no, we are done and there is no Xen support.
2040 # If yes, more tests are run to detect the Xen version.
2042 # Xen (any)
2043 cat > $TMPC <<EOF
2044 #include <xenctrl.h>
2045 int main(void) {
2046 return 0;
2049 if ! compile_prog "" "$xen_libs" ; then
2050 # Xen not found
2051 if test "$xen" = "enabled" ; then
2052 feature_not_found "xen" "Install xen devel"
2054 xen=disabled
2056 # Xen unstable
2057 elif
2058 cat > $TMPC <<EOF &&
2059 #undef XC_WANT_COMPAT_DEVICEMODEL_API
2060 #define __XEN_TOOLS__
2061 #include <xendevicemodel.h>
2062 #include <xenforeignmemory.h>
2063 int main(void) {
2064 xendevicemodel_handle *xd;
2065 xenforeignmemory_handle *xfmem;
2067 xd = xendevicemodel_open(0, 0);
2068 xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);
2070 xfmem = xenforeignmemory_open(0, 0);
2071 xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);
2073 return 0;
2076 compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
2077 then
2078 xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
2079 xen_ctrl_version=41100
2080 xen=enabled
2081 elif
2082 cat > $TMPC <<EOF &&
2083 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
2084 #include <xenforeignmemory.h>
2085 #include <xentoolcore.h>
2086 int main(void) {
2087 xenforeignmemory_handle *xfmem;
2089 xfmem = xenforeignmemory_open(0, 0);
2090 xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
2091 xentoolcore_restrict_all(0);
2093 return 0;
2096 compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
2097 then
2098 xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
2099 xen_ctrl_version=41000
2100 xen=enabled
2101 elif
2102 cat > $TMPC <<EOF &&
2103 #undef XC_WANT_COMPAT_DEVICEMODEL_API
2104 #define __XEN_TOOLS__
2105 #include <xendevicemodel.h>
2106 int main(void) {
2107 xendevicemodel_handle *xd;
2109 xd = xendevicemodel_open(0, 0);
2110 xendevicemodel_close(xd);
2112 return 0;
2115 compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs"
2116 then
2117 xen_stable_libs="-lxendevicemodel $xen_stable_libs"
2118 xen_ctrl_version=40900
2119 xen=enabled
2120 elif
2121 cat > $TMPC <<EOF &&
2123 * If we have stable libs the we don't want the libxc compat
2124 * layers, regardless of what CFLAGS we may have been given.
2126 * Also, check if xengnttab_grant_copy_segment_t is defined and
2127 * grant copy operation is implemented.
2129 #undef XC_WANT_COMPAT_EVTCHN_API
2130 #undef XC_WANT_COMPAT_GNTTAB_API
2131 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
2132 #include <xenctrl.h>
2133 #include <xenstore.h>
2134 #include <xenevtchn.h>
2135 #include <xengnttab.h>
2136 #include <xenforeignmemory.h>
2137 #include <stdint.h>
2138 #include <xen/hvm/hvm_info_table.h>
2139 #if !defined(HVM_MAX_VCPUS)
2140 # error HVM_MAX_VCPUS not defined
2141 #endif
2142 int main(void) {
2143 xc_interface *xc = NULL;
2144 xenforeignmemory_handle *xfmem;
2145 xenevtchn_handle *xe;
2146 xengnttab_handle *xg;
2147 xengnttab_grant_copy_segment_t* seg = NULL;
2149 xs_daemon_open();
2151 xc = xc_interface_open(0, 0, 0);
2152 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2153 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2154 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2155 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2157 xfmem = xenforeignmemory_open(0, 0);
2158 xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2160 xe = xenevtchn_open(0, 0);
2161 xenevtchn_fd(xe);
2163 xg = xengnttab_open(0, 0);
2164 xengnttab_grant_copy(xg, 0, seg);
2166 return 0;
2169 compile_prog "" "$xen_libs $xen_stable_libs"
2170 then
2171 xen_ctrl_version=40800
2172 xen=enabled
2173 elif
2174 cat > $TMPC <<EOF &&
2176 * If we have stable libs the we don't want the libxc compat
2177 * layers, regardless of what CFLAGS we may have been given.
2179 #undef XC_WANT_COMPAT_EVTCHN_API
2180 #undef XC_WANT_COMPAT_GNTTAB_API
2181 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
2182 #include <xenctrl.h>
2183 #include <xenstore.h>
2184 #include <xenevtchn.h>
2185 #include <xengnttab.h>
2186 #include <xenforeignmemory.h>
2187 #include <stdint.h>
2188 #include <xen/hvm/hvm_info_table.h>
2189 #if !defined(HVM_MAX_VCPUS)
2190 # error HVM_MAX_VCPUS not defined
2191 #endif
2192 int main(void) {
2193 xc_interface *xc = NULL;
2194 xenforeignmemory_handle *xfmem;
2195 xenevtchn_handle *xe;
2196 xengnttab_handle *xg;
2198 xs_daemon_open();
2200 xc = xc_interface_open(0, 0, 0);
2201 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2202 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2203 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2204 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2206 xfmem = xenforeignmemory_open(0, 0);
2207 xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2209 xe = xenevtchn_open(0, 0);
2210 xenevtchn_fd(xe);
2212 xg = xengnttab_open(0, 0);
2213 xengnttab_map_grant_ref(xg, 0, 0, 0);
2215 return 0;
2218 compile_prog "" "$xen_libs $xen_stable_libs"
2219 then
2220 xen_ctrl_version=40701
2221 xen=enabled
2223 # Xen 4.6
2224 elif
2225 cat > $TMPC <<EOF &&
2226 #include <xenctrl.h>
2227 #include <xenstore.h>
2228 #include <stdint.h>
2229 #include <xen/hvm/hvm_info_table.h>
2230 #if !defined(HVM_MAX_VCPUS)
2231 # error HVM_MAX_VCPUS not defined
2232 #endif
2233 int main(void) {
2234 xc_interface *xc;
2235 xs_daemon_open();
2236 xc = xc_interface_open(0, 0, 0);
2237 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2238 xc_gnttab_open(NULL, 0);
2239 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2240 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2241 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2242 xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
2243 return 0;
2246 compile_prog "" "$xen_libs"
2247 then
2248 xen_ctrl_version=40600
2249 xen=enabled
2251 # Xen 4.5
2252 elif
2253 cat > $TMPC <<EOF &&
2254 #include <xenctrl.h>
2255 #include <xenstore.h>
2256 #include <stdint.h>
2257 #include <xen/hvm/hvm_info_table.h>
2258 #if !defined(HVM_MAX_VCPUS)
2259 # error HVM_MAX_VCPUS not defined
2260 #endif
2261 int main(void) {
2262 xc_interface *xc;
2263 xs_daemon_open();
2264 xc = xc_interface_open(0, 0, 0);
2265 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2266 xc_gnttab_open(NULL, 0);
2267 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2268 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2269 xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
2270 return 0;
2273 compile_prog "" "$xen_libs"
2274 then
2275 xen_ctrl_version=40500
2276 xen=enabled
2278 elif
2279 cat > $TMPC <<EOF &&
2280 #include <xenctrl.h>
2281 #include <xenstore.h>
2282 #include <stdint.h>
2283 #include <xen/hvm/hvm_info_table.h>
2284 #if !defined(HVM_MAX_VCPUS)
2285 # error HVM_MAX_VCPUS not defined
2286 #endif
2287 int main(void) {
2288 xc_interface *xc;
2289 xs_daemon_open();
2290 xc = xc_interface_open(0, 0, 0);
2291 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2292 xc_gnttab_open(NULL, 0);
2293 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2294 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2295 return 0;
2298 compile_prog "" "$xen_libs"
2299 then
2300 xen_ctrl_version=40200
2301 xen=enabled
2303 else
2304 if test "$xen" = "enabled" ; then
2305 feature_not_found "xen (unsupported version)" \
2306 "Install a supported xen (xen 4.2 or newer)"
2308 xen=disabled
2311 if test "$xen" = enabled; then
2312 if test $xen_ctrl_version -ge 40701 ; then
2313 xen_libs="$xen_libs $xen_stable_libs "
2319 ##########################################
2320 # RDMA needs OpenFabrics libraries
2321 if test "$rdma" != "no" ; then
2322 cat > $TMPC <<EOF
2323 #include <rdma/rdma_cma.h>
2324 int main(void) { return 0; }
2326 rdma_libs="-lrdmacm -libverbs -libumad"
2327 if compile_prog "" "$rdma_libs" ; then
2328 rdma="yes"
2329 else
2330 if test "$rdma" = "yes" ; then
2331 error_exit \
2332 " OpenFabrics librdmacm/libibverbs/libibumad not present." \
2333 " Your options:" \
2334 " (1) Fast: Install infiniband packages (devel) from your distro." \
2335 " (2) Cleanest: Install libraries from www.openfabrics.org" \
2336 " (3) Also: Install softiwarp if you don't have RDMA hardware"
2338 rdma="no"
2342 ##########################################
2343 # PVRDMA detection
2345 cat > $TMPC <<EOF &&
2346 #include <sys/mman.h>
2349 main(void)
2351 char buf = 0;
2352 void *addr = &buf;
2353 addr = mremap(addr, 0, 1, MREMAP_MAYMOVE | MREMAP_FIXED);
2355 return 0;
2359 if test "$rdma" = "yes" ; then
2360 case "$pvrdma" in
2362 if compile_prog "" ""; then
2363 pvrdma="yes"
2364 else
2365 pvrdma="no"
2368 "yes")
2369 if ! compile_prog "" ""; then
2370 error_exit "PVRDMA is not supported since mremap is not implemented"
2372 pvrdma="yes"
2374 "no")
2375 pvrdma="no"
2377 esac
2378 else
2379 if test "$pvrdma" = "yes" ; then
2380 error_exit "PVRDMA requires rdma suppport"
2382 pvrdma="no"
2385 # Let's see if enhanced reg_mr is supported
2386 if test "$pvrdma" = "yes" ; then
2388 cat > $TMPC <<EOF &&
2389 #include <infiniband/verbs.h>
2392 main(void)
2394 struct ibv_mr *mr;
2395 struct ibv_pd *pd = NULL;
2396 size_t length = 10;
2397 uint64_t iova = 0;
2398 int access = 0;
2399 void *addr = NULL;
2401 mr = ibv_reg_mr_iova(pd, addr, length, iova, access);
2403 ibv_dereg_mr(mr);
2405 return 0;
2408 if ! compile_prog "" "-libverbs"; then
2409 QEMU_CFLAGS="$QEMU_CFLAGS -DLEGACY_RDMA_REG_MR"
2413 ##########################################
2414 # xfsctl() probe, used for file-posix.c
2415 if test "$xfs" != "no" ; then
2416 cat > $TMPC << EOF
2417 #include <stddef.h> /* NULL */
2418 #include <xfs/xfs.h>
2419 int main(void)
2421 xfsctl(NULL, 0, 0, NULL);
2422 return 0;
2425 if compile_prog "" "" ; then
2426 xfs="yes"
2427 else
2428 if test "$xfs" = "yes" ; then
2429 feature_not_found "xfs" "Install xfsprogs/xfslibs devel"
2431 xfs=no
2435 ##########################################
2436 # plugin linker support probe
2438 if test "$plugins" != "no"; then
2440 #########################################
2441 # See if --dynamic-list is supported by the linker
2443 ld_dynamic_list="no"
2444 cat > $TMPTXT <<EOF
2446 foo;
2450 cat > $TMPC <<EOF
2451 #include <stdio.h>
2452 void foo(void);
2454 void foo(void)
2456 printf("foo\n");
2459 int main(void)
2461 foo();
2462 return 0;
2466 if compile_prog "" "-Wl,--dynamic-list=$TMPTXT" ; then
2467 ld_dynamic_list="yes"
2470 #########################################
2471 # See if -exported_symbols_list is supported by the linker
2473 ld_exported_symbols_list="no"
2474 cat > $TMPTXT <<EOF
2475 _foo
2478 if compile_prog "" "-Wl,-exported_symbols_list,$TMPTXT" ; then
2479 ld_exported_symbols_list="yes"
2482 if test "$ld_dynamic_list" = "no" &&
2483 test "$ld_exported_symbols_list" = "no" ; then
2484 if test "$plugins" = "yes"; then
2485 error_exit \
2486 "Plugin support requires dynamic linking and specifying a set of symbols " \
2487 "that are exported to plugins. Unfortunately your linker doesn't " \
2488 "support the flag (--dynamic-list or -exported_symbols_list) used " \
2489 "for this purpose."
2490 else
2491 plugins="no"
2493 else
2494 plugins="yes"
2498 ##########################################
2499 # glib support probe
2501 glib_req_ver=2.56
2502 glib_modules=gthread-2.0
2503 if test "$modules" = yes; then
2504 glib_modules="$glib_modules gmodule-export-2.0"
2505 elif test "$plugins" = "yes"; then
2506 glib_modules="$glib_modules gmodule-no-export-2.0"
2509 for i in $glib_modules; do
2510 if $pkg_config --atleast-version=$glib_req_ver $i; then
2511 glib_cflags=$($pkg_config --cflags $i)
2512 glib_libs=$($pkg_config --libs $i)
2513 else
2514 error_exit "glib-$glib_req_ver $i is required to compile QEMU"
2516 done
2518 # This workaround is required due to a bug in pkg-config file for glib as it
2519 # doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
2521 if test "$static" = yes && test "$mingw32" = yes; then
2522 glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
2525 if ! test "$gio" = "no"; then
2526 pass=no
2527 if $pkg_config --atleast-version=$glib_req_ver gio-2.0; then
2528 gio_cflags=$($pkg_config --cflags gio-2.0)
2529 gio_libs=$($pkg_config --libs gio-2.0)
2530 gdbus_codegen=$($pkg_config --variable=gdbus_codegen gio-2.0)
2531 if ! has "$gdbus_codegen"; then
2532 gdbus_codegen=
2534 # Check that the libraries actually work -- Ubuntu 18.04 ships
2535 # with pkg-config --static --libs data for gio-2.0 that is missing
2536 # -lblkid and will give a link error.
2537 cat > $TMPC <<EOF
2538 #include <gio/gio.h>
2539 int main(void)
2541 g_dbus_proxy_new_sync(0, 0, 0, 0, 0, 0, 0, 0);
2542 return 0;
2545 if compile_prog "$gio_cflags" "$gio_libs" ; then
2546 pass=yes
2547 else
2548 pass=no
2551 if test "$pass" = "yes" &&
2552 $pkg_config --atleast-version=$glib_req_ver gio-unix-2.0; then
2553 gio_cflags="$gio_cflags $($pkg_config --cflags gio-unix-2.0)"
2554 gio_libs="$gio_libs $($pkg_config --libs gio-unix-2.0)"
2558 if test "$pass" = "no"; then
2559 if test "$gio" = "yes"; then
2560 feature_not_found "gio" "Install libgio >= 2.0"
2561 else
2562 gio=no
2564 else
2565 gio=yes
2569 # Sanity check that the current size_t matches the
2570 # size that glib thinks it should be. This catches
2571 # problems on multi-arch where people try to build
2572 # 32-bit QEMU while pointing at 64-bit glib headers
2573 cat > $TMPC <<EOF
2574 #include <glib.h>
2575 #include <unistd.h>
2577 #define QEMU_BUILD_BUG_ON(x) \
2578 typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
2580 int main(void) {
2581 QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
2582 return 0;
2586 if ! compile_prog "$glib_cflags" "$glib_libs" ; then
2587 error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
2588 "You probably need to set PKG_CONFIG_LIBDIR"\
2589 "to point to the right pkg-config files for your"\
2590 "build target"
2593 # Silence clang warnings triggered by glib < 2.57.2
2594 cat > $TMPC << EOF
2595 #include <glib.h>
2596 typedef struct Foo {
2597 int i;
2598 } Foo;
2599 static void foo_free(Foo *f)
2601 g_free(f);
2603 G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free);
2604 int main(void) { return 0; }
2606 if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
2607 if cc_has_warning_flag "-Wno-unused-function"; then
2608 glib_cflags="$glib_cflags -Wno-unused-function"
2609 CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
2613 ##########################################
2614 # SHA command probe for modules
2615 if test "$modules" = yes; then
2616 shacmd_probe="sha1sum sha1 shasum"
2617 for c in $shacmd_probe; do
2618 if has $c; then
2619 shacmd="$c"
2620 break
2622 done
2623 if test "$shacmd" = ""; then
2624 error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
2628 ##########################################
2629 # libssh probe
2630 if test "$libssh" != "no" ; then
2631 if $pkg_config --exists "libssh >= 0.8.7"; then
2632 libssh_cflags=$($pkg_config libssh --cflags)
2633 libssh_libs=$($pkg_config libssh --libs)
2634 libssh=yes
2635 else
2636 if test "$libssh" = "yes" ; then
2637 error_exit "libssh required for --enable-libssh"
2639 libssh=no
2643 ##########################################
2644 # TPM emulation is only on POSIX
2646 if test "$tpm" = ""; then
2647 if test "$mingw32" = "yes"; then
2648 tpm=no
2649 else
2650 tpm=yes
2652 elif test "$tpm" = "yes"; then
2653 if test "$mingw32" = "yes" ; then
2654 error_exit "TPM emulation only available on POSIX systems"
2658 ##########################################
2659 # fdt probe
2661 case "$fdt" in
2662 auto | enabled | internal)
2663 # Simpler to always update submodule, even if not needed.
2664 git_submodules="${git_submodules} dtc"
2666 esac
2668 ##########################################
2669 # opengl probe (for sdl2, gtk)
2671 if test "$opengl" != "no" ; then
2672 epoxy=no
2673 if $pkg_config epoxy; then
2674 cat > $TMPC << EOF
2675 #include <epoxy/egl.h>
2676 int main(void) { return 0; }
2678 if compile_prog "" "" ; then
2679 epoxy=yes
2683 if test "$epoxy" = "yes" ; then
2684 opengl_cflags="$($pkg_config --cflags epoxy)"
2685 opengl_libs="$($pkg_config --libs epoxy)"
2686 opengl=yes
2687 else
2688 if test "$opengl" = "yes" ; then
2689 feature_not_found "opengl" "Please install epoxy with EGL"
2691 opengl_cflags=""
2692 opengl_libs=""
2693 opengl=no
2697 ##########################################
2698 # libnuma probe
2700 if test "$numa" != "no" ; then
2701 cat > $TMPC << EOF
2702 #include <numa.h>
2703 int main(void) { return numa_available(); }
2706 if compile_prog "" "-lnuma" ; then
2707 numa=yes
2708 numa_libs="-lnuma"
2709 else
2710 if test "$numa" = "yes" ; then
2711 feature_not_found "numa" "install numactl devel"
2713 numa=no
2717 # check for usbfs
2718 have_usbfs=no
2719 if test "$linux_user" = "yes"; then
2720 cat > $TMPC << EOF
2721 #include <linux/usbdevice_fs.h>
2723 #ifndef USBDEVFS_GET_CAPABILITIES
2724 #error "USBDEVFS_GET_CAPABILITIES undefined"
2725 #endif
2727 #ifndef USBDEVFS_DISCONNECT_CLAIM
2728 #error "USBDEVFS_DISCONNECT_CLAIM undefined"
2729 #endif
2731 int main(void)
2733 return 0;
2736 if compile_prog "" ""; then
2737 have_usbfs=yes
2741 ##########################################
2742 # check if we have VSS SDK headers for win
2744 if test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
2745 test "$vss_win32_sdk" != "no" ; then
2746 case "$vss_win32_sdk" in
2747 "") vss_win32_include="-isystem $source_path" ;;
2748 *\ *) # The SDK is installed in "Program Files" by default, but we cannot
2749 # handle path with spaces. So we symlink the headers into ".sdk/vss".
2750 vss_win32_include="-isystem $source_path/.sdk/vss"
2751 symlink "$vss_win32_sdk/inc" "$source_path/.sdk/vss/inc"
2753 *) vss_win32_include="-isystem $vss_win32_sdk"
2754 esac
2755 cat > $TMPC << EOF
2756 #define __MIDL_user_allocate_free_DEFINED__
2757 #include <inc/win2003/vss.h>
2758 int main(void) { return VSS_CTX_BACKUP; }
2760 if compile_prog "$vss_win32_include" "" ; then
2761 guest_agent_with_vss="yes"
2762 QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
2763 libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++ -Wl,--enable-stdcall-fixup $libs_qga"
2764 qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb"
2765 else
2766 if test "$vss_win32_sdk" != "" ; then
2767 echo "ERROR: Please download and install Microsoft VSS SDK:"
2768 echo "ERROR: http://www.microsoft.com/en-us/download/details.aspx?id=23490"
2769 echo "ERROR: On POSIX-systems, you can extract the SDK headers by:"
2770 echo "ERROR: scripts/extract-vsssdk-headers setup.exe"
2771 echo "ERROR: The headers are extracted in the directory \`inc'."
2772 feature_not_found "VSS support"
2774 guest_agent_with_vss="no"
2778 ##########################################
2779 # lookup Windows platform SDK (if not specified)
2780 # The SDK is needed only to build .tlb (type library) file of guest agent
2781 # VSS provider from the source. It is usually unnecessary because the
2782 # pre-compiled .tlb file is included.
2784 if test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
2785 test "$guest_agent_with_vss" = "yes" ; then
2786 if test -z "$win_sdk"; then
2787 programfiles="$PROGRAMFILES"
2788 test -n "$PROGRAMW6432" && programfiles="$PROGRAMW6432"
2789 if test -n "$programfiles"; then
2790 win_sdk=$(ls -d "$programfiles/Microsoft SDKs/Windows/v"* | tail -1) 2>/dev/null
2791 else
2792 feature_not_found "Windows SDK"
2794 elif test "$win_sdk" = "no"; then
2795 win_sdk=""
2799 ##########################################
2800 # check if mingw environment provides a recent ntddscsi.h
2801 if test "$mingw32" = "yes" && test "$guest_agent" != "no"; then
2802 cat > $TMPC << EOF
2803 #include <windows.h>
2804 #include <ntddscsi.h>
2805 int main(void) {
2806 #if !defined(IOCTL_SCSI_GET_ADDRESS)
2807 #error Missing required ioctl definitions
2808 #endif
2809 SCSI_ADDRESS addr = { .Lun = 0, .TargetId = 0, .PathId = 0 };
2810 return addr.Lun;
2813 if compile_prog "" "" ; then
2814 guest_agent_ntddscsi=yes
2815 libs_qga="-lsetupapi -lcfgmgr32 $libs_qga"
2819 ##########################################
2820 # capstone
2822 case "$capstone" in
2823 auto | enabled | internal)
2824 # Simpler to always update submodule, even if not needed.
2825 git_submodules="${git_submodules} capstone"
2827 esac
2829 ##########################################
2830 # check and set a backend for coroutine
2832 # We prefer ucontext, but it's not always possible. The fallback
2833 # is sigcontext. On Windows the only valid backend is the Windows
2834 # specific one.
2836 ucontext_works=no
2837 if test "$darwin" != "yes"; then
2838 cat > $TMPC << EOF
2839 #include <ucontext.h>
2840 #ifdef __stub_makecontext
2841 #error Ignoring glibc stub makecontext which will always fail
2842 #endif
2843 int main(void) { makecontext(0, 0, 0); return 0; }
2845 if compile_prog "" "" ; then
2846 ucontext_works=yes
2850 if test "$coroutine" = ""; then
2851 if test "$mingw32" = "yes"; then
2852 coroutine=win32
2853 elif test "$ucontext_works" = "yes"; then
2854 coroutine=ucontext
2855 else
2856 coroutine=sigaltstack
2858 else
2859 case $coroutine in
2860 windows)
2861 if test "$mingw32" != "yes"; then
2862 error_exit "'windows' coroutine backend only valid for Windows"
2864 # Unfortunately the user visible backend name doesn't match the
2865 # coroutine-*.c filename for this case, so we have to adjust it here.
2866 coroutine=win32
2868 ucontext)
2869 if test "$ucontext_works" != "yes"; then
2870 feature_not_found "ucontext"
2873 sigaltstack)
2874 if test "$mingw32" = "yes"; then
2875 error_exit "only the 'windows' coroutine backend is valid for Windows"
2879 error_exit "unknown coroutine backend $coroutine"
2881 esac
2884 if test "$coroutine_pool" = ""; then
2885 coroutine_pool=yes
2888 if test "$debug_stack_usage" = "yes"; then
2889 if test "$coroutine_pool" = "yes"; then
2890 echo "WARN: disabling coroutine pool for stack usage debugging"
2891 coroutine_pool=no
2895 ##################################################
2896 # SafeStack
2899 if test "$safe_stack" = "yes"; then
2900 cat > $TMPC << EOF
2901 int main(int argc, char *argv[])
2903 #if ! __has_feature(safe_stack)
2904 #error SafeStack Disabled
2905 #endif
2906 return 0;
2909 flag="-fsanitize=safe-stack"
2910 # Check that safe-stack is supported and enabled.
2911 if compile_prog "-Werror $flag" "$flag"; then
2912 # Flag needed both at compilation and at linking
2913 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2914 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
2915 else
2916 error_exit "SafeStack not supported by your compiler"
2918 if test "$coroutine" != "ucontext"; then
2919 error_exit "SafeStack is only supported by the coroutine backend ucontext"
2921 else
2922 cat > $TMPC << EOF
2923 int main(int argc, char *argv[])
2925 #if defined(__has_feature)
2926 #if __has_feature(safe_stack)
2927 #error SafeStack Enabled
2928 #endif
2929 #endif
2930 return 0;
2933 if test "$safe_stack" = "no"; then
2934 # Make sure that safe-stack is disabled
2935 if ! compile_prog "-Werror" ""; then
2936 # SafeStack was already enabled, try to explicitly remove the feature
2937 flag="-fno-sanitize=safe-stack"
2938 if ! compile_prog "-Werror $flag" "$flag"; then
2939 error_exit "Configure cannot disable SafeStack"
2941 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2942 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
2944 else # "$safe_stack" = ""
2945 # Set safe_stack to yes or no based on pre-existing flags
2946 if compile_prog "-Werror" ""; then
2947 safe_stack="no"
2948 else
2949 safe_stack="yes"
2950 if test "$coroutine" != "ucontext"; then
2951 error_exit "SafeStack is only supported by the coroutine backend ucontext"
2957 ########################################
2958 # check if cpuid.h is usable.
2960 cat > $TMPC << EOF
2961 #include <cpuid.h>
2962 int main(void) {
2963 unsigned a, b, c, d;
2964 int max = __get_cpuid_max(0, 0);
2966 if (max >= 1) {
2967 __cpuid(1, a, b, c, d);
2970 if (max >= 7) {
2971 __cpuid_count(7, 0, a, b, c, d);
2974 return 0;
2977 if compile_prog "" "" ; then
2978 cpuid_h=yes
2981 ##########################################
2982 # avx2 optimization requirement check
2984 # There is no point enabling this if cpuid.h is not usable,
2985 # since we won't be able to select the new routines.
2987 if test "$cpuid_h" = "yes" && test "$avx2_opt" != "no"; then
2988 cat > $TMPC << EOF
2989 #pragma GCC push_options
2990 #pragma GCC target("avx2")
2991 #include <cpuid.h>
2992 #include <immintrin.h>
2993 static int bar(void *a) {
2994 __m256i x = *(__m256i *)a;
2995 return _mm256_testz_si256(x, x);
2997 int main(int argc, char *argv[]) { return bar(argv[0]); }
2999 if compile_object "-Werror" ; then
3000 avx2_opt="yes"
3001 else
3002 avx2_opt="no"
3006 ##########################################
3007 # avx512f optimization requirement check
3009 # There is no point enabling this if cpuid.h is not usable,
3010 # since we won't be able to select the new routines.
3011 # by default, it is turned off.
3012 # if user explicitly want to enable it, check environment
3014 if test "$cpuid_h" = "yes" && test "$avx512f_opt" = "yes"; then
3015 cat > $TMPC << EOF
3016 #pragma GCC push_options
3017 #pragma GCC target("avx512f")
3018 #include <cpuid.h>
3019 #include <immintrin.h>
3020 static int bar(void *a) {
3021 __m512i x = *(__m512i *)a;
3022 return _mm512_test_epi64_mask(x, x);
3024 int main(int argc, char *argv[])
3026 return bar(argv[0]);
3029 if ! compile_object "-Werror" ; then
3030 avx512f_opt="no"
3032 else
3033 avx512f_opt="no"
3036 ########################################
3037 # check if __[u]int128_t is usable.
3039 int128=no
3040 cat > $TMPC << EOF
3041 __int128_t a;
3042 __uint128_t b;
3043 int main (void) {
3044 a = a + b;
3045 b = a * b;
3046 a = a * a;
3047 return 0;
3050 if compile_prog "" "" ; then
3051 int128=yes
3054 #########################################
3055 # See if 128-bit atomic operations are supported.
3057 atomic128=no
3058 if test "$int128" = "yes"; then
3059 cat > $TMPC << EOF
3060 int main(void)
3062 unsigned __int128 x = 0, y = 0;
3063 y = __atomic_load(&x, 0);
3064 __atomic_store(&x, y, 0);
3065 __atomic_compare_exchange(&x, &y, x, 0, 0, 0);
3066 return 0;
3069 if compile_prog "" "" ; then
3070 atomic128=yes
3074 cmpxchg128=no
3075 if test "$int128" = yes && test "$atomic128" = no; then
3076 cat > $TMPC << EOF
3077 int main(void)
3079 unsigned __int128 x = 0, y = 0;
3080 __sync_val_compare_and_swap_16(&x, y, x);
3081 return 0;
3084 if compile_prog "" "" ; then
3085 cmpxchg128=yes
3089 ########################################
3090 # check if ccache is interfering with
3091 # semantic analysis of macros
3093 unset CCACHE_CPP2
3094 ccache_cpp2=no
3095 cat > $TMPC << EOF
3096 static const int Z = 1;
3097 #define fn() ({ Z; })
3098 #define TAUT(X) ((X) == Z)
3099 #define PAREN(X, Y) (X == Y)
3100 #define ID(X) (X)
3101 int main(int argc, char *argv[])
3103 int x = 0, y = 0;
3104 x = ID(x);
3105 x = fn();
3106 fn();
3107 if (PAREN(x, y)) return 0;
3108 if (TAUT(Z)) return 0;
3109 return 0;
3113 if ! compile_object "-Werror"; then
3114 ccache_cpp2=yes
3117 #################################################
3118 # clang does not support glibc + FORTIFY_SOURCE.
3120 if test "$fortify_source" != "no"; then
3121 if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
3122 fortify_source="no";
3123 elif test -n "$cxx" && has $cxx &&
3124 echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
3125 fortify_source="no";
3126 else
3127 fortify_source="yes"
3131 ##########################################
3132 # check for usable membarrier system call
3133 if test "$membarrier" = "yes"; then
3134 have_membarrier=no
3135 if test "$mingw32" = "yes" ; then
3136 have_membarrier=yes
3137 elif test "$linux" = "yes" ; then
3138 cat > $TMPC << EOF
3139 #include <linux/membarrier.h>
3140 #include <sys/syscall.h>
3141 #include <unistd.h>
3142 #include <stdlib.h>
3143 int main(void) {
3144 syscall(__NR_membarrier, MEMBARRIER_CMD_QUERY, 0);
3145 syscall(__NR_membarrier, MEMBARRIER_CMD_SHARED, 0);
3146 exit(0);
3149 if compile_prog "" "" ; then
3150 have_membarrier=yes
3153 if test "$have_membarrier" = "no"; then
3154 feature_not_found "membarrier" "membarrier system call not available"
3156 else
3157 # Do not enable it by default even for Mingw32, because it doesn't
3158 # work on Wine.
3159 membarrier=no
3162 ##########################################
3163 # check for usable AF_ALG environment
3164 have_afalg=no
3165 cat > $TMPC << EOF
3166 #include <errno.h>
3167 #include <sys/types.h>
3168 #include <sys/socket.h>
3169 #include <linux/if_alg.h>
3170 int main(void) {
3171 int sock;
3172 sock = socket(AF_ALG, SOCK_SEQPACKET, 0);
3173 return sock;
3176 if compile_prog "" "" ; then
3177 have_afalg=yes
3179 if test "$crypto_afalg" = "yes"
3180 then
3181 if test "$have_afalg" != "yes"
3182 then
3183 error_exit "AF_ALG requested but could not be detected"
3188 ##########################################
3189 # checks for sanitizers
3191 have_asan=no
3192 have_ubsan=no
3193 have_asan_iface_h=no
3194 have_asan_iface_fiber=no
3196 if test "$sanitizers" = "yes" ; then
3197 write_c_skeleton
3198 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
3199 have_asan=yes
3202 # we could use a simple skeleton for flags checks, but this also
3203 # detect the static linking issue of ubsan, see also:
3204 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
3205 cat > $TMPC << EOF
3206 #include <stdlib.h>
3207 int main(void) {
3208 void *tmp = malloc(10);
3209 if (tmp != NULL) {
3210 return *(int *)(tmp + 2);
3212 return 1;
3215 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
3216 have_ubsan=yes
3219 if check_include "sanitizer/asan_interface.h" ; then
3220 have_asan_iface_h=yes
3223 cat > $TMPC << EOF
3224 #include <sanitizer/asan_interface.h>
3225 int main(void) {
3226 __sanitizer_start_switch_fiber(0, 0, 0);
3227 return 0;
3230 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
3231 have_asan_iface_fiber=yes
3235 # Thread sanitizer is, for now, much noisier than the other sanitizers;
3236 # keep it separate until that is not the case.
3237 if test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
3238 error_exit "TSAN is not supported with other sanitiziers."
3240 have_tsan=no
3241 have_tsan_iface_fiber=no
3242 if test "$tsan" = "yes" ; then
3243 write_c_skeleton
3244 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
3245 have_tsan=yes
3247 cat > $TMPC << EOF
3248 #include <sanitizer/tsan_interface.h>
3249 int main(void) {
3250 __tsan_create_fiber(0);
3251 return 0;
3254 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
3255 have_tsan_iface_fiber=yes
3259 ##########################################
3260 # check for slirp
3262 case "$slirp" in
3263 auto | enabled | internal)
3264 # Simpler to always update submodule, even if not needed.
3265 git_submodules="${git_submodules} slirp"
3267 esac
3269 # Check for slirp smbd dupport
3270 : ${smbd=${SMBD-/usr/sbin/smbd}}
3271 if test "$slirp_smbd" != "no" ; then
3272 if test "$mingw32" = "yes" ; then
3273 if test "$slirp_smbd" = "yes" ; then
3274 error_exit "Host smbd not supported on this platform."
3276 slirp_smbd=no
3277 else
3278 slirp_smbd=yes
3282 ##########################################
3283 # check for usable __NR_keyctl syscall
3285 if test "$linux" = "yes" ; then
3287 have_keyring=no
3288 cat > $TMPC << EOF
3289 #include <errno.h>
3290 #include <asm/unistd.h>
3291 #include <linux/keyctl.h>
3292 #include <unistd.h>
3293 int main(void) {
3294 return syscall(__NR_keyctl, KEYCTL_READ, 0, NULL, NULL, 0);
3297 if compile_prog "" "" ; then
3298 have_keyring=yes
3301 if test "$secret_keyring" != "no"
3302 then
3303 if test "$have_keyring" = "yes"
3304 then
3305 secret_keyring=yes
3306 else
3307 if test "$secret_keyring" = "yes"
3308 then
3309 error_exit "syscall __NR_keyctl requested, \
3310 but not implemented on your system"
3311 else
3312 secret_keyring=no
3317 ##########################################
3318 # End of CC checks
3319 # After here, no more $cc or $ld runs
3321 write_c_skeleton
3323 if test "$gcov" = "yes" ; then
3325 elif test "$fortify_source" = "yes" ; then
3326 QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
3327 debug=no
3330 case "$ARCH" in
3331 alpha)
3332 # Ensure there's only a single GP
3333 QEMU_CFLAGS="-msmall-data $QEMU_CFLAGS"
3335 esac
3337 if test "$gprof" = "yes" ; then
3338 QEMU_CFLAGS="-p $QEMU_CFLAGS"
3339 QEMU_LDFLAGS="-p $QEMU_LDFLAGS"
3342 if test "$have_asan" = "yes"; then
3343 QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
3344 QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
3345 if test "$have_asan_iface_h" = "no" ; then
3346 echo "ASAN build enabled, but ASAN header missing." \
3347 "Without code annotation, the report may be inferior."
3348 elif test "$have_asan_iface_fiber" = "no" ; then
3349 echo "ASAN build enabled, but ASAN header is too old." \
3350 "Without code annotation, the report may be inferior."
3353 if test "$have_tsan" = "yes" ; then
3354 if test "$have_tsan_iface_fiber" = "yes" ; then
3355 QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
3356 QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
3357 else
3358 error_exit "Cannot enable TSAN due to missing fiber annotation interface."
3360 elif test "$tsan" = "yes" ; then
3361 error_exit "Cannot enable TSAN due to missing sanitize thread interface."
3363 if test "$have_ubsan" = "yes"; then
3364 QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
3365 QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
3368 ##########################################
3370 # Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
3371 if test "$solaris" = "no" && test "$tsan" = "no"; then
3372 if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
3373 QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
3377 # Use ASLR, no-SEH and DEP if available
3378 if test "$mingw32" = "yes" ; then
3379 flags="--no-seh --nxcompat"
3381 # Disable ASLR for debug builds to allow debugging with gdb
3382 if test "$debug" = "no" ; then
3383 flags="--dynamicbase $flags"
3386 for flag in $flags; do
3387 if ld_has $flag ; then
3388 QEMU_LDFLAGS="-Wl,$flag $QEMU_LDFLAGS"
3390 done
3393 # Probe for guest agent support/options
3395 if [ "$guest_agent" != "no" ]; then
3396 if [ "$softmmu" = no -a "$want_tools" = no ] ; then
3397 guest_agent=no
3398 elif [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" -o "$mingw32" = "yes" ] ; then
3399 guest_agent=yes
3400 elif [ "$guest_agent" != yes ]; then
3401 guest_agent=no
3402 else
3403 error_exit "Guest agent is not supported on this platform"
3407 # Guest agent Windows MSI package
3409 if test "$QEMU_GA_MANUFACTURER" = ""; then
3410 QEMU_GA_MANUFACTURER=QEMU
3412 if test "$QEMU_GA_DISTRO" = ""; then
3413 QEMU_GA_DISTRO=Linux
3415 if test "$QEMU_GA_VERSION" = ""; then
3416 QEMU_GA_VERSION=$(cat $source_path/VERSION)
3419 QEMU_GA_MSI_MINGW_DLL_PATH="$($pkg_config --variable=prefix glib-2.0)/bin"
3421 # Mac OS X ships with a broken assembler
3422 roms=
3423 if { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \
3424 test "$targetos" != "Darwin" && test "$targetos" != "SunOS" && \
3425 test "$targetos" != "Haiku" && test "$softmmu" = yes ; then
3426 # Different host OS linkers have different ideas about the name of the ELF
3427 # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
3428 # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
3429 for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
3430 if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
3431 ld_i386_emulation="$emu"
3432 roms="optionrom"
3433 break
3435 done
3438 # Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
3439 # or -march=z10 (which is the lowest architecture level that Clang supports)
3440 if test "$cpu" = "s390x" ; then
3441 write_c_skeleton
3442 compile_prog "-march=z900" ""
3443 has_z900=$?
3444 if [ $has_z900 = 0 ] || compile_object "-march=z10 -msoft-float -Werror"; then
3445 if [ $has_z900 != 0 ]; then
3446 echo "WARNING: Your compiler does not support the z900!"
3447 echo " The s390-ccw bios will only work with guest CPUs >= z10."
3449 roms="$roms s390-ccw"
3450 # SLOF is required for building the s390-ccw firmware on s390x,
3451 # since it is using the libnet code from SLOF for network booting.
3452 git_submodules="${git_submodules} roms/SLOF"
3456 # Check that the C++ compiler exists and works with the C compiler.
3457 # All the QEMU_CXXFLAGS are based on QEMU_CFLAGS. Keep this at the end to don't miss any other that could be added.
3458 if has $cxx; then
3459 cat > $TMPC <<EOF
3460 int c_function(void);
3461 int main(void) { return c_function(); }
3464 compile_object
3466 cat > $TMPCXX <<EOF
3467 extern "C" {
3468 int c_function(void);
3470 int c_function(void) { return 42; }
3473 update_cxxflags
3475 if do_cxx $CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
3476 # C++ compiler $cxx works ok with C compiler $cc
3478 else
3479 echo "C++ compiler $cxx does not work with C compiler $cc"
3480 echo "Disabling C++ specific optional code"
3481 cxx=
3483 else
3484 echo "No C++ compiler available; disabling C++ specific optional code"
3485 cxx=
3488 if !(GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
3489 exit 1
3492 config_host_mak="config-host.mak"
3494 echo "# Automatically generated by configure - do not modify" > $config_host_mak
3495 echo >> $config_host_mak
3497 echo all: >> $config_host_mak
3498 echo "GIT=$git" >> $config_host_mak
3499 echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
3500 echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
3502 echo "ARCH=$ARCH" >> $config_host_mak
3504 if test "$debug_tcg" = "yes" ; then
3505 echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
3507 if test "$strip_opt" = "yes" ; then
3508 echo "STRIP=${strip}" >> $config_host_mak
3510 if test "$mingw32" = "yes" ; then
3511 echo "CONFIG_WIN32=y" >> $config_host_mak
3512 if test "$guest_agent_with_vss" = "yes" ; then
3513 echo "CONFIG_QGA_VSS=y" >> $config_host_mak
3514 echo "QGA_VSS_PROVIDER=$qga_vss_provider" >> $config_host_mak
3515 echo "WIN_SDK=\"$win_sdk\"" >> $config_host_mak
3517 if test "$guest_agent_ntddscsi" = "yes" ; then
3518 echo "CONFIG_QGA_NTDDSCSI=y" >> $config_host_mak
3520 echo "QEMU_GA_MSI_MINGW_DLL_PATH=${QEMU_GA_MSI_MINGW_DLL_PATH}" >> $config_host_mak
3521 echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
3522 echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
3523 echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
3524 else
3525 echo "CONFIG_POSIX=y" >> $config_host_mak
3528 if test "$linux" = "yes" ; then
3529 echo "CONFIG_LINUX=y" >> $config_host_mak
3532 if test "$darwin" = "yes" ; then
3533 echo "CONFIG_DARWIN=y" >> $config_host_mak
3536 if test "$solaris" = "yes" ; then
3537 echo "CONFIG_SOLARIS=y" >> $config_host_mak
3539 if test "$haiku" = "yes" ; then
3540 echo "CONFIG_HAIKU=y" >> $config_host_mak
3542 if test "$static" = "yes" ; then
3543 echo "CONFIG_STATIC=y" >> $config_host_mak
3545 if test "$profiler" = "yes" ; then
3546 echo "CONFIG_PROFILER=y" >> $config_host_mak
3548 if test "$want_tools" = "yes" ; then
3549 echo "CONFIG_TOOLS=y" >> $config_host_mak
3551 if test "$guest_agent" = "yes" ; then
3552 echo "CONFIG_GUEST_AGENT=y" >> $config_host_mak
3554 if test "$slirp_smbd" = "yes" ; then
3555 echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak
3556 echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
3558 if test "$l2tpv3" = "yes" ; then
3559 echo "CONFIG_L2TPV3=y" >> $config_host_mak
3561 if test "$gprof" = "yes" ; then
3562 echo "CONFIG_GPROF=y" >> $config_host_mak
3564 echo "CONFIG_BDRV_RW_WHITELIST=$block_drv_rw_whitelist" >> $config_host_mak
3565 echo "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
3566 if test "$block_drv_whitelist_tools" = "yes" ; then
3567 echo "CONFIG_BDRV_WHITELIST_TOOLS=y" >> $config_host_mak
3569 if test "$xfs" = "yes" ; then
3570 echo "CONFIG_XFS=y" >> $config_host_mak
3572 qemu_version=$(head $source_path/VERSION)
3573 echo "PKGVERSION=$pkgversion" >>$config_host_mak
3574 echo "SRC_PATH=$source_path" >> $config_host_mak
3575 echo "TARGET_DIRS=$target_list" >> $config_host_mak
3576 if test "$modules" = "yes"; then
3577 # $shacmd can generate a hash started with digit, which the compiler doesn't
3578 # like as an symbol. So prefix it with an underscore
3579 echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
3580 echo "CONFIG_MODULES=y" >> $config_host_mak
3582 if test "$module_upgrades" = "yes"; then
3583 echo "CONFIG_MODULE_UPGRADES=y" >> $config_host_mak
3585 if test "$have_usbfs" = "yes" ; then
3586 echo "CONFIG_USBFS=y" >> $config_host_mak
3588 if test "$gio" = "yes" ; then
3589 echo "CONFIG_GIO=y" >> $config_host_mak
3590 echo "GIO_CFLAGS=$gio_cflags" >> $config_host_mak
3591 echo "GIO_LIBS=$gio_libs" >> $config_host_mak
3593 if test "$gdbus_codegen" != "" ; then
3594 echo "GDBUS_CODEGEN=$gdbus_codegen" >> $config_host_mak
3596 echo "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak
3598 if test "$xen" = "enabled" ; then
3599 echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
3600 echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
3601 echo "XEN_CFLAGS=$xen_cflags" >> $config_host_mak
3602 echo "XEN_LIBS=$xen_libs" >> $config_host_mak
3604 if test "$vhost_scsi" = "yes" ; then
3605 echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
3607 if test "$vhost_net" = "yes" ; then
3608 echo "CONFIG_VHOST_NET=y" >> $config_host_mak
3610 if test "$vhost_net_user" = "yes" ; then
3611 echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak
3613 if test "$vhost_net_vdpa" = "yes" ; then
3614 echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak
3616 if test "$vhost_crypto" = "yes" ; then
3617 echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
3619 if test "$vhost_vsock" = "yes" ; then
3620 echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
3621 if test "$vhost_user" = "yes" ; then
3622 echo "CONFIG_VHOST_USER_VSOCK=y" >> $config_host_mak
3625 if test "$vhost_kernel" = "yes" ; then
3626 echo "CONFIG_VHOST_KERNEL=y" >> $config_host_mak
3628 if test "$vhost_user" = "yes" ; then
3629 echo "CONFIG_VHOST_USER=y" >> $config_host_mak
3631 if test "$vhost_vdpa" = "yes" ; then
3632 echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
3634 if test "$vhost_user_fs" = "yes" ; then
3635 echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak
3637 if test "$membarrier" = "yes" ; then
3638 echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
3640 if test "$tcg" = "enabled" -a "$tcg_interpreter" = "true" ; then
3641 echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
3644 if test "$opengl" = "yes" ; then
3645 echo "CONFIG_OPENGL=y" >> $config_host_mak
3646 echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
3647 echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
3650 if test "$avx2_opt" = "yes" ; then
3651 echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
3654 if test "$avx512f_opt" = "yes" ; then
3655 echo "CONFIG_AVX512F_OPT=y" >> $config_host_mak
3658 # XXX: suppress that
3659 if [ "$bsd" = "yes" ] ; then
3660 echo "CONFIG_BSD=y" >> $config_host_mak
3663 if test "$qom_cast_debug" = "yes" ; then
3664 echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak
3667 echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
3668 if test "$coroutine_pool" = "yes" ; then
3669 echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
3670 else
3671 echo "CONFIG_COROUTINE_POOL=0" >> $config_host_mak
3674 if test "$debug_stack_usage" = "yes" ; then
3675 echo "CONFIG_DEBUG_STACK_USAGE=y" >> $config_host_mak
3678 if test "$crypto_afalg" = "yes" ; then
3679 echo "CONFIG_AF_ALG=y" >> $config_host_mak
3682 if test "$have_asan_iface_fiber" = "yes" ; then
3683 echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
3686 if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
3687 echo "CONFIG_TSAN=y" >> $config_host_mak
3690 if test "$cpuid_h" = "yes" ; then
3691 echo "CONFIG_CPUID_H=y" >> $config_host_mak
3694 if test "$int128" = "yes" ; then
3695 echo "CONFIG_INT128=y" >> $config_host_mak
3698 if test "$atomic128" = "yes" ; then
3699 echo "CONFIG_ATOMIC128=y" >> $config_host_mak
3702 if test "$cmpxchg128" = "yes" ; then
3703 echo "CONFIG_CMPXCHG128=y" >> $config_host_mak
3706 if test "$libssh" = "yes" ; then
3707 echo "CONFIG_LIBSSH=y" >> $config_host_mak
3708 echo "LIBSSH_CFLAGS=$libssh_cflags" >> $config_host_mak
3709 echo "LIBSSH_LIBS=$libssh_libs" >> $config_host_mak
3712 if test "$live_block_migration" = "yes" ; then
3713 echo "CONFIG_LIVE_BLOCK_MIGRATION=y" >> $config_host_mak
3716 if test "$tpm" = "yes"; then
3717 echo 'CONFIG_TPM=y' >> $config_host_mak
3720 if test "$rdma" = "yes" ; then
3721 echo "CONFIG_RDMA=y" >> $config_host_mak
3722 echo "RDMA_LIBS=$rdma_libs" >> $config_host_mak
3725 if test "$pvrdma" = "yes" ; then
3726 echo "CONFIG_PVRDMA=y" >> $config_host_mak
3729 if test "$replication" = "yes" ; then
3730 echo "CONFIG_REPLICATION=y" >> $config_host_mak
3733 if test "$debug_mutex" = "yes" ; then
3734 echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak
3737 if test "$bochs" = "yes" ; then
3738 echo "CONFIG_BOCHS=y" >> $config_host_mak
3740 if test "$cloop" = "yes" ; then
3741 echo "CONFIG_CLOOP=y" >> $config_host_mak
3743 if test "$dmg" = "yes" ; then
3744 echo "CONFIG_DMG=y" >> $config_host_mak
3746 if test "$qcow1" = "yes" ; then
3747 echo "CONFIG_QCOW1=y" >> $config_host_mak
3749 if test "$vdi" = "yes" ; then
3750 echo "CONFIG_VDI=y" >> $config_host_mak
3752 if test "$vvfat" = "yes" ; then
3753 echo "CONFIG_VVFAT=y" >> $config_host_mak
3755 if test "$qed" = "yes" ; then
3756 echo "CONFIG_QED=y" >> $config_host_mak
3758 if test "$parallels" = "yes" ; then
3759 echo "CONFIG_PARALLELS=y" >> $config_host_mak
3762 if test "$plugins" = "yes" ; then
3763 echo "CONFIG_PLUGIN=y" >> $config_host_mak
3764 # Copy the export object list to the build dir
3765 if test "$ld_dynamic_list" = "yes" ; then
3766 echo "CONFIG_HAS_LD_DYNAMIC_LIST=yes" >> $config_host_mak
3767 ld_symbols=qemu-plugins-ld.symbols
3768 cp "$source_path/plugins/qemu-plugins.symbols" $ld_symbols
3769 elif test "$ld_exported_symbols_list" = "yes" ; then
3770 echo "CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST=yes" >> $config_host_mak
3771 ld64_symbols=qemu-plugins-ld64.symbols
3772 echo "# Automatically generated by configure - do not modify" > $ld64_symbols
3773 grep 'qemu_' "$source_path/plugins/qemu-plugins.symbols" | sed 's/;//g' | \
3774 sed -E 's/^[[:space:]]*(.*)/_\1/' >> $ld64_symbols
3775 else
3776 error_exit \
3777 "If \$plugins=yes, either \$ld_dynamic_list or " \
3778 "\$ld_exported_symbols_list should have been set to 'yes'."
3782 if test -n "$gdb_bin"; then
3783 gdb_version=$($gdb_bin --version | head -n 1)
3784 if version_ge ${gdb_version##* } 9.1; then
3785 echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
3789 if test "$secret_keyring" = "yes" ; then
3790 echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak
3793 echo "ROMS=$roms" >> $config_host_mak
3794 echo "MAKE=$make" >> $config_host_mak
3795 echo "PYTHON=$python" >> $config_host_mak
3796 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
3797 echo "MESON=$meson" >> $config_host_mak
3798 echo "NINJA=$ninja" >> $config_host_mak
3799 echo "CC=$cc" >> $config_host_mak
3800 echo "HOST_CC=$host_cc" >> $config_host_mak
3801 if $iasl -h > /dev/null 2>&1; then
3802 echo "CONFIG_IASL=$iasl" >> $config_host_mak
3804 echo "AR=$ar" >> $config_host_mak
3805 echo "AS=$as" >> $config_host_mak
3806 echo "CCAS=$ccas" >> $config_host_mak
3807 echo "CPP=$cpp" >> $config_host_mak
3808 echo "OBJCOPY=$objcopy" >> $config_host_mak
3809 echo "LD=$ld" >> $config_host_mak
3810 echo "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
3811 echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
3812 echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
3813 echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
3814 echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
3815 echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
3816 echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
3817 echo "EXESUF=$EXESUF" >> $config_host_mak
3818 echo "LIBS_QGA=$libs_qga" >> $config_host_mak
3820 if test "$rng_none" = "yes"; then
3821 echo "CONFIG_RNG_NONE=y" >> $config_host_mak
3824 # use included Linux headers
3825 if test "$linux" = "yes" ; then
3826 mkdir -p linux-headers
3827 case "$cpu" in
3828 i386|x86_64|x32)
3829 linux_arch=x86
3831 ppc|ppc64|ppc64le)
3832 linux_arch=powerpc
3834 s390x)
3835 linux_arch=s390
3837 aarch64)
3838 linux_arch=arm64
3840 mips64)
3841 linux_arch=mips
3844 # For most CPUs the kernel architecture name and QEMU CPU name match.
3845 linux_arch="$cpu"
3847 esac
3848 # For non-KVM architectures we will not have asm headers
3849 if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
3850 symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
3854 for target in $target_list; do
3855 target_dir="$target"
3856 target_name=$(echo $target | cut -d '-' -f 1)
3857 mkdir -p $target_dir
3858 case $target in
3859 *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
3860 *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
3861 esac
3862 done
3864 echo "CONFIG_QEMU_INTERP_PREFIX=$interp_prefix" | sed 's/%M/@0@/' >> $config_host_mak
3865 if test "$default_targets" = "yes"; then
3866 echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
3869 if test "$numa" = "yes"; then
3870 echo "CONFIG_NUMA=y" >> $config_host_mak
3871 echo "NUMA_LIBS=$numa_libs" >> $config_host_mak
3874 if test "$ccache_cpp2" = "yes"; then
3875 echo "export CCACHE_CPP2=y" >> $config_host_mak
3878 if test "$safe_stack" = "yes"; then
3879 echo "CONFIG_SAFESTACK=y" >> $config_host_mak
3882 # If we're using a separate build tree, set it up now.
3883 # DIRS are directories which we simply mkdir in the build tree;
3884 # LINKS are things to symlink back into the source tree
3885 # (these can be both files and directories).
3886 # Caution: do not add files or directories here using wildcards. This
3887 # will result in problems later if a new file matching the wildcard is
3888 # added to the source tree -- nothing will cause configure to be rerun
3889 # so the build tree will be missing the link back to the new file, and
3890 # tests might fail. Prefer to keep the relevant files in their own
3891 # directory and symlink the directory instead.
3892 # UNLINK is used to remove symlinks from older development versions
3893 # that might get into the way when doing "git update" without doing
3894 # a "make distclean" in between.
3895 DIRS="tests tests/tcg tests/qapi-schema tests/qtest/libqos"
3896 DIRS="$DIRS tests/qtest tests/qemu-iotests tests/vm tests/fp tests/qgraph"
3897 DIRS="$DIRS docs docs/interop fsdev scsi"
3898 DIRS="$DIRS pc-bios/optionrom pc-bios/s390-ccw"
3899 DIRS="$DIRS roms/seabios"
3900 DIRS="$DIRS contrib/plugins/"
3901 LINKS="Makefile"
3902 LINKS="$LINKS tests/tcg/Makefile.target"
3903 LINKS="$LINKS pc-bios/optionrom/Makefile"
3904 LINKS="$LINKS pc-bios/s390-ccw/Makefile"
3905 LINKS="$LINKS roms/seabios/Makefile"
3906 LINKS="$LINKS pc-bios/qemu-icon.bmp"
3907 LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
3908 LINKS="$LINKS tests/acceptance tests/data"
3909 LINKS="$LINKS tests/qemu-iotests/check"
3910 LINKS="$LINKS python"
3911 LINKS="$LINKS contrib/plugins/Makefile "
3912 UNLINK="pc-bios/keymaps"
3913 for bios_file in \
3914 $source_path/pc-bios/*.bin \
3915 $source_path/pc-bios/*.elf \
3916 $source_path/pc-bios/*.lid \
3917 $source_path/pc-bios/*.rom \
3918 $source_path/pc-bios/*.dtb \
3919 $source_path/pc-bios/*.img \
3920 $source_path/pc-bios/openbios-* \
3921 $source_path/pc-bios/u-boot.* \
3922 $source_path/pc-bios/edk2-*.fd.bz2 \
3923 $source_path/pc-bios/palcode-* \
3924 $source_path/pc-bios/qemu_vga.ndrv
3927 LINKS="$LINKS pc-bios/$(basename $bios_file)"
3928 done
3929 mkdir -p $DIRS
3930 for f in $LINKS ; do
3931 if [ -e "$source_path/$f" ]; then
3932 symlink "$source_path/$f" "$f"
3934 done
3935 for f in $UNLINK ; do
3936 if [ -L "$f" ]; then
3937 rm -f "$f"
3939 done
3941 (for i in $cross_cc_vars; do
3942 export $i
3943 done
3944 export target_list source_path use_containers ARCH
3945 $source_path/tests/tcg/configure.sh)
3947 # temporary config to build submodules
3948 for rom in seabios; do
3949 config_mak=roms/$rom/config.mak
3950 echo "# Automatically generated by configure - do not modify" > $config_mak
3951 echo "SRC_PATH=$source_path/roms/$rom" >> $config_mak
3952 echo "AS=$as" >> $config_mak
3953 echo "CCAS=$ccas" >> $config_mak
3954 echo "CC=$cc" >> $config_mak
3955 echo "BCC=bcc" >> $config_mak
3956 echo "CPP=$cpp" >> $config_mak
3957 echo "OBJCOPY=objcopy" >> $config_mak
3958 echo "IASL=$iasl" >> $config_mak
3959 echo "LD=$ld" >> $config_mak
3960 echo "RANLIB=$ranlib" >> $config_mak
3961 done
3963 if test "$skip_meson" = no; then
3964 cross="config-meson.cross.new"
3965 meson_quote() {
3966 echo "'$(echo $* | sed "s/ /','/g")'"
3969 echo "# Automatically generated by configure - do not modify" > $cross
3970 echo "[properties]" >> $cross
3972 # unroll any custom device configs
3973 for a in $device_archs; do
3974 eval "c=\$devices_${a}"
3975 echo "${a}-softmmu = '$c'" >> $cross
3976 done
3978 test -z "$cxx" && echo "link_language = 'c'" >> $cross
3979 echo "[built-in options]" >> $cross
3980 echo "c_args = [${CFLAGS:+$(meson_quote $CFLAGS)}]" >> $cross
3981 echo "cpp_args = [${CXXFLAGS:+$(meson_quote $CXXFLAGS)}]" >> $cross
3982 echo "c_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross
3983 echo "cpp_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross
3984 echo "[binaries]" >> $cross
3985 echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
3986 test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
3987 test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
3988 echo "ar = [$(meson_quote $ar)]" >> $cross
3989 echo "nm = [$(meson_quote $nm)]" >> $cross
3990 echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
3991 echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
3992 if has $sdl2_config; then
3993 echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
3995 echo "strip = [$(meson_quote $strip)]" >> $cross
3996 echo "windres = [$(meson_quote $windres)]" >> $cross
3997 if test "$cross_compile" = "yes"; then
3998 cross_arg="--cross-file config-meson.cross"
3999 echo "[host_machine]" >> $cross
4000 if test "$mingw32" = "yes" ; then
4001 echo "system = 'windows'" >> $cross
4003 if test "$linux" = "yes" ; then
4004 echo "system = 'linux'" >> $cross
4006 if test "$darwin" = "yes" ; then
4007 echo "system = 'darwin'" >> $cross
4009 case "$ARCH" in
4010 i386)
4011 echo "cpu_family = 'x86'" >> $cross
4013 x86_64|x32)
4014 echo "cpu_family = 'x86_64'" >> $cross
4016 ppc64le)
4017 echo "cpu_family = 'ppc64'" >> $cross
4020 echo "cpu_family = '$ARCH'" >> $cross
4022 esac
4023 echo "cpu = '$cpu'" >> $cross
4024 if test "$bigendian" = "yes" ; then
4025 echo "endian = 'big'" >> $cross
4026 else
4027 echo "endian = 'little'" >> $cross
4029 else
4030 cross_arg="--native-file config-meson.cross"
4032 mv $cross config-meson.cross
4034 rm -rf meson-private meson-info meson-logs
4035 run_meson() {
4036 NINJA=$ninja $meson setup \
4037 --prefix "$prefix" \
4038 --libdir "$libdir" \
4039 --libexecdir "$libexecdir" \
4040 --bindir "$bindir" \
4041 --includedir "$includedir" \
4042 --datadir "$datadir" \
4043 --mandir "$mandir" \
4044 --sysconfdir "$sysconfdir" \
4045 --localedir "$localedir" \
4046 --localstatedir "$local_statedir" \
4047 -Daudio_drv_list=$audio_drv_list \
4048 -Ddefault_devices=$default_devices \
4049 -Ddocdir="$docdir" \
4050 -Dqemu_firmwarepath="$firmwarepath" \
4051 -Dqemu_suffix="$qemu_suffix" \
4052 -Dsphinx_build="$sphinx_build" \
4053 -Dtrace_file="$trace_file" \
4054 -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) \
4055 -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo false; fi) \
4056 -Dwerror=$(if test "$werror" = yes; then echo true; else echo false; fi) \
4057 -Dstrip=$(if test "$strip_opt" = yes; then echo true; else echo false; fi) \
4058 -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \
4059 -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
4060 -Db_lto=$lto -Dcfi=$cfi -Dtcg=$tcg -Dxen=$xen \
4061 -Dcapstone=$capstone -Dfdt=$fdt -Dslirp=$slirp \
4062 $(test -n "${LIB_FUZZING_ENGINE+xxx}" && echo "-Dfuzzing_engine=$LIB_FUZZING_ENGINE") \
4063 $(if test "$default_feature" = no; then echo "-Dauto_features=disabled"; fi) \
4064 "$@" $cross_arg "$PWD" "$source_path"
4066 eval run_meson $meson_options
4067 if test "$?" -ne 0 ; then
4068 error_exit "meson setup failed"
4070 else
4071 if test -f meson-private/cmd_line.txt; then
4072 # Adjust old command line options whose type was changed
4073 # Avoids having to use "setup --wipe" when Meson is upgraded
4074 perl -i -ne '
4075 s/^gettext = true$/gettext = auto/;
4076 s/^gettext = false$/gettext = disabled/;
4077 /^b_staticpic/ && next;
4078 print;' meson-private/cmd_line.txt
4082 if test -n "${deprecated_features}"; then
4083 echo "Warning, deprecated features enabled."
4084 echo "Please see docs/about/deprecated.rst"
4085 echo " features: ${deprecated_features}"
4088 # Create list of config switches that should be poisoned in common code...
4089 # but filter out CONFIG_TCG and CONFIG_USER_ONLY which are special.
4090 target_configs_h=$(ls *-config-devices.h *-config-target.h 2>/dev/null)
4091 if test -n "$target_configs_h" ; then
4092 sed -n -e '/CONFIG_TCG/d' -e '/CONFIG_USER_ONLY/d' \
4093 -e '/^#define / { s///; s/ .*//; s/^/#pragma GCC poison /p; }' \
4094 $target_configs_h | sort -u > config-poison.h
4095 else
4096 :> config-poison.h
4099 # Save the configure command line for later reuse.
4100 cat <<EOD >config.status
4101 #!/bin/sh
4102 # Generated by configure.
4103 # Run this file to recreate the current configuration.
4104 # Compiler output produced by configure, useful for debugging
4105 # configure, is in config.log if it exists.
4108 preserve_env() {
4109 envname=$1
4111 eval envval=\$$envname
4113 if test -n "$envval"
4114 then
4115 echo "$envname='$envval'" >> config.status
4116 echo "export $envname" >> config.status
4117 else
4118 echo "unset $envname" >> config.status
4122 # Preserve various env variables that influence what
4123 # features/build target configure will detect
4124 preserve_env AR
4125 preserve_env AS
4126 preserve_env CC
4127 preserve_env CPP
4128 preserve_env CXX
4129 preserve_env INSTALL
4130 preserve_env LD
4131 preserve_env LD_LIBRARY_PATH
4132 preserve_env LIBTOOL
4133 preserve_env MAKE
4134 preserve_env NM
4135 preserve_env OBJCOPY
4136 preserve_env PATH
4137 preserve_env PKG_CONFIG
4138 preserve_env PKG_CONFIG_LIBDIR
4139 preserve_env PKG_CONFIG_PATH
4140 preserve_env PYTHON
4141 preserve_env SDL2_CONFIG
4142 preserve_env SMBD
4143 preserve_env STRIP
4144 preserve_env WINDRES
4146 printf "exec" >>config.status
4147 for i in "$0" "$@"; do
4148 test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
4149 done
4150 echo ' "$@"' >>config.status
4151 chmod +x config.status
4153 rm -r "$TMPDIR1"