xref: /openbmc/qemu/configure (revision ad388845)
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.
114cd362defSPaolo Bonzini  local compiler="$1"
115cd362defSPaolo Bonzini  shift
116cd362defSPaolo Bonzini  if test -n "$BASH_VERSION"; then eval '
117cd362defSPaolo Bonzini      echo >>config.log "
118cd362defSPaolo Bonzinifuncs: ${FUNCNAME[*]}
119cd362defSPaolo Bonzinilines: ${BASH_LINENO[*]}"
120cd362defSPaolo Bonzini  '; fi
121cd362defSPaolo Bonzini  echo $compiler "$@" >> config.log
122cd362defSPaolo Bonzini  $compiler "$@" >> config.log 2>&1 || return $?
123cd362defSPaolo Bonzini}
124cd362defSPaolo Bonzini
125cd362defSPaolo Bonzinido_compiler_werror() {
126cd362defSPaolo Bonzini    # Run the compiler, capturing its output to the log. First argument
127cd362defSPaolo Bonzini    # is compiler binary to execute.
128630d86b7SDavid CARLIER    compiler="$1"
1299c83ffd8SPeter Maydell    shift
1308bbe05d7SIan Jackson    if test -n "$BASH_VERSION"; then eval '
1318bbe05d7SIan Jackson        echo >>config.log "
1328bbe05d7SIan Jacksonfuncs: ${FUNCNAME[*]}
1338bbe05d7SIan Jacksonlines: ${BASH_LINENO[*]}"
1348bbe05d7SIan Jackson    '; fi
1359c83ffd8SPeter Maydell    echo $compiler "$@" >> config.log
1369c83ffd8SPeter Maydell    $compiler "$@" >> config.log 2>&1 || return $?
1378dc38a78SPeter Maydell    # Test passed. If this is an --enable-werror build, rerun
1388dc38a78SPeter Maydell    # the test with -Werror and bail out if it fails. This
1398dc38a78SPeter Maydell    # makes warning-generating-errors in configure test code
1408dc38a78SPeter Maydell    # obvious to developers.
1418dc38a78SPeter Maydell    if test "$werror" != "yes"; then
1428dc38a78SPeter Maydell        return 0
1438dc38a78SPeter Maydell    fi
1448dc38a78SPeter Maydell    # Don't bother rerunning the compile if we were already using -Werror
1458dc38a78SPeter Maydell    case "$*" in
1468dc38a78SPeter Maydell        *-Werror*)
1478dc38a78SPeter Maydell           return 0
1488dc38a78SPeter Maydell        ;;
1498dc38a78SPeter Maydell    esac
1509c83ffd8SPeter Maydell    echo $compiler -Werror "$@" >> config.log
1519c83ffd8SPeter Maydell    $compiler -Werror "$@" >> config.log 2>&1 && return $?
15276ad07a4SPeter Maydell    error_exit "configure test passed without -Werror but failed with -Werror." \
15376ad07a4SPeter Maydell        "This is probably a bug in the configure script. The failing command" \
15476ad07a4SPeter Maydell        "will be at the bottom of config.log." \
15576ad07a4SPeter Maydell        "You can run configure with --disable-werror to bypass this check."
1568dc38a78SPeter Maydell}
1578dc38a78SPeter Maydell
1589c83ffd8SPeter Maydelldo_cc() {
159cd362defSPaolo Bonzini    do_compiler_werror "$cc" $CPU_CFLAGS "$@"
1609c83ffd8SPeter Maydell}
1619c83ffd8SPeter Maydell
1629c83ffd8SPeter Maydelldo_cxx() {
163cd362defSPaolo Bonzini    do_compiler_werror "$cxx" $CPU_CFLAGS "$@"
1649c83ffd8SPeter Maydell}
1659c83ffd8SPeter Maydell
1664cb37d11SPhilippe Mathieu-Daudédo_objc() {
167cd362defSPaolo Bonzini    do_compiler_werror "$objcc" $CPU_CFLAGS "$@"
1684cb37d11SPhilippe Mathieu-Daudé}
1694cb37d11SPhilippe Mathieu-Daudé
17000849b92SRichard Henderson# Append $2 to the variable named $1, with space separation
17100849b92SRichard Hendersonadd_to() {
17200849b92SRichard Henderson    eval $1=\${$1:+\"\$$1 \"}\$2
17300849b92SRichard Henderson}
17400849b92SRichard Henderson
1759c83ffd8SPeter Maydellupdate_cxxflags() {
1769c83ffd8SPeter Maydell    # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
1779c83ffd8SPeter Maydell    # options which some versions of GCC's C++ compiler complain about
1789c83ffd8SPeter Maydell    # because they only make sense for C programs.
179de38c0ccSPaolo Bonzini    QEMU_CXXFLAGS="-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
1808a9d3d56SRichard Henderson    CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
1819c83ffd8SPeter Maydell    for arg in $QEMU_CFLAGS; do
1829c83ffd8SPeter Maydell        case $arg in
1839c83ffd8SPeter Maydell            -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
1849c83ffd8SPeter Maydell            -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
1859c83ffd8SPeter Maydell                ;;
1869c83ffd8SPeter Maydell            *)
1879c83ffd8SPeter Maydell                QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
1889c83ffd8SPeter Maydell                ;;
1899c83ffd8SPeter Maydell        esac
1909c83ffd8SPeter Maydell    done
1919c83ffd8SPeter Maydell}
1929c83ffd8SPeter Maydell
19352166aa0SJuan Quintelacompile_object() {
194fd0e6053SJohn Snow  local_cflags="$1"
195a2866660SPaolo Bonzini  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
19652166aa0SJuan Quintela}
19752166aa0SJuan Quintela
19852166aa0SJuan Quintelacompile_prog() {
19952166aa0SJuan Quintela  local_cflags="$1"
20052166aa0SJuan Quintela  local_ldflags="$2"
201a2866660SPaolo Bonzini  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
202a2866660SPaolo Bonzini      $LDFLAGS $EXTRA_LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
20352166aa0SJuan Quintela}
20452166aa0SJuan Quintela
20511568d6dSPaolo Bonzini# symbolically link $1 to $2.  Portable version of "ln -sf".
20611568d6dSPaolo Bonzinisymlink() {
20772b8b5a1SStefan Weil  rm -rf "$2"
208ec5b06d7SAnthony Liguori  mkdir -p "$(dirname "$2")"
20972b8b5a1SStefan Weil  ln -s "$1" "$2"
21011568d6dSPaolo Bonzini}
21111568d6dSPaolo Bonzini
2120dba6195SLoïc Minier# check whether a command is available to this shell (may be either an
2130dba6195SLoïc Minier# executable or a builtin)
2140dba6195SLoïc Minierhas() {
2150dba6195SLoïc Minier    type "$1" >/dev/null 2>&1
2160dba6195SLoïc Minier}
2170dba6195SLoïc Minier
2180a01d76fSMarc-André Lureauversion_ge () {
2192df52b9bSAlex Bennée    local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
2202df52b9bSAlex Bennée    local_ver2=$(echo "$2" | tr . ' ')
2210a01d76fSMarc-André Lureau    while true; do
2220a01d76fSMarc-André Lureau        set x $local_ver1
2230a01d76fSMarc-André Lureau        local_first=${2-0}
224c44a33e2SStefano Garzarella        # 'shift 2' if $2 is set, or 'shift' if $2 is not set
225c44a33e2SStefano Garzarella        shift ${2:+2}
2260a01d76fSMarc-André Lureau        local_ver1=$*
2270a01d76fSMarc-André Lureau        set x $local_ver2
2280a01d76fSMarc-André Lureau        # the second argument finished, the first must be greater or equal
2290a01d76fSMarc-André Lureau        test $# = 1 && return 0
2300a01d76fSMarc-André Lureau        test $local_first -lt $2 && return 1
2310a01d76fSMarc-André Lureau        test $local_first -gt $2 && return 0
232c44a33e2SStefano Garzarella        shift ${2:+2}
2330a01d76fSMarc-André Lureau        local_ver2=$*
2340a01d76fSMarc-André Lureau    done
2350a01d76fSMarc-André Lureau}
2360a01d76fSMarc-André Lureau
2373b6b7550SPaolo Bonziniglob() {
2383b6b7550SPaolo Bonzini    eval test -z '"${1#'"$2"'}"'
2393b6b7550SPaolo Bonzini}
2403b6b7550SPaolo Bonzini
2414ace32e2SAntonio Ospiteif printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
2424ace32e2SAntonio Ospitethen
2434ace32e2SAntonio Ospite  error_exit "main directory cannot contain spaces nor colons"
2444ace32e2SAntonio Ospitefi
2454ace32e2SAntonio Ospite
24614211825SAntonio Ospite# default parameters
2472ff6b91eSJuan Quintelacpu=""
24843ce4dfeSbellardstatic="no"
2493812c0c4SJoelle van Dynecross_compile="no"
2507d13299dSbellardcross_prefix=""
251e49d021eSPeter Maydellhost_cc="cc"
25263678e17SSteven Noonanstack_protector=""
2531e4f6065SDaniele Buonosafe_stack=""
254afc3a8f9SAlex Bennéeuse_containers="yes"
255f2385398SAlex Bennéegdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
256ac0df51dSaliguori
25792712822SDaniel P. Berrangeif test -e "$source_path/.git"
25892712822SDaniel P. Berrangethen
2597d7dbf9dSDan Streetman    git_submodules_action="update"
26092712822SDaniel P. Berrangeelse
2617d7dbf9dSDan Streetman    git_submodules_action="ignore"
26292712822SDaniel P. Berrangefi
2632d652f24SPaolo Bonzini
2642d652f24SPaolo Bonzinigit_submodules="ui/keycodemapdb"
265cc84d63aSDaniel P. Berrangegit="git"
266ac0df51dSaliguori
267afb63ebdSStefan Weil# Don't accept a target_list environment variable.
268afb63ebdSStefan Weilunset target_list
269447e133fSAlex Bennéeunset target_list_exclude
270377529c0SPaolo Bonzini
271377529c0SPaolo Bonzini# Default value for a variable defining feature "foo".
272377529c0SPaolo Bonzini#  * foo="no"  feature will only be used if --enable-foo arg is given
273377529c0SPaolo Bonzini#  * foo=""    feature will be searched for, and if found, will be used
274377529c0SPaolo Bonzini#              unless --disable-foo is given
275377529c0SPaolo Bonzini#  * foo="yes" this value will only be set by --enable-foo flag.
276377529c0SPaolo Bonzini#              feature will searched for,
277377529c0SPaolo Bonzini#              if not found, configure exits with error
278377529c0SPaolo Bonzini#
279377529c0SPaolo Bonzini# Always add --enable-foo and --disable-foo command line args.
280377529c0SPaolo Bonzini# Distributions want to ensure that several features are compiled in, and it
281377529c0SPaolo Bonzini# is impossible without a --enable-foo that exits if a feature is not found.
282377529c0SPaolo Bonzini
283c87ea116SAlex Bennéedefault_feature=""
284c87ea116SAlex Bennée# parse CC options second
285c87ea116SAlex Bennéefor opt do
286c87ea116SAlex Bennée  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
287c87ea116SAlex Bennée  case "$opt" in
288c87ea116SAlex Bennée      --without-default-features)
289c87ea116SAlex Bennée          default_feature="no"
290c87ea116SAlex Bennée  ;;
291c87ea116SAlex Bennée  esac
292c87ea116SAlex Bennéedone
293c87ea116SAlex Bennée
294a2866660SPaolo BonziniEXTRA_CFLAGS=""
295a2866660SPaolo BonziniEXTRA_CXXFLAGS=""
296e910c7d9SPhilippe Mathieu-DaudéEXTRA_OBJCFLAGS=""
297a2866660SPaolo BonziniEXTRA_LDFLAGS=""
298a2866660SPaolo Bonzini
299377529c0SPaolo Bonzinidebug_tcg="no"
300247724cbSMarc-André Lureausanitizers="no"
3010aebab04SLingfeng Yangtsan="no"
3021f3f2bfeSMichael Tokarevfortify_source="yes"
303c7328271SMiroslav RezaninaEXESUF=""
30417969268SFam Zhengmodules="no"
305377529c0SPaolo Bonziniprefix="/usr/local"
30610ff82d1SMarc-André Lureauqemu_suffix="qemu"
307377529c0SPaolo Bonzinisoftmmu="yes"
308b915a2f1SPaolo Bonzinilinux_user=""
309b915a2f1SPaolo Bonzinibsd_user=""
31040d6444eSAvi Kivitypie=""
311519175a2SAlex Barcelocoroutine=""
312ba4dd2aaSAlex Bennéeplugins="$default_feature"
313a5665051SPaolo Bonzinimeson=""
3143b4da132SPaolo Bonzinimeson_args=""
31548328880SPaolo Bonzinininja=""
316c09c1ce7SPaolo Bonzinibindir="bin"
317a5665051SPaolo Bonziniskip_meson=no
318377529c0SPaolo Bonzini
3193b4da132SPaolo Bonzini# The following Meson options are handled manually (still they
3203b4da132SPaolo Bonzini# are included in the automatically generated help message)
3213b4da132SPaolo Bonzini
3223b4da132SPaolo Bonzini# 1. Track which submodules are needed
3230577e84dSThomas Huthif test "$default_feature" = no ; then
3240577e84dSThomas Huth  slirp="disabled"
3250577e84dSThomas Huthelse
3263b4da132SPaolo Bonzini  slirp="auto"
3270577e84dSThomas Huthfi
3280577e84dSThomas Huthfdt="auto"
3293b4da132SPaolo Bonzini
330c54b59eeSPaolo Bonzini# 2. Automatically enable/disable other options
3313b4da132SPaolo Bonzinitcg="enabled"
3323b4da132SPaolo Bonzinicfi="false"
3333b4da132SPaolo Bonzini
334c87ea116SAlex Bennée# parse CC options second
335ac0df51dSaliguorifor opt do
33689138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
337ac0df51dSaliguori  case "$opt" in
338ac0df51dSaliguori  --cross-prefix=*) cross_prefix="$optarg"
3393812c0c4SJoelle van Dyne                    cross_compile="yes"
340ac0df51dSaliguori  ;;
3413d8df640SPaolo Bonzini  --cc=*) CC="$optarg"
342ac0df51dSaliguori  ;;
34383f73fceSTomoki Sekiyama  --cxx=*) CXX="$optarg"
34483f73fceSTomoki Sekiyama  ;;
3452ff6b91eSJuan Quintela  --cpu=*) cpu="$optarg"
3462ff6b91eSJuan Quintela  ;;
347a2866660SPaolo Bonzini  --extra-cflags=*)
348a2866660SPaolo Bonzini    EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
349a2866660SPaolo Bonzini    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
350e910c7d9SPhilippe Mathieu-Daudé    EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
351e2a2ed06SJuan Quintela    ;;
352a2866660SPaolo Bonzini  --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
35311cde1c8SBruno Dominguez  ;;
354e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
355e910c7d9SPhilippe Mathieu-Daudé  ;;
356a2866660SPaolo Bonzini  --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
357e2a2ed06SJuan Quintela  ;;
358d75402b5SAlex Bennée  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
359d75402b5SAlex Bennée  ;;
360479ca4ccSMatheus Ferst  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
361d422b2bcSAlex Bennée                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
362d422b2bcSAlex Bennée  ;;
363d75402b5SAlex Bennée  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
364d75402b5SAlex Bennée                eval "cross_cc_${cc_arch}=\$optarg"
365d75402b5SAlex Bennée  ;;
3665adb43beSPaolo Bonzini  --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-prefix-FOO option"
3675adb43beSPaolo Bonzini  ;;
3685adb43beSPaolo Bonzini  --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
3695adb43beSPaolo Bonzini                    eval "cross_prefix_${cc_arch}=\$optarg"
3705adb43beSPaolo Bonzini  ;;
371ac0df51dSaliguori  esac
372ac0df51dSaliguoridone
373ac0df51dSaliguori# OS specific
374ac0df51dSaliguori# Using uname is really, really broken.  Once we have the right set of checks
37593148aa5SStefan Weil# we can eliminate its usage altogether.
376ac0df51dSaliguori
377e49d021eSPeter Maydell# Preferred compiler:
378e49d021eSPeter Maydell#  ${CC} (if set)
379e49d021eSPeter Maydell#  ${cross_prefix}gcc (if cross-prefix specified)
380e49d021eSPeter Maydell#  system compiler
381e49d021eSPeter Maydellif test -z "${CC}${cross_prefix}"; then
382e49d021eSPeter Maydell  cc="$host_cc"
383e49d021eSPeter Maydellelse
384b3198cc2SStuart Yoder  cc="${CC-${cross_prefix}gcc}"
385e49d021eSPeter Maydellfi
386e49d021eSPeter Maydell
38783f73fceSTomoki Sekiyamaif test -z "${CXX}${cross_prefix}"; then
38883f73fceSTomoki Sekiyama  cxx="c++"
38983f73fceSTomoki Sekiyamaelse
39083f73fceSTomoki Sekiyama  cxx="${CXX-${cross_prefix}g++}"
39183f73fceSTomoki Sekiyamafi
39283f73fceSTomoki Sekiyama
393b3198cc2SStuart Yoderar="${AR-${cross_prefix}ar}"
394cdbd727cSRichard Hendersonas="${AS-${cross_prefix}as}"
3955f6f0e27SRichard Hendersonccas="${CCAS-$cc}"
396b3198cc2SStuart Yoderobjcopy="${OBJCOPY-${cross_prefix}objcopy}"
397b3198cc2SStuart Yoderld="${LD-${cross_prefix}ld}"
3989f81aeb5SAlistair Francisranlib="${RANLIB-${cross_prefix}ranlib}"
3994852ee95SStefan Weilnm="${NM-${cross_prefix}nm}"
40035acbb30SPaolo Bonzinismbd="$SMBD"
401b3198cc2SStuart Yoderstrip="${STRIP-${cross_prefix}strip}"
402158bb224SKonstantin Kostiukwidl="${WIDL-${cross_prefix}widl}"
403b3198cc2SStuart Yoderwindres="${WINDRES-${cross_prefix}windres}"
40417884d7bSSergei Trofimovichpkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
40517884d7bSSergei Trofimovichquery_pkg_config() {
40617884d7bSSergei Trofimovich    "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
40717884d7bSSergei Trofimovich}
40817884d7bSSergei Trofimovichpkg_config=query_pkg_config
40947c03744SDave Airliesdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
410ac0df51dSaliguori
411be17dc90SMichael S. Tsirkin# default flags for all hosts
4122d31515bSPeter Maydell# We use -fwrapv to tell the compiler that we require a C dialect where
4132d31515bSPeter Maydell# left shift of signed integers is well defined and has the expected
4142d31515bSPeter Maydell# 2s-complement style results. (Both clang and gcc agree that it
4152d31515bSPeter Maydell# provides these semantics.)
416de38c0ccSPaolo BonziniQEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
417086d5f75SPaolo BonziniQEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
418c95e3080SKevin WolfQEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
419be17dc90SMichael S. TsirkinQEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
4205770e8afSPaolo Bonzini
421de38c0ccSPaolo BonziniQEMU_LDFLAGS=
422de38c0ccSPaolo Bonzini
4235770e8afSPaolo Bonzini# Flags that are needed during configure but later taken care of by Meson
4248a9d3d56SRichard HendersonCONFIGURE_CFLAGS="-std=gnu11 -Wall"
4255770e8afSPaolo BonziniCONFIGURE_LDFLAGS=
426086d5f75SPaolo Bonzini
427be17dc90SMichael S. Tsirkin
428ac0df51dSaliguoricheck_define() {
429ac0df51dSaliguoricat > $TMPC <<EOF
430ac0df51dSaliguori#if !defined($1)
431fd786e1aSPeter Maydell#error $1 not defined
432ac0df51dSaliguori#endif
433ac0df51dSaliguoriint main(void) { return 0; }
434ac0df51dSaliguoriEOF
43552166aa0SJuan Quintela  compile_object
436ac0df51dSaliguori}
437ac0df51dSaliguori
438307119e7SGerd Hoffmanncheck_include() {
439307119e7SGerd Hoffmanncat > $TMPC <<EOF
440307119e7SGerd Hoffmann#include <$1>
441307119e7SGerd Hoffmannint main(void) { return 0; }
442307119e7SGerd HoffmannEOF
443307119e7SGerd Hoffmann  compile_object
444307119e7SGerd Hoffmann}
445307119e7SGerd Hoffmann
44693b25869SJohn Snowwrite_c_skeleton() {
44793b25869SJohn Snow    cat > $TMPC <<EOF
44893b25869SJohn Snowint main(void) { return 0; }
44993b25869SJohn SnowEOF
45093b25869SJohn Snow}
45193b25869SJohn Snow
452bbea4050SPeter Maydellif check_define __linux__ ; then
453ba7c60c2SPaolo Bonzini  targetos=linux
454bbea4050SPeter Maydellelif check_define _WIN32 ; then
455ba7c60c2SPaolo Bonzini  targetos=windows
456bbea4050SPeter Maydellelif check_define __OpenBSD__ ; then
457ba7c60c2SPaolo Bonzini  targetos=openbsd
458bbea4050SPeter Maydellelif check_define __sun__ ; then
459ba7c60c2SPaolo Bonzini  targetos=sunos
460bbea4050SPeter Maydellelif check_define __HAIKU__ ; then
461ba7c60c2SPaolo Bonzini  targetos=haiku
462951fedfcSPeter Maydellelif check_define __FreeBSD__ ; then
463ba7c60c2SPaolo Bonzini  targetos=freebsd
464951fedfcSPeter Maydellelif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
465ba7c60c2SPaolo Bonzini  targetos=gnu/kfreebsd
466951fedfcSPeter Maydellelif check_define __DragonFly__ ; then
467ba7c60c2SPaolo Bonzini  targetos=dragonfly
468951fedfcSPeter Maydellelif check_define __NetBSD__; then
469ba7c60c2SPaolo Bonzini  targetos=netbsd
470951fedfcSPeter Maydellelif check_define __APPLE__; then
471ba7c60c2SPaolo Bonzini  targetos=darwin
472bbea4050SPeter Maydellelse
473951fedfcSPeter Maydell  # This is a fatal error, but don't report it yet, because we
474951fedfcSPeter Maydell  # might be going to just print the --help text, or it might
475951fedfcSPeter Maydell  # be the result of a missing compiler.
476ba7c60c2SPaolo Bonzini  targetos=bogus
477bbea4050SPeter Maydellfi
478bbea4050SPeter Maydell
47965eff01bSPaolo Bonzini# OS specific
48065eff01bSPaolo Bonzini
4813b0d8643SPaolo Bonzinimingw32="no"
4823b0d8643SPaolo Bonzinibsd="no"
4833b0d8643SPaolo Bonzinilinux="no"
4843b0d8643SPaolo Bonzinisolaris="no"
48565eff01bSPaolo Bonzinicase $targetos in
48665eff01bSPaolo Bonziniwindows)
48765eff01bSPaolo Bonzini  mingw32="yes"
48865eff01bSPaolo Bonzini  plugins="no"
48965eff01bSPaolo Bonzini  pie="no"
49065eff01bSPaolo Bonzini;;
49165eff01bSPaolo Bonzinignu/kfreebsd)
49265eff01bSPaolo Bonzini  bsd="yes"
49365eff01bSPaolo Bonzini;;
49465eff01bSPaolo Bonzinifreebsd)
49565eff01bSPaolo Bonzini  bsd="yes"
49665eff01bSPaolo Bonzini  make="${MAKE-gmake}"
49765eff01bSPaolo Bonzini  # needed for kinfo_getvmmap(3) in libutil.h
49865eff01bSPaolo Bonzini;;
49965eff01bSPaolo Bonzinidragonfly)
50065eff01bSPaolo Bonzini  bsd="yes"
50165eff01bSPaolo Bonzini  make="${MAKE-gmake}"
50265eff01bSPaolo Bonzini;;
50365eff01bSPaolo Bonzininetbsd)
50465eff01bSPaolo Bonzini  bsd="yes"
50565eff01bSPaolo Bonzini  make="${MAKE-gmake}"
50665eff01bSPaolo Bonzini;;
50765eff01bSPaolo Bonziniopenbsd)
50865eff01bSPaolo Bonzini  bsd="yes"
50965eff01bSPaolo Bonzini  make="${MAKE-gmake}"
51065eff01bSPaolo Bonzini;;
51165eff01bSPaolo Bonzinidarwin)
51265eff01bSPaolo Bonzini  bsd="yes"
51365eff01bSPaolo Bonzini  darwin="yes"
51465eff01bSPaolo Bonzini  # Disable attempts to use ObjectiveC features in os/object.h since they
51565eff01bSPaolo Bonzini  # won't work when we're compiling with gcc as a C compiler.
51665eff01bSPaolo Bonzini  QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
51765eff01bSPaolo Bonzini;;
51865eff01bSPaolo Bonzinisunos)
51965eff01bSPaolo Bonzini  solaris="yes"
52065eff01bSPaolo Bonzini  make="${MAKE-gmake}"
52165eff01bSPaolo Bonzini# needed for CMSG_ macros in sys/socket.h
52265eff01bSPaolo Bonzini  QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
52365eff01bSPaolo Bonzini# needed for TIOCWIN* defines in termios.h
52465eff01bSPaolo Bonzini  QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
52565eff01bSPaolo Bonzini  # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
52665eff01bSPaolo Bonzini  # Note that this check is broken for cross-compilation: if you're
527bbea4050SPeter Maydell  # cross-compiling to one of these OSes then you'll need to specify
528bbea4050SPeter Maydell  # the correct CPU with the --cpu option.
529bbea4050SPeter Maydell  if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
530bbea4050SPeter Maydell    cpu="x86_64"
531bbea4050SPeter Maydell  fi
53265eff01bSPaolo Bonzini;;
53365eff01bSPaolo Bonzinihaiku)
53465eff01bSPaolo Bonzini  pie="no"
53565eff01bSPaolo Bonzini  QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
53665eff01bSPaolo Bonzini;;
53765eff01bSPaolo Bonzinilinux)
53865eff01bSPaolo Bonzini  linux="yes"
53965eff01bSPaolo Bonzini;;
540bbea4050SPeter Maydellesac
541bbea4050SPeter Maydell
5422ff6b91eSJuan Quintelaif test ! -z "$cpu" ; then
5432ff6b91eSJuan Quintela  # command line argument
5442ff6b91eSJuan Quintela  :
5452ff6b91eSJuan Quintelaelif check_define __i386__ ; then
546ac0df51dSaliguori  cpu="i386"
547ac0df51dSaliguorielif check_define __x86_64__ ; then
548c72b26ecSRichard Henderson  if check_define __ILP32__ ; then
549c72b26ecSRichard Henderson    cpu="x32"
550c72b26ecSRichard Henderson  else
551ac0df51dSaliguori    cpu="x86_64"
552c72b26ecSRichard Henderson  fi
5533aa9bd6cSblueswir1elif check_define __sparc__ ; then
5543aa9bd6cSblueswir1  if check_define __arch64__ ; then
5553aa9bd6cSblueswir1    cpu="sparc64"
5563aa9bd6cSblueswir1  else
5573aa9bd6cSblueswir1    cpu="sparc"
5583aa9bd6cSblueswir1  fi
559fdf7ed96Smalcelif check_define _ARCH_PPC ; then
560fdf7ed96Smalc  if check_define _ARCH_PPC64 ; then
561f8378accSRichard Henderson    if check_define _LITTLE_ENDIAN ; then
562f8378accSRichard Henderson      cpu="ppc64le"
563f8378accSRichard Henderson    else
564fdf7ed96Smalc      cpu="ppc64"
565f8378accSRichard Henderson    fi
566ac0df51dSaliguori  else
567fdf7ed96Smalc    cpu="ppc"
568fdf7ed96Smalc  fi
569afa05235SAurelien Jarnoelif check_define __mips__ ; then
570afa05235SAurelien Jarno  cpu="mips"
571d66ed0eaSAurelien Jarnoelif check_define __s390__ ; then
572d66ed0eaSAurelien Jarno  if check_define __s390x__ ; then
573d66ed0eaSAurelien Jarno    cpu="s390x"
574d66ed0eaSAurelien Jarno  else
575d66ed0eaSAurelien Jarno    cpu="s390"
576d66ed0eaSAurelien Jarno  fi
577c4f80543SAlistair Franciselif check_define __riscv ; then
578ba0e7333SRichard Henderson  cpu="riscv"
57921d89f84SPeter Maydellelif check_define __arm__ ; then
58021d89f84SPeter Maydell  cpu="arm"
5811f080313SClaudio Fontanaelif check_define __aarch64__ ; then
5821f080313SClaudio Fontana  cpu="aarch64"
583dfcf900bSWANG Xueruielif check_define __loongarch64 ; then
584dfcf900bSWANG Xuerui  cpu="loongarch64"
585fdf7ed96Smalcelse
58689138857SStefan Weil  cpu=$(uname -m)
587ac0df51dSaliguorifi
588ac0df51dSaliguori
589823eb013SPaolo Bonzini# Normalise host CPU name, set multilib cflags
590359bc95dSPeter Maydell# Note that this case should only have supported host CPUs, not guests.
5917d13299dSbellardcase "$cpu" in
592e4da0e39SPaolo Bonzini  armv*b|armv*l|arm)
593e4da0e39SPaolo Bonzini    cpu="arm" ;;
594e4da0e39SPaolo Bonzini
5957d13299dSbellard  i386|i486|i586|i686|i86pc|BePC)
59697a847bcSbellard    cpu="i386"
597e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32" ;;
598e4da0e39SPaolo Bonzini  x32)
5994da270beSPaolo Bonzini    cpu="x86_64"
600e4da0e39SPaolo Bonzini    CPU_CFLAGS="-mx32" ;;
601aaa5fa14Saurel32  x86_64|amd64)
602aaa5fa14Saurel32    cpu="x86_64"
603e4da0e39SPaolo Bonzini    # ??? Only extremely old AMD cpus do not have cmpxchg16b.
604e4da0e39SPaolo Bonzini    # If we truly care, we should simply detect this case at
605e4da0e39SPaolo Bonzini    # runtime and generate the fallback to serial emulation.
606e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64 -mcx16" ;;
607e4da0e39SPaolo Bonzini
608afa05235SAurelien Jarno  mips*)
609e4da0e39SPaolo Bonzini    cpu="mips" ;;
610e4da0e39SPaolo Bonzini
611e4da0e39SPaolo Bonzini  ppc)
612e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32" ;;
613e4da0e39SPaolo Bonzini  ppc64)
614ced5cfffSMiroslav Rezanina    CPU_CFLAGS="-m64 -mbig-endian" ;;
615e4da0e39SPaolo Bonzini  ppc64le)
616d8ff892dSPaolo Bonzini    cpu="ppc64"
617ced5cfffSMiroslav Rezanina    CPU_CFLAGS="-m64 -mlittle-endian" ;;
618e4da0e39SPaolo Bonzini
619e4da0e39SPaolo Bonzini  s390)
620823eb013SPaolo Bonzini    CPU_CFLAGS="-m31" ;;
621e4da0e39SPaolo Bonzini  s390x)
622e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64" ;;
623e4da0e39SPaolo Bonzini
6243142255cSblueswir1  sparc|sun4[cdmuv])
625ae228531Sbellard    cpu="sparc"
626e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
627e4da0e39SPaolo Bonzini  sparc64)
628e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
6297d13299dSbellardesac
630e2d52ad3SJuan Quintela
6310db4a067SPaolo Bonzini: ${make=${MAKE-make}}
632b6daf4d3SPaolo Bonzini
633faf44142SDaniel P. Berrangé# We prefer python 3.x. A bare 'python' is traditionally
634faf44142SDaniel P. Berrangé# python 2.x, but some distros have it as python 3.x, so
635ddf90699SEduardo Habkost# we check that too
636faf44142SDaniel P. Berrangépython=
6370a01d76fSMarc-André Lureauexplicit_python=no
638ddf90699SEduardo Habkostfor binary in "${PYTHON-python3}" python
639faf44142SDaniel P. Berrangédo
640faf44142SDaniel P. Berrangé    if has "$binary"
641faf44142SDaniel P. Berrangé    then
64295c5f2deSPaolo Bonzini        python=$(command -v "$binary")
643faf44142SDaniel P. Berrangé        break
644faf44142SDaniel P. Berrangé    fi
645faf44142SDaniel P. Berrangédone
646903458c8SMarkus Armbruster
647903458c8SMarkus Armbruster
64839d87c8cSAlex Bennée# Check for ancillary tools used in testing
64939d87c8cSAlex Bennéegenisoimage=
6503df437c7SAlex Bennéefor binary in genisoimage mkisofs
65139d87c8cSAlex Bennéedo
65239d87c8cSAlex Bennée    if has $binary
65339d87c8cSAlex Bennée    then
65439d87c8cSAlex Bennée        genisoimage=$(command -v "$binary")
65539d87c8cSAlex Bennée        break
65639d87c8cSAlex Bennée    fi
65739d87c8cSAlex Bennéedone
65839d87c8cSAlex Bennée
6593c4a4d0dSPeter Maydell# Default objcc to clang if available, otherwise use CC
6603c4a4d0dSPeter Maydellif has clang; then
6613c4a4d0dSPeter Maydell  objcc=clang
6623c4a4d0dSPeter Maydellelse
6633c4a4d0dSPeter Maydell  objcc="$cc"
6643c4a4d0dSPeter Maydellfi
6653c4a4d0dSPeter Maydell
6663457a3f8SJuan Quintelaif test "$mingw32" = "yes" ; then
6673457a3f8SJuan Quintela  EXESUF=".exe"
66878e9d4adSStefan Weil  # MinGW needs -mthreads for TLS and macro _MT.
6695770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
67093b25869SJohn Snow  write_c_skeleton;
671d17f305aSPaolo Bonzini  prefix="/qemu"
672c09c1ce7SPaolo Bonzini  bindir=""
67377433a5fSMarc-André Lureau  qemu_suffix=""
6743457a3f8SJuan Quintelafi
6753457a3f8SJuan Quintela
676487fefdbSAnthony Liguoriwerror=""
67785aa5189Sbellard
67861d63097SPaolo Bonzini. $source_path/scripts/meson-buildoptions.sh
67961d63097SPaolo Bonzini
68061d63097SPaolo Bonzinimeson_options=
681c54b59eeSPaolo Bonzinimeson_option_add() {
682c54b59eeSPaolo Bonzini  meson_options="$meson_options $(quote_sh "$1")"
683c54b59eeSPaolo Bonzini}
68461d63097SPaolo Bonzinimeson_option_parse() {
68561d63097SPaolo Bonzini  meson_options="$meson_options $(_meson_option_parse "$@")"
68661d63097SPaolo Bonzini  if test $? -eq 1; then
68761d63097SPaolo Bonzini    echo "ERROR: unknown option $1"
68861d63097SPaolo Bonzini    echo "Try '$0 --help' for more information"
68961d63097SPaolo Bonzini    exit 1
69061d63097SPaolo Bonzini  fi
69161d63097SPaolo Bonzini}
69261d63097SPaolo Bonzini
6937d13299dSbellardfor opt do
69489138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
6957d13299dSbellard  case "$opt" in
6962efc3265Sbellard  --help|-h) show_help=yes
6972efc3265Sbellard  ;;
69899123e13SMike Frysinger  --version|-V) exec cat $source_path/VERSION
69999123e13SMike Frysinger  ;;
700b1a550a0Spbrook  --prefix=*) prefix="$optarg"
7017d13299dSbellard  ;;
702ac0df51dSaliguori  --cross-prefix=*)
7037d13299dSbellard  ;;
704ac0df51dSaliguori  --cc=*)
7057d13299dSbellard  ;;
706b1a550a0Spbrook  --host-cc=*) host_cc="$optarg"
70783469015Sbellard  ;;
70883f73fceSTomoki Sekiyama  --cxx=*)
70983f73fceSTomoki Sekiyama  ;;
7103c4a4d0dSPeter Maydell  --objcc=*) objcc="$optarg"
7113c4a4d0dSPeter Maydell  ;;
712b1a550a0Spbrook  --make=*) make="$optarg"
7137d13299dSbellard  ;;
714b6daf4d3SPaolo Bonzini  --install=*)
7156a882643Spbrook  ;;
7160a01d76fSMarc-André Lureau  --python=*) python="$optarg" ; explicit_python=yes
717c886edfbSBlue Swirl  ;;
718a5665051SPaolo Bonzini  --skip-meson) skip_meson=yes
719a5665051SPaolo Bonzini  ;;
720a5665051SPaolo Bonzini  --meson=*) meson="$optarg"
721a5665051SPaolo Bonzini  ;;
72248328880SPaolo Bonzini  --ninja=*) ninja="$optarg"
72348328880SPaolo Bonzini  ;;
724e2d8830eSBrad  --smbd=*) smbd="$optarg"
725e2d8830eSBrad  ;;
726e2a2ed06SJuan Quintela  --extra-cflags=*)
7277d13299dSbellard  ;;
72811cde1c8SBruno Dominguez  --extra-cxxflags=*)
72911cde1c8SBruno Dominguez  ;;
730e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=*)
731e910c7d9SPhilippe Mathieu-Daudé  ;;
732e2a2ed06SJuan Quintela  --extra-ldflags=*)
7337d13299dSbellard  ;;
734d75402b5SAlex Bennée  --cross-cc-*)
735d75402b5SAlex Bennée  ;;
7365adb43beSPaolo Bonzini  --cross-prefix-*)
7375adb43beSPaolo Bonzini  ;;
738c54b59eeSPaolo Bonzini  --enable-debug-info) meson_option_add -Ddebug=true
73928609749SPaolo Bonzini  ;;
740c54b59eeSPaolo Bonzini  --disable-debug-info) meson_option_add -Ddebug=false
74128609749SPaolo Bonzini  ;;
74217969268SFam Zheng  --enable-modules)
74317969268SFam Zheng      modules="yes"
74417969268SFam Zheng  ;;
7453aa88b31SStefan Hajnoczi  --disable-modules)
7463aa88b31SStefan Hajnoczi      modules="no"
7473aa88b31SStefan Hajnoczi  ;;
7482ff6b91eSJuan Quintela  --cpu=*)
7497d13299dSbellard  ;;
750b1a550a0Spbrook  --target-list=*) target_list="$optarg"
751447e133fSAlex Bennée                   if test "$target_list_exclude"; then
752447e133fSAlex Bennée                       error_exit "Can't mix --target-list with --target-list-exclude"
753447e133fSAlex Bennée                   fi
754447e133fSAlex Bennée  ;;
755447e133fSAlex Bennée  --target-list-exclude=*) target_list_exclude="$optarg"
756447e133fSAlex Bennée                   if test "$target_list"; then
757447e133fSAlex Bennée                       error_exit "Can't mix --target-list-exclude with --target-list"
758447e133fSAlex Bennée                   fi
759de83cd02Sbellard  ;;
760c54b59eeSPaolo Bonzini  --with-default-devices) meson_option_add -Ddefault_devices=true
761f3494749SPaolo Bonzini  ;;
762c54b59eeSPaolo Bonzini  --without-default-devices) meson_option_add -Ddefault_devices=false
763f3494749SPaolo Bonzini  ;;
764d1d5e9eeSAlex Bennée  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
765d1d5e9eeSAlex Bennée  ;;
766d1d5e9eeSAlex Bennée  --with-devices-*) device_arch=${opt#--with-devices-};
767d1d5e9eeSAlex Bennée                    device_arch=${device_arch%%=*}
768d1d5e9eeSAlex Bennée                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
769d1d5e9eeSAlex Bennée                    if test -f "$cf"; then
770d1d5e9eeSAlex Bennée                        device_archs="$device_archs $device_arch"
771d1d5e9eeSAlex Bennée                        eval "devices_${device_arch}=\$optarg"
772d1d5e9eeSAlex Bennée                    else
773d1d5e9eeSAlex Bennée                        error_exit "File $cf does not exist"
774d1d5e9eeSAlex Bennée                    fi
775d1d5e9eeSAlex Bennée  ;;
776c87ea116SAlex Bennée  --without-default-features) # processed above
777c87ea116SAlex Bennée  ;;
77879427693SLoïc Minier  --static)
77979427693SLoïc Minier    static="yes"
78017884d7bSSergei Trofimovich    QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
78143ce4dfeSbellard  ;;
7820b24e75fSPaolo Bonzini  --bindir=*) bindir="$optarg"
7830b24e75fSPaolo Bonzini  ;;
78477433a5fSMarc-André Lureau  --with-suffix=*) qemu_suffix="$optarg"
785023d3d67SEduardo Habkost  ;;
786181ce1d0SOlaf Hering  --host=*|--build=*|\
787181ce1d0SOlaf Hering  --disable-dependency-tracking|\
788785c23aeSLuiz Capitulino  --sbindir=*|--sharedstatedir=*|\
789fe0038beSPaolo Bonzini  --oldincludedir=*|--datarootdir=*|--infodir=*|\
790023ddd74SMax Filippov  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
791023ddd74SMax Filippov    # These switches are silently ignored, for compatibility with
792023ddd74SMax Filippov    # autoconf-generated configure scripts. This allows QEMU's
793023ddd74SMax Filippov    # configure to be used by RPM and similar macros that set
794023ddd74SMax Filippov    # lots of directory switches by default.
795023ddd74SMax Filippov  ;;
796f8393946Saurel32  --enable-debug-tcg) debug_tcg="yes"
797f8393946Saurel32  ;;
798f8393946Saurel32  --disable-debug-tcg) debug_tcg="no"
799f8393946Saurel32  ;;
800f3d08ee6SPaul Brook  --enable-debug)
801f3d08ee6SPaul Brook      # Enable debugging options that aren't excessively noisy
802f3d08ee6SPaul Brook      debug_tcg="yes"
803c55cf6abSPaolo Bonzini      meson_option_parse --enable-debug-mutex ""
804c54b59eeSPaolo Bonzini      meson_option_add -Doptimization=0
805b553a042SJohn Snow      fortify_source="no"
806f3d08ee6SPaul Brook  ;;
807247724cbSMarc-André Lureau  --enable-sanitizers) sanitizers="yes"
808247724cbSMarc-André Lureau  ;;
809247724cbSMarc-André Lureau  --disable-sanitizers) sanitizers="no"
810247724cbSMarc-André Lureau  ;;
8110aebab04SLingfeng Yang  --enable-tsan) tsan="yes"
8120aebab04SLingfeng Yang  ;;
8130aebab04SLingfeng Yang  --disable-tsan) tsan="no"
8140aebab04SLingfeng Yang  ;;
8154d34a86bSPaolo Bonzini  --disable-slirp) slirp="disabled"
816c20709aaSbellard  ;;
817fd6fc214SPaolo Bonzini  --enable-slirp) slirp="enabled"
818fd6fc214SPaolo Bonzini  ;;
8194d34a86bSPaolo Bonzini  --enable-slirp=git) slirp="internal"
8207c57bdd8SMarc-André Lureau  ;;
82103a3c0b3SPaolo Bonzini  --enable-slirp=*) slirp="$optarg"
822675b9b53SMarc-André Lureau  ;;
8231badb709SPaolo Bonzini  --disable-tcg) tcg="disabled"
824d1a14257SAlex Bennée                 plugins="no"
825b3f6ea7eSPaolo Bonzini  ;;
8261badb709SPaolo Bonzini  --enable-tcg) tcg="enabled"
827b3f6ea7eSPaolo Bonzini  ;;
828cad25d69Spbrook  --disable-system) softmmu="no"
8290a8e90f4Spbrook  ;;
830cad25d69Spbrook  --enable-system) softmmu="yes"
8310a8e90f4Spbrook  ;;
8320953a80fSZachary Amsden  --disable-user)
8330953a80fSZachary Amsden      linux_user="no" ;
8340953a80fSZachary Amsden      bsd_user="no" ;
8350953a80fSZachary Amsden  ;;
8360953a80fSZachary Amsden  --enable-user) ;;
837831b7825Sths  --disable-linux-user) linux_user="no"
8380a8e90f4Spbrook  ;;
839831b7825Sths  --enable-linux-user) linux_user="yes"
840831b7825Sths  ;;
84184778508Sblueswir1  --disable-bsd-user) bsd_user="no"
84284778508Sblueswir1  ;;
84384778508Sblueswir1  --enable-bsd-user) bsd_user="yes"
84484778508Sblueswir1  ;;
84540d6444eSAvi Kivity  --enable-pie) pie="yes"
84634005a00SKirill A. Shutemov  ;;
84740d6444eSAvi Kivity  --disable-pie) pie="no"
84834005a00SKirill A. Shutemov  ;;
84985aa5189Sbellard  --enable-werror) werror="yes"
85085aa5189Sbellard  ;;
85185aa5189Sbellard  --disable-werror) werror="no"
85285aa5189Sbellard  ;;
85363678e17SSteven Noonan  --enable-stack-protector) stack_protector="yes"
85463678e17SSteven Noonan  ;;
85563678e17SSteven Noonan  --disable-stack-protector) stack_protector="no"
85663678e17SSteven Noonan  ;;
8571e4f6065SDaniele Buono  --enable-safe-stack) safe_stack="yes"
8581e4f6065SDaniele Buono  ;;
8591e4f6065SDaniele Buono  --disable-safe-stack) safe_stack="no"
8601e4f6065SDaniele Buono  ;;
8619e62ba48SDaniele Buono  --enable-cfi)
8629e62ba48SDaniele Buono      cfi="true";
863c54b59eeSPaolo Bonzini      meson_option_add -Db_lto=true
8649e62ba48SDaniele Buono  ;;
8659e62ba48SDaniele Buono  --disable-cfi) cfi="false"
8669e62ba48SDaniele Buono  ;;
867fbb4121dSPaolo Bonzini  --disable-fdt) fdt="disabled"
8682df87df7SJuan Quintela  ;;
869fbb4121dSPaolo Bonzini  --enable-fdt) fdt="enabled"
870fbb4121dSPaolo Bonzini  ;;
871fbb4121dSPaolo Bonzini  --enable-fdt=git) fdt="internal"
872fbb4121dSPaolo Bonzini  ;;
87303a3c0b3SPaolo Bonzini  --enable-fdt=*) fdt="$optarg"
8742df87df7SJuan Quintela  ;;
875519175a2SAlex Barcelo  --with-coroutine=*) coroutine="$optarg"
876519175a2SAlex Barcelo  ;;
8771ffb3bbbSPaolo Bonzini  --disable-zlib-test)
8781ece9905SAlon Levy  ;;
87952b53c04SFam Zheng  --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
88052b53c04SFam Zheng      echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
881583f6e7bSStefan Hajnoczi  ;;
882cb6414dfSFam Zheng  --enable-vhdx|--disable-vhdx)
883cb6414dfSFam Zheng      echo "$0: $opt is obsolete, VHDX driver is always built" >&2
884cb6414dfSFam Zheng  ;;
885315d3184SFam Zheng  --enable-uuid|--disable-uuid)
886315d3184SFam Zheng      echo "$0: $opt is obsolete, UUID support is always built" >&2
887315d3184SFam Zheng  ;;
888cc84d63aSDaniel P. Berrange  --with-git=*) git="$optarg"
889cc84d63aSDaniel P. Berrange  ;;
8907d7dbf9dSDan Streetman  --with-git-submodules=*)
8917d7dbf9dSDan Streetman      git_submodules_action="$optarg"
892f62bbee5SDaniel P. Berrange  ;;
8939b8e4298SAlex Bennée  --enable-plugins) if test "$mingw32" = "yes"; then
8949b8e4298SAlex Bennée                        error_exit "TCG plugins not currently supported on Windows platforms"
8959b8e4298SAlex Bennée                    else
8969b8e4298SAlex Bennée                        plugins="yes"
8979b8e4298SAlex Bennée                    fi
89840e8c6f4SAlex Bennée  ;;
89940e8c6f4SAlex Bennée  --disable-plugins) plugins="no"
90040e8c6f4SAlex Bennée  ;;
901afc3a8f9SAlex Bennée  --enable-containers) use_containers="yes"
902afc3a8f9SAlex Bennée  ;;
903afc3a8f9SAlex Bennée  --disable-containers) use_containers="no"
904afc3a8f9SAlex Bennée  ;;
905f48e590aSAlex Bennée  --gdb=*) gdb_bin="$optarg"
906f48e590aSAlex Bennée  ;;
9073b4da132SPaolo Bonzini  # backwards compatibility options
9083b4da132SPaolo Bonzini  --enable-trace-backend=*) meson_option_parse "--enable-trace-backends=$optarg" "$optarg"
9093b4da132SPaolo Bonzini  ;;
9103b4da132SPaolo Bonzini  --disable-blobs) meson_option_parse --disable-install-blobs ""
9113b4da132SPaolo Bonzini  ;;
9123b4da132SPaolo Bonzini  --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
9133b4da132SPaolo Bonzini  ;;
9143b4da132SPaolo Bonzini  --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
9153b4da132SPaolo Bonzini  ;;
9163b4da132SPaolo Bonzini  # everything else has the same name in configure and meson
9174fda6011SPaolo Bonzini  --*) meson_option_parse "$opt" "$optarg"
9187f1559c6Sbalrog  ;;
9197d13299dSbellard  esac
9207d13299dSbellarddone
9217d13299dSbellard
922d1a14257SAlex Bennée# test for any invalid configuration combinations
923d1a14257SAlex Bennéeif test "$plugins" = "yes" -a "$tcg" = "disabled"; then
924d1a14257SAlex Bennée    error_exit "Can't enable plugins on non-TCG builds"
925d1a14257SAlex Bennéefi
926d1a14257SAlex Bennée
9277d7dbf9dSDan Streetmancase $git_submodules_action in
9287d7dbf9dSDan Streetman    update|validate)
9297d7dbf9dSDan Streetman        if test ! -e "$source_path/.git"; then
9307d7dbf9dSDan Streetman            echo "ERROR: cannot $git_submodules_action git submodules without .git"
9317d7dbf9dSDan Streetman            exit 1
9327d7dbf9dSDan Streetman        fi
9337d7dbf9dSDan Streetman    ;;
9347d7dbf9dSDan Streetman    ignore)
935b80fd281SPaolo Bonzini        if ! test -f "$source_path/ui/keycodemapdb/README"
936b80fd281SPaolo Bonzini        then
937b80fd281SPaolo Bonzini            echo
938b80fd281SPaolo Bonzini            echo "ERROR: missing GIT submodules"
939b80fd281SPaolo Bonzini            echo
940b80fd281SPaolo Bonzini            if test -e "$source_path/.git"; then
941b80fd281SPaolo Bonzini                echo "--with-git-submodules=ignore specified but submodules were not"
942b80fd281SPaolo Bonzini                echo "checked out.  Please initialize and update submodules."
943b80fd281SPaolo Bonzini            else
944b80fd281SPaolo Bonzini                echo "This is not a GIT checkout but module content appears to"
945b80fd281SPaolo Bonzini                echo "be missing. Do not use 'git archive' or GitHub download links"
946b80fd281SPaolo Bonzini                echo "to acquire QEMU source archives. Non-GIT builds are only"
947b80fd281SPaolo Bonzini                echo "supported with source archives linked from:"
948b80fd281SPaolo Bonzini                echo
949b80fd281SPaolo Bonzini                echo "  https://www.qemu.org/download/#source"
950b80fd281SPaolo Bonzini                echo
951b80fd281SPaolo Bonzini                echo "Developers working with GIT can use scripts/archive-source.sh"
952b80fd281SPaolo Bonzini                echo "if they need to create valid source archives."
953b80fd281SPaolo Bonzini            fi
954b80fd281SPaolo Bonzini            echo
955b80fd281SPaolo Bonzini            exit 1
956b80fd281SPaolo Bonzini        fi
9577d7dbf9dSDan Streetman    ;;
9587d7dbf9dSDan Streetman    *)
9597d7dbf9dSDan Streetman        echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
9607d7dbf9dSDan Streetman        exit 1
9617d7dbf9dSDan Streetman    ;;
9627d7dbf9dSDan Streetmanesac
9637d7dbf9dSDan Streetman
96460e0df25SPeter Maydelldefault_target_list=""
9656e92f823SPeter Maydellmak_wilds=""
9666e92f823SPeter Maydell
967b915a2f1SPaolo Bonziniif [ "$linux_user" != no ]; then
968b915a2f1SPaolo Bonzini    if [ "$targetos" = linux ] && [ -d $source_path/linux-user/include/host/$cpu ]; then
969b915a2f1SPaolo Bonzini        linux_user=yes
970b915a2f1SPaolo Bonzini    elif [ "$linux_user" = yes ]; then
971b915a2f1SPaolo Bonzini        error_exit "linux-user not supported on this architecture"
972b915a2f1SPaolo Bonzini    fi
973b915a2f1SPaolo Bonzinifi
974b915a2f1SPaolo Bonziniif [ "$bsd_user" != no ]; then
975b915a2f1SPaolo Bonzini    if [ "$bsd_user" = "" ]; then
976b915a2f1SPaolo Bonzini        test $targetos = freebsd && bsd_user=yes
977b915a2f1SPaolo Bonzini    fi
978b915a2f1SPaolo Bonzini    if [ "$bsd_user" = yes ] && ! [ -d $source_path/bsd-user/$targetos ]; then
979b915a2f1SPaolo Bonzini        error_exit "bsd-user not supported on this host OS"
980b915a2f1SPaolo Bonzini    fi
981b915a2f1SPaolo Bonzinifi
98260e0df25SPeter Maydellif [ "$softmmu" = "yes" ]; then
983812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
98460e0df25SPeter Maydellfi
98560e0df25SPeter Maydellif [ "$linux_user" = "yes" ]; then
986812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
98760e0df25SPeter Maydellfi
98860e0df25SPeter Maydellif [ "$bsd_user" = "yes" ]; then
989812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
99060e0df25SPeter Maydellfi
99160e0df25SPeter Maydell
992447e133fSAlex Bennéefor config in $mak_wilds; do
993447e133fSAlex Bennée    target="$(basename "$config" .mak)"
99498db9a06SAlex Bennée    if echo "$target_list_exclude" | grep -vq "$target"; then
995447e133fSAlex Bennée        default_target_list="${default_target_list} $target"
996447e133fSAlex Bennée    fi
997447e133fSAlex Bennéedone
9986e92f823SPeter Maydell
999af5db58eSpbrookif test x"$show_help" = x"yes" ; then
1000af5db58eSpbrookcat << EOF
1001af5db58eSpbrook
1002af5db58eSpbrookUsage: configure [options]
1003af5db58eSpbrookOptions: [defaults in brackets after descriptions]
1004af5db58eSpbrook
100508fb77edSStefan WeilStandard options:
100608fb77edSStefan Weil  --help                   print this message
100708fb77edSStefan Weil  --prefix=PREFIX          install in PREFIX [$prefix]
100874154d7eSThomas Huth  --target-list=LIST       set target list (default: build all)
100908fb77edSStefan Weil$(echo Available targets: $default_target_list | \
101008fb77edSStefan Weil  fold -s -w 53 | sed -e 's/^/                           /')
1011447e133fSAlex Bennée  --target-list-exclude=LIST exclude a set of targets from the default target-list
101208fb77edSStefan Weil
101308fb77edSStefan WeilAdvanced options (experts only):
10143812c0c4SJoelle van Dyne  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
101508fb77edSStefan Weil  --cc=CC                  use C compiler CC [$cc]
101608fb77edSStefan Weil  --host-cc=CC             use C compiler CC [$host_cc] for code run at
101708fb77edSStefan Weil                           build time
101808fb77edSStefan Weil  --cxx=CXX                use C++ compiler CXX [$cxx]
101908fb77edSStefan Weil  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
1020a2866660SPaolo Bonzini  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
1021a2866660SPaolo Bonzini  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
1022e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
102308fb77edSStefan Weil  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
1024d75402b5SAlex Bennée  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
1025479ca4ccSMatheus Ferst  --cross-cc-cflags-ARCH=  use compiler flags when building ARCH guest tests
10265adb43beSPaolo Bonzini  --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
102708fb77edSStefan Weil  --make=MAKE              use specified make [$make]
102808fb77edSStefan Weil  --python=PYTHON          use specified python [$python]
1029a5665051SPaolo Bonzini  --meson=MESON            use specified meson [$meson]
103048328880SPaolo Bonzini  --ninja=NINJA            use specified ninja [$ninja]
103108fb77edSStefan Weil  --smbd=SMBD              use specified smbd [$smbd]
1032db1b5f13SThomas Huth  --with-git=GIT           use specified git [$git]
10337d7dbf9dSDan Streetman  --with-git-submodules=update   update git submodules (default if .git dir exists)
10347d7dbf9dSDan Streetman  --with-git-submodules=validate fail if git submodules are not up to date
10357d7dbf9dSDan Streetman  --with-git-submodules=ignore   do not update or check git submodules (default if no .git dir)
103608fb77edSStefan Weil  --static                 enable static build [$static]
103708fb77edSStefan Weil  --bindir=PATH            install binaries in PATH
103813336606SRobert Foley  --efi-aarch64=PATH       PATH of efi file to use for aarch64 VMs.
1039ca8c0909SMarc-André Lureau  --with-suffix=SUFFIX     suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
1040c035c8d6SPaolo Bonzini  --without-default-features default all --enable-* options to "disabled"
1041c035c8d6SPaolo Bonzini  --without-default-devices  do not include any device that is not needed to
1042c035c8d6SPaolo Bonzini                           start the emulator (only use if you are including
1043d1d5e9eeSAlex Bennée                           desired devices in configs/devices/)
1044d1d5e9eeSAlex Bennée  --with-devices-ARCH=NAME override default configs/devices
104508fb77edSStefan Weil  --enable-debug           enable common debug build options
1046247724cbSMarc-André Lureau  --enable-sanitizers      enable default sanitizers
10470aebab04SLingfeng Yang  --enable-tsan            enable thread sanitizer
104808fb77edSStefan Weil  --disable-werror         disable compilation abort on warning
104963678e17SSteven Noonan  --disable-stack-protector disable compiler-provided stack protection
1050c23f23b9SMichael Tokarev  --cpu=CPU                Build for host CPU [$cpu]
105108fb77edSStefan Weil  --with-coroutine=BACKEND coroutine backend. Supported options:
105233c53c54SDaniel P. Berrange                           ucontext, sigaltstack, windows
105340e8c6f4SAlex Bennée  --enable-plugins
105440e8c6f4SAlex Bennée                           enable plugins via shared library loading
1055afc3a8f9SAlex Bennée  --disable-containers     don't use containers for cross-building
1056f48e590aSAlex Bennée  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
105761d63097SPaolo BonziniEOF
105861d63097SPaolo Bonzini  meson_options_help
105961d63097SPaolo Bonzinicat << EOF
1060c23f23b9SMichael Tokarev  system          all system emulation targets
1061c23f23b9SMichael Tokarev  user            supported user emulation targets
1062c23f23b9SMichael Tokarev  linux-user      all linux usermode emulation targets
1063c23f23b9SMichael Tokarev  bsd-user        all BSD usermode emulation targets
1064c23f23b9SMichael Tokarev  pie             Position Independent Executables
106521e709aaSMarc-André Lureau  modules         modules support (non-Windows)
1066c23f23b9SMichael Tokarev  debug-tcg       TCG debugging (default is disabled)
1067c23f23b9SMichael Tokarev  debug-info      debugging information
10681e4f6065SDaniele Buono  safe-stack      SafeStack Stack Smash Protection. Depends on
10691e4f6065SDaniele Buono                  clang/llvm >= 3.7 and requires coroutine backend ucontext.
107008fb77edSStefan Weil
107108fb77edSStefan WeilNOTE: The object files are built at the place where configure is launched
1072af5db58eSpbrookEOF
10732d2ad6d0SFam Zhengexit 0
1074af5db58eSpbrookfi
1075af5db58eSpbrook
10769c790242SThomas Huth# Remove old dependency files to make sure that they get properly regenerated
1077bb768f71SThomas Huthrm -f */config-devices.mak.d
10789c790242SThomas Huth
1079faf44142SDaniel P. Berrangéif test -z "$python"
1080faf44142SDaniel P. Berrangéthen
1081c53eeaf7SStefan Hajnoczi    error_exit "Python not found. Use --python=/path/to/python"
1082c53eeaf7SStefan Hajnoczifi
10838e2c76bdSRoman Bolshakovif ! has "$make"
10848e2c76bdSRoman Bolshakovthen
10858e2c76bdSRoman Bolshakov    error_exit "GNU make ($make) not found"
10868e2c76bdSRoman Bolshakovfi
1087c53eeaf7SStefan Hajnoczi
1088c53eeaf7SStefan Hajnoczi# Note that if the Python conditional here evaluates True we will exit
1089c53eeaf7SStefan Hajnoczi# with status 1 which is a shell 'false' value.
10901b11f28dSThomas Huthif ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then
10911b11f28dSThomas Huth  error_exit "Cannot use '$python', Python >= 3.6 is required." \
1092c53eeaf7SStefan Hajnoczi      "Use --python=/path/to/python to specify a supported Python."
1093c53eeaf7SStefan Hajnoczifi
1094c53eeaf7SStefan Hajnoczi
1095755ee70fSCleber Rosa# Preserve python version since some functionality is dependent on it
1096406ab2f3SCleber 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)
1097755ee70fSCleber Rosa
1098c53eeaf7SStefan Hajnoczi# Suppress writing compiled files
1099c53eeaf7SStefan Hajnoczipython="$python -B"
1100c53eeaf7SStefan Hajnoczi
11010a01d76fSMarc-André Lureauif test -z "$meson"; then
11026638cae5SPaolo Bonzini    if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.59.3; then
11030a01d76fSMarc-André Lureau        meson=meson
11047d7dbf9dSDan Streetman    elif test $git_submodules_action != 'ignore' ; then
11050a01d76fSMarc-André Lureau        meson=git
11060a01d76fSMarc-André Lureau    elif test -e "${source_path}/meson/meson.py" ; then
11070a01d76fSMarc-André Lureau        meson=internal
11080a01d76fSMarc-André Lureau    else
11090a01d76fSMarc-André Lureau        if test "$explicit_python" = yes; then
11100a01d76fSMarc-André Lureau            error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
11110a01d76fSMarc-André Lureau        else
1112a5665051SPaolo Bonzini            error_exit "Meson not found.  Use --meson=/path/to/meson"
1113a5665051SPaolo Bonzini        fi
11140a01d76fSMarc-André Lureau    fi
11150a01d76fSMarc-André Lureauelse
11160a01d76fSMarc-André Lureau    # Meson uses its own Python interpreter to invoke other Python scripts,
11170a01d76fSMarc-André Lureau    # but the user wants to use the one they specified with --python.
11180a01d76fSMarc-André Lureau    #
11190a01d76fSMarc-André Lureau    # We do not want to override the distro Python interpreter (and sometimes
11200a01d76fSMarc-André Lureau    # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
11210a01d76fSMarc-André Lureau    # just require --meson=git|internal together with --python.
11220a01d76fSMarc-André Lureau    if test "$explicit_python" = yes; then
11230a01d76fSMarc-André Lureau        case "$meson" in
11240a01d76fSMarc-André Lureau            git | internal) ;;
11250a01d76fSMarc-André Lureau            *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
11260a01d76fSMarc-André Lureau        esac
11270a01d76fSMarc-André Lureau    fi
11280a01d76fSMarc-André Lureaufi
1129a5665051SPaolo Bonzini
11300a01d76fSMarc-André Lureauif test "$meson" = git; then
11310a01d76fSMarc-André Lureau    git_submodules="${git_submodules} meson"
11320a01d76fSMarc-André Lureaufi
11330a01d76fSMarc-André Lureau
11340a01d76fSMarc-André Lureaucase "$meson" in
11350a01d76fSMarc-André Lureau    git | internal)
11360a01d76fSMarc-André Lureau        meson="$python ${source_path}/meson/meson.py"
11370a01d76fSMarc-André Lureau        ;;
113884ec0c24SPaolo Bonzini    *) meson=$(command -v "$meson") ;;
11390a01d76fSMarc-André Lureauesac
11400a01d76fSMarc-André Lureau
114109e93326SPaolo Bonzini# Probe for ninja
114248328880SPaolo Bonzini
114348328880SPaolo Bonziniif test -z "$ninja"; then
114448328880SPaolo Bonzini    for c in ninja ninja-build samu; do
114548328880SPaolo Bonzini        if has $c; then
114648328880SPaolo Bonzini            ninja=$(command -v "$c")
114748328880SPaolo Bonzini            break
114848328880SPaolo Bonzini        fi
114948328880SPaolo Bonzini    done
115009e93326SPaolo Bonzini    if test -z "$ninja"; then
115109e93326SPaolo Bonzini      error_exit "Cannot find Ninja"
115209e93326SPaolo Bonzini    fi
115348328880SPaolo Bonzinifi
1154a5665051SPaolo Bonzini
11559aae6e54SDaniel Henrique Barboza# Check that the C compiler works. Doing this here before testing
11569aae6e54SDaniel Henrique Barboza# the host CPU ensures that we had a valid CC to autodetect the
11579aae6e54SDaniel Henrique Barboza# $cpu var (and we should bail right here if that's not the case).
11589aae6e54SDaniel Henrique Barboza# It also allows the help message to be printed without a CC.
11599aae6e54SDaniel Henrique Barbozawrite_c_skeleton;
11609aae6e54SDaniel Henrique Barbozaif compile_object ; then
11619aae6e54SDaniel Henrique Barboza  : C compiler works ok
11629aae6e54SDaniel Henrique Barbozaelse
11639aae6e54SDaniel Henrique Barboza    error_exit "\"$cc\" either does not exist or does not work"
11649aae6e54SDaniel Henrique Barbozafi
11659aae6e54SDaniel Henrique Barbozaif ! compile_prog ; then
11669aae6e54SDaniel Henrique Barboza    error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
11679aae6e54SDaniel Henrique Barbozafi
11689aae6e54SDaniel Henrique Barboza
11699c83ffd8SPeter Maydell# Consult white-list to determine whether to enable werror
11709c83ffd8SPeter Maydell# by default.  Only enable by default for git builds
11719c83ffd8SPeter Maydellif test -z "$werror" ; then
11727d7dbf9dSDan Streetman    if test "$git_submodules_action" != "ignore" && \
1173e633a5c6SEric Blake        { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
11749c83ffd8SPeter Maydell        werror="yes"
11759c83ffd8SPeter Maydell    else
11769c83ffd8SPeter Maydell        werror="no"
11779c83ffd8SPeter Maydell    fi
11789c83ffd8SPeter Maydellfi
11799c83ffd8SPeter Maydell
1180975ff037SPaolo Bonziniif test "$targetos" = "bogus"; then
1181fb59dabdSPeter Maydell    # Now that we know that we're not printing the help and that
1182fb59dabdSPeter Maydell    # the compiler works (so the results of the check_defines we used
1183fb59dabdSPeter Maydell    # to identify the OS are reliable), if we didn't recognize the
1184fb59dabdSPeter Maydell    # host OS we should stop now.
1185951fedfcSPeter Maydell    error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1186fb59dabdSPeter Maydellfi
1187fb59dabdSPeter Maydell
1188efc6c070SThomas Huth# Check whether the compiler matches our minimum requirements:
1189efc6c070SThomas Huthcat > $TMPC << EOF
1190efc6c070SThomas Huth#if defined(__clang_major__) && defined(__clang_minor__)
1191efc6c070SThomas Huth# ifdef __apple_build_version__
11922a85a08cSDaniel P. Berrangé#  if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
11932a85a08cSDaniel P. Berrangé#   error You need at least XCode Clang v10.0 to compile QEMU
1194efc6c070SThomas Huth#  endif
1195efc6c070SThomas Huth# else
11962a85a08cSDaniel P. Berrangé#  if __clang_major__ < 6 || (__clang_major__ == 6 && __clang_minor__ < 0)
11972a85a08cSDaniel P. Berrangé#   error You need at least Clang v6.0 to compile QEMU
1198efc6c070SThomas Huth#  endif
1199efc6c070SThomas Huth# endif
1200efc6c070SThomas Huth#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
12013830df5fSnia# if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
12023830df5fSnia#  error You need at least GCC v7.4.0 to compile QEMU
1203efc6c070SThomas Huth# endif
1204efc6c070SThomas Huth#else
1205efc6c070SThomas Huth# error You either need GCC or Clang to compiler QEMU
1206efc6c070SThomas Huth#endif
1207efc6c070SThomas Huthint main (void) { return 0; }
1208efc6c070SThomas HuthEOF
1209efc6c070SThomas Huthif ! compile_prog "" "" ; then
12103830df5fSnia    error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
1211efc6c070SThomas Huthfi
1212efc6c070SThomas Huth
121300849b92SRichard Henderson# Accumulate -Wfoo and -Wno-bar separately.
121400849b92SRichard Henderson# We will list all of the enable flags first, and the disable flags second.
121500849b92SRichard Henderson# Note that we do not add -Werror, because that would enable it for all
121600849b92SRichard Henderson# configure tests. If a configure test failed due to -Werror this would
121700849b92SRichard Henderson# just silently disable some features, so it's too error prone.
121800849b92SRichard Henderson
121900849b92SRichard Hendersonwarn_flags=
122000849b92SRichard Hendersonadd_to warn_flags -Wold-style-declaration
122100849b92SRichard Hendersonadd_to warn_flags -Wold-style-definition
122200849b92SRichard Hendersonadd_to warn_flags -Wtype-limits
122300849b92SRichard Hendersonadd_to warn_flags -Wformat-security
122400849b92SRichard Hendersonadd_to warn_flags -Wformat-y2k
122500849b92SRichard Hendersonadd_to warn_flags -Winit-self
122600849b92SRichard Hendersonadd_to warn_flags -Wignored-qualifiers
122700849b92SRichard Hendersonadd_to warn_flags -Wempty-body
122800849b92SRichard Hendersonadd_to warn_flags -Wnested-externs
122900849b92SRichard Hendersonadd_to warn_flags -Wendif-labels
123000849b92SRichard Hendersonadd_to warn_flags -Wexpansion-to-defined
12310a2ebce9SThomas Huthadd_to warn_flags -Wimplicit-fallthrough=2
123200849b92SRichard Henderson
123300849b92SRichard Hendersonnowarn_flags=
123400849b92SRichard Hendersonadd_to nowarn_flags -Wno-initializer-overrides
123500849b92SRichard Hendersonadd_to nowarn_flags -Wno-missing-include-dirs
123600849b92SRichard Hendersonadd_to nowarn_flags -Wno-shift-negative-value
123700849b92SRichard Hendersonadd_to nowarn_flags -Wno-string-plus-int
123800849b92SRichard Hendersonadd_to nowarn_flags -Wno-typedef-redefinition
1239aabab967SRichard Hendersonadd_to nowarn_flags -Wno-tautological-type-limit-compare
1240bac8d222SRichard Hendersonadd_to nowarn_flags -Wno-psabi
124100849b92SRichard Henderson
124200849b92SRichard Hendersongcc_flags="$warn_flags $nowarn_flags"
124393b25869SJohn Snow
124493b25869SJohn Snowcc_has_warning_flag() {
124593b25869SJohn Snow    write_c_skeleton;
124693b25869SJohn Snow
1247a1d29d6cSPeter Maydell    # Use the positive sense of the flag when testing for -Wno-wombat
1248a1d29d6cSPeter Maydell    # support (gcc will happily accept the -Wno- form of unknown
1249a1d29d6cSPeter Maydell    # warning options).
125093b25869SJohn Snow    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
125193b25869SJohn Snow    compile_prog "-Werror $optflag" ""
125293b25869SJohn Snow}
125393b25869SJohn Snow
12544cb37d11SPhilippe Mathieu-Daudéobjcc_has_warning_flag() {
12554cb37d11SPhilippe Mathieu-Daudé    cat > $TMPM <<EOF
12564cb37d11SPhilippe Mathieu-Daudéint main(void) { return 0; }
12574cb37d11SPhilippe Mathieu-DaudéEOF
12584cb37d11SPhilippe Mathieu-Daudé
12594cb37d11SPhilippe Mathieu-Daudé    # Use the positive sense of the flag when testing for -Wno-wombat
12604cb37d11SPhilippe Mathieu-Daudé    # support (gcc will happily accept the -Wno- form of unknown
12614cb37d11SPhilippe Mathieu-Daudé    # warning options).
12624cb37d11SPhilippe Mathieu-Daudé    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
12634cb37d11SPhilippe Mathieu-Daudé    do_objc -Werror $optflag \
12644cb37d11SPhilippe Mathieu-Daudé      $OBJCFLAGS $EXTRA_OBJCFLAGS $CONFIGURE_OBJCFLAGS $QEMU_OBJCFLAGS \
12654cb37d11SPhilippe Mathieu-Daudé      -o $TMPE $TMPM $QEMU_LDFLAGS
12664cb37d11SPhilippe Mathieu-Daudé}
12674cb37d11SPhilippe Mathieu-Daudé
126893b25869SJohn Snowfor flag in $gcc_flags; do
126993b25869SJohn Snow    if cc_has_warning_flag $flag ; then
12708d05095cSPaolo Bonzini        QEMU_CFLAGS="$QEMU_CFLAGS $flag"
12718d05095cSPaolo Bonzini    fi
12724cb37d11SPhilippe Mathieu-Daudé    if objcc_has_warning_flag $flag ; then
12734cb37d11SPhilippe Mathieu-Daudé        QEMU_OBJCFLAGS="$QEMU_OBJCFLAGS $flag"
12744cb37d11SPhilippe Mathieu-Daudé    fi
12758d05095cSPaolo Bonzinidone
12768d05095cSPaolo Bonzini
127763678e17SSteven Noonanif test "$stack_protector" != "no"; then
1278fccd35a0SRodrigo Rebello  cat > $TMPC << EOF
1279fccd35a0SRodrigo Rebelloint main(int argc, char *argv[])
1280fccd35a0SRodrigo Rebello{
1281fccd35a0SRodrigo Rebello    char arr[64], *p = arr, *c = argv[0];
1282fccd35a0SRodrigo Rebello    while (*c) {
1283fccd35a0SRodrigo Rebello        *p++ = *c++;
1284fccd35a0SRodrigo Rebello    }
1285fccd35a0SRodrigo Rebello    return 0;
1286fccd35a0SRodrigo Rebello}
1287fccd35a0SRodrigo RebelloEOF
128863678e17SSteven Noonan  gcc_flags="-fstack-protector-strong -fstack-protector-all"
12893b463a3fSMiroslav Rezanina  sp_on=0
129063678e17SSteven Noonan  for flag in $gcc_flags; do
1291590e5dd9SPeter Maydell    # We need to check both a compile and a link, since some compiler
1292590e5dd9SPeter Maydell    # setups fail only on a .c->.o compile and some only at link time
1293086d5f75SPaolo Bonzini    if compile_object "-Werror $flag" &&
1294590e5dd9SPeter Maydell       compile_prog "-Werror $flag" ""; then
129563678e17SSteven Noonan      QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1296db5adeaaSPaolo Bonzini      QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
12973b463a3fSMiroslav Rezanina      sp_on=1
129863678e17SSteven Noonan      break
129963678e17SSteven Noonan    fi
130063678e17SSteven Noonan  done
13013b463a3fSMiroslav Rezanina  if test "$stack_protector" = yes; then
13023b463a3fSMiroslav Rezanina    if test $sp_on = 0; then
13033b463a3fSMiroslav Rezanina      error_exit "Stack protector not supported"
13043b463a3fSMiroslav Rezanina    fi
13053b463a3fSMiroslav Rezanina  fi
130637746c5eSMarc-André Lureaufi
130737746c5eSMarc-André Lureau
130820bc94a2SPaolo Bonzini# Disable -Wmissing-braces on older compilers that warn even for
130920bc94a2SPaolo Bonzini# the "universal" C zero initializer {0}.
131020bc94a2SPaolo Bonzinicat > $TMPC << EOF
131120bc94a2SPaolo Bonzinistruct {
131220bc94a2SPaolo Bonzini  int a[2];
131320bc94a2SPaolo Bonzini} x = {0};
131420bc94a2SPaolo BonziniEOF
131520bc94a2SPaolo Bonziniif compile_object "-Werror" "" ; then
131620bc94a2SPaolo Bonzini  :
131720bc94a2SPaolo Bonzinielse
131820bc94a2SPaolo Bonzini  QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
131920bc94a2SPaolo Bonzinifi
132020bc94a2SPaolo Bonzini
132121e709aaSMarc-André Lureau# Our module code doesn't support Windows
132221e709aaSMarc-André Lureauif test "$modules" = "yes" && test "$mingw32" = "yes" ; then
132321e709aaSMarc-André Lureau  error_exit "Modules are not available for Windows"
132421e709aaSMarc-André Lureaufi
132521e709aaSMarc-André Lureau
13265f2453acSAlex Bennée# Static linking is not possible with plugins, modules or PIE
132740d6444eSAvi Kivityif test "$static" = "yes" ; then
1328aa0d1f44SPaolo Bonzini  if test "$modules" = "yes" ; then
1329aa0d1f44SPaolo Bonzini    error_exit "static and modules are mutually incompatible"
1330aa0d1f44SPaolo Bonzini  fi
13315f2453acSAlex Bennée  if test "$plugins" = "yes"; then
13325f2453acSAlex Bennée    error_exit "static and plugins are mutually incompatible"
1333ba4dd2aaSAlex Bennée  else
1334ba4dd2aaSAlex Bennée    plugins="no"
13355f2453acSAlex Bennée  fi
133640d6444eSAvi Kivityfi
133737650689SPaolo Bonzinitest "$plugins" = "" && plugins=yes
133840d6444eSAvi Kivity
133940d6444eSAvi Kivitycat > $TMPC << EOF
134021d4a791SAvi Kivity
134121d4a791SAvi Kivity#ifdef __linux__
134221d4a791SAvi Kivity#  define THREAD __thread
134321d4a791SAvi Kivity#else
134421d4a791SAvi Kivity#  define THREAD
134521d4a791SAvi Kivity#endif
134621d4a791SAvi Kivitystatic THREAD int tls_var;
134721d4a791SAvi Kivityint main(void) { return tls_var; }
134840d6444eSAvi KivityEOF
1349b2634124SRichard Henderson
1350ffd205efSJessica Clarke# Check we support -fno-pie and -no-pie first; we will need the former for
1351ffd205efSJessica Clarke# building ROMs, and both for everything if --disable-pie is passed.
1352412aeacdSAlex Bennéeif compile_prog "-Werror -fno-pie" "-no-pie"; then
1353412aeacdSAlex Bennée  CFLAGS_NOPIE="-fno-pie"
1354ffd205efSJessica Clarke  LDFLAGS_NOPIE="-no-pie"
1355412aeacdSAlex Bennéefi
1356412aeacdSAlex Bennée
135712781462SRichard Hendersonif test "$static" = "yes"; then
1358eca7a8e6SRichard Henderson  if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
13595770e8afSPaolo Bonzini    CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
136012781462SRichard Henderson    QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
136112781462SRichard Henderson    pie="yes"
136212781462SRichard Henderson  elif test "$pie" = "yes"; then
136312781462SRichard Henderson    error_exit "-static-pie not available due to missing toolchain support"
136412781462SRichard Henderson  else
136512781462SRichard Henderson    QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
136612781462SRichard Henderson    pie="no"
136712781462SRichard Henderson  fi
136812781462SRichard Hendersonelif test "$pie" = "no"; then
13695770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="$CFLAGS_NOPIE $CONFIGURE_CFLAGS"
1370ffd205efSJessica Clarke  CONFIGURE_LDFLAGS="$LDFLAGS_NOPIE $CONFIGURE_LDFLAGS"
1371eca7a8e6SRichard Hendersonelif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
13725770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
13735770e8afSPaolo Bonzini  CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
137440d6444eSAvi Kivity  pie="yes"
13752c674109SRichard Hendersonelif test "$pie" = "yes"; then
137676ad07a4SPeter Maydell  error_exit "PIE not available due to missing toolchain support"
137740d6444eSAvi Kivityelse
137840d6444eSAvi Kivity  echo "Disabling PIE due to missing toolchain support"
137940d6444eSAvi Kivity  pie="no"
138040d6444eSAvi Kivityfi
138140d6444eSAvi Kivity
1382e6cbd751SRichard Henderson# Detect support for PT_GNU_RELRO + DT_BIND_NOW.
1383e6cbd751SRichard Henderson# The combination is known as "full relro", because .got.plt is read-only too.
1384e6cbd751SRichard Hendersonif compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1385e6cbd751SRichard Henderson  QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
1386e6cbd751SRichard Hendersonfi
1387e6cbd751SRichard Henderson
138809dada40SPaolo Bonzini##########################################
138909dada40SPaolo Bonzini# __sync_fetch_and_and requires at least -march=i486. Many toolchains
139009dada40SPaolo Bonzini# use i686 as default anyway, but for those that don't, an explicit
139109dada40SPaolo Bonzini# specification is necessary
139209dada40SPaolo Bonzini
139309dada40SPaolo Bonziniif test "$cpu" = "i386"; then
139409dada40SPaolo Bonzini  cat > $TMPC << EOF
139509dada40SPaolo Bonzinistatic int sfaa(int *ptr)
139609dada40SPaolo Bonzini{
139709dada40SPaolo Bonzini  return __sync_fetch_and_and(ptr, 0);
139809dada40SPaolo Bonzini}
139909dada40SPaolo Bonzini
140009dada40SPaolo Bonziniint main(void)
140109dada40SPaolo Bonzini{
140209dada40SPaolo Bonzini  int val = 42;
14031405b629SStefan Weil  val = __sync_val_compare_and_swap(&val, 0, 1);
140409dada40SPaolo Bonzini  sfaa(&val);
140509dada40SPaolo Bonzini  return val;
140609dada40SPaolo Bonzini}
140709dada40SPaolo BonziniEOF
140809dada40SPaolo Bonzini  if ! compile_prog "" "" ; then
140909dada40SPaolo Bonzini    QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
141009dada40SPaolo Bonzini  fi
141109dada40SPaolo Bonzinifi
141209dada40SPaolo Bonzini
141356267b62SPhilippe Mathieu-Daudéif test "$tcg" = "enabled"; then
141456267b62SPhilippe Mathieu-Daudé    git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
141556267b62SPhilippe Mathieu-Daudé    git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
141656267b62SPhilippe Mathieu-Daudéfi
141756267b62SPhilippe Mathieu-Daudé
1418afb63ebdSStefan Weilif test -z "${target_list+xxx}" ; then
1419fdb75aefSPaolo Bonzini    default_targets=yes
1420d880a3baSPaolo Bonzini    for target in $default_target_list; do
1421d880a3baSPaolo Bonzini        target_list="$target_list $target"
1422d880a3baSPaolo Bonzini    done
1423d880a3baSPaolo Bonzini    target_list="${target_list# }"
1424121afa9eSAnthony Liguorielse
1425fdb75aefSPaolo Bonzini    default_targets=no
142689138857SStefan Weil    target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1427d880a3baSPaolo Bonzini    for target in $target_list; do
142825b48338SPeter Maydell        # Check that we recognised the target name; this allows a more
142925b48338SPeter Maydell        # friendly error message than if we let it fall through.
143025b48338SPeter Maydell        case " $default_target_list " in
143125b48338SPeter Maydell            *" $target "*)
143225b48338SPeter Maydell                ;;
143325b48338SPeter Maydell            *)
143425b48338SPeter Maydell                error_exit "Unknown target name '$target'"
143525b48338SPeter Maydell                ;;
143625b48338SPeter Maydell        esac
143725b48338SPeter Maydell    done
1438d880a3baSPaolo Bonzinifi
143925b48338SPeter Maydell
1440f55fe278SPaolo Bonzini# see if system emulation was really requested
1441f55fe278SPaolo Bonzinicase " $target_list " in
1442f55fe278SPaolo Bonzini  *"-softmmu "*) softmmu=yes
1443f55fe278SPaolo Bonzini  ;;
1444f55fe278SPaolo Bonzini  *) softmmu=no
1445f55fe278SPaolo Bonzini  ;;
1446f55fe278SPaolo Bonziniesac
14475327cf48Sbellard
1448249247c9SJuan Quintelafeature_not_found() {
1449249247c9SJuan Quintela  feature=$1
145021684af0SStewart Smith  remedy=$2
1451249247c9SJuan Quintela
145276ad07a4SPeter Maydell  error_exit "User requested feature $feature" \
145321684af0SStewart Smith      "configure was not able to find it." \
145421684af0SStewart Smith      "$remedy"
1455249247c9SJuan Quintela}
1456249247c9SJuan Quintela
14577d13299dSbellard# ---
14587d13299dSbellard# big/little endian test
14597d13299dSbellardcat > $TMPC << EOF
1460659eb157SThomas Huth#include <stdio.h>
146161cc919fSMike Frysingershort big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
146261cc919fSMike Frysingershort little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
1463659eb157SThomas Huthint main(int argc, char *argv[])
1464659eb157SThomas Huth{
1465659eb157SThomas Huth    return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
14667d13299dSbellard}
14677d13299dSbellardEOF
14687d13299dSbellard
1469659eb157SThomas Huthif compile_prog ; then
1470659eb157SThomas Huth    if strings -a $TMPE | grep -q BiGeNdIaN ; then
147161cc919fSMike Frysinger        bigendian="yes"
1472659eb157SThomas Huth    elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
147361cc919fSMike Frysinger        bigendian="no"
14747d13299dSbellard    else
14757d13299dSbellard        echo big/little test failed
1476659eb157SThomas Huth        exit 1
14777d13299dSbellard    fi
14787d13299dSbellardelse
147961cc919fSMike Frysinger    echo big/little test failed
1480659eb157SThomas Huth    exit 1
14817d13299dSbellardfi
14827d13299dSbellard
1483015a33bdSGonglei##########################################
1484779ab5e3SStefan Weil# pkg-config probe
1485779ab5e3SStefan Weil
1486779ab5e3SStefan Weilif ! has "$pkg_config_exe"; then
148776ad07a4SPeter Maydell  error_exit "pkg-config binary '$pkg_config_exe' not found"
1488779ab5e3SStefan Weilfi
1489779ab5e3SStefan Weil
1490779ab5e3SStefan Weil##########################################
1491e18df141SAnthony Liguori# glib support probe
1492a52d28afSPaolo Bonzini
14930ce9b08cSThomas Huth# When bumping glib_req_ver, please check also whether we should increase
14940ce9b08cSThomas Huth# the _WIN32_WINNT setting in osdep.h according to the value from glib
1495b4c6036fSDaniel P. Berrangéglib_req_ver=2.56
1496aa0d1f44SPaolo Bonziniglib_modules=gthread-2.0
1497aa0d1f44SPaolo Bonziniif test "$modules" = yes; then
1498a88afc64SGerd Hoffmann    glib_modules="$glib_modules gmodule-export-2.0"
1499b906acacSPaolo Bonzinielif test "$plugins" = "yes"; then
1500b906acacSPaolo Bonzini    glib_modules="$glib_modules gmodule-no-export-2.0"
150154cb65d8SEmilio G. Cotafi
1502e26110cfSFam Zheng
1503aa0d1f44SPaolo Bonzinifor i in $glib_modules; do
1504e26110cfSFam Zheng    if $pkg_config --atleast-version=$glib_req_ver $i; then
150589138857SStefan Weil        glib_cflags=$($pkg_config --cflags $i)
150689138857SStefan Weil        glib_libs=$($pkg_config --libs $i)
1507e18df141SAnthony Liguori    else
1508e26110cfSFam Zheng        error_exit "glib-$glib_req_ver $i is required to compile QEMU"
1509e26110cfSFam Zheng    fi
1510e26110cfSFam Zhengdone
1511e26110cfSFam Zheng
15125b9e7d05SMarc-André Lureauglib_bindir="$($pkg_config --variable=bindir glib-2.0)"
15135b9e7d05SMarc-André Lureauif test -z "$glib_bindir" ; then
15145b9e7d05SMarc-André Lureau	glib_bindir="$($pkg_config --variable=prefix glib-2.0)"/bin
15155b9e7d05SMarc-André Lureaufi
15165b9e7d05SMarc-André Lureau
1517215b0c2fSPaolo Bonzini# This workaround is required due to a bug in pkg-config file for glib as it
1518215b0c2fSPaolo Bonzini# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
1519215b0c2fSPaolo Bonzini
1520215b0c2fSPaolo Bonziniif test "$static" = yes && test "$mingw32" = yes; then
1521215b0c2fSPaolo Bonzini    glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
1522215b0c2fSPaolo Bonzinifi
1523215b0c2fSPaolo Bonzini
1524977a82abSDaniel P. Berrange# Sanity check that the current size_t matches the
1525977a82abSDaniel P. Berrange# size that glib thinks it should be. This catches
1526977a82abSDaniel P. Berrange# problems on multi-arch where people try to build
1527977a82abSDaniel P. Berrange# 32-bit QEMU while pointing at 64-bit glib headers
1528977a82abSDaniel P. Berrangecat > $TMPC <<EOF
1529977a82abSDaniel P. Berrange#include <glib.h>
1530977a82abSDaniel P. Berrange#include <unistd.h>
1531977a82abSDaniel P. Berrange
1532977a82abSDaniel P. Berrange#define QEMU_BUILD_BUG_ON(x) \
1533977a82abSDaniel P. Berrange  typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
1534977a82abSDaniel P. Berrange
1535977a82abSDaniel P. Berrangeint main(void) {
1536977a82abSDaniel P. Berrange   QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
1537977a82abSDaniel P. Berrange   return 0;
1538977a82abSDaniel P. Berrange}
1539977a82abSDaniel P. BerrangeEOF
1540977a82abSDaniel P. Berrange
1541215b0c2fSPaolo Bonziniif ! compile_prog "$glib_cflags" "$glib_libs" ; then
1542977a82abSDaniel P. Berrange    error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
1543977a82abSDaniel P. Berrange               "You probably need to set PKG_CONFIG_LIBDIR"\
1544977a82abSDaniel P. Berrange	       "to point to the right pkg-config files for your"\
1545977a82abSDaniel P. Berrange	       "build target"
1546977a82abSDaniel P. Berrangefi
1547977a82abSDaniel P. Berrange
15489bda600bSEric Blake# Silence clang warnings triggered by glib < 2.57.2
15499bda600bSEric Blakecat > $TMPC << EOF
15509bda600bSEric Blake#include <glib.h>
15519bda600bSEric Blaketypedef struct Foo {
15529bda600bSEric Blake    int i;
15539bda600bSEric Blake} Foo;
15549bda600bSEric Blakestatic void foo_free(Foo *f)
15559bda600bSEric Blake{
15569bda600bSEric Blake    g_free(f);
15579bda600bSEric Blake}
1558e0e7fe07SMarc-André LureauG_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
15599bda600bSEric Blakeint main(void) { return 0; }
15609bda600bSEric BlakeEOF
15619bda600bSEric Blakeif ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
15629bda600bSEric Blake    if cc_has_warning_flag "-Wno-unused-function"; then
15639bda600bSEric Blake        glib_cflags="$glib_cflags -Wno-unused-function"
15645770e8afSPaolo Bonzini        CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
15659bda600bSEric Blake    fi
15669bda600bSEric Blakefi
15679bda600bSEric Blake
1568e26110cfSFam Zheng##########################################
1569f652e6afSaurel32# fdt probe
1570e169e1e1SPeter Maydell
1571fbb4121dSPaolo Bonzinicase "$fdt" in
1572fbb4121dSPaolo Bonzini  auto | enabled | internal)
1573fbb4121dSPaolo Bonzini    # Simpler to always update submodule, even if not needed.
1574aef45d51SDaniel P. Berrange    git_submodules="${git_submodules} dtc"
1575fbb4121dSPaolo Bonzini    ;;
1576fbb4121dSPaolo Bonziniesac
1577f652e6afSaurel32
157820ff075bSMichael Walle##########################################
1579519175a2SAlex Barcelo# check and set a backend for coroutine
1580d0e2fce5SAneesh Kumar K.V
15817c2acc70SPeter Maydell# We prefer ucontext, but it's not always possible. The fallback
158233c53c54SDaniel P. Berrange# is sigcontext. On Windows the only valid backend is the Windows
158333c53c54SDaniel P. Berrange# specific one.
15847c2acc70SPeter Maydell
15857c2acc70SPeter Maydellucontext_works=no
1586d0e2fce5SAneesh Kumar K.Vif test "$darwin" != "yes"; then
1587d0e2fce5SAneesh Kumar K.V  cat > $TMPC << EOF
1588d0e2fce5SAneesh Kumar K.V#include <ucontext.h>
1589cdf84806SPeter Maydell#ifdef __stub_makecontext
1590cdf84806SPeter Maydell#error Ignoring glibc stub makecontext which will always fail
1591cdf84806SPeter Maydell#endif
159275cafad7SStefan Weilint main(void) { makecontext(0, 0, 0); return 0; }
1593d0e2fce5SAneesh Kumar K.VEOF
1594d0e2fce5SAneesh Kumar K.V  if compile_prog "" "" ; then
15957c2acc70SPeter Maydell    ucontext_works=yes
1596d0e2fce5SAneesh Kumar K.V  fi
1597519175a2SAlex Barcelofi
15987c2acc70SPeter Maydell
15997c2acc70SPeter Maydellif test "$coroutine" = ""; then
16007c2acc70SPeter Maydell  if test "$mingw32" = "yes"; then
16017c2acc70SPeter Maydell    coroutine=win32
16027c2acc70SPeter Maydell  elif test "$ucontext_works" = "yes"; then
16037c2acc70SPeter Maydell    coroutine=ucontext
1604519175a2SAlex Barcelo  else
16057c2acc70SPeter Maydell    coroutine=sigaltstack
16067c2acc70SPeter Maydell  fi
16077c2acc70SPeter Maydellelse
16087c2acc70SPeter Maydell  case $coroutine in
16097c2acc70SPeter Maydell  windows)
16107c2acc70SPeter Maydell    if test "$mingw32" != "yes"; then
16117c2acc70SPeter Maydell      error_exit "'windows' coroutine backend only valid for Windows"
16127c2acc70SPeter Maydell    fi
16137c2acc70SPeter Maydell    # Unfortunately the user visible backend name doesn't match the
16147c2acc70SPeter Maydell    # coroutine-*.c filename for this case, so we have to adjust it here.
16157c2acc70SPeter Maydell    coroutine=win32
16167c2acc70SPeter Maydell    ;;
16177c2acc70SPeter Maydell  ucontext)
16187c2acc70SPeter Maydell    if test "$ucontext_works" != "yes"; then
16197c2acc70SPeter Maydell      feature_not_found "ucontext"
16207c2acc70SPeter Maydell    fi
16217c2acc70SPeter Maydell    ;;
162233c53c54SDaniel P. Berrange  sigaltstack)
16237c2acc70SPeter Maydell    if test "$mingw32" = "yes"; then
16247c2acc70SPeter Maydell      error_exit "only the 'windows' coroutine backend is valid for Windows"
16257c2acc70SPeter Maydell    fi
16267c2acc70SPeter Maydell    ;;
16277c2acc70SPeter Maydell  *)
162876ad07a4SPeter Maydell    error_exit "unknown coroutine backend $coroutine"
16297c2acc70SPeter Maydell    ;;
16307c2acc70SPeter Maydell  esac
1631d0e2fce5SAneesh Kumar K.Vfi
1632d0e2fce5SAneesh Kumar K.V
16331e4f6065SDaniele Buono##################################################
16341e4f6065SDaniele Buono# SafeStack
16351e4f6065SDaniele Buono
16361e4f6065SDaniele Buono
16371e4f6065SDaniele Buonoif test "$safe_stack" = "yes"; then
16381e4f6065SDaniele Buonocat > $TMPC << EOF
16391e4f6065SDaniele Buonoint main(int argc, char *argv[])
16401e4f6065SDaniele Buono{
16411e4f6065SDaniele Buono#if ! __has_feature(safe_stack)
16421e4f6065SDaniele Buono#error SafeStack Disabled
16431e4f6065SDaniele Buono#endif
16441e4f6065SDaniele Buono    return 0;
16451e4f6065SDaniele Buono}
16461e4f6065SDaniele BuonoEOF
16471e4f6065SDaniele Buono  flag="-fsanitize=safe-stack"
16481e4f6065SDaniele Buono  # Check that safe-stack is supported and enabled.
16491e4f6065SDaniele Buono  if compile_prog "-Werror $flag" "$flag"; then
16501e4f6065SDaniele Buono    # Flag needed both at compilation and at linking
16511e4f6065SDaniele Buono    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
16521e4f6065SDaniele Buono    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
16531e4f6065SDaniele Buono  else
16541e4f6065SDaniele Buono    error_exit "SafeStack not supported by your compiler"
16551e4f6065SDaniele Buono  fi
16561e4f6065SDaniele Buono  if test "$coroutine" != "ucontext"; then
16571e4f6065SDaniele Buono    error_exit "SafeStack is only supported by the coroutine backend ucontext"
16581e4f6065SDaniele Buono  fi
16591e4f6065SDaniele Buonoelse
16601e4f6065SDaniele Buonocat > $TMPC << EOF
16611e4f6065SDaniele Buonoint main(int argc, char *argv[])
16621e4f6065SDaniele Buono{
16631e4f6065SDaniele Buono#if defined(__has_feature)
16641e4f6065SDaniele Buono#if __has_feature(safe_stack)
16651e4f6065SDaniele Buono#error SafeStack Enabled
16661e4f6065SDaniele Buono#endif
16671e4f6065SDaniele Buono#endif
16681e4f6065SDaniele Buono    return 0;
16691e4f6065SDaniele Buono}
16701e4f6065SDaniele BuonoEOF
16711e4f6065SDaniele Buonoif test "$safe_stack" = "no"; then
16721e4f6065SDaniele Buono  # Make sure that safe-stack is disabled
16731e4f6065SDaniele Buono  if ! compile_prog "-Werror" ""; then
16741e4f6065SDaniele Buono    # SafeStack was already enabled, try to explicitly remove the feature
16751e4f6065SDaniele Buono    flag="-fno-sanitize=safe-stack"
16761e4f6065SDaniele Buono    if ! compile_prog "-Werror $flag" "$flag"; then
16771e4f6065SDaniele Buono      error_exit "Configure cannot disable SafeStack"
16781e4f6065SDaniele Buono    fi
16791e4f6065SDaniele Buono    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
16801e4f6065SDaniele Buono    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
16811e4f6065SDaniele Buono  fi
16821e4f6065SDaniele Buonoelse # "$safe_stack" = ""
16831e4f6065SDaniele Buono  # Set safe_stack to yes or no based on pre-existing flags
16841e4f6065SDaniele Buono  if compile_prog "-Werror" ""; then
16851e4f6065SDaniele Buono    safe_stack="no"
16861e4f6065SDaniele Buono  else
16871e4f6065SDaniele Buono    safe_stack="yes"
16881e4f6065SDaniele Buono    if test "$coroutine" != "ucontext"; then
16891e4f6065SDaniele Buono      error_exit "SafeStack is only supported by the coroutine backend ucontext"
16901e4f6065SDaniele Buono    fi
16911e4f6065SDaniele Buono  fi
16921e4f6065SDaniele Buonofi
16931e4f6065SDaniele Buonofi
16947d992e4dSPeter Lieven
169576a347e1SRichard Henderson########################################
1696fd0e6053SJohn Snow# check if ccache is interfering with
1697fd0e6053SJohn Snow# semantic analysis of macros
1698fd0e6053SJohn Snow
16995e4dfd3dSJohn Snowunset CCACHE_CPP2
1700fd0e6053SJohn Snowccache_cpp2=no
1701fd0e6053SJohn Snowcat > $TMPC << EOF
1702fd0e6053SJohn Snowstatic const int Z = 1;
1703fd0e6053SJohn Snow#define fn() ({ Z; })
1704fd0e6053SJohn Snow#define TAUT(X) ((X) == Z)
1705fd0e6053SJohn Snow#define PAREN(X, Y) (X == Y)
1706fd0e6053SJohn Snow#define ID(X) (X)
1707fd0e6053SJohn Snowint main(int argc, char *argv[])
1708fd0e6053SJohn Snow{
1709fd0e6053SJohn Snow    int x = 0, y = 0;
1710fd0e6053SJohn Snow    x = ID(x);
1711fd0e6053SJohn Snow    x = fn();
1712fd0e6053SJohn Snow    fn();
1713fd0e6053SJohn Snow    if (PAREN(x, y)) return 0;
1714fd0e6053SJohn Snow    if (TAUT(Z)) return 0;
1715fd0e6053SJohn Snow    return 0;
1716fd0e6053SJohn Snow}
1717fd0e6053SJohn SnowEOF
1718fd0e6053SJohn Snow
1719fd0e6053SJohn Snowif ! compile_object "-Werror"; then
1720fd0e6053SJohn Snow    ccache_cpp2=yes
1721fd0e6053SJohn Snowfi
1722fd0e6053SJohn Snow
1723b553a042SJohn Snow#################################################
1724b553a042SJohn Snow# clang does not support glibc + FORTIFY_SOURCE.
1725b553a042SJohn Snow
1726b553a042SJohn Snowif test "$fortify_source" != "no"; then
1727b553a042SJohn Snow  if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
1728b553a042SJohn Snow    fortify_source="no";
1729e189091fSPeter Maydell  elif test -n "$cxx" && has $cxx &&
1730cfcc7c14SJohn Snow       echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
1731b553a042SJohn Snow    fortify_source="no";
1732b553a042SJohn Snow  else
1733b553a042SJohn Snow    fortify_source="yes"
1734b553a042SJohn Snow  fi
1735b553a042SJohn Snowfi
1736b553a042SJohn Snow
1737d2042378SAneesh Kumar K.V##########################################
1738247724cbSMarc-André Lureau# checks for sanitizers
1739247724cbSMarc-André Lureau
1740247724cbSMarc-André Lureauhave_asan=no
1741247724cbSMarc-André Lureauhave_ubsan=no
1742d83414e1SMarc-André Lureauhave_asan_iface_h=no
1743d83414e1SMarc-André Lureauhave_asan_iface_fiber=no
1744247724cbSMarc-André Lureau
1745247724cbSMarc-André Lureauif test "$sanitizers" = "yes" ; then
1746b9f44da2SMarc-André Lureau  write_c_skeleton
1747247724cbSMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
1748247724cbSMarc-André Lureau      have_asan=yes
1749247724cbSMarc-André Lureau  fi
1750b9f44da2SMarc-André Lureau
1751b9f44da2SMarc-André Lureau  # we could use a simple skeleton for flags checks, but this also
1752b9f44da2SMarc-André Lureau  # detect the static linking issue of ubsan, see also:
1753b9f44da2SMarc-André Lureau  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
1754b9f44da2SMarc-André Lureau  cat > $TMPC << EOF
1755b9f44da2SMarc-André Lureau#include <stdlib.h>
1756b9f44da2SMarc-André Lureauint main(void) {
1757b9f44da2SMarc-André Lureau    void *tmp = malloc(10);
1758f2dfe54cSLeonid Bloch    if (tmp != NULL) {
1759b9f44da2SMarc-André Lureau        return *(int *)(tmp + 2);
1760b9f44da2SMarc-André Lureau    }
1761d1abf3fcSOlaf Hering    return 1;
1762f2dfe54cSLeonid Bloch}
1763b9f44da2SMarc-André LureauEOF
1764247724cbSMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
1765247724cbSMarc-André Lureau      have_ubsan=yes
1766247724cbSMarc-André Lureau  fi
1767d83414e1SMarc-André Lureau
1768d83414e1SMarc-André Lureau  if check_include "sanitizer/asan_interface.h" ; then
1769d83414e1SMarc-André Lureau      have_asan_iface_h=yes
1770d83414e1SMarc-André Lureau  fi
1771d83414e1SMarc-André Lureau
1772d83414e1SMarc-André Lureau  cat > $TMPC << EOF
1773d83414e1SMarc-André Lureau#include <sanitizer/asan_interface.h>
1774d83414e1SMarc-André Lureauint main(void) {
1775d83414e1SMarc-André Lureau  __sanitizer_start_switch_fiber(0, 0, 0);
1776d83414e1SMarc-André Lureau  return 0;
1777d83414e1SMarc-André Lureau}
1778d83414e1SMarc-André LureauEOF
1779d83414e1SMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
1780d83414e1SMarc-André Lureau      have_asan_iface_fiber=yes
1781d83414e1SMarc-André Lureau  fi
1782247724cbSMarc-André Lureaufi
1783247724cbSMarc-André Lureau
17840aebab04SLingfeng Yang# Thread sanitizer is, for now, much noisier than the other sanitizers;
17850aebab04SLingfeng Yang# keep it separate until that is not the case.
17860aebab04SLingfeng Yangif test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
17870aebab04SLingfeng Yang  error_exit "TSAN is not supported with other sanitiziers."
17880aebab04SLingfeng Yangfi
17890aebab04SLingfeng Yanghave_tsan=no
17900aebab04SLingfeng Yanghave_tsan_iface_fiber=no
17910aebab04SLingfeng Yangif test "$tsan" = "yes" ; then
17920aebab04SLingfeng Yang  write_c_skeleton
17930aebab04SLingfeng Yang  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
17940aebab04SLingfeng Yang      have_tsan=yes
17950aebab04SLingfeng Yang  fi
17960aebab04SLingfeng Yang  cat > $TMPC << EOF
17970aebab04SLingfeng Yang#include <sanitizer/tsan_interface.h>
17980aebab04SLingfeng Yangint main(void) {
17990aebab04SLingfeng Yang  __tsan_create_fiber(0);
18000aebab04SLingfeng Yang  return 0;
18010aebab04SLingfeng Yang}
18020aebab04SLingfeng YangEOF
18030aebab04SLingfeng Yang  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
18040aebab04SLingfeng Yang      have_tsan_iface_fiber=yes
18050aebab04SLingfeng Yang  fi
18060aebab04SLingfeng Yangfi
18070aebab04SLingfeng Yang
1808adc28027SAlexander Bulekov##########################################
1809675b9b53SMarc-André Lureau# check for slirp
1810675b9b53SMarc-André Lureau
1811675b9b53SMarc-André Lureaucase "$slirp" in
18124d34a86bSPaolo Bonzini  auto | enabled | internal)
18134d34a86bSPaolo Bonzini    # Simpler to always update submodule, even if not needed.
18147c57bdd8SMarc-André Lureau    git_submodules="${git_submodules} slirp"
1815675b9b53SMarc-André Lureau    ;;
1816675b9b53SMarc-André Lureauesac
1817675b9b53SMarc-André Lureau
181854e7aac0SAlexey Krasikov##########################################
1819cd362defSPaolo Bonzini# functions to probe cross compilers
1820cd362defSPaolo Bonzini
1821cd362defSPaolo Bonzinicontainer="no"
1822cd362defSPaolo Bonziniif test $use_containers = "yes"; then
1823cd362defSPaolo Bonzini    if has "docker" || has "podman"; then
1824cd362defSPaolo Bonzini        container=$($python $source_path/tests/docker/docker.py probe)
1825cd362defSPaolo Bonzini    fi
1826cd362defSPaolo Bonzinifi
1827cd362defSPaolo Bonzini
1828cd362defSPaolo Bonzini# cross compilers defaults, can be overridden with --cross-cc-ARCH
18295adb43beSPaolo Bonzini: ${cross_prefix_aarch64="aarch64-linux-gnu-"}
18305adb43beSPaolo Bonzini: ${cross_prefix_aarch64_be="$cross_prefix_aarch64"}
18315adb43beSPaolo Bonzini: ${cross_prefix_alpha="alpha-linux-gnu-"}
18325adb43beSPaolo Bonzini: ${cross_prefix_arm="arm-linux-gnueabihf-"}
18335adb43beSPaolo Bonzini: ${cross_prefix_armeb="$cross_prefix_arm"}
18345adb43beSPaolo Bonzini: ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
18355adb43beSPaolo Bonzini: ${cross_prefix_hppa="hppa-linux-gnu-"}
18365adb43beSPaolo Bonzini: ${cross_prefix_i386="i686-linux-gnu-"}
18375adb43beSPaolo Bonzini: ${cross_prefix_m68k="m68k-linux-gnu-"}
18385adb43beSPaolo Bonzini: ${cross_prefix_microblaze="microblaze-linux-musl-"}
18395adb43beSPaolo Bonzini: ${cross_prefix_mips64el="mips64el-linux-gnuabi64-"}
18405adb43beSPaolo Bonzini: ${cross_prefix_mips64="mips64-linux-gnuabi64-"}
18415adb43beSPaolo Bonzini: ${cross_prefix_mipsel="mipsel-linux-gnu-"}
18425adb43beSPaolo Bonzini: ${cross_prefix_mips="mips-linux-gnu-"}
18435adb43beSPaolo Bonzini: ${cross_prefix_nios2="nios2-linux-gnu-"}
18445adb43beSPaolo Bonzini: ${cross_prefix_ppc="powerpc-linux-gnu-"}
18455adb43beSPaolo Bonzini: ${cross_prefix_ppc64="powerpc64-linux-gnu-"}
18465adb43beSPaolo Bonzini: ${cross_prefix_ppc64le="$cross_prefix_ppc64"}
18475adb43beSPaolo Bonzini: ${cross_prefix_riscv64="riscv64-linux-gnu-"}
18485adb43beSPaolo Bonzini: ${cross_prefix_s390x="s390x-linux-gnu-"}
18495adb43beSPaolo Bonzini: ${cross_prefix_sh4="sh4-linux-gnu-"}
18505adb43beSPaolo Bonzini: ${cross_prefix_sparc64="sparc64-linux-gnu-"}
18515adb43beSPaolo Bonzini: ${cross_prefix_sparc="$cross_prefix_sparc64"}
18525adb43beSPaolo Bonzini: ${cross_prefix_x86_64="x86_64-linux-gnu-"}
18535adb43beSPaolo Bonzini
1854cd362defSPaolo Bonzini: ${cross_cc_aarch64_be="$cross_cc_aarch64"}
1855cd362defSPaolo Bonzini: ${cross_cc_cflags_aarch64_be="-mbig-endian"}
185646af66edSPaolo Bonzini: ${cross_cc_armeb="$cross_cc_arm"}
1857cd362defSPaolo Bonzini: ${cross_cc_cflags_armeb="-mbig-endian"}
1858cd362defSPaolo Bonzini: ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
1859cd362defSPaolo Bonzini: ${cross_cc_cflags_hexagon="-mv67 -O2 -static"}
1860cd362defSPaolo Bonzini: ${cross_cc_cflags_i386="-m32"}
1861cd362defSPaolo Bonzini: ${cross_cc_cflags_ppc="-m32"}
1862cd362defSPaolo Bonzini: ${cross_cc_cflags_ppc64="-m64 -mbig-endian"}
1863cd362defSPaolo Bonzini: ${cross_cc_ppc64le="$cross_cc_ppc64"}
1864cd362defSPaolo Bonzini: ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"}
1865cd362defSPaolo Bonzini: ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
186646af66edSPaolo Bonzini: ${cross_cc_sparc="$cross_cc_sparc64"}
186746af66edSPaolo Bonzini: ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
1868cd362defSPaolo Bonzini: ${cross_cc_cflags_x86_64="-m64"}
1869cd362defSPaolo Bonzini
18705adb43beSPaolo Bonzinicompute_target_variable() {
18715adb43beSPaolo Bonzini  if eval test -n "\"\${cross_prefix_$1}\""; then
18725adb43beSPaolo Bonzini    if eval has "\"\${cross_prefix_$1}\$3\""; then
18735adb43beSPaolo Bonzini      eval "$2=\"\${cross_prefix_$1}\$3\""
18745adb43beSPaolo Bonzini    fi
18755adb43beSPaolo Bonzini  fi
18765adb43beSPaolo Bonzini}
1877cd362defSPaolo Bonzini
1878cd362defSPaolo Bonziniprobe_target_compiler() {
1879cd362defSPaolo Bonzini  # reset all output variables
1880cd362defSPaolo Bonzini  container_image=
1881cd362defSPaolo Bonzini  container_hosts=
1882cd362defSPaolo Bonzini  container_cross_cc=
188387eb014cSPaolo Bonzini  container_cross_ar=
1884cd362defSPaolo Bonzini  container_cross_as=
1885cd362defSPaolo Bonzini  container_cross_ld=
188687eb014cSPaolo Bonzini  container_cross_nm=
188787eb014cSPaolo Bonzini  container_cross_objcopy=
188887eb014cSPaolo Bonzini  container_cross_ranlib=
188987eb014cSPaolo Bonzini  container_cross_strip=
1890cd362defSPaolo Bonzini  target_cc=
189187eb014cSPaolo Bonzini  target_ar=
1892cd362defSPaolo Bonzini  target_as=
1893cd362defSPaolo Bonzini  target_ld=
189487eb014cSPaolo Bonzini  target_nm=
189587eb014cSPaolo Bonzini  target_objcopy=
189687eb014cSPaolo Bonzini  target_ranlib=
189787eb014cSPaolo Bonzini  target_strip=
1898cd362defSPaolo Bonzini
1899cd362defSPaolo Bonzini  case $1 in
1900cd362defSPaolo Bonzini    aarch64) container_hosts="x86_64 aarch64" ;;
1901cd362defSPaolo Bonzini    alpha) container_hosts=x86_64 ;;
1902cd362defSPaolo Bonzini    arm) container_hosts="x86_64 aarch64" ;;
1903cd362defSPaolo Bonzini    cris) container_hosts=x86_64 ;;
1904cd362defSPaolo Bonzini    hexagon) container_hosts=x86_64 ;;
1905cd362defSPaolo Bonzini    hppa) container_hosts=x86_64 ;;
1906cd362defSPaolo Bonzini    i386) container_hosts=x86_64 ;;
1907cd362defSPaolo Bonzini    m68k) container_hosts=x86_64 ;;
1908cd362defSPaolo Bonzini    microblaze) container_hosts=x86_64 ;;
1909cd362defSPaolo Bonzini    mips64el) container_hosts=x86_64 ;;
1910cd362defSPaolo Bonzini    mips64) container_hosts=x86_64 ;;
1911cd362defSPaolo Bonzini    mipsel) container_hosts=x86_64 ;;
1912cd362defSPaolo Bonzini    mips) container_hosts=x86_64 ;;
1913cd362defSPaolo Bonzini    nios2) container_hosts=x86_64 ;;
1914cd362defSPaolo Bonzini    ppc) container_hosts=x86_64 ;;
1915cd362defSPaolo Bonzini    ppc64|ppc64le) container_hosts=x86_64 ;;
1916cd362defSPaolo Bonzini    riscv64) container_hosts=x86_64 ;;
1917cd362defSPaolo Bonzini    s390x) container_hosts=x86_64 ;;
1918cd362defSPaolo Bonzini    sh4) container_hosts=x86_64 ;;
1919cd362defSPaolo Bonzini    sparc64) container_hosts=x86_64 ;;
1920cd362defSPaolo Bonzini    tricore) container_hosts=x86_64 ;;
1921cd362defSPaolo Bonzini    x86_64) container_hosts="aarch64 ppc64el x86_64" ;;
1922cd362defSPaolo Bonzini    xtensa*) container_hosts=x86_64 ;;
1923cd362defSPaolo Bonzini  esac
1924cd362defSPaolo Bonzini
1925cd362defSPaolo Bonzini  for host in $container_hosts; do
1926cd362defSPaolo Bonzini    test "$container" != no || continue
1927cd362defSPaolo Bonzini    test "$host" = "$cpu" || continue
1928cd362defSPaolo Bonzini    case $1 in
1929cd362defSPaolo Bonzini      aarch64)
1930cd362defSPaolo Bonzini        # We don't have any bigendian build tools so we only use this for AArch64
1931cd362defSPaolo Bonzini        container_image=debian-arm64-cross
19325adb43beSPaolo Bonzini        container_cross_prefix=aarch64-linux-gnu-
19335adb43beSPaolo Bonzini        container_cross_cc=${container_cross_prefix}gcc-10
1934cd362defSPaolo Bonzini        ;;
1935cd362defSPaolo Bonzini      alpha)
1936cd362defSPaolo Bonzini        container_image=debian-alpha-cross
19375adb43beSPaolo Bonzini        container_cross_prefix=alpha-linux-gnu-
1938cd362defSPaolo Bonzini        ;;
1939cd362defSPaolo Bonzini      arm)
1940cd362defSPaolo Bonzini        # We don't have any bigendian build tools so we only use this for ARM
1941cd362defSPaolo Bonzini        container_image=debian-armhf-cross
19425adb43beSPaolo Bonzini        container_cross_prefix=arm-linux-gnueabihf-
1943cd362defSPaolo Bonzini        ;;
1944cd362defSPaolo Bonzini      cris)
1945cd362defSPaolo Bonzini        container_image=fedora-cris-cross
19465adb43beSPaolo Bonzini        container_cross_prefix=cris-linux-gnu-
1947cd362defSPaolo Bonzini        ;;
1948cd362defSPaolo Bonzini      hexagon)
1949cd362defSPaolo Bonzini        container_image=debian-hexagon-cross
19505adb43beSPaolo Bonzini        container_cross_prefix=hexagon-unknown-linux-musl-
19515adb43beSPaolo Bonzini        container_cross_cc=${container_cross_prefix}clang
1952cd362defSPaolo Bonzini        ;;
1953cd362defSPaolo Bonzini      hppa)
1954cd362defSPaolo Bonzini        container_image=debian-hppa-cross
19555adb43beSPaolo Bonzini        container_cross_prefix=hppa-linux-gnu-
1956cd362defSPaolo Bonzini        ;;
1957cd362defSPaolo Bonzini      i386)
1958cd362defSPaolo Bonzini        container_image=fedora-i386-cross
19595adb43beSPaolo Bonzini        container_cross_prefix=
1960cd362defSPaolo Bonzini        ;;
1961cd362defSPaolo Bonzini      m68k)
1962cd362defSPaolo Bonzini        container_image=debian-m68k-cross
19635adb43beSPaolo Bonzini        container_cross_prefix=m68k-linux-gnu-
1964cd362defSPaolo Bonzini        ;;
1965cd362defSPaolo Bonzini      microblaze)
1966cd362defSPaolo Bonzini        container_image=debian-microblaze-cross
19675adb43beSPaolo Bonzini        container_cross_prefix=microblaze-linux-musl-
1968cd362defSPaolo Bonzini        ;;
1969cd362defSPaolo Bonzini      mips64el)
1970cd362defSPaolo Bonzini        container_image=debian-mips64el-cross
19715adb43beSPaolo Bonzini        container_cross_prefix=mips64el-linux-gnuabi64-
1972cd362defSPaolo Bonzini        ;;
1973cd362defSPaolo Bonzini      mips64)
1974cd362defSPaolo Bonzini        container_image=debian-mips64-cross
19755adb43beSPaolo Bonzini        container_cross_prefix=mips64-linux-gnuabi64-
1976cd362defSPaolo Bonzini        ;;
1977cd362defSPaolo Bonzini      mipsel)
1978cd362defSPaolo Bonzini        container_image=debian-mipsel-cross
19795adb43beSPaolo Bonzini        container_cross_prefix=mipsel-linux-gnu-
1980cd362defSPaolo Bonzini        ;;
1981cd362defSPaolo Bonzini      mips)
1982cd362defSPaolo Bonzini        container_image=debian-mips-cross
19835adb43beSPaolo Bonzini        container_cross_prefix=mips-linux-gnu-
1984cd362defSPaolo Bonzini        ;;
1985cd362defSPaolo Bonzini      nios2)
1986cd362defSPaolo Bonzini        container_image=debian-nios2-cross
19875adb43beSPaolo Bonzini        container_cross_prefix=nios2-linux-gnu-
1988cd362defSPaolo Bonzini        ;;
1989cd362defSPaolo Bonzini      ppc)
1990cd362defSPaolo Bonzini        container_image=debian-powerpc-test-cross
19915adb43beSPaolo Bonzini        container_cross_prefix=powerpc-linux-gnu-
19925adb43beSPaolo Bonzini        container_cross_cc=${container_cross_prefix}gcc-10
1993cd362defSPaolo Bonzini        ;;
1994cd362defSPaolo Bonzini      ppc64|ppc64le)
1995cd362defSPaolo Bonzini        container_image=debian-powerpc-test-cross
19965adb43beSPaolo Bonzini        container_cross_prefix=powerpc${1#ppc}-linux-gnu-
19975adb43beSPaolo Bonzini        container_cross_cc=${container_cross_prefix}gcc-10
1998cd362defSPaolo Bonzini        ;;
1999cd362defSPaolo Bonzini      riscv64)
2000cd362defSPaolo Bonzini        container_image=debian-riscv64-test-cross
20015adb43beSPaolo Bonzini        container_cross_prefix=riscv64-linux-gnu-
2002cd362defSPaolo Bonzini        ;;
2003cd362defSPaolo Bonzini      s390x)
2004cd362defSPaolo Bonzini        container_image=debian-s390x-cross
20055adb43beSPaolo Bonzini        container_cross_prefix=s390x-linux-gnu-
2006cd362defSPaolo Bonzini        ;;
2007cd362defSPaolo Bonzini      sh4)
2008cd362defSPaolo Bonzini        container_image=debian-sh4-cross
20095adb43beSPaolo Bonzini        container_cross_prefix=sh4-linux-gnu-
2010cd362defSPaolo Bonzini        ;;
2011cd362defSPaolo Bonzini      sparc64)
2012cd362defSPaolo Bonzini        container_image=debian-sparc64-cross
20135adb43beSPaolo Bonzini        container_cross_prefix=sparc64-linux-gnu-
2014cd362defSPaolo Bonzini        ;;
2015cd362defSPaolo Bonzini      tricore)
2016cd362defSPaolo Bonzini        container_image=debian-tricore-cross
20175adb43beSPaolo Bonzini        container_cross_prefix=tricore-
2018cd362defSPaolo Bonzini        container_cross_as=tricore-as
2019cd362defSPaolo Bonzini        container_cross_ld=tricore-ld
20205adb43beSPaolo Bonzini        break
2021cd362defSPaolo Bonzini        ;;
2022cd362defSPaolo Bonzini      x86_64)
2023cd362defSPaolo Bonzini        container_image=debian-amd64-cross
20245adb43beSPaolo Bonzini        container_cross_prefix=x86_64-linux-gnu-
2025cd362defSPaolo Bonzini        ;;
2026cd362defSPaolo Bonzini      xtensa*)
2027cd362defSPaolo Bonzini        # FIXME: xtensa-linux-user?
2028cd362defSPaolo Bonzini        container_hosts=x86_64
2029cd362defSPaolo Bonzini        container_image=debian-xtensa-cross
2030cd362defSPaolo Bonzini
2031cd362defSPaolo Bonzini        # default to the dc232b cpu
20325adb43beSPaolo Bonzini        container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
2033cd362defSPaolo Bonzini        ;;
2034cd362defSPaolo Bonzini    esac
20355adb43beSPaolo Bonzini    : ${container_cross_cc:=${container_cross_prefix}gcc}
203687eb014cSPaolo Bonzini    : ${container_cross_ar:=${container_cross_prefix}ar}
20375adb43beSPaolo Bonzini    : ${container_cross_as:=${container_cross_prefix}as}
20385adb43beSPaolo Bonzini    : ${container_cross_ld:=${container_cross_prefix}ld}
203987eb014cSPaolo Bonzini    : ${container_cross_nm:=${container_cross_prefix}nm}
204087eb014cSPaolo Bonzini    : ${container_cross_objcopy:=${container_cross_prefix}objcopy}
204187eb014cSPaolo Bonzini    : ${container_cross_ranlib:=${container_cross_prefix}ranlib}
204287eb014cSPaolo Bonzini    : ${container_cross_strip:=${container_cross_prefix}strip}
2043cd362defSPaolo Bonzini  done
2044cd362defSPaolo Bonzini
2045cd362defSPaolo Bonzini  eval "target_cflags=\${cross_cc_cflags_$1}"
2046cd362defSPaolo Bonzini  if eval test -n "\"\${cross_cc_$1}\""; then
2047cd362defSPaolo Bonzini    if eval has "\"\${cross_cc_$1}\""; then
2048cd362defSPaolo Bonzini      eval "target_cc=\"\${cross_cc_$1}\""
2049cd362defSPaolo Bonzini    fi
20505adb43beSPaolo Bonzini  else
20515adb43beSPaolo Bonzini    compute_target_variable $1 target_cc gcc
2052cd362defSPaolo Bonzini  fi
205387eb014cSPaolo Bonzini  target_ccas=$target_cc
205487eb014cSPaolo Bonzini  compute_target_variable $1 target_ar ar
20555adb43beSPaolo Bonzini  compute_target_variable $1 target_as as
20565adb43beSPaolo Bonzini  compute_target_variable $1 target_ld ld
205787eb014cSPaolo Bonzini  compute_target_variable $1 target_nm nm
205887eb014cSPaolo Bonzini  compute_target_variable $1 target_objcopy objcopy
205987eb014cSPaolo Bonzini  compute_target_variable $1 target_ranlib ranlib
206087eb014cSPaolo Bonzini  compute_target_variable $1 target_strip strip
20612ad60f6fSPaolo Bonzini  if test "$1" = $cpu; then
20622ad60f6fSPaolo Bonzini    : ${target_cc:=$cc}
206387eb014cSPaolo Bonzini    : ${target_ccas:=$ccas}
20642ad60f6fSPaolo Bonzini    : ${target_as:=$as}
20652ad60f6fSPaolo Bonzini    : ${target_ld:=$ld}
206687eb014cSPaolo Bonzini    : ${target_ar:=$ar}
206787eb014cSPaolo Bonzini    : ${target_as:=$as}
206887eb014cSPaolo Bonzini    : ${target_ld:=$ld}
206987eb014cSPaolo Bonzini    : ${target_nm:=$nm}
207087eb014cSPaolo Bonzini    : ${target_objcopy:=$objcopy}
207187eb014cSPaolo Bonzini    : ${target_ranlib:=$ranlib}
207287eb014cSPaolo Bonzini    : ${target_strip:=$strip}
20732ad60f6fSPaolo Bonzini  fi
20742ad60f6fSPaolo Bonzini  if test -n "$target_cc"; then
20752ad60f6fSPaolo Bonzini    case $1 in
20762ad60f6fSPaolo Bonzini      i386|x86_64)
20772ad60f6fSPaolo Bonzini        if $target_cc --version | grep -qi "clang"; then
20782ad60f6fSPaolo Bonzini          unset target_cc
20792ad60f6fSPaolo Bonzini        fi
20802ad60f6fSPaolo Bonzini        ;;
20812ad60f6fSPaolo Bonzini    esac
20822ad60f6fSPaolo Bonzini  fi
2083cd362defSPaolo Bonzini}
2084cd362defSPaolo Bonzini
2085cd362defSPaolo Bonziniwrite_target_makefile() {
2086cd362defSPaolo Bonzini  if test -n "$target_cc"; then
2087cd362defSPaolo Bonzini    echo "CC=$target_cc"
208887eb014cSPaolo Bonzini    echo "CCAS=$target_ccas"
208987eb014cSPaolo Bonzini  fi
209087eb014cSPaolo Bonzini  if test -n "$target_ar"; then
209187eb014cSPaolo Bonzini    echo "AR=$target_ar"
2092cd362defSPaolo Bonzini  fi
2093cd362defSPaolo Bonzini  if test -n "$target_as"; then
2094cd362defSPaolo Bonzini    echo "AS=$target_as"
2095cd362defSPaolo Bonzini  fi
2096cd362defSPaolo Bonzini  if test -n "$target_ld"; then
2097cd362defSPaolo Bonzini    echo "LD=$target_ld"
2098cd362defSPaolo Bonzini  fi
209987eb014cSPaolo Bonzini  if test -n "$target_nm"; then
210087eb014cSPaolo Bonzini    echo "NM=$target_nm"
210187eb014cSPaolo Bonzini  fi
210287eb014cSPaolo Bonzini  if test -n "$target_objcopy"; then
210387eb014cSPaolo Bonzini    echo "OBJCOPY=$target_objcopy"
210487eb014cSPaolo Bonzini  fi
210587eb014cSPaolo Bonzini  if test -n "$target_ranlib"; then
210687eb014cSPaolo Bonzini    echo "RANLIB=$target_ranlib"
210787eb014cSPaolo Bonzini  fi
210887eb014cSPaolo Bonzini  if test -n "$target_strip"; then
210987eb014cSPaolo Bonzini    echo "STRIP=$target_strip"
211087eb014cSPaolo Bonzini  fi
2111cd362defSPaolo Bonzini}
2112cd362defSPaolo Bonzini
2113cd362defSPaolo Bonziniwrite_container_target_makefile() {
2114cd362defSPaolo Bonzini  if test -n "$container_cross_cc"; then
2115cd362defSPaolo Bonzini    echo "CC=\$(DOCKER_SCRIPT) cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
211687eb014cSPaolo Bonzini    echo "CCAS=\$(DOCKER_SCRIPT) cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
2117cd362defSPaolo Bonzini  fi
211887eb014cSPaolo Bonzini  echo "AR=\$(DOCKER_SCRIPT) cc --cc $container_cross_ar -i qemu/$container_image -s $source_path --"
2119cd362defSPaolo Bonzini  echo "AS=\$(DOCKER_SCRIPT) cc --cc $container_cross_as -i qemu/$container_image -s $source_path --"
2120cd362defSPaolo Bonzini  echo "LD=\$(DOCKER_SCRIPT) cc --cc $container_cross_ld -i qemu/$container_image -s $source_path --"
212187eb014cSPaolo Bonzini  echo "NM=\$(DOCKER_SCRIPT) cc --cc $container_cross_nm -i qemu/$container_image -s $source_path --"
212287eb014cSPaolo Bonzini  echo "OBJCOPY=\$(DOCKER_SCRIPT) cc --cc $container_cross_objcopy -i qemu/$container_image -s $source_path --"
212387eb014cSPaolo Bonzini  echo "RANLIB=\$(DOCKER_SCRIPT) cc --cc $container_cross_ranlib -i qemu/$container_image -s $source_path --"
212487eb014cSPaolo Bonzini  echo "STRIP=\$(DOCKER_SCRIPT) cc --cc $container_cross_strip -i qemu/$container_image -s $source_path --"
2125cd362defSPaolo Bonzini}
2126cd362defSPaolo Bonzini
2127cd362defSPaolo Bonzini
2128cd362defSPaolo Bonzini
2129cd362defSPaolo Bonzini##########################################
2130e86ecd4bSJuan Quintela# End of CC checks
2131e86ecd4bSJuan Quintela# After here, no more $cc or $ld runs
2132e86ecd4bSJuan Quintela
2133d83414e1SMarc-André Lureauwrite_c_skeleton
2134d83414e1SMarc-André Lureau
2135df42fa7dSPaolo Bonziniif test "$fortify_source" = "yes" ; then
2136086d5f75SPaolo Bonzini  QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
2137086d5f75SPaolo Bonzinifi
2138086d5f75SPaolo Bonzini
2139086d5f75SPaolo Bonzinicase "$ARCH" in
2140086d5f75SPaolo Bonzinialpha)
2141086d5f75SPaolo Bonzini  # Ensure there's only a single GP
2142086d5f75SPaolo Bonzini  QEMU_CFLAGS="-msmall-data $QEMU_CFLAGS"
2143086d5f75SPaolo Bonzini;;
2144086d5f75SPaolo Bonziniesac
2145086d5f75SPaolo Bonzini
2146247724cbSMarc-André Lureauif test "$have_asan" = "yes"; then
2147db5adeaaSPaolo Bonzini  QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
2148db5adeaaSPaolo Bonzini  QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
2149d83414e1SMarc-André Lureau  if test "$have_asan_iface_h" = "no" ; then
2150d83414e1SMarc-André Lureau      echo "ASAN build enabled, but ASAN header missing." \
2151d83414e1SMarc-André Lureau           "Without code annotation, the report may be inferior."
2152d83414e1SMarc-André Lureau  elif test "$have_asan_iface_fiber" = "no" ; then
2153d83414e1SMarc-André Lureau      echo "ASAN build enabled, but ASAN header is too old." \
2154d83414e1SMarc-André Lureau           "Without code annotation, the report may be inferior."
2155d83414e1SMarc-André Lureau  fi
2156247724cbSMarc-André Lureaufi
21570aebab04SLingfeng Yangif test "$have_tsan" = "yes" ; then
21580aebab04SLingfeng Yang  if test "$have_tsan_iface_fiber" = "yes" ; then
21590aebab04SLingfeng Yang    QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
21600aebab04SLingfeng Yang    QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
21610aebab04SLingfeng Yang  else
21620aebab04SLingfeng Yang    error_exit "Cannot enable TSAN due to missing fiber annotation interface."
21630aebab04SLingfeng Yang  fi
21640aebab04SLingfeng Yangelif test "$tsan" = "yes" ; then
21650aebab04SLingfeng Yang  error_exit "Cannot enable TSAN due to missing sanitize thread interface."
21660aebab04SLingfeng Yangfi
2167247724cbSMarc-André Lureauif test "$have_ubsan" = "yes"; then
2168db5adeaaSPaolo Bonzini  QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
2169db5adeaaSPaolo Bonzini  QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
2170247724cbSMarc-André Lureaufi
2171247724cbSMarc-André Lureau
21726542aa9cSPeter Lieven##########################################
21733efac6ebSTomáš Golembiovský
21740aebab04SLingfeng Yang# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
21750aebab04SLingfeng Yangif test "$solaris" = "no" && test "$tsan" = "no"; then
2176e86ecd4bSJuan Quintela    if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
2177db5adeaaSPaolo Bonzini        QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
2178e86ecd4bSJuan Quintela    fi
2179e86ecd4bSJuan Quintelafi
2180e86ecd4bSJuan Quintela
2181b846ab7cSPaolo Bonzini# Guest agent Windows MSI package
21829d6bc27bSMichael Roth
21839d6bc27bSMichael Rothif test "$QEMU_GA_MANUFACTURER" = ""; then
21849d6bc27bSMichael Roth  QEMU_GA_MANUFACTURER=QEMU
21859d6bc27bSMichael Rothfi
21869d6bc27bSMichael Rothif test "$QEMU_GA_DISTRO" = ""; then
21879d6bc27bSMichael Roth  QEMU_GA_DISTRO=Linux
21889d6bc27bSMichael Rothfi
21899d6bc27bSMichael Rothif test "$QEMU_GA_VERSION" = ""; then
219089138857SStefan Weil    QEMU_GA_VERSION=$(cat $source_path/VERSION)
21919d6bc27bSMichael Rothfi
21929d6bc27bSMichael Roth
2193*ad388845SPaolo Bonzini# Set up build tree symlinks that point back into the source tree
2194*ad388845SPaolo Bonzini# (these can be both files and directories).
2195*ad388845SPaolo Bonzini# Caution: avoid adding files or directories here using wildcards. This
2196*ad388845SPaolo Bonzini# will result in problems later if a new file matching the wildcard is
2197*ad388845SPaolo Bonzini# added to the source tree -- nothing will cause configure to be rerun
2198*ad388845SPaolo Bonzini# so the build tree will be missing the link back to the new file, and
2199*ad388845SPaolo Bonzini# tests might fail. Prefer to keep the relevant files in their own
2200*ad388845SPaolo Bonzini# directory and symlink the directory instead.
2201*ad388845SPaolo BonziniLINKS="Makefile"
2202*ad388845SPaolo BonziniLINKS="$LINKS tests/tcg/Makefile.target"
2203*ad388845SPaolo BonziniLINKS="$LINKS pc-bios/optionrom/Makefile"
2204*ad388845SPaolo BonziniLINKS="$LINKS pc-bios/s390-ccw/Makefile"
2205*ad388845SPaolo BonziniLINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
2206*ad388845SPaolo BonziniLINKS="$LINKS tests/avocado tests/data"
2207*ad388845SPaolo BonziniLINKS="$LINKS tests/qemu-iotests/check"
2208*ad388845SPaolo BonziniLINKS="$LINKS python"
2209*ad388845SPaolo BonziniLINKS="$LINKS contrib/plugins/Makefile "
2210*ad388845SPaolo Bonzinifor f in $LINKS ; do
2211*ad388845SPaolo Bonzini    if [ -e "$source_path/$f" ]; then
2212*ad388845SPaolo Bonzini        mkdir -p `dirname ./$f`
2213*ad388845SPaolo Bonzini        symlink "$source_path/$f" "$f"
2214*ad388845SPaolo Bonzini    fi
2215*ad388845SPaolo Bonzinidone
2216*ad388845SPaolo Bonzini
2217ca35f780SPaolo Bonzini# Mac OS X ships with a broken assembler
2218ca35f780SPaolo Bonziniroms=
2219e633a5c6SEric Blakeif { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \
2220ba7c60c2SPaolo Bonzini        test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
2221ba7c60c2SPaolo Bonzini        test "$targetos" != "haiku" && test "$softmmu" = yes ; then
2222e57218b6SPeter Maydell    # Different host OS linkers have different ideas about the name of the ELF
2223c65d5e4eSBrad Smith    # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
2224c65d5e4eSBrad Smith    # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
2225c65d5e4eSBrad Smith    for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
2226e57218b6SPeter Maydell        if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
2227e57218b6SPeter Maydell            ld_i386_emulation="$emu"
2228ca35f780SPaolo Bonzini            roms="optionrom"
2229e57218b6SPeter Maydell            break
2230e57218b6SPeter Maydell        fi
2231e57218b6SPeter Maydell    done
2232ca35f780SPaolo Bonzinifi
2233ca35f780SPaolo Bonzini
22342e33c3f8SThomas Huth# Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
2235a5b2afd5SThomas Huth# or -march=z10 (which is the lowest architecture level that Clang supports)
22369933c305SChristian Borntraegerif test "$cpu" = "s390x" ; then
22372e33c3f8SThomas Huth  write_c_skeleton
2238a5b2afd5SThomas Huth  compile_prog "-march=z900" ""
2239a5b2afd5SThomas Huth  has_z900=$?
22403af448b3SThomas Huth  if [ $has_z900 = 0 ] || compile_object "-march=z10 -msoft-float -Werror"; then
2241a5b2afd5SThomas Huth    if [ $has_z900 != 0 ]; then
2242a5b2afd5SThomas Huth      echo "WARNING: Your compiler does not support the z900!"
2243a5b2afd5SThomas Huth      echo "         The s390-ccw bios will only work with guest CPUs >= z10."
2244a5b2afd5SThomas Huth    fi
22459933c305SChristian Borntraeger    roms="$roms s390-ccw"
22461ef6bfc2SPhilippe Mathieu-Daudé    # SLOF is required for building the s390-ccw firmware on s390x,
22471ef6bfc2SPhilippe Mathieu-Daudé    # since it is using the libnet code from SLOF for network booting.
22481ef6bfc2SPhilippe Mathieu-Daudé    git_submodules="${git_submodules} roms/SLOF"
22491ef6bfc2SPhilippe Mathieu-Daudé  fi
22509933c305SChristian Borntraegerfi
22519933c305SChristian Borntraeger
225211cde1c8SBruno Dominguez# Check that the C++ compiler exists and works with the C compiler.
225311cde1c8SBruno 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.
225411cde1c8SBruno Dominguezif has $cxx; then
225511cde1c8SBruno Dominguez    cat > $TMPC <<EOF
225611cde1c8SBruno Dominguezint c_function(void);
225711cde1c8SBruno Dominguezint main(void) { return c_function(); }
225811cde1c8SBruno DominguezEOF
225911cde1c8SBruno Dominguez
226011cde1c8SBruno Dominguez    compile_object
226111cde1c8SBruno Dominguez
226211cde1c8SBruno Dominguez    cat > $TMPCXX <<EOF
226311cde1c8SBruno Dominguezextern "C" {
226411cde1c8SBruno Dominguez   int c_function(void);
226511cde1c8SBruno Dominguez}
226611cde1c8SBruno Dominguezint c_function(void) { return 42; }
226711cde1c8SBruno DominguezEOF
226811cde1c8SBruno Dominguez
226911cde1c8SBruno Dominguez    update_cxxflags
227011cde1c8SBruno Dominguez
2271a2866660SPaolo Bonzini    if do_cxx $CXXFLAGS $EXTRA_CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
227211cde1c8SBruno Dominguez        # C++ compiler $cxx works ok with C compiler $cc
227311cde1c8SBruno Dominguez        :
227411cde1c8SBruno Dominguez    else
227511cde1c8SBruno Dominguez        echo "C++ compiler $cxx does not work with C compiler $cc"
227611cde1c8SBruno Dominguez        echo "Disabling C++ specific optional code"
227711cde1c8SBruno Dominguez        cxx=
227811cde1c8SBruno Dominguez    fi
227911cde1c8SBruno Dominguezelse
228011cde1c8SBruno Dominguez    echo "No C++ compiler available; disabling C++ specific optional code"
228111cde1c8SBruno Dominguez    cxx=
228211cde1c8SBruno Dominguezfi
228311cde1c8SBruno Dominguez
22847d7dbf9dSDan Streetmanif !(GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
22857d7dbf9dSDan Streetman    exit 1
22865d91a2edSYonggang Luofi
22875d91a2edSYonggang Luo
228898ec69acSJuan Quintelaconfig_host_mak="config-host.mak"
228997a847bcSbellard
229098ec69acSJuan Quintelaecho "# Automatically generated by configure - do not modify" > $config_host_mak
229198ec69acSJuan Quintelaecho >> $config_host_mak
229298ec69acSJuan Quintela
2293e6c3b0f7SPaolo Bonziniecho all: >> $config_host_mak
2294cc84d63aSDaniel P. Berrangeecho "GIT=$git" >> $config_host_mak
2295aef45d51SDaniel P. Berrangeecho "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
22967d7dbf9dSDan Streetmanecho "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
2297804edf29SJuan Quintela
2298f8393946Saurel32if test "$debug_tcg" = "yes" ; then
22992358a494SJuan Quintela  echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
2300f8393946Saurel32fi
230167b915a5Sbellardif test "$mingw32" = "yes" ; then
230298ec69acSJuan Quintela  echo "CONFIG_WIN32=y" >> $config_host_mak
23039dacf32dSYossi Hindin  echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
23049dacf32dSYossi Hindin  echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
23059dacf32dSYossi Hindin  echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
2306210fa556Spbrookelse
230735f4df27SJuan Quintela  echo "CONFIG_POSIX=y" >> $config_host_mak
2308210fa556Spbrookfi
2309128ab2ffSblueswir1
2310dffcb71cSMark McLoughlinif test "$linux" = "yes" ; then
2311dffcb71cSMark McLoughlin  echo "CONFIG_LINUX=y" >> $config_host_mak
2312dffcb71cSMark McLoughlinfi
2313dffcb71cSMark McLoughlin
231483fb7adfSbellardif test "$darwin" = "yes" ; then
231598ec69acSJuan Quintela  echo "CONFIG_DARWIN=y" >> $config_host_mak
231683fb7adfSbellardfi
2317b29fe3edSmalc
2318ec530c81Sbellardif test "$solaris" = "yes" ; then
231998ec69acSJuan Quintela  echo "CONFIG_SOLARIS=y" >> $config_host_mak
2320ec530c81Sbellardfi
232197a847bcSbellardif test "$static" = "yes" ; then
232298ec69acSJuan Quintela  echo "CONFIG_STATIC=y" >> $config_host_mak
232397a847bcSbellardfi
232498ec69acSJuan Quintelaecho "SRC_PATH=$source_path" >> $config_host_mak
23252b1f35b9SAlex Bennéeecho "TARGET_DIRS=$target_list" >> $config_host_mak
232617969268SFam Zhengif test "$modules" = "yes"; then
232717969268SFam Zheng  echo "CONFIG_MODULES=y" >> $config_host_mak
232817969268SFam Zhengfi
2329277abf15SJan Vesely
233083fb7adfSbellard# XXX: suppress that
23317d3505c5Sbellardif [ "$bsd" = "yes" ] ; then
23322358a494SJuan Quintela  echo "CONFIG_BSD=y" >> $config_host_mak
23337d3505c5Sbellardfi
23347d3505c5Sbellard
23357c2acc70SPeter Maydellecho "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
23367d992e4dSPeter Lieven
2337d83414e1SMarc-André Lureauif test "$have_asan_iface_fiber" = "yes" ; then
2338d83414e1SMarc-André Lureau    echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
2339d83414e1SMarc-André Lureaufi
2340d83414e1SMarc-André Lureau
23410aebab04SLingfeng Yangif test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
23420aebab04SLingfeng Yang    echo "CONFIG_TSAN=y" >> $config_host_mak
23430aebab04SLingfeng Yangfi
23440aebab04SLingfeng Yang
234540e8c6f4SAlex Bennéeif test "$plugins" = "yes" ; then
234640e8c6f4SAlex Bennée    echo "CONFIG_PLUGIN=y" >> $config_host_mak
234740e8c6f4SAlex Bennéefi
234840e8c6f4SAlex Bennée
2349f48e590aSAlex Bennéeif test -n "$gdb_bin"; then
2350b1863cccSAlex Bennée    gdb_version=$($gdb_bin --version | head -n 1)
2351d6a66c81SAlex Bennée    if version_ge ${gdb_version##* } 9.1; then
2352f48e590aSAlex Bennée        echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
2353f48e590aSAlex Bennée    fi
2354b1863cccSAlex Bennéefi
2355f48e590aSAlex Bennée
235698ec69acSJuan Quintelaecho "ROMS=$roms" >> $config_host_mak
2357804edf29SJuan Quintelaecho "MAKE=$make" >> $config_host_mak
2358c886edfbSBlue Swirlecho "PYTHON=$python" >> $config_host_mak
235939d87c8cSAlex Bennéeecho "GENISOIMAGE=$genisoimage" >> $config_host_mak
2360a5665051SPaolo Bonziniecho "MESON=$meson" >> $config_host_mak
236109e93326SPaolo Bonziniecho "NINJA=$ninja" >> $config_host_mak
2362804edf29SJuan Quintelaecho "CC=$cc" >> $config_host_mak
2363804edf29SJuan Quintelaecho "AR=$ar" >> $config_host_mak
2364cdbd727cSRichard Hendersonecho "AS=$as" >> $config_host_mak
23655f6f0e27SRichard Hendersonecho "CCAS=$ccas" >> $config_host_mak
2366804edf29SJuan Quintelaecho "OBJCOPY=$objcopy" >> $config_host_mak
2367804edf29SJuan Quintelaecho "LD=$ld" >> $config_host_mak
2368a558ee17SJuan Quintelaecho "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
236911cde1c8SBruno Dominguezecho "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
23704cb37d11SPhilippe Mathieu-Daudéecho "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak
2371a81df1b6SPaolo Bonziniecho "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
2372a81df1b6SPaolo Bonziniecho "GLIB_LIBS=$glib_libs" >> $config_host_mak
23735b9e7d05SMarc-André Lureauecho "GLIB_BINDIR=$glib_bindir" >> $config_host_mak
2374d83acfd0SMarc-André Lureauecho "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak
23758a99e9a3SPhilippe Mathieu-Daudéecho "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
2376e57218b6SPeter Maydellecho "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
2377a70248dbSPaolo Bonziniecho "STRIP=$strip" >> $config_host_mak
2378804edf29SJuan Quintelaecho "EXESUF=$EXESUF" >> $config_host_mak
2379804edf29SJuan Quintela
23806efd7517SPeter Maydell# use included Linux headers
23816efd7517SPeter Maydellif test "$linux" = "yes" ; then
2382a307beb6SAndreas Färber  mkdir -p linux-headers
23836efd7517SPeter Maydell  case "$cpu" in
23844da270beSPaolo Bonzini  i386|x86_64)
238508312a63SPeter Maydell    linux_arch=x86
23866efd7517SPeter Maydell    ;;
2387d8ff892dSPaolo Bonzini  ppc|ppc64)
238808312a63SPeter Maydell    linux_arch=powerpc
23896efd7517SPeter Maydell    ;;
23906efd7517SPeter Maydell  s390x)
239108312a63SPeter Maydell    linux_arch=s390
239208312a63SPeter Maydell    ;;
23931f080313SClaudio Fontana  aarch64)
23941f080313SClaudio Fontana    linux_arch=arm64
23951f080313SClaudio Fontana    ;;
2396dfcf900bSWANG Xuerui  loongarch*)
2397dfcf900bSWANG Xuerui    linux_arch=loongarch
2398dfcf900bSWANG Xuerui    ;;
2399222e7d11SSanjay Lal  mips64)
2400222e7d11SSanjay Lal    linux_arch=mips
2401222e7d11SSanjay Lal    ;;
240208312a63SPeter Maydell  *)
240308312a63SPeter Maydell    # For most CPUs the kernel architecture name and QEMU CPU name match.
240408312a63SPeter Maydell    linux_arch="$cpu"
24056efd7517SPeter Maydell    ;;
24066efd7517SPeter Maydell  esac
240708312a63SPeter Maydell    # For non-KVM architectures we will not have asm headers
240808312a63SPeter Maydell    if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
240908312a63SPeter Maydell      symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
241008312a63SPeter Maydell    fi
24116efd7517SPeter Maydellfi
24126efd7517SPeter Maydell
241397a847bcSbellardfor target in $target_list; do
241497a847bcSbellard    target_dir="$target"
241557a93f16SPhilippe Mathieu-Daudé    target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
241697a847bcSbellard    mkdir -p $target_dir
2417fdb75aefSPaolo Bonzini    case $target in
2418fdb75aefSPaolo Bonzini        *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
2419fdb75aefSPaolo Bonzini        *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
24202408a527Saurel32    esac
242156aebc89Spbrookdone
24227d13299dSbellard
2423fdb75aefSPaolo Bonziniif test "$default_targets" = "yes"; then
2424fdb75aefSPaolo Bonzini  echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
2425fdb75aefSPaolo Bonzinifi
2426a540f158SPeter Crosthwaite
2427fd0e6053SJohn Snowif test "$ccache_cpp2" = "yes"; then
2428fd0e6053SJohn Snow  echo "export CCACHE_CPP2=y" >> $config_host_mak
2429fd0e6053SJohn Snowfi
2430fd0e6053SJohn Snow
24311e4f6065SDaniele Buonoif test "$safe_stack" = "yes"; then
24321e4f6065SDaniele Buono  echo "CONFIG_SAFESTACK=y" >> $config_host_mak
24331e4f6065SDaniele Buonofi
24341e4f6065SDaniele Buono
2435cd362defSPaolo Bonzini# tests/tcg configuration
2436cd362defSPaolo Bonzini(makefile=tests/tcg/Makefile.prereqs
2437cd362defSPaolo Bonziniecho "# Automatically generated by configure - do not modify" > $makefile
2438cd362defSPaolo Bonzini
2439cd362defSPaolo Bonziniconfig_host_mak=tests/tcg/config-host.mak
2440cd362defSPaolo Bonziniecho "# Automatically generated by configure - do not modify" > $config_host_mak
2441cd362defSPaolo Bonziniecho "SRC_PATH=$source_path" >> $config_host_mak
2442cd362defSPaolo Bonziniecho "HOST_CC=$host_cc" >> $config_host_mak
2443cd362defSPaolo Bonzini
2444cd362defSPaolo Bonzinitcg_tests_targets=
2445cd362defSPaolo Bonzinifor target in $target_list; do
2446cd362defSPaolo Bonzini  arch=${target%%-*}
2447cd362defSPaolo Bonzini
2448cd362defSPaolo Bonzini  probe_target_compiler ${arch}
2449cd362defSPaolo Bonzini  config_target_mak=tests/tcg/config-$target.mak
2450cd362defSPaolo Bonzini
2451cd362defSPaolo Bonzini  echo "# Automatically generated by configure - do not modify" > $config_target_mak
2452cd362defSPaolo Bonzini  echo "TARGET_NAME=$arch" >> $config_target_mak
2453cd362defSPaolo Bonzini  case $target in
2454cd362defSPaolo Bonzini    *-softmmu)
2455cd362defSPaolo Bonzini      test -f $source_path/tests/tcg/$arch/Makefile.softmmu-target || continue
2456cd362defSPaolo Bonzini      qemu="qemu-system-$arch"
2457cd362defSPaolo Bonzini      ;;
2458cd362defSPaolo Bonzini    *-linux-user|*-bsd-user)
2459cd362defSPaolo Bonzini      qemu="qemu-$arch"
2460cd362defSPaolo Bonzini      ;;
2461cd362defSPaolo Bonzini  esac
2462cd362defSPaolo Bonzini
2463cd362defSPaolo Bonzini  got_cross_cc=no
2464cd362defSPaolo Bonzini  unset build_static
2465cd362defSPaolo Bonzini
2466cd362defSPaolo Bonzini  if test -n "$target_cc"; then
2467cd362defSPaolo Bonzini      write_c_skeleton
2468cd362defSPaolo Bonzini      if ! do_compiler "$target_cc" $target_cflags \
2469cd362defSPaolo Bonzini           -o $TMPE $TMPC -static ; then
2470cd362defSPaolo Bonzini          # For host systems we might get away with building without -static
2471cd362defSPaolo Bonzini          if do_compiler "$target_cc" $target_cflags \
2472cd362defSPaolo Bonzini                         -o $TMPE $TMPC ; then
2473cd362defSPaolo Bonzini              got_cross_cc=yes
2474cd362defSPaolo Bonzini          fi
2475cd362defSPaolo Bonzini      else
2476cd362defSPaolo Bonzini          got_cross_cc=yes
2477cd362defSPaolo Bonzini          build_static=y
2478cd362defSPaolo Bonzini      fi
2479cd362defSPaolo Bonzini  elif test -n "$target_as" && test -n "$target_ld"; then
2480cd362defSPaolo Bonzini      # Special handling for assembler only tests
2481cd362defSPaolo Bonzini      case $target in
2482cd362defSPaolo Bonzini          tricore-softmmu) got_cross_cc=yes ;;
2483cd362defSPaolo Bonzini      esac
2484cd362defSPaolo Bonzini  fi
2485cd362defSPaolo Bonzini
2486cd362defSPaolo Bonzini  if test $got_cross_cc = yes; then
2487cd362defSPaolo Bonzini      # Test for compiler features for optional tests. We only do this
2488cd362defSPaolo Bonzini      # for cross compilers because ensuring the docker containers based
2489cd362defSPaolo Bonzini      # compilers is a requirememt for adding a new test that needs a
2490cd362defSPaolo Bonzini      # compiler feature.
2491cd362defSPaolo Bonzini
2492cd362defSPaolo Bonzini      echo "BUILD_STATIC=$build_static" >> $config_target_mak
2493cd362defSPaolo Bonzini      write_target_makefile >> $config_target_mak
2494cd362defSPaolo Bonzini      case $target in
2495cd362defSPaolo Bonzini          aarch64-*)
2496cd362defSPaolo Bonzini              if do_compiler "$target_cc" $target_cflags \
2497cd362defSPaolo Bonzini                             -march=armv8.1-a+sve -o $TMPE $TMPC; then
2498cd362defSPaolo Bonzini                  echo "CROSS_CC_HAS_SVE=y" >> $config_target_mak
2499cd362defSPaolo Bonzini              fi
2500cd362defSPaolo Bonzini              if do_compiler "$target_cc" $target_cflags \
2501cd362defSPaolo Bonzini                             -march=armv8.1-a+sve2 -o $TMPE $TMPC; then
2502cd362defSPaolo Bonzini                  echo "CROSS_CC_HAS_SVE2=y" >> $config_target_mak
2503cd362defSPaolo Bonzini              fi
2504cd362defSPaolo Bonzini              if do_compiler "$target_cc" $target_cflags \
2505cd362defSPaolo Bonzini                             -march=armv8.3-a -o $TMPE $TMPC; then
2506cd362defSPaolo Bonzini                  echo "CROSS_CC_HAS_ARMV8_3=y" >> $config_target_mak
2507cd362defSPaolo Bonzini              fi
2508cd362defSPaolo Bonzini              if do_compiler "$target_cc" $target_cflags \
2509cd362defSPaolo Bonzini                             -mbranch-protection=standard -o $TMPE $TMPC; then
2510cd362defSPaolo Bonzini                  echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak
2511cd362defSPaolo Bonzini              fi
2512cd362defSPaolo Bonzini              if do_compiler "$target_cc" $target_cflags \
2513cd362defSPaolo Bonzini                             -march=armv8.5-a+memtag -o $TMPE $TMPC; then
2514cd362defSPaolo Bonzini                  echo "CROSS_CC_HAS_ARMV8_MTE=y" >> $config_target_mak
2515cd362defSPaolo Bonzini              fi
2516cd362defSPaolo Bonzini              ;;
2517cd362defSPaolo Bonzini          ppc*)
2518cd362defSPaolo Bonzini              if do_compiler "$target_cc" $target_cflags \
2519cd362defSPaolo Bonzini                             -mpower8-vector -o $TMPE $TMPC; then
2520cd362defSPaolo Bonzini                  echo "CROSS_CC_HAS_POWER8_VECTOR=y" >> $config_target_mak
2521cd362defSPaolo Bonzini              fi
2522cd362defSPaolo Bonzini              if do_compiler "$target_cc" $target_cflags \
2523cd362defSPaolo Bonzini                             -mpower10 -o $TMPE $TMPC; then
2524cd362defSPaolo Bonzini                  echo "CROSS_CC_HAS_POWER10=y" >> $config_target_mak
2525cd362defSPaolo Bonzini              fi
2526cd362defSPaolo Bonzini              ;;
2527cd362defSPaolo Bonzini          i386-linux-user)
2528cd362defSPaolo Bonzini              if do_compiler "$target_cc" $target_cflags \
2529cd362defSPaolo Bonzini                             -Werror -fno-pie -o $TMPE $TMPC; then
2530cd362defSPaolo Bonzini                  echo "CROSS_CC_HAS_I386_NOPIE=y" >> $config_target_mak
2531cd362defSPaolo Bonzini              fi
2532cd362defSPaolo Bonzini              ;;
2533cd362defSPaolo Bonzini      esac
2534cd362defSPaolo Bonzini  elif test -n "$container_image"; then
2535cd362defSPaolo Bonzini      echo "build-tcg-tests-$target: docker-image-$container_image" >> $makefile
2536cd362defSPaolo Bonzini      echo "BUILD_STATIC=y" >> $config_target_mak
2537cd362defSPaolo Bonzini      write_container_target_makefile >> $config_target_mak
2538cd362defSPaolo Bonzini      case $target in
2539cd362defSPaolo Bonzini          aarch64-*)
2540cd362defSPaolo Bonzini              echo "CROSS_CC_HAS_SVE=y" >> $config_target_mak
2541cd362defSPaolo Bonzini              echo "CROSS_CC_HAS_SVE2=y" >> $config_target_mak
2542cd362defSPaolo Bonzini              echo "CROSS_CC_HAS_ARMV8_3=y" >> $config_target_mak
2543cd362defSPaolo Bonzini              echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak
2544cd362defSPaolo Bonzini              echo "CROSS_CC_HAS_ARMV8_MTE=y" >> $config_target_mak
2545cd362defSPaolo Bonzini              ;;
2546cd362defSPaolo Bonzini          ppc*)
2547cd362defSPaolo Bonzini              echo "CROSS_CC_HAS_POWER8_VECTOR=y" >> $config_target_mak
2548cd362defSPaolo Bonzini              echo "CROSS_CC_HAS_POWER10=y" >> $config_target_mak
2549cd362defSPaolo Bonzini              ;;
2550cd362defSPaolo Bonzini          i386-linux-user)
2551cd362defSPaolo Bonzini              echo "CROSS_CC_HAS_I386_NOPIE=y" >> $config_target_mak
2552cd362defSPaolo Bonzini              ;;
2553cd362defSPaolo Bonzini      esac
2554cd362defSPaolo Bonzini      got_cross_cc=yes
2555cd362defSPaolo Bonzini  fi
2556cd362defSPaolo Bonzini  if test $got_cross_cc = yes; then
2557cd362defSPaolo Bonzini      mkdir -p tests/tcg/$target
2558cd362defSPaolo Bonzini      echo "QEMU=$PWD/$qemu" >> $config_target_mak
2559cd362defSPaolo Bonzini      echo "EXTRA_CFLAGS=$target_cflags" >> $config_target_mak
2560cd362defSPaolo Bonzini      echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> $makefile
2561cd362defSPaolo Bonzini      tcg_tests_targets="$tcg_tests_targets $target"
2562cd362defSPaolo Bonzini  fi
25632038f8c8SPaolo Bonzinidone
2564cd362defSPaolo Bonziniecho "TCG_TESTS_TARGETS=$tcg_tests_targets" >> $makefile)
25652038f8c8SPaolo Bonzini
256698409991SHelge Konetzkaconfig_mak=pc-bios/optionrom/config.mak
256798409991SHelge Konetzkaecho "# Automatically generated by configure - do not modify" > $config_mak
256898409991SHelge Konetzkaecho "TOPSRC_DIR=$source_path" >> $config_mak
256998409991SHelge Konetzka
2570a5665051SPaolo Bonziniif test "$skip_meson" = no; then
2571fc929892SMarc-André Lureau  cross="config-meson.cross.new"
2572fc929892SMarc-André Lureau  meson_quote() {
2573ac7ebcc5SPaolo Bonzini    test $# = 0 && return
257447b30835SPaolo Bonzini    echo "'$(echo $* | sed "s/ /','/g")'"
2575fc929892SMarc-André Lureau  }
2576fc929892SMarc-André Lureau
2577fc929892SMarc-André Lureau  echo "# Automatically generated by configure - do not modify" > $cross
2578fc929892SMarc-André Lureau  echo "[properties]" >> $cross
2579d1d5e9eeSAlex Bennée
2580d1d5e9eeSAlex Bennée  # unroll any custom device configs
2581d1d5e9eeSAlex Bennée  for a in $device_archs; do
2582d1d5e9eeSAlex Bennée      eval "c=\$devices_${a}"
2583d1d5e9eeSAlex Bennée      echo "${a}-softmmu = '$c'" >> $cross
2584d1d5e9eeSAlex Bennée  done
2585d1d5e9eeSAlex Bennée
2586fc929892SMarc-André Lureau  test -z "$cxx" && echo "link_language = 'c'" >> $cross
258747b30835SPaolo Bonzini  echo "[built-in options]" >> $cross
2588a2866660SPaolo Bonzini  echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
2589a2866660SPaolo Bonzini  echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
2590e910c7d9SPhilippe Mathieu-Daudé  test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
2591a2866660SPaolo Bonzini  echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
2592a2866660SPaolo Bonzini  echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
2593fc929892SMarc-André Lureau  echo "[binaries]" >> $cross
25944dba2789SPaolo Bonzini  echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
25954dba2789SPaolo Bonzini  test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
25964dba2789SPaolo Bonzini  test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
259747b30835SPaolo Bonzini  echo "ar = [$(meson_quote $ar)]" >> $cross
259847b30835SPaolo Bonzini  echo "nm = [$(meson_quote $nm)]" >> $cross
259947b30835SPaolo Bonzini  echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
260047b30835SPaolo Bonzini  echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
2601e8178514SPaolo Bonzini  if has $sdl2_config; then
260247b30835SPaolo Bonzini    echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
2603e8178514SPaolo Bonzini  fi
260447b30835SPaolo Bonzini  echo "strip = [$(meson_quote $strip)]" >> $cross
2605158bb224SKonstantin Kostiuk  echo "widl = [$(meson_quote $widl)]" >> $cross
260647b30835SPaolo Bonzini  echo "windres = [$(meson_quote $windres)]" >> $cross
26073812c0c4SJoelle van Dyne  if test "$cross_compile" = "yes"; then
2608fc929892SMarc-André Lureau    cross_arg="--cross-file config-meson.cross"
2609fc929892SMarc-André Lureau    echo "[host_machine]" >> $cross
2610ba7c60c2SPaolo Bonzini    echo "system = '$targetos'" >> $cross
2611823eb013SPaolo Bonzini    case "$cpu" in
2612f6bca9dfSJoelle van Dyne        i386)
2613fc929892SMarc-André Lureau            echo "cpu_family = 'x86'" >> $cross
2614fc929892SMarc-André Lureau            ;;
2615fc929892SMarc-André Lureau        *)
2616823eb013SPaolo Bonzini            echo "cpu_family = '$cpu'" >> $cross
2617fc929892SMarc-André Lureau            ;;
2618fc929892SMarc-André Lureau    esac
2619fc929892SMarc-André Lureau    echo "cpu = '$cpu'" >> $cross
2620fc929892SMarc-André Lureau    if test "$bigendian" = "yes" ; then
2621fc929892SMarc-André Lureau        echo "endian = 'big'" >> $cross
2622fc929892SMarc-André Lureau    else
2623fc929892SMarc-André Lureau        echo "endian = 'little'" >> $cross
2624fc929892SMarc-André Lureau    fi
2625fc929892SMarc-André Lureau  else
2626fc929892SMarc-André Lureau    cross_arg="--native-file config-meson.cross"
2627fc929892SMarc-André Lureau  fi
2628fc929892SMarc-André Lureau  mv $cross config-meson.cross
2629fc929892SMarc-André Lureau
2630a5665051SPaolo Bonzini  rm -rf meson-private meson-info meson-logs
26310a31e3a0SPaolo Bonzini
26320a31e3a0SPaolo Bonzini  # Built-in options
26330a31e3a0SPaolo Bonzini  test "$bindir" != "bin" && meson_option_add "-Dbindir=$bindir"
26340a31e3a0SPaolo Bonzini  test "$default_feature" = no && meson_option_add -Dauto_features=disabled
26350a31e3a0SPaolo Bonzini  test "$pie" = no && meson_option_add -Db_pie=false
26360a31e3a0SPaolo Bonzini  test "$werror" = yes && meson_option_add -Dwerror=true
26370a31e3a0SPaolo Bonzini
26380a31e3a0SPaolo Bonzini  # QEMU options
26390a31e3a0SPaolo Bonzini  test "$cfi" != false && meson_option_add "-Dcfi=$cfi"
26400a31e3a0SPaolo Bonzini  test "$fdt" != auto && meson_option_add "-Dfdt=$fdt"
26410a31e3a0SPaolo Bonzini  test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
26420a31e3a0SPaolo Bonzini  test "$qemu_suffix" != qemu && meson_option_add "-Dqemu_suffix=$qemu_suffix"
26430a31e3a0SPaolo Bonzini  test "$slirp" != auto && meson_option_add "-Dslirp=$slirp"
26440a31e3a0SPaolo Bonzini  test "$smbd" != '' && meson_option_add "-Dsmbd=$smbd"
26450a31e3a0SPaolo Bonzini  test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
264661d63097SPaolo Bonzini  run_meson() {
26470a31e3a0SPaolo Bonzini    NINJA=$ninja $meson setup --prefix "$prefix" "$@" $cross_arg "$PWD" "$source_path"
264861d63097SPaolo Bonzini  }
264961d63097SPaolo Bonzini  eval run_meson $meson_options
2650a5665051SPaolo Bonzini  if test "$?" -ne 0 ; then
2651a5665051SPaolo Bonzini      error_exit "meson setup failed"
2652a5665051SPaolo Bonzini  fi
2653699d3884SPaolo Bonzinielse
2654699d3884SPaolo Bonzini  if test -f meson-private/cmd_line.txt; then
2655699d3884SPaolo Bonzini    # Adjust old command line options whose type was changed
2656699d3884SPaolo Bonzini    # Avoids having to use "setup --wipe" when Meson is upgraded
2657699d3884SPaolo Bonzini    perl -i -ne '
2658699d3884SPaolo Bonzini      s/^gettext = true$/gettext = auto/;
2659699d3884SPaolo Bonzini      s/^gettext = false$/gettext = disabled/;
2660654d6b04SPaolo Bonzini      /^b_staticpic/ && next;
2661699d3884SPaolo Bonzini      print;' meson-private/cmd_line.txt
2662699d3884SPaolo Bonzini  fi
2663a5665051SPaolo Bonzinifi
2664a5665051SPaolo Bonzini
2665dc655404SMichael S. Tsirkin# Save the configure command line for later reuse.
2666dc655404SMichael S. Tsirkincat <<EOD >config.status
2667dc655404SMichael S. Tsirkin#!/bin/sh
2668dc655404SMichael S. Tsirkin# Generated by configure.
2669dc655404SMichael S. Tsirkin# Run this file to recreate the current configuration.
2670dc655404SMichael S. Tsirkin# Compiler output produced by configure, useful for debugging
2671dc655404SMichael S. Tsirkin# configure, is in config.log if it exists.
2672dc655404SMichael S. TsirkinEOD
2673e811da7fSDaniel P. Berrangé
2674e811da7fSDaniel P. Berrangépreserve_env() {
2675e811da7fSDaniel P. Berrangé    envname=$1
2676e811da7fSDaniel P. Berrangé
2677e811da7fSDaniel P. Berrangé    eval envval=\$$envname
2678e811da7fSDaniel P. Berrangé
2679e811da7fSDaniel P. Berrangé    if test -n "$envval"
2680e811da7fSDaniel P. Berrangé    then
2681e811da7fSDaniel P. Berrangé	echo "$envname='$envval'" >> config.status
2682e811da7fSDaniel P. Berrangé	echo "export $envname" >> config.status
2683e811da7fSDaniel P. Berrangé    else
2684e811da7fSDaniel P. Berrangé	echo "unset $envname" >> config.status
2685e811da7fSDaniel P. Berrangé    fi
2686e811da7fSDaniel P. Berrangé}
2687e811da7fSDaniel P. Berrangé
2688e811da7fSDaniel P. Berrangé# Preserve various env variables that influence what
2689e811da7fSDaniel P. Berrangé# features/build target configure will detect
2690e811da7fSDaniel P. Berrangépreserve_env AR
2691e811da7fSDaniel P. Berrangépreserve_env AS
2692e811da7fSDaniel P. Berrangépreserve_env CC
26938009da03SPaolo Bonzinipreserve_env CFLAGS
2694e811da7fSDaniel P. Berrangépreserve_env CXX
26958009da03SPaolo Bonzinipreserve_env CXXFLAGS
2696e811da7fSDaniel P. Berrangépreserve_env INSTALL
2697e811da7fSDaniel P. Berrangépreserve_env LD
26988009da03SPaolo Bonzinipreserve_env LDFLAGS
2699e811da7fSDaniel P. Berrangépreserve_env LD_LIBRARY_PATH
2700e811da7fSDaniel P. Berrangépreserve_env LIBTOOL
2701e811da7fSDaniel P. Berrangépreserve_env MAKE
2702e811da7fSDaniel P. Berrangépreserve_env NM
2703e811da7fSDaniel P. Berrangépreserve_env OBJCOPY
2704e811da7fSDaniel P. Berrangépreserve_env PATH
2705e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG
2706e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_LIBDIR
2707e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_PATH
2708e811da7fSDaniel P. Berrangépreserve_env PYTHON
2709e811da7fSDaniel P. Berrangépreserve_env SDL2_CONFIG
2710e811da7fSDaniel P. Berrangépreserve_env SMBD
2711e811da7fSDaniel P. Berrangépreserve_env STRIP
2712158bb224SKonstantin Kostiukpreserve_env WIDL
2713e811da7fSDaniel P. Berrangépreserve_env WINDRES
2714e811da7fSDaniel P. Berrangé
2715dc655404SMichael S. Tsirkinprintf "exec" >>config.status
2716a5665051SPaolo Bonzinifor i in "$0" "$@"; do
2717835af899SPaolo Bonzini  test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
2718a5665051SPaolo Bonzinidone
2719cf7cc929SDr. David Alan Gilbertecho ' "$@"' >>config.status
2720dc655404SMichael S. Tsirkinchmod +x config.status
2721dc655404SMichael S. Tsirkin
27228cd05ab6SPeter Maydellrm -r "$TMPDIR1"
2723