xref: /openbmc/qemu/configure (revision 5f9ad35e)
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,
75b507233SPaolo Bonzini# just as autoconf does.  Unlike autoconf, we assume that unset exists.
85b507233SPaolo Bonziniunset CLICOLOR_FORCE GREP_OPTIONS BASH_ENV ENV MAIL MAILPATH CDPATH
999519e67SCornelia Huck
105e4dfd3dSJohn Snow# Don't allow CCACHE, if present, to use cached results of compile tests!
115e4dfd3dSJohn Snowexport CCACHE_RECACHE=yes
125e4dfd3dSJohn Snow
13dedad027SDaniel P. Berrangé# make source path absolute
14dedad027SDaniel P. Berrangésource_path=$(cd "$(dirname -- "$0")"; pwd)
15dedad027SDaniel P. Berrangé
16dedad027SDaniel P. Berrangéif test "$PWD" = "$source_path"
17dedad027SDaniel P. Berrangéthen
18dedad027SDaniel P. Berrangé    echo "Using './build' as the directory for build output"
19dedad027SDaniel P. Berrangé
20dedad027SDaniel P. Berrangé    MARKER=build/auto-created-by-configure
21dedad027SDaniel P. Berrangé
22dedad027SDaniel P. Berrangé    if test -e build
23dedad027SDaniel P. Berrangé    then
24dedad027SDaniel P. Berrangé        if test -f $MARKER
25dedad027SDaniel P. Berrangé        then
26dedad027SDaniel P. Berrangé           rm -rf build
27dedad027SDaniel P. Berrangé        else
28dedad027SDaniel P. Berrangé            echo "ERROR: ./build dir already exists and was not previously created by configure"
29dedad027SDaniel P. Berrangé            exit 1
30dedad027SDaniel P. Berrangé        fi
31dedad027SDaniel P. Berrangé    fi
32dedad027SDaniel P. Berrangé
33f160a5b2SDinah Baum    if ! mkdir build || ! touch $MARKER
34f160a5b2SDinah Baum    then
35f160a5b2SDinah Baum        echo "ERROR: Could not create ./build directory. Check the permissions on"
36f160a5b2SDinah Baum        echo "your source directory, or try doing an out-of-tree build."
37f160a5b2SDinah Baum        exit 1
38f160a5b2SDinah Baum    fi
39dedad027SDaniel P. Berrangé
40dedad027SDaniel P. Berrangé    cat > GNUmakefile <<'EOF'
41dedad027SDaniel P. Berrangé# This file is auto-generated by configure to support in-source tree
42dedad027SDaniel P. Berrangé# 'make' command invocation
43dedad027SDaniel P. Berrangé
449abbb375SAkihiko Odakibuild:
45dedad027SDaniel P. Berrangé	@echo 'changing dir to build for $(MAKE) "$(MAKECMDGOALS)"...'
46dedad027SDaniel P. Berrangé	@$(MAKE) -C build -f Makefile $(MAKECMDGOALS)
47dedad027SDaniel P. Berrangé	@if test "$(MAKECMDGOALS)" = "distclean" && \
48dedad027SDaniel P. Berrangé	    test -e build/auto-created-by-configure ; \
49dedad027SDaniel P. Berrangé	then \
50dedad027SDaniel P. Berrangé	    rm -rf build GNUmakefile ; \
51dedad027SDaniel P. Berrangé	fi
529abbb375SAkihiko Odaki%: build
539abbb375SAkihiko Odaki	@
549abbb375SAkihiko Odaki.PHONY: build
55dedad027SDaniel P. BerrangéGNUmakefile: ;
56dedad027SDaniel P. Berrangé
57dedad027SDaniel P. BerrangéEOF
58dedad027SDaniel P. Berrangé    cd build
5964708615SPeter Maydell    exec "$source_path/configure" "$@"
60dedad027SDaniel P. Berrangéfi
61dedad027SDaniel P. Berrangé
628cd05ab6SPeter Maydell# Temporary directory used for files created while
638cd05ab6SPeter Maydell# configure runs. Since it is in the build directory
648cd05ab6SPeter Maydell# we can safely blow away any previous version of it
658cd05ab6SPeter Maydell# (and we need not jump through hoops to try to delete
668cd05ab6SPeter Maydell# it when configure exits.)
678cd05ab6SPeter MaydellTMPDIR1="config-temp"
688cd05ab6SPeter Maydellrm -rf "${TMPDIR1}"
69563661c0SPeter Maydellif ! mkdir -p "${TMPDIR1}"; then
708cd05ab6SPeter Maydell    echo "ERROR: failed to create temporary directory"
718cd05ab6SPeter Maydell    exit 1
727d13299dSbellardfi
737d13299dSbellard
748cd05ab6SPeter MaydellTMPB="qemu-conf"
758cd05ab6SPeter MaydellTMPC="${TMPDIR1}/${TMPB}.c"
7666518bf6SDon SlutzTMPO="${TMPDIR1}/${TMPB}.o"
778cd05ab6SPeter MaydellTMPE="${TMPDIR1}/${TMPB}.exe"
787d13299dSbellard
79da1d85e3SGerd Hoffmannrm -f config.log
809ac81bbbSmalc
81b48e3611SPeter Maydell# Print a helpful header at the top of config.log
82b48e3611SPeter Maydellecho "# QEMU configure log $(date)" >> config.log
83979ae168SPeter Maydellprintf "# Configured with:" >> config.log
847f788779SAlex Bennée# repeat the invocation to log and stdout for CI
857f788779SAlex Bennéeinvoke=$(printf " '%s'" "$0" "$@")
867f788779SAlex Bennéetest -n "$GITLAB_CI" && echo "configuring with: $invoke"
877f788779SAlex Bennée{ echo "$invoke"; echo; echo "#"; } >> config.log
88b48e3611SPeter Maydell
89835af899SPaolo Bonziniquote_sh() {
90835af899SPaolo Bonzini    printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
91835af899SPaolo Bonzini}
92835af899SPaolo Bonzini
93050b4398SPaolo Bonzinierror_exit() {
94d880a3baSPaolo Bonzini    (echo
9576ad07a4SPeter Maydell    echo "ERROR: $1"
9676ad07a4SPeter Maydell    while test -n "$2"; do
9776ad07a4SPeter Maydell        echo "       $2"
9876ad07a4SPeter Maydell        shift
9976ad07a4SPeter Maydell    done
100d880a3baSPaolo Bonzini    echo) >&2
10176ad07a4SPeter Maydell    exit 1
10276ad07a4SPeter Maydell}
10376ad07a4SPeter Maydell
1049c83ffd8SPeter Maydelldo_compiler() {
1059c83ffd8SPeter Maydell  # Run the compiler, capturing its output to the log. First argument
1069c83ffd8SPeter Maydell  # is compiler binary to execute.
107b3b5472dSPeter Maydell  compiler="$1"
108cd362defSPaolo Bonzini  shift
109cd362defSPaolo Bonzini  if test -n "$BASH_VERSION"; then eval '
110cd362defSPaolo Bonzini      echo >>config.log "
111cd362defSPaolo Bonzinifuncs: ${FUNCNAME[*]}
112cd362defSPaolo Bonzinilines: ${BASH_LINENO[*]}"
113cd362defSPaolo Bonzini  '; fi
114cd362defSPaolo Bonzini  echo $compiler "$@" >> config.log
115cd362defSPaolo Bonzini  $compiler "$@" >> config.log 2>&1 || return $?
116cd362defSPaolo Bonzini}
117cd362defSPaolo Bonzini
1189c83ffd8SPeter Maydelldo_cc() {
119d0016b86SPaolo Bonzini    do_compiler "$cc" $CPU_CFLAGS "$@"
1209c83ffd8SPeter Maydell}
1219c83ffd8SPeter Maydell
12252166aa0SJuan Quintelacompile_object() {
123fd0e6053SJohn Snow  local_cflags="$1"
124a988b4c5SPaolo Bonzini  do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -c -o $TMPO $TMPC
12552166aa0SJuan Quintela}
12652166aa0SJuan Quintela
12752166aa0SJuan Quintelacompile_prog() {
12852166aa0SJuan Quintela  local_cflags="$1"
12952166aa0SJuan Quintela  local_ldflags="$2"
130a988b4c5SPaolo Bonzini  do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -o $TMPE $TMPC \
131a988b4c5SPaolo Bonzini      $LDFLAGS $EXTRA_LDFLAGS $local_ldflags
13252166aa0SJuan Quintela}
13352166aa0SJuan Quintela
13411568d6dSPaolo Bonzini# symbolically link $1 to $2.  Portable version of "ln -sf".
13511568d6dSPaolo Bonzinisymlink() {
13672b8b5a1SStefan Weil  rm -rf "$2"
137ec5b06d7SAnthony Liguori  mkdir -p "$(dirname "$2")"
13872b8b5a1SStefan Weil  ln -s "$1" "$2"
13911568d6dSPaolo Bonzini}
14011568d6dSPaolo Bonzini
1410dba6195SLoïc Minier# check whether a command is available to this shell (may be either an
1420dba6195SLoïc Minier# executable or a builtin)
1430dba6195SLoïc Minierhas() {
1440dba6195SLoïc Minier    type "$1" >/dev/null 2>&1
1450dba6195SLoïc Minier}
1460dba6195SLoïc Minier
1470a01d76fSMarc-André Lureauversion_ge () {
1482df52b9bSAlex Bennée    local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
1492df52b9bSAlex Bennée    local_ver2=$(echo "$2" | tr . ' ')
1500a01d76fSMarc-André Lureau    while true; do
1510a01d76fSMarc-André Lureau        set x $local_ver1
1520a01d76fSMarc-André Lureau        local_first=${2-0}
153c44a33e2SStefano Garzarella        # 'shift 2' if $2 is set, or 'shift' if $2 is not set
154c44a33e2SStefano Garzarella        shift ${2:+2}
1550a01d76fSMarc-André Lureau        local_ver1=$*
1560a01d76fSMarc-André Lureau        set x $local_ver2
1570a01d76fSMarc-André Lureau        # the second argument finished, the first must be greater or equal
1580a01d76fSMarc-André Lureau        test $# = 1 && return 0
1590a01d76fSMarc-André Lureau        test $local_first -lt $2 && return 1
1600a01d76fSMarc-André Lureau        test $local_first -gt $2 && return 0
161c44a33e2SStefano Garzarella        shift ${2:+2}
1620a01d76fSMarc-André Lureau        local_ver2=$*
1630a01d76fSMarc-André Lureau    done
1640a01d76fSMarc-André Lureau}
1650a01d76fSMarc-André Lureau
1664ace32e2SAntonio Ospiteif printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
1674ace32e2SAntonio Ospitethen
1684ace32e2SAntonio Ospite  error_exit "main directory cannot contain spaces nor colons"
1694ace32e2SAntonio Ospitefi
1704ace32e2SAntonio Ospite
17113cf376cSPaolo Bonzini# parse CC options first; some compiler tests are used to establish
17213cf376cSPaolo Bonzini# some defaults, based on the host environment
17313cf376cSPaolo Bonzini
17414211825SAntonio Ospite# default parameters
17542ede11aSAlex Bennéecontainer_engine="auto"
1762ff6b91eSJuan Quintelacpu=""
1773812c0c4SJoelle van Dynecross_compile="no"
1787d13299dSbellardcross_prefix=""
179e49d021eSPeter Maydellhost_cc="cc"
18013cf376cSPaolo BonziniEXTRA_CFLAGS=""
18113cf376cSPaolo BonziniEXTRA_CXXFLAGS=""
18213cf376cSPaolo BonziniEXTRA_OBJCFLAGS=""
18313cf376cSPaolo BonziniEXTRA_LDFLAGS=""
184377529c0SPaolo Bonzini
185377529c0SPaolo Bonzini# Default value for a variable defining feature "foo".
186377529c0SPaolo Bonzini#  * foo="no"  feature will only be used if --enable-foo arg is given
187377529c0SPaolo Bonzini#  * foo=""    feature will be searched for, and if found, will be used
188377529c0SPaolo Bonzini#              unless --disable-foo is given
189377529c0SPaolo Bonzini#  * foo="yes" this value will only be set by --enable-foo flag.
190377529c0SPaolo Bonzini#              feature will searched for,
191377529c0SPaolo Bonzini#              if not found, configure exits with error
192377529c0SPaolo Bonzini#
193377529c0SPaolo Bonzini# Always add --enable-foo and --disable-foo command line args.
194377529c0SPaolo Bonzini# Distributions want to ensure that several features are compiled in, and it
195377529c0SPaolo Bonzini# is impossible without a --enable-foo that exits if a feature is not found.
196c87ea116SAlex Bennéedefault_feature=""
197c87ea116SAlex Bennée
198ac0df51dSaliguorifor opt do
19989138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
200ac0df51dSaliguori  case "$opt" in
201ac0df51dSaliguori  --cross-prefix=*) cross_prefix="$optarg"
2023812c0c4SJoelle van Dyne                    cross_compile="yes"
203ac0df51dSaliguori  ;;
2043d8df640SPaolo Bonzini  --cc=*) CC="$optarg"
205ac0df51dSaliguori  ;;
20683f73fceSTomoki Sekiyama  --cxx=*) CXX="$optarg"
20783f73fceSTomoki Sekiyama  ;;
208c0c34c91SPeter Maydell  --objcc=*) objcc="$optarg"
209c0c34c91SPeter Maydell  ;;
2102ff6b91eSJuan Quintela  --cpu=*) cpu="$optarg"
2112ff6b91eSJuan Quintela  ;;
212a2866660SPaolo Bonzini  --extra-cflags=*)
213a2866660SPaolo Bonzini    EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
214a2866660SPaolo Bonzini    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
215e910c7d9SPhilippe Mathieu-Daudé    EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
216e2a2ed06SJuan Quintela    ;;
217a2866660SPaolo Bonzini  --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
21811cde1c8SBruno Dominguez  ;;
219e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
220e910c7d9SPhilippe Mathieu-Daudé  ;;
221a2866660SPaolo Bonzini  --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
222e2a2ed06SJuan Quintela  ;;
223d75402b5SAlex Bennée  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
224d75402b5SAlex Bennée  ;;
225479ca4ccSMatheus Ferst  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
226d422b2bcSAlex Bennée                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
227d422b2bcSAlex Bennée  ;;
228d75402b5SAlex Bennée  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
229d75402b5SAlex Bennée                eval "cross_cc_${cc_arch}=\$optarg"
230d75402b5SAlex Bennée  ;;
2315adb43beSPaolo Bonzini  --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-prefix-FOO option"
2325adb43beSPaolo Bonzini  ;;
2335adb43beSPaolo Bonzini  --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
2345adb43beSPaolo Bonzini                    eval "cross_prefix_${cc_arch}=\$optarg"
2355adb43beSPaolo Bonzini  ;;
23613cf376cSPaolo Bonzini  --without-default-features) default_feature="no"
23713cf376cSPaolo Bonzini  ;;
238ac0df51dSaliguori  esac
239ac0df51dSaliguoridone
240ac0df51dSaliguori
241bafe78adSPaolo Bonzinidefault_cflags='-O2 -g'
24213cf376cSPaolo Bonzinigit_submodules_action="update"
24313cf376cSPaolo Bonzinidocs="auto"
24413cf376cSPaolo BonziniEXESUF=""
24524f9c07aSPaolo Bonzinisystem="yes"
24613cf376cSPaolo Bonzinilinux_user=""
24713cf376cSPaolo Bonzinibsd_user=""
24813cf376cSPaolo Bonziniplugins="$default_feature"
2492a5919abSPaolo Bonzinisubdirs=""
25013cf376cSPaolo Bonzinininja=""
25113cf376cSPaolo Bonzinipython=
252ac4ccac7SPaolo Bonzinidownload="enabled"
25313cf376cSPaolo Bonziniskip_meson=no
25413cf376cSPaolo Bonziniuse_containers="yes"
25513cf376cSPaolo Bonzinigdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
25613cf376cSPaolo Bonzinigdb_arches=""
25713cf376cSPaolo Bonzini
25813cf376cSPaolo Bonzini# Don't accept a target_list environment variable.
25913cf376cSPaolo Bonziniunset target_list
26013cf376cSPaolo Bonziniunset target_list_exclude
26113cf376cSPaolo Bonzini
26213cf376cSPaolo Bonzini# The following Meson options are handled manually (still they
26313cf376cSPaolo Bonzini# are included in the automatically generated help message)
2642019cabfSPaolo Bonzini# because they automatically enable/disable other options
26513cf376cSPaolo Bonzinitcg="auto"
26613cf376cSPaolo Bonzinicfi="false"
26713cf376cSPaolo Bonzini
2682019cabfSPaolo Bonzini# Meson has PIE as a boolean rather than enabled/disabled/auto,
2692019cabfSPaolo Bonzini# and we also need to check for -static-pie before Meson runs
2702019cabfSPaolo Bonzini# which requires knowing whether --static is enabled.
27113cf376cSPaolo Bonzinipie=""
27213cf376cSPaolo Bonzinistatic="no"
27313cf376cSPaolo Bonzini
274e49d021eSPeter Maydell# Preferred compiler:
275e49d021eSPeter Maydell#  ${CC} (if set)
276e49d021eSPeter Maydell#  ${cross_prefix}gcc (if cross-prefix specified)
277e49d021eSPeter Maydell#  system compiler
278e49d021eSPeter Maydellif test -z "${CC}${cross_prefix}"; then
2793c7ee49bSPaolo Bonzini  cc="cc"
280e49d021eSPeter Maydellelse
281b3198cc2SStuart Yoder  cc="${CC-${cross_prefix}gcc}"
282e49d021eSPeter Maydellfi
283e49d021eSPeter Maydell
28483f73fceSTomoki Sekiyamaif test -z "${CXX}${cross_prefix}"; then
28583f73fceSTomoki Sekiyama  cxx="c++"
28683f73fceSTomoki Sekiyamaelse
28783f73fceSTomoki Sekiyama  cxx="${CXX-${cross_prefix}g++}"
28883f73fceSTomoki Sekiyamafi
28983f73fceSTomoki Sekiyama
290c0c34c91SPeter Maydell# Preferred ObjC compiler:
291c0c34c91SPeter Maydell# $objcc (if set, i.e. via --objcc option)
292c0c34c91SPeter Maydell# ${cross_prefix}clang (if cross-prefix specified)
293c0c34c91SPeter Maydell# clang (if available)
294c0c34c91SPeter Maydell# $cc
295c0c34c91SPeter Maydellif test -z "${objcc}${cross_prefix}"; then
296c0c34c91SPeter Maydell  if has clang; then
297c0c34c91SPeter Maydell    objcc=clang
298c0c34c91SPeter Maydell  else
299c0c34c91SPeter Maydell    objcc="$cc"
300c0c34c91SPeter Maydell  fi
301c0c34c91SPeter Maydellelse
302c0c34c91SPeter Maydell  objcc="${objcc-${cross_prefix}clang}"
303c0c34c91SPeter Maydellfi
304c0c34c91SPeter Maydell
305b3198cc2SStuart Yoderar="${AR-${cross_prefix}ar}"
306cdbd727cSRichard Hendersonas="${AS-${cross_prefix}as}"
3075f6f0e27SRichard Hendersonccas="${CCAS-$cc}"
30809f17983SAlex Bennéedlltool="${DLLTOOL-${cross_prefix}dlltool}"
309b3198cc2SStuart Yoderobjcopy="${OBJCOPY-${cross_prefix}objcopy}"
310b3198cc2SStuart Yoderld="${LD-${cross_prefix}ld}"
3119f81aeb5SAlistair Francisranlib="${RANLIB-${cross_prefix}ranlib}"
3124852ee95SStefan Weilnm="${NM-${cross_prefix}nm}"
313b3198cc2SStuart Yoderstrip="${STRIP-${cross_prefix}strip}"
314158bb224SKonstantin Kostiukwidl="${WIDL-${cross_prefix}widl}"
315b3198cc2SStuart Yoderwindres="${WINDRES-${cross_prefix}windres}"
316f9f0e617SAndrey Drobyshevwindmc="${WINDMC-${cross_prefix}windmc}"
317877c5567SPaolo Bonzinipkg_config="${PKG_CONFIG-${cross_prefix}pkg-config}"
31847c03744SDave Airliesdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
319ac0df51dSaliguori
320ac0df51dSaliguoricheck_define() {
321ac0df51dSaliguoricat > $TMPC <<EOF
322ac0df51dSaliguori#if !defined($1)
323fd786e1aSPeter Maydell#error $1 not defined
324ac0df51dSaliguori#endif
325ac0df51dSaliguoriint main(void) { return 0; }
326ac0df51dSaliguoriEOF
32752166aa0SJuan Quintela  compile_object
328ac0df51dSaliguori}
329ac0df51dSaliguori
33093b25869SJohn Snowwrite_c_skeleton() {
33193b25869SJohn Snow    cat > $TMPC <<EOF
33293b25869SJohn Snowint main(void) { return 0; }
33393b25869SJohn SnowEOF
33493b25869SJohn Snow}
33593b25869SJohn Snow
336bbea4050SPeter Maydellif check_define __linux__ ; then
337d0cda6f4SPaolo Bonzini  host_os=linux
338bbea4050SPeter Maydellelif check_define _WIN32 ; then
339d0cda6f4SPaolo Bonzini  host_os=windows
340bbea4050SPeter Maydellelif check_define __OpenBSD__ ; then
341d0cda6f4SPaolo Bonzini  host_os=openbsd
342bbea4050SPeter Maydellelif check_define __sun__ ; then
343d0cda6f4SPaolo Bonzini  host_os=sunos
344bbea4050SPeter Maydellelif check_define __HAIKU__ ; then
345d0cda6f4SPaolo Bonzini  host_os=haiku
346951fedfcSPeter Maydellelif check_define __FreeBSD__ ; then
347d0cda6f4SPaolo Bonzini  host_os=freebsd
348951fedfcSPeter Maydellelif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
349d0cda6f4SPaolo Bonzini  host_os=gnu/kfreebsd
350951fedfcSPeter Maydellelif check_define __DragonFly__ ; then
351d0cda6f4SPaolo Bonzini  host_os=dragonfly
352951fedfcSPeter Maydellelif check_define __NetBSD__; then
353d0cda6f4SPaolo Bonzini  host_os=netbsd
354951fedfcSPeter Maydellelif check_define __APPLE__; then
355d0cda6f4SPaolo Bonzini  host_os=darwin
356bbea4050SPeter Maydellelse
357951fedfcSPeter Maydell  # This is a fatal error, but don't report it yet, because we
358951fedfcSPeter Maydell  # might be going to just print the --help text, or it might
359951fedfcSPeter Maydell  # be the result of a missing compiler.
360d0cda6f4SPaolo Bonzini  host_os=bogus
361bbea4050SPeter Maydellfi
362bbea4050SPeter Maydell
3632ff6b91eSJuan Quintelaif test ! -z "$cpu" ; then
3642ff6b91eSJuan Quintela  # command line argument
3652ff6b91eSJuan Quintela  :
3662ff6b91eSJuan Quintelaelif check_define __i386__ ; then
367ac0df51dSaliguori  cpu="i386"
368ac0df51dSaliguorielif check_define __x86_64__ ; then
369c72b26ecSRichard Henderson  if check_define __ILP32__ ; then
370c72b26ecSRichard Henderson    cpu="x32"
371c72b26ecSRichard Henderson  else
372ac0df51dSaliguori    cpu="x86_64"
373c72b26ecSRichard Henderson  fi
3743aa9bd6cSblueswir1elif check_define __sparc__ ; then
3753aa9bd6cSblueswir1  if check_define __arch64__ ; then
3763aa9bd6cSblueswir1    cpu="sparc64"
3773aa9bd6cSblueswir1  else
3783aa9bd6cSblueswir1    cpu="sparc"
3793aa9bd6cSblueswir1  fi
380fdf7ed96Smalcelif check_define _ARCH_PPC ; then
381fdf7ed96Smalc  if check_define _ARCH_PPC64 ; then
382f8378accSRichard Henderson    if check_define _LITTLE_ENDIAN ; then
383f8378accSRichard Henderson      cpu="ppc64le"
384f8378accSRichard Henderson    else
385fdf7ed96Smalc      cpu="ppc64"
386f8378accSRichard Henderson    fi
387ac0df51dSaliguori  else
388fdf7ed96Smalc    cpu="ppc"
389fdf7ed96Smalc  fi
390afa05235SAurelien Jarnoelif check_define __mips__ ; then
391afa05235SAurelien Jarno  cpu="mips"
392d66ed0eaSAurelien Jarnoelif check_define __s390__ ; then
393d66ed0eaSAurelien Jarno  if check_define __s390x__ ; then
394d66ed0eaSAurelien Jarno    cpu="s390x"
395d66ed0eaSAurelien Jarno  else
396d66ed0eaSAurelien Jarno    cpu="s390"
397d66ed0eaSAurelien Jarno  fi
398c4f80543SAlistair Franciselif check_define __riscv ; then
399e3e477c3SPhilippe Mathieu-Daudé  if check_define _LP64 ; then
400e3e477c3SPhilippe Mathieu-Daudé    cpu="riscv64"
401e3e477c3SPhilippe Mathieu-Daudé  else
402e3e477c3SPhilippe Mathieu-Daudé    cpu="riscv32"
403e3e477c3SPhilippe Mathieu-Daudé  fi
40421d89f84SPeter Maydellelif check_define __arm__ ; then
40521d89f84SPeter Maydell  cpu="arm"
4061f080313SClaudio Fontanaelif check_define __aarch64__ ; then
4071f080313SClaudio Fontana  cpu="aarch64"
408dfcf900bSWANG Xueruielif check_define __loongarch64 ; then
409dfcf900bSWANG Xuerui  cpu="loongarch64"
410fdf7ed96Smalcelse
411f9c77801SPaolo Bonzini  # Using uname is really broken, but it is just a fallback for architectures
412f9c77801SPaolo Bonzini  # that are going to use TCI anyway
41389138857SStefan Weil  cpu=$(uname -m)
414371d60dfSThomas Huth  if test "$host_os" != "bogus"; then
415f9c77801SPaolo Bonzini    echo "WARNING: unrecognized host CPU, proceeding with 'uname -m' output '$cpu'"
416ac0df51dSaliguori  fi
417371d60dfSThomas Huthfi
418ac0df51dSaliguori
419971fac27SPaolo Bonzini# Normalise host CPU name to the values used by Meson cross files and in source
420971fac27SPaolo Bonzini# directories, and set multilib cflags.  The canonicalization isn't really
421971fac27SPaolo Bonzini# necessary, because the architectures that we check for should not hit the
422971fac27SPaolo Bonzini# 'uname -m' case, but better safe than sorry in case --cpu= is used.
423971fac27SPaolo Bonzini#
424359bc95dSPeter Maydell# Note that this case should only have supported host CPUs, not guests.
425971fac27SPaolo Bonzini# Please keep it sorted and synchronized with meson.build's host_arch.
426971fac27SPaolo Bonzinihost_arch=
427971fac27SPaolo Bonzinilinux_arch=
4287d13299dSbellardcase "$cpu" in
429971fac27SPaolo Bonzini  aarch64)
430971fac27SPaolo Bonzini    host_arch=aarch64
431971fac27SPaolo Bonzini    linux_arch=arm64
432971fac27SPaolo Bonzini    ;;
433971fac27SPaolo Bonzini
434e4da0e39SPaolo Bonzini  armv*b|armv*l|arm)
435971fac27SPaolo Bonzini    cpu=arm
436971fac27SPaolo Bonzini    host_arch=arm
437971fac27SPaolo Bonzini    linux_arch=arm
438971fac27SPaolo Bonzini    ;;
439e4da0e39SPaolo Bonzini
440f9c77801SPaolo Bonzini  i386|i486|i586|i686)
44197a847bcSbellard    cpu="i386"
442971fac27SPaolo Bonzini    host_arch=i386
443971fac27SPaolo Bonzini    linux_arch=x86
444971fac27SPaolo Bonzini    CPU_CFLAGS="-m32"
445971fac27SPaolo Bonzini    ;;
446971fac27SPaolo Bonzini
447971fac27SPaolo Bonzini  loongarch*)
448971fac27SPaolo Bonzini    cpu=loongarch64
449971fac27SPaolo Bonzini    host_arch=loongarch64
4507ec5d7d9SBibo Mao    linux_arch=loongarch
451971fac27SPaolo Bonzini    ;;
452971fac27SPaolo Bonzini
453b1fbee45SPaolo Bonzini  mips64*|mipsisa64*)
454971fac27SPaolo Bonzini    cpu=mips64
455971fac27SPaolo Bonzini    host_arch=mips
456971fac27SPaolo Bonzini    linux_arch=mips
457971fac27SPaolo Bonzini    ;;
458971fac27SPaolo Bonzini  mips*)
459971fac27SPaolo Bonzini    cpu=mips
460971fac27SPaolo Bonzini    host_arch=mips
461971fac27SPaolo Bonzini    linux_arch=mips
462971fac27SPaolo Bonzini    ;;
463971fac27SPaolo Bonzini
464971fac27SPaolo Bonzini  ppc)
465971fac27SPaolo Bonzini    host_arch=ppc
466971fac27SPaolo Bonzini    linux_arch=powerpc
467971fac27SPaolo Bonzini    CPU_CFLAGS="-m32"
468971fac27SPaolo Bonzini    ;;
469971fac27SPaolo Bonzini  ppc64)
470971fac27SPaolo Bonzini    host_arch=ppc64
471971fac27SPaolo Bonzini    linux_arch=powerpc
472971fac27SPaolo Bonzini    CPU_CFLAGS="-m64 -mbig-endian"
473971fac27SPaolo Bonzini    ;;
474971fac27SPaolo Bonzini  ppc64le)
475971fac27SPaolo Bonzini    cpu=ppc64
476971fac27SPaolo Bonzini    host_arch=ppc64
477971fac27SPaolo Bonzini    linux_arch=powerpc
478971fac27SPaolo Bonzini    CPU_CFLAGS="-m64 -mlittle-endian"
479971fac27SPaolo Bonzini    ;;
480971fac27SPaolo Bonzini
481971fac27SPaolo Bonzini  riscv32 | riscv64)
482971fac27SPaolo Bonzini    host_arch=riscv
483971fac27SPaolo Bonzini    linux_arch=riscv
484971fac27SPaolo Bonzini    ;;
485971fac27SPaolo Bonzini
486971fac27SPaolo Bonzini  s390)
487971fac27SPaolo Bonzini    linux_arch=s390
488971fac27SPaolo Bonzini    CPU_CFLAGS="-m31"
489971fac27SPaolo Bonzini    ;;
490971fac27SPaolo Bonzini  s390x)
491971fac27SPaolo Bonzini    host_arch=s390x
492971fac27SPaolo Bonzini    linux_arch=s390
493971fac27SPaolo Bonzini    CPU_CFLAGS="-m64"
494971fac27SPaolo Bonzini    ;;
495971fac27SPaolo Bonzini
496971fac27SPaolo Bonzini  sparc|sun4[cdmuv])
497971fac27SPaolo Bonzini    cpu=sparc
498971fac27SPaolo Bonzini    CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc"
499971fac27SPaolo Bonzini    ;;
500971fac27SPaolo Bonzini  sparc64)
501971fac27SPaolo Bonzini    host_arch=sparc64
502971fac27SPaolo Bonzini    CPU_CFLAGS="-m64 -mcpu=ultrasparc"
503971fac27SPaolo Bonzini    ;;
504971fac27SPaolo Bonzini
505e4da0e39SPaolo Bonzini  x32)
5064da270beSPaolo Bonzini    cpu="x86_64"
507971fac27SPaolo Bonzini    host_arch=x86_64
508971fac27SPaolo Bonzini    linux_arch=x86
509971fac27SPaolo Bonzini    CPU_CFLAGS="-mx32"
510971fac27SPaolo Bonzini    ;;
511aaa5fa14Saurel32  x86_64|amd64)
512aaa5fa14Saurel32    cpu="x86_64"
513971fac27SPaolo Bonzini    host_arch=x86_64
514971fac27SPaolo Bonzini    linux_arch=x86
515c2bf2ccbSArtyom Kunakovsky    CPU_CFLAGS="-m64"
516971fac27SPaolo Bonzini    ;;
5177d13299dSbellardesac
518e2d52ad3SJuan Quintela
519971fac27SPaolo Bonziniif test -n "$host_arch" && {
520971fac27SPaolo Bonzini    ! test -d "$source_path/linux-user/include/host/$host_arch" ||
521971fac27SPaolo Bonzini    ! test -d "$source_path/common-user/host/$host_arch"; }; then
522971fac27SPaolo Bonzini    error_exit "linux-user/include/host/$host_arch does not exist." \
523971fac27SPaolo Bonzini       "This is a bug in the configure script, please report it."
524971fac27SPaolo Bonzinifi
525971fac27SPaolo Bonziniif test -n "$linux_arch" && ! test -d "$source_path/linux-headers/asm-$linux_arch"; then
526971fac27SPaolo Bonzini    error_exit "linux-headers/asm-$linux_arch does not exist." \
527971fac27SPaolo Bonzini       "This is a bug in the configure script, please report it."
528971fac27SPaolo Bonzinifi
529971fac27SPaolo Bonzini
530fee6d412SJohn Snowcheck_py_version() {
531ca056f44SPaolo Bonzini    # We require python >= 3.8.
532fee6d412SJohn Snow    # NB: a True python conditional creates a non-zero return code (Failure)
533ca056f44SPaolo Bonzini    "$1" -c 'import sys; sys.exit(sys.version_info < (3,8))'
534fee6d412SJohn Snow}
535fee6d412SJohn Snow
536fee6d412SJohn Snowfirst_python=
537fee6d412SJohn Snowif test -z "${PYTHON}"; then
538fee6d412SJohn Snow    # A bare 'python' is traditionally python 2.x, but some distros
539fee6d412SJohn Snow    # have it as python 3.x, so check in both places.
54019a39e27SJohn Snow    for binary in python3 python python3.12 python3.11 \
54119a39e27SJohn Snow                          python3.10 python3.9 python3.8; do
542fee6d412SJohn Snow        if has "$binary"; then
54395c5f2deSPaolo Bonzini            python=$(command -v "$binary")
544fee6d412SJohn Snow            if check_py_version "$python"; then
545fee6d412SJohn Snow                # This one is good.
546fee6d412SJohn Snow                first_python=
547faf44142SDaniel P. Berrangé                break
548fee6d412SJohn Snow            else
549fee6d412SJohn Snow                first_python=$python
550fee6d412SJohn Snow            fi
551faf44142SDaniel P. Berrangé        fi
552faf44142SDaniel P. Berrangé    done
553fee6d412SJohn Snowelse
554fee6d412SJohn Snow    # Same as above, but only check the environment variable.
555fee6d412SJohn Snow    has "${PYTHON}" || error_exit "The PYTHON environment variable does not point to an executable"
556fee6d412SJohn Snow    python=$(command -v "$PYTHON")
557fee6d412SJohn Snow    if check_py_version "$python"; then
558fee6d412SJohn Snow        # This one is good.
559fee6d412SJohn Snow        first_python=
560fee6d412SJohn Snow    else
561fee6d412SJohn Snow        first_python=$first_python
562fee6d412SJohn Snow    fi
563fee6d412SJohn Snowfi
564903458c8SMarkus Armbruster
56539d87c8cSAlex Bennée# Check for ancillary tools used in testing
56639d87c8cSAlex Bennéegenisoimage=
5673df437c7SAlex Bennéefor binary in genisoimage mkisofs
56839d87c8cSAlex Bennéedo
56939d87c8cSAlex Bennée    if has $binary
57039d87c8cSAlex Bennée    then
57139d87c8cSAlex Bennée        genisoimage=$(command -v "$binary")
57239d87c8cSAlex Bennée        break
57339d87c8cSAlex Bennée    fi
57439d87c8cSAlex Bennéedone
57539d87c8cSAlex Bennée
576d0cda6f4SPaolo Bonziniif test "$host_os" = "windows" ; then
5773457a3f8SJuan Quintela  EXESUF=".exe"
5783457a3f8SJuan Quintelafi
5793457a3f8SJuan Quintela
5808154f5e6SAkihiko Odakimeson_option_build_array() {
5818154f5e6SAkihiko Odaki  printf '['
582d0cda6f4SPaolo Bonzini  (if test "$host_os" = windows; then
5838154f5e6SAkihiko Odaki    IFS=\;
5848154f5e6SAkihiko Odaki  else
5858154f5e6SAkihiko Odaki    IFS=:
5868154f5e6SAkihiko Odaki  fi
5878154f5e6SAkihiko Odaki  for e in $1; do
58865842b03SPeter Maydell    printf '"""'
58965842b03SPeter Maydell    # backslash escape any '\' and '"' characters
59065842b03SPeter Maydell    printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g'
59165842b03SPeter Maydell    printf '""",'
5928154f5e6SAkihiko Odaki  done)
5938154f5e6SAkihiko Odaki  printf ']\n'
5948154f5e6SAkihiko Odaki}
5958154f5e6SAkihiko Odaki
59664708615SPeter Maydell. "$source_path/scripts/meson-buildoptions.sh"
59761d63097SPaolo Bonzini
59861d63097SPaolo Bonzinimeson_options=
599c54b59eeSPaolo Bonzinimeson_option_add() {
600ae22ae65SPaolo Bonzini  local arg
601ae22ae65SPaolo Bonzini  for arg; do
602ae22ae65SPaolo Bonzini    meson_options="$meson_options $(quote_sh "$arg")"
603ae22ae65SPaolo Bonzini  done
604c54b59eeSPaolo Bonzini}
60561d63097SPaolo Bonzinimeson_option_parse() {
60661d63097SPaolo Bonzini  meson_options="$meson_options $(_meson_option_parse "$@")"
60761d63097SPaolo Bonzini  if test $? -eq 1; then
60861d63097SPaolo Bonzini    echo "ERROR: unknown option $1"
60961d63097SPaolo Bonzini    echo "Try '$0 --help' for more information"
61061d63097SPaolo Bonzini    exit 1
61161d63097SPaolo Bonzini  fi
61261d63097SPaolo Bonzini}
61361d63097SPaolo Bonzini
614c36dd41bSPaolo Bonzinimeson_add_machine_file() {
615c36dd41bSPaolo Bonzini  if test "$cross_compile" = "yes"; then
616c36dd41bSPaolo Bonzini    meson_option_add --cross-file "$1"
617c36dd41bSPaolo Bonzini  else
618c36dd41bSPaolo Bonzini    meson_option_add --native-file "$1"
619c36dd41bSPaolo Bonzini  fi
620c36dd41bSPaolo Bonzini}
621c36dd41bSPaolo Bonzini
6227d13299dSbellardfor opt do
62389138857SStefan Weil  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
6247d13299dSbellard  case "$opt" in
6252efc3265Sbellard  --help|-h) show_help=yes
6262efc3265Sbellard  ;;
62764708615SPeter Maydell  --version|-V) exec cat "$source_path/VERSION"
62899123e13SMike Frysinger  ;;
629ac0df51dSaliguori  --cross-prefix=*)
6307d13299dSbellard  ;;
631ac0df51dSaliguori  --cc=*)
6327d13299dSbellard  ;;
633b1a550a0Spbrook  --host-cc=*) host_cc="$optarg"
63483469015Sbellard  ;;
63583f73fceSTomoki Sekiyama  --cxx=*)
63683f73fceSTomoki Sekiyama  ;;
637c0c34c91SPeter Maydell  --objcc=*)
6383c4a4d0dSPeter Maydell  ;;
639b17bbf83SPaolo Bonzini  --make=*)
6407d13299dSbellard  ;;
641b6daf4d3SPaolo Bonzini  --install=*)
6426a882643Spbrook  ;;
64381e2b198SJohn Snow  --python=*) python="$optarg"
644c886edfbSBlue Swirl  ;;
645a5665051SPaolo Bonzini  --skip-meson) skip_meson=yes
646a5665051SPaolo Bonzini  ;;
64748328880SPaolo Bonzini  --ninja=*) ninja="$optarg"
64848328880SPaolo Bonzini  ;;
649e2a2ed06SJuan Quintela  --extra-cflags=*)
6507d13299dSbellard  ;;
65111cde1c8SBruno Dominguez  --extra-cxxflags=*)
65211cde1c8SBruno Dominguez  ;;
653e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=*)
654e910c7d9SPhilippe Mathieu-Daudé  ;;
655e2a2ed06SJuan Quintela  --extra-ldflags=*)
6567d13299dSbellard  ;;
657d75402b5SAlex Bennée  --cross-cc-*)
658d75402b5SAlex Bennée  ;;
6595adb43beSPaolo Bonzini  --cross-prefix-*)
6605adb43beSPaolo Bonzini  ;;
6616b0cedcdSJohn Snow  --enable-docs) docs=enabled
6626b0cedcdSJohn Snow  ;;
6636b0cedcdSJohn Snow  --disable-docs) docs=disabled
6646b0cedcdSJohn Snow  ;;
6652ff6b91eSJuan Quintela  --cpu=*)
6667d13299dSbellard  ;;
667b1a550a0Spbrook  --target-list=*) target_list="$optarg"
668447e133fSAlex Bennée                   if test "$target_list_exclude"; then
669447e133fSAlex Bennée                       error_exit "Can't mix --target-list with --target-list-exclude"
670447e133fSAlex Bennée                   fi
671447e133fSAlex Bennée  ;;
672447e133fSAlex Bennée  --target-list-exclude=*) target_list_exclude="$optarg"
673447e133fSAlex Bennée                   if test "$target_list"; then
674447e133fSAlex Bennée                       error_exit "Can't mix --target-list-exclude with --target-list"
675447e133fSAlex Bennée                   fi
676de83cd02Sbellard  ;;
677c54b59eeSPaolo Bonzini  --with-default-devices) meson_option_add -Ddefault_devices=true
678f3494749SPaolo Bonzini  ;;
679c54b59eeSPaolo Bonzini  --without-default-devices) meson_option_add -Ddefault_devices=false
680f3494749SPaolo Bonzini  ;;
681d1d5e9eeSAlex Bennée  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
682d1d5e9eeSAlex Bennée  ;;
683d1d5e9eeSAlex Bennée  --with-devices-*) device_arch=${opt#--with-devices-};
684d1d5e9eeSAlex Bennée                    device_arch=${device_arch%%=*}
685d1d5e9eeSAlex Bennée                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
686d1d5e9eeSAlex Bennée                    if test -f "$cf"; then
687d1d5e9eeSAlex Bennée                        device_archs="$device_archs $device_arch"
688d1d5e9eeSAlex Bennée                        eval "devices_${device_arch}=\$optarg"
689d1d5e9eeSAlex Bennée                    else
690d1d5e9eeSAlex Bennée                        error_exit "File $cf does not exist"
691d1d5e9eeSAlex Bennée                    fi
692d1d5e9eeSAlex Bennée  ;;
693c87ea116SAlex Bennée  --without-default-features) # processed above
694c87ea116SAlex Bennée  ;;
695877c5567SPaolo Bonzini  --static) static="yes"
69643ce4dfeSbellard  ;;
697181ce1d0SOlaf Hering  --host=*|--build=*|\
698181ce1d0SOlaf Hering  --disable-dependency-tracking|\
699785c23aeSLuiz Capitulino  --sbindir=*|--sharedstatedir=*|\
700fe0038beSPaolo Bonzini  --oldincludedir=*|--datarootdir=*|--infodir=*|\
701023ddd74SMax Filippov  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
702023ddd74SMax Filippov    # These switches are silently ignored, for compatibility with
703023ddd74SMax Filippov    # autoconf-generated configure scripts. This allows QEMU's
704023ddd74SMax Filippov    # configure to be used by RPM and similar macros that set
705023ddd74SMax Filippov    # lots of directory switches by default.
706023ddd74SMax Filippov  ;;
707f3d08ee6SPaul Brook  --enable-debug)
708f3d08ee6SPaul Brook      # Enable debugging options that aren't excessively noisy
7091d558c90SPaolo Bonzini      meson_option_parse --enable-debug-tcg ""
71058a2e3f5SStefan Hajnoczi      meson_option_parse --enable-debug-graph-lock ""
711c55cf6abSPaolo Bonzini      meson_option_parse --enable-debug-mutex ""
712c54b59eeSPaolo Bonzini      meson_option_add -Doptimization=0
713bafe78adSPaolo Bonzini      default_cflags='-O0 -g'
7140aebab04SLingfeng Yang  ;;
7151badb709SPaolo Bonzini  --disable-tcg) tcg="disabled"
716b3f6ea7eSPaolo Bonzini  ;;
7171badb709SPaolo Bonzini  --enable-tcg) tcg="enabled"
718b3f6ea7eSPaolo Bonzini  ;;
71924f9c07aSPaolo Bonzini  --disable-system) system="no"
7200a8e90f4Spbrook  ;;
72124f9c07aSPaolo Bonzini  --enable-system) system="yes"
7220a8e90f4Spbrook  ;;
7230953a80fSZachary Amsden  --disable-user)
7240953a80fSZachary Amsden      linux_user="no" ;
7250953a80fSZachary Amsden      bsd_user="no" ;
7260953a80fSZachary Amsden  ;;
7270953a80fSZachary Amsden  --enable-user) ;;
728831b7825Sths  --disable-linux-user) linux_user="no"
7290a8e90f4Spbrook  ;;
730831b7825Sths  --enable-linux-user) linux_user="yes"
731831b7825Sths  ;;
73284778508Sblueswir1  --disable-bsd-user) bsd_user="no"
73384778508Sblueswir1  ;;
73484778508Sblueswir1  --enable-bsd-user) bsd_user="yes"
73584778508Sblueswir1  ;;
73640d6444eSAvi Kivity  --enable-pie) pie="yes"
73734005a00SKirill A. Shutemov  ;;
73840d6444eSAvi Kivity  --disable-pie) pie="no"
73934005a00SKirill A. Shutemov  ;;
740ae22ae65SPaolo Bonzini  --enable-cfi) cfi=true
7419e62ba48SDaniele Buono  ;;
742ae22ae65SPaolo Bonzini  --disable-cfi) cfi=false
7439e62ba48SDaniele Buono  ;;
7446f3ae23bSPaolo Bonzini  --disable-download) download="disabled"; git_submodules_action=validate;
745f62bbee5SDaniel P. Berrange  ;;
7466f3ae23bSPaolo Bonzini  --enable-download) download="enabled"; git_submodules_action=update;
7470c5f3dcbSJohn Snow  ;;
74839fb3cfcSPaolo Bonzini  --enable-plugins) plugins="yes"
74940e8c6f4SAlex Bennée  ;;
75040e8c6f4SAlex Bennée  --disable-plugins) plugins="no"
75140e8c6f4SAlex Bennée  ;;
752afc3a8f9SAlex Bennée  --enable-containers) use_containers="yes"
753afc3a8f9SAlex Bennée  ;;
754afc3a8f9SAlex Bennée  --disable-containers) use_containers="no"
755afc3a8f9SAlex Bennée  ;;
75642ede11aSAlex Bennée  --container-engine=*) container_engine="$optarg"
75742ede11aSAlex Bennée  ;;
758f48e590aSAlex Bennée  --gdb=*) gdb_bin="$optarg"
759f48e590aSAlex Bennée  ;;
7603b4da132SPaolo Bonzini  # everything else has the same name in configure and meson
7614fda6011SPaolo Bonzini  --*) meson_option_parse "$opt" "$optarg"
7627f1559c6Sbalrog  ;;
763ff136d2aSDaniel P. Berrangé  # Pass through -Dxxxx options to meson
76423b1f53cSPaolo Bonzini  -D*) meson_option_add "$opt"
765ff136d2aSDaniel P. Berrangé  ;;
7667d13299dSbellard  esac
7677d13299dSbellarddone
7687d13299dSbellard
7696f3ae23bSPaolo Bonziniif ! test -e "$source_path/.git"
7706f3ae23bSPaolo Bonzinithen
7718edddaa2SPaolo Bonzini    git_submodules_action="validate"
7726f3ae23bSPaolo Bonzinifi
7736f3ae23bSPaolo Bonzini
7742019cabfSPaolo Bonziniif ! test -f "$source_path/subprojects/keycodemapdb/README" \
775c06b1571SMichal Privoznik    && test "$download" = disabled
7762019cabfSPaolo Bonzinithen
7772019cabfSPaolo Bonzini    echo
7782019cabfSPaolo Bonzini    echo "ERROR: missing subprojects"
7792019cabfSPaolo Bonzini    echo
7802019cabfSPaolo Bonzini    if test -e "$source_path/.git"; then
7812019cabfSPaolo Bonzini        echo "--disable-download specified but subprojects were not"
7822019cabfSPaolo Bonzini        echo 'checked out.  Please invoke "meson subprojects download"'
7832019cabfSPaolo Bonzini        echo "before configuring QEMU, or remove --disable-download"
7842019cabfSPaolo Bonzini        echo "from the command line."
7852019cabfSPaolo Bonzini    else
7862019cabfSPaolo Bonzini        echo "This is not a GIT checkout but subproject content appears to"
7872019cabfSPaolo Bonzini        echo "be missing. Do not use 'git archive' or GitHub download links"
7882019cabfSPaolo Bonzini        echo "to acquire QEMU source archives. Non-GIT builds are only"
7892019cabfSPaolo Bonzini        echo "supported with source archives linked from:"
7902019cabfSPaolo Bonzini        echo
7912019cabfSPaolo Bonzini        echo "  https://www.qemu.org/download/#source"
7922019cabfSPaolo Bonzini        echo
7932019cabfSPaolo Bonzini        echo "Developers working with GIT can use scripts/archive-source.sh"
7942019cabfSPaolo Bonzini        echo "if they need to create valid source archives."
7952019cabfSPaolo Bonzini    fi
7962019cabfSPaolo Bonzini    echo
7972019cabfSPaolo Bonzini    exit 1
7982019cabfSPaolo Bonzinifi
7992019cabfSPaolo Bonzini
80060e0df25SPeter Maydelldefault_target_list=""
8016e92f823SPeter Maydellmak_wilds=""
8026e92f823SPeter Maydell
803473cd070SPaolo Bonziniif [ -n "$host_arch" ] && [ -d "$source_path/common-user/host/$host_arch" ]; then
804b915a2f1SPaolo Bonzini    if [ "$linux_user" != no ]; then
805d0cda6f4SPaolo Bonzini        if [ "$host_os" = linux ]; then
806b915a2f1SPaolo Bonzini            linux_user=yes
807b915a2f1SPaolo Bonzini        elif [ "$linux_user" = yes ]; then
808b915a2f1SPaolo Bonzini            error_exit "linux-user not supported on this architecture"
809b915a2f1SPaolo Bonzini        fi
810473cd070SPaolo Bonzini        if [ "$linux_user" = "yes" ]; then
811473cd070SPaolo Bonzini            mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
812473cd070SPaolo Bonzini        fi
813b915a2f1SPaolo Bonzini    fi
814b915a2f1SPaolo Bonzini    if [ "$bsd_user" != no ]; then
815b915a2f1SPaolo Bonzini        if [ "$bsd_user" = "" ]; then
816d0cda6f4SPaolo Bonzini            test $host_os = freebsd && bsd_user=yes
817b915a2f1SPaolo Bonzini        fi
818d0cda6f4SPaolo Bonzini        if [ "$bsd_user" = yes ] && ! [ -d "$source_path/bsd-user/$host_os" ]; then
819b915a2f1SPaolo Bonzini            error_exit "bsd-user not supported on this host OS"
820b915a2f1SPaolo Bonzini        fi
821473cd070SPaolo Bonzini        if [ "$bsd_user" = "yes" ]; then
822473cd070SPaolo Bonzini            mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
823473cd070SPaolo Bonzini        fi
824473cd070SPaolo Bonzini    fi
825473cd070SPaolo Bonzinielse
826473cd070SPaolo Bonzini    if [ "$linux_user" = yes ] || [ "$bsd_user" = yes ]; then
827473cd070SPaolo Bonzini        error_exit "user mode emulation not supported on this architecture"
828473cd070SPaolo Bonzini    fi
829b915a2f1SPaolo Bonzinifi
83024f9c07aSPaolo Bonziniif [ "$system" = "yes" ]; then
831812b31d3SAlex Bennée    mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
83260e0df25SPeter Maydellfi
83360e0df25SPeter Maydell
834447e133fSAlex Bennéefor config in $mak_wilds; do
835447e133fSAlex Bennée    target="$(basename "$config" .mak)"
83698db9a06SAlex Bennée    if echo "$target_list_exclude" | grep -vq "$target"; then
837447e133fSAlex Bennée        default_target_list="${default_target_list} $target"
838447e133fSAlex Bennée    fi
839447e133fSAlex Bennéedone
8406e92f823SPeter Maydell
841af5db58eSpbrookif test x"$show_help" = x"yes" ; then
842af5db58eSpbrookcat << EOF
843af5db58eSpbrook
844af5db58eSpbrookUsage: configure [options]
845af5db58eSpbrookOptions: [defaults in brackets after descriptions]
846af5db58eSpbrook
84708fb77edSStefan WeilStandard options:
84808fb77edSStefan Weil  --help                   print this message
84974154d7eSThomas Huth  --target-list=LIST       set target list (default: build all)
85008fb77edSStefan Weil$(echo Available targets: $default_target_list | \
85108fb77edSStefan Weil  fold -s -w 53 | sed -e 's/^/                           /')
852447e133fSAlex Bennée  --target-list-exclude=LIST exclude a set of targets from the default target-list
85308fb77edSStefan Weil
85408fb77edSStefan WeilAdvanced options (experts only):
855ff136d2aSDaniel P. Berrangé  -Dmesonoptname=val       passthrough option to meson unmodified
8563812c0c4SJoelle van Dyne  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
85708fb77edSStefan Weil  --cc=CC                  use C compiler CC [$cc]
8583c7ee49bSPaolo Bonzini  --host-cc=CC             when cross compiling, use C compiler CC for code run
8593c7ee49bSPaolo Bonzini                           at build time [$host_cc]
86008fb77edSStefan Weil  --cxx=CXX                use C++ compiler CXX [$cxx]
86108fb77edSStefan Weil  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
862a2866660SPaolo Bonzini  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
863a2866660SPaolo Bonzini  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
864e910c7d9SPhilippe Mathieu-Daudé  --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
86508fb77edSStefan Weil  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
866d75402b5SAlex Bennée  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
867479ca4ccSMatheus Ferst  --cross-cc-cflags-ARCH=  use compiler flags when building ARCH guest tests
8685adb43beSPaolo Bonzini  --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
86908fb77edSStefan Weil  --python=PYTHON          use specified python [$python]
87048328880SPaolo Bonzini  --ninja=NINJA            use specified ninja [$ninja]
87108fb77edSStefan Weil  --static                 enable static build [$static]
872c035c8d6SPaolo Bonzini  --without-default-features default all --enable-* options to "disabled"
873c035c8d6SPaolo Bonzini  --without-default-devices  do not include any device that is not needed to
874c035c8d6SPaolo Bonzini                           start the emulator (only use if you are including
875d1d5e9eeSAlex Bennée                           desired devices in configs/devices/)
876d1d5e9eeSAlex Bennée  --with-devices-ARCH=NAME override default configs/devices
87708fb77edSStefan Weil  --enable-debug           enable common debug build options
878c23f23b9SMichael Tokarev  --cpu=CPU                Build for host CPU [$cpu]
879afc3a8f9SAlex Bennée  --disable-containers     don't use containers for cross-building
88042ede11aSAlex Bennée  --container-engine=TYPE  which container engine to use [$container_engine]
881f48e590aSAlex Bennée  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
88261d63097SPaolo BonziniEOF
88361d63097SPaolo Bonzini  meson_options_help
88461d63097SPaolo Bonzinicat << EOF
885c23f23b9SMichael Tokarev  system          all system emulation targets
886c23f23b9SMichael Tokarev  user            supported user emulation targets
887c23f23b9SMichael Tokarev  linux-user      all linux usermode emulation targets
888c23f23b9SMichael Tokarev  bsd-user        all BSD usermode emulation targets
889c23f23b9SMichael Tokarev  pie             Position Independent Executables
89008fb77edSStefan Weil
89108fb77edSStefan WeilNOTE: The object files are built at the place where configure is launched
892af5db58eSpbrookEOF
8932d2ad6d0SFam Zhengexit 0
894af5db58eSpbrookfi
895af5db58eSpbrook
896371d60dfSThomas Huth# Now that we are sure that the user did not only want to print the --help
897371d60dfSThomas Huth# information, we should double-check that the C compiler really works:
898371d60dfSThomas Huthwrite_c_skeleton
899371d60dfSThomas Huthif ! compile_object ; then
900371d60dfSThomas Huth    error_exit "C compiler \"$cc\" either does not exist or does not work."
901371d60dfSThomas Huthfi
902371d60dfSThomas Huth
9039c790242SThomas Huth# Remove old dependency files to make sure that they get properly regenerated
904002d8c13SPeter Maydellrm -f ./*/config-devices.mak.d
9059c790242SThomas Huth
906faf44142SDaniel P. Berrangéif test -z "$python"
907faf44142SDaniel P. Berrangéthen
908fee6d412SJohn Snow    # If first_python is set, there was a binary somewhere even though
909fee6d412SJohn Snow    # it was not suitable.  Use it for the error message.
910fee6d412SJohn Snow    if test -n "$first_python"; then
911761f241cSJohn Snow        error_exit "Cannot use '$first_python', Python >= 3.8 is required." \
912fee6d412SJohn Snow            "Use --python=/path/to/python to specify a supported Python."
913fee6d412SJohn Snow    else
914c53eeaf7SStefan Hajnoczi        error_exit "Python not found. Use --python=/path/to/python"
915c53eeaf7SStefan Hajnoczi    fi
916fee6d412SJohn Snowfi
917fee6d412SJohn Snow
918fee6d412SJohn Snowif ! check_py_version "$python"; then
919ca056f44SPaolo Bonzini  error_exit "Cannot use '$python', Python >= 3.8 is required." \
920e46b82a0SJohn Snow             "Use --python=/path/to/python to specify a supported Python." \
921e46b82a0SJohn Snow             "Maybe try:" \
922e46b82a0SJohn Snow             "  openSUSE Leap 15.3+: zypper install python39" \
923e46b82a0SJohn Snow             "  CentOS 8: dnf install python38"
924c53eeaf7SStefan Hajnoczifi
925c53eeaf7SStefan Hajnoczi
92681e2b198SJohn Snow# Resolve PATH
92781e2b198SJohn Snowpython="$(command -v "$python")"
92881e2b198SJohn Snow
92981e2b198SJohn Snow# Create a Python virtual environment using our configured python.
93081e2b198SJohn Snow# The stdout of this script will be the location of a symlink that
93181e2b198SJohn Snow# points to the configured Python.
93281e2b198SJohn Snow# Entry point scripts for pip, meson, and sphinx are generated if those
93381e2b198SJohn Snow# packages are present.
93481e2b198SJohn Snow
93581e2b198SJohn Snow# Defaults assumed for now:
93681e2b198SJohn Snow# - venv is cleared if it exists already;
93781e2b198SJohn Snow# - venv is allowed to use system packages;
9380c5f3dcbSJohn Snow# - all setup can be performed offline;
9390c5f3dcbSJohn Snow# - missing packages may be fetched from PyPI,
940ac4ccac7SPaolo Bonzini#   unless --disable-download is passed.
94181e2b198SJohn Snow# - pip is not installed into the venv when possible,
94281e2b198SJohn Snow#   but ensurepip is called as a fallback when necessary.
94381e2b198SJohn Snow
94481e2b198SJohn Snowecho "python determined to be '$python'"
94581e2b198SJohn Snowecho "python version: $($python --version)"
94681e2b198SJohn Snow
94781e2b198SJohn Snowpython="$($python -B "${source_path}/python/scripts/mkvenv.py" create pyvenv)"
94881e2b198SJohn Snowif test "$?" -ne 0 ; then
94981e2b198SJohn Snow    error_exit "python venv creation failed"
95081e2b198SJohn Snowfi
95181e2b198SJohn Snow
95281e2b198SJohn Snow# Suppress writing compiled files
95381e2b198SJohn Snowpython="$python -B"
9546f6652ebSJohn Snowmkvenv="$python ${source_path}/python/scripts/mkvenv.py"
955462a6567SPaolo Bonzini
956edc21078SPaolo Bonzini# Finish preparing the virtual environment using vendored .whl files
957edc21078SPaolo Bonzini
958c853c4d0SPaolo Bonzini$mkvenv ensuregroup --dir "${source_path}/python/wheels" \
959c853c4d0SPaolo Bonzini     ${source_path}/pythondeps.toml meson || exit 1
960a5665051SPaolo Bonzini
96166e2c6cbSJohn Snow# At this point, we expect Meson to be installed and available.
96266e2c6cbSJohn Snow# We expect mkvenv or pip to have created pyvenv/bin/meson for us.
96366e2c6cbSJohn Snow# We ignore PATH completely here: we want to use the venv's Meson
96466e2c6cbSJohn Snow# *exclusively*.
9650a01d76fSMarc-André Lureau
96666e2c6cbSJohn Snowmeson="$(cd pyvenv/bin; pwd)/meson"
9670a01d76fSMarc-André Lureau
9686f6652ebSJohn Snow# Conditionally ensure Sphinx is installed.
9696f6652ebSJohn Snow
970913e47cbSPaolo Bonzinimkvenv_online_flag=""
971913e47cbSPaolo Bonziniif test "$download" = "enabled" ; then
972913e47cbSPaolo Bonzini    mkvenv_online_flag=" --online"
9730c5f3dcbSJohn Snowfi
9740c5f3dcbSJohn Snow
9756f6652ebSJohn Snowif test "$docs" != "disabled" ; then
976c853c4d0SPaolo Bonzini    if ! $mkvenv ensuregroup \
977913e47cbSPaolo Bonzini         $(test "$docs" = "enabled" && echo "$mkvenv_online_flag") \
978c853c4d0SPaolo Bonzini         ${source_path}/pythondeps.toml docs;
9796f6652ebSJohn Snow    then
9806f6652ebSJohn Snow        if test "$docs" = "enabled" ; then
9816f6652ebSJohn Snow            exit 1
9826f6652ebSJohn Snow        fi
9836f6652ebSJohn Snow        echo "Sphinx not found/usable, disabling docs."
9846f6652ebSJohn Snow        docs=disabled
9856f6652ebSJohn Snow    else
9866f6652ebSJohn Snow        docs=enabled
9876f6652ebSJohn Snow    fi
9886f6652ebSJohn Snowfi
9896f6652ebSJohn Snow
99009e93326SPaolo Bonzini# Probe for ninja
99148328880SPaolo Bonzini
99248328880SPaolo Bonziniif test -z "$ninja"; then
99348328880SPaolo Bonzini    for c in ninja ninja-build samu; do
99448328880SPaolo Bonzini        if has $c; then
99548328880SPaolo Bonzini            ninja=$(command -v "$c")
99648328880SPaolo Bonzini            break
99748328880SPaolo Bonzini        fi
99848328880SPaolo Bonzini    done
99909e93326SPaolo Bonzini    if test -z "$ninja"; then
100009e93326SPaolo Bonzini      error_exit "Cannot find Ninja"
100109e93326SPaolo Bonzini    fi
100248328880SPaolo Bonzinifi
1003a5665051SPaolo Bonzini
1004d0cda6f4SPaolo Bonziniif test "$host_os" = "bogus"; then
1005fb59dabdSPeter Maydell    # Now that we know that we're not printing the help and that
1006fb59dabdSPeter Maydell    # the compiler works (so the results of the check_defines we used
1007fb59dabdSPeter Maydell    # to identify the OS are reliable), if we didn't recognize the
1008fb59dabdSPeter Maydell    # host OS we should stop now.
1009951fedfcSPeter Maydell    error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1010fb59dabdSPeter Maydellfi
1011fb59dabdSPeter Maydell
101239fb3cfcSPaolo Bonzini# test for any invalid configuration combinations
1013d0cda6f4SPaolo Bonziniif test "$host_os" = "windows" && ! has "$dlltool"; then
101439fb3cfcSPaolo Bonzini  if test "$plugins" = "yes"; then
101536fa0773SGreg Manning    error_exit "TCG plugins requires dlltool to build on Windows platforms"
101639fb3cfcSPaolo Bonzini  fi
101739fb3cfcSPaolo Bonzini  plugins="no"
101839fb3cfcSPaolo Bonzinifi
101939fb3cfcSPaolo Bonziniif test "$tcg" = "disabled" ; then
102039fb3cfcSPaolo Bonzini  if test "$plugins" = "yes"; then
102139fb3cfcSPaolo Bonzini    error_exit "Can't enable plugins on non-TCG builds"
102239fb3cfcSPaolo Bonzini  fi
102339fb3cfcSPaolo Bonzini  plugins="no"
102439fb3cfcSPaolo Bonzinifi
102540d6444eSAvi Kivityif test "$static" = "yes" ; then
10265f2453acSAlex Bennée  if test "$plugins" = "yes"; then
10275f2453acSAlex Bennée    error_exit "static and plugins are mutually incompatible"
102839fb3cfcSPaolo Bonzini  fi
1029ba4dd2aaSAlex Bennée  plugins="no"
10305f2453acSAlex Bennéefi
103139fb3cfcSPaolo Bonziniif test "$plugins" != "no"; then
103239fb3cfcSPaolo Bonzini  plugins=yes
10332a5919abSPaolo Bonzini  subdirs="$subdirs contrib/plugins"
10342a5919abSPaolo Bonzinifi
103540d6444eSAvi Kivity
103640d6444eSAvi Kivitycat > $TMPC << EOF
103721d4a791SAvi Kivity
103821d4a791SAvi Kivity#ifdef __linux__
103921d4a791SAvi Kivity#  define THREAD __thread
104021d4a791SAvi Kivity#else
104121d4a791SAvi Kivity#  define THREAD
104221d4a791SAvi Kivity#endif
104321d4a791SAvi Kivitystatic THREAD int tls_var;
104421d4a791SAvi Kivityint main(void) { return tls_var; }
104540d6444eSAvi KivityEOF
1046b2634124SRichard Henderson
1047d0cda6f4SPaolo Bonziniif test "$host_os" = windows || test "$host_os" = haiku; then
10482e938a9aSPaolo Bonzini  if test "$pie" = "yes"; then
10492e938a9aSPaolo Bonzini    error_exit "PIE not available due to missing OS support"
10502e938a9aSPaolo Bonzini  fi
10512e938a9aSPaolo Bonzini  pie=no
10522e938a9aSPaolo Bonzinifi
10532e938a9aSPaolo Bonzini
10542e938a9aSPaolo Bonziniif test "$pie" != "no"; then
105512781462SRichard Henderson  if test "$static" = "yes"; then
10562e938a9aSPaolo Bonzini    pie_ldflags=-static-pie
10572e938a9aSPaolo Bonzini  else
10582e938a9aSPaolo Bonzini    pie_ldflags=-pie
10592e938a9aSPaolo Bonzini  fi
10602e938a9aSPaolo Bonzini  if compile_prog "-Werror -fPIE -DPIE" "$pie_ldflags"; then
106112781462SRichard Henderson    pie="yes"
106212781462SRichard Henderson  elif test "$pie" = "yes"; then
106312781462SRichard Henderson    error_exit "-static-pie not available due to missing toolchain support"
106412781462SRichard Henderson  else
106540d6444eSAvi Kivity    echo "Disabling PIE due to missing toolchain support"
106640d6444eSAvi Kivity    pie="no"
106740d6444eSAvi Kivity  fi
1068a988b4c5SPaolo Bonzinifi
106940d6444eSAvi Kivity
107009dada40SPaolo Bonzini##########################################
107109dada40SPaolo Bonzini
1072afb63ebdSStefan Weilif test -z "${target_list+xxx}" ; then
1073fdb75aefSPaolo Bonzini    default_targets=yes
1074d880a3baSPaolo Bonzini    for target in $default_target_list; do
1075d880a3baSPaolo Bonzini        target_list="$target_list $target"
1076d880a3baSPaolo Bonzini    done
1077d880a3baSPaolo Bonzini    target_list="${target_list# }"
1078121afa9eSAnthony Liguorielse
1079fdb75aefSPaolo Bonzini    default_targets=no
108089138857SStefan Weil    target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1081d880a3baSPaolo Bonzini    for target in $target_list; do
108225b48338SPeter Maydell        # Check that we recognised the target name; this allows a more
108325b48338SPeter Maydell        # friendly error message than if we let it fall through.
108425b48338SPeter Maydell        case " $default_target_list " in
108525b48338SPeter Maydell            *" $target "*)
108625b48338SPeter Maydell                ;;
108725b48338SPeter Maydell            *)
108825b48338SPeter Maydell                error_exit "Unknown target name '$target'"
108925b48338SPeter Maydell                ;;
109025b48338SPeter Maydell        esac
109125b48338SPeter Maydell    done
1092d880a3baSPaolo Bonzinifi
109325b48338SPeter Maydell
10947630156dSPhilippe Mathieu-Daudéif test "$tcg" = "auto"; then
10957630156dSPhilippe Mathieu-Daudé  if test -z "$target_list"; then
10967630156dSPhilippe Mathieu-Daudé    tcg="disabled"
10977630156dSPhilippe Mathieu-Daudé  else
10987630156dSPhilippe Mathieu-Daudé    tcg="enabled"
10997630156dSPhilippe Mathieu-Daudé  fi
11007630156dSPhilippe Mathieu-Daudéfi
11017630156dSPhilippe Mathieu-Daudé
1102a47dd5c5SPaolo Bonzini#########################################
1103a47dd5c5SPaolo Bonzini# gdb test
1104a47dd5c5SPaolo Bonzini
1105a47dd5c5SPaolo Bonziniif test -n "$gdb_bin"; then
110634a4ef1cSGustavo Romero    gdb_version_string=$($gdb_bin --version | head -n 1)
110734a4ef1cSGustavo Romero    # Extract last field in the version string
110834a4ef1cSGustavo Romero    gdb_version=${gdb_version_string##* }
110934a4ef1cSGustavo Romero    if version_ge $gdb_version 9.1; then
1110a47dd5c5SPaolo Bonzini        gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
1111a47dd5c5SPaolo Bonzini    else
1112a47dd5c5SPaolo Bonzini        gdb_bin=""
1113a47dd5c5SPaolo Bonzini    fi
1114a47dd5c5SPaolo Bonzinifi
1115a47dd5c5SPaolo Bonzini
111633ab5f24SMichal Privoznik##########################################
11177d13299dSbellard# big/little endian test
11187d13299dSbellardcat > $TMPC << EOF
111933ab5f24SMichal Privoznik#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
112033ab5f24SMichal Privoznik# error LITTLE
112133ab5f24SMichal Privoznik#endif
112233ab5f24SMichal Privoznikint main(void) { return 0; }
11237d13299dSbellardEOF
11247d13299dSbellard
112533ab5f24SMichal Privoznikif ! compile_prog ; then
112661cc919fSMike Frysinger  bigendian="no"
11277d13299dSbellardelse
112833ab5f24SMichal Privoznik  cat > $TMPC << EOF
112933ab5f24SMichal Privoznik#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
113033ab5f24SMichal Privoznik# error BIG
113133ab5f24SMichal Privoznik#endif
113233ab5f24SMichal Privoznikint main(void) { return 0; }
113333ab5f24SMichal PrivoznikEOF
113433ab5f24SMichal Privoznik
113533ab5f24SMichal Privoznik  if ! compile_prog ; then
113633ab5f24SMichal Privoznik    bigendian="yes"
113733ab5f24SMichal Privoznik  else
11387d13299dSbellard    echo big/little test failed
1139659eb157SThomas Huth    exit 1
11407d13299dSbellard  fi
11417d13299dSbellardfi
11427d13299dSbellard
1143adc28027SAlexander Bulekov##########################################
1144cd362defSPaolo Bonzini# functions to probe cross compilers
1145cd362defSPaolo Bonzini
1146cd362defSPaolo Bonzinicontainer="no"
114760f999b7SAlex Bennéerunc=""
114847fdc8fbSStefan Weilif test $use_containers = "yes" && (has "docker" || has "podman"); then
114942ede11aSAlex Bennée    case $($python "$source_path"/tests/docker/docker.py --engine "$container_engine" probe) in
1150c4575b59SPaolo Bonzini        *docker) container=docker ;;
1151c4575b59SPaolo Bonzini        podman) container=podman ;;
1152c4575b59SPaolo Bonzini        no) container=no ;;
1153c4575b59SPaolo Bonzini    esac
1154a3e28f81SPaolo Bonzini    if test "$container" != "no"; then
1155a3e28f81SPaolo Bonzini        docker_py="$python $source_path/tests/docker/docker.py --engine $container"
115642ede11aSAlex Bennée        runc=$container
1157a3e28f81SPaolo Bonzini    fi
1158cd362defSPaolo Bonzinifi
1159cd362defSPaolo Bonzini
1160cd362defSPaolo Bonzini# cross compilers defaults, can be overridden with --cross-cc-ARCH
11615adb43beSPaolo Bonzini: ${cross_prefix_aarch64="aarch64-linux-gnu-"}
11625adb43beSPaolo Bonzini: ${cross_prefix_aarch64_be="$cross_prefix_aarch64"}
11635adb43beSPaolo Bonzini: ${cross_prefix_alpha="alpha-linux-gnu-"}
11645adb43beSPaolo Bonzini: ${cross_prefix_arm="arm-linux-gnueabihf-"}
11655adb43beSPaolo Bonzini: ${cross_prefix_armeb="$cross_prefix_arm"}
11665adb43beSPaolo Bonzini: ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
116734bb43b0SSong Gao: ${cross_prefix_loongarch64="loongarch64-unknown-linux-gnu-"}
11685adb43beSPaolo Bonzini: ${cross_prefix_hppa="hppa-linux-gnu-"}
11695adb43beSPaolo Bonzini: ${cross_prefix_i386="i686-linux-gnu-"}
11705adb43beSPaolo Bonzini: ${cross_prefix_m68k="m68k-linux-gnu-"}
11715adb43beSPaolo Bonzini: ${cross_prefix_microblaze="microblaze-linux-musl-"}
11725adb43beSPaolo Bonzini: ${cross_prefix_mips64el="mips64el-linux-gnuabi64-"}
11735adb43beSPaolo Bonzini: ${cross_prefix_mips64="mips64-linux-gnuabi64-"}
11745adb43beSPaolo Bonzini: ${cross_prefix_mipsel="mipsel-linux-gnu-"}
11755adb43beSPaolo Bonzini: ${cross_prefix_mips="mips-linux-gnu-"}
11765adb43beSPaolo Bonzini: ${cross_prefix_ppc="powerpc-linux-gnu-"}
11775adb43beSPaolo Bonzini: ${cross_prefix_ppc64="powerpc64-linux-gnu-"}
11785adb43beSPaolo Bonzini: ${cross_prefix_ppc64le="$cross_prefix_ppc64"}
11795adb43beSPaolo Bonzini: ${cross_prefix_riscv64="riscv64-linux-gnu-"}
11805adb43beSPaolo Bonzini: ${cross_prefix_s390x="s390x-linux-gnu-"}
11815adb43beSPaolo Bonzini: ${cross_prefix_sh4="sh4-linux-gnu-"}
11825adb43beSPaolo Bonzini: ${cross_prefix_sparc64="sparc64-linux-gnu-"}
11835adb43beSPaolo Bonzini: ${cross_prefix_sparc="$cross_prefix_sparc64"}
1184a3d3de8eSPaolo Bonzini: ${cross_prefix_tricore="tricore-"}
11855adb43beSPaolo Bonzini: ${cross_prefix_x86_64="x86_64-linux-gnu-"}
11865adb43beSPaolo Bonzini
1187cd362defSPaolo Bonzini: ${cross_cc_aarch64_be="$cross_cc_aarch64"}
1188cd362defSPaolo Bonzini: ${cross_cc_cflags_aarch64_be="-mbig-endian"}
118946af66edSPaolo Bonzini: ${cross_cc_armeb="$cross_cc_arm"}
1190cd362defSPaolo Bonzini: ${cross_cc_cflags_armeb="-mbig-endian"}
1191cd362defSPaolo Bonzini: ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
1192fc2622f6STaylor Simpson: ${cross_cc_cflags_hexagon="-mv73 -O2 -static"}
1193cd362defSPaolo Bonzini: ${cross_cc_cflags_i386="-m32"}
1194d44f2f96SPaolo Bonzini: ${cross_cc_cflags_ppc="-m32 -mbig-endian"}
1195cd362defSPaolo Bonzini: ${cross_cc_cflags_ppc64="-m64 -mbig-endian"}
1196cd362defSPaolo Bonzini: ${cross_cc_ppc64le="$cross_cc_ppc64"}
1197cd362defSPaolo Bonzini: ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"}
1198cd362defSPaolo Bonzini: ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
119946af66edSPaolo Bonzini: ${cross_cc_sparc="$cross_cc_sparc64"}
120046af66edSPaolo Bonzini: ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
1201c2bf2ccbSArtyom Kunakovsky: ${cross_cc_cflags_x86_64="-m64 -mcx16"}
1202cd362defSPaolo Bonzini
12035adb43beSPaolo Bonzinicompute_target_variable() {
120492e288fcSPaolo Bonzini  eval "$2="
12055adb43beSPaolo Bonzini  if eval test -n "\"\${cross_prefix_$1}\""; then
12065adb43beSPaolo Bonzini    if eval has "\"\${cross_prefix_$1}\$3\""; then
12075adb43beSPaolo Bonzini      eval "$2=\"\${cross_prefix_$1}\$3\""
12085adb43beSPaolo Bonzini    fi
12095adb43beSPaolo Bonzini  fi
12105adb43beSPaolo Bonzini}
1211cd362defSPaolo Bonzini
121235fd22b0SPaolo Bonzinihave_target() {
121335fd22b0SPaolo Bonzini  for i; do
121435fd22b0SPaolo Bonzini    case " $target_list " in
121535fd22b0SPaolo Bonzini      *" $i "*) return 0;;
121635fd22b0SPaolo Bonzini      *) ;;
121735fd22b0SPaolo Bonzini    esac
121835fd22b0SPaolo Bonzini  done
121935fd22b0SPaolo Bonzini  return 1
122035fd22b0SPaolo Bonzini}
122135fd22b0SPaolo Bonzini
122252f08deaSPaolo Bonzini# probe_target_compiler TARGET
122352f08deaSPaolo Bonzini#
122452f08deaSPaolo Bonzini# Look for a compiler for the given target, either native or cross.
122552f08deaSPaolo Bonzini# Set variables target_* if a compiler is found, and container_cross_*
122652f08deaSPaolo Bonzini# if a Docker-based cross-compiler image is known for the target.
122752f08deaSPaolo Bonzini# Set got_cross_cc to yes/no depending on whether a non-container-based
122852f08deaSPaolo Bonzini# compiler was found.
122952f08deaSPaolo Bonzini#
123052f08deaSPaolo Bonzini# If TARGET is a user-mode emulation target, also set build_static to
123152f08deaSPaolo Bonzini# "y" if static linking is possible.
123252f08deaSPaolo Bonzini#
1233cd362defSPaolo Bonziniprobe_target_compiler() {
1234cd362defSPaolo Bonzini  # reset all output variables
123592e288fcSPaolo Bonzini  got_cross_cc=no
1236cd362defSPaolo Bonzini  container_image=
1237cd362defSPaolo Bonzini  container_hosts=
1238d3322023SPaolo Bonzini  container_cross_prefix=
1239cd362defSPaolo Bonzini  container_cross_cc=
124087eb014cSPaolo Bonzini  container_cross_ar=
1241cd362defSPaolo Bonzini  container_cross_as=
1242cd362defSPaolo Bonzini  container_cross_ld=
124387eb014cSPaolo Bonzini  container_cross_nm=
124487eb014cSPaolo Bonzini  container_cross_objcopy=
124587eb014cSPaolo Bonzini  container_cross_ranlib=
124687eb014cSPaolo Bonzini  container_cross_strip=
1247cd362defSPaolo Bonzini
124852f08deaSPaolo Bonzini  target_arch=${1%%-*}
124952f08deaSPaolo Bonzini  case $target_arch in
1250cd362defSPaolo Bonzini    aarch64) container_hosts="x86_64 aarch64" ;;
1251cd362defSPaolo Bonzini    alpha) container_hosts=x86_64 ;;
1252cd362defSPaolo Bonzini    arm) container_hosts="x86_64 aarch64" ;;
1253cd362defSPaolo Bonzini    cris) container_hosts=x86_64 ;;
1254cd362defSPaolo Bonzini    hexagon) container_hosts=x86_64 ;;
1255cd362defSPaolo Bonzini    hppa) container_hosts=x86_64 ;;
1256cd362defSPaolo Bonzini    i386) container_hosts=x86_64 ;;
1257b70ec50bSRichard Henderson    loongarch64) container_hosts=x86_64 ;;
1258cd362defSPaolo Bonzini    m68k) container_hosts=x86_64 ;;
1259cd362defSPaolo Bonzini    microblaze) container_hosts=x86_64 ;;
1260cd362defSPaolo Bonzini    mips64el) container_hosts=x86_64 ;;
1261cd362defSPaolo Bonzini    mips64) container_hosts=x86_64 ;;
1262cd362defSPaolo Bonzini    mipsel) container_hosts=x86_64 ;;
1263cd362defSPaolo Bonzini    mips) container_hosts=x86_64 ;;
1264cd362defSPaolo Bonzini    ppc) container_hosts=x86_64 ;;
1265cd362defSPaolo Bonzini    ppc64|ppc64le) container_hosts=x86_64 ;;
1266cd362defSPaolo Bonzini    riscv64) container_hosts=x86_64 ;;
1267cd362defSPaolo Bonzini    s390x) container_hosts=x86_64 ;;
1268cd362defSPaolo Bonzini    sh4) container_hosts=x86_64 ;;
1269cd362defSPaolo Bonzini    sparc64) container_hosts=x86_64 ;;
1270cd362defSPaolo Bonzini    tricore) container_hosts=x86_64 ;;
1271a04f3372SPaolo Bonzini    x86_64) container_hosts="aarch64 ppc64le x86_64" ;;
1272cd362defSPaolo Bonzini    xtensa*) container_hosts=x86_64 ;;
1273cd362defSPaolo Bonzini  esac
1274cd362defSPaolo Bonzini
1275cd362defSPaolo Bonzini  for host in $container_hosts; do
1276cd362defSPaolo Bonzini    test "$container" != no || continue
1277cd362defSPaolo Bonzini    test "$host" = "$cpu" || continue
127852f08deaSPaolo Bonzini    case $target_arch in
1279d3322023SPaolo Bonzini      # debian-all-test-cross architectures
1280d3322023SPaolo Bonzini
1281d3322023SPaolo Bonzini      hppa|m68k|mips|riscv64|sparc64)
1282d3322023SPaolo Bonzini        container_image=debian-all-test-cross
1283d3322023SPaolo Bonzini        ;;
1284d3322023SPaolo Bonzini      mips64)
1285d3322023SPaolo Bonzini        container_image=debian-all-test-cross
1286d3322023SPaolo Bonzini        container_cross_prefix=mips64-linux-gnuabi64-
1287d3322023SPaolo Bonzini        ;;
1288d3322023SPaolo Bonzini      ppc|ppc64|ppc64le)
1289d3322023SPaolo Bonzini        container_image=debian-all-test-cross
1290d3322023SPaolo Bonzini        container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu-
1291d3322023SPaolo Bonzini        ;;
1292d3322023SPaolo Bonzini
1293d3322023SPaolo Bonzini      # debian-legacy-test-cross architectures (need Debian 11)
1294d3322023SPaolo Bonzini      # - libc6.1-dev-alpha-cross: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1054412
1295d3322023SPaolo Bonzini      # - sh4-linux-user: binaries don't run with bookworm compiler
1296d3322023SPaolo Bonzini
1297d3322023SPaolo Bonzini      alpha|sh4)
1298d3322023SPaolo Bonzini        container_image=debian-legacy-test-cross
1299d3322023SPaolo Bonzini        ;;
1300d3322023SPaolo Bonzini
1301d3322023SPaolo Bonzini      # architectures with individual containers
1302d3322023SPaolo Bonzini
1303cd362defSPaolo Bonzini      aarch64)
1304cd362defSPaolo Bonzini        # We don't have any bigendian build tools so we only use this for AArch64
1305cd362defSPaolo Bonzini        container_image=debian-arm64-cross
1306d004e27bSAlex Bennée        ;;
1307cd362defSPaolo Bonzini      arm)
1308cd362defSPaolo Bonzini        # We don't have any bigendian build tools so we only use this for ARM
1309cd362defSPaolo Bonzini        container_image=debian-armhf-cross
13105adb43beSPaolo Bonzini        container_cross_prefix=arm-linux-gnueabihf-
1311cd362defSPaolo Bonzini        ;;
1312cd362defSPaolo Bonzini      cris)
1313cd362defSPaolo Bonzini        container_image=fedora-cris-cross
1314cd362defSPaolo Bonzini        ;;
1315cd362defSPaolo Bonzini      hexagon)
13165adb43beSPaolo Bonzini        container_cross_prefix=hexagon-unknown-linux-musl-
13175adb43beSPaolo Bonzini        container_cross_cc=${container_cross_prefix}clang
1318cd362defSPaolo Bonzini        ;;
1319cd362defSPaolo Bonzini      i386)
1320aa5730b0SDaniel P. Berrangé        container_image=debian-i686-cross
1321aa5730b0SDaniel P. Berrangé        container_cross_prefix=i686-linux-gnu-
1322cd362defSPaolo Bonzini        ;;
1323b70ec50bSRichard Henderson      loongarch64)
1324b70ec50bSRichard Henderson        container_image=debian-loongarch-cross
1325b70ec50bSRichard Henderson        container_cross_prefix=loongarch64-unknown-linux-gnu-
1326b70ec50bSRichard Henderson        ;;
1327cd362defSPaolo Bonzini      microblaze)
13285adb43beSPaolo Bonzini        container_cross_prefix=microblaze-linux-musl-
1329cd362defSPaolo Bonzini        ;;
1330cd362defSPaolo Bonzini      mips64el)
1331cd362defSPaolo Bonzini        container_image=debian-mips64el-cross
13325adb43beSPaolo Bonzini        container_cross_prefix=mips64el-linux-gnuabi64-
1333cd362defSPaolo Bonzini        ;;
1334cd362defSPaolo Bonzini      tricore)
1335cd362defSPaolo Bonzini        container_image=debian-tricore-cross
13365adb43beSPaolo Bonzini        container_cross_prefix=tricore-
1337cd362defSPaolo Bonzini        ;;
1338cd362defSPaolo Bonzini      x86_64)
1339cd362defSPaolo Bonzini        container_image=debian-amd64-cross
1340cd362defSPaolo Bonzini        ;;
1341cd362defSPaolo Bonzini      xtensa*)
1342cd362defSPaolo Bonzini        container_image=debian-xtensa-cross
1343cd362defSPaolo Bonzini
1344cd362defSPaolo Bonzini        # default to the dc232b cpu
13455adb43beSPaolo Bonzini        container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
1346cd362defSPaolo Bonzini        ;;
1347cd362defSPaolo Bonzini    esac
1348d3322023SPaolo Bonzini    # Debian and GNU architecture names usually match
1349d3322023SPaolo Bonzini    : ${container_image:=debian-$target_arch-cross}
1350d3322023SPaolo Bonzini    : ${container_cross_prefix:=$target_arch-linux-gnu-}
13515adb43beSPaolo Bonzini    : ${container_cross_cc:=${container_cross_prefix}gcc}
135287eb014cSPaolo Bonzini    : ${container_cross_ar:=${container_cross_prefix}ar}
13535adb43beSPaolo Bonzini    : ${container_cross_as:=${container_cross_prefix}as}
13545adb43beSPaolo Bonzini    : ${container_cross_ld:=${container_cross_prefix}ld}
135587eb014cSPaolo Bonzini    : ${container_cross_nm:=${container_cross_prefix}nm}
135687eb014cSPaolo Bonzini    : ${container_cross_objcopy:=${container_cross_prefix}objcopy}
135787eb014cSPaolo Bonzini    : ${container_cross_ranlib:=${container_cross_prefix}ranlib}
135887eb014cSPaolo Bonzini    : ${container_cross_strip:=${container_cross_prefix}strip}
1359cd362defSPaolo Bonzini  done
1360cd362defSPaolo Bonzini
136192e288fcSPaolo Bonzini  try=cross
136200753158SPaolo Bonzini  # For softmmu/roms also look for a bi-endian or multilib-enabled host compiler
136300753158SPaolo Bonzini  if [ "${1%softmmu}" != "$1" ] || test "$target_arch" = "$cpu"; then
136492e288fcSPaolo Bonzini      case "$target_arch:$cpu" in
136592e288fcSPaolo Bonzini        aarch64_be:aarch64 | \
136692e288fcSPaolo Bonzini        armeb:arm | \
136792e288fcSPaolo Bonzini        i386:x86_64 | \
136892e288fcSPaolo Bonzini        mips*:mips64 | \
136992e288fcSPaolo Bonzini        ppc*:ppc64 | \
137092e288fcSPaolo Bonzini        sparc:sparc64 | \
137192e288fcSPaolo Bonzini        "$cpu:$cpu")
137292e288fcSPaolo Bonzini        try='native cross' ;;
137392e288fcSPaolo Bonzini      esac
1374c2118e9eSAlex Bennée  fi
137552f08deaSPaolo Bonzini  eval "target_cflags=\${cross_cc_cflags_$target_arch}"
1376b3b5472dSPeter Maydell  for thistry in $try; do
1377b3b5472dSPeter Maydell    case $thistry in
137892e288fcSPaolo Bonzini    native)
137992e288fcSPaolo Bonzini      target_cc=$cc
138092e288fcSPaolo Bonzini      target_ccas=$ccas
138192e288fcSPaolo Bonzini      target_ar=$ar
138292e288fcSPaolo Bonzini      target_as=$as
138392e288fcSPaolo Bonzini      target_ld=$ld
138492e288fcSPaolo Bonzini      target_nm=$nm
138592e288fcSPaolo Bonzini      target_objcopy=$objcopy
138692e288fcSPaolo Bonzini      target_ranlib=$ranlib
138792e288fcSPaolo Bonzini      target_strip=$strip
138892e288fcSPaolo Bonzini      ;;
138992e288fcSPaolo Bonzini    cross)
139092e288fcSPaolo Bonzini      target_cc=
139152f08deaSPaolo Bonzini      if eval test -n "\"\${cross_cc_$target_arch}\""; then
139252f08deaSPaolo Bonzini        if eval has "\"\${cross_cc_$target_arch}\""; then
139352f08deaSPaolo Bonzini          eval "target_cc=\"\${cross_cc_$target_arch}\""
1394cd362defSPaolo Bonzini        fi
13955adb43beSPaolo Bonzini      else
139652f08deaSPaolo Bonzini        compute_target_variable $target_arch target_cc gcc
1397cd362defSPaolo Bonzini      fi
139887eb014cSPaolo Bonzini      target_ccas=$target_cc
139952f08deaSPaolo Bonzini      compute_target_variable $target_arch target_ar ar
140052f08deaSPaolo Bonzini      compute_target_variable $target_arch target_as as
140152f08deaSPaolo Bonzini      compute_target_variable $target_arch target_ld ld
140252f08deaSPaolo Bonzini      compute_target_variable $target_arch target_nm nm
140352f08deaSPaolo Bonzini      compute_target_variable $target_arch target_objcopy objcopy
140452f08deaSPaolo Bonzini      compute_target_variable $target_arch target_ranlib ranlib
140552f08deaSPaolo Bonzini      compute_target_variable $target_arch target_strip strip
1406640aabc8SPaolo Bonzini      ;;
1407640aabc8SPaolo Bonzini    esac
140892e288fcSPaolo Bonzini
14092ad60f6fSPaolo Bonzini    if test -n "$target_cc"; then
141052f08deaSPaolo Bonzini      case $target_arch in
14112ad60f6fSPaolo Bonzini        i386|x86_64)
14122ad60f6fSPaolo Bonzini          if $target_cc --version | grep -qi "clang"; then
141392e288fcSPaolo Bonzini            continue
14142ad60f6fSPaolo Bonzini          fi
14152ad60f6fSPaolo Bonzini          ;;
14162ad60f6fSPaolo Bonzini      esac
141792e288fcSPaolo Bonzini    elif test -n "$target_as" && test -n "$target_ld"; then
141892e288fcSPaolo Bonzini      # Special handling for assembler only targets
141992e288fcSPaolo Bonzini      case $target in
142092e288fcSPaolo Bonzini        tricore-softmmu)
142192e288fcSPaolo Bonzini          build_static=
142292e288fcSPaolo Bonzini          got_cross_cc=yes
142392e288fcSPaolo Bonzini          break
142492e288fcSPaolo Bonzini          ;;
142592e288fcSPaolo Bonzini        *)
142692e288fcSPaolo Bonzini          continue
142792e288fcSPaolo Bonzini          ;;
142892e288fcSPaolo Bonzini      esac
142992e288fcSPaolo Bonzini    else
143092e288fcSPaolo Bonzini      continue
143192e288fcSPaolo Bonzini    fi
143292e288fcSPaolo Bonzini
143392e288fcSPaolo Bonzini    write_c_skeleton
143492e288fcSPaolo Bonzini    case $1 in
143592e288fcSPaolo Bonzini      *-softmmu)
143692e288fcSPaolo Bonzini        if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC &&
143792e288fcSPaolo Bonzini          do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then
143892e288fcSPaolo Bonzini          got_cross_cc=yes
143992e288fcSPaolo Bonzini          break
144092e288fcSPaolo Bonzini        fi
144192e288fcSPaolo Bonzini        ;;
144292e288fcSPaolo Bonzini      *)
144392e288fcSPaolo Bonzini        if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC -static ; then
144492e288fcSPaolo Bonzini          build_static=y
144592e288fcSPaolo Bonzini          got_cross_cc=yes
144692e288fcSPaolo Bonzini          break
144792e288fcSPaolo Bonzini        fi
144892e288fcSPaolo Bonzini        if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC ; then
144992e288fcSPaolo Bonzini          build_static=
145092e288fcSPaolo Bonzini          got_cross_cc=yes
145192e288fcSPaolo Bonzini          break
145292e288fcSPaolo Bonzini        fi
145392e288fcSPaolo Bonzini        ;;
145492e288fcSPaolo Bonzini    esac
145592e288fcSPaolo Bonzini  done
145692e288fcSPaolo Bonzini  if test $got_cross_cc != yes; then
145792e288fcSPaolo Bonzini    build_static=
145892e288fcSPaolo Bonzini    target_cc=
145992e288fcSPaolo Bonzini    target_ccas=
146092e288fcSPaolo Bonzini    target_ar=
146192e288fcSPaolo Bonzini    target_as=
146292e288fcSPaolo Bonzini    target_ld=
146392e288fcSPaolo Bonzini    target_nm=
146492e288fcSPaolo Bonzini    target_objcopy=
146592e288fcSPaolo Bonzini    target_ranlib=
146692e288fcSPaolo Bonzini    target_strip=
14672ad60f6fSPaolo Bonzini  fi
1468fde10960SAlex Bennée  test -n "$target_cc"
1469cd362defSPaolo Bonzini}
1470cd362defSPaolo Bonzini
1471cd362defSPaolo Bonziniwrite_target_makefile() {
1472e81785abSPaolo Bonzini  echo "EXTRA_CFLAGS=$target_cflags"
14730825cae0SPaolo Bonzini  if test -z "$target_cc" && test -z "$target_as"; then
14740825cae0SPaolo Bonzini    test -z "$container_image" && error_exit "Internal error: could not find cross compiler for $1?"
14750825cae0SPaolo Bonzini    echo "$1: docker-image-$container_image" >> Makefile.prereqs
14760825cae0SPaolo Bonzini    if test -n "$container_cross_cc"; then
14770825cae0SPaolo Bonzini      echo "CC=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
14780825cae0SPaolo Bonzini      echo "CCAS=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
14790825cae0SPaolo Bonzini    fi
14800825cae0SPaolo Bonzini    echo "AR=$docker_py cc --cc $container_cross_ar -i qemu/$container_image -s $source_path --"
14810825cae0SPaolo Bonzini    echo "AS=$docker_py cc --cc $container_cross_as -i qemu/$container_image -s $source_path --"
14820825cae0SPaolo Bonzini    echo "LD=$docker_py cc --cc $container_cross_ld -i qemu/$container_image -s $source_path --"
14830825cae0SPaolo Bonzini    echo "NM=$docker_py cc --cc $container_cross_nm -i qemu/$container_image -s $source_path --"
14840825cae0SPaolo Bonzini    echo "OBJCOPY=$docker_py cc --cc $container_cross_objcopy -i qemu/$container_image -s $source_path --"
14850825cae0SPaolo Bonzini    echo "RANLIB=$docker_py cc --cc $container_cross_ranlib -i qemu/$container_image -s $source_path --"
14860825cae0SPaolo Bonzini    echo "STRIP=$docker_py cc --cc $container_cross_strip -i qemu/$container_image -s $source_path --"
14870825cae0SPaolo Bonzini  else
1488cd362defSPaolo Bonzini    if test -n "$target_cc"; then
1489cd362defSPaolo Bonzini      echo "CC=$target_cc"
149087eb014cSPaolo Bonzini      echo "CCAS=$target_ccas"
149187eb014cSPaolo Bonzini    fi
149287eb014cSPaolo Bonzini    if test -n "$target_ar"; then
149387eb014cSPaolo Bonzini      echo "AR=$target_ar"
1494cd362defSPaolo Bonzini    fi
1495cd362defSPaolo Bonzini    if test -n "$target_as"; then
1496cd362defSPaolo Bonzini      echo "AS=$target_as"
1497cd362defSPaolo Bonzini    fi
1498cd362defSPaolo Bonzini    if test -n "$target_ld"; then
1499cd362defSPaolo Bonzini      echo "LD=$target_ld"
1500cd362defSPaolo Bonzini    fi
150187eb014cSPaolo Bonzini    if test -n "$target_nm"; then
150287eb014cSPaolo Bonzini      echo "NM=$target_nm"
150387eb014cSPaolo Bonzini    fi
150487eb014cSPaolo Bonzini    if test -n "$target_objcopy"; then
150587eb014cSPaolo Bonzini      echo "OBJCOPY=$target_objcopy"
150687eb014cSPaolo Bonzini    fi
150787eb014cSPaolo Bonzini    if test -n "$target_ranlib"; then
150887eb014cSPaolo Bonzini      echo "RANLIB=$target_ranlib"
150987eb014cSPaolo Bonzini    fi
151087eb014cSPaolo Bonzini    if test -n "$target_strip"; then
151187eb014cSPaolo Bonzini      echo "STRIP=$target_strip"
151287eb014cSPaolo Bonzini    fi
1513cd362defSPaolo Bonzini  fi
1514cd362defSPaolo Bonzini}
1515cd362defSPaolo Bonzini
151633ab4787SPaolo Bonzini#######################################
151733ab4787SPaolo Bonzini# cross-compiled firmware targets
151833ab4787SPaolo Bonzini
1519ad388845SPaolo Bonzini# Set up build tree symlinks that point back into the source tree
1520ad388845SPaolo Bonzini# (these can be both files and directories).
1521ad388845SPaolo Bonzini# Caution: avoid adding files or directories here using wildcards. This
1522ad388845SPaolo Bonzini# will result in problems later if a new file matching the wildcard is
1523ad388845SPaolo Bonzini# added to the source tree -- nothing will cause configure to be rerun
1524ad388845SPaolo Bonzini# so the build tree will be missing the link back to the new file, and
1525ad388845SPaolo Bonzini# tests might fail. Prefer to keep the relevant files in their own
1526ad388845SPaolo Bonzini# directory and symlink the directory instead.
1527ad388845SPaolo BonziniLINKS="Makefile"
1528201aa17eSThomas HuthLINKS="$LINKS docs/config"
1529ad388845SPaolo BonziniLINKS="$LINKS pc-bios/optionrom/Makefile"
1530ad388845SPaolo BonziniLINKS="$LINKS pc-bios/s390-ccw/Makefile"
1531d695918fSPaolo BonziniLINKS="$LINKS pc-bios/vof/Makefile"
1532ad388845SPaolo BonziniLINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
1533ad388845SPaolo BonziniLINKS="$LINKS tests/avocado tests/data"
1534c7e618d4SPaolo BonziniLINKS="$LINKS tests/qemu-iotests/check tests/qemu-iotests/Makefile"
1535ad388845SPaolo BonziniLINKS="$LINKS python"
1536ad388845SPaolo BonziniLINKS="$LINKS contrib/plugins/Makefile "
1537ad388845SPaolo Bonzinifor f in $LINKS ; do
1538ad388845SPaolo Bonzini    if [ -e "$source_path/$f" ]; then
1539ad388845SPaolo Bonzini        symlink "$source_path/$f" "$f"
1540ad388845SPaolo Bonzini    fi
1541ad388845SPaolo Bonzinidone
1542ad388845SPaolo Bonzini
154332f8f832SPaolo Bonzini# use included Linux headers for KVM architectures
154432f8f832SPaolo Bonziniif test "$host_os" = "linux" && test -n "$linux_arch"; then
154532f8f832SPaolo Bonzini  symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
154632f8f832SPaolo Bonzinifi
154732f8f832SPaolo Bonzini
1548b898bf28SPaolo Bonziniecho "# Automatically generated by configure - do not modify" > Makefile.prereqs
1549b898bf28SPaolo Bonzini
1550ca35f780SPaolo Bonzini# Mac OS X ships with a broken assembler
155135fd22b0SPaolo Bonziniif have_target i386-softmmu x86_64-softmmu && \
1552d0cda6f4SPaolo Bonzini        test "$host_os" != "darwin" && test "$host_os" != "sunos" && \
1553d0cda6f4SPaolo Bonzini        test "$host_os" != "haiku" && \
155461cbb356SPaolo Bonzini        probe_target_compiler i386-softmmu; then
15552a5919abSPaolo Bonzini    subdirs="$subdirs pc-bios/optionrom"
155633ab4787SPaolo Bonzini    config_mak=pc-bios/optionrom/config.mak
155733ab4787SPaolo Bonzini    echo "# Automatically generated by configure - do not modify" > $config_mak
155833ab4787SPaolo Bonzini    echo "TOPSRC_DIR=$source_path" >> $config_mak
1559fde10960SAlex Bennée    write_target_makefile >> $config_mak
156033ab4787SPaolo Bonzinifi
1561ca35f780SPaolo Bonzini
156235fd22b0SPaolo Bonziniif have_target ppc-softmmu ppc64-softmmu && \
156335fd22b0SPaolo Bonzini        probe_target_compiler ppc-softmmu; then
15642a5919abSPaolo Bonzini    subdirs="$subdirs pc-bios/vof"
1565d695918fSPaolo Bonzini    config_mak=pc-bios/vof/config.mak
1566d695918fSPaolo Bonzini    echo "# Automatically generated by configure - do not modify" > $config_mak
1567d695918fSPaolo Bonzini    echo "SRC_DIR=$source_path/pc-bios/vof" >> $config_mak
1568fde10960SAlex Bennée    write_target_makefile >> $config_mak
1569d695918fSPaolo Bonzinifi
1570d695918fSPaolo Bonzini
15719ffed426SPaolo Bonzini# Only build s390-ccw bios if the compiler has -march=z900 or -march=z10
15729ffed426SPaolo Bonzini# (which is the lowest architecture level that Clang supports)
1573b11f9bd9SPaolo Bonziniif have_target s390x-softmmu && probe_target_compiler s390x-softmmu && \
1574b11f9bd9SPaolo Bonzini    GIT=git "$source_path/scripts/git-submodule.sh" "$git_submodules_action" roms/SLOF >> config.log 2>&1; then
15752e33c3f8SThomas Huth  write_c_skeleton
15769ffed426SPaolo Bonzini  do_compiler "$target_cc" $target_cc_cflags -march=z900 -o $TMPO -c $TMPC
1577a5b2afd5SThomas Huth  has_z900=$?
15789ffed426SPaolo Bonzini  if [ $has_z900 = 0 ] || do_compiler "$target_cc" $target_cc_cflags -march=z10 -msoft-float -Werror -o $TMPO -c $TMPC; then
1579a5b2afd5SThomas Huth    if [ $has_z900 != 0 ]; then
1580a5b2afd5SThomas Huth      echo "WARNING: Your compiler does not support the z900!"
1581a5b2afd5SThomas Huth      echo "         The s390-ccw bios will only work with guest CPUs >= z10."
1582a5b2afd5SThomas Huth    fi
15832a5919abSPaolo Bonzini    subdirs="$subdirs pc-bios/s390-ccw"
15849ffed426SPaolo Bonzini    config_mak=pc-bios/s390-ccw/config-host.mak
15859ffed426SPaolo Bonzini    echo "# Automatically generated by configure - do not modify" > $config_mak
15869ffed426SPaolo Bonzini    echo "SRC_PATH=$source_path/pc-bios/s390-ccw" >> $config_mak
1587b11f9bd9SPaolo Bonzini    echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_mak
1588fde10960SAlex Bennée    write_target_makefile >> $config_mak
15891ef6bfc2SPhilippe Mathieu-Daudé  fi
15909933c305SChristian Borntraegerfi
15919933c305SChristian Borntraeger
15929ffed426SPaolo Bonzini#######################################
15939ffed426SPaolo Bonzini# generate config-host.mak
15949ffed426SPaolo Bonzini
159598ec69acSJuan Quintelaconfig_host_mak="config-host.mak"
159697a847bcSbellard
159798ec69acSJuan Quintelaecho "# Automatically generated by configure - do not modify" > $config_host_mak
159898ec69acSJuan Quintelaecho >> $config_host_mak
159998ec69acSJuan Quintela
1600e6c3b0f7SPaolo Bonziniecho all: >> $config_host_mak
1601804edf29SJuan Quintela
160298ec69acSJuan Quintelaecho "SRC_PATH=$source_path" >> $config_host_mak
16032b1f35b9SAlex Bennéeecho "TARGET_DIRS=$target_list" >> $config_host_mak
1604a47dd5c5SPaolo Bonziniecho "GDB=$gdb_bin" >> $config_host_mak
1605c4575b59SPaolo Bonziniif test "$container" != no; then
160660f999b7SAlex Bennée    echo "RUNC=$runc" >> $config_host_mak
1607c4575b59SPaolo Bonzinifi
16082a5919abSPaolo Bonziniecho "SUBDIRS=$subdirs" >> $config_host_mak
1609c886edfbSBlue Swirlecho "PYTHON=$python" >> $config_host_mak
1610913e47cbSPaolo Bonziniecho "MKVENV_ENSUREGROUP=$mkvenv ensuregroup $mkvenv_online_flag" >> $config_host_mak
161139d87c8cSAlex Bennéeecho "GENISOIMAGE=$genisoimage" >> $config_host_mak
1612a5665051SPaolo Bonziniecho "MESON=$meson" >> $config_host_mak
161309e93326SPaolo Bonziniecho "NINJA=$ninja" >> $config_host_mak
1614804edf29SJuan Quintelaecho "EXESUF=$EXESUF" >> $config_host_mak
1615fdb75aefSPaolo Bonziniif test "$default_targets" = "yes"; then
1616fdb75aefSPaolo Bonzini  echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
1617fdb75aefSPaolo Bonzinifi
1618a540f158SPeter Crosthwaite
1619bafe78adSPaolo Bonzini# contrib/plugins configuration
1620bafe78adSPaolo Bonziniecho "# Automatically generated by configure - do not modify" > contrib/plugins/$config_host_mak
1621bafe78adSPaolo Bonziniecho "SRC_PATH=$source_path/contrib/plugins" >> contrib/plugins/$config_host_mak
1622bafe78adSPaolo Bonziniecho "PKG_CONFIG=${pkg_config}" >> contrib/plugins/$config_host_mak
1623bafe78adSPaolo Bonziniecho "CC=$cc $CPU_CFLAGS" >> contrib/plugins/$config_host_mak
1624bafe78adSPaolo Bonziniecho "CFLAGS=${CFLAGS-$default_cflags} $EXTRA_CFLAGS" >> contrib/plugins/$config_host_mak
1625d0cda6f4SPaolo Bonziniif test "$host_os" = windows; then
162609f17983SAlex Bennée  echo "DLLTOOL=$dlltool" >> contrib/plugins/$config_host_mak
162709f17983SAlex Bennéefi
1628d0cda6f4SPaolo Bonziniif test "$host_os" = darwin; then
1629bafe78adSPaolo Bonzini  echo "CONFIG_DARWIN=y" >> contrib/plugins/$config_host_mak
1630bafe78adSPaolo Bonzinifi
1631d0cda6f4SPaolo Bonziniif test "$host_os" = windows; then
1632330fe3b0SGreg Manning  echo "CONFIG_WIN32=y" >> contrib/plugins/$config_host_mak
1633330fe3b0SGreg Manningfi
1634bafe78adSPaolo Bonzini
1635cd362defSPaolo Bonzini# tests/tcg configuration
1636d674342eSPaolo Bonzinimkdir -p tests/tcg
1637606c3ba7SPaolo Bonziniecho "# Automatically generated by configure - do not modify" > tests/tcg/$config_host_mak
1638606c3ba7SPaolo Bonziniecho "SRC_PATH=$source_path" >> tests/tcg/$config_host_mak
163915cc1033SPaolo Bonziniif test "$plugins" = "yes" ; then
164015cc1033SPaolo Bonzini    echo "CONFIG_PLUGIN=y" >> tests/tcg/$config_host_mak
164115cc1033SPaolo Bonzinifi
1642cd362defSPaolo Bonzini
1643cd362defSPaolo Bonzinitcg_tests_targets=
1644cd362defSPaolo Bonzinifor target in $target_list; do
1645cd362defSPaolo Bonzini  arch=${target%%-*}
1646cd362defSPaolo Bonzini
1647cd362defSPaolo Bonzini  case $target in
1648c48a5c47SPaolo Bonzini    xtensa*-linux-user)
164924f9c07aSPaolo Bonzini      # the toolchain is not complete with headers, only build system tests
1650c48a5c47SPaolo Bonzini      continue
1651c48a5c47SPaolo Bonzini      ;;
1652cd362defSPaolo Bonzini    *-softmmu)
165364708615SPeter Maydell      test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || continue
1654cd362defSPaolo Bonzini      qemu="qemu-system-$arch"
1655cd362defSPaolo Bonzini      ;;
1656cd362defSPaolo Bonzini    *-linux-user|*-bsd-user)
1657cd362defSPaolo Bonzini      qemu="qemu-$arch"
1658cd362defSPaolo Bonzini      ;;
1659cd362defSPaolo Bonzini  esac
1660cd362defSPaolo Bonzini
1661fde10960SAlex Bennée  if probe_target_compiler $target || test -n "$container_image"; then
16620825cae0SPaolo Bonzini      test -n "$container_image" && build_static=y
1663d674342eSPaolo Bonzini      mkdir -p "tests/tcg/$target"
1664c7022a70SPaolo Bonzini      config_target_mak=tests/tcg/$target/config-target.mak
1665d674342eSPaolo Bonzini      ln -sf "$source_path/tests/tcg/Makefile.target" "tests/tcg/$target/Makefile"
1666c7022a70SPaolo Bonzini      echo "# Automatically generated by configure - do not modify" > "$config_target_mak"
1667c7022a70SPaolo Bonzini      echo "TARGET_NAME=$arch" >> "$config_target_mak"
1668a3e28f81SPaolo Bonzini      echo "TARGET=$target" >> "$config_target_mak"
1669c7022a70SPaolo Bonzini      write_target_makefile "build-tcg-tests-$target" >> "$config_target_mak"
167015b273f8SPaolo Bonzini      echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
1671c7022a70SPaolo Bonzini      echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
1672bcbc36a9SAlex Bennée
1673bcbc36a9SAlex Bennée      # will GDB work with these binaries?
1674bcbc36a9SAlex Bennée      if test "${gdb_arches#*$arch}" != "$gdb_arches"; then
1675a47dd5c5SPaolo Bonzini          echo "GDB=$gdb_bin" >> $config_target_mak
1676bcbc36a9SAlex Bennée      fi
1677bcbc36a9SAlex Bennée
1678*5f9ad35eSGustavo Romero      if test "${gdb_arches#*aarch64}" != "$gdb_arches" && version_ge $gdb_version 15.1; then
1679340ca46bSGustavo Romero          echo "GDB_HAS_MTE=y" >> $config_target_mak
1680340ca46bSGustavo Romero      fi
1681340ca46bSGustavo Romero
1682b898bf28SPaolo Bonzini      echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs
1683cd362defSPaolo Bonzini      tcg_tests_targets="$tcg_tests_targets $target"
1684cd362defSPaolo Bonzini  fi
16852038f8c8SPaolo Bonzinidone
1686c0031d38SFabiano Rosas
1687c0031d38SFabiano Rosasif test "$tcg" = "enabled"; then
1688606c3ba7SPaolo Bonzini    echo "TCG_TESTS_TARGETS=$tcg_tests_targets" >> $config_host_mak
1689c0031d38SFabiano Rosasfi
16902038f8c8SPaolo Bonzini
1691a5665051SPaolo Bonziniif test "$skip_meson" = no; then
1692fc929892SMarc-André Lureau  cross="config-meson.cross.new"
1693fc929892SMarc-André Lureau  meson_quote() {
1694ac7ebcc5SPaolo Bonzini    test $# = 0 && return
169547b30835SPaolo Bonzini    echo "'$(echo $* | sed "s/ /','/g")'"
1696fc929892SMarc-André Lureau  }
1697fc929892SMarc-André Lureau
1698fc929892SMarc-André Lureau  echo "# Automatically generated by configure - do not modify" > $cross
1699fc929892SMarc-André Lureau  echo "[properties]" >> $cross
1700d1d5e9eeSAlex Bennée
1701d1d5e9eeSAlex Bennée  # unroll any custom device configs
1702d1d5e9eeSAlex Bennée  for a in $device_archs; do
1703d1d5e9eeSAlex Bennée      eval "c=\$devices_${a}"
1704d1d5e9eeSAlex Bennée      echo "${a}-softmmu = '$c'" >> $cross
1705d1d5e9eeSAlex Bennée  done
1706d1d5e9eeSAlex Bennée
170747b30835SPaolo Bonzini  echo "[built-in options]" >> $cross
1708a2866660SPaolo Bonzini  echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
1709a2866660SPaolo Bonzini  echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
1710e910c7d9SPhilippe Mathieu-Daudé  test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
1711a2866660SPaolo Bonzini  echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
1712a2866660SPaolo Bonzini  echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
1713090a188cSPaolo Bonzini
1714090a188cSPaolo Bonzini  # Only enable by default for git builds and on select OSes
1715090a188cSPaolo Bonzini  echo "# environment defaults, can still be overridden on " >> $cross
1716090a188cSPaolo Bonzini  echo "# the command line" >> $cross
1717090a188cSPaolo Bonzini  if test -e "$source_path/.git" && \
1718d0cda6f4SPaolo Bonzini      { test "$host_os" = linux || test "$host_os" = "windows"; }; then
1719090a188cSPaolo Bonzini      echo 'werror = true' >> $cross
1720090a188cSPaolo Bonzini  fi
1721090a188cSPaolo Bonzini  echo "[project options]" >> $cross
1722090a188cSPaolo Bonzini  if test "$SMBD" != ''; then
1723090a188cSPaolo Bonzini    echo "smbd = $(meson_quote "$SMBD")" >> $cross
1724090a188cSPaolo Bonzini  fi
1725e20d68aaSPaolo Bonzini  if test "${QEMU_GA_MANUFACTURER}" != ''; then
1726e20d68aaSPaolo Bonzini    echo "qemu_ga_manufacturer = $(meson_quote "${QEMU_GA_MANUFACTURER}")" >> $cross
1727e20d68aaSPaolo Bonzini  fi
1728e20d68aaSPaolo Bonzini  if test "${QEMU_GA_DISTRO}" != ''; then
1729e20d68aaSPaolo Bonzini    echo "qemu_ga_distro = $(meson_quote "${QEMU_GA_DISTRO}")" >> $cross
1730e20d68aaSPaolo Bonzini  fi
1731e20d68aaSPaolo Bonzini  if test "${QEMU_GA_VERSION}" != ''; then
1732e20d68aaSPaolo Bonzini    echo "qemu_ga_version = $(meson_quote "${QEMU_GA_VERSION}")" >> $cross
1733e20d68aaSPaolo Bonzini  fi
1734090a188cSPaolo Bonzini
1735090a188cSPaolo Bonzini  echo >> $cross
1736fc929892SMarc-André Lureau  echo "[binaries]" >> $cross
17374dba2789SPaolo Bonzini  echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
17384dba2789SPaolo Bonzini  test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
17394dba2789SPaolo Bonzini  test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
174047b30835SPaolo Bonzini  echo "ar = [$(meson_quote $ar)]" >> $cross
174109f17983SAlex Bennée  echo "dlltool = [$(meson_quote $dlltool)]" >> $cross
174247b30835SPaolo Bonzini  echo "nm = [$(meson_quote $nm)]" >> $cross
1743877c5567SPaolo Bonzini  echo "pkgconfig = [$(meson_quote $pkg_config)]" >> $cross
174452814898SPaolo Bonzini  echo "pkg-config = [$(meson_quote $pkg_config)]" >> $cross
174547b30835SPaolo Bonzini  echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
1746e8178514SPaolo Bonzini  if has $sdl2_config; then
174747b30835SPaolo Bonzini    echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
1748e8178514SPaolo Bonzini  fi
174947b30835SPaolo Bonzini  echo "strip = [$(meson_quote $strip)]" >> $cross
1750158bb224SKonstantin Kostiuk  echo "widl = [$(meson_quote $widl)]" >> $cross
175147b30835SPaolo Bonzini  echo "windres = [$(meson_quote $windres)]" >> $cross
1752f9f0e617SAndrey Drobyshev  echo "windmc = [$(meson_quote $windmc)]" >> $cross
17533812c0c4SJoelle van Dyne  if test "$cross_compile" = "yes"; then
1754fc929892SMarc-André Lureau    echo "[host_machine]" >> $cross
1755d0cda6f4SPaolo Bonzini    echo "system = '$host_os'" >> $cross
1756823eb013SPaolo Bonzini    case "$cpu" in
1757f6bca9dfSJoelle van Dyne        i386)
1758fc929892SMarc-André Lureau            echo "cpu_family = 'x86'" >> $cross
1759fc929892SMarc-André Lureau            ;;
1760fc929892SMarc-André Lureau        *)
1761823eb013SPaolo Bonzini            echo "cpu_family = '$cpu'" >> $cross
1762fc929892SMarc-André Lureau            ;;
1763fc929892SMarc-André Lureau    esac
1764fc929892SMarc-André Lureau    echo "cpu = '$cpu'" >> $cross
1765fc929892SMarc-André Lureau    if test "$bigendian" = "yes" ; then
1766fc929892SMarc-André Lureau        echo "endian = 'big'" >> $cross
1767fc929892SMarc-André Lureau    else
1768fc929892SMarc-André Lureau        echo "endian = 'little'" >> $cross
1769fc929892SMarc-André Lureau    fi
17703c7ee49bSPaolo Bonzini
17713c7ee49bSPaolo Bonzini    native="config-meson.native.new"
17723c7ee49bSPaolo Bonzini    echo "# Automatically generated by configure - do not modify" > $native
17733c7ee49bSPaolo Bonzini    echo "[binaries]" >> $native
17743c7ee49bSPaolo Bonzini    echo "c = [$(meson_quote $host_cc)]" >> $native
17753c7ee49bSPaolo Bonzini    mv $native config-meson.native
1776c36dd41bSPaolo Bonzini    meson_option_add --native-file
1777c36dd41bSPaolo Bonzini    meson_option_add config-meson.native
1778fc929892SMarc-André Lureau  fi
1779fc929892SMarc-André Lureau  mv $cross config-meson.cross
1780c36dd41bSPaolo Bonzini  meson_add_machine_file config-meson.cross
1781d0cda6f4SPaolo Bonzini  if test -f "$source_path/configs/meson/$host_os.txt"; then
1782d0cda6f4SPaolo Bonzini    meson_add_machine_file $source_path/configs/meson/$host_os.txt
1783c36dd41bSPaolo Bonzini  fi
1784fc929892SMarc-André Lureau
1785a5665051SPaolo Bonzini  rm -rf meson-private meson-info meson-logs
17860a31e3a0SPaolo Bonzini
1787ac4ccac7SPaolo Bonzini  test "$download" = "disabled" && meson_option_add "--wrap-mode=nodownload"
17880a31e3a0SPaolo Bonzini  test "$default_feature" = no && meson_option_add -Dauto_features=disabled
1789a0cbd2e8SPaolo Bonzini  test "$static" = yes && meson_option_add -Dprefer_static=true
17900a31e3a0SPaolo Bonzini  test "$pie" = no && meson_option_add -Db_pie=false
17910a31e3a0SPaolo Bonzini
17920a31e3a0SPaolo Bonzini  # QEMU options
1793ae22ae65SPaolo Bonzini  test "$cfi" != false && meson_option_add "-Dcfi=$cfi" "-Db_lto=$cfi"
17946b0cedcdSJohn Snow  test "$docs" != auto && meson_option_add "-Ddocs=$docs"
17950a31e3a0SPaolo Bonzini  test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
17962c13c574SPaolo Bonzini  test "$plugins" = yes && meson_option_add "-Dplugins=true"
17970a31e3a0SPaolo Bonzini  test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
179861d63097SPaolo Bonzini  run_meson() {
1799c36dd41bSPaolo Bonzini    NINJA=$ninja $meson setup "$@" "$PWD" "$source_path"
180061d63097SPaolo Bonzini  }
180161d63097SPaolo Bonzini  eval run_meson $meson_options
1802a5665051SPaolo Bonzini  if test "$?" -ne 0 ; then
1803a5665051SPaolo Bonzini      error_exit "meson setup failed"
1804a5665051SPaolo Bonzini  fi
18056c5f893dSPaolo Bonzini  echo "$meson" > build.ninja.stamp
1806973038dbSPaolo Bonzinielse
1807973038dbSPaolo Bonzini  if test -f meson-private/cmd_line.txt; then
1808973038dbSPaolo Bonzini    # Adjust old command line options that were removed
1809973038dbSPaolo Bonzini    # sed -i is not portable
1810973038dbSPaolo Bonzini    perl -i -ne '
1811973038dbSPaolo Bonzini      /^sphinx_build/ && next;
1812973038dbSPaolo Bonzini      print;' meson-private/cmd_line.txt
1813973038dbSPaolo Bonzini  fi
1814a5665051SPaolo Bonzinifi
1815a5665051SPaolo Bonzini
1816dc655404SMichael S. Tsirkin# Save the configure command line for later reuse.
1817dc655404SMichael S. Tsirkincat <<EOD >config.status
1818dc655404SMichael S. Tsirkin#!/bin/sh
1819dc655404SMichael S. Tsirkin# Generated by configure.
1820dc655404SMichael S. Tsirkin# Run this file to recreate the current configuration.
1821dc655404SMichael S. Tsirkin# Compiler output produced by configure, useful for debugging
1822dc655404SMichael S. Tsirkin# configure, is in config.log if it exists.
1823dc655404SMichael S. TsirkinEOD
1824e811da7fSDaniel P. Berrangé
1825e811da7fSDaniel P. Berrangépreserve_env() {
1826e811da7fSDaniel P. Berrangé    envname=$1
1827e811da7fSDaniel P. Berrangé
1828e811da7fSDaniel P. Berrangé    eval envval=\$$envname
1829e811da7fSDaniel P. Berrangé
1830e811da7fSDaniel P. Berrangé    if test -n "$envval"
1831e811da7fSDaniel P. Berrangé    then
1832e811da7fSDaniel P. Berrangé	echo "$envname='$envval'" >> config.status
1833e811da7fSDaniel P. Berrangé	echo "export $envname" >> config.status
1834e811da7fSDaniel P. Berrangé    else
1835e811da7fSDaniel P. Berrangé	echo "unset $envname" >> config.status
1836e811da7fSDaniel P. Berrangé    fi
1837e811da7fSDaniel P. Berrangé}
1838e811da7fSDaniel P. Berrangé
1839e811da7fSDaniel P. Berrangé# Preserve various env variables that influence what
1840e811da7fSDaniel P. Berrangé# features/build target configure will detect
1841e811da7fSDaniel P. Berrangépreserve_env AR
1842e811da7fSDaniel P. Berrangépreserve_env AS
1843e811da7fSDaniel P. Berrangépreserve_env CC
18448009da03SPaolo Bonzinipreserve_env CFLAGS
1845e811da7fSDaniel P. Berrangépreserve_env CXX
18468009da03SPaolo Bonzinipreserve_env CXXFLAGS
184709f17983SAlex Bennéepreserve_env DLLTOOL
1848e811da7fSDaniel P. Berrangépreserve_env LD
18498009da03SPaolo Bonzinipreserve_env LDFLAGS
1850e811da7fSDaniel P. Berrangépreserve_env LD_LIBRARY_PATH
1851e811da7fSDaniel P. Berrangépreserve_env NM
1852b5569e5bSPaolo Bonzinipreserve_env OBJCFLAGS
1853e811da7fSDaniel P. Berrangépreserve_env OBJCOPY
1854e811da7fSDaniel P. Berrangépreserve_env PATH
1855e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG
1856e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_LIBDIR
1857e811da7fSDaniel P. Berrangépreserve_env PKG_CONFIG_PATH
1858e811da7fSDaniel P. Berrangépreserve_env PYTHON
1859954ed68fSPaolo Bonzinipreserve_env QEMU_GA_MANUFACTURER
1860954ed68fSPaolo Bonzinipreserve_env QEMU_GA_DISTRO
1861954ed68fSPaolo Bonzinipreserve_env QEMU_GA_VERSION
1862e811da7fSDaniel P. Berrangépreserve_env SDL2_CONFIG
1863e811da7fSDaniel P. Berrangépreserve_env SMBD
1864e811da7fSDaniel P. Berrangépreserve_env STRIP
1865158bb224SKonstantin Kostiukpreserve_env WIDL
1866e811da7fSDaniel P. Berrangépreserve_env WINDRES
1867f9f0e617SAndrey Drobyshevpreserve_env WINDMC
1868e811da7fSDaniel P. Berrangé
1869dc655404SMichael S. Tsirkinprintf "exec" >>config.status
1870a5665051SPaolo Bonzinifor i in "$0" "$@"; do
1871835af899SPaolo Bonzini  test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
1872a5665051SPaolo Bonzinidone
1873cf7cc929SDr. David Alan Gilbertecho ' "$@"' >>config.status
1874dc655404SMichael S. Tsirkinchmod +x config.status
1875dc655404SMichael S. Tsirkin
18768cd05ab6SPeter Maydellrm -r "$TMPDIR1"
1877