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