]> git.proxmox.com Git - mirror_qemu.git/blob - configure
configure, meson: move some default-disabled options to meson_options.txt
[mirror_qemu.git] / configure
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.
8 CLICOLOR_FORCE= GREP_OPTIONS=
9 unset CLICOLOR_FORCE GREP_OPTIONS
10
11 # Don't allow CCACHE, if present, to use cached results of compile tests!
12 export CCACHE_RECACHE=yes
13
14 # make source path absolute
15 source_path=$(cd "$(dirname -- "$0")"; pwd)
16
17 if test "$PWD" = "$source_path"
18 then
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
41 ifeq ($(MAKECMDGOALS),)
42 recurse: all
43 endif
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
54 force: ;
55 .PHONY: force
56 GNUmakefile: ;
57
58 EOF
59 cd build
60 exec $source_path/configure "$@"
61 fi
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.)
68 TMPDIR1="config-temp"
69 rm -rf "${TMPDIR1}"
70 mkdir -p "${TMPDIR1}"
71 if [ $? -ne 0 ]; then
72 echo "ERROR: failed to create temporary directory"
73 exit 1
74 fi
75
76 TMPB="qemu-conf"
77 TMPC="${TMPDIR1}/${TMPB}.c"
78 TMPO="${TMPDIR1}/${TMPB}.o"
79 TMPCXX="${TMPDIR1}/${TMPB}.cxx"
80 TMPE="${TMPDIR1}/${TMPB}.exe"
81
82 rm -f config.log
83
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
90
91 quote_sh() {
92 printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
93 }
94
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
103 }
104
105 error_exit() {
106 print_error "$@"
107 exit 1
108 }
109
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 $?
122 # Test passed. If this is an --enable-werror build, rerun
123 # the test with -Werror and bail out if it fails. This
124 # makes warning-generating-errors in configure test code
125 # obvious to developers.
126 if test "$werror" != "yes"; then
127 return 0
128 fi
129 # Don't bother rerunning the compile if we were already using -Werror
130 case "$*" in
131 *-Werror*)
132 return 0
133 ;;
134 esac
135 echo $compiler -Werror "$@" >> config.log
136 $compiler -Werror "$@" >> config.log 2>&1 && return $?
137 error_exit "configure test passed without -Werror but failed with -Werror." \
138 "This is probably a bug in the configure script. The failing command" \
139 "will be at the bottom of config.log." \
140 "You can run configure with --disable-werror to bypass this check."
141 }
142
143 do_cc() {
144 do_compiler "$cc" $CPU_CFLAGS "$@"
145 }
146
147 do_cxx() {
148 do_compiler "$cxx" $CPU_CFLAGS "$@"
149 }
150
151 # Append $2 to the variable named $1, with space separation
152 add_to() {
153 eval $1=\${$1:+\"\$$1 \"}\$2
154 }
155
156 update_cxxflags() {
157 # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
158 # options which some versions of GCC's C++ compiler complain about
159 # because they only make sense for C programs.
160 QEMU_CXXFLAGS="-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
161 CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
162 for arg in $QEMU_CFLAGS; do
163 case $arg in
164 -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
165 -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
166 ;;
167 *)
168 QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
169 ;;
170 esac
171 done
172 }
173
174 compile_object() {
175 local_cflags="$1"
176 do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
177 }
178
179 compile_prog() {
180 local_cflags="$1"
181 local_ldflags="$2"
182 do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
183 $LDFLAGS $EXTRA_LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
184 }
185
186 # symbolically link $1 to $2. Portable version of "ln -sf".
187 symlink() {
188 rm -rf "$2"
189 mkdir -p "$(dirname "$2")"
190 ln -s "$1" "$2"
191 }
192
193 # check whether a command is available to this shell (may be either an
194 # executable or a builtin)
195 has() {
196 type "$1" >/dev/null 2>&1
197 }
198
199 version_ge () {
200 local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
201 local_ver2=$(echo "$2" | tr . ' ')
202 while true; do
203 set x $local_ver1
204 local_first=${2-0}
205 # 'shift 2' if $2 is set, or 'shift' if $2 is not set
206 shift ${2:+2}
207 local_ver1=$*
208 set x $local_ver2
209 # the second argument finished, the first must be greater or equal
210 test $# = 1 && return 0
211 test $local_first -lt $2 && return 1
212 test $local_first -gt $2 && return 0
213 shift ${2:+2}
214 local_ver2=$*
215 done
216 }
217
218 glob() {
219 eval test -z '"${1#'"$2"'}"'
220 }
221
222 ld_has() {
223 $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
224 }
225
226 if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
227 then
228 error_exit "main directory cannot contain spaces nor colons"
229 fi
230
231 # default parameters
232 cpu=""
233 iasl="iasl"
234 interp_prefix="/usr/gnemul/qemu-%M"
235 static="no"
236 cross_compile="no"
237 cross_prefix=""
238 audio_drv_list="default"
239 block_drv_rw_whitelist=""
240 block_drv_ro_whitelist=""
241 host_cc="cc"
242 debug_info="yes"
243 lto="false"
244 stack_protector=""
245 safe_stack=""
246 use_containers="yes"
247 gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
248
249 if test -e "$source_path/.git"
250 then
251 git_submodules_action="update"
252 else
253 git_submodules_action="ignore"
254 fi
255
256 git_submodules="ui/keycodemapdb"
257 git="git"
258
259 # Don't accept a target_list environment variable.
260 unset target_list
261 unset 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
275 default_feature=""
276 # parse CC options second
277 for opt do
278 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
279 case "$opt" in
280 --without-default-features)
281 default_feature="no"
282 ;;
283 esac
284 done
285
286 EXTRA_CFLAGS=""
287 EXTRA_CXXFLAGS=""
288 EXTRA_LDFLAGS=""
289
290 xen_ctrl_version="$default_feature"
291 vhost_kernel="$default_feature"
292 vhost_net="$default_feature"
293 vhost_crypto="$default_feature"
294 vhost_scsi="$default_feature"
295 vhost_vsock="$default_feature"
296 vhost_user="no"
297 vhost_user_fs="$default_feature"
298 vhost_vdpa="$default_feature"
299 rdma="$default_feature"
300 pvrdma="$default_feature"
301 debug_tcg="no"
302 debug="no"
303 sanitizers="no"
304 tsan="no"
305 fortify_source="$default_feature"
306 gcov="no"
307 EXESUF=""
308 modules="no"
309 module_upgrades="no"
310 prefix="/usr/local"
311 qemu_suffix="qemu"
312 softmmu="yes"
313 linux_user=""
314 bsd_user=""
315 pkgversion=""
316 pie=""
317 trace_backends="log"
318 trace_file="trace"
319 opengl="$default_feature"
320 guest_agent="$default_feature"
321 vss_win32_sdk="$default_feature"
322 win_sdk="no"
323 want_tools="$default_feature"
324 coroutine=""
325 coroutine_pool="$default_feature"
326 debug_stack_usage="no"
327 tls_priority="NORMAL"
328 plugins="$default_feature"
329 secret_keyring="$default_feature"
330 meson=""
331 meson_args=""
332 ninja=""
333 gio="$default_feature"
334 skip_meson=no
335 slirp_smbd="$default_feature"
336
337 # The following Meson options are handled manually (still they
338 # are included in the automatically generated help message)
339
340 # 1. Track which submodules are needed
341 capstone="auto"
342 fdt="auto"
343 slirp="auto"
344
345 # 2. Support --with/--without option
346 default_devices="true"
347
348 # 3. Automatically enable/disable other options
349 tcg="enabled"
350 cfi="false"
351
352 # 4. Detection partly done in configure
353 xen=${default_feature:+disabled}
354
355 # parse CC options second
356 for opt do
357 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
358 case "$opt" in
359 --cross-prefix=*) cross_prefix="$optarg"
360 cross_compile="yes"
361 ;;
362 --cc=*) CC="$optarg"
363 ;;
364 --cxx=*) CXX="$optarg"
365 ;;
366 --cpu=*) cpu="$optarg"
367 ;;
368 --extra-cflags=*)
369 EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
370 EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
371 ;;
372 --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
373 ;;
374 --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
375 ;;
376 --enable-debug-info) debug_info="yes"
377 ;;
378 --disable-debug-info) debug_info="no"
379 ;;
380 --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
381 ;;
382 --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
383 eval "cross_cc_cflags_${cc_arch}=\$optarg"
384 cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
385 ;;
386 --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
387 cc_archs="$cc_archs $cc_arch"
388 eval "cross_cc_${cc_arch}=\$optarg"
389 cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
390 ;;
391 esac
392 done
393 # OS specific
394 # Using uname is really, really broken. Once we have the right set of checks
395 # we can eliminate its usage altogether.
396
397 # Preferred compiler:
398 # ${CC} (if set)
399 # ${cross_prefix}gcc (if cross-prefix specified)
400 # system compiler
401 if test -z "${CC}${cross_prefix}"; then
402 cc="$host_cc"
403 else
404 cc="${CC-${cross_prefix}gcc}"
405 fi
406
407 if test -z "${CXX}${cross_prefix}"; then
408 cxx="c++"
409 else
410 cxx="${CXX-${cross_prefix}g++}"
411 fi
412
413 ar="${AR-${cross_prefix}ar}"
414 as="${AS-${cross_prefix}as}"
415 ccas="${CCAS-$cc}"
416 cpp="${CPP-$cc -E}"
417 objcopy="${OBJCOPY-${cross_prefix}objcopy}"
418 ld="${LD-${cross_prefix}ld}"
419 ranlib="${RANLIB-${cross_prefix}ranlib}"
420 nm="${NM-${cross_prefix}nm}"
421 strip="${STRIP-${cross_prefix}strip}"
422 windres="${WINDRES-${cross_prefix}windres}"
423 pkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
424 query_pkg_config() {
425 "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
426 }
427 pkg_config=query_pkg_config
428 sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
429
430 # default flags for all hosts
431 # We use -fwrapv to tell the compiler that we require a C dialect where
432 # left shift of signed integers is well defined and has the expected
433 # 2s-complement style results. (Both clang and gcc agree that it
434 # provides these semantics.)
435 QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
436 QEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
437 QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
438 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
439
440 QEMU_LDFLAGS=
441
442 # Flags that are needed during configure but later taken care of by Meson
443 CONFIGURE_CFLAGS="-std=gnu11 -Wall"
444 CONFIGURE_LDFLAGS=
445
446
447 check_define() {
448 cat > $TMPC <<EOF
449 #if !defined($1)
450 #error $1 not defined
451 #endif
452 int main(void) { return 0; }
453 EOF
454 compile_object
455 }
456
457 check_include() {
458 cat > $TMPC <<EOF
459 #include <$1>
460 int main(void) { return 0; }
461 EOF
462 compile_object
463 }
464
465 write_c_skeleton() {
466 cat > $TMPC <<EOF
467 int main(void) { return 0; }
468 EOF
469 }
470
471 if check_define __linux__ ; then
472 targetos=linux
473 elif check_define _WIN32 ; then
474 targetos=windows
475 elif check_define __OpenBSD__ ; then
476 targetos=openbsd
477 elif check_define __sun__ ; then
478 targetos=sunos
479 elif check_define __HAIKU__ ; then
480 targetos=haiku
481 elif check_define __FreeBSD__ ; then
482 targetos=freebsd
483 elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
484 targetos=gnu/kfreebsd
485 elif check_define __DragonFly__ ; then
486 targetos=dragonfly
487 elif check_define __NetBSD__; then
488 targetos=netbsd
489 elif check_define __APPLE__; then
490 targetos=darwin
491 else
492 # This is a fatal error, but don't report it yet, because we
493 # might be going to just print the --help text, or it might
494 # be the result of a missing compiler.
495 targetos=bogus
496 fi
497
498 # OS specific
499
500 mingw32="no"
501 bsd="no"
502 linux="no"
503 solaris="no"
504 case $targetos in
505 windows)
506 mingw32="yes"
507 plugins="no"
508 pie="no"
509 ;;
510 gnu/kfreebsd)
511 bsd="yes"
512 ;;
513 freebsd)
514 bsd="yes"
515 make="${MAKE-gmake}"
516 # needed for kinfo_getvmmap(3) in libutil.h
517 ;;
518 dragonfly)
519 bsd="yes"
520 make="${MAKE-gmake}"
521 ;;
522 netbsd)
523 bsd="yes"
524 make="${MAKE-gmake}"
525 ;;
526 openbsd)
527 bsd="yes"
528 make="${MAKE-gmake}"
529 ;;
530 darwin)
531 bsd="yes"
532 darwin="yes"
533 # Disable attempts to use ObjectiveC features in os/object.h since they
534 # won't work when we're compiling with gcc as a C compiler.
535 QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
536 ;;
537 sunos)
538 solaris="yes"
539 make="${MAKE-gmake}"
540 smbd="${SMBD-/usr/sfw/sbin/smbd}"
541 # needed for CMSG_ macros in sys/socket.h
542 QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
543 # needed for TIOCWIN* defines in termios.h
544 QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
545 # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
546 # Note that this check is broken for cross-compilation: if you're
547 # cross-compiling to one of these OSes then you'll need to specify
548 # the correct CPU with the --cpu option.
549 if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
550 cpu="x86_64"
551 fi
552 ;;
553 haiku)
554 pie="no"
555 QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
556 ;;
557 linux)
558 linux="yes"
559 vhost_user=${default_feature:-yes}
560 ;;
561 esac
562
563 if test ! -z "$cpu" ; then
564 # command line argument
565 :
566 elif check_define __i386__ ; then
567 cpu="i386"
568 elif check_define __x86_64__ ; then
569 if check_define __ILP32__ ; then
570 cpu="x32"
571 else
572 cpu="x86_64"
573 fi
574 elif check_define __sparc__ ; then
575 if check_define __arch64__ ; then
576 cpu="sparc64"
577 else
578 cpu="sparc"
579 fi
580 elif check_define _ARCH_PPC ; then
581 if check_define _ARCH_PPC64 ; then
582 if check_define _LITTLE_ENDIAN ; then
583 cpu="ppc64le"
584 else
585 cpu="ppc64"
586 fi
587 else
588 cpu="ppc"
589 fi
590 elif check_define __mips__ ; then
591 cpu="mips"
592 elif check_define __s390__ ; then
593 if check_define __s390x__ ; then
594 cpu="s390x"
595 else
596 cpu="s390"
597 fi
598 elif check_define __riscv ; then
599 cpu="riscv"
600 elif check_define __arm__ ; then
601 cpu="arm"
602 elif check_define __aarch64__ ; then
603 cpu="aarch64"
604 elif check_define __loongarch64 ; then
605 cpu="loongarch64"
606 else
607 cpu=$(uname -m)
608 fi
609
610 # Normalise host CPU name, set multilib cflags
611 # Note that this case should only have supported host CPUs, not guests.
612 case "$cpu" in
613 armv*b|armv*l|arm)
614 cpu="arm" ;;
615
616 i386|i486|i586|i686|i86pc|BePC)
617 cpu="i386"
618 CPU_CFLAGS="-m32" ;;
619 x32)
620 cpu="x86_64"
621 CPU_CFLAGS="-mx32" ;;
622 x86_64|amd64)
623 cpu="x86_64"
624 # ??? Only extremely old AMD cpus do not have cmpxchg16b.
625 # If we truly care, we should simply detect this case at
626 # runtime and generate the fallback to serial emulation.
627 CPU_CFLAGS="-m64 -mcx16" ;;
628
629 mips*)
630 cpu="mips" ;;
631
632 ppc)
633 CPU_CFLAGS="-m32" ;;
634 ppc64)
635 CPU_CFLAGS="-m64 -mbig" ;;
636 ppc64le)
637 cpu="ppc64"
638 CPU_CFLAGS="-m64 -mlittle" ;;
639
640 s390)
641 CPU_CFLAGS="-m31" ;;
642 s390x)
643 CPU_CFLAGS="-m64" ;;
644
645 sparc|sun4[cdmuv])
646 cpu="sparc"
647 CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
648 sparc64)
649 CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
650 esac
651
652 : ${make=${MAKE-make}}
653
654 # We prefer python 3.x. A bare 'python' is traditionally
655 # python 2.x, but some distros have it as python 3.x, so
656 # we check that too
657 python=
658 explicit_python=no
659 for binary in "${PYTHON-python3}" python
660 do
661 if has "$binary"
662 then
663 python=$(command -v "$binary")
664 break
665 fi
666 done
667
668
669 # Check for ancillary tools used in testing
670 genisoimage=
671 for binary in genisoimage mkisofs
672 do
673 if has $binary
674 then
675 genisoimage=$(command -v "$binary")
676 break
677 fi
678 done
679
680 # Default objcc to clang if available, otherwise use CC
681 if has clang; then
682 objcc=clang
683 else
684 objcc="$cc"
685 fi
686
687 if test "$mingw32" = "yes" ; then
688 EXESUF=".exe"
689 # MinGW needs -mthreads for TLS and macro _MT.
690 CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
691 write_c_skeleton;
692 prefix="/qemu"
693 qemu_suffix=""
694 fi
695
696 werror=""
697
698 . $source_path/scripts/meson-buildoptions.sh
699
700 meson_options=
701 meson_option_parse() {
702 meson_options="$meson_options $(_meson_option_parse "$@")"
703 if test $? -eq 1; then
704 echo "ERROR: unknown option $1"
705 echo "Try '$0 --help' for more information"
706 exit 1
707 fi
708 }
709
710 for opt do
711 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
712 case "$opt" in
713 --help|-h) show_help=yes
714 ;;
715 --version|-V) exec cat $source_path/VERSION
716 ;;
717 --prefix=*) prefix="$optarg"
718 ;;
719 --interp-prefix=*) interp_prefix="$optarg"
720 ;;
721 --cross-prefix=*)
722 ;;
723 --cc=*)
724 ;;
725 --host-cc=*) host_cc="$optarg"
726 ;;
727 --cxx=*)
728 ;;
729 --iasl=*) iasl="$optarg"
730 ;;
731 --objcc=*) objcc="$optarg"
732 ;;
733 --make=*) make="$optarg"
734 ;;
735 --install=*)
736 ;;
737 --python=*) python="$optarg" ; explicit_python=yes
738 ;;
739 --sphinx-build=*) sphinx_build="$optarg"
740 ;;
741 --skip-meson) skip_meson=yes
742 ;;
743 --meson=*) meson="$optarg"
744 ;;
745 --ninja=*) ninja="$optarg"
746 ;;
747 --smbd=*) smbd="$optarg"
748 ;;
749 --extra-cflags=*)
750 ;;
751 --extra-cxxflags=*)
752 ;;
753 --extra-ldflags=*)
754 ;;
755 --enable-debug-info)
756 ;;
757 --disable-debug-info)
758 ;;
759 --cross-cc-*)
760 ;;
761 --enable-modules)
762 modules="yes"
763 ;;
764 --disable-modules)
765 modules="no"
766 ;;
767 --disable-module-upgrades) module_upgrades="no"
768 ;;
769 --enable-module-upgrades) module_upgrades="yes"
770 ;;
771 --cpu=*)
772 ;;
773 --target-list=*) target_list="$optarg"
774 if test "$target_list_exclude"; then
775 error_exit "Can't mix --target-list with --target-list-exclude"
776 fi
777 ;;
778 --target-list-exclude=*) target_list_exclude="$optarg"
779 if test "$target_list"; then
780 error_exit "Can't mix --target-list-exclude with --target-list"
781 fi
782 ;;
783 --with-trace-file=*) trace_file="$optarg"
784 ;;
785 --with-default-devices) default_devices="true"
786 ;;
787 --without-default-devices) default_devices="false"
788 ;;
789 --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
790 ;;
791 --with-devices-*) device_arch=${opt#--with-devices-};
792 device_arch=${device_arch%%=*}
793 cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
794 if test -f "$cf"; then
795 device_archs="$device_archs $device_arch"
796 eval "devices_${device_arch}=\$optarg"
797 else
798 error_exit "File $cf does not exist"
799 fi
800 ;;
801 --without-default-features) # processed above
802 ;;
803 --enable-gcov) gcov="yes"
804 ;;
805 --static)
806 static="yes"
807 QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
808 ;;
809 --mandir=*) mandir="$optarg"
810 ;;
811 --bindir=*) bindir="$optarg"
812 ;;
813 --libdir=*) libdir="$optarg"
814 ;;
815 --libexecdir=*) libexecdir="$optarg"
816 ;;
817 --includedir=*) includedir="$optarg"
818 ;;
819 --datadir=*) datadir="$optarg"
820 ;;
821 --with-suffix=*) qemu_suffix="$optarg"
822 ;;
823 --docdir=*) docdir="$optarg"
824 ;;
825 --localedir=*) localedir="$optarg"
826 ;;
827 --sysconfdir=*) sysconfdir="$optarg"
828 ;;
829 --localstatedir=*) local_statedir="$optarg"
830 ;;
831 --firmwarepath=*) firmwarepath="$optarg"
832 ;;
833 --host=*|--build=*|\
834 --disable-dependency-tracking|\
835 --sbindir=*|--sharedstatedir=*|\
836 --oldincludedir=*|--datarootdir=*|--infodir=*|\
837 --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
838 # These switches are silently ignored, for compatibility with
839 # autoconf-generated configure scripts. This allows QEMU's
840 # configure to be used by RPM and similar macros that set
841 # lots of directory switches by default.
842 ;;
843 --audio-drv-list=*) audio_drv_list="$optarg"
844 ;;
845 --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
846 ;;
847 --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
848 ;;
849 --enable-debug-tcg) debug_tcg="yes"
850 ;;
851 --disable-debug-tcg) debug_tcg="no"
852 ;;
853 --enable-debug)
854 # Enable debugging options that aren't excessively noisy
855 debug_tcg="yes"
856 meson_option_parse --enable-debug-mutex ""
857 debug="yes"
858 fortify_source="no"
859 ;;
860 --enable-sanitizers) sanitizers="yes"
861 ;;
862 --disable-sanitizers) sanitizers="no"
863 ;;
864 --enable-tsan) tsan="yes"
865 ;;
866 --disable-tsan) tsan="no"
867 ;;
868 --disable-slirp) slirp="disabled"
869 ;;
870 --enable-slirp) slirp="enabled"
871 ;;
872 --enable-slirp=git) slirp="internal"
873 ;;
874 --enable-slirp=*) slirp="$optarg"
875 ;;
876 --disable-xen) xen="disabled"
877 ;;
878 --enable-xen) xen="enabled"
879 ;;
880 --disable-tcg) tcg="disabled"
881 plugins="no"
882 ;;
883 --enable-tcg) tcg="enabled"
884 ;;
885 --disable-system) softmmu="no"
886 ;;
887 --enable-system) softmmu="yes"
888 ;;
889 --disable-user)
890 linux_user="no" ;
891 bsd_user="no" ;
892 ;;
893 --enable-user) ;;
894 --disable-linux-user) linux_user="no"
895 ;;
896 --enable-linux-user) linux_user="yes"
897 ;;
898 --disable-bsd-user) bsd_user="no"
899 ;;
900 --enable-bsd-user) bsd_user="yes"
901 ;;
902 --enable-pie) pie="yes"
903 ;;
904 --disable-pie) pie="no"
905 ;;
906 --enable-werror) werror="yes"
907 ;;
908 --disable-werror) werror="no"
909 ;;
910 --enable-lto) lto="true"
911 ;;
912 --disable-lto) lto="false"
913 ;;
914 --enable-stack-protector) stack_protector="yes"
915 ;;
916 --disable-stack-protector) stack_protector="no"
917 ;;
918 --enable-safe-stack) safe_stack="yes"
919 ;;
920 --disable-safe-stack) safe_stack="no"
921 ;;
922 --enable-cfi)
923 cfi="true";
924 lto="true";
925 ;;
926 --disable-cfi) cfi="false"
927 ;;
928 --disable-fdt) fdt="disabled"
929 ;;
930 --enable-fdt) fdt="enabled"
931 ;;
932 --enable-fdt=git) fdt="internal"
933 ;;
934 --enable-fdt=*) fdt="$optarg"
935 ;;
936 --with-pkgversion=*) pkgversion="$optarg"
937 ;;
938 --with-coroutine=*) coroutine="$optarg"
939 ;;
940 --disable-coroutine-pool) coroutine_pool="no"
941 ;;
942 --enable-coroutine-pool) coroutine_pool="yes"
943 ;;
944 --enable-debug-stack-usage) debug_stack_usage="yes"
945 ;;
946 --disable-vhost-net) vhost_net="no"
947 ;;
948 --enable-vhost-net) vhost_net="yes"
949 ;;
950 --disable-vhost-crypto) vhost_crypto="no"
951 ;;
952 --enable-vhost-crypto) vhost_crypto="yes"
953 ;;
954 --disable-vhost-scsi) vhost_scsi="no"
955 ;;
956 --enable-vhost-scsi) vhost_scsi="yes"
957 ;;
958 --disable-vhost-vsock) vhost_vsock="no"
959 ;;
960 --enable-vhost-vsock) vhost_vsock="yes"
961 ;;
962 --disable-vhost-user-fs) vhost_user_fs="no"
963 ;;
964 --enable-vhost-user-fs) vhost_user_fs="yes"
965 ;;
966 --disable-opengl) opengl="no"
967 ;;
968 --enable-opengl) opengl="yes"
969 ;;
970 --disable-zlib-test)
971 ;;
972 --enable-guest-agent) guest_agent="yes"
973 ;;
974 --disable-guest-agent) guest_agent="no"
975 ;;
976 --with-vss-sdk) vss_win32_sdk=""
977 ;;
978 --with-vss-sdk=*) vss_win32_sdk="$optarg"
979 ;;
980 --without-vss-sdk) vss_win32_sdk="no"
981 ;;
982 --with-win-sdk) win_sdk=""
983 ;;
984 --with-win-sdk=*) win_sdk="$optarg"
985 ;;
986 --without-win-sdk) win_sdk="no"
987 ;;
988 --enable-tools) want_tools="yes"
989 ;;
990 --disable-tools) want_tools="no"
991 ;;
992 --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
993 echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
994 ;;
995 --enable-vhdx|--disable-vhdx)
996 echo "$0: $opt is obsolete, VHDX driver is always built" >&2
997 ;;
998 --enable-uuid|--disable-uuid)
999 echo "$0: $opt is obsolete, UUID support is always built" >&2
1000 ;;
1001 --tls-priority=*) tls_priority="$optarg"
1002 ;;
1003 --enable-rdma) rdma="yes"
1004 ;;
1005 --disable-rdma) rdma="no"
1006 ;;
1007 --enable-pvrdma) pvrdma="yes"
1008 ;;
1009 --disable-pvrdma) pvrdma="no"
1010 ;;
1011 --disable-vhost-user) vhost_user="no"
1012 ;;
1013 --enable-vhost-user) vhost_user="yes"
1014 ;;
1015 --disable-vhost-vdpa) vhost_vdpa="no"
1016 ;;
1017 --enable-vhost-vdpa) vhost_vdpa="yes"
1018 ;;
1019 --disable-vhost-kernel) vhost_kernel="no"
1020 ;;
1021 --enable-vhost-kernel) vhost_kernel="yes"
1022 ;;
1023 --disable-capstone) capstone="disabled"
1024 ;;
1025 --enable-capstone) capstone="enabled"
1026 ;;
1027 --enable-capstone=git) capstone="internal"
1028 ;;
1029 --enable-capstone=*) capstone="$optarg"
1030 ;;
1031 --with-git=*) git="$optarg"
1032 ;;
1033 --with-git-submodules=*)
1034 git_submodules_action="$optarg"
1035 ;;
1036 --enable-plugins) if test "$mingw32" = "yes"; then
1037 error_exit "TCG plugins not currently supported on Windows platforms"
1038 else
1039 plugins="yes"
1040 fi
1041 ;;
1042 --disable-plugins) plugins="no"
1043 ;;
1044 --enable-containers) use_containers="yes"
1045 ;;
1046 --disable-containers) use_containers="no"
1047 ;;
1048 --gdb=*) gdb_bin="$optarg"
1049 ;;
1050 --enable-keyring) secret_keyring="yes"
1051 ;;
1052 --disable-keyring) secret_keyring="no"
1053 ;;
1054 --enable-gio) gio=yes
1055 ;;
1056 --disable-gio) gio=no
1057 ;;
1058 --enable-slirp-smbd) slirp_smbd=yes
1059 ;;
1060 --disable-slirp-smbd) slirp_smbd=no
1061 ;;
1062 # backwards compatibility options
1063 --enable-trace-backend=*) meson_option_parse "--enable-trace-backends=$optarg" "$optarg"
1064 ;;
1065 --disable-blobs) meson_option_parse --disable-install-blobs ""
1066 ;;
1067 --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
1068 ;;
1069 --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
1070 ;;
1071 # everything else has the same name in configure and meson
1072 --enable-* | --disable-*) meson_option_parse "$opt" "$optarg"
1073 ;;
1074 *)
1075 echo "ERROR: unknown option $opt"
1076 echo "Try '$0 --help' for more information"
1077 exit 1
1078 ;;
1079 esac
1080 done
1081
1082 # test for any invalid configuration combinations
1083 if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
1084 error_exit "Can't enable plugins on non-TCG builds"
1085 fi
1086
1087 case $git_submodules_action in
1088 update|validate)
1089 if test ! -e "$source_path/.git"; then
1090 echo "ERROR: cannot $git_submodules_action git submodules without .git"
1091 exit 1
1092 fi
1093 ;;
1094 ignore)
1095 if ! test -f "$source_path/ui/keycodemapdb/README"
1096 then
1097 echo
1098 echo "ERROR: missing GIT submodules"
1099 echo
1100 if test -e "$source_path/.git"; then
1101 echo "--with-git-submodules=ignore specified but submodules were not"
1102 echo "checked out. Please initialize and update submodules."
1103 else
1104 echo "This is not a GIT checkout but module content appears to"
1105 echo "be missing. Do not use 'git archive' or GitHub download links"
1106 echo "to acquire QEMU source archives. Non-GIT builds are only"
1107 echo "supported with source archives linked from:"
1108 echo
1109 echo " https://www.qemu.org/download/#source"
1110 echo
1111 echo "Developers working with GIT can use scripts/archive-source.sh"
1112 echo "if they need to create valid source archives."
1113 fi
1114 echo
1115 exit 1
1116 fi
1117 ;;
1118 *)
1119 echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
1120 exit 1
1121 ;;
1122 esac
1123
1124 libdir="${libdir:-$prefix/lib}"
1125 libexecdir="${libexecdir:-$prefix/libexec}"
1126 includedir="${includedir:-$prefix/include}"
1127
1128 if test "$mingw32" = "yes" ; then
1129 bindir="${bindir:-$prefix}"
1130 else
1131 bindir="${bindir:-$prefix/bin}"
1132 fi
1133 mandir="${mandir:-$prefix/share/man}"
1134 datadir="${datadir:-$prefix/share}"
1135 docdir="${docdir:-$prefix/share/doc}"
1136 sysconfdir="${sysconfdir:-$prefix/etc}"
1137 local_statedir="${local_statedir:-$prefix/var}"
1138 firmwarepath="${firmwarepath:-$datadir/qemu-firmware}"
1139 localedir="${localedir:-$datadir/locale}"
1140
1141 if eval test -z "\${cross_cc_$cpu}"; then
1142 eval "cross_cc_${cpu}=\$cc"
1143 cross_cc_vars="$cross_cc_vars cross_cc_${cpu}"
1144 fi
1145
1146 default_target_list=""
1147 mak_wilds=""
1148
1149 if [ "$linux_user" != no ]; then
1150 if [ "$targetos" = linux ] && [ -d $source_path/linux-user/include/host/$cpu ]; then
1151 linux_user=yes
1152 elif [ "$linux_user" = yes ]; then
1153 error_exit "linux-user not supported on this architecture"
1154 fi
1155 fi
1156 if [ "$bsd_user" != no ]; then
1157 if [ "$bsd_user" = "" ]; then
1158 test $targetos = freebsd && bsd_user=yes
1159 fi
1160 if [ "$bsd_user" = yes ] && ! [ -d $source_path/bsd-user/$targetos ]; then
1161 error_exit "bsd-user not supported on this host OS"
1162 fi
1163 fi
1164 if [ "$softmmu" = "yes" ]; then
1165 mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
1166 fi
1167 if [ "$linux_user" = "yes" ]; then
1168 mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
1169 fi
1170 if [ "$bsd_user" = "yes" ]; then
1171 mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
1172 fi
1173
1174 for config in $mak_wilds; do
1175 target="$(basename "$config" .mak)"
1176 if echo "$target_list_exclude" | grep -vq "$target"; then
1177 default_target_list="${default_target_list} $target"
1178 fi
1179 done
1180
1181 if test x"$show_help" = x"yes" ; then
1182 cat << EOF
1183
1184 Usage: configure [options]
1185 Options: [defaults in brackets after descriptions]
1186
1187 Standard options:
1188 --help print this message
1189 --prefix=PREFIX install in PREFIX [$prefix]
1190 --interp-prefix=PREFIX where to find shared libraries, etc.
1191 use %M for cpu name [$interp_prefix]
1192 --target-list=LIST set target list (default: build all)
1193 $(echo Available targets: $default_target_list | \
1194 fold -s -w 53 | sed -e 's/^/ /')
1195 --target-list-exclude=LIST exclude a set of targets from the default target-list
1196
1197 Advanced options (experts only):
1198 --cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
1199 --cc=CC use C compiler CC [$cc]
1200 --iasl=IASL use ACPI compiler IASL [$iasl]
1201 --host-cc=CC use C compiler CC [$host_cc] for code run at
1202 build time
1203 --cxx=CXX use C++ compiler CXX [$cxx]
1204 --objcc=OBJCC use Objective-C compiler OBJCC [$objcc]
1205 --extra-cflags=CFLAGS append extra C compiler flags CFLAGS
1206 --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
1207 --extra-ldflags=LDFLAGS append extra linker flags LDFLAGS
1208 --cross-cc-ARCH=CC use compiler when building ARCH guest test cases
1209 --cross-cc-cflags-ARCH= use compiler flags when building ARCH guest tests
1210 --make=MAKE use specified make [$make]
1211 --python=PYTHON use specified python [$python]
1212 --sphinx-build=SPHINX use specified sphinx-build [$sphinx_build]
1213 --meson=MESON use specified meson [$meson]
1214 --ninja=NINJA use specified ninja [$ninja]
1215 --smbd=SMBD use specified smbd [$smbd]
1216 --with-git=GIT use specified git [$git]
1217 --with-git-submodules=update update git submodules (default if .git dir exists)
1218 --with-git-submodules=validate fail if git submodules are not up to date
1219 --with-git-submodules=ignore do not update or check git submodules (default if no .git dir)
1220 --static enable static build [$static]
1221 --mandir=PATH install man pages in PATH
1222 --datadir=PATH install firmware in PATH/$qemu_suffix
1223 --localedir=PATH install translation in PATH/$qemu_suffix
1224 --docdir=PATH install documentation in PATH/$qemu_suffix
1225 --bindir=PATH install binaries in PATH
1226 --libdir=PATH install libraries in PATH
1227 --libexecdir=PATH install helper binaries in PATH
1228 --sysconfdir=PATH install config in PATH/$qemu_suffix
1229 --localstatedir=PATH install local state in PATH (set at runtime on win32)
1230 --firmwarepath=PATH search PATH for firmware files
1231 --efi-aarch64=PATH PATH of efi file to use for aarch64 VMs.
1232 --with-suffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
1233 --with-pkgversion=VERS use specified string as sub-version of the package
1234 --without-default-features default all --enable-* options to "disabled"
1235 --without-default-devices do not include any device that is not needed to
1236 start the emulator (only use if you are including
1237 desired devices in configs/devices/)
1238 --with-devices-ARCH=NAME override default configs/devices
1239 --enable-debug enable common debug build options
1240 --enable-sanitizers enable default sanitizers
1241 --enable-tsan enable thread sanitizer
1242 --disable-werror disable compilation abort on warning
1243 --disable-stack-protector disable compiler-provided stack protection
1244 --audio-drv-list=LIST set audio drivers to try if -audiodev is not used
1245 --block-drv-whitelist=L Same as --block-drv-rw-whitelist=L
1246 --block-drv-rw-whitelist=L
1247 set block driver read-write whitelist
1248 (by default affects only QEMU, not tools like qemu-img)
1249 --block-drv-ro-whitelist=L
1250 set block driver read-only whitelist
1251 (by default affects only QEMU, not tools like qemu-img)
1252 --with-trace-file=NAME Full PATH,NAME of file to store traces
1253 Default:trace-<pid>
1254 --cpu=CPU Build for host CPU [$cpu]
1255 --with-coroutine=BACKEND coroutine backend. Supported options:
1256 ucontext, sigaltstack, windows
1257 --enable-gcov enable test coverage analysis with gcov
1258 --with-vss-sdk=SDK-path enable Windows VSS support in QEMU Guest Agent
1259 --with-win-sdk=SDK-path path to Windows Platform SDK (to build VSS .tlb)
1260 --tls-priority default TLS protocol/cipher priority string
1261 --enable-debug-stack-usage
1262 track the maximum stack usage of stacks created by qemu_alloc_stack
1263 --enable-plugins
1264 enable plugins via shared library loading
1265 --disable-containers don't use containers for cross-building
1266 --gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
1267 EOF
1268 meson_options_help
1269 cat << EOF
1270 system all system emulation targets
1271 user supported user emulation targets
1272 linux-user all linux usermode emulation targets
1273 bsd-user all BSD usermode emulation targets
1274 guest-agent build the QEMU Guest Agent
1275 pie Position Independent Executables
1276 modules modules support (non-Windows)
1277 module-upgrades try to load modules from alternate paths for upgrades
1278 debug-tcg TCG debugging (default is disabled)
1279 debug-info debugging information
1280 lto Enable Link-Time Optimization.
1281 safe-stack SafeStack Stack Smash Protection. Depends on
1282 clang/llvm >= 3.7 and requires coroutine backend ucontext.
1283 rdma Enable RDMA-based migration
1284 pvrdma Enable PVRDMA support
1285 vhost-net vhost-net kernel acceleration support
1286 vhost-vsock virtio sockets device support
1287 vhost-scsi vhost-scsi kernel target support
1288 vhost-crypto vhost-user-crypto backend support
1289 vhost-kernel vhost kernel backend support
1290 vhost-user vhost-user backend support
1291 vhost-vdpa vhost-vdpa kernel backend support
1292 coroutine-pool coroutine freelist (better performance)
1293 opengl opengl support
1294 tools build qemu-io, qemu-nbd and qemu-img tools
1295 gio libgio support
1296 slirp-smbd use smbd (at path --smbd=*) in slirp networking
1297
1298 NOTE: The object files are built at the place where configure is launched
1299 EOF
1300 exit 0
1301 fi
1302
1303 # Remove old dependency files to make sure that they get properly regenerated
1304 rm -f */config-devices.mak.d
1305
1306 if test -z "$python"
1307 then
1308 error_exit "Python not found. Use --python=/path/to/python"
1309 fi
1310 if ! has "$make"
1311 then
1312 error_exit "GNU make ($make) not found"
1313 fi
1314
1315 # Note that if the Python conditional here evaluates True we will exit
1316 # with status 1 which is a shell 'false' value.
1317 if ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then
1318 error_exit "Cannot use '$python', Python >= 3.6 is required." \
1319 "Use --python=/path/to/python to specify a supported Python."
1320 fi
1321
1322 # Preserve python version since some functionality is dependent on it
1323 python_version=$($python -c 'import sys; print("%d.%d.%d" % (sys.version_info[0], sys.version_info[1], sys.version_info[2]))' 2>/dev/null)
1324
1325 # Suppress writing compiled files
1326 python="$python -B"
1327
1328 if test -z "$meson"; then
1329 if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.59.3; then
1330 meson=meson
1331 elif test $git_submodules_action != 'ignore' ; then
1332 meson=git
1333 elif test -e "${source_path}/meson/meson.py" ; then
1334 meson=internal
1335 else
1336 if test "$explicit_python" = yes; then
1337 error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
1338 else
1339 error_exit "Meson not found. Use --meson=/path/to/meson"
1340 fi
1341 fi
1342 else
1343 # Meson uses its own Python interpreter to invoke other Python scripts,
1344 # but the user wants to use the one they specified with --python.
1345 #
1346 # We do not want to override the distro Python interpreter (and sometimes
1347 # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
1348 # just require --meson=git|internal together with --python.
1349 if test "$explicit_python" = yes; then
1350 case "$meson" in
1351 git | internal) ;;
1352 *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
1353 esac
1354 fi
1355 fi
1356
1357 if test "$meson" = git; then
1358 git_submodules="${git_submodules} meson"
1359 fi
1360
1361 case "$meson" in
1362 git | internal)
1363 meson="$python ${source_path}/meson/meson.py"
1364 ;;
1365 *) meson=$(command -v "$meson") ;;
1366 esac
1367
1368 # Probe for ninja
1369
1370 if test -z "$ninja"; then
1371 for c in ninja ninja-build samu; do
1372 if has $c; then
1373 ninja=$(command -v "$c")
1374 break
1375 fi
1376 done
1377 if test -z "$ninja"; then
1378 error_exit "Cannot find Ninja"
1379 fi
1380 fi
1381
1382 # Check that the C compiler works. Doing this here before testing
1383 # the host CPU ensures that we had a valid CC to autodetect the
1384 # $cpu var (and we should bail right here if that's not the case).
1385 # It also allows the help message to be printed without a CC.
1386 write_c_skeleton;
1387 if compile_object ; then
1388 : C compiler works ok
1389 else
1390 error_exit "\"$cc\" either does not exist or does not work"
1391 fi
1392 if ! compile_prog ; then
1393 error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
1394 fi
1395
1396 # Consult white-list to determine whether to enable werror
1397 # by default. Only enable by default for git builds
1398 if test -z "$werror" ; then
1399 if test "$git_submodules_action" != "ignore" && \
1400 { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
1401 werror="yes"
1402 else
1403 werror="no"
1404 fi
1405 fi
1406
1407 if test "$targetos" = "bogus"; then
1408 # Now that we know that we're not printing the help and that
1409 # the compiler works (so the results of the check_defines we used
1410 # to identify the OS are reliable), if we didn't recognize the
1411 # host OS we should stop now.
1412 error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1413 fi
1414
1415 # Check whether the compiler matches our minimum requirements:
1416 cat > $TMPC << EOF
1417 #if defined(__clang_major__) && defined(__clang_minor__)
1418 # ifdef __apple_build_version__
1419 # if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
1420 # error You need at least XCode Clang v10.0 to compile QEMU
1421 # endif
1422 # else
1423 # if __clang_major__ < 6 || (__clang_major__ == 6 && __clang_minor__ < 0)
1424 # error You need at least Clang v6.0 to compile QEMU
1425 # endif
1426 # endif
1427 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
1428 # if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
1429 # error You need at least GCC v7.4.0 to compile QEMU
1430 # endif
1431 #else
1432 # error You either need GCC or Clang to compiler QEMU
1433 #endif
1434 int main (void) { return 0; }
1435 EOF
1436 if ! compile_prog "" "" ; then
1437 error_exit "You need at least GCC v7.4 or Clang v6.0 (or XCode Clang v10.0)"
1438 fi
1439
1440 # Accumulate -Wfoo and -Wno-bar separately.
1441 # We will list all of the enable flags first, and the disable flags second.
1442 # Note that we do not add -Werror, because that would enable it for all
1443 # configure tests. If a configure test failed due to -Werror this would
1444 # just silently disable some features, so it's too error prone.
1445
1446 warn_flags=
1447 add_to warn_flags -Wold-style-declaration
1448 add_to warn_flags -Wold-style-definition
1449 add_to warn_flags -Wtype-limits
1450 add_to warn_flags -Wformat-security
1451 add_to warn_flags -Wformat-y2k
1452 add_to warn_flags -Winit-self
1453 add_to warn_flags -Wignored-qualifiers
1454 add_to warn_flags -Wempty-body
1455 add_to warn_flags -Wnested-externs
1456 add_to warn_flags -Wendif-labels
1457 add_to warn_flags -Wexpansion-to-defined
1458 add_to warn_flags -Wimplicit-fallthrough=2
1459
1460 nowarn_flags=
1461 add_to nowarn_flags -Wno-initializer-overrides
1462 add_to nowarn_flags -Wno-missing-include-dirs
1463 add_to nowarn_flags -Wno-shift-negative-value
1464 add_to nowarn_flags -Wno-string-plus-int
1465 add_to nowarn_flags -Wno-typedef-redefinition
1466 add_to nowarn_flags -Wno-tautological-type-limit-compare
1467 add_to nowarn_flags -Wno-psabi
1468
1469 gcc_flags="$warn_flags $nowarn_flags"
1470
1471 cc_has_warning_flag() {
1472 write_c_skeleton;
1473
1474 # Use the positive sense of the flag when testing for -Wno-wombat
1475 # support (gcc will happily accept the -Wno- form of unknown
1476 # warning options).
1477 optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
1478 compile_prog "-Werror $optflag" ""
1479 }
1480
1481 for flag in $gcc_flags; do
1482 if cc_has_warning_flag $flag ; then
1483 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1484 fi
1485 done
1486
1487 if test "$stack_protector" != "no"; then
1488 cat > $TMPC << EOF
1489 int main(int argc, char *argv[])
1490 {
1491 char arr[64], *p = arr, *c = argv[0];
1492 while (*c) {
1493 *p++ = *c++;
1494 }
1495 return 0;
1496 }
1497 EOF
1498 gcc_flags="-fstack-protector-strong -fstack-protector-all"
1499 sp_on=0
1500 for flag in $gcc_flags; do
1501 # We need to check both a compile and a link, since some compiler
1502 # setups fail only on a .c->.o compile and some only at link time
1503 if compile_object "-Werror $flag" &&
1504 compile_prog "-Werror $flag" ""; then
1505 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1506 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
1507 sp_on=1
1508 break
1509 fi
1510 done
1511 if test "$stack_protector" = yes; then
1512 if test $sp_on = 0; then
1513 error_exit "Stack protector not supported"
1514 fi
1515 fi
1516 fi
1517
1518 # Disable -Wmissing-braces on older compilers that warn even for
1519 # the "universal" C zero initializer {0}.
1520 cat > $TMPC << EOF
1521 struct {
1522 int a[2];
1523 } x = {0};
1524 EOF
1525 if compile_object "-Werror" "" ; then
1526 :
1527 else
1528 QEMU_CFLAGS="$QEMU_CFLAGS -Wno-missing-braces"
1529 fi
1530
1531 # Our module code doesn't support Windows
1532 if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
1533 error_exit "Modules are not available for Windows"
1534 fi
1535
1536 # module_upgrades is only reasonable if modules are enabled
1537 if test "$modules" = "no" && test "$module_upgrades" = "yes" ; then
1538 error_exit "Can't enable module-upgrades as Modules are not enabled"
1539 fi
1540
1541 # Static linking is not possible with plugins, modules or PIE
1542 if test "$static" = "yes" ; then
1543 if test "$modules" = "yes" ; then
1544 error_exit "static and modules are mutually incompatible"
1545 fi
1546 if test "$plugins" = "yes"; then
1547 error_exit "static and plugins are mutually incompatible"
1548 else
1549 plugins="no"
1550 fi
1551 fi
1552 test "$plugins" = "" && plugins=yes
1553
1554 cat > $TMPC << EOF
1555
1556 #ifdef __linux__
1557 # define THREAD __thread
1558 #else
1559 # define THREAD
1560 #endif
1561 static THREAD int tls_var;
1562 int main(void) { return tls_var; }
1563 EOF
1564
1565 # Check we support -fno-pie and -no-pie first; we will need the former for
1566 # building ROMs, and both for everything if --disable-pie is passed.
1567 if compile_prog "-Werror -fno-pie" "-no-pie"; then
1568 CFLAGS_NOPIE="-fno-pie"
1569 LDFLAGS_NOPIE="-no-pie"
1570 fi
1571
1572 if test "$static" = "yes"; then
1573 if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
1574 CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
1575 QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS"
1576 pie="yes"
1577 elif test "$pie" = "yes"; then
1578 error_exit "-static-pie not available due to missing toolchain support"
1579 else
1580 QEMU_LDFLAGS="-static $QEMU_LDFLAGS"
1581 pie="no"
1582 fi
1583 elif test "$pie" = "no"; then
1584 CONFIGURE_CFLAGS="$CFLAGS_NOPIE $CONFIGURE_CFLAGS"
1585 CONFIGURE_LDFLAGS="$LDFLAGS_NOPIE $CONFIGURE_LDFLAGS"
1586 elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
1587 CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
1588 CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
1589 pie="yes"
1590 elif test "$pie" = "yes"; then
1591 error_exit "PIE not available due to missing toolchain support"
1592 else
1593 echo "Disabling PIE due to missing toolchain support"
1594 pie="no"
1595 fi
1596
1597 # Detect support for PT_GNU_RELRO + DT_BIND_NOW.
1598 # The combination is known as "full relro", because .got.plt is read-only too.
1599 if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1600 QEMU_LDFLAGS="-Wl,-z,relro -Wl,-z,now $QEMU_LDFLAGS"
1601 fi
1602
1603 ##########################################
1604 # __sync_fetch_and_and requires at least -march=i486. Many toolchains
1605 # use i686 as default anyway, but for those that don't, an explicit
1606 # specification is necessary
1607
1608 if test "$cpu" = "i386"; then
1609 cat > $TMPC << EOF
1610 static int sfaa(int *ptr)
1611 {
1612 return __sync_fetch_and_and(ptr, 0);
1613 }
1614
1615 int main(void)
1616 {
1617 int val = 42;
1618 val = __sync_val_compare_and_swap(&val, 0, 1);
1619 sfaa(&val);
1620 return val;
1621 }
1622 EOF
1623 if ! compile_prog "" "" ; then
1624 QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
1625 fi
1626 fi
1627
1628 if test "$tcg" = "enabled"; then
1629 git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
1630 git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
1631 fi
1632
1633 if test -z "${target_list+xxx}" ; then
1634 default_targets=yes
1635 for target in $default_target_list; do
1636 target_list="$target_list $target"
1637 done
1638 target_list="${target_list# }"
1639 else
1640 default_targets=no
1641 target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1642 for target in $target_list; do
1643 # Check that we recognised the target name; this allows a more
1644 # friendly error message than if we let it fall through.
1645 case " $default_target_list " in
1646 *" $target "*)
1647 ;;
1648 *)
1649 error_exit "Unknown target name '$target'"
1650 ;;
1651 esac
1652 done
1653 fi
1654
1655 # see if system emulation was really requested
1656 case " $target_list " in
1657 *"-softmmu "*) softmmu=yes
1658 ;;
1659 *) softmmu=no
1660 ;;
1661 esac
1662
1663 feature_not_found() {
1664 feature=$1
1665 remedy=$2
1666
1667 error_exit "User requested feature $feature" \
1668 "configure was not able to find it." \
1669 "$remedy"
1670 }
1671
1672 # ---
1673 # big/little endian test
1674 cat > $TMPC << EOF
1675 #include <stdio.h>
1676 short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
1677 short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
1678 int main(int argc, char *argv[])
1679 {
1680 return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
1681 }
1682 EOF
1683
1684 if compile_prog ; then
1685 if strings -a $TMPE | grep -q BiGeNdIaN ; then
1686 bigendian="yes"
1687 elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
1688 bigendian="no"
1689 else
1690 echo big/little test failed
1691 exit 1
1692 fi
1693 else
1694 echo big/little test failed
1695 exit 1
1696 fi
1697
1698 ##########################################
1699 # system tools
1700 if test -z "$want_tools"; then
1701 if test "$softmmu" = "no"; then
1702 want_tools=no
1703 else
1704 want_tools=yes
1705 fi
1706 fi
1707
1708 #########################################
1709 # vhost interdependencies and host support
1710
1711 # vhost backends
1712 if test "$vhost_user" = "yes" && test "$linux" != "yes"; then
1713 error_exit "vhost-user is only available on Linux"
1714 fi
1715 test "$vhost_vdpa" = "" && vhost_vdpa=$linux
1716 if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
1717 error_exit "vhost-vdpa is only available on Linux"
1718 fi
1719 test "$vhost_kernel" = "" && vhost_kernel=$linux
1720 if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
1721 error_exit "vhost-kernel is only available on Linux"
1722 fi
1723
1724 # vhost-kernel devices
1725 test "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
1726 if test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
1727 error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
1728 fi
1729 test "$vhost_vsock" = "" && vhost_vsock=$vhost_kernel
1730 if test "$vhost_vsock" = "yes" && test "$vhost_kernel" != "yes"; then
1731 error_exit "--enable-vhost-vsock requires --enable-vhost-kernel"
1732 fi
1733
1734 # vhost-user backends
1735 test "$vhost_net_user" = "" && vhost_net_user=$vhost_user
1736 if test "$vhost_net_user" = "yes" && test "$vhost_user" = "no"; then
1737 error_exit "--enable-vhost-net-user requires --enable-vhost-user"
1738 fi
1739 test "$vhost_crypto" = "" && vhost_crypto=$vhost_user
1740 if test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
1741 error_exit "--enable-vhost-crypto requires --enable-vhost-user"
1742 fi
1743 test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
1744 if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
1745 error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
1746 fi
1747 #vhost-vdpa backends
1748 test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa
1749 if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then
1750 error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa"
1751 fi
1752
1753 # OR the vhost-kernel, vhost-vdpa and vhost-user values for simplicity
1754 if test "$vhost_net" = ""; then
1755 test "$vhost_net_user" = "yes" && vhost_net=yes
1756 test "$vhost_net_vdpa" = "yes" && vhost_net=yes
1757 test "$vhost_kernel" = "yes" && vhost_net=yes
1758 fi
1759
1760 ##########################################
1761 # pkg-config probe
1762
1763 if ! has "$pkg_config_exe"; then
1764 error_exit "pkg-config binary '$pkg_config_exe' not found"
1765 fi
1766
1767 ##########################################
1768 # xen probe
1769
1770 if test "$xen" != "disabled" ; then
1771 # Check whether Xen library path is specified via --extra-ldflags to avoid
1772 # overriding this setting with pkg-config output. If not, try pkg-config
1773 # to obtain all needed flags.
1774
1775 if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \
1776 $pkg_config --exists xencontrol ; then
1777 xen_ctrl_version="$(printf '%d%02d%02d' \
1778 $($pkg_config --modversion xencontrol | sed 's/\./ /g') )"
1779 xen=enabled
1780 xen_pc="xencontrol xenstore xenforeignmemory xengnttab"
1781 xen_pc="$xen_pc xenevtchn xendevicemodel"
1782 if $pkg_config --exists xentoolcore; then
1783 xen_pc="$xen_pc xentoolcore"
1784 fi
1785 xen_cflags="$($pkg_config --cflags $xen_pc)"
1786 xen_libs="$($pkg_config --libs $xen_pc)"
1787 else
1788
1789 xen_libs="-lxenstore -lxenctrl"
1790 xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
1791
1792 # First we test whether Xen headers and libraries are available.
1793 # If no, we are done and there is no Xen support.
1794 # If yes, more tests are run to detect the Xen version.
1795
1796 # Xen (any)
1797 cat > $TMPC <<EOF
1798 #include <xenctrl.h>
1799 int main(void) {
1800 return 0;
1801 }
1802 EOF
1803 if ! compile_prog "" "$xen_libs" ; then
1804 # Xen not found
1805 if test "$xen" = "enabled" ; then
1806 feature_not_found "xen" "Install xen devel"
1807 fi
1808 xen=disabled
1809
1810 # Xen unstable
1811 elif
1812 cat > $TMPC <<EOF &&
1813 #undef XC_WANT_COMPAT_DEVICEMODEL_API
1814 #define __XEN_TOOLS__
1815 #include <xendevicemodel.h>
1816 #include <xenforeignmemory.h>
1817 int main(void) {
1818 xendevicemodel_handle *xd;
1819 xenforeignmemory_handle *xfmem;
1820
1821 xd = xendevicemodel_open(0, 0);
1822 xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);
1823
1824 xfmem = xenforeignmemory_open(0, 0);
1825 xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);
1826
1827 return 0;
1828 }
1829 EOF
1830 compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
1831 then
1832 xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
1833 xen_ctrl_version=41100
1834 xen=enabled
1835 elif
1836 cat > $TMPC <<EOF &&
1837 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
1838 #include <xenforeignmemory.h>
1839 #include <xentoolcore.h>
1840 int main(void) {
1841 xenforeignmemory_handle *xfmem;
1842
1843 xfmem = xenforeignmemory_open(0, 0);
1844 xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
1845 xentoolcore_restrict_all(0);
1846
1847 return 0;
1848 }
1849 EOF
1850 compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs -lxentoolcore"
1851 then
1852 xen_stable_libs="-lxendevicemodel $xen_stable_libs -lxentoolcore"
1853 xen_ctrl_version=41000
1854 xen=enabled
1855 elif
1856 cat > $TMPC <<EOF &&
1857 #undef XC_WANT_COMPAT_DEVICEMODEL_API
1858 #define __XEN_TOOLS__
1859 #include <xendevicemodel.h>
1860 int main(void) {
1861 xendevicemodel_handle *xd;
1862
1863 xd = xendevicemodel_open(0, 0);
1864 xendevicemodel_close(xd);
1865
1866 return 0;
1867 }
1868 EOF
1869 compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs"
1870 then
1871 xen_stable_libs="-lxendevicemodel $xen_stable_libs"
1872 xen_ctrl_version=40900
1873 xen=enabled
1874 elif
1875 cat > $TMPC <<EOF &&
1876 /*
1877 * If we have stable libs the we don't want the libxc compat
1878 * layers, regardless of what CFLAGS we may have been given.
1879 *
1880 * Also, check if xengnttab_grant_copy_segment_t is defined and
1881 * grant copy operation is implemented.
1882 */
1883 #undef XC_WANT_COMPAT_EVTCHN_API
1884 #undef XC_WANT_COMPAT_GNTTAB_API
1885 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
1886 #include <xenctrl.h>
1887 #include <xenstore.h>
1888 #include <xenevtchn.h>
1889 #include <xengnttab.h>
1890 #include <xenforeignmemory.h>
1891 #include <stdint.h>
1892 #include <xen/hvm/hvm_info_table.h>
1893 #if !defined(HVM_MAX_VCPUS)
1894 # error HVM_MAX_VCPUS not defined
1895 #endif
1896 int main(void) {
1897 xc_interface *xc = NULL;
1898 xenforeignmemory_handle *xfmem;
1899 xenevtchn_handle *xe;
1900 xengnttab_handle *xg;
1901 xengnttab_grant_copy_segment_t* seg = NULL;
1902
1903 xs_daemon_open();
1904
1905 xc = xc_interface_open(0, 0, 0);
1906 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1907 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
1908 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
1909 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
1910
1911 xfmem = xenforeignmemory_open(0, 0);
1912 xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
1913
1914 xe = xenevtchn_open(0, 0);
1915 xenevtchn_fd(xe);
1916
1917 xg = xengnttab_open(0, 0);
1918 xengnttab_grant_copy(xg, 0, seg);
1919
1920 return 0;
1921 }
1922 EOF
1923 compile_prog "" "$xen_libs $xen_stable_libs"
1924 then
1925 xen_ctrl_version=40800
1926 xen=enabled
1927 elif
1928 cat > $TMPC <<EOF &&
1929 /*
1930 * If we have stable libs the we don't want the libxc compat
1931 * layers, regardless of what CFLAGS we may have been given.
1932 */
1933 #undef XC_WANT_COMPAT_EVTCHN_API
1934 #undef XC_WANT_COMPAT_GNTTAB_API
1935 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
1936 #include <xenctrl.h>
1937 #include <xenstore.h>
1938 #include <xenevtchn.h>
1939 #include <xengnttab.h>
1940 #include <xenforeignmemory.h>
1941 #include <stdint.h>
1942 #include <xen/hvm/hvm_info_table.h>
1943 #if !defined(HVM_MAX_VCPUS)
1944 # error HVM_MAX_VCPUS not defined
1945 #endif
1946 int main(void) {
1947 xc_interface *xc = NULL;
1948 xenforeignmemory_handle *xfmem;
1949 xenevtchn_handle *xe;
1950 xengnttab_handle *xg;
1951
1952 xs_daemon_open();
1953
1954 xc = xc_interface_open(0, 0, 0);
1955 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1956 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
1957 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
1958 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
1959
1960 xfmem = xenforeignmemory_open(0, 0);
1961 xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
1962
1963 xe = xenevtchn_open(0, 0);
1964 xenevtchn_fd(xe);
1965
1966 xg = xengnttab_open(0, 0);
1967 xengnttab_map_grant_ref(xg, 0, 0, 0);
1968
1969 return 0;
1970 }
1971 EOF
1972 compile_prog "" "$xen_libs $xen_stable_libs"
1973 then
1974 xen_ctrl_version=40701
1975 xen=enabled
1976
1977 # Xen 4.6
1978 elif
1979 cat > $TMPC <<EOF &&
1980 #include <xenctrl.h>
1981 #include <xenstore.h>
1982 #include <stdint.h>
1983 #include <xen/hvm/hvm_info_table.h>
1984 #if !defined(HVM_MAX_VCPUS)
1985 # error HVM_MAX_VCPUS not defined
1986 #endif
1987 int main(void) {
1988 xc_interface *xc;
1989 xs_daemon_open();
1990 xc = xc_interface_open(0, 0, 0);
1991 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
1992 xc_gnttab_open(NULL, 0);
1993 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
1994 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
1995 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
1996 xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
1997 return 0;
1998 }
1999 EOF
2000 compile_prog "" "$xen_libs"
2001 then
2002 xen_ctrl_version=40600
2003 xen=enabled
2004
2005 # Xen 4.5
2006 elif
2007 cat > $TMPC <<EOF &&
2008 #include <xenctrl.h>
2009 #include <xenstore.h>
2010 #include <stdint.h>
2011 #include <xen/hvm/hvm_info_table.h>
2012 #if !defined(HVM_MAX_VCPUS)
2013 # error HVM_MAX_VCPUS not defined
2014 #endif
2015 int main(void) {
2016 xc_interface *xc;
2017 xs_daemon_open();
2018 xc = xc_interface_open(0, 0, 0);
2019 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2020 xc_gnttab_open(NULL, 0);
2021 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2022 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2023 xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
2024 return 0;
2025 }
2026 EOF
2027 compile_prog "" "$xen_libs"
2028 then
2029 xen_ctrl_version=40500
2030 xen=enabled
2031
2032 elif
2033 cat > $TMPC <<EOF &&
2034 #include <xenctrl.h>
2035 #include <xenstore.h>
2036 #include <stdint.h>
2037 #include <xen/hvm/hvm_info_table.h>
2038 #if !defined(HVM_MAX_VCPUS)
2039 # error HVM_MAX_VCPUS not defined
2040 #endif
2041 int main(void) {
2042 xc_interface *xc;
2043 xs_daemon_open();
2044 xc = xc_interface_open(0, 0, 0);
2045 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2046 xc_gnttab_open(NULL, 0);
2047 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2048 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2049 return 0;
2050 }
2051 EOF
2052 compile_prog "" "$xen_libs"
2053 then
2054 xen_ctrl_version=40200
2055 xen=enabled
2056
2057 else
2058 if test "$xen" = "enabled" ; then
2059 feature_not_found "xen (unsupported version)" \
2060 "Install a supported xen (xen 4.2 or newer)"
2061 fi
2062 xen=disabled
2063 fi
2064
2065 if test "$xen" = enabled; then
2066 if test $xen_ctrl_version -ge 40701 ; then
2067 xen_libs="$xen_libs $xen_stable_libs "
2068 fi
2069 fi
2070 fi
2071 fi
2072
2073 ##########################################
2074 # RDMA needs OpenFabrics libraries
2075 if test "$rdma" != "no" ; then
2076 cat > $TMPC <<EOF
2077 #include <rdma/rdma_cma.h>
2078 int main(void) { return 0; }
2079 EOF
2080 rdma_libs="-lrdmacm -libverbs -libumad"
2081 if compile_prog "" "$rdma_libs" ; then
2082 rdma="yes"
2083 else
2084 if test "$rdma" = "yes" ; then
2085 error_exit \
2086 " OpenFabrics librdmacm/libibverbs/libibumad not present." \
2087 " Your options:" \
2088 " (1) Fast: Install infiniband packages (devel) from your distro." \
2089 " (2) Cleanest: Install libraries from www.openfabrics.org" \
2090 " (3) Also: Install softiwarp if you don't have RDMA hardware"
2091 fi
2092 rdma="no"
2093 fi
2094 fi
2095
2096 ##########################################
2097 # PVRDMA detection
2098
2099 cat > $TMPC <<EOF &&
2100 #include <sys/mman.h>
2101
2102 int
2103 main(void)
2104 {
2105 char buf = 0;
2106 void *addr = &buf;
2107 addr = mremap(addr, 0, 1, MREMAP_MAYMOVE | MREMAP_FIXED);
2108
2109 return 0;
2110 }
2111 EOF
2112
2113 if test "$rdma" = "yes" ; then
2114 case "$pvrdma" in
2115 "")
2116 if compile_prog "" ""; then
2117 pvrdma="yes"
2118 else
2119 pvrdma="no"
2120 fi
2121 ;;
2122 "yes")
2123 if ! compile_prog "" ""; then
2124 error_exit "PVRDMA is not supported since mremap is not implemented"
2125 fi
2126 pvrdma="yes"
2127 ;;
2128 "no")
2129 pvrdma="no"
2130 ;;
2131 esac
2132 else
2133 if test "$pvrdma" = "yes" ; then
2134 error_exit "PVRDMA requires rdma suppport"
2135 fi
2136 pvrdma="no"
2137 fi
2138
2139 # Let's see if enhanced reg_mr is supported
2140 if test "$pvrdma" = "yes" ; then
2141
2142 cat > $TMPC <<EOF &&
2143 #include <infiniband/verbs.h>
2144
2145 int
2146 main(void)
2147 {
2148 struct ibv_mr *mr;
2149 struct ibv_pd *pd = NULL;
2150 size_t length = 10;
2151 uint64_t iova = 0;
2152 int access = 0;
2153 void *addr = NULL;
2154
2155 mr = ibv_reg_mr_iova(pd, addr, length, iova, access);
2156
2157 ibv_dereg_mr(mr);
2158
2159 return 0;
2160 }
2161 EOF
2162 if ! compile_prog "" "-libverbs"; then
2163 QEMU_CFLAGS="$QEMU_CFLAGS -DLEGACY_RDMA_REG_MR"
2164 fi
2165 fi
2166
2167 ##########################################
2168 # glib support probe
2169
2170 glib_req_ver=2.56
2171 glib_modules=gthread-2.0
2172 if test "$modules" = yes; then
2173 glib_modules="$glib_modules gmodule-export-2.0"
2174 elif test "$plugins" = "yes"; then
2175 glib_modules="$glib_modules gmodule-no-export-2.0"
2176 fi
2177
2178 for i in $glib_modules; do
2179 if $pkg_config --atleast-version=$glib_req_ver $i; then
2180 glib_cflags=$($pkg_config --cflags $i)
2181 glib_libs=$($pkg_config --libs $i)
2182 else
2183 error_exit "glib-$glib_req_ver $i is required to compile QEMU"
2184 fi
2185 done
2186
2187 # This workaround is required due to a bug in pkg-config file for glib as it
2188 # doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
2189
2190 if test "$static" = yes && test "$mingw32" = yes; then
2191 glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
2192 fi
2193
2194 if ! test "$gio" = "no"; then
2195 pass=no
2196 if $pkg_config --atleast-version=$glib_req_ver gio-2.0; then
2197 gio_cflags=$($pkg_config --cflags gio-2.0)
2198 gio_libs=$($pkg_config --libs gio-2.0)
2199 gdbus_codegen=$($pkg_config --variable=gdbus_codegen gio-2.0)
2200 if ! has "$gdbus_codegen"; then
2201 gdbus_codegen=
2202 fi
2203 # Check that the libraries actually work -- Ubuntu 18.04 ships
2204 # with pkg-config --static --libs data for gio-2.0 that is missing
2205 # -lblkid and will give a link error.
2206 cat > $TMPC <<EOF
2207 #include <gio/gio.h>
2208 int main(void)
2209 {
2210 g_dbus_proxy_new_sync(0, 0, 0, 0, 0, 0, 0, 0);
2211 return 0;
2212 }
2213 EOF
2214 if compile_prog "$gio_cflags" "$gio_libs" ; then
2215 pass=yes
2216 else
2217 pass=no
2218 fi
2219
2220 if test "$pass" = "yes" &&
2221 $pkg_config --atleast-version=$glib_req_ver gio-unix-2.0; then
2222 gio_cflags="$gio_cflags $($pkg_config --cflags gio-unix-2.0)"
2223 gio_libs="$gio_libs $($pkg_config --libs gio-unix-2.0)"
2224 fi
2225 fi
2226
2227 if test "$pass" = "no"; then
2228 if test "$gio" = "yes"; then
2229 feature_not_found "gio" "Install libgio >= 2.0"
2230 else
2231 gio=no
2232 fi
2233 else
2234 gio=yes
2235 fi
2236 fi
2237
2238 # Sanity check that the current size_t matches the
2239 # size that glib thinks it should be. This catches
2240 # problems on multi-arch where people try to build
2241 # 32-bit QEMU while pointing at 64-bit glib headers
2242 cat > $TMPC <<EOF
2243 #include <glib.h>
2244 #include <unistd.h>
2245
2246 #define QEMU_BUILD_BUG_ON(x) \
2247 typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
2248
2249 int main(void) {
2250 QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
2251 return 0;
2252 }
2253 EOF
2254
2255 if ! compile_prog "$glib_cflags" "$glib_libs" ; then
2256 error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
2257 "You probably need to set PKG_CONFIG_LIBDIR"\
2258 "to point to the right pkg-config files for your"\
2259 "build target"
2260 fi
2261
2262 # Silence clang warnings triggered by glib < 2.57.2
2263 cat > $TMPC << EOF
2264 #include <glib.h>
2265 typedef struct Foo {
2266 int i;
2267 } Foo;
2268 static void foo_free(Foo *f)
2269 {
2270 g_free(f);
2271 }
2272 G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free);
2273 int main(void) { return 0; }
2274 EOF
2275 if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
2276 if cc_has_warning_flag "-Wno-unused-function"; then
2277 glib_cflags="$glib_cflags -Wno-unused-function"
2278 CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
2279 fi
2280 fi
2281
2282 ##########################################
2283 # SHA command probe for modules
2284 if test "$modules" = yes; then
2285 shacmd_probe="sha1sum sha1 shasum"
2286 for c in $shacmd_probe; do
2287 if has $c; then
2288 shacmd="$c"
2289 break
2290 fi
2291 done
2292 if test "$shacmd" = ""; then
2293 error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
2294 fi
2295 fi
2296
2297 ##########################################
2298 # fdt probe
2299
2300 case "$fdt" in
2301 auto | enabled | internal)
2302 # Simpler to always update submodule, even if not needed.
2303 git_submodules="${git_submodules} dtc"
2304 ;;
2305 esac
2306
2307 ##########################################
2308 # opengl probe (for sdl2, gtk)
2309
2310 if test "$opengl" != "no" ; then
2311 epoxy=no
2312 if $pkg_config epoxy; then
2313 cat > $TMPC << EOF
2314 #include <epoxy/egl.h>
2315 int main(void) { return 0; }
2316 EOF
2317 if compile_prog "" "" ; then
2318 epoxy=yes
2319 fi
2320 fi
2321
2322 if test "$epoxy" = "yes" ; then
2323 opengl_cflags="$($pkg_config --cflags epoxy)"
2324 opengl_libs="$($pkg_config --libs epoxy)"
2325 opengl=yes
2326 else
2327 if test "$opengl" = "yes" ; then
2328 feature_not_found "opengl" "Please install epoxy with EGL"
2329 fi
2330 opengl_cflags=""
2331 opengl_libs=""
2332 opengl=no
2333 fi
2334 fi
2335
2336 # check for usbfs
2337 have_usbfs=no
2338 if test "$linux_user" = "yes"; then
2339 cat > $TMPC << EOF
2340 #include <linux/usbdevice_fs.h>
2341
2342 #ifndef USBDEVFS_GET_CAPABILITIES
2343 #error "USBDEVFS_GET_CAPABILITIES undefined"
2344 #endif
2345
2346 #ifndef USBDEVFS_DISCONNECT_CLAIM
2347 #error "USBDEVFS_DISCONNECT_CLAIM undefined"
2348 #endif
2349
2350 int main(void)
2351 {
2352 return 0;
2353 }
2354 EOF
2355 if compile_prog "" ""; then
2356 have_usbfs=yes
2357 fi
2358 fi
2359
2360 ##########################################
2361 # check if we have VSS SDK headers for win
2362
2363 guest_agent_with_vss="no"
2364 if test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
2365 test "$vss_win32_sdk" != "no" ; then
2366 case "$vss_win32_sdk" in
2367 "") vss_win32_include="-isystem $source_path" ;;
2368 *\ *) # The SDK is installed in "Program Files" by default, but we cannot
2369 # handle path with spaces. So we symlink the headers into ".sdk/vss".
2370 vss_win32_include="-isystem $source_path/.sdk/vss"
2371 symlink "$vss_win32_sdk/inc" "$source_path/.sdk/vss/inc"
2372 ;;
2373 *) vss_win32_include="-isystem $vss_win32_sdk"
2374 esac
2375 cat > $TMPC << EOF
2376 #define __MIDL_user_allocate_free_DEFINED__
2377 #include <inc/win2003/vss.h>
2378 int main(void) { return VSS_CTX_BACKUP; }
2379 EOF
2380 if compile_prog "$vss_win32_include" "" ; then
2381 guest_agent_with_vss="yes"
2382 QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
2383 else
2384 if test "$vss_win32_sdk" != "" ; then
2385 echo "ERROR: Please download and install Microsoft VSS SDK:"
2386 echo "ERROR: http://www.microsoft.com/en-us/download/details.aspx?id=23490"
2387 echo "ERROR: On POSIX-systems, you can extract the SDK headers by:"
2388 echo "ERROR: scripts/extract-vsssdk-headers setup.exe"
2389 echo "ERROR: The headers are extracted in the directory \`inc'."
2390 feature_not_found "VSS support"
2391 fi
2392 fi
2393 fi
2394
2395 ##########################################
2396 # lookup Windows platform SDK (if not specified)
2397 # The SDK is needed only to build .tlb (type library) file of guest agent
2398 # VSS provider from the source. It is usually unnecessary because the
2399 # pre-compiled .tlb file is included.
2400
2401 if test "$mingw32" = "yes" && test "$guest_agent" != "no" && \
2402 test "$guest_agent_with_vss" = "yes" ; then
2403 if test -z "$win_sdk"; then
2404 programfiles="$PROGRAMFILES"
2405 test -n "$PROGRAMW6432" && programfiles="$PROGRAMW6432"
2406 if test -n "$programfiles"; then
2407 win_sdk=$(ls -d "$programfiles/Microsoft SDKs/Windows/v"* | tail -1) 2>/dev/null
2408 else
2409 feature_not_found "Windows SDK"
2410 fi
2411 elif test "$win_sdk" = "no"; then
2412 win_sdk=""
2413 fi
2414 fi
2415
2416 ##########################################
2417 # check if mingw environment provides a recent ntddscsi.h
2418 guest_agent_ntddscsi="no"
2419 if test "$mingw32" = "yes" && test "$guest_agent" != "no"; then
2420 cat > $TMPC << EOF
2421 #include <windows.h>
2422 #include <ntddscsi.h>
2423 int main(void) {
2424 #if !defined(IOCTL_SCSI_GET_ADDRESS)
2425 #error Missing required ioctl definitions
2426 #endif
2427 SCSI_ADDRESS addr = { .Lun = 0, .TargetId = 0, .PathId = 0 };
2428 return addr.Lun;
2429 }
2430 EOF
2431 if compile_prog "" "" ; then
2432 guest_agent_ntddscsi=yes
2433 fi
2434 fi
2435
2436 ##########################################
2437 # capstone
2438
2439 case "$capstone" in
2440 auto | enabled | internal)
2441 # Simpler to always update submodule, even if not needed.
2442 git_submodules="${git_submodules} capstone"
2443 ;;
2444 esac
2445
2446 ##########################################
2447 # check and set a backend for coroutine
2448
2449 # We prefer ucontext, but it's not always possible. The fallback
2450 # is sigcontext. On Windows the only valid backend is the Windows
2451 # specific one.
2452
2453 ucontext_works=no
2454 if test "$darwin" != "yes"; then
2455 cat > $TMPC << EOF
2456 #include <ucontext.h>
2457 #ifdef __stub_makecontext
2458 #error Ignoring glibc stub makecontext which will always fail
2459 #endif
2460 int main(void) { makecontext(0, 0, 0); return 0; }
2461 EOF
2462 if compile_prog "" "" ; then
2463 ucontext_works=yes
2464 fi
2465 fi
2466
2467 if test "$coroutine" = ""; then
2468 if test "$mingw32" = "yes"; then
2469 coroutine=win32
2470 elif test "$ucontext_works" = "yes"; then
2471 coroutine=ucontext
2472 else
2473 coroutine=sigaltstack
2474 fi
2475 else
2476 case $coroutine in
2477 windows)
2478 if test "$mingw32" != "yes"; then
2479 error_exit "'windows' coroutine backend only valid for Windows"
2480 fi
2481 # Unfortunately the user visible backend name doesn't match the
2482 # coroutine-*.c filename for this case, so we have to adjust it here.
2483 coroutine=win32
2484 ;;
2485 ucontext)
2486 if test "$ucontext_works" != "yes"; then
2487 feature_not_found "ucontext"
2488 fi
2489 ;;
2490 sigaltstack)
2491 if test "$mingw32" = "yes"; then
2492 error_exit "only the 'windows' coroutine backend is valid for Windows"
2493 fi
2494 ;;
2495 *)
2496 error_exit "unknown coroutine backend $coroutine"
2497 ;;
2498 esac
2499 fi
2500
2501 if test "$coroutine_pool" = ""; then
2502 coroutine_pool=yes
2503 fi
2504
2505 if test "$debug_stack_usage" = "yes"; then
2506 if test "$coroutine_pool" = "yes"; then
2507 echo "WARN: disabling coroutine pool for stack usage debugging"
2508 coroutine_pool=no
2509 fi
2510 fi
2511
2512 ##################################################
2513 # SafeStack
2514
2515
2516 if test "$safe_stack" = "yes"; then
2517 cat > $TMPC << EOF
2518 int main(int argc, char *argv[])
2519 {
2520 #if ! __has_feature(safe_stack)
2521 #error SafeStack Disabled
2522 #endif
2523 return 0;
2524 }
2525 EOF
2526 flag="-fsanitize=safe-stack"
2527 # Check that safe-stack is supported and enabled.
2528 if compile_prog "-Werror $flag" "$flag"; then
2529 # Flag needed both at compilation and at linking
2530 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2531 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
2532 else
2533 error_exit "SafeStack not supported by your compiler"
2534 fi
2535 if test "$coroutine" != "ucontext"; then
2536 error_exit "SafeStack is only supported by the coroutine backend ucontext"
2537 fi
2538 else
2539 cat > $TMPC << EOF
2540 int main(int argc, char *argv[])
2541 {
2542 #if defined(__has_feature)
2543 #if __has_feature(safe_stack)
2544 #error SafeStack Enabled
2545 #endif
2546 #endif
2547 return 0;
2548 }
2549 EOF
2550 if test "$safe_stack" = "no"; then
2551 # Make sure that safe-stack is disabled
2552 if ! compile_prog "-Werror" ""; then
2553 # SafeStack was already enabled, try to explicitly remove the feature
2554 flag="-fno-sanitize=safe-stack"
2555 if ! compile_prog "-Werror $flag" "$flag"; then
2556 error_exit "Configure cannot disable SafeStack"
2557 fi
2558 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
2559 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
2560 fi
2561 else # "$safe_stack" = ""
2562 # Set safe_stack to yes or no based on pre-existing flags
2563 if compile_prog "-Werror" ""; then
2564 safe_stack="no"
2565 else
2566 safe_stack="yes"
2567 if test "$coroutine" != "ucontext"; then
2568 error_exit "SafeStack is only supported by the coroutine backend ucontext"
2569 fi
2570 fi
2571 fi
2572 fi
2573
2574 ########################################
2575 # check if __[u]int128_t is usable.
2576
2577 int128=no
2578 cat > $TMPC << EOF
2579 __int128_t a;
2580 __uint128_t b;
2581 int main (void) {
2582 a = a + b;
2583 b = a * b;
2584 a = a * a;
2585 return 0;
2586 }
2587 EOF
2588 if compile_prog "" "" ; then
2589 int128=yes
2590 fi
2591
2592 #########################################
2593 # See if 128-bit atomic operations are supported.
2594
2595 atomic128=no
2596 if test "$int128" = "yes"; then
2597 cat > $TMPC << EOF
2598 int main(void)
2599 {
2600 unsigned __int128 x = 0, y = 0;
2601 y = __atomic_load(&x, 0);
2602 __atomic_store(&x, y, 0);
2603 __atomic_compare_exchange(&x, &y, x, 0, 0, 0);
2604 return 0;
2605 }
2606 EOF
2607 if compile_prog "" "" ; then
2608 atomic128=yes
2609 fi
2610 fi
2611
2612 cmpxchg128=no
2613 if test "$int128" = yes && test "$atomic128" = no; then
2614 cat > $TMPC << EOF
2615 int main(void)
2616 {
2617 unsigned __int128 x = 0, y = 0;
2618 __sync_val_compare_and_swap_16(&x, y, x);
2619 return 0;
2620 }
2621 EOF
2622 if compile_prog "" "" ; then
2623 cmpxchg128=yes
2624 fi
2625 fi
2626
2627 ########################################
2628 # check if ccache is interfering with
2629 # semantic analysis of macros
2630
2631 unset CCACHE_CPP2
2632 ccache_cpp2=no
2633 cat > $TMPC << EOF
2634 static const int Z = 1;
2635 #define fn() ({ Z; })
2636 #define TAUT(X) ((X) == Z)
2637 #define PAREN(X, Y) (X == Y)
2638 #define ID(X) (X)
2639 int main(int argc, char *argv[])
2640 {
2641 int x = 0, y = 0;
2642 x = ID(x);
2643 x = fn();
2644 fn();
2645 if (PAREN(x, y)) return 0;
2646 if (TAUT(Z)) return 0;
2647 return 0;
2648 }
2649 EOF
2650
2651 if ! compile_object "-Werror"; then
2652 ccache_cpp2=yes
2653 fi
2654
2655 #################################################
2656 # clang does not support glibc + FORTIFY_SOURCE.
2657
2658 if test "$fortify_source" != "no"; then
2659 if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
2660 fortify_source="no";
2661 elif test -n "$cxx" && has $cxx &&
2662 echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
2663 fortify_source="no";
2664 else
2665 fortify_source="yes"
2666 fi
2667 fi
2668
2669 ##########################################
2670 # checks for sanitizers
2671
2672 have_asan=no
2673 have_ubsan=no
2674 have_asan_iface_h=no
2675 have_asan_iface_fiber=no
2676
2677 if test "$sanitizers" = "yes" ; then
2678 write_c_skeleton
2679 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
2680 have_asan=yes
2681 fi
2682
2683 # we could use a simple skeleton for flags checks, but this also
2684 # detect the static linking issue of ubsan, see also:
2685 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
2686 cat > $TMPC << EOF
2687 #include <stdlib.h>
2688 int main(void) {
2689 void *tmp = malloc(10);
2690 if (tmp != NULL) {
2691 return *(int *)(tmp + 2);
2692 }
2693 return 1;
2694 }
2695 EOF
2696 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
2697 have_ubsan=yes
2698 fi
2699
2700 if check_include "sanitizer/asan_interface.h" ; then
2701 have_asan_iface_h=yes
2702 fi
2703
2704 cat > $TMPC << EOF
2705 #include <sanitizer/asan_interface.h>
2706 int main(void) {
2707 __sanitizer_start_switch_fiber(0, 0, 0);
2708 return 0;
2709 }
2710 EOF
2711 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
2712 have_asan_iface_fiber=yes
2713 fi
2714 fi
2715
2716 # Thread sanitizer is, for now, much noisier than the other sanitizers;
2717 # keep it separate until that is not the case.
2718 if test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
2719 error_exit "TSAN is not supported with other sanitiziers."
2720 fi
2721 have_tsan=no
2722 have_tsan_iface_fiber=no
2723 if test "$tsan" = "yes" ; then
2724 write_c_skeleton
2725 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
2726 have_tsan=yes
2727 fi
2728 cat > $TMPC << EOF
2729 #include <sanitizer/tsan_interface.h>
2730 int main(void) {
2731 __tsan_create_fiber(0);
2732 return 0;
2733 }
2734 EOF
2735 if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
2736 have_tsan_iface_fiber=yes
2737 fi
2738 fi
2739
2740 ##########################################
2741 # check for slirp
2742
2743 case "$slirp" in
2744 auto | enabled | internal)
2745 # Simpler to always update submodule, even if not needed.
2746 git_submodules="${git_submodules} slirp"
2747 ;;
2748 esac
2749
2750 # Check for slirp smbd dupport
2751 : ${smbd=${SMBD-/usr/sbin/smbd}}
2752 if test "$slirp_smbd" != "no" ; then
2753 if test "$mingw32" = "yes" ; then
2754 if test "$slirp_smbd" = "yes" ; then
2755 error_exit "Host smbd not supported on this platform."
2756 fi
2757 slirp_smbd=no
2758 else
2759 slirp_smbd=yes
2760 fi
2761 fi
2762
2763 ##########################################
2764 # check for usable __NR_keyctl syscall
2765
2766 if test "$linux" = "yes" ; then
2767
2768 have_keyring=no
2769 cat > $TMPC << EOF
2770 #include <errno.h>
2771 #include <asm/unistd.h>
2772 #include <linux/keyctl.h>
2773 #include <unistd.h>
2774 int main(void) {
2775 return syscall(__NR_keyctl, KEYCTL_READ, 0, NULL, NULL, 0);
2776 }
2777 EOF
2778 if compile_prog "" "" ; then
2779 have_keyring=yes
2780 fi
2781 fi
2782 if test "$secret_keyring" != "no"
2783 then
2784 if test "$have_keyring" = "yes"
2785 then
2786 secret_keyring=yes
2787 else
2788 if test "$secret_keyring" = "yes"
2789 then
2790 error_exit "syscall __NR_keyctl requested, \
2791 but not implemented on your system"
2792 else
2793 secret_keyring=no
2794 fi
2795 fi
2796 fi
2797
2798 ##########################################
2799 # End of CC checks
2800 # After here, no more $cc or $ld runs
2801
2802 write_c_skeleton
2803
2804 if test "$gcov" = "yes" ; then
2805 :
2806 elif test "$fortify_source" = "yes" ; then
2807 QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
2808 debug=no
2809 fi
2810
2811 case "$ARCH" in
2812 alpha)
2813 # Ensure there's only a single GP
2814 QEMU_CFLAGS="-msmall-data $QEMU_CFLAGS"
2815 ;;
2816 esac
2817
2818 if test "$have_asan" = "yes"; then
2819 QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
2820 QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
2821 if test "$have_asan_iface_h" = "no" ; then
2822 echo "ASAN build enabled, but ASAN header missing." \
2823 "Without code annotation, the report may be inferior."
2824 elif test "$have_asan_iface_fiber" = "no" ; then
2825 echo "ASAN build enabled, but ASAN header is too old." \
2826 "Without code annotation, the report may be inferior."
2827 fi
2828 fi
2829 if test "$have_tsan" = "yes" ; then
2830 if test "$have_tsan_iface_fiber" = "yes" ; then
2831 QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
2832 QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
2833 else
2834 error_exit "Cannot enable TSAN due to missing fiber annotation interface."
2835 fi
2836 elif test "$tsan" = "yes" ; then
2837 error_exit "Cannot enable TSAN due to missing sanitize thread interface."
2838 fi
2839 if test "$have_ubsan" = "yes"; then
2840 QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
2841 QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
2842 fi
2843
2844 ##########################################
2845
2846 # Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
2847 if test "$solaris" = "no" && test "$tsan" = "no"; then
2848 if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
2849 QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
2850 fi
2851 fi
2852
2853 # Use ASLR, no-SEH and DEP if available
2854 if test "$mingw32" = "yes" ; then
2855 flags="--no-seh --nxcompat"
2856
2857 # Disable ASLR for debug builds to allow debugging with gdb
2858 if test "$debug" = "no" ; then
2859 flags="--dynamicbase $flags"
2860 fi
2861
2862 for flag in $flags; do
2863 if ld_has $flag ; then
2864 QEMU_LDFLAGS="-Wl,$flag $QEMU_LDFLAGS"
2865 fi
2866 done
2867 fi
2868
2869 # Probe for guest agent support/options
2870
2871 if [ "$guest_agent" != "no" ]; then
2872 if [ "$softmmu" = no -a "$want_tools" = no ] ; then
2873 guest_agent=no
2874 elif [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" -o "$mingw32" = "yes" ] ; then
2875 guest_agent=yes
2876 elif [ "$guest_agent" != yes ]; then
2877 guest_agent=no
2878 else
2879 error_exit "Guest agent is not supported on this platform"
2880 fi
2881 fi
2882
2883 # Guest agent Windows MSI package
2884
2885 if test "$QEMU_GA_MANUFACTURER" = ""; then
2886 QEMU_GA_MANUFACTURER=QEMU
2887 fi
2888 if test "$QEMU_GA_DISTRO" = ""; then
2889 QEMU_GA_DISTRO=Linux
2890 fi
2891 if test "$QEMU_GA_VERSION" = ""; then
2892 QEMU_GA_VERSION=$(cat $source_path/VERSION)
2893 fi
2894
2895 QEMU_GA_MSI_MINGW_DLL_PATH="$($pkg_config --variable=prefix glib-2.0)/bin"
2896
2897 # Mac OS X ships with a broken assembler
2898 roms=
2899 if { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \
2900 test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
2901 test "$targetos" != "haiku" && test "$softmmu" = yes ; then
2902 # Different host OS linkers have different ideas about the name of the ELF
2903 # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
2904 # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
2905 for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
2906 if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
2907 ld_i386_emulation="$emu"
2908 roms="optionrom"
2909 break
2910 fi
2911 done
2912 fi
2913
2914 # Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
2915 # or -march=z10 (which is the lowest architecture level that Clang supports)
2916 if test "$cpu" = "s390x" ; then
2917 write_c_skeleton
2918 compile_prog "-march=z900" ""
2919 has_z900=$?
2920 if [ $has_z900 = 0 ] || compile_object "-march=z10 -msoft-float -Werror"; then
2921 if [ $has_z900 != 0 ]; then
2922 echo "WARNING: Your compiler does not support the z900!"
2923 echo " The s390-ccw bios will only work with guest CPUs >= z10."
2924 fi
2925 roms="$roms s390-ccw"
2926 # SLOF is required for building the s390-ccw firmware on s390x,
2927 # since it is using the libnet code from SLOF for network booting.
2928 git_submodules="${git_submodules} roms/SLOF"
2929 fi
2930 fi
2931
2932 # Check that the C++ compiler exists and works with the C compiler.
2933 # All the QEMU_CXXFLAGS are based on QEMU_CFLAGS. Keep this at the end to don't miss any other that could be added.
2934 if has $cxx; then
2935 cat > $TMPC <<EOF
2936 int c_function(void);
2937 int main(void) { return c_function(); }
2938 EOF
2939
2940 compile_object
2941
2942 cat > $TMPCXX <<EOF
2943 extern "C" {
2944 int c_function(void);
2945 }
2946 int c_function(void) { return 42; }
2947 EOF
2948
2949 update_cxxflags
2950
2951 if do_cxx $CXXFLAGS $EXTRA_CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
2952 # C++ compiler $cxx works ok with C compiler $cc
2953 :
2954 else
2955 echo "C++ compiler $cxx does not work with C compiler $cc"
2956 echo "Disabling C++ specific optional code"
2957 cxx=
2958 fi
2959 else
2960 echo "No C++ compiler available; disabling C++ specific optional code"
2961 cxx=
2962 fi
2963
2964 if !(GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
2965 exit 1
2966 fi
2967
2968 config_host_mak="config-host.mak"
2969
2970 echo "# Automatically generated by configure - do not modify" > $config_host_mak
2971 echo >> $config_host_mak
2972
2973 echo all: >> $config_host_mak
2974 echo "GIT=$git" >> $config_host_mak
2975 echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
2976 echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
2977
2978 if test "$debug_tcg" = "yes" ; then
2979 echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
2980 fi
2981 if test "$mingw32" = "yes" ; then
2982 echo "CONFIG_WIN32=y" >> $config_host_mak
2983 if test "$guest_agent_with_vss" = "yes" ; then
2984 echo "CONFIG_QGA_VSS=y" >> $config_host_mak
2985 echo "WIN_SDK=\"$win_sdk\"" >> $config_host_mak
2986 fi
2987 if test "$guest_agent_ntddscsi" = "yes" ; then
2988 echo "CONFIG_QGA_NTDDSCSI=y" >> $config_host_mak
2989 fi
2990 echo "QEMU_GA_MSI_MINGW_DLL_PATH=${QEMU_GA_MSI_MINGW_DLL_PATH}" >> $config_host_mak
2991 echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
2992 echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
2993 echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
2994 else
2995 echo "CONFIG_POSIX=y" >> $config_host_mak
2996 fi
2997
2998 if test "$linux" = "yes" ; then
2999 echo "CONFIG_LINUX=y" >> $config_host_mak
3000 fi
3001
3002 if test "$darwin" = "yes" ; then
3003 echo "CONFIG_DARWIN=y" >> $config_host_mak
3004 fi
3005
3006 if test "$solaris" = "yes" ; then
3007 echo "CONFIG_SOLARIS=y" >> $config_host_mak
3008 fi
3009 if test "$static" = "yes" ; then
3010 echo "CONFIG_STATIC=y" >> $config_host_mak
3011 fi
3012 if test "$want_tools" = "yes" ; then
3013 echo "CONFIG_TOOLS=y" >> $config_host_mak
3014 fi
3015 if test "$guest_agent" = "yes" ; then
3016 echo "CONFIG_GUEST_AGENT=y" >> $config_host_mak
3017 fi
3018 if test "$slirp_smbd" = "yes" ; then
3019 echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak
3020 echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
3021 fi
3022 echo "CONFIG_BDRV_RW_WHITELIST=$block_drv_rw_whitelist" >> $config_host_mak
3023 echo "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
3024 qemu_version=$(head $source_path/VERSION)
3025 echo "PKGVERSION=$pkgversion" >>$config_host_mak
3026 echo "SRC_PATH=$source_path" >> $config_host_mak
3027 echo "TARGET_DIRS=$target_list" >> $config_host_mak
3028 if test "$modules" = "yes"; then
3029 # $shacmd can generate a hash started with digit, which the compiler doesn't
3030 # like as an symbol. So prefix it with an underscore
3031 echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
3032 echo "CONFIG_MODULES=y" >> $config_host_mak
3033 fi
3034 if test "$module_upgrades" = "yes"; then
3035 echo "CONFIG_MODULE_UPGRADES=y" >> $config_host_mak
3036 fi
3037 if test "$have_usbfs" = "yes" ; then
3038 echo "CONFIG_USBFS=y" >> $config_host_mak
3039 fi
3040 if test "$gio" = "yes" ; then
3041 echo "CONFIG_GIO=y" >> $config_host_mak
3042 echo "GIO_CFLAGS=$gio_cflags" >> $config_host_mak
3043 echo "GIO_LIBS=$gio_libs" >> $config_host_mak
3044 fi
3045 if test "$gdbus_codegen" != "" ; then
3046 echo "GDBUS_CODEGEN=$gdbus_codegen" >> $config_host_mak
3047 fi
3048 echo "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak
3049
3050 if test "$xen" = "enabled" ; then
3051 echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
3052 echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
3053 echo "XEN_CFLAGS=$xen_cflags" >> $config_host_mak
3054 echo "XEN_LIBS=$xen_libs" >> $config_host_mak
3055 fi
3056 if test "$vhost_scsi" = "yes" ; then
3057 echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
3058 fi
3059 if test "$vhost_net" = "yes" ; then
3060 echo "CONFIG_VHOST_NET=y" >> $config_host_mak
3061 fi
3062 if test "$vhost_net_user" = "yes" ; then
3063 echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak
3064 fi
3065 if test "$vhost_net_vdpa" = "yes" ; then
3066 echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak
3067 fi
3068 if test "$vhost_crypto" = "yes" ; then
3069 echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
3070 fi
3071 if test "$vhost_vsock" = "yes" ; then
3072 echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
3073 if test "$vhost_user" = "yes" ; then
3074 echo "CONFIG_VHOST_USER_VSOCK=y" >> $config_host_mak
3075 fi
3076 fi
3077 if test "$vhost_kernel" = "yes" ; then
3078 echo "CONFIG_VHOST_KERNEL=y" >> $config_host_mak
3079 fi
3080 if test "$vhost_user" = "yes" ; then
3081 echo "CONFIG_VHOST_USER=y" >> $config_host_mak
3082 fi
3083 if test "$vhost_vdpa" = "yes" ; then
3084 echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
3085 fi
3086 if test "$vhost_user_fs" = "yes" ; then
3087 echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak
3088 fi
3089 if test "$tcg" = "enabled" -a "$tcg_interpreter" = "true" ; then
3090 echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
3091 fi
3092
3093 if test "$opengl" = "yes" ; then
3094 echo "CONFIG_OPENGL=y" >> $config_host_mak
3095 echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
3096 echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
3097 fi
3098
3099 # XXX: suppress that
3100 if [ "$bsd" = "yes" ] ; then
3101 echo "CONFIG_BSD=y" >> $config_host_mak
3102 fi
3103
3104 echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
3105 if test "$coroutine_pool" = "yes" ; then
3106 echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
3107 else
3108 echo "CONFIG_COROUTINE_POOL=0" >> $config_host_mak
3109 fi
3110
3111 if test "$debug_stack_usage" = "yes" ; then
3112 echo "CONFIG_DEBUG_STACK_USAGE=y" >> $config_host_mak
3113 fi
3114
3115 if test "$have_asan_iface_fiber" = "yes" ; then
3116 echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
3117 fi
3118
3119 if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
3120 echo "CONFIG_TSAN=y" >> $config_host_mak
3121 fi
3122
3123 if test "$int128" = "yes" ; then
3124 echo "CONFIG_INT128=y" >> $config_host_mak
3125 fi
3126
3127 if test "$atomic128" = "yes" ; then
3128 echo "CONFIG_ATOMIC128=y" >> $config_host_mak
3129 fi
3130
3131 if test "$cmpxchg128" = "yes" ; then
3132 echo "CONFIG_CMPXCHG128=y" >> $config_host_mak
3133 fi
3134
3135 if test "$rdma" = "yes" ; then
3136 echo "CONFIG_RDMA=y" >> $config_host_mak
3137 echo "RDMA_LIBS=$rdma_libs" >> $config_host_mak
3138 fi
3139
3140 if test "$pvrdma" = "yes" ; then
3141 echo "CONFIG_PVRDMA=y" >> $config_host_mak
3142 fi
3143
3144 if test "$plugins" = "yes" ; then
3145 echo "CONFIG_PLUGIN=y" >> $config_host_mak
3146 fi
3147
3148 if test -n "$gdb_bin"; then
3149 gdb_version=$($gdb_bin --version | head -n 1)
3150 if version_ge ${gdb_version##* } 9.1; then
3151 echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
3152 fi
3153 fi
3154
3155 if test "$secret_keyring" = "yes" ; then
3156 echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak
3157 fi
3158
3159 echo "ROMS=$roms" >> $config_host_mak
3160 echo "MAKE=$make" >> $config_host_mak
3161 echo "PYTHON=$python" >> $config_host_mak
3162 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
3163 echo "MESON=$meson" >> $config_host_mak
3164 echo "NINJA=$ninja" >> $config_host_mak
3165 echo "CC=$cc" >> $config_host_mak
3166 echo "HOST_CC=$host_cc" >> $config_host_mak
3167 if $iasl -h > /dev/null 2>&1; then
3168 echo "CONFIG_IASL=$iasl" >> $config_host_mak
3169 fi
3170 echo "AR=$ar" >> $config_host_mak
3171 echo "AS=$as" >> $config_host_mak
3172 echo "CCAS=$ccas" >> $config_host_mak
3173 echo "CPP=$cpp" >> $config_host_mak
3174 echo "OBJCOPY=$objcopy" >> $config_host_mak
3175 echo "LD=$ld" >> $config_host_mak
3176 echo "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
3177 echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
3178 echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
3179 echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
3180 echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
3181 echo "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak
3182 echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
3183 echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
3184 echo "STRIP=$strip" >> $config_host_mak
3185 echo "EXESUF=$EXESUF" >> $config_host_mak
3186
3187 # use included Linux headers
3188 if test "$linux" = "yes" ; then
3189 mkdir -p linux-headers
3190 case "$cpu" in
3191 i386|x86_64)
3192 linux_arch=x86
3193 ;;
3194 ppc|ppc64)
3195 linux_arch=powerpc
3196 ;;
3197 s390x)
3198 linux_arch=s390
3199 ;;
3200 aarch64)
3201 linux_arch=arm64
3202 ;;
3203 loongarch*)
3204 linux_arch=loongarch
3205 ;;
3206 mips64)
3207 linux_arch=mips
3208 ;;
3209 *)
3210 # For most CPUs the kernel architecture name and QEMU CPU name match.
3211 linux_arch="$cpu"
3212 ;;
3213 esac
3214 # For non-KVM architectures we will not have asm headers
3215 if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
3216 symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
3217 fi
3218 fi
3219
3220 for target in $target_list; do
3221 target_dir="$target"
3222 target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
3223 mkdir -p $target_dir
3224 case $target in
3225 *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
3226 *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
3227 esac
3228 done
3229
3230 echo "CONFIG_QEMU_INTERP_PREFIX=$interp_prefix" | sed 's/%M/@0@/' >> $config_host_mak
3231 if test "$default_targets" = "yes"; then
3232 echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
3233 fi
3234
3235 if test "$ccache_cpp2" = "yes"; then
3236 echo "export CCACHE_CPP2=y" >> $config_host_mak
3237 fi
3238
3239 if test "$safe_stack" = "yes"; then
3240 echo "CONFIG_SAFESTACK=y" >> $config_host_mak
3241 fi
3242
3243 # If we're using a separate build tree, set it up now.
3244 # LINKS are things to symlink back into the source tree
3245 # (these can be both files and directories).
3246 # Caution: do not add files or directories here using wildcards. This
3247 # will result in problems later if a new file matching the wildcard is
3248 # added to the source tree -- nothing will cause configure to be rerun
3249 # so the build tree will be missing the link back to the new file, and
3250 # tests might fail. Prefer to keep the relevant files in their own
3251 # directory and symlink the directory instead.
3252 LINKS="Makefile"
3253 LINKS="$LINKS tests/tcg/Makefile.target"
3254 LINKS="$LINKS pc-bios/optionrom/Makefile"
3255 LINKS="$LINKS pc-bios/s390-ccw/Makefile"
3256 LINKS="$LINKS roms/seabios/Makefile"
3257 LINKS="$LINKS pc-bios/qemu-icon.bmp"
3258 LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
3259 LINKS="$LINKS tests/avocado tests/data"
3260 LINKS="$LINKS tests/qemu-iotests/check"
3261 LINKS="$LINKS python"
3262 LINKS="$LINKS contrib/plugins/Makefile "
3263 for bios_file in \
3264 $source_path/pc-bios/*.bin \
3265 $source_path/pc-bios/*.elf \
3266 $source_path/pc-bios/*.lid \
3267 $source_path/pc-bios/*.rom \
3268 $source_path/pc-bios/*.dtb \
3269 $source_path/pc-bios/*.img \
3270 $source_path/pc-bios/openbios-* \
3271 $source_path/pc-bios/u-boot.* \
3272 $source_path/pc-bios/palcode-* \
3273 $source_path/pc-bios/qemu_vga.ndrv
3274
3275 do
3276 LINKS="$LINKS pc-bios/$(basename $bios_file)"
3277 done
3278 for f in $LINKS ; do
3279 if [ -e "$source_path/$f" ]; then
3280 mkdir -p `dirname ./$f`
3281 symlink "$source_path/$f" "$f"
3282 fi
3283 done
3284
3285 (for i in $cross_cc_vars; do
3286 export $i
3287 done
3288 export target_list source_path use_containers cpu
3289 $source_path/tests/tcg/configure.sh)
3290
3291 # temporary config to build submodules
3292 if test -f $source_path/roms/seabios/Makefile; then
3293 for rom in seabios; do
3294 config_mak=roms/$rom/config.mak
3295 echo "# Automatically generated by configure - do not modify" > $config_mak
3296 echo "SRC_PATH=$source_path/roms/$rom" >> $config_mak
3297 echo "AS=$as" >> $config_mak
3298 echo "CCAS=$ccas" >> $config_mak
3299 echo "CC=$cc" >> $config_mak
3300 echo "BCC=bcc" >> $config_mak
3301 echo "CPP=$cpp" >> $config_mak
3302 echo "OBJCOPY=objcopy" >> $config_mak
3303 echo "IASL=$iasl" >> $config_mak
3304 echo "LD=$ld" >> $config_mak
3305 echo "RANLIB=$ranlib" >> $config_mak
3306 done
3307 fi
3308
3309 config_mak=pc-bios/optionrom/config.mak
3310 echo "# Automatically generated by configure - do not modify" > $config_mak
3311 echo "TOPSRC_DIR=$source_path" >> $config_mak
3312
3313 if test "$skip_meson" = no; then
3314 cross="config-meson.cross.new"
3315 meson_quote() {
3316 test $# = 0 && return
3317 echo "'$(echo $* | sed "s/ /','/g")'"
3318 }
3319
3320 echo "# Automatically generated by configure - do not modify" > $cross
3321 echo "[properties]" >> $cross
3322
3323 # unroll any custom device configs
3324 for a in $device_archs; do
3325 eval "c=\$devices_${a}"
3326 echo "${a}-softmmu = '$c'" >> $cross
3327 done
3328
3329 test -z "$cxx" && echo "link_language = 'c'" >> $cross
3330 echo "[built-in options]" >> $cross
3331 echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
3332 echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
3333 echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
3334 echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
3335 echo "[binaries]" >> $cross
3336 echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
3337 test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
3338 test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
3339 echo "ar = [$(meson_quote $ar)]" >> $cross
3340 echo "nm = [$(meson_quote $nm)]" >> $cross
3341 echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
3342 echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
3343 if has $sdl2_config; then
3344 echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
3345 fi
3346 echo "strip = [$(meson_quote $strip)]" >> $cross
3347 echo "windres = [$(meson_quote $windres)]" >> $cross
3348 if test "$cross_compile" = "yes"; then
3349 cross_arg="--cross-file config-meson.cross"
3350 echo "[host_machine]" >> $cross
3351 echo "system = '$targetos'" >> $cross
3352 case "$cpu" in
3353 i386)
3354 echo "cpu_family = 'x86'" >> $cross
3355 ;;
3356 *)
3357 echo "cpu_family = '$cpu'" >> $cross
3358 ;;
3359 esac
3360 echo "cpu = '$cpu'" >> $cross
3361 if test "$bigendian" = "yes" ; then
3362 echo "endian = 'big'" >> $cross
3363 else
3364 echo "endian = 'little'" >> $cross
3365 fi
3366 else
3367 cross_arg="--native-file config-meson.cross"
3368 fi
3369 mv $cross config-meson.cross
3370
3371 rm -rf meson-private meson-info meson-logs
3372 run_meson() {
3373 NINJA=$ninja $meson setup \
3374 --prefix "$prefix" \
3375 --libdir "$libdir" \
3376 --libexecdir "$libexecdir" \
3377 --bindir "$bindir" \
3378 --includedir "$includedir" \
3379 --datadir "$datadir" \
3380 --mandir "$mandir" \
3381 --sysconfdir "$sysconfdir" \
3382 --localedir "$localedir" \
3383 --localstatedir "$local_statedir" \
3384 -Daudio_drv_list=$audio_drv_list \
3385 -Ddefault_devices=$default_devices \
3386 -Ddocdir="$docdir" \
3387 -Dqemu_firmwarepath="$firmwarepath" \
3388 -Dqemu_suffix="$qemu_suffix" \
3389 -Dsphinx_build="$sphinx_build" \
3390 -Dtrace_file="$trace_file" \
3391 -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) \
3392 -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo false; fi) \
3393 -Dwerror=$(if test "$werror" = yes; then echo true; else echo false; fi) \
3394 -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \
3395 -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
3396 -Db_lto=$lto -Dcfi=$cfi -Dtcg=$tcg -Dxen=$xen \
3397 -Dcapstone=$capstone -Dfdt=$fdt -Dslirp=$slirp \
3398 $(test -n "${LIB_FUZZING_ENGINE+xxx}" && echo "-Dfuzzing_engine=$LIB_FUZZING_ENGINE") \
3399 $(if test "$default_feature" = no; then echo "-Dauto_features=disabled"; fi) \
3400 "$@" $cross_arg "$PWD" "$source_path"
3401 }
3402 eval run_meson $meson_options
3403 if test "$?" -ne 0 ; then
3404 error_exit "meson setup failed"
3405 fi
3406 else
3407 if test -f meson-private/cmd_line.txt; then
3408 # Adjust old command line options whose type was changed
3409 # Avoids having to use "setup --wipe" when Meson is upgraded
3410 perl -i -ne '
3411 s/^gettext = true$/gettext = auto/;
3412 s/^gettext = false$/gettext = disabled/;
3413 /^b_staticpic/ && next;
3414 print;' meson-private/cmd_line.txt
3415 fi
3416 fi
3417
3418 # Save the configure command line for later reuse.
3419 cat <<EOD >config.status
3420 #!/bin/sh
3421 # Generated by configure.
3422 # Run this file to recreate the current configuration.
3423 # Compiler output produced by configure, useful for debugging
3424 # configure, is in config.log if it exists.
3425 EOD
3426
3427 preserve_env() {
3428 envname=$1
3429
3430 eval envval=\$$envname
3431
3432 if test -n "$envval"
3433 then
3434 echo "$envname='$envval'" >> config.status
3435 echo "export $envname" >> config.status
3436 else
3437 echo "unset $envname" >> config.status
3438 fi
3439 }
3440
3441 # Preserve various env variables that influence what
3442 # features/build target configure will detect
3443 preserve_env AR
3444 preserve_env AS
3445 preserve_env CC
3446 preserve_env CPP
3447 preserve_env CFLAGS
3448 preserve_env CXX
3449 preserve_env CXXFLAGS
3450 preserve_env INSTALL
3451 preserve_env LD
3452 preserve_env LDFLAGS
3453 preserve_env LD_LIBRARY_PATH
3454 preserve_env LIBTOOL
3455 preserve_env MAKE
3456 preserve_env NM
3457 preserve_env OBJCOPY
3458 preserve_env PATH
3459 preserve_env PKG_CONFIG
3460 preserve_env PKG_CONFIG_LIBDIR
3461 preserve_env PKG_CONFIG_PATH
3462 preserve_env PYTHON
3463 preserve_env SDL2_CONFIG
3464 preserve_env SMBD
3465 preserve_env STRIP
3466 preserve_env WINDRES
3467
3468 printf "exec" >>config.status
3469 for i in "$0" "$@"; do
3470 test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
3471 done
3472 echo ' "$@"' >>config.status
3473 chmod +x config.status
3474
3475 rm -r "$TMPDIR1"