2004-04-29 Martin Baulig <martin@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 AC_CHECK_TOOL(CC, gcc, gcc)
119 AC_PROG_CC
120 AM_PROG_CC_STDC
121 AC_PROG_INSTALL
122 dnl We should use AM_PROG_AS, but it's not available on automake/aclocal 1.4
123 : ${CCAS='$(CC)'}
124 # Set ASFLAGS if not already set.
125 : ${CCASFLAGS='$(CFLAGS)'}
126 AC_SUBST(CCAS)
127 AC_SUBST(CCASFLAGS)
128
129 AC_CHECK_PROG(BISON, bison,yes,no)
130 if test "x$BISON" = "xno";
131 then
132         AC_MSG_ERROR([You need to install bison])
133 fi
134
135 dnl may require a specific autoconf version
136 dnl AC_PROG_CC_FOR_BUILD
137 dnl CC_FOR_BUILD not automatically detected
138 CC_FOR_BUILD=$CC
139 BUILD_EXEEXT=
140 if test "x$cross_compiling" = "xyes"; then
141         CC_FOR_BUILD=cc
142         BUILD_EXEEXT=""
143 fi
144 AC_SUBST(CC_FOR_BUILD)
145 AC_SUBST(HOST_CC)
146 AC_SUBST(BUILD_EXEEXT)
147
148 # Set STDC_HEADERS
149 AC_HEADER_STDC
150 AC_LIBTOOL_WIN32_DLL
151 AM_PROG_LIBTOOL
152
153 # Test whenever ld supports -version-script
154 AC_PROG_LD
155 AC_PROG_LD_GNU
156 if test "x$lt_cv_prog_gnu_ld" = "xno"; then
157    no_version_script=yes
158 fi
159
160 AM_CONDITIONAL(NO_VERSION_SCRIPT, test x$no_version_script = xyes)
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
326         dnl ******************************************************************
327         dnl *** Checks for the IKVM JNI interface library                  ***
328         dnl ******************************************************************
329         AC_ARG_WITH(ikvm-jni, [  --with-ikvm-jni=yes,no  build the IKVM JNI interface library],[with_ikvm_jni=$withval],[with_ikvm_jni=yes])
330         AC_ARG_WITH(jdk, [  --with-jdk=DIRECTORY    Use JDK from DIRECTORY],[with_jdk_dir=$withval],[with_jdk_dir=])
331
332         ikvm_jni_dir=
333         if test x$with_ikvm_jni = xyes; then
334                 AC_MSG_CHECKING([JDK headers])
335
336                 if test x$with_jdk_dir = x; then
337                         # Try JAVA_HOME variable
338                         if test x$JAVA_HOME != x; then
339                                 with_jdk_dir=$JAVA_HOME
340                         fi
341                 fi
342         
343                 jdk_platform=
344                 if test -d $with_jdk_dir/include; then
345                         jdk_headers_found=yes
346
347                         if test -d $with_jdk_dir/include/linux; then
348                                 jdk_platform=linux
349                         else
350                         if test -d $with_jdk_dir/include/solaris; then
351                                 jdk_platform=solaris
352                         else
353                                 jdk_headers_found=no
354                         fi
355                         fi
356                 else
357                         jdk_headers_found=no
358                 fi
359
360                 if test x$jdk_headers_found = xyes; then
361                         AC_MSG_RESULT($with_jdk_dir/include $with_jdk_dir/include/$jdk_platform)
362                 else
363                         AC_MSG_RESULT(not found)
364                 fi
365
366                 if test x$jdk_headers_found = xyes; then
367                         ikvm_jni_dir=ikvm-jni
368                         IKVM_JNI_CFLAGS="-I$with_jdk_dir/include -I$with_jdk_dir/include/$jdk_platform"
369                 fi
370         fi
371
372         AC_SUBST(ikvm_jni_dir)
373         AC_SUBST(IKVM_JNI_CFLAGS)
374
375         AC_CHECK_FUNCS(getgrgid_r)
376         AC_CHECK_FUNCS(getgrnam_r)
377         AC_CHECK_FUNCS(getpwnam_r)
378         AC_CHECK_FUNCS(getpwuid_r)
379         AC_CHECK_FUNCS(getresuid)
380         AC_CHECK_FUNCS(setresuid)
381
382         dnl ******************************************************************
383         dnl *** Check for large file support                               ***
384         dnl *** (If we were using autoconf 2.50 we'd use AC_SYS_LARGEFILE) ***
385         dnl ******************************************************************
386         
387         # Check that off_t can represent 2**63 - 1 correctly, working around
388         # potential compiler bugs.  Defines LARGE_FILE_SUPPORT, adds $1 to
389         # CPPFLAGS and sets $large_offt to yes if the test succeeds
390         large_offt=no
391         AC_DEFUN(LARGE_FILES, [
392                 large_CPPFLAGS=$CPPFLAGS
393                 CPPFLAGS="$CPPFLAGS $1"
394                 AC_TRY_RUN([
395                         #include <sys/types.h>
396
397                         #define BIG_OFF_T (((off_t)1<<62)-1+((off_t)1<<62))
398
399                         int main(void) {
400                                 int big_off_t=((BIG_OFF_T%2147483629==721) &&
401                                                (BIG_OFF_T%2147483647==1));
402                                 if(big_off_t) {
403                                         exit(0);
404                                 } else {
405                                         exit(1);
406                                 }
407                         }
408                 ], [
409                         AC_MSG_RESULT(ok)
410                         AC_DEFINE(HAVE_LARGE_FILE_SUPPORT)
411                         large_CPPFLAGS="$large_CPPFLAGS $1"
412                         large_offt=yes
413                 ], [
414                         AC_MSG_RESULT(no)
415                 ], "")
416                 CPPFLAGS=$large_CPPFLAGS
417         ])
418
419         AC_MSG_CHECKING(if off_t is 64 bits wide)
420         LARGE_FILES("")
421         if test $large_offt = no; then
422                 AC_MSG_CHECKING(if _FILE_OFFSET_BITS=64 gives 64 bit off_t)
423                 LARGE_FILES("-D_FILE_OFFSET_BITS=64")
424         fi
425         if test $large_offt = no; then
426                 AC_MSG_WARN([No 64 bit file size support available])
427         fi
428         
429         dnl *****************************
430         dnl *** Checks for libsocket  ***
431         dnl *****************************
432         AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
433
434         dnl *******************************
435         dnl *** Checks for MSG_NOSIGNAL ***
436         dnl *******************************
437         AC_MSG_CHECKING(for MSG_NOSIGNAL)
438         AC_TRY_COMPILE([#include <sys/socket.h>], [
439                 int f = MSG_NOSIGNAL;
440         ], [
441                 # Yes, we have it...
442                 AC_MSG_RESULT(yes)
443                 AC_DEFINE(HAVE_MSG_NOSIGNAL)
444         ], [
445                 # We'll have to use signals
446                 AC_MSG_RESULT(no)
447         ])
448
449         dnl *****************************
450         dnl *** Checks for SOL_IP     ***
451         dnl *****************************
452         AC_MSG_CHECKING(for SOL_IP)
453         AC_TRY_COMPILE([#include <netdb.h>], [
454                 int level = SOL_IP;
455         ], [
456                 # Yes, we have it...
457                 AC_MSG_RESULT(yes)
458                 AC_DEFINE(HAVE_SOL_IP)
459         ], [
460                 # We'll have to use getprotobyname
461                 AC_MSG_RESULT(no)
462         ])
463
464         dnl *****************************
465         dnl *** Checks for SOL_IPV6     ***
466         dnl *****************************
467         AC_MSG_CHECKING(for SOL_IPV6)
468         AC_TRY_COMPILE([#include <netdb.h>], [
469                 int level = SOL_IPV6;
470         ], [
471                 # Yes, we have it...
472                 AC_MSG_RESULT(yes)
473                 AC_DEFINE(HAVE_SOL_IPV6)
474         ], [
475                 # We'll have to use getprotobyname
476                 AC_MSG_RESULT(no)
477         ])
478
479         dnl *****************************
480         dnl *** Checks for SOL_TCP    ***
481         dnl *****************************
482         AC_MSG_CHECKING(for SOL_TCP)
483         AC_TRY_COMPILE([#include <netdb.h>], [
484                 int level = SOL_TCP;
485         ], [
486                 # Yes, we have it...
487                 AC_MSG_RESULT(yes)
488                 AC_DEFINE(HAVE_SOL_TCP)
489         ], [
490                 # We'll have to use getprotobyname
491                 AC_MSG_RESULT(no)
492         ])
493
494         dnl *****************************
495         dnl *** Checks for IP_PKTINFO ***
496         dnl *****************************
497         AC_MSG_CHECKING(for IP_PKTINFO)
498         AC_TRY_COMPILE([#include <netdb.h>], [
499                 int level = IP_PKTINFO;
500         ], [
501                 # Yes, we have it...
502                 AC_MSG_RESULT(yes)
503                 AC_DEFINE(HAVE_IP_PKTINFO)
504         ], [
505                 AC_MSG_RESULT(no)
506         ])
507
508         dnl *********************************
509         dnl *** Check for struct ip_mreqn ***
510         dnl *********************************
511         AC_MSG_CHECKING(for struct ip_mreqn)
512         AC_TRY_COMPILE([#include <netinet/in.h>], [
513                 struct ip_mreqn mreq;
514                 mreq.imr_address.s_addr = 0;
515         ], [
516                 # Yes, we have it...
517                 AC_MSG_RESULT(yes)
518                 AC_DEFINE(HAVE_STRUCT_IP_MREQN)
519         ], [
520                 # We'll just have to try and use struct ip_mreq
521                 AC_MSG_RESULT(no)
522                 AC_MSG_CHECKING(for struct ip_mreq)
523                 AC_TRY_COMPILE([#include <netinet/in.h>], [
524                         struct ip_mreq mreq;
525                         mreq.imr_interface.s_addr = 0;
526                 ], [
527                         # Yes, we have it...
528                         AC_MSG_RESULT(yes)
529                         AC_DEFINE(HAVE_STRUCT_IP_MREQ)
530                 ], [
531                         # No multicast support
532                         AC_MSG_RESULT(no)
533                 ])
534         ])
535         
536         dnl **********************************
537         dnl *** Check for gethostbyname2_r ***
538         dnl **********************************
539         AC_MSG_CHECKING(for gethostbyname2_r)
540                 AC_TRY_LINK([#include <netdb.h>], [
541                 gethostbyname2_r(NULL,0,NULL,NULL,0,NULL,NULL);
542         ], [
543                 # Yes, we have it...
544                 AC_MSG_RESULT(yes)
545                 AC_DEFINE(HAVE_GETHOSTBYNAME2_R)
546         ], [
547                 AC_MSG_RESULT(no)
548         ])
549
550         dnl *****************************
551         dnl *** Checks for libnsl     ***
552         dnl *****************************
553         AC_CHECK_LIB(nsl, gethostbyaddr, LIBS="$LIBS -lnsl")
554
555         AC_CHECK_FUNCS(inet_pton inet_aton)
556
557         dnl ***********************************************
558         dnl *** Checks for size of sockaddr_un.sun_path ***
559         dnl ***********************************************
560         # AC_CHECK_SIZEOF can't cope with struct members :-(
561         AC_MSG_CHECKING(size of sockaddr_un.sun_path)
562         AC_CACHE_VAL(cv_mono_sizeof_sunpath,
563                 [AC_TRY_RUN([
564                         #include <sys/types.h>
565                         #include <stdio.h>
566                         #include <sys/un.h>
567
568                         int main(void) {
569                                 struct sockaddr_un sock_un;
570                                 FILE *f=fopen("conftestval", "w");
571                                 if(!f) exit(1);
572                                 fprintf(f, "%d\n", sizeof(sock_un.sun_path));
573                                 exit(0);
574                         }
575                 ], cv_mono_sizeof_sunpath=`cat conftestval`,
576                    cv_mono_sizeof_sunpath=0,
577                    cv_mono_sizeof_sunpath=0)])dnl
578         AC_MSG_RESULT($cv_mono_sizeof_sunpath)
579         AC_DEFINE_UNQUOTED(MONO_SIZEOF_SUNPATH, $cv_mono_sizeof_sunpath)
580
581         dnl *************************************
582         dnl *** Checks for zero length arrays ***
583         dnl *************************************
584         AC_MSG_CHECKING(whether $CC supports zero length arrays)
585         AC_TRY_COMPILE([
586                 struct s {
587                         int  length;
588                         char data [0];
589                 };
590         ], [], [
591                 AC_MSG_RESULT(yes)
592                 AC_DEFINE_UNQUOTED(MONO_ZERO_ARRAY_LENGTH, 0)
593         ], [
594                 AC_MSG_RESULT(no)
595                 AC_DEFINE_UNQUOTED(MONO_ZERO_ARRAY_LENGTH, 1)
596         ])
597
598         dnl *****************************
599         dnl *** Checks for libxnet    ***
600         dnl *****************************
601         case "${host}" in
602                 *solaris* )
603                         AC_MSG_CHECKING(for Solaris XPG4 support)
604                         if test -f /usr/lib/libxnet.so; then
605                                 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=500"
606                                 CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__"
607                                 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE_EXTENDED=1"
608                                 LIBS="$LIBS -lxnet"
609                                 AC_MSG_RESULT(yes)
610                         else
611                                 AC_MSG_RESULT(no)
612                         fi
613
614                         if test "$GCC" = "yes"; then
615                                 CFLAGS="$CFLAGS -Wno-char-subscripts"
616                         fi
617                 ;;
618         esac
619
620         dnl *****************************
621         dnl *** Checks for libpthread ***
622         dnl *****************************
623         AC_CHECK_LIB(pthread, main, LIBS="$LIBS -lpthread")
624         AC_CHECK_HEADERS(pthread.h)
625         AC_CHECK_FUNCS(pthread_mutex_timedlock)
626         AC_CHECK_FUNCS(pthread_getattr_np pthread_attr_get_np)
627         AC_MSG_CHECKING(for PTHREAD_MUTEX_RECURSIVE)
628         AC_TRY_COMPILE([ #include <pthread.h>], [
629                 pthread_mutexattr_t attr;
630                 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
631         ], [
632                 AC_MSG_RESULT(ok)
633         ], [
634                 AC_MSG_RESULT(no)
635                 AC_MSG_WARN(Using mono_mutex_t for recursive mutexes)
636                 AC_DEFINE(USE_MONO_MUTEX)
637         ])
638         AC_CHECK_FUNCS(pthread_attr_setstacksize)
639
640         dnl ***********************************
641         dnl *** Checks for working __thread ***
642         dnl ***********************************
643         AC_MSG_CHECKING(for working __thread)
644         if test "x$with_nptl" != "xyes"; then
645                 AC_MSG_RESULT(disabled)
646         else
647                 AC_TRY_RUN([
648                         #include <pthread.h>
649
650                         __thread int i;
651                         static int res1, res2;
652
653                         void thread_main (void *arg)
654                         {
655                                 i = arg;
656                                 sleep (1);
657                                 if (arg == 1)
658                                         res1 = (i == arg);
659                                 else
660                                         res2 = (i == arg);
661                         }
662
663                         int main () {
664                                 pthread_t t1, t2;
665
666                                 i = 5;
667
668                                 pthread_create (&t1, NULL, thread_main, 1);
669                                 pthread_create (&t2, NULL, thread_main, 2);
670
671                                 pthread_join (t1, NULL);
672                                 pthread_join (t2, NULL);
673
674                                 return !(res1 + res2 == 2);
675                         }
676                 ], [
677                                 AC_MSG_RESULT(yes)
678                                 AC_DEFINE(HAVE_KW_THREAD)
679                 ], [
680                                 AC_MSG_RESULT(no)
681                 ])
682         fi
683
684         dnl **************************************
685         dnl *** Checks for working sigaltstack ***
686         dnl **************************************
687         AC_MSG_CHECKING(for working sigaltstack)
688         if test "x$with_sigaltstack" != "xyes"; then
689                 AC_MSG_RESULT(disabled)
690         else
691                 AC_TRY_RUN([
692                         #include <stdio.h>
693                         #include <stdlib.h>
694                         #include <unistd.h>
695                         #include <signal.h>
696                         #include <pthread.h>
697                         #include <sys/wait.h>
698
699                         static void
700                         sigsegv_signal_handler (int _dummy, siginfo_t *info, void *context)
701                         {
702                                 exit (0);
703                         }
704
705                         static void *
706                         loop (void *ignored)
707                         {
708                                 char *ptr = NULL;
709
710                                 *ptr = 0;
711                                 return NULL;
712                         }
713
714                         static void
715                         child ()
716                         {
717                                 struct sigaction sa;
718                                 struct sigaltstack sas;
719                                 pthread_t id;
720                                 pthread_attr_t attr;
721
722                                 sa.sa_sigaction = sigsegv_signal_handler;
723                                 sigemptyset (&sa.sa_mask);
724                                 sa.sa_flags = SA_SIGINFO | SA_STACK;
725                                 if (sigaction (SIGSEGV, &sa, NULL) == -1) {
726                                         perror ("lala");
727                                         return;
728                                 }
729
730                                 sas.ss_sp = malloc (SIGSTKSZ);
731                                 sas.ss_size = SIGSTKSZ;
732                                 sas.ss_flags = SS_ONSTACK;
733                                 if (sigaltstack (&sas, NULL) == -1) {
734                                         perror ("lala");
735                                         return;
736                                 }
737
738                                 pthread_attr_init (&attr);
739                                 if (pthread_create(&id, &attr, loop, &attr) != 0) {
740                                         printf ("failed\n");
741                                         return;
742                                 }
743
744                                 sleep (100);
745                         }
746
747                         int
748                         main ()
749                         {
750                                 pid_t son;
751                                 int status;
752                                 int i;
753
754                                 son = fork ();
755                                 if (son == -1) {
756                                         return 1;
757                                 }
758
759                                 if (son == 0) {
760                                         child ();
761                                         return 0;
762                                 }
763
764                                 for (i = 0; i < 3; ++i) {
765                                         sleep (1);
766                                         waitpid (son, &status, WNOHANG);
767                                         if (WIFEXITED (status) && WEXITSTATUS (status) == 0)
768                                                 return 0;
769                                 }
770
771                                 kill (son, SIGKILL);
772                                 return 1;
773                         }
774
775                 ], [
776                                 AC_MSG_RESULT(yes)
777                                 AC_DEFINE(HAVE_WORKING_SIGALTSTACK)
778                 ], [
779                                 with_sigaltstack=no
780                                 AC_MSG_RESULT(no)
781                 ])
782         fi
783
784         dnl ********************************
785         dnl *** Checks for semaphore lib ***
786         dnl ********************************
787         # 'Real Time' functions on Solaris
788         # posix4 on Solaris 2.6
789         # pthread (first!) on Linux
790         AC_SEARCH_LIBS(sem_init, pthread rt posix4) 
791
792         dnl ********************************
793         dnl *** Checks for timezone stuff **
794         dnl ********************************
795         AC_CACHE_CHECK(for tm_gmtoff in struct tm, ac_cv_struct_tm_gmtoff,
796                 AC_TRY_COMPILE([
797                         #include <time.h>
798                         ], [
799                         struct tm tm;
800                         tm.tm_gmtoff = 1;
801                         ], ac_cv_struct_tm_gmtoff=yes, ac_cv_struct_tm_gmtoff=no))
802         if test $ac_cv_struct_tm_gmtoff = yes; then
803                 AC_DEFINE(HAVE_TM_GMTOFF)
804         else
805                 AC_CACHE_CHECK(for timezone variable, ac_cv_var_timezone,
806                         AC_TRY_COMPILE([
807                                 #include <time.h>
808                         ], [
809                                 timezone = 1;
810                         ], ac_cv_var_timezone=yes, ac_cv_var_timezone=no))
811                 if test $ac_cv_var_timezone = yes; then
812                         AC_DEFINE(HAVE_TIMEZONE)
813                 else
814                         AC_ERROR(unable to find a way to determine timezone)
815                 fi
816         fi
817
818         dnl *********************************
819         dnl *** Checks for math functions ***
820         dnl *********************************
821         LIBS="$LIBS -lm";
822         AC_CHECK_FUNCS(finite, , AC_MSG_CHECKING(for finite in math.h)
823                 AC_TRY_LINK([#include <math.h>], 
824                 [ finite(0.0); ], 
825                 AC_DEFINE(HAVE_FINITE) AC_MSG_RESULT(yes),
826                 AC_MSG_RESULT(no)))
827         AC_CHECK_FUNCS(isfinite, , AC_MSG_CHECKING(for isfinite in math.h)
828                 AC_TRY_LINK([#include <math.h>], 
829                 [ isfinite(0.0); ], 
830                 AC_DEFINE(HAVE_ISFINITE) AC_MSG_RESULT(yes),
831                 AC_MSG_RESULT(no)))
832
833         dnl ****************************************************************
834         dnl *** Checks for working poll() (macosx defines it but doesn't ***
835         dnl *** have it in the library (duh))                            ***
836         dnl ****************************************************************
837         AC_CHECK_FUNCS(poll)
838
839         dnl *************************
840         dnl *** Check for signbit ***
841         dnl *************************
842         AC_MSG_CHECKING(for signbit)
843         AC_TRY_LINK([#include <math.h>], [
844                 int s = signbit(1.0);
845         ], [
846                 AC_MSG_RESULT(yes)
847                 AC_DEFINE(HAVE_SIGNBIT)
848         ], [
849                 AC_MSG_RESULT(no)
850         ]) 
851
852         dnl *********************
853         dnl *** Check for AIO ***
854         dnl *********************
855         AC_CHECK_HEADERS(aio.h sys/aio.h)
856         AC_CHECK_LIB(rt, aio_read, [ LIBS="$LIBS -lrt" ],)
857         SIGVAL_PTR="undefined"
858         if test "$ac_cv_header_aio_h" = "yes" -o "$ac_cv_header_sys_aio_h" = "yes" ; then
859                 AC_CHECK_MEMBER(union sigval.sigval_ptr,SIGVAL_PTR="sigval_ptr",, [
860                                 #include <sys/signal.h>
861                                 ])
862                 AC_CHECK_MEMBER(union sigval.sival_ptr,SIGVAL_PTR="sival_ptr",, [
863                                 #include <sys/signal.h>
864                                 ])
865                 if test "$SIGVAL_PTR" = "undefined" ; then
866                         AC_MSG_ERROR([Unable to detect field name in 'union sigval'])
867                 fi
868         fi
869         AC_DEFINE_UNQUOTED(SIGVAL_PTR,$SIGVAL_PTR,[Pointer field name in 'union sigval'])
870 else
871         AC_CHECK_LIB(ws2_32, main, LIBS="$LIBS -lws2_32", AC_ERROR(bad mingw install?))
872         AC_CHECK_LIB(psapi, main, LIBS="$LIBS -lpsapi", AC_ERROR(bad mingw install?))
873 fi
874
875 dnl socklen_t check
876 AC_MSG_CHECKING(for socklen_t)
877 AC_TRY_COMPILE([
878 #include <sys/types.h>
879 #include <sys/socket.h>
880 ],[
881   socklen_t foo;
882 ],[
883 ac_cv_c_socklen_t=yes
884         AC_DEFINE(HAVE_SOCKLEN_T)
885         AC_MSG_RESULT(yes)
886 ],[
887         AC_MSG_RESULT(no)
888 ])
889
890 AC_CHECK_FUNCS(truncl, , AC_MSG_CHECKING(for truncl in math.h)
891         AC_TRY_LINK([#include <math.h>], 
892         [ truncl(0.0); ], 
893         [
894                 AC_DEFINE(HAVE_TRUNCL) 
895                 AC_MSG_RESULT(yes)
896                 ac_cv_truncl=yes
897         ],
898         AC_MSG_RESULT(no)))
899
900 if test "x$ac_cv_truncl" != "xyes"; then
901    AC_CHECK_LIB(sunmath, aintl, [ AC_DEFINE(HAVE_AINTL) LIBS="$LIBS -lsunmath"])
902 fi
903
904 dnl ****************************
905 dnl *** Look for /dev/random ***
906 dnl ****************************
907
908 AC_MSG_CHECKING([if usage of random device is requested])
909 AC_ARG_ENABLE(dev-random,
910 [  --disable-dev-random    disable the use of the random device],
911 try_dev_random=$enableval, try_dev_random=yes)
912 AC_MSG_RESULT($try_dev_random)
913
914 case "{$target}" in
915     *-openbsd*)
916     NAME_DEV_RANDOM="/dev/srandom"
917     ;;
918
919 dnl Win32 does not have /dev/random, they have their own method...
920
921     *-*-mingw*|*-*-cygwin*)
922     ac_cv_have_dev_random = no
923     ;;
924
925 dnl Everywhere else, it's /dev/random
926
927     *)
928     NAME_DEV_RANDOM="/dev/random"
929     ;;
930 esac
931
932 AC_DEFINE_UNQUOTED(NAME_DEV_RANDOM, "$NAME_DEV_RANDOM")
933
934 dnl Now check if the device actually exists
935
936 if test "x$try_dev_random" = "xyes"; then
937     AC_CACHE_CHECK(for random device, ac_cv_have_dev_random,
938     [if test -r "$NAME_DEV_RANDOM" ; then
939         ac_cv_have_dev_random=yes; else ac_cv_have_dev_random=no; fi])
940     if test "x$ac_cv_have_dev_random" = "xyes"; then
941         AC_DEFINE(HAVE_CRYPT_RNG)
942     fi
943 else
944     AC_MSG_CHECKING(for random device)
945     ac_cv_have_dev_random=no
946     AC_MSG_RESULT(has been disabled)
947 fi
948
949 if test "x$platform_win32" = "xyes"; then
950     AC_DEFINE(HAVE_CRYPT_RNG)
951 fi
952
953 if test "x$ac_cv_have_dev_random" = "xno" \
954     && test "x$platform_win32" = "xno"; then
955     AC_MSG_WARN([[
956 ***
957 *** A system-provided entropy source was not found on this system.
958 *** Because of this, the System.Security.Cryptography random number generator
959 *** will throw a NotImplemented exception.
960 ***
961 *** If you are seeing this message, and you know your system DOES have an
962 *** entropy collection in place, please contact <crichton@gimp.org> and
963 *** provide information about the system and how to access the random device.
964 ***
965 *** Otherwise you can install either egd or prngd and set the environment
966 *** variable MONO_EGD_SOCKET to point to the daemon's socket to use that.
967 ***]])
968 fi
969  
970 AC_MSG_CHECKING([if inter-process shared handles are requested])
971 AC_ARG_ENABLE(shared-handles, [  --disable-shared-handles disable inter-process shared handles], try_shared_handles=$enableval, try_shared_handles=yes)
972 AC_MSG_RESULT($try_shared_handles)
973 if test "x$try_shared_handles" != "xyes"; then
974         AC_DEFINE(DISABLE_SHARED_HANDLES)
975         AC_SUBST(DISABLE_SHARED_HANDLES)
976 fi
977
978 ICU_CFLAGS=""
979 ICU_LIBS=""
980 enable_icu=no
981 AC_PATH_PROG(ICU_CONFIG, icu-config, no)
982 if test "x$ICU_CONFIG" = "xno" -o ! -x "$ICU_CONFIG"; then
983         AC_MSG_WARN([Only invariant locale available; install ICU for I18N support])
984         enable_icu="no, if you want full i18n support download it from: http://oss.software.ibm.com/icu/index.html"
985 else
986         enable_icu="yes. Version: `$ICU_CONFIG --version`"
987         AC_DEFINE(HAVE_ICU)
988         ICU_CFLAGS=`$ICU_CONFIG --cppflags`
989         ICU_LIBS=`$ICU_CONFIG --ldflags`
990 fi
991 AC_SUBST(ICU_CFLAGS)
992 AC_SUBST(ICU_LIBS)
993
994 TARGET="unknown"
995 ACCESS_UNALIGNED="yes"
996
997 JIT_SUPPORTED=no
998 LIBC="libc.so.6"
999
1000 jit_wanted=false
1001 case "$host" in
1002 #       mips-sgi-irix5.* | mips-sgi-irix6.*)
1003 #               TARGET=MIPS;
1004 #               ACCESS_UNALIGNED="no"
1005 #               ;;
1006         i*86-*-*)
1007                 TARGET=X86;
1008                 arch_target=x86;
1009                 JIT_SUPPORTED=yes
1010                 jit_wanted=true
1011                 ;;
1012         x86_64-*-* | amd64-*-*)
1013                 TARGET=AMD64;
1014                 arch_target=amd64;
1015                 JIT_SUPPORTED=no
1016                 ;;
1017         sparc*-*-*)
1018                 TARGET=SPARC;
1019                 arch_target=sparc;
1020                 JIT_SUPPORTED=yes
1021                 ACCESS_UNALIGNED="no"
1022                 jit_wanted=true
1023                 ;;
1024 #       alpha*-*-linux* | alpha*-*-osf*)
1025 #               TARGET=ALPHA;
1026 #               ACCESS_UNALIGNED="no"
1027 #              ;;
1028 #       ia64-*-linux* | ia64-*-hpux*)
1029 #               TARGET=IA64;
1030 #               arch_target=ia64;
1031 #               JIT_SUPPORTED=no;
1032 #               ACCESS_UNALIGNED="no";
1033 #               case "$host_os" in
1034 #                       linux*) LIBC="libc.so.6.1";;
1035 #                       hpux*)  LIBC="libc.so.1";;
1036 #               esac
1037 #               ;;
1038 #       m68k-*-linux*)
1039 #               TARGET=M68K
1040 #               ;;
1041         hppa2.0w-hp-hpux11.00 | hppa64-hp-hpux11.00)
1042                 TARGET=HPPA;
1043                 arch_target=hppa; 
1044                 ACCESS_UNALIGNED="no"
1045                 ;;
1046         macppc-*-openbsd* | powerpc-*-linux* | powerpc-*-openbsd* | \
1047         powerpc-*-sysv* | powerpc-*-darwin*)
1048                 TARGET=POWERPC;
1049                 arch_target=ppc;
1050                 JIT_SUPPORTED=yes
1051                 ;;
1052         arm-*-linux-* | armv4l-*-linux-*)
1053                 TARGET=ARM;
1054                 arch_target=arm;
1055                 ACCESS_UNALIGNED="no"
1056                 ;;
1057         s390-*-linux*)
1058                 TARGET=S390;
1059                 arch_target=s390;
1060                 ACCESS_UNALIGNED="no"
1061                 JIT_SUPPORTED=yes
1062                 ;;
1063 esac
1064
1065 AC_ARG_WITH(jit, [  --with-jit=yes,no       If you want to build scripts that default to the JIT],[
1066         jit_wanted=true
1067 ])
1068
1069 USEJIT=false
1070 if test x$JIT_SUPPORTED = xyes; then
1071    if $jit_wanted; then
1072       USEJIT=true
1073       jit_status="Building and using the JIT"
1074    else
1075       jit_status="Building the JIT, defaulting to the interpreter"
1076    fi
1077 else
1078    jit_status="interpreter"
1079 fi
1080
1081 AM_CONDITIONAL(USE_JIT, test x$USEJIT = xtrue)
1082
1083 libsuffix=".so"
1084
1085 case "$host" in
1086      powerpc-*-darwin*)
1087         libsuffix=".dylib"
1088         ;;
1089 esac
1090 AC_SUBST(libsuffix)
1091
1092 if test ${TARGET} = ARM; then
1093         dnl ******************************************
1094         dnl *** Check to see what FPU is available ***
1095         dnl ******************************************
1096         AC_MSG_CHECKING(which FPU to use)
1097
1098         AC_TRY_COMPILE([], [
1099                 __asm__ ("ldfd f0, [r0]");
1100                 ], fpu=FPA, [
1101                         AC_TRY_COMPILE([], [
1102                                 __asm__ ("fldd d0, [r0]");
1103                         ], fpu=VFP, fpu=NONE)
1104                 ])
1105
1106         AC_MSG_RESULT($fpu)
1107         CPPFLAGS="$CPPFLAGS -DARM_FPU_$fpu"
1108         unset fpu
1109 fi
1110
1111 if test ${TARGET} = unknown; then
1112         CPPFLAGS="$CPPFLAGS -DNO_PORT"
1113         AC_MSG_WARN("mono has not been ported to $host: some things may not work.")
1114 fi
1115
1116 if test ${ACCESS_UNALIGNED} = no; then
1117         CPPFLAGS="$CPPFLAGS -DNO_UNALIGNED_ACCESS"
1118 fi
1119
1120 AM_CONDITIONAL(MIPS_GCC, test ${TARGET}${ac_cv_prog_gcc} = MIPSyes)
1121 AM_CONDITIONAL(MIPS_SGI, test ${TARGET}${ac_cv_prog_gcc} = MIPSno)
1122 AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
1123 AM_CONDITIONAL(X86, test x$TARGET = xX86)
1124 AM_CONDITIONAL(AMD64, test x$TARGET = xAMD64)
1125 AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
1126 AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
1127 AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
1128 AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
1129 AM_CONDITIONAL(ARM, test x$TARGET = xARM)
1130 AM_CONDITIONAL(S390, test x$TARGET = xS390)
1131 AM_CONDITIONAL(HPPA, test x$TARGET = xHPPA)
1132
1133 AM_CONDITIONAL(JIT_SUPPORTED, test x$JIT_SUPPORTED = xyes)
1134
1135 AC_SUBST(LIBC)
1136
1137 AC_SUBST(arch_target)
1138 AC_SUBST(CFLAGS)
1139 AC_SUBST(CPPFLAGS)
1140 AC_SUBST(LDFLAGS)
1141
1142 AC_OUTPUT([
1143 Makefile
1144 mint.pc
1145 mono.pc
1146 mono/Makefile
1147 mono/utils/Makefile
1148 mono/metadata/Makefile
1149 mono/dis/Makefile
1150 mono/cil/Makefile
1151 mono/arch/Makefile
1152 mono/os/Makefile
1153 mono/os/win32/Makefile
1154 mono/os/unix/Makefile
1155 mono/arch/x86/Makefile
1156 mono/arch/amd64/Makefile
1157 mono/arch/hppa/Makefile
1158 mono/arch/ppc/Makefile
1159 mono/arch/sparc/Makefile
1160 mono/arch/s390/Makefile
1161 mono/arch/arm/Makefile
1162 mono/arch/alpha/Makefile
1163 mono/interpreter/Makefile
1164 mono/tests/Makefile
1165 mono/tests/tests-config
1166 mono/benchmark/Makefile
1167 mono/monoburg/Makefile
1168 mono/monograph/Makefile
1169 mono/io-layer/Makefile
1170 mono/handles/Makefile
1171 mono/mini/Makefile
1172 mono/profiler/Makefile
1173 ikvm-jni/Makefile
1174 runtime/Makefile
1175 runtime/net_1_1/Makefile
1176 runtime/net_2_0/Makefile
1177 scripts/Makefile
1178 man/Makefile
1179 web/Makefile
1180 docs/Makefile
1181 data/Makefile
1182 samples/Makefile
1183 support/Makefile
1184 data/config
1185 mono.spec
1186 ])
1187
1188 echo "
1189
1190         GC:          $gc
1191         ICU:         $enable_icu
1192         NPTL:        $with_nptl
1193         SIGALTSTACK: $with_sigaltstack
1194         Engine:      $jit_status
1195         
1196 "