]> Git Repo - qemu.git/blob - configure
Merge remote-tracking branch 'remotes/vivier2/tags/trivial-branch-for-5.2-pull-reques...
[qemu.git] / configure
1 #!/bin/sh
2 #
3 # qemu configure script (c) 2003 Fabrice Bellard
4 #
5
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
10
11 # Don't allow CCACHE, if present, to use cached results of compile tests!
12 export CCACHE_RECACHE=yes
13
14 # make source path absolute
15 source_path=$(cd "$(dirname -- "$0")"; pwd)
16
17 if test "$PWD" = "$source_path"
18 then
19     echo "Using './build' as the directory for build output"
20
21     MARKER=build/auto-created-by-configure
22
23     if test -e build
24     then
25         if test -f $MARKER
26         then
27            rm -rf build
28         else
29             echo "ERROR: ./build dir already exists and was not previously created by configure"
30             exit 1
31         fi
32     fi
33
34     mkdir build
35     touch $MARKER
36
37     cat > GNUmakefile <<'EOF'
38 # This file is auto-generated by configure to support in-source tree
39 # 'make' command invocation
40
41 ifeq ($(MAKECMDGOALS),)
42 recurse: all
43 endif
44
45 .NOTPARALLEL: %
46 %: force
47         @echo 'changing dir to build for $(MAKE) "$(MAKECMDGOALS)"...'
48         @$(MAKE) -C build -f Makefile $(MAKECMDGOALS)
49         @if test "$(MAKECMDGOALS)" = "distclean" && \
50             test -e build/auto-created-by-configure ; \
51         then \
52             rm -rf build GNUmakefile ; \
53         fi
54 force: ;
55 .PHONY: force
56 GNUmakefile: ;
57
58 EOF
59     cd build
60     exec $source_path/configure "$@"
61 fi
62
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
74 fi
75
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"
82
83 rm -f config.log
84
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
91
92 print_error() {
93     (echo
94     echo "ERROR: $1"
95     while test -n "$2"; do
96         echo "       $2"
97         shift
98     done
99     echo) >&2
100 }
101
102 error_exit() {
103     print_error "$@"
104     exit 1
105 }
106
107 do_compiler() {
108     # Run the compiler, capturing its output to the log. First argument
109     # is compiler binary to execute.
110     local compiler="$1"
111     shift
112     if test -n "$BASH_VERSION"; then eval '
113         echo >>config.log "
114 funcs: ${FUNCNAME[*]}
115 lines: ${BASH_LINENO[*]}"
116     '; fi
117     echo $compiler "$@" >> config.log
118     $compiler "$@" >> config.log 2>&1 || return $?
119     # Test passed. If this is an --enable-werror build, rerun
120     # the test with -Werror and bail out if it fails. This
121     # makes warning-generating-errors in configure test code
122     # obvious to developers.
123     if test "$werror" != "yes"; then
124         return 0
125     fi
126     # Don't bother rerunning the compile if we were already using -Werror
127     case "$*" in
128         *-Werror*)
129            return 0
130         ;;
131     esac
132     echo $compiler -Werror "$@" >> config.log
133     $compiler -Werror "$@" >> config.log 2>&1 && return $?
134     error_exit "configure test passed without -Werror but failed with -Werror." \
135         "This is probably a bug in the configure script. The failing command" \
136         "will be at the bottom of config.log." \
137         "You can run configure with --disable-werror to bypass this check."
138 }
139
140 do_cc() {
141     do_compiler "$cc" "$@"
142 }
143
144 do_cxx() {
145     do_compiler "$cxx" "$@"
146 }
147
148 # Append $2 to the variable named $1, with space separation
149 add_to() {
150     eval $1=\${$1:+\"\$$1 \"}\$2
151 }
152
153 update_cxxflags() {
154     # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
155     # options which some versions of GCC's C++ compiler complain about
156     # because they only make sense for C programs.
157     QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
158     CXXFLAGS=$(echo "$CFLAGS" | sed s/-std=gnu99/-std=gnu++11/)
159     for arg in $QEMU_CFLAGS; do
160         case $arg in
161             -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
162             -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
163                 ;;
164             *)
165                 QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
166                 ;;
167         esac
168     done
169 }
170
171 compile_object() {
172   local_cflags="$1"
173   do_cc $CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
174 }
175
176 compile_prog() {
177   local_cflags="$1"
178   local_ldflags="$2"
179   do_cc $CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $QEMU_LDFLAGS $local_ldflags
180 }
181
182 # symbolically link $1 to $2.  Portable version of "ln -sf".
183 symlink() {
184   rm -rf "$2"
185   mkdir -p "$(dirname "$2")"
186   ln -s "$1" "$2"
187 }
188
189 # check whether a command is available to this shell (may be either an
190 # executable or a builtin)
191 has() {
192     type "$1" >/dev/null 2>&1
193 }
194
195 version_ge () {
196     local_ver1=`echo $1 | tr . ' '`
197     local_ver2=`echo $2 | tr . ' '`
198     while true; do
199         set x $local_ver1
200         local_first=${2-0}
201         # 'shift 2' if $2 is set, or 'shift' if $2 is not set
202         shift ${2:+2}
203         local_ver1=$*
204         set x $local_ver2
205         # the second argument finished, the first must be greater or equal
206         test $# = 1 && return 0
207         test $local_first -lt $2 && return 1
208         test $local_first -gt $2 && return 0
209         shift ${2:+2}
210         local_ver2=$*
211     done
212 }
213
214 have_backend () {
215     echo "$trace_backends" | grep "$1" >/dev/null
216 }
217
218 glob() {
219     eval test -z '"${1#'"$2"'}"'
220 }
221
222 supported_hax_target() {
223     test "$hax" = "yes" || return 1
224     glob "$1" "*-softmmu" || return 1
225     case "${1%-softmmu}" in
226         i386|x86_64)
227             return 0
228         ;;
229     esac
230     return 1
231 }
232
233 supported_kvm_target() {
234     test "$kvm" = "yes" || return 1
235     glob "$1" "*-softmmu" || return 1
236     case "${1%-softmmu}:$cpu" in
237         arm:arm | aarch64:aarch64 | \
238         i386:i386 | i386:x86_64 | i386:x32 | \
239         x86_64:i386 | x86_64:x86_64 | x86_64:x32 | \
240         mips:mips | mipsel:mips | mips64:mips | mips64el:mips | \
241         ppc:ppc | ppc64:ppc | ppc:ppc64 | ppc64:ppc64 | ppc64:ppc64le | \
242         s390x:s390x)
243             return 0
244         ;;
245     esac
246     return 1
247 }
248
249 supported_xen_target() {
250     test "$xen" = "yes" || return 1
251     glob "$1" "*-softmmu" || return 1
252     # Only i386 and x86_64 provide the xenpv machine.
253     case "${1%-softmmu}" in
254         i386|x86_64)
255             return 0
256         ;;
257     esac
258     return 1
259 }
260
261 supported_hvf_target() {
262     test "$hvf" = "yes" || return 1
263     glob "$1" "*-softmmu" || return 1
264     case "${1%-softmmu}" in
265         x86_64)
266             return 0
267         ;;
268     esac
269     return 1
270 }
271
272 supported_whpx_target() {
273     test "$whpx" = "yes" || return 1
274     glob "$1" "*-softmmu" || return 1
275     case "${1%-softmmu}" in
276         i386|x86_64)
277             return 0
278         ;;
279     esac
280     return 1
281 }
282
283 supported_target() {
284     case "$1" in
285         *-softmmu)
286             ;;
287         *-linux-user)
288             if test "$linux" != "yes"; then
289                 print_error "Target '$target' is only available on a Linux host"
290                 return 1
291             fi
292             ;;
293         *-bsd-user)
294             if test "$bsd" != "yes"; then
295                 print_error "Target '$target' is only available on a BSD host"
296                 return 1
297             fi
298             ;;
299         *)
300             print_error "Invalid target name '$target'"
301             return 1
302             ;;
303     esac
304     test "$tcg" = "yes" && return 0
305     supported_kvm_target "$1" && return 0
306     supported_xen_target "$1" && return 0
307     supported_hax_target "$1" && return 0
308     supported_hvf_target "$1" && return 0
309     supported_whpx_target "$1" && return 0
310     print_error "TCG disabled, but hardware accelerator not available for '$target'"
311     return 1
312 }
313
314
315 ld_has() {
316     $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
317 }
318
319 if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
320 then
321   error_exit "main directory cannot contain spaces nor colons"
322 fi
323
324 # default parameters
325 cpu=""
326 iasl="iasl"
327 interp_prefix="/usr/gnemul/qemu-%M"
328 static="no"
329 cross_prefix=""
330 audio_drv_list=""
331 block_drv_rw_whitelist=""
332 block_drv_ro_whitelist=""
333 host_cc="cc"
334 audio_win_int=""
335 libs_qga=""
336 debug_info="yes"
337 stack_protector=""
338 safe_stack=""
339 use_containers="yes"
340 gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
341
342 if test -e "$source_path/.git"
343 then
344     git_update=yes
345     git_submodules="ui/keycodemapdb"
346     git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
347     git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
348 else
349     git_update=no
350     git_submodules=""
351
352     if ! test -f "$source_path/ui/keycodemapdb/README"
353     then
354         echo
355         echo "ERROR: missing file $source_path/ui/keycodemapdb/README"
356         echo
357         echo "This is not a GIT checkout but module content appears to"
358         echo "be missing. Do not use 'git archive' or GitHub download links"
359         echo "to acquire QEMU source archives. Non-GIT builds are only"
360         echo "supported with source archives linked from:"
361         echo
362         echo "  https://www.qemu.org/download/#source"
363         echo
364         echo "Developers working with GIT can use scripts/archive-source.sh"
365         echo "if they need to create valid source archives."
366         echo
367         exit 1
368     fi
369 fi
370 git="git"
371
372 # Don't accept a target_list environment variable.
373 unset target_list
374 unset target_list_exclude
375
376 # Default value for a variable defining feature "foo".
377 #  * foo="no"  feature will only be used if --enable-foo arg is given
378 #  * foo=""    feature will be searched for, and if found, will be used
379 #              unless --disable-foo is given
380 #  * foo="yes" this value will only be set by --enable-foo flag.
381 #              feature will searched for,
382 #              if not found, configure exits with error
383 #
384 # Always add --enable-foo and --disable-foo command line args.
385 # Distributions want to ensure that several features are compiled in, and it
386 # is impossible without a --enable-foo that exits if a feature is not found.
387
388 brlapi=""
389 curl=""
390 curses=""
391 docs=""
392 fdt=""
393 netmap="no"
394 sdl="auto"
395 sdl_image="auto"
396 virtfs=""
397 mpath=""
398 vnc="enabled"
399 sparse="no"
400 vde=""
401 vnc_sasl="auto"
402 vnc_jpeg="auto"
403 vnc_png="auto"
404 xkbcommon="auto"
405 xen=""
406 xen_ctrl_version=""
407 xen_pci_passthrough=""
408 linux_aio=""
409 linux_io_uring=""
410 cap_ng=""
411 attr=""
412 libattr=""
413 xfs=""
414 tcg="yes"
415 membarrier=""
416 vhost_net=""
417 vhost_crypto=""
418 vhost_scsi=""
419 vhost_vsock=""
420 vhost_user=""
421 vhost_user_fs=""
422 kvm="no"
423 hax="no"
424 hvf="no"
425 whpx="no"
426 rdma=""
427 pvrdma=""
428 gprof="no"
429 debug_tcg="no"
430 debug="no"
431 sanitizers="no"
432 tsan="no"
433 fortify_source=""
434 strip_opt="yes"
435 tcg_interpreter="no"
436 bigendian="no"
437 mingw32="no"
438 gcov="no"
439 EXESUF=""
440 HOST_DSOSUF=".so"
441 modules="no"
442 module_upgrades="no"
443 prefix="/usr/local"
444 qemu_suffix="qemu"
445 slirp=""
446 oss_lib=""
447 bsd="no"
448 linux="no"
449 solaris="no"
450 profiler="no"
451 cocoa="no"
452 softmmu="yes"
453 linux_user="no"
454 bsd_user="no"
455 blobs="yes"
456 edk2_blobs="no"
457 pkgversion=""
458 pie=""
459 qom_cast_debug="yes"
460 trace_backends="log"
461 trace_file="trace"
462 spice=""
463 rbd=""
464 smartcard=""
465 u2f="auto"
466 libusb=""
467 usb_redir=""
468 opengl=""
469 opengl_dmabuf="no"
470 cpuid_h="no"
471 avx2_opt=""
472 capstone=""
473 lzo=""
474 snappy=""
475 bzip2=""
476 lzfse=""
477 zstd=""
478 guest_agent=""
479 guest_agent_with_vss="no"
480 guest_agent_ntddscsi="no"
481 guest_agent_msi=""
482 vss_win32_sdk=""
483 win_sdk="no"
484 want_tools=""
485 libiscsi=""
486 libnfs=""
487 coroutine=""
488 coroutine_pool=""
489 debug_stack_usage="no"
490 crypto_afalg="no"
491 seccomp=""
492 glusterfs=""
493 glusterfs_xlator_opt="no"
494 glusterfs_discard="no"
495 glusterfs_fallocate="no"
496 glusterfs_zerofill="no"
497 glusterfs_ftruncate_has_stat="no"
498 glusterfs_iocb_has_stat="no"
499 gtk=""
500 gtk_gl="no"
501 tls_priority="NORMAL"
502 gnutls=""
503 nettle=""
504 nettle_xts="no"
505 gcrypt=""
506 gcrypt_hmac="no"
507 gcrypt_xts="no"
508 qemu_private_xts="yes"
509 auth_pam=""
510 vte=""
511 virglrenderer=""
512 tpm=""
513 libssh=""
514 live_block_migration="yes"
515 numa=""
516 tcmalloc="no"
517 jemalloc="no"
518 replication="yes"
519 bochs="yes"
520 cloop="yes"
521 dmg="yes"
522 qcow1="yes"
523 vdi="yes"
524 vvfat="yes"
525 qed="yes"
526 parallels="yes"
527 sheepdog="yes"
528 libxml2=""
529 debug_mutex="no"
530 libpmem=""
531 default_devices="yes"
532 plugins="no"
533 fuzzing="no"
534 rng_none="no"
535 secret_keyring=""
536 libdaxctl=""
537 meson=""
538 ninja=""
539 skip_meson=no
540 gettext=""
541
542 bogus_os="no"
543 malloc_trim=""
544
545 # parse CC options first
546 for opt do
547   optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
548   case "$opt" in
549   --cross-prefix=*) cross_prefix="$optarg"
550   ;;
551   --cc=*) CC="$optarg"
552   ;;
553   --cxx=*) CXX="$optarg"
554   ;;
555   --cpu=*) cpu="$optarg"
556   ;;
557   --extra-cflags=*) QEMU_CFLAGS="$QEMU_CFLAGS $optarg"
558                     QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
559   ;;
560   --extra-cxxflags=*) QEMU_CXXFLAGS="$QEMU_CXXFLAGS $optarg"
561   ;;
562   --extra-ldflags=*) QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
563                      EXTRA_LDFLAGS="$optarg"
564   ;;
565   --enable-debug-info) debug_info="yes"
566   ;;
567   --disable-debug-info) debug_info="no"
568   ;;
569   --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
570   ;;
571   --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-flags-}; cc_arch=${cc_arch%%=*}
572                       eval "cross_cc_cflags_${cc_arch}=\$optarg"
573                       cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
574   ;;
575   --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
576                 cc_archs="$cc_archs $cc_arch"
577                 eval "cross_cc_${cc_arch}=\$optarg"
578                 cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
579   ;;
580   esac
581 done
582 # OS specific
583 # Using uname is really, really broken.  Once we have the right set of checks
584 # we can eliminate its usage altogether.
585
586 # Preferred compiler:
587 #  ${CC} (if set)
588 #  ${cross_prefix}gcc (if cross-prefix specified)
589 #  system compiler
590 if test -z "${CC}${cross_prefix}"; then
591   cc="$host_cc"
592 else
593   cc="${CC-${cross_prefix}gcc}"
594 fi
595
596 if test -z "${CXX}${cross_prefix}"; then
597   cxx="c++"
598 else
599   cxx="${CXX-${cross_prefix}g++}"
600 fi
601
602 ar="${AR-${cross_prefix}ar}"
603 as="${AS-${cross_prefix}as}"
604 ccas="${CCAS-$cc}"
605 cpp="${CPP-$cc -E}"
606 objcopy="${OBJCOPY-${cross_prefix}objcopy}"
607 ld="${LD-${cross_prefix}ld}"
608 ranlib="${RANLIB-${cross_prefix}ranlib}"
609 nm="${NM-${cross_prefix}nm}"
610 strip="${STRIP-${cross_prefix}strip}"
611 windres="${WINDRES-${cross_prefix}windres}"
612 pkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
613 query_pkg_config() {
614     "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
615 }
616 pkg_config=query_pkg_config
617 sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
618
619 # If the user hasn't specified ARFLAGS, default to 'rv', just as make does.
620 ARFLAGS="${ARFLAGS-rv}"
621
622 # default flags for all hosts
623 # We use -fwrapv to tell the compiler that we require a C dialect where
624 # left shift of signed integers is well defined and has the expected
625 # 2s-complement style results. (Both clang and gcc agree that it
626 # provides these semantics.)
627 QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv $QEMU_CFLAGS"
628 QEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
629 QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
630 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
631 QEMU_INCLUDES="-iquote . -iquote ${source_path} -iquote ${source_path}/accel/tcg -iquote ${source_path}/include"
632 QEMU_INCLUDES="$QEMU_INCLUDES -iquote ${source_path}/disas/libvixl"
633 CFLAGS="-std=gnu99 -Wall"
634
635
636 check_define() {
637 cat > $TMPC <<EOF
638 #if !defined($1)
639 #error $1 not defined
640 #endif
641 int main(void) { return 0; }
642 EOF
643   compile_object
644 }
645
646 check_include() {
647 cat > $TMPC <<EOF
648 #include <$1>
649 int main(void) { return 0; }
650 EOF
651   compile_object
652 }
653
654 write_c_skeleton() {
655     cat > $TMPC <<EOF
656 int main(void) { return 0; }
657 EOF
658 }
659
660 write_c_fuzzer_skeleton() {
661     cat > $TMPC <<EOF
662 #include <stdint.h>
663 #include <sys/types.h>
664 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
665 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { return 0; }
666 EOF
667 }
668
669 if check_define __linux__ ; then
670   targetos="Linux"
671 elif check_define _WIN32 ; then
672   targetos='MINGW32'
673 elif check_define __OpenBSD__ ; then
674   targetos='OpenBSD'
675 elif check_define __sun__ ; then
676   targetos='SunOS'
677 elif check_define __HAIKU__ ; then
678   targetos='Haiku'
679 elif check_define __FreeBSD__ ; then
680   targetos='FreeBSD'
681 elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
682   targetos='GNU/kFreeBSD'
683 elif check_define __DragonFly__ ; then
684   targetos='DragonFly'
685 elif check_define __NetBSD__; then
686   targetos='NetBSD'
687 elif check_define __APPLE__; then
688   targetos='Darwin'
689 else
690   # This is a fatal error, but don't report it yet, because we
691   # might be going to just print the --help text, or it might
692   # be the result of a missing compiler.
693   targetos='bogus'
694   bogus_os='yes'
695 fi
696
697 # Some host OSes need non-standard checks for which CPU to use.
698 # Note that these checks are broken for cross-compilation: if you're
699 # cross-compiling to one of these OSes then you'll need to specify
700 # the correct CPU with the --cpu option.
701 case $targetos in
702 Darwin)
703   # on Leopard most of the system is 32-bit, so we have to ask the kernel if we can
704   # run 64-bit userspace code.
705   # If the user didn't specify a CPU explicitly and the kernel says this is
706   # 64 bit hw, then assume x86_64. Otherwise fall through to the usual detection code.
707   if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then
708     cpu="x86_64"
709   fi
710   ;;
711 SunOS)
712   # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
713   if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
714     cpu="x86_64"
715   fi
716 esac
717
718 if test ! -z "$cpu" ; then
719   # command line argument
720   :
721 elif check_define __i386__ ; then
722   cpu="i386"
723 elif check_define __x86_64__ ; then
724   if check_define __ILP32__ ; then
725     cpu="x32"
726   else
727     cpu="x86_64"
728   fi
729 elif check_define __sparc__ ; then
730   if check_define __arch64__ ; then
731     cpu="sparc64"
732   else
733     cpu="sparc"
734   fi
735 elif check_define _ARCH_PPC ; then
736   if check_define _ARCH_PPC64 ; then
737     if check_define _LITTLE_ENDIAN ; then
738       cpu="ppc64le"
739     else
740       cpu="ppc64"
741     fi
742   else
743     cpu="ppc"
744   fi
745 elif check_define __mips__ ; then
746   cpu="mips"
747 elif check_define __s390__ ; then
748   if check_define __s390x__ ; then
749     cpu="s390x"
750   else
751     cpu="s390"
752   fi
753 elif check_define __riscv ; then
754   if check_define _LP64 ; then
755     cpu="riscv64"
756   else
757     cpu="riscv32"
758   fi
759 elif check_define __arm__ ; then
760   cpu="arm"
761 elif check_define __aarch64__ ; then
762   cpu="aarch64"
763 else
764   cpu=$(uname -m)
765 fi
766
767 ARCH=
768 # Normalise host CPU name and set ARCH.
769 # Note that this case should only have supported host CPUs, not guests.
770 case "$cpu" in
771   ppc|ppc64|s390x|sparc64|x32|riscv32|riscv64)
772   ;;
773   ppc64le)
774     ARCH="ppc64"
775   ;;
776   i386|i486|i586|i686|i86pc|BePC)
777     cpu="i386"
778   ;;
779   x86_64|amd64)
780     cpu="x86_64"
781   ;;
782   armv*b|armv*l|arm)
783     cpu="arm"
784   ;;
785   aarch64)
786     cpu="aarch64"
787   ;;
788   mips*)
789     cpu="mips"
790   ;;
791   sparc|sun4[cdmuv])
792     cpu="sparc"
793   ;;
794   *)
795     # This will result in either an error or falling back to TCI later
796     ARCH=unknown
797   ;;
798 esac
799 if test -z "$ARCH"; then
800   ARCH="$cpu"
801 fi
802
803 # OS specific
804
805 # host *BSD for user mode
806 HOST_VARIANT_DIR=""
807
808 case $targetos in
809 MINGW32*)
810   mingw32="yes"
811   hax="yes"
812   whpx=""
813   vhost_user="no"
814   audio_possible_drivers="dsound sdl"
815   if check_include dsound.h; then
816     audio_drv_list="dsound"
817   else
818     audio_drv_list=""
819   fi
820   supported_os="yes"
821   pie="no"
822 ;;
823 GNU/kFreeBSD)
824   bsd="yes"
825   audio_drv_list="oss try-sdl"
826   audio_possible_drivers="oss sdl pa"
827 ;;
828 FreeBSD)
829   bsd="yes"
830   make="${MAKE-gmake}"
831   audio_drv_list="oss try-sdl"
832   audio_possible_drivers="oss sdl pa"
833   # needed for kinfo_getvmmap(3) in libutil.h
834   netmap=""  # enable netmap autodetect
835   HOST_VARIANT_DIR="freebsd"
836 ;;
837 DragonFly)
838   bsd="yes"
839   make="${MAKE-gmake}"
840   audio_drv_list="oss try-sdl"
841   audio_possible_drivers="oss sdl pa"
842   HOST_VARIANT_DIR="dragonfly"
843 ;;
844 NetBSD)
845   bsd="yes"
846   hax="yes"
847   make="${MAKE-gmake}"
848   audio_drv_list="oss try-sdl"
849   audio_possible_drivers="oss sdl"
850   oss_lib="-lossaudio"
851   HOST_VARIANT_DIR="netbsd"
852 ;;
853 OpenBSD)
854   bsd="yes"
855   make="${MAKE-gmake}"
856   audio_drv_list="try-sdl"
857   audio_possible_drivers="sdl"
858   HOST_VARIANT_DIR="openbsd"
859 ;;
860 Darwin)
861   bsd="yes"
862   darwin="yes"
863   hax="yes"
864   hvf="yes"
865   if [ "$cpu" = "x86_64" ] ; then
866     QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
867     QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS"
868   fi
869   cocoa="yes"
870   audio_drv_list="coreaudio try-sdl"
871   audio_possible_drivers="coreaudio sdl"
872   QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit $QEMU_LDFLAGS"
873   # Disable attempts to use ObjectiveC features in os/object.h since they
874   # won't work when we're compiling with gcc as a C compiler.
875   QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
876   HOST_VARIANT_DIR="darwin"
877 ;;
878 SunOS)
879   solaris="yes"
880   make="${MAKE-gmake}"
881   smbd="${SMBD-/usr/sfw/sbin/smbd}"
882   if test -f /usr/include/sys/soundcard.h ; then
883     audio_drv_list="oss try-sdl"
884   fi
885   audio_possible_drivers="oss sdl"
886 # needed for CMSG_ macros in sys/socket.h
887   QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
888 # needed for TIOCWIN* defines in termios.h
889   QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
890 ;;
891 Haiku)
892   haiku="yes"
893   QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -DBSD_SOURCE $QEMU_CFLAGS"
894 ;;
895 Linux)
896   audio_drv_list="try-pa oss"
897   audio_possible_drivers="oss alsa sdl pa"
898   linux="yes"
899   linux_user="yes"
900   kvm="yes"
901   QEMU_INCLUDES="-isystem ${source_path}/linux-headers -Ilinux-headers $QEMU_INCLUDES"
902   libudev="yes"
903 ;;
904 esac
905
906 if [ "$bsd" = "yes" ] ; then
907   if [ "$darwin" != "yes" ] ; then
908     bsd_user="yes"
909   fi
910 fi
911
912 : ${make=${MAKE-make}}
913
914 # We prefer python 3.x. A bare 'python' is traditionally
915 # python 2.x, but some distros have it as python 3.x, so
916 # we check that too
917 python=
918 explicit_python=no
919 for binary in "${PYTHON-python3}" python
920 do
921     if has "$binary"
922     then
923         python=$(command -v "$binary")
924         break
925     fi
926 done
927
928 sphinx_build=
929 for binary in sphinx-build-3 sphinx-build
930 do
931     if has "$binary"
932     then
933         sphinx_build=$(command -v "$binary")
934         break
935     fi
936 done
937
938 # Check for ancillary tools used in testing
939 genisoimage=
940 for binary in genisoimage mkisofs
941 do
942     if has $binary
943     then
944         genisoimage=$(command -v "$binary")
945         break
946     fi
947 done
948
949 : ${smbd=${SMBD-/usr/sbin/smbd}}
950
951 # Default objcc to clang if available, otherwise use CC
952 if has clang; then
953   objcc=clang
954 else
955   objcc="$cc"
956 fi
957
958 if test "$mingw32" = "yes" ; then
959   EXESUF=".exe"
960   HOST_DSOSUF=".dll"
961   # MinGW needs -mthreads for TLS and macro _MT.
962   CFLAGS="-mthreads $CFLAGS"
963   write_c_skeleton;
964   prefix="c:/Program Files/QEMU"
965   qemu_suffix=""
966   libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi -lnetapi32 $libs_qga"
967 fi
968
969 werror=""
970
971 for opt do
972   optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
973   case "$opt" in
974   --help|-h) show_help=yes
975   ;;
976   --version|-V) exec cat $source_path/VERSION
977   ;;
978   --prefix=*) prefix="$optarg"
979   ;;
980   --interp-prefix=*) interp_prefix="$optarg"
981   ;;
982   --cross-prefix=*)
983   ;;
984   --cc=*)
985   ;;
986   --host-cc=*) host_cc="$optarg"
987   ;;
988   --cxx=*)
989   ;;
990   --iasl=*) iasl="$optarg"
991   ;;
992   --objcc=*) objcc="$optarg"
993   ;;
994   --make=*) make="$optarg"
995   ;;
996   --install=*)
997   ;;
998   --python=*) python="$optarg" ; explicit_python=yes
999   ;;
1000   --sphinx-build=*) sphinx_build="$optarg"
1001   ;;
1002   --skip-meson) skip_meson=yes
1003   ;;
1004   --meson=*) meson="$optarg"
1005   ;;
1006   --ninja=*) ninja="$optarg"
1007   ;;
1008   --smbd=*) smbd="$optarg"
1009   ;;
1010   --extra-cflags=*)
1011   ;;
1012   --extra-cxxflags=*)
1013   ;;
1014   --extra-ldflags=*)
1015   ;;
1016   --enable-debug-info)
1017   ;;
1018   --disable-debug-info)
1019   ;;
1020   --cross-cc-*)
1021   ;;
1022   --enable-modules)
1023       modules="yes"
1024   ;;
1025   --disable-modules)
1026       modules="no"
1027   ;;
1028   --disable-module-upgrades) module_upgrades="no"
1029   ;;
1030   --enable-module-upgrades) module_upgrades="yes"
1031   ;;
1032   --cpu=*)
1033   ;;
1034   --target-list=*) target_list="$optarg"
1035                    if test "$target_list_exclude"; then
1036                        error_exit "Can't mix --target-list with --target-list-exclude"
1037                    fi
1038   ;;
1039   --target-list-exclude=*) target_list_exclude="$optarg"
1040                    if test "$target_list"; then
1041                        error_exit "Can't mix --target-list-exclude with --target-list"
1042                    fi
1043   ;;
1044   --enable-trace-backends=*) trace_backends="$optarg"
1045   ;;
1046   # XXX: backwards compatibility
1047   --enable-trace-backend=*) trace_backends="$optarg"
1048   ;;
1049   --with-trace-file=*) trace_file="$optarg"
1050   ;;
1051   --with-default-devices) default_devices="yes"
1052   ;;
1053   --without-default-devices) default_devices="no"
1054   ;;
1055   --enable-gprof) gprof="yes"
1056   ;;
1057   --enable-gcov) gcov="yes"
1058   ;;
1059   --static)
1060     static="yes"
1061     QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
1062   ;;
1063   --mandir=*) mandir="$optarg"
1064   ;;
1065   --bindir=*) bindir="$optarg"
1066   ;;
1067   --libdir=*) libdir="$optarg"
1068   ;;
1069   --libexecdir=*) libexecdir="$optarg"
1070   ;;
1071   --includedir=*) includedir="$optarg"
1072   ;;
1073   --datadir=*) datadir="$optarg"
1074   ;;
1075   --with-suffix=*) qemu_suffix="$optarg"
1076   ;;
1077   --docdir=*) qemu_docdir="$optarg"
1078   ;;
1079   --sysconfdir=*) sysconfdir="$optarg"
1080   ;;
1081   --localstatedir=*) local_statedir="$optarg"
1082   ;;
1083   --firmwarepath=*) firmwarepath="$optarg"
1084   ;;
1085   --host=*|--build=*|\
1086   --disable-dependency-tracking|\
1087   --sbindir=*|--sharedstatedir=*|\
1088   --oldincludedir=*|--datarootdir=*|--infodir=*|--localedir=*|\
1089   --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
1090     # These switches are silently ignored, for compatibility with
1091     # autoconf-generated configure scripts. This allows QEMU's
1092     # configure to be used by RPM and similar macros that set
1093     # lots of directory switches by default.
1094   ;;
1095   --disable-sdl) sdl="disabled"
1096   ;;
1097   --enable-sdl) sdl="enabled"
1098   ;;
1099   --disable-sdl-image) sdl_image="disabled"
1100   ;;
1101   --enable-sdl-image) sdl_image="enabled"
1102   ;;
1103   --disable-qom-cast-debug) qom_cast_debug="no"
1104   ;;
1105   --enable-qom-cast-debug) qom_cast_debug="yes"
1106   ;;
1107   --disable-virtfs) virtfs="no"
1108   ;;
1109   --enable-virtfs) virtfs="yes"
1110   ;;
1111   --disable-mpath) mpath="no"
1112   ;;
1113   --enable-mpath) mpath="yes"
1114   ;;
1115   --disable-vnc) vnc="disabled"
1116   ;;
1117   --enable-vnc) vnc="enabled"
1118   ;;
1119   --disable-gettext) gettext="false"
1120   ;;
1121   --enable-gettext) gettext="true"
1122   ;;
1123   --oss-lib=*) oss_lib="$optarg"
1124   ;;
1125   --audio-drv-list=*) audio_drv_list="$optarg"
1126   ;;
1127   --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
1128   ;;
1129   --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
1130   ;;
1131   --enable-debug-tcg) debug_tcg="yes"
1132   ;;
1133   --disable-debug-tcg) debug_tcg="no"
1134   ;;
1135   --enable-debug)
1136       # Enable debugging options that aren't excessively noisy
1137       debug_tcg="yes"
1138       debug_mutex="yes"
1139       debug="yes"
1140       strip_opt="no"
1141       fortify_source="no"
1142   ;;
1143   --enable-sanitizers) sanitizers="yes"
1144   ;;
1145   --disable-sanitizers) sanitizers="no"
1146   ;;
1147   --enable-tsan) tsan="yes"
1148   ;;
1149   --disable-tsan) tsan="no"
1150   ;;
1151   --enable-sparse) sparse="yes"
1152   ;;
1153   --disable-sparse) sparse="no"
1154   ;;
1155   --disable-strip) strip_opt="no"
1156   ;;
1157   --disable-vnc-sasl) vnc_sasl="disabled"
1158   ;;
1159   --enable-vnc-sasl) vnc_sasl="enabled"
1160   ;;
1161   --disable-vnc-jpeg) vnc_jpeg="disabled"
1162   ;;
1163   --enable-vnc-jpeg) vnc_jpeg="enabled"
1164   ;;
1165   --disable-vnc-png) vnc_png="disabled"
1166   ;;
1167   --enable-vnc-png) vnc_png="enabled"
1168   ;;
1169   --disable-slirp) slirp="no"
1170   ;;
1171   --enable-slirp=git) slirp="git"
1172   ;;
1173   --enable-slirp=system) slirp="system"
1174   ;;
1175   --disable-vde) vde="no"
1176   ;;
1177   --enable-vde) vde="yes"
1178   ;;
1179   --disable-netmap) netmap="no"
1180   ;;
1181   --enable-netmap) netmap="yes"
1182   ;;
1183   --disable-xen) xen="no"
1184   ;;
1185   --enable-xen) xen="yes"
1186   ;;
1187   --disable-xen-pci-passthrough) xen_pci_passthrough="no"
1188   ;;
1189   --enable-xen-pci-passthrough) xen_pci_passthrough="yes"
1190   ;;
1191   --disable-brlapi) brlapi="no"
1192   ;;
1193   --enable-brlapi) brlapi="yes"
1194   ;;
1195   --disable-kvm) kvm="no"
1196   ;;
1197   --enable-kvm) kvm="yes"
1198   ;;
1199   --disable-hax) hax="no"
1200   ;;
1201   --enable-hax) hax="yes"
1202   ;;
1203   --disable-hvf) hvf="no"
1204   ;;
1205   --enable-hvf) hvf="yes"
1206   ;;
1207   --disable-whpx) whpx="no"
1208   ;;
1209   --enable-whpx) whpx="yes"
1210   ;;
1211   --disable-tcg-interpreter) tcg_interpreter="no"
1212   ;;
1213   --enable-tcg-interpreter) tcg_interpreter="yes"
1214   ;;
1215   --disable-cap-ng)  cap_ng="no"
1216   ;;
1217   --enable-cap-ng) cap_ng="yes"
1218   ;;
1219   --disable-tcg) tcg="no"
1220   ;;
1221   --enable-tcg) tcg="yes"
1222   ;;
1223   --disable-malloc-trim) malloc_trim="no"
1224   ;;
1225   --enable-malloc-trim) malloc_trim="yes"
1226   ;;
1227   --disable-spice) spice="no"
1228   ;;
1229   --enable-spice) spice="yes"
1230   ;;
1231   --disable-libiscsi) libiscsi="no"
1232   ;;
1233   --enable-libiscsi) libiscsi="yes"
1234   ;;
1235   --disable-libnfs) libnfs="no"
1236   ;;
1237   --enable-libnfs) libnfs="yes"
1238   ;;
1239   --enable-profiler) profiler="yes"
1240   ;;
1241   --disable-cocoa) cocoa="no"
1242   ;;
1243   --enable-cocoa)
1244       cocoa="yes" ;
1245       audio_drv_list="coreaudio $(echo $audio_drv_list | sed s,coreaudio,,g)"
1246   ;;
1247   --disable-system) softmmu="no"
1248   ;;
1249   --enable-system) softmmu="yes"
1250   ;;
1251   --disable-user)
1252       linux_user="no" ;
1253       bsd_user="no" ;
1254   ;;
1255   --enable-user) ;;
1256   --disable-linux-user) linux_user="no"
1257   ;;
1258   --enable-linux-user) linux_user="yes"
1259   ;;
1260   --disable-bsd-user) bsd_user="no"
1261   ;;
1262   --enable-bsd-user) bsd_user="yes"
1263   ;;
1264   --enable-pie) pie="yes"
1265   ;;
1266   --disable-pie) pie="no"
1267   ;;
1268   --enable-werror) werror="yes"
1269   ;;
1270   --disable-werror) werror="no"
1271   ;;
1272   --enable-stack-protector) stack_protector="yes"
1273   ;;
1274   --disable-stack-protector) stack_protector="no"
1275   ;;
1276   --enable-safe-stack) safe_stack="yes"
1277   ;;
1278   --disable-safe-stack) safe_stack="no"
1279   ;;
1280   --disable-curses) curses="no"
1281   ;;
1282   --enable-curses) curses="yes"
1283   ;;
1284   --disable-iconv) iconv="no"
1285   ;;
1286   --enable-iconv) iconv="yes"
1287   ;;
1288   --disable-curl) curl="no"
1289   ;;
1290   --enable-curl) curl="yes"
1291   ;;
1292   --disable-fdt) fdt="no"
1293   ;;
1294   --enable-fdt) fdt="yes"
1295   ;;
1296   --disable-linux-aio) linux_aio="no"
1297   ;;
1298   --enable-linux-aio) linux_aio="yes"
1299   ;;
1300   --disable-linux-io-uring) linux_io_uring="no"
1301   ;;
1302   --enable-linux-io-uring) linux_io_uring="yes"
1303   ;;
1304   --disable-attr) attr="no"
1305   ;;
1306   --enable-attr) attr="yes"
1307   ;;
1308   --disable-membarrier) membarrier="no"
1309   ;;
1310   --enable-membarrier) membarrier="yes"
1311   ;;
1312   --disable-blobs) blobs="no"
1313   ;;
1314   --with-pkgversion=*) pkgversion="$optarg"
1315   ;;
1316   --with-coroutine=*) coroutine="$optarg"
1317   ;;
1318   --disable-coroutine-pool) coroutine_pool="no"
1319   ;;
1320   --enable-coroutine-pool) coroutine_pool="yes"
1321   ;;
1322   --enable-debug-stack-usage) debug_stack_usage="yes"
1323   ;;
1324   --enable-crypto-afalg) crypto_afalg="yes"
1325   ;;
1326   --disable-crypto-afalg) crypto_afalg="no"
1327   ;;
1328   --disable-docs) docs="no"
1329   ;;
1330   --enable-docs) docs="yes"
1331   ;;
1332   --disable-vhost-net) vhost_net="no"
1333   ;;
1334   --enable-vhost-net) vhost_net="yes"
1335   ;;
1336   --disable-vhost-crypto) vhost_crypto="no"
1337   ;;
1338   --enable-vhost-crypto) vhost_crypto="yes"
1339   ;;
1340   --disable-vhost-scsi) vhost_scsi="no"
1341   ;;
1342   --enable-vhost-scsi) vhost_scsi="yes"
1343   ;;
1344   --disable-vhost-vsock) vhost_vsock="no"
1345   ;;
1346   --enable-vhost-vsock) vhost_vsock="yes"
1347   ;;
1348   --disable-vhost-user-fs) vhost_user_fs="no"
1349   ;;
1350   --enable-vhost-user-fs) vhost_user_fs="yes"
1351   ;;
1352   --disable-opengl) opengl="no"
1353   ;;
1354   --enable-opengl) opengl="yes"
1355   ;;
1356   --disable-rbd) rbd="no"
1357   ;;
1358   --enable-rbd) rbd="yes"
1359   ;;
1360   --disable-xfsctl) xfs="no"
1361   ;;
1362   --enable-xfsctl) xfs="yes"
1363   ;;
1364   --disable-smartcard) smartcard="no"
1365   ;;
1366   --enable-smartcard) smartcard="yes"
1367   ;;
1368   --disable-u2f) u2f="disabled"
1369   ;;
1370   --enable-u2f) u2f="enabled"
1371   ;;
1372   --disable-libusb) libusb="no"
1373   ;;
1374   --enable-libusb) libusb="yes"
1375   ;;
1376   --disable-usb-redir) usb_redir="no"
1377   ;;
1378   --enable-usb-redir) usb_redir="yes"
1379   ;;
1380   --disable-zlib-test)
1381   ;;
1382   --disable-lzo) lzo="no"
1383   ;;
1384   --enable-lzo) lzo="yes"
1385   ;;
1386   --disable-snappy) snappy="no"
1387   ;;
1388   --enable-snappy) snappy="yes"
1389   ;;
1390   --disable-bzip2) bzip2="no"
1391   ;;
1392   --enable-bzip2) bzip2="yes"
1393   ;;
1394   --enable-lzfse) lzfse="yes"
1395   ;;
1396   --disable-lzfse) lzfse="no"
1397   ;;
1398   --disable-zstd) zstd="no"
1399   ;;
1400   --enable-zstd) zstd="yes"
1401   ;;
1402   --enable-guest-agent) guest_agent="yes"
1403   ;;
1404   --disable-guest-agent) guest_agent="no"
1405   ;;
1406   --enable-guest-agent-msi) guest_agent_msi="yes"
1407   ;;
1408   --disable-guest-agent-msi) guest_agent_msi="no"
1409   ;;
1410   --with-vss-sdk) vss_win32_sdk=""
1411   ;;
1412   --with-vss-sdk=*) vss_win32_sdk="$optarg"
1413   ;;
1414   --without-vss-sdk) vss_win32_sdk="no"
1415   ;;
1416   --with-win-sdk) win_sdk=""
1417   ;;
1418   --with-win-sdk=*) win_sdk="$optarg"
1419   ;;
1420   --without-win-sdk) win_sdk="no"
1421   ;;
1422   --enable-tools) want_tools="yes"
1423   ;;
1424   --disable-tools) want_tools="no"
1425   ;;
1426   --enable-seccomp) seccomp="yes"
1427   ;;
1428   --disable-seccomp) seccomp="no"
1429   ;;
1430   --disable-glusterfs) glusterfs="no"
1431   ;;
1432   --disable-avx2) avx2_opt="no"
1433   ;;
1434   --enable-avx2) avx2_opt="yes"
1435   ;;
1436   --disable-avx512f) avx512f_opt="no"
1437   ;;
1438   --enable-avx512f) avx512f_opt="yes"
1439   ;;
1440
1441   --enable-glusterfs) glusterfs="yes"
1442   ;;
1443   --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
1444       echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
1445   ;;
1446   --enable-vhdx|--disable-vhdx)
1447       echo "$0: $opt is obsolete, VHDX driver is always built" >&2
1448   ;;
1449   --enable-uuid|--disable-uuid)
1450       echo "$0: $opt is obsolete, UUID support is always built" >&2
1451   ;;
1452   --disable-gtk) gtk="no"
1453   ;;
1454   --enable-gtk) gtk="yes"
1455   ;;
1456   --tls-priority=*) tls_priority="$optarg"
1457   ;;
1458   --disable-gnutls) gnutls="no"
1459   ;;
1460   --enable-gnutls) gnutls="yes"
1461   ;;
1462   --disable-nettle) nettle="no"
1463   ;;
1464   --enable-nettle) nettle="yes"
1465   ;;
1466   --disable-gcrypt) gcrypt="no"
1467   ;;
1468   --enable-gcrypt) gcrypt="yes"
1469   ;;
1470   --disable-auth-pam) auth_pam="no"
1471   ;;
1472   --enable-auth-pam) auth_pam="yes"
1473   ;;
1474   --enable-rdma) rdma="yes"
1475   ;;
1476   --disable-rdma) rdma="no"
1477   ;;
1478   --enable-pvrdma) pvrdma="yes"
1479   ;;
1480   --disable-pvrdma) pvrdma="no"
1481   ;;
1482   --disable-vte) vte="no"
1483   ;;
1484   --enable-vte) vte="yes"
1485   ;;
1486   --disable-virglrenderer) virglrenderer="no"
1487   ;;
1488   --enable-virglrenderer) virglrenderer="yes"
1489   ;;
1490   --disable-tpm) tpm="no"
1491   ;;
1492   --enable-tpm) tpm="yes"
1493   ;;
1494   --disable-libssh) libssh="no"
1495   ;;
1496   --enable-libssh) libssh="yes"
1497   ;;
1498   --disable-live-block-migration) live_block_migration="no"
1499   ;;
1500   --enable-live-block-migration) live_block_migration="yes"
1501   ;;
1502   --disable-numa) numa="no"
1503   ;;
1504   --enable-numa) numa="yes"
1505   ;;
1506   --disable-libxml2) libxml2="no"
1507   ;;
1508   --enable-libxml2) libxml2="yes"
1509   ;;
1510   --disable-tcmalloc) tcmalloc="no"
1511   ;;
1512   --enable-tcmalloc) tcmalloc="yes"
1513   ;;
1514   --disable-jemalloc) jemalloc="no"
1515   ;;
1516   --enable-jemalloc) jemalloc="yes"
1517   ;;
1518   --disable-replication) replication="no"
1519   ;;
1520   --enable-replication) replication="yes"
1521   ;;
1522   --disable-bochs) bochs="no"
1523   ;;
1524   --enable-bochs) bochs="yes"
1525   ;;
1526   --disable-cloop) cloop="no"
1527   ;;
1528   --enable-cloop) cloop="yes"
1529   ;;
1530   --disable-dmg) dmg="no"
1531   ;;
1532   --enable-dmg) dmg="yes"
1533   ;;
1534   --disable-qcow1) qcow1="no"
1535   ;;
1536   --enable-qcow1) qcow1="yes"
1537   ;;
1538   --disable-vdi) vdi="no"
1539   ;;
1540   --enable-vdi) vdi="yes"
1541   ;;
1542   --disable-vvfat) vvfat="no"
1543   ;;
1544   --enable-vvfat) vvfat="yes"
1545   ;;
1546   --disable-qed) qed="no"
1547   ;;
1548   --enable-qed) qed="yes"
1549   ;;
1550   --disable-parallels) parallels="no"
1551   ;;
1552   --enable-parallels) parallels="yes"
1553   ;;
1554   --disable-sheepdog) sheepdog="no"
1555   ;;
1556   --enable-sheepdog) sheepdog="yes"
1557   ;;
1558   --disable-vhost-user) vhost_user="no"
1559   ;;
1560   --enable-vhost-user) vhost_user="yes"
1561   ;;
1562   --disable-vhost-vdpa) vhost_vdpa="no"
1563   ;;
1564   --enable-vhost-vdpa) vhost_vdpa="yes"
1565   ;;
1566   --disable-vhost-kernel) vhost_kernel="no"
1567   ;;
1568   --enable-vhost-kernel) vhost_kernel="yes"
1569   ;;
1570   --disable-capstone) capstone="no"
1571   ;;
1572   --enable-capstone) capstone="yes"
1573   ;;
1574   --enable-capstone=git) capstone="git"
1575   ;;
1576   --enable-capstone=system) capstone="system"
1577   ;;
1578   --with-git=*) git="$optarg"
1579   ;;
1580   --enable-git-update) git_update=yes
1581   ;;
1582   --disable-git-update) git_update=no
1583   ;;
1584   --enable-debug-mutex) debug_mutex=yes
1585   ;;
1586   --disable-debug-mutex) debug_mutex=no
1587   ;;
1588   --enable-libpmem) libpmem=yes
1589   ;;
1590   --disable-libpmem) libpmem=no
1591   ;;
1592   --enable-xkbcommon) xkbcommon="enabled"
1593   ;;
1594   --disable-xkbcommon) xkbcommon="disabled"
1595   ;;
1596   --enable-plugins) plugins="yes"
1597   ;;
1598   --disable-plugins) plugins="no"
1599   ;;
1600   --enable-containers) use_containers="yes"
1601   ;;
1602   --disable-containers) use_containers="no"
1603   ;;
1604   --enable-fuzzing) fuzzing=yes
1605   ;;
1606   --disable-fuzzing) fuzzing=no
1607   ;;
1608   --gdb=*) gdb_bin="$optarg"
1609   ;;
1610   --enable-rng-none) rng_none=yes
1611   ;;
1612   --disable-rng-none) rng_none=no
1613   ;;
1614   --enable-keyring) secret_keyring="yes"
1615   ;;
1616   --disable-keyring) secret_keyring="no"
1617   ;;
1618   --enable-libdaxctl) libdaxctl=yes
1619   ;;
1620   --disable-libdaxctl) libdaxctl=no
1621   ;;
1622   *)
1623       echo "ERROR: unknown option $opt"
1624       echo "Try '$0 --help' for more information"
1625       exit 1
1626   ;;
1627   esac
1628 done
1629
1630 firmwarepath="${firmwarepath:-$prefix/share/qemu-firmware}"
1631 libdir="${libdir:-$prefix/lib}"
1632 libexecdir="${libexecdir:-$prefix/libexec}"
1633 includedir="${includedir:-$prefix/include}"
1634
1635 if test "$mingw32" = "yes" ; then
1636     mandir="$prefix"
1637     datadir="$prefix"
1638     docdir="$prefix"
1639     bindir="$prefix"
1640     sysconfdir="$prefix"
1641     local_statedir=
1642 else
1643     mandir="${mandir:-$prefix/share/man}"
1644     datadir="${datadir:-$prefix/share}"
1645     docdir="${docdir:-$prefix/share/doc}"
1646     bindir="${bindir:-$prefix/bin}"
1647     sysconfdir="${sysconfdir:-$prefix/etc}"
1648     local_statedir="${local_statedir:-$prefix/var}"
1649 fi
1650
1651 case "$cpu" in
1652     ppc)
1653            CPU_CFLAGS="-m32"
1654            QEMU_LDFLAGS="-m32 $QEMU_LDFLAGS"
1655            ;;
1656     ppc64)
1657            CPU_CFLAGS="-m64"
1658            QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1659            ;;
1660     sparc)
1661            CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc"
1662            QEMU_LDFLAGS="-m32 -mv8plus $QEMU_LDFLAGS"
1663            ;;
1664     sparc64)
1665            CPU_CFLAGS="-m64 -mcpu=ultrasparc"
1666            QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1667            ;;
1668     s390)
1669            CPU_CFLAGS="-m31"
1670            QEMU_LDFLAGS="-m31 $QEMU_LDFLAGS"
1671            ;;
1672     s390x)
1673            CPU_CFLAGS="-m64"
1674            QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1675            ;;
1676     i386)
1677            CPU_CFLAGS="-m32"
1678            QEMU_LDFLAGS="-m32 $QEMU_LDFLAGS"
1679            ;;
1680     x86_64)
1681            # ??? Only extremely old AMD cpus do not have cmpxchg16b.
1682            # If we truly care, we should simply detect this case at
1683            # runtime and generate the fallback to serial emulation.
1684            CPU_CFLAGS="-m64 -mcx16"
1685            QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1686            ;;
1687     x32)
1688            CPU_CFLAGS="-mx32"
1689            QEMU_LDFLAGS="-mx32 $QEMU_LDFLAGS"
1690            ;;
1691     # No special flags required for other host CPUs
1692 esac
1693
1694 eval "cross_cc_${cpu}=\$host_cc"
1695 cross_cc_vars="$cross_cc_vars cross_cc_${cpu}"
1696 QEMU_CFLAGS="$CPU_CFLAGS $QEMU_CFLAGS"
1697
1698 # For user-mode emulation the host arch has to be one we explicitly
1699 # support, even if we're using TCI.
1700 if [ "$ARCH" = "unknown" ]; then
1701   bsd_user="no"
1702   linux_user="no"
1703 fi
1704
1705 if [ "$bsd_user" = "no" -a "$linux_user" = "no" -a "$softmmu" = "no" ] ; then
1706   tcg="no"
1707 fi
1708
1709 default_target_list=""
1710
1711 mak_wilds=""
1712
1713 if [ "$softmmu" = "yes" ]; then
1714     mak_wilds="${mak_wilds} $source_path/default-configs/*-softmmu.mak"
1715 fi
1716 if [ "$linux_user" = "yes" ]; then
1717     mak_wilds="${mak_wilds} $source_path/default-configs/*-linux-user.mak"
1718 fi
1719 if [ "$bsd_user" = "yes" ]; then
1720     mak_wilds="${mak_wilds} $source_path/default-configs/*-bsd-user.mak"
1721 fi
1722
1723 if test -z "$target_list_exclude"; then
1724     for config in $mak_wilds; do
1725         default_target_list="${default_target_list} $(basename "$config" .mak)"
1726     done
1727 else
1728     exclude_list=$(echo "$target_list_exclude" | sed -e 's/,/ /g')
1729     for config in $mak_wilds; do
1730         target="$(basename "$config" .mak)"
1731         exclude="no"
1732         for excl in $exclude_list; do
1733             if test "$excl" = "$target"; then
1734                 exclude="yes"
1735                 break;
1736             fi
1737         done
1738         if test "$exclude" = "no"; then
1739             default_target_list="${default_target_list} $target"
1740         fi
1741     done
1742 fi
1743
1744 # Enumerate public trace backends for --help output
1745 trace_backend_list=$(echo $(grep -le '^PUBLIC = True$' "$source_path"/scripts/tracetool/backend/*.py | sed -e 's/^.*\/\(.*\)\.py$/\1/'))
1746
1747 if test x"$show_help" = x"yes" ; then
1748 cat << EOF
1749
1750 Usage: configure [options]
1751 Options: [defaults in brackets after descriptions]
1752
1753 Standard options:
1754   --help                   print this message
1755   --prefix=PREFIX          install in PREFIX [$prefix]
1756   --interp-prefix=PREFIX   where to find shared libraries, etc.
1757                            use %M for cpu name [$interp_prefix]
1758   --target-list=LIST       set target list (default: build everything)
1759 $(echo Available targets: $default_target_list | \
1760   fold -s -w 53 | sed -e 's/^/                           /')
1761   --target-list-exclude=LIST exclude a set of targets from the default target-list
1762
1763 Advanced options (experts only):
1764   --cross-prefix=PREFIX    use PREFIX for compile tools [$cross_prefix]
1765   --cc=CC                  use C compiler CC [$cc]
1766   --iasl=IASL              use ACPI compiler IASL [$iasl]
1767   --host-cc=CC             use C compiler CC [$host_cc] for code run at
1768                            build time
1769   --cxx=CXX                use C++ compiler CXX [$cxx]
1770   --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
1771   --extra-cflags=CFLAGS    append extra C compiler flags QEMU_CFLAGS
1772   --extra-cxxflags=CXXFLAGS append extra C++ compiler flags QEMU_CXXFLAGS
1773   --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
1774   --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
1775   --cross-cc-flags-ARCH=   use compiler flags when building ARCH guest tests
1776   --make=MAKE              use specified make [$make]
1777   --python=PYTHON          use specified python [$python]
1778   --sphinx-build=SPHINX    use specified sphinx-build [$sphinx_build]
1779   --meson=MESON            use specified meson [$meson]
1780   --ninja=NINJA            use specified ninja [$ninja]
1781   --smbd=SMBD              use specified smbd [$smbd]
1782   --with-git=GIT           use specified git [$git]
1783   --static                 enable static build [$static]
1784   --mandir=PATH            install man pages in PATH
1785   --datadir=PATH           install firmware in PATH/$qemu_suffix
1786   --docdir=PATH            install documentation in PATH/$qemu_suffix
1787   --bindir=PATH            install binaries in PATH
1788   --libdir=PATH            install libraries in PATH
1789   --libexecdir=PATH        install helper binaries in PATH
1790   --sysconfdir=PATH        install config in PATH/$qemu_suffix
1791   --localstatedir=PATH     install local state in PATH (set at runtime on win32)
1792   --firmwarepath=PATH      search PATH for firmware files
1793   --efi-aarch64=PATH       PATH of efi file to use for aarch64 VMs.
1794   --with-suffix=SUFFIX     suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
1795   --with-pkgversion=VERS   use specified string as sub-version of the package
1796   --enable-debug           enable common debug build options
1797   --enable-sanitizers      enable default sanitizers
1798   --enable-tsan            enable thread sanitizer
1799   --disable-strip          disable stripping binaries
1800   --disable-werror         disable compilation abort on warning
1801   --disable-stack-protector disable compiler-provided stack protection
1802   --audio-drv-list=LIST    set audio drivers list:
1803                            Available drivers: $audio_possible_drivers
1804   --block-drv-whitelist=L  Same as --block-drv-rw-whitelist=L
1805   --block-drv-rw-whitelist=L
1806                            set block driver read-write whitelist
1807                            (affects only QEMU, not qemu-img)
1808   --block-drv-ro-whitelist=L
1809                            set block driver read-only whitelist
1810                            (affects only QEMU, not qemu-img)
1811   --enable-trace-backends=B Set trace backend
1812                            Available backends: $trace_backend_list
1813   --with-trace-file=NAME   Full PATH,NAME of file to store traces
1814                            Default:trace-<pid>
1815   --disable-slirp          disable SLIRP userspace network connectivity
1816   --enable-tcg-interpreter enable TCG with bytecode interpreter (TCI)
1817   --enable-malloc-trim     enable libc malloc_trim() for memory optimization
1818   --oss-lib                path to OSS library
1819   --cpu=CPU                Build for host CPU [$cpu]
1820   --with-coroutine=BACKEND coroutine backend. Supported options:
1821                            ucontext, sigaltstack, windows
1822   --enable-gcov            enable test coverage analysis with gcov
1823   --disable-blobs          disable installing provided firmware blobs
1824   --with-vss-sdk=SDK-path  enable Windows VSS support in QEMU Guest Agent
1825   --with-win-sdk=SDK-path  path to Windows Platform SDK (to build VSS .tlb)
1826   --tls-priority           default TLS protocol/cipher priority string
1827   --enable-gprof           QEMU profiling with gprof
1828   --enable-profiler        profiler support
1829   --enable-debug-stack-usage
1830                            track the maximum stack usage of stacks created by qemu_alloc_stack
1831   --enable-plugins
1832                            enable plugins via shared library loading
1833   --disable-containers     don't use containers for cross-building
1834   --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
1835
1836 Optional features, enabled with --enable-FEATURE and
1837 disabled with --disable-FEATURE, default is enabled if available:
1838
1839   system          all system emulation targets
1840   user            supported user emulation targets
1841   linux-user      all linux usermode emulation targets
1842   bsd-user        all BSD usermode emulation targets
1843   docs            build documentation
1844   guest-agent     build the QEMU Guest Agent
1845   guest-agent-msi build guest agent Windows MSI installation package
1846   pie             Position Independent Executables
1847   modules         modules support (non-Windows)
1848   module-upgrades try to load modules from alternate paths for upgrades
1849   debug-tcg       TCG debugging (default is disabled)
1850   debug-info      debugging information
1851   sparse          sparse checker
1852   safe-stack      SafeStack Stack Smash Protection. Depends on
1853                   clang/llvm >= 3.7 and requires coroutine backend ucontext.
1854
1855   gnutls          GNUTLS cryptography support
1856   nettle          nettle cryptography support
1857   gcrypt          libgcrypt cryptography support
1858   auth-pam        PAM access control
1859   sdl             SDL UI
1860   sdl-image       SDL Image support for icons
1861   gtk             gtk UI
1862   vte             vte support for the gtk UI
1863   curses          curses UI
1864   iconv           font glyph conversion support
1865   vnc             VNC UI support
1866   vnc-sasl        SASL encryption for VNC server
1867   vnc-jpeg        JPEG lossy compression for VNC server
1868   vnc-png         PNG compression for VNC server
1869   cocoa           Cocoa UI (Mac OS X only)
1870   virtfs          VirtFS
1871   mpath           Multipath persistent reservation passthrough
1872   xen             xen backend driver support
1873   xen-pci-passthrough    PCI passthrough support for Xen
1874   brlapi          BrlAPI (Braile)
1875   curl            curl connectivity
1876   membarrier      membarrier system call (for Linux 4.14+ or Windows)
1877   fdt             fdt device tree
1878   kvm             KVM acceleration support
1879   hax             HAX acceleration support
1880   hvf             Hypervisor.framework acceleration support
1881   whpx            Windows Hypervisor Platform acceleration support
1882   rdma            Enable RDMA-based migration
1883   pvrdma          Enable PVRDMA support
1884   vde             support for vde network
1885   netmap          support for netmap network
1886   linux-aio       Linux AIO support
1887   linux-io-uring  Linux io_uring support
1888   cap-ng          libcap-ng support
1889   attr            attr and xattr support
1890   vhost-net       vhost-net kernel acceleration support
1891   vhost-vsock     virtio sockets device support
1892   vhost-scsi      vhost-scsi kernel target support
1893   vhost-crypto    vhost-user-crypto backend support
1894   vhost-kernel    vhost kernel backend support
1895   vhost-user      vhost-user backend support
1896   vhost-vdpa      vhost-vdpa kernel backend support
1897   spice           spice
1898   rbd             rados block device (rbd)
1899   libiscsi        iscsi support
1900   libnfs          nfs support
1901   smartcard       smartcard support (libcacard)
1902   u2f             U2F support (u2f-emu)
1903   libusb          libusb (for usb passthrough)
1904   live-block-migration   Block migration in the main migration stream
1905   usb-redir       usb network redirection support
1906   lzo             support of lzo compression library
1907   snappy          support of snappy compression library
1908   bzip2           support of bzip2 compression library
1909                   (for reading bzip2-compressed dmg images)
1910   lzfse           support of lzfse compression library
1911                   (for reading lzfse-compressed dmg images)
1912   zstd            support for zstd compression library
1913                   (for migration compression and qcow2 cluster compression)
1914   seccomp         seccomp support
1915   coroutine-pool  coroutine freelist (better performance)
1916   glusterfs       GlusterFS backend
1917   tpm             TPM support
1918   libssh          ssh block device support
1919   numa            libnuma support
1920   libxml2         for Parallels image format
1921   tcmalloc        tcmalloc support
1922   jemalloc        jemalloc support
1923   avx2            AVX2 optimization support
1924   avx512f         AVX512F optimization support
1925   replication     replication support
1926   opengl          opengl support
1927   virglrenderer   virgl rendering support
1928   xfsctl          xfsctl support
1929   qom-cast-debug  cast debugging support
1930   tools           build qemu-io, qemu-nbd and qemu-img tools
1931   bochs           bochs image format support
1932   cloop           cloop image format support
1933   dmg             dmg image format support
1934   qcow1           qcow v1 image format support
1935   vdi             vdi image format support
1936   vvfat           vvfat image format support
1937   qed             qed image format support
1938   parallels       parallels image format support
1939   sheepdog        sheepdog block driver support
1940   crypto-afalg    Linux AF_ALG crypto backend driver
1941   capstone        capstone disassembler support
1942   debug-mutex     mutex debugging support
1943   libpmem         libpmem support
1944   xkbcommon       xkbcommon support
1945   rng-none        dummy RNG, avoid using /dev/(u)random and getrandom()
1946   libdaxctl       libdaxctl support
1947
1948 NOTE: The object files are built at the place where configure is launched
1949 EOF
1950 exit 0
1951 fi
1952
1953 # Remove old dependency files to make sure that they get properly regenerated
1954 rm -f */config-devices.mak.d
1955
1956 if test -z "$python"
1957 then
1958     error_exit "Python not found. Use --python=/path/to/python"
1959 fi
1960
1961 # Note that if the Python conditional here evaluates True we will exit
1962 # with status 1 which is a shell 'false' value.
1963 if ! $python -c 'import sys; sys.exit(sys.version_info < (3,5))'; then
1964   error_exit "Cannot use '$python', Python >= 3.5 is required." \
1965       "Use --python=/path/to/python to specify a supported Python."
1966 fi
1967
1968 # Preserve python version since some functionality is dependent on it
1969 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)
1970
1971 # Suppress writing compiled files
1972 python="$python -B"
1973
1974 if test -z "$meson"; then
1975     if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.55.1; then
1976         meson=meson
1977     elif test -e "${source_path}/.git" && test $git_update = 'yes' ; then
1978         meson=git
1979     elif test -e "${source_path}/meson/meson.py" ; then
1980         meson=internal
1981     else
1982         if test "$explicit_python" = yes; then
1983             error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
1984         else
1985             error_exit "Meson not found.  Use --meson=/path/to/meson"
1986         fi
1987     fi
1988 else
1989     # Meson uses its own Python interpreter to invoke other Python scripts,
1990     # but the user wants to use the one they specified with --python.
1991     #
1992     # We do not want to override the distro Python interpreter (and sometimes
1993     # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
1994     # just require --meson=git|internal together with --python.
1995     if test "$explicit_python" = yes; then
1996         case "$meson" in
1997             git | internal) ;;
1998             *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
1999         esac
2000     fi
2001 fi
2002
2003 if test "$meson" = git; then
2004     git_submodules="${git_submodules} meson"
2005 fi
2006
2007 case "$meson" in
2008     git | internal)
2009         if ! $python -c 'import pkg_resources' > /dev/null 2>&1; then
2010             error_exit "Python setuptools not found"
2011         fi
2012         meson="$python ${source_path}/meson/meson.py"
2013         ;;
2014     *) meson=$(command -v meson) ;;
2015 esac
2016
2017 # Probe for ninja (used for compdb)
2018
2019 if test -z "$ninja"; then
2020     for c in ninja ninja-build samu; do
2021         if has $c; then
2022             ninja=$(command -v "$c")
2023             break
2024         fi
2025     done
2026 fi
2027
2028 # Check that the C compiler works. Doing this here before testing
2029 # the host CPU ensures that we had a valid CC to autodetect the
2030 # $cpu var (and we should bail right here if that's not the case).
2031 # It also allows the help message to be printed without a CC.
2032 write_c_skeleton;
2033 if compile_object ; then
2034   : C compiler works ok
2035 else
2036     error_exit "\"$cc\" either does not exist or does not work"
2037 fi
2038 if ! compile_prog ; then
2039     error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
2040 fi
2041
2042 # Now we have handled --enable-tcg-interpreter and know we're not just
2043 # printing the help message, bail out if the host CPU isn't supported.
2044 if test "$ARCH" = "unknown"; then
2045     if test "$tcg_interpreter" = "yes" ; then
2046         echo "Unsupported CPU = $cpu, will use TCG with TCI (experimental)"
2047     else
2048         error_exit "Unsupported CPU = $cpu, try --enable-tcg-interpreter"
2049     fi
2050 fi
2051
2052 # Consult white-list to determine whether to enable werror
2053 # by default.  Only enable by default for git builds
2054 if test -z "$werror" ; then
2055     if test -e "$source_path/.git" && \
2056         { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
2057         werror="yes"
2058     else
2059         werror="no"
2060     fi
2061 fi
2062
2063 if test "$bogus_os" = "yes"; then
2064     # Now that we know that we're not printing the help and that
2065     # the compiler works (so the results of the check_defines we used
2066     # to identify the OS are reliable), if we didn't recognize the
2067     # host OS we should stop now.
2068     error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
2069 fi
2070
2071 # Check whether the compiler matches our minimum requirements:
2072 cat > $TMPC << EOF
2073 #if defined(__clang_major__) && defined(__clang_minor__)
2074 # ifdef __apple_build_version__
2075 #  if __clang_major__ < 5 || (__clang_major__ == 5 && __clang_minor__ < 1)
2076 #   error You need at least XCode Clang v5.1 to compile QEMU
2077 #  endif
2078 # else
2079 #  if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 4)
2080 #   error You need at least Clang v3.4 to compile QEMU
2081 #  endif
2082 # endif
2083 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
2084 # if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
2085 #  error You need at least GCC v4.8 to compile QEMU
2086 # endif
2087 #else
2088 # error You either need GCC or Clang to compiler QEMU
2089 #endif
2090 int main (void) { return 0; }
2091 EOF
2092 if ! compile_prog "" "" ; then
2093     error_exit "You need at least GCC v4.8 or Clang v3.4 (or XCode Clang v5.1)"
2094 fi
2095
2096 # Accumulate -Wfoo and -Wno-bar separately.
2097 # We will list all of the enable flags first, and the disable flags second.
2098 # Note that we do not add -Werror, because that would enable it for all
2099 # configure tests. If a configure test failed due to -Werror this would
2100 # just silently disable some features, so it's too error prone.
2101
2102 warn_flags=
2103 add_to warn_flags -Wold-style-declaration
2104 add_to warn_flags -Wold-style-definition
2105 add_to warn_flags -Wtype-limits
2106 add_to warn_flags -Wformat-security
2107 add_to warn_flags -Wformat-y2k
2108 add_to warn_flags -Winit-self
2109 add_to warn_flags -Wignored-qualifiers
2110 add_to warn_flags -Wempty-body
2111 add_to warn_flags -Wnested-externs
2112 add_to warn_flags -Wendif-labels
2113 add_to warn_flags -Wexpansion-to-defined
2114
2115 nowarn_flags=
2116 add_to nowarn_flags -Wno-initializer-overrides
2117 add_to nowarn_flags -Wno-missing-include-dirs
2118 add_to nowarn_flags -Wno-shift-negative-value
2119 add_to nowarn_flags -Wno-string-plus-int
2120 add_to nowarn_flags -Wno-typedef-redefinition
2121 add_to nowarn_flags -Wno-tautological-type-limit-compare
2122 add_to nowarn_flags -Wno-psabi
2123
2124 gcc_flags="$warn_flags $nowarn_flags"
2125
2126 cc_has_warning_flag() {
2127     write_c_skeleton;
2128
2129     # Use the positive sense of the flag when testing for -Wno-wombat
2130     # support (gcc will happily accept the -Wno- form of unknown
2131     # warning options).
2132     optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
2133     compile_prog "-Werror $optflag" ""
2134 }
2135
2136 for flag in $gcc_flags; do
2137     if cc_has_warning_flag $flag ; then
2138         QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2139     fi
2140 done
2141
2142 if test "$stack_protector" != "no"; then
2143   cat > $TMPC << EOF
2144 int main(int argc, char *argv[])
2145 {
2146     char arr[64], *p = arr, *c = argv[0];
2147     while (*c) {
2148         *p++ = *c++;
2149     }
2150     return 0;
2151 }
2152 EOF
2153   gcc_flags="-fstack-protector-strong -fstack-protector-all"
2154   sp_on=0
2155   for flag in $gcc_flags; do
2156     # We need to check both a compile and a link, since some compiler
2157     # setups fail only on a .c->.o compile and some only at link time
2158     if compile_object "-Werror $flag" &&
2159        compile_prog "-Werror $flag" ""; then
2160       QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2161       QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
2162       sp_on=1
2163       break
2164     fi
2165   done
2166   if test "$stack_protector" = yes; then
2167     if test $sp_on = 0; then
2168       error_exit "Stack protector not supported"
2169     fi
2170   fi
2171 fi
2172
2173 # Disable -Wmissing-braces on older compilers that warn even for
2174 # the "universal" C zero initializer {0}.
2175 cat > $TMPC << EOF
2176 struct {
2177   int a[2];
2178 } x = {0};
2179 EOF
2180 if compile_object "-Werror" "" ; then
2181   :
2182 else
2183   QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
2184 fi
2185
2186 # Our module code doesn't support Windows
2187 if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
2188   error_exit "Modules are not available for Windows"
2189 fi
2190
2191 # module_upgrades is only reasonable if modules are enabled
2192 if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
2193   error_exit "Can't enable module-upgrades as Modules are not enabled"
2194 fi
2195
2196 # Static linking is not possible with modules or PIE
2197 if test "$static" = "yes" ; then
2198   if test "$modules" = "yes" ; then
2199     error_exit "static and modules are mutually incompatible"
2200   fi
2201 fi
2202
2203 # Unconditional check for compiler __thread support
2204   cat > $TMPC << EOF
2205 static __thread int tls_var;
2206 int main(void) { return tls_var; }
2207 EOF
2208
2209 if ! compile_prog "-Werror" "" ; then
2210     error_exit "Your compiler does not support the __thread specifier for " \
2211         "Thread-Local Storage (TLS). Please upgrade to a version that does."
2212 fi
2213
2214 cat > $TMPC << EOF
2215
2216 #ifdef __linux__
2217 #  define THREAD __thread
2218 #else
2219 #  define THREAD
2220 #endif
2221 static THREAD int tls_var;
2222 int main(void) { return tls_var; }
2223 EOF
2224
2225 # Check we support --no-pie first; we will need this for building ROMs.
2226 if compile_prog "-Werror -fno-pie" "-no-pie"; then
2227   CFLAGS_NOPIE="-fno-pie"
2228   LDFLAGS_NOPIE="-no-pie"
2229 fi
2230
2231 if test "$static" = "yes"; then
2232   if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
2233     CFLAGS="-fPIE -DPIE $CFLAGS"
2234     QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
2235     pie="yes"
2236   elif test "$pie" = "yes"; then
2237     error_exit "-static-pie not available due to missing toolchain support"
2238   else
2239     QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
2240     pie="no"
2241   fi
2242 elif test "$pie" = "no"; then
2243   CFLAGS="$CFLAGS_NOPIE $CFLAGS"
2244   LDFLAGS="$LDFLAGS_NOPIE $LDFLAGS"
2245 elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
2246   CFLAGS="-fPIE -DPIE $CFLAGS"
2247   LDFLAGS="-pie $LDFLAGS"
2248   pie="yes"
2249 elif test "$pie" = "yes"; then
2250   error_exit "PIE not available due to missing toolchain support"
2251 else
2252   echo "Disabling PIE due to missing toolchain support"
2253   pie="no"
2254 fi
2255
2256 # Detect support for PT_GNU_RELRO + DT_BIND_NOW.
2257 # The combination is known as "full relro", because .got.plt is read-only too.
2258 if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
2259   QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
2260 fi
2261
2262 ##########################################
2263 # __sync_fetch_and_and requires at least -march=i486. Many toolchains
2264 # use i686 as default anyway, but for those that don't, an explicit
2265 # specification is necessary
2266
2267 if test "$cpu" = "i386"; then
2268   cat > $TMPC << EOF
2269 static int sfaa(int *ptr)
2270 {
2271   return __sync_fetch_and_and(ptr, 0);
2272 }
2273
2274 int main(void)
2275 {
2276   int val = 42;
2277   val = __sync_val_compare_and_swap(&val, 0, 1);
2278   sfaa(&val);
2279   return val;
2280 }
2281 EOF
2282   if ! compile_prog "" "" ; then
2283     QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
2284   fi
2285 fi
2286
2287 #########################################
2288 # Solaris specific configure tool chain decisions
2289
2290 if test "$solaris" = "yes" ; then
2291   if has ar; then
2292     :
2293   else
2294     if test -f /usr/ccs/bin/ar ; then
2295       error_exit "No path includes ar" \
2296           "Add /usr/ccs/bin to your path and rerun configure"
2297     fi
2298     error_exit "No path includes ar"
2299   fi
2300 fi
2301
2302 if test -z "${target_list+xxx}" ; then
2303     for target in $default_target_list; do
2304         supported_target $target 2>/dev/null && \
2305             target_list="$target_list $target"
2306     done
2307     target_list="${target_list# }"
2308 else
2309     target_list=$(echo "$target_list" | sed -e 's/,/ /g')
2310     for target in $target_list; do
2311         # Check that we recognised the target name; this allows a more
2312         # friendly error message than if we let it fall through.
2313         case " $default_target_list " in
2314             *" $target "*)
2315                 ;;
2316             *)
2317                 error_exit "Unknown target name '$target'"
2318                 ;;
2319         esac
2320         supported_target $target || exit 1
2321     done
2322 fi
2323
2324 # see if system emulation was really requested
2325 case " $target_list " in
2326   *"-softmmu "*) softmmu=yes
2327   ;;
2328   *) softmmu=no
2329   ;;
2330 esac
2331
2332 for target in $target_list; do
2333   case "$target" in
2334     arm-softmmu | aarch64-softmmu | i386-softmmu | x86_64-softmmu)
2335       edk2_blobs="yes"
2336       ;;
2337   esac
2338 done
2339 # The EDK2 binaries are compressed with bzip2
2340 if test "$edk2_blobs" = "yes" && ! has bzip2; then
2341   error_exit "The bzip2 program is required for building QEMU"
2342 fi
2343
2344 feature_not_found() {
2345   feature=$1
2346   remedy=$2
2347
2348   error_exit "User requested feature $feature" \
2349       "configure was not able to find it." \
2350       "$remedy"
2351 }
2352
2353 # ---
2354 # big/little endian test
2355 cat > $TMPC << EOF
2356 short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
2357 short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
2358 extern int foo(short *, short *);
2359 int main(int argc, char *argv[]) {
2360     return foo(big_endian, little_endian);
2361 }
2362 EOF
2363
2364 if compile_object ; then
2365     if strings -a $TMPO | grep -q BiGeNdIaN ; then
2366         bigendian="yes"
2367     elif strings -a $TMPO | grep -q LiTtLeEnDiAn ; then
2368         bigendian="no"
2369     else
2370         echo big/little test failed
2371     fi
2372 else
2373     echo big/little test failed
2374 fi
2375
2376 ##########################################
2377 # system tools
2378 if test -z "$want_tools"; then
2379     if test "$softmmu" = "no"; then
2380         want_tools=no
2381     else
2382         want_tools=yes
2383     fi
2384 fi
2385
2386 ##########################################
2387 # cocoa implies not SDL or GTK
2388 # (the cocoa UI code currently assumes it is always the active UI
2389 # and doesn't interact well with other UI frontend code)
2390 if test "$cocoa" = "yes"; then
2391     if test "$sdl" = "yes"; then
2392         error_exit "Cocoa and SDL UIs cannot both be enabled at once"
2393     fi
2394     if test "$gtk" = "yes"; then
2395         error_exit "Cocoa and GTK UIs cannot both be enabled at once"
2396     fi
2397     gtk=no
2398     sdl=disabled
2399 fi
2400
2401 # Some versions of Mac OS X incorrectly define SIZE_MAX
2402 cat > $TMPC << EOF
2403 #include <stdint.h>
2404 #include <stdio.h>
2405 int main(int argc, char *argv[]) {
2406     return printf("%zu", SIZE_MAX);
2407 }
2408 EOF
2409 have_broken_size_max=no
2410 if ! compile_object -Werror ; then
2411     have_broken_size_max=yes
2412 fi
2413
2414 ##########################################
2415 # L2TPV3 probe
2416
2417 cat > $TMPC <<EOF
2418 #include <sys/socket.h>
2419 #include <linux/ip.h>
2420 int main(void) { return sizeof(struct mmsghdr); }
2421 EOF
2422 if compile_prog "" "" ; then
2423   l2tpv3=yes
2424 else
2425   l2tpv3=no
2426 fi
2427
2428 if check_include "pty.h" ; then
2429   pty_h=yes
2430 else
2431   pty_h=no
2432 fi
2433
2434 cat > $TMPC <<EOF
2435 #include <sys/mman.h>
2436 int main(int argc, char *argv[]) {
2437     return mlockall(MCL_FUTURE);
2438 }
2439 EOF
2440 if compile_prog "" "" ; then
2441   have_mlockall=yes
2442 else
2443   have_mlockall=no
2444 fi
2445
2446 #########################################
2447 # vhost interdependencies and host support
2448
2449 # vhost backends
2450 test "$vhost_user" = "" && vhost_user=yes
2451 if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then
2452   error_exit "vhost-user isn't available on win32"
2453 fi
2454 test "$vhost_vdpa" = "" && vhost_vdpa=$linux
2455 if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
2456   error_exit "vhost-vdpa is only available on Linux"
2457 fi
2458 test "$vhost_kernel" = "" && vhost_kernel=$linux
2459 if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
2460   error_exit "vhost-kernel is only available on Linux"
2461 fi
2462
2463 # vhost-kernel devices
2464 test "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
2465 if test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
2466   error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
2467 fi
2468 test "$vhost_vsock" = "" && vhost_vsock=$vhost_kernel
2469 if test "$vhost_vsock" = "yes" && test "$vhost_kernel" != "yes"; then
2470   error_exit "--enable-vhost-vsock requires --enable-vhost-kernel"
2471 fi
2472
2473 # vhost-user backends
2474 test "$vhost_net_user" = "" && vhost_net_user=$vhost_user
2475 if test "$vhost_net_user" = "yes" && test "$vhost_user" = "no"; then
2476   error_exit "--enable-vhost-net-user requires --enable-vhost-user"
2477 fi
2478 test "$vhost_crypto" = "" && vhost_crypto=$vhost_user
2479 if test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
2480   error_exit "--enable-vhost-crypto requires --enable-vhost-user"
2481 fi
2482 test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
2483 if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
2484   error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
2485 fi
2486 #vhost-vdpa backends
2487 test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa
2488 if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then
2489   error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa"
2490 fi
2491
2492 # OR the vhost-kernel and vhost-user values for simplicity
2493 if test "$vhost_net" = ""; then
2494   test "$vhost_net_user" = "yes" && vhost_net=yes
2495   test "$vhost_kernel" = "yes" && vhost_net=yes
2496 fi
2497
2498 ##########################################
2499 # MinGW / Mingw-w64 localtime_r/gmtime_r check
2500
2501 if test "$mingw32" = "yes"; then
2502     # Some versions of MinGW / Mingw-w64 lack localtime_r
2503     # and gmtime_r entirely.
2504     #
2505     # Some versions of Mingw-w64 define a macro for
2506     # localtime_r/gmtime_r.
2507     #
2508     # Some versions of Mingw-w64 will define functions
2509     # for localtime_r/gmtime_r, but only if you have
2510     # _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun
2511     # though, unistd.h and pthread.h both define
2512     # that for you.
2513     #
2514     # So this #undef localtime_r and #include <unistd.h>
2515     # are not in fact redundant.
2516 cat > $TMPC << EOF
2517 #include <unistd.h>
2518 #include <time.h>
2519 #undef localtime_r
2520 int main(void) { localtime_r(NULL, NULL); return 0; }
2521 EOF
2522     if compile_prog "" "" ; then
2523         localtime_r="yes"
2524     else
2525         localtime_r="no"
2526     fi
2527 fi
2528
2529 ##########################################
2530 # pkg-config probe
2531
2532 if ! has "$pkg_config_exe"; then
2533   error_exit "pkg-config binary '$pkg_config_exe' not found"
2534 fi
2535
2536 ##########################################
2537 # NPTL probe
2538
2539 if test "$linux_user" = "yes"; then
2540   cat > $TMPC <<EOF
2541 #include <sched.h>
2542 #include <linux/futex.h>
2543 int main(void) {
2544 #if !defined(CLONE_SETTLS) || !defined(FUTEX_WAIT)
2545 #error bork
2546 #endif
2547   return 0;
2548 }
2549 EOF
2550   if ! compile_object ; then
2551     feature_not_found "nptl" "Install glibc and linux kernel headers."
2552   fi
2553 fi
2554
2555 ##########################################
2556 # lzo check
2557
2558 if test "$lzo" != "no" ; then
2559     cat > $TMPC << EOF
2560 #include <lzo/lzo1x.h>
2561 int main(void) { lzo_version(); return 0; }
2562 EOF
2563     if compile_prog "" "-llzo2" ; then
2564         lzo_libs="-llzo2"
2565         lzo="yes"
2566     else
2567         if test "$lzo" = "yes"; then
2568             feature_not_found "liblzo2" "Install liblzo2 devel"
2569         fi
2570         lzo="no"
2571     fi
2572 fi
2573
2574 ##########################################
2575 # snappy check
2576
2577 if test "$snappy" != "no" ; then
2578     cat > $TMPC << EOF
2579 #include <snappy-c.h>
2580 int main(void) { snappy_max_compressed_length(4096); return 0; }
2581 EOF
2582     if compile_prog "" "-lsnappy" ; then
2583         snappy_libs='-lsnappy'
2584         snappy="yes"
2585     else
2586         if test "$snappy" = "yes"; then
2587             feature_not_found "libsnappy" "Install libsnappy devel"
2588         fi
2589         snappy="no"
2590     fi
2591 fi
2592
2593 ##########################################
2594 # bzip2 check
2595
2596 if test "$bzip2" != "no" ; then
2597     cat > $TMPC << EOF
2598 #include <bzlib.h>
2599 int main(void) { BZ2_bzlibVersion(); return 0; }
2600 EOF
2601     if compile_prog "" "-lbz2" ; then
2602         bzip2="yes"
2603     else
2604         if test "$bzip2" = "yes"; then
2605             feature_not_found "libbzip2" "Install libbzip2 devel"
2606         fi
2607         bzip2="no"
2608     fi
2609 fi
2610
2611 ##########################################
2612 # lzfse check
2613
2614 if test "$lzfse" != "no" ; then
2615     cat > $TMPC << EOF
2616 #include <lzfse.h>
2617 int main(void) { lzfse_decode_scratch_size(); return 0; }
2618 EOF
2619     if compile_prog "" "-llzfse" ; then
2620         lzfse="yes"
2621     else
2622         if test "$lzfse" = "yes"; then
2623             feature_not_found "lzfse" "Install lzfse devel"
2624         fi
2625         lzfse="no"
2626     fi
2627 fi
2628
2629 ##########################################
2630 # zstd check
2631
2632 if test "$zstd" != "no" ; then
2633     libzstd_minver="1.4.0"
2634     if $pkg_config --atleast-version=$libzstd_minver libzstd ; then
2635         zstd_cflags="$($pkg_config --cflags libzstd)"
2636         zstd_libs="$($pkg_config --libs libzstd)"
2637         zstd="yes"
2638     else
2639         if test "$zstd" = "yes" ; then
2640             feature_not_found "libzstd" "Install libzstd devel"
2641         fi
2642         zstd="no"
2643     fi
2644 fi
2645
2646 ##########################################
2647 # libseccomp check
2648
2649 if test "$seccomp" != "no" ; then
2650     libseccomp_minver="2.3.0"
2651     if $pkg_config --atleast-version=$libseccomp_minver libseccomp ; then
2652         seccomp_cflags="$($pkg_config --cflags libseccomp)"
2653         seccomp_libs="$($pkg_config --libs libseccomp)"
2654         seccomp="yes"
2655     else
2656         if test "$seccomp" = "yes" ; then
2657             feature_not_found "libseccomp" \
2658                  "Install libseccomp devel >= $libseccomp_minver"
2659         fi
2660         seccomp="no"
2661     fi
2662 fi
2663 ##########################################
2664 # xen probe
2665
2666 if test "$xen" != "no" ; then
2667   # Check whether Xen library path is specified via --extra-ldflags to avoid
2668   # overriding this setting with pkg-config output. If not, try pkg-config
2669   # to obtain all needed flags.
2670
2671   if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \
2672      $pkg_config --exists xencontrol ; then
2673     xen_ctrl_version="$(printf '%d%02d%02d' \
2674       $($pkg_config --modversion xencontrol | sed 's/\./ /g') )"
2675     xen=yes
2676     xen_pc="xencontrol xenstore xenguest xenforeignmemory xengnttab"
2677     xen_pc="$xen_pc xenevtchn xendevicemodel"
2678     if $pkg_config --exists xentoolcore; then
2679       xen_pc="$xen_pc xentoolcore"
2680     fi
2681     xen_cflags="$($pkg_config --cflags $xen_pc)"
2682     xen_libs="$($pkg_config --libs $xen_pc)"
2683   else
2684
2685     xen_libs="-lxenstore -lxenctrl -lxenguest"
2686     xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
2687
2688     # First we test whether Xen headers and libraries are available.
2689     # If no, we are done and there is no Xen support.
2690     # If yes, more tests are run to detect the Xen version.
2691
2692     # Xen (any)
2693     cat > $TMPC <<EOF
2694 #include <xenctrl.h>
2695 int main(void) {
2696   return 0;
2697 }
2698 EOF
2699     if ! compile_prog "" "$xen_libs" ; then
2700       # Xen not found
2701       if test "$xen" = "yes" ; then
2702         feature_not_found "xen" "Install xen devel"
2703       fi
2704       xen=no
2705
2706     # Xen unstable
2707     elif
2708         cat > $TMPC <<EOF &&
2709 #undef XC_WANT_COMPAT_DEVICEMODEL_API
2710 #define __XEN_TOOLS__
2711 #include <xendevicemodel.h>
2712 #include <xenforeignmemory.h>
2713 int main(void) {
2714   xendevicemodel_handle *xd;
2715   xenforeignmemory_handle *xfmem;
2716
2717   xd = xendevicemodel_open(0, 0);
2718   xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);
2719
2720   xfmem = xenforeignmemory_open(0, 0);
2721   xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);
2722
2723   return 0;
2724 }
2725 EOF
2726         compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
2727       then
2728       xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
2729       xen_ctrl_version=41100
2730       xen=yes
2731     elif
2732         cat > $TMPC <<EOF &&
2733 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
2734 #include <xenforeignmemory.h>
2735 #include <xentoolcore.h>
2736 int main(void) {
2737   xenforeignmemory_handle *xfmem;
2738
2739   xfmem = xenforeignmemory_open(0, 0);
2740   xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
2741   xentoolcore_restrict_all(0);
2742
2743   return 0;
2744 }
2745 EOF
2746         compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
2747       then
2748       xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
2749       xen_ctrl_version=41000
2750       xen=yes
2751     elif
2752         cat > $TMPC <<EOF &&
2753 #undef XC_WANT_COMPAT_DEVICEMODEL_API
2754 #define __XEN_TOOLS__
2755 #include <xendevicemodel.h>
2756 int main(void) {
2757   xendevicemodel_handle *xd;
2758
2759   xd = xendevicemodel_open(0, 0);
2760   xendevicemodel_close(xd);
2761
2762   return 0;
2763 }
2764 EOF
2765         compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs"
2766       then
2767       xen_stable_libs="-lxendevicemodel $xen_stable_libs"
2768       xen_ctrl_version=40900
2769       xen=yes
2770     elif
2771         cat > $TMPC <<EOF &&
2772 /*
2773  * If we have stable libs the we don't want the libxc compat
2774  * layers, regardless of what CFLAGS we may have been given.
2775  *
2776  * Also, check if xengnttab_grant_copy_segment_t is defined and
2777  * grant copy operation is implemented.
2778  */
2779 #undef XC_WANT_COMPAT_EVTCHN_API
2780 #undef XC_WANT_COMPAT_GNTTAB_API
2781 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
2782 #include <xenctrl.h>
2783 #include <xenstore.h>
2784 #include <xenevtchn.h>
2785 #include <xengnttab.h>
2786 #include <xenforeignmemory.h>
2787 #include <stdint.h>
2788 #include <xen/hvm/hvm_info_table.h>
2789 #if !defined(HVM_MAX_VCPUS)
2790 # error HVM_MAX_VCPUS not defined
2791 #endif
2792 int main(void) {
2793   xc_interface *xc = NULL;
2794   xenforeignmemory_handle *xfmem;
2795   xenevtchn_handle *xe;
2796   xengnttab_handle *xg;
2797   xengnttab_grant_copy_segment_t* seg = NULL;
2798
2799   xs_daemon_open();
2800
2801   xc = xc_interface_open(0, 0, 0);
2802   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2803   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2804   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2805   xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2806
2807   xfmem = xenforeignmemory_open(0, 0);
2808   xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2809
2810   xe = xenevtchn_open(0, 0);
2811   xenevtchn_fd(xe);
2812
2813   xg = xengnttab_open(0, 0);
2814   xengnttab_grant_copy(xg, 0, seg);
2815
2816   return 0;
2817 }
2818 EOF
2819         compile_prog "" "$xen_libs $xen_stable_libs"
2820       then
2821       xen_ctrl_version=40800
2822       xen=yes
2823     elif
2824         cat > $TMPC <<EOF &&
2825 /*
2826  * If we have stable libs the we don't want the libxc compat
2827  * layers, regardless of what CFLAGS we may have been given.
2828  */
2829 #undef XC_WANT_COMPAT_EVTCHN_API
2830 #undef XC_WANT_COMPAT_GNTTAB_API
2831 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
2832 #include <xenctrl.h>
2833 #include <xenstore.h>
2834 #include <xenevtchn.h>
2835 #include <xengnttab.h>
2836 #include <xenforeignmemory.h>
2837 #include <stdint.h>
2838 #include <xen/hvm/hvm_info_table.h>
2839 #if !defined(HVM_MAX_VCPUS)
2840 # error HVM_MAX_VCPUS not defined
2841 #endif
2842 int main(void) {
2843   xc_interface *xc = NULL;
2844   xenforeignmemory_handle *xfmem;
2845   xenevtchn_handle *xe;
2846   xengnttab_handle *xg;
2847
2848   xs_daemon_open();
2849
2850   xc = xc_interface_open(0, 0, 0);
2851   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2852   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2853   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2854   xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2855
2856   xfmem = xenforeignmemory_open(0, 0);
2857   xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2858
2859   xe = xenevtchn_open(0, 0);
2860   xenevtchn_fd(xe);
2861
2862   xg = xengnttab_open(0, 0);
2863   xengnttab_map_grant_ref(xg, 0, 0, 0);
2864
2865   return 0;
2866 }
2867 EOF
2868         compile_prog "" "$xen_libs $xen_stable_libs"
2869       then
2870       xen_ctrl_version=40701
2871       xen=yes
2872
2873     # Xen 4.6
2874     elif
2875         cat > $TMPC <<EOF &&
2876 #include <xenctrl.h>
2877 #include <xenstore.h>
2878 #include <stdint.h>
2879 #include <xen/hvm/hvm_info_table.h>
2880 #if !defined(HVM_MAX_VCPUS)
2881 # error HVM_MAX_VCPUS not defined
2882 #endif
2883 int main(void) {
2884   xc_interface *xc;
2885   xs_daemon_open();
2886   xc = xc_interface_open(0, 0, 0);
2887   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2888   xc_gnttab_open(NULL, 0);
2889   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2890   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2891   xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2892   xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
2893   return 0;
2894 }
2895 EOF
2896         compile_prog "" "$xen_libs"
2897       then
2898       xen_ctrl_version=40600
2899       xen=yes
2900
2901     # Xen 4.5
2902     elif
2903         cat > $TMPC <<EOF &&
2904 #include <xenctrl.h>
2905 #include <xenstore.h>
2906 #include <stdint.h>
2907 #include <xen/hvm/hvm_info_table.h>
2908 #if !defined(HVM_MAX_VCPUS)
2909 # error HVM_MAX_VCPUS not defined
2910 #endif
2911 int main(void) {
2912   xc_interface *xc;
2913   xs_daemon_open();
2914   xc = xc_interface_open(0, 0, 0);
2915   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2916   xc_gnttab_open(NULL, 0);
2917   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2918   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2919   xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
2920   return 0;
2921 }
2922 EOF
2923         compile_prog "" "$xen_libs"
2924       then
2925       xen_ctrl_version=40500
2926       xen=yes
2927
2928     elif
2929         cat > $TMPC <<EOF &&
2930 #include <xenctrl.h>
2931 #include <xenstore.h>
2932 #include <stdint.h>
2933 #include <xen/hvm/hvm_info_table.h>
2934 #if !defined(HVM_MAX_VCPUS)
2935 # error HVM_MAX_VCPUS not defined
2936 #endif
2937 int main(void) {
2938   xc_interface *xc;
2939   xs_daemon_open();
2940   xc = xc_interface_open(0, 0, 0);
2941   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2942   xc_gnttab_open(NULL, 0);
2943   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2944   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2945   return 0;
2946 }
2947 EOF
2948         compile_prog "" "$xen_libs"
2949       then
2950       xen_ctrl_version=40200
2951       xen=yes
2952
2953     else
2954       if test "$xen" = "yes" ; then
2955         feature_not_found "xen (unsupported version)" \
2956                           "Install a supported xen (xen 4.2 or newer)"
2957       fi
2958       xen=no
2959     fi
2960
2961     if test "$xen" = yes; then
2962       if test $xen_ctrl_version -ge 40701  ; then
2963         xen_libs="$xen_libs $xen_stable_libs "
2964       fi
2965     fi
2966   fi
2967 fi
2968
2969 if test "$xen_pci_passthrough" != "no"; then
2970   if test "$xen" = "yes" && test "$linux" = "yes"; then
2971     xen_pci_passthrough=yes
2972   else
2973     if test "$xen_pci_passthrough" = "yes"; then
2974       error_exit "User requested feature Xen PCI Passthrough" \
2975           " but this feature requires /sys from Linux"
2976     fi
2977     xen_pci_passthrough=no
2978   fi
2979 fi
2980
2981 ##########################################
2982 # Windows Hypervisor Platform accelerator (WHPX) check
2983 if test "$whpx" != "no" ; then
2984     if check_include "WinHvPlatform.h" && check_include "WinHvEmulation.h"; then
2985         whpx="yes"
2986     else
2987         if test "$whpx" = "yes"; then
2988             feature_not_found "WinHvPlatform" "WinHvEmulation is not installed"
2989         fi
2990         whpx="no"
2991     fi
2992 fi
2993
2994 ##########################################
2995 # gettext probe
2996 if test "$gettext" != "false" ; then
2997   if has xgettext; then
2998     gettext=true
2999   else
3000     if test "$gettext" = "true" ; then
3001       feature_not_found "gettext" "Install xgettext binary"
3002     fi
3003     gettext=false
3004   fi
3005 fi
3006
3007 ##########################################
3008 # Sparse probe
3009 if test "$sparse" != "no" ; then
3010   if has sparse; then
3011     sparse=yes
3012   else
3013     if test "$sparse" = "yes" ; then
3014       feature_not_found "sparse" "Install sparse binary"
3015     fi
3016     sparse=no
3017   fi
3018 fi
3019
3020 ##########################################
3021 # X11 probe
3022 if $pkg_config --exists "x11"; then
3023     have_x11=yes
3024     x11_cflags=$($pkg_config --cflags x11)
3025     x11_libs=$($pkg_config --libs x11)
3026 fi
3027
3028 ##########################################
3029 # GTK probe
3030
3031 if test "$gtk" != "no"; then
3032     gtkpackage="gtk+-3.0"
3033     gtkx11package="gtk+-x11-3.0"
3034     gtkversion="3.22.0"
3035     if $pkg_config --exists "$gtkpackage >= $gtkversion"; then
3036         gtk_cflags=$($pkg_config --cflags $gtkpackage)
3037         gtk_libs=$($pkg_config --libs $gtkpackage)
3038         gtk_version=$($pkg_config --modversion $gtkpackage)
3039         if $pkg_config --exists "$gtkx11package >= $gtkversion"; then
3040             need_x11=yes
3041             gtk_cflags="$gtk_cflags $x11_cflags"
3042             gtk_libs="$gtk_libs $x11_libs"
3043         fi
3044         gtk="yes"
3045     elif test "$gtk" = "yes"; then
3046         feature_not_found "gtk" "Install gtk3-devel"
3047     else
3048         gtk="no"
3049     fi
3050 fi
3051
3052
3053 ##########################################
3054 # GNUTLS probe
3055
3056 if test "$gnutls" != "no"; then
3057     pass="no"
3058     if $pkg_config --exists "gnutls >= 3.1.18"; then
3059         gnutls_cflags=$($pkg_config --cflags gnutls)
3060         gnutls_libs=$($pkg_config --libs gnutls)
3061         # Packaging for the static libraries is not always correct.
3062         # At least ubuntu 18.04 ships only shared libraries.
3063         write_c_skeleton
3064         if compile_prog "" "$gnutls_libs" ; then
3065             pass="yes"
3066         fi
3067     fi
3068     if test "$pass" = "no" && test "$gnutls" = "yes"; then
3069         feature_not_found "gnutls" "Install gnutls devel >= 3.1.18"
3070     else
3071         gnutls="$pass"
3072     fi
3073 fi
3074
3075
3076 # If user didn't give a --disable/enable-gcrypt flag,
3077 # then mark as disabled if user requested nettle
3078 # explicitly
3079 if test -z "$gcrypt"
3080 then
3081     if test "$nettle" = "yes"
3082     then
3083         gcrypt="no"
3084     fi
3085 fi
3086
3087 # If user didn't give a --disable/enable-nettle flag,
3088 # then mark as disabled if user requested gcrypt
3089 # explicitly
3090 if test -z "$nettle"
3091 then
3092     if test "$gcrypt" = "yes"
3093     then
3094         nettle="no"
3095     fi
3096 fi
3097
3098 has_libgcrypt() {
3099     if ! has "libgcrypt-config"
3100     then
3101         return 1
3102     fi
3103
3104     if test -n "$cross_prefix"
3105     then
3106         host=$(libgcrypt-config --host)
3107         if test "$host-" != $cross_prefix
3108         then
3109             return 1
3110         fi
3111     fi
3112
3113     maj=`libgcrypt-config --version | awk -F . '{print $1}'`
3114     min=`libgcrypt-config --version | awk -F . '{print $2}'`
3115
3116     if test $maj != 1 || test $min -lt 5
3117     then
3118        return 1
3119     fi
3120
3121     return 0
3122 }
3123
3124
3125 if test "$nettle" != "no"; then
3126     pass="no"
3127     if $pkg_config --exists "nettle >= 2.7.1"; then
3128         nettle_cflags=$($pkg_config --cflags nettle)
3129         nettle_libs=$($pkg_config --libs nettle)
3130         nettle_version=$($pkg_config --modversion nettle)
3131         # Link test to make sure the given libraries work (e.g for static).
3132         write_c_skeleton
3133         if compile_prog "" "$nettle_libs" ; then
3134             if test -z "$gcrypt"; then
3135                gcrypt="no"
3136             fi
3137             pass="yes"
3138         fi
3139     fi
3140     if test "$pass" = "yes"
3141     then
3142         cat > $TMPC << EOF
3143 #include <nettle/xts.h>
3144 int main(void) {
3145   return 0;
3146 }
3147 EOF
3148         if compile_prog "$nettle_cflags" "$nettle_libs" ; then
3149             nettle_xts=yes
3150             qemu_private_xts=no
3151         fi
3152     fi
3153     if test "$pass" = "no" && test "$nettle" = "yes"; then
3154         feature_not_found "nettle" "Install nettle devel >= 2.7.1"
3155     else
3156         nettle="$pass"
3157     fi
3158 fi
3159
3160 if test "$gcrypt" != "no"; then
3161     pass="no"
3162     if has_libgcrypt; then
3163         gcrypt_cflags=$(libgcrypt-config --cflags)
3164         gcrypt_libs=$(libgcrypt-config --libs)
3165         # Debian has removed -lgpg-error from libgcrypt-config
3166         # as it "spreads unnecessary dependencies" which in
3167         # turn breaks static builds...
3168         if test "$static" = "yes"
3169         then
3170             gcrypt_libs="$gcrypt_libs -lgpg-error"
3171         fi
3172
3173         # Link test to make sure the given libraries work (e.g for static).
3174         write_c_skeleton
3175         if compile_prog "" "$gcrypt_libs" ; then
3176             pass="yes"
3177         fi
3178     fi
3179     if test "$pass" = "yes"; then
3180         gcrypt="yes"
3181         cat > $TMPC << EOF
3182 #include <gcrypt.h>
3183 int main(void) {
3184   gcry_mac_hd_t handle;
3185   gcry_mac_open(&handle, GCRY_MAC_HMAC_MD5,
3186                 GCRY_MAC_FLAG_SECURE, NULL);
3187   return 0;
3188 }
3189 EOF
3190         if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then
3191             gcrypt_hmac=yes
3192         fi
3193         cat > $TMPC << EOF
3194 #include <gcrypt.h>
3195 int main(void) {
3196   gcry_cipher_hd_t handle;
3197   gcry_cipher_open(&handle, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_XTS, 0);
3198   return 0;
3199 }
3200 EOF
3201         if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then
3202             gcrypt_xts=yes
3203             qemu_private_xts=no
3204         fi
3205     elif test "$gcrypt" = "yes"; then
3206         feature_not_found "gcrypt" "Install gcrypt devel >= 1.5.0"
3207     else
3208         gcrypt="no"
3209     fi
3210 fi
3211
3212
3213 if test "$gcrypt" = "yes" && test "$nettle" = "yes"
3214 then
3215     error_exit "Only one of gcrypt & nettle can be enabled"
3216 fi
3217
3218 ##########################################
3219 # libtasn1 - only for the TLS creds/session test suite
3220
3221 tasn1=yes
3222 tasn1_cflags=""
3223 tasn1_libs=""
3224 if $pkg_config --exists "libtasn1"; then
3225     tasn1_cflags=$($pkg_config --cflags libtasn1)
3226     tasn1_libs=$($pkg_config --libs libtasn1)
3227 else
3228     tasn1=no
3229 fi
3230
3231
3232 ##########################################
3233 # PAM probe
3234
3235 if test "$auth_pam" != "no"; then
3236     cat > $TMPC <<EOF
3237 #include <security/pam_appl.h>
3238 #include <stdio.h>
3239 int main(void) {
3240    const char *service_name = "qemu";
3241    const char *user = "frank";
3242    const struct pam_conv pam_conv = { 0 };
3243    pam_handle_t *pamh = NULL;
3244    pam_start(service_name, user, &pam_conv, &pamh);
3245    return 0;
3246 }
3247 EOF
3248     if compile_prog "" "-lpam" ; then
3249         auth_pam=yes
3250     else
3251         if test "$auth_pam" = "yes"; then
3252             feature_not_found "PAM" "Install PAM development package"
3253         else
3254             auth_pam=no
3255         fi
3256     fi
3257 fi
3258
3259 ##########################################
3260 # getifaddrs (for tests/test-io-channel-socket )
3261
3262 have_ifaddrs_h=yes
3263 if ! check_include "ifaddrs.h" ; then
3264   have_ifaddrs_h=no
3265 fi
3266
3267 #########################################
3268 # libdrm check
3269 have_drm_h=no
3270 if check_include "libdrm/drm.h" ; then
3271     have_drm_h=yes
3272 fi
3273
3274 #########################################
3275 # sys/signal.h check
3276 have_sys_signal_h=no
3277 if check_include "sys/signal.h" ; then
3278   have_sys_signal_h=yes
3279 fi
3280
3281 ##########################################
3282 # VTE probe
3283
3284 if test "$vte" != "no"; then
3285     vteminversion="0.32.0"
3286     if $pkg_config --exists "vte-2.91"; then
3287       vtepackage="vte-2.91"
3288     else
3289       vtepackage="vte-2.90"
3290     fi
3291     if $pkg_config --exists "$vtepackage >= $vteminversion"; then
3292         vte_cflags=$($pkg_config --cflags $vtepackage)
3293         vte_libs=$($pkg_config --libs $vtepackage)
3294         vteversion=$($pkg_config --modversion $vtepackage)
3295         vte="yes"
3296     elif test "$vte" = "yes"; then
3297         feature_not_found "vte" "Install libvte-2.90/2.91 devel"
3298     else
3299         vte="no"
3300     fi
3301 fi
3302
3303 ##########################################
3304 # RDMA needs OpenFabrics libraries
3305 if test "$rdma" != "no" ; then
3306   cat > $TMPC <<EOF
3307 #include <rdma/rdma_cma.h>
3308 int main(void) { return 0; }
3309 EOF
3310   rdma_libs="-lrdmacm -libverbs -libumad"
3311   if compile_prog "" "$rdma_libs" ; then
3312     rdma="yes"
3313   else
3314     if test "$rdma" = "yes" ; then
3315         error_exit \
3316             " OpenFabrics librdmacm/libibverbs/libibumad not present." \
3317             " Your options:" \
3318             "  (1) Fast: Install infiniband packages (devel) from your distro." \
3319             "  (2) Cleanest: Install libraries from www.openfabrics.org" \
3320             "  (3) Also: Install softiwarp if you don't have RDMA hardware"
3321     fi
3322     rdma="no"
3323   fi
3324 fi
3325
3326 ##########################################
3327 # PVRDMA detection
3328
3329 cat > $TMPC <<EOF &&
3330 #include <sys/mman.h>
3331
3332 int
3333 main(void)
3334 {
3335     char buf = 0;
3336     void *addr = &buf;
3337     addr = mremap(addr, 0, 1, MREMAP_MAYMOVE | MREMAP_FIXED);
3338
3339     return 0;
3340 }
3341 EOF
3342
3343 if test "$rdma" = "yes" ; then
3344     case "$pvrdma" in
3345     "")
3346         if compile_prog "" ""; then
3347             pvrdma="yes"
3348         else
3349             pvrdma="no"
3350         fi
3351         ;;
3352     "yes")
3353         if ! compile_prog "" ""; then
3354             error_exit "PVRDMA is not supported since mremap is not implemented"
3355         fi
3356         pvrdma="yes"
3357         ;;
3358     "no")
3359         pvrdma="no"
3360         ;;
3361     esac
3362 else
3363     if test "$pvrdma" = "yes" ; then
3364         error_exit "PVRDMA requires rdma suppport"
3365     fi
3366     pvrdma="no"
3367 fi
3368
3369 # Let's see if enhanced reg_mr is supported
3370 if test "$pvrdma" = "yes" ; then
3371
3372 cat > $TMPC <<EOF &&
3373 #include <infiniband/verbs.h>
3374
3375 int
3376 main(void)
3377 {
3378     struct ibv_mr *mr;
3379     struct ibv_pd *pd = NULL;
3380     size_t length = 10;
3381     uint64_t iova = 0;
3382     int access = 0;
3383     void *addr = NULL;
3384
3385     mr = ibv_reg_mr_iova(pd, addr, length, iova, access);
3386
3387     ibv_dereg_mr(mr);
3388
3389     return 0;
3390 }
3391 EOF
3392     if ! compile_prog "" "-libverbs"; then
3393         QEMU_CFLAGS="$QEMU_CFLAGS -DLEGACY_RDMA_REG_MR"
3394     fi
3395 fi
3396
3397 ##########################################
3398 # xfsctl() probe, used for file-posix.c
3399 if test "$xfs" != "no" ; then
3400   cat > $TMPC << EOF
3401 #include <stddef.h>  /* NULL */
3402 #include <xfs/xfs.h>
3403 int main(void)
3404 {
3405     xfsctl(NULL, 0, 0, NULL);
3406     return 0;
3407 }
3408 EOF
3409   if compile_prog "" "" ; then
3410     xfs="yes"
3411   else
3412     if test "$xfs" = "yes" ; then
3413       feature_not_found "xfs" "Instal xfsprogs/xfslibs devel"
3414     fi
3415     xfs=no
3416   fi
3417 fi
3418
3419 ##########################################
3420 # vde libraries probe
3421 if test "$vde" != "no" ; then
3422   vde_libs="-lvdeplug"
3423   cat > $TMPC << EOF
3424 #include <libvdeplug.h>
3425 int main(void)
3426 {
3427     struct vde_open_args a = {0, 0, 0};
3428     char s[] = "";
3429     vde_open(s, s, &a);
3430     return 0;
3431 }
3432 EOF
3433   if compile_prog "" "$vde_libs" ; then
3434     vde=yes
3435   else
3436     if test "$vde" = "yes" ; then
3437       feature_not_found "vde" "Install vde (Virtual Distributed Ethernet) devel"
3438     fi
3439     vde=no
3440   fi
3441 fi
3442
3443 ##########################################
3444 # netmap support probe
3445 # Apart from looking for netmap headers, we make sure that the host API version
3446 # supports the netmap backend (>=11). The upper bound (15) is meant to simulate
3447 # a minor/major version number. Minor new features will be marked with values up
3448 # to 15, and if something happens that requires a change to the backend we will
3449 # move above 15, submit the backend fixes and modify this two bounds.
3450 if test "$netmap" != "no" ; then
3451   cat > $TMPC << EOF
3452 #include <inttypes.h>
3453 #include <net/if.h>
3454 #include <net/netmap.h>
3455 #include <net/netmap_user.h>
3456 #if (NETMAP_API < 11) || (NETMAP_API > 15)
3457 #error
3458 #endif
3459 int main(void) { return 0; }
3460 EOF
3461   if compile_prog "" "" ; then
3462     netmap=yes
3463   else
3464     if test "$netmap" = "yes" ; then
3465       feature_not_found "netmap"
3466     fi
3467     netmap=no
3468   fi
3469 fi
3470
3471 ##########################################
3472 # libcap-ng library probe
3473 if test "$cap_ng" != "no" ; then
3474   cap_libs="-lcap-ng"
3475   cat > $TMPC << EOF
3476 #include <cap-ng.h>
3477 int main(void)
3478 {
3479     capng_capability_to_name(CAPNG_EFFECTIVE);
3480     return 0;
3481 }
3482 EOF
3483   if compile_prog "" "$cap_libs" ; then
3484     cap_ng=yes
3485   else
3486     if test "$cap_ng" = "yes" ; then
3487       feature_not_found "cap_ng" "Install libcap-ng devel"
3488     fi
3489     cap_ng=no
3490   fi
3491 fi
3492
3493 ##########################################
3494 # Sound support libraries probe
3495
3496 audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/,/ /g')
3497 for drv in $audio_drv_list; do
3498     case $drv in
3499     alsa | try-alsa)
3500     if $pkg_config alsa --exists; then
3501         alsa_libs=$($pkg_config alsa --libs)
3502         alsa_cflags=$($pkg_config alsa --cflags)
3503         alsa=yes
3504         if test "$drv" = "try-alsa"; then
3505             audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-alsa/alsa/')
3506         fi
3507     else
3508         if test "$drv" = "try-alsa"; then
3509             audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-alsa//')
3510         else
3511             error_exit "$drv check failed" \
3512                 "Make sure to have the $drv libs and headers installed."
3513         fi
3514     fi
3515     ;;
3516
3517     pa | try-pa)
3518     if $pkg_config libpulse --exists; then
3519         libpulse=yes
3520         pulse_libs=$($pkg_config libpulse --libs)
3521         pulse_cflags=$($pkg_config libpulse --cflags)
3522         if test "$drv" = "try-pa"; then
3523             audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-pa/pa/')
3524         fi
3525     else
3526         if test "$drv" = "try-pa"; then
3527             audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-pa//')
3528         else
3529             error_exit "$drv check failed" \
3530                 "Make sure to have the $drv libs and headers installed."
3531         fi
3532     fi
3533     ;;
3534
3535     sdl)
3536     if test "$sdl" = "no"; then
3537         error_exit "sdl not found or disabled, can not use sdl audio driver"
3538     fi
3539     ;;
3540
3541     try-sdl)
3542     if test "$sdl" = "no"; then
3543         audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-sdl//')
3544     else
3545         audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-sdl/sdl/')
3546     fi
3547     ;;
3548
3549     coreaudio)
3550       coreaudio_libs="-framework CoreAudio"
3551     ;;
3552
3553     dsound)
3554       dsound_libs="-lole32 -ldxguid"
3555       audio_win_int="yes"
3556     ;;
3557
3558     oss)
3559       oss_libs="$oss_lib"
3560     ;;
3561
3562     jack | try-jack)
3563     if $pkg_config jack --exists; then
3564         libjack=yes
3565         jack_libs=$($pkg_config jack --libs)
3566         if test "$drv" = "try-jack"; then
3567             audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-jack/jack/')
3568         fi
3569     else
3570         if test "$drv" = "try-jack"; then
3571             audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-jack//')
3572         else
3573             error_exit "$drv check failed" \
3574                 "Make sure to have the $drv libs and headers installed."
3575         fi
3576     fi
3577     ;;
3578
3579     *)
3580     echo "$audio_possible_drivers" | grep -q "\<$drv\>" || {
3581         error_exit "Unknown driver '$drv' selected" \
3582             "Possible drivers are: $audio_possible_drivers"
3583     }
3584     ;;
3585     esac
3586 done
3587
3588 ##########################################
3589 # BrlAPI probe
3590
3591 if test "$brlapi" != "no" ; then
3592   brlapi_libs="-lbrlapi"
3593   cat > $TMPC << EOF
3594 #include <brlapi.h>
3595 #include <stddef.h>
3596 int main( void ) { return brlapi__openConnection (NULL, NULL, NULL); }
3597 EOF
3598   if compile_prog "" "$brlapi_libs" ; then
3599     brlapi=yes
3600   else
3601     if test "$brlapi" = "yes" ; then
3602       feature_not_found "brlapi" "Install brlapi devel"
3603     fi
3604     brlapi=no
3605   fi
3606 fi
3607
3608 ##########################################
3609 # iconv probe
3610 if test "$iconv" != "no" ; then
3611   cat > $TMPC << EOF
3612 #include <iconv.h>
3613 int main(void) {
3614   iconv_t conv = iconv_open("WCHAR_T", "UCS-2");
3615   return conv != (iconv_t) -1;
3616 }
3617 EOF
3618   iconv_prefix_list="/usr/local:/usr"
3619   iconv_lib_list=":-liconv"
3620   IFS=:
3621   for iconv_prefix in $iconv_prefix_list; do
3622     IFS=:
3623     iconv_cflags="-I$iconv_prefix/include"
3624     iconv_ldflags="-L$iconv_prefix/lib"
3625     for iconv_link in $iconv_lib_list; do
3626       unset IFS
3627       iconv_lib="$iconv_ldflags $iconv_link"
3628       echo "looking at iconv in '$iconv_cflags' '$iconv_lib'" >> config.log
3629       if compile_prog "$iconv_cflags" "$iconv_lib" ; then
3630         iconv_found=yes
3631         break
3632       fi
3633     done
3634     if test "$iconv_found" = yes ; then
3635       break
3636     fi
3637   done
3638   if test "$iconv_found" = "yes" ; then
3639     iconv=yes
3640   else
3641     if test "$iconv" = "yes" ; then
3642       feature_not_found "iconv" "Install iconv devel"
3643     fi
3644     iconv=no
3645   fi
3646 fi
3647
3648 ##########################################
3649 # curses probe
3650 if test "$iconv" = "no" ; then
3651   # curses will need iconv
3652   curses=no
3653 fi
3654 if test "$curses" != "no" ; then
3655   if test "$mingw32" = "yes" ; then
3656     curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null):"
3657     curses_lib_list="$($pkg_config --libs ncurses 2>/dev/null):-lpdcurses"
3658   else
3659     curses_inc_list="$($pkg_config --cflags ncursesw 2>/dev/null):-I/usr/include/ncursesw:"
3660     curses_lib_list="$($pkg_config --libs ncursesw 2>/dev/null):-lncursesw:-lcursesw"
3661   fi
3662   curses_found=no
3663   cat > $TMPC << EOF
3664 #include <locale.h>
3665 #include <curses.h>
3666 #include <wchar.h>
3667 #include <langinfo.h>
3668 int main(void) {
3669   const char *codeset;
3670   wchar_t wch = L'w';
3671   setlocale(LC_ALL, "");
3672   resize_term(0, 0);
3673   addwstr(L"wide chars\n");
3674   addnwstr(&wch, 1);
3675   add_wch(WACS_DEGREE);
3676   codeset = nl_langinfo(CODESET);
3677   return codeset != 0;
3678 }
3679 EOF
3680   IFS=:
3681   for curses_inc in $curses_inc_list; do
3682     # Make sure we get the wide character prototypes
3683     curses_inc="-DNCURSES_WIDECHAR $curses_inc"
3684     IFS=:
3685     for curses_lib in $curses_lib_list; do
3686       unset IFS
3687       if compile_prog "$curses_inc" "$curses_lib" ; then
3688         curses_found=yes
3689         break
3690       fi
3691     done
3692     if test "$curses_found" = yes ; then
3693       break
3694     fi
3695   done
3696   unset IFS
3697   if test "$curses_found" = "yes" ; then
3698     curses=yes
3699   else
3700     if test "$curses" = "yes" ; then
3701       feature_not_found "curses" "Install ncurses devel"
3702     fi
3703     curses=no
3704   fi
3705 fi
3706
3707 ##########################################
3708 # curl probe
3709 if test "$curl" != "no" ; then
3710   if $pkg_config libcurl --exists; then
3711     curlconfig="$pkg_config libcurl"
3712   else
3713     curlconfig=curl-config
3714   fi
3715   cat > $TMPC << EOF
3716 #include <curl/curl.h>
3717 int main(void) { curl_easy_init(); curl_multi_setopt(0, 0, 0); return 0; }
3718 EOF
3719   curl_cflags=$($curlconfig --cflags 2>/dev/null)
3720   curl_libs=$($curlconfig --libs 2>/dev/null)
3721   if compile_prog "$curl_cflags" "$curl_libs" ; then
3722     curl=yes
3723   else
3724     if test "$curl" = "yes" ; then
3725       feature_not_found "curl" "Install libcurl devel"
3726     fi
3727     curl=no
3728   fi
3729 fi # test "$curl"
3730
3731 ##########################################
3732 # glib support probe
3733
3734 glib_req_ver=2.48
3735 glib_modules=gthread-2.0
3736 if test "$modules" = yes; then
3737     glib_modules="$glib_modules gmodule-export-2.0"
3738 fi
3739 if test "$plugins" = yes; then
3740     glib_modules="$glib_modules gmodule-2.0"
3741 fi
3742
3743 for i in $glib_modules; do
3744     if $pkg_config --atleast-version=$glib_req_ver $i; then
3745         glib_cflags=$($pkg_config --cflags $i)
3746         glib_libs=$($pkg_config --libs $i)
3747     else
3748         error_exit "glib-$glib_req_ver $i is required to compile QEMU"
3749     fi
3750 done
3751
3752 # This workaround is required due to a bug in pkg-config file for glib as it
3753 # doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
3754
3755 if test "$static" = yes && test "$mingw32" = yes; then
3756     glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
3757 fi
3758
3759 if $pkg_config --atleast-version=$glib_req_ver gio-2.0; then
3760     gio=yes
3761     gio_cflags=$($pkg_config --cflags gio-2.0)
3762     gio_libs=$($pkg_config --libs gio-2.0)
3763     gdbus_codegen=$($pkg_config --variable=gdbus_codegen gio-2.0)
3764     if [ ! -x "$gdbus_codegen" ]; then
3765         gdbus_codegen=
3766     fi
3767 else
3768     gio=no
3769 fi
3770
3771 if $pkg_config --atleast-version=$glib_req_ver gio-unix-2.0; then
3772     gio_cflags="$gio_cflags $($pkg_config --cflags gio-unix-2.0)"
3773     gio_libs="$gio_libs $($pkg_config --libs gio-unix-2.0)"
3774 fi
3775
3776 # Sanity check that the current size_t matches the
3777 # size that glib thinks it should be. This catches
3778 # problems on multi-arch where people try to build
3779 # 32-bit QEMU while pointing at 64-bit glib headers
3780 cat > $TMPC <<EOF
3781 #include <glib.h>
3782 #include <unistd.h>
3783
3784 #define QEMU_BUILD_BUG_ON(x) \
3785   typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
3786
3787 int main(void) {
3788    QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
3789    return 0;
3790 }
3791 EOF
3792
3793 if ! compile_prog "$glib_cflags" "$glib_libs" ; then
3794     error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
3795                "You probably need to set PKG_CONFIG_LIBDIR"\
3796                "to point to the right pkg-config files for your"\
3797                "build target"
3798 fi
3799
3800 # Silence clang 3.5.0 warnings about glib attribute __alloc_size__ usage
3801 cat > $TMPC << EOF
3802 #include <glib.h>
3803 int main(void) { return 0; }
3804 EOF
3805 if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
3806     if cc_has_warning_flag "-Wno-unknown-attributes"; then
3807         glib_cflags="-Wno-unknown-attributes $glib_cflags"
3808         CFLAGS="-Wno-unknown-attributes $CFLAGS"
3809     fi
3810 fi
3811
3812 # Silence clang warnings triggered by glib < 2.57.2
3813 cat > $TMPC << EOF
3814 #include <glib.h>
3815 typedef struct Foo {
3816     int i;
3817 } Foo;
3818 static void foo_free(Foo *f)
3819 {
3820     g_free(f);
3821 }
3822 G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free);
3823 int main(void) { return 0; }
3824 EOF
3825 if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
3826     if cc_has_warning_flag "-Wno-unused-function"; then
3827         glib_cflags="$glib_cflags -Wno-unused-function"
3828         CFLAGS="$CFLAGS -Wno-unused-function"
3829     fi
3830 fi
3831
3832 ##########################################
3833 # SHA command probe for modules
3834 if test "$modules" = yes; then
3835     shacmd_probe="sha1sum sha1 shasum"
3836     for c in $shacmd_probe; do
3837         if has $c; then
3838             shacmd="$c"
3839             break
3840         fi
3841     done
3842     if test "$shacmd" = ""; then
3843         error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
3844     fi
3845 fi
3846
3847 ##########################################
3848 # libmpathpersist probe
3849
3850 if test "$mpath" != "no" ; then
3851   # probe for the new API
3852   cat > $TMPC <<EOF
3853 #include <libudev.h>
3854 #include <mpath_persist.h>
3855 unsigned mpath_mx_alloc_len = 1024;
3856 int logsink;
3857 static struct config *multipath_conf;
3858 extern struct udev *udev;
3859 extern struct config *get_multipath_config(void);
3860 extern void put_multipath_config(struct config *conf);
3861 struct udev *udev;
3862 struct config *get_multipath_config(void) { return multipath_conf; }
3863 void put_multipath_config(struct config *conf) { }
3864
3865 int main(void) {
3866     udev = udev_new();
3867     multipath_conf = mpath_lib_init();
3868     return 0;
3869 }
3870 EOF
3871   if compile_prog "" "-ludev -lmultipath -lmpathpersist" ; then
3872     mpathpersist=yes
3873     mpathpersist_new_api=yes
3874   else
3875     # probe for the old API
3876     cat > $TMPC <<EOF
3877 #include <libudev.h>
3878 #include <mpath_persist.h>
3879 unsigned mpath_mx_alloc_len = 1024;
3880 int logsink;
3881 int main(void) {
3882     struct udev *udev = udev_new();
3883     mpath_lib_init(udev);
3884     return 0;
3885 }
3886 EOF
3887     if compile_prog "" "-ludev -lmultipath -lmpathpersist" ; then
3888       mpathpersist=yes
3889       mpathpersist_new_api=no
3890     else
3891       mpathpersist=no
3892     fi
3893   fi
3894 else
3895   mpathpersist=no
3896 fi
3897
3898 ##########################################
3899 # pthread probe
3900 PTHREADLIBS_LIST="-pthread -lpthread -lpthreadGC2"
3901
3902 pthread=no
3903 cat > $TMPC << EOF
3904 #include <pthread.h>
3905 static void *f(void *p) { return NULL; }
3906 int main(void) {
3907   pthread_t thread;
3908   pthread_create(&thread, 0, f, 0);
3909   return 0;
3910 }
3911 EOF
3912 if compile_prog "" "" ; then
3913   pthread=yes
3914 else
3915   for pthread_lib in $PTHREADLIBS_LIST; do
3916     if compile_prog "" "$pthread_lib" ; then
3917       pthread=yes
3918       found=no
3919       for lib_entry in $LIBS; do
3920         if test "$lib_entry" = "$pthread_lib"; then
3921           found=yes
3922           break
3923         fi
3924       done
3925       if test "$found" = "no"; then
3926         LIBS="$pthread_lib $LIBS"
3927       fi
3928       PTHREAD_LIB="$pthread_lib"
3929       break
3930     fi
3931   done
3932 fi
3933
3934 if test "$mingw32" != yes && test "$pthread" = no; then
3935   error_exit "pthread check failed" \
3936       "Make sure to have the pthread libs and headers installed."
3937 fi
3938
3939 # check for pthread_setname_np with thread id
3940 pthread_setname_np_w_tid=no
3941 cat > $TMPC << EOF
3942 #include <pthread.h>
3943
3944 static void *f(void *p) { return NULL; }
3945 int main(void)
3946 {
3947     pthread_t thread;
3948     pthread_create(&thread, 0, f, 0);
3949     pthread_setname_np(thread, "QEMU");
3950     return 0;
3951 }
3952 EOF
3953 if compile_prog "" "$pthread_lib" ; then
3954   pthread_setname_np_w_tid=yes
3955 fi
3956
3957 # check for pthread_setname_np without thread id
3958 pthread_setname_np_wo_tid=no
3959 cat > $TMPC << EOF
3960 #include <pthread.h>
3961
3962 static void *f(void *p) { pthread_setname_np("QEMU"); return NULL; }
3963 int main(void)
3964 {
3965     pthread_t thread;
3966     pthread_create(&thread, 0, f, 0);
3967     return 0;
3968 }
3969 EOF
3970 if compile_prog "" "$pthread_lib" ; then
3971   pthread_setname_np_wo_tid=yes
3972 fi
3973
3974 ##########################################
3975 # rbd probe
3976 if test "$rbd" != "no" ; then
3977   cat > $TMPC <<EOF
3978 #include <stdio.h>
3979 #include <rbd/librbd.h>
3980 int main(void) {
3981     rados_t cluster;
3982     rados_create(&cluster, NULL);
3983     return 0;
3984 }
3985 EOF
3986   rbd_libs="-lrbd -lrados"
3987   if compile_prog "" "$rbd_libs" ; then
3988     rbd=yes
3989   else
3990     if test "$rbd" = "yes" ; then
3991       feature_not_found "rados block device" "Install librbd/ceph devel"
3992     fi
3993     rbd=no
3994   fi
3995 fi
3996
3997 ##########################################
3998 # libssh probe
3999 if test "$libssh" != "no" ; then
4000   if $pkg_config --exists libssh; then
4001     libssh_cflags=$($pkg_config libssh --cflags)
4002     libssh_libs=$($pkg_config libssh --libs)
4003     libssh=yes
4004   else
4005     if test "$libssh" = "yes" ; then
4006       error_exit "libssh required for --enable-libssh"
4007     fi
4008     libssh=no
4009   fi
4010 fi
4011
4012 ##########################################
4013 # Check for libssh 0.8
4014 # This is done like this instead of using the LIBSSH_VERSION_* and
4015 # SSH_VERSION_* macros because some distributions in the past shipped
4016 # snapshots of the future 0.8 from Git, and those snapshots did not
4017 # have updated version numbers (still referring to 0.7.0).
4018
4019 if test "$libssh" = "yes"; then
4020   cat > $TMPC <<EOF
4021 #include <libssh/libssh.h>
4022 int main(void) { return ssh_get_server_publickey(NULL, NULL); }
4023 EOF
4024   if compile_prog "$libssh_cflags" "$libssh_libs"; then
4025     libssh_cflags="-DHAVE_LIBSSH_0_8 $libssh_cflags"
4026   fi
4027 fi
4028
4029 ##########################################
4030 # linux-aio probe
4031
4032 if test "$linux_aio" != "no" ; then
4033   cat > $TMPC <<EOF
4034 #include <libaio.h>
4035 #include <sys/eventfd.h>
4036 #include <stddef.h>
4037 int main(void) { io_setup(0, NULL); io_set_eventfd(NULL, 0); eventfd(0, 0); return 0; }
4038 EOF
4039   if compile_prog "" "-laio" ; then
4040     linux_aio=yes
4041   else
4042     if test "$linux_aio" = "yes" ; then
4043       feature_not_found "linux AIO" "Install libaio devel"
4044     fi
4045     linux_aio=no
4046   fi
4047 fi
4048 ##########################################
4049 # linux-io-uring probe
4050
4051 if test "$linux_io_uring" != "no" ; then
4052   if $pkg_config liburing; then
4053     linux_io_uring_cflags=$($pkg_config --cflags liburing)
4054     linux_io_uring_libs=$($pkg_config --libs liburing)
4055     linux_io_uring=yes
4056   else
4057     if test "$linux_io_uring" = "yes" ; then
4058       feature_not_found "linux io_uring" "Install liburing devel"
4059     fi
4060     linux_io_uring=no
4061   fi
4062 fi
4063
4064 ##########################################
4065 # TPM emulation is only on POSIX
4066
4067 if test "$tpm" = ""; then
4068   if test "$mingw32" = "yes"; then
4069     tpm=no
4070   else
4071     tpm=yes
4072   fi
4073 elif test "$tpm" = "yes"; then
4074   if test "$mingw32" = "yes" ; then
4075     error_exit "TPM emulation only available on POSIX systems"
4076   fi
4077 fi
4078
4079 ##########################################
4080 # attr probe
4081
4082 libattr_libs=
4083 if test "$attr" != "no" ; then
4084   cat > $TMPC <<EOF
4085 #include <stdio.h>
4086 #include <sys/types.h>
4087 #ifdef CONFIG_LIBATTR
4088 #include <attr/xattr.h>
4089 #else
4090 #include <sys/xattr.h>
4091 #endif
4092 int main(void) { getxattr(NULL, NULL, NULL, 0); setxattr(NULL, NULL, NULL, 0, 0); return 0; }
4093 EOF
4094   if compile_prog "" "" ; then
4095     attr=yes
4096   # Older distros have <attr/xattr.h>, and need -lattr:
4097   elif compile_prog "-DCONFIG_LIBATTR" "-lattr" ; then
4098     attr=yes
4099     libattr_libs="-lattr"
4100     libattr=yes
4101   else
4102     if test "$attr" = "yes" ; then
4103       feature_not_found "ATTR" "Install libc6 or libattr devel"
4104     fi
4105     attr=no
4106   fi
4107 fi
4108
4109 ##########################################
4110 # iovec probe
4111 cat > $TMPC <<EOF
4112 #include <sys/types.h>
4113 #include <sys/uio.h>
4114 #include <unistd.h>
4115 int main(void) { return sizeof(struct iovec); }
4116 EOF
4117 iovec=no
4118 if compile_prog "" "" ; then
4119   iovec=yes
4120 fi
4121
4122 ##########################################
4123 # preadv probe
4124 cat > $TMPC <<EOF
4125 #include <sys/types.h>
4126 #include <sys/uio.h>
4127 #include <unistd.h>
4128 int main(void) { return preadv(0, 0, 0, 0); }
4129 EOF
4130 preadv=no
4131 if compile_prog "" "" ; then
4132   preadv=yes
4133 fi
4134
4135 ##########################################
4136 # fdt probe
4137 # fdt support is mandatory for at least some target architectures,
4138 # so insist on it if we're building those system emulators.
4139 fdt_required=no
4140 for target in $target_list; do
4141   case $target in
4142     aarch64*-softmmu|arm*-softmmu|ppc*-softmmu|microblaze*-softmmu|mips64el-softmmu|riscv*-softmmu|rx-softmmu)
4143       fdt_required=yes
4144     ;;
4145   esac
4146 done
4147
4148 if test "$fdt_required" = "yes"; then
4149   if test "$fdt" = "no"; then
4150     error_exit "fdt disabled but some requested targets require it." \
4151       "You can turn off fdt only if you also disable all the system emulation" \
4152       "targets which need it (by specifying a cut down --target-list)."
4153   fi
4154   fdt=yes
4155 elif test "$fdt" != "yes" ; then
4156   fdt=no
4157 fi
4158
4159 # fdt is only required when building softmmu targets
4160 if test -z "$fdt" -a "$softmmu" != "yes" ; then
4161     fdt="no"
4162 fi
4163
4164 if test "$fdt" != "no" ; then
4165   fdt_libs="-lfdt"
4166   # explicitly check for libfdt_env.h as it is missing in some stable installs
4167   # and test for required functions to make sure we are on a version >= 1.4.2
4168   cat > $TMPC << EOF
4169 #include <libfdt.h>
4170 #include <libfdt_env.h>
4171 int main(void) { fdt_check_full(NULL, 0); return 0; }
4172 EOF
4173   if compile_prog "" "$fdt_libs" ; then
4174     # system DTC is good - use it
4175     fdt=system
4176   else
4177       # have GIT checkout, so activate dtc submodule
4178       if test -e "${source_path}/.git" ; then
4179           git_submodules="${git_submodules} dtc"
4180       fi
4181       if test -d "${source_path}/dtc/libfdt" || test -e "${source_path}/.git" ; then
4182           fdt=git
4183           mkdir -p dtc
4184           fdt_cflags="-I${source_path}/dtc/libfdt"
4185           fdt_ldflags="-Ldtc/libfdt"
4186           fdt_libs="$fdt_libs"
4187       elif test "$fdt" = "yes" ; then
4188           # Not a git build & no libfdt found, prompt for system install
4189           error_exit "DTC (libfdt) version >= 1.4.2 not present." \
4190                      "Please install the DTC (libfdt) devel package"
4191       else
4192           # don't have and don't want
4193           fdt_libs=
4194           fdt=no
4195       fi
4196   fi
4197 fi
4198
4199 ##########################################
4200 # opengl probe (for sdl2, gtk, milkymist-tmu2)
4201
4202 gbm="no"
4203 if $pkg_config gbm; then
4204     gbm_cflags="$($pkg_config --cflags gbm)"
4205     gbm_libs="$($pkg_config --libs gbm)"
4206     gbm="yes"
4207 fi
4208
4209 if test "$opengl" != "no" ; then
4210   opengl_pkgs="epoxy gbm"
4211   if $pkg_config $opengl_pkgs; then
4212     opengl_cflags="$($pkg_config --cflags $opengl_pkgs)"
4213     opengl_libs="$($pkg_config --libs $opengl_pkgs)"
4214     opengl=yes
4215     if test "$gtk" = "yes" && $pkg_config --exists "$gtkpackage >= 3.16"; then
4216         gtk_gl="yes"
4217     fi
4218   else
4219     if test "$opengl" = "yes" ; then
4220       feature_not_found "opengl" "Please install opengl (mesa) devel pkgs: $opengl_pkgs"
4221     fi
4222     opengl_cflags=""
4223     opengl_libs=""
4224     opengl=no
4225   fi
4226 fi
4227
4228 if test "$opengl" = "yes"; then
4229   cat > $TMPC << EOF
4230 #include <epoxy/egl.h>
4231 #ifndef EGL_MESA_image_dma_buf_export
4232 # error mesa/epoxy lacks support for dmabufs (mesa 10.6+)
4233 #endif
4234 int main(void) { return 0; }
4235 EOF
4236   if compile_prog "" "" ; then
4237     opengl_dmabuf=yes
4238   fi
4239 fi
4240
4241 if test "$opengl" = "yes" && test "$have_x11" = "yes"; then
4242   for target in $target_list; do
4243     case $target in
4244       lm32-softmmu) # milkymist-tmu2 requires X11 and OpenGL
4245         need_x11=yes
4246       ;;
4247     esac
4248   done
4249 fi
4250
4251 ##########################################
4252 # libxml2 probe
4253 if test "$libxml2" != "no" ; then
4254     if $pkg_config --exists libxml-2.0; then
4255         libxml2="yes"
4256         libxml2_cflags=$($pkg_config --cflags libxml-2.0)
4257         libxml2_libs=$($pkg_config --libs libxml-2.0)
4258     else
4259         if test "$libxml2" = "yes"; then
4260             feature_not_found "libxml2" "Install libxml2 devel"
4261         fi
4262         libxml2="no"
4263     fi
4264 fi
4265
4266 ##########################################
4267 # glusterfs probe
4268 if test "$glusterfs" != "no" ; then
4269   if $pkg_config --atleast-version=3 glusterfs-api; then
4270     glusterfs="yes"
4271     glusterfs_cflags=$($pkg_config --cflags glusterfs-api)
4272     glusterfs_libs=$($pkg_config --libs glusterfs-api)
4273     if $pkg_config --atleast-version=4 glusterfs-api; then
4274       glusterfs_xlator_opt="yes"
4275     fi
4276     if $pkg_config --atleast-version=5 glusterfs-api; then
4277       glusterfs_discard="yes"
4278     fi
4279     if $pkg_config --atleast-version=6 glusterfs-api; then
4280       glusterfs_fallocate="yes"
4281       glusterfs_zerofill="yes"
4282     fi
4283     cat > $TMPC << EOF
4284 #include <glusterfs/api/glfs.h>
4285
4286 int
4287 main(void)
4288 {
4289         /* new glfs_ftruncate() passes two additional args */
4290         return glfs_ftruncate(NULL, 0, NULL, NULL);
4291 }
4292 EOF
4293     if compile_prog "$glusterfs_cflags" "$glusterfs_libs" ; then
4294       glusterfs_ftruncate_has_stat="yes"
4295     fi
4296     cat > $TMPC << EOF
4297 #include <glusterfs/api/glfs.h>
4298
4299 /* new glfs_io_cbk() passes two additional glfs_stat structs */
4300 static void
4301 glusterfs_iocb(glfs_fd_t *fd, ssize_t ret, struct glfs_stat *prestat, struct glfs_stat *poststat, void *data)
4302 {}
4303
4304 int
4305 main(void)
4306 {
4307         glfs_io_cbk iocb = &glusterfs_iocb;
4308         iocb(NULL, 0 , NULL, NULL, NULL);
4309         return 0;
4310 }
4311 EOF
4312     if compile_prog "$glusterfs_cflags" "$glusterfs_libs" ; then
4313       glusterfs_iocb_has_stat="yes"
4314     fi
4315   else
4316     if test "$glusterfs" = "yes" ; then
4317       feature_not_found "GlusterFS backend support" \
4318           "Install glusterfs-api devel >= 3"
4319     fi
4320     glusterfs="no"
4321   fi
4322 fi
4323
4324 # Check for inotify functions when we are building linux-user
4325 # emulator.  This is done because older glibc versions don't
4326 # have syscall stubs for these implemented.  In that case we
4327 # don't provide them even if kernel supports them.
4328 #
4329 inotify=no
4330 cat > $TMPC << EOF
4331 #include <sys/inotify.h>
4332
4333 int
4334 main(void)
4335 {
4336         /* try to start inotify */
4337         return inotify_init();
4338 }
4339 EOF
4340 if compile_prog "" "" ; then
4341   inotify=yes
4342 fi
4343
4344 inotify1=no
4345 cat > $TMPC << EOF
4346 #include <sys/inotify.h>
4347
4348 int
4349 main(void)
4350 {
4351     /* try to start inotify */
4352     return inotify_init1(0);
4353 }
4354 EOF
4355 if compile_prog "" "" ; then
4356   inotify1=yes
4357 fi
4358
4359 # check if pipe2 is there
4360 pipe2=no
4361 cat > $TMPC << EOF
4362 #include <unistd.h>
4363 #include <fcntl.h>
4364
4365 int main(void)
4366 {
4367     int pipefd[2];
4368     return pipe2(pipefd, O_CLOEXEC);
4369 }
4370 EOF
4371 if compile_prog "" "" ; then
4372   pipe2=yes
4373 fi
4374
4375 # check if accept4 is there
4376 accept4=no
4377 cat > $TMPC << EOF
4378 #include <sys/socket.h>
4379 #include <stddef.h>
4380
4381 int main(void)
4382 {
4383     accept4(0, NULL, NULL, SOCK_CLOEXEC);
4384     return 0;
4385 }
4386 EOF
4387 if compile_prog "" "" ; then
4388   accept4=yes
4389 fi
4390
4391 # check if tee/splice is there. vmsplice was added same time.
4392 splice=no
4393 cat > $TMPC << EOF
4394 #include <unistd.h>
4395 #include <fcntl.h>
4396 #include <limits.h>
4397
4398 int main(void)
4399 {
4400     int len, fd = 0;
4401     len = tee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, SPLICE_F_NONBLOCK);
4402     splice(STDIN_FILENO, NULL, fd, NULL, len, SPLICE_F_MOVE);
4403     return 0;
4404 }
4405 EOF
4406 if compile_prog "" "" ; then
4407   splice=yes
4408 fi
4409
4410 ##########################################
4411 # libnuma probe
4412
4413 if test "$numa" != "no" ; then
4414   cat > $TMPC << EOF
4415 #include <numa.h>
4416 int main(void) { return numa_available(); }
4417 EOF
4418
4419   if compile_prog "" "-lnuma" ; then
4420     numa=yes
4421     numa_libs="-lnuma"
4422   else
4423     if test "$numa" = "yes" ; then
4424       feature_not_found "numa" "install numactl devel"
4425     fi
4426     numa=no
4427   fi
4428 fi
4429
4430 if test "$tcmalloc" = "yes" && test "$jemalloc" = "yes" ; then
4431     echo "ERROR: tcmalloc && jemalloc can't be used at the same time"
4432     exit 1
4433 fi
4434
4435 # Even if malloc_trim() is available, these non-libc memory allocators
4436 # do not support it.
4437 if test "$tcmalloc" = "yes" || test "$jemalloc" = "yes" ; then
4438     if test "$malloc_trim" = "yes" ; then
4439         echo "Disabling malloc_trim with non-libc memory allocator"
4440     fi
4441     malloc_trim="no"
4442 fi
4443
4444 #######################################
4445 # malloc_trim
4446
4447 if test "$malloc_trim" != "no" ; then
4448     cat > $TMPC << EOF
4449 #include <malloc.h>
4450 int main(void) { malloc_trim(0); return 0; }
4451 EOF
4452     if compile_prog "" "" ; then
4453         malloc_trim="yes"
4454     else
4455         malloc_trim="no"
4456     fi
4457 fi
4458
4459 ##########################################
4460 # tcmalloc probe
4461
4462 if test "$tcmalloc" = "yes" ; then
4463   cat > $TMPC << EOF
4464 #include <stdlib.h>
4465 int main(void) {
4466     void *tmp = malloc(1);
4467     if (tmp != NULL) {
4468         return 0;
4469     }
4470     return 1;
4471 }
4472 EOF
4473
4474   if compile_prog "" "-ltcmalloc" ; then
4475     LIBS="-ltcmalloc $LIBS"
4476   else
4477     feature_not_found "tcmalloc" "install gperftools devel"
4478   fi
4479 fi
4480
4481 ##########################################
4482 # jemalloc probe
4483
4484 if test "$jemalloc" = "yes" ; then
4485   cat > $TMPC << EOF
4486 #include <stdlib.h>
4487 int main(void) {
4488     void *tmp = malloc(1);
4489     if (tmp != NULL) {
4490         return 0;
4491     }
4492     return 1;
4493 }
4494 EOF
4495
4496   if compile_prog "" "-ljemalloc" ; then
4497     LIBS="-ljemalloc $LIBS"
4498   else
4499     feature_not_found "jemalloc" "install jemalloc devel"
4500   fi
4501 fi
4502
4503 ##########################################
4504 # signalfd probe
4505 signalfd="no"
4506 cat > $TMPC << EOF
4507 #include <unistd.h>
4508 #include <sys/syscall.h>
4509 #include <signal.h>
4510 int main(void) { return syscall(SYS_signalfd, -1, NULL, _NSIG / 8); }
4511 EOF
4512
4513 if compile_prog "" "" ; then
4514   signalfd=yes
4515 fi
4516
4517 # check if optreset global is declared by <getopt.h>
4518 optreset="no"
4519 cat > $TMPC << EOF
4520 #include <getopt.h>
4521 int main(void) { return optreset; }
4522 EOF
4523
4524 if compile_prog "" "" ; then
4525   optreset=yes
4526 fi
4527
4528 # check if eventfd is supported
4529 eventfd=no
4530 cat > $TMPC << EOF
4531 #include <sys/eventfd.h>
4532
4533 int main(void)
4534 {
4535     return eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
4536 }
4537 EOF
4538 if compile_prog "" "" ; then
4539   eventfd=yes
4540 fi
4541
4542 # check if memfd is supported
4543 memfd=no
4544 cat > $TMPC << EOF
4545 #include <sys/mman.h>
4546
4547 int main(void)
4548 {
4549     return memfd_create("foo", MFD_ALLOW_SEALING);
4550 }
4551 EOF
4552 if compile_prog "" "" ; then
4553   memfd=yes
4554 fi
4555
4556 # check for usbfs
4557 have_usbfs=no
4558 if test "$linux_user" = "yes"; then
4559   cat > $TMPC << EOF
4560 #include <linux/usbdevice_fs.h>
4561
4562 #ifndef USBDEVFS_GET_CAPABILITIES
4563 #error "USBDEVFS_GET_CAPABILITIES undefined"
4564 #endif
4565
4566 #ifndef USBDEVFS_DISCONNECT_CLAIM
4567 #error "USBDEVFS_DISCONNECT_CLAIM undefined"
4568 #endif
4569
4570 int main(void)
4571 {
4572     return 0;
4573 }
4574 EOF
4575   if compile_prog "" ""; then
4576     have_usbfs=yes
4577   fi
4578 fi
4579
4580 # check for fallocate
4581 fallocate=no
4582 cat > $TMPC << EOF
4583 #include <fcntl.h>
4584
4585 int main(void)
4586 {
4587     fallocate(0, 0, 0, 0);
4588     return 0;
4589 }
4590 EOF
4591 if compile_prog "" "" ; then
4592   fallocate=yes
4593 fi
4594
4595 # check for fallocate hole punching
4596 fallocate_punch_hole=no
4597 cat > $TMPC << EOF
4598 #include <fcntl.h>
4599 #include <linux/falloc.h>
4600
4601 int main(void)
4602 {
4603     fallocate(0, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 0);
4604     return 0;
4605 }
4606 EOF
4607 if compile_prog "" "" ; then
4608   fallocate_punch_hole=yes
4609 fi
4610
4611 # check that fallocate supports range zeroing inside the file
4612 fallocate_zero_range=no
4613 cat > $TMPC << EOF
4614 #include <fcntl.h>
4615 #include <linux/falloc.h>
4616
4617 int main(void)
4618 {
4619     fallocate(0, FALLOC_FL_ZERO_RANGE, 0, 0);
4620     return 0;
4621 }
4622 EOF
4623 if compile_prog "" "" ; then
4624   fallocate_zero_range=yes
4625 fi
4626
4627 # check for posix_fallocate
4628 posix_fallocate=no
4629 cat > $TMPC << EOF
4630 #include <fcntl.h>
4631
4632 int main(void)
4633 {
4634     posix_fallocate(0, 0, 0);
4635     return 0;
4636 }
4637 EOF
4638 if compile_prog "" "" ; then
4639     posix_fallocate=yes
4640 fi
4641
4642 # check for sync_file_range
4643 sync_file_range=no
4644 cat > $TMPC << EOF
4645 #include <fcntl.h>
4646
4647 int main(void)
4648 {
4649     sync_file_range(0, 0, 0, 0);
4650     return 0;
4651 }
4652 EOF
4653 if compile_prog "" "" ; then
4654   sync_file_range=yes
4655 fi
4656
4657 # check for linux/fiemap.h and FS_IOC_FIEMAP
4658 fiemap=no
4659 cat > $TMPC << EOF
4660 #include <sys/ioctl.h>
4661 #include <linux/fs.h>
4662 #include <linux/fiemap.h>
4663
4664 int main(void)
4665 {
4666     ioctl(0, FS_IOC_FIEMAP, 0);
4667     return 0;
4668 }
4669 EOF
4670 if compile_prog "" "" ; then
4671   fiemap=yes
4672 fi
4673
4674 # check for dup3
4675 dup3=no
4676 cat > $TMPC << EOF
4677 #include <unistd.h>
4678
4679 int main(void)
4680 {
4681     dup3(0, 0, 0);
4682     return 0;
4683 }
4684 EOF
4685 if compile_prog "" "" ; then
4686   dup3=yes
4687 fi
4688
4689 # check for ppoll support
4690 ppoll=no
4691 cat > $TMPC << EOF
4692 #include <poll.h>
4693
4694 int main(void)
4695 {
4696     struct pollfd pfd = { .fd = 0, .events = 0, .revents = 0 };
4697     ppoll(&pfd, 1, 0, 0);
4698     return 0;
4699 }
4700 EOF
4701 if compile_prog "" "" ; then
4702   ppoll=yes
4703 fi
4704
4705 # check for prctl(PR_SET_TIMERSLACK , ... ) support
4706 prctl_pr_set_timerslack=no
4707 cat > $TMPC << EOF
4708 #include <sys/prctl.h>
4709
4710 int main(void)
4711 {
4712     prctl(PR_SET_TIMERSLACK, 1, 0, 0, 0);
4713     return 0;
4714 }
4715 EOF
4716 if compile_prog "" "" ; then
4717   prctl_pr_set_timerslack=yes
4718 fi
4719
4720 # check for epoll support
4721 epoll=no
4722 cat > $TMPC << EOF
4723 #include <sys/epoll.h>
4724
4725 int main(void)
4726 {
4727     epoll_create(0);
4728     return 0;
4729 }
4730 EOF
4731 if compile_prog "" "" ; then
4732   epoll=yes
4733 fi
4734
4735 # epoll_create1 is a later addition
4736 # so we must check separately for its presence
4737 epoll_create1=no
4738 cat > $TMPC << EOF
4739 #include <sys/epoll.h>
4740
4741 int main(void)
4742 {
4743     /* Note that we use epoll_create1 as a value, not as
4744      * a function being called. This is necessary so that on
4745      * old SPARC glibc versions where the function was present in
4746      * the library but not declared in the header file we will
4747      * fail the configure check. (Otherwise we will get a compiler
4748      * warning but not an error, and will proceed to fail the
4749      * qemu compile where we compile with -Werror.)
4750      */
4751     return (int)(uintptr_t)&epoll_create1;
4752 }
4753 EOF
4754 if compile_prog "" "" ; then
4755   epoll_create1=yes
4756 fi
4757
4758 # check for sendfile support
4759 sendfile=no
4760 cat > $TMPC << EOF
4761 #include <sys/sendfile.h>
4762
4763 int main(void)
4764 {
4765     return sendfile(0, 0, 0, 0);
4766 }
4767 EOF
4768 if compile_prog "" "" ; then
4769   sendfile=yes
4770 fi
4771
4772 # check for timerfd support (glibc 2.8 and newer)
4773 timerfd=no
4774 cat > $TMPC << EOF
4775 #include <sys/timerfd.h>
4776
4777 int main(void)
4778 {
4779     return(timerfd_create(CLOCK_REALTIME, 0));
4780 }
4781 EOF
4782 if compile_prog "" "" ; then
4783   timerfd=yes
4784 fi
4785
4786 # check for setns and unshare support
4787 setns=no
4788 cat > $TMPC << EOF
4789 #include <sched.h>
4790
4791 int main(void)
4792 {
4793     int ret;
4794     ret = setns(0, 0);
4795     ret = unshare(0);
4796     return ret;
4797 }
4798 EOF
4799 if compile_prog "" "" ; then
4800   setns=yes
4801 fi
4802
4803 # clock_adjtime probe
4804 clock_adjtime=no
4805 cat > $TMPC <<EOF
4806 #include <time.h>
4807
4808 int main(void)
4809 {
4810     return clock_adjtime(0, 0);
4811 }
4812 EOF
4813 clock_adjtime=no
4814 if compile_prog "" "" ; then
4815   clock_adjtime=yes
4816 fi
4817
4818 # syncfs probe
4819 syncfs=no
4820 cat > $TMPC <<EOF
4821 #include <unistd.h>
4822
4823 int main(void)
4824 {
4825     return syncfs(0);
4826 }
4827 EOF
4828 syncfs=no
4829 if compile_prog "" "" ; then
4830   syncfs=yes
4831 fi
4832
4833 # check for kcov support (kernel must be 4.4+, compiled with certain options)
4834 kcov=no
4835 if check_include sys/kcov.h ; then
4836     kcov=yes
4837 fi
4838
4839 # check for btrfs filesystem support (kernel must be 3.9+)
4840 btrfs=no
4841 if check_include linux/btrfs.h ; then
4842     btrfs=yes
4843 fi
4844
4845 # If we're making warnings fatal, apply this to Sphinx runs as well
4846 sphinx_werror=""
4847 if test "$werror" = "yes"; then
4848     sphinx_werror="-W"
4849 fi
4850
4851 # Check we have a new enough version of sphinx-build
4852 has_sphinx_build() {
4853     # This is a bit awkward but works: create a trivial document and
4854     # try to run it with our configuration file (which enforces a
4855     # version requirement). This will fail if either
4856     # sphinx-build doesn't exist at all or if it is too old.
4857     mkdir -p "$TMPDIR1/sphinx"
4858     touch "$TMPDIR1/sphinx/index.rst"
4859     "$sphinx_build" $sphinx_werror -c "$source_path/docs" \
4860                     -b html "$TMPDIR1/sphinx" \
4861                     "$TMPDIR1/sphinx/out"  >> config.log 2>&1
4862 }
4863
4864 # Check if tools are available to build documentation.
4865 if test "$docs" != "no" ; then
4866   if has_sphinx_build; then
4867     sphinx_ok=yes
4868   else
4869     sphinx_ok=no
4870   fi
4871   if has makeinfo && has pod2man && test "$sphinx_ok" = "yes"; then
4872     docs=yes
4873   else
4874     if test "$docs" = "yes" ; then
4875       if has $sphinx_build && test "$sphinx_ok" != "yes"; then
4876         echo "Warning: $sphinx_build exists but it is either too old or uses too old a Python version" >&2
4877       fi
4878       feature_not_found "docs" "Install texinfo, Perl/perl-podlators and a Python 3 version of python-sphinx"
4879     fi
4880     docs=no
4881   fi
4882 fi
4883
4884 # Search for bswap_32 function
4885 byteswap_h=no
4886 cat > $TMPC << EOF
4887 #include <byteswap.h>
4888 int main(void) { return bswap_32(0); }
4889 EOF
4890 if compile_prog "" "" ; then
4891   byteswap_h=yes
4892 fi
4893
4894 # Search for bswap32 function
4895 bswap_h=no
4896 cat > $TMPC << EOF
4897 #include <sys/endian.h>
4898 #include <sys/types.h>
4899 #include <machine/bswap.h>
4900 int main(void) { return bswap32(0); }
4901 EOF
4902 if compile_prog "" "" ; then
4903   bswap_h=yes
4904 fi
4905
4906 ##########################################
4907 # Do we have libiscsi >= 1.9.0
4908 if test "$libiscsi" != "no" ; then
4909   if $pkg_config --atleast-version=1.9.0 libiscsi; then
4910     libiscsi="yes"
4911     libiscsi_cflags=$($pkg_config --cflags libiscsi)
4912     libiscsi_libs=$($pkg_config --libs libiscsi)
4913   else
4914     if test "$libiscsi" = "yes" ; then
4915       feature_not_found "libiscsi" "Install libiscsi >= 1.9.0"
4916     fi
4917     libiscsi="no"
4918   fi
4919 fi
4920
4921 ##########################################
4922 # Do we need librt
4923 # uClibc provides 2 versions of clock_gettime(), one with realtime
4924 # support and one without. This means that the clock_gettime() don't
4925 # need -lrt. We still need it for timer_create() so we check for this
4926 # function in addition.
4927 cat > $TMPC <<EOF
4928 #include <signal.h>
4929 #include <time.h>
4930 int main(void) {
4931   timer_create(CLOCK_REALTIME, NULL, NULL);
4932   return clock_gettime(CLOCK_REALTIME, NULL);
4933 }
4934 EOF
4935
4936 if compile_prog "" "" ; then
4937   :
4938 # we need pthread for static linking. use previous pthread test result
4939 elif compile_prog "" "$pthread_lib -lrt" ; then
4940   LIBS="$LIBS -lrt"
4941 fi
4942
4943 # Check whether we have openpty() in either libc or libutil
4944 cat > $TMPC << EOF
4945 extern int openpty(int *am, int *as, char *name, void *termp, void *winp);
4946 int main(void) { return openpty(0, 0, 0, 0, 0); }
4947 EOF
4948
4949 have_openpty="no"
4950 if compile_prog "" "" ; then
4951   have_openpty="yes"
4952 else
4953   if compile_prog "" "-lutil" ; then
4954     have_openpty="yes"
4955   fi
4956 fi
4957
4958 ##########################################
4959 # spice probe
4960 if test "$spice" != "no" ; then
4961   cat > $TMPC << EOF
4962 #include <spice.h>
4963 int main(void) { spice_server_new(); return 0; }
4964 EOF
4965   spice_cflags=$($pkg_config --cflags spice-protocol spice-server 2>/dev/null)
4966   spice_libs=$($pkg_config --libs spice-protocol spice-server 2>/dev/null)
4967   if $pkg_config --atleast-version=0.12.5 spice-server && \
4968      $pkg_config --atleast-version=0.12.3 spice-protocol && \
4969      compile_prog "$spice_cflags" "$spice_libs" ; then
4970     spice="yes"
4971   else
4972     if test "$spice" = "yes" ; then
4973       feature_not_found "spice" \
4974           "Install spice-server(>=0.12.5) and spice-protocol(>=0.12.3) devel"
4975     fi
4976     spice="no"
4977   fi
4978 fi
4979
4980 # check for smartcard support
4981 if test "$smartcard" != "no"; then
4982     if $pkg_config --atleast-version=2.5.1 libcacard; then
4983         libcacard_cflags=$($pkg_config --cflags libcacard)
4984         libcacard_libs=$($pkg_config --libs libcacard)
4985         smartcard="yes"
4986     else
4987         if test "$smartcard" = "yes"; then
4988             feature_not_found "smartcard" "Install libcacard devel"
4989         fi
4990         smartcard="no"
4991     fi
4992 fi
4993
4994 # check for libusb
4995 if test "$libusb" != "no" ; then
4996     if $pkg_config --atleast-version=1.0.13 libusb-1.0; then
4997         libusb="yes"
4998         libusb_cflags=$($pkg_config --cflags libusb-1.0)
4999         libusb_libs=$($pkg_config --libs libusb-1.0)
5000     else
5001         if test "$libusb" = "yes"; then
5002             feature_not_found "libusb" "Install libusb devel >= 1.0.13"
5003         fi
5004         libusb="no"
5005     fi
5006 fi
5007
5008 # check for usbredirparser for usb network redirection support
5009 if test "$usb_redir" != "no" ; then
5010     if $pkg_config --atleast-version=0.6 libusbredirparser-0.5; then
5011         usb_redir="yes"
5012         usb_redir_cflags=$($pkg_config --cflags libusbredirparser-0.5)
5013         usb_redir_libs=$($pkg_config --libs libusbredirparser-0.5)
5014     else
5015         if test "$usb_redir" = "yes"; then
5016             feature_not_found "usb-redir" "Install usbredir devel"
5017         fi
5018         usb_redir="no"
5019     fi
5020 fi
5021
5022 ##########################################
5023 # check if we have VSS SDK headers for win
5024
5025 if test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
5026         test "$vss_win32_sdk" != "no" ; then
5027   case "$vss_win32_sdk" in
5028     "")   vss_win32_include="-isystem $source_path" ;;
5029     *\ *) # The SDK is installed in "Program Files" by default, but we cannot
5030           # handle path with spaces. So we symlink the headers into ".sdk/vss".
5031           vss_win32_include="-isystem $source_path/.sdk/vss"
5032           symlink "$vss_win32_sdk/inc" "$source_path/.sdk/vss/inc"
5033           ;;
5034     *)    vss_win32_include="-isystem $vss_win32_sdk"
5035   esac
5036   cat > $TMPC << EOF
5037 #define __MIDL_user_allocate_free_DEFINED__
5038 #include <inc/win2003/vss.h>
5039 int main(void) { return VSS_CTX_BACKUP; }
5040 EOF
5041   if compile_prog "$vss_win32_include" "" ; then
5042     guest_agent_with_vss="yes"
5043     QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
5044     libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++ -Wl,--enable-stdcall-fixup $libs_qga"
5045     qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb"
5046   else
5047     if test "$vss_win32_sdk" != "" ; then
5048       echo "ERROR: Please download and install Microsoft VSS SDK:"
5049       echo "ERROR:   http://www.microsoft.com/en-us/download/details.aspx?id=23490"
5050       echo "ERROR: On POSIX-systems, you can extract the SDK headers by:"
5051       echo "ERROR:   scripts/extract-vsssdk-headers setup.exe"
5052       echo "ERROR: The headers are extracted in the directory \`inc'."
5053       feature_not_found "VSS support"
5054     fi
5055     guest_agent_with_vss="no"
5056   fi
5057 fi
5058
5059 ##########################################
5060 # lookup Windows platform SDK (if not specified)
5061 # The SDK is needed only to build .tlb (type library) file of guest agent
5062 # VSS provider from the source. It is usually unnecessary because the
5063 # pre-compiled .tlb file is included.
5064
5065 if test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
5066         test "$guest_agent_with_vss" = "yes" ; then
5067   if test -z "$win_sdk"; then
5068     programfiles="$PROGRAMFILES"
5069     test -n "$PROGRAMW6432" && programfiles="$PROGRAMW6432"
5070     if test -n "$programfiles"; then
5071       win_sdk=$(ls -d "$programfiles/Microsoft SDKs/Windows/v"* | tail -1) 2>/dev/null
5072     else
5073       feature_not_found "Windows SDK"
5074     fi
5075   elif test "$win_sdk" = "no"; then
5076     win_sdk=""
5077   fi
5078 fi
5079
5080 ##########################################
5081 # check if mingw environment provides a recent ntddscsi.h
5082 if test "$mingw32" = "yes" && test "$guest_agent" != "no"; then
5083   cat > $TMPC << EOF
5084 #include <windows.h>
5085 #include <ntddscsi.h>
5086 int main(void) {
5087 #if !defined(IOCTL_SCSI_GET_ADDRESS)
5088 #error Missing required ioctl definitions
5089 #endif
5090   SCSI_ADDRESS addr = { .Lun = 0, .TargetId = 0, .PathId = 0 };
5091   return addr.Lun;
5092 }
5093 EOF
5094   if compile_prog "" "" ; then
5095     guest_agent_ntddscsi=yes
5096     libs_qga="-lsetupapi -lcfgmgr32 $libs_qga"
5097   fi
5098 fi
5099
5100 ##########################################
5101 # virgl renderer probe
5102
5103 if test "$virglrenderer" != "no" ; then
5104   cat > $TMPC << EOF
5105 #include <virglrenderer.h>
5106 int main(void) { virgl_renderer_poll(); return 0; }
5107 EOF
5108   virgl_cflags=$($pkg_config --cflags virglrenderer 2>/dev/null)
5109   virgl_libs=$($pkg_config --libs virglrenderer 2>/dev/null)
5110   virgl_version=$($pkg_config --modversion virglrenderer 2>/dev/null)
5111   if $pkg_config virglrenderer >/dev/null 2>&1 && \
5112      compile_prog "$virgl_cflags" "$virgl_libs" ; then
5113     virglrenderer="yes"
5114   else
5115     if test "$virglrenderer" = "yes" ; then
5116       feature_not_found "virglrenderer"
5117     fi
5118     virglrenderer="no"
5119   fi
5120 fi
5121
5122 ##########################################
5123 # capstone
5124
5125 case "$capstone" in
5126   "" | yes)
5127     if $pkg_config capstone; then
5128       capstone=system
5129     elif test -e "${source_path}/.git" && test $git_update = 'yes' ; then
5130       capstone=git
5131     elif test -e "${source_path}/capstone/Makefile" ; then
5132       capstone=internal
5133     elif test -z "$capstone" ; then
5134       capstone=no
5135     else
5136       feature_not_found "capstone" "Install capstone devel or git submodule"
5137     fi
5138     ;;
5139
5140   system)
5141     if ! $pkg_config capstone; then
5142       feature_not_found "capstone" "Install capstone devel"
5143     fi
5144     ;;
5145 esac
5146
5147 case "$capstone" in
5148   git | internal)
5149     if test "$capstone" = git; then
5150       git_submodules="${git_submodules} capstone"
5151     fi
5152     mkdir -p capstone
5153     if test "$mingw32" = "yes"; then
5154       LIBCAPSTONE=capstone.lib
5155     else
5156       LIBCAPSTONE=libcapstone.a
5157     fi
5158     capstone_libs="-Lcapstone -lcapstone"
5159     capstone_cflags="-I${source_path}/capstone/include"
5160     ;;
5161
5162   system)
5163     capstone_libs="$($pkg_config --libs capstone)"
5164     capstone_cflags="$($pkg_config --cflags capstone)"
5165     ;;
5166
5167   no)
5168     ;;
5169   *)
5170     error_exit "Unknown state for capstone: $capstone"
5171     ;;
5172 esac
5173
5174 ##########################################
5175 # check if we have fdatasync
5176
5177 fdatasync=no
5178 cat > $TMPC << EOF
5179 #include <unistd.h>
5180 int main(void) {
5181 #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
5182 return fdatasync(0);
5183 #else
5184 #error Not supported
5185 #endif
5186 }
5187 EOF
5188 if compile_prog "" "" ; then
5189     fdatasync=yes
5190 fi
5191
5192 ##########################################
5193 # check if we have madvise
5194
5195 madvise=no
5196 cat > $TMPC << EOF
5197 #include <sys/types.h>
5198 #include <sys/mman.h>
5199 #include <stddef.h>
5200 int main(void) { return madvise(NULL, 0, MADV_DONTNEED); }
5201 EOF
5202 if compile_prog "" "" ; then
5203     madvise=yes
5204 fi
5205
5206 ##########################################
5207 # check if we have posix_madvise
5208
5209 posix_madvise=no
5210 cat > $TMPC << EOF
5211 #include <sys/mman.h>
5212 #include <stddef.h>
5213 int main(void) { return posix_madvise(NULL, 0, POSIX_MADV_DONTNEED); }
5214 EOF
5215 if compile_prog "" "" ; then
5216     posix_madvise=yes
5217 fi
5218
5219 ##########################################
5220 # check if we have posix_memalign()
5221
5222 posix_memalign=no
5223 cat > $TMPC << EOF
5224 #include <stdlib.h>
5225 int main(void) {
5226     void *p;
5227     return posix_memalign(&p, 8, 8);
5228 }
5229 EOF
5230 if compile_prog "" "" ; then
5231     posix_memalign=yes
5232 fi
5233
5234 ##########################################
5235 # check if we have posix_syslog
5236
5237 posix_syslog=no
5238 cat > $TMPC << EOF
5239 #include <syslog.h>
5240 int main(void) { openlog("qemu", LOG_PID, LOG_DAEMON); syslog(LOG_INFO, "configure"); return 0; }
5241 EOF
5242 if compile_prog "" "" ; then
5243     posix_syslog=yes
5244 fi
5245
5246 ##########################################
5247 # check if we have sem_timedwait
5248
5249 sem_timedwait=no
5250 cat > $TMPC << EOF
5251 #include <semaphore.h>
5252 int main(void) { sem_t s; struct timespec t = {0}; return sem_timedwait(&s, &t); }
5253 EOF
5254 if compile_prog "" "" ; then
5255     sem_timedwait=yes
5256 fi
5257
5258 ##########################################
5259 # check if we have strchrnul
5260
5261 strchrnul=no
5262 cat > $TMPC << EOF
5263 #include <string.h>
5264 int main(void);
5265 // Use a haystack that the compiler shouldn't be able to constant fold
5266 char *haystack = (char*)&main;
5267 int main(void) { return strchrnul(haystack, 'x') != &haystack[6]; }
5268 EOF
5269 if compile_prog "" "" ; then
5270     strchrnul=yes
5271 fi
5272
5273 #########################################
5274 # check if we have st_atim
5275
5276 st_atim=no
5277 cat > $TMPC << EOF
5278 #include <sys/stat.h>
5279 #include <stddef.h>
5280 int main(void) { return offsetof(struct stat, st_atim); }
5281 EOF
5282 if compile_prog "" "" ; then
5283     st_atim=yes
5284 fi
5285
5286 ##########################################
5287 # check if trace backend exists
5288
5289 $python "$source_path/scripts/tracetool.py" "--backends=$trace_backends" --check-backends  > /dev/null 2> /dev/null
5290 if test "$?" -ne 0 ; then
5291   error_exit "invalid trace backends" \
5292       "Please choose supported trace backends."
5293 fi
5294
5295 ##########################################
5296 # For 'ust' backend, test if ust headers are present
5297 if have_backend "ust"; then
5298   cat > $TMPC << EOF
5299 #include <lttng/tracepoint.h>
5300 int main(void) { return 0; }
5301 EOF
5302   if compile_prog "" "-Wl,--no-as-needed -ldl" ; then
5303     if $pkg_config lttng-ust --exists; then
5304       lttng_ust_libs=$($pkg_config --libs lttng-ust)
5305     else
5306       lttng_ust_libs="-llttng-ust -ldl"
5307     fi
5308     if $pkg_config liburcu-bp --exists; then
5309       urcu_bp_libs=$($pkg_config --libs liburcu-bp)
5310     else
5311       urcu_bp_libs="-lurcu-bp"
5312     fi
5313   else
5314     error_exit "Trace backend 'ust' missing lttng-ust header files"
5315   fi
5316 fi
5317
5318 ##########################################
5319 # For 'dtrace' backend, test if 'dtrace' command is present
5320 if have_backend "dtrace"; then
5321   if ! has 'dtrace' ; then
5322     error_exit "dtrace command is not found in PATH $PATH"
5323   fi
5324   trace_backend_stap="no"
5325   if has 'stap' ; then
5326     trace_backend_stap="yes"
5327   fi
5328 fi
5329
5330 ##########################################
5331 # check and set a backend for coroutine
5332
5333 # We prefer ucontext, but it's not always possible. The fallback
5334 # is sigcontext. On Windows the only valid backend is the Windows
5335 # specific one.
5336
5337 ucontext_works=no
5338 if test "$darwin" != "yes"; then
5339   cat > $TMPC << EOF
5340 #include <ucontext.h>
5341 #ifdef __stub_makecontext
5342 #error Ignoring glibc stub makecontext which will always fail
5343 #endif
5344 int main(void) { makecontext(0, 0, 0); return 0; }
5345 EOF
5346   if compile_prog "" "" ; then
5347     ucontext_works=yes
5348   fi
5349 fi
5350
5351 if test "$coroutine" = ""; then
5352   if test "$mingw32" = "yes"; then
5353     coroutine=win32
5354   elif test "$ucontext_works" = "yes"; then
5355     coroutine=ucontext
5356   else
5357     coroutine=sigaltstack
5358   fi
5359 else
5360   case $coroutine in
5361   windows)
5362     if test "$mingw32" != "yes"; then
5363       error_exit "'windows' coroutine backend only valid for Windows"
5364     fi
5365     # Unfortunately the user visible backend name doesn't match the
5366     # coroutine-*.c filename for this case, so we have to adjust it here.
5367     coroutine=win32
5368     ;;
5369   ucontext)
5370     if test "$ucontext_works" != "yes"; then
5371       feature_not_found "ucontext"
5372     fi
5373     ;;
5374   sigaltstack)
5375     if test "$mingw32" = "yes"; then
5376       error_exit "only the 'windows' coroutine backend is valid for Windows"
5377     fi
5378     ;;
5379   *)
5380     error_exit "unknown coroutine backend $coroutine"
5381     ;;
5382   esac
5383 fi
5384
5385 if test "$coroutine_pool" = ""; then
5386   coroutine_pool=yes
5387 fi
5388
5389 if test "$debug_stack_usage" = "yes"; then
5390   if test "$coroutine_pool" = "yes"; then
5391     echo "WARN: disabling coroutine pool for stack usage debugging"
5392     coroutine_pool=no
5393   fi
5394 fi
5395
5396 ##################################################
5397 # SafeStack
5398
5399
5400 if test "$safe_stack" = "yes"; then
5401 cat > $TMPC << EOF
5402 int main(int argc, char *argv[])
5403 {
5404 #if ! __has_feature(safe_stack)
5405 #error SafeStack Disabled
5406 #endif
5407     return 0;
5408 }
5409 EOF
5410   flag="-fsanitize=safe-stack"
5411   # Check that safe-stack is supported and enabled.
5412   if compile_prog "-Werror $flag" "$flag"; then
5413     # Flag needed both at compilation and at linking
5414     QEMU_CFLAGS="$QEMU_CFLAGS $flag"
5415     QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
5416   else
5417     error_exit "SafeStack not supported by your compiler"
5418   fi
5419   if test "$coroutine" != "ucontext"; then
5420     error_exit "SafeStack is only supported by the coroutine backend ucontext"
5421   fi
5422 else
5423 cat > $TMPC << EOF
5424 int main(int argc, char *argv[])
5425 {
5426 #if defined(__has_feature)
5427 #if __has_feature(safe_stack)
5428 #error SafeStack Enabled
5429 #endif
5430 #endif
5431     return 0;
5432 }
5433 EOF
5434 if test "$safe_stack" = "no"; then
5435   # Make sure that safe-stack is disabled
5436   if ! compile_prog "-Werror" ""; then
5437     # SafeStack was already enabled, try to explicitly remove the feature
5438     flag="-fno-sanitize=safe-stack"
5439     if ! compile_prog "-Werror $flag" "$flag"; then
5440       error_exit "Configure cannot disable SafeStack"
5441     fi
5442     QEMU_CFLAGS="$QEMU_CFLAGS $flag"
5443     QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
5444   fi
5445 else # "$safe_stack" = ""
5446   # Set safe_stack to yes or no based on pre-existing flags
5447   if compile_prog "-Werror" ""; then
5448     safe_stack="no"
5449   else
5450     safe_stack="yes"
5451     if test "$coroutine" != "ucontext"; then
5452       error_exit "SafeStack is only supported by the coroutine backend ucontext"
5453     fi
5454   fi
5455 fi
5456 fi
5457
5458 ##########################################
5459 # check if we have open_by_handle_at
5460
5461 open_by_handle_at=no
5462 cat > $TMPC << EOF
5463 #include <fcntl.h>
5464 #if !defined(AT_EMPTY_PATH)
5465 # error missing definition
5466 #else
5467 int main(void) { struct file_handle fh; return open_by_handle_at(0, &fh, 0); }
5468 #endif
5469 EOF
5470 if compile_prog "" "" ; then
5471     open_by_handle_at=yes
5472 fi
5473
5474 ########################################
5475 # check if we have linux/magic.h
5476
5477 linux_magic_h=no
5478 cat > $TMPC << EOF
5479 #include <linux/magic.h>
5480 int main(void) {
5481   return 0;
5482 }
5483 EOF
5484 if compile_prog "" "" ; then
5485     linux_magic_h=yes
5486 fi
5487
5488 ########################################
5489 # check if we have valgrind/valgrind.h
5490
5491 valgrind_h=no
5492 cat > $TMPC << EOF
5493 #include <valgrind/valgrind.h>
5494 int main(void) {
5495   return 0;
5496 }
5497 EOF
5498 if compile_prog "" "" ; then
5499     valgrind_h=yes
5500 fi
5501
5502 ########################################
5503 # check if environ is declared
5504
5505 has_environ=no
5506 cat > $TMPC << EOF
5507 #include <unistd.h>
5508 int main(void) {
5509     environ = 0;
5510     return 0;
5511 }
5512 EOF
5513 if compile_prog "" "" ; then
5514     has_environ=yes
5515 fi
5516
5517 ########################################
5518 # check if cpuid.h is usable.
5519
5520 cat > $TMPC << EOF
5521 #include <cpuid.h>
5522 int main(void) {
5523     unsigned a, b, c, d;
5524     int max = __get_cpuid_max(0, 0);
5525
5526     if (max >= 1) {
5527         __cpuid(1, a, b, c, d);
5528     }
5529
5530     if (max >= 7) {
5531         __cpuid_count(7, 0, a, b, c, d);
5532     }
5533
5534     return 0;
5535 }
5536 EOF
5537 if compile_prog "" "" ; then
5538     cpuid_h=yes
5539 fi
5540
5541 ##########################################
5542 # avx2 optimization requirement check
5543 #
5544 # There is no point enabling this if cpuid.h is not usable,
5545 # since we won't be able to select the new routines.
5546
5547 if test "$cpuid_h" = "yes" && test "$avx2_opt" != "no"; then
5548   cat > $TMPC << EOF
5549 #pragma GCC push_options
5550 #pragma GCC target("avx2")
5551 #include <cpuid.h>
5552 #include <immintrin.h>
5553 static int bar(void *a) {
5554     __m256i x = *(__m256i *)a;
5555     return _mm256_testz_si256(x, x);
5556 }
5557 int main(int argc, char *argv[]) { return bar(argv[0]); }
5558 EOF
5559   if compile_object "" ; then
5560     avx2_opt="yes"
5561   else
5562     avx2_opt="no"
5563   fi
5564 fi
5565
5566 ##########################################
5567 # avx512f optimization requirement check
5568 #
5569 # There is no point enabling this if cpuid.h is not usable,
5570 # since we won't be able to select the new routines.
5571 # by default, it is turned off.
5572 # if user explicitly want to enable it, check environment
5573
5574 if test "$cpuid_h" = "yes" && test "$avx512f_opt" = "yes"; then
5575   cat > $TMPC << EOF
5576 #pragma GCC push_options
5577 #pragma GCC target("avx512f")
5578 #include <cpuid.h>
5579 #include <immintrin.h>
5580 static int bar(void *a) {
5581     __m512i x = *(__m512i *)a;
5582     return _mm512_test_epi64_mask(x, x);
5583 }
5584 int main(int argc, char *argv[])
5585 {
5586         return bar(argv[0]);
5587 }
5588 EOF
5589   if ! compile_object "" ; then
5590     avx512f_opt="no"
5591   fi
5592 else
5593   avx512f_opt="no"
5594 fi
5595
5596 ########################################
5597 # check if __[u]int128_t is usable.
5598
5599 int128=no
5600 cat > $TMPC << EOF
5601 __int128_t a;
5602 __uint128_t b;
5603 int main (void) {
5604   a = a + b;
5605   b = a * b;
5606   a = a * a;
5607   return 0;
5608 }
5609 EOF
5610 if compile_prog "" "" ; then
5611     int128=yes
5612 fi
5613
5614 #########################################
5615 # See if 128-bit atomic operations are supported.
5616
5617 atomic128=no
5618 if test "$int128" = "yes"; then
5619   cat > $TMPC << EOF
5620 int main(void)
5621 {
5622   unsigned __int128 x = 0, y = 0;
5623   y = __atomic_load_16(&x, 0);
5624   __atomic_store_16(&x, y, 0);
5625   __atomic_compare_exchange_16(&x, &y, x, 0, 0, 0);
5626   return 0;
5627 }
5628 EOF
5629   if compile_prog "" "" ; then
5630     atomic128=yes
5631   fi
5632 fi
5633
5634 cmpxchg128=no
5635 if test "$int128" = yes && test "$atomic128" = no; then
5636   cat > $TMPC << EOF
5637 int main(void)
5638 {
5639   unsigned __int128 x = 0, y = 0;
5640   __sync_val_compare_and_swap_16(&x, y, x);
5641   return 0;
5642 }
5643 EOF
5644   if compile_prog "" "" ; then
5645     cmpxchg128=yes
5646   fi
5647 fi
5648
5649 #########################################
5650 # See if 64-bit atomic operations are supported.
5651 # Note that without __atomic builtins, we can only
5652 # assume atomic loads/stores max at pointer size.
5653
5654 cat > $TMPC << EOF
5655 #include <stdint.h>
5656 int main(void)
5657 {
5658   uint64_t x = 0, y = 0;
5659 #ifdef __ATOMIC_RELAXED
5660   y = __atomic_load_n(&x, __ATOMIC_RELAXED);
5661   __atomic_store_n(&x, y, __ATOMIC_RELAXED);
5662   __atomic_compare_exchange_n(&x, &y, x, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
5663   __atomic_exchange_n(&x, y, __ATOMIC_RELAXED);
5664   __atomic_fetch_add(&x, y, __ATOMIC_RELAXED);
5665 #else
5666   typedef char is_host64[sizeof(void *) >= sizeof(uint64_t) ? 1 : -1];
5667   __sync_lock_test_and_set(&x, y);
5668   __sync_val_compare_and_swap(&x, y, 0);
5669   __sync_fetch_and_add(&x, y);
5670 #endif
5671   return 0;
5672 }
5673 EOF
5674 if compile_prog "" "" ; then
5675   atomic64=yes
5676 fi
5677
5678 #########################################
5679 # See if --dynamic-list is supported by the linker
5680 ld_dynamic_list="no"
5681 if test "$static" = "no" ; then
5682     cat > $TMPTXT <<EOF
5683 {
5684   foo;
5685 };
5686 EOF
5687
5688     cat > $TMPC <<EOF
5689 #include <stdio.h>
5690 void foo(void);
5691
5692 void foo(void)
5693 {
5694   printf("foo\n");
5695 }
5696
5697 int main(void)
5698 {
5699   foo();
5700   return 0;
5701 }
5702 EOF
5703
5704     if compile_prog "" "-Wl,--dynamic-list=$TMPTXT" ; then
5705         ld_dynamic_list="yes"
5706     fi
5707 fi
5708
5709 #########################################
5710 # See if -exported_symbols_list is supported by the linker
5711
5712 ld_exported_symbols_list="no"
5713 if test "$static" = "no" ; then
5714     cat > $TMPTXT <<EOF
5715   _foo
5716 EOF
5717
5718     if compile_prog "" "-Wl,-exported_symbols_list,$TMPTXT" ; then
5719         ld_exported_symbols_list="yes"
5720     fi
5721 fi
5722
5723 if  test "$plugins" = "yes" &&
5724     test "$ld_dynamic_list" = "no" &&
5725     test "$ld_exported_symbols_list" = "no" ; then
5726   error_exit \
5727       "Plugin support requires dynamic linking and specifying a set of symbols " \
5728       "that are exported to plugins. Unfortunately your linker doesn't " \
5729       "support the flag (--dynamic-list or -exported_symbols_list) used " \
5730       "for this purpose. You can't build with --static."
5731 fi
5732
5733 ########################################
5734 # See if __attribute__((alias)) is supported.
5735 # This false for Xcode 9, but has been remedied for Xcode 10.
5736 # Unfortunately, travis uses Xcode 9 by default.
5737
5738 attralias=no
5739 cat > $TMPC << EOF
5740 int x = 1;
5741 extern const int y __attribute__((alias("x")));
5742 int main(void) { return 0; }
5743 EOF
5744 if compile_prog "" "" ; then
5745     attralias=yes
5746 fi
5747
5748 ########################################
5749 # check if getauxval is available.
5750
5751 getauxval=no
5752 cat > $TMPC << EOF
5753 #include <sys/auxv.h>
5754 int main(void) {
5755   return getauxval(AT_HWCAP) == 0;
5756 }
5757 EOF
5758 if compile_prog "" "" ; then
5759     getauxval=yes
5760 fi
5761
5762 ########################################
5763 # check if ccache is interfering with
5764 # semantic analysis of macros
5765
5766 unset CCACHE_CPP2
5767 ccache_cpp2=no
5768 cat > $TMPC << EOF
5769 static const int Z = 1;
5770 #define fn() ({ Z; })
5771 #define TAUT(X) ((X) == Z)
5772 #define PAREN(X, Y) (X == Y)
5773 #define ID(X) (X)
5774 int main(int argc, char *argv[])
5775 {
5776     int x = 0, y = 0;
5777     x = ID(x);
5778     x = fn();
5779     fn();
5780     if (PAREN(x, y)) return 0;
5781     if (TAUT(Z)) return 0;
5782     return 0;
5783 }
5784 EOF
5785
5786 if ! compile_object "-Werror"; then
5787     ccache_cpp2=yes
5788 fi
5789
5790 #################################################
5791 # clang does not support glibc + FORTIFY_SOURCE.
5792
5793 if test "$fortify_source" != "no"; then
5794   if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
5795     fortify_source="no";
5796   elif test -n "$cxx" && has $cxx &&
5797        echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
5798     fortify_source="no";
5799   else
5800     fortify_source="yes"
5801   fi
5802 fi
5803
5804 ###############################################
5805 # Check if copy_file_range is provided by glibc
5806 have_copy_file_range=no
5807 cat > $TMPC << EOF
5808 #include <unistd.h>
5809 int main(void) {
5810   copy_file_range(0, NULL, 0, NULL, 0, 0);
5811   return 0;
5812 }
5813 EOF
5814 if compile_prog "" "" ; then
5815     have_copy_file_range=yes
5816 fi
5817
5818 ##########################################
5819 # check if struct fsxattr is available via linux/fs.h
5820
5821 have_fsxattr=no
5822 cat > $TMPC << EOF
5823 #include <linux/fs.h>
5824 struct fsxattr foo;
5825 int main(void) {
5826   return 0;
5827 }
5828 EOF
5829 if compile_prog "" "" ; then
5830     have_fsxattr=yes
5831 fi
5832
5833 ##########################################
5834 # check for usable membarrier system call
5835 if test "$membarrier" = "yes"; then
5836     have_membarrier=no
5837     if test "$mingw32" = "yes" ; then
5838         have_membarrier=yes
5839     elif test "$linux" = "yes" ; then
5840         cat > $TMPC << EOF
5841     #include <linux/membarrier.h>
5842     #include <sys/syscall.h>
5843     #include <unistd.h>
5844     #include <stdlib.h>
5845     int main(void) {
5846         syscall(__NR_membarrier, MEMBARRIER_CMD_QUERY, 0);
5847         syscall(__NR_membarrier, MEMBARRIER_CMD_SHARED, 0);
5848         exit(0);
5849     }
5850 EOF
5851         if compile_prog "" "" ; then
5852             have_membarrier=yes
5853         fi
5854     fi
5855     if test "$have_membarrier" = "no"; then
5856       feature_not_found "membarrier" "membarrier system call not available"
5857     fi
5858 else
5859     # Do not enable it by default even for Mingw32, because it doesn't
5860     # work on Wine.
5861     membarrier=no
5862 fi
5863
5864 ##########################################
5865 # check if rtnetlink.h exists and is useful
5866 have_rtnetlink=no
5867 cat > $TMPC << EOF
5868 #include <linux/rtnetlink.h>
5869 int main(void) {
5870   return IFLA_PROTO_DOWN;
5871 }
5872 EOF
5873 if compile_prog "" "" ; then
5874     have_rtnetlink=yes
5875 fi
5876
5877 ##########################################
5878 # check for usable AF_VSOCK environment
5879 have_af_vsock=no
5880 cat > $TMPC << EOF
5881 #include <errno.h>
5882 #include <sys/types.h>
5883 #include <sys/socket.h>
5884 #if !defined(AF_VSOCK)
5885 # error missing AF_VSOCK flag
5886 #endif
5887 #include <linux/vm_sockets.h>
5888 int main(void) {
5889     int sock, ret;
5890     struct sockaddr_vm svm;
5891     socklen_t len = sizeof(svm);
5892     sock = socket(AF_VSOCK, SOCK_STREAM, 0);
5893     ret = getpeername(sock, (struct sockaddr *)&svm, &len);
5894     if ((ret == -1) && (errno == ENOTCONN)) {
5895         return 0;
5896     }
5897     return -1;
5898 }
5899 EOF
5900 if compile_prog "" "" ; then
5901     have_af_vsock=yes
5902 fi
5903
5904 ##########################################
5905 # check for usable AF_ALG environment
5906 have_afalg=no
5907 cat > $TMPC << EOF
5908 #include <errno.h>
5909 #include <sys/types.h>
5910 #include <sys/socket.h>
5911 #include <linux/if_alg.h>
5912 int main(void) {
5913     int sock;
5914     sock = socket(AF_ALG, SOCK_SEQPACKET, 0);
5915     return sock;
5916 }
5917 EOF
5918 if compile_prog "" "" ; then
5919     have_afalg=yes
5920 fi
5921 if test "$crypto_afalg" = "yes"
5922 then
5923     if test "$have_afalg" != "yes"
5924     then
5925         error_exit "AF_ALG requested but could not be detected"
5926     fi
5927 fi
5928
5929
5930 #################################################
5931 # Check to see if we have the Hypervisor framework
5932 if [ "$darwin" = "yes" ] ; then
5933   cat > $TMPC << EOF
5934 #include <Hypervisor/hv.h>
5935 int main() { return 0;}
5936 EOF
5937   if ! compile_object ""; then
5938     hvf='no'
5939   else
5940     hvf='yes'
5941     QEMU_LDFLAGS="-framework Hypervisor $QEMU_LDFLAGS"
5942   fi
5943 fi
5944
5945 ##########################################
5946 # check for sysmacros.h
5947
5948 have_sysmacros=no
5949 cat > $TMPC << EOF
5950 #include <sys/sysmacros.h>
5951 int main(void) {
5952     return makedev(0, 0);
5953 }
5954 EOF
5955 if compile_prog "" "" ; then
5956     have_sysmacros=yes
5957 fi
5958
5959 ##########################################
5960 # check for _Static_assert()
5961
5962 have_static_assert=no
5963 cat > $TMPC << EOF
5964 _Static_assert(1, "success");
5965 int main(void) {
5966     return 0;
5967 }
5968 EOF
5969 if compile_prog "" "" ; then
5970     have_static_assert=yes
5971 fi
5972
5973 ##########################################
5974 # check for utmpx.h, it is missing e.g. on OpenBSD
5975
5976 have_utmpx=no
5977 cat > $TMPC << EOF
5978 #include <utmpx.h>
5979 struct utmpx user_info;
5980 int main(void) {
5981     return 0;
5982 }
5983 EOF
5984 if compile_prog "" "" ; then
5985     have_utmpx=yes
5986 fi
5987
5988 ##########################################
5989 # check for getrandom()
5990
5991 have_getrandom=no
5992 cat > $TMPC << EOF
5993 #include <sys/random.h>
5994 int main(void) {
5995     return getrandom(0, 0, GRND_NONBLOCK);
5996 }
5997 EOF
5998 if compile_prog "" "" ; then
5999     have_getrandom=yes
6000 fi
6001
6002 ##########################################
6003 # checks for sanitizers
6004
6005 have_asan=no
6006 have_ubsan=no
6007 have_asan_iface_h=no
6008 have_asan_iface_fiber=no
6009
6010 if test "$sanitizers" = "yes" ; then
6011   write_c_skeleton
6012   if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
6013       have_asan=yes
6014   fi
6015
6016   # we could use a simple skeleton for flags checks, but this also
6017   # detect the static linking issue of ubsan, see also:
6018   # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
6019   cat > $TMPC << EOF
6020 #include <stdlib.h>
6021 int main(void) {
6022     void *tmp = malloc(10);
6023     if (tmp != NULL) {
6024         return *(int *)(tmp + 2);
6025     }
6026     return 1;
6027 }
6028 EOF
6029   if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
6030       have_ubsan=yes
6031   fi
6032
6033   if check_include "sanitizer/asan_interface.h" ; then
6034       have_asan_iface_h=yes
6035   fi
6036
6037   cat > $TMPC << EOF
6038 #include <sanitizer/asan_interface.h>
6039 int main(void) {
6040   __sanitizer_start_switch_fiber(0, 0, 0);
6041   return 0;
6042 }
6043 EOF
6044   if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
6045       have_asan_iface_fiber=yes
6046   fi
6047 fi
6048
6049 ##########################################
6050 # checks for fuzzer
6051 if test "$fuzzing" = "yes" && test -z "${LIB_FUZZING_ENGINE+xxx}"; then
6052   write_c_fuzzer_skeleton
6053   if compile_prog "$CPU_CFLAGS -Werror -fsanitize=fuzzer" ""; then
6054     have_fuzzer=yes
6055   else
6056     error_exit "Your compiler doesn't support -fsanitize=fuzzer"
6057     exit 1
6058   fi
6059 fi
6060
6061 # Thread sanitizer is, for now, much noisier than the other sanitizers;
6062 # keep it separate until that is not the case.
6063 if test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
6064   error_exit "TSAN is not supported with other sanitiziers."
6065 fi
6066 have_tsan=no
6067 have_tsan_iface_fiber=no
6068 if test "$tsan" = "yes" ; then
6069   write_c_skeleton
6070   if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
6071       have_tsan=yes
6072   fi
6073   cat > $TMPC << EOF
6074 #include <sanitizer/tsan_interface.h>
6075 int main(void) {
6076   __tsan_create_fiber(0);
6077   return 0;
6078 }
6079 EOF
6080   if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
6081       have_tsan_iface_fiber=yes
6082   fi
6083 fi
6084
6085 ##########################################
6086 # check for libpmem
6087
6088 if test "$libpmem" != "no"; then
6089         if $pkg_config --exists "libpmem"; then
6090                 libpmem="yes"
6091                 libpmem_libs=$($pkg_config --libs libpmem)
6092                 libpmem_cflags=$($pkg_config --cflags libpmem)
6093         else
6094                 if test "$libpmem" = "yes" ; then
6095                         feature_not_found "libpmem" "Install nvml or pmdk"
6096                 fi
6097                 libpmem="no"
6098         fi
6099 fi
6100
6101 ##########################################
6102 # check for libdaxctl
6103
6104 if test "$libdaxctl" != "no"; then
6105         if $pkg_config --atleast-version=57 "libdaxctl"; then
6106                 libdaxctl="yes"
6107                 libdaxctl_libs=$($pkg_config --libs libdaxctl)
6108                 libdaxctl_cflags=$($pkg_config --cflags libdaxctl)
6109         else
6110                 if test "$libdaxctl" = "yes" ; then
6111                         feature_not_found "libdaxctl" "Install libdaxctl"
6112                 fi
6113                 libdaxctl="no"
6114         fi
6115 fi
6116
6117 ##########################################
6118 # check for slirp
6119
6120 # slirp is only required when building softmmu targets
6121 if test -z "$slirp" -a "$softmmu" != "yes" ; then
6122     slirp="no"
6123 fi
6124
6125 case "$slirp" in
6126   "" | yes)
6127     if $pkg_config slirp; then
6128       slirp=system
6129     elif test -e "${source_path}/.git" && test $git_update = 'yes' ; then
6130       slirp=git
6131     elif test -e "${source_path}/slirp/Makefile" ; then
6132       slirp=internal
6133     elif test -z "$slirp" ; then
6134       slirp=no
6135     else
6136       feature_not_found "slirp" "Install slirp devel or git submodule"
6137     fi
6138     ;;
6139
6140   system)
6141     if ! $pkg_config slirp; then
6142       feature_not_found "slirp" "Install slirp devel"
6143     fi
6144     ;;
6145 esac
6146
6147 case "$slirp" in
6148   git | internal)
6149     if test "$slirp" = git; then
6150       git_submodules="${git_submodules} slirp"
6151     fi
6152     mkdir -p slirp
6153     slirp_cflags="-I${source_path}/slirp/src -Islirp/src"
6154     slirp_libs="-Lslirp -lslirp"
6155     if test "$mingw32" = "yes" ; then
6156       slirp_libs="$slirp_libs -lws2_32 -liphlpapi"
6157     fi
6158     ;;
6159
6160   system)
6161     slirp_version=$($pkg_config --modversion slirp 2>/dev/null)
6162     slirp_cflags=$($pkg_config --cflags slirp 2>/dev/null)
6163     slirp_libs=$($pkg_config --libs slirp 2>/dev/null)
6164     ;;
6165
6166   no)
6167     ;;
6168   *)
6169     error_exit "Unknown state for slirp: $slirp"
6170     ;;
6171 esac
6172
6173 ##########################################
6174 # check for usable __NR_keyctl syscall
6175
6176 if test "$linux" = "yes" ; then
6177
6178     have_keyring=no
6179     cat > $TMPC << EOF
6180 #include <errno.h>
6181 #include <asm/unistd.h>
6182 #include <linux/keyctl.h>
6183 #include <unistd.h>
6184 int main(void) {
6185     return syscall(__NR_keyctl, KEYCTL_READ, 0, NULL, NULL, 0);
6186 }
6187 EOF
6188     if compile_prog "" "" ; then
6189         have_keyring=yes
6190     fi
6191 fi
6192 if test "$secret_keyring" != "no"
6193 then
6194     if test "$have_keyring" = "yes"
6195     then
6196         secret_keyring=yes
6197     else
6198         if test "$secret_keyring" = "yes"
6199         then
6200             error_exit "syscall __NR_keyctl requested, \
6201 but not implemented on your system"
6202         else
6203             secret_keyring=no
6204         fi
6205     fi
6206 fi
6207
6208 ##########################################
6209 # End of CC checks
6210 # After here, no more $cc or $ld runs
6211
6212 write_c_skeleton
6213
6214 if test "$gcov" = "yes" ; then
6215   :
6216 elif test "$fortify_source" = "yes" ; then
6217   QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
6218   debug=no
6219 fi
6220 if test "$debug_info" = "yes"; then
6221   CFLAGS="-g $CFLAGS"
6222   LDFLAGS="-g $LDFLAGS"
6223 fi
6224 if test "$debug" = "no"; then
6225   CFLAGS="-O2 $CFLAGS"
6226 fi
6227
6228 case "$ARCH" in
6229 alpha)
6230   # Ensure there's only a single GP
6231   QEMU_CFLAGS="-msmall-data $QEMU_CFLAGS"
6232 ;;
6233 esac
6234
6235 if test "$gprof" = "yes" ; then
6236   QEMU_CFLAGS="-p $QEMU_CFLAGS"
6237   QEMU_LDFLAGS="-p $QEMU_LDFLAGS"
6238 fi
6239
6240 if test "$have_asan" = "yes"; then
6241   QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
6242   QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
6243   if test "$have_asan_iface_h" = "no" ; then
6244       echo "ASAN build enabled, but ASAN header missing." \
6245            "Without code annotation, the report may be inferior."
6246   elif test "$have_asan_iface_fiber" = "no" ; then
6247       echo "ASAN build enabled, but ASAN header is too old." \
6248            "Without code annotation, the report may be inferior."
6249   fi
6250 fi
6251 if test "$have_tsan" = "yes" ; then
6252   if test "$have_tsan_iface_fiber" = "yes" ; then
6253     QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
6254     QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
6255   else
6256     error_exit "Cannot enable TSAN due to missing fiber annotation interface."
6257   fi
6258 elif test "$tsan" = "yes" ; then
6259   error_exit "Cannot enable TSAN due to missing sanitize thread interface."
6260 fi
6261 if test "$have_ubsan" = "yes"; then
6262   QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
6263   QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
6264 fi
6265
6266 ##########################################
6267 # Do we have libnfs
6268 if test "$libnfs" != "no" ; then
6269   if $pkg_config --atleast-version=1.9.3 libnfs; then
6270     libnfs="yes"
6271     libnfs_libs=$($pkg_config --libs libnfs)
6272   else
6273     if test "$libnfs" = "yes" ; then
6274       feature_not_found "libnfs" "Install libnfs devel >= 1.9.3"
6275     fi
6276     libnfs="no"
6277   fi
6278 fi
6279
6280 ##########################################
6281 # Do we have libudev
6282 if test "$libudev" != "no" ; then
6283   if $pkg_config libudev && test "$static" != "yes"; then
6284     libudev="yes"
6285     libudev_libs=$($pkg_config --libs libudev)
6286   else
6287     libudev="no"
6288   fi
6289 fi
6290
6291 # Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
6292 if test "$solaris" = "no" && test "$tsan" = "no"; then
6293     if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
6294         QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
6295     fi
6296 fi
6297
6298 # test if pod2man has --utf8 option
6299 if pod2man --help | grep -q utf8; then
6300     POD2MAN="pod2man --utf8"
6301 else
6302     POD2MAN="pod2man"
6303 fi
6304
6305 # Use ASLR, no-SEH and DEP if available
6306 if test "$mingw32" = "yes" ; then
6307     for flag in --dynamicbase --no-seh --nxcompat; do
6308         if ld_has $flag ; then
6309             QEMU_LDFLAGS="-Wl,$flag $QEMU_LDFLAGS"
6310         fi
6311     done
6312 fi
6313
6314 # Disable OpenBSD W^X if available
6315 if test "$tcg" = "yes" && test "$targetos" = "OpenBSD"; then
6316     cat > $TMPC <<EOF
6317     int main(void) { return 0; }
6318 EOF
6319     wx_ldflags="-Wl,-z,wxneeded"
6320     if compile_prog "" "$wx_ldflags"; then
6321         QEMU_LDFLAGS="$QEMU_LDFLAGS $wx_ldflags"
6322     fi
6323 fi
6324
6325 qemu_confdir="$sysconfdir/$qemu_suffix"
6326 qemu_moddir="$libdir/$qemu_suffix"
6327 qemu_datadir="$datadir/$qemu_suffix"
6328 qemu_docdir="$docdir/$qemu_suffix"
6329 qemu_localedir="$datadir/locale"
6330 qemu_icondir="$datadir/icons"
6331 qemu_desktopdir="$datadir/applications"
6332
6333 # We can only support ivshmem if we have eventfd
6334 if [ "$eventfd" = "yes" ]; then
6335   ivshmem=yes
6336 fi
6337
6338 if test "$softmmu" = yes ; then
6339   if test "$linux" = yes; then
6340     if test "$virtfs" != no && test "$cap_ng" = yes && test "$attr" = yes ; then
6341       virtfs=yes
6342     else
6343       if test "$virtfs" = yes; then
6344         error_exit "VirtFS requires libcap-ng devel and libattr devel"
6345       fi
6346       virtfs=no
6347     fi
6348     if test "$mpath" != no && test "$mpathpersist" = yes ; then
6349       mpath=yes
6350     else
6351       if test "$mpath" = yes; then
6352         error_exit "Multipath requires libmpathpersist devel"
6353       fi
6354       mpath=no
6355     fi
6356   else
6357     if test "$virtfs" = yes; then
6358       error_exit "VirtFS is supported only on Linux"
6359     fi
6360     virtfs=no
6361     if test "$mpath" = yes; then
6362       error_exit "Multipath is supported only on Linux"
6363     fi
6364     mpath=no
6365   fi
6366 fi
6367
6368 # Probe for guest agent support/options
6369
6370 if [ "$guest_agent" != "no" ]; then
6371   if [ "$softmmu" = no -a "$want_tools" = no ] ; then
6372       guest_agent=no
6373   elif [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" -o "$mingw32" = "yes" ] ; then
6374       guest_agent=yes
6375   elif [ "$guest_agent" != yes ]; then
6376       guest_agent=no
6377   else
6378       error_exit "Guest agent is not supported on this platform"
6379   fi
6380 fi
6381
6382 # Guest agent Window MSI  package
6383
6384 if test "$guest_agent" != yes; then
6385   if test "$guest_agent_msi" = yes; then
6386     error_exit "MSI guest agent package requires guest agent enabled"
6387   fi
6388   guest_agent_msi=no
6389 elif test "$mingw32" != "yes"; then
6390   if test "$guest_agent_msi" = "yes"; then
6391     error_exit "MSI guest agent package is available only for MinGW Windows cross-compilation"
6392   fi
6393   guest_agent_msi=no
6394 elif ! has wixl; then
6395   if test "$guest_agent_msi" = "yes"; then
6396     error_exit "MSI guest agent package requires wixl tool installed ( usually from msitools package )"
6397   fi
6398   guest_agent_msi=no
6399 else
6400   # we support qemu-ga, mingw32, and wixl: default to MSI enabled if it wasn't
6401   # disabled explicitly
6402   if test "$guest_agent_msi" != "no"; then
6403     guest_agent_msi=yes
6404   fi
6405 fi
6406
6407 if test "$guest_agent_msi" = "yes"; then
6408   if test "$guest_agent_with_vss" = "yes"; then
6409     QEMU_GA_MSI_WITH_VSS="-D InstallVss"
6410   fi
6411
6412   if test "$QEMU_GA_MANUFACTURER" = ""; then
6413     QEMU_GA_MANUFACTURER=QEMU
6414   fi
6415
6416   if test "$QEMU_GA_DISTRO" = ""; then
6417     QEMU_GA_DISTRO=Linux
6418   fi
6419
6420   if test "$QEMU_GA_VERSION" = ""; then
6421       QEMU_GA_VERSION=$(cat $source_path/VERSION)
6422   fi
6423
6424   QEMU_GA_MSI_MINGW_DLL_PATH="-D Mingw_dlls=$($pkg_config --variable=prefix glib-2.0)/bin"
6425
6426   case "$cpu" in
6427   x86_64)
6428     QEMU_GA_MSI_ARCH="-a x64 -D Arch=64"
6429     ;;
6430   i386)
6431     QEMU_GA_MSI_ARCH="-D Arch=32"
6432     ;;
6433   *)
6434     error_exit "CPU $cpu not supported for building installation package"
6435     ;;
6436   esac
6437 fi
6438
6439 # Mac OS X ships with a broken assembler
6440 roms=
6441 if { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \
6442         test "$targetos" != "Darwin" && test "$targetos" != "SunOS" && \
6443         test "$softmmu" = yes ; then
6444     # Different host OS linkers have different ideas about the name of the ELF
6445     # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
6446     # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
6447     for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
6448         if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
6449             ld_i386_emulation="$emu"
6450             roms="optionrom"
6451             break
6452         fi
6453     done
6454 fi
6455
6456 # Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
6457 if test "$cpu" = "s390x" ; then
6458   write_c_skeleton
6459   if compile_prog "-march=z900" ""; then
6460     roms="$roms s390-ccw"
6461     # SLOF is required for building the s390-ccw firmware on s390x,
6462     # since it is using the libnet code from SLOF for network booting.
6463     if test -e "${source_path}/.git" ; then
6464       git_submodules="${git_submodules} roms/SLOF"
6465     fi
6466   fi
6467 fi
6468
6469 # Check that the C++ compiler exists and works with the C compiler.
6470 # All the QEMU_CXXFLAGS are based on QEMU_CFLAGS. Keep this at the end to don't miss any other that could be added.
6471 if has $cxx; then
6472     cat > $TMPC <<EOF
6473 int c_function(void);
6474 int main(void) { return c_function(); }
6475 EOF
6476
6477     compile_object
6478
6479     cat > $TMPCXX <<EOF
6480 extern "C" {
6481    int c_function(void);
6482 }
6483 int c_function(void) { return 42; }
6484 EOF
6485
6486     update_cxxflags
6487
6488     if do_cxx $CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
6489         # C++ compiler $cxx works ok with C compiler $cc
6490         :
6491     else
6492         echo "C++ compiler $cxx does not work with C compiler $cc"
6493         echo "Disabling C++ specific optional code"
6494         cxx=
6495     fi
6496 else
6497     echo "No C++ compiler available; disabling C++ specific optional code"
6498     cxx=
6499 fi
6500
6501 if test $git_update = 'yes' ; then
6502     (cd "${source_path}" && GIT="$git" "./scripts/git-submodule.sh" update "$git_submodules")
6503 fi
6504 if test "$fdt" = "git" ; then
6505     symlink "$source_path/dtc/Makefile" "dtc/Makefile"
6506 fi
6507
6508 config_host_mak="config-host.mak"
6509
6510 echo "# Automatically generated by configure - do not modify" > $config_host_mak
6511 echo >> $config_host_mak
6512
6513 echo all: >> $config_host_mak
6514 echo "prefix=$prefix" >> $config_host_mak
6515 echo "bindir=$bindir" >> $config_host_mak
6516 echo "libdir=$libdir" >> $config_host_mak
6517 echo "libexecdir=$libexecdir" >> $config_host_mak
6518 echo "includedir=$includedir" >> $config_host_mak
6519 echo "sysconfdir=$sysconfdir" >> $config_host_mak
6520 echo "qemu_confdir=$qemu_confdir" >> $config_host_mak
6521 echo "qemu_datadir=$qemu_datadir" >> $config_host_mak
6522 echo "qemu_firmwarepath=$firmwarepath" >> $config_host_mak
6523 echo "qemu_moddir=$qemu_moddir" >> $config_host_mak
6524 if test "$mingw32" = "no" ; then
6525   echo "qemu_localstatedir=$local_statedir" >> $config_host_mak
6526 fi
6527 echo "qemu_helperdir=$libexecdir" >> $config_host_mak
6528 echo "qemu_localedir=$qemu_localedir" >> $config_host_mak
6529 echo "qemu_icondir=$qemu_icondir" >> $config_host_mak
6530 echo "qemu_desktopdir=$qemu_desktopdir" >> $config_host_mak
6531 echo "GIT=$git" >> $config_host_mak
6532 echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
6533 echo "GIT_UPDATE=$git_update" >> $config_host_mak
6534
6535 echo "ARCH=$ARCH" >> $config_host_mak
6536
6537 if test "$default_devices" = "yes" ; then
6538   echo "CONFIG_MINIKCONF_MODE=--defconfig" >> $config_host_mak
6539 else
6540   echo "CONFIG_MINIKCONF_MODE=--allnoconfig" >> $config_host_mak
6541 fi
6542 if test "$debug_tcg" = "yes" ; then
6543   echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
6544 fi
6545 if test "$strip_opt" = "yes" ; then
6546   echo "STRIP=${strip}" >> $config_host_mak
6547 fi
6548 if test "$bigendian" = "yes" ; then
6549   echo "HOST_WORDS_BIGENDIAN=y" >> $config_host_mak
6550 fi
6551 if test "$mingw32" = "yes" ; then
6552   echo "CONFIG_WIN32=y" >> $config_host_mak
6553   rc_version=$(cat $source_path/VERSION)
6554   version_major=${rc_version%%.*}
6555   rc_version=${rc_version#*.}
6556   version_minor=${rc_version%%.*}
6557   rc_version=${rc_version#*.}
6558   version_subminor=${rc_version%%.*}
6559   version_micro=0
6560   echo "CONFIG_FILEVERSION=$version_major,$version_minor,$version_subminor,$version_micro" >> $config_host_mak
6561   echo "CONFIG_PRODUCTVERSION=$version_major,$version_minor,$version_subminor,$version_micro" >> $config_host_mak
6562   if test "$guest_agent_with_vss" = "yes" ; then
6563     echo "CONFIG_QGA_VSS=y" >> $config_host_mak
6564     echo "QGA_VSS_PROVIDER=$qga_vss_provider" >> $config_host_mak
6565     echo "WIN_SDK=\"$win_sdk\"" >> $config_host_mak
6566   fi
6567   if test "$guest_agent_ntddscsi" = "yes" ; then
6568     echo "CONFIG_QGA_NTDDSCSI=y" >> $config_host_mak
6569   fi
6570   if test "$guest_agent_msi" = "yes"; then
6571     echo "QEMU_GA_MSI_ENABLED=yes" >> $config_host_mak
6572     echo "QEMU_GA_MSI_MINGW_DLL_PATH=${QEMU_GA_MSI_MINGW_DLL_PATH}" >> $config_host_mak
6573     echo "QEMU_GA_MSI_WITH_VSS=${QEMU_GA_MSI_WITH_VSS}" >> $config_host_mak
6574     echo "QEMU_GA_MSI_ARCH=${QEMU_GA_MSI_ARCH}" >> $config_host_mak
6575     echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
6576     echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
6577     echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
6578   fi
6579 else
6580   echo "CONFIG_POSIX=y" >> $config_host_mak
6581 fi
6582
6583 if test "$linux" = "yes" ; then
6584   echo "CONFIG_LINUX=y" >> $config_host_mak
6585 fi
6586
6587 if test "$darwin" = "yes" ; then
6588   echo "CONFIG_DARWIN=y" >> $config_host_mak
6589 fi
6590
6591 if test "$solaris" = "yes" ; then
6592   echo "CONFIG_SOLARIS=y" >> $config_host_mak
6593 fi
6594 if test "$haiku" = "yes" ; then
6595   echo "CONFIG_HAIKU=y" >> $config_host_mak
6596 fi
6597 if test "$static" = "yes" ; then
6598   echo "CONFIG_STATIC=y" >> $config_host_mak
6599 fi
6600 if test "$profiler" = "yes" ; then
6601   echo "CONFIG_PROFILER=y" >> $config_host_mak
6602 fi
6603 if test "$want_tools" = "yes" ; then
6604   echo "CONFIG_TOOLS=y" >> $config_host_mak
6605 fi
6606 if test "$guest_agent" = "yes" ; then
6607   echo "CONFIG_GUEST_AGENT=y" >> $config_host_mak
6608 fi
6609 if test "$slirp" != "no"; then
6610   echo "CONFIG_SLIRP=y" >> $config_host_mak
6611   echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
6612   echo "SLIRP_CFLAGS=$slirp_cflags" >> $config_host_mak
6613   echo "SLIRP_LIBS=$slirp_libs" >> $config_host_mak
6614 fi
6615 subdirs=
6616 if [ "$slirp" = "git" -o "$slirp" = "internal" ]; then
6617   subdirs="$subdirs slirp"
6618 fi
6619 if test "$vde" = "yes" ; then
6620   echo "CONFIG_VDE=y" >> $config_host_mak
6621   echo "VDE_LIBS=$vde_libs" >> $config_host_mak
6622 fi
6623 if test "$netmap" = "yes" ; then
6624   echo "CONFIG_NETMAP=y" >> $config_host_mak
6625 fi
6626 if test "$l2tpv3" = "yes" ; then
6627   echo "CONFIG_L2TPV3=y" >> $config_host_mak
6628 fi
6629 if test "$gprof" = "yes" ; then
6630   echo "CONFIG_GPROF=y" >> $config_host_mak
6631 fi
6632 if test "$cap_ng" = "yes" ; then
6633   echo "CONFIG_LIBCAP_NG=y" >> $config_host_mak
6634   echo "LIBCAP_NG_LIBS=$cap_libs" >> $config_host_mak
6635 fi
6636 echo "CONFIG_AUDIO_DRIVERS=$audio_drv_list" >> $config_host_mak
6637 for drv in $audio_drv_list; do
6638     def=CONFIG_AUDIO_$(echo $drv | LC_ALL=C tr '[a-z]' '[A-Z]')
6639     echo "$def=y" >> $config_host_mak
6640 done
6641 if test "$alsa" = "yes" ; then
6642     echo "CONFIG_ALSA=y" >> $config_host_mak
6643 fi
6644 echo "ALSA_LIBS=$alsa_libs" >> $config_host_mak
6645 echo "ALSA_CFLAGS=$alsa_cflags" >> $config_host_mak
6646 if test "$libpulse" = "yes" ; then
6647     echo "CONFIG_LIBPULSE=y" >> $config_host_mak
6648 fi
6649 echo "PULSE_LIBS=$pulse_libs" >> $config_host_mak
6650 echo "PULSE_CFLAGS=$pulse_cflags" >> $config_host_mak
6651 echo "COREAUDIO_LIBS=$coreaudio_libs" >> $config_host_mak
6652 echo "DSOUND_LIBS=$dsound_libs" >> $config_host_mak
6653 echo "OSS_LIBS=$oss_libs" >> $config_host_mak
6654 if test "$libjack" = "yes" ; then
6655     echo "CONFIG_LIBJACK=y" >> $config_host_mak
6656 fi
6657 echo "JACK_LIBS=$jack_libs" >> $config_host_mak
6658 if test "$audio_win_int" = "yes" ; then
6659   echo "CONFIG_AUDIO_WIN_INT=y" >> $config_host_mak
6660 fi
6661 echo "CONFIG_BDRV_RW_WHITELIST=$block_drv_rw_whitelist" >> $config_host_mak
6662 echo "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
6663 if test "$xfs" = "yes" ; then
6664   echo "CONFIG_XFS=y" >> $config_host_mak
6665 fi
6666 qemu_version=$(head $source_path/VERSION)
6667 echo "PKGVERSION=$pkgversion" >>$config_host_mak
6668 echo "SRC_PATH=$source_path" >> $config_host_mak
6669 echo "TARGET_DIRS=$target_list" >> $config_host_mak
6670 if [ "$docs" = "yes" ] ; then
6671   echo "BUILD_DOCS=yes" >> $config_host_mak
6672 fi
6673 if test "$modules" = "yes"; then
6674   # $shacmd can generate a hash started with digit, which the compiler doesn't
6675   # like as an symbol. So prefix it with an underscore
6676   echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
6677   echo "CONFIG_MODULES=y" >> $config_host_mak
6678 fi
6679 if test "$module_upgrades" = "yes"; then
6680   echo "CONFIG_MODULE_UPGRADES=y" >> $config_host_mak
6681 fi
6682 if test "$have_x11" = "yes" && test "$need_x11" = "yes"; then
6683   echo "CONFIG_X11=y" >> $config_host_mak
6684   echo "X11_CFLAGS=$x11_cflags" >> $config_host_mak
6685   echo "X11_LIBS=$x11_libs" >> $config_host_mak
6686 fi
6687 if test "$cocoa" = "yes" ; then
6688   echo "CONFIG_COCOA=y" >> $config_host_mak
6689 fi
6690 if test "$iconv" = "yes" ; then
6691   echo "CONFIG_ICONV=y" >> $config_host_mak
6692   echo "ICONV_CFLAGS=$iconv_cflags" >> $config_host_mak
6693   echo "ICONV_LIBS=$iconv_lib" >> $config_host_mak
6694 fi
6695 if test "$curses" = "yes" ; then
6696   echo "CONFIG_CURSES=y" >> $config_host_mak
6697   echo "CURSES_CFLAGS=$curses_inc" >> $config_host_mak
6698   echo "CURSES_LIBS=$curses_lib" >> $config_host_mak
6699 fi
6700 if test "$pipe2" = "yes" ; then
6701   echo "CONFIG_PIPE2=y" >> $config_host_mak
6702 fi
6703 if test "$accept4" = "yes" ; then
6704   echo "CONFIG_ACCEPT4=y" >> $config_host_mak
6705 fi
6706 if test "$splice" = "yes" ; then
6707   echo "CONFIG_SPLICE=y" >> $config_host_mak
6708 fi
6709 if test "$eventfd" = "yes" ; then
6710   echo "CONFIG_EVENTFD=y" >> $config_host_mak
6711 fi
6712 if test "$memfd" = "yes" ; then
6713   echo "CONFIG_MEMFD=y" >> $config_host_mak
6714 fi
6715 if test "$have_usbfs" = "yes" ; then
6716   echo "CONFIG_USBFS=y" >> $config_host_mak
6717 fi
6718 if test "$fallocate" = "yes" ; then
6719   echo "CONFIG_FALLOCATE=y" >> $config_host_mak
6720 fi
6721 if test "$fallocate_punch_hole" = "yes" ; then
6722   echo "CONFIG_FALLOCATE_PUNCH_HOLE=y" >> $config_host_mak
6723 fi
6724 if test "$fallocate_zero_range" = "yes" ; then
6725   echo "CONFIG_FALLOCATE_ZERO_RANGE=y" >> $config_host_mak
6726 fi
6727 if test "$posix_fallocate" = "yes" ; then
6728   echo "CONFIG_POSIX_FALLOCATE=y" >> $config_host_mak
6729 fi
6730 if test "$sync_file_range" = "yes" ; then
6731   echo "CONFIG_SYNC_FILE_RANGE=y" >> $config_host_mak
6732 fi
6733 if test "$fiemap" = "yes" ; then
6734   echo "CONFIG_FIEMAP=y" >> $config_host_mak
6735 fi
6736 if test "$dup3" = "yes" ; then
6737   echo "CONFIG_DUP3=y" >> $config_host_mak
6738 fi
6739 if test "$ppoll" = "yes" ; then
6740   echo "CONFIG_PPOLL=y" >> $config_host_mak
6741 fi
6742 if test "$prctl_pr_set_timerslack" = "yes" ; then
6743   echo "CONFIG_PRCTL_PR_SET_TIMERSLACK=y" >> $config_host_mak
6744 fi
6745 if test "$epoll" = "yes" ; then
6746   echo "CONFIG_EPOLL=y" >> $config_host_mak
6747 fi
6748 if test "$epoll_create1" = "yes" ; then
6749   echo "CONFIG_EPOLL_CREATE1=y" >> $config_host_mak
6750 fi
6751 if test "$sendfile" = "yes" ; then
6752   echo "CONFIG_SENDFILE=y" >> $config_host_mak
6753 fi
6754 if test "$timerfd" = "yes" ; then
6755   echo "CONFIG_TIMERFD=y" >> $config_host_mak
6756 fi
6757 if test "$setns" = "yes" ; then
6758   echo "CONFIG_SETNS=y" >> $config_host_mak
6759 fi
6760 if test "$clock_adjtime" = "yes" ; then
6761   echo "CONFIG_CLOCK_ADJTIME=y" >> $config_host_mak
6762 fi
6763 if test "$syncfs" = "yes" ; then
6764   echo "CONFIG_SYNCFS=y" >> $config_host_mak
6765 fi
6766 if test "$kcov" = "yes" ; then
6767   echo "CONFIG_KCOV=y" >> $config_host_mak
6768 fi
6769 if test "$btrfs" = "yes" ; then
6770   echo "CONFIG_BTRFS=y" >> $config_host_mak
6771 fi
6772 if test "$inotify" = "yes" ; then
6773   echo "CONFIG_INOTIFY=y" >> $config_host_mak
6774 fi
6775 if test "$inotify1" = "yes" ; then
6776   echo "CONFIG_INOTIFY1=y" >> $config_host_mak
6777 fi
6778 if test "$sem_timedwait" = "yes" ; then
6779   echo "CONFIG_SEM_TIMEDWAIT=y" >> $config_host_mak
6780 fi
6781 if test "$strchrnul" = "yes" ; then
6782   echo "HAVE_STRCHRNUL=y" >> $config_host_mak
6783 fi
6784 if test "$st_atim" = "yes" ; then
6785   echo "HAVE_STRUCT_STAT_ST_ATIM=y" >> $config_host_mak
6786 fi
6787 if test "$byteswap_h" = "yes" ; then
6788   echo "CONFIG_BYTESWAP_H=y" >> $config_host_mak
6789 fi
6790 if test "$bswap_h" = "yes" ; then
6791   echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak
6792 fi
6793 if test "$curl" = "yes" ; then
6794   echo "CONFIG_CURL=y" >> $config_host_mak
6795   echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak
6796   echo "CURL_LIBS=$curl_libs" >> $config_host_mak
6797 fi
6798 if test "$brlapi" = "yes" ; then
6799   echo "CONFIG_BRLAPI=y" >> $config_host_mak
6800   echo "BRLAPI_LIBS=$brlapi_libs" >> $config_host_mak
6801 fi
6802 if test "$gtk" = "yes" ; then
6803   echo "CONFIG_GTK=y" >> $config_host_mak
6804   echo "GTK_CFLAGS=$gtk_cflags" >> $config_host_mak
6805   echo "GTK_LIBS=$gtk_libs" >> $config_host_mak
6806   if test "$gtk_gl" = "yes" ; then
6807     echo "CONFIG_GTK_GL=y" >> $config_host_mak
6808   fi
6809 fi
6810 if test "$gio" = "yes" ; then
6811     echo "CONFIG_GIO=y" >> $config_host_mak
6812     echo "GIO_CFLAGS=$gio_cflags" >> $config_host_mak
6813     echo "GIO_LIBS=$gio_libs" >> $config_host_mak
6814     echo "GDBUS_CODEGEN=$gdbus_codegen" >> $config_host_mak
6815 fi
6816 echo "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak
6817 if test "$gnutls" = "yes" ; then
6818   echo "CONFIG_GNUTLS=y" >> $config_host_mak
6819   echo "GNUTLS_CFLAGS=$gnutls_cflags" >> $config_host_mak
6820   echo "GNUTLS_LIBS=$gnutls_libs" >> $config_host_mak
6821 fi
6822 if test "$gcrypt" = "yes" ; then
6823   echo "CONFIG_GCRYPT=y" >> $config_host_mak
6824   if test "$gcrypt_hmac" = "yes" ; then
6825     echo "CONFIG_GCRYPT_HMAC=y" >> $config_host_mak
6826   fi
6827   echo "GCRYPT_CFLAGS=$gcrypt_cflags" >> $config_host_mak
6828   echo "GCRYPT_LIBS=$gcrypt_libs" >> $config_host_mak
6829 fi
6830 if test "$nettle" = "yes" ; then
6831   echo "CONFIG_NETTLE=y" >> $config_host_mak
6832   echo "CONFIG_NETTLE_VERSION_MAJOR=${nettle_version%%.*}" >> $config_host_mak
6833   echo "NETTLE_CFLAGS=$nettle_cflags" >> $config_host_mak
6834   echo "NETTLE_LIBS=$nettle_libs" >> $config_host_mak
6835 fi
6836 if test "$qemu_private_xts" = "yes" ; then
6837   echo "CONFIG_QEMU_PRIVATE_XTS=y" >> $config_host_mak
6838 fi
6839 if test "$tasn1" = "yes" ; then
6840   echo "CONFIG_TASN1=y" >> $config_host_mak
6841 fi
6842 if test "$auth_pam" = "yes" ; then
6843     echo "CONFIG_AUTH_PAM=y" >> $config_host_mak
6844 fi
6845 if test "$have_ifaddrs_h" = "yes" ; then
6846     echo "HAVE_IFADDRS_H=y" >> $config_host_mak
6847 fi
6848 if test "$have_drm_h" = "yes" ; then
6849   echo "HAVE_DRM_H=y" >> $config_host_mak
6850 fi
6851 if test "$have_broken_size_max" = "yes" ; then
6852     echo "HAVE_BROKEN_SIZE_MAX=y" >> $config_host_mak
6853 fi
6854 if test "$have_openpty" = "yes" ; then
6855     echo "HAVE_OPENPTY=y" >> $config_host_mak
6856 fi
6857 if test "$have_sys_signal_h" = "yes" ; then
6858     echo "HAVE_SYS_SIGNAL_H=y" >> $config_host_mak
6859 fi
6860
6861 # Work around a system header bug with some kernel/XFS header
6862 # versions where they both try to define 'struct fsxattr':
6863 # xfs headers will not try to redefine structs from linux headers
6864 # if this macro is set.
6865 if test "$have_fsxattr" = "yes" ; then
6866     echo "HAVE_FSXATTR=y" >> $config_host_mak
6867 fi
6868 if test "$have_copy_file_range" = "yes" ; then
6869     echo "HAVE_COPY_FILE_RANGE=y" >> $config_host_mak
6870 fi
6871 if test "$vte" = "yes" ; then
6872   echo "CONFIG_VTE=y" >> $config_host_mak
6873   echo "VTE_CFLAGS=$vte_cflags" >> $config_host_mak
6874   echo "VTE_LIBS=$vte_libs" >> $config_host_mak
6875 fi
6876 if test "$virglrenderer" = "yes" ; then
6877   echo "CONFIG_VIRGL=y" >> $config_host_mak
6878   echo "VIRGL_CFLAGS=$virgl_cflags" >> $config_host_mak
6879   echo "VIRGL_LIBS=$virgl_libs" >> $config_host_mak
6880 fi
6881 if test "$xen" = "yes" ; then
6882   echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
6883   echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
6884   echo "XEN_CFLAGS=$xen_cflags" >> $config_host_mak
6885   echo "XEN_LIBS=$xen_libs" >> $config_host_mak
6886 fi
6887 if test "$linux_aio" = "yes" ; then
6888   echo "CONFIG_LINUX_AIO=y" >> $config_host_mak
6889 fi
6890 if test "$linux_io_uring" = "yes" ; then
6891   echo "CONFIG_LINUX_IO_URING=y" >> $config_host_mak
6892   echo "LINUX_IO_URING_CFLAGS=$linux_io_uring_cflags" >> $config_host_mak
6893   echo "LINUX_IO_URING_LIBS=$linux_io_uring_libs" >> $config_host_mak
6894 fi
6895 if test "$attr" = "yes" ; then
6896   echo "CONFIG_ATTR=y" >> $config_host_mak
6897   echo "LIBATTR_LIBS=$libattr_libs" >> $config_host_mak
6898 fi
6899 if test "$libattr" = "yes" ; then
6900   echo "CONFIG_LIBATTR=y" >> $config_host_mak
6901 fi
6902 if test "$virtfs" = "yes" ; then
6903   echo "CONFIG_VIRTFS=y" >> $config_host_mak
6904 fi
6905 if test "$mpath" = "yes" ; then
6906   echo "CONFIG_MPATH=y" >> $config_host_mak
6907   if test "$mpathpersist_new_api" = "yes"; then
6908     echo "CONFIG_MPATH_NEW_API=y" >> $config_host_mak
6909   fi
6910 fi
6911 if test "$vhost_scsi" = "yes" ; then
6912   echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
6913 fi
6914 if test "$vhost_net" = "yes" ; then
6915   echo "CONFIG_VHOST_NET=y" >> $config_host_mak
6916 fi
6917 if test "$vhost_net_user" = "yes" ; then
6918   echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak
6919 fi
6920 if test "$vhost_net_vdpa" = "yes" ; then
6921   echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak
6922 fi
6923 if test "$vhost_crypto" = "yes" ; then
6924   echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
6925 fi
6926 if test "$vhost_vsock" = "yes" ; then
6927   echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
6928   if test "$vhost_user" = "yes" ; then
6929     echo "CONFIG_VHOST_USER_VSOCK=y" >> $config_host_mak
6930   fi
6931 fi
6932 if test "$vhost_kernel" = "yes" ; then
6933   echo "CONFIG_VHOST_KERNEL=y" >> $config_host_mak
6934 fi
6935 if test "$vhost_user" = "yes" ; then
6936   echo "CONFIG_VHOST_USER=y" >> $config_host_mak
6937 fi
6938 if test "$vhost_vdpa" = "yes" ; then
6939   echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
6940 fi
6941 if test "$vhost_user_fs" = "yes" ; then
6942   echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak
6943 fi
6944 if test "$blobs" = "yes" ; then
6945   echo "INSTALL_BLOBS=yes" >> $config_host_mak
6946 fi
6947 if test "$iovec" = "yes" ; then
6948   echo "CONFIG_IOVEC=y" >> $config_host_mak
6949 fi
6950 if test "$preadv" = "yes" ; then
6951   echo "CONFIG_PREADV=y" >> $config_host_mak
6952 fi
6953 if test "$fdt" != "no" ; then
6954   echo "CONFIG_FDT=y" >> $config_host_mak
6955   echo "FDT_CFLAGS=$fdt_cflags" >> $config_host_mak
6956   echo "FDT_LIBS=$fdt_ldflags $fdt_libs" >> $config_host_mak
6957 fi
6958 if test "$membarrier" = "yes" ; then
6959   echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
6960 fi
6961 if test "$signalfd" = "yes" ; then
6962   echo "CONFIG_SIGNALFD=y" >> $config_host_mak
6963 fi
6964 if test "$optreset" = "yes" ; then
6965   echo "HAVE_OPTRESET=y" >> $config_host_mak
6966 fi
6967 if test "$tcg" = "yes"; then
6968   echo "CONFIG_TCG=y" >> $config_host_mak
6969   if test "$tcg_interpreter" = "yes" ; then
6970     echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
6971   fi
6972 fi
6973 if test "$fdatasync" = "yes" ; then
6974   echo "CONFIG_FDATASYNC=y" >> $config_host_mak
6975 fi
6976 if test "$madvise" = "yes" ; then
6977   echo "CONFIG_MADVISE=y" >> $config_host_mak
6978 fi
6979 if test "$posix_madvise" = "yes" ; then
6980   echo "CONFIG_POSIX_MADVISE=y" >> $config_host_mak
6981 fi
6982 if test "$posix_memalign" = "yes" ; then
6983   echo "CONFIG_POSIX_MEMALIGN=y" >> $config_host_mak
6984 fi
6985 if test "$spice" = "yes" ; then
6986   echo "CONFIG_SPICE=y" >> $config_host_mak
6987   echo "SPICE_CFLAGS=$spice_cflags" >> $config_host_mak
6988   echo "SPICE_LIBS=$spice_libs" >> $config_host_mak
6989 fi
6990
6991 if test "$smartcard" = "yes" ; then
6992   echo "CONFIG_SMARTCARD=y" >> $config_host_mak
6993   echo "SMARTCARD_CFLAGS=$libcacard_cflags" >> $config_host_mak
6994   echo "SMARTCARD_LIBS=$libcacard_libs" >> $config_host_mak
6995 fi
6996
6997 if test "$libusb" = "yes" ; then
6998   echo "CONFIG_USB_LIBUSB=y" >> $config_host_mak
6999   echo "LIBUSB_CFLAGS=$libusb_cflags" >> $config_host_mak
7000   echo "LIBUSB_LIBS=$libusb_libs" >> $config_host_mak
7001 fi
7002
7003 if test "$usb_redir" = "yes" ; then
7004   echo "CONFIG_USB_REDIR=y" >> $config_host_mak
7005   echo "USB_REDIR_CFLAGS=$usb_redir_cflags" >> $config_host_mak
7006   echo "USB_REDIR_LIBS=$usb_redir_libs" >> $config_host_mak
7007 fi
7008
7009 if test "$opengl" = "yes" ; then
7010   echo "CONFIG_OPENGL=y" >> $config_host_mak
7011   echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
7012   echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
7013   if test "$opengl_dmabuf" = "yes" ; then
7014     echo "CONFIG_OPENGL_DMABUF=y" >> $config_host_mak
7015   fi
7016 fi
7017
7018 if test "$gbm" = "yes" ; then
7019     echo "CONFIG_GBM=y" >> $config_host_mak
7020     echo "GBM_LIBS=$gbm_libs" >> $config_host_mak
7021     echo "GBM_CFLAGS=$gbm_cflags" >> $config_host_mak
7022 fi
7023
7024
7025 if test "$malloc_trim" = "yes" ; then
7026   echo "CONFIG_MALLOC_TRIM=y" >> $config_host_mak
7027 fi
7028
7029 if test "$avx2_opt" = "yes" ; then
7030   echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
7031 fi
7032
7033 if test "$avx512f_opt" = "yes" ; then
7034   echo "CONFIG_AVX512F_OPT=y" >> $config_host_mak
7035 fi
7036
7037 if test "$lzo" = "yes" ; then
7038   echo "CONFIG_LZO=y" >> $config_host_mak
7039   echo "LZO_LIBS=$lzo_libs" >> $config_host_mak
7040 fi
7041
7042 if test "$snappy" = "yes" ; then
7043   echo "CONFIG_SNAPPY=y" >> $config_host_mak
7044   echo "SNAPPY_LIBS=$snappy_libs" >> $config_host_mak
7045 fi
7046
7047 if test "$bzip2" = "yes" ; then
7048   echo "CONFIG_BZIP2=y" >> $config_host_mak
7049   echo "BZIP2_LIBS=-lbz2" >> $config_host_mak
7050 fi
7051
7052 if test "$lzfse" = "yes" ; then
7053   echo "CONFIG_LZFSE=y" >> $config_host_mak
7054   echo "LZFSE_LIBS=-llzfse" >> $config_host_mak
7055 fi
7056
7057 if test "$zstd" = "yes" ; then
7058   echo "CONFIG_ZSTD=y" >> $config_host_mak
7059   echo "ZSTD_CFLAGS=$zstd_cflags" >> $config_host_mak
7060   echo "ZSTD_LIBS=$zstd_libs" >> $config_host_mak
7061 fi
7062
7063 if test "$libiscsi" = "yes" ; then
7064   echo "CONFIG_LIBISCSI=y" >> $config_host_mak
7065   echo "LIBISCSI_CFLAGS=$libiscsi_cflags" >> $config_host_mak
7066   echo "LIBISCSI_LIBS=$libiscsi_libs" >> $config_host_mak
7067 fi
7068
7069 if test "$libnfs" = "yes" ; then
7070   echo "CONFIG_LIBNFS=y" >> $config_host_mak
7071   echo "LIBNFS_LIBS=$libnfs_libs" >> $config_host_mak
7072 fi
7073
7074 if test "$seccomp" = "yes"; then
7075   echo "CONFIG_SECCOMP=y" >> $config_host_mak
7076   echo "SECCOMP_CFLAGS=$seccomp_cflags" >> $config_host_mak
7077   echo "SECCOMP_LIBS=$seccomp_libs" >> $config_host_mak
7078 fi
7079
7080 # XXX: suppress that
7081 if [ "$bsd" = "yes" ] ; then
7082   echo "CONFIG_BSD=y" >> $config_host_mak
7083 fi
7084
7085 if test "$localtime_r" = "yes" ; then
7086   echo "CONFIG_LOCALTIME_R=y" >> $config_host_mak
7087 fi
7088 if test "$qom_cast_debug" = "yes" ; then
7089   echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak
7090 fi
7091 if test "$rbd" = "yes" ; then
7092   echo "CONFIG_RBD=y" >> $config_host_mak
7093   echo "RBD_LIBS=$rbd_libs" >> $config_host_mak
7094 fi
7095
7096 echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
7097 if test "$coroutine_pool" = "yes" ; then
7098   echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
7099 else
7100   echo "CONFIG_COROUTINE_POOL=0" >> $config_host_mak
7101 fi
7102
7103 if test "$debug_stack_usage" = "yes" ; then
7104   echo "CONFIG_DEBUG_STACK_USAGE=y" >> $config_host_mak
7105 fi
7106
7107 if test "$crypto_afalg" = "yes" ; then
7108   echo "CONFIG_AF_ALG=y" >> $config_host_mak
7109 fi
7110
7111 if test "$open_by_handle_at" = "yes" ; then
7112   echo "CONFIG_OPEN_BY_HANDLE=y" >> $config_host_mak
7113 fi
7114
7115 if test "$linux_magic_h" = "yes" ; then
7116   echo "CONFIG_LINUX_MAGIC_H=y" >> $config_host_mak
7117 fi
7118
7119 if test "$valgrind_h" = "yes" ; then
7120   echo "CONFIG_VALGRIND_H=y" >> $config_host_mak
7121 fi
7122
7123 if test "$have_asan_iface_fiber" = "yes" ; then
7124     echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
7125 fi
7126
7127 if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
7128     echo "CONFIG_TSAN=y" >> $config_host_mak
7129 fi
7130
7131 if test "$has_environ" = "yes" ; then
7132   echo "CONFIG_HAS_ENVIRON=y" >> $config_host_mak
7133 fi
7134
7135 if test "$cpuid_h" = "yes" ; then
7136   echo "CONFIG_CPUID_H=y" >> $config_host_mak
7137 fi
7138
7139 if test "$int128" = "yes" ; then
7140   echo "CONFIG_INT128=y" >> $config_host_mak
7141 fi
7142
7143 if test "$atomic128" = "yes" ; then
7144   echo "CONFIG_ATOMIC128=y" >> $config_host_mak
7145 fi
7146
7147 if test "$cmpxchg128" = "yes" ; then
7148   echo "CONFIG_CMPXCHG128=y" >> $config_host_mak
7149 fi
7150
7151 if test "$atomic64" = "yes" ; then
7152   echo "CONFIG_ATOMIC64=y" >> $config_host_mak
7153 fi
7154
7155 if test "$attralias" = "yes" ; then
7156   echo "CONFIG_ATTRIBUTE_ALIAS=y" >> $config_host_mak
7157 fi
7158
7159 if test "$getauxval" = "yes" ; then
7160   echo "CONFIG_GETAUXVAL=y" >> $config_host_mak
7161 fi
7162
7163 if test "$glusterfs" = "yes" ; then
7164   echo "CONFIG_GLUSTERFS=y" >> $config_host_mak
7165   echo "GLUSTERFS_CFLAGS=$glusterfs_cflags" >> $config_host_mak
7166   echo "GLUSTERFS_LIBS=$glusterfs_libs" >> $config_host_mak
7167 fi
7168
7169 if test "$glusterfs_xlator_opt" = "yes" ; then
7170   echo "CONFIG_GLUSTERFS_XLATOR_OPT=y" >> $config_host_mak
7171 fi
7172
7173 if test "$glusterfs_discard" = "yes" ; then
7174   echo "CONFIG_GLUSTERFS_DISCARD=y" >> $config_host_mak
7175 fi
7176
7177 if test "$glusterfs_fallocate" = "yes" ; then
7178   echo "CONFIG_GLUSTERFS_FALLOCATE=y" >> $config_host_mak
7179 fi
7180
7181 if test "$glusterfs_zerofill" = "yes" ; then
7182   echo "CONFIG_GLUSTERFS_ZEROFILL=y" >> $config_host_mak
7183 fi
7184
7185 if test "$glusterfs_ftruncate_has_stat" = "yes" ; then
7186   echo "CONFIG_GLUSTERFS_FTRUNCATE_HAS_STAT=y" >> $config_host_mak
7187 fi
7188
7189 if test "$glusterfs_iocb_has_stat" = "yes" ; then
7190   echo "CONFIG_GLUSTERFS_IOCB_HAS_STAT=y" >> $config_host_mak
7191 fi
7192
7193 if test "$libssh" = "yes" ; then
7194   echo "CONFIG_LIBSSH=y" >> $config_host_mak
7195   echo "LIBSSH_CFLAGS=$libssh_cflags" >> $config_host_mak
7196   echo "LIBSSH_LIBS=$libssh_libs" >> $config_host_mak
7197 fi
7198
7199 if test "$live_block_migration" = "yes" ; then
7200   echo "CONFIG_LIVE_BLOCK_MIGRATION=y" >> $config_host_mak
7201 fi
7202
7203 if test "$tpm" = "yes"; then
7204   echo 'CONFIG_TPM=y' >> $config_host_mak
7205 fi
7206
7207 echo "TRACE_BACKENDS=$trace_backends" >> $config_host_mak
7208 if have_backend "nop"; then
7209   echo "CONFIG_TRACE_NOP=y" >> $config_host_mak
7210 fi
7211 if have_backend "simple"; then
7212   echo "CONFIG_TRACE_SIMPLE=y" >> $config_host_mak
7213   # Set the appropriate trace file.
7214   trace_file="\"$trace_file-\" FMT_pid"
7215 fi
7216 if have_backend "log"; then
7217   echo "CONFIG_TRACE_LOG=y" >> $config_host_mak
7218 fi
7219 if have_backend "ust"; then
7220   echo "CONFIG_TRACE_UST=y" >> $config_host_mak
7221   echo "LTTNG_UST_LIBS=$lttng_ust_libs" >> $config_host_mak
7222   echo "URCU_BP_LIBS=$urcu_bp_libs" >> $config_host_mak
7223 fi
7224 if have_backend "dtrace"; then
7225   echo "CONFIG_TRACE_DTRACE=y" >> $config_host_mak
7226   if test "$trace_backend_stap" = "yes" ; then
7227     echo "CONFIG_TRACE_SYSTEMTAP=y" >> $config_host_mak
7228   fi
7229 fi
7230 if have_backend "ftrace"; then
7231   if test "$linux" = "yes" ; then
7232     echo "CONFIG_TRACE_FTRACE=y" >> $config_host_mak
7233   else
7234     feature_not_found "ftrace(trace backend)" "ftrace requires Linux"
7235   fi
7236 fi
7237 if have_backend "syslog"; then
7238   if test "$posix_syslog" = "yes" ; then
7239     echo "CONFIG_TRACE_SYSLOG=y" >> $config_host_mak
7240   else
7241     feature_not_found "syslog(trace backend)" "syslog not available"
7242   fi
7243 fi
7244 echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
7245
7246 if test "$rdma" = "yes" ; then
7247   echo "CONFIG_RDMA=y" >> $config_host_mak
7248   echo "RDMA_LIBS=$rdma_libs" >> $config_host_mak
7249 fi
7250
7251 if test "$pvrdma" = "yes" ; then
7252   echo "CONFIG_PVRDMA=y" >> $config_host_mak
7253 fi
7254
7255 if test "$have_rtnetlink" = "yes" ; then
7256   echo "CONFIG_RTNETLINK=y" >> $config_host_mak
7257 fi
7258
7259 if test "$libxml2" = "yes" ; then
7260   echo "CONFIG_LIBXML2=y" >> $config_host_mak
7261   echo "LIBXML2_CFLAGS=$libxml2_cflags" >> $config_host_mak
7262   echo "LIBXML2_LIBS=$libxml2_libs" >> $config_host_mak
7263 fi
7264
7265 if test "$replication" = "yes" ; then
7266   echo "CONFIG_REPLICATION=y" >> $config_host_mak
7267 fi
7268
7269 if test "$have_af_vsock" = "yes" ; then
7270   echo "CONFIG_AF_VSOCK=y" >> $config_host_mak
7271 fi
7272
7273 if test "$have_sysmacros" = "yes" ; then
7274   echo "CONFIG_SYSMACROS=y" >> $config_host_mak
7275 fi
7276
7277 if test "$have_static_assert" = "yes" ; then
7278   echo "CONFIG_STATIC_ASSERT=y" >> $config_host_mak
7279 fi
7280
7281 if test "$have_utmpx" = "yes" ; then
7282   echo "HAVE_UTMPX=y" >> $config_host_mak
7283 fi
7284 if test "$have_getrandom" = "yes" ; then
7285   echo "CONFIG_GETRANDOM=y" >> $config_host_mak
7286 fi
7287 if test "$ivshmem" = "yes" ; then
7288   echo "CONFIG_IVSHMEM=y" >> $config_host_mak
7289 fi
7290 if test "$capstone" != "no" ; then
7291   echo "CONFIG_CAPSTONE=y" >> $config_host_mak
7292   echo "CAPSTONE_CFLAGS=$capstone_cflags" >> $config_host_mak
7293   echo "CAPSTONE_LIBS=$capstone_libs" >> $config_host_mak
7294 fi
7295 if test "$debug_mutex" = "yes" ; then
7296   echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak
7297 fi
7298
7299 # Hold two types of flag:
7300 #   CONFIG_THREAD_SETNAME_BYTHREAD  - we've got a way of setting the name on
7301 #                                     a thread we have a handle to
7302 #   CONFIG_PTHREAD_SETNAME_NP_W_TID - A way of doing it on a particular
7303 #                                     platform
7304 if test "$pthread_setname_np_w_tid" = "yes" ; then
7305   echo "CONFIG_THREAD_SETNAME_BYTHREAD=y" >> $config_host_mak
7306   echo "CONFIG_PTHREAD_SETNAME_NP_W_TID=y" >> $config_host_mak
7307 elif test "$pthread_setname_np_wo_tid" = "yes" ; then
7308   echo "CONFIG_THREAD_SETNAME_BYTHREAD=y" >> $config_host_mak
7309   echo "CONFIG_PTHREAD_SETNAME_NP_WO_TID=y" >> $config_host_mak
7310 fi
7311
7312 if test "$libpmem" = "yes" ; then
7313   echo "CONFIG_LIBPMEM=y" >> $config_host_mak
7314   echo "LIBPMEM_LIBS=$libpmem_libs" >> $config_host_mak
7315   echo "LIBPMEM_CFLAGS=$libpmem_cflags" >> $config_host_mak
7316 fi
7317
7318 if test "$libdaxctl" = "yes" ; then
7319   echo "CONFIG_LIBDAXCTL=y" >> $config_host_mak
7320   echo "LIBDAXCTL_LIBS=$libdaxctl_libs" >> $config_host_mak
7321 fi
7322
7323 if test "$bochs" = "yes" ; then
7324   echo "CONFIG_BOCHS=y" >> $config_host_mak
7325 fi
7326 if test "$cloop" = "yes" ; then
7327   echo "CONFIG_CLOOP=y" >> $config_host_mak
7328 fi
7329 if test "$dmg" = "yes" ; then
7330   echo "CONFIG_DMG=y" >> $config_host_mak
7331 fi
7332 if test "$qcow1" = "yes" ; then
7333   echo "CONFIG_QCOW1=y" >> $config_host_mak
7334 fi
7335 if test "$vdi" = "yes" ; then
7336   echo "CONFIG_VDI=y" >> $config_host_mak
7337 fi
7338 if test "$vvfat" = "yes" ; then
7339   echo "CONFIG_VVFAT=y" >> $config_host_mak
7340 fi
7341 if test "$qed" = "yes" ; then
7342   echo "CONFIG_QED=y" >> $config_host_mak
7343 fi
7344 if test "$parallels" = "yes" ; then
7345   echo "CONFIG_PARALLELS=y" >> $config_host_mak
7346 fi
7347 if test "$sheepdog" = "yes" ; then
7348   echo "CONFIG_SHEEPDOG=y" >> $config_host_mak
7349 fi
7350 if test "$pty_h" = "yes" ; then
7351   echo "HAVE_PTY_H=y" >> $config_host_mak
7352 fi
7353 if test "$have_mlockall" = "yes" ; then
7354   echo "HAVE_MLOCKALL=y" >> $config_host_mak
7355 fi
7356 if test "$fuzzing" = "yes" ; then
7357   # If LIB_FUZZING_ENGINE is set, assume we are running on OSS-Fuzz, and the
7358   # needed CFLAGS have already been provided
7359   if test -z "${LIB_FUZZING_ENGINE+xxx}" ; then
7360     QEMU_CFLAGS="$QEMU_CFLAGS -fsanitize=fuzzer-no-link"
7361     FUZZ_EXE_LDFLAGS="-fsanitize=fuzzer"
7362   else
7363     FUZZ_EXE_LDFLAGS="$LIB_FUZZING_ENGINE"
7364   fi
7365 fi
7366
7367 if test "$plugins" = "yes" ; then
7368     echo "CONFIG_PLUGIN=y" >> $config_host_mak
7369     # Copy the export object list to the build dir
7370     if test "$ld_dynamic_list" = "yes" ; then
7371         echo "CONFIG_HAS_LD_DYNAMIC_LIST=yes" >> $config_host_mak
7372         ld_symbols=qemu-plugins-ld.symbols
7373         cp "$source_path/plugins/qemu-plugins.symbols" $ld_symbols
7374     elif test "$ld_exported_symbols_list" = "yes" ; then
7375         echo "CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST=yes" >> $config_host_mak
7376         ld64_symbols=qemu-plugins-ld64.symbols
7377         echo "# Automatically generated by configure - do not modify" > $ld64_symbols
7378         grep 'qemu_' "$source_path/plugins/qemu-plugins.symbols" | sed 's/;//g' | \
7379             sed -E 's/^[[:space:]]*(.*)/_\1/' >> $ld64_symbols
7380     else
7381         error_exit \
7382             "If \$plugins=yes, either \$ld_dynamic_list or " \
7383             "\$ld_exported_symbols_list should have been set to 'yes'."
7384     fi
7385 fi
7386
7387 if test -n "$gdb_bin" ; then
7388     echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
7389 fi
7390
7391 if test "$secret_keyring" = "yes" ; then
7392   echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak
7393 fi
7394
7395 if test "$tcg_interpreter" = "yes"; then
7396   QEMU_INCLUDES="-iquote ${source_path}/tcg/tci $QEMU_INCLUDES"
7397 elif test "$ARCH" = "sparc64" ; then
7398   QEMU_INCLUDES="-iquote ${source_path}/tcg/sparc $QEMU_INCLUDES"
7399 elif test "$ARCH" = "s390x" ; then
7400   QEMU_INCLUDES="-iquote ${source_path}/tcg/s390 $QEMU_INCLUDES"
7401 elif test "$ARCH" = "x86_64" || test "$ARCH" = "x32" ; then
7402   QEMU_INCLUDES="-iquote ${source_path}/tcg/i386 $QEMU_INCLUDES"
7403 elif test "$ARCH" = "ppc64" ; then
7404   QEMU_INCLUDES="-iquote ${source_path}/tcg/ppc $QEMU_INCLUDES"
7405 elif test "$ARCH" = "riscv32" || test "$ARCH" = "riscv64" ; then
7406   QEMU_INCLUDES="-I${source_path}/tcg/riscv $QEMU_INCLUDES"
7407 else
7408   QEMU_INCLUDES="-iquote ${source_path}/tcg/${ARCH} $QEMU_INCLUDES"
7409 fi
7410
7411 echo "ROMS=$roms" >> $config_host_mak
7412 echo "MAKE=$make" >> $config_host_mak
7413 echo "PYTHON=$python" >> $config_host_mak
7414 echo "SPHINX_BUILD=$sphinx_build" >> $config_host_mak
7415 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
7416 echo "MESON=$meson" >> $config_host_mak
7417 echo "CC=$cc" >> $config_host_mak
7418 if $iasl -h > /dev/null 2>&1; then
7419   echo "CONFIG_IASL=$iasl" >> $config_host_mak
7420 fi
7421 echo "CXX=$cxx" >> $config_host_mak
7422 echo "OBJCC=$objcc" >> $config_host_mak
7423 echo "AR=$ar" >> $config_host_mak
7424 echo "ARFLAGS=$ARFLAGS" >> $config_host_mak
7425 echo "AS=$as" >> $config_host_mak
7426 echo "CCAS=$ccas" >> $config_host_mak
7427 echo "CPP=$cpp" >> $config_host_mak
7428 echo "OBJCOPY=$objcopy" >> $config_host_mak
7429 echo "LD=$ld" >> $config_host_mak
7430 echo "RANLIB=$ranlib" >> $config_host_mak
7431 echo "NM=$nm" >> $config_host_mak
7432 echo "PKG_CONFIG=$pkg_config_exe" >> $config_host_mak
7433 echo "WINDRES=$windres" >> $config_host_mak
7434 echo "CFLAGS=$CFLAGS" >> $config_host_mak
7435 echo "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
7436 echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
7437 echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
7438 echo "QEMU_INCLUDES=$QEMU_INCLUDES" >> $config_host_mak
7439 echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
7440 echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
7441 if test "$sparse" = "yes" ; then
7442   echo "SPARSE_CFLAGS = -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-non-pointer-null" >> $config_host_mak
7443 fi
7444 echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
7445 echo "LDFLAGS_NOPIE=$LDFLAGS_NOPIE" >> $config_host_mak
7446 echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
7447 echo "PTHREAD_LIB=$PTHREAD_LIB" >> $config_host_mak
7448 echo "EXESUF=$EXESUF" >> $config_host_mak
7449 echo "HOST_DSOSUF=$HOST_DSOSUF" >> $config_host_mak
7450 echo "LIBS_QGA=$libs_qga" >> $config_host_mak
7451 echo "TASN1_LIBS=$tasn1_libs" >> $config_host_mak
7452 echo "TASN1_CFLAGS=$tasn1_cflags" >> $config_host_mak
7453 echo "POD2MAN=$POD2MAN" >> $config_host_mak
7454 if test "$gcov" = "yes" ; then
7455   echo "CONFIG_GCOV=y" >> $config_host_mak
7456 fi
7457
7458 if test "$libudev" != "no"; then
7459     echo "CONFIG_LIBUDEV=y" >> $config_host_mak
7460     echo "LIBUDEV_LIBS=$libudev_libs" >> $config_host_mak
7461 fi
7462 if test "$fuzzing" != "no"; then
7463     echo "CONFIG_FUZZ=y" >> $config_host_mak
7464 fi
7465 echo "FUZZ_EXE_LDFLAGS=$FUZZ_EXE_LDFLAGS" >> $config_host_mak
7466
7467 if test "$edk2_blobs" = "yes" ; then
7468   echo "DECOMPRESS_EDK2_BLOBS=y" >> $config_host_mak
7469 fi
7470
7471 if test "$rng_none" = "yes"; then
7472   echo "CONFIG_RNG_NONE=y" >> $config_host_mak
7473 fi
7474
7475 # use included Linux headers
7476 if test "$linux" = "yes" ; then
7477   mkdir -p linux-headers
7478   case "$cpu" in
7479   i386|x86_64|x32)
7480     linux_arch=x86
7481     ;;
7482   ppc|ppc64|ppc64le)
7483     linux_arch=powerpc
7484     ;;
7485   s390x)
7486     linux_arch=s390
7487     ;;
7488   aarch64)
7489     linux_arch=arm64
7490     ;;
7491   mips64)
7492     linux_arch=mips
7493     ;;
7494   *)
7495     # For most CPUs the kernel architecture name and QEMU CPU name match.
7496     linux_arch="$cpu"
7497     ;;
7498   esac
7499     # For non-KVM architectures we will not have asm headers
7500     if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
7501       symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
7502     fi
7503 fi
7504
7505 for target in $target_list; do
7506 target_dir="$target"
7507 config_target_mak=$target_dir/config-target.mak
7508 target_name=$(echo $target | cut -d '-' -f 1)
7509 target_aligned_only="no"
7510 case "$target_name" in
7511   alpha|hppa|mips64el|mips64|mipsel|mips|mipsn32|mipsn32el|sh4|sh4eb|sparc|sparc64|sparc32plus|xtensa|xtensaeb)
7512   target_aligned_only="yes"
7513   ;;
7514 esac
7515 target_bigendian="no"
7516 case "$target_name" in
7517   armeb|aarch64_be|hppa|lm32|m68k|microblaze|mips|mipsn32|mips64|moxie|or1k|ppc|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb)
7518   target_bigendian="yes"
7519   ;;
7520 esac
7521 target_softmmu="no"
7522 target_user_only="no"
7523 target_linux_user="no"
7524 target_bsd_user="no"
7525 case "$target" in
7526   ${target_name}-softmmu)
7527     target_softmmu="yes"
7528     ;;
7529   ${target_name}-linux-user)
7530     target_user_only="yes"
7531     target_linux_user="yes"
7532     ;;
7533   ${target_name}-bsd-user)
7534     target_user_only="yes"
7535     target_bsd_user="yes"
7536     ;;
7537   *)
7538     error_exit "Target '$target' not recognised"
7539     exit 1
7540     ;;
7541 esac
7542
7543 mkdir -p $target_dir
7544 echo "# Automatically generated by configure - do not modify" > $config_target_mak
7545
7546 bflt="no"
7547 mttcg="no"
7548 interp_prefix1=$(echo "$interp_prefix" | sed "s/%M/$target_name/g")
7549 gdb_xml_files=""
7550
7551 TARGET_ARCH="$target_name"
7552 TARGET_BASE_ARCH=""
7553 TARGET_ABI_DIR=""
7554 TARGET_SYSTBL_ABI=""
7555 TARGET_SYSTBL=""
7556
7557 case "$target_name" in
7558   i386)
7559     mttcg="yes"
7560         gdb_xml_files="i386-32bit.xml"
7561     TARGET_SYSTBL_ABI=i386
7562     TARGET_SYSTBL=syscall_32.tbl
7563   ;;
7564   x86_64)
7565     TARGET_BASE_ARCH=i386
7566     TARGET_SYSTBL_ABI=common,64
7567     TARGET_SYSTBL=syscall_64.tbl
7568     mttcg="yes"
7569     gdb_xml_files="i386-64bit.xml"
7570   ;;
7571   alpha)
7572     mttcg="yes"
7573     TARGET_SYSTBL_ABI=common
7574   ;;
7575   arm|armeb)
7576     TARGET_ARCH=arm
7577     TARGET_SYSTBL_ABI=common,oabi
7578     bflt="yes"
7579     mttcg="yes"
7580     gdb_xml_files="arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml arm-m-profile.xml"
7581   ;;
7582   aarch64|aarch64_be)
7583     TARGET_ARCH=aarch64
7584     TARGET_BASE_ARCH=arm
7585     bflt="yes"
7586     mttcg="yes"
7587     gdb_xml_files="aarch64-core.xml aarch64-fpu.xml arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml arm-m-profile.xml"
7588   ;;
7589   avr)
7590     gdb_xml_files="avr-cpu.xml"
7591     target_compiler=$cross_cc_avr
7592   ;;
7593   cris)
7594   ;;
7595   hppa)
7596     mttcg="yes"
7597     TARGET_SYSTBL_ABI=common,32
7598   ;;
7599   lm32)
7600   ;;
7601   m68k)
7602     bflt="yes"
7603     gdb_xml_files="cf-core.xml cf-fp.xml m68k-core.xml m68k-fp.xml"
7604     TARGET_SYSTBL_ABI=common
7605   ;;
7606   microblaze|microblazeel)
7607     TARGET_ARCH=microblaze
7608     TARGET_SYSTBL_ABI=common
7609     mttcg="yes"
7610     bflt="yes"
7611   ;;
7612   mips|mipsel)
7613     mttcg="yes"
7614     TARGET_ARCH=mips
7615     echo "TARGET_ABI_MIPSO32=y" >> $config_target_mak
7616     TARGET_SYSTBL_ABI=o32
7617     TARGET_SYSTBL=syscall_o32.tbl
7618   ;;
7619   mipsn32|mipsn32el)
7620     mttcg="yes"
7621     TARGET_ARCH=mips64
7622     TARGET_BASE_ARCH=mips
7623     echo "TARGET_ABI_MIPSN32=y" >> $config_target_mak
7624     echo "TARGET_ABI32=y" >> $config_target_mak
7625     TARGET_SYSTBL_ABI=n32
7626     TARGET_SYSTBL=syscall_n32.tbl
7627   ;;
7628   mips64|mips64el)
7629     mttcg="no"
7630     TARGET_ARCH=mips64
7631     TARGET_BASE_ARCH=mips
7632     echo "TARGET_ABI_MIPSN64=y" >> $config_target_mak
7633     TARGET_SYSTBL_ABI=n64
7634     TARGET_SYSTBL=syscall_n64.tbl
7635   ;;
7636   moxie)
7637   ;;
7638   nios2)
7639   ;;
7640   or1k)
7641     TARGET_ARCH=openrisc
7642     TARGET_BASE_ARCH=openrisc
7643   ;;
7644   ppc)
7645     gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
7646     TARGET_SYSTBL_ABI=common,nospu,32
7647   ;;
7648   ppc64)
7649     TARGET_BASE_ARCH=ppc
7650     TARGET_ABI_DIR=ppc
7651     TARGET_SYSTBL_ABI=common,nospu,64
7652     mttcg=yes
7653     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml power-vsx.xml"
7654   ;;
7655   ppc64le)
7656     TARGET_ARCH=ppc64
7657     TARGET_BASE_ARCH=ppc
7658     TARGET_ABI_DIR=ppc
7659     TARGET_SYSTBL_ABI=common,nospu,64
7660     mttcg=yes
7661     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml power-vsx.xml"
7662   ;;
7663   ppc64abi32)
7664     TARGET_ARCH=ppc64
7665     TARGET_BASE_ARCH=ppc
7666     TARGET_ABI_DIR=ppc
7667     TARGET_SYSTBL_ABI=common,nospu,32
7668     echo "TARGET_ABI32=y" >> $config_target_mak
7669     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml power-vsx.xml"
7670   ;;
7671   riscv32)
7672     TARGET_BASE_ARCH=riscv
7673     TARGET_ABI_DIR=riscv
7674     mttcg=yes
7675     gdb_xml_files="riscv-32bit-cpu.xml riscv-32bit-fpu.xml riscv-64bit-fpu.xml riscv-32bit-csr.xml riscv-32bit-virtual.xml"
7676   ;;
7677   riscv64)
7678     TARGET_BASE_ARCH=riscv
7679     TARGET_ABI_DIR=riscv
7680     mttcg=yes
7681     gdb_xml_files="riscv-64bit-cpu.xml riscv-32bit-fpu.xml riscv-64bit-fpu.xml riscv-64bit-csr.xml riscv-64bit-virtual.xml"
7682   ;;
7683   rx)
7684     TARGET_ARCH=rx
7685     bflt="yes"
7686     target_compiler=$cross_cc_rx
7687     gdb_xml_files="rx-core.xml"
7688   ;;
7689   sh4|sh4eb)
7690     TARGET_ARCH=sh4
7691     TARGET_SYSTBL_ABI=common
7692     bflt="yes"
7693   ;;
7694   sparc)
7695     TARGET_SYSTBL_ABI=common,32
7696   ;;
7697   sparc64)
7698     TARGET_BASE_ARCH=sparc
7699     TARGET_SYSTBL_ABI=common,64
7700   ;;
7701   sparc32plus)
7702     TARGET_ARCH=sparc64
7703     TARGET_BASE_ARCH=sparc
7704     TARGET_ABI_DIR=sparc
7705     TARGET_SYSTBL_ABI=common,32
7706     echo "TARGET_ABI32=y" >> $config_target_mak
7707   ;;
7708   s390x)
7709     TARGET_SYSTBL_ABI=common,64
7710     mttcg=yes
7711     gdb_xml_files="s390x-core64.xml s390-acr.xml s390-fpr.xml s390-vx.xml s390-cr.xml s390-virt.xml s390-gs.xml"
7712   ;;
7713   tilegx)
7714   ;;
7715   tricore)
7716   ;;
7717   unicore32)
7718   ;;
7719   xtensa|xtensaeb)
7720     TARGET_ARCH=xtensa
7721     TARGET_SYSTBL_ABI=common
7722     bflt="yes"
7723     mttcg="yes"
7724   ;;
7725   *)
7726     error_exit "Unsupported target CPU"
7727   ;;
7728 esac
7729 # TARGET_BASE_ARCH needs to be defined after TARGET_ARCH
7730 if [ "$TARGET_BASE_ARCH" = "" ]; then
7731   TARGET_BASE_ARCH=$TARGET_ARCH
7732 fi
7733 if [ "$TARGET_SYSTBL_ABI" != "" ] && [ "$TARGET_SYSTBL" = "" ]; then
7734   TARGET_SYSTBL=syscall.tbl
7735 fi
7736
7737 upper() {
7738     echo "$@"| LC_ALL=C tr '[a-z]' '[A-Z]'
7739 }
7740
7741 target_arch_name="$(upper $TARGET_ARCH)"
7742 echo "TARGET_$target_arch_name=y" >> $config_target_mak
7743 echo "TARGET_NAME=$target_name" >> $config_target_mak
7744 echo "TARGET_BASE_ARCH=$TARGET_BASE_ARCH" >> $config_target_mak
7745 if [ "$TARGET_ABI_DIR" = "" ]; then
7746   TARGET_ABI_DIR=$TARGET_ARCH
7747 fi
7748 echo "TARGET_ABI_DIR=$TARGET_ABI_DIR" >> $config_target_mak
7749 if [ "$HOST_VARIANT_DIR" != "" ]; then
7750     echo "HOST_VARIANT_DIR=$HOST_VARIANT_DIR" >> $config_target_mak
7751 fi
7752 if [ "$TARGET_SYSTBL_ABI" != "" ]; then
7753     echo "TARGET_SYSTBL_ABI=$TARGET_SYSTBL_ABI" >> $config_target_mak
7754     echo "TARGET_SYSTBL=$TARGET_SYSTBL" >> $config_target_mak
7755 fi
7756
7757 if supported_xen_target $target; then
7758     echo "CONFIG_XEN=y" >> $config_target_mak
7759     if test "$xen_pci_passthrough" = yes; then
7760         echo "CONFIG_XEN_PCI_PASSTHROUGH=y" >> "$config_target_mak"
7761     fi
7762 fi
7763 if supported_kvm_target $target; then
7764     echo "CONFIG_KVM=y" >> $config_target_mak
7765 fi
7766 if supported_hax_target $target; then
7767     echo "CONFIG_HAX=y" >> $config_target_mak
7768 fi
7769 if supported_hvf_target $target; then
7770     echo "CONFIG_HVF=y" >> $config_target_mak
7771 fi
7772 if supported_whpx_target $target; then
7773     echo "CONFIG_WHPX=y" >> $config_target_mak
7774 fi
7775 if test "$target_aligned_only" = "yes" ; then
7776   echo "TARGET_ALIGNED_ONLY=y" >> $config_target_mak
7777 fi
7778 if test "$target_bigendian" = "yes" ; then
7779   echo "TARGET_WORDS_BIGENDIAN=y" >> $config_target_mak
7780 fi
7781 if test "$target_softmmu" = "yes" ; then
7782   echo "CONFIG_SOFTMMU=y" >> $config_target_mak
7783   if test "$mttcg" = "yes" ; then
7784     echo "TARGET_SUPPORTS_MTTCG=y" >> $config_target_mak
7785   fi
7786 fi
7787 if test "$target_user_only" = "yes" ; then
7788   echo "CONFIG_USER_ONLY=y" >> $config_target_mak
7789   echo "CONFIG_QEMU_INTERP_PREFIX=\"$interp_prefix1\"" >> $config_target_mak
7790   symlink "../qemu-$target_name" "$target_dir/qemu-$target_name"
7791 else
7792   symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name"
7793 fi
7794 if test "$target_linux_user" = "yes" ; then
7795   echo "CONFIG_LINUX_USER=y" >> $config_target_mak
7796 fi
7797 list=""
7798 if test ! -z "$gdb_xml_files" ; then
7799   for x in $gdb_xml_files; do
7800     list="$list gdb-xml/$x"
7801   done
7802   echo "TARGET_XML_FILES=$list" >> $config_target_mak
7803 fi
7804
7805 if test "$target_user_only" = "yes" && test "$bflt" = "yes"; then
7806   echo "TARGET_HAS_BFLT=y" >> $config_target_mak
7807 fi
7808 if test "$target_bsd_user" = "yes" ; then
7809   echo "CONFIG_BSD_USER=y" >> $config_target_mak
7810 fi
7811
7812 done # for target in $targets
7813
7814 if [ "$fdt" = "git" ]; then
7815   subdirs="$subdirs dtc"
7816 fi
7817 if [ "$capstone" = "git" -o "$capstone" = "internal" ]; then
7818   subdirs="$subdirs capstone"
7819 fi
7820 echo "SUBDIRS=$subdirs" >> $config_host_mak
7821 if test -n "$LIBCAPSTONE"; then
7822   echo "LIBCAPSTONE=$LIBCAPSTONE" >> $config_host_mak
7823 fi
7824
7825 if test "$numa" = "yes"; then
7826   echo "CONFIG_NUMA=y" >> $config_host_mak
7827   echo "NUMA_LIBS=$numa_libs" >> $config_host_mak
7828 fi
7829
7830 if test "$ccache_cpp2" = "yes"; then
7831   echo "export CCACHE_CPP2=y" >> $config_host_mak
7832 fi
7833
7834 if test "$safe_stack" = "yes"; then
7835   echo "CONFIG_SAFESTACK=y" >> $config_host_mak
7836 fi
7837
7838 # If we're using a separate build tree, set it up now.
7839 # DIRS are directories which we simply mkdir in the build tree;
7840 # LINKS are things to symlink back into the source tree
7841 # (these can be both files and directories).
7842 # Caution: do not add files or directories here using wildcards. This
7843 # will result in problems later if a new file matching the wildcard is
7844 # added to the source tree -- nothing will cause configure to be rerun
7845 # so the build tree will be missing the link back to the new file, and
7846 # tests might fail. Prefer to keep the relevant files in their own
7847 # directory and symlink the directory instead.
7848 # UNLINK is used to remove symlinks from older development versions
7849 # that might get into the way when doing "git update" without doing
7850 # a "make distclean" in between.
7851 DIRS="tests tests/tcg tests/tcg/lm32 tests/qapi-schema tests/qtest/libqos"
7852 DIRS="$DIRS tests/qtest tests/qemu-iotests tests/vm tests/fp tests/qgraph"
7853 DIRS="$DIRS docs docs/interop fsdev scsi"
7854 DIRS="$DIRS pc-bios/optionrom pc-bios/s390-ccw"
7855 DIRS="$DIRS roms/seabios"
7856 LINKS="Makefile"
7857 LINKS="$LINKS tests/tcg/lm32/Makefile"
7858 LINKS="$LINKS tests/tcg/Makefile.target"
7859 LINKS="$LINKS pc-bios/optionrom/Makefile"
7860 LINKS="$LINKS pc-bios/s390-ccw/Makefile"
7861 LINKS="$LINKS roms/seabios/Makefile"
7862 LINKS="$LINKS pc-bios/qemu-icon.bmp"
7863 LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
7864 LINKS="$LINKS tests/acceptance tests/data"
7865 LINKS="$LINKS tests/qemu-iotests/check"
7866 LINKS="$LINKS python"
7867 UNLINK="pc-bios/keymaps"
7868 for bios_file in \
7869     $source_path/pc-bios/*.bin \
7870     $source_path/pc-bios/*.elf \
7871     $source_path/pc-bios/*.lid \
7872     $source_path/pc-bios/*.rom \
7873     $source_path/pc-bios/*.dtb \
7874     $source_path/pc-bios/*.img \
7875     $source_path/pc-bios/openbios-* \
7876     $source_path/pc-bios/u-boot.* \
7877     $source_path/pc-bios/edk2-*.fd.bz2 \
7878     $source_path/pc-bios/palcode-*
7879 do
7880     LINKS="$LINKS pc-bios/$(basename $bios_file)"
7881 done
7882 mkdir -p $DIRS
7883 for f in $LINKS ; do
7884     if [ -e "$source_path/$f" ]; then
7885         symlink "$source_path/$f" "$f"
7886     fi
7887 done
7888 for f in $UNLINK ; do
7889     if [ -L "$f" ]; then
7890         rm -f "$f"
7891     fi
7892 done
7893
7894 (for i in $cross_cc_vars; do
7895   export $i
7896 done
7897 export target_list source_path use_containers
7898 $source_path/tests/tcg/configure.sh)
7899
7900 # temporary config to build submodules
7901 for rom in seabios; do
7902     config_mak=roms/$rom/config.mak
7903     echo "# Automatically generated by configure - do not modify" > $config_mak
7904     echo "SRC_PATH=$source_path/roms/$rom" >> $config_mak
7905     echo "AS=$as" >> $config_mak
7906     echo "CCAS=$ccas" >> $config_mak
7907     echo "CC=$cc" >> $config_mak
7908     echo "BCC=bcc" >> $config_mak
7909     echo "CPP=$cpp" >> $config_mak
7910     echo "OBJCOPY=objcopy" >> $config_mak
7911     echo "IASL=$iasl" >> $config_mak
7912     echo "LD=$ld" >> $config_mak
7913     echo "RANLIB=$ranlib" >> $config_mak
7914 done
7915
7916 # set up qemu-iotests in this build directory
7917 iotests_common_env="tests/qemu-iotests/common.env"
7918
7919 echo "# Automatically generated by configure - do not modify" > "$iotests_common_env"
7920 echo >> "$iotests_common_env"
7921 echo "export PYTHON='$python'" >> "$iotests_common_env"
7922
7923 if test "$skip_meson" = no; then
7924 cross="config-meson.cross.new"
7925 meson_quote() {
7926     echo "['$(echo $* | sed "s/ /','/g")']"
7927 }
7928
7929 echo "# Automatically generated by configure - do not modify" > $cross
7930 echo "[properties]" >> $cross
7931 test -z "$cxx" && echo "link_language = 'c'" >> $cross
7932 echo "[binaries]" >> $cross
7933 echo "c = $(meson_quote $cc)" >> $cross
7934 test -n "$cxx" && echo "cpp = $(meson_quote $cxx)" >> $cross
7935 echo "ar = $(meson_quote $ar)" >> $cross
7936 echo "nm = $(meson_quote $nm)" >> $cross
7937 echo "pkgconfig = $(meson_quote $pkg_config_exe)" >> $cross
7938 echo "ranlib = $(meson_quote $ranlib)" >> $cross
7939 if has $sdl2_config; then
7940   echo "sdl2-config = $(meson_quote $sdl2_config)" >> $cross
7941 fi
7942 echo "strip = $(meson_quote $strip)" >> $cross
7943 echo "windres = $(meson_quote $windres)" >> $cross
7944 if test -n "$cross_prefix"; then
7945     cross_arg="--cross-file config-meson.cross"
7946     # Hack: Meson expects an absolute path for the *build* machine
7947     # for the prefix, so add a slash in front of a Windows path that
7948     # includes a drive letter.
7949     #
7950     # See https://github.com/mesonbuild/meson/issues/7577.
7951     echo "[host_machine]" >> $cross
7952     if test "$mingw32" = "yes" ; then
7953         echo "system = 'windows'" >> $cross
7954         case $prefix in
7955             ?:*) pre_prefix=/ ;;
7956         esac
7957     fi
7958     if test "$linux" = "yes" ; then
7959         echo "system = 'linux'" >> $cross
7960     fi
7961     case "$ARCH" in
7962         i386|x86_64)
7963             echo "cpu_family = 'x86'" >> $cross
7964             ;;
7965         ppc64le)
7966             echo "cpu_family = 'ppc64'" >> $cross
7967             ;;
7968         *)
7969             echo "cpu_family = '$ARCH'" >> $cross
7970             ;;
7971     esac
7972     echo "cpu = '$cpu'" >> $cross
7973     if test "$bigendian" = "yes" ; then
7974         echo "endian = 'big'" >> $cross
7975     else
7976         echo "endian = 'little'" >> $cross
7977     fi
7978 else
7979     cross_arg="--native-file config-meson.cross"
7980 fi
7981 mv $cross config-meson.cross
7982
7983 rm -rf meson-private meson-info meson-logs
7984 NINJA=${ninja:-$PWD/ninjatool} $meson setup \
7985         --prefix "${pre_prefix}$prefix" \
7986         --libdir "${pre_prefix}$libdir" \
7987         --libexecdir "${pre_prefix}$libexecdir" \
7988         --bindir "${pre_prefix}$bindir" \
7989         --includedir "${pre_prefix}$includedir" \
7990         --datadir "${pre_prefix}$datadir" \
7991         --mandir "${pre_prefix}$mandir" \
7992         --sysconfdir "${pre_prefix}$sysconfdir" \
7993         --localstatedir "${pre_prefix}$local_statedir" \
7994         -Ddocdir="${pre_prefix}$docdir" \
7995         -Dqemu_suffix="$qemu_suffix" \
7996         -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) \
7997         -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo false; fi) \
7998         -Dwerror=$(if test "$werror" = yes; then echo true; else echo false; fi) \
7999         -Dstrip=$(if test "$strip_opt" = yes; then echo true; else echo false; fi) \
8000         -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \
8001         -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
8002         -Dsdl=$sdl -Dsdl_image=$sdl_image \
8003         -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \
8004         -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\
8005         $cross_arg \
8006         "$PWD" "$source_path"
8007
8008 if test "$?" -ne 0 ; then
8009     error_exit "meson setup failed"
8010 fi
8011 touch ninjatool.stamp
8012 fi
8013
8014 # Save the configure command line for later reuse.
8015 cat <<EOD >config.status
8016 #!/bin/sh
8017 # Generated by configure.
8018 # Run this file to recreate the current configuration.
8019 # Compiler output produced by configure, useful for debugging
8020 # configure, is in config.log if it exists.
8021 EOD
8022
8023 preserve_env() {
8024     envname=$1
8025
8026     eval envval=\$$envname
8027
8028     if test -n "$envval"
8029     then
8030         echo "$envname='$envval'" >> config.status
8031         echo "export $envname" >> config.status
8032     else
8033         echo "unset $envname" >> config.status
8034     fi
8035 }
8036
8037 # Preserve various env variables that influence what
8038 # features/build target configure will detect
8039 preserve_env AR
8040 preserve_env AS
8041 preserve_env CC
8042 preserve_env CPP
8043 preserve_env CXX
8044 preserve_env INSTALL
8045 preserve_env LD
8046 preserve_env LD_LIBRARY_PATH
8047 preserve_env LIBTOOL
8048 preserve_env MAKE
8049 preserve_env NM
8050 preserve_env OBJCOPY
8051 preserve_env PATH
8052 preserve_env PKG_CONFIG
8053 preserve_env PKG_CONFIG_LIBDIR
8054 preserve_env PKG_CONFIG_PATH
8055 preserve_env PYTHON
8056 preserve_env SDL2_CONFIG
8057 preserve_env SMBD
8058 preserve_env STRIP
8059 preserve_env WINDRES
8060
8061 printf "exec" >>config.status
8062 for i in "$0" "$@"; do
8063   test "$i" = --skip-meson || printf " '%s'" "$i" >>config.status
8064 done
8065 echo ' "$@"' >>config.status
8066 chmod +x config.status
8067
8068 rm -r "$TMPDIR1"
This page took 0.467407 seconds and 4 git commands to generate.