]> git.proxmox.com Git - mirror_qemu.git/blob - configure
build: move sanitizer tests 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 if ! mkdir build || ! touch $MARKER
35 then
36 echo "ERROR: Could not create ./build directory. Check the permissions on"
37 echo "your source directory, or try doing an out-of-tree build."
38 exit 1
39 fi
40
41 cat > GNUmakefile <<'EOF'
42 # This file is auto-generated by configure to support in-source tree
43 # 'make' command invocation
44
45 ifeq ($(MAKECMDGOALS),)
46 recurse: all
47 endif
48
49 .NOTPARALLEL: %
50 %: force
51 @echo 'changing dir to build for $(MAKE) "$(MAKECMDGOALS)"...'
52 @$(MAKE) -C build -f Makefile $(MAKECMDGOALS)
53 @if test "$(MAKECMDGOALS)" = "distclean" && \
54 test -e build/auto-created-by-configure ; \
55 then \
56 rm -rf build GNUmakefile ; \
57 fi
58 force: ;
59 .PHONY: force
60 GNUmakefile: ;
61
62 EOF
63 cd build
64 exec "$source_path/configure" "$@"
65 fi
66
67 # Temporary directory used for files created while
68 # configure runs. Since it is in the build directory
69 # we can safely blow away any previous version of it
70 # (and we need not jump through hoops to try to delete
71 # it when configure exits.)
72 TMPDIR1="config-temp"
73 rm -rf "${TMPDIR1}"
74 if ! mkdir -p "${TMPDIR1}"; then
75 echo "ERROR: failed to create temporary directory"
76 exit 1
77 fi
78
79 TMPB="qemu-conf"
80 TMPC="${TMPDIR1}/${TMPB}.c"
81 TMPO="${TMPDIR1}/${TMPB}.o"
82 TMPM="${TMPDIR1}/${TMPB}.m"
83 TMPE="${TMPDIR1}/${TMPB}.exe"
84
85 rm -f config.log
86
87 # Print a helpful header at the top of config.log
88 echo "# QEMU configure log $(date)" >> config.log
89 printf "# Configured with:" >> config.log
90 # repeat the invocation to log and stdout for CI
91 invoke=$(printf " '%s'" "$0" "$@")
92 test -n "$GITLAB_CI" && echo "configuring with: $invoke"
93 { echo "$invoke"; echo; echo "#"; } >> config.log
94
95 quote_sh() {
96 printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
97 }
98
99 print_error() {
100 (echo
101 echo "ERROR: $1"
102 while test -n "$2"; do
103 echo " $2"
104 shift
105 done
106 echo) >&2
107 }
108
109 error_exit() {
110 print_error "$@"
111 exit 1
112 }
113
114 do_compiler() {
115 # Run the compiler, capturing its output to the log. First argument
116 # is compiler binary to execute.
117 compiler="$1"
118 shift
119 if test -n "$BASH_VERSION"; then eval '
120 echo >>config.log "
121 funcs: ${FUNCNAME[*]}
122 lines: ${BASH_LINENO[*]}"
123 '; fi
124 echo $compiler "$@" >> config.log
125 $compiler "$@" >> config.log 2>&1 || return $?
126 }
127
128 do_compiler_werror() {
129 # Run the compiler, capturing its output to the log. First argument
130 # is compiler binary to execute.
131 compiler="$1"
132 shift
133 if test -n "$BASH_VERSION"; then eval '
134 echo >>config.log "
135 funcs: ${FUNCNAME[*]}
136 lines: ${BASH_LINENO[*]}"
137 '; fi
138 echo $compiler "$@" >> config.log
139 $compiler "$@" >> config.log 2>&1 || return $?
140 # Test passed. If this is an --enable-werror build, rerun
141 # the test with -Werror and bail out if it fails. This
142 # makes warning-generating-errors in configure test code
143 # obvious to developers.
144 if test "$werror" != "yes"; then
145 return 0
146 fi
147 # Don't bother rerunning the compile if we were already using -Werror
148 case "$*" in
149 *-Werror*)
150 return 0
151 ;;
152 esac
153 echo $compiler -Werror "$@" >> config.log
154 $compiler -Werror "$@" >> config.log 2>&1 && return $?
155 error_exit "configure test passed without -Werror but failed with -Werror." \
156 "This is probably a bug in the configure script. The failing command" \
157 "will be at the bottom of config.log." \
158 "You can run configure with --disable-werror to bypass this check."
159 }
160
161 do_cc() {
162 do_compiler_werror "$cc" $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 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 if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
219 then
220 error_exit "main directory cannot contain spaces nor colons"
221 fi
222
223 # default parameters
224 cpu=""
225 static="no"
226 cross_compile="no"
227 cross_prefix=""
228 host_cc="cc"
229 stack_protector=""
230 safe_stack=""
231 use_containers="yes"
232 gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
233 gdb_arches=""
234
235 if test -e "$source_path/.git"
236 then
237 git_submodules_action="update"
238 else
239 git_submodules_action="ignore"
240 fi
241
242 git_submodules="ui/keycodemapdb"
243 git="git"
244
245 # Don't accept a target_list environment variable.
246 unset target_list
247 unset target_list_exclude
248
249 # Default value for a variable defining feature "foo".
250 # * foo="no" feature will only be used if --enable-foo arg is given
251 # * foo="" feature will be searched for, and if found, will be used
252 # unless --disable-foo is given
253 # * foo="yes" this value will only be set by --enable-foo flag.
254 # feature will searched for,
255 # if not found, configure exits with error
256 #
257 # Always add --enable-foo and --disable-foo command line args.
258 # Distributions want to ensure that several features are compiled in, and it
259 # is impossible without a --enable-foo that exits if a feature is not found.
260
261 default_feature=""
262 # parse CC options second
263 for opt do
264 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
265 case "$opt" in
266 --without-default-features)
267 default_feature="no"
268 ;;
269 esac
270 done
271
272 EXTRA_CFLAGS=""
273 EXTRA_CXXFLAGS=""
274 EXTRA_OBJCFLAGS=""
275 EXTRA_LDFLAGS=""
276
277 debug_tcg="no"
278 docs="auto"
279 EXESUF=""
280 prefix="/usr/local"
281 qemu_suffix="qemu"
282 softmmu="yes"
283 linux_user=""
284 bsd_user=""
285 pie=""
286 coroutine=""
287 plugins="$default_feature"
288 ninja=""
289 bindir="bin"
290 skip_meson=no
291 vfio_user_server="disabled"
292
293 # The following Meson options are handled manually (still they
294 # are included in the automatically generated help message)
295
296 # 1. Track which submodules are needed
297 fdt="auto"
298
299 # 2. Automatically enable/disable other options
300 tcg="auto"
301 cfi="false"
302
303 # parse CC options second
304 for opt do
305 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
306 case "$opt" in
307 --cross-prefix=*) cross_prefix="$optarg"
308 cross_compile="yes"
309 ;;
310 --cc=*) CC="$optarg"
311 ;;
312 --cxx=*) CXX="$optarg"
313 ;;
314 --objcc=*) objcc="$optarg"
315 ;;
316 --cpu=*) cpu="$optarg"
317 ;;
318 --extra-cflags=*)
319 EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
320 EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
321 EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
322 ;;
323 --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
324 ;;
325 --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
326 ;;
327 --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
328 ;;
329 --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
330 ;;
331 --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
332 eval "cross_cc_cflags_${cc_arch}=\$optarg"
333 ;;
334 --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
335 eval "cross_cc_${cc_arch}=\$optarg"
336 ;;
337 --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-prefix-FOO option"
338 ;;
339 --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
340 eval "cross_prefix_${cc_arch}=\$optarg"
341 ;;
342 esac
343 done
344
345 # Preferred compiler:
346 # ${CC} (if set)
347 # ${cross_prefix}gcc (if cross-prefix specified)
348 # system compiler
349 if test -z "${CC}${cross_prefix}"; then
350 cc="$host_cc"
351 else
352 cc="${CC-${cross_prefix}gcc}"
353 fi
354
355 if test -z "${CXX}${cross_prefix}"; then
356 cxx="c++"
357 else
358 cxx="${CXX-${cross_prefix}g++}"
359 fi
360
361 # Preferred ObjC compiler:
362 # $objcc (if set, i.e. via --objcc option)
363 # ${cross_prefix}clang (if cross-prefix specified)
364 # clang (if available)
365 # $cc
366 if test -z "${objcc}${cross_prefix}"; then
367 if has clang; then
368 objcc=clang
369 else
370 objcc="$cc"
371 fi
372 else
373 objcc="${objcc-${cross_prefix}clang}"
374 fi
375
376 ar="${AR-${cross_prefix}ar}"
377 as="${AS-${cross_prefix}as}"
378 ccas="${CCAS-$cc}"
379 objcopy="${OBJCOPY-${cross_prefix}objcopy}"
380 ld="${LD-${cross_prefix}ld}"
381 ranlib="${RANLIB-${cross_prefix}ranlib}"
382 nm="${NM-${cross_prefix}nm}"
383 smbd="$SMBD"
384 strip="${STRIP-${cross_prefix}strip}"
385 widl="${WIDL-${cross_prefix}widl}"
386 windres="${WINDRES-${cross_prefix}windres}"
387 windmc="${WINDMC-${cross_prefix}windmc}"
388 pkg_config="${PKG_CONFIG-${cross_prefix}pkg-config}"
389 sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
390
391 # default flags for all hosts
392 # We use -fwrapv to tell the compiler that we require a C dialect where
393 # left shift of signed integers is well defined and has the expected
394 # 2s-complement style results. (Both clang and gcc agree that it
395 # provides these semantics.)
396 QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
397 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
398
399 QEMU_LDFLAGS=
400
401 # Flags that are needed during configure but later taken care of by Meson
402 CONFIGURE_CFLAGS="-std=gnu11 -Wall"
403 CONFIGURE_LDFLAGS=
404
405
406 check_define() {
407 cat > $TMPC <<EOF
408 #if !defined($1)
409 #error $1 not defined
410 #endif
411 int main(void) { return 0; }
412 EOF
413 compile_object
414 }
415
416 write_c_skeleton() {
417 cat > $TMPC <<EOF
418 int main(void) { return 0; }
419 EOF
420 }
421
422 if check_define __linux__ ; then
423 targetos=linux
424 elif check_define _WIN32 ; then
425 targetos=windows
426 elif check_define __OpenBSD__ ; then
427 targetos=openbsd
428 elif check_define __sun__ ; then
429 targetos=sunos
430 elif check_define __HAIKU__ ; then
431 targetos=haiku
432 elif check_define __FreeBSD__ ; then
433 targetos=freebsd
434 elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
435 targetos=gnu/kfreebsd
436 elif check_define __DragonFly__ ; then
437 targetos=dragonfly
438 elif check_define __NetBSD__; then
439 targetos=netbsd
440 elif check_define __APPLE__; then
441 targetos=darwin
442 else
443 # This is a fatal error, but don't report it yet, because we
444 # might be going to just print the --help text, or it might
445 # be the result of a missing compiler.
446 targetos=bogus
447 fi
448
449 # OS specific
450
451 mingw32="no"
452 bsd="no"
453 linux="no"
454 solaris="no"
455 case $targetos in
456 windows)
457 mingw32="yes"
458 plugins="no"
459 pie="no"
460 ;;
461 gnu/kfreebsd)
462 bsd="yes"
463 ;;
464 freebsd)
465 bsd="yes"
466 make="${MAKE-gmake}"
467 # needed for kinfo_getvmmap(3) in libutil.h
468 ;;
469 dragonfly)
470 bsd="yes"
471 make="${MAKE-gmake}"
472 ;;
473 netbsd)
474 bsd="yes"
475 make="${MAKE-gmake}"
476 ;;
477 openbsd)
478 bsd="yes"
479 make="${MAKE-gmake}"
480 ;;
481 darwin)
482 bsd="yes"
483 darwin="yes"
484 # Disable attempts to use ObjectiveC features in os/object.h since they
485 # won't work when we're compiling with gcc as a C compiler.
486 QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
487 ;;
488 sunos)
489 solaris="yes"
490 make="${MAKE-gmake}"
491 # needed for CMSG_ macros in sys/socket.h
492 QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
493 # needed for TIOCWIN* defines in termios.h
494 QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
495 ;;
496 haiku)
497 pie="no"
498 QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
499 ;;
500 linux)
501 linux="yes"
502 ;;
503 esac
504
505 if test ! -z "$cpu" ; then
506 # command line argument
507 :
508 elif check_define __i386__ ; then
509 cpu="i386"
510 elif check_define __x86_64__ ; then
511 if check_define __ILP32__ ; then
512 cpu="x32"
513 else
514 cpu="x86_64"
515 fi
516 elif check_define __sparc__ ; then
517 if check_define __arch64__ ; then
518 cpu="sparc64"
519 else
520 cpu="sparc"
521 fi
522 elif check_define _ARCH_PPC ; then
523 if check_define _ARCH_PPC64 ; then
524 if check_define _LITTLE_ENDIAN ; then
525 cpu="ppc64le"
526 else
527 cpu="ppc64"
528 fi
529 else
530 cpu="ppc"
531 fi
532 elif check_define __mips__ ; then
533 cpu="mips"
534 elif check_define __s390__ ; then
535 if check_define __s390x__ ; then
536 cpu="s390x"
537 else
538 cpu="s390"
539 fi
540 elif check_define __riscv ; then
541 cpu="riscv"
542 elif check_define __arm__ ; then
543 cpu="arm"
544 elif check_define __aarch64__ ; then
545 cpu="aarch64"
546 elif check_define __loongarch64 ; then
547 cpu="loongarch64"
548 else
549 # Using uname is really broken, but it is just a fallback for architectures
550 # that are going to use TCI anyway
551 cpu=$(uname -m)
552 echo "WARNING: unrecognized host CPU, proceeding with 'uname -m' output '$cpu'"
553 fi
554
555 # Normalise host CPU name and set multilib cflags. The canonicalization
556 # isn't really necessary, because the architectures that we check for
557 # should not hit the 'uname -m' case, but better safe than sorry.
558 # Note that this case should only have supported host CPUs, not guests.
559 case "$cpu" in
560 armv*b|armv*l|arm)
561 cpu="arm" ;;
562
563 i386|i486|i586|i686)
564 cpu="i386"
565 CPU_CFLAGS="-m32" ;;
566 x32)
567 cpu="x86_64"
568 CPU_CFLAGS="-mx32" ;;
569 x86_64|amd64)
570 cpu="x86_64"
571 # ??? Only extremely old AMD cpus do not have cmpxchg16b.
572 # If we truly care, we should simply detect this case at
573 # runtime and generate the fallback to serial emulation.
574 CPU_CFLAGS="-m64 -mcx16" ;;
575
576 mips*)
577 cpu="mips" ;;
578
579 ppc)
580 CPU_CFLAGS="-m32" ;;
581 ppc64)
582 CPU_CFLAGS="-m64 -mbig-endian" ;;
583 ppc64le)
584 cpu="ppc64"
585 CPU_CFLAGS="-m64 -mlittle-endian" ;;
586
587 s390)
588 CPU_CFLAGS="-m31" ;;
589 s390x)
590 CPU_CFLAGS="-m64" ;;
591
592 sparc|sun4[cdmuv])
593 cpu="sparc"
594 CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
595 sparc64)
596 CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
597 esac
598
599 : ${make=${MAKE-make}}
600
601
602 check_py_version() {
603 # We require python >= 3.7.
604 # NB: a True python conditional creates a non-zero return code (Failure)
605 "$1" -c 'import sys; sys.exit(sys.version_info < (3,7))'
606 }
607
608 python=
609 pypi="enabled"
610 first_python=
611 if test -z "${PYTHON}"; then
612 # A bare 'python' is traditionally python 2.x, but some distros
613 # have it as python 3.x, so check in both places.
614 for binary in python3 python python3.11 python3.10 python3.9 python3.8 python3.7; do
615 if has "$binary"; then
616 python=$(command -v "$binary")
617 if check_py_version "$python"; then
618 # This one is good.
619 first_python=
620 break
621 else
622 first_python=$python
623 fi
624 fi
625 done
626 else
627 # Same as above, but only check the environment variable.
628 has "${PYTHON}" || error_exit "The PYTHON environment variable does not point to an executable"
629 python=$(command -v "$PYTHON")
630 if check_py_version "$python"; then
631 # This one is good.
632 first_python=
633 else
634 first_python=$first_python
635 fi
636 fi
637
638 # Check for ancillary tools used in testing
639 genisoimage=
640 for binary in genisoimage mkisofs
641 do
642 if has $binary
643 then
644 genisoimage=$(command -v "$binary")
645 break
646 fi
647 done
648
649 if test "$mingw32" = "yes" ; then
650 EXESUF=".exe"
651 # MinGW needs -mthreads for TLS and macro _MT.
652 CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
653 prefix="/qemu"
654 bindir=""
655 qemu_suffix=""
656 fi
657
658 werror=""
659
660 meson_option_build_array() {
661 printf '['
662 (if test "$targetos" = windows; then
663 IFS=\;
664 else
665 IFS=:
666 fi
667 for e in $1; do
668 printf '"""'
669 # backslash escape any '\' and '"' characters
670 printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g'
671 printf '""",'
672 done)
673 printf ']\n'
674 }
675
676 . "$source_path/scripts/meson-buildoptions.sh"
677
678 meson_options=
679 meson_option_add() {
680 meson_options="$meson_options $(quote_sh "$1")"
681 }
682 meson_option_parse() {
683 meson_options="$meson_options $(_meson_option_parse "$@")"
684 if test $? -eq 1; then
685 echo "ERROR: unknown option $1"
686 echo "Try '$0 --help' for more information"
687 exit 1
688 fi
689 }
690
691 for opt do
692 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
693 case "$opt" in
694 --help|-h) show_help=yes
695 ;;
696 --version|-V) exec cat "$source_path/VERSION"
697 ;;
698 --prefix=*) prefix="$optarg"
699 ;;
700 --cross-prefix=*)
701 ;;
702 --cc=*)
703 ;;
704 --host-cc=*) host_cc="$optarg"
705 ;;
706 --cxx=*)
707 ;;
708 --objcc=*)
709 ;;
710 --make=*) make="$optarg"
711 ;;
712 --install=*)
713 ;;
714 --python=*) python="$optarg"
715 ;;
716 --skip-meson) skip_meson=yes
717 ;;
718 --ninja=*) ninja="$optarg"
719 ;;
720 --smbd=*) smbd="$optarg"
721 ;;
722 --extra-cflags=*)
723 ;;
724 --extra-cxxflags=*)
725 ;;
726 --extra-objcflags=*)
727 ;;
728 --extra-ldflags=*)
729 ;;
730 --cross-cc-*)
731 ;;
732 --cross-prefix-*)
733 ;;
734 --enable-debug-info) meson_option_add -Ddebug=true
735 ;;
736 --disable-debug-info) meson_option_add -Ddebug=false
737 ;;
738 --enable-docs) docs=enabled
739 ;;
740 --disable-docs) docs=disabled
741 ;;
742 --cpu=*)
743 ;;
744 --target-list=*) target_list="$optarg"
745 if test "$target_list_exclude"; then
746 error_exit "Can't mix --target-list with --target-list-exclude"
747 fi
748 ;;
749 --target-list-exclude=*) target_list_exclude="$optarg"
750 if test "$target_list"; then
751 error_exit "Can't mix --target-list-exclude with --target-list"
752 fi
753 ;;
754 --with-default-devices) meson_option_add -Ddefault_devices=true
755 ;;
756 --without-default-devices) meson_option_add -Ddefault_devices=false
757 ;;
758 --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
759 ;;
760 --with-devices-*) device_arch=${opt#--with-devices-};
761 device_arch=${device_arch%%=*}
762 cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
763 if test -f "$cf"; then
764 device_archs="$device_archs $device_arch"
765 eval "devices_${device_arch}=\$optarg"
766 else
767 error_exit "File $cf does not exist"
768 fi
769 ;;
770 --without-default-features) # processed above
771 ;;
772 --static) static="yes"
773 ;;
774 --bindir=*) bindir="$optarg"
775 ;;
776 --with-suffix=*) qemu_suffix="$optarg"
777 ;;
778 --host=*|--build=*|\
779 --disable-dependency-tracking|\
780 --sbindir=*|--sharedstatedir=*|\
781 --oldincludedir=*|--datarootdir=*|--infodir=*|\
782 --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
783 # These switches are silently ignored, for compatibility with
784 # autoconf-generated configure scripts. This allows QEMU's
785 # configure to be used by RPM and similar macros that set
786 # lots of directory switches by default.
787 ;;
788 --enable-debug-tcg) debug_tcg="yes"
789 ;;
790 --disable-debug-tcg) debug_tcg="no"
791 ;;
792 --enable-debug)
793 # Enable debugging options that aren't excessively noisy
794 debug_tcg="yes"
795 meson_option_parse --enable-debug-graph-lock ""
796 meson_option_parse --enable-debug-mutex ""
797 meson_option_add -Doptimization=0
798 ;;
799 --disable-tcg) tcg="disabled"
800 plugins="no"
801 ;;
802 --enable-tcg) tcg="enabled"
803 ;;
804 --disable-system) softmmu="no"
805 ;;
806 --enable-system) softmmu="yes"
807 ;;
808 --disable-user)
809 linux_user="no" ;
810 bsd_user="no" ;
811 ;;
812 --enable-user) ;;
813 --disable-linux-user) linux_user="no"
814 ;;
815 --enable-linux-user) linux_user="yes"
816 ;;
817 --disable-bsd-user) bsd_user="no"
818 ;;
819 --enable-bsd-user) bsd_user="yes"
820 ;;
821 --enable-pie) pie="yes"
822 ;;
823 --disable-pie) pie="no"
824 ;;
825 --enable-werror) werror="yes"
826 ;;
827 --disable-werror) werror="no"
828 ;;
829 --enable-stack-protector) stack_protector="yes"
830 ;;
831 --disable-stack-protector) stack_protector="no"
832 ;;
833 --enable-safe-stack) safe_stack="yes"
834 ;;
835 --disable-safe-stack) safe_stack="no"
836 ;;
837 --enable-cfi)
838 cfi="true";
839 meson_option_add -Db_lto=true
840 ;;
841 --disable-cfi) cfi="false"
842 ;;
843 --disable-fdt) fdt="disabled"
844 ;;
845 --enable-fdt) fdt="enabled"
846 ;;
847 --enable-fdt=git) fdt="internal"
848 ;;
849 --enable-fdt=*) fdt="$optarg"
850 ;;
851 --with-coroutine=*) coroutine="$optarg"
852 ;;
853 --with-git=*) git="$optarg"
854 ;;
855 --with-git-submodules=*)
856 git_submodules_action="$optarg"
857 ;;
858 --disable-pypi) pypi="disabled"
859 ;;
860 --enable-pypi) pypi="enabled"
861 ;;
862 --enable-plugins) if test "$mingw32" = "yes"; then
863 error_exit "TCG plugins not currently supported on Windows platforms"
864 else
865 plugins="yes"
866 fi
867 ;;
868 --disable-plugins) plugins="no"
869 ;;
870 --enable-containers) use_containers="yes"
871 ;;
872 --disable-containers) use_containers="no"
873 ;;
874 --gdb=*) gdb_bin="$optarg"
875 ;;
876 --enable-vfio-user-server) vfio_user_server="enabled"
877 ;;
878 --disable-vfio-user-server) vfio_user_server="disabled"
879 ;;
880 # everything else has the same name in configure and meson
881 --*) meson_option_parse "$opt" "$optarg"
882 ;;
883 esac
884 done
885
886 # test for any invalid configuration combinations
887 if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
888 error_exit "Can't enable plugins on non-TCG builds"
889 fi
890
891 case $git_submodules_action in
892 update|validate)
893 if test ! -e "$source_path/.git"; then
894 echo "ERROR: cannot $git_submodules_action git submodules without .git"
895 exit 1
896 fi
897 ;;
898 ignore)
899 if ! test -f "$source_path/ui/keycodemapdb/README"
900 then
901 echo
902 echo "ERROR: missing GIT submodules"
903 echo
904 if test -e "$source_path/.git"; then
905 echo "--with-git-submodules=ignore specified but submodules were not"
906 echo "checked out. Please initialize and update submodules."
907 else
908 echo "This is not a GIT checkout but module content appears to"
909 echo "be missing. Do not use 'git archive' or GitHub download links"
910 echo "to acquire QEMU source archives. Non-GIT builds are only"
911 echo "supported with source archives linked from:"
912 echo
913 echo " https://www.qemu.org/download/#source"
914 echo
915 echo "Developers working with GIT can use scripts/archive-source.sh"
916 echo "if they need to create valid source archives."
917 fi
918 echo
919 exit 1
920 fi
921 ;;
922 *)
923 echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
924 exit 1
925 ;;
926 esac
927
928 default_target_list=""
929 mak_wilds=""
930
931 if [ "$linux_user" != no ]; then
932 if [ "$targetos" = linux ] && [ -d "$source_path/linux-user/include/host/$cpu" ]; then
933 linux_user=yes
934 elif [ "$linux_user" = yes ]; then
935 error_exit "linux-user not supported on this architecture"
936 fi
937 fi
938 if [ "$bsd_user" != no ]; then
939 if [ "$bsd_user" = "" ]; then
940 test $targetos = freebsd && bsd_user=yes
941 fi
942 if [ "$bsd_user" = yes ] && ! [ -d "$source_path/bsd-user/$targetos" ]; then
943 error_exit "bsd-user not supported on this host OS"
944 fi
945 fi
946 if [ "$softmmu" = "yes" ]; then
947 mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
948 fi
949 if [ "$linux_user" = "yes" ]; then
950 mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
951 fi
952 if [ "$bsd_user" = "yes" ]; then
953 mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
954 fi
955
956 for config in $mak_wilds; do
957 target="$(basename "$config" .mak)"
958 if echo "$target_list_exclude" | grep -vq "$target"; then
959 default_target_list="${default_target_list} $target"
960 fi
961 done
962
963 if test x"$show_help" = x"yes" ; then
964 cat << EOF
965
966 Usage: configure [options]
967 Options: [defaults in brackets after descriptions]
968
969 Standard options:
970 --help print this message
971 --prefix=PREFIX install in PREFIX [$prefix]
972 --target-list=LIST set target list (default: build all)
973 $(echo Available targets: $default_target_list | \
974 fold -s -w 53 | sed -e 's/^/ /')
975 --target-list-exclude=LIST exclude a set of targets from the default target-list
976
977 Advanced options (experts only):
978 --cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
979 --cc=CC use C compiler CC [$cc]
980 --host-cc=CC use C compiler CC [$host_cc] for code run at
981 build time
982 --cxx=CXX use C++ compiler CXX [$cxx]
983 --objcc=OBJCC use Objective-C compiler OBJCC [$objcc]
984 --extra-cflags=CFLAGS append extra C compiler flags CFLAGS
985 --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
986 --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
987 --extra-ldflags=LDFLAGS append extra linker flags LDFLAGS
988 --cross-cc-ARCH=CC use compiler when building ARCH guest test cases
989 --cross-cc-cflags-ARCH= use compiler flags when building ARCH guest tests
990 --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
991 --make=MAKE use specified make [$make]
992 --python=PYTHON use specified python [$python]
993 --ninja=NINJA use specified ninja [$ninja]
994 --smbd=SMBD use specified smbd [$smbd]
995 --with-git=GIT use specified git [$git]
996 --with-git-submodules=update update git submodules (default if .git dir exists)
997 --with-git-submodules=validate fail if git submodules are not up to date
998 --with-git-submodules=ignore do not update or check git submodules (default if no .git dir)
999 --static enable static build [$static]
1000 --bindir=PATH install binaries in PATH
1001 --with-suffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
1002 --without-default-features default all --enable-* options to "disabled"
1003 --without-default-devices do not include any device that is not needed to
1004 start the emulator (only use if you are including
1005 desired devices in configs/devices/)
1006 --with-devices-ARCH=NAME override default configs/devices
1007 --enable-debug enable common debug build options
1008 --disable-werror disable compilation abort on warning
1009 --disable-stack-protector disable compiler-provided stack protection
1010 --cpu=CPU Build for host CPU [$cpu]
1011 --with-coroutine=BACKEND coroutine backend. Supported options:
1012 ucontext, sigaltstack, windows
1013 --enable-plugins
1014 enable plugins via shared library loading
1015 --disable-containers don't use containers for cross-building
1016 --gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
1017 EOF
1018 meson_options_help
1019 cat << EOF
1020 system all system emulation targets
1021 user supported user emulation targets
1022 linux-user all linux usermode emulation targets
1023 bsd-user all BSD usermode emulation targets
1024 pie Position Independent Executables
1025 debug-tcg TCG debugging (default is disabled)
1026 debug-info debugging information
1027 safe-stack SafeStack Stack Smash Protection. Depends on
1028 clang/llvm and requires coroutine backend ucontext.
1029
1030 NOTE: The object files are built at the place where configure is launched
1031 EOF
1032 exit 0
1033 fi
1034
1035 # Remove old dependency files to make sure that they get properly regenerated
1036 rm -f ./*/config-devices.mak.d
1037
1038 if test -z "$python"
1039 then
1040 # If first_python is set, there was a binary somewhere even though
1041 # it was not suitable. Use it for the error message.
1042 if test -n "$first_python"; then
1043 error_exit "Cannot use '$first_python', Python >= 3.7 is required." \
1044 "Use --python=/path/to/python to specify a supported Python."
1045 else
1046 error_exit "Python not found. Use --python=/path/to/python"
1047 fi
1048 fi
1049
1050 if ! has "$make"
1051 then
1052 error_exit "GNU make ($make) not found"
1053 fi
1054
1055 if ! check_py_version "$python"; then
1056 error_exit "Cannot use '$python', Python >= 3.7 is required." \
1057 "Use --python=/path/to/python to specify a supported Python." \
1058 "Maybe try:" \
1059 " openSUSE Leap 15.3+: zypper install python39" \
1060 " CentOS 8: dnf install python38"
1061 fi
1062
1063 # Resolve PATH
1064 python="$(command -v "$python")"
1065
1066 # Create a Python virtual environment using our configured python.
1067 # The stdout of this script will be the location of a symlink that
1068 # points to the configured Python.
1069 # Entry point scripts for pip, meson, and sphinx are generated if those
1070 # packages are present.
1071
1072 # Defaults assumed for now:
1073 # - venv is cleared if it exists already;
1074 # - venv is allowed to use system packages;
1075 # - all setup can be performed offline;
1076 # - missing packages may be fetched from PyPI,
1077 # unless --disable-pypi is passed.
1078 # - pip is not installed into the venv when possible,
1079 # but ensurepip is called as a fallback when necessary.
1080
1081 echo "python determined to be '$python'"
1082 echo "python version: $($python --version)"
1083
1084 python="$($python -B "${source_path}/python/scripts/mkvenv.py" create pyvenv)"
1085 if test "$?" -ne 0 ; then
1086 error_exit "python venv creation failed"
1087 fi
1088
1089 # Suppress writing compiled files
1090 python="$python -B"
1091 mkvenv="$python ${source_path}/python/scripts/mkvenv.py"
1092
1093 mkvenv_flags=""
1094 if test "$pypi" = "enabled" ; then
1095 mkvenv_flags="--online"
1096 fi
1097
1098 if ! $mkvenv ensure \
1099 $mkvenv_flags \
1100 --dir "${source_path}/python/wheels" \
1101 --diagnose "meson" \
1102 "meson>=0.63.0" ;
1103 then
1104 exit 1
1105 fi
1106
1107 # At this point, we expect Meson to be installed and available.
1108 # We expect mkvenv or pip to have created pyvenv/bin/meson for us.
1109 # We ignore PATH completely here: we want to use the venv's Meson
1110 # *exclusively*.
1111
1112 meson="$(cd pyvenv/bin; pwd)/meson"
1113
1114 # Conditionally ensure Sphinx is installed.
1115
1116 mkvenv_flags=""
1117 if test "$pypi" = "enabled" -a "$docs" = "enabled" ; then
1118 mkvenv_flags="--online"
1119 fi
1120
1121 if test "$docs" != "disabled" ; then
1122 if ! $mkvenv ensure \
1123 $mkvenv_flags \
1124 --diagnose "sphinx-build" \
1125 "sphinx>=1.6.0" "sphinx-rtd-theme>=0.5.0";
1126 then
1127 if test "$docs" = "enabled" ; then
1128 exit 1
1129 fi
1130 echo "Sphinx not found/usable, disabling docs."
1131 docs=disabled
1132 else
1133 docs=enabled
1134 fi
1135 fi
1136
1137 # Probe for ninja
1138
1139 if test -z "$ninja"; then
1140 for c in ninja ninja-build samu; do
1141 if has $c; then
1142 ninja=$(command -v "$c")
1143 break
1144 fi
1145 done
1146 if test -z "$ninja"; then
1147 error_exit "Cannot find Ninja"
1148 fi
1149 fi
1150
1151 # Check that the C compiler works. Doing this here before testing
1152 # the host CPU ensures that we had a valid CC to autodetect the
1153 # $cpu var (and we should bail right here if that's not the case).
1154 # It also allows the help message to be printed without a CC.
1155 write_c_skeleton;
1156 if compile_object ; then
1157 : C compiler works ok
1158 else
1159 error_exit "\"$cc\" either does not exist or does not work"
1160 fi
1161 if ! compile_prog ; then
1162 error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
1163 fi
1164
1165 # Consult white-list to determine whether to enable werror
1166 # by default. Only enable by default for git builds
1167 if test -z "$werror" ; then
1168 if test "$git_submodules_action" != "ignore" && \
1169 { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
1170 werror="yes"
1171 else
1172 werror="no"
1173 fi
1174 fi
1175
1176 if test "$targetos" = "bogus"; then
1177 # Now that we know that we're not printing the help and that
1178 # the compiler works (so the results of the check_defines we used
1179 # to identify the OS are reliable), if we didn't recognize the
1180 # host OS we should stop now.
1181 error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1182 fi
1183
1184 # Check whether the compiler matches our minimum requirements:
1185 cat > $TMPC << EOF
1186 #if defined(__clang_major__) && defined(__clang_minor__)
1187 # ifdef __apple_build_version__
1188 # if __clang_major__ < 12 || (__clang_major__ == 12 && __clang_minor__ < 0)
1189 # error You need at least XCode Clang v12.0 to compile QEMU
1190 # endif
1191 # else
1192 # if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
1193 # error You need at least Clang v10.0 to compile QEMU
1194 # endif
1195 # endif
1196 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
1197 # if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
1198 # error You need at least GCC v7.4.0 to compile QEMU
1199 # endif
1200 #else
1201 # error You either need GCC or Clang to compiler QEMU
1202 #endif
1203 int main (void) { return 0; }
1204 EOF
1205 if ! compile_prog "" "" ; then
1206 error_exit "You need at least GCC v7.4 or Clang v10.0 (or XCode Clang v12.0)"
1207 fi
1208
1209 # Accumulate -Wfoo and -Wno-bar separately.
1210 # We will list all of the enable flags first, and the disable flags second.
1211 # Note that we do not add -Werror, because that would enable it for all
1212 # configure tests. If a configure test failed due to -Werror this would
1213 # just silently disable some features, so it's too error prone.
1214
1215 warn_flags=
1216 add_to warn_flags -Wundef
1217 add_to warn_flags -Wwrite-strings
1218 add_to warn_flags -Wmissing-prototypes
1219 add_to warn_flags -Wstrict-prototypes
1220 add_to warn_flags -Wredundant-decls
1221 add_to warn_flags -Wold-style-declaration
1222 add_to warn_flags -Wold-style-definition
1223 add_to warn_flags -Wtype-limits
1224 add_to warn_flags -Wformat-security
1225 add_to warn_flags -Wformat-y2k
1226 add_to warn_flags -Winit-self
1227 add_to warn_flags -Wignored-qualifiers
1228 add_to warn_flags -Wempty-body
1229 add_to warn_flags -Wnested-externs
1230 add_to warn_flags -Wendif-labels
1231 add_to warn_flags -Wexpansion-to-defined
1232 add_to warn_flags -Wimplicit-fallthrough=2
1233 add_to warn_flags -Wmissing-format-attribute
1234
1235 if test "$targetos" != "darwin"; then
1236 add_to warn_flags -Wthread-safety
1237 fi
1238
1239 nowarn_flags=
1240 add_to nowarn_flags -Wno-initializer-overrides
1241 add_to nowarn_flags -Wno-missing-include-dirs
1242 add_to nowarn_flags -Wno-shift-negative-value
1243 add_to nowarn_flags -Wno-string-plus-int
1244 add_to nowarn_flags -Wno-typedef-redefinition
1245 add_to nowarn_flags -Wno-tautological-type-limit-compare
1246 add_to nowarn_flags -Wno-psabi
1247 add_to nowarn_flags -Wno-gnu-variable-sized-type-not-at-end
1248
1249 gcc_flags="$warn_flags $nowarn_flags"
1250
1251 cc_has_warning_flag() {
1252 write_c_skeleton;
1253
1254 # Use the positive sense of the flag when testing for -Wno-wombat
1255 # support (gcc will happily accept the -Wno- form of unknown
1256 # warning options).
1257 optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
1258 compile_prog "-Werror $optflag" ""
1259 }
1260
1261 objcc_has_warning_flag() {
1262 cat > $TMPM <<EOF
1263 int main(void) { return 0; }
1264 EOF
1265
1266 # Use the positive sense of the flag when testing for -Wno-wombat
1267 # support (gcc will happily accept the -Wno- form of unknown
1268 # warning options).
1269 optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
1270 do_objc -Werror $optflag \
1271 $OBJCFLAGS $EXTRA_OBJCFLAGS $CONFIGURE_OBJCFLAGS $QEMU_OBJCFLAGS \
1272 -o $TMPE $TMPM $QEMU_LDFLAGS
1273 }
1274
1275 for flag in $gcc_flags; do
1276 if cc_has_warning_flag $flag ; then
1277 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1278 fi
1279 if objcc_has_warning_flag $flag ; then
1280 QEMU_OBJCFLAGS="$QEMU_OBJCFLAGS $flag"
1281 fi
1282 done
1283
1284 if test "$stack_protector" != "no"; then
1285 cat > $TMPC << EOF
1286 int main(int argc, char *argv[])
1287 {
1288 char arr[64], *p = arr, *c = argv[argc - 1];
1289 while (*c) {
1290 *p++ = *c++;
1291 }
1292 return 0;
1293 }
1294 EOF
1295 gcc_flags="-fstack-protector-strong -fstack-protector-all"
1296 sp_on=0
1297 for flag in $gcc_flags; do
1298 # We need to check both a compile and a link, since some compiler
1299 # setups fail only on a .c->.o compile and some only at link time
1300 if compile_object "-Werror $flag" &&
1301 compile_prog "-Werror $flag" ""; then
1302 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1303 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
1304 sp_on=1
1305 break
1306 fi
1307 done
1308 if test "$stack_protector" = yes; then
1309 if test $sp_on = 0; then
1310 error_exit "Stack protector not supported"
1311 fi
1312 fi
1313 fi
1314
1315 if test "$static" = "yes" ; then
1316 if test "$plugins" = "yes"; then
1317 error_exit "static and plugins are mutually incompatible"
1318 else
1319 plugins="no"
1320 fi
1321 fi
1322 test "$plugins" = "" && plugins=yes
1323
1324 cat > $TMPC << EOF
1325
1326 #ifdef __linux__
1327 # define THREAD __thread
1328 #else
1329 # define THREAD
1330 #endif
1331 static THREAD int tls_var;
1332 int main(void) { return tls_var; }
1333 EOF
1334
1335 # Meson currently only handles pie as a boolean for now so if we have
1336 # explicitly disabled PIE we need to extend our cflags because it wont.
1337 if test "$static" = "yes"; then
1338 if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
1339 CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
1340 pie="yes"
1341 elif test "$pie" = "yes"; then
1342 error_exit "-static-pie not available due to missing toolchain support"
1343 else
1344 pie="no"
1345 QEMU_CFLAGS="-fno-pie $QEMU_CFLAGS"
1346 fi
1347 elif test "$pie" = "no"; then
1348 if compile_prog "-Werror -fno-pie" "-no-pie"; then
1349 CONFIGURE_CFLAGS="-fno-pie $CONFIGURE_CFLAGS"
1350 CONFIGURE_LDFLAGS="-no-pie $CONFIGURE_LDFLAGS"
1351 QEMU_CFLAGS="-fno-pie -no-pie $QEMU_CFLAGS"
1352 fi
1353 elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
1354 CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
1355 CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
1356 pie="yes"
1357 elif test "$pie" = "yes"; then
1358 error_exit "PIE not available due to missing toolchain support"
1359 else
1360 echo "Disabling PIE due to missing toolchain support"
1361 pie="no"
1362 fi
1363
1364 ##########################################
1365 # __sync_fetch_and_and requires at least -march=i486. Many toolchains
1366 # use i686 as default anyway, but for those that don't, an explicit
1367 # specification is necessary
1368
1369 if test "$cpu" = "i386"; then
1370 cat > $TMPC << EOF
1371 static int sfaa(int *ptr)
1372 {
1373 return __sync_fetch_and_and(ptr, 0);
1374 }
1375
1376 int main(void)
1377 {
1378 int val = 42;
1379 val = __sync_val_compare_and_swap(&val, 0, 1);
1380 sfaa(&val);
1381 return val;
1382 }
1383 EOF
1384 if ! compile_prog "" "" ; then
1385 QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
1386 fi
1387 fi
1388
1389 if test -z "${target_list+xxx}" ; then
1390 default_targets=yes
1391 for target in $default_target_list; do
1392 target_list="$target_list $target"
1393 done
1394 target_list="${target_list# }"
1395 else
1396 default_targets=no
1397 target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1398 for target in $target_list; do
1399 # Check that we recognised the target name; this allows a more
1400 # friendly error message than if we let it fall through.
1401 case " $default_target_list " in
1402 *" $target "*)
1403 ;;
1404 *)
1405 error_exit "Unknown target name '$target'"
1406 ;;
1407 esac
1408 done
1409 fi
1410
1411 # see if system emulation was really requested
1412 case " $target_list " in
1413 *"-softmmu "*) softmmu=yes
1414 ;;
1415 *) softmmu=no
1416 ;;
1417 esac
1418
1419 if test "$tcg" = "auto"; then
1420 if test -z "$target_list"; then
1421 tcg="disabled"
1422 else
1423 tcg="enabled"
1424 fi
1425 fi
1426
1427 if test "$tcg" = "enabled"; then
1428 git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
1429 git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
1430 fi
1431
1432 ##########################################
1433 # big/little endian test
1434 cat > $TMPC << EOF
1435 #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1436 # error LITTLE
1437 #endif
1438 int main(void) { return 0; }
1439 EOF
1440
1441 if ! compile_prog ; then
1442 bigendian="no"
1443 else
1444 cat > $TMPC << EOF
1445 #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
1446 # error BIG
1447 #endif
1448 int main(void) { return 0; }
1449 EOF
1450
1451 if ! compile_prog ; then
1452 bigendian="yes"
1453 else
1454 echo big/little test failed
1455 exit 1
1456 fi
1457 fi
1458
1459 ##########################################
1460 # fdt probe
1461
1462 case "$fdt" in
1463 auto | enabled | internal)
1464 # Simpler to always update submodule, even if not needed.
1465 git_submodules="${git_submodules} dtc"
1466 ;;
1467 esac
1468
1469 ##########################################
1470 # check and set a backend for coroutine
1471
1472 # We prefer ucontext, but it's not always possible. The fallback
1473 # is sigcontext. On Windows the only valid backend is the Windows
1474 # specific one.
1475
1476 ucontext_works=no
1477 if test "$darwin" != "yes"; then
1478 cat > $TMPC << EOF
1479 #include <ucontext.h>
1480 #ifdef __stub_makecontext
1481 #error Ignoring glibc stub makecontext which will always fail
1482 #endif
1483 int main(void) { makecontext(0, 0, 0); return 0; }
1484 EOF
1485 if compile_prog "" "" ; then
1486 ucontext_works=yes
1487 fi
1488 fi
1489
1490 if test "$coroutine" = ""; then
1491 if test "$mingw32" = "yes"; then
1492 coroutine=win32
1493 elif test "$ucontext_works" = "yes"; then
1494 coroutine=ucontext
1495 else
1496 coroutine=sigaltstack
1497 fi
1498 else
1499 case $coroutine in
1500 windows)
1501 if test "$mingw32" != "yes"; then
1502 error_exit "'windows' coroutine backend only valid for Windows"
1503 fi
1504 # Unfortunately the user visible backend name doesn't match the
1505 # coroutine-*.c filename for this case, so we have to adjust it here.
1506 coroutine=win32
1507 ;;
1508 ucontext)
1509 if test "$ucontext_works" != "yes"; then
1510 error_exit "'ucontext' backend requested but makecontext not available"
1511 fi
1512 ;;
1513 sigaltstack)
1514 if test "$mingw32" = "yes"; then
1515 error_exit "only the 'windows' coroutine backend is valid for Windows"
1516 fi
1517 ;;
1518 *)
1519 error_exit "unknown coroutine backend $coroutine"
1520 ;;
1521 esac
1522 fi
1523
1524 ##################################################
1525 # SafeStack
1526
1527
1528 if test "$safe_stack" = "yes"; then
1529 cat > $TMPC << EOF
1530 int main(void)
1531 {
1532 #if ! __has_feature(safe_stack)
1533 #error SafeStack Disabled
1534 #endif
1535 return 0;
1536 }
1537 EOF
1538 flag="-fsanitize=safe-stack"
1539 # Check that safe-stack is supported and enabled.
1540 if compile_prog "-Werror $flag" "$flag"; then
1541 # Flag needed both at compilation and at linking
1542 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1543 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
1544 else
1545 error_exit "SafeStack not supported by your compiler"
1546 fi
1547 if test "$coroutine" != "ucontext"; then
1548 error_exit "SafeStack is only supported by the coroutine backend ucontext"
1549 fi
1550 else
1551 cat > $TMPC << EOF
1552 int main(void)
1553 {
1554 #if defined(__has_feature)
1555 #if __has_feature(safe_stack)
1556 #error SafeStack Enabled
1557 #endif
1558 #endif
1559 return 0;
1560 }
1561 EOF
1562 if test "$safe_stack" = "no"; then
1563 # Make sure that safe-stack is disabled
1564 if ! compile_prog "-Werror" ""; then
1565 # SafeStack was already enabled, try to explicitly remove the feature
1566 flag="-fno-sanitize=safe-stack"
1567 if ! compile_prog "-Werror $flag" "$flag"; then
1568 error_exit "Configure cannot disable SafeStack"
1569 fi
1570 QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1571 QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
1572 fi
1573 else # "$safe_stack" = ""
1574 # Set safe_stack to yes or no based on pre-existing flags
1575 if compile_prog "-Werror" ""; then
1576 safe_stack="no"
1577 else
1578 safe_stack="yes"
1579 if test "$coroutine" != "ucontext"; then
1580 error_exit "SafeStack is only supported by the coroutine backend ucontext"
1581 fi
1582 fi
1583 fi
1584 fi
1585
1586 ########################################
1587 # check if ccache is interfering with
1588 # semantic analysis of macros
1589
1590 unset CCACHE_CPP2
1591 ccache_cpp2=no
1592 cat > $TMPC << EOF
1593 static const int Z = 1;
1594 #define fn() ({ Z; })
1595 #define TAUT(X) ((X) == Z)
1596 #define PAREN(X, Y) (X == Y)
1597 #define ID(X) (X)
1598 int main(void)
1599 {
1600 int x = 0, y = 0;
1601 x = ID(x);
1602 x = fn();
1603 fn();
1604 if (PAREN(x, y)) return 0;
1605 if (TAUT(Z)) return 0;
1606 return 0;
1607 }
1608 EOF
1609
1610 if ! compile_object "-Werror"; then
1611 ccache_cpp2=yes
1612 fi
1613
1614 ##########################################
1615 # functions to probe cross compilers
1616
1617 container="no"
1618 runc=""
1619 if test $use_containers = "yes" && (has "docker" || has "podman"); then
1620 case $($python "$source_path"/tests/docker/docker.py probe) in
1621 *docker) container=docker ;;
1622 podman) container=podman ;;
1623 no) container=no ;;
1624 esac
1625 if test "$container" != "no"; then
1626 docker_py="$python $source_path/tests/docker/docker.py --engine $container"
1627 runc=$($python "$source_path"/tests/docker/docker.py probe)
1628 fi
1629 fi
1630
1631 # cross compilers defaults, can be overridden with --cross-cc-ARCH
1632 : ${cross_prefix_aarch64="aarch64-linux-gnu-"}
1633 : ${cross_prefix_aarch64_be="$cross_prefix_aarch64"}
1634 : ${cross_prefix_alpha="alpha-linux-gnu-"}
1635 : ${cross_prefix_arm="arm-linux-gnueabihf-"}
1636 : ${cross_prefix_armeb="$cross_prefix_arm"}
1637 : ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
1638 : ${cross_prefix_loongarch64="loongarch64-unknown-linux-gnu-"}
1639 : ${cross_prefix_hppa="hppa-linux-gnu-"}
1640 : ${cross_prefix_i386="i686-linux-gnu-"}
1641 : ${cross_prefix_m68k="m68k-linux-gnu-"}
1642 : ${cross_prefix_microblaze="microblaze-linux-musl-"}
1643 : ${cross_prefix_mips64el="mips64el-linux-gnuabi64-"}
1644 : ${cross_prefix_mips64="mips64-linux-gnuabi64-"}
1645 : ${cross_prefix_mipsel="mipsel-linux-gnu-"}
1646 : ${cross_prefix_mips="mips-linux-gnu-"}
1647 : ${cross_prefix_nios2="nios2-linux-gnu-"}
1648 : ${cross_prefix_ppc="powerpc-linux-gnu-"}
1649 : ${cross_prefix_ppc64="powerpc64-linux-gnu-"}
1650 : ${cross_prefix_ppc64le="$cross_prefix_ppc64"}
1651 : ${cross_prefix_riscv64="riscv64-linux-gnu-"}
1652 : ${cross_prefix_s390x="s390x-linux-gnu-"}
1653 : ${cross_prefix_sh4="sh4-linux-gnu-"}
1654 : ${cross_prefix_sparc64="sparc64-linux-gnu-"}
1655 : ${cross_prefix_sparc="$cross_prefix_sparc64"}
1656 : ${cross_prefix_x86_64="x86_64-linux-gnu-"}
1657
1658 : ${cross_cc_aarch64_be="$cross_cc_aarch64"}
1659 : ${cross_cc_cflags_aarch64_be="-mbig-endian"}
1660 : ${cross_cc_armeb="$cross_cc_arm"}
1661 : ${cross_cc_cflags_armeb="-mbig-endian"}
1662 : ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
1663 : ${cross_cc_cflags_hexagon="-mv67 -O2 -static"}
1664 : ${cross_cc_cflags_i386="-m32"}
1665 : ${cross_cc_cflags_ppc="-m32 -mbig-endian"}
1666 : ${cross_cc_cflags_ppc64="-m64 -mbig-endian"}
1667 : ${cross_cc_ppc64le="$cross_cc_ppc64"}
1668 : ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"}
1669 : ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
1670 : ${cross_cc_sparc="$cross_cc_sparc64"}
1671 : ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
1672 : ${cross_cc_cflags_x86_64="-m64"}
1673
1674 compute_target_variable() {
1675 eval "$2="
1676 if eval test -n "\"\${cross_prefix_$1}\""; then
1677 if eval has "\"\${cross_prefix_$1}\$3\""; then
1678 eval "$2=\"\${cross_prefix_$1}\$3\""
1679 fi
1680 fi
1681 }
1682
1683 have_target() {
1684 for i; do
1685 case " $target_list " in
1686 *" $i "*) return 0;;
1687 *) ;;
1688 esac
1689 done
1690 return 1
1691 }
1692
1693 # probe_target_compiler TARGET
1694 #
1695 # Look for a compiler for the given target, either native or cross.
1696 # Set variables target_* if a compiler is found, and container_cross_*
1697 # if a Docker-based cross-compiler image is known for the target.
1698 # Set got_cross_cc to yes/no depending on whether a non-container-based
1699 # compiler was found.
1700 #
1701 # If TARGET is a user-mode emulation target, also set build_static to
1702 # "y" if static linking is possible.
1703 #
1704 probe_target_compiler() {
1705 # reset all output variables
1706 got_cross_cc=no
1707 container_image=
1708 container_hosts=
1709 container_cross_cc=
1710 container_cross_ar=
1711 container_cross_as=
1712 container_cross_ld=
1713 container_cross_nm=
1714 container_cross_objcopy=
1715 container_cross_ranlib=
1716 container_cross_strip=
1717
1718 # We shall skip configuring the target compiler if the user didn't
1719 # bother enabling an appropriate guest. This avoids building
1720 # extraneous firmware images and tests.
1721 if test "${target_list#*$1}" = "$1"; then
1722 return 1
1723 fi
1724
1725 target_arch=${1%%-*}
1726 case $target_arch in
1727 aarch64) container_hosts="x86_64 aarch64" ;;
1728 alpha) container_hosts=x86_64 ;;
1729 arm) container_hosts="x86_64 aarch64" ;;
1730 cris) container_hosts=x86_64 ;;
1731 hexagon) container_hosts=x86_64 ;;
1732 hppa) container_hosts=x86_64 ;;
1733 i386) container_hosts=x86_64 ;;
1734 loongarch64) container_hosts=x86_64 ;;
1735 m68k) container_hosts=x86_64 ;;
1736 microblaze) container_hosts=x86_64 ;;
1737 mips64el) container_hosts=x86_64 ;;
1738 mips64) container_hosts=x86_64 ;;
1739 mipsel) container_hosts=x86_64 ;;
1740 mips) container_hosts=x86_64 ;;
1741 nios2) container_hosts=x86_64 ;;
1742 ppc) container_hosts=x86_64 ;;
1743 ppc64|ppc64le) container_hosts=x86_64 ;;
1744 riscv64) container_hosts=x86_64 ;;
1745 s390x) container_hosts=x86_64 ;;
1746 sh4) container_hosts=x86_64 ;;
1747 sparc64) container_hosts=x86_64 ;;
1748 tricore) container_hosts=x86_64 ;;
1749 x86_64) container_hosts="aarch64 ppc64el x86_64" ;;
1750 xtensa*) container_hosts=x86_64 ;;
1751 esac
1752
1753 for host in $container_hosts; do
1754 test "$container" != no || continue
1755 test "$host" = "$cpu" || continue
1756 case $target_arch in
1757 aarch64)
1758 # We don't have any bigendian build tools so we only use this for AArch64
1759 container_image=debian-arm64-cross
1760 container_cross_prefix=aarch64-linux-gnu-
1761 container_cross_cc=${container_cross_prefix}gcc-10
1762 ;;
1763 alpha)
1764 container_image=debian-alpha-cross
1765 container_cross_prefix=alpha-linux-gnu-
1766 ;;
1767 arm)
1768 # We don't have any bigendian build tools so we only use this for ARM
1769 container_image=debian-armhf-cross
1770 container_cross_prefix=arm-linux-gnueabihf-
1771 ;;
1772 cris)
1773 container_image=fedora-cris-cross
1774 container_cross_prefix=cris-linux-gnu-
1775 ;;
1776 hexagon)
1777 container_image=debian-hexagon-cross
1778 container_cross_prefix=hexagon-unknown-linux-musl-
1779 container_cross_cc=${container_cross_prefix}clang
1780 ;;
1781 hppa)
1782 container_image=debian-hppa-cross
1783 container_cross_prefix=hppa-linux-gnu-
1784 ;;
1785 i386)
1786 container_image=fedora-i386-cross
1787 container_cross_prefix=
1788 ;;
1789 loongarch64)
1790 container_image=debian-loongarch-cross
1791 container_cross_prefix=loongarch64-unknown-linux-gnu-
1792 ;;
1793 m68k)
1794 container_image=debian-m68k-cross
1795 container_cross_prefix=m68k-linux-gnu-
1796 ;;
1797 microblaze)
1798 container_image=debian-microblaze-cross
1799 container_cross_prefix=microblaze-linux-musl-
1800 ;;
1801 mips64el)
1802 container_image=debian-mips64el-cross
1803 container_cross_prefix=mips64el-linux-gnuabi64-
1804 ;;
1805 mips64)
1806 container_image=debian-mips64-cross
1807 container_cross_prefix=mips64-linux-gnuabi64-
1808 ;;
1809 mipsel)
1810 container_image=debian-mipsel-cross
1811 container_cross_prefix=mipsel-linux-gnu-
1812 ;;
1813 mips)
1814 container_image=debian-mips-cross
1815 container_cross_prefix=mips-linux-gnu-
1816 ;;
1817 nios2)
1818 container_image=debian-nios2-cross
1819 container_cross_prefix=nios2-linux-gnu-
1820 ;;
1821 ppc)
1822 container_image=debian-powerpc-test-cross
1823 container_cross_prefix=powerpc-linux-gnu-
1824 container_cross_cc=${container_cross_prefix}gcc-10
1825 ;;
1826 ppc64|ppc64le)
1827 container_image=debian-powerpc-test-cross
1828 container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu-
1829 container_cross_cc=${container_cross_prefix}gcc-10
1830 ;;
1831 riscv64)
1832 container_image=debian-riscv64-test-cross
1833 container_cross_prefix=riscv64-linux-gnu-
1834 ;;
1835 s390x)
1836 container_image=debian-s390x-cross
1837 container_cross_prefix=s390x-linux-gnu-
1838 ;;
1839 sh4)
1840 container_image=debian-sh4-cross
1841 container_cross_prefix=sh4-linux-gnu-
1842 ;;
1843 sparc64)
1844 container_image=debian-sparc64-cross
1845 container_cross_prefix=sparc64-linux-gnu-
1846 ;;
1847 tricore)
1848 container_image=debian-tricore-cross
1849 container_cross_prefix=tricore-
1850 container_cross_as=tricore-as
1851 container_cross_ld=tricore-ld
1852 break
1853 ;;
1854 x86_64)
1855 container_image=debian-amd64-cross
1856 container_cross_prefix=x86_64-linux-gnu-
1857 ;;
1858 xtensa*)
1859 container_hosts=x86_64
1860 container_image=debian-xtensa-cross
1861
1862 # default to the dc232b cpu
1863 container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
1864 ;;
1865 esac
1866 : ${container_cross_cc:=${container_cross_prefix}gcc}
1867 : ${container_cross_ar:=${container_cross_prefix}ar}
1868 : ${container_cross_as:=${container_cross_prefix}as}
1869 : ${container_cross_ld:=${container_cross_prefix}ld}
1870 : ${container_cross_nm:=${container_cross_prefix}nm}
1871 : ${container_cross_objcopy:=${container_cross_prefix}objcopy}
1872 : ${container_cross_ranlib:=${container_cross_prefix}ranlib}
1873 : ${container_cross_strip:=${container_cross_prefix}strip}
1874 done
1875
1876 try=cross
1877 case "$target_arch:$cpu" in
1878 aarch64_be:aarch64 | \
1879 armeb:arm | \
1880 i386:x86_64 | \
1881 mips*:mips64 | \
1882 ppc*:ppc64 | \
1883 sparc:sparc64 | \
1884 "$cpu:$cpu")
1885 try='native cross' ;;
1886 esac
1887 eval "target_cflags=\${cross_cc_cflags_$target_arch}"
1888 for thistry in $try; do
1889 case $thistry in
1890 native)
1891 target_cc=$cc
1892 target_ccas=$ccas
1893 target_ar=$ar
1894 target_as=$as
1895 target_ld=$ld
1896 target_nm=$nm
1897 target_objcopy=$objcopy
1898 target_ranlib=$ranlib
1899 target_strip=$strip
1900 ;;
1901 cross)
1902 target_cc=
1903 if eval test -n "\"\${cross_cc_$target_arch}\""; then
1904 if eval has "\"\${cross_cc_$target_arch}\""; then
1905 eval "target_cc=\"\${cross_cc_$target_arch}\""
1906 fi
1907 else
1908 compute_target_variable $target_arch target_cc gcc
1909 fi
1910 target_ccas=$target_cc
1911 compute_target_variable $target_arch target_ar ar
1912 compute_target_variable $target_arch target_as as
1913 compute_target_variable $target_arch target_ld ld
1914 compute_target_variable $target_arch target_nm nm
1915 compute_target_variable $target_arch target_objcopy objcopy
1916 compute_target_variable $target_arch target_ranlib ranlib
1917 compute_target_variable $target_arch target_strip strip
1918 ;;
1919 esac
1920
1921 if test -n "$target_cc"; then
1922 case $target_arch in
1923 i386|x86_64)
1924 if $target_cc --version | grep -qi "clang"; then
1925 continue
1926 fi
1927 ;;
1928 esac
1929 elif test -n "$target_as" && test -n "$target_ld"; then
1930 # Special handling for assembler only targets
1931 case $target in
1932 tricore-softmmu)
1933 build_static=
1934 got_cross_cc=yes
1935 break
1936 ;;
1937 *)
1938 continue
1939 ;;
1940 esac
1941 else
1942 continue
1943 fi
1944
1945 write_c_skeleton
1946 case $1 in
1947 *-softmmu)
1948 if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC &&
1949 do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then
1950 got_cross_cc=yes
1951 break
1952 fi
1953 ;;
1954 *)
1955 if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC -static ; then
1956 build_static=y
1957 got_cross_cc=yes
1958 break
1959 fi
1960 if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC ; then
1961 build_static=
1962 got_cross_cc=yes
1963 break
1964 fi
1965 ;;
1966 esac
1967 done
1968 if test $got_cross_cc != yes; then
1969 build_static=
1970 target_cc=
1971 target_ccas=
1972 target_ar=
1973 target_as=
1974 target_ld=
1975 target_nm=
1976 target_objcopy=
1977 target_ranlib=
1978 target_strip=
1979 fi
1980 test -n "$target_cc"
1981 }
1982
1983 write_target_makefile() {
1984 echo "EXTRA_CFLAGS=$target_cflags"
1985 if test -z "$target_cc" && test -z "$target_as"; then
1986 test -z "$container_image" && error_exit "Internal error: could not find cross compiler for $1?"
1987 echo "$1: docker-image-$container_image" >> Makefile.prereqs
1988 if test -n "$container_cross_cc"; then
1989 echo "CC=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
1990 echo "CCAS=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
1991 fi
1992 echo "AR=$docker_py cc --cc $container_cross_ar -i qemu/$container_image -s $source_path --"
1993 echo "AS=$docker_py cc --cc $container_cross_as -i qemu/$container_image -s $source_path --"
1994 echo "LD=$docker_py cc --cc $container_cross_ld -i qemu/$container_image -s $source_path --"
1995 echo "NM=$docker_py cc --cc $container_cross_nm -i qemu/$container_image -s $source_path --"
1996 echo "OBJCOPY=$docker_py cc --cc $container_cross_objcopy -i qemu/$container_image -s $source_path --"
1997 echo "RANLIB=$docker_py cc --cc $container_cross_ranlib -i qemu/$container_image -s $source_path --"
1998 echo "STRIP=$docker_py cc --cc $container_cross_strip -i qemu/$container_image -s $source_path --"
1999 else
2000 if test -n "$target_cc"; then
2001 echo "CC=$target_cc"
2002 echo "CCAS=$target_ccas"
2003 fi
2004 if test -n "$target_ar"; then
2005 echo "AR=$target_ar"
2006 fi
2007 if test -n "$target_as"; then
2008 echo "AS=$target_as"
2009 fi
2010 if test -n "$target_ld"; then
2011 echo "LD=$target_ld"
2012 fi
2013 if test -n "$target_nm"; then
2014 echo "NM=$target_nm"
2015 fi
2016 if test -n "$target_objcopy"; then
2017 echo "OBJCOPY=$target_objcopy"
2018 fi
2019 if test -n "$target_ranlib"; then
2020 echo "RANLIB=$target_ranlib"
2021 fi
2022 if test -n "$target_strip"; then
2023 echo "STRIP=$target_strip"
2024 fi
2025 fi
2026 }
2027
2028 ##########################################
2029 # check for vfio_user_server
2030
2031 case "$vfio_user_server" in
2032 enabled )
2033 if test "$git_submodules_action" != "ignore"; then
2034 git_submodules="${git_submodules} subprojects/libvfio-user"
2035 fi
2036 ;;
2037 esac
2038
2039 #######################################
2040 # cross-compiled firmware targets
2041
2042 # Set up build tree symlinks that point back into the source tree
2043 # (these can be both files and directories).
2044 # Caution: avoid adding files or directories here using wildcards. This
2045 # will result in problems later if a new file matching the wildcard is
2046 # added to the source tree -- nothing will cause configure to be rerun
2047 # so the build tree will be missing the link back to the new file, and
2048 # tests might fail. Prefer to keep the relevant files in their own
2049 # directory and symlink the directory instead.
2050 LINKS="Makefile"
2051 LINKS="$LINKS docs/config"
2052 LINKS="$LINKS pc-bios/optionrom/Makefile"
2053 LINKS="$LINKS pc-bios/s390-ccw/Makefile"
2054 LINKS="$LINKS pc-bios/vof/Makefile"
2055 LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
2056 LINKS="$LINKS tests/avocado tests/data"
2057 LINKS="$LINKS tests/qemu-iotests/check"
2058 LINKS="$LINKS python"
2059 LINKS="$LINKS contrib/plugins/Makefile "
2060 for f in $LINKS ; do
2061 if [ -e "$source_path/$f" ]; then
2062 mkdir -p "$(dirname ./"$f")"
2063 symlink "$source_path/$f" "$f"
2064 fi
2065 done
2066
2067 echo "# Automatically generated by configure - do not modify" > Makefile.prereqs
2068
2069 # Mac OS X ships with a broken assembler
2070 roms=
2071 if have_target i386-softmmu x86_64-softmmu && \
2072 test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
2073 test "$targetos" != "haiku" && \
2074 probe_target_compiler i386-softmmu; then
2075 roms="pc-bios/optionrom"
2076 config_mak=pc-bios/optionrom/config.mak
2077 echo "# Automatically generated by configure - do not modify" > $config_mak
2078 echo "TOPSRC_DIR=$source_path" >> $config_mak
2079 write_target_makefile >> $config_mak
2080 fi
2081
2082 if have_target ppc-softmmu ppc64-softmmu && \
2083 probe_target_compiler ppc-softmmu; then
2084 roms="$roms pc-bios/vof"
2085 config_mak=pc-bios/vof/config.mak
2086 echo "# Automatically generated by configure - do not modify" > $config_mak
2087 echo "SRC_DIR=$source_path/pc-bios/vof" >> $config_mak
2088 write_target_makefile >> $config_mak
2089 fi
2090
2091 # Only build s390-ccw bios if the compiler has -march=z900 or -march=z10
2092 # (which is the lowest architecture level that Clang supports)
2093 if have_target s390x-softmmu && probe_target_compiler s390x-softmmu; then
2094 write_c_skeleton
2095 do_compiler "$target_cc" $target_cc_cflags -march=z900 -o $TMPO -c $TMPC
2096 has_z900=$?
2097 if [ $has_z900 = 0 ] || do_compiler "$target_cc" $target_cc_cflags -march=z10 -msoft-float -Werror -o $TMPO -c $TMPC; then
2098 if [ $has_z900 != 0 ]; then
2099 echo "WARNING: Your compiler does not support the z900!"
2100 echo " The s390-ccw bios will only work with guest CPUs >= z10."
2101 fi
2102 roms="$roms pc-bios/s390-ccw"
2103 config_mak=pc-bios/s390-ccw/config-host.mak
2104 echo "# Automatically generated by configure - do not modify" > $config_mak
2105 echo "SRC_PATH=$source_path/pc-bios/s390-ccw" >> $config_mak
2106 write_target_makefile >> $config_mak
2107 # SLOF is required for building the s390-ccw firmware on s390x,
2108 # since it is using the libnet code from SLOF for network booting.
2109 git_submodules="${git_submodules} roms/SLOF"
2110 fi
2111 fi
2112
2113 #######################################
2114 # generate config-host.mak
2115
2116 if ! (GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
2117 exit 1
2118 fi
2119
2120 config_host_mak="config-host.mak"
2121
2122 echo "# Automatically generated by configure - do not modify" > $config_host_mak
2123 echo >> $config_host_mak
2124
2125 echo all: >> $config_host_mak
2126 echo "GIT=$git" >> $config_host_mak
2127 echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
2128 echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
2129
2130 if test "$debug_tcg" = "yes" ; then
2131 echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
2132 fi
2133 if test "$mingw32" = "yes" ; then
2134 echo "CONFIG_WIN32=y" >> $config_host_mak
2135 echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER-QEMU}" >> $config_host_mak
2136 echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO-Linux}" >> $config_host_mak
2137 echo "QEMU_GA_VERSION=${QEMU_GA_VERSION-$(cat "$source_path"/VERSION)}" >> $config_host_mak
2138 else
2139 echo "CONFIG_POSIX=y" >> $config_host_mak
2140 fi
2141
2142 if test "$linux" = "yes" ; then
2143 echo "CONFIG_LINUX=y" >> $config_host_mak
2144 fi
2145
2146 if test "$darwin" = "yes" ; then
2147 echo "CONFIG_DARWIN=y" >> $config_host_mak
2148 fi
2149
2150 if test "$solaris" = "yes" ; then
2151 echo "CONFIG_SOLARIS=y" >> $config_host_mak
2152 fi
2153 echo "SRC_PATH=$source_path" >> $config_host_mak
2154 echo "TARGET_DIRS=$target_list" >> $config_host_mak
2155
2156 # XXX: suppress that
2157 if [ "$bsd" = "yes" ] ; then
2158 echo "CONFIG_BSD=y" >> $config_host_mak
2159 fi
2160
2161 echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
2162
2163 if test "$plugins" = "yes" ; then
2164 echo "CONFIG_PLUGIN=y" >> $config_host_mak
2165 fi
2166
2167 if test -n "$gdb_bin"; then
2168 gdb_version=$($gdb_bin --version | head -n 1)
2169 if version_ge ${gdb_version##* } 9.1; then
2170 echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
2171 gdb_arches=$("$source_path/scripts/probe-gdb-support.py" $gdb_bin)
2172 else
2173 gdb_bin=""
2174 fi
2175 fi
2176
2177 if test "$container" != no; then
2178 echo "ENGINE=$container" >> $config_host_mak
2179 echo "RUNC=$runc" >> $config_host_mak
2180 fi
2181 echo "ROMS=$roms" >> $config_host_mak
2182 echo "MAKE=$make" >> $config_host_mak
2183 echo "PYTHON=$python" >> $config_host_mak
2184 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
2185 echo "MESON=$meson" >> $config_host_mak
2186 echo "NINJA=$ninja" >> $config_host_mak
2187 echo "PKG_CONFIG=${pkg_config}" >> $config_host_mak
2188 echo "CC=$cc" >> $config_host_mak
2189 echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
2190 echo "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak
2191 echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
2192 echo "EXESUF=$EXESUF" >> $config_host_mak
2193
2194 # use included Linux headers
2195 if test "$linux" = "yes" ; then
2196 mkdir -p linux-headers
2197 case "$cpu" in
2198 i386|x86_64)
2199 linux_arch=x86
2200 ;;
2201 ppc|ppc64)
2202 linux_arch=powerpc
2203 ;;
2204 s390x)
2205 linux_arch=s390
2206 ;;
2207 aarch64)
2208 linux_arch=arm64
2209 ;;
2210 loongarch*)
2211 linux_arch=loongarch
2212 ;;
2213 mips64)
2214 linux_arch=mips
2215 ;;
2216 *)
2217 # For most CPUs the kernel architecture name and QEMU CPU name match.
2218 linux_arch="$cpu"
2219 ;;
2220 esac
2221 # For non-KVM architectures we will not have asm headers
2222 if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
2223 symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
2224 fi
2225 fi
2226
2227 for target in $target_list; do
2228 target_dir="$target"
2229 target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
2230 mkdir -p "$target_dir"
2231 case $target in
2232 *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
2233 *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
2234 esac
2235 done
2236
2237 if test "$default_targets" = "yes"; then
2238 echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
2239 fi
2240
2241 if test "$ccache_cpp2" = "yes"; then
2242 echo "export CCACHE_CPP2=y" >> $config_host_mak
2243 fi
2244
2245 if test "$safe_stack" = "yes"; then
2246 echo "CONFIG_SAFESTACK=y" >> $config_host_mak
2247 fi
2248
2249 # tests/tcg configuration
2250 (config_host_mak=tests/tcg/config-host.mak
2251 mkdir -p tests/tcg
2252 echo "# Automatically generated by configure - do not modify" > $config_host_mak
2253 echo "SRC_PATH=$source_path" >> $config_host_mak
2254 echo "HOST_CC=$host_cc" >> $config_host_mak
2255
2256 # versioned checked in the main config_host.mak above
2257 if test -n "$gdb_bin"; then
2258 echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
2259 fi
2260 if test "$plugins" = "yes" ; then
2261 echo "CONFIG_PLUGIN=y" >> $config_host_mak
2262 fi
2263
2264 tcg_tests_targets=
2265 for target in $target_list; do
2266 arch=${target%%-*}
2267
2268 case $target in
2269 xtensa*-linux-user)
2270 # the toolchain is not complete with headers, only build softmmu tests
2271 continue
2272 ;;
2273 *-softmmu)
2274 test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || continue
2275 qemu="qemu-system-$arch"
2276 ;;
2277 *-linux-user|*-bsd-user)
2278 qemu="qemu-$arch"
2279 ;;
2280 esac
2281
2282 if probe_target_compiler $target || test -n "$container_image"; then
2283 test -n "$container_image" && build_static=y
2284 mkdir -p "tests/tcg/$target"
2285 config_target_mak=tests/tcg/$target/config-target.mak
2286 ln -sf "$source_path/tests/tcg/Makefile.target" "tests/tcg/$target/Makefile"
2287 echo "# Automatically generated by configure - do not modify" > "$config_target_mak"
2288 echo "TARGET_NAME=$arch" >> "$config_target_mak"
2289 echo "TARGET=$target" >> "$config_target_mak"
2290 write_target_makefile "build-tcg-tests-$target" >> "$config_target_mak"
2291 echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
2292 echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
2293
2294 # will GDB work with these binaries?
2295 if test "${gdb_arches#*$arch}" != "$gdb_arches"; then
2296 echo "HOST_GDB_SUPPORTS_ARCH=y" >> "$config_target_mak"
2297 fi
2298
2299 echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs
2300 tcg_tests_targets="$tcg_tests_targets $target"
2301 fi
2302 done
2303
2304 if test "$tcg" = "enabled"; then
2305 echo "TCG_TESTS_TARGETS=$tcg_tests_targets" >> config-host.mak
2306 fi
2307 )
2308
2309 if test "$skip_meson" = no; then
2310 cross="config-meson.cross.new"
2311 meson_quote() {
2312 test $# = 0 && return
2313 echo "'$(echo $* | sed "s/ /','/g")'"
2314 }
2315
2316 echo "# Automatically generated by configure - do not modify" > $cross
2317 echo "[properties]" >> $cross
2318
2319 # unroll any custom device configs
2320 for a in $device_archs; do
2321 eval "c=\$devices_${a}"
2322 echo "${a}-softmmu = '$c'" >> $cross
2323 done
2324
2325 echo "[built-in options]" >> $cross
2326 echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
2327 echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
2328 test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
2329 echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
2330 echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
2331 echo "[binaries]" >> $cross
2332 echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
2333 test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
2334 test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
2335 echo "ar = [$(meson_quote $ar)]" >> $cross
2336 echo "nm = [$(meson_quote $nm)]" >> $cross
2337 echo "pkgconfig = [$(meson_quote $pkg_config)]" >> $cross
2338 echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
2339 if has $sdl2_config; then
2340 echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
2341 fi
2342 echo "strip = [$(meson_quote $strip)]" >> $cross
2343 echo "widl = [$(meson_quote $widl)]" >> $cross
2344 echo "windres = [$(meson_quote $windres)]" >> $cross
2345 echo "windmc = [$(meson_quote $windmc)]" >> $cross
2346 if test "$cross_compile" = "yes"; then
2347 cross_arg="--cross-file config-meson.cross"
2348 echo "[host_machine]" >> $cross
2349 echo "system = '$targetos'" >> $cross
2350 case "$cpu" in
2351 i386)
2352 echo "cpu_family = 'x86'" >> $cross
2353 ;;
2354 *)
2355 echo "cpu_family = '$cpu'" >> $cross
2356 ;;
2357 esac
2358 echo "cpu = '$cpu'" >> $cross
2359 if test "$bigendian" = "yes" ; then
2360 echo "endian = 'big'" >> $cross
2361 else
2362 echo "endian = 'little'" >> $cross
2363 fi
2364 else
2365 cross_arg="--native-file config-meson.cross"
2366 fi
2367 mv $cross config-meson.cross
2368
2369 rm -rf meson-private meson-info meson-logs
2370
2371 # Prevent meson from automatically downloading wrapped subprojects when missing.
2372 # You can use 'meson subprojects download' before running configure.
2373 meson_option_add "--wrap-mode=nodownload"
2374
2375 # Built-in options
2376 test "$bindir" != "bin" && meson_option_add "-Dbindir=$bindir"
2377 test "$default_feature" = no && meson_option_add -Dauto_features=disabled
2378 test "$static" = yes && meson_option_add -Dprefer_static=true
2379 test "$pie" = no && meson_option_add -Db_pie=false
2380 test "$werror" = yes && meson_option_add -Dwerror=true
2381
2382 # QEMU options
2383 test "$cfi" != false && meson_option_add "-Dcfi=$cfi"
2384 test "$docs" != auto && meson_option_add "-Ddocs=$docs"
2385 test "$fdt" != auto && meson_option_add "-Dfdt=$fdt"
2386 test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
2387 test "$qemu_suffix" != qemu && meson_option_add "-Dqemu_suffix=$qemu_suffix"
2388 test "$smbd" != '' && meson_option_add "-Dsmbd=$smbd"
2389 test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
2390 test "$vfio_user_server" != auto && meson_option_add "-Dvfio_user_server=$vfio_user_server"
2391 run_meson() {
2392 NINJA=$ninja $meson setup --prefix "$prefix" "$@" $cross_arg "$PWD" "$source_path"
2393 }
2394 eval run_meson $meson_options
2395 if test "$?" -ne 0 ; then
2396 error_exit "meson setup failed"
2397 fi
2398 fi
2399
2400 # Save the configure command line for later reuse.
2401 cat <<EOD >config.status
2402 #!/bin/sh
2403 # Generated by configure.
2404 # Run this file to recreate the current configuration.
2405 # Compiler output produced by configure, useful for debugging
2406 # configure, is in config.log if it exists.
2407 EOD
2408
2409 preserve_env() {
2410 envname=$1
2411
2412 eval envval=\$$envname
2413
2414 if test -n "$envval"
2415 then
2416 echo "$envname='$envval'" >> config.status
2417 echo "export $envname" >> config.status
2418 else
2419 echo "unset $envname" >> config.status
2420 fi
2421 }
2422
2423 # Preserve various env variables that influence what
2424 # features/build target configure will detect
2425 preserve_env AR
2426 preserve_env AS
2427 preserve_env CC
2428 preserve_env CFLAGS
2429 preserve_env CXX
2430 preserve_env CXXFLAGS
2431 preserve_env LD
2432 preserve_env LDFLAGS
2433 preserve_env LD_LIBRARY_PATH
2434 preserve_env MAKE
2435 preserve_env NM
2436 preserve_env OBJCFLAGS
2437 preserve_env OBJCOPY
2438 preserve_env PATH
2439 preserve_env PKG_CONFIG
2440 preserve_env PKG_CONFIG_LIBDIR
2441 preserve_env PKG_CONFIG_PATH
2442 preserve_env PYTHON
2443 preserve_env QEMU_GA_MANUFACTURER
2444 preserve_env QEMU_GA_DISTRO
2445 preserve_env QEMU_GA_VERSION
2446 preserve_env SDL2_CONFIG
2447 preserve_env SMBD
2448 preserve_env STRIP
2449 preserve_env WIDL
2450 preserve_env WINDRES
2451 preserve_env WINDMC
2452
2453 printf "exec" >>config.status
2454 for i in "$0" "$@"; do
2455 test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
2456 done
2457 echo ' "$@"' >>config.status
2458 chmod +x config.status
2459
2460 rm -r "$TMPDIR1"