xref: /openbmc/qemu/configure (revision e4da0e39dfce5366b22b3e28ec63d0470c1df550)
17d13299dSbellard#!/bin/sh
27d13299dSbellard#
33ef693a0Sbellard# qemu configure script (c) 2003 Fabrice Bellard
47d13299dSbellard#
58cd05ab6SPeter Maydell
699519e67SCornelia Huck# Unset some variables known to interfere with behavior of common tools,
799519e67SCornelia Huck# just as autoconf does.
899519e67SCornelia HuckCLICOLOR_FORCE= GREP_OPTIONS=
999519e67SCornelia Huckunset CLICOLOR_FORCE GREP_OPTIONS
1099519e67SCornelia Huck
115e4dfd3dSJohn Snow# Don't allow CCACHE, if present, to use cached results of compile tests!
125e4dfd3dSJohn Snowexport CCACHE_RECACHE=yes
135e4dfd3dSJohn Snow
14dedad027SDaniel P. Berrangé# make source path absolute
15dedad027SDaniel P. Berrangésource_path=$(cd "$(dirname -- "$0")"; pwd)
16dedad027SDaniel P. Berrangé
17dedad027SDaniel P. Berrangéif test "$PWD" = "$source_path"
18dedad027SDaniel P. Berrangéthen
19dedad027SDaniel P. Berrangé    echo "Using './build' as the directory for build output"
20dedad027SDaniel P. Berrangé
21dedad027SDaniel P. Berrangé    MARKER=build/auto-created-by-configure
22dedad027SDaniel P. Berrangé
23dedad027SDaniel P. Berrangé    if test -e build
24dedad027SDaniel P. Berrangé    then
25dedad027SDaniel P. Berrangé        if test -f $MARKER
26dedad027SDaniel P. Berrangé        then
27dedad027SDaniel P. Berrangé           rm -rf build
28dedad027SDaniel P. Berrangé        else
29dedad027SDaniel P. Berrangé            echo "ERROR: ./build dir already exists and was not previously created by configure"
30dedad027SDaniel P. Berrangé            exit 1
31dedad027SDaniel P. Berrangé        fi
32dedad027SDaniel P. Berrangé    fi
33dedad027SDaniel P. Berrangé
34dedad027SDaniel P. Berrangé    mkdir build
35dedad027SDaniel P. Berrangé    touch $MARKER
36dedad027SDaniel P. Berrangé
37dedad027SDaniel P. Berrangé    cat > GNUmakefile <<'EOF'
38dedad027SDaniel P. Berrangé# This file is auto-generated by configure to support in-source tree
39dedad027SDaniel P. Berrangé# 'make' command invocation
40dedad027SDaniel P. Berrangé
41dedad027SDaniel P. Berrangéifeq ($(MAKECMDGOALS),)
42dedad027SDaniel P. Berrangérecurse: all
43dedad027SDaniel P. Berrangéendif
44dedad027SDaniel P. Berrangé
45dedad027SDaniel P. Berrangé.NOTPARALLEL: %
46dedad027SDaniel P. Berrangé%: force
47dedad027SDaniel P. Berrangé	@echo 'changing dir to build for $(MAKE) "$(MAKECMDGOALS)"...'
48dedad027SDaniel P. Berrangé	@$(MAKE) -C build -f Makefile $(MAKECMDGOALS)
49dedad027SDaniel P. Berrangé	@if test "$(MAKECMDGOALS)" = "distclean" && \
50dedad027SDaniel P. Berrangé	    test -e build/auto-created-by-configure ; \
51dedad027SDaniel P. Berrangé	then \
52dedad027SDaniel P. Berrangé	    rm -rf build GNUmakefile ; \
53dedad027SDaniel P. Berrangé	fi
54dedad027SDaniel P. Berrangéforce: ;
55dedad027SDaniel P. Berrangé.PHONY: force
56dedad027SDaniel P. BerrangéGNUmakefile: ;
57dedad027SDaniel P. Berrangé
58dedad027SDaniel P. BerrangéEOF
59dedad027SDaniel P. Berrangé    cd build
60dedad027SDaniel P. Berrangé    exec $source_path/configure "$@"
61dedad027SDaniel P. Berrangéfi
62dedad027SDaniel P. Berrangé
638cd05ab6SPeter Maydell# Temporary directory used for files created while
648cd05ab6SPeter Maydell# configure runs. Since it is in the build directory
658cd05ab6SPeter Maydell# we can safely blow away any previous version of it
668cd05ab6SPeter Maydell# (and we need not jump through hoops to try to delete
678cd05ab6SPeter Maydell# it when configure exits.)
688cd05ab6SPeter MaydellTMPDIR1="config-temp"
698cd05ab6SPeter Maydellrm -rf "${TMPDIR1}"
708cd05ab6SPeter Maydellmkdir -p "${TMPDIR1}"
718cd05ab6SPeter Maydellif [ $? -ne 0 ]; then
728cd05ab6SPeter Maydell    echo "ERROR: failed to create temporary directory"
738cd05ab6SPeter Maydell    exit 1
747d13299dSbellardfi
757d13299dSbellard
768cd05ab6SPeter MaydellTMPB="qemu-conf"
778cd05ab6SPeter MaydellTMPC="${TMPDIR1}/${TMPB}.c"
7866518bf6SDon SlutzTMPO="${TMPDIR1}/${TMPB}.o"
799c83ffd8SPeter MaydellTMPCXX="${TMPDIR1}/${TMPB}.cxx"
808cd05ab6SPeter MaydellTMPE="${TMPDIR1}/${TMPB}.exe"
8126fffe29SEmilio G. CotaTMPTXT="${TMPDIR1}/${TMPB}.txt"
827d13299dSbellard
83da1d85e3SGerd Hoffmannrm -f config.log
849ac81bbbSmalc
85b48e3611SPeter Maydell# Print a helpful header at the top of config.log
86b48e3611SPeter Maydellecho "# QEMU configure log $(date)" >> config.log
87979ae168SPeter Maydellprintf "# Configured with:" >> config.log
88979ae168SPeter Maydellprintf " '%s'" "$0" "$@" >> config.log
89979ae168SPeter Maydellecho >> config.log
90b48e3611SPeter Maydellecho "#" >> config.log
91b48e3611SPeter Maydell
92835af899SPaolo Bonziniquote_sh() {
93835af899SPaolo Bonzini    printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
94835af899SPaolo Bonzini}
95835af899SPaolo Bonzini
96d880a3baSPaolo Bonziniprint_error() {
97d880a3baSPaolo Bonzini    (echo
9876ad07a4SPeter Maydell    echo "ERROR: $1"
9976ad07a4SPeter Maydell    while test -n "$2"; do
10076ad07a4SPeter Maydell        echo "       $2"
10176ad07a4SPeter Maydell        shift
10276ad07a4SPeter Maydell    done
103d880a3baSPaolo Bonzini    echo) >&2
104d880a3baSPaolo Bonzini}
105d880a3baSPaolo Bonzini
106d880a3baSPaolo Bonzinierror_exit() {
107d880a3baSPaolo Bonzini    print_error "$@"
10876ad07a4SPeter Maydell    exit 1
10976ad07a4SPeter Maydell}
11076ad07a4SPeter Maydell
1119c83ffd8SPeter Maydelldo_compiler() {
1129c83ffd8SPeter Maydell    # Run the compiler, capturing its output to the log. First argument
1139c83ffd8SPeter Maydell    # is compiler binary to execute.
114630d86b7SDavid CARLIER    compiler="$1"
1159c83ffd8SPeter Maydell    shift
1168bbe05d7SIan Jackson    if test -n "$BASH_VERSION"; then eval '
1178bbe05d7SIan Jackson        echo >>config.log "
1188bbe05d7SIan Jacksonfuncs: ${FUNCNAME[*]}
1198bbe05d7SIan Jacksonlines: ${BASH_LINENO[*]}"
1208bbe05d7SIan Jackson    '; fi
1219c83ffd8SPeter Maydell    echo $compiler "$@" >> config.log
1229c83ffd8SPeter Maydell    $compiler "$@" >> config.log 2>&1 || return $?
1238dc38a78SPeter Maydell    # Test passed. If this is an --enable-werror build, rerun
1248dc38a78SPeter Maydell    # the test with -Werror and bail out if it fails. This
1258dc38a78SPeter Maydell    # makes warning-generating-errors in configure test code
1268dc38a78SPeter Maydell    # obvious to developers.
1278dc38a78SPeter Maydell    if test "$werror" != "yes"; then
1288dc38a78SPeter Maydell        return 0
1298dc38a78SPeter Maydell    fi
1308dc38a78SPeter Maydell    # Don't bother rerunning the compile if we were already using -Werror
1318dc38a78SPeter Maydell    case "$*" in
1328dc38a78SPeter Maydell        *-Werror*)
1338dc38a78SPeter Maydell           return 0
1348dc38a78SPeter Maydell        ;;
1358dc38a78SPeter Maydell    esac
1369c83ffd8SPeter Maydell    echo $compiler -Werror "$@" >> config.log
1379c83ffd8SPeter Maydell    $compiler -Werror "$@" >> config.log 2>&1 && return $?
13876ad07a4SPeter Maydell    error_exit "configure test passed without -Werror but failed with -Werror." \
13976ad07a4SPeter Maydell        "This is probably a bug in the configure script. The failing command" \
14076ad07a4SPeter Maydell        "will be at the bottom of config.log." \
14176ad07a4SPeter Maydell        "You can run configure with --disable-werror to bypass this check."
1428dc38a78SPeter Maydell}
1438dc38a78SPeter Maydell
1449c83ffd8SPeter Maydelldo_cc() {
1454dba2789SPaolo Bonzini    do_compiler "$cc" $CPU_CFLAGS "$@"
1469c83ffd8SPeter Maydell}
1479c83ffd8SPeter Maydell
1489c83ffd8SPeter Maydelldo_cxx() {
1494dba2789SPaolo Bonzini    do_compiler "$cxx" $CPU_CFLAGS "$@"
1509c83ffd8SPeter Maydell}
1519c83ffd8SPeter Maydell
15200849b92SRichard Henderson# Append $2 to the variable named $1, with space separation
15300849b92SRichard Hendersonadd_to() {
15400849b92SRichard Henderson    eval $1=\${$1:+\"\$$1 \"}\$2
15500849b92SRichard Henderson}
15600849b92SRichard Henderson
1579c83ffd8SPeter Maydellupdate_cxxflags() {
1589c83ffd8SPeter Maydell    # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
1599c83ffd8SPeter Maydell    # options which some versions of GCC's C++ compiler complain about
1609c83ffd8SPeter Maydell    # because they only make sense for C programs.
161de38c0ccSPaolo Bonzini    QEMU_CXXFLAGS="-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
1628a9d3d56SRichard Henderson    CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
1639c83ffd8SPeter Maydell    for arg in $QEMU_CFLAGS; do
1649c83ffd8SPeter Maydell        case $arg in
1659c83ffd8SPeter Maydell            -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
1669c83ffd8SPeter Maydell            -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
1679c83ffd8SPeter Maydell                ;;
1689c83ffd8SPeter Maydell            *)
1699c83ffd8SPeter Maydell                QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
1709c83ffd8SPeter Maydell                ;;
1719c83ffd8SPeter Maydell        esac
1729c83ffd8SPeter Maydell    done
1739c83ffd8SPeter Maydell}
1749c83ffd8SPeter Maydell
17552166aa0SJuan Quintelacompile_object() {
176fd0e6053SJohn Snow  local_cflags="$1"
177a2866660SPaolo Bonzini  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
17852166aa0SJuan Quintela}
17952166aa0SJuan Quintela
18052166aa0SJuan Quintelacompile_prog() {
18152166aa0SJuan Quintela  local_cflags="$1"
18252166aa0SJuan Quintela  local_ldflags="$2"
183a2866660SPaolo Bonzini  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
184a2866660SPaolo Bonzini      $LDFLAGS $EXTRA_LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
18552166aa0SJuan Quintela}
18652166aa0SJuan Quintela
18711568d6dSPaolo Bonzini# symbolically link $1 to $2.  Portable version of "ln -sf".
18811568d6dSPaolo Bonzinisymlink() {
18972b8b5a1SStefan Weil  rm -rf "$2"
190ec5b06d7SAnthony Liguori  mkdir -p "$(dirname "$2")"
19172b8b5a1SStefan Weil  ln -s "$1" "$2"
19211568d6dSPaolo Bonzini}
19311568d6dSPaolo Bonzini
1940dba6195SLoïc Minier# check whether a command is available to this shell (may be either an
1950dba6195SLoïc Minier# executable or a builtin)
1960dba6195SLoïc Minierhas() {
1970dba6195SLoïc Minier    type "$1" >/dev/null 2>&1
1980dba6195SLoïc Minier}
1990dba6195SLoïc Minier
2000a01d76fSMarc-André Lureauversion_ge () {
2012df52b9bSAlex Bennée    local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
2022df52b9bSAlex Bennée    local_ver2=$(echo "$2" | tr . ' ')
2030a01d76fSMarc-André Lureau    while true; do
2040a01d76fSMarc-André Lureau        set x $local_ver1
2050a01d76fSMarc-André Lureau        local_first=${2-0}
206c44a33e2SStefano Garzarella        # 'shift 2' if $2 is set, or 'shift' if $2 is not set
207c44a33e2SStefano Garzarella        shift ${2:+2}
2080a01d76fSMarc-André Lureau        local_ver1=$*
2090a01d76fSMarc-André Lureau        set x $local_ver2
2100a01d76fSMarc-André Lureau        # the second argument finished, the first must be greater or equal
2110a01d76fSMarc-André Lureau        test $# = 1 && return 0
2120a01d76fSMarc-André Lureau        test $local_first -lt $2 && return 1
2130a01d76fSMarc-André Lureau        test $local_first -gt $2 && return 0
214c44a33e2SStefano Garzarella        shift ${2:+2}
2150a01d76fSMarc-André Lureau        local_ver2=$*
2160a01d76fSMarc-André Lureau    done
2170a01d76fSMarc-André Lureau}
2180a01d76fSMarc-André Lureau
2193b6b7550SPaolo Bonziniglob() {
2203b6b7550SPaolo Bonzini    eval test -z '"${1#'"$2"'}"'
2213b6b7550SPaolo Bonzini}
2223b6b7550SPaolo Bonzini
223e9a3591fSChristian Borntraegerld_has() {
224e9a3591fSChristian Borntraeger    $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
225e9a3591fSChristian Borntraeger}
226e9a3591fSChristian Borntraeger
2274ace32e2SAntonio Ospiteif printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
2284ace32e2SAntonio Ospitethen
2294ace32e2SAntonio Ospite  error_exit "main directory cannot contain spaces nor colons"
2304ace32e2SAntonio Ospitefi
2314ace32e2SAntonio Ospite
23214211825SAntonio Ospite# default parameters
2332ff6b91eSJuan Quintelacpu=""
234a31a8642SMichael S. Tsirkiniasl="iasl"
2351e43adfcSbellardinterp_prefix="/usr/gnemul/qemu-%M"
23643ce4dfeSbellardstatic="no"
2373812c0c4SJoelle van Dynecross_compile="no"
2387d13299dSbellardcross_prefix=""
23987430d5bSPaolo Bonziniaudio_drv_list="default"
240b64ec4e4SFam Zhengblock_drv_rw_whitelist=""
241b64ec4e4SFam Zhengblock_drv_ro_whitelist=""
242e5f05f8cSKevin Wolfblock_drv_whitelist_tools="no"
243e49d021eSPeter Maydellhost_cc="cc"
244957f1f99SMichael Rothlibs_qga=""
2455bc62e01SGerd Hoffmanndebug_info="yes"
246cdad781dSDaniele Buonolto="false"
24763678e17SSteven Noonanstack_protector=""
2481e4f6065SDaniele Buonosafe_stack=""
249afc3a8f9SAlex Bennéeuse_containers="yes"
250f2385398SAlex Bennéegdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
251ac0df51dSaliguori
25292712822SDaniel P. Berrangeif test -e "$source_path/.git"
25392712822SDaniel P. Berrangethen
2547d7dbf9dSDan Streetman    git_submodules_action="update"
25592712822SDaniel P. Berrangeelse
2567d7dbf9dSDan Streetman    git_submodules_action="ignore"
25792712822SDaniel P. Berrangefi
2582d652f24SPaolo Bonzini
2592d652f24SPaolo Bonzinigit_submodules="ui/keycodemapdb"
260cc84d63aSDaniel P. Berrangegit="git"
261ac0df51dSaliguori
262afb63ebdSStefan Weil# Don't accept a target_list environment variable.
263afb63ebdSStefan Weilunset target_list
264447e133fSAlex Bennéeunset target_list_exclude
265377529c0SPaolo Bonzini
266377529c0SPaolo Bonzini# Default value for a variable defining feature "foo".
267377529c0SPaolo Bonzini#  * foo="no"  feature will only be used if --enable-foo arg is given
268377529c0SPaolo Bonzini#  * foo=""    feature will be searched for, and if found, will be used
269377529c0SPaolo Bonzini#              unless --disable-foo is given
270377529c0SPaolo Bonzini#  * foo="yes" this value will only be set by --enable-foo flag.
271377529c0SPaolo Bonzini#              feature will searched for,
272377529c0SPaolo Bonzini#              if not found, configure exits with error
273377529c0SPaolo Bonzini#
274377529c0SPaolo Bonzini# Always add --enable-foo and --disable-foo command line args.
275377529c0SPaolo Bonzini# Distributions want to ensure that several features are compiled in, and it
276377529c0SPaolo Bonzini# is impossible without a --enable-foo that exits if a feature is not found.
277377529c0SPaolo Bonzini
278c87ea116SAlex Bennéedefault_feature=""
279c87ea116SAlex Bennée# parse CC options second
280c87ea116SAlex Bennéefor opt do
281c87ea116SAlex Bennée  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
282c87ea116SAlex Bennée  case "$opt" in
283c87ea116SAlex Bennée      --without-default-features)
284c87ea116SAlex Bennée          default_feature="no"
285c87ea116SAlex Bennée  ;;
286c87ea116SAlex Bennée  esac
287c87ea116SAlex Bennéedone
288c87ea116SAlex Bennée
289a2866660SPaolo BonziniEXTRA_CFLAGS=""
290a2866660SPaolo BonziniEXTRA_CXXFLAGS=""
291a2866660SPaolo BonziniEXTRA_LDFLAGS=""
292a2866660SPaolo Bonzini
293c87ea116SAlex Bennéexen_ctrl_version="$default_feature"
294c87ea116SAlex Bennéexfs="$default_feature"
295c87ea116SAlex Bennéemembarrier="$default_feature"
2960848f8acSThomas Huthvhost_kernel="$default_feature"
297c87ea116SAlex Bennéevhost_net="$default_feature"
298c87ea116SAlex Bennéevhost_crypto="$default_feature"
299c87ea116SAlex Bennéevhost_scsi="$default_feature"
300c87ea116SAlex Bennéevhost_vsock="$default_feature"
301d88618f7SStefan Hajnoczivhost_user="no"
302c87ea116SAlex Bennéevhost_user_fs="$default_feature"
3030848f8acSThomas Huthvhost_vdpa="$default_feature"
304c87ea116SAlex Bennéerdma="$default_feature"
305c87ea116SAlex Bennéepvrdma="$default_feature"
306377529c0SPaolo Bonzinigprof="no"
307377529c0SPaolo Bonzinidebug_tcg="no"
308377529c0SPaolo Bonzinidebug="no"
309247724cbSMarc-André Lureausanitizers="no"
3100aebab04SLingfeng Yangtsan="no"
311c87ea116SAlex Bennéefortify_source="$default_feature"
312377529c0SPaolo Bonzinistrip_opt="yes"
313377529c0SPaolo Bonzinimingw32="no"
3141d728c39SBlue Swirlgcov="no"
315c7328271SMiroslav RezaninaEXESUF=""
31617969268SFam Zhengmodules="no"
317bd83c861SChristian Ehrhardtmodule_upgrades="no"
318377529c0SPaolo Bonziniprefix="/usr/local"
31910ff82d1SMarc-André Lureauqemu_suffix="qemu"
320377529c0SPaolo Bonzinibsd="no"
321377529c0SPaolo Bonzinilinux="no"
322377529c0SPaolo Bonzinisolaris="no"
323377529c0SPaolo Bonziniprofiler="no"
324377529c0SPaolo Bonzinisoftmmu="yes"
325377529c0SPaolo Bonzinilinux_user="no"
326377529c0SPaolo Bonzinibsd_user="no"
327377529c0SPaolo Bonzinipkgversion=""
32840d6444eSAvi Kivitypie=""
3293556c233SPaolo Bonziniqom_cast_debug="yes"
330baf86d6bSPaolo Bonzinitrace_backends="log"
331377529c0SPaolo Bonzinitrace_file="trace"
332c87ea116SAlex Bennéeopengl="$default_feature"
3335dd89908SRichard Hendersoncpuid_h="no"
334c87ea116SAlex Bennéeavx2_opt="$default_feature"
335c87ea116SAlex Bennéeguest_agent="$default_feature"
336d9840e25STomoki Sekiyamaguest_agent_with_vss="no"
33750cbebb9SMichael Rothguest_agent_ntddscsi="no"
338c87ea116SAlex Bennéevss_win32_sdk="$default_feature"
339d9840e25STomoki Sekiyamawin_sdk="no"
340c87ea116SAlex Bennéewant_tools="$default_feature"
341519175a2SAlex Barcelocoroutine=""
342c87ea116SAlex Bennéecoroutine_pool="$default_feature"
3437d992e4dSPeter Lievendebug_stack_usage="no"
344f0d92b56SLongpeng(Mike)crypto_afalg="no"
345a1c5e949SDaniel P. Berrangetls_priority="NORMAL"
346c87ea116SAlex Bennéetpm="$default_feature"
347c87ea116SAlex Bennéelive_block_migration=${default_feature:-yes}
348c87ea116SAlex Bennéenuma="$default_feature"
349c87ea116SAlex Bennéereplication=${default_feature:-yes}
350c87ea116SAlex Bennéebochs=${default_feature:-yes}
351c87ea116SAlex Bennéecloop=${default_feature:-yes}
352c87ea116SAlex Bennéedmg=${default_feature:-yes}
353c87ea116SAlex Bennéeqcow1=${default_feature:-yes}
354c87ea116SAlex Bennéevdi=${default_feature:-yes}
355c87ea116SAlex Bennéevvfat=${default_feature:-yes}
356c87ea116SAlex Bennéeqed=${default_feature:-yes}
357c87ea116SAlex Bennéeparallels=${default_feature:-yes}
358ba59fb77SPaolo Bonzinidebug_mutex="no"
359ba4dd2aaSAlex Bennéeplugins="$default_feature"
360b767d257SMarek Marczykowski-Góreckirng_none="no"
361c87ea116SAlex Bennéesecret_keyring="$default_feature"
362a5665051SPaolo Bonzinimeson=""
3633b4da132SPaolo Bonzinimeson_args=""
36448328880SPaolo Bonzinininja=""
3653b4da132SPaolo Bonzinigio="$default_feature"
366a5665051SPaolo Bonziniskip_meson=no
367b8e0c493SJoelle van Dyneslirp_smbd="$default_feature"
368377529c0SPaolo Bonzini
3693b4da132SPaolo Bonzini# The following Meson options are handled manually (still they
3703b4da132SPaolo Bonzini# are included in the automatically generated help message)
3713b4da132SPaolo Bonzini
3723b4da132SPaolo Bonzini# 1. Track which submodules are needed
3733b4da132SPaolo Bonzinicapstone="auto"
3743b4da132SPaolo Bonzinifdt="auto"
3753b4da132SPaolo Bonzinislirp="auto"
3763b4da132SPaolo Bonzini
3773b4da132SPaolo Bonzini# 2. Support --with/--without option
3783b4da132SPaolo Bonzinidefault_devices="true"
3793b4da132SPaolo Bonzini
3803b4da132SPaolo Bonzini# 3. Automatically enable/disable other options
3813b4da132SPaolo Bonzinitcg="enabled"
3823b4da132SPaolo Bonzinicfi="false"
3833b4da132SPaolo Bonzini
3843b4da132SPaolo Bonzini# 4. Detection partly done in configure
3853b4da132SPaolo Bonzinixen=${default_feature:+disabled}
386898be3e0SPeter Maydell
387c87ea116SAlex Bennée# parse CC options second
388ac0df51dSaliguorifor opt do
38989138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
390ac0df51dSaliguori  case "$opt" in
391ac0df51dSaliguori  --cross-prefix=*) cross_prefix="$optarg"
3923812c0c4SJoelle van Dyne                    cross_compile="yes"
393ac0df51dSaliguori  ;;
3943d8df640SPaolo Bonzini  --cc=*) CC="$optarg"
395ac0df51dSaliguori  ;;
39683f73fceSTomoki Sekiyama  --cxx=*) CXX="$optarg"
39783f73fceSTomoki Sekiyama  ;;
3982ff6b91eSJuan Quintela  --cpu=*) cpu="$optarg"
3992ff6b91eSJuan Quintela  ;;
400a2866660SPaolo Bonzini  --extra-cflags=*)
401a2866660SPaolo Bonzini    EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
402a2866660SPaolo Bonzini    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
403e2a2ed06SJuan Quintela    ;;
404a2866660SPaolo Bonzini  --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
40511cde1c8SBruno Dominguez  ;;
406a2866660SPaolo Bonzini  --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
407e2a2ed06SJuan Quintela  ;;
4085bc62e01SGerd Hoffmann  --enable-debug-info) debug_info="yes"
4095bc62e01SGerd Hoffmann  ;;
4105bc62e01SGerd Hoffmann  --disable-debug-info) debug_info="no"
4115bc62e01SGerd Hoffmann  ;;
412d75402b5SAlex Bennée  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
413d75402b5SAlex Bennée  ;;
414d422b2bcSAlex Bennée  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-flags-}; cc_arch=${cc_arch%%=*}
415d422b2bcSAlex Bennée                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
4162038f8c8SPaolo Bonzini                      cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
417d422b2bcSAlex Bennée  ;;
418d75402b5SAlex Bennée  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
4192038f8c8SPaolo Bonzini                cc_archs="$cc_archs $cc_arch"
420d75402b5SAlex Bennée                eval "cross_cc_${cc_arch}=\$optarg"
4212038f8c8SPaolo Bonzini                cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
422d75402b5SAlex Bennée  ;;
423ac0df51dSaliguori  esac
424ac0df51dSaliguoridone
425ac0df51dSaliguori# OS specific
426ac0df51dSaliguori# Using uname is really, really broken.  Once we have the right set of checks
42793148aa5SStefan Weil# we can eliminate its usage altogether.
428ac0df51dSaliguori
429e49d021eSPeter Maydell# Preferred compiler:
430e49d021eSPeter Maydell#  ${CC} (if set)
431e49d021eSPeter Maydell#  ${cross_prefix}gcc (if cross-prefix specified)
432e49d021eSPeter Maydell#  system compiler
433e49d021eSPeter Maydellif test -z "${CC}${cross_prefix}"; then
434e49d021eSPeter Maydell  cc="$host_cc"
435e49d021eSPeter Maydellelse
436b3198cc2SStuart Yoder  cc="${CC-${cross_prefix}gcc}"
437e49d021eSPeter Maydellfi
438e49d021eSPeter Maydell
43983f73fceSTomoki Sekiyamaif test -z "${CXX}${cross_prefix}"; then
44083f73fceSTomoki Sekiyama  cxx="c++"
44183f73fceSTomoki Sekiyamaelse
44283f73fceSTomoki Sekiyama  cxx="${CXX-${cross_prefix}g++}"
44383f73fceSTomoki Sekiyamafi
44483f73fceSTomoki Sekiyama
445b3198cc2SStuart Yoderar="${AR-${cross_prefix}ar}"
446cdbd727cSRichard Hendersonas="${AS-${cross_prefix}as}"
4475f6f0e27SRichard Hendersonccas="${CCAS-$cc}"
4483dd46c78SBlue Swirlcpp="${CPP-$cc -E}"
449b3198cc2SStuart Yoderobjcopy="${OBJCOPY-${cross_prefix}objcopy}"
450b3198cc2SStuart Yoderld="${LD-${cross_prefix}ld}"
4519f81aeb5SAlistair Francisranlib="${RANLIB-${cross_prefix}ranlib}"
4524852ee95SStefan Weilnm="${NM-${cross_prefix}nm}"
453b3198cc2SStuart Yoderstrip="${STRIP-${cross_prefix}strip}"
454b3198cc2SStuart Yoderwindres="${WINDRES-${cross_prefix}windres}"
45517884d7bSSergei Trofimovichpkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
45617884d7bSSergei Trofimovichquery_pkg_config() {
45717884d7bSSergei Trofimovich    "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
45817884d7bSSergei Trofimovich}
45917884d7bSSergei Trofimovichpkg_config=query_pkg_config
46047c03744SDave Airliesdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
461ac0df51dSaliguori
462be17dc90SMichael S. Tsirkin# default flags for all hosts
4632d31515bSPeter Maydell# We use -fwrapv to tell the compiler that we require a C dialect where
4642d31515bSPeter Maydell# left shift of signed integers is well defined and has the expected
4652d31515bSPeter Maydell# 2s-complement style results. (Both clang and gcc agree that it
4662d31515bSPeter Maydell# provides these semantics.)
467de38c0ccSPaolo BonziniQEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
468086d5f75SPaolo BonziniQEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
469c95e3080SKevin WolfQEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
470be17dc90SMichael S. TsirkinQEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
4715770e8afSPaolo Bonzini
472de38c0ccSPaolo BonziniQEMU_LDFLAGS=
473de38c0ccSPaolo Bonzini
4745770e8afSPaolo Bonzini# Flags that are needed during configure but later taken care of by Meson
4758a9d3d56SRichard HendersonCONFIGURE_CFLAGS="-std=gnu11 -Wall"
4765770e8afSPaolo BonziniCONFIGURE_LDFLAGS=
477086d5f75SPaolo Bonzini
478be17dc90SMichael S. Tsirkin
479ac0df51dSaliguoricheck_define() {
480ac0df51dSaliguoricat > $TMPC <<EOF
481ac0df51dSaliguori#if !defined($1)
482fd786e1aSPeter Maydell#error $1 not defined
483ac0df51dSaliguori#endif
484ac0df51dSaliguoriint main(void) { return 0; }
485ac0df51dSaliguoriEOF
48652166aa0SJuan Quintela  compile_object
487ac0df51dSaliguori}
488ac0df51dSaliguori
489307119e7SGerd Hoffmanncheck_include() {
490307119e7SGerd Hoffmanncat > $TMPC <<EOF
491307119e7SGerd Hoffmann#include <$1>
492307119e7SGerd Hoffmannint main(void) { return 0; }
493307119e7SGerd HoffmannEOF
494307119e7SGerd Hoffmann  compile_object
495307119e7SGerd Hoffmann}
496307119e7SGerd Hoffmann
49793b25869SJohn Snowwrite_c_skeleton() {
49893b25869SJohn Snow    cat > $TMPC <<EOF
49993b25869SJohn Snowint main(void) { return 0; }
50093b25869SJohn SnowEOF
50193b25869SJohn Snow}
50293b25869SJohn Snow
503bbea4050SPeter Maydellif check_define __linux__ ; then
504ba7c60c2SPaolo Bonzini  targetos=linux
505bbea4050SPeter Maydellelif check_define _WIN32 ; then
506ba7c60c2SPaolo Bonzini  targetos=windows
507bbea4050SPeter Maydellelif check_define __OpenBSD__ ; then
508ba7c60c2SPaolo Bonzini  targetos=openbsd
509bbea4050SPeter Maydellelif check_define __sun__ ; then
510ba7c60c2SPaolo Bonzini  targetos=sunos
511bbea4050SPeter Maydellelif check_define __HAIKU__ ; then
512ba7c60c2SPaolo Bonzini  targetos=haiku
513951fedfcSPeter Maydellelif check_define __FreeBSD__ ; then
514ba7c60c2SPaolo Bonzini  targetos=freebsd
515951fedfcSPeter Maydellelif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
516ba7c60c2SPaolo Bonzini  targetos=gnu/kfreebsd
517951fedfcSPeter Maydellelif check_define __DragonFly__ ; then
518ba7c60c2SPaolo Bonzini  targetos=dragonfly
519951fedfcSPeter Maydellelif check_define __NetBSD__; then
520ba7c60c2SPaolo Bonzini  targetos=netbsd
521951fedfcSPeter Maydellelif check_define __APPLE__; then
522ba7c60c2SPaolo Bonzini  targetos=darwin
523bbea4050SPeter Maydellelse
524951fedfcSPeter Maydell  # This is a fatal error, but don't report it yet, because we
525951fedfcSPeter Maydell  # might be going to just print the --help text, or it might
526951fedfcSPeter Maydell  # be the result of a missing compiler.
527ba7c60c2SPaolo Bonzini  targetos=bogus
528bbea4050SPeter Maydellfi
529bbea4050SPeter Maydell
53065eff01bSPaolo Bonzini# OS specific
53165eff01bSPaolo Bonzini
53265eff01bSPaolo Bonzinicase $targetos in
53365eff01bSPaolo Bonziniwindows)
53465eff01bSPaolo Bonzini  mingw32="yes"
53565eff01bSPaolo Bonzini  plugins="no"
53665eff01bSPaolo Bonzini  pie="no"
53765eff01bSPaolo Bonzini;;
53865eff01bSPaolo Bonzinignu/kfreebsd)
53965eff01bSPaolo Bonzini  bsd="yes"
54065eff01bSPaolo Bonzini;;
54165eff01bSPaolo Bonzinifreebsd)
54265eff01bSPaolo Bonzini  bsd="yes"
54365eff01bSPaolo Bonzini  bsd_user="yes"
54465eff01bSPaolo Bonzini  make="${MAKE-gmake}"
54565eff01bSPaolo Bonzini  # needed for kinfo_getvmmap(3) in libutil.h
54665eff01bSPaolo Bonzini;;
54765eff01bSPaolo Bonzinidragonfly)
54865eff01bSPaolo Bonzini  bsd="yes"
54965eff01bSPaolo Bonzini  make="${MAKE-gmake}"
55065eff01bSPaolo Bonzini;;
55165eff01bSPaolo Bonzininetbsd)
55265eff01bSPaolo Bonzini  bsd="yes"
55365eff01bSPaolo Bonzini  make="${MAKE-gmake}"
55465eff01bSPaolo Bonzini;;
55565eff01bSPaolo Bonziniopenbsd)
55665eff01bSPaolo Bonzini  bsd="yes"
55765eff01bSPaolo Bonzini  make="${MAKE-gmake}"
55865eff01bSPaolo Bonzini;;
55965eff01bSPaolo Bonzinidarwin)
56065eff01bSPaolo Bonzini  bsd="yes"
56165eff01bSPaolo Bonzini  darwin="yes"
56265eff01bSPaolo Bonzini  # Disable attempts to use ObjectiveC features in os/object.h since they
56365eff01bSPaolo Bonzini  # won't work when we're compiling with gcc as a C compiler.
56465eff01bSPaolo Bonzini  QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
56565eff01bSPaolo Bonzini;;
56665eff01bSPaolo Bonzinisunos)
56765eff01bSPaolo Bonzini  solaris="yes"
56865eff01bSPaolo Bonzini  make="${MAKE-gmake}"
56965eff01bSPaolo Bonzini  smbd="${SMBD-/usr/sfw/sbin/smbd}"
57065eff01bSPaolo Bonzini# needed for CMSG_ macros in sys/socket.h
57165eff01bSPaolo Bonzini  QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
57265eff01bSPaolo Bonzini# needed for TIOCWIN* defines in termios.h
57365eff01bSPaolo Bonzini  QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
57465eff01bSPaolo Bonzini  # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
57565eff01bSPaolo Bonzini  # Note that this check is broken for cross-compilation: if you're
576bbea4050SPeter Maydell  # cross-compiling to one of these OSes then you'll need to specify
577bbea4050SPeter Maydell  # the correct CPU with the --cpu option.
578bbea4050SPeter Maydell  if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
579bbea4050SPeter Maydell    cpu="x86_64"
580bbea4050SPeter Maydell  fi
58165eff01bSPaolo Bonzini;;
58265eff01bSPaolo Bonzinihaiku)
58365eff01bSPaolo Bonzini  pie="no"
58465eff01bSPaolo Bonzini  QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
58565eff01bSPaolo Bonzini;;
58665eff01bSPaolo Bonzinilinux)
58765eff01bSPaolo Bonzini  linux="yes"
58865eff01bSPaolo Bonzini  linux_user="yes"
58965eff01bSPaolo Bonzini  vhost_user=${default_feature:-yes}
59065eff01bSPaolo Bonzini;;
591bbea4050SPeter Maydellesac
592bbea4050SPeter Maydell
5932ff6b91eSJuan Quintelaif test ! -z "$cpu" ; then
5942ff6b91eSJuan Quintela  # command line argument
5952ff6b91eSJuan Quintela  :
5962ff6b91eSJuan Quintelaelif check_define __i386__ ; then
597ac0df51dSaliguori  cpu="i386"
598ac0df51dSaliguorielif check_define __x86_64__ ; then
599c72b26ecSRichard Henderson  if check_define __ILP32__ ; then
600c72b26ecSRichard Henderson    cpu="x32"
601c72b26ecSRichard Henderson  else
602ac0df51dSaliguori    cpu="x86_64"
603c72b26ecSRichard Henderson  fi
6043aa9bd6cSblueswir1elif check_define __sparc__ ; then
6053aa9bd6cSblueswir1  if check_define __arch64__ ; then
6063aa9bd6cSblueswir1    cpu="sparc64"
6073aa9bd6cSblueswir1  else
6083aa9bd6cSblueswir1    cpu="sparc"
6093aa9bd6cSblueswir1  fi
610fdf7ed96Smalcelif check_define _ARCH_PPC ; then
611fdf7ed96Smalc  if check_define _ARCH_PPC64 ; then
612f8378accSRichard Henderson    if check_define _LITTLE_ENDIAN ; then
613f8378accSRichard Henderson      cpu="ppc64le"
614f8378accSRichard Henderson    else
615fdf7ed96Smalc      cpu="ppc64"
616f8378accSRichard Henderson    fi
617ac0df51dSaliguori  else
618fdf7ed96Smalc    cpu="ppc"
619fdf7ed96Smalc  fi
620afa05235SAurelien Jarnoelif check_define __mips__ ; then
621afa05235SAurelien Jarno  cpu="mips"
622d66ed0eaSAurelien Jarnoelif check_define __s390__ ; then
623d66ed0eaSAurelien Jarno  if check_define __s390x__ ; then
624d66ed0eaSAurelien Jarno    cpu="s390x"
625d66ed0eaSAurelien Jarno  else
626d66ed0eaSAurelien Jarno    cpu="s390"
627d66ed0eaSAurelien Jarno  fi
628c4f80543SAlistair Franciselif check_define __riscv ; then
629ba0e7333SRichard Henderson  cpu="riscv"
63021d89f84SPeter Maydellelif check_define __arm__ ; then
63121d89f84SPeter Maydell  cpu="arm"
6321f080313SClaudio Fontanaelif check_define __aarch64__ ; then
6331f080313SClaudio Fontana  cpu="aarch64"
634fdf7ed96Smalcelse
63589138857SStefan Weil  cpu=$(uname -m)
636ac0df51dSaliguorifi
637ac0df51dSaliguori
638359bc95dSPeter MaydellARCH=
639*e4da0e39SPaolo Bonzini# Normalise host CPU name, set ARCH and multilib cflags
640359bc95dSPeter Maydell# Note that this case should only have supported host CPUs, not guests.
6417d13299dSbellardcase "$cpu" in
642*e4da0e39SPaolo Bonzini  aarch64|riscv) ;;
643*e4da0e39SPaolo Bonzini  armv*b|armv*l|arm)
644*e4da0e39SPaolo Bonzini    cpu="arm" ;;
645*e4da0e39SPaolo Bonzini
6467d13299dSbellard  i386|i486|i586|i686|i86pc|BePC)
64797a847bcSbellard    cpu="i386"
648*e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32" ;;
649*e4da0e39SPaolo Bonzini  x32)
650*e4da0e39SPaolo Bonzini    CPU_CFLAGS="-mx32" ;;
651aaa5fa14Saurel32  x86_64|amd64)
652aaa5fa14Saurel32    cpu="x86_64"
653*e4da0e39SPaolo Bonzini    # ??? Only extremely old AMD cpus do not have cmpxchg16b.
654*e4da0e39SPaolo Bonzini    # If we truly care, we should simply detect this case at
655*e4da0e39SPaolo Bonzini    # runtime and generate the fallback to serial emulation.
656*e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64 -mcx16" ;;
657*e4da0e39SPaolo Bonzini
658afa05235SAurelien Jarno  mips*)
659*e4da0e39SPaolo Bonzini    cpu="mips" ;;
660*e4da0e39SPaolo Bonzini
661*e4da0e39SPaolo Bonzini  ppc)
662*e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32" ;;
663*e4da0e39SPaolo Bonzini  ppc64)
664*e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64" ;;
665*e4da0e39SPaolo Bonzini  ppc64le)
666*e4da0e39SPaolo Bonzini    ARCH="ppc64" ;;
667*e4da0e39SPaolo Bonzini
668*e4da0e39SPaolo Bonzini  s390)
669*e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m31"
670*e4da0e39SPaolo Bonzini    ARCH=unknown ;;
671*e4da0e39SPaolo Bonzini  s390x)
672*e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64" ;;
673*e4da0e39SPaolo Bonzini
6743142255cSblueswir1  sparc|sun4[cdmuv])
675ae228531Sbellard    cpu="sparc"
676*e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
677*e4da0e39SPaolo Bonzini  sparc64)
678*e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
679*e4da0e39SPaolo Bonzini
6807d13299dSbellard  *)
681359bc95dSPeter Maydell    # This will result in either an error or falling back to TCI later
682359bc95dSPeter Maydell    ARCH=unknown
6837d13299dSbellard  ;;
6847d13299dSbellardesac
685359bc95dSPeter Maydellif test -z "$ARCH"; then
686359bc95dSPeter Maydell  ARCH="$cpu"
687359bc95dSPeter Maydellfi
688e2d52ad3SJuan Quintela
6890db4a067SPaolo Bonzini: ${make=${MAKE-make}}
690b6daf4d3SPaolo Bonzini
691faf44142SDaniel P. Berrangé# We prefer python 3.x. A bare 'python' is traditionally
692faf44142SDaniel P. Berrangé# python 2.x, but some distros have it as python 3.x, so
693ddf90699SEduardo Habkost# we check that too
694faf44142SDaniel P. Berrangépython=
6950a01d76fSMarc-André Lureauexplicit_python=no
696ddf90699SEduardo Habkostfor binary in "${PYTHON-python3}" python
697faf44142SDaniel P. Berrangédo
698faf44142SDaniel P. Berrangé    if has "$binary"
699faf44142SDaniel P. Berrangé    then
70095c5f2deSPaolo Bonzini        python=$(command -v "$binary")
701faf44142SDaniel P. Berrangé        break
702faf44142SDaniel P. Berrangé    fi
703faf44142SDaniel P. Berrangédone
704903458c8SMarkus Armbruster
705903458c8SMarkus Armbruster
70639d87c8cSAlex Bennée# Check for ancillary tools used in testing
70739d87c8cSAlex Bennéegenisoimage=
7083df437c7SAlex Bennéefor binary in genisoimage mkisofs
70939d87c8cSAlex Bennéedo
71039d87c8cSAlex Bennée    if has $binary
71139d87c8cSAlex Bennée    then
71239d87c8cSAlex Bennée        genisoimage=$(command -v "$binary")
71339d87c8cSAlex Bennée        break
71439d87c8cSAlex Bennée    fi
71539d87c8cSAlex Bennéedone
71639d87c8cSAlex Bennée
7173c4a4d0dSPeter Maydell# Default objcc to clang if available, otherwise use CC
7183c4a4d0dSPeter Maydellif has clang; then
7193c4a4d0dSPeter Maydell  objcc=clang
7203c4a4d0dSPeter Maydellelse
7213c4a4d0dSPeter Maydell  objcc="$cc"
7223c4a4d0dSPeter Maydellfi
7233c4a4d0dSPeter Maydell
7243457a3f8SJuan Quintelaif test "$mingw32" = "yes" ; then
7253457a3f8SJuan Quintela  EXESUF=".exe"
72678e9d4adSStefan Weil  # MinGW needs -mthreads for TLS and macro _MT.
7275770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
72893b25869SJohn Snow  write_c_skeleton;
729d17f305aSPaolo Bonzini  prefix="/qemu"
73077433a5fSMarc-André Lureau  qemu_suffix=""
731105fad6bSBishara AbuHattoum  libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi -lnetapi32 $libs_qga"
7323457a3f8SJuan Quintelafi
7333457a3f8SJuan Quintela
734487fefdbSAnthony Liguoriwerror=""
73585aa5189Sbellard
73661d63097SPaolo Bonzini. $source_path/scripts/meson-buildoptions.sh
73761d63097SPaolo Bonzini
73861d63097SPaolo Bonzinimeson_options=
73961d63097SPaolo Bonzinimeson_option_parse() {
74061d63097SPaolo Bonzini  meson_options="$meson_options $(_meson_option_parse "$@")"
74161d63097SPaolo Bonzini  if test $? -eq 1; then
74261d63097SPaolo Bonzini    echo "ERROR: unknown option $1"
74361d63097SPaolo Bonzini    echo "Try '$0 --help' for more information"
74461d63097SPaolo Bonzini    exit 1
74561d63097SPaolo Bonzini  fi
74661d63097SPaolo Bonzini}
74761d63097SPaolo Bonzini
7487d13299dSbellardfor opt do
74989138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
7507d13299dSbellard  case "$opt" in
7512efc3265Sbellard  --help|-h) show_help=yes
7522efc3265Sbellard  ;;
75399123e13SMike Frysinger  --version|-V) exec cat $source_path/VERSION
75499123e13SMike Frysinger  ;;
755b1a550a0Spbrook  --prefix=*) prefix="$optarg"
7567d13299dSbellard  ;;
757b1a550a0Spbrook  --interp-prefix=*) interp_prefix="$optarg"
75832ce6337Sbellard  ;;
759ac0df51dSaliguori  --cross-prefix=*)
7607d13299dSbellard  ;;
761ac0df51dSaliguori  --cc=*)
7627d13299dSbellard  ;;
763b1a550a0Spbrook  --host-cc=*) host_cc="$optarg"
76483469015Sbellard  ;;
76583f73fceSTomoki Sekiyama  --cxx=*)
76683f73fceSTomoki Sekiyama  ;;
767e007dbecSMichael S. Tsirkin  --iasl=*) iasl="$optarg"
768e007dbecSMichael S. Tsirkin  ;;
7693c4a4d0dSPeter Maydell  --objcc=*) objcc="$optarg"
7703c4a4d0dSPeter Maydell  ;;
771b1a550a0Spbrook  --make=*) make="$optarg"
7727d13299dSbellard  ;;
773b6daf4d3SPaolo Bonzini  --install=*)
7746a882643Spbrook  ;;
7750a01d76fSMarc-André Lureau  --python=*) python="$optarg" ; explicit_python=yes
776c886edfbSBlue Swirl  ;;
7772eb054c2SPeter Maydell  --sphinx-build=*) sphinx_build="$optarg"
7782eb054c2SPeter Maydell  ;;
779a5665051SPaolo Bonzini  --skip-meson) skip_meson=yes
780a5665051SPaolo Bonzini  ;;
781a5665051SPaolo Bonzini  --meson=*) meson="$optarg"
782a5665051SPaolo Bonzini  ;;
78348328880SPaolo Bonzini  --ninja=*) ninja="$optarg"
78448328880SPaolo Bonzini  ;;
785e2d8830eSBrad  --smbd=*) smbd="$optarg"
786e2d8830eSBrad  ;;
787e2a2ed06SJuan Quintela  --extra-cflags=*)
7887d13299dSbellard  ;;
78911cde1c8SBruno Dominguez  --extra-cxxflags=*)
79011cde1c8SBruno Dominguez  ;;
791e2a2ed06SJuan Quintela  --extra-ldflags=*)
7927d13299dSbellard  ;;
7935bc62e01SGerd Hoffmann  --enable-debug-info)
7945bc62e01SGerd Hoffmann  ;;
7955bc62e01SGerd Hoffmann  --disable-debug-info)
7965bc62e01SGerd Hoffmann  ;;
797d75402b5SAlex Bennée  --cross-cc-*)
798d75402b5SAlex Bennée  ;;
79917969268SFam Zheng  --enable-modules)
80017969268SFam Zheng      modules="yes"
80117969268SFam Zheng  ;;
8023aa88b31SStefan Hajnoczi  --disable-modules)
8033aa88b31SStefan Hajnoczi      modules="no"
8043aa88b31SStefan Hajnoczi  ;;
805bd83c861SChristian Ehrhardt  --disable-module-upgrades) module_upgrades="no"
806bd83c861SChristian Ehrhardt  ;;
807bd83c861SChristian Ehrhardt  --enable-module-upgrades) module_upgrades="yes"
808bd83c861SChristian Ehrhardt  ;;
8092ff6b91eSJuan Quintela  --cpu=*)
8107d13299dSbellard  ;;
811b1a550a0Spbrook  --target-list=*) target_list="$optarg"
812447e133fSAlex Bennée                   if test "$target_list_exclude"; then
813447e133fSAlex Bennée                       error_exit "Can't mix --target-list with --target-list-exclude"
814447e133fSAlex Bennée                   fi
815447e133fSAlex Bennée  ;;
816447e133fSAlex Bennée  --target-list-exclude=*) target_list_exclude="$optarg"
817447e133fSAlex Bennée                   if test "$target_list"; then
818447e133fSAlex Bennée                       error_exit "Can't mix --target-list-exclude with --target-list"
819447e133fSAlex Bennée                   fi
820de83cd02Sbellard  ;;
82174242e0fSPaolo Bonzini  --with-trace-file=*) trace_file="$optarg"
8229410b56cSPrerna Saxena  ;;
8237bc3ca7fSPaolo Bonzini  --with-default-devices) default_devices="true"
824f3494749SPaolo Bonzini  ;;
8257bc3ca7fSPaolo Bonzini  --without-default-devices) default_devices="false"
826f3494749SPaolo Bonzini  ;;
827d1d5e9eeSAlex Bennée  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
828d1d5e9eeSAlex Bennée  ;;
829d1d5e9eeSAlex Bennée  --with-devices-*) device_arch=${opt#--with-devices-};
830d1d5e9eeSAlex Bennée                    device_arch=${device_arch%%=*}
831d1d5e9eeSAlex Bennée                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
832d1d5e9eeSAlex Bennée                    if test -f "$cf"; then
833d1d5e9eeSAlex Bennée                        device_archs="$device_archs $device_arch"
834d1d5e9eeSAlex Bennée                        eval "devices_${device_arch}=\$optarg"
835d1d5e9eeSAlex Bennée                    else
836d1d5e9eeSAlex Bennée                        error_exit "File $cf does not exist"
837d1d5e9eeSAlex Bennée                    fi
838d1d5e9eeSAlex Bennée  ;;
839c87ea116SAlex Bennée  --without-default-features) # processed above
840c87ea116SAlex Bennée  ;;
8417d13299dSbellard  --enable-gprof) gprof="yes"
8427d13299dSbellard  ;;
8431d728c39SBlue Swirl  --enable-gcov) gcov="yes"
8441d728c39SBlue Swirl  ;;
84579427693SLoïc Minier  --static)
84679427693SLoïc Minier    static="yes"
84717884d7bSSergei Trofimovich    QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
84843ce4dfeSbellard  ;;
8490b24e75fSPaolo Bonzini  --mandir=*) mandir="$optarg"
8500b24e75fSPaolo Bonzini  ;;
8510b24e75fSPaolo Bonzini  --bindir=*) bindir="$optarg"
8520b24e75fSPaolo Bonzini  ;;
8533aa5d2beSAlon Levy  --libdir=*) libdir="$optarg"
8543aa5d2beSAlon Levy  ;;
8558bf188aaSMichael Tokarev  --libexecdir=*) libexecdir="$optarg"
8568bf188aaSMichael Tokarev  ;;
8570f94d6daSAlon Levy  --includedir=*) includedir="$optarg"
8580f94d6daSAlon Levy  ;;
859528ae5b8SEduardo Habkost  --datadir=*) datadir="$optarg"
8600b24e75fSPaolo Bonzini  ;;
86177433a5fSMarc-André Lureau  --with-suffix=*) qemu_suffix="$optarg"
862023d3d67SEduardo Habkost  ;;
863c6502638SBruce Rogers  --docdir=*) docdir="$optarg"
8640b24e75fSPaolo Bonzini  ;;
865fe0038beSPaolo Bonzini  --localedir=*) localedir="$optarg"
866fe0038beSPaolo Bonzini  ;;
867ca2fb938SAndre Przywara  --sysconfdir=*) sysconfdir="$optarg"
86807381cc1SAnthony Liguori  ;;
869785c23aeSLuiz Capitulino  --localstatedir=*) local_statedir="$optarg"
870785c23aeSLuiz Capitulino  ;;
8713d5eecabSGerd Hoffmann  --firmwarepath=*) firmwarepath="$optarg"
8723d5eecabSGerd Hoffmann  ;;
873181ce1d0SOlaf Hering  --host=*|--build=*|\
874181ce1d0SOlaf Hering  --disable-dependency-tracking|\
875785c23aeSLuiz Capitulino  --sbindir=*|--sharedstatedir=*|\
876fe0038beSPaolo Bonzini  --oldincludedir=*|--datarootdir=*|--infodir=*|\
877023ddd74SMax Filippov  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
878023ddd74SMax Filippov    # These switches are silently ignored, for compatibility with
879023ddd74SMax Filippov    # autoconf-generated configure scripts. This allows QEMU's
880023ddd74SMax Filippov    # configure to be used by RPM and similar macros that set
881023ddd74SMax Filippov    # lots of directory switches by default.
882023ddd74SMax Filippov  ;;
8833556c233SPaolo Bonzini  --disable-qom-cast-debug) qom_cast_debug="no"
8843556c233SPaolo Bonzini  ;;
8853556c233SPaolo Bonzini  --enable-qom-cast-debug) qom_cast_debug="yes"
8863556c233SPaolo Bonzini  ;;
8870c58ac1cSmalc  --audio-drv-list=*) audio_drv_list="$optarg"
8880c58ac1cSmalc  ;;
88989138857SStefan Weil  --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
890b64ec4e4SFam Zheng  ;;
89189138857SStefan Weil  --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
892eb852011SMarkus Armbruster  ;;
893e5f05f8cSKevin Wolf  --enable-block-drv-whitelist-in-tools) block_drv_whitelist_tools="yes"
894e5f05f8cSKevin Wolf  ;;
895e5f05f8cSKevin Wolf  --disable-block-drv-whitelist-in-tools) block_drv_whitelist_tools="no"
896e5f05f8cSKevin Wolf  ;;
897f8393946Saurel32  --enable-debug-tcg) debug_tcg="yes"
898f8393946Saurel32  ;;
899f8393946Saurel32  --disable-debug-tcg) debug_tcg="no"
900f8393946Saurel32  ;;
901f3d08ee6SPaul Brook  --enable-debug)
902f3d08ee6SPaul Brook      # Enable debugging options that aren't excessively noisy
903f3d08ee6SPaul Brook      debug_tcg="yes"
9041fcc6d42SPeter Xu      debug_mutex="yes"
905f3d08ee6SPaul Brook      debug="yes"
906f3d08ee6SPaul Brook      strip_opt="no"
907b553a042SJohn Snow      fortify_source="no"
908f3d08ee6SPaul Brook  ;;
909247724cbSMarc-André Lureau  --enable-sanitizers) sanitizers="yes"
910247724cbSMarc-André Lureau  ;;
911247724cbSMarc-André Lureau  --disable-sanitizers) sanitizers="no"
912247724cbSMarc-André Lureau  ;;
9130aebab04SLingfeng Yang  --enable-tsan) tsan="yes"
9140aebab04SLingfeng Yang  ;;
9150aebab04SLingfeng Yang  --disable-tsan) tsan="no"
9160aebab04SLingfeng Yang  ;;
9171625af87Saliguori  --disable-strip) strip_opt="no"
9181625af87Saliguori  ;;
9194d34a86bSPaolo Bonzini  --disable-slirp) slirp="disabled"
920c20709aaSbellard  ;;
921fd6fc214SPaolo Bonzini  --enable-slirp) slirp="enabled"
922fd6fc214SPaolo Bonzini  ;;
9234d34a86bSPaolo Bonzini  --enable-slirp=git) slirp="internal"
9247c57bdd8SMarc-André Lureau  ;;
92503a3c0b3SPaolo Bonzini  --enable-slirp=*) slirp="$optarg"
926675b9b53SMarc-André Lureau  ;;
9271badb709SPaolo Bonzini  --disable-xen) xen="disabled"
928e37630caSaliguori  ;;
9291badb709SPaolo Bonzini  --enable-xen) xen="enabled"
930fc321b4bSJuan Quintela  ;;
9311badb709SPaolo Bonzini  --disable-tcg) tcg="disabled"
932d1a14257SAlex Bennée                 plugins="no"
933b3f6ea7eSPaolo Bonzini  ;;
9341badb709SPaolo Bonzini  --enable-tcg) tcg="enabled"
935b3f6ea7eSPaolo Bonzini  ;;
93605c2a3e7Sbellard  --enable-profiler) profiler="yes"
93705c2a3e7Sbellard  ;;
938cad25d69Spbrook  --disable-system) softmmu="no"
9390a8e90f4Spbrook  ;;
940cad25d69Spbrook  --enable-system) softmmu="yes"
9410a8e90f4Spbrook  ;;
9420953a80fSZachary Amsden  --disable-user)
9430953a80fSZachary Amsden      linux_user="no" ;
9440953a80fSZachary Amsden      bsd_user="no" ;
9450953a80fSZachary Amsden  ;;
9460953a80fSZachary Amsden  --enable-user) ;;
947831b7825Sths  --disable-linux-user) linux_user="no"
9480a8e90f4Spbrook  ;;
949831b7825Sths  --enable-linux-user) linux_user="yes"
950831b7825Sths  ;;
95184778508Sblueswir1  --disable-bsd-user) bsd_user="no"
95284778508Sblueswir1  ;;
95384778508Sblueswir1  --enable-bsd-user) bsd_user="yes"
95484778508Sblueswir1  ;;
95540d6444eSAvi Kivity  --enable-pie) pie="yes"
95634005a00SKirill A. Shutemov  ;;
95740d6444eSAvi Kivity  --disable-pie) pie="no"
95834005a00SKirill A. Shutemov  ;;
95985aa5189Sbellard  --enable-werror) werror="yes"
96085aa5189Sbellard  ;;
96185aa5189Sbellard  --disable-werror) werror="no"
96285aa5189Sbellard  ;;
963cdad781dSDaniele Buono  --enable-lto) lto="true"
964cdad781dSDaniele Buono  ;;
965cdad781dSDaniele Buono  --disable-lto) lto="false"
966cdad781dSDaniele Buono  ;;
96763678e17SSteven Noonan  --enable-stack-protector) stack_protector="yes"
96863678e17SSteven Noonan  ;;
96963678e17SSteven Noonan  --disable-stack-protector) stack_protector="no"
97063678e17SSteven Noonan  ;;
9711e4f6065SDaniele Buono  --enable-safe-stack) safe_stack="yes"
9721e4f6065SDaniele Buono  ;;
9731e4f6065SDaniele Buono  --disable-safe-stack) safe_stack="no"
9741e4f6065SDaniele Buono  ;;
9759e62ba48SDaniele Buono  --enable-cfi)
9769e62ba48SDaniele Buono      cfi="true";
9779e62ba48SDaniele Buono      lto="true";
9789e62ba48SDaniele Buono  ;;
9799e62ba48SDaniele Buono  --disable-cfi) cfi="false"
9809e62ba48SDaniele Buono  ;;
981fbb4121dSPaolo Bonzini  --disable-fdt) fdt="disabled"
9822df87df7SJuan Quintela  ;;
983fbb4121dSPaolo Bonzini  --enable-fdt) fdt="enabled"
984fbb4121dSPaolo Bonzini  ;;
985fbb4121dSPaolo Bonzini  --enable-fdt=git) fdt="internal"
986fbb4121dSPaolo Bonzini  ;;
98703a3c0b3SPaolo Bonzini  --enable-fdt=*) fdt="$optarg"
9882df87df7SJuan Quintela  ;;
989a40161cbSPaolo Bonzini  --disable-membarrier) membarrier="no"
990a40161cbSPaolo Bonzini  ;;
991a40161cbSPaolo Bonzini  --enable-membarrier) membarrier="yes"
992a40161cbSPaolo Bonzini  ;;
9937e563bfbSThomas Huth  --with-pkgversion=*) pkgversion="$optarg"
9944a19f1ecSpbrook  ;;
995519175a2SAlex Barcelo  --with-coroutine=*) coroutine="$optarg"
996519175a2SAlex Barcelo  ;;
99770c60c08SStefan Hajnoczi  --disable-coroutine-pool) coroutine_pool="no"
99870c60c08SStefan Hajnoczi  ;;
99970c60c08SStefan Hajnoczi  --enable-coroutine-pool) coroutine_pool="yes"
100070c60c08SStefan Hajnoczi  ;;
10017d992e4dSPeter Lieven  --enable-debug-stack-usage) debug_stack_usage="yes"
10027d992e4dSPeter Lieven  ;;
1003f0d92b56SLongpeng(Mike)  --enable-crypto-afalg) crypto_afalg="yes"
1004f0d92b56SLongpeng(Mike)  ;;
1005f0d92b56SLongpeng(Mike)  --disable-crypto-afalg) crypto_afalg="no"
1006f0d92b56SLongpeng(Mike)  ;;
1007d5970055SMichael S. Tsirkin  --disable-vhost-net) vhost_net="no"
1008d5970055SMichael S. Tsirkin  ;;
1009d5970055SMichael S. Tsirkin  --enable-vhost-net) vhost_net="yes"
1010d5970055SMichael S. Tsirkin  ;;
1011042cea27SGonglei  --disable-vhost-crypto) vhost_crypto="no"
1012042cea27SGonglei  ;;
1013299e6f19SPaolo Bonzini  --enable-vhost-crypto) vhost_crypto="yes"
1014042cea27SGonglei  ;;
10155e9be92dSNicholas Bellinger  --disable-vhost-scsi) vhost_scsi="no"
10165e9be92dSNicholas Bellinger  ;;
10175e9be92dSNicholas Bellinger  --enable-vhost-scsi) vhost_scsi="yes"
10185e9be92dSNicholas Bellinger  ;;
1019fc0b9b0eSStefan Hajnoczi  --disable-vhost-vsock) vhost_vsock="no"
1020fc0b9b0eSStefan Hajnoczi  ;;
1021fc0b9b0eSStefan Hajnoczi  --enable-vhost-vsock) vhost_vsock="yes"
1022fc0b9b0eSStefan Hajnoczi  ;;
102398fc1adaSDr. David Alan Gilbert  --disable-vhost-user-fs) vhost_user_fs="no"
102498fc1adaSDr. David Alan Gilbert  ;;
102598fc1adaSDr. David Alan Gilbert  --enable-vhost-user-fs) vhost_user_fs="yes"
102698fc1adaSDr. David Alan Gilbert  ;;
1027da076ffeSGerd Hoffmann  --disable-opengl) opengl="no"
102820ff075bSMichael Walle  ;;
1029da076ffeSGerd Hoffmann  --enable-opengl) opengl="yes"
103020ff075bSMichael Walle  ;;
10318c84cf11SSergei Trofimovich  --disable-xfsctl) xfs="no"
10328c84cf11SSergei Trofimovich  ;;
10338c84cf11SSergei Trofimovich  --enable-xfsctl) xfs="yes"
10348c84cf11SSergei Trofimovich  ;;
10351ffb3bbbSPaolo Bonzini  --disable-zlib-test)
10361ece9905SAlon Levy  ;;
1037d138cee9SMichael Roth  --enable-guest-agent) guest_agent="yes"
1038d138cee9SMichael Roth  ;;
1039d138cee9SMichael Roth  --disable-guest-agent) guest_agent="no"
1040d138cee9SMichael Roth  ;;
1041d9840e25STomoki Sekiyama  --with-vss-sdk) vss_win32_sdk=""
1042d9840e25STomoki Sekiyama  ;;
1043d9840e25STomoki Sekiyama  --with-vss-sdk=*) vss_win32_sdk="$optarg"
1044d9840e25STomoki Sekiyama  ;;
1045d9840e25STomoki Sekiyama  --without-vss-sdk) vss_win32_sdk="no"
1046d9840e25STomoki Sekiyama  ;;
1047d9840e25STomoki Sekiyama  --with-win-sdk) win_sdk=""
1048d9840e25STomoki Sekiyama  ;;
1049d9840e25STomoki Sekiyama  --with-win-sdk=*) win_sdk="$optarg"
1050d9840e25STomoki Sekiyama  ;;
1051d9840e25STomoki Sekiyama  --without-win-sdk) win_sdk="no"
1052d9840e25STomoki Sekiyama  ;;
10534b1c11fdSDaniel P. Berrange  --enable-tools) want_tools="yes"
10544b1c11fdSDaniel P. Berrange  ;;
10554b1c11fdSDaniel P. Berrange  --disable-tools) want_tools="no"
10564b1c11fdSDaniel P. Berrange  ;;
105786583a07SLiam Merwick  --disable-avx2) avx2_opt="no"
105886583a07SLiam Merwick  ;;
105986583a07SLiam Merwick  --enable-avx2) avx2_opt="yes"
106086583a07SLiam Merwick  ;;
10616b8cd447SRobert Hoo  --disable-avx512f) avx512f_opt="no"
10626b8cd447SRobert Hoo  ;;
10636b8cd447SRobert Hoo  --enable-avx512f) avx512f_opt="yes"
10646b8cd447SRobert Hoo  ;;
106552b53c04SFam Zheng  --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
106652b53c04SFam Zheng      echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
1067583f6e7bSStefan Hajnoczi  ;;
1068cb6414dfSFam Zheng  --enable-vhdx|--disable-vhdx)
1069cb6414dfSFam Zheng      echo "$0: $opt is obsolete, VHDX driver is always built" >&2
1070cb6414dfSFam Zheng  ;;
1071315d3184SFam Zheng  --enable-uuid|--disable-uuid)
1072315d3184SFam Zheng      echo "$0: $opt is obsolete, UUID support is always built" >&2
1073315d3184SFam Zheng  ;;
1074a1c5e949SDaniel P. Berrange  --tls-priority=*) tls_priority="$optarg"
1075a1c5e949SDaniel P. Berrange  ;;
10762da776dbSMichael R. Hines  --enable-rdma) rdma="yes"
10772da776dbSMichael R. Hines  ;;
10782da776dbSMichael R. Hines  --disable-rdma) rdma="no"
10792da776dbSMichael R. Hines  ;;
108021ab34c9SMarcel Apfelbaum  --enable-pvrdma) pvrdma="yes"
108121ab34c9SMarcel Apfelbaum  ;;
108221ab34c9SMarcel Apfelbaum  --disable-pvrdma) pvrdma="no"
108321ab34c9SMarcel Apfelbaum  ;;
1084e91c793cSCole Robinson  --disable-tpm) tpm="no"
1085e91c793cSCole Robinson  ;;
1086ab214c29SStefan Berger  --enable-tpm) tpm="yes"
1087ab214c29SStefan Berger  ;;
1088ed1701c6SDr. David Alan Gilbert  --disable-live-block-migration) live_block_migration="no"
1089ed1701c6SDr. David Alan Gilbert  ;;
1090ed1701c6SDr. David Alan Gilbert  --enable-live-block-migration) live_block_migration="yes"
1091ed1701c6SDr. David Alan Gilbert  ;;
1092a99d57bbSWanlong Gao  --disable-numa) numa="no"
1093a99d57bbSWanlong Gao  ;;
1094a99d57bbSWanlong Gao  --enable-numa) numa="yes"
1095a99d57bbSWanlong Gao  ;;
1096a6b1d4c0SChanglong Xie  --disable-replication) replication="no"
1097a6b1d4c0SChanglong Xie  ;;
1098a6b1d4c0SChanglong Xie  --enable-replication) replication="yes"
1099a6b1d4c0SChanglong Xie  ;;
11002f740136SJeff Cody  --disable-bochs) bochs="no"
11012f740136SJeff Cody  ;;
11022f740136SJeff Cody  --enable-bochs) bochs="yes"
11032f740136SJeff Cody  ;;
11042f740136SJeff Cody  --disable-cloop) cloop="no"
11052f740136SJeff Cody  ;;
11062f740136SJeff Cody  --enable-cloop) cloop="yes"
11072f740136SJeff Cody  ;;
11082f740136SJeff Cody  --disable-dmg) dmg="no"
11092f740136SJeff Cody  ;;
11102f740136SJeff Cody  --enable-dmg) dmg="yes"
11112f740136SJeff Cody  ;;
11122f740136SJeff Cody  --disable-qcow1) qcow1="no"
11132f740136SJeff Cody  ;;
11142f740136SJeff Cody  --enable-qcow1) qcow1="yes"
11152f740136SJeff Cody  ;;
11162f740136SJeff Cody  --disable-vdi) vdi="no"
11172f740136SJeff Cody  ;;
11182f740136SJeff Cody  --enable-vdi) vdi="yes"
11192f740136SJeff Cody  ;;
11202f740136SJeff Cody  --disable-vvfat) vvfat="no"
11212f740136SJeff Cody  ;;
11222f740136SJeff Cody  --enable-vvfat) vvfat="yes"
11232f740136SJeff Cody  ;;
11242f740136SJeff Cody  --disable-qed) qed="no"
11252f740136SJeff Cody  ;;
11262f740136SJeff Cody  --enable-qed) qed="yes"
11272f740136SJeff Cody  ;;
11282f740136SJeff Cody  --disable-parallels) parallels="no"
11292f740136SJeff Cody  ;;
11302f740136SJeff Cody  --enable-parallels) parallels="yes"
11312f740136SJeff Cody  ;;
1132e6a74868SMarc-André Lureau  --disable-vhost-user) vhost_user="no"
1133e6a74868SMarc-André Lureau  ;;
1134299e6f19SPaolo Bonzini  --enable-vhost-user) vhost_user="yes"
1135299e6f19SPaolo Bonzini  ;;
1136108a6481SCindy Lu  --disable-vhost-vdpa) vhost_vdpa="no"
1137108a6481SCindy Lu  ;;
1138108a6481SCindy Lu  --enable-vhost-vdpa) vhost_vdpa="yes"
1139108a6481SCindy Lu  ;;
1140299e6f19SPaolo Bonzini  --disable-vhost-kernel) vhost_kernel="no"
1141299e6f19SPaolo Bonzini  ;;
1142299e6f19SPaolo Bonzini  --enable-vhost-kernel) vhost_kernel="yes"
1143e6a74868SMarc-André Lureau  ;;
11448b18cdbfSRichard Henderson  --disable-capstone) capstone="disabled"
11458ca80760SRichard Henderson  ;;
11468b18cdbfSRichard Henderson  --enable-capstone) capstone="enabled"
11478ca80760SRichard Henderson  ;;
11488b18cdbfSRichard Henderson  --enable-capstone=git) capstone="internal"
1149e219c499SRichard Henderson  ;;
115003a3c0b3SPaolo Bonzini  --enable-capstone=*) capstone="$optarg"
1151e219c499SRichard Henderson  ;;
1152cc84d63aSDaniel P. Berrange  --with-git=*) git="$optarg"
1153cc84d63aSDaniel P. Berrange  ;;
11547d7dbf9dSDan Streetman  --with-git-submodules=*)
11557d7dbf9dSDan Streetman      git_submodules_action="$optarg"
1156f62bbee5SDaniel P. Berrange  ;;
1157ba59fb77SPaolo Bonzini  --enable-debug-mutex) debug_mutex=yes
1158ba59fb77SPaolo Bonzini  ;;
1159ba59fb77SPaolo Bonzini  --disable-debug-mutex) debug_mutex=no
1160ba59fb77SPaolo Bonzini  ;;
11619b8e4298SAlex Bennée  --enable-plugins) if test "$mingw32" = "yes"; then
11629b8e4298SAlex Bennée                        error_exit "TCG plugins not currently supported on Windows platforms"
11639b8e4298SAlex Bennée                    else
11649b8e4298SAlex Bennée                        plugins="yes"
11659b8e4298SAlex Bennée                    fi
116640e8c6f4SAlex Bennée  ;;
116740e8c6f4SAlex Bennée  --disable-plugins) plugins="no"
116840e8c6f4SAlex Bennée  ;;
1169afc3a8f9SAlex Bennée  --enable-containers) use_containers="yes"
1170afc3a8f9SAlex Bennée  ;;
1171afc3a8f9SAlex Bennée  --disable-containers) use_containers="no"
1172afc3a8f9SAlex Bennée  ;;
1173f48e590aSAlex Bennée  --gdb=*) gdb_bin="$optarg"
1174f48e590aSAlex Bennée  ;;
1175b767d257SMarek Marczykowski-Górecki  --enable-rng-none) rng_none=yes
1176b767d257SMarek Marczykowski-Górecki  ;;
1177b767d257SMarek Marczykowski-Górecki  --disable-rng-none) rng_none=no
1178b767d257SMarek Marczykowski-Górecki  ;;
117954e7aac0SAlexey Krasikov  --enable-keyring) secret_keyring="yes"
118054e7aac0SAlexey Krasikov  ;;
118154e7aac0SAlexey Krasikov  --disable-keyring) secret_keyring="no"
118254e7aac0SAlexey Krasikov  ;;
118320cf7b8eSDenis Plotnikov  --enable-gio) gio=yes
118420cf7b8eSDenis Plotnikov  ;;
118520cf7b8eSDenis Plotnikov  --disable-gio) gio=no
118620cf7b8eSDenis Plotnikov  ;;
1187b8e0c493SJoelle van Dyne  --enable-slirp-smbd) slirp_smbd=yes
1188b8e0c493SJoelle van Dyne  ;;
1189b8e0c493SJoelle van Dyne  --disable-slirp-smbd) slirp_smbd=no
1190b8e0c493SJoelle van Dyne  ;;
11913b4da132SPaolo Bonzini  # backwards compatibility options
11923b4da132SPaolo Bonzini  --enable-trace-backend=*) meson_option_parse "--enable-trace-backends=$optarg" "$optarg"
11933b4da132SPaolo Bonzini  ;;
11943b4da132SPaolo Bonzini  --disable-blobs) meson_option_parse --disable-install-blobs ""
11953b4da132SPaolo Bonzini  ;;
11963b4da132SPaolo Bonzini  --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
11973b4da132SPaolo Bonzini  ;;
11983b4da132SPaolo Bonzini  --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
11993b4da132SPaolo Bonzini  ;;
12003b4da132SPaolo Bonzini  # everything else has the same name in configure and meson
120161d63097SPaolo Bonzini  --enable-* | --disable-*) meson_option_parse "$opt" "$optarg"
120261d63097SPaolo Bonzini  ;;
12032d2ad6d0SFam Zheng  *)
12042d2ad6d0SFam Zheng      echo "ERROR: unknown option $opt"
12052d2ad6d0SFam Zheng      echo "Try '$0 --help' for more information"
12062d2ad6d0SFam Zheng      exit 1
12077f1559c6Sbalrog  ;;
12087d13299dSbellard  esac
12097d13299dSbellarddone
12107d13299dSbellard
1211d1a14257SAlex Bennée# test for any invalid configuration combinations
1212d1a14257SAlex Bennéeif test "$plugins" = "yes" -a "$tcg" = "disabled"; then
1213d1a14257SAlex Bennée    error_exit "Can't enable plugins on non-TCG builds"
1214d1a14257SAlex Bennéefi
1215d1a14257SAlex Bennée
12167d7dbf9dSDan Streetmancase $git_submodules_action in
12177d7dbf9dSDan Streetman    update|validate)
12187d7dbf9dSDan Streetman        if test ! -e "$source_path/.git"; then
12197d7dbf9dSDan Streetman            echo "ERROR: cannot $git_submodules_action git submodules without .git"
12207d7dbf9dSDan Streetman            exit 1
12217d7dbf9dSDan Streetman        fi
12227d7dbf9dSDan Streetman    ;;
12237d7dbf9dSDan Streetman    ignore)
1224b80fd281SPaolo Bonzini        if ! test -f "$source_path/ui/keycodemapdb/README"
1225b80fd281SPaolo Bonzini        then
1226b80fd281SPaolo Bonzini            echo
1227b80fd281SPaolo Bonzini            echo "ERROR: missing GIT submodules"
1228b80fd281SPaolo Bonzini            echo
1229b80fd281SPaolo Bonzini            if test -e "$source_path/.git"; then
1230b80fd281SPaolo Bonzini                echo "--with-git-submodules=ignore specified but submodules were not"
1231b80fd281SPaolo Bonzini                echo "checked out.  Please initialize and update submodules."
1232b80fd281SPaolo Bonzini            else
1233b80fd281SPaolo Bonzini                echo "This is not a GIT checkout but module content appears to"
1234b80fd281SPaolo Bonzini                echo "be missing. Do not use 'git archive' or GitHub download links"
1235b80fd281SPaolo Bonzini                echo "to acquire QEMU source archives. Non-GIT builds are only"
1236b80fd281SPaolo Bonzini                echo "supported with source archives linked from:"
1237b80fd281SPaolo Bonzini                echo
1238b80fd281SPaolo Bonzini                echo "  https://www.qemu.org/download/#source"
1239b80fd281SPaolo Bonzini                echo
1240b80fd281SPaolo Bonzini                echo "Developers working with GIT can use scripts/archive-source.sh"
1241b80fd281SPaolo Bonzini                echo "if they need to create valid source archives."
1242b80fd281SPaolo Bonzini            fi
1243b80fd281SPaolo Bonzini            echo
1244b80fd281SPaolo Bonzini            exit 1
1245b80fd281SPaolo Bonzini        fi
12467d7dbf9dSDan Streetman    ;;
12477d7dbf9dSDan Streetman    *)
12487d7dbf9dSDan Streetman        echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
12497d7dbf9dSDan Streetman        exit 1
12507d7dbf9dSDan Streetman    ;;
12517d7dbf9dSDan Streetmanesac
12527d7dbf9dSDan Streetman
125322a87800SMarc-André Lureaulibdir="${libdir:-$prefix/lib}"
125422a87800SMarc-André Lureaulibexecdir="${libexecdir:-$prefix/libexec}"
125522a87800SMarc-André Lureauincludedir="${includedir:-$prefix/include}"
125622a87800SMarc-André Lureau
125722a87800SMarc-André Lureauif test "$mingw32" = "yes" ; then
125815588a62SJoshua Watt    bindir="${bindir:-$prefix}"
125922a87800SMarc-André Lureauelse
126015588a62SJoshua Watt    bindir="${bindir:-$prefix/bin}"
126115588a62SJoshua Wattfi
126222a87800SMarc-André Lureaumandir="${mandir:-$prefix/share/man}"
126322a87800SMarc-André Lureaudatadir="${datadir:-$prefix/share}"
1264ca8c0909SMarc-André Lureaudocdir="${docdir:-$prefix/share/doc}"
126522a87800SMarc-André Lureausysconfdir="${sysconfdir:-$prefix/etc}"
126622a87800SMarc-André Lureaulocal_statedir="${local_statedir:-$prefix/var}"
126716bf7a33SPaolo Bonzinifirmwarepath="${firmwarepath:-$datadir/qemu-firmware}"
126816bf7a33SPaolo Bonzinilocaledir="${localedir:-$datadir/locale}"
126922a87800SMarc-André Lureau
12709557af9cSAlex Bennéeif eval test -z "\${cross_cc_$cpu}"; then
1271b1aa4de1SAlex Bennée    eval "cross_cc_${cpu}=\$cc"
12722038f8c8SPaolo Bonzini    cross_cc_vars="$cross_cc_vars cross_cc_${cpu}"
12739557af9cSAlex Bennéefi
127479f3b12fSPeter Crosthwaite
1275affc88ccSPeter Maydell# For user-mode emulation the host arch has to be one we explicitly
1276affc88ccSPeter Maydell# support, even if we're using TCI.
1277affc88ccSPeter Maydellif [ "$ARCH" = "unknown" ]; then
1278affc88ccSPeter Maydell  bsd_user="no"
1279affc88ccSPeter Maydell  linux_user="no"
1280affc88ccSPeter Maydellfi
1281affc88ccSPeter Maydell
128260e0df25SPeter Maydelldefault_target_list=""
128343692239SMarkus Armbrusterdeprecated_targets_list=ppc64abi32-linux-user
1284fdb75aefSPaolo Bonzinideprecated_features=""
12856e92f823SPeter Maydellmak_wilds=""
12866e92f823SPeter Maydell
128760e0df25SPeter Maydellif [ "$softmmu" = "yes" ]; then
1288812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
128960e0df25SPeter Maydellfi
129060e0df25SPeter Maydellif [ "$linux_user" = "yes" ]; then
1291812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
129260e0df25SPeter Maydellfi
129360e0df25SPeter Maydellif [ "$bsd_user" = "yes" ]; then
1294812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
129560e0df25SPeter Maydellfi
129660e0df25SPeter Maydell
12973a5ae4a9SAlex Bennée# If the user doesn't explicitly specify a deprecated target we will
12983a5ae4a9SAlex Bennée# skip it.
12993a5ae4a9SAlex Bennéeif test -z "$target_list"; then
13003a5ae4a9SAlex Bennée    if test -z "$target_list_exclude"; then
13013a5ae4a9SAlex Bennée        target_list_exclude="$deprecated_targets_list"
13023a5ae4a9SAlex Bennée    else
13033a5ae4a9SAlex Bennée        target_list_exclude="$target_list_exclude,$deprecated_targets_list"
13043a5ae4a9SAlex Bennée    fi
13052d838d9bSAlex Bennéefi
13062d838d9bSAlex Bennée
1307447e133fSAlex Bennéefor config in $mak_wilds; do
1308447e133fSAlex Bennée    target="$(basename "$config" .mak)"
130998db9a06SAlex Bennée    if echo "$target_list_exclude" | grep -vq "$target"; then
1310447e133fSAlex Bennée        default_target_list="${default_target_list} $target"
1311447e133fSAlex Bennée    fi
1312447e133fSAlex Bennéedone
13136e92f823SPeter Maydell
1314af5db58eSpbrookif test x"$show_help" = x"yes" ; then
1315af5db58eSpbrookcat << EOF
1316af5db58eSpbrook
1317af5db58eSpbrookUsage: configure [options]
1318af5db58eSpbrookOptions: [defaults in brackets after descriptions]
1319af5db58eSpbrook
132008fb77edSStefan WeilStandard options:
132108fb77edSStefan Weil  --help                   print this message
132208fb77edSStefan Weil  --prefix=PREFIX          install in PREFIX [$prefix]
132308fb77edSStefan Weil  --interp-prefix=PREFIX   where to find shared libraries, etc.
132408fb77edSStefan Weil                           use %M for cpu name [$interp_prefix]
13252deca810SAlex Bennée  --target-list=LIST       set target list (default: build all non-deprecated)
132608fb77edSStefan Weil$(echo Available targets: $default_target_list | \
132708fb77edSStefan Weil  fold -s -w 53 | sed -e 's/^/                           /')
13282deca810SAlex Bennée$(echo Deprecated targets: $deprecated_targets_list | \
13292deca810SAlex Bennée  fold -s -w 53 | sed -e 's/^/                           /')
1330447e133fSAlex Bennée  --target-list-exclude=LIST exclude a set of targets from the default target-list
133108fb77edSStefan Weil
133208fb77edSStefan WeilAdvanced options (experts only):
13333812c0c4SJoelle van Dyne  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
133408fb77edSStefan Weil  --cc=CC                  use C compiler CC [$cc]
133508fb77edSStefan Weil  --iasl=IASL              use ACPI compiler IASL [$iasl]
133608fb77edSStefan Weil  --host-cc=CC             use C compiler CC [$host_cc] for code run at
133708fb77edSStefan Weil                           build time
133808fb77edSStefan Weil  --cxx=CXX                use C++ compiler CXX [$cxx]
133908fb77edSStefan Weil  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
1340a2866660SPaolo Bonzini  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
1341a2866660SPaolo Bonzini  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
134208fb77edSStefan Weil  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
1343d75402b5SAlex Bennée  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
1344d422b2bcSAlex Bennée  --cross-cc-flags-ARCH=   use compiler flags when building ARCH guest tests
134508fb77edSStefan Weil  --make=MAKE              use specified make [$make]
134608fb77edSStefan Weil  --python=PYTHON          use specified python [$python]
13472eb054c2SPeter Maydell  --sphinx-build=SPHINX    use specified sphinx-build [$sphinx_build]
1348a5665051SPaolo Bonzini  --meson=MESON            use specified meson [$meson]
134948328880SPaolo Bonzini  --ninja=NINJA            use specified ninja [$ninja]
135008fb77edSStefan Weil  --smbd=SMBD              use specified smbd [$smbd]
1351db1b5f13SThomas Huth  --with-git=GIT           use specified git [$git]
13527d7dbf9dSDan Streetman  --with-git-submodules=update   update git submodules (default if .git dir exists)
13537d7dbf9dSDan Streetman  --with-git-submodules=validate fail if git submodules are not up to date
13547d7dbf9dSDan Streetman  --with-git-submodules=ignore   do not update or check git submodules (default if no .git dir)
135508fb77edSStefan Weil  --static                 enable static build [$static]
135608fb77edSStefan Weil  --mandir=PATH            install man pages in PATH
135710ff82d1SMarc-André Lureau  --datadir=PATH           install firmware in PATH/$qemu_suffix
1358fe0038beSPaolo Bonzini  --localedir=PATH         install translation in PATH/$qemu_suffix
135910ff82d1SMarc-André Lureau  --docdir=PATH            install documentation in PATH/$qemu_suffix
136008fb77edSStefan Weil  --bindir=PATH            install binaries in PATH
136108fb77edSStefan Weil  --libdir=PATH            install libraries in PATH
1362db1b5f13SThomas Huth  --libexecdir=PATH        install helper binaries in PATH
136310ff82d1SMarc-André Lureau  --sysconfdir=PATH        install config in PATH/$qemu_suffix
136408fb77edSStefan Weil  --localstatedir=PATH     install local state in PATH (set at runtime on win32)
13653d5eecabSGerd Hoffmann  --firmwarepath=PATH      search PATH for firmware files
136613336606SRobert Foley  --efi-aarch64=PATH       PATH of efi file to use for aarch64 VMs.
1367ca8c0909SMarc-André Lureau  --with-suffix=SUFFIX     suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
1368db1b5f13SThomas Huth  --with-pkgversion=VERS   use specified string as sub-version of the package
1369c035c8d6SPaolo Bonzini  --without-default-features default all --enable-* options to "disabled"
1370c035c8d6SPaolo Bonzini  --without-default-devices  do not include any device that is not needed to
1371c035c8d6SPaolo Bonzini                           start the emulator (only use if you are including
1372d1d5e9eeSAlex Bennée                           desired devices in configs/devices/)
1373d1d5e9eeSAlex Bennée  --with-devices-ARCH=NAME override default configs/devices
137408fb77edSStefan Weil  --enable-debug           enable common debug build options
1375247724cbSMarc-André Lureau  --enable-sanitizers      enable default sanitizers
13760aebab04SLingfeng Yang  --enable-tsan            enable thread sanitizer
137708fb77edSStefan Weil  --disable-strip          disable stripping binaries
137808fb77edSStefan Weil  --disable-werror         disable compilation abort on warning
137963678e17SSteven Noonan  --disable-stack-protector disable compiler-provided stack protection
138016bfbc70SPaolo Bonzini  --audio-drv-list=LIST    set audio drivers to try if -audiodev is not used
138108fb77edSStefan Weil  --block-drv-whitelist=L  Same as --block-drv-rw-whitelist=L
138208fb77edSStefan Weil  --block-drv-rw-whitelist=L
138308fb77edSStefan Weil                           set block driver read-write whitelist
1384e5f05f8cSKevin Wolf                           (by default affects only QEMU, not tools like qemu-img)
138508fb77edSStefan Weil  --block-drv-ro-whitelist=L
138608fb77edSStefan Weil                           set block driver read-only whitelist
1387e5f05f8cSKevin Wolf                           (by default affects only QEMU, not tools like qemu-img)
1388e5f05f8cSKevin Wolf  --enable-block-drv-whitelist-in-tools
1389e5f05f8cSKevin Wolf                           use block whitelist also in tools instead of only QEMU
139008fb77edSStefan Weil  --with-trace-file=NAME   Full PATH,NAME of file to store traces
139108fb77edSStefan Weil                           Default:trace-<pid>
1392c23f23b9SMichael Tokarev  --cpu=CPU                Build for host CPU [$cpu]
139308fb77edSStefan Weil  --with-coroutine=BACKEND coroutine backend. Supported options:
139433c53c54SDaniel P. Berrange                           ucontext, sigaltstack, windows
139508fb77edSStefan Weil  --enable-gcov            enable test coverage analysis with gcov
1396c23f23b9SMichael Tokarev  --with-vss-sdk=SDK-path  enable Windows VSS support in QEMU Guest Agent
1397c23f23b9SMichael Tokarev  --with-win-sdk=SDK-path  path to Windows Platform SDK (to build VSS .tlb)
1398a1c5e949SDaniel P. Berrange  --tls-priority           default TLS protocol/cipher priority string
1399c12d66aaSLin Ma  --enable-gprof           QEMU profiling with gprof
1400c12d66aaSLin Ma  --enable-profiler        profiler support
1401c12d66aaSLin Ma  --enable-debug-stack-usage
1402c12d66aaSLin Ma                           track the maximum stack usage of stacks created by qemu_alloc_stack
140340e8c6f4SAlex Bennée  --enable-plugins
140440e8c6f4SAlex Bennée                           enable plugins via shared library loading
1405afc3a8f9SAlex Bennée  --disable-containers     don't use containers for cross-building
1406f48e590aSAlex Bennée  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
140761d63097SPaolo BonziniEOF
140861d63097SPaolo Bonzini  meson_options_help
140961d63097SPaolo Bonzinicat << EOF
1410c23f23b9SMichael Tokarev  system          all system emulation targets
1411c23f23b9SMichael Tokarev  user            supported user emulation targets
1412c23f23b9SMichael Tokarev  linux-user      all linux usermode emulation targets
1413c23f23b9SMichael Tokarev  bsd-user        all BSD usermode emulation targets
1414c23f23b9SMichael Tokarev  guest-agent     build the QEMU Guest Agent
1415c23f23b9SMichael Tokarev  pie             Position Independent Executables
141621e709aaSMarc-André Lureau  modules         modules support (non-Windows)
1417bd83c861SChristian Ehrhardt  module-upgrades try to load modules from alternate paths for upgrades
1418c23f23b9SMichael Tokarev  debug-tcg       TCG debugging (default is disabled)
1419c23f23b9SMichael Tokarev  debug-info      debugging information
1420cdad781dSDaniele Buono  lto             Enable Link-Time Optimization.
14211e4f6065SDaniele Buono  safe-stack      SafeStack Stack Smash Protection. Depends on
14221e4f6065SDaniele Buono                  clang/llvm >= 3.7 and requires coroutine backend ucontext.
1423a40161cbSPaolo Bonzini  membarrier      membarrier system call (for Linux 4.14+ or Windows)
142421ab34c9SMarcel Apfelbaum  rdma            Enable RDMA-based migration
142521ab34c9SMarcel Apfelbaum  pvrdma          Enable PVRDMA support
1426299e6f19SPaolo Bonzini  vhost-net       vhost-net kernel acceleration support
1427299e6f19SPaolo Bonzini  vhost-vsock     virtio sockets device support
1428299e6f19SPaolo Bonzini  vhost-scsi      vhost-scsi kernel target support
1429299e6f19SPaolo Bonzini  vhost-crypto    vhost-user-crypto backend support
1430299e6f19SPaolo Bonzini  vhost-kernel    vhost kernel backend support
1431299e6f19SPaolo Bonzini  vhost-user      vhost-user backend support
1432108a6481SCindy Lu  vhost-vdpa      vhost-vdpa kernel backend support
1433ed1701c6SDr. David Alan Gilbert  live-block-migration   Block migration in the main migration stream
1434c23f23b9SMichael Tokarev  coroutine-pool  coroutine freelist (better performance)
1435c23f23b9SMichael Tokarev  tpm             TPM support
1436c23f23b9SMichael Tokarev  numa            libnuma support
143786583a07SLiam Merwick  avx2            AVX2 optimization support
14386b8cd447SRobert Hoo  avx512f         AVX512F optimization support
1439a6b1d4c0SChanglong Xie  replication     replication support
1440c12d66aaSLin Ma  opengl          opengl support
1441c12d66aaSLin Ma  xfsctl          xfsctl support
1442c12d66aaSLin Ma  qom-cast-debug  cast debugging support
14438de73fa8SCleber Rosa  tools           build qemu-io, qemu-nbd and qemu-img tools
14442f740136SJeff Cody  bochs           bochs image format support
14452f740136SJeff Cody  cloop           cloop image format support
14462f740136SJeff Cody  dmg             dmg image format support
14472f740136SJeff Cody  qcow1           qcow v1 image format support
14482f740136SJeff Cody  vdi             vdi image format support
14492f740136SJeff Cody  vvfat           vvfat image format support
14502f740136SJeff Cody  qed             qed image format support
14512f740136SJeff Cody  parallels       parallels image format support
1452f0d92b56SLongpeng(Mike)  crypto-afalg    Linux AF_ALG crypto backend driver
1453ba59fb77SPaolo Bonzini  debug-mutex     mutex debugging support
1454b767d257SMarek Marczykowski-Górecki  rng-none        dummy RNG, avoid using /dev/(u)random and getrandom()
145520cf7b8eSDenis Plotnikov  gio             libgio support
1456b8e0c493SJoelle van Dyne  slirp-smbd      use smbd (at path --smbd=*) in slirp networking
145708fb77edSStefan Weil
145808fb77edSStefan WeilNOTE: The object files are built at the place where configure is launched
1459af5db58eSpbrookEOF
14602d2ad6d0SFam Zhengexit 0
1461af5db58eSpbrookfi
1462af5db58eSpbrook
14639c790242SThomas Huth# Remove old dependency files to make sure that they get properly regenerated
1464bb768f71SThomas Huthrm -f */config-devices.mak.d
14659c790242SThomas Huth
1466faf44142SDaniel P. Berrangéif test -z "$python"
1467faf44142SDaniel P. Berrangéthen
1468c53eeaf7SStefan Hajnoczi    error_exit "Python not found. Use --python=/path/to/python"
1469c53eeaf7SStefan Hajnoczifi
14708e2c76bdSRoman Bolshakovif ! has "$make"
14718e2c76bdSRoman Bolshakovthen
14728e2c76bdSRoman Bolshakov    error_exit "GNU make ($make) not found"
14738e2c76bdSRoman Bolshakovfi
1474c53eeaf7SStefan Hajnoczi
1475c53eeaf7SStefan Hajnoczi# Note that if the Python conditional here evaluates True we will exit
1476c53eeaf7SStefan Hajnoczi# with status 1 which is a shell 'false' value.
14771b11f28dSThomas Huthif ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then
14781b11f28dSThomas Huth  error_exit "Cannot use '$python', Python >= 3.6 is required." \
1479c53eeaf7SStefan Hajnoczi      "Use --python=/path/to/python to specify a supported Python."
1480c53eeaf7SStefan Hajnoczifi
1481c53eeaf7SStefan Hajnoczi
1482755ee70fSCleber Rosa# Preserve python version since some functionality is dependent on it
1483406ab2f3SCleber Rosapython_version=$($python -c 'import sys; print("%d.%d.%d" % (sys.version_info[0], sys.version_info[1], sys.version_info[2]))' 2>/dev/null)
1484755ee70fSCleber Rosa
1485c53eeaf7SStefan Hajnoczi# Suppress writing compiled files
1486c53eeaf7SStefan Hajnoczipython="$python -B"
1487c53eeaf7SStefan Hajnoczi
14880a01d76fSMarc-André Lureauif test -z "$meson"; then
14896638cae5SPaolo Bonzini    if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.59.3; then
14900a01d76fSMarc-André Lureau        meson=meson
14917d7dbf9dSDan Streetman    elif test $git_submodules_action != 'ignore' ; then
14920a01d76fSMarc-André Lureau        meson=git
14930a01d76fSMarc-André Lureau    elif test -e "${source_path}/meson/meson.py" ; then
14940a01d76fSMarc-André Lureau        meson=internal
14950a01d76fSMarc-André Lureau    else
14960a01d76fSMarc-André Lureau        if test "$explicit_python" = yes; then
14970a01d76fSMarc-André Lureau            error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
14980a01d76fSMarc-André Lureau        else
1499a5665051SPaolo Bonzini            error_exit "Meson not found.  Use --meson=/path/to/meson"
1500a5665051SPaolo Bonzini        fi
15010a01d76fSMarc-André Lureau    fi
15020a01d76fSMarc-André Lureauelse
15030a01d76fSMarc-André Lureau    # Meson uses its own Python interpreter to invoke other Python scripts,
15040a01d76fSMarc-André Lureau    # but the user wants to use the one they specified with --python.
15050a01d76fSMarc-André Lureau    #
15060a01d76fSMarc-André Lureau    # We do not want to override the distro Python interpreter (and sometimes
15070a01d76fSMarc-André Lureau    # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
15080a01d76fSMarc-André Lureau    # just require --meson=git|internal together with --python.
15090a01d76fSMarc-André Lureau    if test "$explicit_python" = yes; then
15100a01d76fSMarc-André Lureau        case "$meson" in
15110a01d76fSMarc-André Lureau            git | internal) ;;
15120a01d76fSMarc-André Lureau            *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
15130a01d76fSMarc-André Lureau        esac
15140a01d76fSMarc-André Lureau    fi
15150a01d76fSMarc-André Lureaufi
1516a5665051SPaolo Bonzini
15170a01d76fSMarc-André Lureauif test "$meson" = git; then
15180a01d76fSMarc-André Lureau    git_submodules="${git_submodules} meson"
15190a01d76fSMarc-André Lureaufi
15200a01d76fSMarc-André Lureau
15210a01d76fSMarc-André Lureaucase "$meson" in
15220a01d76fSMarc-André Lureau    git | internal)
15230a01d76fSMarc-André Lureau        meson="$python ${source_path}/meson/meson.py"
15240a01d76fSMarc-André Lureau        ;;
152584ec0c24SPaolo Bonzini    *) meson=$(command -v "$meson") ;;
15260a01d76fSMarc-André Lureauesac
15270a01d76fSMarc-André Lureau
152809e93326SPaolo Bonzini# Probe for ninja
152948328880SPaolo Bonzini
153048328880SPaolo Bonziniif test -z "$ninja"; then
153148328880SPaolo Bonzini    for c in ninja ninja-build samu; do
153248328880SPaolo Bonzini        if has $c; then
153348328880SPaolo Bonzini            ninja=$(command -v "$c")
153448328880SPaolo Bonzini            break
153548328880SPaolo Bonzini        fi
153648328880SPaolo Bonzini    done
153709e93326SPaolo Bonzini    if test -z "$ninja"; then
153809e93326SPaolo Bonzini      error_exit "Cannot find Ninja"
153909e93326SPaolo Bonzini    fi
154048328880SPaolo Bonzinifi
1541a5665051SPaolo Bonzini
15429aae6e54SDaniel Henrique Barboza# Check that the C compiler works. Doing this here before testing
15439aae6e54SDaniel Henrique Barboza# the host CPU ensures that we had a valid CC to autodetect the
15449aae6e54SDaniel Henrique Barboza# $cpu var (and we should bail right here if that's not the case).
15459aae6e54SDaniel Henrique Barboza# It also allows the help message to be printed without a CC.
15469aae6e54SDaniel Henrique Barbozawrite_c_skeleton;
15479aae6e54SDaniel Henrique Barbozaif compile_object ; then
15489aae6e54SDaniel Henrique Barboza  : C compiler works ok
15499aae6e54SDaniel Henrique Barbozaelse
15509aae6e54SDaniel Henrique Barboza    error_exit "\"$cc\" either does not exist or does not work"
15519aae6e54SDaniel Henrique Barbozafi
15529aae6e54SDaniel Henrique Barbozaif ! compile_prog ; then
15539aae6e54SDaniel Henrique Barboza    error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
15549aae6e54SDaniel Henrique Barbozafi
15559aae6e54SDaniel Henrique Barboza
15569c83ffd8SPeter Maydell# Consult white-list to determine whether to enable werror
15579c83ffd8SPeter Maydell# by default.  Only enable by default for git builds
15589c83ffd8SPeter Maydellif test -z "$werror" ; then
15597d7dbf9dSDan Streetman    if test "$git_submodules_action" != "ignore" && \
1560e633a5c6SEric Blake        { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
15619c83ffd8SPeter Maydell        werror="yes"
15629c83ffd8SPeter Maydell    else
15639c83ffd8SPeter Maydell        werror="no"
15649c83ffd8SPeter Maydell    fi
15659c83ffd8SPeter Maydellfi
15669c83ffd8SPeter Maydell
1567975ff037SPaolo Bonziniif test "$targetos" = "bogus"; then
1568fb59dabdSPeter Maydell    # Now that we know that we're not printing the help and that
1569fb59dabdSPeter Maydell    # the compiler works (so the results of the check_defines we used
1570fb59dabdSPeter Maydell    # to identify the OS are reliable), if we didn't recognize the
1571fb59dabdSPeter Maydell    # host OS we should stop now.
1572951fedfcSPeter Maydell    error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1573fb59dabdSPeter Maydellfi
1574fb59dabdSPeter Maydell
1575efc6c070SThomas Huth# Check whether the compiler matches our minimum requirements:
1576efc6c070SThomas Huthcat > $TMPC << EOF
1577efc6c070SThomas Huth#if defined(__clang_major__) && defined(__clang_minor__)
1578efc6c070SThomas Huth# ifdef __apple_build_version__
15792a85a08cSDaniel P. Berrangé#  if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
15802a85a08cSDaniel P. Berrangé#   error You need at least XCode Clang v10.0 to compile QEMU
1581efc6c070SThomas Huth#  endif
1582efc6c070SThomas Huth# else
15832a85a08cSDaniel P. Berrangé#  if __clang_major__ < 6 || (__clang_major__ == 6 && __clang_minor__ < 0)
15842a85a08cSDaniel P. Berrangé#   error You need at least Clang v6.0 to compile QEMU
1585efc6c070SThomas Huth#  endif
1586efc6c070SThomas Huth# endif
1587efc6c070SThomas Huth#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
15883830df5fSnia# if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
15893830df5fSnia#  error You need at least GCC v7.4.0 to compile QEMU
1590efc6c070SThomas Huth# endif
1591efc6c070SThomas Huth#else
1592efc6c070SThomas Huth# error You either need GCC or Clang to compiler QEMU
1593efc6c070SThomas Huth#endif
1594efc6c070SThomas Huthint main (void) { return 0; }
1595efc6c070SThomas HuthEOF
1596efc6c070SThomas Huthif ! compile_prog "" "" ; then
15973830df5fSnia    error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
1598efc6c070SThomas Huthfi
1599efc6c070SThomas Huth
160000849b92SRichard Henderson# Accumulate -Wfoo and -Wno-bar separately.
160100849b92SRichard Henderson# We will list all of the enable flags first, and the disable flags second.
160200849b92SRichard Henderson# Note that we do not add -Werror, because that would enable it for all
160300849b92SRichard Henderson# configure tests. If a configure test failed due to -Werror this would
160400849b92SRichard Henderson# just silently disable some features, so it's too error prone.
160500849b92SRichard Henderson
160600849b92SRichard Hendersonwarn_flags=
160700849b92SRichard Hendersonadd_to warn_flags -Wold-style-declaration
160800849b92SRichard Hendersonadd_to warn_flags -Wold-style-definition
160900849b92SRichard Hendersonadd_to warn_flags -Wtype-limits
161000849b92SRichard Hendersonadd_to warn_flags -Wformat-security
161100849b92SRichard Hendersonadd_to warn_flags -Wformat-y2k
161200849b92SRichard Hendersonadd_to warn_flags -Winit-self
161300849b92SRichard Hendersonadd_to warn_flags -Wignored-qualifiers
161400849b92SRichard Hendersonadd_to warn_flags -Wempty-body
161500849b92SRichard Hendersonadd_to warn_flags -Wnested-externs
161600849b92SRichard Hendersonadd_to warn_flags -Wendif-labels
161700849b92SRichard Hendersonadd_to warn_flags -Wexpansion-to-defined
16180a2ebce9SThomas Huthadd_to warn_flags -Wimplicit-fallthrough=2
161900849b92SRichard Henderson
162000849b92SRichard Hendersonnowarn_flags=
162100849b92SRichard Hendersonadd_to nowarn_flags -Wno-initializer-overrides
162200849b92SRichard Hendersonadd_to nowarn_flags -Wno-missing-include-dirs
162300849b92SRichard Hendersonadd_to nowarn_flags -Wno-shift-negative-value
162400849b92SRichard Hendersonadd_to nowarn_flags -Wno-string-plus-int
162500849b92SRichard Hendersonadd_to nowarn_flags -Wno-typedef-redefinition
1626aabab967SRichard Hendersonadd_to nowarn_flags -Wno-tautological-type-limit-compare
1627bac8d222SRichard Hendersonadd_to nowarn_flags -Wno-psabi
162800849b92SRichard Henderson
162900849b92SRichard Hendersongcc_flags="$warn_flags $nowarn_flags"
163093b25869SJohn Snow
163193b25869SJohn Snowcc_has_warning_flag() {
163293b25869SJohn Snow    write_c_skeleton;
163393b25869SJohn Snow
1634a1d29d6cSPeter Maydell    # Use the positive sense of the flag when testing for -Wno-wombat
1635a1d29d6cSPeter Maydell    # support (gcc will happily accept the -Wno- form of unknown
1636a1d29d6cSPeter Maydell    # warning options).
163793b25869SJohn Snow    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
163893b25869SJohn Snow    compile_prog "-Werror $optflag" ""
163993b25869SJohn Snow}
164093b25869SJohn Snow
164193b25869SJohn Snowfor flag in $gcc_flags; do
164293b25869SJohn Snow    if cc_has_warning_flag $flag ; then
16438d05095cSPaolo Bonzini        QEMU_CFLAGS="$QEMU_CFLAGS $flag"
16448d05095cSPaolo Bonzini    fi
16458d05095cSPaolo Bonzinidone
16468d05095cSPaolo Bonzini
164763678e17SSteven Noonanif test "$stack_protector" != "no"; then
1648fccd35a0SRodrigo Rebello  cat > $TMPC << EOF
1649fccd35a0SRodrigo Rebelloint main(int argc, char *argv[])
1650fccd35a0SRodrigo Rebello{
1651fccd35a0SRodrigo Rebello    char arr[64], *p = arr, *c = argv[0];
1652fccd35a0SRodrigo Rebello    while (*c) {
1653fccd35a0SRodrigo Rebello        *p++ = *c++;
1654fccd35a0SRodrigo Rebello    }
1655fccd35a0SRodrigo Rebello    return 0;
1656fccd35a0SRodrigo Rebello}
1657fccd35a0SRodrigo RebelloEOF
165863678e17SSteven Noonan  gcc_flags="-fstack-protector-strong -fstack-protector-all"
16593b463a3fSMiroslav Rezanina  sp_on=0
166063678e17SSteven Noonan  for flag in $gcc_flags; do
1661590e5dd9SPeter Maydell    # We need to check both a compile and a link, since some compiler
1662590e5dd9SPeter Maydell    # setups fail only on a .c->.o compile and some only at link time
1663086d5f75SPaolo Bonzini    if compile_object "-Werror $flag" &&
1664590e5dd9SPeter Maydell       compile_prog "-Werror $flag" ""; then
166563678e17SSteven Noonan      QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1666db5adeaaSPaolo Bonzini      QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
16673b463a3fSMiroslav Rezanina      sp_on=1
166863678e17SSteven Noonan      break
166963678e17SSteven Noonan    fi
167063678e17SSteven Noonan  done
16713b463a3fSMiroslav Rezanina  if test "$stack_protector" = yes; then
16723b463a3fSMiroslav Rezanina    if test $sp_on = 0; then
16733b463a3fSMiroslav Rezanina      error_exit "Stack protector not supported"
16743b463a3fSMiroslav Rezanina    fi
16753b463a3fSMiroslav Rezanina  fi
167637746c5eSMarc-André Lureaufi
167737746c5eSMarc-André Lureau
167820bc94a2SPaolo Bonzini# Disable -Wmissing-braces on older compilers that warn even for
167920bc94a2SPaolo Bonzini# the "universal" C zero initializer {0}.
168020bc94a2SPaolo Bonzinicat > $TMPC << EOF
168120bc94a2SPaolo Bonzinistruct {
168220bc94a2SPaolo Bonzini  int a[2];
168320bc94a2SPaolo Bonzini} x = {0};
168420bc94a2SPaolo BonziniEOF
168520bc94a2SPaolo Bonziniif compile_object "-Werror" "" ; then
168620bc94a2SPaolo Bonzini  :
168720bc94a2SPaolo Bonzinielse
168820bc94a2SPaolo Bonzini  QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
168920bc94a2SPaolo Bonzinifi
169020bc94a2SPaolo Bonzini
169121e709aaSMarc-André Lureau# Our module code doesn't support Windows
169221e709aaSMarc-André Lureauif test "$modules" = "yes" && test "$mingw32" = "yes" ; then
169321e709aaSMarc-André Lureau  error_exit "Modules are not available for Windows"
169421e709aaSMarc-André Lureaufi
169521e709aaSMarc-André Lureau
1696bd83c861SChristian Ehrhardt# module_upgrades is only reasonable if modules are enabled
1697bd83c861SChristian Ehrhardtif test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
1698bd83c861SChristian Ehrhardt  error_exit "Can't enable module-upgrades as Modules are not enabled"
1699bd83c861SChristian Ehrhardtfi
1700bd83c861SChristian Ehrhardt
17015f2453acSAlex Bennée# Static linking is not possible with plugins, modules or PIE
170240d6444eSAvi Kivityif test "$static" = "yes" ; then
1703aa0d1f44SPaolo Bonzini  if test "$modules" = "yes" ; then
1704aa0d1f44SPaolo Bonzini    error_exit "static and modules are mutually incompatible"
1705aa0d1f44SPaolo Bonzini  fi
17065f2453acSAlex Bennée  if test "$plugins" = "yes"; then
17075f2453acSAlex Bennée    error_exit "static and plugins are mutually incompatible"
1708ba4dd2aaSAlex Bennée  else
1709ba4dd2aaSAlex Bennée    plugins="no"
17105f2453acSAlex Bennée  fi
171140d6444eSAvi Kivityfi
171240d6444eSAvi Kivity
171340d6444eSAvi Kivitycat > $TMPC << EOF
171421d4a791SAvi Kivity
171521d4a791SAvi Kivity#ifdef __linux__
171621d4a791SAvi Kivity#  define THREAD __thread
171721d4a791SAvi Kivity#else
171821d4a791SAvi Kivity#  define THREAD
171921d4a791SAvi Kivity#endif
172021d4a791SAvi Kivitystatic THREAD int tls_var;
172121d4a791SAvi Kivityint main(void) { return tls_var; }
172240d6444eSAvi KivityEOF
1723b2634124SRichard Henderson
1724ffd205efSJessica Clarke# Check we support -fno-pie and -no-pie first; we will need the former for
1725ffd205efSJessica Clarke# building ROMs, and both for everything if --disable-pie is passed.
1726412aeacdSAlex Bennéeif compile_prog "-Werror -fno-pie" "-no-pie"; then
1727412aeacdSAlex Bennée  CFLAGS_NOPIE="-fno-pie"
1728ffd205efSJessica Clarke  LDFLAGS_NOPIE="-no-pie"
1729412aeacdSAlex Bennéefi
1730412aeacdSAlex Bennée
173112781462SRichard Hendersonif test "$static" = "yes"; then
1732eca7a8e6SRichard Henderson  if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
17335770e8afSPaolo Bonzini    CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
173412781462SRichard Henderson    QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
173512781462SRichard Henderson    pie="yes"
173612781462SRichard Henderson  elif test "$pie" = "yes"; then
173712781462SRichard Henderson    error_exit "-static-pie not available due to missing toolchain support"
173812781462SRichard Henderson  else
173912781462SRichard Henderson    QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
174012781462SRichard Henderson    pie="no"
174112781462SRichard Henderson  fi
174212781462SRichard Hendersonelif test "$pie" = "no"; then
17435770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="$CFLAGS_NOPIE $CONFIGURE_CFLAGS"
1744ffd205efSJessica Clarke  CONFIGURE_LDFLAGS="$LDFLAGS_NOPIE $CONFIGURE_LDFLAGS"
1745eca7a8e6SRichard Hendersonelif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
17465770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
17475770e8afSPaolo Bonzini  CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
174840d6444eSAvi Kivity  pie="yes"
17492c674109SRichard Hendersonelif test "$pie" = "yes"; then
175076ad07a4SPeter Maydell  error_exit "PIE not available due to missing toolchain support"
175140d6444eSAvi Kivityelse
175240d6444eSAvi Kivity  echo "Disabling PIE due to missing toolchain support"
175340d6444eSAvi Kivity  pie="no"
175440d6444eSAvi Kivityfi
175540d6444eSAvi Kivity
1756e6cbd751SRichard Henderson# Detect support for PT_GNU_RELRO + DT_BIND_NOW.
1757e6cbd751SRichard Henderson# The combination is known as "full relro", because .got.plt is read-only too.
1758e6cbd751SRichard Hendersonif compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1759e6cbd751SRichard Henderson  QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
1760e6cbd751SRichard Hendersonfi
1761e6cbd751SRichard Henderson
176209dada40SPaolo Bonzini##########################################
176309dada40SPaolo Bonzini# __sync_fetch_and_and requires at least -march=i486. Many toolchains
176409dada40SPaolo Bonzini# use i686 as default anyway, but for those that don't, an explicit
176509dada40SPaolo Bonzini# specification is necessary
176609dada40SPaolo Bonzini
176709dada40SPaolo Bonziniif test "$cpu" = "i386"; then
176809dada40SPaolo Bonzini  cat > $TMPC << EOF
176909dada40SPaolo Bonzinistatic int sfaa(int *ptr)
177009dada40SPaolo Bonzini{
177109dada40SPaolo Bonzini  return __sync_fetch_and_and(ptr, 0);
177209dada40SPaolo Bonzini}
177309dada40SPaolo Bonzini
177409dada40SPaolo Bonziniint main(void)
177509dada40SPaolo Bonzini{
177609dada40SPaolo Bonzini  int val = 42;
17771405b629SStefan Weil  val = __sync_val_compare_and_swap(&val, 0, 1);
177809dada40SPaolo Bonzini  sfaa(&val);
177909dada40SPaolo Bonzini  return val;
178009dada40SPaolo Bonzini}
178109dada40SPaolo BonziniEOF
178209dada40SPaolo Bonzini  if ! compile_prog "" "" ; then
178309dada40SPaolo Bonzini    QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
178409dada40SPaolo Bonzini  fi
178509dada40SPaolo Bonzinifi
178609dada40SPaolo Bonzini
178756267b62SPhilippe Mathieu-Daudéif test "$tcg" = "enabled"; then
178856267b62SPhilippe Mathieu-Daudé    git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
178956267b62SPhilippe Mathieu-Daudé    git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
179056267b62SPhilippe Mathieu-Daudéfi
179156267b62SPhilippe Mathieu-Daudé
1792afb63ebdSStefan Weilif test -z "${target_list+xxx}" ; then
1793fdb75aefSPaolo Bonzini    default_targets=yes
1794d880a3baSPaolo Bonzini    for target in $default_target_list; do
1795d880a3baSPaolo Bonzini        target_list="$target_list $target"
1796d880a3baSPaolo Bonzini    done
1797d880a3baSPaolo Bonzini    target_list="${target_list# }"
1798121afa9eSAnthony Liguorielse
1799fdb75aefSPaolo Bonzini    default_targets=no
180089138857SStefan Weil    target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1801d880a3baSPaolo Bonzini    for target in $target_list; do
180225b48338SPeter Maydell        # Check that we recognised the target name; this allows a more
180325b48338SPeter Maydell        # friendly error message than if we let it fall through.
180425b48338SPeter Maydell        case " $default_target_list " in
180525b48338SPeter Maydell            *" $target "*)
180625b48338SPeter Maydell                ;;
180725b48338SPeter Maydell            *)
180825b48338SPeter Maydell                error_exit "Unknown target name '$target'"
180925b48338SPeter Maydell                ;;
181025b48338SPeter Maydell        esac
181125b48338SPeter Maydell    done
1812d880a3baSPaolo Bonzinifi
181325b48338SPeter Maydell
1814fdb75aefSPaolo Bonzinifor target in $target_list; do
1815fdb75aefSPaolo Bonzini    # if a deprecated target is enabled we note it here
1816fdb75aefSPaolo Bonzini    if echo "$deprecated_targets_list" | grep -q "$target"; then
1817fdb75aefSPaolo Bonzini        add_to deprecated_features $target
1818fdb75aefSPaolo Bonzini    fi
1819fdb75aefSPaolo Bonzinidone
1820fdb75aefSPaolo Bonzini
1821f55fe278SPaolo Bonzini# see if system emulation was really requested
1822f55fe278SPaolo Bonzinicase " $target_list " in
1823f55fe278SPaolo Bonzini  *"-softmmu "*) softmmu=yes
1824f55fe278SPaolo Bonzini  ;;
1825f55fe278SPaolo Bonzini  *) softmmu=no
1826f55fe278SPaolo Bonzini  ;;
1827f55fe278SPaolo Bonziniesac
18285327cf48Sbellard
1829249247c9SJuan Quintelafeature_not_found() {
1830249247c9SJuan Quintela  feature=$1
183121684af0SStewart Smith  remedy=$2
1832249247c9SJuan Quintela
183376ad07a4SPeter Maydell  error_exit "User requested feature $feature" \
183421684af0SStewart Smith      "configure was not able to find it." \
183521684af0SStewart Smith      "$remedy"
1836249247c9SJuan Quintela}
1837249247c9SJuan Quintela
18387d13299dSbellard# ---
18397d13299dSbellard# big/little endian test
18407d13299dSbellardcat > $TMPC << EOF
1841659eb157SThomas Huth#include <stdio.h>
184261cc919fSMike Frysingershort big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
184361cc919fSMike Frysingershort little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
1844659eb157SThomas Huthint main(int argc, char *argv[])
1845659eb157SThomas Huth{
1846659eb157SThomas Huth    return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
18477d13299dSbellard}
18487d13299dSbellardEOF
18497d13299dSbellard
1850659eb157SThomas Huthif compile_prog ; then
1851659eb157SThomas Huth    if strings -a $TMPE | grep -q BiGeNdIaN ; then
185261cc919fSMike Frysinger        bigendian="yes"
1853659eb157SThomas Huth    elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
185461cc919fSMike Frysinger        bigendian="no"
18557d13299dSbellard    else
18567d13299dSbellard        echo big/little test failed
1857659eb157SThomas Huth        exit 1
18587d13299dSbellard    fi
18597d13299dSbellardelse
186061cc919fSMike Frysinger    echo big/little test failed
1861659eb157SThomas Huth    exit 1
18627d13299dSbellardfi
18637d13299dSbellard
1864b0a47e79SJuan Quintela##########################################
1865e10ee3f5SPhilippe Mathieu-Daudé# system tools
1866e10ee3f5SPhilippe Mathieu-Daudéif test -z "$want_tools"; then
1867e10ee3f5SPhilippe Mathieu-Daudé    if test "$softmmu" = "no"; then
1868e10ee3f5SPhilippe Mathieu-Daudé        want_tools=no
1869e10ee3f5SPhilippe Mathieu-Daudé    else
1870e10ee3f5SPhilippe Mathieu-Daudé        want_tools=yes
1871e10ee3f5SPhilippe Mathieu-Daudé    fi
1872e10ee3f5SPhilippe Mathieu-Daudéfi
1873e10ee3f5SPhilippe Mathieu-Daudé
1874299e6f19SPaolo Bonzini#########################################
1875299e6f19SPaolo Bonzini# vhost interdependencies and host support
1876299e6f19SPaolo Bonzini
1877299e6f19SPaolo Bonzini# vhost backends
1878d88618f7SStefan Hajnocziif test "$vhost_user" = "yes" && test "$linux" != "yes"; then
1879d88618f7SStefan Hajnoczi  error_exit "vhost-user is only available on Linux"
1880299e6f19SPaolo Bonzinifi
1881108a6481SCindy Lutest "$vhost_vdpa" = "" && vhost_vdpa=$linux
1882108a6481SCindy Luif test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
1883108a6481SCindy Lu  error_exit "vhost-vdpa is only available on Linux"
1884108a6481SCindy Lufi
1885299e6f19SPaolo Bonzinitest "$vhost_kernel" = "" && vhost_kernel=$linux
1886299e6f19SPaolo Bonziniif test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
1887299e6f19SPaolo Bonzini  error_exit "vhost-kernel is only available on Linux"
1888299e6f19SPaolo Bonzinifi
1889299e6f19SPaolo Bonzini
1890299e6f19SPaolo Bonzini# vhost-kernel devices
1891299e6f19SPaolo Bonzinitest "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
1892299e6f19SPaolo Bonziniif test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
1893299e6f19SPaolo Bonzini  error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
1894299e6f19SPaolo Bonzinifi
1895299e6f19SPaolo Bonzinitest "$vhost_vsock" = "" && vhost_vsock=$vhost_kernel
1896299e6f19SPaolo Bonziniif test "$vhost_vsock" = "yes" && test "$vhost_kernel" != "yes"; then
1897299e6f19SPaolo Bonzini  error_exit "--enable-vhost-vsock requires --enable-vhost-kernel"
1898299e6f19SPaolo Bonzinifi
1899299e6f19SPaolo Bonzini
1900299e6f19SPaolo Bonzini# vhost-user backends
1901299e6f19SPaolo Bonzinitest "$vhost_net_user" = "" && vhost_net_user=$vhost_user
1902299e6f19SPaolo Bonziniif test "$vhost_net_user" = "yes" && test "$vhost_user" = "no"; then
1903299e6f19SPaolo Bonzini  error_exit "--enable-vhost-net-user requires --enable-vhost-user"
1904299e6f19SPaolo Bonzinifi
1905299e6f19SPaolo Bonzinitest "$vhost_crypto" = "" && vhost_crypto=$vhost_user
1906299e6f19SPaolo Bonziniif test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
1907299e6f19SPaolo Bonzini  error_exit "--enable-vhost-crypto requires --enable-vhost-user"
1908299e6f19SPaolo Bonzinifi
190998fc1adaSDr. David Alan Gilberttest "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
191098fc1adaSDr. David Alan Gilbertif test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
191198fc1adaSDr. David Alan Gilbert  error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
191298fc1adaSDr. David Alan Gilbertfi
1913108a6481SCindy Lu#vhost-vdpa backends
1914108a6481SCindy Lutest "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa
1915108a6481SCindy Luif test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then
1916108a6481SCindy Lu  error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa"
1917108a6481SCindy Lufi
1918299e6f19SPaolo Bonzini
191940bc0ca9SLaurent Vivier# OR the vhost-kernel, vhost-vdpa and vhost-user values for simplicity
1920299e6f19SPaolo Bonziniif test "$vhost_net" = ""; then
1921299e6f19SPaolo Bonzini  test "$vhost_net_user" = "yes" && vhost_net=yes
192240bc0ca9SLaurent Vivier  test "$vhost_net_vdpa" = "yes" && vhost_net=yes
1923299e6f19SPaolo Bonzini  test "$vhost_kernel" = "yes" && vhost_net=yes
1924299e6f19SPaolo Bonzinifi
1925299e6f19SPaolo Bonzini
1926015a33bdSGonglei##########################################
1927779ab5e3SStefan Weil# pkg-config probe
1928779ab5e3SStefan Weil
1929779ab5e3SStefan Weilif ! has "$pkg_config_exe"; then
193076ad07a4SPeter Maydell  error_exit "pkg-config binary '$pkg_config_exe' not found"
1931779ab5e3SStefan Weilfi
1932779ab5e3SStefan Weil
1933779ab5e3SStefan Weil##########################################
1934e37630caSaliguori# xen probe
1935e37630caSaliguori
19361badb709SPaolo Bonziniif test "$xen" != "disabled" ; then
1937c1cdd9d5SJuergen Gross  # Check whether Xen library path is specified via --extra-ldflags to avoid
1938c1cdd9d5SJuergen Gross  # overriding this setting with pkg-config output. If not, try pkg-config
1939c1cdd9d5SJuergen Gross  # to obtain all needed flags.
1940c1cdd9d5SJuergen Gross
1941c1cdd9d5SJuergen Gross  if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \
1942c1cdd9d5SJuergen Gross     $pkg_config --exists xencontrol ; then
1943c1cdd9d5SJuergen Gross    xen_ctrl_version="$(printf '%d%02d%02d' \
1944c1cdd9d5SJuergen Gross      $($pkg_config --modversion xencontrol | sed 's/\./ /g') )"
19451badb709SPaolo Bonzini    xen=enabled
19465b6a8f43SMichael Tokarev    xen_pc="xencontrol xenstore xenforeignmemory xengnttab"
1947c1cdd9d5SJuergen Gross    xen_pc="$xen_pc xenevtchn xendevicemodel"
194858ea9a7aSAnthony PERARD    if $pkg_config --exists xentoolcore; then
194958ea9a7aSAnthony PERARD      xen_pc="$xen_pc xentoolcore"
195058ea9a7aSAnthony PERARD    fi
1951582ea95fSMarc-André Lureau    xen_cflags="$($pkg_config --cflags $xen_pc)"
1952582ea95fSMarc-André Lureau    xen_libs="$($pkg_config --libs $xen_pc)"
1953c1cdd9d5SJuergen Gross  else
1954c1cdd9d5SJuergen Gross
19555b6a8f43SMichael Tokarev    xen_libs="-lxenstore -lxenctrl"
1956d9506cabSAnthony PERARD    xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
1957d5b93ddfSAnthony PERARD
195850ced5b3SStefan Weil    # First we test whether Xen headers and libraries are available.
195950ced5b3SStefan Weil    # If no, we are done and there is no Xen support.
196050ced5b3SStefan Weil    # If yes, more tests are run to detect the Xen version.
196150ced5b3SStefan Weil
196250ced5b3SStefan Weil    # Xen (any)
196350ced5b3SStefan Weil    cat > $TMPC <<EOF
196450ced5b3SStefan Weil#include <xenctrl.h>
196550ced5b3SStefan Weilint main(void) {
196650ced5b3SStefan Weil  return 0;
196750ced5b3SStefan Weil}
196850ced5b3SStefan WeilEOF
196950ced5b3SStefan Weil    if ! compile_prog "" "$xen_libs" ; then
197050ced5b3SStefan Weil      # Xen not found
19711badb709SPaolo Bonzini      if test "$xen" = "enabled" ; then
197221684af0SStewart Smith        feature_not_found "xen" "Install xen devel"
197350ced5b3SStefan Weil      fi
19741badb709SPaolo Bonzini      xen=disabled
197550ced5b3SStefan Weil
1976d5b93ddfSAnthony PERARD    # Xen unstable
197769deef08SPeter Maydell    elif
197869deef08SPeter Maydell        cat > $TMPC <<EOF &&
19792cbf8903SRoss Lagerwall#undef XC_WANT_COMPAT_DEVICEMODEL_API
19802cbf8903SRoss Lagerwall#define __XEN_TOOLS__
19812cbf8903SRoss Lagerwall#include <xendevicemodel.h>
1982d3c49ebbSPaul Durrant#include <xenforeignmemory.h>
19832cbf8903SRoss Lagerwallint main(void) {
19842cbf8903SRoss Lagerwall  xendevicemodel_handle *xd;
1985d3c49ebbSPaul Durrant  xenforeignmemory_handle *xfmem;
19862cbf8903SRoss Lagerwall
19872cbf8903SRoss Lagerwall  xd = xendevicemodel_open(0, 0);
19882cbf8903SRoss Lagerwall  xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);
19892cbf8903SRoss Lagerwall
1990d3c49ebbSPaul Durrant  xfmem = xenforeignmemory_open(0, 0);
1991d3c49ebbSPaul Durrant  xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);
1992d3c49ebbSPaul Durrant
19932cbf8903SRoss Lagerwall  return 0;
19942cbf8903SRoss Lagerwall}
19952cbf8903SRoss LagerwallEOF
19962cbf8903SRoss Lagerwall        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
19972cbf8903SRoss Lagerwall      then
19982cbf8903SRoss Lagerwall      xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
19992cbf8903SRoss Lagerwall      xen_ctrl_version=41100
20001badb709SPaolo Bonzini      xen=enabled
20012cbf8903SRoss Lagerwall    elif
20022cbf8903SRoss Lagerwall        cat > $TMPC <<EOF &&
20035ba3d756SIgor Druzhinin#undef XC_WANT_COMPAT_MAP_FOREIGN_API
20045ba3d756SIgor Druzhinin#include <xenforeignmemory.h>
200558ea9a7aSAnthony PERARD#include <xentoolcore.h>
20065ba3d756SIgor Druzhininint main(void) {
20075ba3d756SIgor Druzhinin  xenforeignmemory_handle *xfmem;
20085ba3d756SIgor Druzhinin
20095ba3d756SIgor Druzhinin  xfmem = xenforeignmemory_open(0, 0);
20105ba3d756SIgor Druzhinin  xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
201158ea9a7aSAnthony PERARD  xentoolcore_restrict_all(0);
20125ba3d756SIgor Druzhinin
20135ba3d756SIgor Druzhinin  return 0;
20145ba3d756SIgor Druzhinin}
20155ba3d756SIgor DruzhininEOF
201658ea9a7aSAnthony PERARD        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
20175ba3d756SIgor Druzhinin      then
201858ea9a7aSAnthony PERARD      xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
20195ba3d756SIgor Druzhinin      xen_ctrl_version=41000
20201badb709SPaolo Bonzini      xen=enabled
20215ba3d756SIgor Druzhinin    elif
20225ba3d756SIgor Druzhinin        cat > $TMPC <<EOF &&
2023da8090ccSPaul Durrant#undef XC_WANT_COMPAT_DEVICEMODEL_API
2024da8090ccSPaul Durrant#define __XEN_TOOLS__
2025da8090ccSPaul Durrant#include <xendevicemodel.h>
2026da8090ccSPaul Durrantint main(void) {
2027da8090ccSPaul Durrant  xendevicemodel_handle *xd;
2028da8090ccSPaul Durrant
2029da8090ccSPaul Durrant  xd = xendevicemodel_open(0, 0);
2030da8090ccSPaul Durrant  xendevicemodel_close(xd);
2031da8090ccSPaul Durrant
2032da8090ccSPaul Durrant  return 0;
2033da8090ccSPaul Durrant}
2034da8090ccSPaul DurrantEOF
2035da8090ccSPaul Durrant        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs"
2036da8090ccSPaul Durrant      then
2037da8090ccSPaul Durrant      xen_stable_libs="-lxendevicemodel $xen_stable_libs"
2038f1167ee6SJuergen Gross      xen_ctrl_version=40900
20391badb709SPaolo Bonzini      xen=enabled
2040da8090ccSPaul Durrant    elif
2041da8090ccSPaul Durrant        cat > $TMPC <<EOF &&
20425eeb39c2SIan Campbell/*
20435eeb39c2SIan Campbell * If we have stable libs the we don't want the libxc compat
20445eeb39c2SIan Campbell * layers, regardless of what CFLAGS we may have been given.
2045b6eb9b45SPaulina Szubarczyk *
2046b6eb9b45SPaulina Szubarczyk * Also, check if xengnttab_grant_copy_segment_t is defined and
2047b6eb9b45SPaulina Szubarczyk * grant copy operation is implemented.
2048b6eb9b45SPaulina Szubarczyk */
2049b6eb9b45SPaulina Szubarczyk#undef XC_WANT_COMPAT_EVTCHN_API
2050b6eb9b45SPaulina Szubarczyk#undef XC_WANT_COMPAT_GNTTAB_API
2051b6eb9b45SPaulina Szubarczyk#undef XC_WANT_COMPAT_MAP_FOREIGN_API
2052b6eb9b45SPaulina Szubarczyk#include <xenctrl.h>
2053b6eb9b45SPaulina Szubarczyk#include <xenstore.h>
2054b6eb9b45SPaulina Szubarczyk#include <xenevtchn.h>
2055b6eb9b45SPaulina Szubarczyk#include <xengnttab.h>
2056b6eb9b45SPaulina Szubarczyk#include <xenforeignmemory.h>
2057b6eb9b45SPaulina Szubarczyk#include <stdint.h>
2058b6eb9b45SPaulina Szubarczyk#include <xen/hvm/hvm_info_table.h>
2059b6eb9b45SPaulina Szubarczyk#if !defined(HVM_MAX_VCPUS)
2060b6eb9b45SPaulina Szubarczyk# error HVM_MAX_VCPUS not defined
2061b6eb9b45SPaulina Szubarczyk#endif
2062b6eb9b45SPaulina Szubarczykint main(void) {
2063b6eb9b45SPaulina Szubarczyk  xc_interface *xc = NULL;
2064b6eb9b45SPaulina Szubarczyk  xenforeignmemory_handle *xfmem;
2065b6eb9b45SPaulina Szubarczyk  xenevtchn_handle *xe;
2066b6eb9b45SPaulina Szubarczyk  xengnttab_handle *xg;
2067b6eb9b45SPaulina Szubarczyk  xengnttab_grant_copy_segment_t* seg = NULL;
2068b6eb9b45SPaulina Szubarczyk
2069b6eb9b45SPaulina Szubarczyk  xs_daemon_open();
2070b6eb9b45SPaulina Szubarczyk
2071b6eb9b45SPaulina Szubarczyk  xc = xc_interface_open(0, 0, 0);
2072b6eb9b45SPaulina Szubarczyk  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2073b6eb9b45SPaulina Szubarczyk  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2074b6eb9b45SPaulina Szubarczyk  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2075b6eb9b45SPaulina Szubarczyk  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2076b6eb9b45SPaulina Szubarczyk
2077b6eb9b45SPaulina Szubarczyk  xfmem = xenforeignmemory_open(0, 0);
2078b6eb9b45SPaulina Szubarczyk  xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2079b6eb9b45SPaulina Szubarczyk
2080b6eb9b45SPaulina Szubarczyk  xe = xenevtchn_open(0, 0);
2081b6eb9b45SPaulina Szubarczyk  xenevtchn_fd(xe);
2082b6eb9b45SPaulina Szubarczyk
2083b6eb9b45SPaulina Szubarczyk  xg = xengnttab_open(0, 0);
2084b6eb9b45SPaulina Szubarczyk  xengnttab_grant_copy(xg, 0, seg);
2085b6eb9b45SPaulina Szubarczyk
2086b6eb9b45SPaulina Szubarczyk  return 0;
2087b6eb9b45SPaulina Szubarczyk}
2088b6eb9b45SPaulina SzubarczykEOF
2089b6eb9b45SPaulina Szubarczyk        compile_prog "" "$xen_libs $xen_stable_libs"
2090b6eb9b45SPaulina Szubarczyk      then
2091f1167ee6SJuergen Gross      xen_ctrl_version=40800
20921badb709SPaolo Bonzini      xen=enabled
2093b6eb9b45SPaulina Szubarczyk    elif
2094b6eb9b45SPaulina Szubarczyk        cat > $TMPC <<EOF &&
2095b6eb9b45SPaulina Szubarczyk/*
2096b6eb9b45SPaulina Szubarczyk * If we have stable libs the we don't want the libxc compat
2097b6eb9b45SPaulina Szubarczyk * layers, regardless of what CFLAGS we may have been given.
20985eeb39c2SIan Campbell */
20995eeb39c2SIan Campbell#undef XC_WANT_COMPAT_EVTCHN_API
21005eeb39c2SIan Campbell#undef XC_WANT_COMPAT_GNTTAB_API
21015eeb39c2SIan Campbell#undef XC_WANT_COMPAT_MAP_FOREIGN_API
21025eeb39c2SIan Campbell#include <xenctrl.h>
21035eeb39c2SIan Campbell#include <xenstore.h>
21045eeb39c2SIan Campbell#include <xenevtchn.h>
21055eeb39c2SIan Campbell#include <xengnttab.h>
21065eeb39c2SIan Campbell#include <xenforeignmemory.h>
21075eeb39c2SIan Campbell#include <stdint.h>
21085eeb39c2SIan Campbell#include <xen/hvm/hvm_info_table.h>
21095eeb39c2SIan Campbell#if !defined(HVM_MAX_VCPUS)
21105eeb39c2SIan Campbell# error HVM_MAX_VCPUS not defined
21115eeb39c2SIan Campbell#endif
21125eeb39c2SIan Campbellint main(void) {
21135eeb39c2SIan Campbell  xc_interface *xc = NULL;
21145eeb39c2SIan Campbell  xenforeignmemory_handle *xfmem;
21155eeb39c2SIan Campbell  xenevtchn_handle *xe;
21165eeb39c2SIan Campbell  xengnttab_handle *xg;
21175eeb39c2SIan Campbell
21185eeb39c2SIan Campbell  xs_daemon_open();
21195eeb39c2SIan Campbell
21205eeb39c2SIan Campbell  xc = xc_interface_open(0, 0, 0);
21215eeb39c2SIan Campbell  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
21225eeb39c2SIan Campbell  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
21235eeb39c2SIan Campbell  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
21245eeb39c2SIan Campbell  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
21255eeb39c2SIan Campbell
21265eeb39c2SIan Campbell  xfmem = xenforeignmemory_open(0, 0);
21275eeb39c2SIan Campbell  xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
21285eeb39c2SIan Campbell
21295eeb39c2SIan Campbell  xe = xenevtchn_open(0, 0);
21305eeb39c2SIan Campbell  xenevtchn_fd(xe);
21315eeb39c2SIan Campbell
21325eeb39c2SIan Campbell  xg = xengnttab_open(0, 0);
21335eeb39c2SIan Campbell  xengnttab_map_grant_ref(xg, 0, 0, 0);
21345eeb39c2SIan Campbell
21355eeb39c2SIan Campbell  return 0;
21365eeb39c2SIan Campbell}
21375eeb39c2SIan CampbellEOF
21385eeb39c2SIan Campbell        compile_prog "" "$xen_libs $xen_stable_libs"
21395eeb39c2SIan Campbell      then
2140f1167ee6SJuergen Gross      xen_ctrl_version=40701
21411badb709SPaolo Bonzini      xen=enabled
2142cdadde39SRoger Pau Monne
2143cdadde39SRoger Pau Monne    # Xen 4.6
2144cdadde39SRoger Pau Monne    elif
2145cdadde39SRoger Pau Monne        cat > $TMPC <<EOF &&
2146cdadde39SRoger Pau Monne#include <xenctrl.h>
2147e108a3c1SAnthony PERARD#include <xenstore.h>
2148d5b93ddfSAnthony PERARD#include <stdint.h>
2149d5b93ddfSAnthony PERARD#include <xen/hvm/hvm_info_table.h>
2150d5b93ddfSAnthony PERARD#if !defined(HVM_MAX_VCPUS)
2151d5b93ddfSAnthony PERARD# error HVM_MAX_VCPUS not defined
2152d5b93ddfSAnthony PERARD#endif
2153d5b93ddfSAnthony PERARDint main(void) {
2154d5b93ddfSAnthony PERARD  xc_interface *xc;
2155d5b93ddfSAnthony PERARD  xs_daemon_open();
2156d5b93ddfSAnthony PERARD  xc = xc_interface_open(0, 0, 0);
2157d5b93ddfSAnthony PERARD  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2158d5b93ddfSAnthony PERARD  xc_gnttab_open(NULL, 0);
2159b87de24eSAnthony PERARD  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
21608688e065SStefano Stabellini  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2161d8b441a3SJan Beulich  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
216220a544c7SKonrad Rzeszutek Wilk  xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
2163d8b441a3SJan Beulich  return 0;
2164d8b441a3SJan Beulich}
2165d8b441a3SJan BeulichEOF
2166d8b441a3SJan Beulich        compile_prog "" "$xen_libs"
2167d8b441a3SJan Beulich      then
2168f1167ee6SJuergen Gross      xen_ctrl_version=40600
21691badb709SPaolo Bonzini      xen=enabled
2170d8b441a3SJan Beulich
2171d8b441a3SJan Beulich    # Xen 4.5
2172d8b441a3SJan Beulich    elif
2173d8b441a3SJan Beulich        cat > $TMPC <<EOF &&
2174d8b441a3SJan Beulich#include <xenctrl.h>
2175d8b441a3SJan Beulich#include <xenstore.h>
2176d8b441a3SJan Beulich#include <stdint.h>
2177d8b441a3SJan Beulich#include <xen/hvm/hvm_info_table.h>
2178d8b441a3SJan Beulich#if !defined(HVM_MAX_VCPUS)
2179d8b441a3SJan Beulich# error HVM_MAX_VCPUS not defined
2180d8b441a3SJan Beulich#endif
2181d8b441a3SJan Beulichint main(void) {
2182d8b441a3SJan Beulich  xc_interface *xc;
2183d8b441a3SJan Beulich  xs_daemon_open();
2184d8b441a3SJan Beulich  xc = xc_interface_open(0, 0, 0);
2185d8b441a3SJan Beulich  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2186d8b441a3SJan Beulich  xc_gnttab_open(NULL, 0);
2187d8b441a3SJan Beulich  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2188d8b441a3SJan Beulich  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
21893996e85cSPaul Durrant  xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
21903996e85cSPaul Durrant  return 0;
21913996e85cSPaul Durrant}
21923996e85cSPaul DurrantEOF
21933996e85cSPaul Durrant        compile_prog "" "$xen_libs"
21943996e85cSPaul Durrant      then
2195f1167ee6SJuergen Gross      xen_ctrl_version=40500
21961badb709SPaolo Bonzini      xen=enabled
21973996e85cSPaul Durrant
21983996e85cSPaul Durrant    elif
21993996e85cSPaul Durrant        cat > $TMPC <<EOF &&
22003996e85cSPaul Durrant#include <xenctrl.h>
22013996e85cSPaul Durrant#include <xenstore.h>
22023996e85cSPaul Durrant#include <stdint.h>
22033996e85cSPaul Durrant#include <xen/hvm/hvm_info_table.h>
22043996e85cSPaul Durrant#if !defined(HVM_MAX_VCPUS)
22053996e85cSPaul Durrant# error HVM_MAX_VCPUS not defined
22063996e85cSPaul Durrant#endif
22073996e85cSPaul Durrantint main(void) {
22083996e85cSPaul Durrant  xc_interface *xc;
22093996e85cSPaul Durrant  xs_daemon_open();
22103996e85cSPaul Durrant  xc = xc_interface_open(0, 0, 0);
22113996e85cSPaul Durrant  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
22123996e85cSPaul Durrant  xc_gnttab_open(NULL, 0);
22133996e85cSPaul Durrant  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
22143996e85cSPaul Durrant  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
22158688e065SStefano Stabellini  return 0;
22168688e065SStefano Stabellini}
22178688e065SStefano StabelliniEOF
22188688e065SStefano Stabellini        compile_prog "" "$xen_libs"
221969deef08SPeter Maydell      then
2220f1167ee6SJuergen Gross      xen_ctrl_version=40200
22211badb709SPaolo Bonzini      xen=enabled
22228688e065SStefano Stabellini
2223e37630caSaliguori    else
22241badb709SPaolo Bonzini      if test "$xen" = "enabled" ; then
2225edfb07edSIan Campbell        feature_not_found "xen (unsupported version)" \
2226edfb07edSIan Campbell                          "Install a supported xen (xen 4.2 or newer)"
2227fc321b4bSJuan Quintela      fi
22281badb709SPaolo Bonzini      xen=disabled
2229e37630caSaliguori    fi
2230d5b93ddfSAnthony PERARD
22311badb709SPaolo Bonzini    if test "$xen" = enabled; then
2232f1167ee6SJuergen Gross      if test $xen_ctrl_version -ge 40701  ; then
2233582ea95fSMarc-André Lureau        xen_libs="$xen_libs $xen_stable_libs "
22345eeb39c2SIan Campbell      fi
2235d5b93ddfSAnthony PERARD    fi
2236e37630caSaliguori  fi
2237c1cdd9d5SJuergen Grossfi
2238e37630caSaliguori
2239d661d9a4SJustin Terry (VM)##########################################
22402da776dbSMichael R. Hines# RDMA needs OpenFabrics libraries
22412da776dbSMichael R. Hinesif test "$rdma" != "no" ; then
22422da776dbSMichael R. Hines  cat > $TMPC <<EOF
22432da776dbSMichael R. Hines#include <rdma/rdma_cma.h>
22442da776dbSMichael R. Hinesint main(void) { return 0; }
22452da776dbSMichael R. HinesEOF
2246ef6d4ccdSYuval Shaia  rdma_libs="-lrdmacm -libverbs -libumad"
22472da776dbSMichael R. Hines  if compile_prog "" "$rdma_libs" ; then
22482da776dbSMichael R. Hines    rdma="yes"
22492da776dbSMichael R. Hines  else
22502da776dbSMichael R. Hines    if test "$rdma" = "yes" ; then
22512da776dbSMichael R. Hines        error_exit \
2252ef6d4ccdSYuval Shaia            " OpenFabrics librdmacm/libibverbs/libibumad not present." \
22532da776dbSMichael R. Hines            " Your options:" \
2254ef6d4ccdSYuval Shaia            "  (1) Fast: Install infiniband packages (devel) from your distro." \
22552da776dbSMichael R. Hines            "  (2) Cleanest: Install libraries from www.openfabrics.org" \
22562da776dbSMichael R. Hines            "  (3) Also: Install softiwarp if you don't have RDMA hardware"
22572da776dbSMichael R. Hines    fi
22582da776dbSMichael R. Hines    rdma="no"
22592da776dbSMichael R. Hines  fi
22602da776dbSMichael R. Hinesfi
22612da776dbSMichael R. Hines
226221ab34c9SMarcel Apfelbaum##########################################
226321ab34c9SMarcel Apfelbaum# PVRDMA detection
226421ab34c9SMarcel Apfelbaum
226521ab34c9SMarcel Apfelbaumcat > $TMPC <<EOF &&
226621ab34c9SMarcel Apfelbaum#include <sys/mman.h>
226721ab34c9SMarcel Apfelbaum
226821ab34c9SMarcel Apfelbaumint
226921ab34c9SMarcel Apfelbaummain(void)
227021ab34c9SMarcel Apfelbaum{
227121ab34c9SMarcel Apfelbaum    char buf = 0;
227221ab34c9SMarcel Apfelbaum    void *addr = &buf;
227321ab34c9SMarcel Apfelbaum    addr = mremap(addr, 0, 1, MREMAP_MAYMOVE | MREMAP_FIXED);
227421ab34c9SMarcel Apfelbaum
227521ab34c9SMarcel Apfelbaum    return 0;
227621ab34c9SMarcel Apfelbaum}
227721ab34c9SMarcel ApfelbaumEOF
227821ab34c9SMarcel Apfelbaum
227921ab34c9SMarcel Apfelbaumif test "$rdma" = "yes" ; then
228021ab34c9SMarcel Apfelbaum    case "$pvrdma" in
228121ab34c9SMarcel Apfelbaum    "")
228221ab34c9SMarcel Apfelbaum        if compile_prog "" ""; then
228321ab34c9SMarcel Apfelbaum            pvrdma="yes"
228421ab34c9SMarcel Apfelbaum        else
228521ab34c9SMarcel Apfelbaum            pvrdma="no"
228621ab34c9SMarcel Apfelbaum        fi
228721ab34c9SMarcel Apfelbaum        ;;
228821ab34c9SMarcel Apfelbaum    "yes")
228921ab34c9SMarcel Apfelbaum        if ! compile_prog "" ""; then
229021ab34c9SMarcel Apfelbaum            error_exit "PVRDMA is not supported since mremap is not implemented"
229121ab34c9SMarcel Apfelbaum        fi
229221ab34c9SMarcel Apfelbaum        pvrdma="yes"
229321ab34c9SMarcel Apfelbaum        ;;
229421ab34c9SMarcel Apfelbaum    "no")
229521ab34c9SMarcel Apfelbaum        pvrdma="no"
229621ab34c9SMarcel Apfelbaum        ;;
229721ab34c9SMarcel Apfelbaum    esac
229821ab34c9SMarcel Apfelbaumelse
229921ab34c9SMarcel Apfelbaum    if test "$pvrdma" = "yes" ; then
230021ab34c9SMarcel Apfelbaum        error_exit "PVRDMA requires rdma suppport"
230121ab34c9SMarcel Apfelbaum    fi
230221ab34c9SMarcel Apfelbaum    pvrdma="no"
230321ab34c9SMarcel Apfelbaumfi
230495c6bff3SBenoît Canet
2305ee108585SYuval Shaia# Let's see if enhanced reg_mr is supported
2306ee108585SYuval Shaiaif test "$pvrdma" = "yes" ; then
2307ee108585SYuval Shaia
2308ee108585SYuval Shaiacat > $TMPC <<EOF &&
2309ee108585SYuval Shaia#include <infiniband/verbs.h>
2310ee108585SYuval Shaia
2311ee108585SYuval Shaiaint
2312ee108585SYuval Shaiamain(void)
2313ee108585SYuval Shaia{
2314ee108585SYuval Shaia    struct ibv_mr *mr;
2315ee108585SYuval Shaia    struct ibv_pd *pd = NULL;
2316ee108585SYuval Shaia    size_t length = 10;
2317ee108585SYuval Shaia    uint64_t iova = 0;
2318ee108585SYuval Shaia    int access = 0;
2319ee108585SYuval Shaia    void *addr = NULL;
2320ee108585SYuval Shaia
2321ee108585SYuval Shaia    mr = ibv_reg_mr_iova(pd, addr, length, iova, access);
2322ee108585SYuval Shaia
2323ee108585SYuval Shaia    ibv_dereg_mr(mr);
2324ee108585SYuval Shaia
2325ee108585SYuval Shaia    return 0;
2326ee108585SYuval Shaia}
2327ee108585SYuval ShaiaEOF
2328ee108585SYuval Shaia    if ! compile_prog "" "-libverbs"; then
2329ee108585SYuval Shaia        QEMU_CFLAGS="$QEMU_CFLAGS -DLEGACY_RDMA_REG_MR"
2330ee108585SYuval Shaia    fi
2331ee108585SYuval Shaiafi
2332ee108585SYuval Shaia
233395c6bff3SBenoît Canet##########################################
2334c1bb86cdSEric Blake# xfsctl() probe, used for file-posix.c
2335dce512deSChristoph Hellwigif test "$xfs" != "no" ; then
2336dce512deSChristoph Hellwig  cat > $TMPC << EOF
2337ffc41d10SStefan Weil#include <stddef.h>  /* NULL */
2338dce512deSChristoph Hellwig#include <xfs/xfs.h>
2339dce512deSChristoph Hellwigint main(void)
2340dce512deSChristoph Hellwig{
2341dce512deSChristoph Hellwig    xfsctl(NULL, 0, 0, NULL);
2342dce512deSChristoph Hellwig    return 0;
2343dce512deSChristoph Hellwig}
2344dce512deSChristoph HellwigEOF
2345dce512deSChristoph Hellwig  if compile_prog "" "" ; then
2346dce512deSChristoph Hellwig    xfs="yes"
2347dce512deSChristoph Hellwig  else
2348dce512deSChristoph Hellwig    if test "$xfs" = "yes" ; then
2349e3a6e0daSzhaolichang      feature_not_found "xfs" "Install xfsprogs/xfslibs devel"
2350dce512deSChristoph Hellwig    fi
2351dce512deSChristoph Hellwig    xfs=no
2352dce512deSChristoph Hellwig  fi
2353dce512deSChristoph Hellwigfi
2354dce512deSChristoph Hellwig
2355dce512deSChristoph Hellwig##########################################
2356ba4dd2aaSAlex Bennée# plugin linker support probe
2357ba4dd2aaSAlex Bennée
2358ba4dd2aaSAlex Bennéeif test "$plugins" != "no"; then
2359ba4dd2aaSAlex Bennée
2360ba4dd2aaSAlex Bennée    #########################################
2361ba4dd2aaSAlex Bennée    # See if --dynamic-list is supported by the linker
2362ba4dd2aaSAlex Bennée
2363ba4dd2aaSAlex Bennée    ld_dynamic_list="no"
2364ba4dd2aaSAlex Bennée    cat > $TMPTXT <<EOF
2365ba4dd2aaSAlex Bennée{
2366ba4dd2aaSAlex Bennée  foo;
2367ba4dd2aaSAlex Bennée};
2368ba4dd2aaSAlex BennéeEOF
2369ba4dd2aaSAlex Bennée
2370ba4dd2aaSAlex Bennée        cat > $TMPC <<EOF
2371ba4dd2aaSAlex Bennée#include <stdio.h>
2372ba4dd2aaSAlex Bennéevoid foo(void);
2373ba4dd2aaSAlex Bennée
2374ba4dd2aaSAlex Bennéevoid foo(void)
2375ba4dd2aaSAlex Bennée{
2376ba4dd2aaSAlex Bennée  printf("foo\n");
2377ba4dd2aaSAlex Bennée}
2378ba4dd2aaSAlex Bennée
2379ba4dd2aaSAlex Bennéeint main(void)
2380ba4dd2aaSAlex Bennée{
2381ba4dd2aaSAlex Bennée  foo();
2382ba4dd2aaSAlex Bennée  return 0;
2383ba4dd2aaSAlex Bennée}
2384ba4dd2aaSAlex BennéeEOF
2385ba4dd2aaSAlex Bennée
2386ba4dd2aaSAlex Bennée    if compile_prog "" "-Wl,--dynamic-list=$TMPTXT" ; then
2387ba4dd2aaSAlex Bennée        ld_dynamic_list="yes"
2388ba4dd2aaSAlex Bennée    fi
2389ba4dd2aaSAlex Bennée
2390ba4dd2aaSAlex Bennée    #########################################
2391ba4dd2aaSAlex Bennée    # See if -exported_symbols_list is supported by the linker
2392ba4dd2aaSAlex Bennée
2393ba4dd2aaSAlex Bennée    ld_exported_symbols_list="no"
2394ba4dd2aaSAlex Bennée    cat > $TMPTXT <<EOF
2395ba4dd2aaSAlex Bennée  _foo
2396ba4dd2aaSAlex BennéeEOF
2397ba4dd2aaSAlex Bennée
2398ba4dd2aaSAlex Bennée    if compile_prog "" "-Wl,-exported_symbols_list,$TMPTXT" ; then
2399ba4dd2aaSAlex Bennée        ld_exported_symbols_list="yes"
2400ba4dd2aaSAlex Bennée    fi
2401ba4dd2aaSAlex Bennée
2402ba4dd2aaSAlex Bennée    if test "$ld_dynamic_list" = "no" &&
2403ba4dd2aaSAlex Bennée       test "$ld_exported_symbols_list" = "no" ; then
2404ba4dd2aaSAlex Bennée        if test "$plugins" = "yes"; then
2405ba4dd2aaSAlex Bennée            error_exit \
2406ba4dd2aaSAlex Bennée                "Plugin support requires dynamic linking and specifying a set of symbols " \
2407ba4dd2aaSAlex Bennée                "that are exported to plugins. Unfortunately your linker doesn't " \
2408ba4dd2aaSAlex Bennée                "support the flag (--dynamic-list or -exported_symbols_list) used " \
2409ba4dd2aaSAlex Bennée                "for this purpose."
2410ba4dd2aaSAlex Bennée        else
2411ba4dd2aaSAlex Bennée            plugins="no"
2412ba4dd2aaSAlex Bennée        fi
2413ba4dd2aaSAlex Bennée    else
2414ba4dd2aaSAlex Bennée        plugins="yes"
2415ba4dd2aaSAlex Bennée    fi
2416ba4dd2aaSAlex Bennéefi
2417ba4dd2aaSAlex Bennée
2418ba4dd2aaSAlex Bennée##########################################
2419e18df141SAnthony Liguori# glib support probe
2420a52d28afSPaolo Bonzini
2421b4c6036fSDaniel P. Berrangéglib_req_ver=2.56
2422aa0d1f44SPaolo Bonziniglib_modules=gthread-2.0
2423aa0d1f44SPaolo Bonziniif test "$modules" = yes; then
2424a88afc64SGerd Hoffmann    glib_modules="$glib_modules gmodule-export-2.0"
2425b906acacSPaolo Bonzinielif test "$plugins" = "yes"; then
2426b906acacSPaolo Bonzini    glib_modules="$glib_modules gmodule-no-export-2.0"
242754cb65d8SEmilio G. Cotafi
2428e26110cfSFam Zheng
2429aa0d1f44SPaolo Bonzinifor i in $glib_modules; do
2430e26110cfSFam Zheng    if $pkg_config --atleast-version=$glib_req_ver $i; then
243189138857SStefan Weil        glib_cflags=$($pkg_config --cflags $i)
243289138857SStefan Weil        glib_libs=$($pkg_config --libs $i)
2433e18df141SAnthony Liguori    else
2434e26110cfSFam Zheng        error_exit "glib-$glib_req_ver $i is required to compile QEMU"
2435e26110cfSFam Zheng    fi
2436e26110cfSFam Zhengdone
2437e26110cfSFam Zheng
2438215b0c2fSPaolo Bonzini# This workaround is required due to a bug in pkg-config file for glib as it
2439215b0c2fSPaolo Bonzini# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
2440215b0c2fSPaolo Bonzini
2441215b0c2fSPaolo Bonziniif test "$static" = yes && test "$mingw32" = yes; then
2442215b0c2fSPaolo Bonzini    glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
2443215b0c2fSPaolo Bonzinifi
2444215b0c2fSPaolo Bonzini
244520cf7b8eSDenis Plotnikovif ! test "$gio" = "no"; then
244620cf7b8eSDenis Plotnikov    pass=no
2447f876b765SMarc-André Lureau    if $pkg_config --atleast-version=$glib_req_ver gio-2.0; then
2448f876b765SMarc-André Lureau        gio_cflags=$($pkg_config --cflags gio-2.0)
2449f876b765SMarc-André Lureau        gio_libs=$($pkg_config --libs gio-2.0)
245025a97a56SMarc-André Lureau        gdbus_codegen=$($pkg_config --variable=gdbus_codegen gio-2.0)
24515ecfb76cSPaolo Bonzini        if ! has "$gdbus_codegen"; then
24520dba4897SMarc-André Lureau            gdbus_codegen=
24530dba4897SMarc-André Lureau        fi
245476346b62SPeter Maydell        # Check that the libraries actually work -- Ubuntu 18.04 ships
245576346b62SPeter Maydell        # with pkg-config --static --libs data for gio-2.0 that is missing
245676346b62SPeter Maydell        # -lblkid and will give a link error.
245713ceae66SPeter Maydell        cat > $TMPC <<EOF
245813ceae66SPeter Maydell#include <gio/gio.h>
245913ceae66SPeter Maydellint main(void)
246013ceae66SPeter Maydell{
246113ceae66SPeter Maydell    g_dbus_proxy_new_sync(0, 0, 0, 0, 0, 0, 0, 0);
246213ceae66SPeter Maydell    return 0;
246313ceae66SPeter Maydell}
246413ceae66SPeter MaydellEOF
246513ceae66SPeter Maydell        if compile_prog "$gio_cflags" "$gio_libs" ; then
246620cf7b8eSDenis Plotnikov            pass=yes
246776346b62SPeter Maydell        else
246820cf7b8eSDenis Plotnikov            pass=no
2469f876b765SMarc-André Lureau        fi
2470f876b765SMarc-André Lureau
247120cf7b8eSDenis Plotnikov        if test "$pass" = "yes" &&
247220cf7b8eSDenis Plotnikov            $pkg_config --atleast-version=$glib_req_ver gio-unix-2.0; then
247325a97a56SMarc-André Lureau            gio_cflags="$gio_cflags $($pkg_config --cflags gio-unix-2.0)"
247425a97a56SMarc-André Lureau            gio_libs="$gio_libs $($pkg_config --libs gio-unix-2.0)"
247525a97a56SMarc-André Lureau        fi
247620cf7b8eSDenis Plotnikov    fi
247720cf7b8eSDenis Plotnikov
247820cf7b8eSDenis Plotnikov    if test "$pass" = "no"; then
247920cf7b8eSDenis Plotnikov        if test "$gio" = "yes"; then
248020cf7b8eSDenis Plotnikov            feature_not_found "gio" "Install libgio >= 2.0"
248120cf7b8eSDenis Plotnikov        else
248220cf7b8eSDenis Plotnikov            gio=no
248320cf7b8eSDenis Plotnikov        fi
248420cf7b8eSDenis Plotnikov    else
248520cf7b8eSDenis Plotnikov        gio=yes
248620cf7b8eSDenis Plotnikov    fi
248720cf7b8eSDenis Plotnikovfi
248825a97a56SMarc-André Lureau
2489977a82abSDaniel P. Berrange# Sanity check that the current size_t matches the
2490977a82abSDaniel P. Berrange# size that glib thinks it should be. This catches
2491977a82abSDaniel P. Berrange# problems on multi-arch where people try to build
2492977a82abSDaniel P. Berrange# 32-bit QEMU while pointing at 64-bit glib headers
2493977a82abSDaniel P. Berrangecat > $TMPC <<EOF
2494977a82abSDaniel P. Berrange#include <glib.h>
2495977a82abSDaniel P. Berrange#include <unistd.h>
2496977a82abSDaniel P. Berrange
2497977a82abSDaniel P. Berrange#define QEMU_BUILD_BUG_ON(x) \
2498977a82abSDaniel P. Berrange  typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
2499977a82abSDaniel P. Berrange
2500977a82abSDaniel P. Berrangeint main(void) {
2501977a82abSDaniel P. Berrange   QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
2502977a82abSDaniel P. Berrange   return 0;
2503977a82abSDaniel P. Berrange}
2504977a82abSDaniel P. BerrangeEOF
2505977a82abSDaniel P. Berrange
2506215b0c2fSPaolo Bonziniif ! compile_prog "$glib_cflags" "$glib_libs" ; then
2507977a82abSDaniel P. Berrange    error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
2508977a82abSDaniel P. Berrange               "You probably need to set PKG_CONFIG_LIBDIR"\
2509977a82abSDaniel P. Berrange	       "to point to the right pkg-config files for your"\
2510977a82abSDaniel P. Berrange	       "build target"
2511977a82abSDaniel P. Berrangefi
2512977a82abSDaniel P. Berrange
25139bda600bSEric Blake# Silence clang warnings triggered by glib < 2.57.2
25149bda600bSEric Blakecat > $TMPC << EOF
25159bda600bSEric Blake#include <glib.h>
25169bda600bSEric Blaketypedef struct Foo {
25179bda600bSEric Blake    int i;
25189bda600bSEric Blake} Foo;
25199bda600bSEric Blakestatic void foo_free(Foo *f)
25209bda600bSEric Blake{
25219bda600bSEric Blake    g_free(f);
25229bda600bSEric Blake}
25239bda600bSEric BlakeG_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free);
25249bda600bSEric Blakeint main(void) { return 0; }
25259bda600bSEric BlakeEOF
25269bda600bSEric Blakeif ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
25279bda600bSEric Blake    if cc_has_warning_flag "-Wno-unused-function"; then
25289bda600bSEric Blake        glib_cflags="$glib_cflags -Wno-unused-function"
25295770e8afSPaolo Bonzini        CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
25309bda600bSEric Blake    fi
25319bda600bSEric Blakefi
25329bda600bSEric Blake
2533e26110cfSFam Zheng##########################################
2534e26110cfSFam Zheng# SHA command probe for modules
2535e26110cfSFam Zhengif test "$modules" = yes; then
2536e26110cfSFam Zheng    shacmd_probe="sha1sum sha1 shasum"
2537e26110cfSFam Zheng    for c in $shacmd_probe; do
25388ccefb91SFam Zheng        if has $c; then
2539e26110cfSFam Zheng            shacmd="$c"
2540e26110cfSFam Zheng            break
2541e26110cfSFam Zheng        fi
2542e26110cfSFam Zheng    done
2543e26110cfSFam Zheng    if test "$shacmd" = ""; then
2544e26110cfSFam Zheng        error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
2545e26110cfSFam Zheng    fi
2546e18df141SAnthony Liguorifi
2547e18df141SAnthony Liguori
2548e18df141SAnthony Liguori##########################################
25497aaa6a16SPaolo Bonzini# TPM emulation is only on POSIX
25503b8acc11SPaolo Bonzini
25517aaa6a16SPaolo Bonziniif test "$tpm" = ""; then
25527aaa6a16SPaolo Bonzini  if test "$mingw32" = "yes"; then
25537aaa6a16SPaolo Bonzini    tpm=no
25543b8acc11SPaolo Bonzini  else
25557aaa6a16SPaolo Bonzini    tpm=yes
25567aaa6a16SPaolo Bonzini  fi
25577aaa6a16SPaolo Bonzinielif test "$tpm" = "yes"; then
25587aaa6a16SPaolo Bonzini  if test "$mingw32" = "yes" ; then
25597aaa6a16SPaolo Bonzini    error_exit "TPM emulation only available on POSIX systems"
25607aaa6a16SPaolo Bonzini  fi
25613b8acc11SPaolo Bonzinifi
25623b8acc11SPaolo Bonzini
25633b8acc11SPaolo Bonzini##########################################
2564f652e6afSaurel32# fdt probe
2565e169e1e1SPeter Maydell
2566fbb4121dSPaolo Bonzinicase "$fdt" in
2567fbb4121dSPaolo Bonzini  auto | enabled | internal)
2568fbb4121dSPaolo Bonzini    # Simpler to always update submodule, even if not needed.
2569aef45d51SDaniel P. Berrange    git_submodules="${git_submodules} dtc"
2570fbb4121dSPaolo Bonzini    ;;
2571fbb4121dSPaolo Bonziniesac
2572f652e6afSaurel32
257320ff075bSMichael Walle##########################################
25749d49bcf6SMarkus Armbruster# opengl probe (for sdl2, gtk)
2575b1546f32SGerd Hoffmann
2576da076ffeSGerd Hoffmannif test "$opengl" != "no" ; then
2577bc6a3565SAkihiko Odaki  epoxy=no
2578bc6a3565SAkihiko Odaki  if $pkg_config epoxy; then
2579bc6a3565SAkihiko Odaki    cat > $TMPC << EOF
2580bc6a3565SAkihiko Odaki#include <epoxy/egl.h>
2581bc6a3565SAkihiko Odakiint main(void) { return 0; }
2582bc6a3565SAkihiko OdakiEOF
2583bc6a3565SAkihiko Odaki    if compile_prog "" "" ; then
2584bc6a3565SAkihiko Odaki      epoxy=yes
2585bc6a3565SAkihiko Odaki    fi
2586bc6a3565SAkihiko Odaki  fi
2587bc6a3565SAkihiko Odaki
2588bc6a3565SAkihiko Odaki  if test "$epoxy" = "yes" ; then
2589bc6a3565SAkihiko Odaki    opengl_cflags="$($pkg_config --cflags epoxy)"
2590bc6a3565SAkihiko Odaki    opengl_libs="$($pkg_config --libs epoxy)"
2591da076ffeSGerd Hoffmann    opengl=yes
259220ff075bSMichael Walle  else
2593da076ffeSGerd Hoffmann    if test "$opengl" = "yes" ; then
2594bc6a3565SAkihiko Odaki      feature_not_found "opengl" "Please install epoxy with EGL"
259520ff075bSMichael Walle    fi
2596f676c67eSJeremy White    opengl_cflags=""
2597da076ffeSGerd Hoffmann    opengl_libs=""
2598da076ffeSGerd Hoffmann    opengl=no
259920ff075bSMichael Walle  fi
260020ff075bSMichael Wallefi
260120ff075bSMichael Walle
2602dcc38d1cSMarcelo Tosatti##########################################
2603a99d57bbSWanlong Gao# libnuma probe
2604a99d57bbSWanlong Gao
2605a99d57bbSWanlong Gaoif test "$numa" != "no" ; then
2606a99d57bbSWanlong Gao  cat > $TMPC << EOF
2607a99d57bbSWanlong Gao#include <numa.h>
2608a99d57bbSWanlong Gaoint main(void) { return numa_available(); }
2609a99d57bbSWanlong GaoEOF
2610a99d57bbSWanlong Gao
2611a99d57bbSWanlong Gao  if compile_prog "" "-lnuma" ; then
2612a99d57bbSWanlong Gao    numa=yes
2613ab318051SMarc-André Lureau    numa_libs="-lnuma"
2614a99d57bbSWanlong Gao  else
2615a99d57bbSWanlong Gao    if test "$numa" = "yes" ; then
2616a99d57bbSWanlong Gao      feature_not_found "numa" "install numactl devel"
2617a99d57bbSWanlong Gao    fi
2618a99d57bbSWanlong Gao    numa=no
2619a99d57bbSWanlong Gao  fi
2620a99d57bbSWanlong Gaofi
2621a99d57bbSWanlong Gao
2622955727d2SCortland Tölva# check for usbfs
2623955727d2SCortland Tölvahave_usbfs=no
2624955727d2SCortland Tölvaif test "$linux_user" = "yes"; then
262596566d09SThomas Petazzoni  cat > $TMPC << EOF
262696566d09SThomas Petazzoni#include <linux/usbdevice_fs.h>
262796566d09SThomas Petazzoni
262896566d09SThomas Petazzoni#ifndef USBDEVFS_GET_CAPABILITIES
262996566d09SThomas Petazzoni#error "USBDEVFS_GET_CAPABILITIES undefined"
263096566d09SThomas Petazzoni#endif
263196566d09SThomas Petazzoni
263296566d09SThomas Petazzoni#ifndef USBDEVFS_DISCONNECT_CLAIM
263396566d09SThomas Petazzoni#error "USBDEVFS_DISCONNECT_CLAIM undefined"
263496566d09SThomas Petazzoni#endif
263596566d09SThomas Petazzoni
263696566d09SThomas Petazzoniint main(void)
263796566d09SThomas Petazzoni{
263896566d09SThomas Petazzoni    return 0;
263996566d09SThomas Petazzoni}
264096566d09SThomas PetazzoniEOF
264196566d09SThomas Petazzoni  if compile_prog "" ""; then
2642955727d2SCortland Tölva    have_usbfs=yes
2643955727d2SCortland Tölva  fi
2644955727d2SCortland Tölvafi
2645751bcc39SMarc-André Lureau
2646de5071c5SBlue Swirl##########################################
2647d9840e25STomoki Sekiyama# check if we have VSS SDK headers for win
2648d9840e25STomoki Sekiyama
2649e633a5c6SEric Blakeif test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
2650e633a5c6SEric Blake        test "$vss_win32_sdk" != "no" ; then
2651d9840e25STomoki Sekiyama  case "$vss_win32_sdk" in
2652690604f6SMichael Roth    "")   vss_win32_include="-isystem $source_path" ;;
2653d9840e25STomoki Sekiyama    *\ *) # The SDK is installed in "Program Files" by default, but we cannot
2654d9840e25STomoki Sekiyama          # handle path with spaces. So we symlink the headers into ".sdk/vss".
2655690604f6SMichael Roth          vss_win32_include="-isystem $source_path/.sdk/vss"
2656d9840e25STomoki Sekiyama	  symlink "$vss_win32_sdk/inc" "$source_path/.sdk/vss/inc"
2657d9840e25STomoki Sekiyama	  ;;
2658690604f6SMichael Roth    *)    vss_win32_include="-isystem $vss_win32_sdk"
2659d9840e25STomoki Sekiyama  esac
2660d9840e25STomoki Sekiyama  cat > $TMPC << EOF
2661d9840e25STomoki Sekiyama#define __MIDL_user_allocate_free_DEFINED__
2662d9840e25STomoki Sekiyama#include <inc/win2003/vss.h>
2663d9840e25STomoki Sekiyamaint main(void) { return VSS_CTX_BACKUP; }
2664d9840e25STomoki SekiyamaEOF
2665d9840e25STomoki Sekiyama  if compile_prog "$vss_win32_include" "" ; then
2666d9840e25STomoki Sekiyama    guest_agent_with_vss="yes"
2667d9840e25STomoki Sekiyama    QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
2668315d3184SFam Zheng    libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++ -Wl,--enable-stdcall-fixup $libs_qga"
2669f33ca81fSMichael Roth    qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb"
2670d9840e25STomoki Sekiyama  else
2671d9840e25STomoki Sekiyama    if test "$vss_win32_sdk" != "" ; then
2672d9840e25STomoki Sekiyama      echo "ERROR: Please download and install Microsoft VSS SDK:"
2673d9840e25STomoki Sekiyama      echo "ERROR:   http://www.microsoft.com/en-us/download/details.aspx?id=23490"
2674d9840e25STomoki Sekiyama      echo "ERROR: On POSIX-systems, you can extract the SDK headers by:"
2675d9840e25STomoki Sekiyama      echo "ERROR:   scripts/extract-vsssdk-headers setup.exe"
2676d9840e25STomoki Sekiyama      echo "ERROR: The headers are extracted in the directory \`inc'."
2677d9840e25STomoki Sekiyama      feature_not_found "VSS support"
2678d9840e25STomoki Sekiyama    fi
2679d9840e25STomoki Sekiyama    guest_agent_with_vss="no"
2680d9840e25STomoki Sekiyama  fi
2681d9840e25STomoki Sekiyamafi
2682d9840e25STomoki Sekiyama
2683d9840e25STomoki Sekiyama##########################################
2684d9840e25STomoki Sekiyama# lookup Windows platform SDK (if not specified)
2685d9840e25STomoki Sekiyama# The SDK is needed only to build .tlb (type library) file of guest agent
2686d9840e25STomoki Sekiyama# VSS provider from the source. It is usually unnecessary because the
2687d9840e25STomoki Sekiyama# pre-compiled .tlb file is included.
2688d9840e25STomoki Sekiyama
2689e633a5c6SEric Blakeif test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
2690e633a5c6SEric Blake        test "$guest_agent_with_vss" = "yes" ; then
2691d9840e25STomoki Sekiyama  if test -z "$win_sdk"; then
2692d9840e25STomoki Sekiyama    programfiles="$PROGRAMFILES"
2693d9840e25STomoki Sekiyama    test -n "$PROGRAMW6432" && programfiles="$PROGRAMW6432"
2694d9840e25STomoki Sekiyama    if test -n "$programfiles"; then
2695d9840e25STomoki Sekiyama      win_sdk=$(ls -d "$programfiles/Microsoft SDKs/Windows/v"* | tail -1) 2>/dev/null
2696d9840e25STomoki Sekiyama    else
2697d9840e25STomoki Sekiyama      feature_not_found "Windows SDK"
2698d9840e25STomoki Sekiyama    fi
2699d9840e25STomoki Sekiyama  elif test "$win_sdk" = "no"; then
2700d9840e25STomoki Sekiyama    win_sdk=""
2701d9840e25STomoki Sekiyama  fi
2702d9840e25STomoki Sekiyamafi
2703d9840e25STomoki Sekiyama
2704d9840e25STomoki Sekiyama##########################################
270550cbebb9SMichael Roth# check if mingw environment provides a recent ntddscsi.h
2706e633a5c6SEric Blakeif test "$mingw32" = "yes" && test "$guest_agent" != "no"; then
270750cbebb9SMichael Roth  cat > $TMPC << EOF
270850cbebb9SMichael Roth#include <windows.h>
270950cbebb9SMichael Roth#include <ntddscsi.h>
271050cbebb9SMichael Rothint main(void) {
271150cbebb9SMichael Roth#if !defined(IOCTL_SCSI_GET_ADDRESS)
271250cbebb9SMichael Roth#error Missing required ioctl definitions
271350cbebb9SMichael Roth#endif
271450cbebb9SMichael Roth  SCSI_ADDRESS addr = { .Lun = 0, .TargetId = 0, .PathId = 0 };
271550cbebb9SMichael Roth  return addr.Lun;
271650cbebb9SMichael Roth}
271750cbebb9SMichael RothEOF
271850cbebb9SMichael Roth  if compile_prog "" "" ; then
271950cbebb9SMichael Roth    guest_agent_ntddscsi=yes
2720996b9cdcSMatt Hines    libs_qga="-lsetupapi -lcfgmgr32 $libs_qga"
272150cbebb9SMichael Roth  fi
272250cbebb9SMichael Rothfi
272350cbebb9SMichael Roth
272450cbebb9SMichael Roth##########################################
27258ca80760SRichard Henderson# capstone
27268ca80760SRichard Henderson
2727e219c499SRichard Hendersoncase "$capstone" in
27288b18cdbfSRichard Henderson  auto | enabled | internal)
27298b18cdbfSRichard Henderson    # Simpler to always update submodule, even if not needed.
2730e219c499SRichard Henderson    git_submodules="${git_submodules} capstone"
2731e219c499SRichard Henderson    ;;
2732e219c499SRichard Hendersonesac
27338ca80760SRichard Henderson
27348ca80760SRichard Henderson##########################################
2735519175a2SAlex Barcelo# check and set a backend for coroutine
2736d0e2fce5SAneesh Kumar K.V
27377c2acc70SPeter Maydell# We prefer ucontext, but it's not always possible. The fallback
273833c53c54SDaniel P. Berrange# is sigcontext. On Windows the only valid backend is the Windows
273933c53c54SDaniel P. Berrange# specific one.
27407c2acc70SPeter Maydell
27417c2acc70SPeter Maydellucontext_works=no
2742d0e2fce5SAneesh Kumar K.Vif test "$darwin" != "yes"; then
2743d0e2fce5SAneesh Kumar K.V  cat > $TMPC << EOF
2744d0e2fce5SAneesh Kumar K.V#include <ucontext.h>
2745cdf84806SPeter Maydell#ifdef __stub_makecontext
2746cdf84806SPeter Maydell#error Ignoring glibc stub makecontext which will always fail
2747cdf84806SPeter Maydell#endif
274875cafad7SStefan Weilint main(void) { makecontext(0, 0, 0); return 0; }
2749d0e2fce5SAneesh Kumar K.VEOF
2750d0e2fce5SAneesh Kumar K.V  if compile_prog "" "" ; then
27517c2acc70SPeter Maydell    ucontext_works=yes
2752d0e2fce5SAneesh Kumar K.V  fi
2753519175a2SAlex Barcelofi
27547c2acc70SPeter Maydell
27557c2acc70SPeter Maydellif test "$coroutine" = ""; then
27567c2acc70SPeter Maydell  if test "$mingw32" = "yes"; then
27577c2acc70SPeter Maydell    coroutine=win32
27587c2acc70SPeter Maydell  elif test "$ucontext_works" = "yes"; then
27597c2acc70SPeter Maydell    coroutine=ucontext
2760519175a2SAlex Barcelo  else
27617c2acc70SPeter Maydell    coroutine=sigaltstack
27627c2acc70SPeter Maydell  fi
27637c2acc70SPeter Maydellelse
27647c2acc70SPeter Maydell  case $coroutine in
27657c2acc70SPeter Maydell  windows)
27667c2acc70SPeter Maydell    if test "$mingw32" != "yes"; then
27677c2acc70SPeter Maydell      error_exit "'windows' coroutine backend only valid for Windows"
27687c2acc70SPeter Maydell    fi
27697c2acc70SPeter Maydell    # Unfortunately the user visible backend name doesn't match the
27707c2acc70SPeter Maydell    # coroutine-*.c filename for this case, so we have to adjust it here.
27717c2acc70SPeter Maydell    coroutine=win32
27727c2acc70SPeter Maydell    ;;
27737c2acc70SPeter Maydell  ucontext)
27747c2acc70SPeter Maydell    if test "$ucontext_works" != "yes"; then
27757c2acc70SPeter Maydell      feature_not_found "ucontext"
27767c2acc70SPeter Maydell    fi
27777c2acc70SPeter Maydell    ;;
277833c53c54SDaniel P. Berrange  sigaltstack)
27797c2acc70SPeter Maydell    if test "$mingw32" = "yes"; then
27807c2acc70SPeter Maydell      error_exit "only the 'windows' coroutine backend is valid for Windows"
27817c2acc70SPeter Maydell    fi
27827c2acc70SPeter Maydell    ;;
27837c2acc70SPeter Maydell  *)
278476ad07a4SPeter Maydell    error_exit "unknown coroutine backend $coroutine"
27857c2acc70SPeter Maydell    ;;
27867c2acc70SPeter Maydell  esac
2787d0e2fce5SAneesh Kumar K.Vfi
2788d0e2fce5SAneesh Kumar K.V
278970c60c08SStefan Hajnocziif test "$coroutine_pool" = ""; then
279070c60c08SStefan Hajnoczi  coroutine_pool=yes
279170c60c08SStefan Hajnoczifi
279270c60c08SStefan Hajnoczi
27937d992e4dSPeter Lievenif test "$debug_stack_usage" = "yes"; then
27947d992e4dSPeter Lieven  if test "$coroutine_pool" = "yes"; then
27957d992e4dSPeter Lieven    echo "WARN: disabling coroutine pool for stack usage debugging"
27967d992e4dSPeter Lieven    coroutine_pool=no
27977d992e4dSPeter Lieven  fi
27987d992e4dSPeter Lievenfi
27997d992e4dSPeter Lieven
28001e4f6065SDaniele Buono##################################################
28011e4f6065SDaniele Buono# SafeStack
28021e4f6065SDaniele Buono
28031e4f6065SDaniele Buono
28041e4f6065SDaniele Buonoif test "$safe_stack" = "yes"; then
28051e4f6065SDaniele Buonocat > $TMPC << EOF
28061e4f6065SDaniele Buonoint main(int argc, char *argv[])
28071e4f6065SDaniele Buono{
28081e4f6065SDaniele Buono#if ! __has_feature(safe_stack)
28091e4f6065SDaniele Buono#error SafeStack Disabled
28101e4f6065SDaniele Buono#endif
28111e4f6065SDaniele Buono    return 0;
28121e4f6065SDaniele Buono}
28131e4f6065SDaniele BuonoEOF
28141e4f6065SDaniele Buono  flag="-fsanitize=safe-stack"
28151e4f6065SDaniele Buono  # Check that safe-stack is supported and enabled.
28161e4f6065SDaniele Buono  if compile_prog "-Werror $flag" "$flag"; then
28171e4f6065SDaniele Buono    # Flag needed both at compilation and at linking
28181e4f6065SDaniele Buono    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
28191e4f6065SDaniele Buono    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
28201e4f6065SDaniele Buono  else
28211e4f6065SDaniele Buono    error_exit "SafeStack not supported by your compiler"
28221e4f6065SDaniele Buono  fi
28231e4f6065SDaniele Buono  if test "$coroutine" != "ucontext"; then
28241e4f6065SDaniele Buono    error_exit "SafeStack is only supported by the coroutine backend ucontext"
28251e4f6065SDaniele Buono  fi
28261e4f6065SDaniele Buonoelse
28271e4f6065SDaniele Buonocat > $TMPC << EOF
28281e4f6065SDaniele Buonoint main(int argc, char *argv[])
28291e4f6065SDaniele Buono{
28301e4f6065SDaniele Buono#if defined(__has_feature)
28311e4f6065SDaniele Buono#if __has_feature(safe_stack)
28321e4f6065SDaniele Buono#error SafeStack Enabled
28331e4f6065SDaniele Buono#endif
28341e4f6065SDaniele Buono#endif
28351e4f6065SDaniele Buono    return 0;
28361e4f6065SDaniele Buono}
28371e4f6065SDaniele BuonoEOF
28381e4f6065SDaniele Buonoif test "$safe_stack" = "no"; then
28391e4f6065SDaniele Buono  # Make sure that safe-stack is disabled
28401e4f6065SDaniele Buono  if ! compile_prog "-Werror" ""; then
28411e4f6065SDaniele Buono    # SafeStack was already enabled, try to explicitly remove the feature
28421e4f6065SDaniele Buono    flag="-fno-sanitize=safe-stack"
28431e4f6065SDaniele Buono    if ! compile_prog "-Werror $flag" "$flag"; then
28441e4f6065SDaniele Buono      error_exit "Configure cannot disable SafeStack"
28451e4f6065SDaniele Buono    fi
28461e4f6065SDaniele Buono    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
28471e4f6065SDaniele Buono    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
28481e4f6065SDaniele Buono  fi
28491e4f6065SDaniele Buonoelse # "$safe_stack" = ""
28501e4f6065SDaniele Buono  # Set safe_stack to yes or no based on pre-existing flags
28511e4f6065SDaniele Buono  if compile_prog "-Werror" ""; then
28521e4f6065SDaniele Buono    safe_stack="no"
28531e4f6065SDaniele Buono  else
28541e4f6065SDaniele Buono    safe_stack="yes"
28551e4f6065SDaniele Buono    if test "$coroutine" != "ucontext"; then
28561e4f6065SDaniele Buono      error_exit "SafeStack is only supported by the coroutine backend ucontext"
28571e4f6065SDaniele Buono    fi
28581e4f6065SDaniele Buono  fi
28591e4f6065SDaniele Buonofi
28601e4f6065SDaniele Buonofi
28617d992e4dSPeter Lieven
286276a347e1SRichard Henderson########################################
286376a347e1SRichard Henderson# check if cpuid.h is usable.
286476a347e1SRichard Henderson
286576a347e1SRichard Hendersoncat > $TMPC << EOF
286676a347e1SRichard Henderson#include <cpuid.h>
286776a347e1SRichard Hendersonint main(void) {
2868774d566cSPeter Maydell    unsigned a, b, c, d;
2869774d566cSPeter Maydell    int max = __get_cpuid_max(0, 0);
2870774d566cSPeter Maydell
2871774d566cSPeter Maydell    if (max >= 1) {
2872774d566cSPeter Maydell        __cpuid(1, a, b, c, d);
2873774d566cSPeter Maydell    }
2874774d566cSPeter Maydell
2875774d566cSPeter Maydell    if (max >= 7) {
2876774d566cSPeter Maydell        __cpuid_count(7, 0, a, b, c, d);
2877774d566cSPeter Maydell    }
2878774d566cSPeter Maydell
287976a347e1SRichard Henderson    return 0;
288076a347e1SRichard Henderson}
288176a347e1SRichard HendersonEOF
288276a347e1SRichard Hendersonif compile_prog "" "" ; then
288376a347e1SRichard Henderson    cpuid_h=yes
288476a347e1SRichard Hendersonfi
288576a347e1SRichard Henderson
28865dd89908SRichard Henderson##########################################
28875dd89908SRichard Henderson# avx2 optimization requirement check
28885dd89908SRichard Henderson#
28895dd89908SRichard Henderson# There is no point enabling this if cpuid.h is not usable,
28905dd89908SRichard Henderson# since we won't be able to select the new routines.
28915dd89908SRichard Henderson
2892e633a5c6SEric Blakeif test "$cpuid_h" = "yes" && test "$avx2_opt" != "no"; then
28935dd89908SRichard Henderson  cat > $TMPC << EOF
28945dd89908SRichard Henderson#pragma GCC push_options
28955dd89908SRichard Henderson#pragma GCC target("avx2")
28965dd89908SRichard Henderson#include <cpuid.h>
28975dd89908SRichard Henderson#include <immintrin.h>
28985dd89908SRichard Hendersonstatic int bar(void *a) {
28995dd89908SRichard Henderson    __m256i x = *(__m256i *)a;
29005dd89908SRichard Henderson    return _mm256_testz_si256(x, x);
29015dd89908SRichard Henderson}
29025dd89908SRichard Hendersonint main(int argc, char *argv[]) { return bar(argv[0]); }
29035dd89908SRichard HendersonEOF
29045b945f23SRichard Henderson  if compile_object "-Werror" ; then
29055dd89908SRichard Henderson    avx2_opt="yes"
290686583a07SLiam Merwick  else
290786583a07SLiam Merwick    avx2_opt="no"
29085dd89908SRichard Henderson  fi
29095dd89908SRichard Hendersonfi
29105dd89908SRichard Henderson
29116b8cd447SRobert Hoo##########################################
29126b8cd447SRobert Hoo# avx512f optimization requirement check
29136b8cd447SRobert Hoo#
29146b8cd447SRobert Hoo# There is no point enabling this if cpuid.h is not usable,
29156b8cd447SRobert Hoo# since we won't be able to select the new routines.
29166b8cd447SRobert Hoo# by default, it is turned off.
29176b8cd447SRobert Hoo# if user explicitly want to enable it, check environment
29186b8cd447SRobert Hoo
29196b8cd447SRobert Hooif test "$cpuid_h" = "yes" && test "$avx512f_opt" = "yes"; then
29206b8cd447SRobert Hoo  cat > $TMPC << EOF
29216b8cd447SRobert Hoo#pragma GCC push_options
29226b8cd447SRobert Hoo#pragma GCC target("avx512f")
29236b8cd447SRobert Hoo#include <cpuid.h>
29246b8cd447SRobert Hoo#include <immintrin.h>
29256b8cd447SRobert Hoostatic int bar(void *a) {
29266b8cd447SRobert Hoo    __m512i x = *(__m512i *)a;
29276b8cd447SRobert Hoo    return _mm512_test_epi64_mask(x, x);
29286b8cd447SRobert Hoo}
29296b8cd447SRobert Hooint main(int argc, char *argv[])
29306b8cd447SRobert Hoo{
29316b8cd447SRobert Hoo	return bar(argv[0]);
29326b8cd447SRobert Hoo}
29336b8cd447SRobert HooEOF
29345b945f23SRichard Henderson  if ! compile_object "-Werror" ; then
29356b8cd447SRobert Hoo    avx512f_opt="no"
29366b8cd447SRobert Hoo  fi
29376b8cd447SRobert Hooelse
29386b8cd447SRobert Hoo  avx512f_opt="no"
29396b8cd447SRobert Hoofi
29406b8cd447SRobert Hoo
2941f540166bSRichard Henderson########################################
2942f540166bSRichard Henderson# check if __[u]int128_t is usable.
2943f540166bSRichard Henderson
2944f540166bSRichard Hendersonint128=no
2945f540166bSRichard Hendersoncat > $TMPC << EOF
2946f540166bSRichard Henderson__int128_t a;
2947f540166bSRichard Henderson__uint128_t b;
2948f540166bSRichard Hendersonint main (void) {
2949f540166bSRichard Henderson  a = a + b;
2950f540166bSRichard Henderson  b = a * b;
2951464e3671SPeter Maydell  a = a * a;
2952f540166bSRichard Henderson  return 0;
2953f540166bSRichard Henderson}
2954f540166bSRichard HendersonEOF
2955f540166bSRichard Hendersonif compile_prog "" "" ; then
2956f540166bSRichard Henderson    int128=yes
2957f540166bSRichard Hendersonfi
295876a347e1SRichard Henderson
29597ebee43eSRichard Henderson#########################################
29607ebee43eSRichard Henderson# See if 128-bit atomic operations are supported.
29617ebee43eSRichard Henderson
29627ebee43eSRichard Hendersonatomic128=no
29637ebee43eSRichard Hendersonif test "$int128" = "yes"; then
29647ebee43eSRichard Henderson  cat > $TMPC << EOF
29657ebee43eSRichard Hendersonint main(void)
29667ebee43eSRichard Henderson{
29677ebee43eSRichard Henderson  unsigned __int128 x = 0, y = 0;
2968bceac547SThomas Huth  y = __atomic_load(&x, 0);
2969bceac547SThomas Huth  __atomic_store(&x, y, 0);
2970bceac547SThomas Huth  __atomic_compare_exchange(&x, &y, x, 0, 0, 0);
29717ebee43eSRichard Henderson  return 0;
29727ebee43eSRichard Henderson}
29737ebee43eSRichard HendersonEOF
29747ebee43eSRichard Henderson  if compile_prog "" "" ; then
29757ebee43eSRichard Henderson    atomic128=yes
29767ebee43eSRichard Henderson  fi
29777ebee43eSRichard Hendersonfi
29787ebee43eSRichard Henderson
2979e6cd4bb5SRichard Hendersoncmpxchg128=no
2980e633a5c6SEric Blakeif test "$int128" = yes && test "$atomic128" = no; then
2981e6cd4bb5SRichard Henderson  cat > $TMPC << EOF
2982e6cd4bb5SRichard Hendersonint main(void)
2983e6cd4bb5SRichard Henderson{
2984e6cd4bb5SRichard Henderson  unsigned __int128 x = 0, y = 0;
2985e6cd4bb5SRichard Henderson  __sync_val_compare_and_swap_16(&x, y, x);
2986e6cd4bb5SRichard Henderson  return 0;
2987e6cd4bb5SRichard Henderson}
2988e6cd4bb5SRichard HendersonEOF
2989e6cd4bb5SRichard Henderson  if compile_prog "" "" ; then
2990e6cd4bb5SRichard Henderson    cmpxchg128=yes
2991e6cd4bb5SRichard Henderson  fi
2992e6cd4bb5SRichard Hendersonfi
2993e6cd4bb5SRichard Henderson
2994fd0e6053SJohn Snow########################################
2995fd0e6053SJohn Snow# check if ccache is interfering with
2996fd0e6053SJohn Snow# semantic analysis of macros
2997fd0e6053SJohn Snow
29985e4dfd3dSJohn Snowunset CCACHE_CPP2
2999fd0e6053SJohn Snowccache_cpp2=no
3000fd0e6053SJohn Snowcat > $TMPC << EOF
3001fd0e6053SJohn Snowstatic const int Z = 1;
3002fd0e6053SJohn Snow#define fn() ({ Z; })
3003fd0e6053SJohn Snow#define TAUT(X) ((X) == Z)
3004fd0e6053SJohn Snow#define PAREN(X, Y) (X == Y)
3005fd0e6053SJohn Snow#define ID(X) (X)
3006fd0e6053SJohn Snowint main(int argc, char *argv[])
3007fd0e6053SJohn Snow{
3008fd0e6053SJohn Snow    int x = 0, y = 0;
3009fd0e6053SJohn Snow    x = ID(x);
3010fd0e6053SJohn Snow    x = fn();
3011fd0e6053SJohn Snow    fn();
3012fd0e6053SJohn Snow    if (PAREN(x, y)) return 0;
3013fd0e6053SJohn Snow    if (TAUT(Z)) return 0;
3014fd0e6053SJohn Snow    return 0;
3015fd0e6053SJohn Snow}
3016fd0e6053SJohn SnowEOF
3017fd0e6053SJohn Snow
3018fd0e6053SJohn Snowif ! compile_object "-Werror"; then
3019fd0e6053SJohn Snow    ccache_cpp2=yes
3020fd0e6053SJohn Snowfi
3021fd0e6053SJohn Snow
3022b553a042SJohn Snow#################################################
3023b553a042SJohn Snow# clang does not support glibc + FORTIFY_SOURCE.
3024b553a042SJohn Snow
3025b553a042SJohn Snowif test "$fortify_source" != "no"; then
3026b553a042SJohn Snow  if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
3027b553a042SJohn Snow    fortify_source="no";
3028e189091fSPeter Maydell  elif test -n "$cxx" && has $cxx &&
3029cfcc7c14SJohn Snow       echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
3030b553a042SJohn Snow    fortify_source="no";
3031b553a042SJohn Snow  else
3032b553a042SJohn Snow    fortify_source="yes"
3033b553a042SJohn Snow  fi
3034b553a042SJohn Snowfi
3035b553a042SJohn Snow
3036d2042378SAneesh Kumar K.V##########################################
3037a40161cbSPaolo Bonzini# check for usable membarrier system call
3038a40161cbSPaolo Bonziniif test "$membarrier" = "yes"; then
3039a40161cbSPaolo Bonzini    have_membarrier=no
3040a40161cbSPaolo Bonzini    if test "$mingw32" = "yes" ; then
3041a40161cbSPaolo Bonzini        have_membarrier=yes
3042a40161cbSPaolo Bonzini    elif test "$linux" = "yes" ; then
3043a40161cbSPaolo Bonzini        cat > $TMPC << EOF
3044a40161cbSPaolo Bonzini    #include <linux/membarrier.h>
3045a40161cbSPaolo Bonzini    #include <sys/syscall.h>
3046a40161cbSPaolo Bonzini    #include <unistd.h>
3047a40161cbSPaolo Bonzini    #include <stdlib.h>
3048a40161cbSPaolo Bonzini    int main(void) {
3049a40161cbSPaolo Bonzini        syscall(__NR_membarrier, MEMBARRIER_CMD_QUERY, 0);
3050a40161cbSPaolo Bonzini        syscall(__NR_membarrier, MEMBARRIER_CMD_SHARED, 0);
3051a40161cbSPaolo Bonzini	exit(0);
3052a40161cbSPaolo Bonzini    }
3053a40161cbSPaolo BonziniEOF
3054a40161cbSPaolo Bonzini        if compile_prog "" "" ; then
3055a40161cbSPaolo Bonzini            have_membarrier=yes
3056a40161cbSPaolo Bonzini        fi
3057a40161cbSPaolo Bonzini    fi
3058a40161cbSPaolo Bonzini    if test "$have_membarrier" = "no"; then
3059a40161cbSPaolo Bonzini      feature_not_found "membarrier" "membarrier system call not available"
3060a40161cbSPaolo Bonzini    fi
3061a40161cbSPaolo Bonzinielse
3062a40161cbSPaolo Bonzini    # Do not enable it by default even for Mingw32, because it doesn't
3063a40161cbSPaolo Bonzini    # work on Wine.
3064a40161cbSPaolo Bonzini    membarrier=no
3065a40161cbSPaolo Bonzinifi
3066a40161cbSPaolo Bonzini
3067a40161cbSPaolo Bonzini##########################################
3068f0d92b56SLongpeng(Mike)# check for usable AF_ALG environment
30694f67366eSThomas Huthhave_afalg=no
3070f0d92b56SLongpeng(Mike)cat > $TMPC << EOF
3071f0d92b56SLongpeng(Mike)#include <errno.h>
3072f0d92b56SLongpeng(Mike)#include <sys/types.h>
3073f0d92b56SLongpeng(Mike)#include <sys/socket.h>
3074f0d92b56SLongpeng(Mike)#include <linux/if_alg.h>
3075f0d92b56SLongpeng(Mike)int main(void) {
3076f0d92b56SLongpeng(Mike)    int sock;
3077f0d92b56SLongpeng(Mike)    sock = socket(AF_ALG, SOCK_SEQPACKET, 0);
3078f0d92b56SLongpeng(Mike)    return sock;
3079f0d92b56SLongpeng(Mike)}
3080f0d92b56SLongpeng(Mike)EOF
3081f0d92b56SLongpeng(Mike)if compile_prog "" "" ; then
3082f0d92b56SLongpeng(Mike)    have_afalg=yes
3083f0d92b56SLongpeng(Mike)fi
3084f0d92b56SLongpeng(Mike)if test "$crypto_afalg" = "yes"
3085f0d92b56SLongpeng(Mike)then
3086f0d92b56SLongpeng(Mike)    if test "$have_afalg" != "yes"
3087f0d92b56SLongpeng(Mike)    then
3088f0d92b56SLongpeng(Mike)	error_exit "AF_ALG requested but could not be detected"
3089f0d92b56SLongpeng(Mike)    fi
3090f0d92b56SLongpeng(Mike)fi
3091f0d92b56SLongpeng(Mike)
3092f0d92b56SLongpeng(Mike)
3093db1ed1abSRichard Henderson##########################################
3094247724cbSMarc-André Lureau# checks for sanitizers
3095247724cbSMarc-André Lureau
3096247724cbSMarc-André Lureauhave_asan=no
3097247724cbSMarc-André Lureauhave_ubsan=no
3098d83414e1SMarc-André Lureauhave_asan_iface_h=no
3099d83414e1SMarc-André Lureauhave_asan_iface_fiber=no
3100247724cbSMarc-André Lureau
3101247724cbSMarc-André Lureauif test "$sanitizers" = "yes" ; then
3102b9f44da2SMarc-André Lureau  write_c_skeleton
3103247724cbSMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
3104247724cbSMarc-André Lureau      have_asan=yes
3105247724cbSMarc-André Lureau  fi
3106b9f44da2SMarc-André Lureau
3107b9f44da2SMarc-André Lureau  # we could use a simple skeleton for flags checks, but this also
3108b9f44da2SMarc-André Lureau  # detect the static linking issue of ubsan, see also:
3109b9f44da2SMarc-André Lureau  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
3110b9f44da2SMarc-André Lureau  cat > $TMPC << EOF
3111b9f44da2SMarc-André Lureau#include <stdlib.h>
3112b9f44da2SMarc-André Lureauint main(void) {
3113b9f44da2SMarc-André Lureau    void *tmp = malloc(10);
3114f2dfe54cSLeonid Bloch    if (tmp != NULL) {
3115b9f44da2SMarc-André Lureau        return *(int *)(tmp + 2);
3116b9f44da2SMarc-André Lureau    }
3117d1abf3fcSOlaf Hering    return 1;
3118f2dfe54cSLeonid Bloch}
3119b9f44da2SMarc-André LureauEOF
3120247724cbSMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
3121247724cbSMarc-André Lureau      have_ubsan=yes
3122247724cbSMarc-André Lureau  fi
3123d83414e1SMarc-André Lureau
3124d83414e1SMarc-André Lureau  if check_include "sanitizer/asan_interface.h" ; then
3125d83414e1SMarc-André Lureau      have_asan_iface_h=yes
3126d83414e1SMarc-André Lureau  fi
3127d83414e1SMarc-André Lureau
3128d83414e1SMarc-André Lureau  cat > $TMPC << EOF
3129d83414e1SMarc-André Lureau#include <sanitizer/asan_interface.h>
3130d83414e1SMarc-André Lureauint main(void) {
3131d83414e1SMarc-André Lureau  __sanitizer_start_switch_fiber(0, 0, 0);
3132d83414e1SMarc-André Lureau  return 0;
3133d83414e1SMarc-André Lureau}
3134d83414e1SMarc-André LureauEOF
3135d83414e1SMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
3136d83414e1SMarc-André Lureau      have_asan_iface_fiber=yes
3137d83414e1SMarc-André Lureau  fi
3138247724cbSMarc-André Lureaufi
3139247724cbSMarc-André Lureau
31400aebab04SLingfeng Yang# Thread sanitizer is, for now, much noisier than the other sanitizers;
31410aebab04SLingfeng Yang# keep it separate until that is not the case.
31420aebab04SLingfeng Yangif test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
31430aebab04SLingfeng Yang  error_exit "TSAN is not supported with other sanitiziers."
31440aebab04SLingfeng Yangfi
31450aebab04SLingfeng Yanghave_tsan=no
31460aebab04SLingfeng Yanghave_tsan_iface_fiber=no
31470aebab04SLingfeng Yangif test "$tsan" = "yes" ; then
31480aebab04SLingfeng Yang  write_c_skeleton
31490aebab04SLingfeng Yang  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
31500aebab04SLingfeng Yang      have_tsan=yes
31510aebab04SLingfeng Yang  fi
31520aebab04SLingfeng Yang  cat > $TMPC << EOF
31530aebab04SLingfeng Yang#include <sanitizer/tsan_interface.h>
31540aebab04SLingfeng Yangint main(void) {
31550aebab04SLingfeng Yang  __tsan_create_fiber(0);
31560aebab04SLingfeng Yang  return 0;
31570aebab04SLingfeng Yang}
31580aebab04SLingfeng YangEOF
31590aebab04SLingfeng Yang  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
31600aebab04SLingfeng Yang      have_tsan_iface_fiber=yes
31610aebab04SLingfeng Yang  fi
31620aebab04SLingfeng Yangfi
31630aebab04SLingfeng Yang
3164adc28027SAlexander Bulekov##########################################
3165675b9b53SMarc-André Lureau# check for slirp
3166675b9b53SMarc-André Lureau
3167675b9b53SMarc-André Lureaucase "$slirp" in
31684d34a86bSPaolo Bonzini  auto | enabled | internal)
31694d34a86bSPaolo Bonzini    # Simpler to always update submodule, even if not needed.
31707c57bdd8SMarc-André Lureau    git_submodules="${git_submodules} slirp"
3171675b9b53SMarc-André Lureau    ;;
3172675b9b53SMarc-André Lureauesac
3173675b9b53SMarc-André Lureau
3174b8e0c493SJoelle van Dyne# Check for slirp smbd dupport
3175b8e0c493SJoelle van Dyne: ${smbd=${SMBD-/usr/sbin/smbd}}
3176b8e0c493SJoelle van Dyneif test "$slirp_smbd" != "no" ; then
3177b8e0c493SJoelle van Dyne  if test "$mingw32" = "yes" ; then
3178b8e0c493SJoelle van Dyne    if test "$slirp_smbd" = "yes" ; then
3179b8e0c493SJoelle van Dyne      error_exit "Host smbd not supported on this platform."
3180b8e0c493SJoelle van Dyne    fi
3181b8e0c493SJoelle van Dyne    slirp_smbd=no
3182b8e0c493SJoelle van Dyne  else
3183b8e0c493SJoelle van Dyne    slirp_smbd=yes
3184b8e0c493SJoelle van Dyne  fi
3185b8e0c493SJoelle van Dynefi
3186b8e0c493SJoelle van Dyne
318754e7aac0SAlexey Krasikov##########################################
318854e7aac0SAlexey Krasikov# check for usable __NR_keyctl syscall
318954e7aac0SAlexey Krasikov
319054e7aac0SAlexey Krasikovif test "$linux" = "yes" ; then
319154e7aac0SAlexey Krasikov
319254e7aac0SAlexey Krasikov    have_keyring=no
319354e7aac0SAlexey Krasikov    cat > $TMPC << EOF
319454e7aac0SAlexey Krasikov#include <errno.h>
319554e7aac0SAlexey Krasikov#include <asm/unistd.h>
319654e7aac0SAlexey Krasikov#include <linux/keyctl.h>
319754e7aac0SAlexey Krasikov#include <unistd.h>
319854e7aac0SAlexey Krasikovint main(void) {
319954e7aac0SAlexey Krasikov    return syscall(__NR_keyctl, KEYCTL_READ, 0, NULL, NULL, 0);
320054e7aac0SAlexey Krasikov}
320154e7aac0SAlexey KrasikovEOF
320254e7aac0SAlexey Krasikov    if compile_prog "" "" ; then
320354e7aac0SAlexey Krasikov        have_keyring=yes
320454e7aac0SAlexey Krasikov    fi
320554e7aac0SAlexey Krasikovfi
320654e7aac0SAlexey Krasikovif test "$secret_keyring" != "no"
320754e7aac0SAlexey Krasikovthen
3208b418d265SDavid Edmondson    if test "$have_keyring" = "yes"
320954e7aac0SAlexey Krasikov    then
321054e7aac0SAlexey Krasikov	secret_keyring=yes
321154e7aac0SAlexey Krasikov    else
321254e7aac0SAlexey Krasikov	if test "$secret_keyring" = "yes"
321354e7aac0SAlexey Krasikov	then
321454e7aac0SAlexey Krasikov	    error_exit "syscall __NR_keyctl requested, \
321554e7aac0SAlexey Krasikovbut not implemented on your system"
321654e7aac0SAlexey Krasikov	else
321754e7aac0SAlexey Krasikov	    secret_keyring=no
321854e7aac0SAlexey Krasikov	fi
321954e7aac0SAlexey Krasikov    fi
322054e7aac0SAlexey Krasikovfi
322154e7aac0SAlexey Krasikov
322292500362SAlexey Krasikov##########################################
3223e86ecd4bSJuan Quintela# End of CC checks
3224e86ecd4bSJuan Quintela# After here, no more $cc or $ld runs
3225e86ecd4bSJuan Quintela
3226d83414e1SMarc-André Lureauwrite_c_skeleton
3227d83414e1SMarc-André Lureau
32281d728c39SBlue Swirlif test "$gcov" = "yes" ; then
3229bf0e56a3SMarc-André Lureau  :
3230b553a042SJohn Snowelif test "$fortify_source" = "yes" ; then
3231086d5f75SPaolo Bonzini  QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
3232086d5f75SPaolo Bonzini  debug=no
3233086d5f75SPaolo Bonzinifi
3234086d5f75SPaolo Bonzini
3235086d5f75SPaolo Bonzinicase "$ARCH" in
3236086d5f75SPaolo Bonzinialpha)
3237086d5f75SPaolo Bonzini  # Ensure there's only a single GP
3238086d5f75SPaolo Bonzini  QEMU_CFLAGS="-msmall-data $QEMU_CFLAGS"
3239086d5f75SPaolo Bonzini;;
3240086d5f75SPaolo Bonziniesac
3241086d5f75SPaolo Bonzini
3242086d5f75SPaolo Bonziniif test "$gprof" = "yes" ; then
3243086d5f75SPaolo Bonzini  QEMU_CFLAGS="-p $QEMU_CFLAGS"
3244086d5f75SPaolo Bonzini  QEMU_LDFLAGS="-p $QEMU_LDFLAGS"
3245086d5f75SPaolo Bonzinifi
3246a316e378SJuan Quintela
3247247724cbSMarc-André Lureauif test "$have_asan" = "yes"; then
3248db5adeaaSPaolo Bonzini  QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
3249db5adeaaSPaolo Bonzini  QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
3250d83414e1SMarc-André Lureau  if test "$have_asan_iface_h" = "no" ; then
3251d83414e1SMarc-André Lureau      echo "ASAN build enabled, but ASAN header missing." \
3252d83414e1SMarc-André Lureau           "Without code annotation, the report may be inferior."
3253d83414e1SMarc-André Lureau  elif test "$have_asan_iface_fiber" = "no" ; then
3254d83414e1SMarc-André Lureau      echo "ASAN build enabled, but ASAN header is too old." \
3255d83414e1SMarc-André Lureau           "Without code annotation, the report may be inferior."
3256d83414e1SMarc-André Lureau  fi
3257247724cbSMarc-André Lureaufi
32580aebab04SLingfeng Yangif test "$have_tsan" = "yes" ; then
32590aebab04SLingfeng Yang  if test "$have_tsan_iface_fiber" = "yes" ; then
32600aebab04SLingfeng Yang    QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
32610aebab04SLingfeng Yang    QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
32620aebab04SLingfeng Yang  else
32630aebab04SLingfeng Yang    error_exit "Cannot enable TSAN due to missing fiber annotation interface."
32640aebab04SLingfeng Yang  fi
32650aebab04SLingfeng Yangelif test "$tsan" = "yes" ; then
32660aebab04SLingfeng Yang  error_exit "Cannot enable TSAN due to missing sanitize thread interface."
32670aebab04SLingfeng Yangfi
3268247724cbSMarc-André Lureauif test "$have_ubsan" = "yes"; then
3269db5adeaaSPaolo Bonzini  QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
3270db5adeaaSPaolo Bonzini  QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
3271247724cbSMarc-André Lureaufi
3272247724cbSMarc-André Lureau
32736542aa9cSPeter Lieven##########################################
32743efac6ebSTomáš Golembiovský
32750aebab04SLingfeng Yang# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
32760aebab04SLingfeng Yangif test "$solaris" = "no" && test "$tsan" = "no"; then
3277e86ecd4bSJuan Quintela    if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
3278db5adeaaSPaolo Bonzini        QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
3279e86ecd4bSJuan Quintela    fi
3280e86ecd4bSJuan Quintelafi
3281e86ecd4bSJuan Quintela
3282952afb71SBlue Swirl# Use ASLR, no-SEH and DEP if available
3283952afb71SBlue Swirlif test "$mingw32" = "yes" ; then
3284cb8baa77SMark Cave-Ayland    flags="--no-seh --nxcompat"
3285cb8baa77SMark Cave-Ayland
3286cb8baa77SMark Cave-Ayland    # Disable ASLR for debug builds to allow debugging with gdb
3287cb8baa77SMark Cave-Ayland    if test "$debug" = "no" ; then
3288cb8baa77SMark Cave-Ayland        flags="--dynamicbase $flags"
3289cb8baa77SMark Cave-Ayland    fi
3290cb8baa77SMark Cave-Ayland
3291cb8baa77SMark Cave-Ayland    for flag in $flags; do
3292e9a3591fSChristian Borntraeger        if ld_has $flag ; then
3293db5adeaaSPaolo Bonzini            QEMU_LDFLAGS="-Wl,$flag $QEMU_LDFLAGS"
3294952afb71SBlue Swirl        fi
3295952afb71SBlue Swirl    done
3296952afb71SBlue Swirlfi
3297952afb71SBlue Swirl
32989d6bc27bSMichael Roth# Probe for guest agent support/options
32999d6bc27bSMichael Roth
3300e8ef31a3SMichael Tokarevif [ "$guest_agent" != "no" ]; then
3301a5125905SLaurent Vivier  if [ "$softmmu" = no -a "$want_tools" = no ] ; then
3302a5125905SLaurent Vivier      guest_agent=no
3303a5125905SLaurent Vivier  elif [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" -o "$mingw32" = "yes" ] ; then
3304e8ef31a3SMichael Tokarev      guest_agent=yes
3305e8ef31a3SMichael Tokarev  elif [ "$guest_agent" != yes ]; then
3306e8ef31a3SMichael Tokarev      guest_agent=no
3307e8ef31a3SMichael Tokarev  else
3308e8ef31a3SMichael Tokarev      error_exit "Guest agent is not supported on this platform"
3309ca35f780SPaolo Bonzini  fi
33104b1c11fdSDaniel P. Berrangefi
3311ca35f780SPaolo Bonzini
3312b846ab7cSPaolo Bonzini# Guest agent Windows MSI package
33139d6bc27bSMichael Roth
33149d6bc27bSMichael Rothif test "$QEMU_GA_MANUFACTURER" = ""; then
33159d6bc27bSMichael Roth  QEMU_GA_MANUFACTURER=QEMU
33169d6bc27bSMichael Rothfi
33179d6bc27bSMichael Rothif test "$QEMU_GA_DISTRO" = ""; then
33189d6bc27bSMichael Roth  QEMU_GA_DISTRO=Linux
33199d6bc27bSMichael Rothfi
33209d6bc27bSMichael Rothif test "$QEMU_GA_VERSION" = ""; then
332189138857SStefan Weil    QEMU_GA_VERSION=$(cat $source_path/VERSION)
33229d6bc27bSMichael Rothfi
33239d6bc27bSMichael Roth
3324b846ab7cSPaolo BonziniQEMU_GA_MSI_MINGW_DLL_PATH="$($pkg_config --variable=prefix glib-2.0)/bin"
33259d6bc27bSMichael Roth
3326ca35f780SPaolo Bonzini# Mac OS X ships with a broken assembler
3327ca35f780SPaolo Bonziniroms=
3328e633a5c6SEric Blakeif { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \
3329ba7c60c2SPaolo Bonzini        test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
3330ba7c60c2SPaolo Bonzini        test "$targetos" != "haiku" && test "$softmmu" = yes ; then
3331e57218b6SPeter Maydell    # Different host OS linkers have different ideas about the name of the ELF
3332c65d5e4eSBrad Smith    # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
3333c65d5e4eSBrad Smith    # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
3334c65d5e4eSBrad Smith    for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
3335e57218b6SPeter Maydell        if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
3336e57218b6SPeter Maydell            ld_i386_emulation="$emu"
3337ca35f780SPaolo Bonzini            roms="optionrom"
3338e57218b6SPeter Maydell            break
3339e57218b6SPeter Maydell        fi
3340e57218b6SPeter Maydell    done
3341ca35f780SPaolo Bonzinifi
3342ca35f780SPaolo Bonzini
33432e33c3f8SThomas Huth# Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
3344a5b2afd5SThomas Huth# or -march=z10 (which is the lowest architecture level that Clang supports)
33459933c305SChristian Borntraegerif test "$cpu" = "s390x" ; then
33462e33c3f8SThomas Huth  write_c_skeleton
3347a5b2afd5SThomas Huth  compile_prog "-march=z900" ""
3348a5b2afd5SThomas Huth  has_z900=$?
33493af448b3SThomas Huth  if [ $has_z900 = 0 ] || compile_object "-march=z10 -msoft-float -Werror"; then
3350a5b2afd5SThomas Huth    if [ $has_z900 != 0 ]; then
3351a5b2afd5SThomas Huth      echo "WARNING: Your compiler does not support the z900!"
3352a5b2afd5SThomas Huth      echo "         The s390-ccw bios will only work with guest CPUs >= z10."
3353a5b2afd5SThomas Huth    fi
33549933c305SChristian Borntraeger    roms="$roms s390-ccw"
33551ef6bfc2SPhilippe Mathieu-Daudé    # SLOF is required for building the s390-ccw firmware on s390x,
33561ef6bfc2SPhilippe Mathieu-Daudé    # since it is using the libnet code from SLOF for network booting.
33571ef6bfc2SPhilippe Mathieu-Daudé    git_submodules="${git_submodules} roms/SLOF"
33581ef6bfc2SPhilippe Mathieu-Daudé  fi
33599933c305SChristian Borntraegerfi
33609933c305SChristian Borntraeger
336111cde1c8SBruno Dominguez# Check that the C++ compiler exists and works with the C compiler.
336211cde1c8SBruno Dominguez# All the QEMU_CXXFLAGS are based on QEMU_CFLAGS. Keep this at the end to don't miss any other that could be added.
336311cde1c8SBruno Dominguezif has $cxx; then
336411cde1c8SBruno Dominguez    cat > $TMPC <<EOF
336511cde1c8SBruno Dominguezint c_function(void);
336611cde1c8SBruno Dominguezint main(void) { return c_function(); }
336711cde1c8SBruno DominguezEOF
336811cde1c8SBruno Dominguez
336911cde1c8SBruno Dominguez    compile_object
337011cde1c8SBruno Dominguez
337111cde1c8SBruno Dominguez    cat > $TMPCXX <<EOF
337211cde1c8SBruno Dominguezextern "C" {
337311cde1c8SBruno Dominguez   int c_function(void);
337411cde1c8SBruno Dominguez}
337511cde1c8SBruno Dominguezint c_function(void) { return 42; }
337611cde1c8SBruno DominguezEOF
337711cde1c8SBruno Dominguez
337811cde1c8SBruno Dominguez    update_cxxflags
337911cde1c8SBruno Dominguez
3380a2866660SPaolo Bonzini    if do_cxx $CXXFLAGS $EXTRA_CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
338111cde1c8SBruno Dominguez        # C++ compiler $cxx works ok with C compiler $cc
338211cde1c8SBruno Dominguez        :
338311cde1c8SBruno Dominguez    else
338411cde1c8SBruno Dominguez        echo "C++ compiler $cxx does not work with C compiler $cc"
338511cde1c8SBruno Dominguez        echo "Disabling C++ specific optional code"
338611cde1c8SBruno Dominguez        cxx=
338711cde1c8SBruno Dominguez    fi
338811cde1c8SBruno Dominguezelse
338911cde1c8SBruno Dominguez    echo "No C++ compiler available; disabling C++ specific optional code"
339011cde1c8SBruno Dominguez    cxx=
339111cde1c8SBruno Dominguezfi
339211cde1c8SBruno Dominguez
33937d7dbf9dSDan Streetmanif !(GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
33947d7dbf9dSDan Streetman    exit 1
33955d91a2edSYonggang Luofi
33965d91a2edSYonggang Luo
339798ec69acSJuan Quintelaconfig_host_mak="config-host.mak"
339897a847bcSbellard
339998ec69acSJuan Quintelaecho "# Automatically generated by configure - do not modify" > $config_host_mak
340098ec69acSJuan Quintelaecho >> $config_host_mak
340198ec69acSJuan Quintela
3402e6c3b0f7SPaolo Bonziniecho all: >> $config_host_mak
3403cc84d63aSDaniel P. Berrangeecho "GIT=$git" >> $config_host_mak
3404aef45d51SDaniel P. Berrangeecho "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
34057d7dbf9dSDan Streetmanecho "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
3406804edf29SJuan Quintela
340798ec69acSJuan Quintelaecho "ARCH=$ARCH" >> $config_host_mak
3408727e5283SPaolo Bonzini
3409f8393946Saurel32if test "$debug_tcg" = "yes" ; then
34102358a494SJuan Quintela  echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
3411f8393946Saurel32fi
34121625af87Saliguoriif test "$strip_opt" = "yes" ; then
341352ba784dSHollis Blanchard  echo "STRIP=${strip}" >> $config_host_mak
34141625af87Saliguorifi
341567b915a5Sbellardif test "$mingw32" = "yes" ; then
341698ec69acSJuan Quintela  echo "CONFIG_WIN32=y" >> $config_host_mak
3417d9840e25STomoki Sekiyama  if test "$guest_agent_with_vss" = "yes" ; then
3418d9840e25STomoki Sekiyama    echo "CONFIG_QGA_VSS=y" >> $config_host_mak
3419f33ca81fSMichael Roth    echo "QGA_VSS_PROVIDER=$qga_vss_provider" >> $config_host_mak
3420d9840e25STomoki Sekiyama    echo "WIN_SDK=\"$win_sdk\"" >> $config_host_mak
3421d9840e25STomoki Sekiyama  fi
342250cbebb9SMichael Roth  if test "$guest_agent_ntddscsi" = "yes" ; then
342376dc75caSTomáš Golembiovský    echo "CONFIG_QGA_NTDDSCSI=y" >> $config_host_mak
342450cbebb9SMichael Roth  fi
34259dacf32dSYossi Hindin  echo "QEMU_GA_MSI_MINGW_DLL_PATH=${QEMU_GA_MSI_MINGW_DLL_PATH}" >> $config_host_mak
34269dacf32dSYossi Hindin  echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
34279dacf32dSYossi Hindin  echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
34289dacf32dSYossi Hindin  echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
3429210fa556Spbrookelse
343035f4df27SJuan Quintela  echo "CONFIG_POSIX=y" >> $config_host_mak
3431210fa556Spbrookfi
3432128ab2ffSblueswir1
3433dffcb71cSMark McLoughlinif test "$linux" = "yes" ; then
3434dffcb71cSMark McLoughlin  echo "CONFIG_LINUX=y" >> $config_host_mak
3435dffcb71cSMark McLoughlinfi
3436dffcb71cSMark McLoughlin
343783fb7adfSbellardif test "$darwin" = "yes" ; then
343898ec69acSJuan Quintela  echo "CONFIG_DARWIN=y" >> $config_host_mak
343983fb7adfSbellardfi
3440b29fe3edSmalc
3441ec530c81Sbellardif test "$solaris" = "yes" ; then
344298ec69acSJuan Quintela  echo "CONFIG_SOLARIS=y" >> $config_host_mak
3443ec530c81Sbellardfi
344497a847bcSbellardif test "$static" = "yes" ; then
344598ec69acSJuan Quintela  echo "CONFIG_STATIC=y" >> $config_host_mak
344697a847bcSbellardfi
34471ba16968SStefan Weilif test "$profiler" = "yes" ; then
34482358a494SJuan Quintela  echo "CONFIG_PROFILER=y" >> $config_host_mak
344905c2a3e7Sbellardfi
3450c932ce31SPaolo Bonziniif test "$want_tools" = "yes" ; then
3451c932ce31SPaolo Bonzini  echo "CONFIG_TOOLS=y" >> $config_host_mak
3452c932ce31SPaolo Bonzinifi
3453f15bff25SPaolo Bonziniif test "$guest_agent" = "yes" ; then
3454f15bff25SPaolo Bonzini  echo "CONFIG_GUEST_AGENT=y" >> $config_host_mak
3455f15bff25SPaolo Bonzinifi
3456b8e0c493SJoelle van Dyneif test "$slirp_smbd" = "yes" ; then
3457b8e0c493SJoelle van Dyne  echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak
3458e2d8830eSBrad  echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
3459b8e0c493SJoelle van Dynefi
34604cc600d2SPaolo Bonziniif test "$gprof" = "yes" ; then
34614cc600d2SPaolo Bonzini  echo "CONFIG_GPROF=y" >> $config_host_mak
34624cc600d2SPaolo Bonzinifi
3463b64ec4e4SFam Zhengecho "CONFIG_BDRV_RW_WHITELIST=$block_drv_rw_whitelist" >> $config_host_mak
3464b64ec4e4SFam Zhengecho "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
3465e5f05f8cSKevin Wolfif test "$block_drv_whitelist_tools" = "yes" ; then
3466e5f05f8cSKevin Wolf  echo "CONFIG_BDRV_WHITELIST_TOOLS=y" >> $config_host_mak
3467e5f05f8cSKevin Wolffi
3468dce512deSChristoph Hellwigif test "$xfs" = "yes" ; then
3469dce512deSChristoph Hellwig  echo "CONFIG_XFS=y" >> $config_host_mak
3470dce512deSChristoph Hellwigfi
347189138857SStefan Weilqemu_version=$(head $source_path/VERSION)
34722358a494SJuan Quintelaecho "PKGVERSION=$pkgversion" >>$config_host_mak
347398ec69acSJuan Quintelaecho "SRC_PATH=$source_path" >> $config_host_mak
34742b1f35b9SAlex Bennéeecho "TARGET_DIRS=$target_list" >> $config_host_mak
347517969268SFam Zhengif test "$modules" = "yes"; then
3476e26110cfSFam Zheng  # $shacmd can generate a hash started with digit, which the compiler doesn't
3477e26110cfSFam Zheng  # like as an symbol. So prefix it with an underscore
347889138857SStefan Weil  echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
347917969268SFam Zheng  echo "CONFIG_MODULES=y" >> $config_host_mak
348017969268SFam Zhengfi
3481bd83c861SChristian Ehrhardtif test "$module_upgrades" = "yes"; then
3482bd83c861SChristian Ehrhardt  echo "CONFIG_MODULE_UPGRADES=y" >> $config_host_mak
3483bd83c861SChristian Ehrhardtfi
3484955727d2SCortland Tölvaif test "$have_usbfs" = "yes" ; then
3485955727d2SCortland Tölva  echo "CONFIG_USBFS=y" >> $config_host_mak
3486955727d2SCortland Tölvafi
3487f876b765SMarc-André Lureauif test "$gio" = "yes" ; then
3488f876b765SMarc-André Lureau    echo "CONFIG_GIO=y" >> $config_host_mak
3489f876b765SMarc-André Lureau    echo "GIO_CFLAGS=$gio_cflags" >> $config_host_mak
3490f876b765SMarc-André Lureau    echo "GIO_LIBS=$gio_libs" >> $config_host_mak
34915ecfb76cSPaolo Bonzinifi
34925ecfb76cSPaolo Bonziniif test "$gdbus_codegen" != "" ; then
349325a97a56SMarc-André Lureau    echo "GDBUS_CODEGEN=$gdbus_codegen" >> $config_host_mak
3494f876b765SMarc-André Lureaufi
3495a1c5e949SDaniel P. Berrangeecho "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak
3496277abf15SJan Vesely
34971badb709SPaolo Bonziniif test "$xen" = "enabled" ; then
34986dbd588aSJan Kiszka  echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
3499d5b93ddfSAnthony PERARD  echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
3500582ea95fSMarc-André Lureau  echo "XEN_CFLAGS=$xen_cflags" >> $config_host_mak
3501582ea95fSMarc-André Lureau  echo "XEN_LIBS=$xen_libs" >> $config_host_mak
3502e37630caSaliguorifi
35035e9be92dSNicholas Bellingerif test "$vhost_scsi" = "yes" ; then
35045e9be92dSNicholas Bellinger  echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
35055e9be92dSNicholas Bellingerfi
3506af3bba76SPaolo Bonziniif test "$vhost_net" = "yes" ; then
3507af3bba76SPaolo Bonzini  echo "CONFIG_VHOST_NET=y" >> $config_host_mak
3508af3bba76SPaolo Bonzinifi
3509af3bba76SPaolo Bonziniif test "$vhost_net_user" = "yes" ; then
351056f41de7SPaolo Bonzini  echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak
351103ce5744SNikolay Nikolaevfi
3512108a6481SCindy Luif test "$vhost_net_vdpa" = "yes" ; then
3513108a6481SCindy Lu  echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak
3514108a6481SCindy Lufi
3515042cea27SGongleiif test "$vhost_crypto" = "yes" ; then
3516042cea27SGonglei  echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
3517042cea27SGongleifi
3518fc0b9b0eSStefan Hajnocziif test "$vhost_vsock" = "yes" ; then
3519fc0b9b0eSStefan Hajnoczi  echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
35205fe97d88SStefano Garzarella  if test "$vhost_user" = "yes" ; then
35215fe97d88SStefano Garzarella    echo "CONFIG_VHOST_USER_VSOCK=y" >> $config_host_mak
35225fe97d88SStefano Garzarella  fi
3523fc0b9b0eSStefan Hajnoczifi
3524299e6f19SPaolo Bonziniif test "$vhost_kernel" = "yes" ; then
3525299e6f19SPaolo Bonzini  echo "CONFIG_VHOST_KERNEL=y" >> $config_host_mak
3526299e6f19SPaolo Bonzinifi
3527e6a74868SMarc-André Lureauif test "$vhost_user" = "yes" ; then
3528e6a74868SMarc-André Lureau  echo "CONFIG_VHOST_USER=y" >> $config_host_mak
3529e6a74868SMarc-André Lureaufi
3530108a6481SCindy Luif test "$vhost_vdpa" = "yes" ; then
3531108a6481SCindy Lu  echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
3532108a6481SCindy Lufi
353398fc1adaSDr. David Alan Gilbertif test "$vhost_user_fs" = "yes" ; then
353498fc1adaSDr. David Alan Gilbert  echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak
353598fc1adaSDr. David Alan Gilbertfi
3536a40161cbSPaolo Bonziniif test "$membarrier" = "yes" ; then
3537a40161cbSPaolo Bonzini  echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
3538a40161cbSPaolo Bonzinifi
3539e5b46549SRichard Hendersonif test "$tcg" = "enabled" -a "$tcg_interpreter" = "true" ; then
3540e5b46549SRichard Henderson  echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
3541e5b46549SRichard Hendersonfi
354258d3f3ffSGerd Hoffmann
3543da076ffeSGerd Hoffmannif test "$opengl" = "yes" ; then
3544da076ffeSGerd Hoffmann  echo "CONFIG_OPENGL=y" >> $config_host_mak
3545de2d3005SPaolo Bonzini  echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
3546da076ffeSGerd Hoffmann  echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
354720ff075bSMichael Wallefi
354820ff075bSMichael Walle
354999f2dbd3SLiang Liif test "$avx2_opt" = "yes" ; then
355099f2dbd3SLiang Li  echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
355199f2dbd3SLiang Lifi
355299f2dbd3SLiang Li
35536b8cd447SRobert Hooif test "$avx512f_opt" = "yes" ; then
35546b8cd447SRobert Hoo  echo "CONFIG_AVX512F_OPT=y" >> $config_host_mak
35556b8cd447SRobert Hoofi
35566b8cd447SRobert Hoo
355783fb7adfSbellard# XXX: suppress that
35587d3505c5Sbellardif [ "$bsd" = "yes" ] ; then
35592358a494SJuan Quintela  echo "CONFIG_BSD=y" >> $config_host_mak
35607d3505c5Sbellardfi
35617d3505c5Sbellard
35623556c233SPaolo Bonziniif test "$qom_cast_debug" = "yes" ; then
35633556c233SPaolo Bonzini  echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak
35643556c233SPaolo Bonzinifi
356520ff6c80SAnthony Liguori
35667c2acc70SPeter Maydellecho "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
356770c60c08SStefan Hajnocziif test "$coroutine_pool" = "yes" ; then
356870c60c08SStefan Hajnoczi  echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
356970c60c08SStefan Hajnoczielse
357070c60c08SStefan Hajnoczi  echo "CONFIG_COROUTINE_POOL=0" >> $config_host_mak
357170c60c08SStefan Hajnoczifi
3572d0e2fce5SAneesh Kumar K.V
35737d992e4dSPeter Lievenif test "$debug_stack_usage" = "yes" ; then
35747d992e4dSPeter Lieven  echo "CONFIG_DEBUG_STACK_USAGE=y" >> $config_host_mak
35757d992e4dSPeter Lievenfi
35767d992e4dSPeter Lieven
3577f0d92b56SLongpeng(Mike)if test "$crypto_afalg" = "yes" ; then
3578f0d92b56SLongpeng(Mike)  echo "CONFIG_AF_ALG=y" >> $config_host_mak
3579f0d92b56SLongpeng(Mike)fi
3580f0d92b56SLongpeng(Mike)
3581d83414e1SMarc-André Lureauif test "$have_asan_iface_fiber" = "yes" ; then
3582d83414e1SMarc-André Lureau    echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
3583d83414e1SMarc-André Lureaufi
3584d83414e1SMarc-André Lureau
35850aebab04SLingfeng Yangif test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
35860aebab04SLingfeng Yang    echo "CONFIG_TSAN=y" >> $config_host_mak
35870aebab04SLingfeng Yangfi
35880aebab04SLingfeng Yang
358976a347e1SRichard Hendersonif test "$cpuid_h" = "yes" ; then
359076a347e1SRichard Henderson  echo "CONFIG_CPUID_H=y" >> $config_host_mak
359176a347e1SRichard Hendersonfi
359276a347e1SRichard Henderson
3593f540166bSRichard Hendersonif test "$int128" = "yes" ; then
3594f540166bSRichard Henderson  echo "CONFIG_INT128=y" >> $config_host_mak
3595f540166bSRichard Hendersonfi
3596f540166bSRichard Henderson
35977ebee43eSRichard Hendersonif test "$atomic128" = "yes" ; then
35987ebee43eSRichard Henderson  echo "CONFIG_ATOMIC128=y" >> $config_host_mak
35997ebee43eSRichard Hendersonfi
36007ebee43eSRichard Henderson
3601e6cd4bb5SRichard Hendersonif test "$cmpxchg128" = "yes" ; then
3602e6cd4bb5SRichard Henderson  echo "CONFIG_CMPXCHG128=y" >> $config_host_mak
3603e6cd4bb5SRichard Hendersonfi
3604e6cd4bb5SRichard Henderson
3605ed1701c6SDr. David Alan Gilbertif test "$live_block_migration" = "yes" ; then
3606ed1701c6SDr. David Alan Gilbert  echo "CONFIG_LIVE_BLOCK_MIGRATION=y" >> $config_host_mak
3607ed1701c6SDr. David Alan Gilbertfi
3608ed1701c6SDr. David Alan Gilbert
36093b8acc11SPaolo Bonziniif test "$tpm" = "yes"; then
36103cae16dbSPaolo Bonzini  echo 'CONFIG_TPM=y' >> $config_host_mak
36113b8acc11SPaolo Bonzinifi
36123b8acc11SPaolo Bonzini
36132da776dbSMichael R. Hinesif test "$rdma" = "yes" ; then
36142da776dbSMichael R. Hines  echo "CONFIG_RDMA=y" >> $config_host_mak
3615392fb643SFam Zheng  echo "RDMA_LIBS=$rdma_libs" >> $config_host_mak
36162da776dbSMichael R. Hinesfi
36172da776dbSMichael R. Hines
361821ab34c9SMarcel Apfelbaumif test "$pvrdma" = "yes" ; then
361921ab34c9SMarcel Apfelbaum  echo "CONFIG_PVRDMA=y" >> $config_host_mak
362021ab34c9SMarcel Apfelbaumfi
362121ab34c9SMarcel Apfelbaum
3622a6b1d4c0SChanglong Xieif test "$replication" = "yes" ; then
3623a6b1d4c0SChanglong Xie  echo "CONFIG_REPLICATION=y" >> $config_host_mak
3624a6b1d4c0SChanglong Xiefi
3625a6b1d4c0SChanglong Xie
3626ba59fb77SPaolo Bonziniif test "$debug_mutex" = "yes" ; then
3627ba59fb77SPaolo Bonzini  echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak
3628ba59fb77SPaolo Bonzinifi
3629e0580342SKamil Rytarowski
36302f740136SJeff Codyif test "$bochs" = "yes" ; then
36312f740136SJeff Cody  echo "CONFIG_BOCHS=y" >> $config_host_mak
36322f740136SJeff Codyfi
36332f740136SJeff Codyif test "$cloop" = "yes" ; then
36342f740136SJeff Cody  echo "CONFIG_CLOOP=y" >> $config_host_mak
36352f740136SJeff Codyfi
36362f740136SJeff Codyif test "$dmg" = "yes" ; then
36372f740136SJeff Cody  echo "CONFIG_DMG=y" >> $config_host_mak
36382f740136SJeff Codyfi
36392f740136SJeff Codyif test "$qcow1" = "yes" ; then
36402f740136SJeff Cody  echo "CONFIG_QCOW1=y" >> $config_host_mak
36412f740136SJeff Codyfi
36422f740136SJeff Codyif test "$vdi" = "yes" ; then
36432f740136SJeff Cody  echo "CONFIG_VDI=y" >> $config_host_mak
36442f740136SJeff Codyfi
36452f740136SJeff Codyif test "$vvfat" = "yes" ; then
36462f740136SJeff Cody  echo "CONFIG_VVFAT=y" >> $config_host_mak
36472f740136SJeff Codyfi
36482f740136SJeff Codyif test "$qed" = "yes" ; then
36492f740136SJeff Cody  echo "CONFIG_QED=y" >> $config_host_mak
36502f740136SJeff Codyfi
36512f740136SJeff Codyif test "$parallels" = "yes" ; then
36522f740136SJeff Cody  echo "CONFIG_PARALLELS=y" >> $config_host_mak
36532f740136SJeff Codyfi
36542f740136SJeff Cody
365540e8c6f4SAlex Bennéeif test "$plugins" = "yes" ; then
365640e8c6f4SAlex Bennée    echo "CONFIG_PLUGIN=y" >> $config_host_mak
365726fffe29SEmilio G. Cota    # Copy the export object list to the build dir
365826fffe29SEmilio G. Cota    if test "$ld_dynamic_list" = "yes" ; then
365926fffe29SEmilio G. Cota	echo "CONFIG_HAS_LD_DYNAMIC_LIST=yes" >> $config_host_mak
366026fffe29SEmilio G. Cota	ld_symbols=qemu-plugins-ld.symbols
366126fffe29SEmilio G. Cota	cp "$source_path/plugins/qemu-plugins.symbols" $ld_symbols
366226fffe29SEmilio G. Cota    elif test "$ld_exported_symbols_list" = "yes" ; then
366326fffe29SEmilio G. Cota	echo "CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST=yes" >> $config_host_mak
366426fffe29SEmilio G. Cota	ld64_symbols=qemu-plugins-ld64.symbols
366526fffe29SEmilio G. Cota	echo "# Automatically generated by configure - do not modify" > $ld64_symbols
366626fffe29SEmilio G. Cota	grep 'qemu_' "$source_path/plugins/qemu-plugins.symbols" | sed 's/;//g' | \
366726fffe29SEmilio G. Cota	    sed -E 's/^[[:space:]]*(.*)/_\1/' >> $ld64_symbols
366826fffe29SEmilio G. Cota    else
366926fffe29SEmilio G. Cota	error_exit \
367026fffe29SEmilio G. Cota	    "If \$plugins=yes, either \$ld_dynamic_list or " \
367126fffe29SEmilio G. Cota	    "\$ld_exported_symbols_list should have been set to 'yes'."
367226fffe29SEmilio G. Cota    fi
367340e8c6f4SAlex Bennéefi
367440e8c6f4SAlex Bennée
3675f48e590aSAlex Bennéeif test -n "$gdb_bin"; then
3676b1863cccSAlex Bennée    gdb_version=$($gdb_bin --version | head -n 1)
3677d6a66c81SAlex Bennée    if version_ge ${gdb_version##* } 9.1; then
3678f48e590aSAlex Bennée        echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
3679f48e590aSAlex Bennée    fi
3680b1863cccSAlex Bennéefi
3681f48e590aSAlex Bennée
368254e7aac0SAlexey Krasikovif test "$secret_keyring" = "yes" ; then
368354e7aac0SAlexey Krasikov  echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak
368454e7aac0SAlexey Krasikovfi
368554e7aac0SAlexey Krasikov
368698ec69acSJuan Quintelaecho "ROMS=$roms" >> $config_host_mak
3687804edf29SJuan Quintelaecho "MAKE=$make" >> $config_host_mak
3688c886edfbSBlue Swirlecho "PYTHON=$python" >> $config_host_mak
368939d87c8cSAlex Bennéeecho "GENISOIMAGE=$genisoimage" >> $config_host_mak
3690a5665051SPaolo Bonziniecho "MESON=$meson" >> $config_host_mak
369109e93326SPaolo Bonziniecho "NINJA=$ninja" >> $config_host_mak
3692804edf29SJuan Quintelaecho "CC=$cc" >> $config_host_mak
3693433de74cSBastian Koppelmannecho "HOST_CC=$host_cc" >> $config_host_mak
3694a31a8642SMichael S. Tsirkinif $iasl -h > /dev/null 2>&1; then
3695859aef02SPaolo Bonzini  echo "CONFIG_IASL=$iasl" >> $config_host_mak
3696a31a8642SMichael S. Tsirkinfi
3697804edf29SJuan Quintelaecho "AR=$ar" >> $config_host_mak
3698cdbd727cSRichard Hendersonecho "AS=$as" >> $config_host_mak
36995f6f0e27SRichard Hendersonecho "CCAS=$ccas" >> $config_host_mak
37003dd46c78SBlue Swirlecho "CPP=$cpp" >> $config_host_mak
3701804edf29SJuan Quintelaecho "OBJCOPY=$objcopy" >> $config_host_mak
3702804edf29SJuan Quintelaecho "LD=$ld" >> $config_host_mak
370346eef33bSBradecho "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
3704a558ee17SJuan Quintelaecho "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
370511cde1c8SBruno Dominguezecho "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
3706a81df1b6SPaolo Bonziniecho "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
3707a81df1b6SPaolo Bonziniecho "GLIB_LIBS=$glib_libs" >> $config_host_mak
37088a99e9a3SPhilippe Mathieu-Daudéecho "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
3709e57218b6SPeter Maydellecho "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
3710804edf29SJuan Quintelaecho "EXESUF=$EXESUF" >> $config_host_mak
3711f15bff25SPaolo Bonziniecho "LIBS_QGA=$libs_qga" >> $config_host_mak
3712804edf29SJuan Quintela
3713b767d257SMarek Marczykowski-Góreckiif test "$rng_none" = "yes"; then
3714b767d257SMarek Marczykowski-Górecki  echo "CONFIG_RNG_NONE=y" >> $config_host_mak
3715b767d257SMarek Marczykowski-Góreckifi
3716b767d257SMarek Marczykowski-Górecki
37176efd7517SPeter Maydell# use included Linux headers
37186efd7517SPeter Maydellif test "$linux" = "yes" ; then
3719a307beb6SAndreas Färber  mkdir -p linux-headers
37206efd7517SPeter Maydell  case "$cpu" in
3721c72b26ecSRichard Henderson  i386|x86_64|x32)
372208312a63SPeter Maydell    linux_arch=x86
37236efd7517SPeter Maydell    ;;
3724f8378accSRichard Henderson  ppc|ppc64|ppc64le)
372508312a63SPeter Maydell    linux_arch=powerpc
37266efd7517SPeter Maydell    ;;
37276efd7517SPeter Maydell  s390x)
372808312a63SPeter Maydell    linux_arch=s390
372908312a63SPeter Maydell    ;;
37301f080313SClaudio Fontana  aarch64)
37311f080313SClaudio Fontana    linux_arch=arm64
37321f080313SClaudio Fontana    ;;
3733222e7d11SSanjay Lal  mips64)
3734222e7d11SSanjay Lal    linux_arch=mips
3735222e7d11SSanjay Lal    ;;
373608312a63SPeter Maydell  *)
373708312a63SPeter Maydell    # For most CPUs the kernel architecture name and QEMU CPU name match.
373808312a63SPeter Maydell    linux_arch="$cpu"
37396efd7517SPeter Maydell    ;;
37406efd7517SPeter Maydell  esac
374108312a63SPeter Maydell    # For non-KVM architectures we will not have asm headers
374208312a63SPeter Maydell    if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
374308312a63SPeter Maydell      symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
374408312a63SPeter Maydell    fi
37456efd7517SPeter Maydellfi
37466efd7517SPeter Maydell
374797a847bcSbellardfor target in $target_list; do
374897a847bcSbellard    target_dir="$target"
374957a93f16SPhilippe Mathieu-Daudé    target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
375097a847bcSbellard    mkdir -p $target_dir
3751fdb75aefSPaolo Bonzini    case $target in
3752fdb75aefSPaolo Bonzini        *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
3753fdb75aefSPaolo Bonzini        *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
37542408a527Saurel32    esac
375556aebc89Spbrookdone
37567d13299dSbellard
3757765686d6SPaolo Bonziniecho "CONFIG_QEMU_INTERP_PREFIX=$interp_prefix" | sed 's/%M/@0@/' >> $config_host_mak
3758fdb75aefSPaolo Bonziniif test "$default_targets" = "yes"; then
3759fdb75aefSPaolo Bonzini  echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
3760fdb75aefSPaolo Bonzinifi
3761a540f158SPeter Crosthwaite
3762a99d57bbSWanlong Gaoif test "$numa" = "yes"; then
3763a99d57bbSWanlong Gao  echo "CONFIG_NUMA=y" >> $config_host_mak
3764ab318051SMarc-André Lureau  echo "NUMA_LIBS=$numa_libs" >> $config_host_mak
3765a99d57bbSWanlong Gaofi
3766a99d57bbSWanlong Gao
3767fd0e6053SJohn Snowif test "$ccache_cpp2" = "yes"; then
3768fd0e6053SJohn Snow  echo "export CCACHE_CPP2=y" >> $config_host_mak
3769fd0e6053SJohn Snowfi
3770fd0e6053SJohn Snow
37711e4f6065SDaniele Buonoif test "$safe_stack" = "yes"; then
37721e4f6065SDaniele Buono  echo "CONFIG_SAFESTACK=y" >> $config_host_mak
37731e4f6065SDaniele Buonofi
37741e4f6065SDaniele Buono
3775e29e5c6eSPeter Maydell# If we're using a separate build tree, set it up now.
3776e29e5c6eSPeter Maydell# DIRS are directories which we simply mkdir in the build tree;
3777e29e5c6eSPeter Maydell# LINKS are things to symlink back into the source tree
3778e29e5c6eSPeter Maydell# (these can be both files and directories).
3779e29e5c6eSPeter Maydell# Caution: do not add files or directories here using wildcards. This
3780e29e5c6eSPeter Maydell# will result in problems later if a new file matching the wildcard is
3781e29e5c6eSPeter Maydell# added to the source tree -- nothing will cause configure to be rerun
3782e29e5c6eSPeter Maydell# so the build tree will be missing the link back to the new file, and
3783e29e5c6eSPeter Maydell# tests might fail. Prefer to keep the relevant files in their own
3784e29e5c6eSPeter Maydell# directory and symlink the directory instead.
378509db9b9dSGerd Hoffmann# UNLINK is used to remove symlinks from older development versions
378609db9b9dSGerd Hoffmann# that might get into the way when doing "git update" without doing
378709db9b9dSGerd Hoffmann# a "make distclean" in between.
37889d49bcf6SMarkus ArmbrusterDIRS="tests tests/tcg tests/qapi-schema tests/qtest/libqos"
37891cf4323eSThomas HuthDIRS="$DIRS tests/qtest tests/qemu-iotests tests/vm tests/fp tests/qgraph"
3790b855f8d1SPaolo BonziniDIRS="$DIRS docs docs/interop fsdev scsi"
3791744a928cSAlexey KardashevskiyDIRS="$DIRS pc-bios/optionrom pc-bios/s390-ccw"
37928db2a4fdSGerd HoffmannDIRS="$DIRS roms/seabios"
3793c17a386bSAlex BennéeDIRS="$DIRS contrib/plugins/"
37942038f8c8SPaolo BonziniLINKS="Makefile"
37953941996bSPaolo BonziniLINKS="$LINKS tests/tcg/Makefile.target"
3796ddcf607fSGerd HoffmannLINKS="$LINKS pc-bios/optionrom/Makefile"
3797e29e5c6eSPeter MaydellLINKS="$LINKS pc-bios/s390-ccw/Makefile"
37988db2a4fdSGerd HoffmannLINKS="$LINKS roms/seabios/Makefile"
3799e29e5c6eSPeter MaydellLINKS="$LINKS pc-bios/qemu-icon.bmp"
3800e29e5c6eSPeter MaydellLINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
3801bbbd9b6eSWillian RampazzoLINKS="$LINKS tests/avocado tests/data"
380239950353SPeter MaydellLINKS="$LINKS tests/qemu-iotests/check"
38038f8fd9edSCleber RosaLINKS="$LINKS python"
3804c17a386bSAlex BennéeLINKS="$LINKS contrib/plugins/Makefile "
380509db9b9dSGerd HoffmannUNLINK="pc-bios/keymaps"
3806753d11f2SRichard Hendersonfor bios_file in \
3807753d11f2SRichard Henderson    $source_path/pc-bios/*.bin \
38083a631b8eSBin Meng    $source_path/pc-bios/*.elf \
3809225a9ab8SAlexey Kardashevskiy    $source_path/pc-bios/*.lid \
3810753d11f2SRichard Henderson    $source_path/pc-bios/*.rom \
3811753d11f2SRichard Henderson    $source_path/pc-bios/*.dtb \
3812e89e33e1SDominik Dingel    $source_path/pc-bios/*.img \
3813753d11f2SRichard Henderson    $source_path/pc-bios/openbios-* \
38144e73c781SAlexander Graf    $source_path/pc-bios/u-boot.* \
381526ce90fdSLaszlo Ersek    $source_path/pc-bios/edk2-*.fd.bz2 \
3816cd946e5cSJohn Arbuckle    $source_path/pc-bios/palcode-* \
3817cd946e5cSJohn Arbuckle    $source_path/pc-bios/qemu_vga.ndrv
3818cd946e5cSJohn Arbuckle
3819753d11f2SRichard Hendersondo
3820e29e5c6eSPeter Maydell    LINKS="$LINKS pc-bios/$(basename $bios_file)"
38217ea78b74SJan Kiszkadone
3822d1807a4fSPaolo Bonzinimkdir -p $DIRS
3823e29e5c6eSPeter Maydellfor f in $LINKS ; do
38240f4d8894SPaolo Bonzini    if [ -e "$source_path/$f" ]; then
3825f9245e10SPeter Maydell        symlink "$source_path/$f" "$f"
3826f9245e10SPeter Maydell    fi
38277d13299dSbellarddone
382809db9b9dSGerd Hoffmannfor f in $UNLINK ; do
382909db9b9dSGerd Hoffmann    if [ -L "$f" ]; then
383009db9b9dSGerd Hoffmann        rm -f "$f"
383109db9b9dSGerd Hoffmann    fi
383209db9b9dSGerd Hoffmanndone
38331ad2134fSPaul Brook
38342038f8c8SPaolo Bonzini(for i in $cross_cc_vars; do
38352038f8c8SPaolo Bonzini  export $i
38362038f8c8SPaolo Bonzinidone
3837de6d7e6bSAlex Bennéeexport target_list source_path use_containers ARCH
38382038f8c8SPaolo Bonzini$source_path/tests/tcg/configure.sh)
38392038f8c8SPaolo Bonzini
3840c34ebfdcSAnthony Liguori# temporary config to build submodules
38418db2a4fdSGerd Hoffmannfor rom in seabios; do
3842c34ebfdcSAnthony Liguori    config_mak=roms/$rom/config.mak
384337116c89SStefan Weil    echo "# Automatically generated by configure - do not modify" > $config_mak
3844c34ebfdcSAnthony Liguori    echo "SRC_PATH=$source_path/roms/$rom" >> $config_mak
3845cdbd727cSRichard Henderson    echo "AS=$as" >> $config_mak
38465f6f0e27SRichard Henderson    echo "CCAS=$ccas" >> $config_mak
3847c34ebfdcSAnthony Liguori    echo "CC=$cc" >> $config_mak
3848c34ebfdcSAnthony Liguori    echo "BCC=bcc" >> $config_mak
38493dd46c78SBlue Swirl    echo "CPP=$cpp" >> $config_mak
3850c34ebfdcSAnthony Liguori    echo "OBJCOPY=objcopy" >> $config_mak
3851a31a8642SMichael S. Tsirkin    echo "IASL=$iasl" >> $config_mak
3852c34ebfdcSAnthony Liguori    echo "LD=$ld" >> $config_mak
38539f81aeb5SAlistair Francis    echo "RANLIB=$ranlib" >> $config_mak
3854c34ebfdcSAnthony Liguoridone
3855c34ebfdcSAnthony Liguori
385698409991SHelge Konetzkaconfig_mak=pc-bios/optionrom/config.mak
385798409991SHelge Konetzkaecho "# Automatically generated by configure - do not modify" > $config_mak
385898409991SHelge Konetzkaecho "TOPSRC_DIR=$source_path" >> $config_mak
385998409991SHelge Konetzka
3860a5665051SPaolo Bonziniif test "$skip_meson" = no; then
3861fc929892SMarc-André Lureau  cross="config-meson.cross.new"
3862fc929892SMarc-André Lureau  meson_quote() {
3863ac7ebcc5SPaolo Bonzini    test $# = 0 && return
386447b30835SPaolo Bonzini    echo "'$(echo $* | sed "s/ /','/g")'"
3865fc929892SMarc-André Lureau  }
3866fc929892SMarc-André Lureau
3867fc929892SMarc-André Lureau  echo "# Automatically generated by configure - do not modify" > $cross
3868fc929892SMarc-André Lureau  echo "[properties]" >> $cross
3869d1d5e9eeSAlex Bennée
3870d1d5e9eeSAlex Bennée  # unroll any custom device configs
3871d1d5e9eeSAlex Bennée  for a in $device_archs; do
3872d1d5e9eeSAlex Bennée      eval "c=\$devices_${a}"
3873d1d5e9eeSAlex Bennée      echo "${a}-softmmu = '$c'" >> $cross
3874d1d5e9eeSAlex Bennée  done
3875d1d5e9eeSAlex Bennée
3876fc929892SMarc-André Lureau  test -z "$cxx" && echo "link_language = 'c'" >> $cross
387747b30835SPaolo Bonzini  echo "[built-in options]" >> $cross
3878a2866660SPaolo Bonzini  echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
3879a2866660SPaolo Bonzini  echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
3880a2866660SPaolo Bonzini  echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
3881a2866660SPaolo Bonzini  echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
3882fc929892SMarc-André Lureau  echo "[binaries]" >> $cross
38834dba2789SPaolo Bonzini  echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
38844dba2789SPaolo Bonzini  test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
38854dba2789SPaolo Bonzini  test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
388647b30835SPaolo Bonzini  echo "ar = [$(meson_quote $ar)]" >> $cross
388747b30835SPaolo Bonzini  echo "nm = [$(meson_quote $nm)]" >> $cross
388847b30835SPaolo Bonzini  echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
388947b30835SPaolo Bonzini  echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
3890e8178514SPaolo Bonzini  if has $sdl2_config; then
389147b30835SPaolo Bonzini    echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
3892e8178514SPaolo Bonzini  fi
389347b30835SPaolo Bonzini  echo "strip = [$(meson_quote $strip)]" >> $cross
389447b30835SPaolo Bonzini  echo "windres = [$(meson_quote $windres)]" >> $cross
38953812c0c4SJoelle van Dyne  if test "$cross_compile" = "yes"; then
3896fc929892SMarc-André Lureau    cross_arg="--cross-file config-meson.cross"
3897fc929892SMarc-André Lureau    echo "[host_machine]" >> $cross
3898ba7c60c2SPaolo Bonzini    echo "system = '$targetos'" >> $cross
3899fc929892SMarc-André Lureau    case "$ARCH" in
3900f6bca9dfSJoelle van Dyne        i386)
3901fc929892SMarc-André Lureau            echo "cpu_family = 'x86'" >> $cross
3902fc929892SMarc-André Lureau            ;;
3903f8bb7e1cSDavid Michael        x86_64|x32)
3904f6bca9dfSJoelle van Dyne            echo "cpu_family = 'x86_64'" >> $cross
3905f6bca9dfSJoelle van Dyne            ;;
3906fc929892SMarc-André Lureau        ppc64le)
3907fc929892SMarc-André Lureau            echo "cpu_family = 'ppc64'" >> $cross
3908fc929892SMarc-André Lureau            ;;
3909fc929892SMarc-André Lureau        *)
3910fc929892SMarc-André Lureau            echo "cpu_family = '$ARCH'" >> $cross
3911fc929892SMarc-André Lureau            ;;
3912fc929892SMarc-André Lureau    esac
3913fc929892SMarc-André Lureau    echo "cpu = '$cpu'" >> $cross
3914fc929892SMarc-André Lureau    if test "$bigendian" = "yes" ; then
3915fc929892SMarc-André Lureau        echo "endian = 'big'" >> $cross
3916fc929892SMarc-André Lureau    else
3917fc929892SMarc-André Lureau        echo "endian = 'little'" >> $cross
3918fc929892SMarc-André Lureau    fi
3919fc929892SMarc-André Lureau  else
3920fc929892SMarc-André Lureau    cross_arg="--native-file config-meson.cross"
3921fc929892SMarc-André Lureau  fi
3922fc929892SMarc-André Lureau  mv $cross config-meson.cross
3923fc929892SMarc-André Lureau
3924a5665051SPaolo Bonzini  rm -rf meson-private meson-info meson-logs
392561d63097SPaolo Bonzini  run_meson() {
392609e93326SPaolo Bonzini    NINJA=$ninja $meson setup \
3927d17f305aSPaolo Bonzini        --prefix "$prefix" \
3928d17f305aSPaolo Bonzini        --libdir "$libdir" \
3929d17f305aSPaolo Bonzini        --libexecdir "$libexecdir" \
3930d17f305aSPaolo Bonzini        --bindir "$bindir" \
3931d17f305aSPaolo Bonzini        --includedir "$includedir" \
3932d17f305aSPaolo Bonzini        --datadir "$datadir" \
3933d17f305aSPaolo Bonzini        --mandir "$mandir" \
3934d17f305aSPaolo Bonzini        --sysconfdir "$sysconfdir" \
393516bf7a33SPaolo Bonzini        --localedir "$localedir" \
3936d17f305aSPaolo Bonzini        --localstatedir "$local_statedir" \
39373b4da132SPaolo Bonzini        -Daudio_drv_list=$audio_drv_list \
39383b4da132SPaolo Bonzini        -Ddefault_devices=$default_devices \
3939d17f305aSPaolo Bonzini        -Ddocdir="$docdir" \
394016bf7a33SPaolo Bonzini        -Dqemu_firmwarepath="$firmwarepath" \
394173f3aa37SMarc-André Lureau        -Dqemu_suffix="$qemu_suffix" \
39423b4da132SPaolo Bonzini        -Dsphinx_build="$sphinx_build" \
39433b4da132SPaolo Bonzini        -Dtrace_file="$trace_file" \
3944a5665051SPaolo Bonzini        -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) \
3945a5665051SPaolo Bonzini        -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo false; fi) \
3946a5665051SPaolo Bonzini        -Dwerror=$(if test "$werror" = yes; then echo true; else echo false; fi) \
3947a5665051SPaolo Bonzini        -Dstrip=$(if test "$strip_opt" = yes; then echo true; else echo false; fi) \
3948da6d48b9SMarc-André Lureau        -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \
3949bf0e56a3SMarc-André Lureau        -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
39503b4da132SPaolo Bonzini        -Db_lto=$lto -Dcfi=$cfi -Dtcg=$tcg -Dxen=$xen \
39513b4da132SPaolo Bonzini        -Dcapstone=$capstone -Dfdt=$fdt -Dslirp=$slirp \
3952537b7248SPaolo Bonzini        $(test -n "${LIB_FUZZING_ENGINE+xxx}" && echo "-Dfuzzing_engine=$LIB_FUZZING_ENGINE") \
3953332008e0SThomas Huth        $(if test "$default_feature" = no; then echo "-Dauto_features=disabled"; fi) \
395461d63097SPaolo Bonzini        "$@" $cross_arg "$PWD" "$source_path"
395561d63097SPaolo Bonzini  }
395661d63097SPaolo Bonzini  eval run_meson $meson_options
3957a5665051SPaolo Bonzini  if test "$?" -ne 0 ; then
3958a5665051SPaolo Bonzini      error_exit "meson setup failed"
3959a5665051SPaolo Bonzini  fi
3960699d3884SPaolo Bonzinielse
3961699d3884SPaolo Bonzini  if test -f meson-private/cmd_line.txt; then
3962699d3884SPaolo Bonzini    # Adjust old command line options whose type was changed
3963699d3884SPaolo Bonzini    # Avoids having to use "setup --wipe" when Meson is upgraded
3964699d3884SPaolo Bonzini    perl -i -ne '
3965699d3884SPaolo Bonzini      s/^gettext = true$/gettext = auto/;
3966699d3884SPaolo Bonzini      s/^gettext = false$/gettext = disabled/;
3967654d6b04SPaolo Bonzini      /^b_staticpic/ && next;
3968699d3884SPaolo Bonzini      print;' meson-private/cmd_line.txt
3969699d3884SPaolo Bonzini  fi
3970a5665051SPaolo Bonzinifi
3971a5665051SPaolo Bonzini
39722d838d9bSAlex Bennéeif test -n "${deprecated_features}"; then
39732d838d9bSAlex Bennée    echo "Warning, deprecated features enabled."
3974a476b216SMao Zhongyi    echo "Please see docs/about/deprecated.rst"
39752d838d9bSAlex Bennée    echo "  features: ${deprecated_features}"
39762d838d9bSAlex Bennéefi
39772d838d9bSAlex Bennée
3978e0447a83SThomas Huth# Create list of config switches that should be poisoned in common code...
3979e0447a83SThomas Huth# but filter out CONFIG_TCG and CONFIG_USER_ONLY which are special.
398054b0306eSThomas Huthtarget_configs_h=$(ls *-config-devices.h *-config-target.h 2>/dev/null)
398154b0306eSThomas Huthif test -n "$target_configs_h" ; then
3982e0447a83SThomas Huth    sed -n -e '/CONFIG_TCG/d' -e '/CONFIG_USER_ONLY/d' \
3983e0447a83SThomas Huth        -e '/^#define / { s///; s/ .*//; s/^/#pragma GCC poison /p; }' \
398454b0306eSThomas Huth        $target_configs_h | sort -u > config-poison.h
398554b0306eSThomas Huthelse
398654b0306eSThomas Huth    :> config-poison.h
398754b0306eSThomas Huthfi
3988e0447a83SThomas Huth
3989dc655404SMichael S. Tsirkin# Save the configure command line for later reuse.
3990dc655404SMichael S. Tsirkincat <<EOD >config.status
3991dc655404SMichael S. Tsirkin#!/bin/sh
3992dc655404SMichael S. Tsirkin# Generated by configure.
3993dc655404SMichael S. Tsirkin# Run this file to recreate the current configuration.
3994dc655404SMichael S. Tsirkin# Compiler output produced by configure, useful for debugging
3995dc655404SMichael S. Tsirkin# configure, is in config.log if it exists.
3996dc655404SMichael S. TsirkinEOD
3997e811da7fSDaniel P. Berrangé
3998e811da7fSDaniel P. Berrangépreserve_env() {
3999e811da7fSDaniel P. Berrangé    envname=$1
4000e811da7fSDaniel P. Berrangé
4001e811da7fSDaniel P. Berrangé    eval envval=\$$envname
4002e811da7fSDaniel P. Berrangé
4003e811da7fSDaniel P. Berrangé    if test -n "$envval"
4004e811da7fSDaniel P. Berrangé    then
4005e811da7fSDaniel P. Berrangé	echo "$envname='$envval'" >> config.status
4006e811da7fSDaniel P. Berrangé	echo "export $envname" >> config.status
4007e811da7fSDaniel P. Berrangé    else
4008e811da7fSDaniel P. Berrangé	echo "unset $envname" >> config.status
4009e811da7fSDaniel P. Berrangé    fi
4010e811da7fSDaniel P. Berrangé}
4011e811da7fSDaniel P. Berrangé
4012e811da7fSDaniel P. Berrangé# Preserve various env variables that influence what
4013e811da7fSDaniel P. Berrangé# features/build target configure will detect
4014e811da7fSDaniel P. Berrangépreserve_env AR
4015e811da7fSDaniel P. Berrangépreserve_env AS
4016e811da7fSDaniel P. Berrangépreserve_env CC
4017e811da7fSDaniel P. Berrangépreserve_env CPP
40188009da03SPaolo Bonzinipreserve_env CFLAGS
4019e811da7fSDaniel P. Berrangépreserve_env CXX
40208009da03SPaolo Bonzinipreserve_env CXXFLAGS
4021e811da7fSDaniel P. Berrangépreserve_env INSTALL
4022e811da7fSDaniel P. Berrangépreserve_env LD
40238009da03SPaolo Bonzinipreserve_env LDFLAGS
4024e811da7fSDaniel P. Berrangépreserve_env LD_LIBRARY_PATH
4025e811da7fSDaniel P. Berrangépreserve_env LIBTOOL
4026e811da7fSDaniel P. Berrangépreserve_env MAKE
4027e811da7fSDaniel P. Berrangépreserve_env NM
4028e811da7fSDaniel P. Berrangépreserve_env OBJCOPY
4029e811da7fSDaniel P. Berrangépreserve_env PATH
4030e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG
4031e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_LIBDIR
4032e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_PATH
4033e811da7fSDaniel P. Berrangépreserve_env PYTHON
4034e811da7fSDaniel P. Berrangépreserve_env SDL2_CONFIG
4035e811da7fSDaniel P. Berrangépreserve_env SMBD
4036e811da7fSDaniel P. Berrangépreserve_env STRIP
4037e811da7fSDaniel P. Berrangépreserve_env WINDRES
4038e811da7fSDaniel P. Berrangé
4039dc655404SMichael S. Tsirkinprintf "exec" >>config.status
4040a5665051SPaolo Bonzinifor i in "$0" "$@"; do
4041835af899SPaolo Bonzini  test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
4042a5665051SPaolo Bonzinidone
4043cf7cc929SDr. David Alan Gilbertecho ' "$@"' >>config.status
4044dc655404SMichael S. Tsirkinchmod +x config.status
4045dc655404SMichael S. Tsirkin
40468cd05ab6SPeter Maydellrm -r "$TMPDIR1"
4047