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