OSDN Git Service

Merge remote-tracking branch 'mst/tags/for_upstream' into staging
[qmiga/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 # Temporary directory used for files created while
15 # configure runs. Since it is in the build directory
16 # we can safely blow away any previous version of it
17 # (and we need not jump through hoops to try to delete
18 # it when configure exits.)
19 TMPDIR1="config-temp"
20 rm -rf "${TMPDIR1}"
21 mkdir -p "${TMPDIR1}"
22 if [ $? -ne 0 ]; then
23     echo "ERROR: failed to create temporary directory"
24     exit 1
25 fi
26
27 TMPB="qemu-conf"
28 TMPC="${TMPDIR1}/${TMPB}.c"
29 TMPO="${TMPDIR1}/${TMPB}.o"
30 TMPCXX="${TMPDIR1}/${TMPB}.cxx"
31 TMPE="${TMPDIR1}/${TMPB}.exe"
32 TMPMO="${TMPDIR1}/${TMPB}.mo"
33
34 rm -f config.log
35
36 # Print a helpful header at the top of config.log
37 echo "# QEMU configure log $(date)" >> config.log
38 printf "# Configured with:" >> config.log
39 printf " '%s'" "$0" "$@" >> config.log
40 echo >> config.log
41 echo "#" >> config.log
42
43 error_exit() {
44     echo
45     echo "ERROR: $1"
46     while test -n "$2"; do
47         echo "       $2"
48         shift
49     done
50     echo
51     exit 1
52 }
53
54 do_compiler() {
55     # Run the compiler, capturing its output to the log. First argument
56     # is compiler binary to execute.
57     local compiler="$1"
58     shift
59     echo $compiler "$@" >> config.log
60     $compiler "$@" >> config.log 2>&1 || return $?
61     # Test passed. If this is an --enable-werror build, rerun
62     # the test with -Werror and bail out if it fails. This
63     # makes warning-generating-errors in configure test code
64     # obvious to developers.
65     if test "$werror" != "yes"; then
66         return 0
67     fi
68     # Don't bother rerunning the compile if we were already using -Werror
69     case "$*" in
70         *-Werror*)
71            return 0
72         ;;
73     esac
74     echo $compiler -Werror "$@" >> config.log
75     $compiler -Werror "$@" >> config.log 2>&1 && return $?
76     error_exit "configure test passed without -Werror but failed with -Werror." \
77         "This is probably a bug in the configure script. The failing command" \
78         "will be at the bottom of config.log." \
79         "You can run configure with --disable-werror to bypass this check."
80 }
81
82 do_cc() {
83     do_compiler "$cc" "$@"
84 }
85
86 do_cxx() {
87     do_compiler "$cxx" "$@"
88 }
89
90 update_cxxflags() {
91     # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
92     # options which some versions of GCC's C++ compiler complain about
93     # because they only make sense for C programs.
94     QEMU_CXXFLAGS=
95     for arg in $QEMU_CFLAGS; do
96         case $arg in
97             -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\
98             -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls)
99                 ;;
100             *)
101                 QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg
102                 ;;
103         esac
104     done
105 }
106
107 compile_object() {
108   local_cflags="$1"
109   do_cc $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
110 }
111
112 compile_prog() {
113   local_cflags="$1"
114   local_ldflags="$2"
115   do_cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
116 }
117
118 # symbolically link $1 to $2.  Portable version of "ln -sf".
119 symlink() {
120   rm -rf "$2"
121   mkdir -p "$(dirname "$2")"
122   ln -s "$1" "$2"
123 }
124
125 # check whether a command is available to this shell (may be either an
126 # executable or a builtin)
127 has() {
128     type "$1" >/dev/null 2>&1
129 }
130
131 # search for an executable in PATH
132 path_of() {
133     local_command="$1"
134     local_ifs="$IFS"
135     local_dir=""
136
137     # pathname has a dir component?
138     if [ "${local_command#*/}" != "$local_command" ]; then
139         if [ -x "$local_command" ] && [ ! -d "$local_command" ]; then
140             echo "$local_command"
141             return 0
142         fi
143     fi
144     if [ -z "$local_command" ]; then
145         return 1
146     fi
147
148     IFS=:
149     for local_dir in $PATH; do
150         if [ -x "$local_dir/$local_command" ] && [ ! -d "$local_dir/$local_command" ]; then
151             echo "$local_dir/$local_command"
152             IFS="${local_ifs:-$(printf ' \t\n')}"
153             return 0
154         fi
155     done
156     # not found
157     IFS="${local_ifs:-$(printf ' \t\n')}"
158     return 1
159 }
160
161 have_backend () {
162     echo "$trace_backends" | grep "$1" >/dev/null
163 }
164
165 # default parameters
166 source_path=$(dirname "$0")
167 cpu=""
168 iasl="iasl"
169 interp_prefix="/usr/gnemul/qemu-%M"
170 static="no"
171 cross_prefix=""
172 audio_drv_list=""
173 block_drv_rw_whitelist=""
174 block_drv_ro_whitelist=""
175 host_cc="cc"
176 libs_softmmu=""
177 libs_tools=""
178 audio_pt_int=""
179 audio_win_int=""
180 cc_i386=i386-pc-linux-gnu-gcc
181 libs_qga=""
182 debug_info="yes"
183 stack_protector=""
184
185 # Don't accept a target_list environment variable.
186 unset target_list
187
188 # Default value for a variable defining feature "foo".
189 #  * foo="no"  feature will only be used if --enable-foo arg is given
190 #  * foo=""    feature will be searched for, and if found, will be used
191 #              unless --disable-foo is given
192 #  * foo="yes" this value will only be set by --enable-foo flag.
193 #              feature will searched for,
194 #              if not found, configure exits with error
195 #
196 # Always add --enable-foo and --disable-foo command line args.
197 # Distributions want to ensure that several features are compiled in, and it
198 # is impossible without a --enable-foo that exits if a feature is not found.
199
200 bluez=""
201 brlapi=""
202 curl=""
203 curses=""
204 docs=""
205 fdt=""
206 netmap="no"
207 pixman=""
208 sdl=""
209 sdlabi=""
210 virtfs=""
211 vnc="yes"
212 sparse="no"
213 vde=""
214 vnc_sasl=""
215 vnc_jpeg=""
216 vnc_png=""
217 xen=""
218 xen_ctrl_version=""
219 xen_pv_domain_build="no"
220 xen_pci_passthrough=""
221 linux_aio=""
222 cap_ng=""
223 attr=""
224 libattr=""
225 xfs=""
226
227 vhost_net="no"
228 vhost_scsi="no"
229 vhost_vsock="no"
230 kvm="no"
231 hax="no"
232 rdma=""
233 gprof="no"
234 debug_tcg="no"
235 debug="no"
236 fortify_source=""
237 strip_opt="yes"
238 tcg_interpreter="no"
239 bigendian="no"
240 mingw32="no"
241 gcov="no"
242 gcov_tool="gcov"
243 EXESUF=""
244 DSOSUF=".so"
245 LDFLAGS_SHARED="-shared"
246 modules="no"
247 prefix="/usr/local"
248 mandir="\${prefix}/share/man"
249 datadir="\${prefix}/share"
250 qemu_docdir="\${prefix}/share/doc/qemu"
251 bindir="\${prefix}/bin"
252 libdir="\${prefix}/lib"
253 libexecdir="\${prefix}/libexec"
254 includedir="\${prefix}/include"
255 sysconfdir="\${prefix}/etc"
256 local_statedir="\${prefix}/var"
257 confsuffix="/qemu"
258 slirp="yes"
259 oss_lib=""
260 bsd="no"
261 linux="no"
262 solaris="no"
263 profiler="no"
264 cocoa="no"
265 softmmu="yes"
266 linux_user="no"
267 bsd_user="no"
268 aix="no"
269 blobs="yes"
270 pkgversion=""
271 pie=""
272 qom_cast_debug="yes"
273 trace_backends="log"
274 trace_file="trace"
275 spice=""
276 rbd=""
277 smartcard=""
278 libusb=""
279 usb_redir=""
280 opengl=""
281 opengl_dmabuf="no"
282 avx2_opt="no"
283 zlib="yes"
284 lzo=""
285 snappy=""
286 bzip2=""
287 guest_agent=""
288 guest_agent_with_vss="no"
289 guest_agent_ntddscsi="no"
290 guest_agent_msi=""
291 vss_win32_sdk=""
292 win_sdk="no"
293 want_tools="yes"
294 libiscsi=""
295 libnfs=""
296 coroutine=""
297 coroutine_pool=""
298 debug_stack_usage="no"
299 seccomp=""
300 glusterfs=""
301 glusterfs_xlator_opt="no"
302 glusterfs_discard="no"
303 glusterfs_zerofill="no"
304 gtk=""
305 gtkabi=""
306 gtk_gl="no"
307 tls_priority="NORMAL"
308 gnutls=""
309 gnutls_rnd=""
310 nettle=""
311 nettle_kdf="no"
312 gcrypt=""
313 gcrypt_hmac="no"
314 gcrypt_kdf="no"
315 vte=""
316 virglrenderer=""
317 tpm="yes"
318 libssh2=""
319 numa=""
320 tcmalloc="no"
321 jemalloc="no"
322 replication="yes"
323 vxhs=""
324
325 supported_cpu="no"
326 supported_os="no"
327 bogus_os="no"
328
329 # parse CC options first
330 for opt do
331   optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
332   case "$opt" in
333   --cross-prefix=*) cross_prefix="$optarg"
334   ;;
335   --cc=*) CC="$optarg"
336   ;;
337   --cxx=*) CXX="$optarg"
338   ;;
339   --source-path=*) source_path="$optarg"
340   ;;
341   --cpu=*) cpu="$optarg"
342   ;;
343   --extra-cflags=*) QEMU_CFLAGS="$QEMU_CFLAGS $optarg"
344                     EXTRA_CFLAGS="$optarg"
345   ;;
346   --extra-ldflags=*) LDFLAGS="$LDFLAGS $optarg"
347                      EXTRA_LDFLAGS="$optarg"
348   ;;
349   --enable-debug-info) debug_info="yes"
350   ;;
351   --disable-debug-info) debug_info="no"
352   ;;
353   esac
354 done
355 # OS specific
356 # Using uname is really, really broken.  Once we have the right set of checks
357 # we can eliminate its usage altogether.
358
359 # Preferred compiler:
360 #  ${CC} (if set)
361 #  ${cross_prefix}gcc (if cross-prefix specified)
362 #  system compiler
363 if test -z "${CC}${cross_prefix}"; then
364   cc="$host_cc"
365 else
366   cc="${CC-${cross_prefix}gcc}"
367 fi
368
369 if test -z "${CXX}${cross_prefix}"; then
370   cxx="c++"
371 else
372   cxx="${CXX-${cross_prefix}g++}"
373 fi
374
375 ar="${AR-${cross_prefix}ar}"
376 as="${AS-${cross_prefix}as}"
377 ccas="${CCAS-$cc}"
378 cpp="${CPP-$cc -E}"
379 objcopy="${OBJCOPY-${cross_prefix}objcopy}"
380 ld="${LD-${cross_prefix}ld}"
381 nm="${NM-${cross_prefix}nm}"
382 strip="${STRIP-${cross_prefix}strip}"
383 windres="${WINDRES-${cross_prefix}windres}"
384 pkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
385 query_pkg_config() {
386     "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
387 }
388 pkg_config=query_pkg_config
389 sdl_config="${SDL_CONFIG-${cross_prefix}sdl-config}"
390 sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
391
392 # If the user hasn't specified ARFLAGS, default to 'rv', just as make does.
393 ARFLAGS="${ARFLAGS-rv}"
394
395 # default flags for all hosts
396 # We use -fwrapv to tell the compiler that we require a C dialect where
397 # left shift of signed integers is well defined and has the expected
398 # 2s-complement style results. (Both clang and gcc agree that it
399 # provides these semantics.)
400 QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv $QEMU_CFLAGS"
401 QEMU_CFLAGS="-Wall -Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
402 QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
403 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
404 QEMU_INCLUDES="-I. -I\$(SRC_PATH) -I\$(SRC_PATH)/include"
405 if test "$debug_info" = "yes"; then
406     CFLAGS="-g $CFLAGS"
407     LDFLAGS="-g $LDFLAGS"
408 fi
409
410 # make source path absolute
411 source_path=$(cd "$source_path"; pwd)
412
413 # running configure in the source tree?
414 # we know that's the case if configure is there.
415 if test -f "./configure"; then
416     pwd_is_source_path="y"
417 else
418     pwd_is_source_path="n"
419 fi
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='MINGW32'
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 else
456   targetos=$(uname -s)
457 fi
458
459 # Some host OSes need non-standard checks for which CPU to use.
460 # Note that these checks are broken for cross-compilation: if you're
461 # cross-compiling to one of these OSes then you'll need to specify
462 # the correct CPU with the --cpu option.
463 case $targetos in
464 Darwin)
465   # on Leopard most of the system is 32-bit, so we have to ask the kernel if we can
466   # run 64-bit userspace code.
467   # If the user didn't specify a CPU explicitly and the kernel says this is
468   # 64 bit hw, then assume x86_64. Otherwise fall through to the usual detection code.
469   if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then
470     cpu="x86_64"
471   fi
472   ;;
473 SunOS)
474   # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo
475   if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
476     cpu="x86_64"
477   fi
478 esac
479
480 if test ! -z "$cpu" ; then
481   # command line argument
482   :
483 elif check_define __i386__ ; then
484   cpu="i386"
485 elif check_define __x86_64__ ; then
486   if check_define __ILP32__ ; then
487     cpu="x32"
488   else
489     cpu="x86_64"
490   fi
491 elif check_define __sparc__ ; then
492   if check_define __arch64__ ; then
493     cpu="sparc64"
494   else
495     cpu="sparc"
496   fi
497 elif check_define _ARCH_PPC ; then
498   if check_define _ARCH_PPC64 ; then
499     cpu="ppc64"
500   else
501     cpu="ppc"
502   fi
503 elif check_define __mips__ ; then
504   cpu="mips"
505 elif check_define __ia64__ ; then
506   cpu="ia64"
507 elif check_define __s390__ ; then
508   if check_define __s390x__ ; then
509     cpu="s390x"
510   else
511     cpu="s390"
512   fi
513 elif check_define __arm__ ; then
514   cpu="arm"
515 elif check_define __aarch64__ ; then
516   cpu="aarch64"
517 else
518   cpu=$(uname -m)
519 fi
520
521 ARCH=
522 # Normalise host CPU name and set ARCH.
523 # Note that this case should only have supported host CPUs, not guests.
524 case "$cpu" in
525   ppc|ppc64|s390|s390x|sparc64|x32)
526     cpu="$cpu"
527     supported_cpu="yes"
528   ;;
529   ia64)
530     cpu="$cpu"
531   ;;
532   i386|i486|i586|i686|i86pc|BePC)
533     cpu="i386"
534     supported_cpu="yes"
535   ;;
536   x86_64|amd64)
537     cpu="x86_64"
538     supported_cpu="yes"
539   ;;
540   armv*b|armv*l|arm)
541     cpu="arm"
542     supported_cpu="yes"
543   ;;
544   aarch64)
545     cpu="aarch64"
546     supported_cpu="yes"
547   ;;
548   mips*)
549     cpu="mips"
550     supported_cpu="yes"
551   ;;
552   sparc|sun4[cdmuv])
553     cpu="sparc"
554     supported_cpu="yes"
555   ;;
556   *)
557     # This will result in either an error or falling back to TCI later
558     ARCH=unknown
559   ;;
560 esac
561 if test -z "$ARCH"; then
562   ARCH="$cpu"
563 fi
564
565 # OS specific
566
567 # host *BSD for user mode
568 HOST_VARIANT_DIR=""
569
570 case $targetos in
571 MINGW32*)
572   mingw32="yes"
573   hax="yes"
574   audio_possible_drivers="dsound sdl"
575   if check_include dsound.h; then
576     audio_drv_list="dsound"
577   else
578     audio_drv_list=""
579   fi
580   supported_os="yes"
581 ;;
582 GNU/kFreeBSD)
583   bsd="yes"
584   audio_drv_list="oss"
585   audio_possible_drivers="oss sdl pa"
586 ;;
587 FreeBSD)
588   bsd="yes"
589   make="${MAKE-gmake}"
590   audio_drv_list="oss"
591   audio_possible_drivers="oss sdl pa"
592   # needed for kinfo_getvmmap(3) in libutil.h
593   LIBS="-lutil $LIBS"
594   # needed for kinfo_getproc
595   libs_qga="-lutil $libs_qga"
596   netmap=""  # enable netmap autodetect
597   HOST_VARIANT_DIR="freebsd"
598   supported_os="yes"
599 ;;
600 DragonFly)
601   bsd="yes"
602   make="${MAKE-gmake}"
603   audio_drv_list="oss"
604   audio_possible_drivers="oss sdl pa"
605   HOST_VARIANT_DIR="dragonfly"
606 ;;
607 NetBSD)
608   bsd="yes"
609   make="${MAKE-gmake}"
610   audio_drv_list="oss"
611   audio_possible_drivers="oss sdl"
612   oss_lib="-lossaudio"
613   HOST_VARIANT_DIR="netbsd"
614   supported_os="yes"
615 ;;
616 OpenBSD)
617   bsd="yes"
618   make="${MAKE-gmake}"
619   audio_drv_list="sdl"
620   audio_possible_drivers="sdl"
621   HOST_VARIANT_DIR="openbsd"
622 ;;
623 Darwin)
624   bsd="yes"
625   darwin="yes"
626   hax="yes"
627   LDFLAGS_SHARED="-bundle -undefined dynamic_lookup"
628   if [ "$cpu" = "x86_64" ] ; then
629     QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
630     LDFLAGS="-arch x86_64 $LDFLAGS"
631   fi
632   cocoa="yes"
633   audio_drv_list="coreaudio"
634   audio_possible_drivers="coreaudio sdl"
635   LDFLAGS="-framework CoreFoundation -framework IOKit $LDFLAGS"
636   libs_softmmu="-F/System/Library/Frameworks -framework Cocoa -framework IOKit $libs_softmmu"
637   # Disable attempts to use ObjectiveC features in os/object.h since they
638   # won't work when we're compiling with gcc as a C compiler.
639   QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
640   HOST_VARIANT_DIR="darwin"
641   supported_os="yes"
642 ;;
643 SunOS)
644   solaris="yes"
645   make="${MAKE-gmake}"
646   install="${INSTALL-ginstall}"
647   ld="gld"
648   smbd="${SMBD-/usr/sfw/sbin/smbd}"
649   needs_libsunmath="no"
650   solarisrev=$(uname -r | cut -f2 -d.)
651   if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
652     if test "$solarisrev" -le 9 ; then
653       if test -f /opt/SUNWspro/prod/lib/libsunmath.so.1; then
654         needs_libsunmath="yes"
655         QEMU_CFLAGS="-I/opt/SUNWspro/prod/include/cc $QEMU_CFLAGS"
656         LDFLAGS="-L/opt/SUNWspro/prod/lib -R/opt/SUNWspro/prod/lib $LDFLAGS"
657         LIBS="-lsunmath $LIBS"
658       else
659         error_exit "QEMU will not link correctly on Solaris 8/X86 or 9/x86 without" \
660             "libsunmath from the Sun Studio compilers tools, due to a lack of" \
661             "C99 math features in libm.so in Solaris 8/x86 and Solaris 9/x86" \
662             "Studio 11 can be downloaded from www.sun.com."
663       fi
664     fi
665   fi
666   if test -f /usr/include/sys/soundcard.h ; then
667     audio_drv_list="oss"
668   fi
669   audio_possible_drivers="oss sdl"
670 # needed for CMSG_ macros in sys/socket.h
671   QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
672 # needed for TIOCWIN* defines in termios.h
673   QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
674   QEMU_CFLAGS="-std=gnu99 $QEMU_CFLAGS"
675   solarisnetlibs="-lsocket -lnsl -lresolv"
676   LIBS="$solarisnetlibs $LIBS"
677   libs_qga="$solarisnetlibs $libs_qga"
678 ;;
679 AIX)
680   aix="yes"
681   make="${MAKE-gmake}"
682 ;;
683 Haiku)
684   haiku="yes"
685   QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS $QEMU_CFLAGS"
686   LIBS="-lposix_error_mapper -lnetwork $LIBS"
687 ;;
688 Linux)
689   audio_drv_list="oss"
690   audio_possible_drivers="oss alsa sdl pa"
691   linux="yes"
692   linux_user="yes"
693   kvm="yes"
694   vhost_net="yes"
695   vhost_scsi="yes"
696   vhost_vsock="yes"
697   QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES"
698   supported_os="yes"
699 ;;
700 *)
701   # This is a fatal error, but don't report it yet, because we
702   # might be going to just print the --help text, or it might
703   # be the result of a missing compiler.
704   bogus_os="yes"
705 ;;
706 esac
707
708 if [ "$bsd" = "yes" ] ; then
709   if [ "$darwin" != "yes" ] ; then
710     bsd_user="yes"
711   fi
712 fi
713
714 : ${make=${MAKE-make}}
715 : ${install=${INSTALL-install}}
716 : ${python=${PYTHON-python}}
717 : ${smbd=${SMBD-/usr/sbin/smbd}}
718
719 # Default objcc to clang if available, otherwise use CC
720 if has clang; then
721   objcc=clang
722 else
723   objcc="$cc"
724 fi
725
726 if test "$mingw32" = "yes" ; then
727   EXESUF=".exe"
728   DSOSUF=".dll"
729   QEMU_CFLAGS="-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 $QEMU_CFLAGS"
730   # enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later)
731   QEMU_CFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $QEMU_CFLAGS"
732   # MinGW needs -mthreads for TLS and macro _MT.
733   QEMU_CFLAGS="-mthreads $QEMU_CFLAGS"
734   LIBS="-lwinmm -lws2_32 -liphlpapi $LIBS"
735   write_c_skeleton;
736   if compile_prog "" "-liberty" ; then
737     LIBS="-liberty $LIBS"
738   fi
739   prefix="c:/Program Files/QEMU"
740   mandir="\${prefix}"
741   datadir="\${prefix}"
742   qemu_docdir="\${prefix}"
743   bindir="\${prefix}"
744   sysconfdir="\${prefix}"
745   local_statedir=
746   confsuffix=""
747   libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -liphlpapi -lnetapi32 $libs_qga"
748 fi
749
750 werror=""
751
752 for opt do
753   optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
754   case "$opt" in
755   --help|-h) show_help=yes
756   ;;
757   --version|-V) exec cat $source_path/VERSION
758   ;;
759   --prefix=*) prefix="$optarg"
760   ;;
761   --interp-prefix=*) interp_prefix="$optarg"
762   ;;
763   --source-path=*)
764   ;;
765   --cross-prefix=*)
766   ;;
767   --cc=*)
768   ;;
769   --host-cc=*) host_cc="$optarg"
770   ;;
771   --cxx=*)
772   ;;
773   --iasl=*) iasl="$optarg"
774   ;;
775   --objcc=*) objcc="$optarg"
776   ;;
777   --make=*) make="$optarg"
778   ;;
779   --install=*) install="$optarg"
780   ;;
781   --python=*) python="$optarg"
782   ;;
783   --gcov=*) gcov_tool="$optarg"
784   ;;
785   --smbd=*) smbd="$optarg"
786   ;;
787   --extra-cflags=*)
788   ;;
789   --extra-ldflags=*)
790   ;;
791   --enable-debug-info)
792   ;;
793   --disable-debug-info)
794   ;;
795   --enable-modules)
796       modules="yes"
797   ;;
798   --disable-modules)
799       modules="no"
800   ;;
801   --cpu=*)
802   ;;
803   --target-list=*) target_list="$optarg"
804   ;;
805   --enable-trace-backends=*) trace_backends="$optarg"
806   ;;
807   # XXX: backwards compatibility
808   --enable-trace-backend=*) trace_backends="$optarg"
809   ;;
810   --with-trace-file=*) trace_file="$optarg"
811   ;;
812   --enable-gprof) gprof="yes"
813   ;;
814   --enable-gcov) gcov="yes"
815   ;;
816   --static)
817     static="yes"
818     LDFLAGS="-static $LDFLAGS"
819     QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
820   ;;
821   --mandir=*) mandir="$optarg"
822   ;;
823   --bindir=*) bindir="$optarg"
824   ;;
825   --libdir=*) libdir="$optarg"
826   ;;
827   --libexecdir=*) libexecdir="$optarg"
828   ;;
829   --includedir=*) includedir="$optarg"
830   ;;
831   --datadir=*) datadir="$optarg"
832   ;;
833   --with-confsuffix=*) confsuffix="$optarg"
834   ;;
835   --docdir=*) qemu_docdir="$optarg"
836   ;;
837   --sysconfdir=*) sysconfdir="$optarg"
838   ;;
839   --localstatedir=*) local_statedir="$optarg"
840   ;;
841   --sbindir=*|--sharedstatedir=*|\
842   --oldincludedir=*|--datarootdir=*|--infodir=*|--localedir=*|\
843   --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
844     # These switches are silently ignored, for compatibility with
845     # autoconf-generated configure scripts. This allows QEMU's
846     # configure to be used by RPM and similar macros that set
847     # lots of directory switches by default.
848   ;;
849   --with-system-pixman) pixman="system"
850   ;;
851   --without-system-pixman) pixman="internal"
852   ;;
853   --without-pixman) pixman="none"
854   ;;
855   --disable-sdl) sdl="no"
856   ;;
857   --enable-sdl) sdl="yes"
858   ;;
859   --with-sdlabi=*) sdlabi="$optarg"
860   ;;
861   --disable-qom-cast-debug) qom_cast_debug="no"
862   ;;
863   --enable-qom-cast-debug) qom_cast_debug="yes"
864   ;;
865   --disable-virtfs) virtfs="no"
866   ;;
867   --enable-virtfs) virtfs="yes"
868   ;;
869   --disable-vnc) vnc="no"
870   ;;
871   --enable-vnc) vnc="yes"
872   ;;
873   --oss-lib=*) oss_lib="$optarg"
874   ;;
875   --audio-drv-list=*) audio_drv_list="$optarg"
876   ;;
877   --block-drv-rw-whitelist=*|--block-drv-whitelist=*) block_drv_rw_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
878   ;;
879   --block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
880   ;;
881   --enable-debug-tcg) debug_tcg="yes"
882   ;;
883   --disable-debug-tcg) debug_tcg="no"
884   ;;
885   --enable-debug)
886       # Enable debugging options that aren't excessively noisy
887       debug_tcg="yes"
888       debug="yes"
889       strip_opt="no"
890       fortify_source="no"
891   ;;
892   --enable-sparse) sparse="yes"
893   ;;
894   --disable-sparse) sparse="no"
895   ;;
896   --disable-strip) strip_opt="no"
897   ;;
898   --disable-vnc-sasl) vnc_sasl="no"
899   ;;
900   --enable-vnc-sasl) vnc_sasl="yes"
901   ;;
902   --disable-vnc-jpeg) vnc_jpeg="no"
903   ;;
904   --enable-vnc-jpeg) vnc_jpeg="yes"
905   ;;
906   --disable-vnc-png) vnc_png="no"
907   ;;
908   --enable-vnc-png) vnc_png="yes"
909   ;;
910   --disable-slirp) slirp="no"
911   ;;
912   --disable-vde) vde="no"
913   ;;
914   --enable-vde) vde="yes"
915   ;;
916   --disable-netmap) netmap="no"
917   ;;
918   --enable-netmap) netmap="yes"
919   ;;
920   --disable-xen) xen="no"
921   ;;
922   --enable-xen) xen="yes"
923   ;;
924   --disable-xen-pci-passthrough) xen_pci_passthrough="no"
925   ;;
926   --enable-xen-pci-passthrough) xen_pci_passthrough="yes"
927   ;;
928   --disable-xen-pv-domain-build) xen_pv_domain_build="no"
929   ;;
930   --enable-xen-pv-domain-build) xen_pv_domain_build="yes"
931   ;;
932   --disable-brlapi) brlapi="no"
933   ;;
934   --enable-brlapi) brlapi="yes"
935   ;;
936   --disable-bluez) bluez="no"
937   ;;
938   --enable-bluez) bluez="yes"
939   ;;
940   --disable-kvm) kvm="no"
941   ;;
942   --enable-kvm) kvm="yes"
943   ;;
944   --disable-hax) hax="no"
945   ;;
946   --enable-hax) hax="yes"
947   ;;
948   --disable-tcg-interpreter) tcg_interpreter="no"
949   ;;
950   --enable-tcg-interpreter) tcg_interpreter="yes"
951   ;;
952   --disable-cap-ng)  cap_ng="no"
953   ;;
954   --enable-cap-ng) cap_ng="yes"
955   ;;
956   --disable-spice) spice="no"
957   ;;
958   --enable-spice) spice="yes"
959   ;;
960   --disable-libiscsi) libiscsi="no"
961   ;;
962   --enable-libiscsi) libiscsi="yes"
963   ;;
964   --disable-libnfs) libnfs="no"
965   ;;
966   --enable-libnfs) libnfs="yes"
967   ;;
968   --enable-profiler) profiler="yes"
969   ;;
970   --disable-cocoa) cocoa="no"
971   ;;
972   --enable-cocoa)
973       cocoa="yes" ;
974       audio_drv_list="coreaudio $(echo $audio_drv_list | sed s,coreaudio,,g)"
975   ;;
976   --disable-system) softmmu="no"
977   ;;
978   --enable-system) softmmu="yes"
979   ;;
980   --disable-user)
981       linux_user="no" ;
982       bsd_user="no" ;
983   ;;
984   --enable-user) ;;
985   --disable-linux-user) linux_user="no"
986   ;;
987   --enable-linux-user) linux_user="yes"
988   ;;
989   --disable-bsd-user) bsd_user="no"
990   ;;
991   --enable-bsd-user) bsd_user="yes"
992   ;;
993   --enable-pie) pie="yes"
994   ;;
995   --disable-pie) pie="no"
996   ;;
997   --enable-werror) werror="yes"
998   ;;
999   --disable-werror) werror="no"
1000   ;;
1001   --enable-stack-protector) stack_protector="yes"
1002   ;;
1003   --disable-stack-protector) stack_protector="no"
1004   ;;
1005   --disable-curses) curses="no"
1006   ;;
1007   --enable-curses) curses="yes"
1008   ;;
1009   --disable-curl) curl="no"
1010   ;;
1011   --enable-curl) curl="yes"
1012   ;;
1013   --disable-fdt) fdt="no"
1014   ;;
1015   --enable-fdt) fdt="yes"
1016   ;;
1017   --disable-linux-aio) linux_aio="no"
1018   ;;
1019   --enable-linux-aio) linux_aio="yes"
1020   ;;
1021   --disable-attr) attr="no"
1022   ;;
1023   --enable-attr) attr="yes"
1024   ;;
1025   --disable-blobs) blobs="no"
1026   ;;
1027   --with-pkgversion=*) pkgversion=" ($optarg)"
1028   ;;
1029   --with-coroutine=*) coroutine="$optarg"
1030   ;;
1031   --disable-coroutine-pool) coroutine_pool="no"
1032   ;;
1033   --enable-coroutine-pool) coroutine_pool="yes"
1034   ;;
1035   --enable-debug-stack-usage) debug_stack_usage="yes"
1036   ;;
1037   --disable-docs) docs="no"
1038   ;;
1039   --enable-docs) docs="yes"
1040   ;;
1041   --disable-vhost-net) vhost_net="no"
1042   ;;
1043   --enable-vhost-net) vhost_net="yes"
1044   ;;
1045   --disable-vhost-scsi) vhost_scsi="no"
1046   ;;
1047   --enable-vhost-scsi) vhost_scsi="yes"
1048   ;;
1049   --disable-vhost-vsock) vhost_vsock="no"
1050   ;;
1051   --enable-vhost-vsock) vhost_vsock="yes"
1052   ;;
1053   --disable-opengl) opengl="no"
1054   ;;
1055   --enable-opengl) opengl="yes"
1056   ;;
1057   --disable-rbd) rbd="no"
1058   ;;
1059   --enable-rbd) rbd="yes"
1060   ;;
1061   --disable-xfsctl) xfs="no"
1062   ;;
1063   --enable-xfsctl) xfs="yes"
1064   ;;
1065   --disable-smartcard) smartcard="no"
1066   ;;
1067   --enable-smartcard) smartcard="yes"
1068   ;;
1069   --disable-libusb) libusb="no"
1070   ;;
1071   --enable-libusb) libusb="yes"
1072   ;;
1073   --disable-usb-redir) usb_redir="no"
1074   ;;
1075   --enable-usb-redir) usb_redir="yes"
1076   ;;
1077   --disable-zlib-test) zlib="no"
1078   ;;
1079   --disable-lzo) lzo="no"
1080   ;;
1081   --enable-lzo) lzo="yes"
1082   ;;
1083   --disable-snappy) snappy="no"
1084   ;;
1085   --enable-snappy) snappy="yes"
1086   ;;
1087   --disable-bzip2) bzip2="no"
1088   ;;
1089   --enable-bzip2) bzip2="yes"
1090   ;;
1091   --enable-guest-agent) guest_agent="yes"
1092   ;;
1093   --disable-guest-agent) guest_agent="no"
1094   ;;
1095   --enable-guest-agent-msi) guest_agent_msi="yes"
1096   ;;
1097   --disable-guest-agent-msi) guest_agent_msi="no"
1098   ;;
1099   --with-vss-sdk) vss_win32_sdk=""
1100   ;;
1101   --with-vss-sdk=*) vss_win32_sdk="$optarg"
1102   ;;
1103   --without-vss-sdk) vss_win32_sdk="no"
1104   ;;
1105   --with-win-sdk) win_sdk=""
1106   ;;
1107   --with-win-sdk=*) win_sdk="$optarg"
1108   ;;
1109   --without-win-sdk) win_sdk="no"
1110   ;;
1111   --enable-tools) want_tools="yes"
1112   ;;
1113   --disable-tools) want_tools="no"
1114   ;;
1115   --enable-seccomp) seccomp="yes"
1116   ;;
1117   --disable-seccomp) seccomp="no"
1118   ;;
1119   --disable-glusterfs) glusterfs="no"
1120   ;;
1121   --enable-glusterfs) glusterfs="yes"
1122   ;;
1123   --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
1124       echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
1125   ;;
1126   --enable-vhdx|--disable-vhdx)
1127       echo "$0: $opt is obsolete, VHDX driver is always built" >&2
1128   ;;
1129   --enable-uuid|--disable-uuid)
1130       echo "$0: $opt is obsolete, UUID support is always built" >&2
1131   ;;
1132   --disable-gtk) gtk="no"
1133   ;;
1134   --enable-gtk) gtk="yes"
1135   ;;
1136   --tls-priority=*) tls_priority="$optarg"
1137   ;;
1138   --disable-gnutls) gnutls="no"
1139   ;;
1140   --enable-gnutls) gnutls="yes"
1141   ;;
1142   --disable-nettle) nettle="no"
1143   ;;
1144   --enable-nettle) nettle="yes"
1145   ;;
1146   --disable-gcrypt) gcrypt="no"
1147   ;;
1148   --enable-gcrypt) gcrypt="yes"
1149   ;;
1150   --enable-rdma) rdma="yes"
1151   ;;
1152   --disable-rdma) rdma="no"
1153   ;;
1154   --with-gtkabi=*) gtkabi="$optarg"
1155   ;;
1156   --disable-vte) vte="no"
1157   ;;
1158   --enable-vte) vte="yes"
1159   ;;
1160   --disable-virglrenderer) virglrenderer="no"
1161   ;;
1162   --enable-virglrenderer) virglrenderer="yes"
1163   ;;
1164   --disable-tpm) tpm="no"
1165   ;;
1166   --enable-tpm) tpm="yes"
1167   ;;
1168   --disable-libssh2) libssh2="no"
1169   ;;
1170   --enable-libssh2) libssh2="yes"
1171   ;;
1172   --disable-numa) numa="no"
1173   ;;
1174   --enable-numa) numa="yes"
1175   ;;
1176   --disable-tcmalloc) tcmalloc="no"
1177   ;;
1178   --enable-tcmalloc) tcmalloc="yes"
1179   ;;
1180   --disable-jemalloc) jemalloc="no"
1181   ;;
1182   --enable-jemalloc) jemalloc="yes"
1183   ;;
1184   --disable-replication) replication="no"
1185   ;;
1186   --enable-replication) replication="yes"
1187   ;;
1188   --disable-vxhs) vxhs="no"
1189   ;;
1190   --enable-vxhs) vxhs="yes"
1191   ;;
1192   *)
1193       echo "ERROR: unknown option $opt"
1194       echo "Try '$0 --help' for more information"
1195       exit 1
1196   ;;
1197   esac
1198 done
1199
1200 case "$cpu" in
1201     ppc)
1202            CPU_CFLAGS="-m32"
1203            LDFLAGS="-m32 $LDFLAGS"
1204            ;;
1205     ppc64)
1206            CPU_CFLAGS="-m64"
1207            LDFLAGS="-m64 $LDFLAGS"
1208            ;;
1209     sparc)
1210            LDFLAGS="-m32 $LDFLAGS"
1211            CPU_CFLAGS="-m32 -mcpu=ultrasparc"
1212            ;;
1213     sparc64)
1214            LDFLAGS="-m64 $LDFLAGS"
1215            CPU_CFLAGS="-m64 -mcpu=ultrasparc"
1216            ;;
1217     s390)
1218            CPU_CFLAGS="-m31"
1219            LDFLAGS="-m31 $LDFLAGS"
1220            ;;
1221     s390x)
1222            CPU_CFLAGS="-m64"
1223            LDFLAGS="-m64 $LDFLAGS"
1224            ;;
1225     i386)
1226            CPU_CFLAGS="-m32"
1227            LDFLAGS="-m32 $LDFLAGS"
1228            cc_i386='$(CC) -m32'
1229            ;;
1230     x86_64)
1231            # ??? Only extremely old AMD cpus do not have cmpxchg16b.
1232            # If we truly care, we should simply detect this case at
1233            # runtime and generate the fallback to serial emulation.
1234            CPU_CFLAGS="-m64 -mcx16"
1235            LDFLAGS="-m64 $LDFLAGS"
1236            cc_i386='$(CC) -m32'
1237            ;;
1238     x32)
1239            CPU_CFLAGS="-mx32"
1240            LDFLAGS="-mx32 $LDFLAGS"
1241            cc_i386='$(CC) -m32'
1242            ;;
1243     # No special flags required for other host CPUs
1244 esac
1245
1246 QEMU_CFLAGS="$CPU_CFLAGS $QEMU_CFLAGS"
1247 EXTRA_CFLAGS="$CPU_CFLAGS $EXTRA_CFLAGS"
1248
1249 # For user-mode emulation the host arch has to be one we explicitly
1250 # support, even if we're using TCI.
1251 if [ "$ARCH" = "unknown" ]; then
1252   bsd_user="no"
1253   linux_user="no"
1254 fi
1255
1256 default_target_list=""
1257
1258 mak_wilds=""
1259
1260 if [ "$softmmu" = "yes" ]; then
1261     mak_wilds="${mak_wilds} $source_path/default-configs/*-softmmu.mak"
1262 fi
1263 if [ "$linux_user" = "yes" ]; then
1264     mak_wilds="${mak_wilds} $source_path/default-configs/*-linux-user.mak"
1265 fi
1266 if [ "$bsd_user" = "yes" ]; then
1267     mak_wilds="${mak_wilds} $source_path/default-configs/*-bsd-user.mak"
1268 fi
1269
1270 for config in $mak_wilds; do
1271     default_target_list="${default_target_list} $(basename "$config" .mak)"
1272 done
1273
1274 # Enumerate public trace backends for --help output
1275 trace_backend_list=$(echo $(grep -le '^PUBLIC = True$' "$source_path"/scripts/tracetool/backend/*.py | sed -e 's/^.*\/\(.*\)\.py$/\1/'))
1276
1277 if test x"$show_help" = x"yes" ; then
1278 cat << EOF
1279
1280 Usage: configure [options]
1281 Options: [defaults in brackets after descriptions]
1282
1283 Standard options:
1284   --help                   print this message
1285   --prefix=PREFIX          install in PREFIX [$prefix]
1286   --interp-prefix=PREFIX   where to find shared libraries, etc.
1287                            use %M for cpu name [$interp_prefix]
1288   --target-list=LIST       set target list (default: build everything)
1289 $(echo Available targets: $default_target_list | \
1290   fold -s -w 53 | sed -e 's/^/                           /')
1291
1292 Advanced options (experts only):
1293   --source-path=PATH       path of source code [$source_path]
1294   --cross-prefix=PREFIX    use PREFIX for compile tools [$cross_prefix]
1295   --cc=CC                  use C compiler CC [$cc]
1296   --iasl=IASL              use ACPI compiler IASL [$iasl]
1297   --host-cc=CC             use C compiler CC [$host_cc] for code run at
1298                            build time
1299   --cxx=CXX                use C++ compiler CXX [$cxx]
1300   --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
1301   --extra-cflags=CFLAGS    append extra C compiler flags QEMU_CFLAGS
1302   --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
1303   --make=MAKE              use specified make [$make]
1304   --install=INSTALL        use specified install [$install]
1305   --python=PYTHON          use specified python [$python]
1306   --smbd=SMBD              use specified smbd [$smbd]
1307   --static                 enable static build [$static]
1308   --mandir=PATH            install man pages in PATH
1309   --datadir=PATH           install firmware in PATH$confsuffix
1310   --docdir=PATH            install documentation in PATH$confsuffix
1311   --bindir=PATH            install binaries in PATH
1312   --libdir=PATH            install libraries in PATH
1313   --sysconfdir=PATH        install config in PATH$confsuffix
1314   --localstatedir=PATH     install local state in PATH (set at runtime on win32)
1315   --with-confsuffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir [$confsuffix]
1316   --enable-debug           enable common debug build options
1317   --disable-strip          disable stripping binaries
1318   --disable-werror         disable compilation abort on warning
1319   --disable-stack-protector disable compiler-provided stack protection
1320   --audio-drv-list=LIST    set audio drivers list:
1321                            Available drivers: $audio_possible_drivers
1322   --block-drv-whitelist=L  Same as --block-drv-rw-whitelist=L
1323   --block-drv-rw-whitelist=L
1324                            set block driver read-write whitelist
1325                            (affects only QEMU, not qemu-img)
1326   --block-drv-ro-whitelist=L
1327                            set block driver read-only whitelist
1328                            (affects only QEMU, not qemu-img)
1329   --enable-trace-backends=B Set trace backend
1330                            Available backends: $trace_backend_list
1331   --with-trace-file=NAME   Full PATH,NAME of file to store traces
1332                            Default:trace-<pid>
1333   --disable-slirp          disable SLIRP userspace network connectivity
1334   --enable-tcg-interpreter enable TCG with bytecode interpreter (TCI)
1335   --oss-lib                path to OSS library
1336   --cpu=CPU                Build for host CPU [$cpu]
1337   --with-coroutine=BACKEND coroutine backend. Supported options:
1338                            ucontext, sigaltstack, windows
1339   --enable-gcov            enable test coverage analysis with gcov
1340   --gcov=GCOV              use specified gcov [$gcov_tool]
1341   --disable-blobs          disable installing provided firmware blobs
1342   --with-vss-sdk=SDK-path  enable Windows VSS support in QEMU Guest Agent
1343   --with-win-sdk=SDK-path  path to Windows Platform SDK (to build VSS .tlb)
1344   --tls-priority           default TLS protocol/cipher priority string
1345   --enable-gprof           QEMU profiling with gprof
1346   --enable-profiler        profiler support
1347   --enable-xen-pv-domain-build
1348                            xen pv domain builder
1349   --enable-debug-stack-usage
1350                            track the maximum stack usage of stacks created by qemu_alloc_stack
1351
1352 Optional features, enabled with --enable-FEATURE and
1353 disabled with --disable-FEATURE, default is enabled if available:
1354
1355   system          all system emulation targets
1356   user            supported user emulation targets
1357   linux-user      all linux usermode emulation targets
1358   bsd-user        all BSD usermode emulation targets
1359   docs            build documentation
1360   guest-agent     build the QEMU Guest Agent
1361   guest-agent-msi build guest agent Windows MSI installation package
1362   pie             Position Independent Executables
1363   modules         modules support
1364   debug-tcg       TCG debugging (default is disabled)
1365   debug-info      debugging information
1366   sparse          sparse checker
1367
1368   gnutls          GNUTLS cryptography support
1369   nettle          nettle cryptography support
1370   gcrypt          libgcrypt cryptography support
1371   sdl             SDL UI
1372   --with-sdlabi     select preferred SDL ABI 1.2 or 2.0
1373   gtk             gtk UI
1374   --with-gtkabi     select preferred GTK ABI 2.0 or 3.0
1375   vte             vte support for the gtk UI
1376   curses          curses UI
1377   vnc             VNC UI support
1378   vnc-sasl        SASL encryption for VNC server
1379   vnc-jpeg        JPEG lossy compression for VNC server
1380   vnc-png         PNG compression for VNC server
1381   cocoa           Cocoa UI (Mac OS X only)
1382   virtfs          VirtFS
1383   xen             xen backend driver support
1384   xen-pci-passthrough
1385   brlapi          BrlAPI (Braile)
1386   curl            curl connectivity
1387   fdt             fdt device tree
1388   bluez           bluez stack connectivity
1389   kvm             KVM acceleration support
1390   hax             HAX acceleration support
1391   rdma            RDMA-based migration support
1392   vde             support for vde network
1393   netmap          support for netmap network
1394   linux-aio       Linux AIO support
1395   cap-ng          libcap-ng support
1396   attr            attr and xattr support
1397   vhost-net       vhost-net acceleration support
1398   spice           spice
1399   rbd             rados block device (rbd)
1400   libiscsi        iscsi support
1401   libnfs          nfs support
1402   smartcard       smartcard support (libcacard)
1403   libusb          libusb (for usb passthrough)
1404   usb-redir       usb network redirection support
1405   lzo             support of lzo compression library
1406   snappy          support of snappy compression library
1407   bzip2           support of bzip2 compression library
1408                   (for reading bzip2-compressed dmg images)
1409   seccomp         seccomp support
1410   coroutine-pool  coroutine freelist (better performance)
1411   glusterfs       GlusterFS backend
1412   tpm             TPM support
1413   libssh2         ssh block device support
1414   numa            libnuma support
1415   tcmalloc        tcmalloc support
1416   jemalloc        jemalloc support
1417   replication     replication support
1418   vhost-vsock     virtio sockets device support
1419   opengl          opengl support
1420   virglrenderer   virgl rendering support
1421   xfsctl          xfsctl support
1422   qom-cast-debug  cast debugging support
1423   tools           build qemu-io, qemu-nbd and qemu-image tools
1424   vxhs            Veritas HyperScale vDisk backend support
1425
1426 NOTE: The object files are built at the place where configure is launched
1427 EOF
1428 exit 0
1429 fi
1430
1431 if ! has $python; then
1432   error_exit "Python not found. Use --python=/path/to/python"
1433 fi
1434
1435 # Note that if the Python conditional here evaluates True we will exit
1436 # with status 1 which is a shell 'false' value.
1437 if ! $python -c 'import sys; sys.exit(sys.version_info < (2,6) or sys.version_info >= (3,))'; then
1438   error_exit "Cannot use '$python', Python 2.6 or later is required." \
1439       "Note that Python 3 or later is not yet supported." \
1440       "Use --python=/path/to/python to specify a supported Python."
1441 fi
1442
1443 # Suppress writing compiled files
1444 python="$python -B"
1445
1446 # Now we have handled --enable-tcg-interpreter and know we're not just
1447 # printing the help message, bail out if the host CPU isn't supported.
1448 if test "$ARCH" = "unknown"; then
1449     if test "$tcg_interpreter" = "yes" ; then
1450         echo "Unsupported CPU = $cpu, will use TCG with TCI (experimental)"
1451     else
1452         error_exit "Unsupported CPU = $cpu, try --enable-tcg-interpreter"
1453     fi
1454 fi
1455
1456 # Consult white-list to determine whether to enable werror
1457 # by default.  Only enable by default for git builds
1458 if test -z "$werror" ; then
1459     if test -d "$source_path/.git" -a \
1460         \( "$linux" = "yes" -o "$mingw32" = "yes" \) ; then
1461         werror="yes"
1462     else
1463         werror="no"
1464     fi
1465 fi
1466
1467 # check that the C compiler works.
1468 write_c_skeleton;
1469 if compile_object ; then
1470   : C compiler works ok
1471 else
1472     error_exit "\"$cc\" either does not exist or does not work"
1473 fi
1474 if ! compile_prog ; then
1475     error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
1476 fi
1477
1478 if test "$bogus_os" = "yes"; then
1479     # Now that we know that we're not printing the help and that
1480     # the compiler works (so the results of the check_defines we used
1481     # to identify the OS are reliable), if we didn't recognize the
1482     # host OS we should stop now.
1483     error_exit "Unrecognized host OS $targetos"
1484 fi
1485
1486 # Check that the C++ compiler exists and works with the C compiler
1487 if has $cxx; then
1488     cat > $TMPC <<EOF
1489 int c_function(void);
1490 int main(void) { return c_function(); }
1491 EOF
1492
1493     compile_object
1494
1495     cat > $TMPCXX <<EOF
1496 extern "C" {
1497    int c_function(void);
1498 }
1499 int c_function(void) { return 42; }
1500 EOF
1501
1502     update_cxxflags
1503
1504     if do_cxx $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $LDFLAGS; then
1505         # C++ compiler $cxx works ok with C compiler $cc
1506         :
1507     else
1508         echo "C++ compiler $cxx does not work with C compiler $cc"
1509         echo "Disabling C++ specific optional code"
1510         cxx=
1511     fi
1512 else
1513     echo "No C++ compiler available; disabling C++ specific optional code"
1514     cxx=
1515 fi
1516
1517 gcc_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits"
1518 gcc_flags="-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers $gcc_flags"
1519 gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
1520 gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags"
1521 gcc_flags="-Wno-initializer-overrides $gcc_flags"
1522 gcc_flags="-Wno-string-plus-int $gcc_flags"
1523 # Note that we do not add -Werror to gcc_flags here, because that would
1524 # enable it for all configure tests. If a configure test failed due
1525 # to -Werror this would just silently disable some features,
1526 # so it's too error prone.
1527
1528 cc_has_warning_flag() {
1529     write_c_skeleton;
1530
1531     # Use the positive sense of the flag when testing for -Wno-wombat
1532     # support (gcc will happily accept the -Wno- form of unknown
1533     # warning options).
1534     optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
1535     compile_prog "-Werror $optflag" ""
1536 }
1537
1538 for flag in $gcc_flags; do
1539     if cc_has_warning_flag $flag ; then
1540         QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1541     fi
1542 done
1543
1544 if test "$stack_protector" != "no"; then
1545   cat > $TMPC << EOF
1546 int main(int argc, char *argv[])
1547 {
1548     char arr[64], *p = arr, *c = argv[0];
1549     while (*c) {
1550         *p++ = *c++;
1551     }
1552     return 0;
1553 }
1554 EOF
1555   gcc_flags="-fstack-protector-strong -fstack-protector-all"
1556   sp_on=0
1557   for flag in $gcc_flags; do
1558     # We need to check both a compile and a link, since some compiler
1559     # setups fail only on a .c->.o compile and some only at link time
1560     if do_cc $QEMU_CFLAGS -Werror $flag -c -o $TMPO $TMPC &&
1561        compile_prog "-Werror $flag" ""; then
1562       QEMU_CFLAGS="$QEMU_CFLAGS $flag"
1563       sp_on=1
1564       break
1565     fi
1566   done
1567   if test "$stack_protector" = yes; then
1568     if test $sp_on = 0; then
1569       error_exit "Stack protector not supported"
1570     fi
1571   fi
1572 fi
1573
1574 # Workaround for http://gcc.gnu.org/PR55489.  Happens with -fPIE/-fPIC and
1575 # large functions that use global variables.  The bug is in all releases of
1576 # GCC, but it became particularly acute in 4.6.x and 4.7.x.  It is fixed in
1577 # 4.7.3 and 4.8.0.  We should be able to delete this at the end of 2013.
1578 cat > $TMPC << EOF
1579 #if __GNUC__ == 4 && (__GNUC_MINOR__ == 6 || (__GNUC_MINOR__ == 7 && __GNUC_PATCHLEVEL__ <= 2))
1580 int main(void) { return 0; }
1581 #else
1582 #error No bug in this compiler.
1583 #endif
1584 EOF
1585 if compile_prog "-Werror -fno-gcse" "" ; then
1586   TRANSLATE_OPT_CFLAGS=-fno-gcse
1587 fi
1588
1589 if test "$static" = "yes" ; then
1590   if test "$modules" = "yes" ; then
1591     error_exit "static and modules are mutually incompatible"
1592   fi
1593   if test "$pie" = "yes" ; then
1594     error_exit "static and pie are mutually incompatible"
1595   else
1596     pie="no"
1597   fi
1598 fi
1599
1600 # Unconditional check for compiler __thread support
1601   cat > $TMPC << EOF
1602 static __thread int tls_var;
1603 int main(void) { return tls_var; }
1604 EOF
1605
1606 if ! compile_prog "-Werror" "" ; then
1607     error_exit "Your compiler does not support the __thread specifier for " \
1608         "Thread-Local Storage (TLS). Please upgrade to a version that does."
1609 fi
1610
1611 if test "$pie" = ""; then
1612   case "$cpu-$targetos" in
1613     i386-Linux|x86_64-Linux|x32-Linux|i386-OpenBSD|x86_64-OpenBSD)
1614       ;;
1615     *)
1616       pie="no"
1617       ;;
1618   esac
1619 fi
1620
1621 if test "$pie" != "no" ; then
1622   cat > $TMPC << EOF
1623
1624 #ifdef __linux__
1625 #  define THREAD __thread
1626 #else
1627 #  define THREAD
1628 #endif
1629
1630 static THREAD int tls_var;
1631
1632 int main(void) { return tls_var; }
1633
1634 EOF
1635   if compile_prog "-fPIE -DPIE" "-pie"; then
1636     QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS"
1637     LDFLAGS="-pie $LDFLAGS"
1638     pie="yes"
1639     if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
1640       LDFLAGS="-Wl,-z,relro -Wl,-z,now $LDFLAGS"
1641     fi
1642   else
1643     if test "$pie" = "yes"; then
1644       error_exit "PIE not available due to missing toolchain support"
1645     else
1646       echo "Disabling PIE due to missing toolchain support"
1647       pie="no"
1648     fi
1649   fi
1650
1651   if compile_prog "-Werror -fno-pie" "-nopie"; then
1652     CFLAGS_NOPIE="-fno-pie"
1653     LDFLAGS_NOPIE="-nopie"
1654   fi
1655 fi
1656
1657 ##########################################
1658 # __sync_fetch_and_and requires at least -march=i486. Many toolchains
1659 # use i686 as default anyway, but for those that don't, an explicit
1660 # specification is necessary
1661
1662 if test "$cpu" = "i386"; then
1663   cat > $TMPC << EOF
1664 static int sfaa(int *ptr)
1665 {
1666   return __sync_fetch_and_and(ptr, 0);
1667 }
1668
1669 int main(void)
1670 {
1671   int val = 42;
1672   val = __sync_val_compare_and_swap(&val, 0, 1);
1673   sfaa(&val);
1674   return val;
1675 }
1676 EOF
1677   if ! compile_prog "" "" ; then
1678     QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
1679   fi
1680 fi
1681
1682 #########################################
1683 # Solaris specific configure tool chain decisions
1684
1685 if test "$solaris" = "yes" ; then
1686   if has $install; then
1687     :
1688   else
1689     error_exit "Solaris install program not found. Use --install=/usr/ucb/install or" \
1690         "install fileutils from www.blastwave.org using pkg-get -i fileutils" \
1691         "to get ginstall which is used by default (which lives in /opt/csw/bin)"
1692   fi
1693   if test "$(path_of $install)" = "/usr/sbin/install" ; then
1694     error_exit "Solaris /usr/sbin/install is not an appropriate install program." \
1695         "try ginstall from the GNU fileutils available from www.blastwave.org" \
1696         "using pkg-get -i fileutils, or use --install=/usr/ucb/install"
1697   fi
1698   if has ar; then
1699     :
1700   else
1701     if test -f /usr/ccs/bin/ar ; then
1702       error_exit "No path includes ar" \
1703           "Add /usr/ccs/bin to your path and rerun configure"
1704     fi
1705     error_exit "No path includes ar"
1706   fi
1707 fi
1708
1709 if test -z "${target_list+xxx}" ; then
1710     target_list="$default_target_list"
1711 else
1712     target_list=$(echo "$target_list" | sed -e 's/,/ /g')
1713 fi
1714
1715 # Check that we recognised the target name; this allows a more
1716 # friendly error message than if we let it fall through.
1717 for target in $target_list; do
1718     case " $default_target_list " in
1719         *" $target "*)
1720             ;;
1721         *)
1722             error_exit "Unknown target name '$target'"
1723             ;;
1724     esac
1725 done
1726
1727 # see if system emulation was really requested
1728 case " $target_list " in
1729   *"-softmmu "*) softmmu=yes
1730   ;;
1731   *) softmmu=no
1732   ;;
1733 esac
1734
1735 feature_not_found() {
1736   feature=$1
1737   remedy=$2
1738
1739   error_exit "User requested feature $feature" \
1740       "configure was not able to find it." \
1741       "$remedy"
1742 }
1743
1744 # ---
1745 # big/little endian test
1746 cat > $TMPC << EOF
1747 short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
1748 short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
1749 extern int foo(short *, short *);
1750 int main(int argc, char *argv[]) {
1751     return foo(big_endian, little_endian);
1752 }
1753 EOF
1754
1755 if compile_object ; then
1756     if grep -q BiGeNdIaN $TMPO ; then
1757         bigendian="yes"
1758     elif grep -q LiTtLeEnDiAn $TMPO ; then
1759         bigendian="no"
1760     else
1761         echo big/little test failed
1762     fi
1763 else
1764     echo big/little test failed
1765 fi
1766
1767 ##########################################
1768 # cocoa implies not SDL or GTK
1769 # (the cocoa UI code currently assumes it is always the active UI
1770 # and doesn't interact well with other UI frontend code)
1771 if test "$cocoa" = "yes"; then
1772     if test "$sdl" = "yes"; then
1773         error_exit "Cocoa and SDL UIs cannot both be enabled at once"
1774     fi
1775     if test "$gtk" = "yes"; then
1776         error_exit "Cocoa and GTK UIs cannot both be enabled at once"
1777     fi
1778     gtk=no
1779     sdl=no
1780 fi
1781
1782 # Some versions of Mac OS X incorrectly define SIZE_MAX
1783 cat > $TMPC << EOF
1784 #include <stdint.h>
1785 #include <stdio.h>
1786 int main(int argc, char *argv[]) {
1787     return printf("%zu", SIZE_MAX);
1788 }
1789 EOF
1790 have_broken_size_max=no
1791 if ! compile_object -Werror ; then
1792     have_broken_size_max=yes
1793 fi
1794
1795 ##########################################
1796 # L2TPV3 probe
1797
1798 cat > $TMPC <<EOF
1799 #include <sys/socket.h>
1800 #include <linux/ip.h>
1801 int main(void) { return sizeof(struct mmsghdr); }
1802 EOF
1803 if compile_prog "" "" ; then
1804   l2tpv3=yes
1805 else
1806   l2tpv3=no
1807 fi
1808
1809 ##########################################
1810 # MinGW / Mingw-w64 localtime_r/gmtime_r check
1811
1812 if test "$mingw32" = "yes"; then
1813     # Some versions of MinGW / Mingw-w64 lack localtime_r
1814     # and gmtime_r entirely.
1815     #
1816     # Some versions of Mingw-w64 define a macro for
1817     # localtime_r/gmtime_r.
1818     #
1819     # Some versions of Mingw-w64 will define functions
1820     # for localtime_r/gmtime_r, but only if you have
1821     # _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun
1822     # though, unistd.h and pthread.h both define
1823     # that for you.
1824     #
1825     # So this #undef localtime_r and #include <unistd.h>
1826     # are not in fact redundant.
1827 cat > $TMPC << EOF
1828 #include <unistd.h>
1829 #include <time.h>
1830 #undef localtime_r
1831 int main(void) { localtime_r(NULL, NULL); return 0; }
1832 EOF
1833     if compile_prog "" "" ; then
1834         localtime_r="yes"
1835     else
1836         localtime_r="no"
1837     fi
1838 fi
1839
1840 ##########################################
1841 # pkg-config probe
1842
1843 if ! has "$pkg_config_exe"; then
1844   error_exit "pkg-config binary '$pkg_config_exe' not found"
1845 fi
1846
1847 ##########################################
1848 # NPTL probe
1849
1850 if test "$linux_user" = "yes"; then
1851   cat > $TMPC <<EOF
1852 #include <sched.h>
1853 #include <linux/futex.h>
1854 int main(void) {
1855 #if !defined(CLONE_SETTLS) || !defined(FUTEX_WAIT)
1856 #error bork
1857 #endif
1858   return 0;
1859 }
1860 EOF
1861   if ! compile_object ; then
1862     feature_not_found "nptl" "Install glibc and linux kernel headers."
1863   fi
1864 fi
1865
1866 ##########################################
1867 # avx2 optimization requirement check
1868
1869 cat > $TMPC << EOF
1870 #pragma GCC push_options
1871 #pragma GCC target("avx2")
1872 #include <cpuid.h>
1873 #include <immintrin.h>
1874 static int bar(void *a) {
1875     __m256i x = *(__m256i *)a;
1876     return _mm256_testz_si256(x, x);
1877 }
1878 int main(int argc, char *argv[]) { return bar(argv[0]); }
1879 EOF
1880 if compile_object "" ; then
1881   avx2_opt="yes"
1882 fi
1883
1884 #########################################
1885 # zlib check
1886
1887 if test "$zlib" != "no" ; then
1888     cat > $TMPC << EOF
1889 #include <zlib.h>
1890 int main(void) { zlibVersion(); return 0; }
1891 EOF
1892     if compile_prog "" "-lz" ; then
1893         :
1894     else
1895         error_exit "zlib check failed" \
1896             "Make sure to have the zlib libs and headers installed."
1897     fi
1898 fi
1899 LIBS="$LIBS -lz"
1900
1901 ##########################################
1902 # lzo check
1903
1904 if test "$lzo" != "no" ; then
1905     cat > $TMPC << EOF
1906 #include <lzo/lzo1x.h>
1907 int main(void) { lzo_version(); return 0; }
1908 EOF
1909     if compile_prog "" "-llzo2" ; then
1910         libs_softmmu="$libs_softmmu -llzo2"
1911         lzo="yes"
1912     else
1913         if test "$lzo" = "yes"; then
1914             feature_not_found "liblzo2" "Install liblzo2 devel"
1915         fi
1916         lzo="no"
1917     fi
1918 fi
1919
1920 ##########################################
1921 # snappy check
1922
1923 if test "$snappy" != "no" ; then
1924     cat > $TMPC << EOF
1925 #include <snappy-c.h>
1926 int main(void) { snappy_max_compressed_length(4096); return 0; }
1927 EOF
1928     if compile_prog "" "-lsnappy" ; then
1929         libs_softmmu="$libs_softmmu -lsnappy"
1930         snappy="yes"
1931     else
1932         if test "$snappy" = "yes"; then
1933             feature_not_found "libsnappy" "Install libsnappy devel"
1934         fi
1935         snappy="no"
1936     fi
1937 fi
1938
1939 ##########################################
1940 # bzip2 check
1941
1942 if test "$bzip2" != "no" ; then
1943     cat > $TMPC << EOF
1944 #include <bzlib.h>
1945 int main(void) { BZ2_bzlibVersion(); return 0; }
1946 EOF
1947     if compile_prog "" "-lbz2" ; then
1948         bzip2="yes"
1949     else
1950         if test "$bzip2" = "yes"; then
1951             feature_not_found "libbzip2" "Install libbzip2 devel"
1952         fi
1953         bzip2="no"
1954     fi
1955 fi
1956
1957 ##########################################
1958 # libseccomp check
1959
1960 if test "$seccomp" != "no" ; then
1961     case "$cpu" in
1962     i386|x86_64)
1963         libseccomp_minver="2.1.0"
1964         ;;
1965     mips)
1966         libseccomp_minver="2.2.0"
1967         ;;
1968     arm|aarch64)
1969         libseccomp_minver="2.2.3"
1970         ;;
1971     ppc|ppc64)
1972         libseccomp_minver="2.3.0"
1973         ;;
1974     *)
1975         libseccomp_minver=""
1976         ;;
1977     esac
1978
1979     if test "$libseccomp_minver" != "" &&
1980        $pkg_config --atleast-version=$libseccomp_minver libseccomp ; then
1981         libs_softmmu="$libs_softmmu $($pkg_config --libs libseccomp)"
1982         QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags libseccomp)"
1983         seccomp="yes"
1984     else
1985         if test "$seccomp" = "yes" ; then
1986             if test "$libseccomp_minver" != "" ; then
1987                 feature_not_found "libseccomp" \
1988                     "Install libseccomp devel >= $libseccomp_minver"
1989             else
1990                 feature_not_found "libseccomp" \
1991                     "libseccomp is not supported for host cpu $cpu"
1992             fi
1993         fi
1994         seccomp="no"
1995     fi
1996 fi
1997 ##########################################
1998 # xen probe
1999
2000 if test "$xen" != "no" ; then
2001   # Check whether Xen library path is specified via --extra-ldflags to avoid
2002   # overriding this setting with pkg-config output. If not, try pkg-config
2003   # to obtain all needed flags.
2004
2005   if ! echo $EXTRA_LDFLAGS | grep tools/libxc > /dev/null && \
2006      $pkg_config --exists xencontrol ; then
2007     xen_ctrl_version="$(printf '%d%02d%02d' \
2008       $($pkg_config --modversion xencontrol | sed 's/\./ /g') )"
2009     xen=yes
2010     xen_pc="xencontrol xenstore xenguest xenforeignmemory xengnttab"
2011     xen_pc="$xen_pc xenevtchn xendevicemodel"
2012     QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags $xen_pc)"
2013     libs_softmmu="$($pkg_config --libs $xen_pc) $libs_softmmu"
2014     LDFLAGS="$($pkg_config --libs $xen_pc) $LDFLAGS"
2015   else
2016
2017     xen_libs="-lxenstore -lxenctrl -lxenguest"
2018     xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
2019
2020     # First we test whether Xen headers and libraries are available.
2021     # If no, we are done and there is no Xen support.
2022     # If yes, more tests are run to detect the Xen version.
2023
2024     # Xen (any)
2025     cat > $TMPC <<EOF
2026 #include <xenctrl.h>
2027 int main(void) {
2028   return 0;
2029 }
2030 EOF
2031     if ! compile_prog "" "$xen_libs" ; then
2032       # Xen not found
2033       if test "$xen" = "yes" ; then
2034         feature_not_found "xen" "Install xen devel"
2035       fi
2036       xen=no
2037
2038     # Xen unstable
2039     elif
2040         cat > $TMPC <<EOF &&
2041 #undef XC_WANT_COMPAT_DEVICEMODEL_API
2042 #define __XEN_TOOLS__
2043 #include <xendevicemodel.h>
2044 int main(void) {
2045   xendevicemodel_handle *xd;
2046
2047   xd = xendevicemodel_open(0, 0);
2048   xendevicemodel_close(xd);
2049
2050   return 0;
2051 }
2052 EOF
2053         compile_prog "" "$xen_libs -lxendevicemodel $xen_stable_libs"
2054       then
2055       xen_stable_libs="-lxendevicemodel $xen_stable_libs"
2056       xen_ctrl_version=40900
2057       xen=yes
2058     elif
2059         cat > $TMPC <<EOF &&
2060 /*
2061  * If we have stable libs the we don't want the libxc compat
2062  * layers, regardless of what CFLAGS we may have been given.
2063  *
2064  * Also, check if xengnttab_grant_copy_segment_t is defined and
2065  * grant copy operation is implemented.
2066  */
2067 #undef XC_WANT_COMPAT_EVTCHN_API
2068 #undef XC_WANT_COMPAT_GNTTAB_API
2069 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
2070 #include <xenctrl.h>
2071 #include <xenstore.h>
2072 #include <xenevtchn.h>
2073 #include <xengnttab.h>
2074 #include <xenforeignmemory.h>
2075 #include <stdint.h>
2076 #include <xen/hvm/hvm_info_table.h>
2077 #if !defined(HVM_MAX_VCPUS)
2078 # error HVM_MAX_VCPUS not defined
2079 #endif
2080 int main(void) {
2081   xc_interface *xc = NULL;
2082   xenforeignmemory_handle *xfmem;
2083   xenevtchn_handle *xe;
2084   xengnttab_handle *xg;
2085   xen_domain_handle_t handle;
2086   xengnttab_grant_copy_segment_t* seg = NULL;
2087
2088   xs_daemon_open();
2089
2090   xc = xc_interface_open(0, 0, 0);
2091   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2092   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2093   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2094   xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2095   xc_domain_create(xc, 0, handle, 0, NULL, NULL);
2096
2097   xfmem = xenforeignmemory_open(0, 0);
2098   xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2099
2100   xe = xenevtchn_open(0, 0);
2101   xenevtchn_fd(xe);
2102
2103   xg = xengnttab_open(0, 0);
2104   xengnttab_grant_copy(xg, 0, seg);
2105
2106   return 0;
2107 }
2108 EOF
2109         compile_prog "" "$xen_libs $xen_stable_libs"
2110       then
2111       xen_ctrl_version=40800
2112       xen=yes
2113     elif
2114         cat > $TMPC <<EOF &&
2115 /*
2116  * If we have stable libs the we don't want the libxc compat
2117  * layers, regardless of what CFLAGS we may have been given.
2118  */
2119 #undef XC_WANT_COMPAT_EVTCHN_API
2120 #undef XC_WANT_COMPAT_GNTTAB_API
2121 #undef XC_WANT_COMPAT_MAP_FOREIGN_API
2122 #include <xenctrl.h>
2123 #include <xenstore.h>
2124 #include <xenevtchn.h>
2125 #include <xengnttab.h>
2126 #include <xenforeignmemory.h>
2127 #include <stdint.h>
2128 #include <xen/hvm/hvm_info_table.h>
2129 #if !defined(HVM_MAX_VCPUS)
2130 # error HVM_MAX_VCPUS not defined
2131 #endif
2132 int main(void) {
2133   xc_interface *xc = NULL;
2134   xenforeignmemory_handle *xfmem;
2135   xenevtchn_handle *xe;
2136   xengnttab_handle *xg;
2137   xen_domain_handle_t handle;
2138
2139   xs_daemon_open();
2140
2141   xc = xc_interface_open(0, 0, 0);
2142   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2143   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2144   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2145   xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2146   xc_domain_create(xc, 0, handle, 0, NULL, NULL);
2147
2148   xfmem = xenforeignmemory_open(0, 0);
2149   xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
2150
2151   xe = xenevtchn_open(0, 0);
2152   xenevtchn_fd(xe);
2153
2154   xg = xengnttab_open(0, 0);
2155   xengnttab_map_grant_ref(xg, 0, 0, 0);
2156
2157   return 0;
2158 }
2159 EOF
2160         compile_prog "" "$xen_libs $xen_stable_libs"
2161       then
2162       xen_ctrl_version=40701
2163       xen=yes
2164     elif
2165         cat > $TMPC <<EOF &&
2166 #include <xenctrl.h>
2167 #include <stdint.h>
2168 int main(void) {
2169   xc_interface *xc = NULL;
2170   xen_domain_handle_t handle;
2171   xc_domain_create(xc, 0, handle, 0, NULL, NULL);
2172   return 0;
2173 }
2174 EOF
2175         compile_prog "" "$xen_libs"
2176       then
2177       xen_ctrl_version=40700
2178       xen=yes
2179
2180     # Xen 4.6
2181     elif
2182         cat > $TMPC <<EOF &&
2183 #include <xenctrl.h>
2184 #include <xenstore.h>
2185 #include <stdint.h>
2186 #include <xen/hvm/hvm_info_table.h>
2187 #if !defined(HVM_MAX_VCPUS)
2188 # error HVM_MAX_VCPUS not defined
2189 #endif
2190 int main(void) {
2191   xc_interface *xc;
2192   xs_daemon_open();
2193   xc = xc_interface_open(0, 0, 0);
2194   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2195   xc_gnttab_open(NULL, 0);
2196   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2197   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2198   xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
2199   xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
2200   return 0;
2201 }
2202 EOF
2203         compile_prog "" "$xen_libs"
2204       then
2205       xen_ctrl_version=40600
2206       xen=yes
2207
2208     # Xen 4.5
2209     elif
2210         cat > $TMPC <<EOF &&
2211 #include <xenctrl.h>
2212 #include <xenstore.h>
2213 #include <stdint.h>
2214 #include <xen/hvm/hvm_info_table.h>
2215 #if !defined(HVM_MAX_VCPUS)
2216 # error HVM_MAX_VCPUS not defined
2217 #endif
2218 int main(void) {
2219   xc_interface *xc;
2220   xs_daemon_open();
2221   xc = xc_interface_open(0, 0, 0);
2222   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2223   xc_gnttab_open(NULL, 0);
2224   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2225   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2226   xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
2227   return 0;
2228 }
2229 EOF
2230         compile_prog "" "$xen_libs"
2231       then
2232       xen_ctrl_version=40500
2233       xen=yes
2234
2235     elif
2236         cat > $TMPC <<EOF &&
2237 #include <xenctrl.h>
2238 #include <xenstore.h>
2239 #include <stdint.h>
2240 #include <xen/hvm/hvm_info_table.h>
2241 #if !defined(HVM_MAX_VCPUS)
2242 # error HVM_MAX_VCPUS not defined
2243 #endif
2244 int main(void) {
2245   xc_interface *xc;
2246   xs_daemon_open();
2247   xc = xc_interface_open(0, 0, 0);
2248   xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
2249   xc_gnttab_open(NULL, 0);
2250   xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
2251   xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
2252   return 0;
2253 }
2254 EOF
2255         compile_prog "" "$xen_libs"
2256       then
2257       xen_ctrl_version=40200
2258       xen=yes
2259
2260     else
2261       if test "$xen" = "yes" ; then
2262         feature_not_found "xen (unsupported version)" \
2263                           "Install a supported xen (xen 4.2 or newer)"
2264       fi
2265       xen=no
2266     fi
2267
2268     if test "$xen" = yes; then
2269       if test $xen_ctrl_version -ge 40701  ; then
2270         libs_softmmu="$xen_stable_libs $libs_softmmu"
2271       fi
2272       libs_softmmu="$xen_libs $libs_softmmu"
2273     fi
2274   fi
2275 fi
2276
2277 if test "$xen_pci_passthrough" != "no"; then
2278   if test "$xen" = "yes" && test "$linux" = "yes"; then
2279     xen_pci_passthrough=yes
2280   else
2281     if test "$xen_pci_passthrough" = "yes"; then
2282       error_exit "User requested feature Xen PCI Passthrough" \
2283           " but this feature requires /sys from Linux"
2284     fi
2285     xen_pci_passthrough=no
2286   fi
2287 fi
2288
2289 if test "$xen_pv_domain_build" = "yes" &&
2290    test "$xen" != "yes"; then
2291     error_exit "User requested Xen PV domain builder support" \
2292                "which requires Xen support."
2293 fi
2294
2295 ##########################################
2296 # Sparse probe
2297 if test "$sparse" != "no" ; then
2298   if has cgcc; then
2299     sparse=yes
2300   else
2301     if test "$sparse" = "yes" ; then
2302       feature_not_found "sparse" "Install sparse binary"
2303     fi
2304     sparse=no
2305   fi
2306 fi
2307
2308 ##########################################
2309 # X11 probe
2310 x11_cflags=
2311 x11_libs=-lX11
2312 if $pkg_config --exists "x11"; then
2313     x11_cflags=$($pkg_config --cflags x11)
2314     x11_libs=$($pkg_config --libs x11)
2315 fi
2316
2317 ##########################################
2318 # GTK probe
2319
2320 if test "$gtkabi" = ""; then
2321     # The GTK ABI was not specified explicitly, so try whether 2.0 is available.
2322     # Use 3.0 as a fallback if that is available.
2323     if $pkg_config --exists "gtk+-2.0 >= 2.18.0"; then
2324         gtkabi=2.0
2325     elif $pkg_config --exists "gtk+-3.0 >= 3.0.0"; then
2326         gtkabi=3.0
2327     else
2328         gtkabi=2.0
2329     fi
2330 fi
2331
2332 if test "$gtk" != "no"; then
2333     gtkpackage="gtk+-$gtkabi"
2334     gtkx11package="gtk+-x11-$gtkabi"
2335     if test "$gtkabi" = "3.0" ; then
2336       gtkversion="3.0.0"
2337     else
2338       gtkversion="2.18.0"
2339     fi
2340     if $pkg_config --exists "$gtkpackage >= $gtkversion"; then
2341         gtk_cflags=$($pkg_config --cflags $gtkpackage)
2342         gtk_libs=$($pkg_config --libs $gtkpackage)
2343         gtk_version=$($pkg_config --modversion $gtkpackage)
2344         if $pkg_config --exists "$gtkx11package >= $gtkversion"; then
2345             gtk_cflags="$gtk_cflags $x11_cflags"
2346             gtk_libs="$gtk_libs $x11_libs"
2347         fi
2348         libs_softmmu="$gtk_libs $libs_softmmu"
2349         gtk="yes"
2350     elif test "$gtk" = "yes"; then
2351         feature_not_found "gtk" "Install gtk2 or gtk3 devel"
2352     else
2353         gtk="no"
2354     fi
2355 fi
2356
2357
2358 ##########################################
2359 # GNUTLS probe
2360
2361 gnutls_works() {
2362     # Unfortunately some distros have bad pkg-config information for gnutls
2363     # such that it claims to exist but you get a compiler error if you try
2364     # to use the options returned by --libs. Specifically, Ubuntu for --static
2365     # builds doesn't work:
2366     # https://bugs.launchpad.net/ubuntu/+source/gnutls26/+bug/1478035
2367     #
2368     # So sanity check the cflags/libs before assuming gnutls can be used.
2369     if ! $pkg_config --exists "gnutls"; then
2370         return 1
2371     fi
2372
2373     write_c_skeleton
2374     compile_prog "$($pkg_config --cflags gnutls)" "$($pkg_config --libs gnutls)"
2375 }
2376
2377 gnutls_gcrypt=no
2378 gnutls_nettle=no
2379 if test "$gnutls" != "no"; then
2380     if gnutls_works; then
2381         gnutls_cflags=$($pkg_config --cflags gnutls)
2382         gnutls_libs=$($pkg_config --libs gnutls)
2383         libs_softmmu="$gnutls_libs $libs_softmmu"
2384         libs_tools="$gnutls_libs $libs_tools"
2385         QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags"
2386         gnutls="yes"
2387
2388         # gnutls_rnd requires >= 2.11.0
2389         if $pkg_config --exists "gnutls >= 2.11.0"; then
2390             gnutls_rnd="yes"
2391         else
2392             gnutls_rnd="no"
2393         fi
2394
2395         if $pkg_config --exists 'gnutls >= 3.0'; then
2396             gnutls_gcrypt=no
2397             gnutls_nettle=yes
2398         elif $pkg_config --exists 'gnutls >= 2.12'; then
2399             case $($pkg_config --libs --static gnutls) in
2400                 *gcrypt*)
2401                     gnutls_gcrypt=yes
2402                     gnutls_nettle=no
2403                     ;;
2404                 *nettle*)
2405                     gnutls_gcrypt=no
2406                     gnutls_nettle=yes
2407                     ;;
2408                 *)
2409                     gnutls_gcrypt=yes
2410                     gnutls_nettle=no
2411                     ;;
2412             esac
2413         else
2414             gnutls_gcrypt=yes
2415             gnutls_nettle=no
2416         fi
2417     elif test "$gnutls" = "yes"; then
2418         feature_not_found "gnutls" "Install gnutls devel"
2419     else
2420         gnutls="no"
2421         gnutls_rnd="no"
2422     fi
2423 else
2424     gnutls_rnd="no"
2425 fi
2426
2427
2428 # If user didn't give a --disable/enable-gcrypt flag,
2429 # then mark as disabled if user requested nettle
2430 # explicitly, or if gnutls links to nettle
2431 if test -z "$gcrypt"
2432 then
2433     if test "$nettle" = "yes" || test "$gnutls_nettle" = "yes"
2434     then
2435         gcrypt="no"
2436     fi
2437 fi
2438
2439 # If user didn't give a --disable/enable-nettle flag,
2440 # then mark as disabled if user requested gcrypt
2441 # explicitly, or if gnutls links to gcrypt
2442 if test -z "$nettle"
2443 then
2444     if test "$gcrypt" = "yes" || test "$gnutls_gcrypt" = "yes"
2445     then
2446         nettle="no"
2447     fi
2448 fi
2449
2450 has_libgcrypt_config() {
2451     if ! has "libgcrypt-config"
2452     then
2453         return 1
2454     fi
2455
2456     if test -n "$cross_prefix"
2457     then
2458         host=$(libgcrypt-config --host)
2459         if test "$host-" != $cross_prefix
2460         then
2461             return 1
2462         fi
2463     fi
2464
2465     return 0
2466 }
2467
2468 if test "$gcrypt" != "no"; then
2469     if has_libgcrypt_config; then
2470         gcrypt_cflags=$(libgcrypt-config --cflags)
2471         gcrypt_libs=$(libgcrypt-config --libs)
2472         # Debian has remove -lgpg-error from libgcrypt-config
2473         # as it "spreads unnecessary dependencies" which in
2474         # turn breaks static builds...
2475         if test "$static" = "yes"
2476         then
2477             gcrypt_libs="$gcrypt_libs -lgpg-error"
2478         fi
2479         libs_softmmu="$gcrypt_libs $libs_softmmu"
2480         libs_tools="$gcrypt_libs $libs_tools"
2481         QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags"
2482         gcrypt="yes"
2483         if test -z "$nettle"; then
2484            nettle="no"
2485         fi
2486
2487         cat > $TMPC << EOF
2488 #include <gcrypt.h>
2489 int main(void) {
2490   gcry_kdf_derive(NULL, 0, GCRY_KDF_PBKDF2,
2491                   GCRY_MD_SHA256,
2492                   NULL, 0, 0, 0, NULL);
2493  return 0;
2494 }
2495 EOF
2496         if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then
2497             gcrypt_kdf=yes
2498         fi
2499
2500         cat > $TMPC << EOF
2501 #include <gcrypt.h>
2502 int main(void) {
2503   gcry_mac_hd_t handle;
2504   gcry_mac_open(&handle, GCRY_MAC_HMAC_MD5,
2505                 GCRY_MAC_FLAG_SECURE, NULL);
2506   return 0;
2507 }
2508 EOF
2509         if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then
2510             gcrypt_hmac=yes
2511         fi
2512     else
2513         if test "$gcrypt" = "yes"; then
2514             feature_not_found "gcrypt" "Install gcrypt devel"
2515         else
2516             gcrypt="no"
2517         fi
2518     fi
2519 fi
2520
2521
2522 if test "$nettle" != "no"; then
2523     if $pkg_config --exists "nettle"; then
2524         nettle_cflags=$($pkg_config --cflags nettle)
2525         nettle_libs=$($pkg_config --libs nettle)
2526         nettle_version=$($pkg_config --modversion nettle)
2527         libs_softmmu="$nettle_libs $libs_softmmu"
2528         libs_tools="$nettle_libs $libs_tools"
2529         QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags"
2530         nettle="yes"
2531
2532         cat > $TMPC << EOF
2533 #include <stddef.h>
2534 #include <nettle/pbkdf2.h>
2535 int main(void) {
2536      pbkdf2_hmac_sha256(8, NULL, 1000, 8, NULL, 8, NULL);
2537      return 0;
2538 }
2539 EOF
2540         if compile_prog "$nettle_cflags" "$nettle_libs" ; then
2541             nettle_kdf=yes
2542         fi
2543     else
2544         if test "$nettle" = "yes"; then
2545             feature_not_found "nettle" "Install nettle devel"
2546         else
2547             nettle="no"
2548         fi
2549     fi
2550 fi
2551
2552 if test "$gcrypt" = "yes" && test "$nettle" = "yes"
2553 then
2554     error_exit "Only one of gcrypt & nettle can be enabled"
2555 fi
2556
2557 ##########################################
2558 # libtasn1 - only for the TLS creds/session test suite
2559
2560 tasn1=yes
2561 tasn1_cflags=""
2562 tasn1_libs=""
2563 if $pkg_config --exists "libtasn1"; then
2564     tasn1_cflags=$($pkg_config --cflags libtasn1)
2565     tasn1_libs=$($pkg_config --libs libtasn1)
2566 else
2567     tasn1=no
2568 fi
2569
2570
2571 ##########################################
2572 # getifaddrs (for tests/test-io-channel-socket )
2573
2574 have_ifaddrs_h=yes
2575 if ! check_include "ifaddrs.h" ; then
2576   have_ifaddrs_h=no
2577 fi
2578
2579 ##########################################
2580 # VTE probe
2581
2582 if test "$vte" != "no"; then
2583     if test "$gtkabi" = "3.0"; then
2584       vteminversion="0.32.0"
2585       if $pkg_config --exists "vte-2.91"; then
2586         vtepackage="vte-2.91"
2587       else
2588         vtepackage="vte-2.90"
2589       fi
2590     else
2591       vtepackage="vte"
2592       vteminversion="0.24.0"
2593     fi
2594     if $pkg_config --exists "$vtepackage >= $vteminversion"; then
2595         vte_cflags=$($pkg_config --cflags $vtepackage)
2596         vte_libs=$($pkg_config --libs $vtepackage)
2597         vteversion=$($pkg_config --modversion $vtepackage)
2598         libs_softmmu="$vte_libs $libs_softmmu"
2599         vte="yes"
2600     elif test "$vte" = "yes"; then
2601         if test "$gtkabi" = "3.0"; then
2602             feature_not_found "vte" "Install libvte-2.90/2.91 devel"
2603         else
2604             feature_not_found "vte" "Install libvte devel"
2605         fi
2606     else
2607         vte="no"
2608     fi
2609 fi
2610
2611 ##########################################
2612 # SDL probe
2613
2614 # Look for sdl configuration program (pkg-config or sdl-config).  Try
2615 # sdl-config even without cross prefix, and favour pkg-config over sdl-config.
2616
2617 if test "$sdlabi" = ""; then
2618     if $pkg_config --exists "sdl"; then
2619         sdlabi=1.2
2620     elif $pkg_config --exists "sdl2"; then
2621         sdlabi=2.0
2622     else
2623         sdlabi=1.2
2624     fi
2625 fi
2626
2627 if test $sdlabi = "2.0"; then
2628     sdl_config=$sdl2_config
2629     sdlname=sdl2
2630     sdlconfigname=sdl2_config
2631 elif test $sdlabi = "1.2"; then
2632     sdlname=sdl
2633     sdlconfigname=sdl_config
2634 else
2635     error_exit "Unknown sdlabi $sdlabi, must be 1.2 or 2.0"
2636 fi
2637
2638 if test "$(basename $sdl_config)" != $sdlconfigname && ! has ${sdl_config}; then
2639   sdl_config=$sdlconfigname
2640 fi
2641
2642 if $pkg_config $sdlname --exists; then
2643   sdlconfig="$pkg_config $sdlname"
2644   sdlversion=$($sdlconfig --modversion 2>/dev/null)
2645 elif has ${sdl_config}; then
2646   sdlconfig="$sdl_config"
2647   sdlversion=$($sdlconfig --version)
2648 else
2649   if test "$sdl" = "yes" ; then
2650     feature_not_found "sdl" "Install SDL devel"
2651   fi
2652   sdl=no
2653 fi
2654 if test -n "$cross_prefix" && test "$(basename "$sdlconfig")" = sdl-config; then
2655   echo warning: using "\"$sdlconfig\"" to detect cross-compiled sdl >&2
2656 fi
2657
2658 sdl_too_old=no
2659 if test "$sdl" != "no" ; then
2660   cat > $TMPC << EOF
2661 #include <SDL.h>
2662 #undef main /* We don't want SDL to override our main() */
2663 int main( void ) { return SDL_Init (SDL_INIT_VIDEO); }
2664 EOF
2665   sdl_cflags=$($sdlconfig --cflags 2>/dev/null)
2666   if test "$static" = "yes" ; then
2667     sdl_libs=$($sdlconfig --static-libs 2>/dev/null)
2668   else
2669     sdl_libs=$($sdlconfig --libs 2>/dev/null)
2670   fi
2671   if compile_prog "$sdl_cflags" "$sdl_libs" ; then
2672     if test $(echo $sdlversion | sed 's/[^0-9]//g') -lt 121 ; then
2673       sdl_too_old=yes
2674     else
2675       sdl=yes
2676     fi
2677
2678     # static link with sdl ? (note: sdl.pc's --static --libs is broken)
2679     if test "$sdl" = "yes" -a "$static" = "yes" ; then
2680       if test $? = 0 && echo $sdl_libs | grep -- -laa > /dev/null; then
2681          sdl_libs="$sdl_libs $(aalib-config --static-libs 2>/dev/null)"
2682          sdl_cflags="$sdl_cflags $(aalib-config --cflags 2>/dev/null)"
2683       fi
2684       if compile_prog "$sdl_cflags" "$sdl_libs" ; then
2685         :
2686       else
2687         sdl=no
2688       fi
2689     fi # static link
2690   else # sdl not found
2691     if test "$sdl" = "yes" ; then
2692       feature_not_found "sdl" "Install SDL devel"
2693     fi
2694     sdl=no
2695   fi # sdl compile test
2696 fi
2697
2698 if test "$sdl" = "yes" ; then
2699   cat > $TMPC <<EOF
2700 #include <SDL.h>
2701 #if defined(SDL_VIDEO_DRIVER_X11)
2702 #include <X11/XKBlib.h>
2703 #else
2704 #error No x11 support
2705 #endif
2706 int main(void) { return 0; }
2707 EOF
2708   if compile_prog "$sdl_cflags $x11_cflags" "$sdl_libs $x11_libs" ; then
2709     sdl_cflags="$sdl_cflags $x11_cflags"
2710     sdl_libs="$sdl_libs $x11_libs"
2711   fi
2712   libs_softmmu="$sdl_libs $libs_softmmu"
2713 fi
2714
2715 ##########################################
2716 # RDMA needs OpenFabrics libraries
2717 if test "$rdma" != "no" ; then
2718   cat > $TMPC <<EOF
2719 #include <rdma/rdma_cma.h>
2720 int main(void) { return 0; }
2721 EOF
2722   rdma_libs="-lrdmacm -libverbs"
2723   if compile_prog "" "$rdma_libs" ; then
2724     rdma="yes"
2725     libs_softmmu="$libs_softmmu $rdma_libs"
2726   else
2727     if test "$rdma" = "yes" ; then
2728         error_exit \
2729             " OpenFabrics librdmacm/libibverbs not present." \
2730             " Your options:" \
2731             "  (1) Fast: Install infiniband packages from your distro." \
2732             "  (2) Cleanest: Install libraries from www.openfabrics.org" \
2733             "  (3) Also: Install softiwarp if you don't have RDMA hardware"
2734     fi
2735     rdma="no"
2736   fi
2737 fi
2738
2739
2740 ##########################################
2741 # VNC SASL detection
2742 if test "$vnc" = "yes" -a "$vnc_sasl" != "no" ; then
2743   cat > $TMPC <<EOF
2744 #include <sasl/sasl.h>
2745 #include <stdio.h>
2746 int main(void) { sasl_server_init(NULL, "qemu"); return 0; }
2747 EOF
2748   # Assuming Cyrus-SASL installed in /usr prefix
2749   vnc_sasl_cflags=""
2750   vnc_sasl_libs="-lsasl2"
2751   if compile_prog "$vnc_sasl_cflags" "$vnc_sasl_libs" ; then
2752     vnc_sasl=yes
2753     libs_softmmu="$vnc_sasl_libs $libs_softmmu"
2754     QEMU_CFLAGS="$QEMU_CFLAGS $vnc_sasl_cflags"
2755   else
2756     if test "$vnc_sasl" = "yes" ; then
2757       feature_not_found "vnc-sasl" "Install Cyrus SASL devel"
2758     fi
2759     vnc_sasl=no
2760   fi
2761 fi
2762
2763 ##########################################
2764 # VNC JPEG detection
2765 if test "$vnc" = "yes" -a "$vnc_jpeg" != "no" ; then
2766 cat > $TMPC <<EOF
2767 #include <stdio.h>
2768 #include <jpeglib.h>
2769 int main(void) { struct jpeg_compress_struct s; jpeg_create_compress(&s); return 0; }
2770 EOF
2771     vnc_jpeg_cflags=""
2772     vnc_jpeg_libs="-ljpeg"
2773   if compile_prog "$vnc_jpeg_cflags" "$vnc_jpeg_libs" ; then
2774     vnc_jpeg=yes
2775     libs_softmmu="$vnc_jpeg_libs $libs_softmmu"
2776     QEMU_CFLAGS="$QEMU_CFLAGS $vnc_jpeg_cflags"
2777   else
2778     if test "$vnc_jpeg" = "yes" ; then
2779       feature_not_found "vnc-jpeg" "Install libjpeg-turbo devel"
2780     fi
2781     vnc_jpeg=no
2782   fi
2783 fi
2784
2785 ##########################################
2786 # VNC PNG detection
2787 if test "$vnc" = "yes" -a "$vnc_png" != "no" ; then
2788 cat > $TMPC <<EOF
2789 //#include <stdio.h>
2790 #include <png.h>
2791 #include <stddef.h>
2792 int main(void) {
2793     png_structp png_ptr;
2794     png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
2795     return png_ptr != 0;
2796 }
2797 EOF
2798   if $pkg_config libpng --exists; then
2799     vnc_png_cflags=$($pkg_config libpng --cflags)
2800     vnc_png_libs=$($pkg_config libpng --libs)
2801   else
2802     vnc_png_cflags=""
2803     vnc_png_libs="-lpng"
2804   fi
2805   if compile_prog "$vnc_png_cflags" "$vnc_png_libs" ; then
2806     vnc_png=yes
2807     libs_softmmu="$vnc_png_libs $libs_softmmu"
2808     QEMU_CFLAGS="$QEMU_CFLAGS $vnc_png_cflags"
2809   else
2810     if test "$vnc_png" = "yes" ; then
2811       feature_not_found "vnc-png" "Install libpng devel"
2812     fi
2813     vnc_png=no
2814   fi
2815 fi
2816
2817 ##########################################
2818 # fnmatch() probe, used for ACL routines
2819 fnmatch="no"
2820 cat > $TMPC << EOF
2821 #include <fnmatch.h>
2822 int main(void)
2823 {
2824     fnmatch("foo", "foo", 0);
2825     return 0;
2826 }
2827 EOF
2828 if compile_prog "" "" ; then
2829    fnmatch="yes"
2830 fi
2831
2832 ##########################################
2833 # xfsctl() probe, used for file-posix.c
2834 if test "$xfs" != "no" ; then
2835   cat > $TMPC << EOF
2836 #include <stddef.h>  /* NULL */
2837 #include <xfs/xfs.h>
2838 int main(void)
2839 {
2840     xfsctl(NULL, 0, 0, NULL);
2841     return 0;
2842 }
2843 EOF
2844   if compile_prog "" "" ; then
2845     xfs="yes"
2846   else
2847     if test "$xfs" = "yes" ; then
2848       feature_not_found "xfs" "Instal xfsprogs/xfslibs devel"
2849     fi
2850     xfs=no
2851   fi
2852 fi
2853
2854 ##########################################
2855 # vde libraries probe
2856 if test "$vde" != "no" ; then
2857   vde_libs="-lvdeplug"
2858   cat > $TMPC << EOF
2859 #include <libvdeplug.h>
2860 int main(void)
2861 {
2862     struct vde_open_args a = {0, 0, 0};
2863     char s[] = "";
2864     vde_open(s, s, &a);
2865     return 0;
2866 }
2867 EOF
2868   if compile_prog "" "$vde_libs" ; then
2869     vde=yes
2870     libs_softmmu="$vde_libs $libs_softmmu"
2871     libs_tools="$vde_libs $libs_tools"
2872   else
2873     if test "$vde" = "yes" ; then
2874       feature_not_found "vde" "Install vde (Virtual Distributed Ethernet) devel"
2875     fi
2876     vde=no
2877   fi
2878 fi
2879
2880 ##########################################
2881 # netmap support probe
2882 # Apart from looking for netmap headers, we make sure that the host API version
2883 # supports the netmap backend (>=11). The upper bound (15) is meant to simulate
2884 # a minor/major version number. Minor new features will be marked with values up
2885 # to 15, and if something happens that requires a change to the backend we will
2886 # move above 15, submit the backend fixes and modify this two bounds.
2887 if test "$netmap" != "no" ; then
2888   cat > $TMPC << EOF
2889 #include <inttypes.h>
2890 #include <net/if.h>
2891 #include <net/netmap.h>
2892 #include <net/netmap_user.h>
2893 #if (NETMAP_API < 11) || (NETMAP_API > 15)
2894 #error
2895 #endif
2896 int main(void) { return 0; }
2897 EOF
2898   if compile_prog "" "" ; then
2899     netmap=yes
2900   else
2901     if test "$netmap" = "yes" ; then
2902       feature_not_found "netmap"
2903     fi
2904     netmap=no
2905   fi
2906 fi
2907
2908 ##########################################
2909 # libcap-ng library probe
2910 if test "$cap_ng" != "no" ; then
2911   cap_libs="-lcap-ng"
2912   cat > $TMPC << EOF
2913 #include <cap-ng.h>
2914 int main(void)
2915 {
2916     capng_capability_to_name(CAPNG_EFFECTIVE);
2917     return 0;
2918 }
2919 EOF
2920   if compile_prog "" "$cap_libs" ; then
2921     cap_ng=yes
2922     libs_tools="$cap_libs $libs_tools"
2923   else
2924     if test "$cap_ng" = "yes" ; then
2925       feature_not_found "cap_ng" "Install libcap-ng devel"
2926     fi
2927     cap_ng=no
2928   fi
2929 fi
2930
2931 ##########################################
2932 # Sound support libraries probe
2933
2934 audio_drv_probe()
2935 {
2936     drv=$1
2937     hdr=$2
2938     lib=$3
2939     exp=$4
2940     cfl=$5
2941         cat > $TMPC << EOF
2942 #include <$hdr>
2943 int main(void) { $exp }
2944 EOF
2945     if compile_prog "$cfl" "$lib" ; then
2946         :
2947     else
2948         error_exit "$drv check failed" \
2949             "Make sure to have the $drv libs and headers installed."
2950     fi
2951 }
2952
2953 audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/,/ /g')
2954 for drv in $audio_drv_list; do
2955     case $drv in
2956     alsa)
2957     audio_drv_probe $drv alsa/asoundlib.h -lasound \
2958         "return snd_pcm_close((snd_pcm_t *)0);"
2959     libs_softmmu="-lasound $libs_softmmu"
2960     ;;
2961
2962     pa)
2963     audio_drv_probe $drv pulse/pulseaudio.h "-lpulse" \
2964         "pa_context_set_source_output_volume(NULL, 0, NULL, NULL, NULL); return 0;"
2965     libs_softmmu="-lpulse $libs_softmmu"
2966     audio_pt_int="yes"
2967     ;;
2968
2969     sdl)
2970     if test "$sdl" = "no"; then
2971         error_exit "sdl not found or disabled, can not use sdl audio driver"
2972     fi
2973     ;;
2974
2975     coreaudio)
2976       libs_softmmu="-framework CoreAudio $libs_softmmu"
2977     ;;
2978
2979     dsound)
2980       libs_softmmu="-lole32 -ldxguid $libs_softmmu"
2981       audio_win_int="yes"
2982     ;;
2983
2984     oss)
2985       libs_softmmu="$oss_lib $libs_softmmu"
2986     ;;
2987
2988     wav)
2989     # XXX: Probes for CoreAudio, DirectSound
2990     ;;
2991
2992     *)
2993     echo "$audio_possible_drivers" | grep -q "\<$drv\>" || {
2994         error_exit "Unknown driver '$drv' selected" \
2995             "Possible drivers are: $audio_possible_drivers"
2996     }
2997     ;;
2998     esac
2999 done
3000
3001 ##########################################
3002 # BrlAPI probe
3003
3004 if test "$brlapi" != "no" ; then
3005   brlapi_libs="-lbrlapi"
3006   cat > $TMPC << EOF
3007 #include <brlapi.h>
3008 #include <stddef.h>
3009 int main( void ) { return brlapi__openConnection (NULL, NULL, NULL); }
3010 EOF
3011   if compile_prog "" "$brlapi_libs" ; then
3012     brlapi=yes
3013     libs_softmmu="$brlapi_libs $libs_softmmu"
3014   else
3015     if test "$brlapi" = "yes" ; then
3016       feature_not_found "brlapi" "Install brlapi devel"
3017     fi
3018     brlapi=no
3019   fi
3020 fi
3021
3022 ##########################################
3023 # curses probe
3024 if test "$curses" != "no" ; then
3025   if test "$mingw32" = "yes" ; then
3026     curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null):"
3027     curses_lib_list="$($pkg_config --libs ncurses 2>/dev/null):-lpdcurses"
3028   else
3029     curses_inc_list="$($pkg_config --cflags ncursesw 2>/dev/null):-I/usr/include/ncursesw:"
3030     curses_lib_list="$($pkg_config --libs ncursesw 2>/dev/null):-lncursesw:-lcursesw"
3031   fi
3032   curses_found=no
3033   cat > $TMPC << EOF
3034 #include <locale.h>
3035 #include <curses.h>
3036 #include <wchar.h>
3037 int main(void) {
3038   const char *s = curses_version();
3039   wchar_t wch = L'w';
3040   setlocale(LC_ALL, "");
3041   resize_term(0, 0);
3042   addwstr(L"wide chars\n");
3043   addnwstr(&wch, 1);
3044   add_wch(WACS_DEGREE);
3045   return s != 0;
3046 }
3047 EOF
3048   IFS=:
3049   for curses_inc in $curses_inc_list; do
3050     IFS=:
3051     for curses_lib in $curses_lib_list; do
3052       unset IFS
3053       if compile_prog "$curses_inc" "$curses_lib" ; then
3054         curses_found=yes
3055         QEMU_CFLAGS="$curses_inc $QEMU_CFLAGS"
3056         libs_softmmu="$curses_lib $libs_softmmu"
3057         break
3058       fi
3059     done
3060     if test "$curses_found" = yes ; then
3061       break
3062     fi
3063   done
3064   unset IFS
3065   if test "$curses_found" = "yes" ; then
3066     curses=yes
3067   else
3068     if test "$curses" = "yes" ; then
3069       feature_not_found "curses" "Install ncurses devel"
3070     fi
3071     curses=no
3072   fi
3073 fi
3074
3075 ##########################################
3076 # curl probe
3077 if test "$curl" != "no" ; then
3078   if $pkg_config libcurl --exists; then
3079     curlconfig="$pkg_config libcurl"
3080   else
3081     curlconfig=curl-config
3082   fi
3083   cat > $TMPC << EOF
3084 #include <curl/curl.h>
3085 int main(void) { curl_easy_init(); curl_multi_setopt(0, 0, 0); return 0; }
3086 EOF
3087   curl_cflags=$($curlconfig --cflags 2>/dev/null)
3088   curl_libs=$($curlconfig --libs 2>/dev/null)
3089   if compile_prog "$curl_cflags" "$curl_libs" ; then
3090     curl=yes
3091   else
3092     if test "$curl" = "yes" ; then
3093       feature_not_found "curl" "Install libcurl devel"
3094     fi
3095     curl=no
3096   fi
3097 fi # test "$curl"
3098
3099 ##########################################
3100 # bluez support probe
3101 if test "$bluez" != "no" ; then
3102   cat > $TMPC << EOF
3103 #include <bluetooth/bluetooth.h>
3104 int main(void) { return bt_error(0); }
3105 EOF
3106   bluez_cflags=$($pkg_config --cflags bluez 2>/dev/null)
3107   bluez_libs=$($pkg_config --libs bluez 2>/dev/null)
3108   if compile_prog "$bluez_cflags" "$bluez_libs" ; then
3109     bluez=yes
3110     libs_softmmu="$bluez_libs $libs_softmmu"
3111   else
3112     if test "$bluez" = "yes" ; then
3113       feature_not_found "bluez" "Install bluez-libs/libbluetooth devel"
3114     fi
3115     bluez="no"
3116   fi
3117 fi
3118
3119 ##########################################
3120 # glib support probe
3121
3122 if test "$mingw32" = yes; then
3123     glib_req_ver=2.30
3124 else
3125     glib_req_ver=2.22
3126 fi
3127 glib_modules=gthread-2.0
3128 if test "$modules" = yes; then
3129     glib_modules="$glib_modules gmodule-2.0"
3130 fi
3131
3132 # This workaround is required due to a bug in pkg-config file for glib as it
3133 # doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
3134
3135 if test "$static" = yes -a "$mingw32" = yes; then
3136     QEMU_CFLAGS="-DGLIB_STATIC_COMPILATION $QEMU_CFLAGS"
3137 fi
3138
3139 for i in $glib_modules; do
3140     if $pkg_config --atleast-version=$glib_req_ver $i; then
3141         glib_cflags=$($pkg_config --cflags $i)
3142         glib_libs=$($pkg_config --libs $i)
3143         QEMU_CFLAGS="$glib_cflags $QEMU_CFLAGS"
3144         LIBS="$glib_libs $LIBS"
3145         libs_qga="$glib_libs $libs_qga"
3146     else
3147         error_exit "glib-$glib_req_ver $i is required to compile QEMU"
3148     fi
3149 done
3150
3151 # Sanity check that the current size_t matches the
3152 # size that glib thinks it should be. This catches
3153 # problems on multi-arch where people try to build
3154 # 32-bit QEMU while pointing at 64-bit glib headers
3155 cat > $TMPC <<EOF
3156 #include <glib.h>
3157 #include <unistd.h>
3158
3159 #define QEMU_BUILD_BUG_ON(x) \
3160   typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
3161
3162 int main(void) {
3163    QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
3164    return 0;
3165 }
3166 EOF
3167
3168 if ! compile_prog "$CFLAGS" "$LIBS" ; then
3169     error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
3170                "You probably need to set PKG_CONFIG_LIBDIR"\
3171                "to point to the right pkg-config files for your"\
3172                "build target"
3173 fi
3174
3175 # g_test_trap_subprocess added in 2.38. Used by some tests.
3176 glib_subprocess=yes
3177 if ! $pkg_config --atleast-version=2.38 glib-2.0; then
3178     glib_subprocess=no
3179 fi
3180
3181 # Silence clang 3.5.0 warnings about glib attribute __alloc_size__ usage
3182 cat > $TMPC << EOF
3183 #include <glib.h>
3184 int main(void) { return 0; }
3185 EOF
3186 if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
3187     if cc_has_warning_flag "-Wno-unknown-attributes"; then
3188         glib_cflags="-Wno-unknown-attributes $glib_cflags"
3189         CFLAGS="-Wno-unknown-attributes $CFLAGS"
3190     fi
3191 fi
3192
3193 ##########################################
3194 # SHA command probe for modules
3195 if test "$modules" = yes; then
3196     shacmd_probe="sha1sum sha1 shasum"
3197     for c in $shacmd_probe; do
3198         if has $c; then
3199             shacmd="$c"
3200             break
3201         fi
3202     done
3203     if test "$shacmd" = ""; then
3204         error_exit "one of the checksum commands is required to enable modules: $shacmd_probe"
3205     fi
3206 fi
3207
3208 ##########################################
3209 # pixman support probe
3210
3211 if test "$pixman" = ""; then
3212   if test "$want_tools" = "no" -a "$softmmu" = "no"; then
3213     pixman="none"
3214   elif $pkg_config --atleast-version=0.21.8 pixman-1 > /dev/null 2>&1; then
3215     pixman="system"
3216   else
3217     pixman="internal"
3218   fi
3219 fi
3220 if test "$pixman" = "none"; then
3221   if test "$want_tools" != "no" -o "$softmmu" != "no"; then
3222     error_exit "pixman disabled but system emulation or tools build" \
3223         "enabled.  You can turn off pixman only if you also" \
3224         "disable all system emulation targets and the tools" \
3225         "build with '--disable-tools --disable-system'."
3226   fi
3227   pixman_cflags=
3228   pixman_libs=
3229 elif test "$pixman" = "system"; then
3230   # pixman version has been checked above
3231   pixman_cflags=$($pkg_config --cflags pixman-1)
3232   pixman_libs=$($pkg_config --libs pixman-1)
3233 else
3234   if test ! -d ${source_path}/pixman/pixman; then
3235     error_exit "pixman >= 0.21.8 not present. Your options:" \
3236         "  (1) Preferred: Install the pixman devel package (any recent" \
3237         "      distro should have packages as Xorg needs pixman too)." \
3238         "  (2) Fetch the pixman submodule, using:" \
3239         "      git submodule update --init pixman"
3240   fi
3241   mkdir -p pixman/pixman
3242   pixman_cflags="-I\$(SRC_PATH)/pixman/pixman -I\$(BUILD_DIR)/pixman/pixman"
3243   pixman_libs="-L\$(BUILD_DIR)/pixman/pixman/.libs -lpixman-1"
3244 fi
3245
3246 ##########################################
3247 # libcap probe
3248
3249 if test "$cap" != "no" ; then
3250   cat > $TMPC <<EOF
3251 #include <stdio.h>
3252 #include <sys/capability.h>
3253 int main(void) { cap_t caps; caps = cap_init(); return caps != NULL; }
3254 EOF
3255   if compile_prog "" "-lcap" ; then
3256     cap=yes
3257   else
3258     cap=no
3259   fi
3260 fi
3261
3262 ##########################################
3263 # pthread probe
3264 PTHREADLIBS_LIST="-pthread -lpthread -lpthreadGC2"
3265
3266 pthread=no
3267 cat > $TMPC << EOF
3268 #include <pthread.h>
3269 static void *f(void *p) { return NULL; }
3270 int main(void) {
3271   pthread_t thread;
3272   pthread_create(&thread, 0, f, 0);
3273   return 0;
3274 }
3275 EOF
3276 if compile_prog "" "" ; then
3277   pthread=yes
3278 else
3279   for pthread_lib in $PTHREADLIBS_LIST; do
3280     if compile_prog "" "$pthread_lib" ; then
3281       pthread=yes
3282       found=no
3283       for lib_entry in $LIBS; do
3284         if test "$lib_entry" = "$pthread_lib"; then
3285           found=yes
3286           break
3287         fi
3288       done
3289       if test "$found" = "no"; then
3290         LIBS="$pthread_lib $LIBS"
3291       fi
3292       PTHREAD_LIB="$pthread_lib"
3293       break
3294     fi
3295   done
3296 fi
3297
3298 if test "$mingw32" != yes -a "$pthread" = no; then
3299   error_exit "pthread check failed" \
3300       "Make sure to have the pthread libs and headers installed."
3301 fi
3302
3303 # check for pthread_setname_np
3304 pthread_setname_np=no
3305 cat > $TMPC << EOF
3306 #include <pthread.h>
3307
3308 static void *f(void *p) { return NULL; }
3309 int main(void)
3310 {
3311     pthread_t thread;
3312     pthread_create(&thread, 0, f, 0);
3313     pthread_setname_np(thread, "QEMU");
3314     return 0;
3315 }
3316 EOF
3317 if compile_prog "" "$pthread_lib" ; then
3318   pthread_setname_np=yes
3319 fi
3320
3321 ##########################################
3322 # rbd probe
3323 if test "$rbd" != "no" ; then
3324   cat > $TMPC <<EOF
3325 #include <stdio.h>
3326 #include <rbd/librbd.h>
3327 int main(void) {
3328     rados_t cluster;
3329     rados_create(&cluster, NULL);
3330     return 0;
3331 }
3332 EOF
3333   rbd_libs="-lrbd -lrados"
3334   if compile_prog "" "$rbd_libs" ; then
3335     rbd=yes
3336   else
3337     if test "$rbd" = "yes" ; then
3338       feature_not_found "rados block device" "Install librbd/ceph devel"
3339     fi
3340     rbd=no
3341   fi
3342 fi
3343
3344 ##########################################
3345 # libssh2 probe
3346 min_libssh2_version=1.2.8
3347 if test "$libssh2" != "no" ; then
3348   if $pkg_config --atleast-version=$min_libssh2_version libssh2; then
3349     libssh2_cflags=$($pkg_config libssh2 --cflags)
3350     libssh2_libs=$($pkg_config libssh2 --libs)
3351     libssh2=yes
3352   else
3353     if test "$libssh2" = "yes" ; then
3354       error_exit "libssh2 >= $min_libssh2_version required for --enable-libssh2"
3355     fi
3356     libssh2=no
3357   fi
3358 fi
3359
3360 ##########################################
3361 # libssh2_sftp_fsync probe
3362
3363 if test "$libssh2" = "yes"; then
3364   cat > $TMPC <<EOF
3365 #include <stdio.h>
3366 #include <libssh2.h>
3367 #include <libssh2_sftp.h>
3368 int main(void) {
3369     LIBSSH2_SESSION *session;
3370     LIBSSH2_SFTP *sftp;
3371     LIBSSH2_SFTP_HANDLE *sftp_handle;
3372     session = libssh2_session_init ();
3373     sftp = libssh2_sftp_init (session);
3374     sftp_handle = libssh2_sftp_open (sftp, "/", 0, 0);
3375     libssh2_sftp_fsync (sftp_handle);
3376     return 0;
3377 }
3378 EOF
3379   # libssh2_cflags/libssh2_libs defined in previous test.
3380   if compile_prog "$libssh2_cflags" "$libssh2_libs" ; then
3381     QEMU_CFLAGS="-DHAS_LIBSSH2_SFTP_FSYNC $QEMU_CFLAGS"
3382   fi
3383 fi
3384
3385 ##########################################
3386 # linux-aio probe
3387
3388 if test "$linux_aio" != "no" ; then
3389   cat > $TMPC <<EOF
3390 #include <libaio.h>
3391 #include <sys/eventfd.h>
3392 #include <stddef.h>
3393 int main(void) { io_setup(0, NULL); io_set_eventfd(NULL, 0); eventfd(0, 0); return 0; }
3394 EOF
3395   if compile_prog "" "-laio" ; then
3396     linux_aio=yes
3397   else
3398     if test "$linux_aio" = "yes" ; then
3399       feature_not_found "linux AIO" "Install libaio devel"
3400     fi
3401     linux_aio=no
3402   fi
3403 fi
3404
3405 ##########################################
3406 # TPM passthrough is only on x86 Linux
3407
3408 if test "$targetos" = Linux && test "$cpu" = i386 -o "$cpu" = x86_64; then
3409   tpm_passthrough=$tpm
3410 else
3411   tpm_passthrough=no
3412 fi
3413
3414 ##########################################
3415 # attr probe
3416
3417 if test "$attr" != "no" ; then
3418   cat > $TMPC <<EOF
3419 #include <stdio.h>
3420 #include <sys/types.h>
3421 #ifdef CONFIG_LIBATTR
3422 #include <attr/xattr.h>
3423 #else
3424 #include <sys/xattr.h>
3425 #endif
3426 int main(void) { getxattr(NULL, NULL, NULL, 0); setxattr(NULL, NULL, NULL, 0, 0); return 0; }
3427 EOF
3428   if compile_prog "" "" ; then
3429     attr=yes
3430   # Older distros have <attr/xattr.h>, and need -lattr:
3431   elif compile_prog "-DCONFIG_LIBATTR" "-lattr" ; then
3432     attr=yes
3433     LIBS="-lattr $LIBS"
3434     libattr=yes
3435   else
3436     if test "$attr" = "yes" ; then
3437       feature_not_found "ATTR" "Install libc6 or libattr devel"
3438     fi
3439     attr=no
3440   fi
3441 fi
3442
3443 ##########################################
3444 # iovec probe
3445 cat > $TMPC <<EOF
3446 #include <sys/types.h>
3447 #include <sys/uio.h>
3448 #include <unistd.h>
3449 int main(void) { return sizeof(struct iovec); }
3450 EOF
3451 iovec=no
3452 if compile_prog "" "" ; then
3453   iovec=yes
3454 fi
3455
3456 ##########################################
3457 # preadv probe
3458 cat > $TMPC <<EOF
3459 #include <sys/types.h>
3460 #include <sys/uio.h>
3461 #include <unistd.h>
3462 int main(void) { return preadv(0, 0, 0, 0); }
3463 EOF
3464 preadv=no
3465 if compile_prog "" "" ; then
3466   preadv=yes
3467 fi
3468
3469 ##########################################
3470 # fdt probe
3471 # fdt support is mandatory for at least some target architectures,
3472 # so insist on it if we're building those system emulators.
3473 fdt_required=no
3474 for target in $target_list; do
3475   case $target in
3476     aarch64*-softmmu|arm*-softmmu|ppc*-softmmu|microblaze*-softmmu|mips64el-softmmu)
3477       fdt_required=yes
3478     ;;
3479   esac
3480 done
3481
3482 if test "$fdt_required" = "yes"; then
3483   if test "$fdt" = "no"; then
3484     error_exit "fdt disabled but some requested targets require it." \
3485       "You can turn off fdt only if you also disable all the system emulation" \
3486       "targets which need it (by specifying a cut down --target-list)."
3487   fi
3488   fdt=yes
3489 fi
3490
3491 if test "$fdt" != "no" ; then
3492   fdt_libs="-lfdt"
3493   # explicitly check for libfdt_env.h as it is missing in some stable installs
3494   # and test for required functions to make sure we are on a version >= 1.4.2
3495   cat > $TMPC << EOF
3496 #include <libfdt.h>
3497 #include <libfdt_env.h>
3498 int main(void) { fdt_first_subnode(0, 0); return 0; }
3499 EOF
3500   if compile_prog "" "$fdt_libs" ; then
3501     # system DTC is good - use it
3502     fdt=yes
3503   elif test -d ${source_path}/dtc/libfdt ; then
3504     # have submodule DTC - use it
3505     fdt=yes
3506     dtc_internal="yes"
3507     mkdir -p dtc
3508     if [ "$pwd_is_source_path" != "y" ] ; then
3509        symlink "$source_path/dtc/Makefile" "dtc/Makefile"
3510        symlink "$source_path/dtc/scripts" "dtc/scripts"
3511     fi
3512     fdt_cflags="-I\$(SRC_PATH)/dtc/libfdt"
3513     fdt_libs="-L\$(BUILD_DIR)/dtc/libfdt $fdt_libs"
3514   elif test "$fdt" = "yes" ; then
3515     # have neither and want - prompt for system/submodule install
3516     error_exit "DTC (libfdt) version >= 1.4.2 not present. Your options:" \
3517         "  (1) Preferred: Install the DTC (libfdt) devel package" \
3518         "  (2) Fetch the DTC submodule, using:" \
3519         "      git submodule update --init dtc"
3520   else
3521     # don't have and don't want
3522     fdt_libs=
3523     fdt=no
3524   fi
3525 fi
3526
3527 libs_softmmu="$libs_softmmu $fdt_libs"
3528
3529 ##########################################
3530 # opengl probe (for sdl2, gtk, milkymist-tmu2)
3531
3532 if test "$opengl" != "no" ; then
3533   opengl_pkgs="epoxy libdrm gbm"
3534   if $pkg_config $opengl_pkgs x11; then
3535     opengl_cflags="$($pkg_config --cflags $opengl_pkgs) $x11_cflags"
3536     opengl_libs="$($pkg_config --libs $opengl_pkgs) $x11_libs"
3537     opengl=yes
3538     if test "$gtk" = "yes" && $pkg_config --exists "$gtkpackage >= 3.16"; then
3539         gtk_gl="yes"
3540     fi
3541     QEMU_CFLAGS="$QEMU_CFLAGS $opengl_cflags"
3542   else
3543     if test "$opengl" = "yes" ; then
3544       feature_not_found "opengl" "Please install opengl (mesa) devel pkgs: $opengl_pkgs"
3545     fi
3546     opengl_cflags=""
3547     opengl_libs=""
3548     opengl=no
3549   fi
3550 fi
3551
3552 if test "$opengl" = "yes"; then
3553   cat > $TMPC << EOF
3554 #include <epoxy/egl.h>
3555 #ifndef EGL_MESA_image_dma_buf_export
3556 # error mesa/epoxy lacks support for dmabufs (mesa 10.6+)
3557 #endif
3558 int main(void) { return 0; }
3559 EOF
3560   if compile_prog "" "" ; then
3561     opengl_dmabuf=yes
3562   fi
3563 fi
3564
3565
3566 ##########################################
3567 # glusterfs probe
3568 if test "$glusterfs" != "no" ; then
3569   if $pkg_config --atleast-version=3 glusterfs-api; then
3570     glusterfs="yes"
3571     glusterfs_cflags=$($pkg_config --cflags glusterfs-api)
3572     glusterfs_libs=$($pkg_config --libs glusterfs-api)
3573     if $pkg_config --atleast-version=4 glusterfs-api; then
3574       glusterfs_xlator_opt="yes"
3575     fi
3576     if $pkg_config --atleast-version=5 glusterfs-api; then
3577       glusterfs_discard="yes"
3578     fi
3579     if $pkg_config --atleast-version=6 glusterfs-api; then
3580       glusterfs_zerofill="yes"
3581     fi
3582   else
3583     if test "$glusterfs" = "yes" ; then
3584       feature_not_found "GlusterFS backend support" \
3585           "Install glusterfs-api devel >= 3"
3586     fi
3587     glusterfs="no"
3588   fi
3589 fi
3590
3591 # Check for inotify functions when we are building linux-user
3592 # emulator.  This is done because older glibc versions don't
3593 # have syscall stubs for these implemented.  In that case we
3594 # don't provide them even if kernel supports them.
3595 #
3596 inotify=no
3597 cat > $TMPC << EOF
3598 #include <sys/inotify.h>
3599
3600 int
3601 main(void)
3602 {
3603         /* try to start inotify */
3604         return inotify_init();
3605 }
3606 EOF
3607 if compile_prog "" "" ; then
3608   inotify=yes
3609 fi
3610
3611 inotify1=no
3612 cat > $TMPC << EOF
3613 #include <sys/inotify.h>
3614
3615 int
3616 main(void)
3617 {
3618     /* try to start inotify */
3619     return inotify_init1(0);
3620 }
3621 EOF
3622 if compile_prog "" "" ; then
3623   inotify1=yes
3624 fi
3625
3626 # check if utimensat and futimens are supported
3627 utimens=no
3628 cat > $TMPC << EOF
3629 #define _ATFILE_SOURCE
3630 #include <stddef.h>
3631 #include <fcntl.h>
3632 #include <sys/stat.h>
3633
3634 int main(void)
3635 {
3636     utimensat(AT_FDCWD, "foo", NULL, 0);
3637     futimens(0, NULL);
3638     return 0;
3639 }
3640 EOF
3641 if compile_prog "" "" ; then
3642   utimens=yes
3643 fi
3644
3645 # check if pipe2 is there
3646 pipe2=no
3647 cat > $TMPC << EOF
3648 #include <unistd.h>
3649 #include <fcntl.h>
3650
3651 int main(void)
3652 {
3653     int pipefd[2];
3654     return pipe2(pipefd, O_CLOEXEC);
3655 }
3656 EOF
3657 if compile_prog "" "" ; then
3658   pipe2=yes
3659 fi
3660
3661 # check if accept4 is there
3662 accept4=no
3663 cat > $TMPC << EOF
3664 #include <sys/socket.h>
3665 #include <stddef.h>
3666
3667 int main(void)
3668 {
3669     accept4(0, NULL, NULL, SOCK_CLOEXEC);
3670     return 0;
3671 }
3672 EOF
3673 if compile_prog "" "" ; then
3674   accept4=yes
3675 fi
3676
3677 # check if tee/splice is there. vmsplice was added same time.
3678 splice=no
3679 cat > $TMPC << EOF
3680 #include <unistd.h>
3681 #include <fcntl.h>
3682 #include <limits.h>
3683
3684 int main(void)
3685 {
3686     int len, fd = 0;
3687     len = tee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, SPLICE_F_NONBLOCK);
3688     splice(STDIN_FILENO, NULL, fd, NULL, len, SPLICE_F_MOVE);
3689     return 0;
3690 }
3691 EOF
3692 if compile_prog "" "" ; then
3693   splice=yes
3694 fi
3695
3696 ##########################################
3697 # libnuma probe
3698
3699 if test "$numa" != "no" ; then
3700   cat > $TMPC << EOF
3701 #include <numa.h>
3702 int main(void) { return numa_available(); }
3703 EOF
3704
3705   if compile_prog "" "-lnuma" ; then
3706     numa=yes
3707     libs_softmmu="-lnuma $libs_softmmu"
3708   else
3709     if test "$numa" = "yes" ; then
3710       feature_not_found "numa" "install numactl devel"
3711     fi
3712     numa=no
3713   fi
3714 fi
3715
3716 if test "$tcmalloc" = "yes" && test "$jemalloc" = "yes" ; then
3717     echo "ERROR: tcmalloc && jemalloc can't be used at the same time"
3718     exit 1
3719 fi
3720
3721 ##########################################
3722 # tcmalloc probe
3723
3724 if test "$tcmalloc" = "yes" ; then
3725   cat > $TMPC << EOF
3726 #include <stdlib.h>
3727 int main(void) { malloc(1); return 0; }
3728 EOF
3729
3730   if compile_prog "" "-ltcmalloc" ; then
3731     LIBS="-ltcmalloc $LIBS"
3732   else
3733     feature_not_found "tcmalloc" "install gperftools devel"
3734   fi
3735 fi
3736
3737 ##########################################
3738 # jemalloc probe
3739
3740 if test "$jemalloc" = "yes" ; then
3741   cat > $TMPC << EOF
3742 #include <stdlib.h>
3743 int main(void) { malloc(1); return 0; }
3744 EOF
3745
3746   if compile_prog "" "-ljemalloc" ; then
3747     LIBS="-ljemalloc $LIBS"
3748   else
3749     feature_not_found "jemalloc" "install jemalloc devel"
3750   fi
3751 fi
3752
3753 ##########################################
3754 # signalfd probe
3755 signalfd="no"
3756 cat > $TMPC << EOF
3757 #include <unistd.h>
3758 #include <sys/syscall.h>
3759 #include <signal.h>
3760 int main(void) { return syscall(SYS_signalfd, -1, NULL, _NSIG / 8); }
3761 EOF
3762
3763 if compile_prog "" "" ; then
3764   signalfd=yes
3765 fi
3766
3767 # check if eventfd is supported
3768 eventfd=no
3769 cat > $TMPC << EOF
3770 #include <sys/eventfd.h>
3771
3772 int main(void)
3773 {
3774     return eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
3775 }
3776 EOF
3777 if compile_prog "" "" ; then
3778   eventfd=yes
3779 fi
3780
3781 # check if memfd is supported
3782 memfd=no
3783 cat > $TMPC << EOF
3784 #include <sys/memfd.h>
3785
3786 int main(void)
3787 {
3788     return memfd_create("foo", MFD_ALLOW_SEALING);
3789 }
3790 EOF
3791 if compile_prog "" "" ; then
3792   memfd=yes
3793 fi
3794
3795
3796
3797 # check for fallocate
3798 fallocate=no
3799 cat > $TMPC << EOF
3800 #include <fcntl.h>
3801
3802 int main(void)
3803 {
3804     fallocate(0, 0, 0, 0);
3805     return 0;
3806 }
3807 EOF
3808 if compile_prog "" "" ; then
3809   fallocate=yes
3810 fi
3811
3812 # check for fallocate hole punching
3813 fallocate_punch_hole=no
3814 cat > $TMPC << EOF
3815 #include <fcntl.h>
3816 #include <linux/falloc.h>
3817
3818 int main(void)
3819 {
3820     fallocate(0, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 0);
3821     return 0;
3822 }
3823 EOF
3824 if compile_prog "" "" ; then
3825   fallocate_punch_hole=yes
3826 fi
3827
3828 # check that fallocate supports range zeroing inside the file
3829 fallocate_zero_range=no
3830 cat > $TMPC << EOF
3831 #include <fcntl.h>
3832 #include <linux/falloc.h>
3833
3834 int main(void)
3835 {
3836     fallocate(0, FALLOC_FL_ZERO_RANGE, 0, 0);
3837     return 0;
3838 }
3839 EOF
3840 if compile_prog "" "" ; then
3841   fallocate_zero_range=yes
3842 fi
3843
3844 # check for posix_fallocate
3845 posix_fallocate=no
3846 cat > $TMPC << EOF
3847 #include <fcntl.h>
3848
3849 int main(void)
3850 {
3851     posix_fallocate(0, 0, 0);
3852     return 0;
3853 }
3854 EOF
3855 if compile_prog "" "" ; then
3856     posix_fallocate=yes
3857 fi
3858
3859 # check for sync_file_range
3860 sync_file_range=no
3861 cat > $TMPC << EOF
3862 #include <fcntl.h>
3863
3864 int main(void)
3865 {
3866     sync_file_range(0, 0, 0, 0);
3867     return 0;
3868 }
3869 EOF
3870 if compile_prog "" "" ; then
3871   sync_file_range=yes
3872 fi
3873
3874 # check for linux/fiemap.h and FS_IOC_FIEMAP
3875 fiemap=no
3876 cat > $TMPC << EOF
3877 #include <sys/ioctl.h>
3878 #include <linux/fs.h>
3879 #include <linux/fiemap.h>
3880
3881 int main(void)
3882 {
3883     ioctl(0, FS_IOC_FIEMAP, 0);
3884     return 0;
3885 }
3886 EOF
3887 if compile_prog "" "" ; then
3888   fiemap=yes
3889 fi
3890
3891 # check for dup3
3892 dup3=no
3893 cat > $TMPC << EOF
3894 #include <unistd.h>
3895
3896 int main(void)
3897 {
3898     dup3(0, 0, 0);
3899     return 0;
3900 }
3901 EOF
3902 if compile_prog "" "" ; then
3903   dup3=yes
3904 fi
3905
3906 # check for ppoll support
3907 ppoll=no
3908 cat > $TMPC << EOF
3909 #include <poll.h>
3910
3911 int main(void)
3912 {
3913     struct pollfd pfd = { .fd = 0, .events = 0, .revents = 0 };
3914     ppoll(&pfd, 1, 0, 0);
3915     return 0;
3916 }
3917 EOF
3918 if compile_prog "" "" ; then
3919   ppoll=yes
3920 fi
3921
3922 # check for prctl(PR_SET_TIMERSLACK , ... ) support
3923 prctl_pr_set_timerslack=no
3924 cat > $TMPC << EOF
3925 #include <sys/prctl.h>
3926
3927 int main(void)
3928 {
3929     prctl(PR_SET_TIMERSLACK, 1, 0, 0, 0);
3930     return 0;
3931 }
3932 EOF
3933 if compile_prog "" "" ; then
3934   prctl_pr_set_timerslack=yes
3935 fi
3936
3937 # check for epoll support
3938 epoll=no
3939 cat > $TMPC << EOF
3940 #include <sys/epoll.h>
3941
3942 int main(void)
3943 {
3944     epoll_create(0);
3945     return 0;
3946 }
3947 EOF
3948 if compile_prog "" "" ; then
3949   epoll=yes
3950 fi
3951
3952 # epoll_create1 is a later addition
3953 # so we must check separately for its presence
3954 epoll_create1=no
3955 cat > $TMPC << EOF
3956 #include <sys/epoll.h>
3957
3958 int main(void)
3959 {
3960     /* Note that we use epoll_create1 as a value, not as
3961      * a function being called. This is necessary so that on
3962      * old SPARC glibc versions where the function was present in
3963      * the library but not declared in the header file we will
3964      * fail the configure check. (Otherwise we will get a compiler
3965      * warning but not an error, and will proceed to fail the
3966      * qemu compile where we compile with -Werror.)
3967      */
3968     return (int)(uintptr_t)&epoll_create1;
3969 }
3970 EOF
3971 if compile_prog "" "" ; then
3972   epoll_create1=yes
3973 fi
3974
3975 # check for sendfile support
3976 sendfile=no
3977 cat > $TMPC << EOF
3978 #include <sys/sendfile.h>
3979
3980 int main(void)
3981 {
3982     return sendfile(0, 0, 0, 0);
3983 }
3984 EOF
3985 if compile_prog "" "" ; then
3986   sendfile=yes
3987 fi
3988
3989 # check for timerfd support (glibc 2.8 and newer)
3990 timerfd=no
3991 cat > $TMPC << EOF
3992 #include <sys/timerfd.h>
3993
3994 int main(void)
3995 {
3996     return(timerfd_create(CLOCK_REALTIME, 0));
3997 }
3998 EOF
3999 if compile_prog "" "" ; then
4000   timerfd=yes
4001 fi
4002
4003 # check for setns and unshare support
4004 setns=no
4005 cat > $TMPC << EOF
4006 #include <sched.h>
4007
4008 int main(void)
4009 {
4010     int ret;
4011     ret = setns(0, 0);
4012     ret = unshare(0);
4013     return ret;
4014 }
4015 EOF
4016 if compile_prog "" "" ; then
4017   setns=yes
4018 fi
4019
4020 # clock_adjtime probe
4021 clock_adjtime=no
4022 cat > $TMPC <<EOF
4023 #include <time.h>
4024
4025 int main(void)
4026 {
4027     return clock_adjtime(0, 0);
4028 }
4029 EOF
4030 clock_adjtime=no
4031 if compile_prog "" "" ; then
4032   clock_adjtime=yes
4033 fi
4034
4035 # syncfs probe
4036 syncfs=no
4037 cat > $TMPC <<EOF
4038 #include <unistd.h>
4039
4040 int main(void)
4041 {
4042     return syncfs(0);
4043 }
4044 EOF
4045 syncfs=no
4046 if compile_prog "" "" ; then
4047   syncfs=yes
4048 fi
4049
4050 # Check if tools are available to build documentation.
4051 if test "$docs" != "no" ; then
4052   if has makeinfo && has pod2man; then
4053     docs=yes
4054   else
4055     if test "$docs" = "yes" ; then
4056       feature_not_found "docs" "Install texinfo and Perl/perl-podlators"
4057     fi
4058     docs=no
4059   fi
4060 fi
4061
4062 # Search for bswap_32 function
4063 byteswap_h=no
4064 cat > $TMPC << EOF
4065 #include <byteswap.h>
4066 int main(void) { return bswap_32(0); }
4067 EOF
4068 if compile_prog "" "" ; then
4069   byteswap_h=yes
4070 fi
4071
4072 # Search for bswap32 function
4073 bswap_h=no
4074 cat > $TMPC << EOF
4075 #include <sys/endian.h>
4076 #include <sys/types.h>
4077 #include <machine/bswap.h>
4078 int main(void) { return bswap32(0); }
4079 EOF
4080 if compile_prog "" "" ; then
4081   bswap_h=yes
4082 fi
4083
4084 ##########################################
4085 # Do we have libiscsi >= 1.9.0
4086 if test "$libiscsi" != "no" ; then
4087   if $pkg_config --atleast-version=1.9.0 libiscsi; then
4088     libiscsi="yes"
4089     libiscsi_cflags=$($pkg_config --cflags libiscsi)
4090     libiscsi_libs=$($pkg_config --libs libiscsi)
4091   else
4092     if test "$libiscsi" = "yes" ; then
4093       feature_not_found "libiscsi" "Install libiscsi >= 1.9.0"
4094     fi
4095     libiscsi="no"
4096   fi
4097 fi
4098
4099 ##########################################
4100 # Do we need libm
4101 cat > $TMPC << EOF
4102 #include <math.h>
4103 int main(int argc, char **argv) { return isnan(sin((double)argc)); }
4104 EOF
4105 if compile_prog "" "" ; then
4106   :
4107 elif compile_prog "" "-lm" ; then
4108   LIBS="-lm $LIBS"
4109   libs_qga="-lm $libs_qga"
4110 else
4111   error_exit "libm check failed"
4112 fi
4113
4114 ##########################################
4115 # Do we need librt
4116 # uClibc provides 2 versions of clock_gettime(), one with realtime
4117 # support and one without. This means that the clock_gettime() don't
4118 # need -lrt. We still need it for timer_create() so we check for this
4119 # function in addition.
4120 cat > $TMPC <<EOF
4121 #include <signal.h>
4122 #include <time.h>
4123 int main(void) {
4124   timer_create(CLOCK_REALTIME, NULL, NULL);
4125   return clock_gettime(CLOCK_REALTIME, NULL);
4126 }
4127 EOF
4128
4129 if compile_prog "" "" ; then
4130   :
4131 # we need pthread for static linking. use previous pthread test result
4132 elif compile_prog "" "$pthread_lib -lrt" ; then
4133   LIBS="$LIBS -lrt"
4134   libs_qga="$libs_qga -lrt"
4135 fi
4136
4137 if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \
4138         "$aix" != "yes" -a "$haiku" != "yes" ; then
4139     libs_softmmu="-lutil $libs_softmmu"
4140 fi
4141
4142 ##########################################
4143 # spice probe
4144 if test "$spice" != "no" ; then
4145   cat > $TMPC << EOF
4146 #include <spice.h>
4147 int main(void) { spice_server_new(); return 0; }
4148 EOF
4149   spice_cflags=$($pkg_config --cflags spice-protocol spice-server 2>/dev/null)
4150   spice_libs=$($pkg_config --libs spice-protocol spice-server 2>/dev/null)
4151   if $pkg_config --atleast-version=0.12.0 spice-server && \
4152      $pkg_config --atleast-version=0.12.3 spice-protocol && \
4153      compile_prog "$spice_cflags" "$spice_libs" ; then
4154     spice="yes"
4155     libs_softmmu="$libs_softmmu $spice_libs"
4156     QEMU_CFLAGS="$QEMU_CFLAGS $spice_cflags"
4157     spice_protocol_version=$($pkg_config --modversion spice-protocol)
4158     spice_server_version=$($pkg_config --modversion spice-server)
4159   else
4160     if test "$spice" = "yes" ; then
4161       feature_not_found "spice" \
4162           "Install spice-server(>=0.12.0) and spice-protocol(>=0.12.3) devel"
4163     fi
4164     spice="no"
4165   fi
4166 fi
4167
4168 # check for smartcard support
4169 smartcard_cflags=""
4170 if test "$smartcard" != "no"; then
4171     if $pkg_config libcacard; then
4172         libcacard_cflags=$($pkg_config --cflags libcacard)
4173         libcacard_libs=$($pkg_config --libs libcacard)
4174         QEMU_CFLAGS="$QEMU_CFLAGS $libcacard_cflags"
4175         libs_softmmu="$libs_softmmu $libcacard_libs"
4176         smartcard="yes"
4177     else
4178         if test "$smartcard" = "yes"; then
4179             feature_not_found "smartcard" "Install libcacard devel"
4180         fi
4181         smartcard="no"
4182     fi
4183 fi
4184
4185 # check for libusb
4186 if test "$libusb" != "no" ; then
4187     if $pkg_config --atleast-version=1.0.13 libusb-1.0; then
4188         libusb="yes"
4189         libusb_cflags=$($pkg_config --cflags libusb-1.0)
4190         libusb_libs=$($pkg_config --libs libusb-1.0)
4191         QEMU_CFLAGS="$QEMU_CFLAGS $libusb_cflags"
4192         libs_softmmu="$libs_softmmu $libusb_libs"
4193     else
4194         if test "$libusb" = "yes"; then
4195             feature_not_found "libusb" "Install libusb devel >= 1.0.13"
4196         fi
4197         libusb="no"
4198     fi
4199 fi
4200
4201 # check for usbredirparser for usb network redirection support
4202 if test "$usb_redir" != "no" ; then
4203     if $pkg_config --atleast-version=0.6 libusbredirparser-0.5; then
4204         usb_redir="yes"
4205         usb_redir_cflags=$($pkg_config --cflags libusbredirparser-0.5)
4206         usb_redir_libs=$($pkg_config --libs libusbredirparser-0.5)
4207         QEMU_CFLAGS="$QEMU_CFLAGS $usb_redir_cflags"
4208         libs_softmmu="$libs_softmmu $usb_redir_libs"
4209     else
4210         if test "$usb_redir" = "yes"; then
4211             feature_not_found "usb-redir" "Install usbredir devel"
4212         fi
4213         usb_redir="no"
4214     fi
4215 fi
4216
4217 ##########################################
4218 # check if we have VSS SDK headers for win
4219
4220 if test "$mingw32" = "yes" -a "$guest_agent" != "no" -a "$vss_win32_sdk" != "no" ; then
4221   case "$vss_win32_sdk" in
4222     "")   vss_win32_include="-isystem $source_path" ;;
4223     *\ *) # The SDK is installed in "Program Files" by default, but we cannot
4224           # handle path with spaces. So we symlink the headers into ".sdk/vss".
4225           vss_win32_include="-isystem $source_path/.sdk/vss"
4226           symlink "$vss_win32_sdk/inc" "$source_path/.sdk/vss/inc"
4227           ;;
4228     *)    vss_win32_include="-isystem $vss_win32_sdk"
4229   esac
4230   cat > $TMPC << EOF
4231 #define __MIDL_user_allocate_free_DEFINED__
4232 #include <inc/win2003/vss.h>
4233 int main(void) { return VSS_CTX_BACKUP; }
4234 EOF
4235   if compile_prog "$vss_win32_include" "" ; then
4236     guest_agent_with_vss="yes"
4237     QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
4238     libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++ -Wl,--enable-stdcall-fixup $libs_qga"
4239     qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb"
4240   else
4241     if test "$vss_win32_sdk" != "" ; then
4242       echo "ERROR: Please download and install Microsoft VSS SDK:"
4243       echo "ERROR:   http://www.microsoft.com/en-us/download/details.aspx?id=23490"
4244       echo "ERROR: On POSIX-systems, you can extract the SDK headers by:"
4245       echo "ERROR:   scripts/extract-vsssdk-headers setup.exe"
4246       echo "ERROR: The headers are extracted in the directory \`inc'."
4247       feature_not_found "VSS support"
4248     fi
4249     guest_agent_with_vss="no"
4250   fi
4251 fi
4252
4253 ##########################################
4254 # lookup Windows platform SDK (if not specified)
4255 # The SDK is needed only to build .tlb (type library) file of guest agent
4256 # VSS provider from the source. It is usually unnecessary because the
4257 # pre-compiled .tlb file is included.
4258
4259 if test "$mingw32" = "yes" -a "$guest_agent" != "no" -a "$guest_agent_with_vss" = "yes" ; then
4260   if test -z "$win_sdk"; then
4261     programfiles="$PROGRAMFILES"
4262     test -n "$PROGRAMW6432" && programfiles="$PROGRAMW6432"
4263     if test -n "$programfiles"; then
4264       win_sdk=$(ls -d "$programfiles/Microsoft SDKs/Windows/v"* | tail -1) 2>/dev/null
4265     else
4266       feature_not_found "Windows SDK"
4267     fi
4268   elif test "$win_sdk" = "no"; then
4269     win_sdk=""
4270   fi
4271 fi
4272
4273 ##########################################
4274 # check if mingw environment provides a recent ntddscsi.h
4275 if test "$mingw32" = "yes" -a "$guest_agent" != "no"; then
4276   cat > $TMPC << EOF
4277 #include <windows.h>
4278 #include <ntddscsi.h>
4279 int main(void) {
4280 #if !defined(IOCTL_SCSI_GET_ADDRESS)
4281 #error Missing required ioctl definitions
4282 #endif
4283   SCSI_ADDRESS addr = { .Lun = 0, .TargetId = 0, .PathId = 0 };
4284   return addr.Lun;
4285 }
4286 EOF
4287   if compile_prog "" "" ; then
4288     guest_agent_ntddscsi=yes
4289     libs_qga="-lsetupapi $libs_qga"
4290   fi
4291 fi
4292
4293 ##########################################
4294 # virgl renderer probe
4295
4296 if test "$virglrenderer" != "no" ; then
4297   cat > $TMPC << EOF
4298 #include <virglrenderer.h>
4299 int main(void) { virgl_renderer_poll(); return 0; }
4300 EOF
4301   virgl_cflags=$($pkg_config --cflags virglrenderer 2>/dev/null)
4302   virgl_libs=$($pkg_config --libs virglrenderer 2>/dev/null)
4303   if $pkg_config virglrenderer >/dev/null 2>&1 && \
4304      compile_prog "$virgl_cflags" "$virgl_libs" ; then
4305     virglrenderer="yes"
4306   else
4307     if test "$virglrenderer" = "yes" ; then
4308       feature_not_found "virglrenderer"
4309     fi
4310     virglrenderer="no"
4311   fi
4312 fi
4313
4314 ##########################################
4315 # check if we have fdatasync
4316
4317 fdatasync=no
4318 cat > $TMPC << EOF
4319 #include <unistd.h>
4320 int main(void) {
4321 #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
4322 return fdatasync(0);
4323 #else
4324 #error Not supported
4325 #endif
4326 }
4327 EOF
4328 if compile_prog "" "" ; then
4329     fdatasync=yes
4330 fi
4331
4332 ##########################################
4333 # check if we have madvise
4334
4335 madvise=no
4336 cat > $TMPC << EOF
4337 #include <sys/types.h>
4338 #include <sys/mman.h>
4339 #include <stddef.h>
4340 int main(void) { return madvise(NULL, 0, MADV_DONTNEED); }
4341 EOF
4342 if compile_prog "" "" ; then
4343     madvise=yes
4344 fi
4345
4346 ##########################################
4347 # check if we have posix_madvise
4348
4349 posix_madvise=no
4350 cat > $TMPC << EOF
4351 #include <sys/mman.h>
4352 #include <stddef.h>
4353 int main(void) { return posix_madvise(NULL, 0, POSIX_MADV_DONTNEED); }
4354 EOF
4355 if compile_prog "" "" ; then
4356     posix_madvise=yes
4357 fi
4358
4359 ##########################################
4360 # check if we have posix_syslog
4361
4362 posix_syslog=no
4363 cat > $TMPC << EOF
4364 #include <syslog.h>
4365 int main(void) { openlog("qemu", LOG_PID, LOG_DAEMON); syslog(LOG_INFO, "configure"); return 0; }
4366 EOF
4367 if compile_prog "" "" ; then
4368     posix_syslog=yes
4369 fi
4370
4371 ##########################################
4372 # check if trace backend exists
4373
4374 $python "$source_path/scripts/tracetool.py" "--backends=$trace_backends" --check-backends  > /dev/null 2> /dev/null
4375 if test "$?" -ne 0 ; then
4376   error_exit "invalid trace backends" \
4377       "Please choose supported trace backends."
4378 fi
4379
4380 ##########################################
4381 # For 'ust' backend, test if ust headers are present
4382 if have_backend "ust"; then
4383   cat > $TMPC << EOF
4384 #include <lttng/tracepoint.h>
4385 int main(void) { return 0; }
4386 EOF
4387   if compile_prog "" "-Wl,--no-as-needed -ldl" ; then
4388     if $pkg_config lttng-ust --exists; then
4389       lttng_ust_libs=$($pkg_config --libs lttng-ust)
4390     else
4391       lttng_ust_libs="-llttng-ust -ldl"
4392     fi
4393     if $pkg_config liburcu-bp --exists; then
4394       urcu_bp_libs=$($pkg_config --libs liburcu-bp)
4395     else
4396       urcu_bp_libs="-lurcu-bp"
4397     fi
4398
4399     LIBS="$lttng_ust_libs $urcu_bp_libs $LIBS"
4400     libs_qga="$lttng_ust_libs $urcu_bp_libs $libs_qga"
4401   else
4402     error_exit "Trace backend 'ust' missing lttng-ust header files"
4403   fi
4404 fi
4405
4406 ##########################################
4407 # For 'dtrace' backend, test if 'dtrace' command is present
4408 if have_backend "dtrace"; then
4409   if ! has 'dtrace' ; then
4410     error_exit "dtrace command is not found in PATH $PATH"
4411   fi
4412   trace_backend_stap="no"
4413   if has 'stap' ; then
4414     trace_backend_stap="yes"
4415   fi
4416 fi
4417
4418 ##########################################
4419 # check and set a backend for coroutine
4420
4421 # We prefer ucontext, but it's not always possible. The fallback
4422 # is sigcontext. On Windows the only valid backend is the Windows
4423 # specific one.
4424
4425 ucontext_works=no
4426 if test "$darwin" != "yes"; then
4427   cat > $TMPC << EOF
4428 #include <ucontext.h>
4429 #ifdef __stub_makecontext
4430 #error Ignoring glibc stub makecontext which will always fail
4431 #endif
4432 int main(void) { makecontext(0, 0, 0); return 0; }
4433 EOF
4434   if compile_prog "" "" ; then
4435     ucontext_works=yes
4436   fi
4437 fi
4438
4439 if test "$coroutine" = ""; then
4440   if test "$mingw32" = "yes"; then
4441     coroutine=win32
4442   elif test "$ucontext_works" = "yes"; then
4443     coroutine=ucontext
4444   else
4445     coroutine=sigaltstack
4446   fi
4447 else
4448   case $coroutine in
4449   windows)
4450     if test "$mingw32" != "yes"; then
4451       error_exit "'windows' coroutine backend only valid for Windows"
4452     fi
4453     # Unfortunately the user visible backend name doesn't match the
4454     # coroutine-*.c filename for this case, so we have to adjust it here.
4455     coroutine=win32
4456     ;;
4457   ucontext)
4458     if test "$ucontext_works" != "yes"; then
4459       feature_not_found "ucontext"
4460     fi
4461     ;;
4462   sigaltstack)
4463     if test "$mingw32" = "yes"; then
4464       error_exit "only the 'windows' coroutine backend is valid for Windows"
4465     fi
4466     ;;
4467   *)
4468     error_exit "unknown coroutine backend $coroutine"
4469     ;;
4470   esac
4471 fi
4472
4473 if test "$coroutine_pool" = ""; then
4474   coroutine_pool=yes
4475 fi
4476
4477 if test "$debug_stack_usage" = "yes"; then
4478   if test "$cpu" = "ia64" -o "$cpu" = "hppa"; then
4479     error_exit "stack usage debugging is not supported for $cpu"
4480   fi
4481   if test "$coroutine_pool" = "yes"; then
4482     echo "WARN: disabling coroutine pool for stack usage debugging"
4483     coroutine_pool=no
4484   fi
4485 fi
4486
4487
4488 ##########################################
4489 # check if we have open_by_handle_at
4490
4491 open_by_handle_at=no
4492 cat > $TMPC << EOF
4493 #include <fcntl.h>
4494 #if !defined(AT_EMPTY_PATH)
4495 # error missing definition
4496 #else
4497 int main(void) { struct file_handle fh; return open_by_handle_at(0, &fh, 0); }
4498 #endif
4499 EOF
4500 if compile_prog "" "" ; then
4501     open_by_handle_at=yes
4502 fi
4503
4504 ########################################
4505 # check if we have linux/magic.h
4506
4507 linux_magic_h=no
4508 cat > $TMPC << EOF
4509 #include <linux/magic.h>
4510 int main(void) {
4511   return 0;
4512 }
4513 EOF
4514 if compile_prog "" "" ; then
4515     linux_magic_h=yes
4516 fi
4517
4518 ########################################
4519 # check whether we can disable warning option with a pragma (this is needed
4520 # to silence warnings in the headers of some versions of external libraries).
4521 # This test has to be compiled with -Werror as otherwise an unknown pragma is
4522 # only a warning.
4523 #
4524 # If we can't selectively disable warning in the code, disable -Werror so that
4525 # the build doesn't fail anyway.
4526
4527 pragma_disable_unused_but_set=no
4528 cat > $TMPC << EOF
4529 #pragma GCC diagnostic push
4530 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
4531 #pragma GCC diagnostic ignored "-Wstrict-prototypes"
4532 #pragma GCC diagnostic pop
4533
4534 int main(void) {
4535     return 0;
4536 }
4537 EOF
4538 if compile_prog "-Werror" "" ; then
4539     pragma_diagnostic_available=yes
4540 else
4541     werror=no
4542 fi
4543
4544 ########################################
4545 # check if we have valgrind/valgrind.h
4546
4547 valgrind_h=no
4548 cat > $TMPC << EOF
4549 #include <valgrind/valgrind.h>
4550 int main(void) {
4551   return 0;
4552 }
4553 EOF
4554 if compile_prog "" "" ; then
4555     valgrind_h=yes
4556 fi
4557
4558 ########################################
4559 # check if environ is declared
4560
4561 has_environ=no
4562 cat > $TMPC << EOF
4563 #include <unistd.h>
4564 int main(void) {
4565     environ = 0;
4566     return 0;
4567 }
4568 EOF
4569 if compile_prog "" "" ; then
4570     has_environ=yes
4571 fi
4572
4573 ########################################
4574 # check if cpuid.h is usable.
4575
4576 cpuid_h=no
4577 cat > $TMPC << EOF
4578 #include <cpuid.h>
4579 int main(void) {
4580     unsigned a, b, c, d;
4581     int max = __get_cpuid_max(0, 0);
4582
4583     if (max >= 1) {
4584         __cpuid(1, a, b, c, d);
4585     }
4586
4587     if (max >= 7) {
4588         __cpuid_count(7, 0, a, b, c, d);
4589     }
4590
4591     return 0;
4592 }
4593 EOF
4594 if compile_prog "" "" ; then
4595     cpuid_h=yes
4596 fi
4597
4598 ########################################
4599 # check if __[u]int128_t is usable.
4600
4601 int128=no
4602 cat > $TMPC << EOF
4603 #if defined(__clang_major__) && defined(__clang_minor__)
4604 # if ((__clang_major__ < 3) || (__clang_major__ == 3) && (__clang_minor__ < 2))
4605 #  error __int128_t does not work in CLANG before 3.2
4606 # endif
4607 #endif
4608 __int128_t a;
4609 __uint128_t b;
4610 int main (void) {
4611   a = a + b;
4612   b = a * b;
4613   a = a * a;
4614   return 0;
4615 }
4616 EOF
4617 if compile_prog "" "" ; then
4618     int128=yes
4619 fi
4620
4621 #########################################
4622 # See if 128-bit atomic operations are supported.
4623
4624 atomic128=no
4625 if test "$int128" = "yes"; then
4626   cat > $TMPC << EOF
4627 int main(void)
4628 {
4629   unsigned __int128 x = 0, y = 0;
4630   y = __atomic_load_16(&x, 0);
4631   __atomic_store_16(&x, y, 0);
4632   __atomic_compare_exchange_16(&x, &y, x, 0, 0, 0);
4633   return 0;
4634 }
4635 EOF
4636   if compile_prog "" "" ; then
4637     atomic128=yes
4638   fi
4639 fi
4640
4641 #########################################
4642 # See if 64-bit atomic operations are supported.
4643 # Note that without __atomic builtins, we can only
4644 # assume atomic loads/stores max at pointer size.
4645
4646 cat > $TMPC << EOF
4647 #include <stdint.h>
4648 int main(void)
4649 {
4650   uint64_t x = 0, y = 0;
4651 #ifdef __ATOMIC_RELAXED
4652   y = __atomic_load_8(&x, 0);
4653   __atomic_store_8(&x, y, 0);
4654   __atomic_compare_exchange_8(&x, &y, x, 0, 0, 0);
4655   __atomic_exchange_8(&x, y, 0);
4656   __atomic_fetch_add_8(&x, y, 0);
4657 #else
4658   typedef char is_host64[sizeof(void *) >= sizeof(uint64_t) ? 1 : -1];
4659   __sync_lock_test_and_set(&x, y);
4660   __sync_val_compare_and_swap(&x, y, 0);
4661   __sync_fetch_and_add(&x, y);
4662 #endif
4663   return 0;
4664 }
4665 EOF
4666 if compile_prog "" "" ; then
4667   atomic64=yes
4668 fi
4669
4670 ########################################
4671 # check if getauxval is available.
4672
4673 getauxval=no
4674 cat > $TMPC << EOF
4675 #include <sys/auxv.h>
4676 int main(void) {
4677   return getauxval(AT_HWCAP) == 0;
4678 }
4679 EOF
4680 if compile_prog "" "" ; then
4681     getauxval=yes
4682 fi
4683
4684 ########################################
4685 # check if ccache is interfering with
4686 # semantic analysis of macros
4687
4688 unset CCACHE_CPP2
4689 ccache_cpp2=no
4690 cat > $TMPC << EOF
4691 static const int Z = 1;
4692 #define fn() ({ Z; })
4693 #define TAUT(X) ((X) == Z)
4694 #define PAREN(X, Y) (X == Y)
4695 #define ID(X) (X)
4696 int main(int argc, char *argv[])
4697 {
4698     int x = 0, y = 0;
4699     x = ID(x);
4700     x = fn();
4701     fn();
4702     if (PAREN(x, y)) return 0;
4703     if (TAUT(Z)) return 0;
4704     return 0;
4705 }
4706 EOF
4707
4708 if ! compile_object "-Werror"; then
4709     ccache_cpp2=yes
4710 fi
4711
4712 #################################################
4713 # clang does not support glibc + FORTIFY_SOURCE.
4714
4715 if test "$fortify_source" != "no"; then
4716   if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
4717     fortify_source="no";
4718   elif test -n "$cxx" &&
4719        echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
4720     fortify_source="no";
4721   else
4722     fortify_source="yes"
4723   fi
4724 fi
4725
4726 ##########################################
4727 # check if struct fsxattr is available via linux/fs.h
4728
4729 have_fsxattr=no
4730 cat > $TMPC << EOF
4731 #include <linux/fs.h>
4732 struct fsxattr foo;
4733 int main(void) {
4734   return 0;
4735 }
4736 EOF
4737 if compile_prog "" "" ; then
4738     have_fsxattr=yes
4739 fi
4740
4741 ##########################################
4742 # check if rtnetlink.h exists and is useful
4743 have_rtnetlink=no
4744 cat > $TMPC << EOF
4745 #include <linux/rtnetlink.h>
4746 int main(void) {
4747   return IFLA_PROTO_DOWN;
4748 }
4749 EOF
4750 if compile_prog "" "" ; then
4751     have_rtnetlink=yes
4752 fi
4753
4754 ##########################################
4755 # check for usable AF_VSOCK environment
4756 have_af_vsock=no
4757 cat > $TMPC << EOF
4758 #include <errno.h>
4759 #include <sys/types.h>
4760 #include <sys/socket.h>
4761 #if !defined(AF_VSOCK)
4762 # error missing AF_VSOCK flag
4763 #endif
4764 #include <linux/vm_sockets.h>
4765 int main(void) {
4766     int sock, ret;
4767     struct sockaddr_vm svm;
4768     socklen_t len = sizeof(svm);
4769     sock = socket(AF_VSOCK, SOCK_STREAM, 0);
4770     ret = getpeername(sock, (struct sockaddr *)&svm, &len);
4771     if ((ret == -1) && (errno == ENOTCONN)) {
4772         return 0;
4773     }
4774     return -1;
4775 }
4776 EOF
4777 if compile_prog "" "" ; then
4778     have_af_vsock=yes
4779 fi
4780
4781 #################################################
4782 # Sparc implicitly links with --relax, which is
4783 # incompatible with -r, so --no-relax should be
4784 # given. It does no harm to give it on other
4785 # platforms too.
4786
4787 # Note: the prototype is needed since QEMU_CFLAGS
4788 #       contains -Wmissing-prototypes
4789 cat > $TMPC << EOF
4790 extern int foo(void);
4791 int foo(void) { return 0; }
4792 EOF
4793 if ! compile_object ""; then
4794   error_exit "Failed to compile object file for LD_REL_FLAGS test"
4795 fi
4796 for i in '-Wl,-r -Wl,--no-relax' -Wl,-r -r; do
4797   if do_cc -nostdlib $i -o $TMPMO $TMPO; then
4798     LD_REL_FLAGS=$i
4799     break
4800   fi
4801 done
4802 if test "$modules" = "yes" && test "$LD_REL_FLAGS" = ""; then
4803   feature_not_found "modules" "Cannot find how to build relocatable objects"
4804 fi
4805
4806 ##########################################
4807 # check for sysmacros.h
4808
4809 have_sysmacros=no
4810 cat > $TMPC << EOF
4811 #include <sys/sysmacros.h>
4812 int main(void) {
4813     return makedev(0, 0);
4814 }
4815 EOF
4816 if compile_prog "" "" ; then
4817     have_sysmacros=yes
4818 fi
4819
4820 ##########################################
4821 # Veritas HyperScale block driver VxHS
4822 # Check if libvxhs is installed
4823
4824 if test "$vxhs" != "no" ; then
4825   cat > $TMPC <<EOF
4826 #include <stdint.h>
4827 #include <qnio/qnio_api.h>
4828
4829 void *vxhs_callback;
4830
4831 int main(void) {
4832     iio_init(QNIO_VERSION, vxhs_callback);
4833     return 0;
4834 }
4835 EOF
4836   vxhs_libs="-lvxhs -lssl"
4837   if compile_prog "" "$vxhs_libs" ; then
4838     vxhs=yes
4839   else
4840     if test "$vxhs" = "yes" ; then
4841       feature_not_found "vxhs block device" "Install libvxhs See github"
4842     fi
4843     vxhs=no
4844   fi
4845 fi
4846
4847 ##########################################
4848 # check for _Static_assert()
4849
4850 have_static_assert=no
4851 cat > $TMPC << EOF
4852 _Static_assert(1, "success");
4853 int main(void) {
4854     return 0;
4855 }
4856 EOF
4857 if compile_prog "" "" ; then
4858     have_static_assert=yes
4859 fi
4860
4861 ##########################################
4862 # End of CC checks
4863 # After here, no more $cc or $ld runs
4864
4865 if test "$gcov" = "yes" ; then
4866   CFLAGS="-fprofile-arcs -ftest-coverage -g $CFLAGS"
4867   LDFLAGS="-fprofile-arcs -ftest-coverage $LDFLAGS"
4868 elif test "$fortify_source" = "yes" ; then
4869   CFLAGS="-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $CFLAGS"
4870 elif test "$debug" = "no"; then
4871   CFLAGS="-O2 $CFLAGS"
4872 fi
4873
4874 ##########################################
4875 # Do we have libnfs
4876 if test "$libnfs" != "no" ; then
4877   if $pkg_config --atleast-version=1.9.3 libnfs; then
4878     libnfs="yes"
4879     libnfs_libs=$($pkg_config --libs libnfs)
4880   else
4881     if test "$libnfs" = "yes" ; then
4882       feature_not_found "libnfs" "Install libnfs devel >= 1.9.3"
4883     fi
4884     libnfs="no"
4885   fi
4886 fi
4887
4888 # Now we've finished running tests it's OK to add -Werror to the compiler flags
4889 if test "$werror" = "yes"; then
4890     QEMU_CFLAGS="-Werror $QEMU_CFLAGS"
4891 fi
4892
4893 if test "$solaris" = "no" ; then
4894     if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
4895         LDFLAGS="-Wl,--warn-common $LDFLAGS"
4896     fi
4897 fi
4898
4899 # test if pod2man has --utf8 option
4900 if pod2man --help | grep -q utf8; then
4901     POD2MAN="pod2man --utf8"
4902 else
4903     POD2MAN="pod2man"
4904 fi
4905
4906 # Use ASLR, no-SEH and DEP if available
4907 if test "$mingw32" = "yes" ; then
4908     for flag in --dynamicbase --no-seh --nxcompat; do
4909         if $ld --help 2>/dev/null | grep ".$flag" >/dev/null 2>/dev/null ; then
4910             LDFLAGS="-Wl,$flag $LDFLAGS"
4911         fi
4912     done
4913 fi
4914
4915 qemu_confdir=$sysconfdir$confsuffix
4916 qemu_moddir=$libdir$confsuffix
4917 qemu_datadir=$datadir$confsuffix
4918 qemu_localedir="$datadir/locale"
4919
4920 tools=""
4921 if test "$want_tools" = "yes" ; then
4922   tools="qemu-img\$(EXESUF) qemu-io\$(EXESUF) $tools"
4923   if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then
4924     tools="qemu-nbd\$(EXESUF) $tools"
4925     tools="ivshmem-client\$(EXESUF) ivshmem-server\$(EXESUF) $tools"
4926   fi
4927 fi
4928 if test "$softmmu" = yes ; then
4929   if test "$virtfs" != no ; then
4930     if test "$cap" = yes && test "$linux" = yes && test "$attr" = yes ; then
4931       virtfs=yes
4932       tools="$tools fsdev/virtfs-proxy-helper\$(EXESUF)"
4933     else
4934       if test "$virtfs" = yes; then
4935         error_exit "VirtFS is supported only on Linux and requires libcap devel and libattr devel"
4936       fi
4937       virtfs=no
4938     fi
4939   fi
4940 fi
4941
4942 # Probe for guest agent support/options
4943
4944 if [ "$guest_agent" != "no" ]; then
4945   if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" -o "$mingw32" = "yes" ] ; then
4946       tools="qemu-ga $tools"
4947       guest_agent=yes
4948   elif [ "$guest_agent" != yes ]; then
4949       guest_agent=no
4950   else
4951       error_exit "Guest agent is not supported on this platform"
4952   fi
4953 fi
4954
4955 # Guest agent Window MSI  package
4956
4957 if test "$guest_agent" != yes; then
4958   if test "$guest_agent_msi" = yes; then
4959     error_exit "MSI guest agent package requires guest agent enabled"
4960   fi
4961   guest_agent_msi=no
4962 elif test "$mingw32" != "yes"; then
4963   if test "$guest_agent_msi" = "yes"; then
4964     error_exit "MSI guest agent package is available only for MinGW Windows cross-compilation"
4965   fi
4966   guest_agent_msi=no
4967 elif ! has wixl; then
4968   if test "$guest_agent_msi" = "yes"; then
4969     error_exit "MSI guest agent package requires wixl tool installed ( usually from msitools package )"
4970   fi
4971   guest_agent_msi=no
4972 else
4973   # we support qemu-ga, mingw32, and wixl: default to MSI enabled if it wasn't
4974   # disabled explicitly
4975   if test "$guest_agent_msi" != "no"; then
4976     guest_agent_msi=yes
4977   fi
4978 fi
4979
4980 if test "$guest_agent_msi" = "yes"; then
4981   if test "$guest_agent_with_vss" = "yes"; then
4982     QEMU_GA_MSI_WITH_VSS="-D InstallVss"
4983   fi
4984
4985   if test "$QEMU_GA_MANUFACTURER" = ""; then
4986     QEMU_GA_MANUFACTURER=QEMU
4987   fi
4988
4989   if test "$QEMU_GA_DISTRO" = ""; then
4990     QEMU_GA_DISTRO=Linux
4991   fi
4992
4993   if test "$QEMU_GA_VERSION" = ""; then
4994       QEMU_GA_VERSION=$(cat $source_path/VERSION)
4995   fi
4996
4997   QEMU_GA_MSI_MINGW_DLL_PATH="-D Mingw_dlls=$($pkg_config --variable=prefix glib-2.0)/bin"
4998
4999   case "$cpu" in
5000   x86_64)
5001     QEMU_GA_MSI_ARCH="-a x64 -D Arch=64"
5002     ;;
5003   i386)
5004     QEMU_GA_MSI_ARCH="-D Arch=32"
5005     ;;
5006   *)
5007     error_exit "CPU $cpu not supported for building installation package"
5008     ;;
5009   esac
5010 fi
5011
5012 # Mac OS X ships with a broken assembler
5013 roms=
5014 if test \( "$cpu" = "i386" -o "$cpu" = "x86_64" \) -a \
5015         "$targetos" != "Darwin" -a "$targetos" != "SunOS" -a \
5016         "$softmmu" = yes ; then
5017     # Different host OS linkers have different ideas about the name of the ELF
5018     # emulation. Linux and OpenBSD use 'elf_i386'; FreeBSD uses the _fbsd
5019     # variant; and Windows uses i386pe.
5020     for emu in elf_i386 elf_i386_fbsd i386pe; do
5021         if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
5022             ld_i386_emulation="$emu"
5023             roms="optionrom"
5024             break
5025         fi
5026     done
5027 fi
5028 if test "$cpu" = "ppc64" -a "$targetos" != "Darwin" ; then
5029   roms="$roms spapr-rtas"
5030 fi
5031
5032 if test "$cpu" = "s390x" ; then
5033   roms="$roms s390-ccw"
5034 fi
5035
5036 # Probe for the need for relocating the user-only binary.
5037 if ( [ "$linux_user" = yes ] || [ "$bsd_user" = yes ] ) && [ "$pie" = no ]; then
5038   textseg_addr=
5039   case "$cpu" in
5040     arm | i386 | ppc* | s390* | sparc* | x86_64 | x32)
5041       # ??? Rationale for choosing this address
5042       textseg_addr=0x60000000
5043       ;;
5044     mips)
5045       # A 256M aligned address, high in the address space, with enough
5046       # room for the code_gen_buffer above it before the stack.
5047       textseg_addr=0x60000000
5048       ;;
5049   esac
5050   if [ -n "$textseg_addr" ]; then
5051     cat > $TMPC <<EOF
5052     int main(void) { return 0; }
5053 EOF
5054     textseg_ldflags="-Wl,-Ttext-segment=$textseg_addr"
5055     if ! compile_prog "" "$textseg_ldflags"; then
5056       # In case ld does not support -Ttext-segment, edit the default linker
5057       # script via sed to set the .text start addr.  This is needed on FreeBSD
5058       # at least.
5059       if ! $ld --verbose >/dev/null 2>&1; then
5060         error_exit \
5061             "We need to link the QEMU user mode binaries at a" \
5062             "specific text address. Unfortunately your linker" \
5063             "doesn't support either the -Ttext-segment option or" \
5064             "printing the default linker script with --verbose." \
5065             "If you don't want the user mode binaries, pass the" \
5066             "--disable-user option to configure."
5067       fi
5068
5069       $ld --verbose | sed \
5070         -e '1,/==================================================/d' \
5071         -e '/==================================================/,$d' \
5072         -e "s/[.] = [0-9a-fx]* [+] SIZEOF_HEADERS/. = $textseg_addr + SIZEOF_HEADERS/" \
5073         -e "s/__executable_start = [0-9a-fx]*/__executable_start = $textseg_addr/" > config-host.ld
5074       textseg_ldflags="-Wl,-T../config-host.ld"
5075     fi
5076   fi
5077 fi
5078
5079 echo_version() {
5080     if test "$1" = "yes" ; then
5081         echo "($2)"
5082     fi
5083 }
5084
5085 # prepend pixman and ftd flags after all config tests are done
5086 QEMU_CFLAGS="$pixman_cflags $fdt_cflags $QEMU_CFLAGS"
5087 libs_softmmu="$pixman_libs $libs_softmmu"
5088
5089 echo "Install prefix    $prefix"
5090 echo "BIOS directory    $(eval echo $qemu_datadir)"
5091 echo "binary directory  $(eval echo $bindir)"
5092 echo "library directory $(eval echo $libdir)"
5093 echo "module directory  $(eval echo $qemu_moddir)"
5094 echo "libexec directory $(eval echo $libexecdir)"
5095 echo "include directory $(eval echo $includedir)"
5096 echo "config directory  $(eval echo $sysconfdir)"
5097 if test "$mingw32" = "no" ; then
5098 echo "local state directory   $(eval echo $local_statedir)"
5099 echo "Manual directory  $(eval echo $mandir)"
5100 echo "ELF interp prefix $interp_prefix"
5101 else
5102 echo "local state directory   queried at runtime"
5103 echo "Windows SDK       $win_sdk"
5104 fi
5105 echo "Source path       $source_path"
5106 echo "C compiler        $cc"
5107 echo "Host C compiler   $host_cc"
5108 echo "C++ compiler      $cxx"
5109 echo "Objective-C compiler $objcc"
5110 echo "ARFLAGS           $ARFLAGS"
5111 echo "CFLAGS            $CFLAGS"
5112 echo "QEMU_CFLAGS       $QEMU_CFLAGS"
5113 echo "LDFLAGS           $LDFLAGS"
5114 echo "make              $make"
5115 echo "install           $install"
5116 echo "python            $python"
5117 if test "$slirp" = "yes" ; then
5118     echo "smbd              $smbd"
5119 fi
5120 echo "module support    $modules"
5121 echo "host CPU          $cpu"
5122 echo "host big endian   $bigendian"
5123 echo "target list       $target_list"
5124 echo "tcg debug enabled $debug_tcg"
5125 echo "gprof enabled     $gprof"
5126 echo "sparse enabled    $sparse"
5127 echo "strip binaries    $strip_opt"
5128 echo "profiler          $profiler"
5129 echo "static build      $static"
5130 if test "$darwin" = "yes" ; then
5131     echo "Cocoa support     $cocoa"
5132 fi
5133 echo "pixman            $pixman"
5134 echo "SDL support       $sdl $(echo_version $sdl $sdlversion)"
5135 echo "GTK support       $gtk $(echo_version $gtk $gtk_version)"
5136 echo "GTK GL support    $gtk_gl"
5137 echo "VTE support       $vte $(echo_version $vte $vteversion)"
5138 echo "TLS priority      $tls_priority"
5139 echo "GNUTLS support    $gnutls"
5140 echo "GNUTLS rnd        $gnutls_rnd"
5141 echo "libgcrypt         $gcrypt"
5142 echo "libgcrypt kdf     $gcrypt_kdf"
5143 echo "nettle            $nettle $(echo_version $nettle $nettle_version)"
5144 echo "nettle kdf        $nettle_kdf"
5145 echo "libtasn1          $tasn1"
5146 echo "curses support    $curses"
5147 echo "virgl support     $virglrenderer"
5148 echo "curl support      $curl"
5149 echo "mingw32 support   $mingw32"
5150 echo "Audio drivers     $audio_drv_list"
5151 echo "Block whitelist (rw) $block_drv_rw_whitelist"
5152 echo "Block whitelist (ro) $block_drv_ro_whitelist"
5153 echo "VirtFS support    $virtfs"
5154 echo "VNC support       $vnc"
5155 if test "$vnc" = "yes" ; then
5156     echo "VNC SASL support  $vnc_sasl"
5157     echo "VNC JPEG support  $vnc_jpeg"
5158     echo "VNC PNG support   $vnc_png"
5159 fi
5160 if test -n "$sparc_cpu"; then
5161     echo "Target Sparc Arch $sparc_cpu"
5162 fi
5163 echo "xen support       $xen"
5164 if test "$xen" = "yes" ; then
5165   echo "xen ctrl version  $xen_ctrl_version"
5166   echo "pv dom build      $xen_pv_domain_build"
5167 fi
5168 echo "brlapi support    $brlapi"
5169 echo "bluez  support    $bluez"
5170 echo "Documentation     $docs"
5171 echo "PIE               $pie"
5172 echo "vde support       $vde"
5173 echo "netmap support    $netmap"
5174 echo "Linux AIO support $linux_aio"
5175 echo "ATTR/XATTR support $attr"
5176 echo "Install blobs     $blobs"
5177 echo "KVM support       $kvm"
5178 echo "HAX support       $hax"
5179 echo "RDMA support      $rdma"
5180 echo "TCG interpreter   $tcg_interpreter"
5181 echo "fdt support       $fdt"
5182 echo "preadv support    $preadv"
5183 echo "fdatasync         $fdatasync"
5184 echo "madvise           $madvise"
5185 echo "posix_madvise     $posix_madvise"
5186 echo "libcap-ng support $cap_ng"
5187 echo "vhost-net support $vhost_net"
5188 echo "vhost-scsi support $vhost_scsi"
5189 echo "vhost-vsock support $vhost_vsock"
5190 echo "Trace backends    $trace_backends"
5191 if have_backend "simple"; then
5192 echo "Trace output file $trace_file-<pid>"
5193 fi
5194 echo "spice support     $spice $(echo_version $spice $spice_protocol_version/$spice_server_version)"
5195 echo "rbd support       $rbd"
5196 echo "xfsctl support    $xfs"
5197 echo "smartcard support $smartcard"
5198 echo "libusb            $libusb"
5199 echo "usb net redir     $usb_redir"
5200 echo "OpenGL support    $opengl"
5201 echo "OpenGL dmabufs    $opengl_dmabuf"
5202 echo "libiscsi support  $libiscsi"
5203 echo "libnfs support    $libnfs"
5204 echo "build guest agent $guest_agent"
5205 echo "QGA VSS support   $guest_agent_with_vss"
5206 echo "QGA w32 disk info $guest_agent_ntddscsi"
5207 echo "QGA MSI support   $guest_agent_msi"
5208 echo "seccomp support   $seccomp"
5209 echo "coroutine backend $coroutine"
5210 echo "coroutine pool    $coroutine_pool"
5211 echo "debug stack usage $debug_stack_usage"
5212 echo "GlusterFS support $glusterfs"
5213 echo "gcov              $gcov_tool"
5214 echo "gcov enabled      $gcov"
5215 echo "TPM support       $tpm"
5216 echo "libssh2 support   $libssh2"
5217 echo "TPM passthrough   $tpm_passthrough"
5218 echo "QOM debugging     $qom_cast_debug"
5219 echo "lzo support       $lzo"
5220 echo "snappy support    $snappy"
5221 echo "bzip2 support     $bzip2"
5222 echo "NUMA host support $numa"
5223 echo "tcmalloc support  $tcmalloc"
5224 echo "jemalloc support  $jemalloc"
5225 echo "avx2 optimization $avx2_opt"
5226 echo "replication support $replication"
5227 echo "VxHS block device $vxhs"
5228
5229 if test "$sdl_too_old" = "yes"; then
5230 echo "-> Your SDL version is too old - please upgrade to have SDL support"
5231 fi
5232
5233 if test "$supported_cpu" = "no"; then
5234     echo
5235     echo "WARNING: SUPPORT FOR THIS HOST CPU WILL GO AWAY IN FUTURE RELEASES!"
5236     echo
5237     echo "CPU host architecture $cpu support is not currently maintained."
5238     echo "The QEMU project intends to remove support for this host CPU in"
5239     echo "a future release if nobody volunteers to maintain it and to"
5240     echo "provide a build host for our continuous integration setup."
5241     echo "configure has succeeded and you can continue to build, but"
5242     echo "if you care about QEMU on this platform you should contact"
5243     echo "us upstream at qemu-devel@nongnu.org."
5244 fi
5245
5246 if test "$supported_os" = "no"; then
5247     echo
5248     echo "WARNING: SUPPORT FOR THIS HOST OS WILL GO AWAY IN FUTURE RELEASES!"
5249     echo
5250     echo "Host OS $targetos support is not currently maintained."
5251     echo "The QEMU project intends to remove support for this host OS in"
5252     echo "a future release if nobody volunteers to maintain it and to"
5253     echo "provide a build host for our continuous integration setup."
5254     echo "configure has succeeded and you can continue to build, but"
5255     echo "if you care about QEMU on this platform you should contact"
5256     echo "us upstream at qemu-devel@nongnu.org."
5257 fi
5258
5259 config_host_mak="config-host.mak"
5260
5261 echo "# Automatically generated by configure - do not modify" >config-all-disas.mak
5262
5263 echo "# Automatically generated by configure - do not modify" > $config_host_mak
5264 echo >> $config_host_mak
5265
5266 echo all: >> $config_host_mak
5267 echo "prefix=$prefix" >> $config_host_mak
5268 echo "bindir=$bindir" >> $config_host_mak
5269 echo "libdir=$libdir" >> $config_host_mak
5270 echo "libexecdir=$libexecdir" >> $config_host_mak
5271 echo "includedir=$includedir" >> $config_host_mak
5272 echo "mandir=$mandir" >> $config_host_mak
5273 echo "sysconfdir=$sysconfdir" >> $config_host_mak
5274 echo "qemu_confdir=$qemu_confdir" >> $config_host_mak
5275 echo "qemu_datadir=$qemu_datadir" >> $config_host_mak
5276 echo "qemu_docdir=$qemu_docdir" >> $config_host_mak
5277 echo "qemu_moddir=$qemu_moddir" >> $config_host_mak
5278 if test "$mingw32" = "no" ; then
5279   echo "qemu_localstatedir=$local_statedir" >> $config_host_mak
5280 fi
5281 echo "qemu_helperdir=$libexecdir" >> $config_host_mak
5282 echo "extra_cflags=$EXTRA_CFLAGS" >> $config_host_mak
5283 echo "extra_ldflags=$EXTRA_LDFLAGS" >> $config_host_mak
5284 echo "qemu_localedir=$qemu_localedir" >> $config_host_mak
5285 echo "libs_softmmu=$libs_softmmu" >> $config_host_mak
5286
5287 echo "ARCH=$ARCH" >> $config_host_mak
5288
5289 if test "$debug_tcg" = "yes" ; then
5290   echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
5291 fi
5292 if test "$strip_opt" = "yes" ; then
5293   echo "STRIP=${strip}" >> $config_host_mak
5294 fi
5295 if test "$bigendian" = "yes" ; then
5296   echo "HOST_WORDS_BIGENDIAN=y" >> $config_host_mak
5297 fi
5298 if test "$mingw32" = "yes" ; then
5299   echo "CONFIG_WIN32=y" >> $config_host_mak
5300   rc_version=$(cat $source_path/VERSION)
5301   version_major=${rc_version%%.*}
5302   rc_version=${rc_version#*.}
5303   version_minor=${rc_version%%.*}
5304   rc_version=${rc_version#*.}
5305   version_subminor=${rc_version%%.*}
5306   version_micro=0
5307   echo "CONFIG_FILEVERSION=$version_major,$version_minor,$version_subminor,$version_micro" >> $config_host_mak
5308   echo "CONFIG_PRODUCTVERSION=$version_major,$version_minor,$version_subminor,$version_micro" >> $config_host_mak
5309   if test "$guest_agent_with_vss" = "yes" ; then
5310     echo "CONFIG_QGA_VSS=y" >> $config_host_mak
5311     echo "QGA_VSS_PROVIDER=$qga_vss_provider" >> $config_host_mak
5312     echo "WIN_SDK=\"$win_sdk\"" >> $config_host_mak
5313   fi
5314   if test "$guest_agent_ntddscsi" = "yes" ; then
5315     echo "CONFIG_QGA_NTDDDISK=y" >> $config_host_mak
5316   fi
5317   if test "$guest_agent_msi" = "yes"; then
5318     echo "QEMU_GA_MSI_ENABLED=yes" >> $config_host_mak  
5319     echo "QEMU_GA_MSI_MINGW_DLL_PATH=${QEMU_GA_MSI_MINGW_DLL_PATH}" >> $config_host_mak
5320     echo "QEMU_GA_MSI_WITH_VSS=${QEMU_GA_MSI_WITH_VSS}" >> $config_host_mak
5321     echo "QEMU_GA_MSI_ARCH=${QEMU_GA_MSI_ARCH}" >> $config_host_mak
5322     echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak
5323     echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak
5324     echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak
5325   fi
5326 else
5327   echo "CONFIG_POSIX=y" >> $config_host_mak
5328 fi
5329
5330 if test "$linux" = "yes" ; then
5331   echo "CONFIG_LINUX=y" >> $config_host_mak
5332 fi
5333
5334 if test "$darwin" = "yes" ; then
5335   echo "CONFIG_DARWIN=y" >> $config_host_mak
5336 fi
5337
5338 if test "$aix" = "yes" ; then
5339   echo "CONFIG_AIX=y" >> $config_host_mak
5340 fi
5341
5342 if test "$solaris" = "yes" ; then
5343   echo "CONFIG_SOLARIS=y" >> $config_host_mak
5344   echo "CONFIG_SOLARIS_VERSION=$solarisrev" >> $config_host_mak
5345   if test "$needs_libsunmath" = "yes" ; then
5346     echo "CONFIG_NEEDS_LIBSUNMATH=y" >> $config_host_mak
5347   fi
5348 fi
5349 if test "$haiku" = "yes" ; then
5350   echo "CONFIG_HAIKU=y" >> $config_host_mak
5351 fi
5352 if test "$static" = "yes" ; then
5353   echo "CONFIG_STATIC=y" >> $config_host_mak
5354 fi
5355 if test "$profiler" = "yes" ; then
5356   echo "CONFIG_PROFILER=y" >> $config_host_mak
5357 fi
5358 if test "$slirp" = "yes" ; then
5359   echo "CONFIG_SLIRP=y" >> $config_host_mak
5360   echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
5361 fi
5362 if test "$vde" = "yes" ; then
5363   echo "CONFIG_VDE=y" >> $config_host_mak
5364 fi
5365 if test "$netmap" = "yes" ; then
5366   echo "CONFIG_NETMAP=y" >> $config_host_mak
5367 fi
5368 if test "$l2tpv3" = "yes" ; then
5369   echo "CONFIG_L2TPV3=y" >> $config_host_mak
5370 fi
5371 if test "$cap_ng" = "yes" ; then
5372   echo "CONFIG_LIBCAP=y" >> $config_host_mak
5373 fi
5374 echo "CONFIG_AUDIO_DRIVERS=$audio_drv_list" >> $config_host_mak
5375 for drv in $audio_drv_list; do
5376     def=CONFIG_$(echo $drv | LC_ALL=C tr '[a-z]' '[A-Z]')
5377     echo "$def=y" >> $config_host_mak
5378 done
5379 if test "$audio_pt_int" = "yes" ; then
5380   echo "CONFIG_AUDIO_PT_INT=y" >> $config_host_mak
5381 fi
5382 if test "$audio_win_int" = "yes" ; then
5383   echo "CONFIG_AUDIO_WIN_INT=y" >> $config_host_mak
5384 fi
5385 echo "CONFIG_BDRV_RW_WHITELIST=$block_drv_rw_whitelist" >> $config_host_mak
5386 echo "CONFIG_BDRV_RO_WHITELIST=$block_drv_ro_whitelist" >> $config_host_mak
5387 if test "$vnc" = "yes" ; then
5388   echo "CONFIG_VNC=y" >> $config_host_mak
5389 fi
5390 if test "$vnc_sasl" = "yes" ; then
5391   echo "CONFIG_VNC_SASL=y" >> $config_host_mak
5392 fi
5393 if test "$vnc_jpeg" = "yes" ; then
5394   echo "CONFIG_VNC_JPEG=y" >> $config_host_mak
5395 fi
5396 if test "$vnc_png" = "yes" ; then
5397   echo "CONFIG_VNC_PNG=y" >> $config_host_mak
5398 fi
5399 if test "$fnmatch" = "yes" ; then
5400   echo "CONFIG_FNMATCH=y" >> $config_host_mak
5401 fi
5402 if test "$xfs" = "yes" ; then
5403   echo "CONFIG_XFS=y" >> $config_host_mak
5404 fi
5405 qemu_version=$(head $source_path/VERSION)
5406 echo "VERSION=$qemu_version" >>$config_host_mak
5407 echo "PKGVERSION=$pkgversion" >>$config_host_mak
5408 echo "SRC_PATH=$source_path" >> $config_host_mak
5409 echo "TARGET_DIRS=$target_list" >> $config_host_mak
5410 if [ "$docs" = "yes" ] ; then
5411   echo "BUILD_DOCS=yes" >> $config_host_mak
5412 fi
5413 if test "$modules" = "yes"; then
5414   # $shacmd can generate a hash started with digit, which the compiler doesn't
5415   # like as an symbol. So prefix it with an underscore
5416   echo "CONFIG_STAMP=_$( (echo $qemu_version; echo $pkgversion; cat $0) | $shacmd - | cut -f1 -d\ )" >> $config_host_mak
5417   echo "CONFIG_MODULES=y" >> $config_host_mak
5418 fi
5419 if test "$sdl" = "yes" ; then
5420   echo "CONFIG_SDL=y" >> $config_host_mak
5421   echo "CONFIG_SDLABI=$sdlabi" >> $config_host_mak
5422   echo "SDL_CFLAGS=$sdl_cflags" >> $config_host_mak
5423 fi
5424 if test "$cocoa" = "yes" ; then
5425   echo "CONFIG_COCOA=y" >> $config_host_mak
5426 fi
5427 if test "$curses" = "yes" ; then
5428   echo "CONFIG_CURSES=y" >> $config_host_mak
5429 fi
5430 if test "$utimens" = "yes" ; then
5431   echo "CONFIG_UTIMENSAT=y" >> $config_host_mak
5432 fi
5433 if test "$pipe2" = "yes" ; then
5434   echo "CONFIG_PIPE2=y" >> $config_host_mak
5435 fi
5436 if test "$accept4" = "yes" ; then
5437   echo "CONFIG_ACCEPT4=y" >> $config_host_mak
5438 fi
5439 if test "$splice" = "yes" ; then
5440   echo "CONFIG_SPLICE=y" >> $config_host_mak
5441 fi
5442 if test "$eventfd" = "yes" ; then
5443   echo "CONFIG_EVENTFD=y" >> $config_host_mak
5444 fi
5445 if test "$memfd" = "yes" ; then
5446   echo "CONFIG_MEMFD=y" >> $config_host_mak
5447 fi
5448 if test "$fallocate" = "yes" ; then
5449   echo "CONFIG_FALLOCATE=y" >> $config_host_mak
5450 fi
5451 if test "$fallocate_punch_hole" = "yes" ; then
5452   echo "CONFIG_FALLOCATE_PUNCH_HOLE=y" >> $config_host_mak
5453 fi
5454 if test "$fallocate_zero_range" = "yes" ; then
5455   echo "CONFIG_FALLOCATE_ZERO_RANGE=y" >> $config_host_mak
5456 fi
5457 if test "$posix_fallocate" = "yes" ; then
5458   echo "CONFIG_POSIX_FALLOCATE=y" >> $config_host_mak
5459 fi
5460 if test "$sync_file_range" = "yes" ; then
5461   echo "CONFIG_SYNC_FILE_RANGE=y" >> $config_host_mak
5462 fi
5463 if test "$fiemap" = "yes" ; then
5464   echo "CONFIG_FIEMAP=y" >> $config_host_mak
5465 fi
5466 if test "$dup3" = "yes" ; then
5467   echo "CONFIG_DUP3=y" >> $config_host_mak
5468 fi
5469 if test "$ppoll" = "yes" ; then
5470   echo "CONFIG_PPOLL=y" >> $config_host_mak
5471 fi
5472 if test "$prctl_pr_set_timerslack" = "yes" ; then
5473   echo "CONFIG_PRCTL_PR_SET_TIMERSLACK=y" >> $config_host_mak
5474 fi
5475 if test "$epoll" = "yes" ; then
5476   echo "CONFIG_EPOLL=y" >> $config_host_mak
5477 fi
5478 if test "$epoll_create1" = "yes" ; then
5479   echo "CONFIG_EPOLL_CREATE1=y" >> $config_host_mak
5480 fi
5481 if test "$sendfile" = "yes" ; then
5482   echo "CONFIG_SENDFILE=y" >> $config_host_mak
5483 fi
5484 if test "$timerfd" = "yes" ; then
5485   echo "CONFIG_TIMERFD=y" >> $config_host_mak
5486 fi
5487 if test "$setns" = "yes" ; then
5488   echo "CONFIG_SETNS=y" >> $config_host_mak
5489 fi
5490 if test "$clock_adjtime" = "yes" ; then
5491   echo "CONFIG_CLOCK_ADJTIME=y" >> $config_host_mak
5492 fi
5493 if test "$syncfs" = "yes" ; then
5494   echo "CONFIG_SYNCFS=y" >> $config_host_mak
5495 fi
5496 if test "$inotify" = "yes" ; then
5497   echo "CONFIG_INOTIFY=y" >> $config_host_mak
5498 fi
5499 if test "$inotify1" = "yes" ; then
5500   echo "CONFIG_INOTIFY1=y" >> $config_host_mak
5501 fi
5502 if test "$byteswap_h" = "yes" ; then
5503   echo "CONFIG_BYTESWAP_H=y" >> $config_host_mak
5504 fi
5505 if test "$bswap_h" = "yes" ; then
5506   echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak
5507 fi
5508 if test "$curl" = "yes" ; then
5509   echo "CONFIG_CURL=m" >> $config_host_mak
5510   echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak
5511   echo "CURL_LIBS=$curl_libs" >> $config_host_mak
5512 fi
5513 if test "$brlapi" = "yes" ; then
5514   echo "CONFIG_BRLAPI=y" >> $config_host_mak
5515 fi
5516 if test "$bluez" = "yes" ; then
5517   echo "CONFIG_BLUEZ=y" >> $config_host_mak
5518   echo "BLUEZ_CFLAGS=$bluez_cflags" >> $config_host_mak
5519 fi
5520 if test "$glib_subprocess" = "yes" ; then
5521   echo "CONFIG_HAS_GLIB_SUBPROCESS_TESTS=y" >> $config_host_mak
5522 fi
5523 if test "$gtk" = "yes" ; then
5524   echo "CONFIG_GTK=y" >> $config_host_mak
5525   echo "CONFIG_GTKABI=$gtkabi" >> $config_host_mak
5526   echo "GTK_CFLAGS=$gtk_cflags" >> $config_host_mak
5527   echo "GTK_LIBS=$gtk_libs" >> $config_host_mak
5528   if test "$gtk_gl" = "yes" ; then
5529     echo "CONFIG_GTK_GL=y" >> $config_host_mak
5530   fi
5531 fi
5532 echo "CONFIG_TLS_PRIORITY=\"$tls_priority\"" >> $config_host_mak
5533 if test "$gnutls" = "yes" ; then
5534   echo "CONFIG_GNUTLS=y" >> $config_host_mak
5535 fi
5536 if test "$gnutls_rnd" = "yes" ; then
5537   echo "CONFIG_GNUTLS_RND=y" >> $config_host_mak
5538 fi
5539 if test "$gcrypt" = "yes" ; then
5540   echo "CONFIG_GCRYPT=y" >> $config_host_mak
5541   if test "$gcrypt_hmac" = "yes" ; then
5542     echo "CONFIG_GCRYPT_HMAC=y" >> $config_host_mak
5543   fi
5544   if test "$gcrypt_kdf" = "yes" ; then
5545     echo "CONFIG_GCRYPT_KDF=y" >> $config_host_mak
5546   fi
5547 fi
5548 if test "$nettle" = "yes" ; then
5549   echo "CONFIG_NETTLE=y" >> $config_host_mak
5550   echo "CONFIG_NETTLE_VERSION_MAJOR=${nettle_version%%.*}" >> $config_host_mak
5551   if test "$nettle_kdf" = "yes" ; then
5552     echo "CONFIG_NETTLE_KDF=y" >> $config_host_mak
5553   fi
5554 fi
5555 if test "$tasn1" = "yes" ; then
5556   echo "CONFIG_TASN1=y" >> $config_host_mak
5557 fi
5558 if test "$have_ifaddrs_h" = "yes" ; then
5559     echo "HAVE_IFADDRS_H=y" >> $config_host_mak
5560 fi
5561 if test "$have_broken_size_max" = "yes" ; then
5562     echo "HAVE_BROKEN_SIZE_MAX=y" >> $config_host_mak
5563 fi
5564
5565 # Work around a system header bug with some kernel/XFS header
5566 # versions where they both try to define 'struct fsxattr':
5567 # xfs headers will not try to redefine structs from linux headers
5568 # if this macro is set.
5569 if test "$have_fsxattr" = "yes" ; then
5570     echo "HAVE_FSXATTR=y" >> $config_host_mak
5571 fi
5572 if test "$vte" = "yes" ; then
5573   echo "CONFIG_VTE=y" >> $config_host_mak
5574   echo "VTE_CFLAGS=$vte_cflags" >> $config_host_mak
5575 fi
5576 if test "$virglrenderer" = "yes" ; then
5577   echo "CONFIG_VIRGL=y" >> $config_host_mak
5578   echo "VIRGL_CFLAGS=$virgl_cflags" >> $config_host_mak
5579   echo "VIRGL_LIBS=$virgl_libs" >> $config_host_mak
5580 fi
5581 if test "$xen" = "yes" ; then
5582   echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
5583   echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
5584   if test "$xen_pv_domain_build" = "yes" ; then
5585     echo "CONFIG_XEN_PV_DOMAIN_BUILD=y" >> $config_host_mak
5586   fi
5587 fi
5588 if test "$linux_aio" = "yes" ; then
5589   echo "CONFIG_LINUX_AIO=y" >> $config_host_mak
5590 fi
5591 if test "$attr" = "yes" ; then
5592   echo "CONFIG_ATTR=y" >> $config_host_mak
5593 fi
5594 if test "$libattr" = "yes" ; then
5595   echo "CONFIG_LIBATTR=y" >> $config_host_mak
5596 fi
5597 if test "$virtfs" = "yes" ; then
5598   echo "CONFIG_VIRTFS=y" >> $config_host_mak
5599 fi
5600 if test "$vhost_scsi" = "yes" ; then
5601   echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
5602 fi
5603 if test "$vhost_net" = "yes" ; then
5604   echo "CONFIG_VHOST_NET_USED=y" >> $config_host_mak
5605 fi
5606 if test "$vhost_vsock" = "yes" ; then
5607   echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
5608 fi
5609 if test "$blobs" = "yes" ; then
5610   echo "INSTALL_BLOBS=yes" >> $config_host_mak
5611 fi
5612 if test "$iovec" = "yes" ; then
5613   echo "CONFIG_IOVEC=y" >> $config_host_mak
5614 fi
5615 if test "$preadv" = "yes" ; then
5616   echo "CONFIG_PREADV=y" >> $config_host_mak
5617 fi
5618 if test "$fdt" = "yes" ; then
5619   echo "CONFIG_FDT=y" >> $config_host_mak
5620 fi
5621 if test "$signalfd" = "yes" ; then
5622   echo "CONFIG_SIGNALFD=y" >> $config_host_mak
5623 fi
5624 if test "$tcg_interpreter" = "yes" ; then
5625   echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
5626 fi
5627 if test "$fdatasync" = "yes" ; then
5628   echo "CONFIG_FDATASYNC=y" >> $config_host_mak
5629 fi
5630 if test "$madvise" = "yes" ; then
5631   echo "CONFIG_MADVISE=y" >> $config_host_mak
5632 fi
5633 if test "$posix_madvise" = "yes" ; then
5634   echo "CONFIG_POSIX_MADVISE=y" >> $config_host_mak
5635 fi
5636
5637 if test "$spice" = "yes" ; then
5638   echo "CONFIG_SPICE=y" >> $config_host_mak
5639 fi
5640
5641 if test "$smartcard" = "yes" ; then
5642   echo "CONFIG_SMARTCARD=y" >> $config_host_mak
5643 fi
5644
5645 if test "$libusb" = "yes" ; then
5646   echo "CONFIG_USB_LIBUSB=y" >> $config_host_mak
5647 fi
5648
5649 if test "$usb_redir" = "yes" ; then
5650   echo "CONFIG_USB_REDIR=y" >> $config_host_mak
5651 fi
5652
5653 if test "$opengl" = "yes" ; then
5654   echo "CONFIG_OPENGL=y" >> $config_host_mak
5655   echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
5656   if test "$opengl_dmabuf" = "yes" ; then
5657     echo "CONFIG_OPENGL_DMABUF=y" >> $config_host_mak
5658   fi
5659 fi
5660
5661 if test "$avx2_opt" = "yes" ; then
5662   echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
5663 fi
5664
5665 if test "$lzo" = "yes" ; then
5666   echo "CONFIG_LZO=y" >> $config_host_mak
5667 fi
5668
5669 if test "$snappy" = "yes" ; then
5670   echo "CONFIG_SNAPPY=y" >> $config_host_mak
5671 fi
5672
5673 if test "$bzip2" = "yes" ; then
5674   echo "CONFIG_BZIP2=y" >> $config_host_mak
5675   echo "BZIP2_LIBS=-lbz2" >> $config_host_mak
5676 fi
5677
5678 if test "$libiscsi" = "yes" ; then
5679   echo "CONFIG_LIBISCSI=m" >> $config_host_mak
5680   echo "LIBISCSI_CFLAGS=$libiscsi_cflags" >> $config_host_mak
5681   echo "LIBISCSI_LIBS=$libiscsi_libs" >> $config_host_mak
5682 fi
5683
5684 if test "$libnfs" = "yes" ; then
5685   echo "CONFIG_LIBNFS=m" >> $config_host_mak
5686   echo "LIBNFS_LIBS=$libnfs_libs" >> $config_host_mak
5687 fi
5688
5689 if test "$seccomp" = "yes"; then
5690   echo "CONFIG_SECCOMP=y" >> $config_host_mak
5691 fi
5692
5693 # XXX: suppress that
5694 if [ "$bsd" = "yes" ] ; then
5695   echo "CONFIG_BSD=y" >> $config_host_mak
5696 fi
5697
5698 if test "$localtime_r" = "yes" ; then
5699   echo "CONFIG_LOCALTIME_R=y" >> $config_host_mak
5700 fi
5701 if test "$qom_cast_debug" = "yes" ; then
5702   echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak
5703 fi
5704 if test "$rbd" = "yes" ; then
5705   echo "CONFIG_RBD=m" >> $config_host_mak
5706   echo "RBD_CFLAGS=$rbd_cflags" >> $config_host_mak
5707   echo "RBD_LIBS=$rbd_libs" >> $config_host_mak
5708 fi
5709
5710 echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
5711 if test "$coroutine_pool" = "yes" ; then
5712   echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
5713 else
5714   echo "CONFIG_COROUTINE_POOL=0" >> $config_host_mak
5715 fi
5716
5717 if test "$debug_stack_usage" = "yes" ; then
5718   echo "CONFIG_DEBUG_STACK_USAGE=y" >> $config_host_mak
5719 fi
5720
5721 if test "$open_by_handle_at" = "yes" ; then
5722   echo "CONFIG_OPEN_BY_HANDLE=y" >> $config_host_mak
5723 fi
5724
5725 if test "$linux_magic_h" = "yes" ; then
5726   echo "CONFIG_LINUX_MAGIC_H=y" >> $config_host_mak
5727 fi
5728
5729 if test "$pragma_diagnostic_available" = "yes" ; then
5730   echo "CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE=y" >> $config_host_mak
5731 fi
5732
5733 if test "$valgrind_h" = "yes" ; then
5734   echo "CONFIG_VALGRIND_H=y" >> $config_host_mak
5735 fi
5736
5737 if test "$has_environ" = "yes" ; then
5738   echo "CONFIG_HAS_ENVIRON=y" >> $config_host_mak
5739 fi
5740
5741 if test "$cpuid_h" = "yes" ; then
5742   echo "CONFIG_CPUID_H=y" >> $config_host_mak
5743 fi
5744
5745 if test "$int128" = "yes" ; then
5746   echo "CONFIG_INT128=y" >> $config_host_mak
5747 fi
5748
5749 if test "$atomic128" = "yes" ; then
5750   echo "CONFIG_ATOMIC128=y" >> $config_host_mak
5751 fi
5752
5753 if test "$atomic64" = "yes" ; then
5754   echo "CONFIG_ATOMIC64=y" >> $config_host_mak
5755 fi
5756
5757 if test "$getauxval" = "yes" ; then
5758   echo "CONFIG_GETAUXVAL=y" >> $config_host_mak
5759 fi
5760
5761 if test "$glusterfs" = "yes" ; then
5762   echo "CONFIG_GLUSTERFS=m" >> $config_host_mak
5763   echo "GLUSTERFS_CFLAGS=$glusterfs_cflags" >> $config_host_mak
5764   echo "GLUSTERFS_LIBS=$glusterfs_libs" >> $config_host_mak
5765 fi
5766
5767 if test "$glusterfs_xlator_opt" = "yes" ; then
5768   echo "CONFIG_GLUSTERFS_XLATOR_OPT=y" >> $config_host_mak
5769 fi
5770
5771 if test "$glusterfs_discard" = "yes" ; then
5772   echo "CONFIG_GLUSTERFS_DISCARD=y" >> $config_host_mak
5773 fi
5774
5775 if test "$glusterfs_zerofill" = "yes" ; then
5776   echo "CONFIG_GLUSTERFS_ZEROFILL=y" >> $config_host_mak
5777 fi
5778
5779 if test "$libssh2" = "yes" ; then
5780   echo "CONFIG_LIBSSH2=m" >> $config_host_mak
5781   echo "LIBSSH2_CFLAGS=$libssh2_cflags" >> $config_host_mak
5782   echo "LIBSSH2_LIBS=$libssh2_libs" >> $config_host_mak
5783 fi
5784
5785 # USB host support
5786 if test "$libusb" = "yes"; then
5787   echo "HOST_USB=libusb legacy" >> $config_host_mak
5788 else
5789   echo "HOST_USB=stub" >> $config_host_mak
5790 fi
5791
5792 # TPM passthrough support?
5793 if test "$tpm" = "yes"; then
5794   echo 'CONFIG_TPM=$(CONFIG_SOFTMMU)' >> $config_host_mak
5795   if test "$tpm_passthrough" = "yes"; then
5796     echo "CONFIG_TPM_PASSTHROUGH=y" >> $config_host_mak
5797   fi
5798 fi
5799
5800 echo "TRACE_BACKENDS=$trace_backends" >> $config_host_mak
5801 if have_backend "nop"; then
5802   echo "CONFIG_TRACE_NOP=y" >> $config_host_mak
5803 fi
5804 if have_backend "simple"; then
5805   echo "CONFIG_TRACE_SIMPLE=y" >> $config_host_mak
5806   # Set the appropriate trace file.
5807   trace_file="\"$trace_file-\" FMT_pid"
5808 fi
5809 if have_backend "log"; then
5810   echo "CONFIG_TRACE_LOG=y" >> $config_host_mak
5811 fi
5812 if have_backend "ust"; then
5813   echo "CONFIG_TRACE_UST=y" >> $config_host_mak
5814 fi
5815 if have_backend "dtrace"; then
5816   echo "CONFIG_TRACE_DTRACE=y" >> $config_host_mak
5817   if test "$trace_backend_stap" = "yes" ; then
5818     echo "CONFIG_TRACE_SYSTEMTAP=y" >> $config_host_mak
5819   fi
5820 fi
5821 if have_backend "ftrace"; then
5822   if test "$linux" = "yes" ; then
5823     echo "CONFIG_TRACE_FTRACE=y" >> $config_host_mak
5824   else
5825     feature_not_found "ftrace(trace backend)" "ftrace requires Linux"
5826   fi
5827 fi
5828 if have_backend "syslog"; then
5829   if test "$posix_syslog" = "yes" ; then
5830     echo "CONFIG_TRACE_SYSLOG=y" >> $config_host_mak
5831   else
5832     feature_not_found "syslog(trace backend)" "syslog not available"
5833   fi
5834 fi
5835 echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
5836
5837 if test "$rdma" = "yes" ; then
5838   echo "CONFIG_RDMA=y" >> $config_host_mak
5839 fi
5840
5841 if test "$have_rtnetlink" = "yes" ; then
5842   echo "CONFIG_RTNETLINK=y" >> $config_host_mak
5843 fi
5844
5845 if test "$replication" = "yes" ; then
5846   echo "CONFIG_REPLICATION=y" >> $config_host_mak
5847 fi
5848
5849 if test "$have_af_vsock" = "yes" ; then
5850   echo "CONFIG_AF_VSOCK=y" >> $config_host_mak
5851 fi
5852
5853 if test "$have_sysmacros" = "yes" ; then
5854   echo "CONFIG_SYSMACROS=y" >> $config_host_mak
5855 fi
5856
5857 if test "$have_static_assert" = "yes" ; then
5858   echo "CONFIG_STATIC_ASSERT=y" >> $config_host_mak
5859 fi
5860
5861 # Hold two types of flag:
5862 #   CONFIG_THREAD_SETNAME_BYTHREAD  - we've got a way of setting the name on
5863 #                                     a thread we have a handle to
5864 #   CONFIG_PTHREAD_SETNAME_NP       - A way of doing it on a particular
5865 #                                     platform
5866 if test "$pthread_setname_np" = "yes" ; then
5867   echo "CONFIG_THREAD_SETNAME_BYTHREAD=y" >> $config_host_mak
5868   echo "CONFIG_PTHREAD_SETNAME_NP=y" >> $config_host_mak
5869 fi
5870
5871 if test "$vxhs" = "yes" ; then
5872   echo "CONFIG_VXHS=y" >> $config_host_mak
5873   echo "VXHS_LIBS=$vxhs_libs" >> $config_host_mak
5874 fi
5875
5876 if test "$tcg_interpreter" = "yes"; then
5877   QEMU_INCLUDES="-I\$(SRC_PATH)/tcg/tci $QEMU_INCLUDES"
5878 elif test "$ARCH" = "sparc64" ; then
5879   QEMU_INCLUDES="-I\$(SRC_PATH)/tcg/sparc $QEMU_INCLUDES"
5880 elif test "$ARCH" = "s390x" ; then
5881   QEMU_INCLUDES="-I\$(SRC_PATH)/tcg/s390 $QEMU_INCLUDES"
5882 elif test "$ARCH" = "x86_64" -o "$ARCH" = "x32" ; then
5883   QEMU_INCLUDES="-I\$(SRC_PATH)/tcg/i386 $QEMU_INCLUDES"
5884 elif test "$ARCH" = "ppc64" ; then
5885   QEMU_INCLUDES="-I\$(SRC_PATH)/tcg/ppc $QEMU_INCLUDES"
5886 else
5887   QEMU_INCLUDES="-I\$(SRC_PATH)/tcg/\$(ARCH) $QEMU_INCLUDES"
5888 fi
5889 QEMU_INCLUDES="-I\$(SRC_PATH)/tcg $QEMU_INCLUDES"
5890
5891 echo "TOOLS=$tools" >> $config_host_mak
5892 echo "ROMS=$roms" >> $config_host_mak
5893 echo "MAKE=$make" >> $config_host_mak
5894 echo "INSTALL=$install" >> $config_host_mak
5895 echo "INSTALL_DIR=$install -d -m 0755" >> $config_host_mak
5896 echo "INSTALL_DATA=$install -c -m 0644" >> $config_host_mak
5897 echo "INSTALL_PROG=$install -c -m 0755" >> $config_host_mak
5898 echo "INSTALL_LIB=$install -c -m 0644" >> $config_host_mak
5899 echo "PYTHON=$python" >> $config_host_mak
5900 echo "CC=$cc" >> $config_host_mak
5901 if $iasl -h > /dev/null 2>&1; then
5902   echo "IASL=$iasl" >> $config_host_mak
5903 fi
5904 echo "CC_I386=$cc_i386" >> $config_host_mak
5905 echo "HOST_CC=$host_cc" >> $config_host_mak
5906 echo "CXX=$cxx" >> $config_host_mak
5907 echo "OBJCC=$objcc" >> $config_host_mak
5908 echo "AR=$ar" >> $config_host_mak
5909 echo "ARFLAGS=$ARFLAGS" >> $config_host_mak
5910 echo "AS=$as" >> $config_host_mak
5911 echo "CCAS=$ccas" >> $config_host_mak
5912 echo "CPP=$cpp" >> $config_host_mak
5913 echo "OBJCOPY=$objcopy" >> $config_host_mak
5914 echo "LD=$ld" >> $config_host_mak
5915 echo "NM=$nm" >> $config_host_mak
5916 echo "WINDRES=$windres" >> $config_host_mak
5917 echo "CFLAGS=$CFLAGS" >> $config_host_mak
5918 echo "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
5919 echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
5920 echo "QEMU_INCLUDES=$QEMU_INCLUDES" >> $config_host_mak
5921 if test "$sparse" = "yes" ; then
5922   echo "CC           := REAL_CC=\"\$(CC)\" cgcc"       >> $config_host_mak
5923   echo "CPP          := REAL_CC=\"\$(CPP)\" cgcc"      >> $config_host_mak
5924   echo "CXX          := REAL_CC=\"\$(CXX)\" cgcc"      >> $config_host_mak
5925   echo "HOST_CC      := REAL_CC=\"\$(HOST_CC)\" cgcc"  >> $config_host_mak
5926   echo "QEMU_CFLAGS  += -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-non-pointer-null" >> $config_host_mak
5927 fi
5928 if test "$cross_prefix" != ""; then
5929   echo "AUTOCONF_HOST := --host=${cross_prefix%-}"     >> $config_host_mak
5930 else
5931   echo "AUTOCONF_HOST := "                             >> $config_host_mak
5932 fi
5933 echo "LDFLAGS=$LDFLAGS" >> $config_host_mak
5934 echo "LDFLAGS_NOPIE=$LDFLAGS_NOPIE" >> $config_host_mak
5935 echo "LD_REL_FLAGS=$LD_REL_FLAGS" >> $config_host_mak
5936 echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
5937 echo "LIBS+=$LIBS" >> $config_host_mak
5938 echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak
5939 echo "PTHREAD_LIB=$PTHREAD_LIB" >> $config_host_mak
5940 echo "EXESUF=$EXESUF" >> $config_host_mak
5941 echo "DSOSUF=$DSOSUF" >> $config_host_mak
5942 echo "LDFLAGS_SHARED=$LDFLAGS_SHARED" >> $config_host_mak
5943 echo "LIBS_QGA+=$libs_qga" >> $config_host_mak
5944 echo "TASN1_LIBS=$tasn1_libs" >> $config_host_mak
5945 echo "TASN1_CFLAGS=$tasn1_cflags" >> $config_host_mak
5946 echo "POD2MAN=$POD2MAN" >> $config_host_mak
5947 echo "TRANSLATE_OPT_CFLAGS=$TRANSLATE_OPT_CFLAGS" >> $config_host_mak
5948 if test "$gcov" = "yes" ; then
5949   echo "CONFIG_GCOV=y" >> $config_host_mak
5950   echo "GCOV=$gcov_tool" >> $config_host_mak
5951 fi
5952
5953 # use included Linux headers
5954 if test "$linux" = "yes" ; then
5955   mkdir -p linux-headers
5956   case "$cpu" in
5957   i386|x86_64|x32)
5958     linux_arch=x86
5959     ;;
5960   ppcemb|ppc|ppc64)
5961     linux_arch=powerpc
5962     ;;
5963   s390x)
5964     linux_arch=s390
5965     ;;
5966   aarch64)
5967     linux_arch=arm64
5968     ;;
5969   mips64)
5970     linux_arch=mips
5971     ;;
5972   *)
5973     # For most CPUs the kernel architecture name and QEMU CPU name match.
5974     linux_arch="$cpu"
5975     ;;
5976   esac
5977     # For non-KVM architectures we will not have asm headers
5978     if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
5979       symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
5980     fi
5981 fi
5982
5983 for target in $target_list; do
5984 target_dir="$target"
5985 config_target_mak=$target_dir/config-target.mak
5986 target_name=$(echo $target | cut -d '-' -f 1)
5987 target_bigendian="no"
5988
5989 case "$target_name" in
5990   armeb|hppa|lm32|m68k|microblaze|mips|mipsn32|mips64|moxie|or1k|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb)
5991   target_bigendian=yes
5992   ;;
5993 esac
5994 target_softmmu="no"
5995 target_user_only="no"
5996 target_linux_user="no"
5997 target_bsd_user="no"
5998 case "$target" in
5999   ${target_name}-softmmu)
6000     target_softmmu="yes"
6001     ;;
6002   ${target_name}-linux-user)
6003     if test "$linux" != "yes" ; then
6004       error_exit "Target '$target' is only available on a Linux host"
6005     fi
6006     target_user_only="yes"
6007     target_linux_user="yes"
6008     ;;
6009   ${target_name}-bsd-user)
6010     if test "$bsd" != "yes" ; then
6011       error_exit "Target '$target' is only available on a BSD host"
6012     fi
6013     target_user_only="yes"
6014     target_bsd_user="yes"
6015     ;;
6016   *)
6017     error_exit "Target '$target' not recognised"
6018     exit 1
6019     ;;
6020 esac
6021
6022 mkdir -p $target_dir
6023 echo "# Automatically generated by configure - do not modify" > $config_target_mak
6024
6025 bflt="no"
6026 mttcg="no"
6027 interp_prefix1=$(echo "$interp_prefix" | sed "s/%M/$target_name/g")
6028 gdb_xml_files=""
6029
6030 TARGET_ARCH="$target_name"
6031 TARGET_BASE_ARCH=""
6032 TARGET_ABI_DIR=""
6033
6034 case "$target_name" in
6035   i386)
6036     gdb_xml_files="i386-32bit-core.xml"
6037   ;;
6038   x86_64)
6039     TARGET_BASE_ARCH=i386
6040     gdb_xml_files="i386-64bit-core.xml"
6041   ;;
6042   alpha)
6043     mttcg="yes"
6044   ;;
6045   arm|armeb)
6046     TARGET_ARCH=arm
6047     bflt="yes"
6048     mttcg="yes"
6049     gdb_xml_files="arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"
6050   ;;
6051   aarch64)
6052     TARGET_BASE_ARCH=arm
6053     bflt="yes"
6054     mttcg="yes"
6055     gdb_xml_files="aarch64-core.xml aarch64-fpu.xml arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"
6056   ;;
6057   cris)
6058   ;;
6059   hppa)
6060   ;;
6061   lm32)
6062   ;;
6063   m68k)
6064     bflt="yes"
6065     gdb_xml_files="cf-core.xml cf-fp.xml"
6066   ;;
6067   microblaze|microblazeel)
6068     TARGET_ARCH=microblaze
6069     bflt="yes"
6070   ;;
6071   mips|mipsel)
6072     TARGET_ARCH=mips
6073     echo "TARGET_ABI_MIPSO32=y" >> $config_target_mak
6074   ;;
6075   mipsn32|mipsn32el)
6076     TARGET_ARCH=mips64
6077     TARGET_BASE_ARCH=mips
6078     echo "TARGET_ABI_MIPSN32=y" >> $config_target_mak
6079     echo "TARGET_ABI32=y" >> $config_target_mak
6080   ;;
6081   mips64|mips64el)
6082     TARGET_ARCH=mips64
6083     TARGET_BASE_ARCH=mips
6084     echo "TARGET_ABI_MIPSN64=y" >> $config_target_mak
6085   ;;
6086   moxie)
6087   ;;
6088   nios2)
6089   ;;
6090   or1k)
6091     TARGET_ARCH=openrisc
6092     TARGET_BASE_ARCH=openrisc
6093   ;;
6094   ppc)
6095     gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
6096   ;;
6097   ppcemb)
6098     TARGET_BASE_ARCH=ppc
6099     TARGET_ABI_DIR=ppc
6100     gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
6101   ;;
6102   ppc64)
6103     TARGET_BASE_ARCH=ppc
6104     TARGET_ABI_DIR=ppc
6105     mttcg=yes
6106     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml power-vsx.xml"
6107   ;;
6108   ppc64le)
6109     TARGET_ARCH=ppc64
6110     TARGET_BASE_ARCH=ppc
6111     TARGET_ABI_DIR=ppc
6112     mttcg=yes
6113     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml power-vsx.xml"
6114   ;;
6115   ppc64abi32)
6116     TARGET_ARCH=ppc64
6117     TARGET_BASE_ARCH=ppc
6118     TARGET_ABI_DIR=ppc
6119     echo "TARGET_ABI32=y" >> $config_target_mak
6120     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml power-vsx.xml"
6121   ;;
6122   sh4|sh4eb)
6123     TARGET_ARCH=sh4
6124     bflt="yes"
6125   ;;
6126   sparc)
6127   ;;
6128   sparc64)
6129     TARGET_BASE_ARCH=sparc
6130   ;;
6131   sparc32plus)
6132     TARGET_ARCH=sparc64
6133     TARGET_BASE_ARCH=sparc
6134     TARGET_ABI_DIR=sparc
6135     echo "TARGET_ABI32=y" >> $config_target_mak
6136   ;;
6137   s390x)
6138     gdb_xml_files="s390x-core64.xml s390-acr.xml s390-fpr.xml s390-vx.xml s390-cr.xml s390-virt.xml"
6139   ;;
6140   tilegx)
6141   ;;
6142   tricore)
6143   ;;
6144   unicore32)
6145   ;;
6146   xtensa|xtensaeb)
6147     TARGET_ARCH=xtensa
6148   ;;
6149   *)
6150     error_exit "Unsupported target CPU"
6151   ;;
6152 esac
6153 # TARGET_BASE_ARCH needs to be defined after TARGET_ARCH
6154 if [ "$TARGET_BASE_ARCH" = "" ]; then
6155   TARGET_BASE_ARCH=$TARGET_ARCH
6156 fi
6157
6158 symlink "$source_path/Makefile.target" "$target_dir/Makefile"
6159
6160 upper() {
6161     echo "$@"| LC_ALL=C tr '[a-z]' '[A-Z]'
6162 }
6163
6164 target_arch_name="$(upper $TARGET_ARCH)"
6165 echo "TARGET_$target_arch_name=y" >> $config_target_mak
6166 echo "TARGET_NAME=$target_name" >> $config_target_mak
6167 echo "TARGET_BASE_ARCH=$TARGET_BASE_ARCH" >> $config_target_mak
6168 if [ "$TARGET_ABI_DIR" = "" ]; then
6169   TARGET_ABI_DIR=$TARGET_ARCH
6170 fi
6171 echo "TARGET_ABI_DIR=$TARGET_ABI_DIR" >> $config_target_mak
6172 if [ "$HOST_VARIANT_DIR" != "" ]; then
6173     echo "HOST_VARIANT_DIR=$HOST_VARIANT_DIR" >> $config_target_mak
6174 fi
6175 case "$target_name" in
6176   i386|x86_64)
6177     if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
6178       echo "CONFIG_XEN=y" >> $config_target_mak
6179       if test "$xen_pci_passthrough" = yes; then
6180         echo "CONFIG_XEN_PCI_PASSTHROUGH=y" >> "$config_target_mak"
6181       fi
6182     fi
6183     ;;
6184   *)
6185 esac
6186 case "$target_name" in
6187   aarch64|arm|i386|x86_64|ppcemb|ppc|ppc64|s390x|mipsel|mips)
6188     # Make sure the target and host cpus are compatible
6189     if test "$kvm" = "yes" -a "$target_softmmu" = "yes" -a \
6190       \( "$target_name" = "$cpu" -o \
6191       \( "$target_name" = "ppcemb" -a "$cpu" = "ppc" \) -o \
6192       \( "$target_name" = "ppc64"  -a "$cpu" = "ppc" \) -o \
6193       \( "$target_name" = "ppc"    -a "$cpu" = "ppc64" \) -o \
6194       \( "$target_name" = "ppcemb" -a "$cpu" = "ppc64" \) -o \
6195       \( "$target_name" = "mipsel" -a "$cpu" = "mips" \) -o \
6196       \( "$target_name" = "x86_64" -a "$cpu" = "i386"   \) -o \
6197       \( "$target_name" = "i386"   -a "$cpu" = "x86_64" \) -o \
6198       \( "$target_name" = "x86_64" -a "$cpu" = "x32"   \) -o \
6199       \( "$target_name" = "i386"   -a "$cpu" = "x32" \) \) ; then
6200       echo "CONFIG_KVM=y" >> $config_target_mak
6201       if test "$vhost_net" = "yes" ; then
6202         echo "CONFIG_VHOST_NET=y" >> $config_target_mak
6203         echo "CONFIG_VHOST_NET_TEST_$target_name=y" >> $config_host_mak
6204       fi
6205     fi
6206 esac
6207 if test "$hax" = "yes" ; then
6208   if test "$target_softmmu" = "yes" ; then
6209     case "$target_name" in
6210     i386|x86_64)
6211       echo "CONFIG_HAX=y" >> $config_target_mak
6212     ;;
6213     esac
6214   fi
6215 fi
6216 if test "$target_bigendian" = "yes" ; then
6217   echo "TARGET_WORDS_BIGENDIAN=y" >> $config_target_mak
6218 fi
6219 if test "$target_softmmu" = "yes" ; then
6220   echo "CONFIG_SOFTMMU=y" >> $config_target_mak
6221   if test "$mttcg" = "yes" ; then
6222     echo "TARGET_SUPPORTS_MTTCG=y" >> $config_target_mak
6223   fi
6224 fi
6225 if test "$target_user_only" = "yes" ; then
6226   echo "CONFIG_USER_ONLY=y" >> $config_target_mak
6227   echo "CONFIG_QEMU_INTERP_PREFIX=\"$interp_prefix1\"" >> $config_target_mak
6228 fi
6229 if test "$target_linux_user" = "yes" ; then
6230   echo "CONFIG_LINUX_USER=y" >> $config_target_mak
6231 fi
6232 list=""
6233 if test ! -z "$gdb_xml_files" ; then
6234   for x in $gdb_xml_files; do
6235     list="$list $source_path/gdb-xml/$x"
6236   done
6237   echo "TARGET_XML_FILES=$list" >> $config_target_mak
6238 fi
6239
6240 if test "$target_user_only" = "yes" -a "$bflt" = "yes"; then
6241   echo "TARGET_HAS_BFLT=y" >> $config_target_mak
6242 fi
6243 if test "$target_bsd_user" = "yes" ; then
6244   echo "CONFIG_BSD_USER=y" >> $config_target_mak
6245 fi
6246
6247 # generate QEMU_CFLAGS/LDFLAGS for targets
6248
6249 cflags=""
6250 ldflags=""
6251
6252 disas_config() {
6253   echo "CONFIG_${1}_DIS=y" >> $config_target_mak
6254   echo "CONFIG_${1}_DIS=y" >> config-all-disas.mak
6255 }
6256
6257 for i in $ARCH $TARGET_BASE_ARCH ; do
6258   case "$i" in
6259   alpha)
6260     disas_config "ALPHA"
6261   ;;
6262   aarch64)
6263     if test -n "${cxx}"; then
6264       disas_config "ARM_A64"
6265     fi
6266   ;;
6267   arm)
6268     disas_config "ARM"
6269     if test -n "${cxx}"; then
6270       disas_config "ARM_A64"
6271     fi
6272   ;;
6273   cris)
6274     disas_config "CRIS"
6275   ;;
6276   hppa)
6277     disas_config "HPPA"
6278   ;;
6279   i386|x86_64|x32)
6280     disas_config "I386"
6281   ;;
6282   ia64*)
6283     disas_config "IA64"
6284   ;;
6285   lm32)
6286     disas_config "LM32"
6287   ;;
6288   m68k)
6289     disas_config "M68K"
6290   ;;
6291   microblaze*)
6292     disas_config "MICROBLAZE"
6293   ;;
6294   mips*)
6295     disas_config "MIPS"
6296   ;;
6297   moxie*)
6298     disas_config "MOXIE"
6299   ;;
6300   nios2)
6301     disas_config "NIOS2"
6302   ;;
6303   or1k)
6304     disas_config "OPENRISC"
6305   ;;
6306   ppc*)
6307     disas_config "PPC"
6308   ;;
6309   s390*)
6310     disas_config "S390"
6311   ;;
6312   sh4)
6313     disas_config "SH4"
6314   ;;
6315   sparc*)
6316     disas_config "SPARC"
6317   ;;
6318   xtensa*)
6319     disas_config "XTENSA"
6320   ;;
6321   esac
6322 done
6323 if test "$tcg_interpreter" = "yes" ; then
6324   disas_config "TCI"
6325 fi
6326
6327 case "$ARCH" in
6328 alpha)
6329   # Ensure there's only a single GP
6330   cflags="-msmall-data $cflags"
6331 ;;
6332 esac
6333
6334 if test "$gprof" = "yes" ; then
6335   echo "TARGET_GPROF=yes" >> $config_target_mak
6336   if test "$target_linux_user" = "yes" ; then
6337     cflags="-p $cflags"
6338     ldflags="-p $ldflags"
6339   fi
6340   if test "$target_softmmu" = "yes" ; then
6341     ldflags="-p $ldflags"
6342     echo "GPROF_CFLAGS=-p" >> $config_target_mak
6343   fi
6344 fi
6345
6346 if test "$target_linux_user" = "yes" -o "$target_bsd_user" = "yes" ; then
6347   ldflags="$ldflags $textseg_ldflags"
6348 fi
6349
6350 echo "LDFLAGS+=$ldflags" >> $config_target_mak
6351 echo "QEMU_CFLAGS+=$cflags" >> $config_target_mak
6352
6353 done # for target in $targets
6354
6355 if [ "$pixman" = "internal" ]; then
6356   echo "config-host.h: subdir-pixman" >> $config_host_mak
6357 fi
6358
6359 if [ "$dtc_internal" = "yes" ]; then
6360   echo "config-host.h: subdir-dtc" >> $config_host_mak
6361 fi
6362
6363 if test "$numa" = "yes"; then
6364   echo "CONFIG_NUMA=y" >> $config_host_mak
6365 fi
6366
6367 if test "$ccache_cpp2" = "yes"; then
6368   echo "export CCACHE_CPP2=y" >> $config_host_mak
6369 fi
6370
6371 # build tree in object directory in case the source is not in the current directory
6372 DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos tests/qapi-schema tests/tcg/xtensa tests/qemu-iotests"
6373 DIRS="$DIRS docs fsdev"
6374 DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas pc-bios/s390-ccw"
6375 DIRS="$DIRS roms/seabios roms/vgabios"
6376 DIRS="$DIRS qapi-generated"
6377 FILES="Makefile tests/tcg/Makefile qdict-test-data.txt"
6378 FILES="$FILES tests/tcg/cris/Makefile tests/tcg/cris/.gdbinit"
6379 FILES="$FILES tests/tcg/lm32/Makefile tests/tcg/xtensa/Makefile po/Makefile"
6380 FILES="$FILES pc-bios/optionrom/Makefile pc-bios/keymaps"
6381 FILES="$FILES pc-bios/spapr-rtas/Makefile"
6382 FILES="$FILES pc-bios/s390-ccw/Makefile"
6383 FILES="$FILES roms/seabios/Makefile roms/vgabios/Makefile"
6384 FILES="$FILES pc-bios/qemu-icon.bmp"
6385 for bios_file in \
6386     $source_path/pc-bios/*.bin \
6387     $source_path/pc-bios/*.lid \
6388     $source_path/pc-bios/*.aml \
6389     $source_path/pc-bios/*.rom \
6390     $source_path/pc-bios/*.dtb \
6391     $source_path/pc-bios/*.img \
6392     $source_path/pc-bios/openbios-* \
6393     $source_path/pc-bios/u-boot.* \
6394     $source_path/pc-bios/palcode-*
6395 do
6396     FILES="$FILES pc-bios/$(basename $bios_file)"
6397 done
6398 for test_file in $(find $source_path/tests/acpi-test-data -type f)
6399 do
6400     FILES="$FILES tests/acpi-test-data$(echo $test_file | sed -e 's/.*acpi-test-data//')"
6401 done
6402 mkdir -p $DIRS
6403 for f in $FILES ; do
6404     if [ -e "$source_path/$f" ] && [ "$pwd_is_source_path" != "y" ]; then
6405         symlink "$source_path/$f" "$f"
6406     fi
6407 done
6408
6409 # temporary config to build submodules
6410 for rom in seabios vgabios ; do
6411     config_mak=roms/$rom/config.mak
6412     echo "# Automatically generated by configure - do not modify" > $config_mak
6413     echo "SRC_PATH=$source_path/roms/$rom" >> $config_mak
6414     echo "AS=$as" >> $config_mak
6415     echo "CCAS=$ccas" >> $config_mak
6416     echo "CC=$cc" >> $config_mak
6417     echo "BCC=bcc" >> $config_mak
6418     echo "CPP=$cpp" >> $config_mak
6419     echo "OBJCOPY=objcopy" >> $config_mak
6420     echo "IASL=$iasl" >> $config_mak
6421     echo "LD=$ld" >> $config_mak
6422 done
6423
6424 # set up tests data directory
6425 if [ ! -e tests/data ]; then
6426     symlink "$source_path/tests/data" tests/data
6427 fi
6428
6429 # set up qemu-iotests in this build directory
6430 iotests_common_env="tests/qemu-iotests/common.env"
6431 iotests_check="tests/qemu-iotests/check"
6432
6433 echo "# Automatically generated by configure - do not modify" > "$iotests_common_env"
6434 echo >> "$iotests_common_env"
6435 echo "export PYTHON='$python'" >> "$iotests_common_env"
6436
6437 if [ ! -e "$iotests_check" ]; then
6438     symlink "$source_path/$iotests_check" "$iotests_check"
6439 fi
6440
6441 # Save the configure command line for later reuse.
6442 cat <<EOD >config.status
6443 #!/bin/sh
6444 # Generated by configure.
6445 # Run this file to recreate the current configuration.
6446 # Compiler output produced by configure, useful for debugging
6447 # configure, is in config.log if it exists.
6448 EOD
6449 printf "exec" >>config.status
6450 printf " '%s'" "$0" "$@" >>config.status
6451 echo ' "$@"' >>config.status
6452 chmod +x config.status
6453
6454 rm -r "$TMPDIR1"