xref: /openbmc/qemu/configure (revision 761a9c58)
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
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  --cpu=*) cpu="$optarg"
211  ;;
212  --extra-cflags=*)
213    EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
214    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
215    EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
216    ;;
217  --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
218  ;;
219  --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
220  ;;
221  --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
222  ;;
223  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
224  ;;
225  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
226                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
227  ;;
228  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
229                eval "cross_cc_${cc_arch}=\$optarg"
230  ;;
231  --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-prefix-FOO option"
232  ;;
233  --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
234                    eval "cross_prefix_${cc_arch}=\$optarg"
235  ;;
236  --without-default-features) default_feature="no"
237  ;;
238  esac
239done
240
241default_cflags='-O2 -g'
242git_submodules_action="update"
243docs="auto"
244EXESUF=""
245system="yes"
246linux_user=""
247bsd_user=""
248plugins="$default_feature"
249subdirs=""
250ninja=""
251python=
252download="enabled"
253skip_meson=no
254use_containers="yes"
255gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
256gdb_arches=""
257
258# Don't accept a target_list environment variable.
259unset target_list
260unset target_list_exclude
261
262# The following Meson options are handled manually (still they
263# are included in the automatically generated help message)
264# because they automatically enable/disable other options
265tcg="auto"
266cfi="false"
267
268# Meson has PIE as a boolean rather than enabled/disabled/auto,
269# and we also need to check for -static-pie before Meson runs
270# which requires knowing whether --static is enabled.
271pie=""
272static="no"
273
274# Preferred compiler:
275#  ${CC} (if set)
276#  ${cross_prefix}gcc (if cross-prefix specified)
277#  system compiler
278if test -z "${CC}${cross_prefix}"; then
279  cc="cc"
280else
281  cc="${CC-${cross_prefix}gcc}"
282fi
283
284if test -z "${CXX}${cross_prefix}"; then
285  cxx="c++"
286else
287  cxx="${CXX-${cross_prefix}g++}"
288fi
289
290# Preferred ObjC compiler:
291# $objcc (if set, i.e. via --objcc option)
292# ${cross_prefix}clang (if cross-prefix specified)
293# clang (if available)
294# $cc
295if test -z "${objcc}${cross_prefix}"; then
296  if has clang; then
297    objcc=clang
298  else
299    objcc="$cc"
300  fi
301else
302  objcc="${objcc-${cross_prefix}clang}"
303fi
304
305ar="${AR-${cross_prefix}ar}"
306as="${AS-${cross_prefix}as}"
307ccas="${CCAS-$cc}"
308dlltool="${DLLTOOL-${cross_prefix}dlltool}"
309objcopy="${OBJCOPY-${cross_prefix}objcopy}"
310ld="${LD-${cross_prefix}ld}"
311ranlib="${RANLIB-${cross_prefix}ranlib}"
312nm="${NM-${cross_prefix}nm}"
313strip="${STRIP-${cross_prefix}strip}"
314widl="${WIDL-${cross_prefix}widl}"
315windres="${WINDRES-${cross_prefix}windres}"
316windmc="${WINDMC-${cross_prefix}windmc}"
317pkg_config="${PKG_CONFIG-${cross_prefix}pkg-config}"
318sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
319
320check_define() {
321cat > $TMPC <<EOF
322#if !defined($1)
323#error $1 not defined
324#endif
325int main(void) { return 0; }
326EOF
327  compile_object
328}
329
330write_c_skeleton() {
331    cat > $TMPC <<EOF
332int main(void) { return 0; }
333EOF
334}
335
336if check_define __linux__ ; then
337  host_os=linux
338elif check_define _WIN32 ; then
339  host_os=windows
340elif check_define __OpenBSD__ ; then
341  host_os=openbsd
342elif check_define __sun__ ; then
343  host_os=sunos
344elif check_define __HAIKU__ ; then
345  host_os=haiku
346elif check_define __FreeBSD__ ; then
347  host_os=freebsd
348elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
349  host_os=gnu/kfreebsd
350elif check_define __DragonFly__ ; then
351  host_os=dragonfly
352elif check_define __NetBSD__; then
353  host_os=netbsd
354elif check_define __APPLE__; then
355  host_os=darwin
356else
357  # This is a fatal error, but don't report it yet, because we
358  # might be going to just print the --help text, or it might
359  # be the result of a missing compiler.
360  host_os=bogus
361fi
362
363if test ! -z "$cpu" ; then
364  # command line argument
365  :
366elif check_define __i386__ ; then
367  cpu="i386"
368elif check_define __x86_64__ ; then
369  if check_define __ILP32__ ; then
370    cpu="x32"
371  else
372    cpu="x86_64"
373  fi
374elif check_define __sparc__ ; then
375  if check_define __arch64__ ; then
376    cpu="sparc64"
377  else
378    cpu="sparc"
379  fi
380elif check_define _ARCH_PPC ; then
381  if check_define _ARCH_PPC64 ; then
382    if check_define _LITTLE_ENDIAN ; then
383      cpu="ppc64le"
384    else
385      cpu="ppc64"
386    fi
387  else
388    cpu="ppc"
389  fi
390elif check_define __mips__ ; then
391  cpu="mips"
392elif check_define __s390__ ; then
393  if check_define __s390x__ ; then
394    cpu="s390x"
395  else
396    cpu="s390"
397  fi
398elif check_define __riscv ; then
399  if check_define _LP64 ; then
400    cpu="riscv64"
401  else
402    cpu="riscv32"
403  fi
404elif check_define __arm__ ; then
405  cpu="arm"
406elif check_define __aarch64__ ; then
407  cpu="aarch64"
408elif check_define __loongarch64 ; then
409  cpu="loongarch64"
410else
411  # Using uname is really broken, but it is just a fallback for architectures
412  # that are going to use TCI anyway
413  cpu=$(uname -m)
414  if test "$host_os" != "bogus"; then
415    echo "WARNING: unrecognized host CPU, proceeding with 'uname -m' output '$cpu'"
416  fi
417fi
418
419# Normalise host CPU name to the values used by Meson cross files and in source
420# directories, and set multilib cflags.  The canonicalization isn't really
421# necessary, because the architectures that we check for should not hit the
422# 'uname -m' case, but better safe than sorry in case --cpu= is used.
423#
424# Note that this case should only have supported host CPUs, not guests.
425# Please keep it sorted and synchronized with meson.build's host_arch.
426host_arch=
427linux_arch=
428case "$cpu" in
429  aarch64)
430    host_arch=aarch64
431    linux_arch=arm64
432    ;;
433
434  armv*b|armv*l|arm)
435    cpu=arm
436    host_arch=arm
437    linux_arch=arm
438    ;;
439
440  i386|i486|i586|i686)
441    cpu="i386"
442    host_arch=i386
443    linux_arch=x86
444    CPU_CFLAGS="-m32"
445    ;;
446
447  loongarch*)
448    cpu=loongarch64
449    host_arch=loongarch64
450    linux_arch=loongarch
451    ;;
452
453  mips64*|mipsisa64*)
454    cpu=mips64
455    host_arch=mips
456    linux_arch=mips
457    ;;
458  mips*)
459    cpu=mips
460    host_arch=mips
461    linux_arch=mips
462    ;;
463
464  ppc)
465    host_arch=ppc
466    linux_arch=powerpc
467    CPU_CFLAGS="-m32"
468    ;;
469  ppc64)
470    host_arch=ppc64
471    linux_arch=powerpc
472    CPU_CFLAGS="-m64 -mbig-endian"
473    ;;
474  ppc64le)
475    cpu=ppc64
476    host_arch=ppc64
477    linux_arch=powerpc
478    CPU_CFLAGS="-m64 -mlittle-endian"
479    ;;
480
481  riscv32 | riscv64)
482    host_arch=riscv
483    linux_arch=riscv
484    ;;
485
486  s390)
487    linux_arch=s390
488    CPU_CFLAGS="-m31"
489    ;;
490  s390x)
491    host_arch=s390x
492    linux_arch=s390
493    CPU_CFLAGS="-m64"
494    ;;
495
496  sparc|sun4[cdmuv])
497    cpu=sparc
498    CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc"
499    ;;
500  sparc64)
501    host_arch=sparc64
502    CPU_CFLAGS="-m64 -mcpu=ultrasparc"
503    ;;
504
505  x32)
506    cpu="x86_64"
507    host_arch=x86_64
508    linux_arch=x86
509    CPU_CFLAGS="-mx32"
510    ;;
511  x86_64|amd64)
512    cpu="x86_64"
513    host_arch=x86_64
514    linux_arch=x86
515    CPU_CFLAGS="-m64"
516    ;;
517esac
518
519# Now we have our CPU_CFLAGS we can check if we are targeting a 32 or
520# 64 bit host.
521
522check_64bit_host() {
523cat > $TMPC <<EOF
524#if __SIZEOF_POINTER__ != 8
525#error not 64 bit system
526#endif
527int main(void) { return 0; }
528EOF
529  compile_object "$1"
530}
531
532if check_64bit_host "$CPU_CFLAGS"; then
533    host_bits=64
534else
535    host_bits=32
536fi
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.8.
551    # NB: a True python conditional creates a non-zero return code (Failure)
552    "$1" -c 'import sys; sys.exit(sys.version_info < (3,8))'
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.12 python3.11 \
560                          python3.10 python3.9 python3.8; 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  --make=*)
662  ;;
663  --install=*)
664  ;;
665  --python=*) python="$optarg"
666  ;;
667  --skip-meson) skip_meson=yes
668  ;;
669  --ninja=*) ninja="$optarg"
670  ;;
671  --extra-cflags=*)
672  ;;
673  --extra-cxxflags=*)
674  ;;
675  --extra-objcflags=*)
676  ;;
677  --extra-ldflags=*)
678  ;;
679  --cross-cc-*)
680  ;;
681  --cross-prefix-*)
682  ;;
683  --enable-docs) docs=enabled
684  ;;
685  --disable-docs) docs=disabled
686  ;;
687  --cpu=*)
688  ;;
689  --target-list=*) target_list="$optarg"
690                   if test "$target_list_exclude"; then
691                       error_exit "Can't mix --target-list with --target-list-exclude"
692                   fi
693  ;;
694  --target-list-exclude=*) target_list_exclude="$optarg"
695                   if test "$target_list"; then
696                       error_exit "Can't mix --target-list-exclude with --target-list"
697                   fi
698  ;;
699  --with-default-devices) meson_option_add -Ddefault_devices=true
700  ;;
701  --without-default-devices) meson_option_add -Ddefault_devices=false
702  ;;
703  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
704  ;;
705  --with-devices-*) device_arch=${opt#--with-devices-};
706                    device_arch=${device_arch%%=*}
707                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
708                    if test -f "$cf"; then
709                        device_archs="$device_archs $device_arch"
710                        eval "devices_${device_arch}=\$optarg"
711                    else
712                        error_exit "File $cf does not exist"
713                    fi
714  ;;
715  --without-default-features) # processed above
716  ;;
717  --static) static="yes"
718  ;;
719  --host=*|--build=*|\
720  --disable-dependency-tracking|\
721  --sbindir=*|--sharedstatedir=*|\
722  --oldincludedir=*|--datarootdir=*|--infodir=*|\
723  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
724    # These switches are silently ignored, for compatibility with
725    # autoconf-generated configure scripts. This allows QEMU's
726    # configure to be used by RPM and similar macros that set
727    # lots of directory switches by default.
728  ;;
729  --enable-debug)
730      # Enable debugging options that aren't excessively noisy
731      meson_option_parse --enable-debug-tcg ""
732      meson_option_parse --enable-debug-graph-lock ""
733      meson_option_parse --enable-debug-mutex ""
734      meson_option_add -Doptimization=0
735      default_cflags='-O0 -g'
736  ;;
737  --disable-tcg) tcg="disabled"
738  ;;
739  --enable-tcg) tcg="enabled"
740  ;;
741  --disable-system) system="no"
742  ;;
743  --enable-system) system="yes"
744  ;;
745  --disable-user)
746      linux_user="no" ;
747      bsd_user="no" ;
748  ;;
749  --enable-user) ;;
750  --disable-linux-user) linux_user="no"
751  ;;
752  --enable-linux-user) linux_user="yes"
753  ;;
754  --disable-bsd-user) bsd_user="no"
755  ;;
756  --enable-bsd-user) bsd_user="yes"
757  ;;
758  --enable-pie) pie="yes"
759  ;;
760  --disable-pie) pie="no"
761  ;;
762  --enable-cfi) cfi=true
763  ;;
764  --disable-cfi) cfi=false
765  ;;
766  --disable-download) download="disabled"; git_submodules_action=validate;
767  ;;
768  --enable-download) download="enabled"; git_submodules_action=update;
769  ;;
770  --enable-plugins) plugins="yes"
771  ;;
772  --disable-plugins) plugins="no"
773  ;;
774  --enable-containers) use_containers="yes"
775  ;;
776  --disable-containers) use_containers="no"
777  ;;
778  --container-engine=*) container_engine="$optarg"
779  ;;
780  --gdb=*) gdb_bin="$optarg"
781  ;;
782  # everything else has the same name in configure and meson
783  --*) meson_option_parse "$opt" "$optarg"
784  ;;
785  # Pass through -Dxxxx options to meson
786  -D*) meson_option_add "$opt"
787  ;;
788  esac
789done
790
791if ! test -e "$source_path/.git"
792then
793    git_submodules_action="validate"
794fi
795
796if ! test -f "$source_path/subprojects/keycodemapdb/README" \
797    && test "$download" = disabled
798then
799    echo
800    echo "ERROR: missing subprojects"
801    echo
802    if test -e "$source_path/.git"; then
803        echo "--disable-download specified but subprojects were not"
804        echo 'checked out.  Please invoke "meson subprojects download"'
805        echo "before configuring QEMU, or remove --disable-download"
806        echo "from the command line."
807    else
808        echo "This is not a GIT checkout but subproject content appears to"
809        echo "be missing. Do not use 'git archive' or GitHub download links"
810        echo "to acquire QEMU source archives. Non-GIT builds are only"
811        echo "supported with source archives linked from:"
812        echo
813        echo "  https://www.qemu.org/download/#source"
814        echo
815        echo "Developers working with GIT can use scripts/archive-source.sh"
816        echo "if they need to create valid source archives."
817    fi
818    echo
819    exit 1
820fi
821
822default_target_list=""
823mak_wilds=""
824
825if [ -n "$host_arch" ] && [ -d "$source_path/common-user/host/$host_arch" ]; then
826    if [ "$linux_user" != no ]; then
827        if [ "$host_os" = linux ]; then
828            linux_user=yes
829        elif [ "$linux_user" = yes ]; then
830            error_exit "linux-user not supported on this architecture"
831        fi
832        if [ "$linux_user" = "yes" ]; then
833            mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
834        fi
835    fi
836    if [ "$bsd_user" != no ]; then
837        if [ "$bsd_user" = "" ]; then
838            test $host_os = freebsd && bsd_user=yes
839        fi
840        if [ "$bsd_user" = yes ] && ! [ -d "$source_path/bsd-user/$host_os" ]; then
841            error_exit "bsd-user not supported on this host OS"
842        fi
843        if [ "$bsd_user" = "yes" ]; then
844            mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
845        fi
846    fi
847else
848    if [ "$linux_user" = yes ] || [ "$bsd_user" = yes ]; then
849        error_exit "user mode emulation not supported on this architecture"
850    fi
851fi
852if [ "$system" = "yes" ]; then
853    mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
854fi
855
856for config in $mak_wilds; do
857    target="$(basename "$config" .mak)"
858    if echo "$target_list_exclude" | grep -vq "$target"; then
859        default_target_list="${default_target_list} $target"
860    fi
861done
862
863if test x"$show_help" = x"yes" ; then
864cat << EOF
865
866Usage: configure [options]
867Options: [defaults in brackets after descriptions]
868
869Standard options:
870  --help                   print this message
871  --target-list=LIST       set target list (default: build all)
872$(echo Available targets: $default_target_list | \
873  fold -s -w 53 | sed -e 's/^/                           /')
874  --target-list-exclude=LIST exclude a set of targets from the default target-list
875
876Advanced options (experts only):
877  -Dmesonoptname=val       passthrough option to meson unmodified
878  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
879  --cc=CC                  use C compiler CC [$cc]
880  --host-cc=CC             when cross compiling, use C compiler CC for code run
881                           at build time [$host_cc]
882  --cxx=CXX                use C++ compiler CXX [$cxx]
883  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
884  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
885  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
886  --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
887  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
888  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
889  --cross-cc-cflags-ARCH=  use compiler flags when building ARCH guest tests
890  --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
891  --python=PYTHON          use specified python [$python]
892  --ninja=NINJA            use specified ninja [$ninja]
893  --static                 enable static build [$static]
894  --without-default-features default all --enable-* options to "disabled"
895  --without-default-devices  do not include any device that is not needed to
896                           start the emulator (only use if you are including
897                           desired devices in configs/devices/)
898  --with-devices-ARCH=NAME override default configs/devices
899  --enable-debug           enable common debug build options
900  --cpu=CPU                Build for host CPU [$cpu]
901  --disable-containers     don't use containers for cross-building
902  --container-engine=TYPE  which container engine to use [$container_engine]
903  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
904EOF
905  meson_options_help
906cat << EOF
907  system          all system emulation targets
908  user            supported user emulation targets
909  linux-user      all linux usermode emulation targets
910  bsd-user        all BSD usermode emulation targets
911  pie             Position Independent Executables
912
913NOTE: The object files are built at the place where configure is launched
914EOF
915exit 0
916fi
917
918# Now that we are sure that the user did not only want to print the --help
919# information, we should double-check that the C compiler really works:
920write_c_skeleton
921if ! compile_object ; then
922    error_exit "C compiler \"$cc\" either does not exist or does not work."
923fi
924
925# Remove old dependency files to make sure that they get properly regenerated
926rm -f ./*/config-devices.mak.d
927
928if test -z "$python"
929then
930    # If first_python is set, there was a binary somewhere even though
931    # it was not suitable.  Use it for the error message.
932    if test -n "$first_python"; then
933        error_exit "Cannot use '$first_python', Python >= 3.8 is required." \
934            "Use --python=/path/to/python to specify a supported Python."
935    else
936        error_exit "Python not found. Use --python=/path/to/python"
937    fi
938fi
939
940if ! check_py_version "$python"; then
941  error_exit "Cannot use '$python', Python >= 3.8 is required." \
942             "Use --python=/path/to/python to specify a supported Python." \
943             "Maybe try:" \
944             "  openSUSE Leap 15.3+: zypper install python39" \
945             "  CentOS 8: dnf install python38"
946fi
947
948# Resolve PATH
949python="$(command -v "$python")"
950
951# Create a Python virtual environment using our configured python.
952# The stdout of this script will be the location of a symlink that
953# points to the configured Python.
954# Entry point scripts for pip, meson, and sphinx are generated if those
955# packages are present.
956
957# Defaults assumed for now:
958# - venv is cleared if it exists already;
959# - venv is allowed to use system packages;
960# - all setup can be performed offline;
961# - missing packages may be fetched from PyPI,
962#   unless --disable-download is passed.
963# - pip is not installed into the venv when possible,
964#   but ensurepip is called as a fallback when necessary.
965
966echo "python determined to be '$python'"
967echo "python version: $($python --version)"
968
969python="$($python -B "${source_path}/python/scripts/mkvenv.py" create pyvenv)"
970if test "$?" -ne 0 ; then
971    error_exit "python venv creation failed"
972fi
973
974# Suppress writing compiled files
975python="$python -B"
976mkvenv="$python ${source_path}/python/scripts/mkvenv.py"
977
978# Finish preparing the virtual environment using vendored .whl files
979
980$mkvenv ensuregroup --dir "${source_path}/python/wheels" \
981     ${source_path}/pythondeps.toml meson || exit 1
982
983# At this point, we expect Meson to be installed and available.
984# We expect mkvenv or pip to have created pyvenv/bin/meson for us.
985# We ignore PATH completely here: we want to use the venv's Meson
986# *exclusively*.
987
988meson="$(cd pyvenv/bin; pwd)/meson"
989
990# Conditionally ensure Sphinx is installed.
991
992mkvenv_online_flag=""
993if test "$download" = "enabled" ; then
994    mkvenv_online_flag=" --online"
995fi
996
997if test "$docs" != "disabled" ; then
998    if ! $mkvenv ensuregroup \
999         $(test "$docs" = "enabled" && echo "$mkvenv_online_flag") \
1000         ${source_path}/pythondeps.toml docs;
1001    then
1002        if test "$docs" = "enabled" ; then
1003            exit 1
1004        fi
1005        echo "Sphinx not found/usable, disabling docs."
1006        docs=disabled
1007    else
1008        docs=enabled
1009    fi
1010fi
1011
1012# Probe for ninja
1013
1014if test -z "$ninja"; then
1015    for c in ninja ninja-build samu; do
1016        if has $c; then
1017            ninja=$(command -v "$c")
1018            break
1019        fi
1020    done
1021    if test -z "$ninja"; then
1022      error_exit "Cannot find Ninja"
1023    fi
1024fi
1025
1026if test "$host_os" = "bogus"; then
1027    # Now that we know that we're not printing the help and that
1028    # the compiler works (so the results of the check_defines we used
1029    # to identify the OS are reliable), if we didn't recognize the
1030    # host OS we should stop now.
1031    error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1032fi
1033
1034# test for any invalid configuration combinations
1035if test "$host_os" = "windows" && ! has "$dlltool"; then
1036  if test "$plugins" = "yes"; then
1037    error_exit "TCG plugins requires dlltool to build on Windows platforms"
1038  fi
1039  plugins="no"
1040fi
1041if test "$tcg" = "disabled" ; then
1042  if test "$plugins" = "yes"; then
1043    error_exit "Can't enable plugins on non-TCG builds"
1044  fi
1045  plugins="no"
1046fi
1047if test "$static" = "yes" ; then
1048  if test "$plugins" = "yes"; then
1049    error_exit "static and plugins are mutually incompatible"
1050  fi
1051  plugins="no"
1052fi
1053if test "$plugins" != "no" && test $host_bits -eq 64; then
1054    if has_meson_option "-Dtcg_interpreter=true"; then
1055        plugins="no"
1056    else
1057        plugins=yes
1058        subdirs="$subdirs contrib/plugins"
1059    fi
1060fi
1061
1062cat > $TMPC << EOF
1063
1064#ifdef __linux__
1065#  define THREAD __thread
1066#else
1067#  define THREAD
1068#endif
1069static THREAD int tls_var;
1070int main(void) { return tls_var; }
1071EOF
1072
1073if test "$host_os" = windows || test "$host_os" = haiku; then
1074  if test "$pie" = "yes"; then
1075    error_exit "PIE not available due to missing OS support"
1076  fi
1077  pie=no
1078fi
1079
1080if test "$pie" != "no"; then
1081  if test "$static" = "yes"; then
1082    pie_ldflags=-static-pie
1083  else
1084    pie_ldflags=-pie
1085  fi
1086  if compile_prog "-Werror -fPIE -DPIE" "$pie_ldflags"; then
1087    pie="yes"
1088  elif test "$pie" = "yes"; then
1089    error_exit "-static-pie not available due to missing toolchain support"
1090  else
1091    echo "Disabling PIE due to missing toolchain support"
1092    pie="no"
1093  fi
1094fi
1095
1096##########################################
1097
1098if test -z "${target_list+xxx}" ; then
1099    default_targets=yes
1100    for target in $default_target_list; do
1101        target_list="$target_list $target"
1102    done
1103    target_list="${target_list# }"
1104else
1105    default_targets=no
1106    target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1107    for target in $target_list; do
1108        # Check that we recognised the target name; this allows a more
1109        # friendly error message than if we let it fall through.
1110        case " $default_target_list " in
1111            *" $target "*)
1112                ;;
1113            *)
1114                error_exit "Unknown target name '$target'"
1115                ;;
1116        esac
1117    done
1118fi
1119
1120if test "$tcg" = "auto"; then
1121  if test -z "$target_list"; then
1122    tcg="disabled"
1123  else
1124    tcg="enabled"
1125  fi
1126fi
1127
1128#########################################
1129# gdb test
1130
1131if test -n "$gdb_bin"; then
1132    gdb_version_string=$($gdb_bin --version | head -n 1)
1133    # Extract last field in the version string
1134    gdb_version=${gdb_version_string##* }
1135    if version_ge $gdb_version 9.1; then
1136        gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
1137    else
1138        gdb_bin=""
1139    fi
1140fi
1141
1142##########################################
1143# big/little endian test
1144cat > $TMPC << EOF
1145#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1146# error LITTLE
1147#endif
1148int main(void) { return 0; }
1149EOF
1150
1151if ! compile_prog ; then
1152  bigendian="no"
1153else
1154  cat > $TMPC << EOF
1155#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
1156# error BIG
1157#endif
1158int main(void) { return 0; }
1159EOF
1160
1161  if ! compile_prog ; then
1162    bigendian="yes"
1163  else
1164    echo big/little test failed
1165    exit 1
1166  fi
1167fi
1168
1169##########################################
1170# functions to probe cross compilers
1171
1172container="no"
1173runc=""
1174if test $use_containers = "yes" && (has "docker" || has "podman"); then
1175    case $($python "$source_path"/tests/docker/docker.py --engine "$container_engine" probe) in
1176        *docker) container=docker ;;
1177        podman) container=podman ;;
1178        no) container=no ;;
1179    esac
1180    if test "$container" != "no"; then
1181        docker_py="$python $source_path/tests/docker/docker.py --engine $container"
1182        runc=$container
1183    fi
1184fi
1185
1186# cross compilers defaults, can be overridden with --cross-cc-ARCH
1187: ${cross_prefix_aarch64="aarch64-linux-gnu-"}
1188: ${cross_prefix_aarch64_be="$cross_prefix_aarch64"}
1189: ${cross_prefix_alpha="alpha-linux-gnu-"}
1190: ${cross_prefix_arm="arm-linux-gnueabihf-"}
1191: ${cross_prefix_armeb="$cross_prefix_arm"}
1192: ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
1193: ${cross_prefix_loongarch64="loongarch64-unknown-linux-gnu-"}
1194: ${cross_prefix_hppa="hppa-linux-gnu-"}
1195: ${cross_prefix_i386="i686-linux-gnu-"}
1196: ${cross_prefix_m68k="m68k-linux-gnu-"}
1197: ${cross_prefix_microblaze="microblaze-linux-musl-"}
1198: ${cross_prefix_mips64el="mips64el-linux-gnuabi64-"}
1199: ${cross_prefix_mips64="mips64-linux-gnuabi64-"}
1200: ${cross_prefix_mipsel="mipsel-linux-gnu-"}
1201: ${cross_prefix_mips="mips-linux-gnu-"}
1202: ${cross_prefix_ppc="powerpc-linux-gnu-"}
1203: ${cross_prefix_ppc64="powerpc64-linux-gnu-"}
1204: ${cross_prefix_ppc64le="$cross_prefix_ppc64"}
1205: ${cross_prefix_riscv64="riscv64-linux-gnu-"}
1206: ${cross_prefix_s390x="s390x-linux-gnu-"}
1207: ${cross_prefix_sh4="sh4-linux-gnu-"}
1208: ${cross_prefix_sparc64="sparc64-linux-gnu-"}
1209: ${cross_prefix_sparc="$cross_prefix_sparc64"}
1210: ${cross_prefix_tricore="tricore-"}
1211: ${cross_prefix_x86_64="x86_64-linux-gnu-"}
1212
1213: ${cross_cc_aarch64_be="$cross_cc_aarch64"}
1214: ${cross_cc_cflags_aarch64_be="-mbig-endian"}
1215: ${cross_cc_armeb="$cross_cc_arm"}
1216: ${cross_cc_cflags_armeb="-mbig-endian"}
1217: ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
1218: ${cross_cc_cflags_hexagon="-mv73 -O2 -static"}
1219: ${cross_cc_cflags_i386="-m32"}
1220: ${cross_cc_cflags_ppc="-m32 -mbig-endian"}
1221: ${cross_cc_cflags_ppc64="-m64 -mbig-endian"}
1222: ${cross_cc_ppc64le="$cross_cc_ppc64"}
1223: ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"}
1224: ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
1225: ${cross_cc_sparc="$cross_cc_sparc64"}
1226: ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
1227: ${cross_cc_cflags_x86_64="-m64 -mcx16"}
1228
1229compute_target_variable() {
1230  eval "$2="
1231  if eval test -n "\"\${cross_prefix_$1}\""; then
1232    if eval has "\"\${cross_prefix_$1}\$3\""; then
1233      eval "$2=\"\${cross_prefix_$1}\$3\""
1234    fi
1235  fi
1236}
1237
1238have_target() {
1239  for i; do
1240    case " $target_list " in
1241      *" $i "*) return 0;;
1242      *) ;;
1243    esac
1244  done
1245  return 1
1246}
1247
1248# probe_target_compiler TARGET
1249#
1250# Look for a compiler for the given target, either native or cross.
1251# Set variables target_* if a compiler is found, and container_cross_*
1252# if a Docker-based cross-compiler image is known for the target.
1253# Set got_cross_cc to yes/no depending on whether a non-container-based
1254# compiler was found.
1255#
1256# If TARGET is a user-mode emulation target, also set build_static to
1257# "y" if static linking is possible.
1258#
1259probe_target_compiler() {
1260  # reset all output variables
1261  got_cross_cc=no
1262  container_image=
1263  container_hosts=
1264  container_cross_prefix=
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    hexagon) container_hosts=x86_64 ;;
1280    hppa) container_hosts=x86_64 ;;
1281    i386) container_hosts=x86_64 ;;
1282    loongarch64) container_hosts=x86_64 ;;
1283    m68k) container_hosts=x86_64 ;;
1284    microblaze) container_hosts=x86_64 ;;
1285    mips64el) container_hosts=x86_64 ;;
1286    mips64) container_hosts=x86_64 ;;
1287    mipsel) container_hosts=x86_64 ;;
1288    mips) container_hosts=x86_64 ;;
1289    ppc) container_hosts=x86_64 ;;
1290    ppc64|ppc64le) container_hosts=x86_64 ;;
1291    riscv64) container_hosts=x86_64 ;;
1292    s390x) container_hosts=x86_64 ;;
1293    sh4) container_hosts=x86_64 ;;
1294    sparc64) container_hosts=x86_64 ;;
1295    tricore) container_hosts=x86_64 ;;
1296    x86_64) container_hosts="aarch64 ppc64le x86_64" ;;
1297    xtensa*) container_hosts=x86_64 ;;
1298  esac
1299
1300  for host in $container_hosts; do
1301    test "$container" != no || continue
1302    test "$host" = "$cpu" || continue
1303    case $target_arch in
1304      # debian-all-test-cross architectures
1305
1306      hppa|m68k|mips|riscv64|sparc64)
1307        container_image=debian-all-test-cross
1308        ;;
1309      mips64)
1310        container_image=debian-all-test-cross
1311        container_cross_prefix=mips64-linux-gnuabi64-
1312        ;;
1313      ppc|ppc64|ppc64le)
1314        container_image=debian-all-test-cross
1315        container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu-
1316        ;;
1317
1318      # debian-legacy-test-cross architectures (need Debian 11)
1319      # - libc6.1-dev-alpha-cross: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1054412
1320      # - sh4-linux-user: binaries don't run with bookworm compiler
1321
1322      alpha|sh4)
1323        container_image=debian-legacy-test-cross
1324        ;;
1325
1326      # architectures with individual containers
1327
1328      aarch64)
1329        # We don't have any bigendian build tools so we only use this for AArch64
1330        container_image=debian-arm64-cross
1331        ;;
1332      arm)
1333        # We don't have any bigendian build tools so we only use this for ARM
1334        container_image=debian-armhf-cross
1335        container_cross_prefix=arm-linux-gnueabihf-
1336        ;;
1337      hexagon)
1338        container_cross_prefix=hexagon-unknown-linux-musl-
1339        container_cross_cc=${container_cross_prefix}clang
1340        ;;
1341      i386)
1342        container_image=debian-i686-cross
1343        container_cross_prefix=i686-linux-gnu-
1344        ;;
1345      loongarch64)
1346        container_image=debian-loongarch-cross
1347        container_cross_prefix=loongarch64-unknown-linux-gnu-
1348        ;;
1349      microblaze)
1350        container_cross_prefix=microblaze-linux-musl-
1351        ;;
1352      mips64el)
1353        container_image=debian-all-test-cross
1354        container_cross_prefix=mips64el-linux-gnuabi64-
1355        ;;
1356      tricore)
1357        container_image=debian-tricore-cross
1358        container_cross_prefix=tricore-
1359        ;;
1360      x86_64)
1361        container_image=debian-amd64-cross
1362        ;;
1363      xtensa*)
1364        container_image=debian-xtensa-cross
1365
1366        # default to the dc232b cpu
1367        container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
1368        ;;
1369    esac
1370    # Debian and GNU architecture names usually match
1371    : ${container_image:=debian-$target_arch-cross}
1372    : ${container_cross_prefix:=$target_arch-linux-gnu-}
1373    : ${container_cross_cc:=${container_cross_prefix}gcc}
1374    : ${container_cross_ar:=${container_cross_prefix}ar}
1375    : ${container_cross_as:=${container_cross_prefix}as}
1376    : ${container_cross_ld:=${container_cross_prefix}ld}
1377    : ${container_cross_nm:=${container_cross_prefix}nm}
1378    : ${container_cross_objcopy:=${container_cross_prefix}objcopy}
1379    : ${container_cross_ranlib:=${container_cross_prefix}ranlib}
1380    : ${container_cross_strip:=${container_cross_prefix}strip}
1381  done
1382
1383  try=cross
1384  # For softmmu/roms also look for a bi-endian or multilib-enabled host compiler
1385  if [ "${1%softmmu}" != "$1" ] || test "$target_arch" = "$cpu"; then
1386      case "$target_arch:$cpu" in
1387        aarch64_be:aarch64 | \
1388        armeb:arm | \
1389        i386:x86_64 | \
1390        mips*:mips64 | \
1391        ppc*:ppc64 | \
1392        sparc:sparc64 | \
1393        "$cpu:$cpu")
1394        try='native cross' ;;
1395      esac
1396  fi
1397  eval "target_cflags=\${cross_cc_cflags_$target_arch}"
1398  for thistry in $try; do
1399    case $thistry in
1400    native)
1401      target_cc=$cc
1402      target_ccas=$ccas
1403      target_ar=$ar
1404      target_as=$as
1405      target_ld=$ld
1406      target_nm=$nm
1407      target_objcopy=$objcopy
1408      target_ranlib=$ranlib
1409      target_strip=$strip
1410      ;;
1411    cross)
1412      target_cc=
1413      if eval test -n "\"\${cross_cc_$target_arch}\""; then
1414        if eval has "\"\${cross_cc_$target_arch}\""; then
1415          eval "target_cc=\"\${cross_cc_$target_arch}\""
1416        fi
1417      else
1418        compute_target_variable $target_arch target_cc gcc
1419      fi
1420      target_ccas=$target_cc
1421      compute_target_variable $target_arch target_ar ar
1422      compute_target_variable $target_arch target_as as
1423      compute_target_variable $target_arch target_ld ld
1424      compute_target_variable $target_arch target_nm nm
1425      compute_target_variable $target_arch target_objcopy objcopy
1426      compute_target_variable $target_arch target_ranlib ranlib
1427      compute_target_variable $target_arch target_strip strip
1428      ;;
1429    esac
1430
1431    if test -n "$target_cc"; then
1432      case $target_arch in
1433        i386|x86_64)
1434          if $target_cc --version | grep -qi "clang"; then
1435            continue
1436          fi
1437          ;;
1438      esac
1439    elif test -n "$target_as" && test -n "$target_ld"; then
1440      # Special handling for assembler only targets
1441      case $target in
1442        tricore-softmmu)
1443          build_static=
1444          got_cross_cc=yes
1445          break
1446          ;;
1447        *)
1448          continue
1449          ;;
1450      esac
1451    else
1452      continue
1453    fi
1454
1455    write_c_skeleton
1456    case $1 in
1457      *-softmmu)
1458        if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC &&
1459          do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then
1460          got_cross_cc=yes
1461          break
1462        fi
1463        ;;
1464      *)
1465        if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC -static ; then
1466          build_static=y
1467          got_cross_cc=yes
1468          break
1469        fi
1470        if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC ; then
1471          build_static=
1472          got_cross_cc=yes
1473          break
1474        fi
1475        ;;
1476    esac
1477  done
1478  if test $got_cross_cc != yes; then
1479    build_static=
1480    target_cc=
1481    target_ccas=
1482    target_ar=
1483    target_as=
1484    target_ld=
1485    target_nm=
1486    target_objcopy=
1487    target_ranlib=
1488    target_strip=
1489  fi
1490  test -n "$target_cc"
1491}
1492
1493write_target_makefile() {
1494  echo "EXTRA_CFLAGS=$target_cflags"
1495  if test -z "$target_cc" && test -z "$target_as"; then
1496    test -z "$container_image" && error_exit "Internal error: could not find cross compiler for $1?"
1497    echo "$1: docker-image-$container_image" >> Makefile.prereqs
1498    if test -n "$container_cross_cc"; then
1499      echo "CC=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
1500      echo "CCAS=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
1501    fi
1502    echo "AR=$docker_py cc --cc $container_cross_ar -i qemu/$container_image -s $source_path --"
1503    echo "AS=$docker_py cc --cc $container_cross_as -i qemu/$container_image -s $source_path --"
1504    echo "LD=$docker_py cc --cc $container_cross_ld -i qemu/$container_image -s $source_path --"
1505    echo "NM=$docker_py cc --cc $container_cross_nm -i qemu/$container_image -s $source_path --"
1506    echo "OBJCOPY=$docker_py cc --cc $container_cross_objcopy -i qemu/$container_image -s $source_path --"
1507    echo "RANLIB=$docker_py cc --cc $container_cross_ranlib -i qemu/$container_image -s $source_path --"
1508    echo "STRIP=$docker_py cc --cc $container_cross_strip -i qemu/$container_image -s $source_path --"
1509  else
1510    if test -n "$target_cc"; then
1511      echo "CC=$target_cc"
1512      echo "CCAS=$target_ccas"
1513    fi
1514    if test -n "$target_ar"; then
1515      echo "AR=$target_ar"
1516    fi
1517    if test -n "$target_as"; then
1518      echo "AS=$target_as"
1519    fi
1520    if test -n "$target_ld"; then
1521      echo "LD=$target_ld"
1522    fi
1523    if test -n "$target_nm"; then
1524      echo "NM=$target_nm"
1525    fi
1526    if test -n "$target_objcopy"; then
1527      echo "OBJCOPY=$target_objcopy"
1528    fi
1529    if test -n "$target_ranlib"; then
1530      echo "RANLIB=$target_ranlib"
1531    fi
1532    if test -n "$target_strip"; then
1533      echo "STRIP=$target_strip"
1534    fi
1535  fi
1536}
1537
1538#######################################
1539# cross-compiled firmware targets
1540
1541# Set up build tree symlinks that point back into the source tree
1542# (these can be both files and directories).
1543# Caution: avoid adding files or directories here using wildcards. This
1544# will result in problems later if a new file matching the wildcard is
1545# added to the source tree -- nothing will cause configure to be rerun
1546# so the build tree will be missing the link back to the new file, and
1547# tests might fail. Prefer to keep the relevant files in their own
1548# directory and symlink the directory instead.
1549LINKS="Makefile"
1550LINKS="$LINKS docs/config"
1551LINKS="$LINKS pc-bios/optionrom/Makefile"
1552LINKS="$LINKS pc-bios/s390-ccw/Makefile"
1553LINKS="$LINKS pc-bios/vof/Makefile"
1554LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
1555LINKS="$LINKS tests/avocado tests/data"
1556LINKS="$LINKS tests/qemu-iotests/check tests/qemu-iotests/Makefile"
1557LINKS="$LINKS python"
1558LINKS="$LINKS contrib/plugins/Makefile "
1559for f in $LINKS ; do
1560    if [ -e "$source_path/$f" ]; then
1561        symlink "$source_path/$f" "$f"
1562    fi
1563done
1564
1565# use included Linux headers for KVM architectures
1566if test "$host_os" = "linux" && test -n "$linux_arch"; then
1567  symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
1568fi
1569
1570echo "# Automatically generated by configure - do not modify" > Makefile.prereqs
1571
1572# Mac OS X ships with a broken assembler
1573if have_target i386-softmmu x86_64-softmmu && \
1574        test "$host_os" != "darwin" && test "$host_os" != "sunos" && \
1575        test "$host_os" != "haiku" && \
1576        probe_target_compiler i386-softmmu; then
1577    subdirs="$subdirs pc-bios/optionrom"
1578    config_mak=pc-bios/optionrom/config.mak
1579    echo "# Automatically generated by configure - do not modify" > $config_mak
1580    echo "TOPSRC_DIR=$source_path" >> $config_mak
1581    write_target_makefile >> $config_mak
1582fi
1583
1584if have_target ppc-softmmu ppc64-softmmu && \
1585        probe_target_compiler ppc-softmmu; then
1586    subdirs="$subdirs pc-bios/vof"
1587    config_mak=pc-bios/vof/config.mak
1588    echo "# Automatically generated by configure - do not modify" > $config_mak
1589    echo "SRC_DIR=$source_path/pc-bios/vof" >> $config_mak
1590    write_target_makefile >> $config_mak
1591fi
1592
1593# Only build s390-ccw bios if the compiler has -march=z900 or -march=z10
1594# (which is the lowest architecture level that Clang supports)
1595if have_target s390x-softmmu && probe_target_compiler s390x-softmmu && \
1596    GIT=git "$source_path/scripts/git-submodule.sh" "$git_submodules_action" roms/SLOF >> config.log 2>&1; then
1597  write_c_skeleton
1598  do_compiler "$target_cc" $target_cc_cflags -march=z900 -o $TMPO -c $TMPC
1599  has_z900=$?
1600  if [ $has_z900 = 0 ] || do_compiler "$target_cc" $target_cc_cflags -march=z10 -msoft-float -Werror -o $TMPO -c $TMPC; then
1601    if [ $has_z900 != 0 ]; then
1602      echo "WARNING: Your compiler does not support the z900!"
1603      echo "         The s390-ccw bios will only work with guest CPUs >= z10."
1604    fi
1605    subdirs="$subdirs pc-bios/s390-ccw"
1606    config_mak=pc-bios/s390-ccw/config-host.mak
1607    echo "# Automatically generated by configure - do not modify" > $config_mak
1608    echo "SRC_PATH=$source_path/pc-bios/s390-ccw" >> $config_mak
1609    echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_mak
1610    write_target_makefile >> $config_mak
1611  fi
1612fi
1613
1614#######################################
1615# generate config-host.mak
1616
1617config_host_mak="config-host.mak"
1618
1619echo "# Automatically generated by configure - do not modify" > $config_host_mak
1620echo >> $config_host_mak
1621
1622echo all: >> $config_host_mak
1623
1624echo "SRC_PATH=$source_path" >> $config_host_mak
1625echo "TARGET_DIRS=$target_list" >> $config_host_mak
1626echo "GDB=$gdb_bin" >> $config_host_mak
1627if test "$container" != no; then
1628    echo "RUNC=$runc" >> $config_host_mak
1629fi
1630echo "SUBDIRS=$subdirs" >> $config_host_mak
1631echo "PYTHON=$python" >> $config_host_mak
1632echo "MKVENV_ENSUREGROUP=$mkvenv ensuregroup $mkvenv_online_flag" >> $config_host_mak
1633echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
1634echo "MESON=$meson" >> $config_host_mak
1635echo "NINJA=$ninja" >> $config_host_mak
1636echo "EXESUF=$EXESUF" >> $config_host_mak
1637if test "$default_targets" = "yes"; then
1638  echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
1639fi
1640
1641# contrib/plugins configuration
1642echo "# Automatically generated by configure - do not modify" > contrib/plugins/$config_host_mak
1643echo "SRC_PATH=$source_path/contrib/plugins" >> contrib/plugins/$config_host_mak
1644echo "PKG_CONFIG=${pkg_config}" >> contrib/plugins/$config_host_mak
1645echo "CC=$cc $CPU_CFLAGS" >> contrib/plugins/$config_host_mak
1646echo "CFLAGS=${CFLAGS-$default_cflags} $EXTRA_CFLAGS" >> contrib/plugins/$config_host_mak
1647if test "$host_os" = windows; then
1648  echo "DLLTOOL=$dlltool" >> contrib/plugins/$config_host_mak
1649fi
1650if test "$host_os" = darwin; then
1651  echo "CONFIG_DARWIN=y" >> contrib/plugins/$config_host_mak
1652fi
1653if test "$host_os" = windows; then
1654  echo "CONFIG_WIN32=y" >> contrib/plugins/$config_host_mak
1655fi
1656
1657# tests/tcg configuration
1658mkdir -p tests/tcg
1659echo "# Automatically generated by configure - do not modify" > tests/tcg/$config_host_mak
1660echo "SRC_PATH=$source_path" >> tests/tcg/$config_host_mak
1661if test "$plugins" = "yes" ; then
1662    echo "CONFIG_PLUGIN=y" >> tests/tcg/$config_host_mak
1663fi
1664
1665tcg_tests_targets=
1666for target in $target_list; do
1667  arch=${target%%-*}
1668
1669  case $target in
1670    xtensa*-linux-user)
1671      # the toolchain is not complete with headers, only build system tests
1672      continue
1673      ;;
1674    *-softmmu)
1675      test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || continue
1676      qemu="qemu-system-$arch"
1677      ;;
1678    *-linux-user|*-bsd-user)
1679      qemu="qemu-$arch"
1680      ;;
1681  esac
1682
1683  if probe_target_compiler $target || test -n "$container_image"; then
1684      test -n "$container_image" && build_static=y
1685      mkdir -p "tests/tcg/$target"
1686      config_target_mak=tests/tcg/$target/config-target.mak
1687      ln -sf "$source_path/tests/tcg/Makefile.target" "tests/tcg/$target/Makefile"
1688      echo "# Automatically generated by configure - do not modify" > "$config_target_mak"
1689      echo "TARGET_NAME=$arch" >> "$config_target_mak"
1690      echo "TARGET=$target" >> "$config_target_mak"
1691      write_target_makefile "build-tcg-tests-$target" >> "$config_target_mak"
1692      echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
1693      echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
1694
1695      # will GDB work with these binaries?
1696      if test "${gdb_arches#*$arch}" != "$gdb_arches"; then
1697          echo "GDB=$gdb_bin" >> $config_target_mak
1698      fi
1699
1700      if test "${gdb_arches#*aarch64}" != "$gdb_arches" && version_ge $gdb_version 15.1; then
1701          echo "GDB_HAS_MTE=y" >> $config_target_mak
1702      fi
1703
1704      if test "${gdb_arches#*aarch64}" != "$gdb_arches" && version_ge $gdb_version 16.0; then
1705          # GDB has to support MTE in baremetal to allow debugging MTE in QEMU system mode
1706          echo "GDB_SUPPORTS_MTE_IN_BAREMETAL=y" >> $config_target_mak
1707      fi
1708
1709      echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs
1710      tcg_tests_targets="$tcg_tests_targets $target"
1711  fi
1712done
1713
1714if test "$tcg" = "enabled"; then
1715    echo "TCG_TESTS_TARGETS=$tcg_tests_targets" >> $config_host_mak
1716fi
1717
1718if test "$skip_meson" = no; then
1719  cross="config-meson.cross.new"
1720  meson_quote() {
1721    test $# = 0 && return
1722    echo "'$(echo $* | sed "s/ /','/g")'"
1723  }
1724
1725  echo "# Automatically generated by configure - do not modify" > $cross
1726  echo "[properties]" >> $cross
1727
1728  # unroll any custom device configs
1729  for a in $device_archs; do
1730      eval "c=\$devices_${a}"
1731      echo "${a}-softmmu = '$c'" >> $cross
1732  done
1733
1734  echo "[built-in options]" >> $cross
1735  echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
1736  echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
1737  test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
1738  echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
1739  echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
1740
1741  # Only enable by default for git builds and on select OSes
1742  echo "# environment defaults, can still be overridden on " >> $cross
1743  echo "# the command line" >> $cross
1744  if test -e "$source_path/.git" && \
1745      { test "$host_os" = linux || test "$host_os" = "windows"; }; then
1746      echo 'werror = true' >> $cross
1747  fi
1748  echo "[project options]" >> $cross
1749  if test "$SMBD" != ''; then
1750    echo "smbd = $(meson_quote "$SMBD")" >> $cross
1751  fi
1752  if test "${QEMU_GA_MANUFACTURER}" != ''; then
1753    echo "qemu_ga_manufacturer = $(meson_quote "${QEMU_GA_MANUFACTURER}")" >> $cross
1754  fi
1755  if test "${QEMU_GA_DISTRO}" != ''; then
1756    echo "qemu_ga_distro = $(meson_quote "${QEMU_GA_DISTRO}")" >> $cross
1757  fi
1758  if test "${QEMU_GA_VERSION}" != ''; then
1759    echo "qemu_ga_version = $(meson_quote "${QEMU_GA_VERSION}")" >> $cross
1760  fi
1761
1762  echo >> $cross
1763  echo "[binaries]" >> $cross
1764  echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
1765  test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
1766  test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
1767  echo "ar = [$(meson_quote $ar)]" >> $cross
1768  echo "dlltool = [$(meson_quote $dlltool)]" >> $cross
1769  echo "nm = [$(meson_quote $nm)]" >> $cross
1770  echo "pkgconfig = [$(meson_quote $pkg_config)]" >> $cross
1771  echo "pkg-config = [$(meson_quote $pkg_config)]" >> $cross
1772  echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
1773  if has $sdl2_config; then
1774    echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
1775  fi
1776  echo "strip = [$(meson_quote $strip)]" >> $cross
1777  echo "widl = [$(meson_quote $widl)]" >> $cross
1778  echo "windres = [$(meson_quote $windres)]" >> $cross
1779  echo "windmc = [$(meson_quote $windmc)]" >> $cross
1780  if test "$cross_compile" = "yes"; then
1781    echo "[host_machine]" >> $cross
1782    echo "system = '$host_os'" >> $cross
1783    case "$cpu" in
1784        i386)
1785            echo "cpu_family = 'x86'" >> $cross
1786            ;;
1787        *)
1788            echo "cpu_family = '$cpu'" >> $cross
1789            ;;
1790    esac
1791    echo "cpu = '$cpu'" >> $cross
1792    if test "$bigendian" = "yes" ; then
1793        echo "endian = 'big'" >> $cross
1794    else
1795        echo "endian = 'little'" >> $cross
1796    fi
1797
1798    native="config-meson.native.new"
1799    echo "# Automatically generated by configure - do not modify" > $native
1800    echo "[binaries]" >> $native
1801    echo "c = [$(meson_quote $host_cc)]" >> $native
1802    mv $native config-meson.native
1803    meson_option_add --native-file
1804    meson_option_add config-meson.native
1805  fi
1806  mv $cross config-meson.cross
1807  meson_add_machine_file config-meson.cross
1808  if test -f "$source_path/configs/meson/$host_os.txt"; then
1809    meson_add_machine_file $source_path/configs/meson/$host_os.txt
1810  fi
1811
1812  rm -rf meson-private meson-info meson-logs
1813
1814  test "$download" = "disabled" && meson_option_add "--wrap-mode=nodownload"
1815  test "$default_feature" = no && meson_option_add -Dauto_features=disabled
1816  test "$static" = yes && meson_option_add -Dprefer_static=true
1817  test "$pie" = no && meson_option_add -Db_pie=false
1818
1819  # QEMU options
1820  test "$cfi" != false && meson_option_add "-Dcfi=$cfi" "-Db_lto=$cfi"
1821  test "$docs" != auto && meson_option_add "-Ddocs=$docs"
1822  test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
1823  test "$plugins" = yes && meson_option_add "-Dplugins=true"
1824  test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
1825  run_meson() {
1826    NINJA=$ninja $meson setup "$@" "$PWD" "$source_path"
1827  }
1828  eval run_meson $meson_options
1829  if test "$?" -ne 0 ; then
1830      error_exit "meson setup failed"
1831  fi
1832  echo "$meson" > build.ninja.stamp
1833else
1834  if test -f meson-private/cmd_line.txt; then
1835    # Adjust old command line options that were removed
1836    # sed -i is not portable
1837    perl -i -ne '
1838      /^sphinx_build/ && next;
1839      print;' meson-private/cmd_line.txt
1840  fi
1841fi
1842
1843# Save the configure command line for later reuse.
1844cat <<EOD >config.status
1845#!/bin/sh
1846# Generated by configure.
1847# Run this file to recreate the current configuration.
1848# Compiler output produced by configure, useful for debugging
1849# configure, is in config.log if it exists.
1850EOD
1851
1852preserve_env() {
1853    envname=$1
1854
1855    eval envval=\$$envname
1856
1857    if test -n "$envval"
1858    then
1859	echo "$envname='$envval'" >> config.status
1860	echo "export $envname" >> config.status
1861    else
1862	echo "unset $envname" >> config.status
1863    fi
1864}
1865
1866# Preserve various env variables that influence what
1867# features/build target configure will detect
1868preserve_env AR
1869preserve_env AS
1870preserve_env CC
1871preserve_env CFLAGS
1872preserve_env CXX
1873preserve_env CXXFLAGS
1874preserve_env DLLTOOL
1875preserve_env LD
1876preserve_env LDFLAGS
1877preserve_env LD_LIBRARY_PATH
1878preserve_env NM
1879preserve_env OBJCFLAGS
1880preserve_env OBJCOPY
1881preserve_env PATH
1882preserve_env PKG_CONFIG
1883preserve_env PKG_CONFIG_LIBDIR
1884preserve_env PKG_CONFIG_PATH
1885preserve_env PYTHON
1886preserve_env QEMU_GA_MANUFACTURER
1887preserve_env QEMU_GA_DISTRO
1888preserve_env QEMU_GA_VERSION
1889preserve_env SDL2_CONFIG
1890preserve_env SMBD
1891preserve_env STRIP
1892preserve_env WIDL
1893preserve_env WINDRES
1894preserve_env WINDMC
1895
1896printf "exec" >>config.status
1897for i in "$0" "$@"; do
1898  test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
1899done
1900echo ' "$@"' >>config.status
1901chmod +x config.status
1902
1903rm -r "$TMPDIR1"
1904