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