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