[684600] Treat all value types equally
[mono.git] / configure.in
1 AC_INIT(README)
2 AC_CANONICAL_SYSTEM
3
4 # Gross hack to enable 'make dist' on automake 1.9+tar 1.14.
5 # The extra brackets are to foil regex-based scans.
6 m4_ifdef([_A][M_PROG_TAR],[_A][M_SET_OPTION([tar-ustar])])
7
8 AM_CONFIG_HEADER(config.h)
9 AM_INIT_AUTOMAKE(mono,2.11)
10 AM_MAINTAINER_MODE
11
12 API_VER=2.0
13 AC_SUBST(API_VER)
14
15 AC_PROG_LN_S
16
17 # In case of cygwin, override LN_S, irrespective of what it determines.
18 # The build uses cygwin, but the actual runtime doesn't.
19 case $host_os in
20 *cygwin* ) LN_S='cp -p';;
21 esac
22
23 dnl
24 dnl libgc checks
25 dnl
26
27 gc_headers=no
28 gc=included
29 gc_msg="included Boehm"
30 use_included_gc=no
31 libgc_configure_args=
32
33 if test -d $srcdir/libgc ; then
34   gc_default=included
35 else
36   gc_default=boehm
37 fi
38
39 # These variables are the CPPFLAGS/CFLAGS passed to libgc's configure
40 # libgc should inherit the original CFLAGS/CPPFLAGS passed to configure, i.e. -O0
41 CPPFLAGS_FOR_LIBGC=$CPPFLAGS
42 CFLAGS_FOR_LIBGC=$CFLAGS
43 CPPFLAGS_FOR_EGLIB=$CPPFLAGS
44 CFLAGS_FOR_EGLIB=$CFLAGS
45
46 #
47 # These are the flags that need to be stored in the mono.pc file for 
48 # compiling code that will embed Mono
49 #
50 libmono_cflags=""
51 libmono_ldflags=""
52 AC_SUBST(libmono_cflags)
53 AC_SUBST(libmono_ldflags)
54
55 # Variable to have relocatable .pc files (lib, or lib64)
56 reloc_libdir=`basename ${libdir}`
57 AC_SUBST(reloc_libdir)
58
59 dnl if linker handles the version script
60 no_version_script=no
61
62 # Set to yes if Unix sockets cannot be created in an anonymous namespace
63 need_link_unlink=no
64
65 # Thread configuration inspired by sleepycat's db
66 AC_MSG_CHECKING([host platform characteristics])
67 libgc_threads=no
68 has_dtrace=no
69 parallel_mark=yes
70 ikvm_native=yes
71
72 case "$host" in
73         powerpc*-*-linux*)
74                 # https://bugzilla.novell.com/show_bug.cgi?id=504411
75                 disable_munmap=yes
76         ;;
77 esac
78
79 host_win32=no
80 target_win32=no
81 case "$host" in
82         *-mingw*|*-*-cygwin*)
83                 AC_DEFINE(HOST_WIN32,1,[Host Platform is Win32])
84                 AC_DEFINE(DISABLE_PORTABILITY,1,[Disable the io-portability layer])
85                 AC_DEFINE(PLATFORM_NO_SYMLINKS,1,[This platform does not support symlinks])
86                 host_win32=yes
87                 if test "x$cross_compiling" = "xno"; then
88                         target_win32=yes
89                         if test "x$host" == "x$build"; then
90                                 AC_DEFINE(TARGET_WIN32,1,[Target OS is Win32])
91                         fi
92                         CC="gcc -mno-cygwin -g"
93                         CXX="g++ -mno-cygwin -g"
94                         # So libgc configure gets -mno-cygwin
95                         export CC
96                         export CXX
97                         CFLAGS_FOR_EGLIB="$CFLAGS_FOR_EGLIB -mno-cygwin"
98                 else
99                         target_win32=yes
100                         AC_DEFINE(TARGET_WIN32,1,[Target OS is Win32/MinGW])
101                         AC_DEFINE(MINGW_CROSS_COMPILE,1,[Cross-compiling using MinGW])
102                 fi
103                 HOST_CC="gcc"
104                 # Windows 2000 is required that includes Internet Explorer 5.01
105                 CPPFLAGS="$CPPFLAGS -DWINVER=0x0500 -D_WIN32_WINNT=0x0500 -D_WIN32_IE=0x0501 -D_UNICODE -DUNICODE -DWIN32_THREADS -DFD_SETSIZE=1024"
106                 LDFLAGS="$LDFLAGS -lmswsock -lws2_32 -lole32 -loleaut32 -lpsapi -lversion -ladvapi32 -lwinmm -lkernel32"
107                 libmono_cflags="-mno-cygwin -mms-bitfields -mwindows"
108                 libmono_ldflags="-mno-cygwin -mms-bitfields -mwindows"
109                 libdl=
110                 libgc_threads=win32
111                 gc_default=included
112                 with_sigaltstack=no
113                 LN_S=cp
114                 # This forces libgc to use the DllMain based thread registration code on win32
115                 libgc_configure_args="$libgc_configure_args --enable-win32-dllmain=yes"
116                 ;;
117         *-*-*netbsd*)
118                 host_win32=no
119                 CPPFLAGS="$CPPFLAGS -D_REENTRANT -DGC_NETBSD_THREADS -D_GNU_SOURCE"
120                 libmono_cflags="-D_REENTRANT"
121                 LDFLAGS="$LDFLAGS -pthread"
122                 CPPFLAGS="$CPPFLAGS -DPLATFORM_BSD"
123                 libmono_ldflags="-pthread"
124                 need_link_unlink=yes
125                 libdl="-ldl"
126                 libgc_threads=pthreads
127                 with_sigaltstack=no
128                 use_sigposix=yes
129                 ;;
130         *-*-*freebsd*)
131                 host_win32=no
132                 if test "x$PTHREAD_CFLAGS" = "x"; then
133                         CPPFLAGS="$CPPFLAGS -DGC_FREEBSD_THREADS"
134                         libmono_cflags=
135                 else
136                         CPPFLAGS="$CPPFLAGS $PTHREAD_CFLAGS -DGC_FREEBSD_THREADS"
137                         libmono_cflags="$PTHREAD_CFLAGS"
138                 fi
139                 if test "x$PTHREAD_LIBS" = "x"; then
140                         LDFLAGS="$LDFLAGS -pthread"
141                         libmono_ldflags="-pthread"
142                 else
143                         LDFLAGS="$LDFLAGS $PTHREAD_LIBS"
144                         libmono_ldflags="$PTHREAD_LIBS"
145                 fi
146                 CPPFLAGS="$CPPFLAGS -DPLATFORM_BSD"
147                 need_link_unlink=yes
148                 AC_DEFINE(PTHREAD_POINTER_ID, 1, [pthread is a pointer])
149                 libdl=
150                 libgc_threads=pthreads
151                 # This doesn't seem to work as of 7.0 on amd64
152                 with_sigaltstack=no
153 # TLS is only partially implemented on -CURRENT (compiler support
154 # but NOT library support)
155 #
156                 with_tls=pthread
157                 use_sigposix=yes
158                 ;;
159         *-*-*openbsd*)
160                 host_win32=no
161                 CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE -DGC_OPENBSD_THREADS -DPLATFORM_BSD -D_REENTRANT -DUSE_MMAP"
162                 if test "x$disable_munmap" != "xyes"; then
163                 CPPFLAGS="$CPPFLAGS -DUSE_MUNMAP"
164                 fi
165                 libmono_cflags="-D_THREAD_SAFE -D_REENTRANT"
166                 LDFLAGS="$LDFLAGS -pthread"
167                 need_link_unlink=yes
168                 AC_DEFINE(PTHREAD_POINTER_ID)
169                 libdl=
170                 gc_default=boehm
171                 libgc_threads=pthreads
172                 with_sigaltstack=no
173                 use_sigposix=yes
174                 ;;
175         *-*-linux*)
176                 host_win32=no
177                 CPPFLAGS="$CPPFLAGS -DGC_LINUX_THREADS -D_GNU_SOURCE -D_REENTRANT -DUSE_MMAP"
178                 if test "x$disable_munmap" != "xyes"; then
179                         CPPFLAGS="$CPPFLAGS -DUSE_MUNMAP"
180                 fi
181                 libmono_cflags="-D_REENTRANT"
182                 libdl="-ldl"
183                 libgc_threads=pthreads
184                 use_sigposix=yes
185                 ;;
186         *-*-nacl*)
187                 host_win32=no
188                 CPPFLAGS="$CPPFLAGS -DGC_LINUX_THREADS -D_GNU_SOURCE -D_REENTRANT -DUSE_MMAP"
189                 if test "x$disable_munmap" != "xyes"; then
190                         CPPFLAGS="$CPPFLAGS -DUSE_MUNMAP"
191                 fi
192                 libmono_cflags="-D_REENTRANT"
193                 libdl=
194                 libgc_threads=pthreads
195                 gc_default=boehm
196                 use_sigposix=yes
197                 ikvm_native=no
198                 AC_DEFINE(DISABLE_SOCKETS,1,[Disable sockets support])
199                 AC_DEFINE(DISABLE_ATTACH, 1, [Disable agent attach support])
200                 ;;
201         *-*-hpux*)
202                 host_win32=no
203                 CPPFLAGS="$CPPFLAGS -DGC_HPUX_THREADS -D_HPUX_SOURCE -D_XOPEN_SOURCE_EXTENDED -D_REENTRANT"
204                 # +ESdbgasm only valid on bundled cc on RISC
205                 # silently ignored for ia64
206                 if test $GCC != "yes"; then
207                         CFLAGS="$CFLAGS +ESdbgasm"
208                         # Arrange for run-time dereferencing of null
209                         # pointers to produce a SIGSEGV signal.
210                         LDFLAGS="$LDFLAGS -z"
211                 fi
212                 CFLAGS="$CFLAGS +ESdbgasm"
213                 LDFLAGS="$LDFLAGS -z"
214                 libmono_cflags="-D_REENTRANT"
215                 libmono_ldflags="-lpthread"
216                 libgc_threads=pthreads
217                 need_link_unlink=yes
218                 use_sigposix=yes
219                 ;;
220         *-*-solaris*)
221                 host_win32=no
222                 CPPFLAGS="$CPPFLAGS -DGC_SOLARIS_THREADS -DGC_SOLARIS_PTHREADS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -DUSE_MMAP -DUSE_MUNMAP -DPLATFORM_SOLARIS"
223                 need_link_unlink=yes
224                 libmono_cflags="-D_REENTRANT"
225                 libgc_threads=pthreads
226                 # This doesn't seem to work on solaris/x86, but the configure test runs
227                 with_tls=pthread
228                 has_dtrace=yes
229                 use_sigposix=yes
230                 enable_solaris_tar_check=yes
231                 ;;
232         *-*-darwin*)
233                 parallel_mark="Disabled_Currently_Hangs_On_MacOSX"
234                 host_win32=no
235                 platform_darwin=yes
236                 CPPFLAGS="$CPPFLAGS -no-cpp-precomp -D_THREAD_SAFE -DGC_MACOSX_THREADS -DPLATFORM_MACOSX -DUSE_MMAP -DUSE_MUNMAP"
237                 CPPFLAGS="$CPPFLAGS -DGetCurrentProcess=MonoGetCurrentProcess -DGetCurrentThread=MonoGetCurrentThread -DCreateEvent=MonoCreateEvent"
238                 libmono_cflags="-D_THREAD_SAFE"
239                 LDFLAGS="$LDFLAGS -pthread"
240                 libmono_ldflags="-pthread"
241                 need_link_unlink=yes
242                 AC_DEFINE(PTHREAD_POINTER_ID)
243                 AC_DEFINE(USE_MACH_SEMA, 1, [...])
244                 no_version_script=yes
245                 libdl=
246                 libgc_threads=pthreads
247                 has_dtrace=yes
248                 if test "x$cross_compiling" = "xyes"; then
249                         has_broken_apple_cpp=yes
250                 fi
251                 dnl Snow Leopard is horribly broken -- it reports itself as i386-apple-darwin*, but
252                 dnl its gcc defaults to 64-bit mode.  They have also deprecated the usage of ucontext
253                 dnl we need to set some flags to build our 32-bit binaries on 10.6 properly
254                 case "$host" in
255                         dnl Snow Leopard and newer config.guess reports as this
256                         i*86-*-darwin*)
257                                 BROKEN_DARWIN_FLAGS="-arch i386 -D_XOPEN_SOURCE -mmacosx-version-min=10.5"
258                                 CPPFLAGS="$CPPFLAGS $BROKEN_DARWIN_FLAGS"
259                                 CFLAGS="$CFLAGS $BROKEN_DARWIN_FLAGS"
260                                 CXXFLAGS="$CXXFLAGS $BROKEN_DARWIN_FLAGS"
261                                 CCASFLAGS="$CCASFLAGS $BROKEN_DARWIN_FLAGS"
262                                 CPPFLAGS_FOR_LIBGC="$CPPFLAGS_FOR_LIBGC $BROKEN_DARWIN_FLAGS"
263                                 CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC $BROKEN_DARWIN_FLAGS"
264                                 CPPFLAGS_FOR_EGLIB="$CPPFLAGS_FOR_EGLIB $BROKEN_DARWIN_FLAGS"
265                                 CFLAGS_FOR_EGLIB="$CFLAGS_FOR_EGLIB $BROKEN_DARWIN_FLAGS"
266                                 ;;
267                 esac
268                 ;;
269         *-*-haiku*)
270                 host_win32=no
271                 CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_THREAD_SAFE"
272                 libmono_cflags="-D_REENTRANT -D_THREAD_SAFE"
273                 libdl=
274                 LIBS="$LIBS -lnetwork"
275                 need_link_unlink=yes
276                 AC_DEFINE(PTHREAD_POINTER_ID)
277                 libgc_threads=pthreads
278                 use_sigposix=yes
279                 ;;
280         *)
281                 AC_MSG_WARN([*** Please add $host to configure.in checks!])
282                 host_win32=no
283                 libdl="-ldl"
284                 ;;
285 esac
286 AC_MSG_RESULT(ok)
287
288 if test x$need_link_unlink = xyes; then
289    AC_DEFINE(NEED_LINK_UNLINK, 1, [Define if Unix sockets cannot be created in an anonymous namespace])
290 fi
291
292 AM_CONDITIONAL(HOST_WIN32, test x$host_win32 = xyes)
293 AM_CONDITIONAL(TARGET_WIN32, test x$target_win32 = xyes)
294 AM_CONDITIONAL(PLATFORM_LINUX, echo x$target_os | grep -q linux)
295 AM_CONDITIONAL(PLATFORM_DARWIN, test x$platform_darwin = xyes)
296 AM_CONDITIONAL(PLATFORM_SIGPOSIX, test x$use_sigposix = xyes)
297
298 AC_CHECK_TOOL(CC, gcc, gcc)
299 AC_PROG_CC
300 AC_CHECK_TOOL(CXX, g++, g++)
301 AC_PROG_CXX
302 AM_PROG_AS
303 AM_PROG_CC_STDC
304 AC_PROG_INSTALL
305 AC_PROG_AWK
306 dnl We should use AM_PROG_AS, but it's not available on automake/aclocal 1.4
307 : ${CCAS='$(CC)'}
308 # Set ASFLAGS if not already set.
309 : ${CCASFLAGS='$(CFLAGS)'}
310 AC_SUBST(CCAS)
311 AC_SUBST(CCASFLAGS)
312
313 # AC_PROG_CXX helpfully sets CXX to g++ even if no c++ compiler is found so check
314 # GXX instead. See http://lists.gnu.org/archive/html/bug-autoconf/2002-04/msg00056.html
315 if test "x$CXX" = "xg++"; then
316         if test "x$GXX" != "xyes"; then
317                 # automake/libtool is so broken, it requires g++ even if the c++ sources
318                 # are inside automake conditionals
319                 AC_MSG_ERROR([You need to install g++])
320         fi
321 fi
322
323 AC_CHECK_PROG(BISON, bison,yes,no)
324 if test "x$BISON" = "xno";
325 then
326         AC_MSG_ERROR([You need to install bison])
327 fi
328
329 dnl may require a specific autoconf version
330 dnl AC_PROG_CC_FOR_BUILD
331 dnl CC_FOR_BUILD not automatically detected
332 CC_FOR_BUILD=$CC
333 CFLAGS_FOR_BUILD=$CFLAGS
334 BUILD_EXEEXT=
335 if test "x$cross_compiling" = "xyes"; then
336         CC_FOR_BUILD=cc
337         CFLAGS_FOR_BUILD=
338         BUILD_EXEEXT=""
339 fi
340 AC_SUBST(CC_FOR_BUILD)
341 AC_SUBST(CFLAGS_FOR_BUILD)
342 AC_SUBST(HOST_CC)
343 AC_SUBST(BUILD_EXEEXT)
344
345 AM_CONDITIONAL(CROSS_COMPILING, [test x$cross_compiling = xyes])
346 AM_CONDITIONAL(USE_BATCH_FILES, [test x$host_win32 = xyes -a x$cross_compiling = xyes])
347
348 # Set STDC_HEADERS
349 AC_HEADER_STDC
350 AC_LIBTOOL_WIN32_DLL
351 # This causes monodis to not link correctly
352 #AC_DISABLE_FAST_INSTALL
353 AM_PROG_LIBTOOL
354 # Use dolt (http://dolt.freedesktop.org/) instead of libtool for building.
355 DOLT
356
357 export_ldflags=`(./libtool --config; echo eval echo \\$export_dynamic_flag_spec) | sh`
358 AC_SUBST(export_ldflags)
359
360 # Test whenever ld supports -version-script
361 AC_PROG_LD
362 AC_PROG_LD_GNU
363 if test "x$lt_cv_prog_gnu_ld" = "xno"; then
364    no_version_script=yes
365 fi
366
367 AM_CONDITIONAL(NO_VERSION_SCRIPT, test x$no_version_script = xyes)
368
369 AC_CHECK_HEADERS(sys/filio.h sys/sockio.h netdb.h utime.h sys/utime.h semaphore.h sys/un.h linux/rtc.h sys/syscall.h sys/mkdev.h sys/uio.h sys/param.h)
370 AC_CHECK_HEADERS(sys/param.h sys/socket.h sys/ipc.h sys/sem.h sys/utsname.h alloca.h ucontext.h pwd.h sys/select.h netinet/tcp.h netinet/in.h unistd.h sys/types.h link.h asm/sigcontext.h)
371 AC_CHECK_HEADERS([linux/netlink.h linux/rtnetlink.h],
372                   [], [], [#include <stddef.h>
373                   #include <sys/socket.h>
374                   #include <linux/socket.h>])
375
376 AC_CHECK_HEADERS(sys/user.h, [], [],
377 [
378 #ifdef HAVE_SYS_PARAM_H
379 # include <sys/param.h>
380 #endif
381 ])
382
383 AC_CHECK_HEADER(zlib.h, [have_zlib=yes], [have_zlib=no])
384 if test x$have_zlib = xyes; then
385    AC_TRY_COMPILE([#include <zlib.h>], [
386    #if defined(ZLIB_VERNUM) && (ZLIB_VERNUM >= 0x1230)
387    return 0;
388    #else
389    #error No good zlib found
390    #endif
391    ],[
392         AC_MSG_RESULT(Using system zlib)
393         zlib_msg="system zlib"
394         AC_DEFINE(HAVE_SYS_ZLIB,1,[Have system zlib])
395    ],[
396         AC_MSG_RESULT(Using embedded zlib)
397         have_zlib=no
398         zlib_msg="bundled zlib"
399    ])
400 fi
401
402 AM_CONDITIONAL(HAVE_ZLIB, test x$have_zlib = xyes)
403 AC_DEFINE(HAVE_ZLIB,1,[Have system zlib])
404
405 # for mono/metadata/debug-symfile.c
406 AC_CHECK_HEADERS(elf.h)
407
408 # for support
409 AC_CHECK_HEADERS(poll.h)
410 AC_CHECK_HEADERS(sys/poll.h)
411 AC_CHECK_HEADERS(sys/wait.h)
412 AC_CHECK_HEADERS(grp.h)
413 AC_CHECK_HEADERS(syslog.h)
414
415 # for mono/dis
416 AC_CHECK_HEADERS(wchar.h)
417 AC_CHECK_HEADERS(ieeefp.h)
418 AC_MSG_CHECKING(for isinf)
419 AC_TRY_LINK([#include <math.h>], [
420         int f = isinf (1);
421 ], [
422         AC_MSG_RESULT(yes)
423         AC_DEFINE(HAVE_ISINF, 1, [isinf available])
424 ], [
425         # We'll have to use signals
426         AC_MSG_RESULT(no)
427 ])
428
429
430 # not 64 bit clean in cross-compile
431 AC_CHECK_SIZEOF(void *, 4)
432
433 WARN=''
434 if test x"$GCC" = xyes; then
435         WARN='-Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes  -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wno-cast-qual -Wwrite-strings'
436                 # The runtime code does not respect ANSI C strict aliasing rules
437                 CFLAGS="$CFLAGS -fno-strict-aliasing"
438
439                 ORIG_CFLAGS=$CFLAGS
440                 CFLAGS="$CFLAGS -Wdeclaration-after-statement"
441                 AC_MSG_CHECKING(for -Wdeclaration-after-statement option to gcc)
442                 AC_TRY_COMPILE([], [
443                                                    void main () { }
444                 ], [
445                    AC_MSG_RESULT(yes)
446                 ], [
447                    AC_MSG_RESULT(no)
448                    CFLAGS=$ORIG_CFLAGS
449                 ])
450 else
451         # The Sun Forte compiler complains about inline functions that access static variables
452         # so disable all inlining.
453         case "$host" in
454         *-*-solaris*)
455                 CFLAGS="$CFLAGS -Dinline="
456                 ;;
457         esac
458 fi
459 CFLAGS="$CFLAGS -g $WARN"
460 CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC -g"
461
462 # Where's the 'mcs' source tree?
463 if test -d $srcdir/mcs; then
464   mcsdir=mcs
465 else
466   mcsdir=../mcs
467 fi
468
469 AC_ARG_WITH(mcs-path, [  --with-mcs-path=/path/to/mcs      Specify an alternate mcs source tree],
470         if test x$with_mcs_path != "x" -a -d $with_mcs_path ; then
471                 mcsdir=$with_mcs_path
472         fi
473 )
474
475 #
476 # A sanity check to catch cases where the package was unpacked
477 # with an ancient tar program (Solaris)
478 #
479 AC_ARG_ENABLE(solaris-tar-check,
480 [  --disable-solaris-tar-check    disable solaris tar check],
481    do_solaris_tar_check=no, do_solaris_tar_check=yes)
482
483 if test x"$do_solaris_tar_check" = xyes -a x"$enable_solaris_tar_check" = xyes; then
484         AC_MSG_CHECKING(integrity of package)
485         if test -f $mcsdir/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapTypeMapper.cs
486         then
487                 AC_MSG_RESULT(ok)
488         else
489                 errorm="Your mono distribution is incomplete;  if unpacking from a tar file, make sure you use GNU tar;  see http://www.mono-project.com/IncompletePackage for more details"
490                 AC_MSG_ERROR([$errorm])
491         fi
492 fi
493
494 if test "x$with_mcs_path" != "x"; then
495 mcs_topdir=$(cd "$mcsdir" && pwd)
496 mcs_topdir_from_srcdir=$mcs_topdir
497 else
498 mcs_topdir=$(cd "$srcdir/$mcsdir" && pwd)
499 mcs_topdir_from_srcdir='$(top_builddir)'/$mcsdir
500 fi
501
502 # Convert mcs_topdir* paths to Windows syntax.
503 if test x$cross_compiling$host_win32 = xnoyes; then
504   mcs_topdir=$(cygpath -m $mcs_topdir)
505   case $mcs_topdir_from_srcdir in
506     /cygdrive/*)
507         mcs_topdir_from_srcdir=$(cygpath -m $mcs_topdir_from_srcdir)
508         ;;
509   esac
510 fi
511
512 ## Maybe should also disable if mcsdir is invalid.  Let's punt the issue for now.
513 AM_CONDITIONAL(BUILD_MCS, [test x$cross_compiling = xno && test x$enable_mcs_build != xno])
514
515 AC_SUBST([mcs_topdir])
516 AC_SUBST([mcs_topdir_from_srcdir])
517
518 # Where's the 'olive' source tree?
519 if test -d $srcdir/olive; then
520   olivedir=olive
521 else
522   olivedir=../olive
523 fi
524
525 if test -d $srcdir/$olivedir; then
526 olive_topdir='$(top_srcdir)/'$olivedir
527 fi
528
529 # gettext: prepare the translation directories. 
530 # we do not configure the full gettext, as we consume it dynamically from C#
531 AM_PO_SUBDIRS
532
533 if test "x$USE_NLS" = "xyes"; then
534    AC_CHECK_PROG(HAVE_MSGFMT, msgfmt,yes,no)
535
536    if test "x$HAVE_MSGFMT" = "xno"; then
537           AC_MSG_ERROR([msgfmt not found. You need to install the 'gettext' package, or pass --enable-nls=no to configure.])
538    fi
539 fi
540
541 AC_ARG_WITH([libgdiplus], 
542         [  --with-libgdiplus=installed|sibling|<path>   Override the libgdiplus used for System.Drawing tests (defaults to installed)], 
543         [], [with_libgdiplus=installed])
544
545 case $with_libgdiplus in
546 no|installed) libgdiplus_loc= ;;
547 yes|sibling) libgdiplus_loc=`cd ../libgdiplus && pwd`/src/libgdiplus.la ;;
548 /*) libgdiplus_loc=$with_libgdiplus ;;
549 *) libgdiplus_loc=`pwd`/$with_libgdiplus ;;
550 esac
551 AC_SUBST([libgdiplus_loc])
552
553 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
554
555 pkg_config_path=
556 AC_ARG_WITH(crosspkgdir, [  --with-crosspkgdir=/path/to/pkg-config/dir      Change pkg-config dir to custom dir],
557         if test x$with_crosspkgdir = "x"; then
558                 if test -s $PKG_CONFIG_PATH; then
559                         pkg_config_path=$PKG_CONFIG_PATH
560                 fi
561         else
562                 pkg_config_path=$with_crosspkgdir
563                 PKG_CONFIG_PATH=$pkg_config_path
564                 export PKG_CONFIG_PATH
565         fi
566 )
567
568 ac_configure_args="$ac_configure_args \"CPPFLAGS_FOR_EGLIB=$EGLIB_CPPFLAGS\" \"CFLAGS_FOR_EGLIB=$CFLAGS_FOR_EGLIB\""
569 AC_CONFIG_SUBDIRS(eglib)
570
571 GLIB_CFLAGS='-I$(top_srcdir)/eglib/src -I$(top_builddir)/eglib/src'
572 GLIB_LIBS='-L$(top_builddir)/eglib/src -leglib -lm'
573 BUILD_GLIB_CFLAGS="$GLIB_CFLAGS"
574 BUILD_GLIB_LIBS="$GLIB_LIBS"
575 GMODULE_CFLAGS="$GLIB_CFLAGS"
576 GMODULE_LIBS="$GLIB_LIBS"
577   
578 AC_SUBST(GLIB_CFLAGS)
579 AC_SUBST(GLIB_LIBS)
580 AC_SUBST(GMODULE_CFLAGS)
581 AC_SUBST(GMODULE_LIBS)
582 AC_SUBST(BUILD_GLIB_CFLAGS)
583 AC_SUBST(BUILD_GLIB_LIBS)
584
585 AC_ARG_WITH(gc,   [  --with-gc=boehm,included,none  Controls the Boehm GC config, default=included],[gc=$with_gc],[gc=$gc_default])
586
587 # Enable support for fast thread-local storage
588 # Some systems have broken support, so we allow to disable it.
589 AC_ARG_WITH(tls, [  --with-tls=__thread,pthread    select Thread Local Storage implementation (defaults to __thread)],[],[with_tls=__thread])
590
591 # Enable support for using sigaltstack for SIGSEGV and stack overflow handling
592 # This does not work on some platforms (bug #55253)
593 AC_ARG_WITH(sigaltstack, [  --with-sigaltstack=yes,no      enable/disable support for sigaltstack (defaults to yes)],[],[with_sigaltstack=yes])
594
595 AC_ARG_WITH(static_mono, [  --with-static_mono=yes,no      link mono statically to libmono (faster) (defaults to yes)],[],[with_static_mono=yes])
596 AC_ARG_WITH(shared_mono, [  --with-shared_mono=yes,no      build a shared libmono library (defaults to yes)],[],[with_shared_mono=yes])
597
598 if test "x$enable_static" = "xno"; then
599    with_static_mono=no
600 fi
601
602 if test "x$enable_shared" = "xno"; then
603    with_shared_mono=no
604 fi
605
606 case $host in
607 *nacl* ) with_shared_mono=yes;;
608 esac
609
610 if test "x$host_win32" = "xyes"; then
611    # Boehm GC requires the runtime to be in its own dll
612    with_static_mono=no
613 fi
614
615 AM_CONDITIONAL(STATIC_MONO, test x$with_static_mono != xno)
616 AM_CONDITIONAL(SHARED_MONO, test x$with_shared_mono != xno)
617 AC_ARG_ENABLE(mcs-build, [  --disable-mcs-build disable the build of the mcs directory], try_mcs_build=$enableval, enable_mcs_build=yes)
618
619 AC_ARG_WITH(xen_opt,   [  --with-xen_opt=yes,no          Enable Xen-specific behaviour (defaults to yes)],[],[with_xen_opt=yes])
620 if test "x$with_xen_opt" = "xyes"; then
621         AC_DEFINE(MONO_XEN_OPT, 1, [Xen-specific behaviour])
622         ORIG_CFLAGS=$CFLAGS
623         CFLAGS="$CFLAGS -mno-tls-direct-seg-refs"
624         AC_MSG_CHECKING(for -mno-tls-direct-seg-refs option to gcc)
625         AC_TRY_COMPILE([], [
626                                            void main () { }
627         ], [
628            AC_MSG_RESULT(yes)
629            # Pass it to libgc as well
630            CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC -mno-tls-direct-seg-refs"
631         ], [
632            AC_MSG_RESULT(no)
633            CFLAGS=$ORIG_CFLAGS
634         ])
635 fi
636
637 AC_ARG_ENABLE(quiet-build, [  --enable-quiet-build  Enable quiet runtime build (on by default)], enable_quiet_build=$enableval, enable_quiet_build=yes)
638 AC_ARG_ENABLE(small-config, [  --enable-small-config Enable tweaks to reduce requirements (and capabilities)], enable_small_config=$enableval, enable_small_config=no)
639
640 if test x$enable_small_config = xyes; then
641         AC_DEFINE(MONO_SMALL_CONFIG,1,[Reduce runtime requirements (and capabilities)])
642         CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC -DSMALL_CONFIG"
643 fi
644
645 AC_ARG_ENABLE(system-aot, [  --enable-system-aot  Enable the Ahead-Of-Time compilation of system assemblies during the build (on by default on some platforms)], enable_system_aot=$enableval, enable_system_aot=default)
646
647 DISABLED_FEATURES=none
648
649 AC_ARG_ENABLE(minimal, [  --enable-minimal=LIST      drop support for LIST subsystems.
650      LIST is a comma-separated list from: aot, profiler, decimal, pinvoke, debug,
651      reflection_emit, reflection_emit_save, large_code, logging, com, ssa, generics, attach, jit, simd, soft_debug, normalization, assembly_remapping.],
652 [
653         for feature in `echo "$enable_minimal" | sed -e "s/,/ /g"`; do
654                 eval "mono_feature_disable_$feature='yes'"
655         done
656         DISABLED_FEATURES=$enable_minimal
657         disabled="Disabled:      $enable_minimal"
658 ],[])
659
660 AC_DEFINE_UNQUOTED(DISABLED_FEATURES, "$DISABLED_FEATURES", [String of disabled features])
661
662 if test "x$mono_feature_disable_aot" = "xyes"; then
663         AC_DEFINE(DISABLE_AOT_COMPILER, 1, [Disable AOT Compiler])
664         AC_MSG_NOTICE([Disabled AOT compiler])
665 fi
666
667 if test "x$mono_feature_disable_profiler" = "xyes"; then
668         AC_DEFINE(DISABLE_PROFILER, 1, [Disable default profiler support])
669         AC_MSG_NOTICE([Disabled support for the profiler])
670 fi
671 AM_CONDITIONAL(DISABLE_PROFILER, test x$mono_feature_disable_profiler = xyes)
672
673 if test "x$mono_feature_disable_decimal" = "xyes"; then
674         AC_DEFINE(DISABLE_DECIMAL, 1, [Disable System.Decimal support])
675         AC_MSG_NOTICE([Disabled support for decimal])
676 fi
677
678 if test "x$mono_feature_disable_pinvoke" = "xyes"; then
679         AC_DEFINE(DISABLE_PINVOKE, 1, [Disable P/Invoke support])
680         AC_MSG_NOTICE([Disabled support for P/Invoke])
681 fi
682
683 if test "x$mono_feature_disable_debug" = "xyes"; then
684         AC_DEFINE(DISABLE_DEBUG, 1, [Disable runtime debugging support])
685         AC_MSG_NOTICE([Disabled support for runtime debugging])
686 fi
687
688 if test "x$mono_feature_disable_reflection_emit" = "xyes"; then
689         AC_DEFINE(DISABLE_REFLECTION_EMIT, 1, [Disable reflection emit support])
690         mono_feature_disable_reflection_emit_save=yes
691         AC_MSG_NOTICE([Disabled support for Reflection.Emit])
692 fi
693
694 if test "x$mono_feature_disable_reflection_emit_save" = "xyes"; then
695         AC_DEFINE(DISABLE_REFLECTION_EMIT_SAVE, 1, [Disable assembly saving support in reflection emit])
696         AC_MSG_NOTICE([Disabled support for Reflection.Emit.Save])
697 fi
698
699 if test "x$mono_feature_disable_large_code" = "xyes"; then
700         AC_DEFINE(DISABLE_LARGE_CODE, 1, [Disable support for huge assemblies])
701         AC_MSG_NOTICE([Disabled support for large assemblies])
702 fi
703
704 if test "x$mono_feature_disable_logging" = "xyes"; then
705         AC_DEFINE(DISABLE_LOGGING, 1, [Disable support debug logging])
706         AC_MSG_NOTICE([Disabled support for logging])
707 fi
708
709 if test "x$mono_feature_disable_com" = "xyes"; then
710         AC_DEFINE(DISABLE_COM, 1, [Disable COM support])
711         AC_MSG_NOTICE([Disabled COM support])
712 fi
713
714 if test "x$mono_feature_disable_ssa" = "xyes"; then
715         AC_DEFINE(DISABLE_SSA, 1, [Disable advanced SSA JIT optimizations])
716         AC_MSG_NOTICE([Disabled SSA JIT optimizations])
717 fi
718
719 if test "x$mono_feature_disable_generics" = "xyes"; then
720         AC_DEFINE(DISABLE_GENERICS, 1, [Disable generics support])
721         AC_MSG_NOTICE([Disabled Generics Support])
722 fi
723
724 if test "x$mono_feature_disable_shadowcopy" = "xyes"; then
725         AC_DEFINE(DISABLE_SHADOW_COPY, 1, [Disable Shadow Copy for AppDomains])
726         AC_MSG_NOTICE([Disabled Shadow copy for AppDomains])
727 fi
728
729 if test "x$mono_feature_disable_portability" = "xyes"; then
730         AC_DEFINE(DISABLE_PORTABILITY, 1, [Disables the IO portability layer])
731         AC_MSG_NOTICE([Disabled IO Portability layer])
732 fi
733
734 if test "x$mono_feature_disable_attach" = "xyes"; then
735         AC_DEFINE(DISABLE_ATTACH, 1, [Disable agent attach support])
736         AC_MSG_NOTICE([Disabled agent attach])
737 fi
738
739 if test "x$mono_feature_disable_full_messages" = "xyes"; then
740         AC_DEFINE(DISABLE_FULL_MESSAGES, 1, [Disables building in the full table of WAPI messages])
741         AC_MSG_NOTICE([Disabled full messages for Win32 errors, only core message strings shipped])
742 fi
743
744 if test "x$mono_feature_disable_verifier" = "xyes"; then
745         AC_DEFINE(DISABLE_VERIFIER, 1, [Disables the verifier])
746         AC_MSG_NOTICE([Disabled the metadata and IL verifiers])
747 fi
748
749 if test "x$mono_feature_disable_jit" = "xyes"; then
750         AC_DEFINE(DISABLE_JIT, 1, [Disable the JIT, only full-aot mode will be supported by the runtime.])
751         AC_MSG_NOTICE([Disabled the JIT engine, only full AOT will be supported])
752 fi
753
754 AM_CONDITIONAL(DISABLE_JIT, test x$mono_feature_disable_jit = xyes)
755
756 if test "x$mono_feature_disable_simd" = "xyes"; then
757         AC_DEFINE(DISABLE_SIMD, 1, [Disable SIMD intrinsics related optimizations.])
758         AC_MSG_NOTICE([Disabled SIMD support])
759 fi
760
761 if test "x$mono_feature_disable_soft_debug" = "xyes"; then
762         AC_DEFINE(DISABLE_SOFT_DEBUG, 1, [Disable Soft Debugger Agent.])
763         AC_MSG_NOTICE([Disabled Soft Debugger.])
764 fi
765
766 if test "x$mono_feature_disable_normalization" = "xyes"; then
767         AC_DEFINE(DISABLE_NORMALIZATION, 1, [Disable String normalization support.])
768         AC_MSG_NOTICE([Disabled String normalization support.])
769 fi
770
771 if test "x$mono_feature_disable_assembly_remapping" = "xyes"; then
772         AC_DEFINE(DISABLE_ASSEMBLY_REMAPPING, 1, [Disable assembly remapping.])
773         AC_MSG_NOTICE([Disabled Assembly remapping.])
774 fi
775
776 AC_MSG_CHECKING(for visibility __attribute__)
777 AC_TRY_COMPILE([], [
778    void __attribute__ ((visibility ("hidden"))) doit (void) {}
779    void main () { doit (); }
780 ], [
781    have_visibility_hidden=yes
782    AC_MSG_RESULT(yes)
783 ], [
784    have_visibility_hidden=no
785    AC_MSG_RESULT(no)
786 ])
787
788 AC_MSG_CHECKING(for deprecated __attribute__)
789 AC_TRY_COMPILE([
790      int doit (void) __attribute__ ((deprecated));
791      int doit (void) { return 0; }
792 ], [
793         return 0;
794 ], [
795    have_deprecated=yes
796    AC_MSG_RESULT(yes)
797 ], [
798    have_deprecated=no
799    AC_MSG_RESULT(no)
800 ])
801
802 AC_ARG_ENABLE(parallel-mark, [  --enable-parallel-mark     Enables GC Parallel Marking], enable_parallel_mark=$enableval, enable_parallel_mark=$parallel_mark)
803 if test x$enable_parallel_mark = xyes; then
804         libgc_configure_args="$libgc_configure_args --enable-parallel-mark"
805 fi
806
807 dnl
808 dnl Boehm GC configuration
809 dnl
810 LIBGC_CFLAGS=
811 LIBGC_LIBS=
812 LIBGC_STATIC_LIBS=
813 libgc_dir=
814 case "x$gc" in
815         xboehm|xbohem|xyes)
816                 AC_CHECK_HEADERS(gc.h gc/gc.h, gc_headers=yes)
817                 AC_CHECK_LIB(gc, GC_malloc, found_boehm="yes",,$libdl)
818
819                 if test "x$found_boehm" != "xyes"; then
820                         AC_MSG_ERROR("GC requested but libgc not found! Install libgc or run configure with --with-gc=none.")
821                 fi
822                 if test "x$gc_headers" != "xyes"; then
823                         AC_MSG_ERROR("GC requested but header files not found! You may need to install them by hand.")
824                 fi
825
826                 LIBGC_LIBS="-lgc $libdl"
827                 LIBGC_STATIC_LIBS="$LIBGC_LIBS"
828                 libmono_ldflags="$libmono_ldflags -lgc"
829                 BOEHM_DEFINES="-DHAVE_BOEHM_GC"
830
831                 # AC_CHECK_FUNCS does not work for some reason...
832                 AC_CHECK_LIB(gc, GC_gcj_malloc, found_gcj_malloc="yes",,$libdl)
833                 if test "x$found_gcj_malloc" = "xyes"; then
834                         BOEHM_DEFINES="-DHAVE_GC_GCJ_MALLOC $BOEHM_DEFINES"
835                         AC_DEFINE_UNQUOTED(DEFAULT_GC_NAME, "System Boehm (with typed GC)", [GC description])
836                         gc_msg="System Boehm with typed GC"
837                 else
838                         AC_DEFINE_UNQUOTED(DEFAULT_GC_NAME, "System Boehm (no typed GC)", [GC description])
839                         gc_msg="System Boehm (without typed GC)"
840                 fi
841                 AC_CHECK_LIB(gc, GC_enable, found_gc_enable="yes",,$libdl)
842                 if test "x$found_gc_enable" = "xyes"; then
843                         BOEHM_DEFINES="-DHAVE_GC_ENABLE $BOEHM_DEFINES"
844                 fi
845
846                 # check whether we need to explicitly allow
847                 # thread registering
848                 AC_CHECK_LIB(gc, GC_allow_register_threads, found_allow_register_threads="yes",,$libdl)
849                 if test "x$found_allow_register_threads" = "xyes"; then
850                         AC_DEFINE(HAVE_GC_ALLOW_REGISTER_THREADS, 1, [GC requires thread registration])
851                 fi
852
853                 ;;
854
855         xincluded)
856                 use_included_gc=yes
857                 libgc_dir=libgc
858
859                 LIBGC_CFLAGS='-I$(top_srcdir)/libgc/include'
860                 LIBGC_LIBS='$(top_builddir)/libgc/libmonogc.la'
861                 LIBGC_STATIC_LIBS='$(top_builddir)/libgc/libmonogc-static.la'
862
863                 BOEHM_DEFINES="-DHAVE_BOEHM_GC -DHAVE_GC_H -DUSE_INCLUDED_LIBGC -DHAVE_GC_GCJ_MALLOC -DHAVE_GC_ENABLE"
864
865                 gc_msg="bundled Boehm GC with typed GC"
866                 if test x$enable_parallel_mark = xyes; then
867                         AC_DEFINE_UNQUOTED(DEFAULT_GC_NAME, "Included Boehm (with typed GC and Parallel Mark)", [GC description])
868                         gc_msg="$gc_msg and parallel mark"
869                 else
870                         AC_DEFINE_UNQUOTED(DEFAULT_GC_NAME, "Included Boehm (with typed GC)", [GC description])
871                 fi
872                 ;;
873
874         xsgen)
875                 AC_MSG_WARN("Use --with-sgen instead, --with-gc= controls Boehm configuration")
876                 ;;
877
878         xnone)
879                 AC_MSG_WARN("Compiling mono without GC.")
880                 AC_DEFINE_UNQUOTED(DEFAULT_GC_NAME, "none", [GC description])
881                 AC_DEFINE(HAVE_NULL_GC,1,[No GC support.])
882                 ;;
883         *)
884                 AC_MSG_ERROR([Invalid argument to --with-gc.])
885                 ;;
886 esac
887
888 AC_ARG_WITH(large-heap, [  --with-large-heap=yes,no       Enable support for GC heaps larger than 3GB (defaults to no)], [large_heap=$withval], [large_heap=no])
889 if test "x$large_heap" = "xyes"; then
890    CPPFLAGS="$CPPFLAGS -DLARGE_CONFIG"
891 fi
892
893 AM_CONDITIONAL(INCLUDED_LIBGC, test x$use_included_gc = xyes)
894 AC_SUBST(LIBGC_CFLAGS)
895 AC_SUBST(LIBGC_LIBS)
896 AC_SUBST(LIBGC_STATIC_LIBS)
897 AC_SUBST(libgc_dir)
898 AC_SUBST(BOEHM_DEFINES)
899
900 dnl
901 dnl End of libgc checks
902 dnl
903
904 dnl *************************************
905 dnl *** Checks for zero length arrays ***
906 dnl *************************************
907 AC_MSG_CHECKING(whether $CC supports zero length arrays)
908 AC_TRY_COMPILE([
909         struct s {
910                 int  length;
911                 char data [0];
912         };
913 ], [], [
914         AC_MSG_RESULT(yes)
915         AC_DEFINE_UNQUOTED(MONO_ZERO_LEN_ARRAY, 0, [Length of zero length arrays])
916 ], [
917         AC_MSG_RESULT(no)
918         AC_DEFINE_UNQUOTED(MONO_ZERO_LEN_ARRAY, 1, [Length of zero length arrays])
919 ])
920
921 if test x$target_win32 = xno; then
922
923         dnl hires monotonic clock support
924         AC_SEARCH_LIBS(clock_gettime, rt)
925
926         dnl dynamic loader support
927         AC_CHECK_FUNC(dlopen, DL_LIB="",
928                 AC_CHECK_LIB(dl, dlopen, DL_LIB="-ldl", dl_support=no)
929         )
930         if test x$dl_support = xno; then
931                 AC_MSG_WARN([No dynamic loading support available])
932         else
933                 LIBS="$LIBS $DL_LIB"
934                 AC_DEFINE(HAVE_DL_LOADER,1,[dlopen-based dynamic loader available])
935                 dnl from glib's configure.in
936                 AC_CACHE_CHECK([for preceeding underscore in symbols],
937                         mono_cv_uscore,[
938                         AC_TRY_RUN([#include <dlfcn.h>
939                         int mono_underscore_test (void) { return 42; }
940                         int main() {
941                           void *f1 = (void*)0, *f2 = (void*)0, *handle;
942                           handle = dlopen ((void*)0, 0);
943                           if (handle) {
944                             f1 = dlsym (handle, "mono_underscore_test");
945                             f2 = dlsym (handle, "_mono_underscore_test");
946                           } return (!f2 || f1);
947                         }],
948                                 [mono_cv_uscore=yes],
949                                 [mono_cv_uscore=no],
950                         [])
951                 ])
952                 if test "x$mono_cv_uscore" = "xyes"; then
953                         MONO_DL_NEED_USCORE=1
954                 else
955                         MONO_DL_NEED_USCORE=0
956                 fi
957                 AC_SUBST(MONO_DL_NEED_USCORE)
958                 AC_CHECK_FUNC(dlerror)
959         fi
960
961         dnl ******************************************************************
962         dnl *** Checks for the IKVM JNI interface library                  ***
963         dnl ******************************************************************
964         AC_ARG_WITH(ikvm-native, [  --with-ikvm-native=yes,no      build the IKVM JNI interface library (defaults to yes)],[with_ikvm_native=$withval],[with_ikvm_native=$ikvm_native])
965
966         ikvm_native_dir=
967         if test x$with_ikvm_native = xyes; then
968                 ikvm_native_dir=ikvm-native
969                 jdk_headers_found="IKVM Native"
970         fi
971
972         AC_SUBST(ikvm_native_dir)
973
974         AC_CHECK_HEADERS(execinfo.h)
975
976         AC_CHECK_FUNCS(getgrgid_r)
977         AC_CHECK_FUNCS(getgrnam_r)
978         AC_CHECK_FUNCS(getpwnam_r)
979         AC_CHECK_FUNCS(getpwuid_r)
980         AC_CHECK_FUNCS(getresuid)
981         AC_CHECK_FUNCS(setresuid)
982         AC_CHECK_FUNCS(kqueue)
983         AC_CHECK_FUNCS(backtrace_symbols)
984         AC_CHECK_FUNCS(mkstemp)
985         AC_CHECK_FUNCS(mmap)
986         AC_CHECK_FUNCS(madvise)
987         AC_CHECK_FUNCS(getrusage)
988         AC_CHECK_FUNCS(getpriority)
989         AC_CHECK_FUNCS(setpriority)
990         AC_CHECK_FUNCS(dl_iterate_phdr)
991         AC_CHECK_FUNCS(dladdr)
992         AC_CHECK_FUNCS(sysconf)
993
994         AC_CHECK_FUNCS(sched_setaffinity)
995         AC_CHECK_FUNCS(sched_getcpu)
996
997         dnl ****************************************************************
998         dnl *** Check for sched_setaffinity from glibc versions before   ***
999         dnl *** 2.3.4. The older versions of the function only take 2    ***
1000         dnl *** parameters, not 3.                                       ***
1001         dnl ***                                                          ***
1002         dnl *** Because the interface change was not made in a minor     ***
1003         dnl *** version rev, the __GLIBC__ and __GLIBC_MINOR__ macros    ***
1004         dnl *** won't always indicate the interface sched_affinity has.  ***
1005         dnl ****************************************************************
1006         AC_MSG_CHECKING(for sched_setaffinity from glibc < 2.3.4)
1007         AC_TRY_COMPILE([#include <sched.h>], [
1008                 int main() {
1009             int mask = 1; 
1010             sched_setaffinity(0, &mask);
1011         }
1012         ], [
1013                 # Yes, we have it...
1014                 AC_MSG_RESULT(yes)
1015                 AC_DEFINE(GLIBC_BEFORE_2_3_4_SCHED_SETAFFINITY, 1, [Have GLIBC_BEFORE_2_3_4_SCHED_SETAFFINITY])
1016         ], [
1017                 # We have the new, three-parameter version
1018                 AC_MSG_RESULT(no)
1019         ])
1020
1021
1022         dnl ******************************************************************
1023         dnl *** Check for large file support                               ***
1024         dnl *** (If we were using autoconf 2.50 we'd use AC_SYS_LARGEFILE) ***
1025         dnl ******************************************************************
1026         
1027         # Check that off_t can represent 2**63 - 1 correctly, working around
1028         # potential compiler bugs.  Defines LARGE_FILE_SUPPORT, adds $1 to
1029         # CPPFLAGS and sets $large_offt to yes if the test succeeds
1030         large_offt=no
1031         AC_DEFUN([LARGE_FILES], [
1032                 large_CPPFLAGS=$CPPFLAGS
1033                 CPPFLAGS="$CPPFLAGS $1"
1034                 AC_TRY_RUN([
1035                         #include <sys/types.h>
1036
1037                         #define BIG_OFF_T (((off_t)1<<62)-1+((off_t)1<<62))
1038
1039                         int main(void) {
1040                                 int big_off_t=((BIG_OFF_T%2147483629==721) &&
1041                                                (BIG_OFF_T%2147483647==1));
1042                                 if(big_off_t) {
1043                                         exit(0);
1044                                 } else {
1045                                         exit(1);
1046                                 }
1047                         }
1048                 ], [
1049                         AC_MSG_RESULT(ok)
1050                         AC_DEFINE(HAVE_LARGE_FILE_SUPPORT, 1, [Have large file support])
1051                         large_CPPFLAGS="$large_CPPFLAGS $1"
1052                         large_offt=yes
1053                 ], [
1054                         AC_MSG_RESULT(no)
1055                 ], "")
1056                 CPPFLAGS=$large_CPPFLAGS
1057         ])
1058
1059         AC_MSG_CHECKING(if off_t is 64 bits wide)
1060         LARGE_FILES("")
1061         if test $large_offt = no; then
1062                 AC_MSG_CHECKING(if _FILE_OFFSET_BITS=64 gives 64 bit off_t)
1063                 LARGE_FILES("-D_FILE_OFFSET_BITS=64")
1064         fi
1065         if test $large_offt = no; then
1066                 AC_MSG_WARN([No 64 bit file size support available])
1067         fi
1068         
1069         dnl *****************************
1070         dnl *** Checks for libsocket  ***
1071         dnl *****************************
1072         AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
1073
1074         dnl *******************************
1075         dnl *** Checks for MSG_NOSIGNAL ***
1076         dnl *******************************
1077         AC_MSG_CHECKING(for MSG_NOSIGNAL)
1078         AC_TRY_COMPILE([#include <sys/socket.h>], [
1079                 int f = MSG_NOSIGNAL;
1080         ], [
1081                 # Yes, we have it...
1082                 AC_MSG_RESULT(yes)
1083                 AC_DEFINE(HAVE_MSG_NOSIGNAL, 1, [Have MSG_NOSIGNAL])
1084         ], [
1085                 # We'll have to use signals
1086                 AC_MSG_RESULT(no)
1087         ])
1088
1089         dnl *****************************
1090         dnl *** Checks for SOL_IP     ***
1091         dnl *****************************
1092         AC_MSG_CHECKING(for SOL_IP)
1093         AC_TRY_COMPILE([#include <netdb.h>], [
1094                 int level = SOL_IP;
1095         ], [
1096                 # Yes, we have it...
1097                 AC_MSG_RESULT(yes)
1098                 AC_DEFINE(HAVE_SOL_IP, 1, [Have SOL_IP])
1099         ], [
1100                 # We'll have to use getprotobyname
1101                 AC_MSG_RESULT(no)
1102         ])
1103
1104         dnl *****************************
1105         dnl *** Checks for SOL_IPV6     ***
1106         dnl *****************************
1107         AC_MSG_CHECKING(for SOL_IPV6)
1108         AC_TRY_COMPILE([#include <netdb.h>], [
1109                 int level = SOL_IPV6;
1110         ], [
1111                 # Yes, we have it...
1112                 AC_MSG_RESULT(yes)
1113                 AC_DEFINE(HAVE_SOL_IPV6, 1, [Have SOL_IPV6])
1114         ], [
1115                 # We'll have to use getprotobyname
1116                 AC_MSG_RESULT(no)
1117         ])
1118
1119         dnl *****************************
1120         dnl *** Checks for SOL_TCP    ***
1121         dnl *****************************
1122         AC_MSG_CHECKING(for SOL_TCP)
1123         AC_TRY_COMPILE([#include <netdb.h>], [
1124                 int level = SOL_TCP;
1125         ], [
1126                 # Yes, we have it...
1127                 AC_MSG_RESULT(yes)
1128                 AC_DEFINE(HAVE_SOL_TCP, 1, [Have SOL_TCP])
1129         ], [
1130                 # We'll have to use getprotobyname
1131                 AC_MSG_RESULT(no)
1132         ])
1133
1134         dnl *****************************
1135         dnl *** Checks for IP_PKTINFO ***
1136         dnl *****************************
1137         AC_MSG_CHECKING(for IP_PKTINFO)
1138         AC_TRY_COMPILE([#include <netdb.h>], [
1139                 int level = IP_PKTINFO;
1140         ], [
1141                 # Yes, we have it...
1142                 AC_MSG_RESULT(yes)
1143                 AC_DEFINE(HAVE_IP_PKTINFO, 1, [Have IP_PKTINFO])
1144         ], [
1145                 AC_MSG_RESULT(no)
1146         ])
1147
1148         dnl *****************************
1149         dnl *** Checks for IPV6_PKTINFO ***
1150         dnl *****************************
1151         AC_MSG_CHECKING(for IPV6_PKTINFO)
1152         AC_TRY_COMPILE([#include <netdb.h>], [
1153                 int level = IPV6_PKTINFO;
1154         ], [
1155                 # Yes, we have it...
1156                 AC_MSG_RESULT(yes)
1157                 AC_DEFINE(HAVE_IPV6_PKTINFO, 1, [Have IPV6_PKTINFO])
1158         ], [
1159                 AC_MSG_RESULT(no)
1160         ])
1161
1162         dnl **********************************
1163         dnl *** Checks for IP_DONTFRAGMENT ***
1164         dnl **********************************
1165         AC_MSG_CHECKING(for IP_DONTFRAGMENT)
1166         AC_TRY_COMPILE([#include <netdb.h>], [
1167                 int level = IP_DONTFRAGMENT;
1168         ], [
1169                 # Yes, we have it...
1170                 AC_MSG_RESULT(yes)
1171                 AC_DEFINE(HAVE_IP_DONTFRAGMENT, 1, [Have IP_DONTFRAGMENT])
1172         ], [
1173                 AC_MSG_RESULT(no)
1174         ])
1175
1176         dnl **********************************
1177         dnl *** Checks for IP_MTU_DISCOVER ***
1178         dnl **********************************
1179         AC_MSG_CHECKING(for IP_MTU_DISCOVER)
1180         AC_TRY_COMPILE([#include <netdb.h>], [
1181                 int level = IP_MTU_DISCOVER;
1182         ], [
1183                 # Yes, we have it...
1184                 AC_MSG_RESULT(yes)
1185                 AC_DEFINE(HAVE_IP_MTU_DISCOVER, 1, [Have IP_MTU_DISCOVER])
1186         ], [
1187                 AC_MSG_RESULT(no)
1188         ])
1189
1190         dnl *********************************
1191         dnl *** Check for struct ip_mreqn ***
1192         dnl *********************************
1193         AC_MSG_CHECKING(for struct ip_mreqn)
1194         AC_TRY_COMPILE([#include <netinet/in.h>], [
1195                 struct ip_mreqn mreq;
1196                 mreq.imr_address.s_addr = 0;
1197         ], [
1198                 # Yes, we have it...
1199                 AC_MSG_RESULT(yes)
1200                 AC_DEFINE(HAVE_STRUCT_IP_MREQN, 1, [Have struct ip_mreqn])
1201         ], [
1202                 # We'll just have to try and use struct ip_mreq
1203                 AC_MSG_RESULT(no)
1204                 AC_MSG_CHECKING(for struct ip_mreq)
1205                 AC_TRY_COMPILE([#include <netinet/in.h>], [
1206                         struct ip_mreq mreq;
1207                         mreq.imr_interface.s_addr = 0;
1208                 ], [
1209                         # Yes, we have it...
1210                         AC_MSG_RESULT(yes)
1211                         AC_DEFINE(HAVE_STRUCT_IP_MREQ, 1, [Have struct ip_mreq])
1212                 ], [
1213                         # No multicast support
1214                         AC_MSG_RESULT(no)
1215                 ])
1216         ])
1217         
1218         dnl **********************************
1219         dnl *** Check for gethostbyname2_r ***
1220         dnl **********************************
1221         AC_MSG_CHECKING(for gethostbyname2_r)
1222                 AC_TRY_LINK([#include <netdb.h>], [
1223                 gethostbyname2_r(NULL,0,NULL,NULL,0,NULL,NULL);
1224         ], [
1225                 # Yes, we have it...
1226                 AC_MSG_RESULT(yes)
1227                 AC_DEFINE(HAVE_GETHOSTBYNAME2_R, 1, [Have gethostbyname2_r])
1228         ], [
1229                 AC_MSG_RESULT(no)
1230         ])
1231
1232         dnl *****************************
1233         dnl *** Checks for libnsl     ***
1234         dnl *****************************
1235         AC_CHECK_FUNC(gethostbyaddr, , AC_CHECK_LIB(nsl, gethostbyaddr, LIBS="$LIBS -lnsl"))
1236
1237         AC_CHECK_FUNCS(inet_pton inet_aton)
1238
1239         dnl ***********************************************
1240         dnl *** Checks for size of sockaddr_un.sun_path ***
1241         dnl ***********************************************
1242         # AC_CHECK_SIZEOF can't cope with struct members :-(
1243         AC_MSG_CHECKING(size of sockaddr_un.sun_path)
1244         AC_CACHE_VAL(mono_cv_sizeof_sunpath,
1245                 [AC_TRY_RUN([
1246                         #include <sys/types.h>
1247                         #include <stdio.h>
1248                         #include <sys/un.h>
1249
1250                         int main(void) {
1251                                 struct sockaddr_un sock_un;
1252                                 FILE *f=fopen("conftestval", "w");
1253                                 if(!f) exit(1);
1254                                 fprintf(f, "%d\n", sizeof(sock_un.sun_path));
1255                                 exit(0);
1256                         }
1257                 ], mono_cv_sizeof_sunpath=`cat conftestval`,
1258                    mono_cv_sizeof_sunpath=0,
1259                    mono_cv_sizeof_sunpath=0)])dnl
1260         AC_MSG_RESULT($mono_cv_sizeof_sunpath)
1261         AC_DEFINE_UNQUOTED(MONO_SIZEOF_SUNPATH, $mono_cv_sizeof_sunpath, [Sizeof sock_un.sun_path])
1262
1263         dnl *****************************
1264         dnl *** Checks for libxnet    ***
1265         dnl *****************************
1266         case "${host}" in
1267                 *solaris* )
1268                         AC_MSG_CHECKING(for Solaris XPG4 support)
1269                         if test -f /usr/lib/libxnet.so; then
1270                                 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=500"
1271                                 CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__"
1272                                 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE_EXTENDED=1"
1273                                 LIBS="$LIBS -lxnet"
1274                                 AC_MSG_RESULT(yes)
1275                         else
1276                                 AC_MSG_RESULT(no)
1277                         fi
1278
1279                         if test "$GCC" = "yes"; then
1280                                 CFLAGS="$CFLAGS -Wno-char-subscripts"
1281                         fi
1282                 ;;
1283         esac
1284
1285         dnl *****************************
1286         dnl *** Checks for libpthread ***
1287         dnl *****************************
1288 # on FreeBSD -STABLE, the pthreads functions all reside in libc_r
1289 # and libpthread does not exist
1290 #
1291         case "${host}" in
1292                 *-*-*freebsd*)
1293                         AC_CHECK_LIB(pthread, main, LIBS="$LIBS -pthread")
1294                 ;;
1295                 *-*-*openbsd*)
1296                         AC_CHECK_LIB(pthread, main, LIBS="$LIBS -pthread")
1297                 ;;
1298                 *)
1299                         AC_CHECK_LIB(pthread, main, LIBS="$LIBS -lpthread")
1300                 ;;
1301         esac
1302         AC_CHECK_HEADERS(pthread.h)
1303         AC_CHECK_FUNCS(pthread_mutex_timedlock)
1304         AC_CHECK_FUNCS(pthread_getattr_np pthread_attr_get_np)
1305         AC_MSG_CHECKING(for PTHREAD_MUTEX_RECURSIVE)
1306         AC_TRY_COMPILE([ #include <pthread.h>], [
1307                 pthread_mutexattr_t attr;
1308                 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
1309         ], [
1310                 AC_MSG_RESULT(ok)
1311         ], [
1312                 AC_MSG_RESULT(no)
1313                 AC_MSG_WARN(Using mono_mutex_t for recursive mutexes)
1314                 AC_DEFINE(USE_MONO_MUTEX, 1, [Use mono_mutex_t])
1315         ])
1316         AC_CHECK_FUNCS(pthread_attr_setstacksize)
1317         AC_CHECK_FUNCS(pthread_attr_getstack pthread_attr_getstacksize)
1318         AC_CHECK_FUNCS(pthread_get_stacksize_np pthread_get_stackaddr_np)
1319
1320         dnl ***********************************
1321         dnl *** Checks for signals
1322         dnl ***********************************
1323         AC_CHECK_HEADERS(signal.h)
1324         AC_CHECK_FUNCS(sigaction)
1325
1326         dnl ***********************************
1327         dnl *** Checks for working __thread ***
1328         dnl ***********************************
1329         AC_MSG_CHECKING(for working __thread)
1330         if test "x$with_tls" != "x__thread"; then
1331                 AC_MSG_RESULT(disabled)
1332         else
1333                 AC_TRY_RUN([
1334                         #include <pthread.h>
1335                         __thread int i;
1336                         static int res1, res2;
1337
1338                         void thread_main (void *arg)
1339                         {
1340                                 i = arg;
1341                                 sleep (1);
1342                                 if (arg == 1)
1343                                         res1 = (i == arg);
1344                                 else
1345                                         res2 = (i == arg);
1346                         }
1347
1348                         int main () {
1349                                 pthread_t t1, t2;
1350
1351                                 i = 5;
1352
1353                                 pthread_create (&t1, NULL, thread_main, 1);
1354                                 pthread_create (&t2, NULL, thread_main, 2);
1355
1356                                 pthread_join (t1, NULL);
1357                                 pthread_join (t2, NULL);
1358
1359                                 return !(res1 + res2 == 2);
1360                         }
1361                 ], [
1362                                 AC_MSG_RESULT(yes)
1363                 ], [
1364                                 AC_MSG_RESULT(no)
1365                                 with_tls=pthread
1366                 ])
1367         fi
1368
1369         dnl **************************************
1370         dnl *** Checks for working sigaltstack ***
1371         dnl **************************************
1372         AC_MSG_CHECKING(for working sigaltstack)
1373         if test "x$with_sigaltstack" != "xyes"; then
1374                 AC_MSG_RESULT(disabled)
1375         else
1376                 AC_TRY_RUN([
1377                         #include <stdio.h>
1378                         #include <stdlib.h>
1379                         #include <unistd.h>
1380                         #include <signal.h>
1381                         #include <pthread.h>
1382                         #include <sys/wait.h>
1383                         #if defined(__FreeBSD__) || defined(__NetBSD__)
1384                         #define SA_STACK SA_ONSTACK
1385                         #endif
1386                         static void
1387                         sigsegv_signal_handler (int _dummy, siginfo_t *info, void *context)
1388                         {
1389                                 exit (0);
1390                         }
1391
1392                         static void *
1393                         loop (void *ignored)
1394                         {
1395                                 char *ptr = NULL;
1396
1397                                 *ptr = 0;
1398                                 return NULL;
1399                         }
1400
1401                         static void
1402                         child ()
1403                         {
1404                                 struct sigaction sa;
1405                                 struct sigaltstack sas;
1406                                 pthread_t id;
1407                                 pthread_attr_t attr;
1408
1409                                 sa.sa_sigaction = sigsegv_signal_handler;
1410                                 sigemptyset (&sa.sa_mask);
1411                                 sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
1412                                 if (sigaction (SIGSEGV, &sa, NULL) == -1) {
1413                                         perror ("sigaction");
1414                                         return;
1415                                 }
1416
1417                                 sas.ss_sp = malloc (SIGSTKSZ);
1418                                 sas.ss_size = SIGSTKSZ;
1419                                 sas.ss_flags = 0;
1420                                 if (sigaltstack (&sas, NULL) == -1) {
1421                                         perror ("sigaltstack");
1422                                         return;
1423                                 }
1424
1425                                 pthread_attr_init (&attr);
1426                                 if (pthread_create(&id, &attr, loop, &attr) != 0) {
1427                                         printf ("pthread_create\n");
1428                                         return;
1429                                 }
1430
1431                                 sleep (100);
1432                         }
1433
1434                         int
1435                         main ()
1436                         {
1437                                 pid_t son;
1438                                 int status;
1439                                 int i;
1440
1441                                 son = fork ();
1442                                 if (son == -1) {
1443                                         return 1;
1444                                 }
1445
1446                                 if (son == 0) {
1447                                         child ();
1448                                         return 0;
1449                                 }
1450
1451                                 for (i = 0; i < 3; ++i) {
1452                                         sleep (1);
1453                                         waitpid (son, &status, WNOHANG);
1454                                         if (WIFEXITED (status) && WEXITSTATUS (status) == 0)
1455                                                 return 0;
1456                                 }
1457
1458                                 kill (son, SIGKILL);
1459                                 return 1;
1460                         }
1461
1462                 ], [
1463                                 AC_MSG_RESULT(yes)
1464                                 AC_DEFINE(HAVE_WORKING_SIGALTSTACK, 1, [Have a working sigaltstack])
1465                 ], [
1466                                 with_sigaltstack=no
1467                                 AC_MSG_RESULT(no)
1468                 ])
1469         fi
1470
1471         dnl ********************************
1472         dnl *** Checks for semaphore lib ***
1473         dnl ********************************
1474         # 'Real Time' functions on Solaris
1475         # posix4 on Solaris 2.6
1476         # pthread (first!) on Linux
1477         AC_SEARCH_LIBS(sem_init, pthread rt posix4) 
1478
1479         AC_SEARCH_LIBS(shm_open, pthread rt posix4) 
1480         AC_CHECK_FUNCS(shm_open)
1481
1482         dnl ********************************
1483         dnl *** Checks for timezone stuff **
1484         dnl ********************************
1485         AC_CACHE_CHECK(for tm_gmtoff in struct tm, ac_cv_struct_tm_gmtoff,
1486                 AC_TRY_COMPILE([
1487                         #include <time.h>
1488                         ], [
1489                         struct tm tm;
1490                         tm.tm_gmtoff = 1;
1491                         ], ac_cv_struct_tm_gmtoff=yes, ac_cv_struct_tm_gmtoff=no))
1492         if test $ac_cv_struct_tm_gmtoff = yes; then
1493                 AC_DEFINE(HAVE_TM_GMTOFF, 1, [Have tm_gmtoff])
1494         else
1495                 AC_CACHE_CHECK(for timezone variable, ac_cv_var_timezone,
1496                         AC_TRY_COMPILE([
1497                                 #include <time.h>
1498                         ], [
1499                                 timezone = 1;
1500                         ], ac_cv_var_timezone=yes, ac_cv_var_timezone=no))
1501                 if test $ac_cv_var_timezone = yes; then
1502                         AC_DEFINE(HAVE_TIMEZONE, 1, [Have timezone variable])
1503                 else
1504                         AC_ERROR(unable to find a way to determine timezone)
1505                 fi
1506         fi
1507
1508         dnl *********************************
1509         dnl *** Checks for math functions ***
1510         dnl *********************************
1511         AC_SEARCH_LIBS(sqrtf, m)
1512         if test "x$has_broken_apple_cpp" != "xyes"; then
1513                 AC_CHECK_FUNCS(finite, , AC_MSG_CHECKING(for finite in math.h)
1514                         AC_TRY_LINK([#include <math.h>], 
1515                         [ finite(0.0); ], 
1516                         AC_DEFINE(HAVE_FINITE, 1, [Have finite in -lm]) AC_MSG_RESULT(yes),
1517                         AC_MSG_RESULT(no)))
1518         fi
1519         AC_CHECK_FUNCS(isfinite, , AC_MSG_CHECKING(for isfinite in math.h)
1520                 AC_TRY_LINK([#include <math.h>], 
1521                 [ isfinite(0.0); ], 
1522                 AC_DEFINE(HAVE_ISFINITE, 1, [Have isfinite]) AC_MSG_RESULT(yes),
1523                 AC_MSG_RESULT(no)))
1524
1525         dnl ****************************************************************
1526         dnl *** Checks for working poll() (macosx defines it but doesn't ***
1527         dnl *** have it in the library (duh))                            ***
1528         dnl ****************************************************************
1529         AC_CHECK_FUNCS(poll)
1530
1531         dnl *************************
1532         dnl *** Check for signbit ***
1533         dnl *************************
1534         AC_MSG_CHECKING(for signbit)
1535         AC_TRY_LINK([#include <math.h>], [
1536                 int s = signbit(1.0);
1537         ], [
1538                 AC_MSG_RESULT(yes)
1539                 AC_DEFINE(HAVE_SIGNBIT, 1, [Have signbit])
1540         ], [
1541                 AC_MSG_RESULT(no)
1542         ]) 
1543
1544         dnl **********************************
1545         dnl *** epoll                      ***
1546         dnl **********************************
1547         AC_CHECK_HEADERS(sys/epoll.h)
1548         haveepoll=no
1549         AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], )
1550         if test "x$haveepoll" = "xyes" -a "x$ac_cv_header_sys_epoll_h" = "xyes" ; then
1551                 AC_DEFINE(HAVE_EPOLL, 1, [epoll supported])
1552         fi
1553
1554         havekqueue=no
1555         AC_CHECK_FUNCS(kqueue, , AC_MSG_CHECKING(for kqueue in sys/event.h)
1556                 AC_TRY_LINK([#include <sys/event.h>], 
1557                 [ kqueue(); ], 
1558                 AC_DEFINE(HAVE_KQUEUE, 1, [Have kqueue]) AC_MSG_RESULT(yes),
1559                 AC_MSG_RESULT(no)))
1560         dnl ******************************
1561         dnl *** Checks for SIOCGIFCONF ***
1562         dnl ******************************
1563         AC_CHECK_HEADERS(sys/ioctl.h)
1564         AC_CHECK_HEADERS(net/if.h, [], [],
1565            [
1566            #ifdef HAVE_SYS_TYPES_H
1567            # include <sys/types.h>
1568            #endif
1569            #ifdef HAVE_SYS_SOCKET_H
1570            # include <sys/socket.h>
1571            #endif
1572            ])
1573         AC_MSG_CHECKING(for ifreq)
1574         AC_TRY_COMPILE([
1575                 #include <stdio.h>
1576                 #include <sys/ioctl.h>
1577                 #include <net/if.h>
1578                 ], [
1579                 struct ifconf ifc;
1580                 struct ifreq *ifr;
1581                 void *x;
1582                 ifc.ifc_len = 0;
1583                 ifc.ifc_buf = NULL;
1584                 x = (void *) &ifr->ifr_addr;
1585                 ],[
1586                         AC_MSG_RESULT(yes)
1587                         AC_DEFINE(HAVE_SIOCGIFCONF, 1, [Can get interface list])
1588                 ], [
1589                         AC_MSG_RESULT(no)
1590                 ])
1591         dnl **********************************
1592         dnl ***     Checks for sin_len     ***
1593         dnl **********************************
1594         AC_MSG_CHECKING(for sockaddr_in.sin_len)
1595         AC_TRY_COMPILE([
1596                 #include <netinet/in.h>
1597                 ], [
1598                 struct sockaddr_in saddr;
1599                 saddr.sin_len = sizeof (saddr);
1600                 ],[
1601                         AC_MSG_RESULT(yes)
1602                         AC_DEFINE(HAVE_SOCKADDR_IN_SIN_LEN, 1, [sockaddr_in has sin_len])
1603                 ], [
1604                         AC_MSG_RESULT(no)
1605                 ])      
1606         dnl **********************************
1607         dnl ***    Checks for sin6_len     ***
1608         dnl **********************************
1609         AC_MSG_CHECKING(for sockaddr_in6.sin6_len)
1610         AC_TRY_COMPILE([
1611                 #include <netinet/in.h>
1612                 ], [
1613                 struct sockaddr_in6 saddr6;
1614                 saddr6.sin6_len = sizeof (saddr6);
1615                 ],[
1616                         AC_MSG_RESULT(yes)
1617                         AC_DEFINE(HAVE_SOCKADDR_IN6_SIN_LEN, 1, [sockaddr_in6 has sin6_len])
1618                 ], [
1619                         AC_MSG_RESULT(no)
1620                 ])      
1621         dnl **********************************
1622         dnl *** Checks for MonoPosixHelper ***
1623         dnl **********************************
1624         AC_CHECK_HEADERS(checklist.h)
1625         AC_CHECK_HEADERS(pathconf.h)
1626         AC_CHECK_HEADERS(fstab.h)
1627         AC_CHECK_HEADERS(attr/xattr.h)
1628         AC_CHECK_HEADERS(sys/extattr.h)
1629         AC_CHECK_HEADERS(sys/sendfile.h)
1630         AC_CHECK_HEADERS(sys/statvfs.h)
1631         AC_CHECK_HEADERS(sys/statfs.h)
1632         AC_CHECK_HEADERS(sys/vfstab.h)
1633         AC_CHECK_HEADERS(sys/xattr.h)
1634         AC_CHECK_HEADERS(sys/mman.h)
1635         AC_CHECK_HEADERS(sys/param.h)
1636         AC_CHECK_HEADERS(sys/mount.h, [], [],
1637                 [
1638                 #ifdef HAVE_SYS_PARAM_H
1639                 # include <sys/param.h>
1640                 #endif
1641                 ])
1642         AC_CHECK_HEADERS(sys/mount.h)
1643         AC_CHECK_FUNCS(confstr)
1644         AC_CHECK_FUNCS(seekdir telldir)
1645         AC_CHECK_FUNCS(getdomainname)
1646         AC_CHECK_FUNCS(setdomainname)
1647         AC_CHECK_FUNCS(endgrent getgrent fgetgrent setgrent)
1648         AC_CHECK_FUNCS(setgroups)
1649         AC_CHECK_FUNCS(endpwent getpwent fgetpwent setpwent)
1650         AC_CHECK_FUNCS(getfsstat)
1651         AC_CHECK_FUNCS(lutimes futimes)
1652         AC_CHECK_FUNCS(mremap)
1653         AC_CHECK_FUNCS(remap_file_pages)
1654         AC_CHECK_FUNCS(posix_fadvise)
1655         AC_CHECK_FUNCS(posix_fallocate)
1656         AC_CHECK_FUNCS(posix_madvise)
1657         AC_CHECK_FUNCS(vsnprintf)
1658         AC_CHECK_FUNCS(sendfile)
1659         AC_CHECK_FUNCS(gethostid sethostid)
1660         AC_CHECK_FUNCS(sethostname)
1661         AC_CHECK_FUNCS(statfs)
1662         AC_CHECK_FUNCS(fstatfs)
1663         AC_CHECK_FUNCS(statvfs)
1664         AC_CHECK_FUNCS(fstatvfs)
1665         AC_CHECK_FUNCS(stime)
1666         AC_CHECK_FUNCS(strerror_r)
1667         AC_CHECK_FUNCS(ttyname_r)
1668         AC_CHECK_FUNCS(psignal)
1669         AC_CHECK_FUNCS(getlogin_r)
1670         AC_CHECK_FUNCS(lockf)
1671         AC_CHECK_FUNCS(swab)
1672         AC_CHECK_FUNCS(setusershell endusershell)
1673         AC_CHECK_SIZEOF(size_t)
1674         AC_CHECK_TYPES([blksize_t], [AC_DEFINE(HAVE_BLKSIZE_T)], , 
1675                 [#include <sys/types.h>
1676                  #include <sys/stat.h>
1677                  #include <unistd.h>])
1678         AC_CHECK_TYPES([blkcnt_t], [AC_DEFINE(HAVE_BLKCNT_T)], ,
1679                 [#include <sys/types.h>
1680                  #include <sys/stat.h>
1681                  #include <unistd.h>])
1682         AC_CHECK_TYPES([suseconds_t], [AC_DEFINE(HAVE_SUSECONDS_T)], ,
1683                 [#include <sys/time.h>])
1684         AC_CHECK_TYPES([struct flock], [AC_DEFINE(HAVE_STRUCT_FLOCK)], ,
1685                 [#include <unistd.h>
1686                  #include <fcntl.h>])
1687         AC_CHECK_TYPES([struct pollfd], [AC_DEFINE(HAVE_STRUCT_POLLFD)], ,
1688                 [#include <sys/poll.h>])
1689         AC_CHECK_TYPES([struct stat], [AC_DEFINE(HAVE_STRUCT_STAT)], ,
1690                 [#include <sys/types.h>
1691                  #include <sys/stat.h>
1692                  #include <unistd.h>])
1693         AC_CHECK_TYPES([struct timespec], [AC_DEFINE(HAVE_STRUCT_TIMESPEC)], ,
1694                 [#include <time.h>])
1695         AC_CHECK_TYPES([struct timeval], [AC_DEFINE(HAVE_STRUCT_TIMEVAL)], ,
1696                 [#include <sys/time.h>
1697                  #include <sys/types.h>
1698                  #include <utime.h>])
1699         AC_CHECK_TYPES([struct timezone], [AC_DEFINE(HAVE_STRUCT_TIMEZONE)], ,
1700                 [#include <sys/time.h>])
1701         AC_CHECK_TYPES([struct utimbuf], [AC_DEFINE(HAVE_STRUCT_UTIMBUF)], ,
1702                 [#include <sys/types.h>
1703                  #include <utime.h>])
1704         AC_CHECK_MEMBERS(
1705                 [struct dirent.d_off, struct dirent.d_reclen, struct dirent.d_type],,, 
1706                 [#include <sys/types.h>
1707                  #include <dirent.h>])
1708         AC_CHECK_MEMBERS(
1709                 [struct passwd.pw_gecos],,, 
1710                 [#include <sys/types.h>
1711                  #include <pwd.h>])
1712         AC_CHECK_MEMBERS(
1713                 [struct statfs.f_flags],,, 
1714                 [#include <sys/types.h>
1715                  #include <sys/vfs.h>])
1716
1717         dnl Favour xattr through glibc, but use libattr if we have to
1718         AC_CHECK_FUNC(lsetxattr, ,
1719                 AC_CHECK_LIB(attr, lsetxattr, XATTR_LIB="-lattr",)
1720         )
1721         AC_SUBST(XATTR_LIB)
1722
1723         dnl kinfo_proc.kp_proc works on darwin but fails on other simil-bsds
1724         AC_CHECK_MEMBERS(
1725                 [struct kinfo_proc.kp_proc],,, 
1726                 [#include <sys/types.h>
1727                  #include <sys/param.h>
1728                  #include <sys/sysctl.h>
1729                  #include <sys/proc.h>
1730                  ])
1731
1732         dnl *********************************
1733         dnl *** Checks for Windows compilation ***
1734         dnl *********************************
1735         AC_CHECK_HEADERS(sys/time.h)
1736         AC_CHECK_HEADERS(sys/param.h)
1737         AC_CHECK_HEADERS(dirent.h)
1738
1739         dnl *********************************
1740         dnl *** Check for Console 2.0 I/O ***
1741         dnl *********************************
1742         AC_CHECK_HEADERS([curses.h])
1743         AC_CHECK_HEADERS([term.h], [], [],
1744         [#if HAVE_CURSES_H
1745          #include <curses.h>
1746          #endif
1747         ])
1748         AC_CHECK_HEADERS([termios.h])
1749
1750         dnl * This is provided in io-layer, but on windows it's only available
1751         dnl * on xp+
1752         AC_DEFINE(HAVE_GETPROCESSID, 1, [Define if GetProcessId is available])
1753 else
1754         dnl *********************************
1755         dnl *** Checks for Windows compilation ***
1756         dnl *********************************
1757         AC_CHECK_HEADERS(winternl.h)
1758
1759         jdk_headers_found=no
1760         AC_CHECK_LIB(ws2_32, main, LIBS="$LIBS -lws2_32", AC_ERROR(bad mingw install?))
1761         AC_CHECK_LIB(psapi, main, LIBS="$LIBS -lpsapi", AC_ERROR(bad mingw install?))
1762         AC_CHECK_LIB(ole32, main, LIBS="$LIBS -lole32", AC_ERROR(bad mingw install?))
1763         AC_CHECK_LIB(winmm, main, LIBS="$LIBS -lwinmm", AC_ERROR(bad mingw install?))
1764         AC_CHECK_LIB(oleaut32, main, LIBS="$LIBS -loleaut32", AC_ERROR(bad mingw install?))
1765         AC_CHECK_LIB(advapi32, main, LIBS="$LIBS -ladvapi32", AC_ERROR(bad mingw install?))
1766         AC_CHECK_LIB(version, main, LIBS="$LIBS -lversion", AC_ERROR(bad mingw install?))
1767
1768         dnl *********************************
1769         dnl *** Check for struct ip_mreqn ***
1770         dnl *********************************
1771         AC_MSG_CHECKING(for struct ip_mreqn)
1772         AC_TRY_COMPILE([#include <ws2tcpip.h>], [
1773                 struct ip_mreqn mreq;
1774                 mreq.imr_address.s_addr = 0;
1775         ], [
1776                 # Yes, we have it...
1777                 AC_MSG_RESULT(yes)
1778                 AC_DEFINE(HAVE_STRUCT_IP_MREQN)
1779         ], [
1780                 # We'll just have to try and use struct ip_mreq
1781                 AC_MSG_RESULT(no)
1782                 AC_MSG_CHECKING(for struct ip_mreq)
1783                 AC_TRY_COMPILE([#include <ws2tcpip.h>], [
1784                         struct ip_mreq mreq;
1785                         mreq.imr_interface.s_addr = 0;
1786                 ], [
1787                         # Yes, we have it...
1788                         AC_MSG_RESULT(yes)
1789                         AC_DEFINE(HAVE_STRUCT_IP_MREQ)
1790                 ], [
1791                         # No multicast support
1792                         AC_MSG_RESULT(no)
1793                 ])
1794         ])
1795         AC_CHECK_FUNCS(GetProcessId)
1796 fi
1797
1798 dnl socklen_t check
1799 AC_MSG_CHECKING(for socklen_t)
1800 AC_TRY_COMPILE([
1801 #include <sys/types.h>
1802 #include <sys/socket.h>
1803 ],[
1804   socklen_t foo;
1805 ],[
1806 ac_cv_c_socklen_t=yes
1807         AC_DEFINE(HAVE_SOCKLEN_T, 1, [Have socklen_t])
1808         AC_MSG_RESULT(yes)
1809 ],[
1810         AC_MSG_RESULT(no)
1811 ])
1812
1813 AC_MSG_CHECKING(for array element initializer support)
1814 AC_TRY_COMPILE([#include <sys/socket.h>], [
1815         const int array[] = {[1] = 2,};
1816 ], [
1817         # Yes, we have it...
1818         AC_MSG_RESULT(yes)
1819         AC_DEFINE(HAVE_ARRAY_ELEM_INIT,1,[Supports C99 array initialization])
1820 ], [
1821         # We'll have to use signals
1822         AC_MSG_RESULT(no)
1823 ])
1824
1825 AC_CHECK_FUNCS(trunc, , AC_MSG_CHECKING(for trunc in math.h)
1826         # Simply calling trunc (0.0) is no good since gcc will optimize the call away
1827         AC_TRY_LINK([#include <math.h>], 
1828         [ static void *p = &trunc; ],
1829         [
1830                 AC_DEFINE(HAVE_TRUNC) 
1831                 AC_MSG_RESULT(yes)
1832                 ac_cv_trunc=yes
1833         ],
1834         AC_MSG_RESULT(no)))
1835
1836 if test "x$ac_cv_truncl" != "xyes"; then
1837    AC_CHECK_LIB(sunmath, aintl, [ AC_DEFINE(HAVE_AINTL, 1, [Has the 'aintl' function]) LIBS="$LIBS -lsunmath"])
1838 fi
1839
1840 AC_CHECK_FUNCS(round)
1841 AC_CHECK_FUNCS(rint)
1842 AC_CHECK_FUNCS(execvp)
1843
1844 dnl ****************************
1845 dnl *** Look for /dev/random ***
1846 dnl ****************************
1847
1848 AC_MSG_CHECKING([if usage of random device is requested])
1849 AC_ARG_ENABLE(dev-random,
1850 [  --disable-dev-random    disable the use of the random device (enabled by default)],
1851 try_dev_random=$enableval, try_dev_random=yes)
1852
1853 AC_MSG_RESULT($try_dev_random)
1854
1855 case "{$build}" in
1856     *-openbsd*)
1857     NAME_DEV_RANDOM="/dev/srandom"
1858     ;;
1859
1860 dnl Win32 does not have /dev/random, they have their own method...
1861
1862     *-mingw*|*-*-cygwin*)
1863     ac_cv_have_dev_random=no
1864     ;;
1865
1866 dnl Everywhere else, it's /dev/random
1867
1868     *)
1869     NAME_DEV_RANDOM="/dev/random"
1870     ;;
1871 esac
1872
1873 AC_DEFINE_UNQUOTED(NAME_DEV_RANDOM, "$NAME_DEV_RANDOM", [Name of /dev/random])
1874
1875 dnl Now check if the device actually exists
1876
1877 if test "x$try_dev_random" = "xyes"; then
1878     AC_CACHE_CHECK(for random device, ac_cv_have_dev_random,
1879     [if test -r "$NAME_DEV_RANDOM" ; then
1880         ac_cv_have_dev_random=yes; else ac_cv_have_dev_random=no; fi])
1881     if test "x$ac_cv_have_dev_random" = "xyes"; then
1882         AC_DEFINE(HAVE_CRYPT_RNG, 1, [Have /dev/random])
1883     fi
1884 else
1885     AC_MSG_CHECKING(for random device)
1886     ac_cv_have_dev_random=no
1887     AC_MSG_RESULT(has been disabled)
1888 fi
1889
1890 if test "x$host_win32" = "xyes"; then
1891     AC_DEFINE(HAVE_CRYPT_RNG)
1892 fi
1893
1894 if test "x$ac_cv_have_dev_random" = "xno" \
1895     && test "x$host_win32" = "xno"; then
1896     AC_MSG_WARN([[
1897 ***
1898 *** A system-provided entropy source was not found on this system.
1899 *** Because of this, the System.Security.Cryptography random number generator
1900 *** will throw a NotImplemented exception.
1901 ***
1902 *** If you are seeing this message, and you know your system DOES have an
1903 *** entropy collection in place, please contact <crichton@gimp.org> and
1904 *** provide information about the system and how to access the random device.
1905 ***
1906 *** Otherwise you can install either egd or prngd and set the environment
1907 *** variable MONO_EGD_SOCKET to point to the daemon's socket to use that.
1908 ***]])
1909 fi
1910  
1911 AC_MSG_CHECKING([if inter-process shared handles are requested])
1912 AC_ARG_ENABLE(shared-handles, [  --disable-shared-handles disable inter-process shared handles], try_shared_handles=$enableval, try_shared_handles=yes)
1913 AC_MSG_RESULT($try_shared_handles)
1914 if test "x$try_shared_handles" != "xyes"; then
1915         AC_DEFINE(DISABLE_SHARED_HANDLES, 1, [Disable inter-process shared handles])
1916         AC_SUBST(DISABLE_SHARED_HANDLES)
1917 fi
1918
1919 AC_ARG_ENABLE(nunit-tests, [  --enable-nunit-tests      Run the nunit tests of the class library on 'make check'])
1920 AM_CONDITIONAL(ENABLE_NUNIT_TESTS, [test x$enable_nunit_tests = xyes])
1921
1922 AC_MSG_CHECKING([if big-arrays are to be enabled])
1923 AC_ARG_ENABLE(big-arrays,  [  --enable-big-arrays       Enable the allocation and indexing of arrays greater than Int32.MaxValue], enable_big_arrays=$enableval, enable_big_arrays=no)
1924 if test "x$enable_big_arrays" = "xyes" ; then
1925     if  test "x$ac_cv_sizeof_void_p" = "x8"; then
1926         AC_DEFINE(MONO_BIG_ARRAYS,1,[Enable the allocation and indexing of arrays greater than Int32.MaxValue])
1927     else
1928         AC_MSG_ERROR([The allocation and indexing of arrays greater than Int32.MaxValue is not supported on this platform.])
1929     fi
1930 fi
1931 AC_MSG_RESULT($enable_big_arrays)
1932
1933 dnl **************
1934 dnl *** DTRACE ***
1935 dnl **************
1936
1937 AC_ARG_ENABLE(dtrace,[  --enable-dtrace Enable DTrace probes], enable_dtrace=$enableval, enable_dtrace=$has_dtrace)
1938
1939 if test "x$enable_dtrace" = "xyes"; then
1940    if test "x$has_dtrace" = "xno"; then
1941           AC_MSG_ERROR([DTrace probes are not supported on this platform.])
1942    fi
1943    AC_PATH_PROG(DTRACE, [dtrace], [no], [$PATH:/usr/sbin])
1944    if test "x$DTRACE" = "xno"; then
1945           AC_MSG_RESULT([dtrace utility not found, dtrace support disabled.])
1946           enable_dtrace=no
1947    elif ! $DTRACE -h -s $srcdir/data/mono.d > /dev/null 2>&1; then
1948           AC_MSG_RESULT([dtrace doesn't support -h option, dtrace support disabled.])
1949           enable_dtrace=no
1950    fi
1951 fi
1952
1953 dtrace_g=no
1954 if test "x$enable_dtrace" = "xyes"; then
1955         AC_DEFINE(ENABLE_DTRACE, 1, [Enable DTrace probes])
1956         DTRACEFLAGS=
1957         if test "x$ac_cv_sizeof_void_p" = "x8"; then
1958                 case "$host" in
1959                         powerpc-*-darwin*)
1960                         DTRACEFLAGS="-arch ppc64"
1961                         ;;
1962                         i*86-*-darwin*)
1963                         DTRACEFLAGS="-arch x86_64"
1964                         ;;
1965                         *)
1966                         DTRACEFLAGS=-64
1967                         ;;
1968                 esac
1969         else
1970                 case "$host" in
1971                         powerpc-*-darwin*)
1972                         DTRACEFLAGS="-arch ppc"
1973                         ;;
1974                         i*86-*-darwin*)
1975                         DTRACEFLAGS="-arch i386"
1976                         ;;
1977                         *)
1978                         DTRACEFLAGS=-32
1979                         ;;
1980                 esac
1981         fi
1982         AC_SUBST(DTRACEFLAGS)
1983         case "$host" in
1984                 *-*-solaris*)
1985                 dtrace_g=yes
1986                 ;;
1987         esac
1988         AC_CHECK_HEADERS([sys/sdt.h])
1989 fi
1990 AM_CONDITIONAL(ENABLE_DTRACE, [test x$enable_dtrace = xyes])
1991 AM_CONDITIONAL(DTRACE_G_REQUIRED, [test x$dtrace_g = xyes])
1992
1993 dnl **************
1994 dnl ***  NaCl  ***
1995 dnl **************
1996
1997 AC_ARG_ENABLE(nacl_codegen, [  --enable-nacl-codegen      Enable Native Client code generation], enable_nacl_codegen=$enableval, enable_nacl_codegen=no)
1998 AC_ARG_ENABLE(nacl_gc, [  --enable-nacl-gc           Enable Native Client garbage collection], enable_nacl_gc=$enableval, enable_nacl_gc=no)
1999
2000 AM_CONDITIONAL(NACL_CODEGEN, test x$enable_nacl_codegen != xno)
2001 if test "x$enable_nacl_codegen" = "xyes"; then
2002    MONO_NACL_ALIGN_MASK_OFF=1
2003    CPPFLAGS="$CPPFLAGS -D__native_client_codegen__"
2004    AC_DEFINE(TARGET_NACL, 1, [...])
2005 else
2006    MONO_NACL_ALIGN_MASK_OFF=0
2007    CPPFLAGS="$CPPFLAGS -D__default_codegen__"
2008 fi
2009 if test "x$enable_nacl_gc" = "xyes"; then
2010    CPPFLAGS="$CPPFLAGS -finstrument-for-thread-suspension -D__native_client_gc__"
2011 fi
2012 AC_SUBST(MONO_NACL_ALIGN_MASK_OFF)
2013
2014 dnl **************
2015 dnl ***  LLVM  ***
2016 dnl **************
2017
2018 AC_ARG_ENABLE(llvm,[  --enable-llvm     Enable the LLVM back-end], enable_llvm=$enableval, enable_llvm=no)
2019 AC_ARG_ENABLE(loadedllvm,[  --enable-loadedllvm Load the LLVM back-end dynamically], enable_llvm=$enableval && enable_loadedllvm=$enableval, enable_loadedllvm=no)
2020
2021 if test "x$enable_llvm" = "xyes"; then
2022    AC_PATH_PROG(LLVM_CONFIG, llvm-config, no)
2023    if test "x$LLVM_CONFIG" = "xno"; then
2024           AC_MSG_ERROR([llvm-config not found.])
2025    fi
2026
2027    # The output of --cflags seems to include optimizations flags too
2028    LLVM_CFLAGS=`$LLVM_CONFIG --cflags | sed -e 's/-O2//g' | sed -e 's/-O0//g' | sed -e 's/-fomit-frame-pointer//g' | sed -e 's/-fPIC//g'`
2029    # LLVM is compiled with -fno-rtti, so we need this too, since our classes inherit
2030    # from LLVM classes.
2031    LLVM_CXXFLAGS="`$LLVM_CONFIG --cxxflags` -fno-rtti"
2032    LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags`
2033    LLVM_LIBS=`$LLVM_CONFIG --libs core bitwriter jit x86codegen`
2034    LLVM_LIBS="$LLVM_LDFLAGS $LLVM_LIBS -lstdc++"
2035
2036    # Should be something like '2.6' or '2.7svn'
2037    llvm_version=`$LLVM_CONFIG --version`
2038    major_version=`echo $llvm_version | cut -c 1`
2039    minor_version=`echo $llvm_version | cut -c 3`
2040    if echo $llvm_version | grep -q 'mono'; then
2041           AC_DEFINE(LLVM_MONO_BRANCH, 1, [Whenever we are using the mono branch of LLVM])
2042           LLVM_CXXFLAGS="$LLVM_CXXFLAGS -DLLVM_MONO_BRANCH"       
2043    fi
2044
2045    AC_DEFINE_UNQUOTED(LLVM_MAJOR_VERSION, $major_version, [Major version of LLVM libraries])
2046    AC_DEFINE_UNQUOTED(LLVM_MINOR_VERSION, $minor_version, [Minor version of LLVM libraries])
2047    AC_DEFINE_UNQUOTED(LLVM_VERSION, "$llvm_version", [Full version of LLVM libraties])
2048
2049    # Have to pass these on the command line since mini-llvm-cpp.h already includes
2050    # llvm's config.h
2051    LLVM_CXXFLAGS="$LLVM_CXXFLAGS -DLLVM_MAJOR_VERSION=$major_version -DLLVM_MINOR_VERSION=$minor_version"
2052
2053    AC_SUBST(LLVM_CFLAGS)
2054    AC_SUBST(LLVM_CXXFLAGS)
2055    AC_SUBST(LLVM_LIBS)
2056    AC_SUBST(LLVM_LDFLAGS)
2057    AC_DEFINE(ENABLE_LLVM, 1, [Enable the LLVM back end])
2058 fi
2059
2060 AM_CONDITIONAL(ENABLE_LLVM, [test x$enable_llvm = xyes])
2061 if test "x$enable_loadedllvm" = "xyes"; then
2062    AC_DEFINE(MONO_LLVM_LOADED, 1, [The LLVM back end is dynamically loaded])
2063 fi
2064 AM_CONDITIONAL(LOADED_LLVM, [test x$enable_loadedllvm = xyes])
2065
2066 TARGET="unknown"
2067 ACCESS_UNALIGNED="yes"
2068
2069 JIT_SUPPORTED=no
2070 INTERP_SUPPORTED=no
2071 LIBC="libc.so.6"
2072 INTL="libc.so.6"
2073 SQLITE="libsqlite.so.0"
2074 SQLITE3="libsqlite3.so.0"
2075 X11="libX11.so"
2076
2077 sizeof_register="SIZEOF_VOID_P"
2078
2079 jit_wanted=true
2080 interp_wanted=false
2081 sgen_supported=false
2082 case "$host" in
2083 #       mips-sgi-irix5.* | mips-sgi-irix6.*)
2084 #               TARGET=MIPS;
2085 #               ACCESS_UNALIGNED="no"
2086 #               ;;
2087         mips*)
2088                 TARGET=MIPS;
2089                 arch_target=mips;
2090                 ACCESS_UNALIGNED="no"
2091                 JIT_SUPPORTED=yes
2092
2093                 AC_MSG_CHECKING(for mips n32)
2094                 AC_TRY_COMPILE([], [
2095                 void main () {
2096                 #if _MIPS_SIM != _ABIN32
2097                 #error Not mips n32
2098                 #endif
2099                 }
2100                 ],[
2101                 AC_MSG_RESULT(yes)
2102                 sizeof_register=8
2103                 ],[
2104                 AC_MSG_RESULT(no)
2105                 ])
2106                 ;;
2107         i*86-*-*)
2108                 TARGET=X86;
2109                 arch_target=x86;
2110                 JIT_SUPPORTED=yes
2111                 case $host_os in
2112                   solaris*)
2113                         LIBC="libc.so"
2114                         INTL="libintl.so"
2115                         if test "x$ac_cv_sizeof_void_p" = "x8"; then
2116                                 TARGET=AMD64
2117                                 arch_target=amd64
2118                         fi
2119
2120                         # On solaris 10 x86, gcc prints a warning saying 'visibility attribute not supported on this configuration; ignored', but linking fails. A test case:
2121                         # int astruct __attribute__ ((visibility ("hidden")));
2122                         # void foo ()
2123                         # {
2124                         #       void *p = &astruct;
2125                         # }
2126                         # gcc -fPIC --shared -o libfoo.so foo.c
2127                         # yields:
2128                         # foo.c:6: warning: visibility attribute not supported in this configuration; ignored
2129                         # ld: fatal: relocation error: R_386_GOTOFF: file /var/tmp//ccxYR96k.o: symbol astruct: relocation must bind locally
2130                         have_visibility_hidden=no
2131                         sgen_supported=true
2132                         ;;
2133                   cygwin*)
2134                         have_visibility_hidden=no                 
2135                         ;;
2136                   haiku*)
2137                         LIBC=libroot.so
2138                         ;;
2139                   linux*)
2140                         sgen_supported=true
2141                         AOT_SUPPORTED="yes"
2142                         ;;
2143                   darwin*|openbsd*|freebsd*)
2144                         sgen_supported=true
2145                         ;;
2146                 esac
2147                 ;;
2148         x86_64-*-* | amd64-*-*)
2149                 TARGET=AMD64;
2150                 arch_target=amd64;
2151                 JIT_SUPPORTED=yes
2152                 case $host_os in
2153                   linux*)
2154                         sgen_supported=true
2155                         AOT_SUPPORTED="yes"
2156                         ;;
2157                   darwin*|openbsd*|freebsd*)
2158                         sgen_supported=true
2159                         ;;
2160                 esac
2161                 case "$host" in
2162                         x86_64-*-nacl*)
2163                                 AC_DEFINE(__mono_ilp32__, 1, [64 bit mode with 4 byte longs and pointers])
2164                                 sizeof_register=8
2165                                 ;;
2166                 esac
2167                 ;;
2168         ia64-*-*)
2169                 TARGET=IA64
2170                 arch_target=ia64
2171                 ACCESS_UNALIGNED="no"
2172                 JIT_SUPPORTED=yes
2173                 LIBC="libc.so.6.1"
2174                 INTL="libc.so.6.1"
2175                 AC_CHECK_LIB(unwind, _U_dyn_register, [], [AC_MSG_ERROR(library libunwind not found)])
2176                 libmono_ldflags="-lunwind"
2177                 ;;
2178         sparc*-*-*)
2179                 if test "x$ac_cv_sizeof_void_p" = "x8"; then
2180                    TARGET=SPARC64
2181                 else
2182                         TARGET=SPARC
2183                 fi
2184                 arch_target=sparc;
2185                 JIT_SUPPORTED=yes
2186                 ACCESS_UNALIGNED="no"
2187                 case $host_os in
2188                   linux*) ;;
2189                   *)
2190                         LIBC="libc.so"
2191                         INTL="libintl.so"
2192                 esac
2193                 if test x"$GCC" = xyes; then
2194                         # We don't support v8 cpus
2195                         CFLAGS="$CFLAGS -Wno-cast-align -mcpu=v9"
2196                 fi
2197                 if test x"$AR" = xfalse; then
2198                         AC_MSG_ERROR([The required utility 'ar' is not found in your PATH. Usually it can be found in /usr/ccs/bin.])
2199                 fi
2200                 sgen_supported=true
2201                 ;;
2202        alpha*-*-linux* | alpha*-*-osf*)
2203                 TARGET=ALPHA;
2204                 ACCESS_UNALIGNED="no"
2205                 JIT_SUPPORTED=yes
2206                 arch_target=alpha;
2207                 CFLAGS="$CFLAGS -mieee -O0"
2208                 case $host_os in
2209                   linux*)
2210                         LIBC="libc.so.6.1"
2211                         INTL="libc.so.6.1"
2212                 esac
2213                ;;
2214         *-mingw*|*-*-cygwin*)
2215                 # When this is enabled, it leads to very strange crashes at runtime (gcc-3.4.4)
2216                 have_visibility_hidden=no
2217                 INTL="intl"
2218                 ;;
2219         hppa2.0w-hp-hpux11.00 | hppa64-hp-hpux11.00)
2220                 TARGET=HPPA;
2221                 arch_target=hppa; 
2222                 LIBC="libc.sl"
2223                 ACCESS_UNALIGNED="no"
2224                 INTERP_SUPPORTED=yes
2225                 interp_wanted=true
2226                 ;;
2227         hppa*linux*)
2228                 TARGET=HPPA;
2229                 arch_target=hppa; 
2230                 ACCESS_UNALIGNED="no"
2231                 JIT_SUPPORTED=yes
2232                 ;;
2233         macppc-*-openbsd* | powerpc*-*-linux* | powerpc-*-openbsd* | \
2234         powerpc-*-sysv* | powerpc-*-darwin* | powerpc-*-netbsd* | powerpc-*-freebsd* )
2235                 if test "x$ac_cv_sizeof_void_p" = "x8"; then
2236                         TARGET=POWERPC64;
2237                         CPPFLAGS="$CPPFLAGS -D__mono_ppc__ -D__mono_ppc64__"
2238                         CFLAGS="$CFLAGS -mminimal-toc"
2239                 else
2240                         TARGET=POWERPC;
2241                         CPPFLAGS="$CPPFLAGS -D__mono_ppc__"
2242                 fi
2243                 arch_target=ppc;
2244                 JIT_SUPPORTED=yes
2245                 case $host_os in
2246                   linux*|darwin*)
2247                         sgen_supported=true
2248                         ;;
2249                 esac
2250                 ;;
2251         arm*-darwin*)
2252                 TARGET=ARM;
2253                 arch_target=arm;
2254                 ACCESS_UNALIGNED="no"
2255                 JIT_SUPPORTED=yes
2256                 CPPFLAGS="$CPPFLAGS -DARM_FPU_VFP=1 -D__ARM_EABI__ -DHAVE_ARMV6=1"
2257                 sgen_supported=true
2258                 ;;
2259         arm*-linux*)
2260                 TARGET=ARM;
2261                 arch_target=arm;
2262                 ACCESS_UNALIGNED="no"
2263                 JIT_SUPPORTED=yes
2264                 sgen_supported=true
2265                 AOT_SUPPORTED="yes"
2266                 ;;
2267         s390-*-linux*)
2268                 TARGET=S390;
2269                 arch_target=s390;
2270                 ACCESS_UNALIGNED="yes"
2271                 JIT_SUPPORTED=yes
2272                 sgen_supported=true
2273                 # Required CFLAGS for s390[x].  USE_STRING_INLINES is automatic with gcc 4.1
2274                 CFLAGS="$CFLAGS -mbackchain -D__USE_STRING_INLINES"
2275                 ;;
2276         s390x-*-linux*)
2277                 TARGET=S390x;
2278                 arch_target=s390x;
2279                 ACCESS_UNALIGNED="yes"
2280                 JIT_SUPPORTED=yes
2281                 sgen_supported=true
2282                 CFLAGS="$CFLAGS -mbackchain -D__USE_STRING_INLINES"
2283                 ;;
2284 esac
2285
2286 if test "x$host" != "x$target"; then
2287    case "$target" in
2288    powerpc64-ps3-linux-gnu)
2289                 TARGET=POWERPC64
2290                 arch_target=powerpc64
2291                 AC_DEFINE(TARGET_PS3, 1, [...])
2292                 AC_DEFINE(MONO_CROSS_COMPILE,1,[The runtime is compiled for cross-compiling mode])
2293                 # It would be better to just use TARGET_POWERPC64, but lots of code already
2294                 # uses this define
2295                 AC_DEFINE(__mono_ppc64__, 1, [...])
2296                 AC_DEFINE(__mono_ilp32__, 1, [64 bit mode with 4 byte longs and pointers])
2297                 sizeof_register=8
2298                 target_byte_order=G_BIG_ENDIAN
2299                 ;;
2300
2301    powerpc64-xbox360-linux-gnu)
2302                 TARGET=POWERPC64
2303                 arch_target=powerpc64
2304                 AC_DEFINE(TARGET_XBOX360, 1, [...])
2305                 AC_DEFINE(MONO_CROSS_COMPILE,1,[The runtime is compiled for cross-compiling mode])
2306                 # It would be better to just use TARGET_POWERPC64, but lots of code already
2307                 # uses this define
2308                 sizeof_register=8
2309                 target_byte_order=G_BIG_ENDIAN
2310                 ;;
2311    x86_64-*-nacl)
2312                 TARGET=AMD64
2313                 arch_target=amd64
2314                 AC_DEFINE(TARGET_AMD64, 1, [...])
2315                 AC_DEFINE(MONO_CROSS_COMPILE,1,[The runtime is compiled for cross-compiling mode])
2316                 AC_DEFINE(__mono_ilp32__, 1, [64 bit mode with 4 byte longs and pointers])
2317                 sizeof_register=8
2318                 ;;
2319    armv7l-unknown-linux-gnueabi*)
2320                 # TEGRA
2321                 TARGET=ARM;
2322                 arch_target=arm;
2323                 ACCESS_UNALIGNED="no"
2324                 JIT_SUPPORTED=yes
2325                 CPPFLAGS="$CPPFLAGS -DARM_FPU_VFP=1 -D__ARM_EABI__"
2326                 jit_wanted=true
2327                 # Can't use tls, since it depends on the runtime detection of tls offsets
2328                 # in mono-compiler.h
2329                 with_tls=pthread
2330                 ;;
2331    armv5tel-unknown-linux-gnueabi*)
2332                 TARGET=ARM;
2333                 arch_target=arm;
2334                 ACCESS_UNALIGNED="no"
2335                 JIT_SUPPORTED=yes
2336                 CPPFLAGS="$CPPFLAGS -D__ARM_EABI__"
2337                 jit_wanted=true
2338                 # Can't use tls, since it depends on the runtime detection of tls offsets
2339                 # in mono-compiler.h
2340                 with_tls=pthread
2341                 ;;
2342         *)
2343                 AC_MSG_WARN([Cross compiling is only supported for targets matching 'powerpc64-{ps3,xbox360}-linux-gnu'])
2344         esac
2345 fi
2346
2347 # FIXME: Define the others as well
2348 case "$TARGET" in
2349 X86)
2350         AC_DEFINE(TARGET_X86, 1, [...])
2351         ;;
2352 AMD64)
2353         AC_DEFINE(TARGET_AMD64, 1, [...])
2354         ;;
2355 ARM)
2356         AC_DEFINE(TARGET_ARM, 1, [...])
2357         ;;
2358 POWERPC)
2359         AC_DEFINE(TARGET_POWERPC, 1, [...])
2360         ;;
2361 POWERPC64)
2362         AC_DEFINE(TARGET_POWERPC, 1, [...])
2363         AC_DEFINE(TARGET_POWERPC64, 1, [...])
2364         ;;
2365 S390x)
2366         AC_DEFINE(TARGET_S390X, 1, [...])
2367         ;;
2368 esac
2369
2370 if test "x$sizeof_register" = "x4"; then
2371    AC_DEFINE(SIZEOF_REGISTER,4,[size of machine integer registers])
2372 elif test "x$sizeof_register" = "x8"; then
2373    AC_DEFINE(SIZEOF_REGISTER,8,[size of machine integer registers])
2374 else
2375    AC_DEFINE(SIZEOF_REGISTER,SIZEOF_VOID_P,[size of machine integer registers])
2376 fi
2377
2378 if test "x$target_byte_order" = "xG_BIG_ENDIAN"; then
2379    AC_DEFINE(TARGET_BYTE_ORDER,G_BIG_ENDIAN,[byte order of target])
2380 elif test "x$target_byte_order" = "xG_LITTLE_ENDIAN"; then
2381    AC_DEFINE(TARGET_BYTE_ORDER,G_LITTLE_ENDIAN,[byte order of target])
2382 else
2383    AC_DEFINE(TARGET_BYTE_ORDER,G_BYTE_ORDER,[byte order of target])
2384 fi
2385
2386 if test "x$have_visibility_hidden" = "xyes"; then
2387    AC_DEFINE(HAVE_VISIBILITY_HIDDEN, 1, [Support for the visibility ("hidden") attribute])
2388 fi
2389
2390 if test "x$have_deprecated" = "xyes"; then
2391    AC_DEFINE(HAVE_DEPRECATED, 1, [Support for the deprecated attribute])
2392 fi
2393
2394 dnl 
2395 dnl Simple Generational checks (sgen)
2396 dnl
2397 if $sgen_supported; then
2398    build_sgen_default=yes
2399 else
2400    build_sgen_default=no
2401 fi
2402 SGEN_DEFINES=
2403 AC_ARG_WITH(sgen, [  --with-sgen=yes,no             Extra Generational GC, default=yes],[buildsgen=$with_sgen],[buildsgen=$build_sgen_default])
2404 if test x$buildsgen = xyes; then
2405    if $sgen_supported; then
2406        SGEN_DEFINES="-DHAVE_SGEN_GC -DHAVE_MOVING_COLLECTOR -DHAVE_WRITE_BARRIERS"
2407        gc_msg="sgen and $gc_msg"
2408    else
2409        buildsgen=no
2410        AC_MSG_WARN("Sgen is not supported on this platform")
2411    fi
2412 fi
2413 AC_SUBST(SGEN_DEFINES)
2414 AM_CONDITIONAL(SUPPORT_SGEN, test x$buildsgen = xyes)
2415
2416 USEJIT=false
2417 if test x$JIT_SUPPORTED = xyes; then
2418    if $jit_wanted; then
2419       USEJIT=true
2420       jit_status="Building and using the JIT"
2421    else
2422       if $interp_wanted; then
2423          jit_status="Building the JIT, defaulting to the interpreter"
2424       else
2425          AC_ERROR(No JIT or interpreter support available or selected.)
2426       fi
2427    fi
2428 else
2429    if test x$interp_wanted = xtrue; then
2430       jit_status="interpreter"
2431    else
2432       AC_ERROR(No JIT or interpreter support available or selected.)
2433    fi
2434 fi
2435
2436 AM_CONDITIONAL(USE_JIT, test x$USEJIT = xtrue)
2437
2438 libsuffix=".so"
2439
2440 case "$host" in
2441      *-*-darwin*)
2442         libsuffix=".dylib"
2443         LIBC="libc.dylib"
2444         INTL="libintl.dylib"
2445         SQLITE="libsqlite.0.dylib"
2446         SQLITE3="libsqlite3.0.dylib"
2447         X11="libX11.dylib"
2448         ;;
2449      *-*-*netbsd*)
2450         LIBC="libc.so.12"
2451         INTL="libintl.so.0"
2452         ;;
2453     *-*-*freebsd*)
2454         LIBC="libc.so"
2455         INTL="libintl.so"
2456         SQLITE="libsqlite.so"
2457         SQLITE3="libsqlite3.so"
2458         ;;
2459     *-*-*openbsd*)
2460         LIBC="libc.so"
2461         INTL="libintl.so"
2462         SQLITE="libsqlite.so"
2463         SQLITE3="libsqlite3.so"
2464         ;;
2465     *-*-*linux*)
2466         AC_PATH_X
2467         AC_MSG_CHECKING(for the soname of libX11.so)
2468         for i in $x_libraries /usr/lib /usr/lib64; do
2469                 for r in 4 5 6; do
2470                         if test -f $i/libX11.so.$r; then
2471                                 X11=libX11.so.$r
2472                                 AC_MSG_RESULT($X11)
2473                         fi
2474                 done
2475         done
2476         
2477         if test "x$X11" = "xlibX11.so"; then
2478                 AC_MSG_WARN([Could not find X development libs. Do you have the -devel package installed? WinForms may not work...]);
2479         fi
2480         ;;
2481 esac
2482
2483
2484 AC_SUBST(libsuffix)
2485
2486 if test "x$TARGET" = "xAMD64" -o "x$TARGET" = "xX86"; then
2487         if test "x$with_tls" = "x__thread"; then
2488                 #
2489                 # On some linux distributions, TLS works in executables, but linking 
2490                 # against a shared library containing TLS fails with:
2491                 # undefined reference to `__tls_get_addr'
2492                 #
2493                 rm -f conftest.c conftest.so conftest
2494                 echo "static __thread int foo; void main () { foo = 5; }" > conftest.c
2495                 $CC -fPIC --shared -o conftest.so conftest.c > /dev/null 2>&1
2496                 $CC -o conftest conftest.so > /dev/null 2>&1
2497                 if test ! -f conftest; then
2498                    AC_MSG_WARN([Disabling usage of __thread.]);
2499                    with_tls=pthread
2500                 fi
2501                 rm -f conftest.c conftest.so conftest
2502         fi
2503 fi
2504
2505 mono_debugger_supported=no
2506 AC_ARG_ENABLE(mono-debugger, [  --disable-mono-debugger disable support for the mdb debugger], try_mono_debugger=$enableval, try_mono_debugger=yes)
2507 if test "x$try_mono_debugger" = "xyes"; then
2508         if test "x$TARGET" = "xAMD64" -o "x$TARGET" = "xX86" -o "x$TARGET" = "xALPHA"; then
2509                 if test x$use_included_gc = xyes; then
2510                         case "$host" in
2511                         *-*-*linux*)
2512                                 mono_debugger_supported=yes
2513                                 ;;
2514                         *86-apple-darwin*)
2515                                 mono_debugger_supported=yes
2516                                 ;;              
2517                         esac
2518                 fi
2519         fi
2520 fi
2521
2522 # disable the debugger entirely when building with moonlight
2523 if test "x$with_moonlight" != "xno"; then
2524         mono_debugger_supported=no
2525 fi
2526
2527 AC_MSG_CHECKING(if the Mono Debugger is supported on this platform)
2528 if test "x$mono_debugger_supported" = "xyes"; then
2529         BOEHM_DEFINES="$BOEHM_DEFINES -DMONO_DEBUGGER_SUPPORTED"
2530         NESTED_LIBGC_FLAGS="-DMONO_DEBUGGER_SUPPORTED"
2531 fi
2532 AM_CONDITIONAL(MONO_DEBUGGER_SUPPORTED, test x$mono_debugger_supported = xyes)
2533 AC_MSG_RESULT($mono_debugger_supported)
2534
2535 if test "x$with_tls" = "x__thread"; then
2536         AC_DEFINE(HAVE_KW_THREAD, 1, [Have __thread keyword])
2537         # Pass the information to libgc
2538         CPPFLAGS="$CPPFLAGS -DUSE_COMPILER_TLS"
2539         AC_MSG_CHECKING(if the tls_model attribute is supported)
2540         AC_TRY_COMPILE([static __thread int foo __attribute__((tls_model("initial-exec")));], [
2541                 ], [
2542                         AC_MSG_RESULT(yes)
2543                         AC_DEFINE(HAVE_TLS_MODEL_ATTR, 1, [tld_model available])
2544                 ], [
2545                         AC_MSG_RESULT(no)
2546         ])
2547 fi
2548
2549 if test ${TARGET} = ARM && test x$cross_compiling = xno && test x$enable_mcs_build != xno; then
2550         dnl ******************************************
2551         dnl *** Check to see what FPU is available ***
2552         dnl ******************************************
2553         AC_MSG_CHECKING(which FPU to use)
2554
2555         ORIG_CFLAGS=$CFLAGS
2556         CFLAGS="$CFLAGS -mfpu=vfp -mfloat-abi=softfp"
2557         AC_TRY_RUN([
2558                 int main () { __asm__ ("faddd   d7, d6, d7"); return 0; }
2559                         ], fpu=VFP, fpu=NONE)
2560         CFLAGS=$ORIG_CFLAGS
2561
2562         if test x$fpu = xNONE; then
2563                 AC_TRY_COMPILE([], [
2564                         __asm__ ("ldfd f0, [r0]");
2565                         ], fpu=FPA, fpu=NONE)
2566         fi
2567
2568         AC_MSG_RESULT($fpu)
2569         CPPFLAGS="$CPPFLAGS -DARM_FPU_$fpu=1"
2570         unset fpu
2571
2572         AC_MSG_CHECKING(for ARMV6)
2573         AC_TRY_RUN([
2574                 int main () { __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r" (0) : "memory"); return 0; }
2575                         ], armv6=yes, armv6=no)
2576
2577         AC_MSG_RESULT($armv6)
2578         if test ${armv6} = yes; then
2579            AC_DEFINE(HAVE_ARMV6, 1, "Host supports ARMV6 instructions")
2580         fi
2581 fi
2582
2583 if test ${TARGET} = unknown; then
2584         CPPFLAGS="$CPPFLAGS -DNO_PORT"
2585         AC_MSG_WARN("mono has not been ported to $host: some things may not work.")
2586 fi
2587
2588 if test ${ACCESS_UNALIGNED} = no; then
2589         CPPFLAGS="$CPPFLAGS -DNO_UNALIGNED_ACCESS"
2590 fi
2591
2592 case "x$gc" in
2593         xincluded)
2594                 # Pass CPPFLAGS to libgc configure
2595                 # We should use a separate variable for this to avoid passing useless and
2596                 # potentially problematic defines to libgc (like -D_FILE_OFFSET_BITS=64)
2597                 # This should be executed late so we pick up the final version of CPPFLAGS
2598                 # The problem with this approach, is that during a reconfigure, the main
2599                 # configure scripts gets invoked with these arguments, so we use separate
2600                 # variables understood by libgc's configure to pass CPPFLAGS and CFLAGS.
2601                 LIBGC_CPPFLAGS="$CPPFLAGS $NESTED_LIBGC_FLAGS"
2602                 if test x$TARGET = xSPARC -o x$TARGET = xSPARC64; then
2603                         LIBGC_CPPFLAGS=`echo $LIBGC_CPPFLAGS | sed -e 's/-D_FILE_OFFSET_BITS=64//g'`
2604                 fi
2605                 # Don't pass -finstrument-for-thread-suspension in, 
2606                 # if these are instrumented it will be very bad news 
2607                 # (infinite recursion, undefined parking behavior, etc)
2608                 LIBGC_CPPFLAGS=`echo $LIBGC_CPPFLAGS | sed -e 's/-finstrument-for-thread-suspension//g'`
2609                 ac_configure_args="$ac_configure_args --disable-embed-check --with-libgc-threads=$libgc_threads $libgc_configure_args \"CPPFLAGS_FOR_LIBGC=$LIBGC_CPPFLAGS\" \"CFLAGS_FOR_LIBGC=$CFLAGS_FOR_LIBGC\""
2610                 AC_CONFIG_SUBDIRS(libgc)
2611                 ;;
2612 esac
2613
2614 #AC_ARG_WITH(profile2,  [  --with-profile2=yes,no          If you want to install the 2.0 FX (defaults to yes)],                 [], [with_profile2=yes])
2615 AC_ARG_WITH(profile4,  [  --with-profile4=yes,no          If you want to install the 4.0 FX (defaults to yes)],                  [], [with_profile4=yes])
2616 AC_ARG_WITH(monodroid, [  --with-monodroid=yes,no         If you want to build the MonoDroid 2.1 assemblies (defaults to no)], [], [with_monodroid=no])
2617 AC_ARG_WITH(monotouch, [  --with-monotouch=yes,no         If you want to build the MonoTouch 2.1 assemblies (defaults to no)], [], [with_monotouch=no])
2618
2619 OPROFILE=no
2620 AC_ARG_WITH(oprofile,[  --with-oprofile=no,<oprofile install dir>   Enable oprofile support (defaults to no)],[
2621         if test x$with_oprofile != xno; then
2622             oprofile_include=$with_oprofile/include
2623             if test ! -f $oprofile_include/opagent.h; then
2624                   AC_MSG_ERROR([oprofile include file not found at $oprofile_include/opagent.h])
2625                 fi
2626             OPROFILE=yes
2627                 OPROFILE_CFLAGS="-I$oprofile_include"
2628             OPROFILE_LIBS="-L$with_oprofile/lib/oprofile -lopagent"
2629             AC_DEFINE(HAVE_OPROFILE,1,[Have oprofile support])
2630         fi
2631 ])
2632
2633 MALLOC_MEMPOOLS=no
2634 AC_ARG_WITH(malloc_mempools,[  --with-malloc-mempools=yes,no  Use malloc for each single mempool allocation (only for runtime debugging, defaults to no)],[
2635         if test x$with_malloc_mempools = xyes; then
2636                 MALLOC_MEMPOOLS=yes
2637                 AC_DEFINE(USE_MALLOC_FOR_MEMPOOLS,1,[Use malloc for each single mempool allocation])
2638         fi
2639 ])
2640
2641
2642 DISABLE_MCS_DOCS=no
2643 AC_ARG_WITH(mcs_docs,[  --with-mcs-docs=yes,no         If you want to build the documentation under mcs (defaults to yes)],[
2644         if test x$with_mcs_docs != xyes; then
2645                 DISABLE_MCS_DOCS=yes
2646         fi
2647 ])
2648 if test x$with_profile4 != xyes; then
2649         DISABLE_MCS_DOCS=yes
2650 fi
2651
2652 MOONLIGHT_DEFINES=
2653 AC_ARG_WITH(moonlight, [  --with-moonlight=yes|no|only         If you want to build Mono for Moonlight (defaults to no)],[
2654         if test x$with_moonlight != xno; then
2655         MOONLIGHT_DEFINES="-DMOONLIGHT -DDISABLE_ASSEMBLY_REMAPPING "
2656         fi
2657 ], [with_moonlight=no])
2658 AC_SUBST(MOONLIGHT_DEFINES)
2659
2660 AC_ARG_WITH(moon_gc, [  --with-moon-gc=boehm,sgen               Select the gc to use with Moonlight (defaults to boehm)],[
2661         if test "x$with_moon_gc" != "xsgen"; then
2662                 with_moon_gc=boehm
2663         fi
2664 ], [with_moon_gc=boehm])
2665
2666 AC_CHECK_HEADER([malloc.h], 
2667                 [AC_DEFINE([HAVE_USR_INCLUDE_MALLOC_H], [1], 
2668                         [Define to 1 if you have /usr/include/malloc.h.])],,)
2669
2670 dnl
2671 dnl Consistency settings
2672 dnl
2673 if test x$cross_compiling = xyes -o x$enable_mcs_build = xno; then
2674    DISABLE_MCS_DOCS=yes
2675 fi
2676
2677 if test x$DISABLE_MCS_DOCS = xyes; then
2678    docs_dir=""
2679 else
2680    docs_dir=docs
2681 fi
2682 AC_SUBST(docs_dir)
2683
2684 AM_CONDITIONAL(HAVE_OPROFILE, test x$OPROFILE = xyes)
2685 AC_SUBST(OPROFILE_CFLAGS)
2686 AC_SUBST(OPROFILE_LIBS)
2687
2688 libmono_ldflags="$libmono_ldflags $LIBS"
2689
2690 AM_CONDITIONAL(MOONLIGHT, [test "x$with_moonlight" != "xno"])
2691 AM_CONDITIONAL(ONLY_MOONLIGHT, [test "x$with_moonlight" = "xonly"])
2692 AM_CONDITIONAL(MOONLIGHT_BOEHM, [test "x$with_moon_gc" = "xboehm"])
2693 AM_CONDITIONAL(MOONLIGHT_SGEN, [test "x$with_moon_gc" = "xsgen"])
2694
2695 AM_CONDITIONAL(INSTALL_4_0, [test "x$with_profile4" = xyes])
2696 AM_CONDITIONAL(INSTALL_MONODROID, [test "x$with_monodroid" = xyes])
2697 AM_CONDITIONAL(INSTALL_MONOTOUCH, [test "x$with_monotouch" = xyes])
2698
2699 AM_CONDITIONAL(MIPS_GCC, test ${TARGET}${ac_cv_prog_gcc} = MIPSyes)
2700 AM_CONDITIONAL(MIPS_SGI, test ${TARGET}${ac_cv_prog_gcc} = MIPSno)
2701 AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
2702 AM_CONDITIONAL(SPARC64, test x$TARGET = xSPARC64)
2703 AM_CONDITIONAL(X86, test x$TARGET = xX86)
2704 AM_CONDITIONAL(AMD64, test x$TARGET = xAMD64)
2705 AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
2706 AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
2707 AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
2708 AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS)
2709 AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
2710 AM_CONDITIONAL(POWERPC64, test x$TARGET = xPOWERPC64)
2711 AM_CONDITIONAL(ARM, test x$TARGET = xARM)
2712 AM_CONDITIONAL(S390, test x$TARGET = xS390)
2713 AM_CONDITIONAL(S390x, test x$TARGET = xS390x)
2714 AM_CONDITIONAL(HPPA, test x$TARGET = xHPPA)
2715
2716 AM_CONDITIONAL(JIT_SUPPORTED, test x$JIT_SUPPORTED = xyes)
2717 AM_CONDITIONAL(INTERP_SUPPORTED, test x$interp_wanted = xtrue)
2718 AM_CONDITIONAL(INCLUDED_LIBGC, test x$gc = xincluded)
2719
2720 AC_SUBST(LIBC)
2721 AC_SUBST(INTL)
2722 AC_SUBST(SQLITE)
2723 AC_SUBST(SQLITE3)
2724 AC_SUBST(X11)
2725 AC_DEFINE_UNQUOTED(ARCHITECTURE,"$arch_target",[The architecture this is running on])
2726 AC_SUBST(arch_target)
2727 AC_SUBST(CFLAGS)
2728 AC_SUBST(CPPFLAGS)
2729 AC_SUBST(LDFLAGS)
2730
2731 mono_build_root=`pwd`
2732 AC_SUBST(mono_build_root)
2733
2734 if test x$USEJIT = xtrue; then
2735   mono_runtime=mono/mini/mono
2736 else
2737   mono_runtime=mono/interpreter/mint
2738 fi
2739 AC_SUBST(mono_runtime)
2740
2741 mono_cfg_root=$mono_build_root/runtime
2742 if test x$host_win32 = xyes; then
2743   if test "x$cross_compiling" = "xno"; then
2744     mono_cfg_dir=`cygpath -w -a $mono_cfg_root`\\etc
2745   else
2746     mono_cfg_dir=`echo $mono_cfg_root | tr '/' '\\'`\\etc
2747   fi
2748 else
2749   mono_cfg_dir=$mono_cfg_root/etc
2750 fi
2751 AC_SUBST(mono_cfg_dir)
2752
2753 AC_CONFIG_FILES([po/mcs/Makefile.in])
2754
2755 AC_CONFIG_FILES([runtime/mono-wrapper],[chmod +x runtime/mono-wrapper])
2756 AC_CONFIG_FILES([runtime/monodis-wrapper],[chmod +x runtime/monodis-wrapper])
2757
2758 AC_CONFIG_COMMANDS([runtime/etc/mono/1.0/machine.config],
2759 [   depth=../../../..
2760     case $srcdir in
2761     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
2762     .) reldir=$depth ;;
2763     *) reldir=$depth/$srcdir ;;
2764     esac
2765     $ac_aux_dir/install-sh -d runtime/etc/mono/1.0
2766     cd runtime/etc/mono/1.0
2767     rm -f machine.config
2768     $LN_S $reldir/data/net_1_1/machine.config machine.config
2769     cd $depth
2770 ],[LN_S='$LN_S'])
2771
2772 AC_CONFIG_COMMANDS([runtime/etc/mono/2.0/machine.config],
2773 [   depth=../../../..
2774     case $srcdir in
2775     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
2776     .) reldir=$depth ;;
2777     *) reldir=$depth/$srcdir ;;
2778     esac
2779     $ac_aux_dir/install-sh -d runtime/etc/mono/2.0
2780     cd runtime/etc/mono/2.0
2781     rm -f machine.config
2782     $LN_S $reldir/data/net_2_0/machine.config machine.config
2783     cd $depth
2784 ],[LN_S='$LN_S'])
2785
2786 AC_CONFIG_COMMANDS([runtime/etc/mono/2.0/web.config],
2787 [   depth=../../../..
2788     case $srcdir in
2789     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
2790     .) reldir=$depth ;;
2791     *) reldir=$depth/$srcdir ;;
2792     esac
2793     $ac_aux_dir/install-sh -d runtime/etc/mono/2.0
2794     cd runtime/etc/mono/2.0
2795     rm -f web.config
2796     $LN_S $reldir/data/net_2_0/web.config web.config
2797     cd $depth
2798 ],[LN_S='$LN_S'])
2799
2800 AC_CONFIG_COMMANDS([runtime/etc/mono/browscap.ini],
2801 [   depth=../../..
2802     case $srcdir in
2803     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
2804     .) reldir=$depth ;;
2805     *) reldir=$depth/$srcdir ;;
2806     esac
2807     $ac_aux_dir/install-sh -d runtime/etc/mono/
2808     cd runtime/etc/mono/
2809     rm -f browscap.ini
2810     $LN_S $reldir/data/browscap.ini browscap.ini
2811     cd $depth
2812 ],[LN_S='$LN_S'])
2813
2814 AC_CONFIG_COMMANDS([runtime/etc/mono/2.0/Browsers/Compat.browser],
2815 [   depth=../../../../..
2816     case $srcdir in
2817     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
2818     .) reldir=$depth ;;
2819     *) reldir=$depth/$srcdir ;;
2820     esac
2821     $ac_aux_dir/install-sh -d runtime/etc/mono/2.0/Browsers/
2822     cd runtime/etc/mono/2.0/Browsers
2823     rm -f Compat.browser
2824     $LN_S $reldir/data/net_2_0/Browsers/Compat.browser Compat.browser
2825     cd $depth
2826 ],[LN_S='$LN_S'])
2827
2828 AC_CONFIG_COMMANDS([runtime/etc/mono/4.0/machine.config],
2829 [   depth=../../../..
2830     case $srcdir in
2831     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
2832     .) reldir=$depth ;;
2833     *) reldir=$depth/$srcdir ;;
2834     esac
2835     $ac_aux_dir/install-sh -d runtime/etc/mono/4.0
2836     cd runtime/etc/mono/4.0
2837     rm -f machine.config
2838     $LN_S $reldir/data/net_4_0/machine.config machine.config
2839     cd $depth
2840 ],[LN_S='$LN_S'])
2841
2842 AC_CONFIG_COMMANDS([runtime/etc/mono/4.0/web.config],
2843 [   depth=../../../..
2844     case $srcdir in
2845     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
2846     .) reldir=$depth ;;
2847     *) reldir=$depth/$srcdir ;;
2848     esac
2849     $ac_aux_dir/install-sh -d runtime/etc/mono/4.0
2850     cd runtime/etc/mono/4.0
2851     rm -f web.config
2852     $LN_S $reldir/data/net_4_0/web.config web.config
2853     cd $depth
2854 ],[LN_S='$LN_S'])
2855
2856 if test x$enable_quiet_build = xyes; then
2857    AC_CONFIG_COMMANDS([quiet], [for i in `find mono libgc support -name Makefile.in | sed -e 's/Makefile.in/Makefile/g'`; do if test -f $i; then $srcdir/scripts/patch-quiet.sh $i; fi; done], [shell=$SHELL])
2858    AC_CONFIG_COMMANDS([quiet-libtool], [sed -e 's/$echo "copying selected/$show "copying selected/g' < libtool > libtool.tmp && mv libtool.tmp libtool && chmod a+x libtool; sed -e 's/$ECHO "copying selected/# "copying selected/g' < libtool > libtool.tmp && mv libtool.tmp libtool && chmod a+x libtool])
2859 fi
2860
2861 AC_OUTPUT([
2862 Makefile
2863 mono-core.spec
2864 mono-uninstalled.pc
2865 scripts/mono-find-provides
2866 scripts/mono-find-requires
2867 mono/Makefile
2868 mono/utils/Makefile
2869 mono/metadata/Makefile
2870 mono/dis/Makefile
2871 mono/cil/Makefile
2872 mono/arch/Makefile
2873 mono/arch/x86/Makefile
2874 mono/arch/amd64/Makefile
2875 mono/arch/hppa/Makefile
2876 mono/arch/ppc/Makefile
2877 mono/arch/sparc/Makefile
2878 mono/arch/s390/Makefile
2879 mono/arch/s390x/Makefile
2880 mono/arch/arm/Makefile
2881 mono/arch/alpha/Makefile
2882 mono/arch/ia64/Makefile
2883 mono/arch/mips/Makefile
2884 mono/interpreter/Makefile
2885 mono/tests/Makefile
2886 mono/tests/tests-config
2887 mono/tests/assemblyresolve/Makefile
2888 mono/tests/cas/Makefile
2889 mono/tests/cas/assembly/Makefile
2890 mono/tests/cas/demand/Makefile
2891 mono/tests/cas/inheritance/Makefile
2892 mono/tests/cas/linkdemand/Makefile
2893 mono/tests/cas/threads/Makefile
2894 mono/benchmark/Makefile
2895 mono/monograph/Makefile
2896 mono/io-layer/Makefile
2897 mono/mini/Makefile
2898 mono/profiler/Makefile
2899 ikvm-native/Makefile
2900 scripts/Makefile
2901 man/Makefile
2902 docs/Makefile
2903 data/Makefile
2904 data/net_2_0/Makefile
2905 data/net_4_0/Makefile
2906 data/net_2_0/Browsers/Makefile
2907 data/mint.pc
2908 data/mono-2.pc
2909 data/monosgen-2.pc
2910 data/mono.pc
2911 data/mono-cairo.pc
2912 data/mono-nunit.pc
2913 data/mono-options.pc
2914 data/mono-lineeditor.pc
2915 data/monodoc.pc
2916 data/mono.web.pc
2917 data/dotnet.pc
2918 data/dotnet35.pc
2919 data/wcf.pc
2920 data/cecil.pc
2921 data/system.web.extensions_1.0.pc
2922 data/system.web.extensions.design_1.0.pc
2923 data/system.web.mvc.pc
2924 data/system.web.mvc2.pc
2925 samples/Makefile
2926 support/Makefile
2927 data/config
2928 tools/Makefile
2929 tools/locale-builder/Makefile
2930 tools/sgen/Makefile
2931 runtime/Makefile
2932 msvc/Makefile
2933 po/Makefile
2934 ])
2935
2936 if test x$host_win32 = xyes; then
2937    # Get rid of 'cyg' prefixes in library names
2938    sed -e "s/\/cyg\//\/\//" libtool > libtool.new; mv libtool.new libtool; chmod 755 libtool
2939    # libtool seems to inherit -mno-cygwin from our CFLAGS, and uses it to compile its executable
2940    # wrapper scripts which use exec(). gcc has no problem compiling+linking this, but the resulting
2941    # executable doesn't work...
2942    sed -e "s,-mno-cygwin,,g" libtool > libtool.new; mv libtool.new libtool; chmod 755 libtool
2943 fi
2944
2945 (
2946   case $prefix in
2947   NONE) prefix=$ac_default_prefix ;;
2948   esac
2949   case $exec_prefix in
2950   NONE) exec_prefix='${prefix}' ;;
2951   esac
2952
2953   #
2954   # If we are cross compiling, we don't build in the mcs/ tree.  Let us not clobber
2955   # any existing config.make.  This allows people to share the same source tree
2956   # with different build directories, one native and one cross
2957   #
2958   if test x$cross_compiling = xno && test x$enable_mcs_build != xno; then
2959
2960     test -w $mcs_topdir/build || chmod +w $mcs_topdir/build
2961
2962     echo "prefix=$prefix" > $mcs_topdir/build/config.make
2963     echo "exec_prefix=$exec_prefix" >> $mcs_topdir/build/config.make
2964     echo "sysconfdir=$sysconfdir" >> $mcs_topdir/build/config.make
2965     echo 'mono_libdir=${exec_prefix}/lib' >> $mcs_topdir/build/config.make
2966     echo 'MCS_FLAGS = $(PLATFORM_DEBUG_FLAGS)' >> $mcs_topdir/build/config.make
2967     echo 'IL_FLAGS = /debug' >> $mcs_topdir/build/config.make
2968     echo "RUNTIME = $mono_build_root/runtime/mono-wrapper" >> $mcs_topdir/build/config.make
2969     echo "ILDISASM = $mono_build_root/runtime/monodis-wrapper" >> $mcs_topdir/build/config.make
2970
2971     case $INSTALL in
2972     [[\\/$]]* | ?:[[\\/]]* ) mcs_INSTALL=$INSTALL ;;
2973     *) mcs_INSTALL=$mono_build_root/$INSTALL ;;
2974     esac
2975
2976     echo "INSTALL = $mcs_INSTALL" >> $mcs_topdir/build/config.make
2977
2978     export VERSION
2979     [myver=$($AWK 'BEGIN {
2980       split (ENVIRON["VERSION"] ".0.0.0", vsplit, ".")
2981       if(length(vsplit [1]) > 4) {
2982         split (substr(ENVIRON["VERSION"], 0, 4) "." substr(ENVIRON["VERSION"], 5) ".0.0", vsplit, ".")
2983       }
2984       print vsplit [1] "." vsplit [2] "." vsplit [3] "." vsplit [4]
2985     }')]
2986
2987     echo "MONO_VERSION = $myver" >> $mcs_topdir/build/config.make
2988
2989     if test x$platform_darwin = xyes; then
2990       echo "PLATFORM = darwin" >> $mcs_topdir/build/config.make
2991     fi
2992
2993         if test x$AOT_SUPPORTED = xyes -a x$enable_system_aot = xdefault; then
2994            enable_system_aot=yes
2995         fi
2996
2997         if test "x$enable_loadedllvm" = "xyes"; then
2998            # This seems to fail on the x86 buildbots
2999            enable_system_aot=no
3000         fi
3001
3002     if test x$host_win32 = xno -a x$platform_darwin != xyes -a x$enable_system_aot = xyes; then
3003       echo "ENABLE_AOT = 1" >> $mcs_topdir/build/config.make
3004     fi
3005
3006     if test x$DISABLE_MCS_DOCS = xyes; then
3007       echo "DISABLE_MCS_DOCS = yes" >> $mcs_topdir/build/config.make
3008     fi
3009
3010     if test x$with_moonlight != xno; then
3011       echo "MOONLIGHT = 1" >> $srcdir/$mcsdir/build/config.make
3012     fi
3013
3014   fi
3015
3016   # if we have an olive folder, override the default settings
3017   if test -d $olivedir; then
3018
3019     if test x$cross_compiling = xno && test x$enable_olive_build != xno; then
3020
3021       test -w $srcdir/$olivedir/build || chmod +w $srcdir/$olivedir/build
3022
3023       echo "prefix=$prefix" > $srcdir/$olivedir/build/config.make
3024       echo "exec_prefix=$exec_prefix" >> $srcdir/$olivedir/build/config.make
3025       echo 'mono_libdir=${exec_prefix}/lib' >> $srcdir/$olivedir/build/config.make
3026       echo 'MCS_FLAGS = $(PLATFORM_DEBUG_FLAGS)' >> $srcdir/$olivedir/build/config.make
3027       echo "RUNTIME = $mono_build_root/runtime/mono-wrapper" >> $srcdir/$olivedir/build/config.make
3028       echo "MONO_VERSION = $myver" >> $srcdir/$olivedir/build/config.make
3029     fi
3030   fi
3031
3032 )
3033
3034 libgdiplus_msg=${libgdiplus_loc:-assumed to be installed}
3035
3036 echo "
3037         mcs source:    $mcsdir
3038         olive source:  $olive_topdir
3039
3040    Engine:
3041         GC:            $gc_msg 
3042         TLS:           $with_tls
3043         SIGALTSTACK:   $with_sigaltstack
3044         Engine:        $jit_status
3045         oprofile:      $OPROFILE
3046         BigArrays:     $enable_big_arrays
3047         DTrace:        $enable_dtrace
3048         Parallel Mark: $enable_parallel_mark
3049         LLVM Back End: $enable_llvm (dynamically loaded: $enable_loadedllvm)
3050
3051     Libraries:
3052         Moon Profile:  $with_moonlight ($with_moon_gc)
3053         MonoDroid:     $with_monodroid
3054         MonoTouch:     $with_monotouch
3055         JNI support:   $jdk_headers_found
3056         libgdiplus:    $libgdiplus_msg
3057         zlib:          $zlib_msg
3058         $disabled
3059 "
3060 if test x$with_static_mono = xno -a "x$host_win32" != "xyes"; then
3061    AC_MSG_WARN(Turning off static Mono is a risk, you might run into unexpected bugs)
3062 fi