xref: /qemu/configure (revision 74fb2f4f4c47c966ab54687392e6561b4de4bb8a)
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="-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 $EXTRA_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 $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
184      $LDFLAGS $EXTRA_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
289EXTRA_CFLAGS=""
290EXTRA_CXXFLAGS=""
291EXTRA_LDFLAGS=""
292
293xen_ctrl_version="$default_feature"
294xfs="$default_feature"
295membarrier="$default_feature"
296vhost_kernel="$default_feature"
297vhost_net="$default_feature"
298vhost_crypto="$default_feature"
299vhost_scsi="$default_feature"
300vhost_vsock="$default_feature"
301vhost_user="no"
302vhost_user_fs="$default_feature"
303vhost_vdpa="$default_feature"
304rdma="$default_feature"
305pvrdma="$default_feature"
306gprof="no"
307debug_tcg="no"
308debug="no"
309sanitizers="no"
310tsan="no"
311fortify_source="$default_feature"
312strip_opt="yes"
313mingw32="no"
314gcov="no"
315EXESUF=""
316modules="no"
317module_upgrades="no"
318prefix="/usr/local"
319qemu_suffix="qemu"
320bsd="no"
321linux="no"
322solaris="no"
323profiler="no"
324softmmu="yes"
325linux_user="no"
326bsd_user="no"
327pkgversion=""
328pie=""
329qom_cast_debug="yes"
330trace_backends="log"
331trace_file="trace"
332opengl="$default_feature"
333cpuid_h="no"
334avx2_opt="$default_feature"
335guest_agent="$default_feature"
336guest_agent_with_vss="no"
337guest_agent_ntddscsi="no"
338vss_win32_sdk="$default_feature"
339win_sdk="no"
340want_tools="$default_feature"
341coroutine=""
342coroutine_pool="$default_feature"
343debug_stack_usage="no"
344crypto_afalg="no"
345tls_priority="NORMAL"
346tpm="$default_feature"
347live_block_migration=${default_feature:-yes}
348numa="$default_feature"
349replication=${default_feature:-yes}
350bochs=${default_feature:-yes}
351cloop=${default_feature:-yes}
352dmg=${default_feature:-yes}
353qcow1=${default_feature:-yes}
354vdi=${default_feature:-yes}
355vvfat=${default_feature:-yes}
356qed=${default_feature:-yes}
357parallels=${default_feature:-yes}
358debug_mutex="no"
359plugins="$default_feature"
360rng_none="no"
361secret_keyring="$default_feature"
362meson=""
363meson_args=""
364ninja=""
365gio="$default_feature"
366skip_meson=no
367slirp_smbd="$default_feature"
368
369# The following Meson options are handled manually (still they
370# are included in the automatically generated help message)
371
372# 1. Track which submodules are needed
373capstone="auto"
374fdt="auto"
375slirp="auto"
376
377# 2. Support --with/--without option
378default_devices="true"
379
380# 3. Automatically enable/disable other options
381tcg="enabled"
382cfi="false"
383
384# 4. Detection partly done in configure
385xen=${default_feature:+disabled}
386
387# parse CC options second
388for opt do
389  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
390  case "$opt" in
391  --cross-prefix=*) cross_prefix="$optarg"
392                    cross_compile="yes"
393  ;;
394  --cc=*) CC="$optarg"
395  ;;
396  --cxx=*) CXX="$optarg"
397  ;;
398  --cpu=*) cpu="$optarg"
399  ;;
400  --extra-cflags=*)
401    EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
402    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
403    ;;
404  --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
405  ;;
406  --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
407  ;;
408  --enable-debug-info) debug_info="yes"
409  ;;
410  --disable-debug-info) debug_info="no"
411  ;;
412  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
413  ;;
414  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-flags-}; cc_arch=${cc_arch%%=*}
415                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
416                      cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
417  ;;
418  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
419                cc_archs="$cc_archs $cc_arch"
420                eval "cross_cc_${cc_arch}=\$optarg"
421                cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
422  ;;
423  esac
424done
425# OS specific
426# Using uname is really, really broken.  Once we have the right set of checks
427# we can eliminate its usage altogether.
428
429# Preferred compiler:
430#  ${CC} (if set)
431#  ${cross_prefix}gcc (if cross-prefix specified)
432#  system compiler
433if test -z "${CC}${cross_prefix}"; then
434  cc="$host_cc"
435else
436  cc="${CC-${cross_prefix}gcc}"
437fi
438
439if test -z "${CXX}${cross_prefix}"; then
440  cxx="c++"
441else
442  cxx="${CXX-${cross_prefix}g++}"
443fi
444
445ar="${AR-${cross_prefix}ar}"
446as="${AS-${cross_prefix}as}"
447ccas="${CCAS-$cc}"
448cpp="${CPP-$cc -E}"
449objcopy="${OBJCOPY-${cross_prefix}objcopy}"
450ld="${LD-${cross_prefix}ld}"
451ranlib="${RANLIB-${cross_prefix}ranlib}"
452nm="${NM-${cross_prefix}nm}"
453strip="${STRIP-${cross_prefix}strip}"
454windres="${WINDRES-${cross_prefix}windres}"
455pkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
456query_pkg_config() {
457    "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
458}
459pkg_config=query_pkg_config
460sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
461
462# default flags for all hosts
463# We use -fwrapv to tell the compiler that we require a C dialect where
464# left shift of signed integers is well defined and has the expected
465# 2s-complement style results. (Both clang and gcc agree that it
466# provides these semantics.)
467QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
468QEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
469QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
470QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
471
472QEMU_LDFLAGS=
473
474# Flags that are needed during configure but later taken care of by Meson
475CONFIGURE_CFLAGS="-std=gnu11 -Wall"
476CONFIGURE_LDFLAGS=
477
478
479check_define() {
480cat > $TMPC <<EOF
481#if !defined($1)
482#error $1 not defined
483#endif
484int main(void) { return 0; }
485EOF
486  compile_object
487}
488
489check_include() {
490cat > $TMPC <<EOF
491#include <$1>
492int main(void) { return 0; }
493EOF
494  compile_object
495}
496
497write_c_skeleton() {
498    cat > $TMPC <<EOF
499int main(void) { return 0; }
500EOF
501}
502
503if check_define __linux__ ; then
504  targetos="Linux"
505elif check_define _WIN32 ; then
506  targetos='MINGW32'
507elif check_define __OpenBSD__ ; then
508  targetos='OpenBSD'
509elif check_define __sun__ ; then
510  targetos='SunOS'
511elif check_define __HAIKU__ ; then
512  targetos='Haiku'
513elif check_define __FreeBSD__ ; then
514  targetos='FreeBSD'
515elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
516  targetos='GNU/kFreeBSD'
517elif check_define __DragonFly__ ; then
518  targetos='DragonFly'
519elif check_define __NetBSD__; then
520  targetos='NetBSD'
521elif check_define __APPLE__; then
522  targetos='Darwin'
523else
524  # This is a fatal error, but don't report it yet, because we
525  # might be going to just print the --help text, or it might
526  # be the result of a missing compiler.
527  targetos='bogus'
528fi
529
530# Some host OSes need non-standard checks for which CPU to use.
531# Note that these checks are broken for cross-compilation: if you're
532# cross-compiling to one of these OSes then you'll need to specify
533# the correct CPU with the --cpu option.
534case $targetos in
535SunOS)
536  # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
537  if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
538    cpu="x86_64"
539  fi
540esac
541
542if test ! -z "$cpu" ; then
543  # command line argument
544  :
545elif check_define __i386__ ; then
546  cpu="i386"
547elif check_define __x86_64__ ; then
548  if check_define __ILP32__ ; then
549    cpu="x32"
550  else
551    cpu="x86_64"
552  fi
553elif check_define __sparc__ ; then
554  if check_define __arch64__ ; then
555    cpu="sparc64"
556  else
557    cpu="sparc"
558  fi
559elif check_define _ARCH_PPC ; then
560  if check_define _ARCH_PPC64 ; then
561    if check_define _LITTLE_ENDIAN ; then
562      cpu="ppc64le"
563    else
564      cpu="ppc64"
565    fi
566  else
567    cpu="ppc"
568  fi
569elif check_define __mips__ ; then
570  cpu="mips"
571elif check_define __s390__ ; then
572  if check_define __s390x__ ; then
573    cpu="s390x"
574  else
575    cpu="s390"
576  fi
577elif check_define __riscv ; then
578  cpu="riscv"
579elif check_define __arm__ ; then
580  cpu="arm"
581elif check_define __aarch64__ ; then
582  cpu="aarch64"
583else
584  cpu=$(uname -m)
585fi
586
587ARCH=
588# Normalise host CPU name and set ARCH.
589# Note that this case should only have supported host CPUs, not guests.
590case "$cpu" in
591  ppc|ppc64|s390x|sparc64|x32|riscv)
592  ;;
593  ppc64le)
594    ARCH="ppc64"
595  ;;
596  i386|i486|i586|i686|i86pc|BePC)
597    cpu="i386"
598  ;;
599  x86_64|amd64)
600    cpu="x86_64"
601  ;;
602  armv*b|armv*l|arm)
603    cpu="arm"
604  ;;
605  aarch64)
606    cpu="aarch64"
607  ;;
608  mips*)
609    cpu="mips"
610  ;;
611  sparc|sun4[cdmuv])
612    cpu="sparc"
613  ;;
614  *)
615    # This will result in either an error or falling back to TCI later
616    ARCH=unknown
617  ;;
618esac
619if test -z "$ARCH"; then
620  ARCH="$cpu"
621fi
622
623# OS specific
624
625case $targetos in
626MINGW32*)
627  mingw32="yes"
628  plugins="no"
629  pie="no"
630;;
631GNU/kFreeBSD)
632  bsd="yes"
633;;
634FreeBSD)
635  bsd="yes"
636  bsd_user="yes"
637  make="${MAKE-gmake}"
638  # needed for kinfo_getvmmap(3) in libutil.h
639;;
640DragonFly)
641  bsd="yes"
642  make="${MAKE-gmake}"
643;;
644NetBSD)
645  bsd="yes"
646  make="${MAKE-gmake}"
647;;
648OpenBSD)
649  bsd="yes"
650  make="${MAKE-gmake}"
651;;
652Darwin)
653  bsd="yes"
654  darwin="yes"
655  # Disable attempts to use ObjectiveC features in os/object.h since they
656  # won't work when we're compiling with gcc as a C compiler.
657  QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
658;;
659SunOS)
660  solaris="yes"
661  make="${MAKE-gmake}"
662  smbd="${SMBD-/usr/sfw/sbin/smbd}"
663# needed for CMSG_ macros in sys/socket.h
664  QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
665# needed for TIOCWIN* defines in termios.h
666  QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
667;;
668Haiku)
669  pie="no"
670  QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
671;;
672Linux)
673  linux="yes"
674  linux_user="yes"
675  vhost_user=${default_feature:-yes}
676;;
677esac
678
679: ${make=${MAKE-make}}
680
681# We prefer python 3.x. A bare 'python' is traditionally
682# python 2.x, but some distros have it as python 3.x, so
683# we check that too
684python=
685explicit_python=no
686for binary in "${PYTHON-python3}" python
687do
688    if has "$binary"
689    then
690        python=$(command -v "$binary")
691        break
692    fi
693done
694
695
696# Check for ancillary tools used in testing
697genisoimage=
698for binary in genisoimage mkisofs
699do
700    if has $binary
701    then
702        genisoimage=$(command -v "$binary")
703        break
704    fi
705done
706
707# Default objcc to clang if available, otherwise use CC
708if has clang; then
709  objcc=clang
710else
711  objcc="$cc"
712fi
713
714if test "$mingw32" = "yes" ; then
715  EXESUF=".exe"
716  # MinGW needs -mthreads for TLS and macro _MT.
717  CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
718  write_c_skeleton;
719  prefix="/qemu"
720  qemu_suffix=""
721  libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi -lnetapi32 $libs_qga"
722fi
723
724werror=""
725
726. $source_path/scripts/meson-buildoptions.sh
727
728meson_options=
729meson_option_parse() {
730  meson_options="$meson_options $(_meson_option_parse "$@")"
731  if test $? -eq 1; then
732    echo "ERROR: unknown option $1"
733    echo "Try '$0 --help' for more information"
734    exit 1
735  fi
736}
737
738for opt do
739  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
740  case "$opt" in
741  --help|-h) show_help=yes
742  ;;
743  --version|-V) exec cat $source_path/VERSION
744  ;;
745  --prefix=*) prefix="$optarg"
746  ;;
747  --interp-prefix=*) interp_prefix="$optarg"
748  ;;
749  --cross-prefix=*)
750  ;;
751  --cc=*)
752  ;;
753  --host-cc=*) host_cc="$optarg"
754  ;;
755  --cxx=*)
756  ;;
757  --iasl=*) iasl="$optarg"
758  ;;
759  --objcc=*) objcc="$optarg"
760  ;;
761  --make=*) make="$optarg"
762  ;;
763  --install=*)
764  ;;
765  --python=*) python="$optarg" ; explicit_python=yes
766  ;;
767  --sphinx-build=*) sphinx_build="$optarg"
768  ;;
769  --skip-meson) skip_meson=yes
770  ;;
771  --meson=*) meson="$optarg"
772  ;;
773  --ninja=*) ninja="$optarg"
774  ;;
775  --smbd=*) smbd="$optarg"
776  ;;
777  --extra-cflags=*)
778  ;;
779  --extra-cxxflags=*)
780  ;;
781  --extra-ldflags=*)
782  ;;
783  --enable-debug-info)
784  ;;
785  --disable-debug-info)
786  ;;
787  --cross-cc-*)
788  ;;
789  --enable-modules)
790      modules="yes"
791  ;;
792  --disable-modules)
793      modules="no"
794  ;;
795  --disable-module-upgrades) module_upgrades="no"
796  ;;
797  --enable-module-upgrades) module_upgrades="yes"
798  ;;
799  --cpu=*)
800  ;;
801  --target-list=*) target_list="$optarg"
802                   if test "$target_list_exclude"; then
803                       error_exit "Can't mix --target-list with --target-list-exclude"
804                   fi
805  ;;
806  --target-list-exclude=*) target_list_exclude="$optarg"
807                   if test "$target_list"; then
808                       error_exit "Can't mix --target-list-exclude with --target-list"
809                   fi
810  ;;
811  --with-trace-file=*) trace_file="$optarg"
812  ;;
813  --with-default-devices) default_devices="true"
814  ;;
815  --without-default-devices) default_devices="false"
816  ;;
817  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
818  ;;
819  --with-devices-*) device_arch=${opt#--with-devices-};
820                    device_arch=${device_arch%%=*}
821                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
822                    if test -f "$cf"; then
823                        device_archs="$device_archs $device_arch"
824                        eval "devices_${device_arch}=\$optarg"
825                    else
826                        error_exit "File $cf does not exist"
827                    fi
828  ;;
829  --without-default-features) # processed above
830  ;;
831  --enable-gprof) gprof="yes"
832  ;;
833  --enable-gcov) gcov="yes"
834  ;;
835  --static)
836    static="yes"
837    QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
838  ;;
839  --mandir=*) mandir="$optarg"
840  ;;
841  --bindir=*) bindir="$optarg"
842  ;;
843  --libdir=*) libdir="$optarg"
844  ;;
845  --libexecdir=*) libexecdir="$optarg"
846  ;;
847  --includedir=*) includedir="$optarg"
848  ;;
849  --datadir=*) datadir="$optarg"
850  ;;
851  --with-suffix=*) qemu_suffix="$optarg"
852  ;;
853  --docdir=*) docdir="$optarg"
854  ;;
855  --localedir=*) localedir="$optarg"
856  ;;
857  --sysconfdir=*) sysconfdir="$optarg"
858  ;;
859  --localstatedir=*) local_statedir="$optarg"
860  ;;
861  --firmwarepath=*) firmwarepath="$optarg"
862  ;;
863  --host=*|--build=*|\
864  --disable-dependency-tracking|\
865  --sbindir=*|--sharedstatedir=*|\
866  --oldincludedir=*|--datarootdir=*|--infodir=*|\
867  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
868    # These switches are silently ignored, for compatibility with
869    # autoconf-generated configure scripts. This allows QEMU's
870    # configure to be used by RPM and similar macros that set
871    # lots of directory switches by default.
872  ;;
873  --disable-qom-cast-debug) qom_cast_debug="no"
874  ;;
875  --enable-qom-cast-debug) qom_cast_debug="yes"
876  ;;
877  --audio-drv-list=*) audio_drv_list="$optarg"
878  ;;
879  --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
880  ;;
881  --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
882  ;;
883  --enable-block-drv-whitelist-in-tools) block_drv_whitelist_tools="yes"
884  ;;
885  --disable-block-drv-whitelist-in-tools) block_drv_whitelist_tools="no"
886  ;;
887  --enable-debug-tcg) debug_tcg="yes"
888  ;;
889  --disable-debug-tcg) debug_tcg="no"
890  ;;
891  --enable-debug)
892      # Enable debugging options that aren't excessively noisy
893      debug_tcg="yes"
894      debug_mutex="yes"
895      debug="yes"
896      strip_opt="no"
897      fortify_source="no"
898  ;;
899  --enable-sanitizers) sanitizers="yes"
900  ;;
901  --disable-sanitizers) sanitizers="no"
902  ;;
903  --enable-tsan) tsan="yes"
904  ;;
905  --disable-tsan) tsan="no"
906  ;;
907  --disable-strip) strip_opt="no"
908  ;;
909  --disable-slirp) slirp="disabled"
910  ;;
911  --enable-slirp) slirp="enabled"
912  ;;
913  --enable-slirp=git) slirp="internal"
914  ;;
915  --enable-slirp=*) slirp="$optarg"
916  ;;
917  --disable-xen) xen="disabled"
918  ;;
919  --enable-xen) xen="enabled"
920  ;;
921  --disable-tcg) tcg="disabled"
922                 plugins="no"
923  ;;
924  --enable-tcg) tcg="enabled"
925  ;;
926  --enable-profiler) profiler="yes"
927  ;;
928  --disable-system) softmmu="no"
929  ;;
930  --enable-system) softmmu="yes"
931  ;;
932  --disable-user)
933      linux_user="no" ;
934      bsd_user="no" ;
935  ;;
936  --enable-user) ;;
937  --disable-linux-user) linux_user="no"
938  ;;
939  --enable-linux-user) linux_user="yes"
940  ;;
941  --disable-bsd-user) bsd_user="no"
942  ;;
943  --enable-bsd-user) bsd_user="yes"
944  ;;
945  --enable-pie) pie="yes"
946  ;;
947  --disable-pie) pie="no"
948  ;;
949  --enable-werror) werror="yes"
950  ;;
951  --disable-werror) werror="no"
952  ;;
953  --enable-lto) lto="true"
954  ;;
955  --disable-lto) lto="false"
956  ;;
957  --enable-stack-protector) stack_protector="yes"
958  ;;
959  --disable-stack-protector) stack_protector="no"
960  ;;
961  --enable-safe-stack) safe_stack="yes"
962  ;;
963  --disable-safe-stack) safe_stack="no"
964  ;;
965  --enable-cfi)
966      cfi="true";
967      lto="true";
968  ;;
969  --disable-cfi) cfi="false"
970  ;;
971  --disable-fdt) fdt="disabled"
972  ;;
973  --enable-fdt) fdt="enabled"
974  ;;
975  --enable-fdt=git) fdt="internal"
976  ;;
977  --enable-fdt=*) fdt="$optarg"
978  ;;
979  --disable-membarrier) membarrier="no"
980  ;;
981  --enable-membarrier) membarrier="yes"
982  ;;
983  --with-pkgversion=*) pkgversion="$optarg"
984  ;;
985  --with-coroutine=*) coroutine="$optarg"
986  ;;
987  --disable-coroutine-pool) coroutine_pool="no"
988  ;;
989  --enable-coroutine-pool) coroutine_pool="yes"
990  ;;
991  --enable-debug-stack-usage) debug_stack_usage="yes"
992  ;;
993  --enable-crypto-afalg) crypto_afalg="yes"
994  ;;
995  --disable-crypto-afalg) crypto_afalg="no"
996  ;;
997  --disable-vhost-net) vhost_net="no"
998  ;;
999  --enable-vhost-net) vhost_net="yes"
1000  ;;
1001  --disable-vhost-crypto) vhost_crypto="no"
1002  ;;
1003  --enable-vhost-crypto) vhost_crypto="yes"
1004  ;;
1005  --disable-vhost-scsi) vhost_scsi="no"
1006  ;;
1007  --enable-vhost-scsi) vhost_scsi="yes"
1008  ;;
1009  --disable-vhost-vsock) vhost_vsock="no"
1010  ;;
1011  --enable-vhost-vsock) vhost_vsock="yes"
1012  ;;
1013  --disable-vhost-user-fs) vhost_user_fs="no"
1014  ;;
1015  --enable-vhost-user-fs) vhost_user_fs="yes"
1016  ;;
1017  --disable-opengl) opengl="no"
1018  ;;
1019  --enable-opengl) opengl="yes"
1020  ;;
1021  --disable-xfsctl) xfs="no"
1022  ;;
1023  --enable-xfsctl) xfs="yes"
1024  ;;
1025  --disable-zlib-test)
1026  ;;
1027  --enable-guest-agent) guest_agent="yes"
1028  ;;
1029  --disable-guest-agent) guest_agent="no"
1030  ;;
1031  --with-vss-sdk) vss_win32_sdk=""
1032  ;;
1033  --with-vss-sdk=*) vss_win32_sdk="$optarg"
1034  ;;
1035  --without-vss-sdk) vss_win32_sdk="no"
1036  ;;
1037  --with-win-sdk) win_sdk=""
1038  ;;
1039  --with-win-sdk=*) win_sdk="$optarg"
1040  ;;
1041  --without-win-sdk) win_sdk="no"
1042  ;;
1043  --enable-tools) want_tools="yes"
1044  ;;
1045  --disable-tools) want_tools="no"
1046  ;;
1047  --disable-avx2) avx2_opt="no"
1048  ;;
1049  --enable-avx2) avx2_opt="yes"
1050  ;;
1051  --disable-avx512f) avx512f_opt="no"
1052  ;;
1053  --enable-avx512f) avx512f_opt="yes"
1054  ;;
1055  --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
1056      echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
1057  ;;
1058  --enable-vhdx|--disable-vhdx)
1059      echo "$0: $opt is obsolete, VHDX driver is always built" >&2
1060  ;;
1061  --enable-uuid|--disable-uuid)
1062      echo "$0: $opt is obsolete, UUID support is always built" >&2
1063  ;;
1064  --tls-priority=*) tls_priority="$optarg"
1065  ;;
1066  --enable-rdma) rdma="yes"
1067  ;;
1068  --disable-rdma) rdma="no"
1069  ;;
1070  --enable-pvrdma) pvrdma="yes"
1071  ;;
1072  --disable-pvrdma) pvrdma="no"
1073  ;;
1074  --disable-tpm) tpm="no"
1075  ;;
1076  --enable-tpm) tpm="yes"
1077  ;;
1078  --disable-live-block-migration) live_block_migration="no"
1079  ;;
1080  --enable-live-block-migration) live_block_migration="yes"
1081  ;;
1082  --disable-numa) numa="no"
1083  ;;
1084  --enable-numa) numa="yes"
1085  ;;
1086  --disable-replication) replication="no"
1087  ;;
1088  --enable-replication) replication="yes"
1089  ;;
1090  --disable-bochs) bochs="no"
1091  ;;
1092  --enable-bochs) bochs="yes"
1093  ;;
1094  --disable-cloop) cloop="no"
1095  ;;
1096  --enable-cloop) cloop="yes"
1097  ;;
1098  --disable-dmg) dmg="no"
1099  ;;
1100  --enable-dmg) dmg="yes"
1101  ;;
1102  --disable-qcow1) qcow1="no"
1103  ;;
1104  --enable-qcow1) qcow1="yes"
1105  ;;
1106  --disable-vdi) vdi="no"
1107  ;;
1108  --enable-vdi) vdi="yes"
1109  ;;
1110  --disable-vvfat) vvfat="no"
1111  ;;
1112  --enable-vvfat) vvfat="yes"
1113  ;;
1114  --disable-qed) qed="no"
1115  ;;
1116  --enable-qed) qed="yes"
1117  ;;
1118  --disable-parallels) parallels="no"
1119  ;;
1120  --enable-parallels) parallels="yes"
1121  ;;
1122  --disable-vhost-user) vhost_user="no"
1123  ;;
1124  --enable-vhost-user) vhost_user="yes"
1125  ;;
1126  --disable-vhost-vdpa) vhost_vdpa="no"
1127  ;;
1128  --enable-vhost-vdpa) vhost_vdpa="yes"
1129  ;;
1130  --disable-vhost-kernel) vhost_kernel="no"
1131  ;;
1132  --enable-vhost-kernel) vhost_kernel="yes"
1133  ;;
1134  --disable-capstone) capstone="disabled"
1135  ;;
1136  --enable-capstone) capstone="enabled"
1137  ;;
1138  --enable-capstone=git) capstone="internal"
1139  ;;
1140  --enable-capstone=*) capstone="$optarg"
1141  ;;
1142  --with-git=*) git="$optarg"
1143  ;;
1144  --with-git-submodules=*)
1145      git_submodules_action="$optarg"
1146  ;;
1147  --enable-debug-mutex) debug_mutex=yes
1148  ;;
1149  --disable-debug-mutex) debug_mutex=no
1150  ;;
1151  --enable-plugins) if test "$mingw32" = "yes"; then
1152                        error_exit "TCG plugins not currently supported on Windows platforms"
1153                    else
1154                        plugins="yes"
1155                    fi
1156  ;;
1157  --disable-plugins) plugins="no"
1158  ;;
1159  --enable-containers) use_containers="yes"
1160  ;;
1161  --disable-containers) use_containers="no"
1162  ;;
1163  --gdb=*) gdb_bin="$optarg"
1164  ;;
1165  --enable-rng-none) rng_none=yes
1166  ;;
1167  --disable-rng-none) rng_none=no
1168  ;;
1169  --enable-keyring) secret_keyring="yes"
1170  ;;
1171  --disable-keyring) secret_keyring="no"
1172  ;;
1173  --enable-gio) gio=yes
1174  ;;
1175  --disable-gio) gio=no
1176  ;;
1177  --enable-slirp-smbd) slirp_smbd=yes
1178  ;;
1179  --disable-slirp-smbd) slirp_smbd=no
1180  ;;
1181  # backwards compatibility options
1182  --enable-trace-backend=*) meson_option_parse "--enable-trace-backends=$optarg" "$optarg"
1183  ;;
1184  --disable-blobs) meson_option_parse --disable-install-blobs ""
1185  ;;
1186  --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
1187  ;;
1188  --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
1189  ;;
1190  # everything else has the same name in configure and meson
1191  --enable-* | --disable-*) meson_option_parse "$opt" "$optarg"
1192  ;;
1193  *)
1194      echo "ERROR: unknown option $opt"
1195      echo "Try '$0 --help' for more information"
1196      exit 1
1197  ;;
1198  esac
1199done
1200
1201# test for any invalid configuration combinations
1202if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
1203    error_exit "Can't enable plugins on non-TCG builds"
1204fi
1205
1206case $git_submodules_action in
1207    update|validate)
1208        if test ! -e "$source_path/.git"; then
1209            echo "ERROR: cannot $git_submodules_action git submodules without .git"
1210            exit 1
1211        fi
1212    ;;
1213    ignore)
1214        if ! test -f "$source_path/ui/keycodemapdb/README"
1215        then
1216            echo
1217            echo "ERROR: missing GIT submodules"
1218            echo
1219            if test -e "$source_path/.git"; then
1220                echo "--with-git-submodules=ignore specified but submodules were not"
1221                echo "checked out.  Please initialize and update submodules."
1222            else
1223                echo "This is not a GIT checkout but module content appears to"
1224                echo "be missing. Do not use 'git archive' or GitHub download links"
1225                echo "to acquire QEMU source archives. Non-GIT builds are only"
1226                echo "supported with source archives linked from:"
1227                echo
1228                echo "  https://www.qemu.org/download/#source"
1229                echo
1230                echo "Developers working with GIT can use scripts/archive-source.sh"
1231                echo "if they need to create valid source archives."
1232            fi
1233            echo
1234            exit 1
1235        fi
1236    ;;
1237    *)
1238        echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
1239        exit 1
1240    ;;
1241esac
1242
1243libdir="${libdir:-$prefix/lib}"
1244libexecdir="${libexecdir:-$prefix/libexec}"
1245includedir="${includedir:-$prefix/include}"
1246
1247if test "$mingw32" = "yes" ; then
1248    bindir="${bindir:-$prefix}"
1249else
1250    bindir="${bindir:-$prefix/bin}"
1251fi
1252mandir="${mandir:-$prefix/share/man}"
1253datadir="${datadir:-$prefix/share}"
1254docdir="${docdir:-$prefix/share/doc}"
1255sysconfdir="${sysconfdir:-$prefix/etc}"
1256local_statedir="${local_statedir:-$prefix/var}"
1257firmwarepath="${firmwarepath:-$datadir/qemu-firmware}"
1258localedir="${localedir:-$datadir/locale}"
1259
1260case "$cpu" in
1261    ppc) CPU_CFLAGS="-m32" ;;
1262    ppc64) CPU_CFLAGS="-m64" ;;
1263    sparc) CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
1264    sparc64) CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
1265    s390) CPU_CFLAGS="-m31" ;;
1266    s390x) CPU_CFLAGS="-m64" ;;
1267    i386) CPU_CFLAGS="-m32" ;;
1268    x32) CPU_CFLAGS="-mx32" ;;
1269
1270    # ??? Only extremely old AMD cpus do not have cmpxchg16b.
1271    # If we truly care, we should simply detect this case at
1272    # runtime and generate the fallback to serial emulation.
1273    x86_64) CPU_CFLAGS="-m64 -mcx16" ;;
1274
1275    # No special flags required for other host CPUs
1276esac
1277
1278if eval test -z "\${cross_cc_$cpu}"; then
1279    eval "cross_cc_${cpu}=\$cc"
1280    cross_cc_vars="$cross_cc_vars cross_cc_${cpu}"
1281fi
1282
1283# For user-mode emulation the host arch has to be one we explicitly
1284# support, even if we're using TCI.
1285if [ "$ARCH" = "unknown" ]; then
1286  bsd_user="no"
1287  linux_user="no"
1288fi
1289
1290default_target_list=""
1291deprecated_targets_list=ppc64abi32-linux-user
1292deprecated_features=""
1293mak_wilds=""
1294
1295if [ "$softmmu" = "yes" ]; then
1296    mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
1297fi
1298if [ "$linux_user" = "yes" ]; then
1299    mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
1300fi
1301if [ "$bsd_user" = "yes" ]; then
1302    mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
1303fi
1304
1305# If the user doesn't explicitly specify a deprecated target we will
1306# skip it.
1307if test -z "$target_list"; then
1308    if test -z "$target_list_exclude"; then
1309        target_list_exclude="$deprecated_targets_list"
1310    else
1311        target_list_exclude="$target_list_exclude,$deprecated_targets_list"
1312    fi
1313fi
1314
1315for config in $mak_wilds; do
1316    target="$(basename "$config" .mak)"
1317    if echo "$target_list_exclude" | grep -vq "$target"; then
1318        default_target_list="${default_target_list} $target"
1319    fi
1320done
1321
1322if test x"$show_help" = x"yes" ; then
1323cat << EOF
1324
1325Usage: configure [options]
1326Options: [defaults in brackets after descriptions]
1327
1328Standard options:
1329  --help                   print this message
1330  --prefix=PREFIX          install in PREFIX [$prefix]
1331  --interp-prefix=PREFIX   where to find shared libraries, etc.
1332                           use %M for cpu name [$interp_prefix]
1333  --target-list=LIST       set target list (default: build all non-deprecated)
1334$(echo Available targets: $default_target_list | \
1335  fold -s -w 53 | sed -e 's/^/                           /')
1336$(echo Deprecated targets: $deprecated_targets_list | \
1337  fold -s -w 53 | sed -e 's/^/                           /')
1338  --target-list-exclude=LIST exclude a set of targets from the default target-list
1339
1340Advanced options (experts only):
1341  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
1342  --cc=CC                  use C compiler CC [$cc]
1343  --iasl=IASL              use ACPI compiler IASL [$iasl]
1344  --host-cc=CC             use C compiler CC [$host_cc] for code run at
1345                           build time
1346  --cxx=CXX                use C++ compiler CXX [$cxx]
1347  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
1348  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
1349  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
1350  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
1351  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
1352  --cross-cc-flags-ARCH=   use compiler flags when building ARCH guest tests
1353  --make=MAKE              use specified make [$make]
1354  --python=PYTHON          use specified python [$python]
1355  --sphinx-build=SPHINX    use specified sphinx-build [$sphinx_build]
1356  --meson=MESON            use specified meson [$meson]
1357  --ninja=NINJA            use specified ninja [$ninja]
1358  --smbd=SMBD              use specified smbd [$smbd]
1359  --with-git=GIT           use specified git [$git]
1360  --with-git-submodules=update   update git submodules (default if .git dir exists)
1361  --with-git-submodules=validate fail if git submodules are not up to date
1362  --with-git-submodules=ignore   do not update or check git submodules (default if no .git dir)
1363  --static                 enable static build [$static]
1364  --mandir=PATH            install man pages in PATH
1365  --datadir=PATH           install firmware in PATH/$qemu_suffix
1366  --localedir=PATH         install translation in PATH/$qemu_suffix
1367  --docdir=PATH            install documentation in PATH/$qemu_suffix
1368  --bindir=PATH            install binaries in PATH
1369  --libdir=PATH            install libraries in PATH
1370  --libexecdir=PATH        install helper binaries in PATH
1371  --sysconfdir=PATH        install config in PATH/$qemu_suffix
1372  --localstatedir=PATH     install local state in PATH (set at runtime on win32)
1373  --firmwarepath=PATH      search PATH for firmware files
1374  --efi-aarch64=PATH       PATH of efi file to use for aarch64 VMs.
1375  --with-suffix=SUFFIX     suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
1376  --with-pkgversion=VERS   use specified string as sub-version of the package
1377  --without-default-features default all --enable-* options to "disabled"
1378  --without-default-devices  do not include any device that is not needed to
1379                           start the emulator (only use if you are including
1380                           desired devices in configs/devices/)
1381  --with-devices-ARCH=NAME override default configs/devices
1382  --enable-debug           enable common debug build options
1383  --enable-sanitizers      enable default sanitizers
1384  --enable-tsan            enable thread sanitizer
1385  --disable-strip          disable stripping binaries
1386  --disable-werror         disable compilation abort on warning
1387  --disable-stack-protector disable compiler-provided stack protection
1388  --audio-drv-list=LIST    set audio drivers to try if -audiodev is not used
1389  --block-drv-whitelist=L  Same as --block-drv-rw-whitelist=L
1390  --block-drv-rw-whitelist=L
1391                           set block driver read-write whitelist
1392                           (by default affects only QEMU, not tools like qemu-img)
1393  --block-drv-ro-whitelist=L
1394                           set block driver read-only whitelist
1395                           (by default affects only QEMU, not tools like qemu-img)
1396  --enable-block-drv-whitelist-in-tools
1397                           use block whitelist also in tools instead of only QEMU
1398  --with-trace-file=NAME   Full PATH,NAME of file to store traces
1399                           Default:trace-<pid>
1400  --cpu=CPU                Build for host CPU [$cpu]
1401  --with-coroutine=BACKEND coroutine backend. Supported options:
1402                           ucontext, sigaltstack, windows
1403  --enable-gcov            enable test coverage analysis with gcov
1404  --with-vss-sdk=SDK-path  enable Windows VSS support in QEMU Guest Agent
1405  --with-win-sdk=SDK-path  path to Windows Platform SDK (to build VSS .tlb)
1406  --tls-priority           default TLS protocol/cipher priority string
1407  --enable-gprof           QEMU profiling with gprof
1408  --enable-profiler        profiler support
1409  --enable-debug-stack-usage
1410                           track the maximum stack usage of stacks created by qemu_alloc_stack
1411  --enable-plugins
1412                           enable plugins via shared library loading
1413  --disable-containers     don't use containers for cross-building
1414  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
1415EOF
1416  meson_options_help
1417cat << EOF
1418  system          all system emulation targets
1419  user            supported user emulation targets
1420  linux-user      all linux usermode emulation targets
1421  bsd-user        all BSD usermode emulation targets
1422  guest-agent     build the QEMU Guest Agent
1423  pie             Position Independent Executables
1424  modules         modules support (non-Windows)
1425  module-upgrades try to load modules from alternate paths for upgrades
1426  debug-tcg       TCG debugging (default is disabled)
1427  debug-info      debugging information
1428  lto             Enable Link-Time Optimization.
1429  safe-stack      SafeStack Stack Smash Protection. Depends on
1430                  clang/llvm >= 3.7 and requires coroutine backend ucontext.
1431  membarrier      membarrier system call (for Linux 4.14+ or Windows)
1432  rdma            Enable RDMA-based migration
1433  pvrdma          Enable PVRDMA support
1434  vhost-net       vhost-net kernel acceleration support
1435  vhost-vsock     virtio sockets device support
1436  vhost-scsi      vhost-scsi kernel target support
1437  vhost-crypto    vhost-user-crypto backend support
1438  vhost-kernel    vhost kernel backend support
1439  vhost-user      vhost-user backend support
1440  vhost-vdpa      vhost-vdpa kernel backend support
1441  live-block-migration   Block migration in the main migration stream
1442  coroutine-pool  coroutine freelist (better performance)
1443  tpm             TPM support
1444  numa            libnuma support
1445  avx2            AVX2 optimization support
1446  avx512f         AVX512F optimization support
1447  replication     replication support
1448  opengl          opengl support
1449  xfsctl          xfsctl support
1450  qom-cast-debug  cast debugging support
1451  tools           build qemu-io, qemu-nbd and qemu-img tools
1452  bochs           bochs image format support
1453  cloop           cloop image format support
1454  dmg             dmg image format support
1455  qcow1           qcow v1 image format support
1456  vdi             vdi image format support
1457  vvfat           vvfat image format support
1458  qed             qed image format support
1459  parallels       parallels image format support
1460  crypto-afalg    Linux AF_ALG crypto backend driver
1461  debug-mutex     mutex debugging support
1462  rng-none        dummy RNG, avoid using /dev/(u)random and getrandom()
1463  gio             libgio support
1464  slirp-smbd      use smbd (at path --smbd=*) in slirp networking
1465
1466NOTE: The object files are built at the place where configure is launched
1467EOF
1468exit 0
1469fi
1470
1471# Remove old dependency files to make sure that they get properly regenerated
1472rm -f */config-devices.mak.d
1473
1474if test -z "$python"
1475then
1476    error_exit "Python not found. Use --python=/path/to/python"
1477fi
1478if ! has "$make"
1479then
1480    error_exit "GNU make ($make) not found"
1481fi
1482
1483# Note that if the Python conditional here evaluates True we will exit
1484# with status 1 which is a shell 'false' value.
1485if ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then
1486  error_exit "Cannot use '$python', Python >= 3.6 is required." \
1487      "Use --python=/path/to/python to specify a supported Python."
1488fi
1489
1490# Preserve python version since some functionality is dependent on it
1491python_version=$($python -c 'import sys; print("%d.%d.%d" % (sys.version_info[0], sys.version_info[1], sys.version_info[2]))' 2>/dev/null)
1492
1493# Suppress writing compiled files
1494python="$python -B"
1495
1496if test -z "$meson"; then
1497    if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.59.3; then
1498        meson=meson
1499    elif test $git_submodules_action != 'ignore' ; then
1500        meson=git
1501    elif test -e "${source_path}/meson/meson.py" ; then
1502        meson=internal
1503    else
1504        if test "$explicit_python" = yes; then
1505            error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
1506        else
1507            error_exit "Meson not found.  Use --meson=/path/to/meson"
1508        fi
1509    fi
1510else
1511    # Meson uses its own Python interpreter to invoke other Python scripts,
1512    # but the user wants to use the one they specified with --python.
1513    #
1514    # We do not want to override the distro Python interpreter (and sometimes
1515    # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
1516    # just require --meson=git|internal together with --python.
1517    if test "$explicit_python" = yes; then
1518        case "$meson" in
1519            git | internal) ;;
1520            *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
1521        esac
1522    fi
1523fi
1524
1525if test "$meson" = git; then
1526    git_submodules="${git_submodules} meson"
1527fi
1528
1529case "$meson" in
1530    git | internal)
1531        meson="$python ${source_path}/meson/meson.py"
1532        ;;
1533    *) meson=$(command -v "$meson") ;;
1534esac
1535
1536# Probe for ninja
1537
1538if test -z "$ninja"; then
1539    for c in ninja ninja-build samu; do
1540        if has $c; then
1541            ninja=$(command -v "$c")
1542            break
1543        fi
1544    done
1545    if test -z "$ninja"; then
1546      error_exit "Cannot find Ninja"
1547    fi
1548fi
1549
1550# Check that the C compiler works. Doing this here before testing
1551# the host CPU ensures that we had a valid CC to autodetect the
1552# $cpu var (and we should bail right here if that's not the case).
1553# It also allows the help message to be printed without a CC.
1554write_c_skeleton;
1555if compile_object ; then
1556  : C compiler works ok
1557else
1558    error_exit "\"$cc\" either does not exist or does not work"
1559fi
1560if ! compile_prog ; then
1561    error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
1562fi
1563
1564# Consult white-list to determine whether to enable werror
1565# by default.  Only enable by default for git builds
1566if test -z "$werror" ; then
1567    if test "$git_submodules_action" != "ignore" && \
1568        { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
1569        werror="yes"
1570    else
1571        werror="no"
1572    fi
1573fi
1574
1575if test "$targetos" = "bogus"; then
1576    # Now that we know that we're not printing the help and that
1577    # the compiler works (so the results of the check_defines we used
1578    # to identify the OS are reliable), if we didn't recognize the
1579    # host OS we should stop now.
1580    error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1581fi
1582
1583# Check whether the compiler matches our minimum requirements:
1584cat > $TMPC << EOF
1585#if defined(__clang_major__) && defined(__clang_minor__)
1586# ifdef __apple_build_version__
1587#  if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
1588#   error You need at least XCode Clang v10.0 to compile QEMU
1589#  endif
1590# else
1591#  if __clang_major__ < 6 || (__clang_major__ == 6 && __clang_minor__ < 0)
1592#   error You need at least Clang v6.0 to compile QEMU
1593#  endif
1594# endif
1595#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
1596# if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
1597#  error You need at least GCC v7.4.0 to compile QEMU
1598# endif
1599#else
1600# error You either need GCC or Clang to compiler QEMU
1601#endif
1602int main (void) { return 0; }
1603EOF
1604if ! compile_prog "" "" ; then
1605    error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
1606fi
1607
1608# Accumulate -Wfoo and -Wno-bar separately.
1609# We will list all of the enable flags first, and the disable flags second.
1610# Note that we do not add -Werror, because that would enable it for all
1611# configure tests. If a configure test failed due to -Werror this would
1612# just silently disable some features, so it's too error prone.
1613
1614warn_flags=
1615add_to warn_flags -Wold-style-declaration
1616add_to warn_flags -Wold-style-definition
1617add_to warn_flags -Wtype-limits
1618add_to warn_flags -Wformat-security
1619add_to warn_flags -Wformat-y2k
1620add_to warn_flags -Winit-self
1621add_to warn_flags -Wignored-qualifiers
1622add_to warn_flags -Wempty-body
1623add_to warn_flags -Wnested-externs
1624add_to warn_flags -Wendif-labels
1625add_to warn_flags -Wexpansion-to-defined
1626add_to warn_flags -Wimplicit-fallthrough=2
1627
1628nowarn_flags=
1629add_to nowarn_flags -Wno-initializer-overrides
1630add_to nowarn_flags -Wno-missing-include-dirs
1631add_to nowarn_flags -Wno-shift-negative-value
1632add_to nowarn_flags -Wno-string-plus-int
1633add_to nowarn_flags -Wno-typedef-redefinition
1634add_to nowarn_flags -Wno-tautological-type-limit-compare
1635add_to nowarn_flags -Wno-psabi
1636
1637gcc_flags="$warn_flags $nowarn_flags"
1638
1639cc_has_warning_flag() {
1640    write_c_skeleton;
1641
1642    # Use the positive sense of the flag when testing for -Wno-wombat
1643    # support (gcc will happily accept the -Wno- form of unknown
1644    # warning options).
1645    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
1646    compile_prog "-Werror $optflag" ""
1647}
1648
1649for flag in $gcc_flags; do
1650    if cc_has_warning_flag $flag ; then
1651        QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1652    fi
1653done
1654
1655if test "$stack_protector" != "no"; then
1656  cat > $TMPC << EOF
1657int main(int argc, char *argv[])
1658{
1659    char arr[64], *p = arr, *c = argv[0];
1660    while (*c) {
1661        *p++ = *c++;
1662    }
1663    return 0;
1664}
1665EOF
1666  gcc_flags="-fstack-protector-strong -fstack-protector-all"
1667  sp_on=0
1668  for flag in $gcc_flags; do
1669    # We need to check both a compile and a link, since some compiler
1670    # setups fail only on a .c->.o compile and some only at link time
1671    if compile_object "-Werror $flag" &&
1672       compile_prog "-Werror $flag" ""; then
1673      QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1674      QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
1675      sp_on=1
1676      break
1677    fi
1678  done
1679  if test "$stack_protector" = yes; then
1680    if test $sp_on = 0; then
1681      error_exit "Stack protector not supported"
1682    fi
1683  fi
1684fi
1685
1686# Disable -Wmissing-braces on older compilers that warn even for
1687# the "universal" C zero initializer {0}.
1688cat > $TMPC << EOF
1689struct {
1690  int a[2];
1691} x = {0};
1692EOF
1693if compile_object "-Werror" "" ; then
1694  :
1695else
1696  QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
1697fi
1698
1699# Our module code doesn't support Windows
1700if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
1701  error_exit "Modules are not available for Windows"
1702fi
1703
1704# module_upgrades is only reasonable if modules are enabled
1705if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
1706  error_exit "Can't enable module-upgrades as Modules are not enabled"
1707fi
1708
1709# Static linking is not possible with plugins, modules or PIE
1710if test "$static" = "yes" ; then
1711  if test "$modules" = "yes" ; then
1712    error_exit "static and modules are mutually incompatible"
1713  fi
1714  if test "$plugins" = "yes"; then
1715    error_exit "static and plugins are mutually incompatible"
1716  else
1717    plugins="no"
1718  fi
1719fi
1720
1721cat > $TMPC << EOF
1722
1723#ifdef __linux__
1724#  define THREAD __thread
1725#else
1726#  define THREAD
1727#endif
1728static THREAD int tls_var;
1729int main(void) { return tls_var; }
1730EOF
1731
1732# Check we support -fno-pie and -no-pie first; we will need the former for
1733# building ROMs, and both for everything if --disable-pie is passed.
1734if compile_prog "-Werror -fno-pie" "-no-pie"; then
1735  CFLAGS_NOPIE="-fno-pie"
1736  LDFLAGS_NOPIE="-no-pie"
1737fi
1738
1739if test "$static" = "yes"; then
1740  if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
1741    CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
1742    QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
1743    pie="yes"
1744  elif test "$pie" = "yes"; then
1745    error_exit "-static-pie not available due to missing toolchain support"
1746  else
1747    QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
1748    pie="no"
1749  fi
1750elif test "$pie" = "no"; then
1751  CONFIGURE_CFLAGS="$CFLAGS_NOPIE $CONFIGURE_CFLAGS"
1752  CONFIGURE_LDFLAGS="$LDFLAGS_NOPIE $CONFIGURE_LDFLAGS"
1753elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
1754  CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
1755  CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
1756  pie="yes"
1757elif test "$pie" = "yes"; then
1758  error_exit "PIE not available due to missing toolchain support"
1759else
1760  echo "Disabling PIE due to missing toolchain support"
1761  pie="no"
1762fi
1763
1764# Detect support for PT_GNU_RELRO + DT_BIND_NOW.
1765# The combination is known as "full relro", because .got.plt is read-only too.
1766if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1767  QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
1768fi
1769
1770##########################################
1771# __sync_fetch_and_and requires at least -march=i486. Many toolchains
1772# use i686 as default anyway, but for those that don't, an explicit
1773# specification is necessary
1774
1775if test "$cpu" = "i386"; then
1776  cat > $TMPC << EOF
1777static int sfaa(int *ptr)
1778{
1779  return __sync_fetch_and_and(ptr, 0);
1780}
1781
1782int main(void)
1783{
1784  int val = 42;
1785  val = __sync_val_compare_and_swap(&val, 0, 1);
1786  sfaa(&val);
1787  return val;
1788}
1789EOF
1790  if ! compile_prog "" "" ; then
1791    QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
1792  fi
1793fi
1794
1795if test "$tcg" = "enabled"; then
1796    git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
1797    git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
1798fi
1799
1800if test -z "${target_list+xxx}" ; then
1801    default_targets=yes
1802    for target in $default_target_list; do
1803        target_list="$target_list $target"
1804    done
1805    target_list="${target_list# }"
1806else
1807    default_targets=no
1808    target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1809    for target in $target_list; do
1810        # Check that we recognised the target name; this allows a more
1811        # friendly error message than if we let it fall through.
1812        case " $default_target_list " in
1813            *" $target "*)
1814                ;;
1815            *)
1816                error_exit "Unknown target name '$target'"
1817                ;;
1818        esac
1819    done
1820fi
1821
1822for target in $target_list; do
1823    # if a deprecated target is enabled we note it here
1824    if echo "$deprecated_targets_list" | grep -q "$target"; then
1825        add_to deprecated_features $target
1826    fi
1827done
1828
1829# see if system emulation was really requested
1830case " $target_list " in
1831  *"-softmmu "*) softmmu=yes
1832  ;;
1833  *) softmmu=no
1834  ;;
1835esac
1836
1837feature_not_found() {
1838  feature=$1
1839  remedy=$2
1840
1841  error_exit "User requested feature $feature" \
1842      "configure was not able to find it." \
1843      "$remedy"
1844}
1845
1846# ---
1847# big/little endian test
1848cat > $TMPC << EOF
1849#include <stdio.h>
1850short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
1851short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
1852int main(int argc, char *argv[])
1853{
1854    return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
1855}
1856EOF
1857
1858if compile_prog ; then
1859    if strings -a $TMPE | grep -q BiGeNdIaN ; then
1860        bigendian="yes"
1861    elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
1862        bigendian="no"
1863    else
1864        echo big/little test failed
1865        exit 1
1866    fi
1867else
1868    echo big/little test failed
1869    exit 1
1870fi
1871
1872##########################################
1873# system tools
1874if test -z "$want_tools"; then
1875    if test "$softmmu" = "no"; then
1876        want_tools=no
1877    else
1878        want_tools=yes
1879    fi
1880fi
1881
1882#########################################
1883# vhost interdependencies and host support
1884
1885# vhost backends
1886if test "$vhost_user" = "yes" && test "$linux" != "yes"; then
1887  error_exit "vhost-user is only available on Linux"
1888fi
1889test "$vhost_vdpa" = "" && vhost_vdpa=$linux
1890if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
1891  error_exit "vhost-vdpa is only available on Linux"
1892fi
1893test "$vhost_kernel" = "" && vhost_kernel=$linux
1894if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
1895  error_exit "vhost-kernel is only available on Linux"
1896fi
1897
1898# vhost-kernel devices
1899test "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
1900if test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
1901  error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
1902fi
1903test "$vhost_vsock" = "" && vhost_vsock=$vhost_kernel
1904if test "$vhost_vsock" = "yes" && test "$vhost_kernel" != "yes"; then
1905  error_exit "--enable-vhost-vsock requires --enable-vhost-kernel"
1906fi
1907
1908# vhost-user backends
1909test "$vhost_net_user" = "" && vhost_net_user=$vhost_user
1910if test "$vhost_net_user" = "yes" && test "$vhost_user" = "no"; then
1911  error_exit "--enable-vhost-net-user requires --enable-vhost-user"
1912fi
1913test "$vhost_crypto" = "" && vhost_crypto=$vhost_user
1914if test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
1915  error_exit "--enable-vhost-crypto requires --enable-vhost-user"
1916fi
1917test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
1918if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
1919  error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
1920fi
1921#vhost-vdpa backends
1922test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa
1923if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then
1924  error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa"
1925fi
1926
1927# OR the vhost-kernel, vhost-vdpa and vhost-user values for simplicity
1928if test "$vhost_net" = ""; then
1929  test "$vhost_net_user" = "yes" && vhost_net=yes
1930  test "$vhost_net_vdpa" = "yes" && vhost_net=yes
1931  test "$vhost_kernel" = "yes" && vhost_net=yes
1932fi
1933
1934##########################################
1935# pkg-config probe
1936
1937if ! has "$pkg_config_exe"; then
1938  error_exit "pkg-config binary '$pkg_config_exe' not found"
1939fi
1940
1941##########################################
1942# xen probe
1943
1944if test "$xen" != "disabled" ; then
1945  # Check whether Xen library path is specified via --extra-ldflags to avoid
1946  # overriding this setting with pkg-config output. If not, try pkg-config
1947  # to obtain all needed flags.
1948
1949  if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \
1950     $pkg_config --exists xencontrol ; then
1951    xen_ctrl_version="$(printf '%d%02d%02d' \
1952      $($pkg_config --modversion xencontrol | sed 's/\./ /g') )"
1953    xen=enabled
1954    xen_pc="xencontrol xenstore xenforeignmemory xengnttab"
1955    xen_pc="$xen_pc xenevtchn xendevicemodel"
1956    if $pkg_config --exists xentoolcore; then
1957      xen_pc="$xen_pc xentoolcore"
1958    fi
1959    xen_cflags="$($pkg_config --cflags $xen_pc)"
1960    xen_libs="$($pkg_config --libs $xen_pc)"
1961  else
1962
1963    xen_libs="-lxenstore -lxenctrl"
1964    xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
1965
1966    # First we test whether Xen headers and libraries are available.
1967    # If no, we are done and there is no Xen support.
1968    # If yes, more tests are run to detect the Xen version.
1969
1970    # Xen (any)
1971    cat > $TMPC <<EOF
1972#include <xenctrl.h>
1973int main(void) {
1974  return 0;
1975}
1976EOF
1977    if ! compile_prog "" "$xen_libs" ; then
1978      # Xen not found
1979      if test "$xen" = "enabled" ; then
1980        feature_not_found "xen" "Install xen devel"
1981      fi
1982      xen=disabled
1983
1984    # Xen unstable
1985    elif
1986        cat > $TMPC <<EOF &&
1987#undef XC_WANT_COMPAT_DEVICEMODEL_API
1988#define __XEN_TOOLS__
1989#include <xendevicemodel.h>
1990#include <xenforeignmemory.h>
1991int main(void) {
1992  xendevicemodel_handle *xd;
1993  xenforeignmemory_handle *xfmem;
1994
1995  xd = xendevicemodel_open(0, 0);
1996  xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);
1997
1998  xfmem = xenforeignmemory_open(0, 0);
1999  xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);
2000
2001  return 0;
2002}
2003EOF
2004        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
2005      then
2006      xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
2007      xen_ctrl_version=41100
2008      xen=enabled
2009    elif
2010        cat > $TMPC <<EOF &&
2011#undef XC_WANT_COMPAT_MAP_FOREIGN_API
2012#include <xenforeignmemory.h>
2013#include <xentoolcore.h>
2014int main(void) {
2015  xenforeignmemory_handle *xfmem;
2016
2017  xfmem = xenforeignmemory_open(0, 0);
2018  xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
2019  xentoolcore_restrict_all(0);
2020
2021  return 0;
2022}
2023EOF
2024        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
2025      then
2026      xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
2027      xen_ctrl_version=41000
2028      xen=enabled
2029    elif
2030        cat > $TMPC <<EOF &&
2031#undef XC_WANT_COMPAT_DEVICEMODEL_API
2032#define __XEN_TOOLS__
2033#include <xendevicemodel.h>
2034int main(void) {
2035  xendevicemodel_handle *xd;
2036
2037  xd = xendevicemodel_open(0, 0);
2038  xendevicemodel_close(xd);
2039
2040  return 0;
2041}
2042EOF
2043        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs"
2044      then
2045      xen_stable_libs="-lxendevicemodel $xen_stable_libs"
2046      xen_ctrl_version=40900
2047      xen=enabled
2048    elif
2049        cat > $TMPC <<EOF &&
2050/*
2051 * If we have stable libs the we don't want the libxc compat
2052 * layers, regardless of what CFLAGS we may have been given.
2053 *
2054 * Also, check if xengnttab_grant_copy_segment_t is defined and
2055 * grant copy operation is implemented.
2056 */
2057#undef XC_WANT_COMPAT_EVTCHN_API
2058#undef XC_WANT_COMPAT_GNTTAB_API
2059#undef XC_WANT_COMPAT_MAP_FOREIGN_API
2060#include <xenctrl.h>
2061#include <xenstore.h>
2062#include <xenevtchn.h>
2063#include <xengnttab.h>
2064#include <xenforeignmemory.h>
2065#include <stdint.h>
2066#include <xen/hvm/hvm_info_table.h>
2067#if !defined(HVM_MAX_VCPUS)
2068# error HVM_MAX_VCPUS not defined
2069#endif
2070int main(void) {
2071  xc_interface *xc = NULL;
2072  xenforeignmemory_handle *xfmem;
2073  xenevtchn_handle *xe;
2074  xengnttab_handle *xg;
2075  xengnttab_grant_copy_segment_t* seg = NULL;
2076
2077  xs_daemon_open();
2078
2079  xc = xc_interface_open(0, 0, 0);
2080  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2081  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2082  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2083  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2084
2085  xfmem = xenforeignmemory_open(0, 0);
2086  xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2087
2088  xe = xenevtchn_open(0, 0);
2089  xenevtchn_fd(xe);
2090
2091  xg = xengnttab_open(0, 0);
2092  xengnttab_grant_copy(xg, 0, seg);
2093
2094  return 0;
2095}
2096EOF
2097        compile_prog "" "$xen_libs $xen_stable_libs"
2098      then
2099      xen_ctrl_version=40800
2100      xen=enabled
2101    elif
2102        cat > $TMPC <<EOF &&
2103/*
2104 * If we have stable libs the we don't want the libxc compat
2105 * layers, regardless of what CFLAGS we may have been given.
2106 */
2107#undef XC_WANT_COMPAT_EVTCHN_API
2108#undef XC_WANT_COMPAT_GNTTAB_API
2109#undef XC_WANT_COMPAT_MAP_FOREIGN_API
2110#include <xenctrl.h>
2111#include <xenstore.h>
2112#include <xenevtchn.h>
2113#include <xengnttab.h>
2114#include <xenforeignmemory.h>
2115#include <stdint.h>
2116#include <xen/hvm/hvm_info_table.h>
2117#if !defined(HVM_MAX_VCPUS)
2118# error HVM_MAX_VCPUS not defined
2119#endif
2120int main(void) {
2121  xc_interface *xc = NULL;
2122  xenforeignmemory_handle *xfmem;
2123  xenevtchn_handle *xe;
2124  xengnttab_handle *xg;
2125
2126  xs_daemon_open();
2127
2128  xc = xc_interface_open(0, 0, 0);
2129  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2130  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2131  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2132  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2133
2134  xfmem = xenforeignmemory_open(0, 0);
2135  xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2136
2137  xe = xenevtchn_open(0, 0);
2138  xenevtchn_fd(xe);
2139
2140  xg = xengnttab_open(0, 0);
2141  xengnttab_map_grant_ref(xg, 0, 0, 0);
2142
2143  return 0;
2144}
2145EOF
2146        compile_prog "" "$xen_libs $xen_stable_libs"
2147      then
2148      xen_ctrl_version=40701
2149      xen=enabled
2150
2151    # Xen 4.6
2152    elif
2153        cat > $TMPC <<EOF &&
2154#include <xenctrl.h>
2155#include <xenstore.h>
2156#include <stdint.h>
2157#include <xen/hvm/hvm_info_table.h>
2158#if !defined(HVM_MAX_VCPUS)
2159# error HVM_MAX_VCPUS not defined
2160#endif
2161int main(void) {
2162  xc_interface *xc;
2163  xs_daemon_open();
2164  xc = xc_interface_open(0, 0, 0);
2165  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2166  xc_gnttab_open(NULL, 0);
2167  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2168  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2169  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2170  xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
2171  return 0;
2172}
2173EOF
2174        compile_prog "" "$xen_libs"
2175      then
2176      xen_ctrl_version=40600
2177      xen=enabled
2178
2179    # Xen 4.5
2180    elif
2181        cat > $TMPC <<EOF &&
2182#include <xenctrl.h>
2183#include <xenstore.h>
2184#include <stdint.h>
2185#include <xen/hvm/hvm_info_table.h>
2186#if !defined(HVM_MAX_VCPUS)
2187# error HVM_MAX_VCPUS not defined
2188#endif
2189int main(void) {
2190  xc_interface *xc;
2191  xs_daemon_open();
2192  xc = xc_interface_open(0, 0, 0);
2193  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2194  xc_gnttab_open(NULL, 0);
2195  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2196  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2197  xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
2198  return 0;
2199}
2200EOF
2201        compile_prog "" "$xen_libs"
2202      then
2203      xen_ctrl_version=40500
2204      xen=enabled
2205
2206    elif
2207        cat > $TMPC <<EOF &&
2208#include <xenctrl.h>
2209#include <xenstore.h>
2210#include <stdint.h>
2211#include <xen/hvm/hvm_info_table.h>
2212#if !defined(HVM_MAX_VCPUS)
2213# error HVM_MAX_VCPUS not defined
2214#endif
2215int main(void) {
2216  xc_interface *xc;
2217  xs_daemon_open();
2218  xc = xc_interface_open(0, 0, 0);
2219  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2220  xc_gnttab_open(NULL, 0);
2221  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2222  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2223  return 0;
2224}
2225EOF
2226        compile_prog "" "$xen_libs"
2227      then
2228      xen_ctrl_version=40200
2229      xen=enabled
2230
2231    else
2232      if test "$xen" = "enabled" ; then
2233        feature_not_found "xen (unsupported version)" \
2234                          "Install a supported xen (xen 4.2 or newer)"
2235      fi
2236      xen=disabled
2237    fi
2238
2239    if test "$xen" = enabled; then
2240      if test $xen_ctrl_version -ge 40701  ; then
2241        xen_libs="$xen_libs $xen_stable_libs "
2242      fi
2243    fi
2244  fi
2245fi
2246
2247##########################################
2248# RDMA needs OpenFabrics libraries
2249if test "$rdma" != "no" ; then
2250  cat > $TMPC <<EOF
2251#include <rdma/rdma_cma.h>
2252int main(void) { return 0; }
2253EOF
2254  rdma_libs="-lrdmacm -libverbs -libumad"
2255  if compile_prog "" "$rdma_libs" ; then
2256    rdma="yes"
2257  else
2258    if test "$rdma" = "yes" ; then
2259        error_exit \
2260            " OpenFabrics librdmacm/libibverbs/libibumad not present." \
2261            " Your options:" \
2262            "  (1) Fast: Install infiniband packages (devel) from your distro." \
2263            "  (2) Cleanest: Install libraries from www.openfabrics.org" \
2264            "  (3) Also: Install softiwarp if you don't have RDMA hardware"
2265    fi
2266    rdma="no"
2267  fi
2268fi
2269
2270##########################################
2271# PVRDMA detection
2272
2273cat > $TMPC <<EOF &&
2274#include <sys/mman.h>
2275
2276int
2277main(void)
2278{
2279    char buf = 0;
2280    void *addr = &buf;
2281    addr = mremap(addr, 0, 1, MREMAP_MAYMOVE | MREMAP_FIXED);
2282
2283    return 0;
2284}
2285EOF
2286
2287if test "$rdma" = "yes" ; then
2288    case "$pvrdma" in
2289    "")
2290        if compile_prog "" ""; then
2291            pvrdma="yes"
2292        else
2293            pvrdma="no"
2294        fi
2295        ;;
2296    "yes")
2297        if ! compile_prog "" ""; then
2298            error_exit "PVRDMA is not supported since mremap is not implemented"
2299        fi
2300        pvrdma="yes"
2301        ;;
2302    "no")
2303        pvrdma="no"
2304        ;;
2305    esac
2306else
2307    if test "$pvrdma" = "yes" ; then
2308        error_exit "PVRDMA requires rdma suppport"
2309    fi
2310    pvrdma="no"
2311fi
2312
2313# Let's see if enhanced reg_mr is supported
2314if test "$pvrdma" = "yes" ; then
2315
2316cat > $TMPC <<EOF &&
2317#include <infiniband/verbs.h>
2318
2319int
2320main(void)
2321{
2322    struct ibv_mr *mr;
2323    struct ibv_pd *pd = NULL;
2324    size_t length = 10;
2325    uint64_t iova = 0;
2326    int access = 0;
2327    void *addr = NULL;
2328
2329    mr = ibv_reg_mr_iova(pd, addr, length, iova, access);
2330
2331    ibv_dereg_mr(mr);
2332
2333    return 0;
2334}
2335EOF
2336    if ! compile_prog "" "-libverbs"; then
2337        QEMU_CFLAGS="$QEMU_CFLAGS -DLEGACY_RDMA_REG_MR"
2338    fi
2339fi
2340
2341##########################################
2342# xfsctl() probe, used for file-posix.c
2343if test "$xfs" != "no" ; then
2344  cat > $TMPC << EOF
2345#include <stddef.h>  /* NULL */
2346#include <xfs/xfs.h>
2347int main(void)
2348{
2349    xfsctl(NULL, 0, 0, NULL);
2350    return 0;
2351}
2352EOF
2353  if compile_prog "" "" ; then
2354    xfs="yes"
2355  else
2356    if test "$xfs" = "yes" ; then
2357      feature_not_found "xfs" "Install xfsprogs/xfslibs devel"
2358    fi
2359    xfs=no
2360  fi
2361fi
2362
2363##########################################
2364# plugin linker support probe
2365
2366if test "$plugins" != "no"; then
2367
2368    #########################################
2369    # See if --dynamic-list is supported by the linker
2370
2371    ld_dynamic_list="no"
2372    cat > $TMPTXT <<EOF
2373{
2374  foo;
2375};
2376EOF
2377
2378        cat > $TMPC <<EOF
2379#include <stdio.h>
2380void foo(void);
2381
2382void foo(void)
2383{
2384  printf("foo\n");
2385}
2386
2387int main(void)
2388{
2389  foo();
2390  return 0;
2391}
2392EOF
2393
2394    if compile_prog "" "-Wl,--dynamic-list=$TMPTXT" ; then
2395        ld_dynamic_list="yes"
2396    fi
2397
2398    #########################################
2399    # See if -exported_symbols_list is supported by the linker
2400
2401    ld_exported_symbols_list="no"
2402    cat > $TMPTXT <<EOF
2403  _foo
2404EOF
2405
2406    if compile_prog "" "-Wl,-exported_symbols_list,$TMPTXT" ; then
2407        ld_exported_symbols_list="yes"
2408    fi
2409
2410    if test "$ld_dynamic_list" = "no" &&
2411       test "$ld_exported_symbols_list" = "no" ; then
2412        if test "$plugins" = "yes"; then
2413            error_exit \
2414                "Plugin support requires dynamic linking and specifying a set of symbols " \
2415                "that are exported to plugins. Unfortunately your linker doesn't " \
2416                "support the flag (--dynamic-list or -exported_symbols_list) used " \
2417                "for this purpose."
2418        else
2419            plugins="no"
2420        fi
2421    else
2422        plugins="yes"
2423    fi
2424fi
2425
2426##########################################
2427# glib support probe
2428
2429glib_req_ver=2.56
2430glib_modules=gthread-2.0
2431if test "$modules" = yes; then
2432    glib_modules="$glib_modules gmodule-export-2.0"
2433elif test "$plugins" = "yes"; then
2434    glib_modules="$glib_modules gmodule-no-export-2.0"
2435fi
2436
2437for i in $glib_modules; do
2438    if $pkg_config --atleast-version=$glib_req_ver $i; then
2439        glib_cflags=$($pkg_config --cflags $i)
2440        glib_libs=$($pkg_config --libs $i)
2441    else
2442        error_exit "glib-$glib_req_ver $i is required to compile QEMU"
2443    fi
2444done
2445
2446# This workaround is required due to a bug in pkg-config file for glib as it
2447# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
2448
2449if test "$static" = yes && test "$mingw32" = yes; then
2450    glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
2451fi
2452
2453if ! test "$gio" = "no"; then
2454    pass=no
2455    if $pkg_config --atleast-version=$glib_req_ver gio-2.0; then
2456        gio_cflags=$($pkg_config --cflags gio-2.0)
2457        gio_libs=$($pkg_config --libs gio-2.0)
2458        gdbus_codegen=$($pkg_config --variable=gdbus_codegen gio-2.0)
2459        if ! has "$gdbus_codegen"; then
2460            gdbus_codegen=
2461        fi
2462        # Check that the libraries actually work -- Ubuntu 18.04 ships
2463        # with pkg-config --static --libs data for gio-2.0 that is missing
2464        # -lblkid and will give a link error.
2465        cat > $TMPC <<EOF
2466#include <gio/gio.h>
2467int main(void)
2468{
2469    g_dbus_proxy_new_sync(0, 0, 0, 0, 0, 0, 0, 0);
2470    return 0;
2471}
2472EOF
2473        if compile_prog "$gio_cflags" "$gio_libs" ; then
2474            pass=yes
2475        else
2476            pass=no
2477        fi
2478
2479        if test "$pass" = "yes" &&
2480            $pkg_config --atleast-version=$glib_req_ver gio-unix-2.0; then
2481            gio_cflags="$gio_cflags $($pkg_config --cflags gio-unix-2.0)"
2482            gio_libs="$gio_libs $($pkg_config --libs gio-unix-2.0)"
2483        fi
2484    fi
2485
2486    if test "$pass" = "no"; then
2487        if test "$gio" = "yes"; then
2488            feature_not_found "gio" "Install libgio >= 2.0"
2489        else
2490            gio=no
2491        fi
2492    else
2493        gio=yes
2494    fi
2495fi
2496
2497# Sanity check that the current size_t matches the
2498# size that glib thinks it should be. This catches
2499# problems on multi-arch where people try to build
2500# 32-bit QEMU while pointing at 64-bit glib headers
2501cat > $TMPC <<EOF
2502#include <glib.h>
2503#include <unistd.h>
2504
2505#define QEMU_BUILD_BUG_ON(x) \
2506  typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
2507
2508int main(void) {
2509   QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
2510   return 0;
2511}
2512EOF
2513
2514if ! compile_prog "$glib_cflags" "$glib_libs" ; then
2515    error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
2516               "You probably need to set PKG_CONFIG_LIBDIR"\
2517	       "to point to the right pkg-config files for your"\
2518	       "build target"
2519fi
2520
2521# Silence clang warnings triggered by glib < 2.57.2
2522cat > $TMPC << EOF
2523#include <glib.h>
2524typedef struct Foo {
2525    int i;
2526} Foo;
2527static void foo_free(Foo *f)
2528{
2529    g_free(f);
2530}
2531G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free);
2532int main(void) { return 0; }
2533EOF
2534if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
2535    if cc_has_warning_flag "-Wno-unused-function"; then
2536        glib_cflags="$glib_cflags -Wno-unused-function"
2537        CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
2538    fi
2539fi
2540
2541##########################################
2542# SHA command probe for modules
2543if test "$modules" = yes; then
2544    shacmd_probe="sha1sum sha1 shasum"
2545    for c in $shacmd_probe; do
2546        if has $c; then
2547            shacmd="$c"
2548            break
2549        fi
2550    done
2551    if test "$shacmd" = ""; then
2552        error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
2553    fi
2554fi
2555
2556##########################################
2557# TPM emulation is only on POSIX
2558
2559if test "$tpm" = ""; then
2560  if test "$mingw32" = "yes"; then
2561    tpm=no
2562  else
2563    tpm=yes
2564  fi
2565elif test "$tpm" = "yes"; then
2566  if test "$mingw32" = "yes" ; then
2567    error_exit "TPM emulation only available on POSIX systems"
2568  fi
2569fi
2570
2571##########################################
2572# fdt probe
2573
2574case "$fdt" in
2575  auto | enabled | internal)
2576    # Simpler to always update submodule, even if not needed.
2577    git_submodules="${git_submodules} dtc"
2578    ;;
2579esac
2580
2581##########################################
2582# opengl probe (for sdl2, gtk)
2583
2584if test "$opengl" != "no" ; then
2585  epoxy=no
2586  if $pkg_config epoxy; then
2587    cat > $TMPC << EOF
2588#include <epoxy/egl.h>
2589int main(void) { return 0; }
2590EOF
2591    if compile_prog "" "" ; then
2592      epoxy=yes
2593    fi
2594  fi
2595
2596  if test "$epoxy" = "yes" ; then
2597    opengl_cflags="$($pkg_config --cflags epoxy)"
2598    opengl_libs="$($pkg_config --libs epoxy)"
2599    opengl=yes
2600  else
2601    if test "$opengl" = "yes" ; then
2602      feature_not_found "opengl" "Please install epoxy with EGL"
2603    fi
2604    opengl_cflags=""
2605    opengl_libs=""
2606    opengl=no
2607  fi
2608fi
2609
2610##########################################
2611# libnuma probe
2612
2613if test "$numa" != "no" ; then
2614  cat > $TMPC << EOF
2615#include <numa.h>
2616int main(void) { return numa_available(); }
2617EOF
2618
2619  if compile_prog "" "-lnuma" ; then
2620    numa=yes
2621    numa_libs="-lnuma"
2622  else
2623    if test "$numa" = "yes" ; then
2624      feature_not_found "numa" "install numactl devel"
2625    fi
2626    numa=no
2627  fi
2628fi
2629
2630# check for usbfs
2631have_usbfs=no
2632if test "$linux_user" = "yes"; then
2633  cat > $TMPC << EOF
2634#include <linux/usbdevice_fs.h>
2635
2636#ifndef USBDEVFS_GET_CAPABILITIES
2637#error "USBDEVFS_GET_CAPABILITIES undefined"
2638#endif
2639
2640#ifndef USBDEVFS_DISCONNECT_CLAIM
2641#error "USBDEVFS_DISCONNECT_CLAIM undefined"
2642#endif
2643
2644int main(void)
2645{
2646    return 0;
2647}
2648EOF
2649  if compile_prog "" ""; then
2650    have_usbfs=yes
2651  fi
2652fi
2653
2654##########################################
2655# check if we have VSS SDK headers for win
2656
2657if test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
2658        test "$vss_win32_sdk" != "no" ; then
2659  case "$vss_win32_sdk" in
2660    "")   vss_win32_include="-isystem $source_path" ;;
2661    *\ *) # The SDK is installed in "Program Files" by default, but we cannot
2662          # handle path with spaces. So we symlink the headers into ".sdk/vss".
2663          vss_win32_include="-isystem $source_path/.sdk/vss"
2664	  symlink "$vss_win32_sdk/inc" "$source_path/.sdk/vss/inc"
2665	  ;;
2666    *)    vss_win32_include="-isystem $vss_win32_sdk"
2667  esac
2668  cat > $TMPC << EOF
2669#define __MIDL_user_allocate_free_DEFINED__
2670#include <inc/win2003/vss.h>
2671int main(void) { return VSS_CTX_BACKUP; }
2672EOF
2673  if compile_prog "$vss_win32_include" "" ; then
2674    guest_agent_with_vss="yes"
2675    QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
2676    libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++ -Wl,--enable-stdcall-fixup $libs_qga"
2677    qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb"
2678  else
2679    if test "$vss_win32_sdk" != "" ; then
2680      echo "ERROR: Please download and install Microsoft VSS SDK:"
2681      echo "ERROR:   http://www.microsoft.com/en-us/download/details.aspx?id=23490"
2682      echo "ERROR: On POSIX-systems, you can extract the SDK headers by:"
2683      echo "ERROR:   scripts/extract-vsssdk-headers setup.exe"
2684      echo "ERROR: The headers are extracted in the directory \`inc'."
2685      feature_not_found "VSS support"
2686    fi
2687    guest_agent_with_vss="no"
2688  fi
2689fi
2690
2691##########################################
2692# lookup Windows platform SDK (if not specified)
2693# The SDK is needed only to build .tlb (type library) file of guest agent
2694# VSS provider from the source. It is usually unnecessary because the
2695# pre-compiled .tlb file is included.
2696
2697if test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
2698        test "$guest_agent_with_vss" = "yes" ; then
2699  if test -z "$win_sdk"; then
2700    programfiles="$PROGRAMFILES"
2701    test -n "$PROGRAMW6432" && programfiles="$PROGRAMW6432"
2702    if test -n "$programfiles"; then
2703      win_sdk=$(ls -d "$programfiles/Microsoft SDKs/Windows/v"* | tail -1) 2>/dev/null
2704    else
2705      feature_not_found "Windows SDK"
2706    fi
2707  elif test "$win_sdk" = "no"; then
2708    win_sdk=""
2709  fi
2710fi
2711
2712##########################################
2713# check if mingw environment provides a recent ntddscsi.h
2714if test "$mingw32" = "yes" && test "$guest_agent" != "no"; then
2715  cat > $TMPC << EOF
2716#include <windows.h>
2717#include <ntddscsi.h>
2718int main(void) {
2719#if !defined(IOCTL_SCSI_GET_ADDRESS)
2720#error Missing required ioctl definitions
2721#endif
2722  SCSI_ADDRESS addr = { .Lun = 0, .TargetId = 0, .PathId = 0 };
2723  return addr.Lun;
2724}
2725EOF
2726  if compile_prog "" "" ; then
2727    guest_agent_ntddscsi=yes
2728    libs_qga="-lsetupapi -lcfgmgr32 $libs_qga"
2729  fi
2730fi
2731
2732##########################################
2733# capstone
2734
2735case "$capstone" in
2736  auto | enabled | internal)
2737    # Simpler to always update submodule, even if not needed.
2738    git_submodules="${git_submodules} capstone"
2739    ;;
2740esac
2741
2742##########################################
2743# check and set a backend for coroutine
2744
2745# We prefer ucontext, but it's not always possible. The fallback
2746# is sigcontext. On Windows the only valid backend is the Windows
2747# specific one.
2748
2749ucontext_works=no
2750if test "$darwin" != "yes"; then
2751  cat > $TMPC << EOF
2752#include <ucontext.h>
2753#ifdef __stub_makecontext
2754#error Ignoring glibc stub makecontext which will always fail
2755#endif
2756int main(void) { makecontext(0, 0, 0); return 0; }
2757EOF
2758  if compile_prog "" "" ; then
2759    ucontext_works=yes
2760  fi
2761fi
2762
2763if test "$coroutine" = ""; then
2764  if test "$mingw32" = "yes"; then
2765    coroutine=win32
2766  elif test "$ucontext_works" = "yes"; then
2767    coroutine=ucontext
2768  else
2769    coroutine=sigaltstack
2770  fi
2771else
2772  case $coroutine in
2773  windows)
2774    if test "$mingw32" != "yes"; then
2775      error_exit "'windows' coroutine backend only valid for Windows"
2776    fi
2777    # Unfortunately the user visible backend name doesn't match the
2778    # coroutine-*.c filename for this case, so we have to adjust it here.
2779    coroutine=win32
2780    ;;
2781  ucontext)
2782    if test "$ucontext_works" != "yes"; then
2783      feature_not_found "ucontext"
2784    fi
2785    ;;
2786  sigaltstack)
2787    if test "$mingw32" = "yes"; then
2788      error_exit "only the 'windows' coroutine backend is valid for Windows"
2789    fi
2790    ;;
2791  *)
2792    error_exit "unknown coroutine backend $coroutine"
2793    ;;
2794  esac
2795fi
2796
2797if test "$coroutine_pool" = ""; then
2798  coroutine_pool=yes
2799fi
2800
2801if test "$debug_stack_usage" = "yes"; then
2802  if test "$coroutine_pool" = "yes"; then
2803    echo "WARN: disabling coroutine pool for stack usage debugging"
2804    coroutine_pool=no
2805  fi
2806fi
2807
2808##################################################
2809# SafeStack
2810
2811
2812if test "$safe_stack" = "yes"; then
2813cat > $TMPC << EOF
2814int main(int argc, char *argv[])
2815{
2816#if ! __has_feature(safe_stack)
2817#error SafeStack Disabled
2818#endif
2819    return 0;
2820}
2821EOF
2822  flag="-fsanitize=safe-stack"
2823  # Check that safe-stack is supported and enabled.
2824  if compile_prog "-Werror $flag" "$flag"; then
2825    # Flag needed both at compilation and at linking
2826    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2827    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
2828  else
2829    error_exit "SafeStack not supported by your compiler"
2830  fi
2831  if test "$coroutine" != "ucontext"; then
2832    error_exit "SafeStack is only supported by the coroutine backend ucontext"
2833  fi
2834else
2835cat > $TMPC << EOF
2836int main(int argc, char *argv[])
2837{
2838#if defined(__has_feature)
2839#if __has_feature(safe_stack)
2840#error SafeStack Enabled
2841#endif
2842#endif
2843    return 0;
2844}
2845EOF
2846if test "$safe_stack" = "no"; then
2847  # Make sure that safe-stack is disabled
2848  if ! compile_prog "-Werror" ""; then
2849    # SafeStack was already enabled, try to explicitly remove the feature
2850    flag="-fno-sanitize=safe-stack"
2851    if ! compile_prog "-Werror $flag" "$flag"; then
2852      error_exit "Configure cannot disable SafeStack"
2853    fi
2854    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2855    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
2856  fi
2857else # "$safe_stack" = ""
2858  # Set safe_stack to yes or no based on pre-existing flags
2859  if compile_prog "-Werror" ""; then
2860    safe_stack="no"
2861  else
2862    safe_stack="yes"
2863    if test "$coroutine" != "ucontext"; then
2864      error_exit "SafeStack is only supported by the coroutine backend ucontext"
2865    fi
2866  fi
2867fi
2868fi
2869
2870########################################
2871# check if cpuid.h is usable.
2872
2873cat > $TMPC << EOF
2874#include <cpuid.h>
2875int main(void) {
2876    unsigned a, b, c, d;
2877    int max = __get_cpuid_max(0, 0);
2878
2879    if (max >= 1) {
2880        __cpuid(1, a, b, c, d);
2881    }
2882
2883    if (max >= 7) {
2884        __cpuid_count(7, 0, a, b, c, d);
2885    }
2886
2887    return 0;
2888}
2889EOF
2890if compile_prog "" "" ; then
2891    cpuid_h=yes
2892fi
2893
2894##########################################
2895# avx2 optimization requirement check
2896#
2897# There is no point enabling this if cpuid.h is not usable,
2898# since we won't be able to select the new routines.
2899
2900if test "$cpuid_h" = "yes" && test "$avx2_opt" != "no"; then
2901  cat > $TMPC << EOF
2902#pragma GCC push_options
2903#pragma GCC target("avx2")
2904#include <cpuid.h>
2905#include <immintrin.h>
2906static int bar(void *a) {
2907    __m256i x = *(__m256i *)a;
2908    return _mm256_testz_si256(x, x);
2909}
2910int main(int argc, char *argv[]) { return bar(argv[0]); }
2911EOF
2912  if compile_object "-Werror" ; then
2913    avx2_opt="yes"
2914  else
2915    avx2_opt="no"
2916  fi
2917fi
2918
2919##########################################
2920# avx512f optimization requirement check
2921#
2922# There is no point enabling this if cpuid.h is not usable,
2923# since we won't be able to select the new routines.
2924# by default, it is turned off.
2925# if user explicitly want to enable it, check environment
2926
2927if test "$cpuid_h" = "yes" && test "$avx512f_opt" = "yes"; then
2928  cat > $TMPC << EOF
2929#pragma GCC push_options
2930#pragma GCC target("avx512f")
2931#include <cpuid.h>
2932#include <immintrin.h>
2933static int bar(void *a) {
2934    __m512i x = *(__m512i *)a;
2935    return _mm512_test_epi64_mask(x, x);
2936}
2937int main(int argc, char *argv[])
2938{
2939	return bar(argv[0]);
2940}
2941EOF
2942  if ! compile_object "-Werror" ; then
2943    avx512f_opt="no"
2944  fi
2945else
2946  avx512f_opt="no"
2947fi
2948
2949########################################
2950# check if __[u]int128_t is usable.
2951
2952int128=no
2953cat > $TMPC << EOF
2954__int128_t a;
2955__uint128_t b;
2956int main (void) {
2957  a = a + b;
2958  b = a * b;
2959  a = a * a;
2960  return 0;
2961}
2962EOF
2963if compile_prog "" "" ; then
2964    int128=yes
2965fi
2966
2967#########################################
2968# See if 128-bit atomic operations are supported.
2969
2970atomic128=no
2971if test "$int128" = "yes"; then
2972  cat > $TMPC << EOF
2973int main(void)
2974{
2975  unsigned __int128 x = 0, y = 0;
2976  y = __atomic_load(&x, 0);
2977  __atomic_store(&x, y, 0);
2978  __atomic_compare_exchange(&x, &y, x, 0, 0, 0);
2979  return 0;
2980}
2981EOF
2982  if compile_prog "" "" ; then
2983    atomic128=yes
2984  fi
2985fi
2986
2987cmpxchg128=no
2988if test "$int128" = yes && test "$atomic128" = no; then
2989  cat > $TMPC << EOF
2990int main(void)
2991{
2992  unsigned __int128 x = 0, y = 0;
2993  __sync_val_compare_and_swap_16(&x, y, x);
2994  return 0;
2995}
2996EOF
2997  if compile_prog "" "" ; then
2998    cmpxchg128=yes
2999  fi
3000fi
3001
3002########################################
3003# check if ccache is interfering with
3004# semantic analysis of macros
3005
3006unset CCACHE_CPP2
3007ccache_cpp2=no
3008cat > $TMPC << EOF
3009static const int Z = 1;
3010#define fn() ({ Z; })
3011#define TAUT(X) ((X) == Z)
3012#define PAREN(X, Y) (X == Y)
3013#define ID(X) (X)
3014int main(int argc, char *argv[])
3015{
3016    int x = 0, y = 0;
3017    x = ID(x);
3018    x = fn();
3019    fn();
3020    if (PAREN(x, y)) return 0;
3021    if (TAUT(Z)) return 0;
3022    return 0;
3023}
3024EOF
3025
3026if ! compile_object "-Werror"; then
3027    ccache_cpp2=yes
3028fi
3029
3030#################################################
3031# clang does not support glibc + FORTIFY_SOURCE.
3032
3033if test "$fortify_source" != "no"; then
3034  if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
3035    fortify_source="no";
3036  elif test -n "$cxx" && has $cxx &&
3037       echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
3038    fortify_source="no";
3039  else
3040    fortify_source="yes"
3041  fi
3042fi
3043
3044##########################################
3045# check for usable membarrier system call
3046if test "$membarrier" = "yes"; then
3047    have_membarrier=no
3048    if test "$mingw32" = "yes" ; then
3049        have_membarrier=yes
3050    elif test "$linux" = "yes" ; then
3051        cat > $TMPC << EOF
3052    #include <linux/membarrier.h>
3053    #include <sys/syscall.h>
3054    #include <unistd.h>
3055    #include <stdlib.h>
3056    int main(void) {
3057        syscall(__NR_membarrier, MEMBARRIER_CMD_QUERY, 0);
3058        syscall(__NR_membarrier, MEMBARRIER_CMD_SHARED, 0);
3059	exit(0);
3060    }
3061EOF
3062        if compile_prog "" "" ; then
3063            have_membarrier=yes
3064        fi
3065    fi
3066    if test "$have_membarrier" = "no"; then
3067      feature_not_found "membarrier" "membarrier system call not available"
3068    fi
3069else
3070    # Do not enable it by default even for Mingw32, because it doesn't
3071    # work on Wine.
3072    membarrier=no
3073fi
3074
3075##########################################
3076# check for usable AF_ALG environment
3077have_afalg=no
3078cat > $TMPC << EOF
3079#include <errno.h>
3080#include <sys/types.h>
3081#include <sys/socket.h>
3082#include <linux/if_alg.h>
3083int main(void) {
3084    int sock;
3085    sock = socket(AF_ALG, SOCK_SEQPACKET, 0);
3086    return sock;
3087}
3088EOF
3089if compile_prog "" "" ; then
3090    have_afalg=yes
3091fi
3092if test "$crypto_afalg" = "yes"
3093then
3094    if test "$have_afalg" != "yes"
3095    then
3096	error_exit "AF_ALG requested but could not be detected"
3097    fi
3098fi
3099
3100
3101##########################################
3102# checks for sanitizers
3103
3104have_asan=no
3105have_ubsan=no
3106have_asan_iface_h=no
3107have_asan_iface_fiber=no
3108
3109if test "$sanitizers" = "yes" ; then
3110  write_c_skeleton
3111  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
3112      have_asan=yes
3113  fi
3114
3115  # we could use a simple skeleton for flags checks, but this also
3116  # detect the static linking issue of ubsan, see also:
3117  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
3118  cat > $TMPC << EOF
3119#include <stdlib.h>
3120int main(void) {
3121    void *tmp = malloc(10);
3122    if (tmp != NULL) {
3123        return *(int *)(tmp + 2);
3124    }
3125    return 1;
3126}
3127EOF
3128  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
3129      have_ubsan=yes
3130  fi
3131
3132  if check_include "sanitizer/asan_interface.h" ; then
3133      have_asan_iface_h=yes
3134  fi
3135
3136  cat > $TMPC << EOF
3137#include <sanitizer/asan_interface.h>
3138int main(void) {
3139  __sanitizer_start_switch_fiber(0, 0, 0);
3140  return 0;
3141}
3142EOF
3143  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
3144      have_asan_iface_fiber=yes
3145  fi
3146fi
3147
3148# Thread sanitizer is, for now, much noisier than the other sanitizers;
3149# keep it separate until that is not the case.
3150if test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
3151  error_exit "TSAN is not supported with other sanitiziers."
3152fi
3153have_tsan=no
3154have_tsan_iface_fiber=no
3155if test "$tsan" = "yes" ; then
3156  write_c_skeleton
3157  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
3158      have_tsan=yes
3159  fi
3160  cat > $TMPC << EOF
3161#include <sanitizer/tsan_interface.h>
3162int main(void) {
3163  __tsan_create_fiber(0);
3164  return 0;
3165}
3166EOF
3167  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
3168      have_tsan_iface_fiber=yes
3169  fi
3170fi
3171
3172##########################################
3173# check for slirp
3174
3175case "$slirp" in
3176  auto | enabled | internal)
3177    # Simpler to always update submodule, even if not needed.
3178    git_submodules="${git_submodules} slirp"
3179    ;;
3180esac
3181
3182# Check for slirp smbd dupport
3183: ${smbd=${SMBD-/usr/sbin/smbd}}
3184if test "$slirp_smbd" != "no" ; then
3185  if test "$mingw32" = "yes" ; then
3186    if test "$slirp_smbd" = "yes" ; then
3187      error_exit "Host smbd not supported on this platform."
3188    fi
3189    slirp_smbd=no
3190  else
3191    slirp_smbd=yes
3192  fi
3193fi
3194
3195##########################################
3196# check for usable __NR_keyctl syscall
3197
3198if test "$linux" = "yes" ; then
3199
3200    have_keyring=no
3201    cat > $TMPC << EOF
3202#include <errno.h>
3203#include <asm/unistd.h>
3204#include <linux/keyctl.h>
3205#include <unistd.h>
3206int main(void) {
3207    return syscall(__NR_keyctl, KEYCTL_READ, 0, NULL, NULL, 0);
3208}
3209EOF
3210    if compile_prog "" "" ; then
3211        have_keyring=yes
3212    fi
3213fi
3214if test "$secret_keyring" != "no"
3215then
3216    if test "$have_keyring" = "yes"
3217    then
3218	secret_keyring=yes
3219    else
3220	if test "$secret_keyring" = "yes"
3221	then
3222	    error_exit "syscall __NR_keyctl requested, \
3223but not implemented on your system"
3224	else
3225	    secret_keyring=no
3226	fi
3227    fi
3228fi
3229
3230##########################################
3231# End of CC checks
3232# After here, no more $cc or $ld runs
3233
3234write_c_skeleton
3235
3236if test "$gcov" = "yes" ; then
3237  :
3238elif test "$fortify_source" = "yes" ; then
3239  QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
3240  debug=no
3241fi
3242
3243case "$ARCH" in
3244alpha)
3245  # Ensure there's only a single GP
3246  QEMU_CFLAGS="-msmall-data $QEMU_CFLAGS"
3247;;
3248esac
3249
3250if test "$gprof" = "yes" ; then
3251  QEMU_CFLAGS="-p $QEMU_CFLAGS"
3252  QEMU_LDFLAGS="-p $QEMU_LDFLAGS"
3253fi
3254
3255if test "$have_asan" = "yes"; then
3256  QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
3257  QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
3258  if test "$have_asan_iface_h" = "no" ; then
3259      echo "ASAN build enabled, but ASAN header missing." \
3260           "Without code annotation, the report may be inferior."
3261  elif test "$have_asan_iface_fiber" = "no" ; then
3262      echo "ASAN build enabled, but ASAN header is too old." \
3263           "Without code annotation, the report may be inferior."
3264  fi
3265fi
3266if test "$have_tsan" = "yes" ; then
3267  if test "$have_tsan_iface_fiber" = "yes" ; then
3268    QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
3269    QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
3270  else
3271    error_exit "Cannot enable TSAN due to missing fiber annotation interface."
3272  fi
3273elif test "$tsan" = "yes" ; then
3274  error_exit "Cannot enable TSAN due to missing sanitize thread interface."
3275fi
3276if test "$have_ubsan" = "yes"; then
3277  QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
3278  QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
3279fi
3280
3281##########################################
3282
3283# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
3284if test "$solaris" = "no" && test "$tsan" = "no"; then
3285    if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
3286        QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
3287    fi
3288fi
3289
3290# Use ASLR, no-SEH and DEP if available
3291if test "$mingw32" = "yes" ; then
3292    flags="--no-seh --nxcompat"
3293
3294    # Disable ASLR for debug builds to allow debugging with gdb
3295    if test "$debug" = "no" ; then
3296        flags="--dynamicbase $flags"
3297    fi
3298
3299    for flag in $flags; do
3300        if ld_has $flag ; then
3301            QEMU_LDFLAGS="-Wl,$flag $QEMU_LDFLAGS"
3302        fi
3303    done
3304fi
3305
3306# Probe for guest agent support/options
3307
3308if [ "$guest_agent" != "no" ]; then
3309  if [ "$softmmu" = no -a "$want_tools" = no ] ; then
3310      guest_agent=no
3311  elif [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" -o "$mingw32" = "yes" ] ; then
3312      guest_agent=yes
3313  elif [ "$guest_agent" != yes ]; then
3314      guest_agent=no
3315  else
3316      error_exit "Guest agent is not supported on this platform"
3317  fi
3318fi
3319
3320# Guest agent Windows MSI package
3321
3322if test "$QEMU_GA_MANUFACTURER" = ""; then
3323  QEMU_GA_MANUFACTURER=QEMU
3324fi
3325if test "$QEMU_GA_DISTRO" = ""; then
3326  QEMU_GA_DISTRO=Linux
3327fi
3328if test "$QEMU_GA_VERSION" = ""; then
3329    QEMU_GA_VERSION=$(cat $source_path/VERSION)
3330fi
3331
3332QEMU_GA_MSI_MINGW_DLL_PATH="$($pkg_config --variable=prefix glib-2.0)/bin"
3333
3334# Mac OS X ships with a broken assembler
3335roms=
3336if { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \
3337        test "$targetos" != "Darwin" && test "$targetos" != "SunOS" && \
3338        test "$targetos" != "Haiku" && test "$softmmu" = yes ; then
3339    # Different host OS linkers have different ideas about the name of the ELF
3340    # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
3341    # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
3342    for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
3343        if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
3344            ld_i386_emulation="$emu"
3345            roms="optionrom"
3346            break
3347        fi
3348    done
3349fi
3350
3351# Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
3352# or -march=z10 (which is the lowest architecture level that Clang supports)
3353if test "$cpu" = "s390x" ; then
3354  write_c_skeleton
3355  compile_prog "-march=z900" ""
3356  has_z900=$?
3357  if [ $has_z900 = 0 ] || compile_object "-march=z10 -msoft-float -Werror"; then
3358    if [ $has_z900 != 0 ]; then
3359      echo "WARNING: Your compiler does not support the z900!"
3360      echo "         The s390-ccw bios will only work with guest CPUs >= z10."
3361    fi
3362    roms="$roms s390-ccw"
3363    # SLOF is required for building the s390-ccw firmware on s390x,
3364    # since it is using the libnet code from SLOF for network booting.
3365    git_submodules="${git_submodules} roms/SLOF"
3366  fi
3367fi
3368
3369# Check that the C++ compiler exists and works with the C compiler.
3370# All the QEMU_CXXFLAGS are based on QEMU_CFLAGS. Keep this at the end to don't miss any other that could be added.
3371if has $cxx; then
3372    cat > $TMPC <<EOF
3373int c_function(void);
3374int main(void) { return c_function(); }
3375EOF
3376
3377    compile_object
3378
3379    cat > $TMPCXX <<EOF
3380extern "C" {
3381   int c_function(void);
3382}
3383int c_function(void) { return 42; }
3384EOF
3385
3386    update_cxxflags
3387
3388    if do_cxx $CXXFLAGS $EXTRA_CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
3389        # C++ compiler $cxx works ok with C compiler $cc
3390        :
3391    else
3392        echo "C++ compiler $cxx does not work with C compiler $cc"
3393        echo "Disabling C++ specific optional code"
3394        cxx=
3395    fi
3396else
3397    echo "No C++ compiler available; disabling C++ specific optional code"
3398    cxx=
3399fi
3400
3401if !(GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
3402    exit 1
3403fi
3404
3405config_host_mak="config-host.mak"
3406
3407echo "# Automatically generated by configure - do not modify" > $config_host_mak
3408echo >> $config_host_mak
3409
3410echo all: >> $config_host_mak
3411echo "GIT=$git" >> $config_host_mak
3412echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
3413echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
3414
3415echo "ARCH=$ARCH" >> $config_host_mak
3416
3417if test "$debug_tcg" = "yes" ; then
3418  echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
3419fi
3420if test "$strip_opt" = "yes" ; then
3421  echo "STRIP=${strip}" >> $config_host_mak
3422fi
3423if test "$mingw32" = "yes" ; then
3424  echo "CONFIG_WIN32=y" >> $config_host_mak
3425  if test "$guest_agent_with_vss" = "yes" ; then
3426    echo "CONFIG_QGA_VSS=y" >> $config_host_mak
3427    echo "QGA_VSS_PROVIDER=$qga_vss_provider" >> $config_host_mak
3428    echo "WIN_SDK=\"$win_sdk\"" >> $config_host_mak
3429  fi
3430  if test "$guest_agent_ntddscsi" = "yes" ; then
3431    echo "CONFIG_QGA_NTDDSCSI=y" >> $config_host_mak
3432  fi
3433  echo "QEMU_GA_MSI_MINGW_DLL_PATH=${QEMU_GA_MSI_MINGW_DLL_PATH}" >> $config_host_mak
3434  echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
3435  echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
3436  echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
3437else
3438  echo "CONFIG_POSIX=y" >> $config_host_mak
3439fi
3440
3441if test "$linux" = "yes" ; then
3442  echo "CONFIG_LINUX=y" >> $config_host_mak
3443fi
3444
3445if test "$darwin" = "yes" ; then
3446  echo "CONFIG_DARWIN=y" >> $config_host_mak
3447fi
3448
3449if test "$solaris" = "yes" ; then
3450  echo "CONFIG_SOLARIS=y" >> $config_host_mak
3451fi
3452if test "$static" = "yes" ; then
3453  echo "CONFIG_STATIC=y" >> $config_host_mak
3454fi
3455if test "$profiler" = "yes" ; then
3456  echo "CONFIG_PROFILER=y" >> $config_host_mak
3457fi
3458if test "$want_tools" = "yes" ; then
3459  echo "CONFIG_TOOLS=y" >> $config_host_mak
3460fi
3461if test "$guest_agent" = "yes" ; then
3462  echo "CONFIG_GUEST_AGENT=y" >> $config_host_mak
3463fi
3464if test "$slirp_smbd" = "yes" ; then
3465  echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak
3466  echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
3467fi
3468if test "$gprof" = "yes" ; then
3469  echo "CONFIG_GPROF=y" >> $config_host_mak
3470fi
3471echo "CONFIG_BDRV_RW_WHITELIST=$block_drv_rw_whitelist" >> $config_host_mak
3472echo "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
3473if test "$block_drv_whitelist_tools" = "yes" ; then
3474  echo "CONFIG_BDRV_WHITELIST_TOOLS=y" >> $config_host_mak
3475fi
3476if test "$xfs" = "yes" ; then
3477  echo "CONFIG_XFS=y" >> $config_host_mak
3478fi
3479qemu_version=$(head $source_path/VERSION)
3480echo "PKGVERSION=$pkgversion" >>$config_host_mak
3481echo "SRC_PATH=$source_path" >> $config_host_mak
3482echo "TARGET_DIRS=$target_list" >> $config_host_mak
3483if test "$modules" = "yes"; then
3484  # $shacmd can generate a hash started with digit, which the compiler doesn't
3485  # like as an symbol. So prefix it with an underscore
3486  echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
3487  echo "CONFIG_MODULES=y" >> $config_host_mak
3488fi
3489if test "$module_upgrades" = "yes"; then
3490  echo "CONFIG_MODULE_UPGRADES=y" >> $config_host_mak
3491fi
3492if test "$have_usbfs" = "yes" ; then
3493  echo "CONFIG_USBFS=y" >> $config_host_mak
3494fi
3495if test "$gio" = "yes" ; then
3496    echo "CONFIG_GIO=y" >> $config_host_mak
3497    echo "GIO_CFLAGS=$gio_cflags" >> $config_host_mak
3498    echo "GIO_LIBS=$gio_libs" >> $config_host_mak
3499fi
3500if test "$gdbus_codegen" != "" ; then
3501    echo "GDBUS_CODEGEN=$gdbus_codegen" >> $config_host_mak
3502fi
3503echo "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak
3504
3505if test "$xen" = "enabled" ; then
3506  echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
3507  echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
3508  echo "XEN_CFLAGS=$xen_cflags" >> $config_host_mak
3509  echo "XEN_LIBS=$xen_libs" >> $config_host_mak
3510fi
3511if test "$vhost_scsi" = "yes" ; then
3512  echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
3513fi
3514if test "$vhost_net" = "yes" ; then
3515  echo "CONFIG_VHOST_NET=y" >> $config_host_mak
3516fi
3517if test "$vhost_net_user" = "yes" ; then
3518  echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak
3519fi
3520if test "$vhost_net_vdpa" = "yes" ; then
3521  echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak
3522fi
3523if test "$vhost_crypto" = "yes" ; then
3524  echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
3525fi
3526if test "$vhost_vsock" = "yes" ; then
3527  echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
3528  if test "$vhost_user" = "yes" ; then
3529    echo "CONFIG_VHOST_USER_VSOCK=y" >> $config_host_mak
3530  fi
3531fi
3532if test "$vhost_kernel" = "yes" ; then
3533  echo "CONFIG_VHOST_KERNEL=y" >> $config_host_mak
3534fi
3535if test "$vhost_user" = "yes" ; then
3536  echo "CONFIG_VHOST_USER=y" >> $config_host_mak
3537fi
3538if test "$vhost_vdpa" = "yes" ; then
3539  echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
3540fi
3541if test "$vhost_user_fs" = "yes" ; then
3542  echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak
3543fi
3544if test "$membarrier" = "yes" ; then
3545  echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
3546fi
3547if test "$tcg" = "enabled" -a "$tcg_interpreter" = "true" ; then
3548  echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
3549fi
3550
3551if test "$opengl" = "yes" ; then
3552  echo "CONFIG_OPENGL=y" >> $config_host_mak
3553  echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
3554  echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
3555fi
3556
3557if test "$avx2_opt" = "yes" ; then
3558  echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
3559fi
3560
3561if test "$avx512f_opt" = "yes" ; then
3562  echo "CONFIG_AVX512F_OPT=y" >> $config_host_mak
3563fi
3564
3565# XXX: suppress that
3566if [ "$bsd" = "yes" ] ; then
3567  echo "CONFIG_BSD=y" >> $config_host_mak
3568fi
3569
3570if test "$qom_cast_debug" = "yes" ; then
3571  echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak
3572fi
3573
3574echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
3575if test "$coroutine_pool" = "yes" ; then
3576  echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
3577else
3578  echo "CONFIG_COROUTINE_POOL=0" >> $config_host_mak
3579fi
3580
3581if test "$debug_stack_usage" = "yes" ; then
3582  echo "CONFIG_DEBUG_STACK_USAGE=y" >> $config_host_mak
3583fi
3584
3585if test "$crypto_afalg" = "yes" ; then
3586  echo "CONFIG_AF_ALG=y" >> $config_host_mak
3587fi
3588
3589if test "$have_asan_iface_fiber" = "yes" ; then
3590    echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
3591fi
3592
3593if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
3594    echo "CONFIG_TSAN=y" >> $config_host_mak
3595fi
3596
3597if test "$cpuid_h" = "yes" ; then
3598  echo "CONFIG_CPUID_H=y" >> $config_host_mak
3599fi
3600
3601if test "$int128" = "yes" ; then
3602  echo "CONFIG_INT128=y" >> $config_host_mak
3603fi
3604
3605if test "$atomic128" = "yes" ; then
3606  echo "CONFIG_ATOMIC128=y" >> $config_host_mak
3607fi
3608
3609if test "$cmpxchg128" = "yes" ; then
3610  echo "CONFIG_CMPXCHG128=y" >> $config_host_mak
3611fi
3612
3613if test "$live_block_migration" = "yes" ; then
3614  echo "CONFIG_LIVE_BLOCK_MIGRATION=y" >> $config_host_mak
3615fi
3616
3617if test "$tpm" = "yes"; then
3618  echo 'CONFIG_TPM=y' >> $config_host_mak
3619fi
3620
3621if test "$rdma" = "yes" ; then
3622  echo "CONFIG_RDMA=y" >> $config_host_mak
3623  echo "RDMA_LIBS=$rdma_libs" >> $config_host_mak
3624fi
3625
3626if test "$pvrdma" = "yes" ; then
3627  echo "CONFIG_PVRDMA=y" >> $config_host_mak
3628fi
3629
3630if test "$replication" = "yes" ; then
3631  echo "CONFIG_REPLICATION=y" >> $config_host_mak
3632fi
3633
3634if test "$debug_mutex" = "yes" ; then
3635  echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak
3636fi
3637
3638if test "$bochs" = "yes" ; then
3639  echo "CONFIG_BOCHS=y" >> $config_host_mak
3640fi
3641if test "$cloop" = "yes" ; then
3642  echo "CONFIG_CLOOP=y" >> $config_host_mak
3643fi
3644if test "$dmg" = "yes" ; then
3645  echo "CONFIG_DMG=y" >> $config_host_mak
3646fi
3647if test "$qcow1" = "yes" ; then
3648  echo "CONFIG_QCOW1=y" >> $config_host_mak
3649fi
3650if test "$vdi" = "yes" ; then
3651  echo "CONFIG_VDI=y" >> $config_host_mak
3652fi
3653if test "$vvfat" = "yes" ; then
3654  echo "CONFIG_VVFAT=y" >> $config_host_mak
3655fi
3656if test "$qed" = "yes" ; then
3657  echo "CONFIG_QED=y" >> $config_host_mak
3658fi
3659if test "$parallels" = "yes" ; then
3660  echo "CONFIG_PARALLELS=y" >> $config_host_mak
3661fi
3662
3663if test "$plugins" = "yes" ; then
3664    echo "CONFIG_PLUGIN=y" >> $config_host_mak
3665    # Copy the export object list to the build dir
3666    if test "$ld_dynamic_list" = "yes" ; then
3667	echo "CONFIG_HAS_LD_DYNAMIC_LIST=yes" >> $config_host_mak
3668	ld_symbols=qemu-plugins-ld.symbols
3669	cp "$source_path/plugins/qemu-plugins.symbols" $ld_symbols
3670    elif test "$ld_exported_symbols_list" = "yes" ; then
3671	echo "CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST=yes" >> $config_host_mak
3672	ld64_symbols=qemu-plugins-ld64.symbols
3673	echo "# Automatically generated by configure - do not modify" > $ld64_symbols
3674	grep 'qemu_' "$source_path/plugins/qemu-plugins.symbols" | sed 's/;//g' | \
3675	    sed -E 's/^[[:space:]]*(.*)/_\1/' >> $ld64_symbols
3676    else
3677	error_exit \
3678	    "If \$plugins=yes, either \$ld_dynamic_list or " \
3679	    "\$ld_exported_symbols_list should have been set to 'yes'."
3680    fi
3681fi
3682
3683if test -n "$gdb_bin"; then
3684    gdb_version=$($gdb_bin --version | head -n 1)
3685    if version_ge ${gdb_version##* } 9.1; then
3686        echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
3687    fi
3688fi
3689
3690if test "$secret_keyring" = "yes" ; then
3691  echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak
3692fi
3693
3694echo "ROMS=$roms" >> $config_host_mak
3695echo "MAKE=$make" >> $config_host_mak
3696echo "PYTHON=$python" >> $config_host_mak
3697echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
3698echo "MESON=$meson" >> $config_host_mak
3699echo "NINJA=$ninja" >> $config_host_mak
3700echo "CC=$cc" >> $config_host_mak
3701echo "HOST_CC=$host_cc" >> $config_host_mak
3702if $iasl -h > /dev/null 2>&1; then
3703  echo "CONFIG_IASL=$iasl" >> $config_host_mak
3704fi
3705echo "AR=$ar" >> $config_host_mak
3706echo "AS=$as" >> $config_host_mak
3707echo "CCAS=$ccas" >> $config_host_mak
3708echo "CPP=$cpp" >> $config_host_mak
3709echo "OBJCOPY=$objcopy" >> $config_host_mak
3710echo "LD=$ld" >> $config_host_mak
3711echo "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
3712echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
3713echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
3714echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
3715echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
3716echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
3717echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
3718echo "EXESUF=$EXESUF" >> $config_host_mak
3719echo "LIBS_QGA=$libs_qga" >> $config_host_mak
3720
3721if test "$rng_none" = "yes"; then
3722  echo "CONFIG_RNG_NONE=y" >> $config_host_mak
3723fi
3724
3725# use included Linux headers
3726if test "$linux" = "yes" ; then
3727  mkdir -p linux-headers
3728  case "$cpu" in
3729  i386|x86_64|x32)
3730    linux_arch=x86
3731    ;;
3732  ppc|ppc64|ppc64le)
3733    linux_arch=powerpc
3734    ;;
3735  s390x)
3736    linux_arch=s390
3737    ;;
3738  aarch64)
3739    linux_arch=arm64
3740    ;;
3741  mips64)
3742    linux_arch=mips
3743    ;;
3744  *)
3745    # For most CPUs the kernel architecture name and QEMU CPU name match.
3746    linux_arch="$cpu"
3747    ;;
3748  esac
3749    # For non-KVM architectures we will not have asm headers
3750    if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
3751      symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
3752    fi
3753fi
3754
3755for target in $target_list; do
3756    target_dir="$target"
3757    target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
3758    mkdir -p $target_dir
3759    case $target in
3760        *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
3761        *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
3762    esac
3763done
3764
3765echo "CONFIG_QEMU_INTERP_PREFIX=$interp_prefix" | sed 's/%M/@0@/' >> $config_host_mak
3766if test "$default_targets" = "yes"; then
3767  echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
3768fi
3769
3770if test "$numa" = "yes"; then
3771  echo "CONFIG_NUMA=y" >> $config_host_mak
3772  echo "NUMA_LIBS=$numa_libs" >> $config_host_mak
3773fi
3774
3775if test "$ccache_cpp2" = "yes"; then
3776  echo "export CCACHE_CPP2=y" >> $config_host_mak
3777fi
3778
3779if test "$safe_stack" = "yes"; then
3780  echo "CONFIG_SAFESTACK=y" >> $config_host_mak
3781fi
3782
3783# If we're using a separate build tree, set it up now.
3784# DIRS are directories which we simply mkdir in the build tree;
3785# LINKS are things to symlink back into the source tree
3786# (these can be both files and directories).
3787# Caution: do not add files or directories here using wildcards. This
3788# will result in problems later if a new file matching the wildcard is
3789# added to the source tree -- nothing will cause configure to be rerun
3790# so the build tree will be missing the link back to the new file, and
3791# tests might fail. Prefer to keep the relevant files in their own
3792# directory and symlink the directory instead.
3793# UNLINK is used to remove symlinks from older development versions
3794# that might get into the way when doing "git update" without doing
3795# a "make distclean" in between.
3796DIRS="tests tests/tcg tests/qapi-schema tests/qtest/libqos"
3797DIRS="$DIRS tests/qtest tests/qemu-iotests tests/vm tests/fp tests/qgraph"
3798DIRS="$DIRS docs docs/interop fsdev scsi"
3799DIRS="$DIRS pc-bios/optionrom pc-bios/s390-ccw"
3800DIRS="$DIRS roms/seabios"
3801DIRS="$DIRS contrib/plugins/"
3802LINKS="Makefile"
3803LINKS="$LINKS tests/tcg/Makefile.target"
3804LINKS="$LINKS pc-bios/optionrom/Makefile"
3805LINKS="$LINKS pc-bios/s390-ccw/Makefile"
3806LINKS="$LINKS roms/seabios/Makefile"
3807LINKS="$LINKS pc-bios/qemu-icon.bmp"
3808LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
3809LINKS="$LINKS tests/avocado tests/data"
3810LINKS="$LINKS tests/qemu-iotests/check"
3811LINKS="$LINKS python"
3812LINKS="$LINKS contrib/plugins/Makefile "
3813UNLINK="pc-bios/keymaps"
3814for bios_file in \
3815    $source_path/pc-bios/*.bin \
3816    $source_path/pc-bios/*.elf \
3817    $source_path/pc-bios/*.lid \
3818    $source_path/pc-bios/*.rom \
3819    $source_path/pc-bios/*.dtb \
3820    $source_path/pc-bios/*.img \
3821    $source_path/pc-bios/openbios-* \
3822    $source_path/pc-bios/u-boot.* \
3823    $source_path/pc-bios/edk2-*.fd.bz2 \
3824    $source_path/pc-bios/palcode-* \
3825    $source_path/pc-bios/qemu_vga.ndrv
3826
3827do
3828    LINKS="$LINKS pc-bios/$(basename $bios_file)"
3829done
3830mkdir -p $DIRS
3831for f in $LINKS ; do
3832    if [ -e "$source_path/$f" ]; then
3833        symlink "$source_path/$f" "$f"
3834    fi
3835done
3836for f in $UNLINK ; do
3837    if [ -L "$f" ]; then
3838        rm -f "$f"
3839    fi
3840done
3841
3842(for i in $cross_cc_vars; do
3843  export $i
3844done
3845export target_list source_path use_containers ARCH
3846$source_path/tests/tcg/configure.sh)
3847
3848# temporary config to build submodules
3849for rom in seabios; do
3850    config_mak=roms/$rom/config.mak
3851    echo "# Automatically generated by configure - do not modify" > $config_mak
3852    echo "SRC_PATH=$source_path/roms/$rom" >> $config_mak
3853    echo "AS=$as" >> $config_mak
3854    echo "CCAS=$ccas" >> $config_mak
3855    echo "CC=$cc" >> $config_mak
3856    echo "BCC=bcc" >> $config_mak
3857    echo "CPP=$cpp" >> $config_mak
3858    echo "OBJCOPY=objcopy" >> $config_mak
3859    echo "IASL=$iasl" >> $config_mak
3860    echo "LD=$ld" >> $config_mak
3861    echo "RANLIB=$ranlib" >> $config_mak
3862done
3863
3864config_mak=pc-bios/optionrom/config.mak
3865echo "# Automatically generated by configure - do not modify" > $config_mak
3866echo "TOPSRC_DIR=$source_path" >> $config_mak
3867
3868if test "$skip_meson" = no; then
3869  cross="config-meson.cross.new"
3870  meson_quote() {
3871    test $# = 0 && return
3872    echo "'$(echo $* | sed "s/ /','/g")'"
3873  }
3874
3875  echo "# Automatically generated by configure - do not modify" > $cross
3876  echo "[properties]" >> $cross
3877
3878  # unroll any custom device configs
3879  for a in $device_archs; do
3880      eval "c=\$devices_${a}"
3881      echo "${a}-softmmu = '$c'" >> $cross
3882  done
3883
3884  test -z "$cxx" && echo "link_language = 'c'" >> $cross
3885  echo "[built-in options]" >> $cross
3886  echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
3887  echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
3888  echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
3889  echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
3890  echo "[binaries]" >> $cross
3891  echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
3892  test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
3893  test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
3894  echo "ar = [$(meson_quote $ar)]" >> $cross
3895  echo "nm = [$(meson_quote $nm)]" >> $cross
3896  echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
3897  echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
3898  if has $sdl2_config; then
3899    echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
3900  fi
3901  echo "strip = [$(meson_quote $strip)]" >> $cross
3902  echo "windres = [$(meson_quote $windres)]" >> $cross
3903  if test "$cross_compile" = "yes"; then
3904    cross_arg="--cross-file config-meson.cross"
3905    echo "[host_machine]" >> $cross
3906    if test "$mingw32" = "yes" ; then
3907        echo "system = 'windows'" >> $cross
3908    fi
3909    if test "$linux" = "yes" ; then
3910        echo "system = 'linux'" >> $cross
3911    fi
3912    if test "$darwin" = "yes" ; then
3913        echo "system = 'darwin'" >> $cross
3914    fi
3915    case "$ARCH" in
3916        i386)
3917            echo "cpu_family = 'x86'" >> $cross
3918            ;;
3919        x86_64|x32)
3920            echo "cpu_family = 'x86_64'" >> $cross
3921            ;;
3922        ppc64le)
3923            echo "cpu_family = 'ppc64'" >> $cross
3924            ;;
3925        *)
3926            echo "cpu_family = '$ARCH'" >> $cross
3927            ;;
3928    esac
3929    echo "cpu = '$cpu'" >> $cross
3930    if test "$bigendian" = "yes" ; then
3931        echo "endian = 'big'" >> $cross
3932    else
3933        echo "endian = 'little'" >> $cross
3934    fi
3935  else
3936    cross_arg="--native-file config-meson.cross"
3937  fi
3938  mv $cross config-meson.cross
3939
3940  rm -rf meson-private meson-info meson-logs
3941  run_meson() {
3942    NINJA=$ninja $meson setup \
3943        --prefix "$prefix" \
3944        --libdir "$libdir" \
3945        --libexecdir "$libexecdir" \
3946        --bindir "$bindir" \
3947        --includedir "$includedir" \
3948        --datadir "$datadir" \
3949        --mandir "$mandir" \
3950        --sysconfdir "$sysconfdir" \
3951        --localedir "$localedir" \
3952        --localstatedir "$local_statedir" \
3953        -Daudio_drv_list=$audio_drv_list \
3954        -Ddefault_devices=$default_devices \
3955        -Ddocdir="$docdir" \
3956        -Dqemu_firmwarepath="$firmwarepath" \
3957        -Dqemu_suffix="$qemu_suffix" \
3958        -Dsphinx_build="$sphinx_build" \
3959        -Dtrace_file="$trace_file" \
3960        -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) \
3961        -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo false; fi) \
3962        -Dwerror=$(if test "$werror" = yes; then echo true; else echo false; fi) \
3963        -Dstrip=$(if test "$strip_opt" = yes; then echo true; else echo false; fi) \
3964        -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \
3965        -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
3966        -Db_lto=$lto -Dcfi=$cfi -Dtcg=$tcg -Dxen=$xen \
3967        -Dcapstone=$capstone -Dfdt=$fdt -Dslirp=$slirp \
3968        $(test -n "${LIB_FUZZING_ENGINE+xxx}" && echo "-Dfuzzing_engine=$LIB_FUZZING_ENGINE") \
3969        $(if test "$default_feature" = no; then echo "-Dauto_features=disabled"; fi) \
3970        "$@" $cross_arg "$PWD" "$source_path"
3971  }
3972  eval run_meson $meson_options
3973  if test "$?" -ne 0 ; then
3974      error_exit "meson setup failed"
3975  fi
3976else
3977  if test -f meson-private/cmd_line.txt; then
3978    # Adjust old command line options whose type was changed
3979    # Avoids having to use "setup --wipe" when Meson is upgraded
3980    perl -i -ne '
3981      s/^gettext = true$/gettext = auto/;
3982      s/^gettext = false$/gettext = disabled/;
3983      /^b_staticpic/ && next;
3984      print;' meson-private/cmd_line.txt
3985  fi
3986fi
3987
3988if test -n "${deprecated_features}"; then
3989    echo "Warning, deprecated features enabled."
3990    echo "Please see docs/about/deprecated.rst"
3991    echo "  features: ${deprecated_features}"
3992fi
3993
3994# Create list of config switches that should be poisoned in common code...
3995# but filter out CONFIG_TCG and CONFIG_USER_ONLY which are special.
3996target_configs_h=$(ls *-config-devices.h *-config-target.h 2>/dev/null)
3997if test -n "$target_configs_h" ; then
3998    sed -n -e '/CONFIG_TCG/d' -e '/CONFIG_USER_ONLY/d' \
3999        -e '/^#define / { s///; s/ .*//; s/^/#pragma GCC poison /p; }' \
4000        $target_configs_h | sort -u > config-poison.h
4001else
4002    :> config-poison.h
4003fi
4004
4005# Save the configure command line for later reuse.
4006cat <<EOD >config.status
4007#!/bin/sh
4008# Generated by configure.
4009# Run this file to recreate the current configuration.
4010# Compiler output produced by configure, useful for debugging
4011# configure, is in config.log if it exists.
4012EOD
4013
4014preserve_env() {
4015    envname=$1
4016
4017    eval envval=\$$envname
4018
4019    if test -n "$envval"
4020    then
4021	echo "$envname='$envval'" >> config.status
4022	echo "export $envname" >> config.status
4023    else
4024	echo "unset $envname" >> config.status
4025    fi
4026}
4027
4028# Preserve various env variables that influence what
4029# features/build target configure will detect
4030preserve_env AR
4031preserve_env AS
4032preserve_env CC
4033preserve_env CPP
4034preserve_env CFLAGS
4035preserve_env CXX
4036preserve_env CXXFLAGS
4037preserve_env INSTALL
4038preserve_env LD
4039preserve_env LDFLAGS
4040preserve_env LD_LIBRARY_PATH
4041preserve_env LIBTOOL
4042preserve_env MAKE
4043preserve_env NM
4044preserve_env OBJCOPY
4045preserve_env PATH
4046preserve_env PKG_CONFIG
4047preserve_env PKG_CONFIG_LIBDIR
4048preserve_env PKG_CONFIG_PATH
4049preserve_env PYTHON
4050preserve_env SDL2_CONFIG
4051preserve_env SMBD
4052preserve_env STRIP
4053preserve_env WINDRES
4054
4055printf "exec" >>config.status
4056for i in "$0" "$@"; do
4057  test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
4058done
4059echo ' "$@"' >>config.status
4060chmod +x config.status
4061
4062rm -r "$TMPDIR1"
4063