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