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