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