Merge tag 'v8.1.0-rc3'
[qemu/ar7.git] / configure
blob0328d8948293557214e52e49d560b05973853818
1 #!/bin/sh
3 # qemu configure script (c) 2003 Fabrice Bellard
6 # Unset some variables known to interfere with behavior of common tools,
7 # just as autoconf does. Unlike autoconf, we assume that unset exists.
8 unset CLICOLOR_FORCE GREP_OPTIONS BASH_ENV ENV MAIL MAILPATH CDPATH
10 # Don't allow CCACHE, if present, to use cached results of compile tests!
11 export CCACHE_RECACHE=yes
13 # make source path absolute
14 source_path=$(cd "$(dirname -- "$0")"; pwd)
16 if test "$PWD" = "$source_path"
17 then
18 echo "Using './build' as the directory for build output"
20 MARKER=build/auto-created-by-configure
22 if test -e build
23 then
24 if test -f $MARKER
25 then
26 rm -rf build
27 else
28 echo "ERROR: ./build dir already exists and was not previously created by configure"
29 exit 1
33 if ! mkdir build || ! touch $MARKER
34 then
35 echo "ERROR: Could not create ./build directory. Check the permissions on"
36 echo "your source directory, or try doing an out-of-tree build."
37 exit 1
40 cat > GNUmakefile <<'EOF'
41 # This file is auto-generated by configure to support in-source tree
42 # 'make' command invocation
44 ifeq ($(MAKECMDGOALS),)
45 recurse: all
46 endif
48 .NOTPARALLEL: %
49 %: force
50 @echo 'changing dir to build for $(MAKE) "$(MAKECMDGOALS)"...'
51 @$(MAKE) -C build -f Makefile $(MAKECMDGOALS)
52 @if test "$(MAKECMDGOALS)" = "distclean" && \
53 test -e build/auto-created-by-configure ; \
54 then \
55 rm -rf build GNUmakefile ; \
57 force: ;
58 .PHONY: force
59 GNUmakefile: ;
61 EOF
62 cd build
63 exec "$source_path/configure" "$@"
66 # Temporary directory used for files created while
67 # configure runs. Since it is in the build directory
68 # we can safely blow away any previous version of it
69 # (and we need not jump through hoops to try to delete
70 # it when configure exits.)
71 TMPDIR1="config-temp"
72 rm -rf "${TMPDIR1}"
73 if ! mkdir -p "${TMPDIR1}"; then
74 echo "ERROR: failed to create temporary directory"
75 exit 1
78 TMPB="qemu-conf"
79 TMPC="${TMPDIR1}/${TMPB}.c"
80 TMPO="${TMPDIR1}/${TMPB}.o"
81 TMPE="${TMPDIR1}/${TMPB}.exe"
83 rm -f config.log
85 # Print a helpful header at the top of config.log
86 echo "# QEMU configure log $(date)" >> config.log
87 printf "# Configured with:" >> config.log
88 # repeat the invocation to log and stdout for CI
89 invoke=$(printf " '%s'" "$0" "$@")
90 test -n "$GITLAB_CI" && echo "configuring with: $invoke"
91 { echo "$invoke"; echo; echo "#"; } >> config.log
93 quote_sh() {
94 printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
97 print_error() {
98 (echo
99 echo "ERROR: $1"
100 while test -n "$2"; do
101 echo " $2"
102 shift
103 done
104 echo) >&2
107 error_exit() {
108 print_error "$@"
109 exit 1
112 do_compiler() {
113 # Run the compiler, capturing its output to the log. First argument
114 # is compiler binary to execute.
115 compiler="$1"
116 shift
117 if test -n "$BASH_VERSION"; then eval '
118 echo >>config.log "
119 funcs: ${FUNCNAME[*]}
120 lines: ${BASH_LINENO[*]}"
121 '; fi
122 echo $compiler "$@" >> config.log
123 $compiler "$@" >> config.log 2>&1 || return $?
126 do_cc() {
127 do_compiler "$cc" $CPU_CFLAGS "$@"
130 compile_object() {
131 local_cflags="$1"
132 do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -c -o $TMPO $TMPC
135 compile_prog() {
136 local_cflags="$1"
137 local_ldflags="$2"
138 do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -o $TMPE $TMPC \
139 $LDFLAGS $EXTRA_LDFLAGS $local_ldflags
142 # symbolically link $1 to $2. Portable version of "ln -sf".
143 symlink() {
144 rm -rf "$2"
145 mkdir -p "$(dirname "$2")"
146 ln -s "$1" "$2"
149 # check whether a command is available to this shell (may be either an
150 # executable or a builtin)
151 has() {
152 type "$1" >/dev/null 2>&1
155 version_ge () {
156 local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
157 local_ver2=$(echo "$2" | tr . ' ')
158 while true; do
159 set x $local_ver1
160 local_first=${2-0}
161 # 'shift 2' if $2 is set, or 'shift' if $2 is not set
162 shift ${2:+2}
163 local_ver1=$*
164 set x $local_ver2
165 # the second argument finished, the first must be greater or equal
166 test $# = 1 && return 0
167 test $local_first -lt $2 && return 1
168 test $local_first -gt $2 && return 0
169 shift ${2:+2}
170 local_ver2=$*
171 done
174 if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
175 then
176 error_exit "main directory cannot contain spaces nor colons"
179 # parse CC options first; some compiler tests are used to establish
180 # some defaults, based on the host environment
182 # default parameters
183 cpu=""
184 cross_compile="no"
185 cross_prefix=""
186 host_cc="cc"
187 EXTRA_CFLAGS=""
188 EXTRA_CXXFLAGS=""
189 EXTRA_OBJCFLAGS=""
190 EXTRA_LDFLAGS=""
192 # Default value for a variable defining feature "foo".
193 # * foo="no" feature will only be used if --enable-foo arg is given
194 # * foo="" feature will be searched for, and if found, will be used
195 # unless --disable-foo is given
196 # * foo="yes" this value will only be set by --enable-foo flag.
197 # feature will searched for,
198 # if not found, configure exits with error
200 # Always add --enable-foo and --disable-foo command line args.
201 # Distributions want to ensure that several features are compiled in, and it
202 # is impossible without a --enable-foo that exits if a feature is not found.
203 default_feature=""
205 for opt do
206 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
207 case "$opt" in
208 --cross-prefix=*) cross_prefix="$optarg"
209 cross_compile="yes"
211 --cc=*) CC="$optarg"
213 --cxx=*) CXX="$optarg"
215 --objcc=*) objcc="$optarg"
217 --cpu=*) cpu="$optarg"
219 --extra-cflags=*)
220 EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
221 EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
222 EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
224 --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
226 --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
228 --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
230 --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
232 --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
233 eval "cross_cc_cflags_${cc_arch}=\$optarg"
235 --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
236 eval "cross_cc_${cc_arch}=\$optarg"
238 --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-prefix-FOO option"
240 --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
241 eval "cross_prefix_${cc_arch}=\$optarg"
243 --without-default-features) default_feature="no"
245 esac
246 done
249 git_submodules_action="update"
250 git="git"
251 debug_tcg="no"
252 docs="auto"
253 EXESUF=""
254 prefix="/usr/local"
255 qemu_suffix="qemu"
256 softmmu="yes"
257 linux_user=""
258 bsd_user=""
259 plugins="$default_feature"
260 ninja=""
261 python=
262 download="enabled"
263 bindir="bin"
264 skip_meson=no
265 use_containers="yes"
266 gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
267 gdb_arches=""
268 werror=""
270 # Don't accept a target_list environment variable.
271 unset target_list
272 unset target_list_exclude
274 # The following Meson options are handled manually (still they
275 # are included in the automatically generated help message)
276 # because they automatically enable/disable other options
277 tcg="auto"
278 cfi="false"
280 # Meson has PIE as a boolean rather than enabled/disabled/auto,
281 # and we also need to check for -static-pie before Meson runs
282 # which requires knowing whether --static is enabled.
283 pie=""
284 static="no"
286 # Preferred compiler:
287 # ${CC} (if set)
288 # ${cross_prefix}gcc (if cross-prefix specified)
289 # system compiler
290 if test -z "${CC}${cross_prefix}"; then
291 cc="$host_cc"
292 else
293 cc="${CC-${cross_prefix}gcc}"
296 if test -z "${CXX}${cross_prefix}"; then
297 cxx="c++"
298 else
299 cxx="${CXX-${cross_prefix}g++}"
302 # Preferred ObjC compiler:
303 # $objcc (if set, i.e. via --objcc option)
304 # ${cross_prefix}clang (if cross-prefix specified)
305 # clang (if available)
306 # $cc
307 if test -z "${objcc}${cross_prefix}"; then
308 if has clang; then
309 objcc=clang
310 else
311 objcc="$cc"
313 else
314 objcc="${objcc-${cross_prefix}clang}"
317 ar="${AR-${cross_prefix}ar}"
318 as="${AS-${cross_prefix}as}"
319 ccas="${CCAS-$cc}"
320 objcopy="${OBJCOPY-${cross_prefix}objcopy}"
321 ld="${LD-${cross_prefix}ld}"
322 ranlib="${RANLIB-${cross_prefix}ranlib}"
323 nm="${NM-${cross_prefix}nm}"
324 smbd="$SMBD"
325 strip="${STRIP-${cross_prefix}strip}"
326 widl="${WIDL-${cross_prefix}widl}"
327 windres="${WINDRES-${cross_prefix}windres}"
328 windmc="${WINDMC-${cross_prefix}windmc}"
329 pkg_config="${PKG_CONFIG-${cross_prefix}pkg-config}"
330 sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
332 check_define() {
333 rm -f $TMPC
334 cat > $TMPC <<EOF
335 #if !defined($1)
336 #error $1 not defined
337 #endif
338 int main(void) { return 0; }
340 compile_object
343 write_c_skeleton() {
344 cat > $TMPC <<EOF
345 int main(void) { return 0; }
349 if check_define __linux__ ; then
350 targetos=linux
351 elif check_define _WIN32 ; then
352 targetos=windows
353 elif check_define __OpenBSD__ ; then
354 targetos=openbsd
355 elif check_define __sun__ ; then
356 targetos=sunos
357 elif check_define __HAIKU__ ; then
358 targetos=haiku
359 elif check_define __FreeBSD__ ; then
360 targetos=freebsd
361 elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
362 targetos=gnu/kfreebsd
363 elif check_define __DragonFly__ ; then
364 targetos=dragonfly
365 elif check_define __NetBSD__; then
366 targetos=netbsd
367 elif check_define __APPLE__; then
368 targetos=darwin
369 else
370 # This is a fatal error, but don't report it yet, because we
371 # might be going to just print the --help text, or it might
372 # be the result of a missing compiler.
373 targetos=bogus
376 # OS specific
378 mingw32="no"
379 bsd="no"
380 linux="no"
381 solaris="no"
382 case $targetos in
383 windows)
384 mingw32="yes"
385 plugins="no"
386 pie="no"
388 gnu/kfreebsd)
389 bsd="yes"
391 freebsd)
392 bsd="yes"
393 # needed for kinfo_getvmmap(3) in libutil.h
395 dragonfly)
396 bsd="yes"
398 netbsd)
399 bsd="yes"
401 openbsd)
402 bsd="yes"
404 darwin)
405 bsd="yes"
406 darwin="yes"
408 sunos)
409 solaris="yes"
411 haiku)
412 pie="no"
414 linux)
415 linux="yes"
417 esac
419 if test ! -z "$cpu" ; then
420 # command line argument
422 elif check_define __i386__ ; then
423 cpu="i386"
424 elif check_define __x86_64__ ; then
425 if check_define __ILP32__ ; then
426 cpu="x32"
427 else
428 cpu="x86_64"
430 elif check_define __sparc__ ; then
431 if check_define __arch64__ ; then
432 cpu="sparc64"
433 else
434 cpu="sparc"
436 elif check_define _ARCH_PPC ; then
437 if check_define _ARCH_PPC64 ; then
438 if check_define _LITTLE_ENDIAN ; then
439 cpu="ppc64le"
440 else
441 cpu="ppc64"
443 else
444 cpu="ppc"
446 elif check_define __mips__ ; then
447 if check_define __mips64 ; then
448 cpu="mips64"
449 else
450 cpu="mips"
452 elif check_define __s390__ ; then
453 if check_define __s390x__ ; then
454 cpu="s390x"
455 else
456 cpu="s390"
458 elif check_define __riscv ; then
459 if check_define _LP64 ; then
460 cpu="riscv64"
461 else
462 cpu="riscv32"
464 elif check_define __arm__ ; then
465 cpu="arm"
466 elif check_define __aarch64__ ; then
467 cpu="aarch64"
468 elif check_define __loongarch64 ; then
469 cpu="loongarch64"
470 else
471 # Using uname is really broken, but it is just a fallback for architectures
472 # that are going to use TCI anyway
473 cpu=$(uname -m)
474 echo "WARNING: unrecognized host CPU, proceeding with 'uname -m' output '$cpu'"
477 # Normalise host CPU name to the values used by Meson cross files and in source
478 # directories, and set multilib cflags. The canonicalization isn't really
479 # necessary, because the architectures that we check for should not hit the
480 # 'uname -m' case, but better safe than sorry in case --cpu= is used.
482 # Note that this case should only have supported host CPUs, not guests.
483 # Please keep it sorted and synchronized with meson.build's host_arch.
484 host_arch=
485 linux_arch=
486 case "$cpu" in
487 aarch64)
488 host_arch=aarch64
489 linux_arch=arm64
492 armv*b|armv*l|arm)
493 cpu=arm
494 host_arch=arm
495 linux_arch=arm
498 i386|i486|i586|i686)
499 cpu="i386"
500 host_arch=i386
501 linux_arch=x86
502 CPU_CFLAGS="-m32"
505 loongarch*)
506 cpu=loongarch64
507 host_arch=loongarch64
510 mips64*)
511 cpu=mips64
512 host_arch=mips
513 linux_arch=mips
515 mips*)
516 cpu=mips
517 host_arch=mips
518 linux_arch=mips
521 ppc)
522 host_arch=ppc
523 linux_arch=powerpc
524 CPU_CFLAGS="-m32"
526 ppc64)
527 host_arch=ppc64
528 linux_arch=powerpc
529 CPU_CFLAGS="-m64 -mbig-endian"
531 ppc64le)
532 cpu=ppc64
533 host_arch=ppc64
534 linux_arch=powerpc
535 CPU_CFLAGS="-m64 -mlittle-endian"
538 riscv32 | riscv64)
539 host_arch=riscv
540 linux_arch=riscv
543 s390)
544 linux_arch=s390
545 CPU_CFLAGS="-m31"
547 s390x)
548 host_arch=s390x
549 linux_arch=s390
550 CPU_CFLAGS="-m64"
553 sparc|sun4[cdmuv])
554 cpu=sparc
555 CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc"
557 sparc64)
558 host_arch=sparc64
559 CPU_CFLAGS="-m64 -mcpu=ultrasparc"
562 x32)
563 cpu="x86_64"
564 host_arch=x86_64
565 linux_arch=x86
566 CPU_CFLAGS="-mx32"
568 x86_64|amd64)
569 cpu="x86_64"
570 host_arch=x86_64
571 linux_arch=x86
572 # ??? Only extremely old AMD cpus do not have cmpxchg16b.
573 # If we truly care, we should simply detect this case at
574 # runtime and generate the fallback to serial emulation.
575 CPU_CFLAGS="-m64 -mcx16"
577 esac
579 if test -n "$host_arch" && {
580 ! test -d "$source_path/linux-user/include/host/$host_arch" ||
581 ! test -d "$source_path/common-user/host/$host_arch"; }; then
582 error_exit "linux-user/include/host/$host_arch does not exist." \
583 "This is a bug in the configure script, please report it."
585 if test -n "$linux_arch" && ! test -d "$source_path/linux-headers/asm-$linux_arch"; then
586 error_exit "linux-headers/asm-$linux_arch does not exist." \
587 "This is a bug in the configure script, please report it."
590 check_py_version() {
591 # We require python >= 3.7.
592 # NB: a True python conditional creates a non-zero return code (Failure)
593 "$1" -c 'import sys; sys.exit(sys.version_info < (3,7))'
596 first_python=
597 if test -z "${PYTHON}"; then
598 # A bare 'python' is traditionally python 2.x, but some distros
599 # have it as python 3.x, so check in both places.
600 for binary in python3 python python3.11 python3.10 python3.9 python3.8 python3.7; do
601 if has "$binary"; then
602 python=$(command -v "$binary")
603 if check_py_version "$python"; then
604 # This one is good.
605 first_python=
606 break
607 else
608 first_python=$python
611 done
612 else
613 # Same as above, but only check the environment variable.
614 has "${PYTHON}" || error_exit "The PYTHON environment variable does not point to an executable"
615 python=$(command -v "$PYTHON")
616 if check_py_version "$python"; then
617 # This one is good.
618 first_python=
619 else
620 first_python=$first_python
624 # Check for ancillary tools used in testing
625 genisoimage=
626 for binary in genisoimage mkisofs
628 if has $binary
629 then
630 genisoimage=$(command -v "$binary")
631 break
633 done
635 if test "$mingw32" = "yes" ; then
636 EXESUF=".exe"
637 prefix="/qemu"
638 bindir=""
639 qemu_suffix=""
642 meson_option_build_array() {
643 printf '['
644 (if test "$targetos" = windows; then
645 IFS=\;
646 else
647 IFS=:
649 for e in $1; do
650 printf '"""'
651 # backslash escape any '\' and '"' characters
652 printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g'
653 printf '""",'
654 done)
655 printf ']\n'
658 . "$source_path/scripts/meson-buildoptions.sh"
660 meson_options=
661 meson_option_add() {
662 meson_options="$meson_options $(quote_sh "$1")"
664 meson_option_parse() {
665 meson_options="$meson_options $(_meson_option_parse "$@")"
666 if test $? -eq 1; then
667 echo "ERROR: unknown option $1"
668 echo "Try '$0 --help' for more information"
669 exit 1
673 for opt do
674 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
675 case "$opt" in
676 --help|-h) show_help=yes
678 --version|-V) exec cat "$source_path/VERSION"
680 --prefix=*) prefix="$optarg"
682 --cross-prefix=*)
684 --cc=*)
686 --host-cc=*) host_cc="$optarg"
688 --cxx=*)
690 --objcc=*)
692 --make=*)
694 --install=*)
696 --python=*) python="$optarg"
698 --skip-meson) skip_meson=yes
700 --ninja=*) ninja="$optarg"
702 --smbd=*) smbd="$optarg"
704 --extra-cflags=*)
706 --extra-cxxflags=*)
708 --extra-objcflags=*)
710 --extra-ldflags=*)
712 --cross-cc-*)
714 --cross-prefix-*)
716 --enable-docs) docs=enabled
718 --disable-docs) docs=disabled
720 --cpu=*)
722 --target-list=*) target_list="$optarg"
723 if test "$target_list_exclude"; then
724 error_exit "Can't mix --target-list with --target-list-exclude"
727 --target-list-exclude=*) target_list_exclude="$optarg"
728 if test "$target_list"; then
729 error_exit "Can't mix --target-list-exclude with --target-list"
732 --with-default-devices) meson_option_add -Ddefault_devices=true
734 --without-default-devices) meson_option_add -Ddefault_devices=false
736 --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
738 --with-devices-*) device_arch=${opt#--with-devices-};
739 device_arch=${device_arch%%=*}
740 cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
741 if test -f "$cf"; then
742 device_archs="$device_archs $device_arch"
743 eval "devices_${device_arch}=\$optarg"
744 else
745 error_exit "File $cf does not exist"
748 --without-default-features) # processed above
750 --static) static="yes"
752 --bindir=*) bindir="$optarg"
754 --with-suffix=*) qemu_suffix="$optarg"
756 --host=*|--build=*|\
757 --disable-dependency-tracking|\
758 --sbindir=*|--sharedstatedir=*|\
759 --oldincludedir=*|--datarootdir=*|--infodir=*|\
760 --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
761 # These switches are silently ignored, for compatibility with
762 # autoconf-generated configure scripts. This allows QEMU's
763 # configure to be used by RPM and similar macros that set
764 # lots of directory switches by default.
766 --enable-debug-tcg) debug_tcg="yes"
768 --disable-debug-tcg) debug_tcg="no"
770 --enable-debug)
771 # Enable debugging options that aren't excessively noisy
772 debug_tcg="yes"
773 meson_option_parse --enable-debug-graph-lock ""
774 meson_option_parse --enable-debug-mutex ""
775 meson_option_add -Doptimization=0
777 --disable-tcg) tcg="disabled"
778 plugins="no"
780 --enable-tcg) tcg="enabled"
782 --disable-system) softmmu="no"
784 --enable-system) softmmu="yes"
786 --disable-user)
787 linux_user="no" ;
788 bsd_user="no" ;
790 --enable-user) ;;
791 --disable-linux-user) linux_user="no"
793 --enable-linux-user) linux_user="yes"
795 --disable-bsd-user) bsd_user="no"
797 --enable-bsd-user) bsd_user="yes"
799 --enable-pie) pie="yes"
801 --disable-pie) pie="no"
803 --enable-werror) werror="yes"
805 --disable-werror) werror="no"
807 --enable-cfi)
808 cfi="true";
809 meson_option_add -Db_lto=true
811 --disable-cfi) cfi="false"
813 --disable-download) download="disabled"; git_submodules_action=validate;
815 --enable-download) download="enabled"; git_submodules_action=update;
817 --enable-plugins) if test "$mingw32" = "yes"; then
818 error_exit "TCG plugins not currently supported on Windows platforms"
819 else
820 plugins="yes"
823 --disable-plugins) plugins="no"
825 --enable-containers) use_containers="yes"
827 --disable-containers) use_containers="no"
829 --gdb=*) gdb_bin="$optarg"
831 # everything else has the same name in configure and meson
832 --*) meson_option_parse "$opt" "$optarg"
834 # Pass through -Dxxxx options to meson
835 -D*) meson_options="$meson_options $opt"
837 esac
838 done
840 if ! test -e "$source_path/.git"
841 then
842 git_submodules_action="validate"
845 # test for any invalid configuration combinations
846 if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
847 error_exit "Can't enable plugins on non-TCG builds"
850 if ! test -f "$source_path/subprojects/keycodemapdb/README" \
851 && test "$download" = disabled
852 then
853 echo
854 echo "ERROR: missing subprojects"
855 echo
856 if test -e "$source_path/.git"; then
857 echo "--disable-download specified but subprojects were not"
858 echo 'checked out. Please invoke "meson subprojects download"'
859 echo "before configuring QEMU, or remove --disable-download"
860 echo "from the command line."
861 else
862 echo "This is not a GIT checkout but subproject content appears to"
863 echo "be missing. Do not use 'git archive' or GitHub download links"
864 echo "to acquire QEMU source archives. Non-GIT builds are only"
865 echo "supported with source archives linked from:"
866 echo
867 echo " https://www.qemu.org/download/#source"
868 echo
869 echo "Developers working with GIT can use scripts/archive-source.sh"
870 echo "if they need to create valid source archives."
872 echo
873 exit 1
876 default_target_list=""
877 mak_wilds=""
879 if [ "$linux_user" != no ]; then
880 if [ "$targetos" = linux ] && [ -n "$host_arch" ]; then
881 linux_user=yes
882 elif [ "$linux_user" = yes ]; then
883 error_exit "linux-user not supported on this architecture"
886 if [ "$bsd_user" != no ]; then
887 if [ "$bsd_user" = "" ]; then
888 test $targetos = freebsd && bsd_user=yes
890 if [ "$bsd_user" = yes ] && ! [ -d "$source_path/bsd-user/$targetos" ]; then
891 error_exit "bsd-user not supported on this host OS"
894 if [ "$softmmu" = "yes" ]; then
895 mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
897 if [ "$linux_user" = "yes" ]; then
898 mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
900 if [ "$bsd_user" = "yes" ]; then
901 mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
904 for config in $mak_wilds; do
905 target="$(basename "$config" .mak)"
906 if echo "$target_list_exclude" | grep -vq "$target"; then
907 default_target_list="${default_target_list} $target"
909 done
911 if test x"$show_help" = x"yes" ; then
912 cat << EOF
914 Usage: configure [options]
915 Options: [defaults in brackets after descriptions]
917 Standard options:
918 --help print this message
919 --prefix=PREFIX install in PREFIX [$prefix]
920 --target-list=LIST set target list (default: build all)
921 $(echo Available targets: $default_target_list | \
922 fold -s -w 53 | sed -e 's/^/ /')
923 --target-list-exclude=LIST exclude a set of targets from the default target-list
925 Advanced options (experts only):
926 -Dmesonoptname=val passthrough option to meson unmodified
927 --cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
928 --cc=CC use C compiler CC [$cc]
929 --host-cc=CC use C compiler CC [$host_cc] for code run at
930 build time
931 --cxx=CXX use C++ compiler CXX [$cxx]
932 --objcc=OBJCC use Objective-C compiler OBJCC [$objcc]
933 --extra-cflags=CFLAGS append extra C compiler flags CFLAGS
934 --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
935 --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
936 --extra-ldflags=LDFLAGS append extra linker flags LDFLAGS
937 --cross-cc-ARCH=CC use compiler when building ARCH guest test cases
938 --cross-cc-cflags-ARCH= use compiler flags when building ARCH guest tests
939 --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
940 --python=PYTHON use specified python [$python]
941 --ninja=NINJA use specified ninja [$ninja]
942 --smbd=SMBD use specified smbd [$smbd]
943 --static enable static build [$static]
944 --bindir=PATH install binaries in PATH
945 --with-suffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
946 --without-default-features default all --enable-* options to "disabled"
947 --without-default-devices do not include any device that is not needed to
948 start the emulator (only use if you are including
949 desired devices in configs/devices/)
950 --with-devices-ARCH=NAME override default configs/devices
951 --enable-debug enable common debug build options
952 --disable-werror disable compilation abort on warning
953 --cpu=CPU Build for host CPU [$cpu]
954 --enable-plugins
955 enable plugins via shared library loading
956 --disable-containers don't use containers for cross-building
957 --gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
959 meson_options_help
960 cat << EOF
961 system all system emulation targets
962 user supported user emulation targets
963 linux-user all linux usermode emulation targets
964 bsd-user all BSD usermode emulation targets
965 pie Position Independent Executables
966 debug-tcg TCG debugging (default is disabled)
968 NOTE: The object files are built at the place where configure is launched
970 exit 0
973 # Remove old dependency files to make sure that they get properly regenerated
974 rm -f ./*/config-devices.mak.d
976 if test -z "$python"
977 then
978 # If first_python is set, there was a binary somewhere even though
979 # it was not suitable. Use it for the error message.
980 if test -n "$first_python"; then
981 error_exit "Cannot use '$first_python', Python >= 3.7 is required." \
982 "Use --python=/path/to/python to specify a supported Python."
983 else
984 error_exit "Python not found. Use --python=/path/to/python"
988 if ! check_py_version "$python"; then
989 error_exit "Cannot use '$python', Python >= 3.7 is required." \
990 "Use --python=/path/to/python to specify a supported Python." \
991 "Maybe try:" \
992 " openSUSE Leap 15.3+: zypper install python39" \
993 " CentOS 8: dnf install python38"
996 # Resolve PATH
997 python="$(command -v "$python")"
999 # Create a Python virtual environment using our configured python.
1000 # The stdout of this script will be the location of a symlink that
1001 # points to the configured Python.
1002 # Entry point scripts for pip, meson, and sphinx are generated if those
1003 # packages are present.
1005 # Defaults assumed for now:
1006 # - venv is cleared if it exists already;
1007 # - venv is allowed to use system packages;
1008 # - all setup can be performed offline;
1009 # - missing packages may be fetched from PyPI,
1010 # unless --disable-download is passed.
1011 # - pip is not installed into the venv when possible,
1012 # but ensurepip is called as a fallback when necessary.
1014 echo "python determined to be '$python'"
1015 echo "python version: $($python --version)"
1017 python="$($python -B "${source_path}/python/scripts/mkvenv.py" create pyvenv)"
1018 if test "$?" -ne 0 ; then
1019 error_exit "python venv creation failed"
1022 # Suppress writing compiled files
1023 python="$python -B"
1024 mkvenv="$python ${source_path}/python/scripts/mkvenv.py"
1026 mkvenv_flags=""
1027 if test "$download" = "enabled" ; then
1028 mkvenv_flags="--online"
1031 if ! $mkvenv ensure \
1032 $mkvenv_flags \
1033 --dir "${source_path}/python/wheels" \
1034 --diagnose "meson" \
1035 "meson>=0.63.0" ;
1036 then
1037 exit 1
1040 # At this point, we expect Meson to be installed and available.
1041 # We expect mkvenv or pip to have created pyvenv/bin/meson for us.
1042 # We ignore PATH completely here: we want to use the venv's Meson
1043 # *exclusively*.
1045 meson="$(cd pyvenv/bin; pwd)/meson"
1047 # Conditionally ensure Sphinx is installed.
1049 mkvenv_flags=""
1050 if test "$download" = "enabled" -a "$docs" = "enabled" ; then
1051 mkvenv_flags="--online"
1054 if test "$docs" != "disabled" ; then
1055 if ! $mkvenv ensure \
1056 $mkvenv_flags \
1057 --diagnose "sphinx-build" \
1058 "sphinx>=1.6.0" "sphinx-rtd-theme>=0.5.0";
1059 then
1060 if test "$docs" = "enabled" ; then
1061 exit 1
1063 echo "Sphinx not found/usable, disabling docs."
1064 docs=disabled
1065 else
1066 docs=enabled
1070 # Probe for ninja
1072 if test -z "$ninja"; then
1073 for c in ninja ninja-build samu; do
1074 if has $c; then
1075 ninja=$(command -v "$c")
1076 break
1078 done
1079 if test -z "$ninja"; then
1080 error_exit "Cannot find Ninja"
1084 # Consult white-list to determine whether to enable werror
1085 # by default. Only enable by default for git builds
1086 if test -z "$werror" ; then
1087 if test -e "$source_path/.git" && \
1088 { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
1089 werror="yes"
1090 else
1091 werror="no"
1095 if test "$targetos" = "bogus"; then
1096 # Now that we know that we're not printing the help and that
1097 # the compiler works (so the results of the check_defines we used
1098 # to identify the OS are reliable), if we didn't recognize the
1099 # host OS we should stop now.
1100 error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
1103 if test "$static" = "yes" ; then
1104 if test "$plugins" = "yes"; then
1105 error_exit "static and plugins are mutually incompatible"
1106 else
1107 plugins="no"
1110 test "$plugins" = "" && plugins=yes
1112 cat > $TMPC << EOF
1114 #ifdef __linux__
1115 # define THREAD __thread
1116 #else
1117 # define THREAD
1118 #endif
1119 static THREAD int tls_var;
1120 int main(void) { return tls_var; }
1123 if test "$static" = "yes"; then
1124 if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
1125 pie="yes"
1126 elif test "$pie" = "yes"; then
1127 error_exit "-static-pie not available due to missing toolchain support"
1128 else
1129 pie="no"
1131 elif test "$pie" != "no"; then
1132 if compile_prog "-Werror -fPIE -DPIE" "-pie"; then
1133 pie="yes"
1134 elif test "$pie" = "yes"; then
1135 error_exit "PIE not available due to missing toolchain support"
1136 else
1137 echo "Disabling PIE due to missing toolchain support"
1138 pie="no"
1142 ##########################################
1144 if test -z "${target_list+xxx}" ; then
1145 default_targets=yes
1146 for target in $default_target_list; do
1147 target_list="$target_list $target"
1148 done
1149 target_list="${target_list# }"
1150 else
1151 default_targets=no
1152 target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1153 for target in $target_list; do
1154 # Check that we recognised the target name; this allows a more
1155 # friendly error message than if we let it fall through.
1156 case " $default_target_list " in
1157 *" $target "*)
1160 error_exit "Unknown target name '$target'"
1162 esac
1163 done
1166 # see if system emulation was really requested
1167 case " $target_list " in
1168 *"-softmmu "*) softmmu=yes
1170 *) softmmu=no
1172 esac
1174 if test "$tcg" = "auto"; then
1175 if test -z "$target_list"; then
1176 tcg="disabled"
1177 else
1178 tcg="enabled"
1182 ##########################################
1183 # big/little endian test
1184 cat > $TMPC << EOF
1185 #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1186 # error LITTLE
1187 #endif
1188 int main(void) { return 0; }
1191 if ! compile_prog ; then
1192 bigendian="no"
1193 else
1194 cat > $TMPC << EOF
1195 #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
1196 # error BIG
1197 #endif
1198 int main(void) { return 0; }
1201 if ! compile_prog ; then
1202 bigendian="yes"
1203 else
1204 echo big/little test failed
1205 exit 1
1209 ########################################
1210 # check if ccache is interfering with
1211 # semantic analysis of macros
1213 unset CCACHE_CPP2
1214 ccache_cpp2=no
1215 cat > $TMPC << EOF
1216 static const int Z = 1;
1217 #define fn() ({ Z; })
1218 #define TAUT(X) ((X) == Z)
1219 #define PAREN(X, Y) (X == Y)
1220 #define ID(X) (X)
1221 int main(void)
1223 int x = 0, y = 0;
1224 x = ID(x);
1225 x = fn();
1226 fn();
1227 if (PAREN(x, y)) return 0;
1228 if (TAUT(Z)) return 0;
1229 return 0;
1233 if ! compile_object "-Werror"; then
1234 ccache_cpp2=yes
1237 ##########################################
1238 # functions to probe cross compilers
1240 container="no"
1241 runc=""
1242 if test $use_containers = "yes" && (has "docker" || has "podman"); then
1243 case $($python "$source_path"/tests/docker/docker.py probe) in
1244 *docker) container=docker ;;
1245 podman) container=podman ;;
1246 no) container=no ;;
1247 esac
1248 if test "$container" != "no"; then
1249 docker_py="$python $source_path/tests/docker/docker.py --engine $container"
1250 runc=$($python "$source_path"/tests/docker/docker.py probe)
1254 # cross compilers defaults, can be overridden with --cross-cc-ARCH
1255 : ${cross_prefix_aarch64="aarch64-linux-gnu-"}
1256 : ${cross_prefix_aarch64_be="$cross_prefix_aarch64"}
1257 : ${cross_prefix_alpha="alpha-linux-gnu-"}
1258 : ${cross_prefix_arm="arm-linux-gnueabihf-"}
1259 : ${cross_prefix_armeb="$cross_prefix_arm"}
1260 : ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
1261 : ${cross_prefix_loongarch64="loongarch64-unknown-linux-gnu-"}
1262 : ${cross_prefix_hppa="hppa-linux-gnu-"}
1263 : ${cross_prefix_i386="i686-linux-gnu-"}
1264 : ${cross_prefix_m68k="m68k-linux-gnu-"}
1265 : ${cross_prefix_microblaze="microblaze-linux-musl-"}
1266 : ${cross_prefix_mips64el="mips64el-linux-gnuabi64-"}
1267 : ${cross_prefix_mips64="mips64-linux-gnuabi64-"}
1268 : ${cross_prefix_mipsel="mipsel-linux-gnu-"}
1269 : ${cross_prefix_mips="mips-linux-gnu-"}
1270 : ${cross_prefix_nios2="nios2-linux-gnu-"}
1271 : ${cross_prefix_ppc="powerpc-linux-gnu-"}
1272 : ${cross_prefix_ppc64="powerpc64-linux-gnu-"}
1273 : ${cross_prefix_ppc64le="$cross_prefix_ppc64"}
1274 : ${cross_prefix_riscv64="riscv64-linux-gnu-"}
1275 : ${cross_prefix_s390x="s390x-linux-gnu-"}
1276 : ${cross_prefix_sh4="sh4-linux-gnu-"}
1277 : ${cross_prefix_sparc64="sparc64-linux-gnu-"}
1278 : ${cross_prefix_sparc="$cross_prefix_sparc64"}
1279 : ${cross_prefix_x86_64="x86_64-linux-gnu-"}
1281 : ${cross_cc_aarch64_be="$cross_cc_aarch64"}
1282 : ${cross_cc_cflags_aarch64_be="-mbig-endian"}
1283 : ${cross_cc_armeb="$cross_cc_arm"}
1284 : ${cross_cc_cflags_armeb="-mbig-endian"}
1285 : ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
1286 : ${cross_cc_cflags_hexagon="-mv73 -O2 -static"}
1287 : ${cross_cc_cflags_i386="-m32"}
1288 : ${cross_cc_cflags_ppc="-m32 -mbig-endian"}
1289 : ${cross_cc_cflags_ppc64="-m64 -mbig-endian"}
1290 : ${cross_cc_ppc64le="$cross_cc_ppc64"}
1291 : ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"}
1292 : ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
1293 : ${cross_cc_sparc="$cross_cc_sparc64"}
1294 : ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
1295 : ${cross_cc_cflags_x86_64="-m64"}
1297 compute_target_variable() {
1298 eval "$2="
1299 if eval test -n "\"\${cross_prefix_$1}\""; then
1300 if eval has "\"\${cross_prefix_$1}\$3\""; then
1301 eval "$2=\"\${cross_prefix_$1}\$3\""
1306 have_target() {
1307 for i; do
1308 case " $target_list " in
1309 *" $i "*) return 0;;
1310 *) ;;
1311 esac
1312 done
1313 return 1
1316 # probe_target_compiler TARGET
1318 # Look for a compiler for the given target, either native or cross.
1319 # Set variables target_* if a compiler is found, and container_cross_*
1320 # if a Docker-based cross-compiler image is known for the target.
1321 # Set got_cross_cc to yes/no depending on whether a non-container-based
1322 # compiler was found.
1324 # If TARGET is a user-mode emulation target, also set build_static to
1325 # "y" if static linking is possible.
1327 probe_target_compiler() {
1328 # reset all output variables
1329 got_cross_cc=no
1330 container_image=
1331 container_hosts=
1332 container_cross_cc=
1333 container_cross_ar=
1334 container_cross_as=
1335 container_cross_ld=
1336 container_cross_nm=
1337 container_cross_objcopy=
1338 container_cross_ranlib=
1339 container_cross_strip=
1341 target_arch=${1%%-*}
1342 case $target_arch in
1343 aarch64) container_hosts="x86_64 aarch64" ;;
1344 alpha) container_hosts=x86_64 ;;
1345 arm) container_hosts="x86_64 aarch64" ;;
1346 cris) container_hosts=x86_64 ;;
1347 hexagon) container_hosts=x86_64 ;;
1348 hppa) container_hosts=x86_64 ;;
1349 i386) container_hosts=x86_64 ;;
1350 loongarch64) container_hosts=x86_64 ;;
1351 m68k) container_hosts=x86_64 ;;
1352 microblaze) container_hosts=x86_64 ;;
1353 mips64el) container_hosts=x86_64 ;;
1354 mips64) container_hosts=x86_64 ;;
1355 mipsel) container_hosts=x86_64 ;;
1356 mips) container_hosts=x86_64 ;;
1357 nios2) container_hosts=x86_64 ;;
1358 ppc) container_hosts=x86_64 ;;
1359 ppc64|ppc64le) container_hosts=x86_64 ;;
1360 riscv64) container_hosts=x86_64 ;;
1361 s390x) container_hosts=x86_64 ;;
1362 sh4) container_hosts=x86_64 ;;
1363 sparc64) container_hosts=x86_64 ;;
1364 tricore) container_hosts=x86_64 ;;
1365 x86_64) container_hosts="aarch64 ppc64el x86_64" ;;
1366 xtensa*) container_hosts=x86_64 ;;
1367 esac
1369 for host in $container_hosts; do
1370 test "$container" != no || continue
1371 test "$host" = "$cpu" || continue
1372 case $target_arch in
1373 aarch64)
1374 # We don't have any bigendian build tools so we only use this for AArch64
1375 container_image=debian-arm64-cross
1376 container_cross_prefix=aarch64-linux-gnu-
1377 container_cross_cc=${container_cross_prefix}gcc-10
1379 alpha)
1380 container_image=debian-alpha-cross
1381 container_cross_prefix=alpha-linux-gnu-
1383 arm)
1384 # We don't have any bigendian build tools so we only use this for ARM
1385 container_image=debian-armhf-cross
1386 container_cross_prefix=arm-linux-gnueabihf-
1388 cris)
1389 container_image=fedora-cris-cross
1390 container_cross_prefix=cris-linux-gnu-
1392 hexagon)
1393 container_image=debian-hexagon-cross
1394 container_cross_prefix=hexagon-unknown-linux-musl-
1395 container_cross_cc=${container_cross_prefix}clang
1397 hppa)
1398 container_image=debian-hppa-cross
1399 container_cross_prefix=hppa-linux-gnu-
1401 i386)
1402 container_image=fedora-i386-cross
1403 container_cross_prefix=
1405 loongarch64)
1406 container_image=debian-loongarch-cross
1407 container_cross_prefix=loongarch64-unknown-linux-gnu-
1409 m68k)
1410 container_image=debian-m68k-cross
1411 container_cross_prefix=m68k-linux-gnu-
1413 microblaze)
1414 container_image=debian-microblaze-cross
1415 container_cross_prefix=microblaze-linux-musl-
1417 mips64el)
1418 container_image=debian-mips64el-cross
1419 container_cross_prefix=mips64el-linux-gnuabi64-
1421 mips64)
1422 container_image=debian-mips64-cross
1423 container_cross_prefix=mips64-linux-gnuabi64-
1425 mipsel)
1426 container_image=debian-mipsel-cross
1427 container_cross_prefix=mipsel-linux-gnu-
1429 mips)
1430 container_image=debian-mips-cross
1431 container_cross_prefix=mips-linux-gnu-
1433 nios2)
1434 container_image=debian-nios2-cross
1435 container_cross_prefix=nios2-linux-gnu-
1437 ppc)
1438 container_image=debian-powerpc-test-cross
1439 container_cross_prefix=powerpc-linux-gnu-
1440 container_cross_cc=${container_cross_prefix}gcc-10
1442 ppc64|ppc64le)
1443 container_image=debian-powerpc-test-cross
1444 container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu-
1445 container_cross_cc=${container_cross_prefix}gcc-10
1447 riscv64)
1448 container_image=debian-riscv64-test-cross
1449 container_cross_prefix=riscv64-linux-gnu-
1451 s390x)
1452 container_image=debian-s390x-cross
1453 container_cross_prefix=s390x-linux-gnu-
1455 sh4)
1456 container_image=debian-sh4-cross
1457 container_cross_prefix=sh4-linux-gnu-
1459 sparc64)
1460 container_image=debian-sparc64-cross
1461 container_cross_prefix=sparc64-linux-gnu-
1463 tricore)
1464 container_image=debian-tricore-cross
1465 container_cross_prefix=tricore-
1466 container_cross_as=tricore-as
1467 container_cross_ld=tricore-ld
1468 container_cross_cc=tricore-gcc
1469 break
1471 x86_64)
1472 container_image=debian-amd64-cross
1473 container_cross_prefix=x86_64-linux-gnu-
1475 xtensa*)
1476 container_hosts=x86_64
1477 container_image=debian-xtensa-cross
1479 # default to the dc232b cpu
1480 container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
1482 esac
1483 : ${container_cross_cc:=${container_cross_prefix}gcc}
1484 : ${container_cross_ar:=${container_cross_prefix}ar}
1485 : ${container_cross_as:=${container_cross_prefix}as}
1486 : ${container_cross_ld:=${container_cross_prefix}ld}
1487 : ${container_cross_nm:=${container_cross_prefix}nm}
1488 : ${container_cross_objcopy:=${container_cross_prefix}objcopy}
1489 : ${container_cross_ranlib:=${container_cross_prefix}ranlib}
1490 : ${container_cross_strip:=${container_cross_prefix}strip}
1491 done
1493 try=cross
1494 case "$target_arch:$cpu" in
1495 aarch64_be:aarch64 | \
1496 armeb:arm | \
1497 i386:x86_64 | \
1498 mips*:mips64 | \
1499 ppc*:ppc64 | \
1500 sparc:sparc64 | \
1501 "$cpu:$cpu")
1502 try='native cross' ;;
1503 esac
1504 eval "target_cflags=\${cross_cc_cflags_$target_arch}"
1505 for thistry in $try; do
1506 case $thistry in
1507 native)
1508 target_cc=$cc
1509 target_ccas=$ccas
1510 target_ar=$ar
1511 target_as=$as
1512 target_ld=$ld
1513 target_nm=$nm
1514 target_objcopy=$objcopy
1515 target_ranlib=$ranlib
1516 target_strip=$strip
1518 cross)
1519 target_cc=
1520 if eval test -n "\"\${cross_cc_$target_arch}\""; then
1521 if eval has "\"\${cross_cc_$target_arch}\""; then
1522 eval "target_cc=\"\${cross_cc_$target_arch}\""
1524 else
1525 compute_target_variable $target_arch target_cc gcc
1527 target_ccas=$target_cc
1528 compute_target_variable $target_arch target_ar ar
1529 compute_target_variable $target_arch target_as as
1530 compute_target_variable $target_arch target_ld ld
1531 compute_target_variable $target_arch target_nm nm
1532 compute_target_variable $target_arch target_objcopy objcopy
1533 compute_target_variable $target_arch target_ranlib ranlib
1534 compute_target_variable $target_arch target_strip strip
1536 esac
1538 if test -n "$target_cc"; then
1539 case $target_arch in
1540 i386|x86_64)
1541 if $target_cc --version | grep -qi "clang"; then
1542 continue
1545 esac
1546 elif test -n "$target_as" && test -n "$target_ld"; then
1547 # Special handling for assembler only targets
1548 case $target in
1549 tricore-softmmu)
1550 build_static=
1551 got_cross_cc=yes
1552 break
1555 continue
1557 esac
1558 else
1559 continue
1562 write_c_skeleton
1563 case $1 in
1564 *-softmmu)
1565 if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC &&
1566 do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then
1567 got_cross_cc=yes
1568 break
1572 if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC -static ; then
1573 build_static=y
1574 got_cross_cc=yes
1575 break
1577 if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC ; then
1578 build_static=
1579 got_cross_cc=yes
1580 break
1583 esac
1584 done
1585 if test $got_cross_cc != yes; then
1586 build_static=
1587 target_cc=
1588 target_ccas=
1589 target_ar=
1590 target_as=
1591 target_ld=
1592 target_nm=
1593 target_objcopy=
1594 target_ranlib=
1595 target_strip=
1597 test -n "$target_cc"
1600 write_target_makefile() {
1601 echo "EXTRA_CFLAGS=$target_cflags"
1602 if test -z "$target_cc" && test -z "$target_as"; then
1603 test -z "$container_image" && error_exit "Internal error: could not find cross compiler for $1?"
1604 echo "$1: docker-image-$container_image" >> Makefile.prereqs
1605 if test -n "$container_cross_cc"; then
1606 echo "CC=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
1607 echo "CCAS=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
1609 echo "AR=$docker_py cc --cc $container_cross_ar -i qemu/$container_image -s $source_path --"
1610 echo "AS=$docker_py cc --cc $container_cross_as -i qemu/$container_image -s $source_path --"
1611 echo "LD=$docker_py cc --cc $container_cross_ld -i qemu/$container_image -s $source_path --"
1612 echo "NM=$docker_py cc --cc $container_cross_nm -i qemu/$container_image -s $source_path --"
1613 echo "OBJCOPY=$docker_py cc --cc $container_cross_objcopy -i qemu/$container_image -s $source_path --"
1614 echo "RANLIB=$docker_py cc --cc $container_cross_ranlib -i qemu/$container_image -s $source_path --"
1615 echo "STRIP=$docker_py cc --cc $container_cross_strip -i qemu/$container_image -s $source_path --"
1616 else
1617 if test -n "$target_cc"; then
1618 echo "CC=$target_cc"
1619 echo "CCAS=$target_ccas"
1621 if test -n "$target_ar"; then
1622 echo "AR=$target_ar"
1624 if test -n "$target_as"; then
1625 echo "AS=$target_as"
1627 if test -n "$target_ld"; then
1628 echo "LD=$target_ld"
1630 if test -n "$target_nm"; then
1631 echo "NM=$target_nm"
1633 if test -n "$target_objcopy"; then
1634 echo "OBJCOPY=$target_objcopy"
1636 if test -n "$target_ranlib"; then
1637 echo "RANLIB=$target_ranlib"
1639 if test -n "$target_strip"; then
1640 echo "STRIP=$target_strip"
1645 #######################################
1646 # cross-compiled firmware targets
1648 # Set up build tree symlinks that point back into the source tree
1649 # (these can be both files and directories).
1650 # Caution: avoid adding files or directories here using wildcards. This
1651 # will result in problems later if a new file matching the wildcard is
1652 # added to the source tree -- nothing will cause configure to be rerun
1653 # so the build tree will be missing the link back to the new file, and
1654 # tests might fail. Prefer to keep the relevant files in their own
1655 # directory and symlink the directory instead.
1656 LINKS="Makefile"
1657 LINKS="$LINKS docs/config"
1658 LINKS="$LINKS pc-bios/optionrom/Makefile"
1659 LINKS="$LINKS pc-bios/s390-ccw/Makefile"
1660 LINKS="$LINKS pc-bios/vof/Makefile"
1661 LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
1662 LINKS="$LINKS tests/avocado tests/data"
1663 LINKS="$LINKS tests/qemu-iotests/check"
1664 LINKS="$LINKS python"
1665 LINKS="$LINKS contrib/plugins/Makefile "
1666 for f in $LINKS ; do
1667 if [ -e "$source_path/$f" ]; then
1668 symlink "$source_path/$f" "$f"
1670 done
1672 echo "# Automatically generated by configure - do not modify" > Makefile.prereqs
1674 # Mac OS X ships with a broken assembler
1675 roms=
1676 if have_target i386-softmmu x86_64-softmmu && \
1677 test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
1678 test "$targetos" != "haiku" && \
1679 probe_target_compiler i386-softmmu; then
1680 roms="pc-bios/optionrom"
1681 config_mak=pc-bios/optionrom/config.mak
1682 echo "# Automatically generated by configure - do not modify" > $config_mak
1683 echo "TOPSRC_DIR=$source_path" >> $config_mak
1684 write_target_makefile >> $config_mak
1687 if have_target ppc-softmmu ppc64-softmmu && \
1688 probe_target_compiler ppc-softmmu; then
1689 roms="$roms pc-bios/vof"
1690 config_mak=pc-bios/vof/config.mak
1691 echo "# Automatically generated by configure - do not modify" > $config_mak
1692 echo "SRC_DIR=$source_path/pc-bios/vof" >> $config_mak
1693 write_target_makefile >> $config_mak
1696 # Only build s390-ccw bios if the compiler has -march=z900 or -march=z10
1697 # (which is the lowest architecture level that Clang supports)
1698 if have_target s390x-softmmu && probe_target_compiler s390x-softmmu && \
1699 GIT=git "$source_path/scripts/git-submodule.sh" "$git_submodules_action" roms/SLOF >> config.log 2>&1; then
1700 write_c_skeleton
1701 do_compiler "$target_cc" $target_cc_cflags -march=z900 -o $TMPO -c $TMPC
1702 has_z900=$?
1703 if [ $has_z900 = 0 ] || do_compiler "$target_cc" $target_cc_cflags -march=z10 -msoft-float -Werror -o $TMPO -c $TMPC; then
1704 if [ $has_z900 != 0 ]; then
1705 echo "WARNING: Your compiler does not support the z900!"
1706 echo " The s390-ccw bios will only work with guest CPUs >= z10."
1708 roms="$roms pc-bios/s390-ccw"
1709 config_mak=pc-bios/s390-ccw/config-host.mak
1710 echo "# Automatically generated by configure - do not modify" > $config_mak
1711 echo "SRC_PATH=$source_path/pc-bios/s390-ccw" >> $config_mak
1712 echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_mak
1713 write_target_makefile >> $config_mak
1717 #######################################
1718 # generate config-host.mak
1720 config_host_mak="config-host.mak"
1722 echo "# Automatically generated by configure - do not modify" > $config_host_mak
1723 echo >> $config_host_mak
1725 echo all: >> $config_host_mak
1727 if test "$debug_tcg" = "yes" ; then
1728 echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
1730 if test "$mingw32" = "yes" ; then
1731 echo "CONFIG_WIN32=y" >> $config_host_mak
1732 echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER-QEMU}" >> $config_host_mak
1733 echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO-Linux}" >> $config_host_mak
1734 echo "QEMU_GA_VERSION=${QEMU_GA_VERSION-$(cat "$source_path"/VERSION)}" >> $config_host_mak
1735 else
1736 echo "CONFIG_POSIX=y" >> $config_host_mak
1739 if test "$linux" = "yes" ; then
1740 echo "CONFIG_LINUX=y" >> $config_host_mak
1743 if test "$darwin" = "yes" ; then
1744 echo "CONFIG_DARWIN=y" >> $config_host_mak
1747 if test "$solaris" = "yes" ; then
1748 echo "CONFIG_SOLARIS=y" >> $config_host_mak
1750 echo "SRC_PATH=$source_path" >> $config_host_mak
1751 echo "TARGET_DIRS=$target_list" >> $config_host_mak
1753 # XXX: suppress that
1754 if [ "$bsd" = "yes" ] ; then
1755 echo "CONFIG_BSD=y" >> $config_host_mak
1758 if test "$plugins" = "yes" ; then
1759 echo "CONFIG_PLUGIN=y" >> $config_host_mak
1762 if test -n "$gdb_bin"; then
1763 gdb_version=$($gdb_bin --version | head -n 1)
1764 if version_ge ${gdb_version##* } 9.1; then
1765 echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
1766 gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
1767 else
1768 gdb_bin=""
1772 if test "$container" != no; then
1773 echo "ENGINE=$container" >> $config_host_mak
1774 echo "RUNC=$runc" >> $config_host_mak
1776 echo "ROMS=$roms" >> $config_host_mak
1777 echo "PYTHON=$python" >> $config_host_mak
1778 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
1779 echo "MESON=$meson" >> $config_host_mak
1780 echo "NINJA=$ninja" >> $config_host_mak
1781 echo "PKG_CONFIG=${pkg_config}" >> $config_host_mak
1782 echo "CC=$cc" >> $config_host_mak
1783 echo "EXESUF=$EXESUF" >> $config_host_mak
1785 # use included Linux headers for KVM architectures
1786 if test "$linux" = "yes" && test -n "$linux_arch"; then
1787 symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
1790 for target in $target_list; do
1791 target_dir="$target"
1792 target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
1793 mkdir -p "$target_dir"
1794 case $target in
1795 *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
1796 *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
1797 esac
1798 done
1800 if test "$default_targets" = "yes"; then
1801 echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
1804 if test "$ccache_cpp2" = "yes"; then
1805 echo "export CCACHE_CPP2=y" >> $config_host_mak
1808 # tests/tcg configuration
1809 (config_host_mak=tests/tcg/config-host.mak
1810 mkdir -p tests/tcg
1811 echo "# Automatically generated by configure - do not modify" > $config_host_mak
1812 echo "SRC_PATH=$source_path" >> $config_host_mak
1813 echo "HOST_CC=$host_cc" >> $config_host_mak
1815 # versioned checked in the main config_host.mak above
1816 if test -n "$gdb_bin"; then
1817 echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
1819 if test "$plugins" = "yes" ; then
1820 echo "CONFIG_PLUGIN=y" >> $config_host_mak
1823 tcg_tests_targets=
1824 for target in $target_list; do
1825 arch=${target%%-*}
1827 case $target in
1828 xtensa*-linux-user)
1829 # the toolchain is not complete with headers, only build softmmu tests
1830 continue
1832 *-softmmu)
1833 test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || continue
1834 qemu="qemu-system-$arch"
1836 *-linux-user|*-bsd-user)
1837 qemu="qemu-$arch"
1839 esac
1841 if probe_target_compiler $target || test -n "$container_image"; then
1842 test -n "$container_image" && build_static=y
1843 mkdir -p "tests/tcg/$target"
1844 config_target_mak=tests/tcg/$target/config-target.mak
1845 ln -sf "$source_path/tests/tcg/Makefile.target" "tests/tcg/$target/Makefile"
1846 echo "# Automatically generated by configure - do not modify" > "$config_target_mak"
1847 echo "TARGET_NAME=$arch" >> "$config_target_mak"
1848 echo "TARGET=$target" >> "$config_target_mak"
1849 write_target_makefile "build-tcg-tests-$target" >> "$config_target_mak"
1850 echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
1851 echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
1853 # will GDB work with these binaries?
1854 if test "${gdb_arches#*$arch}" != "$gdb_arches"; then
1855 echo "HOST_GDB_SUPPORTS_ARCH=y" >> "$config_target_mak"
1858 echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs
1859 tcg_tests_targets="$tcg_tests_targets $target"
1861 done
1863 if test "$tcg" = "enabled"; then
1864 echo "TCG_TESTS_TARGETS=$tcg_tests_targets" >> config-host.mak
1868 if test "$skip_meson" = no; then
1869 cross="config-meson.cross.new"
1870 meson_quote() {
1871 test $# = 0 && return
1872 echo "'$(echo $* | sed "s/ /','/g")'"
1875 echo "# Automatically generated by configure - do not modify" > $cross
1876 echo "[properties]" >> $cross
1878 # unroll any custom device configs
1879 for a in $device_archs; do
1880 eval "c=\$devices_${a}"
1881 echo "${a}-softmmu = '$c'" >> $cross
1882 done
1884 echo "[built-in options]" >> $cross
1885 echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
1886 echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
1887 test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
1888 echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
1889 echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
1890 echo "[binaries]" >> $cross
1891 echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
1892 test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
1893 test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
1894 echo "ar = [$(meson_quote $ar)]" >> $cross
1895 echo "nm = [$(meson_quote $nm)]" >> $cross
1896 echo "pkgconfig = [$(meson_quote $pkg_config)]" >> $cross
1897 echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
1898 if has $sdl2_config; then
1899 echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
1901 echo "strip = [$(meson_quote $strip)]" >> $cross
1902 echo "widl = [$(meson_quote $widl)]" >> $cross
1903 echo "windres = [$(meson_quote $windres)]" >> $cross
1904 echo "windmc = [$(meson_quote $windmc)]" >> $cross
1905 if test "$cross_compile" = "yes"; then
1906 cross_arg="--cross-file config-meson.cross"
1907 echo "[host_machine]" >> $cross
1908 echo "system = '$targetos'" >> $cross
1909 case "$cpu" in
1910 i386)
1911 echo "cpu_family = 'x86'" >> $cross
1914 echo "cpu_family = '$cpu'" >> $cross
1916 esac
1917 echo "cpu = '$cpu'" >> $cross
1918 if test "$bigendian" = "yes" ; then
1919 echo "endian = 'big'" >> $cross
1920 else
1921 echo "endian = 'little'" >> $cross
1923 else
1924 cross_arg="--native-file config-meson.cross"
1926 mv $cross config-meson.cross
1928 rm -rf meson-private meson-info meson-logs
1930 # Built-in options
1931 test "$download" = "disabled" && meson_option_add "--wrap-mode=nodownload"
1932 test "$bindir" != "bin" && meson_option_add "-Dbindir=$bindir"
1933 test "$default_feature" = no && meson_option_add -Dauto_features=disabled
1934 test "$static" = yes && meson_option_add -Dprefer_static=true
1935 test "$pie" = no && meson_option_add -Db_pie=false
1936 test "$werror" = yes && meson_option_add -Dwerror=true
1938 # QEMU options
1939 test "$cfi" != false && meson_option_add "-Dcfi=$cfi"
1940 test "$docs" != auto && meson_option_add "-Ddocs=$docs"
1941 test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
1942 test "$qemu_suffix" != qemu && meson_option_add "-Dqemu_suffix=$qemu_suffix"
1943 test "$smbd" != '' && meson_option_add "-Dsmbd=$smbd"
1944 test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
1945 run_meson() {
1946 NINJA=$ninja $meson setup --prefix "$prefix" "$@" $cross_arg "$PWD" "$source_path"
1948 eval run_meson $meson_options
1949 if test "$?" -ne 0 ; then
1950 error_exit "meson setup failed"
1952 echo "$meson" > build.ninja.stamp
1953 else
1954 if test -f meson-private/cmd_line.txt; then
1955 # Adjust old command line options that were removed
1956 # sed -i is not portable
1957 perl -i -ne '
1958 /^sphinx_build/ && next;
1959 print;' meson-private/cmd_line.txt
1963 # Save the configure command line for later reuse.
1964 cat <<EOD >config.status
1965 #!/bin/sh
1966 # Generated by configure.
1967 # Run this file to recreate the current configuration.
1968 # Compiler output produced by configure, useful for debugging
1969 # configure, is in config.log if it exists.
1972 preserve_env() {
1973 envname=$1
1975 eval envval=\$$envname
1977 if test -n "$envval"
1978 then
1979 echo "$envname='$envval'" >> config.status
1980 echo "export $envname" >> config.status
1981 else
1982 echo "unset $envname" >> config.status
1986 # Preserve various env variables that influence what
1987 # features/build target configure will detect
1988 preserve_env AR
1989 preserve_env AS
1990 preserve_env CC
1991 preserve_env CFLAGS
1992 preserve_env CXX
1993 preserve_env CXXFLAGS
1994 preserve_env LD
1995 preserve_env LDFLAGS
1996 preserve_env LD_LIBRARY_PATH
1997 preserve_env NM
1998 preserve_env OBJCFLAGS
1999 preserve_env OBJCOPY
2000 preserve_env PATH
2001 preserve_env PKG_CONFIG
2002 preserve_env PKG_CONFIG_LIBDIR
2003 preserve_env PKG_CONFIG_PATH
2004 preserve_env PYTHON
2005 preserve_env QEMU_GA_MANUFACTURER
2006 preserve_env QEMU_GA_DISTRO
2007 preserve_env QEMU_GA_VERSION
2008 preserve_env SDL2_CONFIG
2009 preserve_env SMBD
2010 preserve_env STRIP
2011 preserve_env WIDL
2012 preserve_env WINDRES
2013 preserve_env WINDMC
2015 printf "exec" >>config.status
2016 for i in "$0" "$@"; do
2017 test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
2018 done
2019 echo ' "$@"' >>config.status
2020 chmod +x config.status
2022 rm -r "$TMPDIR1"