configure: do not include $(...) variables in config-host.mak
[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 # Temporary directory used for files created while
15 # configure runs. Since it is in the build directory
16 # we can safely blow away any previous version of it
17 # (and we need not jump through hoops to try to delete
18 # it when configure exits.)
19 TMPDIR1="config-temp"
20 rm -rf "${TMPDIR1}"
21 mkdir -p "${TMPDIR1}"
22 if [ $? -ne 0 ]; then
23     echo "ERROR: failed to create temporary directory"
24     exit 1
25 fi
26
27 TMPB="qemu-conf"
28 TMPC="${TMPDIR1}/${TMPB}.c"
29 TMPO="${TMPDIR1}/${TMPB}.o"
30 TMPCXX="${TMPDIR1}/${TMPB}.cxx"
31 TMPE="${TMPDIR1}/${TMPB}.exe"
32 TMPMO="${TMPDIR1}/${TMPB}.mo"
33 TMPTXT="${TMPDIR1}/${TMPB}.txt"
34
35 rm -f config.log
36
37 # Print a helpful header at the top of config.log
38 echo "# QEMU configure log $(date)" >> config.log
39 printf "# Configured with:" >> config.log
40 printf " '%s'" "$0" "$@" >> config.log
41 echo >> config.log
42 echo "#" >> config.log
43
44 print_error() {
45     (echo
46     echo "ERROR: $1"
47     while test -n "$2"; do
48         echo "       $2"
49         shift
50     done
51     echo) >&2
52 }
53
54 error_exit() {
55     print_error "$@"
56     exit 1
57 }
58
59 do_compiler() {
60     # Run the compiler, capturing its output to the log. First argument
61     # is compiler binary to execute.
62     local compiler="$1"
63     shift
64     if test -n "$BASH_VERSION"; then eval '
65         echo >>config.log "
66 funcs: ${FUNCNAME[*]}
67 lines: ${BASH_LINENO[*]}"
68     '; fi
69     echo $compiler "$@" >> config.log
70     $compiler "$@" >> config.log 2>&1 || return $?
71     # Test passed. If this is an --enable-werror build, rerun
72     # the test with -Werror and bail out if it fails. This
73     # makes warning-generating-errors in configure test code
74     # obvious to developers.
75     if test "$werror" != "yes"; then
76         return 0
77     fi
78     # Don't bother rerunning the compile if we were already using -Werror
79     case "$*" in
80         *-Werror*)
81            return 0
82         ;;
83     esac
84     echo $compiler -Werror "$@" >> config.log
85     $compiler -Werror "$@" >> config.log 2>&1 && return $?
86     error_exit "configure test passed without -Werror but failed with -Werror." \
87         "This is probably a bug in the configure script. The failing command" \
88         "will be at the bottom of config.log." \
89         "You can run configure with --disable-werror to bypass this check."
90 }
91
92 do_cc() {
93     do_compiler "$cc" "$@"
94 }
95
96 do_cxx() {
97     do_compiler "$cxx" "$@"
98 }
99
100 # Append $2 to the variable named $1, with space separation
101 add_to() {
102     eval $1=\${$1:+\"\$$1 \"}\$2
103 }
104
105 update_cxxflags() {
106     # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
107     # options which some versions of GCC's C++ compiler complain about
108     # because they only make sense for C programs.
109     QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
110
111     for arg in $QEMU_CFLAGS; do
112         case $arg in
113             -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
114             -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
115                 ;;
116             -std=gnu99)
117                 QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }"-std=gnu++98"
118                 ;;
119             *)
120                 QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
121                 ;;
122         esac
123     done
124 }
125
126 compile_object() {
127   local_cflags="$1"
128   do_cc $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
129 }
130
131 compile_prog() {
132   local_cflags="$1"
133   local_ldflags="$2"
134   do_cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $QEMU_LDFLAGS $local_ldflags
135 }
136
137 # symbolically link $1 to $2.  Portable version of "ln -sf".
138 symlink() {
139   rm -rf "$2"
140   mkdir -p "$(dirname "$2")"
141   ln -s "$1" "$2"
142 }
143
144 # check whether a command is available to this shell (may be either an
145 # executable or a builtin)
146 has() {
147     type "$1" >/dev/null 2>&1
148 }
149
150 # search for an executable in PATH
151 path_of() {
152     local_command="$1"
153     local_ifs="$IFS"
154     local_dir=""
155
156     # pathname has a dir component?
157     if [ "${local_command#*/}" != "$local_command" ]; then
158         if [ -x "$local_command" ] && [ ! -d "$local_command" ]; then
159             echo "$local_command"
160             return 0
161         fi
162     fi
163     if [ -z "$local_command" ]; then
164         return 1
165     fi
166
167     IFS=:
168     for local_dir in $PATH; do
169         if [ -x "$local_dir/$local_command" ] && [ ! -d "$local_dir/$local_command" ]; then
170             echo "$local_dir/$local_command"
171             IFS="${local_ifs:-$(printf ' \t\n')}"
172             return 0
173         fi
174     done
175     # not found
176     IFS="${local_ifs:-$(printf ' \t\n')}"
177     return 1
178 }
179
180 have_backend () {
181     echo "$trace_backends" | grep "$1" >/dev/null
182 }
183
184 glob() {
185     eval test -z '"${1#'"$2"'}"'
186 }
187
188 supported_hax_target() {
189     test "$hax" = "yes" || return 1
190     glob "$1" "*-softmmu" || return 1
191     case "${1%-softmmu}" in
192         i386|x86_64)
193             return 0
194         ;;
195     esac
196     return 1
197 }
198
199 supported_kvm_target() {
200     test "$kvm" = "yes" || return 1
201     glob "$1" "*-softmmu" || return 1
202     case "${1%-softmmu}:$cpu" in
203         arm:arm | aarch64:aarch64 | \
204         i386:i386 | i386:x86_64 | i386:x32 | \
205         x86_64:i386 | x86_64:x86_64 | x86_64:x32 | \
206         mips:mips | mipsel:mips | mips64:mips | mips64el:mips | \
207         ppc:ppc | ppc64:ppc | ppc:ppc64 | ppc64:ppc64 | ppc64:ppc64le | \
208         s390x:s390x)
209             return 0
210         ;;
211     esac
212     return 1
213 }
214
215 supported_xen_target() {
216     test "$xen" = "yes" || return 1
217     glob "$1" "*-softmmu" || return 1
218     # Only i386 and x86_64 provide the xenpv machine.
219     case "${1%-softmmu}" in
220         i386|x86_64)
221             return 0
222         ;;
223     esac
224     return 1
225 }
226
227 supported_hvf_target() {
228     test "$hvf" = "yes" || return 1
229     glob "$1" "*-softmmu" || return 1
230     case "${1%-softmmu}" in
231         x86_64)
232             return 0
233         ;;
234     esac
235     return 1
236 }
237
238 supported_whpx_target() {
239     test "$whpx" = "yes" || return 1
240     glob "$1" "*-softmmu" || return 1
241     case "${1%-softmmu}" in
242         i386|x86_64)
243             return 0
244         ;;
245     esac
246     return 1
247 }
248
249 supported_target() {
250     case "$1" in
251         *-softmmu)
252             ;;
253         *-linux-user)
254             if test "$linux" != "yes"; then
255                 print_error "Target '$target' is only available on a Linux host"
256                 return 1
257             fi
258             ;;
259         *-bsd-user)
260             if test "$bsd" != "yes"; then
261                 print_error "Target '$target' is only available on a BSD host"
262                 return 1
263             fi
264             ;;
265         *)
266             print_error "Invalid target name '$target'"
267             return 1
268             ;;
269     esac
270     test "$tcg" = "yes" && return 0
271     supported_kvm_target "$1" && return 0
272     supported_xen_target "$1" && return 0
273     supported_hax_target "$1" && return 0
274     supported_hvf_target "$1" && return 0
275     supported_whpx_target "$1" && return 0
276     print_error "TCG disabled, but hardware accelerator not available for '$target'"
277     return 1
278 }
279
280
281 ld_has() {
282     $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
283 }
284
285 # make source path absolute
286 source_path=$(cd "$(dirname -- "$0")"; pwd)
287
288 if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
289 then
290   error_exit "main directory cannot contain spaces nor colons"
291 fi
292
293 # default parameters
294 cpu=""
295 iasl="iasl"
296 interp_prefix="/usr/gnemul/qemu-%M"
297 static="no"
298 cross_prefix=""
299 audio_drv_list=""
300 block_drv_rw_whitelist=""
301 block_drv_ro_whitelist=""
302 host_cc="cc"
303 libs_cpu=""
304 libs_softmmu=""
305 libs_tools=""
306 audio_win_int=""
307 libs_qga=""
308 debug_info="yes"
309 stack_protector=""
310 safe_stack=""
311 use_containers="yes"
312 gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
313
314 if test -e "$source_path/.git"
315 then
316     git_update=yes
317     git_submodules="ui/keycodemapdb"
318     git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
319     git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
320 else
321     git_update=no
322     git_submodules=""
323
324     if ! test -f "$source_path/ui/keycodemapdb/README"
325     then
326         echo
327         echo "ERROR: missing file $source_path/ui/keycodemapdb/README"
328         echo
329         echo "This is not a GIT checkout but module content appears to"
330         echo "be missing. Do not use 'git archive' or GitHub download links"
331         echo "to acquire QEMU source archives. Non-GIT builds are only"
332         echo "supported with source archives linked from:"
333         echo
334         echo "  https://www.qemu.org/download/#source"
335         echo
336         echo "Developers working with GIT can use scripts/archive-source.sh"
337         echo "if they need to create valid source archives."
338         echo
339         exit 1
340     fi
341 fi
342 git="git"
343
344 # Don't accept a target_list environment variable.
345 unset target_list
346 unset target_list_exclude
347
348 # Default value for a variable defining feature "foo".
349 #  * foo="no"  feature will only be used if --enable-foo arg is given
350 #  * foo=""    feature will be searched for, and if found, will be used
351 #              unless --disable-foo is given
352 #  * foo="yes" this value will only be set by --enable-foo flag.
353 #              feature will searched for,
354 #              if not found, configure exits with error
355 #
356 # Always add --enable-foo and --disable-foo command line args.
357 # Distributions want to ensure that several features are compiled in, and it
358 # is impossible without a --enable-foo that exits if a feature is not found.
359
360 brlapi=""
361 curl=""
362 curses=""
363 docs=""
364 fdt=""
365 netmap="no"
366 sdl=""
367 sdl_image=""
368 virtfs=""
369 mpath=""
370 vnc="yes"
371 sparse="no"
372 vde=""
373 vnc_sasl=""
374 vnc_jpeg=""
375 vnc_png=""
376 xkbcommon=""
377 xen=""
378 xen_ctrl_version=""
379 xen_pci_passthrough=""
380 linux_aio=""
381 linux_io_uring=""
382 cap_ng=""
383 attr=""
384 libattr=""
385 xfs=""
386 tcg="yes"
387 membarrier=""
388 vhost_net=""
389 vhost_crypto=""
390 vhost_scsi=""
391 vhost_vsock=""
392 vhost_user=""
393 vhost_user_fs=""
394 kvm="no"
395 hax="no"
396 hvf="no"
397 whpx="no"
398 rdma=""
399 pvrdma=""
400 gprof="no"
401 debug_tcg="no"
402 debug="no"
403 sanitizers="no"
404 tsan="no"
405 fortify_source=""
406 strip_opt="yes"
407 tcg_interpreter="no"
408 bigendian="no"
409 mingw32="no"
410 gcov="no"
411 gcov_tool="gcov"
412 EXESUF=""
413 DSOSUF=".so"
414 LDFLAGS_SHARED="-shared"
415 modules="no"
416 module_upgrades="no"
417 prefix="/usr/local"
418 mandir="\${prefix}/share/man"
419 datadir="\${prefix}/share"
420 firmwarepath="\${prefix}/share/qemu-firmware"
421 qemu_docdir="\${prefix}/share/doc/qemu"
422 bindir="\${prefix}/bin"
423 libdir="\${prefix}/lib"
424 libexecdir="\${prefix}/libexec"
425 includedir="\${prefix}/include"
426 sysconfdir="\${prefix}/etc"
427 local_statedir="\${prefix}/var"
428 confsuffix="/qemu"
429 slirp=""
430 oss_lib=""
431 bsd="no"
432 linux="no"
433 solaris="no"
434 profiler="no"
435 cocoa="no"
436 softmmu="yes"
437 linux_user="no"
438 bsd_user="no"
439 blobs="yes"
440 edk2_blobs="no"
441 pkgversion=""
442 pie=""
443 qom_cast_debug="yes"
444 trace_backends="log"
445 trace_file="trace"
446 spice=""
447 rbd=""
448 smartcard=""
449 libusb=""
450 usb_redir=""
451 opengl=""
452 opengl_dmabuf="no"
453 cpuid_h="no"
454 avx2_opt=""
455 zlib="yes"
456 capstone=""
457 lzo=""
458 snappy=""
459 bzip2=""
460 lzfse=""
461 zstd=""
462 guest_agent=""
463 guest_agent_with_vss="no"
464 guest_agent_ntddscsi="no"
465 guest_agent_msi=""
466 vss_win32_sdk=""
467 win_sdk="no"
468 want_tools=""
469 libiscsi=""
470 libnfs=""
471 coroutine=""
472 coroutine_pool=""
473 debug_stack_usage="no"
474 crypto_afalg="no"
475 seccomp=""
476 glusterfs=""
477 glusterfs_xlator_opt="no"
478 glusterfs_discard="no"
479 glusterfs_fallocate="no"
480 glusterfs_zerofill="no"
481 glusterfs_ftruncate_has_stat="no"
482 glusterfs_iocb_has_stat="no"
483 gtk=""
484 gtk_gl="no"
485 tls_priority="NORMAL"
486 gnutls=""
487 nettle=""
488 nettle_xts="no"
489 gcrypt=""
490 gcrypt_hmac="no"
491 gcrypt_xts="no"
492 qemu_private_xts="yes"
493 auth_pam=""
494 vte=""
495 virglrenderer=""
496 tpm=""
497 libssh=""
498 live_block_migration="yes"
499 numa=""
500 tcmalloc="no"
501 jemalloc="no"
502 replication="yes"
503 bochs="yes"
504 cloop="yes"
505 dmg="yes"
506 qcow1="yes"
507 vdi="yes"
508 vvfat="yes"
509 qed="yes"
510 parallels="yes"
511 sheepdog="yes"
512 libxml2=""
513 debug_mutex="no"
514 libpmem=""
515 default_devices="yes"
516 plugins="no"
517 fuzzing="no"
518 rng_none="no"
519 secret_keyring=""
520 libdaxctl=""
521
522 supported_cpu="no"
523 supported_os="no"
524 bogus_os="no"
525 malloc_trim=""
526
527 # parse CC options first
528 for opt do
529   optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
530   case "$opt" in
531   --cross-prefix=*) cross_prefix="$optarg"
532   ;;
533   --cc=*) CC="$optarg"
534   ;;
535   --cxx=*) CXX="$optarg"
536   ;;
537   --cpu=*) cpu="$optarg"
538   ;;
539   --extra-cflags=*) QEMU_CFLAGS="$QEMU_CFLAGS $optarg"
540                     QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
541   ;;
542   --extra-cxxflags=*) QEMU_CXXFLAGS="$QEMU_CXXFLAGS $optarg"
543   ;;
544   --extra-ldflags=*) QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
545                      EXTRA_LDFLAGS="$optarg"
546   ;;
547   --enable-debug-info) debug_info="yes"
548   ;;
549   --disable-debug-info) debug_info="no"
550   ;;
551   --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
552   ;;
553   --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-flags-}; cc_arch=${cc_arch%%=*}
554                       eval "cross_cc_cflags_${cc_arch}=\$optarg"
555                       cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
556   ;;
557   --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
558                 cc_archs="$cc_archs $cc_arch"
559                 eval "cross_cc_${cc_arch}=\$optarg"
560                 cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
561   ;;
562   esac
563 done
564 # OS specific
565 # Using uname is really, really broken.  Once we have the right set of checks
566 # we can eliminate its usage altogether.
567
568 # Preferred compiler:
569 #  ${CC} (if set)
570 #  ${cross_prefix}gcc (if cross-prefix specified)
571 #  system compiler
572 if test -z "${CC}${cross_prefix}"; then
573   cc="$host_cc"
574 else
575   cc="${CC-${cross_prefix}gcc}"
576 fi
577
578 if test -z "${CXX}${cross_prefix}"; then
579   cxx="c++"
580 else
581   cxx="${CXX-${cross_prefix}g++}"
582 fi
583
584 ar="${AR-${cross_prefix}ar}"
585 as="${AS-${cross_prefix}as}"
586 ccas="${CCAS-$cc}"
587 cpp="${CPP-$cc -E}"
588 objcopy="${OBJCOPY-${cross_prefix}objcopy}"
589 ld="${LD-${cross_prefix}ld}"
590 ranlib="${RANLIB-${cross_prefix}ranlib}"
591 nm="${NM-${cross_prefix}nm}"
592 strip="${STRIP-${cross_prefix}strip}"
593 windres="${WINDRES-${cross_prefix}windres}"
594 pkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
595 query_pkg_config() {
596     "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
597 }
598 pkg_config=query_pkg_config
599 sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
600
601 # If the user hasn't specified ARFLAGS, default to 'rv', just as make does.
602 ARFLAGS="${ARFLAGS-rv}"
603
604 # default flags for all hosts
605 # We use -fwrapv to tell the compiler that we require a C dialect where
606 # left shift of signed integers is well defined and has the expected
607 # 2s-complement style results. (Both clang and gcc agree that it
608 # provides these semantics.)
609 QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv -std=gnu99 $QEMU_CFLAGS"
610 QEMU_CFLAGS="-Wall -Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
611 QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
612 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
613 QEMU_INCLUDES="-iquote . -iquote ${source_path} -iquote ${source_path}/accel/tcg -iquote ${source_path}/include"
614 QEMU_INCLUDES="$QEMU_INCLUDES -iquote ${source_path}/disas/libvixl"
615 if test "$debug_info" = "yes"; then
616     CFLAGS="-g $CFLAGS"
617 fi
618
619 # running configure in the source tree?
620 # we know that's the case if configure is there.
621 if test -f "./configure"; then
622     pwd_is_source_path="y"
623 else
624     pwd_is_source_path="n"
625 fi
626
627 check_define() {
628 cat > $TMPC <<EOF
629 #if !defined($1)
630 #error $1 not defined
631 #endif
632 int main(void) { return 0; }
633 EOF
634   compile_object
635 }
636
637 check_include() {
638 cat > $TMPC <<EOF
639 #include <$1>
640 int main(void) { return 0; }
641 EOF
642   compile_object
643 }
644
645 write_c_skeleton() {
646     cat > $TMPC <<EOF
647 int main(void) { return 0; }
648 EOF
649 }
650
651 write_c_fuzzer_skeleton() {
652     cat > $TMPC <<EOF
653 #include <stdint.h>
654 #include <sys/types.h>
655 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
656 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { return 0; }
657 EOF
658 }
659
660 if check_define __linux__ ; then
661   targetos="Linux"
662 elif check_define _WIN32 ; then
663   targetos='MINGW32'
664 elif check_define __OpenBSD__ ; then
665   targetos='OpenBSD'
666 elif check_define __sun__ ; then
667   targetos='SunOS'
668 elif check_define __HAIKU__ ; then
669   targetos='Haiku'
670 elif check_define __FreeBSD__ ; then
671   targetos='FreeBSD'
672 elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
673   targetos='GNU/kFreeBSD'
674 elif check_define __DragonFly__ ; then
675   targetos='DragonFly'
676 elif check_define __NetBSD__; then
677   targetos='NetBSD'
678 elif check_define __APPLE__; then
679   targetos='Darwin'
680 else
681   # This is a fatal error, but don't report it yet, because we
682   # might be going to just print the --help text, or it might
683   # be the result of a missing compiler.
684   targetos='bogus'
685   bogus_os='yes'
686 fi
687
688 # Some host OSes need non-standard checks for which CPU to use.
689 # Note that these checks are broken for cross-compilation: if you're
690 # cross-compiling to one of these OSes then you'll need to specify
691 # the correct CPU with the --cpu option.
692 case $targetos in
693 Darwin)
694   # on Leopard most of the system is 32-bit, so we have to ask the kernel if we can
695   # run 64-bit userspace code.
696   # If the user didn't specify a CPU explicitly and the kernel says this is
697   # 64 bit hw, then assume x86_64. Otherwise fall through to the usual detection code.
698   if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then
699     cpu="x86_64"
700   fi
701   ;;
702 SunOS)
703   # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
704   if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
705     cpu="x86_64"
706   fi
707 esac
708
709 if test ! -z "$cpu" ; then
710   # command line argument
711   :
712 elif check_define __i386__ ; then
713   cpu="i386"
714 elif check_define __x86_64__ ; then
715   if check_define __ILP32__ ; then
716     cpu="x32"
717   else
718     cpu="x86_64"
719   fi
720 elif check_define __sparc__ ; then
721   if check_define __arch64__ ; then
722     cpu="sparc64"
723   else
724     cpu="sparc"
725   fi
726 elif check_define _ARCH_PPC ; then
727   if check_define _ARCH_PPC64 ; then
728     if check_define _LITTLE_ENDIAN ; then
729       cpu="ppc64le"
730     else
731       cpu="ppc64"
732     fi
733   else
734     cpu="ppc"
735   fi
736 elif check_define __mips__ ; then
737   cpu="mips"
738 elif check_define __s390__ ; then
739   if check_define __s390x__ ; then
740     cpu="s390x"
741   else
742     cpu="s390"
743   fi
744 elif check_define __riscv ; then
745   if check_define _LP64 ; then
746     cpu="riscv64"
747   else
748     cpu="riscv32"
749   fi
750 elif check_define __arm__ ; then
751   cpu="arm"
752 elif check_define __aarch64__ ; then
753   cpu="aarch64"
754 else
755   cpu=$(uname -m)
756 fi
757
758 ARCH=
759 # Normalise host CPU name and set ARCH.
760 # Note that this case should only have supported host CPUs, not guests.
761 case "$cpu" in
762   ppc|ppc64|s390x|sparc64|x32|riscv32|riscv64)
763     supported_cpu="yes"
764   ;;
765   ppc64le)
766     ARCH="ppc64"
767     supported_cpu="yes"
768   ;;
769   i386|i486|i586|i686|i86pc|BePC)
770     cpu="i386"
771     supported_cpu="yes"
772   ;;
773   x86_64|amd64)
774     cpu="x86_64"
775     supported_cpu="yes"
776   ;;
777   armv*b|armv*l|arm)
778     cpu="arm"
779     supported_cpu="yes"
780   ;;
781   aarch64)
782     cpu="aarch64"
783     supported_cpu="yes"
784   ;;
785   mips*)
786     cpu="mips"
787     supported_cpu="yes"
788   ;;
789   sparc|sun4[cdmuv])
790     cpu="sparc"
791     supported_cpu="yes"
792   ;;
793   *)
794     # This will result in either an error or falling back to TCI later
795     ARCH=unknown
796   ;;
797 esac
798 if test -z "$ARCH"; then
799   ARCH="$cpu"
800 fi
801
802 # OS specific
803
804 # host *BSD for user mode
805 HOST_VARIANT_DIR=""
806
807 case $targetos in
808 MINGW32*)
809   mingw32="yes"
810   hax="yes"
811   vhost_user="no"
812   audio_possible_drivers="dsound sdl"
813   if check_include dsound.h; then
814     audio_drv_list="dsound"
815   else
816     audio_drv_list=""
817   fi
818   supported_os="yes"
819   pie="no"
820 ;;
821 GNU/kFreeBSD)
822   bsd="yes"
823   audio_drv_list="oss try-sdl"
824   audio_possible_drivers="oss sdl pa"
825 ;;
826 FreeBSD)
827   bsd="yes"
828   make="${MAKE-gmake}"
829   audio_drv_list="oss try-sdl"
830   audio_possible_drivers="oss sdl pa"
831   # needed for kinfo_getvmmap(3) in libutil.h
832   LIBS="-lutil $LIBS"
833   # needed for kinfo_getproc
834   libs_qga="-lutil $libs_qga"
835   netmap=""  # enable netmap autodetect
836   HOST_VARIANT_DIR="freebsd"
837   supported_os="yes"
838 ;;
839 DragonFly)
840   bsd="yes"
841   make="${MAKE-gmake}"
842   audio_drv_list="oss try-sdl"
843   audio_possible_drivers="oss sdl pa"
844   HOST_VARIANT_DIR="dragonfly"
845 ;;
846 NetBSD)
847   bsd="yes"
848   hax="yes"
849   make="${MAKE-gmake}"
850   audio_drv_list="oss try-sdl"
851   audio_possible_drivers="oss sdl"
852   oss_lib="-lossaudio"
853   HOST_VARIANT_DIR="netbsd"
854   supported_os="yes"
855 ;;
856 OpenBSD)
857   bsd="yes"
858   make="${MAKE-gmake}"
859   audio_drv_list="try-sdl"
860   audio_possible_drivers="sdl"
861   HOST_VARIANT_DIR="openbsd"
862   supported_os="yes"
863 ;;
864 Darwin)
865   bsd="yes"
866   darwin="yes"
867   hax="yes"
868   hvf="yes"
869   LDFLAGS_SHARED="-bundle -undefined dynamic_lookup"
870   if [ "$cpu" = "x86_64" ] ; then
871     QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
872     QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS"
873   fi
874   cocoa="yes"
875   audio_drv_list="coreaudio try-sdl"
876   audio_possible_drivers="coreaudio sdl"
877   QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit $QEMU_LDFLAGS"
878   libs_softmmu="-F/System/Library/Frameworks -framework Cocoa -framework IOKit $libs_softmmu"
879   # Disable attempts to use ObjectiveC features in os/object.h since they
880   # won't work when we're compiling with gcc as a C compiler.
881   QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
882   HOST_VARIANT_DIR="darwin"
883   supported_os="yes"
884 ;;
885 SunOS)
886   solaris="yes"
887   make="${MAKE-gmake}"
888   install="${INSTALL-ginstall}"
889   smbd="${SMBD-/usr/sfw/sbin/smbd}"
890   if test -f /usr/include/sys/soundcard.h ; then
891     audio_drv_list="oss try-sdl"
892   fi
893   audio_possible_drivers="oss sdl"
894 # needed for CMSG_ macros in sys/socket.h
895   QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
896 # needed for TIOCWIN* defines in termios.h
897   QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
898   QEMU_CFLAGS="-std=gnu99 $QEMU_CFLAGS"
899   solarisnetlibs="-lsocket -lnsl -lresolv"
900   LIBS="$solarisnetlibs $LIBS"
901   libs_qga="$solarisnetlibs $libs_qga"
902 ;;
903 Haiku)
904   haiku="yes"
905   QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -DBSD_SOURCE $QEMU_CFLAGS"
906   LIBS="-lposix_error_mapper -lnetwork -lbsd $LIBS"
907 ;;
908 Linux)
909   audio_drv_list="try-pa oss"
910   audio_possible_drivers="oss alsa sdl pa"
911   linux="yes"
912   linux_user="yes"
913   kvm="yes"
914   QEMU_INCLUDES="-isystem ${source_path}/linux-headers -I$PWD/linux-headers $QEMU_INCLUDES"
915   supported_os="yes"
916   libudev="yes"
917 ;;
918 esac
919
920 if [ "$bsd" = "yes" ] ; then
921   if [ "$darwin" != "yes" ] ; then
922     bsd_user="yes"
923   fi
924 fi
925
926 : ${make=${MAKE-make}}
927 : ${install=${INSTALL-install}}
928 # We prefer python 3.x. A bare 'python' is traditionally
929 # python 2.x, but some distros have it as python 3.x, so
930 # we check that too
931 python=
932 for binary in "${PYTHON-python3}" python
933 do
934     if has "$binary"
935     then
936         python=$(command -v "$binary")
937         break
938     fi
939 done
940
941 sphinx_build=
942 for binary in sphinx-build-3 sphinx-build
943 do
944     if has "$binary"
945     then
946         sphinx_build=$(command -v "$binary")
947         break
948     fi
949 done
950
951 # Check for ancillary tools used in testing
952 genisoimage=
953 for binary in genisoimage mkisofs
954 do
955     if has $binary
956     then
957         genisoimage=$(command -v "$binary")
958         break
959     fi
960 done
961
962 : ${smbd=${SMBD-/usr/sbin/smbd}}
963
964 # Default objcc to clang if available, otherwise use CC
965 if has clang; then
966   objcc=clang
967 else
968   objcc="$cc"
969 fi
970
971 if test "$mingw32" = "yes" ; then
972   EXESUF=".exe"
973   DSOSUF=".dll"
974   # MinGW needs -mthreads for TLS and macro _MT.
975   QEMU_CFLAGS="-mthreads $QEMU_CFLAGS"
976   LIBS="-lwinmm -lws2_32 $LIBS"
977   write_c_skeleton;
978   if compile_prog "" "-liberty" ; then
979     LIBS="-liberty $LIBS"
980   fi
981   prefix="c:/Program Files/QEMU"
982   mandir="\${prefix}"
983   datadir="\${prefix}"
984   qemu_docdir="\${prefix}"
985   bindir="\${prefix}"
986   sysconfdir="\${prefix}"
987   local_statedir=
988   confsuffix=""
989   libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi -lnetapi32 $libs_qga"
990 fi
991
992 werror=""
993
994 for opt do
995   optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
996   case "$opt" in
997   --help|-h) show_help=yes
998   ;;
999   --version|-V) exec cat $source_path/VERSION
1000   ;;
1001   --prefix=*) prefix="$optarg"
1002   ;;
1003   --interp-prefix=*) interp_prefix="$optarg"
1004   ;;
1005   --cross-prefix=*)
1006   ;;
1007   --cc=*)
1008   ;;
1009   --host-cc=*) host_cc="$optarg"
1010   ;;
1011   --cxx=*)
1012   ;;
1013   --iasl=*) iasl="$optarg"
1014   ;;
1015   --objcc=*) objcc="$optarg"
1016   ;;
1017   --make=*) make="$optarg"
1018   ;;
1019   --install=*) install="$optarg"
1020   ;;
1021   --python=*) python="$optarg"
1022   ;;
1023   --sphinx-build=*) sphinx_build="$optarg"
1024   ;;
1025   --gcov=*) gcov_tool="$optarg"
1026   ;;
1027   --smbd=*) smbd="$optarg"
1028   ;;
1029   --extra-cflags=*)
1030   ;;
1031   --extra-cxxflags=*)
1032   ;;
1033   --extra-ldflags=*)
1034   ;;
1035   --enable-debug-info)
1036   ;;
1037   --disable-debug-info)
1038   ;;
1039   --cross-cc-*)
1040   ;;
1041   --enable-modules)
1042       modules="yes"
1043   ;;
1044   --disable-modules)
1045       modules="no"
1046   ;;
1047   --disable-module-upgrades) module_upgrades="no"
1048   ;;
1049   --enable-module-upgrades) module_upgrades="yes"
1050   ;;
1051   --cpu=*)
1052   ;;
1053   --target-list=*) target_list="$optarg"
1054                    if test "$target_list_exclude"; then
1055                        error_exit "Can't mix --target-list with --target-list-exclude"
1056                    fi
1057   ;;
1058   --target-list-exclude=*) target_list_exclude="$optarg"
1059                    if test "$target_list"; then
1060                        error_exit "Can't mix --target-list-exclude with --target-list"
1061                    fi
1062   ;;
1063   --enable-trace-backends=*) trace_backends="$optarg"
1064   ;;
1065   # XXX: backwards compatibility
1066   --enable-trace-backend=*) trace_backends="$optarg"
1067   ;;
1068   --with-trace-file=*) trace_file="$optarg"
1069   ;;
1070   --with-default-devices) default_devices="yes"
1071   ;;
1072   --without-default-devices) default_devices="no"
1073   ;;
1074   --enable-gprof) gprof="yes"
1075   ;;
1076   --enable-gcov) gcov="yes"
1077   ;;
1078   --static)
1079     static="yes"
1080     QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
1081   ;;
1082   --mandir=*) mandir="$optarg"
1083   ;;
1084   --bindir=*) bindir="$optarg"
1085   ;;
1086   --libdir=*) libdir="$optarg"
1087   ;;
1088   --libexecdir=*) libexecdir="$optarg"
1089   ;;
1090   --includedir=*) includedir="$optarg"
1091   ;;
1092   --datadir=*) datadir="$optarg"
1093   ;;
1094   --with-confsuffix=*) confsuffix="$optarg"
1095   ;;
1096   --docdir=*) qemu_docdir="$optarg"
1097   ;;
1098   --sysconfdir=*) sysconfdir="$optarg"
1099   ;;
1100   --localstatedir=*) local_statedir="$optarg"
1101   ;;
1102   --firmwarepath=*) firmwarepath="$optarg"
1103   ;;
1104   --host=*|--build=*|\
1105   --disable-dependency-tracking|\
1106   --sbindir=*|--sharedstatedir=*|\
1107   --oldincludedir=*|--datarootdir=*|--infodir=*|--localedir=*|\
1108   --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
1109     # These switches are silently ignored, for compatibility with
1110     # autoconf-generated configure scripts. This allows QEMU's
1111     # configure to be used by RPM and similar macros that set
1112     # lots of directory switches by default.
1113   ;;
1114   --disable-sdl) sdl="no"
1115   ;;
1116   --enable-sdl) sdl="yes"
1117   ;;
1118   --disable-sdl-image) sdl_image="no"
1119   ;;
1120   --enable-sdl-image) sdl_image="yes"
1121   ;;
1122   --disable-qom-cast-debug) qom_cast_debug="no"
1123   ;;
1124   --enable-qom-cast-debug) qom_cast_debug="yes"
1125   ;;
1126   --disable-virtfs) virtfs="no"
1127   ;;
1128   --enable-virtfs) virtfs="yes"
1129   ;;
1130   --disable-mpath) mpath="no"
1131   ;;
1132   --enable-mpath) mpath="yes"
1133   ;;
1134   --disable-vnc) vnc="no"
1135   ;;
1136   --enable-vnc) vnc="yes"
1137   ;;
1138   --oss-lib=*) oss_lib="$optarg"
1139   ;;
1140   --audio-drv-list=*) audio_drv_list="$optarg"
1141   ;;
1142   --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
1143   ;;
1144   --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
1145   ;;
1146   --enable-debug-tcg) debug_tcg="yes"
1147   ;;
1148   --disable-debug-tcg) debug_tcg="no"
1149   ;;
1150   --enable-debug)
1151       # Enable debugging options that aren't excessively noisy
1152       debug_tcg="yes"
1153       debug_mutex="yes"
1154       debug="yes"
1155       strip_opt="no"
1156       fortify_source="no"
1157   ;;
1158   --enable-sanitizers) sanitizers="yes"
1159   ;;
1160   --disable-sanitizers) sanitizers="no"
1161   ;;
1162   --enable-tsan) tsan="yes"
1163   ;;
1164   --disable-tsan) tsan="no"
1165   ;;
1166   --enable-sparse) sparse="yes"
1167   ;;
1168   --disable-sparse) sparse="no"
1169   ;;
1170   --disable-strip) strip_opt="no"
1171   ;;
1172   --disable-vnc-sasl) vnc_sasl="no"
1173   ;;
1174   --enable-vnc-sasl) vnc_sasl="yes"
1175   ;;
1176   --disable-vnc-jpeg) vnc_jpeg="no"
1177   ;;
1178   --enable-vnc-jpeg) vnc_jpeg="yes"
1179   ;;
1180   --disable-vnc-png) vnc_png="no"
1181   ;;
1182   --enable-vnc-png) vnc_png="yes"
1183   ;;
1184   --disable-slirp) slirp="no"
1185   ;;
1186   --enable-slirp=git) slirp="git"
1187   ;;
1188   --enable-slirp=system) slirp="system"
1189   ;;
1190   --disable-vde) vde="no"
1191   ;;
1192   --enable-vde) vde="yes"
1193   ;;
1194   --disable-netmap) netmap="no"
1195   ;;
1196   --enable-netmap) netmap="yes"
1197   ;;
1198   --disable-xen) xen="no"
1199   ;;
1200   --enable-xen) xen="yes"
1201   ;;
1202   --disable-xen-pci-passthrough) xen_pci_passthrough="no"
1203   ;;
1204   --enable-xen-pci-passthrough) xen_pci_passthrough="yes"
1205   ;;
1206   --disable-brlapi) brlapi="no"
1207   ;;
1208   --enable-brlapi) brlapi="yes"
1209   ;;
1210   --disable-kvm) kvm="no"
1211   ;;
1212   --enable-kvm) kvm="yes"
1213   ;;
1214   --disable-hax) hax="no"
1215   ;;
1216   --enable-hax) hax="yes"
1217   ;;
1218   --disable-hvf) hvf="no"
1219   ;;
1220   --enable-hvf) hvf="yes"
1221   ;;
1222   --disable-whpx) whpx="no"
1223   ;;
1224   --enable-whpx) whpx="yes"
1225   ;;
1226   --disable-tcg-interpreter) tcg_interpreter="no"
1227   ;;
1228   --enable-tcg-interpreter) tcg_interpreter="yes"
1229   ;;
1230   --disable-cap-ng)  cap_ng="no"
1231   ;;
1232   --enable-cap-ng) cap_ng="yes"
1233   ;;
1234   --disable-tcg) tcg="no"
1235   ;;
1236   --enable-tcg) tcg="yes"
1237   ;;
1238   --disable-malloc-trim) malloc_trim="no"
1239   ;;
1240   --enable-malloc-trim) malloc_trim="yes"
1241   ;;
1242   --disable-spice) spice="no"
1243   ;;
1244   --enable-spice) spice="yes"
1245   ;;
1246   --disable-libiscsi) libiscsi="no"
1247   ;;
1248   --enable-libiscsi) libiscsi="yes"
1249   ;;
1250   --disable-libnfs) libnfs="no"
1251   ;;
1252   --enable-libnfs) libnfs="yes"
1253   ;;
1254   --enable-profiler) profiler="yes"
1255   ;;
1256   --disable-cocoa) cocoa="no"
1257   ;;
1258   --enable-cocoa)
1259       cocoa="yes" ;
1260       audio_drv_list="coreaudio $(echo $audio_drv_list | sed s,coreaudio,,g)"
1261   ;;
1262   --disable-system) softmmu="no"
1263   ;;
1264   --enable-system) softmmu="yes"
1265   ;;
1266   --disable-user)
1267       linux_user="no" ;
1268       bsd_user="no" ;
1269   ;;
1270   --enable-user) ;;
1271   --disable-linux-user) linux_user="no"
1272   ;;
1273   --enable-linux-user) linux_user="yes"
1274   ;;
1275   --disable-bsd-user) bsd_user="no"
1276   ;;
1277   --enable-bsd-user) bsd_user="yes"
1278   ;;
1279   --enable-pie) pie="yes"
1280   ;;
1281   --disable-pie) pie="no"
1282   ;;
1283   --enable-werror) werror="yes"
1284   ;;
1285   --disable-werror) werror="no"
1286   ;;
1287   --enable-stack-protector) stack_protector="yes"
1288   ;;
1289   --disable-stack-protector) stack_protector="no"
1290   ;;
1291   --enable-safe-stack) safe_stack="yes"
1292   ;;
1293   --disable-safe-stack) safe_stack="no"
1294   ;;
1295   --disable-curses) curses="no"
1296   ;;
1297   --enable-curses) curses="yes"
1298   ;;
1299   --disable-iconv) iconv="no"
1300   ;;
1301   --enable-iconv) iconv="yes"
1302   ;;
1303   --disable-curl) curl="no"
1304   ;;
1305   --enable-curl) curl="yes"
1306   ;;
1307   --disable-fdt) fdt="no"
1308   ;;
1309   --enable-fdt) fdt="yes"
1310   ;;
1311   --disable-linux-aio) linux_aio="no"
1312   ;;
1313   --enable-linux-aio) linux_aio="yes"
1314   ;;
1315   --disable-linux-io-uring) linux_io_uring="no"
1316   ;;
1317   --enable-linux-io-uring) linux_io_uring="yes"
1318   ;;
1319   --disable-attr) attr="no"
1320   ;;
1321   --enable-attr) attr="yes"
1322   ;;
1323   --disable-membarrier) membarrier="no"
1324   ;;
1325   --enable-membarrier) membarrier="yes"
1326   ;;
1327   --disable-blobs) blobs="no"
1328   ;;
1329   --with-pkgversion=*) pkgversion="$optarg"
1330   ;;
1331   --with-coroutine=*) coroutine="$optarg"
1332   ;;
1333   --disable-coroutine-pool) coroutine_pool="no"
1334   ;;
1335   --enable-coroutine-pool) coroutine_pool="yes"
1336   ;;
1337   --enable-debug-stack-usage) debug_stack_usage="yes"
1338   ;;
1339   --enable-crypto-afalg) crypto_afalg="yes"
1340   ;;
1341   --disable-crypto-afalg) crypto_afalg="no"
1342   ;;
1343   --disable-docs) docs="no"
1344   ;;
1345   --enable-docs) docs="yes"
1346   ;;
1347   --disable-vhost-net) vhost_net="no"
1348   ;;
1349   --enable-vhost-net) vhost_net="yes"
1350   ;;
1351   --disable-vhost-crypto) vhost_crypto="no"
1352   ;;
1353   --enable-vhost-crypto) vhost_crypto="yes"
1354   ;;
1355   --disable-vhost-scsi) vhost_scsi="no"
1356   ;;
1357   --enable-vhost-scsi) vhost_scsi="yes"
1358   ;;
1359   --disable-vhost-vsock) vhost_vsock="no"
1360   ;;
1361   --enable-vhost-vsock) vhost_vsock="yes"
1362   ;;
1363   --disable-vhost-user-fs) vhost_user_fs="no"
1364   ;;
1365   --enable-vhost-user-fs) vhost_user_fs="yes"
1366   ;;
1367   --disable-opengl) opengl="no"
1368   ;;
1369   --enable-opengl) opengl="yes"
1370   ;;
1371   --disable-rbd) rbd="no"
1372   ;;
1373   --enable-rbd) rbd="yes"
1374   ;;
1375   --disable-xfsctl) xfs="no"
1376   ;;
1377   --enable-xfsctl) xfs="yes"
1378   ;;
1379   --disable-smartcard) smartcard="no"
1380   ;;
1381   --enable-smartcard) smartcard="yes"
1382   ;;
1383   --disable-libusb) libusb="no"
1384   ;;
1385   --enable-libusb) libusb="yes"
1386   ;;
1387   --disable-usb-redir) usb_redir="no"
1388   ;;
1389   --enable-usb-redir) usb_redir="yes"
1390   ;;
1391   --disable-zlib-test) zlib="no"
1392   ;;
1393   --disable-lzo) lzo="no"
1394   ;;
1395   --enable-lzo) lzo="yes"
1396   ;;
1397   --disable-snappy) snappy="no"
1398   ;;
1399   --enable-snappy) snappy="yes"
1400   ;;
1401   --disable-bzip2) bzip2="no"
1402   ;;
1403   --enable-bzip2) bzip2="yes"
1404   ;;
1405   --enable-lzfse) lzfse="yes"
1406   ;;
1407   --disable-lzfse) lzfse="no"
1408   ;;
1409   --disable-zstd) zstd="no"
1410   ;;
1411   --enable-zstd) zstd="yes"
1412   ;;
1413   --enable-guest-agent) guest_agent="yes"
1414   ;;
1415   --disable-guest-agent) guest_agent="no"
1416   ;;
1417   --enable-guest-agent-msi) guest_agent_msi="yes"
1418   ;;
1419   --disable-guest-agent-msi) guest_agent_msi="no"
1420   ;;
1421   --with-vss-sdk) vss_win32_sdk=""
1422   ;;
1423   --with-vss-sdk=*) vss_win32_sdk="$optarg"
1424   ;;
1425   --without-vss-sdk) vss_win32_sdk="no"
1426   ;;
1427   --with-win-sdk) win_sdk=""
1428   ;;
1429   --with-win-sdk=*) win_sdk="$optarg"
1430   ;;
1431   --without-win-sdk) win_sdk="no"
1432   ;;
1433   --enable-tools) want_tools="yes"
1434   ;;
1435   --disable-tools) want_tools="no"
1436   ;;
1437   --enable-seccomp) seccomp="yes"
1438   ;;
1439   --disable-seccomp) seccomp="no"
1440   ;;
1441   --disable-glusterfs) glusterfs="no"
1442   ;;
1443   --disable-avx2) avx2_opt="no"
1444   ;;
1445   --enable-avx2) avx2_opt="yes"
1446   ;;
1447   --disable-avx512f) avx512f_opt="no"
1448   ;;
1449   --enable-avx512f) avx512f_opt="yes"
1450   ;;
1451
1452   --enable-glusterfs) glusterfs="yes"
1453   ;;
1454   --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
1455       echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
1456   ;;
1457   --enable-vhdx|--disable-vhdx)
1458       echo "$0: $opt is obsolete, VHDX driver is always built" >&2
1459   ;;
1460   --enable-uuid|--disable-uuid)
1461       echo "$0: $opt is obsolete, UUID support is always built" >&2
1462   ;;
1463   --disable-gtk) gtk="no"
1464   ;;
1465   --enable-gtk) gtk="yes"
1466   ;;
1467   --tls-priority=*) tls_priority="$optarg"
1468   ;;
1469   --disable-gnutls) gnutls="no"
1470   ;;
1471   --enable-gnutls) gnutls="yes"
1472   ;;
1473   --disable-nettle) nettle="no"
1474   ;;
1475   --enable-nettle) nettle="yes"
1476   ;;
1477   --disable-gcrypt) gcrypt="no"
1478   ;;
1479   --enable-gcrypt) gcrypt="yes"
1480   ;;
1481   --disable-auth-pam) auth_pam="no"
1482   ;;
1483   --enable-auth-pam) auth_pam="yes"
1484   ;;
1485   --enable-rdma) rdma="yes"
1486   ;;
1487   --disable-rdma) rdma="no"
1488   ;;
1489   --enable-pvrdma) pvrdma="yes"
1490   ;;
1491   --disable-pvrdma) pvrdma="no"
1492   ;;
1493   --disable-vte) vte="no"
1494   ;;
1495   --enable-vte) vte="yes"
1496   ;;
1497   --disable-virglrenderer) virglrenderer="no"
1498   ;;
1499   --enable-virglrenderer) virglrenderer="yes"
1500   ;;
1501   --disable-tpm) tpm="no"
1502   ;;
1503   --enable-tpm) tpm="yes"
1504   ;;
1505   --disable-libssh) libssh="no"
1506   ;;
1507   --enable-libssh) libssh="yes"
1508   ;;
1509   --disable-live-block-migration) live_block_migration="no"
1510   ;;
1511   --enable-live-block-migration) live_block_migration="yes"
1512   ;;
1513   --disable-numa) numa="no"
1514   ;;
1515   --enable-numa) numa="yes"
1516   ;;
1517   --disable-libxml2) libxml2="no"
1518   ;;
1519   --enable-libxml2) libxml2="yes"
1520   ;;
1521   --disable-tcmalloc) tcmalloc="no"
1522   ;;
1523   --enable-tcmalloc) tcmalloc="yes"
1524   ;;
1525   --disable-jemalloc) jemalloc="no"
1526   ;;
1527   --enable-jemalloc) jemalloc="yes"
1528   ;;
1529   --disable-replication) replication="no"
1530   ;;
1531   --enable-replication) replication="yes"
1532   ;;
1533   --disable-bochs) bochs="no"
1534   ;;
1535   --enable-bochs) bochs="yes"
1536   ;;
1537   --disable-cloop) cloop="no"
1538   ;;
1539   --enable-cloop) cloop="yes"
1540   ;;
1541   --disable-dmg) dmg="no"
1542   ;;
1543   --enable-dmg) dmg="yes"
1544   ;;
1545   --disable-qcow1) qcow1="no"
1546   ;;
1547   --enable-qcow1) qcow1="yes"
1548   ;;
1549   --disable-vdi) vdi="no"
1550   ;;
1551   --enable-vdi) vdi="yes"
1552   ;;
1553   --disable-vvfat) vvfat="no"
1554   ;;
1555   --enable-vvfat) vvfat="yes"
1556   ;;
1557   --disable-qed) qed="no"
1558   ;;
1559   --enable-qed) qed="yes"
1560   ;;
1561   --disable-parallels) parallels="no"
1562   ;;
1563   --enable-parallels) parallels="yes"
1564   ;;
1565   --disable-sheepdog) sheepdog="no"
1566   ;;
1567   --enable-sheepdog) sheepdog="yes"
1568   ;;
1569   --disable-vhost-user) vhost_user="no"
1570   ;;
1571   --enable-vhost-user) vhost_user="yes"
1572   ;;
1573   --disable-vhost-vdpa) vhost_vdpa="no"
1574   ;;
1575   --enable-vhost-vdpa) vhost_vdpa="yes"
1576   ;;
1577   --disable-vhost-kernel) vhost_kernel="no"
1578   ;;
1579   --enable-vhost-kernel) vhost_kernel="yes"
1580   ;;
1581   --disable-capstone) capstone="no"
1582   ;;
1583   --enable-capstone) capstone="yes"
1584   ;;
1585   --enable-capstone=git) capstone="git"
1586   ;;
1587   --enable-capstone=system) capstone="system"
1588   ;;
1589   --with-git=*) git="$optarg"
1590   ;;
1591   --enable-git-update) git_update=yes
1592   ;;
1593   --disable-git-update) git_update=no
1594   ;;
1595   --enable-debug-mutex) debug_mutex=yes
1596   ;;
1597   --disable-debug-mutex) debug_mutex=no
1598   ;;
1599   --enable-libpmem) libpmem=yes
1600   ;;
1601   --disable-libpmem) libpmem=no
1602   ;;
1603   --enable-xkbcommon) xkbcommon=yes
1604   ;;
1605   --disable-xkbcommon) xkbcommon=no
1606   ;;
1607   --enable-plugins) plugins="yes"
1608   ;;
1609   --disable-plugins) plugins="no"
1610   ;;
1611   --enable-containers) use_containers="yes"
1612   ;;
1613   --disable-containers) use_containers="no"
1614   ;;
1615   --enable-fuzzing) fuzzing=yes
1616   ;;
1617   --disable-fuzzing) fuzzing=no
1618   ;;
1619   --gdb=*) gdb_bin="$optarg"
1620   ;;
1621   --enable-rng-none) rng_none=yes
1622   ;;
1623   --disable-rng-none) rng_none=no
1624   ;;
1625   --enable-keyring) secret_keyring="yes"
1626   ;;
1627   --disable-keyring) secret_keyring="no"
1628   ;;
1629   --enable-libdaxctl) libdaxctl=yes
1630   ;;
1631   --disable-libdaxctl) libdaxctl=no
1632   ;;
1633   *)
1634       echo "ERROR: unknown option $opt"
1635       echo "Try '$0 --help' for more information"
1636       exit 1
1637   ;;
1638   esac
1639 done
1640
1641 case "$cpu" in
1642     ppc)
1643            CPU_CFLAGS="-m32"
1644            QEMU_LDFLAGS="-m32 $QEMU_LDFLAGS"
1645            ;;
1646     ppc64)
1647            CPU_CFLAGS="-m64"
1648            QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1649            ;;
1650     sparc)
1651            CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc"
1652            QEMU_LDFLAGS="-m32 -mv8plus $QEMU_LDFLAGS"
1653            ;;
1654     sparc64)
1655            CPU_CFLAGS="-m64 -mcpu=ultrasparc"
1656            QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1657            ;;
1658     s390)
1659            CPU_CFLAGS="-m31"
1660            QEMU_LDFLAGS="-m31 $QEMU_LDFLAGS"
1661            ;;
1662     s390x)
1663            CPU_CFLAGS="-m64"
1664            QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1665            ;;
1666     i386)
1667            CPU_CFLAGS="-m32"
1668            QEMU_LDFLAGS="-m32 $QEMU_LDFLAGS"
1669            ;;
1670     x86_64)
1671            # ??? Only extremely old AMD cpus do not have cmpxchg16b.
1672            # If we truly care, we should simply detect this case at
1673            # runtime and generate the fallback to serial emulation.
1674            CPU_CFLAGS="-m64 -mcx16"
1675            QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1676            ;;
1677     x32)
1678            CPU_CFLAGS="-mx32"
1679            QEMU_LDFLAGS="-mx32 $QEMU_LDFLAGS"
1680            ;;
1681     # No special flags required for other host CPUs
1682 esac
1683
1684 eval "cross_cc_${cpu}=\$host_cc"
1685 cross_cc_vars="$cross_cc_vars cross_cc_${cpu}"
1686 QEMU_CFLAGS="$CPU_CFLAGS $QEMU_CFLAGS"
1687
1688 # For user-mode emulation the host arch has to be one we explicitly
1689 # support, even if we're using TCI.
1690 if [ "$ARCH" = "unknown" ]; then
1691   bsd_user="no"
1692   linux_user="no"
1693 fi
1694
1695 if [ "$bsd_user" = "no" -a "$linux_user" = "no" -a "$softmmu" = "no" ] ; then
1696   tcg="no"
1697 fi
1698
1699 default_target_list=""
1700
1701 mak_wilds=""
1702
1703 if [ "$softmmu" = "yes" ]; then
1704     mak_wilds="${mak_wilds} $source_path/default-configs/*-softmmu.mak"
1705 fi
1706 if [ "$linux_user" = "yes" ]; then
1707     mak_wilds="${mak_wilds} $source_path/default-configs/*-linux-user.mak"
1708 fi
1709 if [ "$bsd_user" = "yes" ]; then
1710     mak_wilds="${mak_wilds} $source_path/default-configs/*-bsd-user.mak"
1711 fi
1712
1713 if test -z "$target_list_exclude"; then
1714     for config in $mak_wilds; do
1715         default_target_list="${default_target_list} $(basename "$config" .mak)"
1716     done
1717 else
1718     exclude_list=$(echo "$target_list_exclude" | sed -e 's/,/ /g')
1719     for config in $mak_wilds; do
1720         target="$(basename "$config" .mak)"
1721         exclude="no"
1722         for excl in $exclude_list; do
1723             if test "$excl" = "$target"; then
1724                 exclude="yes"
1725                 break;
1726             fi
1727         done
1728         if test "$exclude" = "no"; then
1729             default_target_list="${default_target_list} $target"
1730         fi
1731     done
1732 fi
1733
1734 # Enumerate public trace backends for --help output
1735 trace_backend_list=$(echo $(grep -le '^PUBLIC = True$' "$source_path"/scripts/tracetool/backend/*.py | sed -e 's/^.*\/\(.*\)\.py$/\1/'))
1736
1737 if test x"$show_help" = x"yes" ; then
1738 cat << EOF
1739
1740 Usage: configure [options]
1741 Options: [defaults in brackets after descriptions]
1742
1743 Standard options:
1744   --help                   print this message
1745   --prefix=PREFIX          install in PREFIX [$prefix]
1746   --interp-prefix=PREFIX   where to find shared libraries, etc.
1747                            use %M for cpu name [$interp_prefix]
1748   --target-list=LIST       set target list (default: build everything)
1749 $(echo Available targets: $default_target_list | \
1750   fold -s -w 53 | sed -e 's/^/                           /')
1751   --target-list-exclude=LIST exclude a set of targets from the default target-list
1752
1753 Advanced options (experts only):
1754   --cross-prefix=PREFIX    use PREFIX for compile tools [$cross_prefix]
1755   --cc=CC                  use C compiler CC [$cc]
1756   --iasl=IASL              use ACPI compiler IASL [$iasl]
1757   --host-cc=CC             use C compiler CC [$host_cc] for code run at
1758                            build time
1759   --cxx=CXX                use C++ compiler CXX [$cxx]
1760   --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
1761   --extra-cflags=CFLAGS    append extra C compiler flags QEMU_CFLAGS
1762   --extra-cxxflags=CXXFLAGS append extra C++ compiler flags QEMU_CXXFLAGS
1763   --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
1764   --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
1765   --cross-cc-flags-ARCH=   use compiler flags when building ARCH guest tests
1766   --make=MAKE              use specified make [$make]
1767   --install=INSTALL        use specified install [$install]
1768   --python=PYTHON          use specified python [$python]
1769   --sphinx-build=SPHINX    use specified sphinx-build [$sphinx_build]
1770   --smbd=SMBD              use specified smbd [$smbd]
1771   --with-git=GIT           use specified git [$git]
1772   --static                 enable static build [$static]
1773   --mandir=PATH            install man pages in PATH
1774   --datadir=PATH           install firmware in PATH$confsuffix
1775   --docdir=PATH            install documentation in PATH$confsuffix
1776   --bindir=PATH            install binaries in PATH
1777   --libdir=PATH            install libraries in PATH
1778   --libexecdir=PATH        install helper binaries in PATH
1779   --sysconfdir=PATH        install config in PATH$confsuffix
1780   --localstatedir=PATH     install local state in PATH (set at runtime on win32)
1781   --firmwarepath=PATH      search PATH for firmware files
1782   --efi-aarch64=PATH       PATH of efi file to use for aarch64 VMs.
1783   --with-confsuffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir [$confsuffix]
1784   --with-pkgversion=VERS   use specified string as sub-version of the package
1785   --enable-debug           enable common debug build options
1786   --enable-sanitizers      enable default sanitizers
1787   --enable-tsan            enable thread sanitizer
1788   --disable-strip          disable stripping binaries
1789   --disable-werror         disable compilation abort on warning
1790   --disable-stack-protector disable compiler-provided stack protection
1791   --audio-drv-list=LIST    set audio drivers list:
1792                            Available drivers: $audio_possible_drivers
1793   --block-drv-whitelist=L  Same as --block-drv-rw-whitelist=L
1794   --block-drv-rw-whitelist=L
1795                            set block driver read-write whitelist
1796                            (affects only QEMU, not qemu-img)
1797   --block-drv-ro-whitelist=L
1798                            set block driver read-only whitelist
1799                            (affects only QEMU, not qemu-img)
1800   --enable-trace-backends=B Set trace backend
1801                            Available backends: $trace_backend_list
1802   --with-trace-file=NAME   Full PATH,NAME of file to store traces
1803                            Default:trace-<pid>
1804   --disable-slirp          disable SLIRP userspace network connectivity
1805   --enable-tcg-interpreter enable TCG with bytecode interpreter (TCI)
1806   --enable-malloc-trim     enable libc malloc_trim() for memory optimization
1807   --oss-lib                path to OSS library
1808   --cpu=CPU                Build for host CPU [$cpu]
1809   --with-coroutine=BACKEND coroutine backend. Supported options:
1810                            ucontext, sigaltstack, windows
1811   --enable-gcov            enable test coverage analysis with gcov
1812   --gcov=GCOV              use specified gcov [$gcov_tool]
1813   --disable-blobs          disable installing provided firmware blobs
1814   --with-vss-sdk=SDK-path  enable Windows VSS support in QEMU Guest Agent
1815   --with-win-sdk=SDK-path  path to Windows Platform SDK (to build VSS .tlb)
1816   --tls-priority           default TLS protocol/cipher priority string
1817   --enable-gprof           QEMU profiling with gprof
1818   --enable-profiler        profiler support
1819   --enable-debug-stack-usage
1820                            track the maximum stack usage of stacks created by qemu_alloc_stack
1821   --enable-plugins
1822                            enable plugins via shared library loading
1823   --disable-containers     don't use containers for cross-building
1824   --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
1825
1826 Optional features, enabled with --enable-FEATURE and
1827 disabled with --disable-FEATURE, default is enabled if available:
1828
1829   system          all system emulation targets
1830   user            supported user emulation targets
1831   linux-user      all linux usermode emulation targets
1832   bsd-user        all BSD usermode emulation targets
1833   docs            build documentation
1834   guest-agent     build the QEMU Guest Agent
1835   guest-agent-msi build guest agent Windows MSI installation package
1836   pie             Position Independent Executables
1837   modules         modules support (non-Windows)
1838   module-upgrades try to load modules from alternate paths for upgrades
1839   debug-tcg       TCG debugging (default is disabled)
1840   debug-info      debugging information
1841   sparse          sparse checker
1842   safe-stack      SafeStack Stack Smash Protection. Depends on
1843                   clang/llvm >= 3.7 and requires coroutine backend ucontext.
1844
1845   gnutls          GNUTLS cryptography support
1846   nettle          nettle cryptography support
1847   gcrypt          libgcrypt cryptography support
1848   auth-pam        PAM access control
1849   sdl             SDL UI
1850   sdl-image       SDL Image support for icons
1851   gtk             gtk UI
1852   vte             vte support for the gtk UI
1853   curses          curses UI
1854   iconv           font glyph conversion support
1855   vnc             VNC UI support
1856   vnc-sasl        SASL encryption for VNC server
1857   vnc-jpeg        JPEG lossy compression for VNC server
1858   vnc-png         PNG compression for VNC server
1859   cocoa           Cocoa UI (Mac OS X only)
1860   virtfs          VirtFS
1861   mpath           Multipath persistent reservation passthrough
1862   xen             xen backend driver support
1863   xen-pci-passthrough    PCI passthrough support for Xen
1864   brlapi          BrlAPI (Braile)
1865   curl            curl connectivity
1866   membarrier      membarrier system call (for Linux 4.14+ or Windows)
1867   fdt             fdt device tree
1868   kvm             KVM acceleration support
1869   hax             HAX acceleration support
1870   hvf             Hypervisor.framework acceleration support
1871   whpx            Windows Hypervisor Platform acceleration support
1872   rdma            Enable RDMA-based migration
1873   pvrdma          Enable PVRDMA support
1874   vde             support for vde network
1875   netmap          support for netmap network
1876   linux-aio       Linux AIO support
1877   linux-io-uring  Linux io_uring support
1878   cap-ng          libcap-ng support
1879   attr            attr and xattr support
1880   vhost-net       vhost-net kernel acceleration support
1881   vhost-vsock     virtio sockets device support
1882   vhost-scsi      vhost-scsi kernel target support
1883   vhost-crypto    vhost-user-crypto backend support
1884   vhost-kernel    vhost kernel backend support
1885   vhost-user      vhost-user backend support
1886   vhost-vdpa      vhost-vdpa kernel backend support
1887   spice           spice
1888   rbd             rados block device (rbd)
1889   libiscsi        iscsi support
1890   libnfs          nfs support
1891   smartcard       smartcard support (libcacard)
1892   libusb          libusb (for usb passthrough)
1893   live-block-migration   Block migration in the main migration stream
1894   usb-redir       usb network redirection support
1895   lzo             support of lzo compression library
1896   snappy          support of snappy compression library
1897   bzip2           support of bzip2 compression library
1898                   (for reading bzip2-compressed dmg images)
1899   lzfse           support of lzfse compression library
1900                   (for reading lzfse-compressed dmg images)
1901   zstd            support for zstd compression library
1902                   (for migration compression and qcow2 cluster compression)
1903   seccomp         seccomp support
1904   coroutine-pool  coroutine freelist (better performance)
1905   glusterfs       GlusterFS backend
1906   tpm             TPM support
1907   libssh          ssh block device support
1908   numa            libnuma support
1909   libxml2         for Parallels image format
1910   tcmalloc        tcmalloc support
1911   jemalloc        jemalloc support
1912   avx2            AVX2 optimization support
1913   avx512f         AVX512F optimization support
1914   replication     replication support
1915   opengl          opengl support
1916   virglrenderer   virgl rendering support
1917   xfsctl          xfsctl support
1918   qom-cast-debug  cast debugging support
1919   tools           build qemu-io, qemu-nbd and qemu-img tools
1920   bochs           bochs image format support
1921   cloop           cloop image format support
1922   dmg             dmg image format support
1923   qcow1           qcow v1 image format support
1924   vdi             vdi image format support
1925   vvfat           vvfat image format support
1926   qed             qed image format support
1927   parallels       parallels image format support
1928   sheepdog        sheepdog block driver support
1929   crypto-afalg    Linux AF_ALG crypto backend driver
1930   capstone        capstone disassembler support
1931   debug-mutex     mutex debugging support
1932   libpmem         libpmem support
1933   xkbcommon       xkbcommon support
1934   rng-none        dummy RNG, avoid using /dev/(u)random and getrandom()
1935   libdaxctl       libdaxctl support
1936
1937 NOTE: The object files are built at the place where configure is launched
1938 EOF
1939 exit 0
1940 fi
1941
1942 # Remove old dependency files to make sure that they get properly regenerated
1943 rm -f */config-devices.mak.d
1944
1945 # Remove syscall_nr.h to be sure they will be regenerated in the build
1946 # directory, not in the source directory
1947 for arch in alpha hppa m68k xtensa sh4 microblaze arm ppc s390x sparc sparc64 \
1948     i386 x86_64 mips mips64 ; do
1949     # remove the file if it has been generated in the source directory
1950     rm -f "${source_path}/linux-user/${arch}/syscall_nr.h"
1951     # remove the dependency files
1952     for target in ${arch}*-linux-user ; do
1953         test -d "${target}" && find "${target}" -type f -name "*.d" \
1954              -exec grep -q "${source_path}/linux-user/${arch}/syscall_nr.h" {} \; \
1955              -print | while read file ; do rm "${file}" "${file%.d}.o" ; done
1956     done
1957 done
1958
1959 if test -z "$python"
1960 then
1961     error_exit "Python not found. Use --python=/path/to/python"
1962 fi
1963
1964 # Note that if the Python conditional here evaluates True we will exit
1965 # with status 1 which is a shell 'false' value.
1966 if ! $python -c 'import sys; sys.exit(sys.version_info < (3,5))'; then
1967   error_exit "Cannot use '$python', Python >= 3.5 is required." \
1968       "Use --python=/path/to/python to specify a supported Python."
1969 fi
1970
1971 # Preserve python version since some functionality is dependent on it
1972 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)
1973
1974 # Suppress writing compiled files
1975 python="$python -B"
1976
1977 # Check that the C compiler works. Doing this here before testing
1978 # the host CPU ensures that we had a valid CC to autodetect the
1979 # $cpu var (and we should bail right here if that's not the case).
1980 # It also allows the help message to be printed without a CC.
1981 write_c_skeleton;
1982 if compile_object ; then
1983   : C compiler works ok
1984 else
1985     error_exit "\"$cc\" either does not exist or does not work"
1986 fi
1987 if ! compile_prog ; then
1988     error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
1989 fi
1990
1991 # Now we have handled --enable-tcg-interpreter and know we're not just
1992 # printing the help message, bail out if the host CPU isn't supported.
1993 if test "$ARCH" = "unknown"; then
1994     if test "$tcg_interpreter" = "yes" ; then
1995         echo "Unsupported CPU = $cpu, will use TCG with TCI (experimental)"
1996     else
1997         error_exit "Unsupported CPU = $cpu, try --enable-tcg-interpreter"
1998     fi
1999 fi
2000
2001 # Consult white-list to determine whether to enable werror
2002 # by default.  Only enable by default for git builds
2003 if test -z "$werror" ; then
2004     if test -e "$source_path/.git" && \
2005         { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
2006         werror="yes"
2007     else
2008         werror="no"
2009     fi
2010 fi
2011
2012 if test "$bogus_os" = "yes"; then
2013     # Now that we know that we're not printing the help and that
2014     # the compiler works (so the results of the check_defines we used
2015     # to identify the OS are reliable), if we didn't recognize the
2016     # host OS we should stop now.
2017     error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
2018 fi
2019
2020 # Check whether the compiler matches our minimum requirements:
2021 cat > $TMPC << EOF
2022 #if defined(__clang_major__) && defined(__clang_minor__)
2023 # ifdef __apple_build_version__
2024 #  if __clang_major__ < 5 || (__clang_major__ == 5 && __clang_minor__ < 1)
2025 #   error You need at least XCode Clang v5.1 to compile QEMU
2026 #  endif
2027 # else
2028 #  if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 4)
2029 #   error You need at least Clang v3.4 to compile QEMU
2030 #  endif
2031 # endif
2032 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
2033 # if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
2034 #  error You need at least GCC v4.8 to compile QEMU
2035 # endif
2036 #else
2037 # error You either need GCC or Clang to compiler QEMU
2038 #endif
2039 int main (void) { return 0; }
2040 EOF
2041 if ! compile_prog "" "" ; then
2042     error_exit "You need at least GCC v4.8 or Clang v3.4 (or XCode Clang v5.1)"
2043 fi
2044
2045 # Accumulate -Wfoo and -Wno-bar separately.
2046 # We will list all of the enable flags first, and the disable flags second.
2047 # Note that we do not add -Werror, because that would enable it for all
2048 # configure tests. If a configure test failed due to -Werror this would
2049 # just silently disable some features, so it's too error prone.
2050
2051 warn_flags=
2052 add_to warn_flags -Wold-style-declaration
2053 add_to warn_flags -Wold-style-definition
2054 add_to warn_flags -Wtype-limits
2055 add_to warn_flags -Wformat-security
2056 add_to warn_flags -Wformat-y2k
2057 add_to warn_flags -Winit-self
2058 add_to warn_flags -Wignored-qualifiers
2059 add_to warn_flags -Wempty-body
2060 add_to warn_flags -Wnested-externs
2061 add_to warn_flags -Wendif-labels
2062 add_to warn_flags -Wexpansion-to-defined
2063
2064 nowarn_flags=
2065 add_to nowarn_flags -Wno-initializer-overrides
2066 add_to nowarn_flags -Wno-missing-include-dirs
2067 add_to nowarn_flags -Wno-shift-negative-value
2068 add_to nowarn_flags -Wno-string-plus-int
2069 add_to nowarn_flags -Wno-typedef-redefinition
2070 add_to nowarn_flags -Wno-tautological-type-limit-compare
2071 add_to nowarn_flags -Wno-psabi
2072
2073 gcc_flags="$warn_flags $nowarn_flags"
2074
2075 cc_has_warning_flag() {
2076     write_c_skeleton;
2077
2078     # Use the positive sense of the flag when testing for -Wno-wombat
2079     # support (gcc will happily accept the -Wno- form of unknown
2080     # warning options).
2081     optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
2082     compile_prog "-Werror $optflag" ""
2083 }
2084
2085 for flag in $gcc_flags; do
2086     if cc_has_warning_flag $flag ; then
2087         QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2088     fi
2089 done
2090
2091 if test "$stack_protector" != "no"; then
2092   cat > $TMPC << EOF
2093 int main(int argc, char *argv[])
2094 {
2095     char arr[64], *p = arr, *c = argv[0];
2096     while (*c) {
2097         *p++ = *c++;
2098     }
2099     return 0;
2100 }
2101 EOF
2102   gcc_flags="-fstack-protector-strong -fstack-protector-all"
2103   sp_on=0
2104   for flag in $gcc_flags; do
2105     # We need to check both a compile and a link, since some compiler
2106     # setups fail only on a .c->.o compile and some only at link time
2107     if do_cc $QEMU_CFLAGS -Werror $flag -c -o $TMPO $TMPC &&
2108        compile_prog "-Werror $flag" ""; then
2109       QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2110       QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
2111       sp_on=1
2112       break
2113     fi
2114   done
2115   if test "$stack_protector" = yes; then
2116     if test $sp_on = 0; then
2117       error_exit "Stack protector not supported"
2118     fi
2119   fi
2120 fi
2121
2122 # Disable -Wmissing-braces on older compilers that warn even for
2123 # the "universal" C zero initializer {0}.
2124 cat > $TMPC << EOF
2125 struct {
2126   int a[2];
2127 } x = {0};
2128 EOF
2129 if compile_object "-Werror" "" ; then
2130   :
2131 else
2132   QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
2133 fi
2134
2135 # Our module code doesn't support Windows
2136 if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
2137   error_exit "Modules are not available for Windows"
2138 fi
2139
2140 # module_upgrades is only reasonable if modules are enabled
2141 if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
2142   error_exit "Can't enable module-upgrades as Modules are not enabled"
2143 fi
2144
2145 # Static linking is not possible with modules or PIE
2146 if test "$static" = "yes" ; then
2147   if test "$modules" = "yes" ; then
2148     error_exit "static and modules are mutually incompatible"
2149   fi
2150 fi
2151
2152 # Unconditional check for compiler __thread support
2153   cat > $TMPC << EOF
2154 static __thread int tls_var;
2155 int main(void) { return tls_var; }
2156 EOF
2157
2158 if ! compile_prog "-Werror" "" ; then
2159     error_exit "Your compiler does not support the __thread specifier for " \
2160         "Thread-Local Storage (TLS). Please upgrade to a version that does."
2161 fi
2162
2163 cat > $TMPC << EOF
2164
2165 #ifdef __linux__
2166 #  define THREAD __thread
2167 #else
2168 #  define THREAD
2169 #endif
2170 static THREAD int tls_var;
2171 int main(void) { return tls_var; }
2172 EOF
2173
2174 # Check we support --no-pie first; we will need this for building ROMs.
2175 if compile_prog "-Werror -fno-pie" "-no-pie"; then
2176   CFLAGS_NOPIE="-fno-pie"
2177   LDFLAGS_NOPIE="-no-pie"
2178 fi
2179
2180 if test "$static" = "yes"; then
2181   if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
2182     QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS"
2183     QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
2184     pie="yes"
2185   elif test "$pie" = "yes"; then
2186     error_exit "-static-pie not available due to missing toolchain support"
2187   else
2188     QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
2189     pie="no"
2190   fi
2191 elif test "$pie" = "no"; then
2192   QEMU_CFLAGS="$CFLAGS_NOPIE $QEMU_CFLAGS"
2193   QEMU_LDFLAGS="$LDFLAGS_NOPIE $QEMU_LDFLAGS"
2194 elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
2195   QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS"
2196   QEMU_LDFLAGS="-pie $QEMU_LDFLAGS"
2197   pie="yes"
2198 elif test "$pie" = "yes"; then
2199   error_exit "PIE not available due to missing toolchain support"
2200 else
2201   echo "Disabling PIE due to missing toolchain support"
2202   pie="no"
2203 fi
2204
2205 # Detect support for PT_GNU_RELRO + DT_BIND_NOW.
2206 # The combination is known as "full relro", because .got.plt is read-only too.
2207 if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
2208   QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
2209 fi
2210
2211 ##########################################
2212 # __sync_fetch_and_and requires at least -march=i486. Many toolchains
2213 # use i686 as default anyway, but for those that don't, an explicit
2214 # specification is necessary
2215
2216 if test "$cpu" = "i386"; then
2217   cat > $TMPC << EOF
2218 static int sfaa(int *ptr)
2219 {
2220   return __sync_fetch_and_and(ptr, 0);
2221 }
2222
2223 int main(void)
2224 {
2225   int val = 42;
2226   val = __sync_val_compare_and_swap(&val, 0, 1);
2227   sfaa(&val);
2228   return val;
2229 }
2230 EOF
2231   if ! compile_prog "" "" ; then
2232     QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
2233   fi
2234 fi
2235
2236 #########################################
2237 # Solaris specific configure tool chain decisions
2238
2239 if test "$solaris" = "yes" ; then
2240   if has $install; then
2241     :
2242   else
2243     error_exit "Solaris install program not found. Use --install=/usr/ucb/install or" \
2244         "install fileutils from www.blastwave.org using pkg-get -i fileutils" \
2245         "to get ginstall which is used by default (which lives in /opt/csw/bin)"
2246   fi
2247   if test "$(path_of $install)" = "/usr/sbin/install" ; then
2248     error_exit "Solaris /usr/sbin/install is not an appropriate install program." \
2249         "try ginstall from the GNU fileutils available from www.blastwave.org" \
2250         "using pkg-get -i fileutils, or use --install=/usr/ucb/install"
2251   fi
2252   if has ar; then
2253     :
2254   else
2255     if test -f /usr/ccs/bin/ar ; then
2256       error_exit "No path includes ar" \
2257           "Add /usr/ccs/bin to your path and rerun configure"
2258     fi
2259     error_exit "No path includes ar"
2260   fi
2261 fi
2262
2263 if test -z "${target_list+xxx}" ; then
2264     for target in $default_target_list; do
2265         supported_target $target 2>/dev/null && \
2266             target_list="$target_list $target"
2267     done
2268     target_list="${target_list# }"
2269 else
2270     target_list=$(echo "$target_list" | sed -e 's/,/ /g')
2271     for target in $target_list; do
2272         # Check that we recognised the target name; this allows a more
2273         # friendly error message than if we let it fall through.
2274         case " $default_target_list " in
2275             *" $target "*)
2276                 ;;
2277             *)
2278                 error_exit "Unknown target name '$target'"
2279                 ;;
2280         esac
2281         supported_target $target || exit 1
2282     done
2283 fi
2284
2285 # see if system emulation was really requested
2286 case " $target_list " in
2287   *"-softmmu "*) softmmu=yes
2288   ;;
2289   *) softmmu=no
2290   ;;
2291 esac
2292
2293 for target in $target_list; do
2294   case "$target" in
2295     arm-softmmu | aarch64-softmmu | i386-softmmu | x86_64-softmmu)
2296       edk2_blobs="yes"
2297       ;;
2298   esac
2299 done
2300 # The EDK2 binaries are compressed with bzip2
2301 if test "$edk2_blobs" = "yes" && ! has bzip2; then
2302   error_exit "The bzip2 program is required for building QEMU"
2303 fi
2304
2305 feature_not_found() {
2306   feature=$1
2307   remedy=$2
2308
2309   error_exit "User requested feature $feature" \
2310       "configure was not able to find it." \
2311       "$remedy"
2312 }
2313
2314 # ---
2315 # big/little endian test
2316 cat > $TMPC << EOF
2317 short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
2318 short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
2319 extern int foo(short *, short *);
2320 int main(int argc, char *argv[]) {
2321     return foo(big_endian, little_endian);
2322 }
2323 EOF
2324
2325 if compile_object ; then
2326     if strings -a $TMPO | grep -q BiGeNdIaN ; then
2327         bigendian="yes"
2328     elif strings -a $TMPO | grep -q LiTtLeEnDiAn ; then
2329         bigendian="no"
2330     else
2331         echo big/little test failed
2332     fi
2333 else
2334     echo big/little test failed
2335 fi
2336
2337 ##########################################
2338 # system tools
2339 if test -z "$want_tools"; then
2340     if test "$softmmu" = "no"; then
2341         want_tools=no
2342     else
2343         want_tools=yes
2344     fi
2345 fi
2346
2347 ##########################################
2348 # cocoa implies not SDL or GTK
2349 # (the cocoa UI code currently assumes it is always the active UI
2350 # and doesn't interact well with other UI frontend code)
2351 if test "$cocoa" = "yes"; then
2352     if test "$sdl" = "yes"; then
2353         error_exit "Cocoa and SDL UIs cannot both be enabled at once"
2354     fi
2355     if test "$gtk" = "yes"; then
2356         error_exit "Cocoa and GTK UIs cannot both be enabled at once"
2357     fi
2358     gtk=no
2359     sdl=no
2360 fi
2361
2362 # Some versions of Mac OS X incorrectly define SIZE_MAX
2363 cat > $TMPC << EOF
2364 #include <stdint.h>
2365 #include <stdio.h>
2366 int main(int argc, char *argv[]) {
2367     return printf("%zu", SIZE_MAX);
2368 }
2369 EOF
2370 have_broken_size_max=no
2371 if ! compile_object -Werror ; then
2372     have_broken_size_max=yes
2373 fi
2374
2375 ##########################################
2376 # L2TPV3 probe
2377
2378 cat > $TMPC <<EOF
2379 #include <sys/socket.h>
2380 #include <linux/ip.h>
2381 int main(void) { return sizeof(struct mmsghdr); }
2382 EOF
2383 if compile_prog "" "" ; then
2384   l2tpv3=yes
2385 else
2386   l2tpv3=no
2387 fi
2388
2389 if check_include "pty.h" ; then
2390   pty_h=yes
2391 else
2392   pty_h=no
2393 fi
2394
2395 cat > $TMPC <<EOF
2396 #include <sys/mman.h>
2397 int main(int argc, char *argv[]) {
2398     return mlockall(MCL_FUTURE);
2399 }
2400 EOF
2401 if compile_prog "" "" ; then
2402   have_mlockall=yes
2403 else
2404   have_mlockall=no
2405 fi
2406
2407 #########################################
2408 # vhost interdependencies and host support
2409
2410 # vhost backends
2411 test "$vhost_user" = "" && vhost_user=yes
2412 if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then
2413   error_exit "vhost-user isn't available on win32"
2414 fi
2415 test "$vhost_vdpa" = "" && vhost_vdpa=$linux
2416 if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
2417   error_exit "vhost-vdpa is only available on Linux"
2418 fi
2419 test "$vhost_kernel" = "" && vhost_kernel=$linux
2420 if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
2421   error_exit "vhost-kernel is only available on Linux"
2422 fi
2423
2424 # vhost-kernel devices
2425 test "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
2426 if test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
2427   error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
2428 fi
2429 test "$vhost_vsock" = "" && vhost_vsock=$vhost_kernel
2430 if test "$vhost_vsock" = "yes" && test "$vhost_kernel" != "yes"; then
2431   error_exit "--enable-vhost-vsock requires --enable-vhost-kernel"
2432 fi
2433
2434 # vhost-user backends
2435 test "$vhost_net_user" = "" && vhost_net_user=$vhost_user
2436 if test "$vhost_net_user" = "yes" && test "$vhost_user" = "no"; then
2437   error_exit "--enable-vhost-net-user requires --enable-vhost-user"
2438 fi
2439 test "$vhost_crypto" = "" && vhost_crypto=$vhost_user
2440 if test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
2441   error_exit "--enable-vhost-crypto requires --enable-vhost-user"
2442 fi
2443 test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
2444 if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
2445   error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
2446 fi
2447 #vhost-vdpa backends
2448 test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa
2449 if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then
2450   error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa"
2451 fi
2452
2453 # OR the vhost-kernel and vhost-user values for simplicity
2454 if test "$vhost_net" = ""; then
2455   test "$vhost_net_user" = "yes" && vhost_net=yes
2456   test "$vhost_kernel" = "yes" && vhost_net=yes
2457 fi
2458
2459 ##########################################
2460 # MinGW / Mingw-w64 localtime_r/gmtime_r check
2461
2462 if test "$mingw32" = "yes"; then
2463     # Some versions of MinGW / Mingw-w64 lack localtime_r
2464     # and gmtime_r entirely.
2465     #
2466     # Some versions of Mingw-w64 define a macro for
2467     # localtime_r/gmtime_r.
2468     #
2469     # Some versions of Mingw-w64 will define functions
2470     # for localtime_r/gmtime_r, but only if you have
2471     # _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun
2472     # though, unistd.h and pthread.h both define
2473     # that for you.
2474     #
2475     # So this #undef localtime_r and #include <unistd.h>
2476     # are not in fact redundant.
2477 cat > $TMPC << EOF
2478 #include <unistd.h>
2479 #include <time.h>
2480 #undef localtime_r
2481 int main(void) { localtime_r(NULL, NULL); return 0; }
2482 EOF
2483     if compile_prog "" "" ; then
2484         localtime_r="yes"
2485     else
2486         localtime_r="no"
2487     fi
2488 fi
2489
2490 ##########################################
2491 # pkg-config probe
2492
2493 if ! has "$pkg_config_exe"; then
2494   error_exit "pkg-config binary '$pkg_config_exe' not found"
2495 fi
2496
2497 ##########################################
2498 # NPTL probe
2499
2500 if test "$linux_user" = "yes"; then
2501   cat > $TMPC <<EOF
2502 #include <sched.h>
2503 #include <linux/futex.h>
2504 int main(void) {
2505 #if !defined(CLONE_SETTLS) || !defined(FUTEX_WAIT)
2506 #error bork
2507 #endif
2508   return 0;
2509 }
2510 EOF
2511   if ! compile_object ; then
2512     feature_not_found "nptl" "Install glibc and linux kernel headers."
2513   fi
2514 fi
2515
2516 ##########################################
2517 # lzo check
2518
2519 if test "$lzo" != "no" ; then
2520     cat > $TMPC << EOF
2521 #include <lzo/lzo1x.h>
2522 int main(void) { lzo_version(); return 0; }
2523 EOF
2524     if compile_prog "" "-llzo2" ; then
2525         libs_softmmu="$libs_softmmu -llzo2"
2526         lzo="yes"
2527     else
2528         if test "$lzo" = "yes"; then
2529             feature_not_found "liblzo2" "Install liblzo2 devel"
2530         fi
2531         lzo="no"
2532     fi
2533 fi
2534
2535 ##########################################
2536 # snappy check
2537
2538 if test "$snappy" != "no" ; then
2539     cat > $TMPC << EOF
2540 #include <snappy-c.h>
2541 int main(void) { snappy_max_compressed_length(4096); return 0; }
2542 EOF
2543     if compile_prog "" "-lsnappy" ; then
2544         libs_softmmu="$libs_softmmu -lsnappy"
2545         snappy="yes"
2546     else
2547         if test "$snappy" = "yes"; then
2548             feature_not_found "libsnappy" "Install libsnappy devel"
2549         fi
2550         snappy="no"
2551     fi
2552 fi
2553
2554 ##########################################
2555 # bzip2 check
2556
2557 if test "$bzip2" != "no" ; then
2558     cat > $TMPC << EOF
2559 #include <bzlib.h>
2560 int main(void) { BZ2_bzlibVersion(); return 0; }
2561 EOF
2562     if compile_prog "" "-lbz2" ; then
2563         bzip2="yes"
2564     else
2565         if test "$bzip2" = "yes"; then
2566             feature_not_found "libbzip2" "Install libbzip2 devel"
2567         fi
2568         bzip2="no"
2569     fi
2570 fi
2571
2572 ##########################################
2573 # lzfse check
2574
2575 if test "$lzfse" != "no" ; then
2576     cat > $TMPC << EOF
2577 #include <lzfse.h>
2578 int main(void) { lzfse_decode_scratch_size(); return 0; }
2579 EOF
2580     if compile_prog "" "-llzfse" ; then
2581         lzfse="yes"
2582     else
2583         if test "$lzfse" = "yes"; then
2584             feature_not_found "lzfse" "Install lzfse devel"
2585         fi
2586         lzfse="no"
2587     fi
2588 fi
2589
2590 ##########################################
2591 # zstd check
2592
2593 if test "$zstd" != "no" ; then
2594     libzstd_minver="1.4.0"
2595     if $pkg_config --atleast-version=$libzstd_minver libzstd ; then
2596         zstd_cflags="$($pkg_config --cflags libzstd)"
2597         zstd_libs="$($pkg_config --libs libzstd)"
2598         LIBS="$zstd_libs $LIBS"
2599         QEMU_CFLAGS="$QEMU_CFLAGS $zstd_cflags"
2600         zstd="yes"
2601     else
2602         if test "$zstd" = "yes" ; then
2603             feature_not_found "libzstd" "Install libzstd devel"
2604         fi
2605         zstd="no"
2606     fi
2607 fi
2608
2609 ##########################################
2610 # libseccomp check
2611
2612 if test "$seccomp" != "no" ; then
2613     libseccomp_minver="2.3.0"
2614     if $pkg_config --atleast-version=$libseccomp_minver libseccomp ; then
2615         seccomp_cflags="$($pkg_config --cflags libseccomp)"
2616         seccomp_libs="$($pkg_config --libs libseccomp)"
2617         seccomp="yes"
2618     else
2619         if test "$seccomp" = "yes" ; then
2620             feature_not_found "libseccomp" \
2621                  "Install libseccomp devel >= $libseccomp_minver"
2622         fi
2623         seccomp="no"
2624     fi
2625 fi
2626 ##########################################
2627 # xen probe
2628
2629 if test "$xen" != "no" ; then
2630   # Check whether Xen library path is specified via --extra-ldflags to avoid
2631   # overriding this setting with pkg-config output. If not, try pkg-config
2632   # to obtain all needed flags.
2633
2634   if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \
2635      $pkg_config --exists xencontrol ; then
2636     xen_ctrl_version="$(printf '%d%02d%02d' \
2637       $($pkg_config --modversion xencontrol | sed 's/\./ /g') )"
2638     xen=yes
2639     xen_pc="xencontrol xenstore xenguest xenforeignmemory xengnttab"
2640     xen_pc="$xen_pc xenevtchn xendevicemodel"
2641     if $pkg_config --exists xentoolcore; then
2642       xen_pc="$xen_pc xentoolcore"
2643     fi
2644     QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags $xen_pc)"
2645     libs_softmmu="$($pkg_config --libs $xen_pc) $libs_softmmu"
2646   else
2647
2648     xen_libs="-lxenstore -lxenctrl -lxenguest"
2649     xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
2650
2651     # First we test whether Xen headers and libraries are available.
2652     # If no, we are done and there is no Xen support.
2653     # If yes, more tests are run to detect the Xen version.
2654
2655     # Xen (any)
2656     cat > $TMPC <<EOF
2657 #include <xenctrl.h>
2658 int main(void) {
2659   return 0;
2660 }
2661 EOF
2662     if ! compile_prog "" "$xen_libs" ; then
2663       # Xen not found
2664       if test "$xen" = "yes" ; then
2665         feature_not_found "xen" "Install xen devel"
2666       fi
2667       xen=no
2668
2669     # Xen unstable
2670     elif
2671         cat > $TMPC <<EOF &&
2672 #undef XC_WANT_COMPAT_DEVICEMODEL_API
2673 #define __XEN_TOOLS__
2674 #include <xendevicemodel.h>
2675 #include <xenforeignmemory.h>
2676 int main(void) {
2677   xendevicemodel_handle *xd;
2678   xenforeignmemory_handle *xfmem;
2679
2680   xd = xendevicemodel_open(0, 0);
2681   xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);
2682
2683   xfmem = xenforeignmemory_open(0, 0);
2684   xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);
2685
2686   return 0;
2687 }
2688 EOF
2689         compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
2690       then
2691       xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
2692       xen_ctrl_version=41100
2693       xen=yes
2694     elif
2695         cat > $TMPC <<EOF &&
2696 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
2697 #include <xenforeignmemory.h>
2698 #include <xentoolcore.h>
2699 int main(void) {
2700   xenforeignmemory_handle *xfmem;
2701
2702   xfmem = xenforeignmemory_open(0, 0);
2703   xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
2704   xentoolcore_restrict_all(0);
2705
2706   return 0;
2707 }
2708 EOF
2709         compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
2710       then
2711       xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
2712       xen_ctrl_version=41000
2713       xen=yes
2714     elif
2715         cat > $TMPC <<EOF &&
2716 #undef XC_WANT_COMPAT_DEVICEMODEL_API
2717 #define __XEN_TOOLS__
2718 #include <xendevicemodel.h>
2719 int main(void) {
2720   xendevicemodel_handle *xd;
2721
2722   xd = xendevicemodel_open(0, 0);
2723   xendevicemodel_close(xd);
2724
2725   return 0;
2726 }
2727 EOF
2728         compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs"
2729       then
2730       xen_stable_libs="-lxendevicemodel $xen_stable_libs"
2731       xen_ctrl_version=40900
2732       xen=yes
2733     elif
2734         cat > $TMPC <<EOF &&
2735 /*
2736  * If we have stable libs the we don't want the libxc compat
2737  * layers, regardless of what CFLAGS we may have been given.
2738  *
2739  * Also, check if xengnttab_grant_copy_segment_t is defined and
2740  * grant copy operation is implemented.
2741  */
2742 #undef XC_WANT_COMPAT_EVTCHN_API
2743 #undef XC_WANT_COMPAT_GNTTAB_API
2744 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
2745 #include <xenctrl.h>
2746 #include <xenstore.h>
2747 #include <xenevtchn.h>
2748 #include <xengnttab.h>
2749 #include <xenforeignmemory.h>
2750 #include <stdint.h>
2751 #include <xen/hvm/hvm_info_table.h>
2752 #if !defined(HVM_MAX_VCPUS)
2753 # error HVM_MAX_VCPUS not defined
2754 #endif
2755 int main(void) {
2756   xc_interface *xc = NULL;
2757   xenforeignmemory_handle *xfmem;
2758   xenevtchn_handle *xe;
2759   xengnttab_handle *xg;
2760   xengnttab_grant_copy_segment_t* seg = NULL;
2761
2762   xs_daemon_open();
2763
2764   xc = xc_interface_open(0, 0, 0);
2765   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2766   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2767   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2768   xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2769
2770   xfmem = xenforeignmemory_open(0, 0);
2771   xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2772
2773   xe = xenevtchn_open(0, 0);
2774   xenevtchn_fd(xe);
2775
2776   xg = xengnttab_open(0, 0);
2777   xengnttab_grant_copy(xg, 0, seg);
2778
2779   return 0;
2780 }
2781 EOF
2782         compile_prog "" "$xen_libs $xen_stable_libs"
2783       then
2784       xen_ctrl_version=40800
2785       xen=yes
2786     elif
2787         cat > $TMPC <<EOF &&
2788 /*
2789  * If we have stable libs the we don't want the libxc compat
2790  * layers, regardless of what CFLAGS we may have been given.
2791  */
2792 #undef XC_WANT_COMPAT_EVTCHN_API
2793 #undef XC_WANT_COMPAT_GNTTAB_API
2794 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
2795 #include <xenctrl.h>
2796 #include <xenstore.h>
2797 #include <xenevtchn.h>
2798 #include <xengnttab.h>
2799 #include <xenforeignmemory.h>
2800 #include <stdint.h>
2801 #include <xen/hvm/hvm_info_table.h>
2802 #if !defined(HVM_MAX_VCPUS)
2803 # error HVM_MAX_VCPUS not defined
2804 #endif
2805 int main(void) {
2806   xc_interface *xc = NULL;
2807   xenforeignmemory_handle *xfmem;
2808   xenevtchn_handle *xe;
2809   xengnttab_handle *xg;
2810
2811   xs_daemon_open();
2812
2813   xc = xc_interface_open(0, 0, 0);
2814   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2815   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2816   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2817   xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2818
2819   xfmem = xenforeignmemory_open(0, 0);
2820   xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2821
2822   xe = xenevtchn_open(0, 0);
2823   xenevtchn_fd(xe);
2824
2825   xg = xengnttab_open(0, 0);
2826   xengnttab_map_grant_ref(xg, 0, 0, 0);
2827
2828   return 0;
2829 }
2830 EOF
2831         compile_prog "" "$xen_libs $xen_stable_libs"
2832       then
2833       xen_ctrl_version=40701
2834       xen=yes
2835
2836     # Xen 4.6
2837     elif
2838         cat > $TMPC <<EOF &&
2839 #include <xenctrl.h>
2840 #include <xenstore.h>
2841 #include <stdint.h>
2842 #include <xen/hvm/hvm_info_table.h>
2843 #if !defined(HVM_MAX_VCPUS)
2844 # error HVM_MAX_VCPUS not defined
2845 #endif
2846 int main(void) {
2847   xc_interface *xc;
2848   xs_daemon_open();
2849   xc = xc_interface_open(0, 0, 0);
2850   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2851   xc_gnttab_open(NULL, 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   xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
2856   return 0;
2857 }
2858 EOF
2859         compile_prog "" "$xen_libs"
2860       then
2861       xen_ctrl_version=40600
2862       xen=yes
2863
2864     # Xen 4.5
2865     elif
2866         cat > $TMPC <<EOF &&
2867 #include <xenctrl.h>
2868 #include <xenstore.h>
2869 #include <stdint.h>
2870 #include <xen/hvm/hvm_info_table.h>
2871 #if !defined(HVM_MAX_VCPUS)
2872 # error HVM_MAX_VCPUS not defined
2873 #endif
2874 int main(void) {
2875   xc_interface *xc;
2876   xs_daemon_open();
2877   xc = xc_interface_open(0, 0, 0);
2878   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2879   xc_gnttab_open(NULL, 0);
2880   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2881   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2882   xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
2883   return 0;
2884 }
2885 EOF
2886         compile_prog "" "$xen_libs"
2887       then
2888       xen_ctrl_version=40500
2889       xen=yes
2890
2891     elif
2892         cat > $TMPC <<EOF &&
2893 #include <xenctrl.h>
2894 #include <xenstore.h>
2895 #include <stdint.h>
2896 #include <xen/hvm/hvm_info_table.h>
2897 #if !defined(HVM_MAX_VCPUS)
2898 # error HVM_MAX_VCPUS not defined
2899 #endif
2900 int main(void) {
2901   xc_interface *xc;
2902   xs_daemon_open();
2903   xc = xc_interface_open(0, 0, 0);
2904   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2905   xc_gnttab_open(NULL, 0);
2906   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2907   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2908   return 0;
2909 }
2910 EOF
2911         compile_prog "" "$xen_libs"
2912       then
2913       xen_ctrl_version=40200
2914       xen=yes
2915
2916     else
2917       if test "$xen" = "yes" ; then
2918         feature_not_found "xen (unsupported version)" \
2919                           "Install a supported xen (xen 4.2 or newer)"
2920       fi
2921       xen=no
2922     fi
2923
2924     if test "$xen" = yes; then
2925       if test $xen_ctrl_version -ge 40701  ; then
2926         libs_softmmu="$xen_stable_libs $libs_softmmu"
2927       fi
2928       libs_softmmu="$xen_libs $libs_softmmu"
2929     fi
2930   fi
2931 fi
2932
2933 if test "$xen_pci_passthrough" != "no"; then
2934   if test "$xen" = "yes" && test "$linux" = "yes"; then
2935     xen_pci_passthrough=yes
2936   else
2937     if test "$xen_pci_passthrough" = "yes"; then
2938       error_exit "User requested feature Xen PCI Passthrough" \
2939           " but this feature requires /sys from Linux"
2940     fi
2941     xen_pci_passthrough=no
2942   fi
2943 fi
2944
2945 ##########################################
2946 # Windows Hypervisor Platform accelerator (WHPX) check
2947 if test "$whpx" != "no" ; then
2948     if check_include "WinHvPlatform.h" && check_include "WinHvEmulation.h"; then
2949         whpx="yes"
2950     else
2951         if test "$whpx" = "yes"; then
2952             feature_not_found "WinHvPlatform" "WinHvEmulation is not installed"
2953         fi
2954         whpx="no"
2955     fi
2956 fi
2957
2958 ##########################################
2959 # Sparse probe
2960 if test "$sparse" != "no" ; then
2961   if has cgcc; then
2962     sparse=yes
2963   else
2964     if test "$sparse" = "yes" ; then
2965       feature_not_found "sparse" "Install sparse binary"
2966     fi
2967     sparse=no
2968   fi
2969 fi
2970
2971 ##########################################
2972 # X11 probe
2973 if $pkg_config --exists "x11"; then
2974     have_x11=yes
2975     x11_cflags=$($pkg_config --cflags x11)
2976     x11_libs=$($pkg_config --libs x11)
2977 fi
2978
2979 ##########################################
2980 # GTK probe
2981
2982 if test "$gtk" != "no"; then
2983     gtkpackage="gtk+-3.0"
2984     gtkx11package="gtk+-x11-3.0"
2985     gtkversion="3.22.0"
2986     if $pkg_config --exists "$gtkpackage >= $gtkversion"; then
2987         gtk_cflags=$($pkg_config --cflags $gtkpackage)
2988         gtk_libs=$($pkg_config --libs $gtkpackage)
2989         gtk_version=$($pkg_config --modversion $gtkpackage)
2990         if $pkg_config --exists "$gtkx11package >= $gtkversion"; then
2991             need_x11=yes
2992             gtk_cflags="$gtk_cflags $x11_cflags"
2993             gtk_libs="$gtk_libs $x11_libs"
2994         fi
2995         gtk="yes"
2996     elif test "$gtk" = "yes"; then
2997         feature_not_found "gtk" "Install gtk3-devel"
2998     else
2999         gtk="no"
3000     fi
3001 fi
3002
3003
3004 ##########################################
3005 # GNUTLS probe
3006
3007 if test "$gnutls" != "no"; then
3008     pass="no"
3009     if $pkg_config --exists "gnutls >= 3.1.18"; then
3010         gnutls_cflags=$($pkg_config --cflags gnutls)
3011         gnutls_libs=$($pkg_config --libs gnutls)
3012         # Packaging for the static libraries is not always correct.
3013         # At least ubuntu 18.04 ships only shared libraries.
3014         write_c_skeleton
3015         if compile_prog "" "$gnutls_libs" ; then
3016             LIBS="$gnutls_libs $LIBS"
3017             QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags"
3018             pass="yes"
3019         fi
3020     fi
3021     if test "$pass" = "no" && test "$gnutls" = "yes"; then
3022         feature_not_found "gnutls" "Install gnutls devel >= 3.1.18"
3023     else
3024         gnutls="$pass"
3025     fi
3026 fi
3027
3028
3029 # If user didn't give a --disable/enable-gcrypt flag,
3030 # then mark as disabled if user requested nettle
3031 # explicitly
3032 if test -z "$gcrypt"
3033 then
3034     if test "$nettle" = "yes"
3035     then
3036         gcrypt="no"
3037     fi
3038 fi
3039
3040 # If user didn't give a --disable/enable-nettle flag,
3041 # then mark as disabled if user requested gcrypt
3042 # explicitly
3043 if test -z "$nettle"
3044 then
3045     if test "$gcrypt" = "yes"
3046     then
3047         nettle="no"
3048     fi
3049 fi
3050
3051 has_libgcrypt() {
3052     if ! has "libgcrypt-config"
3053     then
3054         return 1
3055     fi
3056
3057     if test -n "$cross_prefix"
3058     then
3059         host=$(libgcrypt-config --host)
3060         if test "$host-" != $cross_prefix
3061         then
3062             return 1
3063         fi
3064     fi
3065
3066     maj=`libgcrypt-config --version | awk -F . '{print $1}'`
3067     min=`libgcrypt-config --version | awk -F . '{print $2}'`
3068
3069     if test $maj != 1 || test $min -lt 5
3070     then
3071        return 1
3072     fi
3073
3074     return 0
3075 }
3076
3077
3078 if test "$nettle" != "no"; then
3079     pass="no"
3080     if $pkg_config --exists "nettle >= 2.7.1"; then
3081         nettle_cflags=$($pkg_config --cflags nettle)
3082         nettle_libs=$($pkg_config --libs nettle)
3083         nettle_version=$($pkg_config --modversion nettle)
3084         # Link test to make sure the given libraries work (e.g for static).
3085         write_c_skeleton
3086         if compile_prog "" "$nettle_libs" ; then
3087             LIBS="$nettle_libs $LIBS"
3088             QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags"
3089             if test -z "$gcrypt"; then
3090                gcrypt="no"
3091             fi
3092             pass="yes"
3093         fi
3094     fi
3095     if test "$pass" = "yes"
3096     then
3097         cat > $TMPC << EOF
3098 #include <nettle/xts.h>
3099 int main(void) {
3100   return 0;
3101 }
3102 EOF
3103         if compile_prog "$nettle_cflags" "$nettle_libs" ; then
3104             nettle_xts=yes
3105             qemu_private_xts=no
3106         fi
3107     fi
3108     if test "$pass" = "no" && test "$nettle" = "yes"; then
3109         feature_not_found "nettle" "Install nettle devel >= 2.7.1"
3110     else
3111         nettle="$pass"
3112     fi
3113 fi
3114
3115 if test "$gcrypt" != "no"; then
3116     pass="no"
3117     if has_libgcrypt; then
3118         gcrypt_cflags=$(libgcrypt-config --cflags)
3119         gcrypt_libs=$(libgcrypt-config --libs)
3120         # Debian has removed -lgpg-error from libgcrypt-config
3121         # as it "spreads unnecessary dependencies" which in
3122         # turn breaks static builds...
3123         if test "$static" = "yes"
3124         then
3125             gcrypt_libs="$gcrypt_libs -lgpg-error"
3126         fi
3127
3128         # Link test to make sure the given libraries work (e.g for static).
3129         write_c_skeleton
3130         if compile_prog "" "$gcrypt_libs" ; then
3131             LIBS="$gcrypt_libs $LIBS"
3132             QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags"
3133             pass="yes"
3134         fi
3135     fi
3136     if test "$pass" = "yes"; then
3137         gcrypt="yes"
3138         cat > $TMPC << EOF
3139 #include <gcrypt.h>
3140 int main(void) {
3141   gcry_mac_hd_t handle;
3142   gcry_mac_open(&handle, GCRY_MAC_HMAC_MD5,
3143                 GCRY_MAC_FLAG_SECURE, NULL);
3144   return 0;
3145 }
3146 EOF
3147         if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then
3148             gcrypt_hmac=yes
3149         fi
3150         cat > $TMPC << EOF
3151 #include <gcrypt.h>
3152 int main(void) {
3153   gcry_cipher_hd_t handle;
3154   gcry_cipher_open(&handle, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_XTS, 0);
3155   return 0;
3156 }
3157 EOF
3158         if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then
3159             gcrypt_xts=yes
3160             qemu_private_xts=no
3161         fi
3162     elif test "$gcrypt" = "yes"; then
3163         feature_not_found "gcrypt" "Install gcrypt devel >= 1.5.0"
3164     else
3165         gcrypt="no"
3166     fi
3167 fi
3168
3169
3170 if test "$gcrypt" = "yes" && test "$nettle" = "yes"
3171 then
3172     error_exit "Only one of gcrypt & nettle can be enabled"
3173 fi
3174
3175 ##########################################
3176 # libtasn1 - only for the TLS creds/session test suite
3177
3178 tasn1=yes
3179 tasn1_cflags=""
3180 tasn1_libs=""
3181 if $pkg_config --exists "libtasn1"; then
3182     tasn1_cflags=$($pkg_config --cflags libtasn1)
3183     tasn1_libs=$($pkg_config --libs libtasn1)
3184 else
3185     tasn1=no
3186 fi
3187
3188
3189 ##########################################
3190 # PAM probe
3191
3192 if test "$auth_pam" != "no"; then
3193     cat > $TMPC <<EOF
3194 #include <security/pam_appl.h>
3195 #include <stdio.h>
3196 int main(void) {
3197    const char *service_name = "qemu";
3198    const char *user = "frank";
3199    const struct pam_conv pam_conv = { 0 };
3200    pam_handle_t *pamh = NULL;
3201    pam_start(service_name, user, &pam_conv, &pamh);
3202    return 0;
3203 }
3204 EOF
3205     if compile_prog "" "-lpam" ; then
3206         auth_pam=yes
3207     else
3208         if test "$auth_pam" = "yes"; then
3209             feature_not_found "PAM" "Install PAM development package"
3210         else
3211             auth_pam=no
3212         fi
3213     fi
3214 fi
3215
3216 ##########################################
3217 # getifaddrs (for tests/test-io-channel-socket )
3218
3219 have_ifaddrs_h=yes
3220 if ! check_include "ifaddrs.h" ; then
3221   have_ifaddrs_h=no
3222 fi
3223
3224 #########################################
3225 # libdrm check
3226 have_drm_h=no
3227 if check_include "libdrm/drm.h" ; then
3228     have_drm_h=yes
3229 fi
3230
3231 #########################################
3232 # sys/signal.h check
3233 have_sys_signal_h=no
3234 if check_include "sys/signal.h" ; then
3235   have_sys_signal_h=yes
3236 fi
3237
3238 ##########################################
3239 # VTE probe
3240
3241 if test "$vte" != "no"; then
3242     vteminversion="0.32.0"
3243     if $pkg_config --exists "vte-2.91"; then
3244       vtepackage="vte-2.91"
3245     else
3246       vtepackage="vte-2.90"
3247     fi
3248     if $pkg_config --exists "$vtepackage >= $vteminversion"; then
3249         vte_cflags=$($pkg_config --cflags $vtepackage)
3250         vte_libs=$($pkg_config --libs $vtepackage)
3251         vteversion=$($pkg_config --modversion $vtepackage)
3252         vte="yes"
3253     elif test "$vte" = "yes"; then
3254         feature_not_found "vte" "Install libvte-2.90/2.91 devel"
3255     else
3256         vte="no"
3257     fi
3258 fi
3259
3260 ##########################################
3261 # SDL probe
3262
3263 # Look for sdl configuration program (pkg-config or sdl2-config).  Try
3264 # sdl2-config even without cross prefix, and favour pkg-config over sdl2-config.
3265
3266 sdl_probe ()
3267 {
3268   if $pkg_config sdl2 --exists; then
3269     sdlconfig="$pkg_config sdl2"
3270     sdlversion=$($sdlconfig --modversion 2>/dev/null)
3271   elif has "$sdl2_config"; then
3272     sdlconfig="$sdl2_config"
3273     sdlversion=$($sdlconfig --version)
3274   else
3275     if test "$sdl" = "yes" ; then
3276       feature_not_found "sdl" "Install SDL2-devel"
3277     fi
3278     sdl=no
3279     # no need to do the rest
3280     return
3281   fi
3282   if test -n "$cross_prefix" && test "$(basename "$sdlconfig")" = sdl2-config; then
3283     echo warning: using "\"$sdlconfig\"" to detect cross-compiled sdl >&2
3284   fi
3285
3286   cat > $TMPC << EOF
3287 #include <SDL.h>
3288 #undef main /* We don't want SDL to override our main() */
3289 int main( void ) { return SDL_Init (SDL_INIT_VIDEO); }
3290 EOF
3291   sdl_cflags=$($sdlconfig --cflags 2>/dev/null)
3292   sdl_cflags="$sdl_cflags -Wno-undef"  # workaround 2.0.8 bug
3293   if test "$static" = "yes" ; then
3294     if $pkg_config sdl2 --exists; then
3295       sdl_libs=$($pkg_config sdl2 --static --libs 2>/dev/null)
3296     else
3297       sdl_libs=$($sdlconfig --static-libs 2>/dev/null)
3298     fi
3299   else
3300     sdl_libs=$($sdlconfig --libs 2>/dev/null)
3301   fi
3302   if compile_prog "$sdl_cflags" "$sdl_libs" ; then
3303     sdl=yes
3304
3305     # static link with sdl ? (note: sdl.pc's --static --libs is broken)
3306     if test "$sdl" = "yes" && test "$static" = "yes" ; then
3307       if test $? = 0 && echo $sdl_libs | grep -- -laa > /dev/null; then
3308          sdl_libs="$sdl_libs $(aalib-config --static-libs 2>/dev/null)"
3309          sdl_cflags="$sdl_cflags $(aalib-config --cflags 2>/dev/null)"
3310       fi
3311       if compile_prog "$sdl_cflags" "$sdl_libs" ; then
3312         :
3313       else
3314         sdl=no
3315       fi
3316     fi # static link
3317   else # sdl not found
3318     if test "$sdl" = "yes" ; then
3319       feature_not_found "sdl" "Install SDL2 devel"
3320     fi
3321     sdl=no
3322   fi # sdl compile test
3323 }
3324
3325 sdl_image_probe ()
3326 {
3327     if test "$sdl_image" != "no" ; then
3328         if $pkg_config SDL2_image --exists; then
3329             if test "$static" = "yes"; then
3330                 sdl_image_libs=$($pkg_config SDL2_image --libs --static 2>/dev/null)
3331             else
3332                 sdl_image_libs=$($pkg_config SDL2_image --libs 2>/dev/null)
3333             fi
3334             sdl_image_cflags=$($pkg_config SDL2_image --cflags 2>/dev/null)
3335             sdl_image=yes
3336
3337             sdl_cflags="$sdl_cflags $sdl_image_cflags"
3338             sdl_libs="$sdl_libs $sdl_image_libs"
3339         else
3340             if test "$sdl_image" = "yes" ; then
3341                 feature_not_found "sdl_image" "Install SDL Image devel"
3342             else
3343                 sdl_image=no
3344             fi
3345         fi
3346     fi
3347 }
3348
3349 if test "$sdl" != "no" ; then
3350   sdl_probe
3351 fi
3352
3353 if test "$sdl" = "yes" ; then
3354   sdl_image_probe
3355 else
3356   if test "$sdl_image" = "yes"; then
3357     echo "warning: SDL Image requested, but SDL is not available, disabling"
3358   fi
3359   sdl_image=no
3360 fi
3361
3362 if test "$sdl" = "yes" ; then
3363   cat > $TMPC <<EOF
3364 #include <SDL.h>
3365 #if defined(SDL_VIDEO_DRIVER_X11)
3366 #include <X11/XKBlib.h>
3367 #else
3368 #error No x11 support
3369 #endif
3370 int main(void) { return 0; }
3371 EOF
3372   if compile_prog "$sdl_cflags $x11_cflags" "$sdl_libs $x11_libs" ; then
3373     need_x11=yes
3374     sdl_cflags="$sdl_cflags $x11_cflags"
3375     sdl_libs="$sdl_libs $x11_libs"
3376   fi
3377 fi
3378
3379 ##########################################
3380 # RDMA needs OpenFabrics libraries
3381 if test "$rdma" != "no" ; then
3382   cat > $TMPC <<EOF
3383 #include <rdma/rdma_cma.h>
3384 int main(void) { return 0; }
3385 EOF
3386   rdma_libs="-lrdmacm -libverbs -libumad"
3387   if compile_prog "" "$rdma_libs" ; then
3388     rdma="yes"
3389     libs_softmmu="$libs_softmmu $rdma_libs"
3390   else
3391     if test "$rdma" = "yes" ; then
3392         error_exit \
3393             " OpenFabrics librdmacm/libibverbs/libibumad not present." \
3394             " Your options:" \
3395             "  (1) Fast: Install infiniband packages (devel) from your distro." \
3396             "  (2) Cleanest: Install libraries from www.openfabrics.org" \
3397             "  (3) Also: Install softiwarp if you don't have RDMA hardware"
3398     fi
3399     rdma="no"
3400   fi
3401 fi
3402
3403 ##########################################
3404 # PVRDMA detection
3405
3406 cat > $TMPC <<EOF &&
3407 #include <sys/mman.h>
3408
3409 int
3410 main(void)
3411 {
3412     char buf = 0;
3413     void *addr = &buf;
3414     addr = mremap(addr, 0, 1, MREMAP_MAYMOVE | MREMAP_FIXED);
3415
3416     return 0;
3417 }
3418 EOF
3419
3420 if test "$rdma" = "yes" ; then
3421     case "$pvrdma" in
3422     "")
3423         if compile_prog "" ""; then
3424             pvrdma="yes"
3425         else
3426             pvrdma="no"
3427         fi
3428         ;;
3429     "yes")
3430         if ! compile_prog "" ""; then
3431             error_exit "PVRDMA is not supported since mremap is not implemented"
3432         fi
3433         pvrdma="yes"
3434         ;;
3435     "no")
3436         pvrdma="no"
3437         ;;
3438     esac
3439 else
3440     if test "$pvrdma" = "yes" ; then
3441         error_exit "PVRDMA requires rdma suppport"
3442     fi
3443     pvrdma="no"
3444 fi
3445
3446 # Let's see if enhanced reg_mr is supported
3447 if test "$pvrdma" = "yes" ; then
3448
3449 cat > $TMPC <<EOF &&
3450 #include <infiniband/verbs.h>
3451
3452 int
3453 main(void)
3454 {
3455     struct ibv_mr *mr;
3456     struct ibv_pd *pd = NULL;
3457     size_t length = 10;
3458     uint64_t iova = 0;
3459     int access = 0;
3460     void *addr = NULL;
3461
3462     mr = ibv_reg_mr_iova(pd, addr, length, iova, access);
3463
3464     ibv_dereg_mr(mr);
3465
3466     return 0;
3467 }
3468 EOF
3469     if ! compile_prog "" "-libverbs"; then
3470         QEMU_CFLAGS="$QEMU_CFLAGS -DLEGACY_RDMA_REG_MR"
3471     fi
3472 fi
3473
3474 ##########################################
3475 # VNC SASL detection
3476 if test "$vnc" = "yes" && test "$vnc_sasl" != "no" ; then
3477   cat > $TMPC <<EOF
3478 #include <sasl/sasl.h>
3479 #include <stdio.h>
3480 int main(void) { sasl_server_init(NULL, "qemu"); return 0; }
3481 EOF
3482   # Assuming Cyrus-SASL installed in /usr prefix
3483   # QEMU defines struct iovec in "qemu/osdep.h",
3484   # we don't want libsasl to redefine it in <sasl/sasl.h>.
3485   vnc_sasl_cflags="-DSTRUCT_IOVEC_DEFINED"
3486   vnc_sasl_libs="-lsasl2"
3487   if compile_prog "$vnc_sasl_cflags" "$vnc_sasl_libs" ; then
3488     vnc_sasl=yes
3489     libs_softmmu="$vnc_sasl_libs $libs_softmmu"
3490     QEMU_CFLAGS="$QEMU_CFLAGS $vnc_sasl_cflags"
3491   else
3492     if test "$vnc_sasl" = "yes" ; then
3493       feature_not_found "vnc-sasl" "Install Cyrus SASL devel"
3494     fi
3495     vnc_sasl=no
3496   fi
3497 fi
3498
3499 ##########################################
3500 # VNC JPEG detection
3501 if test "$vnc" = "yes" && test "$vnc_jpeg" != "no" ; then
3502 cat > $TMPC <<EOF
3503 #include <stdio.h>
3504 #include <jpeglib.h>
3505 int main(void) { struct jpeg_compress_struct s; jpeg_create_compress(&s); return 0; }
3506 EOF
3507     vnc_jpeg_cflags=""
3508     vnc_jpeg_libs="-ljpeg"
3509   if compile_prog "$vnc_jpeg_cflags" "$vnc_jpeg_libs" ; then
3510     vnc_jpeg=yes
3511     libs_softmmu="$vnc_jpeg_libs $libs_softmmu"
3512     QEMU_CFLAGS="$QEMU_CFLAGS $vnc_jpeg_cflags"
3513   else
3514     if test "$vnc_jpeg" = "yes" ; then
3515       feature_not_found "vnc-jpeg" "Install libjpeg-turbo devel"
3516     fi
3517     vnc_jpeg=no
3518   fi
3519 fi
3520
3521 ##########################################
3522 # VNC PNG detection
3523 if test "$vnc" = "yes" && test "$vnc_png" != "no" ; then
3524 cat > $TMPC <<EOF
3525 //#include <stdio.h>
3526 #include <png.h>
3527 #include <stddef.h>
3528 int main(void) {
3529     png_structp png_ptr;
3530     png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
3531     return png_ptr != 0;
3532 }
3533 EOF
3534   if $pkg_config libpng --exists; then
3535     vnc_png_cflags=$($pkg_config libpng --cflags)
3536     vnc_png_libs=$($pkg_config libpng --libs)
3537   else
3538     vnc_png_cflags=""
3539     vnc_png_libs="-lpng"
3540   fi
3541   if compile_prog "$vnc_png_cflags" "$vnc_png_libs" ; then
3542     vnc_png=yes
3543     libs_softmmu="$vnc_png_libs $libs_softmmu"
3544     QEMU_CFLAGS="$QEMU_CFLAGS $vnc_png_cflags"
3545   else
3546     if test "$vnc_png" = "yes" ; then
3547       feature_not_found "vnc-png" "Install libpng devel"
3548     fi
3549     vnc_png=no
3550   fi
3551 fi
3552
3553 ##########################################
3554 # xkbcommon probe
3555 if test "$xkbcommon" != "no" ; then
3556   if $pkg_config xkbcommon --exists; then
3557     xkbcommon_cflags=$($pkg_config xkbcommon --cflags)
3558     xkbcommon_libs=$($pkg_config xkbcommon --libs)
3559     xkbcommon=yes
3560   else
3561     if test "$xkbcommon" = "yes" ; then
3562       feature_not_found "xkbcommon" "Install libxkbcommon-devel"
3563     fi
3564     xkbcommon=no
3565   fi
3566 fi
3567
3568
3569 ##########################################
3570 # xfsctl() probe, used for file-posix.c
3571 if test "$xfs" != "no" ; then
3572   cat > $TMPC << EOF
3573 #include <stddef.h>  /* NULL */
3574 #include <xfs/xfs.h>
3575 int main(void)
3576 {
3577     xfsctl(NULL, 0, 0, NULL);
3578     return 0;
3579 }
3580 EOF
3581   if compile_prog "" "" ; then
3582     xfs="yes"
3583   else
3584     if test "$xfs" = "yes" ; then
3585       feature_not_found "xfs" "Instal xfsprogs/xfslibs devel"
3586     fi
3587     xfs=no
3588   fi
3589 fi
3590
3591 ##########################################
3592 # vde libraries probe
3593 if test "$vde" != "no" ; then
3594   vde_libs="-lvdeplug"
3595   cat > $TMPC << EOF
3596 #include <libvdeplug.h>
3597 int main(void)
3598 {
3599     struct vde_open_args a = {0, 0, 0};
3600     char s[] = "";
3601     vde_open(s, s, &a);
3602     return 0;
3603 }
3604 EOF
3605   if compile_prog "" "$vde_libs" ; then
3606     vde=yes
3607   else
3608     if test "$vde" = "yes" ; then
3609       feature_not_found "vde" "Install vde (Virtual Distributed Ethernet) devel"
3610     fi
3611     vde=no
3612   fi
3613 fi
3614
3615 ##########################################
3616 # netmap support probe
3617 # Apart from looking for netmap headers, we make sure that the host API version
3618 # supports the netmap backend (>=11). The upper bound (15) is meant to simulate
3619 # a minor/major version number. Minor new features will be marked with values up
3620 # to 15, and if something happens that requires a change to the backend we will
3621 # move above 15, submit the backend fixes and modify this two bounds.
3622 if test "$netmap" != "no" ; then
3623   cat > $TMPC << EOF
3624 #include <inttypes.h>
3625 #include <net/if.h>
3626 #include <net/netmap.h>
3627 #include <net/netmap_user.h>
3628 #if (NETMAP_API < 11) || (NETMAP_API > 15)
3629 #error
3630 #endif
3631 int main(void) { return 0; }
3632 EOF
3633   if compile_prog "" "" ; then
3634     netmap=yes
3635   else
3636     if test "$netmap" = "yes" ; then
3637       feature_not_found "netmap"
3638     fi
3639     netmap=no
3640   fi
3641 fi
3642
3643 ##########################################
3644 # libcap-ng library probe
3645 if test "$cap_ng" != "no" ; then
3646   cap_libs="-lcap-ng"
3647   cat > $TMPC << EOF
3648 #include <cap-ng.h>
3649 int main(void)
3650 {
3651     capng_capability_to_name(CAPNG_EFFECTIVE);
3652     return 0;
3653 }
3654 EOF
3655   if compile_prog "" "$cap_libs" ; then
3656     cap_ng=yes
3657     libs_tools="$cap_libs $libs_tools"
3658   else
3659     if test "$cap_ng" = "yes" ; then
3660       feature_not_found "cap_ng" "Install libcap-ng devel"
3661     fi
3662     cap_ng=no
3663   fi
3664 fi
3665
3666 ##########################################
3667 # Sound support libraries probe
3668
3669 audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/,/ /g')
3670 for drv in $audio_drv_list; do
3671     case $drv in
3672     alsa | try-alsa)
3673     if $pkg_config alsa --exists; then
3674         alsa_libs=$($pkg_config alsa --libs)
3675         if test "$drv" = "try-alsa"; then
3676             audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-alsa/alsa/')
3677         fi
3678     else
3679         if test "$drv" = "try-alsa"; then
3680             audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-alsa//')
3681         else
3682             error_exit "$drv check failed" \
3683                 "Make sure to have the $drv libs and headers installed."
3684         fi
3685     fi
3686     ;;
3687
3688     pa | try-pa)
3689     if $pkg_config libpulse --exists; then
3690         pulse_libs=$($pkg_config libpulse --libs)
3691         if test "$drv" = "try-pa"; then
3692             audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-pa/pa/')
3693         fi
3694     else
3695         if test "$drv" = "try-pa"; then
3696             audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-pa//')
3697         else
3698             error_exit "$drv check failed" \
3699                 "Make sure to have the $drv libs and headers installed."
3700         fi
3701     fi
3702     ;;
3703
3704     sdl)
3705     if test "$sdl" = "no"; then
3706         error_exit "sdl not found or disabled, can not use sdl audio driver"
3707     fi
3708     ;;
3709
3710     try-sdl)
3711     if test "$sdl" = "no"; then
3712         audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-sdl//')
3713     else
3714         audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-sdl/sdl/')
3715     fi
3716     ;;
3717
3718     coreaudio)
3719       coreaudio_libs="-framework CoreAudio"
3720     ;;
3721
3722     dsound)
3723       dsound_libs="-lole32 -ldxguid"
3724       audio_win_int="yes"
3725     ;;
3726
3727     oss)
3728       oss_libs="$oss_lib"
3729     ;;
3730
3731     jack | try-jack)
3732     if $pkg_config jack --exists; then
3733         jack_libs=$($pkg_config jack --libs)
3734         if test "$drv" = "try-jack"; then
3735             audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-jack/jack/')
3736         fi
3737     else
3738         if test "$drv" = "try-jack"; then
3739             audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-jack//')
3740         else
3741             error_exit "$drv check failed" \
3742                 "Make sure to have the $drv libs and headers installed."
3743         fi
3744     fi
3745     ;;
3746
3747     *)
3748     echo "$audio_possible_drivers" | grep -q "\<$drv\>" || {
3749         error_exit "Unknown driver '$drv' selected" \
3750             "Possible drivers are: $audio_possible_drivers"
3751     }
3752     ;;
3753     esac
3754 done
3755
3756 ##########################################
3757 # BrlAPI probe
3758
3759 if test "$brlapi" != "no" ; then
3760   brlapi_libs="-lbrlapi"
3761   cat > $TMPC << EOF
3762 #include <brlapi.h>
3763 #include <stddef.h>
3764 int main( void ) { return brlapi__openConnection (NULL, NULL, NULL); }
3765 EOF
3766   if compile_prog "" "$brlapi_libs" ; then
3767     brlapi=yes
3768   else
3769     if test "$brlapi" = "yes" ; then
3770       feature_not_found "brlapi" "Install brlapi devel"
3771     fi
3772     brlapi=no
3773   fi
3774 fi
3775
3776 ##########################################
3777 # iconv probe
3778 if test "$iconv" != "no" ; then
3779   cat > $TMPC << EOF
3780 #include <iconv.h>
3781 int main(void) {
3782   iconv_t conv = iconv_open("WCHAR_T", "UCS-2");
3783   return conv != (iconv_t) -1;
3784 }
3785 EOF
3786   iconv_prefix_list="/usr/local:/usr"
3787   iconv_lib_list=":-liconv"
3788   IFS=:
3789   for iconv_prefix in $iconv_prefix_list; do
3790     IFS=:
3791     iconv_cflags="-I$iconv_prefix/include"
3792     iconv_ldflags="-L$iconv_prefix/lib"
3793     for iconv_link in $iconv_lib_list; do
3794       unset IFS
3795       iconv_lib="$iconv_ldflags $iconv_link"
3796       echo "looking at iconv in '$iconv_cflags' '$iconv_lib'" >> config.log
3797       if compile_prog "$iconv_cflags" "$iconv_lib" ; then
3798         iconv_found=yes
3799         break
3800       fi
3801     done
3802     if test "$iconv_found" = yes ; then
3803       break
3804     fi
3805   done
3806   if test "$iconv_found" = "yes" ; then
3807     iconv=yes
3808   else
3809     if test "$iconv" = "yes" ; then
3810       feature_not_found "iconv" "Install iconv devel"
3811     fi
3812     iconv=no
3813   fi
3814 fi
3815
3816 ##########################################
3817 # curses probe
3818 if test "$iconv" = "no" ; then
3819   # curses will need iconv
3820   curses=no
3821 fi
3822 if test "$curses" != "no" ; then
3823   if test "$mingw32" = "yes" ; then
3824     curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null):"
3825     curses_lib_list="$($pkg_config --libs ncurses 2>/dev/null):-lpdcurses"
3826   else
3827     curses_inc_list="$($pkg_config --cflags ncursesw 2>/dev/null):-I/usr/include/ncursesw:"
3828     curses_lib_list="$($pkg_config --libs ncursesw 2>/dev/null):-lncursesw:-lcursesw"
3829   fi
3830   curses_found=no
3831   cat > $TMPC << EOF
3832 #include <locale.h>
3833 #include <curses.h>
3834 #include <wchar.h>
3835 #include <langinfo.h>
3836 int main(void) {
3837   const char *codeset;
3838   wchar_t wch = L'w';
3839   setlocale(LC_ALL, "");
3840   resize_term(0, 0);
3841   addwstr(L"wide chars\n");
3842   addnwstr(&wch, 1);
3843   add_wch(WACS_DEGREE);
3844   codeset = nl_langinfo(CODESET);
3845   return codeset != 0;
3846 }
3847 EOF
3848   IFS=:
3849   for curses_inc in $curses_inc_list; do
3850     # Make sure we get the wide character prototypes
3851     curses_inc="-DNCURSES_WIDECHAR $curses_inc"
3852     IFS=:
3853     for curses_lib in $curses_lib_list; do
3854       unset IFS
3855       if compile_prog "$curses_inc" "$curses_lib" ; then
3856         curses_found=yes
3857         break
3858       fi
3859     done
3860     if test "$curses_found" = yes ; then
3861       break
3862     fi
3863   done
3864   unset IFS
3865   if test "$curses_found" = "yes" ; then
3866     curses=yes
3867   else
3868     if test "$curses" = "yes" ; then
3869       feature_not_found "curses" "Install ncurses devel"
3870     fi
3871     curses=no
3872   fi
3873 fi
3874
3875 ##########################################
3876 # curl probe
3877 if test "$curl" != "no" ; then
3878   if $pkg_config libcurl --exists; then
3879     curlconfig="$pkg_config libcurl"
3880   else
3881     curlconfig=curl-config
3882   fi
3883   cat > $TMPC << EOF
3884 #include <curl/curl.h>
3885 int main(void) { curl_easy_init(); curl_multi_setopt(0, 0, 0); return 0; }
3886 EOF
3887   curl_cflags=$($curlconfig --cflags 2>/dev/null)
3888   curl_libs=$($curlconfig --libs 2>/dev/null)
3889   if compile_prog "$curl_cflags" "$curl_libs" ; then
3890     curl=yes
3891   else
3892     if test "$curl" = "yes" ; then
3893       feature_not_found "curl" "Install libcurl devel"
3894     fi
3895     curl=no
3896   fi
3897 fi # test "$curl"
3898
3899 ##########################################
3900 # glib support probe
3901
3902 glib_req_ver=2.48
3903 glib_modules=gthread-2.0
3904 if test "$modules" = yes; then
3905     glib_modules="$glib_modules gmodule-export-2.0"
3906 fi
3907 if test "$plugins" = yes; then
3908     glib_modules="$glib_modules gmodule-2.0"
3909 fi
3910
3911 # This workaround is required due to a bug in pkg-config file for glib as it
3912 # doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
3913
3914 if test "$static" = yes && test "$mingw32" = yes; then
3915     QEMU_CFLAGS="-DGLIB_STATIC_COMPILATION $QEMU_CFLAGS"
3916 fi
3917
3918 for i in $glib_modules; do
3919     if $pkg_config --atleast-version=$glib_req_ver $i; then
3920         glib_cflags=$($pkg_config --cflags $i)
3921         glib_libs=$($pkg_config --libs $i)
3922         QEMU_CFLAGS="$glib_cflags $QEMU_CFLAGS"
3923         LIBS="$glib_libs $LIBS"
3924         libs_qga="$glib_libs $libs_qga"
3925     else
3926         error_exit "glib-$glib_req_ver $i is required to compile QEMU"
3927     fi
3928 done
3929
3930 if $pkg_config --atleast-version=$glib_req_ver gio-2.0; then
3931     gio=yes
3932     gio_cflags=$($pkg_config --cflags gio-2.0)
3933     gio_libs=$($pkg_config --libs gio-2.0)
3934     gdbus_codegen=$($pkg_config --variable=gdbus_codegen gio-2.0)
3935     if [ ! -x "$gdbus_codegen" ]; then
3936         gdbus_codegen=
3937     fi
3938 else
3939     gio=no
3940 fi
3941
3942 if $pkg_config --atleast-version=$glib_req_ver gio-unix-2.0; then
3943     gio_cflags="$gio_cflags $($pkg_config --cflags gio-unix-2.0)"
3944     gio_libs="$gio_libs $($pkg_config --libs gio-unix-2.0)"
3945 fi
3946
3947 # Sanity check that the current size_t matches the
3948 # size that glib thinks it should be. This catches
3949 # problems on multi-arch where people try to build
3950 # 32-bit QEMU while pointing at 64-bit glib headers
3951 cat > $TMPC <<EOF
3952 #include <glib.h>
3953 #include <unistd.h>
3954
3955 #define QEMU_BUILD_BUG_ON(x) \
3956   typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
3957
3958 int main(void) {
3959    QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
3960    return 0;
3961 }
3962 EOF
3963
3964 if ! compile_prog "$CFLAGS" "$LIBS" ; then
3965     error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
3966                "You probably need to set PKG_CONFIG_LIBDIR"\
3967                "to point to the right pkg-config files for your"\
3968                "build target"
3969 fi
3970
3971 # Silence clang 3.5.0 warnings about glib attribute __alloc_size__ usage
3972 cat > $TMPC << EOF
3973 #include <glib.h>
3974 int main(void) { return 0; }
3975 EOF
3976 if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
3977     if cc_has_warning_flag "-Wno-unknown-attributes"; then
3978         glib_cflags="-Wno-unknown-attributes $glib_cflags"
3979         CFLAGS="-Wno-unknown-attributes $CFLAGS"
3980     fi
3981 fi
3982
3983 # Silence clang warnings triggered by glib < 2.57.2
3984 cat > $TMPC << EOF
3985 #include <glib.h>
3986 typedef struct Foo {
3987     int i;
3988 } Foo;
3989 static void foo_free(Foo *f)
3990 {
3991     g_free(f);
3992 }
3993 G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free);
3994 int main(void) { return 0; }
3995 EOF
3996 if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
3997     if cc_has_warning_flag "-Wno-unused-function"; then
3998         glib_cflags="$glib_cflags -Wno-unused-function"
3999         CFLAGS="$CFLAGS -Wno-unused-function"
4000     fi
4001 fi
4002
4003 #########################################
4004 # zlib check
4005
4006 if test "$zlib" != "no" ; then
4007     if $pkg_config --exists zlib; then
4008         zlib_cflags=$($pkg_config --cflags zlib)
4009         zlib_libs=$($pkg_config --libs zlib)
4010         QEMU_CFLAGS="$zlib_cflags $QEMU_CFLAGS"
4011         LIBS="$zlib_libs $LIBS"
4012     else
4013         cat > $TMPC << EOF
4014 #include <zlib.h>
4015 int main(void) { zlibVersion(); return 0; }
4016 EOF
4017         if compile_prog "" "-lz" ; then
4018             LIBS="$LIBS -lz"
4019         else
4020             error_exit "zlib check failed" \
4021                 "Make sure to have the zlib libs and headers installed."
4022         fi
4023     fi
4024 fi
4025
4026 ##########################################
4027 # SHA command probe for modules
4028 if test "$modules" = yes; then
4029     shacmd_probe="sha1sum sha1 shasum"
4030     for c in $shacmd_probe; do
4031         if has $c; then
4032             shacmd="$c"
4033             break
4034         fi
4035     done
4036     if test "$shacmd" = ""; then
4037         error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
4038     fi
4039 fi
4040
4041 ##########################################
4042 # pixman support probe
4043
4044 if test "$softmmu" = "no"; then
4045   pixman_cflags=
4046   pixman_libs=
4047 elif $pkg_config --atleast-version=0.21.8 pixman-1 > /dev/null 2>&1; then
4048   pixman_cflags=$($pkg_config --cflags pixman-1)
4049   pixman_libs=$($pkg_config --libs pixman-1)
4050 else
4051   error_exit "pixman >= 0.21.8 not present." \
4052       "Please install the pixman devel package."
4053 fi
4054
4055 ##########################################
4056 # libmpathpersist probe
4057
4058 if test "$mpath" != "no" ; then
4059   # probe for the new API
4060   cat > $TMPC <<EOF
4061 #include <libudev.h>
4062 #include <mpath_persist.h>
4063 unsigned mpath_mx_alloc_len = 1024;
4064 int logsink;
4065 static struct config *multipath_conf;
4066 extern struct udev *udev;
4067 extern struct config *get_multipath_config(void);
4068 extern void put_multipath_config(struct config *conf);
4069 struct udev *udev;
4070 struct config *get_multipath_config(void) { return multipath_conf; }
4071 void put_multipath_config(struct config *conf) { }
4072
4073 int main(void) {
4074     udev = udev_new();
4075     multipath_conf = mpath_lib_init();
4076     return 0;
4077 }
4078 EOF
4079   if compile_prog "" "-ludev -lmultipath -lmpathpersist" ; then
4080     mpathpersist=yes
4081     mpathpersist_new_api=yes
4082   else
4083     # probe for the old API
4084     cat > $TMPC <<EOF
4085 #include <libudev.h>
4086 #include <mpath_persist.h>
4087 unsigned mpath_mx_alloc_len = 1024;
4088 int logsink;
4089 int main(void) {
4090     struct udev *udev = udev_new();
4091     mpath_lib_init(udev);
4092     return 0;
4093 }
4094 EOF
4095     if compile_prog "" "-ludev -lmultipath -lmpathpersist" ; then
4096       mpathpersist=yes
4097       mpathpersist_new_api=no
4098     else
4099       mpathpersist=no
4100     fi
4101   fi
4102 else
4103   mpathpersist=no
4104 fi
4105
4106 ##########################################
4107 # pthread probe
4108 PTHREADLIBS_LIST="-pthread -lpthread -lpthreadGC2"
4109
4110 pthread=no
4111 cat > $TMPC << EOF
4112 #include <pthread.h>
4113 static void *f(void *p) { return NULL; }
4114 int main(void) {
4115   pthread_t thread;
4116   pthread_create(&thread, 0, f, 0);
4117   return 0;
4118 }
4119 EOF
4120 if compile_prog "" "" ; then
4121   pthread=yes
4122 else
4123   for pthread_lib in $PTHREADLIBS_LIST; do
4124     if compile_prog "" "$pthread_lib" ; then
4125       pthread=yes
4126       found=no
4127       for lib_entry in $LIBS; do
4128         if test "$lib_entry" = "$pthread_lib"; then
4129           found=yes
4130           break
4131         fi
4132       done
4133       if test "$found" = "no"; then
4134         LIBS="$pthread_lib $LIBS"
4135         libs_qga="$pthread_lib $libs_qga"
4136       fi
4137       PTHREAD_LIB="$pthread_lib"
4138       break
4139     fi
4140   done
4141 fi
4142
4143 if test "$mingw32" != yes && test "$pthread" = no; then
4144   error_exit "pthread check failed" \
4145       "Make sure to have the pthread libs and headers installed."
4146 fi
4147
4148 # check for pthread_setname_np with thread id
4149 pthread_setname_np_w_tid=no
4150 cat > $TMPC << EOF
4151 #include <pthread.h>
4152
4153 static void *f(void *p) { return NULL; }
4154 int main(void)
4155 {
4156     pthread_t thread;
4157     pthread_create(&thread, 0, f, 0);
4158     pthread_setname_np(thread, "QEMU");
4159     return 0;
4160 }
4161 EOF
4162 if compile_prog "" "$pthread_lib" ; then
4163   pthread_setname_np_w_tid=yes
4164 fi
4165
4166 # check for pthread_setname_np without thread id
4167 pthread_setname_np_wo_tid=no
4168 cat > $TMPC << EOF
4169 #include <pthread.h>
4170
4171 static void *f(void *p) { pthread_setname_np("QEMU"); return NULL; }
4172 int main(void)
4173 {
4174     pthread_t thread;
4175     pthread_create(&thread, 0, f, 0);
4176     return 0;
4177 }
4178 EOF
4179 if compile_prog "" "$pthread_lib" ; then
4180   pthread_setname_np_wo_tid=yes
4181 fi
4182
4183 ##########################################
4184 # rbd probe
4185 if test "$rbd" != "no" ; then
4186   cat > $TMPC <<EOF
4187 #include <stdio.h>
4188 #include <rbd/librbd.h>
4189 int main(void) {
4190     rados_t cluster;
4191     rados_create(&cluster, NULL);
4192     return 0;
4193 }
4194 EOF
4195   rbd_libs="-lrbd -lrados"
4196   if compile_prog "" "$rbd_libs" ; then
4197     rbd=yes
4198   else
4199     if test "$rbd" = "yes" ; then
4200       feature_not_found "rados block device" "Install librbd/ceph devel"
4201     fi
4202     rbd=no
4203   fi
4204 fi
4205
4206 ##########################################
4207 # libssh probe
4208 if test "$libssh" != "no" ; then
4209   if $pkg_config --exists libssh; then
4210     libssh_cflags=$($pkg_config libssh --cflags)
4211     libssh_libs=$($pkg_config libssh --libs)
4212     libssh=yes
4213   else
4214     if test "$libssh" = "yes" ; then
4215       error_exit "libssh required for --enable-libssh"
4216     fi