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