Fix some compile and linking issues on NetBSD.
[qemu] / configure
1 #!/bin/sh
2 #
3 # qemu configure script (c) 2003 Fabrice Bellard
4 #
5 # set temporary file name
6 if test ! -z "$TMPDIR" ; then
7     TMPDIR1="${TMPDIR}"
8 elif test ! -z "$TEMPDIR" ; then
9     TMPDIR1="${TEMPDIR}"
10 else
11     TMPDIR1="/tmp"
12 fi
13
14 TMPC="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.c"
15 TMPO="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.o"
16 TMPE="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}"
17 TMPS="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.S"
18 TMPI="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.i"
19
20 # default parameters
21 prefix=""
22 interp_prefix="/usr/gnemul/qemu-%M"
23 static="no"
24 cross_prefix=""
25 cc="gcc"
26 gcc3_search="yes"
27 gcc3_list="gcc-3.4.6 gcc-3.4 gcc34 gcc-3.3.6 gcc-3.3 gcc33 gcc-3.2 gcc32"
28 audio_drv_list=""
29 audio_card_list=""
30 host_cc="gcc"
31 ar="ar"
32 make="make"
33 install="install"
34 strip="strip"
35 cpu=`test $(uname -s) = AIX && uname -p || uname -m`
36 target_list=""
37 case "$cpu" in
38   i386|i486|i586|i686|i86pc|BePC)
39     cpu="i386"
40   ;;
41   x86_64|amd64)
42     cpu="x86_64"
43   ;;
44   alpha)
45     cpu="alpha"
46   ;;
47   armv*b)
48     cpu="armv4b"
49   ;;
50   armv*l)
51     cpu="armv4l"
52   ;;
53   cris)
54     cpu="cris"
55   ;;
56   parisc|parisc64)
57     cpu="hppa"
58   ;;
59   ia64)
60     cpu="ia64"
61   ;;
62   m68k)
63     cpu="m68k"
64   ;;
65   mips)
66     cpu="mips"
67   ;;
68   mips64)
69     cpu="mips64"
70   ;;
71   "Power Macintosh"|ppc|ppc64|powerpc)
72     cpu="powerpc"
73   ;;
74   s390*)
75     cpu="s390"
76   ;;
77   sparc|sun4[cdmuv])
78     cpu="sparc"
79   ;;
80   sparc64)
81     cpu="sparc64"
82   ;;
83   *)
84     cpu="unknown"
85   ;;
86 esac
87 gprof="no"
88 sparse="no"
89 bigendian="no"
90 mingw32="no"
91 EXESUF=""
92 gdbstub="yes"
93 slirp="yes"
94 vde="yes"
95 fmod_lib=""
96 fmod_inc=""
97 oss_lib=""
98 vnc_tls="yes"
99 bsd="no"
100 linux="no"
101 solaris="no"
102 kqemu="no"
103 profiler="no"
104 cocoa="no"
105 check_gfx="yes"
106 check_gcc="yes"
107 softmmu="yes"
108 linux_user="no"
109 darwin_user="no"
110 bsd_user="no"
111 build_docs="no"
112 uname_release=""
113 curses="yes"
114 aio="yes"
115 nptl="yes"
116 mixemu="no"
117 bluez="yes"
118 kvm="yes"
119 kerneldir=""
120 aix="no"
121
122 # OS specific
123 targetos=`uname -s`
124 case $targetos in
125 CYGWIN*)
126 mingw32="yes"
127 OS_CFLAGS="-mno-cygwin"
128 if [ "$cpu" = "i386" ] ; then
129     kqemu="yes"
130 fi
131 audio_possible_drivers="sdl"
132 ;;
133 MINGW32*)
134 mingw32="yes"
135 if [ "$cpu" = "i386" ] ; then
136     kqemu="yes"
137 fi
138 audio_possible_drivers="dsound sdl fmod"
139 ;;
140 GNU/kFreeBSD)
141 audio_drv_list="oss"
142 audio_possible_drivers="oss sdl esd pa"
143 if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
144     kqemu="yes"
145 fi
146 ;;
147 FreeBSD)
148 bsd="yes"
149 audio_drv_list="oss"
150 audio_possible_drivers="oss sdl esd pa"
151 aiolib="-lpthread"
152 if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
153     kqemu="yes"
154 fi
155 ;;
156 NetBSD)
157 bsd="yes"
158 audio_drv_list="oss"
159 audio_possible_drivers="oss sdl esd"
160 oss_lib="-lossaudio"
161 aio_lib="-lrt -lpthread"
162 ;;
163 OpenBSD)
164 bsd="yes"
165 openbsd="yes"
166 audio_drv_list="oss"
167 audio_possible_drivers="oss sdl esd"
168 oss_lib="-lossaudio"
169 aio_lib="-lpthread"
170 ;;
171 Darwin)
172 bsd="yes"
173 darwin="yes"
174 darwin_user="yes"
175 cocoa="yes"
176 audio_drv_list="coreaudio"
177 audio_possible_drivers="coreaudio sdl fmod"
178 OS_CFLAGS="-mdynamic-no-pic"
179 OS_LDFLAGS="-framework CoreFoundation -framework IOKit"
180 aio_lib="-lpthread"
181 ;;
182 SunOS)
183     solaris="yes"
184     make="gmake"
185     install="ginstall"
186     needs_libsunmath="no"
187     solarisrev=`uname -r | cut -f2 -d.`
188     # have to select again, because `uname -m` returns i86pc
189     # even on an x86_64 box.
190     solariscpu=`isainfo -k`
191     if test "${solariscpu}" = "amd64" ; then
192         cpu="x86_64"
193     fi
194     if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
195         if test "$solarisrev" -le 9 ; then
196             if test -f /opt/SUNWspro/prod/lib/libsunmath.so.1; then
197                 needs_libsunmath="yes"
198             else
199                 echo "QEMU will not link correctly on Solaris 8/X86 or 9/x86 without"
200                 echo "libsunmath from the Sun Studio compilers tools, due to a lack of"
201                 echo "C99 math features in libm.so in Solaris 8/x86 and Solaris 9/x86"
202                 echo "Studio 11 can be downloaded from www.sun.com."
203                 exit 1
204             fi
205         fi
206         if test "$solarisrev" -ge 9 ; then
207             kqemu="yes"
208         fi
209     fi
210     if test -f /usr/include/sys/soundcard.h ; then
211         audio_drv_list="oss"
212     fi
213     audio_possible_drivers="oss sdl"
214 ;;
215 AIX)
216 aix="yes"
217 make="gmake"
218 ;;
219 *)
220 audio_drv_list="oss"
221 audio_possible_drivers="oss alsa sdl esd pa"
222 linux="yes"
223 linux_user="yes"
224 if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
225     kqemu="yes"
226     audio_possible_drivers="$audio_possible_drivers fmod"
227 fi
228 ;;
229 esac
230
231 if [ "$bsd" = "yes" ] ; then
232   if [ "$darwin" != "yes" ] ; then
233     make="gmake"
234   fi
235   bsd_user="yes"
236 fi
237
238 # find source path
239 source_path=`dirname "$0"`
240 source_path_used="no"
241 workdir=`pwd`
242 if [ -z "$source_path" ]; then
243     source_path=$workdir
244 else
245     source_path=`cd "$source_path"; pwd`
246 fi
247 [ -f "$workdir/vl.c" ] || source_path_used="yes"
248
249 werror="no"
250 # generate compile errors on warnings for development builds
251 #if grep cvs $source_path/VERSION > /dev/null 2>&1 ; then
252 #werror="yes";
253 #fi
254
255 for opt do
256   optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
257   case "$opt" in
258   --help|-h) show_help=yes
259   ;;
260   --prefix=*) prefix="$optarg"
261   ;;
262   --interp-prefix=*) interp_prefix="$optarg"
263   ;;
264   --source-path=*) source_path="$optarg"
265   source_path_used="yes"
266   ;;
267   --cross-prefix=*) cross_prefix="$optarg"
268   ;;
269   --cc=*) cc="$optarg"
270   gcc3_search="no"
271   ;;
272   --host-cc=*) host_cc="$optarg"
273   ;;
274   --make=*) make="$optarg"
275   ;;
276   --install=*) install="$optarg"
277   ;;
278   --extra-cflags=*) CFLAGS="$optarg"
279   ;;
280   --extra-ldflags=*) LDFLAGS="$optarg"
281   ;;
282   --cpu=*) cpu="$optarg"
283   ;;
284   --target-list=*) target_list="$optarg"
285   ;;
286   --enable-gprof) gprof="yes"
287   ;;
288   --static) static="yes"
289   ;;
290   --disable-sdl) sdl="no"
291   ;;
292   --fmod-lib=*) fmod_lib="$optarg"
293   ;;
294   --fmod-inc=*) fmod_inc="$optarg"
295   ;;
296   --oss-lib=*) oss_lib="$optarg"
297   ;;
298   --audio-card-list=*) audio_card_list=`echo "$optarg" | sed -e 's/,/ /g'`
299   ;;
300   --audio-drv-list=*) audio_drv_list="$optarg"
301   ;;
302   --enable-sparse) sparse="yes"
303   ;;
304   --disable-sparse) sparse="no"
305   ;;
306   --disable-vnc-tls) vnc_tls="no"
307   ;;
308   --disable-slirp) slirp="no"
309   ;;
310   --disable-vde) vde="no"
311   ;;
312   --disable-kqemu) kqemu="no"
313   ;;
314   --disable-brlapi) brlapi="no"
315   ;;
316   --disable-bluez) bluez="no"
317   ;;
318   --disable-kvm) kvm="no"
319   ;;
320   --enable-profiler) profiler="yes"
321   ;;
322   --enable-cocoa)
323       cocoa="yes" ;
324       sdl="no" ;
325       audio_drv_list="coreaudio `echo $audio_drv_list | sed s,coreaudio,,g`"
326   ;;
327   --disable-gfx-check) check_gfx="no"
328   ;;
329   --disable-gcc-check) check_gcc="no"
330   ;;
331   --disable-system) softmmu="no"
332   ;;
333   --enable-system) softmmu="yes"
334   ;;
335   --disable-linux-user) linux_user="no"
336   ;;
337   --enable-linux-user) linux_user="yes"
338   ;;
339   --disable-darwin-user) darwin_user="no"
340   ;;
341   --enable-darwin-user) darwin_user="yes"
342   ;;
343   --disable-bsd-user) bsd_user="no"
344   ;;
345   --enable-bsd-user) bsd_user="yes"
346   ;;
347   --enable-uname-release=*) uname_release="$optarg"
348   ;;
349   --sparc_cpu=*)
350       sparc_cpu="$optarg"
351       case $sparc_cpu in
352         v7|v8) SP_CFLAGS="-m32 -mcpu=${sparc_cpu} -D__sparc_${sparc_cpu}__"; SP_LDFLAGS="-m32"
353                  target_cpu="sparc"; cpu="sparc" ;;
354         v8plus|v8plusa) SP_CFLAGS="-m32 -mcpu=ultrasparc -D__sparc_${sparc_cpu}__"; SP_LDFLAGS="-m32"
355                  target_cpu="sparc"; cpu="sparc" ;;
356         v9)    SP_CFLAGS="-m64 -mcpu=ultrasparc -D__sparc_${sparc_cpu}__"; SP_LDFLAGS="-m64"
357                  target_cpu="sparc64"; cpu="sparc64" ;;
358         *)     echo "undefined SPARC architecture. Exiting";exit 1;;
359       esac
360   ;;
361   --enable-werror) werror="yes"
362   ;;
363   --disable-werror) werror="no"
364   ;;
365   --disable-curses) curses="no"
366   ;;
367   --disable-nptl) nptl="no"
368   ;;
369   --enable-mixemu) mixemu="yes"
370   ;;
371   --disable-aio) aio="no"
372   ;;
373   --kerneldir=*) kerneldir="$optarg"
374   ;;
375   *) echo "ERROR: unknown option $opt"; show_help="yes"
376   ;;
377   esac
378 done
379
380 # default flags for all hosts
381 CFLAGS="$CFLAGS -O2 -g -fno-strict-aliasing"
382 CFLAGS="$CFLAGS -Wall -Wundef -Wendif-labels -Wwrite-strings"
383 LDFLAGS="$LDFLAGS -g"
384 if test "$werror" = "yes" ; then
385 CFLAGS="$CFLAGS -Werror"
386 fi
387
388 if test "$solaris" = "no" ; then
389     if ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
390         LDFLAGS="$LDFLAGS -Wl,--warn-common"
391     fi
392 fi
393
394 #
395 # If cpu ~= sparc and  sparc_cpu hasn't been defined, plug in the right
396 # ARCH_CFLAGS/ARCH_LDFLAGS (assume sparc_v8plus for 32-bit and sparc_v9 for 64-bit)
397 #
398 case "$cpu" in
399     sparc) if test -z "$sparc_cpu" ; then
400                ARCH_CFLAGS="-m32 -mcpu=ultrasparc -D__sparc_v8plus__"
401                ARCH_LDFLAGS="-m32"
402            else
403                ARCH_CFLAGS="${SP_CFLAGS}"
404                ARCH_LDFLAGS="${SP_LDFLAGS}"
405            fi
406            ;;
407     sparc64) if test -z "$sparc_cpu" ; then
408                ARCH_CFLAGS="-m64 -mcpu=ultrasparc -D__sparc_v9__"
409                ARCH_LDFLAGS="-m64"
410            else
411                ARCH_CFLAGS="${SP_CFLAGS}"
412                ARCH_LDFLAGS="${SP_LDFLAGS}"
413            fi
414            ;;
415     s390)
416            ARCH_CFLAGS="-march=z900"
417            ;;
418     i386)
419            ARCH_CFLAGS="-m32"
420            ARCH_LDFLAGS="-m32"
421            ;;
422     x86_64)
423            ARCH_CFLAGS="-m64"
424            ARCH_LDFLAGS="-m64"
425            ;;
426 esac
427
428 if test x"$show_help" = x"yes" ; then
429 cat << EOF
430
431 Usage: configure [options]
432 Options: [defaults in brackets after descriptions]
433
434 EOF
435 echo "Standard options:"
436 echo "  --help                   print this message"
437 echo "  --prefix=PREFIX          install in PREFIX [$prefix]"
438 echo "  --interp-prefix=PREFIX   where to find shared libraries, etc."
439 echo "                           use %M for cpu name [$interp_prefix]"
440 echo "  --target-list=LIST       set target list [$target_list]"
441 echo ""
442 echo "kqemu kernel acceleration support:"
443 echo "  --disable-kqemu          disable kqemu support"
444 echo ""
445 echo "Advanced options (experts only):"
446 echo "  --source-path=PATH       path of source code [$source_path]"
447 echo "  --cross-prefix=PREFIX    use PREFIX for compile tools [$cross_prefix]"
448 echo "  --cc=CC                  use C compiler CC [$cc]"
449 echo "  --host-cc=CC             use C compiler CC [$host_cc] for dyngen etc."
450 echo "  --make=MAKE              use specified make [$make]"
451 echo "  --install=INSTALL        use specified install [$install]"
452 echo "  --static                 enable static build [$static]"
453 echo "  --enable-sparse          enable sparse checker"
454 echo "  --disable-sparse         disable sparse checker (default)"
455 echo "  --disable-werror         disable compilation abort on warning"
456 echo "  --disable-sdl            disable SDL"
457 echo "  --enable-cocoa           enable COCOA (Mac OS X only)"
458 echo "  --audio-drv-list=LIST    set audio drivers list:"
459 echo "                           Available drivers: $audio_possible_drivers"
460 echo "  --audio-card-list=LIST   set list of additional emulated audio cards"
461 echo "                           Available cards: ac97 adlib cs4231a gus"
462 echo "  --enable-mixemu          enable mixer emulation"
463 echo "  --disable-brlapi         disable BrlAPI"
464 echo "  --disable-vnc-tls        disable TLS encryption for VNC server"
465 echo "  --disable-curses         disable curses output"
466 echo "  --disable-bluez          disable bluez stack connectivity"
467 echo "  --disable-kvm            disable KVM acceleration support"
468 echo "  --disable-nptl           disable usermode NPTL support"
469 echo "  --enable-system          enable all system emulation targets"
470 echo "  --disable-system         disable all system emulation targets"
471 echo "  --enable-linux-user      enable all linux usermode emulation targets"
472 echo "  --disable-linux-user     disable all linux usermode emulation targets"
473 echo "  --enable-darwin-user     enable all darwin usermode emulation targets"
474 echo "  --disable-darwin-user    disable all darwin usermode emulation targets"
475 echo "  --enable-bsd-user        enable all BSD usermode emulation targets"
476 echo "  --disable-bsd-user       disable all BSD usermode emulation targets"
477 echo "  --fmod-lib               path to FMOD library"
478 echo "  --fmod-inc               path to FMOD includes"
479 echo "  --oss-lib                path to OSS library"
480 echo "  --enable-uname-release=R Return R for uname -r in usermode emulation"
481 echo "  --sparc_cpu=V            Build qemu for Sparc architecture v7, v8, v8plus, v8plusa, v9"
482 echo "  --disable-vde            disable support for vde network"
483 echo "  --disable-aio            disable AIO support"
484 echo "  --kerneldir=PATH         look for kernel includes in PATH"
485 echo ""
486 echo "NOTE: The object files are built at the place where configure is launched"
487 exit 1
488 fi
489
490 cc="${cross_prefix}${cc}"
491 ar="${cross_prefix}${ar}"
492 strip="${cross_prefix}${strip}"
493
494 # check that the C compiler works.
495 cat > $TMPC <<EOF
496 int main(void) {}
497 EOF
498
499 if $cc $ARCH_CFLAGS -c -o $TMPO $TMPC 2> /dev/null ; then
500   : C compiler works ok
501 else
502     echo "ERROR: \"$cc\" either does not exist or does not work"
503     exit 1
504 fi
505
506 # check compiler to see if we're on mingw32
507 cat > $TMPC <<EOF
508 #include <windows.h>
509 #ifndef _WIN32
510 #error not windows
511 #endif
512 int main(void) {}
513 EOF
514
515 if $cc $ARCH_CFLAGS -c -o $TMPO $TMPC 2> /dev/null ; then
516     mingw32="yes"
517 fi
518
519 if test "$mingw32" = "yes" ; then
520     linux="no"
521     EXESUF=".exe"
522     oss="no"
523     linux_user="no"
524     bsd_user="no"
525 fi
526
527 if [ "$darwin" = "yes" -o "$mingw32" = "yes" ] ; then
528     AIOLIBS=
529 elif [ "$bsd" = "yes" ]; then
530     AIOLIBS="$aio_lib"
531 else
532     # Some Linux architectures (e.g. s390) don't imply -lpthread automatically.
533     AIOLIBS="-lrt -lpthread"
534 fi
535
536 # Check for gcc4, error if pre-gcc4
537 if test "$check_gcc" = "yes" ; then
538     cat > $TMPC <<EOF
539 #if __GNUC__ < 4
540 #error gcc3
541 #endif
542 int main(){return 0;}
543 EOF
544     if "$cc" $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
545         echo "WARNING: \"$cc\" looks like gcc 4.x"
546         found_compat_cc="no"
547         if test "$gcc3_search" = "yes" ; then
548             echo "Looking for gcc 3.x"
549             for compat_cc in $gcc3_list ; do
550                 if "$cross_prefix$compat_cc" --version 2> /dev/null | fgrep '(GCC) 3.' > /dev/null 2>&1 ; then
551                     echo "Found \"$compat_cc\""
552                     cc="$cross_prefix$compat_cc"
553                     found_compat_cc="yes"
554                     break
555                 fi
556             done
557             if test "$found_compat_cc" = "no" ; then
558                 echo "gcc 3.x not found!"
559             fi
560         fi
561         if test "$found_compat_cc" = "no" ; then
562             echo "QEMU is known to have problems when compiled with gcc 4.x"
563             echo "It is recommended that you use gcc 3.x to build QEMU"
564             echo "To use this compiler anyway, configure with --disable-gcc-check"
565             exit 1;
566         fi
567     fi
568 fi
569
570 if test ! -x "$(which cgcc 2>/dev/null)"; then
571     sparse="no"
572 fi
573
574 #
575 # Solaris specific configure tool chain decisions
576 #
577 if test "$solaris" = "yes" ; then
578   #
579   # gcc for solaris 10/fcs in /usr/sfw/bin doesn't compile qemu correctly
580   # override the check with --disable-gcc-check
581   #
582   if test "$solarisrev" -eq 10 -a "$check_gcc" = "yes" ; then
583     solgcc=`which $cc`
584     if test "$solgcc" = "/usr/sfw/bin/gcc" ; then
585       echo "Solaris 10/FCS gcc in /usr/sfw/bin will not compiled qemu correctly."
586       echo "please get gcc-3.4.3 or later, from www.blastwave.org using pkg-get -i gcc3"
587       echo "or get the latest patch from SunSolve for gcc"
588       exit 1
589     fi
590   fi
591   solinst=`which $install 2> /dev/null | /usr/bin/grep -v "no $install in"`
592   if test -z "$solinst" ; then
593     echo "Solaris install program not found. Use --install=/usr/ucb/install or"
594     echo "install fileutils from www.blastwave.org using pkg-get -i fileutils"
595     echo "to get ginstall which is used by default (which lives in /opt/csw/bin)"
596     exit 1
597   fi
598   if test "$solinst" = "/usr/sbin/install" ; then
599     echo "Error: Solaris /usr/sbin/install is not an appropriate install program."
600     echo "try ginstall from the GNU fileutils available from www.blastwave.org"
601     echo "using pkg-get -i fileutils, or use --install=/usr/ucb/install"
602     exit 1
603   fi
604   sol_ar=`which ar 2> /dev/null | /usr/bin/grep -v "no ar in"`
605   if test -z "$sol_ar" ; then
606     echo "Error: No path includes ar"
607     if test -f /usr/ccs/bin/ar ; then
608       echo "Add /usr/ccs/bin to your path and rerun configure"
609     fi
610     exit 1
611   fi
612 fi
613
614
615 if test -z "$target_list" ; then
616 # these targets are portable
617     if [ "$softmmu" = "yes" ] ; then
618         target_list="\
619 i386-softmmu \
620 x86_64-softmmu \
621 arm-softmmu \
622 cris-softmmu \
623 m68k-softmmu \
624 mips-softmmu \
625 mipsel-softmmu \
626 mips64-softmmu \
627 mips64el-softmmu \
628 ppc-softmmu \
629 ppcemb-softmmu \
630 ppc64-softmmu \
631 sh4-softmmu \
632 sh4eb-softmmu \
633 sparc-softmmu \
634 "
635     fi
636 # the following are Linux specific
637     if [ "$linux_user" = "yes" ] ; then
638         target_list="${target_list}\
639 i386-linux-user \
640 x86_64-linux-user \
641 alpha-linux-user \
642 arm-linux-user \
643 armeb-linux-user \
644 cris-linux-user \
645 m68k-linux-user \
646 mips-linux-user \
647 mipsel-linux-user \
648 ppc-linux-user \
649 ppc64-linux-user \
650 ppc64abi32-linux-user \
651 sh4-linux-user \
652 sh4eb-linux-user \
653 sparc-linux-user \
654 sparc64-linux-user \
655 sparc32plus-linux-user \
656 "
657     fi
658 # the following are Darwin specific
659     if [ "$darwin_user" = "yes" ] ; then
660         target_list="$target_list i386-darwin-user ppc-darwin-user"
661     fi
662 # the following are BSD specific
663     if [ "$bsd_user" = "yes" ] ; then
664         target_list="${target_list}\
665 sparc64-bsd-user \
666 "
667     fi
668 else
669     target_list=`echo "$target_list" | sed -e 's/,/ /g'`
670 fi
671 if test -z "$target_list" ; then
672     echo "No targets enabled"
673     exit 1
674 fi
675
676 if test -z "$cross_prefix" ; then
677
678 # ---
679 # big/little endian test
680 cat > $TMPC << EOF
681 #include <inttypes.h>
682 int main(int argc, char ** argv){
683         volatile uint32_t i=0x01234567;
684         return (*((uint8_t*)(&i))) == 0x67;
685 }
686 EOF
687
688 if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
689 $TMPE && bigendian="yes"
690 else
691 echo big/little test failed
692 fi
693
694 else
695
696 # if cross compiling, cannot launch a program, so make a static guess
697 if test "$cpu" = "armv4b" \
698      -o "$cpu" = "hppa" \
699      -o "$cpu" = "m68k" \
700      -o "$cpu" = "mips" \
701      -o "$cpu" = "mips64" \
702      -o "$cpu" = "powerpc" \
703      -o "$cpu" = "s390" \
704      -o "$cpu" = "sparc" \
705      -o "$cpu" = "sparc64"; then
706     bigendian="yes"
707 fi
708
709 fi
710
711 # host long bits test
712 hostlongbits="32"
713 if test "$cpu" = "x86_64" \
714      -o "$cpu" = "alpha" \
715      -o "$cpu" = "ia64" \
716      -o "$cpu" = "sparc64"; then
717     hostlongbits="64"
718 fi
719
720 # ppc specific hostlongbits selection
721 if test "$cpu" = "powerpc" ; then
722     if $cc $ARCH_CFLAGS -dM -E - -o $TMPI 2>/dev/null </dev/null; then
723         grep -q __powerpc64__ $TMPI && hostlongbits=64
724     else
725         echo hostlongbits test failed
726         exit 1
727     fi
728 fi
729
730 # check gcc options support
731 cat > $TMPC <<EOF
732 int main(void) {
733 }
734 EOF
735
736 # Check host NPTL support
737 cat > $TMPC <<EOF
738 #include <sched.h>
739 #include <linux/futex.h>
740 void foo()
741 {
742 #if !defined(CLONE_SETTLS) || !defined(FUTEX_WAIT)
743 #error bork
744 #endif
745 }
746 EOF
747
748 if $cc $ARCH_CFLAGS -c -o $TMPO $TMPC 2> /dev/null ; then
749   :
750 else
751    nptl="no"
752 fi
753
754 ##########################################
755 # zlib check
756
757 cat > $TMPC << EOF
758 #include <zlib.h>
759 int main(void) { zlibVersion(); return 0; }
760 EOF
761 if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $TMPC -lz 2> /dev/null ; then
762     :
763 else
764     echo
765     echo "Error: zlib check failed"
766     echo "Make sure to have the zlib libs and headers installed."
767     echo
768     exit 1
769 fi
770
771 ##########################################
772 # SDL probe
773
774 sdl_too_old=no
775
776 if test -z "$sdl" ; then
777     sdl_config="sdl-config"
778     sdl=no
779     sdl_static=no
780
781 cat > $TMPC << EOF
782 #include <SDL.h>
783 #undef main /* We don't want SDL to override our main() */
784 int main( void ) { return SDL_Init (SDL_INIT_VIDEO); }
785 EOF
786     if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} `$sdl_config --cflags 2> /dev/null` $TMPC `$sdl_config --libs 2> /dev/null` 2> /tmp/qemu-$$-sdl-config.log ; then
787         _sdlversion=`$sdl_config --version | sed 's/[^0-9]//g'`
788         if test "$_sdlversion" -lt 121 ; then
789             sdl_too_old=yes
790         else
791             if test "$cocoa" = "no" ; then
792                 sdl=yes
793             fi
794         fi
795
796         # static link with sdl ?
797         if test "$sdl" = "yes" ; then
798             aa="no"
799             `$sdl_config --static-libs 2>/dev/null | grep \\\-laa > /dev/null` && aa="yes"
800             sdl_static_libs=`$sdl_config --static-libs 2>/dev/null`
801             if [ "$aa" = "yes" ] ; then
802                 sdl_static_libs="$sdl_static_libs `aalib-config --static-libs`"
803             fi
804
805             if $cc -o $TMPE ${OS_CFLAGS} `$sdl_config --cflags 2> /dev/null` $TMPC $sdl_static_libs 2> /dev/null; then
806                 sdl_static=yes
807             fi
808         fi # static link
809     fi # sdl compile test
810 else
811     # Make sure to disable cocoa if sdl was set
812     if test "$sdl" = "yes" ; then
813        cocoa="no"
814        audio_drv_list="`echo $audio_drv_list | sed s,coreaudio,,g`"
815     fi
816 fi # -z $sdl
817
818 ##########################################
819 # VNC TLS detection
820 if test "$vnc_tls" = "yes" ; then
821 cat > $TMPC <<EOF
822 #include <gnutls/gnutls.h>
823 int main(void) { gnutls_session_t s; gnutls_init(&s, GNUTLS_SERVER); return 0; }
824 EOF
825     vnc_tls_cflags=`pkg-config --cflags gnutls 2> /dev/null`
826     vnc_tls_libs=`pkg-config --libs gnutls 2> /dev/null`
827     if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $vnc_tls_cflags $TMPC \
828            $vnc_tls_libs 2> /dev/null ; then
829         :
830     else
831         vnc_tls="no"
832     fi
833 fi
834
835 ##########################################
836 # vde libraries probe
837 if test "$vde" = "yes" ; then
838   cat > $TMPC << EOF
839 #include <libvdeplug.h>
840 int main(void)
841 {
842     struct vde_open_args a = {0, 0, 0};
843     vde_open("", "", &a);
844     return 0;
845 }
846 EOF
847     if $cc $ARCH_CFLAGS -o $TMPE $TMPC -lvdeplug 2> /dev/null ; then
848         :
849     else
850         vde="no"
851     fi
852 fi
853
854 ##########################################
855 # Sound support libraries probe
856
857 audio_drv_probe()
858 {
859     drv=$1
860     hdr=$2
861     lib=$3
862     exp=$4
863     cfl=$5
864         cat > $TMPC << EOF
865 #include <$hdr>
866 int main(void) { $exp }
867 EOF
868     if $cc $ARCH_CFLAGS $cfl -o $TMPE $TMPC $lib 2> /dev/null ; then
869         :
870     else
871         echo
872         echo "Error: $drv check failed"
873         echo "Make sure to have the $drv libs and headers installed."
874         echo
875         exit 1
876     fi
877 }
878
879 audio_drv_list=`echo "$audio_drv_list" | sed -e 's/,/ /g'`
880 for drv in $audio_drv_list; do
881     case $drv in
882     alsa)
883     audio_drv_probe $drv alsa/asoundlib.h -lasound \
884         "snd_pcm_t **handle; return snd_pcm_close(*handle);"
885     ;;
886
887     fmod)
888     if test -z $fmod_lib || test -z $fmod_inc; then
889         echo
890         echo "Error: You must specify path to FMOD library and headers"
891         echo "Example: --fmod-inc=/path/include/fmod --fmod-lib=/path/lib/libfmod-3.74.so"
892         echo
893         exit 1
894     fi
895     audio_drv_probe $drv fmod.h $fmod_lib "return FSOUND_GetVersion();" "-I $fmod_inc"
896     ;;
897
898     esd)
899     audio_drv_probe $drv esd.h -lesd 'return esd_play_stream(0, 0, "", 0);'
900     ;;
901
902     pa)
903     audio_drv_probe $drv pulse/simple.h -lpulse-simple \
904         "pa_simple *s = NULL; pa_simple_free(s); return 0;"
905     ;;
906
907     oss|sdl|core|wav|dsound)
908     # XXX: Probes for CoreAudio, DirectSound, SDL(?)
909     ;;
910
911     *)
912     echo "$audio_possible_drivers" | grep -q "\<$drv\>" || {
913         echo
914         echo "Error: Unknown driver '$drv' selected"
915         echo "Possible drivers are: $audio_possible_drivers"
916         echo
917         exit 1
918     }
919     ;;
920     esac
921 done
922
923 ##########################################
924 # BrlAPI probe
925
926 if test -z "$brlapi" ; then
927     brlapi=no
928 cat > $TMPC << EOF
929 #include <brlapi.h>
930 int main( void ) { return brlapi__openConnection (NULL, NULL, NULL); }
931 EOF
932     if $cc ${ARCH_CFLAGS} -o $TMPE ${OS_CFLAGS} $TMPC -lbrlapi 2> /dev/null ; then
933             brlapi=yes
934     fi # brlapi compile test
935 fi # -z $brlapi
936
937 ##########################################
938 # curses probe
939
940 if test "$curses" = "yes" ; then
941   curses=no
942   cat > $TMPC << EOF
943 #include <curses.h>
944 int main(void) { return curses_version(); }
945 EOF
946   if $cc $ARCH_CFLAGS -o $TMPE $TMPC -lcurses 2> /dev/null ; then
947     curses=yes
948   fi
949 fi # test "$curses"
950
951 ##########################################
952 # bluez support probe
953 if test "$bluez" = "yes" ; then
954   `pkg-config bluez` || bluez="no"
955 fi
956 if test "$bluez" = "yes" ; then
957   cat > $TMPC << EOF
958 #include <bluetooth/bluetooth.h>
959 int main(void) { return bt_error(0); }
960 EOF
961   bluez_cflags=`pkg-config --cflags bluez`
962   bluez_libs=`pkg-config --libs bluez`
963   if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $bluez_cflags $TMPC \
964       $bluez_libs 2> /dev/null ; then
965     :
966   else
967     bluez="no"
968   fi
969 fi
970
971 ##########################################
972 # kvm probe
973 if test "$kvm" = "yes" ; then
974     cat > $TMPC <<EOF
975 #include <linux/kvm.h>
976 #if !defined(KVM_API_VERSION) || \
977     KVM_API_VERSION < 12 || \
978     KVM_API_VERSION > 12 || \
979     !defined(KVM_CAP_USER_MEMORY) || \
980     !defined(KVM_CAP_SET_TSS_ADDR)
981 #error Invalid KVM version
982 #endif
983 int main(void) { return 0; }
984 EOF
985   if test "$kerneldir" != "" ; then
986       kvm_cflags=-I"$kerneldir"/include
987   else
988       kvm_cflags=""
989   fi
990   if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $kvm_cflags $TMPC \
991       2>/dev/null ; then
992     :
993   else
994     kvm="no"
995   fi
996 fi
997
998 ##########################################
999 # AIO probe
1000 if test "$aio" = "yes" ; then
1001   aio=no
1002   cat > $TMPC << EOF
1003 #include <aio.h>
1004 int main(void) { return aio_write(NULL); }
1005 EOF
1006   if $cc $ARCH_CFLAGS -o $TMPE $AIOLIBS $TMPC 2> /dev/null ; then
1007     aio=yes
1008   fi
1009 fi
1010
1011 # Check if tools are available to build documentation.
1012 if [ -x "`which texi2html 2>/dev/null`" ] && \
1013    [ -x "`which pod2man 2>/dev/null`" ]; then
1014   build_docs="yes"
1015 fi
1016
1017 if test "$mingw32" = "yes" ; then
1018   if test -z "$prefix" ; then
1019       prefix="c:\\\\Program Files\\\\Qemu"
1020   fi
1021   mansuffix=""
1022   datasuffix=""
1023   docsuffix=""
1024   binsuffix=""
1025 else
1026   if test -z "$prefix" ; then
1027       prefix="/usr/local"
1028   fi
1029   mansuffix="/share/man"
1030   datasuffix="/share/qemu"
1031   docsuffix="/share/doc/qemu"
1032   binsuffix="/bin"
1033 fi
1034
1035 echo "Install prefix    $prefix"
1036 echo "BIOS directory    $prefix$datasuffix"
1037 echo "binary directory  $prefix$binsuffix"
1038 if test "$mingw32" = "no" ; then
1039 echo "Manual directory  $prefix$mansuffix"
1040 echo "ELF interp prefix $interp_prefix"
1041 fi
1042 echo "Source path       $source_path"
1043 echo "C compiler        $cc"
1044 echo "Host C compiler   $host_cc"
1045 echo "ARCH_CFLAGS       $ARCH_CFLAGS"
1046 echo "make              $make"
1047 echo "install           $install"
1048 echo "host CPU          $cpu"
1049 echo "host big endian   $bigendian"
1050 echo "target list       $target_list"
1051 echo "gprof enabled     $gprof"
1052 echo "sparse enabled    $sparse"
1053 echo "profiler          $profiler"
1054 echo "static build      $static"
1055 echo "-Werror enabled   $werror"
1056 if test "$darwin" = "yes" ; then
1057     echo "Cocoa support     $cocoa"
1058 fi
1059 echo "SDL support       $sdl"
1060 if test "$sdl" != "no" ; then
1061     echo "SDL static link   $sdl_static"
1062 fi
1063 echo "curses support    $curses"
1064 echo "mingw32 support   $mingw32"
1065 echo "Audio drivers     $audio_drv_list"
1066 echo "Extra audio cards $audio_card_list"
1067 echo "Mixer emulation   $mixemu"
1068 echo "VNC TLS support   $vnc_tls"
1069 if test "$vnc_tls" = "yes" ; then
1070     echo "    TLS CFLAGS    $vnc_tls_cflags"
1071     echo "    TLS LIBS      $vnc_tls_libs"
1072 fi
1073 if test -n "$sparc_cpu"; then
1074     echo "Target Sparc Arch $sparc_cpu"
1075 fi
1076 echo "kqemu support     $kqemu"
1077 echo "brlapi support    $brlapi"
1078 echo "Documentation     $build_docs"
1079 [ ! -z "$uname_release" ] && \
1080 echo "uname -r          $uname_release"
1081 echo "NPTL support      $nptl"
1082 echo "vde support       $vde"
1083 echo "AIO support       $aio"
1084 echo "KVM support       $kvm"
1085
1086 if test $sdl_too_old = "yes"; then
1087 echo "-> Your SDL version is too old - please upgrade to have SDL support"
1088 fi
1089 if [ -s /tmp/qemu-$$-sdl-config.log ]; then
1090   echo "The error log from compiling the libSDL test is: "
1091   cat /tmp/qemu-$$-sdl-config.log
1092 fi
1093 rm -f /tmp/qemu-$$-sdl-config.log
1094 #if test "$sdl_static" = "no"; then
1095 #  echo "WARNING: cannot compile statically with SDL - qemu-fast won't have a graphical output"
1096 #fi
1097 config_mak="config-host.mak"
1098 config_h="config-host.h"
1099
1100 #echo "Creating $config_mak and $config_h"
1101
1102 test -f $config_h && mv $config_h ${config_h}~
1103
1104 echo "# Automatically generated by configure - do not modify" > $config_mak
1105 echo "# Configured with: $0 $@" >> $config_mak
1106 echo "/* Automatically generated by configure - do not modify */" > $config_h
1107
1108 echo "prefix=$prefix" >> $config_mak
1109 echo "bindir=\${prefix}$binsuffix" >> $config_mak
1110 echo "mandir=\${prefix}$mansuffix" >> $config_mak
1111 echo "datadir=\${prefix}$datasuffix" >> $config_mak
1112 echo "docdir=\${prefix}$docsuffix" >> $config_mak
1113 echo "#define CONFIG_QEMU_SHAREDIR \"$prefix$datasuffix\"" >> $config_h
1114 echo "MAKE=$make" >> $config_mak
1115 echo "INSTALL=$install" >> $config_mak
1116 echo "CC=$cc" >> $config_mak
1117 echo "HOST_CC=$host_cc" >> $config_mak
1118 echo "AR=$ar" >> $config_mak
1119 echo "STRIP=$strip -s -R .comment -R .note" >> $config_mak
1120 # XXX: only use CFLAGS and LDFLAGS ?  
1121 # XXX: should export HOST_CFLAGS and HOST_LDFLAGS for cross
1122 # compilation of dyngen tool (useful for win32 build on Linux host)
1123 echo "OS_CFLAGS=$OS_CFLAGS" >> $config_mak
1124 echo "OS_LDFLAGS=$OS_LDFLAGS" >> $config_mak
1125 echo "ARCH_CFLAGS=$ARCH_CFLAGS" >> $config_mak
1126 echo "ARCH_LDFLAGS=$ARCH_LDFLAGS" >> $config_mak
1127 echo "CFLAGS=$CFLAGS" >> $config_mak
1128 echo "LDFLAGS=$LDFLAGS" >> $config_mak
1129 echo "EXESUF=$EXESUF" >> $config_mak
1130 echo "AIOLIBS=$AIOLIBS" >> $config_mak
1131 case "$cpu" in
1132   i386)
1133     echo "ARCH=i386" >> $config_mak
1134     echo "#define HOST_I386 1" >> $config_h
1135   ;;
1136   x86_64)
1137     echo "ARCH=x86_64" >> $config_mak
1138     echo "#define HOST_X86_64 1" >> $config_h
1139   ;;
1140   alpha)
1141     echo "ARCH=alpha" >> $config_mak
1142     echo "#define HOST_ALPHA 1" >> $config_h
1143   ;;
1144   armv4b)
1145     echo "ARCH=arm" >> $config_mak
1146     echo "#define HOST_ARM 1" >> $config_h
1147   ;;
1148   armv4l)
1149     echo "ARCH=arm" >> $config_mak
1150     echo "#define HOST_ARM 1" >> $config_h
1151   ;;
1152   cris)
1153     echo "ARCH=cris" >> $config_mak
1154     echo "#define HOST_CRIS 1" >> $config_h
1155   ;;
1156   hppa)
1157     echo "ARCH=hppa" >> $config_mak
1158     echo "#define HOST_HPPA 1" >> $config_h
1159   ;;
1160   ia64)
1161     echo "ARCH=ia64" >> $config_mak
1162     echo "#define HOST_IA64 1" >> $config_h
1163   ;;
1164   m68k)
1165     echo "ARCH=m68k" >> $config_mak
1166     echo "#define HOST_M68K 1" >> $config_h
1167   ;;
1168   mips)
1169     echo "ARCH=mips" >> $config_mak
1170     echo "#define HOST_MIPS 1" >> $config_h
1171   ;;
1172   mips64)
1173     echo "ARCH=mips64" >> $config_mak
1174     echo "#define HOST_MIPS64 1" >> $config_h
1175   ;;
1176   powerpc)
1177   if test "$hostlongbits" = "32"; then
1178       echo "ARCH=ppc" >> $config_mak
1179       echo "#define HOST_PPC 1" >> $config_h
1180   else
1181       echo "ARCH=ppc64" >> $config_mak
1182       echo "#define HOST_PPC64 1" >> $config_h
1183   fi
1184   ;;
1185   s390)
1186     echo "ARCH=s390" >> $config_mak
1187     echo "#define HOST_S390 1" >> $config_h
1188   ;;
1189   sparc)
1190     echo "ARCH=sparc" >> $config_mak
1191     echo "#define HOST_SPARC 1" >> $config_h
1192   ;;
1193   sparc64)
1194     echo "ARCH=sparc64" >> $config_mak
1195     echo "#define HOST_SPARC64 1" >> $config_h
1196   ;;
1197   *)
1198     echo "Unsupported CPU = $cpu"
1199     exit 1
1200   ;;
1201 esac
1202 if test "$sparse" = "yes" ; then
1203   echo "CC      := REAL_CC=\"\$(CC)\" cgcc"       >> $config_mak
1204   echo "HOST_CC := REAL_CC=\"\$(HOST_CC)\" cgcc"  >> $config_mak
1205   echo "CFLAGS  += -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-non-pointer-null" >> $config_mak
1206 fi
1207 if test "$bigendian" = "yes" ; then
1208   echo "WORDS_BIGENDIAN=yes" >> $config_mak
1209   echo "#define WORDS_BIGENDIAN 1" >> $config_h
1210 fi
1211 echo "#define HOST_LONG_BITS $hostlongbits" >> $config_h
1212 if test "$mingw32" = "yes" ; then
1213   echo "CONFIG_WIN32=yes" >> $config_mak
1214   echo "#define CONFIG_WIN32 1" >> $config_h
1215 else
1216   cat > $TMPC << EOF
1217 #include <byteswap.h>
1218 int main(void) { return bswap_32(0); }
1219 EOF
1220   if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
1221     echo "#define HAVE_BYTESWAP_H 1" >> $config_h
1222   fi
1223 fi
1224
1225 if [ "$openbsd" = "yes" ] ; then
1226   echo "#define ENOTSUP 4096" >> $config_h
1227 fi
1228
1229 if test "$darwin" = "yes" ; then
1230   echo "CONFIG_DARWIN=yes" >> $config_mak
1231   echo "#define CONFIG_DARWIN 1" >> $config_h
1232 fi
1233
1234 if test "$aix" = "yes" ; then
1235   echo "CONFIG_AIX=yes" >> $config_mak
1236   echo "#define CONFIG_AIX 1" >> $config_h
1237 fi
1238
1239 if test "$solaris" = "yes" ; then
1240   echo "CONFIG_SOLARIS=yes" >> $config_mak
1241   echo "#define HOST_SOLARIS $solarisrev" >> $config_h
1242   if test "$needs_libsunmath" = "yes" ; then
1243     echo "NEEDS_LIBSUNMATH=yes" >> $config_mak
1244     echo "#define NEEDS_LIBSUNMATH 1" >> $config_h
1245   fi
1246 fi
1247 if test -n "$sparc_cpu"; then
1248   echo "CONFIG__sparc_${sparc_cpu}__=yes" >> $config_mak
1249   echo "#define __sparc_${sparc_cpu}__ 1" >> $config_h
1250 fi
1251 if test "$gdbstub" = "yes" ; then
1252   echo "CONFIG_GDBSTUB=yes" >> $config_mak
1253   echo "#define CONFIG_GDBSTUB 1" >> $config_h
1254 fi
1255 if test "$gprof" = "yes" ; then
1256   echo "TARGET_GPROF=yes" >> $config_mak
1257   echo "#define HAVE_GPROF 1" >> $config_h
1258 fi
1259 if test "$static" = "yes" ; then
1260   echo "CONFIG_STATIC=yes" >> $config_mak
1261   echo "#define CONFIG_STATIC 1" >> $config_h
1262 fi
1263 if test $profiler = "yes" ; then
1264   echo "#define CONFIG_PROFILER 1" >> $config_h
1265 fi
1266 if test "$slirp" = "yes" ; then
1267   echo "CONFIG_SLIRP=yes" >> $config_mak
1268   echo "#define CONFIG_SLIRP 1" >> $config_h
1269 fi
1270 if test "$vde" = "yes" ; then
1271   echo "CONFIG_VDE=yes" >> $config_mak
1272   echo "#define CONFIG_VDE 1" >> $config_h
1273   echo "VDE_LIBS=-lvdeplug" >> $config_mak
1274 fi
1275 for card in $audio_card_list; do
1276     def=CONFIG_`echo $card | tr '[:lower:]' '[:upper:]'`
1277     echo "$def=yes" >> $config_mak
1278     echo "#define $def 1" >> $config_h
1279 done
1280 echo "#define AUDIO_DRIVERS \\" >> $config_h
1281 for drv in $audio_drv_list; do
1282     echo "    &${drv}_audio_driver, \\" >>$config_h
1283     def=CONFIG_`echo $drv | tr '[:lower:]' '[:upper:]'`
1284     echo "$def=yes" >> $config_mak
1285     if test "$drv" = "fmod"; then
1286         echo "CONFIG_FMOD_LIB=$fmod_lib" >> $config_mak
1287         echo "CONFIG_FMOD_INC=$fmod_inc" >> $config_mak
1288     elif test "$drv" = "oss"; then
1289         echo "CONFIG_OSS_LIB=$oss_lib" >> $config_mak
1290     fi
1291 done
1292 echo "" >>$config_h
1293 if test "$mixemu" = "yes" ; then
1294   echo "CONFIG_MIXEMU=yes" >> $config_mak
1295   echo "#define CONFIG_MIXEMU 1" >> $config_h
1296 fi
1297 if test "$vnc_tls" = "yes" ; then
1298   echo "CONFIG_VNC_TLS=yes" >> $config_mak
1299   echo "CONFIG_VNC_TLS_CFLAGS=$vnc_tls_cflags" >> $config_mak
1300   echo "CONFIG_VNC_TLS_LIBS=$vnc_tls_libs" >> $config_mak
1301   echo "#define CONFIG_VNC_TLS 1" >> $config_h
1302 fi
1303 qemu_version=`head $source_path/VERSION`
1304 echo "VERSION=$qemu_version" >>$config_mak
1305 echo "#define QEMU_VERSION \"$qemu_version\"" >> $config_h
1306
1307 echo "SRC_PATH=$source_path" >> $config_mak
1308 if [ "$source_path_used" = "yes" ]; then
1309   echo "VPATH=$source_path" >> $config_mak
1310 fi
1311 echo "TARGET_DIRS=$target_list" >> $config_mak
1312 if [ "$build_docs" = "yes" ] ; then
1313   echo "BUILD_DOCS=yes" >> $config_mak
1314 fi
1315 if test "$static" = "yes"; then
1316   sdl1=$sdl_static
1317 else
1318   sdl1=$sdl
1319 fi
1320 if test "$sdl1" = "yes" ; then
1321   echo "#define CONFIG_SDL 1" >> $config_h
1322   echo "CONFIG_SDL=yes" >> $config_mak
1323   if test "$target_softmmu" = "no" -o "$static" = "yes"; then
1324     echo "SDL_LIBS=$sdl_static_libs" >> $config_mak
1325   else
1326     echo "SDL_LIBS=`$sdl_config --libs`" >> $config_mak
1327   fi
1328   if [ "${aa}" = "yes" ] ; then
1329     echo "SDL_CFLAGS=`$sdl_config --cflags` `aalib-config --cflags`" >> $config_mak
1330   else
1331     echo "SDL_CFLAGS=`$sdl_config --cflags`" >> $config_mak
1332   fi
1333 fi
1334 if test "$cocoa" = "yes" ; then
1335   echo "#define CONFIG_COCOA 1" >> $config_h
1336   echo "CONFIG_COCOA=yes" >> $config_mak
1337 fi
1338 if test "$curses" = "yes" ; then
1339   echo "#define CONFIG_CURSES 1" >> $config_h
1340   echo "CONFIG_CURSES=yes" >> $config_mak
1341   echo "CURSES_LIBS=-lcurses" >> $config_mak
1342 fi
1343 if test "$brlapi" = "yes" ; then
1344   echo "CONFIG_BRLAPI=yes" >> $config_mak
1345   echo "#define CONFIG_BRLAPI 1" >> $config_h
1346   echo "BRLAPI_LIBS=-lbrlapi" >> $config_mak
1347 fi
1348 if test "$bluez" = "yes" ; then
1349   echo "CONFIG_BLUEZ=yes" >> $config_mak
1350   echo "CONFIG_BLUEZ_CFLAGS=$bluez_cflags" >> $config_mak
1351   echo "CONFIG_BLUEZ_LIBS=$bluez_libs" >> $config_mak
1352   echo "#define CONFIG_BLUEZ 1" >> $config_h
1353 fi
1354 if test "$aio" = "yes" ; then
1355   echo "#define CONFIG_AIO 1" >> $config_h
1356   echo "CONFIG_AIO=yes" >> $config_mak
1357 fi
1358
1359 # XXX: suppress that
1360 if [ "$bsd" = "yes" ] ; then
1361   echo "#define O_LARGEFILE 0" >> $config_h
1362   echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
1363   echo "#define _BSD 1" >> $config_h
1364 fi
1365
1366 echo "#define CONFIG_UNAME_RELEASE \"$uname_release\"" >> $config_h
1367
1368 tools=
1369 if test `expr "$target_list" : ".*softmmu.*"` != 0 ; then
1370   tools="qemu-img\$(EXESUF) $tools"
1371   if [ "$linux" = "yes" ] ; then
1372       tools="qemu-nbd\$(EXESUF) $tools"
1373   fi
1374 fi
1375 echo "TOOLS=$tools" >> $config_mak
1376
1377 test -f ${config_h}~ && cmp -s $config_h ${config_h}~ && mv ${config_h}~ $config_h
1378
1379 for target in $target_list; do
1380 target_dir="$target"
1381 config_mak=$target_dir/config.mak
1382 config_h=$target_dir/config.h
1383 target_cpu=`echo $target | cut -d '-' -f 1`
1384 target_bigendian="no"
1385 [ "$target_cpu" = "armeb" ] && target_bigendian=yes
1386 [ "$target_cpu" = "m68k" ] && target_bigendian=yes
1387 [ "$target_cpu" = "mips" ] && target_bigendian=yes
1388 [ "$target_cpu" = "mipsn32" ] && target_bigendian=yes
1389 [ "$target_cpu" = "mips64" ] && target_bigendian=yes
1390 [ "$target_cpu" = "ppc" ] && target_bigendian=yes
1391 [ "$target_cpu" = "ppcemb" ] && target_bigendian=yes
1392 [ "$target_cpu" = "ppc64" ] && target_bigendian=yes
1393 [ "$target_cpu" = "ppc64abi32" ] && target_bigendian=yes
1394 [ "$target_cpu" = "sh4eb" ] && target_bigendian=yes
1395 [ "$target_cpu" = "sparc" ] && target_bigendian=yes
1396 [ "$target_cpu" = "sparc64" ] && target_bigendian=yes
1397 [ "$target_cpu" = "sparc32plus" ] && target_bigendian=yes
1398 target_softmmu="no"
1399 target_user_only="no"
1400 target_linux_user="no"
1401 target_darwin_user="no"
1402 target_bsd_user="no"
1403 case "$target" in
1404   ${target_cpu}-softmmu)
1405     target_softmmu="yes"
1406     ;;
1407   ${target_cpu}-linux-user)
1408     target_user_only="yes"
1409     target_linux_user="yes"
1410     ;;
1411   ${target_cpu}-darwin-user)
1412     target_user_only="yes"
1413     target_darwin_user="yes"
1414     ;;
1415   ${target_cpu}-bsd-user)
1416     target_user_only="yes"
1417     target_bsd_user="yes"
1418     ;;
1419   *)
1420     echo "ERROR: Target '$target' not recognised"
1421     exit 1
1422     ;;
1423 esac
1424
1425 if test "$target_user_only" = "no" -a "$check_gfx" = "yes" \
1426         -a "$sdl" = "no" -a "$cocoa" = "no" ; then
1427     echo "ERROR: QEMU requires SDL or Cocoa for graphical output"
1428     echo "To build QEMU without graphical output configure with --disable-gfx-check"
1429     echo "Note that this will disable all output from the virtual graphics card"
1430     echo "except through VNC or curses."
1431     exit 1;
1432 fi
1433
1434 #echo "Creating $config_mak, $config_h and $target_dir/Makefile"
1435
1436 test -f $config_h && mv $config_h ${config_h}~
1437
1438 mkdir -p $target_dir
1439 mkdir -p $target_dir/fpu
1440 mkdir -p $target_dir/tcg
1441 if test "$target" = "arm-linux-user" -o "$target" = "armeb-linux-user" -o "$target" = "arm-bsd-user" -o "$target" = "armeb-bsd-user" ; then
1442   mkdir -p $target_dir/nwfpe
1443 fi
1444
1445 #
1446 # don't use ln -sf as not all "ln -sf" over write the file/link
1447 #
1448 rm -f $target_dir/Makefile
1449 ln -s $source_path/Makefile.target $target_dir/Makefile
1450
1451
1452 echo "# Automatically generated by configure - do not modify" > $config_mak
1453 echo "/* Automatically generated by configure - do not modify */" > $config_h
1454
1455
1456 echo "include ../config-host.mak" >> $config_mak
1457 echo "#include \"../config-host.h\"" >> $config_h
1458
1459 bflt="no"
1460 elfload32="no"
1461 target_nptl="no"
1462 interp_prefix1=`echo "$interp_prefix" | sed "s/%M/$target_cpu/g"`
1463 echo "#define CONFIG_QEMU_PREFIX \"$interp_prefix1\"" >> $config_h
1464 gdb_xml_files=""
1465
1466 # Make sure the target and host cpus are compatible
1467 if test "$kvm" = "yes" -a ! \( "$target_cpu" = "$cpu" -o \
1468   \( "$target_cpu" = "x86_64" -a "$cpu" = "i386"   \) -o \
1469   \( "$target_cpu" = "i386"   -a "$cpu" = "x86_64" \) \) ; then
1470   kvm="no"
1471 fi
1472 # Disable KVM for linux-user
1473 if test "$kvm" = "yes" -a "$target_softmmu" = "no" ; then
1474   kvm="no"
1475 fi
1476
1477 case "$target_cpu" in
1478   i386)
1479     echo "TARGET_ARCH=i386" >> $config_mak
1480     echo "#define TARGET_ARCH \"i386\"" >> $config_h
1481     echo "#define TARGET_I386 1" >> $config_h
1482     if test $kqemu = "yes" -a "$target_softmmu" = "yes"
1483     then
1484       echo "#define USE_KQEMU 1" >> $config_h
1485     fi
1486     if test "$kvm" = "yes" ; then
1487       echo "CONFIG_KVM=yes" >> $config_mak
1488       echo "KVM_CFLAGS=$kvm_cflags" >> $config_mak
1489       echo "#define CONFIG_KVM 1" >> $config_h
1490     fi
1491     gcc3minver=`$cc --version 2> /dev/null| fgrep "(GCC) 3." | awk '{ print $3 }' | cut -f2 -d.`
1492     if test -n "$gcc3minver" && test $gcc3minver -gt 3
1493     then
1494       echo "HAVE_GT_GCC_3_3=true" >> $config_mak
1495     else
1496       echo "HAVE_GT_GCC_3_3=false" >> $config_mak
1497     fi
1498   ;;
1499   x86_64)
1500     echo "TARGET_ARCH=x86_64" >> $config_mak
1501     echo "#define TARGET_ARCH \"x86_64\"" >> $config_h
1502     echo "#define TARGET_I386 1" >> $config_h
1503     echo "#define TARGET_X86_64 1" >> $config_h
1504     if test $kqemu = "yes" -a "$target_softmmu" = "yes" -a $cpu = "x86_64"
1505     then
1506       echo "#define USE_KQEMU 1" >> $config_h
1507     fi
1508     if test "$kvm" = "yes" ; then
1509       echo "CONFIG_KVM=yes" >> $config_mak
1510       echo "KVM_CFLAGS=$kvm_cflags" >> $config_mak
1511       echo "#define CONFIG_KVM 1" >> $config_h
1512     fi
1513   ;;
1514   alpha)
1515     echo "TARGET_ARCH=alpha" >> $config_mak
1516     echo "#define TARGET_ARCH \"alpha\"" >> $config_h
1517     echo "#define TARGET_ALPHA 1" >> $config_h
1518   ;;
1519   arm|armeb)
1520     echo "TARGET_ARCH=arm" >> $config_mak
1521     echo "#define TARGET_ARCH \"arm\"" >> $config_h
1522     echo "#define TARGET_ARM 1" >> $config_h
1523     bflt="yes"
1524     target_nptl="yes"
1525     gdb_xml_files="arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"
1526   ;;
1527   cris)
1528     echo "TARGET_ARCH=cris" >> $config_mak
1529     echo "#define TARGET_ARCH \"cris\"" >> $config_h
1530     echo "#define TARGET_CRIS 1" >> $config_h
1531   ;;
1532   m68k)
1533     echo "TARGET_ARCH=m68k" >> $config_mak
1534     echo "#define TARGET_ARCH \"m68k\"" >> $config_h
1535     echo "#define TARGET_M68K 1" >> $config_h
1536     bflt="yes"
1537     gdb_xml_files="cf-core.xml cf-fp.xml"
1538   ;;
1539   mips|mipsel)
1540     echo "TARGET_ARCH=mips" >> $config_mak
1541     echo "#define TARGET_ARCH \"mips\"" >> $config_h
1542     echo "#define TARGET_MIPS 1" >> $config_h
1543     echo "#define TARGET_ABI_MIPSO32 1" >> $config_h
1544   ;;
1545   mipsn32|mipsn32el)
1546     echo "TARGET_ARCH=mipsn32" >> $config_mak
1547     echo "#define TARGET_ARCH \"mipsn32\"" >> $config_h
1548     echo "#define TARGET_MIPS 1" >> $config_h
1549     echo "#define TARGET_ABI_MIPSN32 1" >> $config_h
1550   ;;
1551   mips64|mips64el)
1552     echo "TARGET_ARCH=mips64" >> $config_mak
1553     echo "#define TARGET_ARCH \"mips64\"" >> $config_h
1554     echo "#define TARGET_MIPS 1" >> $config_h
1555     echo "#define TARGET_MIPS64 1" >> $config_h
1556     echo "#define TARGET_ABI_MIPSN64 1" >> $config_h
1557   ;;
1558   ppc)
1559     echo "TARGET_ARCH=ppc" >> $config_mak
1560     echo "CONFIG_DYNGEN_OP=yes" >> $config_mak
1561     echo "#define TARGET_ARCH \"ppc\"" >> $config_h
1562     echo "#define TARGET_PPC 1" >> $config_h
1563     echo "#define CONFIG_DYNGEN_OP 1" >> $config_h
1564   ;;
1565   ppcemb)
1566     echo "TARGET_ARCH=ppcemb" >> $config_mak
1567     echo "TARGET_ABI_DIR=ppc" >> $config_mak
1568     echo "CONFIG_DYNGEN_OP=yes" >> $config_mak
1569     echo "#define TARGET_ARCH \"ppcemb\"" >> $config_h
1570     echo "#define TARGET_PPC 1" >> $config_h
1571     echo "#define TARGET_PPCEMB 1" >> $config_h
1572     echo "#define CONFIG_DYNGEN_OP 1" >> $config_h
1573   ;;
1574   ppc64)
1575     echo "TARGET_ARCH=ppc64" >> $config_mak
1576     echo "TARGET_ABI_DIR=ppc" >> $config_mak
1577     echo "CONFIG_DYNGEN_OP=yes" >> $config_mak
1578     echo "#define TARGET_ARCH \"ppc64\"" >> $config_h
1579     echo "#define TARGET_PPC 1" >> $config_h
1580     echo "#define TARGET_PPC64 1" >> $config_h
1581     echo "#define CONFIG_DYNGEN_OP 1" >> $config_h
1582   ;;
1583   ppc64abi32)
1584     echo "TARGET_ARCH=ppc64" >> $config_mak
1585     echo "TARGET_ABI_DIR=ppc" >> $config_mak
1586     echo "TARGET_ARCH2=ppc64abi32" >> $config_mak
1587     echo "CONFIG_DYNGEN_OP=yes" >> $config_mak
1588     echo "#define TARGET_ARCH \"ppc64\"" >> $config_h
1589     echo "#define TARGET_PPC 1" >> $config_h
1590     echo "#define TARGET_PPC64 1" >> $config_h
1591     echo "#define TARGET_ABI32 1" >> $config_h
1592     echo "#define CONFIG_DYNGEN_OP 1" >> $config_h
1593   ;;
1594   sh4|sh4eb)
1595     echo "TARGET_ARCH=sh4" >> $config_mak
1596     echo "#define TARGET_ARCH \"sh4\"" >> $config_h
1597     echo "#define TARGET_SH4 1" >> $config_h
1598     bflt="yes"
1599     target_nptl="yes"
1600   ;;
1601   sparc)
1602     echo "TARGET_ARCH=sparc" >> $config_mak
1603     echo "#define TARGET_ARCH \"sparc\"" >> $config_h
1604     echo "#define TARGET_SPARC 1" >> $config_h
1605   ;;
1606   sparc64)
1607     echo "TARGET_ARCH=sparc64" >> $config_mak
1608     echo "#define TARGET_ARCH \"sparc64\"" >> $config_h
1609     echo "#define TARGET_SPARC 1" >> $config_h
1610     echo "#define TARGET_SPARC64 1" >> $config_h
1611     elfload32="yes"
1612   ;;
1613   sparc32plus)
1614     echo "TARGET_ARCH=sparc64" >> $config_mak
1615     echo "TARGET_ABI_DIR=sparc" >> $config_mak
1616     echo "TARGET_ARCH2=sparc32plus" >> $config_mak
1617     echo "#define TARGET_ARCH \"sparc64\"" >> $config_h
1618     echo "#define TARGET_SPARC 1" >> $config_h
1619     echo "#define TARGET_SPARC64 1" >> $config_h
1620     echo "#define TARGET_ABI32 1" >> $config_h
1621   ;;
1622   *)
1623     echo "Unsupported target CPU"
1624     exit 1
1625   ;;
1626 esac
1627 if test "$target_bigendian" = "yes" ; then
1628   echo "TARGET_WORDS_BIGENDIAN=yes" >> $config_mak
1629   echo "#define TARGET_WORDS_BIGENDIAN 1" >> $config_h
1630 fi
1631 if test "$target_softmmu" = "yes" ; then
1632   echo "CONFIG_SOFTMMU=yes" >> $config_mak
1633   echo "#define CONFIG_SOFTMMU 1" >> $config_h
1634 fi
1635 if test "$target_user_only" = "yes" ; then
1636   echo "CONFIG_USER_ONLY=yes" >> $config_mak
1637   echo "#define CONFIG_USER_ONLY 1" >> $config_h
1638 fi
1639 if test "$target_linux_user" = "yes" ; then
1640   echo "CONFIG_LINUX_USER=yes" >> $config_mak
1641   echo "#define CONFIG_LINUX_USER 1" >> $config_h
1642 fi
1643 if test "$target_darwin_user" = "yes" ; then
1644   echo "CONFIG_DARWIN_USER=yes" >> $config_mak
1645   echo "#define CONFIG_DARWIN_USER 1" >> $config_h
1646 fi
1647 list=""
1648 if test ! -z "$gdb_xml_files" ; then
1649   for x in $gdb_xml_files; do
1650     list="$list $source_path/gdb-xml/$x"
1651   done
1652 fi
1653 echo "TARGET_XML_FILES=$list" >> $config_mak
1654
1655 if test "$target_cpu" = "arm" \
1656      -o "$target_cpu" = "armeb" \
1657      -o "$target_cpu" = "m68k" \
1658      -o "$target_cpu" = "mips" \
1659      -o "$target_cpu" = "mipsel" \
1660      -o "$target_cpu" = "mipsn32" \
1661      -o "$target_cpu" = "mipsn32el" \
1662      -o "$target_cpu" = "mips64" \
1663      -o "$target_cpu" = "mips64el" \
1664      -o "$target_cpu" = "sparc" \
1665      -o "$target_cpu" = "sparc64" \
1666      -o "$target_cpu" = "sparc32plus"; then
1667   echo "CONFIG_SOFTFLOAT=yes" >> $config_mak
1668   echo "#define CONFIG_SOFTFLOAT 1" >> $config_h
1669 fi
1670 if test "$target_user_only" = "yes" -a "$bflt" = "yes"; then
1671   echo "TARGET_HAS_BFLT=yes" >> $config_mak
1672   echo "#define TARGET_HAS_BFLT 1" >> $config_h
1673 fi
1674 if test "$target_user_only" = "yes" \
1675         -a "$nptl" = "yes" -a "$target_nptl" = "yes"; then
1676   echo "#define USE_NPTL 1" >> $config_h
1677 fi
1678 # 32 bit ELF loader in addition to native 64 bit loader?
1679 if test "$target_user_only" = "yes" -a "$elfload32" = "yes"; then
1680   echo "TARGET_HAS_ELFLOAD32=yes" >> $config_mak
1681   echo "#define TARGET_HAS_ELFLOAD32 1" >> $config_h
1682 fi
1683 if test "$target_bsd_user" = "yes" ; then
1684   echo "CONFIG_BSD_USER=yes" >> $config_mak
1685   echo "#define CONFIG_BSD_USER 1" >> $config_h
1686 fi
1687
1688 test -f ${config_h}~ && cmp -s $config_h ${config_h}~ && mv ${config_h}~ $config_h
1689
1690 done # for target in $targets
1691
1692 # build tree in object directory if source path is different from current one
1693 if test "$source_path_used" = "yes" ; then
1694     DIRS="tests tests/cris slirp audio"
1695     FILES="Makefile tests/Makefile"
1696     FILES="$FILES tests/cris/Makefile tests/cris/.gdbinit"
1697     FILES="$FILES tests/test-mmap.c"
1698     for dir in $DIRS ; do
1699             mkdir -p $dir
1700     done
1701     # remove the link and recreate it, as not all "ln -sf" overwrite the link
1702     for f in $FILES ; do
1703         rm -f $f
1704         ln -s $source_path/$f $f
1705     done
1706 fi
1707
1708 rm -f $TMPO $TMPC $TMPE $TMPS $TMPI