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