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