Add error message for feature not found
[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
18 trap "rm -f $TMPC $TMPO $TMPE ; exit" 0 2 3 15
19
20 compile_object() {
21   $cc $QEMU_CFLAGS -c -o $TMPO $TMPC > /dev/null 2> /dev/null
22 }
23
24 compile_prog() {
25   local_cflags="$1"
26   local_ldflags="$2"
27   $cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags > /dev/null 2> /dev/null
28 }
29
30 # default parameters
31 cpu=""
32 prefix=""
33 interp_prefix="/usr/gnemul/qemu-%M"
34 static="no"
35 sparc_cpu=""
36 cross_prefix=""
37 cc="gcc"
38 audio_drv_list=""
39 audio_card_list="ac97 es1370 sb16"
40 audio_possible_cards="ac97 es1370 sb16 cs4231a adlib gus"
41 host_cc="gcc"
42 ar="ar"
43 make="make"
44 install="install"
45 objcopy="objcopy"
46 ld="ld"
47 helper_cflags=""
48 libs_softmmu=""
49 libs_tools=""
50 audio_pt_int=""
51
52 # parse CC options first
53 for opt do
54   optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
55   case "$opt" in
56   --cross-prefix=*) cross_prefix="$optarg"
57   ;;
58   --cc=*) cc="$optarg"
59   ;;
60   --cpu=*) cpu="$optarg"
61   ;;
62   --extra-cflags=*) QEMU_CFLAGS="$optarg $QEMU_CFLAGS"
63   ;;
64   --extra-ldflags=*) LDFLAGS="$optarg $LDFLAGS"
65   ;;
66   --sparc_cpu=*)
67     sparc_cpu="$optarg"
68     case $sparc_cpu in
69     v7|v8|v8plus|v8plusa)
70       cpu="sparc"
71     ;;
72     v9)
73       cpu="sparc64"
74     ;;
75     *)
76       echo "undefined SPARC architecture. Exiting";
77       exit 1
78     ;;
79     esac
80   ;;
81   esac
82 done
83 # OS specific
84 # Using uname is really, really broken.  Once we have the right set of checks
85 # we can eliminate it's usage altogether
86
87 cc="${cross_prefix}${cc}"
88 ar="${cross_prefix}${ar}"
89 objcopy="${cross_prefix}${objcopy}"
90 ld="${cross_prefix}${ld}"
91
92 # check that the C compiler works.
93 cat > $TMPC <<EOF
94 int main(void) {}
95 EOF
96
97 if compile_object ; then
98   : C compiler works ok
99 else
100     echo "ERROR: \"$cc\" either does not exist or does not work"
101     exit 1
102 fi
103
104 check_define() {
105 cat > $TMPC <<EOF
106 #if !defined($1)
107 #error Not defined
108 #endif
109 int main(void) { return 0; }
110 EOF
111   compile_object
112 }
113
114 if test ! -z "$cpu" ; then
115   # command line argument
116   :
117 elif check_define __i386__ ; then
118   cpu="i386"
119 elif check_define __x86_64__ ; then
120   cpu="x86_64"
121 elif check_define __sparc__ ; then
122   # We can't check for 64 bit (when gcc is biarch) or V8PLUSA
123   # They must be specified using --sparc_cpu
124   if check_define __arch64__ ; then
125     cpu="sparc64"
126   else
127     cpu="sparc"
128   fi
129 elif check_define _ARCH_PPC ; then
130   if check_define _ARCH_PPC64 ; then
131     cpu="ppc64"
132   else
133     cpu="ppc"
134   fi
135 else
136   cpu=`uname -m`
137 fi
138
139 target_list=""
140 case "$cpu" in
141   alpha|cris|ia64|m68k|microblaze|mips|mips64|ppc|ppc64|sparc64)
142     cpu="$cpu"
143   ;;
144   i386|i486|i586|i686|i86pc|BePC)
145     cpu="i386"
146   ;;
147   x86_64|amd64)
148     cpu="x86_64"
149   ;;
150   armv*b)
151     cpu="armv4b"
152   ;;
153   armv*l)
154     cpu="armv4l"
155   ;;
156   parisc|parisc64)
157     cpu="hppa"
158   ;;
159   s390*)
160     cpu="s390"
161   ;;
162   sparc|sun4[cdmuv])
163     cpu="sparc"
164   ;;
165   *)
166     cpu="unknown"
167   ;;
168 esac
169
170 # Default value for a variable defining feature "foo"
171 #  * foo="no", feature will only be used if --enable-foo arg is given
172 #  * foo="", feature will be searched for, and if found, will be used
173 #  * foo="yes", this value vill only be set by --enable-foo flag.
174 #                   feature will searched for, if not found, configure exits with error
175 #
176 # Always add --enable-foo and --disable-foo command line args.  Distributions want
177 # to ensure that several features are compiled in, and it is impossible without a
178 # --enable-foo that exits if feature is not found
179
180 brlapi="yes"
181 gprof="no"
182 debug_tcg="no"
183 debug="no"
184 sparse="no"
185 strip_opt="yes"
186 bigendian="no"
187 mingw32="no"
188 EXESUF=""
189 slirp="yes"
190 vde="yes"
191 fmod_lib=""
192 fmod_inc=""
193 oss_lib=""
194 vnc_tls="yes"
195 vnc_sasl="yes"
196 bsd="no"
197 linux="no"
198 solaris="no"
199 profiler="no"
200 cocoa="no"
201 softmmu="yes"
202 linux_user="no"
203 darwin_user="no"
204 bsd_user="no"
205 guest_base=""
206 build_docs="yes"
207 uname_release=""
208 curses="yes"
209 curl="yes"
210 io_thread="no"
211 nptl="yes"
212 mixemu="no"
213 bluez="yes"
214 kvm="no"
215 kerneldir=""
216 aix="no"
217 blobs="yes"
218 fdt="yes"
219 sdl="yes"
220 xen="yes"
221 pkgversion=""
222
223 # OS specific
224 if check_define __linux__ ; then
225   targetos="Linux"
226 elif check_define _WIN32 ; then
227   targetos='MINGW32'
228 elif check_define __OpenBSD__ ; then
229   targetos='OpenBSD'
230 elif check_define __sun__ ; then
231   targetos='SunOS'
232 else
233   targetos=`uname -s`
234 fi
235
236 case $targetos in
237 CYGWIN*)
238   mingw32="yes"
239   QEMU_CFLAGS="-mno-cygwin $QEMU_CFLAGS"
240   audio_possible_drivers="sdl"
241 ;;
242 MINGW32*)
243   mingw32="yes"
244   audio_possible_drivers="dsound sdl fmod"
245 ;;
246 GNU/kFreeBSD)
247   audio_drv_list="oss"
248   audio_possible_drivers="oss sdl esd pa"
249 ;;
250 FreeBSD)
251   bsd="yes"
252   audio_drv_list="oss"
253   audio_possible_drivers="oss sdl esd pa"
254 ;;
255 DragonFly)
256   bsd="yes"
257   audio_drv_list="oss"
258   audio_possible_drivers="oss sdl esd pa"
259 ;;
260 NetBSD)
261   bsd="yes"
262   audio_drv_list="oss"
263   audio_possible_drivers="oss sdl esd"
264   oss_lib="-lossaudio"
265 ;;
266 OpenBSD)
267   bsd="yes"
268   audio_drv_list="oss"
269   audio_possible_drivers="oss sdl esd"
270   oss_lib="-lossaudio"
271 ;;
272 Darwin)
273   bsd="yes"
274   darwin="yes"
275   # on Leopard most of the system is 32-bit, so we have to ask the kernel it if we can
276   # run 64-bit userspace code
277   if [ "$cpu" = "i386" ] ; then
278     is_x86_64=`sysctl -n hw.optional.x86_64`
279     [ "$is_x86_64" = "1" ] && cpu=x86_64
280   fi
281   if [ "$cpu" = "x86_64" ] ; then
282     QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
283     LDFLAGS="-arch x86_64 $LDFLAGS"
284   else
285     QEMU_CFLAGS="-mdynamic-no-pic $QEMU_CFLAGS"
286   fi
287   darwin_user="yes"
288   cocoa="yes"
289   audio_drv_list="coreaudio"
290   audio_possible_drivers="coreaudio sdl fmod"
291   LDFLAGS="-framework CoreFoundation -framework IOKit $LDFLAGS"
292   libs_softmmu="-F/System/Library/Frameworks -framework Cocoa -framework IOKit $libs_softmmu"
293 ;;
294 SunOS)
295   solaris="yes"
296   make="gmake"
297   install="ginstall"
298   needs_libsunmath="no"
299   solarisrev=`uname -r | cut -f2 -d.`
300   # have to select again, because `uname -m` returns i86pc
301   # even on an x86_64 box.
302   solariscpu=`isainfo -k`
303   if test "${solariscpu}" = "amd64" ; then
304     cpu="x86_64"
305   fi
306   if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
307     if test "$solarisrev" -le 9 ; then
308       if test -f /opt/SUNWspro/prod/lib/libsunmath.so.1; then
309         needs_libsunmath="yes"
310         QEMU_CFLAGS="-I/opt/SUNWspro/prod/include/cc $QEMU_CFLAGS"
311         LDFLAGS="-L/opt/SUNWspro/prod/lib -R/opt/SUNWspro/prod/lib $LDFLAGS"
312         LIBS="-lsunmath $LIBS"
313       else
314         echo "QEMU will not link correctly on Solaris 8/X86 or 9/x86 without"
315         echo "libsunmath from the Sun Studio compilers tools, due to a lack of"
316         echo "C99 math features in libm.so in Solaris 8/x86 and Solaris 9/x86"
317         echo "Studio 11 can be downloaded from www.sun.com."
318         exit 1
319       fi
320     fi
321   fi
322   if test -f /usr/include/sys/soundcard.h ; then
323     audio_drv_list="oss"
324   fi
325   audio_possible_drivers="oss sdl"
326   QEMU_CFLAGS="-std=gnu99 $QEMU_CFLAGS"
327   LIBS="-lsocket -lnsl -lresolv $LIBS"
328 ;;
329 AIX)
330   aix="yes"
331   make="gmake"
332 ;;
333 *)
334   audio_drv_list="oss"
335   audio_possible_drivers="oss alsa sdl esd pa"
336   linux="yes"
337   linux_user="yes"
338   usb="linux"
339   kvm="yes"
340   if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
341     audio_possible_drivers="$audio_possible_drivers fmod"
342   fi
343 ;;
344 esac
345
346 if [ "$bsd" = "yes" ] ; then
347   if [ "$darwin" != "yes" ] ; then
348     make="gmake"
349     usb="bsd"
350   fi
351   bsd_user="yes"
352 fi
353
354 if test "$mingw32" = "yes" ; then
355   EXESUF=".exe"
356   QEMU_CFLAGS="-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 $QEMU_CFLAGS"
357   LIBS="-lwinmm -lws2_32 -liphlpapi $LIBS"
358 fi
359
360 # find source path
361 source_path=`dirname "$0"`
362 source_path_used="no"
363 workdir=`pwd`
364 if [ -z "$source_path" ]; then
365     source_path=$workdir
366 else
367     source_path=`cd "$source_path"; pwd`
368 fi
369 [ -f "$workdir/vl.c" ] || source_path_used="yes"
370
371 werror=""
372
373 for opt do
374   optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
375   case "$opt" in
376   --help|-h) show_help=yes
377   ;;
378   --prefix=*) prefix="$optarg"
379   ;;
380   --interp-prefix=*) interp_prefix="$optarg"
381   ;;
382   --source-path=*) source_path="$optarg"
383   source_path_used="yes"
384   ;;
385   --cross-prefix=*)
386   ;;
387   --cc=*)
388   ;;
389   --host-cc=*) host_cc="$optarg"
390   ;;
391   --make=*) make="$optarg"
392   ;;
393   --install=*) install="$optarg"
394   ;;
395   --extra-cflags=*)
396   ;;
397   --extra-ldflags=*)
398   ;;
399   --cpu=*)
400   ;;
401   --target-list=*) target_list="$optarg"
402   ;;
403   --enable-gprof) gprof="yes"
404   ;;
405   --static) static="yes"
406   ;;
407   --disable-sdl) sdl="no"
408   ;;
409   --fmod-lib=*) fmod_lib="$optarg"
410   ;;
411   --fmod-inc=*) fmod_inc="$optarg"
412   ;;
413   --oss-lib=*) oss_lib="$optarg"
414   ;;
415   --audio-card-list=*) audio_card_list=`echo "$optarg" | sed -e 's/,/ /g'`
416   ;;
417   --audio-drv-list=*) audio_drv_list="$optarg"
418   ;;
419   --enable-debug-tcg) debug_tcg="yes"
420   ;;
421   --disable-debug-tcg) debug_tcg="no"
422   ;;
423   --enable-debug)
424       # Enable debugging options that aren't excessively noisy
425       debug_tcg="yes"
426       debug="yes"
427       strip_opt="no"
428   ;;
429   --enable-sparse) sparse="yes"
430   ;;
431   --disable-sparse) sparse="no"
432   ;;
433   --disable-strip) strip_opt="no"
434   ;;
435   --disable-vnc-tls) vnc_tls="no"
436   ;;
437   --disable-vnc-sasl) vnc_sasl="no"
438   ;;
439   --disable-slirp) slirp="no"
440   ;;
441   --disable-vde) vde="no"
442   ;;
443   --disable-xen) xen="no"
444   ;;
445   --disable-brlapi) brlapi="no"
446   ;;
447   --disable-bluez) bluez="no"
448   ;;
449   --disable-kvm) kvm="no"
450   ;;
451   --enable-profiler) profiler="yes"
452   ;;
453   --enable-cocoa)
454       cocoa="yes" ;
455       sdl="no" ;
456       audio_drv_list="coreaudio `echo $audio_drv_list | sed s,coreaudio,,g`"
457   ;;
458   --disable-system) softmmu="no"
459   ;;
460   --enable-system) softmmu="yes"
461   ;;
462   --disable-user)
463       linux_user="no" ;
464       bsd_user="no" ;
465       darwin_user="no"
466   ;;
467   --enable-user) ;;
468   --disable-linux-user) linux_user="no"
469   ;;
470   --enable-linux-user) linux_user="yes"
471   ;;
472   --disable-darwin-user) darwin_user="no"
473   ;;
474   --enable-darwin-user) darwin_user="yes"
475   ;;
476   --disable-bsd-user) bsd_user="no"
477   ;;
478   --enable-bsd-user) bsd_user="yes"
479   ;;
480   --enable-guest-base) guest_base="yes"
481   ;;
482   --disable-guest-base) guest_base="no"
483   ;;
484   --enable-uname-release=*) uname_release="$optarg"
485   ;;
486   --sparc_cpu=*)
487   ;;
488   --enable-werror) werror="yes"
489   ;;
490   --disable-werror) werror="no"
491   ;;
492   --disable-curses) curses="no"
493   ;;
494   --disable-curl) curl="no"
495   ;;
496   --disable-nptl) nptl="no"
497   ;;
498   --enable-mixemu) mixemu="yes"
499   ;;
500   --enable-io-thread) io_thread="yes"
501   ;;
502   --disable-blobs) blobs="no"
503   ;;
504   --kerneldir=*) kerneldir="$optarg"
505   ;;
506   --with-pkgversion=*) pkgversion=" ($optarg)"
507   ;;
508   --disable-docs) build_docs="no"
509   ;;
510   *) echo "ERROR: unknown option $opt"; show_help="yes"
511   ;;
512   esac
513 done
514
515 #
516 # If cpu ~= sparc and  sparc_cpu hasn't been defined, plug in the right
517 # QEMU_CFLAGS/LDFLAGS (assume sparc_v8plus for 32-bit and sparc_v9 for 64-bit)
518 #
519 host_guest_base="no"
520 case "$cpu" in
521     sparc) case $sparc_cpu in
522            v7|v8)
523              QEMU_CFLAGS="-mcpu=${sparc_cpu} -D__sparc_${sparc_cpu}__ $QEMU_CFLAGS"
524            ;;
525            v8plus|v8plusa)
526              QEMU_CFLAGS="-mcpu=ultrasparc -D__sparc_${sparc_cpu}__ $QEMU_CFLAGS"
527            ;;
528            *) # sparc_cpu not defined in the command line
529              QEMU_CFLAGS="-mcpu=ultrasparc -D__sparc_v8plus__ $QEMU_CFLAGS"
530            esac
531            LDFLAGS="-m32 $LDFLAGS"
532            QEMU_CFLAGS="-m32 -ffixed-g2 -ffixed-g3 $QEMU_CFLAGS"
533            if test "$solaris" = "no" ; then
534              QEMU_CFLAGS="-ffixed-g1 -ffixed-g6 $QEMU_CFLAGS"
535              helper_cflags="-ffixed-i0"
536            fi
537            ;;
538     sparc64)
539            QEMU_CFLAGS="-m64 -mcpu=ultrasparc -D__sparc_v9__ $QEMU_CFLAGS"
540            LDFLAGS="-m64 $LDFLAGS"
541            QEMU_CFLAGS="-ffixed-g5 -ffixed-g6 -ffixed-g7 $QEMU_CFLAGS"
542            if test "$solaris" != "no" ; then
543              QEMU_CFLAGS="-ffixed-g1 $QEMU_CFLAGS"
544            fi
545            ;;
546     s390)
547            QEMU_CFLAGS="-march=z900 $QEMU_CFLAGS"
548            ;;
549     i386)
550            QEMU_CFLAGS="-m32 $QEMU_CFLAGS"
551            LDFLAGS="-m32 $LDFLAGS"
552            helper_cflags="-fomit-frame-pointer"
553            host_guest_base="yes"
554            ;;
555     x86_64)
556            QEMU_CFLAGS="-m64 $QEMU_CFLAGS"
557            LDFLAGS="-m64 $LDFLAGS"
558            host_guest_base="yes"
559            ;;
560     arm*)
561            host_guest_base="yes"
562            ;;
563     ppc*)
564            host_guest_base="yes"
565            ;;
566 esac
567
568 [ -z "$guest_base" ] && guest_base="$host_guest_base"
569
570 if test x"$show_help" = x"yes" ; then
571 cat << EOF
572
573 Usage: configure [options]
574 Options: [defaults in brackets after descriptions]
575
576 EOF
577 echo "Standard options:"
578 echo "  --help                   print this message"
579 echo "  --prefix=PREFIX          install in PREFIX [$prefix]"
580 echo "  --interp-prefix=PREFIX   where to find shared libraries, etc."
581 echo "                           use %M for cpu name [$interp_prefix]"
582 echo "  --target-list=LIST       set target list [$target_list]"
583 echo ""
584 echo "Advanced options (experts only):"
585 echo "  --source-path=PATH       path of source code [$source_path]"
586 echo "  --cross-prefix=PREFIX    use PREFIX for compile tools [$cross_prefix]"
587 echo "  --cc=CC                  use C compiler CC [$cc]"
588 echo "  --host-cc=CC             use C compiler CC [$host_cc] for dyngen etc."
589 echo "  --extra-cflags=CFLAGS    append extra C compiler flags QEMU_CFLAGS"
590 echo "  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS"
591 echo "  --make=MAKE              use specified make [$make]"
592 echo "  --install=INSTALL        use specified install [$install]"
593 echo "  --static                 enable static build [$static]"
594 echo "  --enable-debug-tcg       enable TCG debugging"
595 echo "  --disable-debug-tcg      disable TCG debugging (default)"
596 echo "  --enable-debug           enable common debug build options"
597 echo "  --enable-sparse          enable sparse checker"
598 echo "  --disable-sparse         disable sparse checker (default)"
599 echo "  --disable-strip          disable stripping binaries"
600 echo "  --disable-werror         disable compilation abort on warning"
601 echo "  --disable-sdl            disable SDL"
602 echo "  --enable-cocoa           enable COCOA (Mac OS X only)"
603 echo "  --audio-drv-list=LIST    set audio drivers list:"
604 echo "                           Available drivers: $audio_possible_drivers"
605 echo "  --audio-card-list=LIST   set list of emulated audio cards [$audio_card_list]"
606 echo "                           Available cards: $audio_possible_cards"
607 echo "  --enable-mixemu          enable mixer emulation"
608 echo "  --disable-xen            disable xen backend driver support"
609 echo "  --disable-brlapi         disable BrlAPI"
610 echo "  --disable-vnc-tls        disable TLS encryption for VNC server"
611 echo "  --disable-vnc-sasl       disable SASL encryption for VNC server"
612 echo "  --disable-curses         disable curses output"
613 echo "  --disable-curl           disable curl connectivity"
614 echo "  --disable-bluez          disable bluez stack connectivity"
615 echo "  --disable-kvm            disable KVM acceleration support"
616 echo "  --disable-nptl           disable usermode NPTL support"
617 echo "  --enable-system          enable all system emulation targets"
618 echo "  --disable-system         disable all system emulation targets"
619 echo "  --enable-user            enable supported user emulation targets"
620 echo "  --disable-user           disable all user emulation targets"
621 echo "  --enable-linux-user      enable all linux usermode emulation targets"
622 echo "  --disable-linux-user     disable all linux usermode emulation targets"
623 echo "  --enable-darwin-user     enable all darwin usermode emulation targets"
624 echo "  --disable-darwin-user    disable all darwin usermode emulation targets"
625 echo "  --enable-bsd-user        enable all BSD usermode emulation targets"
626 echo "  --disable-bsd-user       disable all BSD usermode emulation targets"
627 echo "  --enable-guest-base      enable GUEST_BASE support for usermode"
628 echo "                           emulation targets"
629 echo "  --disable-guest-base     disable GUEST_BASE support"
630 echo "  --fmod-lib               path to FMOD library"
631 echo "  --fmod-inc               path to FMOD includes"
632 echo "  --oss-lib                path to OSS library"
633 echo "  --enable-uname-release=R Return R for uname -r in usermode emulation"
634 echo "  --sparc_cpu=V            Build qemu for Sparc architecture v7, v8, v8plus, v8plusa, v9"
635 echo "  --disable-vde            disable support for vde network"
636 echo "  --enable-io-thread       enable IO thread"
637 echo "  --disable-blobs          disable installing provided firmware blobs"
638 echo "  --kerneldir=PATH         look for kernel includes in PATH"
639 echo ""
640 echo "NOTE: The object files are built at the place where configure is launched"
641 exit 1
642 fi
643
644 if test ! -x "$(which cgcc 2>/dev/null)"; then
645     sparse="no"
646 fi
647
648 #
649 # Solaris specific configure tool chain decisions
650 #
651 if test "$solaris" = "yes" ; then
652   solinst=`which $install 2> /dev/null | /usr/bin/grep -v "no $install in"`
653   if test -z "$solinst" ; then
654     echo "Solaris install program not found. Use --install=/usr/ucb/install or"
655     echo "install fileutils from www.blastwave.org using pkg-get -i fileutils"
656     echo "to get ginstall which is used by default (which lives in /opt/csw/bin)"
657     exit 1
658   fi
659   if test "$solinst" = "/usr/sbin/install" ; then
660     echo "Error: Solaris /usr/sbin/install is not an appropriate install program."
661     echo "try ginstall from the GNU fileutils available from www.blastwave.org"
662     echo "using pkg-get -i fileutils, or use --install=/usr/ucb/install"
663     exit 1
664   fi
665   sol_ar=`which ar 2> /dev/null | /usr/bin/grep -v "no ar in"`
666   if test -z "$sol_ar" ; then
667     echo "Error: No path includes ar"
668     if test -f /usr/ccs/bin/ar ; then
669       echo "Add /usr/ccs/bin to your path and rerun configure"
670     fi
671     exit 1
672   fi
673 fi
674
675
676 if test -z "$target_list" ; then
677 # these targets are portable
678     if [ "$softmmu" = "yes" ] ; then
679         target_list="\
680 i386-softmmu \
681 x86_64-softmmu \
682 arm-softmmu \
683 cris-softmmu \
684 m68k-softmmu \
685 microblaze-softmmu \
686 mips-softmmu \
687 mipsel-softmmu \
688 mips64-softmmu \
689 mips64el-softmmu \
690 ppc-softmmu \
691 ppcemb-softmmu \
692 ppc64-softmmu \
693 sh4-softmmu \
694 sh4eb-softmmu \
695 sparc-softmmu \
696 sparc64-softmmu \
697 "
698     fi
699 # the following are Linux specific
700     if [ "$linux_user" = "yes" ] ; then
701         target_list="${target_list}\
702 i386-linux-user \
703 x86_64-linux-user \
704 alpha-linux-user \
705 arm-linux-user \
706 armeb-linux-user \
707 cris-linux-user \
708 m68k-linux-user \
709 microblaze-linux-user \
710 mips-linux-user \
711 mipsel-linux-user \
712 ppc-linux-user \
713 ppc64-linux-user \
714 ppc64abi32-linux-user \
715 sh4-linux-user \
716 sh4eb-linux-user \
717 sparc-linux-user \
718 sparc64-linux-user \
719 sparc32plus-linux-user \
720 "
721     fi
722 # the following are Darwin specific
723     if [ "$darwin_user" = "yes" ] ; then
724         target_list="$target_list i386-darwin-user ppc-darwin-user "
725     fi
726 # the following are BSD specific
727     if [ "$bsd_user" = "yes" ] ; then
728         target_list="${target_list}\
729 i386-bsd-user \
730 x86_64-bsd-user \
731 sparc-bsd-user \
732 sparc64-bsd-user \
733 "
734     fi
735 else
736     target_list=`echo "$target_list" | sed -e 's/,/ /g'`
737 fi
738 if test -z "$target_list" ; then
739     echo "No targets enabled"
740     exit 1
741 fi
742
743 feature_not_found() {
744   feature=$1
745
746   echo "ERROR"
747   echo "ERROR: User requested feature $feature"
748   echo "ERROR: configure was not able to found it"
749   echo "ERROR"
750   exit 1;
751 }
752
753 if test -z "$cross_prefix" ; then
754
755 # ---
756 # big/little endian test
757 cat > $TMPC << EOF
758 #include <inttypes.h>
759 int main(int argc, char ** argv){
760         volatile uint32_t i=0x01234567;
761         return (*((uint8_t*)(&i))) == 0x67;
762 }
763 EOF
764
765 if compile_prog "" "" ; then
766 $TMPE && bigendian="yes"
767 else
768 echo big/little test failed
769 fi
770
771 else
772
773 # if cross compiling, cannot launch a program, so make a static guess
774 case "$cpu" in
775   armv4b|hppa|m68k|mips|mips64|ppc|ppc64|s390|sparc|sparc64)
776     bigendian=yes
777   ;;
778 esac
779
780 fi
781
782 # host long bits test
783 hostlongbits="32"
784 case "$cpu" in
785   x86_64|alpha|ia64|sparc64|ppc64)
786     hostlongbits=64
787   ;;
788 esac
789
790 # Check host NPTL support
791 cat > $TMPC <<EOF
792 #include <sched.h>
793 #include <linux/futex.h>
794 void foo()
795 {
796 #if !defined(CLONE_SETTLS) || !defined(FUTEX_WAIT)
797 #error bork
798 #endif
799 }
800 EOF
801
802 if compile_object ; then
803   :
804 else
805    nptl="no"
806 fi
807
808 ##########################################
809 # zlib check
810
811 cat > $TMPC << EOF
812 #include <zlib.h>
813 int main(void) { zlibVersion(); return 0; }
814 EOF
815 if compile_prog "" "-lz" ; then
816     :
817 else
818     echo
819     echo "Error: zlib check failed"
820     echo "Make sure to have the zlib libs and headers installed."
821     echo
822     exit 1
823 fi
824
825 ##########################################
826 # xen probe
827
828 if test "$xen" = "yes" ; then
829   xen_libs="-lxenstore -lxenctrl -lxenguest"
830   cat > $TMPC <<EOF
831 #include <xenctrl.h>
832 #include <xs.h>
833 int main(void) { xs_daemon_open(); xc_interface_open(); return 0; }
834 EOF
835   if compile_prog "" "$xen_libs" ; then
836     libs_softmmu="$xen_libs $libs_softmmu"
837   else
838     xen="no"
839   fi
840 fi
841
842 ##########################################
843 # SDL probe
844
845 sdl_too_old=no
846
847 if test "$sdl" = "yes" ; then
848   sdl=no
849   cat > $TMPC << EOF
850 #include <SDL.h>
851 #undef main /* We don't want SDL to override our main() */
852 int main( void ) { return SDL_Init (SDL_INIT_VIDEO); }
853 EOF
854   sdl_cflags=`sdl-config --cflags 2> /dev/null`
855   sdl_libs=`sdl-config --libs 2> /dev/null`
856   if compile_prog "$sdl_cflags" "$sdl_libs" ; then
857     _sdlversion=`sdl-config --version | sed 's/[^0-9]//g'`
858     if test "$_sdlversion" -lt 121 ; then
859       sdl_too_old=yes
860     else
861       if test "$cocoa" = "no" ; then
862         sdl=yes
863       fi
864     fi
865
866     # static link with sdl ?
867     if test "$sdl" = "yes" -a "$static" = "yes" ; then
868       sdl_libs=`sdl-config --static-libs 2>/dev/null`
869       if test `sdl-config --static-libs 2>/dev/null | grep \\\-laa > /dev/null` ; then
870          sdl_libs="$sdl_libs `aalib-config --static-libs >2 /dev/null`"
871          sdl_cflags="$sd_cflags `aalib-config --cflags >2 /dev/null`"
872       fi
873       if compile_prog "$sdl_cflags" "$sdl_libs" ; then
874         :
875       else
876         sdl=no
877       fi
878     fi # static link
879   fi # sdl compile test
880 fi
881
882 if test "$sdl" = "yes" ; then
883   cat > $TMPC <<EOF
884 #include <SDL.h>
885 #if defined(SDL_VIDEO_DRIVER_X11)
886 #include <X11/XKBlib.h>
887 #else
888 #error No x11 support
889 #endif
890 int main(void) { return 0; }
891 EOF
892   if compile_prog "$sdl_cflags" "$sdl_libs" ; then
893     sdl_libs="$sdl_libs -lX11"
894   fi
895   if test "$mingw32" = "yes" ; then
896     sdl_libs="`echo $sdl_libs | sed s/-mwindows//g` -mconsole"
897   fi
898   libs_softmmu="$sdl_libs $libs_softmmu"
899 fi
900
901 ##########################################
902 # VNC TLS detection
903 if test "$vnc_tls" = "yes" ; then
904 cat > $TMPC <<EOF
905 #include <gnutls/gnutls.h>
906 int main(void) { gnutls_session_t s; gnutls_init(&s, GNUTLS_SERVER); return 0; }
907 EOF
908     vnc_tls_cflags=`pkg-config --cflags gnutls 2> /dev/null`
909     vnc_tls_libs=`pkg-config --libs gnutls 2> /dev/null`
910     if compile_prog "$vnc_tls_cflags" "$vnc_tls_libs" ; then
911         libs_softmmu="$vnc_tls_libs $libs_softmmu"
912     else
913         vnc_tls="no"
914     fi
915 fi
916
917 ##########################################
918 # VNC SASL detection
919 if test "$vnc_sasl" = "yes" ; then
920 cat > $TMPC <<EOF
921 #include <sasl/sasl.h>
922 #include <stdio.h>
923 int main(void) { sasl_server_init(NULL, "qemu"); return 0; }
924 EOF
925     # Assuming Cyrus-SASL installed in /usr prefix
926     vnc_sasl_cflags=""
927     vnc_sasl_libs="-lsasl2"
928     if compile_prog "$vnc_sasl_cflags" "$vnc_sasl_libs" ; then
929         libs_softmmu="$vnc_sasl_libs $libs_softmmu"
930     else
931         vnc_sasl="no"
932     fi
933 fi
934
935 ##########################################
936 # fnmatch() probe, used for ACL routines
937 fnmatch="no"
938 cat > $TMPC << EOF
939 #include <fnmatch.h>
940 int main(void)
941 {
942     fnmatch("foo", "foo", 0);
943     return 0;
944 }
945 EOF
946 if compile_prog "" "" ; then
947    fnmatch="yes"
948 fi
949
950 ##########################################
951 # vde libraries probe
952 if test "$vde" = "yes" ; then
953   vde=no
954   vde_libs="-lvdeplug"
955   cat > $TMPC << EOF
956 #include <libvdeplug.h>
957 int main(void)
958 {
959     struct vde_open_args a = {0, 0, 0};
960     vde_open("", "", &a);
961     return 0;
962 }
963 EOF
964   if compile_prog "" "$vde_libs" ; then
965     vde=yes
966     libs_softmmu="$vde_libs $libs_softmmu"
967     libs_tools="$vde_libs $libs_tools"
968   fi
969 fi
970
971 ##########################################
972 # Sound support libraries probe
973
974 audio_drv_probe()
975 {
976     drv=$1
977     hdr=$2
978     lib=$3
979     exp=$4
980     cfl=$5
981         cat > $TMPC << EOF
982 #include <$hdr>
983 int main(void) { $exp }
984 EOF
985     if compile_prog "$cfl" "$lib" ; then
986         :
987     else
988         echo
989         echo "Error: $drv check failed"
990         echo "Make sure to have the $drv libs and headers installed."
991         echo
992         exit 1
993     fi
994 }
995
996 audio_drv_list=`echo "$audio_drv_list" | sed -e 's/,/ /g'`
997 for drv in $audio_drv_list; do
998     case $drv in
999     alsa)
1000     audio_drv_probe $drv alsa/asoundlib.h -lasound \
1001         "snd_pcm_t **handle; return snd_pcm_close(*handle);"
1002     libs_softmmu="-lasound $libs_softmmu"
1003     ;;
1004
1005     fmod)
1006     if test -z $fmod_lib || test -z $fmod_inc; then
1007         echo
1008         echo "Error: You must specify path to FMOD library and headers"
1009         echo "Example: --fmod-inc=/path/include/fmod --fmod-lib=/path/lib/libfmod-3.74.so"
1010         echo
1011         exit 1
1012     fi
1013     audio_drv_probe $drv fmod.h $fmod_lib "return FSOUND_GetVersion();" "-I $fmod_inc"
1014     libs_softmmu="$fmod_lib $libs_softmmu"
1015     ;;
1016
1017     esd)
1018     audio_drv_probe $drv esd.h -lesd 'return esd_play_stream(0, 0, "", 0);'
1019     libs_softmmu="-lesd $libs_softmmu"
1020     audio_pt_int="yes"
1021     ;;
1022
1023     pa)
1024     audio_drv_probe $drv pulse/simple.h -lpulse-simple \
1025         "pa_simple *s = NULL; pa_simple_free(s); return 0;"
1026     libs_softmmu="-lpulse-simple $libs_softmmu"
1027     audio_pt_int="yes"
1028     ;;
1029
1030     coreaudio)
1031       libs_softmmu="-framework CoreAudio $libs_softmmu"
1032     ;;
1033
1034     dsound)
1035       libs_softmmu="-lole32 -ldxguid $libs_softmmu"
1036     ;;
1037
1038     oss)
1039       libs_softmmu="$oss_lib $libs_softmmu"
1040     ;;
1041
1042     sdl|wav)
1043     # XXX: Probes for CoreAudio, DirectSound, SDL(?)
1044     ;;
1045
1046     *)
1047     echo "$audio_possible_drivers" | grep -q "\<$drv\>" || {
1048         echo
1049         echo "Error: Unknown driver '$drv' selected"
1050         echo "Possible drivers are: $audio_possible_drivers"
1051         echo
1052         exit 1
1053     }
1054     ;;
1055     esac
1056 done
1057
1058 ##########################################
1059 # BrlAPI probe
1060
1061 if test "$brlapi" = "yes" ; then
1062   brlapi=no
1063   brlapi_libs="-lbrlapi"
1064   cat > $TMPC << EOF
1065 #include <brlapi.h>
1066 int main( void ) { return brlapi__openConnection (NULL, NULL, NULL); }
1067 EOF
1068   if compile_prog "" "$brlapi_libs" ; then
1069     brlapi=yes
1070     libs_softmmu="$brlapi_libs $libs_softmmu"
1071   fi
1072 fi
1073
1074 ##########################################
1075 # curses probe
1076 curses_list="-lncurses -lcurses"
1077
1078 if test "$curses" = "yes" ; then
1079   curses=no
1080   cat > $TMPC << EOF
1081 #include <curses.h>
1082 #ifdef __OpenBSD__
1083 #define resize_term resizeterm
1084 #endif
1085 int main(void) { resize_term(0, 0); return curses_version(); }
1086 EOF
1087   for curses_lib in $curses_list; do
1088     if compile_prog "" "$curses_lib" ; then
1089       curses=yes
1090       libs_softmmu="$curses_lib $libs_softmmu"
1091       break
1092     fi
1093   done
1094 fi
1095
1096 ##########################################
1097 # curl probe
1098
1099 if test "$curl" = "yes" ; then
1100   curl=no
1101   cat > $TMPC << EOF
1102 #include <curl/curl.h>
1103 int main(void) { return curl_easy_init(); }
1104 EOF
1105   curl_cflags=`curl-config --cflags 2>/dev/null`
1106   curl_libs=`curl-config --libs 2>/dev/null`
1107   if compile_prog "$curl_cflags" "$curl_libs" ; then
1108     curl=yes
1109     libs_tools="$curl_libs $libs_tools"
1110     libs_softmmu="$curl_libs $libs_softmmu"
1111   fi
1112 fi # test "$curl"
1113
1114 ##########################################
1115 # bluez support probe
1116 if test "$bluez" = "yes" ; then
1117   `pkg-config bluez 2> /dev/null` || bluez="no"
1118 fi
1119 if test "$bluez" = "yes" ; then
1120   cat > $TMPC << EOF
1121 #include <bluetooth/bluetooth.h>
1122 int main(void) { return bt_error(0); }
1123 EOF
1124   bluez_cflags=`pkg-config --cflags bluez 2> /dev/null`
1125   bluez_libs=`pkg-config --libs bluez 2> /dev/null`
1126   if compile_prog "$bluez_cflags" "$bluez_libs" ; then
1127     libs_softmmu="$bluez_libs $libs_softmmu"
1128   else
1129     bluez="no"
1130   fi
1131 fi
1132
1133 ##########################################
1134 # kvm probe
1135 if test "$kvm" = "yes" ; then
1136     cat > $TMPC <<EOF
1137 #include <linux/kvm.h>
1138 #if !defined(KVM_API_VERSION) || KVM_API_VERSION < 12 || KVM_API_VERSION > 12
1139 #error Invalid KVM version
1140 #endif
1141 #if !defined(KVM_CAP_USER_MEMORY)
1142 #error Missing KVM capability KVM_CAP_USER_MEMORY
1143 #endif
1144 #if !defined(KVM_CAP_SET_TSS_ADDR)
1145 #error Missing KVM capability KVM_CAP_SET_TSS_ADDR
1146 #endif
1147 #if !defined(KVM_CAP_DESTROY_MEMORY_REGION_WORKS)
1148 #error Missing KVM capability KVM_CAP_DESTROY_MEMORY_REGION_WORKS
1149 #endif
1150 int main(void) { return 0; }
1151 EOF
1152   if test "$kerneldir" != "" ; then
1153       kvm_cflags=-I"$kerneldir"/include
1154       if test \( "$cpu" = "i386" -o "$cpu" = "x86_64" \) \
1155          -a -d "$kerneldir/arch/x86/include" ; then
1156             kvm_cflags="$kvm_cflags -I$kerneldir/arch/x86/include"
1157         elif test "$cpu" = "ppc" -a -d "$kerneldir/arch/powerpc/include" ; then
1158             kvm_cflags="$kvm_cflags -I$kerneldir/arch/powerpc/include"
1159         elif test -d "$kerneldir/arch/$cpu/include" ; then
1160             kvm_cflags="$kvm_cflags -I$kerneldir/arch/$cpu/include"
1161       fi
1162   else
1163       kvm_cflags=""
1164   fi
1165   if compile_prog "$kvm_cflags" "" ; then
1166     :
1167   else
1168     kvm="no";
1169     if [ -x "`which awk 2>/dev/null`" ] && \
1170        [ -x "`which grep 2>/dev/null`" ]; then
1171       kvmerr=`LANG=C $cc $QEMU_CFLAGS -o $TMPE $kvm_cflags $TMPC 2>&1 \
1172         | grep "error: " \
1173         | awk -F "error: " '{if (NR>1) printf(", "); printf("%s",$2);}'`
1174       if test "$kvmerr" != "" ; then
1175         kvm="no - (${kvmerr})\n\
1176     NOTE: To enable KVM support, update your kernel to 2.6.29+ or install \
1177 recent kvm-kmod from http://sourceforge.net/projects/kvm."
1178       fi
1179     fi
1180   fi
1181 fi
1182
1183 ##########################################
1184 # pthread probe
1185 PTHREADLIBS_LIST="-lpthread -lpthreadGC2"
1186
1187 pthread=no
1188 cat > $TMPC << EOF
1189 #include <pthread.h>
1190 int main(void) { pthread_create(0,0,0,0); return 0; }
1191 EOF
1192 for pthread_lib in $PTHREADLIBS_LIST; do
1193   if compile_prog "" "$pthread_lib" ; then
1194     pthread=yes
1195     LIBS="$pthread_lib $LIBS"
1196     break
1197   fi
1198 done
1199
1200 if test "$pthread" = no; then
1201   echo
1202   echo "Error: pthread check failed"
1203   echo "Make sure to have the pthread libs and headers installed."
1204   echo
1205   exit 1
1206 fi
1207
1208 ##########################################
1209 # iovec probe
1210 cat > $TMPC <<EOF
1211 #include <sys/types.h>
1212 #include <sys/uio.h>
1213 #include <unistd.h>
1214 int main(void) { struct iovec iov; return 0; }
1215 EOF
1216 iovec=no
1217 if compile_prog "" "" ; then
1218   iovec=yes
1219 fi
1220
1221 ##########################################
1222 # preadv probe
1223 cat > $TMPC <<EOF
1224 #include <sys/types.h>
1225 #include <sys/uio.h>
1226 #include <unistd.h>
1227 int main(void) { preadv; }
1228 EOF
1229 preadv=no
1230 if compile_prog "" "" ; then
1231   preadv=yes
1232 fi
1233
1234 ##########################################
1235 # fdt probe
1236 if test "$fdt" = "yes" ; then
1237   fdt=no
1238   fdt_libs="-lfdt"
1239   cat > $TMPC << EOF
1240 int main(void) { return 0; }
1241 EOF
1242   if compile_prog "" "$fdt_libs" ; then
1243     fdt=yes
1244     libs_softmmu="$fdt_libs $libs_softmmu"
1245   fi
1246 fi
1247
1248 #
1249 # Check for xxxat() functions when we are building linux-user
1250 # emulator.  This is done because older glibc versions don't
1251 # have syscall stubs for these implemented.
1252 #
1253 atfile=no
1254 cat > $TMPC << EOF
1255 #define _ATFILE_SOURCE
1256 #include <sys/types.h>
1257 #include <fcntl.h>
1258 #include <unistd.h>
1259
1260 int
1261 main(void)
1262 {
1263         /* try to unlink nonexisting file */
1264         return (unlinkat(AT_FDCWD, "nonexistent_file", 0));
1265 }
1266 EOF
1267 if compile_prog "" "" ; then
1268   atfile=yes
1269 fi
1270
1271 # Check for inotify functions when we are building linux-user
1272 # emulator.  This is done because older glibc versions don't
1273 # have syscall stubs for these implemented.  In that case we
1274 # don't provide them even if kernel supports them.
1275 #
1276 inotify=no
1277 cat > $TMPC << EOF
1278 #include <sys/inotify.h>
1279
1280 int
1281 main(void)
1282 {
1283         /* try to start inotify */
1284         return inotify_init();
1285 }
1286 EOF
1287 if compile_prog "" "" ; then
1288   inotify=yes
1289 fi
1290
1291 # check if utimensat and futimens are supported
1292 utimens=no
1293 cat > $TMPC << EOF
1294 #define _ATFILE_SOURCE
1295 #define _GNU_SOURCE
1296 #include <stddef.h>
1297 #include <fcntl.h>
1298
1299 int main(void)
1300 {
1301     utimensat(AT_FDCWD, "foo", NULL, 0);
1302     futimens(0, NULL);
1303     return 0;
1304 }
1305 EOF
1306 if compile_prog "" "" ; then
1307   utimens=yes
1308 fi
1309
1310 # check if pipe2 is there
1311 pipe2=no
1312 cat > $TMPC << EOF
1313 #define _GNU_SOURCE
1314 #include <unistd.h>
1315 #include <fcntl.h>
1316
1317 int main(void)
1318 {
1319     int pipefd[2];
1320     pipe2(pipefd, O_CLOEXEC);
1321     return 0;
1322 }
1323 EOF
1324 if compile_prog "" "" ; then
1325   pipe2=yes
1326 fi
1327
1328 # check if tee/splice is there. vmsplice was added same time.
1329 splice=no
1330 cat > $TMPC << EOF
1331 #define _GNU_SOURCE
1332 #include <unistd.h>
1333 #include <fcntl.h>
1334 #include <limits.h>
1335
1336 int main(void)
1337 {
1338     int len, fd;
1339     len = tee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, SPLICE_F_NONBLOCK);
1340     splice(STDIN_FILENO, NULL, fd, NULL, len, SPLICE_F_MOVE);
1341     return 0;
1342 }
1343 EOF
1344 if compile_prog "" "" ; then
1345   splice=yes
1346 fi
1347
1348 # Check if tools are available to build documentation.
1349 if test "$build_docs" = "yes" -a \( ! -x "`which texi2html 2>/dev/null`" -o ! -x "`which pod2man 2>/dev/null`" \) ; then
1350   build_docs="no"
1351 fi
1352
1353 # Search for bsawp_32 function
1354 byteswap_h=no
1355 cat > $TMPC << EOF
1356 #include <byteswap.h>
1357 int main(void) { return bswap_32(0); }
1358 EOF
1359 if compile_prog "" "" ; then
1360   byteswap_h=yes
1361 fi
1362
1363 # Search for bsawp_32 function
1364 bswap_h=no
1365 cat > $TMPC << EOF
1366 #include <sys/endian.h>
1367 #include <sys/types.h>
1368 #include <machine/bswap.h>
1369 int main(void) { return bswap32(0); }
1370 EOF
1371 if compile_prog "" "" ; then
1372   bswap_h=yes
1373 fi
1374
1375 ##########################################
1376 # Do we need librt
1377 cat > $TMPC <<EOF
1378 #include <signal.h>
1379 #include <time.h>
1380 int main(void) { clockid_t id; return clock_gettime(id, NULL); }
1381 EOF
1382
1383 if compile_prog "" "" ; then
1384   :
1385 elif compile_prog "" "-lrt" ; then
1386   LIBS="-lrt $LIBS"
1387 fi
1388
1389 # Determine what linker flags to use to force archive inclusion
1390 check_linker_flags()
1391 {
1392     w2=
1393     if test "$2" ; then
1394         w2=-Wl,$2
1395     fi
1396     compile_prog "" "-Wl,$1 ${w2}"
1397 }
1398
1399 cat > $TMPC << EOF
1400 int main(void) { }
1401 EOF
1402 if check_linker_flags --whole-archive --no-whole-archive ; then
1403     # GNU ld
1404     arlibs_begin="-Wl,--whole-archive"
1405     arlibs_end="-Wl,--no-whole-archive"
1406 elif check_linker_flags -z,allextract -z,defaultextract ; then
1407     # Solaris ld
1408     arlibs_begin"=-Wl,-z,allextract"
1409     arlibs_end="-Wl,-z,defaultextract"
1410 elif check_linker_flags -all_load ; then
1411     # Mac OS X
1412     arlibs_begin="-all_load"
1413     arlibs_end=""
1414 else
1415     echo "Error: your linker does not support --whole-archive or -z."
1416     echo "Please report to qemu-devel@nongnu.org"
1417     exit 1
1418 fi
1419
1420 if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaries" != yes -a \
1421         "$aix" != "yes" ; then
1422     libs_softmmu="-lutil $libs_softmmu"
1423 fi
1424
1425 # End of CC checks
1426 # After here, no more $cc or $ld runs
1427
1428 # default flags for all hosts
1429 QEMU_CFLAGS="-fno-strict-aliasing $QEMU_CFLAGS"
1430 CFLAGS="-g $CFLAGS"
1431 if test "$debug" = "no" ; then
1432   CFLAGS="-O2 $CFLAGS"
1433 fi
1434 QEMU_CFLAGS="-Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
1435 QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
1436 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
1437 QEMU_CFLAGS="-U_FORTIFY_SOURCE $QEMU_CFLAGS"
1438 QEMU_CFLAGS="-I. -I\$(SRC_PATH) -MMD -MP -MT \$@ $QEMU_CFLAGS"
1439 LDFLAGS="-g $LDFLAGS"
1440
1441 # Consult white-list to determine whether to enable werror
1442 # by default.  Only enable by default for git builds
1443 if test -z "$werror" ; then
1444     z_version=`cut -f3 -d. $source_path/VERSION`
1445     if test "$z_version" = "50" -a \
1446         "$linux" = "yes" ; then
1447         werror="yes"
1448     else
1449         werror="no"
1450     fi
1451 fi
1452
1453 if test "$werror" = "yes" ; then
1454     QEMU_CFLAGS="-Werror $QEMU_CFLAGS"
1455 fi
1456
1457 if test "$solaris" = "no" ; then
1458     if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
1459         LDFLAGS="-Wl,--warn-common $LDFLAGS"
1460     fi
1461 fi
1462
1463 if test "$mingw32" = "yes" ; then
1464   if test -z "$prefix" ; then
1465       prefix="c:/Program Files/Qemu"
1466   fi
1467   mansuffix=""
1468   datasuffix=""
1469   docsuffix=""
1470   binsuffix=""
1471 else
1472   if test -z "$prefix" ; then
1473       prefix="/usr/local"
1474   fi
1475   mansuffix="/share/man"
1476   datasuffix="/share/qemu"
1477   docsuffix="/share/doc/qemu"
1478   binsuffix="/bin"
1479 fi
1480
1481 echo "Install prefix    $prefix"
1482 echo "BIOS directory    $prefix$datasuffix"
1483 echo "binary directory  $prefix$binsuffix"
1484 if test "$mingw32" = "no" ; then
1485 echo "Manual directory  $prefix$mansuffix"
1486 echo "ELF interp prefix $interp_prefix"
1487 fi
1488 echo "Source path       $source_path"
1489 echo "C compiler        $cc"
1490 echo "Host C compiler   $host_cc"
1491 echo "CFLAGS            $CFLAGS"
1492 echo "QEMU_CFLAGS       $QEMU_CFLAGS"
1493 echo "LDFLAGS           $LDFLAGS"
1494 echo "make              $make"
1495 echo "install           $install"
1496 echo "host CPU          $cpu"
1497 echo "host big endian   $bigendian"
1498 echo "target list       $target_list"
1499 echo "tcg debug enabled $debug_tcg"
1500 echo "gprof enabled     $gprof"
1501 echo "sparse enabled    $sparse"
1502 echo "strip binaries    $strip_opt"
1503 echo "profiler          $profiler"
1504 echo "static build      $static"
1505 echo "-Werror enabled   $werror"
1506 if test "$darwin" = "yes" ; then
1507     echo "Cocoa support     $cocoa"
1508 fi
1509 echo "SDL support       $sdl"
1510 echo "curses support    $curses"
1511 echo "curl support      $curl"
1512 echo "mingw32 support   $mingw32"
1513 echo "Audio drivers     $audio_drv_list"
1514 echo "Extra audio cards $audio_card_list"
1515 echo "Mixer emulation   $mixemu"
1516 echo "VNC TLS support   $vnc_tls"
1517 echo "VNC SASL support  $vnc_sasl"
1518 if test -n "$sparc_cpu"; then
1519     echo "Target Sparc Arch $sparc_cpu"
1520 fi
1521 echo "xen support       $xen"
1522 echo "brlapi support    $brlapi"
1523 echo "Documentation     $build_docs"
1524 [ ! -z "$uname_release" ] && \
1525 echo "uname -r          $uname_release"
1526 echo "NPTL support      $nptl"
1527 echo "GUEST_BASE        $guest_base"
1528 echo "vde support       $vde"
1529 echo "IO thread         $io_thread"
1530 echo "Install blobs     $blobs"
1531 echo -e "KVM support       $kvm"
1532 echo "fdt support       $fdt"
1533 echo "preadv support    $preadv"
1534
1535 if test $sdl_too_old = "yes"; then
1536 echo "-> Your SDL version is too old - please upgrade to have SDL support"
1537 fi
1538
1539 config_host_mak="config-host.mak"
1540 config_host_h="config-host.h"
1541 config_host_ld="config-host.ld"
1542
1543 #echo "Creating $config_host_mak and $config_host_h"
1544
1545 test -f $config_host_h && mv $config_host_h ${config_host_h}~
1546
1547 echo "# Automatically generated by configure - do not modify" > $config_host_mak
1548 printf "# Configured with:" >> $config_host_mak
1549 printf " '%s'" "$0" "$@" >> $config_host_mak
1550 echo >> $config_host_mak
1551
1552 echo "CONFIG_QEMU_SHAREDIR=\"$prefix$datasuffix\"" >> $config_host_mak
1553
1554 case "$cpu" in
1555   i386|x86_64|alpha|cris|hppa|ia64|m68k|microblaze|mips|mips64|ppc|ppc64|s390|sparc|sparc64)
1556     ARCH=$cpu
1557   ;;
1558   armv4b|armv4l)
1559     ARCH=arm
1560   ;;
1561   *)
1562     echo "Unsupported CPU = $cpu"
1563     exit 1
1564   ;;
1565 esac
1566 echo "ARCH=$ARCH" >> $config_host_mak
1567 if test "$debug_tcg" = "yes" ; then
1568   echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
1569 fi
1570 if test "$debug" = "yes" ; then
1571   echo "CONFIG_DEBUG_EXEC=y" >> $config_host_mak
1572 fi
1573 if test "$strip_opt" = "yes" ; then
1574   echo "STRIP_OPT=-s" >> $config_host_mak
1575 fi
1576 if test "$bigendian" = "yes" ; then
1577   echo "HOST_WORDS_BIGENDIAN=y" >> $config_host_mak
1578 fi
1579 echo "HOST_LONG_BITS=$hostlongbits" >> $config_host_mak
1580 if test "$mingw32" = "yes" ; then
1581   echo "CONFIG_WIN32=y" >> $config_host_mak
1582 else
1583   echo "CONFIG_POSIX=y" >> $config_host_mak
1584 fi
1585
1586 if test "$darwin" = "yes" ; then
1587   echo "CONFIG_DARWIN=y" >> $config_host_mak
1588 fi
1589
1590 if test "$aix" = "yes" ; then
1591   echo "CONFIG_AIX=y" >> $config_host_mak
1592 fi
1593
1594 if test "$solaris" = "yes" ; then
1595   echo "CONFIG_SOLARIS=y" >> $config_host_mak
1596   echo "CONFIG_SOLARIS_VERSION=$solarisrev" >> $config_host_mak
1597   if test "$needs_libsunmath" = "yes" ; then
1598     echo "CONFIG_NEEDS_LIBSUNMATH=y" >> $config_host_mak
1599   fi
1600 fi
1601 if test "$static" = "yes" ; then
1602   echo "CONFIG_STATIC=y" >> $config_host_mak
1603   LDFLAGS="-static $LDFLAGS"
1604 fi
1605 if test $profiler = "yes" ; then
1606   echo "CONFIG_PROFILER=y" >> $config_host_mak
1607 fi
1608 if test "$slirp" = "yes" ; then
1609   echo "CONFIG_SLIRP=y" >> $config_host_mak
1610   CFLAGS="-I\$(SRC_PATH)/slirp $CFLAGS"
1611 fi
1612 if test "$vde" = "yes" ; then
1613   echo "CONFIG_VDE=y" >> $config_host_mak
1614 fi
1615 for card in $audio_card_list; do
1616     def=CONFIG_`echo $card | tr '[:lower:]' '[:upper:]'`
1617     echo "$def=y" >> $config_host_mak
1618 done
1619 echo "CONFIG_AUDIO_DRIVERS=$audio_drv_list" >> $config_host_mak
1620 for drv in $audio_drv_list; do
1621     def=CONFIG_`echo $drv | tr '[:lower:]' '[:upper:]'`
1622     echo "$def=y" >> $config_host_mak
1623     if test "$drv" = "fmod"; then
1624         echo "FMOD_CFLAGS=-I$fmod_inc" >> $config_host_mak
1625     fi
1626 done
1627 if test "$audio_pt_int" = "yes" ; then
1628   echo "CONFIG_AUDIO_PT_INT=y" >> $config_host_mak
1629 fi
1630 if test "$mixemu" = "yes" ; then
1631   echo "CONFIG_MIXEMU=y" >> $config_host_mak
1632 fi
1633 if test "$vnc_tls" = "yes" ; then
1634   echo "CONFIG_VNC_TLS=y" >> $config_host_mak
1635   echo "VNC_TLS_CFLAGS=$vnc_tls_cflags" >> $config_host_mak
1636 fi
1637 if test "$vnc_sasl" = "yes" ; then
1638   echo "CONFIG_VNC_SASL=y" >> $config_host_mak
1639   echo "VNC_SASL_CFLAGS=$vnc_sasl_cflags" >> $config_host_mak
1640 fi
1641 if test "$fnmatch" = "yes" ; then
1642   echo "CONFIG_FNMATCH=y" >> $config_host_mak
1643 fi
1644 qemu_version=`head $source_path/VERSION`
1645 echo "VERSION=$qemu_version" >>$config_host_mak
1646 echo "PKGVERSION=$pkgversion" >>$config_host_mak
1647 echo "SRC_PATH=$source_path" >> $config_host_mak
1648 if [ "$source_path_used" = "yes" ]; then
1649   echo "VPATH=$source_path" >> $config_host_mak
1650 fi
1651 echo "TARGET_DIRS=$target_list" >> $config_host_mak
1652 if [ "$build_docs" = "yes" ] ; then
1653   echo "BUILD_DOCS=yes" >> $config_host_mak
1654 fi
1655 if test "$sdl" = "yes" ; then
1656   echo "CONFIG_SDL=y" >> $config_host_mak
1657   echo "SDL_CFLAGS=$sdl_cflags" >> $config_host_mak
1658 fi
1659 if test "$cocoa" = "yes" ; then
1660   echo "CONFIG_COCOA=y" >> $config_host_mak
1661 fi
1662 if test "$curses" = "yes" ; then
1663   echo "CONFIG_CURSES=y" >> $config_host_mak
1664 fi
1665 if test "$atfile" = "yes" ; then
1666   echo "CONFIG_ATFILE=y" >> $config_host_mak
1667 fi
1668 if test "$utimens" = "yes" ; then
1669   echo "CONFIG_UTIMENSAT=y" >> $config_host_mak
1670 fi
1671 if test "$pipe2" = "yes" ; then
1672   echo "CONFIG_PIPE2=y" >> $config_host_mak
1673 fi
1674 if test "$splice" = "yes" ; then
1675   echo "CONFIG_SPLICE=y" >> $config_host_mak
1676 fi
1677 if test "$inotify" = "yes" ; then
1678   echo "CONFIG_INOTIFY=y" >> $config_host_mak
1679 fi
1680 if test "$byteswap_h" = "yes" ; then
1681   echo "CONFIG_BYTESWAP_H=y" >> $config_host_mak
1682 fi
1683 if test "$bswap_h" = "yes" ; then
1684   echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak
1685 fi
1686 if test "$curl" = "yes" ; then
1687   echo "CONFIG_CURL=y" >> $config_host_mak
1688   echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak
1689 fi
1690 if test "$brlapi" = "yes" ; then
1691   echo "CONFIG_BRLAPI=y" >> $config_host_mak
1692 fi
1693 if test "$bluez" = "yes" ; then
1694   echo "CONFIG_BLUEZ=y" >> $config_host_mak
1695   echo "BLUEZ_CFLAGS=$bluez_cflags" >> $config_host_mak
1696 fi
1697 if test "$xen" = "yes" ; then
1698   echo "CONFIG_XEN=y" >> $config_host_mak
1699 fi
1700 if test "$io_thread" = "yes" ; then
1701   echo "CONFIG_IOTHREAD=y" >> $config_host_mak
1702 fi
1703 if test "$blobs" = "yes" ; then
1704   echo "INSTALL_BLOBS=yes" >> $config_host_mak
1705 fi
1706 if test "$iovec" = "yes" ; then
1707   echo "CONFIG_IOVEC=y" >> $config_host_mak
1708 fi
1709 if test "$preadv" = "yes" ; then
1710   echo "CONFIG_PREADV=y" >> $config_host_mak
1711 fi
1712 if test "$fdt" = "yes" ; then
1713   echo "CONFIG_FDT=y" >> $config_host_mak
1714 fi
1715
1716 # XXX: suppress that
1717 if [ "$bsd" = "yes" ] ; then
1718   echo "CONFIG_BSD=y" >> $config_host_mak
1719 fi
1720
1721 echo "CONFIG_UNAME_RELEASE=\"$uname_release\"" >> $config_host_mak
1722
1723 # USB host support
1724 case "$usb" in
1725 linux)
1726   echo "HOST_USB=linux" >> $config_host_mak
1727 ;;
1728 bsd)
1729   echo "HOST_USB=bsd" >> $config_host_mak
1730 ;;
1731 *)
1732   echo "HOST_USB=stub" >> $config_host_mak
1733 ;;
1734 esac
1735
1736 tools=
1737 if test `expr "$target_list" : ".*softmmu.*"` != 0 ; then
1738   tools="qemu-img\$(EXESUF) $tools"
1739   if [ "$linux" = "yes" ] ; then
1740       tools="qemu-nbd\$(EXESUF) qemu-io\$(EXESUF) $tools"
1741   fi
1742 fi
1743 echo "TOOLS=$tools" >> $config_host_mak
1744
1745 # Mac OS X ships with a broken assembler
1746 roms=
1747 if test \( "$cpu" = "i386" -o "$cpu" = "x86_64" \) -a \
1748         "$targetos" != "Darwin" ; then
1749   roms="optionrom"
1750 fi
1751 echo "ROMS=$roms" >> $config_host_mak
1752
1753 echo "prefix=$prefix" >> $config_host_mak
1754 echo "bindir=\${prefix}$binsuffix" >> $config_host_mak
1755 echo "mandir=\${prefix}$mansuffix" >> $config_host_mak
1756 echo "datadir=\${prefix}$datasuffix" >> $config_host_mak
1757 echo "docdir=\${prefix}$docsuffix" >> $config_host_mak
1758 echo "MAKE=$make" >> $config_host_mak
1759 echo "INSTALL=$install" >> $config_host_mak
1760 echo "INSTALL_DIR=$install -d -m0755 -p" >> $config_host_mak
1761 echo "INSTALL_DATA=$install -m0644 -p" >> $config_host_mak
1762 echo "INSTALL_PROG=$install -m0755 -p" >> $config_host_mak
1763 echo "CC=$cc" >> $config_host_mak
1764 echo "HOST_CC=$host_cc" >> $config_host_mak
1765 if test "$sparse" = "yes" ; then
1766   echo "CC      := REAL_CC=\"\$(CC)\" cgcc"       >> $config_host_mak
1767   echo "HOST_CC := REAL_CC=\"\$(HOST_CC)\" cgcc"  >> $config_host_mak
1768   echo "QEMU_CFLAGS  += -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-non-pointer-null" >> $config_host_mak
1769 fi
1770 echo "AR=$ar" >> $config_host_mak
1771 echo "OBJCOPY=$objcopy" >> $config_host_mak
1772 echo "LD=$ld" >> $config_host_mak
1773 echo "CFLAGS=$CFLAGS" >> $config_host_mak
1774 echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
1775 echo "HELPER_CFLAGS=$helper_cflags" >> $config_host_mak
1776 echo "LDFLAGS=$LDFLAGS" >> $config_host_mak
1777 echo "ARLIBS_BEGIN=$arlibs_begin" >> $config_host_mak
1778 echo "ARLIBS_END=$arlibs_end" >> $config_host_mak
1779 echo "LIBS+=$LIBS" >> $config_host_mak
1780 echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak
1781 echo "EXESUF=$EXESUF" >> $config_host_mak
1782
1783 echo "/* Automatically generated by configure - do not modify */" > $config_host_h
1784
1785 /bin/sh $source_path/create_config < $config_host_mak >> $config_host_h
1786
1787 if test -f ${config_host_h}~ ; then
1788   if cmp -s $config_host_h ${config_host_h}~ ; then
1789     mv ${config_host_h}~ $config_host_h
1790   else
1791     rm ${config_host_h}~
1792   fi
1793 fi
1794
1795 # generate list of library paths for linker script
1796
1797 $ld --verbose -v 2> /dev/null | grep SEARCH_DIR > ${config_host_ld}
1798
1799 if test -f ${config_host_ld}~ ; then
1800   if cmp -s $config_host_ld ${config_host_ld}~ ; then
1801     mv ${config_host_ld}~ $config_host_ld
1802   else
1803     rm ${config_host_ld}~
1804   fi
1805 fi
1806
1807 for target in $target_list; do
1808 target_dir="$target"
1809 config_mak=$target_dir/config.mak
1810 config_h=$target_dir/config.h
1811 target_arch2=`echo $target | cut -d '-' -f 1`
1812 target_bigendian="no"
1813 case "$target_arch2" in
1814   armeb|m68k|microblaze|mips|mipsn32|mips64|ppc|ppcemb|ppc64|ppc64abi32|sh4eb|sparc|sparc64|sparc32plus)
1815   target_bigendian=yes
1816   ;;
1817 esac
1818 target_softmmu="no"
1819 target_user_only="no"
1820 target_linux_user="no"
1821 target_darwin_user="no"
1822 target_bsd_user="no"
1823 case "$target" in
1824   ${target_arch2}-softmmu)
1825     target_softmmu="yes"
1826     ;;
1827   ${target_arch2}-linux-user)
1828     target_user_only="yes"
1829     target_linux_user="yes"
1830     ;;
1831   ${target_arch2}-darwin-user)
1832     target_user_only="yes"
1833     target_darwin_user="yes"
1834     ;;
1835   ${target_arch2}-bsd-user)
1836     target_user_only="yes"
1837     target_bsd_user="yes"
1838     ;;
1839   *)
1840     echo "ERROR: Target '$target' not recognised"
1841     exit 1
1842     ;;
1843 esac
1844
1845 #echo "Creating $config_mak, $config_h and $target_dir/Makefile"
1846
1847 test -f $config_h && mv $config_h ${config_h}~
1848
1849 mkdir -p $target_dir
1850 mkdir -p $target_dir/fpu
1851 mkdir -p $target_dir/tcg
1852 if test "$target" = "arm-linux-user" -o "$target" = "armeb-linux-user" -o "$target" = "arm-bsd-user" -o "$target" = "armeb-bsd-user" ; then
1853   mkdir -p $target_dir/nwfpe
1854 fi
1855
1856 #
1857 # don't use ln -sf as not all "ln -sf" over write the file/link
1858 #
1859 rm -f $target_dir/Makefile
1860 ln -s $source_path/Makefile.target $target_dir/Makefile
1861
1862
1863 echo "# Automatically generated by configure - do not modify" > $config_mak
1864
1865 echo "include ../config-host.mak" >> $config_mak
1866
1867 bflt="no"
1868 elfload32="no"
1869 target_nptl="no"
1870 interp_prefix1=`echo "$interp_prefix" | sed "s/%M/$target_arch2/g"`
1871 echo "CONFIG_QEMU_PREFIX=\"$interp_prefix1\"" >> $config_mak
1872 gdb_xml_files=""
1873
1874 TARGET_ARCH="$target_arch2"
1875 TARGET_BASE_ARCH=""
1876 TARGET_ABI_DIR=""
1877
1878 case "$target_arch2" in
1879   i386)
1880     target_phys_bits=32
1881   ;;
1882   x86_64)
1883     TARGET_BASE_ARCH=i386
1884     target_phys_bits=64
1885   ;;
1886   alpha)
1887     target_phys_bits=64
1888   ;;
1889   arm|armeb)
1890     TARGET_ARCH=arm
1891     bflt="yes"
1892     target_nptl="yes"
1893     gdb_xml_files="arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"
1894     target_phys_bits=32
1895   ;;
1896   cris)
1897     target_nptl="yes"
1898     target_phys_bits=32
1899   ;;
1900   m68k)
1901     bflt="yes"
1902     gdb_xml_files="cf-core.xml cf-fp.xml"
1903     target_phys_bits=32
1904   ;;
1905   microblaze)
1906     bflt="yes"
1907     target_nptl="yes"
1908     target_phys_bits=32
1909   ;;
1910   mips|mipsel)
1911     TARGET_ARCH=mips
1912     echo "TARGET_ABI_MIPSO32=y" >> $config_mak
1913     target_nptl="yes"
1914     target_phys_bits=64
1915   ;;
1916   mipsn32|mipsn32el)
1917     TARGET_ARCH=mipsn32
1918     TARGET_BASE_ARCH=mips
1919     echo "TARGET_ABI_MIPSN32=y" >> $config_mak
1920     target_phys_bits=64
1921   ;;
1922   mips64|mips64el)
1923     TARGET_ARCH=mips64
1924     TARGET_BASE_ARCH=mips
1925     echo "TARGET_ABI_MIPSN64=y" >> $config_mak
1926     target_phys_bits=64
1927   ;;
1928   ppc)
1929     gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
1930     target_phys_bits=32
1931     target_nptl="yes"
1932   ;;
1933   ppcemb)
1934     TARGET_BASE_ARCH=ppc
1935     TARGET_ABI_DIR=ppc
1936     gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
1937     target_phys_bits=64
1938     target_nptl="yes"
1939   ;;
1940   ppc64)
1941     TARGET_BASE_ARCH=ppc
1942     TARGET_ABI_DIR=ppc
1943     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
1944     target_phys_bits=64
1945   ;;
1946   ppc64abi32)
1947     TARGET_ARCH=ppc64
1948     TARGET_BASE_ARCH=ppc
1949     TARGET_ABI_DIR=ppc
1950     echo "TARGET_ABI32=y" >> $config_mak
1951     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
1952     target_phys_bits=64
1953   ;;
1954   sh4|sh4eb)
1955     TARGET_ARCH=sh4
1956     bflt="yes"
1957     target_nptl="yes"
1958     target_phys_bits=32
1959   ;;
1960   sparc)
1961     target_phys_bits=64
1962   ;;
1963   sparc64)
1964     TARGET_BASE_ARCH=sparc
1965     elfload32="yes"
1966     target_phys_bits=64
1967   ;;
1968   sparc32plus)
1969     TARGET_ARCH=sparc64
1970     TARGET_BASE_ARCH=sparc
1971     TARGET_ABI_DIR=sparc
1972     echo "TARGET_ABI32=y" >> $config_mak
1973     target_phys_bits=64
1974   ;;
1975   *)
1976     echo "Unsupported target CPU"
1977     exit 1
1978   ;;
1979 esac
1980 echo "TARGET_ARCH=$TARGET_ARCH" >> $config_mak
1981 target_arch_name="`echo $TARGET_ARCH | tr '[:lower:]' '[:upper:]'`"
1982 echo "TARGET_$target_arch_name=y" >> $config_mak
1983 echo "TARGET_ARCH2=$target_arch2" >> $config_mak
1984 # TARGET_BASE_ARCH needs to be defined after TARGET_ARCH
1985 if [ "$TARGET_BASE_ARCH" = "" ]; then
1986   TARGET_BASE_ARCH=$TARGET_ARCH
1987 fi
1988 echo "TARGET_BASE_ARCH=$TARGET_BASE_ARCH" >> $config_mak
1989 if [ "$TARGET_ABI_DIR" = "" ]; then
1990   TARGET_ABI_DIR=$TARGET_ARCH
1991 fi
1992 echo "TARGET_ABI_DIR=$TARGET_ABI_DIR" >> $config_mak
1993 if [ $target_phys_bits -lt $hostlongbits ] ; then
1994   target_phys_bits=$hostlongbits
1995 fi
1996 case "$target_arch2" in
1997   i386|x86_64)
1998     if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
1999       echo "CONFIG_XEN=y" >> $config_mak
2000     fi
2001 esac
2002 case "$target_arch2" in
2003   i386|x86_64|ppcemb|ppc|ppc64)
2004     # Make sure the target and host cpus are compatible
2005     if test "$kvm" = "yes" -a "$target_softmmu" = "yes" -a \
2006       \( "$target_arch2" = "$cpu" -o \
2007       \( "$target_arch2" = "ppcemb" -a "$cpu" = "ppc" \) -o \
2008       \( "$target_arch2" = "ppc64"  -a "$cpu" = "ppc" \) -o \
2009       \( "$target_arch2" = "x86_64" -a "$cpu" = "i386"   \) -o \
2010       \( "$target_arch2" = "i386"   -a "$cpu" = "x86_64" \) \) ; then
2011       echo "CONFIG_KVM=y" >> $config_mak
2012       echo "KVM_CFLAGS=$kvm_cflags" >> $config_mak
2013     fi
2014 esac
2015 echo "HWLIB=../libhw$target_phys_bits/libqemuhw$target_phys_bits.a" >> $config_mak
2016 echo "TARGET_PHYS_ADDR_BITS=$target_phys_bits" >> $config_mak
2017 echo "subdir-$target: subdir-libhw$target_phys_bits" >> $config_host_mak
2018 if test "$target_bigendian" = "yes" ; then
2019   echo "TARGET_WORDS_BIGENDIAN=y" >> $config_mak
2020 fi
2021 if test "$target_softmmu" = "yes" ; then
2022   echo "CONFIG_SOFTMMU=y" >> $config_mak
2023   echo "LIBS+=$libs_softmmu" >> $config_mak
2024 fi
2025 if test "$target_user_only" = "yes" ; then
2026   echo "CONFIG_USER_ONLY=y" >> $config_mak
2027 fi
2028 if test "$target_linux_user" = "yes" ; then
2029   echo "CONFIG_LINUX_USER=y" >> $config_mak
2030 fi
2031 if test "$target_darwin_user" = "yes" ; then
2032   echo "CONFIG_DARWIN_USER=y" >> $config_mak
2033 fi
2034 list=""
2035 if test ! -z "$gdb_xml_files" ; then
2036   for x in $gdb_xml_files; do
2037     list="$list $source_path/gdb-xml/$x"
2038   done
2039 fi
2040 echo "TARGET_XML_FILES=$list" >> $config_mak
2041
2042 case "$target_arch2" in
2043   arm|armeb|m68k|microblaze|mips|mipsel|mipsn32|mipsn32el|mips64|mips64el|ppc|ppc64|ppc64abi32|ppcemb|sparc|sparc64|sparc32plus)
2044     echo "CONFIG_SOFTFLOAT=y" >> $config_mak
2045     ;;
2046   *)
2047     echo "CONFIG_NOSOFTFLOAT=y" >> $config_mak
2048     ;;
2049 esac
2050
2051 if test "$target_user_only" = "yes" -a "$bflt" = "yes"; then
2052   echo "TARGET_HAS_BFLT=y" >> $config_mak
2053 fi
2054 if test "$target_user_only" = "yes" \
2055         -a "$nptl" = "yes" -a "$target_nptl" = "yes"; then
2056   echo "CONFIG_USE_NPTL=y" >> $config_mak
2057 fi
2058 # 32 bit ELF loader in addition to native 64 bit loader?
2059 if test "$target_user_only" = "yes" -a "$elfload32" = "yes"; then
2060   echo "TARGET_HAS_ELFLOAD32=y" >> $config_mak
2061 fi
2062 if test "$target_user_only" = "yes" -a "$guest_base" = "yes"; then
2063   echo "CONFIG_USE_GUEST_BASE=y" >> $config_mak
2064 fi
2065 if test "$target_bsd_user" = "yes" ; then
2066   echo "CONFIG_BSD_USER=y" >> $config_mak
2067 fi
2068
2069 # generate QEMU_CFLAGS/LDFLAGS for targets
2070
2071 cflags=""
2072 ldflags=""
2073
2074 if test "$ARCH" = "sparc64" ; then
2075   cflags="-I\$(SRC_PATH)/tcg/sparc $cflags"
2076 else
2077   cflags="-I\$(SRC_PATH)/tcg/\$(ARCH) $cflags"
2078 fi
2079 cflags="-I\$(SRC_PATH)/tcg $cflags"
2080 cflags="-I\$(SRC_PATH)/fpu $cflags"
2081
2082 for i in $ARCH $TARGET_BASE_ARCH ; do
2083   case "$i" in
2084   alpha)
2085     echo "CONFIG_ALPHA_DIS=y"  >> $config_mak
2086   ;;
2087   arm)
2088     echo "CONFIG_ARM_DIS=y"  >> $config_mak
2089   ;;
2090   cris)
2091     echo "CONFIG_CRIS_DIS=y"  >> $config_mak
2092   ;;
2093   hppa)
2094     echo "CONFIG_HPPA_DIS=y"  >> $config_mak
2095   ;;
2096   i386|x86_64)
2097     echo "CONFIG_I386_DIS=y"  >> $config_mak
2098   ;;
2099   m68k)
2100     echo "CONFIG_M68K_DIS=y"  >> $config_mak
2101   ;;
2102   microblaze)
2103     echo "CONFIG_MICROBLAZE_DIS=y"  >> $config_mak
2104   ;;
2105   mips*)
2106     echo "CONFIG_MIPS_DIS=y"  >> $config_mak
2107   ;;
2108   ppc*)
2109     echo "CONFIG_PPC_DIS=y"  >> $config_mak
2110   ;;
2111   s390)
2112     echo "CONFIG_S390_DIS=y"  >> $config_mak
2113   ;;
2114   sh4)
2115     echo "CONFIG_SH4_DIS=y"  >> $config_mak
2116   ;;
2117   sparc*)
2118     echo "CONFIG_SPARC_DIS=y"  >> $config_mak
2119   ;;
2120   esac
2121 done
2122
2123 case "$ARCH" in
2124 alpha)
2125   # Ensure there's only a single GP
2126   cflags="-msmall-data $cflags"
2127 ;;
2128 ia64)
2129   cflags="-mno-sdata $cflags"
2130 ;;
2131 esac
2132
2133 if test "$target_softmmu" = "yes" ; then
2134   case "$TARGET_BASE_ARCH" in
2135   arm)
2136     cflags="-DHAS_AUDIO $cflags"
2137   ;;
2138   i386|mips|ppc)
2139     cflags="-DHAS_AUDIO -DHAS_AUDIO_CHOICE $cflags"
2140   ;;
2141   esac
2142 fi
2143
2144 if test "$target_softmmu" = "yes" -a \( \
2145         "$TARGET_ARCH" = "microblaze" -o \
2146         "$TARGET_ARCH" = "cris" \) ; then
2147   echo "CONFIG_NEED_MMU=y" >> $config_mak
2148 fi
2149
2150 if test "$gprof" = "yes" ; then
2151   echo "TARGET_GPROF=yes" >> $config_mak
2152   if test "$target_linux_user" = "yes" ; then
2153     cflags="-p $cflags"
2154     ldflags="-p $ldflags"
2155   fi
2156   if test "$target_softmmu" = "yes" ; then
2157     ldflags="-p $ldflags"
2158     echo "GPROF_CFLAGS=-p" >> $config_mak
2159   fi
2160 fi
2161
2162 linker_script="-Wl,-T../config-host.ld -Wl,-T,\$(SRC_PATH)/\$(ARCH).ld"
2163 if test "$target_linux_user" = "yes" -o "$target_bsd_user" = "yes" ; then
2164   case "$ARCH" in
2165   i386)
2166     if test "$gprof" = "yes" -o "$static" = "yes" ; then
2167       ldflags="$linker_script $ldflags"
2168     else
2169       # WARNING: this LDFLAGS is _very_ tricky : qemu is an ELF shared object
2170       # that the kernel ELF loader considers as an executable. I think this
2171       # is the simplest way to make it self virtualizable!
2172       ldflags="-Wl,-shared $ldflags"
2173     fi
2174     ;;
2175   sparc)
2176     # -static is used to avoid g1/g3 usage by the dynamic linker
2177     ldflags="$linker_script -static $ldflags"
2178     ;;
2179   ia64)
2180     ldflags="-Wl,-G0 $linker_script -static $ldflags"
2181     ;;
2182   x86_64|ppc|ppc64|s390|sparc64|alpha|arm|m68k|mips|mips64)
2183     ldflags="$linker_script $ldflags"
2184     ;;
2185   esac
2186 fi
2187 if test "$target_softmmu" = "yes" ; then
2188   case "$ARCH" in
2189   ia64)
2190     ldflags="-Wl,-G0 $linker_script -static $ldflags"
2191     ;;
2192   esac
2193 fi
2194
2195 echo "LDFLAGS+=$ldflags" >> $config_mak
2196 echo "QEMU_CFLAGS+=$cflags" >> $config_mak
2197
2198 echo "/* Automatically generated by configure - do not modify */" > $config_h
2199 echo "#include \"../config-host.h\"" >> $config_h
2200
2201 /bin/sh $source_path/create_config < $config_mak >> $config_h
2202
2203 if test -f ${config_h}~ ; then
2204   if cmp -s $config_h ${config_h}~ ; then
2205     mv ${config_h}~ $config_h
2206   else
2207     rm ${config_h}~
2208   fi
2209 fi
2210
2211 done # for target in $targets
2212
2213 # build tree in object directory if source path is different from current one
2214 if test "$source_path_used" = "yes" ; then
2215     DIRS="tests tests/cris slirp audio block pc-bios/optionrom"
2216     FILES="Makefile tests/Makefile"
2217     FILES="$FILES tests/cris/Makefile tests/cris/.gdbinit"
2218     FILES="$FILES tests/test-mmap.c"
2219     FILES="$FILES pc-bios/optionrom/Makefile pc-bios/keymaps pc-bios/video.x"
2220     for bios_file in $source_path/pc-bios/*.bin $source_path/pc-bios/*.dtb $source_path/pc-bios/openbios-*; do
2221         FILES="$FILES pc-bios/`basename $bios_file`"
2222     done
2223     for dir in $DIRS ; do
2224             mkdir -p $dir
2225     done
2226     # remove the link and recreate it, as not all "ln -sf" overwrite the link
2227     for f in $FILES ; do
2228         rm -f $f
2229         ln -s $source_path/$f $f
2230     done
2231 fi
2232
2233 for hwlib in 32 64; do
2234   d=libhw$hwlib
2235   mkdir -p $d
2236   rm -f $d/Makefile
2237   ln -s $source_path/Makefile.hw $d/Makefile
2238   echo "HWLIB=libqemuhw$hwlib.a" > $d/config.mak
2239   echo "QEMU_CFLAGS+=-DTARGET_PHYS_ADDR_BITS=$hwlib" >> $d/config.mak
2240 done