ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/configure.ac
Revision: 1.1
Committed: 2004-06-30T08:45:14Z (20 years, 4 months ago) by gbeauche
Branch: MAIN
Log Message:
Use autoconf 2.5 so that we could get m4sugar macros (AS_VAR_PUSHDEF et al.)
and more importantly correct macros for AC_SYS_LARGEFILE support.

BTW, also fix test for <linux/if.h>

File Contents

# User Rev Content
1 gbeauche 1.1 dnl Process this file with autoconf to produce a configure script.
2     dnl Written in 2002 by Christian Bauer
3    
4     AC_INIT([SheepShaver], 2.2, [Christian.Bauer@uni-mainz.de], SheepShaver)
5     AC_CONFIG_SRCDIR(main_unix.cpp)
6     AC_PREREQ(2.52)
7     AC_CONFIG_HEADER(config.h)
8    
9     dnl Canonical system information.
10     AC_CANONICAL_HOST
11     AC_CANONICAL_TARGET
12    
13     dnl Options.
14     AC_ARG_ENABLE(jit, [ --enable-jit enable JIT compiler [default=yes]], [WANT_JIT=$enableval], [WANT_JIT=yes])
15     AC_ARG_ENABLE(ppc-emulator, [ --enable-ppc-emulator use the selected PowerPC emulator [default=auto]], [WANT_EMULATED_PPC=$enableval], [WANT_EMULATED_PPC=auto])
16     AC_ARG_ENABLE(xf86-dga, [ --enable-xf86-dga use the XFree86 DGA extension [default=yes]], [WANT_XF86_DGA=$enableval], [WANT_XF86_DGA=yes])
17     AC_ARG_ENABLE(xf86-vidmode, [ --enable-xf86-vidmode use the XFree86 VidMode extension [default=no]], [WANT_XF86_VIDMODE=$enableval], [WANT_XF86_VIDMODE=no])
18     AC_ARG_ENABLE(vosf, [ --enable-vosf enable video on SEGV signals [default=yes]], [WANT_VOSF=$enableval], [WANT_VOSF=yes])
19     AC_ARG_WITH(esd, [ --with-esd support ESD for sound under Linux/FreeBSD [default=yes]], [WANT_ESD=$withval], [WANT_ESD=yes])
20     AC_ARG_WITH(gtk, [ --with-gtk use GTK user interface [default=yes]], [WANT_GTK=$withval], [WANT_GTK=yes])
21     AC_ARG_WITH(mon, [ --with-mon use mon as debugger [default=yes]], [WANT_MON=$withval], [WANT_MON=yes])
22     AC_ARG_WITH(dgcc, [ --with-dgcc=COMPILER use C++ COMPILER to compile synthetic opcodes], [DYNGEN_CC=$withval])
23    
24     dnl SDL options.
25     AC_ARG_ENABLE(sdl-static, [ --enable-sdl-static use SDL static libraries for linking [default=no]], [WANT_SDL_STATIC=$enableval], [WANT_SDL_STATIC=no])
26     AC_ARG_ENABLE(sdl-video, [ --enable-sdl-video use SDL for video graphics [default=no]], [WANT_SDL_VIDEO=$enableval], [WANT_SDL_VIDEO=no])
27    
28     dnl Checks for programs.
29     AC_PROG_CC
30     AC_PROG_CPP
31     AC_PROG_CXX
32     AC_PROG_MAKE_SET
33     AC_PROG_INSTALL
34    
35     dnl Check for PowerPC target CPU.
36     HAVE_PPC=no
37     AC_MSG_CHECKING(for PowerPC target CPU)
38     AC_EGREP_CPP(yes,
39     [
40     #ifdef __powerpc__
41     yes
42     #endif
43     #ifdef __ppc__
44     yes
45     #endif
46     ], [AC_MSG_RESULT(yes); HAVE_PPC=yes], AC_MSG_RESULT(no))
47    
48     dnl We use native CPU if possible.
49     EMULATED_PPC=yes
50     case $WANT_EMULATED_PPC in
51     auto) [[ "x$HAVE_PPC" = "xyes" ]] && EMULATED_PPC=no;;
52     no) EMULATED_PPC=no;;
53     esac
54     if [[ "x$EMULATED_PPC" = "xyes" ]]; then
55     AC_DEFINE(EMULATED_PPC, 1, [Define if using a PowerPC CPU emulator.])
56     fi
57    
58     dnl We use mon if possible.
59     MONSRCS=
60     case "x$WANT_MON" in
61     x/* | x.*)
62     mon_srcdir=$WANT_MON
63     WANT_MON=yes
64     ;;
65     xyes)
66     mon_srcdir=../../../mon/src
67     ;;
68     esac
69     if [[ "x$WANT_MON" = "xyes" ]]; then
70     AC_MSG_CHECKING(for mon)
71     if grep mon_init $mon_srcdir/mon.h >/dev/null 2>/dev/null; then
72     AC_MSG_RESULT(yes)
73     AC_DEFINE(ENABLE_MON, 1, [Define if using "mon".])
74     MONSRCS="$mon_srcdir/mon.cpp $mon_srcdir/mon_6502.cpp $mon_srcdir/mon_z80.cpp $mon_srcdir/mon_cmd.cpp $mon_srcdir/mon_lowmem.cpp $mon_srcdir/mon_disass.cpp $mon_srcdir/mon_ppc.cpp $mon_srcdir/disass/floatformat.c $mon_srcdir/disass/i386-dis.c $mon_srcdir/disass/m68k-dis.c $mon_srcdir/disass/m68k-opc.c"
75     CXXFLAGS="$CXXFLAGS -I$mon_srcdir -I$mon_srcdir/disass"
76     AC_CHECK_LIB(ncurses, tgetent, ,
77     AC_CHECK_LIB(termcap, tgetent, ,
78     AC_CHECK_LIB(termlib, tgetent, ,
79     AC_CHECK_LIB(terminfo, tgetent, ,
80     AC_CHECK_LIB(Hcurses, tgetent, ,
81     AC_CHECK_LIB(curses, tgetent))))))
82     AC_CHECK_LIB(readline, readline)
83     AC_CHECK_HEADERS(readline.h history.h readline/readline.h readline/history.h)
84     else
85     AC_MSG_RESULT(no)
86     AC_MSG_WARN([Could not find mon, ignoring --with-mon.])
87     WANT_MON=no
88     fi
89     fi
90    
91     dnl Checks for libraries.
92     AC_CHECK_LIB(posix4, sem_init)
93    
94     dnl Do we need SDL?
95     WANT_SDL=no
96     SDL_SUPPORT="none"
97     if [[ "x$WANT_SDL_VIDEO" = "xyes" ]]; then
98     WANT_SDL=yes
99     WANT_XF86_DGA=no
100     WANT_XF86_VIDMODE=no
101     WANT_FBDEV_DGA=no
102     SDL_SUPPORT="video"
103     fi
104     if [[ "x$WANT_SDL" = "xyes" ]]; then
105     AC_PATH_PROG(sdl_config, "sdl-config")
106     if [[ -n "$sdl_config" ]]; then
107     sdl_cflags=`$sdl_config --cflags`
108     if [[ "x$WANT_SDL_STATIC" = "xyes" ]]; then
109     sdl_libs=`$sdl_config --static-libs`
110     else
111     sdl_libs=`$sdl_config --libs`
112     fi
113     CFLAGS="$CFLAGS $sdl_cflags"
114     CXXFLAGS="$CXXFLAGS $sdl_cflags"
115     LIBS="$LIBS $sdl_libs"
116     else
117     WANT_SDL=no
118     fi
119     fi
120    
121     dnl We need X11, if not using SDL.
122     if [[ "x$WANT_SDL" = "xno" ]]; then
123     AC_PATH_XTRA
124     if [[ "x$no_x" = "xyes" ]]; then
125     AC_MSG_ERROR([You need X11 to run SheepShaver.])
126     fi
127     CFLAGS="$CFLAGS $X_CFLAGS"
128     CXXFLAGS="$CXXFLAGS $X_CFLAGS"
129     LIBS="$LIBS $X_PRE_LIBS $X_LIBS -lX11 -lXext $X_EXTRA_LIBS"
130     fi
131    
132     dnl We need pthreads on non-PowerPC systems. Try libpthread first, then libc_r (FreeBSD), then PTL.
133     HAVE_PTHREADS=yes
134     case $EMULATED_PPC:$target_os in
135     no:linux*)
136     dnl We do have our own pthread_cancel() implementation
137     AC_DEFINE(HAVE_PTHREAD_CANCEL, 1, [Define if you have the pthread_cancel function.])
138     ;;
139     *:*)
140     AC_CHECK_LIB(pthread, pthread_create, , [
141     AC_CHECK_LIB(c_r, pthread_create, , [
142     AC_CHECK_LIB(PTL, pthread_create, , [
143     AC_MSG_ERROR([You need pthreads to run Basilisk II.])
144     ])
145     ])
146     ])
147     AC_CHECK_FUNCS(pthread_cancel)
148     AC_CHECK_FUNCS(pthread_mutexattr_setprotocol)
149     AC_CHECK_FUNCS(pthread_mutexattr_settype)
150     AC_CHECK_FUNCS(pthread_mutexattr_setpshared)
151     if [[ "x$HAVE_PTHREADS" = "xyes" ]]; then
152     AC_DEFINE(HAVE_PTHREADS, 1, [Define if pthreads are available.])
153     fi
154     dnl If POSIX.4 semaphores are not available, we emulate them with pthread mutexes.
155     SEMSRC=
156     AC_CHECK_FUNCS(sem_init, , [
157     if test "x$HAVE_PTHREADS" = "xyes"; then
158     SEMSRC=posix_sem.cpp
159     fi
160     ])
161     ;;
162     esac
163    
164     dnl We use XFree86 DGA if possible.
165     if [[ "x$WANT_XF86_DGA" = "xyes" ]]; then
166     AC_CHECK_LIB(Xxf86dga, XF86DGAQueryExtension, [
167     AC_DEFINE(ENABLE_XF86_DGA, 1, [Define if using XFree86 DGA extension.])
168     LIBS="$LIBS -lXxf86dga"
169     ], [
170     AC_MSG_WARN([Could not find XFree86 DGA extension, ignoring --enable-xf86-dga.])
171     WANT_XF86_DGA=no
172     ])
173     fi
174    
175     dnl We use XFree86 VidMode if possible.
176     if [[ "x$WANT_XF86_VIDMODE" = "xyes" ]]; then
177     AC_CHECK_LIB(Xxf86vm, XF86VidModeQueryExtension, [
178     AC_DEFINE(ENABLE_XF86_VIDMODE, 1, [Define if using XFree86 DGA extension.])
179     LIBS="$LIBS -lXxf86vm"
180     ], [
181     AC_MSG_WARN([Could not find XFree86 VidMode extension, ignoring --enable-xf86-vidmode.])
182     WANT_XF86_VIDMODE=no
183     ])
184     fi
185    
186     dnl We use GTK+ if possible.
187     UISRCS=../dummy/prefs_editor_dummy.cpp
188     if [[ "x$WANT_GTK" = "xyes" ]]; then
189     AM_PATH_GTK(1.2.0, [
190     AC_DEFINE(ENABLE_GTK, 1, [Define if using GTK.])
191     CFLAGS="$CFLAGS $GTK_CFLAGS"
192     CXXFLAGS="$CXXFLAGS $GTK_CFLAGS"
193     LIBS="$LIBS $GTK_LIBS"
194     UISRCS=prefs_editor_gtk.cpp
195     ], [
196     AC_MSG_WARN([Could not find GTK+, disabling user interface.])
197     WANT_GTK=no
198     ])
199     fi
200    
201     dnl We use ESD if possible.
202     if [[ "x$WANT_ESD" = "xyes" ]]; then
203     AM_PATH_ESD(0.2.8, [
204     AC_DEFINE(ENABLE_ESD, 1, [Define is using ESD.])
205     CFLAGS="$CFLAGS $ESD_CFLAGS"
206     CXXFLAGS="$CXXFLAGS $ESD_CFLAGS"
207     LIBS="$LIBS $ESD_LIBS"
208     ], [
209     AC_MSG_WARN([Could not find ESD, disabling ESD support.])
210     WANT_ESD=no
211     ])
212     fi
213    
214     dnl Checks for header files.
215     AC_HEADER_STDC
216     AC_HEADER_SYS_WAIT
217     AC_CHECK_HEADERS(mach/vm_map.h mach/mach_init.h sys/mman.h)
218     AC_CHECK_HEADERS(sys/time.h sys/times.h sys/socket.h)
219     AC_CHECK_HEADERS(unistd.h fcntl.h byteswap.h)
220     AC_CHECK_HEADERS(linux/if.h, [], [], [
221     #if HAVE_SYS_SOCKET_H
222     # include <sys/socket.h>
223     #endif
224     ])
225     AC_CHECK_HEADERS(linux/if_tun.h net/if.h net/if_tun.h)
226    
227     dnl Checks for typedefs, structures, and compiler characteristics.
228     AC_C_BIGENDIAN
229     AC_C_CONST
230     AC_C_INLINE
231     AC_CHECK_SIZEOF(short, 2)
232     AC_CHECK_SIZEOF(int, 4)
233     AC_CHECK_SIZEOF(long, 4)
234     AC_CHECK_SIZEOF(long long, 8)
235     AC_CHECK_SIZEOF(float, 4)
236     AC_CHECK_SIZEOF(double, 8)
237     AC_CHECK_SIZEOF(void *, 4)
238     AC_TYPE_OFF_T
239     AC_CHECK_TYPE(loff_t, off_t)
240     AC_TYPE_SIZE_T
241     AC_TYPE_SIGNAL
242     AC_HEADER_TIME
243     AC_STRUCT_TM
244    
245     dnl Check whether struct sigaction has sa_restorer member.
246     AC_CACHE_CHECK([whether struct sigaction has sa_restorer],
247     ac_cv_signal_sa_restorer, [
248     AC_TRY_COMPILE([
249     #include <signal.h>
250     ], [struct sigaction sa; sa.sa_restorer = 0;],
251     ac_cv_signal_sa_restorer=yes, ac_cv_signal_sa_restorer=no,
252     dnl When cross-compiling, do not assume anything.
253     ac_cv_signal_sa_restorer=no
254     )
255     ])
256     if [[ "x$ac_cv_signal_sa_restorer" = "xyes" ]]; then
257     AC_DEFINE(HAVE_SIGNAL_SA_RESTORER, 1, [Define if sa_restorer is available in struct sigaction.])
258     fi
259    
260     dnl Checks for library functions.
261     AC_CHECK_FUNCS(strdup strlcpy cfmakeraw)
262     AC_CHECK_FUNCS(nanosleep)
263     AC_CHECK_FUNCS(sigaction signal)
264     AC_CHECK_FUNCS(mmap mprotect munmap)
265     AC_CHECK_FUNCS(vm_allocate vm_deallocate vm_protect)
266     AC_CHECK_FUNCS(posix_memalign memalign valloc)
267    
268     dnl Darwin seems to define mach_task_self() instead of task_self().
269     AC_CHECK_FUNCS(mach_task_self task_self)
270    
271     dnl We need clock_gettime() for better performance but it may drag
272     dnl libpthread in, which we don't want for native ppc mode
273     case $EMULATED_PPC:$target_os in
274     no:linux*)
275     ;;
276     *:*)
277     AC_SEARCH_LIBS(clock_gettime, [rt posix4])
278     AC_CHECK_FUNCS(clock_gettime)
279     ;;
280     esac
281    
282     dnl AC_CHECK_FRAMEWORK($1=NAME, $2=INCLUDES)
283     AC_DEFUN(AC_CHECK_FRAMEWORK, [
284     AS_VAR_PUSHDEF([ac_Framework], [ac_cv_framework_$1])dnl
285     AC_CACHE_CHECK([whether compiler supports framework $1],
286     ac_Framework, [
287     saved_LIBS="$LIBS"
288     LIBS="$LIBS -framework $1"
289     AC_TRY_LINK(
290     [$2], [int main(void) { return 0; }],
291     [AS_VAR_SET(ac_Framework, yes)], [AS_VAR_SET(ac_Framework, no); LIBS="$saved_LIBS"]
292     )
293     ])
294     AS_IF([test AS_VAR_GET(ac_Framework) = yes],
295     [AC_DEFINE(AS_TR_CPP(HAVE_FRAMEWORK_$1), 1, [Define if framework $1 is available.])]
296     )
297     AS_VAR_POPDEF([ac_Framework])dnl
298     ])
299    
300     dnl Check for some MacOS X frameworks
301     AC_CHECK_FRAMEWORK(Carbon, [#include <Carbon/Carbon.h>])
302     AC_CHECK_FRAMEWORK(IOKit, [#include <IOKit/IOKitLib.h>])
303    
304     dnl Select system-dependant sources.
305     SERIALSRC=serial_unix.cpp
306     ETHERSRC=../dummy/ether_dummy.cpp
307     SCSISRC=../dummy/scsi_dummy.cpp
308     AUDIOSRC=../dummy/audio_dummy.cpp
309     EXTRASYSSRCS=
310     case "$target_os" in
311     linux*)
312     ETHERSRC=Linux/ether_linux.cpp
313     AUDIOSRC=audio_oss_esd.cpp
314     SCSISRC=Linux/scsi_linux.cpp
315     if [[ "x$EMULATED_PPC" = "xno" ]]; then
316     EXTRASYSSRCS="Linux/paranoia.cpp Linux/sheepthreads.c Linux/asm_linux.S"
317     fi
318     ;;
319     darwin*)
320     if [[ "x$EMULATED_PPC" = "xno" ]]; then
321     EXTRASYSSRCS="Darwin/paranoia.cpp Linux/asm_linux.S"
322     fi
323     if [[ "x$ac_cv_framework_IOKit" = "xyes" ]]; then
324     EXTRASYSSRCS="$EXTRASYSSRCS ../MacOSX/sys_darwin.cpp"
325     fi
326     ;;
327     esac
328    
329     dnl SDL overrides
330     if [[ "x$WANT_SDL" = "xyes" ]]; then
331     AC_DEFINE(USE_SDL, 1, [Define to enble SDL support.])
332     fi
333     if [[ "x$WANT_SDL_VIDEO" = "xyes" ]]; then
334     VIDEOSRCS="../SDL/video_sdl.cpp"
335     AC_DEFINE(USE_SDL_VIDEO, 1, [Define to enable SDL video graphics support.])
336     KEYCODES="../SDL/keycodes"
337     if [[ "x$ac_cv_framework_Carbon" = "xyes" ]]; then
338     EXTRASYSSRCS="$EXTRASYSSRCS ../MacOSX/clip_macosx.cpp"
339     else
340     EXTRASYSSRCS="$EXTRASYSSRCS ../dummy/clip_dummy.cpp"
341     fi
342     else
343     VIDEOSRCS="video_x.cpp"
344     KEYCODES="keycodes"
345     EXTRASYSSRCS="$EXTRASYSSRCS clip_unix.cpp"
346     fi
347    
348     SYSSRCS="$VIDEOSRCS $SERIALSRC $ETHERSRC $SCSISRC $AUDIOSRC $SEMSRC $UISRCS $MONSRCS $EXTRASYSSRCS"
349    
350     dnl Define a macro that translates a yesno-variable into a C macro definition
351     dnl to be put into the config.h file
352     dnl $1 -- the macro to define
353     dnl $2 -- the value to translate
354     dnl $3 -- template name
355     AC_DEFUN(AC_TRANSLATE_DEFINE, [
356     if [[ "x$2" = "xyes" -o "x$2" = "xguessing yes" ]]; then
357     AC_DEFINE($1, 1, $3)
358     fi
359     ])
360    
361     dnl Check that the host supports TUN/TAP devices
362     AC_CACHE_CHECK([whether TUN/TAP is supported],
363     ac_cv_tun_tap_support, [
364     AC_TRY_COMPILE([
365     #if defined(HAVE_LINUX_IF_H) && defined(HAVE_LINUX_IF_TUN_H)
366     #include <linux/if.h>
367     #include <linux/if_tun.h>
368     #endif
369     #if defined(HAVE_NET_IF_H) && defined(HAVE_NET_IF_TUN_H)
370     #include <net/if.h>
371     #include <net/if_tun.h>
372     #endif
373     ], [
374     struct ifreq ifr;
375     memset(&ifr, 0, sizeof(ifr));
376     ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
377     ],
378     ac_cv_tun_tap_support=yes, ac_cv_tun_tap_support=no
379     )
380     ])
381     AC_TRANSLATE_DEFINE(ENABLE_TUNTAP, "$ac_cv_tun_tap_support",
382     [Define if your system supports TUN/TAP devices.])
383    
384     dnl Various checks if the system supports vm_allocate() and the like functions.
385     have_mach_vm=no
386     if [[ "x$ac_cv_func_vm_allocate" = "xyes" -a "x$ac_cv_func_vm_deallocate" = "xyes" -a \
387     "x$ac_cv_func_vm_protect" = "xyes" ]]; then
388     have_mach_vm=yes
389     fi
390     AC_TRANSLATE_DEFINE(HAVE_MACH_VM, "$have_mach_vm",
391     [Define if your system has a working vm_allocate()-based memory allocator.])
392    
393     dnl Check that vm_allocate(), vm_protect() work
394     if [[ "x$have_mach_vm" = "xyes" ]]; then
395    
396     AC_CACHE_CHECK([whether vm_protect works],
397     ac_cv_vm_protect_works, [
398     AC_LANG_SAVE
399     AC_LANG_CPLUSPLUS
400     ac_cv_vm_protect_works=yes
401     dnl First the tests that should segfault
402     for test_def in NONE_READ NONE_WRITE READ_WRITE; do
403     AC_TRY_RUN([
404     #define CONFIGURE_TEST_VM_MAP
405     #define TEST_VM_PROT_$test_def
406     #include "vm_alloc.cpp"
407     ], ac_cv_vm_protect_works=no, rm -f core,
408     dnl When cross-compiling, do not assume anything
409     ac_cv_vm_protect_works="guessing no"
410     )
411     done
412     AC_TRY_RUN([
413     #define CONFIGURE_TEST_VM_MAP
414     #define TEST_VM_PROT_RDWR_WRITE
415     #include "vm_alloc.cpp"
416     ], , ac_cv_vm_protect_works=no,
417     dnl When cross-compiling, do not assume anything
418     ac_cv_vm_protect_works="guessing no"
419     )
420     AC_LANG_RESTORE
421     ]
422     )
423    
424     dnl Remove support for vm_allocate() if vm_protect() does not work
425     if [[ "x$have_mach_vm" = "xyes" ]]; then
426     case $ac_cv_vm_protect_works in
427     *yes) have_mach_vm=yes;;
428     *no) have_mach_vm=no;;
429     esac
430     fi
431     AC_TRANSLATE_DEFINE(HAVE_MACH_VM, "$have_mach_vm",
432     [Define if your system has a working vm_allocate()-based memory allocator.])
433    
434     fi dnl HAVE_MACH_VM
435    
436     dnl Various checks if the system supports mmap() and the like functions.
437     dnl ... and Mach memory allocators are not supported
438     have_mmap_vm=no
439     if [[ "x$ac_cv_func_mmap" = "xyes" -a "x$ac_cv_func_munmap" = "xyes" -a \
440     "x$ac_cv_func_mprotect" = "xyes" ]]; then
441     if [[ "x$have_mach_vm" = "xno" ]]; then
442     have_mmap_vm=yes
443     fi
444     fi
445     AC_TRANSLATE_DEFINE(HAVE_MMAP_VM, "$have_mmap_vm",
446     [Define if your system has a working mmap()-based memory allocator.])
447    
448     dnl Check that mmap() and associated functions work.
449     if [[ "x$have_mmap_vm" = "xyes" ]]; then
450    
451     dnl Check if we have a working anonymous mmap()
452     AC_CACHE_CHECK([whether mmap supports MAP_ANON],
453     ac_cv_mmap_anon, [
454     AC_LANG_SAVE
455     AC_LANG_CPLUSPLUS
456     AC_TRY_RUN([
457     #define HAVE_MMAP_ANON
458     #define CONFIGURE_TEST_VM_MAP
459     #define TEST_VM_MMAP_ANON
460     #include "vm_alloc.cpp"
461     ], ac_cv_mmap_anon=yes, ac_cv_mmap_anon=no,
462     dnl When cross-compiling, do not assume anything.
463     ac_cv_mmap_anon="guessing no"
464     )
465     AC_LANG_RESTORE
466     ]
467     )
468     AC_TRANSLATE_DEFINE(HAVE_MMAP_ANON, "$ac_cv_mmap_anon",
469     [Define if <sys/mman.h> defines MAP_ANON and mmap()'ing with MAP_ANON works.])
470    
471     AC_CACHE_CHECK([whether mmap supports MAP_ANONYMOUS],
472     ac_cv_mmap_anonymous, [
473     AC_LANG_SAVE
474     AC_LANG_CPLUSPLUS
475     AC_TRY_RUN([
476     #define HAVE_MMAP_ANONYMOUS
477     #define CONFIGURE_TEST_VM_MAP
478     #define TEST_VM_MMAP_ANON
479     #include "vm_alloc.cpp"
480     ], ac_cv_mmap_anonymous=yes, ac_cv_mmap_anonymous=no,
481     dnl When cross-compiling, do not assume anything.
482     ac_cv_mmap_anonymous="guessing no"
483     )
484     AC_LANG_RESTORE
485     ]
486     )
487     AC_TRANSLATE_DEFINE(HAVE_MMAP_ANONYMOUS, "$ac_cv_mmap_anonymous",
488     [Define if <sys/mman.h> defines MAP_ANONYMOUS and mmap()'ing with MAP_ANONYMOUS works.])
489    
490     AC_CACHE_CHECK([whether mprotect works],
491     ac_cv_mprotect_works, [
492     AC_LANG_SAVE
493     AC_LANG_CPLUSPLUS
494     ac_cv_mprotect_works=yes
495     dnl First the tests that should segfault
496     for test_def in NONE_READ NONE_WRITE READ_WRITE; do
497     AC_TRY_RUN([
498     #define CONFIGURE_TEST_VM_MAP
499     #define TEST_VM_PROT_$test_def
500     #include "vm_alloc.cpp"
501     ], ac_cv_mprotect_works=no, rm -f core,
502     dnl When cross-compiling, do not assume anything
503     ac_cv_mprotect_works="guessing no"
504     )
505     done
506     AC_TRY_RUN([
507     #define CONFIGURE_TEST_VM_MAP
508     #define TEST_VM_PROT_RDWR_WRITE
509     #include "vm_alloc.cpp"
510     ], , ac_cv_mprotect_works=no,
511     dnl When cross-compiling, do not assume anything
512     ac_cv_mprotect_works="guessing no"
513     )
514     AC_LANG_RESTORE
515     ]
516     )
517    
518     dnl Remove support for mmap() if mprotect() does not work
519     if [[ "x$have_mmap_vm" = "xyes" ]]; then
520     case $ac_cv_mprotect_works in
521     *yes) have_mmap_vm=yes;;
522     *no) have_mmap_vm=no;;
523     esac
524     fi
525     AC_TRANSLATE_DEFINE(HAVE_MMAP_VM, $have_mmap_vm,
526     [Define if your system has a working mmap()-based memory allocator.])
527    
528     fi dnl HAVE_MMAP_VM
529    
530     dnl Check if we can modify the __PAGEZERO segment for use as Low Memory
531     AC_CACHE_CHECK([whether __PAGEZERO can be Low Memory area 0x0000-0x3000],
532     ac_cv_pagezero_hack, [
533     ac_cv_pagezero_hack=no
534     if AC_TRY_COMMAND([Darwin/testlmem.sh 0x3000]); then
535     ac_cv_pagezero_hack=yes
536     dnl might as well skip the test for mmap-able low memory
537     ac_cv_can_map_lm=no
538     fi
539     ])
540     AC_TRANSLATE_DEFINE(PAGEZERO_HACK, "$ac_cv_pagezero_hack",
541     [Define if the __PAGEZERO Mach-O Low Memory Globals hack works on this system.])
542    
543     dnl Check if we can mmap 0x3000 bytes from 0x0000
544     AC_CACHE_CHECK([whether we can map Low Memory area 0x0000-0x3000],
545     ac_cv_can_map_lm, [
546     AC_LANG_SAVE
547     AC_LANG_CPLUSPLUS
548     AC_TRY_RUN([
549     #include "vm_alloc.cpp"
550     int main(void) { /* returns 0 if we could map the lowmem globals */
551     volatile char * lm = 0;
552     if (vm_init() < 0) exit(1);
553     if (vm_acquire_fixed(0, 0x2000) < 0) exit(1);
554     lm[0] = 'z';
555     if (vm_release((char *)lm, 0x2000) < 0) exit(1);
556     vm_exit(); exit(0);
557     }
558     ], ac_cv_can_map_lm=yes, ac_cv_can_map_lm=no,
559     dnl When cross-compiling, do not assume anything.
560     ac_cv_can_map_lm="guessing no"
561     )
562     AC_LANG_RESTORE
563     ]
564     )
565    
566     dnl Check signal handlers need to be reinstalled
567     AC_CACHE_CHECK([whether signal handlers need to be reinstalled],
568     ac_cv_signal_need_reinstall, [
569     AC_LANG_SAVE
570     AC_LANG_CPLUSPLUS
571     AC_TRY_RUN([
572     #include <stdlib.h>
573     #ifdef HAVE_UNISTD_H
574     #include <unistd.h>
575     #endif
576     #include <signal.h>
577     static int handled_signal = 0;
578     RETSIGTYPE sigusr1_handler(int) { handled_signal++; }
579     int main(void) { /* returns 0 if signals need not to be reinstalled */
580     signal(SIGUSR1, sigusr1_handler); raise(SIGUSR1); raise(SIGUSR1);
581     exit(handled_signal == 2);
582     }
583     ], ac_cv_signal_need_reinstall=yes, ac_cv_signal_need_reinstall=no,
584     dnl When cross-compiling, do not assume anything.
585     ac_cv_signal_need_reinstall="guessing yes"
586     )
587     AC_LANG_RESTORE
588     ]
589     )
590     AC_TRANSLATE_DEFINE(SIGNAL_NEED_REINSTALL, "$ac_cv_signal_need_reinstall",
591     [Define if your system requires signals to be reinstalled.])
592    
593     dnl Check if sigaction handlers need to be reinstalled
594     AC_CACHE_CHECK([whether sigaction handlers need to be reinstalled],
595     ac_cv_sigaction_need_reinstall, [
596     AC_LANG_SAVE
597     AC_LANG_CPLUSPLUS
598     AC_TRY_RUN([
599     #include <stdlib.h>
600     #ifdef HAVE_UNISTD_H
601     #include <unistd.h>
602     #endif
603     #include <signal.h>
604     static int handled_signal = 0;
605     RETSIGTYPE sigusr1_handler(int) { handled_signal++; }
606     typedef RETSIGTYPE (*signal_handler)(int);
607     static signal_handler mysignal(int sig, signal_handler handler) {
608     struct sigaction old_sa;
609     struct sigaction new_sa;
610     new_sa.sa_handler = handler;
611     return ((sigaction(sig,&new_sa,&old_sa) < 0) ? SIG_IGN : old_sa.sa_handler);
612     }
613     int main(void) { /* returns 0 if signals need not to be reinstalled */
614     mysignal(SIGUSR1, sigusr1_handler); raise(SIGUSR1); raise(SIGUSR1);
615     exit(handled_signal == 2);
616     }
617     ], ac_cv_sigaction_need_reinstall=yes, ac_cv_sigaction_need_reinstall=no,
618     dnl When cross-compiling, do not assume anything.
619     ac_cv_sigaction_need_reinstall="guessing yes"
620     )
621     AC_LANG_RESTORE
622     ]
623     )
624     AC_TRANSLATE_DEFINE(SIGACTION_NEED_REINSTALL, "$ac_cv_sigaction_need_reinstall",
625     [Define if your system requires sigactions to be reinstalled.])
626    
627     dnl Check if Mach exceptions supported.
628     AC_CACHE_CHECK([whether your system supports Mach exceptions],
629     ac_cv_have_mach_exceptions, [
630     AC_LANG_SAVE
631     AC_LANG_CPLUSPLUS
632     AC_TRY_RUN([
633     #define HAVE_MACH_EXCEPTIONS 1
634     #define CONFIGURE_TEST_SIGSEGV_RECOVERY
635     #include "vm_alloc.cpp"
636     #include "sigsegv.cpp"
637     ],
638     ac_cv_have_mach_exceptions=yes,
639     ac_cv_have_mach_exceptions=no,
640     dnl When cross-compiling, do not assume anything.
641     ac_cv_have_mach_exceptions=no
642     )
643     AC_LANG_RESTORE
644     ]
645     )
646     if [[ "$ac_cv_have_mach_exceptions" = "yes" ]]; then
647     sigsegv_recovery=mach
648     fi
649     AC_TRANSLATE_DEFINE(HAVE_MACH_EXCEPTIONS, "$ac_cv_have_mach_exceptions",
650     [Define if your system supports Mach exceptions.])
651    
652     dnl Otherwise, check if extended signals are supported.
653     if [[ -z "$sigsegv_recovery" ]]; then
654     AC_CACHE_CHECK([whether your system supports extended signal handlers],
655     ac_cv_have_extended_signals, [
656     AC_LANG_SAVE
657     AC_LANG_CPLUSPLUS
658     AC_TRY_RUN([
659     #define HAVE_SIGINFO_T 1
660     #define CONFIGURE_TEST_SIGSEGV_RECOVERY
661     #include "vm_alloc.cpp"
662     #include "sigsegv.cpp"
663     ],
664     ac_cv_have_extended_signals=yes,
665     ac_cv_have_extended_signals=no,
666     dnl When cross-compiling, do not assume anything.
667     ac_cv_have_extended_signals=no
668     )
669     AC_LANG_RESTORE
670     ]
671     )
672     if [[ "$ac_cv_have_extended_signals" = "yes" ]]; then
673     sigsegv_recovery=siginfo
674     fi
675     AC_TRANSLATE_DEFINE(HAVE_SIGINFO_T, "$ac_cv_have_extended_signals",
676     [Define if your system support extended signals.])
677     fi
678    
679     dnl Otherwise, check for subterfuges.
680     if [[ -z "$sigsegv_recovery" ]]; then
681     AC_CACHE_CHECK([whether we then have a subterfuge for your system],
682     ac_cv_have_sigcontext_hack, [
683     AC_LANG_SAVE
684     AC_LANG_CPLUSPLUS
685     AC_TRY_RUN([
686     #define HAVE_SIGCONTEXT_SUBTERFUGE 1
687     #define CONFIGURE_TEST_SIGSEGV_RECOVERY
688     #include "vm_alloc.cpp"
689     #include "sigsegv.cpp"
690     ],
691     ac_cv_have_sigcontext_hack=yes,
692     ac_cv_have_sigcontext_hack=no,
693     dnl When cross-compiling, do not assume anything.
694     ac_cv_have_sigcontext_hack=no
695     )
696     AC_LANG_RESTORE
697     ])
698     if [[ "$ac_cv_have_sigcontext_hack" = "yes" ]]; then
699     sigsegv_recovery=sigcontext
700     fi
701     AC_TRANSLATE_DEFINE(HAVE_SIGCONTEXT_SUBTERFUGE, "$ac_cv_have_sigcontext_hack",
702     [Define if we know a hack to replace siginfo_t->si_addr member.])
703     fi
704    
705     dnl Check if we can ignore the fault (instruction skipping in SIGSEGV handler)
706     AC_CACHE_CHECK([whether we can skip instruction in SIGSEGV handler],
707     ac_cv_have_skip_instruction, [
708     AC_LANG_SAVE
709     AC_LANG_CPLUSPLUS
710     AC_TRY_RUN([
711     #define HAVE_SIGSEGV_SKIP_INSTRUCTION 1
712     #define CONFIGURE_TEST_SIGSEGV_RECOVERY
713     #include "vm_alloc.cpp"
714     #include "sigsegv.cpp"
715     ], ac_cv_have_skip_instruction=yes, ac_cv_have_skip_instruction=no,
716     dnl When cross-compiling, do not assume anything.
717     ac_cv_have_skip_instruction=no
718     )
719     AC_LANG_RESTORE
720     ]
721     )
722     AC_TRANSLATE_DEFINE(HAVE_SIGSEGV_SKIP_INSTRUCTION, "$ac_cv_have_skip_instruction",
723     [Define if we can ignore the fault (instruction skipping in SIGSEGV handler).])
724    
725     dnl Can we do Video on SEGV Signals ?
726     CAN_VOSF=no
727     if [[ -n "$sigsegv_recovery" ]]; then
728     CAN_VOSF=yes
729     fi
730    
731     dnl Enable VOSF screen updates with this feature is requested and feasible
732     if [[ "x$WANT_VOSF" = "xyes" -a "x$CAN_VOSF" = "xyes" ]]; then
733     AC_DEFINE(ENABLE_VOSF, 1, [Define if using video enabled on SEGV signals.])
734     else
735     WANT_VOSF=no
736     fi
737    
738     dnl Platform specific binary postprocessor
739     AC_PATH_PROG(BLESS, "true")
740     if [[ "x$ac_cv_pagezero_hack" = "xyes" ]]; then
741     BLESS=Darwin/lowmem
742     LDFLAGS="$LDFLAGS -pagezero_size 0x3000"
743     fi
744    
745     dnl Check for GCC 2.7 or higher.
746     HAVE_GCC27=no
747     AC_MSG_CHECKING(for GCC 2.7 or higher)
748     AC_EGREP_CPP(xyes,
749     [#if __GNUC__ - 1 > 1 || __GNUC_MINOR__ - 1 > 5
750     xyes
751     #endif
752     ], [AC_MSG_RESULT(yes); HAVE_GCC27=yes], AC_MSG_RESULT(no))
753    
754     dnl Check for GCC 3.0 or higher.
755     HAVE_GCC30=no
756     AC_MSG_CHECKING(for GCC 3.0 or higher)
757     AC_EGREP_CPP(xyes,
758     [#if __GNUC__ >= 3
759     xyes
760     #endif
761     ], [AC_MSG_RESULT(yes); HAVE_GCC30=yes], AC_MSG_RESULT(no))
762    
763     dnl Check for ICC.
764     AC_MSG_CHECKING(for ICC)
765     HAVE_ICC=no
766     if $CXX -V -v 2>&1 | grep -q "Intel(R) C++ Compiler"; then
767     HAVE_ICC=yes
768     fi
769     AC_MSG_RESULT($HAVE_ICC)
770    
771     # Test if the compiler can generate ELF objects
772     AC_CACHE_CHECK([whether the compiler can generate ELF objects],
773     ac_cv_elf_objects, [
774     echo 'int i;' > conftest.$ac_ext
775     ac_cv_elf_objects=no
776     if AC_TRY_EVAL(ac_compile); then
777     case `/usr/bin/file conftest.$ac_objext` in
778     *"ELF"*)
779     ac_cv_elf_objects=yes
780     ;;
781     esac
782     fi
783     rm -rf conftest*
784     ])
785     ELF_OBJECTS=$ac_cv_elf_objects
786    
787     dnl CPU emulator sources
788     if [[ "x$EMULATED_PPC" = "xyes" ]]; then
789     CPUSRCS="\
790     ../kpx_cpu/src/cpu/ppc/ppc-cpu.cpp \
791     ../kpx_cpu/src/cpu/ppc/ppc-decode.cpp \
792     ../kpx_cpu/src/cpu/ppc/ppc-execute.cpp \
793     ../kpx_cpu/src/cpu/ppc/ppc-translate.cpp"
794     CPPFLAGS="$CPPFLAGS -I../kpx_cpu/include -I../kpx_cpu/src"
795    
796     dnl Enable JIT compiler, if possible
797     if [[ "x$WANT_JIT" = "xyes" ]]; then
798     AC_CACHE_CHECK([whether dyngen can be used],
799     ac_cv_use_dyngen, [
800     case $host_cpu:$ELF_OBJECTS in
801     powerpc:yes)
802     ac_cv_use_dyngen=yes
803     ;;
804     x86_64:yes)
805     ac_cv_use_dyngen=yes
806     ;;
807     i?86:yes)
808     ac_cv_use_dyngen=yes
809     ;;
810     *:*)
811     ac_cv_use_dyngen=no
812     ;;
813     esac
814     dnl Check for a suitable synthetic opcodes compiler (icc is faking itself as gcc 3.2.2)
815     if [[ -z "$DYNGEN_CC" ]]; then
816     if [[ "x$HAVE_GCC27" = "xyes" -a "x$HAVE_ICC" = "xno" ]]; then
817     DYNGEN_CC=$CXX
818     else
819     for p in /usr/bin /usr/local/bin; do
820     gxx="$p/g++"
821     if [[ -x "$gxx" ]]; then
822     DYNGEN_CC="$gxx"
823     fi
824     done
825     fi
826     fi
827     if [[ -z "$DYNGEN_CC" ]] || ! { echo '#include <limits>' | $DYNGEN_CC -xc++ -c -o /dev/null - >& /dev/null; }; then
828     ac_cv_use_dyngen=no
829     fi
830     ])
831     if [[ "x$ac_cv_use_dyngen" = "xyes" ]]; then
832     case $host_cpu in
833     i?86)
834     DYNGEN_OP_FLAGS="-fomit-frame-pointer -mpreferred-stack-boundary=2"
835     if [[ "x$HAVE_GCC30" = "xyes" ]]; then
836     DYNGEN_OP_FLAGS="$DYNGEN_OP_FLAGS -falign-functions=0"
837     else
838     DYNGEN_OP_FLAGS="$DYNGEN_OP_FLAGS -malign-functions=0"
839     fi
840     saved_CPPFLAGS=$CPPFLAGS
841     CPPFLAGS="$CPPFLAGS -mmmx"
842     AC_CHECK_HEADERS(mmintrin.h, [DYNGEN_OP_FLAGS="$DYNGEN_OP_FLAGS -mmmx"])
843     CPPFLAGS="$CPPFLAGS -msse"
844     AC_CHECK_HEADERS(xmmintrin.h, [DYNGEN_OP_FLAGS="$DYNGEN_OP_FLAGS -msse"])
845     CPPFLAGS="$CPPFLAGS -msse2"
846     AC_CHECK_HEADERS(emmintrin.h, [DYNGEN_OP_FLAGS="$DYNGEN_OP_FLAGS -msse2"])
847     CPPFLAGS=$saved_CPPFLAGS
848     ;;
849     x86_64)
850     AC_CHECK_HEADERS(mmintrin.h xmmintrin.h emmintrin.h)
851     ;;
852     esac
853     DYNGEN_OP_FLAGS="$DYNGEN_OP_FLAGS -finline-limit=10000"
854     if [[ "x$HAVE_GCC30" = "xyes" ]]; then
855     DYNGEN_OP_FLAGS="$DYNGEN_OP_FLAGS -fno-reorder-blocks -fno-optimize-sibling-calls"
856     fi
857     else
858     WANT_JIT=no
859     fi
860     AC_TRANSLATE_DEFINE(ENABLE_DYNGEN, $ac_cv_use_dyngen, [Define to enable dyngen engine])
861     if [[ "x$WANT_JIT" = "xyes" ]]; then
862     DYNGENSRCS="\
863     ../kpx_cpu/src/cpu/jit/dyngen.c \
864     ../kpx_cpu/src/cpu/jit/cxxdemangle.cpp"
865     CPUSRCS="\
866     ../kpx_cpu/src/cpu/jit/jit-cache.cpp \
867     ../kpx_cpu/src/cpu/jit/basic-dyngen.cpp \
868     ../kpx_cpu/src/cpu/ppc/ppc-dyngen.cpp $CPUSRCS"
869     fi
870     fi
871     CPUSRCS="$CPUSRCS ../kpx_cpu/sheepshaver_glue.cpp"
872     else
873     WANT_JIT=no
874     fi
875     if [[ "x$ac_cv_use_dyngen" = "xyes" ]]; then
876     AC_CACHE_CHECK([whether static data regions are executable],
877     ac_cv_have_static_data_exec, [
878     AC_TRY_RUN([int main(void) {
879     #if defined(__powerpc__)
880     static unsigned int p[8] = {0x4e800020,};
881     asm volatile("dcbst 0,%0" : : "r" (p) : "memory");
882     asm volatile("sync" : : : "memory");
883     asm volatile("icbi 0,%0" : : "r" (p) : "memory");
884     asm volatile("sync" : : : "memory");
885     asm volatile("isync" : : : "memory");
886     ((void (*)(void))p)();
887     return 0;
888     #endif
889     return 1;
890     }], ac_cv_have_static_data_exec=yes, ac_cv_have_static_data_exec=no,
891     dnl When cross-compiling, do not assume anything.
892     ac_cv_have_static_data_exec=no
893     )
894     ])
895     fi
896     AC_TRANSLATE_DEFINE(HAVE_STATIC_DATA_EXEC, "$ac_cv_have_static_data_exec",
897     [Define if your system marks static data pages as executable.])
898    
899     if [[ "x$WANT_JIT" = "xyes" ]]; then
900     CPPFLAGS="$CPPFLAGS -DUSE_JIT"
901     fi
902    
903     dnl Generate Makefile.
904     AC_SUBST(DYNGENSRCS)
905     AC_SUBST(DYNGEN_CC)
906     AC_SUBST(DYNGEN_OP_FLAGS)
907     AC_SUBST(SYSSRCS)
908     AC_SUBST(CPUSRCS)
909     AC_SUBST(BLESS)
910     AC_SUBST(KEYCODES)
911     AC_OUTPUT(Makefile)
912    
913     dnl Print summary.
914     echo
915     echo SheepShaver configuration summary:
916     echo
917     echo SDL support ...................... : $SDL_SUPPORT
918     echo XFree86 DGA support .............. : $WANT_XF86_DGA
919     echo XFree86 VidMode support .......... : $WANT_XF86_VIDMODE
920     echo Using PowerPC emulator ........... : $EMULATED_PPC
921     echo Enable JIT compiler .............. : $WANT_JIT
922     echo Enable video on SEGV signals ..... : $WANT_VOSF
923     echo ESD sound support ................ : $WANT_ESD
924     echo GTK user interface ............... : $WANT_GTK
925     echo mon debugger support ............. : $WANT_MON
926     echo Bad memory access recovery type .. : $sigsegv_recovery
927     echo
928     echo "Configuration done. Now type \"make\"."