xref: /openbmc/qemu/configure (revision 544f4a2578f0e8d0269383950499b2dc291f9fcf)
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"
804cb37d11SPhilippe Mathieu-DaudéTMPM="${TMPDIR1}/${TMPB}.m"
818cd05ab6SPeter MaydellTMPE="${TMPDIR1}/${TMPB}.exe"
827d13299dSbellard
83da1d85e3SGerd Hoffmannrm -f config.log
849ac81bbbSmalc
85b48e3611SPeter Maydell# Print a helpful header at the top of config.log
86b48e3611SPeter Maydellecho "# QEMU configure log $(date)" >> config.log
87979ae168SPeter Maydellprintf "# Configured with:" >> config.log
88979ae168SPeter Maydellprintf " '%s'" "$0" "$@" >> config.log
89979ae168SPeter Maydellecho >> config.log
90b48e3611SPeter Maydellecho "#" >> config.log
91b48e3611SPeter Maydell
92835af899SPaolo Bonziniquote_sh() {
93835af899SPaolo Bonzini    printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
94835af899SPaolo Bonzini}
95835af899SPaolo Bonzini
96d880a3baSPaolo Bonziniprint_error() {
97d880a3baSPaolo Bonzini    (echo
9876ad07a4SPeter Maydell    echo "ERROR: $1"
9976ad07a4SPeter Maydell    while test -n "$2"; do
10076ad07a4SPeter Maydell        echo "       $2"
10176ad07a4SPeter Maydell        shift
10276ad07a4SPeter Maydell    done
103d880a3baSPaolo Bonzini    echo) >&2
104d880a3baSPaolo Bonzini}
105d880a3baSPaolo Bonzini
106d880a3baSPaolo Bonzinierror_exit() {
107d880a3baSPaolo Bonzini    print_error "$@"
10876ad07a4SPeter Maydell    exit 1
10976ad07a4SPeter Maydell}
11076ad07a4SPeter Maydell
1119c83ffd8SPeter Maydelldo_compiler() {
1129c83ffd8SPeter Maydell    # Run the compiler, capturing its output to the log. First argument
1139c83ffd8SPeter Maydell    # is compiler binary to execute.
114630d86b7SDavid CARLIER    compiler="$1"
1159c83ffd8SPeter Maydell    shift
1168bbe05d7SIan Jackson    if test -n "$BASH_VERSION"; then eval '
1178bbe05d7SIan Jackson        echo >>config.log "
1188bbe05d7SIan Jacksonfuncs: ${FUNCNAME[*]}
1198bbe05d7SIan Jacksonlines: ${BASH_LINENO[*]}"
1208bbe05d7SIan Jackson    '; fi
1219c83ffd8SPeter Maydell    echo $compiler "$@" >> config.log
1229c83ffd8SPeter Maydell    $compiler "$@" >> config.log 2>&1 || return $?
1238dc38a78SPeter Maydell    # Test passed. If this is an --enable-werror build, rerun
1248dc38a78SPeter Maydell    # the test with -Werror and bail out if it fails. This
1258dc38a78SPeter Maydell    # makes warning-generating-errors in configure test code
1268dc38a78SPeter Maydell    # obvious to developers.
1278dc38a78SPeter Maydell    if test "$werror" != "yes"; then
1288dc38a78SPeter Maydell        return 0
1298dc38a78SPeter Maydell    fi
1308dc38a78SPeter Maydell    # Don't bother rerunning the compile if we were already using -Werror
1318dc38a78SPeter Maydell    case "$*" in
1328dc38a78SPeter Maydell        *-Werror*)
1338dc38a78SPeter Maydell           return 0
1348dc38a78SPeter Maydell        ;;
1358dc38a78SPeter Maydell    esac
1369c83ffd8SPeter Maydell    echo $compiler -Werror "$@" >> config.log
1379c83ffd8SPeter Maydell    $compiler -Werror "$@" >> config.log 2>&1 && return $?
13876ad07a4SPeter Maydell    error_exit "configure test passed without -Werror but failed with -Werror." \
13976ad07a4SPeter Maydell        "This is probably a bug in the configure script. The failing command" \
14076ad07a4SPeter Maydell        "will be at the bottom of config.log." \
14176ad07a4SPeter Maydell        "You can run configure with --disable-werror to bypass this check."
1428dc38a78SPeter Maydell}
1438dc38a78SPeter Maydell
1449c83ffd8SPeter Maydelldo_cc() {
1454dba2789SPaolo Bonzini    do_compiler "$cc" $CPU_CFLAGS "$@"
1469c83ffd8SPeter Maydell}
1479c83ffd8SPeter Maydell
1489c83ffd8SPeter Maydelldo_cxx() {
1494dba2789SPaolo Bonzini    do_compiler "$cxx" $CPU_CFLAGS "$@"
1509c83ffd8SPeter Maydell}
1519c83ffd8SPeter Maydell
1524cb37d11SPhilippe Mathieu-Daudédo_objc() {
1534cb37d11SPhilippe Mathieu-Daudé    do_compiler "$objcc" $CPU_CFLAGS "$@"
1544cb37d11SPhilippe Mathieu-Daudé}
1554cb37d11SPhilippe Mathieu-Daudé
15600849b92SRichard Henderson# Append $2 to the variable named $1, with space separation
15700849b92SRichard Hendersonadd_to() {
15800849b92SRichard Henderson    eval $1=\${$1:+\"\$$1 \"}\$2
15900849b92SRichard Henderson}
16000849b92SRichard Henderson
1619c83ffd8SPeter Maydellupdate_cxxflags() {
1629c83ffd8SPeter Maydell    # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
1639c83ffd8SPeter Maydell    # options which some versions of GCC's C++ compiler complain about
1649c83ffd8SPeter Maydell    # because they only make sense for C programs.
165de38c0ccSPaolo Bonzini    QEMU_CXXFLAGS="-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
1668a9d3d56SRichard Henderson    CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
1679c83ffd8SPeter Maydell    for arg in $QEMU_CFLAGS; do
1689c83ffd8SPeter Maydell        case $arg in
1699c83ffd8SPeter Maydell            -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
1709c83ffd8SPeter Maydell            -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
1719c83ffd8SPeter Maydell                ;;
1729c83ffd8SPeter Maydell            *)
1739c83ffd8SPeter Maydell                QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
1749c83ffd8SPeter Maydell                ;;
1759c83ffd8SPeter Maydell        esac
1769c83ffd8SPeter Maydell    done
1779c83ffd8SPeter Maydell}
1789c83ffd8SPeter Maydell
17952166aa0SJuan Quintelacompile_object() {
180fd0e6053SJohn Snow  local_cflags="$1"
181a2866660SPaolo Bonzini  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
18252166aa0SJuan Quintela}
18352166aa0SJuan Quintela
18452166aa0SJuan Quintelacompile_prog() {
18552166aa0SJuan Quintela  local_cflags="$1"
18652166aa0SJuan Quintela  local_ldflags="$2"
187a2866660SPaolo Bonzini  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
188a2866660SPaolo Bonzini      $LDFLAGS $EXTRA_LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
18952166aa0SJuan Quintela}
19052166aa0SJuan Quintela
19111568d6dSPaolo Bonzini# symbolically link $1 to $2.  Portable version of "ln -sf".
19211568d6dSPaolo Bonzinisymlink() {
19372b8b5a1SStefan Weil  rm -rf "$2"
194ec5b06d7SAnthony Liguori  mkdir -p "$(dirname "$2")"
19572b8b5a1SStefan Weil  ln -s "$1" "$2"
19611568d6dSPaolo Bonzini}
19711568d6dSPaolo Bonzini
1980dba6195SLoïc Minier# check whether a command is available to this shell (may be either an
1990dba6195SLoïc Minier# executable or a builtin)
2000dba6195SLoïc Minierhas() {
2010dba6195SLoïc Minier    type "$1" >/dev/null 2>&1
2020dba6195SLoïc Minier}
2030dba6195SLoïc Minier
2040a01d76fSMarc-André Lureauversion_ge () {
2052df52b9bSAlex Bennée    local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
2062df52b9bSAlex Bennée    local_ver2=$(echo "$2" | tr . ' ')
2070a01d76fSMarc-André Lureau    while true; do
2080a01d76fSMarc-André Lureau        set x $local_ver1
2090a01d76fSMarc-André Lureau        local_first=${2-0}
210c44a33e2SStefano Garzarella        # 'shift 2' if $2 is set, or 'shift' if $2 is not set
211c44a33e2SStefano Garzarella        shift ${2:+2}
2120a01d76fSMarc-André Lureau        local_ver1=$*
2130a01d76fSMarc-André Lureau        set x $local_ver2
2140a01d76fSMarc-André Lureau        # the second argument finished, the first must be greater or equal
2150a01d76fSMarc-André Lureau        test $# = 1 && return 0
2160a01d76fSMarc-André Lureau        test $local_first -lt $2 && return 1
2170a01d76fSMarc-André Lureau        test $local_first -gt $2 && return 0
218c44a33e2SStefano Garzarella        shift ${2:+2}
2190a01d76fSMarc-André Lureau        local_ver2=$*
2200a01d76fSMarc-André Lureau    done
2210a01d76fSMarc-André Lureau}
2220a01d76fSMarc-André Lureau
2233b6b7550SPaolo Bonziniglob() {
2243b6b7550SPaolo Bonzini    eval test -z '"${1#'"$2"'}"'
2253b6b7550SPaolo Bonzini}
2263b6b7550SPaolo Bonzini
227e9a3591fSChristian Borntraegerld_has() {
228e9a3591fSChristian Borntraeger    $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
229e9a3591fSChristian Borntraeger}
230e9a3591fSChristian Borntraeger
2314ace32e2SAntonio Ospiteif printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
2324ace32e2SAntonio Ospitethen
2334ace32e2SAntonio Ospite  error_exit "main directory cannot contain spaces nor colons"
2344ace32e2SAntonio Ospitefi
2354ace32e2SAntonio Ospite
23614211825SAntonio Ospite# default parameters
2372ff6b91eSJuan Quintelacpu=""
238a31a8642SMichael S. Tsirkiniasl="iasl"
2391e43adfcSbellardinterp_prefix="/usr/gnemul/qemu-%M"
24043ce4dfeSbellardstatic="no"
2413812c0c4SJoelle van Dynecross_compile="no"
2427d13299dSbellardcross_prefix=""
24387430d5bSPaolo Bonziniaudio_drv_list="default"
244b64ec4e4SFam Zhengblock_drv_rw_whitelist=""
245b64ec4e4SFam Zhengblock_drv_ro_whitelist=""
246e49d021eSPeter Maydellhost_cc="cc"
2475bc62e01SGerd Hoffmanndebug_info="yes"
248cdad781dSDaniele Buonolto="false"
24963678e17SSteven Noonanstack_protector=""
2501e4f6065SDaniele Buonosafe_stack=""
251afc3a8f9SAlex Bennéeuse_containers="yes"
252f2385398SAlex Bennéegdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
253ac0df51dSaliguori
25492712822SDaniel P. Berrangeif test -e "$source_path/.git"
25592712822SDaniel P. Berrangethen
2567d7dbf9dSDan Streetman    git_submodules_action="update"
25792712822SDaniel P. Berrangeelse
2587d7dbf9dSDan Streetman    git_submodules_action="ignore"
25992712822SDaniel P. Berrangefi
2602d652f24SPaolo Bonzini
2612d652f24SPaolo Bonzinigit_submodules="ui/keycodemapdb"
262cc84d63aSDaniel P. Berrangegit="git"
263ac0df51dSaliguori
264afb63ebdSStefan Weil# Don't accept a target_list environment variable.
265afb63ebdSStefan Weilunset target_list
266447e133fSAlex Bennéeunset target_list_exclude
267377529c0SPaolo Bonzini
268377529c0SPaolo Bonzini# Default value for a variable defining feature "foo".
269377529c0SPaolo Bonzini#  * foo="no"  feature will only be used if --enable-foo arg is given
270377529c0SPaolo Bonzini#  * foo=""    feature will be searched for, and if found, will be used
271377529c0SPaolo Bonzini#              unless --disable-foo is given
272377529c0SPaolo Bonzini#  * foo="yes" this value will only be set by --enable-foo flag.
273377529c0SPaolo Bonzini#              feature will searched for,
274377529c0SPaolo Bonzini#              if not found, configure exits with error
275377529c0SPaolo Bonzini#
276377529c0SPaolo Bonzini# Always add --enable-foo and --disable-foo command line args.
277377529c0SPaolo Bonzini# Distributions want to ensure that several features are compiled in, and it
278377529c0SPaolo Bonzini# is impossible without a --enable-foo that exits if a feature is not found.
279377529c0SPaolo Bonzini
280c87ea116SAlex Bennéedefault_feature=""
281c87ea116SAlex Bennée# parse CC options second
282c87ea116SAlex Bennéefor opt do
283c87ea116SAlex Bennée  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
284c87ea116SAlex Bennée  case "$opt" in
285c87ea116SAlex Bennée      --without-default-features)
286c87ea116SAlex Bennée          default_feature="no"
287c87ea116SAlex Bennée  ;;
288c87ea116SAlex Bennée  esac
289c87ea116SAlex Bennéedone
290c87ea116SAlex Bennée
291a2866660SPaolo BonziniEXTRA_CFLAGS=""
292a2866660SPaolo BonziniEXTRA_CXXFLAGS=""
293e910c7d9SPhilippe Mathieu-DaudéEXTRA_OBJCFLAGS=""
294a2866660SPaolo BonziniEXTRA_LDFLAGS=""
295a2866660SPaolo Bonzini
296c87ea116SAlex Bennéexen_ctrl_version="$default_feature"
2970848f8acSThomas Huthvhost_kernel="$default_feature"
298c87ea116SAlex Bennéevhost_net="$default_feature"
299c87ea116SAlex Bennéevhost_crypto="$default_feature"
300c87ea116SAlex Bennéevhost_scsi="$default_feature"
301c87ea116SAlex Bennéevhost_vsock="$default_feature"
302d88618f7SStefan Hajnoczivhost_user="no"
303c87ea116SAlex Bennéevhost_user_fs="$default_feature"
3040848f8acSThomas Huthvhost_vdpa="$default_feature"
305c87ea116SAlex Bennéerdma="$default_feature"
306c87ea116SAlex Bennéepvrdma="$default_feature"
307377529c0SPaolo Bonzinidebug_tcg="no"
308377529c0SPaolo Bonzinidebug="no"
309247724cbSMarc-André Lureausanitizers="no"
3100aebab04SLingfeng Yangtsan="no"
311c87ea116SAlex Bennéefortify_source="$default_feature"
3121d728c39SBlue Swirlgcov="no"
313c7328271SMiroslav RezaninaEXESUF=""
31417969268SFam Zhengmodules="no"
315bd83c861SChristian Ehrhardtmodule_upgrades="no"
316377529c0SPaolo Bonziniprefix="/usr/local"
31710ff82d1SMarc-André Lureauqemu_suffix="qemu"
318377529c0SPaolo Bonzinisoftmmu="yes"
319b915a2f1SPaolo Bonzinilinux_user=""
320b915a2f1SPaolo Bonzinibsd_user=""
321377529c0SPaolo Bonzinipkgversion=""
32240d6444eSAvi Kivitypie=""
323baf86d6bSPaolo Bonzinitrace_backends="log"
324377529c0SPaolo Bonzinitrace_file="trace"
325c87ea116SAlex Bennéeopengl="$default_feature"
326519175a2SAlex Barcelocoroutine=""
327a1c5e949SDaniel P. Berrangetls_priority="NORMAL"
328ba4dd2aaSAlex Bennéeplugins="$default_feature"
329c87ea116SAlex Bennéesecret_keyring="$default_feature"
330a5665051SPaolo Bonzinimeson=""
3313b4da132SPaolo Bonzinimeson_args=""
33248328880SPaolo Bonzinininja=""
3333b4da132SPaolo Bonzinigio="$default_feature"
334a5665051SPaolo Bonziniskip_meson=no
335377529c0SPaolo Bonzini
3363b4da132SPaolo Bonzini# The following Meson options are handled manually (still they
3373b4da132SPaolo Bonzini# are included in the automatically generated help message)
3383b4da132SPaolo Bonzini
3393b4da132SPaolo Bonzini# 1. Track which submodules are needed
3400577e84dSThomas Huthif test "$default_feature" = no ; then
3410577e84dSThomas Huth  capstone="disabled"
3420577e84dSThomas Huth  slirp="disabled"
3430577e84dSThomas Huthelse
3443b4da132SPaolo Bonzini  capstone="auto"
3453b4da132SPaolo Bonzini  slirp="auto"
3460577e84dSThomas Huthfi
3470577e84dSThomas Huthfdt="auto"
3483b4da132SPaolo Bonzini
3493b4da132SPaolo Bonzini# 2. Support --with/--without option
3503b4da132SPaolo Bonzinidefault_devices="true"
3513b4da132SPaolo Bonzini
3523b4da132SPaolo Bonzini# 3. Automatically enable/disable other options
3533b4da132SPaolo Bonzinitcg="enabled"
3543b4da132SPaolo Bonzinicfi="false"
3553b4da132SPaolo Bonzini
3563b4da132SPaolo Bonzini# 4. Detection partly done in configure
3573b4da132SPaolo Bonzinixen=${default_feature:+disabled}
358898be3e0SPeter Maydell
359c87ea116SAlex Bennée# parse CC options second
360ac0df51dSaliguorifor opt do
36189138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
362ac0df51dSaliguori  case "$opt" in
363ac0df51dSaliguori  --cross-prefix=*) cross_prefix="$optarg"
3643812c0c4SJoelle van Dyne                    cross_compile="yes"
365ac0df51dSaliguori  ;;
3663d8df640SPaolo Bonzini  --cc=*) CC="$optarg"
367ac0df51dSaliguori  ;;
36883f73fceSTomoki Sekiyama  --cxx=*) CXX="$optarg"
36983f73fceSTomoki Sekiyama  ;;
3702ff6b91eSJuan Quintela  --cpu=*) cpu="$optarg"
3712ff6b91eSJuan Quintela  ;;
372a2866660SPaolo Bonzini  --extra-cflags=*)
373a2866660SPaolo Bonzini    EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
374a2866660SPaolo Bonzini    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
375e910c7d9SPhilippe Mathieu-Daudé    EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
376e2a2ed06SJuan Quintela    ;;
377a2866660SPaolo Bonzini  --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
37811cde1c8SBruno Dominguez  ;;
379e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
380e910c7d9SPhilippe Mathieu-Daudé  ;;
381a2866660SPaolo Bonzini  --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
382e2a2ed06SJuan Quintela  ;;
3835bc62e01SGerd Hoffmann  --enable-debug-info) debug_info="yes"
3845bc62e01SGerd Hoffmann  ;;
3855bc62e01SGerd Hoffmann  --disable-debug-info) debug_info="no"
3865bc62e01SGerd Hoffmann  ;;
387d75402b5SAlex Bennée  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
388d75402b5SAlex Bennée  ;;
389479ca4ccSMatheus Ferst  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
390d422b2bcSAlex Bennée                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
3912038f8c8SPaolo Bonzini                      cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
392d422b2bcSAlex Bennée  ;;
393d75402b5SAlex Bennée  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
3942038f8c8SPaolo Bonzini                cc_archs="$cc_archs $cc_arch"
395d75402b5SAlex Bennée                eval "cross_cc_${cc_arch}=\$optarg"
3962038f8c8SPaolo Bonzini                cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
397d75402b5SAlex Bennée  ;;
398ac0df51dSaliguori  esac
399ac0df51dSaliguoridone
400ac0df51dSaliguori# OS specific
401ac0df51dSaliguori# Using uname is really, really broken.  Once we have the right set of checks
40293148aa5SStefan Weil# we can eliminate its usage altogether.
403ac0df51dSaliguori
404e49d021eSPeter Maydell# Preferred compiler:
405e49d021eSPeter Maydell#  ${CC} (if set)
406e49d021eSPeter Maydell#  ${cross_prefix}gcc (if cross-prefix specified)
407e49d021eSPeter Maydell#  system compiler
408e49d021eSPeter Maydellif test -z "${CC}${cross_prefix}"; then
409e49d021eSPeter Maydell  cc="$host_cc"
410e49d021eSPeter Maydellelse
411b3198cc2SStuart Yoder  cc="${CC-${cross_prefix}gcc}"
412e49d021eSPeter Maydellfi
413e49d021eSPeter Maydell
41483f73fceSTomoki Sekiyamaif test -z "${CXX}${cross_prefix}"; then
41583f73fceSTomoki Sekiyama  cxx="c++"
41683f73fceSTomoki Sekiyamaelse
41783f73fceSTomoki Sekiyama  cxx="${CXX-${cross_prefix}g++}"
41883f73fceSTomoki Sekiyamafi
41983f73fceSTomoki Sekiyama
420b3198cc2SStuart Yoderar="${AR-${cross_prefix}ar}"
421cdbd727cSRichard Hendersonas="${AS-${cross_prefix}as}"
4225f6f0e27SRichard Hendersonccas="${CCAS-$cc}"
4233dd46c78SBlue Swirlcpp="${CPP-$cc -E}"
424b3198cc2SStuart Yoderobjcopy="${OBJCOPY-${cross_prefix}objcopy}"
425b3198cc2SStuart Yoderld="${LD-${cross_prefix}ld}"
4269f81aeb5SAlistair Francisranlib="${RANLIB-${cross_prefix}ranlib}"
4274852ee95SStefan Weilnm="${NM-${cross_prefix}nm}"
42835acbb30SPaolo Bonzinismbd="$SMBD"
429b3198cc2SStuart Yoderstrip="${STRIP-${cross_prefix}strip}"
430b3198cc2SStuart Yoderwindres="${WINDRES-${cross_prefix}windres}"
43117884d7bSSergei Trofimovichpkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
43217884d7bSSergei Trofimovichquery_pkg_config() {
43317884d7bSSergei Trofimovich    "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
43417884d7bSSergei Trofimovich}
43517884d7bSSergei Trofimovichpkg_config=query_pkg_config
43647c03744SDave Airliesdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
437ac0df51dSaliguori
438be17dc90SMichael S. Tsirkin# default flags for all hosts
4392d31515bSPeter Maydell# We use -fwrapv to tell the compiler that we require a C dialect where
4402d31515bSPeter Maydell# left shift of signed integers is well defined and has the expected
4412d31515bSPeter Maydell# 2s-complement style results. (Both clang and gcc agree that it
4422d31515bSPeter Maydell# provides these semantics.)
443de38c0ccSPaolo BonziniQEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
444086d5f75SPaolo BonziniQEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
445c95e3080SKevin WolfQEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
446be17dc90SMichael S. TsirkinQEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
4475770e8afSPaolo Bonzini
448de38c0ccSPaolo BonziniQEMU_LDFLAGS=
449de38c0ccSPaolo Bonzini
4505770e8afSPaolo Bonzini# Flags that are needed during configure but later taken care of by Meson
4518a9d3d56SRichard HendersonCONFIGURE_CFLAGS="-std=gnu11 -Wall"
4525770e8afSPaolo BonziniCONFIGURE_LDFLAGS=
453086d5f75SPaolo Bonzini
454be17dc90SMichael S. Tsirkin
455ac0df51dSaliguoricheck_define() {
456ac0df51dSaliguoricat > $TMPC <<EOF
457ac0df51dSaliguori#if !defined($1)
458fd786e1aSPeter Maydell#error $1 not defined
459ac0df51dSaliguori#endif
460ac0df51dSaliguoriint main(void) { return 0; }
461ac0df51dSaliguoriEOF
46252166aa0SJuan Quintela  compile_object
463ac0df51dSaliguori}
464ac0df51dSaliguori
465307119e7SGerd Hoffmanncheck_include() {
466307119e7SGerd Hoffmanncat > $TMPC <<EOF
467307119e7SGerd Hoffmann#include <$1>
468307119e7SGerd Hoffmannint main(void) { return 0; }
469307119e7SGerd HoffmannEOF
470307119e7SGerd Hoffmann  compile_object
471307119e7SGerd Hoffmann}
472307119e7SGerd Hoffmann
47393b25869SJohn Snowwrite_c_skeleton() {
47493b25869SJohn Snow    cat > $TMPC <<EOF
47593b25869SJohn Snowint main(void) { return 0; }
47693b25869SJohn SnowEOF
47793b25869SJohn Snow}
47893b25869SJohn Snow
479bbea4050SPeter Maydellif check_define __linux__ ; then
480ba7c60c2SPaolo Bonzini  targetos=linux
481bbea4050SPeter Maydellelif check_define _WIN32 ; then
482ba7c60c2SPaolo Bonzini  targetos=windows
483bbea4050SPeter Maydellelif check_define __OpenBSD__ ; then
484ba7c60c2SPaolo Bonzini  targetos=openbsd
485bbea4050SPeter Maydellelif check_define __sun__ ; then
486ba7c60c2SPaolo Bonzini  targetos=sunos
487bbea4050SPeter Maydellelif check_define __HAIKU__ ; then
488ba7c60c2SPaolo Bonzini  targetos=haiku
489951fedfcSPeter Maydellelif check_define __FreeBSD__ ; then
490ba7c60c2SPaolo Bonzini  targetos=freebsd
491951fedfcSPeter Maydellelif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
492ba7c60c2SPaolo Bonzini  targetos=gnu/kfreebsd
493951fedfcSPeter Maydellelif check_define __DragonFly__ ; then
494ba7c60c2SPaolo Bonzini  targetos=dragonfly
495951fedfcSPeter Maydellelif check_define __NetBSD__; then
496ba7c60c2SPaolo Bonzini  targetos=netbsd
497951fedfcSPeter Maydellelif check_define __APPLE__; then
498ba7c60c2SPaolo Bonzini  targetos=darwin
499bbea4050SPeter Maydellelse
500951fedfcSPeter Maydell  # This is a fatal error, but don't report it yet, because we
501951fedfcSPeter Maydell  # might be going to just print the --help text, or it might
502951fedfcSPeter Maydell  # be the result of a missing compiler.
503ba7c60c2SPaolo Bonzini  targetos=bogus
504bbea4050SPeter Maydellfi
505bbea4050SPeter Maydell
50665eff01bSPaolo Bonzini# OS specific
50765eff01bSPaolo Bonzini
5083b0d8643SPaolo Bonzinimingw32="no"
5093b0d8643SPaolo Bonzinibsd="no"
5103b0d8643SPaolo Bonzinilinux="no"
5113b0d8643SPaolo Bonzinisolaris="no"
51265eff01bSPaolo Bonzinicase $targetos in
51365eff01bSPaolo Bonziniwindows)
51465eff01bSPaolo Bonzini  mingw32="yes"
51565eff01bSPaolo Bonzini  plugins="no"
51665eff01bSPaolo Bonzini  pie="no"
51765eff01bSPaolo Bonzini;;
51865eff01bSPaolo Bonzinignu/kfreebsd)
51965eff01bSPaolo Bonzini  bsd="yes"
52065eff01bSPaolo Bonzini;;
52165eff01bSPaolo Bonzinifreebsd)
52265eff01bSPaolo Bonzini  bsd="yes"
52365eff01bSPaolo Bonzini  make="${MAKE-gmake}"
52465eff01bSPaolo Bonzini  # needed for kinfo_getvmmap(3) in libutil.h
52565eff01bSPaolo Bonzini;;
52665eff01bSPaolo Bonzinidragonfly)
52765eff01bSPaolo Bonzini  bsd="yes"
52865eff01bSPaolo Bonzini  make="${MAKE-gmake}"
52965eff01bSPaolo Bonzini;;
53065eff01bSPaolo Bonzininetbsd)
53165eff01bSPaolo Bonzini  bsd="yes"
53265eff01bSPaolo Bonzini  make="${MAKE-gmake}"
53365eff01bSPaolo Bonzini;;
53465eff01bSPaolo Bonziniopenbsd)
53565eff01bSPaolo Bonzini  bsd="yes"
53665eff01bSPaolo Bonzini  make="${MAKE-gmake}"
53765eff01bSPaolo Bonzini;;
53865eff01bSPaolo Bonzinidarwin)
53965eff01bSPaolo Bonzini  bsd="yes"
54065eff01bSPaolo Bonzini  darwin="yes"
54165eff01bSPaolo Bonzini  # Disable attempts to use ObjectiveC features in os/object.h since they
54265eff01bSPaolo Bonzini  # won't work when we're compiling with gcc as a C compiler.
54365eff01bSPaolo Bonzini  QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
54465eff01bSPaolo Bonzini;;
54565eff01bSPaolo Bonzinisunos)
54665eff01bSPaolo Bonzini  solaris="yes"
54765eff01bSPaolo Bonzini  make="${MAKE-gmake}"
54865eff01bSPaolo Bonzini# needed for CMSG_ macros in sys/socket.h
54965eff01bSPaolo Bonzini  QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
55065eff01bSPaolo Bonzini# needed for TIOCWIN* defines in termios.h
55165eff01bSPaolo Bonzini  QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
55265eff01bSPaolo Bonzini  # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
55365eff01bSPaolo Bonzini  # Note that this check is broken for cross-compilation: if you're
554bbea4050SPeter Maydell  # cross-compiling to one of these OSes then you'll need to specify
555bbea4050SPeter Maydell  # the correct CPU with the --cpu option.
556bbea4050SPeter Maydell  if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
557bbea4050SPeter Maydell    cpu="x86_64"
558bbea4050SPeter Maydell  fi
55965eff01bSPaolo Bonzini;;
56065eff01bSPaolo Bonzinihaiku)
56165eff01bSPaolo Bonzini  pie="no"
56265eff01bSPaolo Bonzini  QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
56365eff01bSPaolo Bonzini;;
56465eff01bSPaolo Bonzinilinux)
56565eff01bSPaolo Bonzini  linux="yes"
56665eff01bSPaolo Bonzini  vhost_user=${default_feature:-yes}
56765eff01bSPaolo Bonzini;;
568bbea4050SPeter Maydellesac
569bbea4050SPeter Maydell
5702ff6b91eSJuan Quintelaif test ! -z "$cpu" ; then
5712ff6b91eSJuan Quintela  # command line argument
5722ff6b91eSJuan Quintela  :
5732ff6b91eSJuan Quintelaelif check_define __i386__ ; then
574ac0df51dSaliguori  cpu="i386"
575ac0df51dSaliguorielif check_define __x86_64__ ; then
576c72b26ecSRichard Henderson  if check_define __ILP32__ ; then
577c72b26ecSRichard Henderson    cpu="x32"
578c72b26ecSRichard Henderson  else
579ac0df51dSaliguori    cpu="x86_64"
580c72b26ecSRichard Henderson  fi
5813aa9bd6cSblueswir1elif check_define __sparc__ ; then
5823aa9bd6cSblueswir1  if check_define __arch64__ ; then
5833aa9bd6cSblueswir1    cpu="sparc64"
5843aa9bd6cSblueswir1  else
5853aa9bd6cSblueswir1    cpu="sparc"
5863aa9bd6cSblueswir1  fi
587fdf7ed96Smalcelif check_define _ARCH_PPC ; then
588fdf7ed96Smalc  if check_define _ARCH_PPC64 ; then
589f8378accSRichard Henderson    if check_define _LITTLE_ENDIAN ; then
590f8378accSRichard Henderson      cpu="ppc64le"
591f8378accSRichard Henderson    else
592fdf7ed96Smalc      cpu="ppc64"
593f8378accSRichard Henderson    fi
594ac0df51dSaliguori  else
595fdf7ed96Smalc    cpu="ppc"
596fdf7ed96Smalc  fi
597afa05235SAurelien Jarnoelif check_define __mips__ ; then
598afa05235SAurelien Jarno  cpu="mips"
599d66ed0eaSAurelien Jarnoelif check_define __s390__ ; then
600d66ed0eaSAurelien Jarno  if check_define __s390x__ ; then
601d66ed0eaSAurelien Jarno    cpu="s390x"
602d66ed0eaSAurelien Jarno  else
603d66ed0eaSAurelien Jarno    cpu="s390"
604d66ed0eaSAurelien Jarno  fi
605c4f80543SAlistair Franciselif check_define __riscv ; then
606ba0e7333SRichard Henderson  cpu="riscv"
60721d89f84SPeter Maydellelif check_define __arm__ ; then
60821d89f84SPeter Maydell  cpu="arm"
6091f080313SClaudio Fontanaelif check_define __aarch64__ ; then
6101f080313SClaudio Fontana  cpu="aarch64"
611dfcf900bSWANG Xueruielif check_define __loongarch64 ; then
612dfcf900bSWANG Xuerui  cpu="loongarch64"
613fdf7ed96Smalcelse
61489138857SStefan Weil  cpu=$(uname -m)
615ac0df51dSaliguorifi
616ac0df51dSaliguori
617823eb013SPaolo Bonzini# Normalise host CPU name, set multilib cflags
618359bc95dSPeter Maydell# Note that this case should only have supported host CPUs, not guests.
6197d13299dSbellardcase "$cpu" in
620e4da0e39SPaolo Bonzini  armv*b|armv*l|arm)
621e4da0e39SPaolo Bonzini    cpu="arm" ;;
622e4da0e39SPaolo Bonzini
6237d13299dSbellard  i386|i486|i586|i686|i86pc|BePC)
62497a847bcSbellard    cpu="i386"
625e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32" ;;
626e4da0e39SPaolo Bonzini  x32)
6274da270beSPaolo Bonzini    cpu="x86_64"
628e4da0e39SPaolo Bonzini    CPU_CFLAGS="-mx32" ;;
629aaa5fa14Saurel32  x86_64|amd64)
630aaa5fa14Saurel32    cpu="x86_64"
631e4da0e39SPaolo Bonzini    # ??? Only extremely old AMD cpus do not have cmpxchg16b.
632e4da0e39SPaolo Bonzini    # If we truly care, we should simply detect this case at
633e4da0e39SPaolo Bonzini    # runtime and generate the fallback to serial emulation.
634e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64 -mcx16" ;;
635e4da0e39SPaolo Bonzini
636afa05235SAurelien Jarno  mips*)
637e4da0e39SPaolo Bonzini    cpu="mips" ;;
638e4da0e39SPaolo Bonzini
639e4da0e39SPaolo Bonzini  ppc)
640e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32" ;;
641e4da0e39SPaolo Bonzini  ppc64)
642ced5cfffSMiroslav Rezanina    CPU_CFLAGS="-m64 -mbig-endian" ;;
643e4da0e39SPaolo Bonzini  ppc64le)
644d8ff892dSPaolo Bonzini    cpu="ppc64"
645ced5cfffSMiroslav Rezanina    CPU_CFLAGS="-m64 -mlittle-endian" ;;
646e4da0e39SPaolo Bonzini
647e4da0e39SPaolo Bonzini  s390)
648823eb013SPaolo Bonzini    CPU_CFLAGS="-m31" ;;
649e4da0e39SPaolo Bonzini  s390x)
650e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64" ;;
651e4da0e39SPaolo Bonzini
6523142255cSblueswir1  sparc|sun4[cdmuv])
653ae228531Sbellard    cpu="sparc"
654e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
655e4da0e39SPaolo Bonzini  sparc64)
656e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
6577d13299dSbellardesac
658e2d52ad3SJuan Quintela
6590db4a067SPaolo Bonzini: ${make=${MAKE-make}}
660b6daf4d3SPaolo Bonzini
661faf44142SDaniel P. Berrangé# We prefer python 3.x. A bare 'python' is traditionally
662faf44142SDaniel P. Berrangé# python 2.x, but some distros have it as python 3.x, so
663ddf90699SEduardo Habkost# we check that too
664faf44142SDaniel P. Berrangépython=
6650a01d76fSMarc-André Lureauexplicit_python=no
666ddf90699SEduardo Habkostfor binary in "${PYTHON-python3}" python
667faf44142SDaniel P. Berrangédo
668faf44142SDaniel P. Berrangé    if has "$binary"
669faf44142SDaniel P. Berrangé    then
67095c5f2deSPaolo Bonzini        python=$(command -v "$binary")
671faf44142SDaniel P. Berrangé        break
672faf44142SDaniel P. Berrangé    fi
673faf44142SDaniel P. Berrangédone
674903458c8SMarkus Armbruster
675903458c8SMarkus Armbruster
67639d87c8cSAlex Bennée# Check for ancillary tools used in testing
67739d87c8cSAlex Bennéegenisoimage=
6783df437c7SAlex Bennéefor binary in genisoimage mkisofs
67939d87c8cSAlex Bennéedo
68039d87c8cSAlex Bennée    if has $binary
68139d87c8cSAlex Bennée    then
68239d87c8cSAlex Bennée        genisoimage=$(command -v "$binary")
68339d87c8cSAlex Bennée        break
68439d87c8cSAlex Bennée    fi
68539d87c8cSAlex Bennéedone
68639d87c8cSAlex Bennée
6873c4a4d0dSPeter Maydell# Default objcc to clang if available, otherwise use CC
6883c4a4d0dSPeter Maydellif has clang; then
6893c4a4d0dSPeter Maydell  objcc=clang
6903c4a4d0dSPeter Maydellelse
6913c4a4d0dSPeter Maydell  objcc="$cc"
6923c4a4d0dSPeter Maydellfi
6933c4a4d0dSPeter Maydell
6943457a3f8SJuan Quintelaif test "$mingw32" = "yes" ; then
6953457a3f8SJuan Quintela  EXESUF=".exe"
69678e9d4adSStefan Weil  # MinGW needs -mthreads for TLS and macro _MT.
6975770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
69893b25869SJohn Snow  write_c_skeleton;
699d17f305aSPaolo Bonzini  prefix="/qemu"
70077433a5fSMarc-André Lureau  qemu_suffix=""
7013457a3f8SJuan Quintelafi
7023457a3f8SJuan Quintela
703487fefdbSAnthony Liguoriwerror=""
70485aa5189Sbellard
70561d63097SPaolo Bonzini. $source_path/scripts/meson-buildoptions.sh
70661d63097SPaolo Bonzini
70761d63097SPaolo Bonzinimeson_options=
70861d63097SPaolo Bonzinimeson_option_parse() {
70961d63097SPaolo Bonzini  meson_options="$meson_options $(_meson_option_parse "$@")"
71061d63097SPaolo Bonzini  if test $? -eq 1; then
71161d63097SPaolo Bonzini    echo "ERROR: unknown option $1"
71261d63097SPaolo Bonzini    echo "Try '$0 --help' for more information"
71361d63097SPaolo Bonzini    exit 1
71461d63097SPaolo Bonzini  fi
71561d63097SPaolo Bonzini}
71661d63097SPaolo Bonzini
7177d13299dSbellardfor opt do
71889138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
7197d13299dSbellard  case "$opt" in
7202efc3265Sbellard  --help|-h) show_help=yes
7212efc3265Sbellard  ;;
72299123e13SMike Frysinger  --version|-V) exec cat $source_path/VERSION
72399123e13SMike Frysinger  ;;
724b1a550a0Spbrook  --prefix=*) prefix="$optarg"
7257d13299dSbellard  ;;
726b1a550a0Spbrook  --interp-prefix=*) interp_prefix="$optarg"
72732ce6337Sbellard  ;;
728ac0df51dSaliguori  --cross-prefix=*)
7297d13299dSbellard  ;;
730ac0df51dSaliguori  --cc=*)
7317d13299dSbellard  ;;
732b1a550a0Spbrook  --host-cc=*) host_cc="$optarg"
73383469015Sbellard  ;;
73483f73fceSTomoki Sekiyama  --cxx=*)
73583f73fceSTomoki Sekiyama  ;;
736e007dbecSMichael S. Tsirkin  --iasl=*) iasl="$optarg"
737e007dbecSMichael S. Tsirkin  ;;
7383c4a4d0dSPeter Maydell  --objcc=*) objcc="$optarg"
7393c4a4d0dSPeter Maydell  ;;
740b1a550a0Spbrook  --make=*) make="$optarg"
7417d13299dSbellard  ;;
742b6daf4d3SPaolo Bonzini  --install=*)
7436a882643Spbrook  ;;
7440a01d76fSMarc-André Lureau  --python=*) python="$optarg" ; explicit_python=yes
745c886edfbSBlue Swirl  ;;
7462eb054c2SPeter Maydell  --sphinx-build=*) sphinx_build="$optarg"
7472eb054c2SPeter Maydell  ;;
748a5665051SPaolo Bonzini  --skip-meson) skip_meson=yes
749a5665051SPaolo Bonzini  ;;
750a5665051SPaolo Bonzini  --meson=*) meson="$optarg"
751a5665051SPaolo Bonzini  ;;
75248328880SPaolo Bonzini  --ninja=*) ninja="$optarg"
75348328880SPaolo Bonzini  ;;
754e2d8830eSBrad  --smbd=*) smbd="$optarg"
755e2d8830eSBrad  ;;
756e2a2ed06SJuan Quintela  --extra-cflags=*)
7577d13299dSbellard  ;;
75811cde1c8SBruno Dominguez  --extra-cxxflags=*)
75911cde1c8SBruno Dominguez  ;;
760e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=*)
761e910c7d9SPhilippe Mathieu-Daudé  ;;
762e2a2ed06SJuan Quintela  --extra-ldflags=*)
7637d13299dSbellard  ;;
7645bc62e01SGerd Hoffmann  --enable-debug-info)
7655bc62e01SGerd Hoffmann  ;;
7665bc62e01SGerd Hoffmann  --disable-debug-info)
7675bc62e01SGerd Hoffmann  ;;
768d75402b5SAlex Bennée  --cross-cc-*)
769d75402b5SAlex Bennée  ;;
77017969268SFam Zheng  --enable-modules)
77117969268SFam Zheng      modules="yes"
77217969268SFam Zheng  ;;
7733aa88b31SStefan Hajnoczi  --disable-modules)
7743aa88b31SStefan Hajnoczi      modules="no"
7753aa88b31SStefan Hajnoczi  ;;
776bd83c861SChristian Ehrhardt  --disable-module-upgrades) module_upgrades="no"
777bd83c861SChristian Ehrhardt  ;;
778bd83c861SChristian Ehrhardt  --enable-module-upgrades) module_upgrades="yes"
779bd83c861SChristian Ehrhardt  ;;
7802ff6b91eSJuan Quintela  --cpu=*)
7817d13299dSbellard  ;;
782b1a550a0Spbrook  --target-list=*) target_list="$optarg"
783447e133fSAlex Bennée                   if test "$target_list_exclude"; then
784447e133fSAlex Bennée                       error_exit "Can't mix --target-list with --target-list-exclude"
785447e133fSAlex Bennée                   fi
786447e133fSAlex Bennée  ;;
787447e133fSAlex Bennée  --target-list-exclude=*) target_list_exclude="$optarg"
788447e133fSAlex Bennée                   if test "$target_list"; then
789447e133fSAlex Bennée                       error_exit "Can't mix --target-list-exclude with --target-list"
790447e133fSAlex Bennée                   fi
791de83cd02Sbellard  ;;
79274242e0fSPaolo Bonzini  --with-trace-file=*) trace_file="$optarg"
7939410b56cSPrerna Saxena  ;;
7947bc3ca7fSPaolo Bonzini  --with-default-devices) default_devices="true"
795f3494749SPaolo Bonzini  ;;
7967bc3ca7fSPaolo Bonzini  --without-default-devices) default_devices="false"
797f3494749SPaolo Bonzini  ;;
798d1d5e9eeSAlex Bennée  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
799d1d5e9eeSAlex Bennée  ;;
800d1d5e9eeSAlex Bennée  --with-devices-*) device_arch=${opt#--with-devices-};
801d1d5e9eeSAlex Bennée                    device_arch=${device_arch%%=*}
802d1d5e9eeSAlex Bennée                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
803d1d5e9eeSAlex Bennée                    if test -f "$cf"; then
804d1d5e9eeSAlex Bennée                        device_archs="$device_archs $device_arch"
805d1d5e9eeSAlex Bennée                        eval "devices_${device_arch}=\$optarg"
806d1d5e9eeSAlex Bennée                    else
807d1d5e9eeSAlex Bennée                        error_exit "File $cf does not exist"
808d1d5e9eeSAlex Bennée                    fi
809d1d5e9eeSAlex Bennée  ;;
810c87ea116SAlex Bennée  --without-default-features) # processed above
811c87ea116SAlex Bennée  ;;
8121d728c39SBlue Swirl  --enable-gcov) gcov="yes"
8131d728c39SBlue Swirl  ;;
81479427693SLoïc Minier  --static)
81579427693SLoïc Minier    static="yes"
81617884d7bSSergei Trofimovich    QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
81743ce4dfeSbellard  ;;
8180b24e75fSPaolo Bonzini  --mandir=*) mandir="$optarg"
8190b24e75fSPaolo Bonzini  ;;
8200b24e75fSPaolo Bonzini  --bindir=*) bindir="$optarg"
8210b24e75fSPaolo Bonzini  ;;
8223aa5d2beSAlon Levy  --libdir=*) libdir="$optarg"
8233aa5d2beSAlon Levy  ;;
8248bf188aaSMichael Tokarev  --libexecdir=*) libexecdir="$optarg"
8258bf188aaSMichael Tokarev  ;;
8260f94d6daSAlon Levy  --includedir=*) includedir="$optarg"
8270f94d6daSAlon Levy  ;;
828528ae5b8SEduardo Habkost  --datadir=*) datadir="$optarg"
8290b24e75fSPaolo Bonzini  ;;
83077433a5fSMarc-André Lureau  --with-suffix=*) qemu_suffix="$optarg"
831023d3d67SEduardo Habkost  ;;
832c6502638SBruce Rogers  --docdir=*) docdir="$optarg"
8330b24e75fSPaolo Bonzini  ;;
834fe0038beSPaolo Bonzini  --localedir=*) localedir="$optarg"
835fe0038beSPaolo Bonzini  ;;
836ca2fb938SAndre Przywara  --sysconfdir=*) sysconfdir="$optarg"
83707381cc1SAnthony Liguori  ;;
838785c23aeSLuiz Capitulino  --localstatedir=*) local_statedir="$optarg"
839785c23aeSLuiz Capitulino  ;;
8403d5eecabSGerd Hoffmann  --firmwarepath=*) firmwarepath="$optarg"
8413d5eecabSGerd Hoffmann  ;;
842181ce1d0SOlaf Hering  --host=*|--build=*|\
843181ce1d0SOlaf Hering  --disable-dependency-tracking|\
844785c23aeSLuiz Capitulino  --sbindir=*|--sharedstatedir=*|\
845fe0038beSPaolo Bonzini  --oldincludedir=*|--datarootdir=*|--infodir=*|\
846023ddd74SMax Filippov  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
847023ddd74SMax Filippov    # These switches are silently ignored, for compatibility with
848023ddd74SMax Filippov    # autoconf-generated configure scripts. This allows QEMU's
849023ddd74SMax Filippov    # configure to be used by RPM and similar macros that set
850023ddd74SMax Filippov    # lots of directory switches by default.
851023ddd74SMax Filippov  ;;
8520c58ac1cSmalc  --audio-drv-list=*) audio_drv_list="$optarg"
8530c58ac1cSmalc  ;;
85489138857SStefan Weil  --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
855b64ec4e4SFam Zheng  ;;
85689138857SStefan Weil  --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
857eb852011SMarkus Armbruster  ;;
858f8393946Saurel32  --enable-debug-tcg) debug_tcg="yes"
859f8393946Saurel32  ;;
860f8393946Saurel32  --disable-debug-tcg) debug_tcg="no"
861f8393946Saurel32  ;;
862f3d08ee6SPaul Brook  --enable-debug)
863f3d08ee6SPaul Brook      # Enable debugging options that aren't excessively noisy
864f3d08ee6SPaul Brook      debug_tcg="yes"
865c55cf6abSPaolo Bonzini      meson_option_parse --enable-debug-mutex ""
866f3d08ee6SPaul Brook      debug="yes"
867b553a042SJohn Snow      fortify_source="no"
868f3d08ee6SPaul Brook  ;;
869247724cbSMarc-André Lureau  --enable-sanitizers) sanitizers="yes"
870247724cbSMarc-André Lureau  ;;
871247724cbSMarc-André Lureau  --disable-sanitizers) sanitizers="no"
872247724cbSMarc-André Lureau  ;;
8730aebab04SLingfeng Yang  --enable-tsan) tsan="yes"
8740aebab04SLingfeng Yang  ;;
8750aebab04SLingfeng Yang  --disable-tsan) tsan="no"
8760aebab04SLingfeng Yang  ;;
8774d34a86bSPaolo Bonzini  --disable-slirp) slirp="disabled"
878c20709aaSbellard  ;;
879fd6fc214SPaolo Bonzini  --enable-slirp) slirp="enabled"
880fd6fc214SPaolo Bonzini  ;;
8814d34a86bSPaolo Bonzini  --enable-slirp=git) slirp="internal"
8827c57bdd8SMarc-André Lureau  ;;
88303a3c0b3SPaolo Bonzini  --enable-slirp=*) slirp="$optarg"
884675b9b53SMarc-André Lureau  ;;
8851badb709SPaolo Bonzini  --disable-xen) xen="disabled"
886e37630caSaliguori  ;;
8871badb709SPaolo Bonzini  --enable-xen) xen="enabled"
888fc321b4bSJuan Quintela  ;;
8891badb709SPaolo Bonzini  --disable-tcg) tcg="disabled"
890d1a14257SAlex Bennée                 plugins="no"
891b3f6ea7eSPaolo Bonzini  ;;
8921badb709SPaolo Bonzini  --enable-tcg) tcg="enabled"
893b3f6ea7eSPaolo Bonzini  ;;
894cad25d69Spbrook  --disable-system) softmmu="no"
8950a8e90f4Spbrook  ;;
896cad25d69Spbrook  --enable-system) softmmu="yes"
8970a8e90f4Spbrook  ;;
8980953a80fSZachary Amsden  --disable-user)
8990953a80fSZachary Amsden      linux_user="no" ;
9000953a80fSZachary Amsden      bsd_user="no" ;
9010953a80fSZachary Amsden  ;;
9020953a80fSZachary Amsden  --enable-user) ;;
903831b7825Sths  --disable-linux-user) linux_user="no"
9040a8e90f4Spbrook  ;;
905831b7825Sths  --enable-linux-user) linux_user="yes"
906831b7825Sths  ;;
90784778508Sblueswir1  --disable-bsd-user) bsd_user="no"
90884778508Sblueswir1  ;;
90984778508Sblueswir1  --enable-bsd-user) bsd_user="yes"
91084778508Sblueswir1  ;;
91140d6444eSAvi Kivity  --enable-pie) pie="yes"
91234005a00SKirill A. Shutemov  ;;
91340d6444eSAvi Kivity  --disable-pie) pie="no"
91434005a00SKirill A. Shutemov  ;;
91585aa5189Sbellard  --enable-werror) werror="yes"
91685aa5189Sbellard  ;;
91785aa5189Sbellard  --disable-werror) werror="no"
91885aa5189Sbellard  ;;
919cdad781dSDaniele Buono  --enable-lto) lto="true"
920cdad781dSDaniele Buono  ;;
921cdad781dSDaniele Buono  --disable-lto) lto="false"
922cdad781dSDaniele Buono  ;;
92363678e17SSteven Noonan  --enable-stack-protector) stack_protector="yes"
92463678e17SSteven Noonan  ;;
92563678e17SSteven Noonan  --disable-stack-protector) stack_protector="no"
92663678e17SSteven Noonan  ;;
9271e4f6065SDaniele Buono  --enable-safe-stack) safe_stack="yes"
9281e4f6065SDaniele Buono  ;;
9291e4f6065SDaniele Buono  --disable-safe-stack) safe_stack="no"
9301e4f6065SDaniele Buono  ;;
9319e62ba48SDaniele Buono  --enable-cfi)
9329e62ba48SDaniele Buono      cfi="true";
9339e62ba48SDaniele Buono      lto="true";
9349e62ba48SDaniele Buono  ;;
9359e62ba48SDaniele Buono  --disable-cfi) cfi="false"
9369e62ba48SDaniele Buono  ;;
937fbb4121dSPaolo Bonzini  --disable-fdt) fdt="disabled"
9382df87df7SJuan Quintela  ;;
939fbb4121dSPaolo Bonzini  --enable-fdt) fdt="enabled"
940fbb4121dSPaolo Bonzini  ;;
941fbb4121dSPaolo Bonzini  --enable-fdt=git) fdt="internal"
942fbb4121dSPaolo Bonzini  ;;
94303a3c0b3SPaolo Bonzini  --enable-fdt=*) fdt="$optarg"
9442df87df7SJuan Quintela  ;;
9457e563bfbSThomas Huth  --with-pkgversion=*) pkgversion="$optarg"
9464a19f1ecSpbrook  ;;
947519175a2SAlex Barcelo  --with-coroutine=*) coroutine="$optarg"
948519175a2SAlex Barcelo  ;;
949d5970055SMichael S. Tsirkin  --disable-vhost-net) vhost_net="no"
950d5970055SMichael S. Tsirkin  ;;
951d5970055SMichael S. Tsirkin  --enable-vhost-net) vhost_net="yes"
952d5970055SMichael S. Tsirkin  ;;
953042cea27SGonglei  --disable-vhost-crypto) vhost_crypto="no"
954042cea27SGonglei  ;;
955299e6f19SPaolo Bonzini  --enable-vhost-crypto) vhost_crypto="yes"
956042cea27SGonglei  ;;
9575e9be92dSNicholas Bellinger  --disable-vhost-scsi) vhost_scsi="no"
9585e9be92dSNicholas Bellinger  ;;
9595e9be92dSNicholas Bellinger  --enable-vhost-scsi) vhost_scsi="yes"
9605e9be92dSNicholas Bellinger  ;;
961fc0b9b0eSStefan Hajnoczi  --disable-vhost-vsock) vhost_vsock="no"
962fc0b9b0eSStefan Hajnoczi  ;;
963fc0b9b0eSStefan Hajnoczi  --enable-vhost-vsock) vhost_vsock="yes"
964fc0b9b0eSStefan Hajnoczi  ;;
96598fc1adaSDr. David Alan Gilbert  --disable-vhost-user-fs) vhost_user_fs="no"
96698fc1adaSDr. David Alan Gilbert  ;;
96798fc1adaSDr. David Alan Gilbert  --enable-vhost-user-fs) vhost_user_fs="yes"
96898fc1adaSDr. David Alan Gilbert  ;;
969da076ffeSGerd Hoffmann  --disable-opengl) opengl="no"
97020ff075bSMichael Walle  ;;
971da076ffeSGerd Hoffmann  --enable-opengl) opengl="yes"
97220ff075bSMichael Walle  ;;
9731ffb3bbbSPaolo Bonzini  --disable-zlib-test)
9741ece9905SAlon Levy  ;;
97552b53c04SFam Zheng  --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
97652b53c04SFam Zheng      echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
977583f6e7bSStefan Hajnoczi  ;;
978cb6414dfSFam Zheng  --enable-vhdx|--disable-vhdx)
979cb6414dfSFam Zheng      echo "$0: $opt is obsolete, VHDX driver is always built" >&2
980cb6414dfSFam Zheng  ;;
981315d3184SFam Zheng  --enable-uuid|--disable-uuid)
982315d3184SFam Zheng      echo "$0: $opt is obsolete, UUID support is always built" >&2
983315d3184SFam Zheng  ;;
984a1c5e949SDaniel P. Berrange  --tls-priority=*) tls_priority="$optarg"
985a1c5e949SDaniel P. Berrange  ;;
9862da776dbSMichael R. Hines  --enable-rdma) rdma="yes"
9872da776dbSMichael R. Hines  ;;
9882da776dbSMichael R. Hines  --disable-rdma) rdma="no"
9892da776dbSMichael R. Hines  ;;
99021ab34c9SMarcel Apfelbaum  --enable-pvrdma) pvrdma="yes"
99121ab34c9SMarcel Apfelbaum  ;;
99221ab34c9SMarcel Apfelbaum  --disable-pvrdma) pvrdma="no"
99321ab34c9SMarcel Apfelbaum  ;;
994e6a74868SMarc-André Lureau  --disable-vhost-user) vhost_user="no"
995e6a74868SMarc-André Lureau  ;;
996299e6f19SPaolo Bonzini  --enable-vhost-user) vhost_user="yes"
997299e6f19SPaolo Bonzini  ;;
998108a6481SCindy Lu  --disable-vhost-vdpa) vhost_vdpa="no"
999108a6481SCindy Lu  ;;
1000108a6481SCindy Lu  --enable-vhost-vdpa) vhost_vdpa="yes"
1001108a6481SCindy Lu  ;;
1002299e6f19SPaolo Bonzini  --disable-vhost-kernel) vhost_kernel="no"
1003299e6f19SPaolo Bonzini  ;;
1004299e6f19SPaolo Bonzini  --enable-vhost-kernel) vhost_kernel="yes"
1005e6a74868SMarc-André Lureau  ;;
10068b18cdbfSRichard Henderson  --disable-capstone) capstone="disabled"
10078ca80760SRichard Henderson  ;;
10088b18cdbfSRichard Henderson  --enable-capstone) capstone="enabled"
10098ca80760SRichard Henderson  ;;
10108b18cdbfSRichard Henderson  --enable-capstone=git) capstone="internal"
1011e219c499SRichard Henderson  ;;
101203a3c0b3SPaolo Bonzini  --enable-capstone=*) capstone="$optarg"
1013e219c499SRichard Henderson  ;;
1014cc84d63aSDaniel P. Berrange  --with-git=*) git="$optarg"
1015cc84d63aSDaniel P. Berrange  ;;
10167d7dbf9dSDan Streetman  --with-git-submodules=*)
10177d7dbf9dSDan Streetman      git_submodules_action="$optarg"
1018f62bbee5SDaniel P. Berrange  ;;
10199b8e4298SAlex Bennée  --enable-plugins) if test "$mingw32" = "yes"; then
10209b8e4298SAlex Bennée                        error_exit "TCG plugins not currently supported on Windows platforms"
10219b8e4298SAlex Bennée                    else
10229b8e4298SAlex Bennée                        plugins="yes"
10239b8e4298SAlex Bennée                    fi
102440e8c6f4SAlex Bennée  ;;
102540e8c6f4SAlex Bennée  --disable-plugins) plugins="no"
102640e8c6f4SAlex Bennée  ;;
1027afc3a8f9SAlex Bennée  --enable-containers) use_containers="yes"
1028afc3a8f9SAlex Bennée  ;;
1029afc3a8f9SAlex Bennée  --disable-containers) use_containers="no"
1030afc3a8f9SAlex Bennée  ;;
1031f48e590aSAlex Bennée  --gdb=*) gdb_bin="$optarg"
1032f48e590aSAlex Bennée  ;;
103354e7aac0SAlexey Krasikov  --enable-keyring) secret_keyring="yes"
103454e7aac0SAlexey Krasikov  ;;
103554e7aac0SAlexey Krasikov  --disable-keyring) secret_keyring="no"
103654e7aac0SAlexey Krasikov  ;;
103720cf7b8eSDenis Plotnikov  --enable-gio) gio=yes
103820cf7b8eSDenis Plotnikov  ;;
103920cf7b8eSDenis Plotnikov  --disable-gio) gio=no
104020cf7b8eSDenis Plotnikov  ;;
10413b4da132SPaolo Bonzini  # backwards compatibility options
10423b4da132SPaolo Bonzini  --enable-trace-backend=*) meson_option_parse "--enable-trace-backends=$optarg" "$optarg"
10433b4da132SPaolo Bonzini  ;;
10443b4da132SPaolo Bonzini  --disable-blobs) meson_option_parse --disable-install-blobs ""
10453b4da132SPaolo Bonzini  ;;
10463b4da132SPaolo Bonzini  --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
10473b4da132SPaolo Bonzini  ;;
10483b4da132SPaolo Bonzini  --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
10493b4da132SPaolo Bonzini  ;;
10503b4da132SPaolo Bonzini  # everything else has the same name in configure and meson
105161d63097SPaolo Bonzini  --enable-* | --disable-*) meson_option_parse "$opt" "$optarg"
105261d63097SPaolo Bonzini  ;;
10532d2ad6d0SFam Zheng  *)
10542d2ad6d0SFam Zheng      echo "ERROR: unknown option $opt"
10552d2ad6d0SFam Zheng      echo "Try '$0 --help' for more information"
10562d2ad6d0SFam Zheng      exit 1
10577f1559c6Sbalrog  ;;
10587d13299dSbellard  esac
10597d13299dSbellarddone
10607d13299dSbellard
1061d1a14257SAlex Bennée# test for any invalid configuration combinations
1062d1a14257SAlex Bennéeif test "$plugins" = "yes" -a "$tcg" = "disabled"; then
1063d1a14257SAlex Bennée    error_exit "Can't enable plugins on non-TCG builds"
1064d1a14257SAlex Bennéefi
1065d1a14257SAlex Bennée
10667d7dbf9dSDan Streetmancase $git_submodules_action in
10677d7dbf9dSDan Streetman    update|validate)
10687d7dbf9dSDan Streetman        if test ! -e "$source_path/.git"; then
10697d7dbf9dSDan Streetman            echo "ERROR: cannot $git_submodules_action git submodules without .git"
10707d7dbf9dSDan Streetman            exit 1
10717d7dbf9dSDan Streetman        fi
10727d7dbf9dSDan Streetman    ;;
10737d7dbf9dSDan Streetman    ignore)
1074b80fd281SPaolo Bonzini        if ! test -f "$source_path/ui/keycodemapdb/README"
1075b80fd281SPaolo Bonzini        then
1076b80fd281SPaolo Bonzini            echo
1077b80fd281SPaolo Bonzini            echo "ERROR: missing GIT submodules"
1078b80fd281SPaolo Bonzini            echo
1079b80fd281SPaolo Bonzini            if test -e "$source_path/.git"; then
1080b80fd281SPaolo Bonzini                echo "--with-git-submodules=ignore specified but submodules were not"
1081b80fd281SPaolo Bonzini                echo "checked out.  Please initialize and update submodules."
1082b80fd281SPaolo Bonzini            else
1083b80fd281SPaolo Bonzini                echo "This is not a GIT checkout but module content appears to"
1084b80fd281SPaolo Bonzini                echo "be missing. Do not use 'git archive' or GitHub download links"
1085b80fd281SPaolo Bonzini                echo "to acquire QEMU source archives. Non-GIT builds are only"
1086b80fd281SPaolo Bonzini                echo "supported with source archives linked from:"
1087b80fd281SPaolo Bonzini                echo
1088b80fd281SPaolo Bonzini                echo "  https://www.qemu.org/download/#source"
1089b80fd281SPaolo Bonzini                echo
1090b80fd281SPaolo Bonzini                echo "Developers working with GIT can use scripts/archive-source.sh"
1091b80fd281SPaolo Bonzini                echo "if they need to create valid source archives."
1092b80fd281SPaolo Bonzini            fi
1093b80fd281SPaolo Bonzini            echo
1094b80fd281SPaolo Bonzini            exit 1
1095b80fd281SPaolo Bonzini        fi
10967d7dbf9dSDan Streetman    ;;
10977d7dbf9dSDan Streetman    *)
10987d7dbf9dSDan Streetman        echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
10997d7dbf9dSDan Streetman        exit 1
11007d7dbf9dSDan Streetman    ;;
11017d7dbf9dSDan Streetmanesac
11027d7dbf9dSDan Streetman
110322a87800SMarc-André Lureaulibdir="${libdir:-$prefix/lib}"
110422a87800SMarc-André Lureaulibexecdir="${libexecdir:-$prefix/libexec}"
110522a87800SMarc-André Lureauincludedir="${includedir:-$prefix/include}"
110622a87800SMarc-André Lureau
110722a87800SMarc-André Lureauif test "$mingw32" = "yes" ; then
110815588a62SJoshua Watt    bindir="${bindir:-$prefix}"
110922a87800SMarc-André Lureauelse
111015588a62SJoshua Watt    bindir="${bindir:-$prefix/bin}"
111115588a62SJoshua Wattfi
111222a87800SMarc-André Lureaumandir="${mandir:-$prefix/share/man}"
111322a87800SMarc-André Lureaudatadir="${datadir:-$prefix/share}"
1114ca8c0909SMarc-André Lureaudocdir="${docdir:-$prefix/share/doc}"
111522a87800SMarc-André Lureausysconfdir="${sysconfdir:-$prefix/etc}"
111622a87800SMarc-André Lureaulocal_statedir="${local_statedir:-$prefix/var}"
111716bf7a33SPaolo Bonzinifirmwarepath="${firmwarepath:-$datadir/qemu-firmware}"
111816bf7a33SPaolo Bonzinilocaledir="${localedir:-$datadir/locale}"
111922a87800SMarc-André Lureau
11209557af9cSAlex Bennéeif eval test -z "\${cross_cc_$cpu}"; then
1121b1aa4de1SAlex Bennée    eval "cross_cc_${cpu}=\$cc"
11222038f8c8SPaolo Bonzini    cross_cc_vars="$cross_cc_vars cross_cc_${cpu}"
11239557af9cSAlex Bennéefi
112479f3b12fSPeter Crosthwaite
112560e0df25SPeter Maydelldefault_target_list=""
11266e92f823SPeter Maydellmak_wilds=""
11276e92f823SPeter Maydell
1128b915a2f1SPaolo Bonziniif [ "$linux_user" != no ]; then
1129b915a2f1SPaolo Bonzini    if [ "$targetos" = linux ] && [ -d $source_path/linux-user/include/host/$cpu ]; then
1130b915a2f1SPaolo Bonzini        linux_user=yes
1131b915a2f1SPaolo Bonzini    elif [ "$linux_user" = yes ]; then
1132b915a2f1SPaolo Bonzini        error_exit "linux-user not supported on this architecture"
1133b915a2f1SPaolo Bonzini    fi
1134b915a2f1SPaolo Bonzinifi
1135b915a2f1SPaolo Bonziniif [ "$bsd_user" != no ]; then
1136b915a2f1SPaolo Bonzini    if [ "$bsd_user" = "" ]; then
1137b915a2f1SPaolo Bonzini        test $targetos = freebsd && bsd_user=yes
1138b915a2f1SPaolo Bonzini    fi
1139b915a2f1SPaolo Bonzini    if [ "$bsd_user" = yes ] && ! [ -d $source_path/bsd-user/$targetos ]; then
1140b915a2f1SPaolo Bonzini        error_exit "bsd-user not supported on this host OS"
1141b915a2f1SPaolo Bonzini    fi
1142b915a2f1SPaolo Bonzinifi
114360e0df25SPeter Maydellif [ "$softmmu" = "yes" ]; then
1144812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
114560e0df25SPeter Maydellfi
114660e0df25SPeter Maydellif [ "$linux_user" = "yes" ]; then
1147812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
114860e0df25SPeter Maydellfi
114960e0df25SPeter Maydellif [ "$bsd_user" = "yes" ]; then
1150812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
115160e0df25SPeter Maydellfi
115260e0df25SPeter Maydell
1153447e133fSAlex Bennéefor config in $mak_wilds; do
1154447e133fSAlex Bennée    target="$(basename "$config" .mak)"
115598db9a06SAlex Bennée    if echo "$target_list_exclude" | grep -vq "$target"; then
1156447e133fSAlex Bennée        default_target_list="${default_target_list} $target"
1157447e133fSAlex Bennée    fi
1158447e133fSAlex Bennéedone
11596e92f823SPeter Maydell
1160af5db58eSpbrookif test x"$show_help" = x"yes" ; then
1161af5db58eSpbrookcat << EOF
1162af5db58eSpbrook
1163af5db58eSpbrookUsage: configure [options]
1164af5db58eSpbrookOptions: [defaults in brackets after descriptions]
1165af5db58eSpbrook
116608fb77edSStefan WeilStandard options:
116708fb77edSStefan Weil  --help                   print this message
116808fb77edSStefan Weil  --prefix=PREFIX          install in PREFIX [$prefix]
116908fb77edSStefan Weil  --interp-prefix=PREFIX   where to find shared libraries, etc.
117008fb77edSStefan Weil                           use %M for cpu name [$interp_prefix]
117174154d7eSThomas Huth  --target-list=LIST       set target list (default: build all)
117208fb77edSStefan Weil$(echo Available targets: $default_target_list | \
117308fb77edSStefan Weil  fold -s -w 53 | sed -e 's/^/                           /')
1174447e133fSAlex Bennée  --target-list-exclude=LIST exclude a set of targets from the default target-list
117508fb77edSStefan Weil
117608fb77edSStefan WeilAdvanced options (experts only):
11773812c0c4SJoelle van Dyne  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
117808fb77edSStefan Weil  --cc=CC                  use C compiler CC [$cc]
117908fb77edSStefan Weil  --iasl=IASL              use ACPI compiler IASL [$iasl]
118008fb77edSStefan Weil  --host-cc=CC             use C compiler CC [$host_cc] for code run at
118108fb77edSStefan Weil                           build time
118208fb77edSStefan Weil  --cxx=CXX                use C++ compiler CXX [$cxx]
118308fb77edSStefan Weil  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
1184a2866660SPaolo Bonzini  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
1185a2866660SPaolo Bonzini  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
1186e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
118708fb77edSStefan Weil  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
1188d75402b5SAlex Bennée  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
1189479ca4ccSMatheus Ferst  --cross-cc-cflags-ARCH=  use compiler flags when building ARCH guest tests
119008fb77edSStefan Weil  --make=MAKE              use specified make [$make]
119108fb77edSStefan Weil  --python=PYTHON          use specified python [$python]
11922eb054c2SPeter Maydell  --sphinx-build=SPHINX    use specified sphinx-build [$sphinx_build]
1193a5665051SPaolo Bonzini  --meson=MESON            use specified meson [$meson]
119448328880SPaolo Bonzini  --ninja=NINJA            use specified ninja [$ninja]
119508fb77edSStefan Weil  --smbd=SMBD              use specified smbd [$smbd]
1196db1b5f13SThomas Huth  --with-git=GIT           use specified git [$git]
11977d7dbf9dSDan Streetman  --with-git-submodules=update   update git submodules (default if .git dir exists)
11987d7dbf9dSDan Streetman  --with-git-submodules=validate fail if git submodules are not up to date
11997d7dbf9dSDan Streetman  --with-git-submodules=ignore   do not update or check git submodules (default if no .git dir)
120008fb77edSStefan Weil  --static                 enable static build [$static]
120108fb77edSStefan Weil  --mandir=PATH            install man pages in PATH
120210ff82d1SMarc-André Lureau  --datadir=PATH           install firmware in PATH/$qemu_suffix
1203fe0038beSPaolo Bonzini  --localedir=PATH         install translation in PATH/$qemu_suffix
120410ff82d1SMarc-André Lureau  --docdir=PATH            install documentation in PATH/$qemu_suffix
120508fb77edSStefan Weil  --bindir=PATH            install binaries in PATH
120608fb77edSStefan Weil  --libdir=PATH            install libraries in PATH
1207db1b5f13SThomas Huth  --libexecdir=PATH        install helper binaries in PATH
120810ff82d1SMarc-André Lureau  --sysconfdir=PATH        install config in PATH/$qemu_suffix
120908fb77edSStefan Weil  --localstatedir=PATH     install local state in PATH (set at runtime on win32)
12103d5eecabSGerd Hoffmann  --firmwarepath=PATH      search PATH for firmware files
121113336606SRobert Foley  --efi-aarch64=PATH       PATH of efi file to use for aarch64 VMs.
1212ca8c0909SMarc-André Lureau  --with-suffix=SUFFIX     suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
1213db1b5f13SThomas Huth  --with-pkgversion=VERS   use specified string as sub-version of the package
1214c035c8d6SPaolo Bonzini  --without-default-features default all --enable-* options to "disabled"
1215c035c8d6SPaolo Bonzini  --without-default-devices  do not include any device that is not needed to
1216c035c8d6SPaolo Bonzini                           start the emulator (only use if you are including
1217d1d5e9eeSAlex Bennée                           desired devices in configs/devices/)
1218d1d5e9eeSAlex Bennée  --with-devices-ARCH=NAME override default configs/devices
121908fb77edSStefan Weil  --enable-debug           enable common debug build options
1220247724cbSMarc-André Lureau  --enable-sanitizers      enable default sanitizers
12210aebab04SLingfeng Yang  --enable-tsan            enable thread sanitizer
122208fb77edSStefan Weil  --disable-werror         disable compilation abort on warning
122363678e17SSteven Noonan  --disable-stack-protector disable compiler-provided stack protection
122416bfbc70SPaolo Bonzini  --audio-drv-list=LIST    set audio drivers to try if -audiodev is not used
122508fb77edSStefan Weil  --block-drv-whitelist=L  Same as --block-drv-rw-whitelist=L
122608fb77edSStefan Weil  --block-drv-rw-whitelist=L
122708fb77edSStefan Weil                           set block driver read-write whitelist
1228e5f05f8cSKevin Wolf                           (by default affects only QEMU, not tools like qemu-img)
122908fb77edSStefan Weil  --block-drv-ro-whitelist=L
123008fb77edSStefan Weil                           set block driver read-only whitelist
1231e5f05f8cSKevin Wolf                           (by default affects only QEMU, not tools like qemu-img)
123208fb77edSStefan Weil  --with-trace-file=NAME   Full PATH,NAME of file to store traces
123308fb77edSStefan Weil                           Default:trace-<pid>
1234c23f23b9SMichael Tokarev  --cpu=CPU                Build for host CPU [$cpu]
123508fb77edSStefan Weil  --with-coroutine=BACKEND coroutine backend. Supported options:
123633c53c54SDaniel P. Berrange                           ucontext, sigaltstack, windows
123708fb77edSStefan Weil  --enable-gcov            enable test coverage analysis with gcov
1238a1c5e949SDaniel P. Berrange  --tls-priority           default TLS protocol/cipher priority string
123940e8c6f4SAlex Bennée  --enable-plugins
124040e8c6f4SAlex Bennée                           enable plugins via shared library loading
1241afc3a8f9SAlex Bennée  --disable-containers     don't use containers for cross-building
1242f48e590aSAlex Bennée  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
124361d63097SPaolo BonziniEOF
124461d63097SPaolo Bonzini  meson_options_help
124561d63097SPaolo Bonzinicat << EOF
1246c23f23b9SMichael Tokarev  system          all system emulation targets
1247c23f23b9SMichael Tokarev  user            supported user emulation targets
1248c23f23b9SMichael Tokarev  linux-user      all linux usermode emulation targets
1249c23f23b9SMichael Tokarev  bsd-user        all BSD usermode emulation targets
1250c23f23b9SMichael Tokarev  pie             Position Independent Executables
125121e709aaSMarc-André Lureau  modules         modules support (non-Windows)
1252bd83c861SChristian Ehrhardt  module-upgrades try to load modules from alternate paths for upgrades
1253c23f23b9SMichael Tokarev  debug-tcg       TCG debugging (default is disabled)
1254c23f23b9SMichael Tokarev  debug-info      debugging information
1255cdad781dSDaniele Buono  lto             Enable Link-Time Optimization.
12561e4f6065SDaniele Buono  safe-stack      SafeStack Stack Smash Protection. Depends on
12571e4f6065SDaniele Buono                  clang/llvm >= 3.7 and requires coroutine backend ucontext.
125821ab34c9SMarcel Apfelbaum  rdma            Enable RDMA-based migration
125921ab34c9SMarcel Apfelbaum  pvrdma          Enable PVRDMA support
1260299e6f19SPaolo Bonzini  vhost-net       vhost-net kernel acceleration support
1261299e6f19SPaolo Bonzini  vhost-vsock     virtio sockets device support
1262299e6f19SPaolo Bonzini  vhost-scsi      vhost-scsi kernel target support
1263299e6f19SPaolo Bonzini  vhost-crypto    vhost-user-crypto backend support
1264299e6f19SPaolo Bonzini  vhost-kernel    vhost kernel backend support
1265299e6f19SPaolo Bonzini  vhost-user      vhost-user backend support
1266108a6481SCindy Lu  vhost-vdpa      vhost-vdpa kernel backend support
1267c12d66aaSLin Ma  opengl          opengl support
126820cf7b8eSDenis Plotnikov  gio             libgio support
126908fb77edSStefan Weil
127008fb77edSStefan WeilNOTE: The object files are built at the place where configure is launched
1271af5db58eSpbrookEOF
12722d2ad6d0SFam Zhengexit 0
1273af5db58eSpbrookfi
1274af5db58eSpbrook
12759c790242SThomas Huth# Remove old dependency files to make sure that they get properly regenerated
1276bb768f71SThomas Huthrm -f */config-devices.mak.d
12779c790242SThomas Huth
1278faf44142SDaniel P. Berrangéif test -z "$python"
1279faf44142SDaniel P. Berrangéthen
1280c53eeaf7SStefan Hajnoczi    error_exit "Python not found. Use --python=/path/to/python"
1281c53eeaf7SStefan Hajnoczifi
12828e2c76bdSRoman Bolshakovif ! has "$make"
12838e2c76bdSRoman Bolshakovthen
12848e2c76bdSRoman Bolshakov    error_exit "GNU make ($make) not found"
12858e2c76bdSRoman Bolshakovfi
1286c53eeaf7SStefan Hajnoczi
1287c53eeaf7SStefan Hajnoczi# Note that if the Python conditional here evaluates True we will exit
1288c53eeaf7SStefan Hajnoczi# with status 1 which is a shell 'false' value.
12891b11f28dSThomas Huthif ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then
12901b11f28dSThomas Huth  error_exit "Cannot use '$python', Python >= 3.6 is required." \
1291c53eeaf7SStefan Hajnoczi      "Use --python=/path/to/python to specify a supported Python."
1292c53eeaf7SStefan Hajnoczifi
1293c53eeaf7SStefan Hajnoczi
1294755ee70fSCleber Rosa# Preserve python version since some functionality is dependent on it
1295406ab2f3SCleber 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)
1296755ee70fSCleber Rosa
1297c53eeaf7SStefan Hajnoczi# Suppress writing compiled files
1298c53eeaf7SStefan Hajnoczipython="$python -B"
1299c53eeaf7SStefan Hajnoczi
13000a01d76fSMarc-André Lureauif test -z "$meson"; then
13016638cae5SPaolo Bonzini    if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.59.3; then
13020a01d76fSMarc-André Lureau        meson=meson
13037d7dbf9dSDan Streetman    elif test $git_submodules_action != 'ignore' ; then
13040a01d76fSMarc-André Lureau        meson=git
13050a01d76fSMarc-André Lureau    elif test -e "${source_path}/meson/meson.py" ; then
13060a01d76fSMarc-André Lureau        meson=internal
13070a01d76fSMarc-André Lureau    else
13080a01d76fSMarc-André Lureau        if test "$explicit_python" = yes; then
13090a01d76fSMarc-André Lureau            error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
13100a01d76fSMarc-André Lureau        else
1311a5665051SPaolo Bonzini            error_exit "Meson not found.  Use --meson=/path/to/meson"
1312a5665051SPaolo Bonzini        fi
13130a01d76fSMarc-André Lureau    fi
13140a01d76fSMarc-André Lureauelse
13150a01d76fSMarc-André Lureau    # Meson uses its own Python interpreter to invoke other Python scripts,
13160a01d76fSMarc-André Lureau    # but the user wants to use the one they specified with --python.
13170a01d76fSMarc-André Lureau    #
13180a01d76fSMarc-André Lureau    # We do not want to override the distro Python interpreter (and sometimes
13190a01d76fSMarc-André Lureau    # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
13200a01d76fSMarc-André Lureau    # just require --meson=git|internal together with --python.
13210a01d76fSMarc-André Lureau    if test "$explicit_python" = yes; then
13220a01d76fSMarc-André Lureau        case "$meson" in
13230a01d76fSMarc-André Lureau            git | internal) ;;
13240a01d76fSMarc-André Lureau            *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
13250a01d76fSMarc-André Lureau        esac
13260a01d76fSMarc-André Lureau    fi
13270a01d76fSMarc-André Lureaufi
1328a5665051SPaolo Bonzini
13290a01d76fSMarc-André Lureauif test "$meson" = git; then
13300a01d76fSMarc-André Lureau    git_submodules="${git_submodules} meson"
13310a01d76fSMarc-André Lureaufi
13320a01d76fSMarc-André Lureau
13330a01d76fSMarc-André Lureaucase "$meson" in
13340a01d76fSMarc-André Lureau    git | internal)
13350a01d76fSMarc-André Lureau        meson="$python ${source_path}/meson/meson.py"
13360a01d76fSMarc-André Lureau        ;;
133784ec0c24SPaolo Bonzini    *) meson=$(command -v "$meson") ;;
13380a01d76fSMarc-André Lureauesac
13390a01d76fSMarc-André Lureau
134009e93326SPaolo Bonzini# Probe for ninja
134148328880SPaolo Bonzini
134248328880SPaolo Bonziniif test -z "$ninja"; then
134348328880SPaolo Bonzini    for c in ninja ninja-build samu; do
134448328880SPaolo Bonzini        if has $c; then
134548328880SPaolo Bonzini            ninja=$(command -v "$c")
134648328880SPaolo Bonzini            break
134748328880SPaolo Bonzini        fi
134848328880SPaolo Bonzini    done
134909e93326SPaolo Bonzini    if test -z "$ninja"; then
135009e93326SPaolo Bonzini      error_exit "Cannot find Ninja"
135109e93326SPaolo Bonzini    fi
135248328880SPaolo Bonzinifi
1353a5665051SPaolo Bonzini
13549aae6e54SDaniel Henrique Barboza# Check that the C compiler works. Doing this here before testing
13559aae6e54SDaniel Henrique Barboza# the host CPU ensures that we had a valid CC to autodetect the
13569aae6e54SDaniel Henrique Barboza# $cpu var (and we should bail right here if that's not the case).
13579aae6e54SDaniel Henrique Barboza# It also allows the help message to be printed without a CC.
13589aae6e54SDaniel Henrique Barbozawrite_c_skeleton;
13599aae6e54SDaniel Henrique Barbozaif compile_object ; then
13609aae6e54SDaniel Henrique Barboza  : C compiler works ok
13619aae6e54SDaniel Henrique Barbozaelse
13629aae6e54SDaniel Henrique Barboza    error_exit "\"$cc\" either does not exist or does not work"
13639aae6e54SDaniel Henrique Barbozafi
13649aae6e54SDaniel Henrique Barbozaif ! compile_prog ; then
13659aae6e54SDaniel Henrique Barboza    error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
13669aae6e54SDaniel Henrique Barbozafi
13679aae6e54SDaniel Henrique Barboza
13689c83ffd8SPeter Maydell# Consult white-list to determine whether to enable werror
13699c83ffd8SPeter Maydell# by default.  Only enable by default for git builds
13709c83ffd8SPeter Maydellif test -z "$werror" ; then
13717d7dbf9dSDan Streetman    if test "$git_submodules_action" != "ignore" && \
1372e633a5c6SEric Blake        { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
13739c83ffd8SPeter Maydell        werror="yes"
13749c83ffd8SPeter Maydell    else
13759c83ffd8SPeter Maydell        werror="no"
13769c83ffd8SPeter Maydell    fi
13779c83ffd8SPeter Maydellfi
13789c83ffd8SPeter Maydell
1379975ff037SPaolo Bonziniif test "$targetos" = "bogus"; then
1380fb59dabdSPeter Maydell    # Now that we know that we're not printing the help and that
1381fb59dabdSPeter Maydell    # the compiler works (so the results of the check_defines we used
1382fb59dabdSPeter Maydell    # to identify the OS are reliable), if we didn't recognize the
1383fb59dabdSPeter Maydell    # host OS we should stop now.
1384951fedfcSPeter Maydell    error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1385fb59dabdSPeter Maydellfi
1386fb59dabdSPeter Maydell
1387efc6c070SThomas Huth# Check whether the compiler matches our minimum requirements:
1388efc6c070SThomas Huthcat > $TMPC << EOF
1389efc6c070SThomas Huth#if defined(__clang_major__) && defined(__clang_minor__)
1390efc6c070SThomas Huth# ifdef __apple_build_version__
13912a85a08cSDaniel P. Berrangé#  if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
13922a85a08cSDaniel P. Berrangé#   error You need at least XCode Clang v10.0 to compile QEMU
1393efc6c070SThomas Huth#  endif
1394efc6c070SThomas Huth# else
13952a85a08cSDaniel P. Berrangé#  if __clang_major__ < 6 || (__clang_major__ == 6 && __clang_minor__ < 0)
13962a85a08cSDaniel P. Berrangé#   error You need at least Clang v6.0 to compile QEMU
1397efc6c070SThomas Huth#  endif
1398efc6c070SThomas Huth# endif
1399efc6c070SThomas Huth#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
14003830df5fSnia# if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
14013830df5fSnia#  error You need at least GCC v7.4.0 to compile QEMU
1402efc6c070SThomas Huth# endif
1403efc6c070SThomas Huth#else
1404efc6c070SThomas Huth# error You either need GCC or Clang to compiler QEMU
1405efc6c070SThomas Huth#endif
1406efc6c070SThomas Huthint main (void) { return 0; }
1407efc6c070SThomas HuthEOF
1408efc6c070SThomas Huthif ! compile_prog "" "" ; then
14093830df5fSnia    error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
1410efc6c070SThomas Huthfi
1411efc6c070SThomas Huth
141200849b92SRichard Henderson# Accumulate -Wfoo and -Wno-bar separately.
141300849b92SRichard Henderson# We will list all of the enable flags first, and the disable flags second.
141400849b92SRichard Henderson# Note that we do not add -Werror, because that would enable it for all
141500849b92SRichard Henderson# configure tests. If a configure test failed due to -Werror this would
141600849b92SRichard Henderson# just silently disable some features, so it's too error prone.
141700849b92SRichard Henderson
141800849b92SRichard Hendersonwarn_flags=
141900849b92SRichard Hendersonadd_to warn_flags -Wold-style-declaration
142000849b92SRichard Hendersonadd_to warn_flags -Wold-style-definition
142100849b92SRichard Hendersonadd_to warn_flags -Wtype-limits
142200849b92SRichard Hendersonadd_to warn_flags -Wformat-security
142300849b92SRichard Hendersonadd_to warn_flags -Wformat-y2k
142400849b92SRichard Hendersonadd_to warn_flags -Winit-self
142500849b92SRichard Hendersonadd_to warn_flags -Wignored-qualifiers
142600849b92SRichard Hendersonadd_to warn_flags -Wempty-body
142700849b92SRichard Hendersonadd_to warn_flags -Wnested-externs
142800849b92SRichard Hendersonadd_to warn_flags -Wendif-labels
142900849b92SRichard Hendersonadd_to warn_flags -Wexpansion-to-defined
14300a2ebce9SThomas Huthadd_to warn_flags -Wimplicit-fallthrough=2
143100849b92SRichard Henderson
143200849b92SRichard Hendersonnowarn_flags=
143300849b92SRichard Hendersonadd_to nowarn_flags -Wno-initializer-overrides
143400849b92SRichard Hendersonadd_to nowarn_flags -Wno-missing-include-dirs
143500849b92SRichard Hendersonadd_to nowarn_flags -Wno-shift-negative-value
143600849b92SRichard Hendersonadd_to nowarn_flags -Wno-string-plus-int
143700849b92SRichard Hendersonadd_to nowarn_flags -Wno-typedef-redefinition
1438aabab967SRichard Hendersonadd_to nowarn_flags -Wno-tautological-type-limit-compare
1439bac8d222SRichard Hendersonadd_to nowarn_flags -Wno-psabi
144000849b92SRichard Henderson
144100849b92SRichard Hendersongcc_flags="$warn_flags $nowarn_flags"
144293b25869SJohn Snow
144393b25869SJohn Snowcc_has_warning_flag() {
144493b25869SJohn Snow    write_c_skeleton;
144593b25869SJohn Snow
1446a1d29d6cSPeter Maydell    # Use the positive sense of the flag when testing for -Wno-wombat
1447a1d29d6cSPeter Maydell    # support (gcc will happily accept the -Wno- form of unknown
1448a1d29d6cSPeter Maydell    # warning options).
144993b25869SJohn Snow    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
145093b25869SJohn Snow    compile_prog "-Werror $optflag" ""
145193b25869SJohn Snow}
145293b25869SJohn Snow
14534cb37d11SPhilippe Mathieu-Daudéobjcc_has_warning_flag() {
14544cb37d11SPhilippe Mathieu-Daudé    cat > $TMPM <<EOF
14554cb37d11SPhilippe Mathieu-Daudéint main(void) { return 0; }
14564cb37d11SPhilippe Mathieu-DaudéEOF
14574cb37d11SPhilippe Mathieu-Daudé
14584cb37d11SPhilippe Mathieu-Daudé    # Use the positive sense of the flag when testing for -Wno-wombat
14594cb37d11SPhilippe Mathieu-Daudé    # support (gcc will happily accept the -Wno- form of unknown
14604cb37d11SPhilippe Mathieu-Daudé    # warning options).
14614cb37d11SPhilippe Mathieu-Daudé    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
14624cb37d11SPhilippe Mathieu-Daudé    do_objc -Werror $optflag \
14634cb37d11SPhilippe Mathieu-Daudé      $OBJCFLAGS $EXTRA_OBJCFLAGS $CONFIGURE_OBJCFLAGS $QEMU_OBJCFLAGS \
14644cb37d11SPhilippe Mathieu-Daudé      -o $TMPE $TMPM $QEMU_LDFLAGS
14654cb37d11SPhilippe Mathieu-Daudé}
14664cb37d11SPhilippe Mathieu-Daudé
146793b25869SJohn Snowfor flag in $gcc_flags; do
146893b25869SJohn Snow    if cc_has_warning_flag $flag ; then
14698d05095cSPaolo Bonzini        QEMU_CFLAGS="$QEMU_CFLAGS $flag"
14708d05095cSPaolo Bonzini    fi
14714cb37d11SPhilippe Mathieu-Daudé    if objcc_has_warning_flag $flag ; then
14724cb37d11SPhilippe Mathieu-Daudé        QEMU_OBJCFLAGS="$QEMU_OBJCFLAGS $flag"
14734cb37d11SPhilippe Mathieu-Daudé    fi
14748d05095cSPaolo Bonzinidone
14758d05095cSPaolo Bonzini
147663678e17SSteven Noonanif test "$stack_protector" != "no"; then
1477fccd35a0SRodrigo Rebello  cat > $TMPC << EOF
1478fccd35a0SRodrigo Rebelloint main(int argc, char *argv[])
1479fccd35a0SRodrigo Rebello{
1480fccd35a0SRodrigo Rebello    char arr[64], *p = arr, *c = argv[0];
1481fccd35a0SRodrigo Rebello    while (*c) {
1482fccd35a0SRodrigo Rebello        *p++ = *c++;
1483fccd35a0SRodrigo Rebello    }
1484fccd35a0SRodrigo Rebello    return 0;
1485fccd35a0SRodrigo Rebello}
1486fccd35a0SRodrigo RebelloEOF
148763678e17SSteven Noonan  gcc_flags="-fstack-protector-strong -fstack-protector-all"
14883b463a3fSMiroslav Rezanina  sp_on=0
148963678e17SSteven Noonan  for flag in $gcc_flags; do
1490590e5dd9SPeter Maydell    # We need to check both a compile and a link, since some compiler
1491590e5dd9SPeter Maydell    # setups fail only on a .c->.o compile and some only at link time
1492086d5f75SPaolo Bonzini    if compile_object "-Werror $flag" &&
1493590e5dd9SPeter Maydell       compile_prog "-Werror $flag" ""; then
149463678e17SSteven Noonan      QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1495db5adeaaSPaolo Bonzini      QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
14963b463a3fSMiroslav Rezanina      sp_on=1
149763678e17SSteven Noonan      break
149863678e17SSteven Noonan    fi
149963678e17SSteven Noonan  done
15003b463a3fSMiroslav Rezanina  if test "$stack_protector" = yes; then
15013b463a3fSMiroslav Rezanina    if test $sp_on = 0; then
15023b463a3fSMiroslav Rezanina      error_exit "Stack protector not supported"
15033b463a3fSMiroslav Rezanina    fi
15043b463a3fSMiroslav Rezanina  fi
150537746c5eSMarc-André Lureaufi
150637746c5eSMarc-André Lureau
150720bc94a2SPaolo Bonzini# Disable -Wmissing-braces on older compilers that warn even for
150820bc94a2SPaolo Bonzini# the "universal" C zero initializer {0}.
150920bc94a2SPaolo Bonzinicat > $TMPC << EOF
151020bc94a2SPaolo Bonzinistruct {
151120bc94a2SPaolo Bonzini  int a[2];
151220bc94a2SPaolo Bonzini} x = {0};
151320bc94a2SPaolo BonziniEOF
151420bc94a2SPaolo Bonziniif compile_object "-Werror" "" ; then
151520bc94a2SPaolo Bonzini  :
151620bc94a2SPaolo Bonzinielse
151720bc94a2SPaolo Bonzini  QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
151820bc94a2SPaolo Bonzinifi
151920bc94a2SPaolo Bonzini
152021e709aaSMarc-André Lureau# Our module code doesn't support Windows
152121e709aaSMarc-André Lureauif test "$modules" = "yes" && test "$mingw32" = "yes" ; then
152221e709aaSMarc-André Lureau  error_exit "Modules are not available for Windows"
152321e709aaSMarc-André Lureaufi
152421e709aaSMarc-André Lureau
1525bd83c861SChristian Ehrhardt# module_upgrades is only reasonable if modules are enabled
1526bd83c861SChristian Ehrhardtif test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
1527bd83c861SChristian Ehrhardt  error_exit "Can't enable module-upgrades as Modules are not enabled"
1528bd83c861SChristian Ehrhardtfi
1529bd83c861SChristian Ehrhardt
15305f2453acSAlex Bennée# Static linking is not possible with plugins, modules or PIE
153140d6444eSAvi Kivityif test "$static" = "yes" ; then
1532aa0d1f44SPaolo Bonzini  if test "$modules" = "yes" ; then
1533aa0d1f44SPaolo Bonzini    error_exit "static and modules are mutually incompatible"
1534aa0d1f44SPaolo Bonzini  fi
15355f2453acSAlex Bennée  if test "$plugins" = "yes"; then
15365f2453acSAlex Bennée    error_exit "static and plugins are mutually incompatible"
1537ba4dd2aaSAlex Bennée  else
1538ba4dd2aaSAlex Bennée    plugins="no"
15395f2453acSAlex Bennée  fi
154040d6444eSAvi Kivityfi
154137650689SPaolo Bonzinitest "$plugins" = "" && plugins=yes
154240d6444eSAvi Kivity
154340d6444eSAvi Kivitycat > $TMPC << EOF
154421d4a791SAvi Kivity
154521d4a791SAvi Kivity#ifdef __linux__
154621d4a791SAvi Kivity#  define THREAD __thread
154721d4a791SAvi Kivity#else
154821d4a791SAvi Kivity#  define THREAD
154921d4a791SAvi Kivity#endif
155021d4a791SAvi Kivitystatic THREAD int tls_var;
155121d4a791SAvi Kivityint main(void) { return tls_var; }
155240d6444eSAvi KivityEOF
1553b2634124SRichard Henderson
1554ffd205efSJessica Clarke# Check we support -fno-pie and -no-pie first; we will need the former for
1555ffd205efSJessica Clarke# building ROMs, and both for everything if --disable-pie is passed.
1556412aeacdSAlex Bennéeif compile_prog "-Werror -fno-pie" "-no-pie"; then
1557412aeacdSAlex Bennée  CFLAGS_NOPIE="-fno-pie"
1558ffd205efSJessica Clarke  LDFLAGS_NOPIE="-no-pie"
1559412aeacdSAlex Bennéefi
1560412aeacdSAlex Bennée
156112781462SRichard Hendersonif test "$static" = "yes"; then
1562eca7a8e6SRichard Henderson  if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
15635770e8afSPaolo Bonzini    CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
156412781462SRichard Henderson    QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
156512781462SRichard Henderson    pie="yes"
156612781462SRichard Henderson  elif test "$pie" = "yes"; then
156712781462SRichard Henderson    error_exit "-static-pie not available due to missing toolchain support"
156812781462SRichard Henderson  else
156912781462SRichard Henderson    QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
157012781462SRichard Henderson    pie="no"
157112781462SRichard Henderson  fi
157212781462SRichard Hendersonelif test "$pie" = "no"; then
15735770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="$CFLAGS_NOPIE $CONFIGURE_CFLAGS"
1574ffd205efSJessica Clarke  CONFIGURE_LDFLAGS="$LDFLAGS_NOPIE $CONFIGURE_LDFLAGS"
1575eca7a8e6SRichard Hendersonelif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
15765770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
15775770e8afSPaolo Bonzini  CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
157840d6444eSAvi Kivity  pie="yes"
15792c674109SRichard Hendersonelif test "$pie" = "yes"; then
158076ad07a4SPeter Maydell  error_exit "PIE not available due to missing toolchain support"
158140d6444eSAvi Kivityelse
158240d6444eSAvi Kivity  echo "Disabling PIE due to missing toolchain support"
158340d6444eSAvi Kivity  pie="no"
158440d6444eSAvi Kivityfi
158540d6444eSAvi Kivity
1586e6cbd751SRichard Henderson# Detect support for PT_GNU_RELRO + DT_BIND_NOW.
1587e6cbd751SRichard Henderson# The combination is known as "full relro", because .got.plt is read-only too.
1588e6cbd751SRichard Hendersonif compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1589e6cbd751SRichard Henderson  QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
1590e6cbd751SRichard Hendersonfi
1591e6cbd751SRichard Henderson
159209dada40SPaolo Bonzini##########################################
159309dada40SPaolo Bonzini# __sync_fetch_and_and requires at least -march=i486. Many toolchains
159409dada40SPaolo Bonzini# use i686 as default anyway, but for those that don't, an explicit
159509dada40SPaolo Bonzini# specification is necessary
159609dada40SPaolo Bonzini
159709dada40SPaolo Bonziniif test "$cpu" = "i386"; then
159809dada40SPaolo Bonzini  cat > $TMPC << EOF
159909dada40SPaolo Bonzinistatic int sfaa(int *ptr)
160009dada40SPaolo Bonzini{
160109dada40SPaolo Bonzini  return __sync_fetch_and_and(ptr, 0);
160209dada40SPaolo Bonzini}
160309dada40SPaolo Bonzini
160409dada40SPaolo Bonziniint main(void)
160509dada40SPaolo Bonzini{
160609dada40SPaolo Bonzini  int val = 42;
16071405b629SStefan Weil  val = __sync_val_compare_and_swap(&val, 0, 1);
160809dada40SPaolo Bonzini  sfaa(&val);
160909dada40SPaolo Bonzini  return val;
161009dada40SPaolo Bonzini}
161109dada40SPaolo BonziniEOF
161209dada40SPaolo Bonzini  if ! compile_prog "" "" ; then
161309dada40SPaolo Bonzini    QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
161409dada40SPaolo Bonzini  fi
161509dada40SPaolo Bonzinifi
161609dada40SPaolo Bonzini
161756267b62SPhilippe Mathieu-Daudéif test "$tcg" = "enabled"; then
161856267b62SPhilippe Mathieu-Daudé    git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
161956267b62SPhilippe Mathieu-Daudé    git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
162056267b62SPhilippe Mathieu-Daudéfi
162156267b62SPhilippe Mathieu-Daudé
1622afb63ebdSStefan Weilif test -z "${target_list+xxx}" ; then
1623fdb75aefSPaolo Bonzini    default_targets=yes
1624d880a3baSPaolo Bonzini    for target in $default_target_list; do
1625d880a3baSPaolo Bonzini        target_list="$target_list $target"
1626d880a3baSPaolo Bonzini    done
1627d880a3baSPaolo Bonzini    target_list="${target_list# }"
1628121afa9eSAnthony Liguorielse
1629fdb75aefSPaolo Bonzini    default_targets=no
163089138857SStefan Weil    target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1631d880a3baSPaolo Bonzini    for target in $target_list; do
163225b48338SPeter Maydell        # Check that we recognised the target name; this allows a more
163325b48338SPeter Maydell        # friendly error message than if we let it fall through.
163425b48338SPeter Maydell        case " $default_target_list " in
163525b48338SPeter Maydell            *" $target "*)
163625b48338SPeter Maydell                ;;
163725b48338SPeter Maydell            *)
163825b48338SPeter Maydell                error_exit "Unknown target name '$target'"
163925b48338SPeter Maydell                ;;
164025b48338SPeter Maydell        esac
164125b48338SPeter Maydell    done
1642d880a3baSPaolo Bonzinifi
164325b48338SPeter Maydell
1644f55fe278SPaolo Bonzini# see if system emulation was really requested
1645f55fe278SPaolo Bonzinicase " $target_list " in
1646f55fe278SPaolo Bonzini  *"-softmmu "*) softmmu=yes
1647f55fe278SPaolo Bonzini  ;;
1648f55fe278SPaolo Bonzini  *) softmmu=no
1649f55fe278SPaolo Bonzini  ;;
1650f55fe278SPaolo Bonziniesac
16515327cf48Sbellard
1652249247c9SJuan Quintelafeature_not_found() {
1653249247c9SJuan Quintela  feature=$1
165421684af0SStewart Smith  remedy=$2
1655249247c9SJuan Quintela
165676ad07a4SPeter Maydell  error_exit "User requested feature $feature" \
165721684af0SStewart Smith      "configure was not able to find it." \
165821684af0SStewart Smith      "$remedy"
1659249247c9SJuan Quintela}
1660249247c9SJuan Quintela
16617d13299dSbellard# ---
16627d13299dSbellard# big/little endian test
16637d13299dSbellardcat > $TMPC << EOF
1664659eb157SThomas Huth#include <stdio.h>
166561cc919fSMike Frysingershort big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
166661cc919fSMike Frysingershort little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
1667659eb157SThomas Huthint main(int argc, char *argv[])
1668659eb157SThomas Huth{
1669659eb157SThomas Huth    return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
16707d13299dSbellard}
16717d13299dSbellardEOF
16727d13299dSbellard
1673659eb157SThomas Huthif compile_prog ; then
1674659eb157SThomas Huth    if strings -a $TMPE | grep -q BiGeNdIaN ; then
167561cc919fSMike Frysinger        bigendian="yes"
1676659eb157SThomas Huth    elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
167761cc919fSMike Frysinger        bigendian="no"
16787d13299dSbellard    else
16797d13299dSbellard        echo big/little test failed
1680659eb157SThomas Huth        exit 1
16817d13299dSbellard    fi
16827d13299dSbellardelse
168361cc919fSMike Frysinger    echo big/little test failed
1684659eb157SThomas Huth    exit 1
16857d13299dSbellardfi
16867d13299dSbellard
1687299e6f19SPaolo Bonzini#########################################
1688299e6f19SPaolo Bonzini# vhost interdependencies and host support
1689299e6f19SPaolo Bonzini
1690299e6f19SPaolo Bonzini# vhost backends
1691eb9baecdSSergio Lopezif test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then
1692eb9baecdSSergio Lopez  error_exit "vhost-user is not available on Windows"
1693299e6f19SPaolo Bonzinifi
1694108a6481SCindy Lutest "$vhost_vdpa" = "" && vhost_vdpa=$linux
1695108a6481SCindy Luif test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
1696108a6481SCindy Lu  error_exit "vhost-vdpa is only available on Linux"
1697108a6481SCindy Lufi
1698299e6f19SPaolo Bonzinitest "$vhost_kernel" = "" && vhost_kernel=$linux
1699299e6f19SPaolo Bonziniif test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
1700299e6f19SPaolo Bonzini  error_exit "vhost-kernel is only available on Linux"
1701299e6f19SPaolo Bonzinifi
1702299e6f19SPaolo Bonzini
1703299e6f19SPaolo Bonzini# vhost-kernel devices
1704299e6f19SPaolo Bonzinitest "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
1705299e6f19SPaolo Bonziniif test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
1706299e6f19SPaolo Bonzini  error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
1707299e6f19SPaolo Bonzinifi
1708299e6f19SPaolo Bonzinitest "$vhost_vsock" = "" && vhost_vsock=$vhost_kernel
1709299e6f19SPaolo Bonziniif test "$vhost_vsock" = "yes" && test "$vhost_kernel" != "yes"; then
1710299e6f19SPaolo Bonzini  error_exit "--enable-vhost-vsock requires --enable-vhost-kernel"
1711299e6f19SPaolo Bonzinifi
1712299e6f19SPaolo Bonzini
1713299e6f19SPaolo Bonzini# vhost-user backends
1714299e6f19SPaolo Bonzinitest "$vhost_net_user" = "" && vhost_net_user=$vhost_user
1715299e6f19SPaolo Bonziniif test "$vhost_net_user" = "yes" && test "$vhost_user" = "no"; then
1716299e6f19SPaolo Bonzini  error_exit "--enable-vhost-net-user requires --enable-vhost-user"
1717299e6f19SPaolo Bonzinifi
1718299e6f19SPaolo Bonzinitest "$vhost_crypto" = "" && vhost_crypto=$vhost_user
1719299e6f19SPaolo Bonziniif test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
1720299e6f19SPaolo Bonzini  error_exit "--enable-vhost-crypto requires --enable-vhost-user"
1721299e6f19SPaolo Bonzinifi
172298fc1adaSDr. David Alan Gilberttest "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
172398fc1adaSDr. David Alan Gilbertif test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
172498fc1adaSDr. David Alan Gilbert  error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
172598fc1adaSDr. David Alan Gilbertfi
1726108a6481SCindy Lu#vhost-vdpa backends
1727108a6481SCindy Lutest "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa
1728108a6481SCindy Luif test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then
1729108a6481SCindy Lu  error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa"
1730108a6481SCindy Lufi
1731299e6f19SPaolo Bonzini
173240bc0ca9SLaurent Vivier# OR the vhost-kernel, vhost-vdpa and vhost-user values for simplicity
1733299e6f19SPaolo Bonziniif test "$vhost_net" = ""; then
1734299e6f19SPaolo Bonzini  test "$vhost_net_user" = "yes" && vhost_net=yes
173540bc0ca9SLaurent Vivier  test "$vhost_net_vdpa" = "yes" && vhost_net=yes
1736299e6f19SPaolo Bonzini  test "$vhost_kernel" = "yes" && vhost_net=yes
1737299e6f19SPaolo Bonzinifi
1738299e6f19SPaolo Bonzini
1739015a33bdSGonglei##########################################
1740779ab5e3SStefan Weil# pkg-config probe
1741779ab5e3SStefan Weil
1742779ab5e3SStefan Weilif ! has "$pkg_config_exe"; then
174376ad07a4SPeter Maydell  error_exit "pkg-config binary '$pkg_config_exe' not found"
1744779ab5e3SStefan Weilfi
1745779ab5e3SStefan Weil
1746779ab5e3SStefan Weil##########################################
1747e37630caSaliguori# xen probe
1748e37630caSaliguori
17491badb709SPaolo Bonziniif test "$xen" != "disabled" ; then
1750c1cdd9d5SJuergen Gross  # Check whether Xen library path is specified via --extra-ldflags to avoid
1751c1cdd9d5SJuergen Gross  # overriding this setting with pkg-config output. If not, try pkg-config
1752c1cdd9d5SJuergen Gross  # to obtain all needed flags.
1753c1cdd9d5SJuergen Gross
1754c1cdd9d5SJuergen Gross  if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \
1755c1cdd9d5SJuergen Gross     $pkg_config --exists xencontrol ; then
1756c1cdd9d5SJuergen Gross    xen_ctrl_version="$(printf '%d%02d%02d' \
1757c1cdd9d5SJuergen Gross      $($pkg_config --modversion xencontrol | sed 's/\./ /g') )"
17581badb709SPaolo Bonzini    xen=enabled
17595b6a8f43SMichael Tokarev    xen_pc="xencontrol xenstore xenforeignmemory xengnttab"
1760c1cdd9d5SJuergen Gross    xen_pc="$xen_pc xenevtchn xendevicemodel"
176158ea9a7aSAnthony PERARD    if $pkg_config --exists xentoolcore; then
176258ea9a7aSAnthony PERARD      xen_pc="$xen_pc xentoolcore"
176358ea9a7aSAnthony PERARD    fi
1764582ea95fSMarc-André Lureau    xen_cflags="$($pkg_config --cflags $xen_pc)"
1765582ea95fSMarc-André Lureau    xen_libs="$($pkg_config --libs $xen_pc)"
1766c1cdd9d5SJuergen Gross  else
1767c1cdd9d5SJuergen Gross
17685b6a8f43SMichael Tokarev    xen_libs="-lxenstore -lxenctrl"
1769d9506cabSAnthony PERARD    xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
1770d5b93ddfSAnthony PERARD
177150ced5b3SStefan Weil    # First we test whether Xen headers and libraries are available.
177250ced5b3SStefan Weil    # If no, we are done and there is no Xen support.
177350ced5b3SStefan Weil    # If yes, more tests are run to detect the Xen version.
177450ced5b3SStefan Weil
177550ced5b3SStefan Weil    # Xen (any)
177650ced5b3SStefan Weil    cat > $TMPC <<EOF
177750ced5b3SStefan Weil#include <xenctrl.h>
177850ced5b3SStefan Weilint main(void) {
177950ced5b3SStefan Weil  return 0;
178050ced5b3SStefan Weil}
178150ced5b3SStefan WeilEOF
178250ced5b3SStefan Weil    if ! compile_prog "" "$xen_libs" ; then
178350ced5b3SStefan Weil      # Xen not found
17841badb709SPaolo Bonzini      if test "$xen" = "enabled" ; then
178521684af0SStewart Smith        feature_not_found "xen" "Install xen devel"
178650ced5b3SStefan Weil      fi
17871badb709SPaolo Bonzini      xen=disabled
178850ced5b3SStefan Weil
1789d5b93ddfSAnthony PERARD    # Xen unstable
179069deef08SPeter Maydell    elif
179169deef08SPeter Maydell        cat > $TMPC <<EOF &&
17922cbf8903SRoss Lagerwall#undef XC_WANT_COMPAT_DEVICEMODEL_API
17932cbf8903SRoss Lagerwall#define __XEN_TOOLS__
17942cbf8903SRoss Lagerwall#include <xendevicemodel.h>
1795d3c49ebbSPaul Durrant#include <xenforeignmemory.h>
17962cbf8903SRoss Lagerwallint main(void) {
17972cbf8903SRoss Lagerwall  xendevicemodel_handle *xd;
1798d3c49ebbSPaul Durrant  xenforeignmemory_handle *xfmem;
17992cbf8903SRoss Lagerwall
18002cbf8903SRoss Lagerwall  xd = xendevicemodel_open(0, 0);
18012cbf8903SRoss Lagerwall  xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);
18022cbf8903SRoss Lagerwall
1803d3c49ebbSPaul Durrant  xfmem = xenforeignmemory_open(0, 0);
1804d3c49ebbSPaul Durrant  xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);
1805d3c49ebbSPaul Durrant
18062cbf8903SRoss Lagerwall  return 0;
18072cbf8903SRoss Lagerwall}
18082cbf8903SRoss LagerwallEOF
18092cbf8903SRoss Lagerwall        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
18102cbf8903SRoss Lagerwall      then
18112cbf8903SRoss Lagerwall      xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
18122cbf8903SRoss Lagerwall      xen_ctrl_version=41100
18131badb709SPaolo Bonzini      xen=enabled
18142cbf8903SRoss Lagerwall    elif
18152cbf8903SRoss Lagerwall        cat > $TMPC <<EOF &&
18165ba3d756SIgor Druzhinin#undef XC_WANT_COMPAT_MAP_FOREIGN_API
18175ba3d756SIgor Druzhinin#include <xenforeignmemory.h>
181858ea9a7aSAnthony PERARD#include <xentoolcore.h>
18195ba3d756SIgor Druzhininint main(void) {
18205ba3d756SIgor Druzhinin  xenforeignmemory_handle *xfmem;
18215ba3d756SIgor Druzhinin
18225ba3d756SIgor Druzhinin  xfmem = xenforeignmemory_open(0, 0);
18235ba3d756SIgor Druzhinin  xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
182458ea9a7aSAnthony PERARD  xentoolcore_restrict_all(0);
18255ba3d756SIgor Druzhinin
18265ba3d756SIgor Druzhinin  return 0;
18275ba3d756SIgor Druzhinin}
18285ba3d756SIgor DruzhininEOF
182958ea9a7aSAnthony PERARD        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
18305ba3d756SIgor Druzhinin      then
183158ea9a7aSAnthony PERARD      xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
18325ba3d756SIgor Druzhinin      xen_ctrl_version=41000
18331badb709SPaolo Bonzini      xen=enabled
18345ba3d756SIgor Druzhinin    elif
18355ba3d756SIgor Druzhinin        cat > $TMPC <<EOF &&
1836da8090ccSPaul Durrant#undef XC_WANT_COMPAT_DEVICEMODEL_API
1837da8090ccSPaul Durrant#define __XEN_TOOLS__
1838da8090ccSPaul Durrant#include <xendevicemodel.h>
1839da8090ccSPaul Durrantint main(void) {
1840da8090ccSPaul Durrant  xendevicemodel_handle *xd;
1841da8090ccSPaul Durrant
1842da8090ccSPaul Durrant  xd = xendevicemodel_open(0, 0);
1843da8090ccSPaul Durrant  xendevicemodel_close(xd);
1844da8090ccSPaul Durrant
1845da8090ccSPaul Durrant  return 0;
1846da8090ccSPaul Durrant}
1847da8090ccSPaul DurrantEOF
1848da8090ccSPaul Durrant        compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs"
1849da8090ccSPaul Durrant      then
1850da8090ccSPaul Durrant      xen_stable_libs="-lxendevicemodel $xen_stable_libs"
1851f1167ee6SJuergen Gross      xen_ctrl_version=40900
18521badb709SPaolo Bonzini      xen=enabled
1853da8090ccSPaul Durrant    elif
1854da8090ccSPaul Durrant        cat > $TMPC <<EOF &&
18555eeb39c2SIan Campbell/*
18565eeb39c2SIan Campbell * If we have stable libs the we don't want the libxc compat
18575eeb39c2SIan Campbell * layers, regardless of what CFLAGS we may have been given.
1858b6eb9b45SPaulina Szubarczyk *
1859b6eb9b45SPaulina Szubarczyk * Also, check if xengnttab_grant_copy_segment_t is defined and
1860b6eb9b45SPaulina Szubarczyk * grant copy operation is implemented.
1861b6eb9b45SPaulina Szubarczyk */
1862b6eb9b45SPaulina Szubarczyk#undef XC_WANT_COMPAT_EVTCHN_API
1863b6eb9b45SPaulina Szubarczyk#undef XC_WANT_COMPAT_GNTTAB_API
1864b6eb9b45SPaulina Szubarczyk#undef XC_WANT_COMPAT_MAP_FOREIGN_API
1865b6eb9b45SPaulina Szubarczyk#include <xenctrl.h>
1866b6eb9b45SPaulina Szubarczyk#include <xenstore.h>
1867b6eb9b45SPaulina Szubarczyk#include <xenevtchn.h>
1868b6eb9b45SPaulina Szubarczyk#include <xengnttab.h>
1869b6eb9b45SPaulina Szubarczyk#include <xenforeignmemory.h>
1870b6eb9b45SPaulina Szubarczyk#include <stdint.h>
1871b6eb9b45SPaulina Szubarczyk#include <xen/hvm/hvm_info_table.h>
1872b6eb9b45SPaulina Szubarczyk#if !defined(HVM_MAX_VCPUS)
1873b6eb9b45SPaulina Szubarczyk# error HVM_MAX_VCPUS not defined
1874b6eb9b45SPaulina Szubarczyk#endif
1875b6eb9b45SPaulina Szubarczykint main(void) {
1876b6eb9b45SPaulina Szubarczyk  xc_interface *xc = NULL;
1877b6eb9b45SPaulina Szubarczyk  xenforeignmemory_handle *xfmem;
1878b6eb9b45SPaulina Szubarczyk  xenevtchn_handle *xe;
1879b6eb9b45SPaulina Szubarczyk  xengnttab_handle *xg;
1880b6eb9b45SPaulina Szubarczyk  xengnttab_grant_copy_segment_t* seg = NULL;
1881b6eb9b45SPaulina Szubarczyk
1882b6eb9b45SPaulina Szubarczyk  xs_daemon_open();
1883b6eb9b45SPaulina Szubarczyk
1884b6eb9b45SPaulina Szubarczyk  xc = xc_interface_open(0, 0, 0);
1885b6eb9b45SPaulina Szubarczyk  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1886b6eb9b45SPaulina Szubarczyk  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
1887b6eb9b45SPaulina Szubarczyk  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
1888b6eb9b45SPaulina Szubarczyk  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
1889b6eb9b45SPaulina Szubarczyk
1890b6eb9b45SPaulina Szubarczyk  xfmem = xenforeignmemory_open(0, 0);
1891b6eb9b45SPaulina Szubarczyk  xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
1892b6eb9b45SPaulina Szubarczyk
1893b6eb9b45SPaulina Szubarczyk  xe = xenevtchn_open(0, 0);
1894b6eb9b45SPaulina Szubarczyk  xenevtchn_fd(xe);
1895b6eb9b45SPaulina Szubarczyk
1896b6eb9b45SPaulina Szubarczyk  xg = xengnttab_open(0, 0);
1897b6eb9b45SPaulina Szubarczyk  xengnttab_grant_copy(xg, 0, seg);
1898b6eb9b45SPaulina Szubarczyk
1899b6eb9b45SPaulina Szubarczyk  return 0;
1900b6eb9b45SPaulina Szubarczyk}
1901b6eb9b45SPaulina SzubarczykEOF
1902b6eb9b45SPaulina Szubarczyk        compile_prog "" "$xen_libs $xen_stable_libs"
1903b6eb9b45SPaulina Szubarczyk      then
1904f1167ee6SJuergen Gross      xen_ctrl_version=40800
19051badb709SPaolo Bonzini      xen=enabled
1906b6eb9b45SPaulina Szubarczyk    elif
1907b6eb9b45SPaulina Szubarczyk        cat > $TMPC <<EOF &&
1908b6eb9b45SPaulina Szubarczyk/*
1909b6eb9b45SPaulina Szubarczyk * If we have stable libs the we don't want the libxc compat
1910b6eb9b45SPaulina Szubarczyk * layers, regardless of what CFLAGS we may have been given.
19115eeb39c2SIan Campbell */
19125eeb39c2SIan Campbell#undef XC_WANT_COMPAT_EVTCHN_API
19135eeb39c2SIan Campbell#undef XC_WANT_COMPAT_GNTTAB_API
19145eeb39c2SIan Campbell#undef XC_WANT_COMPAT_MAP_FOREIGN_API
19155eeb39c2SIan Campbell#include <xenctrl.h>
19165eeb39c2SIan Campbell#include <xenstore.h>
19175eeb39c2SIan Campbell#include <xenevtchn.h>
19185eeb39c2SIan Campbell#include <xengnttab.h>
19195eeb39c2SIan Campbell#include <xenforeignmemory.h>
19205eeb39c2SIan Campbell#include <stdint.h>
19215eeb39c2SIan Campbell#include <xen/hvm/hvm_info_table.h>
19225eeb39c2SIan Campbell#if !defined(HVM_MAX_VCPUS)
19235eeb39c2SIan Campbell# error HVM_MAX_VCPUS not defined
19245eeb39c2SIan Campbell#endif
19255eeb39c2SIan Campbellint main(void) {
19265eeb39c2SIan Campbell  xc_interface *xc = NULL;
19275eeb39c2SIan Campbell  xenforeignmemory_handle *xfmem;
19285eeb39c2SIan Campbell  xenevtchn_handle *xe;
19295eeb39c2SIan Campbell  xengnttab_handle *xg;
19305eeb39c2SIan Campbell
19315eeb39c2SIan Campbell  xs_daemon_open();
19325eeb39c2SIan Campbell
19335eeb39c2SIan Campbell  xc = xc_interface_open(0, 0, 0);
19345eeb39c2SIan Campbell  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
19355eeb39c2SIan Campbell  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
19365eeb39c2SIan Campbell  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
19375eeb39c2SIan Campbell  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
19385eeb39c2SIan Campbell
19395eeb39c2SIan Campbell  xfmem = xenforeignmemory_open(0, 0);
19405eeb39c2SIan Campbell  xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
19415eeb39c2SIan Campbell
19425eeb39c2SIan Campbell  xe = xenevtchn_open(0, 0);
19435eeb39c2SIan Campbell  xenevtchn_fd(xe);
19445eeb39c2SIan Campbell
19455eeb39c2SIan Campbell  xg = xengnttab_open(0, 0);
19465eeb39c2SIan Campbell  xengnttab_map_grant_ref(xg, 0, 0, 0);
19475eeb39c2SIan Campbell
19485eeb39c2SIan Campbell  return 0;
19495eeb39c2SIan Campbell}
19505eeb39c2SIan CampbellEOF
19515eeb39c2SIan Campbell        compile_prog "" "$xen_libs $xen_stable_libs"
19525eeb39c2SIan Campbell      then
1953f1167ee6SJuergen Gross      xen_ctrl_version=40701
19541badb709SPaolo Bonzini      xen=enabled
1955cdadde39SRoger Pau Monne
1956cdadde39SRoger Pau Monne    # Xen 4.6
1957cdadde39SRoger Pau Monne    elif
1958cdadde39SRoger Pau Monne        cat > $TMPC <<EOF &&
1959cdadde39SRoger Pau Monne#include <xenctrl.h>
1960e108a3c1SAnthony PERARD#include <xenstore.h>
1961d5b93ddfSAnthony PERARD#include <stdint.h>
1962d5b93ddfSAnthony PERARD#include <xen/hvm/hvm_info_table.h>
1963d5b93ddfSAnthony PERARD#if !defined(HVM_MAX_VCPUS)
1964d5b93ddfSAnthony PERARD# error HVM_MAX_VCPUS not defined
1965d5b93ddfSAnthony PERARD#endif
1966d5b93ddfSAnthony PERARDint main(void) {
1967d5b93ddfSAnthony PERARD  xc_interface *xc;
1968d5b93ddfSAnthony PERARD  xs_daemon_open();
1969d5b93ddfSAnthony PERARD  xc = xc_interface_open(0, 0, 0);
1970d5b93ddfSAnthony PERARD  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1971d5b93ddfSAnthony PERARD  xc_gnttab_open(NULL, 0);
1972b87de24eSAnthony PERARD  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
19738688e065SStefano Stabellini  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
1974d8b441a3SJan Beulich  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
197520a544c7SKonrad Rzeszutek Wilk  xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
1976d8b441a3SJan Beulich  return 0;
1977d8b441a3SJan Beulich}
1978d8b441a3SJan BeulichEOF
1979d8b441a3SJan Beulich        compile_prog "" "$xen_libs"
1980d8b441a3SJan Beulich      then
1981f1167ee6SJuergen Gross      xen_ctrl_version=40600
19821badb709SPaolo Bonzini      xen=enabled
1983d8b441a3SJan Beulich
1984d8b441a3SJan Beulich    # Xen 4.5
1985d8b441a3SJan Beulich    elif
1986d8b441a3SJan Beulich        cat > $TMPC <<EOF &&
1987d8b441a3SJan Beulich#include <xenctrl.h>
1988d8b441a3SJan Beulich#include <xenstore.h>
1989d8b441a3SJan Beulich#include <stdint.h>
1990d8b441a3SJan Beulich#include <xen/hvm/hvm_info_table.h>
1991d8b441a3SJan Beulich#if !defined(HVM_MAX_VCPUS)
1992d8b441a3SJan Beulich# error HVM_MAX_VCPUS not defined
1993d8b441a3SJan Beulich#endif
1994d8b441a3SJan Beulichint main(void) {
1995d8b441a3SJan Beulich  xc_interface *xc;
1996d8b441a3SJan Beulich  xs_daemon_open();
1997d8b441a3SJan Beulich  xc = xc_interface_open(0, 0, 0);
1998d8b441a3SJan Beulich  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1999d8b441a3SJan Beulich  xc_gnttab_open(NULL, 0);
2000d8b441a3SJan Beulich  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2001d8b441a3SJan Beulich  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
20023996e85cSPaul Durrant  xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
20033996e85cSPaul Durrant  return 0;
20043996e85cSPaul Durrant}
20053996e85cSPaul DurrantEOF
20063996e85cSPaul Durrant        compile_prog "" "$xen_libs"
20073996e85cSPaul Durrant      then
2008f1167ee6SJuergen Gross      xen_ctrl_version=40500
20091badb709SPaolo Bonzini      xen=enabled
20103996e85cSPaul Durrant
20113996e85cSPaul Durrant    elif
20123996e85cSPaul Durrant        cat > $TMPC <<EOF &&
20133996e85cSPaul Durrant#include <xenctrl.h>
20143996e85cSPaul Durrant#include <xenstore.h>
20153996e85cSPaul Durrant#include <stdint.h>
20163996e85cSPaul Durrant#include <xen/hvm/hvm_info_table.h>
20173996e85cSPaul Durrant#if !defined(HVM_MAX_VCPUS)
20183996e85cSPaul Durrant# error HVM_MAX_VCPUS not defined
20193996e85cSPaul Durrant#endif
20203996e85cSPaul Durrantint main(void) {
20213996e85cSPaul Durrant  xc_interface *xc;
20223996e85cSPaul Durrant  xs_daemon_open();
20233996e85cSPaul Durrant  xc = xc_interface_open(0, 0, 0);
20243996e85cSPaul Durrant  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
20253996e85cSPaul Durrant  xc_gnttab_open(NULL, 0);
20263996e85cSPaul Durrant  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
20273996e85cSPaul Durrant  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
20288688e065SStefano Stabellini  return 0;
20298688e065SStefano Stabellini}
20308688e065SStefano StabelliniEOF
20318688e065SStefano Stabellini        compile_prog "" "$xen_libs"
203269deef08SPeter Maydell      then
2033f1167ee6SJuergen Gross      xen_ctrl_version=40200
20341badb709SPaolo Bonzini      xen=enabled
20358688e065SStefano Stabellini
2036e37630caSaliguori    else
20371badb709SPaolo Bonzini      if test "$xen" = "enabled" ; then
2038edfb07edSIan Campbell        feature_not_found "xen (unsupported version)" \
2039edfb07edSIan Campbell                          "Install a supported xen (xen 4.2 or newer)"
2040fc321b4bSJuan Quintela      fi
20411badb709SPaolo Bonzini      xen=disabled
2042e37630caSaliguori    fi
2043d5b93ddfSAnthony PERARD
20441badb709SPaolo Bonzini    if test "$xen" = enabled; then
2045f1167ee6SJuergen Gross      if test $xen_ctrl_version -ge 40701  ; then
2046582ea95fSMarc-André Lureau        xen_libs="$xen_libs $xen_stable_libs "
20475eeb39c2SIan Campbell      fi
2048d5b93ddfSAnthony PERARD    fi
2049e37630caSaliguori  fi
2050c1cdd9d5SJuergen Grossfi
2051e37630caSaliguori
2052d661d9a4SJustin Terry (VM)##########################################
20532da776dbSMichael R. Hines# RDMA needs OpenFabrics libraries
20542da776dbSMichael R. Hinesif test "$rdma" != "no" ; then
20552da776dbSMichael R. Hines  cat > $TMPC <<EOF
20562da776dbSMichael R. Hines#include <rdma/rdma_cma.h>
20572da776dbSMichael R. Hinesint main(void) { return 0; }
20582da776dbSMichael R. HinesEOF
2059ef6d4ccdSYuval Shaia  rdma_libs="-lrdmacm -libverbs -libumad"
20602da776dbSMichael R. Hines  if compile_prog "" "$rdma_libs" ; then
20612da776dbSMichael R. Hines    rdma="yes"
20622da776dbSMichael R. Hines  else
20632da776dbSMichael R. Hines    if test "$rdma" = "yes" ; then
20642da776dbSMichael R. Hines        error_exit \
2065ef6d4ccdSYuval Shaia            " OpenFabrics librdmacm/libibverbs/libibumad not present." \
20662da776dbSMichael R. Hines            " Your options:" \
2067ef6d4ccdSYuval Shaia            "  (1) Fast: Install infiniband packages (devel) from your distro." \
20682da776dbSMichael R. Hines            "  (2) Cleanest: Install libraries from www.openfabrics.org" \
20692da776dbSMichael R. Hines            "  (3) Also: Install softiwarp if you don't have RDMA hardware"
20702da776dbSMichael R. Hines    fi
20712da776dbSMichael R. Hines    rdma="no"
20722da776dbSMichael R. Hines  fi
20732da776dbSMichael R. Hinesfi
20742da776dbSMichael R. Hines
207521ab34c9SMarcel Apfelbaum##########################################
207621ab34c9SMarcel Apfelbaum# PVRDMA detection
207721ab34c9SMarcel Apfelbaum
207821ab34c9SMarcel Apfelbaumcat > $TMPC <<EOF &&
207921ab34c9SMarcel Apfelbaum#include <sys/mman.h>
208021ab34c9SMarcel Apfelbaum
208121ab34c9SMarcel Apfelbaumint
208221ab34c9SMarcel Apfelbaummain(void)
208321ab34c9SMarcel Apfelbaum{
208421ab34c9SMarcel Apfelbaum    char buf = 0;
208521ab34c9SMarcel Apfelbaum    void *addr = &buf;
208621ab34c9SMarcel Apfelbaum    addr = mremap(addr, 0, 1, MREMAP_MAYMOVE | MREMAP_FIXED);
208721ab34c9SMarcel Apfelbaum
208821ab34c9SMarcel Apfelbaum    return 0;
208921ab34c9SMarcel Apfelbaum}
209021ab34c9SMarcel ApfelbaumEOF
209121ab34c9SMarcel Apfelbaum
209221ab34c9SMarcel Apfelbaumif test "$rdma" = "yes" ; then
209321ab34c9SMarcel Apfelbaum    case "$pvrdma" in
209421ab34c9SMarcel Apfelbaum    "")
209521ab34c9SMarcel Apfelbaum        if compile_prog "" ""; then
209621ab34c9SMarcel Apfelbaum            pvrdma="yes"
209721ab34c9SMarcel Apfelbaum        else
209821ab34c9SMarcel Apfelbaum            pvrdma="no"
209921ab34c9SMarcel Apfelbaum        fi
210021ab34c9SMarcel Apfelbaum        ;;
210121ab34c9SMarcel Apfelbaum    "yes")
210221ab34c9SMarcel Apfelbaum        if ! compile_prog "" ""; then
210321ab34c9SMarcel Apfelbaum            error_exit "PVRDMA is not supported since mremap is not implemented"
210421ab34c9SMarcel Apfelbaum        fi
210521ab34c9SMarcel Apfelbaum        pvrdma="yes"
210621ab34c9SMarcel Apfelbaum        ;;
210721ab34c9SMarcel Apfelbaum    "no")
210821ab34c9SMarcel Apfelbaum        pvrdma="no"
210921ab34c9SMarcel Apfelbaum        ;;
211021ab34c9SMarcel Apfelbaum    esac
211121ab34c9SMarcel Apfelbaumelse
211221ab34c9SMarcel Apfelbaum    if test "$pvrdma" = "yes" ; then
211321ab34c9SMarcel Apfelbaum        error_exit "PVRDMA requires rdma suppport"
211421ab34c9SMarcel Apfelbaum    fi
211521ab34c9SMarcel Apfelbaum    pvrdma="no"
211621ab34c9SMarcel Apfelbaumfi
211795c6bff3SBenoît Canet
2118ee108585SYuval Shaia# Let's see if enhanced reg_mr is supported
2119ee108585SYuval Shaiaif test "$pvrdma" = "yes" ; then
2120ee108585SYuval Shaia
2121ee108585SYuval Shaiacat > $TMPC <<EOF &&
2122ee108585SYuval Shaia#include <infiniband/verbs.h>
2123ee108585SYuval Shaia
2124ee108585SYuval Shaiaint
2125ee108585SYuval Shaiamain(void)
2126ee108585SYuval Shaia{
2127ee108585SYuval Shaia    struct ibv_mr *mr;
2128ee108585SYuval Shaia    struct ibv_pd *pd = NULL;
2129ee108585SYuval Shaia    size_t length = 10;
2130ee108585SYuval Shaia    uint64_t iova = 0;
2131ee108585SYuval Shaia    int access = 0;
2132ee108585SYuval Shaia    void *addr = NULL;
2133ee108585SYuval Shaia
2134ee108585SYuval Shaia    mr = ibv_reg_mr_iova(pd, addr, length, iova, access);
2135ee108585SYuval Shaia
2136ee108585SYuval Shaia    ibv_dereg_mr(mr);
2137ee108585SYuval Shaia
2138ee108585SYuval Shaia    return 0;
2139ee108585SYuval Shaia}
2140ee108585SYuval ShaiaEOF
2141ee108585SYuval Shaia    if ! compile_prog "" "-libverbs"; then
2142ee108585SYuval Shaia        QEMU_CFLAGS="$QEMU_CFLAGS -DLEGACY_RDMA_REG_MR"
2143ee108585SYuval Shaia    fi
2144ee108585SYuval Shaiafi
2145ee108585SYuval Shaia
214695c6bff3SBenoît Canet##########################################
2147e18df141SAnthony Liguori# glib support probe
2148a52d28afSPaolo Bonzini
2149b4c6036fSDaniel P. Berrangéglib_req_ver=2.56
2150aa0d1f44SPaolo Bonziniglib_modules=gthread-2.0
2151aa0d1f44SPaolo Bonziniif test "$modules" = yes; then
2152a88afc64SGerd Hoffmann    glib_modules="$glib_modules gmodule-export-2.0"
2153b906acacSPaolo Bonzinielif test "$plugins" = "yes"; then
2154b906acacSPaolo Bonzini    glib_modules="$glib_modules gmodule-no-export-2.0"
215554cb65d8SEmilio G. Cotafi
2156e26110cfSFam Zheng
2157aa0d1f44SPaolo Bonzinifor i in $glib_modules; do
2158e26110cfSFam Zheng    if $pkg_config --atleast-version=$glib_req_ver $i; then
215989138857SStefan Weil        glib_cflags=$($pkg_config --cflags $i)
216089138857SStefan Weil        glib_libs=$($pkg_config --libs $i)
2161e18df141SAnthony Liguori    else
2162e26110cfSFam Zheng        error_exit "glib-$glib_req_ver $i is required to compile QEMU"
2163e26110cfSFam Zheng    fi
2164e26110cfSFam Zhengdone
2165e26110cfSFam Zheng
2166215b0c2fSPaolo Bonzini# This workaround is required due to a bug in pkg-config file for glib as it
2167215b0c2fSPaolo Bonzini# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
2168215b0c2fSPaolo Bonzini
2169215b0c2fSPaolo Bonziniif test "$static" = yes && test "$mingw32" = yes; then
2170215b0c2fSPaolo Bonzini    glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
2171215b0c2fSPaolo Bonzinifi
2172215b0c2fSPaolo Bonzini
217320cf7b8eSDenis Plotnikovif ! test "$gio" = "no"; then
217420cf7b8eSDenis Plotnikov    pass=no
2175f876b765SMarc-André Lureau    if $pkg_config --atleast-version=$glib_req_ver gio-2.0; then
2176f876b765SMarc-André Lureau        gio_cflags=$($pkg_config --cflags gio-2.0)
2177f876b765SMarc-André Lureau        gio_libs=$($pkg_config --libs gio-2.0)
217825a97a56SMarc-André Lureau        gdbus_codegen=$($pkg_config --variable=gdbus_codegen gio-2.0)
21795ecfb76cSPaolo Bonzini        if ! has "$gdbus_codegen"; then
21800dba4897SMarc-André Lureau            gdbus_codegen=
21810dba4897SMarc-André Lureau        fi
218276346b62SPeter Maydell        # Check that the libraries actually work -- Ubuntu 18.04 ships
218376346b62SPeter Maydell        # with pkg-config --static --libs data for gio-2.0 that is missing
218476346b62SPeter Maydell        # -lblkid and will give a link error.
218513ceae66SPeter Maydell        cat > $TMPC <<EOF
218613ceae66SPeter Maydell#include <gio/gio.h>
218713ceae66SPeter Maydellint main(void)
218813ceae66SPeter Maydell{
218913ceae66SPeter Maydell    g_dbus_proxy_new_sync(0, 0, 0, 0, 0, 0, 0, 0);
219013ceae66SPeter Maydell    return 0;
219113ceae66SPeter Maydell}
219213ceae66SPeter MaydellEOF
219313ceae66SPeter Maydell        if compile_prog "$gio_cflags" "$gio_libs" ; then
219420cf7b8eSDenis Plotnikov            pass=yes
219576346b62SPeter Maydell        else
219620cf7b8eSDenis Plotnikov            pass=no
2197f876b765SMarc-André Lureau        fi
2198f876b765SMarc-André Lureau
219920cf7b8eSDenis Plotnikov        if test "$pass" = "yes" &&
220020cf7b8eSDenis Plotnikov            $pkg_config --atleast-version=$glib_req_ver gio-unix-2.0; then
220125a97a56SMarc-André Lureau            gio_cflags="$gio_cflags $($pkg_config --cflags gio-unix-2.0)"
220225a97a56SMarc-André Lureau            gio_libs="$gio_libs $($pkg_config --libs gio-unix-2.0)"
220325a97a56SMarc-André Lureau        fi
220420cf7b8eSDenis Plotnikov    fi
220520cf7b8eSDenis Plotnikov
220620cf7b8eSDenis Plotnikov    if test "$pass" = "no"; then
220720cf7b8eSDenis Plotnikov        if test "$gio" = "yes"; then
220820cf7b8eSDenis Plotnikov            feature_not_found "gio" "Install libgio >= 2.0"
220920cf7b8eSDenis Plotnikov        else
221020cf7b8eSDenis Plotnikov            gio=no
221120cf7b8eSDenis Plotnikov        fi
221220cf7b8eSDenis Plotnikov    else
221320cf7b8eSDenis Plotnikov        gio=yes
221420cf7b8eSDenis Plotnikov    fi
221520cf7b8eSDenis Plotnikovfi
221625a97a56SMarc-André Lureau
2217977a82abSDaniel P. Berrange# Sanity check that the current size_t matches the
2218977a82abSDaniel P. Berrange# size that glib thinks it should be. This catches
2219977a82abSDaniel P. Berrange# problems on multi-arch where people try to build
2220977a82abSDaniel P. Berrange# 32-bit QEMU while pointing at 64-bit glib headers
2221977a82abSDaniel P. Berrangecat > $TMPC <<EOF
2222977a82abSDaniel P. Berrange#include <glib.h>
2223977a82abSDaniel P. Berrange#include <unistd.h>
2224977a82abSDaniel P. Berrange
2225977a82abSDaniel P. Berrange#define QEMU_BUILD_BUG_ON(x) \
2226977a82abSDaniel P. Berrange  typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
2227977a82abSDaniel P. Berrange
2228977a82abSDaniel P. Berrangeint main(void) {
2229977a82abSDaniel P. Berrange   QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
2230977a82abSDaniel P. Berrange   return 0;
2231977a82abSDaniel P. Berrange}
2232977a82abSDaniel P. BerrangeEOF
2233977a82abSDaniel P. Berrange
2234215b0c2fSPaolo Bonziniif ! compile_prog "$glib_cflags" "$glib_libs" ; then
2235977a82abSDaniel P. Berrange    error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
2236977a82abSDaniel P. Berrange               "You probably need to set PKG_CONFIG_LIBDIR"\
2237977a82abSDaniel P. Berrange	       "to point to the right pkg-config files for your"\
2238977a82abSDaniel P. Berrange	       "build target"
2239977a82abSDaniel P. Berrangefi
2240977a82abSDaniel P. Berrange
22419bda600bSEric Blake# Silence clang warnings triggered by glib < 2.57.2
22429bda600bSEric Blakecat > $TMPC << EOF
22439bda600bSEric Blake#include <glib.h>
22449bda600bSEric Blaketypedef struct Foo {
22459bda600bSEric Blake    int i;
22469bda600bSEric Blake} Foo;
22479bda600bSEric Blakestatic void foo_free(Foo *f)
22489bda600bSEric Blake{
22499bda600bSEric Blake    g_free(f);
22509bda600bSEric Blake}
2251e0e7fe07SMarc-André LureauG_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
22529bda600bSEric Blakeint main(void) { return 0; }
22539bda600bSEric BlakeEOF
22549bda600bSEric Blakeif ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
22559bda600bSEric Blake    if cc_has_warning_flag "-Wno-unused-function"; then
22569bda600bSEric Blake        glib_cflags="$glib_cflags -Wno-unused-function"
22575770e8afSPaolo Bonzini        CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
22589bda600bSEric Blake    fi
22599bda600bSEric Blakefi
22609bda600bSEric Blake
2261e26110cfSFam Zheng##########################################
2262e26110cfSFam Zheng# SHA command probe for modules
2263e26110cfSFam Zhengif test "$modules" = yes; then
2264e26110cfSFam Zheng    shacmd_probe="sha1sum sha1 shasum"
2265e26110cfSFam Zheng    for c in $shacmd_probe; do
22668ccefb91SFam Zheng        if has $c; then
2267e26110cfSFam Zheng            shacmd="$c"
2268e26110cfSFam Zheng            break
2269e26110cfSFam Zheng        fi
2270e26110cfSFam Zheng    done
2271e26110cfSFam Zheng    if test "$shacmd" = ""; then
2272e26110cfSFam Zheng        error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
2273e26110cfSFam Zheng    fi
2274e18df141SAnthony Liguorifi
2275e18df141SAnthony Liguori
2276e18df141SAnthony Liguori##########################################
2277f652e6afSaurel32# fdt probe
2278e169e1e1SPeter Maydell
2279fbb4121dSPaolo Bonzinicase "$fdt" in
2280fbb4121dSPaolo Bonzini  auto | enabled | internal)
2281fbb4121dSPaolo Bonzini    # Simpler to always update submodule, even if not needed.
2282aef45d51SDaniel P. Berrange    git_submodules="${git_submodules} dtc"
2283fbb4121dSPaolo Bonzini    ;;
2284fbb4121dSPaolo Bonziniesac
2285f652e6afSaurel32
228620ff075bSMichael Walle##########################################
22879d49bcf6SMarkus Armbruster# opengl probe (for sdl2, gtk)
2288b1546f32SGerd Hoffmann
2289da076ffeSGerd Hoffmannif test "$opengl" != "no" ; then
2290bc6a3565SAkihiko Odaki  epoxy=no
2291bc6a3565SAkihiko Odaki  if $pkg_config epoxy; then
2292bc6a3565SAkihiko Odaki    cat > $TMPC << EOF
2293bc6a3565SAkihiko Odaki#include <epoxy/egl.h>
2294bc6a3565SAkihiko Odakiint main(void) { return 0; }
2295bc6a3565SAkihiko OdakiEOF
2296bc6a3565SAkihiko Odaki    if compile_prog "" "" ; then
2297bc6a3565SAkihiko Odaki      epoxy=yes
2298bc6a3565SAkihiko Odaki    fi
2299bc6a3565SAkihiko Odaki  fi
2300bc6a3565SAkihiko Odaki
2301bc6a3565SAkihiko Odaki  if test "$epoxy" = "yes" ; then
2302bc6a3565SAkihiko Odaki    opengl_cflags="$($pkg_config --cflags epoxy)"
2303bc6a3565SAkihiko Odaki    opengl_libs="$($pkg_config --libs epoxy)"
2304da076ffeSGerd Hoffmann    opengl=yes
230520ff075bSMichael Walle  else
2306da076ffeSGerd Hoffmann    if test "$opengl" = "yes" ; then
2307bc6a3565SAkihiko Odaki      feature_not_found "opengl" "Please install epoxy with EGL"
230820ff075bSMichael Walle    fi
2309f676c67eSJeremy White    opengl_cflags=""
2310da076ffeSGerd Hoffmann    opengl_libs=""
2311da076ffeSGerd Hoffmann    opengl=no
231220ff075bSMichael Walle  fi
231320ff075bSMichael Wallefi
231420ff075bSMichael Walle
2315955727d2SCortland Tölva# check for usbfs
2316955727d2SCortland Tölvahave_usbfs=no
2317955727d2SCortland Tölvaif test "$linux_user" = "yes"; then
231896566d09SThomas Petazzoni  cat > $TMPC << EOF
231996566d09SThomas Petazzoni#include <linux/usbdevice_fs.h>
232096566d09SThomas Petazzoni
232196566d09SThomas Petazzoni#ifndef USBDEVFS_GET_CAPABILITIES
232296566d09SThomas Petazzoni#error "USBDEVFS_GET_CAPABILITIES undefined"
232396566d09SThomas Petazzoni#endif
232496566d09SThomas Petazzoni
232596566d09SThomas Petazzoni#ifndef USBDEVFS_DISCONNECT_CLAIM
232696566d09SThomas Petazzoni#error "USBDEVFS_DISCONNECT_CLAIM undefined"
232796566d09SThomas Petazzoni#endif
232896566d09SThomas Petazzoni
232996566d09SThomas Petazzoniint main(void)
233096566d09SThomas Petazzoni{
233196566d09SThomas Petazzoni    return 0;
233296566d09SThomas Petazzoni}
233396566d09SThomas PetazzoniEOF
233496566d09SThomas Petazzoni  if compile_prog "" ""; then
2335955727d2SCortland Tölva    have_usbfs=yes
2336955727d2SCortland Tölva  fi
2337955727d2SCortland Tölvafi
2338751bcc39SMarc-André Lureau
2339de5071c5SBlue Swirl##########################################
23408ca80760SRichard Henderson# capstone
23418ca80760SRichard Henderson
2342e219c499SRichard Hendersoncase "$capstone" in
23438b18cdbfSRichard Henderson  auto | enabled | internal)
23448b18cdbfSRichard Henderson    # Simpler to always update submodule, even if not needed.
2345e219c499SRichard Henderson    git_submodules="${git_submodules} capstone"
2346e219c499SRichard Henderson    ;;
2347e219c499SRichard Hendersonesac
23488ca80760SRichard Henderson
23498ca80760SRichard Henderson##########################################
2350519175a2SAlex Barcelo# check and set a backend for coroutine
2351d0e2fce5SAneesh Kumar K.V
23527c2acc70SPeter Maydell# We prefer ucontext, but it's not always possible. The fallback
235333c53c54SDaniel P. Berrange# is sigcontext. On Windows the only valid backend is the Windows
235433c53c54SDaniel P. Berrange# specific one.
23557c2acc70SPeter Maydell
23567c2acc70SPeter Maydellucontext_works=no
2357d0e2fce5SAneesh Kumar K.Vif test "$darwin" != "yes"; then
2358d0e2fce5SAneesh Kumar K.V  cat > $TMPC << EOF
2359d0e2fce5SAneesh Kumar K.V#include <ucontext.h>
2360cdf84806SPeter Maydell#ifdef __stub_makecontext
2361cdf84806SPeter Maydell#error Ignoring glibc stub makecontext which will always fail
2362cdf84806SPeter Maydell#endif
236375cafad7SStefan Weilint main(void) { makecontext(0, 0, 0); return 0; }
2364d0e2fce5SAneesh Kumar K.VEOF
2365d0e2fce5SAneesh Kumar K.V  if compile_prog "" "" ; then
23667c2acc70SPeter Maydell    ucontext_works=yes
2367d0e2fce5SAneesh Kumar K.V  fi
2368519175a2SAlex Barcelofi
23697c2acc70SPeter Maydell
23707c2acc70SPeter Maydellif test "$coroutine" = ""; then
23717c2acc70SPeter Maydell  if test "$mingw32" = "yes"; then
23727c2acc70SPeter Maydell    coroutine=win32
23737c2acc70SPeter Maydell  elif test "$ucontext_works" = "yes"; then
23747c2acc70SPeter Maydell    coroutine=ucontext
2375519175a2SAlex Barcelo  else
23767c2acc70SPeter Maydell    coroutine=sigaltstack
23777c2acc70SPeter Maydell  fi
23787c2acc70SPeter Maydellelse
23797c2acc70SPeter Maydell  case $coroutine in
23807c2acc70SPeter Maydell  windows)
23817c2acc70SPeter Maydell    if test "$mingw32" != "yes"; then
23827c2acc70SPeter Maydell      error_exit "'windows' coroutine backend only valid for Windows"
23837c2acc70SPeter Maydell    fi
23847c2acc70SPeter Maydell    # Unfortunately the user visible backend name doesn't match the
23857c2acc70SPeter Maydell    # coroutine-*.c filename for this case, so we have to adjust it here.
23867c2acc70SPeter Maydell    coroutine=win32
23877c2acc70SPeter Maydell    ;;
23887c2acc70SPeter Maydell  ucontext)
23897c2acc70SPeter Maydell    if test "$ucontext_works" != "yes"; then
23907c2acc70SPeter Maydell      feature_not_found "ucontext"
23917c2acc70SPeter Maydell    fi
23927c2acc70SPeter Maydell    ;;
239333c53c54SDaniel P. Berrange  sigaltstack)
23947c2acc70SPeter Maydell    if test "$mingw32" = "yes"; then
23957c2acc70SPeter Maydell      error_exit "only the 'windows' coroutine backend is valid for Windows"
23967c2acc70SPeter Maydell    fi
23977c2acc70SPeter Maydell    ;;
23987c2acc70SPeter Maydell  *)
239976ad07a4SPeter Maydell    error_exit "unknown coroutine backend $coroutine"
24007c2acc70SPeter Maydell    ;;
24017c2acc70SPeter Maydell  esac
2402d0e2fce5SAneesh Kumar K.Vfi
2403d0e2fce5SAneesh Kumar K.V
24041e4f6065SDaniele Buono##################################################
24051e4f6065SDaniele Buono# SafeStack
24061e4f6065SDaniele Buono
24071e4f6065SDaniele Buono
24081e4f6065SDaniele Buonoif test "$safe_stack" = "yes"; then
24091e4f6065SDaniele Buonocat > $TMPC << EOF
24101e4f6065SDaniele Buonoint main(int argc, char *argv[])
24111e4f6065SDaniele Buono{
24121e4f6065SDaniele Buono#if ! __has_feature(safe_stack)
24131e4f6065SDaniele Buono#error SafeStack Disabled
24141e4f6065SDaniele Buono#endif
24151e4f6065SDaniele Buono    return 0;
24161e4f6065SDaniele Buono}
24171e4f6065SDaniele BuonoEOF
24181e4f6065SDaniele Buono  flag="-fsanitize=safe-stack"
24191e4f6065SDaniele Buono  # Check that safe-stack is supported and enabled.
24201e4f6065SDaniele Buono  if compile_prog "-Werror $flag" "$flag"; then
24211e4f6065SDaniele Buono    # Flag needed both at compilation and at linking
24221e4f6065SDaniele Buono    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
24231e4f6065SDaniele Buono    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
24241e4f6065SDaniele Buono  else
24251e4f6065SDaniele Buono    error_exit "SafeStack not supported by your compiler"
24261e4f6065SDaniele Buono  fi
24271e4f6065SDaniele Buono  if test "$coroutine" != "ucontext"; then
24281e4f6065SDaniele Buono    error_exit "SafeStack is only supported by the coroutine backend ucontext"
24291e4f6065SDaniele Buono  fi
24301e4f6065SDaniele Buonoelse
24311e4f6065SDaniele Buonocat > $TMPC << EOF
24321e4f6065SDaniele Buonoint main(int argc, char *argv[])
24331e4f6065SDaniele Buono{
24341e4f6065SDaniele Buono#if defined(__has_feature)
24351e4f6065SDaniele Buono#if __has_feature(safe_stack)
24361e4f6065SDaniele Buono#error SafeStack Enabled
24371e4f6065SDaniele Buono#endif
24381e4f6065SDaniele Buono#endif
24391e4f6065SDaniele Buono    return 0;
24401e4f6065SDaniele Buono}
24411e4f6065SDaniele BuonoEOF
24421e4f6065SDaniele Buonoif test "$safe_stack" = "no"; then
24431e4f6065SDaniele Buono  # Make sure that safe-stack is disabled
24441e4f6065SDaniele Buono  if ! compile_prog "-Werror" ""; then
24451e4f6065SDaniele Buono    # SafeStack was already enabled, try to explicitly remove the feature
24461e4f6065SDaniele Buono    flag="-fno-sanitize=safe-stack"
24471e4f6065SDaniele Buono    if ! compile_prog "-Werror $flag" "$flag"; then
24481e4f6065SDaniele Buono      error_exit "Configure cannot disable SafeStack"
24491e4f6065SDaniele Buono    fi
24501e4f6065SDaniele Buono    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
24511e4f6065SDaniele Buono    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
24521e4f6065SDaniele Buono  fi
24531e4f6065SDaniele Buonoelse # "$safe_stack" = ""
24541e4f6065SDaniele Buono  # Set safe_stack to yes or no based on pre-existing flags
24551e4f6065SDaniele Buono  if compile_prog "-Werror" ""; then
24561e4f6065SDaniele Buono    safe_stack="no"
24571e4f6065SDaniele Buono  else
24581e4f6065SDaniele Buono    safe_stack="yes"
24591e4f6065SDaniele Buono    if test "$coroutine" != "ucontext"; then
24601e4f6065SDaniele Buono      error_exit "SafeStack is only supported by the coroutine backend ucontext"
24611e4f6065SDaniele Buono    fi
24621e4f6065SDaniele Buono  fi
24631e4f6065SDaniele Buonofi
24641e4f6065SDaniele Buonofi
24657d992e4dSPeter Lieven
246676a347e1SRichard Henderson########################################
2467fd0e6053SJohn Snow# check if ccache is interfering with
2468fd0e6053SJohn Snow# semantic analysis of macros
2469fd0e6053SJohn Snow
24705e4dfd3dSJohn Snowunset CCACHE_CPP2
2471fd0e6053SJohn Snowccache_cpp2=no
2472fd0e6053SJohn Snowcat > $TMPC << EOF
2473fd0e6053SJohn Snowstatic const int Z = 1;
2474fd0e6053SJohn Snow#define fn() ({ Z; })
2475fd0e6053SJohn Snow#define TAUT(X) ((X) == Z)
2476fd0e6053SJohn Snow#define PAREN(X, Y) (X == Y)
2477fd0e6053SJohn Snow#define ID(X) (X)
2478fd0e6053SJohn Snowint main(int argc, char *argv[])
2479fd0e6053SJohn Snow{
2480fd0e6053SJohn Snow    int x = 0, y = 0;
2481fd0e6053SJohn Snow    x = ID(x);
2482fd0e6053SJohn Snow    x = fn();
2483fd0e6053SJohn Snow    fn();
2484fd0e6053SJohn Snow    if (PAREN(x, y)) return 0;
2485fd0e6053SJohn Snow    if (TAUT(Z)) return 0;
2486fd0e6053SJohn Snow    return 0;
2487fd0e6053SJohn Snow}
2488fd0e6053SJohn SnowEOF
2489fd0e6053SJohn Snow
2490fd0e6053SJohn Snowif ! compile_object "-Werror"; then
2491fd0e6053SJohn Snow    ccache_cpp2=yes
2492fd0e6053SJohn Snowfi
2493fd0e6053SJohn Snow
2494b553a042SJohn Snow#################################################
2495b553a042SJohn Snow# clang does not support glibc + FORTIFY_SOURCE.
2496b553a042SJohn Snow
2497b553a042SJohn Snowif test "$fortify_source" != "no"; then
2498b553a042SJohn Snow  if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
2499b553a042SJohn Snow    fortify_source="no";
2500e189091fSPeter Maydell  elif test -n "$cxx" && has $cxx &&
2501cfcc7c14SJohn Snow       echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
2502b553a042SJohn Snow    fortify_source="no";
2503b553a042SJohn Snow  else
2504b553a042SJohn Snow    fortify_source="yes"
2505b553a042SJohn Snow  fi
2506b553a042SJohn Snowfi
2507b553a042SJohn Snow
2508d2042378SAneesh Kumar K.V##########################################
2509247724cbSMarc-André Lureau# checks for sanitizers
2510247724cbSMarc-André Lureau
2511247724cbSMarc-André Lureauhave_asan=no
2512247724cbSMarc-André Lureauhave_ubsan=no
2513d83414e1SMarc-André Lureauhave_asan_iface_h=no
2514d83414e1SMarc-André Lureauhave_asan_iface_fiber=no
2515247724cbSMarc-André Lureau
2516247724cbSMarc-André Lureauif test "$sanitizers" = "yes" ; then
2517b9f44da2SMarc-André Lureau  write_c_skeleton
2518247724cbSMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
2519247724cbSMarc-André Lureau      have_asan=yes
2520247724cbSMarc-André Lureau  fi
2521b9f44da2SMarc-André Lureau
2522b9f44da2SMarc-André Lureau  # we could use a simple skeleton for flags checks, but this also
2523b9f44da2SMarc-André Lureau  # detect the static linking issue of ubsan, see also:
2524b9f44da2SMarc-André Lureau  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
2525b9f44da2SMarc-André Lureau  cat > $TMPC << EOF
2526b9f44da2SMarc-André Lureau#include <stdlib.h>
2527b9f44da2SMarc-André Lureauint main(void) {
2528b9f44da2SMarc-André Lureau    void *tmp = malloc(10);
2529f2dfe54cSLeonid Bloch    if (tmp != NULL) {
2530b9f44da2SMarc-André Lureau        return *(int *)(tmp + 2);
2531b9f44da2SMarc-André Lureau    }
2532d1abf3fcSOlaf Hering    return 1;
2533f2dfe54cSLeonid Bloch}
2534b9f44da2SMarc-André LureauEOF
2535247724cbSMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
2536247724cbSMarc-André Lureau      have_ubsan=yes
2537247724cbSMarc-André Lureau  fi
2538d83414e1SMarc-André Lureau
2539d83414e1SMarc-André Lureau  if check_include "sanitizer/asan_interface.h" ; then
2540d83414e1SMarc-André Lureau      have_asan_iface_h=yes
2541d83414e1SMarc-André Lureau  fi
2542d83414e1SMarc-André Lureau
2543d83414e1SMarc-André Lureau  cat > $TMPC << EOF
2544d83414e1SMarc-André Lureau#include <sanitizer/asan_interface.h>
2545d83414e1SMarc-André Lureauint main(void) {
2546d83414e1SMarc-André Lureau  __sanitizer_start_switch_fiber(0, 0, 0);
2547d83414e1SMarc-André Lureau  return 0;
2548d83414e1SMarc-André Lureau}
2549d83414e1SMarc-André LureauEOF
2550d83414e1SMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
2551d83414e1SMarc-André Lureau      have_asan_iface_fiber=yes
2552d83414e1SMarc-André Lureau  fi
2553247724cbSMarc-André Lureaufi
2554247724cbSMarc-André Lureau
25550aebab04SLingfeng Yang# Thread sanitizer is, for now, much noisier than the other sanitizers;
25560aebab04SLingfeng Yang# keep it separate until that is not the case.
25570aebab04SLingfeng Yangif test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
25580aebab04SLingfeng Yang  error_exit "TSAN is not supported with other sanitiziers."
25590aebab04SLingfeng Yangfi
25600aebab04SLingfeng Yanghave_tsan=no
25610aebab04SLingfeng Yanghave_tsan_iface_fiber=no
25620aebab04SLingfeng Yangif test "$tsan" = "yes" ; then
25630aebab04SLingfeng Yang  write_c_skeleton
25640aebab04SLingfeng Yang  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
25650aebab04SLingfeng Yang      have_tsan=yes
25660aebab04SLingfeng Yang  fi
25670aebab04SLingfeng Yang  cat > $TMPC << EOF
25680aebab04SLingfeng Yang#include <sanitizer/tsan_interface.h>
25690aebab04SLingfeng Yangint main(void) {
25700aebab04SLingfeng Yang  __tsan_create_fiber(0);
25710aebab04SLingfeng Yang  return 0;
25720aebab04SLingfeng Yang}
25730aebab04SLingfeng YangEOF
25740aebab04SLingfeng Yang  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
25750aebab04SLingfeng Yang      have_tsan_iface_fiber=yes
25760aebab04SLingfeng Yang  fi
25770aebab04SLingfeng Yangfi
25780aebab04SLingfeng Yang
2579adc28027SAlexander Bulekov##########################################
2580675b9b53SMarc-André Lureau# check for slirp
2581675b9b53SMarc-André Lureau
2582675b9b53SMarc-André Lureaucase "$slirp" in
25834d34a86bSPaolo Bonzini  auto | enabled | internal)
25844d34a86bSPaolo Bonzini    # Simpler to always update submodule, even if not needed.
25857c57bdd8SMarc-André Lureau    git_submodules="${git_submodules} slirp"
2586675b9b53SMarc-André Lureau    ;;
2587675b9b53SMarc-André Lureauesac
2588675b9b53SMarc-André Lureau
258954e7aac0SAlexey Krasikov##########################################
259054e7aac0SAlexey Krasikov# check for usable __NR_keyctl syscall
259154e7aac0SAlexey Krasikov
259254e7aac0SAlexey Krasikovif test "$linux" = "yes" ; then
259354e7aac0SAlexey Krasikov
259454e7aac0SAlexey Krasikov    have_keyring=no
259554e7aac0SAlexey Krasikov    cat > $TMPC << EOF
259654e7aac0SAlexey Krasikov#include <errno.h>
259754e7aac0SAlexey Krasikov#include <asm/unistd.h>
259854e7aac0SAlexey Krasikov#include <linux/keyctl.h>
259954e7aac0SAlexey Krasikov#include <unistd.h>
260054e7aac0SAlexey Krasikovint main(void) {
260154e7aac0SAlexey Krasikov    return syscall(__NR_keyctl, KEYCTL_READ, 0, NULL, NULL, 0);
260254e7aac0SAlexey Krasikov}
260354e7aac0SAlexey KrasikovEOF
260454e7aac0SAlexey Krasikov    if compile_prog "" "" ; then
260554e7aac0SAlexey Krasikov        have_keyring=yes
260654e7aac0SAlexey Krasikov    fi
260754e7aac0SAlexey Krasikovfi
260854e7aac0SAlexey Krasikovif test "$secret_keyring" != "no"
260954e7aac0SAlexey Krasikovthen
2610b418d265SDavid Edmondson    if test "$have_keyring" = "yes"
261154e7aac0SAlexey Krasikov    then
261254e7aac0SAlexey Krasikov	secret_keyring=yes
261354e7aac0SAlexey Krasikov    else
261454e7aac0SAlexey Krasikov	if test "$secret_keyring" = "yes"
261554e7aac0SAlexey Krasikov	then
261654e7aac0SAlexey Krasikov	    error_exit "syscall __NR_keyctl requested, \
261754e7aac0SAlexey Krasikovbut not implemented on your system"
261854e7aac0SAlexey Krasikov	else
261954e7aac0SAlexey Krasikov	    secret_keyring=no
262054e7aac0SAlexey Krasikov	fi
262154e7aac0SAlexey Krasikov    fi
262254e7aac0SAlexey Krasikovfi
262354e7aac0SAlexey Krasikov
262492500362SAlexey Krasikov##########################################
2625e86ecd4bSJuan Quintela# End of CC checks
2626e86ecd4bSJuan Quintela# After here, no more $cc or $ld runs
2627e86ecd4bSJuan Quintela
2628d83414e1SMarc-André Lureauwrite_c_skeleton
2629d83414e1SMarc-André Lureau
26301d728c39SBlue Swirlif test "$gcov" = "yes" ; then
2631bf0e56a3SMarc-André Lureau  :
2632b553a042SJohn Snowelif test "$fortify_source" = "yes" ; then
2633086d5f75SPaolo Bonzini  QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
2634086d5f75SPaolo Bonzini  debug=no
2635086d5f75SPaolo Bonzinifi
2636086d5f75SPaolo Bonzini
2637086d5f75SPaolo Bonzinicase "$ARCH" in
2638086d5f75SPaolo Bonzinialpha)
2639086d5f75SPaolo Bonzini  # Ensure there's only a single GP
2640086d5f75SPaolo Bonzini  QEMU_CFLAGS="-msmall-data $QEMU_CFLAGS"
2641086d5f75SPaolo Bonzini;;
2642086d5f75SPaolo Bonziniesac
2643086d5f75SPaolo Bonzini
2644247724cbSMarc-André Lureauif test "$have_asan" = "yes"; then
2645db5adeaaSPaolo Bonzini  QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
2646db5adeaaSPaolo Bonzini  QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
2647d83414e1SMarc-André Lureau  if test "$have_asan_iface_h" = "no" ; then
2648d83414e1SMarc-André Lureau      echo "ASAN build enabled, but ASAN header missing." \
2649d83414e1SMarc-André Lureau           "Without code annotation, the report may be inferior."
2650d83414e1SMarc-André Lureau  elif test "$have_asan_iface_fiber" = "no" ; then
2651d83414e1SMarc-André Lureau      echo "ASAN build enabled, but ASAN header is too old." \
2652d83414e1SMarc-André Lureau           "Without code annotation, the report may be inferior."
2653d83414e1SMarc-André Lureau  fi
2654247724cbSMarc-André Lureaufi
26550aebab04SLingfeng Yangif test "$have_tsan" = "yes" ; then
26560aebab04SLingfeng Yang  if test "$have_tsan_iface_fiber" = "yes" ; then
26570aebab04SLingfeng Yang    QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
26580aebab04SLingfeng Yang    QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
26590aebab04SLingfeng Yang  else
26600aebab04SLingfeng Yang    error_exit "Cannot enable TSAN due to missing fiber annotation interface."
26610aebab04SLingfeng Yang  fi
26620aebab04SLingfeng Yangelif test "$tsan" = "yes" ; then
26630aebab04SLingfeng Yang  error_exit "Cannot enable TSAN due to missing sanitize thread interface."
26640aebab04SLingfeng Yangfi
2665247724cbSMarc-André Lureauif test "$have_ubsan" = "yes"; then
2666db5adeaaSPaolo Bonzini  QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
2667db5adeaaSPaolo Bonzini  QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
2668247724cbSMarc-André Lureaufi
2669247724cbSMarc-André Lureau
26706542aa9cSPeter Lieven##########################################
26713efac6ebSTomáš Golembiovský
26720aebab04SLingfeng Yang# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
26730aebab04SLingfeng Yangif test "$solaris" = "no" && test "$tsan" = "no"; then
2674e86ecd4bSJuan Quintela    if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
2675db5adeaaSPaolo Bonzini        QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
2676e86ecd4bSJuan Quintela    fi
2677e86ecd4bSJuan Quintelafi
2678e86ecd4bSJuan Quintela
2679952afb71SBlue Swirl# Use ASLR, no-SEH and DEP if available
2680952afb71SBlue Swirlif test "$mingw32" = "yes" ; then
2681cb8baa77SMark Cave-Ayland    flags="--no-seh --nxcompat"
2682cb8baa77SMark Cave-Ayland
2683cb8baa77SMark Cave-Ayland    # Disable ASLR for debug builds to allow debugging with gdb
2684cb8baa77SMark Cave-Ayland    if test "$debug" = "no" ; then
2685cb8baa77SMark Cave-Ayland        flags="--dynamicbase $flags"
2686cb8baa77SMark Cave-Ayland    fi
2687cb8baa77SMark Cave-Ayland
2688cb8baa77SMark Cave-Ayland    for flag in $flags; do
2689e9a3591fSChristian Borntraeger        if ld_has $flag ; then
2690db5adeaaSPaolo Bonzini            QEMU_LDFLAGS="-Wl,$flag $QEMU_LDFLAGS"
2691952afb71SBlue Swirl        fi
2692952afb71SBlue Swirl    done
2693952afb71SBlue Swirlfi
2694952afb71SBlue Swirl
2695b846ab7cSPaolo Bonzini# Guest agent Windows MSI package
26969d6bc27bSMichael Roth
26979d6bc27bSMichael Rothif test "$QEMU_GA_MANUFACTURER" = ""; then
26989d6bc27bSMichael Roth  QEMU_GA_MANUFACTURER=QEMU
26999d6bc27bSMichael Rothfi
27009d6bc27bSMichael Rothif test "$QEMU_GA_DISTRO" = ""; then
27019d6bc27bSMichael Roth  QEMU_GA_DISTRO=Linux
27029d6bc27bSMichael Rothfi
27039d6bc27bSMichael Rothif test "$QEMU_GA_VERSION" = ""; then
270489138857SStefan Weil    QEMU_GA_VERSION=$(cat $source_path/VERSION)
27059d6bc27bSMichael Rothfi
27069d6bc27bSMichael Roth
2707b846ab7cSPaolo BonziniQEMU_GA_MSI_MINGW_DLL_PATH="$($pkg_config --variable=prefix glib-2.0)/bin"
27089d6bc27bSMichael Roth
2709ca35f780SPaolo Bonzini# Mac OS X ships with a broken assembler
2710ca35f780SPaolo Bonziniroms=
2711e633a5c6SEric Blakeif { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \
2712ba7c60c2SPaolo Bonzini        test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
2713ba7c60c2SPaolo Bonzini        test "$targetos" != "haiku" && test "$softmmu" = yes ; then
2714e57218b6SPeter Maydell    # Different host OS linkers have different ideas about the name of the ELF
2715c65d5e4eSBrad Smith    # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
2716c65d5e4eSBrad Smith    # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
2717c65d5e4eSBrad Smith    for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
2718e57218b6SPeter Maydell        if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
2719e57218b6SPeter Maydell            ld_i386_emulation="$emu"
2720ca35f780SPaolo Bonzini            roms="optionrom"
2721e57218b6SPeter Maydell            break
2722e57218b6SPeter Maydell        fi
2723e57218b6SPeter Maydell    done
2724ca35f780SPaolo Bonzinifi
2725ca35f780SPaolo Bonzini
27262e33c3f8SThomas Huth# Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
2727a5b2afd5SThomas Huth# or -march=z10 (which is the lowest architecture level that Clang supports)
27289933c305SChristian Borntraegerif test "$cpu" = "s390x" ; then
27292e33c3f8SThomas Huth  write_c_skeleton
2730a5b2afd5SThomas Huth  compile_prog "-march=z900" ""
2731a5b2afd5SThomas Huth  has_z900=$?
27323af448b3SThomas Huth  if [ $has_z900 = 0 ] || compile_object "-march=z10 -msoft-float -Werror"; then
2733a5b2afd5SThomas Huth    if [ $has_z900 != 0 ]; then
2734a5b2afd5SThomas Huth      echo "WARNING: Your compiler does not support the z900!"
2735a5b2afd5SThomas Huth      echo "         The s390-ccw bios will only work with guest CPUs >= z10."
2736a5b2afd5SThomas Huth    fi
27379933c305SChristian Borntraeger    roms="$roms s390-ccw"
27381ef6bfc2SPhilippe Mathieu-Daudé    # SLOF is required for building the s390-ccw firmware on s390x,
27391ef6bfc2SPhilippe Mathieu-Daudé    # since it is using the libnet code from SLOF for network booting.
27401ef6bfc2SPhilippe Mathieu-Daudé    git_submodules="${git_submodules} roms/SLOF"
27411ef6bfc2SPhilippe Mathieu-Daudé  fi
27429933c305SChristian Borntraegerfi
27439933c305SChristian Borntraeger
274411cde1c8SBruno Dominguez# Check that the C++ compiler exists and works with the C compiler.
274511cde1c8SBruno 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.
274611cde1c8SBruno Dominguezif has $cxx; then
274711cde1c8SBruno Dominguez    cat > $TMPC <<EOF
274811cde1c8SBruno Dominguezint c_function(void);
274911cde1c8SBruno Dominguezint main(void) { return c_function(); }
275011cde1c8SBruno DominguezEOF
275111cde1c8SBruno Dominguez
275211cde1c8SBruno Dominguez    compile_object
275311cde1c8SBruno Dominguez
275411cde1c8SBruno Dominguez    cat > $TMPCXX <<EOF
275511cde1c8SBruno Dominguezextern "C" {
275611cde1c8SBruno Dominguez   int c_function(void);
275711cde1c8SBruno Dominguez}
275811cde1c8SBruno Dominguezint c_function(void) { return 42; }
275911cde1c8SBruno DominguezEOF
276011cde1c8SBruno Dominguez
276111cde1c8SBruno Dominguez    update_cxxflags
276211cde1c8SBruno Dominguez
2763a2866660SPaolo Bonzini    if do_cxx $CXXFLAGS $EXTRA_CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
276411cde1c8SBruno Dominguez        # C++ compiler $cxx works ok with C compiler $cc
276511cde1c8SBruno Dominguez        :
276611cde1c8SBruno Dominguez    else
276711cde1c8SBruno Dominguez        echo "C++ compiler $cxx does not work with C compiler $cc"
276811cde1c8SBruno Dominguez        echo "Disabling C++ specific optional code"
276911cde1c8SBruno Dominguez        cxx=
277011cde1c8SBruno Dominguez    fi
277111cde1c8SBruno Dominguezelse
277211cde1c8SBruno Dominguez    echo "No C++ compiler available; disabling C++ specific optional code"
277311cde1c8SBruno Dominguez    cxx=
277411cde1c8SBruno Dominguezfi
277511cde1c8SBruno Dominguez
27767d7dbf9dSDan Streetmanif !(GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
27777d7dbf9dSDan Streetman    exit 1
27785d91a2edSYonggang Luofi
27795d91a2edSYonggang Luo
278098ec69acSJuan Quintelaconfig_host_mak="config-host.mak"
278197a847bcSbellard
278298ec69acSJuan Quintelaecho "# Automatically generated by configure - do not modify" > $config_host_mak
278398ec69acSJuan Quintelaecho >> $config_host_mak
278498ec69acSJuan Quintela
2785e6c3b0f7SPaolo Bonziniecho all: >> $config_host_mak
2786cc84d63aSDaniel P. Berrangeecho "GIT=$git" >> $config_host_mak
2787aef45d51SDaniel P. Berrangeecho "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
27887d7dbf9dSDan Streetmanecho "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
2789804edf29SJuan Quintela
2790f8393946Saurel32if test "$debug_tcg" = "yes" ; then
27912358a494SJuan Quintela  echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
2792f8393946Saurel32fi
279367b915a5Sbellardif test "$mingw32" = "yes" ; then
279498ec69acSJuan Quintela  echo "CONFIG_WIN32=y" >> $config_host_mak
27959dacf32dSYossi Hindin  echo "QEMU_GA_MSI_MINGW_DLL_PATH=${QEMU_GA_MSI_MINGW_DLL_PATH}" >> $config_host_mak
27969dacf32dSYossi Hindin  echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
27979dacf32dSYossi Hindin  echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
27989dacf32dSYossi Hindin  echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
2799210fa556Spbrookelse
280035f4df27SJuan Quintela  echo "CONFIG_POSIX=y" >> $config_host_mak
2801210fa556Spbrookfi
2802128ab2ffSblueswir1
2803dffcb71cSMark McLoughlinif test "$linux" = "yes" ; then
2804dffcb71cSMark McLoughlin  echo "CONFIG_LINUX=y" >> $config_host_mak
2805dffcb71cSMark McLoughlinfi
2806dffcb71cSMark McLoughlin
280783fb7adfSbellardif test "$darwin" = "yes" ; then
280898ec69acSJuan Quintela  echo "CONFIG_DARWIN=y" >> $config_host_mak
280983fb7adfSbellardfi
2810b29fe3edSmalc
2811ec530c81Sbellardif test "$solaris" = "yes" ; then
281298ec69acSJuan Quintela  echo "CONFIG_SOLARIS=y" >> $config_host_mak
2813ec530c81Sbellardfi
281497a847bcSbellardif test "$static" = "yes" ; then
281598ec69acSJuan Quintela  echo "CONFIG_STATIC=y" >> $config_host_mak
281697a847bcSbellardfi
2817b64ec4e4SFam Zhengecho "CONFIG_BDRV_RW_WHITELIST=$block_drv_rw_whitelist" >> $config_host_mak
2818b64ec4e4SFam Zhengecho "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
281989138857SStefan Weilqemu_version=$(head $source_path/VERSION)
28202358a494SJuan Quintelaecho "PKGVERSION=$pkgversion" >>$config_host_mak
282198ec69acSJuan Quintelaecho "SRC_PATH=$source_path" >> $config_host_mak
28222b1f35b9SAlex Bennéeecho "TARGET_DIRS=$target_list" >> $config_host_mak
282317969268SFam Zhengif test "$modules" = "yes"; then
2824e26110cfSFam Zheng  # $shacmd can generate a hash started with digit, which the compiler doesn't
2825e26110cfSFam Zheng  # like as an symbol. So prefix it with an underscore
282689138857SStefan Weil  echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
282717969268SFam Zheng  echo "CONFIG_MODULES=y" >> $config_host_mak
282817969268SFam Zhengfi
2829bd83c861SChristian Ehrhardtif test "$module_upgrades" = "yes"; then
2830bd83c861SChristian Ehrhardt  echo "CONFIG_MODULE_UPGRADES=y" >> $config_host_mak
2831bd83c861SChristian Ehrhardtfi
2832955727d2SCortland Tölvaif test "$have_usbfs" = "yes" ; then
2833955727d2SCortland Tölva  echo "CONFIG_USBFS=y" >> $config_host_mak
2834955727d2SCortland Tölvafi
2835f876b765SMarc-André Lureauif test "$gio" = "yes" ; then
2836f876b765SMarc-André Lureau    echo "CONFIG_GIO=y" >> $config_host_mak
2837f876b765SMarc-André Lureau    echo "GIO_CFLAGS=$gio_cflags" >> $config_host_mak
2838f876b765SMarc-André Lureau    echo "GIO_LIBS=$gio_libs" >> $config_host_mak
28395ecfb76cSPaolo Bonzinifi
28405ecfb76cSPaolo Bonziniif test "$gdbus_codegen" != "" ; then
284125a97a56SMarc-André Lureau    echo "GDBUS_CODEGEN=$gdbus_codegen" >> $config_host_mak
2842f876b765SMarc-André Lureaufi
2843a1c5e949SDaniel P. Berrangeecho "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak
2844277abf15SJan Vesely
28451badb709SPaolo Bonziniif test "$xen" = "enabled" ; then
28466dbd588aSJan Kiszka  echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
2847d5b93ddfSAnthony PERARD  echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
2848582ea95fSMarc-André Lureau  echo "XEN_CFLAGS=$xen_cflags" >> $config_host_mak
2849582ea95fSMarc-André Lureau  echo "XEN_LIBS=$xen_libs" >> $config_host_mak
2850e37630caSaliguorifi
28515e9be92dSNicholas Bellingerif test "$vhost_scsi" = "yes" ; then
28525e9be92dSNicholas Bellinger  echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
28535e9be92dSNicholas Bellingerfi
2854af3bba76SPaolo Bonziniif test "$vhost_net" = "yes" ; then
2855af3bba76SPaolo Bonzini  echo "CONFIG_VHOST_NET=y" >> $config_host_mak
2856af3bba76SPaolo Bonzinifi
2857af3bba76SPaolo Bonziniif test "$vhost_net_user" = "yes" ; then
285856f41de7SPaolo Bonzini  echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak
285903ce5744SNikolay Nikolaevfi
2860108a6481SCindy Luif test "$vhost_net_vdpa" = "yes" ; then
2861108a6481SCindy Lu  echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak
2862108a6481SCindy Lufi
2863042cea27SGongleiif test "$vhost_crypto" = "yes" ; then
2864042cea27SGonglei  echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
2865042cea27SGongleifi
2866fc0b9b0eSStefan Hajnocziif test "$vhost_vsock" = "yes" ; then
2867fc0b9b0eSStefan Hajnoczi  echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
28685fe97d88SStefano Garzarella  if test "$vhost_user" = "yes" ; then
28695fe97d88SStefano Garzarella    echo "CONFIG_VHOST_USER_VSOCK=y" >> $config_host_mak
28705fe97d88SStefano Garzarella  fi
2871fc0b9b0eSStefan Hajnoczifi
2872299e6f19SPaolo Bonziniif test "$vhost_kernel" = "yes" ; then
2873299e6f19SPaolo Bonzini  echo "CONFIG_VHOST_KERNEL=y" >> $config_host_mak
2874299e6f19SPaolo Bonzinifi
2875e6a74868SMarc-André Lureauif test "$vhost_user" = "yes" ; then
2876e6a74868SMarc-André Lureau  echo "CONFIG_VHOST_USER=y" >> $config_host_mak
2877e6a74868SMarc-André Lureaufi
2878108a6481SCindy Luif test "$vhost_vdpa" = "yes" ; then
2879108a6481SCindy Lu  echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
2880108a6481SCindy Lufi
288198fc1adaSDr. David Alan Gilbertif test "$vhost_user_fs" = "yes" ; then
288298fc1adaSDr. David Alan Gilbert  echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak
288398fc1adaSDr. David Alan Gilbertfi
2884e5b46549SRichard Hendersonif test "$tcg" = "enabled" -a "$tcg_interpreter" = "true" ; then
2885e5b46549SRichard Henderson  echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
2886e5b46549SRichard Hendersonfi
288758d3f3ffSGerd Hoffmann
2888da076ffeSGerd Hoffmannif test "$opengl" = "yes" ; then
2889da076ffeSGerd Hoffmann  echo "CONFIG_OPENGL=y" >> $config_host_mak
2890de2d3005SPaolo Bonzini  echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
2891da076ffeSGerd Hoffmann  echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
289220ff075bSMichael Wallefi
289320ff075bSMichael Walle
289483fb7adfSbellard# XXX: suppress that
28957d3505c5Sbellardif [ "$bsd" = "yes" ] ; then
28962358a494SJuan Quintela  echo "CONFIG_BSD=y" >> $config_host_mak
28977d3505c5Sbellardfi
28987d3505c5Sbellard
28997c2acc70SPeter Maydellecho "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
29007d992e4dSPeter Lieven
2901d83414e1SMarc-André Lureauif test "$have_asan_iface_fiber" = "yes" ; then
2902d83414e1SMarc-André Lureau    echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
2903d83414e1SMarc-André Lureaufi
2904d83414e1SMarc-André Lureau
29050aebab04SLingfeng Yangif test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
29060aebab04SLingfeng Yang    echo "CONFIG_TSAN=y" >> $config_host_mak
29070aebab04SLingfeng Yangfi
29080aebab04SLingfeng Yang
29092da776dbSMichael R. Hinesif test "$rdma" = "yes" ; then
29102da776dbSMichael R. Hines  echo "CONFIG_RDMA=y" >> $config_host_mak
2911392fb643SFam Zheng  echo "RDMA_LIBS=$rdma_libs" >> $config_host_mak
29122da776dbSMichael R. Hinesfi
29132da776dbSMichael R. Hines
291421ab34c9SMarcel Apfelbaumif test "$pvrdma" = "yes" ; then
291521ab34c9SMarcel Apfelbaum  echo "CONFIG_PVRDMA=y" >> $config_host_mak
291621ab34c9SMarcel Apfelbaumfi
291721ab34c9SMarcel Apfelbaum
291840e8c6f4SAlex Bennéeif test "$plugins" = "yes" ; then
291940e8c6f4SAlex Bennée    echo "CONFIG_PLUGIN=y" >> $config_host_mak
292040e8c6f4SAlex Bennéefi
292140e8c6f4SAlex Bennée
2922f48e590aSAlex Bennéeif test -n "$gdb_bin"; then
2923b1863cccSAlex Bennée    gdb_version=$($gdb_bin --version | head -n 1)
2924d6a66c81SAlex Bennée    if version_ge ${gdb_version##* } 9.1; then
2925f48e590aSAlex Bennée        echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
2926f48e590aSAlex Bennée    fi
2927b1863cccSAlex Bennéefi
2928f48e590aSAlex Bennée
292954e7aac0SAlexey Krasikovif test "$secret_keyring" = "yes" ; then
293054e7aac0SAlexey Krasikov  echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak
293154e7aac0SAlexey Krasikovfi
293254e7aac0SAlexey Krasikov
293398ec69acSJuan Quintelaecho "ROMS=$roms" >> $config_host_mak
2934804edf29SJuan Quintelaecho "MAKE=$make" >> $config_host_mak
2935c886edfbSBlue Swirlecho "PYTHON=$python" >> $config_host_mak
293639d87c8cSAlex Bennéeecho "GENISOIMAGE=$genisoimage" >> $config_host_mak
2937a5665051SPaolo Bonziniecho "MESON=$meson" >> $config_host_mak
293809e93326SPaolo Bonziniecho "NINJA=$ninja" >> $config_host_mak
2939804edf29SJuan Quintelaecho "CC=$cc" >> $config_host_mak
2940804edf29SJuan Quintelaecho "AR=$ar" >> $config_host_mak
2941cdbd727cSRichard Hendersonecho "AS=$as" >> $config_host_mak
29425f6f0e27SRichard Hendersonecho "CCAS=$ccas" >> $config_host_mak
29433dd46c78SBlue Swirlecho "CPP=$cpp" >> $config_host_mak
2944804edf29SJuan Quintelaecho "OBJCOPY=$objcopy" >> $config_host_mak
2945804edf29SJuan Quintelaecho "LD=$ld" >> $config_host_mak
294646eef33bSBradecho "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
2947a558ee17SJuan Quintelaecho "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
294811cde1c8SBruno Dominguezecho "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
29494cb37d11SPhilippe Mathieu-Daudéecho "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak
2950a81df1b6SPaolo Bonziniecho "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
2951a81df1b6SPaolo Bonziniecho "GLIB_LIBS=$glib_libs" >> $config_host_mak
2952d83acfd0SMarc-André Lureauecho "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak
29538a99e9a3SPhilippe Mathieu-Daudéecho "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
2954e57218b6SPeter Maydellecho "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
2955a70248dbSPaolo Bonziniecho "STRIP=$strip" >> $config_host_mak
2956804edf29SJuan Quintelaecho "EXESUF=$EXESUF" >> $config_host_mak
2957804edf29SJuan Quintela
29586efd7517SPeter Maydell# use included Linux headers
29596efd7517SPeter Maydellif test "$linux" = "yes" ; then
2960a307beb6SAndreas Färber  mkdir -p linux-headers
29616efd7517SPeter Maydell  case "$cpu" in
29624da270beSPaolo Bonzini  i386|x86_64)
296308312a63SPeter Maydell    linux_arch=x86
29646efd7517SPeter Maydell    ;;
2965d8ff892dSPaolo Bonzini  ppc|ppc64)
296608312a63SPeter Maydell    linux_arch=powerpc
29676efd7517SPeter Maydell    ;;
29686efd7517SPeter Maydell  s390x)
296908312a63SPeter Maydell    linux_arch=s390
297008312a63SPeter Maydell    ;;
29711f080313SClaudio Fontana  aarch64)
29721f080313SClaudio Fontana    linux_arch=arm64
29731f080313SClaudio Fontana    ;;
2974dfcf900bSWANG Xuerui  loongarch*)
2975dfcf900bSWANG Xuerui    linux_arch=loongarch
2976dfcf900bSWANG Xuerui    ;;
2977222e7d11SSanjay Lal  mips64)
2978222e7d11SSanjay Lal    linux_arch=mips
2979222e7d11SSanjay Lal    ;;
298008312a63SPeter Maydell  *)
298108312a63SPeter Maydell    # For most CPUs the kernel architecture name and QEMU CPU name match.
298208312a63SPeter Maydell    linux_arch="$cpu"
29836efd7517SPeter Maydell    ;;
29846efd7517SPeter Maydell  esac
298508312a63SPeter Maydell    # For non-KVM architectures we will not have asm headers
298608312a63SPeter Maydell    if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
298708312a63SPeter Maydell      symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
298808312a63SPeter Maydell    fi
29896efd7517SPeter Maydellfi
29906efd7517SPeter Maydell
299197a847bcSbellardfor target in $target_list; do
299297a847bcSbellard    target_dir="$target"
299357a93f16SPhilippe Mathieu-Daudé    target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
299497a847bcSbellard    mkdir -p $target_dir
2995fdb75aefSPaolo Bonzini    case $target in
2996fdb75aefSPaolo Bonzini        *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
2997fdb75aefSPaolo Bonzini        *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
29982408a527Saurel32    esac
299956aebc89Spbrookdone
30007d13299dSbellard
3001765686d6SPaolo Bonziniecho "CONFIG_QEMU_INTERP_PREFIX=$interp_prefix" | sed 's/%M/@0@/' >> $config_host_mak
3002fdb75aefSPaolo Bonziniif test "$default_targets" = "yes"; then
3003fdb75aefSPaolo Bonzini  echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
3004fdb75aefSPaolo Bonzinifi
3005a540f158SPeter Crosthwaite
3006fd0e6053SJohn Snowif test "$ccache_cpp2" = "yes"; then
3007fd0e6053SJohn Snow  echo "export CCACHE_CPP2=y" >> $config_host_mak
3008fd0e6053SJohn Snowfi
3009fd0e6053SJohn Snow
30101e4f6065SDaniele Buonoif test "$safe_stack" = "yes"; then
30111e4f6065SDaniele Buono  echo "CONFIG_SAFESTACK=y" >> $config_host_mak
30121e4f6065SDaniele Buonofi
30131e4f6065SDaniele Buono
3014e29e5c6eSPeter Maydell# If we're using a separate build tree, set it up now.
3015e29e5c6eSPeter Maydell# LINKS are things to symlink back into the source tree
3016e29e5c6eSPeter Maydell# (these can be both files and directories).
3017e29e5c6eSPeter Maydell# Caution: do not add files or directories here using wildcards. This
3018e29e5c6eSPeter Maydell# will result in problems later if a new file matching the wildcard is
3019e29e5c6eSPeter Maydell# added to the source tree -- nothing will cause configure to be rerun
3020e29e5c6eSPeter Maydell# so the build tree will be missing the link back to the new file, and
3021e29e5c6eSPeter Maydell# tests might fail. Prefer to keep the relevant files in their own
3022e29e5c6eSPeter Maydell# directory and symlink the directory instead.
30232038f8c8SPaolo BonziniLINKS="Makefile"
30243941996bSPaolo BonziniLINKS="$LINKS tests/tcg/Makefile.target"
3025ddcf607fSGerd HoffmannLINKS="$LINKS pc-bios/optionrom/Makefile"
3026e29e5c6eSPeter MaydellLINKS="$LINKS pc-bios/s390-ccw/Makefile"
30278db2a4fdSGerd HoffmannLINKS="$LINKS roms/seabios/Makefile"
3028e29e5c6eSPeter MaydellLINKS="$LINKS pc-bios/qemu-icon.bmp"
3029e29e5c6eSPeter MaydellLINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
3030bbbd9b6eSWillian RampazzoLINKS="$LINKS tests/avocado tests/data"
303139950353SPeter MaydellLINKS="$LINKS tests/qemu-iotests/check"
30328f8fd9edSCleber RosaLINKS="$LINKS python"
3033c17a386bSAlex BennéeLINKS="$LINKS contrib/plugins/Makefile "
3034753d11f2SRichard Hendersonfor bios_file in \
3035753d11f2SRichard Henderson    $source_path/pc-bios/*.bin \
30363a631b8eSBin Meng    $source_path/pc-bios/*.elf \
3037225a9ab8SAlexey Kardashevskiy    $source_path/pc-bios/*.lid \
3038753d11f2SRichard Henderson    $source_path/pc-bios/*.rom \
3039753d11f2SRichard Henderson    $source_path/pc-bios/*.dtb \
3040e89e33e1SDominik Dingel    $source_path/pc-bios/*.img \
3041753d11f2SRichard Henderson    $source_path/pc-bios/openbios-* \
30424e73c781SAlexander Graf    $source_path/pc-bios/u-boot.* \
3043cd946e5cSJohn Arbuckle    $source_path/pc-bios/palcode-* \
3044cd946e5cSJohn Arbuckle    $source_path/pc-bios/qemu_vga.ndrv
3045cd946e5cSJohn Arbuckle
3046753d11f2SRichard Hendersondo
3047e29e5c6eSPeter Maydell    LINKS="$LINKS pc-bios/$(basename $bios_file)"
30487ea78b74SJan Kiszkadone
3049e29e5c6eSPeter Maydellfor f in $LINKS ; do
30500f4d8894SPaolo Bonzini    if [ -e "$source_path/$f" ]; then
30515dce7b8dSPaolo Bonzini        mkdir -p `dirname ./$f`
3052f9245e10SPeter Maydell        symlink "$source_path/$f" "$f"
3053f9245e10SPeter Maydell    fi
30547d13299dSbellarddone
30551ad2134fSPaul Brook
30562038f8c8SPaolo Bonzini(for i in $cross_cc_vars; do
30572038f8c8SPaolo Bonzini  export $i
30582038f8c8SPaolo Bonzinidone
3059*544f4a25SPaolo Bonziniexport target_list source_path use_containers cpu host_cc
30602038f8c8SPaolo Bonzini$source_path/tests/tcg/configure.sh)
30612038f8c8SPaolo Bonzini
3062c34ebfdcSAnthony Liguori# temporary config to build submodules
3063bb7cb3adSPaolo Bonziniif test -f $source_path/roms/seabios/Makefile; then
30648db2a4fdSGerd Hoffmann  for rom in seabios; do
3065c34ebfdcSAnthony Liguori    config_mak=roms/$rom/config.mak
306637116c89SStefan Weil    echo "# Automatically generated by configure - do not modify" > $config_mak
3067c34ebfdcSAnthony Liguori    echo "SRC_PATH=$source_path/roms/$rom" >> $config_mak
3068cdbd727cSRichard Henderson    echo "AS=$as" >> $config_mak
30695f6f0e27SRichard Henderson    echo "CCAS=$ccas" >> $config_mak
3070c34ebfdcSAnthony Liguori    echo "CC=$cc" >> $config_mak
3071c34ebfdcSAnthony Liguori    echo "BCC=bcc" >> $config_mak
30723dd46c78SBlue Swirl    echo "CPP=$cpp" >> $config_mak
3073c34ebfdcSAnthony Liguori    echo "OBJCOPY=objcopy" >> $config_mak
3074a31a8642SMichael S. Tsirkin    echo "IASL=$iasl" >> $config_mak
3075c34ebfdcSAnthony Liguori    echo "LD=$ld" >> $config_mak
30769f81aeb5SAlistair Francis    echo "RANLIB=$ranlib" >> $config_mak
3077c34ebfdcSAnthony Liguori  done
3078bb7cb3adSPaolo Bonzinifi
3079c34ebfdcSAnthony Liguori
308098409991SHelge Konetzkaconfig_mak=pc-bios/optionrom/config.mak
308198409991SHelge Konetzkaecho "# Automatically generated by configure - do not modify" > $config_mak
308298409991SHelge Konetzkaecho "TOPSRC_DIR=$source_path" >> $config_mak
308398409991SHelge Konetzka
3084a5665051SPaolo Bonziniif test "$skip_meson" = no; then
3085fc929892SMarc-André Lureau  cross="config-meson.cross.new"
3086fc929892SMarc-André Lureau  meson_quote() {
3087ac7ebcc5SPaolo Bonzini    test $# = 0 && return
308847b30835SPaolo Bonzini    echo "'$(echo $* | sed "s/ /','/g")'"
3089fc929892SMarc-André Lureau  }
3090fc929892SMarc-André Lureau
3091fc929892SMarc-André Lureau  echo "# Automatically generated by configure - do not modify" > $cross
3092fc929892SMarc-André Lureau  echo "[properties]" >> $cross
3093d1d5e9eeSAlex Bennée
3094d1d5e9eeSAlex Bennée  # unroll any custom device configs
3095d1d5e9eeSAlex Bennée  for a in $device_archs; do
3096d1d5e9eeSAlex Bennée      eval "c=\$devices_${a}"
3097d1d5e9eeSAlex Bennée      echo "${a}-softmmu = '$c'" >> $cross
3098d1d5e9eeSAlex Bennée  done
3099d1d5e9eeSAlex Bennée
3100fc929892SMarc-André Lureau  test -z "$cxx" && echo "link_language = 'c'" >> $cross
310147b30835SPaolo Bonzini  echo "[built-in options]" >> $cross
3102a2866660SPaolo Bonzini  echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
3103a2866660SPaolo Bonzini  echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
3104e910c7d9SPhilippe Mathieu-Daudé  test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
3105a2866660SPaolo Bonzini  echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
3106a2866660SPaolo Bonzini  echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
3107fc929892SMarc-André Lureau  echo "[binaries]" >> $cross
31084dba2789SPaolo Bonzini  echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
31094dba2789SPaolo Bonzini  test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
31104dba2789SPaolo Bonzini  test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
311147b30835SPaolo Bonzini  echo "ar = [$(meson_quote $ar)]" >> $cross
311247b30835SPaolo Bonzini  echo "nm = [$(meson_quote $nm)]" >> $cross
311347b30835SPaolo Bonzini  echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
311447b30835SPaolo Bonzini  echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
3115e8178514SPaolo Bonzini  if has $sdl2_config; then
311647b30835SPaolo Bonzini    echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
3117e8178514SPaolo Bonzini  fi
311847b30835SPaolo Bonzini  echo "strip = [$(meson_quote $strip)]" >> $cross
311947b30835SPaolo Bonzini  echo "windres = [$(meson_quote $windres)]" >> $cross
31203812c0c4SJoelle van Dyne  if test "$cross_compile" = "yes"; then
3121fc929892SMarc-André Lureau    cross_arg="--cross-file config-meson.cross"
3122fc929892SMarc-André Lureau    echo "[host_machine]" >> $cross
3123ba7c60c2SPaolo Bonzini    echo "system = '$targetos'" >> $cross
3124823eb013SPaolo Bonzini    case "$cpu" in
3125f6bca9dfSJoelle van Dyne        i386)
3126fc929892SMarc-André Lureau            echo "cpu_family = 'x86'" >> $cross
3127fc929892SMarc-André Lureau            ;;
3128fc929892SMarc-André Lureau        *)
3129823eb013SPaolo Bonzini            echo "cpu_family = '$cpu'" >> $cross
3130fc929892SMarc-André Lureau            ;;
3131fc929892SMarc-André Lureau    esac
3132fc929892SMarc-André Lureau    echo "cpu = '$cpu'" >> $cross
3133fc929892SMarc-André Lureau    if test "$bigendian" = "yes" ; then
3134fc929892SMarc-André Lureau        echo "endian = 'big'" >> $cross
3135fc929892SMarc-André Lureau    else
3136fc929892SMarc-André Lureau        echo "endian = 'little'" >> $cross
3137fc929892SMarc-André Lureau    fi
3138fc929892SMarc-André Lureau  else
3139fc929892SMarc-André Lureau    cross_arg="--native-file config-meson.cross"
3140fc929892SMarc-André Lureau  fi
3141fc929892SMarc-André Lureau  mv $cross config-meson.cross
3142fc929892SMarc-André Lureau
3143a5665051SPaolo Bonzini  rm -rf meson-private meson-info meson-logs
314461d63097SPaolo Bonzini  run_meson() {
314509e93326SPaolo Bonzini    NINJA=$ninja $meson setup \
3146d17f305aSPaolo Bonzini        --prefix "$prefix" \
3147d17f305aSPaolo Bonzini        --libdir "$libdir" \
3148d17f305aSPaolo Bonzini        --libexecdir "$libexecdir" \
3149d17f305aSPaolo Bonzini        --bindir "$bindir" \
3150d17f305aSPaolo Bonzini        --includedir "$includedir" \
3151d17f305aSPaolo Bonzini        --datadir "$datadir" \
3152d17f305aSPaolo Bonzini        --mandir "$mandir" \
3153d17f305aSPaolo Bonzini        --sysconfdir "$sysconfdir" \
315416bf7a33SPaolo Bonzini        --localedir "$localedir" \
3155d17f305aSPaolo Bonzini        --localstatedir "$local_statedir" \
31563b4da132SPaolo Bonzini        -Daudio_drv_list=$audio_drv_list \
31573b4da132SPaolo Bonzini        -Ddefault_devices=$default_devices \
3158d17f305aSPaolo Bonzini        -Ddocdir="$docdir" \
31595dc4618eSPaolo Bonzini        -Diasl="$($iasl -h >/dev/null 2>&1 && printf %s "$iasl")" \
316016bf7a33SPaolo Bonzini        -Dqemu_firmwarepath="$firmwarepath" \
316173f3aa37SMarc-André Lureau        -Dqemu_suffix="$qemu_suffix" \
316235acbb30SPaolo Bonzini        -Dsmbd="$smbd" \
31633b4da132SPaolo Bonzini        -Dsphinx_build="$sphinx_build" \
31643b4da132SPaolo Bonzini        -Dtrace_file="$trace_file" \
3165a5665051SPaolo Bonzini        -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) \
3166a5665051SPaolo Bonzini        -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo false; fi) \
3167a5665051SPaolo Bonzini        -Dwerror=$(if test "$werror" = yes; then echo true; else echo false; fi) \
3168da6d48b9SMarc-André Lureau        -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \
3169bf0e56a3SMarc-André Lureau        -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
31703b4da132SPaolo Bonzini        -Db_lto=$lto -Dcfi=$cfi -Dtcg=$tcg -Dxen=$xen \
31713b4da132SPaolo Bonzini        -Dcapstone=$capstone -Dfdt=$fdt -Dslirp=$slirp \
3172537b7248SPaolo Bonzini        $(test -n "${LIB_FUZZING_ENGINE+xxx}" && echo "-Dfuzzing_engine=$LIB_FUZZING_ENGINE") \
3173332008e0SThomas Huth        $(if test "$default_feature" = no; then echo "-Dauto_features=disabled"; fi) \
317461d63097SPaolo Bonzini        "$@" $cross_arg "$PWD" "$source_path"
317561d63097SPaolo Bonzini  }
317661d63097SPaolo Bonzini  eval run_meson $meson_options
3177a5665051SPaolo Bonzini  if test "$?" -ne 0 ; then
3178a5665051SPaolo Bonzini      error_exit "meson setup failed"
3179a5665051SPaolo Bonzini  fi
3180699d3884SPaolo Bonzinielse
3181699d3884SPaolo Bonzini  if test -f meson-private/cmd_line.txt; then
3182699d3884SPaolo Bonzini    # Adjust old command line options whose type was changed
3183699d3884SPaolo Bonzini    # Avoids having to use "setup --wipe" when Meson is upgraded
3184699d3884SPaolo Bonzini    perl -i -ne '
3185699d3884SPaolo Bonzini      s/^gettext = true$/gettext = auto/;
3186699d3884SPaolo Bonzini      s/^gettext = false$/gettext = disabled/;
3187654d6b04SPaolo Bonzini      /^b_staticpic/ && next;
3188699d3884SPaolo Bonzini      print;' meson-private/cmd_line.txt
3189699d3884SPaolo Bonzini  fi
3190a5665051SPaolo Bonzinifi
3191a5665051SPaolo Bonzini
3192dc655404SMichael S. Tsirkin# Save the configure command line for later reuse.
3193dc655404SMichael S. Tsirkincat <<EOD >config.status
3194dc655404SMichael S. Tsirkin#!/bin/sh
3195dc655404SMichael S. Tsirkin# Generated by configure.
3196dc655404SMichael S. Tsirkin# Run this file to recreate the current configuration.
3197dc655404SMichael S. Tsirkin# Compiler output produced by configure, useful for debugging
3198dc655404SMichael S. Tsirkin# configure, is in config.log if it exists.
3199dc655404SMichael S. TsirkinEOD
3200e811da7fSDaniel P. Berrangé
3201e811da7fSDaniel P. Berrangépreserve_env() {
3202e811da7fSDaniel P. Berrangé    envname=$1
3203e811da7fSDaniel P. Berrangé
3204e811da7fSDaniel P. Berrangé    eval envval=\$$envname
3205e811da7fSDaniel P. Berrangé
3206e811da7fSDaniel P. Berrangé    if test -n "$envval"
3207e811da7fSDaniel P. Berrangé    then
3208e811da7fSDaniel P. Berrangé	echo "$envname='$envval'" >> config.status
3209e811da7fSDaniel P. Berrangé	echo "export $envname" >> config.status
3210e811da7fSDaniel P. Berrangé    else
3211e811da7fSDaniel P. Berrangé	echo "unset $envname" >> config.status
3212e811da7fSDaniel P. Berrangé    fi
3213e811da7fSDaniel P. Berrangé}
3214e811da7fSDaniel P. Berrangé
3215e811da7fSDaniel P. Berrangé# Preserve various env variables that influence what
3216e811da7fSDaniel P. Berrangé# features/build target configure will detect
3217e811da7fSDaniel P. Berrangépreserve_env AR
3218e811da7fSDaniel P. Berrangépreserve_env AS
3219e811da7fSDaniel P. Berrangépreserve_env CC
3220e811da7fSDaniel P. Berrangépreserve_env CPP
32218009da03SPaolo Bonzinipreserve_env CFLAGS
3222e811da7fSDaniel P. Berrangépreserve_env CXX
32238009da03SPaolo Bonzinipreserve_env CXXFLAGS
3224e811da7fSDaniel P. Berrangépreserve_env INSTALL
3225e811da7fSDaniel P. Berrangépreserve_env LD
32268009da03SPaolo Bonzinipreserve_env LDFLAGS
3227e811da7fSDaniel P. Berrangépreserve_env LD_LIBRARY_PATH
3228e811da7fSDaniel P. Berrangépreserve_env LIBTOOL
3229e811da7fSDaniel P. Berrangépreserve_env MAKE
3230e811da7fSDaniel P. Berrangépreserve_env NM
3231e811da7fSDaniel P. Berrangépreserve_env OBJCOPY
3232e811da7fSDaniel P. Berrangépreserve_env PATH
3233e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG
3234e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_LIBDIR
3235e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_PATH
3236e811da7fSDaniel P. Berrangépreserve_env PYTHON
3237e811da7fSDaniel P. Berrangépreserve_env SDL2_CONFIG
3238e811da7fSDaniel P. Berrangépreserve_env SMBD
3239e811da7fSDaniel P. Berrangépreserve_env STRIP
3240e811da7fSDaniel P. Berrangépreserve_env WINDRES
3241e811da7fSDaniel P. Berrangé
3242dc655404SMichael S. Tsirkinprintf "exec" >>config.status
3243a5665051SPaolo Bonzinifor i in "$0" "$@"; do
3244835af899SPaolo Bonzini  test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
3245a5665051SPaolo Bonzinidone
3246cf7cc929SDr. David Alan Gilbertecho ' "$@"' >>config.status
3247dc655404SMichael S. Tsirkinchmod +x config.status
3248dc655404SMichael S. Tsirkin
32498cd05ab6SPeter Maydellrm -r "$TMPDIR1"
3250