xref: /openbmc/qemu/configure (revision 2266d443)
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# Temporary directory used for files created while
15# configure runs. Since it is in the build directory
16# we can safely blow away any previous version of it
17# (and we need not jump through hoops to try to delete
18# it when configure exits.)
19TMPDIR1="config-temp"
20rm -rf "${TMPDIR1}"
21mkdir -p "${TMPDIR1}"
22if [ $? -ne 0 ]; then
23    echo "ERROR: failed to create temporary directory"
24    exit 1
25fi
26
27TMPB="qemu-conf"
28TMPC="${TMPDIR1}/${TMPB}.c"
29TMPO="${TMPDIR1}/${TMPB}.o"
30TMPCXX="${TMPDIR1}/${TMPB}.cxx"
31TMPE="${TMPDIR1}/${TMPB}.exe"
32TMPMO="${TMPDIR1}/${TMPB}.mo"
33
34rm -f config.log
35
36# Print a helpful header at the top of config.log
37echo "# QEMU configure log $(date)" >> config.log
38printf "# Configured with:" >> config.log
39printf " '%s'" "$0" "$@" >> config.log
40echo >> config.log
41echo "#" >> config.log
42
43print_error() {
44    (echo
45    echo "ERROR: $1"
46    while test -n "$2"; do
47        echo "       $2"
48        shift
49    done
50    echo) >&2
51}
52
53error_exit() {
54    print_error "$@"
55    exit 1
56}
57
58do_compiler() {
59    # Run the compiler, capturing its output to the log. First argument
60    # is compiler binary to execute.
61    local compiler="$1"
62    shift
63    if test -n "$BASH_VERSION"; then eval '
64        echo >>config.log "
65funcs: ${FUNCNAME[*]}
66lines: ${BASH_LINENO[*]}"
67    '; fi
68    echo $compiler "$@" >> config.log
69    $compiler "$@" >> config.log 2>&1 || return $?
70    # Test passed. If this is an --enable-werror build, rerun
71    # the test with -Werror and bail out if it fails. This
72    # makes warning-generating-errors in configure test code
73    # obvious to developers.
74    if test "$werror" != "yes"; then
75        return 0
76    fi
77    # Don't bother rerunning the compile if we were already using -Werror
78    case "$*" in
79        *-Werror*)
80           return 0
81        ;;
82    esac
83    echo $compiler -Werror "$@" >> config.log
84    $compiler -Werror "$@" >> config.log 2>&1 && return $?
85    error_exit "configure test passed without -Werror but failed with -Werror." \
86        "This is probably a bug in the configure script. The failing command" \
87        "will be at the bottom of config.log." \
88        "You can run configure with --disable-werror to bypass this check."
89}
90
91do_cc() {
92    do_compiler "$cc" "$@"
93}
94
95do_cxx() {
96    do_compiler "$cxx" "$@"
97}
98
99update_cxxflags() {
100    # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
101    # options which some versions of GCC's C++ compiler complain about
102    # because they only make sense for C programs.
103    QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS"
104
105    for arg in $QEMU_CFLAGS; do
106        case $arg in
107            -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
108            -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
109                ;;
110            *)
111                QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
112                ;;
113        esac
114    done
115}
116
117compile_object() {
118  local_cflags="$1"
119  do_cc $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
120}
121
122compile_prog() {
123  local_cflags="$1"
124  local_ldflags="$2"
125  do_cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
126}
127
128# symbolically link $1 to $2.  Portable version of "ln -sf".
129symlink() {
130  rm -rf "$2"
131  mkdir -p "$(dirname "$2")"
132  ln -s "$1" "$2"
133}
134
135# check whether a command is available to this shell (may be either an
136# executable or a builtin)
137has() {
138    type "$1" >/dev/null 2>&1
139}
140
141# search for an executable in PATH
142path_of() {
143    local_command="$1"
144    local_ifs="$IFS"
145    local_dir=""
146
147    # pathname has a dir component?
148    if [ "${local_command#*/}" != "$local_command" ]; then
149        if [ -x "$local_command" ] && [ ! -d "$local_command" ]; then
150            echo "$local_command"
151            return 0
152        fi
153    fi
154    if [ -z "$local_command" ]; then
155        return 1
156    fi
157
158    IFS=:
159    for local_dir in $PATH; do
160        if [ -x "$local_dir/$local_command" ] && [ ! -d "$local_dir/$local_command" ]; then
161            echo "$local_dir/$local_command"
162            IFS="${local_ifs:-$(printf ' \t\n')}"
163            return 0
164        fi
165    done
166    # not found
167    IFS="${local_ifs:-$(printf ' \t\n')}"
168    return 1
169}
170
171have_backend () {
172    echo "$trace_backends" | grep "$1" >/dev/null
173}
174
175glob() {
176    eval test -z '"${1#'"$2"'}"'
177}
178
179supported_hax_target() {
180    test "$hax" = "yes" || return 1
181    glob "$1" "*-softmmu" || return 1
182    case "${1%-softmmu}" in
183        i386|x86_64)
184            return 0
185        ;;
186    esac
187    return 1
188}
189
190supported_kvm_target() {
191    test "$kvm" = "yes" || return 1
192    glob "$1" "*-softmmu" || return 1
193    case "${1%-softmmu}:$cpu" in
194        arm:arm | aarch64:aarch64 | \
195        i386:i386 | i386:x86_64 | i386:x32 | \
196        x86_64:i386 | x86_64:x86_64 | x86_64:x32 | \
197        mips:mips | mipsel:mips | \
198        ppc:ppc | ppcemb:ppc | ppc64:ppc | \
199        ppc:ppc64 | ppcemb:ppc64 | ppc64:ppc64 | \
200        s390x:s390x)
201            return 0
202        ;;
203    esac
204    return 1
205}
206
207supported_xen_target() {
208    test "$xen" = "yes" || return 1
209    glob "$1" "*-softmmu" || return 1
210    # Only i386 and x86_64 provide the xenpv machine.
211    case "${1%-softmmu}" in
212        i386|x86_64)
213            return 0
214        ;;
215    esac
216    return 1
217}
218
219supported_hvf_target() {
220    test "$hvf" = "yes" || return 1
221    glob "$1" "*-softmmu" || return 1
222    case "${1%-softmmu}" in
223        x86_64)
224            return 0
225        ;;
226    esac
227    return 1
228}
229
230supported_whpx_target() {
231    test "$whpx" = "yes" || return 1
232    glob "$1" "*-softmmu" || return 1
233    case "${1%-softmmu}" in
234        i386|x86_64)
235            return 0
236        ;;
237    esac
238    return 1
239}
240
241supported_target() {
242    case "$1" in
243        *-softmmu)
244            ;;
245        *-linux-user)
246            if test "$linux" != "yes"; then
247                print_error "Target '$target' is only available on a Linux host"
248                return 1
249            fi
250            ;;
251        *-bsd-user)
252            if test "$bsd" != "yes"; then
253                print_error "Target '$target' is only available on a BSD host"
254                return 1
255            fi
256            ;;
257        *)
258            print_error "Invalid target name '$target'"
259            return 1
260            ;;
261    esac
262    test "$tcg" = "yes" && return 0
263    supported_kvm_target "$1" && return 0
264    supported_xen_target "$1" && return 0
265    supported_hax_target "$1" && return 0
266    supported_hvf_target "$1" && return 0
267    supported_whpx_target "$1" && return 0
268    print_error "TCG disabled, but hardware accelerator not available for '$target'"
269    return 1
270}
271
272
273ld_has() {
274    $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
275}
276
277# default parameters
278source_path=$(dirname "$0")
279cpu=""
280iasl="iasl"
281interp_prefix="/usr/gnemul/qemu-%M"
282static="no"
283cross_prefix=""
284audio_drv_list=""
285block_drv_rw_whitelist=""
286block_drv_ro_whitelist=""
287host_cc="cc"
288libs_softmmu=""
289libs_tools=""
290audio_pt_int=""
291audio_win_int=""
292libs_qga=""
293debug_info="yes"
294stack_protector=""
295
296if test -e "$source_path/.git"
297then
298    git_update=yes
299    git_submodules="ui/keycodemapdb"
300else
301    git_update=no
302    git_submodules=""
303fi
304git="git"
305
306# Don't accept a target_list environment variable.
307unset target_list
308
309# Default value for a variable defining feature "foo".
310#  * foo="no"  feature will only be used if --enable-foo arg is given
311#  * foo=""    feature will be searched for, and if found, will be used
312#              unless --disable-foo is given
313#  * foo="yes" this value will only be set by --enable-foo flag.
314#              feature will searched for,
315#              if not found, configure exits with error
316#
317# Always add --enable-foo and --disable-foo command line args.
318# Distributions want to ensure that several features are compiled in, and it
319# is impossible without a --enable-foo that exits if a feature is not found.
320
321bluez=""
322brlapi=""
323curl=""
324curses=""
325docs=""
326fdt=""
327netmap="no"
328sdl=""
329sdlabi=""
330virtfs=""
331mpath=""
332vnc="yes"
333sparse="no"
334vde=""
335vnc_sasl=""
336vnc_jpeg=""
337vnc_png=""
338xkbcommon=""
339xen=""
340xen_ctrl_version=""
341xen_pv_domain_build="no"
342xen_pci_passthrough=""
343linux_aio=""
344cap_ng=""
345attr=""
346libattr=""
347xfs=""
348tcg="yes"
349membarrier=""
350vhost_net="no"
351vhost_crypto="no"
352vhost_scsi="no"
353vhost_vsock="no"
354vhost_user=""
355kvm="no"
356hax="no"
357hvf="no"
358whpx="no"
359rdma=""
360gprof="no"
361debug_tcg="no"
362debug="no"
363sanitizers="no"
364fortify_source=""
365strip_opt="yes"
366tcg_interpreter="no"
367bigendian="no"
368mingw32="no"
369gcov="no"
370gcov_tool="gcov"
371EXESUF=""
372DSOSUF=".so"
373LDFLAGS_SHARED="-shared"
374modules="no"
375prefix="/usr/local"
376mandir="\${prefix}/share/man"
377datadir="\${prefix}/share"
378firmwarepath="\${prefix}/share/qemu-firmware"
379qemu_docdir="\${prefix}/share/doc/qemu"
380bindir="\${prefix}/bin"
381libdir="\${prefix}/lib"
382libexecdir="\${prefix}/libexec"
383includedir="\${prefix}/include"
384sysconfdir="\${prefix}/etc"
385local_statedir="\${prefix}/var"
386confsuffix="/qemu"
387slirp="yes"
388oss_lib=""
389bsd="no"
390linux="no"
391solaris="no"
392profiler="no"
393cocoa="no"
394softmmu="yes"
395linux_user="no"
396bsd_user="no"
397blobs="yes"
398pkgversion=""
399pie=""
400qom_cast_debug="yes"
401trace_backends="log"
402trace_file="trace"
403spice=""
404rbd=""
405smartcard=""
406libusb=""
407usb_redir=""
408opengl=""
409opengl_dmabuf="no"
410cpuid_h="no"
411avx2_opt="no"
412zlib="yes"
413capstone=""
414lzo=""
415snappy=""
416bzip2=""
417guest_agent=""
418guest_agent_with_vss="no"
419guest_agent_ntddscsi="no"
420guest_agent_msi=""
421vss_win32_sdk=""
422win_sdk="no"
423want_tools="yes"
424libiscsi=""
425libnfs=""
426coroutine=""
427coroutine_pool=""
428debug_stack_usage="no"
429crypto_afalg="no"
430seccomp=""
431glusterfs=""
432glusterfs_xlator_opt="no"
433glusterfs_discard="no"
434glusterfs_fallocate="no"
435glusterfs_zerofill="no"
436gtk=""
437gtkabi=""
438gtk_gl="no"
439tls_priority="NORMAL"
440gnutls=""
441gnutls_rnd=""
442nettle=""
443nettle_kdf="no"
444gcrypt=""
445gcrypt_hmac="no"
446gcrypt_kdf="no"
447vte=""
448virglrenderer=""
449tpm="yes"
450libssh2=""
451live_block_migration="yes"
452numa=""
453tcmalloc="no"
454jemalloc="no"
455replication="yes"
456vxhs=""
457libxml2=""
458docker="no"
459debug_mutex="no"
460
461# cross compilers defaults, can be overridden with --cross-cc-ARCH
462cross_cc_aarch64="aarch64-linux-gnu-gcc"
463cross_cc_aarch64_be="$cross_cc_aarch64"
464cross_cc_cflags_aarch64_be="-mbig-endian"
465cross_cc_arm="arm-linux-gnueabihf-gcc"
466cross_cc_cflags_armeb="-mbig-endian"
467cross_cc_i386="i386-pc-linux-gnu-gcc"
468cross_cc_cflags_i386=""
469cross_cc_powerpc="powerpc-linux-gnu-gcc"
470cross_cc_powerpc="powerpc-linux-gnu-gcc"
471
472enabled_cross_compilers=""
473
474supported_cpu="no"
475supported_os="no"
476bogus_os="no"
477malloc_trim=""
478
479# parse CC options first
480for opt do
481  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
482  case "$opt" in
483  --cross-prefix=*) cross_prefix="$optarg"
484  ;;
485  --cc=*) CC="$optarg"
486  ;;
487  --cxx=*) CXX="$optarg"
488  ;;
489  --source-path=*) source_path="$optarg"
490  ;;
491  --cpu=*) cpu="$optarg"
492  ;;
493  --extra-cflags=*) QEMU_CFLAGS="$QEMU_CFLAGS $optarg"
494  ;;
495  --extra-cxxflags=*) QEMU_CXXFLAGS="$QEMU_CXXFLAGS $optarg"
496  ;;
497  --extra-ldflags=*) LDFLAGS="$LDFLAGS $optarg"
498                     EXTRA_LDFLAGS="$optarg"
499  ;;
500  --enable-debug-info) debug_info="yes"
501  ;;
502  --disable-debug-info) debug_info="no"
503  ;;
504  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
505  ;;
506  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-flags-}; cc_arch=${cc_arch%%=*}
507                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
508  ;;
509  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
510                eval "cross_cc_${cc_arch}=\$optarg"
511  ;;
512  esac
513done
514# OS specific
515# Using uname is really, really broken.  Once we have the right set of checks
516# we can eliminate its usage altogether.
517
518# Preferred compiler:
519#  ${CC} (if set)
520#  ${cross_prefix}gcc (if cross-prefix specified)
521#  system compiler
522if test -z "${CC}${cross_prefix}"; then
523  cc="$host_cc"
524else
525  cc="${CC-${cross_prefix}gcc}"
526fi
527
528if test -z "${CXX}${cross_prefix}"; then
529  cxx="c++"
530else
531  cxx="${CXX-${cross_prefix}g++}"
532fi
533
534ar="${AR-${cross_prefix}ar}"
535as="${AS-${cross_prefix}as}"
536ccas="${CCAS-$cc}"
537cpp="${CPP-$cc -E}"
538objcopy="${OBJCOPY-${cross_prefix}objcopy}"
539ld="${LD-${cross_prefix}ld}"
540ranlib="${RANLIB-${cross_prefix}ranlib}"
541nm="${NM-${cross_prefix}nm}"
542strip="${STRIP-${cross_prefix}strip}"
543windres="${WINDRES-${cross_prefix}windres}"
544pkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
545query_pkg_config() {
546    "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
547}
548pkg_config=query_pkg_config
549sdl_config="${SDL_CONFIG-${cross_prefix}sdl-config}"
550sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
551
552# If the user hasn't specified ARFLAGS, default to 'rv', just as make does.
553ARFLAGS="${ARFLAGS-rv}"
554
555# default flags for all hosts
556# We use -fwrapv to tell the compiler that we require a C dialect where
557# left shift of signed integers is well defined and has the expected
558# 2s-complement style results. (Both clang and gcc agree that it
559# provides these semantics.)
560QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv $QEMU_CFLAGS"
561QEMU_CFLAGS="-Wall -Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
562QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
563QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
564QEMU_INCLUDES="-iquote . -iquote \$(SRC_PATH) -iquote \$(SRC_PATH)/accel/tcg -iquote \$(SRC_PATH)/include"
565if test "$debug_info" = "yes"; then
566    CFLAGS="-g $CFLAGS"
567    LDFLAGS="-g $LDFLAGS"
568fi
569
570# make source path absolute
571source_path=$(cd "$source_path"; pwd)
572
573# running configure in the source tree?
574# we know that's the case if configure is there.
575if test -f "./configure"; then
576    pwd_is_source_path="y"
577else
578    pwd_is_source_path="n"
579fi
580
581check_define() {
582cat > $TMPC <<EOF
583#if !defined($1)
584#error $1 not defined
585#endif
586int main(void) { return 0; }
587EOF
588  compile_object
589}
590
591check_include() {
592cat > $TMPC <<EOF
593#include <$1>
594int main(void) { return 0; }
595EOF
596  compile_object
597}
598
599write_c_skeleton() {
600    cat > $TMPC <<EOF
601int main(void) { return 0; }
602EOF
603}
604
605if check_define __linux__ ; then
606  targetos="Linux"
607elif check_define _WIN32 ; then
608  targetos='MINGW32'
609elif check_define __OpenBSD__ ; then
610  targetos='OpenBSD'
611elif check_define __sun__ ; then
612  targetos='SunOS'
613elif check_define __HAIKU__ ; then
614  targetos='Haiku'
615elif check_define __FreeBSD__ ; then
616  targetos='FreeBSD'
617elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
618  targetos='GNU/kFreeBSD'
619elif check_define __DragonFly__ ; then
620  targetos='DragonFly'
621elif check_define __NetBSD__; then
622  targetos='NetBSD'
623elif check_define __APPLE__; then
624  targetos='Darwin'
625else
626  # This is a fatal error, but don't report it yet, because we
627  # might be going to just print the --help text, or it might
628  # be the result of a missing compiler.
629  targetos='bogus'
630  bogus_os='yes'
631fi
632
633# Some host OSes need non-standard checks for which CPU to use.
634# Note that these checks are broken for cross-compilation: if you're
635# cross-compiling to one of these OSes then you'll need to specify
636# the correct CPU with the --cpu option.
637case $targetos in
638Darwin)
639  # on Leopard most of the system is 32-bit, so we have to ask the kernel if we can
640  # run 64-bit userspace code.
641  # If the user didn't specify a CPU explicitly and the kernel says this is
642  # 64 bit hw, then assume x86_64. Otherwise fall through to the usual detection code.
643  if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then
644    cpu="x86_64"
645  fi
646  ;;
647SunOS)
648  # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
649  if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
650    cpu="x86_64"
651  fi
652esac
653
654if test ! -z "$cpu" ; then
655  # command line argument
656  :
657elif check_define __i386__ ; then
658  cpu="i386"
659elif check_define __x86_64__ ; then
660  if check_define __ILP32__ ; then
661    cpu="x32"
662  else
663    cpu="x86_64"
664  fi
665elif check_define __sparc__ ; then
666  if check_define __arch64__ ; then
667    cpu="sparc64"
668  else
669    cpu="sparc"
670  fi
671elif check_define _ARCH_PPC ; then
672  if check_define _ARCH_PPC64 ; then
673    cpu="ppc64"
674  else
675    cpu="ppc"
676  fi
677elif check_define __mips__ ; then
678  cpu="mips"
679elif check_define __s390__ ; then
680  if check_define __s390x__ ; then
681    cpu="s390x"
682  else
683    cpu="s390"
684  fi
685elif check_define __arm__ ; then
686  cpu="arm"
687elif check_define __aarch64__ ; then
688  cpu="aarch64"
689else
690  cpu=$(uname -m)
691fi
692
693ARCH=
694# Normalise host CPU name and set ARCH.
695# Note that this case should only have supported host CPUs, not guests.
696case "$cpu" in
697  ppc|ppc64|s390|s390x|sparc64|x32)
698    cpu="$cpu"
699    supported_cpu="yes"
700    eval "cross_cc_${cpu}=\$host_cc"
701  ;;
702  i386|i486|i586|i686|i86pc|BePC)
703    cpu="i386"
704    supported_cpu="yes"
705    cross_cc_i386=$host_cc
706  ;;
707  x86_64|amd64)
708    cpu="x86_64"
709    supported_cpu="yes"
710    cross_cc_x86_64=$host_cc
711  ;;
712  armv*b|armv*l|arm)
713    cpu="arm"
714    supported_cpu="yes"
715    cross_cc_arm=$host_cc
716  ;;
717  aarch64)
718    cpu="aarch64"
719    supported_cpu="yes"
720    cross_cc_aarch64=$host_cc
721  ;;
722  mips*)
723    cpu="mips"
724    supported_cpu="yes"
725    cross_cc_mips=$host_cc
726  ;;
727  sparc|sun4[cdmuv])
728    cpu="sparc"
729    supported_cpu="yes"
730    cross_cc_sparc=$host_cc
731  ;;
732  *)
733    # This will result in either an error or falling back to TCI later
734    ARCH=unknown
735  ;;
736esac
737if test -z "$ARCH"; then
738  ARCH="$cpu"
739fi
740
741# OS specific
742
743# host *BSD for user mode
744HOST_VARIANT_DIR=""
745
746case $targetos in
747MINGW32*)
748  mingw32="yes"
749  hax="yes"
750  audio_possible_drivers="dsound sdl"
751  if check_include dsound.h; then
752    audio_drv_list="dsound"
753  else
754    audio_drv_list=""
755  fi
756  supported_os="yes"
757;;
758GNU/kFreeBSD)
759  bsd="yes"
760  audio_drv_list="oss"
761  audio_possible_drivers="oss sdl pa"
762;;
763FreeBSD)
764  bsd="yes"
765  make="${MAKE-gmake}"
766  audio_drv_list="oss"
767  audio_possible_drivers="oss sdl pa"
768  # needed for kinfo_getvmmap(3) in libutil.h
769  LIBS="-lutil $LIBS"
770  # needed for kinfo_getproc
771  libs_qga="-lutil $libs_qga"
772  netmap=""  # enable netmap autodetect
773  HOST_VARIANT_DIR="freebsd"
774  supported_os="yes"
775;;
776DragonFly)
777  bsd="yes"
778  make="${MAKE-gmake}"
779  audio_drv_list="oss"
780  audio_possible_drivers="oss sdl pa"
781  HOST_VARIANT_DIR="dragonfly"
782;;
783NetBSD)
784  bsd="yes"
785  make="${MAKE-gmake}"
786  audio_drv_list="oss"
787  audio_possible_drivers="oss sdl"
788  oss_lib="-lossaudio"
789  HOST_VARIANT_DIR="netbsd"
790  supported_os="yes"
791;;
792OpenBSD)
793  bsd="yes"
794  make="${MAKE-gmake}"
795  audio_drv_list="sdl"
796  audio_possible_drivers="sdl"
797  HOST_VARIANT_DIR="openbsd"
798  supported_os="yes"
799;;
800Darwin)
801  bsd="yes"
802  darwin="yes"
803  hax="yes"
804  hvf="yes"
805  LDFLAGS_SHARED="-bundle -undefined dynamic_lookup"
806  if [ "$cpu" = "x86_64" ] ; then
807    QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
808    LDFLAGS="-arch x86_64 $LDFLAGS"
809  fi
810  cocoa="yes"
811  audio_drv_list="coreaudio"
812  audio_possible_drivers="coreaudio sdl"
813  LDFLAGS="-framework CoreFoundation -framework IOKit $LDFLAGS"
814  libs_softmmu="-F/System/Library/Frameworks -framework Cocoa -framework IOKit $libs_softmmu"
815  # Disable attempts to use ObjectiveC features in os/object.h since they
816  # won't work when we're compiling with gcc as a C compiler.
817  QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
818  HOST_VARIANT_DIR="darwin"
819  supported_os="yes"
820;;
821SunOS)
822  solaris="yes"
823  make="${MAKE-gmake}"
824  install="${INSTALL-ginstall}"
825  smbd="${SMBD-/usr/sfw/sbin/smbd}"
826  if test -f /usr/include/sys/soundcard.h ; then
827    audio_drv_list="oss"
828  fi
829  audio_possible_drivers="oss sdl"
830# needed for CMSG_ macros in sys/socket.h
831  QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
832# needed for TIOCWIN* defines in termios.h
833  QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
834  QEMU_CFLAGS="-std=gnu99 $QEMU_CFLAGS"
835  solarisnetlibs="-lsocket -lnsl -lresolv"
836  LIBS="$solarisnetlibs $LIBS"
837  libs_qga="$solarisnetlibs $libs_qga"
838;;
839Haiku)
840  haiku="yes"
841  QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS $QEMU_CFLAGS"
842  LIBS="-lposix_error_mapper -lnetwork $LIBS"
843;;
844Linux)
845  audio_drv_list="oss"
846  audio_possible_drivers="oss alsa sdl pa"
847  linux="yes"
848  linux_user="yes"
849  kvm="yes"
850  vhost_net="yes"
851  vhost_crypto="yes"
852  vhost_scsi="yes"
853  vhost_vsock="yes"
854  QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES"
855  supported_os="yes"
856;;
857esac
858
859if [ "$bsd" = "yes" ] ; then
860  if [ "$darwin" != "yes" ] ; then
861    bsd_user="yes"
862  fi
863fi
864
865: ${make=${MAKE-make}}
866: ${install=${INSTALL-install}}
867: ${python=${PYTHON-python}}
868: ${smbd=${SMBD-/usr/sbin/smbd}}
869
870# Default objcc to clang if available, otherwise use CC
871if has clang; then
872  objcc=clang
873else
874  objcc="$cc"
875fi
876
877if test "$mingw32" = "yes" ; then
878  EXESUF=".exe"
879  DSOSUF=".dll"
880  QEMU_CFLAGS="-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 $QEMU_CFLAGS"
881  # enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later)
882  QEMU_CFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $QEMU_CFLAGS"
883  # MinGW needs -mthreads for TLS and macro _MT.
884  QEMU_CFLAGS="-mthreads $QEMU_CFLAGS"
885  LIBS="-lwinmm -lws2_32 -liphlpapi $LIBS"
886  write_c_skeleton;
887  if compile_prog "" "-liberty" ; then
888    LIBS="-liberty $LIBS"
889  fi
890  prefix="c:/Program Files/QEMU"
891  mandir="\${prefix}"
892  datadir="\${prefix}"
893  qemu_docdir="\${prefix}"
894  bindir="\${prefix}"
895  sysconfdir="\${prefix}"
896  local_statedir=
897  confsuffix=""
898  libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi -lnetapi32 $libs_qga"
899fi
900
901werror=""
902
903for opt do
904  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
905  case "$opt" in
906  --help|-h) show_help=yes
907  ;;
908  --version|-V) exec cat $source_path/VERSION
909  ;;
910  --prefix=*) prefix="$optarg"
911  ;;
912  --interp-prefix=*) interp_prefix="$optarg"
913  ;;
914  --source-path=*)
915  ;;
916  --cross-prefix=*)
917  ;;
918  --cc=*)
919  ;;
920  --host-cc=*) host_cc="$optarg"
921  ;;
922  --cxx=*)
923  ;;
924  --iasl=*) iasl="$optarg"
925  ;;
926  --objcc=*) objcc="$optarg"
927  ;;
928  --make=*) make="$optarg"
929  ;;
930  --install=*) install="$optarg"
931  ;;
932  --python=*) python="$optarg"
933  ;;
934  --gcov=*) gcov_tool="$optarg"
935  ;;
936  --smbd=*) smbd="$optarg"
937  ;;
938  --extra-cflags=*)
939  ;;
940  --extra-cxxflags=*)
941  ;;
942  --extra-ldflags=*)
943  ;;
944  --enable-debug-info)
945  ;;
946  --disable-debug-info)
947  ;;
948  --cross-cc-*)
949  ;;
950  --enable-modules)
951      modules="yes"
952  ;;
953  --disable-modules)
954      modules="no"
955  ;;
956  --cpu=*)
957  ;;
958  --target-list=*) target_list="$optarg"
959  ;;
960  --enable-trace-backends=*) trace_backends="$optarg"
961  ;;
962  # XXX: backwards compatibility
963  --enable-trace-backend=*) trace_backends="$optarg"
964  ;;
965  --with-trace-file=*) trace_file="$optarg"
966  ;;
967  --enable-gprof) gprof="yes"
968  ;;
969  --enable-gcov) gcov="yes"
970  ;;
971  --static)
972    static="yes"
973    LDFLAGS="-static $LDFLAGS"
974    QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
975  ;;
976  --mandir=*) mandir="$optarg"
977  ;;
978  --bindir=*) bindir="$optarg"
979  ;;
980  --libdir=*) libdir="$optarg"
981  ;;
982  --libexecdir=*) libexecdir="$optarg"
983  ;;
984  --includedir=*) includedir="$optarg"
985  ;;
986  --datadir=*) datadir="$optarg"
987  ;;
988  --with-confsuffix=*) confsuffix="$optarg"
989  ;;
990  --docdir=*) qemu_docdir="$optarg"
991  ;;
992  --sysconfdir=*) sysconfdir="$optarg"
993  ;;
994  --localstatedir=*) local_statedir="$optarg"
995  ;;
996  --firmwarepath=*) firmwarepath="$optarg"
997  ;;
998  --host=*|--build=*|\
999  --disable-dependency-tracking|\
1000  --sbindir=*|--sharedstatedir=*|\
1001  --oldincludedir=*|--datarootdir=*|--infodir=*|--localedir=*|\
1002  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
1003    # These switches are silently ignored, for compatibility with
1004    # autoconf-generated configure scripts. This allows QEMU's
1005    # configure to be used by RPM and similar macros that set
1006    # lots of directory switches by default.
1007  ;;
1008  --disable-sdl) sdl="no"
1009  ;;
1010  --enable-sdl) sdl="yes"
1011  ;;
1012  --with-sdlabi=*) sdlabi="$optarg"
1013  ;;
1014  --disable-qom-cast-debug) qom_cast_debug="no"
1015  ;;
1016  --enable-qom-cast-debug) qom_cast_debug="yes"
1017  ;;
1018  --disable-virtfs) virtfs="no"
1019  ;;
1020  --enable-virtfs) virtfs="yes"
1021  ;;
1022  --disable-mpath) mpath="no"
1023  ;;
1024  --enable-mpath) mpath="yes"
1025  ;;
1026  --disable-vnc) vnc="no"
1027  ;;
1028  --enable-vnc) vnc="yes"
1029  ;;
1030  --oss-lib=*) oss_lib="$optarg"
1031  ;;
1032  --audio-drv-list=*) audio_drv_list="$optarg"
1033  ;;
1034  --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
1035  ;;
1036  --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
1037  ;;
1038  --enable-debug-tcg) debug_tcg="yes"
1039  ;;
1040  --disable-debug-tcg) debug_tcg="no"
1041  ;;
1042  --enable-debug)
1043      # Enable debugging options that aren't excessively noisy
1044      debug_tcg="yes"
1045      debug_mutex="yes"
1046      debug="yes"
1047      strip_opt="no"
1048      fortify_source="no"
1049  ;;
1050  --enable-sanitizers) sanitizers="yes"
1051  ;;
1052  --disable-sanitizers) sanitizers="no"
1053  ;;
1054  --enable-sparse) sparse="yes"
1055  ;;
1056  --disable-sparse) sparse="no"
1057  ;;
1058  --disable-strip) strip_opt="no"
1059  ;;
1060  --disable-vnc-sasl) vnc_sasl="no"
1061  ;;
1062  --enable-vnc-sasl) vnc_sasl="yes"
1063  ;;
1064  --disable-vnc-jpeg) vnc_jpeg="no"
1065  ;;
1066  --enable-vnc-jpeg) vnc_jpeg="yes"
1067  ;;
1068  --disable-vnc-png) vnc_png="no"
1069  ;;
1070  --enable-vnc-png) vnc_png="yes"
1071  ;;
1072  --disable-slirp) slirp="no"
1073  ;;
1074  --disable-vde) vde="no"
1075  ;;
1076  --enable-vde) vde="yes"
1077  ;;
1078  --disable-netmap) netmap="no"
1079  ;;
1080  --enable-netmap) netmap="yes"
1081  ;;
1082  --disable-xen) xen="no"
1083  ;;
1084  --enable-xen) xen="yes"
1085  ;;
1086  --disable-xen-pci-passthrough) xen_pci_passthrough="no"
1087  ;;
1088  --enable-xen-pci-passthrough) xen_pci_passthrough="yes"
1089  ;;
1090  --disable-xen-pv-domain-build) xen_pv_domain_build="no"
1091  ;;
1092  --enable-xen-pv-domain-build) xen_pv_domain_build="yes"
1093  ;;
1094  --disable-brlapi) brlapi="no"
1095  ;;
1096  --enable-brlapi) brlapi="yes"
1097  ;;
1098  --disable-bluez) bluez="no"
1099  ;;
1100  --enable-bluez) bluez="yes"
1101  ;;
1102  --disable-kvm) kvm="no"
1103  ;;
1104  --enable-kvm) kvm="yes"
1105  ;;
1106  --disable-hax) hax="no"
1107  ;;
1108  --enable-hax) hax="yes"
1109  ;;
1110  --disable-hvf) hvf="no"
1111  ;;
1112  --enable-hvf) hvf="yes"
1113  ;;
1114  --disable-whpx) whpx="no"
1115  ;;
1116  --enable-whpx) whpx="yes"
1117  ;;
1118  --disable-tcg-interpreter) tcg_interpreter="no"
1119  ;;
1120  --enable-tcg-interpreter) tcg_interpreter="yes"
1121  ;;
1122  --disable-cap-ng)  cap_ng="no"
1123  ;;
1124  --enable-cap-ng) cap_ng="yes"
1125  ;;
1126  --disable-tcg) tcg="no"
1127  ;;
1128  --enable-tcg) tcg="yes"
1129  ;;
1130  --disable-malloc-trim) malloc_trim="no"
1131  ;;
1132  --enable-malloc-trim) malloc_trim="yes"
1133  ;;
1134  --disable-spice) spice="no"
1135  ;;
1136  --enable-spice) spice="yes"
1137  ;;
1138  --disable-libiscsi) libiscsi="no"
1139  ;;
1140  --enable-libiscsi) libiscsi="yes"
1141  ;;
1142  --disable-libnfs) libnfs="no"
1143  ;;
1144  --enable-libnfs) libnfs="yes"
1145  ;;
1146  --enable-profiler) profiler="yes"
1147  ;;
1148  --disable-cocoa) cocoa="no"
1149  ;;
1150  --enable-cocoa)
1151      cocoa="yes" ;
1152      audio_drv_list="coreaudio $(echo $audio_drv_list | sed s,coreaudio,,g)"
1153  ;;
1154  --disable-system) softmmu="no"
1155  ;;
1156  --enable-system) softmmu="yes"
1157  ;;
1158  --disable-user)
1159      linux_user="no" ;
1160      bsd_user="no" ;
1161  ;;
1162  --enable-user) ;;
1163  --disable-linux-user) linux_user="no"
1164  ;;
1165  --enable-linux-user) linux_user="yes"
1166  ;;
1167  --disable-bsd-user) bsd_user="no"
1168  ;;
1169  --enable-bsd-user) bsd_user="yes"
1170  ;;
1171  --enable-pie) pie="yes"
1172  ;;
1173  --disable-pie) pie="no"
1174  ;;
1175  --enable-werror) werror="yes"
1176  ;;
1177  --disable-werror) werror="no"
1178  ;;
1179  --enable-stack-protector) stack_protector="yes"
1180  ;;
1181  --disable-stack-protector) stack_protector="no"
1182  ;;
1183  --disable-curses) curses="no"
1184  ;;
1185  --enable-curses) curses="yes"
1186  ;;
1187  --disable-curl) curl="no"
1188  ;;
1189  --enable-curl) curl="yes"
1190  ;;
1191  --disable-fdt) fdt="no"
1192  ;;
1193  --enable-fdt) fdt="yes"
1194  ;;
1195  --disable-linux-aio) linux_aio="no"
1196  ;;
1197  --enable-linux-aio) linux_aio="yes"
1198  ;;
1199  --disable-attr) attr="no"
1200  ;;
1201  --enable-attr) attr="yes"
1202  ;;
1203  --disable-membarrier) membarrier="no"
1204  ;;
1205  --enable-membarrier) membarrier="yes"
1206  ;;
1207  --disable-blobs) blobs="no"
1208  ;;
1209  --with-pkgversion=*) pkgversion="$optarg"
1210  ;;
1211  --with-coroutine=*) coroutine="$optarg"
1212  ;;
1213  --disable-coroutine-pool) coroutine_pool="no"
1214  ;;
1215  --enable-coroutine-pool) coroutine_pool="yes"
1216  ;;
1217  --enable-debug-stack-usage) debug_stack_usage="yes"
1218  ;;
1219  --enable-crypto-afalg) crypto_afalg="yes"
1220  ;;
1221  --disable-crypto-afalg) crypto_afalg="no"
1222  ;;
1223  --disable-docs) docs="no"
1224  ;;
1225  --enable-docs) docs="yes"
1226  ;;
1227  --disable-vhost-net) vhost_net="no"
1228  ;;
1229  --enable-vhost-net) vhost_net="yes"
1230  ;;
1231  --disable-vhost-crypto) vhost_crypto="no"
1232  ;;
1233  --enable-vhost-crypto)
1234      vhost_crypto="yes"
1235      if test "$mingw32" = "yes"; then
1236          error_exit "vhost-crypto isn't available on win32"
1237      fi
1238  ;;
1239  --disable-vhost-scsi) vhost_scsi="no"
1240  ;;
1241  --enable-vhost-scsi) vhost_scsi="yes"
1242  ;;
1243  --disable-vhost-vsock) vhost_vsock="no"
1244  ;;
1245  --enable-vhost-vsock) vhost_vsock="yes"
1246  ;;
1247  --disable-opengl) opengl="no"
1248  ;;
1249  --enable-opengl) opengl="yes"
1250  ;;
1251  --disable-rbd) rbd="no"
1252  ;;
1253  --enable-rbd) rbd="yes"
1254  ;;
1255  --disable-xfsctl) xfs="no"
1256  ;;
1257  --enable-xfsctl) xfs="yes"
1258  ;;
1259  --disable-smartcard) smartcard="no"
1260  ;;
1261  --enable-smartcard) smartcard="yes"
1262  ;;
1263  --disable-libusb) libusb="no"
1264  ;;
1265  --enable-libusb) libusb="yes"
1266  ;;
1267  --disable-usb-redir) usb_redir="no"
1268  ;;
1269  --enable-usb-redir) usb_redir="yes"
1270  ;;
1271  --disable-zlib-test) zlib="no"
1272  ;;
1273  --disable-lzo) lzo="no"
1274  ;;
1275  --enable-lzo) lzo="yes"
1276  ;;
1277  --disable-snappy) snappy="no"
1278  ;;
1279  --enable-snappy) snappy="yes"
1280  ;;
1281  --disable-bzip2) bzip2="no"
1282  ;;
1283  --enable-bzip2) bzip2="yes"
1284  ;;
1285  --enable-guest-agent) guest_agent="yes"
1286  ;;
1287  --disable-guest-agent) guest_agent="no"
1288  ;;
1289  --enable-guest-agent-msi) guest_agent_msi="yes"
1290  ;;
1291  --disable-guest-agent-msi) guest_agent_msi="no"
1292  ;;
1293  --with-vss-sdk) vss_win32_sdk=""
1294  ;;
1295  --with-vss-sdk=*) vss_win32_sdk="$optarg"
1296  ;;
1297  --without-vss-sdk) vss_win32_sdk="no"
1298  ;;
1299  --with-win-sdk) win_sdk=""
1300  ;;
1301  --with-win-sdk=*) win_sdk="$optarg"
1302  ;;
1303  --without-win-sdk) win_sdk="no"
1304  ;;
1305  --enable-tools) want_tools="yes"
1306  ;;
1307  --disable-tools) want_tools="no"
1308  ;;
1309  --enable-seccomp) seccomp="yes"
1310  ;;
1311  --disable-seccomp) seccomp="no"
1312  ;;
1313  --disable-glusterfs) glusterfs="no"
1314  ;;
1315  --enable-glusterfs) glusterfs="yes"
1316  ;;
1317  --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
1318      echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
1319  ;;
1320  --enable-vhdx|--disable-vhdx)
1321      echo "$0: $opt is obsolete, VHDX driver is always built" >&2
1322  ;;
1323  --enable-uuid|--disable-uuid)
1324      echo "$0: $opt is obsolete, UUID support is always built" >&2
1325  ;;
1326  --disable-gtk) gtk="no"
1327  ;;
1328  --enable-gtk) gtk="yes"
1329  ;;
1330  --tls-priority=*) tls_priority="$optarg"
1331  ;;
1332  --disable-gnutls) gnutls="no"
1333  ;;
1334  --enable-gnutls) gnutls="yes"
1335  ;;
1336  --disable-nettle) nettle="no"
1337  ;;
1338  --enable-nettle) nettle="yes"
1339  ;;
1340  --disable-gcrypt) gcrypt="no"
1341  ;;
1342  --enable-gcrypt) gcrypt="yes"
1343  ;;
1344  --enable-rdma) rdma="yes"
1345  ;;
1346  --disable-rdma) rdma="no"
1347  ;;
1348  --with-gtkabi=*) gtkabi="$optarg"
1349  ;;
1350  --disable-vte) vte="no"
1351  ;;
1352  --enable-vte) vte="yes"
1353  ;;
1354  --disable-virglrenderer) virglrenderer="no"
1355  ;;
1356  --enable-virglrenderer) virglrenderer="yes"
1357  ;;
1358  --disable-tpm) tpm="no"
1359  ;;
1360  --enable-tpm) tpm="yes"
1361  ;;
1362  --disable-libssh2) libssh2="no"
1363  ;;
1364  --enable-libssh2) libssh2="yes"
1365  ;;
1366  --disable-live-block-migration) live_block_migration="no"
1367  ;;
1368  --enable-live-block-migration) live_block_migration="yes"
1369  ;;
1370  --disable-numa) numa="no"
1371  ;;
1372  --enable-numa) numa="yes"
1373  ;;
1374  --disable-libxml2) libxml2="no"
1375  ;;
1376  --enable-libxml2) libxml2="yes"
1377  ;;
1378  --disable-tcmalloc) tcmalloc="no"
1379  ;;
1380  --enable-tcmalloc) tcmalloc="yes"
1381  ;;
1382  --disable-jemalloc) jemalloc="no"
1383  ;;
1384  --enable-jemalloc) jemalloc="yes"
1385  ;;
1386  --disable-replication) replication="no"
1387  ;;
1388  --enable-replication) replication="yes"
1389  ;;
1390  --disable-vxhs) vxhs="no"
1391  ;;
1392  --enable-vxhs) vxhs="yes"
1393  ;;
1394  --disable-vhost-user) vhost_user="no"
1395  ;;
1396  --enable-vhost-user)
1397      vhost_user="yes"
1398      if test "$mingw32" = "yes"; then
1399          error_exit "vhost-user isn't available on win32"
1400      fi
1401  ;;
1402  --disable-capstone) capstone="no"
1403  ;;
1404  --enable-capstone) capstone="yes"
1405  ;;
1406  --enable-capstone=git) capstone="git"
1407  ;;
1408  --enable-capstone=system) capstone="system"
1409  ;;
1410  --with-git=*) git="$optarg"
1411  ;;
1412  --enable-git-update) git_update=yes
1413  ;;
1414  --disable-git-update) git_update=no
1415  ;;
1416  --enable-debug-mutex) debug_mutex=yes
1417  ;;
1418  --disable-debug-mutex) debug_mutex=no
1419  ;;
1420  *)
1421      echo "ERROR: unknown option $opt"
1422      echo "Try '$0 --help' for more information"
1423      exit 1
1424  ;;
1425  esac
1426done
1427
1428if test "$vhost_user" = ""; then
1429    if test "$mingw32" = "yes"; then
1430        vhost_user="no"
1431    else
1432        vhost_user="yes"
1433    fi
1434fi
1435
1436case "$cpu" in
1437    ppc)
1438           CPU_CFLAGS="-m32"
1439           LDFLAGS="-m32 $LDFLAGS"
1440           cross_cc_powerpc=$cc
1441           cross_cc_cflags_powerpc=$CPU_CFLAGS
1442           ;;
1443    ppc64)
1444           CPU_CFLAGS="-m64"
1445           LDFLAGS="-m64 $LDFLAGS"
1446           cross_cc_ppc64=$cc
1447           cross_cc_cflags_ppc64=$CPU_CFLAGS
1448           ;;
1449    sparc)
1450           CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc"
1451           LDFLAGS="-m32 -mv8plus $LDFLAGS"
1452           cross_cc_sparc=$cc
1453           cross_cc_cflags_sparc=$CPU_CFLAGS
1454           ;;
1455    sparc64)
1456           CPU_CFLAGS="-m64 -mcpu=ultrasparc"
1457           LDFLAGS="-m64 $LDFLAGS"
1458           cross_cc_sparc64=$cc
1459           cross_cc_cflags_sparc64=$CPU_CFLAGS
1460           ;;
1461    s390)
1462           CPU_CFLAGS="-m31"
1463           LDFLAGS="-m31 $LDFLAGS"
1464           cross_cc_s390=$cc
1465           cross_cc_cflags_s390=$CPU_CFLAGS
1466           ;;
1467    s390x)
1468           CPU_CFLAGS="-m64"
1469           LDFLAGS="-m64 $LDFLAGS"
1470           cross_cc_s390x=$cc
1471           cross_cc_cflags_s390x=$CPU_CFLAGS
1472           ;;
1473    i386)
1474           CPU_CFLAGS="-m32"
1475           LDFLAGS="-m32 $LDFLAGS"
1476           cross_cc_i386=$cc
1477           cross_cc_cflags_i386=$CPU_CFLAGS
1478           ;;
1479    x86_64)
1480           # ??? Only extremely old AMD cpus do not have cmpxchg16b.
1481           # If we truly care, we should simply detect this case at
1482           # runtime and generate the fallback to serial emulation.
1483           CPU_CFLAGS="-m64 -mcx16"
1484           LDFLAGS="-m64 $LDFLAGS"
1485           cross_cc_x86_64=$cc
1486           cross_cc_cflags_x86_64=$CPU_CFLAGS
1487           ;;
1488    x32)
1489           CPU_CFLAGS="-mx32"
1490           LDFLAGS="-mx32 $LDFLAGS"
1491           cross_cc_i386=$cc
1492           cross_cc_cflags_i386=$CPU_CFLAGS
1493           ;;
1494    # No special flags required for other host CPUs
1495esac
1496
1497QEMU_CFLAGS="$CPU_CFLAGS $QEMU_CFLAGS"
1498
1499# For user-mode emulation the host arch has to be one we explicitly
1500# support, even if we're using TCI.
1501if [ "$ARCH" = "unknown" ]; then
1502  bsd_user="no"
1503  linux_user="no"
1504fi
1505
1506default_target_list=""
1507
1508mak_wilds=""
1509
1510if [ "$softmmu" = "yes" ]; then
1511    mak_wilds="${mak_wilds} $source_path/default-configs/*-softmmu.mak"
1512fi
1513if [ "$linux_user" = "yes" ]; then
1514    mak_wilds="${mak_wilds} $source_path/default-configs/*-linux-user.mak"
1515fi
1516if [ "$bsd_user" = "yes" ]; then
1517    mak_wilds="${mak_wilds} $source_path/default-configs/*-bsd-user.mak"
1518fi
1519
1520for config in $mak_wilds; do
1521    default_target_list="${default_target_list} $(basename "$config" .mak)"
1522done
1523
1524# Enumerate public trace backends for --help output
1525trace_backend_list=$(echo $(grep -le '^PUBLIC = True$' "$source_path"/scripts/tracetool/backend/*.py | sed -e 's/^.*\/\(.*\)\.py$/\1/'))
1526
1527if test x"$show_help" = x"yes" ; then
1528cat << EOF
1529
1530Usage: configure [options]
1531Options: [defaults in brackets after descriptions]
1532
1533Standard options:
1534  --help                   print this message
1535  --prefix=PREFIX          install in PREFIX [$prefix]
1536  --interp-prefix=PREFIX   where to find shared libraries, etc.
1537                           use %M for cpu name [$interp_prefix]
1538  --target-list=LIST       set target list (default: build everything)
1539$(echo Available targets: $default_target_list | \
1540  fold -s -w 53 | sed -e 's/^/                           /')
1541
1542Advanced options (experts only):
1543  --source-path=PATH       path of source code [$source_path]
1544  --cross-prefix=PREFIX    use PREFIX for compile tools [$cross_prefix]
1545  --cc=CC                  use C compiler CC [$cc]
1546  --iasl=IASL              use ACPI compiler IASL [$iasl]
1547  --host-cc=CC             use C compiler CC [$host_cc] for code run at
1548                           build time
1549  --cxx=CXX                use C++ compiler CXX [$cxx]
1550  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
1551  --extra-cflags=CFLAGS    append extra C compiler flags QEMU_CFLAGS
1552  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags QEMU_CXXFLAGS
1553  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
1554  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
1555  --cross-cc-flags-ARCH=   use compiler flags when building ARCH guest tests
1556  --make=MAKE              use specified make [$make]
1557  --install=INSTALL        use specified install [$install]
1558  --python=PYTHON          use specified python [$python]
1559  --smbd=SMBD              use specified smbd [$smbd]
1560  --with-git=GIT           use specified git [$git]
1561  --static                 enable static build [$static]
1562  --mandir=PATH            install man pages in PATH
1563  --datadir=PATH           install firmware in PATH$confsuffix
1564  --docdir=PATH            install documentation in PATH$confsuffix
1565  --bindir=PATH            install binaries in PATH
1566  --libdir=PATH            install libraries in PATH
1567  --libexecdir=PATH        install helper binaries in PATH
1568  --sysconfdir=PATH        install config in PATH$confsuffix
1569  --localstatedir=PATH     install local state in PATH (set at runtime on win32)
1570  --firmwarepath=PATH      search PATH for firmware files
1571  --with-confsuffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir [$confsuffix]
1572  --with-pkgversion=VERS   use specified string as sub-version of the package
1573  --enable-debug           enable common debug build options
1574  --enable-sanitizers      enable default sanitizers
1575  --disable-strip          disable stripping binaries
1576  --disable-werror         disable compilation abort on warning
1577  --disable-stack-protector disable compiler-provided stack protection
1578  --audio-drv-list=LIST    set audio drivers list:
1579                           Available drivers: $audio_possible_drivers
1580  --block-drv-whitelist=L  Same as --block-drv-rw-whitelist=L
1581  --block-drv-rw-whitelist=L
1582                           set block driver read-write whitelist
1583                           (affects only QEMU, not qemu-img)
1584  --block-drv-ro-whitelist=L
1585                           set block driver read-only whitelist
1586                           (affects only QEMU, not qemu-img)
1587  --enable-trace-backends=B Set trace backend
1588                           Available backends: $trace_backend_list
1589  --with-trace-file=NAME   Full PATH,NAME of file to store traces
1590                           Default:trace-<pid>
1591  --disable-slirp          disable SLIRP userspace network connectivity
1592  --enable-tcg-interpreter enable TCG with bytecode interpreter (TCI)
1593  --enable-malloc-trim     enable libc malloc_trim() for memory optimization
1594  --oss-lib                path to OSS library
1595  --cpu=CPU                Build for host CPU [$cpu]
1596  --with-coroutine=BACKEND coroutine backend. Supported options:
1597                           ucontext, sigaltstack, windows
1598  --enable-gcov            enable test coverage analysis with gcov
1599  --gcov=GCOV              use specified gcov [$gcov_tool]
1600  --disable-blobs          disable installing provided firmware blobs
1601  --with-vss-sdk=SDK-path  enable Windows VSS support in QEMU Guest Agent
1602  --with-win-sdk=SDK-path  path to Windows Platform SDK (to build VSS .tlb)
1603  --tls-priority           default TLS protocol/cipher priority string
1604  --enable-gprof           QEMU profiling with gprof
1605  --enable-profiler        profiler support
1606  --enable-xen-pv-domain-build
1607                           xen pv domain builder
1608  --enable-debug-stack-usage
1609                           track the maximum stack usage of stacks created by qemu_alloc_stack
1610
1611Optional features, enabled with --enable-FEATURE and
1612disabled with --disable-FEATURE, default is enabled if available:
1613
1614  system          all system emulation targets
1615  user            supported user emulation targets
1616  linux-user      all linux usermode emulation targets
1617  bsd-user        all BSD usermode emulation targets
1618  docs            build documentation
1619  guest-agent     build the QEMU Guest Agent
1620  guest-agent-msi build guest agent Windows MSI installation package
1621  pie             Position Independent Executables
1622  modules         modules support
1623  debug-tcg       TCG debugging (default is disabled)
1624  debug-info      debugging information
1625  sparse          sparse checker
1626
1627  gnutls          GNUTLS cryptography support
1628  nettle          nettle cryptography support
1629  gcrypt          libgcrypt cryptography support
1630  sdl             SDL UI
1631  --with-sdlabi     select preferred SDL ABI 1.2 or 2.0
1632  gtk             gtk UI
1633  --with-gtkabi     select preferred GTK ABI 2.0 or 3.0
1634  vte             vte support for the gtk UI
1635  curses          curses UI
1636  vnc             VNC UI support
1637  vnc-sasl        SASL encryption for VNC server
1638  vnc-jpeg        JPEG lossy compression for VNC server
1639  vnc-png         PNG compression for VNC server
1640  cocoa           Cocoa UI (Mac OS X only)
1641  virtfs          VirtFS
1642  mpath           Multipath persistent reservation passthrough
1643  xen             xen backend driver support
1644  xen-pci-passthrough    PCI passthrough support for Xen
1645  brlapi          BrlAPI (Braile)
1646  curl            curl connectivity
1647  membarrier      membarrier system call (for Linux 4.14+ or Windows)
1648  fdt             fdt device tree
1649  bluez           bluez stack connectivity
1650  kvm             KVM acceleration support
1651  hax             HAX acceleration support
1652  hvf             Hypervisor.framework acceleration support
1653  whpx            Windows Hypervisor Platform acceleration support
1654  rdma            Enable RDMA-based migration and PVRDMA support
1655  vde             support for vde network
1656  netmap          support for netmap network
1657  linux-aio       Linux AIO support
1658  cap-ng          libcap-ng support
1659  attr            attr and xattr support
1660  vhost-net       vhost-net acceleration support
1661  vhost-crypto    vhost-crypto acceleration support
1662  spice           spice
1663  rbd             rados block device (rbd)
1664  libiscsi        iscsi support
1665  libnfs          nfs support
1666  smartcard       smartcard support (libcacard)
1667  libusb          libusb (for usb passthrough)
1668  live-block-migration   Block migration in the main migration stream
1669  usb-redir       usb network redirection support
1670  lzo             support of lzo compression library
1671  snappy          support of snappy compression library
1672  bzip2           support of bzip2 compression library
1673                  (for reading bzip2-compressed dmg images)
1674  seccomp         seccomp support
1675  coroutine-pool  coroutine freelist (better performance)
1676  glusterfs       GlusterFS backend
1677  tpm             TPM support
1678  libssh2         ssh block device support
1679  numa            libnuma support
1680  libxml2         for Parallels image format
1681  tcmalloc        tcmalloc support
1682  jemalloc        jemalloc support
1683  replication     replication support
1684  vhost-vsock     virtio sockets device support
1685  opengl          opengl support
1686  virglrenderer   virgl rendering support
1687  xfsctl          xfsctl support
1688  qom-cast-debug  cast debugging support
1689  tools           build qemu-io, qemu-nbd and qemu-image tools
1690  vxhs            Veritas HyperScale vDisk backend support
1691  crypto-afalg    Linux AF_ALG crypto backend driver
1692  vhost-user      vhost-user support
1693  capstone        capstone disassembler support
1694  debug-mutex     mutex debugging support
1695
1696NOTE: The object files are built at the place where configure is launched
1697EOF
1698exit 0
1699fi
1700
1701if ! has $python; then
1702  error_exit "Python not found. Use --python=/path/to/python"
1703fi
1704
1705# Note that if the Python conditional here evaluates True we will exit
1706# with status 1 which is a shell 'false' value.
1707if ! $python -c 'import sys; sys.exit(sys.version_info < (2,7))'; then
1708  error_exit "Cannot use '$python', Python 2 >= 2.7 or Python 3 is required." \
1709      "Use --python=/path/to/python to specify a supported Python."
1710fi
1711
1712# Suppress writing compiled files
1713python="$python -B"
1714
1715# Check that the C compiler works. Doing this here before testing
1716# the host CPU ensures that we had a valid CC to autodetect the
1717# $cpu var (and we should bail right here if that's not the case).
1718# It also allows the help message to be printed without a CC.
1719write_c_skeleton;
1720if compile_object ; then
1721  : C compiler works ok
1722else
1723    error_exit "\"$cc\" either does not exist or does not work"
1724fi
1725if ! compile_prog ; then
1726    error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
1727fi
1728
1729# Now we have handled --enable-tcg-interpreter and know we're not just
1730# printing the help message, bail out if the host CPU isn't supported.
1731if test "$ARCH" = "unknown"; then
1732    if test "$tcg_interpreter" = "yes" ; then
1733        echo "Unsupported CPU = $cpu, will use TCG with TCI (experimental)"
1734    else
1735        error_exit "Unsupported CPU = $cpu, try --enable-tcg-interpreter"
1736    fi
1737fi
1738
1739# Consult white-list to determine whether to enable werror
1740# by default.  Only enable by default for git builds
1741if test -z "$werror" ; then
1742    if test -d "$source_path/.git" -a \
1743        \( "$linux" = "yes" -o "$mingw32" = "yes" \) ; then
1744        werror="yes"
1745    else
1746        werror="no"
1747    fi
1748fi
1749
1750if test "$bogus_os" = "yes"; then
1751    # Now that we know that we're not printing the help and that
1752    # the compiler works (so the results of the check_defines we used
1753    # to identify the OS are reliable), if we didn't recognize the
1754    # host OS we should stop now.
1755    error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1756fi
1757
1758gcc_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits"
1759gcc_flags="-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers $gcc_flags"
1760gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
1761gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags"
1762gcc_flags="-Wno-initializer-overrides -Wexpansion-to-defined $gcc_flags"
1763gcc_flags="-Wno-string-plus-int $gcc_flags"
1764gcc_flags="-Wno-error=address-of-packed-member $gcc_flags"
1765# Note that we do not add -Werror to gcc_flags here, because that would
1766# enable it for all configure tests. If a configure test failed due
1767# to -Werror this would just silently disable some features,
1768# so it's too error prone.
1769
1770cc_has_warning_flag() {
1771    write_c_skeleton;
1772
1773    # Use the positive sense of the flag when testing for -Wno-wombat
1774    # support (gcc will happily accept the -Wno- form of unknown
1775    # warning options).
1776    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
1777    compile_prog "-Werror $optflag" ""
1778}
1779
1780for flag in $gcc_flags; do
1781    if cc_has_warning_flag $flag ; then
1782        QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1783    fi
1784done
1785
1786if test "$stack_protector" != "no"; then
1787  cat > $TMPC << EOF
1788int main(int argc, char *argv[])
1789{
1790    char arr[64], *p = arr, *c = argv[0];
1791    while (*c) {
1792        *p++ = *c++;
1793    }
1794    return 0;
1795}
1796EOF
1797  gcc_flags="-fstack-protector-strong -fstack-protector-all"
1798  sp_on=0
1799  for flag in $gcc_flags; do
1800    # We need to check both a compile and a link, since some compiler
1801    # setups fail only on a .c->.o compile and some only at link time
1802    if do_cc $QEMU_CFLAGS -Werror $flag -c -o $TMPO $TMPC &&
1803       compile_prog "-Werror $flag" ""; then
1804      QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1805      sp_on=1
1806      break
1807    fi
1808  done
1809  if test "$stack_protector" = yes; then
1810    if test $sp_on = 0; then
1811      error_exit "Stack protector not supported"
1812    fi
1813  fi
1814fi
1815
1816# Disable -Wmissing-braces on older compilers that warn even for
1817# the "universal" C zero initializer {0}.
1818cat > $TMPC << EOF
1819struct {
1820  int a[2];
1821} x = {0};
1822EOF
1823if compile_object "-Werror" "" ; then
1824  :
1825else
1826  QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
1827fi
1828
1829# Workaround for http://gcc.gnu.org/PR55489.  Happens with -fPIE/-fPIC and
1830# large functions that use global variables.  The bug is in all releases of
1831# GCC, but it became particularly acute in 4.6.x and 4.7.x.  It is fixed in
1832# 4.7.3 and 4.8.0.  We should be able to delete this at the end of 2013.
1833cat > $TMPC << EOF
1834#if __GNUC__ == 4 && (__GNUC_MINOR__ == 6 || (__GNUC_MINOR__ == 7 && __GNUC_PATCHLEVEL__ <= 2))
1835int main(void) { return 0; }
1836#else
1837#error No bug in this compiler.
1838#endif
1839EOF
1840if compile_prog "-Werror -fno-gcse" "" ; then
1841  TRANSLATE_OPT_CFLAGS=-fno-gcse
1842fi
1843
1844if test "$static" = "yes" ; then
1845  if test "$modules" = "yes" ; then
1846    error_exit "static and modules are mutually incompatible"
1847  fi
1848  if test "$pie" = "yes" ; then
1849    error_exit "static and pie are mutually incompatible"
1850  else
1851    pie="no"
1852  fi
1853fi
1854
1855# Unconditional check for compiler __thread support
1856  cat > $TMPC << EOF
1857static __thread int tls_var;
1858int main(void) { return tls_var; }
1859EOF
1860
1861if ! compile_prog "-Werror" "" ; then
1862    error_exit "Your compiler does not support the __thread specifier for " \
1863	"Thread-Local Storage (TLS). Please upgrade to a version that does."
1864fi
1865
1866if test "$pie" = ""; then
1867  case "$cpu-$targetos" in
1868    i386-Linux|x86_64-Linux|x32-Linux|i386-OpenBSD|x86_64-OpenBSD)
1869      ;;
1870    *)
1871      pie="no"
1872      ;;
1873  esac
1874fi
1875
1876if test "$pie" != "no" ; then
1877  cat > $TMPC << EOF
1878
1879#ifdef __linux__
1880#  define THREAD __thread
1881#else
1882#  define THREAD
1883#endif
1884
1885static THREAD int tls_var;
1886
1887int main(void) { return tls_var; }
1888
1889EOF
1890  if compile_prog "-fPIE -DPIE" "-pie"; then
1891    QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS"
1892    LDFLAGS="-pie $LDFLAGS"
1893    pie="yes"
1894    if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1895      LDFLAGS="-Wl,-z,relro -Wl,-z,now $LDFLAGS"
1896    fi
1897  else
1898    if test "$pie" = "yes"; then
1899      error_exit "PIE not available due to missing toolchain support"
1900    else
1901      echo "Disabling PIE due to missing toolchain support"
1902      pie="no"
1903    fi
1904  fi
1905
1906  if compile_prog "-Werror -fno-pie" "-nopie"; then
1907    CFLAGS_NOPIE="-fno-pie"
1908    LDFLAGS_NOPIE="-nopie"
1909  fi
1910fi
1911
1912##########################################
1913# __sync_fetch_and_and requires at least -march=i486. Many toolchains
1914# use i686 as default anyway, but for those that don't, an explicit
1915# specification is necessary
1916
1917if test "$cpu" = "i386"; then
1918  cat > $TMPC << EOF
1919static int sfaa(int *ptr)
1920{
1921  return __sync_fetch_and_and(ptr, 0);
1922}
1923
1924int main(void)
1925{
1926  int val = 42;
1927  val = __sync_val_compare_and_swap(&val, 0, 1);
1928  sfaa(&val);
1929  return val;
1930}
1931EOF
1932  if ! compile_prog "" "" ; then
1933    QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
1934  fi
1935fi
1936
1937#########################################
1938# Solaris specific configure tool chain decisions
1939
1940if test "$solaris" = "yes" ; then
1941  if has $install; then
1942    :
1943  else
1944    error_exit "Solaris install program not found. Use --install=/usr/ucb/install or" \
1945        "install fileutils from www.blastwave.org using pkg-get -i fileutils" \
1946        "to get ginstall which is used by default (which lives in /opt/csw/bin)"
1947  fi
1948  if test "$(path_of $install)" = "/usr/sbin/install" ; then
1949    error_exit "Solaris /usr/sbin/install is not an appropriate install program." \
1950        "try ginstall from the GNU fileutils available from www.blastwave.org" \
1951        "using pkg-get -i fileutils, or use --install=/usr/ucb/install"
1952  fi
1953  if has ar; then
1954    :
1955  else
1956    if test -f /usr/ccs/bin/ar ; then
1957      error_exit "No path includes ar" \
1958          "Add /usr/ccs/bin to your path and rerun configure"
1959    fi
1960    error_exit "No path includes ar"
1961  fi
1962fi
1963
1964if test -z "${target_list+xxx}" ; then
1965    for target in $default_target_list; do
1966        supported_target $target 2>/dev/null && \
1967            target_list="$target_list $target"
1968    done
1969    target_list="${target_list# }"
1970else
1971    target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1972    for target in $target_list; do
1973        # Check that we recognised the target name; this allows a more
1974        # friendly error message than if we let it fall through.
1975        case " $default_target_list " in
1976            *" $target "*)
1977                ;;
1978            *)
1979                error_exit "Unknown target name '$target'"
1980                ;;
1981        esac
1982        supported_target $target || exit 1
1983    done
1984fi
1985
1986# see if system emulation was really requested
1987case " $target_list " in
1988  *"-softmmu "*) softmmu=yes
1989  ;;
1990  *) softmmu=no
1991  ;;
1992esac
1993
1994feature_not_found() {
1995  feature=$1
1996  remedy=$2
1997
1998  error_exit "User requested feature $feature" \
1999      "configure was not able to find it." \
2000      "$remedy"
2001}
2002
2003# ---
2004# big/little endian test
2005cat > $TMPC << EOF
2006short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
2007short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
2008extern int foo(short *, short *);
2009int main(int argc, char *argv[]) {
2010    return foo(big_endian, little_endian);
2011}
2012EOF
2013
2014if compile_object ; then
2015    if strings -a $TMPO | grep -q BiGeNdIaN ; then
2016        bigendian="yes"
2017    elif strings -a $TMPO | grep -q LiTtLeEnDiAn ; then
2018        bigendian="no"
2019    else
2020        echo big/little test failed
2021    fi
2022else
2023    echo big/little test failed
2024fi
2025
2026##########################################
2027# cocoa implies not SDL or GTK
2028# (the cocoa UI code currently assumes it is always the active UI
2029# and doesn't interact well with other UI frontend code)
2030if test "$cocoa" = "yes"; then
2031    if test "$sdl" = "yes"; then
2032        error_exit "Cocoa and SDL UIs cannot both be enabled at once"
2033    fi
2034    if test "$gtk" = "yes"; then
2035        error_exit "Cocoa and GTK UIs cannot both be enabled at once"
2036    fi
2037    gtk=no
2038    sdl=no
2039fi
2040
2041# Some versions of Mac OS X incorrectly define SIZE_MAX
2042cat > $TMPC << EOF
2043#include <stdint.h>
2044#include <stdio.h>
2045int main(int argc, char *argv[]) {
2046    return printf("%zu", SIZE_MAX);
2047}
2048EOF
2049have_broken_size_max=no
2050if ! compile_object -Werror ; then
2051    have_broken_size_max=yes
2052fi
2053
2054##########################################
2055# L2TPV3 probe
2056
2057cat > $TMPC <<EOF
2058#include <sys/socket.h>
2059#include <linux/ip.h>
2060int main(void) { return sizeof(struct mmsghdr); }
2061EOF
2062if compile_prog "" "" ; then
2063  l2tpv3=yes
2064else
2065  l2tpv3=no
2066fi
2067
2068##########################################
2069# MinGW / Mingw-w64 localtime_r/gmtime_r check
2070
2071if test "$mingw32" = "yes"; then
2072    # Some versions of MinGW / Mingw-w64 lack localtime_r
2073    # and gmtime_r entirely.
2074    #
2075    # Some versions of Mingw-w64 define a macro for
2076    # localtime_r/gmtime_r.
2077    #
2078    # Some versions of Mingw-w64 will define functions
2079    # for localtime_r/gmtime_r, but only if you have
2080    # _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun
2081    # though, unistd.h and pthread.h both define
2082    # that for you.
2083    #
2084    # So this #undef localtime_r and #include <unistd.h>
2085    # are not in fact redundant.
2086cat > $TMPC << EOF
2087#include <unistd.h>
2088#include <time.h>
2089#undef localtime_r
2090int main(void) { localtime_r(NULL, NULL); return 0; }
2091EOF
2092    if compile_prog "" "" ; then
2093        localtime_r="yes"
2094    else
2095        localtime_r="no"
2096    fi
2097fi
2098
2099##########################################
2100# pkg-config probe
2101
2102if ! has "$pkg_config_exe"; then
2103  error_exit "pkg-config binary '$pkg_config_exe' not found"
2104fi
2105
2106##########################################
2107# NPTL probe
2108
2109if test "$linux_user" = "yes"; then
2110  cat > $TMPC <<EOF
2111#include <sched.h>
2112#include <linux/futex.h>
2113int main(void) {
2114#if !defined(CLONE_SETTLS) || !defined(FUTEX_WAIT)
2115#error bork
2116#endif
2117  return 0;
2118}
2119EOF
2120  if ! compile_object ; then
2121    feature_not_found "nptl" "Install glibc and linux kernel headers."
2122  fi
2123fi
2124
2125#########################################
2126# zlib check
2127
2128if test "$zlib" != "no" ; then
2129    cat > $TMPC << EOF
2130#include <zlib.h>
2131int main(void) { zlibVersion(); return 0; }
2132EOF
2133    if compile_prog "" "-lz" ; then
2134        :
2135    else
2136        error_exit "zlib check failed" \
2137            "Make sure to have the zlib libs and headers installed."
2138    fi
2139fi
2140LIBS="$LIBS -lz"
2141
2142##########################################
2143# lzo check
2144
2145if test "$lzo" != "no" ; then
2146    cat > $TMPC << EOF
2147#include <lzo/lzo1x.h>
2148int main(void) { lzo_version(); return 0; }
2149EOF
2150    if compile_prog "" "-llzo2" ; then
2151        libs_softmmu="$libs_softmmu -llzo2"
2152        lzo="yes"
2153    else
2154        if test "$lzo" = "yes"; then
2155            feature_not_found "liblzo2" "Install liblzo2 devel"
2156        fi
2157        lzo="no"
2158    fi
2159fi
2160
2161##########################################
2162# snappy check
2163
2164if test "$snappy" != "no" ; then
2165    cat > $TMPC << EOF
2166#include <snappy-c.h>
2167int main(void) { snappy_max_compressed_length(4096); return 0; }
2168EOF
2169    if compile_prog "" "-lsnappy" ; then
2170        libs_softmmu="$libs_softmmu -lsnappy"
2171        snappy="yes"
2172    else
2173        if test "$snappy" = "yes"; then
2174            feature_not_found "libsnappy" "Install libsnappy devel"
2175        fi
2176        snappy="no"
2177    fi
2178fi
2179
2180##########################################
2181# bzip2 check
2182
2183if test "$bzip2" != "no" ; then
2184    cat > $TMPC << EOF
2185#include <bzlib.h>
2186int main(void) { BZ2_bzlibVersion(); return 0; }
2187EOF
2188    if compile_prog "" "-lbz2" ; then
2189        bzip2="yes"
2190    else
2191        if test "$bzip2" = "yes"; then
2192            feature_not_found "libbzip2" "Install libbzip2 devel"
2193        fi
2194        bzip2="no"
2195    fi
2196fi
2197
2198##########################################
2199# libseccomp check
2200
2201if test "$seccomp" != "no" ; then
2202    case "$cpu" in
2203    i386|x86_64)
2204        libseccomp_minver="2.1.0"
2205        ;;
2206    mips)
2207        libseccomp_minver="2.2.0"
2208        ;;
2209    arm|aarch64)
2210        libseccomp_minver="2.2.3"
2211        ;;
2212    ppc|ppc64|s390x)
2213        libseccomp_minver="2.3.0"
2214        ;;
2215    *)
2216        libseccomp_minver=""
2217        ;;
2218    esac
2219
2220    if test "$libseccomp_minver" != "" &&
2221       $pkg_config --atleast-version=$libseccomp_minver libseccomp ; then
2222        seccomp_cflags="$($pkg_config --cflags libseccomp)"
2223        seccomp_libs="$($pkg_config --libs libseccomp)"
2224        seccomp="yes"
2225    else
2226        if test "$seccomp" = "yes" ; then
2227            if test "$libseccomp_minver" != "" ; then
2228                feature_not_found "libseccomp" \
2229                    "Install libseccomp devel >= $libseccomp_minver"
2230            else
2231                feature_not_found "libseccomp" \
2232                    "libseccomp is not supported for host cpu $cpu"
2233            fi
2234        fi
2235        seccomp="no"
2236    fi
2237fi
2238##########################################
2239# xen probe
2240
2241if test "$xen" != "no" ; then
2242  # Check whether Xen library path is specified via --extra-ldflags to avoid
2243  # overriding this setting with pkg-config output. If not, try pkg-config
2244  # to obtain all needed flags.
2245
2246  if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \
2247     $pkg_config --exists xencontrol ; then
2248    xen_ctrl_version="$(printf '%d%02d%02d' \
2249      $($pkg_config --modversion xencontrol | sed 's/\./ /g') )"
2250    xen=yes
2251    xen_pc="xencontrol xenstore xenguest xenforeignmemory xengnttab"
2252    xen_pc="$xen_pc xenevtchn xendevicemodel"
2253    if $pkg_config --exists xentoolcore; then
2254      xen_pc="$xen_pc xentoolcore"
2255    fi
2256    QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags $xen_pc)"
2257    libs_softmmu="$($pkg_config --libs $xen_pc) $libs_softmmu"
2258    LDFLAGS="$($pkg_config --libs $xen_pc) $LDFLAGS"
2259  else
2260
2261    xen_libs="-lxenstore -lxenctrl -lxenguest"
2262    xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
2263
2264    # First we test whether Xen headers and libraries are available.
2265    # If no, we are done and there is no Xen support.
2266    # If yes, more tests are run to detect the Xen version.
2267
2268    # Xen (any)
2269    cat > $TMPC <<EOF
2270#include <xenctrl.h>
2271int main(void) {
2272  return 0;
2273}
2274EOF
2275    if ! compile_prog "" "$xen_libs" ; then
2276      # Xen not found
2277      if test "$xen" = "yes" ; then
2278        feature_not_found "xen" "Install xen devel"
2279      fi
2280      xen=no
2281
2282    # Xen unstable
2283    elif
2284        cat > $TMPC <<EOF &&
2285#undef XC_WANT_COMPAT_DEVICEMODEL_API
2286#define __XEN_TOOLS__
2287#include <xendevicemodel.h>
2288#include <xenforeignmemory.h>
2289int main(void) {
2290  xendevicemodel_handle *xd;
2291  xenforeignmemory_handle *xfmem;
2292
2293  xd = xendevicemodel_open(0, 0);
2294  xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);
2295
2296  xfmem = xenforeignmemory_open(0, 0);
2297  xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);
2298
2299  return 0;
2300}
2301EOF
2302        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
2303      then
2304      xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
2305      xen_ctrl_version=41100
2306      xen=yes
2307    elif
2308        cat > $TMPC <<EOF &&
2309#undef XC_WANT_COMPAT_MAP_FOREIGN_API
2310#include <xenforeignmemory.h>
2311#include <xentoolcore.h>
2312int main(void) {
2313  xenforeignmemory_handle *xfmem;
2314
2315  xfmem = xenforeignmemory_open(0, 0);
2316  xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
2317  xentoolcore_restrict_all(0);
2318
2319  return 0;
2320}
2321EOF
2322        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
2323      then
2324      xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
2325      xen_ctrl_version=41000
2326      xen=yes
2327    elif
2328        cat > $TMPC <<EOF &&
2329#undef XC_WANT_COMPAT_DEVICEMODEL_API
2330#define __XEN_TOOLS__
2331#include <xendevicemodel.h>
2332int main(void) {
2333  xendevicemodel_handle *xd;
2334
2335  xd = xendevicemodel_open(0, 0);
2336  xendevicemodel_close(xd);
2337
2338  return 0;
2339}
2340EOF
2341        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs"
2342      then
2343      xen_stable_libs="-lxendevicemodel $xen_stable_libs"
2344      xen_ctrl_version=40900
2345      xen=yes
2346    elif
2347        cat > $TMPC <<EOF &&
2348/*
2349 * If we have stable libs the we don't want the libxc compat
2350 * layers, regardless of what CFLAGS we may have been given.
2351 *
2352 * Also, check if xengnttab_grant_copy_segment_t is defined and
2353 * grant copy operation is implemented.
2354 */
2355#undef XC_WANT_COMPAT_EVTCHN_API
2356#undef XC_WANT_COMPAT_GNTTAB_API
2357#undef XC_WANT_COMPAT_MAP_FOREIGN_API
2358#include <xenctrl.h>
2359#include <xenstore.h>
2360#include <xenevtchn.h>
2361#include <xengnttab.h>
2362#include <xenforeignmemory.h>
2363#include <stdint.h>
2364#include <xen/hvm/hvm_info_table.h>
2365#if !defined(HVM_MAX_VCPUS)
2366# error HVM_MAX_VCPUS not defined
2367#endif
2368int main(void) {
2369  xc_interface *xc = NULL;
2370  xenforeignmemory_handle *xfmem;
2371  xenevtchn_handle *xe;
2372  xengnttab_handle *xg;
2373  xen_domain_handle_t handle;
2374  xengnttab_grant_copy_segment_t* seg = NULL;
2375
2376  xs_daemon_open();
2377
2378  xc = xc_interface_open(0, 0, 0);
2379  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2380  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2381  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2382  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2383  xc_domain_create(xc, 0, handle, 0, NULL, NULL);
2384
2385  xfmem = xenforeignmemory_open(0, 0);
2386  xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2387
2388  xe = xenevtchn_open(0, 0);
2389  xenevtchn_fd(xe);
2390
2391  xg = xengnttab_open(0, 0);
2392  xengnttab_grant_copy(xg, 0, seg);
2393
2394  return 0;
2395}
2396EOF
2397        compile_prog "" "$xen_libs $xen_stable_libs"
2398      then
2399      xen_ctrl_version=40800
2400      xen=yes
2401    elif
2402        cat > $TMPC <<EOF &&
2403/*
2404 * If we have stable libs the we don't want the libxc compat
2405 * layers, regardless of what CFLAGS we may have been given.
2406 */
2407#undef XC_WANT_COMPAT_EVTCHN_API
2408#undef XC_WANT_COMPAT_GNTTAB_API
2409#undef XC_WANT_COMPAT_MAP_FOREIGN_API
2410#include <xenctrl.h>
2411#include <xenstore.h>
2412#include <xenevtchn.h>
2413#include <xengnttab.h>
2414#include <xenforeignmemory.h>
2415#include <stdint.h>
2416#include <xen/hvm/hvm_info_table.h>
2417#if !defined(HVM_MAX_VCPUS)
2418# error HVM_MAX_VCPUS not defined
2419#endif
2420int main(void) {
2421  xc_interface *xc = NULL;
2422  xenforeignmemory_handle *xfmem;
2423  xenevtchn_handle *xe;
2424  xengnttab_handle *xg;
2425  xen_domain_handle_t handle;
2426
2427  xs_daemon_open();
2428
2429  xc = xc_interface_open(0, 0, 0);
2430  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2431  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2432  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2433  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2434  xc_domain_create(xc, 0, handle, 0, NULL, NULL);
2435
2436  xfmem = xenforeignmemory_open(0, 0);
2437  xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2438
2439  xe = xenevtchn_open(0, 0);
2440  xenevtchn_fd(xe);
2441
2442  xg = xengnttab_open(0, 0);
2443  xengnttab_map_grant_ref(xg, 0, 0, 0);
2444
2445  return 0;
2446}
2447EOF
2448        compile_prog "" "$xen_libs $xen_stable_libs"
2449      then
2450      xen_ctrl_version=40701
2451      xen=yes
2452    elif
2453        cat > $TMPC <<EOF &&
2454#include <xenctrl.h>
2455#include <stdint.h>
2456int main(void) {
2457  xc_interface *xc = NULL;
2458  xen_domain_handle_t handle;
2459  xc_domain_create(xc, 0, handle, 0, NULL, NULL);
2460  return 0;
2461}
2462EOF
2463        compile_prog "" "$xen_libs"
2464      then
2465      xen_ctrl_version=40700
2466      xen=yes
2467
2468    # Xen 4.6
2469    elif
2470        cat > $TMPC <<EOF &&
2471#include <xenctrl.h>
2472#include <xenstore.h>
2473#include <stdint.h>
2474#include <xen/hvm/hvm_info_table.h>
2475#if !defined(HVM_MAX_VCPUS)
2476# error HVM_MAX_VCPUS not defined
2477#endif
2478int main(void) {
2479  xc_interface *xc;
2480  xs_daemon_open();
2481  xc = xc_interface_open(0, 0, 0);
2482  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2483  xc_gnttab_open(NULL, 0);
2484  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2485  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2486  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2487  xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
2488  return 0;
2489}
2490EOF
2491        compile_prog "" "$xen_libs"
2492      then
2493      xen_ctrl_version=40600
2494      xen=yes
2495
2496    # Xen 4.5
2497    elif
2498        cat > $TMPC <<EOF &&
2499#include <xenctrl.h>
2500#include <xenstore.h>
2501#include <stdint.h>
2502#include <xen/hvm/hvm_info_table.h>
2503#if !defined(HVM_MAX_VCPUS)
2504# error HVM_MAX_VCPUS not defined
2505#endif
2506int main(void) {
2507  xc_interface *xc;
2508  xs_daemon_open();
2509  xc = xc_interface_open(0, 0, 0);
2510  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2511  xc_gnttab_open(NULL, 0);
2512  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2513  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2514  xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
2515  return 0;
2516}
2517EOF
2518        compile_prog "" "$xen_libs"
2519      then
2520      xen_ctrl_version=40500
2521      xen=yes
2522
2523    elif
2524        cat > $TMPC <<EOF &&
2525#include <xenctrl.h>
2526#include <xenstore.h>
2527#include <stdint.h>
2528#include <xen/hvm/hvm_info_table.h>
2529#if !defined(HVM_MAX_VCPUS)
2530# error HVM_MAX_VCPUS not defined
2531#endif
2532int main(void) {
2533  xc_interface *xc;
2534  xs_daemon_open();
2535  xc = xc_interface_open(0, 0, 0);
2536  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2537  xc_gnttab_open(NULL, 0);
2538  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2539  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2540  return 0;
2541}
2542EOF
2543        compile_prog "" "$xen_libs"
2544      then
2545      xen_ctrl_version=40200
2546      xen=yes
2547
2548    else
2549      if test "$xen" = "yes" ; then
2550        feature_not_found "xen (unsupported version)" \
2551                          "Install a supported xen (xen 4.2 or newer)"
2552      fi
2553      xen=no
2554    fi
2555
2556    if test "$xen" = yes; then
2557      if test $xen_ctrl_version -ge 40701  ; then
2558        libs_softmmu="$xen_stable_libs $libs_softmmu"
2559      fi
2560      libs_softmmu="$xen_libs $libs_softmmu"
2561    fi
2562  fi
2563fi
2564
2565if test "$xen_pci_passthrough" != "no"; then
2566  if test "$xen" = "yes" && test "$linux" = "yes"; then
2567    xen_pci_passthrough=yes
2568  else
2569    if test "$xen_pci_passthrough" = "yes"; then
2570      error_exit "User requested feature Xen PCI Passthrough" \
2571          " but this feature requires /sys from Linux"
2572    fi
2573    xen_pci_passthrough=no
2574  fi
2575fi
2576
2577if test "$xen_pv_domain_build" = "yes" &&
2578   test "$xen" != "yes"; then
2579    error_exit "User requested Xen PV domain builder support" \
2580	       "which requires Xen support."
2581fi
2582
2583##########################################
2584# Windows Hypervisor Platform accelerator (WHPX) check
2585if test "$whpx" != "no" ; then
2586    if check_include "WinHvPlatform.h" && check_include "WinHvEmulation.h"; then
2587        whpx="yes"
2588    else
2589        if test "$whpx" = "yes"; then
2590            feature_not_found "WinHvPlatform" "WinHvEmulation is not installed"
2591        fi
2592        whpx="no"
2593    fi
2594fi
2595
2596##########################################
2597# Sparse probe
2598if test "$sparse" != "no" ; then
2599  if has cgcc; then
2600    sparse=yes
2601  else
2602    if test "$sparse" = "yes" ; then
2603      feature_not_found "sparse" "Install sparse binary"
2604    fi
2605    sparse=no
2606  fi
2607fi
2608
2609##########################################
2610# X11 probe
2611if $pkg_config --exists "x11"; then
2612    have_x11=yes
2613    x11_cflags=$($pkg_config --cflags x11)
2614    x11_libs=$($pkg_config --libs x11)
2615fi
2616
2617##########################################
2618# GTK probe
2619
2620if test "$gtk" != "no"; then
2621    if test "$gtkabi" = ""; then
2622        # The GTK ABI was not specified explicitly, so try whether 3.0 is available.
2623        # Use 2.0 as a fallback if that is available.
2624        if $pkg_config --exists "gtk+-3.0 >= 3.0.0"; then
2625            gtkabi=3.0
2626        elif $pkg_config --exists "gtk+-2.0 >= 2.18.0"; then
2627            gtkabi=2.0
2628        else
2629            gtkabi=3.0
2630        fi
2631    fi
2632    gtkpackage="gtk+-$gtkabi"
2633    gtkx11package="gtk+-x11-$gtkabi"
2634    if test "$gtkabi" = "3.0" ; then
2635      gtkversion="3.0.0"
2636    else
2637      gtkversion="2.18.0"
2638    fi
2639    if $pkg_config --exists "$gtkpackage >= $gtkversion"; then
2640        gtk_cflags=$($pkg_config --cflags $gtkpackage)
2641        gtk_libs=$($pkg_config --libs $gtkpackage)
2642        gtk_version=$($pkg_config --modversion $gtkpackage)
2643        if $pkg_config --exists "$gtkx11package >= $gtkversion"; then
2644            need_x11=yes
2645            gtk_cflags="$gtk_cflags $x11_cflags"
2646            gtk_libs="$gtk_libs $x11_libs"
2647        fi
2648        gtk="yes"
2649    elif test "$gtk" = "yes"; then
2650        feature_not_found "gtk" "Install gtk3-devel"
2651    else
2652        gtk="no"
2653    fi
2654fi
2655
2656
2657##########################################
2658# GNUTLS probe
2659
2660gnutls_works() {
2661    # Unfortunately some distros have bad pkg-config information for gnutls
2662    # such that it claims to exist but you get a compiler error if you try
2663    # to use the options returned by --libs. Specifically, Ubuntu for --static
2664    # builds doesn't work:
2665    # https://bugs.launchpad.net/ubuntu/+source/gnutls26/+bug/1478035
2666    #
2667    # So sanity check the cflags/libs before assuming gnutls can be used.
2668    if ! $pkg_config --exists "gnutls"; then
2669        return 1
2670    fi
2671
2672    write_c_skeleton
2673    compile_prog "$($pkg_config --cflags gnutls)" "$($pkg_config --libs gnutls)"
2674}
2675
2676gnutls_gcrypt=no
2677gnutls_nettle=no
2678if test "$gnutls" != "no"; then
2679    if gnutls_works; then
2680        gnutls_cflags=$($pkg_config --cflags gnutls)
2681        gnutls_libs=$($pkg_config --libs gnutls)
2682        libs_softmmu="$gnutls_libs $libs_softmmu"
2683        libs_tools="$gnutls_libs $libs_tools"
2684	QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags"
2685        gnutls="yes"
2686
2687	# gnutls_rnd requires >= 2.11.0
2688	if $pkg_config --exists "gnutls >= 2.11.0"; then
2689	    gnutls_rnd="yes"
2690	else
2691	    gnutls_rnd="no"
2692	fi
2693
2694	if $pkg_config --exists 'gnutls >= 3.0'; then
2695	    gnutls_gcrypt=no
2696	    gnutls_nettle=yes
2697	elif $pkg_config --exists 'gnutls >= 2.12'; then
2698	    case $($pkg_config --libs --static gnutls) in
2699		*gcrypt*)
2700		    gnutls_gcrypt=yes
2701		    gnutls_nettle=no
2702		    ;;
2703		*nettle*)
2704		    gnutls_gcrypt=no
2705		    gnutls_nettle=yes
2706		    ;;
2707		*)
2708		    gnutls_gcrypt=yes
2709		    gnutls_nettle=no
2710		    ;;
2711	    esac
2712	else
2713	    gnutls_gcrypt=yes
2714	    gnutls_nettle=no
2715	fi
2716    elif test "$gnutls" = "yes"; then
2717	feature_not_found "gnutls" "Install gnutls devel"
2718    else
2719        gnutls="no"
2720        gnutls_rnd="no"
2721    fi
2722else
2723    gnutls_rnd="no"
2724fi
2725
2726
2727# If user didn't give a --disable/enable-gcrypt flag,
2728# then mark as disabled if user requested nettle
2729# explicitly, or if gnutls links to nettle
2730if test -z "$gcrypt"
2731then
2732    if test "$nettle" = "yes" || test "$gnutls_nettle" = "yes"
2733    then
2734        gcrypt="no"
2735    fi
2736fi
2737
2738# If user didn't give a --disable/enable-nettle flag,
2739# then mark as disabled if user requested gcrypt
2740# explicitly, or if gnutls links to gcrypt
2741if test -z "$nettle"
2742then
2743    if test "$gcrypt" = "yes" || test "$gnutls_gcrypt" = "yes"
2744    then
2745        nettle="no"
2746    fi
2747fi
2748
2749has_libgcrypt_config() {
2750    if ! has "libgcrypt-config"
2751    then
2752	return 1
2753    fi
2754
2755    if test -n "$cross_prefix"
2756    then
2757	host=$(libgcrypt-config --host)
2758	if test "$host-" != $cross_prefix
2759	then
2760	    return 1
2761	fi
2762    fi
2763
2764    return 0
2765}
2766
2767if test "$gcrypt" != "no"; then
2768    if has_libgcrypt_config; then
2769        gcrypt_cflags=$(libgcrypt-config --cflags)
2770        gcrypt_libs=$(libgcrypt-config --libs)
2771        # Debian has remove -lgpg-error from libgcrypt-config
2772        # as it "spreads unnecessary dependencies" which in
2773        # turn breaks static builds...
2774        if test "$static" = "yes"
2775        then
2776            gcrypt_libs="$gcrypt_libs -lgpg-error"
2777        fi
2778        libs_softmmu="$gcrypt_libs $libs_softmmu"
2779        libs_tools="$gcrypt_libs $libs_tools"
2780        QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags"
2781        gcrypt="yes"
2782        if test -z "$nettle"; then
2783           nettle="no"
2784        fi
2785
2786        cat > $TMPC << EOF
2787#include <gcrypt.h>
2788int main(void) {
2789  gcry_kdf_derive(NULL, 0, GCRY_KDF_PBKDF2,
2790                  GCRY_MD_SHA256,
2791                  NULL, 0, 0, 0, NULL);
2792 return 0;
2793}
2794EOF
2795        if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then
2796            gcrypt_kdf=yes
2797        fi
2798
2799        cat > $TMPC << EOF
2800#include <gcrypt.h>
2801int main(void) {
2802  gcry_mac_hd_t handle;
2803  gcry_mac_open(&handle, GCRY_MAC_HMAC_MD5,
2804                GCRY_MAC_FLAG_SECURE, NULL);
2805  return 0;
2806}
2807EOF
2808        if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then
2809            gcrypt_hmac=yes
2810        fi
2811    else
2812        if test "$gcrypt" = "yes"; then
2813            feature_not_found "gcrypt" "Install gcrypt devel"
2814        else
2815            gcrypt="no"
2816        fi
2817    fi
2818fi
2819
2820
2821if test "$nettle" != "no"; then
2822    if $pkg_config --exists "nettle"; then
2823        nettle_cflags=$($pkg_config --cflags nettle)
2824        nettle_libs=$($pkg_config --libs nettle)
2825        nettle_version=$($pkg_config --modversion nettle)
2826        libs_softmmu="$nettle_libs $libs_softmmu"
2827        libs_tools="$nettle_libs $libs_tools"
2828        QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags"
2829        nettle="yes"
2830
2831        cat > $TMPC << EOF
2832#include <stddef.h>
2833#include <nettle/pbkdf2.h>
2834int main(void) {
2835     pbkdf2_hmac_sha256(8, NULL, 1000, 8, NULL, 8, NULL);
2836     return 0;
2837}
2838EOF
2839        if compile_prog "$nettle_cflags" "$nettle_libs" ; then
2840            nettle_kdf=yes
2841        fi
2842    else
2843        if test "$nettle" = "yes"; then
2844            feature_not_found "nettle" "Install nettle devel"
2845        else
2846            nettle="no"
2847        fi
2848    fi
2849fi
2850
2851if test "$gcrypt" = "yes" && test "$nettle" = "yes"
2852then
2853    error_exit "Only one of gcrypt & nettle can be enabled"
2854fi
2855
2856##########################################
2857# libtasn1 - only for the TLS creds/session test suite
2858
2859tasn1=yes
2860tasn1_cflags=""
2861tasn1_libs=""
2862if $pkg_config --exists "libtasn1"; then
2863    tasn1_cflags=$($pkg_config --cflags libtasn1)
2864    tasn1_libs=$($pkg_config --libs libtasn1)
2865else
2866    tasn1=no
2867fi
2868
2869
2870##########################################
2871# getifaddrs (for tests/test-io-channel-socket )
2872
2873have_ifaddrs_h=yes
2874if ! check_include "ifaddrs.h" ; then
2875  have_ifaddrs_h=no
2876fi
2877
2878##########################################
2879# VTE probe
2880
2881if test "$vte" != "no"; then
2882    if test "$gtkabi" = "3.0"; then
2883      vteminversion="0.32.0"
2884      if $pkg_config --exists "vte-2.91"; then
2885        vtepackage="vte-2.91"
2886      else
2887        vtepackage="vte-2.90"
2888      fi
2889    else
2890      vtepackage="vte"
2891      vteminversion="0.24.0"
2892    fi
2893    if $pkg_config --exists "$vtepackage >= $vteminversion"; then
2894        vte_cflags=$($pkg_config --cflags $vtepackage)
2895        vte_libs=$($pkg_config --libs $vtepackage)
2896        vteversion=$($pkg_config --modversion $vtepackage)
2897        vte="yes"
2898    elif test "$vte" = "yes"; then
2899        if test "$gtkabi" = "3.0"; then
2900            feature_not_found "vte" "Install libvte-2.90/2.91 devel"
2901        else
2902            feature_not_found "vte" "Install libvte devel"
2903        fi
2904    else
2905        vte="no"
2906    fi
2907fi
2908
2909##########################################
2910# SDL probe
2911
2912# Look for sdl configuration program (pkg-config or sdl-config).  Try
2913# sdl-config even without cross prefix, and favour pkg-config over sdl-config.
2914
2915sdl_probe ()
2916{
2917  sdl_too_old=no
2918  if test "$sdlabi" = ""; then
2919      if $pkg_config --exists "sdl2"; then
2920          sdlabi=2.0
2921      elif $pkg_config --exists "sdl"; then
2922          sdlabi=1.2
2923      else
2924          sdlabi=2.0
2925      fi
2926  fi
2927
2928  if test $sdlabi = "2.0"; then
2929      sdl_config=$sdl2_config
2930      sdlname=sdl2
2931      sdlconfigname=sdl2_config
2932  elif test $sdlabi = "1.2"; then
2933      sdlname=sdl
2934      sdlconfigname=sdl_config
2935  else
2936      error_exit "Unknown sdlabi $sdlabi, must be 1.2 or 2.0"
2937  fi
2938
2939  if test "$(basename $sdl_config)" != $sdlconfigname && ! has ${sdl_config}; then
2940    sdl_config=$sdlconfigname
2941  fi
2942
2943  if $pkg_config $sdlname --exists; then
2944    sdlconfig="$pkg_config $sdlname"
2945    sdlversion=$($sdlconfig --modversion 2>/dev/null)
2946  elif has ${sdl_config}; then
2947    sdlconfig="$sdl_config"
2948    sdlversion=$($sdlconfig --version)
2949  else
2950    if test "$sdl" = "yes" ; then
2951      feature_not_found "sdl" "Install SDL2-devel"
2952    fi
2953    sdl=no
2954    # no need to do the rest
2955    return
2956  fi
2957  if test -n "$cross_prefix" && test "$(basename "$sdlconfig")" = sdl-config; then
2958    echo warning: using "\"$sdlconfig\"" to detect cross-compiled sdl >&2
2959  fi
2960
2961  cat > $TMPC << EOF
2962#include <SDL.h>
2963#undef main /* We don't want SDL to override our main() */
2964int main( void ) { return SDL_Init (SDL_INIT_VIDEO); }
2965EOF
2966  sdl_cflags=$($sdlconfig --cflags 2>/dev/null)
2967  sdl_cflags="$sdl_cflags -Wno-undef"  # workaround 2.0.8 bug
2968  if test "$static" = "yes" ; then
2969    if $pkg_config $sdlname --exists; then
2970      sdl_libs=$($pkg_config $sdlname --static --libs 2>/dev/null)
2971    else
2972      sdl_libs=$($sdlconfig --static-libs 2>/dev/null)
2973    fi
2974  else
2975    sdl_libs=$($sdlconfig --libs 2>/dev/null)
2976  fi
2977  if compile_prog "$sdl_cflags" "$sdl_libs" ; then
2978    if test $(echo $sdlversion | sed 's/[^0-9]//g') -lt 121 ; then
2979      sdl_too_old=yes
2980    else
2981      sdl=yes
2982    fi
2983
2984    # static link with sdl ? (note: sdl.pc's --static --libs is broken)
2985    if test "$sdl" = "yes" -a "$static" = "yes" ; then
2986      if test $? = 0 && echo $sdl_libs | grep -- -laa > /dev/null; then
2987         sdl_libs="$sdl_libs $(aalib-config --static-libs 2>/dev/null)"
2988         sdl_cflags="$sdl_cflags $(aalib-config --cflags 2>/dev/null)"
2989      fi
2990      if compile_prog "$sdl_cflags" "$sdl_libs" ; then
2991	:
2992      else
2993        sdl=no
2994      fi
2995    fi # static link
2996  else # sdl not found
2997    if test "$sdl" = "yes" ; then
2998      feature_not_found "sdl" "Install SDL devel"
2999    fi
3000    sdl=no
3001  fi # sdl compile test
3002}
3003
3004if test "$sdl" != "no" ; then
3005  sdl_probe
3006fi
3007
3008if test "$sdl" = "yes" ; then
3009  cat > $TMPC <<EOF
3010#include <SDL.h>
3011#if defined(SDL_VIDEO_DRIVER_X11)
3012#include <X11/XKBlib.h>
3013#else
3014#error No x11 support
3015#endif
3016int main(void) { return 0; }
3017EOF
3018  if compile_prog "$sdl_cflags $x11_cflags" "$sdl_libs $x11_libs" ; then
3019    need_x11=yes
3020    sdl_cflags="$sdl_cflags $x11_cflags"
3021    sdl_libs="$sdl_libs $x11_libs"
3022  fi
3023fi
3024
3025##########################################
3026# RDMA needs OpenFabrics libraries
3027if test "$rdma" != "no" ; then
3028  cat > $TMPC <<EOF
3029#include <rdma/rdma_cma.h>
3030int main(void) { return 0; }
3031EOF
3032  rdma_libs="-lrdmacm -libverbs -libumad"
3033  if compile_prog "" "$rdma_libs" ; then
3034    rdma="yes"
3035    libs_softmmu="$libs_softmmu $rdma_libs"
3036  else
3037    if test "$rdma" = "yes" ; then
3038        error_exit \
3039            " OpenFabrics librdmacm/libibverbs/libibumad not present." \
3040            " Your options:" \
3041            "  (1) Fast: Install infiniband packages (devel) from your distro." \
3042            "  (2) Cleanest: Install libraries from www.openfabrics.org" \
3043            "  (3) Also: Install softiwarp if you don't have RDMA hardware"
3044    fi
3045    rdma="no"
3046  fi
3047fi
3048
3049
3050##########################################
3051# VNC SASL detection
3052if test "$vnc" = "yes" -a "$vnc_sasl" != "no" ; then
3053  cat > $TMPC <<EOF
3054#include <sasl/sasl.h>
3055#include <stdio.h>
3056int main(void) { sasl_server_init(NULL, "qemu"); return 0; }
3057EOF
3058  # Assuming Cyrus-SASL installed in /usr prefix
3059  vnc_sasl_cflags=""
3060  vnc_sasl_libs="-lsasl2"
3061  if compile_prog "$vnc_sasl_cflags" "$vnc_sasl_libs" ; then
3062    vnc_sasl=yes
3063    libs_softmmu="$vnc_sasl_libs $libs_softmmu"
3064    QEMU_CFLAGS="$QEMU_CFLAGS $vnc_sasl_cflags"
3065  else
3066    if test "$vnc_sasl" = "yes" ; then
3067      feature_not_found "vnc-sasl" "Install Cyrus SASL devel"
3068    fi
3069    vnc_sasl=no
3070  fi
3071fi
3072
3073##########################################
3074# VNC JPEG detection
3075if test "$vnc" = "yes" -a "$vnc_jpeg" != "no" ; then
3076cat > $TMPC <<EOF
3077#include <stdio.h>
3078#include <jpeglib.h>
3079int main(void) { struct jpeg_compress_struct s; jpeg_create_compress(&s); return 0; }
3080EOF
3081    vnc_jpeg_cflags=""
3082    vnc_jpeg_libs="-ljpeg"
3083  if compile_prog "$vnc_jpeg_cflags" "$vnc_jpeg_libs" ; then
3084    vnc_jpeg=yes
3085    libs_softmmu="$vnc_jpeg_libs $libs_softmmu"
3086    QEMU_CFLAGS="$QEMU_CFLAGS $vnc_jpeg_cflags"
3087  else
3088    if test "$vnc_jpeg" = "yes" ; then
3089      feature_not_found "vnc-jpeg" "Install libjpeg-turbo devel"
3090    fi
3091    vnc_jpeg=no
3092  fi
3093fi
3094
3095##########################################
3096# VNC PNG detection
3097if test "$vnc" = "yes" -a "$vnc_png" != "no" ; then
3098cat > $TMPC <<EOF
3099//#include <stdio.h>
3100#include <png.h>
3101#include <stddef.h>
3102int main(void) {
3103    png_structp png_ptr;
3104    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
3105    return png_ptr != 0;
3106}
3107EOF
3108  if $pkg_config libpng --exists; then
3109    vnc_png_cflags=$($pkg_config libpng --cflags)
3110    vnc_png_libs=$($pkg_config libpng --libs)
3111  else
3112    vnc_png_cflags=""
3113    vnc_png_libs="-lpng"
3114  fi
3115  if compile_prog "$vnc_png_cflags" "$vnc_png_libs" ; then
3116    vnc_png=yes
3117    libs_softmmu="$vnc_png_libs $libs_softmmu"
3118    QEMU_CFLAGS="$QEMU_CFLAGS $vnc_png_cflags"
3119  else
3120    if test "$vnc_png" = "yes" ; then
3121      feature_not_found "vnc-png" "Install libpng devel"
3122    fi
3123    vnc_png=no
3124  fi
3125fi
3126
3127##########################################
3128# xkbcommon probe
3129if test "$xkbcommon" != "no" ; then
3130  if $pkg_config xkbcommon --exists; then
3131    xkbcommon_cflags=$($pkg_config xkbcommon --cflags)
3132    xkbcommon_libs=$($pkg_config xkbcommon --libs)
3133    xkbcommon=yes
3134  else
3135    if test "$xkbcommon" = "yes" ; then
3136      feature_not_found "xkbcommon" "Install libxkbcommon-devel"
3137    fi
3138    xkbcommon=no
3139  fi
3140fi
3141
3142##########################################
3143# fnmatch() probe, used for ACL routines
3144fnmatch="no"
3145cat > $TMPC << EOF
3146#include <fnmatch.h>
3147int main(void)
3148{
3149    fnmatch("foo", "foo", 0);
3150    return 0;
3151}
3152EOF
3153if compile_prog "" "" ; then
3154   fnmatch="yes"
3155fi
3156
3157##########################################
3158# xfsctl() probe, used for file-posix.c
3159if test "$xfs" != "no" ; then
3160  cat > $TMPC << EOF
3161#include <stddef.h>  /* NULL */
3162#include <xfs/xfs.h>
3163int main(void)
3164{
3165    xfsctl(NULL, 0, 0, NULL);
3166    return 0;
3167}
3168EOF
3169  if compile_prog "" "" ; then
3170    xfs="yes"
3171  else
3172    if test "$xfs" = "yes" ; then
3173      feature_not_found "xfs" "Instal xfsprogs/xfslibs devel"
3174    fi
3175    xfs=no
3176  fi
3177fi
3178
3179##########################################
3180# vde libraries probe
3181if test "$vde" != "no" ; then
3182  vde_libs="-lvdeplug"
3183  cat > $TMPC << EOF
3184#include <libvdeplug.h>
3185int main(void)
3186{
3187    struct vde_open_args a = {0, 0, 0};
3188    char s[] = "";
3189    vde_open(s, s, &a);
3190    return 0;
3191}
3192EOF
3193  if compile_prog "" "$vde_libs" ; then
3194    vde=yes
3195  else
3196    if test "$vde" = "yes" ; then
3197      feature_not_found "vde" "Install vde (Virtual Distributed Ethernet) devel"
3198    fi
3199    vde=no
3200  fi
3201fi
3202
3203##########################################
3204# netmap support probe
3205# Apart from looking for netmap headers, we make sure that the host API version
3206# supports the netmap backend (>=11). The upper bound (15) is meant to simulate
3207# a minor/major version number. Minor new features will be marked with values up
3208# to 15, and if something happens that requires a change to the backend we will
3209# move above 15, submit the backend fixes and modify this two bounds.
3210if test "$netmap" != "no" ; then
3211  cat > $TMPC << EOF
3212#include <inttypes.h>
3213#include <net/if.h>
3214#include <net/netmap.h>
3215#include <net/netmap_user.h>
3216#if (NETMAP_API < 11) || (NETMAP_API > 15)
3217#error
3218#endif
3219int main(void) { return 0; }
3220EOF
3221  if compile_prog "" "" ; then
3222    netmap=yes
3223  else
3224    if test "$netmap" = "yes" ; then
3225      feature_not_found "netmap"
3226    fi
3227    netmap=no
3228  fi
3229fi
3230
3231##########################################
3232# libcap-ng library probe
3233if test "$cap_ng" != "no" ; then
3234  cap_libs="-lcap-ng"
3235  cat > $TMPC << EOF
3236#include <cap-ng.h>
3237int main(void)
3238{
3239    capng_capability_to_name(CAPNG_EFFECTIVE);
3240    return 0;
3241}
3242EOF
3243  if compile_prog "" "$cap_libs" ; then
3244    cap_ng=yes
3245    libs_tools="$cap_libs $libs_tools"
3246  else
3247    if test "$cap_ng" = "yes" ; then
3248      feature_not_found "cap_ng" "Install libcap-ng devel"
3249    fi
3250    cap_ng=no
3251  fi
3252fi
3253
3254##########################################
3255# Sound support libraries probe
3256
3257audio_drv_probe()
3258{
3259    drv=$1
3260    hdr=$2
3261    lib=$3
3262    exp=$4
3263    cfl=$5
3264        cat > $TMPC << EOF
3265#include <$hdr>
3266int main(void) { $exp }
3267EOF
3268    if compile_prog "$cfl" "$lib" ; then
3269        :
3270    else
3271        error_exit "$drv check failed" \
3272            "Make sure to have the $drv libs and headers installed."
3273    fi
3274}
3275
3276audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/,/ /g')
3277for drv in $audio_drv_list; do
3278    case $drv in
3279    alsa)
3280    audio_drv_probe $drv alsa/asoundlib.h -lasound \
3281        "return snd_pcm_close((snd_pcm_t *)0);"
3282    alsa_libs="-lasound"
3283    ;;
3284
3285    pa)
3286    audio_drv_probe $drv pulse/pulseaudio.h "-lpulse" \
3287        "pa_context_set_source_output_volume(NULL, 0, NULL, NULL, NULL); return 0;"
3288    pulse_libs="-lpulse"
3289    audio_pt_int="yes"
3290    ;;
3291
3292    sdl)
3293    if test "$sdl" = "no"; then
3294        error_exit "sdl not found or disabled, can not use sdl audio driver"
3295    fi
3296    ;;
3297
3298    coreaudio)
3299      coreaudio_libs="-framework CoreAudio"
3300    ;;
3301
3302    dsound)
3303      dsound_libs="-lole32 -ldxguid"
3304      audio_win_int="yes"
3305    ;;
3306
3307    oss)
3308      oss_libs="$oss_lib"
3309    ;;
3310
3311    wav)
3312    # XXX: Probes for CoreAudio, DirectSound
3313    ;;
3314
3315    *)
3316    echo "$audio_possible_drivers" | grep -q "\<$drv\>" || {
3317        error_exit "Unknown driver '$drv' selected" \
3318            "Possible drivers are: $audio_possible_drivers"
3319    }
3320    ;;
3321    esac
3322done
3323
3324##########################################
3325# BrlAPI probe
3326
3327if test "$brlapi" != "no" ; then
3328  brlapi_libs="-lbrlapi"
3329  cat > $TMPC << EOF
3330#include <brlapi.h>
3331#include <stddef.h>
3332int main( void ) { return brlapi__openConnection (NULL, NULL, NULL); }
3333EOF
3334  if compile_prog "" "$brlapi_libs" ; then
3335    brlapi=yes
3336  else
3337    if test "$brlapi" = "yes" ; then
3338      feature_not_found "brlapi" "Install brlapi devel"
3339    fi
3340    brlapi=no
3341  fi
3342fi
3343
3344##########################################
3345# curses probe
3346if test "$curses" != "no" ; then
3347  if test "$mingw32" = "yes" ; then
3348    curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null):"
3349    curses_lib_list="$($pkg_config --libs ncurses 2>/dev/null):-lpdcurses"
3350  else
3351    curses_inc_list="$($pkg_config --cflags ncursesw 2>/dev/null):-I/usr/include/ncursesw:"
3352    curses_lib_list="$($pkg_config --libs ncursesw 2>/dev/null):-lncursesw:-lcursesw"
3353  fi
3354  curses_found=no
3355  cat > $TMPC << EOF
3356#include <locale.h>
3357#include <curses.h>
3358#include <wchar.h>
3359int main(void) {
3360  wchar_t wch = L'w';
3361  setlocale(LC_ALL, "");
3362  resize_term(0, 0);
3363  addwstr(L"wide chars\n");
3364  addnwstr(&wch, 1);
3365  add_wch(WACS_DEGREE);
3366  return 0;
3367}
3368EOF
3369  IFS=:
3370  for curses_inc in $curses_inc_list; do
3371    # Make sure we get the wide character prototypes
3372    curses_inc="-DNCURSES_WIDECHAR $curses_inc"
3373    IFS=:
3374    for curses_lib in $curses_lib_list; do
3375      unset IFS
3376      if compile_prog "$curses_inc" "$curses_lib" ; then
3377        curses_found=yes
3378        break
3379      fi
3380    done
3381    if test "$curses_found" = yes ; then
3382      break
3383    fi
3384  done
3385  unset IFS
3386  if test "$curses_found" = "yes" ; then
3387    curses=yes
3388  else
3389    if test "$curses" = "yes" ; then
3390      feature_not_found "curses" "Install ncurses devel"
3391    fi
3392    curses=no
3393  fi
3394fi
3395
3396##########################################
3397# curl probe
3398if test "$curl" != "no" ; then
3399  if $pkg_config libcurl --exists; then
3400    curlconfig="$pkg_config libcurl"
3401  else
3402    curlconfig=curl-config
3403  fi
3404  cat > $TMPC << EOF
3405#include <curl/curl.h>
3406int main(void) { curl_easy_init(); curl_multi_setopt(0, 0, 0); return 0; }
3407EOF
3408  curl_cflags=$($curlconfig --cflags 2>/dev/null)
3409  curl_libs=$($curlconfig --libs 2>/dev/null)
3410  if compile_prog "$curl_cflags" "$curl_libs" ; then
3411    curl=yes
3412  else
3413    if test "$curl" = "yes" ; then
3414      feature_not_found "curl" "Install libcurl devel"
3415    fi
3416    curl=no
3417  fi
3418fi # test "$curl"
3419
3420##########################################
3421# bluez support probe
3422if test "$bluez" != "no" ; then
3423  cat > $TMPC << EOF
3424#include <bluetooth/bluetooth.h>
3425int main(void) { return bt_error(0); }
3426EOF
3427  bluez_cflags=$($pkg_config --cflags bluez 2>/dev/null)
3428  bluez_libs=$($pkg_config --libs bluez 2>/dev/null)
3429  if compile_prog "$bluez_cflags" "$bluez_libs" ; then
3430    bluez=yes
3431    libs_softmmu="$bluez_libs $libs_softmmu"
3432  else
3433    if test "$bluez" = "yes" ; then
3434      feature_not_found "bluez" "Install bluez-libs/libbluetooth devel"
3435    fi
3436    bluez="no"
3437  fi
3438fi
3439
3440##########################################
3441# glib support probe
3442
3443if test "$mingw32" = yes; then
3444    glib_req_ver=2.30
3445else
3446    glib_req_ver=2.22
3447fi
3448glib_modules=gthread-2.0
3449if test "$modules" = yes; then
3450    glib_modules="$glib_modules gmodule-export-2.0"
3451fi
3452
3453# This workaround is required due to a bug in pkg-config file for glib as it
3454# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
3455
3456if test "$static" = yes -a "$mingw32" = yes; then
3457    QEMU_CFLAGS="-DGLIB_STATIC_COMPILATION $QEMU_CFLAGS"
3458fi
3459
3460for i in $glib_modules; do
3461    if $pkg_config --atleast-version=$glib_req_ver $i; then
3462        glib_cflags=$($pkg_config --cflags $i)
3463        glib_libs=$($pkg_config --libs $i)
3464        QEMU_CFLAGS="$glib_cflags $QEMU_CFLAGS"
3465        LIBS="$glib_libs $LIBS"
3466        libs_qga="$glib_libs $libs_qga"
3467    else
3468        error_exit "glib-$glib_req_ver $i is required to compile QEMU"
3469    fi
3470done
3471
3472# Sanity check that the current size_t matches the
3473# size that glib thinks it should be. This catches
3474# problems on multi-arch where people try to build
3475# 32-bit QEMU while pointing at 64-bit glib headers
3476cat > $TMPC <<EOF
3477#include <glib.h>
3478#include <unistd.h>
3479
3480#define QEMU_BUILD_BUG_ON(x) \
3481  typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
3482
3483int main(void) {
3484   QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
3485   return 0;
3486}
3487EOF
3488
3489if ! compile_prog "$CFLAGS" "$LIBS" ; then
3490    error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
3491               "You probably need to set PKG_CONFIG_LIBDIR"\
3492	       "to point to the right pkg-config files for your"\
3493	       "build target"
3494fi
3495
3496# g_test_trap_subprocess added in 2.38. Used by some tests.
3497glib_subprocess=yes
3498if ! $pkg_config --atleast-version=2.38 glib-2.0; then
3499    glib_subprocess=no
3500fi
3501
3502# Silence clang 3.5.0 warnings about glib attribute __alloc_size__ usage
3503cat > $TMPC << EOF
3504#include <glib.h>
3505int main(void) { return 0; }
3506EOF
3507if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
3508    if cc_has_warning_flag "-Wno-unknown-attributes"; then
3509        glib_cflags="-Wno-unknown-attributes $glib_cflags"
3510        CFLAGS="-Wno-unknown-attributes $CFLAGS"
3511    fi
3512fi
3513
3514##########################################
3515# SHA command probe for modules
3516if test "$modules" = yes; then
3517    shacmd_probe="sha1sum sha1 shasum"
3518    for c in $shacmd_probe; do
3519        if has $c; then
3520            shacmd="$c"
3521            break
3522        fi
3523    done
3524    if test "$shacmd" = ""; then
3525        error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
3526    fi
3527fi
3528
3529##########################################
3530# pixman support probe
3531
3532if test "$want_tools" = "no" -a "$softmmu" = "no"; then
3533  pixman_cflags=
3534  pixman_libs=
3535elif $pkg_config --atleast-version=0.21.8 pixman-1 > /dev/null 2>&1; then
3536  pixman_cflags=$($pkg_config --cflags pixman-1)
3537  pixman_libs=$($pkg_config --libs pixman-1)
3538else
3539  error_exit "pixman >= 0.21.8 not present." \
3540      "Please install the pixman devel package."
3541fi
3542
3543##########################################
3544# libmpathpersist probe
3545
3546if test "$mpath" != "no" ; then
3547  cat > $TMPC <<EOF
3548#include <libudev.h>
3549#include <mpath_persist.h>
3550unsigned mpath_mx_alloc_len = 1024;
3551int logsink;
3552static struct config *multipath_conf;
3553extern struct udev *udev;
3554extern struct config *get_multipath_config(void);
3555extern void put_multipath_config(struct config *conf);
3556struct udev *udev;
3557struct config *get_multipath_config(void) { return multipath_conf; }
3558void put_multipath_config(struct config *conf) { }
3559
3560int main(void) {
3561    udev = udev_new();
3562    multipath_conf = mpath_lib_init();
3563    return 0;
3564}
3565EOF
3566  if compile_prog "" "-ludev -lmultipath -lmpathpersist" ; then
3567    mpathpersist=yes
3568  else
3569    mpathpersist=no
3570  fi
3571else
3572  mpathpersist=no
3573fi
3574
3575##########################################
3576# libcap probe
3577
3578if test "$cap" != "no" ; then
3579  cat > $TMPC <<EOF
3580#include <stdio.h>
3581#include <sys/capability.h>
3582int main(void) { cap_t caps; caps = cap_init(); return caps != NULL; }
3583EOF
3584  if compile_prog "" "-lcap" ; then
3585    cap=yes
3586  else
3587    cap=no
3588  fi
3589fi
3590
3591##########################################
3592# pthread probe
3593PTHREADLIBS_LIST="-pthread -lpthread -lpthreadGC2"
3594
3595pthread=no
3596cat > $TMPC << EOF
3597#include <pthread.h>
3598static void *f(void *p) { return NULL; }
3599int main(void) {
3600  pthread_t thread;
3601  pthread_create(&thread, 0, f, 0);
3602  return 0;
3603}
3604EOF
3605if compile_prog "" "" ; then
3606  pthread=yes
3607else
3608  for pthread_lib in $PTHREADLIBS_LIST; do
3609    if compile_prog "" "$pthread_lib" ; then
3610      pthread=yes
3611      found=no
3612      for lib_entry in $LIBS; do
3613        if test "$lib_entry" = "$pthread_lib"; then
3614          found=yes
3615          break
3616        fi
3617      done
3618      if test "$found" = "no"; then
3619        LIBS="$pthread_lib $LIBS"
3620        libs_qga="$pthread_lib $libs_qga"
3621      fi
3622      PTHREAD_LIB="$pthread_lib"
3623      break
3624    fi
3625  done
3626fi
3627
3628if test "$mingw32" != yes -a "$pthread" = no; then
3629  error_exit "pthread check failed" \
3630      "Make sure to have the pthread libs and headers installed."
3631fi
3632
3633# check for pthread_setname_np
3634pthread_setname_np=no
3635cat > $TMPC << EOF
3636#include <pthread.h>
3637
3638static void *f(void *p) { return NULL; }
3639int main(void)
3640{
3641    pthread_t thread;
3642    pthread_create(&thread, 0, f, 0);
3643    pthread_setname_np(thread, "QEMU");
3644    return 0;
3645}
3646EOF
3647if compile_prog "" "$pthread_lib" ; then
3648  pthread_setname_np=yes
3649fi
3650
3651##########################################
3652# rbd probe
3653if test "$rbd" != "no" ; then
3654  cat > $TMPC <<EOF
3655#include <stdio.h>
3656#include <rbd/librbd.h>
3657int main(void) {
3658    rados_t cluster;
3659    rados_create(&cluster, NULL);
3660    return 0;
3661}
3662EOF
3663  rbd_libs="-lrbd -lrados"
3664  if compile_prog "" "$rbd_libs" ; then
3665    rbd=yes
3666  else
3667    if test "$rbd" = "yes" ; then
3668      feature_not_found "rados block device" "Install librbd/ceph devel"
3669    fi
3670    rbd=no
3671  fi
3672fi
3673
3674##########################################
3675# libssh2 probe
3676min_libssh2_version=1.2.8
3677if test "$libssh2" != "no" ; then
3678  if $pkg_config --atleast-version=$min_libssh2_version libssh2; then
3679    libssh2_cflags=$($pkg_config libssh2 --cflags)
3680    libssh2_libs=$($pkg_config libssh2 --libs)
3681    libssh2=yes
3682  else
3683    if test "$libssh2" = "yes" ; then
3684      error_exit "libssh2 >= $min_libssh2_version required for --enable-libssh2"
3685    fi
3686    libssh2=no
3687  fi
3688fi
3689
3690##########################################
3691# libssh2_sftp_fsync probe
3692
3693if test "$libssh2" = "yes"; then
3694  cat > $TMPC <<EOF
3695#include <stdio.h>
3696#include <libssh2.h>
3697#include <libssh2_sftp.h>
3698int main(void) {
3699    LIBSSH2_SESSION *session;
3700    LIBSSH2_SFTP *sftp;
3701    LIBSSH2_SFTP_HANDLE *sftp_handle;
3702    session = libssh2_session_init ();
3703    sftp = libssh2_sftp_init (session);
3704    sftp_handle = libssh2_sftp_open (sftp, "/", 0, 0);
3705    libssh2_sftp_fsync (sftp_handle);
3706    return 0;
3707}
3708EOF
3709  # libssh2_cflags/libssh2_libs defined in previous test.
3710  if compile_prog "$libssh2_cflags" "$libssh2_libs" ; then
3711    QEMU_CFLAGS="-DHAS_LIBSSH2_SFTP_FSYNC $QEMU_CFLAGS"
3712  fi
3713fi
3714
3715##########################################
3716# linux-aio probe
3717
3718if test "$linux_aio" != "no" ; then
3719  cat > $TMPC <<EOF
3720#include <libaio.h>
3721#include <sys/eventfd.h>
3722#include <stddef.h>
3723int main(void) { io_setup(0, NULL); io_set_eventfd(NULL, 0); eventfd(0, 0); return 0; }
3724EOF
3725  if compile_prog "" "-laio" ; then
3726    linux_aio=yes
3727  else
3728    if test "$linux_aio" = "yes" ; then
3729      feature_not_found "linux AIO" "Install libaio devel"
3730    fi
3731    linux_aio=no
3732  fi
3733fi
3734
3735##########################################
3736# TPM passthrough is only on x86 Linux
3737
3738if test "$targetos" = Linux && test "$cpu" = i386 -o "$cpu" = x86_64; then
3739  tpm_passthrough=$tpm
3740else
3741  tpm_passthrough=no
3742fi
3743
3744# TPM emulator is for all posix systems
3745if test "$mingw32" != "yes"; then
3746  tpm_emulator=$tpm
3747else
3748  tpm_emulator=no
3749fi
3750##########################################
3751# attr probe
3752
3753if test "$attr" != "no" ; then
3754  cat > $TMPC <<EOF
3755#include <stdio.h>
3756#include <sys/types.h>
3757#ifdef CONFIG_LIBATTR
3758#include <attr/xattr.h>
3759#else
3760#include <sys/xattr.h>
3761#endif
3762int main(void) { getxattr(NULL, NULL, NULL, 0); setxattr(NULL, NULL, NULL, 0, 0); return 0; }
3763EOF
3764  if compile_prog "" "" ; then
3765    attr=yes
3766  # Older distros have <attr/xattr.h>, and need -lattr:
3767  elif compile_prog "-DCONFIG_LIBATTR" "-lattr" ; then
3768    attr=yes
3769    LIBS="-lattr $LIBS"
3770    libattr=yes
3771  else
3772    if test "$attr" = "yes" ; then
3773      feature_not_found "ATTR" "Install libc6 or libattr devel"
3774    fi
3775    attr=no
3776  fi
3777fi
3778
3779##########################################
3780# iovec probe
3781cat > $TMPC <<EOF
3782#include <sys/types.h>
3783#include <sys/uio.h>
3784#include <unistd.h>
3785int main(void) { return sizeof(struct iovec); }
3786EOF
3787iovec=no
3788if compile_prog "" "" ; then
3789  iovec=yes
3790fi
3791
3792##########################################
3793# preadv probe
3794cat > $TMPC <<EOF
3795#include <sys/types.h>
3796#include <sys/uio.h>
3797#include <unistd.h>
3798int main(void) { return preadv(0, 0, 0, 0); }
3799EOF
3800preadv=no
3801if compile_prog "" "" ; then
3802  preadv=yes
3803fi
3804
3805##########################################
3806# fdt probe
3807# fdt support is mandatory for at least some target architectures,
3808# so insist on it if we're building those system emulators.
3809fdt_required=no
3810for target in $target_list; do
3811  case $target in
3812    aarch64*-softmmu|arm*-softmmu|ppc*-softmmu|microblaze*-softmmu|mips64el-softmmu|riscv*-softmmu)
3813      fdt_required=yes
3814    ;;
3815  esac
3816done
3817
3818if test "$fdt_required" = "yes"; then
3819  if test "$fdt" = "no"; then
3820    error_exit "fdt disabled but some requested targets require it." \
3821      "You can turn off fdt only if you also disable all the system emulation" \
3822      "targets which need it (by specifying a cut down --target-list)."
3823  fi
3824  fdt=yes
3825fi
3826
3827if test "$fdt" != "no" ; then
3828  fdt_libs="-lfdt"
3829  # explicitly check for libfdt_env.h as it is missing in some stable installs
3830  # and test for required functions to make sure we are on a version >= 1.4.2
3831  cat > $TMPC << EOF
3832#include <libfdt.h>
3833#include <libfdt_env.h>
3834int main(void) { fdt_first_subnode(0, 0); return 0; }
3835EOF
3836  if compile_prog "" "$fdt_libs" ; then
3837    # system DTC is good - use it
3838    fdt=system
3839  else
3840      # have GIT checkout, so activate dtc submodule
3841      if test -e "${source_path}/.git" ; then
3842          git_submodules="${git_submodules} dtc"
3843      fi
3844      if test -d "${source_path}/dtc/libfdt" || test -e "${source_path}/.git" ; then
3845          fdt=git
3846          mkdir -p dtc
3847          if [ "$pwd_is_source_path" != "y" ] ; then
3848              symlink "$source_path/dtc/Makefile" "dtc/Makefile"
3849              symlink "$source_path/dtc/scripts" "dtc/scripts"
3850          fi
3851          fdt_cflags="-I\$(SRC_PATH)/dtc/libfdt"
3852          fdt_ldflags="-L\$(BUILD_DIR)/dtc/libfdt"
3853          fdt_libs="$fdt_libs"
3854      elif test "$fdt" = "yes" ; then
3855          # Not a git build & no libfdt found, prompt for system install
3856          error_exit "DTC (libfdt) version >= 1.4.2 not present." \
3857                     "Please install the DTC (libfdt) devel package"
3858      else
3859          # don't have and don't want
3860          fdt_libs=
3861          fdt=no
3862      fi
3863  fi
3864fi
3865
3866libs_softmmu="$libs_softmmu $fdt_libs"
3867
3868##########################################
3869# opengl probe (for sdl2, gtk, milkymist-tmu2)
3870
3871if test "$opengl" != "no" ; then
3872  opengl_pkgs="epoxy libdrm gbm"
3873  if $pkg_config $opengl_pkgs; then
3874    opengl_cflags="$($pkg_config --cflags $opengl_pkgs)"
3875    opengl_libs="$($pkg_config --libs $opengl_pkgs)"
3876    opengl=yes
3877    if test "$gtk" = "yes" && $pkg_config --exists "$gtkpackage >= 3.16"; then
3878        gtk_gl="yes"
3879    fi
3880    QEMU_CFLAGS="$QEMU_CFLAGS $opengl_cflags"
3881  else
3882    if test "$opengl" = "yes" ; then
3883      feature_not_found "opengl" "Please install opengl (mesa) devel pkgs: $opengl_pkgs"
3884    fi
3885    opengl_cflags=""
3886    opengl_libs=""
3887    opengl=no
3888  fi
3889fi
3890
3891if test "$opengl" = "yes"; then
3892  cat > $TMPC << EOF
3893#include <epoxy/egl.h>
3894#ifndef EGL_MESA_image_dma_buf_export
3895# error mesa/epoxy lacks support for dmabufs (mesa 10.6+)
3896#endif
3897int main(void) { return 0; }
3898EOF
3899  if compile_prog "" "" ; then
3900    opengl_dmabuf=yes
3901  fi
3902fi
3903
3904##########################################
3905# libxml2 probe
3906if test "$libxml2" != "no" ; then
3907    if $pkg_config --exists libxml-2.0; then
3908        libxml2="yes"
3909        libxml2_cflags=$($pkg_config --cflags libxml-2.0)
3910        libxml2_libs=$($pkg_config --libs libxml-2.0)
3911    else
3912        if test "$libxml2" = "yes"; then
3913            feature_not_found "libxml2" "Install libxml2 devel"
3914        fi
3915        libxml2="no"
3916    fi
3917fi
3918
3919##########################################
3920# glusterfs probe
3921if test "$glusterfs" != "no" ; then
3922  if $pkg_config --atleast-version=3 glusterfs-api; then
3923    glusterfs="yes"
3924    glusterfs_cflags=$($pkg_config --cflags glusterfs-api)
3925    glusterfs_libs=$($pkg_config --libs glusterfs-api)
3926    if $pkg_config --atleast-version=4 glusterfs-api; then
3927      glusterfs_xlator_opt="yes"
3928    fi
3929    if $pkg_config --atleast-version=5 glusterfs-api; then
3930      glusterfs_discard="yes"
3931    fi
3932    if $pkg_config --atleast-version=6 glusterfs-api; then
3933      glusterfs_fallocate="yes"
3934      glusterfs_zerofill="yes"
3935    fi
3936  else
3937    if test "$glusterfs" = "yes" ; then
3938      feature_not_found "GlusterFS backend support" \
3939          "Install glusterfs-api devel >= 3"
3940    fi
3941    glusterfs="no"
3942  fi
3943fi
3944
3945# Check for inotify functions when we are building linux-user
3946# emulator.  This is done because older glibc versions don't
3947# have syscall stubs for these implemented.  In that case we
3948# don't provide them even if kernel supports them.
3949#
3950inotify=no
3951cat > $TMPC << EOF
3952#include <sys/inotify.h>
3953
3954int
3955main(void)
3956{
3957	/* try to start inotify */
3958	return inotify_init();
3959}
3960EOF
3961if compile_prog "" "" ; then
3962  inotify=yes
3963fi
3964
3965inotify1=no
3966cat > $TMPC << EOF
3967#include <sys/inotify.h>
3968
3969int
3970main(void)
3971{
3972    /* try to start inotify */
3973    return inotify_init1(0);
3974}
3975EOF
3976if compile_prog "" "" ; then
3977  inotify1=yes
3978fi
3979
3980# check if pipe2 is there
3981pipe2=no
3982cat > $TMPC << EOF
3983#include <unistd.h>
3984#include <fcntl.h>
3985
3986int main(void)
3987{
3988    int pipefd[2];
3989    return pipe2(pipefd, O_CLOEXEC);
3990}
3991EOF
3992if compile_prog "" "" ; then
3993  pipe2=yes
3994fi
3995
3996# check if accept4 is there
3997accept4=no
3998cat > $TMPC << EOF
3999#include <sys/socket.h>
4000#include <stddef.h>
4001
4002int main(void)
4003{
4004    accept4(0, NULL, NULL, SOCK_CLOEXEC);
4005    return 0;
4006}
4007EOF
4008if compile_prog "" "" ; then
4009  accept4=yes
4010fi
4011
4012# check if tee/splice is there. vmsplice was added same time.
4013splice=no
4014cat > $TMPC << EOF
4015#include <unistd.h>
4016#include <fcntl.h>
4017#include <limits.h>
4018
4019int main(void)
4020{
4021    int len, fd = 0;
4022    len = tee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, SPLICE_F_NONBLOCK);
4023    splice(STDIN_FILENO, NULL, fd, NULL, len, SPLICE_F_MOVE);
4024    return 0;
4025}
4026EOF
4027if compile_prog "" "" ; then
4028  splice=yes
4029fi
4030
4031##########################################
4032# libnuma probe
4033
4034if test "$numa" != "no" ; then
4035  cat > $TMPC << EOF
4036#include <numa.h>
4037int main(void) { return numa_available(); }
4038EOF
4039
4040  if compile_prog "" "-lnuma" ; then
4041    numa=yes
4042    libs_softmmu="-lnuma $libs_softmmu"
4043  else
4044    if test "$numa" = "yes" ; then
4045      feature_not_found "numa" "install numactl devel"
4046    fi
4047    numa=no
4048  fi
4049fi
4050
4051if test "$tcmalloc" = "yes" && test "$jemalloc" = "yes" ; then
4052    echo "ERROR: tcmalloc && jemalloc can't be used at the same time"
4053    exit 1
4054fi
4055
4056# Even if malloc_trim() is available, these non-libc memory allocators
4057# do not support it.
4058if test "$tcmalloc" = "yes" || test "$jemalloc" = "yes" ; then
4059    if test "$malloc_trim" = "yes" ; then
4060        echo "Disabling malloc_trim with non-libc memory allocator"
4061    fi
4062    malloc_trim="no"
4063fi
4064
4065#######################################
4066# malloc_trim
4067
4068if test "$malloc_trim" != "no" ; then
4069    cat > $TMPC << EOF
4070#include <malloc.h>
4071int main(void) { malloc_trim(0); return 0; }
4072EOF
4073    if compile_prog "" "" ; then
4074        malloc_trim="yes"
4075    else
4076        malloc_trim="no"
4077    fi
4078fi
4079
4080##########################################
4081# tcmalloc probe
4082
4083if test "$tcmalloc" = "yes" ; then
4084  cat > $TMPC << EOF
4085#include <stdlib.h>
4086int main(void) { malloc(1); return 0; }
4087EOF
4088
4089  if compile_prog "" "-ltcmalloc" ; then
4090    LIBS="-ltcmalloc $LIBS"
4091  else
4092    feature_not_found "tcmalloc" "install gperftools devel"
4093  fi
4094fi
4095
4096##########################################
4097# jemalloc probe
4098
4099if test "$jemalloc" = "yes" ; then
4100  cat > $TMPC << EOF
4101#include <stdlib.h>
4102int main(void) { malloc(1); return 0; }
4103EOF
4104
4105  if compile_prog "" "-ljemalloc" ; then
4106    LIBS="-ljemalloc $LIBS"
4107  else
4108    feature_not_found "jemalloc" "install jemalloc devel"
4109  fi
4110fi
4111
4112##########################################
4113# signalfd probe
4114signalfd="no"
4115cat > $TMPC << EOF
4116#include <unistd.h>
4117#include <sys/syscall.h>
4118#include <signal.h>
4119int main(void) { return syscall(SYS_signalfd, -1, NULL, _NSIG / 8); }
4120EOF
4121
4122if compile_prog "" "" ; then
4123  signalfd=yes
4124fi
4125
4126# check if eventfd is supported
4127eventfd=no
4128cat > $TMPC << EOF
4129#include <sys/eventfd.h>
4130
4131int main(void)
4132{
4133    return eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
4134}
4135EOF
4136if compile_prog "" "" ; then
4137  eventfd=yes
4138fi
4139
4140# check if memfd is supported
4141memfd=no
4142cat > $TMPC << EOF
4143#include <sys/mman.h>
4144
4145int main(void)
4146{
4147    return memfd_create("foo", MFD_ALLOW_SEALING);
4148}
4149EOF
4150if compile_prog "" "" ; then
4151  memfd=yes
4152fi
4153
4154
4155
4156# check for fallocate
4157fallocate=no
4158cat > $TMPC << EOF
4159#include <fcntl.h>
4160
4161int main(void)
4162{
4163    fallocate(0, 0, 0, 0);
4164    return 0;
4165}
4166EOF
4167if compile_prog "" "" ; then
4168  fallocate=yes
4169fi
4170
4171# check for fallocate hole punching
4172fallocate_punch_hole=no
4173cat > $TMPC << EOF
4174#include <fcntl.h>
4175#include <linux/falloc.h>
4176
4177int main(void)
4178{
4179    fallocate(0, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 0);
4180    return 0;
4181}
4182EOF
4183if compile_prog "" "" ; then
4184  fallocate_punch_hole=yes
4185fi
4186
4187# check that fallocate supports range zeroing inside the file
4188fallocate_zero_range=no
4189cat > $TMPC << EOF
4190#include <fcntl.h>
4191#include <linux/falloc.h>
4192
4193int main(void)
4194{
4195    fallocate(0, FALLOC_FL_ZERO_RANGE, 0, 0);
4196    return 0;
4197}
4198EOF
4199if compile_prog "" "" ; then
4200  fallocate_zero_range=yes
4201fi
4202
4203# check for posix_fallocate
4204posix_fallocate=no
4205cat > $TMPC << EOF
4206#include <fcntl.h>
4207
4208int main(void)
4209{
4210    posix_fallocate(0, 0, 0);
4211    return 0;
4212}
4213EOF
4214if compile_prog "" "" ; then
4215    posix_fallocate=yes
4216fi
4217
4218# check for sync_file_range
4219sync_file_range=no
4220cat > $TMPC << EOF
4221#include <fcntl.h>
4222
4223int main(void)
4224{
4225    sync_file_range(0, 0, 0, 0);
4226    return 0;
4227}
4228EOF
4229if compile_prog "" "" ; then
4230  sync_file_range=yes
4231fi
4232
4233# check for linux/fiemap.h and FS_IOC_FIEMAP
4234fiemap=no
4235cat > $TMPC << EOF
4236#include <sys/ioctl.h>
4237#include <linux/fs.h>
4238#include <linux/fiemap.h>
4239
4240int main(void)
4241{
4242    ioctl(0, FS_IOC_FIEMAP, 0);
4243    return 0;
4244}
4245EOF
4246if compile_prog "" "" ; then
4247  fiemap=yes
4248fi
4249
4250# check for dup3
4251dup3=no
4252cat > $TMPC << EOF
4253#include <unistd.h>
4254
4255int main(void)
4256{
4257    dup3(0, 0, 0);
4258    return 0;
4259}
4260EOF
4261if compile_prog "" "" ; then
4262  dup3=yes
4263fi
4264
4265# check for ppoll support
4266ppoll=no
4267cat > $TMPC << EOF
4268#include <poll.h>
4269
4270int main(void)
4271{
4272    struct pollfd pfd = { .fd = 0, .events = 0, .revents = 0 };
4273    ppoll(&pfd, 1, 0, 0);
4274    return 0;
4275}
4276EOF
4277if compile_prog "" "" ; then
4278  ppoll=yes
4279fi
4280
4281# check for prctl(PR_SET_TIMERSLACK , ... ) support
4282prctl_pr_set_timerslack=no
4283cat > $TMPC << EOF
4284#include <sys/prctl.h>
4285
4286int main(void)
4287{
4288    prctl(PR_SET_TIMERSLACK, 1, 0, 0, 0);
4289    return 0;
4290}
4291EOF
4292if compile_prog "" "" ; then
4293  prctl_pr_set_timerslack=yes
4294fi
4295
4296# check for epoll support
4297epoll=no
4298cat > $TMPC << EOF
4299#include <sys/epoll.h>
4300
4301int main(void)
4302{
4303    epoll_create(0);
4304    return 0;
4305}
4306EOF
4307if compile_prog "" "" ; then
4308  epoll=yes
4309fi
4310
4311# epoll_create1 is a later addition
4312# so we must check separately for its presence
4313epoll_create1=no
4314cat > $TMPC << EOF
4315#include <sys/epoll.h>
4316
4317int main(void)
4318{
4319    /* Note that we use epoll_create1 as a value, not as
4320     * a function being called. This is necessary so that on
4321     * old SPARC glibc versions where the function was present in
4322     * the library but not declared in the header file we will
4323     * fail the configure check. (Otherwise we will get a compiler
4324     * warning but not an error, and will proceed to fail the
4325     * qemu compile where we compile with -Werror.)
4326     */
4327    return (int)(uintptr_t)&epoll_create1;
4328}
4329EOF
4330if compile_prog "" "" ; then
4331  epoll_create1=yes
4332fi
4333
4334# check for sendfile support
4335sendfile=no
4336cat > $TMPC << EOF
4337#include <sys/sendfile.h>
4338
4339int main(void)
4340{
4341    return sendfile(0, 0, 0, 0);
4342}
4343EOF
4344if compile_prog "" "" ; then
4345  sendfile=yes
4346fi
4347
4348# check for timerfd support (glibc 2.8 and newer)
4349timerfd=no
4350cat > $TMPC << EOF
4351#include <sys/timerfd.h>
4352
4353int main(void)
4354{
4355    return(timerfd_create(CLOCK_REALTIME, 0));
4356}
4357EOF
4358if compile_prog "" "" ; then
4359  timerfd=yes
4360fi
4361
4362# check for setns and unshare support
4363setns=no
4364cat > $TMPC << EOF
4365#include <sched.h>
4366
4367int main(void)
4368{
4369    int ret;
4370    ret = setns(0, 0);
4371    ret = unshare(0);
4372    return ret;
4373}
4374EOF
4375if compile_prog "" "" ; then
4376  setns=yes
4377fi
4378
4379# clock_adjtime probe
4380clock_adjtime=no
4381cat > $TMPC <<EOF
4382#include <time.h>
4383
4384int main(void)
4385{
4386    return clock_adjtime(0, 0);
4387}
4388EOF
4389clock_adjtime=no
4390if compile_prog "" "" ; then
4391  clock_adjtime=yes
4392fi
4393
4394# syncfs probe
4395syncfs=no
4396cat > $TMPC <<EOF
4397#include <unistd.h>
4398
4399int main(void)
4400{
4401    return syncfs(0);
4402}
4403EOF
4404syncfs=no
4405if compile_prog "" "" ; then
4406  syncfs=yes
4407fi
4408
4409# Check if tools are available to build documentation.
4410if test "$docs" != "no" ; then
4411  if has makeinfo && has pod2man; then
4412    docs=yes
4413  else
4414    if test "$docs" = "yes" ; then
4415      feature_not_found "docs" "Install texinfo and Perl/perl-podlators"
4416    fi
4417    docs=no
4418  fi
4419fi
4420
4421# Search for bswap_32 function
4422byteswap_h=no
4423cat > $TMPC << EOF
4424#include <byteswap.h>
4425int main(void) { return bswap_32(0); }
4426EOF
4427if compile_prog "" "" ; then
4428  byteswap_h=yes
4429fi
4430
4431# Search for bswap32 function
4432bswap_h=no
4433cat > $TMPC << EOF
4434#include <sys/endian.h>
4435#include <sys/types.h>
4436#include <machine/bswap.h>
4437int main(void) { return bswap32(0); }
4438EOF
4439if compile_prog "" "" ; then
4440  bswap_h=yes
4441fi
4442
4443##########################################
4444# Do we have libiscsi >= 1.9.0
4445if test "$libiscsi" != "no" ; then
4446  if $pkg_config --atleast-version=1.9.0 libiscsi; then
4447    libiscsi="yes"
4448    libiscsi_cflags=$($pkg_config --cflags libiscsi)
4449    libiscsi_libs=$($pkg_config --libs libiscsi)
4450  else
4451    if test "$libiscsi" = "yes" ; then
4452      feature_not_found "libiscsi" "Install libiscsi >= 1.9.0"
4453    fi
4454    libiscsi="no"
4455  fi
4456fi
4457
4458##########################################
4459# Do we need libm
4460cat > $TMPC << EOF
4461#include <math.h>
4462int main(int argc, char **argv) { return isnan(sin((double)argc)); }
4463EOF
4464if compile_prog "" "" ; then
4465  :
4466elif compile_prog "" "-lm" ; then
4467  LIBS="-lm $LIBS"
4468  libs_qga="-lm $libs_qga"
4469else
4470  error_exit "libm check failed"
4471fi
4472
4473##########################################
4474# Do we need librt
4475# uClibc provides 2 versions of clock_gettime(), one with realtime
4476# support and one without. This means that the clock_gettime() don't
4477# need -lrt. We still need it for timer_create() so we check for this
4478# function in addition.
4479cat > $TMPC <<EOF
4480#include <signal.h>
4481#include <time.h>
4482int main(void) {
4483  timer_create(CLOCK_REALTIME, NULL, NULL);
4484  return clock_gettime(CLOCK_REALTIME, NULL);
4485}
4486EOF
4487
4488if compile_prog "" "" ; then
4489  :
4490# we need pthread for static linking. use previous pthread test result
4491elif compile_prog "" "$pthread_lib -lrt" ; then
4492  LIBS="$LIBS -lrt"
4493  libs_qga="$libs_qga -lrt"
4494fi
4495
4496if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \
4497        "$haiku" != "yes" ; then
4498    libs_softmmu="-lutil $libs_softmmu"
4499fi
4500
4501##########################################
4502# spice probe
4503if test "$spice" != "no" ; then
4504  cat > $TMPC << EOF
4505#include <spice.h>
4506int main(void) { spice_server_new(); return 0; }
4507EOF
4508  spice_cflags=$($pkg_config --cflags spice-protocol spice-server 2>/dev/null)
4509  spice_libs=$($pkg_config --libs spice-protocol spice-server 2>/dev/null)
4510  if $pkg_config --atleast-version=0.12.0 spice-server && \
4511     $pkg_config --atleast-version=0.12.3 spice-protocol && \
4512     compile_prog "$spice_cflags" "$spice_libs" ; then
4513    spice="yes"
4514    libs_softmmu="$libs_softmmu $spice_libs"
4515    QEMU_CFLAGS="$QEMU_CFLAGS $spice_cflags"
4516    spice_protocol_version=$($pkg_config --modversion spice-protocol)
4517    spice_server_version=$($pkg_config --modversion spice-server)
4518  else
4519    if test "$spice" = "yes" ; then
4520      feature_not_found "spice" \
4521          "Install spice-server(>=0.12.0) and spice-protocol(>=0.12.3) devel"
4522    fi
4523    spice="no"
4524  fi
4525fi
4526
4527# check for smartcard support
4528if test "$smartcard" != "no"; then
4529    if $pkg_config --atleast-version=2.5.1 libcacard; then
4530        libcacard_cflags=$($pkg_config --cflags libcacard)
4531        libcacard_libs=$($pkg_config --libs libcacard)
4532        smartcard="yes"
4533    else
4534        if test "$smartcard" = "yes"; then
4535            feature_not_found "smartcard" "Install libcacard devel"
4536        fi
4537        smartcard="no"
4538    fi
4539fi
4540
4541# check for libusb
4542if test "$libusb" != "no" ; then
4543    if $pkg_config --atleast-version=1.0.13 libusb-1.0; then
4544        libusb="yes"
4545        libusb_cflags=$($pkg_config --cflags libusb-1.0)
4546        libusb_libs=$($pkg_config --libs libusb-1.0)
4547    else
4548        if test "$libusb" = "yes"; then
4549            feature_not_found "libusb" "Install libusb devel >= 1.0.13"
4550        fi
4551        libusb="no"
4552    fi
4553fi
4554
4555# check for usbredirparser for usb network redirection support
4556if test "$usb_redir" != "no" ; then
4557    if $pkg_config --atleast-version=0.6 libusbredirparser-0.5; then
4558        usb_redir="yes"
4559        usb_redir_cflags=$($pkg_config --cflags libusbredirparser-0.5)
4560        usb_redir_libs=$($pkg_config --libs libusbredirparser-0.5)
4561    else
4562        if test "$usb_redir" = "yes"; then
4563            feature_not_found "usb-redir" "Install usbredir devel"
4564        fi
4565        usb_redir="no"
4566    fi
4567fi
4568
4569##########################################
4570# check if we have VSS SDK headers for win
4571
4572if test "$mingw32" = "yes" -a "$guest_agent" != "no" -a "$vss_win32_sdk" != "no" ; then
4573  case "$vss_win32_sdk" in
4574    "")   vss_win32_include="-isystem $source_path" ;;
4575    *\ *) # The SDK is installed in "Program Files" by default, but we cannot
4576          # handle path with spaces. So we symlink the headers into ".sdk/vss".
4577          vss_win32_include="-isystem $source_path/.sdk/vss"
4578	  symlink "$vss_win32_sdk/inc" "$source_path/.sdk/vss/inc"
4579	  ;;
4580    *)    vss_win32_include="-isystem $vss_win32_sdk"
4581  esac
4582  cat > $TMPC << EOF
4583#define __MIDL_user_allocate_free_DEFINED__
4584#include <inc/win2003/vss.h>
4585int main(void) { return VSS_CTX_BACKUP; }
4586EOF
4587  if compile_prog "$vss_win32_include" "" ; then
4588    guest_agent_with_vss="yes"
4589    QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
4590    libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++ -Wl,--enable-stdcall-fixup $libs_qga"
4591    qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb"
4592  else
4593    if test "$vss_win32_sdk" != "" ; then
4594      echo "ERROR: Please download and install Microsoft VSS SDK:"
4595      echo "ERROR:   http://www.microsoft.com/en-us/download/details.aspx?id=23490"
4596      echo "ERROR: On POSIX-systems, you can extract the SDK headers by:"
4597      echo "ERROR:   scripts/extract-vsssdk-headers setup.exe"
4598      echo "ERROR: The headers are extracted in the directory \`inc'."
4599      feature_not_found "VSS support"
4600    fi
4601    guest_agent_with_vss="no"
4602  fi
4603fi
4604
4605##########################################
4606# lookup Windows platform SDK (if not specified)
4607# The SDK is needed only to build .tlb (type library) file of guest agent
4608# VSS provider from the source. It is usually unnecessary because the
4609# pre-compiled .tlb file is included.
4610
4611if test "$mingw32" = "yes" -a "$guest_agent" != "no" -a "$guest_agent_with_vss" = "yes" ; then
4612  if test -z "$win_sdk"; then
4613    programfiles="$PROGRAMFILES"
4614    test -n "$PROGRAMW6432" && programfiles="$PROGRAMW6432"
4615    if test -n "$programfiles"; then
4616      win_sdk=$(ls -d "$programfiles/Microsoft SDKs/Windows/v"* | tail -1) 2>/dev/null
4617    else
4618      feature_not_found "Windows SDK"
4619    fi
4620  elif test "$win_sdk" = "no"; then
4621    win_sdk=""
4622  fi
4623fi
4624
4625##########################################
4626# check if mingw environment provides a recent ntddscsi.h
4627if test "$mingw32" = "yes" -a "$guest_agent" != "no"; then
4628  cat > $TMPC << EOF
4629#include <windows.h>
4630#include <ntddscsi.h>
4631int main(void) {
4632#if !defined(IOCTL_SCSI_GET_ADDRESS)
4633#error Missing required ioctl definitions
4634#endif
4635  SCSI_ADDRESS addr = { .Lun = 0, .TargetId = 0, .PathId = 0 };
4636  return addr.Lun;
4637}
4638EOF
4639  if compile_prog "" "" ; then
4640    guest_agent_ntddscsi=yes
4641    libs_qga="-lsetupapi $libs_qga"
4642  fi
4643fi
4644
4645##########################################
4646# virgl renderer probe
4647
4648if test "$virglrenderer" != "no" ; then
4649  cat > $TMPC << EOF
4650#include <virglrenderer.h>
4651int main(void) { virgl_renderer_poll(); return 0; }
4652EOF
4653  virgl_cflags=$($pkg_config --cflags virglrenderer 2>/dev/null)
4654  virgl_libs=$($pkg_config --libs virglrenderer 2>/dev/null)
4655  virgl_version=$($pkg_config --modversion virglrenderer 2>/dev/null)
4656  if $pkg_config virglrenderer >/dev/null 2>&1 && \
4657     compile_prog "$virgl_cflags" "$virgl_libs" ; then
4658    virglrenderer="yes"
4659  else
4660    if test "$virglrenderer" = "yes" ; then
4661      feature_not_found "virglrenderer"
4662    fi
4663    virglrenderer="no"
4664  fi
4665fi
4666
4667##########################################
4668# capstone
4669
4670case "$capstone" in
4671  "" | yes)
4672    if $pkg_config capstone; then
4673      capstone=system
4674    elif test -e "${source_path}/.git" -a $git_update = 'yes' ; then
4675      capstone=git
4676    elif test -e "${source_path}/capstone/Makefile" ; then
4677      capstone=internal
4678    elif test -z "$capstone" ; then
4679      capstone=no
4680    else
4681      feature_not_found "capstone" "Install capstone devel or git submodule"
4682    fi
4683    ;;
4684
4685  system)
4686    if ! $pkg_config capstone; then
4687      feature_not_found "capstone" "Install capstone devel"
4688    fi
4689    ;;
4690esac
4691
4692case "$capstone" in
4693  git | internal)
4694    if test "$capstone" = git; then
4695      git_submodules="${git_submodules} capstone"
4696    fi
4697    mkdir -p capstone
4698    QEMU_CFLAGS="$QEMU_CFLAGS -I\$(SRC_PATH)/capstone/include"
4699    if test "$mingw32" = "yes"; then
4700      LIBCAPSTONE=capstone.lib
4701    else
4702      LIBCAPSTONE=libcapstone.a
4703    fi
4704    LIBS="-L\$(BUILD_DIR)/capstone -lcapstone $LIBS"
4705    ;;
4706
4707  system)
4708    QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags capstone)"
4709    LIBS="$($pkg_config --libs capstone) $LIBS"
4710    ;;
4711
4712  no)
4713    ;;
4714  *)
4715    error_exit "Unknown state for capstone: $capstone"
4716    ;;
4717esac
4718
4719##########################################
4720# check if we have fdatasync
4721
4722fdatasync=no
4723cat > $TMPC << EOF
4724#include <unistd.h>
4725int main(void) {
4726#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
4727return fdatasync(0);
4728#else
4729#error Not supported
4730#endif
4731}
4732EOF
4733if compile_prog "" "" ; then
4734    fdatasync=yes
4735fi
4736
4737##########################################
4738# check if we have madvise
4739
4740madvise=no
4741cat > $TMPC << EOF
4742#include <sys/types.h>
4743#include <sys/mman.h>
4744#include <stddef.h>
4745int main(void) { return madvise(NULL, 0, MADV_DONTNEED); }
4746EOF
4747if compile_prog "" "" ; then
4748    madvise=yes
4749fi
4750
4751##########################################
4752# check if we have posix_madvise
4753
4754posix_madvise=no
4755cat > $TMPC << EOF
4756#include <sys/mman.h>
4757#include <stddef.h>
4758int main(void) { return posix_madvise(NULL, 0, POSIX_MADV_DONTNEED); }
4759EOF
4760if compile_prog "" "" ; then
4761    posix_madvise=yes
4762fi
4763
4764##########################################
4765# check if we have posix_memalign()
4766
4767posix_memalign=no
4768cat > $TMPC << EOF
4769#include <stdlib.h>
4770int main(void) {
4771    void *p;
4772    return posix_memalign(&p, 8, 8);
4773}
4774EOF
4775if compile_prog "" "" ; then
4776    posix_memalign=yes
4777fi
4778
4779##########################################
4780# check if we have posix_syslog
4781
4782posix_syslog=no
4783cat > $TMPC << EOF
4784#include <syslog.h>
4785int main(void) { openlog("qemu", LOG_PID, LOG_DAEMON); syslog(LOG_INFO, "configure"); return 0; }
4786EOF
4787if compile_prog "" "" ; then
4788    posix_syslog=yes
4789fi
4790
4791##########################################
4792# check if we have sem_timedwait
4793
4794sem_timedwait=no
4795cat > $TMPC << EOF
4796#include <semaphore.h>
4797int main(void) { return sem_timedwait(0, 0); }
4798EOF
4799if compile_prog "" "" ; then
4800    sem_timedwait=yes
4801fi
4802
4803##########################################
4804# check if trace backend exists
4805
4806$python "$source_path/scripts/tracetool.py" "--backends=$trace_backends" --check-backends  > /dev/null 2> /dev/null
4807if test "$?" -ne 0 ; then
4808  error_exit "invalid trace backends" \
4809      "Please choose supported trace backends."
4810fi
4811
4812##########################################
4813# For 'ust' backend, test if ust headers are present
4814if have_backend "ust"; then
4815  cat > $TMPC << EOF
4816#include <lttng/tracepoint.h>
4817int main(void) { return 0; }
4818EOF
4819  if compile_prog "" "-Wl,--no-as-needed -ldl" ; then
4820    if $pkg_config lttng-ust --exists; then
4821      lttng_ust_libs=$($pkg_config --libs lttng-ust)
4822    else
4823      lttng_ust_libs="-llttng-ust -ldl"
4824    fi
4825    if $pkg_config liburcu-bp --exists; then
4826      urcu_bp_libs=$($pkg_config --libs liburcu-bp)
4827    else
4828      urcu_bp_libs="-lurcu-bp"
4829    fi
4830
4831    LIBS="$lttng_ust_libs $urcu_bp_libs $LIBS"
4832    libs_qga="$lttng_ust_libs $urcu_bp_libs $libs_qga"
4833  else
4834    error_exit "Trace backend 'ust' missing lttng-ust header files"
4835  fi
4836fi
4837
4838##########################################
4839# For 'dtrace' backend, test if 'dtrace' command is present
4840if have_backend "dtrace"; then
4841  if ! has 'dtrace' ; then
4842    error_exit "dtrace command is not found in PATH $PATH"
4843  fi
4844  trace_backend_stap="no"
4845  if has 'stap' ; then
4846    trace_backend_stap="yes"
4847  fi
4848fi
4849
4850##########################################
4851# check and set a backend for coroutine
4852
4853# We prefer ucontext, but it's not always possible. The fallback
4854# is sigcontext. On Windows the only valid backend is the Windows
4855# specific one.
4856
4857ucontext_works=no
4858if test "$darwin" != "yes"; then
4859  cat > $TMPC << EOF
4860#include <ucontext.h>
4861#ifdef __stub_makecontext
4862#error Ignoring glibc stub makecontext which will always fail
4863#endif
4864int main(void) { makecontext(0, 0, 0); return 0; }
4865EOF
4866  if compile_prog "" "" ; then
4867    ucontext_works=yes
4868  fi
4869fi
4870
4871if test "$coroutine" = ""; then
4872  if test "$mingw32" = "yes"; then
4873    coroutine=win32
4874  elif test "$ucontext_works" = "yes"; then
4875    coroutine=ucontext
4876  else
4877    coroutine=sigaltstack
4878  fi
4879else
4880  case $coroutine in
4881  windows)
4882    if test "$mingw32" != "yes"; then
4883      error_exit "'windows' coroutine backend only valid for Windows"
4884    fi
4885    # Unfortunately the user visible backend name doesn't match the
4886    # coroutine-*.c filename for this case, so we have to adjust it here.
4887    coroutine=win32
4888    ;;
4889  ucontext)
4890    if test "$ucontext_works" != "yes"; then
4891      feature_not_found "ucontext"
4892    fi
4893    ;;
4894  sigaltstack)
4895    if test "$mingw32" = "yes"; then
4896      error_exit "only the 'windows' coroutine backend is valid for Windows"
4897    fi
4898    ;;
4899  *)
4900    error_exit "unknown coroutine backend $coroutine"
4901    ;;
4902  esac
4903fi
4904
4905if test "$coroutine_pool" = ""; then
4906  coroutine_pool=yes
4907fi
4908
4909if test "$debug_stack_usage" = "yes"; then
4910  if test "$coroutine_pool" = "yes"; then
4911    echo "WARN: disabling coroutine pool for stack usage debugging"
4912    coroutine_pool=no
4913  fi
4914fi
4915
4916
4917##########################################
4918# check if we have open_by_handle_at
4919
4920open_by_handle_at=no
4921cat > $TMPC << EOF
4922#include <fcntl.h>
4923#if !defined(AT_EMPTY_PATH)
4924# error missing definition
4925#else
4926int main(void) { struct file_handle fh; return open_by_handle_at(0, &fh, 0); }
4927#endif
4928EOF
4929if compile_prog "" "" ; then
4930    open_by_handle_at=yes
4931fi
4932
4933########################################
4934# check if we have linux/magic.h
4935
4936linux_magic_h=no
4937cat > $TMPC << EOF
4938#include <linux/magic.h>
4939int main(void) {
4940  return 0;
4941}
4942EOF
4943if compile_prog "" "" ; then
4944    linux_magic_h=yes
4945fi
4946
4947########################################
4948# check whether we can disable warning option with a pragma (this is needed
4949# to silence warnings in the headers of some versions of external libraries).
4950# This test has to be compiled with -Werror as otherwise an unknown pragma is
4951# only a warning.
4952#
4953# If we can't selectively disable warning in the code, disable -Werror so that
4954# the build doesn't fail anyway.
4955
4956pragma_disable_unused_but_set=no
4957cat > $TMPC << EOF
4958#pragma GCC diagnostic push
4959#pragma GCC diagnostic ignored "-Wstrict-prototypes"
4960#pragma GCC diagnostic pop
4961
4962int main(void) {
4963    return 0;
4964}
4965EOF
4966if compile_prog "-Werror" "" ; then
4967    pragma_diagnostic_available=yes
4968else
4969    werror=no
4970fi
4971
4972########################################
4973# check if we have valgrind/valgrind.h
4974
4975valgrind_h=no
4976cat > $TMPC << EOF
4977#include <valgrind/valgrind.h>
4978int main(void) {
4979  return 0;
4980}
4981EOF
4982if compile_prog "" "" ; then
4983    valgrind_h=yes
4984fi
4985
4986########################################
4987# check if environ is declared
4988
4989has_environ=no
4990cat > $TMPC << EOF
4991#include <unistd.h>
4992int main(void) {
4993    environ = 0;
4994    return 0;
4995}
4996EOF
4997if compile_prog "" "" ; then
4998    has_environ=yes
4999fi
5000
5001########################################
5002# check if cpuid.h is usable.
5003
5004cat > $TMPC << EOF
5005#include <cpuid.h>
5006int main(void) {
5007    unsigned a, b, c, d;
5008    int max = __get_cpuid_max(0, 0);
5009
5010    if (max >= 1) {
5011        __cpuid(1, a, b, c, d);
5012    }
5013
5014    if (max >= 7) {
5015        __cpuid_count(7, 0, a, b, c, d);
5016    }
5017
5018    return 0;
5019}
5020EOF
5021if compile_prog "" "" ; then
5022    cpuid_h=yes
5023fi
5024
5025##########################################
5026# avx2 optimization requirement check
5027#
5028# There is no point enabling this if cpuid.h is not usable,
5029# since we won't be able to select the new routines.
5030
5031if test $cpuid_h = yes; then
5032  cat > $TMPC << EOF
5033#pragma GCC push_options
5034#pragma GCC target("avx2")
5035#include <cpuid.h>
5036#include <immintrin.h>
5037static int bar(void *a) {
5038    __m256i x = *(__m256i *)a;
5039    return _mm256_testz_si256(x, x);
5040}
5041int main(int argc, char *argv[]) { return bar(argv[0]); }
5042EOF
5043  if compile_object "" ; then
5044    avx2_opt="yes"
5045  fi
5046fi
5047
5048########################################
5049# check if __[u]int128_t is usable.
5050
5051int128=no
5052cat > $TMPC << EOF
5053#if defined(__clang_major__) && defined(__clang_minor__)
5054# if ((__clang_major__ < 3) || (__clang_major__ == 3) && (__clang_minor__ < 2))
5055#  error __int128_t does not work in CLANG before 3.2
5056# endif
5057#endif
5058__int128_t a;
5059__uint128_t b;
5060int main (void) {
5061  a = a + b;
5062  b = a * b;
5063  a = a * a;
5064  return 0;
5065}
5066EOF
5067if compile_prog "" "" ; then
5068    int128=yes
5069fi
5070
5071#########################################
5072# See if 128-bit atomic operations are supported.
5073
5074atomic128=no
5075if test "$int128" = "yes"; then
5076  cat > $TMPC << EOF
5077int main(void)
5078{
5079  unsigned __int128 x = 0, y = 0;
5080  y = __atomic_load_16(&x, 0);
5081  __atomic_store_16(&x, y, 0);
5082  __atomic_compare_exchange_16(&x, &y, x, 0, 0, 0);
5083  return 0;
5084}
5085EOF
5086  if compile_prog "" "" ; then
5087    atomic128=yes
5088  fi
5089fi
5090
5091#########################################
5092# See if 64-bit atomic operations are supported.
5093# Note that without __atomic builtins, we can only
5094# assume atomic loads/stores max at pointer size.
5095
5096cat > $TMPC << EOF
5097#include <stdint.h>
5098int main(void)
5099{
5100  uint64_t x = 0, y = 0;
5101#ifdef __ATOMIC_RELAXED
5102  y = __atomic_load_8(&x, 0);
5103  __atomic_store_8(&x, y, 0);
5104  __atomic_compare_exchange_8(&x, &y, x, 0, 0, 0);
5105  __atomic_exchange_8(&x, y, 0);
5106  __atomic_fetch_add_8(&x, y, 0);
5107#else
5108  typedef char is_host64[sizeof(void *) >= sizeof(uint64_t) ? 1 : -1];
5109  __sync_lock_test_and_set(&x, y);
5110  __sync_val_compare_and_swap(&x, y, 0);
5111  __sync_fetch_and_add(&x, y);
5112#endif
5113  return 0;
5114}
5115EOF
5116if compile_prog "" "" ; then
5117  atomic64=yes
5118fi
5119
5120########################################
5121# See if 16-byte vector operations are supported.
5122# Even without a vector unit the compiler may expand these.
5123# There is a bug in old GCC for PPC that crashes here.
5124# Unfortunately it's the system compiler for Centos 7.
5125
5126cat > $TMPC << EOF
5127typedef unsigned char U1 __attribute__((vector_size(16)));
5128typedef unsigned short U2 __attribute__((vector_size(16)));
5129typedef unsigned int U4 __attribute__((vector_size(16)));
5130typedef unsigned long long U8 __attribute__((vector_size(16)));
5131typedef signed char S1 __attribute__((vector_size(16)));
5132typedef signed short S2 __attribute__((vector_size(16)));
5133typedef signed int S4 __attribute__((vector_size(16)));
5134typedef signed long long S8 __attribute__((vector_size(16)));
5135static U1 a1, b1;
5136static U2 a2, b2;
5137static U4 a4, b4;
5138static U8 a8, b8;
5139static S1 c1;
5140static S2 c2;
5141static S4 c4;
5142static S8 c8;
5143static int i;
5144void helper(void *d, void *a, int shift, int i);
5145void helper(void *d, void *a, int shift, int i)
5146{
5147  *(U1 *)(d + i) = *(U1 *)(a + i) << shift;
5148  *(U2 *)(d + i) = *(U2 *)(a + i) << shift;
5149  *(U4 *)(d + i) = *(U4 *)(a + i) << shift;
5150  *(U8 *)(d + i) = *(U8 *)(a + i) << shift;
5151}
5152int main(void)
5153{
5154  a1 += b1; a2 += b2; a4 += b4; a8 += b8;
5155  a1 -= b1; a2 -= b2; a4 -= b4; a8 -= b8;
5156  a1 *= b1; a2 *= b2; a4 *= b4; a8 *= b8;
5157  a1 &= b1; a2 &= b2; a4 &= b4; a8 &= b8;
5158  a1 |= b1; a2 |= b2; a4 |= b4; a8 |= b8;
5159  a1 ^= b1; a2 ^= b2; a4 ^= b4; a8 ^= b8;
5160  a1 <<= i; a2 <<= i; a4 <<= i; a8 <<= i;
5161  a1 >>= i; a2 >>= i; a4 >>= i; a8 >>= i;
5162  c1 >>= i; c2 >>= i; c4 >>= i; c8 >>= i;
5163  return 0;
5164}
5165EOF
5166
5167vector16=no
5168if compile_prog "" "" ; then
5169  vector16=yes
5170fi
5171
5172########################################
5173# check if getauxval is available.
5174
5175getauxval=no
5176cat > $TMPC << EOF
5177#include <sys/auxv.h>
5178int main(void) {
5179  return getauxval(AT_HWCAP) == 0;
5180}
5181EOF
5182if compile_prog "" "" ; then
5183    getauxval=yes
5184fi
5185
5186########################################
5187# check if ccache is interfering with
5188# semantic analysis of macros
5189
5190unset CCACHE_CPP2
5191ccache_cpp2=no
5192cat > $TMPC << EOF
5193static const int Z = 1;
5194#define fn() ({ Z; })
5195#define TAUT(X) ((X) == Z)
5196#define PAREN(X, Y) (X == Y)
5197#define ID(X) (X)
5198int main(int argc, char *argv[])
5199{
5200    int x = 0, y = 0;
5201    x = ID(x);
5202    x = fn();
5203    fn();
5204    if (PAREN(x, y)) return 0;
5205    if (TAUT(Z)) return 0;
5206    return 0;
5207}
5208EOF
5209
5210if ! compile_object "-Werror"; then
5211    ccache_cpp2=yes
5212fi
5213
5214#################################################
5215# clang does not support glibc + FORTIFY_SOURCE.
5216
5217if test "$fortify_source" != "no"; then
5218  if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
5219    fortify_source="no";
5220  elif test -n "$cxx" && has $cxx &&
5221       echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
5222    fortify_source="no";
5223  else
5224    fortify_source="yes"
5225  fi
5226fi
5227
5228###############################################
5229# Check if copy_file_range is provided by glibc
5230have_copy_file_range=no
5231cat > $TMPC << EOF
5232#include <unistd.h>
5233int main(void) {
5234  copy_file_range(0, NULL, 0, NULL, 0, 0);
5235  return 0;
5236}
5237EOF
5238if compile_prog "" "" ; then
5239    have_copy_file_range=yes
5240fi
5241
5242##########################################
5243# check if struct fsxattr is available via linux/fs.h
5244
5245have_fsxattr=no
5246cat > $TMPC << EOF
5247#include <linux/fs.h>
5248struct fsxattr foo;
5249int main(void) {
5250  return 0;
5251}
5252EOF
5253if compile_prog "" "" ; then
5254    have_fsxattr=yes
5255fi
5256
5257##########################################
5258# check for usable membarrier system call
5259if test "$membarrier" = "yes"; then
5260    have_membarrier=no
5261    if test "$mingw32" = "yes" ; then
5262        have_membarrier=yes
5263    elif test "$linux" = "yes" ; then
5264        cat > $TMPC << EOF
5265    #include <linux/membarrier.h>
5266    #include <sys/syscall.h>
5267    #include <unistd.h>
5268    #include <stdlib.h>
5269    int main(void) {
5270        syscall(__NR_membarrier, MEMBARRIER_CMD_QUERY, 0);
5271        syscall(__NR_membarrier, MEMBARRIER_CMD_SHARED, 0);
5272	exit(0);
5273    }
5274EOF
5275        if compile_prog "" "" ; then
5276            have_membarrier=yes
5277        fi
5278    fi
5279    if test "$have_membarrier" = "no"; then
5280      feature_not_found "membarrier" "membarrier system call not available"
5281    fi
5282else
5283    # Do not enable it by default even for Mingw32, because it doesn't
5284    # work on Wine.
5285    membarrier=no
5286fi
5287
5288##########################################
5289# check if rtnetlink.h exists and is useful
5290have_rtnetlink=no
5291cat > $TMPC << EOF
5292#include <linux/rtnetlink.h>
5293int main(void) {
5294  return IFLA_PROTO_DOWN;
5295}
5296EOF
5297if compile_prog "" "" ; then
5298    have_rtnetlink=yes
5299fi
5300
5301##########################################
5302# check for usable AF_VSOCK environment
5303have_af_vsock=no
5304cat > $TMPC << EOF
5305#include <errno.h>
5306#include <sys/types.h>
5307#include <sys/socket.h>
5308#if !defined(AF_VSOCK)
5309# error missing AF_VSOCK flag
5310#endif
5311#include <linux/vm_sockets.h>
5312int main(void) {
5313    int sock, ret;
5314    struct sockaddr_vm svm;
5315    socklen_t len = sizeof(svm);
5316    sock = socket(AF_VSOCK, SOCK_STREAM, 0);
5317    ret = getpeername(sock, (struct sockaddr *)&svm, &len);
5318    if ((ret == -1) && (errno == ENOTCONN)) {
5319        return 0;
5320    }
5321    return -1;
5322}
5323EOF
5324if compile_prog "" "" ; then
5325    have_af_vsock=yes
5326fi
5327
5328##########################################
5329# check for usable AF_ALG environment
5330hava_afalg=no
5331cat > $TMPC << EOF
5332#include <errno.h>
5333#include <sys/types.h>
5334#include <sys/socket.h>
5335#include <linux/if_alg.h>
5336int main(void) {
5337    int sock;
5338    sock = socket(AF_ALG, SOCK_SEQPACKET, 0);
5339    return sock;
5340}
5341EOF
5342if compile_prog "" "" ; then
5343    have_afalg=yes
5344fi
5345if test "$crypto_afalg" = "yes"
5346then
5347    if test "$have_afalg" != "yes"
5348    then
5349	error_exit "AF_ALG requested but could not be detected"
5350    fi
5351fi
5352
5353
5354#################################################
5355# Check to see if we have the Hypervisor framework
5356if [ "$darwin" = "yes" ] ; then
5357  cat > $TMPC << EOF
5358#include <Hypervisor/hv.h>
5359int main() { return 0;}
5360EOF
5361  if ! compile_object ""; then
5362    hvf='no'
5363  else
5364    hvf='yes'
5365    LDFLAGS="-framework Hypervisor $LDFLAGS"
5366  fi
5367fi
5368
5369#################################################
5370# Sparc implicitly links with --relax, which is
5371# incompatible with -r, so --no-relax should be
5372# given. It does no harm to give it on other
5373# platforms too.
5374
5375# Note: the prototype is needed since QEMU_CFLAGS
5376#       contains -Wmissing-prototypes
5377cat > $TMPC << EOF
5378extern int foo(void);
5379int foo(void) { return 0; }
5380EOF
5381if ! compile_object ""; then
5382  error_exit "Failed to compile object file for LD_REL_FLAGS test"
5383fi
5384for i in '-Wl,-r -Wl,--no-relax' -Wl,-r -r; do
5385  if do_cc -nostdlib $i -o $TMPMO $TMPO; then
5386    LD_REL_FLAGS=$i
5387    break
5388  fi
5389done
5390if test "$modules" = "yes" && test "$LD_REL_FLAGS" = ""; then
5391  feature_not_found "modules" "Cannot find how to build relocatable objects"
5392fi
5393
5394##########################################
5395# check for sysmacros.h
5396
5397have_sysmacros=no
5398cat > $TMPC << EOF
5399#include <sys/sysmacros.h>
5400int main(void) {
5401    return makedev(0, 0);
5402}
5403EOF
5404if compile_prog "" "" ; then
5405    have_sysmacros=yes
5406fi
5407
5408##########################################
5409# Veritas HyperScale block driver VxHS
5410# Check if libvxhs is installed
5411
5412if test "$vxhs" != "no" ; then
5413  cat > $TMPC <<EOF
5414#include <stdint.h>
5415#include <qnio/qnio_api.h>
5416
5417void *vxhs_callback;
5418
5419int main(void) {
5420    iio_init(QNIO_VERSION, vxhs_callback);
5421    return 0;
5422}
5423EOF
5424  vxhs_libs="-lvxhs -lssl"
5425  if compile_prog "" "$vxhs_libs" ; then
5426    vxhs=yes
5427  else
5428    if test "$vxhs" = "yes" ; then
5429      feature_not_found "vxhs block device" "Install libvxhs See github"
5430    fi
5431    vxhs=no
5432  fi
5433fi
5434
5435##########################################
5436# check for _Static_assert()
5437
5438have_static_assert=no
5439cat > $TMPC << EOF
5440_Static_assert(1, "success");
5441int main(void) {
5442    return 0;
5443}
5444EOF
5445if compile_prog "" "" ; then
5446    have_static_assert=yes
5447fi
5448
5449##########################################
5450# check for utmpx.h, it is missing e.g. on OpenBSD
5451
5452have_utmpx=no
5453cat > $TMPC << EOF
5454#include <utmpx.h>
5455struct utmpx user_info;
5456int main(void) {
5457    return 0;
5458}
5459EOF
5460if compile_prog "" "" ; then
5461    have_utmpx=yes
5462fi
5463
5464##########################################
5465# checks for sanitizers
5466
5467have_asan=no
5468have_ubsan=no
5469have_asan_iface_h=no
5470have_asan_iface_fiber=no
5471
5472if test "$sanitizers" = "yes" ; then
5473  write_c_skeleton
5474  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
5475      have_asan=yes
5476  fi
5477
5478  # we could use a simple skeleton for flags checks, but this also
5479  # detect the static linking issue of ubsan, see also:
5480  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
5481  cat > $TMPC << EOF
5482#include <stdlib.h>
5483int main(void) {
5484    void *tmp = malloc(10);
5485    return *(int *)(tmp + 2);
5486}
5487EOF
5488  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
5489      have_ubsan=yes
5490  fi
5491
5492  if check_include "sanitizer/asan_interface.h" ; then
5493      have_asan_iface_h=yes
5494  fi
5495
5496  cat > $TMPC << EOF
5497#include <sanitizer/asan_interface.h>
5498int main(void) {
5499  __sanitizer_start_switch_fiber(0, 0, 0);
5500  return 0;
5501}
5502EOF
5503  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
5504      have_asan_iface_fiber=yes
5505  fi
5506fi
5507
5508##########################################
5509# Docker and cross-compiler support
5510#
5511# This is specifically for building test
5512# cases for foreign architectures, not
5513# cross-compiling QEMU itself.
5514
5515if has "docker"; then
5516    docker=$($python $source_path/tests/docker/docker.py probe)
5517fi
5518
5519##########################################
5520# End of CC checks
5521# After here, no more $cc or $ld runs
5522
5523write_c_skeleton
5524
5525if test "$gcov" = "yes" ; then
5526  CFLAGS="-fprofile-arcs -ftest-coverage -g $CFLAGS"
5527  LDFLAGS="-fprofile-arcs -ftest-coverage $LDFLAGS"
5528elif test "$fortify_source" = "yes" ; then
5529  CFLAGS="-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $CFLAGS"
5530elif test "$debug" = "no"; then
5531  CFLAGS="-O2 $CFLAGS"
5532fi
5533
5534if test "$have_asan" = "yes"; then
5535  CFLAGS="-fsanitize=address $CFLAGS"
5536  if test "$have_asan_iface_h" = "no" ; then
5537      echo "ASAN build enabled, but ASAN header missing." \
5538           "Without code annotation, the report may be inferior."
5539  elif test "$have_asan_iface_fiber" = "no" ; then
5540      echo "ASAN build enabled, but ASAN header is too old." \
5541           "Without code annotation, the report may be inferior."
5542  fi
5543fi
5544if test "$have_ubsan" = "yes"; then
5545  CFLAGS="-fsanitize=undefined $CFLAGS"
5546fi
5547
5548##########################################
5549# Do we have libnfs
5550if test "$libnfs" != "no" ; then
5551  if $pkg_config --atleast-version=1.9.3 libnfs; then
5552    libnfs="yes"
5553    libnfs_libs=$($pkg_config --libs libnfs)
5554  else
5555    if test "$libnfs" = "yes" ; then
5556      feature_not_found "libnfs" "Install libnfs devel >= 1.9.3"
5557    fi
5558    libnfs="no"
5559  fi
5560fi
5561
5562# Now we've finished running tests it's OK to add -Werror to the compiler flags
5563if test "$werror" = "yes"; then
5564    QEMU_CFLAGS="-Werror $QEMU_CFLAGS"
5565fi
5566
5567if test "$solaris" = "no" ; then
5568    if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
5569        LDFLAGS="-Wl,--warn-common $LDFLAGS"
5570    fi
5571fi
5572
5573# test if pod2man has --utf8 option
5574if pod2man --help | grep -q utf8; then
5575    POD2MAN="pod2man --utf8"
5576else
5577    POD2MAN="pod2man"
5578fi
5579
5580# Use ASLR, no-SEH and DEP if available
5581if test "$mingw32" = "yes" ; then
5582    for flag in --dynamicbase --no-seh --nxcompat; do
5583        if ld_has $flag ; then
5584            LDFLAGS="-Wl,$flag $LDFLAGS"
5585        fi
5586    done
5587fi
5588
5589qemu_confdir=$sysconfdir$confsuffix
5590qemu_moddir=$libdir$confsuffix
5591qemu_datadir=$datadir$confsuffix
5592qemu_localedir="$datadir/locale"
5593
5594# We can only support ivshmem if we have eventfd
5595if [ "$eventfd" = "yes" ]; then
5596  ivshmem=yes
5597fi
5598
5599tools=""
5600if test "$want_tools" = "yes" ; then
5601  tools="qemu-img\$(EXESUF) qemu-io\$(EXESUF) $tools"
5602  if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then
5603    tools="qemu-nbd\$(EXESUF) $tools"
5604  fi
5605  if [ "$ivshmem" = "yes" ]; then
5606    tools="ivshmem-client\$(EXESUF) ivshmem-server\$(EXESUF) $tools"
5607  fi
5608fi
5609if test "$softmmu" = yes ; then
5610  if test "$linux" = yes; then
5611    if test "$virtfs" != no && test "$cap" = yes && test "$attr" = yes ; then
5612      virtfs=yes
5613      tools="$tools fsdev/virtfs-proxy-helper\$(EXESUF)"
5614    else
5615      if test "$virtfs" = yes; then
5616        error_exit "VirtFS requires libcap devel and libattr devel"
5617      fi
5618      virtfs=no
5619    fi
5620    if test "$mpath" != no && test "$mpathpersist" = yes ; then
5621      mpath=yes
5622    else
5623      if test "$mpath" = yes; then
5624        error_exit "Multipath requires libmpathpersist devel"
5625      fi
5626      mpath=no
5627    fi
5628    tools="$tools scsi/qemu-pr-helper\$(EXESUF)"
5629  else
5630    if test "$virtfs" = yes; then
5631      error_exit "VirtFS is supported only on Linux"
5632    fi
5633    virtfs=no
5634    if test "$mpath" = yes; then
5635      error_exit "Multipath is supported only on Linux"
5636    fi
5637    mpath=no
5638  fi
5639  if test "$xkbcommon" = "yes"; then
5640    tools="qemu-keymap\$(EXESUF) $tools"
5641  fi
5642fi
5643
5644# Probe for guest agent support/options
5645
5646if [ "$guest_agent" != "no" ]; then
5647  if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" -o "$mingw32" = "yes" ] ; then
5648      tools="qemu-ga $tools"
5649      guest_agent=yes
5650  elif [ "$guest_agent" != yes ]; then
5651      guest_agent=no
5652  else
5653      error_exit "Guest agent is not supported on this platform"
5654  fi
5655fi
5656
5657# Guest agent Window MSI  package
5658
5659if test "$guest_agent" != yes; then
5660  if test "$guest_agent_msi" = yes; then
5661    error_exit "MSI guest agent package requires guest agent enabled"
5662  fi
5663  guest_agent_msi=no
5664elif test "$mingw32" != "yes"; then
5665  if test "$guest_agent_msi" = "yes"; then
5666    error_exit "MSI guest agent package is available only for MinGW Windows cross-compilation"
5667  fi
5668  guest_agent_msi=no
5669elif ! has wixl; then
5670  if test "$guest_agent_msi" = "yes"; then
5671    error_exit "MSI guest agent package requires wixl tool installed ( usually from msitools package )"
5672  fi
5673  guest_agent_msi=no
5674else
5675  # we support qemu-ga, mingw32, and wixl: default to MSI enabled if it wasn't
5676  # disabled explicitly
5677  if test "$guest_agent_msi" != "no"; then
5678    guest_agent_msi=yes
5679  fi
5680fi
5681
5682if test "$guest_agent_msi" = "yes"; then
5683  if test "$guest_agent_with_vss" = "yes"; then
5684    QEMU_GA_MSI_WITH_VSS="-D InstallVss"
5685  fi
5686
5687  if test "$QEMU_GA_MANUFACTURER" = ""; then
5688    QEMU_GA_MANUFACTURER=QEMU
5689  fi
5690
5691  if test "$QEMU_GA_DISTRO" = ""; then
5692    QEMU_GA_DISTRO=Linux
5693  fi
5694
5695  if test "$QEMU_GA_VERSION" = ""; then
5696      QEMU_GA_VERSION=$(cat $source_path/VERSION)
5697  fi
5698
5699  QEMU_GA_MSI_MINGW_DLL_PATH="-D Mingw_dlls=$($pkg_config --variable=prefix glib-2.0)/bin"
5700
5701  case "$cpu" in
5702  x86_64)
5703    QEMU_GA_MSI_ARCH="-a x64 -D Arch=64"
5704    ;;
5705  i386)
5706    QEMU_GA_MSI_ARCH="-D Arch=32"
5707    ;;
5708  *)
5709    error_exit "CPU $cpu not supported for building installation package"
5710    ;;
5711  esac
5712fi
5713
5714# Mac OS X ships with a broken assembler
5715roms=
5716if test \( "$cpu" = "i386" -o "$cpu" = "x86_64" \) -a \
5717        "$targetos" != "Darwin" -a "$targetos" != "SunOS" -a \
5718        "$softmmu" = yes ; then
5719    # Different host OS linkers have different ideas about the name of the ELF
5720    # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
5721    # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
5722    for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
5723        if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
5724            ld_i386_emulation="$emu"
5725            roms="optionrom"
5726            break
5727        fi
5728    done
5729fi
5730if test "$cpu" = "ppc64" -a "$targetos" != "Darwin" ; then
5731  roms="$roms spapr-rtas"
5732fi
5733
5734if test "$cpu" = "s390x" ; then
5735  roms="$roms s390-ccw"
5736fi
5737
5738# Probe for the need for relocating the user-only binary.
5739if ( [ "$linux_user" = yes ] || [ "$bsd_user" = yes ] ) && [ "$pie" = no ]; then
5740  textseg_addr=
5741  case "$cpu" in
5742    arm | i386 | ppc* | s390* | sparc* | x86_64 | x32)
5743      # ??? Rationale for choosing this address
5744      textseg_addr=0x60000000
5745      ;;
5746    mips)
5747      # A 256M aligned address, high in the address space, with enough
5748      # room for the code_gen_buffer above it before the stack.
5749      textseg_addr=0x60000000
5750      ;;
5751  esac
5752  if [ -n "$textseg_addr" ]; then
5753    cat > $TMPC <<EOF
5754    int main(void) { return 0; }
5755EOF
5756    textseg_ldflags="-Wl,-Ttext-segment=$textseg_addr"
5757    if ! compile_prog "" "$textseg_ldflags"; then
5758      # In case ld does not support -Ttext-segment, edit the default linker
5759      # script via sed to set the .text start addr.  This is needed on FreeBSD
5760      # at least.
5761      if ! $ld --verbose >/dev/null 2>&1; then
5762        error_exit \
5763            "We need to link the QEMU user mode binaries at a" \
5764            "specific text address. Unfortunately your linker" \
5765            "doesn't support either the -Ttext-segment option or" \
5766            "printing the default linker script with --verbose." \
5767            "If you don't want the user mode binaries, pass the" \
5768            "--disable-user option to configure."
5769      fi
5770
5771      $ld --verbose | sed \
5772        -e '1,/==================================================/d' \
5773        -e '/==================================================/,$d' \
5774        -e "s/[.] = [0-9a-fx]* [+] SIZEOF_HEADERS/. = $textseg_addr + SIZEOF_HEADERS/" \
5775        -e "s/__executable_start = [0-9a-fx]*/__executable_start = $textseg_addr/" > config-host.ld
5776      textseg_ldflags="-Wl,-T../config-host.ld"
5777    fi
5778  fi
5779fi
5780
5781# Check that the C++ compiler exists and works with the C compiler.
5782# All the QEMU_CXXFLAGS are based on QEMU_CFLAGS. Keep this at the end to don't miss any other that could be added.
5783if has $cxx; then
5784    cat > $TMPC <<EOF
5785int c_function(void);
5786int main(void) { return c_function(); }
5787EOF
5788
5789    compile_object
5790
5791    cat > $TMPCXX <<EOF
5792extern "C" {
5793   int c_function(void);
5794}
5795int c_function(void) { return 42; }
5796EOF
5797
5798    update_cxxflags
5799
5800    if do_cxx $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $LDFLAGS; then
5801        # C++ compiler $cxx works ok with C compiler $cc
5802        :
5803    else
5804        echo "C++ compiler $cxx does not work with C compiler $cc"
5805        echo "Disabling C++ specific optional code"
5806        cxx=
5807    fi
5808else
5809    echo "No C++ compiler available; disabling C++ specific optional code"
5810    cxx=
5811fi
5812
5813echo_version() {
5814    if test "$1" = "yes" ; then
5815        echo "($2)"
5816    fi
5817}
5818
5819# prepend pixman and ftd flags after all config tests are done
5820QEMU_CFLAGS="$pixman_cflags $fdt_cflags $QEMU_CFLAGS"
5821QEMU_LDFLAGS="$fdt_ldflags $QEMU_LDFLAGS"
5822libs_softmmu="$pixman_libs $libs_softmmu"
5823
5824echo "Install prefix    $prefix"
5825echo "BIOS directory    $(eval echo $qemu_datadir)"
5826echo "firmware path     $(eval echo $firmwarepath)"
5827echo "binary directory  $(eval echo $bindir)"
5828echo "library directory $(eval echo $libdir)"
5829echo "module directory  $(eval echo $qemu_moddir)"
5830echo "libexec directory $(eval echo $libexecdir)"
5831echo "include directory $(eval echo $includedir)"
5832echo "config directory  $(eval echo $sysconfdir)"
5833if test "$mingw32" = "no" ; then
5834echo "local state directory   $(eval echo $local_statedir)"
5835echo "Manual directory  $(eval echo $mandir)"
5836echo "ELF interp prefix $interp_prefix"
5837else
5838echo "local state directory   queried at runtime"
5839echo "Windows SDK       $win_sdk"
5840fi
5841echo "Source path       $source_path"
5842echo "GIT binary        $git"
5843echo "GIT submodules    $git_submodules"
5844echo "C compiler        $cc"
5845echo "Host C compiler   $host_cc"
5846echo "C++ compiler      $cxx"
5847echo "Objective-C compiler $objcc"
5848echo "ARFLAGS           $ARFLAGS"
5849echo "CFLAGS            $CFLAGS"
5850echo "QEMU_CFLAGS       $QEMU_CFLAGS"
5851echo "LDFLAGS           $LDFLAGS"
5852echo "QEMU_LDFLAGS      $QEMU_LDFLAGS"
5853echo "make              $make"
5854echo "install           $install"
5855echo "python            $python"
5856if test "$slirp" = "yes" ; then
5857    echo "smbd              $smbd"
5858fi
5859echo "module support    $modules"
5860echo "host CPU          $cpu"
5861echo "host big endian   $bigendian"
5862echo "target list       $target_list"
5863echo "gprof enabled     $gprof"
5864echo "sparse enabled    $sparse"
5865echo "strip binaries    $strip_opt"
5866echo "profiler          $profiler"
5867echo "static build      $static"
5868if test "$darwin" = "yes" ; then
5869    echo "Cocoa support     $cocoa"
5870fi
5871echo "SDL support       $sdl $(echo_version $sdl $sdlversion)"
5872echo "GTK support       $gtk $(echo_version $gtk $gtk_version)"
5873echo "GTK GL support    $gtk_gl"
5874echo "VTE support       $vte $(echo_version $vte $vteversion)"
5875echo "TLS priority      $tls_priority"
5876echo "GNUTLS support    $gnutls"
5877echo "GNUTLS rnd        $gnutls_rnd"
5878echo "libgcrypt         $gcrypt"
5879echo "libgcrypt kdf     $gcrypt_kdf"
5880echo "nettle            $nettle $(echo_version $nettle $nettle_version)"
5881echo "nettle kdf        $nettle_kdf"
5882echo "libtasn1          $tasn1"
5883echo "curses support    $curses"
5884echo "virgl support     $virglrenderer $(echo_version $virglrenderer $virgl_version)"
5885echo "curl support      $curl"
5886echo "mingw32 support   $mingw32"
5887echo "Audio drivers     $audio_drv_list"
5888echo "Block whitelist (rw) $block_drv_rw_whitelist"
5889echo "Block whitelist (ro) $block_drv_ro_whitelist"
5890echo "VirtFS support    $virtfs"
5891echo "Multipath support $mpath"
5892echo "VNC support       $vnc"
5893if test "$vnc" = "yes" ; then
5894    echo "VNC SASL support  $vnc_sasl"
5895    echo "VNC JPEG support  $vnc_jpeg"
5896    echo "VNC PNG support   $vnc_png"
5897fi
5898if test -n "$sparc_cpu"; then
5899    echo "Target Sparc Arch $sparc_cpu"
5900fi
5901echo "xen support       $xen"
5902if test "$xen" = "yes" ; then
5903  echo "xen ctrl version  $xen_ctrl_version"
5904  echo "pv dom build      $xen_pv_domain_build"
5905fi
5906echo "brlapi support    $brlapi"
5907echo "bluez  support    $bluez"
5908echo "Documentation     $docs"
5909echo "PIE               $pie"
5910echo "vde support       $vde"
5911echo "netmap support    $netmap"
5912echo "Linux AIO support $linux_aio"
5913echo "ATTR/XATTR support $attr"
5914echo "Install blobs     $blobs"
5915echo "KVM support       $kvm"
5916echo "HAX support       $hax"
5917echo "HVF support       $hvf"
5918echo "WHPX support      $whpx"
5919echo "TCG support       $tcg"
5920if test "$tcg" = "yes" ; then
5921    echo "TCG debug enabled $debug_tcg"
5922    echo "TCG interpreter   $tcg_interpreter"
5923fi
5924echo "malloc trim support $malloc_trim"
5925echo "RDMA support      $rdma"
5926echo "fdt support       $fdt"
5927echo "membarrier        $membarrier"
5928echo "preadv support    $preadv"
5929echo "fdatasync         $fdatasync"
5930echo "madvise           $madvise"
5931echo "posix_madvise     $posix_madvise"
5932echo "posix_memalign    $posix_memalign"
5933echo "libcap-ng support $cap_ng"
5934echo "vhost-net support $vhost_net"
5935echo "vhost-crypto support $vhost_crypto"
5936echo "vhost-scsi support $vhost_scsi"
5937echo "vhost-vsock support $vhost_vsock"
5938echo "vhost-user support $vhost_user"
5939echo "Trace backends    $trace_backends"
5940if have_backend "simple"; then
5941echo "Trace output file $trace_file-<pid>"
5942fi
5943echo "spice support     $spice $(echo_version $spice $spice_protocol_version/$spice_server_version)"
5944echo "rbd support       $rbd"
5945echo "xfsctl support    $xfs"
5946echo "smartcard support $smartcard"
5947echo "libusb            $libusb"
5948echo "usb net redir     $usb_redir"
5949echo "OpenGL support    $opengl"
5950echo "OpenGL dmabufs    $opengl_dmabuf"
5951echo "libiscsi support  $libiscsi"
5952echo "libnfs support    $libnfs"
5953echo "build guest agent $guest_agent"
5954echo "QGA VSS support   $guest_agent_with_vss"
5955echo "QGA w32 disk info $guest_agent_ntddscsi"
5956echo "QGA MSI support   $guest_agent_msi"
5957echo "seccomp support   $seccomp"
5958echo "coroutine backend $coroutine"
5959echo "coroutine pool    $coroutine_pool"
5960echo "debug stack usage $debug_stack_usage"
5961echo "mutex debugging   $debug_mutex"
5962echo "crypto afalg      $crypto_afalg"
5963echo "GlusterFS support $glusterfs"
5964echo "gcov              $gcov_tool"
5965echo "gcov enabled      $gcov"
5966echo "TPM support       $tpm"
5967echo "libssh2 support   $libssh2"
5968echo "TPM passthrough   $tpm_passthrough"
5969echo "TPM emulator      $tpm_emulator"
5970echo "QOM debugging     $qom_cast_debug"
5971echo "Live block migration $live_block_migration"
5972echo "lzo support       $lzo"
5973echo "snappy support    $snappy"
5974echo "bzip2 support     $bzip2"
5975echo "NUMA host support $numa"
5976echo "libxml2           $libxml2"
5977echo "tcmalloc support  $tcmalloc"
5978echo "jemalloc support  $jemalloc"
5979echo "avx2 optimization $avx2_opt"
5980echo "replication support $replication"
5981echo "VxHS block device $vxhs"
5982echo "capstone          $capstone"
5983echo "docker            $docker"
5984
5985if test "$sdl_too_old" = "yes"; then
5986echo "-> Your SDL version is too old - please upgrade to have SDL support"
5987fi
5988
5989if test "$gtkabi" = "2.0"; then
5990    echo
5991    echo "WARNING: Use of GTK 2.0 is deprecated and will be removed in"
5992    echo "WARNING: future releases. Please switch to using GTK 3.0"
5993fi
5994
5995if test "$sdlabi" = "1.2"; then
5996    echo
5997    echo "WARNING: Use of SDL 1.2 is deprecated and will be removed in"
5998    echo "WARNING: future releases. Please switch to using SDL 2.0"
5999fi
6000
6001if test "$supported_cpu" = "no"; then
6002    echo
6003    echo "WARNING: SUPPORT FOR THIS HOST CPU WILL GO AWAY IN FUTURE RELEASES!"
6004    echo
6005    echo "CPU host architecture $cpu support is not currently maintained."
6006    echo "The QEMU project intends to remove support for this host CPU in"
6007    echo "a future release if nobody volunteers to maintain it and to"
6008    echo "provide a build host for our continuous integration setup."
6009    echo "configure has succeeded and you can continue to build, but"
6010    echo "if you care about QEMU on this platform you should contact"
6011    echo "us upstream at qemu-devel@nongnu.org."
6012fi
6013
6014if test "$supported_os" = "no"; then
6015    echo
6016    echo "WARNING: SUPPORT FOR THIS HOST OS WILL GO AWAY IN FUTURE RELEASES!"
6017    echo
6018    echo "Host OS $targetos support is not currently maintained."
6019    echo "The QEMU project intends to remove support for this host OS in"
6020    echo "a future release if nobody volunteers to maintain it and to"
6021    echo "provide a build host for our continuous integration setup."
6022    echo "configure has succeeded and you can continue to build, but"
6023    echo "if you care about QEMU on this platform you should contact"
6024    echo "us upstream at qemu-devel@nongnu.org."
6025fi
6026
6027config_host_mak="config-host.mak"
6028
6029echo "# Automatically generated by configure - do not modify" >config-all-disas.mak
6030
6031echo "# Automatically generated by configure - do not modify" > $config_host_mak
6032echo >> $config_host_mak
6033
6034echo all: >> $config_host_mak
6035echo "prefix=$prefix" >> $config_host_mak
6036echo "bindir=$bindir" >> $config_host_mak
6037echo "libdir=$libdir" >> $config_host_mak
6038echo "libexecdir=$libexecdir" >> $config_host_mak
6039echo "includedir=$includedir" >> $config_host_mak
6040echo "mandir=$mandir" >> $config_host_mak
6041echo "sysconfdir=$sysconfdir" >> $config_host_mak
6042echo "qemu_confdir=$qemu_confdir" >> $config_host_mak
6043echo "qemu_datadir=$qemu_datadir" >> $config_host_mak
6044echo "qemu_firmwarepath=$firmwarepath" >> $config_host_mak
6045echo "qemu_docdir=$qemu_docdir" >> $config_host_mak
6046echo "qemu_moddir=$qemu_moddir" >> $config_host_mak
6047if test "$mingw32" = "no" ; then
6048  echo "qemu_localstatedir=$local_statedir" >> $config_host_mak
6049fi
6050echo "qemu_helperdir=$libexecdir" >> $config_host_mak
6051echo "qemu_localedir=$qemu_localedir" >> $config_host_mak
6052echo "libs_softmmu=$libs_softmmu" >> $config_host_mak
6053echo "GIT=$git" >> $config_host_mak
6054echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
6055echo "GIT_UPDATE=$git_update" >> $config_host_mak
6056
6057echo "ARCH=$ARCH" >> $config_host_mak
6058
6059if test "$debug_tcg" = "yes" ; then
6060  echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
6061fi
6062if test "$strip_opt" = "yes" ; then
6063  echo "STRIP=${strip}" >> $config_host_mak
6064fi
6065if test "$bigendian" = "yes" ; then
6066  echo "HOST_WORDS_BIGENDIAN=y" >> $config_host_mak
6067fi
6068if test "$mingw32" = "yes" ; then
6069  echo "CONFIG_WIN32=y" >> $config_host_mak
6070  rc_version=$(cat $source_path/VERSION)
6071  version_major=${rc_version%%.*}
6072  rc_version=${rc_version#*.}
6073  version_minor=${rc_version%%.*}
6074  rc_version=${rc_version#*.}
6075  version_subminor=${rc_version%%.*}
6076  version_micro=0
6077  echo "CONFIG_FILEVERSION=$version_major,$version_minor,$version_subminor,$version_micro" >> $config_host_mak
6078  echo "CONFIG_PRODUCTVERSION=$version_major,$version_minor,$version_subminor,$version_micro" >> $config_host_mak
6079  if test "$guest_agent_with_vss" = "yes" ; then
6080    echo "CONFIG_QGA_VSS=y" >> $config_host_mak
6081    echo "QGA_VSS_PROVIDER=$qga_vss_provider" >> $config_host_mak
6082    echo "WIN_SDK=\"$win_sdk\"" >> $config_host_mak
6083  fi
6084  if test "$guest_agent_ntddscsi" = "yes" ; then
6085    echo "CONFIG_QGA_NTDDDISK=y" >> $config_host_mak
6086  fi
6087  if test "$guest_agent_msi" = "yes"; then
6088    echo "QEMU_GA_MSI_ENABLED=yes" >> $config_host_mak
6089    echo "QEMU_GA_MSI_MINGW_DLL_PATH=${QEMU_GA_MSI_MINGW_DLL_PATH}" >> $config_host_mak
6090    echo "QEMU_GA_MSI_WITH_VSS=${QEMU_GA_MSI_WITH_VSS}" >> $config_host_mak
6091    echo "QEMU_GA_MSI_ARCH=${QEMU_GA_MSI_ARCH}" >> $config_host_mak
6092    echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
6093    echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
6094    echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
6095  fi
6096else
6097  echo "CONFIG_POSIX=y" >> $config_host_mak
6098fi
6099
6100if test "$linux" = "yes" ; then
6101  echo "CONFIG_LINUX=y" >> $config_host_mak
6102fi
6103
6104if test "$darwin" = "yes" ; then
6105  echo "CONFIG_DARWIN=y" >> $config_host_mak
6106fi
6107
6108if test "$solaris" = "yes" ; then
6109  echo "CONFIG_SOLARIS=y" >> $config_host_mak
6110fi
6111if test "$haiku" = "yes" ; then
6112  echo "CONFIG_HAIKU=y" >> $config_host_mak
6113fi
6114if test "$static" = "yes" ; then
6115  echo "CONFIG_STATIC=y" >> $config_host_mak
6116fi
6117if test "$profiler" = "yes" ; then
6118  echo "CONFIG_PROFILER=y" >> $config_host_mak
6119fi
6120if test "$slirp" = "yes" ; then
6121  echo "CONFIG_SLIRP=y" >> $config_host_mak
6122  echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
6123fi
6124if test "$vde" = "yes" ; then
6125  echo "CONFIG_VDE=y" >> $config_host_mak
6126  echo "VDE_LIBS=$vde_libs" >> $config_host_mak
6127fi
6128if test "$netmap" = "yes" ; then
6129  echo "CONFIG_NETMAP=y" >> $config_host_mak
6130fi
6131if test "$l2tpv3" = "yes" ; then
6132  echo "CONFIG_L2TPV3=y" >> $config_host_mak
6133fi
6134if test "$cap_ng" = "yes" ; then
6135  echo "CONFIG_LIBCAP=y" >> $config_host_mak
6136fi
6137echo "CONFIG_AUDIO_DRIVERS=$audio_drv_list" >> $config_host_mak
6138for drv in $audio_drv_list; do
6139    def=CONFIG_AUDIO_$(echo $drv | LC_ALL=C tr '[a-z]' '[A-Z]')
6140    case "$drv" in
6141	alsa | oss | pa | sdl)
6142	    echo "$def=m" >> $config_host_mak ;;
6143	*)
6144	    echo "$def=y" >> $config_host_mak ;;
6145    esac
6146done
6147echo "ALSA_LIBS=$alsa_libs" >> $config_host_mak
6148echo "PULSE_LIBS=$pulse_libs" >> $config_host_mak
6149echo "COREAUDIO_LIBS=$coreaudio_libs" >> $config_host_mak
6150echo "DSOUND_LIBS=$dsound_libs" >> $config_host_mak
6151echo "OSS_LIBS=$oss_libs" >> $config_host_mak
6152if test "$audio_pt_int" = "yes" ; then
6153  echo "CONFIG_AUDIO_PT_INT=y" >> $config_host_mak
6154fi
6155if test "$audio_win_int" = "yes" ; then
6156  echo "CONFIG_AUDIO_WIN_INT=y" >> $config_host_mak
6157fi
6158echo "CONFIG_BDRV_RW_WHITELIST=$block_drv_rw_whitelist" >> $config_host_mak
6159echo "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
6160if test "$vnc" = "yes" ; then
6161  echo "CONFIG_VNC=y" >> $config_host_mak
6162fi
6163if test "$vnc_sasl" = "yes" ; then
6164  echo "CONFIG_VNC_SASL=y" >> $config_host_mak
6165fi
6166if test "$vnc_jpeg" = "yes" ; then
6167  echo "CONFIG_VNC_JPEG=y" >> $config_host_mak
6168fi
6169if test "$vnc_png" = "yes" ; then
6170  echo "CONFIG_VNC_PNG=y" >> $config_host_mak
6171fi
6172if test "$xkbcommon" = "yes" ; then
6173  echo "XKBCOMMON_CFLAGS=$xkbcommon_cflags" >> $config_host_mak
6174  echo "XKBCOMMON_LIBS=$xkbcommon_libs" >> $config_host_mak
6175fi
6176if test "$fnmatch" = "yes" ; then
6177  echo "CONFIG_FNMATCH=y" >> $config_host_mak
6178fi
6179if test "$xfs" = "yes" ; then
6180  echo "CONFIG_XFS=y" >> $config_host_mak
6181fi
6182qemu_version=$(head $source_path/VERSION)
6183echo "VERSION=$qemu_version" >>$config_host_mak
6184echo "PKGVERSION=$pkgversion" >>$config_host_mak
6185echo "SRC_PATH=$source_path" >> $config_host_mak
6186echo "TARGET_LIST=$target_list" >> $config_host_mak
6187if [ "$docs" = "yes" ] ; then
6188  echo "BUILD_DOCS=yes" >> $config_host_mak
6189fi
6190if test "$modules" = "yes"; then
6191  # $shacmd can generate a hash started with digit, which the compiler doesn't
6192  # like as an symbol. So prefix it with an underscore
6193  echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
6194  echo "CONFIG_MODULES=y" >> $config_host_mak
6195fi
6196if test "$have_x11" = "yes" -a "$need_x11" = "yes"; then
6197  echo "CONFIG_X11=y" >> $config_host_mak
6198  echo "X11_CFLAGS=$x11_cflags" >> $config_host_mak
6199  echo "X11_LIBS=$x11_libs" >> $config_host_mak
6200fi
6201if test "$sdl" = "yes" ; then
6202  echo "CONFIG_SDL=m" >> $config_host_mak
6203  echo "CONFIG_SDLABI=$sdlabi" >> $config_host_mak
6204  echo "SDL_CFLAGS=$sdl_cflags" >> $config_host_mak
6205  echo "SDL_LIBS=$sdl_libs" >> $config_host_mak
6206fi
6207if test "$cocoa" = "yes" ; then
6208  echo "CONFIG_COCOA=y" >> $config_host_mak
6209fi
6210if test "$curses" = "yes" ; then
6211  echo "CONFIG_CURSES=m" >> $config_host_mak
6212  echo "CURSES_CFLAGS=$curses_inc" >> $config_host_mak
6213  echo "CURSES_LIBS=$curses_lib" >> $config_host_mak
6214fi
6215if test "$pipe2" = "yes" ; then
6216  echo "CONFIG_PIPE2=y" >> $config_host_mak
6217fi
6218if test "$accept4" = "yes" ; then
6219  echo "CONFIG_ACCEPT4=y" >> $config_host_mak
6220fi
6221if test "$splice" = "yes" ; then
6222  echo "CONFIG_SPLICE=y" >> $config_host_mak
6223fi
6224if test "$eventfd" = "yes" ; then
6225  echo "CONFIG_EVENTFD=y" >> $config_host_mak
6226fi
6227if test "$memfd" = "yes" ; then
6228  echo "CONFIG_MEMFD=y" >> $config_host_mak
6229fi
6230if test "$fallocate" = "yes" ; then
6231  echo "CONFIG_FALLOCATE=y" >> $config_host_mak
6232fi
6233if test "$fallocate_punch_hole" = "yes" ; then
6234  echo "CONFIG_FALLOCATE_PUNCH_HOLE=y" >> $config_host_mak
6235fi
6236if test "$fallocate_zero_range" = "yes" ; then
6237  echo "CONFIG_FALLOCATE_ZERO_RANGE=y" >> $config_host_mak
6238fi
6239if test "$posix_fallocate" = "yes" ; then
6240  echo "CONFIG_POSIX_FALLOCATE=y" >> $config_host_mak
6241fi
6242if test "$sync_file_range" = "yes" ; then
6243  echo "CONFIG_SYNC_FILE_RANGE=y" >> $config_host_mak
6244fi
6245if test "$fiemap" = "yes" ; then
6246  echo "CONFIG_FIEMAP=y" >> $config_host_mak
6247fi
6248if test "$dup3" = "yes" ; then
6249  echo "CONFIG_DUP3=y" >> $config_host_mak
6250fi
6251if test "$ppoll" = "yes" ; then
6252  echo "CONFIG_PPOLL=y" >> $config_host_mak
6253fi
6254if test "$prctl_pr_set_timerslack" = "yes" ; then
6255  echo "CONFIG_PRCTL_PR_SET_TIMERSLACK=y" >> $config_host_mak
6256fi
6257if test "$epoll" = "yes" ; then
6258  echo "CONFIG_EPOLL=y" >> $config_host_mak
6259fi
6260if test "$epoll_create1" = "yes" ; then
6261  echo "CONFIG_EPOLL_CREATE1=y" >> $config_host_mak
6262fi
6263if test "$sendfile" = "yes" ; then
6264  echo "CONFIG_SENDFILE=y" >> $config_host_mak
6265fi
6266if test "$timerfd" = "yes" ; then
6267  echo "CONFIG_TIMERFD=y" >> $config_host_mak
6268fi
6269if test "$setns" = "yes" ; then
6270  echo "CONFIG_SETNS=y" >> $config_host_mak
6271fi
6272if test "$clock_adjtime" = "yes" ; then
6273  echo "CONFIG_CLOCK_ADJTIME=y" >> $config_host_mak
6274fi
6275if test "$syncfs" = "yes" ; then
6276  echo "CONFIG_SYNCFS=y" >> $config_host_mak
6277fi
6278if test "$inotify" = "yes" ; then
6279  echo "CONFIG_INOTIFY=y" >> $config_host_mak
6280fi
6281if test "$inotify1" = "yes" ; then
6282  echo "CONFIG_INOTIFY1=y" >> $config_host_mak
6283fi
6284if test "$sem_timedwait" = "yes" ; then
6285  echo "CONFIG_SEM_TIMEDWAIT=y" >> $config_host_mak
6286fi
6287if test "$byteswap_h" = "yes" ; then
6288  echo "CONFIG_BYTESWAP_H=y" >> $config_host_mak
6289fi
6290if test "$bswap_h" = "yes" ; then
6291  echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak
6292fi
6293if test "$curl" = "yes" ; then
6294  echo "CONFIG_CURL=m" >> $config_host_mak
6295  echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak
6296  echo "CURL_LIBS=$curl_libs" >> $config_host_mak
6297fi
6298if test "$brlapi" = "yes" ; then
6299  echo "CONFIG_BRLAPI=y" >> $config_host_mak
6300  echo "BRLAPI_LIBS=$brlapi_libs" >> $config_host_mak
6301fi
6302if test "$bluez" = "yes" ; then
6303  echo "CONFIG_BLUEZ=y" >> $config_host_mak
6304  echo "BLUEZ_CFLAGS=$bluez_cflags" >> $config_host_mak
6305fi
6306if test "$glib_subprocess" = "yes" ; then
6307  echo "CONFIG_HAS_GLIB_SUBPROCESS_TESTS=y" >> $config_host_mak
6308fi
6309if test "$gtk" = "yes" ; then
6310  echo "CONFIG_GTK=m" >> $config_host_mak
6311  echo "CONFIG_GTKABI=$gtkabi" >> $config_host_mak
6312  echo "GTK_CFLAGS=$gtk_cflags" >> $config_host_mak
6313  echo "GTK_LIBS=$gtk_libs" >> $config_host_mak
6314  if test "$gtk_gl" = "yes" ; then
6315    echo "CONFIG_GTK_GL=y" >> $config_host_mak
6316  fi
6317fi
6318echo "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak
6319if test "$gnutls" = "yes" ; then
6320  echo "CONFIG_GNUTLS=y" >> $config_host_mak
6321fi
6322if test "$gnutls_rnd" = "yes" ; then
6323  echo "CONFIG_GNUTLS_RND=y" >> $config_host_mak
6324fi
6325if test "$gcrypt" = "yes" ; then
6326  echo "CONFIG_GCRYPT=y" >> $config_host_mak
6327  if test "$gcrypt_hmac" = "yes" ; then
6328    echo "CONFIG_GCRYPT_HMAC=y" >> $config_host_mak
6329  fi
6330  if test "$gcrypt_kdf" = "yes" ; then
6331    echo "CONFIG_GCRYPT_KDF=y" >> $config_host_mak
6332  fi
6333fi
6334if test "$nettle" = "yes" ; then
6335  echo "CONFIG_NETTLE=y" >> $config_host_mak
6336  echo "CONFIG_NETTLE_VERSION_MAJOR=${nettle_version%%.*}" >> $config_host_mak
6337  if test "$nettle_kdf" = "yes" ; then
6338    echo "CONFIG_NETTLE_KDF=y" >> $config_host_mak
6339  fi
6340fi
6341if test "$tasn1" = "yes" ; then
6342  echo "CONFIG_TASN1=y" >> $config_host_mak
6343fi
6344if test "$have_ifaddrs_h" = "yes" ; then
6345    echo "HAVE_IFADDRS_H=y" >> $config_host_mak
6346fi
6347if test "$have_broken_size_max" = "yes" ; then
6348    echo "HAVE_BROKEN_SIZE_MAX=y" >> $config_host_mak
6349fi
6350
6351# Work around a system header bug with some kernel/XFS header
6352# versions where they both try to define 'struct fsxattr':
6353# xfs headers will not try to redefine structs from linux headers
6354# if this macro is set.
6355if test "$have_fsxattr" = "yes" ; then
6356    echo "HAVE_FSXATTR=y" >> $config_host_mak
6357fi
6358if test "$have_copy_file_range" = "yes" ; then
6359    echo "HAVE_COPY_FILE_RANGE=y" >> $config_host_mak
6360fi
6361if test "$vte" = "yes" ; then
6362  echo "CONFIG_VTE=y" >> $config_host_mak
6363  echo "VTE_CFLAGS=$vte_cflags" >> $config_host_mak
6364  echo "VTE_LIBS=$vte_libs" >> $config_host_mak
6365fi
6366if test "$virglrenderer" = "yes" ; then
6367  echo "CONFIG_VIRGL=y" >> $config_host_mak
6368  echo "VIRGL_CFLAGS=$virgl_cflags" >> $config_host_mak
6369  echo "VIRGL_LIBS=$virgl_libs" >> $config_host_mak
6370fi
6371if test "$xen" = "yes" ; then
6372  echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
6373  echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
6374  if test "$xen_pv_domain_build" = "yes" ; then
6375    echo "CONFIG_XEN_PV_DOMAIN_BUILD=y" >> $config_host_mak
6376  fi
6377fi
6378if test "$linux_aio" = "yes" ; then
6379  echo "CONFIG_LINUX_AIO=y" >> $config_host_mak
6380fi
6381if test "$attr" = "yes" ; then
6382  echo "CONFIG_ATTR=y" >> $config_host_mak
6383fi
6384if test "$libattr" = "yes" ; then
6385  echo "CONFIG_LIBATTR=y" >> $config_host_mak
6386fi
6387if test "$virtfs" = "yes" ; then
6388  echo "CONFIG_VIRTFS=y" >> $config_host_mak
6389fi
6390if test "$mpath" = "yes" ; then
6391  echo "CONFIG_MPATH=y" >> $config_host_mak
6392fi
6393if test "$vhost_scsi" = "yes" ; then
6394  echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
6395fi
6396if test "$vhost_net" = "yes" -a "$vhost_user" = "yes"; then
6397  echo "CONFIG_VHOST_NET_USED=y" >> $config_host_mak
6398fi
6399if test "$vhost_crypto" = "yes" ; then
6400  echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
6401fi
6402if test "$vhost_vsock" = "yes" ; then
6403  echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
6404fi
6405if test "$vhost_user" = "yes" ; then
6406  echo "CONFIG_VHOST_USER=y" >> $config_host_mak
6407fi
6408if test "$blobs" = "yes" ; then
6409  echo "INSTALL_BLOBS=yes" >> $config_host_mak
6410fi
6411if test "$iovec" = "yes" ; then
6412  echo "CONFIG_IOVEC=y" >> $config_host_mak
6413fi
6414if test "$preadv" = "yes" ; then
6415  echo "CONFIG_PREADV=y" >> $config_host_mak
6416fi
6417if test "$fdt" != "no" ; then
6418  echo "CONFIG_FDT=y" >> $config_host_mak
6419fi
6420if test "$membarrier" = "yes" ; then
6421  echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
6422fi
6423if test "$signalfd" = "yes" ; then
6424  echo "CONFIG_SIGNALFD=y" >> $config_host_mak
6425fi
6426if test "$tcg" = "yes"; then
6427  echo "CONFIG_TCG=y" >> $config_host_mak
6428  if test "$tcg_interpreter" = "yes" ; then
6429    echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
6430  fi
6431fi
6432if test "$fdatasync" = "yes" ; then
6433  echo "CONFIG_FDATASYNC=y" >> $config_host_mak
6434fi
6435if test "$madvise" = "yes" ; then
6436  echo "CONFIG_MADVISE=y" >> $config_host_mak
6437fi
6438if test "$posix_madvise" = "yes" ; then
6439  echo "CONFIG_POSIX_MADVISE=y" >> $config_host_mak
6440fi
6441if test "$posix_memalign" = "yes" ; then
6442  echo "CONFIG_POSIX_MEMALIGN=y" >> $config_host_mak
6443fi
6444
6445if test "$spice" = "yes" ; then
6446  echo "CONFIG_SPICE=y" >> $config_host_mak
6447fi
6448
6449if test "$smartcard" = "yes" ; then
6450  echo "CONFIG_SMARTCARD=y" >> $config_host_mak
6451  echo "SMARTCARD_CFLAGS=$libcacard_cflags" >> $config_host_mak
6452  echo "SMARTCARD_LIBS=$libcacard_libs" >> $config_host_mak
6453fi
6454
6455if test "$libusb" = "yes" ; then
6456  echo "CONFIG_USB_LIBUSB=y" >> $config_host_mak
6457  echo "LIBUSB_CFLAGS=$libusb_cflags" >> $config_host_mak
6458  echo "LIBUSB_LIBS=$libusb_libs" >> $config_host_mak
6459fi
6460
6461if test "$usb_redir" = "yes" ; then
6462  echo "CONFIG_USB_REDIR=y" >> $config_host_mak
6463  echo "USB_REDIR_CFLAGS=$usb_redir_cflags" >> $config_host_mak
6464  echo "USB_REDIR_LIBS=$usb_redir_libs" >> $config_host_mak
6465fi
6466
6467if test "$opengl" = "yes" ; then
6468  echo "CONFIG_OPENGL=y" >> $config_host_mak
6469  echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
6470  if test "$opengl_dmabuf" = "yes" ; then
6471    echo "CONFIG_OPENGL_DMABUF=y" >> $config_host_mak
6472  fi
6473fi
6474
6475if test "$malloc_trim" = "yes" ; then
6476  echo "CONFIG_MALLOC_TRIM=y" >> $config_host_mak
6477fi
6478
6479if test "$avx2_opt" = "yes" ; then
6480  echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
6481fi
6482
6483if test "$lzo" = "yes" ; then
6484  echo "CONFIG_LZO=y" >> $config_host_mak
6485fi
6486
6487if test "$snappy" = "yes" ; then
6488  echo "CONFIG_SNAPPY=y" >> $config_host_mak
6489fi
6490
6491if test "$bzip2" = "yes" ; then
6492  echo "CONFIG_BZIP2=y" >> $config_host_mak
6493  echo "BZIP2_LIBS=-lbz2" >> $config_host_mak
6494fi
6495
6496if test "$libiscsi" = "yes" ; then
6497  echo "CONFIG_LIBISCSI=m" >> $config_host_mak
6498  echo "LIBISCSI_CFLAGS=$libiscsi_cflags" >> $config_host_mak
6499  echo "LIBISCSI_LIBS=$libiscsi_libs" >> $config_host_mak
6500fi
6501
6502if test "$libnfs" = "yes" ; then
6503  echo "CONFIG_LIBNFS=m" >> $config_host_mak
6504  echo "LIBNFS_LIBS=$libnfs_libs" >> $config_host_mak
6505fi
6506
6507if test "$seccomp" = "yes"; then
6508  echo "CONFIG_SECCOMP=y" >> $config_host_mak
6509  echo "SECCOMP_CFLAGS=$seccomp_cflags" >> $config_host_mak
6510  echo "SECCOMP_LIBS=$seccomp_libs" >> $config_host_mak
6511fi
6512
6513# XXX: suppress that
6514if [ "$bsd" = "yes" ] ; then
6515  echo "CONFIG_BSD=y" >> $config_host_mak
6516fi
6517
6518if test "$localtime_r" = "yes" ; then
6519  echo "CONFIG_LOCALTIME_R=y" >> $config_host_mak
6520fi
6521if test "$qom_cast_debug" = "yes" ; then
6522  echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak
6523fi
6524if test "$rbd" = "yes" ; then
6525  echo "CONFIG_RBD=m" >> $config_host_mak
6526  echo "RBD_CFLAGS=$rbd_cflags" >> $config_host_mak
6527  echo "RBD_LIBS=$rbd_libs" >> $config_host_mak
6528fi
6529
6530echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
6531if test "$coroutine_pool" = "yes" ; then
6532  echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
6533else
6534  echo "CONFIG_COROUTINE_POOL=0" >> $config_host_mak
6535fi
6536
6537if test "$debug_stack_usage" = "yes" ; then
6538  echo "CONFIG_DEBUG_STACK_USAGE=y" >> $config_host_mak
6539fi
6540
6541if test "$crypto_afalg" = "yes" ; then
6542  echo "CONFIG_AF_ALG=y" >> $config_host_mak
6543fi
6544
6545if test "$open_by_handle_at" = "yes" ; then
6546  echo "CONFIG_OPEN_BY_HANDLE=y" >> $config_host_mak
6547fi
6548
6549if test "$linux_magic_h" = "yes" ; then
6550  echo "CONFIG_LINUX_MAGIC_H=y" >> $config_host_mak
6551fi
6552
6553if test "$pragma_diagnostic_available" = "yes" ; then
6554  echo "CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE=y" >> $config_host_mak
6555fi
6556
6557if test "$valgrind_h" = "yes" ; then
6558  echo "CONFIG_VALGRIND_H=y" >> $config_host_mak
6559fi
6560
6561if test "$have_asan_iface_fiber" = "yes" ; then
6562    echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
6563fi
6564
6565if test "$has_environ" = "yes" ; then
6566  echo "CONFIG_HAS_ENVIRON=y" >> $config_host_mak
6567fi
6568
6569if test "$cpuid_h" = "yes" ; then
6570  echo "CONFIG_CPUID_H=y" >> $config_host_mak
6571fi
6572
6573if test "$int128" = "yes" ; then
6574  echo "CONFIG_INT128=y" >> $config_host_mak
6575fi
6576
6577if test "$atomic128" = "yes" ; then
6578  echo "CONFIG_ATOMIC128=y" >> $config_host_mak
6579fi
6580
6581if test "$atomic64" = "yes" ; then
6582  echo "CONFIG_ATOMIC64=y" >> $config_host_mak
6583fi
6584
6585if test "$vector16" = "yes" ; then
6586  echo "CONFIG_VECTOR16=y" >> $config_host_mak
6587fi
6588
6589if test "$getauxval" = "yes" ; then
6590  echo "CONFIG_GETAUXVAL=y" >> $config_host_mak
6591fi
6592
6593if test "$glusterfs" = "yes" ; then
6594  echo "CONFIG_GLUSTERFS=m" >> $config_host_mak
6595  echo "GLUSTERFS_CFLAGS=$glusterfs_cflags" >> $config_host_mak
6596  echo "GLUSTERFS_LIBS=$glusterfs_libs" >> $config_host_mak
6597fi
6598
6599if test "$glusterfs_xlator_opt" = "yes" ; then
6600  echo "CONFIG_GLUSTERFS_XLATOR_OPT=y" >> $config_host_mak
6601fi
6602
6603if test "$glusterfs_discard" = "yes" ; then
6604  echo "CONFIG_GLUSTERFS_DISCARD=y" >> $config_host_mak
6605fi
6606
6607if test "$glusterfs_fallocate" = "yes" ; then
6608  echo "CONFIG_GLUSTERFS_FALLOCATE=y" >> $config_host_mak
6609fi
6610
6611if test "$glusterfs_zerofill" = "yes" ; then
6612  echo "CONFIG_GLUSTERFS_ZEROFILL=y" >> $config_host_mak
6613fi
6614
6615if test "$libssh2" = "yes" ; then
6616  echo "CONFIG_LIBSSH2=m" >> $config_host_mak
6617  echo "LIBSSH2_CFLAGS=$libssh2_cflags" >> $config_host_mak
6618  echo "LIBSSH2_LIBS=$libssh2_libs" >> $config_host_mak
6619fi
6620
6621if test "$live_block_migration" = "yes" ; then
6622  echo "CONFIG_LIVE_BLOCK_MIGRATION=y" >> $config_host_mak
6623fi
6624
6625if test "$tpm" = "yes"; then
6626  echo 'CONFIG_TPM=$(CONFIG_SOFTMMU)' >> $config_host_mak
6627  # TPM passthrough support?
6628  if test "$tpm_passthrough" = "yes"; then
6629    echo "CONFIG_TPM_PASSTHROUGH=y" >> $config_host_mak
6630  fi
6631  # TPM emulator support?
6632  if test "$tpm_emulator" = "yes"; then
6633    echo "CONFIG_TPM_EMULATOR=y" >> $config_host_mak
6634  fi
6635fi
6636
6637echo "TRACE_BACKENDS=$trace_backends" >> $config_host_mak
6638if have_backend "nop"; then
6639  echo "CONFIG_TRACE_NOP=y" >> $config_host_mak
6640fi
6641if have_backend "simple"; then
6642  echo "CONFIG_TRACE_SIMPLE=y" >> $config_host_mak
6643  # Set the appropriate trace file.
6644  trace_file="\"$trace_file-\" FMT_pid"
6645fi
6646if have_backend "log"; then
6647  echo "CONFIG_TRACE_LOG=y" >> $config_host_mak
6648fi
6649if have_backend "ust"; then
6650  echo "CONFIG_TRACE_UST=y" >> $config_host_mak
6651fi
6652if have_backend "dtrace"; then
6653  echo "CONFIG_TRACE_DTRACE=y" >> $config_host_mak
6654  if test "$trace_backend_stap" = "yes" ; then
6655    echo "CONFIG_TRACE_SYSTEMTAP=y" >> $config_host_mak
6656  fi
6657fi
6658if have_backend "ftrace"; then
6659  if test "$linux" = "yes" ; then
6660    echo "CONFIG_TRACE_FTRACE=y" >> $config_host_mak
6661  else
6662    feature_not_found "ftrace(trace backend)" "ftrace requires Linux"
6663  fi
6664fi
6665if have_backend "syslog"; then
6666  if test "$posix_syslog" = "yes" ; then
6667    echo "CONFIG_TRACE_SYSLOG=y" >> $config_host_mak
6668  else
6669    feature_not_found "syslog(trace backend)" "syslog not available"
6670  fi
6671fi
6672echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
6673
6674if test "$rdma" = "yes" ; then
6675  echo "CONFIG_RDMA=y" >> $config_host_mak
6676  echo "RDMA_LIBS=$rdma_libs" >> $config_host_mak
6677fi
6678
6679if test "$have_rtnetlink" = "yes" ; then
6680  echo "CONFIG_RTNETLINK=y" >> $config_host_mak
6681fi
6682
6683if test "$libxml2" = "yes" ; then
6684  echo "CONFIG_LIBXML2=y" >> $config_host_mak
6685  echo "LIBXML2_CFLAGS=$libxml2_cflags" >> $config_host_mak
6686  echo "LIBXML2_LIBS=$libxml2_libs" >> $config_host_mak
6687fi
6688
6689if test "$replication" = "yes" ; then
6690  echo "CONFIG_REPLICATION=y" >> $config_host_mak
6691fi
6692
6693if test "$have_af_vsock" = "yes" ; then
6694  echo "CONFIG_AF_VSOCK=y" >> $config_host_mak
6695fi
6696
6697if test "$have_sysmacros" = "yes" ; then
6698  echo "CONFIG_SYSMACROS=y" >> $config_host_mak
6699fi
6700
6701if test "$have_static_assert" = "yes" ; then
6702  echo "CONFIG_STATIC_ASSERT=y" >> $config_host_mak
6703fi
6704
6705if test "$have_utmpx" = "yes" ; then
6706  echo "HAVE_UTMPX=y" >> $config_host_mak
6707fi
6708
6709if test "$ivshmem" = "yes" ; then
6710  echo "CONFIG_IVSHMEM=y" >> $config_host_mak
6711fi
6712if test "$capstone" != "no" ; then
6713  echo "CONFIG_CAPSTONE=y" >> $config_host_mak
6714fi
6715if test "$debug_mutex" = "yes" ; then
6716  echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak
6717fi
6718
6719# Hold two types of flag:
6720#   CONFIG_THREAD_SETNAME_BYTHREAD  - we've got a way of setting the name on
6721#                                     a thread we have a handle to
6722#   CONFIG_PTHREAD_SETNAME_NP       - A way of doing it on a particular
6723#                                     platform
6724if test "$pthread_setname_np" = "yes" ; then
6725  echo "CONFIG_THREAD_SETNAME_BYTHREAD=y" >> $config_host_mak
6726  echo "CONFIG_PTHREAD_SETNAME_NP=y" >> $config_host_mak
6727fi
6728
6729if test "$vxhs" = "yes" ; then
6730  echo "CONFIG_VXHS=y" >> $config_host_mak
6731  echo "VXHS_LIBS=$vxhs_libs" >> $config_host_mak
6732fi
6733
6734if test "$tcg_interpreter" = "yes"; then
6735  QEMU_INCLUDES="-iquote \$(SRC_PATH)/tcg/tci $QEMU_INCLUDES"
6736elif test "$ARCH" = "sparc64" ; then
6737  QEMU_INCLUDES="-iquote \$(SRC_PATH)/tcg/sparc $QEMU_INCLUDES"
6738elif test "$ARCH" = "s390x" ; then
6739  QEMU_INCLUDES="-iquote \$(SRC_PATH)/tcg/s390 $QEMU_INCLUDES"
6740elif test "$ARCH" = "x86_64" -o "$ARCH" = "x32" ; then
6741  QEMU_INCLUDES="-iquote \$(SRC_PATH)/tcg/i386 $QEMU_INCLUDES"
6742elif test "$ARCH" = "ppc64" ; then
6743  QEMU_INCLUDES="-iquote \$(SRC_PATH)/tcg/ppc $QEMU_INCLUDES"
6744else
6745  QEMU_INCLUDES="-iquote \$(SRC_PATH)/tcg/\$(ARCH) $QEMU_INCLUDES"
6746fi
6747QEMU_INCLUDES="-iquote \$(SRC_PATH)/tcg $QEMU_INCLUDES"
6748
6749echo "TOOLS=$tools" >> $config_host_mak
6750echo "ROMS=$roms" >> $config_host_mak
6751echo "MAKE=$make" >> $config_host_mak
6752echo "INSTALL=$install" >> $config_host_mak
6753echo "INSTALL_DIR=$install -d -m 0755" >> $config_host_mak
6754echo "INSTALL_DATA=$install -c -m 0644" >> $config_host_mak
6755echo "INSTALL_PROG=$install -c -m 0755" >> $config_host_mak
6756echo "INSTALL_LIB=$install -c -m 0644" >> $config_host_mak
6757echo "PYTHON=$python" >> $config_host_mak
6758echo "CC=$cc" >> $config_host_mak
6759if $iasl -h > /dev/null 2>&1; then
6760  echo "IASL=$iasl" >> $config_host_mak
6761fi
6762echo "HOST_CC=$host_cc" >> $config_host_mak
6763echo "CXX=$cxx" >> $config_host_mak
6764echo "OBJCC=$objcc" >> $config_host_mak
6765echo "AR=$ar" >> $config_host_mak
6766echo "ARFLAGS=$ARFLAGS" >> $config_host_mak
6767echo "AS=$as" >> $config_host_mak
6768echo "CCAS=$ccas" >> $config_host_mak
6769echo "CPP=$cpp" >> $config_host_mak
6770echo "OBJCOPY=$objcopy" >> $config_host_mak
6771echo "LD=$ld" >> $config_host_mak
6772echo "RANLIB=$ranlib" >> $config_host_mak
6773echo "NM=$nm" >> $config_host_mak
6774echo "WINDRES=$windres" >> $config_host_mak
6775echo "CFLAGS=$CFLAGS" >> $config_host_mak
6776echo "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
6777echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
6778echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
6779echo "QEMU_INCLUDES=$QEMU_INCLUDES" >> $config_host_mak
6780if test "$sparse" = "yes" ; then
6781  echo "CC           := REAL_CC=\"\$(CC)\" cgcc"       >> $config_host_mak
6782  echo "CPP          := REAL_CC=\"\$(CPP)\" cgcc"      >> $config_host_mak
6783  echo "CXX          := REAL_CC=\"\$(CXX)\" cgcc"      >> $config_host_mak
6784  echo "HOST_CC      := REAL_CC=\"\$(HOST_CC)\" cgcc"  >> $config_host_mak
6785  echo "QEMU_CFLAGS  += -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-non-pointer-null" >> $config_host_mak
6786fi
6787if test "$cross_prefix" != ""; then
6788  echo "AUTOCONF_HOST := --host=${cross_prefix%-}"     >> $config_host_mak
6789else
6790  echo "AUTOCONF_HOST := "                             >> $config_host_mak
6791fi
6792echo "LDFLAGS=$LDFLAGS" >> $config_host_mak
6793echo "LDFLAGS_NOPIE=$LDFLAGS_NOPIE" >> $config_host_mak
6794echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
6795echo "LD_REL_FLAGS=$LD_REL_FLAGS" >> $config_host_mak
6796echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
6797echo "LIBS+=$LIBS" >> $config_host_mak
6798echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak
6799echo "PTHREAD_LIB=$PTHREAD_LIB" >> $config_host_mak
6800echo "EXESUF=$EXESUF" >> $config_host_mak
6801echo "DSOSUF=$DSOSUF" >> $config_host_mak
6802echo "LDFLAGS_SHARED=$LDFLAGS_SHARED" >> $config_host_mak
6803echo "LIBS_QGA+=$libs_qga" >> $config_host_mak
6804echo "TASN1_LIBS=$tasn1_libs" >> $config_host_mak
6805echo "TASN1_CFLAGS=$tasn1_cflags" >> $config_host_mak
6806echo "POD2MAN=$POD2MAN" >> $config_host_mak
6807echo "TRANSLATE_OPT_CFLAGS=$TRANSLATE_OPT_CFLAGS" >> $config_host_mak
6808if test "$gcov" = "yes" ; then
6809  echo "CONFIG_GCOV=y" >> $config_host_mak
6810  echo "GCOV=$gcov_tool" >> $config_host_mak
6811fi
6812
6813if test "$docker" != "no"; then
6814    echo "HAVE_USER_DOCKER=y" >> $config_host_mak
6815fi
6816
6817# use included Linux headers
6818if test "$linux" = "yes" ; then
6819  mkdir -p linux-headers
6820  case "$cpu" in
6821  i386|x86_64|x32)
6822    linux_arch=x86
6823    ;;
6824  ppcemb|ppc|ppc64)
6825    linux_arch=powerpc
6826    ;;
6827  s390x)
6828    linux_arch=s390
6829    ;;
6830  aarch64)
6831    linux_arch=arm64
6832    ;;
6833  mips64)
6834    linux_arch=mips
6835    ;;
6836  *)
6837    # For most CPUs the kernel architecture name and QEMU CPU name match.
6838    linux_arch="$cpu"
6839    ;;
6840  esac
6841    # For non-KVM architectures we will not have asm headers
6842    if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
6843      symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
6844    fi
6845fi
6846
6847for target in $target_list; do
6848target_dir="$target"
6849config_target_mak=$target_dir/config-target.mak
6850target_name=$(echo $target | cut -d '-' -f 1)
6851target_bigendian="no"
6852
6853case "$target_name" in
6854  armeb|aarch64_be|hppa|lm32|m68k|microblaze|mips|mipsn32|mips64|moxie|or1k|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb)
6855  target_bigendian=yes
6856  ;;
6857esac
6858target_softmmu="no"
6859target_user_only="no"
6860target_linux_user="no"
6861target_bsd_user="no"
6862case "$target" in
6863  ${target_name}-softmmu)
6864    target_softmmu="yes"
6865    ;;
6866  ${target_name}-linux-user)
6867    target_user_only="yes"
6868    target_linux_user="yes"
6869    ;;
6870  ${target_name}-bsd-user)
6871    target_user_only="yes"
6872    target_bsd_user="yes"
6873    ;;
6874  *)
6875    error_exit "Target '$target' not recognised"
6876    exit 1
6877    ;;
6878esac
6879
6880target_compiler=""
6881target_compiler_static=""
6882target_compiler_cflags=""
6883
6884mkdir -p $target_dir
6885echo "# Automatically generated by configure - do not modify" > $config_target_mak
6886
6887bflt="no"
6888mttcg="no"
6889interp_prefix1=$(echo "$interp_prefix" | sed "s/%M/$target_name/g")
6890gdb_xml_files=""
6891
6892TARGET_ARCH="$target_name"
6893TARGET_BASE_ARCH=""
6894TARGET_ABI_DIR=""
6895
6896case "$target_name" in
6897  i386)
6898    gdb_xml_files="i386-32bit.xml i386-32bit-core.xml i386-32bit-sse.xml"
6899    target_compiler=$cross_cc_i386
6900    target_compiler_cflags=$cross_cc_ccflags_i386
6901  ;;
6902  x86_64)
6903    TARGET_BASE_ARCH=i386
6904    gdb_xml_files="i386-64bit.xml i386-64bit-core.xml i386-64bit-sse.xml"
6905    target_compiler=$cross_cc_x86_64
6906  ;;
6907  alpha)
6908    mttcg="yes"
6909    target_compiler=$cross_cc_alpha
6910  ;;
6911  arm|armeb)
6912    TARGET_ARCH=arm
6913    bflt="yes"
6914    mttcg="yes"
6915    gdb_xml_files="arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"
6916    target_compiler=$cross_cc_arm
6917    eval "target_compiler_cflags=\$cross_cc_cflags_${target_name}"
6918  ;;
6919  aarch64|aarch64_be)
6920    TARGET_ARCH=aarch64
6921    TARGET_BASE_ARCH=arm
6922    bflt="yes"
6923    mttcg="yes"
6924    gdb_xml_files="aarch64-core.xml aarch64-fpu.xml arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"
6925    target_compiler=$cross_cc_aarch64
6926    eval "target_compiler_cflags=\$cross_cc_cflags_${target_name}"
6927  ;;
6928  cris)
6929    target_compiler=$cross_cc_cris
6930  ;;
6931  hppa)
6932    mttcg="yes"
6933    target_compiler=$cross_cc_hppa
6934  ;;
6935  lm32)
6936    target_compiler=$cross_cc_lm32
6937  ;;
6938  m68k)
6939    bflt="yes"
6940    gdb_xml_files="cf-core.xml cf-fp.xml m68k-fp.xml"
6941    target_compiler=$cross_cc_m68k
6942  ;;
6943  microblaze|microblazeel)
6944    TARGET_ARCH=microblaze
6945    bflt="yes"
6946    echo "TARGET_ABI32=y" >> $config_target_mak
6947    target_compiler=$cross_cc_microblaze
6948  ;;
6949  mips|mipsel)
6950    TARGET_ARCH=mips
6951    target_compiler=$cross_cc_mips
6952    echo "TARGET_ABI_MIPSO32=y" >> $config_target_mak
6953  ;;
6954  mipsn32|mipsn32el)
6955    TARGET_ARCH=mips64
6956    TARGET_BASE_ARCH=mips
6957    target_compiler=$cross_cc_mipsn32
6958    echo "TARGET_ABI_MIPSN32=y" >> $config_target_mak
6959    echo "TARGET_ABI32=y" >> $config_target_mak
6960  ;;
6961  mips64|mips64el)
6962    TARGET_ARCH=mips64
6963    TARGET_BASE_ARCH=mips
6964    target_compiler=$cross_cc_mips64
6965    echo "TARGET_ABI_MIPSN64=y" >> $config_target_mak
6966  ;;
6967  moxie)
6968    target_compiler=$cross_cc_moxie
6969  ;;
6970  nios2)
6971    target_compiler=$cross_cc_nios2
6972  ;;
6973  or1k)
6974    target_compiler=$cross_cc_or1k
6975    TARGET_ARCH=openrisc
6976    TARGET_BASE_ARCH=openrisc
6977  ;;
6978  ppc)
6979    gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
6980    target_compiler=$cross_cc_powerpc
6981  ;;
6982  ppcemb)
6983    TARGET_BASE_ARCH=ppc
6984    TARGET_ABI_DIR=ppc
6985    gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
6986    target_compiler=$cross_cc_ppcemb
6987  ;;
6988  ppc64)
6989    TARGET_BASE_ARCH=ppc
6990    TARGET_ABI_DIR=ppc
6991    mttcg=yes
6992    gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml power-vsx.xml"
6993    target_compiler=$cross_cc_ppc64
6994  ;;
6995  ppc64le)
6996    TARGET_ARCH=ppc64
6997    TARGET_BASE_ARCH=ppc
6998    TARGET_ABI_DIR=ppc
6999    mttcg=yes
7000    gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml power-vsx.xml"
7001    target_compiler=$cross_cc_ppc64le
7002  ;;
7003  ppc64abi32)
7004    TARGET_ARCH=ppc64
7005    TARGET_BASE_ARCH=ppc
7006    TARGET_ABI_DIR=ppc
7007    echo "TARGET_ABI32=y" >> $config_target_mak
7008    gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml power-vsx.xml"
7009    target_compiler=$cross_cc_ppc64abi32
7010  ;;
7011  riscv32)
7012    TARGET_BASE_ARCH=riscv
7013    TARGET_ABI_DIR=riscv
7014    mttcg=yes
7015    target_compiler=$cross_cc_riscv32
7016  ;;
7017  riscv64)
7018    TARGET_BASE_ARCH=riscv
7019    TARGET_ABI_DIR=riscv
7020    mttcg=yes
7021    target_compiler=$cross_cc_riscv64
7022  ;;
7023  sh4|sh4eb)
7024    TARGET_ARCH=sh4
7025    bflt="yes"
7026    target_compiler=$cross_cc_sh4
7027  ;;
7028  sparc)
7029    target_compiler=$cross_cc_sparc
7030  ;;
7031  sparc64)
7032    TARGET_BASE_ARCH=sparc
7033    target_compiler=$cross_cc_sparc64
7034  ;;
7035  sparc32plus)
7036    TARGET_ARCH=sparc64
7037    TARGET_BASE_ARCH=sparc
7038    TARGET_ABI_DIR=sparc
7039    target_compiler=$cross_cc_sparc32plus
7040    echo "TARGET_ABI32=y" >> $config_target_mak
7041  ;;
7042  s390x)
7043    mttcg=yes
7044    gdb_xml_files="s390x-core64.xml s390-acr.xml s390-fpr.xml s390-vx.xml s390-cr.xml s390-virt.xml s390-gs.xml"
7045    target_compiler=$cross_cc_s390x
7046  ;;
7047  tilegx)
7048    target_compiler=$cross_cc_tilegx
7049  ;;
7050  tricore)
7051    target_compiler=$cross_cc_tricore
7052  ;;
7053  unicore32)
7054    target_compiler=$cross_cc_unicore32
7055  ;;
7056  xtensa|xtensaeb)
7057    TARGET_ARCH=xtensa
7058    mttcg="yes"
7059    target_compiler=$cross_cc_xtensa
7060  ;;
7061  *)
7062    error_exit "Unsupported target CPU"
7063  ;;
7064esac
7065# TARGET_BASE_ARCH needs to be defined after TARGET_ARCH
7066if [ "$TARGET_BASE_ARCH" = "" ]; then
7067  TARGET_BASE_ARCH=$TARGET_ARCH
7068fi
7069
7070# Do we have a cross compiler for this target?
7071if has $target_compiler; then
7072
7073    write_c_skeleton
7074
7075    if ! do_compiler "$target_compiler" $target_compiler_cflags -o $TMPE $TMPC -static ; then
7076        # For host systems we might get away with building without -static
7077        if ! do_compiler "$target_compiler" $target_compiler_cflags -o $TMPE $TMPC ; then
7078            target_compiler=""
7079        else
7080            enabled_cross_compilers="${enabled_cross_compilers} '${target_compiler}'"
7081            target_compiler_static="n"
7082        fi
7083    else
7084        enabled_cross_compilers="${enabled_cross_compilers} '${target_compiler}'"
7085        target_compiler_static="y"
7086    fi
7087else
7088    target_compiler=""
7089fi
7090
7091symlink "$source_path/Makefile.target" "$target_dir/Makefile"
7092
7093upper() {
7094    echo "$@"| LC_ALL=C tr '[a-z]' '[A-Z]'
7095}
7096
7097target_arch_name="$(upper $TARGET_ARCH)"
7098echo "TARGET_$target_arch_name=y" >> $config_target_mak
7099echo "TARGET_NAME=$target_name" >> $config_target_mak
7100echo "TARGET_BASE_ARCH=$TARGET_BASE_ARCH" >> $config_target_mak
7101if [ "$TARGET_ABI_DIR" = "" ]; then
7102  TARGET_ABI_DIR=$TARGET_ARCH
7103fi
7104echo "TARGET_ABI_DIR=$TARGET_ABI_DIR" >> $config_target_mak
7105if [ "$HOST_VARIANT_DIR" != "" ]; then
7106    echo "HOST_VARIANT_DIR=$HOST_VARIANT_DIR" >> $config_target_mak
7107fi
7108
7109if supported_xen_target $target; then
7110    echo "CONFIG_XEN=y" >> $config_target_mak
7111    if test "$xen_pci_passthrough" = yes; then
7112        echo "CONFIG_XEN_PCI_PASSTHROUGH=y" >> "$config_target_mak"
7113    fi
7114fi
7115if supported_kvm_target $target; then
7116    echo "CONFIG_KVM=y" >> $config_target_mak
7117    if test "$vhost_net" = "yes" ; then
7118        echo "CONFIG_VHOST_NET=y" >> $config_target_mak
7119        if test "$vhost_user" = "yes" ; then
7120            echo "CONFIG_VHOST_USER_NET_TEST_$target_name=y" >> $config_host_mak
7121        fi
7122    fi
7123fi
7124if supported_hax_target $target; then
7125    echo "CONFIG_HAX=y" >> $config_target_mak
7126fi
7127if supported_hvf_target $target; then
7128    echo "CONFIG_HVF=y" >> $config_target_mak
7129fi
7130if supported_whpx_target $target; then
7131    echo "CONFIG_WHPX=y" >> $config_target_mak
7132fi
7133if test "$target_bigendian" = "yes" ; then
7134  echo "TARGET_WORDS_BIGENDIAN=y" >> $config_target_mak
7135fi
7136if test "$target_softmmu" = "yes" ; then
7137  echo "CONFIG_SOFTMMU=y" >> $config_target_mak
7138  if test "$mttcg" = "yes" ; then
7139    echo "TARGET_SUPPORTS_MTTCG=y" >> $config_target_mak
7140  fi
7141fi
7142if test "$target_user_only" = "yes" ; then
7143  echo "CONFIG_USER_ONLY=y" >> $config_target_mak
7144  echo "CONFIG_QEMU_INTERP_PREFIX=\"$interp_prefix1\"" >> $config_target_mak
7145fi
7146if test "$target_linux_user" = "yes" ; then
7147  echo "CONFIG_LINUX_USER=y" >> $config_target_mak
7148fi
7149list=""
7150if test ! -z "$gdb_xml_files" ; then
7151  for x in $gdb_xml_files; do
7152    list="$list $source_path/gdb-xml/$x"
7153  done
7154  echo "TARGET_XML_FILES=$list" >> $config_target_mak
7155fi
7156
7157if test "$target_user_only" = "yes" -a "$bflt" = "yes"; then
7158  echo "TARGET_HAS_BFLT=y" >> $config_target_mak
7159fi
7160if test "$target_bsd_user" = "yes" ; then
7161  echo "CONFIG_BSD_USER=y" >> $config_target_mak
7162fi
7163
7164if test -n "$target_compiler"; then
7165  echo "CROSS_CC_GUEST=\"$target_compiler\"" >> $config_target_mak
7166
7167  if test -n "$target_compiler_static"; then
7168      echo "CROSS_CC_GUEST_STATIC=$target_compiler_static" >> $config_target_mak
7169  fi
7170
7171  if test -n "$target_compiler_cflags"; then
7172      echo "CROSS_CC_GUEST_CFLAGS=$target_compiler_cflags" >> $config_target_mak
7173  fi
7174fi
7175
7176
7177# generate QEMU_CFLAGS/LDFLAGS for targets
7178
7179cflags=""
7180ldflags=""
7181
7182disas_config() {
7183  echo "CONFIG_${1}_DIS=y" >> $config_target_mak
7184  echo "CONFIG_${1}_DIS=y" >> config-all-disas.mak
7185}
7186
7187for i in $ARCH $TARGET_BASE_ARCH ; do
7188  case "$i" in
7189  alpha)
7190    disas_config "ALPHA"
7191  ;;
7192  aarch64)
7193    if test -n "${cxx}"; then
7194      disas_config "ARM_A64"
7195    fi
7196  ;;
7197  arm)
7198    disas_config "ARM"
7199    if test -n "${cxx}"; then
7200      disas_config "ARM_A64"
7201    fi
7202  ;;
7203  cris)
7204    disas_config "CRIS"
7205  ;;
7206  hppa)
7207    disas_config "HPPA"
7208  ;;
7209  i386|x86_64|x32)
7210    disas_config "I386"
7211  ;;
7212  lm32)
7213    disas_config "LM32"
7214  ;;
7215  m68k)
7216    disas_config "M68K"
7217  ;;
7218  microblaze*)
7219    disas_config "MICROBLAZE"
7220  ;;
7221  mips*)
7222    disas_config "MIPS"
7223  ;;
7224  moxie*)
7225    disas_config "MOXIE"
7226  ;;
7227  nios2)
7228    disas_config "NIOS2"
7229  ;;
7230  or1k)
7231    disas_config "OPENRISC"
7232  ;;
7233  ppc*)
7234    disas_config "PPC"
7235  ;;
7236  riscv)
7237    disas_config "RISCV"
7238  ;;
7239  s390*)
7240    disas_config "S390"
7241  ;;
7242  sh4)
7243    disas_config "SH4"
7244  ;;
7245  sparc*)
7246    disas_config "SPARC"
7247  ;;
7248  xtensa*)
7249    disas_config "XTENSA"
7250  ;;
7251  esac
7252done
7253if test "$tcg_interpreter" = "yes" ; then
7254  disas_config "TCI"
7255fi
7256
7257case "$ARCH" in
7258alpha)
7259  # Ensure there's only a single GP
7260  cflags="-msmall-data $cflags"
7261;;
7262esac
7263
7264if test "$gprof" = "yes" ; then
7265  echo "TARGET_GPROF=yes" >> $config_target_mak
7266  if test "$target_linux_user" = "yes" ; then
7267    cflags="-p $cflags"
7268    ldflags="-p $ldflags"
7269  fi
7270  if test "$target_softmmu" = "yes" ; then
7271    ldflags="-p $ldflags"
7272    echo "GPROF_CFLAGS=-p" >> $config_target_mak
7273  fi
7274fi
7275
7276if test "$target_linux_user" = "yes" -o "$target_bsd_user" = "yes" ; then
7277  ldflags="$ldflags $textseg_ldflags"
7278fi
7279
7280# Newer kernels on s390 check for an S390_PGSTE program header and
7281# enable the pgste page table extensions in that case. This makes
7282# the vm.allocate_pgste sysctl unnecessary. We enable this program
7283# header if
7284#  - we build on s390x
7285#  - we build the system emulation for s390x (qemu-system-s390x)
7286#  - KVM is enabled
7287#  - the linker supports --s390-pgste
7288if test "$TARGET_ARCH" = "s390x" -a "$target_softmmu" = "yes"  -a "$ARCH" = "s390x" -a "$kvm" = "yes"; then
7289    if ld_has --s390-pgste ; then
7290        ldflags="-Wl,--s390-pgste $ldflags"
7291    fi
7292fi
7293
7294echo "LDFLAGS+=$ldflags" >> $config_target_mak
7295echo "QEMU_CFLAGS+=$cflags" >> $config_target_mak
7296
7297done # for target in $targets
7298
7299if test -n "$enabled_cross_compilers"; then
7300    echo
7301    echo "NOTE: cross-compilers enabled: $enabled_cross_compilers"
7302fi
7303
7304if [ "$fdt" = "git" ]; then
7305  echo "config-host.h: subdir-dtc" >> $config_host_mak
7306fi
7307if [ "$capstone" = "git" -o "$capstone" = "internal" ]; then
7308  echo "config-host.h: subdir-capstone" >> $config_host_mak
7309fi
7310if test -n "$LIBCAPSTONE"; then
7311  echo "LIBCAPSTONE=$LIBCAPSTONE" >> $config_host_mak
7312fi
7313
7314if test "$numa" = "yes"; then
7315  echo "CONFIG_NUMA=y" >> $config_host_mak
7316fi
7317
7318if test "$ccache_cpp2" = "yes"; then
7319  echo "export CCACHE_CPP2=y" >> $config_host_mak
7320fi
7321
7322# build tree in object directory in case the source is not in the current directory
7323DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos tests/qapi-schema tests/tcg/xtensa tests/qemu-iotests tests/vm"
7324DIRS="$DIRS docs docs/interop fsdev scsi"
7325DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas pc-bios/s390-ccw"
7326DIRS="$DIRS roms/seabios roms/vgabios"
7327FILES="Makefile tests/tcg/Makefile qdict-test-data.txt"
7328FILES="$FILES tests/tcg/cris/Makefile tests/tcg/cris/.gdbinit"
7329FILES="$FILES tests/tcg/lm32/Makefile tests/tcg/xtensa/Makefile po/Makefile"
7330FILES="$FILES pc-bios/optionrom/Makefile pc-bios/keymaps"
7331FILES="$FILES pc-bios/spapr-rtas/Makefile"
7332FILES="$FILES pc-bios/s390-ccw/Makefile"
7333FILES="$FILES roms/seabios/Makefile roms/vgabios/Makefile"
7334FILES="$FILES pc-bios/qemu-icon.bmp"
7335FILES="$FILES .gdbinit scripts" # scripts needed by relative path in .gdbinit
7336for bios_file in \
7337    $source_path/pc-bios/*.bin \
7338    $source_path/pc-bios/*.lid \
7339    $source_path/pc-bios/*.aml \
7340    $source_path/pc-bios/*.rom \
7341    $source_path/pc-bios/*.dtb \
7342    $source_path/pc-bios/*.img \
7343    $source_path/pc-bios/openbios-* \
7344    $source_path/pc-bios/u-boot.* \
7345    $source_path/pc-bios/palcode-*
7346do
7347    FILES="$FILES pc-bios/$(basename $bios_file)"
7348done
7349for test_file in $(find $source_path/tests/acpi-test-data -type f)
7350do
7351    FILES="$FILES tests/acpi-test-data$(echo $test_file | sed -e 's/.*acpi-test-data//')"
7352done
7353mkdir -p $DIRS
7354for f in $FILES ; do
7355    if [ -e "$source_path/$f" ] && [ "$pwd_is_source_path" != "y" ]; then
7356        symlink "$source_path/$f" "$f"
7357    fi
7358done
7359
7360# temporary config to build submodules
7361for rom in seabios vgabios ; do
7362    config_mak=roms/$rom/config.mak
7363    echo "# Automatically generated by configure - do not modify" > $config_mak
7364    echo "SRC_PATH=$source_path/roms/$rom" >> $config_mak
7365    echo "AS=$as" >> $config_mak
7366    echo "CCAS=$ccas" >> $config_mak
7367    echo "CC=$cc" >> $config_mak
7368    echo "BCC=bcc" >> $config_mak
7369    echo "CPP=$cpp" >> $config_mak
7370    echo "OBJCOPY=objcopy" >> $config_mak
7371    echo "IASL=$iasl" >> $config_mak
7372    echo "LD=$ld" >> $config_mak
7373    echo "RANLIB=$ranlib" >> $config_mak
7374done
7375
7376# set up tests data directory
7377for tests_subdir in acceptance data; do
7378    if [ ! -e tests/$tests_subdir ]; then
7379        symlink "$source_path/tests/$tests_subdir" tests/$tests_subdir
7380    fi
7381done
7382
7383# set up qemu-iotests in this build directory
7384iotests_common_env="tests/qemu-iotests/common.env"
7385iotests_check="tests/qemu-iotests/check"
7386
7387echo "# Automatically generated by configure - do not modify" > "$iotests_common_env"
7388echo >> "$iotests_common_env"
7389echo "export PYTHON='$python'" >> "$iotests_common_env"
7390
7391if [ ! -e "$iotests_check" ]; then
7392    symlink "$source_path/$iotests_check" "$iotests_check"
7393fi
7394
7395# Save the configure command line for later reuse.
7396cat <<EOD >config.status
7397#!/bin/sh
7398# Generated by configure.
7399# Run this file to recreate the current configuration.
7400# Compiler output produced by configure, useful for debugging
7401# configure, is in config.log if it exists.
7402EOD
7403printf "exec" >>config.status
7404printf " '%s'" "$0" "$@" >>config.status
7405echo ' "$@"' >>config.status
7406chmod +x config.status
7407
7408rm -r "$TMPDIR1"
7409