x86: use typedef for SetupData struct
[qemu.git] / configure
blobcc4ecd6008b364951e6c81611d5b0d69b56ad4e7
1 #!/bin/sh
3 # qemu configure script (c) 2003 Fabrice Bellard
6 # Unset some variables known to interfere with behavior of common tools,
7 # just as autoconf does.
8 CLICOLOR_FORCE= GREP_OPTIONS=
9 unset CLICOLOR_FORCE GREP_OPTIONS
11 # Don't allow CCACHE, if present, to use cached results of compile tests!
12 export CCACHE_RECACHE=yes
14 # make source path absolute
15 source_path=$(cd "$(dirname -- "$0")"; pwd)
17 if test "$PWD" = "$source_path"
18 then
19 echo "Using './build' as the directory for build output"
21 MARKER=build/auto-created-by-configure
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
34 mkdir build
35 touch $MARKER
37 cat > GNUmakefile <<'EOF'
38 # This file is auto-generated by configure to support in-source tree
39 # 'make' command invocation
41 ifeq ($(MAKECMDGOALS),)
42 recurse: all
43 endif
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 ; \
54 force: ;
55 .PHONY: force
56 GNUmakefile: ;
58 EOF
59 cd build
60 exec "$source_path/configure" "$@"
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.)
68 TMPDIR1="config-temp"
69 rm -rf "${TMPDIR1}"
70 if ! mkdir -p "${TMPDIR1}"; then
71 echo "ERROR: failed to create temporary directory"
72 exit 1
75 TMPB="qemu-conf"
76 TMPC="${TMPDIR1}/${TMPB}.c"
77 TMPO="${TMPDIR1}/${TMPB}.o"
78 TMPCXX="${TMPDIR1}/${TMPB}.cxx"
79 TMPM="${TMPDIR1}/${TMPB}.m"
80 TMPE="${TMPDIR1}/${TMPB}.exe"
82 rm -f config.log
84 # Print a helpful header at the top of config.log
85 echo "# QEMU configure log $(date)" >> config.log
86 printf "# Configured with:" >> config.log
87 printf " '%s'" "$0" "$@" >> config.log
88 echo >> config.log
89 echo "#" >> config.log
91 quote_sh() {
92 printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
95 print_error() {
96 (echo
97 echo "ERROR: $1"
98 while test -n "$2"; do
99 echo " $2"
100 shift
101 done
102 echo) >&2
105 error_exit() {
106 print_error "$@"
107 exit 1
110 do_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 "
117 funcs: ${FUNCNAME[*]}
118 lines: ${BASH_LINENO[*]}"
119 '; fi
120 echo $compiler "$@" >> config.log
121 $compiler "$@" >> config.log 2>&1 || return $?
124 do_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 "
131 funcs: ${FUNCNAME[*]}
132 lines: ${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
143 # Don't bother rerunning the compile if we were already using -Werror
144 case "$*" in
145 *-Werror*)
146 return 0
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."
157 do_cc() {
158 do_compiler_werror "$cc" $CPU_CFLAGS "$@"
161 do_cxx() {
162 do_compiler_werror "$cxx" $CPU_CFLAGS "$@"
165 do_objc() {
166 do_compiler_werror "$objcc" $CPU_CFLAGS "$@"
169 # Append $2 to the variable named $1, with space separation
170 add_to() {
171 eval $1=\${$1:+\"\$$1 \"}\$2
174 update_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)
186 QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
188 esac
189 done
192 compile_object() {
193 local_cflags="$1"
194 do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
197 compile_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
204 # symbolically link $1 to $2. Portable version of "ln -sf".
205 symlink() {
206 rm -rf "$2"
207 mkdir -p "$(dirname "$2")"
208 ln -s "$1" "$2"
211 # check whether a command is available to this shell (may be either an
212 # executable or a builtin)
213 has() {
214 type "$1" >/dev/null 2>&1
217 version_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
236 glob() {
237 eval test -z '"${1#'"$2"'}"'
240 if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
241 then
242 error_exit "main directory cannot contain spaces nor colons"
245 # default parameters
246 cpu=""
247 static="no"
248 cross_compile="no"
249 cross_prefix=""
250 host_cc="cc"
251 stack_protector=""
252 safe_stack=""
253 use_containers="yes"
254 gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
256 if test -e "$source_path/.git"
257 then
258 git_submodules_action="update"
259 else
260 git_submodules_action="ignore"
263 git_submodules="ui/keycodemapdb"
264 git="git"
266 # Don't accept a target_list environment variable.
267 unset target_list
268 unset target_list_exclude
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
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.
282 default_feature=""
283 # parse CC options second
284 for opt do
285 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
286 case "$opt" in
287 --without-default-features)
288 default_feature="no"
290 esac
291 done
293 EXTRA_CFLAGS=""
294 EXTRA_CXXFLAGS=""
295 EXTRA_OBJCFLAGS=""
296 EXTRA_LDFLAGS=""
298 debug_tcg="no"
299 sanitizers="no"
300 tsan="no"
301 fortify_source="yes"
302 EXESUF=""
303 modules="no"
304 prefix="/usr/local"
305 qemu_suffix="qemu"
306 softmmu="yes"
307 linux_user=""
308 bsd_user=""
309 pie=""
310 coroutine=""
311 plugins="$default_feature"
312 meson=""
313 ninja=""
314 bindir="bin"
315 skip_meson=no
316 vfio_user_server="disabled"
318 # The following Meson options are handled manually (still they
319 # are included in the automatically generated help message)
321 # 1. Track which submodules are needed
322 if test "$default_feature" = no ; then
323 slirp="disabled"
324 else
325 slirp="auto"
327 fdt="auto"
329 # 2. Automatically enable/disable other options
330 tcg="auto"
331 cfi="false"
333 # parse CC options second
334 for opt do
335 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
336 case "$opt" in
337 --cross-prefix=*) cross_prefix="$optarg"
338 cross_compile="yes"
340 --cc=*) CC="$optarg"
342 --cxx=*) CXX="$optarg"
344 --cpu=*) cpu="$optarg"
346 --extra-cflags=*)
347 EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
348 EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
349 EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
351 --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
353 --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
355 --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
357 --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
359 --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
360 eval "cross_cc_cflags_${cc_arch}=\$optarg"
362 --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
363 eval "cross_cc_${cc_arch}=\$optarg"
365 --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-prefix-FOO option"
367 --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
368 eval "cross_prefix_${cc_arch}=\$optarg"
370 esac
371 done
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.
376 # Preferred compiler:
377 # ${CC} (if set)
378 # ${cross_prefix}gcc (if cross-prefix specified)
379 # system compiler
380 if test -z "${CC}${cross_prefix}"; then
381 cc="$host_cc"
382 else
383 cc="${CC-${cross_prefix}gcc}"
386 if test -z "${CXX}${cross_prefix}"; then
387 cxx="c++"
388 else
389 cxx="${CXX-${cross_prefix}g++}"
392 ar="${AR-${cross_prefix}ar}"
393 as="${AS-${cross_prefix}as}"
394 ccas="${CCAS-$cc}"
395 objcopy="${OBJCOPY-${cross_prefix}objcopy}"
396 ld="${LD-${cross_prefix}ld}"
397 ranlib="${RANLIB-${cross_prefix}ranlib}"
398 nm="${NM-${cross_prefix}nm}"
399 smbd="$SMBD"
400 strip="${STRIP-${cross_prefix}strip}"
401 widl="${WIDL-${cross_prefix}widl}"
402 windres="${WINDRES-${cross_prefix}windres}"
403 pkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
404 query_pkg_config() {
405 "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
407 pkg_config=query_pkg_config
408 sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
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.)
415 QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
416 QEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
417 QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
418 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
420 QEMU_LDFLAGS=
422 # Flags that are needed during configure but later taken care of by Meson
423 CONFIGURE_CFLAGS="-std=gnu11 -Wall"
424 CONFIGURE_LDFLAGS=
427 check_define() {
428 cat > $TMPC <<EOF
429 #if !defined($1)
430 #error $1 not defined
431 #endif
432 int main(void) { return 0; }
434 compile_object
437 check_include() {
438 cat > $TMPC <<EOF
439 #include <$1>
440 int main(void) { return 0; }
442 compile_object
445 write_c_skeleton() {
446 cat > $TMPC <<EOF
447 int main(void) { return 0; }
451 if check_define __linux__ ; then
452 targetos=linux
453 elif check_define _WIN32 ; then
454 targetos=windows
455 elif check_define __OpenBSD__ ; then
456 targetos=openbsd
457 elif check_define __sun__ ; then
458 targetos=sunos
459 elif check_define __HAIKU__ ; then
460 targetos=haiku
461 elif check_define __FreeBSD__ ; then
462 targetos=freebsd
463 elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
464 targetos=gnu/kfreebsd
465 elif check_define __DragonFly__ ; then
466 targetos=dragonfly
467 elif check_define __NetBSD__; then
468 targetos=netbsd
469 elif check_define __APPLE__; then
470 targetos=darwin
471 else
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
478 # OS specific
480 mingw32="no"
481 bsd="no"
482 linux="no"
483 solaris="no"
484 case $targetos in
485 windows)
486 mingw32="yes"
487 plugins="no"
488 pie="no"
490 gnu/kfreebsd)
491 bsd="yes"
493 freebsd)
494 bsd="yes"
495 make="${MAKE-gmake}"
496 # needed for kinfo_getvmmap(3) in libutil.h
498 dragonfly)
499 bsd="yes"
500 make="${MAKE-gmake}"
502 netbsd)
503 bsd="yes"
504 make="${MAKE-gmake}"
506 openbsd)
507 bsd="yes"
508 make="${MAKE-gmake}"
510 darwin)
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"
517 sunos)
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"
532 haiku)
533 pie="no"
534 QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
536 linux)
537 linux="yes"
539 esac
541 if test ! -z "$cpu" ; then
542 # command line argument
544 elif check_define __i386__ ; then
545 cpu="i386"
546 elif check_define __x86_64__ ; then
547 if check_define __ILP32__ ; then
548 cpu="x32"
549 else
550 cpu="x86_64"
552 elif check_define __sparc__ ; then
553 if check_define __arch64__ ; then
554 cpu="sparc64"
555 else
556 cpu="sparc"
558 elif 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"
565 else
566 cpu="ppc"
568 elif check_define __mips__ ; then
569 cpu="mips"
570 elif check_define __s390__ ; then
571 if check_define __s390x__ ; then
572 cpu="s390x"
573 else
574 cpu="s390"
576 elif check_define __riscv ; then
577 cpu="riscv"
578 elif check_define __arm__ ; then
579 cpu="arm"
580 elif check_define __aarch64__ ; then
581 cpu="aarch64"
582 elif check_define __loongarch64 ; then
583 cpu="loongarch64"
584 else
585 cpu=$(uname -m)
588 # Normalise host CPU name, set multilib cflags
589 # Note that this case should only have supported host CPUs, not guests.
590 case "$cpu" in
591 armv*b|armv*l|arm)
592 cpu="arm" ;;
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" ;;
607 mips*)
608 cpu="mips" ;;
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" ;;
618 s390)
619 CPU_CFLAGS="-m31" ;;
620 s390x)
621 CPU_CFLAGS="-m64" ;;
623 sparc|sun4[cdmuv])
624 cpu="sparc"
625 CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
626 sparc64)
627 CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
628 esac
630 : ${make=${MAKE-make}}
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
635 python=
636 explicit_python=no
637 for binary in "${PYTHON-python3}" python
639 if has "$binary"
640 then
641 python=$(command -v "$binary")
642 break
644 done
647 # Check for ancillary tools used in testing
648 genisoimage=
649 for binary in genisoimage mkisofs
651 if has $binary
652 then
653 genisoimage=$(command -v "$binary")
654 break
656 done
658 # Default objcc to clang if available, otherwise use CC
659 if has clang; then
660 objcc=clang
661 else
662 objcc="$cc"
665 if 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=""
675 werror=""
677 meson_option_build_array() {
678 printf '['
679 (if test "$targetos" = windows; then
680 IFS=\;
681 else
682 IFS=:
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'
693 . "$source_path/scripts/meson-buildoptions.sh"
695 meson_options=
696 meson_option_add() {
697 meson_options="$meson_options $(quote_sh "$1")"
699 meson_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
708 for opt do
709 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
710 case "$opt" in
711 --help|-h) show_help=yes
713 --version|-V) exec cat "$source_path/VERSION"
715 --prefix=*) prefix="$optarg"
717 --cross-prefix=*)
719 --cc=*)
721 --host-cc=*) host_cc="$optarg"
723 --cxx=*)
725 --objcc=*) objcc="$optarg"
727 --make=*) make="$optarg"
729 --install=*)
731 --python=*) python="$optarg" ; explicit_python=yes
733 --skip-meson) skip_meson=yes
735 --meson=*) meson="$optarg"
737 --ninja=*) ninja="$optarg"
739 --smbd=*) smbd="$optarg"
741 --extra-cflags=*)
743 --extra-cxxflags=*)
745 --extra-objcflags=*)
747 --extra-ldflags=*)
749 --cross-cc-*)
751 --cross-prefix-*)
753 --enable-debug-info) meson_option_add -Ddebug=true
755 --disable-debug-info) meson_option_add -Ddebug=false
757 --enable-modules)
758 modules="yes"
760 --disable-modules)
761 modules="no"
763 --cpu=*)
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"
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"
775 --with-default-devices) meson_option_add -Ddefault_devices=true
777 --without-default-devices) meson_option_add -Ddefault_devices=false
779 --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
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"
791 --without-default-features) # processed above
793 --static)
794 static="yes"
795 QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
797 --bindir=*) bindir="$optarg"
799 --with-suffix=*) qemu_suffix="$optarg"
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.
811 --enable-debug-tcg) debug_tcg="yes"
813 --disable-debug-tcg) debug_tcg="no"
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"
822 --enable-sanitizers) sanitizers="yes"
824 --disable-sanitizers) sanitizers="no"
826 --enable-tsan) tsan="yes"
828 --disable-tsan) tsan="no"
830 --disable-slirp) slirp="disabled"
832 --enable-slirp) slirp="enabled"
834 --enable-slirp=git) slirp="internal"
836 --enable-slirp=*) slirp="$optarg"
838 --disable-tcg) tcg="disabled"
839 plugins="no"
841 --enable-tcg) tcg="enabled"
843 --disable-system) softmmu="no"
845 --enable-system) softmmu="yes"
847 --disable-user)
848 linux_user="no" ;
849 bsd_user="no" ;
851 --enable-user) ;;
852 --disable-linux-user) linux_user="no"
854 --enable-linux-user) linux_user="yes"
856 --disable-bsd-user) bsd_user="no"
858 --enable-bsd-user) bsd_user="yes"
860 --enable-pie) pie="yes"
862 --disable-pie) pie="no"
864 --enable-werror) werror="yes"
866 --disable-werror) werror="no"
868 --enable-stack-protector) stack_protector="yes"
870 --disable-stack-protector) stack_protector="no"
872 --enable-safe-stack) safe_stack="yes"
874 --disable-safe-stack) safe_stack="no"
876 --enable-cfi)
877 cfi="true";
878 meson_option_add -Db_lto=true
880 --disable-cfi) cfi="false"
882 --disable-fdt) fdt="disabled"
884 --enable-fdt) fdt="enabled"
886 --enable-fdt=git) fdt="internal"
888 --enable-fdt=*) fdt="$optarg"
890 --with-coroutine=*) coroutine="$optarg"
892 --disable-zlib-test)
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
897 --enable-vhdx|--disable-vhdx)
898 echo "$0: $opt is obsolete, VHDX driver is always built" >&2
900 --enable-uuid|--disable-uuid)
901 echo "$0: $opt is obsolete, UUID support is always built" >&2
903 --with-git=*) git="$optarg"
905 --with-git-submodules=*)
906 git_submodules_action="$optarg"
908 --enable-plugins) if test "$mingw32" = "yes"; then
909 error_exit "TCG plugins not currently supported on Windows platforms"
910 else
911 plugins="yes"
914 --disable-plugins) plugins="no"
916 --enable-containers) use_containers="yes"
918 --disable-containers) use_containers="no"
920 --gdb=*) gdb_bin="$optarg"
922 # backwards compatibility options
923 --enable-trace-backend=*) meson_option_parse "--enable-trace-backends=$optarg" "$optarg"
925 --disable-blobs) meson_option_parse --disable-install-blobs ""
927 --enable-vfio-user-server) vfio_user_server="enabled"
929 --disable-vfio-user-server) vfio_user_server="disabled"
931 --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
933 --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
935 # everything else has the same name in configure and meson
936 --*) meson_option_parse "$opt" "$optarg"
938 esac
939 done
941 # test for any invalid configuration combinations
942 if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
943 error_exit "Can't enable plugins on non-TCG builds"
946 case $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
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."
973 echo
974 exit 1
978 echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
979 exit 1
981 esac
983 default_target_list=""
984 mak_wilds=""
986 if [ "$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"
993 if [ "$bsd_user" != no ]; then
994 if [ "$bsd_user" = "" ]; then
995 test $targetos = freebsd && bsd_user=yes
997 if [ "$bsd_user" = yes ] && ! [ -d "$source_path/bsd-user/$targetos" ]; then
998 error_exit "bsd-user not supported on this host OS"
1001 if [ "$softmmu" = "yes" ]; then
1002 mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
1004 if [ "$linux_user" = "yes" ]; then
1005 mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
1007 if [ "$bsd_user" = "yes" ]; then
1008 mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
1011 for 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"
1016 done
1018 if test x"$show_help" = x"yes" ; then
1019 cat << EOF
1021 Usage: configure [options]
1022 Options: [defaults in brackets after descriptions]
1024 Standard 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
1032 Advanced 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]
1076 meson_options_help
1077 cat << 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.
1089 NOTE: The object files are built at the place where configure is launched
1091 exit 0
1094 # Remove old dependency files to make sure that they get properly regenerated
1095 rm -f ./*/config-devices.mak.d
1097 if test -z "$python"
1098 then
1099 error_exit "Python not found. Use --python=/path/to/python"
1101 if ! has "$make"
1102 then
1103 error_exit "GNU make ($make) not found"
1106 # Note that if the Python conditional here evaluates True we will exit
1107 # with status 1 which is a shell 'false' value.
1108 if ! $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."
1113 # Suppress writing compiled files
1114 python="$python -B"
1116 if 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"
1130 else
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.
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
1145 if test "$meson" = git; then
1146 git_submodules="${git_submodules} meson"
1149 case "$meson" in
1150 git | internal)
1151 meson="$python ${source_path}/meson/meson.py"
1153 *) meson=$(command -v "$meson") ;;
1154 esac
1156 # Probe for ninja
1158 if 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
1164 done
1165 if test -z "$ninja"; then
1166 error_exit "Cannot find Ninja"
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.
1174 write_c_skeleton;
1175 if compile_object ; then
1176 : C compiler works ok
1177 else
1178 error_exit "\"$cc\" either does not exist or does not work"
1180 if ! compile_prog ; then
1181 error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
1184 # Consult white-list to determine whether to enable werror
1185 # by default. Only enable by default for git builds
1186 if 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"
1195 if 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)')"
1203 # Check whether the compiler matches our minimum requirements:
1204 cat > $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
1222 int main (void) { return 0; }
1224 if ! compile_prog "" "" ; then
1225 error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
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.
1234 warn_flags=
1235 add_to warn_flags -Wold-style-declaration
1236 add_to warn_flags -Wold-style-definition
1237 add_to warn_flags -Wtype-limits
1238 add_to warn_flags -Wformat-security
1239 add_to warn_flags -Wformat-y2k
1240 add_to warn_flags -Winit-self
1241 add_to warn_flags -Wignored-qualifiers
1242 add_to warn_flags -Wempty-body
1243 add_to warn_flags -Wnested-externs
1244 add_to warn_flags -Wendif-labels
1245 add_to warn_flags -Wexpansion-to-defined
1246 add_to warn_flags -Wimplicit-fallthrough=2
1248 nowarn_flags=
1249 add_to nowarn_flags -Wno-initializer-overrides
1250 add_to nowarn_flags -Wno-missing-include-dirs
1251 add_to nowarn_flags -Wno-shift-negative-value
1252 add_to nowarn_flags -Wno-string-plus-int
1253 add_to nowarn_flags -Wno-typedef-redefinition
1254 add_to nowarn_flags -Wno-tautological-type-limit-compare
1255 add_to nowarn_flags -Wno-psabi
1257 gcc_flags="$warn_flags $nowarn_flags"
1259 cc_has_warning_flag() {
1260 write_c_skeleton;
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" ""
1269 objcc_has_warning_flag() {
1270 cat > $TMPM <<EOF
1271 int main(void) { return 0; }
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
1283 for flag in $gcc_flags; do
1284 if cc_has_warning_flag $flag ; then
1285 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1287 if objcc_has_warning_flag $flag ; then
1288 QEMU_OBJCFLAGS="$QEMU_OBJCFLAGS $flag"
1290 done
1292 if test "$stack_protector" != "no"; then
1293 cat > $TMPC << EOF
1294 int main(int argc, char *argv[])
1296 char arr[64], *p = arr, *c = argv[0];
1297 while (*c) {
1298 *p++ = *c++;
1300 return 0;
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
1315 done
1316 if test "$stack_protector" = yes; then
1317 if test $sp_on = 0; then
1318 error_exit "Stack protector not supported"
1323 # Disable -Wmissing-braces on older compilers that warn even for
1324 # the "universal" C zero initializer {0}.
1325 cat > $TMPC << EOF
1326 struct {
1327 int a[2];
1328 } x = {0};
1330 if compile_object "-Werror" "" ; then
1332 else
1333 QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
1336 # Our module code doesn't support Windows
1337 if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
1338 error_exit "Modules are not available for Windows"
1341 # Static linking is not possible with plugins, modules or PIE
1342 if test "$static" = "yes" ; then
1343 if test "$modules" = "yes" ; then
1344 error_exit "static and modules are mutually incompatible"
1346 if test "$plugins" = "yes"; then
1347 error_exit "static and plugins are mutually incompatible"
1348 else
1349 plugins="no"
1352 test "$plugins" = "" && plugins=yes
1354 cat > $TMPC << EOF
1356 #ifdef __linux__
1357 # define THREAD __thread
1358 #else
1359 # define THREAD
1360 #endif
1361 static THREAD int tls_var;
1362 int main(void) { return tls_var; }
1365 if 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"
1376 elif 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"
1384 elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
1385 CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
1386 CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
1387 pie="yes"
1388 elif test "$pie" = "yes"; then
1389 error_exit "PIE not available due to missing toolchain support"
1390 else
1391 echo "Disabling PIE due to missing toolchain support"
1392 pie="no"
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.
1397 if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1398 QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
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
1406 if test "$cpu" = "i386"; then
1407 cat > $TMPC << EOF
1408 static int sfaa(int *ptr)
1410 return __sync_fetch_and_and(ptr, 0);
1413 int main(void)
1415 int val = 42;
1416 val = __sync_val_compare_and_swap(&val, 0, 1);
1417 sfaa(&val);
1418 return val;
1421 if ! compile_prog "" "" ; then
1422 QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
1426 if 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# }"
1432 else
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 "*)
1442 error_exit "Unknown target name '$target'"
1444 esac
1445 done
1448 # see if system emulation was really requested
1449 case " $target_list " in
1450 *"-softmmu "*) softmmu=yes
1452 *) softmmu=no
1454 esac
1456 if test "$tcg" = "auto"; then
1457 if test -z "$target_list"; then
1458 tcg="disabled"
1459 else
1460 tcg="enabled"
1464 if test "$tcg" = "enabled"; then
1465 git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
1466 git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
1469 # ---
1470 # big/little endian test
1471 cat > $TMPC << EOF
1472 #include <stdio.h>
1473 short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
1474 short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
1475 int main(int argc, char *argv[])
1477 return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
1481 if 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
1490 else
1491 echo big/little test failed
1492 exit 1
1495 ##########################################
1496 # pkg-config probe
1498 if ! has "$pkg_config_exe"; then
1499 error_exit "pkg-config binary '$pkg_config_exe' not found"
1502 ##########################################
1503 # glib support probe
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
1507 glib_req_ver=2.56
1508 glib_modules=gthread-2.0
1509 if test "$modules" = yes; then
1510 glib_modules="$glib_modules gmodule-export-2.0"
1511 elif test "$plugins" = "yes"; then
1512 glib_modules="$glib_modules gmodule-no-export-2.0"
1515 for 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"
1522 done
1524 glib_bindir="$($pkg_config --variable=bindir glib-2.0)"
1525 if test -z "$glib_bindir" ; then
1526 glib_bindir="$($pkg_config --variable=prefix glib-2.0)"/bin
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
1532 if test "$static" = yes && test "$mingw32" = yes; then
1533 glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
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
1540 cat > $TMPC <<EOF
1541 #include <glib.h>
1542 #include <unistd.h>
1544 #define QEMU_BUILD_BUG_ON(x) \
1545 typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
1547 int main(void) {
1548 QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
1549 return 0;
1553 if ! 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"
1560 # Silence clang warnings triggered by glib < 2.57.2
1561 cat > $TMPC << EOF
1562 #include <glib.h>
1563 typedef struct Foo {
1564 int i;
1565 } Foo;
1566 static void foo_free(Foo *f)
1568 g_free(f);
1570 G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
1571 int main(void) { return 0; }
1573 if ! 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"
1580 ##########################################
1581 # fdt probe
1583 case "$fdt" in
1584 auto | enabled | internal)
1585 # Simpler to always update submodule, even if not needed.
1586 git_submodules="${git_submodules} dtc"
1588 esac
1590 ##########################################
1591 # check and set a backend for coroutine
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.
1597 ucontext_works=no
1598 if 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
1604 int main(void) { makecontext(0, 0, 0); return 0; }
1606 if compile_prog "" "" ; then
1607 ucontext_works=yes
1611 if 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
1619 else
1620 case $coroutine in
1621 windows)
1622 if test "$mingw32" != "yes"; then
1623 error_exit "'windows' coroutine backend only valid for Windows"
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
1629 ucontext)
1630 if test "$ucontext_works" != "yes"; then
1631 error_exit "'ucontext' backend requested but makecontext not available"
1634 sigaltstack)
1635 if test "$mingw32" = "yes"; then
1636 error_exit "only the 'windows' coroutine backend is valid for Windows"
1640 error_exit "unknown coroutine backend $coroutine"
1642 esac
1645 ##################################################
1646 # SafeStack
1649 if test "$safe_stack" = "yes"; then
1650 cat > $TMPC << EOF
1651 int main(int argc, char *argv[])
1653 #if ! __has_feature(safe_stack)
1654 #error SafeStack Disabled
1655 #endif
1656 return 0;
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"
1668 if test "$coroutine" != "ucontext"; then
1669 error_exit "SafeStack is only supported by the coroutine backend ucontext"
1671 else
1672 cat > $TMPC << EOF
1673 int main(int argc, char *argv[])
1675 #if defined(__has_feature)
1676 #if __has_feature(safe_stack)
1677 #error SafeStack Enabled
1678 #endif
1679 #endif
1680 return 0;
1683 if 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"
1691 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1692 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
1694 else # "$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"
1707 ########################################
1708 # check if ccache is interfering with
1709 # semantic analysis of macros
1711 unset CCACHE_CPP2
1712 ccache_cpp2=no
1713 cat > $TMPC << EOF
1714 static 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)
1719 int main(int argc, char *argv[])
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;
1731 if ! compile_object "-Werror"; then
1732 ccache_cpp2=yes
1735 #################################################
1736 # clang does not support glibc + FORTIFY_SOURCE.
1738 if 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"
1749 ##########################################
1750 # checks for sanitizers
1752 have_asan=no
1753 have_ubsan=no
1754 have_asan_iface_h=no
1755 have_asan_iface_fiber=no
1757 if test "$sanitizers" = "yes" ; then
1758 write_c_skeleton
1759 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
1760 have_asan=yes
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>
1768 int main(void) {
1769 void *tmp = malloc(10);
1770 if (tmp != NULL) {
1771 return *(int *)(tmp + 2);
1773 return 1;
1776 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
1777 have_ubsan=yes
1780 if check_include "sanitizer/asan_interface.h" ; then
1781 have_asan_iface_h=yes
1784 cat > $TMPC << EOF
1785 #include <sanitizer/asan_interface.h>
1786 int main(void) {
1787 __sanitizer_start_switch_fiber(0, 0, 0);
1788 return 0;
1791 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
1792 have_asan_iface_fiber=yes
1796 # Thread sanitizer is, for now, much noisier than the other sanitizers;
1797 # keep it separate until that is not the case.
1798 if test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
1799 error_exit "TSAN is not supported with other sanitiziers."
1801 have_tsan=no
1802 have_tsan_iface_fiber=no
1803 if test "$tsan" = "yes" ; then
1804 write_c_skeleton
1805 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
1806 have_tsan=yes
1808 cat > $TMPC << EOF
1809 #include <sanitizer/tsan_interface.h>
1810 int main(void) {
1811 __tsan_create_fiber(0);
1812 return 0;
1815 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
1816 have_tsan_iface_fiber=yes
1820 ##########################################
1821 # check for slirp
1823 case "$slirp" in
1824 auto | enabled | internal)
1825 # Simpler to always update submodule, even if not needed.
1826 git_submodules="${git_submodules} slirp"
1828 esac
1830 ##########################################
1831 # functions to probe cross compilers
1833 container="no"
1834 if test $use_containers = "yes"; then
1835 if has "docker" || has "podman"; then
1836 container=$($python "$source_path"/tests/docker/docker.py probe)
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-"}
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"}
1883 compute_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\""
1892 # probe_target_compiler TARGET
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.
1900 # If TARGET is a user-mode emulation target, also set build_static to
1901 # "y" if static linking is possible.
1903 probe_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=
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
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
1955 alpha)
1956 container_image=debian-alpha-cross
1957 container_cross_prefix=alpha-linux-gnu-
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-
1964 cris)
1965 container_image=fedora-cris-cross
1966 container_cross_prefix=cris-linux-gnu-
1968 hexagon)
1969 container_image=debian-hexagon-cross
1970 container_cross_prefix=hexagon-unknown-linux-musl-
1971 container_cross_cc=${container_cross_prefix}clang
1973 hppa)
1974 container_image=debian-hppa-cross
1975 container_cross_prefix=hppa-linux-gnu-
1977 i386)
1978 container_image=fedora-i386-cross
1979 container_cross_prefix=
1981 loongarch64)
1982 container_image=debian-loongarch-cross
1983 container_cross_prefix=loongarch64-unknown-linux-gnu-
1985 m68k)
1986 container_image=debian-m68k-cross
1987 container_cross_prefix=m68k-linux-gnu-
1989 microblaze)
1990 container_image=debian-microblaze-cross
1991 container_cross_prefix=microblaze-linux-musl-
1993 mips64el)
1994 container_image=debian-mips64el-cross
1995 container_cross_prefix=mips64el-linux-gnuabi64-
1997 mips64)
1998 container_image=debian-mips64-cross
1999 container_cross_prefix=mips64-linux-gnuabi64-
2001 mipsel)
2002 container_image=debian-mipsel-cross
2003 container_cross_prefix=mipsel-linux-gnu-
2005 mips)
2006 container_image=debian-mips-cross
2007 container_cross_prefix=mips-linux-gnu-
2009 nios2)
2010 container_image=debian-nios2-cross
2011 container_cross_prefix=nios2-linux-gnu-
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
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
2023 riscv64)
2024 container_image=debian-riscv64-test-cross
2025 container_cross_prefix=riscv64-linux-gnu-
2027 s390x)
2028 container_image=debian-s390x-cross
2029 container_cross_prefix=s390x-linux-gnu-
2031 sh4)
2032 container_image=debian-sh4-cross
2033 container_cross_prefix=sh4-linux-gnu-
2035 sparc64)
2036 container_image=debian-sparc64-cross
2037 container_cross_prefix=sparc64-linux-gnu-
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
2046 x86_64)
2047 container_image=debian-amd64-cross
2048 container_cross_prefix=x86_64-linux-gnu-
2050 xtensa*)
2051 container_hosts=x86_64
2052 container_image=debian-xtensa-cross
2054 # default to the dc232b cpu
2055 container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
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
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
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}\""
2099 else
2100 compute_target_variable $target_arch target_cc gcc
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
2111 esac
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
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
2130 continue
2132 esac
2133 else
2134 continue
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
2147 if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC -static ; then
2148 build_static=y
2149 got_cross_cc=yes
2150 break
2152 if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC ; then
2153 build_static=
2154 got_cross_cc=yes
2155 break
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=
2174 write_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"
2180 if test -n "$target_ar"; then
2181 echo "AR=$target_ar"
2183 if test -n "$target_as"; then
2184 echo "AS=$target_as"
2186 if test -n "$target_ld"; then
2187 echo "LD=$target_ld"
2189 if test -n "$target_nm"; then
2190 echo "NM=$target_nm"
2192 if test -n "$target_objcopy"; then
2193 echo "OBJCOPY=$target_objcopy"
2195 if test -n "$target_ranlib"; then
2196 echo "RANLIB=$target_ranlib"
2198 if test -n "$target_strip"; then
2199 echo "STRIP=$target_strip"
2203 write_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 --"
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 --"
2220 ##########################################
2221 # check for vfio_user_server
2223 case "$vfio_user_server" in
2224 enabled )
2225 if test "$git_submodules_action" != "ignore"; then
2226 git_submodules="${git_submodules} subprojects/libvfio-user"
2229 esac
2231 ##########################################
2232 # End of CC checks
2233 # After here, no more $cc or $ld runs
2235 write_c_skeleton
2237 if test "$fortify_source" = "yes" ; then
2238 QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
2241 if 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."
2252 if 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."
2259 elif test "$tsan" = "yes" ; then
2260 error_exit "Cannot enable TSAN due to missing sanitize thread interface."
2262 if test "$have_ubsan" = "yes"; then
2263 QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
2264 QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
2267 ##########################################
2269 # Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
2270 if 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"
2276 # Guest agent Windows MSI package
2278 if test "$QEMU_GA_MANUFACTURER" = ""; then
2279 QEMU_GA_MANUFACTURER=QEMU
2281 if test "$QEMU_GA_DISTRO" = ""; then
2282 QEMU_GA_DISTRO=Linux
2284 if test "$QEMU_GA_VERSION" = ""; then
2285 QEMU_GA_VERSION=$(cat "$source_path"/VERSION)
2289 #######################################
2290 # cross-compiled firmware targets
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.
2300 LINKS="Makefile"
2301 LINKS="$LINKS tests/tcg/Makefile.target"
2302 LINKS="$LINKS pc-bios/optionrom/Makefile"
2303 LINKS="$LINKS pc-bios/s390-ccw/Makefile"
2304 LINKS="$LINKS pc-bios/vof/Makefile"
2305 LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
2306 LINKS="$LINKS tests/avocado tests/data"
2307 LINKS="$LINKS tests/qemu-iotests/check"
2308 LINKS="$LINKS python"
2309 LINKS="$LINKS contrib/plugins/Makefile "
2310 for f in $LINKS ; do
2311 if [ -e "$source_path/$f" ]; then
2312 mkdir -p "$(dirname ./"$f")"
2313 symlink "$source_path/$f" "$f"
2315 done
2317 # Mac OS X ships with a broken assembler
2318 roms=
2319 probe_target_compiler i386-softmmu
2320 if 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
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
2342 probe_target_compiler ppc-softmmu
2343 if 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
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)
2353 probe_target_compiler s390x-softmmu
2354 if 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."
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"
2374 #######################################
2375 # generate config-host.mak
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.
2379 if has $cxx; then
2380 cat > $TMPC <<EOF
2381 int c_function(void);
2382 int main(void) { return c_function(); }
2385 compile_object
2387 cat > $TMPCXX <<EOF
2388 extern "C" {
2389 int c_function(void);
2391 int c_function(void) { return 42; }
2394 update_cxxflags
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
2399 else
2400 echo "C++ compiler $cxx does not work with C compiler $cc"
2401 echo "Disabling C++ specific optional code"
2402 cxx=
2404 else
2405 echo "No C++ compiler available; disabling C++ specific optional code"
2406 cxx=
2409 if ! (GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
2410 exit 1
2413 config_host_mak="config-host.mak"
2415 echo "# Automatically generated by configure - do not modify" > $config_host_mak
2416 echo >> $config_host_mak
2418 echo all: >> $config_host_mak
2419 echo "GIT=$git" >> $config_host_mak
2420 echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
2421 echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
2423 if test "$debug_tcg" = "yes" ; then
2424 echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
2426 if 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
2431 else
2432 echo "CONFIG_POSIX=y" >> $config_host_mak
2435 if test "$linux" = "yes" ; then
2436 echo "CONFIG_LINUX=y" >> $config_host_mak
2439 if test "$darwin" = "yes" ; then
2440 echo "CONFIG_DARWIN=y" >> $config_host_mak
2443 if test "$solaris" = "yes" ; then
2444 echo "CONFIG_SOLARIS=y" >> $config_host_mak
2446 if test "$static" = "yes" ; then
2447 echo "CONFIG_STATIC=y" >> $config_host_mak
2449 echo "SRC_PATH=$source_path" >> $config_host_mak
2450 echo "TARGET_DIRS=$target_list" >> $config_host_mak
2451 if test "$modules" = "yes"; then
2452 echo "CONFIG_MODULES=y" >> $config_host_mak
2455 # XXX: suppress that
2456 if [ "$bsd" = "yes" ] ; then
2457 echo "CONFIG_BSD=y" >> $config_host_mak
2460 echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
2462 if test "$have_asan_iface_fiber" = "yes" ; then
2463 echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
2466 if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
2467 echo "CONFIG_TSAN=y" >> $config_host_mak
2470 if test "$plugins" = "yes" ; then
2471 echo "CONFIG_PLUGIN=y" >> $config_host_mak
2474 if 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
2481 echo "ROMS=$roms" >> $config_host_mak
2482 echo "MAKE=$make" >> $config_host_mak
2483 echo "PYTHON=$python" >> $config_host_mak
2484 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
2485 echo "MESON=$meson" >> $config_host_mak
2486 echo "NINJA=$ninja" >> $config_host_mak
2487 echo "CC=$cc" >> $config_host_mak
2488 echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
2489 echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
2490 echo "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak
2491 echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
2492 echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
2493 echo "GLIB_BINDIR=$glib_bindir" >> $config_host_mak
2494 echo "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak
2495 echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
2496 echo "EXESUF=$EXESUF" >> $config_host_mak
2498 # use included Linux headers
2499 if test "$linux" = "yes" ; then
2500 mkdir -p linux-headers
2501 case "$cpu" in
2502 i386|x86_64)
2503 linux_arch=x86
2505 ppc|ppc64)
2506 linux_arch=powerpc
2508 s390x)
2509 linux_arch=s390
2511 aarch64)
2512 linux_arch=arm64
2514 loongarch*)
2515 linux_arch=loongarch
2517 mips64)
2518 linux_arch=mips
2521 # For most CPUs the kernel architecture name and QEMU CPU name match.
2522 linux_arch="$cpu"
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
2531 for 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
2539 done
2541 if test "$default_targets" = "yes"; then
2542 echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
2545 if test "$ccache_cpp2" = "yes"; then
2546 echo "export CCACHE_CPP2=y" >> $config_host_mak
2549 if test "$safe_stack" = "yes"; then
2550 echo "CONFIG_SAFESTACK=y" >> $config_host_mak
2553 # tests/tcg configuration
2554 (makefile=tests/tcg/Makefile.prereqs
2555 echo "# Automatically generated by configure - do not modify" > $makefile
2557 config_host_mak=tests/tcg/config-host.mak
2558 echo "# Automatically generated by configure - do not modify" > $config_host_mak
2559 echo "SRC_PATH=$source_path" >> $config_host_mak
2560 echo "HOST_CC=$host_cc" >> $config_host_mak
2562 tcg_tests_targets=
2563 for target in $target_list; do
2564 arch=${target%%-*}
2566 config_target_mak=tests/tcg/config-$target.mak
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
2575 *-softmmu)
2576 test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || continue
2577 qemu="qemu-system-$arch"
2579 *-linux-user|*-bsd-user)
2580 qemu="qemu-$arch"
2582 esac
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.
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"
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"
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"
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"
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"
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"
2621 if do_compiler "$target_cc" $target_cflags \
2622 -mpower10 -o $TMPE $TMPC; then
2623 echo "CROSS_CC_HAS_POWER10=y" >> "$config_target_mak"
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"
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"
2645 ppc*)
2646 echo "CROSS_CC_HAS_POWER8_VECTOR=y" >> "$config_target_mak"
2647 echo "CROSS_CC_HAS_POWER10=y" >> "$config_target_mak"
2649 i386-linux-user)
2650 echo "CROSS_CC_HAS_I386_NOPIE=y" >> "$config_target_mak"
2652 esac
2653 got_cross_cc=yes
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"
2661 done
2662 echo "TCG_TESTS_TARGETS=$tcg_tests_targets" >> $makefile)
2664 if test "$skip_meson" = no; then
2665 cross="config-meson.cross.new"
2666 meson_quote() {
2667 test $# = 0 && return
2668 echo "'$(echo $* | sed "s/ /','/g")'"
2671 echo "# Automatically generated by configure - do not modify" > $cross
2672 echo "[properties]" >> $cross
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
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
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
2710 echo "cpu_family = '$cpu'" >> $cross
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
2719 else
2720 cross_arg="--native-file config-meson.cross"
2722 mv $cross config-meson.cross
2724 rm -rf meson-private meson-info meson-logs
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
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"
2744 eval run_meson $meson_options
2745 if test "$?" -ne 0 ; then
2746 error_exit "meson setup failed"
2748 else
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
2760 # Save the configure command line for later reuse.
2761 cat <<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.
2769 preserve_env() {
2770 envname=$1
2772 eval envval=\$$envname
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
2783 # Preserve various env variables that influence what
2784 # features/build target configure will detect
2785 preserve_env AR
2786 preserve_env AS
2787 preserve_env CC
2788 preserve_env CFLAGS
2789 preserve_env CXX
2790 preserve_env CXXFLAGS
2791 preserve_env LD
2792 preserve_env LDFLAGS
2793 preserve_env LD_LIBRARY_PATH
2794 preserve_env MAKE
2795 preserve_env NM
2796 preserve_env OBJCFLAGS
2797 preserve_env OBJCOPY
2798 preserve_env PATH
2799 preserve_env PKG_CONFIG
2800 preserve_env PKG_CONFIG_LIBDIR
2801 preserve_env PKG_CONFIG_PATH
2802 preserve_env PYTHON
2803 preserve_env SDL2_CONFIG
2804 preserve_env SMBD
2805 preserve_env STRIP
2806 preserve_env WIDL
2807 preserve_env WINDRES
2809 printf "exec" >>config.status
2810 for i in "$0" "$@"; do
2811 test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
2812 done
2813 echo ' "$@"' >>config.status
2814 chmod +x config.status
2816 rm -r "$TMPDIR1"