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