xref: /openbmc/qemu/configure (revision ff66f3e5)
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
92quote_sh() {
93    printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
94}
95
96print_error() {
97    (echo
98    echo "ERROR: $1"
99    while test -n "$2"; do
100        echo "       $2"
101        shift
102    done
103    echo) >&2
104}
105
106error_exit() {
107    print_error "$@"
108    exit 1
109}
110
111do_compiler() {
112    # Run the compiler, capturing its output to the log. First argument
113    # is compiler binary to execute.
114    compiler="$1"
115    shift
116    if test -n "$BASH_VERSION"; then eval '
117        echo >>config.log "
118funcs: ${FUNCNAME[*]}
119lines: ${BASH_LINENO[*]}"
120    '; fi
121    echo $compiler "$@" >> config.log
122    $compiler "$@" >> config.log 2>&1 || return $?
123    # Test passed. If this is an --enable-werror build, rerun
124    # the test with -Werror and bail out if it fails. This
125    # makes warning-generating-errors in configure test code
126    # obvious to developers.
127    if test "$werror" != "yes"; then
128        return 0
129    fi
130    # Don't bother rerunning the compile if we were already using -Werror
131    case "$*" in
132        *-Werror*)
133           return 0
134        ;;
135    esac
136    echo $compiler -Werror "$@" >> config.log
137    $compiler -Werror "$@" >> config.log 2>&1 && return $?
138    error_exit "configure test passed without -Werror but failed with -Werror." \
139        "This is probably a bug in the configure script. The failing command" \
140        "will be at the bottom of config.log." \
141        "You can run configure with --disable-werror to bypass this check."
142}
143
144do_cc() {
145    do_compiler "$cc" $CPU_CFLAGS "$@"
146}
147
148do_cxx() {
149    do_compiler "$cxx" $CPU_CFLAGS "$@"
150}
151
152# Append $2 to the variable named $1, with space separation
153add_to() {
154    eval $1=\${$1:+\"\$$1 \"}\$2
155}
156
157update_cxxflags() {
158    # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
159    # options which some versions of GCC's C++ compiler complain about
160    # because they only make sense for C programs.
161    QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
162    CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
163    for arg in $QEMU_CFLAGS; do
164        case $arg in
165            -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
166            -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
167                ;;
168            *)
169                QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
170                ;;
171        esac
172    done
173}
174
175compile_object() {
176  local_cflags="$1"
177  do_cc $CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
178}
179
180compile_prog() {
181  local_cflags="$1"
182  local_ldflags="$2"
183  do_cc $CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
184      $LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
185}
186
187# symbolically link $1 to $2.  Portable version of "ln -sf".
188symlink() {
189  rm -rf "$2"
190  mkdir -p "$(dirname "$2")"
191  ln -s "$1" "$2"
192}
193
194# check whether a command is available to this shell (may be either an
195# executable or a builtin)
196has() {
197    type "$1" >/dev/null 2>&1
198}
199
200version_ge () {
201    local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
202    local_ver2=$(echo "$2" | tr . ' ')
203    while true; do
204        set x $local_ver1
205        local_first=${2-0}
206        # 'shift 2' if $2 is set, or 'shift' if $2 is not set
207        shift ${2:+2}
208        local_ver1=$*
209        set x $local_ver2
210        # the second argument finished, the first must be greater or equal
211        test $# = 1 && return 0
212        test $local_first -lt $2 && return 1
213        test $local_first -gt $2 && return 0
214        shift ${2:+2}
215        local_ver2=$*
216    done
217}
218
219glob() {
220    eval test -z '"${1#'"$2"'}"'
221}
222
223ld_has() {
224    $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
225}
226
227if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
228then
229  error_exit "main directory cannot contain spaces nor colons"
230fi
231
232# default parameters
233cpu=""
234iasl="iasl"
235interp_prefix="/usr/gnemul/qemu-%M"
236static="no"
237cross_compile="no"
238cross_prefix=""
239audio_drv_list="default"
240block_drv_rw_whitelist=""
241block_drv_ro_whitelist=""
242block_drv_whitelist_tools="no"
243host_cc="cc"
244libs_qga=""
245debug_info="yes"
246lto="false"
247stack_protector=""
248safe_stack=""
249use_containers="yes"
250gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
251
252if test -e "$source_path/.git"
253then
254    git_submodules_action="update"
255else
256    git_submodules_action="ignore"
257fi
258
259git_submodules="ui/keycodemapdb"
260git="git"
261
262# Don't accept a target_list environment variable.
263unset target_list
264unset target_list_exclude
265
266# Default value for a variable defining feature "foo".
267#  * foo="no"  feature will only be used if --enable-foo arg is given
268#  * foo=""    feature will be searched for, and if found, will be used
269#              unless --disable-foo is given
270#  * foo="yes" this value will only be set by --enable-foo flag.
271#              feature will searched for,
272#              if not found, configure exits with error
273#
274# Always add --enable-foo and --disable-foo command line args.
275# Distributions want to ensure that several features are compiled in, and it
276# is impossible without a --enable-foo that exits if a feature is not found.
277
278default_feature=""
279# parse CC options second
280for opt do
281  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
282  case "$opt" in
283      --without-default-features)
284          default_feature="no"
285  ;;
286  esac
287done
288
289brlapi="auto"
290curl="auto"
291iconv="auto"
292curses="auto"
293docs="auto"
294fdt="auto"
295netmap="no"
296sdl="auto"
297sdl_image="auto"
298virtiofsd="auto"
299virtfs="auto"
300libudev="auto"
301mpath="auto"
302vnc="auto"
303sparse="auto"
304vde="$default_feature"
305vnc_sasl="auto"
306vnc_jpeg="auto"
307vnc_png="auto"
308xkbcommon="auto"
309alsa="auto"
310coreaudio="auto"
311dsound="auto"
312jack="auto"
313oss="auto"
314pa="auto"
315xen=${default_feature:+disabled}
316xen_ctrl_version="$default_feature"
317xen_pci_passthrough="auto"
318linux_aio="auto"
319linux_io_uring="auto"
320cap_ng="auto"
321attr="auto"
322xfs="$default_feature"
323tcg="enabled"
324membarrier="$default_feature"
325vhost_kernel="$default_feature"
326vhost_net="$default_feature"
327vhost_crypto="$default_feature"
328vhost_scsi="$default_feature"
329vhost_vsock="$default_feature"
330vhost_user="no"
331vhost_user_blk_server="auto"
332vhost_user_fs="$default_feature"
333vhost_vdpa="$default_feature"
334bpf="auto"
335kvm="auto"
336hax="auto"
337hvf="auto"
338whpx="auto"
339nvmm="auto"
340rdma="$default_feature"
341pvrdma="$default_feature"
342gprof="no"
343debug_tcg="no"
344debug="no"
345sanitizers="no"
346tsan="no"
347fortify_source="$default_feature"
348strip_opt="yes"
349tcg_interpreter="false"
350mingw32="no"
351gcov="no"
352EXESUF=""
353modules="no"
354module_upgrades="no"
355prefix="/usr/local"
356qemu_suffix="qemu"
357slirp="auto"
358bsd="no"
359linux="no"
360solaris="no"
361profiler="no"
362cocoa="auto"
363softmmu="yes"
364linux_user="no"
365bsd_user="no"
366blobs="true"
367pkgversion=""
368pie=""
369qom_cast_debug="yes"
370trace_backends="log"
371trace_file="trace"
372spice="$default_feature"
373spice_protocol="auto"
374rbd="auto"
375smartcard="auto"
376u2f="auto"
377libusb="auto"
378usb_redir="auto"
379opengl="$default_feature"
380cpuid_h="no"
381avx2_opt="$default_feature"
382capstone="auto"
383lzo="auto"
384snappy="auto"
385bzip2="auto"
386lzfse="auto"
387zstd="auto"
388guest_agent="$default_feature"
389guest_agent_with_vss="no"
390guest_agent_ntddscsi="no"
391guest_agent_msi="auto"
392vss_win32_sdk="$default_feature"
393win_sdk="no"
394want_tools="$default_feature"
395libiscsi="auto"
396libnfs="auto"
397coroutine=""
398coroutine_pool="$default_feature"
399debug_stack_usage="no"
400crypto_afalg="no"
401cfi="false"
402cfi_debug="false"
403seccomp="auto"
404glusterfs="auto"
405gtk="auto"
406tls_priority="NORMAL"
407gnutls="auto"
408nettle="auto"
409gcrypt="auto"
410auth_pam="auto"
411vte="auto"
412virglrenderer="auto"
413tpm="$default_feature"
414libssh="$default_feature"
415live_block_migration=${default_feature:-yes}
416numa="$default_feature"
417tcmalloc="no"
418jemalloc="no"
419replication=${default_feature:-yes}
420bochs=${default_feature:-yes}
421cloop=${default_feature:-yes}
422dmg=${default_feature:-yes}
423qcow1=${default_feature:-yes}
424vdi=${default_feature:-yes}
425vvfat=${default_feature:-yes}
426qed=${default_feature:-yes}
427parallels=${default_feature:-yes}
428libxml2="auto"
429debug_mutex="no"
430libpmem="auto"
431default_devices="true"
432plugins="$default_feature"
433fuzzing="false"
434rng_none="no"
435secret_keyring="$default_feature"
436libdaxctl="auto"
437meson=""
438ninja=""
439skip_meson=no
440gettext="auto"
441fuse="auto"
442fuse_lseek="auto"
443multiprocess="auto"
444slirp_smbd="$default_feature"
445
446malloc_trim="auto"
447gio="$default_feature"
448
449# parse CC options second
450for opt do
451  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
452  case "$opt" in
453  --cross-prefix=*) cross_prefix="$optarg"
454                    cross_compile="yes"
455  ;;
456  --cc=*) CC="$optarg"
457  ;;
458  --cxx=*) CXX="$optarg"
459  ;;
460  --cpu=*) cpu="$optarg"
461  ;;
462  --extra-cflags=*) QEMU_CFLAGS="$QEMU_CFLAGS $optarg"
463                    QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
464  ;;
465  --extra-cxxflags=*) QEMU_CXXFLAGS="$QEMU_CXXFLAGS $optarg"
466  ;;
467  --extra-ldflags=*) QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
468                     EXTRA_LDFLAGS="$optarg"
469  ;;
470  --enable-debug-info) debug_info="yes"
471  ;;
472  --disable-debug-info) debug_info="no"
473  ;;
474  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
475  ;;
476  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-flags-}; cc_arch=${cc_arch%%=*}
477                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
478                      cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
479  ;;
480  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
481                cc_archs="$cc_archs $cc_arch"
482                eval "cross_cc_${cc_arch}=\$optarg"
483                cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
484  ;;
485  esac
486done
487# OS specific
488# Using uname is really, really broken.  Once we have the right set of checks
489# we can eliminate its usage altogether.
490
491# Preferred compiler:
492#  ${CC} (if set)
493#  ${cross_prefix}gcc (if cross-prefix specified)
494#  system compiler
495if test -z "${CC}${cross_prefix}"; then
496  cc="$host_cc"
497else
498  cc="${CC-${cross_prefix}gcc}"
499fi
500
501if test -z "${CXX}${cross_prefix}"; then
502  cxx="c++"
503else
504  cxx="${CXX-${cross_prefix}g++}"
505fi
506
507ar="${AR-${cross_prefix}ar}"
508as="${AS-${cross_prefix}as}"
509ccas="${CCAS-$cc}"
510cpp="${CPP-$cc -E}"
511objcopy="${OBJCOPY-${cross_prefix}objcopy}"
512ld="${LD-${cross_prefix}ld}"
513ranlib="${RANLIB-${cross_prefix}ranlib}"
514nm="${NM-${cross_prefix}nm}"
515strip="${STRIP-${cross_prefix}strip}"
516windres="${WINDRES-${cross_prefix}windres}"
517pkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
518query_pkg_config() {
519    "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
520}
521pkg_config=query_pkg_config
522sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
523
524# default flags for all hosts
525# We use -fwrapv to tell the compiler that we require a C dialect where
526# left shift of signed integers is well defined and has the expected
527# 2s-complement style results. (Both clang and gcc agree that it
528# provides these semantics.)
529QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv $QEMU_CFLAGS"
530QEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
531QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
532QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
533
534# Flags that are needed during configure but later taken care of by Meson
535CONFIGURE_CFLAGS="-std=gnu11 -Wall"
536CONFIGURE_LDFLAGS=
537
538
539check_define() {
540cat > $TMPC <<EOF
541#if !defined($1)
542#error $1 not defined
543#endif
544int main(void) { return 0; }
545EOF
546  compile_object
547}
548
549check_include() {
550cat > $TMPC <<EOF
551#include <$1>
552int main(void) { return 0; }
553EOF
554  compile_object
555}
556
557write_c_skeleton() {
558    cat > $TMPC <<EOF
559int main(void) { return 0; }
560EOF
561}
562
563if check_define __linux__ ; then
564  targetos="Linux"
565elif check_define _WIN32 ; then
566  targetos='MINGW32'
567elif check_define __OpenBSD__ ; then
568  targetos='OpenBSD'
569elif check_define __sun__ ; then
570  targetos='SunOS'
571elif check_define __HAIKU__ ; then
572  targetos='Haiku'
573elif check_define __FreeBSD__ ; then
574  targetos='FreeBSD'
575elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
576  targetos='GNU/kFreeBSD'
577elif check_define __DragonFly__ ; then
578  targetos='DragonFly'
579elif check_define __NetBSD__; then
580  targetos='NetBSD'
581elif check_define __APPLE__; then
582  targetos='Darwin'
583else
584  # This is a fatal error, but don't report it yet, because we
585  # might be going to just print the --help text, or it might
586  # be the result of a missing compiler.
587  targetos='bogus'
588fi
589
590# Some host OSes need non-standard checks for which CPU to use.
591# Note that these checks are broken for cross-compilation: if you're
592# cross-compiling to one of these OSes then you'll need to specify
593# the correct CPU with the --cpu option.
594case $targetos in
595SunOS)
596  # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
597  if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
598    cpu="x86_64"
599  fi
600esac
601
602if test ! -z "$cpu" ; then
603  # command line argument
604  :
605elif check_define __i386__ ; then
606  cpu="i386"
607elif check_define __x86_64__ ; then
608  if check_define __ILP32__ ; then
609    cpu="x32"
610  else
611    cpu="x86_64"
612  fi
613elif check_define __sparc__ ; then
614  if check_define __arch64__ ; then
615    cpu="sparc64"
616  else
617    cpu="sparc"
618  fi
619elif check_define _ARCH_PPC ; then
620  if check_define _ARCH_PPC64 ; then
621    if check_define _LITTLE_ENDIAN ; then
622      cpu="ppc64le"
623    else
624      cpu="ppc64"
625    fi
626  else
627    cpu="ppc"
628  fi
629elif check_define __mips__ ; then
630  cpu="mips"
631elif check_define __s390__ ; then
632  if check_define __s390x__ ; then
633    cpu="s390x"
634  else
635    cpu="s390"
636  fi
637elif check_define __riscv ; then
638  if check_define _LP64 ; then
639    cpu="riscv64"
640  else
641    cpu="riscv32"
642  fi
643elif check_define __arm__ ; then
644  cpu="arm"
645elif check_define __aarch64__ ; then
646  cpu="aarch64"
647else
648  cpu=$(uname -m)
649fi
650
651ARCH=
652# Normalise host CPU name and set ARCH.
653# Note that this case should only have supported host CPUs, not guests.
654case "$cpu" in
655  ppc|ppc64|s390x|sparc64|x32|riscv32|riscv64)
656  ;;
657  ppc64le)
658    ARCH="ppc64"
659  ;;
660  i386|i486|i586|i686|i86pc|BePC)
661    cpu="i386"
662  ;;
663  x86_64|amd64)
664    cpu="x86_64"
665  ;;
666  armv*b|armv*l|arm)
667    cpu="arm"
668  ;;
669  aarch64)
670    cpu="aarch64"
671  ;;
672  mips*)
673    cpu="mips"
674  ;;
675  sparc|sun4[cdmuv])
676    cpu="sparc"
677  ;;
678  *)
679    # This will result in either an error or falling back to TCI later
680    ARCH=unknown
681  ;;
682esac
683if test -z "$ARCH"; then
684  ARCH="$cpu"
685fi
686
687# OS specific
688
689case $targetos in
690MINGW32*)
691  mingw32="yes"
692  supported_os="yes"
693  plugins="no"
694  pie="no"
695;;
696GNU/kFreeBSD)
697  bsd="yes"
698;;
699FreeBSD)
700  bsd="yes"
701  bsd_user="yes"
702  make="${MAKE-gmake}"
703  # needed for kinfo_getvmmap(3) in libutil.h
704  netmap=""  # enable netmap autodetect
705;;
706DragonFly)
707  bsd="yes"
708  make="${MAKE-gmake}"
709;;
710NetBSD)
711  bsd="yes"
712  make="${MAKE-gmake}"
713;;
714OpenBSD)
715  bsd="yes"
716  make="${MAKE-gmake}"
717;;
718Darwin)
719  bsd="yes"
720  darwin="yes"
721  # Disable attempts to use ObjectiveC features in os/object.h since they
722  # won't work when we're compiling with gcc as a C compiler.
723  QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
724;;
725SunOS)
726  solaris="yes"
727  make="${MAKE-gmake}"
728  smbd="${SMBD-/usr/sfw/sbin/smbd}"
729# needed for CMSG_ macros in sys/socket.h
730  QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
731# needed for TIOCWIN* defines in termios.h
732  QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
733;;
734Haiku)
735  haiku="yes"
736  pie="no"
737  QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
738;;
739Linux)
740  linux="yes"
741  linux_user="yes"
742  vhost_user=${default_feature:-yes}
743;;
744esac
745
746: ${make=${MAKE-make}}
747
748# We prefer python 3.x. A bare 'python' is traditionally
749# python 2.x, but some distros have it as python 3.x, so
750# we check that too
751python=
752explicit_python=no
753for binary in "${PYTHON-python3}" python
754do
755    if has "$binary"
756    then
757        python=$(command -v "$binary")
758        break
759    fi
760done
761
762
763# Check for ancillary tools used in testing
764genisoimage=
765for binary in genisoimage mkisofs
766do
767    if has $binary
768    then
769        genisoimage=$(command -v "$binary")
770        break
771    fi
772done
773
774# Default objcc to clang if available, otherwise use CC
775if has clang; then
776  objcc=clang
777else
778  objcc="$cc"
779fi
780
781if test "$mingw32" = "yes" ; then
782  EXESUF=".exe"
783  # MinGW needs -mthreads for TLS and macro _MT.
784  CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
785  write_c_skeleton;
786  prefix="/qemu"
787  qemu_suffix=""
788  libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi -lnetapi32 $libs_qga"
789fi
790
791werror=""
792
793for opt do
794  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
795  case "$opt" in
796  --help|-h) show_help=yes
797  ;;
798  --version|-V) exec cat $source_path/VERSION
799  ;;
800  --prefix=*) prefix="$optarg"
801  ;;
802  --interp-prefix=*) interp_prefix="$optarg"
803  ;;
804  --cross-prefix=*)
805  ;;
806  --cc=*)
807  ;;
808  --host-cc=*) host_cc="$optarg"
809  ;;
810  --cxx=*)
811  ;;
812  --iasl=*) iasl="$optarg"
813  ;;
814  --objcc=*) objcc="$optarg"
815  ;;
816  --make=*) make="$optarg"
817  ;;
818  --install=*)
819  ;;
820  --python=*) python="$optarg" ; explicit_python=yes
821  ;;
822  --sphinx-build=*) sphinx_build="$optarg"
823  ;;
824  --skip-meson) skip_meson=yes
825  ;;
826  --meson=*) meson="$optarg"
827  ;;
828  --ninja=*) ninja="$optarg"
829  ;;
830  --smbd=*) smbd="$optarg"
831  ;;
832  --extra-cflags=*)
833  ;;
834  --extra-cxxflags=*)
835  ;;
836  --extra-ldflags=*)
837  ;;
838  --enable-debug-info)
839  ;;
840  --disable-debug-info)
841  ;;
842  --cross-cc-*)
843  ;;
844  --enable-modules)
845      modules="yes"
846  ;;
847  --disable-modules)
848      modules="no"
849  ;;
850  --disable-module-upgrades) module_upgrades="no"
851  ;;
852  --enable-module-upgrades) module_upgrades="yes"
853  ;;
854  --cpu=*)
855  ;;
856  --target-list=*) target_list="$optarg"
857                   if test "$target_list_exclude"; then
858                       error_exit "Can't mix --target-list with --target-list-exclude"
859                   fi
860  ;;
861  --target-list-exclude=*) target_list_exclude="$optarg"
862                   if test "$target_list"; then
863                       error_exit "Can't mix --target-list-exclude with --target-list"
864                   fi
865  ;;
866  --enable-trace-backends=*) trace_backends="$optarg"
867  ;;
868  # XXX: backwards compatibility
869  --enable-trace-backend=*) trace_backends="$optarg"
870  ;;
871  --with-trace-file=*) trace_file="$optarg"
872  ;;
873  --with-default-devices) default_devices="true"
874  ;;
875  --without-default-devices) default_devices="false"
876  ;;
877  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
878  ;;
879  --with-devices-*) device_arch=${opt#--with-devices-};
880                    device_arch=${device_arch%%=*}
881                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
882                    if test -f "$cf"; then
883                        device_archs="$device_archs $device_arch"
884                        eval "devices_${device_arch}=\$optarg"
885                    else
886                        error_exit "File $cf does not exist"
887                    fi
888  ;;
889  --without-default-features) # processed above
890  ;;
891  --enable-gprof) gprof="yes"
892  ;;
893  --enable-gcov) gcov="yes"
894  ;;
895  --static)
896    static="yes"
897    QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
898  ;;
899  --mandir=*) mandir="$optarg"
900  ;;
901  --bindir=*) bindir="$optarg"
902  ;;
903  --libdir=*) libdir="$optarg"
904  ;;
905  --libexecdir=*) libexecdir="$optarg"
906  ;;
907  --includedir=*) includedir="$optarg"
908  ;;
909  --datadir=*) datadir="$optarg"
910  ;;
911  --with-suffix=*) qemu_suffix="$optarg"
912  ;;
913  --docdir=*) docdir="$optarg"
914  ;;
915  --localedir=*) localedir="$optarg"
916  ;;
917  --sysconfdir=*) sysconfdir="$optarg"
918  ;;
919  --localstatedir=*) local_statedir="$optarg"
920  ;;
921  --firmwarepath=*) firmwarepath="$optarg"
922  ;;
923  --host=*|--build=*|\
924  --disable-dependency-tracking|\
925  --sbindir=*|--sharedstatedir=*|\
926  --oldincludedir=*|--datarootdir=*|--infodir=*|\
927  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
928    # These switches are silently ignored, for compatibility with
929    # autoconf-generated configure scripts. This allows QEMU's
930    # configure to be used by RPM and similar macros that set
931    # lots of directory switches by default.
932  ;;
933  --disable-sdl) sdl="disabled"
934  ;;
935  --enable-sdl) sdl="enabled"
936  ;;
937  --disable-sdl-image) sdl_image="disabled"
938  ;;
939  --enable-sdl-image) sdl_image="enabled"
940  ;;
941  --disable-qom-cast-debug) qom_cast_debug="no"
942  ;;
943  --enable-qom-cast-debug) qom_cast_debug="yes"
944  ;;
945  --disable-virtfs) virtfs="disabled"
946  ;;
947  --enable-virtfs) virtfs="enabled"
948  ;;
949  --disable-libudev) libudev="disabled"
950  ;;
951  --enable-libudev) libudev="enabled"
952  ;;
953  --disable-virtiofsd) virtiofsd="disabled"
954  ;;
955  --enable-virtiofsd) virtiofsd="enabled"
956  ;;
957  --disable-mpath) mpath="disabled"
958  ;;
959  --enable-mpath) mpath="enabled"
960  ;;
961  --disable-vnc) vnc="disabled"
962  ;;
963  --enable-vnc) vnc="enabled"
964  ;;
965  --disable-gettext) gettext="disabled"
966  ;;
967  --enable-gettext) gettext="enabled"
968  ;;
969  --audio-drv-list=*) audio_drv_list="$optarg"
970  ;;
971  --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
972  ;;
973  --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
974  ;;
975  --enable-block-drv-whitelist-in-tools) block_drv_whitelist_tools="yes"
976  ;;
977  --disable-block-drv-whitelist-in-tools) block_drv_whitelist_tools="no"
978  ;;
979  --enable-debug-tcg) debug_tcg="yes"
980  ;;
981  --disable-debug-tcg) debug_tcg="no"
982  ;;
983  --enable-debug)
984      # Enable debugging options that aren't excessively noisy
985      debug_tcg="yes"
986      debug_mutex="yes"
987      debug="yes"
988      strip_opt="no"
989      fortify_source="no"
990  ;;
991  --enable-sanitizers) sanitizers="yes"
992  ;;
993  --disable-sanitizers) sanitizers="no"
994  ;;
995  --enable-tsan) tsan="yes"
996  ;;
997  --disable-tsan) tsan="no"
998  ;;
999  --enable-sparse) sparse="enabled"
1000  ;;
1001  --disable-sparse) sparse="disabled"
1002  ;;
1003  --disable-strip) strip_opt="no"
1004  ;;
1005  --disable-vnc-sasl) vnc_sasl="disabled"
1006  ;;
1007  --enable-vnc-sasl) vnc_sasl="enabled"
1008  ;;
1009  --disable-vnc-jpeg) vnc_jpeg="disabled"
1010  ;;
1011  --enable-vnc-jpeg) vnc_jpeg="enabled"
1012  ;;
1013  --disable-vnc-png) vnc_png="disabled"
1014  ;;
1015  --enable-vnc-png) vnc_png="enabled"
1016  ;;
1017  --disable-slirp) slirp="disabled"
1018  ;;
1019  --enable-slirp) slirp="enabled"
1020  ;;
1021  --enable-slirp=git) slirp="internal"
1022  ;;
1023  --enable-slirp=system) slirp="system"
1024  ;;
1025  --disable-vde) vde="no"
1026  ;;
1027  --enable-vde) vde="yes"
1028  ;;
1029  --disable-netmap) netmap="no"
1030  ;;
1031  --enable-netmap) netmap="yes"
1032  ;;
1033  --disable-xen) xen="disabled"
1034  ;;
1035  --enable-xen) xen="enabled"
1036  ;;
1037  --disable-xen-pci-passthrough) xen_pci_passthrough="disabled"
1038  ;;
1039  --enable-xen-pci-passthrough) xen_pci_passthrough="enabled"
1040  ;;
1041  --disable-alsa) alsa="disabled"
1042  ;;
1043  --enable-alsa) alsa="enabled"
1044  ;;
1045  --disable-coreaudio) coreaudio="disabled"
1046  ;;
1047  --enable-coreaudio) coreaudio="enabled"
1048  ;;
1049  --disable-dsound) dsound="disabled"
1050  ;;
1051  --enable-dsound) dsound="enabled"
1052  ;;
1053  --disable-jack) jack="disabled"
1054  ;;
1055  --enable-jack) jack="enabled"
1056  ;;
1057  --disable-oss) oss="disabled"
1058  ;;
1059  --enable-oss) oss="enabled"
1060  ;;
1061  --disable-pa) pa="disabled"
1062  ;;
1063  --enable-pa) pa="enabled"
1064  ;;
1065  --disable-brlapi) brlapi="disabled"
1066  ;;
1067  --enable-brlapi) brlapi="enabled"
1068  ;;
1069  --disable-kvm) kvm="disabled"
1070  ;;
1071  --enable-kvm) kvm="enabled"
1072  ;;
1073  --disable-hax) hax="disabled"
1074  ;;
1075  --enable-hax) hax="enabled"
1076  ;;
1077  --disable-hvf) hvf="disabled"
1078  ;;
1079  --enable-hvf) hvf="enabled"
1080  ;;
1081  --disable-nvmm) nvmm="disabled"
1082  ;;
1083  --enable-nvmm) nvmm="enabled"
1084  ;;
1085  --disable-whpx) whpx="disabled"
1086  ;;
1087  --enable-whpx) whpx="enabled"
1088  ;;
1089  --disable-tcg-interpreter) tcg_interpreter="false"
1090  ;;
1091  --enable-tcg-interpreter) tcg_interpreter="true"
1092  ;;
1093  --disable-cap-ng)  cap_ng="disabled"
1094  ;;
1095  --enable-cap-ng) cap_ng="enabled"
1096  ;;
1097  --disable-tcg) tcg="disabled"
1098                 plugins="no"
1099  ;;
1100  --enable-tcg) tcg="enabled"
1101  ;;
1102  --disable-malloc-trim) malloc_trim="disabled"
1103  ;;
1104  --enable-malloc-trim) malloc_trim="enabled"
1105  ;;
1106  --disable-spice) spice="no"
1107  ;;
1108  --enable-spice)
1109      spice_protocol="yes"
1110      spice="yes"
1111  ;;
1112  --disable-spice-protocol)
1113      spice_protocol="no"
1114      spice="no"
1115  ;;
1116  --enable-spice-protocol) spice_protocol="yes"
1117  ;;
1118  --disable-libiscsi) libiscsi="disabled"
1119  ;;
1120  --enable-libiscsi) libiscsi="enabled"
1121  ;;
1122  --disable-libnfs) libnfs="disabled"
1123  ;;
1124  --enable-libnfs) libnfs="enabled"
1125  ;;
1126  --enable-profiler) profiler="yes"
1127  ;;
1128  --disable-cocoa) cocoa="disabled"
1129  ;;
1130  --enable-cocoa) cocoa="enabled"
1131  ;;
1132  --disable-system) softmmu="no"
1133  ;;
1134  --enable-system) softmmu="yes"
1135  ;;
1136  --disable-user)
1137      linux_user="no" ;
1138      bsd_user="no" ;
1139  ;;
1140  --enable-user) ;;
1141  --disable-linux-user) linux_user="no"
1142  ;;
1143  --enable-linux-user) linux_user="yes"
1144  ;;
1145  --disable-bsd-user) bsd_user="no"
1146  ;;
1147  --enable-bsd-user) bsd_user="yes"
1148  ;;
1149  --enable-pie) pie="yes"
1150  ;;
1151  --disable-pie) pie="no"
1152  ;;
1153  --enable-werror) werror="yes"
1154  ;;
1155  --disable-werror) werror="no"
1156  ;;
1157  --enable-lto) lto="true"
1158  ;;
1159  --disable-lto) lto="false"
1160  ;;
1161  --enable-stack-protector) stack_protector="yes"
1162  ;;
1163  --disable-stack-protector) stack_protector="no"
1164  ;;
1165  --enable-safe-stack) safe_stack="yes"
1166  ;;
1167  --disable-safe-stack) safe_stack="no"
1168  ;;
1169  --enable-cfi)
1170      cfi="true";
1171      lto="true";
1172  ;;
1173  --disable-cfi) cfi="false"
1174  ;;
1175  --enable-cfi-debug) cfi_debug="true"
1176  ;;
1177  --disable-cfi-debug) cfi_debug="false"
1178  ;;
1179  --disable-curses) curses="disabled"
1180  ;;
1181  --enable-curses) curses="enabled"
1182  ;;
1183  --disable-iconv) iconv="disabled"
1184  ;;
1185  --enable-iconv) iconv="enabled"
1186  ;;
1187  --disable-curl) curl="disabled"
1188  ;;
1189  --enable-curl) curl="enabled"
1190  ;;
1191  --disable-fdt) fdt="disabled"
1192  ;;
1193  --enable-fdt) fdt="enabled"
1194  ;;
1195  --enable-fdt=git) fdt="internal"
1196  ;;
1197  --enable-fdt=system) fdt="system"
1198  ;;
1199  --disable-linux-aio) linux_aio="disabled"
1200  ;;
1201  --enable-linux-aio) linux_aio="enabled"
1202  ;;
1203  --disable-linux-io-uring) linux_io_uring="disabled"
1204  ;;
1205  --enable-linux-io-uring) linux_io_uring="enabled"
1206  ;;
1207  --disable-attr) attr="disabled"
1208  ;;
1209  --enable-attr) attr="enabled"
1210  ;;
1211  --disable-membarrier) membarrier="no"
1212  ;;
1213  --enable-membarrier) membarrier="yes"
1214  ;;
1215  --disable-bpf) bpf="disabled"
1216  ;;
1217  --enable-bpf) bpf="enabled"
1218  ;;
1219  --disable-blobs) blobs="false"
1220  ;;
1221  --with-pkgversion=*) pkgversion="$optarg"
1222  ;;
1223  --with-coroutine=*) coroutine="$optarg"
1224  ;;
1225  --disable-coroutine-pool) coroutine_pool="no"
1226  ;;
1227  --enable-coroutine-pool) coroutine_pool="yes"
1228  ;;
1229  --enable-debug-stack-usage) debug_stack_usage="yes"
1230  ;;
1231  --enable-crypto-afalg) crypto_afalg="yes"
1232  ;;
1233  --disable-crypto-afalg) crypto_afalg="no"
1234  ;;
1235  --disable-docs) docs="disabled"
1236  ;;
1237  --enable-docs) docs="enabled"
1238  ;;
1239  --disable-vhost-net) vhost_net="no"
1240  ;;
1241  --enable-vhost-net) vhost_net="yes"
1242  ;;
1243  --disable-vhost-crypto) vhost_crypto="no"
1244  ;;
1245  --enable-vhost-crypto) vhost_crypto="yes"
1246  ;;
1247  --disable-vhost-scsi) vhost_scsi="no"
1248  ;;
1249  --enable-vhost-scsi) vhost_scsi="yes"
1250  ;;
1251  --disable-vhost-vsock) vhost_vsock="no"
1252  ;;
1253  --enable-vhost-vsock) vhost_vsock="yes"
1254  ;;
1255  --disable-vhost-user-blk-server) vhost_user_blk_server="disabled"
1256  ;;
1257  --enable-vhost-user-blk-server) vhost_user_blk_server="enabled"
1258  ;;
1259  --disable-vhost-user-fs) vhost_user_fs="no"
1260  ;;
1261  --enable-vhost-user-fs) vhost_user_fs="yes"
1262  ;;
1263  --disable-opengl) opengl="no"
1264  ;;
1265  --enable-opengl) opengl="yes"
1266  ;;
1267  --disable-rbd) rbd="disabled"
1268  ;;
1269  --enable-rbd) rbd="enabled"
1270  ;;
1271  --disable-xfsctl) xfs="no"
1272  ;;
1273  --enable-xfsctl) xfs="yes"
1274  ;;
1275  --disable-smartcard) smartcard="disabled"
1276  ;;
1277  --enable-smartcard) smartcard="enabled"
1278  ;;
1279  --disable-u2f) u2f="disabled"
1280  ;;
1281  --enable-u2f) u2f="enabled"
1282  ;;
1283  --disable-libusb) libusb="disabled"
1284  ;;
1285  --enable-libusb) libusb="enabled"
1286  ;;
1287  --disable-usb-redir) usb_redir="disabled"
1288  ;;
1289  --enable-usb-redir) usb_redir="enabled"
1290  ;;
1291  --disable-zlib-test)
1292  ;;
1293  --disable-lzo) lzo="disabled"
1294  ;;
1295  --enable-lzo) lzo="enabled"
1296  ;;
1297  --disable-snappy) snappy="disabled"
1298  ;;
1299  --enable-snappy) snappy="enabled"
1300  ;;
1301  --disable-bzip2) bzip2="disabled"
1302  ;;
1303  --enable-bzip2) bzip2="enabled"
1304  ;;
1305  --enable-lzfse) lzfse="enabled"
1306  ;;
1307  --disable-lzfse) lzfse="disabled"
1308  ;;
1309  --disable-zstd) zstd="disabled"
1310  ;;
1311  --enable-zstd) zstd="enabled"
1312  ;;
1313  --enable-guest-agent) guest_agent="yes"
1314  ;;
1315  --disable-guest-agent) guest_agent="no"
1316  ;;
1317  --enable-guest-agent-msi) guest_agent_msi="enabled"
1318  ;;
1319  --disable-guest-agent-msi) guest_agent_msi="disabled"
1320  ;;
1321  --with-vss-sdk) vss_win32_sdk=""
1322  ;;
1323  --with-vss-sdk=*) vss_win32_sdk="$optarg"
1324  ;;
1325  --without-vss-sdk) vss_win32_sdk="no"
1326  ;;
1327  --with-win-sdk) win_sdk=""
1328  ;;
1329  --with-win-sdk=*) win_sdk="$optarg"
1330  ;;
1331  --without-win-sdk) win_sdk="no"
1332  ;;
1333  --enable-tools) want_tools="yes"
1334  ;;
1335  --disable-tools) want_tools="no"
1336  ;;
1337  --enable-seccomp) seccomp="enabled"
1338  ;;
1339  --disable-seccomp) seccomp="disabled"
1340  ;;
1341  --disable-glusterfs) glusterfs="disabled"
1342  ;;
1343  --disable-avx2) avx2_opt="no"
1344  ;;
1345  --enable-avx2) avx2_opt="yes"
1346  ;;
1347  --disable-avx512f) avx512f_opt="no"
1348  ;;
1349  --enable-avx512f) avx512f_opt="yes"
1350  ;;
1351
1352  --enable-glusterfs) glusterfs="enabled"
1353  ;;
1354  --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
1355      echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
1356  ;;
1357  --enable-vhdx|--disable-vhdx)
1358      echo "$0: $opt is obsolete, VHDX driver is always built" >&2
1359  ;;
1360  --enable-uuid|--disable-uuid)
1361      echo "$0: $opt is obsolete, UUID support is always built" >&2
1362  ;;
1363  --disable-gtk) gtk="disabled"
1364  ;;
1365  --enable-gtk) gtk="enabled"
1366  ;;
1367  --tls-priority=*) tls_priority="$optarg"
1368  ;;
1369  --disable-gnutls) gnutls="disabled"
1370  ;;
1371  --enable-gnutls) gnutls="enabled"
1372  ;;
1373  --disable-nettle) nettle="disabled"
1374  ;;
1375  --enable-nettle) nettle="enabled"
1376  ;;
1377  --disable-gcrypt) gcrypt="disabled"
1378  ;;
1379  --enable-gcrypt) gcrypt="enabled"
1380  ;;
1381  --disable-auth-pam) auth_pam="disabled"
1382  ;;
1383  --enable-auth-pam) auth_pam="enabled"
1384  ;;
1385  --enable-rdma) rdma="yes"
1386  ;;
1387  --disable-rdma) rdma="no"
1388  ;;
1389  --enable-pvrdma) pvrdma="yes"
1390  ;;
1391  --disable-pvrdma) pvrdma="no"
1392  ;;
1393  --disable-vte) vte="disabled"
1394  ;;
1395  --enable-vte) vte="enabled"
1396  ;;
1397  --disable-virglrenderer) virglrenderer="disabled"
1398  ;;
1399  --enable-virglrenderer) virglrenderer="enabled"
1400  ;;
1401  --disable-tpm) tpm="no"
1402  ;;
1403  --enable-tpm) tpm="yes"
1404  ;;
1405  --disable-libssh) libssh="no"
1406  ;;
1407  --enable-libssh) libssh="yes"
1408  ;;
1409  --disable-live-block-migration) live_block_migration="no"
1410  ;;
1411  --enable-live-block-migration) live_block_migration="yes"
1412  ;;
1413  --disable-numa) numa="no"
1414  ;;
1415  --enable-numa) numa="yes"
1416  ;;
1417  --disable-libxml2) libxml2="disabled"
1418  ;;
1419  --enable-libxml2) libxml2="enabled"
1420  ;;
1421  --disable-tcmalloc) tcmalloc="no"
1422  ;;
1423  --enable-tcmalloc) tcmalloc="yes"
1424  ;;
1425  --disable-jemalloc) jemalloc="no"
1426  ;;
1427  --enable-jemalloc) jemalloc="yes"
1428  ;;
1429  --disable-replication) replication="no"
1430  ;;
1431  --enable-replication) replication="yes"
1432  ;;
1433  --disable-bochs) bochs="no"
1434  ;;
1435  --enable-bochs) bochs="yes"
1436  ;;
1437  --disable-cloop) cloop="no"
1438  ;;
1439  --enable-cloop) cloop="yes"
1440  ;;
1441  --disable-dmg) dmg="no"
1442  ;;
1443  --enable-dmg) dmg="yes"
1444  ;;
1445  --disable-qcow1) qcow1="no"
1446  ;;
1447  --enable-qcow1) qcow1="yes"
1448  ;;
1449  --disable-vdi) vdi="no"
1450  ;;
1451  --enable-vdi) vdi="yes"
1452  ;;
1453  --disable-vvfat) vvfat="no"
1454  ;;
1455  --enable-vvfat) vvfat="yes"
1456  ;;
1457  --disable-qed) qed="no"
1458  ;;
1459  --enable-qed) qed="yes"
1460  ;;
1461  --disable-parallels) parallels="no"
1462  ;;
1463  --enable-parallels) parallels="yes"
1464  ;;
1465  --disable-vhost-user) vhost_user="no"
1466  ;;
1467  --enable-vhost-user) vhost_user="yes"
1468  ;;
1469  --disable-vhost-vdpa) vhost_vdpa="no"
1470  ;;
1471  --enable-vhost-vdpa) vhost_vdpa="yes"
1472  ;;
1473  --disable-vhost-kernel) vhost_kernel="no"
1474  ;;
1475  --enable-vhost-kernel) vhost_kernel="yes"
1476  ;;
1477  --disable-capstone) capstone="disabled"
1478  ;;
1479  --enable-capstone) capstone="enabled"
1480  ;;
1481  --enable-capstone=git) capstone="internal"
1482  ;;
1483  --enable-capstone=system) capstone="system"
1484  ;;
1485  --with-git=*) git="$optarg"
1486  ;;
1487  --enable-git-update)
1488      git_submodules_action="update"
1489      echo "--enable-git-update deprecated, use --with-git-submodules=update"
1490  ;;
1491  --disable-git-update)
1492      git_submodules_action="validate"
1493      echo "--disable-git-update deprecated, use --with-git-submodules=validate"
1494  ;;
1495  --with-git-submodules=*)
1496      git_submodules_action="$optarg"
1497  ;;
1498  --enable-debug-mutex) debug_mutex=yes
1499  ;;
1500  --disable-debug-mutex) debug_mutex=no
1501  ;;
1502  --enable-libpmem) libpmem="enabled"
1503  ;;
1504  --disable-libpmem) libpmem="disabled"
1505  ;;
1506  --enable-xkbcommon) xkbcommon="enabled"
1507  ;;
1508  --disable-xkbcommon) xkbcommon="disabled"
1509  ;;
1510  --enable-plugins) if test "$mingw32" = "yes"; then
1511                        error_exit "TCG plugins not currently supported on Windows platforms"
1512                    else
1513                        plugins="yes"
1514                    fi
1515  ;;
1516  --disable-plugins) plugins="no"
1517  ;;
1518  --enable-containers) use_containers="yes"
1519  ;;
1520  --disable-containers) use_containers="no"
1521  ;;
1522  --enable-fuzzing) fuzzing=true
1523  ;;
1524  --disable-fuzzing) fuzzing=false
1525  ;;
1526  --gdb=*) gdb_bin="$optarg"
1527  ;;
1528  --enable-rng-none) rng_none=yes
1529  ;;
1530  --disable-rng-none) rng_none=no
1531  ;;
1532  --enable-keyring) secret_keyring="yes"
1533  ;;
1534  --disable-keyring) secret_keyring="no"
1535  ;;
1536  --enable-libdaxctl) libdaxctl="enabled"
1537  ;;
1538  --disable-libdaxctl) libdaxctl="disabled"
1539  ;;
1540  --enable-fuse) fuse="enabled"
1541  ;;
1542  --disable-fuse) fuse="disabled"
1543  ;;
1544  --enable-fuse-lseek) fuse_lseek="enabled"
1545  ;;
1546  --disable-fuse-lseek) fuse_lseek="disabled"
1547  ;;
1548  --enable-multiprocess) multiprocess="enabled"
1549  ;;
1550  --disable-multiprocess) multiprocess="disabled"
1551  ;;
1552  --enable-gio) gio=yes
1553  ;;
1554  --disable-gio) gio=no
1555  ;;
1556  --enable-slirp-smbd) slirp_smbd=yes
1557  ;;
1558  --disable-slirp-smbd) slirp_smbd=no
1559  ;;
1560  *)
1561      echo "ERROR: unknown option $opt"
1562      echo "Try '$0 --help' for more information"
1563      exit 1
1564  ;;
1565  esac
1566done
1567
1568# test for any invalid configuration combinations
1569if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
1570    error_exit "Can't enable plugins on non-TCG builds"
1571fi
1572
1573case $git_submodules_action in
1574    update|validate)
1575        if test ! -e "$source_path/.git"; then
1576            echo "ERROR: cannot $git_submodules_action git submodules without .git"
1577            exit 1
1578        fi
1579    ;;
1580    ignore)
1581        if ! test -f "$source_path/ui/keycodemapdb/README"
1582        then
1583            echo
1584            echo "ERROR: missing GIT submodules"
1585            echo
1586            if test -e "$source_path/.git"; then
1587                echo "--with-git-submodules=ignore specified but submodules were not"
1588                echo "checked out.  Please initialize and update submodules."
1589            else
1590                echo "This is not a GIT checkout but module content appears to"
1591                echo "be missing. Do not use 'git archive' or GitHub download links"
1592                echo "to acquire QEMU source archives. Non-GIT builds are only"
1593                echo "supported with source archives linked from:"
1594                echo
1595                echo "  https://www.qemu.org/download/#source"
1596                echo
1597                echo "Developers working with GIT can use scripts/archive-source.sh"
1598                echo "if they need to create valid source archives."
1599            fi
1600            echo
1601            exit 1
1602        fi
1603    ;;
1604    *)
1605        echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
1606        exit 1
1607    ;;
1608esac
1609
1610libdir="${libdir:-$prefix/lib}"
1611libexecdir="${libexecdir:-$prefix/libexec}"
1612includedir="${includedir:-$prefix/include}"
1613
1614if test "$mingw32" = "yes" ; then
1615    bindir="${bindir:-$prefix}"
1616else
1617    bindir="${bindir:-$prefix/bin}"
1618fi
1619mandir="${mandir:-$prefix/share/man}"
1620datadir="${datadir:-$prefix/share}"
1621docdir="${docdir:-$prefix/share/doc}"
1622sysconfdir="${sysconfdir:-$prefix/etc}"
1623local_statedir="${local_statedir:-$prefix/var}"
1624firmwarepath="${firmwarepath:-$datadir/qemu-firmware}"
1625localedir="${localedir:-$datadir/locale}"
1626
1627case "$cpu" in
1628    ppc)
1629           CPU_CFLAGS="-m32"
1630           QEMU_LDFLAGS="-m32 $QEMU_LDFLAGS"
1631           ;;
1632    ppc64)
1633           CPU_CFLAGS="-m64"
1634           QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1635           ;;
1636    sparc)
1637           CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc"
1638           QEMU_LDFLAGS="-m32 -mv8plus $QEMU_LDFLAGS"
1639           ;;
1640    sparc64)
1641           CPU_CFLAGS="-m64 -mcpu=ultrasparc"
1642           QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1643           ;;
1644    s390)
1645           CPU_CFLAGS="-m31"
1646           QEMU_LDFLAGS="-m31 $QEMU_LDFLAGS"
1647           ;;
1648    s390x)
1649           CPU_CFLAGS="-m64"
1650           QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1651           ;;
1652    i386)
1653           CPU_CFLAGS="-m32"
1654           QEMU_LDFLAGS="-m32 $QEMU_LDFLAGS"
1655           ;;
1656    x86_64)
1657           # ??? Only extremely old AMD cpus do not have cmpxchg16b.
1658           # If we truly care, we should simply detect this case at
1659           # runtime and generate the fallback to serial emulation.
1660           CPU_CFLAGS="-m64 -mcx16"
1661           QEMU_LDFLAGS="-m64 $QEMU_LDFLAGS"
1662           ;;
1663    x32)
1664           CPU_CFLAGS="-mx32"
1665           QEMU_LDFLAGS="-mx32 $QEMU_LDFLAGS"
1666           ;;
1667    # No special flags required for other host CPUs
1668esac
1669
1670if eval test -z "\${cross_cc_$cpu}"; then
1671    eval "cross_cc_${cpu}=\$cc"
1672    cross_cc_vars="$cross_cc_vars cross_cc_${cpu}"
1673fi
1674
1675# For user-mode emulation the host arch has to be one we explicitly
1676# support, even if we're using TCI.
1677if [ "$ARCH" = "unknown" ]; then
1678  bsd_user="no"
1679  linux_user="no"
1680fi
1681
1682default_target_list=""
1683deprecated_targets_list=ppc64abi32-linux-user
1684deprecated_features=""
1685mak_wilds=""
1686
1687if [ "$softmmu" = "yes" ]; then
1688    mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
1689fi
1690if [ "$linux_user" = "yes" ]; then
1691    mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
1692fi
1693if [ "$bsd_user" = "yes" ]; then
1694    mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
1695fi
1696
1697# If the user doesn't explicitly specify a deprecated target we will
1698# skip it.
1699if test -z "$target_list"; then
1700    if test -z "$target_list_exclude"; then
1701        target_list_exclude="$deprecated_targets_list"
1702    else
1703        target_list_exclude="$target_list_exclude,$deprecated_targets_list"
1704    fi
1705fi
1706
1707for config in $mak_wilds; do
1708    target="$(basename "$config" .mak)"
1709    if echo "$target_list_exclude" | grep -vq "$target"; then
1710        default_target_list="${default_target_list} $target"
1711    fi
1712done
1713
1714# Enumerate public trace backends for --help output
1715trace_backend_list=$(echo $(grep -le '^PUBLIC = True$' "$source_path"/scripts/tracetool/backend/*.py | sed -e 's/^.*\/\(.*\)\.py$/\1/'))
1716
1717if test x"$show_help" = x"yes" ; then
1718cat << EOF
1719
1720Usage: configure [options]
1721Options: [defaults in brackets after descriptions]
1722
1723Standard options:
1724  --help                   print this message
1725  --prefix=PREFIX          install in PREFIX [$prefix]
1726  --interp-prefix=PREFIX   where to find shared libraries, etc.
1727                           use %M for cpu name [$interp_prefix]
1728  --target-list=LIST       set target list (default: build all non-deprecated)
1729$(echo Available targets: $default_target_list | \
1730  fold -s -w 53 | sed -e 's/^/                           /')
1731$(echo Deprecated targets: $deprecated_targets_list | \
1732  fold -s -w 53 | sed -e 's/^/                           /')
1733  --target-list-exclude=LIST exclude a set of targets from the default target-list
1734
1735Advanced options (experts only):
1736  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
1737  --cc=CC                  use C compiler CC [$cc]
1738  --iasl=IASL              use ACPI compiler IASL [$iasl]
1739  --host-cc=CC             use C compiler CC [$host_cc] for code run at
1740                           build time
1741  --cxx=CXX                use C++ compiler CXX [$cxx]
1742  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
1743  --extra-cflags=CFLAGS    append extra C compiler flags QEMU_CFLAGS
1744  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags QEMU_CXXFLAGS
1745  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
1746  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
1747  --cross-cc-flags-ARCH=   use compiler flags when building ARCH guest tests
1748  --make=MAKE              use specified make [$make]
1749  --python=PYTHON          use specified python [$python]
1750  --sphinx-build=SPHINX    use specified sphinx-build [$sphinx_build]
1751  --meson=MESON            use specified meson [$meson]
1752  --ninja=NINJA            use specified ninja [$ninja]
1753  --smbd=SMBD              use specified smbd [$smbd]
1754  --with-git=GIT           use specified git [$git]
1755  --with-git-submodules=update   update git submodules (default if .git dir exists)
1756  --with-git-submodules=validate fail if git submodules are not up to date
1757  --with-git-submodules=ignore   do not update or check git submodules (default if no .git dir)
1758  --static                 enable static build [$static]
1759  --mandir=PATH            install man pages in PATH
1760  --datadir=PATH           install firmware in PATH/$qemu_suffix
1761  --localedir=PATH         install translation in PATH/$qemu_suffix
1762  --docdir=PATH            install documentation in PATH/$qemu_suffix
1763  --bindir=PATH            install binaries in PATH
1764  --libdir=PATH            install libraries in PATH
1765  --libexecdir=PATH        install helper binaries in PATH
1766  --sysconfdir=PATH        install config in PATH/$qemu_suffix
1767  --localstatedir=PATH     install local state in PATH (set at runtime on win32)
1768  --firmwarepath=PATH      search PATH for firmware files
1769  --efi-aarch64=PATH       PATH of efi file to use for aarch64 VMs.
1770  --with-suffix=SUFFIX     suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
1771  --with-pkgversion=VERS   use specified string as sub-version of the package
1772  --without-default-features default all --enable-* options to "disabled"
1773  --without-default-devices  do not include any device that is not needed to
1774                           start the emulator (only use if you are including
1775                           desired devices in configs/devices/)
1776  --with-devices-ARCH=NAME override default configs/devices
1777  --enable-debug           enable common debug build options
1778  --enable-sanitizers      enable default sanitizers
1779  --enable-tsan            enable thread sanitizer
1780  --disable-strip          disable stripping binaries
1781  --disable-werror         disable compilation abort on warning
1782  --disable-stack-protector disable compiler-provided stack protection
1783  --audio-drv-list=LIST    set audio drivers list
1784  --block-drv-whitelist=L  Same as --block-drv-rw-whitelist=L
1785  --block-drv-rw-whitelist=L
1786                           set block driver read-write whitelist
1787                           (by default affects only QEMU, not tools like qemu-img)
1788  --block-drv-ro-whitelist=L
1789                           set block driver read-only whitelist
1790                           (by default affects only QEMU, not tools like qemu-img)
1791  --enable-block-drv-whitelist-in-tools
1792                           use block whitelist also in tools instead of only QEMU
1793  --enable-trace-backends=B Set trace backend
1794                           Available backends: $trace_backend_list
1795  --with-trace-file=NAME   Full PATH,NAME of file to store traces
1796                           Default:trace-<pid>
1797  --disable-slirp          disable SLIRP userspace network connectivity
1798  --enable-tcg-interpreter enable TCI (TCG with bytecode interpreter, experimental and slow)
1799  --enable-malloc-trim     enable libc malloc_trim() for memory optimization
1800  --cpu=CPU                Build for host CPU [$cpu]
1801  --with-coroutine=BACKEND coroutine backend. Supported options:
1802                           ucontext, sigaltstack, windows
1803  --enable-gcov            enable test coverage analysis with gcov
1804  --disable-blobs          disable installing provided firmware blobs
1805  --with-vss-sdk=SDK-path  enable Windows VSS support in QEMU Guest Agent
1806  --with-win-sdk=SDK-path  path to Windows Platform SDK (to build VSS .tlb)
1807  --tls-priority           default TLS protocol/cipher priority string
1808  --enable-gprof           QEMU profiling with gprof
1809  --enable-profiler        profiler support
1810  --enable-debug-stack-usage
1811                           track the maximum stack usage of stacks created by qemu_alloc_stack
1812  --enable-plugins
1813                           enable plugins via shared library loading
1814  --disable-containers     don't use containers for cross-building
1815  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
1816
1817Optional features, enabled with --enable-FEATURE and
1818disabled with --disable-FEATURE, default is enabled if available
1819(unless built with --without-default-features):
1820
1821  system          all system emulation targets
1822  user            supported user emulation targets
1823  linux-user      all linux usermode emulation targets
1824  bsd-user        all BSD usermode emulation targets
1825  docs            build documentation
1826  guest-agent     build the QEMU Guest Agent
1827  guest-agent-msi build guest agent Windows MSI installation package
1828  pie             Position Independent Executables
1829  modules         modules support (non-Windows)
1830  module-upgrades try to load modules from alternate paths for upgrades
1831  debug-tcg       TCG debugging (default is disabled)
1832  debug-info      debugging information
1833  lto             Enable Link-Time Optimization.
1834  sparse          sparse checker
1835  safe-stack      SafeStack Stack Smash Protection. Depends on
1836                  clang/llvm >= 3.7 and requires coroutine backend ucontext.
1837  cfi             Enable Control-Flow Integrity for indirect function calls.
1838                  In case of a cfi violation, QEMU is terminated with SIGILL
1839                  Depends on lto and is incompatible with modules
1840                  Automatically enables Link-Time Optimization (lto)
1841  cfi-debug       In case of a cfi violation, a message containing the line that
1842                  triggered the error is written to stderr. After the error,
1843                  QEMU is still terminated with SIGILL
1844  gnutls          GNUTLS cryptography support
1845  nettle          nettle cryptography support
1846  gcrypt          libgcrypt cryptography support
1847  auth-pam        PAM access control
1848  sdl             SDL UI
1849  sdl-image       SDL Image support for icons
1850  gtk             gtk UI
1851  vte             vte support for the gtk UI
1852  curses          curses UI
1853  iconv           font glyph conversion support
1854  vnc             VNC UI support
1855  vnc-sasl        SASL encryption for VNC server
1856  vnc-jpeg        JPEG lossy compression for VNC server
1857  vnc-png         PNG compression for VNC server
1858  cocoa           Cocoa UI (Mac OS X only)
1859  virtfs          VirtFS
1860  virtiofsd       build virtiofs daemon (virtiofsd)
1861  libudev         Use libudev to enumerate host devices
1862  mpath           Multipath persistent reservation passthrough
1863  xen             xen backend driver support
1864  xen-pci-passthrough    PCI passthrough support for Xen
1865  alsa            ALSA sound support
1866  coreaudio       CoreAudio sound support
1867  dsound          DirectSound sound support
1868  jack            JACK sound support
1869  oss             OSS sound support
1870  pa              PulseAudio sound support
1871  brlapi          BrlAPI (Braile)
1872  curl            curl connectivity
1873  membarrier      membarrier system call (for Linux 4.14+ or Windows)
1874  fdt             fdt device tree
1875  kvm             KVM acceleration support
1876  hax             HAX acceleration support
1877  hvf             Hypervisor.framework acceleration support
1878  nvmm            NVMM acceleration support
1879  whpx            Windows Hypervisor Platform acceleration support
1880  rdma            Enable RDMA-based migration
1881  pvrdma          Enable PVRDMA support
1882  vde             support for vde network
1883  netmap          support for netmap network
1884  linux-aio       Linux AIO support
1885  linux-io-uring  Linux io_uring support
1886  cap-ng          libcap-ng support
1887  attr            attr and xattr support
1888  vhost-net       vhost-net kernel acceleration support
1889  vhost-vsock     virtio sockets device support
1890  vhost-scsi      vhost-scsi kernel target support
1891  vhost-crypto    vhost-user-crypto backend support
1892  vhost-kernel    vhost kernel backend support
1893  vhost-user      vhost-user backend support
1894  vhost-user-blk-server    vhost-user-blk server support
1895  vhost-vdpa      vhost-vdpa kernel backend support
1896  bpf             BPF kernel support
1897  spice           spice
1898  spice-protocol  spice-protocol
1899  rbd             rados block device (rbd)
1900  libiscsi        iscsi support
1901  libnfs          nfs support
1902  smartcard       smartcard support (libcacard)
1903  u2f             U2F support (u2f-emu)
1904  libusb          libusb (for usb passthrough)
1905  live-block-migration   Block migration in the main migration stream
1906  usb-redir       usb network redirection support
1907  lzo             support of lzo compression library
1908  snappy          support of snappy compression library
1909  bzip2           support of bzip2 compression library
1910                  (for reading bzip2-compressed dmg images)
1911  lzfse           support of lzfse compression library
1912                  (for reading lzfse-compressed dmg images)
1913  zstd            support for zstd compression library
1914                  (for migration compression and qcow2 cluster compression)
1915  seccomp         seccomp support
1916  coroutine-pool  coroutine freelist (better performance)
1917  glusterfs       GlusterFS backend
1918  tpm             TPM support
1919  libssh          ssh block device support
1920  numa            libnuma support
1921  libxml2         for Parallels image format
1922  tcmalloc        tcmalloc support
1923  jemalloc        jemalloc support
1924  avx2            AVX2 optimization support
1925  avx512f         AVX512F optimization support
1926  replication     replication support
1927  opengl          opengl support
1928  virglrenderer   virgl rendering support
1929  xfsctl          xfsctl support
1930  qom-cast-debug  cast debugging support
1931  tools           build qemu-io, qemu-nbd and qemu-img tools
1932  bochs           bochs image format support
1933  cloop           cloop image format support
1934  dmg             dmg image format support
1935  qcow1           qcow v1 image format support
1936  vdi             vdi image format support
1937  vvfat           vvfat image format support
1938  qed             qed image format support
1939  parallels       parallels image format 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  fuse            FUSE block device export
1948  fuse-lseek      SEEK_HOLE/SEEK_DATA support for FUSE exports
1949  multiprocess    Out of process device emulation support
1950  gio             libgio support
1951  slirp-smbd      use smbd (at path --smbd=*) in slirp networking
1952
1953NOTE: The object files are built at the place where configure is launched
1954EOF
1955exit 0
1956fi
1957
1958# Remove old dependency files to make sure that they get properly regenerated
1959rm -f */config-devices.mak.d
1960
1961if test -z "$python"
1962then
1963    error_exit "Python not found. Use --python=/path/to/python"
1964fi
1965if ! has "$make"
1966then
1967    error_exit "GNU make ($make) not found"
1968fi
1969
1970# Note that if the Python conditional here evaluates True we will exit
1971# with status 1 which is a shell 'false' value.
1972if ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then
1973  error_exit "Cannot use '$python', Python >= 3.6 is required." \
1974      "Use --python=/path/to/python to specify a supported Python."
1975fi
1976
1977# Preserve python version since some functionality is dependent on it
1978python_version=$($python -c 'import sys; print("%d.%d.%d" % (sys.version_info[0], sys.version_info[1], sys.version_info[2]))' 2>/dev/null)
1979
1980# Suppress writing compiled files
1981python="$python -B"
1982
1983if test -z "$meson"; then
1984    if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.59.2; then
1985        meson=meson
1986    elif test $git_submodules_action != 'ignore' ; then
1987        meson=git
1988    elif test -e "${source_path}/meson/meson.py" ; then
1989        meson=internal
1990    else
1991        if test "$explicit_python" = yes; then
1992            error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
1993        else
1994            error_exit "Meson not found.  Use --meson=/path/to/meson"
1995        fi
1996    fi
1997else
1998    # Meson uses its own Python interpreter to invoke other Python scripts,
1999    # but the user wants to use the one they specified with --python.
2000    #
2001    # We do not want to override the distro Python interpreter (and sometimes
2002    # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
2003    # just require --meson=git|internal together with --python.
2004    if test "$explicit_python" = yes; then
2005        case "$meson" in
2006            git | internal) ;;
2007            *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
2008        esac
2009    fi
2010fi
2011
2012if test "$meson" = git; then
2013    git_submodules="${git_submodules} meson"
2014fi
2015
2016case "$meson" in
2017    git | internal)
2018        meson="$python ${source_path}/meson/meson.py"
2019        ;;
2020    *) meson=$(command -v "$meson") ;;
2021esac
2022
2023# Probe for ninja
2024
2025if test -z "$ninja"; then
2026    for c in ninja ninja-build samu; do
2027        if has $c; then
2028            ninja=$(command -v "$c")
2029            break
2030        fi
2031    done
2032    if test -z "$ninja"; then
2033      error_exit "Cannot find Ninja"
2034    fi
2035fi
2036
2037# Check that the C compiler works. Doing this here before testing
2038# the host CPU ensures that we had a valid CC to autodetect the
2039# $cpu var (and we should bail right here if that's not the case).
2040# It also allows the help message to be printed without a CC.
2041write_c_skeleton;
2042if compile_object ; then
2043  : C compiler works ok
2044else
2045    error_exit "\"$cc\" either does not exist or does not work"
2046fi
2047if ! compile_prog ; then
2048    error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
2049fi
2050
2051# Consult white-list to determine whether to enable werror
2052# by default.  Only enable by default for git builds
2053if test -z "$werror" ; then
2054    if test "$git_submodules_action" != "ignore" && \
2055        { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
2056        werror="yes"
2057    else
2058        werror="no"
2059    fi
2060fi
2061
2062if test "$targetos" = "bogus"; then
2063    # Now that we know that we're not printing the help and that
2064    # the compiler works (so the results of the check_defines we used
2065    # to identify the OS are reliable), if we didn't recognize the
2066    # host OS we should stop now.
2067    error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
2068fi
2069
2070# Check whether the compiler matches our minimum requirements:
2071cat > $TMPC << EOF
2072#if defined(__clang_major__) && defined(__clang_minor__)
2073# ifdef __apple_build_version__
2074#  if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
2075#   error You need at least XCode Clang v10.0 to compile QEMU
2076#  endif
2077# else
2078#  if __clang_major__ < 6 || (__clang_major__ == 6 && __clang_minor__ < 0)
2079#   error You need at least Clang v6.0 to compile QEMU
2080#  endif
2081# endif
2082#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
2083# if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
2084#  error You need at least GCC v7.4.0 to compile QEMU
2085# endif
2086#else
2087# error You either need GCC or Clang to compiler QEMU
2088#endif
2089int main (void) { return 0; }
2090EOF
2091if ! compile_prog "" "" ; then
2092    error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
2093fi
2094
2095# Accumulate -Wfoo and -Wno-bar separately.
2096# We will list all of the enable flags first, and the disable flags second.
2097# Note that we do not add -Werror, because that would enable it for all
2098# configure tests. If a configure test failed due to -Werror this would
2099# just silently disable some features, so it's too error prone.
2100
2101warn_flags=
2102add_to warn_flags -Wold-style-declaration
2103add_to warn_flags -Wold-style-definition
2104add_to warn_flags -Wtype-limits
2105add_to warn_flags -Wformat-security
2106add_to warn_flags -Wformat-y2k
2107add_to warn_flags -Winit-self
2108add_to warn_flags -Wignored-qualifiers
2109add_to warn_flags -Wempty-body
2110add_to warn_flags -Wnested-externs
2111add_to warn_flags -Wendif-labels
2112add_to warn_flags -Wexpansion-to-defined
2113add_to warn_flags -Wimplicit-fallthrough=2
2114
2115nowarn_flags=
2116add_to nowarn_flags -Wno-initializer-overrides
2117add_to nowarn_flags -Wno-missing-include-dirs
2118add_to nowarn_flags -Wno-shift-negative-value
2119add_to nowarn_flags -Wno-string-plus-int
2120add_to nowarn_flags -Wno-typedef-redefinition
2121add_to nowarn_flags -Wno-tautological-type-limit-compare
2122add_to nowarn_flags -Wno-psabi
2123
2124gcc_flags="$warn_flags $nowarn_flags"
2125
2126cc_has_warning_flag() {
2127    write_c_skeleton;
2128
2129    # Use the positive sense of the flag when testing for -Wno-wombat
2130    # support (gcc will happily accept the -Wno- form of unknown
2131    # warning options).
2132    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
2133    compile_prog "-Werror $optflag" ""
2134}
2135
2136for flag in $gcc_flags; do
2137    if cc_has_warning_flag $flag ; then
2138        QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2139    fi
2140done
2141
2142if test "$stack_protector" != "no"; then
2143  cat > $TMPC << EOF
2144int main(int argc, char *argv[])
2145{
2146    char arr[64], *p = arr, *c = argv[0];
2147    while (*c) {
2148        *p++ = *c++;
2149    }
2150    return 0;
2151}
2152EOF
2153  gcc_flags="-fstack-protector-strong -fstack-protector-all"
2154  sp_on=0
2155  for flag in $gcc_flags; do
2156    # We need to check both a compile and a link, since some compiler
2157    # setups fail only on a .c->.o compile and some only at link time
2158    if compile_object "-Werror $flag" &&
2159       compile_prog "-Werror $flag" ""; then
2160      QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2161      QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
2162      sp_on=1
2163      break
2164    fi
2165  done
2166  if test "$stack_protector" = yes; then
2167    if test $sp_on = 0; then
2168      error_exit "Stack protector not supported"
2169    fi
2170  fi
2171fi
2172
2173# Disable -Wmissing-braces on older compilers that warn even for
2174# the "universal" C zero initializer {0}.
2175cat > $TMPC << EOF
2176struct {
2177  int a[2];
2178} x = {0};
2179EOF
2180if compile_object "-Werror" "" ; then
2181  :
2182else
2183  QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
2184fi
2185
2186# Our module code doesn't support Windows
2187if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
2188  error_exit "Modules are not available for Windows"
2189fi
2190
2191# module_upgrades is only reasonable if modules are enabled
2192if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
2193  error_exit "Can't enable module-upgrades as Modules are not enabled"
2194fi
2195
2196# Static linking is not possible with plugins, modules or PIE
2197if test "$static" = "yes" ; then
2198  if test "$modules" = "yes" ; then
2199    error_exit "static and modules are mutually incompatible"
2200  fi
2201  if test "$plugins" = "yes"; then
2202    error_exit "static and plugins are mutually incompatible"
2203  else
2204    plugins="no"
2205  fi
2206fi
2207
2208# Unconditional check for compiler __thread support
2209  cat > $TMPC << EOF
2210static __thread int tls_var;
2211int main(void) { return tls_var; }
2212EOF
2213
2214if ! compile_prog "-Werror" "" ; then
2215    error_exit "Your compiler does not support the __thread specifier for " \
2216	"Thread-Local Storage (TLS). Please upgrade to a version that does."
2217fi
2218
2219cat > $TMPC << EOF
2220
2221#ifdef __linux__
2222#  define THREAD __thread
2223#else
2224#  define THREAD
2225#endif
2226static THREAD int tls_var;
2227int main(void) { return tls_var; }
2228EOF
2229
2230# Check we support --no-pie first; we will need this for building ROMs.
2231if compile_prog "-Werror -fno-pie" "-no-pie"; then
2232  CFLAGS_NOPIE="-fno-pie"
2233fi
2234
2235if test "$static" = "yes"; then
2236  if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
2237    CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
2238    QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
2239    pie="yes"
2240  elif test "$pie" = "yes"; then
2241    error_exit "-static-pie not available due to missing toolchain support"
2242  else
2243    QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
2244    pie="no"
2245  fi
2246elif test "$pie" = "no"; then
2247  CONFIGURE_CFLAGS="$CFLAGS_NOPIE $CONFIGURE_CFLAGS"
2248elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
2249  CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
2250  CONFIGURE_LDFLAGS="-pie $CONFIGURE_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 "$tcg" = "enabled"; then
2306    git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
2307    git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
2308fi
2309
2310if test -z "${target_list+xxx}" ; then
2311    default_targets=yes
2312    for target in $default_target_list; do
2313        target_list="$target_list $target"
2314    done
2315    target_list="${target_list# }"
2316else
2317    default_targets=no
2318    target_list=$(echo "$target_list" | sed -e 's/,/ /g')
2319    for target in $target_list; do
2320        # Check that we recognised the target name; this allows a more
2321        # friendly error message than if we let it fall through.
2322        case " $default_target_list " in
2323            *" $target "*)
2324                ;;
2325            *)
2326                error_exit "Unknown target name '$target'"
2327                ;;
2328        esac
2329    done
2330fi
2331
2332for target in $target_list; do
2333    # if a deprecated target is enabled we note it here
2334    if echo "$deprecated_targets_list" | grep -q "$target"; then
2335        add_to deprecated_features $target
2336    fi
2337done
2338
2339# see if system emulation was really requested
2340case " $target_list " in
2341  *"-softmmu "*) softmmu=yes
2342  ;;
2343  *) softmmu=no
2344  ;;
2345esac
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
2359#include <stdio.h>
2360short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
2361short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
2362int main(int argc, char *argv[])
2363{
2364    return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
2365}
2366EOF
2367
2368if compile_prog ; then
2369    if strings -a $TMPE | grep -q BiGeNdIaN ; then
2370        bigendian="yes"
2371    elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
2372        bigendian="no"
2373    else
2374        echo big/little test failed
2375        exit 1
2376    fi
2377else
2378    echo big/little test failed
2379    exit 1
2380fi
2381
2382##########################################
2383# system tools
2384if test -z "$want_tools"; then
2385    if test "$softmmu" = "no"; then
2386        want_tools=no
2387    else
2388        want_tools=yes
2389    fi
2390fi
2391
2392##########################################
2393# L2TPV3 probe
2394
2395cat > $TMPC <<EOF
2396#include <sys/socket.h>
2397#include <linux/ip.h>
2398int main(void) { return sizeof(struct mmsghdr); }
2399EOF
2400if compile_prog "" "" ; then
2401  l2tpv3=yes
2402else
2403  l2tpv3=no
2404fi
2405
2406#########################################
2407# vhost interdependencies and host support
2408
2409# vhost backends
2410if test "$vhost_user" = "yes" && test "$linux" != "yes"; then
2411  error_exit "vhost-user is only available on Linux"
2412fi
2413test "$vhost_vdpa" = "" && vhost_vdpa=$linux
2414if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
2415  error_exit "vhost-vdpa is only available on Linux"
2416fi
2417test "$vhost_kernel" = "" && vhost_kernel=$linux
2418if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
2419  error_exit "vhost-kernel is only available on Linux"
2420fi
2421
2422# vhost-kernel devices
2423test "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
2424if test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
2425  error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
2426fi
2427test "$vhost_vsock" = "" && vhost_vsock=$vhost_kernel
2428if test "$vhost_vsock" = "yes" && test "$vhost_kernel" != "yes"; then
2429  error_exit "--enable-vhost-vsock requires --enable-vhost-kernel"
2430fi
2431
2432# vhost-user backends
2433test "$vhost_net_user" = "" && vhost_net_user=$vhost_user
2434if test "$vhost_net_user" = "yes" && test "$vhost_user" = "no"; then
2435  error_exit "--enable-vhost-net-user requires --enable-vhost-user"
2436fi
2437test "$vhost_crypto" = "" && vhost_crypto=$vhost_user
2438if test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
2439  error_exit "--enable-vhost-crypto requires --enable-vhost-user"
2440fi
2441test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
2442if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
2443  error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
2444fi
2445#vhost-vdpa backends
2446test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa
2447if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then
2448  error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa"
2449fi
2450
2451# OR the vhost-kernel, vhost-vdpa and vhost-user values for simplicity
2452if test "$vhost_net" = ""; then
2453  test "$vhost_net_user" = "yes" && vhost_net=yes
2454  test "$vhost_net_vdpa" = "yes" && vhost_net=yes
2455  test "$vhost_kernel" = "yes" && vhost_net=yes
2456fi
2457
2458##########################################
2459# pkg-config probe
2460
2461if ! has "$pkg_config_exe"; then
2462  error_exit "pkg-config binary '$pkg_config_exe' not found"
2463fi
2464
2465##########################################
2466# NPTL probe
2467
2468if test "$linux_user" = "yes"; then
2469  cat > $TMPC <<EOF
2470#include <sched.h>
2471#include <linux/futex.h>
2472int main(void) {
2473#if !defined(CLONE_SETTLS) || !defined(FUTEX_WAIT)
2474#error bork
2475#endif
2476  return 0;
2477}
2478EOF
2479  if ! compile_object ; then
2480    feature_not_found "nptl" "Install glibc and linux kernel headers."
2481  fi
2482fi
2483
2484##########################################
2485# xen probe
2486
2487if test "$xen" != "disabled" ; then
2488  # Check whether Xen library path is specified via --extra-ldflags to avoid
2489  # overriding this setting with pkg-config output. If not, try pkg-config
2490  # to obtain all needed flags.
2491
2492  if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \
2493     $pkg_config --exists xencontrol ; then
2494    xen_ctrl_version="$(printf '%d%02d%02d' \
2495      $($pkg_config --modversion xencontrol | sed 's/\./ /g') )"
2496    xen=enabled
2497    xen_pc="xencontrol xenstore xenforeignmemory xengnttab"
2498    xen_pc="$xen_pc xenevtchn xendevicemodel"
2499    if $pkg_config --exists xentoolcore; then
2500      xen_pc="$xen_pc xentoolcore"
2501    fi
2502    xen_cflags="$($pkg_config --cflags $xen_pc)"
2503    xen_libs="$($pkg_config --libs $xen_pc)"
2504  else
2505
2506    xen_libs="-lxenstore -lxenctrl"
2507    xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
2508
2509    # First we test whether Xen headers and libraries are available.
2510    # If no, we are done and there is no Xen support.
2511    # If yes, more tests are run to detect the Xen version.
2512
2513    # Xen (any)
2514    cat > $TMPC <<EOF
2515#include <xenctrl.h>
2516int main(void) {
2517  return 0;
2518}
2519EOF
2520    if ! compile_prog "" "$xen_libs" ; then
2521      # Xen not found
2522      if test "$xen" = "enabled" ; then
2523        feature_not_found "xen" "Install xen devel"
2524      fi
2525      xen=disabled
2526
2527    # Xen unstable
2528    elif
2529        cat > $TMPC <<EOF &&
2530#undef XC_WANT_COMPAT_DEVICEMODEL_API
2531#define __XEN_TOOLS__
2532#include <xendevicemodel.h>
2533#include <xenforeignmemory.h>
2534int main(void) {
2535  xendevicemodel_handle *xd;
2536  xenforeignmemory_handle *xfmem;
2537
2538  xd = xendevicemodel_open(0, 0);
2539  xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);
2540
2541  xfmem = xenforeignmemory_open(0, 0);
2542  xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);
2543
2544  return 0;
2545}
2546EOF
2547        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
2548      then
2549      xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
2550      xen_ctrl_version=41100
2551      xen=enabled
2552    elif
2553        cat > $TMPC <<EOF &&
2554#undef XC_WANT_COMPAT_MAP_FOREIGN_API
2555#include <xenforeignmemory.h>
2556#include <xentoolcore.h>
2557int main(void) {
2558  xenforeignmemory_handle *xfmem;
2559
2560  xfmem = xenforeignmemory_open(0, 0);
2561  xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
2562  xentoolcore_restrict_all(0);
2563
2564  return 0;
2565}
2566EOF
2567        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
2568      then
2569      xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
2570      xen_ctrl_version=41000
2571      xen=enabled
2572    elif
2573        cat > $TMPC <<EOF &&
2574#undef XC_WANT_COMPAT_DEVICEMODEL_API
2575#define __XEN_TOOLS__
2576#include <xendevicemodel.h>
2577int main(void) {
2578  xendevicemodel_handle *xd;
2579
2580  xd = xendevicemodel_open(0, 0);
2581  xendevicemodel_close(xd);
2582
2583  return 0;
2584}
2585EOF
2586        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs"
2587      then
2588      xen_stable_libs="-lxendevicemodel $xen_stable_libs"
2589      xen_ctrl_version=40900
2590      xen=enabled
2591    elif
2592        cat > $TMPC <<EOF &&
2593/*
2594 * If we have stable libs the we don't want the libxc compat
2595 * layers, regardless of what CFLAGS we may have been given.
2596 *
2597 * Also, check if xengnttab_grant_copy_segment_t is defined and
2598 * grant copy operation is implemented.
2599 */
2600#undef XC_WANT_COMPAT_EVTCHN_API
2601#undef XC_WANT_COMPAT_GNTTAB_API
2602#undef XC_WANT_COMPAT_MAP_FOREIGN_API
2603#include <xenctrl.h>
2604#include <xenstore.h>
2605#include <xenevtchn.h>
2606#include <xengnttab.h>
2607#include <xenforeignmemory.h>
2608#include <stdint.h>
2609#include <xen/hvm/hvm_info_table.h>
2610#if !defined(HVM_MAX_VCPUS)
2611# error HVM_MAX_VCPUS not defined
2612#endif
2613int main(void) {
2614  xc_interface *xc = NULL;
2615  xenforeignmemory_handle *xfmem;
2616  xenevtchn_handle *xe;
2617  xengnttab_handle *xg;
2618  xengnttab_grant_copy_segment_t* seg = NULL;
2619
2620  xs_daemon_open();
2621
2622  xc = xc_interface_open(0, 0, 0);
2623  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2624  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2625  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2626  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2627
2628  xfmem = xenforeignmemory_open(0, 0);
2629  xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2630
2631  xe = xenevtchn_open(0, 0);
2632  xenevtchn_fd(xe);
2633
2634  xg = xengnttab_open(0, 0);
2635  xengnttab_grant_copy(xg, 0, seg);
2636
2637  return 0;
2638}
2639EOF
2640        compile_prog "" "$xen_libs $xen_stable_libs"
2641      then
2642      xen_ctrl_version=40800
2643      xen=enabled
2644    elif
2645        cat > $TMPC <<EOF &&
2646/*
2647 * If we have stable libs the we don't want the libxc compat
2648 * layers, regardless of what CFLAGS we may have been given.
2649 */
2650#undef XC_WANT_COMPAT_EVTCHN_API
2651#undef XC_WANT_COMPAT_GNTTAB_API
2652#undef XC_WANT_COMPAT_MAP_FOREIGN_API
2653#include <xenctrl.h>
2654#include <xenstore.h>
2655#include <xenevtchn.h>
2656#include <xengnttab.h>
2657#include <xenforeignmemory.h>
2658#include <stdint.h>
2659#include <xen/hvm/hvm_info_table.h>
2660#if !defined(HVM_MAX_VCPUS)
2661# error HVM_MAX_VCPUS not defined
2662#endif
2663int main(void) {
2664  xc_interface *xc = NULL;
2665  xenforeignmemory_handle *xfmem;
2666  xenevtchn_handle *xe;
2667  xengnttab_handle *xg;
2668
2669  xs_daemon_open();
2670
2671  xc = xc_interface_open(0, 0, 0);
2672  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2673  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2674  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2675  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2676
2677  xfmem = xenforeignmemory_open(0, 0);
2678  xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2679
2680  xe = xenevtchn_open(0, 0);
2681  xenevtchn_fd(xe);
2682
2683  xg = xengnttab_open(0, 0);
2684  xengnttab_map_grant_ref(xg, 0, 0, 0);
2685
2686  return 0;
2687}
2688EOF
2689        compile_prog "" "$xen_libs $xen_stable_libs"
2690      then
2691      xen_ctrl_version=40701
2692      xen=enabled
2693
2694    # Xen 4.6
2695    elif
2696        cat > $TMPC <<EOF &&
2697#include <xenctrl.h>
2698#include <xenstore.h>
2699#include <stdint.h>
2700#include <xen/hvm/hvm_info_table.h>
2701#if !defined(HVM_MAX_VCPUS)
2702# error HVM_MAX_VCPUS not defined
2703#endif
2704int main(void) {
2705  xc_interface *xc;
2706  xs_daemon_open();
2707  xc = xc_interface_open(0, 0, 0);
2708  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2709  xc_gnttab_open(NULL, 0);
2710  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2711  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2712  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2713  xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
2714  return 0;
2715}
2716EOF
2717        compile_prog "" "$xen_libs"
2718      then
2719      xen_ctrl_version=40600
2720      xen=enabled
2721
2722    # Xen 4.5
2723    elif
2724        cat > $TMPC <<EOF &&
2725#include <xenctrl.h>
2726#include <xenstore.h>
2727#include <stdint.h>
2728#include <xen/hvm/hvm_info_table.h>
2729#if !defined(HVM_MAX_VCPUS)
2730# error HVM_MAX_VCPUS not defined
2731#endif
2732int main(void) {
2733  xc_interface *xc;
2734  xs_daemon_open();
2735  xc = xc_interface_open(0, 0, 0);
2736  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2737  xc_gnttab_open(NULL, 0);
2738  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2739  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2740  xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
2741  return 0;
2742}
2743EOF
2744        compile_prog "" "$xen_libs"
2745      then
2746      xen_ctrl_version=40500
2747      xen=enabled
2748
2749    elif
2750        cat > $TMPC <<EOF &&
2751#include <xenctrl.h>
2752#include <xenstore.h>
2753#include <stdint.h>
2754#include <xen/hvm/hvm_info_table.h>
2755#if !defined(HVM_MAX_VCPUS)
2756# error HVM_MAX_VCPUS not defined
2757#endif
2758int main(void) {
2759  xc_interface *xc;
2760  xs_daemon_open();
2761  xc = xc_interface_open(0, 0, 0);
2762  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2763  xc_gnttab_open(NULL, 0);
2764  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2765  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2766  return 0;
2767}
2768EOF
2769        compile_prog "" "$xen_libs"
2770      then
2771      xen_ctrl_version=40200
2772      xen=enabled
2773
2774    else
2775      if test "$xen" = "enabled" ; then
2776        feature_not_found "xen (unsupported version)" \
2777                          "Install a supported xen (xen 4.2 or newer)"
2778      fi
2779      xen=disabled
2780    fi
2781
2782    if test "$xen" = enabled; then
2783      if test $xen_ctrl_version -ge 40701  ; then
2784        xen_libs="$xen_libs $xen_stable_libs "
2785      fi
2786    fi
2787  fi
2788fi
2789
2790##########################################
2791# RDMA needs OpenFabrics libraries
2792if test "$rdma" != "no" ; then
2793  cat > $TMPC <<EOF
2794#include <rdma/rdma_cma.h>
2795int main(void) { return 0; }
2796EOF
2797  rdma_libs="-lrdmacm -libverbs -libumad"
2798  if compile_prog "" "$rdma_libs" ; then
2799    rdma="yes"
2800  else
2801    if test "$rdma" = "yes" ; then
2802        error_exit \
2803            " OpenFabrics librdmacm/libibverbs/libibumad not present." \
2804            " Your options:" \
2805            "  (1) Fast: Install infiniband packages (devel) from your distro." \
2806            "  (2) Cleanest: Install libraries from www.openfabrics.org" \
2807            "  (3) Also: Install softiwarp if you don't have RDMA hardware"
2808    fi
2809    rdma="no"
2810  fi
2811fi
2812
2813##########################################
2814# PVRDMA detection
2815
2816cat > $TMPC <<EOF &&
2817#include <sys/mman.h>
2818
2819int
2820main(void)
2821{
2822    char buf = 0;
2823    void *addr = &buf;
2824    addr = mremap(addr, 0, 1, MREMAP_MAYMOVE | MREMAP_FIXED);
2825
2826    return 0;
2827}
2828EOF
2829
2830if test "$rdma" = "yes" ; then
2831    case "$pvrdma" in
2832    "")
2833        if compile_prog "" ""; then
2834            pvrdma="yes"
2835        else
2836            pvrdma="no"
2837        fi
2838        ;;
2839    "yes")
2840        if ! compile_prog "" ""; then
2841            error_exit "PVRDMA is not supported since mremap is not implemented"
2842        fi
2843        pvrdma="yes"
2844        ;;
2845    "no")
2846        pvrdma="no"
2847        ;;
2848    esac
2849else
2850    if test "$pvrdma" = "yes" ; then
2851        error_exit "PVRDMA requires rdma suppport"
2852    fi
2853    pvrdma="no"
2854fi
2855
2856# Let's see if enhanced reg_mr is supported
2857if test "$pvrdma" = "yes" ; then
2858
2859cat > $TMPC <<EOF &&
2860#include <infiniband/verbs.h>
2861
2862int
2863main(void)
2864{
2865    struct ibv_mr *mr;
2866    struct ibv_pd *pd = NULL;
2867    size_t length = 10;
2868    uint64_t iova = 0;
2869    int access = 0;
2870    void *addr = NULL;
2871
2872    mr = ibv_reg_mr_iova(pd, addr, length, iova, access);
2873
2874    ibv_dereg_mr(mr);
2875
2876    return 0;
2877}
2878EOF
2879    if ! compile_prog "" "-libverbs"; then
2880        QEMU_CFLAGS="$QEMU_CFLAGS -DLEGACY_RDMA_REG_MR"
2881    fi
2882fi
2883
2884##########################################
2885# xfsctl() probe, used for file-posix.c
2886if test "$xfs" != "no" ; then
2887  cat > $TMPC << EOF
2888#include <stddef.h>  /* NULL */
2889#include <xfs/xfs.h>
2890int main(void)
2891{
2892    xfsctl(NULL, 0, 0, NULL);
2893    return 0;
2894}
2895EOF
2896  if compile_prog "" "" ; then
2897    xfs="yes"
2898  else
2899    if test "$xfs" = "yes" ; then
2900      feature_not_found "xfs" "Install xfsprogs/xfslibs devel"
2901    fi
2902    xfs=no
2903  fi
2904fi
2905
2906##########################################
2907# vde libraries probe
2908if test "$vde" != "no" ; then
2909  vde_libs="-lvdeplug"
2910  cat > $TMPC << EOF
2911#include <libvdeplug.h>
2912int main(void)
2913{
2914    struct vde_open_args a = {0, 0, 0};
2915    char s[] = "";
2916    vde_open(s, s, &a);
2917    return 0;
2918}
2919EOF
2920  if compile_prog "" "$vde_libs" ; then
2921    vde=yes
2922  else
2923    if test "$vde" = "yes" ; then
2924      feature_not_found "vde" "Install vde (Virtual Distributed Ethernet) devel"
2925    fi
2926    vde=no
2927  fi
2928fi
2929
2930##########################################
2931# netmap support probe
2932# Apart from looking for netmap headers, we make sure that the host API version
2933# supports the netmap backend (>=11). The upper bound (15) is meant to simulate
2934# a minor/major version number. Minor new features will be marked with values up
2935# to 15, and if something happens that requires a change to the backend we will
2936# move above 15, submit the backend fixes and modify this two bounds.
2937if test "$netmap" != "no" ; then
2938  cat > $TMPC << EOF
2939#include <inttypes.h>
2940#include <net/if.h>
2941#include <net/netmap.h>
2942#include <net/netmap_user.h>
2943#if (NETMAP_API < 11) || (NETMAP_API > 15)
2944#error
2945#endif
2946int main(void) { return 0; }
2947EOF
2948  if compile_prog "" "" ; then
2949    netmap=yes
2950  else
2951    if test "$netmap" = "yes" ; then
2952      feature_not_found "netmap"
2953    fi
2954    netmap=no
2955  fi
2956fi
2957
2958##########################################
2959# plugin linker support probe
2960
2961if test "$plugins" != "no"; then
2962
2963    #########################################
2964    # See if --dynamic-list is supported by the linker
2965
2966    ld_dynamic_list="no"
2967    cat > $TMPTXT <<EOF
2968{
2969  foo;
2970};
2971EOF
2972
2973        cat > $TMPC <<EOF
2974#include <stdio.h>
2975void foo(void);
2976
2977void foo(void)
2978{
2979  printf("foo\n");
2980}
2981
2982int main(void)
2983{
2984  foo();
2985  return 0;
2986}
2987EOF
2988
2989    if compile_prog "" "-Wl,--dynamic-list=$TMPTXT" ; then
2990        ld_dynamic_list="yes"
2991    fi
2992
2993    #########################################
2994    # See if -exported_symbols_list is supported by the linker
2995
2996    ld_exported_symbols_list="no"
2997    cat > $TMPTXT <<EOF
2998  _foo
2999EOF
3000
3001    if compile_prog "" "-Wl,-exported_symbols_list,$TMPTXT" ; then
3002        ld_exported_symbols_list="yes"
3003    fi
3004
3005    if test "$ld_dynamic_list" = "no" &&
3006       test "$ld_exported_symbols_list" = "no" ; then
3007        if test "$plugins" = "yes"; then
3008            error_exit \
3009                "Plugin support requires dynamic linking and specifying a set of symbols " \
3010                "that are exported to plugins. Unfortunately your linker doesn't " \
3011                "support the flag (--dynamic-list or -exported_symbols_list) used " \
3012                "for this purpose."
3013        else
3014            plugins="no"
3015        fi
3016    else
3017        plugins="yes"
3018    fi
3019fi
3020
3021##########################################
3022# glib support probe
3023
3024glib_req_ver=2.56
3025glib_modules=gthread-2.0
3026if test "$modules" = yes; then
3027    glib_modules="$glib_modules gmodule-export-2.0"
3028elif test "$plugins" = "yes"; then
3029    glib_modules="$glib_modules gmodule-no-export-2.0"
3030fi
3031
3032for i in $glib_modules; do
3033    if $pkg_config --atleast-version=$glib_req_ver $i; then
3034        glib_cflags=$($pkg_config --cflags $i)
3035        glib_libs=$($pkg_config --libs $i)
3036    else
3037        error_exit "glib-$glib_req_ver $i is required to compile QEMU"
3038    fi
3039done
3040
3041# This workaround is required due to a bug in pkg-config file for glib as it
3042# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
3043
3044if test "$static" = yes && test "$mingw32" = yes; then
3045    glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
3046fi
3047
3048if ! test "$gio" = "no"; then
3049    pass=no
3050    if $pkg_config --atleast-version=$glib_req_ver gio-2.0; then
3051        gio_cflags=$($pkg_config --cflags gio-2.0)
3052        gio_libs=$($pkg_config --libs gio-2.0)
3053        gdbus_codegen=$($pkg_config --variable=gdbus_codegen gio-2.0)
3054        if ! has "$gdbus_codegen"; then
3055            gdbus_codegen=
3056        fi
3057        # Check that the libraries actually work -- Ubuntu 18.04 ships
3058        # with pkg-config --static --libs data for gio-2.0 that is missing
3059        # -lblkid and will give a link error.
3060        cat > $TMPC <<EOF
3061#include <gio/gio.h>
3062int main(void)
3063{
3064    g_dbus_proxy_new_sync(0, 0, 0, 0, 0, 0, 0, 0);
3065    return 0;
3066}
3067EOF
3068        if compile_prog "$gio_cflags" "$gio_libs" ; then
3069            pass=yes
3070        else
3071            pass=no
3072        fi
3073
3074        if test "$pass" = "yes" &&
3075            $pkg_config --atleast-version=$glib_req_ver gio-unix-2.0; then
3076            gio_cflags="$gio_cflags $($pkg_config --cflags gio-unix-2.0)"
3077            gio_libs="$gio_libs $($pkg_config --libs gio-unix-2.0)"
3078        fi
3079    fi
3080
3081    if test "$pass" = "no"; then
3082        if test "$gio" = "yes"; then
3083            feature_not_found "gio" "Install libgio >= 2.0"
3084        else
3085            gio=no
3086        fi
3087    else
3088        gio=yes
3089    fi
3090fi
3091
3092# Sanity check that the current size_t matches the
3093# size that glib thinks it should be. This catches
3094# problems on multi-arch where people try to build
3095# 32-bit QEMU while pointing at 64-bit glib headers
3096cat > $TMPC <<EOF
3097#include <glib.h>
3098#include <unistd.h>
3099
3100#define QEMU_BUILD_BUG_ON(x) \
3101  typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
3102
3103int main(void) {
3104   QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
3105   return 0;
3106}
3107EOF
3108
3109if ! compile_prog "$glib_cflags" "$glib_libs" ; then
3110    error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
3111               "You probably need to set PKG_CONFIG_LIBDIR"\
3112	       "to point to the right pkg-config files for your"\
3113	       "build target"
3114fi
3115
3116# Silence clang warnings triggered by glib < 2.57.2
3117cat > $TMPC << EOF
3118#include <glib.h>
3119typedef struct Foo {
3120    int i;
3121} Foo;
3122static void foo_free(Foo *f)
3123{
3124    g_free(f);
3125}
3126G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free);
3127int main(void) { return 0; }
3128EOF
3129if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
3130    if cc_has_warning_flag "-Wno-unused-function"; then
3131        glib_cflags="$glib_cflags -Wno-unused-function"
3132        CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
3133    fi
3134fi
3135
3136##########################################
3137# SHA command probe for modules
3138if test "$modules" = yes; then
3139    shacmd_probe="sha1sum sha1 shasum"
3140    for c in $shacmd_probe; do
3141        if has $c; then
3142            shacmd="$c"
3143            break
3144        fi
3145    done
3146    if test "$shacmd" = ""; then
3147        error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
3148    fi
3149fi
3150
3151##########################################
3152# libssh probe
3153if test "$libssh" != "no" ; then
3154  if $pkg_config --exists "libssh >= 0.8.7"; then
3155    libssh_cflags=$($pkg_config libssh --cflags)
3156    libssh_libs=$($pkg_config libssh --libs)
3157    libssh=yes
3158  else
3159    if test "$libssh" = "yes" ; then
3160      error_exit "libssh required for --enable-libssh"
3161    fi
3162    libssh=no
3163  fi
3164fi
3165
3166##########################################
3167# TPM emulation is only on POSIX
3168
3169if test "$tpm" = ""; then
3170  if test "$mingw32" = "yes"; then
3171    tpm=no
3172  else
3173    tpm=yes
3174  fi
3175elif test "$tpm" = "yes"; then
3176  if test "$mingw32" = "yes" ; then
3177    error_exit "TPM emulation only available on POSIX systems"
3178  fi
3179fi
3180
3181##########################################
3182# iovec probe
3183cat > $TMPC <<EOF
3184#include <sys/types.h>
3185#include <sys/uio.h>
3186#include <unistd.h>
3187int main(void) { return sizeof(struct iovec); }
3188EOF
3189iovec=no
3190if compile_prog "" "" ; then
3191  iovec=yes
3192fi
3193
3194##########################################
3195# fdt probe
3196
3197case "$fdt" in
3198  auto | enabled | internal)
3199    # Simpler to always update submodule, even if not needed.
3200    git_submodules="${git_submodules} dtc"
3201    ;;
3202esac
3203
3204##########################################
3205# opengl probe (for sdl2, gtk)
3206
3207if test "$opengl" != "no" ; then
3208  epoxy=no
3209  if $pkg_config epoxy; then
3210    cat > $TMPC << EOF
3211#include <epoxy/egl.h>
3212int main(void) { return 0; }
3213EOF
3214    if compile_prog "" "" ; then
3215      epoxy=yes
3216    fi
3217  fi
3218
3219  if test "$epoxy" = "yes" ; then
3220    opengl_cflags="$($pkg_config --cflags epoxy)"
3221    opengl_libs="$($pkg_config --libs epoxy)"
3222    opengl=yes
3223  else
3224    if test "$opengl" = "yes" ; then
3225      feature_not_found "opengl" "Please install epoxy with EGL"
3226    fi
3227    opengl_cflags=""
3228    opengl_libs=""
3229    opengl=no
3230  fi
3231fi
3232
3233##########################################
3234# libnuma probe
3235
3236if test "$numa" != "no" ; then
3237  cat > $TMPC << EOF
3238#include <numa.h>
3239int main(void) { return numa_available(); }
3240EOF
3241
3242  if compile_prog "" "-lnuma" ; then
3243    numa=yes
3244    numa_libs="-lnuma"
3245  else
3246    if test "$numa" = "yes" ; then
3247      feature_not_found "numa" "install numactl devel"
3248    fi
3249    numa=no
3250  fi
3251fi
3252
3253malloc=system
3254if test "$tcmalloc" = "yes" && test "$jemalloc" = "yes" ; then
3255    echo "ERROR: tcmalloc && jemalloc can't be used at the same time"
3256    exit 1
3257elif test "$tcmalloc" = "yes" ; then
3258    malloc=tcmalloc
3259elif test "$jemalloc" = "yes" ; then
3260    malloc=jemalloc
3261fi
3262
3263# check for usbfs
3264have_usbfs=no
3265if test "$linux_user" = "yes"; then
3266  cat > $TMPC << EOF
3267#include <linux/usbdevice_fs.h>
3268
3269#ifndef USBDEVFS_GET_CAPABILITIES
3270#error "USBDEVFS_GET_CAPABILITIES undefined"
3271#endif
3272
3273#ifndef USBDEVFS_DISCONNECT_CLAIM
3274#error "USBDEVFS_DISCONNECT_CLAIM undefined"
3275#endif
3276
3277int main(void)
3278{
3279    return 0;
3280}
3281EOF
3282  if compile_prog "" ""; then
3283    have_usbfs=yes
3284  fi
3285fi
3286
3287##########################################
3288# spice probe
3289if test "$spice_protocol" != "no" ; then
3290  spice_protocol_cflags=$($pkg_config --cflags spice-protocol 2>/dev/null)
3291  if $pkg_config --atleast-version=0.12.3 spice-protocol; then
3292    spice_protocol="yes"
3293  else
3294    if test "$spice_protocol" = "yes" ; then
3295      feature_not_found "spice_protocol" \
3296          "Install spice-protocol(>=0.12.3) devel"
3297    fi
3298    spice_protocol="no"
3299  fi
3300fi
3301
3302if test "$spice" != "no" ; then
3303  cat > $TMPC << EOF
3304#include <spice.h>
3305int main(void) { spice_server_new(); return 0; }
3306EOF
3307  spice_cflags=$($pkg_config --cflags spice-protocol spice-server 2>/dev/null)
3308  spice_libs=$($pkg_config --libs spice-protocol spice-server 2>/dev/null)
3309  if $pkg_config --atleast-version=0.12.5 spice-server && \
3310     test "$spice_protocol" = "yes" && \
3311     compile_prog "$spice_cflags" "$spice_libs" ; then
3312    spice="yes"
3313  else
3314    if test "$spice" = "yes" ; then
3315      feature_not_found "spice" \
3316          "Install spice-server(>=0.12.5) devel"
3317    fi
3318    spice="no"
3319  fi
3320fi
3321
3322##########################################
3323# check if we have VSS SDK headers for win
3324
3325if test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
3326        test "$vss_win32_sdk" != "no" ; then
3327  case "$vss_win32_sdk" in
3328    "")   vss_win32_include="-isystem $source_path" ;;
3329    *\ *) # The SDK is installed in "Program Files" by default, but we cannot
3330          # handle path with spaces. So we symlink the headers into ".sdk/vss".
3331          vss_win32_include="-isystem $source_path/.sdk/vss"
3332	  symlink "$vss_win32_sdk/inc" "$source_path/.sdk/vss/inc"
3333	  ;;
3334    *)    vss_win32_include="-isystem $vss_win32_sdk"
3335  esac
3336  cat > $TMPC << EOF
3337#define __MIDL_user_allocate_free_DEFINED__
3338#include <inc/win2003/vss.h>
3339int main(void) { return VSS_CTX_BACKUP; }
3340EOF
3341  if compile_prog "$vss_win32_include" "" ; then
3342    guest_agent_with_vss="yes"
3343    QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
3344    libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++ -Wl,--enable-stdcall-fixup $libs_qga"
3345    qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb"
3346  else
3347    if test "$vss_win32_sdk" != "" ; then
3348      echo "ERROR: Please download and install Microsoft VSS SDK:"
3349      echo "ERROR:   http://www.microsoft.com/en-us/download/details.aspx?id=23490"
3350      echo "ERROR: On POSIX-systems, you can extract the SDK headers by:"
3351      echo "ERROR:   scripts/extract-vsssdk-headers setup.exe"
3352      echo "ERROR: The headers are extracted in the directory \`inc'."
3353      feature_not_found "VSS support"
3354    fi
3355    guest_agent_with_vss="no"
3356  fi
3357fi
3358
3359##########################################
3360# lookup Windows platform SDK (if not specified)
3361# The SDK is needed only to build .tlb (type library) file of guest agent
3362# VSS provider from the source. It is usually unnecessary because the
3363# pre-compiled .tlb file is included.
3364
3365if test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
3366        test "$guest_agent_with_vss" = "yes" ; then
3367  if test -z "$win_sdk"; then
3368    programfiles="$PROGRAMFILES"
3369    test -n "$PROGRAMW6432" && programfiles="$PROGRAMW6432"
3370    if test -n "$programfiles"; then
3371      win_sdk=$(ls -d "$programfiles/Microsoft SDKs/Windows/v"* | tail -1) 2>/dev/null
3372    else
3373      feature_not_found "Windows SDK"
3374    fi
3375  elif test "$win_sdk" = "no"; then
3376    win_sdk=""
3377  fi
3378fi
3379
3380##########################################
3381# check if mingw environment provides a recent ntddscsi.h
3382if test "$mingw32" = "yes" && test "$guest_agent" != "no"; then
3383  cat > $TMPC << EOF
3384#include <windows.h>
3385#include <ntddscsi.h>
3386int main(void) {
3387#if !defined(IOCTL_SCSI_GET_ADDRESS)
3388#error Missing required ioctl definitions
3389#endif
3390  SCSI_ADDRESS addr = { .Lun = 0, .TargetId = 0, .PathId = 0 };
3391  return addr.Lun;
3392}
3393EOF
3394  if compile_prog "" "" ; then
3395    guest_agent_ntddscsi=yes
3396    libs_qga="-lsetupapi -lcfgmgr32 $libs_qga"
3397  fi
3398fi
3399
3400##########################################
3401# capstone
3402
3403case "$capstone" in
3404  auto | enabled | internal)
3405    # Simpler to always update submodule, even if not needed.
3406    git_submodules="${git_submodules} capstone"
3407    ;;
3408esac
3409
3410##########################################
3411# check and set a backend for coroutine
3412
3413# We prefer ucontext, but it's not always possible. The fallback
3414# is sigcontext. On Windows the only valid backend is the Windows
3415# specific one.
3416
3417ucontext_works=no
3418if test "$darwin" != "yes"; then
3419  cat > $TMPC << EOF
3420#include <ucontext.h>
3421#ifdef __stub_makecontext
3422#error Ignoring glibc stub makecontext which will always fail
3423#endif
3424int main(void) { makecontext(0, 0, 0); return 0; }
3425EOF
3426  if compile_prog "" "" ; then
3427    ucontext_works=yes
3428  fi
3429fi
3430
3431if test "$coroutine" = ""; then
3432  if test "$mingw32" = "yes"; then
3433    coroutine=win32
3434  elif test "$ucontext_works" = "yes"; then
3435    coroutine=ucontext
3436  else
3437    coroutine=sigaltstack
3438  fi
3439else
3440  case $coroutine in
3441  windows)
3442    if test "$mingw32" != "yes"; then
3443      error_exit "'windows' coroutine backend only valid for Windows"
3444    fi
3445    # Unfortunately the user visible backend name doesn't match the
3446    # coroutine-*.c filename for this case, so we have to adjust it here.
3447    coroutine=win32
3448    ;;
3449  ucontext)
3450    if test "$ucontext_works" != "yes"; then
3451      feature_not_found "ucontext"
3452    fi
3453    ;;
3454  sigaltstack)
3455    if test "$mingw32" = "yes"; then
3456      error_exit "only the 'windows' coroutine backend is valid for Windows"
3457    fi
3458    ;;
3459  *)
3460    error_exit "unknown coroutine backend $coroutine"
3461    ;;
3462  esac
3463fi
3464
3465if test "$coroutine_pool" = ""; then
3466  coroutine_pool=yes
3467fi
3468
3469if test "$debug_stack_usage" = "yes"; then
3470  if test "$coroutine_pool" = "yes"; then
3471    echo "WARN: disabling coroutine pool for stack usage debugging"
3472    coroutine_pool=no
3473  fi
3474fi
3475
3476##################################################
3477# SafeStack
3478
3479
3480if test "$safe_stack" = "yes"; then
3481cat > $TMPC << EOF
3482int main(int argc, char *argv[])
3483{
3484#if ! __has_feature(safe_stack)
3485#error SafeStack Disabled
3486#endif
3487    return 0;
3488}
3489EOF
3490  flag="-fsanitize=safe-stack"
3491  # Check that safe-stack is supported and enabled.
3492  if compile_prog "-Werror $flag" "$flag"; then
3493    # Flag needed both at compilation and at linking
3494    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
3495    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
3496  else
3497    error_exit "SafeStack not supported by your compiler"
3498  fi
3499  if test "$coroutine" != "ucontext"; then
3500    error_exit "SafeStack is only supported by the coroutine backend ucontext"
3501  fi
3502else
3503cat > $TMPC << EOF
3504int main(int argc, char *argv[])
3505{
3506#if defined(__has_feature)
3507#if __has_feature(safe_stack)
3508#error SafeStack Enabled
3509#endif
3510#endif
3511    return 0;
3512}
3513EOF
3514if test "$safe_stack" = "no"; then
3515  # Make sure that safe-stack is disabled
3516  if ! compile_prog "-Werror" ""; then
3517    # SafeStack was already enabled, try to explicitly remove the feature
3518    flag="-fno-sanitize=safe-stack"
3519    if ! compile_prog "-Werror $flag" "$flag"; then
3520      error_exit "Configure cannot disable SafeStack"
3521    fi
3522    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
3523    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
3524  fi
3525else # "$safe_stack" = ""
3526  # Set safe_stack to yes or no based on pre-existing flags
3527  if compile_prog "-Werror" ""; then
3528    safe_stack="no"
3529  else
3530    safe_stack="yes"
3531    if test "$coroutine" != "ucontext"; then
3532      error_exit "SafeStack is only supported by the coroutine backend ucontext"
3533    fi
3534  fi
3535fi
3536fi
3537
3538########################################
3539# check if cpuid.h is usable.
3540
3541cat > $TMPC << EOF
3542#include <cpuid.h>
3543int main(void) {
3544    unsigned a, b, c, d;
3545    int max = __get_cpuid_max(0, 0);
3546
3547    if (max >= 1) {
3548        __cpuid(1, a, b, c, d);
3549    }
3550
3551    if (max >= 7) {
3552        __cpuid_count(7, 0, a, b, c, d);
3553    }
3554
3555    return 0;
3556}
3557EOF
3558if compile_prog "" "" ; then
3559    cpuid_h=yes
3560fi
3561
3562##########################################
3563# avx2 optimization requirement check
3564#
3565# There is no point enabling this if cpuid.h is not usable,
3566# since we won't be able to select the new routines.
3567
3568if test "$cpuid_h" = "yes" && test "$avx2_opt" != "no"; then
3569  cat > $TMPC << EOF
3570#pragma GCC push_options
3571#pragma GCC target("avx2")
3572#include <cpuid.h>
3573#include <immintrin.h>
3574static int bar(void *a) {
3575    __m256i x = *(__m256i *)a;
3576    return _mm256_testz_si256(x, x);
3577}
3578int main(int argc, char *argv[]) { return bar(argv[0]); }
3579EOF
3580  if compile_object "-Werror" ; then
3581    avx2_opt="yes"
3582  else
3583    avx2_opt="no"
3584  fi
3585fi
3586
3587##########################################
3588# avx512f optimization requirement check
3589#
3590# There is no point enabling this if cpuid.h is not usable,
3591# since we won't be able to select the new routines.
3592# by default, it is turned off.
3593# if user explicitly want to enable it, check environment
3594
3595if test "$cpuid_h" = "yes" && test "$avx512f_opt" = "yes"; then
3596  cat > $TMPC << EOF
3597#pragma GCC push_options
3598#pragma GCC target("avx512f")
3599#include <cpuid.h>
3600#include <immintrin.h>
3601static int bar(void *a) {
3602    __m512i x = *(__m512i *)a;
3603    return _mm512_test_epi64_mask(x, x);
3604}
3605int main(int argc, char *argv[])
3606{
3607	return bar(argv[0]);
3608}
3609EOF
3610  if ! compile_object "-Werror" ; then
3611    avx512f_opt="no"
3612  fi
3613else
3614  avx512f_opt="no"
3615fi
3616
3617########################################
3618# check if __[u]int128_t is usable.
3619
3620int128=no
3621cat > $TMPC << EOF
3622__int128_t a;
3623__uint128_t b;
3624int main (void) {
3625  a = a + b;
3626  b = a * b;
3627  a = a * a;
3628  return 0;
3629}
3630EOF
3631if compile_prog "" "" ; then
3632    int128=yes
3633fi
3634
3635#########################################
3636# See if 128-bit atomic operations are supported.
3637
3638atomic128=no
3639if test "$int128" = "yes"; then
3640  cat > $TMPC << EOF
3641int main(void)
3642{
3643  unsigned __int128 x = 0, y = 0;
3644  y = __atomic_load(&x, 0);
3645  __atomic_store(&x, y, 0);
3646  __atomic_compare_exchange(&x, &y, x, 0, 0, 0);
3647  return 0;
3648}
3649EOF
3650  if compile_prog "" "" ; then
3651    atomic128=yes
3652  fi
3653fi
3654
3655cmpxchg128=no
3656if test "$int128" = yes && test "$atomic128" = no; then
3657  cat > $TMPC << EOF
3658int main(void)
3659{
3660  unsigned __int128 x = 0, y = 0;
3661  __sync_val_compare_and_swap_16(&x, y, x);
3662  return 0;
3663}
3664EOF
3665  if compile_prog "" "" ; then
3666    cmpxchg128=yes
3667  fi
3668fi
3669
3670#########################################
3671# See if 64-bit atomic operations are supported.
3672# Note that without __atomic builtins, we can only
3673# assume atomic loads/stores max at pointer size.
3674
3675cat > $TMPC << EOF
3676#include <stdint.h>
3677int main(void)
3678{
3679  uint64_t x = 0, y = 0;
3680  y = __atomic_load_n(&x, __ATOMIC_RELAXED);
3681  __atomic_store_n(&x, y, __ATOMIC_RELAXED);
3682  __atomic_compare_exchange_n(&x, &y, x, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
3683  __atomic_exchange_n(&x, y, __ATOMIC_RELAXED);
3684  __atomic_fetch_add(&x, y, __ATOMIC_RELAXED);
3685  return 0;
3686}
3687EOF
3688if compile_prog "" "" ; then
3689  atomic64=yes
3690fi
3691
3692########################################
3693# check if getauxval is available.
3694
3695getauxval=no
3696cat > $TMPC << EOF
3697#include <sys/auxv.h>
3698int main(void) {
3699  return getauxval(AT_HWCAP) == 0;
3700}
3701EOF
3702if compile_prog "" "" ; then
3703    getauxval=yes
3704fi
3705
3706########################################
3707# check if ccache is interfering with
3708# semantic analysis of macros
3709
3710unset CCACHE_CPP2
3711ccache_cpp2=no
3712cat > $TMPC << EOF
3713static const int Z = 1;
3714#define fn() ({ Z; })
3715#define TAUT(X) ((X) == Z)
3716#define PAREN(X, Y) (X == Y)
3717#define ID(X) (X)
3718int main(int argc, char *argv[])
3719{
3720    int x = 0, y = 0;
3721    x = ID(x);
3722    x = fn();
3723    fn();
3724    if (PAREN(x, y)) return 0;
3725    if (TAUT(Z)) return 0;
3726    return 0;
3727}
3728EOF
3729
3730if ! compile_object "-Werror"; then
3731    ccache_cpp2=yes
3732fi
3733
3734#################################################
3735# clang does not support glibc + FORTIFY_SOURCE.
3736
3737if test "$fortify_source" != "no"; then
3738  if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
3739    fortify_source="no";
3740  elif test -n "$cxx" && has $cxx &&
3741       echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
3742    fortify_source="no";
3743  else
3744    fortify_source="yes"
3745  fi
3746fi
3747
3748##########################################
3749# check for usable membarrier system call
3750if test "$membarrier" = "yes"; then
3751    have_membarrier=no
3752    if test "$mingw32" = "yes" ; then
3753        have_membarrier=yes
3754    elif test "$linux" = "yes" ; then
3755        cat > $TMPC << EOF
3756    #include <linux/membarrier.h>
3757    #include <sys/syscall.h>
3758    #include <unistd.h>
3759    #include <stdlib.h>
3760    int main(void) {
3761        syscall(__NR_membarrier, MEMBARRIER_CMD_QUERY, 0);
3762        syscall(__NR_membarrier, MEMBARRIER_CMD_SHARED, 0);
3763	exit(0);
3764    }
3765EOF
3766        if compile_prog "" "" ; then
3767            have_membarrier=yes
3768        fi
3769    fi
3770    if test "$have_membarrier" = "no"; then
3771      feature_not_found "membarrier" "membarrier system call not available"
3772    fi
3773else
3774    # Do not enable it by default even for Mingw32, because it doesn't
3775    # work on Wine.
3776    membarrier=no
3777fi
3778
3779##########################################
3780# check for usable AF_VSOCK environment
3781have_af_vsock=no
3782cat > $TMPC << EOF
3783#include <errno.h>
3784#include <sys/types.h>
3785#include <sys/socket.h>
3786#if !defined(AF_VSOCK)
3787# error missing AF_VSOCK flag
3788#endif
3789#include <linux/vm_sockets.h>
3790int main(void) {
3791    int sock, ret;
3792    struct sockaddr_vm svm;
3793    socklen_t len = sizeof(svm);
3794    sock = socket(AF_VSOCK, SOCK_STREAM, 0);
3795    ret = getpeername(sock, (struct sockaddr *)&svm, &len);
3796    if ((ret == -1) && (errno == ENOTCONN)) {
3797        return 0;
3798    }
3799    return -1;
3800}
3801EOF
3802if compile_prog "" "" ; then
3803    have_af_vsock=yes
3804fi
3805
3806##########################################
3807# check for usable AF_ALG environment
3808have_afalg=no
3809cat > $TMPC << EOF
3810#include <errno.h>
3811#include <sys/types.h>
3812#include <sys/socket.h>
3813#include <linux/if_alg.h>
3814int main(void) {
3815    int sock;
3816    sock = socket(AF_ALG, SOCK_SEQPACKET, 0);
3817    return sock;
3818}
3819EOF
3820if compile_prog "" "" ; then
3821    have_afalg=yes
3822fi
3823if test "$crypto_afalg" = "yes"
3824then
3825    if test "$have_afalg" != "yes"
3826    then
3827	error_exit "AF_ALG requested but could not be detected"
3828    fi
3829fi
3830
3831
3832##########################################
3833# checks for sanitizers
3834
3835have_asan=no
3836have_ubsan=no
3837have_asan_iface_h=no
3838have_asan_iface_fiber=no
3839
3840if test "$sanitizers" = "yes" ; then
3841  write_c_skeleton
3842  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
3843      have_asan=yes
3844  fi
3845
3846  # we could use a simple skeleton for flags checks, but this also
3847  # detect the static linking issue of ubsan, see also:
3848  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
3849  cat > $TMPC << EOF
3850#include <stdlib.h>
3851int main(void) {
3852    void *tmp = malloc(10);
3853    if (tmp != NULL) {
3854        return *(int *)(tmp + 2);
3855    }
3856    return 1;
3857}
3858EOF
3859  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
3860      have_ubsan=yes
3861  fi
3862
3863  if check_include "sanitizer/asan_interface.h" ; then
3864      have_asan_iface_h=yes
3865  fi
3866
3867  cat > $TMPC << EOF
3868#include <sanitizer/asan_interface.h>
3869int main(void) {
3870  __sanitizer_start_switch_fiber(0, 0, 0);
3871  return 0;
3872}
3873EOF
3874  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
3875      have_asan_iface_fiber=yes
3876  fi
3877fi
3878
3879# Thread sanitizer is, for now, much noisier than the other sanitizers;
3880# keep it separate until that is not the case.
3881if test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
3882  error_exit "TSAN is not supported with other sanitiziers."
3883fi
3884have_tsan=no
3885have_tsan_iface_fiber=no
3886if test "$tsan" = "yes" ; then
3887  write_c_skeleton
3888  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
3889      have_tsan=yes
3890  fi
3891  cat > $TMPC << EOF
3892#include <sanitizer/tsan_interface.h>
3893int main(void) {
3894  __tsan_create_fiber(0);
3895  return 0;
3896}
3897EOF
3898  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
3899      have_tsan_iface_fiber=yes
3900  fi
3901fi
3902
3903##########################################
3904# check for slirp
3905
3906case "$slirp" in
3907  auto | enabled | internal)
3908    # Simpler to always update submodule, even if not needed.
3909    git_submodules="${git_submodules} slirp"
3910    ;;
3911esac
3912
3913# Check for slirp smbd dupport
3914: ${smbd=${SMBD-/usr/sbin/smbd}}
3915if test "$slirp_smbd" != "no" ; then
3916  if test "$mingw32" = "yes" ; then
3917    if test "$slirp_smbd" = "yes" ; then
3918      error_exit "Host smbd not supported on this platform."
3919    fi
3920    slirp_smbd=no
3921  else
3922    slirp_smbd=yes
3923  fi
3924fi
3925
3926##########################################
3927# check for usable __NR_keyctl syscall
3928
3929if test "$linux" = "yes" ; then
3930
3931    have_keyring=no
3932    cat > $TMPC << EOF
3933#include <errno.h>
3934#include <asm/unistd.h>
3935#include <linux/keyctl.h>
3936#include <unistd.h>
3937int main(void) {
3938    return syscall(__NR_keyctl, KEYCTL_READ, 0, NULL, NULL, 0);
3939}
3940EOF
3941    if compile_prog "" "" ; then
3942        have_keyring=yes
3943    fi
3944fi
3945if test "$secret_keyring" != "no"
3946then
3947    if test "$have_keyring" = "yes"
3948    then
3949	secret_keyring=yes
3950    else
3951	if test "$secret_keyring" = "yes"
3952	then
3953	    error_exit "syscall __NR_keyctl requested, \
3954but not implemented on your system"
3955	else
3956	    secret_keyring=no
3957	fi
3958    fi
3959fi
3960
3961##########################################
3962# End of CC checks
3963# After here, no more $cc or $ld runs
3964
3965write_c_skeleton
3966
3967if test "$gcov" = "yes" ; then
3968  :
3969elif test "$fortify_source" = "yes" ; then
3970  QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
3971  debug=no
3972fi
3973
3974case "$ARCH" in
3975alpha)
3976  # Ensure there's only a single GP
3977  QEMU_CFLAGS="-msmall-data $QEMU_CFLAGS"
3978;;
3979esac
3980
3981if test "$gprof" = "yes" ; then
3982  QEMU_CFLAGS="-p $QEMU_CFLAGS"
3983  QEMU_LDFLAGS="-p $QEMU_LDFLAGS"
3984fi
3985
3986if test "$have_asan" = "yes"; then
3987  QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
3988  QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
3989  if test "$have_asan_iface_h" = "no" ; then
3990      echo "ASAN build enabled, but ASAN header missing." \
3991           "Without code annotation, the report may be inferior."
3992  elif test "$have_asan_iface_fiber" = "no" ; then
3993      echo "ASAN build enabled, but ASAN header is too old." \
3994           "Without code annotation, the report may be inferior."
3995  fi
3996fi
3997if test "$have_tsan" = "yes" ; then
3998  if test "$have_tsan_iface_fiber" = "yes" ; then
3999    QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
4000    QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
4001  else
4002    error_exit "Cannot enable TSAN due to missing fiber annotation interface."
4003  fi
4004elif test "$tsan" = "yes" ; then
4005  error_exit "Cannot enable TSAN due to missing sanitize thread interface."
4006fi
4007if test "$have_ubsan" = "yes"; then
4008  QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
4009  QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
4010fi
4011
4012##########################################
4013
4014# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
4015if test "$solaris" = "no" && test "$tsan" = "no"; then
4016    if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
4017        QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
4018    fi
4019fi
4020
4021# Use ASLR, no-SEH and DEP if available
4022if test "$mingw32" = "yes" ; then
4023    flags="--no-seh --nxcompat"
4024
4025    # Disable ASLR for debug builds to allow debugging with gdb
4026    if test "$debug" = "no" ; then
4027        flags="--dynamicbase $flags"
4028    fi
4029
4030    for flag in $flags; do
4031        if ld_has $flag ; then
4032            QEMU_LDFLAGS="-Wl,$flag $QEMU_LDFLAGS"
4033        fi
4034    done
4035fi
4036
4037# Probe for guest agent support/options
4038
4039if [ "$guest_agent" != "no" ]; then
4040  if [ "$softmmu" = no -a "$want_tools" = no ] ; then
4041      guest_agent=no
4042  elif [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" -o "$mingw32" = "yes" ] ; then
4043      guest_agent=yes
4044  elif [ "$guest_agent" != yes ]; then
4045      guest_agent=no
4046  else
4047      error_exit "Guest agent is not supported on this platform"
4048  fi
4049fi
4050
4051# Guest agent Windows MSI package
4052
4053if test "$QEMU_GA_MANUFACTURER" = ""; then
4054  QEMU_GA_MANUFACTURER=QEMU
4055fi
4056if test "$QEMU_GA_DISTRO" = ""; then
4057  QEMU_GA_DISTRO=Linux
4058fi
4059if test "$QEMU_GA_VERSION" = ""; then
4060    QEMU_GA_VERSION=$(cat $source_path/VERSION)
4061fi
4062
4063QEMU_GA_MSI_MINGW_DLL_PATH="$($pkg_config --variable=prefix glib-2.0)/bin"
4064
4065# Mac OS X ships with a broken assembler
4066roms=
4067if { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \
4068        test "$targetos" != "Darwin" && test "$targetos" != "SunOS" && \
4069        test "$targetos" != "Haiku" && test "$softmmu" = yes ; then
4070    # Different host OS linkers have different ideas about the name of the ELF
4071    # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
4072    # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
4073    for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
4074        if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
4075            ld_i386_emulation="$emu"
4076            roms="optionrom"
4077            break
4078        fi
4079    done
4080fi
4081
4082# Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
4083# or -march=z10 (which is the lowest architecture level that Clang supports)
4084if test "$cpu" = "s390x" ; then
4085  write_c_skeleton
4086  compile_prog "-march=z900" ""
4087  has_z900=$?
4088  if [ $has_z900 = 0 ] || compile_object "-march=z10 -msoft-float -Werror"; then
4089    if [ $has_z900 != 0 ]; then
4090      echo "WARNING: Your compiler does not support the z900!"
4091      echo "         The s390-ccw bios will only work with guest CPUs >= z10."
4092    fi
4093    roms="$roms s390-ccw"
4094    # SLOF is required for building the s390-ccw firmware on s390x,
4095    # since it is using the libnet code from SLOF for network booting.
4096    git_submodules="${git_submodules} roms/SLOF"
4097  fi
4098fi
4099
4100# Check that the C++ compiler exists and works with the C compiler.
4101# All the QEMU_CXXFLAGS are based on QEMU_CFLAGS. Keep this at the end to don't miss any other that could be added.
4102if has $cxx; then
4103    cat > $TMPC <<EOF
4104int c_function(void);
4105int main(void) { return c_function(); }
4106EOF
4107
4108    compile_object
4109
4110    cat > $TMPCXX <<EOF
4111extern "C" {
4112   int c_function(void);
4113}
4114int c_function(void) { return 42; }
4115EOF
4116
4117    update_cxxflags
4118
4119    if do_cxx $CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
4120        # C++ compiler $cxx works ok with C compiler $cc
4121        :
4122    else
4123        echo "C++ compiler $cxx does not work with C compiler $cc"
4124        echo "Disabling C++ specific optional code"
4125        cxx=
4126    fi
4127else
4128    echo "No C++ compiler available; disabling C++ specific optional code"
4129    cxx=
4130fi
4131
4132if !(GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
4133    exit 1
4134fi
4135
4136config_host_mak="config-host.mak"
4137
4138echo "# Automatically generated by configure - do not modify" > $config_host_mak
4139echo >> $config_host_mak
4140
4141echo all: >> $config_host_mak
4142echo "GIT=$git" >> $config_host_mak
4143echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
4144echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
4145
4146echo "ARCH=$ARCH" >> $config_host_mak
4147
4148if test "$debug_tcg" = "yes" ; then
4149  echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
4150fi
4151if test "$strip_opt" = "yes" ; then
4152  echo "STRIP=${strip}" >> $config_host_mak
4153fi
4154if test "$mingw32" = "yes" ; then
4155  echo "CONFIG_WIN32=y" >> $config_host_mak
4156  if test "$guest_agent_with_vss" = "yes" ; then
4157    echo "CONFIG_QGA_VSS=y" >> $config_host_mak
4158    echo "QGA_VSS_PROVIDER=$qga_vss_provider" >> $config_host_mak
4159    echo "WIN_SDK=\"$win_sdk\"" >> $config_host_mak
4160  fi
4161  if test "$guest_agent_ntddscsi" = "yes" ; then
4162    echo "CONFIG_QGA_NTDDSCSI=y" >> $config_host_mak
4163  fi
4164  echo "QEMU_GA_MSI_MINGW_DLL_PATH=${QEMU_GA_MSI_MINGW_DLL_PATH}" >> $config_host_mak
4165  echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
4166  echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
4167  echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
4168else
4169  echo "CONFIG_POSIX=y" >> $config_host_mak
4170fi
4171
4172if test "$linux" = "yes" ; then
4173  echo "CONFIG_LINUX=y" >> $config_host_mak
4174fi
4175
4176if test "$darwin" = "yes" ; then
4177  echo "CONFIG_DARWIN=y" >> $config_host_mak
4178fi
4179
4180if test "$solaris" = "yes" ; then
4181  echo "CONFIG_SOLARIS=y" >> $config_host_mak
4182fi
4183if test "$haiku" = "yes" ; then
4184  echo "CONFIG_HAIKU=y" >> $config_host_mak
4185fi
4186if test "$static" = "yes" ; then
4187  echo "CONFIG_STATIC=y" >> $config_host_mak
4188fi
4189if test "$profiler" = "yes" ; then
4190  echo "CONFIG_PROFILER=y" >> $config_host_mak
4191fi
4192if test "$want_tools" = "yes" ; then
4193  echo "CONFIG_TOOLS=y" >> $config_host_mak
4194fi
4195if test "$guest_agent" = "yes" ; then
4196  echo "CONFIG_GUEST_AGENT=y" >> $config_host_mak
4197fi
4198if test "$slirp_smbd" = "yes" ; then
4199  echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak
4200  echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
4201fi
4202if test "$vde" = "yes" ; then
4203  echo "CONFIG_VDE=y" >> $config_host_mak
4204  echo "VDE_LIBS=$vde_libs" >> $config_host_mak
4205fi
4206if test "$netmap" = "yes" ; then
4207  echo "CONFIG_NETMAP=y" >> $config_host_mak
4208fi
4209if test "$l2tpv3" = "yes" ; then
4210  echo "CONFIG_L2TPV3=y" >> $config_host_mak
4211fi
4212if test "$gprof" = "yes" ; then
4213  echo "CONFIG_GPROF=y" >> $config_host_mak
4214fi
4215echo "CONFIG_BDRV_RW_WHITELIST=$block_drv_rw_whitelist" >> $config_host_mak
4216echo "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
4217if test "$block_drv_whitelist_tools" = "yes" ; then
4218  echo "CONFIG_BDRV_WHITELIST_TOOLS=y" >> $config_host_mak
4219fi
4220if test "$xfs" = "yes" ; then
4221  echo "CONFIG_XFS=y" >> $config_host_mak
4222fi
4223qemu_version=$(head $source_path/VERSION)
4224echo "PKGVERSION=$pkgversion" >>$config_host_mak
4225echo "SRC_PATH=$source_path" >> $config_host_mak
4226echo "TARGET_DIRS=$target_list" >> $config_host_mak
4227if test "$modules" = "yes"; then
4228  # $shacmd can generate a hash started with digit, which the compiler doesn't
4229  # like as an symbol. So prefix it with an underscore
4230  echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
4231  echo "CONFIG_MODULES=y" >> $config_host_mak
4232fi
4233if test "$module_upgrades" = "yes"; then
4234  echo "CONFIG_MODULE_UPGRADES=y" >> $config_host_mak
4235fi
4236if test "$have_usbfs" = "yes" ; then
4237  echo "CONFIG_USBFS=y" >> $config_host_mak
4238fi
4239if test "$gio" = "yes" ; then
4240    echo "CONFIG_GIO=y" >> $config_host_mak
4241    echo "GIO_CFLAGS=$gio_cflags" >> $config_host_mak
4242    echo "GIO_LIBS=$gio_libs" >> $config_host_mak
4243fi
4244if test "$gdbus_codegen" != "" ; then
4245    echo "GDBUS_CODEGEN=$gdbus_codegen" >> $config_host_mak
4246fi
4247echo "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak
4248
4249if test "$xen" = "enabled" ; then
4250  echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
4251  echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
4252  echo "XEN_CFLAGS=$xen_cflags" >> $config_host_mak
4253  echo "XEN_LIBS=$xen_libs" >> $config_host_mak
4254fi
4255if test "$vhost_scsi" = "yes" ; then
4256  echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
4257fi
4258if test "$vhost_net" = "yes" ; then
4259  echo "CONFIG_VHOST_NET=y" >> $config_host_mak
4260fi
4261if test "$vhost_net_user" = "yes" ; then
4262  echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak
4263fi
4264if test "$vhost_net_vdpa" = "yes" ; then
4265  echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak
4266fi
4267if test "$vhost_crypto" = "yes" ; then
4268  echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
4269fi
4270if test "$vhost_vsock" = "yes" ; then
4271  echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
4272  if test "$vhost_user" = "yes" ; then
4273    echo "CONFIG_VHOST_USER_VSOCK=y" >> $config_host_mak
4274  fi
4275fi
4276if test "$vhost_kernel" = "yes" ; then
4277  echo "CONFIG_VHOST_KERNEL=y" >> $config_host_mak
4278fi
4279if test "$vhost_user" = "yes" ; then
4280  echo "CONFIG_VHOST_USER=y" >> $config_host_mak
4281fi
4282if test "$vhost_vdpa" = "yes" ; then
4283  echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
4284fi
4285if test "$vhost_user_fs" = "yes" ; then
4286  echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak
4287fi
4288if test "$iovec" = "yes" ; then
4289  echo "CONFIG_IOVEC=y" >> $config_host_mak
4290fi
4291if test "$membarrier" = "yes" ; then
4292  echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
4293fi
4294if test "$tcg" = "enabled" -a "$tcg_interpreter" = "true" ; then
4295  echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
4296fi
4297
4298if test "$spice_protocol" = "yes" ; then
4299  echo "CONFIG_SPICE_PROTOCOL=y" >> $config_host_mak
4300  echo "SPICE_PROTOCOL_CFLAGS=$spice_protocol_cflags" >> $config_host_mak
4301fi
4302if test "$spice" = "yes" ; then
4303  echo "CONFIG_SPICE=y" >> $config_host_mak
4304  echo "SPICE_CFLAGS=$spice_cflags $spice_protocol_cflags" >> $config_host_mak
4305  echo "SPICE_LIBS=$spice_libs" >> $config_host_mak
4306fi
4307
4308if test "$opengl" = "yes" ; then
4309  echo "CONFIG_OPENGL=y" >> $config_host_mak
4310  echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
4311  echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
4312fi
4313
4314if test "$avx2_opt" = "yes" ; then
4315  echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
4316fi
4317
4318if test "$avx512f_opt" = "yes" ; then
4319  echo "CONFIG_AVX512F_OPT=y" >> $config_host_mak
4320fi
4321
4322# XXX: suppress that
4323if [ "$bsd" = "yes" ] ; then
4324  echo "CONFIG_BSD=y" >> $config_host_mak
4325fi
4326
4327if test "$qom_cast_debug" = "yes" ; then
4328  echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak
4329fi
4330
4331echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
4332if test "$coroutine_pool" = "yes" ; then
4333  echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
4334else
4335  echo "CONFIG_COROUTINE_POOL=0" >> $config_host_mak
4336fi
4337
4338if test "$debug_stack_usage" = "yes" ; then
4339  echo "CONFIG_DEBUG_STACK_USAGE=y" >> $config_host_mak
4340fi
4341
4342if test "$crypto_afalg" = "yes" ; then
4343  echo "CONFIG_AF_ALG=y" >> $config_host_mak
4344fi
4345
4346if test "$have_asan_iface_fiber" = "yes" ; then
4347    echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
4348fi
4349
4350if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
4351    echo "CONFIG_TSAN=y" >> $config_host_mak
4352fi
4353
4354if test "$cpuid_h" = "yes" ; then
4355  echo "CONFIG_CPUID_H=y" >> $config_host_mak
4356fi
4357
4358if test "$int128" = "yes" ; then
4359  echo "CONFIG_INT128=y" >> $config_host_mak
4360fi
4361
4362if test "$atomic128" = "yes" ; then
4363  echo "CONFIG_ATOMIC128=y" >> $config_host_mak
4364fi
4365
4366if test "$cmpxchg128" = "yes" ; then
4367  echo "CONFIG_CMPXCHG128=y" >> $config_host_mak
4368fi
4369
4370if test "$atomic64" = "yes" ; then
4371  echo "CONFIG_ATOMIC64=y" >> $config_host_mak
4372fi
4373
4374if test "$getauxval" = "yes" ; then
4375  echo "CONFIG_GETAUXVAL=y" >> $config_host_mak
4376fi
4377
4378if test "$libssh" = "yes" ; then
4379  echo "CONFIG_LIBSSH=y" >> $config_host_mak
4380  echo "LIBSSH_CFLAGS=$libssh_cflags" >> $config_host_mak
4381  echo "LIBSSH_LIBS=$libssh_libs" >> $config_host_mak
4382fi
4383
4384if test "$live_block_migration" = "yes" ; then
4385  echo "CONFIG_LIVE_BLOCK_MIGRATION=y" >> $config_host_mak
4386fi
4387
4388if test "$tpm" = "yes"; then
4389  echo 'CONFIG_TPM=y' >> $config_host_mak
4390fi
4391
4392if test "$rdma" = "yes" ; then
4393  echo "CONFIG_RDMA=y" >> $config_host_mak
4394  echo "RDMA_LIBS=$rdma_libs" >> $config_host_mak
4395fi
4396
4397if test "$pvrdma" = "yes" ; then
4398  echo "CONFIG_PVRDMA=y" >> $config_host_mak
4399fi
4400
4401if test "$replication" = "yes" ; then
4402  echo "CONFIG_REPLICATION=y" >> $config_host_mak
4403fi
4404
4405if test "$have_af_vsock" = "yes" ; then
4406  echo "CONFIG_AF_VSOCK=y" >> $config_host_mak
4407fi
4408
4409if test "$debug_mutex" = "yes" ; then
4410  echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak
4411fi
4412
4413if test "$bochs" = "yes" ; then
4414  echo "CONFIG_BOCHS=y" >> $config_host_mak
4415fi
4416if test "$cloop" = "yes" ; then
4417  echo "CONFIG_CLOOP=y" >> $config_host_mak
4418fi
4419if test "$dmg" = "yes" ; then
4420  echo "CONFIG_DMG=y" >> $config_host_mak
4421fi
4422if test "$qcow1" = "yes" ; then
4423  echo "CONFIG_QCOW1=y" >> $config_host_mak
4424fi
4425if test "$vdi" = "yes" ; then
4426  echo "CONFIG_VDI=y" >> $config_host_mak
4427fi
4428if test "$vvfat" = "yes" ; then
4429  echo "CONFIG_VVFAT=y" >> $config_host_mak
4430fi
4431if test "$qed" = "yes" ; then
4432  echo "CONFIG_QED=y" >> $config_host_mak
4433fi
4434if test "$parallels" = "yes" ; then
4435  echo "CONFIG_PARALLELS=y" >> $config_host_mak
4436fi
4437
4438if test "$plugins" = "yes" ; then
4439    echo "CONFIG_PLUGIN=y" >> $config_host_mak
4440    # Copy the export object list to the build dir
4441    if test "$ld_dynamic_list" = "yes" ; then
4442	echo "CONFIG_HAS_LD_DYNAMIC_LIST=yes" >> $config_host_mak
4443	ld_symbols=qemu-plugins-ld.symbols
4444	cp "$source_path/plugins/qemu-plugins.symbols" $ld_symbols
4445    elif test "$ld_exported_symbols_list" = "yes" ; then
4446	echo "CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST=yes" >> $config_host_mak
4447	ld64_symbols=qemu-plugins-ld64.symbols
4448	echo "# Automatically generated by configure - do not modify" > $ld64_symbols
4449	grep 'qemu_' "$source_path/plugins/qemu-plugins.symbols" | sed 's/;//g' | \
4450	    sed -E 's/^[[:space:]]*(.*)/_\1/' >> $ld64_symbols
4451    else
4452	error_exit \
4453	    "If \$plugins=yes, either \$ld_dynamic_list or " \
4454	    "\$ld_exported_symbols_list should have been set to 'yes'."
4455    fi
4456fi
4457
4458if test -n "$gdb_bin"; then
4459    gdb_version=$($gdb_bin --version | head -n 1)
4460    if version_ge ${gdb_version##* } 9.1; then
4461        echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
4462    fi
4463fi
4464
4465if test "$secret_keyring" = "yes" ; then
4466  echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak
4467fi
4468
4469echo "ROMS=$roms" >> $config_host_mak
4470echo "MAKE=$make" >> $config_host_mak
4471echo "PYTHON=$python" >> $config_host_mak
4472echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
4473echo "MESON=$meson" >> $config_host_mak
4474echo "NINJA=$ninja" >> $config_host_mak
4475echo "CC=$cc" >> $config_host_mak
4476echo "HOST_CC=$host_cc" >> $config_host_mak
4477if $iasl -h > /dev/null 2>&1; then
4478  echo "CONFIG_IASL=$iasl" >> $config_host_mak
4479fi
4480echo "AR=$ar" >> $config_host_mak
4481echo "AS=$as" >> $config_host_mak
4482echo "CCAS=$ccas" >> $config_host_mak
4483echo "CPP=$cpp" >> $config_host_mak
4484echo "OBJCOPY=$objcopy" >> $config_host_mak
4485echo "LD=$ld" >> $config_host_mak
4486echo "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
4487echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
4488echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
4489echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
4490echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
4491echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
4492echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
4493echo "EXESUF=$EXESUF" >> $config_host_mak
4494echo "LIBS_QGA=$libs_qga" >> $config_host_mak
4495
4496if test "$rng_none" = "yes"; then
4497  echo "CONFIG_RNG_NONE=y" >> $config_host_mak
4498fi
4499
4500# use included Linux headers
4501if test "$linux" = "yes" ; then
4502  mkdir -p linux-headers
4503  case "$cpu" in
4504  i386|x86_64|x32)
4505    linux_arch=x86
4506    ;;
4507  ppc|ppc64|ppc64le)
4508    linux_arch=powerpc
4509    ;;
4510  s390x)
4511    linux_arch=s390
4512    ;;
4513  aarch64)
4514    linux_arch=arm64
4515    ;;
4516  mips64)
4517    linux_arch=mips
4518    ;;
4519  *)
4520    # For most CPUs the kernel architecture name and QEMU CPU name match.
4521    linux_arch="$cpu"
4522    ;;
4523  esac
4524    # For non-KVM architectures we will not have asm headers
4525    if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
4526      symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
4527    fi
4528fi
4529
4530for target in $target_list; do
4531    target_dir="$target"
4532    target_name=$(echo $target | cut -d '-' -f 1)
4533    mkdir -p $target_dir
4534    case $target in
4535        *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
4536        *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
4537    esac
4538done
4539
4540echo "CONFIG_QEMU_INTERP_PREFIX=$interp_prefix" | sed 's/%M/@0@/' >> $config_host_mak
4541if test "$default_targets" = "yes"; then
4542  echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
4543fi
4544
4545if test "$numa" = "yes"; then
4546  echo "CONFIG_NUMA=y" >> $config_host_mak
4547  echo "NUMA_LIBS=$numa_libs" >> $config_host_mak
4548fi
4549
4550if test "$ccache_cpp2" = "yes"; then
4551  echo "export CCACHE_CPP2=y" >> $config_host_mak
4552fi
4553
4554if test "$safe_stack" = "yes"; then
4555  echo "CONFIG_SAFESTACK=y" >> $config_host_mak
4556fi
4557
4558# If we're using a separate build tree, set it up now.
4559# DIRS are directories which we simply mkdir in the build tree;
4560# LINKS are things to symlink back into the source tree
4561# (these can be both files and directories).
4562# Caution: do not add files or directories here using wildcards. This
4563# will result in problems later if a new file matching the wildcard is
4564# added to the source tree -- nothing will cause configure to be rerun
4565# so the build tree will be missing the link back to the new file, and
4566# tests might fail. Prefer to keep the relevant files in their own
4567# directory and symlink the directory instead.
4568# UNLINK is used to remove symlinks from older development versions
4569# that might get into the way when doing "git update" without doing
4570# a "make distclean" in between.
4571DIRS="tests tests/tcg tests/qapi-schema tests/qtest/libqos"
4572DIRS="$DIRS tests/qtest tests/qemu-iotests tests/vm tests/fp tests/qgraph"
4573DIRS="$DIRS docs docs/interop fsdev scsi"
4574DIRS="$DIRS pc-bios/optionrom pc-bios/s390-ccw"
4575DIRS="$DIRS roms/seabios"
4576DIRS="$DIRS contrib/plugins/"
4577LINKS="Makefile"
4578LINKS="$LINKS tests/tcg/Makefile.target"
4579LINKS="$LINKS pc-bios/optionrom/Makefile"
4580LINKS="$LINKS pc-bios/s390-ccw/Makefile"
4581LINKS="$LINKS roms/seabios/Makefile"
4582LINKS="$LINKS pc-bios/qemu-icon.bmp"
4583LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
4584LINKS="$LINKS tests/acceptance tests/data"
4585LINKS="$LINKS tests/qemu-iotests/check"
4586LINKS="$LINKS python"
4587LINKS="$LINKS contrib/plugins/Makefile "
4588UNLINK="pc-bios/keymaps"
4589for bios_file in \
4590    $source_path/pc-bios/*.bin \
4591    $source_path/pc-bios/*.elf \
4592    $source_path/pc-bios/*.lid \
4593    $source_path/pc-bios/*.rom \
4594    $source_path/pc-bios/*.dtb \
4595    $source_path/pc-bios/*.img \
4596    $source_path/pc-bios/openbios-* \
4597    $source_path/pc-bios/u-boot.* \
4598    $source_path/pc-bios/edk2-*.fd.bz2 \
4599    $source_path/pc-bios/palcode-* \
4600    $source_path/pc-bios/qemu_vga.ndrv
4601
4602do
4603    LINKS="$LINKS pc-bios/$(basename $bios_file)"
4604done
4605mkdir -p $DIRS
4606for f in $LINKS ; do
4607    if [ -e "$source_path/$f" ]; then
4608        symlink "$source_path/$f" "$f"
4609    fi
4610done
4611for f in $UNLINK ; do
4612    if [ -L "$f" ]; then
4613        rm -f "$f"
4614    fi
4615done
4616
4617(for i in $cross_cc_vars; do
4618  export $i
4619done
4620export target_list source_path use_containers ARCH
4621$source_path/tests/tcg/configure.sh)
4622
4623# temporary config to build submodules
4624for rom in seabios; do
4625    config_mak=roms/$rom/config.mak
4626    echo "# Automatically generated by configure - do not modify" > $config_mak
4627    echo "SRC_PATH=$source_path/roms/$rom" >> $config_mak
4628    echo "AS=$as" >> $config_mak
4629    echo "CCAS=$ccas" >> $config_mak
4630    echo "CC=$cc" >> $config_mak
4631    echo "BCC=bcc" >> $config_mak
4632    echo "CPP=$cpp" >> $config_mak
4633    echo "OBJCOPY=objcopy" >> $config_mak
4634    echo "IASL=$iasl" >> $config_mak
4635    echo "LD=$ld" >> $config_mak
4636    echo "RANLIB=$ranlib" >> $config_mak
4637done
4638
4639if test "$skip_meson" = no; then
4640  cross="config-meson.cross.new"
4641  meson_quote() {
4642    echo "'$(echo $* | sed "s/ /','/g")'"
4643  }
4644
4645  echo "# Automatically generated by configure - do not modify" > $cross
4646  echo "[properties]" >> $cross
4647
4648  # unroll any custom device configs
4649  for a in $device_archs; do
4650      eval "c=\$devices_${a}"
4651      echo "${a}-softmmu = '$c'" >> $cross
4652  done
4653
4654  test -z "$cxx" && echo "link_language = 'c'" >> $cross
4655  echo "[built-in options]" >> $cross
4656  echo "c_args = [${CFLAGS:+$(meson_quote $CFLAGS)}]" >> $cross
4657  echo "cpp_args = [${CXXFLAGS:+$(meson_quote $CXXFLAGS)}]" >> $cross
4658  echo "c_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross
4659  echo "cpp_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross
4660  echo "[binaries]" >> $cross
4661  echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
4662  test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
4663  test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
4664  echo "ar = [$(meson_quote $ar)]" >> $cross
4665  echo "nm = [$(meson_quote $nm)]" >> $cross
4666  echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
4667  echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
4668  if has $sdl2_config; then
4669    echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
4670  fi
4671  echo "strip = [$(meson_quote $strip)]" >> $cross
4672  echo "windres = [$(meson_quote $windres)]" >> $cross
4673  if test "$cross_compile" = "yes"; then
4674    cross_arg="--cross-file config-meson.cross"
4675    echo "[host_machine]" >> $cross
4676    if test "$mingw32" = "yes" ; then
4677        echo "system = 'windows'" >> $cross
4678    fi
4679    if test "$linux" = "yes" ; then
4680        echo "system = 'linux'" >> $cross
4681    fi
4682    if test "$darwin" = "yes" ; then
4683        echo "system = 'darwin'" >> $cross
4684    fi
4685    case "$ARCH" in
4686        i386)
4687            echo "cpu_family = 'x86'" >> $cross
4688            ;;
4689        x86_64|x32)
4690            echo "cpu_family = 'x86_64'" >> $cross
4691            ;;
4692        ppc64le)
4693            echo "cpu_family = 'ppc64'" >> $cross
4694            ;;
4695        *)
4696            echo "cpu_family = '$ARCH'" >> $cross
4697            ;;
4698    esac
4699    echo "cpu = '$cpu'" >> $cross
4700    if test "$bigendian" = "yes" ; then
4701        echo "endian = 'big'" >> $cross
4702    else
4703        echo "endian = 'little'" >> $cross
4704    fi
4705  else
4706    cross_arg="--native-file config-meson.cross"
4707  fi
4708  mv $cross config-meson.cross
4709
4710  rm -rf meson-private meson-info meson-logs
4711  NINJA=$ninja $meson setup \
4712        --prefix "$prefix" \
4713        --libdir "$libdir" \
4714        --libexecdir "$libexecdir" \
4715        --bindir "$bindir" \
4716        --includedir "$includedir" \
4717        --datadir "$datadir" \
4718        --mandir "$mandir" \
4719        --sysconfdir "$sysconfdir" \
4720        --localedir "$localedir" \
4721        --localstatedir "$local_statedir" \
4722        -Ddocdir="$docdir" \
4723        -Dqemu_firmwarepath="$firmwarepath" \
4724        -Dqemu_suffix="$qemu_suffix" \
4725        -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) \
4726        -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo false; fi) \
4727        -Dwerror=$(if test "$werror" = yes; then echo true; else echo false; fi) \
4728        -Dstrip=$(if test "$strip_opt" = yes; then echo true; else echo false; fi) \
4729        -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \
4730        -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
4731        -Db_lto=$lto -Dcfi=$cfi -Dcfi_debug=$cfi_debug -Dfuzzing=$fuzzing \
4732        $(test -n "${LIB_FUZZING_ENGINE+xxx}" && echo "-Dfuzzing_engine=$LIB_FUZZING_ENGINE") \
4733        -Dmalloc=$malloc -Dmalloc_trim=$malloc_trim -Dsparse=$sparse \
4734        -Dkvm=$kvm -Dhax=$hax -Dwhpx=$whpx -Dhvf=$hvf -Dnvmm=$nvmm \
4735        -Dxen=$xen -Dxen_pci_passthrough=$xen_pci_passthrough -Dtcg=$tcg \
4736        -Dcocoa=$cocoa -Dgtk=$gtk -Dmpath=$mpath -Dsdl=$sdl -Dsdl_image=$sdl_image \
4737        -Dlibusb=$libusb -Dsmartcard=$smartcard -Dusb_redir=$usb_redir -Dvte=$vte \
4738        -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \
4739        -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f -Dvirtiofsd=$virtiofsd \
4740        -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt -Dbrlapi=$brlapi \
4741        -Dcurl=$curl -Dglusterfs=$glusterfs -Dbzip2=$bzip2 -Dlibiscsi=$libiscsi \
4742        -Dlibnfs=$libnfs -Diconv=$iconv -Dcurses=$curses -Dlibudev=$libudev\
4743        -Drbd=$rbd -Dlzo=$lzo -Dsnappy=$snappy -Dlzfse=$lzfse -Dlibxml2=$libxml2 \
4744        -Dlibdaxctl=$libdaxctl -Dlibpmem=$libpmem -Dlinux_io_uring=$linux_io_uring \
4745        -Dgnutls=$gnutls -Dnettle=$nettle -Dgcrypt=$gcrypt -Dauth_pam=$auth_pam \
4746        -Dzstd=$zstd -Dseccomp=$seccomp -Dvirtfs=$virtfs -Dcap_ng=$cap_ng \
4747        -Dattr=$attr -Ddefault_devices=$default_devices -Dvirglrenderer=$virglrenderer \
4748        -Ddocs=$docs -Dsphinx_build=$sphinx_build -Dinstall_blobs=$blobs \
4749        -Dvhost_user_blk_server=$vhost_user_blk_server -Dmultiprocess=$multiprocess \
4750        -Dfuse=$fuse -Dfuse_lseek=$fuse_lseek -Dguest_agent_msi=$guest_agent_msi -Dbpf=$bpf\
4751        $(if test "$default_feature" = no; then echo "-Dauto_features=disabled"; fi) \
4752        -Dalsa=$alsa -Dcoreaudio=$coreaudio -Ddsound=$dsound -Djack=$jack -Doss=$oss \
4753        -Dpa=$pa -Daudio_drv_list=$audio_drv_list -Dtcg_interpreter=$tcg_interpreter \
4754        -Dtrace_backends=$trace_backends -Dtrace_file=$trace_file -Dlinux_aio=$linux_aio \
4755        $cross_arg \
4756        "$PWD" "$source_path"
4757
4758  if test "$?" -ne 0 ; then
4759      error_exit "meson setup failed"
4760  fi
4761else
4762  if test -f meson-private/cmd_line.txt; then
4763    # Adjust old command line options whose type was changed
4764    # Avoids having to use "setup --wipe" when Meson is upgraded
4765    perl -i -ne '
4766      s/^gettext = true$/gettext = auto/;
4767      s/^gettext = false$/gettext = disabled/;
4768      /^b_staticpic/ && next;
4769      print;' meson-private/cmd_line.txt
4770  fi
4771fi
4772
4773if test -n "${deprecated_features}"; then
4774    echo "Warning, deprecated features enabled."
4775    echo "Please see docs/about/deprecated.rst"
4776    echo "  features: ${deprecated_features}"
4777fi
4778
4779# Create list of config switches that should be poisoned in common code...
4780# but filter out CONFIG_TCG and CONFIG_USER_ONLY which are special.
4781target_configs_h=$(ls *-config-devices.h *-config-target.h 2>/dev/null)
4782if test -n "$target_configs_h" ; then
4783    sed -n -e '/CONFIG_TCG/d' -e '/CONFIG_USER_ONLY/d' \
4784        -e '/^#define / { s///; s/ .*//; s/^/#pragma GCC poison /p; }' \
4785        $target_configs_h | sort -u > config-poison.h
4786else
4787    :> config-poison.h
4788fi
4789
4790# Save the configure command line for later reuse.
4791cat <<EOD >config.status
4792#!/bin/sh
4793# Generated by configure.
4794# Run this file to recreate the current configuration.
4795# Compiler output produced by configure, useful for debugging
4796# configure, is in config.log if it exists.
4797EOD
4798
4799preserve_env() {
4800    envname=$1
4801
4802    eval envval=\$$envname
4803
4804    if test -n "$envval"
4805    then
4806	echo "$envname='$envval'" >> config.status
4807	echo "export $envname" >> config.status
4808    else
4809	echo "unset $envname" >> config.status
4810    fi
4811}
4812
4813# Preserve various env variables that influence what
4814# features/build target configure will detect
4815preserve_env AR
4816preserve_env AS
4817preserve_env CC
4818preserve_env CPP
4819preserve_env CXX
4820preserve_env INSTALL
4821preserve_env LD
4822preserve_env LD_LIBRARY_PATH
4823preserve_env LIBTOOL
4824preserve_env MAKE
4825preserve_env NM
4826preserve_env OBJCOPY
4827preserve_env PATH
4828preserve_env PKG_CONFIG
4829preserve_env PKG_CONFIG_LIBDIR
4830preserve_env PKG_CONFIG_PATH
4831preserve_env PYTHON
4832preserve_env SDL2_CONFIG
4833preserve_env SMBD
4834preserve_env STRIP
4835preserve_env WINDRES
4836
4837printf "exec" >>config.status
4838for i in "$0" "$@"; do
4839  test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
4840done
4841echo ' "$@"' >>config.status
4842chmod +x config.status
4843
4844rm -r "$TMPDIR1"
4845