xref: /openbmc/qemu/configure (revision 14efd8d3b5fee7027f0ee072aea6620e0655774f)
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"
247cdad781dSDaniele Buonolto="false"
24863678e17SSteven Noonanstack_protector=""
2491e4f6065SDaniele Buonosafe_stack=""
250afc3a8f9SAlex Bennéeuse_containers="yes"
251f2385398SAlex Bennéegdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
252ac0df51dSaliguori
25392712822SDaniel P. Berrangeif test -e "$source_path/.git"
25492712822SDaniel P. Berrangethen
2557d7dbf9dSDan Streetman    git_submodules_action="update"
25692712822SDaniel P. Berrangeelse
2577d7dbf9dSDan Streetman    git_submodules_action="ignore"
25892712822SDaniel P. Berrangefi
2592d652f24SPaolo Bonzini
2602d652f24SPaolo Bonzinigit_submodules="ui/keycodemapdb"
261cc84d63aSDaniel P. Berrangegit="git"
262ac0df51dSaliguori
263afb63ebdSStefan Weil# Don't accept a target_list environment variable.
264afb63ebdSStefan Weilunset target_list
265447e133fSAlex Bennéeunset target_list_exclude
266377529c0SPaolo Bonzini
267377529c0SPaolo Bonzini# Default value for a variable defining feature "foo".
268377529c0SPaolo Bonzini#  * foo="no"  feature will only be used if --enable-foo arg is given
269377529c0SPaolo Bonzini#  * foo=""    feature will be searched for, and if found, will be used
270377529c0SPaolo Bonzini#              unless --disable-foo is given
271377529c0SPaolo Bonzini#  * foo="yes" this value will only be set by --enable-foo flag.
272377529c0SPaolo Bonzini#              feature will searched for,
273377529c0SPaolo Bonzini#              if not found, configure exits with error
274377529c0SPaolo Bonzini#
275377529c0SPaolo Bonzini# Always add --enable-foo and --disable-foo command line args.
276377529c0SPaolo Bonzini# Distributions want to ensure that several features are compiled in, and it
277377529c0SPaolo Bonzini# is impossible without a --enable-foo that exits if a feature is not found.
278377529c0SPaolo Bonzini
279c87ea116SAlex Bennéedefault_feature=""
280c87ea116SAlex Bennée# parse CC options second
281c87ea116SAlex Bennéefor opt do
282c87ea116SAlex Bennée  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
283c87ea116SAlex Bennée  case "$opt" in
284c87ea116SAlex Bennée      --without-default-features)
285c87ea116SAlex Bennée          default_feature="no"
286c87ea116SAlex Bennée  ;;
287c87ea116SAlex Bennée  esac
288c87ea116SAlex Bennéedone
289c87ea116SAlex Bennée
290a2866660SPaolo BonziniEXTRA_CFLAGS=""
291a2866660SPaolo BonziniEXTRA_CXXFLAGS=""
292e910c7d9SPhilippe Mathieu-DaudéEXTRA_OBJCFLAGS=""
293a2866660SPaolo BonziniEXTRA_LDFLAGS=""
294a2866660SPaolo Bonzini
2950848f8acSThomas Huthvhost_kernel="$default_feature"
296c87ea116SAlex Bennéevhost_net="$default_feature"
297c87ea116SAlex Bennéevhost_crypto="$default_feature"
298c87ea116SAlex Bennéevhost_scsi="$default_feature"
299c87ea116SAlex Bennéevhost_vsock="$default_feature"
300d88618f7SStefan Hajnoczivhost_user="no"
301c87ea116SAlex Bennéevhost_user_fs="$default_feature"
3020848f8acSThomas Huthvhost_vdpa="$default_feature"
30328609749SPaolo Bonzinidebug_info="yes"
304377529c0SPaolo Bonzinidebug_tcg="no"
305377529c0SPaolo Bonzinidebug="no"
306247724cbSMarc-André Lureausanitizers="no"
3070aebab04SLingfeng Yangtsan="no"
3081f3f2bfeSMichael Tokarevfortify_source="yes"
3091d728c39SBlue Swirlgcov="no"
310c7328271SMiroslav RezaninaEXESUF=""
31117969268SFam Zhengmodules="no"
312377529c0SPaolo Bonziniprefix="/usr/local"
31310ff82d1SMarc-André Lureauqemu_suffix="qemu"
314377529c0SPaolo Bonzinisoftmmu="yes"
315b915a2f1SPaolo Bonzinilinux_user=""
316b915a2f1SPaolo Bonzinibsd_user=""
317377529c0SPaolo Bonzinipkgversion=""
31840d6444eSAvi Kivitypie=""
319377529c0SPaolo Bonzinitrace_file="trace"
320519175a2SAlex Barcelocoroutine=""
321a1c5e949SDaniel P. Berrangetls_priority="NORMAL"
322ba4dd2aaSAlex Bennéeplugins="$default_feature"
323a5665051SPaolo Bonzinimeson=""
3243b4da132SPaolo Bonzinimeson_args=""
32548328880SPaolo Bonzinininja=""
326a5665051SPaolo Bonziniskip_meson=no
327377529c0SPaolo Bonzini
3283b4da132SPaolo Bonzini# The following Meson options are handled manually (still they
3293b4da132SPaolo Bonzini# are included in the automatically generated help message)
3303b4da132SPaolo Bonzini
3313b4da132SPaolo Bonzini# 1. Track which submodules are needed
3320577e84dSThomas Huthif test "$default_feature" = no ; then
3330577e84dSThomas Huth  capstone="disabled"
3340577e84dSThomas Huth  slirp="disabled"
3350577e84dSThomas Huthelse
3363b4da132SPaolo Bonzini  capstone="auto"
3373b4da132SPaolo Bonzini  slirp="auto"
3380577e84dSThomas Huthfi
3390577e84dSThomas Huthfdt="auto"
3403b4da132SPaolo Bonzini
3413b4da132SPaolo Bonzini# 2. Support --with/--without option
3423b4da132SPaolo Bonzinidefault_devices="true"
3433b4da132SPaolo Bonzini
3443b4da132SPaolo Bonzini# 3. Automatically enable/disable other options
3453b4da132SPaolo Bonzinitcg="enabled"
3463b4da132SPaolo Bonzinicfi="false"
3473b4da132SPaolo Bonzini
348c87ea116SAlex Bennée# parse CC options second
349ac0df51dSaliguorifor opt do
35089138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
351ac0df51dSaliguori  case "$opt" in
352ac0df51dSaliguori  --cross-prefix=*) cross_prefix="$optarg"
3533812c0c4SJoelle van Dyne                    cross_compile="yes"
354ac0df51dSaliguori  ;;
3553d8df640SPaolo Bonzini  --cc=*) CC="$optarg"
356ac0df51dSaliguori  ;;
35783f73fceSTomoki Sekiyama  --cxx=*) CXX="$optarg"
35883f73fceSTomoki Sekiyama  ;;
3592ff6b91eSJuan Quintela  --cpu=*) cpu="$optarg"
3602ff6b91eSJuan Quintela  ;;
361a2866660SPaolo Bonzini  --extra-cflags=*)
362a2866660SPaolo Bonzini    EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
363a2866660SPaolo Bonzini    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
364e910c7d9SPhilippe Mathieu-Daudé    EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
365e2a2ed06SJuan Quintela    ;;
366a2866660SPaolo Bonzini  --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
36711cde1c8SBruno Dominguez  ;;
368e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
369e910c7d9SPhilippe Mathieu-Daudé  ;;
370a2866660SPaolo Bonzini  --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
371e2a2ed06SJuan Quintela  ;;
372d75402b5SAlex Bennée  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
373d75402b5SAlex Bennée  ;;
374479ca4ccSMatheus Ferst  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
375d422b2bcSAlex Bennée                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
3762038f8c8SPaolo Bonzini                      cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
377d422b2bcSAlex Bennée  ;;
378d75402b5SAlex Bennée  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
379d75402b5SAlex Bennée                eval "cross_cc_${cc_arch}=\$optarg"
3802038f8c8SPaolo Bonzini                cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
381d75402b5SAlex Bennée  ;;
382ac0df51dSaliguori  esac
383ac0df51dSaliguoridone
384ac0df51dSaliguori# OS specific
385ac0df51dSaliguori# Using uname is really, really broken.  Once we have the right set of checks
38693148aa5SStefan Weil# we can eliminate its usage altogether.
387ac0df51dSaliguori
388e49d021eSPeter Maydell# Preferred compiler:
389e49d021eSPeter Maydell#  ${CC} (if set)
390e49d021eSPeter Maydell#  ${cross_prefix}gcc (if cross-prefix specified)
391e49d021eSPeter Maydell#  system compiler
392e49d021eSPeter Maydellif test -z "${CC}${cross_prefix}"; then
393e49d021eSPeter Maydell  cc="$host_cc"
394e49d021eSPeter Maydellelse
395b3198cc2SStuart Yoder  cc="${CC-${cross_prefix}gcc}"
396e49d021eSPeter Maydellfi
397e49d021eSPeter Maydell
39883f73fceSTomoki Sekiyamaif test -z "${CXX}${cross_prefix}"; then
39983f73fceSTomoki Sekiyama  cxx="c++"
40083f73fceSTomoki Sekiyamaelse
40183f73fceSTomoki Sekiyama  cxx="${CXX-${cross_prefix}g++}"
40283f73fceSTomoki Sekiyamafi
40383f73fceSTomoki Sekiyama
404b3198cc2SStuart Yoderar="${AR-${cross_prefix}ar}"
405cdbd727cSRichard Hendersonas="${AS-${cross_prefix}as}"
4065f6f0e27SRichard Hendersonccas="${CCAS-$cc}"
4073dd46c78SBlue Swirlcpp="${CPP-$cc -E}"
408b3198cc2SStuart Yoderobjcopy="${OBJCOPY-${cross_prefix}objcopy}"
409b3198cc2SStuart Yoderld="${LD-${cross_prefix}ld}"
4109f81aeb5SAlistair Francisranlib="${RANLIB-${cross_prefix}ranlib}"
4114852ee95SStefan Weilnm="${NM-${cross_prefix}nm}"
41235acbb30SPaolo Bonzinismbd="$SMBD"
413b3198cc2SStuart Yoderstrip="${STRIP-${cross_prefix}strip}"
414158bb224SKonstantin Kostiukwidl="${WIDL-${cross_prefix}widl}"
415b3198cc2SStuart Yoderwindres="${WINDRES-${cross_prefix}windres}"
41617884d7bSSergei Trofimovichpkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
41717884d7bSSergei Trofimovichquery_pkg_config() {
41817884d7bSSergei Trofimovich    "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
41917884d7bSSergei Trofimovich}
42017884d7bSSergei Trofimovichpkg_config=query_pkg_config
42147c03744SDave Airliesdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
422ac0df51dSaliguori
423be17dc90SMichael S. Tsirkin# default flags for all hosts
4242d31515bSPeter Maydell# We use -fwrapv to tell the compiler that we require a C dialect where
4252d31515bSPeter Maydell# left shift of signed integers is well defined and has the expected
4262d31515bSPeter Maydell# 2s-complement style results. (Both clang and gcc agree that it
4272d31515bSPeter Maydell# provides these semantics.)
428de38c0ccSPaolo BonziniQEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
429086d5f75SPaolo BonziniQEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
430c95e3080SKevin WolfQEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
431be17dc90SMichael S. TsirkinQEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
4325770e8afSPaolo Bonzini
433de38c0ccSPaolo BonziniQEMU_LDFLAGS=
434de38c0ccSPaolo Bonzini
4355770e8afSPaolo Bonzini# Flags that are needed during configure but later taken care of by Meson
4368a9d3d56SRichard HendersonCONFIGURE_CFLAGS="-std=gnu11 -Wall"
4375770e8afSPaolo BonziniCONFIGURE_LDFLAGS=
438086d5f75SPaolo Bonzini
439be17dc90SMichael S. Tsirkin
440ac0df51dSaliguoricheck_define() {
441ac0df51dSaliguoricat > $TMPC <<EOF
442ac0df51dSaliguori#if !defined($1)
443fd786e1aSPeter Maydell#error $1 not defined
444ac0df51dSaliguori#endif
445ac0df51dSaliguoriint main(void) { return 0; }
446ac0df51dSaliguoriEOF
44752166aa0SJuan Quintela  compile_object
448ac0df51dSaliguori}
449ac0df51dSaliguori
450307119e7SGerd Hoffmanncheck_include() {
451307119e7SGerd Hoffmanncat > $TMPC <<EOF
452307119e7SGerd Hoffmann#include <$1>
453307119e7SGerd Hoffmannint main(void) { return 0; }
454307119e7SGerd HoffmannEOF
455307119e7SGerd Hoffmann  compile_object
456307119e7SGerd Hoffmann}
457307119e7SGerd Hoffmann
45893b25869SJohn Snowwrite_c_skeleton() {
45993b25869SJohn Snow    cat > $TMPC <<EOF
46093b25869SJohn Snowint main(void) { return 0; }
46193b25869SJohn SnowEOF
46293b25869SJohn Snow}
46393b25869SJohn Snow
464bbea4050SPeter Maydellif check_define __linux__ ; then
465ba7c60c2SPaolo Bonzini  targetos=linux
466bbea4050SPeter Maydellelif check_define _WIN32 ; then
467ba7c60c2SPaolo Bonzini  targetos=windows
468bbea4050SPeter Maydellelif check_define __OpenBSD__ ; then
469ba7c60c2SPaolo Bonzini  targetos=openbsd
470bbea4050SPeter Maydellelif check_define __sun__ ; then
471ba7c60c2SPaolo Bonzini  targetos=sunos
472bbea4050SPeter Maydellelif check_define __HAIKU__ ; then
473ba7c60c2SPaolo Bonzini  targetos=haiku
474951fedfcSPeter Maydellelif check_define __FreeBSD__ ; then
475ba7c60c2SPaolo Bonzini  targetos=freebsd
476951fedfcSPeter Maydellelif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
477ba7c60c2SPaolo Bonzini  targetos=gnu/kfreebsd
478951fedfcSPeter Maydellelif check_define __DragonFly__ ; then
479ba7c60c2SPaolo Bonzini  targetos=dragonfly
480951fedfcSPeter Maydellelif check_define __NetBSD__; then
481ba7c60c2SPaolo Bonzini  targetos=netbsd
482951fedfcSPeter Maydellelif check_define __APPLE__; then
483ba7c60c2SPaolo Bonzini  targetos=darwin
484bbea4050SPeter Maydellelse
485951fedfcSPeter Maydell  # This is a fatal error, but don't report it yet, because we
486951fedfcSPeter Maydell  # might be going to just print the --help text, or it might
487951fedfcSPeter Maydell  # be the result of a missing compiler.
488ba7c60c2SPaolo Bonzini  targetos=bogus
489bbea4050SPeter Maydellfi
490bbea4050SPeter Maydell
49165eff01bSPaolo Bonzini# OS specific
49265eff01bSPaolo Bonzini
4933b0d8643SPaolo Bonzinimingw32="no"
4943b0d8643SPaolo Bonzinibsd="no"
4953b0d8643SPaolo Bonzinilinux="no"
4963b0d8643SPaolo Bonzinisolaris="no"
49765eff01bSPaolo Bonzinicase $targetos in
49865eff01bSPaolo Bonziniwindows)
49965eff01bSPaolo Bonzini  mingw32="yes"
50065eff01bSPaolo Bonzini  plugins="no"
50165eff01bSPaolo Bonzini  pie="no"
50265eff01bSPaolo Bonzini;;
50365eff01bSPaolo Bonzinignu/kfreebsd)
50465eff01bSPaolo Bonzini  bsd="yes"
50565eff01bSPaolo Bonzini;;
50665eff01bSPaolo Bonzinifreebsd)
50765eff01bSPaolo Bonzini  bsd="yes"
50865eff01bSPaolo Bonzini  make="${MAKE-gmake}"
50965eff01bSPaolo Bonzini  # needed for kinfo_getvmmap(3) in libutil.h
51065eff01bSPaolo Bonzini;;
51165eff01bSPaolo Bonzinidragonfly)
51265eff01bSPaolo Bonzini  bsd="yes"
51365eff01bSPaolo Bonzini  make="${MAKE-gmake}"
51465eff01bSPaolo Bonzini;;
51565eff01bSPaolo Bonzininetbsd)
51665eff01bSPaolo Bonzini  bsd="yes"
51765eff01bSPaolo Bonzini  make="${MAKE-gmake}"
51865eff01bSPaolo Bonzini;;
51965eff01bSPaolo Bonziniopenbsd)
52065eff01bSPaolo Bonzini  bsd="yes"
52165eff01bSPaolo Bonzini  make="${MAKE-gmake}"
52265eff01bSPaolo Bonzini;;
52365eff01bSPaolo Bonzinidarwin)
52465eff01bSPaolo Bonzini  bsd="yes"
52565eff01bSPaolo Bonzini  darwin="yes"
52665eff01bSPaolo Bonzini  # Disable attempts to use ObjectiveC features in os/object.h since they
52765eff01bSPaolo Bonzini  # won't work when we're compiling with gcc as a C compiler.
52865eff01bSPaolo Bonzini  QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
52965eff01bSPaolo Bonzini;;
53065eff01bSPaolo Bonzinisunos)
53165eff01bSPaolo Bonzini  solaris="yes"
53265eff01bSPaolo Bonzini  make="${MAKE-gmake}"
53365eff01bSPaolo Bonzini# needed for CMSG_ macros in sys/socket.h
53465eff01bSPaolo Bonzini  QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
53565eff01bSPaolo Bonzini# needed for TIOCWIN* defines in termios.h
53665eff01bSPaolo Bonzini  QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
53765eff01bSPaolo Bonzini  # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
53865eff01bSPaolo Bonzini  # Note that this check is broken for cross-compilation: if you're
539bbea4050SPeter Maydell  # cross-compiling to one of these OSes then you'll need to specify
540bbea4050SPeter Maydell  # the correct CPU with the --cpu option.
541bbea4050SPeter Maydell  if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
542bbea4050SPeter Maydell    cpu="x86_64"
543bbea4050SPeter Maydell  fi
54465eff01bSPaolo Bonzini;;
54565eff01bSPaolo Bonzinihaiku)
54665eff01bSPaolo Bonzini  pie="no"
54765eff01bSPaolo Bonzini  QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
54865eff01bSPaolo Bonzini;;
54965eff01bSPaolo Bonzinilinux)
55065eff01bSPaolo Bonzini  linux="yes"
55165eff01bSPaolo Bonzini  vhost_user=${default_feature:-yes}
55265eff01bSPaolo Bonzini;;
553bbea4050SPeter Maydellesac
554bbea4050SPeter Maydell
5552ff6b91eSJuan Quintelaif test ! -z "$cpu" ; then
5562ff6b91eSJuan Quintela  # command line argument
5572ff6b91eSJuan Quintela  :
5582ff6b91eSJuan Quintelaelif check_define __i386__ ; then
559ac0df51dSaliguori  cpu="i386"
560ac0df51dSaliguorielif check_define __x86_64__ ; then
561c72b26ecSRichard Henderson  if check_define __ILP32__ ; then
562c72b26ecSRichard Henderson    cpu="x32"
563c72b26ecSRichard Henderson  else
564ac0df51dSaliguori    cpu="x86_64"
565c72b26ecSRichard Henderson  fi
5663aa9bd6cSblueswir1elif check_define __sparc__ ; then
5673aa9bd6cSblueswir1  if check_define __arch64__ ; then
5683aa9bd6cSblueswir1    cpu="sparc64"
5693aa9bd6cSblueswir1  else
5703aa9bd6cSblueswir1    cpu="sparc"
5713aa9bd6cSblueswir1  fi
572fdf7ed96Smalcelif check_define _ARCH_PPC ; then
573fdf7ed96Smalc  if check_define _ARCH_PPC64 ; then
574f8378accSRichard Henderson    if check_define _LITTLE_ENDIAN ; then
575f8378accSRichard Henderson      cpu="ppc64le"
576f8378accSRichard Henderson    else
577fdf7ed96Smalc      cpu="ppc64"
578f8378accSRichard Henderson    fi
579ac0df51dSaliguori  else
580fdf7ed96Smalc    cpu="ppc"
581fdf7ed96Smalc  fi
582afa05235SAurelien Jarnoelif check_define __mips__ ; then
583afa05235SAurelien Jarno  cpu="mips"
584d66ed0eaSAurelien Jarnoelif check_define __s390__ ; then
585d66ed0eaSAurelien Jarno  if check_define __s390x__ ; then
586d66ed0eaSAurelien Jarno    cpu="s390x"
587d66ed0eaSAurelien Jarno  else
588d66ed0eaSAurelien Jarno    cpu="s390"
589d66ed0eaSAurelien Jarno  fi
590c4f80543SAlistair Franciselif check_define __riscv ; then
591ba0e7333SRichard Henderson  cpu="riscv"
59221d89f84SPeter Maydellelif check_define __arm__ ; then
59321d89f84SPeter Maydell  cpu="arm"
5941f080313SClaudio Fontanaelif check_define __aarch64__ ; then
5951f080313SClaudio Fontana  cpu="aarch64"
596dfcf900bSWANG Xueruielif check_define __loongarch64 ; then
597dfcf900bSWANG Xuerui  cpu="loongarch64"
598fdf7ed96Smalcelse
59989138857SStefan Weil  cpu=$(uname -m)
600ac0df51dSaliguorifi
601ac0df51dSaliguori
602823eb013SPaolo Bonzini# Normalise host CPU name, set multilib cflags
603359bc95dSPeter Maydell# Note that this case should only have supported host CPUs, not guests.
6047d13299dSbellardcase "$cpu" in
605e4da0e39SPaolo Bonzini  armv*b|armv*l|arm)
606e4da0e39SPaolo Bonzini    cpu="arm" ;;
607e4da0e39SPaolo Bonzini
6087d13299dSbellard  i386|i486|i586|i686|i86pc|BePC)
60997a847bcSbellard    cpu="i386"
610e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32" ;;
611e4da0e39SPaolo Bonzini  x32)
6124da270beSPaolo Bonzini    cpu="x86_64"
613e4da0e39SPaolo Bonzini    CPU_CFLAGS="-mx32" ;;
614aaa5fa14Saurel32  x86_64|amd64)
615aaa5fa14Saurel32    cpu="x86_64"
616e4da0e39SPaolo Bonzini    # ??? Only extremely old AMD cpus do not have cmpxchg16b.
617e4da0e39SPaolo Bonzini    # If we truly care, we should simply detect this case at
618e4da0e39SPaolo Bonzini    # runtime and generate the fallback to serial emulation.
619e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64 -mcx16" ;;
620e4da0e39SPaolo Bonzini
621afa05235SAurelien Jarno  mips*)
622e4da0e39SPaolo Bonzini    cpu="mips" ;;
623e4da0e39SPaolo Bonzini
624e4da0e39SPaolo Bonzini  ppc)
625e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32" ;;
626e4da0e39SPaolo Bonzini  ppc64)
627ced5cfffSMiroslav Rezanina    CPU_CFLAGS="-m64 -mbig-endian" ;;
628e4da0e39SPaolo Bonzini  ppc64le)
629d8ff892dSPaolo Bonzini    cpu="ppc64"
630ced5cfffSMiroslav Rezanina    CPU_CFLAGS="-m64 -mlittle-endian" ;;
631e4da0e39SPaolo Bonzini
632e4da0e39SPaolo Bonzini  s390)
633823eb013SPaolo Bonzini    CPU_CFLAGS="-m31" ;;
634e4da0e39SPaolo Bonzini  s390x)
635e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64" ;;
636e4da0e39SPaolo Bonzini
6373142255cSblueswir1  sparc|sun4[cdmuv])
638ae228531Sbellard    cpu="sparc"
639e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
640e4da0e39SPaolo Bonzini  sparc64)
641e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
6427d13299dSbellardesac
643e2d52ad3SJuan Quintela
6440db4a067SPaolo Bonzini: ${make=${MAKE-make}}
645b6daf4d3SPaolo Bonzini
646faf44142SDaniel P. Berrangé# We prefer python 3.x. A bare 'python' is traditionally
647faf44142SDaniel P. Berrangé# python 2.x, but some distros have it as python 3.x, so
648ddf90699SEduardo Habkost# we check that too
649faf44142SDaniel P. Berrangépython=
6500a01d76fSMarc-André Lureauexplicit_python=no
651ddf90699SEduardo Habkostfor binary in "${PYTHON-python3}" python
652faf44142SDaniel P. Berrangédo
653faf44142SDaniel P. Berrangé    if has "$binary"
654faf44142SDaniel P. Berrangé    then
65595c5f2deSPaolo Bonzini        python=$(command -v "$binary")
656faf44142SDaniel P. Berrangé        break
657faf44142SDaniel P. Berrangé    fi
658faf44142SDaniel P. Berrangédone
659903458c8SMarkus Armbruster
660903458c8SMarkus Armbruster
66139d87c8cSAlex Bennée# Check for ancillary tools used in testing
66239d87c8cSAlex Bennéegenisoimage=
6633df437c7SAlex Bennéefor binary in genisoimage mkisofs
66439d87c8cSAlex Bennéedo
66539d87c8cSAlex Bennée    if has $binary
66639d87c8cSAlex Bennée    then
66739d87c8cSAlex Bennée        genisoimage=$(command -v "$binary")
66839d87c8cSAlex Bennée        break
66939d87c8cSAlex Bennée    fi
67039d87c8cSAlex Bennéedone
67139d87c8cSAlex Bennée
6723c4a4d0dSPeter Maydell# Default objcc to clang if available, otherwise use CC
6733c4a4d0dSPeter Maydellif has clang; then
6743c4a4d0dSPeter Maydell  objcc=clang
6753c4a4d0dSPeter Maydellelse
6763c4a4d0dSPeter Maydell  objcc="$cc"
6773c4a4d0dSPeter Maydellfi
6783c4a4d0dSPeter Maydell
6793457a3f8SJuan Quintelaif test "$mingw32" = "yes" ; then
6803457a3f8SJuan Quintela  EXESUF=".exe"
68178e9d4adSStefan Weil  # MinGW needs -mthreads for TLS and macro _MT.
6825770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
68393b25869SJohn Snow  write_c_skeleton;
684d17f305aSPaolo Bonzini  prefix="/qemu"
68577433a5fSMarc-André Lureau  qemu_suffix=""
6863457a3f8SJuan Quintelafi
6873457a3f8SJuan Quintela
688487fefdbSAnthony Liguoriwerror=""
68985aa5189Sbellard
69061d63097SPaolo Bonzini. $source_path/scripts/meson-buildoptions.sh
69161d63097SPaolo Bonzini
69261d63097SPaolo Bonzinimeson_options=
69361d63097SPaolo Bonzinimeson_option_parse() {
69461d63097SPaolo Bonzini  meson_options="$meson_options $(_meson_option_parse "$@")"
69561d63097SPaolo Bonzini  if test $? -eq 1; then
69661d63097SPaolo Bonzini    echo "ERROR: unknown option $1"
69761d63097SPaolo Bonzini    echo "Try '$0 --help' for more information"
69861d63097SPaolo Bonzini    exit 1
69961d63097SPaolo Bonzini  fi
70061d63097SPaolo Bonzini}
70161d63097SPaolo Bonzini
7027d13299dSbellardfor opt do
70389138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
7047d13299dSbellard  case "$opt" in
7052efc3265Sbellard  --help|-h) show_help=yes
7062efc3265Sbellard  ;;
70799123e13SMike Frysinger  --version|-V) exec cat $source_path/VERSION
70899123e13SMike Frysinger  ;;
709b1a550a0Spbrook  --prefix=*) prefix="$optarg"
7107d13299dSbellard  ;;
711b1a550a0Spbrook  --interp-prefix=*) interp_prefix="$optarg"
71232ce6337Sbellard  ;;
713ac0df51dSaliguori  --cross-prefix=*)
7147d13299dSbellard  ;;
715ac0df51dSaliguori  --cc=*)
7167d13299dSbellard  ;;
717b1a550a0Spbrook  --host-cc=*) host_cc="$optarg"
71883469015Sbellard  ;;
71983f73fceSTomoki Sekiyama  --cxx=*)
72083f73fceSTomoki Sekiyama  ;;
721e007dbecSMichael S. Tsirkin  --iasl=*) iasl="$optarg"
722e007dbecSMichael S. Tsirkin  ;;
7233c4a4d0dSPeter Maydell  --objcc=*) objcc="$optarg"
7243c4a4d0dSPeter Maydell  ;;
725b1a550a0Spbrook  --make=*) make="$optarg"
7267d13299dSbellard  ;;
727b6daf4d3SPaolo Bonzini  --install=*)
7286a882643Spbrook  ;;
7290a01d76fSMarc-André Lureau  --python=*) python="$optarg" ; explicit_python=yes
730c886edfbSBlue Swirl  ;;
7312eb054c2SPeter Maydell  --sphinx-build=*) sphinx_build="$optarg"
7322eb054c2SPeter Maydell  ;;
733a5665051SPaolo Bonzini  --skip-meson) skip_meson=yes
734a5665051SPaolo Bonzini  ;;
735a5665051SPaolo Bonzini  --meson=*) meson="$optarg"
736a5665051SPaolo Bonzini  ;;
73748328880SPaolo Bonzini  --ninja=*) ninja="$optarg"
73848328880SPaolo Bonzini  ;;
739e2d8830eSBrad  --smbd=*) smbd="$optarg"
740e2d8830eSBrad  ;;
741e2a2ed06SJuan Quintela  --extra-cflags=*)
7427d13299dSbellard  ;;
74311cde1c8SBruno Dominguez  --extra-cxxflags=*)
74411cde1c8SBruno Dominguez  ;;
745e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=*)
746e910c7d9SPhilippe Mathieu-Daudé  ;;
747e2a2ed06SJuan Quintela  --extra-ldflags=*)
7487d13299dSbellard  ;;
749d75402b5SAlex Bennée  --cross-cc-*)
750d75402b5SAlex Bennée  ;;
75128609749SPaolo Bonzini  --enable-debug-info) debug_info="yes"
75228609749SPaolo Bonzini  ;;
75328609749SPaolo Bonzini  --disable-debug-info) debug_info="no"
75428609749SPaolo Bonzini  ;;
75517969268SFam Zheng  --enable-modules)
75617969268SFam Zheng      modules="yes"
75717969268SFam Zheng  ;;
7583aa88b31SStefan Hajnoczi  --disable-modules)
7593aa88b31SStefan Hajnoczi      modules="no"
7603aa88b31SStefan Hajnoczi  ;;
7612ff6b91eSJuan Quintela  --cpu=*)
7627d13299dSbellard  ;;
763b1a550a0Spbrook  --target-list=*) target_list="$optarg"
764447e133fSAlex Bennée                   if test "$target_list_exclude"; then
765447e133fSAlex Bennée                       error_exit "Can't mix --target-list with --target-list-exclude"
766447e133fSAlex Bennée                   fi
767447e133fSAlex Bennée  ;;
768447e133fSAlex Bennée  --target-list-exclude=*) target_list_exclude="$optarg"
769447e133fSAlex Bennée                   if test "$target_list"; then
770447e133fSAlex Bennée                       error_exit "Can't mix --target-list-exclude with --target-list"
771447e133fSAlex Bennée                   fi
772de83cd02Sbellard  ;;
77374242e0fSPaolo Bonzini  --with-trace-file=*) trace_file="$optarg"
7749410b56cSPrerna Saxena  ;;
7757bc3ca7fSPaolo Bonzini  --with-default-devices) default_devices="true"
776f3494749SPaolo Bonzini  ;;
7777bc3ca7fSPaolo Bonzini  --without-default-devices) default_devices="false"
778f3494749SPaolo Bonzini  ;;
779d1d5e9eeSAlex Bennée  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
780d1d5e9eeSAlex Bennée  ;;
781d1d5e9eeSAlex Bennée  --with-devices-*) device_arch=${opt#--with-devices-};
782d1d5e9eeSAlex Bennée                    device_arch=${device_arch%%=*}
783d1d5e9eeSAlex Bennée                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
784d1d5e9eeSAlex Bennée                    if test -f "$cf"; then
785d1d5e9eeSAlex Bennée                        device_archs="$device_archs $device_arch"
786d1d5e9eeSAlex Bennée                        eval "devices_${device_arch}=\$optarg"
787d1d5e9eeSAlex Bennée                    else
788d1d5e9eeSAlex Bennée                        error_exit "File $cf does not exist"
789d1d5e9eeSAlex Bennée                    fi
790d1d5e9eeSAlex Bennée  ;;
791c87ea116SAlex Bennée  --without-default-features) # processed above
792c87ea116SAlex Bennée  ;;
7931d728c39SBlue Swirl  --enable-gcov) gcov="yes"
7941d728c39SBlue Swirl  ;;
79579427693SLoïc Minier  --static)
79679427693SLoïc Minier    static="yes"
79717884d7bSSergei Trofimovich    QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
79843ce4dfeSbellard  ;;
7990b24e75fSPaolo Bonzini  --mandir=*) mandir="$optarg"
8000b24e75fSPaolo Bonzini  ;;
8010b24e75fSPaolo Bonzini  --bindir=*) bindir="$optarg"
8020b24e75fSPaolo Bonzini  ;;
8033aa5d2beSAlon Levy  --libdir=*) libdir="$optarg"
8043aa5d2beSAlon Levy  ;;
8058bf188aaSMichael Tokarev  --libexecdir=*) libexecdir="$optarg"
8068bf188aaSMichael Tokarev  ;;
8070f94d6daSAlon Levy  --includedir=*) includedir="$optarg"
8080f94d6daSAlon Levy  ;;
809528ae5b8SEduardo Habkost  --datadir=*) datadir="$optarg"
8100b24e75fSPaolo Bonzini  ;;
81177433a5fSMarc-André Lureau  --with-suffix=*) qemu_suffix="$optarg"
812023d3d67SEduardo Habkost  ;;
813c6502638SBruce Rogers  --docdir=*) docdir="$optarg"
8140b24e75fSPaolo Bonzini  ;;
815fe0038beSPaolo Bonzini  --localedir=*) localedir="$optarg"
816fe0038beSPaolo Bonzini  ;;
817ca2fb938SAndre Przywara  --sysconfdir=*) sysconfdir="$optarg"
81807381cc1SAnthony Liguori  ;;
819785c23aeSLuiz Capitulino  --localstatedir=*) local_statedir="$optarg"
820785c23aeSLuiz Capitulino  ;;
8213d5eecabSGerd Hoffmann  --firmwarepath=*) firmwarepath="$optarg"
8223d5eecabSGerd Hoffmann  ;;
823181ce1d0SOlaf Hering  --host=*|--build=*|\
824181ce1d0SOlaf Hering  --disable-dependency-tracking|\
825785c23aeSLuiz Capitulino  --sbindir=*|--sharedstatedir=*|\
826fe0038beSPaolo Bonzini  --oldincludedir=*|--datarootdir=*|--infodir=*|\
827023ddd74SMax Filippov  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
828023ddd74SMax Filippov    # These switches are silently ignored, for compatibility with
829023ddd74SMax Filippov    # autoconf-generated configure scripts. This allows QEMU's
830023ddd74SMax Filippov    # configure to be used by RPM and similar macros that set
831023ddd74SMax Filippov    # lots of directory switches by default.
832023ddd74SMax Filippov  ;;
8330c58ac1cSmalc  --audio-drv-list=*) audio_drv_list="$optarg"
8340c58ac1cSmalc  ;;
83589138857SStefan Weil  --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
836b64ec4e4SFam Zheng  ;;
83789138857SStefan Weil  --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
838eb852011SMarkus Armbruster  ;;
839f8393946Saurel32  --enable-debug-tcg) debug_tcg="yes"
840f8393946Saurel32  ;;
841f8393946Saurel32  --disable-debug-tcg) debug_tcg="no"
842f8393946Saurel32  ;;
843f3d08ee6SPaul Brook  --enable-debug)
844f3d08ee6SPaul Brook      # Enable debugging options that aren't excessively noisy
845f3d08ee6SPaul Brook      debug_tcg="yes"
846c55cf6abSPaolo Bonzini      meson_option_parse --enable-debug-mutex ""
847f3d08ee6SPaul Brook      debug="yes"
848b553a042SJohn Snow      fortify_source="no"
849f3d08ee6SPaul Brook  ;;
850247724cbSMarc-André Lureau  --enable-sanitizers) sanitizers="yes"
851247724cbSMarc-André Lureau  ;;
852247724cbSMarc-André Lureau  --disable-sanitizers) sanitizers="no"
853247724cbSMarc-André Lureau  ;;
8540aebab04SLingfeng Yang  --enable-tsan) tsan="yes"
8550aebab04SLingfeng Yang  ;;
8560aebab04SLingfeng Yang  --disable-tsan) tsan="no"
8570aebab04SLingfeng Yang  ;;
8584d34a86bSPaolo Bonzini  --disable-slirp) slirp="disabled"
859c20709aaSbellard  ;;
860fd6fc214SPaolo Bonzini  --enable-slirp) slirp="enabled"
861fd6fc214SPaolo Bonzini  ;;
8624d34a86bSPaolo Bonzini  --enable-slirp=git) slirp="internal"
8637c57bdd8SMarc-André Lureau  ;;
86403a3c0b3SPaolo Bonzini  --enable-slirp=*) slirp="$optarg"
865675b9b53SMarc-André Lureau  ;;
8661badb709SPaolo Bonzini  --disable-tcg) tcg="disabled"
867d1a14257SAlex Bennée                 plugins="no"
868b3f6ea7eSPaolo Bonzini  ;;
8691badb709SPaolo Bonzini  --enable-tcg) tcg="enabled"
870b3f6ea7eSPaolo Bonzini  ;;
871cad25d69Spbrook  --disable-system) softmmu="no"
8720a8e90f4Spbrook  ;;
873cad25d69Spbrook  --enable-system) softmmu="yes"
8740a8e90f4Spbrook  ;;
8750953a80fSZachary Amsden  --disable-user)
8760953a80fSZachary Amsden      linux_user="no" ;
8770953a80fSZachary Amsden      bsd_user="no" ;
8780953a80fSZachary Amsden  ;;
8790953a80fSZachary Amsden  --enable-user) ;;
880831b7825Sths  --disable-linux-user) linux_user="no"
8810a8e90f4Spbrook  ;;
882831b7825Sths  --enable-linux-user) linux_user="yes"
883831b7825Sths  ;;
88484778508Sblueswir1  --disable-bsd-user) bsd_user="no"
88584778508Sblueswir1  ;;
88684778508Sblueswir1  --enable-bsd-user) bsd_user="yes"
88784778508Sblueswir1  ;;
88840d6444eSAvi Kivity  --enable-pie) pie="yes"
88934005a00SKirill A. Shutemov  ;;
89040d6444eSAvi Kivity  --disable-pie) pie="no"
89134005a00SKirill A. Shutemov  ;;
89285aa5189Sbellard  --enable-werror) werror="yes"
89385aa5189Sbellard  ;;
89485aa5189Sbellard  --disable-werror) werror="no"
89585aa5189Sbellard  ;;
896cdad781dSDaniele Buono  --enable-lto) lto="true"
897cdad781dSDaniele Buono  ;;
898cdad781dSDaniele Buono  --disable-lto) lto="false"
899cdad781dSDaniele Buono  ;;
90063678e17SSteven Noonan  --enable-stack-protector) stack_protector="yes"
90163678e17SSteven Noonan  ;;
90263678e17SSteven Noonan  --disable-stack-protector) stack_protector="no"
90363678e17SSteven Noonan  ;;
9041e4f6065SDaniele Buono  --enable-safe-stack) safe_stack="yes"
9051e4f6065SDaniele Buono  ;;
9061e4f6065SDaniele Buono  --disable-safe-stack) safe_stack="no"
9071e4f6065SDaniele Buono  ;;
9089e62ba48SDaniele Buono  --enable-cfi)
9099e62ba48SDaniele Buono      cfi="true";
9109e62ba48SDaniele Buono      lto="true";
9119e62ba48SDaniele Buono  ;;
9129e62ba48SDaniele Buono  --disable-cfi) cfi="false"
9139e62ba48SDaniele Buono  ;;
914fbb4121dSPaolo Bonzini  --disable-fdt) fdt="disabled"
9152df87df7SJuan Quintela  ;;
916fbb4121dSPaolo Bonzini  --enable-fdt) fdt="enabled"
917fbb4121dSPaolo Bonzini  ;;
918fbb4121dSPaolo Bonzini  --enable-fdt=git) fdt="internal"
919fbb4121dSPaolo Bonzini  ;;
92003a3c0b3SPaolo Bonzini  --enable-fdt=*) fdt="$optarg"
9212df87df7SJuan Quintela  ;;
9227e563bfbSThomas Huth  --with-pkgversion=*) pkgversion="$optarg"
9234a19f1ecSpbrook  ;;
924519175a2SAlex Barcelo  --with-coroutine=*) coroutine="$optarg"
925519175a2SAlex Barcelo  ;;
926d5970055SMichael S. Tsirkin  --disable-vhost-net) vhost_net="no"
927d5970055SMichael S. Tsirkin  ;;
928d5970055SMichael S. Tsirkin  --enable-vhost-net) vhost_net="yes"
929d5970055SMichael S. Tsirkin  ;;
930042cea27SGonglei  --disable-vhost-crypto) vhost_crypto="no"
931042cea27SGonglei  ;;
932299e6f19SPaolo Bonzini  --enable-vhost-crypto) vhost_crypto="yes"
933042cea27SGonglei  ;;
9345e9be92dSNicholas Bellinger  --disable-vhost-scsi) vhost_scsi="no"
9355e9be92dSNicholas Bellinger  ;;
9365e9be92dSNicholas Bellinger  --enable-vhost-scsi) vhost_scsi="yes"
9375e9be92dSNicholas Bellinger  ;;
938fc0b9b0eSStefan Hajnoczi  --disable-vhost-vsock) vhost_vsock="no"
939fc0b9b0eSStefan Hajnoczi  ;;
940fc0b9b0eSStefan Hajnoczi  --enable-vhost-vsock) vhost_vsock="yes"
941fc0b9b0eSStefan Hajnoczi  ;;
94298fc1adaSDr. David Alan Gilbert  --disable-vhost-user-fs) vhost_user_fs="no"
94398fc1adaSDr. David Alan Gilbert  ;;
94498fc1adaSDr. David Alan Gilbert  --enable-vhost-user-fs) vhost_user_fs="yes"
94598fc1adaSDr. David Alan Gilbert  ;;
9461ffb3bbbSPaolo Bonzini  --disable-zlib-test)
9471ece9905SAlon Levy  ;;
94852b53c04SFam Zheng  --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
94952b53c04SFam Zheng      echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
950583f6e7bSStefan Hajnoczi  ;;
951cb6414dfSFam Zheng  --enable-vhdx|--disable-vhdx)
952cb6414dfSFam Zheng      echo "$0: $opt is obsolete, VHDX driver is always built" >&2
953cb6414dfSFam Zheng  ;;
954315d3184SFam Zheng  --enable-uuid|--disable-uuid)
955315d3184SFam Zheng      echo "$0: $opt is obsolete, UUID support is always built" >&2
956315d3184SFam Zheng  ;;
957a1c5e949SDaniel P. Berrange  --tls-priority=*) tls_priority="$optarg"
958a1c5e949SDaniel P. Berrange  ;;
959e6a74868SMarc-André Lureau  --disable-vhost-user) vhost_user="no"
960e6a74868SMarc-André Lureau  ;;
961299e6f19SPaolo Bonzini  --enable-vhost-user) vhost_user="yes"
962299e6f19SPaolo Bonzini  ;;
963108a6481SCindy Lu  --disable-vhost-vdpa) vhost_vdpa="no"
964108a6481SCindy Lu  ;;
965108a6481SCindy Lu  --enable-vhost-vdpa) vhost_vdpa="yes"
966108a6481SCindy Lu  ;;
967299e6f19SPaolo Bonzini  --disable-vhost-kernel) vhost_kernel="no"
968299e6f19SPaolo Bonzini  ;;
969299e6f19SPaolo Bonzini  --enable-vhost-kernel) vhost_kernel="yes"
970e6a74868SMarc-André Lureau  ;;
9718b18cdbfSRichard Henderson  --disable-capstone) capstone="disabled"
9728ca80760SRichard Henderson  ;;
9738b18cdbfSRichard Henderson  --enable-capstone) capstone="enabled"
9748ca80760SRichard Henderson  ;;
9758b18cdbfSRichard Henderson  --enable-capstone=git) capstone="internal"
976e219c499SRichard Henderson  ;;
97703a3c0b3SPaolo Bonzini  --enable-capstone=*) capstone="$optarg"
978e219c499SRichard Henderson  ;;
979cc84d63aSDaniel P. Berrange  --with-git=*) git="$optarg"
980cc84d63aSDaniel P. Berrange  ;;
9817d7dbf9dSDan Streetman  --with-git-submodules=*)
9827d7dbf9dSDan Streetman      git_submodules_action="$optarg"
983f62bbee5SDaniel P. Berrange  ;;
9849b8e4298SAlex Bennée  --enable-plugins) if test "$mingw32" = "yes"; then
9859b8e4298SAlex Bennée                        error_exit "TCG plugins not currently supported on Windows platforms"
9869b8e4298SAlex Bennée                    else
9879b8e4298SAlex Bennée                        plugins="yes"
9889b8e4298SAlex Bennée                    fi
98940e8c6f4SAlex Bennée  ;;
99040e8c6f4SAlex Bennée  --disable-plugins) plugins="no"
99140e8c6f4SAlex Bennée  ;;
992afc3a8f9SAlex Bennée  --enable-containers) use_containers="yes"
993afc3a8f9SAlex Bennée  ;;
994afc3a8f9SAlex Bennée  --disable-containers) use_containers="no"
995afc3a8f9SAlex Bennée  ;;
996f48e590aSAlex Bennée  --gdb=*) gdb_bin="$optarg"
997f48e590aSAlex Bennée  ;;
9983b4da132SPaolo Bonzini  # backwards compatibility options
9993b4da132SPaolo Bonzini  --enable-trace-backend=*) meson_option_parse "--enable-trace-backends=$optarg" "$optarg"
10003b4da132SPaolo Bonzini  ;;
10013b4da132SPaolo Bonzini  --disable-blobs) meson_option_parse --disable-install-blobs ""
10023b4da132SPaolo Bonzini  ;;
10033b4da132SPaolo Bonzini  --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
10043b4da132SPaolo Bonzini  ;;
10053b4da132SPaolo Bonzini  --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
10063b4da132SPaolo Bonzini  ;;
10073b4da132SPaolo Bonzini  # everything else has the same name in configure and meson
100861d63097SPaolo Bonzini  --enable-* | --disable-*) meson_option_parse "$opt" "$optarg"
100961d63097SPaolo Bonzini  ;;
10102d2ad6d0SFam Zheng  *)
10112d2ad6d0SFam Zheng      echo "ERROR: unknown option $opt"
10122d2ad6d0SFam Zheng      echo "Try '$0 --help' for more information"
10132d2ad6d0SFam Zheng      exit 1
10147f1559c6Sbalrog  ;;
10157d13299dSbellard  esac
10167d13299dSbellarddone
10177d13299dSbellard
1018d1a14257SAlex Bennée# test for any invalid configuration combinations
1019d1a14257SAlex Bennéeif test "$plugins" = "yes" -a "$tcg" = "disabled"; then
1020d1a14257SAlex Bennée    error_exit "Can't enable plugins on non-TCG builds"
1021d1a14257SAlex Bennéefi
1022d1a14257SAlex Bennée
10237d7dbf9dSDan Streetmancase $git_submodules_action in
10247d7dbf9dSDan Streetman    update|validate)
10257d7dbf9dSDan Streetman        if test ! -e "$source_path/.git"; then
10267d7dbf9dSDan Streetman            echo "ERROR: cannot $git_submodules_action git submodules without .git"
10277d7dbf9dSDan Streetman            exit 1
10287d7dbf9dSDan Streetman        fi
10297d7dbf9dSDan Streetman    ;;
10307d7dbf9dSDan Streetman    ignore)
1031b80fd281SPaolo Bonzini        if ! test -f "$source_path/ui/keycodemapdb/README"
1032b80fd281SPaolo Bonzini        then
1033b80fd281SPaolo Bonzini            echo
1034b80fd281SPaolo Bonzini            echo "ERROR: missing GIT submodules"
1035b80fd281SPaolo Bonzini            echo
1036b80fd281SPaolo Bonzini            if test -e "$source_path/.git"; then
1037b80fd281SPaolo Bonzini                echo "--with-git-submodules=ignore specified but submodules were not"
1038b80fd281SPaolo Bonzini                echo "checked out.  Please initialize and update submodules."
1039b80fd281SPaolo Bonzini            else
1040b80fd281SPaolo Bonzini                echo "This is not a GIT checkout but module content appears to"
1041b80fd281SPaolo Bonzini                echo "be missing. Do not use 'git archive' or GitHub download links"
1042b80fd281SPaolo Bonzini                echo "to acquire QEMU source archives. Non-GIT builds are only"
1043b80fd281SPaolo Bonzini                echo "supported with source archives linked from:"
1044b80fd281SPaolo Bonzini                echo
1045b80fd281SPaolo Bonzini                echo "  https://www.qemu.org/download/#source"
1046b80fd281SPaolo Bonzini                echo
1047b80fd281SPaolo Bonzini                echo "Developers working with GIT can use scripts/archive-source.sh"
1048b80fd281SPaolo Bonzini                echo "if they need to create valid source archives."
1049b80fd281SPaolo Bonzini            fi
1050b80fd281SPaolo Bonzini            echo
1051b80fd281SPaolo Bonzini            exit 1
1052b80fd281SPaolo Bonzini        fi
10537d7dbf9dSDan Streetman    ;;
10547d7dbf9dSDan Streetman    *)
10557d7dbf9dSDan Streetman        echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
10567d7dbf9dSDan Streetman        exit 1
10577d7dbf9dSDan Streetman    ;;
10587d7dbf9dSDan Streetmanesac
10597d7dbf9dSDan Streetman
106022a87800SMarc-André Lureaulibdir="${libdir:-$prefix/lib}"
106122a87800SMarc-André Lureaulibexecdir="${libexecdir:-$prefix/libexec}"
106222a87800SMarc-André Lureauincludedir="${includedir:-$prefix/include}"
106322a87800SMarc-André Lureau
106422a87800SMarc-André Lureauif test "$mingw32" = "yes" ; then
106515588a62SJoshua Watt    bindir="${bindir:-$prefix}"
106622a87800SMarc-André Lureauelse
106715588a62SJoshua Watt    bindir="${bindir:-$prefix/bin}"
106815588a62SJoshua Wattfi
106922a87800SMarc-André Lureaumandir="${mandir:-$prefix/share/man}"
107022a87800SMarc-André Lureaudatadir="${datadir:-$prefix/share}"
1071ca8c0909SMarc-André Lureaudocdir="${docdir:-$prefix/share/doc}"
107222a87800SMarc-André Lureausysconfdir="${sysconfdir:-$prefix/etc}"
107322a87800SMarc-André Lureaulocal_statedir="${local_statedir:-$prefix/var}"
107416bf7a33SPaolo Bonzinifirmwarepath="${firmwarepath:-$datadir/qemu-firmware}"
107516bf7a33SPaolo Bonzinilocaledir="${localedir:-$datadir/locale}"
107622a87800SMarc-André Lureau
10779557af9cSAlex Bennéeif eval test -z "\${cross_cc_$cpu}"; then
1078b1aa4de1SAlex Bennée    eval "cross_cc_${cpu}=\$cc"
10792038f8c8SPaolo Bonzini    cross_cc_vars="$cross_cc_vars cross_cc_${cpu}"
10809557af9cSAlex Bennéefi
108179f3b12fSPeter Crosthwaite
108260e0df25SPeter Maydelldefault_target_list=""
10836e92f823SPeter Maydellmak_wilds=""
10846e92f823SPeter Maydell
1085b915a2f1SPaolo Bonziniif [ "$linux_user" != no ]; then
1086b915a2f1SPaolo Bonzini    if [ "$targetos" = linux ] && [ -d $source_path/linux-user/include/host/$cpu ]; then
1087b915a2f1SPaolo Bonzini        linux_user=yes
1088b915a2f1SPaolo Bonzini    elif [ "$linux_user" = yes ]; then
1089b915a2f1SPaolo Bonzini        error_exit "linux-user not supported on this architecture"
1090b915a2f1SPaolo Bonzini    fi
1091b915a2f1SPaolo Bonzinifi
1092b915a2f1SPaolo Bonziniif [ "$bsd_user" != no ]; then
1093b915a2f1SPaolo Bonzini    if [ "$bsd_user" = "" ]; then
1094b915a2f1SPaolo Bonzini        test $targetos = freebsd && bsd_user=yes
1095b915a2f1SPaolo Bonzini    fi
1096b915a2f1SPaolo Bonzini    if [ "$bsd_user" = yes ] && ! [ -d $source_path/bsd-user/$targetos ]; then
1097b915a2f1SPaolo Bonzini        error_exit "bsd-user not supported on this host OS"
1098b915a2f1SPaolo Bonzini    fi
1099b915a2f1SPaolo Bonzinifi
110060e0df25SPeter Maydellif [ "$softmmu" = "yes" ]; then
1101812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
110260e0df25SPeter Maydellfi
110360e0df25SPeter Maydellif [ "$linux_user" = "yes" ]; then
1104812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
110560e0df25SPeter Maydellfi
110660e0df25SPeter Maydellif [ "$bsd_user" = "yes" ]; then
1107812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
110860e0df25SPeter Maydellfi
110960e0df25SPeter Maydell
1110447e133fSAlex Bennéefor config in $mak_wilds; do
1111447e133fSAlex Bennée    target="$(basename "$config" .mak)"
111298db9a06SAlex Bennée    if echo "$target_list_exclude" | grep -vq "$target"; then
1113447e133fSAlex Bennée        default_target_list="${default_target_list} $target"
1114447e133fSAlex Bennée    fi
1115447e133fSAlex Bennéedone
11166e92f823SPeter Maydell
1117af5db58eSpbrookif test x"$show_help" = x"yes" ; then
1118af5db58eSpbrookcat << EOF
1119af5db58eSpbrook
1120af5db58eSpbrookUsage: configure [options]
1121af5db58eSpbrookOptions: [defaults in brackets after descriptions]
1122af5db58eSpbrook
112308fb77edSStefan WeilStandard options:
112408fb77edSStefan Weil  --help                   print this message
112508fb77edSStefan Weil  --prefix=PREFIX          install in PREFIX [$prefix]
112608fb77edSStefan Weil  --interp-prefix=PREFIX   where to find shared libraries, etc.
112708fb77edSStefan Weil                           use %M for cpu name [$interp_prefix]
112874154d7eSThomas Huth  --target-list=LIST       set target list (default: build all)
112908fb77edSStefan Weil$(echo Available targets: $default_target_list | \
113008fb77edSStefan Weil  fold -s -w 53 | sed -e 's/^/                           /')
1131447e133fSAlex Bennée  --target-list-exclude=LIST exclude a set of targets from the default target-list
113208fb77edSStefan Weil
113308fb77edSStefan WeilAdvanced options (experts only):
11343812c0c4SJoelle van Dyne  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
113508fb77edSStefan Weil  --cc=CC                  use C compiler CC [$cc]
113608fb77edSStefan Weil  --iasl=IASL              use ACPI compiler IASL [$iasl]
113708fb77edSStefan Weil  --host-cc=CC             use C compiler CC [$host_cc] for code run at
113808fb77edSStefan Weil                           build time
113908fb77edSStefan Weil  --cxx=CXX                use C++ compiler CXX [$cxx]
114008fb77edSStefan Weil  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
1141a2866660SPaolo Bonzini  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
1142a2866660SPaolo Bonzini  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
1143e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
114408fb77edSStefan Weil  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
1145d75402b5SAlex Bennée  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
1146479ca4ccSMatheus Ferst  --cross-cc-cflags-ARCH=  use compiler flags when building ARCH guest tests
114708fb77edSStefan Weil  --make=MAKE              use specified make [$make]
114808fb77edSStefan Weil  --python=PYTHON          use specified python [$python]
11492eb054c2SPeter Maydell  --sphinx-build=SPHINX    use specified sphinx-build [$sphinx_build]
1150a5665051SPaolo Bonzini  --meson=MESON            use specified meson [$meson]
115148328880SPaolo Bonzini  --ninja=NINJA            use specified ninja [$ninja]
115208fb77edSStefan Weil  --smbd=SMBD              use specified smbd [$smbd]
1153db1b5f13SThomas Huth  --with-git=GIT           use specified git [$git]
11547d7dbf9dSDan Streetman  --with-git-submodules=update   update git submodules (default if .git dir exists)
11557d7dbf9dSDan Streetman  --with-git-submodules=validate fail if git submodules are not up to date
11567d7dbf9dSDan Streetman  --with-git-submodules=ignore   do not update or check git submodules (default if no .git dir)
115708fb77edSStefan Weil  --static                 enable static build [$static]
115808fb77edSStefan Weil  --mandir=PATH            install man pages in PATH
115910ff82d1SMarc-André Lureau  --datadir=PATH           install firmware in PATH/$qemu_suffix
1160fe0038beSPaolo Bonzini  --localedir=PATH         install translation in PATH/$qemu_suffix
116110ff82d1SMarc-André Lureau  --docdir=PATH            install documentation in PATH/$qemu_suffix
116208fb77edSStefan Weil  --bindir=PATH            install binaries in PATH
116308fb77edSStefan Weil  --libdir=PATH            install libraries in PATH
1164db1b5f13SThomas Huth  --libexecdir=PATH        install helper binaries in PATH
116510ff82d1SMarc-André Lureau  --sysconfdir=PATH        install config in PATH/$qemu_suffix
116608fb77edSStefan Weil  --localstatedir=PATH     install local state in PATH (set at runtime on win32)
11673d5eecabSGerd Hoffmann  --firmwarepath=PATH      search PATH for firmware files
116813336606SRobert Foley  --efi-aarch64=PATH       PATH of efi file to use for aarch64 VMs.
1169ca8c0909SMarc-André Lureau  --with-suffix=SUFFIX     suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
1170db1b5f13SThomas Huth  --with-pkgversion=VERS   use specified string as sub-version of the package
1171c035c8d6SPaolo Bonzini  --without-default-features default all --enable-* options to "disabled"
1172c035c8d6SPaolo Bonzini  --without-default-devices  do not include any device that is not needed to
1173c035c8d6SPaolo Bonzini                           start the emulator (only use if you are including
1174d1d5e9eeSAlex Bennée                           desired devices in configs/devices/)
1175d1d5e9eeSAlex Bennée  --with-devices-ARCH=NAME override default configs/devices
117608fb77edSStefan Weil  --enable-debug           enable common debug build options
1177247724cbSMarc-André Lureau  --enable-sanitizers      enable default sanitizers
11780aebab04SLingfeng Yang  --enable-tsan            enable thread sanitizer
117908fb77edSStefan Weil  --disable-werror         disable compilation abort on warning
118063678e17SSteven Noonan  --disable-stack-protector disable compiler-provided stack protection
118116bfbc70SPaolo Bonzini  --audio-drv-list=LIST    set audio drivers to try if -audiodev is not used
118208fb77edSStefan Weil  --block-drv-whitelist=L  Same as --block-drv-rw-whitelist=L
118308fb77edSStefan Weil  --block-drv-rw-whitelist=L
118408fb77edSStefan Weil                           set block driver read-write whitelist
1185e5f05f8cSKevin Wolf                           (by default affects only QEMU, not tools like qemu-img)
118608fb77edSStefan Weil  --block-drv-ro-whitelist=L
118708fb77edSStefan Weil                           set block driver read-only whitelist
1188e5f05f8cSKevin Wolf                           (by default affects only QEMU, not tools like qemu-img)
118908fb77edSStefan Weil  --with-trace-file=NAME   Full PATH,NAME of file to store traces
119008fb77edSStefan Weil                           Default:trace-<pid>
1191c23f23b9SMichael Tokarev  --cpu=CPU                Build for host CPU [$cpu]
119208fb77edSStefan Weil  --with-coroutine=BACKEND coroutine backend. Supported options:
119333c53c54SDaniel P. Berrange                           ucontext, sigaltstack, windows
119408fb77edSStefan Weil  --enable-gcov            enable test coverage analysis with gcov
1195a1c5e949SDaniel P. Berrange  --tls-priority           default TLS protocol/cipher priority string
119640e8c6f4SAlex Bennée  --enable-plugins
119740e8c6f4SAlex Bennée                           enable plugins via shared library loading
1198afc3a8f9SAlex Bennée  --disable-containers     don't use containers for cross-building
1199f48e590aSAlex Bennée  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
120061d63097SPaolo BonziniEOF
120161d63097SPaolo Bonzini  meson_options_help
120261d63097SPaolo Bonzinicat << EOF
1203c23f23b9SMichael Tokarev  system          all system emulation targets
1204c23f23b9SMichael Tokarev  user            supported user emulation targets
1205c23f23b9SMichael Tokarev  linux-user      all linux usermode emulation targets
1206c23f23b9SMichael Tokarev  bsd-user        all BSD usermode emulation targets
1207c23f23b9SMichael Tokarev  pie             Position Independent Executables
120821e709aaSMarc-André Lureau  modules         modules support (non-Windows)
1209c23f23b9SMichael Tokarev  debug-tcg       TCG debugging (default is disabled)
1210c23f23b9SMichael Tokarev  debug-info      debugging information
1211cdad781dSDaniele Buono  lto             Enable Link-Time Optimization.
12121e4f6065SDaniele Buono  safe-stack      SafeStack Stack Smash Protection. Depends on
12131e4f6065SDaniele Buono                  clang/llvm >= 3.7 and requires coroutine backend ucontext.
1214299e6f19SPaolo Bonzini  vhost-net       vhost-net kernel acceleration support
1215299e6f19SPaolo Bonzini  vhost-vsock     virtio sockets device support
1216299e6f19SPaolo Bonzini  vhost-scsi      vhost-scsi kernel target support
1217299e6f19SPaolo Bonzini  vhost-crypto    vhost-user-crypto backend support
1218299e6f19SPaolo Bonzini  vhost-kernel    vhost kernel backend support
1219299e6f19SPaolo Bonzini  vhost-user      vhost-user backend support
1220108a6481SCindy Lu  vhost-vdpa      vhost-vdpa kernel backend support
122108fb77edSStefan Weil
122208fb77edSStefan WeilNOTE: The object files are built at the place where configure is launched
1223af5db58eSpbrookEOF
12242d2ad6d0SFam Zhengexit 0
1225af5db58eSpbrookfi
1226af5db58eSpbrook
12279c790242SThomas Huth# Remove old dependency files to make sure that they get properly regenerated
1228bb768f71SThomas Huthrm -f */config-devices.mak.d
12299c790242SThomas Huth
1230faf44142SDaniel P. Berrangéif test -z "$python"
1231faf44142SDaniel P. Berrangéthen
1232c53eeaf7SStefan Hajnoczi    error_exit "Python not found. Use --python=/path/to/python"
1233c53eeaf7SStefan Hajnoczifi
12348e2c76bdSRoman Bolshakovif ! has "$make"
12358e2c76bdSRoman Bolshakovthen
12368e2c76bdSRoman Bolshakov    error_exit "GNU make ($make) not found"
12378e2c76bdSRoman Bolshakovfi
1238c53eeaf7SStefan Hajnoczi
1239c53eeaf7SStefan Hajnoczi# Note that if the Python conditional here evaluates True we will exit
1240c53eeaf7SStefan Hajnoczi# with status 1 which is a shell 'false' value.
12411b11f28dSThomas Huthif ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then
12421b11f28dSThomas Huth  error_exit "Cannot use '$python', Python >= 3.6 is required." \
1243c53eeaf7SStefan Hajnoczi      "Use --python=/path/to/python to specify a supported Python."
1244c53eeaf7SStefan Hajnoczifi
1245c53eeaf7SStefan Hajnoczi
1246755ee70fSCleber Rosa# Preserve python version since some functionality is dependent on it
1247406ab2f3SCleber 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)
1248755ee70fSCleber Rosa
1249c53eeaf7SStefan Hajnoczi# Suppress writing compiled files
1250c53eeaf7SStefan Hajnoczipython="$python -B"
1251c53eeaf7SStefan Hajnoczi
12520a01d76fSMarc-André Lureauif test -z "$meson"; then
12536638cae5SPaolo Bonzini    if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.59.3; then
12540a01d76fSMarc-André Lureau        meson=meson
12557d7dbf9dSDan Streetman    elif test $git_submodules_action != 'ignore' ; then
12560a01d76fSMarc-André Lureau        meson=git
12570a01d76fSMarc-André Lureau    elif test -e "${source_path}/meson/meson.py" ; then
12580a01d76fSMarc-André Lureau        meson=internal
12590a01d76fSMarc-André Lureau    else
12600a01d76fSMarc-André Lureau        if test "$explicit_python" = yes; then
12610a01d76fSMarc-André Lureau            error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
12620a01d76fSMarc-André Lureau        else
1263a5665051SPaolo Bonzini            error_exit "Meson not found.  Use --meson=/path/to/meson"
1264a5665051SPaolo Bonzini        fi
12650a01d76fSMarc-André Lureau    fi
12660a01d76fSMarc-André Lureauelse
12670a01d76fSMarc-André Lureau    # Meson uses its own Python interpreter to invoke other Python scripts,
12680a01d76fSMarc-André Lureau    # but the user wants to use the one they specified with --python.
12690a01d76fSMarc-André Lureau    #
12700a01d76fSMarc-André Lureau    # We do not want to override the distro Python interpreter (and sometimes
12710a01d76fSMarc-André Lureau    # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
12720a01d76fSMarc-André Lureau    # just require --meson=git|internal together with --python.
12730a01d76fSMarc-André Lureau    if test "$explicit_python" = yes; then
12740a01d76fSMarc-André Lureau        case "$meson" in
12750a01d76fSMarc-André Lureau            git | internal) ;;
12760a01d76fSMarc-André Lureau            *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
12770a01d76fSMarc-André Lureau        esac
12780a01d76fSMarc-André Lureau    fi
12790a01d76fSMarc-André Lureaufi
1280a5665051SPaolo Bonzini
12810a01d76fSMarc-André Lureauif test "$meson" = git; then
12820a01d76fSMarc-André Lureau    git_submodules="${git_submodules} meson"
12830a01d76fSMarc-André Lureaufi
12840a01d76fSMarc-André Lureau
12850a01d76fSMarc-André Lureaucase "$meson" in
12860a01d76fSMarc-André Lureau    git | internal)
12870a01d76fSMarc-André Lureau        meson="$python ${source_path}/meson/meson.py"
12880a01d76fSMarc-André Lureau        ;;
128984ec0c24SPaolo Bonzini    *) meson=$(command -v "$meson") ;;
12900a01d76fSMarc-André Lureauesac
12910a01d76fSMarc-André Lureau
129209e93326SPaolo Bonzini# Probe for ninja
129348328880SPaolo Bonzini
129448328880SPaolo Bonziniif test -z "$ninja"; then
129548328880SPaolo Bonzini    for c in ninja ninja-build samu; do
129648328880SPaolo Bonzini        if has $c; then
129748328880SPaolo Bonzini            ninja=$(command -v "$c")
129848328880SPaolo Bonzini            break
129948328880SPaolo Bonzini        fi
130048328880SPaolo Bonzini    done
130109e93326SPaolo Bonzini    if test -z "$ninja"; then
130209e93326SPaolo Bonzini      error_exit "Cannot find Ninja"
130309e93326SPaolo Bonzini    fi
130448328880SPaolo Bonzinifi
1305a5665051SPaolo Bonzini
13069aae6e54SDaniel Henrique Barboza# Check that the C compiler works. Doing this here before testing
13079aae6e54SDaniel Henrique Barboza# the host CPU ensures that we had a valid CC to autodetect the
13089aae6e54SDaniel Henrique Barboza# $cpu var (and we should bail right here if that's not the case).
13099aae6e54SDaniel Henrique Barboza# It also allows the help message to be printed without a CC.
13109aae6e54SDaniel Henrique Barbozawrite_c_skeleton;
13119aae6e54SDaniel Henrique Barbozaif compile_object ; then
13129aae6e54SDaniel Henrique Barboza  : C compiler works ok
13139aae6e54SDaniel Henrique Barbozaelse
13149aae6e54SDaniel Henrique Barboza    error_exit "\"$cc\" either does not exist or does not work"
13159aae6e54SDaniel Henrique Barbozafi
13169aae6e54SDaniel Henrique Barbozaif ! compile_prog ; then
13179aae6e54SDaniel Henrique Barboza    error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
13189aae6e54SDaniel Henrique Barbozafi
13199aae6e54SDaniel Henrique Barboza
13209c83ffd8SPeter Maydell# Consult white-list to determine whether to enable werror
13219c83ffd8SPeter Maydell# by default.  Only enable by default for git builds
13229c83ffd8SPeter Maydellif test -z "$werror" ; then
13237d7dbf9dSDan Streetman    if test "$git_submodules_action" != "ignore" && \
1324e633a5c6SEric Blake        { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
13259c83ffd8SPeter Maydell        werror="yes"
13269c83ffd8SPeter Maydell    else
13279c83ffd8SPeter Maydell        werror="no"
13289c83ffd8SPeter Maydell    fi
13299c83ffd8SPeter Maydellfi
13309c83ffd8SPeter Maydell
1331975ff037SPaolo Bonziniif test "$targetos" = "bogus"; then
1332fb59dabdSPeter Maydell    # Now that we know that we're not printing the help and that
1333fb59dabdSPeter Maydell    # the compiler works (so the results of the check_defines we used
1334fb59dabdSPeter Maydell    # to identify the OS are reliable), if we didn't recognize the
1335fb59dabdSPeter Maydell    # host OS we should stop now.
1336951fedfcSPeter Maydell    error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1337fb59dabdSPeter Maydellfi
1338fb59dabdSPeter Maydell
1339efc6c070SThomas Huth# Check whether the compiler matches our minimum requirements:
1340efc6c070SThomas Huthcat > $TMPC << EOF
1341efc6c070SThomas Huth#if defined(__clang_major__) && defined(__clang_minor__)
1342efc6c070SThomas Huth# ifdef __apple_build_version__
13432a85a08cSDaniel P. Berrangé#  if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
13442a85a08cSDaniel P. Berrangé#   error You need at least XCode Clang v10.0 to compile QEMU
1345efc6c070SThomas Huth#  endif
1346efc6c070SThomas Huth# else
13472a85a08cSDaniel P. Berrangé#  if __clang_major__ < 6 || (__clang_major__ == 6 && __clang_minor__ < 0)
13482a85a08cSDaniel P. Berrangé#   error You need at least Clang v6.0 to compile QEMU
1349efc6c070SThomas Huth#  endif
1350efc6c070SThomas Huth# endif
1351efc6c070SThomas Huth#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
13523830df5fSnia# if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
13533830df5fSnia#  error You need at least GCC v7.4.0 to compile QEMU
1354efc6c070SThomas Huth# endif
1355efc6c070SThomas Huth#else
1356efc6c070SThomas Huth# error You either need GCC or Clang to compiler QEMU
1357efc6c070SThomas Huth#endif
1358efc6c070SThomas Huthint main (void) { return 0; }
1359efc6c070SThomas HuthEOF
1360efc6c070SThomas Huthif ! compile_prog "" "" ; then
13613830df5fSnia    error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
1362efc6c070SThomas Huthfi
1363efc6c070SThomas Huth
136400849b92SRichard Henderson# Accumulate -Wfoo and -Wno-bar separately.
136500849b92SRichard Henderson# We will list all of the enable flags first, and the disable flags second.
136600849b92SRichard Henderson# Note that we do not add -Werror, because that would enable it for all
136700849b92SRichard Henderson# configure tests. If a configure test failed due to -Werror this would
136800849b92SRichard Henderson# just silently disable some features, so it's too error prone.
136900849b92SRichard Henderson
137000849b92SRichard Hendersonwarn_flags=
137100849b92SRichard Hendersonadd_to warn_flags -Wold-style-declaration
137200849b92SRichard Hendersonadd_to warn_flags -Wold-style-definition
137300849b92SRichard Hendersonadd_to warn_flags -Wtype-limits
137400849b92SRichard Hendersonadd_to warn_flags -Wformat-security
137500849b92SRichard Hendersonadd_to warn_flags -Wformat-y2k
137600849b92SRichard Hendersonadd_to warn_flags -Winit-self
137700849b92SRichard Hendersonadd_to warn_flags -Wignored-qualifiers
137800849b92SRichard Hendersonadd_to warn_flags -Wempty-body
137900849b92SRichard Hendersonadd_to warn_flags -Wnested-externs
138000849b92SRichard Hendersonadd_to warn_flags -Wendif-labels
138100849b92SRichard Hendersonadd_to warn_flags -Wexpansion-to-defined
13820a2ebce9SThomas Huthadd_to warn_flags -Wimplicit-fallthrough=2
138300849b92SRichard Henderson
138400849b92SRichard Hendersonnowarn_flags=
138500849b92SRichard Hendersonadd_to nowarn_flags -Wno-initializer-overrides
138600849b92SRichard Hendersonadd_to nowarn_flags -Wno-missing-include-dirs
138700849b92SRichard Hendersonadd_to nowarn_flags -Wno-shift-negative-value
138800849b92SRichard Hendersonadd_to nowarn_flags -Wno-string-plus-int
138900849b92SRichard Hendersonadd_to nowarn_flags -Wno-typedef-redefinition
1390aabab967SRichard Hendersonadd_to nowarn_flags -Wno-tautological-type-limit-compare
1391bac8d222SRichard Hendersonadd_to nowarn_flags -Wno-psabi
139200849b92SRichard Henderson
139300849b92SRichard Hendersongcc_flags="$warn_flags $nowarn_flags"
139493b25869SJohn Snow
139593b25869SJohn Snowcc_has_warning_flag() {
139693b25869SJohn Snow    write_c_skeleton;
139793b25869SJohn Snow
1398a1d29d6cSPeter Maydell    # Use the positive sense of the flag when testing for -Wno-wombat
1399a1d29d6cSPeter Maydell    # support (gcc will happily accept the -Wno- form of unknown
1400a1d29d6cSPeter Maydell    # warning options).
140193b25869SJohn Snow    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
140293b25869SJohn Snow    compile_prog "-Werror $optflag" ""
140393b25869SJohn Snow}
140493b25869SJohn Snow
14054cb37d11SPhilippe Mathieu-Daudéobjcc_has_warning_flag() {
14064cb37d11SPhilippe Mathieu-Daudé    cat > $TMPM <<EOF
14074cb37d11SPhilippe Mathieu-Daudéint main(void) { return 0; }
14084cb37d11SPhilippe Mathieu-DaudéEOF
14094cb37d11SPhilippe Mathieu-Daudé
14104cb37d11SPhilippe Mathieu-Daudé    # Use the positive sense of the flag when testing for -Wno-wombat
14114cb37d11SPhilippe Mathieu-Daudé    # support (gcc will happily accept the -Wno- form of unknown
14124cb37d11SPhilippe Mathieu-Daudé    # warning options).
14134cb37d11SPhilippe Mathieu-Daudé    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
14144cb37d11SPhilippe Mathieu-Daudé    do_objc -Werror $optflag \
14154cb37d11SPhilippe Mathieu-Daudé      $OBJCFLAGS $EXTRA_OBJCFLAGS $CONFIGURE_OBJCFLAGS $QEMU_OBJCFLAGS \
14164cb37d11SPhilippe Mathieu-Daudé      -o $TMPE $TMPM $QEMU_LDFLAGS
14174cb37d11SPhilippe Mathieu-Daudé}
14184cb37d11SPhilippe Mathieu-Daudé
141993b25869SJohn Snowfor flag in $gcc_flags; do
142093b25869SJohn Snow    if cc_has_warning_flag $flag ; then
14218d05095cSPaolo Bonzini        QEMU_CFLAGS="$QEMU_CFLAGS $flag"
14228d05095cSPaolo Bonzini    fi
14234cb37d11SPhilippe Mathieu-Daudé    if objcc_has_warning_flag $flag ; then
14244cb37d11SPhilippe Mathieu-Daudé        QEMU_OBJCFLAGS="$QEMU_OBJCFLAGS $flag"
14254cb37d11SPhilippe Mathieu-Daudé    fi
14268d05095cSPaolo Bonzinidone
14278d05095cSPaolo Bonzini
142863678e17SSteven Noonanif test "$stack_protector" != "no"; then
1429fccd35a0SRodrigo Rebello  cat > $TMPC << EOF
1430fccd35a0SRodrigo Rebelloint main(int argc, char *argv[])
1431fccd35a0SRodrigo Rebello{
1432fccd35a0SRodrigo Rebello    char arr[64], *p = arr, *c = argv[0];
1433fccd35a0SRodrigo Rebello    while (*c) {
1434fccd35a0SRodrigo Rebello        *p++ = *c++;
1435fccd35a0SRodrigo Rebello    }
1436fccd35a0SRodrigo Rebello    return 0;
1437fccd35a0SRodrigo Rebello}
1438fccd35a0SRodrigo RebelloEOF
143963678e17SSteven Noonan  gcc_flags="-fstack-protector-strong -fstack-protector-all"
14403b463a3fSMiroslav Rezanina  sp_on=0
144163678e17SSteven Noonan  for flag in $gcc_flags; do
1442590e5dd9SPeter Maydell    # We need to check both a compile and a link, since some compiler
1443590e5dd9SPeter Maydell    # setups fail only on a .c->.o compile and some only at link time
1444086d5f75SPaolo Bonzini    if compile_object "-Werror $flag" &&
1445590e5dd9SPeter Maydell       compile_prog "-Werror $flag" ""; then
144663678e17SSteven Noonan      QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1447db5adeaaSPaolo Bonzini      QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
14483b463a3fSMiroslav Rezanina      sp_on=1
144963678e17SSteven Noonan      break
145063678e17SSteven Noonan    fi
145163678e17SSteven Noonan  done
14523b463a3fSMiroslav Rezanina  if test "$stack_protector" = yes; then
14533b463a3fSMiroslav Rezanina    if test $sp_on = 0; then
14543b463a3fSMiroslav Rezanina      error_exit "Stack protector not supported"
14553b463a3fSMiroslav Rezanina    fi
14563b463a3fSMiroslav Rezanina  fi
145737746c5eSMarc-André Lureaufi
145837746c5eSMarc-André Lureau
145920bc94a2SPaolo Bonzini# Disable -Wmissing-braces on older compilers that warn even for
146020bc94a2SPaolo Bonzini# the "universal" C zero initializer {0}.
146120bc94a2SPaolo Bonzinicat > $TMPC << EOF
146220bc94a2SPaolo Bonzinistruct {
146320bc94a2SPaolo Bonzini  int a[2];
146420bc94a2SPaolo Bonzini} x = {0};
146520bc94a2SPaolo BonziniEOF
146620bc94a2SPaolo Bonziniif compile_object "-Werror" "" ; then
146720bc94a2SPaolo Bonzini  :
146820bc94a2SPaolo Bonzinielse
146920bc94a2SPaolo Bonzini  QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
147020bc94a2SPaolo Bonzinifi
147120bc94a2SPaolo Bonzini
147221e709aaSMarc-André Lureau# Our module code doesn't support Windows
147321e709aaSMarc-André Lureauif test "$modules" = "yes" && test "$mingw32" = "yes" ; then
147421e709aaSMarc-André Lureau  error_exit "Modules are not available for Windows"
147521e709aaSMarc-André Lureaufi
147621e709aaSMarc-André Lureau
14775f2453acSAlex Bennée# Static linking is not possible with plugins, modules or PIE
147840d6444eSAvi Kivityif test "$static" = "yes" ; then
1479aa0d1f44SPaolo Bonzini  if test "$modules" = "yes" ; then
1480aa0d1f44SPaolo Bonzini    error_exit "static and modules are mutually incompatible"
1481aa0d1f44SPaolo Bonzini  fi
14825f2453acSAlex Bennée  if test "$plugins" = "yes"; then
14835f2453acSAlex Bennée    error_exit "static and plugins are mutually incompatible"
1484ba4dd2aaSAlex Bennée  else
1485ba4dd2aaSAlex Bennée    plugins="no"
14865f2453acSAlex Bennée  fi
148740d6444eSAvi Kivityfi
148837650689SPaolo Bonzinitest "$plugins" = "" && plugins=yes
148940d6444eSAvi Kivity
149040d6444eSAvi Kivitycat > $TMPC << EOF
149121d4a791SAvi Kivity
149221d4a791SAvi Kivity#ifdef __linux__
149321d4a791SAvi Kivity#  define THREAD __thread
149421d4a791SAvi Kivity#else
149521d4a791SAvi Kivity#  define THREAD
149621d4a791SAvi Kivity#endif
149721d4a791SAvi Kivitystatic THREAD int tls_var;
149821d4a791SAvi Kivityint main(void) { return tls_var; }
149940d6444eSAvi KivityEOF
1500b2634124SRichard Henderson
1501ffd205efSJessica Clarke# Check we support -fno-pie and -no-pie first; we will need the former for
1502ffd205efSJessica Clarke# building ROMs, and both for everything if --disable-pie is passed.
1503412aeacdSAlex Bennéeif compile_prog "-Werror -fno-pie" "-no-pie"; then
1504412aeacdSAlex Bennée  CFLAGS_NOPIE="-fno-pie"
1505ffd205efSJessica Clarke  LDFLAGS_NOPIE="-no-pie"
1506412aeacdSAlex Bennéefi
1507412aeacdSAlex Bennée
150812781462SRichard Hendersonif test "$static" = "yes"; then
1509eca7a8e6SRichard Henderson  if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
15105770e8afSPaolo Bonzini    CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
151112781462SRichard Henderson    QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
151212781462SRichard Henderson    pie="yes"
151312781462SRichard Henderson  elif test "$pie" = "yes"; then
151412781462SRichard Henderson    error_exit "-static-pie not available due to missing toolchain support"
151512781462SRichard Henderson  else
151612781462SRichard Henderson    QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
151712781462SRichard Henderson    pie="no"
151812781462SRichard Henderson  fi
151912781462SRichard Hendersonelif test "$pie" = "no"; then
15205770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="$CFLAGS_NOPIE $CONFIGURE_CFLAGS"
1521ffd205efSJessica Clarke  CONFIGURE_LDFLAGS="$LDFLAGS_NOPIE $CONFIGURE_LDFLAGS"
1522eca7a8e6SRichard Hendersonelif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
15235770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
15245770e8afSPaolo Bonzini  CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
152540d6444eSAvi Kivity  pie="yes"
15262c674109SRichard Hendersonelif test "$pie" = "yes"; then
152776ad07a4SPeter Maydell  error_exit "PIE not available due to missing toolchain support"
152840d6444eSAvi Kivityelse
152940d6444eSAvi Kivity  echo "Disabling PIE due to missing toolchain support"
153040d6444eSAvi Kivity  pie="no"
153140d6444eSAvi Kivityfi
153240d6444eSAvi Kivity
1533e6cbd751SRichard Henderson# Detect support for PT_GNU_RELRO + DT_BIND_NOW.
1534e6cbd751SRichard Henderson# The combination is known as "full relro", because .got.plt is read-only too.
1535e6cbd751SRichard Hendersonif compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1536e6cbd751SRichard Henderson  QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
1537e6cbd751SRichard Hendersonfi
1538e6cbd751SRichard Henderson
153909dada40SPaolo Bonzini##########################################
154009dada40SPaolo Bonzini# __sync_fetch_and_and requires at least -march=i486. Many toolchains
154109dada40SPaolo Bonzini# use i686 as default anyway, but for those that don't, an explicit
154209dada40SPaolo Bonzini# specification is necessary
154309dada40SPaolo Bonzini
154409dada40SPaolo Bonziniif test "$cpu" = "i386"; then
154509dada40SPaolo Bonzini  cat > $TMPC << EOF
154609dada40SPaolo Bonzinistatic int sfaa(int *ptr)
154709dada40SPaolo Bonzini{
154809dada40SPaolo Bonzini  return __sync_fetch_and_and(ptr, 0);
154909dada40SPaolo Bonzini}
155009dada40SPaolo Bonzini
155109dada40SPaolo Bonziniint main(void)
155209dada40SPaolo Bonzini{
155309dada40SPaolo Bonzini  int val = 42;
15541405b629SStefan Weil  val = __sync_val_compare_and_swap(&val, 0, 1);
155509dada40SPaolo Bonzini  sfaa(&val);
155609dada40SPaolo Bonzini  return val;
155709dada40SPaolo Bonzini}
155809dada40SPaolo BonziniEOF
155909dada40SPaolo Bonzini  if ! compile_prog "" "" ; then
156009dada40SPaolo Bonzini    QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
156109dada40SPaolo Bonzini  fi
156209dada40SPaolo Bonzinifi
156309dada40SPaolo Bonzini
156456267b62SPhilippe Mathieu-Daudéif test "$tcg" = "enabled"; then
156556267b62SPhilippe Mathieu-Daudé    git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
156656267b62SPhilippe Mathieu-Daudé    git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
156756267b62SPhilippe Mathieu-Daudéfi
156856267b62SPhilippe Mathieu-Daudé
1569afb63ebdSStefan Weilif test -z "${target_list+xxx}" ; then
1570fdb75aefSPaolo Bonzini    default_targets=yes
1571d880a3baSPaolo Bonzini    for target in $default_target_list; do
1572d880a3baSPaolo Bonzini        target_list="$target_list $target"
1573d880a3baSPaolo Bonzini    done
1574d880a3baSPaolo Bonzini    target_list="${target_list# }"
1575121afa9eSAnthony Liguorielse
1576fdb75aefSPaolo Bonzini    default_targets=no
157789138857SStefan Weil    target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1578d880a3baSPaolo Bonzini    for target in $target_list; do
157925b48338SPeter Maydell        # Check that we recognised the target name; this allows a more
158025b48338SPeter Maydell        # friendly error message than if we let it fall through.
158125b48338SPeter Maydell        case " $default_target_list " in
158225b48338SPeter Maydell            *" $target "*)
158325b48338SPeter Maydell                ;;
158425b48338SPeter Maydell            *)
158525b48338SPeter Maydell                error_exit "Unknown target name '$target'"
158625b48338SPeter Maydell                ;;
158725b48338SPeter Maydell        esac
158825b48338SPeter Maydell    done
1589d880a3baSPaolo Bonzinifi
159025b48338SPeter Maydell
1591f55fe278SPaolo Bonzini# see if system emulation was really requested
1592f55fe278SPaolo Bonzinicase " $target_list " in
1593f55fe278SPaolo Bonzini  *"-softmmu "*) softmmu=yes
1594f55fe278SPaolo Bonzini  ;;
1595f55fe278SPaolo Bonzini  *) softmmu=no
1596f55fe278SPaolo Bonzini  ;;
1597f55fe278SPaolo Bonziniesac
15985327cf48Sbellard
1599249247c9SJuan Quintelafeature_not_found() {
1600249247c9SJuan Quintela  feature=$1
160121684af0SStewart Smith  remedy=$2
1602249247c9SJuan Quintela
160376ad07a4SPeter Maydell  error_exit "User requested feature $feature" \
160421684af0SStewart Smith      "configure was not able to find it." \
160521684af0SStewart Smith      "$remedy"
1606249247c9SJuan Quintela}
1607249247c9SJuan Quintela
16087d13299dSbellard# ---
16097d13299dSbellard# big/little endian test
16107d13299dSbellardcat > $TMPC << EOF
1611659eb157SThomas Huth#include <stdio.h>
161261cc919fSMike Frysingershort big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
161361cc919fSMike Frysingershort little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
1614659eb157SThomas Huthint main(int argc, char *argv[])
1615659eb157SThomas Huth{
1616659eb157SThomas Huth    return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
16177d13299dSbellard}
16187d13299dSbellardEOF
16197d13299dSbellard
1620659eb157SThomas Huthif compile_prog ; then
1621659eb157SThomas Huth    if strings -a $TMPE | grep -q BiGeNdIaN ; then
162261cc919fSMike Frysinger        bigendian="yes"
1623659eb157SThomas Huth    elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
162461cc919fSMike Frysinger        bigendian="no"
16257d13299dSbellard    else
16267d13299dSbellard        echo big/little test failed
1627659eb157SThomas Huth        exit 1
16287d13299dSbellard    fi
16297d13299dSbellardelse
163061cc919fSMike Frysinger    echo big/little test failed
1631659eb157SThomas Huth    exit 1
16327d13299dSbellardfi
16337d13299dSbellard
1634299e6f19SPaolo Bonzini#########################################
1635299e6f19SPaolo Bonzini# vhost interdependencies and host support
1636299e6f19SPaolo Bonzini
1637299e6f19SPaolo Bonzini# vhost backends
1638eb9baecdSSergio Lopezif test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then
1639eb9baecdSSergio Lopez  error_exit "vhost-user is not available on Windows"
1640299e6f19SPaolo Bonzinifi
1641108a6481SCindy Lutest "$vhost_vdpa" = "" && vhost_vdpa=$linux
1642108a6481SCindy Luif test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
1643108a6481SCindy Lu  error_exit "vhost-vdpa is only available on Linux"
1644108a6481SCindy Lufi
1645299e6f19SPaolo Bonzinitest "$vhost_kernel" = "" && vhost_kernel=$linux
1646299e6f19SPaolo Bonziniif test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
1647299e6f19SPaolo Bonzini  error_exit "vhost-kernel is only available on Linux"
1648299e6f19SPaolo Bonzinifi
1649299e6f19SPaolo Bonzini
1650299e6f19SPaolo Bonzini# vhost-kernel devices
1651299e6f19SPaolo Bonzinitest "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
1652299e6f19SPaolo Bonziniif test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
1653299e6f19SPaolo Bonzini  error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
1654299e6f19SPaolo Bonzinifi
1655299e6f19SPaolo Bonzinitest "$vhost_vsock" = "" && vhost_vsock=$vhost_kernel
1656299e6f19SPaolo Bonziniif test "$vhost_vsock" = "yes" && test "$vhost_kernel" != "yes"; then
1657299e6f19SPaolo Bonzini  error_exit "--enable-vhost-vsock requires --enable-vhost-kernel"
1658299e6f19SPaolo Bonzinifi
1659299e6f19SPaolo Bonzini
1660299e6f19SPaolo Bonzini# vhost-user backends
1661299e6f19SPaolo Bonzinitest "$vhost_net_user" = "" && vhost_net_user=$vhost_user
1662299e6f19SPaolo Bonziniif test "$vhost_net_user" = "yes" && test "$vhost_user" = "no"; then
1663299e6f19SPaolo Bonzini  error_exit "--enable-vhost-net-user requires --enable-vhost-user"
1664299e6f19SPaolo Bonzinifi
1665299e6f19SPaolo Bonzinitest "$vhost_crypto" = "" && vhost_crypto=$vhost_user
1666299e6f19SPaolo Bonziniif test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
1667299e6f19SPaolo Bonzini  error_exit "--enable-vhost-crypto requires --enable-vhost-user"
1668299e6f19SPaolo Bonzinifi
166998fc1adaSDr. David Alan Gilberttest "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
167098fc1adaSDr. David Alan Gilbertif test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
167198fc1adaSDr. David Alan Gilbert  error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
167298fc1adaSDr. David Alan Gilbertfi
1673108a6481SCindy Lu#vhost-vdpa backends
1674108a6481SCindy Lutest "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa
1675108a6481SCindy Luif test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then
1676108a6481SCindy Lu  error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa"
1677108a6481SCindy Lufi
1678299e6f19SPaolo Bonzini
167940bc0ca9SLaurent Vivier# OR the vhost-kernel, vhost-vdpa and vhost-user values for simplicity
1680299e6f19SPaolo Bonziniif test "$vhost_net" = ""; then
1681299e6f19SPaolo Bonzini  test "$vhost_net_user" = "yes" && vhost_net=yes
168240bc0ca9SLaurent Vivier  test "$vhost_net_vdpa" = "yes" && vhost_net=yes
1683299e6f19SPaolo Bonzini  test "$vhost_kernel" = "yes" && vhost_net=yes
1684299e6f19SPaolo Bonzinifi
1685299e6f19SPaolo Bonzini
1686015a33bdSGonglei##########################################
1687779ab5e3SStefan Weil# pkg-config probe
1688779ab5e3SStefan Weil
1689779ab5e3SStefan Weilif ! has "$pkg_config_exe"; then
169076ad07a4SPeter Maydell  error_exit "pkg-config binary '$pkg_config_exe' not found"
1691779ab5e3SStefan Weilfi
1692779ab5e3SStefan Weil
1693779ab5e3SStefan Weil##########################################
1694e18df141SAnthony Liguori# glib support probe
1695a52d28afSPaolo Bonzini
1696b4c6036fSDaniel P. Berrangéglib_req_ver=2.56
1697aa0d1f44SPaolo Bonziniglib_modules=gthread-2.0
1698aa0d1f44SPaolo Bonziniif test "$modules" = yes; then
1699a88afc64SGerd Hoffmann    glib_modules="$glib_modules gmodule-export-2.0"
1700b906acacSPaolo Bonzinielif test "$plugins" = "yes"; then
1701b906acacSPaolo Bonzini    glib_modules="$glib_modules gmodule-no-export-2.0"
170254cb65d8SEmilio G. Cotafi
1703e26110cfSFam Zheng
1704aa0d1f44SPaolo Bonzinifor i in $glib_modules; do
1705e26110cfSFam Zheng    if $pkg_config --atleast-version=$glib_req_ver $i; then
170689138857SStefan Weil        glib_cflags=$($pkg_config --cflags $i)
170789138857SStefan Weil        glib_libs=$($pkg_config --libs $i)
1708e18df141SAnthony Liguori    else
1709e26110cfSFam Zheng        error_exit "glib-$glib_req_ver $i is required to compile QEMU"
1710e26110cfSFam Zheng    fi
1711e26110cfSFam Zhengdone
1712e26110cfSFam Zheng
1713215b0c2fSPaolo Bonzini# This workaround is required due to a bug in pkg-config file for glib as it
1714215b0c2fSPaolo Bonzini# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
1715215b0c2fSPaolo Bonzini
1716215b0c2fSPaolo Bonziniif test "$static" = yes && test "$mingw32" = yes; then
1717215b0c2fSPaolo Bonzini    glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
1718215b0c2fSPaolo Bonzinifi
1719215b0c2fSPaolo Bonzini
1720977a82abSDaniel P. Berrange# Sanity check that the current size_t matches the
1721977a82abSDaniel P. Berrange# size that glib thinks it should be. This catches
1722977a82abSDaniel P. Berrange# problems on multi-arch where people try to build
1723977a82abSDaniel P. Berrange# 32-bit QEMU while pointing at 64-bit glib headers
1724977a82abSDaniel P. Berrangecat > $TMPC <<EOF
1725977a82abSDaniel P. Berrange#include <glib.h>
1726977a82abSDaniel P. Berrange#include <unistd.h>
1727977a82abSDaniel P. Berrange
1728977a82abSDaniel P. Berrange#define QEMU_BUILD_BUG_ON(x) \
1729977a82abSDaniel P. Berrange  typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
1730977a82abSDaniel P. Berrange
1731977a82abSDaniel P. Berrangeint main(void) {
1732977a82abSDaniel P. Berrange   QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
1733977a82abSDaniel P. Berrange   return 0;
1734977a82abSDaniel P. Berrange}
1735977a82abSDaniel P. BerrangeEOF
1736977a82abSDaniel P. Berrange
1737215b0c2fSPaolo Bonziniif ! compile_prog "$glib_cflags" "$glib_libs" ; then
1738977a82abSDaniel P. Berrange    error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
1739977a82abSDaniel P. Berrange               "You probably need to set PKG_CONFIG_LIBDIR"\
1740977a82abSDaniel P. Berrange	       "to point to the right pkg-config files for your"\
1741977a82abSDaniel P. Berrange	       "build target"
1742977a82abSDaniel P. Berrangefi
1743977a82abSDaniel P. Berrange
17449bda600bSEric Blake# Silence clang warnings triggered by glib < 2.57.2
17459bda600bSEric Blakecat > $TMPC << EOF
17469bda600bSEric Blake#include <glib.h>
17479bda600bSEric Blaketypedef struct Foo {
17489bda600bSEric Blake    int i;
17499bda600bSEric Blake} Foo;
17509bda600bSEric Blakestatic void foo_free(Foo *f)
17519bda600bSEric Blake{
17529bda600bSEric Blake    g_free(f);
17539bda600bSEric Blake}
1754e0e7fe07SMarc-André LureauG_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
17559bda600bSEric Blakeint main(void) { return 0; }
17569bda600bSEric BlakeEOF
17579bda600bSEric Blakeif ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
17589bda600bSEric Blake    if cc_has_warning_flag "-Wno-unused-function"; then
17599bda600bSEric Blake        glib_cflags="$glib_cflags -Wno-unused-function"
17605770e8afSPaolo Bonzini        CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
17619bda600bSEric Blake    fi
17629bda600bSEric Blakefi
17639bda600bSEric Blake
1764e26110cfSFam Zheng##########################################
1765e26110cfSFam Zheng# SHA command probe for modules
1766e26110cfSFam Zhengif test "$modules" = yes; then
1767e26110cfSFam Zheng    shacmd_probe="sha1sum sha1 shasum"
1768e26110cfSFam Zheng    for c in $shacmd_probe; do
17698ccefb91SFam Zheng        if has $c; then
1770e26110cfSFam Zheng            shacmd="$c"
1771e26110cfSFam Zheng            break
1772e26110cfSFam Zheng        fi
1773e26110cfSFam Zheng    done
1774e26110cfSFam Zheng    if test "$shacmd" = ""; then
1775e26110cfSFam Zheng        error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
1776e26110cfSFam Zheng    fi
1777e18df141SAnthony Liguorifi
1778e18df141SAnthony Liguori
1779e18df141SAnthony Liguori##########################################
1780f652e6afSaurel32# fdt probe
1781e169e1e1SPeter Maydell
1782fbb4121dSPaolo Bonzinicase "$fdt" in
1783fbb4121dSPaolo Bonzini  auto | enabled | internal)
1784fbb4121dSPaolo Bonzini    # Simpler to always update submodule, even if not needed.
1785aef45d51SDaniel P. Berrange    git_submodules="${git_submodules} dtc"
1786fbb4121dSPaolo Bonzini    ;;
1787fbb4121dSPaolo Bonziniesac
1788f652e6afSaurel32
178920ff075bSMichael Walle##########################################
17908ca80760SRichard Henderson# capstone
17918ca80760SRichard Henderson
1792e219c499SRichard Hendersoncase "$capstone" in
17938b18cdbfSRichard Henderson  auto | enabled | internal)
17948b18cdbfSRichard Henderson    # Simpler to always update submodule, even if not needed.
1795e219c499SRichard Henderson    git_submodules="${git_submodules} capstone"
1796e219c499SRichard Henderson    ;;
1797e219c499SRichard Hendersonesac
17988ca80760SRichard Henderson
17998ca80760SRichard Henderson##########################################
1800519175a2SAlex Barcelo# check and set a backend for coroutine
1801d0e2fce5SAneesh Kumar K.V
18027c2acc70SPeter Maydell# We prefer ucontext, but it's not always possible. The fallback
180333c53c54SDaniel P. Berrange# is sigcontext. On Windows the only valid backend is the Windows
180433c53c54SDaniel P. Berrange# specific one.
18057c2acc70SPeter Maydell
18067c2acc70SPeter Maydellucontext_works=no
1807d0e2fce5SAneesh Kumar K.Vif test "$darwin" != "yes"; then
1808d0e2fce5SAneesh Kumar K.V  cat > $TMPC << EOF
1809d0e2fce5SAneesh Kumar K.V#include <ucontext.h>
1810cdf84806SPeter Maydell#ifdef __stub_makecontext
1811cdf84806SPeter Maydell#error Ignoring glibc stub makecontext which will always fail
1812cdf84806SPeter Maydell#endif
181375cafad7SStefan Weilint main(void) { makecontext(0, 0, 0); return 0; }
1814d0e2fce5SAneesh Kumar K.VEOF
1815d0e2fce5SAneesh Kumar K.V  if compile_prog "" "" ; then
18167c2acc70SPeter Maydell    ucontext_works=yes
1817d0e2fce5SAneesh Kumar K.V  fi
1818519175a2SAlex Barcelofi
18197c2acc70SPeter Maydell
18207c2acc70SPeter Maydellif test "$coroutine" = ""; then
18217c2acc70SPeter Maydell  if test "$mingw32" = "yes"; then
18227c2acc70SPeter Maydell    coroutine=win32
18237c2acc70SPeter Maydell  elif test "$ucontext_works" = "yes"; then
18247c2acc70SPeter Maydell    coroutine=ucontext
1825519175a2SAlex Barcelo  else
18267c2acc70SPeter Maydell    coroutine=sigaltstack
18277c2acc70SPeter Maydell  fi
18287c2acc70SPeter Maydellelse
18297c2acc70SPeter Maydell  case $coroutine in
18307c2acc70SPeter Maydell  windows)
18317c2acc70SPeter Maydell    if test "$mingw32" != "yes"; then
18327c2acc70SPeter Maydell      error_exit "'windows' coroutine backend only valid for Windows"
18337c2acc70SPeter Maydell    fi
18347c2acc70SPeter Maydell    # Unfortunately the user visible backend name doesn't match the
18357c2acc70SPeter Maydell    # coroutine-*.c filename for this case, so we have to adjust it here.
18367c2acc70SPeter Maydell    coroutine=win32
18377c2acc70SPeter Maydell    ;;
18387c2acc70SPeter Maydell  ucontext)
18397c2acc70SPeter Maydell    if test "$ucontext_works" != "yes"; then
18407c2acc70SPeter Maydell      feature_not_found "ucontext"
18417c2acc70SPeter Maydell    fi
18427c2acc70SPeter Maydell    ;;
184333c53c54SDaniel P. Berrange  sigaltstack)
18447c2acc70SPeter Maydell    if test "$mingw32" = "yes"; then
18457c2acc70SPeter Maydell      error_exit "only the 'windows' coroutine backend is valid for Windows"
18467c2acc70SPeter Maydell    fi
18477c2acc70SPeter Maydell    ;;
18487c2acc70SPeter Maydell  *)
184976ad07a4SPeter Maydell    error_exit "unknown coroutine backend $coroutine"
18507c2acc70SPeter Maydell    ;;
18517c2acc70SPeter Maydell  esac
1852d0e2fce5SAneesh Kumar K.Vfi
1853d0e2fce5SAneesh Kumar K.V
18541e4f6065SDaniele Buono##################################################
18551e4f6065SDaniele Buono# SafeStack
18561e4f6065SDaniele Buono
18571e4f6065SDaniele Buono
18581e4f6065SDaniele Buonoif test "$safe_stack" = "yes"; then
18591e4f6065SDaniele Buonocat > $TMPC << EOF
18601e4f6065SDaniele Buonoint main(int argc, char *argv[])
18611e4f6065SDaniele Buono{
18621e4f6065SDaniele Buono#if ! __has_feature(safe_stack)
18631e4f6065SDaniele Buono#error SafeStack Disabled
18641e4f6065SDaniele Buono#endif
18651e4f6065SDaniele Buono    return 0;
18661e4f6065SDaniele Buono}
18671e4f6065SDaniele BuonoEOF
18681e4f6065SDaniele Buono  flag="-fsanitize=safe-stack"
18691e4f6065SDaniele Buono  # Check that safe-stack is supported and enabled.
18701e4f6065SDaniele Buono  if compile_prog "-Werror $flag" "$flag"; then
18711e4f6065SDaniele Buono    # Flag needed both at compilation and at linking
18721e4f6065SDaniele Buono    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
18731e4f6065SDaniele Buono    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
18741e4f6065SDaniele Buono  else
18751e4f6065SDaniele Buono    error_exit "SafeStack not supported by your compiler"
18761e4f6065SDaniele Buono  fi
18771e4f6065SDaniele Buono  if test "$coroutine" != "ucontext"; then
18781e4f6065SDaniele Buono    error_exit "SafeStack is only supported by the coroutine backend ucontext"
18791e4f6065SDaniele Buono  fi
18801e4f6065SDaniele Buonoelse
18811e4f6065SDaniele Buonocat > $TMPC << EOF
18821e4f6065SDaniele Buonoint main(int argc, char *argv[])
18831e4f6065SDaniele Buono{
18841e4f6065SDaniele Buono#if defined(__has_feature)
18851e4f6065SDaniele Buono#if __has_feature(safe_stack)
18861e4f6065SDaniele Buono#error SafeStack Enabled
18871e4f6065SDaniele Buono#endif
18881e4f6065SDaniele Buono#endif
18891e4f6065SDaniele Buono    return 0;
18901e4f6065SDaniele Buono}
18911e4f6065SDaniele BuonoEOF
18921e4f6065SDaniele Buonoif test "$safe_stack" = "no"; then
18931e4f6065SDaniele Buono  # Make sure that safe-stack is disabled
18941e4f6065SDaniele Buono  if ! compile_prog "-Werror" ""; then
18951e4f6065SDaniele Buono    # SafeStack was already enabled, try to explicitly remove the feature
18961e4f6065SDaniele Buono    flag="-fno-sanitize=safe-stack"
18971e4f6065SDaniele Buono    if ! compile_prog "-Werror $flag" "$flag"; then
18981e4f6065SDaniele Buono      error_exit "Configure cannot disable SafeStack"
18991e4f6065SDaniele Buono    fi
19001e4f6065SDaniele Buono    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
19011e4f6065SDaniele Buono    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
19021e4f6065SDaniele Buono  fi
19031e4f6065SDaniele Buonoelse # "$safe_stack" = ""
19041e4f6065SDaniele Buono  # Set safe_stack to yes or no based on pre-existing flags
19051e4f6065SDaniele Buono  if compile_prog "-Werror" ""; then
19061e4f6065SDaniele Buono    safe_stack="no"
19071e4f6065SDaniele Buono  else
19081e4f6065SDaniele Buono    safe_stack="yes"
19091e4f6065SDaniele Buono    if test "$coroutine" != "ucontext"; then
19101e4f6065SDaniele Buono      error_exit "SafeStack is only supported by the coroutine backend ucontext"
19111e4f6065SDaniele Buono    fi
19121e4f6065SDaniele Buono  fi
19131e4f6065SDaniele Buonofi
19141e4f6065SDaniele Buonofi
19157d992e4dSPeter Lieven
191676a347e1SRichard Henderson########################################
1917fd0e6053SJohn Snow# check if ccache is interfering with
1918fd0e6053SJohn Snow# semantic analysis of macros
1919fd0e6053SJohn Snow
19205e4dfd3dSJohn Snowunset CCACHE_CPP2
1921fd0e6053SJohn Snowccache_cpp2=no
1922fd0e6053SJohn Snowcat > $TMPC << EOF
1923fd0e6053SJohn Snowstatic const int Z = 1;
1924fd0e6053SJohn Snow#define fn() ({ Z; })
1925fd0e6053SJohn Snow#define TAUT(X) ((X) == Z)
1926fd0e6053SJohn Snow#define PAREN(X, Y) (X == Y)
1927fd0e6053SJohn Snow#define ID(X) (X)
1928fd0e6053SJohn Snowint main(int argc, char *argv[])
1929fd0e6053SJohn Snow{
1930fd0e6053SJohn Snow    int x = 0, y = 0;
1931fd0e6053SJohn Snow    x = ID(x);
1932fd0e6053SJohn Snow    x = fn();
1933fd0e6053SJohn Snow    fn();
1934fd0e6053SJohn Snow    if (PAREN(x, y)) return 0;
1935fd0e6053SJohn Snow    if (TAUT(Z)) return 0;
1936fd0e6053SJohn Snow    return 0;
1937fd0e6053SJohn Snow}
1938fd0e6053SJohn SnowEOF
1939fd0e6053SJohn Snow
1940fd0e6053SJohn Snowif ! compile_object "-Werror"; then
1941fd0e6053SJohn Snow    ccache_cpp2=yes
1942fd0e6053SJohn Snowfi
1943fd0e6053SJohn Snow
1944b553a042SJohn Snow#################################################
1945b553a042SJohn Snow# clang does not support glibc + FORTIFY_SOURCE.
1946b553a042SJohn Snow
1947b553a042SJohn Snowif test "$fortify_source" != "no"; then
1948b553a042SJohn Snow  if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
1949b553a042SJohn Snow    fortify_source="no";
1950e189091fSPeter Maydell  elif test -n "$cxx" && has $cxx &&
1951cfcc7c14SJohn Snow       echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
1952b553a042SJohn Snow    fortify_source="no";
1953b553a042SJohn Snow  else
1954b553a042SJohn Snow    fortify_source="yes"
1955b553a042SJohn Snow  fi
1956b553a042SJohn Snowfi
1957b553a042SJohn Snow
1958d2042378SAneesh Kumar K.V##########################################
1959247724cbSMarc-André Lureau# checks for sanitizers
1960247724cbSMarc-André Lureau
1961247724cbSMarc-André Lureauhave_asan=no
1962247724cbSMarc-André Lureauhave_ubsan=no
1963d83414e1SMarc-André Lureauhave_asan_iface_h=no
1964d83414e1SMarc-André Lureauhave_asan_iface_fiber=no
1965247724cbSMarc-André Lureau
1966247724cbSMarc-André Lureauif test "$sanitizers" = "yes" ; then
1967b9f44da2SMarc-André Lureau  write_c_skeleton
1968247724cbSMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
1969247724cbSMarc-André Lureau      have_asan=yes
1970247724cbSMarc-André Lureau  fi
1971b9f44da2SMarc-André Lureau
1972b9f44da2SMarc-André Lureau  # we could use a simple skeleton for flags checks, but this also
1973b9f44da2SMarc-André Lureau  # detect the static linking issue of ubsan, see also:
1974b9f44da2SMarc-André Lureau  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
1975b9f44da2SMarc-André Lureau  cat > $TMPC << EOF
1976b9f44da2SMarc-André Lureau#include <stdlib.h>
1977b9f44da2SMarc-André Lureauint main(void) {
1978b9f44da2SMarc-André Lureau    void *tmp = malloc(10);
1979f2dfe54cSLeonid Bloch    if (tmp != NULL) {
1980b9f44da2SMarc-André Lureau        return *(int *)(tmp + 2);
1981b9f44da2SMarc-André Lureau    }
1982d1abf3fcSOlaf Hering    return 1;
1983f2dfe54cSLeonid Bloch}
1984b9f44da2SMarc-André LureauEOF
1985247724cbSMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
1986247724cbSMarc-André Lureau      have_ubsan=yes
1987247724cbSMarc-André Lureau  fi
1988d83414e1SMarc-André Lureau
1989d83414e1SMarc-André Lureau  if check_include "sanitizer/asan_interface.h" ; then
1990d83414e1SMarc-André Lureau      have_asan_iface_h=yes
1991d83414e1SMarc-André Lureau  fi
1992d83414e1SMarc-André Lureau
1993d83414e1SMarc-André Lureau  cat > $TMPC << EOF
1994d83414e1SMarc-André Lureau#include <sanitizer/asan_interface.h>
1995d83414e1SMarc-André Lureauint main(void) {
1996d83414e1SMarc-André Lureau  __sanitizer_start_switch_fiber(0, 0, 0);
1997d83414e1SMarc-André Lureau  return 0;
1998d83414e1SMarc-André Lureau}
1999d83414e1SMarc-André LureauEOF
2000d83414e1SMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
2001d83414e1SMarc-André Lureau      have_asan_iface_fiber=yes
2002d83414e1SMarc-André Lureau  fi
2003247724cbSMarc-André Lureaufi
2004247724cbSMarc-André Lureau
20050aebab04SLingfeng Yang# Thread sanitizer is, for now, much noisier than the other sanitizers;
20060aebab04SLingfeng Yang# keep it separate until that is not the case.
20070aebab04SLingfeng Yangif test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
20080aebab04SLingfeng Yang  error_exit "TSAN is not supported with other sanitiziers."
20090aebab04SLingfeng Yangfi
20100aebab04SLingfeng Yanghave_tsan=no
20110aebab04SLingfeng Yanghave_tsan_iface_fiber=no
20120aebab04SLingfeng Yangif test "$tsan" = "yes" ; then
20130aebab04SLingfeng Yang  write_c_skeleton
20140aebab04SLingfeng Yang  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
20150aebab04SLingfeng Yang      have_tsan=yes
20160aebab04SLingfeng Yang  fi
20170aebab04SLingfeng Yang  cat > $TMPC << EOF
20180aebab04SLingfeng Yang#include <sanitizer/tsan_interface.h>
20190aebab04SLingfeng Yangint main(void) {
20200aebab04SLingfeng Yang  __tsan_create_fiber(0);
20210aebab04SLingfeng Yang  return 0;
20220aebab04SLingfeng Yang}
20230aebab04SLingfeng YangEOF
20240aebab04SLingfeng Yang  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
20250aebab04SLingfeng Yang      have_tsan_iface_fiber=yes
20260aebab04SLingfeng Yang  fi
20270aebab04SLingfeng Yangfi
20280aebab04SLingfeng Yang
2029adc28027SAlexander Bulekov##########################################
2030675b9b53SMarc-André Lureau# check for slirp
2031675b9b53SMarc-André Lureau
2032675b9b53SMarc-André Lureaucase "$slirp" in
20334d34a86bSPaolo Bonzini  auto | enabled | internal)
20344d34a86bSPaolo Bonzini    # Simpler to always update submodule, even if not needed.
20357c57bdd8SMarc-André Lureau    git_submodules="${git_submodules} slirp"
2036675b9b53SMarc-André Lureau    ;;
2037675b9b53SMarc-André Lureauesac
2038675b9b53SMarc-André Lureau
203954e7aac0SAlexey Krasikov##########################################
2040e86ecd4bSJuan Quintela# End of CC checks
2041e86ecd4bSJuan Quintela# After here, no more $cc or $ld runs
2042e86ecd4bSJuan Quintela
2043d83414e1SMarc-André Lureauwrite_c_skeleton
2044d83414e1SMarc-André Lureau
2045df42fa7dSPaolo Bonziniif test "$fortify_source" = "yes" ; then
2046086d5f75SPaolo Bonzini  QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
2047086d5f75SPaolo Bonzini  debug=no
2048086d5f75SPaolo Bonzinifi
2049086d5f75SPaolo Bonzini
2050086d5f75SPaolo Bonzinicase "$ARCH" in
2051086d5f75SPaolo Bonzinialpha)
2052086d5f75SPaolo Bonzini  # Ensure there's only a single GP
2053086d5f75SPaolo Bonzini  QEMU_CFLAGS="-msmall-data $QEMU_CFLAGS"
2054086d5f75SPaolo Bonzini;;
2055086d5f75SPaolo Bonziniesac
2056086d5f75SPaolo Bonzini
2057247724cbSMarc-André Lureauif test "$have_asan" = "yes"; then
2058db5adeaaSPaolo Bonzini  QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
2059db5adeaaSPaolo Bonzini  QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
2060d83414e1SMarc-André Lureau  if test "$have_asan_iface_h" = "no" ; then
2061d83414e1SMarc-André Lureau      echo "ASAN build enabled, but ASAN header missing." \
2062d83414e1SMarc-André Lureau           "Without code annotation, the report may be inferior."
2063d83414e1SMarc-André Lureau  elif test "$have_asan_iface_fiber" = "no" ; then
2064d83414e1SMarc-André Lureau      echo "ASAN build enabled, but ASAN header is too old." \
2065d83414e1SMarc-André Lureau           "Without code annotation, the report may be inferior."
2066d83414e1SMarc-André Lureau  fi
2067247724cbSMarc-André Lureaufi
20680aebab04SLingfeng Yangif test "$have_tsan" = "yes" ; then
20690aebab04SLingfeng Yang  if test "$have_tsan_iface_fiber" = "yes" ; then
20700aebab04SLingfeng Yang    QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
20710aebab04SLingfeng Yang    QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
20720aebab04SLingfeng Yang  else
20730aebab04SLingfeng Yang    error_exit "Cannot enable TSAN due to missing fiber annotation interface."
20740aebab04SLingfeng Yang  fi
20750aebab04SLingfeng Yangelif test "$tsan" = "yes" ; then
20760aebab04SLingfeng Yang  error_exit "Cannot enable TSAN due to missing sanitize thread interface."
20770aebab04SLingfeng Yangfi
2078247724cbSMarc-André Lureauif test "$have_ubsan" = "yes"; then
2079db5adeaaSPaolo Bonzini  QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
2080db5adeaaSPaolo Bonzini  QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
2081247724cbSMarc-André Lureaufi
2082247724cbSMarc-André Lureau
20836542aa9cSPeter Lieven##########################################
20843efac6ebSTomáš Golembiovský
20850aebab04SLingfeng Yang# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
20860aebab04SLingfeng Yangif test "$solaris" = "no" && test "$tsan" = "no"; then
2087e86ecd4bSJuan Quintela    if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
2088db5adeaaSPaolo Bonzini        QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
2089e86ecd4bSJuan Quintela    fi
2090e86ecd4bSJuan Quintelafi
2091e86ecd4bSJuan Quintela
2092952afb71SBlue Swirl# Use ASLR, no-SEH and DEP if available
2093952afb71SBlue Swirlif test "$mingw32" = "yes" ; then
2094cb8baa77SMark Cave-Ayland    flags="--no-seh --nxcompat"
2095cb8baa77SMark Cave-Ayland
2096cb8baa77SMark Cave-Ayland    # Disable ASLR for debug builds to allow debugging with gdb
2097cb8baa77SMark Cave-Ayland    if test "$debug" = "no" ; then
2098cb8baa77SMark Cave-Ayland        flags="--dynamicbase $flags"
2099cb8baa77SMark Cave-Ayland    fi
2100cb8baa77SMark Cave-Ayland
2101cb8baa77SMark Cave-Ayland    for flag in $flags; do
2102e9a3591fSChristian Borntraeger        if ld_has $flag ; then
2103db5adeaaSPaolo Bonzini            QEMU_LDFLAGS="-Wl,$flag $QEMU_LDFLAGS"
2104952afb71SBlue Swirl        fi
2105952afb71SBlue Swirl    done
2106952afb71SBlue Swirlfi
2107952afb71SBlue Swirl
2108b846ab7cSPaolo Bonzini# Guest agent Windows MSI package
21099d6bc27bSMichael Roth
21109d6bc27bSMichael Rothif test "$QEMU_GA_MANUFACTURER" = ""; then
21119d6bc27bSMichael Roth  QEMU_GA_MANUFACTURER=QEMU
21129d6bc27bSMichael Rothfi
21139d6bc27bSMichael Rothif test "$QEMU_GA_DISTRO" = ""; then
21149d6bc27bSMichael Roth  QEMU_GA_DISTRO=Linux
21159d6bc27bSMichael Rothfi
21169d6bc27bSMichael Rothif test "$QEMU_GA_VERSION" = ""; then
211789138857SStefan Weil    QEMU_GA_VERSION=$(cat $source_path/VERSION)
21189d6bc27bSMichael Rothfi
21199d6bc27bSMichael Roth
21206e444209SPaolo BonziniQEMU_GA_MSI_MINGW_BIN_PATH="$($pkg_config --variable=prefix glib-2.0)/bin"
21219d6bc27bSMichael Roth
2122ca35f780SPaolo Bonzini# Mac OS X ships with a broken assembler
2123ca35f780SPaolo Bonziniroms=
2124e633a5c6SEric Blakeif { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \
2125ba7c60c2SPaolo Bonzini        test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
2126ba7c60c2SPaolo Bonzini        test "$targetos" != "haiku" && test "$softmmu" = yes ; then
2127e57218b6SPeter Maydell    # Different host OS linkers have different ideas about the name of the ELF
2128c65d5e4eSBrad Smith    # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
2129c65d5e4eSBrad Smith    # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
2130c65d5e4eSBrad Smith    for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
2131e57218b6SPeter Maydell        if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
2132e57218b6SPeter Maydell            ld_i386_emulation="$emu"
2133ca35f780SPaolo Bonzini            roms="optionrom"
2134e57218b6SPeter Maydell            break
2135e57218b6SPeter Maydell        fi
2136e57218b6SPeter Maydell    done
2137ca35f780SPaolo Bonzinifi
2138ca35f780SPaolo Bonzini
21392e33c3f8SThomas Huth# Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
2140a5b2afd5SThomas Huth# or -march=z10 (which is the lowest architecture level that Clang supports)
21419933c305SChristian Borntraegerif test "$cpu" = "s390x" ; then
21422e33c3f8SThomas Huth  write_c_skeleton
2143a5b2afd5SThomas Huth  compile_prog "-march=z900" ""
2144a5b2afd5SThomas Huth  has_z900=$?
21453af448b3SThomas Huth  if [ $has_z900 = 0 ] || compile_object "-march=z10 -msoft-float -Werror"; then
2146a5b2afd5SThomas Huth    if [ $has_z900 != 0 ]; then
2147a5b2afd5SThomas Huth      echo "WARNING: Your compiler does not support the z900!"
2148a5b2afd5SThomas Huth      echo "         The s390-ccw bios will only work with guest CPUs >= z10."
2149a5b2afd5SThomas Huth    fi
21509933c305SChristian Borntraeger    roms="$roms s390-ccw"
21511ef6bfc2SPhilippe Mathieu-Daudé    # SLOF is required for building the s390-ccw firmware on s390x,
21521ef6bfc2SPhilippe Mathieu-Daudé    # since it is using the libnet code from SLOF for network booting.
21531ef6bfc2SPhilippe Mathieu-Daudé    git_submodules="${git_submodules} roms/SLOF"
21541ef6bfc2SPhilippe Mathieu-Daudé  fi
21559933c305SChristian Borntraegerfi
21569933c305SChristian Borntraeger
215711cde1c8SBruno Dominguez# Check that the C++ compiler exists and works with the C compiler.
215811cde1c8SBruno 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.
215911cde1c8SBruno Dominguezif has $cxx; then
216011cde1c8SBruno Dominguez    cat > $TMPC <<EOF
216111cde1c8SBruno Dominguezint c_function(void);
216211cde1c8SBruno Dominguezint main(void) { return c_function(); }
216311cde1c8SBruno DominguezEOF
216411cde1c8SBruno Dominguez
216511cde1c8SBruno Dominguez    compile_object
216611cde1c8SBruno Dominguez
216711cde1c8SBruno Dominguez    cat > $TMPCXX <<EOF
216811cde1c8SBruno Dominguezextern "C" {
216911cde1c8SBruno Dominguez   int c_function(void);
217011cde1c8SBruno Dominguez}
217111cde1c8SBruno Dominguezint c_function(void) { return 42; }
217211cde1c8SBruno DominguezEOF
217311cde1c8SBruno Dominguez
217411cde1c8SBruno Dominguez    update_cxxflags
217511cde1c8SBruno Dominguez
2176a2866660SPaolo Bonzini    if do_cxx $CXXFLAGS $EXTRA_CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
217711cde1c8SBruno Dominguez        # C++ compiler $cxx works ok with C compiler $cc
217811cde1c8SBruno Dominguez        :
217911cde1c8SBruno Dominguez    else
218011cde1c8SBruno Dominguez        echo "C++ compiler $cxx does not work with C compiler $cc"
218111cde1c8SBruno Dominguez        echo "Disabling C++ specific optional code"
218211cde1c8SBruno Dominguez        cxx=
218311cde1c8SBruno Dominguez    fi
218411cde1c8SBruno Dominguezelse
218511cde1c8SBruno Dominguez    echo "No C++ compiler available; disabling C++ specific optional code"
218611cde1c8SBruno Dominguez    cxx=
218711cde1c8SBruno Dominguezfi
218811cde1c8SBruno Dominguez
21897d7dbf9dSDan Streetmanif !(GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
21907d7dbf9dSDan Streetman    exit 1
21915d91a2edSYonggang Luofi
21925d91a2edSYonggang Luo
219398ec69acSJuan Quintelaconfig_host_mak="config-host.mak"
219497a847bcSbellard
219598ec69acSJuan Quintelaecho "# Automatically generated by configure - do not modify" > $config_host_mak
219698ec69acSJuan Quintelaecho >> $config_host_mak
219798ec69acSJuan Quintela
2198e6c3b0f7SPaolo Bonziniecho all: >> $config_host_mak
2199cc84d63aSDaniel P. Berrangeecho "GIT=$git" >> $config_host_mak
2200aef45d51SDaniel P. Berrangeecho "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
22017d7dbf9dSDan Streetmanecho "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
2202804edf29SJuan Quintela
2203f8393946Saurel32if test "$debug_tcg" = "yes" ; then
22042358a494SJuan Quintela  echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
2205f8393946Saurel32fi
220667b915a5Sbellardif test "$mingw32" = "yes" ; then
220798ec69acSJuan Quintela  echo "CONFIG_WIN32=y" >> $config_host_mak
22086e444209SPaolo Bonzini  echo "QEMU_GA_MSI_MINGW_BIN_PATH=${QEMU_GA_MSI_MINGW_BIN_PATH}" >> $config_host_mak
22099dacf32dSYossi Hindin  echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
22109dacf32dSYossi Hindin  echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
22119dacf32dSYossi Hindin  echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
2212210fa556Spbrookelse
221335f4df27SJuan Quintela  echo "CONFIG_POSIX=y" >> $config_host_mak
2214210fa556Spbrookfi
2215128ab2ffSblueswir1
2216dffcb71cSMark McLoughlinif test "$linux" = "yes" ; then
2217dffcb71cSMark McLoughlin  echo "CONFIG_LINUX=y" >> $config_host_mak
2218dffcb71cSMark McLoughlinfi
2219dffcb71cSMark McLoughlin
222083fb7adfSbellardif test "$darwin" = "yes" ; then
222198ec69acSJuan Quintela  echo "CONFIG_DARWIN=y" >> $config_host_mak
222283fb7adfSbellardfi
2223b29fe3edSmalc
2224ec530c81Sbellardif test "$solaris" = "yes" ; then
222598ec69acSJuan Quintela  echo "CONFIG_SOLARIS=y" >> $config_host_mak
2226ec530c81Sbellardfi
222797a847bcSbellardif test "$static" = "yes" ; then
222898ec69acSJuan Quintela  echo "CONFIG_STATIC=y" >> $config_host_mak
222997a847bcSbellardfi
2230b64ec4e4SFam Zhengecho "CONFIG_BDRV_RW_WHITELIST=$block_drv_rw_whitelist" >> $config_host_mak
2231b64ec4e4SFam Zhengecho "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
223289138857SStefan Weilqemu_version=$(head $source_path/VERSION)
22332358a494SJuan Quintelaecho "PKGVERSION=$pkgversion" >>$config_host_mak
223498ec69acSJuan Quintelaecho "SRC_PATH=$source_path" >> $config_host_mak
22352b1f35b9SAlex Bennéeecho "TARGET_DIRS=$target_list" >> $config_host_mak
223617969268SFam Zhengif test "$modules" = "yes"; then
2237e26110cfSFam Zheng  # $shacmd can generate a hash started with digit, which the compiler doesn't
2238e26110cfSFam Zheng  # like as an symbol. So prefix it with an underscore
223989138857SStefan Weil  echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
224017969268SFam Zheng  echo "CONFIG_MODULES=y" >> $config_host_mak
224117969268SFam Zhengfi
2242a1c5e949SDaniel P. Berrangeecho "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak
2243277abf15SJan Vesely
22445e9be92dSNicholas Bellingerif test "$vhost_scsi" = "yes" ; then
22455e9be92dSNicholas Bellinger  echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
22465e9be92dSNicholas Bellingerfi
2247af3bba76SPaolo Bonziniif test "$vhost_net" = "yes" ; then
2248af3bba76SPaolo Bonzini  echo "CONFIG_VHOST_NET=y" >> $config_host_mak
2249af3bba76SPaolo Bonzinifi
2250af3bba76SPaolo Bonziniif test "$vhost_net_user" = "yes" ; then
225156f41de7SPaolo Bonzini  echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak
225203ce5744SNikolay Nikolaevfi
2253108a6481SCindy Luif test "$vhost_net_vdpa" = "yes" ; then
2254108a6481SCindy Lu  echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak
2255108a6481SCindy Lufi
2256042cea27SGongleiif test "$vhost_crypto" = "yes" ; then
2257042cea27SGonglei  echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
2258042cea27SGongleifi
2259fc0b9b0eSStefan Hajnocziif test "$vhost_vsock" = "yes" ; then
2260fc0b9b0eSStefan Hajnoczi  echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
22615fe97d88SStefano Garzarella  if test "$vhost_user" = "yes" ; then
22625fe97d88SStefano Garzarella    echo "CONFIG_VHOST_USER_VSOCK=y" >> $config_host_mak
22635fe97d88SStefano Garzarella  fi
2264fc0b9b0eSStefan Hajnoczifi
2265299e6f19SPaolo Bonziniif test "$vhost_kernel" = "yes" ; then
2266299e6f19SPaolo Bonzini  echo "CONFIG_VHOST_KERNEL=y" >> $config_host_mak
2267299e6f19SPaolo Bonzinifi
2268e6a74868SMarc-André Lureauif test "$vhost_user" = "yes" ; then
2269e6a74868SMarc-André Lureau  echo "CONFIG_VHOST_USER=y" >> $config_host_mak
2270e6a74868SMarc-André Lureaufi
2271108a6481SCindy Luif test "$vhost_vdpa" = "yes" ; then
2272108a6481SCindy Lu  echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
2273108a6481SCindy Lufi
227498fc1adaSDr. David Alan Gilbertif test "$vhost_user_fs" = "yes" ; then
227598fc1adaSDr. David Alan Gilbert  echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak
227698fc1adaSDr. David Alan Gilbertfi
227758d3f3ffSGerd Hoffmann
227883fb7adfSbellard# XXX: suppress that
22797d3505c5Sbellardif [ "$bsd" = "yes" ] ; then
22802358a494SJuan Quintela  echo "CONFIG_BSD=y" >> $config_host_mak
22817d3505c5Sbellardfi
22827d3505c5Sbellard
22837c2acc70SPeter Maydellecho "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
22847d992e4dSPeter Lieven
2285d83414e1SMarc-André Lureauif test "$have_asan_iface_fiber" = "yes" ; then
2286d83414e1SMarc-André Lureau    echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
2287d83414e1SMarc-André Lureaufi
2288d83414e1SMarc-André Lureau
22890aebab04SLingfeng Yangif test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
22900aebab04SLingfeng Yang    echo "CONFIG_TSAN=y" >> $config_host_mak
22910aebab04SLingfeng Yangfi
22920aebab04SLingfeng Yang
229340e8c6f4SAlex Bennéeif test "$plugins" = "yes" ; then
229440e8c6f4SAlex Bennée    echo "CONFIG_PLUGIN=y" >> $config_host_mak
229540e8c6f4SAlex Bennéefi
229640e8c6f4SAlex Bennée
2297f48e590aSAlex Bennéeif test -n "$gdb_bin"; then
2298b1863cccSAlex Bennée    gdb_version=$($gdb_bin --version | head -n 1)
2299d6a66c81SAlex Bennée    if version_ge ${gdb_version##* } 9.1; then
2300f48e590aSAlex Bennée        echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
2301f48e590aSAlex Bennée    fi
2302b1863cccSAlex Bennéefi
2303f48e590aSAlex Bennée
230498ec69acSJuan Quintelaecho "ROMS=$roms" >> $config_host_mak
2305804edf29SJuan Quintelaecho "MAKE=$make" >> $config_host_mak
2306c886edfbSBlue Swirlecho "PYTHON=$python" >> $config_host_mak
230739d87c8cSAlex Bennéeecho "GENISOIMAGE=$genisoimage" >> $config_host_mak
2308a5665051SPaolo Bonziniecho "MESON=$meson" >> $config_host_mak
230909e93326SPaolo Bonziniecho "NINJA=$ninja" >> $config_host_mak
2310804edf29SJuan Quintelaecho "CC=$cc" >> $config_host_mak
2311804edf29SJuan Quintelaecho "AR=$ar" >> $config_host_mak
2312cdbd727cSRichard Hendersonecho "AS=$as" >> $config_host_mak
23135f6f0e27SRichard Hendersonecho "CCAS=$ccas" >> $config_host_mak
23143dd46c78SBlue Swirlecho "CPP=$cpp" >> $config_host_mak
2315804edf29SJuan Quintelaecho "OBJCOPY=$objcopy" >> $config_host_mak
2316804edf29SJuan Quintelaecho "LD=$ld" >> $config_host_mak
231746eef33bSBradecho "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
2318a558ee17SJuan Quintelaecho "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
231911cde1c8SBruno Dominguezecho "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
23204cb37d11SPhilippe Mathieu-Daudéecho "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak
2321a81df1b6SPaolo Bonziniecho "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
2322a81df1b6SPaolo Bonziniecho "GLIB_LIBS=$glib_libs" >> $config_host_mak
2323d83acfd0SMarc-André Lureauecho "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak
23248a99e9a3SPhilippe Mathieu-Daudéecho "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
2325e57218b6SPeter Maydellecho "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
2326a70248dbSPaolo Bonziniecho "STRIP=$strip" >> $config_host_mak
2327804edf29SJuan Quintelaecho "EXESUF=$EXESUF" >> $config_host_mak
2328804edf29SJuan Quintela
23296efd7517SPeter Maydell# use included Linux headers
23306efd7517SPeter Maydellif test "$linux" = "yes" ; then
2331a307beb6SAndreas Färber  mkdir -p linux-headers
23326efd7517SPeter Maydell  case "$cpu" in
23334da270beSPaolo Bonzini  i386|x86_64)
233408312a63SPeter Maydell    linux_arch=x86
23356efd7517SPeter Maydell    ;;
2336d8ff892dSPaolo Bonzini  ppc|ppc64)
233708312a63SPeter Maydell    linux_arch=powerpc
23386efd7517SPeter Maydell    ;;
23396efd7517SPeter Maydell  s390x)
234008312a63SPeter Maydell    linux_arch=s390
234108312a63SPeter Maydell    ;;
23421f080313SClaudio Fontana  aarch64)
23431f080313SClaudio Fontana    linux_arch=arm64
23441f080313SClaudio Fontana    ;;
2345dfcf900bSWANG Xuerui  loongarch*)
2346dfcf900bSWANG Xuerui    linux_arch=loongarch
2347dfcf900bSWANG Xuerui    ;;
2348222e7d11SSanjay Lal  mips64)
2349222e7d11SSanjay Lal    linux_arch=mips
2350222e7d11SSanjay Lal    ;;
235108312a63SPeter Maydell  *)
235208312a63SPeter Maydell    # For most CPUs the kernel architecture name and QEMU CPU name match.
235308312a63SPeter Maydell    linux_arch="$cpu"
23546efd7517SPeter Maydell    ;;
23556efd7517SPeter Maydell  esac
235608312a63SPeter Maydell    # For non-KVM architectures we will not have asm headers
235708312a63SPeter Maydell    if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
235808312a63SPeter Maydell      symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
235908312a63SPeter Maydell    fi
23606efd7517SPeter Maydellfi
23616efd7517SPeter Maydell
236297a847bcSbellardfor target in $target_list; do
236397a847bcSbellard    target_dir="$target"
236457a93f16SPhilippe Mathieu-Daudé    target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
236597a847bcSbellard    mkdir -p $target_dir
2366fdb75aefSPaolo Bonzini    case $target in
2367fdb75aefSPaolo Bonzini        *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
2368fdb75aefSPaolo Bonzini        *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
23692408a527Saurel32    esac
237056aebc89Spbrookdone
23717d13299dSbellard
2372765686d6SPaolo Bonziniecho "CONFIG_QEMU_INTERP_PREFIX=$interp_prefix" | sed 's/%M/@0@/' >> $config_host_mak
2373fdb75aefSPaolo Bonziniif test "$default_targets" = "yes"; then
2374fdb75aefSPaolo Bonzini  echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
2375fdb75aefSPaolo Bonzinifi
2376a540f158SPeter Crosthwaite
2377fd0e6053SJohn Snowif test "$ccache_cpp2" = "yes"; then
2378fd0e6053SJohn Snow  echo "export CCACHE_CPP2=y" >> $config_host_mak
2379fd0e6053SJohn Snowfi
2380fd0e6053SJohn Snow
23811e4f6065SDaniele Buonoif test "$safe_stack" = "yes"; then
23821e4f6065SDaniele Buono  echo "CONFIG_SAFESTACK=y" >> $config_host_mak
23831e4f6065SDaniele Buonofi
23841e4f6065SDaniele Buono
2385e29e5c6eSPeter Maydell# If we're using a separate build tree, set it up now.
2386e29e5c6eSPeter Maydell# LINKS are things to symlink back into the source tree
2387e29e5c6eSPeter Maydell# (these can be both files and directories).
2388e29e5c6eSPeter Maydell# Caution: do not add files or directories here using wildcards. This
2389e29e5c6eSPeter Maydell# will result in problems later if a new file matching the wildcard is
2390e29e5c6eSPeter Maydell# added to the source tree -- nothing will cause configure to be rerun
2391e29e5c6eSPeter Maydell# so the build tree will be missing the link back to the new file, and
2392e29e5c6eSPeter Maydell# tests might fail. Prefer to keep the relevant files in their own
2393e29e5c6eSPeter Maydell# directory and symlink the directory instead.
23942038f8c8SPaolo BonziniLINKS="Makefile"
23953941996bSPaolo BonziniLINKS="$LINKS tests/tcg/Makefile.target"
2396ddcf607fSGerd HoffmannLINKS="$LINKS pc-bios/optionrom/Makefile"
2397e29e5c6eSPeter MaydellLINKS="$LINKS pc-bios/s390-ccw/Makefile"
2398e29e5c6eSPeter MaydellLINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
2399bbbd9b6eSWillian RampazzoLINKS="$LINKS tests/avocado tests/data"
240039950353SPeter MaydellLINKS="$LINKS tests/qemu-iotests/check"
24018f8fd9edSCleber RosaLINKS="$LINKS python"
2402c17a386bSAlex BennéeLINKS="$LINKS contrib/plugins/Makefile "
2403753d11f2SRichard Hendersonfor bios_file in \
2404753d11f2SRichard Henderson    $source_path/pc-bios/*.bin \
24053a631b8eSBin Meng    $source_path/pc-bios/*.elf \
2406225a9ab8SAlexey Kardashevskiy    $source_path/pc-bios/*.lid \
2407753d11f2SRichard Henderson    $source_path/pc-bios/*.rom \
2408753d11f2SRichard Henderson    $source_path/pc-bios/*.dtb \
2409e89e33e1SDominik Dingel    $source_path/pc-bios/*.img \
2410753d11f2SRichard Henderson    $source_path/pc-bios/openbios-* \
24114e73c781SAlexander Graf    $source_path/pc-bios/u-boot.* \
2412cd946e5cSJohn Arbuckle    $source_path/pc-bios/palcode-* \
2413cd946e5cSJohn Arbuckle    $source_path/pc-bios/qemu_vga.ndrv
2414cd946e5cSJohn Arbuckle
2415753d11f2SRichard Hendersondo
2416e29e5c6eSPeter Maydell    LINKS="$LINKS pc-bios/$(basename $bios_file)"
24177ea78b74SJan Kiszkadone
2418e29e5c6eSPeter Maydellfor f in $LINKS ; do
24190f4d8894SPaolo Bonzini    if [ -e "$source_path/$f" ]; then
24205dce7b8dSPaolo Bonzini        mkdir -p `dirname ./$f`
2421f9245e10SPeter Maydell        symlink "$source_path/$f" "$f"
2422f9245e10SPeter Maydell    fi
24237d13299dSbellarddone
24241ad2134fSPaul Brook
24252038f8c8SPaolo Bonzini(for i in $cross_cc_vars; do
24262038f8c8SPaolo Bonzini  export $i
24272038f8c8SPaolo Bonzinidone
2428544f4a25SPaolo Bonziniexport target_list source_path use_containers cpu host_cc
24292038f8c8SPaolo Bonzini$source_path/tests/tcg/configure.sh)
24302038f8c8SPaolo Bonzini
243198409991SHelge Konetzkaconfig_mak=pc-bios/optionrom/config.mak
243298409991SHelge Konetzkaecho "# Automatically generated by configure - do not modify" > $config_mak
243398409991SHelge Konetzkaecho "TOPSRC_DIR=$source_path" >> $config_mak
243498409991SHelge Konetzka
2435a5665051SPaolo Bonziniif test "$skip_meson" = no; then
2436fc929892SMarc-André Lureau  cross="config-meson.cross.new"
2437fc929892SMarc-André Lureau  meson_quote() {
2438ac7ebcc5SPaolo Bonzini    test $# = 0 && return
243947b30835SPaolo Bonzini    echo "'$(echo $* | sed "s/ /','/g")'"
2440fc929892SMarc-André Lureau  }
2441fc929892SMarc-André Lureau
2442fc929892SMarc-André Lureau  echo "# Automatically generated by configure - do not modify" > $cross
2443fc929892SMarc-André Lureau  echo "[properties]" >> $cross
2444d1d5e9eeSAlex Bennée
2445d1d5e9eeSAlex Bennée  # unroll any custom device configs
2446d1d5e9eeSAlex Bennée  for a in $device_archs; do
2447d1d5e9eeSAlex Bennée      eval "c=\$devices_${a}"
2448d1d5e9eeSAlex Bennée      echo "${a}-softmmu = '$c'" >> $cross
2449d1d5e9eeSAlex Bennée  done
2450d1d5e9eeSAlex Bennée
2451fc929892SMarc-André Lureau  test -z "$cxx" && echo "link_language = 'c'" >> $cross
245247b30835SPaolo Bonzini  echo "[built-in options]" >> $cross
2453a2866660SPaolo Bonzini  echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
2454a2866660SPaolo Bonzini  echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
2455e910c7d9SPhilippe Mathieu-Daudé  test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
2456a2866660SPaolo Bonzini  echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
2457a2866660SPaolo Bonzini  echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
2458fc929892SMarc-André Lureau  echo "[binaries]" >> $cross
24594dba2789SPaolo Bonzini  echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
24604dba2789SPaolo Bonzini  test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
24614dba2789SPaolo Bonzini  test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
246247b30835SPaolo Bonzini  echo "ar = [$(meson_quote $ar)]" >> $cross
246347b30835SPaolo Bonzini  echo "nm = [$(meson_quote $nm)]" >> $cross
246447b30835SPaolo Bonzini  echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
246547b30835SPaolo Bonzini  echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
2466e8178514SPaolo Bonzini  if has $sdl2_config; then
246747b30835SPaolo Bonzini    echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
2468e8178514SPaolo Bonzini  fi
246947b30835SPaolo Bonzini  echo "strip = [$(meson_quote $strip)]" >> $cross
2470158bb224SKonstantin Kostiuk  echo "widl = [$(meson_quote $widl)]" >> $cross
247147b30835SPaolo Bonzini  echo "windres = [$(meson_quote $windres)]" >> $cross
24723812c0c4SJoelle van Dyne  if test "$cross_compile" = "yes"; then
2473fc929892SMarc-André Lureau    cross_arg="--cross-file config-meson.cross"
2474fc929892SMarc-André Lureau    echo "[host_machine]" >> $cross
2475ba7c60c2SPaolo Bonzini    echo "system = '$targetos'" >> $cross
2476823eb013SPaolo Bonzini    case "$cpu" in
2477f6bca9dfSJoelle van Dyne        i386)
2478fc929892SMarc-André Lureau            echo "cpu_family = 'x86'" >> $cross
2479fc929892SMarc-André Lureau            ;;
2480fc929892SMarc-André Lureau        *)
2481823eb013SPaolo Bonzini            echo "cpu_family = '$cpu'" >> $cross
2482fc929892SMarc-André Lureau            ;;
2483fc929892SMarc-André Lureau    esac
2484fc929892SMarc-André Lureau    echo "cpu = '$cpu'" >> $cross
2485fc929892SMarc-André Lureau    if test "$bigendian" = "yes" ; then
2486fc929892SMarc-André Lureau        echo "endian = 'big'" >> $cross
2487fc929892SMarc-André Lureau    else
2488fc929892SMarc-André Lureau        echo "endian = 'little'" >> $cross
2489fc929892SMarc-André Lureau    fi
2490fc929892SMarc-André Lureau  else
2491fc929892SMarc-André Lureau    cross_arg="--native-file config-meson.cross"
2492fc929892SMarc-André Lureau  fi
2493fc929892SMarc-André Lureau  mv $cross config-meson.cross
2494fc929892SMarc-André Lureau
2495a5665051SPaolo Bonzini  rm -rf meson-private meson-info meson-logs
249661d63097SPaolo Bonzini  run_meson() {
249709e93326SPaolo Bonzini    NINJA=$ninja $meson setup \
2498d17f305aSPaolo Bonzini        --prefix "$prefix" \
2499d17f305aSPaolo Bonzini        --libdir "$libdir" \
2500d17f305aSPaolo Bonzini        --libexecdir "$libexecdir" \
2501d17f305aSPaolo Bonzini        --bindir "$bindir" \
2502d17f305aSPaolo Bonzini        --includedir "$includedir" \
2503d17f305aSPaolo Bonzini        --datadir "$datadir" \
2504d17f305aSPaolo Bonzini        --mandir "$mandir" \
2505d17f305aSPaolo Bonzini        --sysconfdir "$sysconfdir" \
250616bf7a33SPaolo Bonzini        --localedir "$localedir" \
2507d17f305aSPaolo Bonzini        --localstatedir "$local_statedir" \
25083b4da132SPaolo Bonzini        -Daudio_drv_list=$audio_drv_list \
25093b4da132SPaolo Bonzini        -Ddefault_devices=$default_devices \
2510d17f305aSPaolo Bonzini        -Ddocdir="$docdir" \
25115dc4618eSPaolo Bonzini        -Diasl="$($iasl -h >/dev/null 2>&1 && printf %s "$iasl")" \
251216bf7a33SPaolo Bonzini        -Dqemu_firmwarepath="$firmwarepath" \
251373f3aa37SMarc-André Lureau        -Dqemu_suffix="$qemu_suffix" \
251435acbb30SPaolo Bonzini        -Dsmbd="$smbd" \
25153b4da132SPaolo Bonzini        -Dsphinx_build="$sphinx_build" \
25163b4da132SPaolo Bonzini        -Dtrace_file="$trace_file" \
2517a5665051SPaolo Bonzini        -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) \
2518a5665051SPaolo Bonzini        -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo false; fi) \
2519a5665051SPaolo Bonzini        -Dwerror=$(if test "$werror" = yes; then echo true; else echo false; fi) \
2520da6d48b9SMarc-André Lureau        -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \
2521bf0e56a3SMarc-André Lureau        -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
2522*14efd8d3SPaolo Bonzini        -Db_lto=$lto -Dcfi=$cfi -Dtcg=$tcg \
25233b4da132SPaolo Bonzini        -Dcapstone=$capstone -Dfdt=$fdt -Dslirp=$slirp \
2524537b7248SPaolo Bonzini        $(test -n "${LIB_FUZZING_ENGINE+xxx}" && echo "-Dfuzzing_engine=$LIB_FUZZING_ENGINE") \
2525332008e0SThomas Huth        $(if test "$default_feature" = no; then echo "-Dauto_features=disabled"; fi) \
252661d63097SPaolo Bonzini        "$@" $cross_arg "$PWD" "$source_path"
252761d63097SPaolo Bonzini  }
252861d63097SPaolo Bonzini  eval run_meson $meson_options
2529a5665051SPaolo Bonzini  if test "$?" -ne 0 ; then
2530a5665051SPaolo Bonzini      error_exit "meson setup failed"
2531a5665051SPaolo Bonzini  fi
2532699d3884SPaolo Bonzinielse
2533699d3884SPaolo Bonzini  if test -f meson-private/cmd_line.txt; then
2534699d3884SPaolo Bonzini    # Adjust old command line options whose type was changed
2535699d3884SPaolo Bonzini    # Avoids having to use "setup --wipe" when Meson is upgraded
2536699d3884SPaolo Bonzini    perl -i -ne '
2537699d3884SPaolo Bonzini      s/^gettext = true$/gettext = auto/;
2538699d3884SPaolo Bonzini      s/^gettext = false$/gettext = disabled/;
2539654d6b04SPaolo Bonzini      /^b_staticpic/ && next;
2540699d3884SPaolo Bonzini      print;' meson-private/cmd_line.txt
2541699d3884SPaolo Bonzini  fi
2542a5665051SPaolo Bonzinifi
2543a5665051SPaolo Bonzini
2544dc655404SMichael S. Tsirkin# Save the configure command line for later reuse.
2545dc655404SMichael S. Tsirkincat <<EOD >config.status
2546dc655404SMichael S. Tsirkin#!/bin/sh
2547dc655404SMichael S. Tsirkin# Generated by configure.
2548dc655404SMichael S. Tsirkin# Run this file to recreate the current configuration.
2549dc655404SMichael S. Tsirkin# Compiler output produced by configure, useful for debugging
2550dc655404SMichael S. Tsirkin# configure, is in config.log if it exists.
2551dc655404SMichael S. TsirkinEOD
2552e811da7fSDaniel P. Berrangé
2553e811da7fSDaniel P. Berrangépreserve_env() {
2554e811da7fSDaniel P. Berrangé    envname=$1
2555e811da7fSDaniel P. Berrangé
2556e811da7fSDaniel P. Berrangé    eval envval=\$$envname
2557e811da7fSDaniel P. Berrangé
2558e811da7fSDaniel P. Berrangé    if test -n "$envval"
2559e811da7fSDaniel P. Berrangé    then
2560e811da7fSDaniel P. Berrangé	echo "$envname='$envval'" >> config.status
2561e811da7fSDaniel P. Berrangé	echo "export $envname" >> config.status
2562e811da7fSDaniel P. Berrangé    else
2563e811da7fSDaniel P. Berrangé	echo "unset $envname" >> config.status
2564e811da7fSDaniel P. Berrangé    fi
2565e811da7fSDaniel P. Berrangé}
2566e811da7fSDaniel P. Berrangé
2567e811da7fSDaniel P. Berrangé# Preserve various env variables that influence what
2568e811da7fSDaniel P. Berrangé# features/build target configure will detect
2569e811da7fSDaniel P. Berrangépreserve_env AR
2570e811da7fSDaniel P. Berrangépreserve_env AS
2571e811da7fSDaniel P. Berrangépreserve_env CC
2572e811da7fSDaniel P. Berrangépreserve_env CPP
25738009da03SPaolo Bonzinipreserve_env CFLAGS
2574e811da7fSDaniel P. Berrangépreserve_env CXX
25758009da03SPaolo Bonzinipreserve_env CXXFLAGS
2576e811da7fSDaniel P. Berrangépreserve_env INSTALL
2577e811da7fSDaniel P. Berrangépreserve_env LD
25788009da03SPaolo Bonzinipreserve_env LDFLAGS
2579e811da7fSDaniel P. Berrangépreserve_env LD_LIBRARY_PATH
2580e811da7fSDaniel P. Berrangépreserve_env LIBTOOL
2581e811da7fSDaniel P. Berrangépreserve_env MAKE
2582e811da7fSDaniel P. Berrangépreserve_env NM
2583e811da7fSDaniel P. Berrangépreserve_env OBJCOPY
2584e811da7fSDaniel P. Berrangépreserve_env PATH
2585e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG
2586e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_LIBDIR
2587e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_PATH
2588e811da7fSDaniel P. Berrangépreserve_env PYTHON
2589e811da7fSDaniel P. Berrangépreserve_env SDL2_CONFIG
2590e811da7fSDaniel P. Berrangépreserve_env SMBD
2591e811da7fSDaniel P. Berrangépreserve_env STRIP
2592158bb224SKonstantin Kostiukpreserve_env WIDL
2593e811da7fSDaniel P. Berrangépreserve_env WINDRES
2594e811da7fSDaniel P. Berrangé
2595dc655404SMichael S. Tsirkinprintf "exec" >>config.status
2596a5665051SPaolo Bonzinifor i in "$0" "$@"; do
2597835af899SPaolo Bonzini  test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
2598a5665051SPaolo Bonzinidone
2599cf7cc929SDr. David Alan Gilbertecho ' "$@"' >>config.status
2600dc655404SMichael S. Tsirkinchmod +x config.status
2601dc655404SMichael S. Tsirkin
26028cd05ab6SPeter Maydellrm -r "$TMPDIR1"
2603