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