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