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