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