2004-04-02 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / configure.in
1 AC_INIT(README)
2 AC_CANONICAL_SYSTEM
3 AM_CONFIG_HEADER(config.h)
4 AM_INIT_AUTOMAKE(mono,0.31.99)
5 AM_MAINTAINER_MODE
6
7 dnl
8 dnl libgc checks
9 dnl
10
11 gc_headers=no
12 gc=included
13 use_included_gc=no
14
15 if test -d $srcdir/libgc ; then
16   gc_default=included
17 else
18   gc_default=boehm
19 fi
20
21 #
22 # These are the flags that need to be stored in the mono.pc file for 
23 # compiling code that will embed Mono
24 #
25 libmono_cflags=""
26 libmono_ldflags=""
27 AC_SUBST(libmono_cflags)
28 AC_SUBST(libmono_ldflags)
29
30 dnl if linker handles the version script
31 no_version_script=no
32
33 # Thread configuration inspired by sleepycat's db
34 AC_MSG_CHECKING([host platform characteristics])
35 libgc_threads=no
36 case "$host" in
37         *-*-mingw*|*-*-cygwin*)
38                 platform_win32=yes
39                 AC_DEFINE(PLATFORM_WIN32)
40                 CC="gcc -mno-cygwin"
41                 HOST_CC="gcc"
42 # latest libgc already defines GC_WIN32_THREADS
43 #               CPPFLAGS="$CPPFLAGS -DGC_WIN32_THREADS -DWIN32_THREADS"
44                 CPPFLAGS="$CPPFLAGS -DWIN32_THREADS"
45                 libdl=
46                 libgc_threads=win32
47                 gc_default=boehm 
48                 ;;
49         *-*-*netbsd*)
50                 platform_win32=no
51                 CPPFLAGS="$CPPFLAGS -D_REENTRANT"
52                 libmono_cflags="-D_REENTRANT"
53                 LDFLAGS="$LDFLAGS -pthread"
54                 libmono_ldflags="-pthread"
55                 AC_DEFINE(NEED_LINK_UNLINK)
56                 libdl=
57                 libgc_threads=pthreads
58                 ;;
59         *-*-*freebsd*|*-*-*openbsd*)
60                 platform_win32=no
61                 CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE"
62                 libmono_cflags="-D_THREAD_SAFE"
63                 LDFLAGS="$LDFLAGS -pthread"
64                 libmono_ldflags="-pthread"
65                 AC_DEFINE(NEED_LINK_UNLINK)
66                 AC_DEFINE(PTHREAD_POINTER_ID)
67                 libdl=
68                 libgc_threads=pthreads
69                 ;;
70         *-*-linux*)
71                 platform_win32=no
72                 CPPFLAGS="$CPPFLAGS -DGC_LINUX_THREADS -DMONO_USE_EXC_TABLES -D_GNU_SOURCE -D_REENTRANT -fexceptions"
73                 libmono_cflags="-DMONO_USE_EXC_TABLES -fexceptions -D_REENTRANT"
74                 libmono_ldflags="-lpthread"
75                 libdl="-ldl"
76                 libgc_threads=pthreads
77                 ;;
78         *-*-hpux*)
79                 platform_win32=no
80                 CPPFLAGS="$CPPFLAGS -DGC_HPUX_THREADS -D_HPUX_SOURCE -D_XOPEN_SOURCE_EXTENDED -D_REENTRANT"
81                 CFLAGS="$CFLAGS +ESdbgasm"
82                 LDFLAGS="$LDFLAGS -z"
83                 libmono_cflags="-D_REENTRANT"
84                 libmono_ldflags="-lpthread"
85                 libgc_threads=pthreads
86                 AC_DEFINE(NEED_LINK_UNLINK)
87                 ;;
88         *-*-solaris*)
89                 platform_win32=no
90                 CPPFLAGS="$CPPFLAGS -DGC_SOLARIS_THREADS -DGC_SOLARIS_PTHREADS -D_REENTRANT"
91                 AC_DEFINE(NEED_LINK_UNLINK)
92                 libmono_cflags="-D_REENTRANT"
93                 libgc_threads=pthreads
94                 ;;
95         *-*-darwin*)
96                 platform_win32=no
97                 CPPFLAGS="$CPPFLAGS -no-cpp-precomp -D_THREAD_SAFE"
98                 libmono_cflags="-D_THREAD_SAFE"
99                 LDFLAGS="$LDFLAGS -pthread"
100                 libmono_ldflags="-pthread"
101                 AC_DEFINE(NEED_LINK_UNLINK)
102                 AC_DEFINE(PTHREAD_POINTER_ID)
103                 AC_DEFINE(USE_MACH_SEMA)
104                 no_version_script=yes
105                 libdl=
106                 libgc_threads=no
107                 gc_default=none 
108                 ;;
109         *)
110                 AC_MSG_WARN([*** Please add $host to configure.in checks!])
111                 platform_win32=no
112                 libdl="-ldl"
113                 ;;
114 esac
115 AC_MSG_RESULT(ok)
116 AM_CONDITIONAL(PLATFORM_WIN32, test x$platform_win32 = xyes)
117
118 AM_CONDITIONAL(NO_VERSION_SCRIPT, test x$no_version_script = xyes)
119
120 AC_CHECK_TOOL(CC, gcc, gcc)
121 AC_PROG_CC
122 AM_PROG_CC_STDC
123 AC_PROG_INSTALL
124 dnl We should use AM_PROG_AS, but it's not available on automake/aclocal 1.4
125 : ${CCAS='$(CC)'}
126 # Set ASFLAGS if not already set.
127 : ${CCASFLAGS='$(CFLAGS)'}
128 AC_SUBST(CCAS)
129 AC_SUBST(CCASFLAGS)
130
131 AC_CHECK_PROG(BISON, bison,yes,no)
132 if test "x$BISON" = "xno";
133 then
134         AC_MSG_ERROR([You need to install bison])
135 fi
136
137 dnl may require a specific autoconf version
138 dnl AC_PROG_CC_FOR_BUILD
139 dnl CC_FOR_BUILD not automatically detected
140 CC_FOR_BUILD=$CC
141 BUILD_EXEEXT=
142 if test "x$cross_compiling" = "xyes"; then
143         CC_FOR_BUILD=cc
144         BUILD_EXEEXT=""
145 fi
146 AC_SUBST(CC_FOR_BUILD)
147 AC_SUBST(HOST_CC)
148 AC_SUBST(BUILD_EXEEXT)
149
150 # Set STDC_HEADERS
151 AC_HEADER_STDC
152 AC_LIBTOOL_WIN32_DLL
153 AM_PROG_LIBTOOL
154
155 # Test whenever ld supports -version-script
156 AC_PROG_LD
157 AC_PROG_LD_GNU
158 if test "x$lt_cv_prog_gnu_ld" = "xno"; then
159    no_version_script=yes
160 fi
161
162 AC_CHECK_HEADERS(sys/filio.h sys/sockio.h netdb.h utime.h semaphore.h sys/un.h)
163
164 # for mono/mini/tramp-x86.c
165 AC_CHECK_HEADERS(valgrind/memcheck.h)
166
167 # for mono/metadata/debug-symfile.c
168 AC_CHECK_HEADERS(elf.h)
169
170 # for mono/dis
171 AC_CHECK_HEADERS(wchar.h)
172
173 # not 64 bit clean in cross-compile
174 AC_CHECK_SIZEOF(void *, 4)
175
176 WARN=''
177 if test x"$GCC" = xyes; then
178         WARN='-Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes  -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wno-cast-qual -Wcast-align -Wwrite-strings'
179                 # The runtime code does not respect ANSI C strict aliasing rules
180                 CFLAGS="$CFLAGS -fno-strict-aliasing"
181 else
182         # The Sun Forte compiler complains about inline functions that access static variables
183         # so disable all inlining.
184         case "$host" in
185         *-*-solaris*)
186                 CFLAGS="$CFLAGS -Dinline="
187                 ;;
188         esac
189 fi
190 CFLAGS="$CFLAGS -g $WARN"
191
192 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
193 if test "x$PKG_CONFIG" = "xno"; then
194         AC_MSG_ERROR([You need to install pkg-config])
195 fi
196
197 dnl for use on the build system
198 dnl pkg-config is stupid
199 BUILD_GLIB_CFLAGS=`$PKG_CONFIG --cflags glib-2.0 gthread-2.0`
200 BUILD_GLIB_LIBS=`$PKG_CONFIG --libs glib-2.0 gthread-2.0`
201 AC_SUBST(BUILD_GLIB_CFLAGS)
202 AC_SUBST(BUILD_GLIB_LIBS)
203
204 PKG_PATH=
205 AC_ARG_WITH(crosspkgdir, [  --with-crosspkgdir=/path/to/pkg-config/dir],
206         if test x$with_crosspkgdir = "x"; then
207                 if test -s $PKG_CONFIG_PATH; then
208                         PKG_PATH=$PKG_CONFIG_PATH
209                 fi
210         else
211                 PKG_PATH=$with_crosspkgdir
212                 PKG_CONFIG_PATH=$PKG_PATH
213                 export PKG_CONFIG_PATH
214         fi
215 )
216
217 ## Versions of dependencies
218 GLIB_REQUIRED_VERSION=1.3.11
219
220 PKG_CHECK_MODULES(BASE_DEPENDENCIES, glib-2.0 >= $GLIB_REQUIRED_VERSION)
221
222 GLIB_CFLAGS=`$PKG_CONFIG --cflags glib-2.0 gthread-2.0`
223 GLIB_LIBS=`$PKG_CONFIG --libs glib-2.0 gthread-2.0`
224 GMODULE_CFLAGS=`$PKG_CONFIG --cflags gmodule-2.0`
225 GMODULE_LIBS=`$PKG_CONFIG --libs gmodule-2.0`
226
227 AC_SUBST(GLIB_CFLAGS)
228 AC_SUBST(GLIB_LIBS)
229 AC_SUBST(GMODULE_CFLAGS)
230 AC_SUBST(GMODULE_LIBS)
231
232 AC_ARG_WITH(gc, [  --with-gc=boehm,included,none],[gc=$with_gc],[gc=$gc_default])
233
234 # Enable support for NPTL only features like fast thread-local storage
235 # We can't reliably detect nptl at compile & run time
236 # so this option will stay until nptl becomes more widespread
237 AC_ARG_WITH(nptl, [  --with-nptl=yes,no      enable/disable support for NPTL],[],[with_nptl=yes])
238
239 # Enable support for using sigaltstack for SIGSEGV and stack overflow handling
240 # This does not work on some platforms (bug #55253)
241 AC_ARG_WITH(sigaltstack, [  --with-sigaltstack=yes,no      enable/disable support for sigaltstack],[],[with_sigaltstack=yes])
242
243 # assembly bundle support, see metadata/make-bundle.pl for more info
244 AC_ARG_WITH(bundle, [  --with-bundle=bundle_template],[
245         BUNDLE_FILE=$with_bundle
246         AC_SUBST(BUNDLE_FILE)
247         AC_DEFINE(WITH_BUNDLE)
248 ],[with_bundle=no])
249 AM_CONDITIONAL(WITH_BUNDLE, test x$with_bundle != xno)
250
251 LIBGC_CFLAGS=
252 LIBGC_LIBS=
253 libgc_dir=
254 case "x$gc" in
255         xboehm|xbohem|xyes)
256                 AC_CHECK_HEADERS(gc.h gc/gc.h, gc_headers=yes)
257                 AC_CHECK_LIB(gc, GC_malloc, found_boehm="yes",,$libdl)
258
259                 if test "x$found_boehm" != "xyes"; then
260                         AC_MSG_ERROR("GC requested but libgc not found! Install libgc or run configure with --with-gc=none.")
261                 fi
262                 if test "x$gc_headers" != "xyes"; then
263                         AC_MSG_ERROR("GC requested but header files not found! You may need to install them by hand.")
264                 fi
265
266                 AC_DEFINE(HAVE_BOEHM_GC)
267                 AC_SUBST(HAVE_BOEHM_GC)
268                 LIBGC_LIBS="-lgc $libdl"
269
270                 # AC_CHECK_FUNCS does not work for some reason...
271                 AC_CHECK_LIB(gc, GC_gcj_malloc, found_gcj_malloc="yes",,$libdl)
272                 if test "x$found_gcj_malloc" = "xyes"; then
273                         AC_DEFINE(HAVE_GC_GCJ_MALLOC)
274                 fi
275                 AC_CHECK_LIB(gc, GC_enable, found_gc_enable="yes",,$libdl)
276                 if test "x$found_gc_enable" = "xyes"; then
277                         AC_DEFINE(HAVE_GC_ENABLE)
278                 fi
279                 ;;
280
281         xincluded)
282                 AC_CONFIG_SUBDIRS(libgc)
283
284                 found_boehm=yes
285                 gc_headers=yes
286                 use_included_gc=yes
287                 libgc_dir=libgc
288
289                 LIBGC_CFLAGS='-I$(top_srcdir)/libgc/include'
290                 LIBGC_LIBS='$(top_builddir)/libgc/libmonogc.la'
291
292                 AC_DEFINE(HAVE_BOEHM_GC)
293                 AC_SUBST(HAVE_BOEHM_GC)
294
295                 AC_DEFINE(HAVE_GC_H)
296                 AC_DEFINE(USE_INCLUDED_LIBGC)
297
298                 # The included libgc contains GCJ support
299                 AC_DEFINE(HAVE_GC_GCJ_MALLOC)
300                 AC_DEFINE(HAVE_GC_ENABLE)
301                 ;;
302
303         xnone)
304                 AC_MSG_WARN("Compiling mono without GC.")
305                 ;;
306         *)
307                 AC_MSG_ERROR([Invalid argument to --with-gc.])
308                 ;;
309 esac
310
311 we_are_embedded_in_mono=yes
312 export we_are_embedded_in_mono
313 export libgc_threads
314
315 AM_CONDITIONAL(INCLUDED_LIBGC, test x$use_included_gc = xyes)
316 AC_SUBST(LIBGC_CFLAGS)
317 AC_SUBST(LIBGC_LIBS)
318 AC_SUBST(libgc_dir)
319
320 dnl
321 dnl End of libgc checks
322 dnl
323
324 if test x$platform_win32 = xno; then
325         AC_CHECK_FUNCS(getpwuid_r)
326         dnl ******************************************************************
327         dnl *** Check for large file support                               ***
328         dnl *** (If we were using autoconf 2.50 we'd use AC_SYS_LARGEFILE) ***
329         dnl ******************************************************************
330         
331         # Check that off_t can represent 2**63 - 1 correctly, working around
332         # potential compiler bugs.  Defines LARGE_FILE_SUPPORT, adds $1 to
333         # CPPFLAGS and sets $large_offt to yes if the test succeeds
334         large_offt=no
335         AC_DEFUN(LARGE_FILES, [
336                 large_CPPFLAGS=$CPPFLAGS
337                 CPPFLAGS="$CPPFLAGS $1"
338                 AC_TRY_RUN([
339                         #include <sys/types.h>
340
341                         #define BIG_OFF_T (((off_t)1<<62)-1+((off_t)1<<62))
342
343                         int main(void) {
344                                 int big_off_t=((BIG_OFF_T%2147483629==721) &&
345                                                (BIG_OFF_T%2147483647==1));
346                                 if(big_off_t) {
347                                         exit(0);
348                                 } else {
349                                         exit(1);
350                                 }
351                         }
352                 ], [
353                         AC_MSG_RESULT(ok)
354                         AC_DEFINE(HAVE_LARGE_FILE_SUPPORT)
355                         large_CPPFLAGS="$large_CPPFLAGS $1"
356                         large_offt=yes
357                 ], [
358                         AC_MSG_RESULT(no)
359                 ], "")
360                 CPPFLAGS=$large_CPPFLAGS
361         ])
362
363         AC_MSG_CHECKING(if off_t is 64 bits wide)
364         LARGE_FILES("")
365         if test $large_offt = no; then
366                 AC_MSG_CHECKING(if _FILE_OFFSET_BITS=64 gives 64 bit off_t)
367                 LARGE_FILES("-D_FILE_OFFSET_BITS=64")
368         fi
369         if test $large_offt = no; then
370                 AC_MSG_WARN([No 64 bit file size support available])
371         fi
372         
373         dnl *****************************
374         dnl *** Checks for libsocket  ***
375         dnl *****************************
376         AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
377
378         dnl *******************************
379         dnl *** Checks for MSG_NOSIGNAL ***
380         dnl *******************************
381         AC_MSG_CHECKING(for MSG_NOSIGNAL)
382         AC_TRY_COMPILE([#include <sys/socket.h>], [
383                 int f = MSG_NOSIGNAL;
384         ], [
385                 # Yes, we have it...
386                 AC_MSG_RESULT(yes)
387                 AC_DEFINE(HAVE_MSG_NOSIGNAL)
388         ], [
389                 # We'll have to use signals
390                 AC_MSG_RESULT(no)
391         ])
392
393         dnl *****************************
394         dnl *** Checks for SOL_IP     ***
395         dnl *****************************
396         AC_MSG_CHECKING(for SOL_IP)
397         AC_TRY_COMPILE([#include <netdb.h>], [
398                 int level = SOL_IP;
399         ], [
400                 # Yes, we have it...
401                 AC_MSG_RESULT(yes)
402                 AC_DEFINE(HAVE_SOL_IP)
403         ], [
404                 # We'll have to use getprotobyname
405                 AC_MSG_RESULT(no)
406         ])
407
408         dnl *****************************
409         dnl *** Checks for SOL_IPV6     ***
410         dnl *****************************
411         AC_MSG_CHECKING(for SOL_IPV6)
412         AC_TRY_COMPILE([#include <netdb.h>], [
413                 int level = SOL_IPV6;
414         ], [
415                 # Yes, we have it...
416                 AC_MSG_RESULT(yes)
417                 AC_DEFINE(HAVE_SOL_IPV6)
418         ], [
419                 # We'll have to use getprotobyname
420                 AC_MSG_RESULT(no)
421         ])
422
423         dnl *****************************
424         dnl *** Checks for SOL_TCP    ***
425         dnl *****************************
426         AC_MSG_CHECKING(for SOL_TCP)
427         AC_TRY_COMPILE([#include <netdb.h>], [
428                 int level = SOL_TCP;
429         ], [
430                 # Yes, we have it...
431                 AC_MSG_RESULT(yes)
432                 AC_DEFINE(HAVE_SOL_TCP)
433         ], [
434                 # We'll have to use getprotobyname
435                 AC_MSG_RESULT(no)
436         ])
437
438         dnl *****************************
439         dnl *** Checks for IP_PKTINFO ***
440         dnl *****************************
441         AC_MSG_CHECKING(for IP_PKTINFO)
442         AC_TRY_COMPILE([#include <netdb.h>], [
443                 int level = IP_PKTINFO;
444         ], [
445                 # Yes, we have it...
446                 AC_MSG_RESULT(yes)
447                 AC_DEFINE(HAVE_IP_PKTINFO)
448         ], [
449                 AC_MSG_RESULT(no)
450         ])
451
452         dnl *********************************
453         dnl *** Check for struct ip_mreqn ***
454         dnl *********************************
455         AC_MSG_CHECKING(for struct ip_mreqn)
456         AC_TRY_COMPILE([#include <netinet/in.h>], [
457                 struct ip_mreqn mreq;
458                 mreq.imr_address.s_addr = 0;
459         ], [
460                 # Yes, we have it...
461                 AC_MSG_RESULT(yes)
462                 AC_DEFINE(HAVE_STRUCT_IP_MREQN)
463         ], [
464                 # We'll just have to try and use struct ip_mreq
465                 AC_MSG_RESULT(no)
466                 AC_MSG_CHECKING(for struct ip_mreq)
467                 AC_TRY_COMPILE([#include <netinet/in.h>], [
468                         struct ip_mreq mreq;
469                         mreq.imr_interface.s_addr = 0;
470                 ], [
471                         # Yes, we have it...
472                         AC_MSG_RESULT(yes)
473                         AC_DEFINE(HAVE_STRUCT_IP_MREQ)
474                 ], [
475                         # No multicast support
476                         AC_MSG_RESULT(no)
477                 ])
478         ])
479         
480         dnl **********************************
481         dnl *** Check for gethostbyname2_r ***
482         dnl **********************************
483         AC_MSG_CHECKING(for gethostbyname2_r)
484                 AC_TRY_LINK([#include <netdb.h>], [
485                 gethostbyname2_r(NULL,0,NULL,NULL,0,NULL,NULL);
486         ], [
487                 # Yes, we have it...
488                 AC_MSG_RESULT(yes)
489                 AC_DEFINE(HAVE_GETHOSTBYNAME2_R)
490         ], [
491                 AC_MSG_RESULT(no)
492         ])
493
494         dnl *****************************
495         dnl *** Checks for libnsl     ***
496         dnl *****************************
497         AC_CHECK_LIB(nsl, gethostbyaddr, LIBS="$LIBS -lnsl")
498
499         AC_CHECK_FUNCS(inet_pton inet_aton)
500
501         dnl ***********************************************
502         dnl *** Checks for size of sockaddr_un.sun_path ***
503         dnl ***********************************************
504         # AC_CHECK_SIZEOF can't cope with struct members :-(
505         AC_MSG_CHECKING(size of sockaddr_un.sun_path)
506         AC_CACHE_VAL(cv_mono_sizeof_sunpath,
507                 [AC_TRY_RUN([
508                         #include <sys/types.h>
509                         #include <stdio.h>
510                         #include <sys/un.h>
511
512                         int main(void) {
513                                 struct sockaddr_un sock_un;
514                                 FILE *f=fopen("conftestval", "w");
515                                 if(!f) exit(1);
516                                 fprintf(f, "%d\n", sizeof(sock_un.sun_path));
517                                 exit(0);
518                         }
519                 ], cv_mono_sizeof_sunpath=`cat conftestval`,
520                    cv_mono_sizeof_sunpath=0,
521                    cv_mono_sizeof_sunpath=0)])dnl
522         AC_MSG_RESULT($cv_mono_sizeof_sunpath)
523         AC_DEFINE_UNQUOTED(MONO_SIZEOF_SUNPATH, $cv_mono_sizeof_sunpath)
524
525         dnl *************************************
526         dnl *** Checks for zero length arrays ***
527         dnl *************************************
528         AC_MSG_CHECKING(whether $CC supports zero length arrays)
529         AC_TRY_COMPILE([
530                 struct s {
531                         int  length;
532                         char data [0];
533                 };
534         ], [], [
535                 AC_MSG_RESULT(yes)
536                 AC_DEFINE_UNQUOTED(MONO_ZERO_ARRAY_LENGTH, 0)
537         ], [
538                 AC_MSG_RESULT(no)
539                 AC_DEFINE_UNQUOTED(MONO_ZERO_ARRAY_LENGTH, 1)
540         ])
541
542         dnl *****************************
543         dnl *** Checks for libxnet    ***
544         dnl *****************************
545         case "${host}" in
546                 *solaris* )
547                         AC_MSG_CHECKING(for Solaris XPG4 support)
548                         if test -f /usr/lib/libxnet.so; then
549                                 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=500"
550                                 CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__"
551                                 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE_EXTENDED=1"
552                                 LIBS="$LIBS -lxnet"
553                                 AC_MSG_RESULT(yes)
554                         else
555                                 AC_MSG_RESULT(no)
556                         fi
557
558                         if test "$GCC" = "yes"; then
559                                 CFLAGS="$CFLAGS -Wno-char-subscripts"
560                         fi
561                 ;;
562         esac
563
564         dnl *****************************
565         dnl *** Checks for libpthread ***
566         dnl *****************************
567         AC_CHECK_LIB(pthread, main, LIBS="$LIBS -lpthread")
568         AC_CHECK_HEADERS(pthread.h)
569         AC_CHECK_FUNCS(pthread_mutex_timedlock)
570         AC_MSG_CHECKING(for PTHREAD_MUTEX_RECURSIVE)
571         AC_TRY_COMPILE([ #include <pthread.h>], [
572                 pthread_mutexattr_t attr;
573                 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
574         ], [
575                 AC_MSG_RESULT(ok)
576         ], [
577                 AC_MSG_RESULT(no)
578                 AC_MSG_WARN(Using mono_mutex_t for recursive mutexes)
579                 AC_DEFINE(USE_MONO_MUTEX)
580         ])
581         AC_CHECK_FUNCS(pthread_attr_setstacksize)
582
583         dnl ***********************************
584         dnl *** Checks for working __thread ***
585         dnl ***********************************
586         AC_MSG_CHECKING(for working __thread)
587         AC_TRY_RUN([
588                 #include <pthread.h>
589
590                 __thread int i;
591                 static int res1, res2;
592
593                 void thread_main (void *arg)
594                 {
595                         i = arg;
596                         sleep (1);
597                         if (arg == 1)
598                                 res1 = (i == arg);
599                         else
600                                 res2 = (i == arg);
601                 }
602
603                 int main () {
604                         pthread_t t1, t2;
605
606                         i = 5;
607
608                         pthread_create (&t1, NULL, thread_main, 1);
609                         pthread_create (&t2, NULL, thread_main, 2);
610
611                         pthread_join (t1, NULL);
612                         pthread_join (t2, NULL);
613
614                         return !(res1 + res2 == 2);
615                 }
616         ], [
617                         if test "x$with_nptl" != "xyes"; then
618                                 AC_MSG_RESULT(disabled)
619                         else
620                                 AC_MSG_RESULT(yes)
621                                 AC_DEFINE(HAVE_KW_THREAD)
622                         fi
623         ], [
624                         AC_MSG_RESULT(no)
625         ])
626
627         dnl **************************************
628         dnl *** Checks for working sigaltstack ***
629         dnl **************************************
630         AC_MSG_CHECKING(for working sigaltstack)
631         AC_TRY_RUN([
632                 #include <stdio.h>
633                 #include <stdlib.h>
634                 #include <unistd.h>
635                 #include <signal.h>
636                 #include <pthread.h>
637                 #include <sys/wait.h>
638
639                 static void
640                 sigsegv_signal_handler (int _dummy, siginfo_t *info, void *context)
641                 {
642                         exit (0);
643                 }
644
645                 static void *
646                 loop (void *ignored)
647                 {
648                         char *ptr = NULL;
649
650                         *ptr = 0;
651                         return NULL;
652                 }
653
654                 static void
655                 child ()
656                 {
657                         struct sigaction sa;
658                         struct sigaltstack sas;
659                         pthread_t id;
660                         pthread_attr_t attr;
661
662                         sa.sa_sigaction = sigsegv_signal_handler;
663                         sigemptyset (&sa.sa_mask);
664                         sa.sa_flags = SA_SIGINFO | SA_STACK;
665                         if (sigaction (SIGSEGV, &sa, NULL) == -1) {
666                                 perror ("lala");
667                                 return;
668                         }
669
670                         sas.ss_sp = malloc (SIGSTKSZ);
671                         sas.ss_size = SIGSTKSZ;
672                         sas.ss_flags = SS_ONSTACK;
673                         if (sigaltstack (&sas, NULL) == -1) {
674                                 perror ("lala");
675                                 return;
676                         }
677
678                         pthread_attr_init (&attr);
679                         if (pthread_create(&id, &attr, loop, &attr) != 0) {
680                                 printf ("failed\n");
681                                 return;
682                         }
683
684                         sleep (100);
685                 }
686
687                 int
688                 main ()
689                 {
690                         pid_t son;
691                         int status;
692                         int i;
693
694                         son = fork ();
695                         if (son == -1) {
696                                 return 1;
697                         }
698
699                         if (son == 0) {
700                                 child ();
701                                 return 0;
702                         }
703
704                         for (i = 0; i < 3; ++i) {
705                                 sleep (1);
706                                 waitpid (son, &status, WNOHANG);
707                                 if (WIFEXITED (status) && WEXITSTATUS (status) == 0)
708                                         return 0;
709                         }
710
711                         kill (son, SIGKILL);
712                         return 1;
713                 }
714
715         ], [
716                         if test "x$with_sigaltstack" != "xyes"; then
717                                 AC_MSG_RESULT(disabled)
718                         else
719                                 AC_MSG_RESULT(yes)
720                                 AC_DEFINE(HAVE_WORKING_SIGALTSTACK)
721                         fi
722         ], [
723                         with_sigaltstack=no
724                         AC_MSG_RESULT(no)
725         ])
726
727         dnl ********************************
728         dnl *** Checks for semaphore lib ***
729         dnl ********************************
730         # 'Real Time' functions on Solaris
731         # posix4 on Solaris 2.6
732         # pthread (first!) on Linux
733         AC_SEARCH_LIBS(sem_init, pthread rt posix4) 
734
735         dnl ********************************
736         dnl *** Checks for timezone stuff **
737         dnl ********************************
738         AC_CACHE_CHECK(for tm_gmtoff in struct tm, ac_cv_struct_tm_gmtoff,
739                 AC_TRY_COMPILE([
740                         #include <time.h>
741                         ], [
742                         struct tm tm;
743                         tm.tm_gmtoff = 1;
744                         ], ac_cv_struct_tm_gmtoff=yes, ac_cv_struct_tm_gmtoff=no))
745         if test $ac_cv_struct_tm_gmtoff = yes; then
746                 AC_DEFINE(HAVE_TM_GMTOFF)
747         else
748                 AC_CACHE_CHECK(for timezone variable, ac_cv_var_timezone,
749                         AC_TRY_COMPILE([
750                                 #include <time.h>
751                         ], [
752                                 timezone = 1;
753                         ], ac_cv_var_timezone=yes, ac_cv_var_timezone=no))
754                 if test $ac_cv_var_timezone = yes; then
755                         AC_DEFINE(HAVE_TIMEZONE)
756                 else
757                         AC_ERROR(unable to find a way to determine timezone)
758                 fi
759         fi
760
761         dnl *********************************
762         dnl *** Checks for math functions ***
763         dnl *********************************
764         LIBS="$LIBS -lm";
765         AC_CHECK_FUNCS(finite, , AC_MSG_CHECKING(for finite in math.h)
766                 AC_TRY_LINK([#include <math.h>], 
767                 [ finite(0.0); ], 
768                 AC_DEFINE(HAVE_FINITE) AC_MSG_RESULT(yes),
769                 AC_MSG_RESULT(no)))
770         AC_CHECK_FUNCS(isfinite, , AC_MSG_CHECKING(for isfinite in math.h)
771                 AC_TRY_LINK([#include <math.h>], 
772                 [ isfinite(0.0); ], 
773                 AC_DEFINE(HAVE_ISFINITE) AC_MSG_RESULT(yes),
774                 AC_MSG_RESULT(no)))
775
776         dnl ****************************************************************
777         dnl *** Checks for working poll() (macosx defines it but doesn't ***
778         dnl *** have it in the library (duh))                            ***
779         dnl ****************************************************************
780         AC_CHECK_FUNCS(poll)
781
782         dnl *************************
783         dnl *** Check for signbit ***
784         dnl *************************
785         AC_MSG_CHECKING(for signbit)
786         AC_TRY_LINK([#include <math.h>], [
787                 int s = signbit(1.0);
788         ], [
789                 AC_MSG_RESULT(yes)
790                 AC_DEFINE(HAVE_SIGNBIT)
791         ], [
792                 AC_MSG_RESULT(no)
793         ]) 
794
795         dnl *********************
796         dnl *** Check for AIO ***
797         dnl *********************
798         AC_CHECK_HEADERS(aio.h)
799         AC_CHECK_LIB(rt, aio_read, [ LIBS="$LIBS -lrt" ],)
800 else
801         AC_CHECK_LIB(ws2_32, main, LIBS="$LIBS -lws2_32", AC_ERROR(bad mingw install?))
802         AC_CHECK_LIB(psapi, main, LIBS="$LIBS -lpsapi", AC_ERROR(bad mingw install?))
803 fi
804
805 dnl socklen_t check
806 AC_MSG_CHECKING(for socklen_t)
807 AC_TRY_COMPILE([
808 #include <sys/types.h>
809 #include <sys/socket.h>
810 ],[
811   socklen_t foo;
812 ],[
813 ac_cv_c_socklen_t=yes
814         AC_DEFINE(HAVE_SOCKLEN_T)
815         AC_MSG_RESULT(yes)
816 ],[
817         AC_MSG_RESULT(no)
818 ])
819
820 AC_CHECK_FUNCS(truncl, , AC_MSG_CHECKING(for truncl in math.h)
821         AC_TRY_LINK([#include <math.h>], 
822         [ truncl(0.0); ], 
823         [
824                 AC_DEFINE(HAVE_TRUNCL) 
825                 AC_MSG_RESULT(yes)
826                 ac_cv_truncl=yes
827         ],
828         AC_MSG_RESULT(no)))
829
830 if test "x$ac_cv_truncl" != "xyes"; then
831    AC_CHECK_LIB(sunmath, aintl, [ AC_DEFINE(HAVE_AINTL) LIBS="$LIBS -lsunmath"])
832 fi
833
834 dnl ****************************
835 dnl *** Look for /dev/random ***
836 dnl ****************************
837
838 AC_MSG_CHECKING([if usage of random device is requested])
839 AC_ARG_ENABLE(dev-random,
840 [  --disable-dev-random    disable the use of the random device],
841 try_dev_random=$enableval, try_dev_random=yes)
842 AC_MSG_RESULT($try_dev_random)
843
844 case "{$target}" in
845     *-openbsd*)
846     NAME_DEV_RANDOM="/dev/srandom"
847     ;;
848
849 dnl Win32 does not have /dev/random, they have their own method...
850
851     *-*-mingw*|*-*-cygwin*)
852     ac_cv_have_dev_random = no
853     ;;
854
855 dnl Everywhere else, it's /dev/random
856
857     *)
858     NAME_DEV_RANDOM="/dev/random"
859     ;;
860 esac
861
862 AC_DEFINE_UNQUOTED(NAME_DEV_RANDOM, "$NAME_DEV_RANDOM")
863
864 dnl Now check if the device actually exists
865
866 if test "x$try_dev_random" = "xyes"; then
867     AC_CACHE_CHECK(for random device, ac_cv_have_dev_random,
868     [if test -r "$NAME_DEV_RANDOM" ; then
869         ac_cv_have_dev_random=yes; else ac_cv_have_dev_random=no; fi])
870     if test "x$ac_cv_have_dev_random" = "xyes"; then
871         AC_DEFINE(HAVE_CRYPT_RNG)
872     fi
873 else
874     AC_MSG_CHECKING(for random device)
875     ac_cv_have_dev_random=no
876     AC_MSG_RESULT(has been disabled)
877 fi
878
879 if test "x$platform_win32" = "xyes"; then
880     AC_DEFINE(HAVE_CRYPT_RNG)
881 fi
882
883 if test "x$ac_cv_have_dev_random" = "xno" \
884     && test "x$platform_win32" = "xno"; then
885     AC_MSG_WARN([[
886 ***
887 *** A system-provided entropy source was not found on this system.
888 *** Because of this, the System.Security.Cryptography random number generator
889 *** will throw a NotImplemented exception.
890 ***
891 *** If you are seeing this message, and you know your system DOES have an
892 *** entropy collection in place, please contact <crichton@gimp.org> and
893 *** provide information about the system and how to access the random device.
894 ***
895 *** For those systems who lack a random device, EGD support is forthcoming.
896 ***]])
897 fi
898  
899 AC_MSG_CHECKING([if inter-process shared handles are requested])
900 AC_ARG_ENABLE(shared-handles, [  --disable-shared-handles disable inter-process shared handles], try_shared_handles=$enableval, try_shared_handles=yes)
901 AC_MSG_RESULT($try_shared_handles)
902 if test "x$try_shared_handles" != "xyes"; then
903         AC_DEFINE(DISABLE_SHARED_HANDLES)
904         AC_SUBST(DISABLE_SHARED_HANDLES)
905 fi
906
907 ICU_CFLAGS=""
908 ICU_LIBS=""
909 enable_icu=no
910 AC_PATH_PROG(ICU_CONFIG, icu-config, no)
911 if test "x$ICU_CONFIG" = "xno" -o ! -x "$ICU_CONFIG"; then
912         AC_MSG_WARN([Only invariant locale available; install ICU for I18N support])
913         enable_icu="no, if you want full i18n support download it from: http://oss.software.ibm.com/icu/index.html"
914 else
915         enable_icu="yes. Version: `$ICU_CONFIG --version`"
916         AC_DEFINE(HAVE_ICU)
917         ICU_CFLAGS=`$ICU_CONFIG --cppflags`
918         ICU_LIBS=`$ICU_CONFIG --ldflags`
919 fi
920 AC_SUBST(ICU_CFLAGS)
921 AC_SUBST(ICU_LIBS)
922
923 TARGET="unknown"
924 ACCESS_UNALIGNED="yes"
925
926 JIT_SUPPORTED=no
927 LIBC="libc.so.6"
928
929 jit_wanted=false
930 case "$host" in
931 #       mips-sgi-irix5.* | mips-sgi-irix6.*)
932 #               TARGET=MIPS;
933 #               ACCESS_UNALIGNED="no"
934 #               ;;
935         i*86-*-*)
936                 TARGET=X86;
937                 arch_target=x86;
938                 JIT_SUPPORTED=yes
939                 jit_wanted=true
940                 ;;
941         x86_64-*-* | amd64-*-*)
942                 TARGET=AMD64;
943                 arch_target=amd64;
944                 JIT_SUPPORTED=no
945                 ;;
946         sparc*-*-*)
947                 TARGET=SPARC;
948                 arch_target=sparc;
949                 JIT_SUPPORTED=yes
950                 ACCESS_UNALIGNED="no"
951                 jit_wanted=true
952                 ;;
953 #       alpha*-*-linux* | alpha*-*-osf*)
954 #               TARGET=ALPHA;
955 #               ACCESS_UNALIGNED="no"
956 #              ;;
957 #       ia64-*-linux* | ia64-*-hpux*)
958 #               TARGET=IA64;
959 #               arch_target=ia64;
960 #               JIT_SUPPORTED=no;
961 #               ACCESS_UNALIGNED="no";
962 #               case "$host_os" in
963 #                       linux*) LIBC="libc.so.6.1";;
964 #                       hpux*)  LIBC="libc.so.1";;
965 #               esac
966 #               ;;
967 #       m68k-*-linux*)
968 #               TARGET=M68K
969 #               ;;
970         hppa2.0w-hp-hpux11.00 | hppa64-hp-hpux11.00)
971                 TARGET=HPPA;
972                 arch_target=hppa; 
973                 ACCESS_UNALIGNED="no"
974                 ;;
975         macppc-*-openbsd* | powerpc-*-linux* | powerpc-*-openbsd* | \
976         powerpc-*-sysv* | powerpc-*-darwin*)
977                 TARGET=POWERPC;
978                 arch_target=ppc;
979                 JIT_SUPPORTED=yes
980                 ;;
981         arm-*-linux-* | armv4l-*-linux-*)
982                 TARGET=ARM;
983                 arch_target=arm;
984                 ACCESS_UNALIGNED="no"
985                 ;;
986         s390-*-linux*)
987                 TARGET=S390;
988                 arch_target=s390;
989                 ACCESS_UNALIGNED="no"
990                 ;;
991 esac
992
993 AC_ARG_WITH(jit, [  --with-jit=yes,no    If you want to build scripts that default to the JIT],[
994         jit_wanted=true
995 ])
996
997 USEJIT=false
998 if test x$JIT_SUPPORTED = xyes; then
999    if $jit_wanted; then
1000       USEJIT=true
1001       jit_status="Building and using the JIT"
1002    else
1003       jit_status="Building the JIT, defaulting to the interpreter"
1004    fi
1005 else
1006    jit_status="interpreter"
1007 fi
1008
1009 AM_CONDITIONAL(USE_JIT, test x$USEJIT = xtrue)
1010
1011 libsuffix=".so"
1012
1013 case "$host" in
1014      powerpc-*-darwin*)
1015         libsuffix=".dylib"
1016         ;;
1017 esac
1018 AC_SUBST(libsuffix)
1019
1020 if test ${TARGET} = ARM; then
1021         dnl ******************************************
1022         dnl *** Check to see what FPU is available ***
1023         dnl ******************************************
1024         AC_MSG_CHECKING(which FPU to use)
1025
1026         AC_TRY_COMPILE([], [
1027                 __asm__ ("ldfd f0, [r0]");
1028                 ], fpu=FPA, [
1029                         AC_TRY_COMPILE([], [
1030                                 __asm__ ("fldd d0, [r0]");
1031                         ], fpu=VFP, fpu=NONE)
1032                 ])
1033
1034         AC_MSG_RESULT($fpu)
1035         CPPFLAGS="$CPPFLAGS -DARM_FPU_$fpu"
1036         unset fpu
1037 fi
1038
1039 if test ${TARGET} = unknown; then
1040         CPPFLAGS="$CPPFLAGS -DNO_PORT"
1041         AC_MSG_WARN("mono has not been ported to $host: some things may not work.")
1042 fi
1043
1044 if test ${ACCESS_UNALIGNED} = no; then
1045         CPPFLAGS="$CPPFLAGS -DNO_UNALIGNED_ACCESS"
1046 fi
1047
1048 AM_CONDITIONAL(MIPS_GCC, test ${TARGET}${ac_cv_prog_gcc} = MIPSyes)
1049 AM_CONDITIONAL(MIPS_SGI, test ${TARGET}${ac_cv_prog_gcc} = MIPSno)
1050 AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
1051 AM_CONDITIONAL(X86, test x$TARGET = xX86)
1052 AM_CONDITIONAL(AMD64, test x$TARGET = xAMD64)
1053 AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
1054 AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
1055 AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
1056 AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
1057 AM_CONDITIONAL(ARM, test x$TARGET = xARM)
1058 AM_CONDITIONAL(S390, test x$TARGET = xS390)
1059 AM_CONDITIONAL(HPPA, test x$TARGET = xHPPA)
1060
1061 AM_CONDITIONAL(JIT_SUPPORTED, test x$JIT_SUPPORTED = xyes)
1062
1063 AC_SUBST(LIBC)
1064
1065 AC_SUBST(arch_target)
1066 AC_SUBST(CFLAGS)
1067 AC_SUBST(CPPFLAGS)
1068 AC_SUBST(LDFLAGS)
1069
1070 AC_OUTPUT([
1071 Makefile
1072 mint.pc
1073 mono.pc
1074 mono/Makefile
1075 mono/utils/Makefile
1076 mono/metadata/Makefile
1077 mono/dis/Makefile
1078 mono/cil/Makefile
1079 mono/arch/Makefile
1080 mono/os/Makefile
1081 mono/os/win32/Makefile
1082 mono/os/unix/Makefile
1083 mono/arch/x86/Makefile
1084 mono/arch/amd64/Makefile
1085 mono/arch/hppa/Makefile
1086 mono/arch/ppc/Makefile
1087 mono/arch/sparc/Makefile
1088 mono/arch/s390/Makefile
1089 mono/arch/arm/Makefile
1090 mono/arch/alpha/Makefile
1091 mono/interpreter/Makefile
1092 mono/tests/Makefile
1093 mono/tests/tests-config
1094 mono/benchmark/Makefile
1095 mono/monoburg/Makefile
1096 mono/monograph/Makefile
1097 mono/io-layer/Makefile
1098 mono/handles/Makefile
1099 mono/mini/Makefile
1100 mono/profiler/Makefile
1101 runtime/Makefile
1102 scripts/Makefile
1103 man/Makefile
1104 web/Makefile
1105 docs/Makefile
1106 data/Makefile
1107 samples/Makefile
1108 support/Makefile
1109 data/config
1110 mono.spec
1111 ])
1112
1113 echo "
1114
1115         GC:          $gc
1116         ICU:         $enable_icu
1117         NPTL:        $with_nptl
1118         SIGALTSTACK: $with_sigaltstack
1119         Engine:      $jit_status
1120         
1121 "