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