xref: /openbmc/qemu/configure (revision e910c7d9)
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"
817d13299dSbellard
82da1d85e3SGerd Hoffmannrm -f config.log
839ac81bbbSmalc
84b48e3611SPeter Maydell# Print a helpful header at the top of config.log
85b48e3611SPeter Maydellecho "# QEMU configure log $(date)" >> config.log
86979ae168SPeter Maydellprintf "# Configured with:" >> config.log
87979ae168SPeter Maydellprintf " '%s'" "$0" "$@" >> config.log
88979ae168SPeter Maydellecho >> config.log
89b48e3611SPeter Maydellecho "#" >> config.log
90b48e3611SPeter Maydell
91835af899SPaolo Bonziniquote_sh() {
92835af899SPaolo Bonzini    printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
93835af899SPaolo Bonzini}
94835af899SPaolo Bonzini
95d880a3baSPaolo Bonziniprint_error() {
96d880a3baSPaolo Bonzini    (echo
9776ad07a4SPeter Maydell    echo "ERROR: $1"
9876ad07a4SPeter Maydell    while test -n "$2"; do
9976ad07a4SPeter Maydell        echo "       $2"
10076ad07a4SPeter Maydell        shift
10176ad07a4SPeter Maydell    done
102d880a3baSPaolo Bonzini    echo) >&2
103d880a3baSPaolo Bonzini}
104d880a3baSPaolo Bonzini
105d880a3baSPaolo Bonzinierror_exit() {
106d880a3baSPaolo Bonzini    print_error "$@"
10776ad07a4SPeter Maydell    exit 1
10876ad07a4SPeter Maydell}
10976ad07a4SPeter Maydell
1109c83ffd8SPeter Maydelldo_compiler() {
1119c83ffd8SPeter Maydell    # Run the compiler, capturing its output to the log. First argument
1129c83ffd8SPeter Maydell    # is compiler binary to execute.
113630d86b7SDavid CARLIER    compiler="$1"
1149c83ffd8SPeter Maydell    shift
1158bbe05d7SIan Jackson    if test -n "$BASH_VERSION"; then eval '
1168bbe05d7SIan Jackson        echo >>config.log "
1178bbe05d7SIan Jacksonfuncs: ${FUNCNAME[*]}
1188bbe05d7SIan Jacksonlines: ${BASH_LINENO[*]}"
1198bbe05d7SIan Jackson    '; fi
1209c83ffd8SPeter Maydell    echo $compiler "$@" >> config.log
1219c83ffd8SPeter Maydell    $compiler "$@" >> config.log 2>&1 || return $?
1228dc38a78SPeter Maydell    # Test passed. If this is an --enable-werror build, rerun
1238dc38a78SPeter Maydell    # the test with -Werror and bail out if it fails. This
1248dc38a78SPeter Maydell    # makes warning-generating-errors in configure test code
1258dc38a78SPeter Maydell    # obvious to developers.
1268dc38a78SPeter Maydell    if test "$werror" != "yes"; then
1278dc38a78SPeter Maydell        return 0
1288dc38a78SPeter Maydell    fi
1298dc38a78SPeter Maydell    # Don't bother rerunning the compile if we were already using -Werror
1308dc38a78SPeter Maydell    case "$*" in
1318dc38a78SPeter Maydell        *-Werror*)
1328dc38a78SPeter Maydell           return 0
1338dc38a78SPeter Maydell        ;;
1348dc38a78SPeter Maydell    esac
1359c83ffd8SPeter Maydell    echo $compiler -Werror "$@" >> config.log
1369c83ffd8SPeter Maydell    $compiler -Werror "$@" >> config.log 2>&1 && return $?
13776ad07a4SPeter Maydell    error_exit "configure test passed without -Werror but failed with -Werror." \
13876ad07a4SPeter Maydell        "This is probably a bug in the configure script. The failing command" \
13976ad07a4SPeter Maydell        "will be at the bottom of config.log." \
14076ad07a4SPeter Maydell        "You can run configure with --disable-werror to bypass this check."
1418dc38a78SPeter Maydell}
1428dc38a78SPeter Maydell
1439c83ffd8SPeter Maydelldo_cc() {
1444dba2789SPaolo Bonzini    do_compiler "$cc" $CPU_CFLAGS "$@"
1459c83ffd8SPeter Maydell}
1469c83ffd8SPeter Maydell
1479c83ffd8SPeter Maydelldo_cxx() {
1484dba2789SPaolo Bonzini    do_compiler "$cxx" $CPU_CFLAGS "$@"
1499c83ffd8SPeter Maydell}
1509c83ffd8SPeter Maydell
15100849b92SRichard Henderson# Append $2 to the variable named $1, with space separation
15200849b92SRichard Hendersonadd_to() {
15300849b92SRichard Henderson    eval $1=\${$1:+\"\$$1 \"}\$2
15400849b92SRichard Henderson}
15500849b92SRichard Henderson
1569c83ffd8SPeter Maydellupdate_cxxflags() {
1579c83ffd8SPeter Maydell    # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
1589c83ffd8SPeter Maydell    # options which some versions of GCC's C++ compiler complain about
1599c83ffd8SPeter Maydell    # because they only make sense for C programs.
160de38c0ccSPaolo Bonzini    QEMU_CXXFLAGS="-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
1618a9d3d56SRichard Henderson    CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
1629c83ffd8SPeter Maydell    for arg in $QEMU_CFLAGS; do
1639c83ffd8SPeter Maydell        case $arg in
1649c83ffd8SPeter Maydell            -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
1659c83ffd8SPeter Maydell            -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
1669c83ffd8SPeter Maydell                ;;
1679c83ffd8SPeter Maydell            *)
1689c83ffd8SPeter Maydell                QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
1699c83ffd8SPeter Maydell                ;;
1709c83ffd8SPeter Maydell        esac
1719c83ffd8SPeter Maydell    done
1729c83ffd8SPeter Maydell}
1739c83ffd8SPeter Maydell
17452166aa0SJuan Quintelacompile_object() {
175fd0e6053SJohn Snow  local_cflags="$1"
176a2866660SPaolo Bonzini  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
17752166aa0SJuan Quintela}
17852166aa0SJuan Quintela
17952166aa0SJuan Quintelacompile_prog() {
18052166aa0SJuan Quintela  local_cflags="$1"
18152166aa0SJuan Quintela  local_ldflags="$2"
182a2866660SPaolo Bonzini  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
183a2866660SPaolo Bonzini      $LDFLAGS $EXTRA_LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
18452166aa0SJuan Quintela}
18552166aa0SJuan Quintela
18611568d6dSPaolo Bonzini# symbolically link $1 to $2.  Portable version of "ln -sf".
18711568d6dSPaolo Bonzinisymlink() {
18872b8b5a1SStefan Weil  rm -rf "$2"
189ec5b06d7SAnthony Liguori  mkdir -p "$(dirname "$2")"
19072b8b5a1SStefan Weil  ln -s "$1" "$2"
19111568d6dSPaolo Bonzini}
19211568d6dSPaolo Bonzini
1930dba6195SLoïc Minier# check whether a command is available to this shell (may be either an
1940dba6195SLoïc Minier# executable or a builtin)
1950dba6195SLoïc Minierhas() {
1960dba6195SLoïc Minier    type "$1" >/dev/null 2>&1
1970dba6195SLoïc Minier}
1980dba6195SLoïc Minier
1990a01d76fSMarc-André Lureauversion_ge () {
2002df52b9bSAlex Bennée    local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
2012df52b9bSAlex Bennée    local_ver2=$(echo "$2" | tr . ' ')
2020a01d76fSMarc-André Lureau    while true; do
2030a01d76fSMarc-André Lureau        set x $local_ver1
2040a01d76fSMarc-André Lureau        local_first=${2-0}
205c44a33e2SStefano Garzarella        # 'shift 2' if $2 is set, or 'shift' if $2 is not set
206c44a33e2SStefano Garzarella        shift ${2:+2}
2070a01d76fSMarc-André Lureau        local_ver1=$*
2080a01d76fSMarc-André Lureau        set x $local_ver2
2090a01d76fSMarc-André Lureau        # the second argument finished, the first must be greater or equal
2100a01d76fSMarc-André Lureau        test $# = 1 && return 0
2110a01d76fSMarc-André Lureau        test $local_first -lt $2 && return 1
2120a01d76fSMarc-André Lureau        test $local_first -gt $2 && return 0
213c44a33e2SStefano Garzarella        shift ${2:+2}
2140a01d76fSMarc-André Lureau        local_ver2=$*
2150a01d76fSMarc-André Lureau    done
2160a01d76fSMarc-André Lureau}
2170a01d76fSMarc-André Lureau
2183b6b7550SPaolo Bonziniglob() {
2193b6b7550SPaolo Bonzini    eval test -z '"${1#'"$2"'}"'
2203b6b7550SPaolo Bonzini}
2213b6b7550SPaolo Bonzini
222e9a3591fSChristian Borntraegerld_has() {
223e9a3591fSChristian Borntraeger    $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
224e9a3591fSChristian Borntraeger}
225e9a3591fSChristian Borntraeger
2264ace32e2SAntonio Ospiteif printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
2274ace32e2SAntonio Ospitethen
2284ace32e2SAntonio Ospite  error_exit "main directory cannot contain spaces nor colons"
2294ace32e2SAntonio Ospitefi
2304ace32e2SAntonio Ospite
23114211825SAntonio Ospite# default parameters
2322ff6b91eSJuan Quintelacpu=""
233a31a8642SMichael S. Tsirkiniasl="iasl"
2341e43adfcSbellardinterp_prefix="/usr/gnemul/qemu-%M"
23543ce4dfeSbellardstatic="no"
2363812c0c4SJoelle van Dynecross_compile="no"
2377d13299dSbellardcross_prefix=""
23887430d5bSPaolo Bonziniaudio_drv_list="default"
239b64ec4e4SFam Zhengblock_drv_rw_whitelist=""
240b64ec4e4SFam Zhengblock_drv_ro_whitelist=""
241e49d021eSPeter Maydellhost_cc="cc"
2425bc62e01SGerd Hoffmanndebug_info="yes"
243cdad781dSDaniele Buonolto="false"
24463678e17SSteven Noonanstack_protector=""
2451e4f6065SDaniele Buonosafe_stack=""
246afc3a8f9SAlex Bennéeuse_containers="yes"
247f2385398SAlex Bennéegdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
248ac0df51dSaliguori
24992712822SDaniel P. Berrangeif test -e "$source_path/.git"
25092712822SDaniel P. Berrangethen
2517d7dbf9dSDan Streetman    git_submodules_action="update"
25292712822SDaniel P. Berrangeelse
2537d7dbf9dSDan Streetman    git_submodules_action="ignore"
25492712822SDaniel P. Berrangefi
2552d652f24SPaolo Bonzini
2562d652f24SPaolo Bonzinigit_submodules="ui/keycodemapdb"
257cc84d63aSDaniel P. Berrangegit="git"
258ac0df51dSaliguori
259afb63ebdSStefan Weil# Don't accept a target_list environment variable.
260afb63ebdSStefan Weilunset target_list
261447e133fSAlex Bennéeunset target_list_exclude
262377529c0SPaolo Bonzini
263377529c0SPaolo Bonzini# Default value for a variable defining feature "foo".
264377529c0SPaolo Bonzini#  * foo="no"  feature will only be used if --enable-foo arg is given
265377529c0SPaolo Bonzini#  * foo=""    feature will be searched for, and if found, will be used
266377529c0SPaolo Bonzini#              unless --disable-foo is given
267377529c0SPaolo Bonzini#  * foo="yes" this value will only be set by --enable-foo flag.
268377529c0SPaolo Bonzini#              feature will searched for,
269377529c0SPaolo Bonzini#              if not found, configure exits with error
270377529c0SPaolo Bonzini#
271377529c0SPaolo Bonzini# Always add --enable-foo and --disable-foo command line args.
272377529c0SPaolo Bonzini# Distributions want to ensure that several features are compiled in, and it
273377529c0SPaolo Bonzini# is impossible without a --enable-foo that exits if a feature is not found.
274377529c0SPaolo Bonzini
275c87ea116SAlex Bennéedefault_feature=""
276c87ea116SAlex Bennée# parse CC options second
277c87ea116SAlex Bennéefor opt do
278c87ea116SAlex Bennée  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
279c87ea116SAlex Bennée  case "$opt" in
280c87ea116SAlex Bennée      --without-default-features)
281c87ea116SAlex Bennée          default_feature="no"
282c87ea116SAlex Bennée  ;;
283c87ea116SAlex Bennée  esac
284c87ea116SAlex Bennéedone
285c87ea116SAlex Bennée
286a2866660SPaolo BonziniEXTRA_CFLAGS=""
287a2866660SPaolo BonziniEXTRA_CXXFLAGS=""
288*e910c7d9SPhilippe Mathieu-DaudéEXTRA_OBJCFLAGS=""
289a2866660SPaolo BonziniEXTRA_LDFLAGS=""
290a2866660SPaolo Bonzini
291c87ea116SAlex Bennéexen_ctrl_version="$default_feature"
2920848f8acSThomas Huthvhost_kernel="$default_feature"
293c87ea116SAlex Bennéevhost_net="$default_feature"
294c87ea116SAlex Bennéevhost_crypto="$default_feature"
295c87ea116SAlex Bennéevhost_scsi="$default_feature"
296c87ea116SAlex Bennéevhost_vsock="$default_feature"
297d88618f7SStefan Hajnoczivhost_user="no"
298c87ea116SAlex Bennéevhost_user_fs="$default_feature"
2990848f8acSThomas Huthvhost_vdpa="$default_feature"
300c87ea116SAlex Bennéerdma="$default_feature"
301c87ea116SAlex Bennéepvrdma="$default_feature"
302377529c0SPaolo Bonzinidebug_tcg="no"
303377529c0SPaolo Bonzinidebug="no"
304247724cbSMarc-André Lureausanitizers="no"
3050aebab04SLingfeng Yangtsan="no"
306c87ea116SAlex Bennéefortify_source="$default_feature"
3071d728c39SBlue Swirlgcov="no"
308c7328271SMiroslav RezaninaEXESUF=""
30917969268SFam Zhengmodules="no"
310bd83c861SChristian Ehrhardtmodule_upgrades="no"
311377529c0SPaolo Bonziniprefix="/usr/local"
31210ff82d1SMarc-André Lureauqemu_suffix="qemu"
313377529c0SPaolo Bonzinisoftmmu="yes"
314b915a2f1SPaolo Bonzinilinux_user=""
315b915a2f1SPaolo Bonzinibsd_user=""
316377529c0SPaolo Bonzinipkgversion=""
31740d6444eSAvi Kivitypie=""
318baf86d6bSPaolo Bonzinitrace_backends="log"
319377529c0SPaolo Bonzinitrace_file="trace"
320c87ea116SAlex Bennéeopengl="$default_feature"
321519175a2SAlex Barcelocoroutine=""
322a1c5e949SDaniel P. Berrangetls_priority="NORMAL"
323ba4dd2aaSAlex Bennéeplugins="$default_feature"
324c87ea116SAlex Bennéesecret_keyring="$default_feature"
325a5665051SPaolo Bonzinimeson=""
3263b4da132SPaolo Bonzinimeson_args=""
32748328880SPaolo Bonzinininja=""
3283b4da132SPaolo Bonzinigio="$default_feature"
329a5665051SPaolo Bonziniskip_meson=no
330377529c0SPaolo Bonzini
3313b4da132SPaolo Bonzini# The following Meson options are handled manually (still they
3323b4da132SPaolo Bonzini# are included in the automatically generated help message)
3333b4da132SPaolo Bonzini
3343b4da132SPaolo Bonzini# 1. Track which submodules are needed
3350577e84dSThomas Huthif test "$default_feature" = no ; then
3360577e84dSThomas Huth  capstone="disabled"
3370577e84dSThomas Huth  slirp="disabled"
3380577e84dSThomas Huthelse
3393b4da132SPaolo Bonzini  capstone="auto"
3403b4da132SPaolo Bonzini  slirp="auto"
3410577e84dSThomas Huthfi
3420577e84dSThomas Huthfdt="auto"
3433b4da132SPaolo Bonzini
3443b4da132SPaolo Bonzini# 2. Support --with/--without option
3453b4da132SPaolo Bonzinidefault_devices="true"
3463b4da132SPaolo Bonzini
3473b4da132SPaolo Bonzini# 3. Automatically enable/disable other options
3483b4da132SPaolo Bonzinitcg="enabled"
3493b4da132SPaolo Bonzinicfi="false"
3503b4da132SPaolo Bonzini
3513b4da132SPaolo Bonzini# 4. Detection partly done in configure
3523b4da132SPaolo Bonzinixen=${default_feature:+disabled}
353898be3e0SPeter Maydell
354c87ea116SAlex Bennée# parse CC options second
355ac0df51dSaliguorifor opt do
35689138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
357ac0df51dSaliguori  case "$opt" in
358ac0df51dSaliguori  --cross-prefix=*) cross_prefix="$optarg"
3593812c0c4SJoelle van Dyne                    cross_compile="yes"
360ac0df51dSaliguori  ;;
3613d8df640SPaolo Bonzini  --cc=*) CC="$optarg"
362ac0df51dSaliguori  ;;
36383f73fceSTomoki Sekiyama  --cxx=*) CXX="$optarg"
36483f73fceSTomoki Sekiyama  ;;
3652ff6b91eSJuan Quintela  --cpu=*) cpu="$optarg"
3662ff6b91eSJuan Quintela  ;;
367a2866660SPaolo Bonzini  --extra-cflags=*)
368a2866660SPaolo Bonzini    EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
369a2866660SPaolo Bonzini    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
370*e910c7d9SPhilippe Mathieu-Daudé    EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
371e2a2ed06SJuan Quintela    ;;
372a2866660SPaolo Bonzini  --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
37311cde1c8SBruno Dominguez  ;;
374*e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
375*e910c7d9SPhilippe Mathieu-Daudé  ;;
376a2866660SPaolo Bonzini  --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
377e2a2ed06SJuan Quintela  ;;
3785bc62e01SGerd Hoffmann  --enable-debug-info) debug_info="yes"
3795bc62e01SGerd Hoffmann  ;;
3805bc62e01SGerd Hoffmann  --disable-debug-info) debug_info="no"
3815bc62e01SGerd Hoffmann  ;;
382d75402b5SAlex Bennée  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
383d75402b5SAlex Bennée  ;;
384479ca4ccSMatheus Ferst  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
385d422b2bcSAlex Bennée                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
3862038f8c8SPaolo Bonzini                      cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
387d422b2bcSAlex Bennée  ;;
388d75402b5SAlex Bennée  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
3892038f8c8SPaolo Bonzini                cc_archs="$cc_archs $cc_arch"
390d75402b5SAlex Bennée                eval "cross_cc_${cc_arch}=\$optarg"
3912038f8c8SPaolo Bonzini                cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
392d75402b5SAlex Bennée  ;;
393ac0df51dSaliguori  esac
394ac0df51dSaliguoridone
395ac0df51dSaliguori# OS specific
396ac0df51dSaliguori# Using uname is really, really broken.  Once we have the right set of checks
39793148aa5SStefan Weil# we can eliminate its usage altogether.
398ac0df51dSaliguori
399e49d021eSPeter Maydell# Preferred compiler:
400e49d021eSPeter Maydell#  ${CC} (if set)
401e49d021eSPeter Maydell#  ${cross_prefix}gcc (if cross-prefix specified)
402e49d021eSPeter Maydell#  system compiler
403e49d021eSPeter Maydellif test -z "${CC}${cross_prefix}"; then
404e49d021eSPeter Maydell  cc="$host_cc"
405e49d021eSPeter Maydellelse
406b3198cc2SStuart Yoder  cc="${CC-${cross_prefix}gcc}"
407e49d021eSPeter Maydellfi
408e49d021eSPeter Maydell
40983f73fceSTomoki Sekiyamaif test -z "${CXX}${cross_prefix}"; then
41083f73fceSTomoki Sekiyama  cxx="c++"
41183f73fceSTomoki Sekiyamaelse
41283f73fceSTomoki Sekiyama  cxx="${CXX-${cross_prefix}g++}"
41383f73fceSTomoki Sekiyamafi
41483f73fceSTomoki Sekiyama
415b3198cc2SStuart Yoderar="${AR-${cross_prefix}ar}"
416cdbd727cSRichard Hendersonas="${AS-${cross_prefix}as}"
4175f6f0e27SRichard Hendersonccas="${CCAS-$cc}"
4183dd46c78SBlue Swirlcpp="${CPP-$cc -E}"
419b3198cc2SStuart Yoderobjcopy="${OBJCOPY-${cross_prefix}objcopy}"
420b3198cc2SStuart Yoderld="${LD-${cross_prefix}ld}"
4219f81aeb5SAlistair Francisranlib="${RANLIB-${cross_prefix}ranlib}"
4224852ee95SStefan Weilnm="${NM-${cross_prefix}nm}"
42335acbb30SPaolo Bonzinismbd="$SMBD"
424b3198cc2SStuart Yoderstrip="${STRIP-${cross_prefix}strip}"
425b3198cc2SStuart Yoderwindres="${WINDRES-${cross_prefix}windres}"
42617884d7bSSergei Trofimovichpkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
42717884d7bSSergei Trofimovichquery_pkg_config() {
42817884d7bSSergei Trofimovich    "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
42917884d7bSSergei Trofimovich}
43017884d7bSSergei Trofimovichpkg_config=query_pkg_config
43147c03744SDave Airliesdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
432ac0df51dSaliguori
433be17dc90SMichael S. Tsirkin# default flags for all hosts
4342d31515bSPeter Maydell# We use -fwrapv to tell the compiler that we require a C dialect where
4352d31515bSPeter Maydell# left shift of signed integers is well defined and has the expected
4362d31515bSPeter Maydell# 2s-complement style results. (Both clang and gcc agree that it
4372d31515bSPeter Maydell# provides these semantics.)
438de38c0ccSPaolo BonziniQEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
439086d5f75SPaolo BonziniQEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
440c95e3080SKevin WolfQEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
441be17dc90SMichael S. TsirkinQEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
4425770e8afSPaolo Bonzini
443de38c0ccSPaolo BonziniQEMU_LDFLAGS=
444de38c0ccSPaolo Bonzini
4455770e8afSPaolo Bonzini# Flags that are needed during configure but later taken care of by Meson
4468a9d3d56SRichard HendersonCONFIGURE_CFLAGS="-std=gnu11 -Wall"
4475770e8afSPaolo BonziniCONFIGURE_LDFLAGS=
448086d5f75SPaolo Bonzini
449be17dc90SMichael S. Tsirkin
450ac0df51dSaliguoricheck_define() {
451ac0df51dSaliguoricat > $TMPC <<EOF
452ac0df51dSaliguori#if !defined($1)
453fd786e1aSPeter Maydell#error $1 not defined
454ac0df51dSaliguori#endif
455ac0df51dSaliguoriint main(void) { return 0; }
456ac0df51dSaliguoriEOF
45752166aa0SJuan Quintela  compile_object
458ac0df51dSaliguori}
459ac0df51dSaliguori
460307119e7SGerd Hoffmanncheck_include() {
461307119e7SGerd Hoffmanncat > $TMPC <<EOF
462307119e7SGerd Hoffmann#include <$1>
463307119e7SGerd Hoffmannint main(void) { return 0; }
464307119e7SGerd HoffmannEOF
465307119e7SGerd Hoffmann  compile_object
466307119e7SGerd Hoffmann}
467307119e7SGerd Hoffmann
46893b25869SJohn Snowwrite_c_skeleton() {
46993b25869SJohn Snow    cat > $TMPC <<EOF
47093b25869SJohn Snowint main(void) { return 0; }
47193b25869SJohn SnowEOF
47293b25869SJohn Snow}
47393b25869SJohn Snow
474bbea4050SPeter Maydellif check_define __linux__ ; then
475ba7c60c2SPaolo Bonzini  targetos=linux
476bbea4050SPeter Maydellelif check_define _WIN32 ; then
477ba7c60c2SPaolo Bonzini  targetos=windows
478bbea4050SPeter Maydellelif check_define __OpenBSD__ ; then
479ba7c60c2SPaolo Bonzini  targetos=openbsd
480bbea4050SPeter Maydellelif check_define __sun__ ; then
481ba7c60c2SPaolo Bonzini  targetos=sunos
482bbea4050SPeter Maydellelif check_define __HAIKU__ ; then
483ba7c60c2SPaolo Bonzini  targetos=haiku
484951fedfcSPeter Maydellelif check_define __FreeBSD__ ; then
485ba7c60c2SPaolo Bonzini  targetos=freebsd
486951fedfcSPeter Maydellelif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
487ba7c60c2SPaolo Bonzini  targetos=gnu/kfreebsd
488951fedfcSPeter Maydellelif check_define __DragonFly__ ; then
489ba7c60c2SPaolo Bonzini  targetos=dragonfly
490951fedfcSPeter Maydellelif check_define __NetBSD__; then
491ba7c60c2SPaolo Bonzini  targetos=netbsd
492951fedfcSPeter Maydellelif check_define __APPLE__; then
493ba7c60c2SPaolo Bonzini  targetos=darwin
494bbea4050SPeter Maydellelse
495951fedfcSPeter Maydell  # This is a fatal error, but don't report it yet, because we
496951fedfcSPeter Maydell  # might be going to just print the --help text, or it might
497951fedfcSPeter Maydell  # be the result of a missing compiler.
498ba7c60c2SPaolo Bonzini  targetos=bogus
499bbea4050SPeter Maydellfi
500bbea4050SPeter Maydell
50165eff01bSPaolo Bonzini# OS specific
50265eff01bSPaolo Bonzini
5033b0d8643SPaolo Bonzinimingw32="no"
5043b0d8643SPaolo Bonzinibsd="no"
5053b0d8643SPaolo Bonzinilinux="no"
5063b0d8643SPaolo Bonzinisolaris="no"
50765eff01bSPaolo Bonzinicase $targetos in
50865eff01bSPaolo Bonziniwindows)
50965eff01bSPaolo Bonzini  mingw32="yes"
51065eff01bSPaolo Bonzini  plugins="no"
51165eff01bSPaolo Bonzini  pie="no"
51265eff01bSPaolo Bonzini;;
51365eff01bSPaolo Bonzinignu/kfreebsd)
51465eff01bSPaolo Bonzini  bsd="yes"
51565eff01bSPaolo Bonzini;;
51665eff01bSPaolo Bonzinifreebsd)
51765eff01bSPaolo Bonzini  bsd="yes"
51865eff01bSPaolo Bonzini  make="${MAKE-gmake}"
51965eff01bSPaolo Bonzini  # needed for kinfo_getvmmap(3) in libutil.h
52065eff01bSPaolo Bonzini;;
52165eff01bSPaolo Bonzinidragonfly)
52265eff01bSPaolo Bonzini  bsd="yes"
52365eff01bSPaolo Bonzini  make="${MAKE-gmake}"
52465eff01bSPaolo Bonzini;;
52565eff01bSPaolo Bonzininetbsd)
52665eff01bSPaolo Bonzini  bsd="yes"
52765eff01bSPaolo Bonzini  make="${MAKE-gmake}"
52865eff01bSPaolo Bonzini;;
52965eff01bSPaolo Bonziniopenbsd)
53065eff01bSPaolo Bonzini  bsd="yes"
53165eff01bSPaolo Bonzini  make="${MAKE-gmake}"
53265eff01bSPaolo Bonzini;;
53365eff01bSPaolo Bonzinidarwin)
53465eff01bSPaolo Bonzini  bsd="yes"
53565eff01bSPaolo Bonzini  darwin="yes"
53665eff01bSPaolo Bonzini  # Disable attempts to use ObjectiveC features in os/object.h since they
53765eff01bSPaolo Bonzini  # won't work when we're compiling with gcc as a C compiler.
53865eff01bSPaolo Bonzini  QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
53965eff01bSPaolo Bonzini;;
54065eff01bSPaolo Bonzinisunos)
54165eff01bSPaolo Bonzini  solaris="yes"
54265eff01bSPaolo Bonzini  make="${MAKE-gmake}"
54365eff01bSPaolo Bonzini# needed for CMSG_ macros in sys/socket.h
54465eff01bSPaolo Bonzini  QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
54565eff01bSPaolo Bonzini# needed for TIOCWIN* defines in termios.h
54665eff01bSPaolo Bonzini  QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
54765eff01bSPaolo Bonzini  # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
54865eff01bSPaolo Bonzini  # Note that this check is broken for cross-compilation: if you're
549bbea4050SPeter Maydell  # cross-compiling to one of these OSes then you'll need to specify
550bbea4050SPeter Maydell  # the correct CPU with the --cpu option.
551bbea4050SPeter Maydell  if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
552bbea4050SPeter Maydell    cpu="x86_64"
553bbea4050SPeter Maydell  fi
55465eff01bSPaolo Bonzini;;
55565eff01bSPaolo Bonzinihaiku)
55665eff01bSPaolo Bonzini  pie="no"
55765eff01bSPaolo Bonzini  QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
55865eff01bSPaolo Bonzini;;
55965eff01bSPaolo Bonzinilinux)
56065eff01bSPaolo Bonzini  linux="yes"
56165eff01bSPaolo Bonzini  vhost_user=${default_feature:-yes}
56265eff01bSPaolo Bonzini;;
563bbea4050SPeter Maydellesac
564bbea4050SPeter Maydell
5652ff6b91eSJuan Quintelaif test ! -z "$cpu" ; then
5662ff6b91eSJuan Quintela  # command line argument
5672ff6b91eSJuan Quintela  :
5682ff6b91eSJuan Quintelaelif check_define __i386__ ; then
569ac0df51dSaliguori  cpu="i386"
570ac0df51dSaliguorielif check_define __x86_64__ ; then
571c72b26ecSRichard Henderson  if check_define __ILP32__ ; then
572c72b26ecSRichard Henderson    cpu="x32"
573c72b26ecSRichard Henderson  else
574ac0df51dSaliguori    cpu="x86_64"
575c72b26ecSRichard Henderson  fi
5763aa9bd6cSblueswir1elif check_define __sparc__ ; then
5773aa9bd6cSblueswir1  if check_define __arch64__ ; then
5783aa9bd6cSblueswir1    cpu="sparc64"
5793aa9bd6cSblueswir1  else
5803aa9bd6cSblueswir1    cpu="sparc"
5813aa9bd6cSblueswir1  fi
582fdf7ed96Smalcelif check_define _ARCH_PPC ; then
583fdf7ed96Smalc  if check_define _ARCH_PPC64 ; then
584f8378accSRichard Henderson    if check_define _LITTLE_ENDIAN ; then
585f8378accSRichard Henderson      cpu="ppc64le"
586f8378accSRichard Henderson    else
587fdf7ed96Smalc      cpu="ppc64"
588f8378accSRichard Henderson    fi
589ac0df51dSaliguori  else
590fdf7ed96Smalc    cpu="ppc"
591fdf7ed96Smalc  fi
592afa05235SAurelien Jarnoelif check_define __mips__ ; then
593afa05235SAurelien Jarno  cpu="mips"
594d66ed0eaSAurelien Jarnoelif check_define __s390__ ; then
595d66ed0eaSAurelien Jarno  if check_define __s390x__ ; then
596d66ed0eaSAurelien Jarno    cpu="s390x"
597d66ed0eaSAurelien Jarno  else
598d66ed0eaSAurelien Jarno    cpu="s390"
599d66ed0eaSAurelien Jarno  fi
600c4f80543SAlistair Franciselif check_define __riscv ; then
601ba0e7333SRichard Henderson  cpu="riscv"
60221d89f84SPeter Maydellelif check_define __arm__ ; then
60321d89f84SPeter Maydell  cpu="arm"
6041f080313SClaudio Fontanaelif check_define __aarch64__ ; then
6051f080313SClaudio Fontana  cpu="aarch64"
606dfcf900bSWANG Xueruielif check_define __loongarch64 ; then
607dfcf900bSWANG Xuerui  cpu="loongarch64"
608fdf7ed96Smalcelse
60989138857SStefan Weil  cpu=$(uname -m)
610ac0df51dSaliguorifi
611ac0df51dSaliguori
612823eb013SPaolo Bonzini# Normalise host CPU name, set multilib cflags
613359bc95dSPeter Maydell# Note that this case should only have supported host CPUs, not guests.
6147d13299dSbellardcase "$cpu" in
615e4da0e39SPaolo Bonzini  armv*b|armv*l|arm)
616e4da0e39SPaolo Bonzini    cpu="arm" ;;
617e4da0e39SPaolo Bonzini
6187d13299dSbellard  i386|i486|i586|i686|i86pc|BePC)
61997a847bcSbellard    cpu="i386"
620e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32" ;;
621e4da0e39SPaolo Bonzini  x32)
6224da270beSPaolo Bonzini    cpu="x86_64"
623e4da0e39SPaolo Bonzini    CPU_CFLAGS="-mx32" ;;
624aaa5fa14Saurel32  x86_64|amd64)
625aaa5fa14Saurel32    cpu="x86_64"
626e4da0e39SPaolo Bonzini    # ??? Only extremely old AMD cpus do not have cmpxchg16b.
627e4da0e39SPaolo Bonzini    # If we truly care, we should simply detect this case at
628e4da0e39SPaolo Bonzini    # runtime and generate the fallback to serial emulation.
629e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64 -mcx16" ;;
630e4da0e39SPaolo Bonzini
631afa05235SAurelien Jarno  mips*)
632e4da0e39SPaolo Bonzini    cpu="mips" ;;
633e4da0e39SPaolo Bonzini
634e4da0e39SPaolo Bonzini  ppc)
635e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32" ;;
636e4da0e39SPaolo Bonzini  ppc64)
637ced5cfffSMiroslav Rezanina    CPU_CFLAGS="-m64 -mbig-endian" ;;
638e4da0e39SPaolo Bonzini  ppc64le)
639d8ff892dSPaolo Bonzini    cpu="ppc64"
640ced5cfffSMiroslav Rezanina    CPU_CFLAGS="-m64 -mlittle-endian" ;;
641e4da0e39SPaolo Bonzini
642e4da0e39SPaolo Bonzini  s390)
643823eb013SPaolo Bonzini    CPU_CFLAGS="-m31" ;;
644e4da0e39SPaolo Bonzini  s390x)
645e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64" ;;
646e4da0e39SPaolo Bonzini
6473142255cSblueswir1  sparc|sun4[cdmuv])
648ae228531Sbellard    cpu="sparc"
649e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
650e4da0e39SPaolo Bonzini  sparc64)
651e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
6527d13299dSbellardesac
653e2d52ad3SJuan Quintela
6540db4a067SPaolo Bonzini: ${make=${MAKE-make}}
655b6daf4d3SPaolo Bonzini
656faf44142SDaniel P. Berrangé# We prefer python 3.x. A bare 'python' is traditionally
657faf44142SDaniel P. Berrangé# python 2.x, but some distros have it as python 3.x, so
658ddf90699SEduardo Habkost# we check that too
659faf44142SDaniel P. Berrangépython=
6600a01d76fSMarc-André Lureauexplicit_python=no
661ddf90699SEduardo Habkostfor binary in "${PYTHON-python3}" python
662faf44142SDaniel P. Berrangédo
663faf44142SDaniel P. Berrangé    if has "$binary"
664faf44142SDaniel P. Berrangé    then
66595c5f2deSPaolo Bonzini        python=$(command -v "$binary")
666faf44142SDaniel P. Berrangé        break
667faf44142SDaniel P. Berrangé    fi
668faf44142SDaniel P. Berrangédone
669903458c8SMarkus Armbruster
670903458c8SMarkus Armbruster
67139d87c8cSAlex Bennée# Check for ancillary tools used in testing
67239d87c8cSAlex Bennéegenisoimage=
6733df437c7SAlex Bennéefor binary in genisoimage mkisofs
67439d87c8cSAlex Bennéedo
67539d87c8cSAlex Bennée    if has $binary
67639d87c8cSAlex Bennée    then
67739d87c8cSAlex Bennée        genisoimage=$(command -v "$binary")
67839d87c8cSAlex Bennée        break
67939d87c8cSAlex Bennée    fi
68039d87c8cSAlex Bennéedone
68139d87c8cSAlex Bennée
6823c4a4d0dSPeter Maydell# Default objcc to clang if available, otherwise use CC
6833c4a4d0dSPeter Maydellif has clang; then
6843c4a4d0dSPeter Maydell  objcc=clang
6853c4a4d0dSPeter Maydellelse
6863c4a4d0dSPeter Maydell  objcc="$cc"
6873c4a4d0dSPeter Maydellfi
6883c4a4d0dSPeter Maydell
6893457a3f8SJuan Quintelaif test "$mingw32" = "yes" ; then
6903457a3f8SJuan Quintela  EXESUF=".exe"
69178e9d4adSStefan Weil  # MinGW needs -mthreads for TLS and macro _MT.
6925770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
69393b25869SJohn Snow  write_c_skeleton;
694d17f305aSPaolo Bonzini  prefix="/qemu"
69577433a5fSMarc-André Lureau  qemu_suffix=""
6963457a3f8SJuan Quintelafi
6973457a3f8SJuan Quintela
698487fefdbSAnthony Liguoriwerror=""
69985aa5189Sbellard
70061d63097SPaolo Bonzini. $source_path/scripts/meson-buildoptions.sh
70161d63097SPaolo Bonzini
70261d63097SPaolo Bonzinimeson_options=
70361d63097SPaolo Bonzinimeson_option_parse() {
70461d63097SPaolo Bonzini  meson_options="$meson_options $(_meson_option_parse "$@")"
70561d63097SPaolo Bonzini  if test $? -eq 1; then
70661d63097SPaolo Bonzini    echo "ERROR: unknown option $1"
70761d63097SPaolo Bonzini    echo "Try '$0 --help' for more information"
70861d63097SPaolo Bonzini    exit 1
70961d63097SPaolo Bonzini  fi
71061d63097SPaolo Bonzini}
71161d63097SPaolo Bonzini
7127d13299dSbellardfor opt do
71389138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
7147d13299dSbellard  case "$opt" in
7152efc3265Sbellard  --help|-h) show_help=yes
7162efc3265Sbellard  ;;
71799123e13SMike Frysinger  --version|-V) exec cat $source_path/VERSION
71899123e13SMike Frysinger  ;;
719b1a550a0Spbrook  --prefix=*) prefix="$optarg"
7207d13299dSbellard  ;;
721b1a550a0Spbrook  --interp-prefix=*) interp_prefix="$optarg"
72232ce6337Sbellard  ;;
723ac0df51dSaliguori  --cross-prefix=*)
7247d13299dSbellard  ;;
725ac0df51dSaliguori  --cc=*)
7267d13299dSbellard  ;;
727b1a550a0Spbrook  --host-cc=*) host_cc="$optarg"
72883469015Sbellard  ;;
72983f73fceSTomoki Sekiyama  --cxx=*)
73083f73fceSTomoki Sekiyama  ;;
731e007dbecSMichael S. Tsirkin  --iasl=*) iasl="$optarg"
732e007dbecSMichael S. Tsirkin  ;;
7333c4a4d0dSPeter Maydell  --objcc=*) objcc="$optarg"
7343c4a4d0dSPeter Maydell  ;;
735b1a550a0Spbrook  --make=*) make="$optarg"
7367d13299dSbellard  ;;
737b6daf4d3SPaolo Bonzini  --install=*)
7386a882643Spbrook  ;;
7390a01d76fSMarc-André Lureau  --python=*) python="$optarg" ; explicit_python=yes
740c886edfbSBlue Swirl  ;;
7412eb054c2SPeter Maydell  --sphinx-build=*) sphinx_build="$optarg"
7422eb054c2SPeter Maydell  ;;
743a5665051SPaolo Bonzini  --skip-meson) skip_meson=yes
744a5665051SPaolo Bonzini  ;;
745a5665051SPaolo Bonzini  --meson=*) meson="$optarg"
746a5665051SPaolo Bonzini  ;;
74748328880SPaolo Bonzini  --ninja=*) ninja="$optarg"
74848328880SPaolo Bonzini  ;;
749e2d8830eSBrad  --smbd=*) smbd="$optarg"
750e2d8830eSBrad  ;;
751e2a2ed06SJuan Quintela  --extra-cflags=*)
7527d13299dSbellard  ;;
75311cde1c8SBruno Dominguez  --extra-cxxflags=*)
75411cde1c8SBruno Dominguez  ;;
755*e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=*)
756*e910c7d9SPhilippe Mathieu-Daudé  ;;
757e2a2ed06SJuan Quintela  --extra-ldflags=*)
7587d13299dSbellard  ;;
7595bc62e01SGerd Hoffmann  --enable-debug-info)
7605bc62e01SGerd Hoffmann  ;;
7615bc62e01SGerd Hoffmann  --disable-debug-info)
7625bc62e01SGerd Hoffmann  ;;
763d75402b5SAlex Bennée  --cross-cc-*)
764d75402b5SAlex Bennée  ;;
76517969268SFam Zheng  --enable-modules)
76617969268SFam Zheng      modules="yes"
76717969268SFam Zheng  ;;
7683aa88b31SStefan Hajnoczi  --disable-modules)
7693aa88b31SStefan Hajnoczi      modules="no"
7703aa88b31SStefan Hajnoczi  ;;
771bd83c861SChristian Ehrhardt  --disable-module-upgrades) module_upgrades="no"
772bd83c861SChristian Ehrhardt  ;;
773bd83c861SChristian Ehrhardt  --enable-module-upgrades) module_upgrades="yes"
774bd83c861SChristian Ehrhardt  ;;
7752ff6b91eSJuan Quintela  --cpu=*)
7767d13299dSbellard  ;;
777b1a550a0Spbrook  --target-list=*) target_list="$optarg"
778447e133fSAlex Bennée                   if test "$target_list_exclude"; then
779447e133fSAlex Bennée                       error_exit "Can't mix --target-list with --target-list-exclude"
780447e133fSAlex Bennée                   fi
781447e133fSAlex Bennée  ;;
782447e133fSAlex Bennée  --target-list-exclude=*) target_list_exclude="$optarg"
783447e133fSAlex Bennée                   if test "$target_list"; then
784447e133fSAlex Bennée                       error_exit "Can't mix --target-list-exclude with --target-list"
785447e133fSAlex Bennée                   fi
786de83cd02Sbellard  ;;
78774242e0fSPaolo Bonzini  --with-trace-file=*) trace_file="$optarg"
7889410b56cSPrerna Saxena  ;;
7897bc3ca7fSPaolo Bonzini  --with-default-devices) default_devices="true"
790f3494749SPaolo Bonzini  ;;
7917bc3ca7fSPaolo Bonzini  --without-default-devices) default_devices="false"
792f3494749SPaolo Bonzini  ;;
793d1d5e9eeSAlex Bennée  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
794d1d5e9eeSAlex Bennée  ;;
795d1d5e9eeSAlex Bennée  --with-devices-*) device_arch=${opt#--with-devices-};
796d1d5e9eeSAlex Bennée                    device_arch=${device_arch%%=*}
797d1d5e9eeSAlex Bennée                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
798d1d5e9eeSAlex Bennée                    if test -f "$cf"; then
799d1d5e9eeSAlex Bennée                        device_archs="$device_archs $device_arch"
800d1d5e9eeSAlex Bennée                        eval "devices_${device_arch}=\$optarg"
801d1d5e9eeSAlex Bennée                    else
802d1d5e9eeSAlex Bennée                        error_exit "File $cf does not exist"
803d1d5e9eeSAlex Bennée                    fi
804d1d5e9eeSAlex Bennée  ;;
805c87ea116SAlex Bennée  --without-default-features) # processed above
806c87ea116SAlex Bennée  ;;
8071d728c39SBlue Swirl  --enable-gcov) gcov="yes"
8081d728c39SBlue Swirl  ;;
80979427693SLoïc Minier  --static)
81079427693SLoïc Minier    static="yes"
81117884d7bSSergei Trofimovich    QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
81243ce4dfeSbellard  ;;
8130b24e75fSPaolo Bonzini  --mandir=*) mandir="$optarg"
8140b24e75fSPaolo Bonzini  ;;
8150b24e75fSPaolo Bonzini  --bindir=*) bindir="$optarg"
8160b24e75fSPaolo Bonzini  ;;
8173aa5d2beSAlon Levy  --libdir=*) libdir="$optarg"
8183aa5d2beSAlon Levy  ;;
8198bf188aaSMichael Tokarev  --libexecdir=*) libexecdir="$optarg"
8208bf188aaSMichael Tokarev  ;;
8210f94d6daSAlon Levy  --includedir=*) includedir="$optarg"
8220f94d6daSAlon Levy  ;;
823528ae5b8SEduardo Habkost  --datadir=*) datadir="$optarg"
8240b24e75fSPaolo Bonzini  ;;
82577433a5fSMarc-André Lureau  --with-suffix=*) qemu_suffix="$optarg"
826023d3d67SEduardo Habkost  ;;
827c6502638SBruce Rogers  --docdir=*) docdir="$optarg"
8280b24e75fSPaolo Bonzini  ;;
829fe0038beSPaolo Bonzini  --localedir=*) localedir="$optarg"
830fe0038beSPaolo Bonzini  ;;
831ca2fb938SAndre Przywara  --sysconfdir=*) sysconfdir="$optarg"
83207381cc1SAnthony Liguori  ;;
833785c23aeSLuiz Capitulino  --localstatedir=*) local_statedir="$optarg"
834785c23aeSLuiz Capitulino  ;;
8353d5eecabSGerd Hoffmann  --firmwarepath=*) firmwarepath="$optarg"
8363d5eecabSGerd Hoffmann  ;;
837181ce1d0SOlaf Hering  --host=*|--build=*|\
838181ce1d0SOlaf Hering  --disable-dependency-tracking|\
839785c23aeSLuiz Capitulino  --sbindir=*|--sharedstatedir=*|\
840fe0038beSPaolo Bonzini  --oldincludedir=*|--datarootdir=*|--infodir=*|\
841023ddd74SMax Filippov  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
842023ddd74SMax Filippov    # These switches are silently ignored, for compatibility with
843023ddd74SMax Filippov    # autoconf-generated configure scripts. This allows QEMU's
844023ddd74SMax Filippov    # configure to be used by RPM and similar macros that set
845023ddd74SMax Filippov    # lots of directory switches by default.
846023ddd74SMax Filippov  ;;
8470c58ac1cSmalc  --audio-drv-list=*) audio_drv_list="$optarg"
8480c58ac1cSmalc  ;;
84989138857SStefan Weil  --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
850b64ec4e4SFam Zheng  ;;
85189138857SStefan Weil  --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
852eb852011SMarkus Armbruster  ;;
853f8393946Saurel32  --enable-debug-tcg) debug_tcg="yes"
854f8393946Saurel32  ;;
855f8393946Saurel32  --disable-debug-tcg) debug_tcg="no"
856f8393946Saurel32  ;;
857f3d08ee6SPaul Brook  --enable-debug)
858f3d08ee6SPaul Brook      # Enable debugging options that aren't excessively noisy
859f3d08ee6SPaul Brook      debug_tcg="yes"
860c55cf6abSPaolo Bonzini      meson_option_parse --enable-debug-mutex ""
861f3d08ee6SPaul Brook      debug="yes"
862b553a042SJohn Snow      fortify_source="no"
863f3d08ee6SPaul Brook  ;;
864247724cbSMarc-André Lureau  --enable-sanitizers) sanitizers="yes"
865247724cbSMarc-André Lureau  ;;
866247724cbSMarc-André Lureau  --disable-sanitizers) sanitizers="no"
867247724cbSMarc-André Lureau  ;;
8680aebab04SLingfeng Yang  --enable-tsan) tsan="yes"
8690aebab04SLingfeng Yang  ;;
8700aebab04SLingfeng Yang  --disable-tsan) tsan="no"
8710aebab04SLingfeng Yang  ;;
8724d34a86bSPaolo Bonzini  --disable-slirp) slirp="disabled"
873c20709aaSbellard  ;;
874fd6fc214SPaolo Bonzini  --enable-slirp) slirp="enabled"
875fd6fc214SPaolo Bonzini  ;;
8764d34a86bSPaolo Bonzini  --enable-slirp=git) slirp="internal"
8777c57bdd8SMarc-André Lureau  ;;
87803a3c0b3SPaolo Bonzini  --enable-slirp=*) slirp="$optarg"
879675b9b53SMarc-André Lureau  ;;
8801badb709SPaolo Bonzini  --disable-xen) xen="disabled"
881e37630caSaliguori  ;;
8821badb709SPaolo Bonzini  --enable-xen) xen="enabled"
883fc321b4bSJuan Quintela  ;;
8841badb709SPaolo Bonzini  --disable-tcg) tcg="disabled"
885d1a14257SAlex Bennée                 plugins="no"
886b3f6ea7eSPaolo Bonzini  ;;
8871badb709SPaolo Bonzini  --enable-tcg) tcg="enabled"
888b3f6ea7eSPaolo Bonzini  ;;
889cad25d69Spbrook  --disable-system) softmmu="no"
8900a8e90f4Spbrook  ;;
891cad25d69Spbrook  --enable-system) softmmu="yes"
8920a8e90f4Spbrook  ;;
8930953a80fSZachary Amsden  --disable-user)
8940953a80fSZachary Amsden      linux_user="no" ;
8950953a80fSZachary Amsden      bsd_user="no" ;
8960953a80fSZachary Amsden  ;;
8970953a80fSZachary Amsden  --enable-user) ;;
898831b7825Sths  --disable-linux-user) linux_user="no"
8990a8e90f4Spbrook  ;;
900831b7825Sths  --enable-linux-user) linux_user="yes"
901831b7825Sths  ;;
90284778508Sblueswir1  --disable-bsd-user) bsd_user="no"
90384778508Sblueswir1  ;;
90484778508Sblueswir1  --enable-bsd-user) bsd_user="yes"
90584778508Sblueswir1  ;;
90640d6444eSAvi Kivity  --enable-pie) pie="yes"
90734005a00SKirill A. Shutemov  ;;
90840d6444eSAvi Kivity  --disable-pie) pie="no"
90934005a00SKirill A. Shutemov  ;;
91085aa5189Sbellard  --enable-werror) werror="yes"
91185aa5189Sbellard  ;;
91285aa5189Sbellard  --disable-werror) werror="no"
91385aa5189Sbellard  ;;
914cdad781dSDaniele Buono  --enable-lto) lto="true"
915cdad781dSDaniele Buono  ;;
916cdad781dSDaniele Buono  --disable-lto) lto="false"
917cdad781dSDaniele Buono  ;;
91863678e17SSteven Noonan  --enable-stack-protector) stack_protector="yes"
91963678e17SSteven Noonan  ;;
92063678e17SSteven Noonan  --disable-stack-protector) stack_protector="no"
92163678e17SSteven Noonan  ;;
9221e4f6065SDaniele Buono  --enable-safe-stack) safe_stack="yes"
9231e4f6065SDaniele Buono  ;;
9241e4f6065SDaniele Buono  --disable-safe-stack) safe_stack="no"
9251e4f6065SDaniele Buono  ;;
9269e62ba48SDaniele Buono  --enable-cfi)
9279e62ba48SDaniele Buono      cfi="true";
9289e62ba48SDaniele Buono      lto="true";
9299e62ba48SDaniele Buono  ;;
9309e62ba48SDaniele Buono  --disable-cfi) cfi="false"
9319e62ba48SDaniele Buono  ;;
932fbb4121dSPaolo Bonzini  --disable-fdt) fdt="disabled"
9332df87df7SJuan Quintela  ;;
934fbb4121dSPaolo Bonzini  --enable-fdt) fdt="enabled"
935fbb4121dSPaolo Bonzini  ;;
936fbb4121dSPaolo Bonzini  --enable-fdt=git) fdt="internal"
937fbb4121dSPaolo Bonzini  ;;
93803a3c0b3SPaolo Bonzini  --enable-fdt=*) fdt="$optarg"
9392df87df7SJuan Quintela  ;;
9407e563bfbSThomas Huth  --with-pkgversion=*) pkgversion="$optarg"
9414a19f1ecSpbrook  ;;
942519175a2SAlex Barcelo  --with-coroutine=*) coroutine="$optarg"
943519175a2SAlex Barcelo  ;;
944d5970055SMichael S. Tsirkin  --disable-vhost-net) vhost_net="no"
945d5970055SMichael S. Tsirkin  ;;
946d5970055SMichael S. Tsirkin  --enable-vhost-net) vhost_net="yes"
947d5970055SMichael S. Tsirkin  ;;
948042cea27SGonglei  --disable-vhost-crypto) vhost_crypto="no"
949042cea27SGonglei  ;;
950299e6f19SPaolo Bonzini  --enable-vhost-crypto) vhost_crypto="yes"
951042cea27SGonglei  ;;
9525e9be92dSNicholas Bellinger  --disable-vhost-scsi) vhost_scsi="no"
9535e9be92dSNicholas Bellinger  ;;
9545e9be92dSNicholas Bellinger  --enable-vhost-scsi) vhost_scsi="yes"
9555e9be92dSNicholas Bellinger  ;;
956fc0b9b0eSStefan Hajnoczi  --disable-vhost-vsock) vhost_vsock="no"
957fc0b9b0eSStefan Hajnoczi  ;;
958fc0b9b0eSStefan Hajnoczi  --enable-vhost-vsock) vhost_vsock="yes"
959fc0b9b0eSStefan Hajnoczi  ;;
96098fc1adaSDr. David Alan Gilbert  --disable-vhost-user-fs) vhost_user_fs="no"
96198fc1adaSDr. David Alan Gilbert  ;;
96298fc1adaSDr. David Alan Gilbert  --enable-vhost-user-fs) vhost_user_fs="yes"
96398fc1adaSDr. David Alan Gilbert  ;;
964da076ffeSGerd Hoffmann  --disable-opengl) opengl="no"
96520ff075bSMichael Walle  ;;
966da076ffeSGerd Hoffmann  --enable-opengl) opengl="yes"
96720ff075bSMichael Walle  ;;
9681ffb3bbbSPaolo Bonzini  --disable-zlib-test)
9691ece9905SAlon Levy  ;;
97052b53c04SFam Zheng  --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
97152b53c04SFam Zheng      echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
972583f6e7bSStefan Hajnoczi  ;;
973cb6414dfSFam Zheng  --enable-vhdx|--disable-vhdx)
974cb6414dfSFam Zheng      echo "$0: $opt is obsolete, VHDX driver is always built" >&2
975cb6414dfSFam Zheng  ;;
976315d3184SFam Zheng  --enable-uuid|--disable-uuid)
977315d3184SFam Zheng      echo "$0: $opt is obsolete, UUID support is always built" >&2
978315d3184SFam Zheng  ;;
979a1c5e949SDaniel P. Berrange  --tls-priority=*) tls_priority="$optarg"
980a1c5e949SDaniel P. Berrange  ;;
9812da776dbSMichael R. Hines  --enable-rdma) rdma="yes"
9822da776dbSMichael R. Hines  ;;
9832da776dbSMichael R. Hines  --disable-rdma) rdma="no"
9842da776dbSMichael R. Hines  ;;
98521ab34c9SMarcel Apfelbaum  --enable-pvrdma) pvrdma="yes"
98621ab34c9SMarcel Apfelbaum  ;;
98721ab34c9SMarcel Apfelbaum  --disable-pvrdma) pvrdma="no"
98821ab34c9SMarcel Apfelbaum  ;;
989e6a74868SMarc-André Lureau  --disable-vhost-user) vhost_user="no"
990e6a74868SMarc-André Lureau  ;;
991299e6f19SPaolo Bonzini  --enable-vhost-user) vhost_user="yes"
992299e6f19SPaolo Bonzini  ;;
993108a6481SCindy Lu  --disable-vhost-vdpa) vhost_vdpa="no"
994108a6481SCindy Lu  ;;
995108a6481SCindy Lu  --enable-vhost-vdpa) vhost_vdpa="yes"
996108a6481SCindy Lu  ;;
997299e6f19SPaolo Bonzini  --disable-vhost-kernel) vhost_kernel="no"
998299e6f19SPaolo Bonzini  ;;
999299e6f19SPaolo Bonzini  --enable-vhost-kernel) vhost_kernel="yes"
1000e6a74868SMarc-André Lureau  ;;
10018b18cdbfSRichard Henderson  --disable-capstone) capstone="disabled"
10028ca80760SRichard Henderson  ;;
10038b18cdbfSRichard Henderson  --enable-capstone) capstone="enabled"
10048ca80760SRichard Henderson  ;;
10058b18cdbfSRichard Henderson  --enable-capstone=git) capstone="internal"
1006e219c499SRichard Henderson  ;;
100703a3c0b3SPaolo Bonzini  --enable-capstone=*) capstone="$optarg"
1008e219c499SRichard Henderson  ;;
1009cc84d63aSDaniel P. Berrange  --with-git=*) git="$optarg"
1010cc84d63aSDaniel P. Berrange  ;;
10117d7dbf9dSDan Streetman  --with-git-submodules=*)
10127d7dbf9dSDan Streetman      git_submodules_action="$optarg"
1013f62bbee5SDaniel P. Berrange  ;;
10149b8e4298SAlex Bennée  --enable-plugins) if test "$mingw32" = "yes"; then
10159b8e4298SAlex Bennée                        error_exit "TCG plugins not currently supported on Windows platforms"
10169b8e4298SAlex Bennée                    else
10179b8e4298SAlex Bennée                        plugins="yes"
10189b8e4298SAlex Bennée                    fi
101940e8c6f4SAlex Bennée  ;;
102040e8c6f4SAlex Bennée  --disable-plugins) plugins="no"
102140e8c6f4SAlex Bennée  ;;
1022afc3a8f9SAlex Bennée  --enable-containers) use_containers="yes"
1023afc3a8f9SAlex Bennée  ;;
1024afc3a8f9SAlex Bennée  --disable-containers) use_containers="no"
1025afc3a8f9SAlex Bennée  ;;
1026f48e590aSAlex Bennée  --gdb=*) gdb_bin="$optarg"
1027f48e590aSAlex Bennée  ;;
102854e7aac0SAlexey Krasikov  --enable-keyring) secret_keyring="yes"
102954e7aac0SAlexey Krasikov  ;;
103054e7aac0SAlexey Krasikov  --disable-keyring) secret_keyring="no"
103154e7aac0SAlexey Krasikov  ;;
103220cf7b8eSDenis Plotnikov  --enable-gio) gio=yes
103320cf7b8eSDenis Plotnikov  ;;
103420cf7b8eSDenis Plotnikov  --disable-gio) gio=no
103520cf7b8eSDenis Plotnikov  ;;
10363b4da132SPaolo Bonzini  # backwards compatibility options
10373b4da132SPaolo Bonzini  --enable-trace-backend=*) meson_option_parse "--enable-trace-backends=$optarg" "$optarg"
10383b4da132SPaolo Bonzini  ;;
10393b4da132SPaolo Bonzini  --disable-blobs) meson_option_parse --disable-install-blobs ""
10403b4da132SPaolo Bonzini  ;;
10413b4da132SPaolo Bonzini  --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
10423b4da132SPaolo Bonzini  ;;
10433b4da132SPaolo Bonzini  --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
10443b4da132SPaolo Bonzini  ;;
10453b4da132SPaolo Bonzini  # everything else has the same name in configure and meson
104661d63097SPaolo Bonzini  --enable-* | --disable-*) meson_option_parse "$opt" "$optarg"
104761d63097SPaolo Bonzini  ;;
10482d2ad6d0SFam Zheng  *)
10492d2ad6d0SFam Zheng      echo "ERROR: unknown option $opt"
10502d2ad6d0SFam Zheng      echo "Try '$0 --help' for more information"
10512d2ad6d0SFam Zheng      exit 1
10527f1559c6Sbalrog  ;;
10537d13299dSbellard  esac
10547d13299dSbellarddone
10557d13299dSbellard
1056d1a14257SAlex Bennée# test for any invalid configuration combinations
1057d1a14257SAlex Bennéeif test "$plugins" = "yes" -a "$tcg" = "disabled"; then
1058d1a14257SAlex Bennée    error_exit "Can't enable plugins on non-TCG builds"
1059d1a14257SAlex Bennéefi
1060d1a14257SAlex Bennée
10617d7dbf9dSDan Streetmancase $git_submodules_action in
10627d7dbf9dSDan Streetman    update|validate)
10637d7dbf9dSDan Streetman        if test ! -e "$source_path/.git"; then
10647d7dbf9dSDan Streetman            echo "ERROR: cannot $git_submodules_action git submodules without .git"
10657d7dbf9dSDan Streetman            exit 1
10667d7dbf9dSDan Streetman        fi
10677d7dbf9dSDan Streetman    ;;
10687d7dbf9dSDan Streetman    ignore)
1069b80fd281SPaolo Bonzini        if ! test -f "$source_path/ui/keycodemapdb/README"
1070b80fd281SPaolo Bonzini        then
1071b80fd281SPaolo Bonzini            echo
1072b80fd281SPaolo Bonzini            echo "ERROR: missing GIT submodules"
1073b80fd281SPaolo Bonzini            echo
1074b80fd281SPaolo Bonzini            if test -e "$source_path/.git"; then
1075b80fd281SPaolo Bonzini                echo "--with-git-submodules=ignore specified but submodules were not"
1076b80fd281SPaolo Bonzini                echo "checked out.  Please initialize and update submodules."
1077b80fd281SPaolo Bonzini            else
1078b80fd281SPaolo Bonzini                echo "This is not a GIT checkout but module content appears to"
1079b80fd281SPaolo Bonzini                echo "be missing. Do not use 'git archive' or GitHub download links"
1080b80fd281SPaolo Bonzini                echo "to acquire QEMU source archives. Non-GIT builds are only"
1081b80fd281SPaolo Bonzini                echo "supported with source archives linked from:"
1082b80fd281SPaolo Bonzini                echo
1083b80fd281SPaolo Bonzini                echo "  https://www.qemu.org/download/#source"
1084b80fd281SPaolo Bonzini                echo
1085b80fd281SPaolo Bonzini                echo "Developers working with GIT can use scripts/archive-source.sh"
1086b80fd281SPaolo Bonzini                echo "if they need to create valid source archives."
1087b80fd281SPaolo Bonzini            fi
1088b80fd281SPaolo Bonzini            echo
1089b80fd281SPaolo Bonzini            exit 1
1090b80fd281SPaolo Bonzini        fi
10917d7dbf9dSDan Streetman    ;;
10927d7dbf9dSDan Streetman    *)
10937d7dbf9dSDan Streetman        echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
10947d7dbf9dSDan Streetman        exit 1
10957d7dbf9dSDan Streetman    ;;
10967d7dbf9dSDan Streetmanesac
10977d7dbf9dSDan Streetman
109822a87800SMarc-André Lureaulibdir="${libdir:-$prefix/lib}"
109922a87800SMarc-André Lureaulibexecdir="${libexecdir:-$prefix/libexec}"
110022a87800SMarc-André Lureauincludedir="${includedir:-$prefix/include}"
110122a87800SMarc-André Lureau
110222a87800SMarc-André Lureauif test "$mingw32" = "yes" ; then
110315588a62SJoshua Watt    bindir="${bindir:-$prefix}"
110422a87800SMarc-André Lureauelse
110515588a62SJoshua Watt    bindir="${bindir:-$prefix/bin}"
110615588a62SJoshua Wattfi
110722a87800SMarc-André Lureaumandir="${mandir:-$prefix/share/man}"
110822a87800SMarc-André Lureaudatadir="${datadir:-$prefix/share}"
1109ca8c0909SMarc-André Lureaudocdir="${docdir:-$prefix/share/doc}"
111022a87800SMarc-André Lureausysconfdir="${sysconfdir:-$prefix/etc}"
111122a87800SMarc-André Lureaulocal_statedir="${local_statedir:-$prefix/var}"
111216bf7a33SPaolo Bonzinifirmwarepath="${firmwarepath:-$datadir/qemu-firmware}"
111316bf7a33SPaolo Bonzinilocaledir="${localedir:-$datadir/locale}"
111422a87800SMarc-André Lureau
11159557af9cSAlex Bennéeif eval test -z "\${cross_cc_$cpu}"; then
1116b1aa4de1SAlex Bennée    eval "cross_cc_${cpu}=\$cc"
11172038f8c8SPaolo Bonzini    cross_cc_vars="$cross_cc_vars cross_cc_${cpu}"
11189557af9cSAlex Bennéefi
111979f3b12fSPeter Crosthwaite
112060e0df25SPeter Maydelldefault_target_list=""
11216e92f823SPeter Maydellmak_wilds=""
11226e92f823SPeter Maydell
1123b915a2f1SPaolo Bonziniif [ "$linux_user" != no ]; then
1124b915a2f1SPaolo Bonzini    if [ "$targetos" = linux ] && [ -d $source_path/linux-user/include/host/$cpu ]; then
1125b915a2f1SPaolo Bonzini        linux_user=yes
1126b915a2f1SPaolo Bonzini    elif [ "$linux_user" = yes ]; then
1127b915a2f1SPaolo Bonzini        error_exit "linux-user not supported on this architecture"
1128b915a2f1SPaolo Bonzini    fi
1129b915a2f1SPaolo Bonzinifi
1130b915a2f1SPaolo Bonziniif [ "$bsd_user" != no ]; then
1131b915a2f1SPaolo Bonzini    if [ "$bsd_user" = "" ]; then
1132b915a2f1SPaolo Bonzini        test $targetos = freebsd && bsd_user=yes
1133b915a2f1SPaolo Bonzini    fi
1134b915a2f1SPaolo Bonzini    if [ "$bsd_user" = yes ] && ! [ -d $source_path/bsd-user/$targetos ]; then
1135b915a2f1SPaolo Bonzini        error_exit "bsd-user not supported on this host OS"
1136b915a2f1SPaolo Bonzini    fi
1137b915a2f1SPaolo Bonzinifi
113860e0df25SPeter Maydellif [ "$softmmu" = "yes" ]; then
1139812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
114060e0df25SPeter Maydellfi
114160e0df25SPeter Maydellif [ "$linux_user" = "yes" ]; then
1142812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
114360e0df25SPeter Maydellfi
114460e0df25SPeter Maydellif [ "$bsd_user" = "yes" ]; then
1145812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
114660e0df25SPeter Maydellfi
114760e0df25SPeter Maydell
1148447e133fSAlex Bennéefor config in $mak_wilds; do
1149447e133fSAlex Bennée    target="$(basename "$config" .mak)"
115098db9a06SAlex Bennée    if echo "$target_list_exclude" | grep -vq "$target"; then
1151447e133fSAlex Bennée        default_target_list="${default_target_list} $target"
1152447e133fSAlex Bennée    fi
1153447e133fSAlex Bennéedone
11546e92f823SPeter Maydell
1155af5db58eSpbrookif test x"$show_help" = x"yes" ; then
1156af5db58eSpbrookcat << EOF
1157af5db58eSpbrook
1158af5db58eSpbrookUsage: configure [options]
1159af5db58eSpbrookOptions: [defaults in brackets after descriptions]
1160af5db58eSpbrook
116108fb77edSStefan WeilStandard options:
116208fb77edSStefan Weil  --help                   print this message
116308fb77edSStefan Weil  --prefix=PREFIX          install in PREFIX [$prefix]
116408fb77edSStefan Weil  --interp-prefix=PREFIX   where to find shared libraries, etc.
116508fb77edSStefan Weil                           use %M for cpu name [$interp_prefix]
116674154d7eSThomas Huth  --target-list=LIST       set target list (default: build all)
116708fb77edSStefan Weil$(echo Available targets: $default_target_list | \
116808fb77edSStefan Weil  fold -s -w 53 | sed -e 's/^/                           /')
1169447e133fSAlex Bennée  --target-list-exclude=LIST exclude a set of targets from the default target-list
117008fb77edSStefan Weil
117108fb77edSStefan WeilAdvanced options (experts only):
11723812c0c4SJoelle van Dyne  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
117308fb77edSStefan Weil  --cc=CC                  use C compiler CC [$cc]
117408fb77edSStefan Weil  --iasl=IASL              use ACPI compiler IASL [$iasl]
117508fb77edSStefan Weil  --host-cc=CC             use C compiler CC [$host_cc] for code run at
117608fb77edSStefan Weil                           build time
117708fb77edSStefan Weil  --cxx=CXX                use C++ compiler CXX [$cxx]
117808fb77edSStefan Weil  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
1179a2866660SPaolo Bonzini  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
1180a2866660SPaolo Bonzini  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
1181*e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
118208fb77edSStefan Weil  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
1183d75402b5SAlex Bennée  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
1184479ca4ccSMatheus Ferst  --cross-cc-cflags-ARCH=  use compiler flags when building ARCH guest tests
118508fb77edSStefan Weil  --make=MAKE              use specified make [$make]
118608fb77edSStefan Weil  --python=PYTHON          use specified python [$python]
11872eb054c2SPeter Maydell  --sphinx-build=SPHINX    use specified sphinx-build [$sphinx_build]
1188a5665051SPaolo Bonzini  --meson=MESON            use specified meson [$meson]
118948328880SPaolo Bonzini  --ninja=NINJA            use specified ninja [$ninja]
119008fb77edSStefan Weil  --smbd=SMBD              use specified smbd [$smbd]
1191db1b5f13SThomas Huth  --with-git=GIT           use specified git [$git]
11927d7dbf9dSDan Streetman  --with-git-submodules=update   update git submodules (default if .git dir exists)
11937d7dbf9dSDan Streetman  --with-git-submodules=validate fail if git submodules are not up to date
11947d7dbf9dSDan Streetman  --with-git-submodules=ignore   do not update or check git submodules (default if no .git dir)
119508fb77edSStefan Weil  --static                 enable static build [$static]
119608fb77edSStefan Weil  --mandir=PATH            install man pages in PATH
119710ff82d1SMarc-André Lureau  --datadir=PATH           install firmware in PATH/$qemu_suffix
1198fe0038beSPaolo Bonzini  --localedir=PATH         install translation in PATH/$qemu_suffix
119910ff82d1SMarc-André Lureau  --docdir=PATH            install documentation in PATH/$qemu_suffix
120008fb77edSStefan Weil  --bindir=PATH            install binaries in PATH
120108fb77edSStefan Weil  --libdir=PATH            install libraries in PATH
1202db1b5f13SThomas Huth  --libexecdir=PATH        install helper binaries in PATH
120310ff82d1SMarc-André Lureau  --sysconfdir=PATH        install config in PATH/$qemu_suffix
120408fb77edSStefan Weil  --localstatedir=PATH     install local state in PATH (set at runtime on win32)
12053d5eecabSGerd Hoffmann  --firmwarepath=PATH      search PATH for firmware files
120613336606SRobert Foley  --efi-aarch64=PATH       PATH of efi file to use for aarch64 VMs.
1207ca8c0909SMarc-André Lureau  --with-suffix=SUFFIX     suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
1208db1b5f13SThomas Huth  --with-pkgversion=VERS   use specified string as sub-version of the package
1209c035c8d6SPaolo Bonzini  --without-default-features default all --enable-* options to "disabled"
1210c035c8d6SPaolo Bonzini  --without-default-devices  do not include any device that is not needed to
1211c035c8d6SPaolo Bonzini                           start the emulator (only use if you are including
1212d1d5e9eeSAlex Bennée                           desired devices in configs/devices/)
1213d1d5e9eeSAlex Bennée  --with-devices-ARCH=NAME override default configs/devices
121408fb77edSStefan Weil  --enable-debug           enable common debug build options
1215247724cbSMarc-André Lureau  --enable-sanitizers      enable default sanitizers
12160aebab04SLingfeng Yang  --enable-tsan            enable thread sanitizer
121708fb77edSStefan Weil  --disable-werror         disable compilation abort on warning
121863678e17SSteven Noonan  --disable-stack-protector disable compiler-provided stack protection
121916bfbc70SPaolo Bonzini  --audio-drv-list=LIST    set audio drivers to try if -audiodev is not used
122008fb77edSStefan Weil  --block-drv-whitelist=L  Same as --block-drv-rw-whitelist=L
122108fb77edSStefan Weil  --block-drv-rw-whitelist=L
122208fb77edSStefan Weil                           set block driver read-write whitelist
1223e5f05f8cSKevin Wolf                           (by default affects only QEMU, not tools like qemu-img)
122408fb77edSStefan Weil  --block-drv-ro-whitelist=L
122508fb77edSStefan Weil                           set block driver read-only whitelist
1226e5f05f8cSKevin Wolf                           (by default affects only QEMU, not tools like qemu-img)
122708fb77edSStefan Weil  --with-trace-file=NAME   Full PATH,NAME of file to store traces
122808fb77edSStefan Weil                           Default:trace-<pid>
1229c23f23b9SMichael Tokarev  --cpu=CPU                Build for host CPU [$cpu]
123008fb77edSStefan Weil  --with-coroutine=BACKEND coroutine backend. Supported options:
123133c53c54SDaniel P. Berrange                           ucontext, sigaltstack, windows
123208fb77edSStefan Weil  --enable-gcov            enable test coverage analysis with gcov
1233a1c5e949SDaniel P. Berrange  --tls-priority           default TLS protocol/cipher priority string
123440e8c6f4SAlex Bennée  --enable-plugins
123540e8c6f4SAlex Bennée                           enable plugins via shared library loading
1236afc3a8f9SAlex Bennée  --disable-containers     don't use containers for cross-building
1237f48e590aSAlex Bennée  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
123861d63097SPaolo BonziniEOF
123961d63097SPaolo Bonzini  meson_options_help
124061d63097SPaolo Bonzinicat << EOF
1241c23f23b9SMichael Tokarev  system          all system emulation targets
1242c23f23b9SMichael Tokarev  user            supported user emulation targets
1243c23f23b9SMichael Tokarev  linux-user      all linux usermode emulation targets
1244c23f23b9SMichael Tokarev  bsd-user        all BSD usermode emulation targets
1245c23f23b9SMichael Tokarev  pie             Position Independent Executables
124621e709aaSMarc-André Lureau  modules         modules support (non-Windows)
1247bd83c861SChristian Ehrhardt  module-upgrades try to load modules from alternate paths for upgrades
1248c23f23b9SMichael Tokarev  debug-tcg       TCG debugging (default is disabled)
1249c23f23b9SMichael Tokarev  debug-info      debugging information
1250cdad781dSDaniele Buono  lto             Enable Link-Time Optimization.
12511e4f6065SDaniele Buono  safe-stack      SafeStack Stack Smash Protection. Depends on
12521e4f6065SDaniele Buono                  clang/llvm >= 3.7 and requires coroutine backend ucontext.
125321ab34c9SMarcel Apfelbaum  rdma            Enable RDMA-based migration
125421ab34c9SMarcel Apfelbaum  pvrdma          Enable PVRDMA support
1255299e6f19SPaolo Bonzini  vhost-net       vhost-net kernel acceleration support
1256299e6f19SPaolo Bonzini  vhost-vsock     virtio sockets device support
1257299e6f19SPaolo Bonzini  vhost-scsi      vhost-scsi kernel target support
1258299e6f19SPaolo Bonzini  vhost-crypto    vhost-user-crypto backend support
1259299e6f19SPaolo Bonzini  vhost-kernel    vhost kernel backend support
1260299e6f19SPaolo Bonzini  vhost-user      vhost-user backend support
1261108a6481SCindy Lu  vhost-vdpa      vhost-vdpa kernel backend support
1262c12d66aaSLin Ma  opengl          opengl support
126320cf7b8eSDenis Plotnikov  gio             libgio support
126408fb77edSStefan Weil
126508fb77edSStefan WeilNOTE: The object files are built at the place where configure is launched
1266af5db58eSpbrookEOF
12672d2ad6d0SFam Zhengexit 0
1268af5db58eSpbrookfi
1269af5db58eSpbrook
12709c790242SThomas Huth# Remove old dependency files to make sure that they get properly regenerated
1271bb768f71SThomas Huthrm -f */config-devices.mak.d
12729c790242SThomas Huth
1273faf44142SDaniel P. Berrangéif test -z "$python"
1274faf44142SDaniel P. Berrangéthen
1275c53eeaf7SStefan Hajnoczi    error_exit "Python not found. Use --python=/path/to/python"
1276c53eeaf7SStefan Hajnoczifi
12778e2c76bdSRoman Bolshakovif ! has "$make"
12788e2c76bdSRoman Bolshakovthen
12798e2c76bdSRoman Bolshakov    error_exit "GNU make ($make) not found"
12808e2c76bdSRoman Bolshakovfi
1281c53eeaf7SStefan Hajnoczi
1282c53eeaf7SStefan Hajnoczi# Note that if the Python conditional here evaluates True we will exit
1283c53eeaf7SStefan Hajnoczi# with status 1 which is a shell 'false' value.
12841b11f28dSThomas Huthif ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then
12851b11f28dSThomas Huth  error_exit "Cannot use '$python', Python >= 3.6 is required." \
1286c53eeaf7SStefan Hajnoczi      "Use --python=/path/to/python to specify a supported Python."
1287c53eeaf7SStefan Hajnoczifi
1288c53eeaf7SStefan Hajnoczi
1289755ee70fSCleber Rosa# Preserve python version since some functionality is dependent on it
1290406ab2f3SCleber 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)
1291755ee70fSCleber Rosa
1292c53eeaf7SStefan Hajnoczi# Suppress writing compiled files
1293c53eeaf7SStefan Hajnoczipython="$python -B"
1294c53eeaf7SStefan Hajnoczi
12950a01d76fSMarc-André Lureauif test -z "$meson"; then
12966638cae5SPaolo Bonzini    if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.59.3; then
12970a01d76fSMarc-André Lureau        meson=meson
12987d7dbf9dSDan Streetman    elif test $git_submodules_action != 'ignore' ; then
12990a01d76fSMarc-André Lureau        meson=git
13000a01d76fSMarc-André Lureau    elif test -e "${source_path}/meson/meson.py" ; then
13010a01d76fSMarc-André Lureau        meson=internal
13020a01d76fSMarc-André Lureau    else
13030a01d76fSMarc-André Lureau        if test "$explicit_python" = yes; then
13040a01d76fSMarc-André Lureau            error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
13050a01d76fSMarc-André Lureau        else
1306a5665051SPaolo Bonzini            error_exit "Meson not found.  Use --meson=/path/to/meson"
1307a5665051SPaolo Bonzini        fi
13080a01d76fSMarc-André Lureau    fi
13090a01d76fSMarc-André Lureauelse
13100a01d76fSMarc-André Lureau    # Meson uses its own Python interpreter to invoke other Python scripts,
13110a01d76fSMarc-André Lureau    # but the user wants to use the one they specified with --python.
13120a01d76fSMarc-André Lureau    #
13130a01d76fSMarc-André Lureau    # We do not want to override the distro Python interpreter (and sometimes
13140a01d76fSMarc-André Lureau    # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
13150a01d76fSMarc-André Lureau    # just require --meson=git|internal together with --python.
13160a01d76fSMarc-André Lureau    if test "$explicit_python" = yes; then
13170a01d76fSMarc-André Lureau        case "$meson" in
13180a01d76fSMarc-André Lureau            git | internal) ;;
13190a01d76fSMarc-André Lureau            *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
13200a01d76fSMarc-André Lureau        esac
13210a01d76fSMarc-André Lureau    fi
13220a01d76fSMarc-André Lureaufi
1323a5665051SPaolo Bonzini
13240a01d76fSMarc-André Lureauif test "$meson" = git; then
13250a01d76fSMarc-André Lureau    git_submodules="${git_submodules} meson"
13260a01d76fSMarc-André Lureaufi
13270a01d76fSMarc-André Lureau
13280a01d76fSMarc-André Lureaucase "$meson" in
13290a01d76fSMarc-André Lureau    git | internal)
13300a01d76fSMarc-André Lureau        meson="$python ${source_path}/meson/meson.py"
13310a01d76fSMarc-André Lureau        ;;
133284ec0c24SPaolo Bonzini    *) meson=$(command -v "$meson") ;;
13330a01d76fSMarc-André Lureauesac
13340a01d76fSMarc-André Lureau
133509e93326SPaolo Bonzini# Probe for ninja
133648328880SPaolo Bonzini
133748328880SPaolo Bonziniif test -z "$ninja"; then
133848328880SPaolo Bonzini    for c in ninja ninja-build samu; do
133948328880SPaolo Bonzini        if has $c; then
134048328880SPaolo Bonzini            ninja=$(command -v "$c")
134148328880SPaolo Bonzini            break
134248328880SPaolo Bonzini        fi
134348328880SPaolo Bonzini    done
134409e93326SPaolo Bonzini    if test -z "$ninja"; then
134509e93326SPaolo Bonzini      error_exit "Cannot find Ninja"
134609e93326SPaolo Bonzini    fi
134748328880SPaolo Bonzinifi
1348a5665051SPaolo Bonzini
13499aae6e54SDaniel Henrique Barboza# Check that the C compiler works. Doing this here before testing
13509aae6e54SDaniel Henrique Barboza# the host CPU ensures that we had a valid CC to autodetect the
13519aae6e54SDaniel Henrique Barboza# $cpu var (and we should bail right here if that's not the case).
13529aae6e54SDaniel Henrique Barboza# It also allows the help message to be printed without a CC.
13539aae6e54SDaniel Henrique Barbozawrite_c_skeleton;
13549aae6e54SDaniel Henrique Barbozaif compile_object ; then
13559aae6e54SDaniel Henrique Barboza  : C compiler works ok
13569aae6e54SDaniel Henrique Barbozaelse
13579aae6e54SDaniel Henrique Barboza    error_exit "\"$cc\" either does not exist or does not work"
13589aae6e54SDaniel Henrique Barbozafi
13599aae6e54SDaniel Henrique Barbozaif ! compile_prog ; then
13609aae6e54SDaniel Henrique Barboza    error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
13619aae6e54SDaniel Henrique Barbozafi
13629aae6e54SDaniel Henrique Barboza
13639c83ffd8SPeter Maydell# Consult white-list to determine whether to enable werror
13649c83ffd8SPeter Maydell# by default.  Only enable by default for git builds
13659c83ffd8SPeter Maydellif test -z "$werror" ; then
13667d7dbf9dSDan Streetman    if test "$git_submodules_action" != "ignore" && \
1367e633a5c6SEric Blake        { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
13689c83ffd8SPeter Maydell        werror="yes"
13699c83ffd8SPeter Maydell    else
13709c83ffd8SPeter Maydell        werror="no"
13719c83ffd8SPeter Maydell    fi
13729c83ffd8SPeter Maydellfi
13739c83ffd8SPeter Maydell
1374975ff037SPaolo Bonziniif test "$targetos" = "bogus"; then
1375fb59dabdSPeter Maydell    # Now that we know that we're not printing the help and that
1376fb59dabdSPeter Maydell    # the compiler works (so the results of the check_defines we used
1377fb59dabdSPeter Maydell    # to identify the OS are reliable), if we didn't recognize the
1378fb59dabdSPeter Maydell    # host OS we should stop now.
1379951fedfcSPeter Maydell    error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1380fb59dabdSPeter Maydellfi
1381fb59dabdSPeter Maydell
1382efc6c070SThomas Huth# Check whether the compiler matches our minimum requirements:
1383efc6c070SThomas Huthcat > $TMPC << EOF
1384efc6c070SThomas Huth#if defined(__clang_major__) && defined(__clang_minor__)
1385efc6c070SThomas Huth# ifdef __apple_build_version__
13862a85a08cSDaniel P. Berrangé#  if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
13872a85a08cSDaniel P. Berrangé#   error You need at least XCode Clang v10.0 to compile QEMU
1388efc6c070SThomas Huth#  endif
1389efc6c070SThomas Huth# else
13902a85a08cSDaniel P. Berrangé#  if __clang_major__ < 6 || (__clang_major__ == 6 && __clang_minor__ < 0)
13912a85a08cSDaniel P. Berrangé#   error You need at least Clang v6.0 to compile QEMU
1392efc6c070SThomas Huth#  endif
1393efc6c070SThomas Huth# endif
1394efc6c070SThomas Huth#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
13953830df5fSnia# if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
13963830df5fSnia#  error You need at least GCC v7.4.0 to compile QEMU
1397efc6c070SThomas Huth# endif
1398efc6c070SThomas Huth#else
1399efc6c070SThomas Huth# error You either need GCC or Clang to compiler QEMU
1400efc6c070SThomas Huth#endif
1401efc6c070SThomas Huthint main (void) { return 0; }
1402efc6c070SThomas HuthEOF
1403efc6c070SThomas Huthif ! compile_prog "" "" ; then
14043830df5fSnia    error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
1405efc6c070SThomas Huthfi
1406efc6c070SThomas Huth
140700849b92SRichard Henderson# Accumulate -Wfoo and -Wno-bar separately.
140800849b92SRichard Henderson# We will list all of the enable flags first, and the disable flags second.
140900849b92SRichard Henderson# Note that we do not add -Werror, because that would enable it for all
141000849b92SRichard Henderson# configure tests. If a configure test failed due to -Werror this would
141100849b92SRichard Henderson# just silently disable some features, so it's too error prone.
141200849b92SRichard Henderson
141300849b92SRichard Hendersonwarn_flags=
141400849b92SRichard Hendersonadd_to warn_flags -Wold-style-declaration
141500849b92SRichard Hendersonadd_to warn_flags -Wold-style-definition
141600849b92SRichard Hendersonadd_to warn_flags -Wtype-limits
141700849b92SRichard Hendersonadd_to warn_flags -Wformat-security
141800849b92SRichard Hendersonadd_to warn_flags -Wformat-y2k
141900849b92SRichard Hendersonadd_to warn_flags -Winit-self
142000849b92SRichard Hendersonadd_to warn_flags -Wignored-qualifiers
142100849b92SRichard Hendersonadd_to warn_flags -Wempty-body
142200849b92SRichard Hendersonadd_to warn_flags -Wnested-externs
142300849b92SRichard Hendersonadd_to warn_flags -Wendif-labels
142400849b92SRichard Hendersonadd_to warn_flags -Wexpansion-to-defined
14250a2ebce9SThomas Huthadd_to warn_flags -Wimplicit-fallthrough=2
142600849b92SRichard Henderson
142700849b92SRichard Hendersonnowarn_flags=
142800849b92SRichard Hendersonadd_to nowarn_flags -Wno-initializer-overrides
142900849b92SRichard Hendersonadd_to nowarn_flags -Wno-missing-include-dirs
143000849b92SRichard Hendersonadd_to nowarn_flags -Wno-shift-negative-value
143100849b92SRichard Hendersonadd_to nowarn_flags -Wno-string-plus-int
143200849b92SRichard Hendersonadd_to nowarn_flags -Wno-typedef-redefinition
1433aabab967SRichard Hendersonadd_to nowarn_flags -Wno-tautological-type-limit-compare
1434bac8d222SRichard Hendersonadd_to nowarn_flags -Wno-psabi
143500849b92SRichard Henderson
143600849b92SRichard Hendersongcc_flags="$warn_flags $nowarn_flags"
143793b25869SJohn Snow
143893b25869SJohn Snowcc_has_warning_flag() {
143993b25869SJohn Snow    write_c_skeleton;
144093b25869SJohn Snow
1441a1d29d6cSPeter Maydell    # Use the positive sense of the flag when testing for -Wno-wombat
1442a1d29d6cSPeter Maydell    # support (gcc will happily accept the -Wno- form of unknown
1443a1d29d6cSPeter Maydell    # warning options).
144493b25869SJohn Snow    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
144593b25869SJohn Snow    compile_prog "-Werror $optflag" ""
144693b25869SJohn Snow}
144793b25869SJohn Snow
144893b25869SJohn Snowfor flag in $gcc_flags; do
144993b25869SJohn Snow    if cc_has_warning_flag $flag ; then
14508d05095cSPaolo Bonzini        QEMU_CFLAGS="$QEMU_CFLAGS $flag"
14518d05095cSPaolo Bonzini    fi
14528d05095cSPaolo Bonzinidone
14538d05095cSPaolo Bonzini
145463678e17SSteven Noonanif test "$stack_protector" != "no"; then
1455fccd35a0SRodrigo Rebello  cat > $TMPC << EOF
1456fccd35a0SRodrigo Rebelloint main(int argc, char *argv[])
1457fccd35a0SRodrigo Rebello{
1458fccd35a0SRodrigo Rebello    char arr[64], *p = arr, *c = argv[0];
1459fccd35a0SRodrigo Rebello    while (*c) {
1460fccd35a0SRodrigo Rebello        *p++ = *c++;
1461fccd35a0SRodrigo Rebello    }
1462fccd35a0SRodrigo Rebello    return 0;
1463fccd35a0SRodrigo Rebello}
1464fccd35a0SRodrigo RebelloEOF
146563678e17SSteven Noonan  gcc_flags="-fstack-protector-strong -fstack-protector-all"
14663b463a3fSMiroslav Rezanina  sp_on=0
146763678e17SSteven Noonan  for flag in $gcc_flags; do
1468590e5dd9SPeter Maydell    # We need to check both a compile and a link, since some compiler
1469590e5dd9SPeter Maydell    # setups fail only on a .c->.o compile and some only at link time
1470086d5f75SPaolo Bonzini    if compile_object "-Werror $flag" &&
1471590e5dd9SPeter Maydell       compile_prog "-Werror $flag" ""; then
147263678e17SSteven Noonan      QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1473db5adeaaSPaolo Bonzini      QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
14743b463a3fSMiroslav Rezanina      sp_on=1
147563678e17SSteven Noonan      break
147663678e17SSteven Noonan    fi
147763678e17SSteven Noonan  done
14783b463a3fSMiroslav Rezanina  if test "$stack_protector" = yes; then
14793b463a3fSMiroslav Rezanina    if test $sp_on = 0; then
14803b463a3fSMiroslav Rezanina      error_exit "Stack protector not supported"
14813b463a3fSMiroslav Rezanina    fi
14823b463a3fSMiroslav Rezanina  fi
148337746c5eSMarc-André Lureaufi
148437746c5eSMarc-André Lureau
148520bc94a2SPaolo Bonzini# Disable -Wmissing-braces on older compilers that warn even for
148620bc94a2SPaolo Bonzini# the "universal" C zero initializer {0}.
148720bc94a2SPaolo Bonzinicat > $TMPC << EOF
148820bc94a2SPaolo Bonzinistruct {
148920bc94a2SPaolo Bonzini  int a[2];
149020bc94a2SPaolo Bonzini} x = {0};
149120bc94a2SPaolo BonziniEOF
149220bc94a2SPaolo Bonziniif compile_object "-Werror" "" ; then
149320bc94a2SPaolo Bonzini  :
149420bc94a2SPaolo Bonzinielse
149520bc94a2SPaolo Bonzini  QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
149620bc94a2SPaolo Bonzinifi
149720bc94a2SPaolo Bonzini
149821e709aaSMarc-André Lureau# Our module code doesn't support Windows
149921e709aaSMarc-André Lureauif test "$modules" = "yes" && test "$mingw32" = "yes" ; then
150021e709aaSMarc-André Lureau  error_exit "Modules are not available for Windows"
150121e709aaSMarc-André Lureaufi
150221e709aaSMarc-André Lureau
1503bd83c861SChristian Ehrhardt# module_upgrades is only reasonable if modules are enabled
1504bd83c861SChristian Ehrhardtif test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
1505bd83c861SChristian Ehrhardt  error_exit "Can't enable module-upgrades as Modules are not enabled"
1506bd83c861SChristian Ehrhardtfi
1507bd83c861SChristian Ehrhardt
15085f2453acSAlex Bennée# Static linking is not possible with plugins, modules or PIE
150940d6444eSAvi Kivityif test "$static" = "yes" ; then
1510aa0d1f44SPaolo Bonzini  if test "$modules" = "yes" ; then
1511aa0d1f44SPaolo Bonzini    error_exit "static and modules are mutually incompatible"
1512aa0d1f44SPaolo Bonzini  fi
15135f2453acSAlex Bennée  if test "$plugins" = "yes"; then
15145f2453acSAlex Bennée    error_exit "static and plugins are mutually incompatible"
1515ba4dd2aaSAlex Bennée  else
1516ba4dd2aaSAlex Bennée    plugins="no"
15175f2453acSAlex Bennée  fi
151840d6444eSAvi Kivityfi
151937650689SPaolo Bonzinitest "$plugins" = "" && plugins=yes
152040d6444eSAvi Kivity
152140d6444eSAvi Kivitycat > $TMPC << EOF
152221d4a791SAvi Kivity
152321d4a791SAvi Kivity#ifdef __linux__
152421d4a791SAvi Kivity#  define THREAD __thread
152521d4a791SAvi Kivity#else
152621d4a791SAvi Kivity#  define THREAD
152721d4a791SAvi Kivity#endif
152821d4a791SAvi Kivitystatic THREAD int tls_var;
152921d4a791SAvi Kivityint main(void) { return tls_var; }
153040d6444eSAvi KivityEOF
1531b2634124SRichard Henderson
1532ffd205efSJessica Clarke# Check we support -fno-pie and -no-pie first; we will need the former for
1533ffd205efSJessica Clarke# building ROMs, and both for everything if --disable-pie is passed.
1534412aeacdSAlex Bennéeif compile_prog "-Werror -fno-pie" "-no-pie"; then
1535412aeacdSAlex Bennée  CFLAGS_NOPIE="-fno-pie"
1536ffd205efSJessica Clarke  LDFLAGS_NOPIE="-no-pie"
1537412aeacdSAlex Bennéefi
1538412aeacdSAlex Bennée
153912781462SRichard Hendersonif test "$static" = "yes"; then
1540eca7a8e6SRichard Henderson  if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
15415770e8afSPaolo Bonzini    CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
154212781462SRichard Henderson    QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
154312781462SRichard Henderson    pie="yes"
154412781462SRichard Henderson  elif test "$pie" = "yes"; then
154512781462SRichard Henderson    error_exit "-static-pie not available due to missing toolchain support"
154612781462SRichard Henderson  else
154712781462SRichard Henderson    QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
154812781462SRichard Henderson    pie="no"
154912781462SRichard Henderson  fi
155012781462SRichard Hendersonelif test "$pie" = "no"; then
15515770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="$CFLAGS_NOPIE $CONFIGURE_CFLAGS"
1552ffd205efSJessica Clarke  CONFIGURE_LDFLAGS="$LDFLAGS_NOPIE $CONFIGURE_LDFLAGS"
1553eca7a8e6SRichard Hendersonelif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
15545770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
15555770e8afSPaolo Bonzini  CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
155640d6444eSAvi Kivity  pie="yes"
15572c674109SRichard Hendersonelif test "$pie" = "yes"; then
155876ad07a4SPeter Maydell  error_exit "PIE not available due to missing toolchain support"
155940d6444eSAvi Kivityelse
156040d6444eSAvi Kivity  echo "Disabling PIE due to missing toolchain support"
156140d6444eSAvi Kivity  pie="no"
156240d6444eSAvi Kivityfi
156340d6444eSAvi Kivity
1564e6cbd751SRichard Henderson# Detect support for PT_GNU_RELRO + DT_BIND_NOW.
1565e6cbd751SRichard Henderson# The combination is known as "full relro", because .got.plt is read-only too.
1566e6cbd751SRichard Hendersonif compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1567e6cbd751SRichard Henderson  QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
1568e6cbd751SRichard Hendersonfi
1569e6cbd751SRichard Henderson
157009dada40SPaolo Bonzini##########################################
157109dada40SPaolo Bonzini# __sync_fetch_and_and requires at least -march=i486. Many toolchains
157209dada40SPaolo Bonzini# use i686 as default anyway, but for those that don't, an explicit
157309dada40SPaolo Bonzini# specification is necessary
157409dada40SPaolo Bonzini
157509dada40SPaolo Bonziniif test "$cpu" = "i386"; then
157609dada40SPaolo Bonzini  cat > $TMPC << EOF
157709dada40SPaolo Bonzinistatic int sfaa(int *ptr)
157809dada40SPaolo Bonzini{
157909dada40SPaolo Bonzini  return __sync_fetch_and_and(ptr, 0);
158009dada40SPaolo Bonzini}
158109dada40SPaolo Bonzini
158209dada40SPaolo Bonziniint main(void)
158309dada40SPaolo Bonzini{
158409dada40SPaolo Bonzini  int val = 42;
15851405b629SStefan Weil  val = __sync_val_compare_and_swap(&val, 0, 1);
158609dada40SPaolo Bonzini  sfaa(&val);
158709dada40SPaolo Bonzini  return val;
158809dada40SPaolo Bonzini}
158909dada40SPaolo BonziniEOF
159009dada40SPaolo Bonzini  if ! compile_prog "" "" ; then
159109dada40SPaolo Bonzini    QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
159209dada40SPaolo Bonzini  fi
159309dada40SPaolo Bonzinifi
159409dada40SPaolo Bonzini
159556267b62SPhilippe Mathieu-Daudéif test "$tcg" = "enabled"; then
159656267b62SPhilippe Mathieu-Daudé    git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
159756267b62SPhilippe Mathieu-Daudé    git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
159856267b62SPhilippe Mathieu-Daudéfi
159956267b62SPhilippe Mathieu-Daudé
1600afb63ebdSStefan Weilif test -z "${target_list+xxx}" ; then
1601fdb75aefSPaolo Bonzini    default_targets=yes
1602d880a3baSPaolo Bonzini    for target in $default_target_list; do
1603d880a3baSPaolo Bonzini        target_list="$target_list $target"
1604d880a3baSPaolo Bonzini    done
1605d880a3baSPaolo Bonzini    target_list="${target_list# }"
1606121afa9eSAnthony Liguorielse
1607fdb75aefSPaolo Bonzini    default_targets=no
160889138857SStefan Weil    target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1609d880a3baSPaolo Bonzini    for target in $target_list; do
161025b48338SPeter Maydell        # Check that we recognised the target name; this allows a more
161125b48338SPeter Maydell        # friendly error message than if we let it fall through.
161225b48338SPeter Maydell        case " $default_target_list " in
161325b48338SPeter Maydell            *" $target "*)
161425b48338SPeter Maydell                ;;
161525b48338SPeter Maydell            *)
161625b48338SPeter Maydell                error_exit "Unknown target name '$target'"
161725b48338SPeter Maydell                ;;
161825b48338SPeter Maydell        esac
161925b48338SPeter Maydell    done
1620d880a3baSPaolo Bonzinifi
162125b48338SPeter Maydell
1622f55fe278SPaolo Bonzini# see if system emulation was really requested
1623f55fe278SPaolo Bonzinicase " $target_list " in
1624f55fe278SPaolo Bonzini  *"-softmmu "*) softmmu=yes
1625f55fe278SPaolo Bonzini  ;;
1626f55fe278SPaolo Bonzini  *) softmmu=no
1627f55fe278SPaolo Bonzini  ;;
1628f55fe278SPaolo Bonziniesac
16295327cf48Sbellard
1630249247c9SJuan Quintelafeature_not_found() {
1631249247c9SJuan Quintela  feature=$1
163221684af0SStewart Smith  remedy=$2
1633249247c9SJuan Quintela
163476ad07a4SPeter Maydell  error_exit "User requested feature $feature" \
163521684af0SStewart Smith      "configure was not able to find it." \
163621684af0SStewart Smith      "$remedy"
1637249247c9SJuan Quintela}
1638249247c9SJuan Quintela
16397d13299dSbellard# ---
16407d13299dSbellard# big/little endian test
16417d13299dSbellardcat > $TMPC << EOF
1642659eb157SThomas Huth#include <stdio.h>
164361cc919fSMike Frysingershort big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
164461cc919fSMike Frysingershort little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
1645659eb157SThomas Huthint main(int argc, char *argv[])
1646659eb157SThomas Huth{
1647659eb157SThomas Huth    return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
16487d13299dSbellard}
16497d13299dSbellardEOF
16507d13299dSbellard
1651659eb157SThomas Huthif compile_prog ; then
1652659eb157SThomas Huth    if strings -a $TMPE | grep -q BiGeNdIaN ; then
165361cc919fSMike Frysinger        bigendian="yes"
1654659eb157SThomas Huth    elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
165561cc919fSMike Frysinger        bigendian="no"
16567d13299dSbellard    else
16577d13299dSbellard        echo big/little test failed
1658659eb157SThomas Huth        exit 1
16597d13299dSbellard    fi
16607d13299dSbellardelse
166161cc919fSMike Frysinger    echo big/little test failed
1662659eb157SThomas Huth    exit 1
16637d13299dSbellardfi
16647d13299dSbellard
1665299e6f19SPaolo Bonzini#########################################
1666299e6f19SPaolo Bonzini# vhost interdependencies and host support
1667299e6f19SPaolo Bonzini
1668299e6f19SPaolo Bonzini# vhost backends
1669eb9baecdSSergio Lopezif test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then
1670eb9baecdSSergio Lopez  error_exit "vhost-user is not available on Windows"
1671299e6f19SPaolo Bonzinifi
1672108a6481SCindy Lutest "$vhost_vdpa" = "" && vhost_vdpa=$linux
1673108a6481SCindy Luif test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
1674108a6481SCindy Lu  error_exit "vhost-vdpa is only available on Linux"
1675108a6481SCindy Lufi
1676299e6f19SPaolo Bonzinitest "$vhost_kernel" = "" && vhost_kernel=$linux
1677299e6f19SPaolo Bonziniif test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
1678299e6f19SPaolo Bonzini  error_exit "vhost-kernel is only available on Linux"
1679299e6f19SPaolo Bonzinifi
1680299e6f19SPaolo Bonzini
1681299e6f19SPaolo Bonzini# vhost-kernel devices
1682299e6f19SPaolo Bonzinitest "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
1683299e6f19SPaolo Bonziniif test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
1684299e6f19SPaolo Bonzini  error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
1685299e6f19SPaolo Bonzinifi
1686299e6f19SPaolo Bonzinitest "$vhost_vsock" = "" && vhost_vsock=$vhost_kernel
1687299e6f19SPaolo Bonziniif test "$vhost_vsock" = "yes" && test "$vhost_kernel" != "yes"; then
1688299e6f19SPaolo Bonzini  error_exit "--enable-vhost-vsock requires --enable-vhost-kernel"
1689299e6f19SPaolo Bonzinifi
1690299e6f19SPaolo Bonzini
1691299e6f19SPaolo Bonzini# vhost-user backends
1692299e6f19SPaolo Bonzinitest "$vhost_net_user" = "" && vhost_net_user=$vhost_user
1693299e6f19SPaolo Bonziniif test "$vhost_net_user" = "yes" && test "$vhost_user" = "no"; then
1694299e6f19SPaolo Bonzini  error_exit "--enable-vhost-net-user requires --enable-vhost-user"
1695299e6f19SPaolo Bonzinifi
1696299e6f19SPaolo Bonzinitest "$vhost_crypto" = "" && vhost_crypto=$vhost_user
1697299e6f19SPaolo Bonziniif test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
1698299e6f19SPaolo Bonzini  error_exit "--enable-vhost-crypto requires --enable-vhost-user"
1699299e6f19SPaolo Bonzinifi
170098fc1adaSDr. David Alan Gilberttest "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
170198fc1adaSDr. David Alan Gilbertif test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
170298fc1adaSDr. David Alan Gilbert  error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
170398fc1adaSDr. David Alan Gilbertfi
1704108a6481SCindy Lu#vhost-vdpa backends
1705108a6481SCindy Lutest "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa
1706108a6481SCindy Luif test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then
1707108a6481SCindy Lu  error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa"
1708108a6481SCindy Lufi
1709299e6f19SPaolo Bonzini
171040bc0ca9SLaurent Vivier# OR the vhost-kernel, vhost-vdpa and vhost-user values for simplicity
1711299e6f19SPaolo Bonziniif test "$vhost_net" = ""; then
1712299e6f19SPaolo Bonzini  test "$vhost_net_user" = "yes" && vhost_net=yes
171340bc0ca9SLaurent Vivier  test "$vhost_net_vdpa" = "yes" && vhost_net=yes
1714299e6f19SPaolo Bonzini  test "$vhost_kernel" = "yes" && vhost_net=yes
1715299e6f19SPaolo Bonzinifi
1716299e6f19SPaolo Bonzini
1717015a33bdSGonglei##########################################
1718779ab5e3SStefan Weil# pkg-config probe
1719779ab5e3SStefan Weil
1720779ab5e3SStefan Weilif ! has "$pkg_config_exe"; then
172176ad07a4SPeter Maydell  error_exit "pkg-config binary '$pkg_config_exe' not found"
1722779ab5e3SStefan Weilfi
1723779ab5e3SStefan Weil
1724779ab5e3SStefan Weil##########################################
1725e37630caSaliguori# xen probe
1726e37630caSaliguori
17271badb709SPaolo Bonziniif test "$xen" != "disabled" ; then
1728c1cdd9d5SJuergen Gross  # Check whether Xen library path is specified via --extra-ldflags to avoid
1729c1cdd9d5SJuergen Gross  # overriding this setting with pkg-config output. If not, try pkg-config
1730c1cdd9d5SJuergen Gross  # to obtain all needed flags.
1731c1cdd9d5SJuergen Gross
1732c1cdd9d5SJuergen Gross  if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \
1733c1cdd9d5SJuergen Gross     $pkg_config --exists xencontrol ; then
1734c1cdd9d5SJuergen Gross    xen_ctrl_version="$(printf '%d%02d%02d' \
1735c1cdd9d5SJuergen Gross      $($pkg_config --modversion xencontrol | sed 's/\./ /g') )"
17361badb709SPaolo Bonzini    xen=enabled
17375b6a8f43SMichael Tokarev    xen_pc="xencontrol xenstore xenforeignmemory xengnttab"
1738c1cdd9d5SJuergen Gross    xen_pc="$xen_pc xenevtchn xendevicemodel"
173958ea9a7aSAnthony PERARD    if $pkg_config --exists xentoolcore; then
174058ea9a7aSAnthony PERARD      xen_pc="$xen_pc xentoolcore"
174158ea9a7aSAnthony PERARD    fi
1742582ea95fSMarc-André Lureau    xen_cflags="$($pkg_config --cflags $xen_pc)"
1743582ea95fSMarc-André Lureau    xen_libs="$($pkg_config --libs $xen_pc)"
1744c1cdd9d5SJuergen Gross  else
1745c1cdd9d5SJuergen Gross
17465b6a8f43SMichael Tokarev    xen_libs="-lxenstore -lxenctrl"
1747d9506cabSAnthony PERARD    xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
1748d5b93ddfSAnthony PERARD
174950ced5b3SStefan Weil    # First we test whether Xen headers and libraries are available.
175050ced5b3SStefan Weil    # If no, we are done and there is no Xen support.
175150ced5b3SStefan Weil    # If yes, more tests are run to detect the Xen version.
175250ced5b3SStefan Weil
175350ced5b3SStefan Weil    # Xen (any)
175450ced5b3SStefan Weil    cat > $TMPC <<EOF
175550ced5b3SStefan Weil#include <xenctrl.h>
175650ced5b3SStefan Weilint main(void) {
175750ced5b3SStefan Weil  return 0;
175850ced5b3SStefan Weil}
175950ced5b3SStefan WeilEOF
176050ced5b3SStefan Weil    if ! compile_prog "" "$xen_libs" ; then
176150ced5b3SStefan Weil      # Xen not found
17621badb709SPaolo Bonzini      if test "$xen" = "enabled" ; then
176321684af0SStewart Smith        feature_not_found "xen" "Install xen devel"
176450ced5b3SStefan Weil      fi
17651badb709SPaolo Bonzini      xen=disabled
176650ced5b3SStefan Weil
1767d5b93ddfSAnthony PERARD    # Xen unstable
176869deef08SPeter Maydell    elif
176969deef08SPeter Maydell        cat > $TMPC <<EOF &&
17702cbf8903SRoss Lagerwall#undef XC_WANT_COMPAT_DEVICEMODEL_API
17712cbf8903SRoss Lagerwall#define __XEN_TOOLS__
17722cbf8903SRoss Lagerwall#include <xendevicemodel.h>
1773d3c49ebbSPaul Durrant#include <xenforeignmemory.h>
17742cbf8903SRoss Lagerwallint main(void) {
17752cbf8903SRoss Lagerwall  xendevicemodel_handle *xd;
1776d3c49ebbSPaul Durrant  xenforeignmemory_handle *xfmem;
17772cbf8903SRoss Lagerwall
17782cbf8903SRoss Lagerwall  xd = xendevicemodel_open(0, 0);
17792cbf8903SRoss Lagerwall  xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);
17802cbf8903SRoss Lagerwall
1781d3c49ebbSPaul Durrant  xfmem = xenforeignmemory_open(0, 0);
1782d3c49ebbSPaul Durrant  xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);
1783d3c49ebbSPaul Durrant
17842cbf8903SRoss Lagerwall  return 0;
17852cbf8903SRoss Lagerwall}
17862cbf8903SRoss LagerwallEOF
17872cbf8903SRoss Lagerwall        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
17882cbf8903SRoss Lagerwall      then
17892cbf8903SRoss Lagerwall      xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
17902cbf8903SRoss Lagerwall      xen_ctrl_version=41100
17911badb709SPaolo Bonzini      xen=enabled
17922cbf8903SRoss Lagerwall    elif
17932cbf8903SRoss Lagerwall        cat > $TMPC <<EOF &&
17945ba3d756SIgor Druzhinin#undef XC_WANT_COMPAT_MAP_FOREIGN_API
17955ba3d756SIgor Druzhinin#include <xenforeignmemory.h>
179658ea9a7aSAnthony PERARD#include <xentoolcore.h>
17975ba3d756SIgor Druzhininint main(void) {
17985ba3d756SIgor Druzhinin  xenforeignmemory_handle *xfmem;
17995ba3d756SIgor Druzhinin
18005ba3d756SIgor Druzhinin  xfmem = xenforeignmemory_open(0, 0);
18015ba3d756SIgor Druzhinin  xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
180258ea9a7aSAnthony PERARD  xentoolcore_restrict_all(0);
18035ba3d756SIgor Druzhinin
18045ba3d756SIgor Druzhinin  return 0;
18055ba3d756SIgor Druzhinin}
18065ba3d756SIgor DruzhininEOF
180758ea9a7aSAnthony PERARD        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
18085ba3d756SIgor Druzhinin      then
180958ea9a7aSAnthony PERARD      xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
18105ba3d756SIgor Druzhinin      xen_ctrl_version=41000
18111badb709SPaolo Bonzini      xen=enabled
18125ba3d756SIgor Druzhinin    elif
18135ba3d756SIgor Druzhinin        cat > $TMPC <<EOF &&
1814da8090ccSPaul Durrant#undef XC_WANT_COMPAT_DEVICEMODEL_API
1815da8090ccSPaul Durrant#define __XEN_TOOLS__
1816da8090ccSPaul Durrant#include <xendevicemodel.h>
1817da8090ccSPaul Durrantint main(void) {
1818da8090ccSPaul Durrant  xendevicemodel_handle *xd;
1819da8090ccSPaul Durrant
1820da8090ccSPaul Durrant  xd = xendevicemodel_open(0, 0);
1821da8090ccSPaul Durrant  xendevicemodel_close(xd);
1822da8090ccSPaul Durrant
1823da8090ccSPaul Durrant  return 0;
1824da8090ccSPaul Durrant}
1825da8090ccSPaul DurrantEOF
1826da8090ccSPaul Durrant        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs"
1827da8090ccSPaul Durrant      then
1828da8090ccSPaul Durrant      xen_stable_libs="-lxendevicemodel $xen_stable_libs"
1829f1167ee6SJuergen Gross      xen_ctrl_version=40900
18301badb709SPaolo Bonzini      xen=enabled
1831da8090ccSPaul Durrant    elif
1832da8090ccSPaul Durrant        cat > $TMPC <<EOF &&
18335eeb39c2SIan Campbell/*
18345eeb39c2SIan Campbell * If we have stable libs the we don't want the libxc compat
18355eeb39c2SIan Campbell * layers, regardless of what CFLAGS we may have been given.
1836b6eb9b45SPaulina Szubarczyk *
1837b6eb9b45SPaulina Szubarczyk * Also, check if xengnttab_grant_copy_segment_t is defined and
1838b6eb9b45SPaulina Szubarczyk * grant copy operation is implemented.
1839b6eb9b45SPaulina Szubarczyk */
1840b6eb9b45SPaulina Szubarczyk#undef XC_WANT_COMPAT_EVTCHN_API
1841b6eb9b45SPaulina Szubarczyk#undef XC_WANT_COMPAT_GNTTAB_API
1842b6eb9b45SPaulina Szubarczyk#undef XC_WANT_COMPAT_MAP_FOREIGN_API
1843b6eb9b45SPaulina Szubarczyk#include <xenctrl.h>
1844b6eb9b45SPaulina Szubarczyk#include <xenstore.h>
1845b6eb9b45SPaulina Szubarczyk#include <xenevtchn.h>
1846b6eb9b45SPaulina Szubarczyk#include <xengnttab.h>
1847b6eb9b45SPaulina Szubarczyk#include <xenforeignmemory.h>
1848b6eb9b45SPaulina Szubarczyk#include <stdint.h>
1849b6eb9b45SPaulina Szubarczyk#include <xen/hvm/hvm_info_table.h>
1850b6eb9b45SPaulina Szubarczyk#if !defined(HVM_MAX_VCPUS)
1851b6eb9b45SPaulina Szubarczyk# error HVM_MAX_VCPUS not defined
1852b6eb9b45SPaulina Szubarczyk#endif
1853b6eb9b45SPaulina Szubarczykint main(void) {
1854b6eb9b45SPaulina Szubarczyk  xc_interface *xc = NULL;
1855b6eb9b45SPaulina Szubarczyk  xenforeignmemory_handle *xfmem;
1856b6eb9b45SPaulina Szubarczyk  xenevtchn_handle *xe;
1857b6eb9b45SPaulina Szubarczyk  xengnttab_handle *xg;
1858b6eb9b45SPaulina Szubarczyk  xengnttab_grant_copy_segment_t* seg = NULL;
1859b6eb9b45SPaulina Szubarczyk
1860b6eb9b45SPaulina Szubarczyk  xs_daemon_open();
1861b6eb9b45SPaulina Szubarczyk
1862b6eb9b45SPaulina Szubarczyk  xc = xc_interface_open(0, 0, 0);
1863b6eb9b45SPaulina Szubarczyk  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1864b6eb9b45SPaulina Szubarczyk  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
1865b6eb9b45SPaulina Szubarczyk  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
1866b6eb9b45SPaulina Szubarczyk  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
1867b6eb9b45SPaulina Szubarczyk
1868b6eb9b45SPaulina Szubarczyk  xfmem = xenforeignmemory_open(0, 0);
1869b6eb9b45SPaulina Szubarczyk  xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
1870b6eb9b45SPaulina Szubarczyk
1871b6eb9b45SPaulina Szubarczyk  xe = xenevtchn_open(0, 0);
1872b6eb9b45SPaulina Szubarczyk  xenevtchn_fd(xe);
1873b6eb9b45SPaulina Szubarczyk
1874b6eb9b45SPaulina Szubarczyk  xg = xengnttab_open(0, 0);
1875b6eb9b45SPaulina Szubarczyk  xengnttab_grant_copy(xg, 0, seg);
1876b6eb9b45SPaulina Szubarczyk
1877b6eb9b45SPaulina Szubarczyk  return 0;
1878b6eb9b45SPaulina Szubarczyk}
1879b6eb9b45SPaulina SzubarczykEOF
1880b6eb9b45SPaulina Szubarczyk        compile_prog "" "$xen_libs $xen_stable_libs"
1881b6eb9b45SPaulina Szubarczyk      then
1882f1167ee6SJuergen Gross      xen_ctrl_version=40800
18831badb709SPaolo Bonzini      xen=enabled
1884b6eb9b45SPaulina Szubarczyk    elif
1885b6eb9b45SPaulina Szubarczyk        cat > $TMPC <<EOF &&
1886b6eb9b45SPaulina Szubarczyk/*
1887b6eb9b45SPaulina Szubarczyk * If we have stable libs the we don't want the libxc compat
1888b6eb9b45SPaulina Szubarczyk * layers, regardless of what CFLAGS we may have been given.
18895eeb39c2SIan Campbell */
18905eeb39c2SIan Campbell#undef XC_WANT_COMPAT_EVTCHN_API
18915eeb39c2SIan Campbell#undef XC_WANT_COMPAT_GNTTAB_API
18925eeb39c2SIan Campbell#undef XC_WANT_COMPAT_MAP_FOREIGN_API
18935eeb39c2SIan Campbell#include <xenctrl.h>
18945eeb39c2SIan Campbell#include <xenstore.h>
18955eeb39c2SIan Campbell#include <xenevtchn.h>
18965eeb39c2SIan Campbell#include <xengnttab.h>
18975eeb39c2SIan Campbell#include <xenforeignmemory.h>
18985eeb39c2SIan Campbell#include <stdint.h>
18995eeb39c2SIan Campbell#include <xen/hvm/hvm_info_table.h>
19005eeb39c2SIan Campbell#if !defined(HVM_MAX_VCPUS)
19015eeb39c2SIan Campbell# error HVM_MAX_VCPUS not defined
19025eeb39c2SIan Campbell#endif
19035eeb39c2SIan Campbellint main(void) {
19045eeb39c2SIan Campbell  xc_interface *xc = NULL;
19055eeb39c2SIan Campbell  xenforeignmemory_handle *xfmem;
19065eeb39c2SIan Campbell  xenevtchn_handle *xe;
19075eeb39c2SIan Campbell  xengnttab_handle *xg;
19085eeb39c2SIan Campbell
19095eeb39c2SIan Campbell  xs_daemon_open();
19105eeb39c2SIan Campbell
19115eeb39c2SIan Campbell  xc = xc_interface_open(0, 0, 0);
19125eeb39c2SIan Campbell  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
19135eeb39c2SIan Campbell  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
19145eeb39c2SIan Campbell  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
19155eeb39c2SIan Campbell  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
19165eeb39c2SIan Campbell
19175eeb39c2SIan Campbell  xfmem = xenforeignmemory_open(0, 0);
19185eeb39c2SIan Campbell  xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
19195eeb39c2SIan Campbell
19205eeb39c2SIan Campbell  xe = xenevtchn_open(0, 0);
19215eeb39c2SIan Campbell  xenevtchn_fd(xe);
19225eeb39c2SIan Campbell
19235eeb39c2SIan Campbell  xg = xengnttab_open(0, 0);
19245eeb39c2SIan Campbell  xengnttab_map_grant_ref(xg, 0, 0, 0);
19255eeb39c2SIan Campbell
19265eeb39c2SIan Campbell  return 0;
19275eeb39c2SIan Campbell}
19285eeb39c2SIan CampbellEOF
19295eeb39c2SIan Campbell        compile_prog "" "$xen_libs $xen_stable_libs"
19305eeb39c2SIan Campbell      then
1931f1167ee6SJuergen Gross      xen_ctrl_version=40701
19321badb709SPaolo Bonzini      xen=enabled
1933cdadde39SRoger Pau Monne
1934cdadde39SRoger Pau Monne    # Xen 4.6
1935cdadde39SRoger Pau Monne    elif
1936cdadde39SRoger Pau Monne        cat > $TMPC <<EOF &&
1937cdadde39SRoger Pau Monne#include <xenctrl.h>
1938e108a3c1SAnthony PERARD#include <xenstore.h>
1939d5b93ddfSAnthony PERARD#include <stdint.h>
1940d5b93ddfSAnthony PERARD#include <xen/hvm/hvm_info_table.h>
1941d5b93ddfSAnthony PERARD#if !defined(HVM_MAX_VCPUS)
1942d5b93ddfSAnthony PERARD# error HVM_MAX_VCPUS not defined
1943d5b93ddfSAnthony PERARD#endif
1944d5b93ddfSAnthony PERARDint main(void) {
1945d5b93ddfSAnthony PERARD  xc_interface *xc;
1946d5b93ddfSAnthony PERARD  xs_daemon_open();
1947d5b93ddfSAnthony PERARD  xc = xc_interface_open(0, 0, 0);
1948d5b93ddfSAnthony PERARD  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1949d5b93ddfSAnthony PERARD  xc_gnttab_open(NULL, 0);
1950b87de24eSAnthony PERARD  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
19518688e065SStefano Stabellini  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
1952d8b441a3SJan Beulich  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
195320a544c7SKonrad Rzeszutek Wilk  xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
1954d8b441a3SJan Beulich  return 0;
1955d8b441a3SJan Beulich}
1956d8b441a3SJan BeulichEOF
1957d8b441a3SJan Beulich        compile_prog "" "$xen_libs"
1958d8b441a3SJan Beulich      then
1959f1167ee6SJuergen Gross      xen_ctrl_version=40600
19601badb709SPaolo Bonzini      xen=enabled
1961d8b441a3SJan Beulich
1962d8b441a3SJan Beulich    # Xen 4.5
1963d8b441a3SJan Beulich    elif
1964d8b441a3SJan Beulich        cat > $TMPC <<EOF &&
1965d8b441a3SJan Beulich#include <xenctrl.h>
1966d8b441a3SJan Beulich#include <xenstore.h>
1967d8b441a3SJan Beulich#include <stdint.h>
1968d8b441a3SJan Beulich#include <xen/hvm/hvm_info_table.h>
1969d8b441a3SJan Beulich#if !defined(HVM_MAX_VCPUS)
1970d8b441a3SJan Beulich# error HVM_MAX_VCPUS not defined
1971d8b441a3SJan Beulich#endif
1972d8b441a3SJan Beulichint main(void) {
1973d8b441a3SJan Beulich  xc_interface *xc;
1974d8b441a3SJan Beulich  xs_daemon_open();
1975d8b441a3SJan Beulich  xc = xc_interface_open(0, 0, 0);
1976d8b441a3SJan Beulich  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1977d8b441a3SJan Beulich  xc_gnttab_open(NULL, 0);
1978d8b441a3SJan Beulich  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
1979d8b441a3SJan Beulich  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
19803996e85cSPaul Durrant  xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
19813996e85cSPaul Durrant  return 0;
19823996e85cSPaul Durrant}
19833996e85cSPaul DurrantEOF
19843996e85cSPaul Durrant        compile_prog "" "$xen_libs"
19853996e85cSPaul Durrant      then
1986f1167ee6SJuergen Gross      xen_ctrl_version=40500
19871badb709SPaolo Bonzini      xen=enabled
19883996e85cSPaul Durrant
19893996e85cSPaul Durrant    elif
19903996e85cSPaul Durrant        cat > $TMPC <<EOF &&
19913996e85cSPaul Durrant#include <xenctrl.h>
19923996e85cSPaul Durrant#include <xenstore.h>
19933996e85cSPaul Durrant#include <stdint.h>
19943996e85cSPaul Durrant#include <xen/hvm/hvm_info_table.h>
19953996e85cSPaul Durrant#if !defined(HVM_MAX_VCPUS)
19963996e85cSPaul Durrant# error HVM_MAX_VCPUS not defined
19973996e85cSPaul Durrant#endif
19983996e85cSPaul Durrantint main(void) {
19993996e85cSPaul Durrant  xc_interface *xc;
20003996e85cSPaul Durrant  xs_daemon_open();
20013996e85cSPaul Durrant  xc = xc_interface_open(0, 0, 0);
20023996e85cSPaul Durrant  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
20033996e85cSPaul Durrant  xc_gnttab_open(NULL, 0);
20043996e85cSPaul Durrant  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
20053996e85cSPaul Durrant  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
20068688e065SStefano Stabellini  return 0;
20078688e065SStefano Stabellini}
20088688e065SStefano StabelliniEOF
20098688e065SStefano Stabellini        compile_prog "" "$xen_libs"
201069deef08SPeter Maydell      then
2011f1167ee6SJuergen Gross      xen_ctrl_version=40200
20121badb709SPaolo Bonzini      xen=enabled
20138688e065SStefano Stabellini
2014e37630caSaliguori    else
20151badb709SPaolo Bonzini      if test "$xen" = "enabled" ; then
2016edfb07edSIan Campbell        feature_not_found "xen (unsupported version)" \
2017edfb07edSIan Campbell                          "Install a supported xen (xen 4.2 or newer)"
2018fc321b4bSJuan Quintela      fi
20191badb709SPaolo Bonzini      xen=disabled
2020e37630caSaliguori    fi
2021d5b93ddfSAnthony PERARD
20221badb709SPaolo Bonzini    if test "$xen" = enabled; then
2023f1167ee6SJuergen Gross      if test $xen_ctrl_version -ge 40701  ; then
2024582ea95fSMarc-André Lureau        xen_libs="$xen_libs $xen_stable_libs "
20255eeb39c2SIan Campbell      fi
2026d5b93ddfSAnthony PERARD    fi
2027e37630caSaliguori  fi
2028c1cdd9d5SJuergen Grossfi
2029e37630caSaliguori
2030d661d9a4SJustin Terry (VM)##########################################
20312da776dbSMichael R. Hines# RDMA needs OpenFabrics libraries
20322da776dbSMichael R. Hinesif test "$rdma" != "no" ; then
20332da776dbSMichael R. Hines  cat > $TMPC <<EOF
20342da776dbSMichael R. Hines#include <rdma/rdma_cma.h>
20352da776dbSMichael R. Hinesint main(void) { return 0; }
20362da776dbSMichael R. HinesEOF
2037ef6d4ccdSYuval Shaia  rdma_libs="-lrdmacm -libverbs -libumad"
20382da776dbSMichael R. Hines  if compile_prog "" "$rdma_libs" ; then
20392da776dbSMichael R. Hines    rdma="yes"
20402da776dbSMichael R. Hines  else
20412da776dbSMichael R. Hines    if test "$rdma" = "yes" ; then
20422da776dbSMichael R. Hines        error_exit \
2043ef6d4ccdSYuval Shaia            " OpenFabrics librdmacm/libibverbs/libibumad not present." \
20442da776dbSMichael R. Hines            " Your options:" \
2045ef6d4ccdSYuval Shaia            "  (1) Fast: Install infiniband packages (devel) from your distro." \
20462da776dbSMichael R. Hines            "  (2) Cleanest: Install libraries from www.openfabrics.org" \
20472da776dbSMichael R. Hines            "  (3) Also: Install softiwarp if you don't have RDMA hardware"
20482da776dbSMichael R. Hines    fi
20492da776dbSMichael R. Hines    rdma="no"
20502da776dbSMichael R. Hines  fi
20512da776dbSMichael R. Hinesfi
20522da776dbSMichael R. Hines
205321ab34c9SMarcel Apfelbaum##########################################
205421ab34c9SMarcel Apfelbaum# PVRDMA detection
205521ab34c9SMarcel Apfelbaum
205621ab34c9SMarcel Apfelbaumcat > $TMPC <<EOF &&
205721ab34c9SMarcel Apfelbaum#include <sys/mman.h>
205821ab34c9SMarcel Apfelbaum
205921ab34c9SMarcel Apfelbaumint
206021ab34c9SMarcel Apfelbaummain(void)
206121ab34c9SMarcel Apfelbaum{
206221ab34c9SMarcel Apfelbaum    char buf = 0;
206321ab34c9SMarcel Apfelbaum    void *addr = &buf;
206421ab34c9SMarcel Apfelbaum    addr = mremap(addr, 0, 1, MREMAP_MAYMOVE | MREMAP_FIXED);
206521ab34c9SMarcel Apfelbaum
206621ab34c9SMarcel Apfelbaum    return 0;
206721ab34c9SMarcel Apfelbaum}
206821ab34c9SMarcel ApfelbaumEOF
206921ab34c9SMarcel Apfelbaum
207021ab34c9SMarcel Apfelbaumif test "$rdma" = "yes" ; then
207121ab34c9SMarcel Apfelbaum    case "$pvrdma" in
207221ab34c9SMarcel Apfelbaum    "")
207321ab34c9SMarcel Apfelbaum        if compile_prog "" ""; then
207421ab34c9SMarcel Apfelbaum            pvrdma="yes"
207521ab34c9SMarcel Apfelbaum        else
207621ab34c9SMarcel Apfelbaum            pvrdma="no"
207721ab34c9SMarcel Apfelbaum        fi
207821ab34c9SMarcel Apfelbaum        ;;
207921ab34c9SMarcel Apfelbaum    "yes")
208021ab34c9SMarcel Apfelbaum        if ! compile_prog "" ""; then
208121ab34c9SMarcel Apfelbaum            error_exit "PVRDMA is not supported since mremap is not implemented"
208221ab34c9SMarcel Apfelbaum        fi
208321ab34c9SMarcel Apfelbaum        pvrdma="yes"
208421ab34c9SMarcel Apfelbaum        ;;
208521ab34c9SMarcel Apfelbaum    "no")
208621ab34c9SMarcel Apfelbaum        pvrdma="no"
208721ab34c9SMarcel Apfelbaum        ;;
208821ab34c9SMarcel Apfelbaum    esac
208921ab34c9SMarcel Apfelbaumelse
209021ab34c9SMarcel Apfelbaum    if test "$pvrdma" = "yes" ; then
209121ab34c9SMarcel Apfelbaum        error_exit "PVRDMA requires rdma suppport"
209221ab34c9SMarcel Apfelbaum    fi
209321ab34c9SMarcel Apfelbaum    pvrdma="no"
209421ab34c9SMarcel Apfelbaumfi
209595c6bff3SBenoît Canet
2096ee108585SYuval Shaia# Let's see if enhanced reg_mr is supported
2097ee108585SYuval Shaiaif test "$pvrdma" = "yes" ; then
2098ee108585SYuval Shaia
2099ee108585SYuval Shaiacat > $TMPC <<EOF &&
2100ee108585SYuval Shaia#include <infiniband/verbs.h>
2101ee108585SYuval Shaia
2102ee108585SYuval Shaiaint
2103ee108585SYuval Shaiamain(void)
2104ee108585SYuval Shaia{
2105ee108585SYuval Shaia    struct ibv_mr *mr;
2106ee108585SYuval Shaia    struct ibv_pd *pd = NULL;
2107ee108585SYuval Shaia    size_t length = 10;
2108ee108585SYuval Shaia    uint64_t iova = 0;
2109ee108585SYuval Shaia    int access = 0;
2110ee108585SYuval Shaia    void *addr = NULL;
2111ee108585SYuval Shaia
2112ee108585SYuval Shaia    mr = ibv_reg_mr_iova(pd, addr, length, iova, access);
2113ee108585SYuval Shaia
2114ee108585SYuval Shaia    ibv_dereg_mr(mr);
2115ee108585SYuval Shaia
2116ee108585SYuval Shaia    return 0;
2117ee108585SYuval Shaia}
2118ee108585SYuval ShaiaEOF
2119ee108585SYuval Shaia    if ! compile_prog "" "-libverbs"; then
2120ee108585SYuval Shaia        QEMU_CFLAGS="$QEMU_CFLAGS -DLEGACY_RDMA_REG_MR"
2121ee108585SYuval Shaia    fi
2122ee108585SYuval Shaiafi
2123ee108585SYuval Shaia
212495c6bff3SBenoît Canet##########################################
2125e18df141SAnthony Liguori# glib support probe
2126a52d28afSPaolo Bonzini
2127b4c6036fSDaniel P. Berrangéglib_req_ver=2.56
2128aa0d1f44SPaolo Bonziniglib_modules=gthread-2.0
2129aa0d1f44SPaolo Bonziniif test "$modules" = yes; then
2130a88afc64SGerd Hoffmann    glib_modules="$glib_modules gmodule-export-2.0"
2131b906acacSPaolo Bonzinielif test "$plugins" = "yes"; then
2132b906acacSPaolo Bonzini    glib_modules="$glib_modules gmodule-no-export-2.0"
213354cb65d8SEmilio G. Cotafi
2134e26110cfSFam Zheng
2135aa0d1f44SPaolo Bonzinifor i in $glib_modules; do
2136e26110cfSFam Zheng    if $pkg_config --atleast-version=$glib_req_ver $i; then
213789138857SStefan Weil        glib_cflags=$($pkg_config --cflags $i)
213889138857SStefan Weil        glib_libs=$($pkg_config --libs $i)
2139e18df141SAnthony Liguori    else
2140e26110cfSFam Zheng        error_exit "glib-$glib_req_ver $i is required to compile QEMU"
2141e26110cfSFam Zheng    fi
2142e26110cfSFam Zhengdone
2143e26110cfSFam Zheng
2144215b0c2fSPaolo Bonzini# This workaround is required due to a bug in pkg-config file for glib as it
2145215b0c2fSPaolo Bonzini# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
2146215b0c2fSPaolo Bonzini
2147215b0c2fSPaolo Bonziniif test "$static" = yes && test "$mingw32" = yes; then
2148215b0c2fSPaolo Bonzini    glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
2149215b0c2fSPaolo Bonzinifi
2150215b0c2fSPaolo Bonzini
215120cf7b8eSDenis Plotnikovif ! test "$gio" = "no"; then
215220cf7b8eSDenis Plotnikov    pass=no
2153f876b765SMarc-André Lureau    if $pkg_config --atleast-version=$glib_req_ver gio-2.0; then
2154f876b765SMarc-André Lureau        gio_cflags=$($pkg_config --cflags gio-2.0)
2155f876b765SMarc-André Lureau        gio_libs=$($pkg_config --libs gio-2.0)
215625a97a56SMarc-André Lureau        gdbus_codegen=$($pkg_config --variable=gdbus_codegen gio-2.0)
21575ecfb76cSPaolo Bonzini        if ! has "$gdbus_codegen"; then
21580dba4897SMarc-André Lureau            gdbus_codegen=
21590dba4897SMarc-André Lureau        fi
216076346b62SPeter Maydell        # Check that the libraries actually work -- Ubuntu 18.04 ships
216176346b62SPeter Maydell        # with pkg-config --static --libs data for gio-2.0 that is missing
216276346b62SPeter Maydell        # -lblkid and will give a link error.
216313ceae66SPeter Maydell        cat > $TMPC <<EOF
216413ceae66SPeter Maydell#include <gio/gio.h>
216513ceae66SPeter Maydellint main(void)
216613ceae66SPeter Maydell{
216713ceae66SPeter Maydell    g_dbus_proxy_new_sync(0, 0, 0, 0, 0, 0, 0, 0);
216813ceae66SPeter Maydell    return 0;
216913ceae66SPeter Maydell}
217013ceae66SPeter MaydellEOF
217113ceae66SPeter Maydell        if compile_prog "$gio_cflags" "$gio_libs" ; then
217220cf7b8eSDenis Plotnikov            pass=yes
217376346b62SPeter Maydell        else
217420cf7b8eSDenis Plotnikov            pass=no
2175f876b765SMarc-André Lureau        fi
2176f876b765SMarc-André Lureau
217720cf7b8eSDenis Plotnikov        if test "$pass" = "yes" &&
217820cf7b8eSDenis Plotnikov            $pkg_config --atleast-version=$glib_req_ver gio-unix-2.0; then
217925a97a56SMarc-André Lureau            gio_cflags="$gio_cflags $($pkg_config --cflags gio-unix-2.0)"
218025a97a56SMarc-André Lureau            gio_libs="$gio_libs $($pkg_config --libs gio-unix-2.0)"
218125a97a56SMarc-André Lureau        fi
218220cf7b8eSDenis Plotnikov    fi
218320cf7b8eSDenis Plotnikov
218420cf7b8eSDenis Plotnikov    if test "$pass" = "no"; then
218520cf7b8eSDenis Plotnikov        if test "$gio" = "yes"; then
218620cf7b8eSDenis Plotnikov            feature_not_found "gio" "Install libgio >= 2.0"
218720cf7b8eSDenis Plotnikov        else
218820cf7b8eSDenis Plotnikov            gio=no
218920cf7b8eSDenis Plotnikov        fi
219020cf7b8eSDenis Plotnikov    else
219120cf7b8eSDenis Plotnikov        gio=yes
219220cf7b8eSDenis Plotnikov    fi
219320cf7b8eSDenis Plotnikovfi
219425a97a56SMarc-André Lureau
2195977a82abSDaniel P. Berrange# Sanity check that the current size_t matches the
2196977a82abSDaniel P. Berrange# size that glib thinks it should be. This catches
2197977a82abSDaniel P. Berrange# problems on multi-arch where people try to build
2198977a82abSDaniel P. Berrange# 32-bit QEMU while pointing at 64-bit glib headers
2199977a82abSDaniel P. Berrangecat > $TMPC <<EOF
2200977a82abSDaniel P. Berrange#include <glib.h>
2201977a82abSDaniel P. Berrange#include <unistd.h>
2202977a82abSDaniel P. Berrange
2203977a82abSDaniel P. Berrange#define QEMU_BUILD_BUG_ON(x) \
2204977a82abSDaniel P. Berrange  typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
2205977a82abSDaniel P. Berrange
2206977a82abSDaniel P. Berrangeint main(void) {
2207977a82abSDaniel P. Berrange   QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
2208977a82abSDaniel P. Berrange   return 0;
2209977a82abSDaniel P. Berrange}
2210977a82abSDaniel P. BerrangeEOF
2211977a82abSDaniel P. Berrange
2212215b0c2fSPaolo Bonziniif ! compile_prog "$glib_cflags" "$glib_libs" ; then
2213977a82abSDaniel P. Berrange    error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
2214977a82abSDaniel P. Berrange               "You probably need to set PKG_CONFIG_LIBDIR"\
2215977a82abSDaniel P. Berrange	       "to point to the right pkg-config files for your"\
2216977a82abSDaniel P. Berrange	       "build target"
2217977a82abSDaniel P. Berrangefi
2218977a82abSDaniel P. Berrange
22199bda600bSEric Blake# Silence clang warnings triggered by glib < 2.57.2
22209bda600bSEric Blakecat > $TMPC << EOF
22219bda600bSEric Blake#include <glib.h>
22229bda600bSEric Blaketypedef struct Foo {
22239bda600bSEric Blake    int i;
22249bda600bSEric Blake} Foo;
22259bda600bSEric Blakestatic void foo_free(Foo *f)
22269bda600bSEric Blake{
22279bda600bSEric Blake    g_free(f);
22289bda600bSEric Blake}
22299bda600bSEric BlakeG_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free);
22309bda600bSEric Blakeint main(void) { return 0; }
22319bda600bSEric BlakeEOF
22329bda600bSEric Blakeif ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
22339bda600bSEric Blake    if cc_has_warning_flag "-Wno-unused-function"; then
22349bda600bSEric Blake        glib_cflags="$glib_cflags -Wno-unused-function"
22355770e8afSPaolo Bonzini        CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
22369bda600bSEric Blake    fi
22379bda600bSEric Blakefi
22389bda600bSEric Blake
2239e26110cfSFam Zheng##########################################
2240e26110cfSFam Zheng# SHA command probe for modules
2241e26110cfSFam Zhengif test "$modules" = yes; then
2242e26110cfSFam Zheng    shacmd_probe="sha1sum sha1 shasum"
2243e26110cfSFam Zheng    for c in $shacmd_probe; do
22448ccefb91SFam Zheng        if has $c; then
2245e26110cfSFam Zheng            shacmd="$c"
2246e26110cfSFam Zheng            break
2247e26110cfSFam Zheng        fi
2248e26110cfSFam Zheng    done
2249e26110cfSFam Zheng    if test "$shacmd" = ""; then
2250e26110cfSFam Zheng        error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
2251e26110cfSFam Zheng    fi
2252e18df141SAnthony Liguorifi
2253e18df141SAnthony Liguori
2254e18df141SAnthony Liguori##########################################
2255f652e6afSaurel32# fdt probe
2256e169e1e1SPeter Maydell
2257fbb4121dSPaolo Bonzinicase "$fdt" in
2258fbb4121dSPaolo Bonzini  auto | enabled | internal)
2259fbb4121dSPaolo Bonzini    # Simpler to always update submodule, even if not needed.
2260aef45d51SDaniel P. Berrange    git_submodules="${git_submodules} dtc"
2261fbb4121dSPaolo Bonzini    ;;
2262fbb4121dSPaolo Bonziniesac
2263f652e6afSaurel32
226420ff075bSMichael Walle##########################################
22659d49bcf6SMarkus Armbruster# opengl probe (for sdl2, gtk)
2266b1546f32SGerd Hoffmann
2267da076ffeSGerd Hoffmannif test "$opengl" != "no" ; then
2268bc6a3565SAkihiko Odaki  epoxy=no
2269bc6a3565SAkihiko Odaki  if $pkg_config epoxy; then
2270bc6a3565SAkihiko Odaki    cat > $TMPC << EOF
2271bc6a3565SAkihiko Odaki#include <epoxy/egl.h>
2272bc6a3565SAkihiko Odakiint main(void) { return 0; }
2273bc6a3565SAkihiko OdakiEOF
2274bc6a3565SAkihiko Odaki    if compile_prog "" "" ; then
2275bc6a3565SAkihiko Odaki      epoxy=yes
2276bc6a3565SAkihiko Odaki    fi
2277bc6a3565SAkihiko Odaki  fi
2278bc6a3565SAkihiko Odaki
2279bc6a3565SAkihiko Odaki  if test "$epoxy" = "yes" ; then
2280bc6a3565SAkihiko Odaki    opengl_cflags="$($pkg_config --cflags epoxy)"
2281bc6a3565SAkihiko Odaki    opengl_libs="$($pkg_config --libs epoxy)"
2282da076ffeSGerd Hoffmann    opengl=yes
228320ff075bSMichael Walle  else
2284da076ffeSGerd Hoffmann    if test "$opengl" = "yes" ; then
2285bc6a3565SAkihiko Odaki      feature_not_found "opengl" "Please install epoxy with EGL"
228620ff075bSMichael Walle    fi
2287f676c67eSJeremy White    opengl_cflags=""
2288da076ffeSGerd Hoffmann    opengl_libs=""
2289da076ffeSGerd Hoffmann    opengl=no
229020ff075bSMichael Walle  fi
229120ff075bSMichael Wallefi
229220ff075bSMichael Walle
2293955727d2SCortland Tölva# check for usbfs
2294955727d2SCortland Tölvahave_usbfs=no
2295955727d2SCortland Tölvaif test "$linux_user" = "yes"; then
229696566d09SThomas Petazzoni  cat > $TMPC << EOF
229796566d09SThomas Petazzoni#include <linux/usbdevice_fs.h>
229896566d09SThomas Petazzoni
229996566d09SThomas Petazzoni#ifndef USBDEVFS_GET_CAPABILITIES
230096566d09SThomas Petazzoni#error "USBDEVFS_GET_CAPABILITIES undefined"
230196566d09SThomas Petazzoni#endif
230296566d09SThomas Petazzoni
230396566d09SThomas Petazzoni#ifndef USBDEVFS_DISCONNECT_CLAIM
230496566d09SThomas Petazzoni#error "USBDEVFS_DISCONNECT_CLAIM undefined"
230596566d09SThomas Petazzoni#endif
230696566d09SThomas Petazzoni
230796566d09SThomas Petazzoniint main(void)
230896566d09SThomas Petazzoni{
230996566d09SThomas Petazzoni    return 0;
231096566d09SThomas Petazzoni}
231196566d09SThomas PetazzoniEOF
231296566d09SThomas Petazzoni  if compile_prog "" ""; then
2313955727d2SCortland Tölva    have_usbfs=yes
2314955727d2SCortland Tölva  fi
2315955727d2SCortland Tölvafi
2316751bcc39SMarc-André Lureau
2317de5071c5SBlue Swirl##########################################
23188ca80760SRichard Henderson# capstone
23198ca80760SRichard Henderson
2320e219c499SRichard Hendersoncase "$capstone" in
23218b18cdbfSRichard Henderson  auto | enabled | internal)
23228b18cdbfSRichard Henderson    # Simpler to always update submodule, even if not needed.
2323e219c499SRichard Henderson    git_submodules="${git_submodules} capstone"
2324e219c499SRichard Henderson    ;;
2325e219c499SRichard Hendersonesac
23268ca80760SRichard Henderson
23278ca80760SRichard Henderson##########################################
2328519175a2SAlex Barcelo# check and set a backend for coroutine
2329d0e2fce5SAneesh Kumar K.V
23307c2acc70SPeter Maydell# We prefer ucontext, but it's not always possible. The fallback
233133c53c54SDaniel P. Berrange# is sigcontext. On Windows the only valid backend is the Windows
233233c53c54SDaniel P. Berrange# specific one.
23337c2acc70SPeter Maydell
23347c2acc70SPeter Maydellucontext_works=no
2335d0e2fce5SAneesh Kumar K.Vif test "$darwin" != "yes"; then
2336d0e2fce5SAneesh Kumar K.V  cat > $TMPC << EOF
2337d0e2fce5SAneesh Kumar K.V#include <ucontext.h>
2338cdf84806SPeter Maydell#ifdef __stub_makecontext
2339cdf84806SPeter Maydell#error Ignoring glibc stub makecontext which will always fail
2340cdf84806SPeter Maydell#endif
234175cafad7SStefan Weilint main(void) { makecontext(0, 0, 0); return 0; }
2342d0e2fce5SAneesh Kumar K.VEOF
2343d0e2fce5SAneesh Kumar K.V  if compile_prog "" "" ; then
23447c2acc70SPeter Maydell    ucontext_works=yes
2345d0e2fce5SAneesh Kumar K.V  fi
2346519175a2SAlex Barcelofi
23477c2acc70SPeter Maydell
23487c2acc70SPeter Maydellif test "$coroutine" = ""; then
23497c2acc70SPeter Maydell  if test "$mingw32" = "yes"; then
23507c2acc70SPeter Maydell    coroutine=win32
23517c2acc70SPeter Maydell  elif test "$ucontext_works" = "yes"; then
23527c2acc70SPeter Maydell    coroutine=ucontext
2353519175a2SAlex Barcelo  else
23547c2acc70SPeter Maydell    coroutine=sigaltstack
23557c2acc70SPeter Maydell  fi
23567c2acc70SPeter Maydellelse
23577c2acc70SPeter Maydell  case $coroutine in
23587c2acc70SPeter Maydell  windows)
23597c2acc70SPeter Maydell    if test "$mingw32" != "yes"; then
23607c2acc70SPeter Maydell      error_exit "'windows' coroutine backend only valid for Windows"
23617c2acc70SPeter Maydell    fi
23627c2acc70SPeter Maydell    # Unfortunately the user visible backend name doesn't match the
23637c2acc70SPeter Maydell    # coroutine-*.c filename for this case, so we have to adjust it here.
23647c2acc70SPeter Maydell    coroutine=win32
23657c2acc70SPeter Maydell    ;;
23667c2acc70SPeter Maydell  ucontext)
23677c2acc70SPeter Maydell    if test "$ucontext_works" != "yes"; then
23687c2acc70SPeter Maydell      feature_not_found "ucontext"
23697c2acc70SPeter Maydell    fi
23707c2acc70SPeter Maydell    ;;
237133c53c54SDaniel P. Berrange  sigaltstack)
23727c2acc70SPeter Maydell    if test "$mingw32" = "yes"; then
23737c2acc70SPeter Maydell      error_exit "only the 'windows' coroutine backend is valid for Windows"
23747c2acc70SPeter Maydell    fi
23757c2acc70SPeter Maydell    ;;
23767c2acc70SPeter Maydell  *)
237776ad07a4SPeter Maydell    error_exit "unknown coroutine backend $coroutine"
23787c2acc70SPeter Maydell    ;;
23797c2acc70SPeter Maydell  esac
2380d0e2fce5SAneesh Kumar K.Vfi
2381d0e2fce5SAneesh Kumar K.V
23821e4f6065SDaniele Buono##################################################
23831e4f6065SDaniele Buono# SafeStack
23841e4f6065SDaniele Buono
23851e4f6065SDaniele Buono
23861e4f6065SDaniele Buonoif test "$safe_stack" = "yes"; then
23871e4f6065SDaniele Buonocat > $TMPC << EOF
23881e4f6065SDaniele Buonoint main(int argc, char *argv[])
23891e4f6065SDaniele Buono{
23901e4f6065SDaniele Buono#if ! __has_feature(safe_stack)
23911e4f6065SDaniele Buono#error SafeStack Disabled
23921e4f6065SDaniele Buono#endif
23931e4f6065SDaniele Buono    return 0;
23941e4f6065SDaniele Buono}
23951e4f6065SDaniele BuonoEOF
23961e4f6065SDaniele Buono  flag="-fsanitize=safe-stack"
23971e4f6065SDaniele Buono  # Check that safe-stack is supported and enabled.
23981e4f6065SDaniele Buono  if compile_prog "-Werror $flag" "$flag"; then
23991e4f6065SDaniele Buono    # Flag needed both at compilation and at linking
24001e4f6065SDaniele Buono    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
24011e4f6065SDaniele Buono    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
24021e4f6065SDaniele Buono  else
24031e4f6065SDaniele Buono    error_exit "SafeStack not supported by your compiler"
24041e4f6065SDaniele Buono  fi
24051e4f6065SDaniele Buono  if test "$coroutine" != "ucontext"; then
24061e4f6065SDaniele Buono    error_exit "SafeStack is only supported by the coroutine backend ucontext"
24071e4f6065SDaniele Buono  fi
24081e4f6065SDaniele Buonoelse
24091e4f6065SDaniele Buonocat > $TMPC << EOF
24101e4f6065SDaniele Buonoint main(int argc, char *argv[])
24111e4f6065SDaniele Buono{
24121e4f6065SDaniele Buono#if defined(__has_feature)
24131e4f6065SDaniele Buono#if __has_feature(safe_stack)
24141e4f6065SDaniele Buono#error SafeStack Enabled
24151e4f6065SDaniele Buono#endif
24161e4f6065SDaniele Buono#endif
24171e4f6065SDaniele Buono    return 0;
24181e4f6065SDaniele Buono}
24191e4f6065SDaniele BuonoEOF
24201e4f6065SDaniele Buonoif test "$safe_stack" = "no"; then
24211e4f6065SDaniele Buono  # Make sure that safe-stack is disabled
24221e4f6065SDaniele Buono  if ! compile_prog "-Werror" ""; then
24231e4f6065SDaniele Buono    # SafeStack was already enabled, try to explicitly remove the feature
24241e4f6065SDaniele Buono    flag="-fno-sanitize=safe-stack"
24251e4f6065SDaniele Buono    if ! compile_prog "-Werror $flag" "$flag"; then
24261e4f6065SDaniele Buono      error_exit "Configure cannot disable SafeStack"
24271e4f6065SDaniele Buono    fi
24281e4f6065SDaniele Buono    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
24291e4f6065SDaniele Buono    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
24301e4f6065SDaniele Buono  fi
24311e4f6065SDaniele Buonoelse # "$safe_stack" = ""
24321e4f6065SDaniele Buono  # Set safe_stack to yes or no based on pre-existing flags
24331e4f6065SDaniele Buono  if compile_prog "-Werror" ""; then
24341e4f6065SDaniele Buono    safe_stack="no"
24351e4f6065SDaniele Buono  else
24361e4f6065SDaniele Buono    safe_stack="yes"
24371e4f6065SDaniele Buono    if test "$coroutine" != "ucontext"; then
24381e4f6065SDaniele Buono      error_exit "SafeStack is only supported by the coroutine backend ucontext"
24391e4f6065SDaniele Buono    fi
24401e4f6065SDaniele Buono  fi
24411e4f6065SDaniele Buonofi
24421e4f6065SDaniele Buonofi
24437d992e4dSPeter Lieven
244476a347e1SRichard Henderson########################################
2445f540166bSRichard Henderson# check if __[u]int128_t is usable.
2446f540166bSRichard Henderson
2447f540166bSRichard Hendersonint128=no
2448f540166bSRichard Hendersoncat > $TMPC << EOF
2449f540166bSRichard Henderson__int128_t a;
2450f540166bSRichard Henderson__uint128_t b;
2451f540166bSRichard Hendersonint main (void) {
2452f540166bSRichard Henderson  a = a + b;
2453f540166bSRichard Henderson  b = a * b;
2454464e3671SPeter Maydell  a = a * a;
2455f540166bSRichard Henderson  return 0;
2456f540166bSRichard Henderson}
2457f540166bSRichard HendersonEOF
2458f540166bSRichard Hendersonif compile_prog "" "" ; then
2459f540166bSRichard Henderson    int128=yes
2460f540166bSRichard Hendersonfi
246176a347e1SRichard Henderson
24627ebee43eSRichard Henderson#########################################
24637ebee43eSRichard Henderson# See if 128-bit atomic operations are supported.
24647ebee43eSRichard Henderson
24657ebee43eSRichard Hendersonatomic128=no
24667ebee43eSRichard Hendersonif test "$int128" = "yes"; then
24677ebee43eSRichard Henderson  cat > $TMPC << EOF
24687ebee43eSRichard Hendersonint main(void)
24697ebee43eSRichard Henderson{
24707ebee43eSRichard Henderson  unsigned __int128 x = 0, y = 0;
2471bceac547SThomas Huth  y = __atomic_load(&x, 0);
2472bceac547SThomas Huth  __atomic_store(&x, y, 0);
2473bceac547SThomas Huth  __atomic_compare_exchange(&x, &y, x, 0, 0, 0);
24747ebee43eSRichard Henderson  return 0;
24757ebee43eSRichard Henderson}
24767ebee43eSRichard HendersonEOF
24777ebee43eSRichard Henderson  if compile_prog "" "" ; then
24787ebee43eSRichard Henderson    atomic128=yes
24797ebee43eSRichard Henderson  fi
24807ebee43eSRichard Hendersonfi
24817ebee43eSRichard Henderson
2482e6cd4bb5SRichard Hendersoncmpxchg128=no
2483e633a5c6SEric Blakeif test "$int128" = yes && test "$atomic128" = no; then
2484e6cd4bb5SRichard Henderson  cat > $TMPC << EOF
2485e6cd4bb5SRichard Hendersonint main(void)
2486e6cd4bb5SRichard Henderson{
2487e6cd4bb5SRichard Henderson  unsigned __int128 x = 0, y = 0;
2488e6cd4bb5SRichard Henderson  __sync_val_compare_and_swap_16(&x, y, x);
2489e6cd4bb5SRichard Henderson  return 0;
2490e6cd4bb5SRichard Henderson}
2491e6cd4bb5SRichard HendersonEOF
2492e6cd4bb5SRichard Henderson  if compile_prog "" "" ; then
2493e6cd4bb5SRichard Henderson    cmpxchg128=yes
2494e6cd4bb5SRichard Henderson  fi
2495e6cd4bb5SRichard Hendersonfi
2496e6cd4bb5SRichard Henderson
2497fd0e6053SJohn Snow########################################
2498fd0e6053SJohn Snow# check if ccache is interfering with
2499fd0e6053SJohn Snow# semantic analysis of macros
2500fd0e6053SJohn Snow
25015e4dfd3dSJohn Snowunset CCACHE_CPP2
2502fd0e6053SJohn Snowccache_cpp2=no
2503fd0e6053SJohn Snowcat > $TMPC << EOF
2504fd0e6053SJohn Snowstatic const int Z = 1;
2505fd0e6053SJohn Snow#define fn() ({ Z; })
2506fd0e6053SJohn Snow#define TAUT(X) ((X) == Z)
2507fd0e6053SJohn Snow#define PAREN(X, Y) (X == Y)
2508fd0e6053SJohn Snow#define ID(X) (X)
2509fd0e6053SJohn Snowint main(int argc, char *argv[])
2510fd0e6053SJohn Snow{
2511fd0e6053SJohn Snow    int x = 0, y = 0;
2512fd0e6053SJohn Snow    x = ID(x);
2513fd0e6053SJohn Snow    x = fn();
2514fd0e6053SJohn Snow    fn();
2515fd0e6053SJohn Snow    if (PAREN(x, y)) return 0;
2516fd0e6053SJohn Snow    if (TAUT(Z)) return 0;
2517fd0e6053SJohn Snow    return 0;
2518fd0e6053SJohn Snow}
2519fd0e6053SJohn SnowEOF
2520fd0e6053SJohn Snow
2521fd0e6053SJohn Snowif ! compile_object "-Werror"; then
2522fd0e6053SJohn Snow    ccache_cpp2=yes
2523fd0e6053SJohn Snowfi
2524fd0e6053SJohn Snow
2525b553a042SJohn Snow#################################################
2526b553a042SJohn Snow# clang does not support glibc + FORTIFY_SOURCE.
2527b553a042SJohn Snow
2528b553a042SJohn Snowif test "$fortify_source" != "no"; then
2529b553a042SJohn Snow  if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
2530b553a042SJohn Snow    fortify_source="no";
2531e189091fSPeter Maydell  elif test -n "$cxx" && has $cxx &&
2532cfcc7c14SJohn Snow       echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
2533b553a042SJohn Snow    fortify_source="no";
2534b553a042SJohn Snow  else
2535b553a042SJohn Snow    fortify_source="yes"
2536b553a042SJohn Snow  fi
2537b553a042SJohn Snowfi
2538b553a042SJohn Snow
2539d2042378SAneesh Kumar K.V##########################################
2540247724cbSMarc-André Lureau# checks for sanitizers
2541247724cbSMarc-André Lureau
2542247724cbSMarc-André Lureauhave_asan=no
2543247724cbSMarc-André Lureauhave_ubsan=no
2544d83414e1SMarc-André Lureauhave_asan_iface_h=no
2545d83414e1SMarc-André Lureauhave_asan_iface_fiber=no
2546247724cbSMarc-André Lureau
2547247724cbSMarc-André Lureauif test "$sanitizers" = "yes" ; then
2548b9f44da2SMarc-André Lureau  write_c_skeleton
2549247724cbSMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
2550247724cbSMarc-André Lureau      have_asan=yes
2551247724cbSMarc-André Lureau  fi
2552b9f44da2SMarc-André Lureau
2553b9f44da2SMarc-André Lureau  # we could use a simple skeleton for flags checks, but this also
2554b9f44da2SMarc-André Lureau  # detect the static linking issue of ubsan, see also:
2555b9f44da2SMarc-André Lureau  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
2556b9f44da2SMarc-André Lureau  cat > $TMPC << EOF
2557b9f44da2SMarc-André Lureau#include <stdlib.h>
2558b9f44da2SMarc-André Lureauint main(void) {
2559b9f44da2SMarc-André Lureau    void *tmp = malloc(10);
2560f2dfe54cSLeonid Bloch    if (tmp != NULL) {
2561b9f44da2SMarc-André Lureau        return *(int *)(tmp + 2);
2562b9f44da2SMarc-André Lureau    }
2563d1abf3fcSOlaf Hering    return 1;
2564f2dfe54cSLeonid Bloch}
2565b9f44da2SMarc-André LureauEOF
2566247724cbSMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
2567247724cbSMarc-André Lureau      have_ubsan=yes
2568247724cbSMarc-André Lureau  fi
2569d83414e1SMarc-André Lureau
2570d83414e1SMarc-André Lureau  if check_include "sanitizer/asan_interface.h" ; then
2571d83414e1SMarc-André Lureau      have_asan_iface_h=yes
2572d83414e1SMarc-André Lureau  fi
2573d83414e1SMarc-André Lureau
2574d83414e1SMarc-André Lureau  cat > $TMPC << EOF
2575d83414e1SMarc-André Lureau#include <sanitizer/asan_interface.h>
2576d83414e1SMarc-André Lureauint main(void) {
2577d83414e1SMarc-André Lureau  __sanitizer_start_switch_fiber(0, 0, 0);
2578d83414e1SMarc-André Lureau  return 0;
2579d83414e1SMarc-André Lureau}
2580d83414e1SMarc-André LureauEOF
2581d83414e1SMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
2582d83414e1SMarc-André Lureau      have_asan_iface_fiber=yes
2583d83414e1SMarc-André Lureau  fi
2584247724cbSMarc-André Lureaufi
2585247724cbSMarc-André Lureau
25860aebab04SLingfeng Yang# Thread sanitizer is, for now, much noisier than the other sanitizers;
25870aebab04SLingfeng Yang# keep it separate until that is not the case.
25880aebab04SLingfeng Yangif test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
25890aebab04SLingfeng Yang  error_exit "TSAN is not supported with other sanitiziers."
25900aebab04SLingfeng Yangfi
25910aebab04SLingfeng Yanghave_tsan=no
25920aebab04SLingfeng Yanghave_tsan_iface_fiber=no
25930aebab04SLingfeng Yangif test "$tsan" = "yes" ; then
25940aebab04SLingfeng Yang  write_c_skeleton
25950aebab04SLingfeng Yang  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
25960aebab04SLingfeng Yang      have_tsan=yes
25970aebab04SLingfeng Yang  fi
25980aebab04SLingfeng Yang  cat > $TMPC << EOF
25990aebab04SLingfeng Yang#include <sanitizer/tsan_interface.h>
26000aebab04SLingfeng Yangint main(void) {
26010aebab04SLingfeng Yang  __tsan_create_fiber(0);
26020aebab04SLingfeng Yang  return 0;
26030aebab04SLingfeng Yang}
26040aebab04SLingfeng YangEOF
26050aebab04SLingfeng Yang  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
26060aebab04SLingfeng Yang      have_tsan_iface_fiber=yes
26070aebab04SLingfeng Yang  fi
26080aebab04SLingfeng Yangfi
26090aebab04SLingfeng Yang
2610adc28027SAlexander Bulekov##########################################
2611675b9b53SMarc-André Lureau# check for slirp
2612675b9b53SMarc-André Lureau
2613675b9b53SMarc-André Lureaucase "$slirp" in
26144d34a86bSPaolo Bonzini  auto | enabled | internal)
26154d34a86bSPaolo Bonzini    # Simpler to always update submodule, even if not needed.
26167c57bdd8SMarc-André Lureau    git_submodules="${git_submodules} slirp"
2617675b9b53SMarc-André Lureau    ;;
2618675b9b53SMarc-André Lureauesac
2619675b9b53SMarc-André Lureau
262054e7aac0SAlexey Krasikov##########################################
262154e7aac0SAlexey Krasikov# check for usable __NR_keyctl syscall
262254e7aac0SAlexey Krasikov
262354e7aac0SAlexey Krasikovif test "$linux" = "yes" ; then
262454e7aac0SAlexey Krasikov
262554e7aac0SAlexey Krasikov    have_keyring=no
262654e7aac0SAlexey Krasikov    cat > $TMPC << EOF
262754e7aac0SAlexey Krasikov#include <errno.h>
262854e7aac0SAlexey Krasikov#include <asm/unistd.h>
262954e7aac0SAlexey Krasikov#include <linux/keyctl.h>
263054e7aac0SAlexey Krasikov#include <unistd.h>
263154e7aac0SAlexey Krasikovint main(void) {
263254e7aac0SAlexey Krasikov    return syscall(__NR_keyctl, KEYCTL_READ, 0, NULL, NULL, 0);
263354e7aac0SAlexey Krasikov}
263454e7aac0SAlexey KrasikovEOF
263554e7aac0SAlexey Krasikov    if compile_prog "" "" ; then
263654e7aac0SAlexey Krasikov        have_keyring=yes
263754e7aac0SAlexey Krasikov    fi
263854e7aac0SAlexey Krasikovfi
263954e7aac0SAlexey Krasikovif test "$secret_keyring" != "no"
264054e7aac0SAlexey Krasikovthen
2641b418d265SDavid Edmondson    if test "$have_keyring" = "yes"
264254e7aac0SAlexey Krasikov    then
264354e7aac0SAlexey Krasikov	secret_keyring=yes
264454e7aac0SAlexey Krasikov    else
264554e7aac0SAlexey Krasikov	if test "$secret_keyring" = "yes"
264654e7aac0SAlexey Krasikov	then
264754e7aac0SAlexey Krasikov	    error_exit "syscall __NR_keyctl requested, \
264854e7aac0SAlexey Krasikovbut not implemented on your system"
264954e7aac0SAlexey Krasikov	else
265054e7aac0SAlexey Krasikov	    secret_keyring=no
265154e7aac0SAlexey Krasikov	fi
265254e7aac0SAlexey Krasikov    fi
265354e7aac0SAlexey Krasikovfi
265454e7aac0SAlexey Krasikov
265592500362SAlexey Krasikov##########################################
2656e86ecd4bSJuan Quintela# End of CC checks
2657e86ecd4bSJuan Quintela# After here, no more $cc or $ld runs
2658e86ecd4bSJuan Quintela
2659d83414e1SMarc-André Lureauwrite_c_skeleton
2660d83414e1SMarc-André Lureau
26611d728c39SBlue Swirlif test "$gcov" = "yes" ; then
2662bf0e56a3SMarc-André Lureau  :
2663b553a042SJohn Snowelif test "$fortify_source" = "yes" ; then
2664086d5f75SPaolo Bonzini  QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
2665086d5f75SPaolo Bonzini  debug=no
2666086d5f75SPaolo Bonzinifi
2667086d5f75SPaolo Bonzini
2668086d5f75SPaolo Bonzinicase "$ARCH" in
2669086d5f75SPaolo Bonzinialpha)
2670086d5f75SPaolo Bonzini  # Ensure there's only a single GP
2671086d5f75SPaolo Bonzini  QEMU_CFLAGS="-msmall-data $QEMU_CFLAGS"
2672086d5f75SPaolo Bonzini;;
2673086d5f75SPaolo Bonziniesac
2674086d5f75SPaolo Bonzini
2675247724cbSMarc-André Lureauif test "$have_asan" = "yes"; then
2676db5adeaaSPaolo Bonzini  QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
2677db5adeaaSPaolo Bonzini  QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
2678d83414e1SMarc-André Lureau  if test "$have_asan_iface_h" = "no" ; then
2679d83414e1SMarc-André Lureau      echo "ASAN build enabled, but ASAN header missing." \
2680d83414e1SMarc-André Lureau           "Without code annotation, the report may be inferior."
2681d83414e1SMarc-André Lureau  elif test "$have_asan_iface_fiber" = "no" ; then
2682d83414e1SMarc-André Lureau      echo "ASAN build enabled, but ASAN header is too old." \
2683d83414e1SMarc-André Lureau           "Without code annotation, the report may be inferior."
2684d83414e1SMarc-André Lureau  fi
2685247724cbSMarc-André Lureaufi
26860aebab04SLingfeng Yangif test "$have_tsan" = "yes" ; then
26870aebab04SLingfeng Yang  if test "$have_tsan_iface_fiber" = "yes" ; then
26880aebab04SLingfeng Yang    QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
26890aebab04SLingfeng Yang    QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
26900aebab04SLingfeng Yang  else
26910aebab04SLingfeng Yang    error_exit "Cannot enable TSAN due to missing fiber annotation interface."
26920aebab04SLingfeng Yang  fi
26930aebab04SLingfeng Yangelif test "$tsan" = "yes" ; then
26940aebab04SLingfeng Yang  error_exit "Cannot enable TSAN due to missing sanitize thread interface."
26950aebab04SLingfeng Yangfi
2696247724cbSMarc-André Lureauif test "$have_ubsan" = "yes"; then
2697db5adeaaSPaolo Bonzini  QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
2698db5adeaaSPaolo Bonzini  QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
2699247724cbSMarc-André Lureaufi
2700247724cbSMarc-André Lureau
27016542aa9cSPeter Lieven##########################################
27023efac6ebSTomáš Golembiovský
27030aebab04SLingfeng Yang# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
27040aebab04SLingfeng Yangif test "$solaris" = "no" && test "$tsan" = "no"; then
2705e86ecd4bSJuan Quintela    if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
2706db5adeaaSPaolo Bonzini        QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
2707e86ecd4bSJuan Quintela    fi
2708e86ecd4bSJuan Quintelafi
2709e86ecd4bSJuan Quintela
2710952afb71SBlue Swirl# Use ASLR, no-SEH and DEP if available
2711952afb71SBlue Swirlif test "$mingw32" = "yes" ; then
2712cb8baa77SMark Cave-Ayland    flags="--no-seh --nxcompat"
2713cb8baa77SMark Cave-Ayland
2714cb8baa77SMark Cave-Ayland    # Disable ASLR for debug builds to allow debugging with gdb
2715cb8baa77SMark Cave-Ayland    if test "$debug" = "no" ; then
2716cb8baa77SMark Cave-Ayland        flags="--dynamicbase $flags"
2717cb8baa77SMark Cave-Ayland    fi
2718cb8baa77SMark Cave-Ayland
2719cb8baa77SMark Cave-Ayland    for flag in $flags; do
2720e9a3591fSChristian Borntraeger        if ld_has $flag ; then
2721db5adeaaSPaolo Bonzini            QEMU_LDFLAGS="-Wl,$flag $QEMU_LDFLAGS"
2722952afb71SBlue Swirl        fi
2723952afb71SBlue Swirl    done
2724952afb71SBlue Swirlfi
2725952afb71SBlue Swirl
2726b846ab7cSPaolo Bonzini# Guest agent Windows MSI package
27279d6bc27bSMichael Roth
27289d6bc27bSMichael Rothif test "$QEMU_GA_MANUFACTURER" = ""; then
27299d6bc27bSMichael Roth  QEMU_GA_MANUFACTURER=QEMU
27309d6bc27bSMichael Rothfi
27319d6bc27bSMichael Rothif test "$QEMU_GA_DISTRO" = ""; then
27329d6bc27bSMichael Roth  QEMU_GA_DISTRO=Linux
27339d6bc27bSMichael Rothfi
27349d6bc27bSMichael Rothif test "$QEMU_GA_VERSION" = ""; then
273589138857SStefan Weil    QEMU_GA_VERSION=$(cat $source_path/VERSION)
27369d6bc27bSMichael Rothfi
27379d6bc27bSMichael Roth
2738b846ab7cSPaolo BonziniQEMU_GA_MSI_MINGW_DLL_PATH="$($pkg_config --variable=prefix glib-2.0)/bin"
27399d6bc27bSMichael Roth
2740ca35f780SPaolo Bonzini# Mac OS X ships with a broken assembler
2741ca35f780SPaolo Bonziniroms=
2742e633a5c6SEric Blakeif { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \
2743ba7c60c2SPaolo Bonzini        test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
2744ba7c60c2SPaolo Bonzini        test "$targetos" != "haiku" && test "$softmmu" = yes ; then
2745e57218b6SPeter Maydell    # Different host OS linkers have different ideas about the name of the ELF
2746c65d5e4eSBrad Smith    # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
2747c65d5e4eSBrad Smith    # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
2748c65d5e4eSBrad Smith    for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
2749e57218b6SPeter Maydell        if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
2750e57218b6SPeter Maydell            ld_i386_emulation="$emu"
2751ca35f780SPaolo Bonzini            roms="optionrom"
2752e57218b6SPeter Maydell            break
2753e57218b6SPeter Maydell        fi
2754e57218b6SPeter Maydell    done
2755ca35f780SPaolo Bonzinifi
2756ca35f780SPaolo Bonzini
27572e33c3f8SThomas Huth# Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
2758a5b2afd5SThomas Huth# or -march=z10 (which is the lowest architecture level that Clang supports)
27599933c305SChristian Borntraegerif test "$cpu" = "s390x" ; then
27602e33c3f8SThomas Huth  write_c_skeleton
2761a5b2afd5SThomas Huth  compile_prog "-march=z900" ""
2762a5b2afd5SThomas Huth  has_z900=$?
27633af448b3SThomas Huth  if [ $has_z900 = 0 ] || compile_object "-march=z10 -msoft-float -Werror"; then
2764a5b2afd5SThomas Huth    if [ $has_z900 != 0 ]; then
2765a5b2afd5SThomas Huth      echo "WARNING: Your compiler does not support the z900!"
2766a5b2afd5SThomas Huth      echo "         The s390-ccw bios will only work with guest CPUs >= z10."
2767a5b2afd5SThomas Huth    fi
27689933c305SChristian Borntraeger    roms="$roms s390-ccw"
27691ef6bfc2SPhilippe Mathieu-Daudé    # SLOF is required for building the s390-ccw firmware on s390x,
27701ef6bfc2SPhilippe Mathieu-Daudé    # since it is using the libnet code from SLOF for network booting.
27711ef6bfc2SPhilippe Mathieu-Daudé    git_submodules="${git_submodules} roms/SLOF"
27721ef6bfc2SPhilippe Mathieu-Daudé  fi
27739933c305SChristian Borntraegerfi
27749933c305SChristian Borntraeger
277511cde1c8SBruno Dominguez# Check that the C++ compiler exists and works with the C compiler.
277611cde1c8SBruno 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.
277711cde1c8SBruno Dominguezif has $cxx; then
277811cde1c8SBruno Dominguez    cat > $TMPC <<EOF
277911cde1c8SBruno Dominguezint c_function(void);
278011cde1c8SBruno Dominguezint main(void) { return c_function(); }
278111cde1c8SBruno DominguezEOF
278211cde1c8SBruno Dominguez
278311cde1c8SBruno Dominguez    compile_object
278411cde1c8SBruno Dominguez
278511cde1c8SBruno Dominguez    cat > $TMPCXX <<EOF
278611cde1c8SBruno Dominguezextern "C" {
278711cde1c8SBruno Dominguez   int c_function(void);
278811cde1c8SBruno Dominguez}
278911cde1c8SBruno Dominguezint c_function(void) { return 42; }
279011cde1c8SBruno DominguezEOF
279111cde1c8SBruno Dominguez
279211cde1c8SBruno Dominguez    update_cxxflags
279311cde1c8SBruno Dominguez
2794a2866660SPaolo Bonzini    if do_cxx $CXXFLAGS $EXTRA_CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
279511cde1c8SBruno Dominguez        # C++ compiler $cxx works ok with C compiler $cc
279611cde1c8SBruno Dominguez        :
279711cde1c8SBruno Dominguez    else
279811cde1c8SBruno Dominguez        echo "C++ compiler $cxx does not work with C compiler $cc"
279911cde1c8SBruno Dominguez        echo "Disabling C++ specific optional code"
280011cde1c8SBruno Dominguez        cxx=
280111cde1c8SBruno Dominguez    fi
280211cde1c8SBruno Dominguezelse
280311cde1c8SBruno Dominguez    echo "No C++ compiler available; disabling C++ specific optional code"
280411cde1c8SBruno Dominguez    cxx=
280511cde1c8SBruno Dominguezfi
280611cde1c8SBruno Dominguez
28077d7dbf9dSDan Streetmanif !(GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
28087d7dbf9dSDan Streetman    exit 1
28095d91a2edSYonggang Luofi
28105d91a2edSYonggang Luo
281198ec69acSJuan Quintelaconfig_host_mak="config-host.mak"
281297a847bcSbellard
281398ec69acSJuan Quintelaecho "# Automatically generated by configure - do not modify" > $config_host_mak
281498ec69acSJuan Quintelaecho >> $config_host_mak
281598ec69acSJuan Quintela
2816e6c3b0f7SPaolo Bonziniecho all: >> $config_host_mak
2817cc84d63aSDaniel P. Berrangeecho "GIT=$git" >> $config_host_mak
2818aef45d51SDaniel P. Berrangeecho "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
28197d7dbf9dSDan Streetmanecho "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
2820804edf29SJuan Quintela
2821f8393946Saurel32if test "$debug_tcg" = "yes" ; then
28222358a494SJuan Quintela  echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
2823f8393946Saurel32fi
282467b915a5Sbellardif test "$mingw32" = "yes" ; then
282598ec69acSJuan Quintela  echo "CONFIG_WIN32=y" >> $config_host_mak
28269dacf32dSYossi Hindin  echo "QEMU_GA_MSI_MINGW_DLL_PATH=${QEMU_GA_MSI_MINGW_DLL_PATH}" >> $config_host_mak
28279dacf32dSYossi Hindin  echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
28289dacf32dSYossi Hindin  echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
28299dacf32dSYossi Hindin  echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
2830210fa556Spbrookelse
283135f4df27SJuan Quintela  echo "CONFIG_POSIX=y" >> $config_host_mak
2832210fa556Spbrookfi
2833128ab2ffSblueswir1
2834dffcb71cSMark McLoughlinif test "$linux" = "yes" ; then
2835dffcb71cSMark McLoughlin  echo "CONFIG_LINUX=y" >> $config_host_mak
2836dffcb71cSMark McLoughlinfi
2837dffcb71cSMark McLoughlin
283883fb7adfSbellardif test "$darwin" = "yes" ; then
283998ec69acSJuan Quintela  echo "CONFIG_DARWIN=y" >> $config_host_mak
284083fb7adfSbellardfi
2841b29fe3edSmalc
2842ec530c81Sbellardif test "$solaris" = "yes" ; then
284398ec69acSJuan Quintela  echo "CONFIG_SOLARIS=y" >> $config_host_mak
2844ec530c81Sbellardfi
284597a847bcSbellardif test "$static" = "yes" ; then
284698ec69acSJuan Quintela  echo "CONFIG_STATIC=y" >> $config_host_mak
284797a847bcSbellardfi
2848b64ec4e4SFam Zhengecho "CONFIG_BDRV_RW_WHITELIST=$block_drv_rw_whitelist" >> $config_host_mak
2849b64ec4e4SFam Zhengecho "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
285089138857SStefan Weilqemu_version=$(head $source_path/VERSION)
28512358a494SJuan Quintelaecho "PKGVERSION=$pkgversion" >>$config_host_mak
285298ec69acSJuan Quintelaecho "SRC_PATH=$source_path" >> $config_host_mak
28532b1f35b9SAlex Bennéeecho "TARGET_DIRS=$target_list" >> $config_host_mak
285417969268SFam Zhengif test "$modules" = "yes"; then
2855e26110cfSFam Zheng  # $shacmd can generate a hash started with digit, which the compiler doesn't
2856e26110cfSFam Zheng  # like as an symbol. So prefix it with an underscore
285789138857SStefan Weil  echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
285817969268SFam Zheng  echo "CONFIG_MODULES=y" >> $config_host_mak
285917969268SFam Zhengfi
2860bd83c861SChristian Ehrhardtif test "$module_upgrades" = "yes"; then
2861bd83c861SChristian Ehrhardt  echo "CONFIG_MODULE_UPGRADES=y" >> $config_host_mak
2862bd83c861SChristian Ehrhardtfi
2863955727d2SCortland Tölvaif test "$have_usbfs" = "yes" ; then
2864955727d2SCortland Tölva  echo "CONFIG_USBFS=y" >> $config_host_mak
2865955727d2SCortland Tölvafi
2866f876b765SMarc-André Lureauif test "$gio" = "yes" ; then
2867f876b765SMarc-André Lureau    echo "CONFIG_GIO=y" >> $config_host_mak
2868f876b765SMarc-André Lureau    echo "GIO_CFLAGS=$gio_cflags" >> $config_host_mak
2869f876b765SMarc-André Lureau    echo "GIO_LIBS=$gio_libs" >> $config_host_mak
28705ecfb76cSPaolo Bonzinifi
28715ecfb76cSPaolo Bonziniif test "$gdbus_codegen" != "" ; then
287225a97a56SMarc-André Lureau    echo "GDBUS_CODEGEN=$gdbus_codegen" >> $config_host_mak
2873f876b765SMarc-André Lureaufi
2874a1c5e949SDaniel P. Berrangeecho "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak
2875277abf15SJan Vesely
28761badb709SPaolo Bonziniif test "$xen" = "enabled" ; then
28776dbd588aSJan Kiszka  echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
2878d5b93ddfSAnthony PERARD  echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
2879582ea95fSMarc-André Lureau  echo "XEN_CFLAGS=$xen_cflags" >> $config_host_mak
2880582ea95fSMarc-André Lureau  echo "XEN_LIBS=$xen_libs" >> $config_host_mak
2881e37630caSaliguorifi
28825e9be92dSNicholas Bellingerif test "$vhost_scsi" = "yes" ; then
28835e9be92dSNicholas Bellinger  echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
28845e9be92dSNicholas Bellingerfi
2885af3bba76SPaolo Bonziniif test "$vhost_net" = "yes" ; then
2886af3bba76SPaolo Bonzini  echo "CONFIG_VHOST_NET=y" >> $config_host_mak
2887af3bba76SPaolo Bonzinifi
2888af3bba76SPaolo Bonziniif test "$vhost_net_user" = "yes" ; then
288956f41de7SPaolo Bonzini  echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak
289003ce5744SNikolay Nikolaevfi
2891108a6481SCindy Luif test "$vhost_net_vdpa" = "yes" ; then
2892108a6481SCindy Lu  echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak
2893108a6481SCindy Lufi
2894042cea27SGongleiif test "$vhost_crypto" = "yes" ; then
2895042cea27SGonglei  echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
2896042cea27SGongleifi
2897fc0b9b0eSStefan Hajnocziif test "$vhost_vsock" = "yes" ; then
2898fc0b9b0eSStefan Hajnoczi  echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
28995fe97d88SStefano Garzarella  if test "$vhost_user" = "yes" ; then
29005fe97d88SStefano Garzarella    echo "CONFIG_VHOST_USER_VSOCK=y" >> $config_host_mak
29015fe97d88SStefano Garzarella  fi
2902fc0b9b0eSStefan Hajnoczifi
2903299e6f19SPaolo Bonziniif test "$vhost_kernel" = "yes" ; then
2904299e6f19SPaolo Bonzini  echo "CONFIG_VHOST_KERNEL=y" >> $config_host_mak
2905299e6f19SPaolo Bonzinifi
2906e6a74868SMarc-André Lureauif test "$vhost_user" = "yes" ; then
2907e6a74868SMarc-André Lureau  echo "CONFIG_VHOST_USER=y" >> $config_host_mak
2908e6a74868SMarc-André Lureaufi
2909108a6481SCindy Luif test "$vhost_vdpa" = "yes" ; then
2910108a6481SCindy Lu  echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
2911108a6481SCindy Lufi
291298fc1adaSDr. David Alan Gilbertif test "$vhost_user_fs" = "yes" ; then
291398fc1adaSDr. David Alan Gilbert  echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak
291498fc1adaSDr. David Alan Gilbertfi
2915e5b46549SRichard Hendersonif test "$tcg" = "enabled" -a "$tcg_interpreter" = "true" ; then
2916e5b46549SRichard Henderson  echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
2917e5b46549SRichard Hendersonfi
291858d3f3ffSGerd Hoffmann
2919da076ffeSGerd Hoffmannif test "$opengl" = "yes" ; then
2920da076ffeSGerd Hoffmann  echo "CONFIG_OPENGL=y" >> $config_host_mak
2921de2d3005SPaolo Bonzini  echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
2922da076ffeSGerd Hoffmann  echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
292320ff075bSMichael Wallefi
292420ff075bSMichael Walle
292583fb7adfSbellard# XXX: suppress that
29267d3505c5Sbellardif [ "$bsd" = "yes" ] ; then
29272358a494SJuan Quintela  echo "CONFIG_BSD=y" >> $config_host_mak
29287d3505c5Sbellardfi
29297d3505c5Sbellard
29307c2acc70SPeter Maydellecho "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
29317d992e4dSPeter Lieven
2932d83414e1SMarc-André Lureauif test "$have_asan_iface_fiber" = "yes" ; then
2933d83414e1SMarc-André Lureau    echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
2934d83414e1SMarc-André Lureaufi
2935d83414e1SMarc-André Lureau
29360aebab04SLingfeng Yangif test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
29370aebab04SLingfeng Yang    echo "CONFIG_TSAN=y" >> $config_host_mak
29380aebab04SLingfeng Yangfi
29390aebab04SLingfeng Yang
2940f540166bSRichard Hendersonif test "$int128" = "yes" ; then
2941f540166bSRichard Henderson  echo "CONFIG_INT128=y" >> $config_host_mak
2942f540166bSRichard Hendersonfi
2943f540166bSRichard Henderson
29447ebee43eSRichard Hendersonif test "$atomic128" = "yes" ; then
29457ebee43eSRichard Henderson  echo "CONFIG_ATOMIC128=y" >> $config_host_mak
29467ebee43eSRichard Hendersonfi
29477ebee43eSRichard Henderson
2948e6cd4bb5SRichard Hendersonif test "$cmpxchg128" = "yes" ; then
2949e6cd4bb5SRichard Henderson  echo "CONFIG_CMPXCHG128=y" >> $config_host_mak
2950e6cd4bb5SRichard Hendersonfi
2951e6cd4bb5SRichard Henderson
29522da776dbSMichael R. Hinesif test "$rdma" = "yes" ; then
29532da776dbSMichael R. Hines  echo "CONFIG_RDMA=y" >> $config_host_mak
2954392fb643SFam Zheng  echo "RDMA_LIBS=$rdma_libs" >> $config_host_mak
29552da776dbSMichael R. Hinesfi
29562da776dbSMichael R. Hines
295721ab34c9SMarcel Apfelbaumif test "$pvrdma" = "yes" ; then
295821ab34c9SMarcel Apfelbaum  echo "CONFIG_PVRDMA=y" >> $config_host_mak
295921ab34c9SMarcel Apfelbaumfi
296021ab34c9SMarcel Apfelbaum
296140e8c6f4SAlex Bennéeif test "$plugins" = "yes" ; then
296240e8c6f4SAlex Bennée    echo "CONFIG_PLUGIN=y" >> $config_host_mak
296340e8c6f4SAlex Bennéefi
296440e8c6f4SAlex Bennée
2965f48e590aSAlex Bennéeif test -n "$gdb_bin"; then
2966b1863cccSAlex Bennée    gdb_version=$($gdb_bin --version | head -n 1)
2967d6a66c81SAlex Bennée    if version_ge ${gdb_version##* } 9.1; then
2968f48e590aSAlex Bennée        echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
2969f48e590aSAlex Bennée    fi
2970b1863cccSAlex Bennéefi
2971f48e590aSAlex Bennée
297254e7aac0SAlexey Krasikovif test "$secret_keyring" = "yes" ; then
297354e7aac0SAlexey Krasikov  echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak
297454e7aac0SAlexey Krasikovfi
297554e7aac0SAlexey Krasikov
297698ec69acSJuan Quintelaecho "ROMS=$roms" >> $config_host_mak
2977804edf29SJuan Quintelaecho "MAKE=$make" >> $config_host_mak
2978c886edfbSBlue Swirlecho "PYTHON=$python" >> $config_host_mak
297939d87c8cSAlex Bennéeecho "GENISOIMAGE=$genisoimage" >> $config_host_mak
2980a5665051SPaolo Bonziniecho "MESON=$meson" >> $config_host_mak
298109e93326SPaolo Bonziniecho "NINJA=$ninja" >> $config_host_mak
2982804edf29SJuan Quintelaecho "CC=$cc" >> $config_host_mak
2983433de74cSBastian Koppelmannecho "HOST_CC=$host_cc" >> $config_host_mak
2984804edf29SJuan Quintelaecho "AR=$ar" >> $config_host_mak
2985cdbd727cSRichard Hendersonecho "AS=$as" >> $config_host_mak
29865f6f0e27SRichard Hendersonecho "CCAS=$ccas" >> $config_host_mak
29873dd46c78SBlue Swirlecho "CPP=$cpp" >> $config_host_mak
2988804edf29SJuan Quintelaecho "OBJCOPY=$objcopy" >> $config_host_mak
2989804edf29SJuan Quintelaecho "LD=$ld" >> $config_host_mak
299046eef33bSBradecho "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
2991a558ee17SJuan Quintelaecho "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
299211cde1c8SBruno Dominguezecho "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
2993a81df1b6SPaolo Bonziniecho "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
2994a81df1b6SPaolo Bonziniecho "GLIB_LIBS=$glib_libs" >> $config_host_mak
2995d83acfd0SMarc-André Lureauecho "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak
29968a99e9a3SPhilippe Mathieu-Daudéecho "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
2997e57218b6SPeter Maydellecho "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
2998a70248dbSPaolo Bonziniecho "STRIP=$strip" >> $config_host_mak
2999804edf29SJuan Quintelaecho "EXESUF=$EXESUF" >> $config_host_mak
3000804edf29SJuan Quintela
30016efd7517SPeter Maydell# use included Linux headers
30026efd7517SPeter Maydellif test "$linux" = "yes" ; then
3003a307beb6SAndreas Färber  mkdir -p linux-headers
30046efd7517SPeter Maydell  case "$cpu" in
30054da270beSPaolo Bonzini  i386|x86_64)
300608312a63SPeter Maydell    linux_arch=x86
30076efd7517SPeter Maydell    ;;
3008d8ff892dSPaolo Bonzini  ppc|ppc64)
300908312a63SPeter Maydell    linux_arch=powerpc
30106efd7517SPeter Maydell    ;;
30116efd7517SPeter Maydell  s390x)
301208312a63SPeter Maydell    linux_arch=s390
301308312a63SPeter Maydell    ;;
30141f080313SClaudio Fontana  aarch64)
30151f080313SClaudio Fontana    linux_arch=arm64
30161f080313SClaudio Fontana    ;;
3017dfcf900bSWANG Xuerui  loongarch*)
3018dfcf900bSWANG Xuerui    linux_arch=loongarch
3019dfcf900bSWANG Xuerui    ;;
3020222e7d11SSanjay Lal  mips64)
3021222e7d11SSanjay Lal    linux_arch=mips
3022222e7d11SSanjay Lal    ;;
302308312a63SPeter Maydell  *)
302408312a63SPeter Maydell    # For most CPUs the kernel architecture name and QEMU CPU name match.
302508312a63SPeter Maydell    linux_arch="$cpu"
30266efd7517SPeter Maydell    ;;
30276efd7517SPeter Maydell  esac
302808312a63SPeter Maydell    # For non-KVM architectures we will not have asm headers
302908312a63SPeter Maydell    if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
303008312a63SPeter Maydell      symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
303108312a63SPeter Maydell    fi
30326efd7517SPeter Maydellfi
30336efd7517SPeter Maydell
303497a847bcSbellardfor target in $target_list; do
303597a847bcSbellard    target_dir="$target"
303657a93f16SPhilippe Mathieu-Daudé    target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
303797a847bcSbellard    mkdir -p $target_dir
3038fdb75aefSPaolo Bonzini    case $target in
3039fdb75aefSPaolo Bonzini        *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
3040fdb75aefSPaolo Bonzini        *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
30412408a527Saurel32    esac
304256aebc89Spbrookdone
30437d13299dSbellard
3044765686d6SPaolo Bonziniecho "CONFIG_QEMU_INTERP_PREFIX=$interp_prefix" | sed 's/%M/@0@/' >> $config_host_mak
3045fdb75aefSPaolo Bonziniif test "$default_targets" = "yes"; then
3046fdb75aefSPaolo Bonzini  echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
3047fdb75aefSPaolo Bonzinifi
3048a540f158SPeter Crosthwaite
3049fd0e6053SJohn Snowif test "$ccache_cpp2" = "yes"; then
3050fd0e6053SJohn Snow  echo "export CCACHE_CPP2=y" >> $config_host_mak
3051fd0e6053SJohn Snowfi
3052fd0e6053SJohn Snow
30531e4f6065SDaniele Buonoif test "$safe_stack" = "yes"; then
30541e4f6065SDaniele Buono  echo "CONFIG_SAFESTACK=y" >> $config_host_mak
30551e4f6065SDaniele Buonofi
30561e4f6065SDaniele Buono
3057e29e5c6eSPeter Maydell# If we're using a separate build tree, set it up now.
3058e29e5c6eSPeter Maydell# LINKS are things to symlink back into the source tree
3059e29e5c6eSPeter Maydell# (these can be both files and directories).
3060e29e5c6eSPeter Maydell# Caution: do not add files or directories here using wildcards. This
3061e29e5c6eSPeter Maydell# will result in problems later if a new file matching the wildcard is
3062e29e5c6eSPeter Maydell# added to the source tree -- nothing will cause configure to be rerun
3063e29e5c6eSPeter Maydell# so the build tree will be missing the link back to the new file, and
3064e29e5c6eSPeter Maydell# tests might fail. Prefer to keep the relevant files in their own
3065e29e5c6eSPeter Maydell# directory and symlink the directory instead.
30662038f8c8SPaolo BonziniLINKS="Makefile"
30673941996bSPaolo BonziniLINKS="$LINKS tests/tcg/Makefile.target"
3068ddcf607fSGerd HoffmannLINKS="$LINKS pc-bios/optionrom/Makefile"
3069e29e5c6eSPeter MaydellLINKS="$LINKS pc-bios/s390-ccw/Makefile"
30708db2a4fdSGerd HoffmannLINKS="$LINKS roms/seabios/Makefile"
3071e29e5c6eSPeter MaydellLINKS="$LINKS pc-bios/qemu-icon.bmp"
3072e29e5c6eSPeter MaydellLINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
3073bbbd9b6eSWillian RampazzoLINKS="$LINKS tests/avocado tests/data"
307439950353SPeter MaydellLINKS="$LINKS tests/qemu-iotests/check"
30758f8fd9edSCleber RosaLINKS="$LINKS python"
3076c17a386bSAlex BennéeLINKS="$LINKS contrib/plugins/Makefile "
3077753d11f2SRichard Hendersonfor bios_file in \
3078753d11f2SRichard Henderson    $source_path/pc-bios/*.bin \
30793a631b8eSBin Meng    $source_path/pc-bios/*.elf \
3080225a9ab8SAlexey Kardashevskiy    $source_path/pc-bios/*.lid \
3081753d11f2SRichard Henderson    $source_path/pc-bios/*.rom \
3082753d11f2SRichard Henderson    $source_path/pc-bios/*.dtb \
3083e89e33e1SDominik Dingel    $source_path/pc-bios/*.img \
3084753d11f2SRichard Henderson    $source_path/pc-bios/openbios-* \
30854e73c781SAlexander Graf    $source_path/pc-bios/u-boot.* \
3086cd946e5cSJohn Arbuckle    $source_path/pc-bios/palcode-* \
3087cd946e5cSJohn Arbuckle    $source_path/pc-bios/qemu_vga.ndrv
3088cd946e5cSJohn Arbuckle
3089753d11f2SRichard Hendersondo
3090e29e5c6eSPeter Maydell    LINKS="$LINKS pc-bios/$(basename $bios_file)"
30917ea78b74SJan Kiszkadone
3092e29e5c6eSPeter Maydellfor f in $LINKS ; do
30930f4d8894SPaolo Bonzini    if [ -e "$source_path/$f" ]; then
30945dce7b8dSPaolo Bonzini        mkdir -p `dirname ./$f`
3095f9245e10SPeter Maydell        symlink "$source_path/$f" "$f"
3096f9245e10SPeter Maydell    fi
30977d13299dSbellarddone
30981ad2134fSPaul Brook
30992038f8c8SPaolo Bonzini(for i in $cross_cc_vars; do
31002038f8c8SPaolo Bonzini  export $i
31012038f8c8SPaolo Bonzinidone
3102fd0f79d7SRichard Hendersonexport target_list source_path use_containers cpu
31032038f8c8SPaolo Bonzini$source_path/tests/tcg/configure.sh)
31042038f8c8SPaolo Bonzini
3105c34ebfdcSAnthony Liguori# temporary config to build submodules
3106bb7cb3adSPaolo Bonziniif test -f $source_path/roms/seabios/Makefile; then
31078db2a4fdSGerd Hoffmann  for rom in seabios; do
3108c34ebfdcSAnthony Liguori    config_mak=roms/$rom/config.mak
310937116c89SStefan Weil    echo "# Automatically generated by configure - do not modify" > $config_mak
3110c34ebfdcSAnthony Liguori    echo "SRC_PATH=$source_path/roms/$rom" >> $config_mak
3111cdbd727cSRichard Henderson    echo "AS=$as" >> $config_mak
31125f6f0e27SRichard Henderson    echo "CCAS=$ccas" >> $config_mak
3113c34ebfdcSAnthony Liguori    echo "CC=$cc" >> $config_mak
3114c34ebfdcSAnthony Liguori    echo "BCC=bcc" >> $config_mak
31153dd46c78SBlue Swirl    echo "CPP=$cpp" >> $config_mak
3116c34ebfdcSAnthony Liguori    echo "OBJCOPY=objcopy" >> $config_mak
3117a31a8642SMichael S. Tsirkin    echo "IASL=$iasl" >> $config_mak
3118c34ebfdcSAnthony Liguori    echo "LD=$ld" >> $config_mak
31199f81aeb5SAlistair Francis    echo "RANLIB=$ranlib" >> $config_mak
3120c34ebfdcSAnthony Liguori  done
3121bb7cb3adSPaolo Bonzinifi
3122c34ebfdcSAnthony Liguori
312398409991SHelge Konetzkaconfig_mak=pc-bios/optionrom/config.mak
312498409991SHelge Konetzkaecho "# Automatically generated by configure - do not modify" > $config_mak
312598409991SHelge Konetzkaecho "TOPSRC_DIR=$source_path" >> $config_mak
312698409991SHelge Konetzka
3127a5665051SPaolo Bonziniif test "$skip_meson" = no; then
3128fc929892SMarc-André Lureau  cross="config-meson.cross.new"
3129fc929892SMarc-André Lureau  meson_quote() {
3130ac7ebcc5SPaolo Bonzini    test $# = 0 && return
313147b30835SPaolo Bonzini    echo "'$(echo $* | sed "s/ /','/g")'"
3132fc929892SMarc-André Lureau  }
3133fc929892SMarc-André Lureau
3134fc929892SMarc-André Lureau  echo "# Automatically generated by configure - do not modify" > $cross
3135fc929892SMarc-André Lureau  echo "[properties]" >> $cross
3136d1d5e9eeSAlex Bennée
3137d1d5e9eeSAlex Bennée  # unroll any custom device configs
3138d1d5e9eeSAlex Bennée  for a in $device_archs; do
3139d1d5e9eeSAlex Bennée      eval "c=\$devices_${a}"
3140d1d5e9eeSAlex Bennée      echo "${a}-softmmu = '$c'" >> $cross
3141d1d5e9eeSAlex Bennée  done
3142d1d5e9eeSAlex Bennée
3143fc929892SMarc-André Lureau  test -z "$cxx" && echo "link_language = 'c'" >> $cross
314447b30835SPaolo Bonzini  echo "[built-in options]" >> $cross
3145a2866660SPaolo Bonzini  echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
3146a2866660SPaolo Bonzini  echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
3147*e910c7d9SPhilippe Mathieu-Daudé  test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
3148a2866660SPaolo Bonzini  echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
3149a2866660SPaolo Bonzini  echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
3150fc929892SMarc-André Lureau  echo "[binaries]" >> $cross
31514dba2789SPaolo Bonzini  echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
31524dba2789SPaolo Bonzini  test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
31534dba2789SPaolo Bonzini  test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
315447b30835SPaolo Bonzini  echo "ar = [$(meson_quote $ar)]" >> $cross
315547b30835SPaolo Bonzini  echo "nm = [$(meson_quote $nm)]" >> $cross
315647b30835SPaolo Bonzini  echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
315747b30835SPaolo Bonzini  echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
3158e8178514SPaolo Bonzini  if has $sdl2_config; then
315947b30835SPaolo Bonzini    echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
3160e8178514SPaolo Bonzini  fi
316147b30835SPaolo Bonzini  echo "strip = [$(meson_quote $strip)]" >> $cross
316247b30835SPaolo Bonzini  echo "windres = [$(meson_quote $windres)]" >> $cross
31633812c0c4SJoelle van Dyne  if test "$cross_compile" = "yes"; then
3164fc929892SMarc-André Lureau    cross_arg="--cross-file config-meson.cross"
3165fc929892SMarc-André Lureau    echo "[host_machine]" >> $cross
3166ba7c60c2SPaolo Bonzini    echo "system = '$targetos'" >> $cross
3167823eb013SPaolo Bonzini    case "$cpu" in
3168f6bca9dfSJoelle van Dyne        i386)
3169fc929892SMarc-André Lureau            echo "cpu_family = 'x86'" >> $cross
3170fc929892SMarc-André Lureau            ;;
3171fc929892SMarc-André Lureau        *)
3172823eb013SPaolo Bonzini            echo "cpu_family = '$cpu'" >> $cross
3173fc929892SMarc-André Lureau            ;;
3174fc929892SMarc-André Lureau    esac
3175fc929892SMarc-André Lureau    echo "cpu = '$cpu'" >> $cross
3176fc929892SMarc-André Lureau    if test "$bigendian" = "yes" ; then
3177fc929892SMarc-André Lureau        echo "endian = 'big'" >> $cross
3178fc929892SMarc-André Lureau    else
3179fc929892SMarc-André Lureau        echo "endian = 'little'" >> $cross
3180fc929892SMarc-André Lureau    fi
3181fc929892SMarc-André Lureau  else
3182fc929892SMarc-André Lureau    cross_arg="--native-file config-meson.cross"
3183fc929892SMarc-André Lureau  fi
3184fc929892SMarc-André Lureau  mv $cross config-meson.cross
3185fc929892SMarc-André Lureau
3186a5665051SPaolo Bonzini  rm -rf meson-private meson-info meson-logs
318761d63097SPaolo Bonzini  run_meson() {
318809e93326SPaolo Bonzini    NINJA=$ninja $meson setup \
3189d17f305aSPaolo Bonzini        --prefix "$prefix" \
3190d17f305aSPaolo Bonzini        --libdir "$libdir" \
3191d17f305aSPaolo Bonzini        --libexecdir "$libexecdir" \
3192d17f305aSPaolo Bonzini        --bindir "$bindir" \
3193d17f305aSPaolo Bonzini        --includedir "$includedir" \
3194d17f305aSPaolo Bonzini        --datadir "$datadir" \
3195d17f305aSPaolo Bonzini        --mandir "$mandir" \
3196d17f305aSPaolo Bonzini        --sysconfdir "$sysconfdir" \
319716bf7a33SPaolo Bonzini        --localedir "$localedir" \
3198d17f305aSPaolo Bonzini        --localstatedir "$local_statedir" \
31993b4da132SPaolo Bonzini        -Daudio_drv_list=$audio_drv_list \
32003b4da132SPaolo Bonzini        -Ddefault_devices=$default_devices \
3201d17f305aSPaolo Bonzini        -Ddocdir="$docdir" \
32025dc4618eSPaolo Bonzini        -Diasl="$($iasl -h >/dev/null 2>&1 && printf %s "$iasl")" \
320316bf7a33SPaolo Bonzini        -Dqemu_firmwarepath="$firmwarepath" \
320473f3aa37SMarc-André Lureau        -Dqemu_suffix="$qemu_suffix" \
320535acbb30SPaolo Bonzini        -Dsmbd="$smbd" \
32063b4da132SPaolo Bonzini        -Dsphinx_build="$sphinx_build" \
32073b4da132SPaolo Bonzini        -Dtrace_file="$trace_file" \
3208a5665051SPaolo Bonzini        -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) \
3209a5665051SPaolo Bonzini        -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo false; fi) \
3210a5665051SPaolo Bonzini        -Dwerror=$(if test "$werror" = yes; then echo true; else echo false; fi) \
3211da6d48b9SMarc-André Lureau        -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \
3212bf0e56a3SMarc-André Lureau        -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
32133b4da132SPaolo Bonzini        -Db_lto=$lto -Dcfi=$cfi -Dtcg=$tcg -Dxen=$xen \
32143b4da132SPaolo Bonzini        -Dcapstone=$capstone -Dfdt=$fdt -Dslirp=$slirp \
3215537b7248SPaolo Bonzini        $(test -n "${LIB_FUZZING_ENGINE+xxx}" && echo "-Dfuzzing_engine=$LIB_FUZZING_ENGINE") \
3216332008e0SThomas Huth        $(if test "$default_feature" = no; then echo "-Dauto_features=disabled"; fi) \
321761d63097SPaolo Bonzini        "$@" $cross_arg "$PWD" "$source_path"
321861d63097SPaolo Bonzini  }
321961d63097SPaolo Bonzini  eval run_meson $meson_options
3220a5665051SPaolo Bonzini  if test "$?" -ne 0 ; then
3221a5665051SPaolo Bonzini      error_exit "meson setup failed"
3222a5665051SPaolo Bonzini  fi
3223699d3884SPaolo Bonzinielse
3224699d3884SPaolo Bonzini  if test -f meson-private/cmd_line.txt; then
3225699d3884SPaolo Bonzini    # Adjust old command line options whose type was changed
3226699d3884SPaolo Bonzini    # Avoids having to use "setup --wipe" when Meson is upgraded
3227699d3884SPaolo Bonzini    perl -i -ne '
3228699d3884SPaolo Bonzini      s/^gettext = true$/gettext = auto/;
3229699d3884SPaolo Bonzini      s/^gettext = false$/gettext = disabled/;
3230654d6b04SPaolo Bonzini      /^b_staticpic/ && next;
3231699d3884SPaolo Bonzini      print;' meson-private/cmd_line.txt
3232699d3884SPaolo Bonzini  fi
3233a5665051SPaolo Bonzinifi
3234a5665051SPaolo Bonzini
3235dc655404SMichael S. Tsirkin# Save the configure command line for later reuse.
3236dc655404SMichael S. Tsirkincat <<EOD >config.status
3237dc655404SMichael S. Tsirkin#!/bin/sh
3238dc655404SMichael S. Tsirkin# Generated by configure.
3239dc655404SMichael S. Tsirkin# Run this file to recreate the current configuration.
3240dc655404SMichael S. Tsirkin# Compiler output produced by configure, useful for debugging
3241dc655404SMichael S. Tsirkin# configure, is in config.log if it exists.
3242dc655404SMichael S. TsirkinEOD
3243e811da7fSDaniel P. Berrangé
3244e811da7fSDaniel P. Berrangépreserve_env() {
3245e811da7fSDaniel P. Berrangé    envname=$1
3246e811da7fSDaniel P. Berrangé
3247e811da7fSDaniel P. Berrangé    eval envval=\$$envname
3248e811da7fSDaniel P. Berrangé
3249e811da7fSDaniel P. Berrangé    if test -n "$envval"
3250e811da7fSDaniel P. Berrangé    then
3251e811da7fSDaniel P. Berrangé	echo "$envname='$envval'" >> config.status
3252e811da7fSDaniel P. Berrangé	echo "export $envname" >> config.status
3253e811da7fSDaniel P. Berrangé    else
3254e811da7fSDaniel P. Berrangé	echo "unset $envname" >> config.status
3255e811da7fSDaniel P. Berrangé    fi
3256e811da7fSDaniel P. Berrangé}
3257e811da7fSDaniel P. Berrangé
3258e811da7fSDaniel P. Berrangé# Preserve various env variables that influence what
3259e811da7fSDaniel P. Berrangé# features/build target configure will detect
3260e811da7fSDaniel P. Berrangépreserve_env AR
3261e811da7fSDaniel P. Berrangépreserve_env AS
3262e811da7fSDaniel P. Berrangépreserve_env CC
3263e811da7fSDaniel P. Berrangépreserve_env CPP
32648009da03SPaolo Bonzinipreserve_env CFLAGS
3265e811da7fSDaniel P. Berrangépreserve_env CXX
32668009da03SPaolo Bonzinipreserve_env CXXFLAGS
3267e811da7fSDaniel P. Berrangépreserve_env INSTALL
3268e811da7fSDaniel P. Berrangépreserve_env LD
32698009da03SPaolo Bonzinipreserve_env LDFLAGS
3270e811da7fSDaniel P. Berrangépreserve_env LD_LIBRARY_PATH
3271e811da7fSDaniel P. Berrangépreserve_env LIBTOOL
3272e811da7fSDaniel P. Berrangépreserve_env MAKE
3273e811da7fSDaniel P. Berrangépreserve_env NM
3274e811da7fSDaniel P. Berrangépreserve_env OBJCOPY
3275e811da7fSDaniel P. Berrangépreserve_env PATH
3276e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG
3277e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_LIBDIR
3278e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_PATH
3279e811da7fSDaniel P. Berrangépreserve_env PYTHON
3280e811da7fSDaniel P. Berrangépreserve_env SDL2_CONFIG
3281e811da7fSDaniel P. Berrangépreserve_env SMBD
3282e811da7fSDaniel P. Berrangépreserve_env STRIP
3283e811da7fSDaniel P. Berrangépreserve_env WINDRES
3284e811da7fSDaniel P. Berrangé
3285dc655404SMichael S. Tsirkinprintf "exec" >>config.status
3286a5665051SPaolo Bonzinifor i in "$0" "$@"; do
3287835af899SPaolo Bonzini  test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
3288a5665051SPaolo Bonzinidone
3289cf7cc929SDr. David Alan Gilbertecho ' "$@"' >>config.status
3290dc655404SMichael S. Tsirkinchmod +x config.status
3291dc655404SMichael S. Tsirkin
32928cd05ab6SPeter Maydellrm -r "$TMPDIR1"
3293