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