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