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