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