xref: /openbmc/qemu/configure (revision 15b273f8)
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
6064708615SPeter Maydell    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}"
70563661c0SPeter Maydellif ! mkdir -p "${TMPDIR1}"; then
718cd05ab6SPeter Maydell    echo "ERROR: failed to create temporary directory"
728cd05ab6SPeter Maydell    exit 1
737d13299dSbellardfi
747d13299dSbellard
758cd05ab6SPeter MaydellTMPB="qemu-conf"
768cd05ab6SPeter MaydellTMPC="${TMPDIR1}/${TMPB}.c"
7766518bf6SDon SlutzTMPO="${TMPDIR1}/${TMPB}.o"
784cb37d11SPhilippe Mathieu-DaudéTMPM="${TMPDIR1}/${TMPB}.m"
798cd05ab6SPeter MaydellTMPE="${TMPDIR1}/${TMPB}.exe"
807d13299dSbellard
81da1d85e3SGerd Hoffmannrm -f config.log
829ac81bbbSmalc
83b48e3611SPeter Maydell# Print a helpful header at the top of config.log
84b48e3611SPeter Maydellecho "# QEMU configure log $(date)" >> config.log
85979ae168SPeter Maydellprintf "# Configured with:" >> config.log
86979ae168SPeter Maydellprintf " '%s'" "$0" "$@" >> config.log
87979ae168SPeter Maydellecho >> config.log
88b48e3611SPeter Maydellecho "#" >> config.log
89b48e3611SPeter Maydell
90835af899SPaolo Bonziniquote_sh() {
91835af899SPaolo Bonzini    printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
92835af899SPaolo Bonzini}
93835af899SPaolo Bonzini
94d880a3baSPaolo Bonziniprint_error() {
95d880a3baSPaolo Bonzini    (echo
9676ad07a4SPeter Maydell    echo "ERROR: $1"
9776ad07a4SPeter Maydell    while test -n "$2"; do
9876ad07a4SPeter Maydell        echo "       $2"
9976ad07a4SPeter Maydell        shift
10076ad07a4SPeter Maydell    done
101d880a3baSPaolo Bonzini    echo) >&2
102d880a3baSPaolo Bonzini}
103d880a3baSPaolo Bonzini
104d880a3baSPaolo Bonzinierror_exit() {
105d880a3baSPaolo Bonzini    print_error "$@"
10676ad07a4SPeter Maydell    exit 1
10776ad07a4SPeter Maydell}
10876ad07a4SPeter Maydell
1099c83ffd8SPeter Maydelldo_compiler() {
1109c83ffd8SPeter Maydell  # Run the compiler, capturing its output to the log. First argument
1119c83ffd8SPeter Maydell  # is compiler binary to execute.
112b3b5472dSPeter Maydell  compiler="$1"
113cd362defSPaolo Bonzini  shift
114cd362defSPaolo Bonzini  if test -n "$BASH_VERSION"; then eval '
115cd362defSPaolo Bonzini      echo >>config.log "
116cd362defSPaolo Bonzinifuncs: ${FUNCNAME[*]}
117cd362defSPaolo Bonzinilines: ${BASH_LINENO[*]}"
118cd362defSPaolo Bonzini  '; fi
119cd362defSPaolo Bonzini  echo $compiler "$@" >> config.log
120cd362defSPaolo Bonzini  $compiler "$@" >> config.log 2>&1 || return $?
121cd362defSPaolo Bonzini}
122cd362defSPaolo Bonzini
123cd362defSPaolo Bonzinido_compiler_werror() {
124cd362defSPaolo Bonzini    # Run the compiler, capturing its output to the log. First argument
125cd362defSPaolo Bonzini    # is compiler binary to execute.
126630d86b7SDavid CARLIER    compiler="$1"
1279c83ffd8SPeter Maydell    shift
1288bbe05d7SIan Jackson    if test -n "$BASH_VERSION"; then eval '
1298bbe05d7SIan Jackson        echo >>config.log "
1308bbe05d7SIan Jacksonfuncs: ${FUNCNAME[*]}
1318bbe05d7SIan Jacksonlines: ${BASH_LINENO[*]}"
1328bbe05d7SIan Jackson    '; fi
1339c83ffd8SPeter Maydell    echo $compiler "$@" >> config.log
1349c83ffd8SPeter Maydell    $compiler "$@" >> config.log 2>&1 || return $?
1358dc38a78SPeter Maydell    # Test passed. If this is an --enable-werror build, rerun
1368dc38a78SPeter Maydell    # the test with -Werror and bail out if it fails. This
1378dc38a78SPeter Maydell    # makes warning-generating-errors in configure test code
1388dc38a78SPeter Maydell    # obvious to developers.
1398dc38a78SPeter Maydell    if test "$werror" != "yes"; then
1408dc38a78SPeter Maydell        return 0
1418dc38a78SPeter Maydell    fi
1428dc38a78SPeter Maydell    # Don't bother rerunning the compile if we were already using -Werror
1438dc38a78SPeter Maydell    case "$*" in
1448dc38a78SPeter Maydell        *-Werror*)
1458dc38a78SPeter Maydell           return 0
1468dc38a78SPeter Maydell        ;;
1478dc38a78SPeter Maydell    esac
1489c83ffd8SPeter Maydell    echo $compiler -Werror "$@" >> config.log
1499c83ffd8SPeter Maydell    $compiler -Werror "$@" >> config.log 2>&1 && return $?
15076ad07a4SPeter Maydell    error_exit "configure test passed without -Werror but failed with -Werror." \
15176ad07a4SPeter Maydell        "This is probably a bug in the configure script. The failing command" \
15276ad07a4SPeter Maydell        "will be at the bottom of config.log." \
15376ad07a4SPeter Maydell        "You can run configure with --disable-werror to bypass this check."
1548dc38a78SPeter Maydell}
1558dc38a78SPeter Maydell
1569c83ffd8SPeter Maydelldo_cc() {
157cd362defSPaolo Bonzini    do_compiler_werror "$cc" $CPU_CFLAGS "$@"
1589c83ffd8SPeter Maydell}
1599c83ffd8SPeter Maydell
1604cb37d11SPhilippe Mathieu-Daudédo_objc() {
161cd362defSPaolo Bonzini    do_compiler_werror "$objcc" $CPU_CFLAGS "$@"
1624cb37d11SPhilippe Mathieu-Daudé}
1634cb37d11SPhilippe Mathieu-Daudé
16400849b92SRichard Henderson# Append $2 to the variable named $1, with space separation
16500849b92SRichard Hendersonadd_to() {
16600849b92SRichard Henderson    eval $1=\${$1:+\"\$$1 \"}\$2
16700849b92SRichard Henderson}
16800849b92SRichard Henderson
16952166aa0SJuan Quintelacompile_object() {
170fd0e6053SJohn Snow  local_cflags="$1"
171a2866660SPaolo Bonzini  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
17252166aa0SJuan Quintela}
17352166aa0SJuan Quintela
17452166aa0SJuan Quintelacompile_prog() {
17552166aa0SJuan Quintela  local_cflags="$1"
17652166aa0SJuan Quintela  local_ldflags="$2"
177a2866660SPaolo Bonzini  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
178a2866660SPaolo Bonzini      $LDFLAGS $EXTRA_LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
17952166aa0SJuan Quintela}
18052166aa0SJuan Quintela
18111568d6dSPaolo Bonzini# symbolically link $1 to $2.  Portable version of "ln -sf".
18211568d6dSPaolo Bonzinisymlink() {
18372b8b5a1SStefan Weil  rm -rf "$2"
184ec5b06d7SAnthony Liguori  mkdir -p "$(dirname "$2")"
18572b8b5a1SStefan Weil  ln -s "$1" "$2"
18611568d6dSPaolo Bonzini}
18711568d6dSPaolo Bonzini
1880dba6195SLoïc Minier# check whether a command is available to this shell (may be either an
1890dba6195SLoïc Minier# executable or a builtin)
1900dba6195SLoïc Minierhas() {
1910dba6195SLoïc Minier    type "$1" >/dev/null 2>&1
1920dba6195SLoïc Minier}
1930dba6195SLoïc Minier
1940a01d76fSMarc-André Lureauversion_ge () {
1952df52b9bSAlex Bennée    local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
1962df52b9bSAlex Bennée    local_ver2=$(echo "$2" | tr . ' ')
1970a01d76fSMarc-André Lureau    while true; do
1980a01d76fSMarc-André Lureau        set x $local_ver1
1990a01d76fSMarc-André Lureau        local_first=${2-0}
200c44a33e2SStefano Garzarella        # 'shift 2' if $2 is set, or 'shift' if $2 is not set
201c44a33e2SStefano Garzarella        shift ${2:+2}
2020a01d76fSMarc-André Lureau        local_ver1=$*
2030a01d76fSMarc-André Lureau        set x $local_ver2
2040a01d76fSMarc-André Lureau        # the second argument finished, the first must be greater or equal
2050a01d76fSMarc-André Lureau        test $# = 1 && return 0
2060a01d76fSMarc-André Lureau        test $local_first -lt $2 && return 1
2070a01d76fSMarc-André Lureau        test $local_first -gt $2 && return 0
208c44a33e2SStefano Garzarella        shift ${2:+2}
2090a01d76fSMarc-André Lureau        local_ver2=$*
2100a01d76fSMarc-André Lureau    done
2110a01d76fSMarc-André Lureau}
2120a01d76fSMarc-André Lureau
2133b6b7550SPaolo Bonziniglob() {
2143b6b7550SPaolo Bonzini    eval test -z '"${1#'"$2"'}"'
2153b6b7550SPaolo Bonzini}
2163b6b7550SPaolo Bonzini
2174ace32e2SAntonio Ospiteif printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
2184ace32e2SAntonio Ospitethen
2194ace32e2SAntonio Ospite  error_exit "main directory cannot contain spaces nor colons"
2204ace32e2SAntonio Ospitefi
2214ace32e2SAntonio Ospite
22214211825SAntonio Ospite# default parameters
2232ff6b91eSJuan Quintelacpu=""
22443ce4dfeSbellardstatic="no"
2253812c0c4SJoelle van Dynecross_compile="no"
2267d13299dSbellardcross_prefix=""
227e49d021eSPeter Maydellhost_cc="cc"
22863678e17SSteven Noonanstack_protector=""
2291e4f6065SDaniele Buonosafe_stack=""
230afc3a8f9SAlex Bennéeuse_containers="yes"
231f2385398SAlex Bennéegdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
232ac0df51dSaliguori
23392712822SDaniel P. Berrangeif test -e "$source_path/.git"
23492712822SDaniel P. Berrangethen
2357d7dbf9dSDan Streetman    git_submodules_action="update"
23692712822SDaniel P. Berrangeelse
2377d7dbf9dSDan Streetman    git_submodules_action="ignore"
23892712822SDaniel P. Berrangefi
2392d652f24SPaolo Bonzini
2402d652f24SPaolo Bonzinigit_submodules="ui/keycodemapdb"
241cc84d63aSDaniel P. Berrangegit="git"
242ac0df51dSaliguori
243afb63ebdSStefan Weil# Don't accept a target_list environment variable.
244afb63ebdSStefan Weilunset target_list
245447e133fSAlex Bennéeunset target_list_exclude
246377529c0SPaolo Bonzini
247377529c0SPaolo Bonzini# Default value for a variable defining feature "foo".
248377529c0SPaolo Bonzini#  * foo="no"  feature will only be used if --enable-foo arg is given
249377529c0SPaolo Bonzini#  * foo=""    feature will be searched for, and if found, will be used
250377529c0SPaolo Bonzini#              unless --disable-foo is given
251377529c0SPaolo Bonzini#  * foo="yes" this value will only be set by --enable-foo flag.
252377529c0SPaolo Bonzini#              feature will searched for,
253377529c0SPaolo Bonzini#              if not found, configure exits with error
254377529c0SPaolo Bonzini#
255377529c0SPaolo Bonzini# Always add --enable-foo and --disable-foo command line args.
256377529c0SPaolo Bonzini# Distributions want to ensure that several features are compiled in, and it
257377529c0SPaolo Bonzini# is impossible without a --enable-foo that exits if a feature is not found.
258377529c0SPaolo Bonzini
259c87ea116SAlex Bennéedefault_feature=""
260c87ea116SAlex Bennée# parse CC options second
261c87ea116SAlex Bennéefor opt do
262c87ea116SAlex Bennée  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
263c87ea116SAlex Bennée  case "$opt" in
264c87ea116SAlex Bennée      --without-default-features)
265c87ea116SAlex Bennée          default_feature="no"
266c87ea116SAlex Bennée  ;;
267c87ea116SAlex Bennée  esac
268c87ea116SAlex Bennéedone
269c87ea116SAlex Bennée
270a2866660SPaolo BonziniEXTRA_CFLAGS=""
271a2866660SPaolo BonziniEXTRA_CXXFLAGS=""
272e910c7d9SPhilippe Mathieu-DaudéEXTRA_OBJCFLAGS=""
273a2866660SPaolo BonziniEXTRA_LDFLAGS=""
274a2866660SPaolo Bonzini
275377529c0SPaolo Bonzinidebug_tcg="no"
276247724cbSMarc-André Lureausanitizers="no"
2770aebab04SLingfeng Yangtsan="no"
2781f3f2bfeSMichael Tokarevfortify_source="yes"
279c7328271SMiroslav RezaninaEXESUF=""
28017969268SFam Zhengmodules="no"
281377529c0SPaolo Bonziniprefix="/usr/local"
28210ff82d1SMarc-André Lureauqemu_suffix="qemu"
283377529c0SPaolo Bonzinisoftmmu="yes"
284b915a2f1SPaolo Bonzinilinux_user=""
285b915a2f1SPaolo Bonzinibsd_user=""
28640d6444eSAvi Kivitypie=""
287519175a2SAlex Barcelocoroutine=""
288ba4dd2aaSAlex Bennéeplugins="$default_feature"
289a5665051SPaolo Bonzinimeson=""
29048328880SPaolo Bonzinininja=""
291c09c1ce7SPaolo Bonzinibindir="bin"
292a5665051SPaolo Bonziniskip_meson=no
29355116968SJagannathan Ramanvfio_user_server="disabled"
294377529c0SPaolo Bonzini
2953b4da132SPaolo Bonzini# The following Meson options are handled manually (still they
2963b4da132SPaolo Bonzini# are included in the automatically generated help message)
2973b4da132SPaolo Bonzini
2983b4da132SPaolo Bonzini# 1. Track which submodules are needed
2990577e84dSThomas Huthfdt="auto"
3003b4da132SPaolo Bonzini
301c54b59eeSPaolo Bonzini# 2. Automatically enable/disable other options
3027630156dSPhilippe Mathieu-Daudétcg="auto"
3033b4da132SPaolo Bonzinicfi="false"
3043b4da132SPaolo Bonzini
305c87ea116SAlex Bennée# parse CC options second
306ac0df51dSaliguorifor opt do
30789138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
308ac0df51dSaliguori  case "$opt" in
309ac0df51dSaliguori  --cross-prefix=*) cross_prefix="$optarg"
3103812c0c4SJoelle van Dyne                    cross_compile="yes"
311ac0df51dSaliguori  ;;
3123d8df640SPaolo Bonzini  --cc=*) CC="$optarg"
313ac0df51dSaliguori  ;;
31483f73fceSTomoki Sekiyama  --cxx=*) CXX="$optarg"
31583f73fceSTomoki Sekiyama  ;;
3162ff6b91eSJuan Quintela  --cpu=*) cpu="$optarg"
3172ff6b91eSJuan Quintela  ;;
318a2866660SPaolo Bonzini  --extra-cflags=*)
319a2866660SPaolo Bonzini    EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
320a2866660SPaolo Bonzini    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
321e910c7d9SPhilippe Mathieu-Daudé    EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
322e2a2ed06SJuan Quintela    ;;
323a2866660SPaolo Bonzini  --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
32411cde1c8SBruno Dominguez  ;;
325e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
326e910c7d9SPhilippe Mathieu-Daudé  ;;
327a2866660SPaolo Bonzini  --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
328e2a2ed06SJuan Quintela  ;;
329d75402b5SAlex Bennée  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
330d75402b5SAlex Bennée  ;;
331479ca4ccSMatheus Ferst  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
332d422b2bcSAlex Bennée                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
333d422b2bcSAlex Bennée  ;;
334d75402b5SAlex Bennée  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
335d75402b5SAlex Bennée                eval "cross_cc_${cc_arch}=\$optarg"
336d75402b5SAlex Bennée  ;;
3375adb43beSPaolo Bonzini  --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-prefix-FOO option"
3385adb43beSPaolo Bonzini  ;;
3395adb43beSPaolo Bonzini  --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
3405adb43beSPaolo Bonzini                    eval "cross_prefix_${cc_arch}=\$optarg"
3415adb43beSPaolo Bonzini  ;;
342ac0df51dSaliguori  esac
343ac0df51dSaliguoridone
344ac0df51dSaliguori# OS specific
345ac0df51dSaliguori# Using uname is really, really broken.  Once we have the right set of checks
34693148aa5SStefan Weil# we can eliminate its usage altogether.
347ac0df51dSaliguori
348e49d021eSPeter Maydell# Preferred compiler:
349e49d021eSPeter Maydell#  ${CC} (if set)
350e49d021eSPeter Maydell#  ${cross_prefix}gcc (if cross-prefix specified)
351e49d021eSPeter Maydell#  system compiler
352e49d021eSPeter Maydellif test -z "${CC}${cross_prefix}"; then
353e49d021eSPeter Maydell  cc="$host_cc"
354e49d021eSPeter Maydellelse
355b3198cc2SStuart Yoder  cc="${CC-${cross_prefix}gcc}"
356e49d021eSPeter Maydellfi
357e49d021eSPeter Maydell
35883f73fceSTomoki Sekiyamaif test -z "${CXX}${cross_prefix}"; then
35983f73fceSTomoki Sekiyama  cxx="c++"
36083f73fceSTomoki Sekiyamaelse
36183f73fceSTomoki Sekiyama  cxx="${CXX-${cross_prefix}g++}"
36283f73fceSTomoki Sekiyamafi
36383f73fceSTomoki Sekiyama
364b3198cc2SStuart Yoderar="${AR-${cross_prefix}ar}"
365cdbd727cSRichard Hendersonas="${AS-${cross_prefix}as}"
3665f6f0e27SRichard Hendersonccas="${CCAS-$cc}"
367b3198cc2SStuart Yoderobjcopy="${OBJCOPY-${cross_prefix}objcopy}"
368b3198cc2SStuart Yoderld="${LD-${cross_prefix}ld}"
3699f81aeb5SAlistair Francisranlib="${RANLIB-${cross_prefix}ranlib}"
3704852ee95SStefan Weilnm="${NM-${cross_prefix}nm}"
37135acbb30SPaolo Bonzinismbd="$SMBD"
372b3198cc2SStuart Yoderstrip="${STRIP-${cross_prefix}strip}"
373158bb224SKonstantin Kostiukwidl="${WIDL-${cross_prefix}widl}"
374b3198cc2SStuart Yoderwindres="${WINDRES-${cross_prefix}windres}"
37517884d7bSSergei Trofimovichpkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
37617884d7bSSergei Trofimovichquery_pkg_config() {
37717884d7bSSergei Trofimovich    "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
37817884d7bSSergei Trofimovich}
37917884d7bSSergei Trofimovichpkg_config=query_pkg_config
38047c03744SDave Airliesdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
381ac0df51dSaliguori
382be17dc90SMichael S. Tsirkin# default flags for all hosts
3832d31515bSPeter Maydell# We use -fwrapv to tell the compiler that we require a C dialect where
3842d31515bSPeter Maydell# left shift of signed integers is well defined and has the expected
3852d31515bSPeter Maydell# 2s-complement style results. (Both clang and gcc agree that it
3862d31515bSPeter Maydell# provides these semantics.)
387de38c0ccSPaolo BonziniQEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
388086d5f75SPaolo BonziniQEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
389c95e3080SKevin WolfQEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
390be17dc90SMichael S. TsirkinQEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
3915770e8afSPaolo Bonzini
392de38c0ccSPaolo BonziniQEMU_LDFLAGS=
393de38c0ccSPaolo Bonzini
3945770e8afSPaolo Bonzini# Flags that are needed during configure but later taken care of by Meson
3958a9d3d56SRichard HendersonCONFIGURE_CFLAGS="-std=gnu11 -Wall"
3965770e8afSPaolo BonziniCONFIGURE_LDFLAGS=
397086d5f75SPaolo Bonzini
398be17dc90SMichael S. Tsirkin
399ac0df51dSaliguoricheck_define() {
400ac0df51dSaliguoricat > $TMPC <<EOF
401ac0df51dSaliguori#if !defined($1)
402fd786e1aSPeter Maydell#error $1 not defined
403ac0df51dSaliguori#endif
404ac0df51dSaliguoriint main(void) { return 0; }
405ac0df51dSaliguoriEOF
40652166aa0SJuan Quintela  compile_object
407ac0df51dSaliguori}
408ac0df51dSaliguori
409307119e7SGerd Hoffmanncheck_include() {
410307119e7SGerd Hoffmanncat > $TMPC <<EOF
411307119e7SGerd Hoffmann#include <$1>
412307119e7SGerd Hoffmannint main(void) { return 0; }
413307119e7SGerd HoffmannEOF
414307119e7SGerd Hoffmann  compile_object
415307119e7SGerd Hoffmann}
416307119e7SGerd Hoffmann
41793b25869SJohn Snowwrite_c_skeleton() {
41893b25869SJohn Snow    cat > $TMPC <<EOF
41993b25869SJohn Snowint main(void) { return 0; }
42093b25869SJohn SnowEOF
42193b25869SJohn Snow}
42293b25869SJohn Snow
423bbea4050SPeter Maydellif check_define __linux__ ; then
424ba7c60c2SPaolo Bonzini  targetos=linux
425bbea4050SPeter Maydellelif check_define _WIN32 ; then
426ba7c60c2SPaolo Bonzini  targetos=windows
427bbea4050SPeter Maydellelif check_define __OpenBSD__ ; then
428ba7c60c2SPaolo Bonzini  targetos=openbsd
429bbea4050SPeter Maydellelif check_define __sun__ ; then
430ba7c60c2SPaolo Bonzini  targetos=sunos
431bbea4050SPeter Maydellelif check_define __HAIKU__ ; then
432ba7c60c2SPaolo Bonzini  targetos=haiku
433951fedfcSPeter Maydellelif check_define __FreeBSD__ ; then
434ba7c60c2SPaolo Bonzini  targetos=freebsd
435951fedfcSPeter Maydellelif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
436ba7c60c2SPaolo Bonzini  targetos=gnu/kfreebsd
437951fedfcSPeter Maydellelif check_define __DragonFly__ ; then
438ba7c60c2SPaolo Bonzini  targetos=dragonfly
439951fedfcSPeter Maydellelif check_define __NetBSD__; then
440ba7c60c2SPaolo Bonzini  targetos=netbsd
441951fedfcSPeter Maydellelif check_define __APPLE__; then
442ba7c60c2SPaolo Bonzini  targetos=darwin
443bbea4050SPeter Maydellelse
444951fedfcSPeter Maydell  # This is a fatal error, but don't report it yet, because we
445951fedfcSPeter Maydell  # might be going to just print the --help text, or it might
446951fedfcSPeter Maydell  # be the result of a missing compiler.
447ba7c60c2SPaolo Bonzini  targetos=bogus
448bbea4050SPeter Maydellfi
449bbea4050SPeter Maydell
45065eff01bSPaolo Bonzini# OS specific
45165eff01bSPaolo Bonzini
4523b0d8643SPaolo Bonzinimingw32="no"
4533b0d8643SPaolo Bonzinibsd="no"
4543b0d8643SPaolo Bonzinilinux="no"
4553b0d8643SPaolo Bonzinisolaris="no"
45665eff01bSPaolo Bonzinicase $targetos in
45765eff01bSPaolo Bonziniwindows)
45865eff01bSPaolo Bonzini  mingw32="yes"
45965eff01bSPaolo Bonzini  plugins="no"
46065eff01bSPaolo Bonzini  pie="no"
46165eff01bSPaolo Bonzini;;
46265eff01bSPaolo Bonzinignu/kfreebsd)
46365eff01bSPaolo Bonzini  bsd="yes"
46465eff01bSPaolo Bonzini;;
46565eff01bSPaolo Bonzinifreebsd)
46665eff01bSPaolo Bonzini  bsd="yes"
46765eff01bSPaolo Bonzini  make="${MAKE-gmake}"
46865eff01bSPaolo Bonzini  # needed for kinfo_getvmmap(3) in libutil.h
46965eff01bSPaolo Bonzini;;
47065eff01bSPaolo Bonzinidragonfly)
47165eff01bSPaolo Bonzini  bsd="yes"
47265eff01bSPaolo Bonzini  make="${MAKE-gmake}"
47365eff01bSPaolo Bonzini;;
47465eff01bSPaolo Bonzininetbsd)
47565eff01bSPaolo Bonzini  bsd="yes"
47665eff01bSPaolo Bonzini  make="${MAKE-gmake}"
47765eff01bSPaolo Bonzini;;
47865eff01bSPaolo Bonziniopenbsd)
47965eff01bSPaolo Bonzini  bsd="yes"
48065eff01bSPaolo Bonzini  make="${MAKE-gmake}"
48165eff01bSPaolo Bonzini;;
48265eff01bSPaolo Bonzinidarwin)
48365eff01bSPaolo Bonzini  bsd="yes"
48465eff01bSPaolo Bonzini  darwin="yes"
48565eff01bSPaolo Bonzini  # Disable attempts to use ObjectiveC features in os/object.h since they
48665eff01bSPaolo Bonzini  # won't work when we're compiling with gcc as a C compiler.
48765eff01bSPaolo Bonzini  QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
48865eff01bSPaolo Bonzini;;
48965eff01bSPaolo Bonzinisunos)
49065eff01bSPaolo Bonzini  solaris="yes"
49165eff01bSPaolo Bonzini  make="${MAKE-gmake}"
49265eff01bSPaolo Bonzini# needed for CMSG_ macros in sys/socket.h
49365eff01bSPaolo Bonzini  QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
49465eff01bSPaolo Bonzini# needed for TIOCWIN* defines in termios.h
49565eff01bSPaolo Bonzini  QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
49665eff01bSPaolo Bonzini  # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
49765eff01bSPaolo Bonzini  # Note that this check is broken for cross-compilation: if you're
498bbea4050SPeter Maydell  # cross-compiling to one of these OSes then you'll need to specify
499bbea4050SPeter Maydell  # the correct CPU with the --cpu option.
500bbea4050SPeter Maydell  if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
501bbea4050SPeter Maydell    cpu="x86_64"
502bbea4050SPeter Maydell  fi
50365eff01bSPaolo Bonzini;;
50465eff01bSPaolo Bonzinihaiku)
50565eff01bSPaolo Bonzini  pie="no"
50665eff01bSPaolo Bonzini  QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
50765eff01bSPaolo Bonzini;;
50865eff01bSPaolo Bonzinilinux)
50965eff01bSPaolo Bonzini  linux="yes"
51065eff01bSPaolo Bonzini;;
511bbea4050SPeter Maydellesac
512bbea4050SPeter Maydell
5132ff6b91eSJuan Quintelaif test ! -z "$cpu" ; then
5142ff6b91eSJuan Quintela  # command line argument
5152ff6b91eSJuan Quintela  :
5162ff6b91eSJuan Quintelaelif check_define __i386__ ; then
517ac0df51dSaliguori  cpu="i386"
518ac0df51dSaliguorielif check_define __x86_64__ ; then
519c72b26ecSRichard Henderson  if check_define __ILP32__ ; then
520c72b26ecSRichard Henderson    cpu="x32"
521c72b26ecSRichard Henderson  else
522ac0df51dSaliguori    cpu="x86_64"
523c72b26ecSRichard Henderson  fi
5243aa9bd6cSblueswir1elif check_define __sparc__ ; then
5253aa9bd6cSblueswir1  if check_define __arch64__ ; then
5263aa9bd6cSblueswir1    cpu="sparc64"
5273aa9bd6cSblueswir1  else
5283aa9bd6cSblueswir1    cpu="sparc"
5293aa9bd6cSblueswir1  fi
530fdf7ed96Smalcelif check_define _ARCH_PPC ; then
531fdf7ed96Smalc  if check_define _ARCH_PPC64 ; then
532f8378accSRichard Henderson    if check_define _LITTLE_ENDIAN ; then
533f8378accSRichard Henderson      cpu="ppc64le"
534f8378accSRichard Henderson    else
535fdf7ed96Smalc      cpu="ppc64"
536f8378accSRichard Henderson    fi
537ac0df51dSaliguori  else
538fdf7ed96Smalc    cpu="ppc"
539fdf7ed96Smalc  fi
540afa05235SAurelien Jarnoelif check_define __mips__ ; then
541afa05235SAurelien Jarno  cpu="mips"
542d66ed0eaSAurelien Jarnoelif check_define __s390__ ; then
543d66ed0eaSAurelien Jarno  if check_define __s390x__ ; then
544d66ed0eaSAurelien Jarno    cpu="s390x"
545d66ed0eaSAurelien Jarno  else
546d66ed0eaSAurelien Jarno    cpu="s390"
547d66ed0eaSAurelien Jarno  fi
548c4f80543SAlistair Franciselif check_define __riscv ; then
549ba0e7333SRichard Henderson  cpu="riscv"
55021d89f84SPeter Maydellelif check_define __arm__ ; then
55121d89f84SPeter Maydell  cpu="arm"
5521f080313SClaudio Fontanaelif check_define __aarch64__ ; then
5531f080313SClaudio Fontana  cpu="aarch64"
554dfcf900bSWANG Xueruielif check_define __loongarch64 ; then
555dfcf900bSWANG Xuerui  cpu="loongarch64"
556fdf7ed96Smalcelse
55789138857SStefan Weil  cpu=$(uname -m)
558ac0df51dSaliguorifi
559ac0df51dSaliguori
560823eb013SPaolo Bonzini# Normalise host CPU name, set multilib cflags
561359bc95dSPeter Maydell# Note that this case should only have supported host CPUs, not guests.
5627d13299dSbellardcase "$cpu" in
563e4da0e39SPaolo Bonzini  armv*b|armv*l|arm)
564e4da0e39SPaolo Bonzini    cpu="arm" ;;
565e4da0e39SPaolo Bonzini
5667d13299dSbellard  i386|i486|i586|i686|i86pc|BePC)
56797a847bcSbellard    cpu="i386"
568e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32" ;;
569e4da0e39SPaolo Bonzini  x32)
5704da270beSPaolo Bonzini    cpu="x86_64"
571e4da0e39SPaolo Bonzini    CPU_CFLAGS="-mx32" ;;
572aaa5fa14Saurel32  x86_64|amd64)
573aaa5fa14Saurel32    cpu="x86_64"
574e4da0e39SPaolo Bonzini    # ??? Only extremely old AMD cpus do not have cmpxchg16b.
575e4da0e39SPaolo Bonzini    # If we truly care, we should simply detect this case at
576e4da0e39SPaolo Bonzini    # runtime and generate the fallback to serial emulation.
577e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64 -mcx16" ;;
578e4da0e39SPaolo Bonzini
579afa05235SAurelien Jarno  mips*)
580e4da0e39SPaolo Bonzini    cpu="mips" ;;
581e4da0e39SPaolo Bonzini
582e4da0e39SPaolo Bonzini  ppc)
583e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32" ;;
584e4da0e39SPaolo Bonzini  ppc64)
585ced5cfffSMiroslav Rezanina    CPU_CFLAGS="-m64 -mbig-endian" ;;
586e4da0e39SPaolo Bonzini  ppc64le)
587d8ff892dSPaolo Bonzini    cpu="ppc64"
588ced5cfffSMiroslav Rezanina    CPU_CFLAGS="-m64 -mlittle-endian" ;;
589e4da0e39SPaolo Bonzini
590e4da0e39SPaolo Bonzini  s390)
591823eb013SPaolo Bonzini    CPU_CFLAGS="-m31" ;;
592e4da0e39SPaolo Bonzini  s390x)
593e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64" ;;
594e4da0e39SPaolo Bonzini
5953142255cSblueswir1  sparc|sun4[cdmuv])
596ae228531Sbellard    cpu="sparc"
597e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
598e4da0e39SPaolo Bonzini  sparc64)
599e4da0e39SPaolo Bonzini    CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
6007d13299dSbellardesac
601e2d52ad3SJuan Quintela
6020db4a067SPaolo Bonzini: ${make=${MAKE-make}}
603b6daf4d3SPaolo Bonzini
604faf44142SDaniel P. Berrangé# We prefer python 3.x. A bare 'python' is traditionally
605faf44142SDaniel P. Berrangé# python 2.x, but some distros have it as python 3.x, so
606ddf90699SEduardo Habkost# we check that too
607faf44142SDaniel P. Berrangépython=
6080a01d76fSMarc-André Lureauexplicit_python=no
609ddf90699SEduardo Habkostfor binary in "${PYTHON-python3}" python
610faf44142SDaniel P. Berrangédo
611faf44142SDaniel P. Berrangé    if has "$binary"
612faf44142SDaniel P. Berrangé    then
61395c5f2deSPaolo Bonzini        python=$(command -v "$binary")
614faf44142SDaniel P. Berrangé        break
615faf44142SDaniel P. Berrangé    fi
616faf44142SDaniel P. Berrangédone
617903458c8SMarkus Armbruster
618903458c8SMarkus Armbruster
61939d87c8cSAlex Bennée# Check for ancillary tools used in testing
62039d87c8cSAlex Bennéegenisoimage=
6213df437c7SAlex Bennéefor binary in genisoimage mkisofs
62239d87c8cSAlex Bennéedo
62339d87c8cSAlex Bennée    if has $binary
62439d87c8cSAlex Bennée    then
62539d87c8cSAlex Bennée        genisoimage=$(command -v "$binary")
62639d87c8cSAlex Bennée        break
62739d87c8cSAlex Bennée    fi
62839d87c8cSAlex Bennéedone
62939d87c8cSAlex Bennée
6303c4a4d0dSPeter Maydell# Default objcc to clang if available, otherwise use CC
6313c4a4d0dSPeter Maydellif has clang; then
6323c4a4d0dSPeter Maydell  objcc=clang
6333c4a4d0dSPeter Maydellelse
6343c4a4d0dSPeter Maydell  objcc="$cc"
6353c4a4d0dSPeter Maydellfi
6363c4a4d0dSPeter Maydell
6373457a3f8SJuan Quintelaif test "$mingw32" = "yes" ; then
6383457a3f8SJuan Quintela  EXESUF=".exe"
63978e9d4adSStefan Weil  # MinGW needs -mthreads for TLS and macro _MT.
6405770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
64193b25869SJohn Snow  write_c_skeleton;
642d17f305aSPaolo Bonzini  prefix="/qemu"
643c09c1ce7SPaolo Bonzini  bindir=""
64477433a5fSMarc-André Lureau  qemu_suffix=""
6453457a3f8SJuan Quintelafi
6463457a3f8SJuan Quintela
647487fefdbSAnthony Liguoriwerror=""
64885aa5189Sbellard
6498154f5e6SAkihiko Odakimeson_option_build_array() {
6508154f5e6SAkihiko Odaki  printf '['
651c5cfdabaSPeter Maydell  (if test "$targetos" = windows; then
6528154f5e6SAkihiko Odaki    IFS=\;
6538154f5e6SAkihiko Odaki  else
6548154f5e6SAkihiko Odaki    IFS=:
6558154f5e6SAkihiko Odaki  fi
6568154f5e6SAkihiko Odaki  for e in $1; do
65765842b03SPeter Maydell    printf '"""'
65865842b03SPeter Maydell    # backslash escape any '\' and '"' characters
65965842b03SPeter Maydell    printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g'
66065842b03SPeter Maydell    printf '""",'
6618154f5e6SAkihiko Odaki  done)
6628154f5e6SAkihiko Odaki  printf ']\n'
6638154f5e6SAkihiko Odaki}
6648154f5e6SAkihiko Odaki
66564708615SPeter Maydell. "$source_path/scripts/meson-buildoptions.sh"
66661d63097SPaolo Bonzini
66761d63097SPaolo Bonzinimeson_options=
668c54b59eeSPaolo Bonzinimeson_option_add() {
669c54b59eeSPaolo Bonzini  meson_options="$meson_options $(quote_sh "$1")"
670c54b59eeSPaolo Bonzini}
67161d63097SPaolo Bonzinimeson_option_parse() {
67261d63097SPaolo Bonzini  meson_options="$meson_options $(_meson_option_parse "$@")"
67361d63097SPaolo Bonzini  if test $? -eq 1; then
67461d63097SPaolo Bonzini    echo "ERROR: unknown option $1"
67561d63097SPaolo Bonzini    echo "Try '$0 --help' for more information"
67661d63097SPaolo Bonzini    exit 1
67761d63097SPaolo Bonzini  fi
67861d63097SPaolo Bonzini}
67961d63097SPaolo Bonzini
6807d13299dSbellardfor opt do
68189138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
6827d13299dSbellard  case "$opt" in
6832efc3265Sbellard  --help|-h) show_help=yes
6842efc3265Sbellard  ;;
68564708615SPeter Maydell  --version|-V) exec cat "$source_path/VERSION"
68699123e13SMike Frysinger  ;;
687b1a550a0Spbrook  --prefix=*) prefix="$optarg"
6887d13299dSbellard  ;;
689ac0df51dSaliguori  --cross-prefix=*)
6907d13299dSbellard  ;;
691ac0df51dSaliguori  --cc=*)
6927d13299dSbellard  ;;
693b1a550a0Spbrook  --host-cc=*) host_cc="$optarg"
69483469015Sbellard  ;;
69583f73fceSTomoki Sekiyama  --cxx=*)
69683f73fceSTomoki Sekiyama  ;;
6973c4a4d0dSPeter Maydell  --objcc=*) objcc="$optarg"
6983c4a4d0dSPeter Maydell  ;;
699b1a550a0Spbrook  --make=*) make="$optarg"
7007d13299dSbellard  ;;
701b6daf4d3SPaolo Bonzini  --install=*)
7026a882643Spbrook  ;;
7030a01d76fSMarc-André Lureau  --python=*) python="$optarg" ; explicit_python=yes
704c886edfbSBlue Swirl  ;;
705a5665051SPaolo Bonzini  --skip-meson) skip_meson=yes
706a5665051SPaolo Bonzini  ;;
707a5665051SPaolo Bonzini  --meson=*) meson="$optarg"
708a5665051SPaolo Bonzini  ;;
70948328880SPaolo Bonzini  --ninja=*) ninja="$optarg"
71048328880SPaolo Bonzini  ;;
711e2d8830eSBrad  --smbd=*) smbd="$optarg"
712e2d8830eSBrad  ;;
713e2a2ed06SJuan Quintela  --extra-cflags=*)
7147d13299dSbellard  ;;
71511cde1c8SBruno Dominguez  --extra-cxxflags=*)
71611cde1c8SBruno Dominguez  ;;
717e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=*)
718e910c7d9SPhilippe Mathieu-Daudé  ;;
719e2a2ed06SJuan Quintela  --extra-ldflags=*)
7207d13299dSbellard  ;;
721d75402b5SAlex Bennée  --cross-cc-*)
722d75402b5SAlex Bennée  ;;
7235adb43beSPaolo Bonzini  --cross-prefix-*)
7245adb43beSPaolo Bonzini  ;;
725c54b59eeSPaolo Bonzini  --enable-debug-info) meson_option_add -Ddebug=true
72628609749SPaolo Bonzini  ;;
727c54b59eeSPaolo Bonzini  --disable-debug-info) meson_option_add -Ddebug=false
72828609749SPaolo Bonzini  ;;
72917969268SFam Zheng  --enable-modules)
73017969268SFam Zheng      modules="yes"
73117969268SFam Zheng  ;;
7323aa88b31SStefan Hajnoczi  --disable-modules)
7333aa88b31SStefan Hajnoczi      modules="no"
7343aa88b31SStefan Hajnoczi  ;;
7352ff6b91eSJuan Quintela  --cpu=*)
7367d13299dSbellard  ;;
737b1a550a0Spbrook  --target-list=*) target_list="$optarg"
738447e133fSAlex Bennée                   if test "$target_list_exclude"; then
739447e133fSAlex Bennée                       error_exit "Can't mix --target-list with --target-list-exclude"
740447e133fSAlex Bennée                   fi
741447e133fSAlex Bennée  ;;
742447e133fSAlex Bennée  --target-list-exclude=*) target_list_exclude="$optarg"
743447e133fSAlex Bennée                   if test "$target_list"; then
744447e133fSAlex Bennée                       error_exit "Can't mix --target-list-exclude with --target-list"
745447e133fSAlex Bennée                   fi
746de83cd02Sbellard  ;;
747c54b59eeSPaolo Bonzini  --with-default-devices) meson_option_add -Ddefault_devices=true
748f3494749SPaolo Bonzini  ;;
749c54b59eeSPaolo Bonzini  --without-default-devices) meson_option_add -Ddefault_devices=false
750f3494749SPaolo Bonzini  ;;
751d1d5e9eeSAlex Bennée  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
752d1d5e9eeSAlex Bennée  ;;
753d1d5e9eeSAlex Bennée  --with-devices-*) device_arch=${opt#--with-devices-};
754d1d5e9eeSAlex Bennée                    device_arch=${device_arch%%=*}
755d1d5e9eeSAlex Bennée                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
756d1d5e9eeSAlex Bennée                    if test -f "$cf"; then
757d1d5e9eeSAlex Bennée                        device_archs="$device_archs $device_arch"
758d1d5e9eeSAlex Bennée                        eval "devices_${device_arch}=\$optarg"
759d1d5e9eeSAlex Bennée                    else
760d1d5e9eeSAlex Bennée                        error_exit "File $cf does not exist"
761d1d5e9eeSAlex Bennée                    fi
762d1d5e9eeSAlex Bennée  ;;
763c87ea116SAlex Bennée  --without-default-features) # processed above
764c87ea116SAlex Bennée  ;;
76579427693SLoïc Minier  --static)
76679427693SLoïc Minier    static="yes"
76717884d7bSSergei Trofimovich    QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
76843ce4dfeSbellard  ;;
7690b24e75fSPaolo Bonzini  --bindir=*) bindir="$optarg"
7700b24e75fSPaolo Bonzini  ;;
77177433a5fSMarc-André Lureau  --with-suffix=*) qemu_suffix="$optarg"
772023d3d67SEduardo Habkost  ;;
773181ce1d0SOlaf Hering  --host=*|--build=*|\
774181ce1d0SOlaf Hering  --disable-dependency-tracking|\
775785c23aeSLuiz Capitulino  --sbindir=*|--sharedstatedir=*|\
776fe0038beSPaolo Bonzini  --oldincludedir=*|--datarootdir=*|--infodir=*|\
777023ddd74SMax Filippov  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
778023ddd74SMax Filippov    # These switches are silently ignored, for compatibility with
779023ddd74SMax Filippov    # autoconf-generated configure scripts. This allows QEMU's
780023ddd74SMax Filippov    # configure to be used by RPM and similar macros that set
781023ddd74SMax Filippov    # lots of directory switches by default.
782023ddd74SMax Filippov  ;;
783f8393946Saurel32  --enable-debug-tcg) debug_tcg="yes"
784f8393946Saurel32  ;;
785f8393946Saurel32  --disable-debug-tcg) debug_tcg="no"
786f8393946Saurel32  ;;
787f3d08ee6SPaul Brook  --enable-debug)
788f3d08ee6SPaul Brook      # Enable debugging options that aren't excessively noisy
789f3d08ee6SPaul Brook      debug_tcg="yes"
790c55cf6abSPaolo Bonzini      meson_option_parse --enable-debug-mutex ""
791c54b59eeSPaolo Bonzini      meson_option_add -Doptimization=0
792b553a042SJohn Snow      fortify_source="no"
793f3d08ee6SPaul Brook  ;;
794247724cbSMarc-André Lureau  --enable-sanitizers) sanitizers="yes"
795247724cbSMarc-André Lureau  ;;
796247724cbSMarc-André Lureau  --disable-sanitizers) sanitizers="no"
797247724cbSMarc-André Lureau  ;;
7980aebab04SLingfeng Yang  --enable-tsan) tsan="yes"
7990aebab04SLingfeng Yang  ;;
8000aebab04SLingfeng Yang  --disable-tsan) tsan="no"
8010aebab04SLingfeng Yang  ;;
8021badb709SPaolo Bonzini  --disable-tcg) tcg="disabled"
803d1a14257SAlex Bennée                 plugins="no"
804b3f6ea7eSPaolo Bonzini  ;;
8051badb709SPaolo Bonzini  --enable-tcg) tcg="enabled"
806b3f6ea7eSPaolo Bonzini  ;;
807cad25d69Spbrook  --disable-system) softmmu="no"
8080a8e90f4Spbrook  ;;
809cad25d69Spbrook  --enable-system) softmmu="yes"
8100a8e90f4Spbrook  ;;
8110953a80fSZachary Amsden  --disable-user)
8120953a80fSZachary Amsden      linux_user="no" ;
8130953a80fSZachary Amsden      bsd_user="no" ;
8140953a80fSZachary Amsden  ;;
8150953a80fSZachary Amsden  --enable-user) ;;
816831b7825Sths  --disable-linux-user) linux_user="no"
8170a8e90f4Spbrook  ;;
818831b7825Sths  --enable-linux-user) linux_user="yes"
819831b7825Sths  ;;
82084778508Sblueswir1  --disable-bsd-user) bsd_user="no"
82184778508Sblueswir1  ;;
82284778508Sblueswir1  --enable-bsd-user) bsd_user="yes"
82384778508Sblueswir1  ;;
82440d6444eSAvi Kivity  --enable-pie) pie="yes"
82534005a00SKirill A. Shutemov  ;;
82640d6444eSAvi Kivity  --disable-pie) pie="no"
82734005a00SKirill A. Shutemov  ;;
82885aa5189Sbellard  --enable-werror) werror="yes"
82985aa5189Sbellard  ;;
83085aa5189Sbellard  --disable-werror) werror="no"
83185aa5189Sbellard  ;;
83263678e17SSteven Noonan  --enable-stack-protector) stack_protector="yes"
83363678e17SSteven Noonan  ;;
83463678e17SSteven Noonan  --disable-stack-protector) stack_protector="no"
83563678e17SSteven Noonan  ;;
8361e4f6065SDaniele Buono  --enable-safe-stack) safe_stack="yes"
8371e4f6065SDaniele Buono  ;;
8381e4f6065SDaniele Buono  --disable-safe-stack) safe_stack="no"
8391e4f6065SDaniele Buono  ;;
8409e62ba48SDaniele Buono  --enable-cfi)
8419e62ba48SDaniele Buono      cfi="true";
842c54b59eeSPaolo Bonzini      meson_option_add -Db_lto=true
8439e62ba48SDaniele Buono  ;;
8449e62ba48SDaniele Buono  --disable-cfi) cfi="false"
8459e62ba48SDaniele Buono  ;;
846fbb4121dSPaolo Bonzini  --disable-fdt) fdt="disabled"
8472df87df7SJuan Quintela  ;;
848fbb4121dSPaolo Bonzini  --enable-fdt) fdt="enabled"
849fbb4121dSPaolo Bonzini  ;;
850fbb4121dSPaolo Bonzini  --enable-fdt=git) fdt="internal"
851fbb4121dSPaolo Bonzini  ;;
85203a3c0b3SPaolo Bonzini  --enable-fdt=*) fdt="$optarg"
8532df87df7SJuan Quintela  ;;
854519175a2SAlex Barcelo  --with-coroutine=*) coroutine="$optarg"
855519175a2SAlex Barcelo  ;;
8561ffb3bbbSPaolo Bonzini  --disable-zlib-test)
8571ece9905SAlon Levy  ;;
85852b53c04SFam Zheng  --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
85952b53c04SFam Zheng      echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
860583f6e7bSStefan Hajnoczi  ;;
861cb6414dfSFam Zheng  --enable-vhdx|--disable-vhdx)
862cb6414dfSFam Zheng      echo "$0: $opt is obsolete, VHDX driver is always built" >&2
863cb6414dfSFam Zheng  ;;
864315d3184SFam Zheng  --enable-uuid|--disable-uuid)
865315d3184SFam Zheng      echo "$0: $opt is obsolete, UUID support is always built" >&2
866315d3184SFam Zheng  ;;
867cc84d63aSDaniel P. Berrange  --with-git=*) git="$optarg"
868cc84d63aSDaniel P. Berrange  ;;
8697d7dbf9dSDan Streetman  --with-git-submodules=*)
8707d7dbf9dSDan Streetman      git_submodules_action="$optarg"
871f62bbee5SDaniel P. Berrange  ;;
8729b8e4298SAlex Bennée  --enable-plugins) if test "$mingw32" = "yes"; then
8739b8e4298SAlex Bennée                        error_exit "TCG plugins not currently supported on Windows platforms"
8749b8e4298SAlex Bennée                    else
8759b8e4298SAlex Bennée                        plugins="yes"
8769b8e4298SAlex Bennée                    fi
87740e8c6f4SAlex Bennée  ;;
87840e8c6f4SAlex Bennée  --disable-plugins) plugins="no"
87940e8c6f4SAlex Bennée  ;;
880afc3a8f9SAlex Bennée  --enable-containers) use_containers="yes"
881afc3a8f9SAlex Bennée  ;;
882afc3a8f9SAlex Bennée  --disable-containers) use_containers="no"
883afc3a8f9SAlex Bennée  ;;
884f48e590aSAlex Bennée  --gdb=*) gdb_bin="$optarg"
885f48e590aSAlex Bennée  ;;
8863b4da132SPaolo Bonzini  # backwards compatibility options
8873b4da132SPaolo Bonzini  --enable-trace-backend=*) meson_option_parse "--enable-trace-backends=$optarg" "$optarg"
8883b4da132SPaolo Bonzini  ;;
8893b4da132SPaolo Bonzini  --disable-blobs) meson_option_parse --disable-install-blobs ""
8903b4da132SPaolo Bonzini  ;;
89155116968SJagannathan Raman  --enable-vfio-user-server) vfio_user_server="enabled"
89255116968SJagannathan Raman  ;;
89355116968SJagannathan Raman  --disable-vfio-user-server) vfio_user_server="disabled"
89455116968SJagannathan Raman  ;;
8953b4da132SPaolo Bonzini  --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
8963b4da132SPaolo Bonzini  ;;
8973b4da132SPaolo Bonzini  --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
8983b4da132SPaolo Bonzini  ;;
8993b4da132SPaolo Bonzini  # everything else has the same name in configure and meson
9004fda6011SPaolo Bonzini  --*) meson_option_parse "$opt" "$optarg"
9017f1559c6Sbalrog  ;;
9027d13299dSbellard  esac
9037d13299dSbellarddone
9047d13299dSbellard
905d1a14257SAlex Bennée# test for any invalid configuration combinations
906d1a14257SAlex Bennéeif test "$plugins" = "yes" -a "$tcg" = "disabled"; then
907d1a14257SAlex Bennée    error_exit "Can't enable plugins on non-TCG builds"
908d1a14257SAlex Bennéefi
909d1a14257SAlex Bennée
9107d7dbf9dSDan Streetmancase $git_submodules_action in
9117d7dbf9dSDan Streetman    update|validate)
9127d7dbf9dSDan Streetman        if test ! -e "$source_path/.git"; then
9137d7dbf9dSDan Streetman            echo "ERROR: cannot $git_submodules_action git submodules without .git"
9147d7dbf9dSDan Streetman            exit 1
9157d7dbf9dSDan Streetman        fi
9167d7dbf9dSDan Streetman    ;;
9177d7dbf9dSDan Streetman    ignore)
918b80fd281SPaolo Bonzini        if ! test -f "$source_path/ui/keycodemapdb/README"
919b80fd281SPaolo Bonzini        then
920b80fd281SPaolo Bonzini            echo
921b80fd281SPaolo Bonzini            echo "ERROR: missing GIT submodules"
922b80fd281SPaolo Bonzini            echo
923b80fd281SPaolo Bonzini            if test -e "$source_path/.git"; then
924b80fd281SPaolo Bonzini                echo "--with-git-submodules=ignore specified but submodules were not"
925b80fd281SPaolo Bonzini                echo "checked out.  Please initialize and update submodules."
926b80fd281SPaolo Bonzini            else
927b80fd281SPaolo Bonzini                echo "This is not a GIT checkout but module content appears to"
928b80fd281SPaolo Bonzini                echo "be missing. Do not use 'git archive' or GitHub download links"
929b80fd281SPaolo Bonzini                echo "to acquire QEMU source archives. Non-GIT builds are only"
930b80fd281SPaolo Bonzini                echo "supported with source archives linked from:"
931b80fd281SPaolo Bonzini                echo
932b80fd281SPaolo Bonzini                echo "  https://www.qemu.org/download/#source"
933b80fd281SPaolo Bonzini                echo
934b80fd281SPaolo Bonzini                echo "Developers working with GIT can use scripts/archive-source.sh"
935b80fd281SPaolo Bonzini                echo "if they need to create valid source archives."
936b80fd281SPaolo Bonzini            fi
937b80fd281SPaolo Bonzini            echo
938b80fd281SPaolo Bonzini            exit 1
939b80fd281SPaolo Bonzini        fi
9407d7dbf9dSDan Streetman    ;;
9417d7dbf9dSDan Streetman    *)
9427d7dbf9dSDan Streetman        echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
9437d7dbf9dSDan Streetman        exit 1
9447d7dbf9dSDan Streetman    ;;
9457d7dbf9dSDan Streetmanesac
9467d7dbf9dSDan Streetman
94760e0df25SPeter Maydelldefault_target_list=""
9486e92f823SPeter Maydellmak_wilds=""
9496e92f823SPeter Maydell
950b915a2f1SPaolo Bonziniif [ "$linux_user" != no ]; then
95164708615SPeter Maydell    if [ "$targetos" = linux ] && [ -d "$source_path/linux-user/include/host/$cpu" ]; then
952b915a2f1SPaolo Bonzini        linux_user=yes
953b915a2f1SPaolo Bonzini    elif [ "$linux_user" = yes ]; then
954b915a2f1SPaolo Bonzini        error_exit "linux-user not supported on this architecture"
955b915a2f1SPaolo Bonzini    fi
956b915a2f1SPaolo Bonzinifi
957b915a2f1SPaolo Bonziniif [ "$bsd_user" != no ]; then
958b915a2f1SPaolo Bonzini    if [ "$bsd_user" = "" ]; then
959b915a2f1SPaolo Bonzini        test $targetos = freebsd && bsd_user=yes
960b915a2f1SPaolo Bonzini    fi
96164708615SPeter Maydell    if [ "$bsd_user" = yes ] && ! [ -d "$source_path/bsd-user/$targetos" ]; then
962b915a2f1SPaolo Bonzini        error_exit "bsd-user not supported on this host OS"
963b915a2f1SPaolo Bonzini    fi
964b915a2f1SPaolo Bonzinifi
96560e0df25SPeter Maydellif [ "$softmmu" = "yes" ]; then
966812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
96760e0df25SPeter Maydellfi
96860e0df25SPeter Maydellif [ "$linux_user" = "yes" ]; then
969812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
97060e0df25SPeter Maydellfi
97160e0df25SPeter Maydellif [ "$bsd_user" = "yes" ]; then
972812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
97360e0df25SPeter Maydellfi
97460e0df25SPeter Maydell
975447e133fSAlex Bennéefor config in $mak_wilds; do
976447e133fSAlex Bennée    target="$(basename "$config" .mak)"
97798db9a06SAlex Bennée    if echo "$target_list_exclude" | grep -vq "$target"; then
978447e133fSAlex Bennée        default_target_list="${default_target_list} $target"
979447e133fSAlex Bennée    fi
980447e133fSAlex Bennéedone
9816e92f823SPeter Maydell
982af5db58eSpbrookif test x"$show_help" = x"yes" ; then
983af5db58eSpbrookcat << EOF
984af5db58eSpbrook
985af5db58eSpbrookUsage: configure [options]
986af5db58eSpbrookOptions: [defaults in brackets after descriptions]
987af5db58eSpbrook
98808fb77edSStefan WeilStandard options:
98908fb77edSStefan Weil  --help                   print this message
99008fb77edSStefan Weil  --prefix=PREFIX          install in PREFIX [$prefix]
99174154d7eSThomas Huth  --target-list=LIST       set target list (default: build all)
99208fb77edSStefan Weil$(echo Available targets: $default_target_list | \
99308fb77edSStefan Weil  fold -s -w 53 | sed -e 's/^/                           /')
994447e133fSAlex Bennée  --target-list-exclude=LIST exclude a set of targets from the default target-list
99508fb77edSStefan Weil
99608fb77edSStefan WeilAdvanced options (experts only):
9973812c0c4SJoelle van Dyne  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
99808fb77edSStefan Weil  --cc=CC                  use C compiler CC [$cc]
99908fb77edSStefan Weil  --host-cc=CC             use C compiler CC [$host_cc] for code run at
100008fb77edSStefan Weil                           build time
100108fb77edSStefan Weil  --cxx=CXX                use C++ compiler CXX [$cxx]
100208fb77edSStefan Weil  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
1003a2866660SPaolo Bonzini  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
1004a2866660SPaolo Bonzini  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
1005e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
100608fb77edSStefan Weil  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
1007d75402b5SAlex Bennée  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
1008479ca4ccSMatheus Ferst  --cross-cc-cflags-ARCH=  use compiler flags when building ARCH guest tests
10095adb43beSPaolo Bonzini  --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
101008fb77edSStefan Weil  --make=MAKE              use specified make [$make]
101108fb77edSStefan Weil  --python=PYTHON          use specified python [$python]
1012a5665051SPaolo Bonzini  --meson=MESON            use specified meson [$meson]
101348328880SPaolo Bonzini  --ninja=NINJA            use specified ninja [$ninja]
101408fb77edSStefan Weil  --smbd=SMBD              use specified smbd [$smbd]
1015db1b5f13SThomas Huth  --with-git=GIT           use specified git [$git]
10167d7dbf9dSDan Streetman  --with-git-submodules=update   update git submodules (default if .git dir exists)
10177d7dbf9dSDan Streetman  --with-git-submodules=validate fail if git submodules are not up to date
10187d7dbf9dSDan Streetman  --with-git-submodules=ignore   do not update or check git submodules (default if no .git dir)
101908fb77edSStefan Weil  --static                 enable static build [$static]
102008fb77edSStefan Weil  --bindir=PATH            install binaries in PATH
1021ca8c0909SMarc-André Lureau  --with-suffix=SUFFIX     suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
1022c035c8d6SPaolo Bonzini  --without-default-features default all --enable-* options to "disabled"
1023c035c8d6SPaolo Bonzini  --without-default-devices  do not include any device that is not needed to
1024c035c8d6SPaolo Bonzini                           start the emulator (only use if you are including
1025d1d5e9eeSAlex Bennée                           desired devices in configs/devices/)
1026d1d5e9eeSAlex Bennée  --with-devices-ARCH=NAME override default configs/devices
102708fb77edSStefan Weil  --enable-debug           enable common debug build options
1028247724cbSMarc-André Lureau  --enable-sanitizers      enable default sanitizers
10290aebab04SLingfeng Yang  --enable-tsan            enable thread sanitizer
103008fb77edSStefan Weil  --disable-werror         disable compilation abort on warning
103163678e17SSteven Noonan  --disable-stack-protector disable compiler-provided stack protection
1032c23f23b9SMichael Tokarev  --cpu=CPU                Build for host CPU [$cpu]
103308fb77edSStefan Weil  --with-coroutine=BACKEND coroutine backend. Supported options:
103433c53c54SDaniel P. Berrange                           ucontext, sigaltstack, windows
103540e8c6f4SAlex Bennée  --enable-plugins
103640e8c6f4SAlex Bennée                           enable plugins via shared library loading
1037afc3a8f9SAlex Bennée  --disable-containers     don't use containers for cross-building
1038f48e590aSAlex Bennée  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
103961d63097SPaolo BonziniEOF
104061d63097SPaolo Bonzini  meson_options_help
104161d63097SPaolo Bonzinicat << EOF
1042c23f23b9SMichael Tokarev  system          all system emulation targets
1043c23f23b9SMichael Tokarev  user            supported user emulation targets
1044c23f23b9SMichael Tokarev  linux-user      all linux usermode emulation targets
1045c23f23b9SMichael Tokarev  bsd-user        all BSD usermode emulation targets
1046c23f23b9SMichael Tokarev  pie             Position Independent Executables
104721e709aaSMarc-André Lureau  modules         modules support (non-Windows)
1048c23f23b9SMichael Tokarev  debug-tcg       TCG debugging (default is disabled)
1049c23f23b9SMichael Tokarev  debug-info      debugging information
10501e4f6065SDaniele Buono  safe-stack      SafeStack Stack Smash Protection. Depends on
10511e4f6065SDaniele Buono                  clang/llvm >= 3.7 and requires coroutine backend ucontext.
105208fb77edSStefan Weil
105308fb77edSStefan WeilNOTE: The object files are built at the place where configure is launched
1054af5db58eSpbrookEOF
10552d2ad6d0SFam Zhengexit 0
1056af5db58eSpbrookfi
1057af5db58eSpbrook
10589c790242SThomas Huth# Remove old dependency files to make sure that they get properly regenerated
1059002d8c13SPeter Maydellrm -f ./*/config-devices.mak.d
10609c790242SThomas Huth
1061faf44142SDaniel P. Berrangéif test -z "$python"
1062faf44142SDaniel P. Berrangéthen
1063c53eeaf7SStefan Hajnoczi    error_exit "Python not found. Use --python=/path/to/python"
1064c53eeaf7SStefan Hajnoczifi
10658e2c76bdSRoman Bolshakovif ! has "$make"
10668e2c76bdSRoman Bolshakovthen
10678e2c76bdSRoman Bolshakov    error_exit "GNU make ($make) not found"
10688e2c76bdSRoman Bolshakovfi
1069c53eeaf7SStefan Hajnoczi
1070c53eeaf7SStefan Hajnoczi# Note that if the Python conditional here evaluates True we will exit
1071c53eeaf7SStefan Hajnoczi# with status 1 which is a shell 'false' value.
10721b11f28dSThomas Huthif ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then
10731b11f28dSThomas Huth  error_exit "Cannot use '$python', Python >= 3.6 is required." \
1074c53eeaf7SStefan Hajnoczi      "Use --python=/path/to/python to specify a supported Python."
1075c53eeaf7SStefan Hajnoczifi
1076c53eeaf7SStefan Hajnoczi
1077c53eeaf7SStefan Hajnoczi# Suppress writing compiled files
1078c53eeaf7SStefan Hajnoczipython="$python -B"
1079c53eeaf7SStefan Hajnoczi
10800a01d76fSMarc-André Lureauif test -z "$meson"; then
10818a29c205SPaolo Bonzini    if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.61.5; then
10820a01d76fSMarc-André Lureau        meson=meson
108364708615SPeter Maydell    elif test "$git_submodules_action" != 'ignore' ; then
10840a01d76fSMarc-André Lureau        meson=git
10850a01d76fSMarc-André Lureau    elif test -e "${source_path}/meson/meson.py" ; then
10860a01d76fSMarc-André Lureau        meson=internal
10870a01d76fSMarc-André Lureau    else
10880a01d76fSMarc-André Lureau        if test "$explicit_python" = yes; then
10890a01d76fSMarc-André Lureau            error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
10900a01d76fSMarc-André Lureau        else
1091a5665051SPaolo Bonzini            error_exit "Meson not found.  Use --meson=/path/to/meson"
1092a5665051SPaolo Bonzini        fi
10930a01d76fSMarc-André Lureau    fi
10940a01d76fSMarc-André Lureauelse
10950a01d76fSMarc-André Lureau    # Meson uses its own Python interpreter to invoke other Python scripts,
10960a01d76fSMarc-André Lureau    # but the user wants to use the one they specified with --python.
10970a01d76fSMarc-André Lureau    #
10980a01d76fSMarc-André Lureau    # We do not want to override the distro Python interpreter (and sometimes
10990a01d76fSMarc-André Lureau    # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
11000a01d76fSMarc-André Lureau    # just require --meson=git|internal together with --python.
11010a01d76fSMarc-André Lureau    if test "$explicit_python" = yes; then
11020a01d76fSMarc-André Lureau        case "$meson" in
11030a01d76fSMarc-André Lureau            git | internal) ;;
11040a01d76fSMarc-André Lureau            *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
11050a01d76fSMarc-André Lureau        esac
11060a01d76fSMarc-André Lureau    fi
11070a01d76fSMarc-André Lureaufi
1108a5665051SPaolo Bonzini
11090a01d76fSMarc-André Lureauif test "$meson" = git; then
11100a01d76fSMarc-André Lureau    git_submodules="${git_submodules} meson"
11110a01d76fSMarc-André Lureaufi
11120a01d76fSMarc-André Lureau
11130a01d76fSMarc-André Lureaucase "$meson" in
11140a01d76fSMarc-André Lureau    git | internal)
11150a01d76fSMarc-André Lureau        meson="$python ${source_path}/meson/meson.py"
11160a01d76fSMarc-André Lureau        ;;
111784ec0c24SPaolo Bonzini    *) meson=$(command -v "$meson") ;;
11180a01d76fSMarc-André Lureauesac
11190a01d76fSMarc-André Lureau
112009e93326SPaolo Bonzini# Probe for ninja
112148328880SPaolo Bonzini
112248328880SPaolo Bonziniif test -z "$ninja"; then
112348328880SPaolo Bonzini    for c in ninja ninja-build samu; do
112448328880SPaolo Bonzini        if has $c; then
112548328880SPaolo Bonzini            ninja=$(command -v "$c")
112648328880SPaolo Bonzini            break
112748328880SPaolo Bonzini        fi
112848328880SPaolo Bonzini    done
112909e93326SPaolo Bonzini    if test -z "$ninja"; then
113009e93326SPaolo Bonzini      error_exit "Cannot find Ninja"
113109e93326SPaolo Bonzini    fi
113248328880SPaolo Bonzinifi
1133a5665051SPaolo Bonzini
11349aae6e54SDaniel Henrique Barboza# Check that the C compiler works. Doing this here before testing
11359aae6e54SDaniel Henrique Barboza# the host CPU ensures that we had a valid CC to autodetect the
11369aae6e54SDaniel Henrique Barboza# $cpu var (and we should bail right here if that's not the case).
11379aae6e54SDaniel Henrique Barboza# It also allows the help message to be printed without a CC.
11389aae6e54SDaniel Henrique Barbozawrite_c_skeleton;
11399aae6e54SDaniel Henrique Barbozaif compile_object ; then
11409aae6e54SDaniel Henrique Barboza  : C compiler works ok
11419aae6e54SDaniel Henrique Barbozaelse
11429aae6e54SDaniel Henrique Barboza    error_exit "\"$cc\" either does not exist or does not work"
11439aae6e54SDaniel Henrique Barbozafi
11449aae6e54SDaniel Henrique Barbozaif ! compile_prog ; then
11459aae6e54SDaniel Henrique Barboza    error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
11469aae6e54SDaniel Henrique Barbozafi
11479aae6e54SDaniel Henrique Barboza
11489c83ffd8SPeter Maydell# Consult white-list to determine whether to enable werror
11499c83ffd8SPeter Maydell# by default.  Only enable by default for git builds
11509c83ffd8SPeter Maydellif test -z "$werror" ; then
11517d7dbf9dSDan Streetman    if test "$git_submodules_action" != "ignore" && \
1152e633a5c6SEric Blake        { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
11539c83ffd8SPeter Maydell        werror="yes"
11549c83ffd8SPeter Maydell    else
11559c83ffd8SPeter Maydell        werror="no"
11569c83ffd8SPeter Maydell    fi
11579c83ffd8SPeter Maydellfi
11589c83ffd8SPeter Maydell
1159975ff037SPaolo Bonziniif test "$targetos" = "bogus"; then
1160fb59dabdSPeter Maydell    # Now that we know that we're not printing the help and that
1161fb59dabdSPeter Maydell    # the compiler works (so the results of the check_defines we used
1162fb59dabdSPeter Maydell    # to identify the OS are reliable), if we didn't recognize the
1163fb59dabdSPeter Maydell    # host OS we should stop now.
1164951fedfcSPeter Maydell    error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1165fb59dabdSPeter Maydellfi
1166fb59dabdSPeter Maydell
1167efc6c070SThomas Huth# Check whether the compiler matches our minimum requirements:
1168efc6c070SThomas Huthcat > $TMPC << EOF
1169efc6c070SThomas Huth#if defined(__clang_major__) && defined(__clang_minor__)
1170efc6c070SThomas Huth# ifdef __apple_build_version__
11712a85a08cSDaniel P. Berrangé#  if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
11722a85a08cSDaniel P. Berrangé#   error You need at least XCode Clang v10.0 to compile QEMU
1173efc6c070SThomas Huth#  endif
1174efc6c070SThomas Huth# else
11752a85a08cSDaniel P. Berrangé#  if __clang_major__ < 6 || (__clang_major__ == 6 && __clang_minor__ < 0)
11762a85a08cSDaniel P. Berrangé#   error You need at least Clang v6.0 to compile QEMU
1177efc6c070SThomas Huth#  endif
1178efc6c070SThomas Huth# endif
1179efc6c070SThomas Huth#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
11803830df5fSnia# if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
11813830df5fSnia#  error You need at least GCC v7.4.0 to compile QEMU
1182efc6c070SThomas Huth# endif
1183efc6c070SThomas Huth#else
1184efc6c070SThomas Huth# error You either need GCC or Clang to compiler QEMU
1185efc6c070SThomas Huth#endif
1186efc6c070SThomas Huthint main (void) { return 0; }
1187efc6c070SThomas HuthEOF
1188efc6c070SThomas Huthif ! compile_prog "" "" ; then
11893830df5fSnia    error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
1190efc6c070SThomas Huthfi
1191efc6c070SThomas Huth
119200849b92SRichard Henderson# Accumulate -Wfoo and -Wno-bar separately.
119300849b92SRichard Henderson# We will list all of the enable flags first, and the disable flags second.
119400849b92SRichard Henderson# Note that we do not add -Werror, because that would enable it for all
119500849b92SRichard Henderson# configure tests. If a configure test failed due to -Werror this would
119600849b92SRichard Henderson# just silently disable some features, so it's too error prone.
119700849b92SRichard Henderson
119800849b92SRichard Hendersonwarn_flags=
119900849b92SRichard Hendersonadd_to warn_flags -Wold-style-declaration
120000849b92SRichard Hendersonadd_to warn_flags -Wold-style-definition
120100849b92SRichard Hendersonadd_to warn_flags -Wtype-limits
120200849b92SRichard Hendersonadd_to warn_flags -Wformat-security
120300849b92SRichard Hendersonadd_to warn_flags -Wformat-y2k
120400849b92SRichard Hendersonadd_to warn_flags -Winit-self
120500849b92SRichard Hendersonadd_to warn_flags -Wignored-qualifiers
120600849b92SRichard Hendersonadd_to warn_flags -Wempty-body
120700849b92SRichard Hendersonadd_to warn_flags -Wnested-externs
120800849b92SRichard Hendersonadd_to warn_flags -Wendif-labels
120900849b92SRichard Hendersonadd_to warn_flags -Wexpansion-to-defined
12100a2ebce9SThomas Huthadd_to warn_flags -Wimplicit-fallthrough=2
121100849b92SRichard Henderson
121200849b92SRichard Hendersonnowarn_flags=
121300849b92SRichard Hendersonadd_to nowarn_flags -Wno-initializer-overrides
121400849b92SRichard Hendersonadd_to nowarn_flags -Wno-missing-include-dirs
121500849b92SRichard Hendersonadd_to nowarn_flags -Wno-shift-negative-value
121600849b92SRichard Hendersonadd_to nowarn_flags -Wno-string-plus-int
121700849b92SRichard Hendersonadd_to nowarn_flags -Wno-typedef-redefinition
1218aabab967SRichard Hendersonadd_to nowarn_flags -Wno-tautological-type-limit-compare
1219bac8d222SRichard Hendersonadd_to nowarn_flags -Wno-psabi
122028d01b1dSChenyi Qiangadd_to nowarn_flags -Wno-gnu-variable-sized-type-not-at-end
122100849b92SRichard Henderson
122200849b92SRichard Hendersongcc_flags="$warn_flags $nowarn_flags"
122393b25869SJohn Snow
122493b25869SJohn Snowcc_has_warning_flag() {
122593b25869SJohn Snow    write_c_skeleton;
122693b25869SJohn Snow
1227a1d29d6cSPeter Maydell    # Use the positive sense of the flag when testing for -Wno-wombat
1228a1d29d6cSPeter Maydell    # support (gcc will happily accept the -Wno- form of unknown
1229a1d29d6cSPeter Maydell    # warning options).
123093b25869SJohn Snow    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
123193b25869SJohn Snow    compile_prog "-Werror $optflag" ""
123293b25869SJohn Snow}
123393b25869SJohn Snow
12344cb37d11SPhilippe Mathieu-Daudéobjcc_has_warning_flag() {
12354cb37d11SPhilippe Mathieu-Daudé    cat > $TMPM <<EOF
12364cb37d11SPhilippe Mathieu-Daudéint main(void) { return 0; }
12374cb37d11SPhilippe Mathieu-DaudéEOF
12384cb37d11SPhilippe Mathieu-Daudé
12394cb37d11SPhilippe Mathieu-Daudé    # Use the positive sense of the flag when testing for -Wno-wombat
12404cb37d11SPhilippe Mathieu-Daudé    # support (gcc will happily accept the -Wno- form of unknown
12414cb37d11SPhilippe Mathieu-Daudé    # warning options).
12424cb37d11SPhilippe Mathieu-Daudé    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
12434cb37d11SPhilippe Mathieu-Daudé    do_objc -Werror $optflag \
12444cb37d11SPhilippe Mathieu-Daudé      $OBJCFLAGS $EXTRA_OBJCFLAGS $CONFIGURE_OBJCFLAGS $QEMU_OBJCFLAGS \
12454cb37d11SPhilippe Mathieu-Daudé      -o $TMPE $TMPM $QEMU_LDFLAGS
12464cb37d11SPhilippe Mathieu-Daudé}
12474cb37d11SPhilippe Mathieu-Daudé
124893b25869SJohn Snowfor flag in $gcc_flags; do
124993b25869SJohn Snow    if cc_has_warning_flag $flag ; then
12508d05095cSPaolo Bonzini        QEMU_CFLAGS="$QEMU_CFLAGS $flag"
12518d05095cSPaolo Bonzini    fi
12524cb37d11SPhilippe Mathieu-Daudé    if objcc_has_warning_flag $flag ; then
12534cb37d11SPhilippe Mathieu-Daudé        QEMU_OBJCFLAGS="$QEMU_OBJCFLAGS $flag"
12544cb37d11SPhilippe Mathieu-Daudé    fi
12558d05095cSPaolo Bonzinidone
12568d05095cSPaolo Bonzini
125763678e17SSteven Noonanif test "$stack_protector" != "no"; then
1258fccd35a0SRodrigo Rebello  cat > $TMPC << EOF
1259fccd35a0SRodrigo Rebelloint main(int argc, char *argv[])
1260fccd35a0SRodrigo Rebello{
1261fccd35a0SRodrigo Rebello    char arr[64], *p = arr, *c = argv[0];
1262fccd35a0SRodrigo Rebello    while (*c) {
1263fccd35a0SRodrigo Rebello        *p++ = *c++;
1264fccd35a0SRodrigo Rebello    }
1265fccd35a0SRodrigo Rebello    return 0;
1266fccd35a0SRodrigo Rebello}
1267fccd35a0SRodrigo RebelloEOF
126863678e17SSteven Noonan  gcc_flags="-fstack-protector-strong -fstack-protector-all"
12693b463a3fSMiroslav Rezanina  sp_on=0
127063678e17SSteven Noonan  for flag in $gcc_flags; do
1271590e5dd9SPeter Maydell    # We need to check both a compile and a link, since some compiler
1272590e5dd9SPeter Maydell    # setups fail only on a .c->.o compile and some only at link time
1273086d5f75SPaolo Bonzini    if compile_object "-Werror $flag" &&
1274590e5dd9SPeter Maydell       compile_prog "-Werror $flag" ""; then
127563678e17SSteven Noonan      QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1276db5adeaaSPaolo Bonzini      QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
12773b463a3fSMiroslav Rezanina      sp_on=1
127863678e17SSteven Noonan      break
127963678e17SSteven Noonan    fi
128063678e17SSteven Noonan  done
12813b463a3fSMiroslav Rezanina  if test "$stack_protector" = yes; then
12823b463a3fSMiroslav Rezanina    if test $sp_on = 0; then
12833b463a3fSMiroslav Rezanina      error_exit "Stack protector not supported"
12843b463a3fSMiroslav Rezanina    fi
12853b463a3fSMiroslav Rezanina  fi
128637746c5eSMarc-André Lureaufi
128737746c5eSMarc-André Lureau
128820bc94a2SPaolo Bonzini# Disable -Wmissing-braces on older compilers that warn even for
128920bc94a2SPaolo Bonzini# the "universal" C zero initializer {0}.
129020bc94a2SPaolo Bonzinicat > $TMPC << EOF
129120bc94a2SPaolo Bonzinistruct {
129220bc94a2SPaolo Bonzini  int a[2];
129320bc94a2SPaolo Bonzini} x = {0};
129420bc94a2SPaolo BonziniEOF
129520bc94a2SPaolo Bonziniif compile_object "-Werror" "" ; then
129620bc94a2SPaolo Bonzini  :
129720bc94a2SPaolo Bonzinielse
129820bc94a2SPaolo Bonzini  QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
129920bc94a2SPaolo Bonzinifi
130020bc94a2SPaolo Bonzini
130121e709aaSMarc-André Lureau# Our module code doesn't support Windows
130221e709aaSMarc-André Lureauif test "$modules" = "yes" && test "$mingw32" = "yes" ; then
130321e709aaSMarc-André Lureau  error_exit "Modules are not available for Windows"
130421e709aaSMarc-André Lureaufi
130521e709aaSMarc-André Lureau
13065f2453acSAlex Bennée# Static linking is not possible with plugins, modules or PIE
130740d6444eSAvi Kivityif test "$static" = "yes" ; then
1308aa0d1f44SPaolo Bonzini  if test "$modules" = "yes" ; then
1309aa0d1f44SPaolo Bonzini    error_exit "static and modules are mutually incompatible"
1310aa0d1f44SPaolo Bonzini  fi
13115f2453acSAlex Bennée  if test "$plugins" = "yes"; then
13125f2453acSAlex Bennée    error_exit "static and plugins are mutually incompatible"
1313ba4dd2aaSAlex Bennée  else
1314ba4dd2aaSAlex Bennée    plugins="no"
13155f2453acSAlex Bennée  fi
131640d6444eSAvi Kivityfi
131737650689SPaolo Bonzinitest "$plugins" = "" && plugins=yes
131840d6444eSAvi Kivity
131940d6444eSAvi Kivitycat > $TMPC << EOF
132021d4a791SAvi Kivity
132121d4a791SAvi Kivity#ifdef __linux__
132221d4a791SAvi Kivity#  define THREAD __thread
132321d4a791SAvi Kivity#else
132421d4a791SAvi Kivity#  define THREAD
132521d4a791SAvi Kivity#endif
132621d4a791SAvi Kivitystatic THREAD int tls_var;
132721d4a791SAvi Kivityint main(void) { return tls_var; }
132840d6444eSAvi KivityEOF
1329b2634124SRichard Henderson
133012781462SRichard Hendersonif test "$static" = "yes"; then
1331eca7a8e6SRichard Henderson  if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
13325770e8afSPaolo Bonzini    CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
133312781462SRichard Henderson    pie="yes"
133412781462SRichard Henderson  elif test "$pie" = "yes"; then
133512781462SRichard Henderson    error_exit "-static-pie not available due to missing toolchain support"
133612781462SRichard Henderson  else
133712781462SRichard Henderson    pie="no"
133812781462SRichard Henderson  fi
133912781462SRichard Hendersonelif test "$pie" = "no"; then
1340b9eae9efSPaolo Bonzini  if compile_prog "-Werror -fno-pie" "-no-pie"; then
1341b9eae9efSPaolo Bonzini    CONFIGURE_CFLAGS="-fno-pie $CONFIGURE_CFLAGS"
1342b9eae9efSPaolo Bonzini    CONFIGURE_LDFLAGS="-no-pie $CONFIGURE_LDFLAGS"
1343abafb64bSAlex Bennée    # Meson currently only handles pie as a boolean for now so if we have
1344abafb64bSAlex Bennée    # explicitly disabled PIE we need to extend our cflags because it wont.
1345abafb64bSAlex Bennée    QEMU_CFLAGS="-fno-pie -no-pie $QEMU_CFLAGS"
1346b9eae9efSPaolo Bonzini  fi
1347eca7a8e6SRichard Hendersonelif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
13485770e8afSPaolo Bonzini  CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
13495770e8afSPaolo Bonzini  CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
135040d6444eSAvi Kivity  pie="yes"
13512c674109SRichard Hendersonelif test "$pie" = "yes"; then
135276ad07a4SPeter Maydell  error_exit "PIE not available due to missing toolchain support"
135340d6444eSAvi Kivityelse
135440d6444eSAvi Kivity  echo "Disabling PIE due to missing toolchain support"
135540d6444eSAvi Kivity  pie="no"
135640d6444eSAvi Kivityfi
135740d6444eSAvi Kivity
135809dada40SPaolo Bonzini##########################################
135909dada40SPaolo Bonzini# __sync_fetch_and_and requires at least -march=i486. Many toolchains
136009dada40SPaolo Bonzini# use i686 as default anyway, but for those that don't, an explicit
136109dada40SPaolo Bonzini# specification is necessary
136209dada40SPaolo Bonzini
136309dada40SPaolo Bonziniif test "$cpu" = "i386"; then
136409dada40SPaolo Bonzini  cat > $TMPC << EOF
136509dada40SPaolo Bonzinistatic int sfaa(int *ptr)
136609dada40SPaolo Bonzini{
136709dada40SPaolo Bonzini  return __sync_fetch_and_and(ptr, 0);
136809dada40SPaolo Bonzini}
136909dada40SPaolo Bonzini
137009dada40SPaolo Bonziniint main(void)
137109dada40SPaolo Bonzini{
137209dada40SPaolo Bonzini  int val = 42;
13731405b629SStefan Weil  val = __sync_val_compare_and_swap(&val, 0, 1);
137409dada40SPaolo Bonzini  sfaa(&val);
137509dada40SPaolo Bonzini  return val;
137609dada40SPaolo Bonzini}
137709dada40SPaolo BonziniEOF
137809dada40SPaolo Bonzini  if ! compile_prog "" "" ; then
137909dada40SPaolo Bonzini    QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
138009dada40SPaolo Bonzini  fi
138109dada40SPaolo Bonzinifi
138209dada40SPaolo Bonzini
1383afb63ebdSStefan Weilif test -z "${target_list+xxx}" ; then
1384fdb75aefSPaolo Bonzini    default_targets=yes
1385d880a3baSPaolo Bonzini    for target in $default_target_list; do
1386d880a3baSPaolo Bonzini        target_list="$target_list $target"
1387d880a3baSPaolo Bonzini    done
1388d880a3baSPaolo Bonzini    target_list="${target_list# }"
1389121afa9eSAnthony Liguorielse
1390fdb75aefSPaolo Bonzini    default_targets=no
139189138857SStefan Weil    target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1392d880a3baSPaolo Bonzini    for target in $target_list; do
139325b48338SPeter Maydell        # Check that we recognised the target name; this allows a more
139425b48338SPeter Maydell        # friendly error message than if we let it fall through.
139525b48338SPeter Maydell        case " $default_target_list " in
139625b48338SPeter Maydell            *" $target "*)
139725b48338SPeter Maydell                ;;
139825b48338SPeter Maydell            *)
139925b48338SPeter Maydell                error_exit "Unknown target name '$target'"
140025b48338SPeter Maydell                ;;
140125b48338SPeter Maydell        esac
140225b48338SPeter Maydell    done
1403d880a3baSPaolo Bonzinifi
140425b48338SPeter Maydell
1405f55fe278SPaolo Bonzini# see if system emulation was really requested
1406f55fe278SPaolo Bonzinicase " $target_list " in
1407f55fe278SPaolo Bonzini  *"-softmmu "*) softmmu=yes
1408f55fe278SPaolo Bonzini  ;;
1409f55fe278SPaolo Bonzini  *) softmmu=no
1410f55fe278SPaolo Bonzini  ;;
1411f55fe278SPaolo Bonziniesac
14125327cf48Sbellard
14137630156dSPhilippe Mathieu-Daudéif test "$tcg" = "auto"; then
14147630156dSPhilippe Mathieu-Daudé  if test -z "$target_list"; then
14157630156dSPhilippe Mathieu-Daudé    tcg="disabled"
14167630156dSPhilippe Mathieu-Daudé  else
14177630156dSPhilippe Mathieu-Daudé    tcg="enabled"
14187630156dSPhilippe Mathieu-Daudé  fi
14197630156dSPhilippe Mathieu-Daudéfi
14207630156dSPhilippe Mathieu-Daudé
14217630156dSPhilippe Mathieu-Daudéif test "$tcg" = "enabled"; then
14227630156dSPhilippe Mathieu-Daudé    git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
14237630156dSPhilippe Mathieu-Daudé    git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
14247630156dSPhilippe Mathieu-Daudéfi
14257630156dSPhilippe Mathieu-Daudé
14267d13299dSbellard# ---
14277d13299dSbellard# big/little endian test
14287d13299dSbellardcat > $TMPC << EOF
1429659eb157SThomas Huth#include <stdio.h>
143061cc919fSMike Frysingershort big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
143161cc919fSMike Frysingershort little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
1432659eb157SThomas Huthint main(int argc, char *argv[])
1433659eb157SThomas Huth{
1434659eb157SThomas Huth    return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
14357d13299dSbellard}
14367d13299dSbellardEOF
14377d13299dSbellard
1438659eb157SThomas Huthif compile_prog ; then
1439659eb157SThomas Huth    if strings -a $TMPE | grep -q BiGeNdIaN ; then
144061cc919fSMike Frysinger        bigendian="yes"
1441659eb157SThomas Huth    elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
144261cc919fSMike Frysinger        bigendian="no"
14437d13299dSbellard    else
14447d13299dSbellard        echo big/little test failed
1445659eb157SThomas Huth        exit 1
14467d13299dSbellard    fi
14477d13299dSbellardelse
144861cc919fSMike Frysinger    echo big/little test failed
1449659eb157SThomas Huth    exit 1
14507d13299dSbellardfi
14517d13299dSbellard
1452015a33bdSGonglei##########################################
1453779ab5e3SStefan Weil# pkg-config probe
1454779ab5e3SStefan Weil
1455779ab5e3SStefan Weilif ! has "$pkg_config_exe"; then
145676ad07a4SPeter Maydell  error_exit "pkg-config binary '$pkg_config_exe' not found"
1457779ab5e3SStefan Weilfi
1458779ab5e3SStefan Weil
1459779ab5e3SStefan Weil##########################################
1460e18df141SAnthony Liguori# glib support probe
1461a52d28afSPaolo Bonzini
14620ce9b08cSThomas Huth# When bumping glib_req_ver, please check also whether we should increase
14630ce9b08cSThomas Huth# the _WIN32_WINNT setting in osdep.h according to the value from glib
1464b4c6036fSDaniel P. Berrangéglib_req_ver=2.56
1465aa0d1f44SPaolo Bonziniglib_modules=gthread-2.0
1466aa0d1f44SPaolo Bonziniif test "$modules" = yes; then
1467a88afc64SGerd Hoffmann    glib_modules="$glib_modules gmodule-export-2.0"
1468b906acacSPaolo Bonzinielif test "$plugins" = "yes"; then
1469b906acacSPaolo Bonzini    glib_modules="$glib_modules gmodule-no-export-2.0"
147054cb65d8SEmilio G. Cotafi
1471e26110cfSFam Zheng
1472aa0d1f44SPaolo Bonzinifor i in $glib_modules; do
1473e26110cfSFam Zheng    if $pkg_config --atleast-version=$glib_req_ver $i; then
147489138857SStefan Weil        glib_cflags=$($pkg_config --cflags $i)
147589138857SStefan Weil        glib_libs=$($pkg_config --libs $i)
1476e18df141SAnthony Liguori    else
1477e26110cfSFam Zheng        error_exit "glib-$glib_req_ver $i is required to compile QEMU"
1478e26110cfSFam Zheng    fi
1479e26110cfSFam Zhengdone
1480e26110cfSFam Zheng
14815b9e7d05SMarc-André Lureauglib_bindir="$($pkg_config --variable=bindir glib-2.0)"
14825b9e7d05SMarc-André Lureauif test -z "$glib_bindir" ; then
14835b9e7d05SMarc-André Lureau	glib_bindir="$($pkg_config --variable=prefix glib-2.0)"/bin
14845b9e7d05SMarc-André Lureaufi
14855b9e7d05SMarc-André Lureau
1486215b0c2fSPaolo Bonzini# This workaround is required due to a bug in pkg-config file for glib as it
1487215b0c2fSPaolo Bonzini# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
1488215b0c2fSPaolo Bonzini
1489215b0c2fSPaolo Bonziniif test "$static" = yes && test "$mingw32" = yes; then
1490215b0c2fSPaolo Bonzini    glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
1491215b0c2fSPaolo Bonzinifi
1492215b0c2fSPaolo Bonzini
1493977a82abSDaniel P. Berrange# Sanity check that the current size_t matches the
1494977a82abSDaniel P. Berrange# size that glib thinks it should be. This catches
1495977a82abSDaniel P. Berrange# problems on multi-arch where people try to build
1496977a82abSDaniel P. Berrange# 32-bit QEMU while pointing at 64-bit glib headers
1497977a82abSDaniel P. Berrangecat > $TMPC <<EOF
1498977a82abSDaniel P. Berrange#include <glib.h>
1499977a82abSDaniel P. Berrange#include <unistd.h>
1500977a82abSDaniel P. Berrange
1501977a82abSDaniel P. Berrange#define QEMU_BUILD_BUG_ON(x) \
1502977a82abSDaniel P. Berrange  typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
1503977a82abSDaniel P. Berrange
1504977a82abSDaniel P. Berrangeint main(void) {
1505977a82abSDaniel P. Berrange   QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
1506977a82abSDaniel P. Berrange   return 0;
1507977a82abSDaniel P. Berrange}
1508977a82abSDaniel P. BerrangeEOF
1509977a82abSDaniel P. Berrange
1510215b0c2fSPaolo Bonziniif ! compile_prog "$glib_cflags" "$glib_libs" ; then
1511977a82abSDaniel P. Berrange    error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
1512977a82abSDaniel P. Berrange               "You probably need to set PKG_CONFIG_LIBDIR"\
1513977a82abSDaniel P. Berrange	       "to point to the right pkg-config files for your"\
1514977a82abSDaniel P. Berrange	       "build target"
1515977a82abSDaniel P. Berrangefi
1516977a82abSDaniel P. Berrange
15179bda600bSEric Blake# Silence clang warnings triggered by glib < 2.57.2
15189bda600bSEric Blakecat > $TMPC << EOF
15199bda600bSEric Blake#include <glib.h>
15209bda600bSEric Blaketypedef struct Foo {
15219bda600bSEric Blake    int i;
15229bda600bSEric Blake} Foo;
15239bda600bSEric Blakestatic void foo_free(Foo *f)
15249bda600bSEric Blake{
15259bda600bSEric Blake    g_free(f);
15269bda600bSEric Blake}
1527e0e7fe07SMarc-André LureauG_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
15289bda600bSEric Blakeint main(void) { return 0; }
15299bda600bSEric BlakeEOF
15309bda600bSEric Blakeif ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
15319bda600bSEric Blake    if cc_has_warning_flag "-Wno-unused-function"; then
15329bda600bSEric Blake        glib_cflags="$glib_cflags -Wno-unused-function"
15335770e8afSPaolo Bonzini        CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
15349bda600bSEric Blake    fi
15359bda600bSEric Blakefi
15369bda600bSEric Blake
1537e26110cfSFam Zheng##########################################
1538f652e6afSaurel32# fdt probe
1539e169e1e1SPeter Maydell
1540fbb4121dSPaolo Bonzinicase "$fdt" in
1541fbb4121dSPaolo Bonzini  auto | enabled | internal)
1542fbb4121dSPaolo Bonzini    # Simpler to always update submodule, even if not needed.
1543aef45d51SDaniel P. Berrange    git_submodules="${git_submodules} dtc"
1544fbb4121dSPaolo Bonzini    ;;
1545fbb4121dSPaolo Bonziniesac
1546f652e6afSaurel32
154720ff075bSMichael Walle##########################################
1548519175a2SAlex Barcelo# check and set a backend for coroutine
1549d0e2fce5SAneesh Kumar K.V
15507c2acc70SPeter Maydell# We prefer ucontext, but it's not always possible. The fallback
155133c53c54SDaniel P. Berrange# is sigcontext. On Windows the only valid backend is the Windows
155233c53c54SDaniel P. Berrange# specific one.
15537c2acc70SPeter Maydell
15547c2acc70SPeter Maydellucontext_works=no
1555d0e2fce5SAneesh Kumar K.Vif test "$darwin" != "yes"; then
1556d0e2fce5SAneesh Kumar K.V  cat > $TMPC << EOF
1557d0e2fce5SAneesh Kumar K.V#include <ucontext.h>
1558cdf84806SPeter Maydell#ifdef __stub_makecontext
1559cdf84806SPeter Maydell#error Ignoring glibc stub makecontext which will always fail
1560cdf84806SPeter Maydell#endif
156175cafad7SStefan Weilint main(void) { makecontext(0, 0, 0); return 0; }
1562d0e2fce5SAneesh Kumar K.VEOF
1563d0e2fce5SAneesh Kumar K.V  if compile_prog "" "" ; then
15647c2acc70SPeter Maydell    ucontext_works=yes
1565d0e2fce5SAneesh Kumar K.V  fi
1566519175a2SAlex Barcelofi
15677c2acc70SPeter Maydell
15687c2acc70SPeter Maydellif test "$coroutine" = ""; then
15697c2acc70SPeter Maydell  if test "$mingw32" = "yes"; then
15707c2acc70SPeter Maydell    coroutine=win32
15717c2acc70SPeter Maydell  elif test "$ucontext_works" = "yes"; then
15727c2acc70SPeter Maydell    coroutine=ucontext
1573519175a2SAlex Barcelo  else
15747c2acc70SPeter Maydell    coroutine=sigaltstack
15757c2acc70SPeter Maydell  fi
15767c2acc70SPeter Maydellelse
15777c2acc70SPeter Maydell  case $coroutine in
15787c2acc70SPeter Maydell  windows)
15797c2acc70SPeter Maydell    if test "$mingw32" != "yes"; then
15807c2acc70SPeter Maydell      error_exit "'windows' coroutine backend only valid for Windows"
15817c2acc70SPeter Maydell    fi
15827c2acc70SPeter Maydell    # Unfortunately the user visible backend name doesn't match the
15837c2acc70SPeter Maydell    # coroutine-*.c filename for this case, so we have to adjust it here.
15847c2acc70SPeter Maydell    coroutine=win32
15857c2acc70SPeter Maydell    ;;
15867c2acc70SPeter Maydell  ucontext)
15877c2acc70SPeter Maydell    if test "$ucontext_works" != "yes"; then
15887cb58448SPaolo Bonzini      error_exit "'ucontext' backend requested but makecontext not available"
15897c2acc70SPeter Maydell    fi
15907c2acc70SPeter Maydell    ;;
159133c53c54SDaniel P. Berrange  sigaltstack)
15927c2acc70SPeter Maydell    if test "$mingw32" = "yes"; then
15937c2acc70SPeter Maydell      error_exit "only the 'windows' coroutine backend is valid for Windows"
15947c2acc70SPeter Maydell    fi
15957c2acc70SPeter Maydell    ;;
15967c2acc70SPeter Maydell  *)
159776ad07a4SPeter Maydell    error_exit "unknown coroutine backend $coroutine"
15987c2acc70SPeter Maydell    ;;
15997c2acc70SPeter Maydell  esac
1600d0e2fce5SAneesh Kumar K.Vfi
1601d0e2fce5SAneesh Kumar K.V
16021e4f6065SDaniele Buono##################################################
16031e4f6065SDaniele Buono# SafeStack
16041e4f6065SDaniele Buono
16051e4f6065SDaniele Buono
16061e4f6065SDaniele Buonoif test "$safe_stack" = "yes"; then
16071e4f6065SDaniele Buonocat > $TMPC << EOF
16081e4f6065SDaniele Buonoint main(int argc, char *argv[])
16091e4f6065SDaniele Buono{
16101e4f6065SDaniele Buono#if ! __has_feature(safe_stack)
16111e4f6065SDaniele Buono#error SafeStack Disabled
16121e4f6065SDaniele Buono#endif
16131e4f6065SDaniele Buono    return 0;
16141e4f6065SDaniele Buono}
16151e4f6065SDaniele BuonoEOF
16161e4f6065SDaniele Buono  flag="-fsanitize=safe-stack"
16171e4f6065SDaniele Buono  # Check that safe-stack is supported and enabled.
16181e4f6065SDaniele Buono  if compile_prog "-Werror $flag" "$flag"; then
16191e4f6065SDaniele Buono    # Flag needed both at compilation and at linking
16201e4f6065SDaniele Buono    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
16211e4f6065SDaniele Buono    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
16221e4f6065SDaniele Buono  else
16231e4f6065SDaniele Buono    error_exit "SafeStack not supported by your compiler"
16241e4f6065SDaniele Buono  fi
16251e4f6065SDaniele Buono  if test "$coroutine" != "ucontext"; then
16261e4f6065SDaniele Buono    error_exit "SafeStack is only supported by the coroutine backend ucontext"
16271e4f6065SDaniele Buono  fi
16281e4f6065SDaniele Buonoelse
16291e4f6065SDaniele Buonocat > $TMPC << EOF
16301e4f6065SDaniele Buonoint main(int argc, char *argv[])
16311e4f6065SDaniele Buono{
16321e4f6065SDaniele Buono#if defined(__has_feature)
16331e4f6065SDaniele Buono#if __has_feature(safe_stack)
16341e4f6065SDaniele Buono#error SafeStack Enabled
16351e4f6065SDaniele Buono#endif
16361e4f6065SDaniele Buono#endif
16371e4f6065SDaniele Buono    return 0;
16381e4f6065SDaniele Buono}
16391e4f6065SDaniele BuonoEOF
16401e4f6065SDaniele Buonoif test "$safe_stack" = "no"; then
16411e4f6065SDaniele Buono  # Make sure that safe-stack is disabled
16421e4f6065SDaniele Buono  if ! compile_prog "-Werror" ""; then
16431e4f6065SDaniele Buono    # SafeStack was already enabled, try to explicitly remove the feature
16441e4f6065SDaniele Buono    flag="-fno-sanitize=safe-stack"
16451e4f6065SDaniele Buono    if ! compile_prog "-Werror $flag" "$flag"; then
16461e4f6065SDaniele Buono      error_exit "Configure cannot disable SafeStack"
16471e4f6065SDaniele Buono    fi
16481e4f6065SDaniele Buono    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
16491e4f6065SDaniele Buono    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
16501e4f6065SDaniele Buono  fi
16511e4f6065SDaniele Buonoelse # "$safe_stack" = ""
16521e4f6065SDaniele Buono  # Set safe_stack to yes or no based on pre-existing flags
16531e4f6065SDaniele Buono  if compile_prog "-Werror" ""; then
16541e4f6065SDaniele Buono    safe_stack="no"
16551e4f6065SDaniele Buono  else
16561e4f6065SDaniele Buono    safe_stack="yes"
16571e4f6065SDaniele Buono    if test "$coroutine" != "ucontext"; then
16581e4f6065SDaniele Buono      error_exit "SafeStack is only supported by the coroutine backend ucontext"
16591e4f6065SDaniele Buono    fi
16601e4f6065SDaniele Buono  fi
16611e4f6065SDaniele Buonofi
16621e4f6065SDaniele Buonofi
16637d992e4dSPeter Lieven
166476a347e1SRichard Henderson########################################
1665fd0e6053SJohn Snow# check if ccache is interfering with
1666fd0e6053SJohn Snow# semantic analysis of macros
1667fd0e6053SJohn Snow
16685e4dfd3dSJohn Snowunset CCACHE_CPP2
1669fd0e6053SJohn Snowccache_cpp2=no
1670fd0e6053SJohn Snowcat > $TMPC << EOF
1671fd0e6053SJohn Snowstatic const int Z = 1;
1672fd0e6053SJohn Snow#define fn() ({ Z; })
1673fd0e6053SJohn Snow#define TAUT(X) ((X) == Z)
1674fd0e6053SJohn Snow#define PAREN(X, Y) (X == Y)
1675fd0e6053SJohn Snow#define ID(X) (X)
1676fd0e6053SJohn Snowint main(int argc, char *argv[])
1677fd0e6053SJohn Snow{
1678fd0e6053SJohn Snow    int x = 0, y = 0;
1679fd0e6053SJohn Snow    x = ID(x);
1680fd0e6053SJohn Snow    x = fn();
1681fd0e6053SJohn Snow    fn();
1682fd0e6053SJohn Snow    if (PAREN(x, y)) return 0;
1683fd0e6053SJohn Snow    if (TAUT(Z)) return 0;
1684fd0e6053SJohn Snow    return 0;
1685fd0e6053SJohn Snow}
1686fd0e6053SJohn SnowEOF
1687fd0e6053SJohn Snow
1688fd0e6053SJohn Snowif ! compile_object "-Werror"; then
1689fd0e6053SJohn Snow    ccache_cpp2=yes
1690fd0e6053SJohn Snowfi
1691fd0e6053SJohn Snow
1692b553a042SJohn Snow#################################################
1693b553a042SJohn Snow# clang does not support glibc + FORTIFY_SOURCE.
1694b553a042SJohn Snow
1695b553a042SJohn Snowif test "$fortify_source" != "no"; then
1696b553a042SJohn Snow  if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
1697b553a042SJohn Snow    fortify_source="no";
1698e189091fSPeter Maydell  elif test -n "$cxx" && has $cxx &&
1699cfcc7c14SJohn Snow       echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
1700b553a042SJohn Snow    fortify_source="no";
1701b553a042SJohn Snow  else
1702b553a042SJohn Snow    fortify_source="yes"
1703b553a042SJohn Snow  fi
1704b553a042SJohn Snowfi
1705b553a042SJohn Snow
1706d2042378SAneesh Kumar K.V##########################################
1707247724cbSMarc-André Lureau# checks for sanitizers
1708247724cbSMarc-André Lureau
1709247724cbSMarc-André Lureauhave_asan=no
1710247724cbSMarc-André Lureauhave_ubsan=no
1711d83414e1SMarc-André Lureauhave_asan_iface_h=no
1712d83414e1SMarc-André Lureauhave_asan_iface_fiber=no
1713247724cbSMarc-André Lureau
1714247724cbSMarc-André Lureauif test "$sanitizers" = "yes" ; then
1715b9f44da2SMarc-André Lureau  write_c_skeleton
1716247724cbSMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
1717247724cbSMarc-André Lureau      have_asan=yes
1718247724cbSMarc-André Lureau  fi
1719b9f44da2SMarc-André Lureau
1720b9f44da2SMarc-André Lureau  # we could use a simple skeleton for flags checks, but this also
1721b9f44da2SMarc-André Lureau  # detect the static linking issue of ubsan, see also:
1722b9f44da2SMarc-André Lureau  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
1723b9f44da2SMarc-André Lureau  cat > $TMPC << EOF
1724b9f44da2SMarc-André Lureau#include <stdlib.h>
1725b9f44da2SMarc-André Lureauint main(void) {
1726b9f44da2SMarc-André Lureau    void *tmp = malloc(10);
1727f2dfe54cSLeonid Bloch    if (tmp != NULL) {
1728b9f44da2SMarc-André Lureau        return *(int *)(tmp + 2);
1729b9f44da2SMarc-André Lureau    }
1730d1abf3fcSOlaf Hering    return 1;
1731f2dfe54cSLeonid Bloch}
1732b9f44da2SMarc-André LureauEOF
1733247724cbSMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
1734247724cbSMarc-André Lureau      have_ubsan=yes
1735247724cbSMarc-André Lureau  fi
1736d83414e1SMarc-André Lureau
1737d83414e1SMarc-André Lureau  if check_include "sanitizer/asan_interface.h" ; then
1738d83414e1SMarc-André Lureau      have_asan_iface_h=yes
1739d83414e1SMarc-André Lureau  fi
1740d83414e1SMarc-André Lureau
1741d83414e1SMarc-André Lureau  cat > $TMPC << EOF
1742d83414e1SMarc-André Lureau#include <sanitizer/asan_interface.h>
1743d83414e1SMarc-André Lureauint main(void) {
1744d83414e1SMarc-André Lureau  __sanitizer_start_switch_fiber(0, 0, 0);
1745d83414e1SMarc-André Lureau  return 0;
1746d83414e1SMarc-André Lureau}
1747d83414e1SMarc-André LureauEOF
1748d83414e1SMarc-André Lureau  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
1749d83414e1SMarc-André Lureau      have_asan_iface_fiber=yes
1750d83414e1SMarc-André Lureau  fi
1751247724cbSMarc-André Lureaufi
1752247724cbSMarc-André Lureau
17530aebab04SLingfeng Yang# Thread sanitizer is, for now, much noisier than the other sanitizers;
17540aebab04SLingfeng Yang# keep it separate until that is not the case.
17550aebab04SLingfeng Yangif test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
17560aebab04SLingfeng Yang  error_exit "TSAN is not supported with other sanitiziers."
17570aebab04SLingfeng Yangfi
17580aebab04SLingfeng Yanghave_tsan=no
17590aebab04SLingfeng Yanghave_tsan_iface_fiber=no
17600aebab04SLingfeng Yangif test "$tsan" = "yes" ; then
17610aebab04SLingfeng Yang  write_c_skeleton
17620aebab04SLingfeng Yang  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
17630aebab04SLingfeng Yang      have_tsan=yes
17640aebab04SLingfeng Yang  fi
17650aebab04SLingfeng Yang  cat > $TMPC << EOF
17660aebab04SLingfeng Yang#include <sanitizer/tsan_interface.h>
17670aebab04SLingfeng Yangint main(void) {
17680aebab04SLingfeng Yang  __tsan_create_fiber(0);
17690aebab04SLingfeng Yang  return 0;
17700aebab04SLingfeng Yang}
17710aebab04SLingfeng YangEOF
17720aebab04SLingfeng Yang  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
17730aebab04SLingfeng Yang      have_tsan_iface_fiber=yes
17740aebab04SLingfeng Yang  fi
17750aebab04SLingfeng Yangfi
17760aebab04SLingfeng Yang
1777adc28027SAlexander Bulekov##########################################
1778cd362defSPaolo Bonzini# functions to probe cross compilers
1779cd362defSPaolo Bonzini
1780cd362defSPaolo Bonzinicontainer="no"
1781cd362defSPaolo Bonziniif test $use_containers = "yes"; then
1782c4575b59SPaolo Bonzini    case $($python "$source_path"/tests/docker/docker.py probe) in
1783c4575b59SPaolo Bonzini        *docker) container=docker ;;
1784c4575b59SPaolo Bonzini        podman) container=podman ;;
1785c4575b59SPaolo Bonzini        no) container=no ;;
1786c4575b59SPaolo Bonzini    esac
1787a3e28f81SPaolo Bonzini    if test "$container" != "no"; then
1788a3e28f81SPaolo Bonzini        docker_py="$python $source_path/tests/docker/docker.py --engine $container"
1789a3e28f81SPaolo Bonzini    fi
1790cd362defSPaolo Bonzinifi
1791cd362defSPaolo Bonzini
1792cd362defSPaolo Bonzini# cross compilers defaults, can be overridden with --cross-cc-ARCH
17935adb43beSPaolo Bonzini: ${cross_prefix_aarch64="aarch64-linux-gnu-"}
17945adb43beSPaolo Bonzini: ${cross_prefix_aarch64_be="$cross_prefix_aarch64"}
17955adb43beSPaolo Bonzini: ${cross_prefix_alpha="alpha-linux-gnu-"}
17965adb43beSPaolo Bonzini: ${cross_prefix_arm="arm-linux-gnueabihf-"}
17975adb43beSPaolo Bonzini: ${cross_prefix_armeb="$cross_prefix_arm"}
17985adb43beSPaolo Bonzini: ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
179934bb43b0SSong Gao: ${cross_prefix_loongarch64="loongarch64-unknown-linux-gnu-"}
18005adb43beSPaolo Bonzini: ${cross_prefix_hppa="hppa-linux-gnu-"}
18015adb43beSPaolo Bonzini: ${cross_prefix_i386="i686-linux-gnu-"}
18025adb43beSPaolo Bonzini: ${cross_prefix_m68k="m68k-linux-gnu-"}
18035adb43beSPaolo Bonzini: ${cross_prefix_microblaze="microblaze-linux-musl-"}
18045adb43beSPaolo Bonzini: ${cross_prefix_mips64el="mips64el-linux-gnuabi64-"}
18055adb43beSPaolo Bonzini: ${cross_prefix_mips64="mips64-linux-gnuabi64-"}
18065adb43beSPaolo Bonzini: ${cross_prefix_mipsel="mipsel-linux-gnu-"}
18075adb43beSPaolo Bonzini: ${cross_prefix_mips="mips-linux-gnu-"}
18085adb43beSPaolo Bonzini: ${cross_prefix_nios2="nios2-linux-gnu-"}
18095adb43beSPaolo Bonzini: ${cross_prefix_ppc="powerpc-linux-gnu-"}
18105adb43beSPaolo Bonzini: ${cross_prefix_ppc64="powerpc64-linux-gnu-"}
18115adb43beSPaolo Bonzini: ${cross_prefix_ppc64le="$cross_prefix_ppc64"}
18125adb43beSPaolo Bonzini: ${cross_prefix_riscv64="riscv64-linux-gnu-"}
18135adb43beSPaolo Bonzini: ${cross_prefix_s390x="s390x-linux-gnu-"}
18145adb43beSPaolo Bonzini: ${cross_prefix_sh4="sh4-linux-gnu-"}
18155adb43beSPaolo Bonzini: ${cross_prefix_sparc64="sparc64-linux-gnu-"}
18165adb43beSPaolo Bonzini: ${cross_prefix_sparc="$cross_prefix_sparc64"}
18175adb43beSPaolo Bonzini: ${cross_prefix_x86_64="x86_64-linux-gnu-"}
18185adb43beSPaolo Bonzini
1819cd362defSPaolo Bonzini: ${cross_cc_aarch64_be="$cross_cc_aarch64"}
1820cd362defSPaolo Bonzini: ${cross_cc_cflags_aarch64_be="-mbig-endian"}
182146af66edSPaolo Bonzini: ${cross_cc_armeb="$cross_cc_arm"}
1822cd362defSPaolo Bonzini: ${cross_cc_cflags_armeb="-mbig-endian"}
1823cd362defSPaolo Bonzini: ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
1824cd362defSPaolo Bonzini: ${cross_cc_cflags_hexagon="-mv67 -O2 -static"}
1825cd362defSPaolo Bonzini: ${cross_cc_cflags_i386="-m32"}
1826d44f2f96SPaolo Bonzini: ${cross_cc_cflags_ppc="-m32 -mbig-endian"}
1827cd362defSPaolo Bonzini: ${cross_cc_cflags_ppc64="-m64 -mbig-endian"}
1828cd362defSPaolo Bonzini: ${cross_cc_ppc64le="$cross_cc_ppc64"}
1829cd362defSPaolo Bonzini: ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"}
1830cd362defSPaolo Bonzini: ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
183146af66edSPaolo Bonzini: ${cross_cc_sparc="$cross_cc_sparc64"}
183246af66edSPaolo Bonzini: ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
1833cd362defSPaolo Bonzini: ${cross_cc_cflags_x86_64="-m64"}
1834cd362defSPaolo Bonzini
18355adb43beSPaolo Bonzinicompute_target_variable() {
183692e288fcSPaolo Bonzini  eval "$2="
18375adb43beSPaolo Bonzini  if eval test -n "\"\${cross_prefix_$1}\""; then
18385adb43beSPaolo Bonzini    if eval has "\"\${cross_prefix_$1}\$3\""; then
18395adb43beSPaolo Bonzini      eval "$2=\"\${cross_prefix_$1}\$3\""
18405adb43beSPaolo Bonzini    fi
18415adb43beSPaolo Bonzini  fi
18425adb43beSPaolo Bonzini}
1843cd362defSPaolo Bonzini
184452f08deaSPaolo Bonzini# probe_target_compiler TARGET
184552f08deaSPaolo Bonzini#
184652f08deaSPaolo Bonzini# Look for a compiler for the given target, either native or cross.
184752f08deaSPaolo Bonzini# Set variables target_* if a compiler is found, and container_cross_*
184852f08deaSPaolo Bonzini# if a Docker-based cross-compiler image is known for the target.
184952f08deaSPaolo Bonzini# Set got_cross_cc to yes/no depending on whether a non-container-based
185052f08deaSPaolo Bonzini# compiler was found.
185152f08deaSPaolo Bonzini#
185252f08deaSPaolo Bonzini# If TARGET is a user-mode emulation target, also set build_static to
185352f08deaSPaolo Bonzini# "y" if static linking is possible.
185452f08deaSPaolo Bonzini#
1855cd362defSPaolo Bonziniprobe_target_compiler() {
1856cd362defSPaolo Bonzini  # reset all output variables
185792e288fcSPaolo Bonzini  got_cross_cc=no
1858cd362defSPaolo Bonzini  container_image=
1859cd362defSPaolo Bonzini  container_hosts=
1860cd362defSPaolo Bonzini  container_cross_cc=
186187eb014cSPaolo Bonzini  container_cross_ar=
1862cd362defSPaolo Bonzini  container_cross_as=
1863cd362defSPaolo Bonzini  container_cross_ld=
186487eb014cSPaolo Bonzini  container_cross_nm=
186587eb014cSPaolo Bonzini  container_cross_objcopy=
186687eb014cSPaolo Bonzini  container_cross_ranlib=
186787eb014cSPaolo Bonzini  container_cross_strip=
1868cd362defSPaolo Bonzini
186952f08deaSPaolo Bonzini  target_arch=${1%%-*}
187052f08deaSPaolo Bonzini  case $target_arch in
1871cd362defSPaolo Bonzini    aarch64) container_hosts="x86_64 aarch64" ;;
1872cd362defSPaolo Bonzini    alpha) container_hosts=x86_64 ;;
1873cd362defSPaolo Bonzini    arm) container_hosts="x86_64 aarch64" ;;
1874cd362defSPaolo Bonzini    cris) container_hosts=x86_64 ;;
1875cd362defSPaolo Bonzini    hexagon) container_hosts=x86_64 ;;
1876cd362defSPaolo Bonzini    hppa) container_hosts=x86_64 ;;
1877cd362defSPaolo Bonzini    i386) container_hosts=x86_64 ;;
1878b70ec50bSRichard Henderson    loongarch64) container_hosts=x86_64 ;;
1879cd362defSPaolo Bonzini    m68k) container_hosts=x86_64 ;;
1880cd362defSPaolo Bonzini    microblaze) container_hosts=x86_64 ;;
1881cd362defSPaolo Bonzini    mips64el) container_hosts=x86_64 ;;
1882cd362defSPaolo Bonzini    mips64) container_hosts=x86_64 ;;
1883cd362defSPaolo Bonzini    mipsel) container_hosts=x86_64 ;;
1884cd362defSPaolo Bonzini    mips) container_hosts=x86_64 ;;
1885cd362defSPaolo Bonzini    nios2) container_hosts=x86_64 ;;
1886cd362defSPaolo Bonzini    ppc) container_hosts=x86_64 ;;
1887cd362defSPaolo Bonzini    ppc64|ppc64le) container_hosts=x86_64 ;;
1888cd362defSPaolo Bonzini    riscv64) container_hosts=x86_64 ;;
1889cd362defSPaolo Bonzini    s390x) container_hosts=x86_64 ;;
1890cd362defSPaolo Bonzini    sh4) container_hosts=x86_64 ;;
1891cd362defSPaolo Bonzini    sparc64) container_hosts=x86_64 ;;
1892cd362defSPaolo Bonzini    tricore) container_hosts=x86_64 ;;
1893cd362defSPaolo Bonzini    x86_64) container_hosts="aarch64 ppc64el x86_64" ;;
1894cd362defSPaolo Bonzini    xtensa*) container_hosts=x86_64 ;;
1895cd362defSPaolo Bonzini  esac
1896cd362defSPaolo Bonzini
1897cd362defSPaolo Bonzini  for host in $container_hosts; do
1898cd362defSPaolo Bonzini    test "$container" != no || continue
1899cd362defSPaolo Bonzini    test "$host" = "$cpu" || continue
190052f08deaSPaolo Bonzini    case $target_arch in
1901cd362defSPaolo Bonzini      aarch64)
1902cd362defSPaolo Bonzini        # We don't have any bigendian build tools so we only use this for AArch64
1903cd362defSPaolo Bonzini        container_image=debian-arm64-cross
19045adb43beSPaolo Bonzini        container_cross_prefix=aarch64-linux-gnu-
19055adb43beSPaolo Bonzini        container_cross_cc=${container_cross_prefix}gcc-10
1906cd362defSPaolo Bonzini        ;;
1907cd362defSPaolo Bonzini      alpha)
1908cd362defSPaolo Bonzini        container_image=debian-alpha-cross
19095adb43beSPaolo Bonzini        container_cross_prefix=alpha-linux-gnu-
1910cd362defSPaolo Bonzini        ;;
1911cd362defSPaolo Bonzini      arm)
1912cd362defSPaolo Bonzini        # We don't have any bigendian build tools so we only use this for ARM
1913cd362defSPaolo Bonzini        container_image=debian-armhf-cross
19145adb43beSPaolo Bonzini        container_cross_prefix=arm-linux-gnueabihf-
1915cd362defSPaolo Bonzini        ;;
1916cd362defSPaolo Bonzini      cris)
1917cd362defSPaolo Bonzini        container_image=fedora-cris-cross
19185adb43beSPaolo Bonzini        container_cross_prefix=cris-linux-gnu-
1919cd362defSPaolo Bonzini        ;;
1920cd362defSPaolo Bonzini      hexagon)
1921cd362defSPaolo Bonzini        container_image=debian-hexagon-cross
19225adb43beSPaolo Bonzini        container_cross_prefix=hexagon-unknown-linux-musl-
19235adb43beSPaolo Bonzini        container_cross_cc=${container_cross_prefix}clang
1924cd362defSPaolo Bonzini        ;;
1925cd362defSPaolo Bonzini      hppa)
1926cd362defSPaolo Bonzini        container_image=debian-hppa-cross
19275adb43beSPaolo Bonzini        container_cross_prefix=hppa-linux-gnu-
1928cd362defSPaolo Bonzini        ;;
1929cd362defSPaolo Bonzini      i386)
1930cd362defSPaolo Bonzini        container_image=fedora-i386-cross
19315adb43beSPaolo Bonzini        container_cross_prefix=
1932cd362defSPaolo Bonzini        ;;
1933b70ec50bSRichard Henderson      loongarch64)
1934b70ec50bSRichard Henderson        container_image=debian-loongarch-cross
1935b70ec50bSRichard Henderson        container_cross_prefix=loongarch64-unknown-linux-gnu-
1936b70ec50bSRichard Henderson        ;;
1937cd362defSPaolo Bonzini      m68k)
1938cd362defSPaolo Bonzini        container_image=debian-m68k-cross
19395adb43beSPaolo Bonzini        container_cross_prefix=m68k-linux-gnu-
1940cd362defSPaolo Bonzini        ;;
1941cd362defSPaolo Bonzini      microblaze)
1942cd362defSPaolo Bonzini        container_image=debian-microblaze-cross
19435adb43beSPaolo Bonzini        container_cross_prefix=microblaze-linux-musl-
1944cd362defSPaolo Bonzini        ;;
1945cd362defSPaolo Bonzini      mips64el)
1946cd362defSPaolo Bonzini        container_image=debian-mips64el-cross
19475adb43beSPaolo Bonzini        container_cross_prefix=mips64el-linux-gnuabi64-
1948cd362defSPaolo Bonzini        ;;
1949cd362defSPaolo Bonzini      mips64)
1950cd362defSPaolo Bonzini        container_image=debian-mips64-cross
19515adb43beSPaolo Bonzini        container_cross_prefix=mips64-linux-gnuabi64-
1952cd362defSPaolo Bonzini        ;;
1953cd362defSPaolo Bonzini      mipsel)
1954cd362defSPaolo Bonzini        container_image=debian-mipsel-cross
19555adb43beSPaolo Bonzini        container_cross_prefix=mipsel-linux-gnu-
1956cd362defSPaolo Bonzini        ;;
1957cd362defSPaolo Bonzini      mips)
1958cd362defSPaolo Bonzini        container_image=debian-mips-cross
19595adb43beSPaolo Bonzini        container_cross_prefix=mips-linux-gnu-
1960cd362defSPaolo Bonzini        ;;
1961cd362defSPaolo Bonzini      nios2)
1962cd362defSPaolo Bonzini        container_image=debian-nios2-cross
19635adb43beSPaolo Bonzini        container_cross_prefix=nios2-linux-gnu-
1964cd362defSPaolo Bonzini        ;;
1965cd362defSPaolo Bonzini      ppc)
1966cd362defSPaolo Bonzini        container_image=debian-powerpc-test-cross
19675adb43beSPaolo Bonzini        container_cross_prefix=powerpc-linux-gnu-
19685adb43beSPaolo Bonzini        container_cross_cc=${container_cross_prefix}gcc-10
1969cd362defSPaolo Bonzini        ;;
1970cd362defSPaolo Bonzini      ppc64|ppc64le)
1971cd362defSPaolo Bonzini        container_image=debian-powerpc-test-cross
1972705c881fSRichard Henderson        container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu-
19735adb43beSPaolo Bonzini        container_cross_cc=${container_cross_prefix}gcc-10
1974cd362defSPaolo Bonzini        ;;
1975cd362defSPaolo Bonzini      riscv64)
1976cd362defSPaolo Bonzini        container_image=debian-riscv64-test-cross
19775adb43beSPaolo Bonzini        container_cross_prefix=riscv64-linux-gnu-
1978cd362defSPaolo Bonzini        ;;
1979cd362defSPaolo Bonzini      s390x)
1980cd362defSPaolo Bonzini        container_image=debian-s390x-cross
19815adb43beSPaolo Bonzini        container_cross_prefix=s390x-linux-gnu-
1982cd362defSPaolo Bonzini        ;;
1983cd362defSPaolo Bonzini      sh4)
1984cd362defSPaolo Bonzini        container_image=debian-sh4-cross
19855adb43beSPaolo Bonzini        container_cross_prefix=sh4-linux-gnu-
1986cd362defSPaolo Bonzini        ;;
1987cd362defSPaolo Bonzini      sparc64)
1988cd362defSPaolo Bonzini        container_image=debian-sparc64-cross
19895adb43beSPaolo Bonzini        container_cross_prefix=sparc64-linux-gnu-
1990cd362defSPaolo Bonzini        ;;
1991cd362defSPaolo Bonzini      tricore)
1992cd362defSPaolo Bonzini        container_image=debian-tricore-cross
19935adb43beSPaolo Bonzini        container_cross_prefix=tricore-
1994cd362defSPaolo Bonzini        container_cross_as=tricore-as
1995cd362defSPaolo Bonzini        container_cross_ld=tricore-ld
19965adb43beSPaolo Bonzini        break
1997cd362defSPaolo Bonzini        ;;
1998cd362defSPaolo Bonzini      x86_64)
1999cd362defSPaolo Bonzini        container_image=debian-amd64-cross
20005adb43beSPaolo Bonzini        container_cross_prefix=x86_64-linux-gnu-
2001cd362defSPaolo Bonzini        ;;
2002cd362defSPaolo Bonzini      xtensa*)
2003cd362defSPaolo Bonzini        container_hosts=x86_64
2004cd362defSPaolo Bonzini        container_image=debian-xtensa-cross
2005cd362defSPaolo Bonzini
2006cd362defSPaolo Bonzini        # default to the dc232b cpu
20075adb43beSPaolo Bonzini        container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
2008cd362defSPaolo Bonzini        ;;
2009cd362defSPaolo Bonzini    esac
20105adb43beSPaolo Bonzini    : ${container_cross_cc:=${container_cross_prefix}gcc}
201187eb014cSPaolo Bonzini    : ${container_cross_ar:=${container_cross_prefix}ar}
20125adb43beSPaolo Bonzini    : ${container_cross_as:=${container_cross_prefix}as}
20135adb43beSPaolo Bonzini    : ${container_cross_ld:=${container_cross_prefix}ld}
201487eb014cSPaolo Bonzini    : ${container_cross_nm:=${container_cross_prefix}nm}
201587eb014cSPaolo Bonzini    : ${container_cross_objcopy:=${container_cross_prefix}objcopy}
201687eb014cSPaolo Bonzini    : ${container_cross_ranlib:=${container_cross_prefix}ranlib}
201787eb014cSPaolo Bonzini    : ${container_cross_strip:=${container_cross_prefix}strip}
2018cd362defSPaolo Bonzini  done
2019cd362defSPaolo Bonzini
202092e288fcSPaolo Bonzini  try=cross
202192e288fcSPaolo Bonzini  case "$target_arch:$cpu" in
202292e288fcSPaolo Bonzini    aarch64_be:aarch64 | \
202392e288fcSPaolo Bonzini    armeb:arm | \
202492e288fcSPaolo Bonzini    i386:x86_64 | \
202592e288fcSPaolo Bonzini    mips*:mips64 | \
202692e288fcSPaolo Bonzini    ppc*:ppc64 | \
202792e288fcSPaolo Bonzini    sparc:sparc64 | \
202892e288fcSPaolo Bonzini    "$cpu:$cpu")
202992e288fcSPaolo Bonzini      try='native cross' ;;
203092e288fcSPaolo Bonzini  esac
203152f08deaSPaolo Bonzini  eval "target_cflags=\${cross_cc_cflags_$target_arch}"
2032b3b5472dSPeter Maydell  for thistry in $try; do
2033b3b5472dSPeter Maydell    case $thistry in
203492e288fcSPaolo Bonzini    native)
203592e288fcSPaolo Bonzini      target_cc=$cc
203692e288fcSPaolo Bonzini      target_ccas=$ccas
203792e288fcSPaolo Bonzini      target_ar=$ar
203892e288fcSPaolo Bonzini      target_as=$as
203992e288fcSPaolo Bonzini      target_ld=$ld
204092e288fcSPaolo Bonzini      target_nm=$nm
204192e288fcSPaolo Bonzini      target_objcopy=$objcopy
204292e288fcSPaolo Bonzini      target_ranlib=$ranlib
204392e288fcSPaolo Bonzini      target_strip=$strip
204492e288fcSPaolo Bonzini      ;;
204592e288fcSPaolo Bonzini    cross)
204692e288fcSPaolo Bonzini      target_cc=
204752f08deaSPaolo Bonzini      if eval test -n "\"\${cross_cc_$target_arch}\""; then
204852f08deaSPaolo Bonzini        if eval has "\"\${cross_cc_$target_arch}\""; then
204952f08deaSPaolo Bonzini          eval "target_cc=\"\${cross_cc_$target_arch}\""
2050cd362defSPaolo Bonzini        fi
20515adb43beSPaolo Bonzini      else
205252f08deaSPaolo Bonzini        compute_target_variable $target_arch target_cc gcc
2053cd362defSPaolo Bonzini      fi
205487eb014cSPaolo Bonzini      target_ccas=$target_cc
205552f08deaSPaolo Bonzini      compute_target_variable $target_arch target_ar ar
205652f08deaSPaolo Bonzini      compute_target_variable $target_arch target_as as
205752f08deaSPaolo Bonzini      compute_target_variable $target_arch target_ld ld
205852f08deaSPaolo Bonzini      compute_target_variable $target_arch target_nm nm
205952f08deaSPaolo Bonzini      compute_target_variable $target_arch target_objcopy objcopy
206052f08deaSPaolo Bonzini      compute_target_variable $target_arch target_ranlib ranlib
206152f08deaSPaolo Bonzini      compute_target_variable $target_arch target_strip strip
2062640aabc8SPaolo Bonzini      ;;
2063640aabc8SPaolo Bonzini    esac
206492e288fcSPaolo Bonzini
20652ad60f6fSPaolo Bonzini    if test -n "$target_cc"; then
206652f08deaSPaolo Bonzini      case $target_arch in
20672ad60f6fSPaolo Bonzini        i386|x86_64)
20682ad60f6fSPaolo Bonzini          if $target_cc --version | grep -qi "clang"; then
206992e288fcSPaolo Bonzini            continue
20702ad60f6fSPaolo Bonzini          fi
20712ad60f6fSPaolo Bonzini          ;;
20722ad60f6fSPaolo Bonzini      esac
207392e288fcSPaolo Bonzini    elif test -n "$target_as" && test -n "$target_ld"; then
207492e288fcSPaolo Bonzini      # Special handling for assembler only targets
207592e288fcSPaolo Bonzini      case $target in
207692e288fcSPaolo Bonzini        tricore-softmmu)
207792e288fcSPaolo Bonzini          build_static=
207892e288fcSPaolo Bonzini          got_cross_cc=yes
207992e288fcSPaolo Bonzini          break
208092e288fcSPaolo Bonzini          ;;
208192e288fcSPaolo Bonzini        *)
208292e288fcSPaolo Bonzini          continue
208392e288fcSPaolo Bonzini          ;;
208492e288fcSPaolo Bonzini      esac
208592e288fcSPaolo Bonzini    else
208692e288fcSPaolo Bonzini      continue
208792e288fcSPaolo Bonzini    fi
208892e288fcSPaolo Bonzini
208992e288fcSPaolo Bonzini    write_c_skeleton
209092e288fcSPaolo Bonzini    case $1 in
209192e288fcSPaolo Bonzini      *-softmmu)
209292e288fcSPaolo Bonzini        if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC &&
209392e288fcSPaolo Bonzini          do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then
209492e288fcSPaolo Bonzini          got_cross_cc=yes
209592e288fcSPaolo Bonzini          break
209692e288fcSPaolo Bonzini        fi
209792e288fcSPaolo Bonzini        ;;
209892e288fcSPaolo Bonzini      *)
209992e288fcSPaolo Bonzini        if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC -static ; then
210092e288fcSPaolo Bonzini          build_static=y
210192e288fcSPaolo Bonzini          got_cross_cc=yes
210292e288fcSPaolo Bonzini          break
210392e288fcSPaolo Bonzini        fi
210492e288fcSPaolo Bonzini        if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC ; then
210592e288fcSPaolo Bonzini          build_static=
210692e288fcSPaolo Bonzini          got_cross_cc=yes
210792e288fcSPaolo Bonzini          break
210892e288fcSPaolo Bonzini        fi
210992e288fcSPaolo Bonzini        ;;
211092e288fcSPaolo Bonzini    esac
211192e288fcSPaolo Bonzini  done
211292e288fcSPaolo Bonzini  if test $got_cross_cc != yes; then
211392e288fcSPaolo Bonzini    build_static=
211492e288fcSPaolo Bonzini    target_cc=
211592e288fcSPaolo Bonzini    target_ccas=
211692e288fcSPaolo Bonzini    target_ar=
211792e288fcSPaolo Bonzini    target_as=
211892e288fcSPaolo Bonzini    target_ld=
211992e288fcSPaolo Bonzini    target_nm=
212092e288fcSPaolo Bonzini    target_objcopy=
212192e288fcSPaolo Bonzini    target_ranlib=
212292e288fcSPaolo Bonzini    target_strip=
21232ad60f6fSPaolo Bonzini  fi
212461cbb356SPaolo Bonzini  test -n "$target_cc"
2125cd362defSPaolo Bonzini}
2126cd362defSPaolo Bonzini
2127cd362defSPaolo Bonziniwrite_target_makefile() {
2128e81785abSPaolo Bonzini  echo "EXTRA_CFLAGS=$target_cflags"
2129cd362defSPaolo Bonzini  if test -n "$target_cc"; then
2130cd362defSPaolo Bonzini    echo "CC=$target_cc"
213187eb014cSPaolo Bonzini    echo "CCAS=$target_ccas"
213287eb014cSPaolo Bonzini  fi
213387eb014cSPaolo Bonzini  if test -n "$target_ar"; then
213487eb014cSPaolo Bonzini    echo "AR=$target_ar"
2135cd362defSPaolo Bonzini  fi
2136cd362defSPaolo Bonzini  if test -n "$target_as"; then
2137cd362defSPaolo Bonzini    echo "AS=$target_as"
2138cd362defSPaolo Bonzini  fi
2139cd362defSPaolo Bonzini  if test -n "$target_ld"; then
2140cd362defSPaolo Bonzini    echo "LD=$target_ld"
2141cd362defSPaolo Bonzini  fi
214287eb014cSPaolo Bonzini  if test -n "$target_nm"; then
214387eb014cSPaolo Bonzini    echo "NM=$target_nm"
214487eb014cSPaolo Bonzini  fi
214587eb014cSPaolo Bonzini  if test -n "$target_objcopy"; then
214687eb014cSPaolo Bonzini    echo "OBJCOPY=$target_objcopy"
214787eb014cSPaolo Bonzini  fi
214887eb014cSPaolo Bonzini  if test -n "$target_ranlib"; then
214987eb014cSPaolo Bonzini    echo "RANLIB=$target_ranlib"
215087eb014cSPaolo Bonzini  fi
215187eb014cSPaolo Bonzini  if test -n "$target_strip"; then
215287eb014cSPaolo Bonzini    echo "STRIP=$target_strip"
215387eb014cSPaolo Bonzini  fi
2154cd362defSPaolo Bonzini}
2155cd362defSPaolo Bonzini
2156cd362defSPaolo Bonziniwrite_container_target_makefile() {
2157e81785abSPaolo Bonzini  echo "EXTRA_CFLAGS=$target_cflags"
2158cd362defSPaolo Bonzini  if test -n "$container_cross_cc"; then
2159a3e28f81SPaolo Bonzini    echo "CC=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
2160a3e28f81SPaolo Bonzini    echo "CCAS=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
2161cd362defSPaolo Bonzini  fi
2162a3e28f81SPaolo Bonzini  echo "AR=$docker_py cc --cc $container_cross_ar -i qemu/$container_image -s $source_path --"
2163a3e28f81SPaolo Bonzini  echo "AS=$docker_py cc --cc $container_cross_as -i qemu/$container_image -s $source_path --"
2164a3e28f81SPaolo Bonzini  echo "LD=$docker_py cc --cc $container_cross_ld -i qemu/$container_image -s $source_path --"
2165a3e28f81SPaolo Bonzini  echo "NM=$docker_py cc --cc $container_cross_nm -i qemu/$container_image -s $source_path --"
2166a3e28f81SPaolo Bonzini  echo "OBJCOPY=$docker_py cc --cc $container_cross_objcopy -i qemu/$container_image -s $source_path --"
2167a3e28f81SPaolo Bonzini  echo "RANLIB=$docker_py cc --cc $container_cross_ranlib -i qemu/$container_image -s $source_path --"
2168a3e28f81SPaolo Bonzini  echo "STRIP=$docker_py cc --cc $container_cross_strip -i qemu/$container_image -s $source_path --"
2169cd362defSPaolo Bonzini}
2170cd362defSPaolo Bonzini
2171cd362defSPaolo Bonzini
2172cd362defSPaolo Bonzini
2173cd362defSPaolo Bonzini##########################################
217455116968SJagannathan Raman# check for vfio_user_server
217555116968SJagannathan Raman
217655116968SJagannathan Ramancase "$vfio_user_server" in
217755116968SJagannathan Raman  enabled )
217855116968SJagannathan Raman    if test "$git_submodules_action" != "ignore"; then
217955116968SJagannathan Raman      git_submodules="${git_submodules} subprojects/libvfio-user"
218055116968SJagannathan Raman    fi
218155116968SJagannathan Raman    ;;
218255116968SJagannathan Ramanesac
218355116968SJagannathan Raman
218455116968SJagannathan Raman##########################################
2185e86ecd4bSJuan Quintela# End of CC checks
2186e86ecd4bSJuan Quintela# After here, no more $cc or $ld runs
2187e86ecd4bSJuan Quintela
2188d83414e1SMarc-André Lureauwrite_c_skeleton
2189d83414e1SMarc-André Lureau
2190df42fa7dSPaolo Bonziniif test "$fortify_source" = "yes" ; then
2191086d5f75SPaolo Bonzini  QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
2192086d5f75SPaolo Bonzinifi
2193086d5f75SPaolo Bonzini
2194247724cbSMarc-André Lureauif test "$have_asan" = "yes"; then
2195db5adeaaSPaolo Bonzini  QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
2196db5adeaaSPaolo Bonzini  QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
2197d83414e1SMarc-André Lureau  if test "$have_asan_iface_h" = "no" ; then
2198d83414e1SMarc-André Lureau      echo "ASAN build enabled, but ASAN header missing." \
2199d83414e1SMarc-André Lureau           "Without code annotation, the report may be inferior."
2200d83414e1SMarc-André Lureau  elif test "$have_asan_iface_fiber" = "no" ; then
2201d83414e1SMarc-André Lureau      echo "ASAN build enabled, but ASAN header is too old." \
2202d83414e1SMarc-André Lureau           "Without code annotation, the report may be inferior."
2203d83414e1SMarc-André Lureau  fi
2204247724cbSMarc-André Lureaufi
22050aebab04SLingfeng Yangif test "$have_tsan" = "yes" ; then
22060aebab04SLingfeng Yang  if test "$have_tsan_iface_fiber" = "yes" ; then
22070aebab04SLingfeng Yang    QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
22080aebab04SLingfeng Yang    QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
22090aebab04SLingfeng Yang  else
22100aebab04SLingfeng Yang    error_exit "Cannot enable TSAN due to missing fiber annotation interface."
22110aebab04SLingfeng Yang  fi
22120aebab04SLingfeng Yangelif test "$tsan" = "yes" ; then
22130aebab04SLingfeng Yang  error_exit "Cannot enable TSAN due to missing sanitize thread interface."
22140aebab04SLingfeng Yangfi
2215247724cbSMarc-André Lureauif test "$have_ubsan" = "yes"; then
2216db5adeaaSPaolo Bonzini  QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
2217db5adeaaSPaolo Bonzini  QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
2218247724cbSMarc-André Lureaufi
2219247724cbSMarc-André Lureau
22206542aa9cSPeter Lieven##########################################
2221b846ab7cSPaolo Bonzini# Guest agent Windows MSI package
22229d6bc27bSMichael Roth
22239d6bc27bSMichael Rothif test "$QEMU_GA_MANUFACTURER" = ""; then
22249d6bc27bSMichael Roth  QEMU_GA_MANUFACTURER=QEMU
22259d6bc27bSMichael Rothfi
22269d6bc27bSMichael Rothif test "$QEMU_GA_DISTRO" = ""; then
22279d6bc27bSMichael Roth  QEMU_GA_DISTRO=Linux
22289d6bc27bSMichael Rothfi
22299d6bc27bSMichael Rothif test "$QEMU_GA_VERSION" = ""; then
223064708615SPeter Maydell    QEMU_GA_VERSION=$(cat "$source_path"/VERSION)
22319d6bc27bSMichael Rothfi
22329d6bc27bSMichael Roth
223333ab4787SPaolo Bonzini
223433ab4787SPaolo Bonzini#######################################
223533ab4787SPaolo Bonzini# cross-compiled firmware targets
223633ab4787SPaolo Bonzini
2237ad388845SPaolo Bonzini# Set up build tree symlinks that point back into the source tree
2238ad388845SPaolo Bonzini# (these can be both files and directories).
2239ad388845SPaolo Bonzini# Caution: avoid adding files or directories here using wildcards. This
2240ad388845SPaolo Bonzini# will result in problems later if a new file matching the wildcard is
2241ad388845SPaolo Bonzini# added to the source tree -- nothing will cause configure to be rerun
2242ad388845SPaolo Bonzini# so the build tree will be missing the link back to the new file, and
2243ad388845SPaolo Bonzini# tests might fail. Prefer to keep the relevant files in their own
2244ad388845SPaolo Bonzini# directory and symlink the directory instead.
2245ad388845SPaolo BonziniLINKS="Makefile"
2246ad388845SPaolo BonziniLINKS="$LINKS pc-bios/optionrom/Makefile"
2247ad388845SPaolo BonziniLINKS="$LINKS pc-bios/s390-ccw/Makefile"
2248d695918fSPaolo BonziniLINKS="$LINKS pc-bios/vof/Makefile"
2249ad388845SPaolo BonziniLINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
2250ad388845SPaolo BonziniLINKS="$LINKS tests/avocado tests/data"
2251ad388845SPaolo BonziniLINKS="$LINKS tests/qemu-iotests/check"
2252ad388845SPaolo BonziniLINKS="$LINKS python"
2253ad388845SPaolo BonziniLINKS="$LINKS contrib/plugins/Makefile "
2254ad388845SPaolo Bonzinifor f in $LINKS ; do
2255ad388845SPaolo Bonzini    if [ -e "$source_path/$f" ]; then
2256cc3c71e8SPeter Maydell        mkdir -p "$(dirname ./"$f")"
2257ad388845SPaolo Bonzini        symlink "$source_path/$f" "$f"
2258ad388845SPaolo Bonzini    fi
2259ad388845SPaolo Bonzinidone
2260ad388845SPaolo Bonzini
2261ca35f780SPaolo Bonzini# Mac OS X ships with a broken assembler
2262ca35f780SPaolo Bonziniroms=
226361cbb356SPaolo Bonziniif test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
226461cbb356SPaolo Bonzini        test "$targetos" != "haiku" && test "$softmmu" = yes && \
226561cbb356SPaolo Bonzini        probe_target_compiler i386-softmmu; then
226676ca98b0SPaolo Bonzini    roms="pc-bios/optionrom"
226733ab4787SPaolo Bonzini    config_mak=pc-bios/optionrom/config.mak
226833ab4787SPaolo Bonzini    echo "# Automatically generated by configure - do not modify" > $config_mak
226933ab4787SPaolo Bonzini    echo "TOPSRC_DIR=$source_path" >> $config_mak
227033ab4787SPaolo Bonzini    write_target_makefile >> $config_mak
227133ab4787SPaolo Bonzinifi
2272ca35f780SPaolo Bonzini
227361cbb356SPaolo Bonziniif test "$softmmu" = yes && probe_target_compiler ppc-softmmu; then
227476ca98b0SPaolo Bonzini    roms="$roms pc-bios/vof"
2275d695918fSPaolo Bonzini    config_mak=pc-bios/vof/config.mak
2276d695918fSPaolo Bonzini    echo "# Automatically generated by configure - do not modify" > $config_mak
2277d695918fSPaolo Bonzini    echo "SRC_DIR=$source_path/pc-bios/vof" >> $config_mak
2278d695918fSPaolo Bonzini    write_target_makefile >> $config_mak
2279d695918fSPaolo Bonzinifi
2280d695918fSPaolo Bonzini
22819ffed426SPaolo Bonzini# Only build s390-ccw bios if the compiler has -march=z900 or -march=z10
22829ffed426SPaolo Bonzini# (which is the lowest architecture level that Clang supports)
228361cbb356SPaolo Bonziniif test "$softmmu" = yes && probe_target_compiler s390x-softmmu; then
22842e33c3f8SThomas Huth  write_c_skeleton
22859ffed426SPaolo Bonzini  do_compiler "$target_cc" $target_cc_cflags -march=z900 -o $TMPO -c $TMPC
2286a5b2afd5SThomas Huth  has_z900=$?
22879ffed426SPaolo Bonzini  if [ $has_z900 = 0 ] || do_compiler "$target_cc" $target_cc_cflags -march=z10 -msoft-float -Werror -o $TMPO -c $TMPC; then
2288a5b2afd5SThomas Huth    if [ $has_z900 != 0 ]; then
2289a5b2afd5SThomas Huth      echo "WARNING: Your compiler does not support the z900!"
2290a5b2afd5SThomas Huth      echo "         The s390-ccw bios will only work with guest CPUs >= z10."
2291a5b2afd5SThomas Huth    fi
229276ca98b0SPaolo Bonzini    roms="$roms pc-bios/s390-ccw"
22939ffed426SPaolo Bonzini    config_mak=pc-bios/s390-ccw/config-host.mak
22949ffed426SPaolo Bonzini    echo "# Automatically generated by configure - do not modify" > $config_mak
22959ffed426SPaolo Bonzini    echo "SRC_PATH=$source_path/pc-bios/s390-ccw" >> $config_mak
22969ffed426SPaolo Bonzini    write_target_makefile >> $config_mak
22971ef6bfc2SPhilippe Mathieu-Daudé    # SLOF is required for building the s390-ccw firmware on s390x,
22981ef6bfc2SPhilippe Mathieu-Daudé    # since it is using the libnet code from SLOF for network booting.
22991ef6bfc2SPhilippe Mathieu-Daudé    git_submodules="${git_submodules} roms/SLOF"
23001ef6bfc2SPhilippe Mathieu-Daudé  fi
23019933c305SChristian Borntraegerfi
23029933c305SChristian Borntraeger
23039ffed426SPaolo Bonzini#######################################
23049ffed426SPaolo Bonzini# generate config-host.mak
23059ffed426SPaolo Bonzini
23067d7dbf9dSDan Streetmanif ! (GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
23077d7dbf9dSDan Streetman    exit 1
23085d91a2edSYonggang Luofi
23095d91a2edSYonggang Luo
231098ec69acSJuan Quintelaconfig_host_mak="config-host.mak"
231197a847bcSbellard
231298ec69acSJuan Quintelaecho "# Automatically generated by configure - do not modify" > $config_host_mak
231398ec69acSJuan Quintelaecho >> $config_host_mak
231498ec69acSJuan Quintela
2315e6c3b0f7SPaolo Bonziniecho all: >> $config_host_mak
2316cc84d63aSDaniel P. Berrangeecho "GIT=$git" >> $config_host_mak
2317aef45d51SDaniel P. Berrangeecho "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
23187d7dbf9dSDan Streetmanecho "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
2319804edf29SJuan Quintela
2320f8393946Saurel32if test "$debug_tcg" = "yes" ; then
23212358a494SJuan Quintela  echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
2322f8393946Saurel32fi
232367b915a5Sbellardif test "$mingw32" = "yes" ; then
232498ec69acSJuan Quintela  echo "CONFIG_WIN32=y" >> $config_host_mak
23259dacf32dSYossi Hindin  echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
23269dacf32dSYossi Hindin  echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
23279dacf32dSYossi Hindin  echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
2328210fa556Spbrookelse
232935f4df27SJuan Quintela  echo "CONFIG_POSIX=y" >> $config_host_mak
2330210fa556Spbrookfi
2331128ab2ffSblueswir1
2332dffcb71cSMark McLoughlinif test "$linux" = "yes" ; then
2333dffcb71cSMark McLoughlin  echo "CONFIG_LINUX=y" >> $config_host_mak
2334dffcb71cSMark McLoughlinfi
2335dffcb71cSMark McLoughlin
233683fb7adfSbellardif test "$darwin" = "yes" ; then
233798ec69acSJuan Quintela  echo "CONFIG_DARWIN=y" >> $config_host_mak
233883fb7adfSbellardfi
2339b29fe3edSmalc
2340ec530c81Sbellardif test "$solaris" = "yes" ; then
234198ec69acSJuan Quintela  echo "CONFIG_SOLARIS=y" >> $config_host_mak
2342ec530c81Sbellardfi
234397a847bcSbellardif test "$static" = "yes" ; then
234498ec69acSJuan Quintela  echo "CONFIG_STATIC=y" >> $config_host_mak
234597a847bcSbellardfi
234698ec69acSJuan Quintelaecho "SRC_PATH=$source_path" >> $config_host_mak
23472b1f35b9SAlex Bennéeecho "TARGET_DIRS=$target_list" >> $config_host_mak
234817969268SFam Zhengif test "$modules" = "yes"; then
234917969268SFam Zheng  echo "CONFIG_MODULES=y" >> $config_host_mak
235017969268SFam Zhengfi
2351277abf15SJan Vesely
235283fb7adfSbellard# XXX: suppress that
23537d3505c5Sbellardif [ "$bsd" = "yes" ] ; then
23542358a494SJuan Quintela  echo "CONFIG_BSD=y" >> $config_host_mak
23557d3505c5Sbellardfi
23567d3505c5Sbellard
23577c2acc70SPeter Maydellecho "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
23587d992e4dSPeter Lieven
2359d83414e1SMarc-André Lureauif test "$have_asan_iface_fiber" = "yes" ; then
2360d83414e1SMarc-André Lureau    echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
2361d83414e1SMarc-André Lureaufi
2362d83414e1SMarc-André Lureau
23630aebab04SLingfeng Yangif test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
23640aebab04SLingfeng Yang    echo "CONFIG_TSAN=y" >> $config_host_mak
23650aebab04SLingfeng Yangfi
23660aebab04SLingfeng Yang
236740e8c6f4SAlex Bennéeif test "$plugins" = "yes" ; then
236840e8c6f4SAlex Bennée    echo "CONFIG_PLUGIN=y" >> $config_host_mak
236940e8c6f4SAlex Bennéefi
237040e8c6f4SAlex Bennée
2371f48e590aSAlex Bennéeif test -n "$gdb_bin"; then
2372b1863cccSAlex Bennée    gdb_version=$($gdb_bin --version | head -n 1)
2373d6a66c81SAlex Bennée    if version_ge ${gdb_version##* } 9.1; then
2374f48e590aSAlex Bennée        echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
237548543dd7SAlex Bennée    else
237648543dd7SAlex Bennée        gdb_bin=""
2377f48e590aSAlex Bennée    fi
2378b1863cccSAlex Bennéefi
2379f48e590aSAlex Bennée
2380c4575b59SPaolo Bonziniif test "$container" != no; then
2381c4575b59SPaolo Bonzini    echo "ENGINE=$container" >> $config_host_mak
2382c4575b59SPaolo Bonzinifi
238398ec69acSJuan Quintelaecho "ROMS=$roms" >> $config_host_mak
2384804edf29SJuan Quintelaecho "MAKE=$make" >> $config_host_mak
2385c886edfbSBlue Swirlecho "PYTHON=$python" >> $config_host_mak
238639d87c8cSAlex Bennéeecho "GENISOIMAGE=$genisoimage" >> $config_host_mak
2387a5665051SPaolo Bonziniecho "MESON=$meson" >> $config_host_mak
238809e93326SPaolo Bonziniecho "NINJA=$ninja" >> $config_host_mak
2389804edf29SJuan Quintelaecho "CC=$cc" >> $config_host_mak
2390a558ee17SJuan Quintelaecho "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
23914cb37d11SPhilippe Mathieu-Daudéecho "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak
2392a81df1b6SPaolo Bonziniecho "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
2393a81df1b6SPaolo Bonziniecho "GLIB_LIBS=$glib_libs" >> $config_host_mak
23945b9e7d05SMarc-André Lureauecho "GLIB_BINDIR=$glib_bindir" >> $config_host_mak
2395d83acfd0SMarc-André Lureauecho "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak
23968a99e9a3SPhilippe Mathieu-Daudéecho "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
2397804edf29SJuan Quintelaecho "EXESUF=$EXESUF" >> $config_host_mak
2398804edf29SJuan Quintela
23996efd7517SPeter Maydell# use included Linux headers
24006efd7517SPeter Maydellif test "$linux" = "yes" ; then
2401a307beb6SAndreas Färber  mkdir -p linux-headers
24026efd7517SPeter Maydell  case "$cpu" in
24034da270beSPaolo Bonzini  i386|x86_64)
240408312a63SPeter Maydell    linux_arch=x86
24056efd7517SPeter Maydell    ;;
2406d8ff892dSPaolo Bonzini  ppc|ppc64)
240708312a63SPeter Maydell    linux_arch=powerpc
24086efd7517SPeter Maydell    ;;
24096efd7517SPeter Maydell  s390x)
241008312a63SPeter Maydell    linux_arch=s390
241108312a63SPeter Maydell    ;;
24121f080313SClaudio Fontana  aarch64)
24131f080313SClaudio Fontana    linux_arch=arm64
24141f080313SClaudio Fontana    ;;
2415dfcf900bSWANG Xuerui  loongarch*)
2416dfcf900bSWANG Xuerui    linux_arch=loongarch
2417dfcf900bSWANG Xuerui    ;;
2418222e7d11SSanjay Lal  mips64)
2419222e7d11SSanjay Lal    linux_arch=mips
2420222e7d11SSanjay Lal    ;;
242108312a63SPeter Maydell  *)
242208312a63SPeter Maydell    # For most CPUs the kernel architecture name and QEMU CPU name match.
242308312a63SPeter Maydell    linux_arch="$cpu"
24246efd7517SPeter Maydell    ;;
24256efd7517SPeter Maydell  esac
242608312a63SPeter Maydell    # For non-KVM architectures we will not have asm headers
242708312a63SPeter Maydell    if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
242808312a63SPeter Maydell      symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
242908312a63SPeter Maydell    fi
24306efd7517SPeter Maydellfi
24316efd7517SPeter Maydell
243297a847bcSbellardfor target in $target_list; do
243397a847bcSbellard    target_dir="$target"
243457a93f16SPhilippe Mathieu-Daudé    target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
243564708615SPeter Maydell    mkdir -p "$target_dir"
2436fdb75aefSPaolo Bonzini    case $target in
2437fdb75aefSPaolo Bonzini        *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
2438fdb75aefSPaolo Bonzini        *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
24392408a527Saurel32    esac
244056aebc89Spbrookdone
24417d13299dSbellard
2442fdb75aefSPaolo Bonziniif test "$default_targets" = "yes"; then
2443fdb75aefSPaolo Bonzini  echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
2444fdb75aefSPaolo Bonzinifi
2445a540f158SPeter Crosthwaite
2446fd0e6053SJohn Snowif test "$ccache_cpp2" = "yes"; then
2447fd0e6053SJohn Snow  echo "export CCACHE_CPP2=y" >> $config_host_mak
2448fd0e6053SJohn Snowfi
2449fd0e6053SJohn Snow
24501e4f6065SDaniele Buonoif test "$safe_stack" = "yes"; then
24511e4f6065SDaniele Buono  echo "CONFIG_SAFESTACK=y" >> $config_host_mak
24521e4f6065SDaniele Buonofi
24531e4f6065SDaniele Buono
2454cd362defSPaolo Bonzini# tests/tcg configuration
2455cd362defSPaolo Bonzini(makefile=tests/tcg/Makefile.prereqs
2456cd362defSPaolo Bonziniecho "# Automatically generated by configure - do not modify" > $makefile
2457cd362defSPaolo Bonzini
2458cd362defSPaolo Bonziniconfig_host_mak=tests/tcg/config-host.mak
2459d674342eSPaolo Bonzinimkdir -p tests/tcg
2460cd362defSPaolo Bonziniecho "# Automatically generated by configure - do not modify" > $config_host_mak
2461cd362defSPaolo Bonziniecho "SRC_PATH=$source_path" >> $config_host_mak
2462cd362defSPaolo Bonziniecho "HOST_CC=$host_cc" >> $config_host_mak
2463cd362defSPaolo Bonzini
246448543dd7SAlex Bennée# versioned checked in the main config_host.mak above
246548543dd7SAlex Bennéeif test -n "$gdb_bin"; then
246648543dd7SAlex Bennée    echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
246748543dd7SAlex Bennéefi
246848543dd7SAlex Bennée
2469cd362defSPaolo Bonzinitcg_tests_targets=
2470cd362defSPaolo Bonzinifor target in $target_list; do
2471cd362defSPaolo Bonzini  arch=${target%%-*}
2472cd362defSPaolo Bonzini
2473cd362defSPaolo Bonzini  config_target_mak=tests/tcg/config-$target.mak
2474cd362defSPaolo Bonzini
2475cd362defSPaolo Bonzini  echo "# Automatically generated by configure - do not modify" > $config_target_mak
247664708615SPeter Maydell  echo "TARGET_NAME=$arch" >> "$config_target_mak"
2477cd362defSPaolo Bonzini  case $target in
2478c48a5c47SPaolo Bonzini    xtensa*-linux-user)
2479c48a5c47SPaolo Bonzini      # the toolchain is not complete with headers, only build softmmu tests
2480c48a5c47SPaolo Bonzini      continue
2481c48a5c47SPaolo Bonzini      ;;
2482cd362defSPaolo Bonzini    *-softmmu)
248364708615SPeter Maydell      test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || continue
2484cd362defSPaolo Bonzini      qemu="qemu-system-$arch"
2485cd362defSPaolo Bonzini      ;;
2486cd362defSPaolo Bonzini    *-linux-user|*-bsd-user)
2487cd362defSPaolo Bonzini      qemu="qemu-$arch"
2488cd362defSPaolo Bonzini      ;;
2489cd362defSPaolo Bonzini  esac
2490cd362defSPaolo Bonzini
249152f08deaSPaolo Bonzini  probe_target_compiler $target
2492cd362defSPaolo Bonzini  if test $got_cross_cc = yes; then
249364708615SPeter Maydell      write_target_makefile >> "$config_target_mak"
2494cd362defSPaolo Bonzini  elif test -n "$container_image"; then
2495*15b273f8SPaolo Bonzini      build_static=y
2496cd362defSPaolo Bonzini      echo "build-tcg-tests-$target: docker-image-$container_image" >> $makefile
249764708615SPeter Maydell      write_container_target_makefile >> "$config_target_mak"
2498cd362defSPaolo Bonzini      got_cross_cc=yes
2499cd362defSPaolo Bonzini  fi
2500cd362defSPaolo Bonzini  if test $got_cross_cc = yes; then
2501d674342eSPaolo Bonzini      mkdir -p "tests/tcg/$target"
2502d674342eSPaolo Bonzini      ln -sf "$source_path/tests/tcg/Makefile.target" "tests/tcg/$target/Makefile"
2503d674342eSPaolo Bonzini      ln -sf "../config-$target.mak" "tests/tcg/$target/config-target.mak"
2504a3e28f81SPaolo Bonzini      echo "TARGET=$target" >> "$config_target_mak"
250564708615SPeter Maydell      echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
2506*15b273f8SPaolo Bonzini      echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
2507cd362defSPaolo Bonzini      echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> $makefile
2508cd362defSPaolo Bonzini      tcg_tests_targets="$tcg_tests_targets $target"
2509cd362defSPaolo Bonzini  fi
25102038f8c8SPaolo Bonzinidone
2511cd362defSPaolo Bonziniecho "TCG_TESTS_TARGETS=$tcg_tests_targets" >> $makefile)
25122038f8c8SPaolo Bonzini
2513a5665051SPaolo Bonziniif test "$skip_meson" = no; then
2514fc929892SMarc-André Lureau  cross="config-meson.cross.new"
2515fc929892SMarc-André Lureau  meson_quote() {
2516ac7ebcc5SPaolo Bonzini    test $# = 0 && return
251747b30835SPaolo Bonzini    echo "'$(echo $* | sed "s/ /','/g")'"
2518fc929892SMarc-André Lureau  }
2519fc929892SMarc-André Lureau
2520fc929892SMarc-André Lureau  echo "# Automatically generated by configure - do not modify" > $cross
2521fc929892SMarc-André Lureau  echo "[properties]" >> $cross
2522d1d5e9eeSAlex Bennée
2523d1d5e9eeSAlex Bennée  # unroll any custom device configs
2524d1d5e9eeSAlex Bennée  for a in $device_archs; do
2525d1d5e9eeSAlex Bennée      eval "c=\$devices_${a}"
2526d1d5e9eeSAlex Bennée      echo "${a}-softmmu = '$c'" >> $cross
2527d1d5e9eeSAlex Bennée  done
2528d1d5e9eeSAlex Bennée
252947b30835SPaolo Bonzini  echo "[built-in options]" >> $cross
2530a2866660SPaolo Bonzini  echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
2531a2866660SPaolo Bonzini  echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
2532e910c7d9SPhilippe Mathieu-Daudé  test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
2533a2866660SPaolo Bonzini  echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
2534a2866660SPaolo Bonzini  echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
2535fc929892SMarc-André Lureau  echo "[binaries]" >> $cross
25364dba2789SPaolo Bonzini  echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
25374dba2789SPaolo Bonzini  test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
25384dba2789SPaolo Bonzini  test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
253947b30835SPaolo Bonzini  echo "ar = [$(meson_quote $ar)]" >> $cross
254047b30835SPaolo Bonzini  echo "nm = [$(meson_quote $nm)]" >> $cross
254147b30835SPaolo Bonzini  echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
254247b30835SPaolo Bonzini  echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
2543e8178514SPaolo Bonzini  if has $sdl2_config; then
254447b30835SPaolo Bonzini    echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
2545e8178514SPaolo Bonzini  fi
254647b30835SPaolo Bonzini  echo "strip = [$(meson_quote $strip)]" >> $cross
2547158bb224SKonstantin Kostiuk  echo "widl = [$(meson_quote $widl)]" >> $cross
254847b30835SPaolo Bonzini  echo "windres = [$(meson_quote $windres)]" >> $cross
25493812c0c4SJoelle van Dyne  if test "$cross_compile" = "yes"; then
2550fc929892SMarc-André Lureau    cross_arg="--cross-file config-meson.cross"
2551fc929892SMarc-André Lureau    echo "[host_machine]" >> $cross
2552ba7c60c2SPaolo Bonzini    echo "system = '$targetos'" >> $cross
2553823eb013SPaolo Bonzini    case "$cpu" in
2554f6bca9dfSJoelle van Dyne        i386)
2555fc929892SMarc-André Lureau            echo "cpu_family = 'x86'" >> $cross
2556fc929892SMarc-André Lureau            ;;
2557fc929892SMarc-André Lureau        *)
2558823eb013SPaolo Bonzini            echo "cpu_family = '$cpu'" >> $cross
2559fc929892SMarc-André Lureau            ;;
2560fc929892SMarc-André Lureau    esac
2561fc929892SMarc-André Lureau    echo "cpu = '$cpu'" >> $cross
2562fc929892SMarc-André Lureau    if test "$bigendian" = "yes" ; then
2563fc929892SMarc-André Lureau        echo "endian = 'big'" >> $cross
2564fc929892SMarc-André Lureau    else
2565fc929892SMarc-André Lureau        echo "endian = 'little'" >> $cross
2566fc929892SMarc-André Lureau    fi
2567fc929892SMarc-André Lureau  else
2568fc929892SMarc-André Lureau    cross_arg="--native-file config-meson.cross"
2569fc929892SMarc-André Lureau  fi
2570fc929892SMarc-André Lureau  mv $cross config-meson.cross
2571fc929892SMarc-André Lureau
2572a5665051SPaolo Bonzini  rm -rf meson-private meson-info meson-logs
25730a31e3a0SPaolo Bonzini
25740a31e3a0SPaolo Bonzini  # Built-in options
25750a31e3a0SPaolo Bonzini  test "$bindir" != "bin" && meson_option_add "-Dbindir=$bindir"
25760a31e3a0SPaolo Bonzini  test "$default_feature" = no && meson_option_add -Dauto_features=disabled
25770a31e3a0SPaolo Bonzini  test "$pie" = no && meson_option_add -Db_pie=false
25780a31e3a0SPaolo Bonzini  test "$werror" = yes && meson_option_add -Dwerror=true
25790a31e3a0SPaolo Bonzini
25800a31e3a0SPaolo Bonzini  # QEMU options
25810a31e3a0SPaolo Bonzini  test "$cfi" != false && meson_option_add "-Dcfi=$cfi"
25820a31e3a0SPaolo Bonzini  test "$fdt" != auto && meson_option_add "-Dfdt=$fdt"
25830a31e3a0SPaolo Bonzini  test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
25840a31e3a0SPaolo Bonzini  test "$qemu_suffix" != qemu && meson_option_add "-Dqemu_suffix=$qemu_suffix"
25850a31e3a0SPaolo Bonzini  test "$smbd" != '' && meson_option_add "-Dsmbd=$smbd"
25860a31e3a0SPaolo Bonzini  test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
258755116968SJagannathan Raman  test "$vfio_user_server" != auto && meson_option_add "-Dvfio_user_server=$vfio_user_server"
258861d63097SPaolo Bonzini  run_meson() {
25890a31e3a0SPaolo Bonzini    NINJA=$ninja $meson setup --prefix "$prefix" "$@" $cross_arg "$PWD" "$source_path"
259061d63097SPaolo Bonzini  }
259161d63097SPaolo Bonzini  eval run_meson $meson_options
2592a5665051SPaolo Bonzini  if test "$?" -ne 0 ; then
2593a5665051SPaolo Bonzini      error_exit "meson setup failed"
2594a5665051SPaolo Bonzini  fi
2595699d3884SPaolo Bonzinielse
2596699d3884SPaolo Bonzini  if test -f meson-private/cmd_line.txt; then
2597699d3884SPaolo Bonzini    # Adjust old command line options whose type was changed
2598699d3884SPaolo Bonzini    # Avoids having to use "setup --wipe" when Meson is upgraded
2599699d3884SPaolo Bonzini    perl -i -ne '
2600699d3884SPaolo Bonzini      s/^gettext = true$/gettext = auto/;
2601699d3884SPaolo Bonzini      s/^gettext = false$/gettext = disabled/;
2602654d6b04SPaolo Bonzini      /^b_staticpic/ && next;
2603699d3884SPaolo Bonzini      print;' meson-private/cmd_line.txt
2604699d3884SPaolo Bonzini  fi
2605a5665051SPaolo Bonzinifi
2606a5665051SPaolo Bonzini
2607dc655404SMichael S. Tsirkin# Save the configure command line for later reuse.
2608dc655404SMichael S. Tsirkincat <<EOD >config.status
2609dc655404SMichael S. Tsirkin#!/bin/sh
2610dc655404SMichael S. Tsirkin# Generated by configure.
2611dc655404SMichael S. Tsirkin# Run this file to recreate the current configuration.
2612dc655404SMichael S. Tsirkin# Compiler output produced by configure, useful for debugging
2613dc655404SMichael S. Tsirkin# configure, is in config.log if it exists.
2614dc655404SMichael S. TsirkinEOD
2615e811da7fSDaniel P. Berrangé
2616e811da7fSDaniel P. Berrangépreserve_env() {
2617e811da7fSDaniel P. Berrangé    envname=$1
2618e811da7fSDaniel P. Berrangé
2619e811da7fSDaniel P. Berrangé    eval envval=\$$envname
2620e811da7fSDaniel P. Berrangé
2621e811da7fSDaniel P. Berrangé    if test -n "$envval"
2622e811da7fSDaniel P. Berrangé    then
2623e811da7fSDaniel P. Berrangé	echo "$envname='$envval'" >> config.status
2624e811da7fSDaniel P. Berrangé	echo "export $envname" >> config.status
2625e811da7fSDaniel P. Berrangé    else
2626e811da7fSDaniel P. Berrangé	echo "unset $envname" >> config.status
2627e811da7fSDaniel P. Berrangé    fi
2628e811da7fSDaniel P. Berrangé}
2629e811da7fSDaniel P. Berrangé
2630e811da7fSDaniel P. Berrangé# Preserve various env variables that influence what
2631e811da7fSDaniel P. Berrangé# features/build target configure will detect
2632e811da7fSDaniel P. Berrangépreserve_env AR
2633e811da7fSDaniel P. Berrangépreserve_env AS
2634e811da7fSDaniel P. Berrangépreserve_env CC
26358009da03SPaolo Bonzinipreserve_env CFLAGS
2636e811da7fSDaniel P. Berrangépreserve_env CXX
26378009da03SPaolo Bonzinipreserve_env CXXFLAGS
2638e811da7fSDaniel P. Berrangépreserve_env LD
26398009da03SPaolo Bonzinipreserve_env LDFLAGS
2640e811da7fSDaniel P. Berrangépreserve_env LD_LIBRARY_PATH
2641e811da7fSDaniel P. Berrangépreserve_env MAKE
2642e811da7fSDaniel P. Berrangépreserve_env NM
2643b5569e5bSPaolo Bonzinipreserve_env OBJCFLAGS
2644e811da7fSDaniel P. Berrangépreserve_env OBJCOPY
2645e811da7fSDaniel P. Berrangépreserve_env PATH
2646e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG
2647e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_LIBDIR
2648e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_PATH
2649e811da7fSDaniel P. Berrangépreserve_env PYTHON
2650e811da7fSDaniel P. Berrangépreserve_env SDL2_CONFIG
2651e811da7fSDaniel P. Berrangépreserve_env SMBD
2652e811da7fSDaniel P. Berrangépreserve_env STRIP
2653158bb224SKonstantin Kostiukpreserve_env WIDL
2654e811da7fSDaniel P. Berrangépreserve_env WINDRES
2655e811da7fSDaniel P. Berrangé
2656dc655404SMichael S. Tsirkinprintf "exec" >>config.status
2657a5665051SPaolo Bonzinifor i in "$0" "$@"; do
2658835af899SPaolo Bonzini  test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
2659a5665051SPaolo Bonzinidone
2660cf7cc929SDr. David Alan Gilbertecho ' "$@"' >>config.status
2661dc655404SMichael S. Tsirkinchmod +x config.status
2662dc655404SMichael S. Tsirkin
26638cd05ab6SPeter Maydellrm -r "$TMPDIR1"
2664