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