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