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