xref: /openbmc/qemu/configure (revision 513eb437)
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.
8CLICOLOR_FORCE= GREP_OPTIONS=
9unset CLICOLOR_FORCE GREP_OPTIONS
10
11# Don't allow CCACHE, if present, to use cached results of compile tests!
12export CCACHE_RECACHE=yes
13
14# make source path absolute
15source_path=$(cd "$(dirname -- "$0")"; pwd)
16
17if test "$PWD" = "$source_path"
18then
19    echo "Using './build' as the directory for build output"
20
21    MARKER=build/auto-created-by-configure
22
23    if test -e build
24    then
25        if test -f $MARKER
26        then
27           rm -rf build
28        else
29            echo "ERROR: ./build dir already exists and was not previously created by configure"
30            exit 1
31        fi
32    fi
33
34    mkdir build
35    touch $MARKER
36
37    cat > GNUmakefile <<'EOF'
38# This file is auto-generated by configure to support in-source tree
39# 'make' command invocation
40
41ifeq ($(MAKECMDGOALS),)
42recurse: all
43endif
44
45.NOTPARALLEL: %
46%: force
47	@echo 'changing dir to build for $(MAKE) "$(MAKECMDGOALS)"...'
48	@$(MAKE) -C build -f Makefile $(MAKECMDGOALS)
49	@if test "$(MAKECMDGOALS)" = "distclean" && \
50	    test -e build/auto-created-by-configure ; \
51	then \
52	    rm -rf build GNUmakefile ; \
53	fi
54force: ;
55.PHONY: force
56GNUmakefile: ;
57
58EOF
59    cd build
60    exec "$source_path/configure" "$@"
61fi
62
63# Temporary directory used for files created while
64# configure runs. Since it is in the build directory
65# we can safely blow away any previous version of it
66# (and we need not jump through hoops to try to delete
67# it when configure exits.)
68TMPDIR1="config-temp"
69rm -rf "${TMPDIR1}"
70if ! mkdir -p "${TMPDIR1}"; then
71    echo "ERROR: failed to create temporary directory"
72    exit 1
73fi
74
75TMPB="qemu-conf"
76TMPC="${TMPDIR1}/${TMPB}.c"
77TMPO="${TMPDIR1}/${TMPB}.o"
78TMPCXX="${TMPDIR1}/${TMPB}.cxx"
79TMPM="${TMPDIR1}/${TMPB}.m"
80TMPE="${TMPDIR1}/${TMPB}.exe"
81
82rm -f config.log
83
84# Print a helpful header at the top of config.log
85echo "# QEMU configure log $(date)" >> config.log
86printf "# Configured with:" >> config.log
87printf " '%s'" "$0" "$@" >> config.log
88echo >> config.log
89echo "#" >> config.log
90
91quote_sh() {
92    printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
93}
94
95print_error() {
96    (echo
97    echo "ERROR: $1"
98    while test -n "$2"; do
99        echo "       $2"
100        shift
101    done
102    echo) >&2
103}
104
105error_exit() {
106    print_error "$@"
107    exit 1
108}
109
110do_compiler() {
111  # Run the compiler, capturing its output to the log. First argument
112  # is compiler binary to execute.
113  compiler="$1"
114  shift
115  if test -n "$BASH_VERSION"; then eval '
116      echo >>config.log "
117funcs: ${FUNCNAME[*]}
118lines: ${BASH_LINENO[*]}"
119  '; fi
120  echo $compiler "$@" >> config.log
121  $compiler "$@" >> config.log 2>&1 || return $?
122}
123
124do_compiler_werror() {
125    # Run the compiler, capturing its output to the log. First argument
126    # is compiler binary to execute.
127    compiler="$1"
128    shift
129    if test -n "$BASH_VERSION"; then eval '
130        echo >>config.log "
131funcs: ${FUNCNAME[*]}
132lines: ${BASH_LINENO[*]}"
133    '; fi
134    echo $compiler "$@" >> config.log
135    $compiler "$@" >> config.log 2>&1 || return $?
136    # Test passed. If this is an --enable-werror build, rerun
137    # the test with -Werror and bail out if it fails. This
138    # makes warning-generating-errors in configure test code
139    # obvious to developers.
140    if test "$werror" != "yes"; then
141        return 0
142    fi
143    # Don't bother rerunning the compile if we were already using -Werror
144    case "$*" in
145        *-Werror*)
146           return 0
147        ;;
148    esac
149    echo $compiler -Werror "$@" >> config.log
150    $compiler -Werror "$@" >> config.log 2>&1 && return $?
151    error_exit "configure test passed without -Werror but failed with -Werror." \
152        "This is probably a bug in the configure script. The failing command" \
153        "will be at the bottom of config.log." \
154        "You can run configure with --disable-werror to bypass this check."
155}
156
157do_cc() {
158    do_compiler_werror "$cc" $CPU_CFLAGS "$@"
159}
160
161do_cxx() {
162    do_compiler_werror "$cxx" $CPU_CFLAGS "$@"
163}
164
165do_objc() {
166    do_compiler_werror "$objcc" $CPU_CFLAGS "$@"
167}
168
169# Append $2 to the variable named $1, with space separation
170add_to() {
171    eval $1=\${$1:+\"\$$1 \"}\$2
172}
173
174update_cxxflags() {
175    # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
176    # options which some versions of GCC's C++ compiler complain about
177    # because they only make sense for C programs.
178    QEMU_CXXFLAGS="-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
179    CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
180    for arg in $QEMU_CFLAGS; do
181        case $arg in
182            -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
183            -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
184                ;;
185            *)
186                QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
187                ;;
188        esac
189    done
190}
191
192compile_object() {
193  local_cflags="$1"
194  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
195}
196
197compile_prog() {
198  local_cflags="$1"
199  local_ldflags="$2"
200  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
201      $LDFLAGS $EXTRA_LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
202}
203
204# symbolically link $1 to $2.  Portable version of "ln -sf".
205symlink() {
206  rm -rf "$2"
207  mkdir -p "$(dirname "$2")"
208  ln -s "$1" "$2"
209}
210
211# check whether a command is available to this shell (may be either an
212# executable or a builtin)
213has() {
214    type "$1" >/dev/null 2>&1
215}
216
217version_ge () {
218    local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
219    local_ver2=$(echo "$2" | tr . ' ')
220    while true; do
221        set x $local_ver1
222        local_first=${2-0}
223        # 'shift 2' if $2 is set, or 'shift' if $2 is not set
224        shift ${2:+2}
225        local_ver1=$*
226        set x $local_ver2
227        # the second argument finished, the first must be greater or equal
228        test $# = 1 && return 0
229        test $local_first -lt $2 && return 1
230        test $local_first -gt $2 && return 0
231        shift ${2:+2}
232        local_ver2=$*
233    done
234}
235
236glob() {
237    eval test -z '"${1#'"$2"'}"'
238}
239
240if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
241then
242  error_exit "main directory cannot contain spaces nor colons"
243fi
244
245# default parameters
246cpu=""
247static="no"
248cross_compile="no"
249cross_prefix=""
250host_cc="cc"
251stack_protector=""
252safe_stack=""
253use_containers="yes"
254gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
255
256if test -e "$source_path/.git"
257then
258    git_submodules_action="update"
259else
260    git_submodules_action="ignore"
261fi
262
263git_submodules="ui/keycodemapdb"
264git="git"
265
266# Don't accept a target_list environment variable.
267unset target_list
268unset target_list_exclude
269
270# Default value for a variable defining feature "foo".
271#  * foo="no"  feature will only be used if --enable-foo arg is given
272#  * foo=""    feature will be searched for, and if found, will be used
273#              unless --disable-foo is given
274#  * foo="yes" this value will only be set by --enable-foo flag.
275#              feature will searched for,
276#              if not found, configure exits with error
277#
278# Always add --enable-foo and --disable-foo command line args.
279# Distributions want to ensure that several features are compiled in, and it
280# is impossible without a --enable-foo that exits if a feature is not found.
281
282default_feature=""
283# parse CC options second
284for opt do
285  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
286  case "$opt" in
287      --without-default-features)
288          default_feature="no"
289  ;;
290  esac
291done
292
293EXTRA_CFLAGS=""
294EXTRA_CXXFLAGS=""
295EXTRA_OBJCFLAGS=""
296EXTRA_LDFLAGS=""
297
298debug_tcg="no"
299sanitizers="no"
300tsan="no"
301fortify_source="yes"
302EXESUF=""
303modules="no"
304prefix="/usr/local"
305qemu_suffix="qemu"
306softmmu="yes"
307linux_user=""
308bsd_user=""
309pie=""
310coroutine=""
311plugins="$default_feature"
312meson=""
313ninja=""
314bindir="bin"
315skip_meson=no
316vfio_user_server="disabled"
317
318# The following Meson options are handled manually (still they
319# are included in the automatically generated help message)
320
321# 1. Track which submodules are needed
322if test "$default_feature" = no ; then
323  slirp="disabled"
324else
325  slirp="auto"
326fi
327fdt="auto"
328
329# 2. Automatically enable/disable other options
330tcg="auto"
331cfi="false"
332
333# parse CC options second
334for opt do
335  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
336  case "$opt" in
337  --cross-prefix=*) cross_prefix="$optarg"
338                    cross_compile="yes"
339  ;;
340  --cc=*) CC="$optarg"
341  ;;
342  --cxx=*) CXX="$optarg"
343  ;;
344  --cpu=*) cpu="$optarg"
345  ;;
346  --extra-cflags=*)
347    EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
348    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
349    EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
350    ;;
351  --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
352  ;;
353  --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
354  ;;
355  --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
356  ;;
357  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
358  ;;
359  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
360                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
361  ;;
362  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
363                eval "cross_cc_${cc_arch}=\$optarg"
364  ;;
365  --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-prefix-FOO option"
366  ;;
367  --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
368                    eval "cross_prefix_${cc_arch}=\$optarg"
369  ;;
370  esac
371done
372# OS specific
373# Using uname is really, really broken.  Once we have the right set of checks
374# we can eliminate its usage altogether.
375
376# Preferred compiler:
377#  ${CC} (if set)
378#  ${cross_prefix}gcc (if cross-prefix specified)
379#  system compiler
380if test -z "${CC}${cross_prefix}"; then
381  cc="$host_cc"
382else
383  cc="${CC-${cross_prefix}gcc}"
384fi
385
386if test -z "${CXX}${cross_prefix}"; then
387  cxx="c++"
388else
389  cxx="${CXX-${cross_prefix}g++}"
390fi
391
392ar="${AR-${cross_prefix}ar}"
393as="${AS-${cross_prefix}as}"
394ccas="${CCAS-$cc}"
395objcopy="${OBJCOPY-${cross_prefix}objcopy}"
396ld="${LD-${cross_prefix}ld}"
397ranlib="${RANLIB-${cross_prefix}ranlib}"
398nm="${NM-${cross_prefix}nm}"
399smbd="$SMBD"
400strip="${STRIP-${cross_prefix}strip}"
401widl="${WIDL-${cross_prefix}widl}"
402windres="${WINDRES-${cross_prefix}windres}"
403pkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
404query_pkg_config() {
405    "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
406}
407pkg_config=query_pkg_config
408sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
409
410# default flags for all hosts
411# We use -fwrapv to tell the compiler that we require a C dialect where
412# left shift of signed integers is well defined and has the expected
413# 2s-complement style results. (Both clang and gcc agree that it
414# provides these semantics.)
415QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
416QEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
417QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
418QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
419
420QEMU_LDFLAGS=
421
422# Flags that are needed during configure but later taken care of by Meson
423CONFIGURE_CFLAGS="-std=gnu11 -Wall"
424CONFIGURE_LDFLAGS=
425
426
427check_define() {
428cat > $TMPC <<EOF
429#if !defined($1)
430#error $1 not defined
431#endif
432int main(void) { return 0; }
433EOF
434  compile_object
435}
436
437check_include() {
438cat > $TMPC <<EOF
439#include <$1>
440int main(void) { return 0; }
441EOF
442  compile_object
443}
444
445write_c_skeleton() {
446    cat > $TMPC <<EOF
447int main(void) { return 0; }
448EOF
449}
450
451if check_define __linux__ ; then
452  targetos=linux
453elif check_define _WIN32 ; then
454  targetos=windows
455elif check_define __OpenBSD__ ; then
456  targetos=openbsd
457elif check_define __sun__ ; then
458  targetos=sunos
459elif check_define __HAIKU__ ; then
460  targetos=haiku
461elif check_define __FreeBSD__ ; then
462  targetos=freebsd
463elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
464  targetos=gnu/kfreebsd
465elif check_define __DragonFly__ ; then
466  targetos=dragonfly
467elif check_define __NetBSD__; then
468  targetos=netbsd
469elif check_define __APPLE__; then
470  targetos=darwin
471else
472  # This is a fatal error, but don't report it yet, because we
473  # might be going to just print the --help text, or it might
474  # be the result of a missing compiler.
475  targetos=bogus
476fi
477
478# OS specific
479
480mingw32="no"
481bsd="no"
482linux="no"
483solaris="no"
484case $targetos in
485windows)
486  mingw32="yes"
487  plugins="no"
488  pie="no"
489;;
490gnu/kfreebsd)
491  bsd="yes"
492;;
493freebsd)
494  bsd="yes"
495  make="${MAKE-gmake}"
496  # needed for kinfo_getvmmap(3) in libutil.h
497;;
498dragonfly)
499  bsd="yes"
500  make="${MAKE-gmake}"
501;;
502netbsd)
503  bsd="yes"
504  make="${MAKE-gmake}"
505;;
506openbsd)
507  bsd="yes"
508  make="${MAKE-gmake}"
509;;
510darwin)
511  bsd="yes"
512  darwin="yes"
513  # Disable attempts to use ObjectiveC features in os/object.h since they
514  # won't work when we're compiling with gcc as a C compiler.
515  QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
516;;
517sunos)
518  solaris="yes"
519  make="${MAKE-gmake}"
520# needed for CMSG_ macros in sys/socket.h
521  QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
522# needed for TIOCWIN* defines in termios.h
523  QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
524  # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
525  # Note that this check is broken for cross-compilation: if you're
526  # cross-compiling to one of these OSes then you'll need to specify
527  # the correct CPU with the --cpu option.
528  if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
529    cpu="x86_64"
530  fi
531;;
532haiku)
533  pie="no"
534  QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
535;;
536linux)
537  linux="yes"
538;;
539esac
540
541if test ! -z "$cpu" ; then
542  # command line argument
543  :
544elif check_define __i386__ ; then
545  cpu="i386"
546elif check_define __x86_64__ ; then
547  if check_define __ILP32__ ; then
548    cpu="x32"
549  else
550    cpu="x86_64"
551  fi
552elif check_define __sparc__ ; then
553  if check_define __arch64__ ; then
554    cpu="sparc64"
555  else
556    cpu="sparc"
557  fi
558elif check_define _ARCH_PPC ; then
559  if check_define _ARCH_PPC64 ; then
560    if check_define _LITTLE_ENDIAN ; then
561      cpu="ppc64le"
562    else
563      cpu="ppc64"
564    fi
565  else
566    cpu="ppc"
567  fi
568elif check_define __mips__ ; then
569  cpu="mips"
570elif check_define __s390__ ; then
571  if check_define __s390x__ ; then
572    cpu="s390x"
573  else
574    cpu="s390"
575  fi
576elif check_define __riscv ; then
577  cpu="riscv"
578elif check_define __arm__ ; then
579  cpu="arm"
580elif check_define __aarch64__ ; then
581  cpu="aarch64"
582elif check_define __loongarch64 ; then
583  cpu="loongarch64"
584else
585  cpu=$(uname -m)
586fi
587
588# Normalise host CPU name, set multilib cflags
589# Note that this case should only have supported host CPUs, not guests.
590case "$cpu" in
591  armv*b|armv*l|arm)
592    cpu="arm" ;;
593
594  i386|i486|i586|i686|i86pc|BePC)
595    cpu="i386"
596    CPU_CFLAGS="-m32" ;;
597  x32)
598    cpu="x86_64"
599    CPU_CFLAGS="-mx32" ;;
600  x86_64|amd64)
601    cpu="x86_64"
602    # ??? Only extremely old AMD cpus do not have cmpxchg16b.
603    # If we truly care, we should simply detect this case at
604    # runtime and generate the fallback to serial emulation.
605    CPU_CFLAGS="-m64 -mcx16" ;;
606
607  mips*)
608    cpu="mips" ;;
609
610  ppc)
611    CPU_CFLAGS="-m32" ;;
612  ppc64)
613    CPU_CFLAGS="-m64 -mbig-endian" ;;
614  ppc64le)
615    cpu="ppc64"
616    CPU_CFLAGS="-m64 -mlittle-endian" ;;
617
618  s390)
619    CPU_CFLAGS="-m31" ;;
620  s390x)
621    CPU_CFLAGS="-m64" ;;
622
623  sparc|sun4[cdmuv])
624    cpu="sparc"
625    CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
626  sparc64)
627    CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
628esac
629
630: ${make=${MAKE-make}}
631
632# We prefer python 3.x. A bare 'python' is traditionally
633# python 2.x, but some distros have it as python 3.x, so
634# we check that too
635python=
636explicit_python=no
637for binary in "${PYTHON-python3}" python
638do
639    if has "$binary"
640    then
641        python=$(command -v "$binary")
642        break
643    fi
644done
645
646
647# Check for ancillary tools used in testing
648genisoimage=
649for binary in genisoimage mkisofs
650do
651    if has $binary
652    then
653        genisoimage=$(command -v "$binary")
654        break
655    fi
656done
657
658# Default objcc to clang if available, otherwise use CC
659if has clang; then
660  objcc=clang
661else
662  objcc="$cc"
663fi
664
665if test "$mingw32" = "yes" ; then
666  EXESUF=".exe"
667  # MinGW needs -mthreads for TLS and macro _MT.
668  CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
669  write_c_skeleton;
670  prefix="/qemu"
671  bindir=""
672  qemu_suffix=""
673fi
674
675werror=""
676
677meson_option_build_array() {
678  printf '['
679  (if test "$targetos" = windows; then
680    IFS=\;
681  else
682    IFS=:
683  fi
684  for e in $1; do
685    printf '"""'
686    # backslash escape any '\' and '"' characters
687    printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g'
688    printf '""",'
689  done)
690  printf ']\n'
691}
692
693. "$source_path/scripts/meson-buildoptions.sh"
694
695meson_options=
696meson_option_add() {
697  meson_options="$meson_options $(quote_sh "$1")"
698}
699meson_option_parse() {
700  meson_options="$meson_options $(_meson_option_parse "$@")"
701  if test $? -eq 1; then
702    echo "ERROR: unknown option $1"
703    echo "Try '$0 --help' for more information"
704    exit 1
705  fi
706}
707
708for opt do
709  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
710  case "$opt" in
711  --help|-h) show_help=yes
712  ;;
713  --version|-V) exec cat "$source_path/VERSION"
714  ;;
715  --prefix=*) prefix="$optarg"
716  ;;
717  --cross-prefix=*)
718  ;;
719  --cc=*)
720  ;;
721  --host-cc=*) host_cc="$optarg"
722  ;;
723  --cxx=*)
724  ;;
725  --objcc=*) objcc="$optarg"
726  ;;
727  --make=*) make="$optarg"
728  ;;
729  --install=*)
730  ;;
731  --python=*) python="$optarg" ; explicit_python=yes
732  ;;
733  --skip-meson) skip_meson=yes
734  ;;
735  --meson=*) meson="$optarg"
736  ;;
737  --ninja=*) ninja="$optarg"
738  ;;
739  --smbd=*) smbd="$optarg"
740  ;;
741  --extra-cflags=*)
742  ;;
743  --extra-cxxflags=*)
744  ;;
745  --extra-objcflags=*)
746  ;;
747  --extra-ldflags=*)
748  ;;
749  --cross-cc-*)
750  ;;
751  --cross-prefix-*)
752  ;;
753  --enable-debug-info) meson_option_add -Ddebug=true
754  ;;
755  --disable-debug-info) meson_option_add -Ddebug=false
756  ;;
757  --enable-modules)
758      modules="yes"
759  ;;
760  --disable-modules)
761      modules="no"
762  ;;
763  --cpu=*)
764  ;;
765  --target-list=*) target_list="$optarg"
766                   if test "$target_list_exclude"; then
767                       error_exit "Can't mix --target-list with --target-list-exclude"
768                   fi
769  ;;
770  --target-list-exclude=*) target_list_exclude="$optarg"
771                   if test "$target_list"; then
772                       error_exit "Can't mix --target-list-exclude with --target-list"
773                   fi
774  ;;
775  --with-default-devices) meson_option_add -Ddefault_devices=true
776  ;;
777  --without-default-devices) meson_option_add -Ddefault_devices=false
778  ;;
779  --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
780  ;;
781  --with-devices-*) device_arch=${opt#--with-devices-};
782                    device_arch=${device_arch%%=*}
783                    cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
784                    if test -f "$cf"; then
785                        device_archs="$device_archs $device_arch"
786                        eval "devices_${device_arch}=\$optarg"
787                    else
788                        error_exit "File $cf does not exist"
789                    fi
790  ;;
791  --without-default-features) # processed above
792  ;;
793  --static)
794    static="yes"
795    QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
796  ;;
797  --bindir=*) bindir="$optarg"
798  ;;
799  --with-suffix=*) qemu_suffix="$optarg"
800  ;;
801  --host=*|--build=*|\
802  --disable-dependency-tracking|\
803  --sbindir=*|--sharedstatedir=*|\
804  --oldincludedir=*|--datarootdir=*|--infodir=*|\
805  --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
806    # These switches are silently ignored, for compatibility with
807    # autoconf-generated configure scripts. This allows QEMU's
808    # configure to be used by RPM and similar macros that set
809    # lots of directory switches by default.
810  ;;
811  --enable-debug-tcg) debug_tcg="yes"
812  ;;
813  --disable-debug-tcg) debug_tcg="no"
814  ;;
815  --enable-debug)
816      # Enable debugging options that aren't excessively noisy
817      debug_tcg="yes"
818      meson_option_parse --enable-debug-mutex ""
819      meson_option_add -Doptimization=0
820      fortify_source="no"
821  ;;
822  --enable-sanitizers) sanitizers="yes"
823  ;;
824  --disable-sanitizers) sanitizers="no"
825  ;;
826  --enable-tsan) tsan="yes"
827  ;;
828  --disable-tsan) tsan="no"
829  ;;
830  --disable-slirp) slirp="disabled"
831  ;;
832  --enable-slirp) slirp="enabled"
833  ;;
834  --enable-slirp=git) slirp="internal"
835  ;;
836  --enable-slirp=*) slirp="$optarg"
837  ;;
838  --disable-tcg) tcg="disabled"
839                 plugins="no"
840  ;;
841  --enable-tcg) tcg="enabled"
842  ;;
843  --disable-system) softmmu="no"
844  ;;
845  --enable-system) softmmu="yes"
846  ;;
847  --disable-user)
848      linux_user="no" ;
849      bsd_user="no" ;
850  ;;
851  --enable-user) ;;
852  --disable-linux-user) linux_user="no"
853  ;;
854  --enable-linux-user) linux_user="yes"
855  ;;
856  --disable-bsd-user) bsd_user="no"
857  ;;
858  --enable-bsd-user) bsd_user="yes"
859  ;;
860  --enable-pie) pie="yes"
861  ;;
862  --disable-pie) pie="no"
863  ;;
864  --enable-werror) werror="yes"
865  ;;
866  --disable-werror) werror="no"
867  ;;
868  --enable-stack-protector) stack_protector="yes"
869  ;;
870  --disable-stack-protector) stack_protector="no"
871  ;;
872  --enable-safe-stack) safe_stack="yes"
873  ;;
874  --disable-safe-stack) safe_stack="no"
875  ;;
876  --enable-cfi)
877      cfi="true";
878      meson_option_add -Db_lto=true
879  ;;
880  --disable-cfi) cfi="false"
881  ;;
882  --disable-fdt) fdt="disabled"
883  ;;
884  --enable-fdt) fdt="enabled"
885  ;;
886  --enable-fdt=git) fdt="internal"
887  ;;
888  --enable-fdt=*) fdt="$optarg"
889  ;;
890  --with-coroutine=*) coroutine="$optarg"
891  ;;
892  --disable-zlib-test)
893  ;;
894  --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
895      echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
896  ;;
897  --enable-vhdx|--disable-vhdx)
898      echo "$0: $opt is obsolete, VHDX driver is always built" >&2
899  ;;
900  --enable-uuid|--disable-uuid)
901      echo "$0: $opt is obsolete, UUID support is always built" >&2
902  ;;
903  --with-git=*) git="$optarg"
904  ;;
905  --with-git-submodules=*)
906      git_submodules_action="$optarg"
907  ;;
908  --enable-plugins) if test "$mingw32" = "yes"; then
909                        error_exit "TCG plugins not currently supported on Windows platforms"
910                    else
911                        plugins="yes"
912                    fi
913  ;;
914  --disable-plugins) plugins="no"
915  ;;
916  --enable-containers) use_containers="yes"
917  ;;
918  --disable-containers) use_containers="no"
919  ;;
920  --gdb=*) gdb_bin="$optarg"
921  ;;
922  # backwards compatibility options
923  --enable-trace-backend=*) meson_option_parse "--enable-trace-backends=$optarg" "$optarg"
924  ;;
925  --disable-blobs) meson_option_parse --disable-install-blobs ""
926  ;;
927  --enable-vfio-user-server) vfio_user_server="enabled"
928  ;;
929  --disable-vfio-user-server) vfio_user_server="disabled"
930  ;;
931  --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
932  ;;
933  --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
934  ;;
935  # everything else has the same name in configure and meson
936  --*) meson_option_parse "$opt" "$optarg"
937  ;;
938  esac
939done
940
941# test for any invalid configuration combinations
942if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
943    error_exit "Can't enable plugins on non-TCG builds"
944fi
945
946case $git_submodules_action in
947    update|validate)
948        if test ! -e "$source_path/.git"; then
949            echo "ERROR: cannot $git_submodules_action git submodules without .git"
950            exit 1
951        fi
952    ;;
953    ignore)
954        if ! test -f "$source_path/ui/keycodemapdb/README"
955        then
956            echo
957            echo "ERROR: missing GIT submodules"
958            echo
959            if test -e "$source_path/.git"; then
960                echo "--with-git-submodules=ignore specified but submodules were not"
961                echo "checked out.  Please initialize and update submodules."
962            else
963                echo "This is not a GIT checkout but module content appears to"
964                echo "be missing. Do not use 'git archive' or GitHub download links"
965                echo "to acquire QEMU source archives. Non-GIT builds are only"
966                echo "supported with source archives linked from:"
967                echo
968                echo "  https://www.qemu.org/download/#source"
969                echo
970                echo "Developers working with GIT can use scripts/archive-source.sh"
971                echo "if they need to create valid source archives."
972            fi
973            echo
974            exit 1
975        fi
976    ;;
977    *)
978        echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
979        exit 1
980    ;;
981esac
982
983default_target_list=""
984mak_wilds=""
985
986if [ "$linux_user" != no ]; then
987    if [ "$targetos" = linux ] && [ -d "$source_path/linux-user/include/host/$cpu" ]; then
988        linux_user=yes
989    elif [ "$linux_user" = yes ]; then
990        error_exit "linux-user not supported on this architecture"
991    fi
992fi
993if [ "$bsd_user" != no ]; then
994    if [ "$bsd_user" = "" ]; then
995        test $targetos = freebsd && bsd_user=yes
996    fi
997    if [ "$bsd_user" = yes ] && ! [ -d "$source_path/bsd-user/$targetos" ]; then
998        error_exit "bsd-user not supported on this host OS"
999    fi
1000fi
1001if [ "$softmmu" = "yes" ]; then
1002    mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
1003fi
1004if [ "$linux_user" = "yes" ]; then
1005    mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
1006fi
1007if [ "$bsd_user" = "yes" ]; then
1008    mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
1009fi
1010
1011for config in $mak_wilds; do
1012    target="$(basename "$config" .mak)"
1013    if echo "$target_list_exclude" | grep -vq "$target"; then
1014        default_target_list="${default_target_list} $target"
1015    fi
1016done
1017
1018if test x"$show_help" = x"yes" ; then
1019cat << EOF
1020
1021Usage: configure [options]
1022Options: [defaults in brackets after descriptions]
1023
1024Standard options:
1025  --help                   print this message
1026  --prefix=PREFIX          install in PREFIX [$prefix]
1027  --target-list=LIST       set target list (default: build all)
1028$(echo Available targets: $default_target_list | \
1029  fold -s -w 53 | sed -e 's/^/                           /')
1030  --target-list-exclude=LIST exclude a set of targets from the default target-list
1031
1032Advanced options (experts only):
1033  --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
1034  --cc=CC                  use C compiler CC [$cc]
1035  --host-cc=CC             use C compiler CC [$host_cc] for code run at
1036                           build time
1037  --cxx=CXX                use C++ compiler CXX [$cxx]
1038  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
1039  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
1040  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
1041  --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
1042  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
1043  --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
1044  --cross-cc-cflags-ARCH=  use compiler flags when building ARCH guest tests
1045  --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
1046  --make=MAKE              use specified make [$make]
1047  --python=PYTHON          use specified python [$python]
1048  --meson=MESON            use specified meson [$meson]
1049  --ninja=NINJA            use specified ninja [$ninja]
1050  --smbd=SMBD              use specified smbd [$smbd]
1051  --with-git=GIT           use specified git [$git]
1052  --with-git-submodules=update   update git submodules (default if .git dir exists)
1053  --with-git-submodules=validate fail if git submodules are not up to date
1054  --with-git-submodules=ignore   do not update or check git submodules (default if no .git dir)
1055  --static                 enable static build [$static]
1056  --bindir=PATH            install binaries in PATH
1057  --with-suffix=SUFFIX     suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
1058  --without-default-features default all --enable-* options to "disabled"
1059  --without-default-devices  do not include any device that is not needed to
1060                           start the emulator (only use if you are including
1061                           desired devices in configs/devices/)
1062  --with-devices-ARCH=NAME override default configs/devices
1063  --enable-debug           enable common debug build options
1064  --enable-sanitizers      enable default sanitizers
1065  --enable-tsan            enable thread sanitizer
1066  --disable-werror         disable compilation abort on warning
1067  --disable-stack-protector disable compiler-provided stack protection
1068  --cpu=CPU                Build for host CPU [$cpu]
1069  --with-coroutine=BACKEND coroutine backend. Supported options:
1070                           ucontext, sigaltstack, windows
1071  --enable-plugins
1072                           enable plugins via shared library loading
1073  --disable-containers     don't use containers for cross-building
1074  --gdb=GDB-path           gdb to use for gdbstub tests [$gdb_bin]
1075EOF
1076  meson_options_help
1077cat << EOF
1078  system          all system emulation targets
1079  user            supported user emulation targets
1080  linux-user      all linux usermode emulation targets
1081  bsd-user        all BSD usermode emulation targets
1082  pie             Position Independent Executables
1083  modules         modules support (non-Windows)
1084  debug-tcg       TCG debugging (default is disabled)
1085  debug-info      debugging information
1086  safe-stack      SafeStack Stack Smash Protection. Depends on
1087                  clang/llvm >= 3.7 and requires coroutine backend ucontext.
1088
1089NOTE: The object files are built at the place where configure is launched
1090EOF
1091exit 0
1092fi
1093
1094# Remove old dependency files to make sure that they get properly regenerated
1095rm -f ./*/config-devices.mak.d
1096
1097if test -z "$python"
1098then
1099    error_exit "Python not found. Use --python=/path/to/python"
1100fi
1101if ! has "$make"
1102then
1103    error_exit "GNU make ($make) not found"
1104fi
1105
1106# Note that if the Python conditional here evaluates True we will exit
1107# with status 1 which is a shell 'false' value.
1108if ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then
1109  error_exit "Cannot use '$python', Python >= 3.6 is required." \
1110      "Use --python=/path/to/python to specify a supported Python."
1111fi
1112
1113# Suppress writing compiled files
1114python="$python -B"
1115
1116if test -z "$meson"; then
1117    if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.59.3; then
1118        meson=meson
1119    elif test "$git_submodules_action" != 'ignore' ; then
1120        meson=git
1121    elif test -e "${source_path}/meson/meson.py" ; then
1122        meson=internal
1123    else
1124        if test "$explicit_python" = yes; then
1125            error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
1126        else
1127            error_exit "Meson not found.  Use --meson=/path/to/meson"
1128        fi
1129    fi
1130else
1131    # Meson uses its own Python interpreter to invoke other Python scripts,
1132    # but the user wants to use the one they specified with --python.
1133    #
1134    # We do not want to override the distro Python interpreter (and sometimes
1135    # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
1136    # just require --meson=git|internal together with --python.
1137    if test "$explicit_python" = yes; then
1138        case "$meson" in
1139            git | internal) ;;
1140            *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
1141        esac
1142    fi
1143fi
1144
1145if test "$meson" = git; then
1146    git_submodules="${git_submodules} meson"
1147fi
1148
1149case "$meson" in
1150    git | internal)
1151        meson="$python ${source_path}/meson/meson.py"
1152        ;;
1153    *) meson=$(command -v "$meson") ;;
1154esac
1155
1156# Probe for ninja
1157
1158if test -z "$ninja"; then
1159    for c in ninja ninja-build samu; do
1160        if has $c; then
1161            ninja=$(command -v "$c")
1162            break
1163        fi
1164    done
1165    if test -z "$ninja"; then
1166      error_exit "Cannot find Ninja"
1167    fi
1168fi
1169
1170# Check that the C compiler works. Doing this here before testing
1171# the host CPU ensures that we had a valid CC to autodetect the
1172# $cpu var (and we should bail right here if that's not the case).
1173# It also allows the help message to be printed without a CC.
1174write_c_skeleton;
1175if compile_object ; then
1176  : C compiler works ok
1177else
1178    error_exit "\"$cc\" either does not exist or does not work"
1179fi
1180if ! compile_prog ; then
1181    error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
1182fi
1183
1184# Consult white-list to determine whether to enable werror
1185# by default.  Only enable by default for git builds
1186if test -z "$werror" ; then
1187    if test "$git_submodules_action" != "ignore" && \
1188        { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
1189        werror="yes"
1190    else
1191        werror="no"
1192    fi
1193fi
1194
1195if test "$targetos" = "bogus"; then
1196    # Now that we know that we're not printing the help and that
1197    # the compiler works (so the results of the check_defines we used
1198    # to identify the OS are reliable), if we didn't recognize the
1199    # host OS we should stop now.
1200    error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1201fi
1202
1203# Check whether the compiler matches our minimum requirements:
1204cat > $TMPC << EOF
1205#if defined(__clang_major__) && defined(__clang_minor__)
1206# ifdef __apple_build_version__
1207#  if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
1208#   error You need at least XCode Clang v10.0 to compile QEMU
1209#  endif
1210# else
1211#  if __clang_major__ < 6 || (__clang_major__ == 6 && __clang_minor__ < 0)
1212#   error You need at least Clang v6.0 to compile QEMU
1213#  endif
1214# endif
1215#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
1216# if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
1217#  error You need at least GCC v7.4.0 to compile QEMU
1218# endif
1219#else
1220# error You either need GCC or Clang to compiler QEMU
1221#endif
1222int main (void) { return 0; }
1223EOF
1224if ! compile_prog "" "" ; then
1225    error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
1226fi
1227
1228# Accumulate -Wfoo and -Wno-bar separately.
1229# We will list all of the enable flags first, and the disable flags second.
1230# Note that we do not add -Werror, because that would enable it for all
1231# configure tests. If a configure test failed due to -Werror this would
1232# just silently disable some features, so it's too error prone.
1233
1234warn_flags=
1235add_to warn_flags -Wold-style-declaration
1236add_to warn_flags -Wold-style-definition
1237add_to warn_flags -Wtype-limits
1238add_to warn_flags -Wformat-security
1239add_to warn_flags -Wformat-y2k
1240add_to warn_flags -Winit-self
1241add_to warn_flags -Wignored-qualifiers
1242add_to warn_flags -Wempty-body
1243add_to warn_flags -Wnested-externs
1244add_to warn_flags -Wendif-labels
1245add_to warn_flags -Wexpansion-to-defined
1246add_to warn_flags -Wimplicit-fallthrough=2
1247
1248nowarn_flags=
1249add_to nowarn_flags -Wno-initializer-overrides
1250add_to nowarn_flags -Wno-missing-include-dirs
1251add_to nowarn_flags -Wno-shift-negative-value
1252add_to nowarn_flags -Wno-string-plus-int
1253add_to nowarn_flags -Wno-typedef-redefinition
1254add_to nowarn_flags -Wno-tautological-type-limit-compare
1255add_to nowarn_flags -Wno-psabi
1256
1257gcc_flags="$warn_flags $nowarn_flags"
1258
1259cc_has_warning_flag() {
1260    write_c_skeleton;
1261
1262    # Use the positive sense of the flag when testing for -Wno-wombat
1263    # support (gcc will happily accept the -Wno- form of unknown
1264    # warning options).
1265    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
1266    compile_prog "-Werror $optflag" ""
1267}
1268
1269objcc_has_warning_flag() {
1270    cat > $TMPM <<EOF
1271int main(void) { return 0; }
1272EOF
1273
1274    # Use the positive sense of the flag when testing for -Wno-wombat
1275    # support (gcc will happily accept the -Wno- form of unknown
1276    # warning options).
1277    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
1278    do_objc -Werror $optflag \
1279      $OBJCFLAGS $EXTRA_OBJCFLAGS $CONFIGURE_OBJCFLAGS $QEMU_OBJCFLAGS \
1280      -o $TMPE $TMPM $QEMU_LDFLAGS
1281}
1282
1283for flag in $gcc_flags; do
1284    if cc_has_warning_flag $flag ; then
1285        QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1286    fi
1287    if objcc_has_warning_flag $flag ; then
1288        QEMU_OBJCFLAGS="$QEMU_OBJCFLAGS $flag"
1289    fi
1290done
1291
1292if test "$stack_protector" != "no"; then
1293  cat > $TMPC << EOF
1294int main(int argc, char *argv[])
1295{
1296    char arr[64], *p = arr, *c = argv[0];
1297    while (*c) {
1298        *p++ = *c++;
1299    }
1300    return 0;
1301}
1302EOF
1303  gcc_flags="-fstack-protector-strong -fstack-protector-all"
1304  sp_on=0
1305  for flag in $gcc_flags; do
1306    # We need to check both a compile and a link, since some compiler
1307    # setups fail only on a .c->.o compile and some only at link time
1308    if compile_object "-Werror $flag" &&
1309       compile_prog "-Werror $flag" ""; then
1310      QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1311      QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
1312      sp_on=1
1313      break
1314    fi
1315  done
1316  if test "$stack_protector" = yes; then
1317    if test $sp_on = 0; then
1318      error_exit "Stack protector not supported"
1319    fi
1320  fi
1321fi
1322
1323# Disable -Wmissing-braces on older compilers that warn even for
1324# the "universal" C zero initializer {0}.
1325cat > $TMPC << EOF
1326struct {
1327  int a[2];
1328} x = {0};
1329EOF
1330if compile_object "-Werror" "" ; then
1331  :
1332else
1333  QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
1334fi
1335
1336# Our module code doesn't support Windows
1337if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
1338  error_exit "Modules are not available for Windows"
1339fi
1340
1341# Static linking is not possible with plugins, modules or PIE
1342if test "$static" = "yes" ; then
1343  if test "$modules" = "yes" ; then
1344    error_exit "static and modules are mutually incompatible"
1345  fi
1346  if test "$plugins" = "yes"; then
1347    error_exit "static and plugins are mutually incompatible"
1348  else
1349    plugins="no"
1350  fi
1351fi
1352test "$plugins" = "" && plugins=yes
1353
1354cat > $TMPC << EOF
1355
1356#ifdef __linux__
1357#  define THREAD __thread
1358#else
1359#  define THREAD
1360#endif
1361static THREAD int tls_var;
1362int main(void) { return tls_var; }
1363EOF
1364
1365if test "$static" = "yes"; then
1366  if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
1367    CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
1368    QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
1369    pie="yes"
1370  elif test "$pie" = "yes"; then
1371    error_exit "-static-pie not available due to missing toolchain support"
1372  else
1373    QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
1374    pie="no"
1375  fi
1376elif test "$pie" = "no"; then
1377  if compile_prog "-Werror -fno-pie" "-no-pie"; then
1378    CONFIGURE_CFLAGS="-fno-pie $CONFIGURE_CFLAGS"
1379    CONFIGURE_LDFLAGS="-no-pie $CONFIGURE_LDFLAGS"
1380    # Meson currently only handles pie as a boolean for now so if we have
1381    # explicitly disabled PIE we need to extend our cflags because it wont.
1382    QEMU_CFLAGS="-fno-pie -no-pie $QEMU_CFLAGS"
1383  fi
1384elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
1385  CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
1386  CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
1387  pie="yes"
1388elif test "$pie" = "yes"; then
1389  error_exit "PIE not available due to missing toolchain support"
1390else
1391  echo "Disabling PIE due to missing toolchain support"
1392  pie="no"
1393fi
1394
1395# Detect support for PT_GNU_RELRO + DT_BIND_NOW.
1396# The combination is known as "full relro", because .got.plt is read-only too.
1397if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1398  QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
1399fi
1400
1401##########################################
1402# __sync_fetch_and_and requires at least -march=i486. Many toolchains
1403# use i686 as default anyway, but for those that don't, an explicit
1404# specification is necessary
1405
1406if test "$cpu" = "i386"; then
1407  cat > $TMPC << EOF
1408static int sfaa(int *ptr)
1409{
1410  return __sync_fetch_and_and(ptr, 0);
1411}
1412
1413int main(void)
1414{
1415  int val = 42;
1416  val = __sync_val_compare_and_swap(&val, 0, 1);
1417  sfaa(&val);
1418  return val;
1419}
1420EOF
1421  if ! compile_prog "" "" ; then
1422    QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
1423  fi
1424fi
1425
1426if test -z "${target_list+xxx}" ; then
1427    default_targets=yes
1428    for target in $default_target_list; do
1429        target_list="$target_list $target"
1430    done
1431    target_list="${target_list# }"
1432else
1433    default_targets=no
1434    target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1435    for target in $target_list; do
1436        # Check that we recognised the target name; this allows a more
1437        # friendly error message than if we let it fall through.
1438        case " $default_target_list " in
1439            *" $target "*)
1440                ;;
1441            *)
1442                error_exit "Unknown target name '$target'"
1443                ;;
1444        esac
1445    done
1446fi
1447
1448# see if system emulation was really requested
1449case " $target_list " in
1450  *"-softmmu "*) softmmu=yes
1451  ;;
1452  *) softmmu=no
1453  ;;
1454esac
1455
1456if test "$tcg" = "auto"; then
1457  if test -z "$target_list"; then
1458    tcg="disabled"
1459  else
1460    tcg="enabled"
1461  fi
1462fi
1463
1464if test "$tcg" = "enabled"; then
1465    git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
1466    git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
1467fi
1468
1469# ---
1470# big/little endian test
1471cat > $TMPC << EOF
1472#include <stdio.h>
1473short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
1474short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
1475int main(int argc, char *argv[])
1476{
1477    return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
1478}
1479EOF
1480
1481if compile_prog ; then
1482    if strings -a $TMPE | grep -q BiGeNdIaN ; then
1483        bigendian="yes"
1484    elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
1485        bigendian="no"
1486    else
1487        echo big/little test failed
1488        exit 1
1489    fi
1490else
1491    echo big/little test failed
1492    exit 1
1493fi
1494
1495##########################################
1496# pkg-config probe
1497
1498if ! has "$pkg_config_exe"; then
1499  error_exit "pkg-config binary '$pkg_config_exe' not found"
1500fi
1501
1502##########################################
1503# glib support probe
1504
1505# When bumping glib_req_ver, please check also whether we should increase
1506# the _WIN32_WINNT setting in osdep.h according to the value from glib
1507glib_req_ver=2.56
1508glib_modules=gthread-2.0
1509if test "$modules" = yes; then
1510    glib_modules="$glib_modules gmodule-export-2.0"
1511elif test "$plugins" = "yes"; then
1512    glib_modules="$glib_modules gmodule-no-export-2.0"
1513fi
1514
1515for i in $glib_modules; do
1516    if $pkg_config --atleast-version=$glib_req_ver $i; then
1517        glib_cflags=$($pkg_config --cflags $i)
1518        glib_libs=$($pkg_config --libs $i)
1519    else
1520        error_exit "glib-$glib_req_ver $i is required to compile QEMU"
1521    fi
1522done
1523
1524glib_bindir="$($pkg_config --variable=bindir glib-2.0)"
1525if test -z "$glib_bindir" ; then
1526	glib_bindir="$($pkg_config --variable=prefix glib-2.0)"/bin
1527fi
1528
1529# This workaround is required due to a bug in pkg-config file for glib as it
1530# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
1531
1532if test "$static" = yes && test "$mingw32" = yes; then
1533    glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
1534fi
1535
1536# Sanity check that the current size_t matches the
1537# size that glib thinks it should be. This catches
1538# problems on multi-arch where people try to build
1539# 32-bit QEMU while pointing at 64-bit glib headers
1540cat > $TMPC <<EOF
1541#include <glib.h>
1542#include <unistd.h>
1543
1544#define QEMU_BUILD_BUG_ON(x) \
1545  typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
1546
1547int main(void) {
1548   QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
1549   return 0;
1550}
1551EOF
1552
1553if ! compile_prog "$glib_cflags" "$glib_libs" ; then
1554    error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
1555               "You probably need to set PKG_CONFIG_LIBDIR"\
1556	       "to point to the right pkg-config files for your"\
1557	       "build target"
1558fi
1559
1560# Silence clang warnings triggered by glib < 2.57.2
1561cat > $TMPC << EOF
1562#include <glib.h>
1563typedef struct Foo {
1564    int i;
1565} Foo;
1566static void foo_free(Foo *f)
1567{
1568    g_free(f);
1569}
1570G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
1571int main(void) { return 0; }
1572EOF
1573if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
1574    if cc_has_warning_flag "-Wno-unused-function"; then
1575        glib_cflags="$glib_cflags -Wno-unused-function"
1576        CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
1577    fi
1578fi
1579
1580##########################################
1581# fdt probe
1582
1583case "$fdt" in
1584  auto | enabled | internal)
1585    # Simpler to always update submodule, even if not needed.
1586    git_submodules="${git_submodules} dtc"
1587    ;;
1588esac
1589
1590##########################################
1591# check and set a backend for coroutine
1592
1593# We prefer ucontext, but it's not always possible. The fallback
1594# is sigcontext. On Windows the only valid backend is the Windows
1595# specific one.
1596
1597ucontext_works=no
1598if test "$darwin" != "yes"; then
1599  cat > $TMPC << EOF
1600#include <ucontext.h>
1601#ifdef __stub_makecontext
1602#error Ignoring glibc stub makecontext which will always fail
1603#endif
1604int main(void) { makecontext(0, 0, 0); return 0; }
1605EOF
1606  if compile_prog "" "" ; then
1607    ucontext_works=yes
1608  fi
1609fi
1610
1611if test "$coroutine" = ""; then
1612  if test "$mingw32" = "yes"; then
1613    coroutine=win32
1614  elif test "$ucontext_works" = "yes"; then
1615    coroutine=ucontext
1616  else
1617    coroutine=sigaltstack
1618  fi
1619else
1620  case $coroutine in
1621  windows)
1622    if test "$mingw32" != "yes"; then
1623      error_exit "'windows' coroutine backend only valid for Windows"
1624    fi
1625    # Unfortunately the user visible backend name doesn't match the
1626    # coroutine-*.c filename for this case, so we have to adjust it here.
1627    coroutine=win32
1628    ;;
1629  ucontext)
1630    if test "$ucontext_works" != "yes"; then
1631      error_exit "'ucontext' backend requested but makecontext not available"
1632    fi
1633    ;;
1634  sigaltstack)
1635    if test "$mingw32" = "yes"; then
1636      error_exit "only the 'windows' coroutine backend is valid for Windows"
1637    fi
1638    ;;
1639  *)
1640    error_exit "unknown coroutine backend $coroutine"
1641    ;;
1642  esac
1643fi
1644
1645##################################################
1646# SafeStack
1647
1648
1649if test "$safe_stack" = "yes"; then
1650cat > $TMPC << EOF
1651int main(int argc, char *argv[])
1652{
1653#if ! __has_feature(safe_stack)
1654#error SafeStack Disabled
1655#endif
1656    return 0;
1657}
1658EOF
1659  flag="-fsanitize=safe-stack"
1660  # Check that safe-stack is supported and enabled.
1661  if compile_prog "-Werror $flag" "$flag"; then
1662    # Flag needed both at compilation and at linking
1663    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1664    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
1665  else
1666    error_exit "SafeStack not supported by your compiler"
1667  fi
1668  if test "$coroutine" != "ucontext"; then
1669    error_exit "SafeStack is only supported by the coroutine backend ucontext"
1670  fi
1671else
1672cat > $TMPC << EOF
1673int main(int argc, char *argv[])
1674{
1675#if defined(__has_feature)
1676#if __has_feature(safe_stack)
1677#error SafeStack Enabled
1678#endif
1679#endif
1680    return 0;
1681}
1682EOF
1683if test "$safe_stack" = "no"; then
1684  # Make sure that safe-stack is disabled
1685  if ! compile_prog "-Werror" ""; then
1686    # SafeStack was already enabled, try to explicitly remove the feature
1687    flag="-fno-sanitize=safe-stack"
1688    if ! compile_prog "-Werror $flag" "$flag"; then
1689      error_exit "Configure cannot disable SafeStack"
1690    fi
1691    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1692    QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
1693  fi
1694else # "$safe_stack" = ""
1695  # Set safe_stack to yes or no based on pre-existing flags
1696  if compile_prog "-Werror" ""; then
1697    safe_stack="no"
1698  else
1699    safe_stack="yes"
1700    if test "$coroutine" != "ucontext"; then
1701      error_exit "SafeStack is only supported by the coroutine backend ucontext"
1702    fi
1703  fi
1704fi
1705fi
1706
1707########################################
1708# check if ccache is interfering with
1709# semantic analysis of macros
1710
1711unset CCACHE_CPP2
1712ccache_cpp2=no
1713cat > $TMPC << EOF
1714static const int Z = 1;
1715#define fn() ({ Z; })
1716#define TAUT(X) ((X) == Z)
1717#define PAREN(X, Y) (X == Y)
1718#define ID(X) (X)
1719int main(int argc, char *argv[])
1720{
1721    int x = 0, y = 0;
1722    x = ID(x);
1723    x = fn();
1724    fn();
1725    if (PAREN(x, y)) return 0;
1726    if (TAUT(Z)) return 0;
1727    return 0;
1728}
1729EOF
1730
1731if ! compile_object "-Werror"; then
1732    ccache_cpp2=yes
1733fi
1734
1735#################################################
1736# clang does not support glibc + FORTIFY_SOURCE.
1737
1738if test "$fortify_source" != "no"; then
1739  if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
1740    fortify_source="no";
1741  elif test -n "$cxx" && has $cxx &&
1742       echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
1743    fortify_source="no";
1744  else
1745    fortify_source="yes"
1746  fi
1747fi
1748
1749##########################################
1750# checks for sanitizers
1751
1752have_asan=no
1753have_ubsan=no
1754have_asan_iface_h=no
1755have_asan_iface_fiber=no
1756
1757if test "$sanitizers" = "yes" ; then
1758  write_c_skeleton
1759  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
1760      have_asan=yes
1761  fi
1762
1763  # we could use a simple skeleton for flags checks, but this also
1764  # detect the static linking issue of ubsan, see also:
1765  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
1766  cat > $TMPC << EOF
1767#include <stdlib.h>
1768int main(void) {
1769    void *tmp = malloc(10);
1770    if (tmp != NULL) {
1771        return *(int *)(tmp + 2);
1772    }
1773    return 1;
1774}
1775EOF
1776  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
1777      have_ubsan=yes
1778  fi
1779
1780  if check_include "sanitizer/asan_interface.h" ; then
1781      have_asan_iface_h=yes
1782  fi
1783
1784  cat > $TMPC << EOF
1785#include <sanitizer/asan_interface.h>
1786int main(void) {
1787  __sanitizer_start_switch_fiber(0, 0, 0);
1788  return 0;
1789}
1790EOF
1791  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
1792      have_asan_iface_fiber=yes
1793  fi
1794fi
1795
1796# Thread sanitizer is, for now, much noisier than the other sanitizers;
1797# keep it separate until that is not the case.
1798if test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
1799  error_exit "TSAN is not supported with other sanitiziers."
1800fi
1801have_tsan=no
1802have_tsan_iface_fiber=no
1803if test "$tsan" = "yes" ; then
1804  write_c_skeleton
1805  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
1806      have_tsan=yes
1807  fi
1808  cat > $TMPC << EOF
1809#include <sanitizer/tsan_interface.h>
1810int main(void) {
1811  __tsan_create_fiber(0);
1812  return 0;
1813}
1814EOF
1815  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
1816      have_tsan_iface_fiber=yes
1817  fi
1818fi
1819
1820##########################################
1821# check for slirp
1822
1823case "$slirp" in
1824  auto | enabled | internal)
1825    # Simpler to always update submodule, even if not needed.
1826    git_submodules="${git_submodules} slirp"
1827    ;;
1828esac
1829
1830##########################################
1831# functions to probe cross compilers
1832
1833container="no"
1834if test $use_containers = "yes"; then
1835    if has "docker" || has "podman"; then
1836        container=$($python "$source_path"/tests/docker/docker.py probe)
1837    fi
1838fi
1839
1840# cross compilers defaults, can be overridden with --cross-cc-ARCH
1841: ${cross_prefix_aarch64="aarch64-linux-gnu-"}
1842: ${cross_prefix_aarch64_be="$cross_prefix_aarch64"}
1843: ${cross_prefix_alpha="alpha-linux-gnu-"}
1844: ${cross_prefix_arm="arm-linux-gnueabihf-"}
1845: ${cross_prefix_armeb="$cross_prefix_arm"}
1846: ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
1847: ${cross_prefix_loongarch64="loongarch64-unknown-linux-gnu-"}
1848: ${cross_prefix_hppa="hppa-linux-gnu-"}
1849: ${cross_prefix_i386="i686-linux-gnu-"}
1850: ${cross_prefix_m68k="m68k-linux-gnu-"}
1851: ${cross_prefix_microblaze="microblaze-linux-musl-"}
1852: ${cross_prefix_mips64el="mips64el-linux-gnuabi64-"}
1853: ${cross_prefix_mips64="mips64-linux-gnuabi64-"}
1854: ${cross_prefix_mipsel="mipsel-linux-gnu-"}
1855: ${cross_prefix_mips="mips-linux-gnu-"}
1856: ${cross_prefix_nios2="nios2-linux-gnu-"}
1857: ${cross_prefix_ppc="powerpc-linux-gnu-"}
1858: ${cross_prefix_ppc64="powerpc64-linux-gnu-"}
1859: ${cross_prefix_ppc64le="$cross_prefix_ppc64"}
1860: ${cross_prefix_riscv64="riscv64-linux-gnu-"}
1861: ${cross_prefix_s390x="s390x-linux-gnu-"}
1862: ${cross_prefix_sh4="sh4-linux-gnu-"}
1863: ${cross_prefix_sparc64="sparc64-linux-gnu-"}
1864: ${cross_prefix_sparc="$cross_prefix_sparc64"}
1865: ${cross_prefix_x86_64="x86_64-linux-gnu-"}
1866
1867: ${cross_cc_aarch64_be="$cross_cc_aarch64"}
1868: ${cross_cc_cflags_aarch64_be="-mbig-endian"}
1869: ${cross_cc_armeb="$cross_cc_arm"}
1870: ${cross_cc_cflags_armeb="-mbig-endian"}
1871: ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
1872: ${cross_cc_cflags_hexagon="-mv67 -O2 -static"}
1873: ${cross_cc_cflags_i386="-m32"}
1874: ${cross_cc_cflags_ppc="-m32 -mbig-endian"}
1875: ${cross_cc_cflags_ppc64="-m64 -mbig-endian"}
1876: ${cross_cc_ppc64le="$cross_cc_ppc64"}
1877: ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"}
1878: ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
1879: ${cross_cc_sparc="$cross_cc_sparc64"}
1880: ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
1881: ${cross_cc_cflags_x86_64="-m64"}
1882
1883compute_target_variable() {
1884  eval "$2="
1885  if eval test -n "\"\${cross_prefix_$1}\""; then
1886    if eval has "\"\${cross_prefix_$1}\$3\""; then
1887      eval "$2=\"\${cross_prefix_$1}\$3\""
1888    fi
1889  fi
1890}
1891
1892# probe_target_compiler TARGET
1893#
1894# Look for a compiler for the given target, either native or cross.
1895# Set variables target_* if a compiler is found, and container_cross_*
1896# if a Docker-based cross-compiler image is known for the target.
1897# Set got_cross_cc to yes/no depending on whether a non-container-based
1898# compiler was found.
1899#
1900# If TARGET is a user-mode emulation target, also set build_static to
1901# "y" if static linking is possible.
1902#
1903probe_target_compiler() {
1904  # reset all output variables
1905  got_cross_cc=no
1906  container_image=
1907  container_hosts=
1908  container_cross_cc=
1909  container_cross_ar=
1910  container_cross_as=
1911  container_cross_ld=
1912  container_cross_nm=
1913  container_cross_objcopy=
1914  container_cross_ranlib=
1915  container_cross_strip=
1916
1917  target_arch=${1%%-*}
1918  case $target_arch in
1919    aarch64) container_hosts="x86_64 aarch64" ;;
1920    alpha) container_hosts=x86_64 ;;
1921    arm) container_hosts="x86_64 aarch64" ;;
1922    cris) container_hosts=x86_64 ;;
1923    hexagon) container_hosts=x86_64 ;;
1924    hppa) container_hosts=x86_64 ;;
1925    i386) container_hosts=x86_64 ;;
1926    loongarch64) container_hosts=x86_64 ;;
1927    m68k) container_hosts=x86_64 ;;
1928    microblaze) container_hosts=x86_64 ;;
1929    mips64el) container_hosts=x86_64 ;;
1930    mips64) container_hosts=x86_64 ;;
1931    mipsel) container_hosts=x86_64 ;;
1932    mips) container_hosts=x86_64 ;;
1933    nios2) container_hosts=x86_64 ;;
1934    ppc) container_hosts=x86_64 ;;
1935    ppc64|ppc64le) container_hosts=x86_64 ;;
1936    riscv64) container_hosts=x86_64 ;;
1937    s390x) container_hosts=x86_64 ;;
1938    sh4) container_hosts=x86_64 ;;
1939    sparc64) container_hosts=x86_64 ;;
1940    tricore) container_hosts=x86_64 ;;
1941    x86_64) container_hosts="aarch64 ppc64el x86_64" ;;
1942    xtensa*) container_hosts=x86_64 ;;
1943  esac
1944
1945  for host in $container_hosts; do
1946    test "$container" != no || continue
1947    test "$host" = "$cpu" || continue
1948    case $target_arch in
1949      aarch64)
1950        # We don't have any bigendian build tools so we only use this for AArch64
1951        container_image=debian-arm64-cross
1952        container_cross_prefix=aarch64-linux-gnu-
1953        container_cross_cc=${container_cross_prefix}gcc-10
1954        ;;
1955      alpha)
1956        container_image=debian-alpha-cross
1957        container_cross_prefix=alpha-linux-gnu-
1958        ;;
1959      arm)
1960        # We don't have any bigendian build tools so we only use this for ARM
1961        container_image=debian-armhf-cross
1962        container_cross_prefix=arm-linux-gnueabihf-
1963        ;;
1964      cris)
1965        container_image=fedora-cris-cross
1966        container_cross_prefix=cris-linux-gnu-
1967        ;;
1968      hexagon)
1969        container_image=debian-hexagon-cross
1970        container_cross_prefix=hexagon-unknown-linux-musl-
1971        container_cross_cc=${container_cross_prefix}clang
1972        ;;
1973      hppa)
1974        container_image=debian-hppa-cross
1975        container_cross_prefix=hppa-linux-gnu-
1976        ;;
1977      i386)
1978        container_image=fedora-i386-cross
1979        container_cross_prefix=
1980        ;;
1981      loongarch64)
1982        container_image=debian-loongarch-cross
1983        container_cross_prefix=loongarch64-unknown-linux-gnu-
1984        ;;
1985      m68k)
1986        container_image=debian-m68k-cross
1987        container_cross_prefix=m68k-linux-gnu-
1988        ;;
1989      microblaze)
1990        container_image=debian-microblaze-cross
1991        container_cross_prefix=microblaze-linux-musl-
1992        ;;
1993      mips64el)
1994        container_image=debian-mips64el-cross
1995        container_cross_prefix=mips64el-linux-gnuabi64-
1996        ;;
1997      mips64)
1998        container_image=debian-mips64-cross
1999        container_cross_prefix=mips64-linux-gnuabi64-
2000        ;;
2001      mipsel)
2002        container_image=debian-mipsel-cross
2003        container_cross_prefix=mipsel-linux-gnu-
2004        ;;
2005      mips)
2006        container_image=debian-mips-cross
2007        container_cross_prefix=mips-linux-gnu-
2008        ;;
2009      nios2)
2010        container_image=debian-nios2-cross
2011        container_cross_prefix=nios2-linux-gnu-
2012        ;;
2013      ppc)
2014        container_image=debian-powerpc-test-cross
2015        container_cross_prefix=powerpc-linux-gnu-
2016        container_cross_cc=${container_cross_prefix}gcc-10
2017        ;;
2018      ppc64|ppc64le)
2019        container_image=debian-powerpc-test-cross
2020        container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu-
2021        container_cross_cc=${container_cross_prefix}gcc-10
2022        ;;
2023      riscv64)
2024        container_image=debian-riscv64-test-cross
2025        container_cross_prefix=riscv64-linux-gnu-
2026        ;;
2027      s390x)
2028        container_image=debian-s390x-cross
2029        container_cross_prefix=s390x-linux-gnu-
2030        ;;
2031      sh4)
2032        container_image=debian-sh4-cross
2033        container_cross_prefix=sh4-linux-gnu-
2034        ;;
2035      sparc64)
2036        container_image=debian-sparc64-cross
2037        container_cross_prefix=sparc64-linux-gnu-
2038        ;;
2039      tricore)
2040        container_image=debian-tricore-cross
2041        container_cross_prefix=tricore-
2042        container_cross_as=tricore-as
2043        container_cross_ld=tricore-ld
2044        break
2045        ;;
2046      x86_64)
2047        container_image=debian-amd64-cross
2048        container_cross_prefix=x86_64-linux-gnu-
2049        ;;
2050      xtensa*)
2051        container_hosts=x86_64
2052        container_image=debian-xtensa-cross
2053
2054        # default to the dc232b cpu
2055        container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
2056        ;;
2057    esac
2058    : ${container_cross_cc:=${container_cross_prefix}gcc}
2059    : ${container_cross_ar:=${container_cross_prefix}ar}
2060    : ${container_cross_as:=${container_cross_prefix}as}
2061    : ${container_cross_ld:=${container_cross_prefix}ld}
2062    : ${container_cross_nm:=${container_cross_prefix}nm}
2063    : ${container_cross_objcopy:=${container_cross_prefix}objcopy}
2064    : ${container_cross_ranlib:=${container_cross_prefix}ranlib}
2065    : ${container_cross_strip:=${container_cross_prefix}strip}
2066  done
2067
2068  try=cross
2069  case "$target_arch:$cpu" in
2070    aarch64_be:aarch64 | \
2071    armeb:arm | \
2072    i386:x86_64 | \
2073    mips*:mips64 | \
2074    ppc*:ppc64 | \
2075    sparc:sparc64 | \
2076    "$cpu:$cpu")
2077      try='native cross' ;;
2078  esac
2079  eval "target_cflags=\${cross_cc_cflags_$target_arch}"
2080  for thistry in $try; do
2081    case $thistry in
2082    native)
2083      target_cc=$cc
2084      target_ccas=$ccas
2085      target_ar=$ar
2086      target_as=$as
2087      target_ld=$ld
2088      target_nm=$nm
2089      target_objcopy=$objcopy
2090      target_ranlib=$ranlib
2091      target_strip=$strip
2092      ;;
2093    cross)
2094      target_cc=
2095      if eval test -n "\"\${cross_cc_$target_arch}\""; then
2096        if eval has "\"\${cross_cc_$target_arch}\""; then
2097          eval "target_cc=\"\${cross_cc_$target_arch}\""
2098        fi
2099      else
2100        compute_target_variable $target_arch target_cc gcc
2101      fi
2102      target_ccas=$target_cc
2103      compute_target_variable $target_arch target_ar ar
2104      compute_target_variable $target_arch target_as as
2105      compute_target_variable $target_arch target_ld ld
2106      compute_target_variable $target_arch target_nm nm
2107      compute_target_variable $target_arch target_objcopy objcopy
2108      compute_target_variable $target_arch target_ranlib ranlib
2109      compute_target_variable $target_arch target_strip strip
2110      ;;
2111    esac
2112
2113    if test -n "$target_cc"; then
2114      case $target_arch in
2115        i386|x86_64)
2116          if $target_cc --version | grep -qi "clang"; then
2117            continue
2118          fi
2119          ;;
2120      esac
2121    elif test -n "$target_as" && test -n "$target_ld"; then
2122      # Special handling for assembler only targets
2123      case $target in
2124        tricore-softmmu)
2125          build_static=
2126          got_cross_cc=yes
2127          break
2128          ;;
2129        *)
2130          continue
2131          ;;
2132      esac
2133    else
2134      continue
2135    fi
2136
2137    write_c_skeleton
2138    case $1 in
2139      *-softmmu)
2140        if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC &&
2141          do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then
2142          got_cross_cc=yes
2143          break
2144        fi
2145        ;;
2146      *)
2147        if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC -static ; then
2148          build_static=y
2149          got_cross_cc=yes
2150          break
2151        fi
2152        if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC ; then
2153          build_static=
2154          got_cross_cc=yes
2155          break
2156        fi
2157        ;;
2158    esac
2159  done
2160  if test $got_cross_cc != yes; then
2161    build_static=
2162    target_cc=
2163    target_ccas=
2164    target_ar=
2165    target_as=
2166    target_ld=
2167    target_nm=
2168    target_objcopy=
2169    target_ranlib=
2170    target_strip=
2171  fi
2172}
2173
2174write_target_makefile() {
2175  echo "EXTRA_CFLAGS=$target_cflags"
2176  if test -n "$target_cc"; then
2177    echo "CC=$target_cc"
2178    echo "CCAS=$target_ccas"
2179  fi
2180  if test -n "$target_ar"; then
2181    echo "AR=$target_ar"
2182  fi
2183  if test -n "$target_as"; then
2184    echo "AS=$target_as"
2185  fi
2186  if test -n "$target_ld"; then
2187    echo "LD=$target_ld"
2188  fi
2189  if test -n "$target_nm"; then
2190    echo "NM=$target_nm"
2191  fi
2192  if test -n "$target_objcopy"; then
2193    echo "OBJCOPY=$target_objcopy"
2194  fi
2195  if test -n "$target_ranlib"; then
2196    echo "RANLIB=$target_ranlib"
2197  fi
2198  if test -n "$target_strip"; then
2199    echo "STRIP=$target_strip"
2200  fi
2201}
2202
2203write_container_target_makefile() {
2204  echo "EXTRA_CFLAGS=$target_cflags"
2205  if test -n "$container_cross_cc"; then
2206    echo "CC=\$(DOCKER_SCRIPT) cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
2207    echo "CCAS=\$(DOCKER_SCRIPT) cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
2208  fi
2209  echo "AR=\$(DOCKER_SCRIPT) cc --cc $container_cross_ar -i qemu/$container_image -s $source_path --"
2210  echo "AS=\$(DOCKER_SCRIPT) cc --cc $container_cross_as -i qemu/$container_image -s $source_path --"
2211  echo "LD=\$(DOCKER_SCRIPT) cc --cc $container_cross_ld -i qemu/$container_image -s $source_path --"
2212  echo "NM=\$(DOCKER_SCRIPT) cc --cc $container_cross_nm -i qemu/$container_image -s $source_path --"
2213  echo "OBJCOPY=\$(DOCKER_SCRIPT) cc --cc $container_cross_objcopy -i qemu/$container_image -s $source_path --"
2214  echo "RANLIB=\$(DOCKER_SCRIPT) cc --cc $container_cross_ranlib -i qemu/$container_image -s $source_path --"
2215  echo "STRIP=\$(DOCKER_SCRIPT) cc --cc $container_cross_strip -i qemu/$container_image -s $source_path --"
2216}
2217
2218
2219
2220##########################################
2221# check for vfio_user_server
2222
2223case "$vfio_user_server" in
2224  enabled )
2225    if test "$git_submodules_action" != "ignore"; then
2226      git_submodules="${git_submodules} subprojects/libvfio-user"
2227    fi
2228    ;;
2229esac
2230
2231##########################################
2232# End of CC checks
2233# After here, no more $cc or $ld runs
2234
2235write_c_skeleton
2236
2237if test "$fortify_source" = "yes" ; then
2238  QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
2239fi
2240
2241if test "$have_asan" = "yes"; then
2242  QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
2243  QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
2244  if test "$have_asan_iface_h" = "no" ; then
2245      echo "ASAN build enabled, but ASAN header missing." \
2246           "Without code annotation, the report may be inferior."
2247  elif test "$have_asan_iface_fiber" = "no" ; then
2248      echo "ASAN build enabled, but ASAN header is too old." \
2249           "Without code annotation, the report may be inferior."
2250  fi
2251fi
2252if test "$have_tsan" = "yes" ; then
2253  if test "$have_tsan_iface_fiber" = "yes" ; then
2254    QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
2255    QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
2256  else
2257    error_exit "Cannot enable TSAN due to missing fiber annotation interface."
2258  fi
2259elif test "$tsan" = "yes" ; then
2260  error_exit "Cannot enable TSAN due to missing sanitize thread interface."
2261fi
2262if test "$have_ubsan" = "yes"; then
2263  QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
2264  QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
2265fi
2266
2267##########################################
2268
2269# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
2270if test "$solaris" = "no" && test "$tsan" = "no"; then
2271    if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
2272        QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
2273    fi
2274fi
2275
2276# Guest agent Windows MSI package
2277
2278if test "$QEMU_GA_MANUFACTURER" = ""; then
2279  QEMU_GA_MANUFACTURER=QEMU
2280fi
2281if test "$QEMU_GA_DISTRO" = ""; then
2282  QEMU_GA_DISTRO=Linux
2283fi
2284if test "$QEMU_GA_VERSION" = ""; then
2285    QEMU_GA_VERSION=$(cat "$source_path"/VERSION)
2286fi
2287
2288
2289#######################################
2290# cross-compiled firmware targets
2291
2292# Set up build tree symlinks that point back into the source tree
2293# (these can be both files and directories).
2294# Caution: avoid adding files or directories here using wildcards. This
2295# will result in problems later if a new file matching the wildcard is
2296# added to the source tree -- nothing will cause configure to be rerun
2297# so the build tree will be missing the link back to the new file, and
2298# tests might fail. Prefer to keep the relevant files in their own
2299# directory and symlink the directory instead.
2300LINKS="Makefile"
2301LINKS="$LINKS tests/tcg/Makefile.target"
2302LINKS="$LINKS pc-bios/optionrom/Makefile"
2303LINKS="$LINKS pc-bios/s390-ccw/Makefile"
2304LINKS="$LINKS pc-bios/vof/Makefile"
2305LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
2306LINKS="$LINKS tests/avocado tests/data"
2307LINKS="$LINKS tests/qemu-iotests/check"
2308LINKS="$LINKS python"
2309LINKS="$LINKS contrib/plugins/Makefile "
2310for f in $LINKS ; do
2311    if [ -e "$source_path/$f" ]; then
2312        mkdir -p "$(dirname ./"$f")"
2313        symlink "$source_path/$f" "$f"
2314    fi
2315done
2316
2317# Mac OS X ships with a broken assembler
2318roms=
2319probe_target_compiler i386-softmmu
2320if test -n "$target_cc" &&
2321        test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
2322        test "$targetos" != "haiku" && test "$softmmu" = yes ; then
2323    # Different host OS linkers have different ideas about the name of the ELF
2324    # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
2325    # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
2326    for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
2327        if "$target_ld" -verbose 2>&1 | grep -q "^[[:space:]]*${emu}[[:space:]]*$"; then
2328            ld_i386_emulation="$emu"
2329            break
2330        fi
2331    done
2332    if test -n "$ld_i386_emulation"; then
2333        roms="pc-bios/optionrom"
2334        config_mak=pc-bios/optionrom/config.mak
2335        echo "# Automatically generated by configure - do not modify" > $config_mak
2336        echo "TOPSRC_DIR=$source_path" >> $config_mak
2337        echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_mak
2338        write_target_makefile >> $config_mak
2339    fi
2340fi
2341
2342probe_target_compiler ppc-softmmu
2343if test -n "$target_cc" && test "$softmmu" = yes; then
2344    roms="$roms pc-bios/vof"
2345    config_mak=pc-bios/vof/config.mak
2346    echo "# Automatically generated by configure - do not modify" > $config_mak
2347    echo "SRC_DIR=$source_path/pc-bios/vof" >> $config_mak
2348    write_target_makefile >> $config_mak
2349fi
2350
2351# Only build s390-ccw bios if the compiler has -march=z900 or -march=z10
2352# (which is the lowest architecture level that Clang supports)
2353probe_target_compiler s390x-softmmu
2354if test -n "$target_cc" && test "$softmmu" = yes; then
2355  write_c_skeleton
2356  do_compiler "$target_cc" $target_cc_cflags -march=z900 -o $TMPO -c $TMPC
2357  has_z900=$?
2358  if [ $has_z900 = 0 ] || do_compiler "$target_cc" $target_cc_cflags -march=z10 -msoft-float -Werror -o $TMPO -c $TMPC; then
2359    if [ $has_z900 != 0 ]; then
2360      echo "WARNING: Your compiler does not support the z900!"
2361      echo "         The s390-ccw bios will only work with guest CPUs >= z10."
2362    fi
2363    roms="$roms pc-bios/s390-ccw"
2364    config_mak=pc-bios/s390-ccw/config-host.mak
2365    echo "# Automatically generated by configure - do not modify" > $config_mak
2366    echo "SRC_PATH=$source_path/pc-bios/s390-ccw" >> $config_mak
2367    write_target_makefile >> $config_mak
2368    # SLOF is required for building the s390-ccw firmware on s390x,
2369    # since it is using the libnet code from SLOF for network booting.
2370    git_submodules="${git_submodules} roms/SLOF"
2371  fi
2372fi
2373
2374#######################################
2375# generate config-host.mak
2376
2377# Check that the C++ compiler exists and works with the C compiler.
2378# All the QEMU_CXXFLAGS are based on QEMU_CFLAGS. Keep this at the end to don't miss any other that could be added.
2379if has $cxx; then
2380    cat > $TMPC <<EOF
2381int c_function(void);
2382int main(void) { return c_function(); }
2383EOF
2384
2385    compile_object
2386
2387    cat > $TMPCXX <<EOF
2388extern "C" {
2389   int c_function(void);
2390}
2391int c_function(void) { return 42; }
2392EOF
2393
2394    update_cxxflags
2395
2396    if do_cxx $CXXFLAGS $EXTRA_CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
2397        # C++ compiler $cxx works ok with C compiler $cc
2398        :
2399    else
2400        echo "C++ compiler $cxx does not work with C compiler $cc"
2401        echo "Disabling C++ specific optional code"
2402        cxx=
2403    fi
2404else
2405    echo "No C++ compiler available; disabling C++ specific optional code"
2406    cxx=
2407fi
2408
2409if ! (GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
2410    exit 1
2411fi
2412
2413config_host_mak="config-host.mak"
2414
2415echo "# Automatically generated by configure - do not modify" > $config_host_mak
2416echo >> $config_host_mak
2417
2418echo all: >> $config_host_mak
2419echo "GIT=$git" >> $config_host_mak
2420echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
2421echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
2422
2423if test "$debug_tcg" = "yes" ; then
2424  echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
2425fi
2426if test "$mingw32" = "yes" ; then
2427  echo "CONFIG_WIN32=y" >> $config_host_mak
2428  echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
2429  echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
2430  echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
2431else
2432  echo "CONFIG_POSIX=y" >> $config_host_mak
2433fi
2434
2435if test "$linux" = "yes" ; then
2436  echo "CONFIG_LINUX=y" >> $config_host_mak
2437fi
2438
2439if test "$darwin" = "yes" ; then
2440  echo "CONFIG_DARWIN=y" >> $config_host_mak
2441fi
2442
2443if test "$solaris" = "yes" ; then
2444  echo "CONFIG_SOLARIS=y" >> $config_host_mak
2445fi
2446if test "$static" = "yes" ; then
2447  echo "CONFIG_STATIC=y" >> $config_host_mak
2448fi
2449echo "SRC_PATH=$source_path" >> $config_host_mak
2450echo "TARGET_DIRS=$target_list" >> $config_host_mak
2451if test "$modules" = "yes"; then
2452  echo "CONFIG_MODULES=y" >> $config_host_mak
2453fi
2454
2455# XXX: suppress that
2456if [ "$bsd" = "yes" ] ; then
2457  echo "CONFIG_BSD=y" >> $config_host_mak
2458fi
2459
2460echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
2461
2462if test "$have_asan_iface_fiber" = "yes" ; then
2463    echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
2464fi
2465
2466if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
2467    echo "CONFIG_TSAN=y" >> $config_host_mak
2468fi
2469
2470if test "$plugins" = "yes" ; then
2471    echo "CONFIG_PLUGIN=y" >> $config_host_mak
2472fi
2473
2474if test -n "$gdb_bin"; then
2475    gdb_version=$($gdb_bin --version | head -n 1)
2476    if version_ge ${gdb_version##* } 9.1; then
2477        echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
2478    fi
2479fi
2480
2481echo "ROMS=$roms" >> $config_host_mak
2482echo "MAKE=$make" >> $config_host_mak
2483echo "PYTHON=$python" >> $config_host_mak
2484echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
2485echo "MESON=$meson" >> $config_host_mak
2486echo "NINJA=$ninja" >> $config_host_mak
2487echo "CC=$cc" >> $config_host_mak
2488echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
2489echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
2490echo "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak
2491echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
2492echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
2493echo "GLIB_BINDIR=$glib_bindir" >> $config_host_mak
2494echo "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak
2495echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
2496echo "EXESUF=$EXESUF" >> $config_host_mak
2497
2498# use included Linux headers
2499if test "$linux" = "yes" ; then
2500  mkdir -p linux-headers
2501  case "$cpu" in
2502  i386|x86_64)
2503    linux_arch=x86
2504    ;;
2505  ppc|ppc64)
2506    linux_arch=powerpc
2507    ;;
2508  s390x)
2509    linux_arch=s390
2510    ;;
2511  aarch64)
2512    linux_arch=arm64
2513    ;;
2514  loongarch*)
2515    linux_arch=loongarch
2516    ;;
2517  mips64)
2518    linux_arch=mips
2519    ;;
2520  *)
2521    # For most CPUs the kernel architecture name and QEMU CPU name match.
2522    linux_arch="$cpu"
2523    ;;
2524  esac
2525    # For non-KVM architectures we will not have asm headers
2526    if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
2527      symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
2528    fi
2529fi
2530
2531for target in $target_list; do
2532    target_dir="$target"
2533    target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
2534    mkdir -p "$target_dir"
2535    case $target in
2536        *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
2537        *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
2538    esac
2539done
2540
2541if test "$default_targets" = "yes"; then
2542  echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
2543fi
2544
2545if test "$ccache_cpp2" = "yes"; then
2546  echo "export CCACHE_CPP2=y" >> $config_host_mak
2547fi
2548
2549if test "$safe_stack" = "yes"; then
2550  echo "CONFIG_SAFESTACK=y" >> $config_host_mak
2551fi
2552
2553# tests/tcg configuration
2554(makefile=tests/tcg/Makefile.prereqs
2555echo "# Automatically generated by configure - do not modify" > $makefile
2556
2557config_host_mak=tests/tcg/config-host.mak
2558echo "# Automatically generated by configure - do not modify" > $config_host_mak
2559echo "SRC_PATH=$source_path" >> $config_host_mak
2560echo "HOST_CC=$host_cc" >> $config_host_mak
2561
2562tcg_tests_targets=
2563for target in $target_list; do
2564  arch=${target%%-*}
2565
2566  config_target_mak=tests/tcg/config-$target.mak
2567
2568  echo "# Automatically generated by configure - do not modify" > $config_target_mak
2569  echo "TARGET_NAME=$arch" >> "$config_target_mak"
2570  case $target in
2571    xtensa*-linux-user)
2572      # the toolchain is not complete with headers, only build softmmu tests
2573      continue
2574      ;;
2575    *-softmmu)
2576      test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || continue
2577      qemu="qemu-system-$arch"
2578      ;;
2579    *-linux-user|*-bsd-user)
2580      qemu="qemu-$arch"
2581      ;;
2582  esac
2583
2584  probe_target_compiler $target
2585  if test $got_cross_cc = yes; then
2586      # Test for compiler features for optional tests. We only do this
2587      # for cross compilers because ensuring the docker containers based
2588      # compilers is a requirememt for adding a new test that needs a
2589      # compiler feature.
2590
2591      echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
2592      write_target_makefile >> "$config_target_mak"
2593      case $target in
2594          aarch64-*)
2595              if do_compiler "$target_cc" $target_cflags \
2596                             -march=armv8.1-a+sve -o $TMPE $TMPC; then
2597                  echo "CROSS_CC_HAS_SVE=y" >> "$config_target_mak"
2598              fi
2599              if do_compiler "$target_cc" $target_cflags \
2600                             -march=armv8.1-a+sve2 -o $TMPE $TMPC; then
2601                  echo "CROSS_CC_HAS_SVE2=y" >> "$config_target_mak"
2602              fi
2603              if do_compiler "$target_cc" $target_cflags \
2604                             -march=armv8.3-a -o $TMPE $TMPC; then
2605                  echo "CROSS_CC_HAS_ARMV8_3=y" >> "$config_target_mak"
2606              fi
2607              if do_compiler "$target_cc" $target_cflags \
2608                             -mbranch-protection=standard -o $TMPE $TMPC; then
2609                  echo "CROSS_CC_HAS_ARMV8_BTI=y" >> "$config_target_mak"
2610              fi
2611              if do_compiler "$target_cc" $target_cflags \
2612                             -march=armv8.5-a+memtag -o $TMPE $TMPC; then
2613                  echo "CROSS_CC_HAS_ARMV8_MTE=y" >> "$config_target_mak"
2614              fi
2615              ;;
2616          ppc*)
2617              if do_compiler "$target_cc" $target_cflags \
2618                             -mpower8-vector -o $TMPE $TMPC; then
2619                  echo "CROSS_CC_HAS_POWER8_VECTOR=y" >> "$config_target_mak"
2620              fi
2621              if do_compiler "$target_cc" $target_cflags \
2622                             -mpower10 -o $TMPE $TMPC; then
2623                  echo "CROSS_CC_HAS_POWER10=y" >> "$config_target_mak"
2624              fi
2625              ;;
2626          i386-linux-user)
2627              if do_compiler "$target_cc" $target_cflags \
2628                             -Werror -fno-pie -o $TMPE $TMPC; then
2629                  echo "CROSS_CC_HAS_I386_NOPIE=y" >> "$config_target_mak"
2630              fi
2631              ;;
2632      esac
2633  elif test -n "$container_image"; then
2634      echo "build-tcg-tests-$target: docker-image-$container_image" >> $makefile
2635      echo "BUILD_STATIC=y" >> "$config_target_mak"
2636      write_container_target_makefile >> "$config_target_mak"
2637      case $target in
2638          aarch64-*)
2639              echo "CROSS_CC_HAS_SVE=y" >> "$config_target_mak"
2640              echo "CROSS_CC_HAS_SVE2=y" >> "$config_target_mak"
2641              echo "CROSS_CC_HAS_ARMV8_3=y" >> "$config_target_mak"
2642              echo "CROSS_CC_HAS_ARMV8_BTI=y" >> "$config_target_mak"
2643              echo "CROSS_CC_HAS_ARMV8_MTE=y" >> "$config_target_mak"
2644              ;;
2645          ppc*)
2646              echo "CROSS_CC_HAS_POWER8_VECTOR=y" >> "$config_target_mak"
2647              echo "CROSS_CC_HAS_POWER10=y" >> "$config_target_mak"
2648              ;;
2649          i386-linux-user)
2650              echo "CROSS_CC_HAS_I386_NOPIE=y" >> "$config_target_mak"
2651              ;;
2652      esac
2653      got_cross_cc=yes
2654  fi
2655  if test $got_cross_cc = yes; then
2656      mkdir -p tests/tcg/$target
2657      echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
2658      echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> $makefile
2659      tcg_tests_targets="$tcg_tests_targets $target"
2660  fi
2661done
2662echo "TCG_TESTS_TARGETS=$tcg_tests_targets" >> $makefile)
2663
2664if test "$skip_meson" = no; then
2665  cross="config-meson.cross.new"
2666  meson_quote() {
2667    test $# = 0 && return
2668    echo "'$(echo $* | sed "s/ /','/g")'"
2669  }
2670
2671  echo "# Automatically generated by configure - do not modify" > $cross
2672  echo "[properties]" >> $cross
2673
2674  # unroll any custom device configs
2675  for a in $device_archs; do
2676      eval "c=\$devices_${a}"
2677      echo "${a}-softmmu = '$c'" >> $cross
2678  done
2679
2680  test -z "$cxx" && echo "link_language = 'c'" >> $cross
2681  echo "[built-in options]" >> $cross
2682  echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
2683  echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
2684  test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
2685  echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
2686  echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
2687  echo "[binaries]" >> $cross
2688  echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
2689  test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
2690  test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
2691  echo "ar = [$(meson_quote $ar)]" >> $cross
2692  echo "nm = [$(meson_quote $nm)]" >> $cross
2693  echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
2694  echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
2695  if has $sdl2_config; then
2696    echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
2697  fi
2698  echo "strip = [$(meson_quote $strip)]" >> $cross
2699  echo "widl = [$(meson_quote $widl)]" >> $cross
2700  echo "windres = [$(meson_quote $windres)]" >> $cross
2701  if test "$cross_compile" = "yes"; then
2702    cross_arg="--cross-file config-meson.cross"
2703    echo "[host_machine]" >> $cross
2704    echo "system = '$targetos'" >> $cross
2705    case "$cpu" in
2706        i386)
2707            echo "cpu_family = 'x86'" >> $cross
2708            ;;
2709        *)
2710            echo "cpu_family = '$cpu'" >> $cross
2711            ;;
2712    esac
2713    echo "cpu = '$cpu'" >> $cross
2714    if test "$bigendian" = "yes" ; then
2715        echo "endian = 'big'" >> $cross
2716    else
2717        echo "endian = 'little'" >> $cross
2718    fi
2719  else
2720    cross_arg="--native-file config-meson.cross"
2721  fi
2722  mv $cross config-meson.cross
2723
2724  rm -rf meson-private meson-info meson-logs
2725
2726  # Built-in options
2727  test "$bindir" != "bin" && meson_option_add "-Dbindir=$bindir"
2728  test "$default_feature" = no && meson_option_add -Dauto_features=disabled
2729  test "$pie" = no && meson_option_add -Db_pie=false
2730  test "$werror" = yes && meson_option_add -Dwerror=true
2731
2732  # QEMU options
2733  test "$cfi" != false && meson_option_add "-Dcfi=$cfi"
2734  test "$fdt" != auto && meson_option_add "-Dfdt=$fdt"
2735  test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
2736  test "$qemu_suffix" != qemu && meson_option_add "-Dqemu_suffix=$qemu_suffix"
2737  test "$slirp" != auto && meson_option_add "-Dslirp=$slirp"
2738  test "$smbd" != '' && meson_option_add "-Dsmbd=$smbd"
2739  test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
2740  test "$vfio_user_server" != auto && meson_option_add "-Dvfio_user_server=$vfio_user_server"
2741  run_meson() {
2742    NINJA=$ninja $meson setup --prefix "$prefix" "$@" $cross_arg "$PWD" "$source_path"
2743  }
2744  eval run_meson $meson_options
2745  if test "$?" -ne 0 ; then
2746      error_exit "meson setup failed"
2747  fi
2748else
2749  if test -f meson-private/cmd_line.txt; then
2750    # Adjust old command line options whose type was changed
2751    # Avoids having to use "setup --wipe" when Meson is upgraded
2752    perl -i -ne '
2753      s/^gettext = true$/gettext = auto/;
2754      s/^gettext = false$/gettext = disabled/;
2755      /^b_staticpic/ && next;
2756      print;' meson-private/cmd_line.txt
2757  fi
2758fi
2759
2760# Save the configure command line for later reuse.
2761cat <<EOD >config.status
2762#!/bin/sh
2763# Generated by configure.
2764# Run this file to recreate the current configuration.
2765# Compiler output produced by configure, useful for debugging
2766# configure, is in config.log if it exists.
2767EOD
2768
2769preserve_env() {
2770    envname=$1
2771
2772    eval envval=\$$envname
2773
2774    if test -n "$envval"
2775    then
2776	echo "$envname='$envval'" >> config.status
2777	echo "export $envname" >> config.status
2778    else
2779	echo "unset $envname" >> config.status
2780    fi
2781}
2782
2783# Preserve various env variables that influence what
2784# features/build target configure will detect
2785preserve_env AR
2786preserve_env AS
2787preserve_env CC
2788preserve_env CFLAGS
2789preserve_env CXX
2790preserve_env CXXFLAGS
2791preserve_env LD
2792preserve_env LDFLAGS
2793preserve_env LD_LIBRARY_PATH
2794preserve_env MAKE
2795preserve_env NM
2796preserve_env OBJCFLAGS
2797preserve_env OBJCOPY
2798preserve_env PATH
2799preserve_env PKG_CONFIG
2800preserve_env PKG_CONFIG_LIBDIR
2801preserve_env PKG_CONFIG_PATH
2802preserve_env PYTHON
2803preserve_env SDL2_CONFIG
2804preserve_env SMBD
2805preserve_env STRIP
2806preserve_env WIDL
2807preserve_env WINDRES
2808
2809printf "exec" >>config.status
2810for i in "$0" "$@"; do
2811  test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
2812done
2813echo ' "$@"' >>config.status
2814chmod +x config.status
2815
2816rm -r "$TMPDIR1"
2817