xref: /qemu/configure (revision c5f122fdcc280a82e7c5f31de890f985aa7ba773)
1#!/bin/sh
2#
3# qemu configure script (c) 2003 Fabrice Bellard
4#
5
6# Unset some variables known to interfere with behavior of common tools,
7# just as autoconf does.  Unlike autoconf, we assume that unset exists.
8unset CLICOLOR_FORCE GREP_OPTIONS BASH_ENV ENV MAIL MAILPATH CDPATH
9
10# Don't allow CCACHE, if present, to use cached results of compile tests!
11export CCACHE_RECACHE=yes
12
13# make source path absolute
14source_path=$(cd "$(dirname -- "$0")"; pwd)
15
16if test "$PWD" -ef "$source_path"
17then
18    echo "Using './build' as the directory for build output"
19
20    MARKER=build/auto-created-by-configure
21
22    if test -e build
23    then
24        if test -f $MARKER
25        then
26           rm -rf build
27        else
28            echo "ERROR: ./build dir already exists and was not previously created by configure"
29            exit 1
30        fi
31    fi
32
33    if ! mkdir build || ! touch $MARKER
34    then
35        echo "ERROR: Could not create ./build directory. Check the permissions on"
36        echo "your source directory, or try doing an out-of-tree build."
37        exit 1
38    fi
39
40    cat > GNUmakefile <<'EOF'
41# This file is auto-generated by configure to support in-source tree
42# 'make' command invocation
43
44build:
45	@echo 'changing dir to build for $(MAKE) "$(MAKECMDGOALS)"...'
46	@$(MAKE) -C build -f Makefile $(MAKECMDGOALS)
47	@if test "$(MAKECMDGOALS)" = "distclean" && \
48	    test -e build/auto-created-by-configure ; \
49	then \
50	    rm -rf build GNUmakefile ; \
51	fi
52%: build
53	@
54.PHONY: build
55GNUmakefile: ;
56
57EOF
58    cd build
59    exec "$source_path/configure" "$@"
60fi
61
62# Temporary directory used for files created while
63# configure runs. Since it is in the build directory
64# we can safely blow away any previous version of it
65# (and we need not jump through hoops to try to delete
66# it when configure exits.)
67TMPDIR1="config-temp"
68rm -rf "${TMPDIR1}"
69if ! mkdir -p "${TMPDIR1}"; then
70    echo "ERROR: failed to create temporary directory"
71    exit 1
72fi
73
74TMPB="qemu-conf"
75TMPC="${TMPDIR1}/${TMPB}.c"
76TMPO="${TMPDIR1}/${TMPB}.o"
77TMPE="${TMPDIR1}/${TMPB}.exe"
78
79rm -f config.log
80
81# Print a helpful header at the top of config.log
82echo "# QEMU configure log $(date)" >> config.log
83printf "# Configured with:" >> config.log
84# repeat the invocation to log and stdout for CI
85invoke=$(printf " '%s'" "$0" "$@")
86test -n "$GITLAB_CI" && echo "configuring with: $invoke"
87{ echo "$invoke"; echo; echo "#"; } >> config.log
88
89quote_sh() {
90    printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
91}
92
93error_exit() {
94    (echo
95    echo "ERROR: $1"
96    while test -n "$2"; do
97        echo "       $2"
98        shift
99    done
100    echo) >&2
101    exit 1
102}
103
104do_compiler() {
105  # Run the compiler, capturing its output to the log. First argument
106  # is compiler binary to execute.
107  compiler="$1"
108  shift
109  if test -n "$BASH_VERSION"; then eval '
110      echo >>config.log "
111funcs: ${FUNCNAME[*]}
112lines: ${BASH_LINENO[*]}"
113  '; fi
114  echo $compiler "$@" >> config.log
115  $compiler "$@" >> config.log 2>&1 || return $?
116}
117
118do_cc() {
119    do_compiler "$cc" $CPU_CFLAGS "$@"
120}
121
122compile_object() {
123  local_cflags="$1"
124  do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -c -o $TMPO $TMPC
125}
126
127compile_prog() {
128  local_cflags="$1"
129  local_ldflags="$2"
130  do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -o $TMPE $TMPC \
131      $LDFLAGS $EXTRA_LDFLAGS $local_ldflags
132}
133
134# symbolically link $1 to $2.  Portable version of "ln -sf".
135symlink() {
136  rm -rf "$2"
137  mkdir -p "$(dirname "$2")"
138  ln -s "$1" "$2"
139}
140
141# check whether a command is available to this shell (may be either an
142# executable or a builtin)
143has() {
144    type "$1" >/dev/null 2>&1
145}
146
147version_ge () {
148    local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
149    local_ver2=$(echo "$2" | tr . ' ')
150    while true; do
151        set x $local_ver1
152        local_first=${2-0}
153        # 'shift 2' if $2 is set, or 'shift' if $2 is not set
154        shift ${2:+2}
155        local_ver1=$*
156        set x $local_ver2
157        # the second argument finished, the first must be greater or equal
158        test $# = 1 && return 0
159        test $local_first -lt $2 && return 1
160        test $local_first -gt $2 && return 0
161        shift ${2:+2}
162        local_ver2=$*
163    done
164}
165
166if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
167then
168  error_exit "main directory cannot contain spaces nor colons"
169fi
170
171# parse CC options first; some compiler tests are used to establish
172# some defaults, based on the host environment
173
174# default parameters
175container_engine="auto"
176cpu=""
177cross_compile="no"
178cross_prefix=""
179host_cc="cc"
180EXTRA_CFLAGS=""
181EXTRA_CXXFLAGS=""
182EXTRA_OBJCFLAGS=""
183EXTRA_LDFLAGS=""
184
185# Default value for a variable defining feature "foo".
186#  * foo="no"  feature will only be used if --enable-foo arg is given
187#  * foo=""    feature will be searched for, and if found, will be used
188#              unless --disable-foo is given
189#  * foo="yes" this value will only be set by --enable-foo flag.
190#              feature will searched for,
191#              if not found, configure exits with error
192#
193# Always add --enable-foo and --disable-foo command line args.
194# Distributions want to ensure that several features are compiled in, and it
195# is impossible without a --enable-foo that exits if a feature is not found.
196default_feature=""
197
198for opt do
199  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
200  case "$opt" in
201  --cross-prefix=*) cross_prefix="$optarg"
202                    cross_compile="yes"
203  ;;
204  --cc=*) CC="$optarg"
205  ;;
206  --cxx=*) CXX="$optarg"
207  ;;
208  --objcc=*) objcc="$optarg"
209  ;;
210  --rustc=*) RUSTC="$optarg"
211  ;;
212  --cpu=*) cpu="$optarg"
213  ;;
214  --extra-cflags=*)
215    EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
216    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
217    EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
218    ;;
219  --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
220  ;;
221  --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
222  ;;
223  --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
224  ;;
225  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
226  ;;
227  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
228                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
229  ;;
230  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
231                eval "cross_cc_${cc_arch}=\$optarg"
232  ;;
233  --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-prefix-FOO option"
234  ;;
235  --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
236                    eval "cross_prefix_${cc_arch}=\$optarg"
237  ;;
238  --without-default-features) default_feature="no"
239  ;;
240  esac
241done
242
243default_cflags='-O2 -g'
244git_submodules_action="update"
245docs="auto"
246EXESUF=""
247system="yes"
248linux_user=""
249bsd_user=""
250plugins="$default_feature"
251subdirs=""
252ninja=""
253python=
254download="enabled"
255skip_meson=no
256use_containers="yes"
257rust="disabled"
258rust_target_triple=""
259gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
260gdb_arches=""
261
262# Don't accept a target_list environment variable.
263unset target_list
264unset target_list_exclude
265
266# The following Meson options are handled manually (still they
267# are included in the automatically generated help message)
268# because they automatically enable/disable other options
269tcg="auto"
270cfi="false"
271
272# Meson has PIE as a boolean rather than enabled/disabled/auto,
273# and we also need to check for -static-pie before Meson runs
274# which requires knowing whether --static is enabled.
275pie=""
276static="no"
277
278# Preferred compiler:
279#  ${CC} (if set)
280#  ${cross_prefix}gcc (if cross-prefix specified)
281#  system compiler
282if test -z "${CC}${cross_prefix}"; then
283  cc="cc"
284else
285  cc="${CC-${cross_prefix}gcc}"
286fi
287
288if test -z "${CXX}${cross_prefix}"; then
289  cxx="c++"
290else
291  cxx="${CXX-${cross_prefix}g++}"
292fi
293
294# Preferred ObjC compiler:
295# $objcc (if set, i.e. via --objcc option)
296# ${cross_prefix}clang (if cross-prefix specified)
297# clang (if available)
298# $cc
299if test -z "${objcc}${cross_prefix}"; then
300  if has clang; then
301    objcc=clang
302  else
303    objcc="$cc"
304  fi
305else
306  objcc="${objcc-${cross_prefix}clang}"
307fi
308
309ar="${AR-${cross_prefix}ar}"
310as="${AS-${cross_prefix}as}"
311ccas="${CCAS-$cc}"
312dlltool="${DLLTOOL-${cross_prefix}dlltool}"
313objcopy="${OBJCOPY-${cross_prefix}objcopy}"
314ld="${LD-${cross_prefix}ld}"
315ranlib="${RANLIB-${cross_prefix}ranlib}"
316nm="${NM-${cross_prefix}nm}"
317readelf="${READELF-${cross_prefix}readelf}"
318strip="${STRIP-${cross_prefix}strip}"
319widl="${WIDL-${cross_prefix}widl}"
320windres="${WINDRES-${cross_prefix}windres}"
321windmc="${WINDMC-${cross_prefix}windmc}"
322pkg_config="${PKG_CONFIG-${cross_prefix}pkg-config}"
323sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
324
325rustc="${RUSTC-rustc}"
326
327check_define() {
328cat > $TMPC <<EOF
329#if !defined($1)
330#error $1 not defined
331#endif
332int main(void) { return 0; }
333EOF
334  compile_object
335}
336
337write_c_skeleton() {
338    cat > $TMPC <<EOF
339int main(void) { return 0; }
340EOF
341}
342
343if check_define __linux__ ; then
344  host_os=linux
345elif check_define _WIN32 ; then
346  host_os=windows
347elif check_define __OpenBSD__ ; then
348  host_os=openbsd
349elif check_define __sun__ ; then
350  host_os=sunos
351elif check_define __HAIKU__ ; then
352  host_os=haiku
353elif check_define __FreeBSD__ ; then
354  host_os=freebsd
355elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
356  host_os=gnu/kfreebsd
357elif check_define __DragonFly__ ; then
358  host_os=dragonfly
359elif check_define __NetBSD__; then
360  host_os=netbsd
361elif check_define __APPLE__; then
362  host_os=darwin
363elif check_define EMSCRIPTEN ; then
364  host_os=emscripten
365  cpu=wasm32
366  cross_compile="yes"
367else
368  # This is a fatal error, but don't report it yet, because we
369  # might be going to just print the --help text, or it might
370  # be the result of a missing compiler.
371  host_os=bogus
372fi
373
374if test ! -z "$cpu" ; then
375  # command line argument
376  :
377elif check_define __i386__ ; then
378  cpu="i386"
379elif check_define __x86_64__ ; then
380  if check_define __ILP32__ ; then
381    cpu="x32"
382  else
383    cpu="x86_64"
384  fi
385elif check_define __sparc__ ; then
386  if check_define __arch64__ ; then
387    cpu="sparc64"
388  else
389    cpu="sparc"
390  fi
391elif check_define _ARCH_PPC ; then
392  if check_define _ARCH_PPC64 ; then
393    if check_define _LITTLE_ENDIAN ; then
394      cpu="ppc64le"
395    else
396      cpu="ppc64"
397    fi
398  else
399    cpu="ppc"
400  fi
401elif check_define __mips__ ; then
402  if check_define __mips64 ; then
403    cpu="mips64"
404  else
405    cpu="mips"
406  fi
407elif check_define __s390__ ; then
408  if check_define __s390x__ ; then
409    cpu="s390x"
410  else
411    cpu="s390"
412  fi
413elif check_define __riscv ; then
414  if check_define _LP64 ; then
415    cpu="riscv64"
416  else
417    cpu="riscv32"
418  fi
419elif check_define __arm__ ; then
420  cpu="arm"
421elif check_define __aarch64__ ; then
422  cpu="aarch64"
423elif check_define __loongarch64 ; then
424  cpu="loongarch64"
425else
426  # Using uname is really broken, but it is just a fallback for architectures
427  # that are going to use TCI anyway
428  cpu=$(uname -m)
429  if test "$host_os" != "bogus"; then
430    echo "WARNING: unrecognized host CPU, proceeding with 'uname -m' output '$cpu'"
431  fi
432fi
433
434# Normalise host CPU name to the values used by Meson cross files and in source
435# directories, and set multilib cflags.  The canonicalization isn't really
436# necessary, because the architectures that we check for should not hit the
437# 'uname -m' case, but better safe than sorry in case --cpu= is used.
438#
439# Note that this case should only have supported host CPUs, not guests.
440# Please keep it sorted and synchronized with meson.build's host_arch.
441host_arch=
442linux_arch=
443raw_cpu=$cpu
444case "$cpu" in
445  aarch64)
446    host_arch=aarch64
447    linux_arch=arm64
448    ;;
449
450  armv*b|armv*l|arm)
451    cpu=arm
452    host_arch=arm
453    linux_arch=arm
454    ;;
455
456  i386|i486|i586|i686)
457    cpu="i386"
458    host_arch=i386
459    linux_arch=x86
460    CPU_CFLAGS="-m32"
461    ;;
462
463  loongarch*)
464    cpu=loongarch64
465    host_arch=loongarch64
466    linux_arch=loongarch
467    ;;
468
469  mips64*|mipsisa64*)
470    cpu=mips64
471    host_arch=mips
472    linux_arch=mips
473    ;;
474  mips*)
475    cpu=mips
476    host_arch=mips
477    linux_arch=mips
478    ;;
479
480  ppc)
481    host_arch=ppc
482    linux_arch=powerpc
483    CPU_CFLAGS="-m32"
484    ;;
485  ppc64)
486    host_arch=ppc64
487    linux_arch=powerpc
488    CPU_CFLAGS="-m64 -mbig-endian"
489    ;;
490  ppc64le)
491    cpu=ppc64
492    host_arch=ppc64
493    linux_arch=powerpc
494    CPU_CFLAGS="-m64 -mlittle-endian"
495    ;;
496
497  riscv32 | riscv64)
498    host_arch=riscv
499    linux_arch=riscv
500    ;;
501
502  s390)
503    linux_arch=s390
504    CPU_CFLAGS="-m31"
505    ;;
506  s390x)
507    host_arch=s390x
508    linux_arch=s390
509    CPU_CFLAGS="-m64"
510    ;;
511
512  sparc|sun4[cdmuv])
513    cpu=sparc
514    CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc"
515    ;;
516  sparc64)
517    host_arch=sparc64
518    CPU_CFLAGS="-m64 -mcpu=ultrasparc"
519    ;;
520
521  x32)
522    cpu="x86_64"
523    host_arch=x86_64
524    linux_arch=x86
525    CPU_CFLAGS="-mx32"
526    ;;
527  x86_64|amd64)
528    cpu="x86_64"
529    host_arch=x86_64
530    linux_arch=x86
531    CPU_CFLAGS="-m64"
532    ;;
533  wasm32)
534    CPU_CFLAGS="-m32"
535    ;;
536esac
537
538if test -n "$host_arch" && {
539    ! test -d "$source_path/linux-user/include/host/$host_arch" ||
540    ! test -d "$source_path/common-user/host/$host_arch"; }; then
541    error_exit "linux-user/include/host/$host_arch does not exist." \
542       "This is a bug in the configure script, please report it."
543fi
544if test -n "$linux_arch" && ! test -d "$source_path/linux-headers/asm-$linux_arch"; then
545    error_exit "linux-headers/asm-$linux_arch does not exist." \
546       "This is a bug in the configure script, please report it."
547fi
548
549check_py_version() {
550    # We require python >= 3.9.
551    # NB: a True python conditional creates a non-zero return code (Failure)
552    "$1" -c 'import sys; sys.exit(sys.version_info < (3,9))'
553}
554
555first_python=
556if test -z "${PYTHON}"; then
557    # A bare 'python' is traditionally python 2.x, but some distros
558    # have it as python 3.x, so check in both places.
559    for binary in python3 python python3.13 python3.12 python3.11 \
560                          python3.10 python3.9 ; do
561        if has "$binary"; then
562            python=$(command -v "$binary")
563            if check_py_version "$python"; then
564                # This one is good.
565                first_python=
566                break
567            else
568                first_python=$python
569            fi
570        fi
571    done
572else
573    # Same as above, but only check the environment variable.
574    has "${PYTHON}" || error_exit "The PYTHON environment variable does not point to an executable"
575    python=$(command -v "$PYTHON")
576    if check_py_version "$python"; then
577        # This one is good.
578        first_python=
579    else
580        first_python=$first_python
581    fi
582fi
583
584# Check for ancillary tools used in testing
585genisoimage=
586for binary in genisoimage mkisofs
587do
588    if has $binary
589    then
590        genisoimage=$(command -v "$binary")
591        break
592    fi
593done
594
595if test "$host_os" = "windows" ; then
596  EXESUF=".exe"
597fi
598
599meson_option_build_array() {
600  printf '['
601  (if test "$host_os" = windows; then
602    IFS=\;
603  else
604    IFS=:
605  fi
606  for e in $1; do
607    printf '"""'
608    # backslash escape any '\' and '"' characters
609    printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g'
610    printf '""",'
611  done)
612  printf ']\n'
613}
614
615. "$source_path/scripts/meson-buildoptions.sh"
616
617meson_options=
618meson_option_add() {
619  local arg
620  for arg; do
621    meson_options="$meson_options $(quote_sh "$arg")"
622  done
623}
624meson_option_parse() {
625  meson_options="$meson_options $(_meson_option_parse "$@")"
626  if test $? -eq 1; then
627    echo "ERROR: unknown option $1"
628    echo "Try '$0 --help' for more information"
629    exit 1
630  fi
631}
632has_meson_option() {
633    test "${meson_options#*"$1"}" != "$meson_options"
634}
635
636meson_add_machine_file() {
637  if test "$cross_compile" = "yes"; then
638    meson_option_add --cross-file "$1"
639  else
640    meson_option_add --native-file "$1"
641  fi
642}
643
644for opt do
645  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
646  case "$opt" in
647  --help|-h) show_help=yes
648  ;;
649  --version|-V) exec cat "$source_path/VERSION"
650  ;;
651  --cross-prefix=*)
652  ;;
653  --cc=*)
654  ;;
655  --host-cc=*) host_cc="$optarg"
656  ;;
657  --cxx=*)
658  ;;
659  --objcc=*)
660  ;;
661  --rustc=*)
662  ;;
663  --make=*)
664  ;;
665  --install=*)
666  ;;
667  --python=*) python="$optarg"
668  ;;
669  --skip-meson) skip_meson=yes
670  ;;
671  --ninja=*) ninja="$optarg"
672  ;;
673  --extra-cflags=*)
674  ;;
675  --extra-cxxflags=*)
676  ;;
677  --extra-objcflags=*)
678  ;;
679  --extra-ldflags=*)
680  ;;
681  --cross-cc-*)
682  ;;
683  --cross-prefix-*)
684  ;;
685  --enable-docs) docs=enabled
686  ;;
687  --disable-docs) docs=disabled
688  ;;
689  --cpu=*)
690  ;;
691  --target-list=*) target_list="$optarg"
692                   if test "$target_list_exclude"; then
693                       error_exit "Can't mix --target-list with --target-list-exclude"
694                   fi
695  ;;
696  --target-list-exclude=*) target_list_exclude="$optarg"
697                   if test "$target_list"; then
698                       error_exit "Can't mix --target-list-exclude with --target-list"
699                   fi
700  ;;
701  --with-default-devices) meson_option_add -Ddefault_devices=true
702  ;;
703  --without-default-devices) meson_option_add -Ddefault_devices=false
704  ;;
705  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
706  ;;
707  --with-devices-*) device_arch=${opt#--with-devices-};
708                    device_arch=${device_arch%%=*}
709                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
710                    if test -f "$cf"; then
711                        device_archs="$device_archs $device_arch"
712                        eval "devices_${device_arch}=\$optarg"
713                    else
714                        error_exit "File $cf does not exist"
715                    fi
716  ;;
717  --without-default-features) # processed above
718  ;;
719  --static) static="yes"
720  ;;
721  --host=*|--build=*|\
722  --disable-dependency-tracking|\
723  --sbindir=*|--sharedstatedir=*|\
724  --oldincludedir=*|--datarootdir=*|--infodir=*|\
725  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
726    # These switches are silently ignored, for compatibility with
727    # autoconf-generated configure scripts. This allows QEMU's
728    # configure to be used by RPM and similar macros that set
729    # lots of directory switches by default.
730  ;;
731  --enable-debug)
732      # Enable debugging options that aren't excessively noisy
733      meson_option_parse --enable-debug-tcg ""
734      meson_option_parse --enable-debug-graph-lock ""
735      meson_option_parse --enable-debug-mutex ""
736      meson_option_add -Doptimization=0
737      default_cflags='-O0 -g'
738  ;;
739  --disable-tcg) tcg="disabled"
740  ;;
741  --enable-tcg) tcg="enabled"
742  ;;
743  --disable-system) system="no"
744  ;;
745  --enable-system) system="yes"
746  ;;
747  --disable-user)
748      linux_user="no" ;
749      bsd_user="no" ;
750  ;;
751  --enable-user) ;;
752  --disable-linux-user) linux_user="no"
753  ;;
754  --enable-linux-user) linux_user="yes"
755  ;;
756  --disable-bsd-user) bsd_user="no"
757  ;;
758  --enable-bsd-user) bsd_user="yes"
759  ;;
760  --enable-pie) pie="yes"
761  ;;
762  --disable-pie) pie="no"
763  ;;
764  --enable-cfi) cfi=true
765  ;;
766  --disable-cfi) cfi=false
767  ;;
768  --disable-download) download="disabled"; git_submodules_action=validate;
769  ;;
770  --enable-download) download="enabled"; git_submodules_action=update;
771  ;;
772  --enable-plugins) plugins="yes"
773  ;;
774  --disable-plugins) plugins="no"
775  ;;
776  --enable-containers) use_containers="yes"
777  ;;
778  --disable-containers) use_containers="no"
779  ;;
780  --container-engine=*) container_engine="$optarg"
781  ;;
782  --rust-target-triple=*) rust_target_triple="$optarg"
783  ;;
784  --gdb=*) gdb_bin="$optarg"
785  ;;
786  --enable-rust) rust=enabled
787  ;;
788  --disable-rust) rust=disabled
789  ;;
790  # everything else has the same name in configure and meson
791  --*) meson_option_parse "$opt" "$optarg"
792  ;;
793  # Pass through -Dxxxx options to meson
794  -D*) meson_option_add "$opt"
795  ;;
796  esac
797done
798
799if ! test -e "$source_path/.git"
800then
801    git_submodules_action="validate"
802fi
803
804if ! test -f "$source_path/subprojects/keycodemapdb/README" \
805    && test "$download" = disabled
806then
807    echo
808    echo "ERROR: missing subprojects"
809    echo
810    if test -e "$source_path/.git"; then
811        echo "--disable-download specified but subprojects were not"
812        echo 'checked out.  Please invoke "meson subprojects download"'
813        echo "before configuring QEMU, or remove --disable-download"
814        echo "from the command line."
815    else
816        echo "This is not a GIT checkout but subproject content appears to"
817        echo "be missing. Do not use 'git archive' or GitHub download links"
818        echo "to acquire QEMU source archives. Non-GIT builds are only"
819        echo "supported with source archives linked from:"
820        echo
821        echo "  https://www.qemu.org/download/#source"
822        echo
823        echo "Developers working with GIT can use scripts/archive-source.sh"
824        echo "if they need to create valid source archives."
825    fi
826    echo
827    exit 1
828fi
829
830default_target_list=""
831mak_wilds=""
832
833if [ -n "$host_arch" ] && [ -d "$source_path/common-user/host/$host_arch" ]; then
834    if [ "$linux_user" != no ]; then
835        if [ "$host_os" = linux ]; then
836            linux_user=yes
837        elif [ "$linux_user" = yes ]; then
838            error_exit "linux-user not supported on this architecture"
839        fi
840        if [ "$linux_user" = "yes" ]; then
841            mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
842        fi
843    fi
844    if [ "$bsd_user" != no ]; then
845        if [ "$bsd_user" = "" ]; then
846            test $host_os = freebsd && bsd_user=yes
847        fi
848        if [ "$bsd_user" = yes ] && ! [ -d "$source_path/bsd-user/$host_os" ]; then
849            error_exit "bsd-user not supported on this host OS"
850        fi
851        if [ "$bsd_user" = "yes" ]; then
852            mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
853        fi
854    fi
855else
856    if [ "$linux_user" = yes ] || [ "$bsd_user" = yes ]; then
857        error_exit "user mode emulation not supported on this architecture"
858    fi
859fi
860if [ "$system" = "yes" ]; then
861    mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
862fi
863
864for config in $mak_wilds; do
865    target="$(basename "$config" .mak)"
866    if echo "$target_list_exclude" | grep -vq "$target"; then
867        default_target_list="${default_target_list} $target"
868    fi
869done
870
871if test x"$show_help" = x"yes" ; then
872cat << EOF
873
874Usage: configure [options]
875Options: [defaults in brackets after descriptions]
876
877Standard options:
878  --help                   print this message
879  --target-list=LIST       set target list (default: build all)
880$(echo Available targets: $default_target_list | \
881  fold -s -w 53 | sed -e 's/^/                           /')
882  --target-list-exclude=LIST exclude a set of targets from the default target-list
883
884Advanced options (experts only):
885  -Dmesonoptname=val       passthrough option to meson unmodified
886  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
887  --cc=CC                  use C compiler CC [$cc]
888  --host-cc=CC             when cross compiling, use C compiler CC for code run
889                           at build time [$host_cc]
890  --cxx=CXX                use C++ compiler CXX [$cxx]
891  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
892  --rustc=RUSTC            use Rust compiler RUSTC [$rustc]
893  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
894  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
895  --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
896  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
897  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
898  --cross-cc-cflags-ARCH=  use compiler flags when building ARCH guest tests
899  --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
900  --python=PYTHON          use specified python [$python]
901  --ninja=NINJA            use specified ninja [$ninja]
902  --static                 enable static build [$static]
903  --rust-target-triple=TRIPLE  compilation target for Rust code [autodetect]
904  --without-default-features   default all --enable-* options to "disabled"
905  --without-default-devices    do not include any device that is not needed to
906                           start the emulator (only use if you are including
907                           desired devices in configs/devices/)
908  --with-devices-ARCH=NAME override default configs/devices
909  --enable-debug           enable common debug build options
910  --cpu=CPU                Build for host CPU [$cpu]
911  --disable-containers     don't use containers for cross-building
912  --container-engine=TYPE  which container engine to use [$container_engine]
913  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
914EOF
915  meson_options_help
916cat << EOF
917  system          all system emulation targets
918  user            supported user emulation targets
919  linux-user      all linux usermode emulation targets
920  bsd-user        all BSD usermode emulation targets
921  pie             Position Independent Executables
922
923NOTE: The object files are built at the place where configure is launched
924EOF
925exit 0
926fi
927
928# Now that we are sure that the user did not only want to print the --help
929# information, we should double-check that the C compiler really works:
930write_c_skeleton
931if ! compile_object ; then
932    error_exit "C compiler \"$cc\" either does not exist or does not work."
933fi
934
935# Remove old dependency files to make sure that they get properly regenerated
936rm -f ./*/config-devices.mak.d
937
938if test -z "$python"
939then
940    # If first_python is set, there was a binary somewhere even though
941    # it was not suitable.  Use it for the error message.
942    if test -n "$first_python"; then
943        error_exit "Cannot use '$first_python', Python >= 3.9 is required." \
944            "Use --python=/path/to/python to specify a supported Python."
945    else
946        error_exit "Python not found. Use --python=/path/to/python"
947    fi
948fi
949
950if ! check_py_version "$python"; then
951  error_exit "Cannot use '$python', Python >= 3.9 is required." \
952             "Use --python=/path/to/python to specify a supported Python." \
953             "Maybe try:" \
954             "  openSUSE Leap 15.3+: zypper install python39" \
955             "  CentOS: dnf install python3.12"
956fi
957
958# Resolve PATH
959python="$(command -v "$python")"
960
961# Create a Python virtual environment using our configured python.
962# The stdout of this script will be the location of a symlink that
963# points to the configured Python.
964# Entry point scripts for pip, meson, and sphinx are generated if those
965# packages are present.
966
967# Defaults assumed for now:
968# - venv is cleared if it exists already;
969# - venv is allowed to use system packages;
970# - all setup can be performed offline;
971# - missing packages may be fetched from PyPI,
972#   unless --disable-download is passed.
973# - pip is not installed into the venv when possible,
974#   but ensurepip is called as a fallback when necessary.
975
976echo "python determined to be '$python'"
977echo "python version: $($python --version)"
978
979python="$($python -B "${source_path}/python/scripts/mkvenv.py" create pyvenv)"
980if test "$?" -ne 0 ; then
981    error_exit "python venv creation failed"
982fi
983
984# Suppress writing compiled files
985python="$python -B"
986mkvenv="$python ${source_path}/python/scripts/mkvenv.py"
987
988# Finish preparing the virtual environment using vendored .whl files
989
990$mkvenv ensuregroup --dir "${source_path}/python/wheels" \
991     ${source_path}/pythondeps.toml meson || exit 1
992
993# At this point, we expect Meson to be installed and available.
994# We expect mkvenv or pip to have created pyvenv/bin/meson for us.
995# We ignore PATH completely here: we want to use the venv's Meson
996# *exclusively*.
997
998meson="$(cd pyvenv/bin; pwd)/meson"
999
1000# Conditionally ensure Sphinx is installed.
1001
1002mkvenv_online_flag=""
1003if test "$download" = "enabled" ; then
1004    mkvenv_online_flag=" --online"
1005fi
1006
1007if test "$docs" != "disabled" ; then
1008    if ! $mkvenv ensuregroup \
1009         $(test "$docs" = "enabled" && echo "$mkvenv_online_flag") \
1010         ${source_path}/pythondeps.toml docs;
1011    then
1012        if test "$docs" = "enabled" ; then
1013            exit 1
1014        fi
1015        echo "Sphinx not found/usable, disabling docs."
1016        docs=disabled
1017    else
1018        docs=enabled
1019    fi
1020fi
1021
1022# Probe for ninja
1023
1024if test -z "$ninja"; then
1025    for c in ninja ninja-build samu; do
1026        if has $c; then
1027            ninja=$(command -v "$c")
1028            break
1029        fi
1030    done
1031    if test -z "$ninja"; then
1032      error_exit "Cannot find Ninja"
1033    fi
1034fi
1035
1036if test "$host_os" = "bogus"; then
1037    # Now that we know that we're not printing the help and that
1038    # the compiler works (so the results of the check_defines we used
1039    # to identify the OS are reliable), if we didn't recognize the
1040    # host OS we should stop now.
1041    error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1042fi
1043
1044# test for any invalid configuration combinations
1045if test "$host_os" = "windows" && ! has "$dlltool"; then
1046  if test "$plugins" = "yes"; then
1047    error_exit "TCG plugins requires dlltool to build on Windows platforms"
1048  fi
1049  plugins="no"
1050fi
1051if test "$tcg" = "disabled" ; then
1052  if test "$plugins" = "yes"; then
1053    error_exit "Can't enable plugins on non-TCG builds"
1054  fi
1055  plugins="no"
1056fi
1057if test "$static" = "yes" ; then
1058  if test "$plugins" = "yes"; then
1059    error_exit "static and plugins are mutually incompatible"
1060  fi
1061  plugins="no"
1062fi
1063if test "$plugins" != "no"; then
1064    if has_meson_option "-Dtcg_interpreter=true"; then
1065        plugins="no"
1066    else
1067        plugins=yes
1068    fi
1069fi
1070
1071cat > $TMPC << EOF
1072
1073#ifdef __linux__
1074#  define THREAD __thread
1075#else
1076#  define THREAD
1077#endif
1078static THREAD int tls_var;
1079int main(void) { return tls_var; }
1080EOF
1081
1082if test "$host_os" = windows || test "$host_os" = haiku; then
1083  if test "$pie" = "yes"; then
1084    error_exit "PIE not available due to missing OS support"
1085  fi
1086  pie=no
1087fi
1088
1089if test "$pie" != "no"; then
1090  if test "$static" = "yes"; then
1091    pie_ldflags=-static-pie
1092  else
1093    pie_ldflags=-pie
1094  fi
1095  if compile_prog "-Werror -fPIE -DPIE" "$pie_ldflags"; then
1096    pie="yes"
1097  elif test "$pie" = "yes"; then
1098    error_exit "-static-pie not available due to missing toolchain support"
1099  else
1100    echo "Disabling PIE due to missing toolchain support"
1101    pie="no"
1102  fi
1103fi
1104
1105##########################################
1106
1107if test -z "${target_list+xxx}" ; then
1108    default_targets=yes
1109    for target in $default_target_list; do
1110        target_list="$target_list $target"
1111    done
1112    target_list="${target_list# }"
1113else
1114    default_targets=no
1115    target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1116    for target in $target_list; do
1117        # Check that we recognised the target name; this allows a more
1118        # friendly error message than if we let it fall through.
1119        case " $default_target_list " in
1120            *" $target "*)
1121                ;;
1122            *)
1123                error_exit "Unknown target name '$target'"
1124                ;;
1125        esac
1126    done
1127fi
1128
1129if test "$tcg" = "auto"; then
1130  if test -z "$target_list"; then
1131    tcg="disabled"
1132  else
1133    tcg="enabled"
1134  fi
1135fi
1136
1137#########################################
1138# gdb test
1139
1140if test -n "$gdb_bin"; then
1141    gdb_version_string=$($gdb_bin --version | head -n 1)
1142    # Extract last field in the version string
1143    gdb_version=${gdb_version_string##* }
1144    if version_ge $gdb_version 9.1; then
1145        gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
1146    else
1147        gdb_bin=""
1148    fi
1149fi
1150
1151##########################################
1152# big/little endian test
1153cat > $TMPC << EOF
1154#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1155# error LITTLE
1156#endif
1157int main(void) { return 0; }
1158EOF
1159
1160if ! compile_prog ; then
1161  bigendian="no"
1162else
1163  cat > $TMPC << EOF
1164#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
1165# error BIG
1166#endif
1167int main(void) { return 0; }
1168EOF
1169
1170  if ! compile_prog ; then
1171    bigendian="yes"
1172  else
1173    echo big/little test failed
1174    exit 1
1175  fi
1176fi
1177
1178##########################################
1179# detect rust triple
1180
1181if test "$rust" != disabled && has "$rustc" && $rustc -vV > "${TMPDIR1}/${TMPB}.out"; then
1182  rust_host_triple=$(sed -n 's/^host: //p' "${TMPDIR1}/${TMPB}.out")
1183else
1184  if test "$rust" = enabled; then
1185    error_exit "could not execute rustc binary \"$rustc\""
1186  fi
1187  rust=disabled
1188fi
1189if test "$rust" != disabled && test -z "$rust_target_triple"; then
1190  # arch and os generally matches between meson and rust
1191  rust_arch=$host_arch
1192  rust_os=$host_os
1193  rust_machine=unknown
1194  rust_osvariant=
1195
1196  # tweak rust_os if needed; also, machine and variant depend on the OS
1197  android=no
1198  case "$host_os" in
1199  darwin)
1200    # e.g. aarch64-apple-darwin
1201    rust_machine=apple
1202    ;;
1203
1204  linux)
1205    # detect android/glibc/musl
1206    if check_define __ANDROID__; then
1207      rust_osvariant=android
1208      android=yes
1209    else
1210      cat > $TMPC << EOF
1211#define _GNU_SOURCE
1212#include <features.h>
1213#ifndef __USE_GNU
1214error using musl
1215#endif
1216EOF
1217      if compile_object; then
1218        rust_osvariant=gnu
1219      else
1220        rust_osvariant=musl
1221      fi
1222    fi
1223
1224    case "$cpu" in
1225    arm)
1226      # e.g. arm-unknown-linux-gnueabi, arm-unknown-linux-gnueabihf
1227      write_c_skeleton
1228      compile_object
1229      if $READELF -A $TMPO | grep Tag_API_VFP_args: > /dev/null; then
1230        rust_osvariant=${rust_osvariant}eabihf
1231      else
1232        rust_osvariant=${rust_osvariant}eabi
1233      fi
1234      ;;
1235
1236    mips64)
1237      # e.g. mips64-unknown-linux-gnuabi64
1238      rust_osvariant=${rust_osvariant}abi64
1239      ;;
1240    esac
1241    ;;
1242
1243  netbsd)
1244    # e.g. arm-unknown-netbsd-eabihf
1245    test "$host_arch" = arm && rust_osvariant=eabihf
1246    ;;
1247
1248  sunos)
1249    rust_machine=pc
1250    rust_os=solaris
1251    ;;
1252
1253  windows)
1254    # e.g. aarch64-pc-windows-gnullvm, x86_64-pc-windows-gnu (MSVC not supported)
1255    rust_machine=pc
1256    if test "$host_arch" = aarch64; then
1257      rust_osvariant=gnullvm
1258    else
1259      rust_osvariant=gnu
1260    fi
1261    ;;
1262  esac
1263
1264  # now tweak the architecture part, possibly based on pre-canonicalization --cpu
1265  case "$host_arch" in
1266  arm)
1267    # preserve ISA version (armv7 etc.) from $raw_cpu if passed via --cpu
1268    rust_arch=$raw_cpu
1269    test "$rust_arch" = arm && test "$rust_os" != linux && rust_arch=armv7
1270    ;;
1271
1272  mips)
1273    # preserve ISA version (mipsisa64r6 etc.) and include endianness
1274    rust_arch=${raw_cpu%el}
1275    test "$bigendian" = no && rust_arch=${rust_arch}el
1276    ;;
1277
1278  riscv32|riscv64)
1279    # e.g. riscv64gc-unknown-linux-gnu, but riscv64-linux-android
1280    test "$android" = no && rust_arch=${rust_arch}gc
1281    ;;
1282
1283  sparc64)
1284    if test "$rust_os" = solaris; then
1285      rust_arch=sparcv9
1286      rust_machine=sun
1287    fi
1288    ;;
1289
1290  x86_64)
1291    # e.g. x86_64-unknown-linux-gnux32
1292    test "$raw_cpu" = x32 && rust_osvariant=${rust_osvariant}x32
1293    ;;
1294  esac
1295
1296  if test "$android" = yes; then
1297    # e.g. aarch64-linux-android
1298    rust_target_triple=$rust_arch-$rust_os-$rust_osvariant
1299  else
1300    rust_target_triple=$rust_arch-$rust_machine-$rust_os${rust_osvariant:+-$rust_osvariant}
1301  fi
1302fi
1303
1304##########################################
1305# functions to probe cross compilers
1306
1307container="no"
1308runc=""
1309if test $use_containers = "yes" && (has "docker" || has "podman"); then
1310    case $($python "$source_path"/tests/docker/docker.py --engine "$container_engine" probe) in
1311        *docker) container=docker ;;
1312        podman) container=podman ;;
1313        no) container=no ;;
1314    esac
1315    if test "$container" != "no"; then
1316        docker_py="$python $source_path/tests/docker/docker.py --engine $container"
1317        runc=$container
1318    fi
1319fi
1320
1321# cross compilers defaults, can be overridden with --cross-cc-ARCH
1322: ${cross_prefix_aarch64="aarch64-linux-gnu-"}
1323: ${cross_prefix_aarch64_be="$cross_prefix_aarch64"}
1324: ${cross_prefix_alpha="alpha-linux-gnu-"}
1325: ${cross_prefix_arm="arm-linux-gnueabihf-"}
1326: ${cross_prefix_armeb="$cross_prefix_arm"}
1327: ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
1328: ${cross_prefix_loongarch64="loongarch64-unknown-linux-gnu-"}
1329: ${cross_prefix_hppa="hppa-linux-gnu-"}
1330: ${cross_prefix_i386="i686-linux-gnu-"}
1331: ${cross_prefix_m68k="m68k-linux-gnu-"}
1332: ${cross_prefix_microblaze="microblaze-linux-musl-"}
1333: ${cross_prefix_mips64el="mips64el-linux-gnuabi64-"}
1334: ${cross_prefix_mips64="mips64-linux-gnuabi64-"}
1335: ${cross_prefix_mipsel="mipsel-linux-gnu-"}
1336: ${cross_prefix_mips="mips-linux-gnu-"}
1337: ${cross_prefix_ppc="powerpc-linux-gnu-"}
1338: ${cross_prefix_ppc64="powerpc64-linux-gnu-"}
1339: ${cross_prefix_ppc64le="$cross_prefix_ppc64"}
1340: ${cross_prefix_riscv64="riscv64-linux-gnu-"}
1341: ${cross_prefix_s390x="s390x-linux-gnu-"}
1342: ${cross_prefix_sh4="sh4-linux-gnu-"}
1343: ${cross_prefix_sparc64="sparc64-linux-gnu-"}
1344: ${cross_prefix_sparc="$cross_prefix_sparc64"}
1345: ${cross_prefix_tricore="tricore-"}
1346: ${cross_prefix_x86_64="x86_64-linux-gnu-"}
1347
1348: ${cross_cc_aarch64_be="$cross_cc_aarch64"}
1349: ${cross_cc_cflags_aarch64_be="-mbig-endian"}
1350: ${cross_cc_armeb="$cross_cc_arm"}
1351: ${cross_cc_cflags_armeb="-mbig-endian"}
1352: ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
1353: ${cross_cc_cflags_hexagon="-mv73 -O2 -static"}
1354: ${cross_cc_cflags_i386="-m32"}
1355: ${cross_cc_cflags_ppc="-m32 -mbig-endian"}
1356: ${cross_cc_cflags_ppc64="-m64 -mbig-endian"}
1357: ${cross_cc_ppc64le="$cross_cc_ppc64"}
1358: ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"}
1359: ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
1360: ${cross_cc_sparc="$cross_cc_sparc64"}
1361: ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
1362: ${cross_cc_cflags_x86_64="-m64 -mcx16"}
1363
1364compute_target_variable() {
1365  eval "$2="
1366  if eval test -n "\"\${cross_prefix_$1}\""; then
1367    if eval has "\"\${cross_prefix_$1}\$3\""; then
1368      eval "$2=\"\${cross_prefix_$1}\$3\""
1369    fi
1370  fi
1371}
1372
1373have_target() {
1374  for i; do
1375    case " $target_list " in
1376      *" $i "*) return 0;;
1377      *) ;;
1378    esac
1379  done
1380  return 1
1381}
1382
1383# probe_target_compiler TARGET
1384#
1385# Look for a compiler for the given target, either native or cross.
1386# Set variables target_* if a compiler is found, and container_cross_*
1387# if a Docker-based cross-compiler image is known for the target.
1388# Set got_cross_cc to yes/no depending on whether a non-container-based
1389# compiler was found.
1390#
1391# If TARGET is a user-mode emulation target, also set build_static to
1392# "y" if static linking is possible.
1393#
1394probe_target_compiler() {
1395  # reset all output variables
1396  got_cross_cc=no
1397  container_image=
1398  container_hosts=
1399  container_cross_prefix=
1400  container_cross_cc=
1401  container_cross_ar=
1402  container_cross_as=
1403  container_cross_ld=
1404  container_cross_nm=
1405  container_cross_objcopy=
1406  container_cross_ranlib=
1407  container_cross_strip=
1408
1409  target_arch=${1%%-*}
1410  case $target_arch in
1411    aarch64) container_hosts="x86_64 aarch64" ;;
1412    aarch64_be) container_hosts="x86_64 aarch64" ;;
1413    alpha) container_hosts=x86_64 ;;
1414    arm) container_hosts="x86_64 aarch64" ;;
1415    hexagon) container_hosts=x86_64 ;;
1416    hppa) container_hosts=x86_64 ;;
1417    i386) container_hosts=x86_64 ;;
1418    loongarch64) container_hosts=x86_64 ;;
1419    m68k) container_hosts=x86_64 ;;
1420    microblaze) container_hosts=x86_64 ;;
1421    mips64el) container_hosts=x86_64 ;;
1422    mips64) container_hosts=x86_64 ;;
1423    mipsel) container_hosts=x86_64 ;;
1424    mips) container_hosts=x86_64 ;;
1425    ppc) container_hosts=x86_64 ;;
1426    ppc64|ppc64le) container_hosts=x86_64 ;;
1427    riscv64) container_hosts=x86_64 ;;
1428    s390x) container_hosts=x86_64 ;;
1429    sh4) container_hosts=x86_64 ;;
1430    sparc64) container_hosts=x86_64 ;;
1431    tricore) container_hosts=x86_64 ;;
1432    x86_64) container_hosts="aarch64 ppc64le x86_64" ;;
1433    xtensa*) container_hosts=x86_64 ;;
1434  esac
1435
1436  for host in $container_hosts; do
1437    test "$container" != no || continue
1438    test "$host" = "$cpu" || continue
1439    case $target_arch in
1440      # debian-all-test-cross architectures
1441
1442      aarch64_be)
1443        container_image=debian-all-test-cross
1444        container_cross_prefix=aarch64-linux-gnu-
1445        ;;
1446      hppa|m68k|mips|riscv64|sparc64)
1447        container_image=debian-all-test-cross
1448        ;;
1449      mips64)
1450        container_image=debian-all-test-cross
1451        container_cross_prefix=mips64-linux-gnuabi64-
1452        ;;
1453      ppc|ppc64|ppc64le)
1454        container_image=debian-all-test-cross
1455        container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu-
1456        ;;
1457
1458      # debian-legacy-test-cross architectures (need Debian 11)
1459      # - libc6.1-dev-alpha-cross: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1054412
1460      # - sh4-linux-user: binaries don't run with bookworm compiler
1461
1462      alpha|sh4)
1463        container_image=debian-legacy-test-cross
1464        ;;
1465
1466      # architectures with individual containers
1467
1468      aarch64)
1469        # We don't have any bigendian build tools so we only use this for AArch64
1470        container_image=debian-arm64-cross
1471        ;;
1472      arm)
1473        # We don't have any bigendian build tools so we only use this for ARM
1474        container_image=debian-armhf-cross
1475        container_cross_prefix=arm-linux-gnueabihf-
1476        ;;
1477      hexagon)
1478        container_cross_prefix=hexagon-unknown-linux-musl-
1479        container_cross_cc=${container_cross_prefix}clang
1480        ;;
1481      i386)
1482        container_image=debian-i686-cross
1483        container_cross_prefix=i686-linux-gnu-
1484        ;;
1485      loongarch64)
1486        container_image=debian-loongarch-cross
1487        container_cross_prefix=loongarch64-unknown-linux-gnu-
1488        ;;
1489      microblaze)
1490        container_cross_prefix=microblaze-linux-musl-
1491        ;;
1492      mips64el)
1493        container_image=debian-all-test-cross
1494        container_cross_prefix=mips64el-linux-gnuabi64-
1495        ;;
1496      tricore)
1497        container_image=debian-tricore-cross
1498        container_cross_prefix=tricore-
1499        ;;
1500      x86_64)
1501        container_image=debian-amd64-cross
1502        ;;
1503      xtensa*)
1504        container_image=debian-xtensa-cross
1505
1506        # default to the dc232b cpu
1507        container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
1508        ;;
1509    esac
1510    # Debian and GNU architecture names usually match
1511    : ${container_image:=debian-$target_arch-cross}
1512    : ${container_cross_prefix:=$target_arch-linux-gnu-}
1513    : ${container_cross_cc:=${container_cross_prefix}gcc}
1514    : ${container_cross_ar:=${container_cross_prefix}ar}
1515    : ${container_cross_as:=${container_cross_prefix}as}
1516    : ${container_cross_ld:=${container_cross_prefix}ld}
1517    : ${container_cross_nm:=${container_cross_prefix}nm}
1518    : ${container_cross_objcopy:=${container_cross_prefix}objcopy}
1519    : ${container_cross_ranlib:=${container_cross_prefix}ranlib}
1520    : ${container_cross_strip:=${container_cross_prefix}strip}
1521  done
1522
1523  try=cross
1524  # For softmmu/roms also look for a bi-endian or multilib-enabled host compiler
1525  if [ "${1%softmmu}" != "$1" ] || test "$target_arch" = "$cpu"; then
1526      case "$target_arch:$cpu" in
1527        aarch64_be:aarch64 | \
1528        armeb:arm | \
1529        i386:x86_64 | \
1530        mips*:mips64 | \
1531        ppc*:ppc64 | \
1532        sparc:sparc64 | \
1533        "$cpu:$cpu")
1534        try='native cross' ;;
1535      esac
1536  fi
1537  eval "target_cflags=\${cross_cc_cflags_$target_arch}"
1538  for thistry in $try; do
1539    case $thistry in
1540    native)
1541      target_cc=$cc
1542      target_ccas=$ccas
1543      target_ar=$ar
1544      target_as=$as
1545      target_ld=$ld
1546      target_nm=$nm
1547      target_objcopy=$objcopy
1548      target_ranlib=$ranlib
1549      target_strip=$strip
1550      ;;
1551    cross)
1552      target_cc=
1553      if eval test -n "\"\${cross_cc_$target_arch}\""; then
1554        if eval has "\"\${cross_cc_$target_arch}\""; then
1555          eval "target_cc=\"\${cross_cc_$target_arch}\""
1556        fi
1557      else
1558        compute_target_variable $target_arch target_cc gcc
1559      fi
1560      target_ccas=$target_cc
1561      compute_target_variable $target_arch target_ar ar
1562      compute_target_variable $target_arch target_as as
1563      compute_target_variable $target_arch target_ld ld
1564      compute_target_variable $target_arch target_nm nm
1565      compute_target_variable $target_arch target_objcopy objcopy
1566      compute_target_variable $target_arch target_ranlib ranlib
1567      compute_target_variable $target_arch target_strip strip
1568      ;;
1569    esac
1570
1571    if test -n "$target_cc"; then
1572      case $target_arch in
1573        i386|x86_64)
1574          if $target_cc --version | grep -qi "clang"; then
1575            continue
1576          fi
1577          ;;
1578      esac
1579    elif test -n "$target_as" && test -n "$target_ld"; then
1580      # Special handling for assembler only targets
1581      case $target in
1582        tricore-softmmu)
1583          build_static=
1584          got_cross_cc=yes
1585          break
1586          ;;
1587        *)
1588          continue
1589          ;;
1590      esac
1591    else
1592      continue
1593    fi
1594
1595    write_c_skeleton
1596    case $1 in
1597      *-softmmu)
1598        if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC &&
1599          do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then
1600          got_cross_cc=yes
1601          break
1602        fi
1603        ;;
1604      *)
1605        if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC -static ; then
1606          build_static=y
1607          got_cross_cc=yes
1608          break
1609        fi
1610        if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC ; then
1611          build_static=
1612          got_cross_cc=yes
1613          break
1614        fi
1615        ;;
1616    esac
1617  done
1618  if test $got_cross_cc != yes; then
1619    build_static=
1620    target_cc=
1621    target_ccas=
1622    target_ar=
1623    target_as=
1624    target_ld=
1625    target_nm=
1626    target_objcopy=
1627    target_ranlib=
1628    target_strip=
1629  fi
1630  test -n "$target_cc"
1631}
1632
1633write_target_makefile() {
1634  echo "EXTRA_CFLAGS=$target_cflags"
1635  if test -z "$target_cc" && test -z "$target_as"; then
1636    test -z "$container_image" && error_exit "Internal error: could not find cross compiler for $1?"
1637    echo "$1: docker-image-$container_image" >> Makefile.prereqs
1638    if test -n "$container_cross_cc"; then
1639      echo "CC=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
1640      echo "CCAS=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
1641    fi
1642    echo "AR=$docker_py cc --cc $container_cross_ar -i qemu/$container_image -s $source_path --"
1643    echo "AS=$docker_py cc --cc $container_cross_as -i qemu/$container_image -s $source_path --"
1644    echo "LD=$docker_py cc --cc $container_cross_ld -i qemu/$container_image -s $source_path --"
1645    echo "NM=$docker_py cc --cc $container_cross_nm -i qemu/$container_image -s $source_path --"
1646    echo "OBJCOPY=$docker_py cc --cc $container_cross_objcopy -i qemu/$container_image -s $source_path --"
1647    echo "RANLIB=$docker_py cc --cc $container_cross_ranlib -i qemu/$container_image -s $source_path --"
1648    echo "STRIP=$docker_py cc --cc $container_cross_strip -i qemu/$container_image -s $source_path --"
1649  else
1650    if test -n "$target_cc"; then
1651      echo "CC=$target_cc"
1652      echo "CCAS=$target_ccas"
1653    fi
1654    if test -n "$target_ar"; then
1655      echo "AR=$target_ar"
1656    fi
1657    if test -n "$target_as"; then
1658      echo "AS=$target_as"
1659    fi
1660    if test -n "$target_ld"; then
1661      echo "LD=$target_ld"
1662    fi
1663    if test -n "$target_nm"; then
1664      echo "NM=$target_nm"
1665    fi
1666    if test -n "$target_objcopy"; then
1667      echo "OBJCOPY=$target_objcopy"
1668    fi
1669    if test -n "$target_ranlib"; then
1670      echo "RANLIB=$target_ranlib"
1671    fi
1672    if test -n "$target_strip"; then
1673      echo "STRIP=$target_strip"
1674    fi
1675  fi
1676}
1677
1678#######################################
1679# cross-compiled firmware targets
1680
1681# Set up build tree symlinks that point back into the source tree
1682# (these can be both files and directories).
1683# Caution: avoid adding files or directories here using wildcards. This
1684# will result in problems later if a new file matching the wildcard is
1685# added to the source tree -- nothing will cause configure to be rerun
1686# so the build tree will be missing the link back to the new file, and
1687# tests might fail. Prefer to keep the relevant files in their own
1688# directory and symlink the directory instead.
1689LINKS="Makefile"
1690LINKS="$LINKS docs/config"
1691LINKS="$LINKS pc-bios/optionrom/Makefile"
1692LINKS="$LINKS pc-bios/s390-ccw/Makefile"
1693LINKS="$LINKS pc-bios/vof/Makefile"
1694LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
1695LINKS="$LINKS tests/data"
1696LINKS="$LINKS tests/qemu-iotests/check tests/qemu-iotests/Makefile"
1697LINKS="$LINKS python"
1698for f in $LINKS ; do
1699    if [ -e "$source_path/$f" ]; then
1700        symlink "$source_path/$f" "$f"
1701    fi
1702done
1703
1704# use included Linux headers for KVM architectures
1705if test "$host_os" = "linux" && test -n "$linux_arch"; then
1706  symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
1707fi
1708
1709echo "# Automatically generated by configure - do not modify" > Makefile.prereqs
1710
1711# Mac OS X ships with a broken assembler
1712if have_target i386-softmmu x86_64-softmmu && \
1713        test "$host_os" != "darwin" && test "$host_os" != "sunos" && \
1714        test "$host_os" != "haiku" && \
1715        probe_target_compiler i386-softmmu; then
1716    subdirs="$subdirs pc-bios/optionrom"
1717    config_mak=pc-bios/optionrom/config.mak
1718    echo "# Automatically generated by configure - do not modify" > $config_mak
1719    echo "TOPSRC_DIR=$source_path" >> $config_mak
1720    write_target_makefile >> $config_mak
1721fi
1722
1723if have_target ppc-softmmu ppc64-softmmu && \
1724        probe_target_compiler ppc-softmmu; then
1725    subdirs="$subdirs pc-bios/vof"
1726    config_mak=pc-bios/vof/config.mak
1727    echo "# Automatically generated by configure - do not modify" > $config_mak
1728    echo "SRC_DIR=$source_path/pc-bios/vof" >> $config_mak
1729    write_target_makefile >> $config_mak
1730fi
1731
1732# Only build s390-ccw bios if the compiler has -march=z900 or -march=z10
1733# (which is the lowest architecture level that Clang supports)
1734if have_target s390x-softmmu && probe_target_compiler s390x-softmmu && \
1735    GIT=git "$source_path/scripts/git-submodule.sh" "$git_submodules_action" roms/SLOF >> config.log 2>&1; then
1736  write_c_skeleton
1737  do_compiler "$target_cc" $target_cc_cflags -march=z900 -o $TMPO -c $TMPC
1738  has_z900=$?
1739  if [ $has_z900 = 0 ] || do_compiler "$target_cc" $target_cc_cflags -march=z10 -msoft-float -Werror -o $TMPO -c $TMPC; then
1740    if [ $has_z900 != 0 ]; then
1741      echo "WARNING: Your compiler does not support the z900!"
1742      echo "         The s390-ccw bios will only work with guest CPUs >= z10."
1743    fi
1744    subdirs="$subdirs pc-bios/s390-ccw"
1745    config_mak=pc-bios/s390-ccw/config-host.mak
1746    echo "# Automatically generated by configure - do not modify" > $config_mak
1747    echo "SRC_PATH=$source_path/pc-bios/s390-ccw" >> $config_mak
1748    echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_mak
1749    write_target_makefile >> $config_mak
1750  fi
1751fi
1752
1753#######################################
1754# generate config-host.mak
1755
1756config_host_mak="config-host.mak"
1757
1758echo "# Automatically generated by configure - do not modify" > $config_host_mak
1759echo >> $config_host_mak
1760
1761echo all: >> $config_host_mak
1762
1763echo "SRC_PATH=$source_path" >> $config_host_mak
1764echo "TARGET_DIRS=$target_list" >> $config_host_mak
1765echo "GDB=$gdb_bin" >> $config_host_mak
1766if test "$container" != no; then
1767    echo "RUNC=$runc" >> $config_host_mak
1768fi
1769echo "SUBDIRS=$subdirs" >> $config_host_mak
1770if test "$rust" != disabled; then
1771  echo "RUST_TARGET_TRIPLE=$rust_target_triple" >> $config_host_mak
1772fi
1773echo "PYTHON=$python" >> $config_host_mak
1774echo "MKVENV_ENSUREGROUP=$mkvenv ensuregroup $mkvenv_online_flag" >> $config_host_mak
1775echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
1776echo "MESON=$meson" >> $config_host_mak
1777echo "NINJA=$ninja" >> $config_host_mak
1778echo "EXESUF=$EXESUF" >> $config_host_mak
1779if test "$default_targets" = "yes"; then
1780  echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
1781fi
1782
1783# tests/tcg configuration
1784mkdir -p tests/tcg
1785echo "# Automatically generated by configure - do not modify" > tests/tcg/$config_host_mak
1786echo "SRC_PATH=$source_path" >> tests/tcg/$config_host_mak
1787if test "$plugins" = "yes" ; then
1788    echo "CONFIG_PLUGIN=y" >> tests/tcg/$config_host_mak
1789fi
1790
1791tcg_tests_targets=
1792for target in $target_list; do
1793  arch=${target%%-*}
1794
1795  case $target in
1796    xtensa*-linux-user)
1797      # the toolchain is not complete with headers, only build system tests
1798      continue
1799      ;;
1800    *-softmmu)
1801      test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || continue
1802      qemu="qemu-system-$arch"
1803      ;;
1804    *-linux-user|*-bsd-user)
1805      qemu="qemu-$arch"
1806      ;;
1807  esac
1808
1809  if probe_target_compiler $target || test -n "$container_image"; then
1810      test -n "$container_image" && build_static=y
1811      mkdir -p "tests/tcg/$target"
1812      config_target_mak=tests/tcg/$target/config-target.mak
1813      ln -sf "$source_path/tests/tcg/Makefile.target" "tests/tcg/$target/Makefile"
1814      echo "# Automatically generated by configure - do not modify" > "$config_target_mak"
1815      echo "TARGET_NAME=$arch" >> "$config_target_mak"
1816      echo "TARGET=$target" >> "$config_target_mak"
1817      write_target_makefile "build-tcg-tests-$target" >> "$config_target_mak"
1818      echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
1819      echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
1820
1821      # will GDB work with these binaries?
1822      if test "${gdb_arches#*$arch}" != "$gdb_arches"; then
1823          echo "GDB=$gdb_bin" >> $config_target_mak
1824      fi
1825
1826      if test "${gdb_arches#*aarch64}" != "$gdb_arches" && version_ge $gdb_version 15.1; then
1827          echo "GDB_HAS_MTE=y" >> $config_target_mak
1828      fi
1829
1830      if test "${gdb_arches#*aarch64}" != "$gdb_arches" && version_ge $gdb_version 16.0; then
1831          # GDB has to support MTE in baremetal to allow debugging MTE in QEMU system mode
1832          echo "GDB_SUPPORTS_MTE_IN_BAREMETAL=y" >> $config_target_mak
1833      fi
1834
1835      echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs
1836      tcg_tests_targets="$tcg_tests_targets $target"
1837  fi
1838done
1839
1840if test "$tcg" = "enabled"; then
1841    echo "TCG_TESTS_TARGETS=$tcg_tests_targets" >> $config_host_mak
1842fi
1843
1844if test "$skip_meson" = no; then
1845  cross="config-meson.cross.new"
1846  meson_quote() {
1847    test $# = 0 && return
1848    echo "'$(echo $* | sed "s/ /','/g")'"
1849  }
1850
1851  echo "# Automatically generated by configure - do not modify" > $cross
1852  echo "[properties]" >> $cross
1853
1854  # unroll any custom device configs
1855  for a in $device_archs; do
1856      eval "c=\$devices_${a}"
1857      echo "${a}-softmmu = '$c'" >> $cross
1858  done
1859
1860  echo "[built-in options]" >> $cross
1861  echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
1862  echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
1863  test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
1864  echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
1865  echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
1866
1867  # Only enable by default for git builds and on select OSes
1868  echo "# environment defaults, can still be overridden on " >> $cross
1869  echo "# the command line" >> $cross
1870  if test -e "$source_path/.git" && \
1871      { test "$host_os" = linux || test "$host_os" = "windows"; }; then
1872      echo 'werror = true' >> $cross
1873  fi
1874  echo "[project options]" >> $cross
1875  if test "$SMBD" != ''; then
1876    echo "smbd = $(meson_quote "$SMBD")" >> $cross
1877  fi
1878  if test "${QEMU_GA_MANUFACTURER}" != ''; then
1879    echo "qemu_ga_manufacturer = $(meson_quote "${QEMU_GA_MANUFACTURER}")" >> $cross
1880  fi
1881  if test "${QEMU_GA_DISTRO}" != ''; then
1882    echo "qemu_ga_distro = $(meson_quote "${QEMU_GA_DISTRO}")" >> $cross
1883  fi
1884  if test "${QEMU_GA_VERSION}" != ''; then
1885    echo "qemu_ga_version = $(meson_quote "${QEMU_GA_VERSION}")" >> $cross
1886  fi
1887
1888  echo >> $cross
1889  echo "[binaries]" >> $cross
1890  echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
1891  test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
1892  test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
1893  if test "$rust" != disabled; then
1894    if test "$rust_host_triple" != "$rust_target_triple"; then
1895      echo "rust = [$(meson_quote $rustc --target "$rust_target_triple")]" >> $cross
1896    else
1897      echo "rust = [$(meson_quote $rustc)]" >> $cross
1898    fi
1899  fi
1900  echo "ar = [$(meson_quote $ar)]" >> $cross
1901  echo "dlltool = [$(meson_quote $dlltool)]" >> $cross
1902  echo "nm = [$(meson_quote $nm)]" >> $cross
1903  echo "pkgconfig = [$(meson_quote $pkg_config)]" >> $cross
1904  echo "pkg-config = [$(meson_quote $pkg_config)]" >> $cross
1905  echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
1906  echo "readelf = [$(meson_quote $readelf)]" >> $cross
1907  if has $sdl2_config; then
1908    echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
1909  fi
1910  echo "strip = [$(meson_quote $strip)]" >> $cross
1911  echo "widl = [$(meson_quote $widl)]" >> $cross
1912  echo "windres = [$(meson_quote $windres)]" >> $cross
1913  echo "windmc = [$(meson_quote $windmc)]" >> $cross
1914  if test "$cross_compile" = "yes"; then
1915    echo "[host_machine]" >> $cross
1916    echo "system = '$host_os'" >> $cross
1917    case "$cpu" in
1918        i386)
1919            echo "cpu_family = 'x86'" >> $cross
1920            ;;
1921        *)
1922            echo "cpu_family = '$cpu'" >> $cross
1923            ;;
1924    esac
1925    echo "cpu = '$cpu'" >> $cross
1926    if test "$bigendian" = "yes" ; then
1927        echo "endian = 'big'" >> $cross
1928    else
1929        echo "endian = 'little'" >> $cross
1930    fi
1931
1932    native="config-meson.native.new"
1933    echo "# Automatically generated by configure - do not modify" > $native
1934    echo "[binaries]" >> $native
1935    echo "c = [$(meson_quote $host_cc)]" >> $native
1936    if test "$rust" != disabled; then
1937      echo "rust = [$(meson_quote $rustc)]" >> $cross
1938    fi
1939    mv $native config-meson.native
1940    meson_option_add --native-file
1941    meson_option_add config-meson.native
1942  fi
1943  mv $cross config-meson.cross
1944  meson_add_machine_file config-meson.cross
1945  if test -f "$source_path/configs/meson/$host_os.txt"; then
1946    meson_add_machine_file $source_path/configs/meson/$host_os.txt
1947  fi
1948
1949  rm -rf meson-private meson-info meson-logs
1950
1951  test "$download" = "disabled" && meson_option_add "--wrap-mode=nodownload"
1952  test "$default_feature" = no && meson_option_add -Dauto_features=disabled
1953  test "$static" = yes && meson_option_add -Dprefer_static=true
1954  test "$pie" = no && meson_option_add -Db_pie=false
1955
1956  # QEMU options
1957  test "$rust" != "disabled" && meson_option_add "-Drust=$rust"
1958  test "$cfi" != false && meson_option_add "-Dcfi=$cfi" "-Db_lto=$cfi"
1959  test "$docs" != auto && meson_option_add "-Ddocs=$docs"
1960  test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
1961  test "$plugins" = yes && meson_option_add "-Dplugins=true"
1962  test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
1963  run_meson() {
1964    NINJA=$ninja $meson setup "$@" "$PWD" "$source_path"
1965  }
1966  eval run_meson $meson_options
1967  if test "$?" -ne 0 ; then
1968      error_exit "meson setup failed"
1969  fi
1970  echo "$meson" > build.ninja.stamp
1971else
1972  if test -f meson-private/cmd_line.txt; then
1973    # Adjust old command line options that were removed
1974    # sed -i is not portable
1975    perl -i -ne '
1976      /^sphinx_build/ && next;
1977      print;' meson-private/cmd_line.txt
1978  fi
1979fi
1980
1981# Save the configure command line for later reuse.
1982cat <<EOD >config.status
1983#!/bin/sh
1984# Generated by configure.
1985# Run this file to recreate the current configuration.
1986# Compiler output produced by configure, useful for debugging
1987# configure, is in config.log if it exists.
1988EOD
1989
1990preserve_env() {
1991    envname=$1
1992
1993    eval envval=\$$envname
1994
1995    if test -n "$envval"
1996    then
1997	echo "$envname='$envval'" >> config.status
1998	echo "export $envname" >> config.status
1999    else
2000	echo "unset $envname" >> config.status
2001    fi
2002}
2003
2004# Preserve various env variables that influence what
2005# features/build target configure will detect
2006preserve_env AR
2007preserve_env AS
2008preserve_env CC
2009preserve_env CFLAGS
2010preserve_env CXX
2011preserve_env CXXFLAGS
2012preserve_env DLLTOOL
2013preserve_env LD
2014preserve_env LDFLAGS
2015preserve_env LD_LIBRARY_PATH
2016preserve_env NM
2017preserve_env OBJCFLAGS
2018preserve_env OBJCOPY
2019preserve_env PATH
2020preserve_env PKG_CONFIG
2021preserve_env PKG_CONFIG_LIBDIR
2022preserve_env PKG_CONFIG_PATH
2023preserve_env PYTHON
2024preserve_env QEMU_GA_MANUFACTURER
2025preserve_env QEMU_GA_DISTRO
2026preserve_env QEMU_GA_VERSION
2027preserve_env SDL2_CONFIG
2028preserve_env SMBD
2029preserve_env STRIP
2030preserve_env WIDL
2031preserve_env WINDRES
2032preserve_env WINDMC
2033
2034printf "exec" >>config.status
2035for i in "$0" "$@"; do
2036  test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
2037done
2038echo ' "$@"' >>config.status
2039chmod +x config.status
2040
2041rm -r "$TMPDIR1"
2042
2043if test "$rust" != disabled; then
2044  echo
2045  echo 'INFO: Rust bindings generation with `bindgen` might fail in some cases where'
2046  echo 'the detected `libclang` does not match the expected `clang` version/target. In'
2047  echo 'this case you must pass the path to `clang` and `libclang` to your build'
2048  echo 'command invocation using the environment variables CLANG_PATH and LIBCLANG_PATH'
2049fi
2050