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