2005-02-28 Martin Baulig <martin@ximian.com>
[mono.git] / configure.in
1 AC_INIT(README)
2 AC_CANONICAL_SYSTEM
3
4 # Gross hack to enable 'make dist' on automake 1.9+tar 1.14.
5 # The extra brackets are to foil regex-based scans.
6 m4_ifdef([_A][M_PROG_TAR],[_A][M_SET_OPTION([tar-ustar])])
7
8 AM_CONFIG_HEADER(config.h)
9 AM_INIT_AUTOMAKE(mono,1.1.4)
10 AM_MAINTAINER_MODE
11
12 AC_PROG_LN_S
13
14 # In case of cygwin, override LN_S, irrespective of what it determines.
15 # The build uses cygwin, but the actual runtime doesn't.
16 case $host_os in
17 *cygwin* ) LN_S='cp -p';;
18 esac
19
20
21 dnl
22 dnl libgc checks
23 dnl
24
25 gc_headers=no
26 gc=included
27 use_included_gc=no
28
29 if test -d $srcdir/libgc ; then
30   gc_default=included
31 else
32   gc_default=boehm
33 fi
34
35 #
36 # These are the flags that need to be stored in the mono.pc file for 
37 # compiling code that will embed Mono
38 #
39 libmono_cflags=""
40 libmono_ldflags=""
41 AC_SUBST(libmono_cflags)
42 AC_SUBST(libmono_ldflags)
43
44 dnl if linker handles the version script
45 no_version_script=no
46
47 # Set to yes if Unix sockets cannot be created in an anonymous namespace
48 need_link_unlink=no
49
50 # Thread configuration inspired by sleepycat's db
51 AC_MSG_CHECKING([host platform characteristics])
52 libgc_threads=no
53 case "$host" in
54         *-*-mingw*|*-*-cygwin*)
55                 platform_win32=yes
56                 AC_DEFINE(PLATFORM_WIN32,1,[Platform is Win32])
57                 CC="gcc -mno-cygwin -g"
58                 HOST_CC="gcc"
59                 # So libgc configure gets -mno-cygwin
60                 export CC
61 # latest libgc already defines GC_WIN32_THREADS
62 #               CPPFLAGS="$CPPFLAGS -DGC_WIN32_THREADS -DWIN32_THREADS"
63                 CPPFLAGS="$CPPFLAGS -DWIN32_THREADS"
64                 libdl=
65                 libgc_threads=win32
66                 gc_default=included
67                 with_nptl=default
68                 with_sigaltstack=no
69                 LN_S=cp
70                 ;;
71         *-*-*netbsd*)
72                 platform_win32=no
73                 CPPFLAGS="$CPPFLAGS -D_REENTRANT"
74                 libmono_cflags="-D_REENTRANT"
75                 LDFLAGS="$LDFLAGS -pthread"
76                 libmono_ldflags="-pthread"
77                 need_link_unlink=yes
78                 libdl=
79                 libgc_threads=no
80                 ;;
81 # these flags will work for all versions of -STABLE
82 #
83         *-*-*freebsd4*)
84                 platform_win32=no
85                 if test "x$PTHREAD_CFLAGS" = "x"; then
86                         CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE -DGC_FREEBSD_THREADS"
87                         libmono_cflags="-D_THREAD_SAFE"
88                 else
89                         CPPFLAGS="$CPPFLAGS $PTHREAD_CFLAGS -DGC_FREEBSD_THREADS"
90                         libmono_cflags="$PTHREAD_CFLAGS"
91                 fi
92                 if test "x$PTHREAD_LIBS" = "x"; then
93                         LDFLAGS="$LDFLAGS -pthread"
94                         libmono_ldflags="-pthread"
95                 else
96                         LDFLAGS="$LDFLAGS $PTHREAD_LIBS"
97                         libmono_ldflags="$PTHREAD_LIBS"
98                 fi
99                 need_link_unlink=yes
100                 AC_DEFINE(PTHREAD_POINTER_ID)
101                 libdl=
102                 libgc_threads=pthreads
103 # TLS isn't implemented at all on -STABLE
104                 with_nptl=no
105                 with_tls=pthread
106                 ;;
107 # older versions of -CURRENT will break with these flags but testing
108 # indicates these older versions won't run Mono anyway
109 #
110         *-*-*freebsd5*)
111                 platform_win32=no
112                 if test "x$PTHREAD_CFLAGS" = "x"; then
113                         CPPFLAGS="$CPPFLAGS -DGC_FREEBSD_THREADS"
114                         libmono_cflags=
115                 else
116                         CPPFLAGS="$CPPFLAGS $PTHREAD_CFLAGS -DGC_FREEBSD_THREADS"
117                         libmono_cflags="$PTHREAD_CFLAGS"
118                 fi
119                 if test "x$PTHREAD_LIBS" = "x"; then
120                         LDFLAGS="$LDFLAGS -lpthread"
121                         libmono_ldflags="-lpthread"
122                 else
123                         LDFLAGS="$LDFLAGS $PTHREAD_LIBS"
124                         libmono_ldflags="$PTHREAD_LIBS"
125                 fi
126                 need_link_unlink=yes
127                 AC_DEFINE(PTHREAD_POINTER_ID)
128                 libdl=
129                 libgc_threads=pthreads
130 # TLS is only partially implemented on -CURRENT (compiler support
131 # but NOT library support)
132 #
133                 with_nptl=no
134                 with_tls=pthread
135                 ;;
136         *-*-*openbsd*)
137                 platform_win32=no
138                 CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE -DGC_FREEBSD_THREADS"
139                 libmono_cflags="-D_THREAD_SAFE"
140                 LDFLAGS="$LDFLAGS -pthread"
141                 libmono_ldflags="-pthread"
142                 need_link_unlink=yes
143                 AC_DEFINE(PTHREAD_POINTER_ID)
144                 libdl=
145                 libgc_threads=pthreads
146                 ;;
147         *-*-linux*)
148                 platform_win32=no
149                 CPPFLAGS="$CPPFLAGS -DGC_LINUX_THREADS -D_GNU_SOURCE -D_REENTRANT"
150                 libmono_cflags="-D_REENTRANT"
151                 libmono_ldflags="-lpthread"
152                 libdl="-ldl"
153                 libgc_threads=pthreads
154                 ;;
155         *-*-hpux*)
156                 platform_win32=no
157                 CPPFLAGS="$CPPFLAGS -DGC_HPUX_THREADS -D_HPUX_SOURCE -D_XOPEN_SOURCE_EXTENDED -D_REENTRANT"
158                 CFLAGS="$CFLAGS +ESdbgasm"
159                 LDFLAGS="$LDFLAGS -z"
160                 libmono_cflags="-D_REENTRANT"
161                 libmono_ldflags="-lpthread"
162                 libgc_threads=pthreads
163                 need_link_unlink=yes
164                 ;;
165         *-*-solaris*)
166                 platform_win32=no
167                 CPPFLAGS="$CPPFLAGS -DGC_SOLARIS_THREADS -DGC_SOLARIS_PTHREADS -D_REENTRANT"
168                 need_link_unlink=yes
169                 libmono_cflags="-D_REENTRANT"
170                 libgc_threads=pthreads
171                 ;;
172         *-*-darwin*)
173                 platform_win32=no
174                 CPPFLAGS="$CPPFLAGS -no-cpp-precomp -D_THREAD_SAFE -DGC_MACOSX_THREADS"
175                 libmono_cflags="-D_THREAD_SAFE"
176                 LDFLAGS="$LDFLAGS -pthread"
177                 libmono_ldflags="-pthread"
178                 need_link_unlink=yes
179                 AC_DEFINE(PTHREAD_POINTER_ID)
180                 AC_DEFINE(USE_MACH_SEMA)
181                 no_version_script=yes
182                 libdl=
183                 libgc_threads=pthreads
184                 ;;
185         *)
186                 AC_MSG_WARN([*** Please add $host to configure.in checks!])
187                 platform_win32=no
188                 libdl="-ldl"
189                 ;;
190 esac
191 AC_MSG_RESULT(ok)
192
193 if test x$need_link_unlink = xyes; then
194    AC_DEFINE(NEED_LINK_UNLINK, 1, [Define if Unix sockets cannot be created in an anonymous namespace])
195 fi
196
197 AM_CONDITIONAL(PLATFORM_WIN32, test x$platform_win32 = xyes)
198
199 AC_CHECK_TOOL(CC, gcc, gcc)
200 AC_PROG_CC
201 AM_PROG_CC_STDC
202 AC_PROG_INSTALL
203 dnl We should use AM_PROG_AS, but it's not available on automake/aclocal 1.4
204 : ${CCAS='$(CC)'}
205 # Set ASFLAGS if not already set.
206 : ${CCASFLAGS='$(CFLAGS)'}
207 AC_SUBST(CCAS)
208 AC_SUBST(CCASFLAGS)
209
210 AC_CHECK_PROG(BISON, bison,yes,no)
211 if test "x$BISON" = "xno";
212 then
213         AC_MSG_ERROR([You need to install bison])
214 fi
215
216 dnl may require a specific autoconf version
217 dnl AC_PROG_CC_FOR_BUILD
218 dnl CC_FOR_BUILD not automatically detected
219 CC_FOR_BUILD=$CC
220 BUILD_EXEEXT=
221 if test "x$cross_compiling" = "xyes"; then
222         CC_FOR_BUILD=cc
223         BUILD_EXEEXT=""
224 fi
225 AC_SUBST(CC_FOR_BUILD)
226 AC_SUBST(HOST_CC)
227 AC_SUBST(BUILD_EXEEXT)
228
229 # Set STDC_HEADERS
230 AC_HEADER_STDC
231 AC_LIBTOOL_WIN32_DLL
232 AM_PROG_LIBTOOL
233
234 # Test whenever ld supports -version-script
235 AC_PROG_LD
236 AC_PROG_LD_GNU
237 if test "x$lt_cv_prog_gnu_ld" = "xno"; then
238    no_version_script=yes
239 fi
240
241 AM_CONDITIONAL(NO_VERSION_SCRIPT, test x$no_version_script = xyes)
242
243 AC_CHECK_HEADERS(sys/filio.h sys/sockio.h netdb.h utime.h semaphore.h sys/un.h linux/rtc.h)
244
245 AC_CHECK_HEADER(zlib.h, [have_zlib=yes], [have_zlib=no])
246
247 AM_CONDITIONAL(HAVE_ZLIB, test x$have_zlib = xyes)
248
249 # for mono/metadata/debug-symfile.c
250 AC_CHECK_HEADERS(elf.h)
251
252 # for mono/dis
253 AC_CHECK_HEADERS(wchar.h)
254 AC_CHECK_HEADERS(ieeefp.h)
255 AC_MSG_CHECKING(for isinf)
256 AC_TRY_COMPILE([#include <math.h>], [
257         int f = isinf (1);
258 ], [
259         AC_MSG_RESULT(yes)
260         AC_DEFINE(HAVE_ISINF, 1, [isinf available])
261 ], [
262         # We'll have to use signals
263         AC_MSG_RESULT(no)
264 ])
265
266
267 # not 64 bit clean in cross-compile
268 AC_CHECK_SIZEOF(void *, 4)
269
270 WARN=''
271 if test x"$GCC" = xyes; then
272         WARN='-Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes  -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wno-cast-qual -Wcast-align -Wwrite-strings'
273                 # The runtime code does not respect ANSI C strict aliasing rules
274                 CFLAGS="$CFLAGS -fno-strict-aliasing"
275
276                 ORIG_CFLAGS=$CFLAGS
277                 CFLAGS="$CFLAGS -Wdeclaration-after-statement"
278                 AC_MSG_CHECKING(for -Wdeclaration-after-statement option to gcc)
279                 AC_TRY_COMPILE([], [
280                                                    void main () { }
281                 ], [
282                    AC_MSG_RESULT(yes)
283                 ], [
284                    AC_MSG_RESULT(no)
285                    CFLAGS=$ORIG_CFLAGS
286                 ])
287 else
288         # The Sun Forte compiler complains about inline functions that access static variables
289         # so disable all inlining.
290         case "$host" in
291         *-*-solaris*)
292                 CFLAGS="$CFLAGS -Dinline="
293                 ;;
294         esac
295 fi
296 CFLAGS="$CFLAGS -g $WARN"
297
298 # Where's the 'mcs' source tree?
299 if test -d $srcdir/mcs; then
300   mcsdir=mcs
301 else
302   mcsdir=../mcs
303 fi
304
305 mcs_topdir='$(top_srcdir)/'$mcsdir
306 mcs_topdir_from_srcdir='$(top_builddir)/'$mcsdir
307
308 AC_SUBST([mcs_topdir])
309 AC_SUBST([mcs_topdir_from_srcdir])
310
311 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
312 if test "x$PKG_CONFIG" = "xno"; then
313         AC_MSG_ERROR([You need to install pkg-config])
314 fi
315
316 dnl for use on the build system
317 dnl pkg-config is stupid
318 BUILD_GLIB_CFLAGS=`$PKG_CONFIG --cflags glib-2.0 gthread-2.0`
319 BUILD_GLIB_LIBS=`$PKG_CONFIG --libs glib-2.0 gthread-2.0`
320 AC_SUBST(BUILD_GLIB_CFLAGS)
321 AC_SUBST(BUILD_GLIB_LIBS)
322
323 PKG_PATH=
324 AC_ARG_WITH(crosspkgdir, [  --with-crosspkgdir=/path/to/pkg-config/dir],
325         if test x$with_crosspkgdir = "x"; then
326                 if test -s $PKG_CONFIG_PATH; then
327                         PKG_PATH=$PKG_CONFIG_PATH
328                 fi
329         else
330                 PKG_PATH=$with_crosspkgdir
331                 PKG_CONFIG_PATH=$PKG_PATH
332                 export PKG_CONFIG_PATH
333         fi
334 )
335
336 ## Versions of dependencies
337 GLIB_REQUIRED_VERSION=1.3.11
338
339 PKG_CHECK_MODULES(BASE_DEPENDENCIES, glib-2.0 >= $GLIB_REQUIRED_VERSION)
340
341 GLIB_CFLAGS=`$PKG_CONFIG --cflags glib-2.0 gthread-2.0`
342 GLIB_LIBS=`$PKG_CONFIG --libs glib-2.0 gthread-2.0`
343 GMODULE_CFLAGS=`$PKG_CONFIG --cflags gmodule-2.0`
344 GMODULE_LIBS=`$PKG_CONFIG --libs gmodule-2.0`
345
346 AC_SUBST(GLIB_CFLAGS)
347 AC_SUBST(GLIB_LIBS)
348 AC_SUBST(GMODULE_CFLAGS)
349 AC_SUBST(GMODULE_LIBS)
350
351 if test x$platform_win32 = xyes; then   
352    AC_MSG_CHECKING(for cygwin glib2-dev package)
353    if [ cygcheck --f /usr/lib/libglib-2.0.dll.a | grep -q glib2-devel ]; then
354       AC_MSG_RESULT(found)
355           AC_MSG_ERROR([Mono cannot be built with the cygwin glib2-devel package installed, because that package doesn't work with -mno-cygwin. Please uninstall it then re-run configure.])
356    else
357       AC_MSG_RESULT(not found, ok)
358    fi
359
360    AC_MSG_CHECKING(for broken gwin32.h)
361    glib_include=`$PKG_CONFIG --cflags-only-I glib-2.0 | sed -e 's/ -I.*//g' | sed -e 's/-I//g'`
362    if test -f $glib_include/glib/gwin32.h; then
363           if [ grep ftruncate $glib_include/glib/gwin32.h | grep -q define ]; then
364                  AC_MSG_RESULT(failed)
365                  hashmark='#'
366                  AC_MSG_ERROR([Your version of gwin32.h is broken and will cause compilation errors when building mono. Please fix it by deleting the line: '$hashmark   define ftruncate...' from '$glib_include/glib/gwin32.h' then re-run configure.])
367           fi
368    fi
369    AC_MSG_RESULT(ok)
370 fi
371
372 AC_ARG_WITH(gc, [  --with-gc=boehm,included,none],[gc=$with_gc],[gc=$gc_default])
373
374 # Enable support for fast thread-local storage
375 # Some systems have broken support, so we allow to disable it.
376 AC_ARG_WITH(tls, [  --with-tls=__thread,pthread       select Thread Local Storage implementation],[],[with_tls=__thread])
377
378 # Kept for compatibility
379 AC_ARG_WITH(nptl, [  --with-nptl=yes,no      deprecated, use --with-tls instead],[],[with_nptl=default])
380
381 if test "x$with_nptl" != "xdefault"; then
382    if test "x$with_nptl" = "xyes"; then
383       AC_MSG_WARN([--with-nptl=yes is deprecated, use --with-tls=__thread option instead.])
384           with_tls=__thread
385    fi
386    if test "x$with_nptl" = "xno"; then
387       AC_MSG_WARN([--with-nptl=no is deprecated, use --with-tls=pthread option instead.])
388           with_tls=pthread
389    fi
390 fi
391
392 # Enable support for using sigaltstack for SIGSEGV and stack overflow handling
393 # This does not work on some platforms (bug #55253)
394 AC_ARG_WITH(sigaltstack, [  --with-sigaltstack=yes,no      enable/disable support for sigaltstack],[],[with_sigaltstack=no])
395
396 AC_ARG_WITH(static_mono, [  --with-static_mono=yes,no      link mono statically to libmono (faster)],[],[with_static_mono=yes])
397
398 if test "x$enable_static" = "xno"; then
399    with_static_mono=no
400 fi
401
402 AM_CONDITIONAL(STATIC_MONO, test x$with_static_mono != xno)
403
404 AC_ARG_ENABLE(minimal, [  --enable-minimal=LIST      drop support for LIST subsystems.
405   LIST is a comma-separated list from: aot, profiler, decimal, pinvoke, debug, reflection_emit.],
406 [
407         for feature in `echo "$enable_minimal" | sed -e "s/,/ /g"`; do
408                 eval "mono_feature_disable_$feature='yes'"
409                 AC_MSG_NOTICE([Disabled support for feature: $feature])
410         done
411         disabled="Disabled:    $enable_minimal"
412 ],[])
413
414 if test "x$mono_feature_disable_aot" = "xyes"; then
415         AC_DEFINE(DISABLE_AOT, 1, [Disable AOT support])
416 fi
417
418 if test "x$mono_feature_disable_profiler" = "xyes"; then
419         AC_DEFINE(DISABLE_PROFILER, 1, [Disable default profiler support])
420 fi
421
422 if test "x$mono_feature_disable_decimal" = "xyes"; then
423         AC_DEFINE(DISABLE_DECIMAL, 1, [Disable System.Decimal support])
424 fi
425
426 if test "x$mono_feature_disable_pinvoke" = "xyes"; then
427         AC_DEFINE(DISABLE_PINVOKE, 1, [Disable P/Invoke support])
428 fi
429
430 if test "x$mono_feature_disable_debug" = "xyes"; then
431         AC_DEFINE(DISABLE_DEBUG, 1, [Disable runtime debugging support])
432 fi
433
434 if test "x$mono_feature_disable_reflection_emit" = "xyes"; then
435         AC_DEFINE(DISABLE_REFLECTION_EMIT, 1, [Disable reflection emit support])
436 fi
437
438 LIBGC_CFLAGS=
439 LIBGC_LIBS=
440 LIBGC_STATIC_LIBS=
441 libgc_dir=
442 case "x$gc" in
443         xboehm|xbohem|xyes)
444                 AC_CHECK_HEADERS(gc.h gc/gc.h, gc_headers=yes)
445                 AC_CHECK_LIB(gc, GC_malloc, found_boehm="yes",,$libdl)
446
447                 if test "x$found_boehm" != "xyes"; then
448                         AC_MSG_ERROR("GC requested but libgc not found! Install libgc or run configure with --with-gc=none.")
449                 fi
450                 if test "x$gc_headers" != "xyes"; then
451                         AC_MSG_ERROR("GC requested but header files not found! You may need to install them by hand.")
452                 fi
453
454                 AC_DEFINE(HAVE_BOEHM_GC)
455                 AC_SUBST(HAVE_BOEHM_GC)
456                 LIBGC_LIBS="-lgc $libdl"
457                 LIBGC_STATIC_LIBS="$LIBGC_LIBS"
458
459                 # AC_CHECK_FUNCS does not work for some reason...
460                 AC_CHECK_LIB(gc, GC_gcj_malloc, found_gcj_malloc="yes",,$libdl)
461                 if test "x$found_gcj_malloc" = "xyes"; then
462                         AC_DEFINE(HAVE_GC_GCJ_MALLOC)
463                 fi
464                 AC_CHECK_LIB(gc, GC_enable, found_gc_enable="yes",,$libdl)
465                 if test "x$found_gc_enable" = "xyes"; then
466                         AC_DEFINE(HAVE_GC_ENABLE)
467                 fi
468                 ;;
469
470         xincluded)
471                 AC_CONFIG_SUBDIRS(libgc)
472
473                 found_boehm=yes
474                 gc_headers=yes
475                 use_included_gc=yes
476                 libgc_dir=libgc
477
478                 LIBGC_CFLAGS='-I$(top_srcdir)/libgc/include'
479                 LIBGC_LIBS='$(top_builddir)/libgc/libmonogc.la'
480                 LIBGC_STATIC_LIBS='$(top_builddir)/libgc/libmonogc-static.la'
481
482                 AC_DEFINE(HAVE_BOEHM_GC)
483                 AC_SUBST(HAVE_BOEHM_GC)
484
485                 AC_DEFINE(HAVE_GC_H)
486                 AC_DEFINE(USE_INCLUDED_LIBGC)
487
488                 # The included libgc contains GCJ support
489                 AC_DEFINE(HAVE_GC_GCJ_MALLOC)
490                 AC_DEFINE(HAVE_GC_ENABLE)
491                 ;;
492
493         xnone)
494                 AC_MSG_WARN("Compiling mono without GC.")
495                 ;;
496         *)
497                 AC_MSG_ERROR([Invalid argument to --with-gc.])
498                 ;;
499 esac
500
501
502 # tell libgc/configure about what we want
503 ac_configure_args="$ac_configure_args --disable-embed-check --with-libgc-threads=$libgc_threads"
504
505 AM_CONDITIONAL(INCLUDED_LIBGC, test x$use_included_gc = xyes)
506 AC_SUBST(LIBGC_CFLAGS)
507 AC_SUBST(LIBGC_LIBS)
508 AC_SUBST(LIBGC_STATIC_LIBS)
509 AC_SUBST(libgc_dir)
510
511 dnl
512 dnl End of libgc checks
513 dnl
514
515 if test x$platform_win32 = xno; then
516
517         dnl ******************************************************************
518         dnl *** Checks for the IKVM JNI interface library                  ***
519         dnl ******************************************************************
520         AC_ARG_WITH(ikvm-native, [  --with-ikvm-native=yes,no  build the IKVM JNI interface library],[with_ikvm_native=$withval],[with_ikvm_native=yes])
521
522         ikvm_native_dir=
523         if test x$with_ikvm_native = xyes; then
524                 ikvm_native_dir=ikvm-native
525                 jdk_headers_found="IKVM Native"
526         fi
527
528         AC_SUBST(ikvm_native_dir)
529
530         AC_CHECK_FUNCS(getgrgid_r)
531         AC_CHECK_FUNCS(getgrnam_r)
532         AC_CHECK_FUNCS(getpwnam_r)
533         AC_CHECK_FUNCS(getpwuid_r)
534         AC_CHECK_FUNCS(getresuid)
535         AC_CHECK_FUNCS(setresuid)
536         AC_CHECK_FUNCS(kqueue)
537         AC_CHECK_FUNCS(backtrace_symbols)
538
539         dnl ******************************************************************
540         dnl *** Check for large file support                               ***
541         dnl *** (If we were using autoconf 2.50 we'd use AC_SYS_LARGEFILE) ***
542         dnl ******************************************************************
543         
544         # Check that off_t can represent 2**63 - 1 correctly, working around
545         # potential compiler bugs.  Defines LARGE_FILE_SUPPORT, adds $1 to
546         # CPPFLAGS and sets $large_offt to yes if the test succeeds
547         large_offt=no
548         AC_DEFUN(LARGE_FILES, [
549                 large_CPPFLAGS=$CPPFLAGS
550                 CPPFLAGS="$CPPFLAGS $1"
551                 AC_TRY_RUN([
552                         #include <sys/types.h>
553
554                         #define BIG_OFF_T (((off_t)1<<62)-1+((off_t)1<<62))
555
556                         int main(void) {
557                                 int big_off_t=((BIG_OFF_T%2147483629==721) &&
558                                                (BIG_OFF_T%2147483647==1));
559                                 if(big_off_t) {
560                                         exit(0);
561                                 } else {
562                                         exit(1);
563                                 }
564                         }
565                 ], [
566                         AC_MSG_RESULT(ok)
567                         AC_DEFINE(HAVE_LARGE_FILE_SUPPORT)
568                         large_CPPFLAGS="$large_CPPFLAGS $1"
569                         large_offt=yes
570                 ], [
571                         AC_MSG_RESULT(no)
572                 ], "")
573                 CPPFLAGS=$large_CPPFLAGS
574         ])
575
576         AC_MSG_CHECKING(if off_t is 64 bits wide)
577         LARGE_FILES("")
578         if test $large_offt = no; then
579                 AC_MSG_CHECKING(if _FILE_OFFSET_BITS=64 gives 64 bit off_t)
580                 LARGE_FILES("-D_FILE_OFFSET_BITS=64")
581         fi
582         if test $large_offt = no; then
583                 AC_MSG_WARN([No 64 bit file size support available])
584         fi
585         
586         dnl *****************************
587         dnl *** Checks for libsocket  ***
588         dnl *****************************
589         AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
590
591         dnl *******************************
592         dnl *** Checks for MSG_NOSIGNAL ***
593         dnl *******************************
594         AC_MSG_CHECKING(for MSG_NOSIGNAL)
595         AC_TRY_COMPILE([#include <sys/socket.h>], [
596                 int f = MSG_NOSIGNAL;
597         ], [
598                 # Yes, we have it...
599                 AC_MSG_RESULT(yes)
600                 AC_DEFINE(HAVE_MSG_NOSIGNAL)
601         ], [
602                 # We'll have to use signals
603                 AC_MSG_RESULT(no)
604         ])
605
606         dnl *****************************
607         dnl *** Checks for SOL_IP     ***
608         dnl *****************************
609         AC_MSG_CHECKING(for SOL_IP)
610         AC_TRY_COMPILE([#include <netdb.h>], [
611                 int level = SOL_IP;
612         ], [
613                 # Yes, we have it...
614                 AC_MSG_RESULT(yes)
615                 AC_DEFINE(HAVE_SOL_IP)
616         ], [
617                 # We'll have to use getprotobyname
618                 AC_MSG_RESULT(no)
619         ])
620
621         dnl *****************************
622         dnl *** Checks for SOL_IPV6     ***
623         dnl *****************************
624         AC_MSG_CHECKING(for SOL_IPV6)
625         AC_TRY_COMPILE([#include <netdb.h>], [
626                 int level = SOL_IPV6;
627         ], [
628                 # Yes, we have it...
629                 AC_MSG_RESULT(yes)
630                 AC_DEFINE(HAVE_SOL_IPV6)
631         ], [
632                 # We'll have to use getprotobyname
633                 AC_MSG_RESULT(no)
634         ])
635
636         dnl *****************************
637         dnl *** Checks for SOL_TCP    ***
638         dnl *****************************
639         AC_MSG_CHECKING(for SOL_TCP)
640         AC_TRY_COMPILE([#include <netdb.h>], [
641                 int level = SOL_TCP;
642         ], [
643                 # Yes, we have it...
644                 AC_MSG_RESULT(yes)
645                 AC_DEFINE(HAVE_SOL_TCP)
646         ], [
647                 # We'll have to use getprotobyname
648                 AC_MSG_RESULT(no)
649         ])
650
651         dnl *****************************
652         dnl *** Checks for IP_PKTINFO ***
653         dnl *****************************
654         AC_MSG_CHECKING(for IP_PKTINFO)
655         AC_TRY_COMPILE([#include <netdb.h>], [
656                 int level = IP_PKTINFO;
657         ], [
658                 # Yes, we have it...
659                 AC_MSG_RESULT(yes)
660                 AC_DEFINE(HAVE_IP_PKTINFO)
661         ], [
662                 AC_MSG_RESULT(no)
663         ])
664
665         dnl *********************************
666         dnl *** Check for struct ip_mreqn ***
667         dnl *********************************
668         AC_MSG_CHECKING(for struct ip_mreqn)
669         AC_TRY_COMPILE([#include <netinet/in.h>], [
670                 struct ip_mreqn mreq;
671                 mreq.imr_address.s_addr = 0;
672         ], [
673                 # Yes, we have it...
674                 AC_MSG_RESULT(yes)
675                 AC_DEFINE(HAVE_STRUCT_IP_MREQN)
676         ], [
677                 # We'll just have to try and use struct ip_mreq
678                 AC_MSG_RESULT(no)
679                 AC_MSG_CHECKING(for struct ip_mreq)
680                 AC_TRY_COMPILE([#include <netinet/in.h>], [
681                         struct ip_mreq mreq;
682                         mreq.imr_interface.s_addr = 0;
683                 ], [
684                         # Yes, we have it...
685                         AC_MSG_RESULT(yes)
686                         AC_DEFINE(HAVE_STRUCT_IP_MREQ)
687                 ], [
688                         # No multicast support
689                         AC_MSG_RESULT(no)
690                 ])
691         ])
692         
693         dnl **********************************
694         dnl *** Check for gethostbyname2_r ***
695         dnl **********************************
696         AC_MSG_CHECKING(for gethostbyname2_r)
697                 AC_TRY_LINK([#include <netdb.h>], [
698                 gethostbyname2_r(NULL,0,NULL,NULL,0,NULL,NULL);
699         ], [
700                 # Yes, we have it...
701                 AC_MSG_RESULT(yes)
702                 AC_DEFINE(HAVE_GETHOSTBYNAME2_R)
703         ], [
704                 AC_MSG_RESULT(no)
705         ])
706
707         dnl *****************************
708         dnl *** Checks for libnsl     ***
709         dnl *****************************
710         AC_CHECK_LIB(nsl, gethostbyaddr, LIBS="$LIBS -lnsl")
711
712         AC_CHECK_FUNCS(inet_pton inet_aton)
713
714         dnl ***********************************************
715         dnl *** Checks for size of sockaddr_un.sun_path ***
716         dnl ***********************************************
717         # AC_CHECK_SIZEOF can't cope with struct members :-(
718         AC_MSG_CHECKING(size of sockaddr_un.sun_path)
719         AC_CACHE_VAL(cv_mono_sizeof_sunpath,
720                 [AC_TRY_RUN([
721                         #include <sys/types.h>
722                         #include <stdio.h>
723                         #include <sys/un.h>
724
725                         int main(void) {
726                                 struct sockaddr_un sock_un;
727                                 FILE *f=fopen("conftestval", "w");
728                                 if(!f) exit(1);
729                                 fprintf(f, "%d\n", sizeof(sock_un.sun_path));
730                                 exit(0);
731                         }
732                 ], cv_mono_sizeof_sunpath=`cat conftestval`,
733                    cv_mono_sizeof_sunpath=0,
734                    cv_mono_sizeof_sunpath=0)])dnl
735         AC_MSG_RESULT($cv_mono_sizeof_sunpath)
736         AC_DEFINE_UNQUOTED(MONO_SIZEOF_SUNPATH, $cv_mono_sizeof_sunpath)
737
738         dnl *************************************
739         dnl *** Checks for zero length arrays ***
740         dnl *************************************
741         AC_MSG_CHECKING(whether $CC supports zero length arrays)
742         AC_TRY_COMPILE([
743                 struct s {
744                         int  length;
745                         char data [0];
746                 };
747         ], [], [
748                 AC_MSG_RESULT(yes)
749                 AC_DEFINE_UNQUOTED(MONO_ZERO_ARRAY_LENGTH, 0)
750         ], [
751                 AC_MSG_RESULT(no)
752                 AC_DEFINE_UNQUOTED(MONO_ZERO_ARRAY_LENGTH, 1)
753         ])
754
755         dnl *****************************
756         dnl *** Checks for libxnet    ***
757         dnl *****************************
758         case "${host}" in
759                 *solaris* )
760                         AC_MSG_CHECKING(for Solaris XPG4 support)
761                         if test -f /usr/lib/libxnet.so; then
762                                 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=500"
763                                 CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__"
764                                 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE_EXTENDED=1"
765                                 LIBS="$LIBS -lxnet"
766                                 AC_MSG_RESULT(yes)
767                         else
768                                 AC_MSG_RESULT(no)
769                         fi
770
771                         if test "$GCC" = "yes"; then
772                                 CFLAGS="$CFLAGS -Wno-char-subscripts"
773                         fi
774                 ;;
775         esac
776
777         dnl *****************************
778         dnl *** Checks for libpthread ***
779         dnl *****************************
780 # on FreeBSD -STABLE, the pthreads functions all reside in libc_r
781 # and libpthread does not exist
782 #
783         case "${host}" in
784                 *-*-*freebsd4*)
785                         AC_CHECK_LIB(pthread, main, LIBS="$LIBS -pthread")
786                 ;;
787                 *)
788                         AC_CHECK_LIB(pthread, main, LIBS="$LIBS -lpthread")
789                 ;;
790         esac
791         AC_CHECK_HEADERS(pthread.h)
792         AC_CHECK_FUNCS(pthread_mutex_timedlock)
793         AC_CHECK_FUNCS(pthread_getattr_np pthread_attr_get_np)
794         AC_MSG_CHECKING(for PTHREAD_MUTEX_RECURSIVE)
795         AC_TRY_COMPILE([ #include <pthread.h>], [
796                 pthread_mutexattr_t attr;
797                 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
798         ], [
799                 AC_MSG_RESULT(ok)
800         ], [
801                 AC_MSG_RESULT(no)
802                 AC_MSG_WARN(Using mono_mutex_t for recursive mutexes)
803                 AC_DEFINE(USE_MONO_MUTEX)
804         ])
805         AC_CHECK_FUNCS(pthread_attr_setstacksize)
806
807         dnl ***********************************
808         dnl *** Checks for working __thread ***
809         dnl ***********************************
810         AC_MSG_CHECKING(for working __thread)
811         if test "x$with_tls" != "x__thread"; then
812                 AC_MSG_RESULT(disabled)
813         else
814                 AC_TRY_RUN([
815                         #include <pthread.h>
816
817                         __thread int i;
818                         static int res1, res2;
819
820                         void thread_main (void *arg)
821                         {
822                                 i = arg;
823                                 sleep (1);
824                                 if (arg == 1)
825                                         res1 = (i == arg);
826                                 else
827                                         res2 = (i == arg);
828                         }
829
830                         int main () {
831                                 pthread_t t1, t2;
832
833                                 i = 5;
834
835                                 pthread_create (&t1, NULL, thread_main, 1);
836                                 pthread_create (&t2, NULL, thread_main, 2);
837
838                                 pthread_join (t1, NULL);
839                                 pthread_join (t2, NULL);
840
841                                 return !(res1 + res2 == 2);
842                         }
843                 ], [
844                                 AC_MSG_RESULT(yes)
845                 ], [
846                                 AC_MSG_RESULT(no)
847                                 with_tls=pthread
848                 ])
849         fi
850
851         dnl **************************************
852         dnl *** Checks for working sigaltstack ***
853         dnl **************************************
854         AC_MSG_CHECKING(for working sigaltstack)
855         if test "x$with_sigaltstack" != "xyes"; then
856                 AC_MSG_RESULT(disabled)
857         else
858                 AC_TRY_RUN([
859                         #include <stdio.h>
860                         #include <stdlib.h>
861                         #include <unistd.h>
862                         #include <signal.h>
863                         #include <pthread.h>
864                         #include <sys/wait.h>
865
866                         static void
867                         sigsegv_signal_handler (int _dummy, siginfo_t *info, void *context)
868                         {
869                                 exit (0);
870                         }
871
872                         static void *
873                         loop (void *ignored)
874                         {
875                                 char *ptr = NULL;
876
877                                 *ptr = 0;
878                                 return NULL;
879                         }
880
881                         static void
882                         child ()
883                         {
884                                 struct sigaction sa;
885                                 struct sigaltstack sas;
886                                 pthread_t id;
887                                 pthread_attr_t attr;
888
889                                 sa.sa_sigaction = sigsegv_signal_handler;
890                                 sigemptyset (&sa.sa_mask);
891                                 sa.sa_flags = SA_SIGINFO | SA_STACK;
892                                 if (sigaction (SIGSEGV, &sa, NULL) == -1) {
893                                         perror ("lala");
894                                         return;
895                                 }
896
897                                 sas.ss_sp = malloc (SIGSTKSZ);
898                                 sas.ss_size = SIGSTKSZ;
899                                 sas.ss_flags = SS_ONSTACK;
900                                 if (sigaltstack (&sas, NULL) == -1) {
901                                         perror ("lala");
902                                         return;
903                                 }
904
905                                 pthread_attr_init (&attr);
906                                 if (pthread_create(&id, &attr, loop, &attr) != 0) {
907                                         printf ("failed\n");
908                                         return;
909                                 }
910
911                                 sleep (100);
912                         }
913
914                         int
915                         main ()
916                         {
917                                 pid_t son;
918                                 int status;
919                                 int i;
920
921                                 son = fork ();
922                                 if (son == -1) {
923                                         return 1;
924                                 }
925
926                                 if (son == 0) {
927                                         child ();
928                                         return 0;
929                                 }
930
931                                 for (i = 0; i < 3; ++i) {
932                                         sleep (1);
933                                         waitpid (son, &status, WNOHANG);
934                                         if (WIFEXITED (status) && WEXITSTATUS (status) == 0)
935                                                 return 0;
936                                 }
937
938                                 kill (son, SIGKILL);
939                                 return 1;
940                         }
941
942                 ], [
943                                 AC_MSG_RESULT(yes)
944                                 AC_DEFINE(HAVE_WORKING_SIGALTSTACK)
945                 ], [
946                                 with_sigaltstack=no
947                                 AC_MSG_RESULT(no)
948                 ])
949         fi
950
951         dnl ********************************
952         dnl *** Checks for semaphore lib ***
953         dnl ********************************
954         # 'Real Time' functions on Solaris
955         # posix4 on Solaris 2.6
956         # pthread (first!) on Linux
957         AC_SEARCH_LIBS(sem_init, pthread rt posix4) 
958
959         dnl ********************************
960         dnl *** Checks for timezone stuff **
961         dnl ********************************
962         AC_CACHE_CHECK(for tm_gmtoff in struct tm, ac_cv_struct_tm_gmtoff,
963                 AC_TRY_COMPILE([
964                         #include <time.h>
965                         ], [
966                         struct tm tm;
967                         tm.tm_gmtoff = 1;
968                         ], ac_cv_struct_tm_gmtoff=yes, ac_cv_struct_tm_gmtoff=no))
969         if test $ac_cv_struct_tm_gmtoff = yes; then
970                 AC_DEFINE(HAVE_TM_GMTOFF)
971         else
972                 AC_CACHE_CHECK(for timezone variable, ac_cv_var_timezone,
973                         AC_TRY_COMPILE([
974                                 #include <time.h>
975                         ], [
976                                 timezone = 1;
977                         ], ac_cv_var_timezone=yes, ac_cv_var_timezone=no))
978                 if test $ac_cv_var_timezone = yes; then
979                         AC_DEFINE(HAVE_TIMEZONE)
980                 else
981                         AC_ERROR(unable to find a way to determine timezone)
982                 fi
983         fi
984
985         dnl *********************************
986         dnl *** Checks for math functions ***
987         dnl *********************************
988         LIBS="$LIBS -lm";
989         AC_CHECK_FUNCS(finite, , AC_MSG_CHECKING(for finite in math.h)
990                 AC_TRY_LINK([#include <math.h>], 
991                 [ finite(0.0); ], 
992                 AC_DEFINE(HAVE_FINITE) AC_MSG_RESULT(yes),
993                 AC_MSG_RESULT(no)))
994         AC_CHECK_FUNCS(isfinite, , AC_MSG_CHECKING(for isfinite in math.h)
995                 AC_TRY_LINK([#include <math.h>], 
996                 [ isfinite(0.0); ], 
997                 AC_DEFINE(HAVE_ISFINITE) AC_MSG_RESULT(yes),
998                 AC_MSG_RESULT(no)))
999
1000         dnl ****************************************************************
1001         dnl *** Checks for working poll() (macosx defines it but doesn't ***
1002         dnl *** have it in the library (duh))                            ***
1003         dnl ****************************************************************
1004         AC_CHECK_FUNCS(poll)
1005
1006         dnl *************************
1007         dnl *** Check for signbit ***
1008         dnl *************************
1009         AC_MSG_CHECKING(for signbit)
1010         AC_TRY_LINK([#include <math.h>], [
1011                 int s = signbit(1.0);
1012         ], [
1013                 AC_MSG_RESULT(yes)
1014                 AC_DEFINE(HAVE_SIGNBIT)
1015         ], [
1016                 AC_MSG_RESULT(no)
1017         ]) 
1018
1019         dnl *********************
1020         dnl *** Check for AIO ***
1021         dnl *********************
1022         AC_MSG_CHECKING([for SIGEV_THREAD definition])
1023         dnl Some systems (FreeBSD at least) may have aio_read
1024         dnl but don't support/define SIGEV_THREAD.
1025         AC_TRY_COMPILE([
1026         #include <sys/signal.h>
1027         ],[
1028         int x = SIGEV_THREAD;
1029         ],[
1030                 ac_cv_c_sigev_thread=yes
1031                 AC_MSG_RESULT(yes)
1032         ],[
1033                 AC_MSG_RESULT(no)
1034         ])
1035
1036         if test "$ac_cv_c_sigev_thread" = "yes" ; then
1037                 AC_CHECK_HEADERS(aio.h sys/aio.h)
1038                 AC_CHECK_LIB(rt, aio_read, [ LIBS="$LIBS -lrt" ],)
1039                 SIGVAL_PTR="undefined"
1040                 if test "$ac_cv_header_aio_h" = "yes" -o "$ac_cv_header_sys_aio_h" = "yes" ; then
1041                         AC_CHECK_MEMBER(union sigval.sigval_ptr,SIGVAL_PTR="sigval_ptr",, [
1042                                         #include <sys/signal.h>
1043                                         ])
1044                         AC_CHECK_MEMBER(union sigval.sival_ptr,SIGVAL_PTR="sival_ptr",, [
1045                                         #include <sys/signal.h>
1046                                         ])
1047                         if test "$SIGVAL_PTR" = "undefined" ; then
1048                                 AC_MSG_ERROR([Unable to detect field name in 'union sigval'])
1049                         fi
1050                 fi
1051                 AC_DEFINE_UNQUOTED(SIGVAL_PTR,$SIGVAL_PTR,[Pointer field name in 'union sigval'])
1052         fi
1053
1054         dnl **********************************
1055         dnl *** Checks for MonoPosixHelper ***
1056         dnl **********************************
1057         AC_CHECK_HEADERS(checklist.h)
1058         AC_CHECK_HEADERS(fstab.h)
1059         AC_CHECK_HEADERS(sys/sendfile.h)
1060         AC_CHECK_HEADERS(sys/statvfs.h)
1061         AC_CHECK_HEADERS(sys/vfstab.h)
1062         AC_CHECK_FUNCS(getdomainname)
1063         AC_CHECK_FUNCS(setdomainname)
1064         AC_CHECK_FUNCS(fgetgrent)
1065         AC_CHECK_FUNCS(fgetpwent)
1066         AC_CHECK_FUNCS(fgetpwent)
1067         AC_CHECK_FUNCS(getfsstat)
1068         AC_CHECK_FUNCS(posix_fadvise)
1069         AC_CHECK_FUNCS(posix_fallocate)
1070         AC_CHECK_FUNCS(posix_madvise)
1071         AC_CHECK_FUNCS(vsnprintf)
1072         AC_CHECK_FUNCS(sendfile)
1073         AC_CHECK_FUNCS(sethostid)
1074         AC_CHECK_FUNCS(statfs)
1075         AC_CHECK_FUNCS(fstatfs)
1076         AC_CHECK_FUNCS(statvfs)
1077         AC_CHECK_FUNCS(fstatvfs)
1078         AC_CHECK_FUNCS(stime)
1079         AC_CHECK_FUNCS(strerror_r)
1080         AC_CHECK_FUNCS(ttyname_r)
1081         AC_CHECK_SIZEOF(size_t)
1082         AC_CHECK_MEMBERS(
1083                 [struct dirent.d_off, struct dirent.d_reclen, struct dirent.d_type],,, 
1084                 [#include <sys/types.h>
1085                  #include <dirent.h>])
1086
1087         dnl *********************************
1088         dnl *** Check for Console 2.0 I/O ***
1089         dnl *********************************
1090         AC_CHECK_HEADERS([curses.h])
1091         AC_CHECK_HEADERS([term.h], [], [],
1092         [#if HAVE_CURSES_H
1093          #include <curses.h>
1094          #endif
1095         ])
1096         AC_CHECK_HEADERS([termios.h])
1097 else
1098         jdk_headers_found=no
1099         AC_CHECK_LIB(ws2_32, main, LIBS="$LIBS -lws2_32", AC_ERROR(bad mingw install?))
1100         AC_CHECK_LIB(psapi, main, LIBS="$LIBS -lpsapi", AC_ERROR(bad mingw install?))
1101         AC_CHECK_LIB(ole32, main, LIBS="$LIBS -lole32", AC_ERROR(bad mingw install?))
1102
1103         dnl *********************************
1104         dnl *** Check for struct ip_mreqn ***
1105         dnl *********************************
1106         AC_MSG_CHECKING(for struct ip_mreqn)
1107         AC_TRY_COMPILE([#include <ws2tcpip.h>], [
1108                 struct ip_mreqn mreq;
1109                 mreq.imr_address.s_addr = 0;
1110         ], [
1111                 # Yes, we have it...
1112                 AC_MSG_RESULT(yes)
1113                 AC_DEFINE(HAVE_STRUCT_IP_MREQN)
1114         ], [
1115                 # We'll just have to try and use struct ip_mreq
1116                 AC_MSG_RESULT(no)
1117                 AC_MSG_CHECKING(for struct ip_mreq)
1118                 AC_TRY_COMPILE([#include <ws2tcpip.h>], [
1119                         struct ip_mreq mreq;
1120                         mreq.imr_interface.s_addr = 0;
1121                 ], [
1122                         # Yes, we have it...
1123                         AC_MSG_RESULT(yes)
1124                         AC_DEFINE(HAVE_STRUCT_IP_MREQ)
1125                 ], [
1126                         # No multicast support
1127                         AC_MSG_RESULT(no)
1128                 ])
1129         ])
1130 fi
1131
1132 dnl socklen_t check
1133 AC_MSG_CHECKING(for socklen_t)
1134 AC_TRY_COMPILE([
1135 #include <sys/types.h>
1136 #include <sys/socket.h>
1137 ],[
1138   socklen_t foo;
1139 ],[
1140 ac_cv_c_socklen_t=yes
1141         AC_DEFINE(HAVE_SOCKLEN_T)
1142         AC_MSG_RESULT(yes)
1143 ],[
1144         AC_MSG_RESULT(no)
1145 ])
1146
1147 AC_MSG_CHECKING(for array element initalizer support)
1148 AC_TRY_COMPILE([#include <sys/socket.h>], [
1149         const int array[] = {[1] = 2,};
1150 ], [
1151         # Yes, we have it...
1152         AC_MSG_RESULT(yes)
1153         AC_DEFINE(HAVE_ARRAY_ELEM_INIT,1,[Supports C99 array initialization])
1154 ], [
1155         # We'll have to use signals
1156         AC_MSG_RESULT(no)
1157 ])
1158
1159 AC_CHECK_FUNCS(trunc, , AC_MSG_CHECKING(for trunc in math.h)
1160         # Simply calling trunc (0.0) is no good since gcc will optimize the call away
1161         AC_TRY_LINK([#include <math.h>], 
1162         [ static void *p = &trunc; ],
1163         [
1164                 AC_DEFINE(HAVE_TRUNC) 
1165                 AC_MSG_RESULT(yes)
1166                 ac_cv_trunc=yes
1167         ],
1168         AC_MSG_RESULT(no)))
1169
1170 if test "x$ac_cv_truncl" != "xyes"; then
1171    AC_CHECK_LIB(sunmath, aintl, [ AC_DEFINE(HAVE_AINTL) LIBS="$LIBS -lsunmath"])
1172 fi
1173
1174 dnl ****************************
1175 dnl *** Look for /dev/random ***
1176 dnl ****************************
1177
1178 AC_MSG_CHECKING([if usage of random device is requested])
1179 AC_ARG_ENABLE(dev-random,
1180 [  --disable-dev-random    disable the use of the random device],
1181 try_dev_random=$enableval, try_dev_random=yes)
1182 AC_MSG_RESULT($try_dev_random)
1183
1184 case "{$target}" in
1185     *-openbsd*)
1186     NAME_DEV_RANDOM="/dev/srandom"
1187     ;;
1188
1189 dnl Win32 does not have /dev/random, they have their own method...
1190
1191     *-*-mingw*|*-*-cygwin*)
1192     ac_cv_have_dev_random=no
1193     ;;
1194
1195 dnl Everywhere else, it's /dev/random
1196
1197     *)
1198     NAME_DEV_RANDOM="/dev/random"
1199     ;;
1200 esac
1201
1202 AC_DEFINE_UNQUOTED(NAME_DEV_RANDOM, "$NAME_DEV_RANDOM")
1203
1204 dnl Now check if the device actually exists
1205
1206 if test "x$try_dev_random" = "xyes"; then
1207     AC_CACHE_CHECK(for random device, ac_cv_have_dev_random,
1208     [if test -r "$NAME_DEV_RANDOM" ; then
1209         ac_cv_have_dev_random=yes; else ac_cv_have_dev_random=no; fi])
1210     if test "x$ac_cv_have_dev_random" = "xyes"; then
1211         AC_DEFINE(HAVE_CRYPT_RNG)
1212     fi
1213 else
1214     AC_MSG_CHECKING(for random device)
1215     ac_cv_have_dev_random=no
1216     AC_MSG_RESULT(has been disabled)
1217 fi
1218
1219 if test "x$platform_win32" = "xyes"; then
1220     AC_DEFINE(HAVE_CRYPT_RNG)
1221 fi
1222
1223 if test "x$ac_cv_have_dev_random" = "xno" \
1224     && test "x$platform_win32" = "xno"; then
1225     AC_MSG_WARN([[
1226 ***
1227 *** A system-provided entropy source was not found on this system.
1228 *** Because of this, the System.Security.Cryptography random number generator
1229 *** will throw a NotImplemented exception.
1230 ***
1231 *** If you are seeing this message, and you know your system DOES have an
1232 *** entropy collection in place, please contact <crichton@gimp.org> and
1233 *** provide information about the system and how to access the random device.
1234 ***
1235 *** Otherwise you can install either egd or prngd and set the environment
1236 *** variable MONO_EGD_SOCKET to point to the daemon's socket to use that.
1237 ***]])
1238 fi
1239  
1240 AC_MSG_CHECKING([if inter-process shared handles are requested])
1241 AC_ARG_ENABLE(shared-handles, [  --disable-shared-handles disable inter-process shared handles], try_shared_handles=$enableval, try_shared_handles=yes)
1242 AC_MSG_RESULT($try_shared_handles)
1243 if test "x$try_shared_handles" != "xyes"; then
1244         AC_DEFINE(DISABLE_SHARED_HANDLES)
1245         AC_SUBST(DISABLE_SHARED_HANDLES)
1246 fi
1247
1248 #
1249 # ICU 
1250 #
1251 ICU_CFLAGS=""
1252 ICU_LIBS=""
1253 enable_glob="normal;  default"
1254
1255 probe_icu=false
1256 AC_ARG_WITH(icu, [  --with-icu=yes/no],
1257         if test x$with_icu = xno; then
1258            probe_icu=false;
1259            AC_MSG_RESULT(Will not probe for ICU)
1260         fi
1261         if test x$with_icu = xyes; then
1262            probe_icu=true;
1263         fi
1264 )
1265
1266 if $probe_icu; then
1267         AC_PATH_PROG(ICU_CONFIG, icu-config, no)
1268         if test "x$ICU_CONFIG" = "xno" -o ! -x "$ICU_CONFIG"; then
1269                 enable_glob="ICU not found, using non-ICU globalization code."
1270         else
1271                 enable_glob="ICU, unsupported. Version: `$ICU_CONFIG --version`"
1272                 AC_DEFINE(HAVE_ICU)
1273                 ICU_CFLAGS=`$ICU_CONFIG --cppflags`
1274                 ICU_LIBS=`$ICU_CONFIG --ldflags`
1275         fi
1276 fi
1277 AC_SUBST(ICU_CFLAGS)
1278 AC_SUBST(ICU_LIBS)
1279
1280 AC_ARG_ENABLE(nunit-tests, [ --enable-nunit-tests       Run the nunit tests of the class library on 'make check'])
1281 AM_CONDITIONAL(ENABLE_NUNIT_TESTS, [test x$enable_nunit_tests = xyes])
1282
1283 TARGET="unknown"
1284 ACCESS_UNALIGNED="yes"
1285
1286 JIT_SUPPORTED=no
1287 INTERP_SUPPORTED=no
1288 LIBC="libc.so.6"
1289 INTL="libc.so.6"
1290
1291 jit_wanted=false
1292 interp_wanted=false
1293 case "$host" in
1294 #       mips-sgi-irix5.* | mips-sgi-irix6.*)
1295 #               TARGET=MIPS;
1296 #               ACCESS_UNALIGNED="no"
1297 #               ;;
1298         i*86-*-*)
1299                 TARGET=X86;
1300                 arch_target=x86;
1301                 JIT_SUPPORTED=yes
1302                 jit_wanted=true
1303                 ;;
1304         x86_64-*-* | amd64-*-*)
1305                 TARGET=AMD64;
1306                 arch_target=amd64;
1307                 JIT_SUPPORTED=yes
1308                 jit_wanted=true
1309                 ;;
1310         sparc*-*-*)
1311                 if test "x$ac_cv_sizeof_void_p" = "x8"; then
1312                    TARGET=SPARC64
1313                 else
1314                         TARGET=SPARC
1315                 fi
1316                 arch_target=sparc;
1317                 JIT_SUPPORTED=yes
1318                 ACCESS_UNALIGNED="no"
1319                 LIBC="libc.so"
1320                 INTL="libintl.so"
1321                 jit_wanted=true
1322                 if test x"$GCC" = xyes; then
1323                         CFLAGS="$CFLAGS -Wno-cast-align"
1324                 fi
1325                 ;;
1326        alpha*-*-linux* | alpha*-*-osf*)
1327                 TARGET=ALPHA;
1328                 ACCESS_UNALIGNED="no"
1329                 JIT_SUPPORTED=no
1330                 INTERP_SUPPORTED=yes
1331                 interp_wanted=true
1332                 arch_target=alpha;
1333                ;;
1334 #       ia64-*-linux* | ia64-*-hpux*)
1335 #               TARGET=IA64;
1336 #               arch_target=ia64;
1337 #               JIT_SUPPORTED=no;
1338 #               ACCESS_UNALIGNED="no";
1339 #               case "$host_os" in
1340 #                       linux*) LIBC="libc.so.6.1";;
1341 #                       hpux*)  LIBC="libc.so.1";;
1342 #               esac
1343 #               ;;
1344 #       m68k-*-linux*)
1345 #               TARGET=M68K
1346 #               ;;
1347         hppa2.0w-hp-hpux11.00 | hppa64-hp-hpux11.00)
1348                 TARGET=HPPA;
1349                 arch_target=hppa; 
1350                 LIBC="libc.sl"
1351                 ACCESS_UNALIGNED="no"
1352                 INTERP_SUPPORTED=yes
1353                 interp_wanted=true
1354                 ;;
1355         hppa*linux*)
1356                 TARGET=HPPA;
1357                 arch_target=hppa; 
1358                 ACCESS_UNALIGNED="no"
1359                 INTERP_SUPPORTED=yes
1360                 interp_wanted=true
1361                 ;;
1362         macppc-*-openbsd* | powerpc-*-linux* | powerpc-*-openbsd* | \
1363         powerpc-*-sysv* | powerpc-*-darwin*)
1364                 TARGET=POWERPC;
1365                 AC_DEFINE(MONO_ARCH_REGPARMS,1,[Architecture uses registers for Parameters])
1366                 arch_target=ppc;
1367                 JIT_SUPPORTED=yes
1368                 jit_wanted=true
1369                 ;;
1370         arm-*-linux-* | armv4l-*-linux-*)
1371                 TARGET=ARM;
1372                 arch_target=arm;
1373                 ACCESS_UNALIGNED="no"
1374                 INTERP_SUPPORTED=yes
1375                 interp_wanted=true
1376                 ;;
1377         s390-*-linux*)
1378                 TARGET=S390;
1379                 AC_DEFINE(MONO_ARCH_REGPARMS,1,[Architecture uses registers for Parameters])
1380                 arch_target=s390;
1381                 ACCESS_UNALIGNED="no"
1382                 JIT_SUPPORTED=yes
1383                 ;;
1384         s390x-*-linux*)
1385                 TARGET=S390x;
1386                 AC_DEFINE(MONO_ARCH_REGPARMS,1,[Architecture uses registers for Parameters])
1387                 arch_target=s390x;
1388                 ACCESS_UNALIGNED="no"
1389                 JIT_SUPPORTED=yes
1390                 ;;
1391 esac
1392
1393 AC_ARG_WITH(jit, [  --with-jit=yes,no       If you want to build scripts that default to the JIT],[
1394         if test x$withval = xyes; then
1395            jit_wanted=true
1396         else
1397            jit_wanted=false
1398         fi
1399 ])
1400
1401 AC_ARG_WITH(interp, [  --with-interp=yes,no    If you want to build scripts that default to the interpreter],[
1402         if test x$withval = xyes; then
1403            interp_wanted=true
1404         else
1405            interp_wanted=false
1406         fi
1407 ])
1408
1409 USEJIT=false
1410 if test x$JIT_SUPPORTED = xyes; then
1411    if $jit_wanted; then
1412       USEJIT=true
1413       jit_status="Building and using the JIT"
1414    else
1415       if $interp_wanted; then
1416          jit_status="Building the JIT, defaulting to the interpreter"
1417       else
1418          AC_ERROR(No JIT or interpreter support available or selected.)
1419       fi
1420    fi
1421 else
1422    if $interp_wanted; then
1423       jit_status="interpreter"
1424    else
1425       AC_ERROR(No JIT or interpreter support available or selected.)
1426    fi
1427 fi
1428
1429 AM_CONDITIONAL(USE_JIT, test x$USEJIT = xtrue)
1430
1431 libsuffix=".so"
1432
1433 case "$host" in
1434      powerpc-*-darwin*)
1435         libsuffix=".dylib"
1436         LIBC="libc.dylib"
1437         INTL="libintl.dylib"
1438         ;;
1439      *-*-*netbsd*)
1440         LIBC="libc.so.12"
1441         INTL="libintl.so.0"
1442         ;;
1443     *-*-*freebsd*)
1444         LIBC="libc.so"
1445         INTL="libintl.so"
1446         ;;
1447     *-*-*openbsd*)
1448         LIBC="libc.so"
1449         INTL="libintl.so"
1450         ;;
1451 esac
1452 AC_SUBST(libsuffix)
1453
1454 if test "x$TARGET" != "xAMD64"; then
1455    # valgrind headers don't compile under x86-64
1456    AC_CHECK_HEADERS(valgrind/memcheck.h)
1457 fi
1458
1459 if test "x$TARGET" = "xAMD64" -o "x$TARGET" = "xX86"; then
1460         if test "x$with_tls" = "x__thread"; then
1461                 #
1462                 # On some linux distributions, TLS works in executables, but linking 
1463                 # against a shared library containing TLS fails with:
1464                 # undefined reference to `__tls_get_addr'
1465                 #
1466                 rm -f conftest.c conftest.so conftest
1467                 echo "static __thread int foo; void main () { foo = 5; }" > conftest.c
1468                 gcc -fPIC --shared -o conftest.so conftest.c > /dev/null 2>&1
1469                 gcc -o conftest conftest.so > /dev/null 2>&1
1470                 if test ! -f conftest; then
1471                    AC_MSG_WARN([Disabling usage of __thread.]);
1472                    with_tls=pthread
1473                 fi
1474                 rm -f conftest.c conftest.so conftest
1475         fi
1476 fi
1477
1478 if test "x$with_tls" = "x__thread"; then
1479         AC_DEFINE(HAVE_KW_THREAD)
1480    # Pass the information to libgc
1481         CPPFLAGS="$CPPFLAGS -DUSE_COMPILER_TLS"
1482         export CPPFLAGS
1483         AC_MSG_CHECKING(if the tls_model attribute is supported)
1484         AC_TRY_COMPILE([static __thread int foo __attribute__((tls_model("initial-exec")));], [
1485                 ], [
1486                         AC_MSG_RESULT(yes)
1487                         AC_DEFINE(HAVE_TLS_MODEL_ATTR, 1, [tld_model available])
1488                 ], [
1489                         AC_MSG_RESULT(no)
1490         ])
1491 fi
1492
1493 if test ${TARGET} = ARM; then
1494         dnl ******************************************
1495         dnl *** Check to see what FPU is available ***
1496         dnl ******************************************
1497         AC_MSG_CHECKING(which FPU to use)
1498
1499         AC_TRY_COMPILE([], [
1500                 __asm__ ("ldfd f0, [r0]");
1501                 ], fpu=FPA, [
1502                         AC_TRY_COMPILE([], [
1503                                 __asm__ ("fldd d0, [r0]");
1504                         ], fpu=VFP, fpu=NONE)
1505                 ])
1506
1507         AC_MSG_RESULT($fpu)
1508         CPPFLAGS="$CPPFLAGS -DARM_FPU_$fpu"
1509         unset fpu
1510 fi
1511
1512 if test ${TARGET} = unknown; then
1513         CPPFLAGS="$CPPFLAGS -DNO_PORT"
1514         AC_MSG_WARN("mono has not been ported to $host: some things may not work.")
1515 fi
1516
1517 if test ${ACCESS_UNALIGNED} = no; then
1518         CPPFLAGS="$CPPFLAGS -DNO_UNALIGNED_ACCESS"
1519 fi
1520
1521 PREVIEW=no
1522 AC_ARG_WITH(preview, [ --with-preview=yes,no     If you want to install the 2.0 FX preview],[
1523         if test x$with_preview = xyes; then
1524               PREVIEW=yes
1525         fi
1526 ])
1527
1528 AM_CONDITIONAL(INSTALL_2_0, test x$PREVIEW = xyes)
1529
1530 AM_CONDITIONAL(MIPS_GCC, test ${TARGET}${ac_cv_prog_gcc} = MIPSyes)
1531 AM_CONDITIONAL(MIPS_SGI, test ${TARGET}${ac_cv_prog_gcc} = MIPSno)
1532 AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
1533 AM_CONDITIONAL(SPARC64, test x$TARGET = xSPARC64)
1534 AM_CONDITIONAL(X86, test x$TARGET = xX86)
1535 AM_CONDITIONAL(AMD64, test x$TARGET = xAMD64)
1536 AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
1537 AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
1538 AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
1539 AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
1540 AM_CONDITIONAL(ARM, test x$TARGET = xARM)
1541 AM_CONDITIONAL(S390, test x$TARGET = xS390)
1542 AM_CONDITIONAL(S390x, test x$TARGET = xS390x)
1543 AM_CONDITIONAL(HPPA, test x$TARGET = xHPPA)
1544
1545 AM_CONDITIONAL(JIT_SUPPORTED, test x$JIT_SUPPORTED = xyes)
1546 AM_CONDITIONAL(INTERP_SUPPORTED, test x$interp_wanted = xtrue)
1547 AM_CONDITIONAL(INCLUDED_LIBGC, test x$gc = xincluded)
1548
1549 AC_SUBST(LIBC)
1550 AC_SUBST(INTL)
1551
1552 AC_SUBST(arch_target)
1553 AC_SUBST(CFLAGS)
1554 AC_SUBST(CPPFLAGS)
1555 AC_SUBST(LDFLAGS)
1556
1557 mono_build_root=`pwd`
1558 AC_SUBST(mono_build_root)
1559
1560 if test x$USEJIT = xtrue; then
1561   mono_runtime=mono/mini/mono
1562 else
1563   mono_runtime=mono/interpreter/mint
1564 fi
1565 AC_SUBST(mono_runtime)
1566
1567 mono_cfg_root=$mono_build_root/runtime
1568 if test x$platform_win32 = xyes; then
1569   mono_cfg_dir=`cygpath -w -a $mono_cfg_root`\\etc
1570 else
1571   mono_cfg_dir=$mono_cfg_root/etc
1572 fi
1573 AC_SUBST(mono_cfg_dir)
1574
1575 AC_CONFIG_FILES([runtime/mono-wrapper],[chmod +x runtime/mono-wrapper])
1576
1577 AC_CONFIG_COMMANDS([runtime/etc/mono/1.0/machine.config],
1578 [   depth=../../../..
1579     case $srcdir in
1580     [\\/$]* | ?:[\\/]* ) reldir=$srcdir ;;
1581     .) reldir=$depth ;;
1582     *) reldir=$depth/$srcdir ;;
1583     esac
1584     $ac_aux_dir/install-sh -d runtime/etc/mono/1.0
1585     cd runtime/etc/mono/1.0
1586     rm -f machine.config
1587     $LN_S $reldir/data/net_1_1/machine.config machine.config
1588     cd $depth
1589 ],[LN_S='$LN_S'])
1590
1591 AC_CONFIG_COMMANDS([runtime/etc/mono/2.0/machine.config],
1592 [   depth=../../../..
1593     case $srcdir in
1594     [\\/$]* | ?:[\\/]* ) reldir=$srcdir ;;
1595     .) reldir=$depth ;;
1596     *) reldir=$depth/$srcdir ;;
1597     esac
1598     $ac_aux_dir/install-sh -d runtime/etc/mono/2.0
1599     cd runtime/etc/mono/2.0
1600     rm -f machine.config
1601     $LN_S $reldir/data/net_2_0/machine.config machine.config
1602     cd $depth
1603 ],[LN_S='$LN_S'])
1604
1605 AC_OUTPUT([
1606 Makefile
1607 mint.pc
1608 mono.pc
1609 scripts/mono-nunit.pc
1610 mono/Makefile
1611 mono/utils/Makefile
1612 mono/metadata/Makefile
1613 mono/dis/Makefile
1614 mono/cil/Makefile
1615 mono/arch/Makefile
1616 mono/os/Makefile
1617 mono/os/win32/Makefile
1618 mono/os/unix/Makefile
1619 mono/arch/x86/Makefile
1620 mono/arch/amd64/Makefile
1621 mono/arch/hppa/Makefile
1622 mono/arch/ppc/Makefile
1623 mono/arch/sparc/Makefile
1624 mono/arch/s390/Makefile
1625 mono/arch/s390x/Makefile
1626 mono/arch/arm/Makefile
1627 mono/arch/alpha/Makefile
1628 mono/interpreter/Makefile
1629 mono/tests/Makefile
1630 mono/tests/tests-config
1631 mono/benchmark/Makefile
1632 mono/monoburg/Makefile
1633 mono/monograph/Makefile
1634 mono/io-layer/Makefile
1635 mono/handles/Makefile
1636 mono/mini/Makefile
1637 mono/profiler/Makefile
1638 ikvm-native/Makefile
1639 scripts/Makefile
1640 man/Makefile
1641 web/Makefile
1642 docs/Makefile
1643 data/Makefile
1644 data/net_1_1/Makefile
1645 data/net_2_0/Makefile
1646 samples/Makefile
1647 support/Makefile
1648 data/config
1649 mono.spec
1650 tools/Makefile
1651 tools/locale-builder/Makefile
1652 runtime/Makefile
1653 ])
1654
1655 (
1656   case $prefix in
1657   NONE) prefix=/usr/local ;;
1658   esac
1659   case $exec_prefix in
1660   NONE | '${prefix}') exec_prefix=$prefix ;;
1661   esac
1662
1663   echo "prefix=$prefix" > $srcdir/$mcsdir/build/config.make
1664   echo "exec_prefix=$exec_prefix" >> $srcdir/$mcsdir/build/config.make
1665   echo "libdir=$libdir" >> $srcdir/$mcsdir/build/config.make
1666   echo 'MCS_FLAGS = $(PLATFORM_DEBUG_FLAGS)' >> $srcdir/$mcsdir/build/config.make
1667 )
1668
1669 echo "
1670         mcs source:  $mcs_topdir
1671         GC:          $gc
1672         Globalization:     $enable_glob
1673         TLS:         $with_tls
1674         SIGALTSTACK: $with_sigaltstack
1675         Engine:      $jit_status
1676         2.0 Alpha:   $PREVIEW
1677         JNI support: $jdk_headers_found
1678         $disabled
1679
1680 "