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