Merge pull request #3591 from directhex/mono_libdir_fallback
[mono.git] / configure.ac
1 # Process this file with autoconf to produce a configure script.
2 #AC_PREREQ([2.62])
3
4 # when bumping version number below, keep it in sync with man/mono.1 too
5 AC_INIT(mono, [4.9.0],
6         [http://bugzilla.xamarin.com/enter_bug.cgi?classification=Mono])
7
8 AC_CONFIG_SRCDIR([README.md])
9 AC_CONFIG_MACRO_DIR([m4])
10 AC_CANONICAL_SYSTEM
11 AC_CANONICAL_HOST
12
13 # Gross hack to enable 'make dist' on automake 1.9+tar 1.14.
14 # The extra brackets are to foil regex-based scans.
15 m4_ifdef([_A][M_PROG_TAR],[_A][M_SET_OPTION([tar-ustar])])
16
17 AM_INIT_AUTOMAKE([1.9 dist-bzip2 tar-ustar no-dist-gzip foreign subdir-objects]
18                  m4_esyscmd([case `automake --version | head -n 1` in    # parallel-tests is default in automake 1.13+, we need to explicitly enable it
19                              *1.11*|*1.12*) echo parallel-tests;;        # for 1.11 and 1.12 but not below as those versions don't recognize the flag
20                              esac]))                                     # TODO: remove this hack once we require automake 1.11+
21
22 AC_CONFIG_HEADERS([config.h])
23 AM_MAINTAINER_MODE
24
25 API_VER=2.0
26 AC_SUBST(API_VER)
27
28 AC_PROG_LN_S
29
30 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
31
32 case $host_os in
33 *cygwin* )
34                  echo "Run configure using ./configure --host=i686-pc-mingw32"
35                  exit 1
36 esac
37
38 # In case of cygwin, override LN_S, irrespective of what it determines.
39 # The build uses cygwin, but the actual runtime doesn't.
40 case $host_os in
41 *cygwin* ) LN_S='cp -p';;
42 esac
43
44 #
45 # libgc defaults
46 #
47 libgc_configure_args=
48
49 # These variables are the CPPFLAGS/CFLAGS passed to libgc's configure
50 # libgc should inherit the original CFLAGS/CPPFLAGS passed to configure, i.e. -O0
51 CPPFLAGS_FOR_LIBGC=$CPPFLAGS
52 CFLAGS_FOR_LIBGC=$CFLAGS
53 CPPFLAGS_FOR_EGLIB=$CPPFLAGS
54 CFLAGS_FOR_EGLIB=$CFLAGS
55 CPPFLAGS_FOR_BTLS=$CPPFLAGS
56 CFLAGS_FOR_BTLS=$CFLAGS
57
58 # libgc uses some deprecated APIs
59 CFLAGS_FOR_LIBGC="$CFLAGS -Wno-deprecated-declarations"
60
61 #
62 # These are the flags that need to be stored in the mono.pc file for 
63 # compiling code that will embed Mono
64 #
65 libmono_cflags=""
66 libmono_ldflags=""
67 AC_SUBST(libmono_cflags)
68 AC_SUBST(libmono_ldflags)
69
70 # Variable to have relocatable .pc files (lib, or lib64)
71 # realpath isn't always available, and requires that all but the tip of the provided
72 # path exists. Fall back to the old behaviour, but realpath allows depth >1
73 # e.g. Debian puts Mono in /usr/bin and libs in /usr/lib/x86_64-linux-gnu/ which is
74 # too deep for the old method to work
75 reloc_libdir=`realpath --relative-to=${prefix} ${libdir} 2> /dev/null || basename ${libdir}`
76 AC_SUBST(reloc_libdir)
77
78 # Set to yes if Unix sockets cannot be created in an anonymous namespace
79 need_link_unlink=no
80
81 #Set to extra linker flags to be passed to the runtime binaries (mono /mono-sgen)
82 extra_runtime_ldflags=""
83
84 # Thread configuration inspired by sleepycat's db
85 AC_MSG_CHECKING([host platform characteristics])
86 libgc_threads=no
87 has_dtrace=no
88 parallel_mark=yes
89 ikvm_native=yes
90
91 host_win32=no
92 target_win32=no
93 platform_android=no
94 host_darwin=no
95 case "$host" in
96         *-mingw*|*-*-cygwin*)
97                 AC_DEFINE(DISABLE_PORTABILITY,1,[Disable the io-portability layer])
98                 AC_DEFINE(PLATFORM_NO_SYMLINKS,1,[This platform does not support symlinks])
99                 host_win32=yes
100                 mono_cv_clang=no
101                 if test "x$cross_compiling" = "xno"; then
102                         if test "x$host" = "x$build" -a "x$host" = "x$target"; then
103                                 target_win32=yes
104                         fi
105                 else
106                         if test "x$host" = "x$target"; then
107                                 target_win32=yes
108                         fi
109                 fi
110                 HOST_CC="gcc"
111                 # Windows Vista or later is required
112                 CPPFLAGS="$CPPFLAGS -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 -D_WIN32_IE=0x0501 -D_UNICODE -DUNICODE -DWIN32_THREADS -DFD_SETSIZE=1024"
113                 LDFLAGS="$LDFLAGS -lmswsock -lws2_32 -lole32 -loleaut32 -lpsapi -lversion -ladvapi32 -lwinmm -lkernel32 -liphlpapi"
114                 libmono_cflags="-mms-bitfields -mwindows"
115                 libmono_ldflags="-mms-bitfields -mwindows"
116                 libdl=
117                 libgc_threads=win32
118                 with_sigaltstack=no
119                 with_tls=pthread
120                 LN_S=cp
121                 # This forces libgc to use the DllMain based thread registration code on win32
122                 libgc_configure_args="$libgc_configure_args --enable-win32-dllmain=yes"
123                 ;;
124         *-*-*netbsd*)
125                 CPPFLAGS="$CPPFLAGS -D_REENTRANT -DGC_NETBSD_THREADS -D_GNU_SOURCE"
126                 libmono_cflags="-D_REENTRANT"
127                 LDFLAGS="$LDFLAGS -pthread"
128                 CPPFLAGS="$CPPFLAGS -DPLATFORM_BSD"
129                 libmono_ldflags="-pthread"
130                 need_link_unlink=yes
131                 libdl="-ldl"
132                 libgc_threads=pthreads
133                 with_sigaltstack=no
134                 use_sigposix=yes
135                 ;;
136         *-*-kfreebsd*-gnu)
137                 CPPFLAGS="$CPPFLAGS -DGC_FREEBSD_THREADS -D_GNU_SOURCE -D_REENTRANT -DUSE_MMAP -DUSE_MUNMAP -DTHREAD_LOCAL_ALLOC -pthread"
138                 libmono_cflags="-D_REENTRANT -DTHREAD_LOCAL_ALLOC -pthread"
139                 libmono_ldflags="-lpthread -pthread"
140                 libdl="-ldl"
141                 libgc_threads=pthreads
142                 need_link_unlink=yes
143                 with_sigaltstack=no
144                 use_sigposix=yes
145                 ;;
146         *-*-*freebsd*)
147                 if test "x$PTHREAD_CFLAGS" = "x"; then
148                         CPPFLAGS="$CPPFLAGS -DGC_FREEBSD_THREADS"
149                         libmono_cflags=
150                 else
151                         CPPFLAGS="$CPPFLAGS $PTHREAD_CFLAGS -DGC_FREEBSD_THREADS"
152                         libmono_cflags="$PTHREAD_CFLAGS"
153                 fi
154                 if test "x$PTHREAD_LIBS" = "x"; then
155                         LDFLAGS="$LDFLAGS -pthread -L/usr/local/lib"
156                         libmono_ldflags="-pthread"
157                 else
158                         LDFLAGS="$LDFLAGS $PTHREAD_LIBS -L/usr/local/lib"
159                         libmono_ldflags="$PTHREAD_LIBS"
160                 fi
161                 CPPFLAGS="$CPPFLAGS -DPLATFORM_BSD"
162                 need_link_unlink=yes
163                 AC_DEFINE(PTHREAD_POINTER_ID, 1, [pthread is a pointer])
164                 libdl=
165                 libgc_threads=pthreads
166                 use_sigposix=yes
167                 has_dtrace=yes
168                 ;;
169         *-*-*openbsd*)
170                 CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE -DGC_OPENBSD_THREADS -DPLATFORM_BSD -D_REENTRANT -DUSE_MMAP"
171                 if test "x$disable_munmap" != "xyes"; then
172                 CPPFLAGS="$CPPFLAGS -DUSE_MUNMAP"
173                 fi
174                 libmono_cflags="-D_THREAD_SAFE -D_REENTRANT"
175                 LDFLAGS="$LDFLAGS -pthread"
176                 need_link_unlink=yes
177                 AC_DEFINE(PTHREAD_POINTER_ID)
178                 libdl=
179                 libgc_threads=pthreads
180                 with_sigaltstack=no
181                 use_sigposix=yes
182                 ;;
183         *-*-linux-android*)
184                 platform_android=yes
185                 AC_DEFINE(PLATFORM_ANDROID,1,[Targeting the Android platform])
186                 AC_DEFINE(TARGET_ANDROID,1,[Targeting the Android platform])
187
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="-ldl"
194                 libgc_threads=pthreads
195                 use_sigposix=yes
196
197                 with_tls=pthread
198                 with_sigaltstack=no
199                 with_static_mono=no
200
201                 # Android doesn't support boehm, as it's missing <link.h>
202                 support_boehm=no
203                 with_gc=sgen
204
205                 # isinf(3) requires -lm; see isinf check below
206                 LDFLAGS="$LDFLAGS -lm"
207
208                 # Bionic's <pthread.h> sets PTHREAD_STACK_MIN=2*PAGE_SIZE; doesn't define
209                 # PAGE_SIZE; breaks mono/io-layer/collection.c
210                 # Bionic doesn't provide S_IWRITE; breaks io-layer/io.c
211                 CFLAGS="$CFLAGS -DPAGE_SIZE=4096 -DS_IWRITE=S_IWUSR"
212                 CXXFLAGS="$CXXFLAGS -DPAGE_SIZE=4096 -DS_IWRITE=S_IWUSR"
213
214                 # The configure check can't detect this
215                 AC_DEFINE(HAVE_LARGE_FILE_SUPPORT, 1, [Have large file support])
216
217                 # to bypass the underscore linker check, can't work when cross-compiling
218                 mono_cv_uscore=yes
219                 mono_cv_clang=no
220                 ;;
221         *-*-linux*)
222                 CPPFLAGS="$CPPFLAGS -DGC_LINUX_THREADS -D_GNU_SOURCE -D_REENTRANT -DUSE_MMAP"
223                 if test "x$disable_munmap" != "xyes"; then
224                         CPPFLAGS="$CPPFLAGS -DUSE_MUNMAP"
225                 fi
226                 libmono_cflags="-D_REENTRANT"
227                 libdl="-ldl"
228                 libgc_threads=pthreads
229                 use_sigposix=yes
230                 if test "x$cross_compiling" != "xno"; then
231                         # to bypass the underscore linker check, not
232                         # available during cross-compilation
233                         mono_cv_uscore=no
234                 fi
235                 case "$host" in
236                 aarch64-*)
237                         support_boehm=no
238                         with_gc=sgen
239                         ;;
240                 powerpc*-*-linux*)
241                         # https://bugzilla.novell.com/show_bug.cgi?id=504411
242                         disable_munmap=yes
243                         ;;
244                 esac
245                 ;;
246         *-*-nacl*)
247                 CPPFLAGS="$CPPFLAGS -DGC_LINUX_THREADS -D_GNU_SOURCE -D_REENTRANT -DUSE_MMAP"
248                 if test "x$disable_munmap" != "xyes"; then
249                         CPPFLAGS="$CPPFLAGS -DUSE_MUNMAP"
250                 fi
251                 libmono_cflags="-D_REENTRANT"
252                 libdl=
253                 libgc_threads=pthreads
254                 use_sigposix=yes
255                 ikvm_native=no
256                 AC_DEFINE(DISABLE_SOCKETS,1,[Disable sockets support])
257                 AC_DEFINE(DISABLE_ATTACH, 1, [Disable agent attach support])
258                 ;;
259         *-*-hpux*)
260                 CPPFLAGS="$CPPFLAGS -DGC_HPUX_THREADS -D_HPUX_SOURCE -D_XOPEN_SOURCE_EXTENDED -D_REENTRANT"
261                 # +ESdbgasm only valid on bundled cc on RISC
262                 # silently ignored for ia64
263                 if test $GCC != "yes"; then
264                         CFLAGS="$CFLAGS +ESdbgasm"
265                         # Arrange for run-time dereferencing of null
266                         # pointers to produce a SIGSEGV signal.
267                         LDFLAGS="$LDFLAGS -z"
268                 fi
269                 CFLAGS="$CFLAGS +ESdbgasm"
270                 LDFLAGS="$LDFLAGS -z"
271                 libmono_cflags="-D_REENTRANT"
272                 libmono_ldflags="-lpthread"
273                 libgc_threads=pthreads
274                 need_link_unlink=yes
275                 use_sigposix=yes
276                 ;;
277         *-*-solaris*)
278                 CPPFLAGS="$CPPFLAGS -DGC_SOLARIS_THREADS -DGC_SOLARIS_PTHREADS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -DUSE_MMAP -DUSE_MUNMAP -DPLATFORM_SOLARIS"
279                 need_link_unlink=yes
280                 libmono_cflags="-D_REENTRANT"
281                 libgc_threads=pthreads
282                 has_dtrace=yes
283                 use_sigposix=yes
284                 enable_solaris_tar_check=yes
285                 ;;
286         *-*-darwin*)
287                 parallel_mark="Disabled_Currently_Hangs_On_MacOSX"
288                 host_darwin=yes
289                 target_mach=yes
290                 CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE -DGC_MACOSX_THREADS -DPLATFORM_MACOSX -DUSE_MMAP -DUSE_MUNMAP"
291                 libmono_cflags="-D_THREAD_SAFE"
292                 need_link_unlink=yes
293                 AC_DEFINE(PTHREAD_POINTER_ID)
294                 AC_DEFINE(USE_MACH_SEMA, 1, [...])
295                 libdl=
296                 libgc_threads=pthreads
297                 has_dtrace=yes
298                 if test "x$cross_compiling" = "xyes"; then
299                         has_broken_apple_cpp=yes
300                 fi
301                 dnl Snow Leopard is horribly broken -- it reports itself as i386-apple-darwin*, but
302                 dnl its gcc defaults to 64-bit mode.  They have also deprecated the usage of ucontext
303                 dnl we need to set some flags to build our 32-bit binaries on 10.6 properly
304                 case "$host" in
305                         dnl Snow Leopard and newer config.guess reports as this
306                         i*86-*-darwin*)
307                                 BROKEN_DARWIN_FLAGS="-arch i386 -D_XOPEN_SOURCE"
308                                 BROKEN_DARWIN_CPPFLAGS="-D_XOPEN_SOURCE"
309                                 CPPFLAGS="$CPPFLAGS $BROKEN_DARWIN_CPPFLAGS"
310                                 CFLAGS="$CFLAGS $BROKEN_DARWIN_FLAGS"
311                                 CXXFLAGS="$CXXFLAGS $BROKEN_DARWIN_FLAGS"
312                                 CCASFLAGS="$CCASFLAGS $BROKEN_DARWIN_FLAGS"
313                                 CPPFLAGS_FOR_LIBGC="$CPPFLAGS_FOR_LIBGC $BROKEN_DARWIN_CPPFLAGS"
314                                 CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC $BROKEN_DARWIN_FLAGS"
315                                 CPPFLAGS_FOR_EGLIB="$CPPFLAGS_FOR_EGLIB $BROKEN_DARWIN_CPPFLAGS"
316                                 CFLAGS_FOR_EGLIB="$CFLAGS_FOR_EGLIB $BROKEN_DARWIN_FLAGS"
317                                 ;;
318                         x*64-*-darwin*)
319                                 ;;
320                         arm*-darwin*)
321                                 has_dtrace=no
322                                 ;;                      
323                 esac
324                 ;;
325         *-*-haiku*)
326                 CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_THREAD_SAFE"
327                 libmono_cflags="-D_REENTRANT -D_THREAD_SAFE"
328                 libdl=
329                 LIBS="$LIBS -lnetwork"
330                 need_link_unlink=yes
331                 AC_DEFINE(PTHREAD_POINTER_ID)
332                 libgc_threads=pthreads
333                 use_sigposix=yes
334                 ;;
335         *)
336                 AC_MSG_WARN([*** Please add $host to configure.ac checks!])
337                 libdl="-ldl"
338                 ;;
339 esac
340 AC_MSG_RESULT(ok)
341
342 if test x$need_link_unlink = xyes; then
343    AC_DEFINE(NEED_LINK_UNLINK, 1, [Define if Unix sockets cannot be created in an anonymous namespace])
344 fi
345
346 if test x$host_win32 = xyes; then
347    AC_DEFINE(HOST_WIN32, 1, [Host Platform is Win32])
348 fi
349
350 if test x$target_win32 = xyes; then
351    AC_DEFINE(TARGET_WIN32, 1, [Target Platform is Win32])
352 fi
353
354 # Defined for all targets/platforms using classic Windows API support.
355 AC_DEFINE(HAVE_CLASSIC_WINAPI_SUPPORT, 1, [Use classic Windows API support])
356 AC_DEFINE(HAVE_UWP_WINAPI_SUPPORT, 0, [Don't use UWP Windows API support])
357
358 AC_SUBST(extra_runtime_ldflags)
359 AM_CONDITIONAL(HOST_WIN32, test x$host_win32 = xyes)
360 AM_CONDITIONAL(TARGET_WIN32, test x$target_win32 = xyes)
361 AM_CONDITIONAL(PLATFORM_LINUX, echo x$target_os | grep -q linux)
362 AM_CONDITIONAL(PLATFORM_DARWIN, test x$host_darwin = xyes)
363 AM_CONDITIONAL(PLATFORM_SIGPOSIX, test x$use_sigposix = xyes)
364 AM_CONDITIONAL(PLATFORM_ANDROID, test x$platform_android = xyes)
365
366 if test -z "$PLATFORM_DARWIN_TRUE"; then :
367 PLATFORM_AOT_SUFFIX=.dylib
368 fi
369
370 if test -z "$PLATFORM_LINUX_TRUE"; then :
371 PLATFORM_AOT_SUFFIX=.so
372 fi
373
374 AC_SUBST(PLATFORM_AOT_SUFFIX)
375
376 ## PLATFORM_AOT_SUFFIX not so simple for windows :-)
377
378 AC_CHECK_TOOL(CC, gcc, gcc)
379 AC_PROG_CC
380 AC_CHECK_TOOL(CXX, g++, g++)
381 AC_PROG_CXX
382 AM_PROG_AS
383 AC_PROG_INSTALL
384 AC_PROG_AWK
385 AM_PROG_CC_C_O
386 dnl We should use AM_PROG_AS, but it's not available on automake/aclocal 1.4
387 : ${CCAS='$(CC)'}
388 # Set ASFLAGS if not already set.
389 : ${CCASFLAGS='$(CFLAGS)'}
390 AC_SUBST(CCAS)
391 AC_SUBST(CCASFLAGS)
392
393 # AC_PROG_CXX helpfully sets CXX to g++ even if no c++ compiler is found so check
394 # GXX instead. See http://lists.gnu.org/archive/html/bug-autoconf/2002-04/msg00056.html
395 if test "x$CXX" = "xg++"; then
396         if test "x$GXX" != "xyes"; then
397                 # automake/libtool is so broken, it requires g++ even if the c++ sources
398                 # are inside automake conditionals
399                 AC_MSG_ERROR([You need to install g++])
400         fi
401 fi
402
403 dnl may require a specific autoconf version
404 dnl AC_PROG_CC_FOR_BUILD
405 dnl CC_FOR_BUILD not automatically detected
406 CC_FOR_BUILD=$CC
407 CFLAGS_FOR_BUILD=$CFLAGS
408 BUILD_EXEEXT=
409 if test "x$cross_compiling" = "xyes"; then
410         CC_FOR_BUILD=cc
411         CFLAGS_FOR_BUILD=
412         BUILD_EXEEXT=""
413 fi
414 AC_SUBST(CC_FOR_BUILD)
415 AC_SUBST(CFLAGS_FOR_BUILD)
416 AC_SUBST(HOST_CC)
417 AC_SUBST(BUILD_EXEEXT)
418
419 AM_CONDITIONAL(CROSS_COMPILING, [test x$cross_compiling = xyes])
420 AM_CONDITIONAL(USE_BATCH_FILES, [test x$host_win32 = xyes -a x$cross_compiling = xyes])
421
422 # Set STDC_HEADERS
423 AC_HEADER_STDC
424 AC_LIBTOOL_WIN32_DLL
425 # This causes monodis to not link correctly
426 #AC_DISABLE_FAST_INSTALL
427 AM_PROG_LIBTOOL
428 # Use dolt (http://dolt.freedesktop.org/) instead of libtool for building.
429 DOLT
430
431 export_ldflags=`(./libtool --config; echo eval echo \\$export_dynamic_flag_spec) | sh`
432 AC_SUBST(export_ldflags)
433
434 # Test whenever ld supports -version-script
435 AC_PROG_LD
436 AC_PROG_LD_GNU
437
438 AM_ICONV()
439
440 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 sys/sysctl.h libproc.h sys/prctl.h)
441 AC_CHECK_HEADERS(sys/param.h sys/socket.h sys/ipc.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 sys/inotify.h arpa/inet.h complex.h unwind.h)
442 AC_CHECK_HEADERS([linux/netlink.h linux/rtnetlink.h],
443                   [], [], [#include <stddef.h>
444                   #include <sys/socket.h>
445                   #include <linux/socket.h>])
446
447 AC_CHECK_HEADERS(sys/user.h, [], [],
448 [
449 #ifdef HAVE_SYS_PARAM_H
450 # include <sys/param.h>
451 #endif
452 ])
453
454 AC_CHECK_HEADERS(linux/serial.h)
455
456 AC_CHECK_HEADER(zlib.h, [have_zlib=yes], [have_zlib=no])
457 if test x$have_zlib = xyes; then
458    AC_TRY_COMPILE([#include <zlib.h>], [
459    #if defined(ZLIB_VERNUM) && (ZLIB_VERNUM >= 0x1230)
460    return 0;
461    #else
462    #error No good zlib found
463    #endif
464    ],[
465         AC_MSG_RESULT(Using system zlib)
466         zlib_msg="system zlib"
467         AC_DEFINE(HAVE_SYS_ZLIB,1,[Have system zlib])
468    ],[
469         AC_MSG_RESULT(Using embedded zlib)
470         have_zlib=no
471         zlib_msg="bundled zlib"
472    ])
473 fi
474
475 AM_CONDITIONAL(HAVE_ZLIB, test x$have_zlib = xyes)
476 AC_DEFINE(HAVE_ZLIB,1,[Have system zlib])
477
478 # for mono/metadata/debug-symfile.c
479 AC_CHECK_HEADERS(elf.h)
480
481 # for support
482 AC_CHECK_HEADERS(poll.h)
483 AC_CHECK_HEADERS(sys/poll.h)
484 AC_CHECK_HEADERS(sys/wait.h)
485 AC_CHECK_HEADERS(grp.h)
486 AC_CHECK_HEADERS(syslog.h)
487
488 # for mono/dis
489 AC_CHECK_HEADERS(wchar.h)
490 AC_CHECK_HEADERS(ieeefp.h)
491 AC_MSG_CHECKING(for isinf)
492 AC_TRY_LINK([#include <math.h>], [
493         int f = isinf (1.0);
494 ], [
495         AC_MSG_RESULT(yes)
496         AC_DEFINE(HAVE_ISINF, 1, [isinf available])
497 ], [
498         # We'll have to use signals
499         AC_MSG_RESULT(no)
500 ])
501 # mingw
502 AC_CHECK_FUNCS(_finite, , AC_MSG_CHECKING(for _finite in math.h)
503         AC_TRY_LINK([#include <math.h>], 
504         [ _finite(0.0); ], 
505         AC_DEFINE(HAVE__FINITE, 1, [Have _finite in -lm]) AC_MSG_RESULT(yes),
506         AC_MSG_RESULT(no)))
507
508 # for Linux statfs support
509 AC_CHECK_HEADERS(linux/magic.h)
510
511 # not 64 bit clean in cross-compile
512 AC_CHECK_SIZEOF(void *, 4)
513
514 AC_CACHE_CHECK([for clang],
515         mono_cv_clang,[
516         AC_TRY_COMPILE([], [
517                 #ifdef __clang__
518                 #else
519                 #error "FAILED"
520                 #endif
521                 return 0;
522         ],
523         [mono_cv_clang=yes],
524         [mono_cv_clang=no],
525         [])
526 ])
527
528 AC_ARG_ENABLE(visibility-hidden,
529 [  --disable-visibility-hidden    disable usage of -fvisiblity=hidden],
530    disable_visibility_hidden=yes, disable_visibility_hidden=no)
531
532 WARN=''
533 if test x"$GCC" = xyes; then
534         WARN='-Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes  -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wno-cast-qual -Wwrite-strings -Wno-switch -Wno-switch-enum -Wno-unused-value -Wno-attributes'
535
536                 # We require C99 with some GNU extensions, e.g. `linux` macro
537                 CFLAGS="$CFLAGS -std=gnu99"
538
539                 # The runtime code does not respect ANSI C strict aliasing rules
540                 CFLAGS="$CFLAGS -fno-strict-aliasing"
541
542                 # We rely on signed overflow to behave
543                 CFLAGS="$CFLAGS -fwrapv"
544
545                 # We rely on zero length arrays in structs
546                 CFLAGS="$CFLAGS -Wno-zero-length-array"
547
548                 CFLAGS="$CFLAGS -DMONO_DLL_EXPORT"
549                 if test x"$disable_visibility_hidden" = xno; then
550                    # Don't export any symbols by default
551                    SHARED_CFLAGS="-fvisibility=hidden"
552                    CFLAGS_FOR_EGLIB="$CFLAGS_FOR_EGLIB -fvisibility=hidden"
553                    CXXFLAGS="$CXXFLAGS -fvisibility=hidden"
554                 fi
555
556                 ORIG_CFLAGS=$CFLAGS
557                 # Check for the normal version, since gcc ignores unknown -Wno options
558                 CFLAGS="$CFLAGS -Wunused-but-set-variable -Werror"
559                 AC_MSG_CHECKING(for -Wno-unused-but-set-variable option to gcc)
560                 AC_TRY_COMPILE([],[
561                                 return 0;
562                 ], [
563                    AC_MSG_RESULT(yes)
564                    CFLAGS="$ORIG_CFLAGS -Wno-unused-but-set-variable"
565                 ], [
566                    AC_MSG_RESULT(no)
567                    CFLAGS=$ORIG_CFLAGS
568                 ])
569
570                 if test "x$mono_cv_clang" = "xyes"; then
571                    # https://bugzilla.samba.org/show_bug.cgi?id=8118
572                    WARN="$WARN -Qunused-arguments"
573                    WARN="$WARN -Wno-unused-function -Wno-tautological-compare -Wno-parentheses-equality -Wno-self-assign -Wno-return-stack-address -Wno-constant-logical-operand"
574                 fi
575 else
576         # The Sun Forte compiler complains about inline functions that access static variables
577         # so disable all inlining.
578         case "$host" in
579         *-*-solaris*)
580                 CFLAGS="$CFLAGS -Dinline="
581                 ;;
582         esac
583 fi
584 CFLAGS="$CFLAGS -g $WARN"
585 CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC -g"
586 CPPFLAGS="$CPPFLAGS -g $WARN"
587
588 # Where's the 'mcs' source tree?
589 if test -d $srcdir/mcs; then
590   mcsdir=mcs
591 else
592   mcsdir=../mcs
593 fi
594
595 AC_ARG_WITH(mcs-path, [  --with-mcs-path=/path/to/mcs      Specify an alternate mcs source tree],
596         if test x$with_mcs_path != "x" -a -d $with_mcs_path ; then
597                 mcsdir=$with_mcs_path
598         fi
599 )
600
601 AC_ARG_WITH(jumptables, [  --with-jumptables=yes,no      enable/disable support for jumptables (ARM-only for now) (defaults to no)],[],[with_jumptables=no])
602
603 #
604 # A sanity check to catch cases where the package was unpacked
605 # with an ancient tar program (Solaris)
606 #
607 AC_ARG_ENABLE(solaris-tar-check,
608 [  --disable-solaris-tar-check    disable solaris tar check],
609    do_solaris_tar_check=no, do_solaris_tar_check=yes)
610
611 if test x"$do_solaris_tar_check" = xyes -a x"$enable_solaris_tar_check" = xyes; then
612         AC_MSG_CHECKING(integrity of package)
613         if test -f $mcsdir/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapTypeMapper.cs
614         then
615                 AC_MSG_RESULT(ok)
616         else
617                 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"
618                 AC_MSG_ERROR([$errorm])
619         fi
620 fi
621
622 if test "x$with_mcs_path" != "x"; then
623 mcs_topdir=$(cd "$mcsdir" && pwd)
624 mcs_topdir_from_srcdir=$mcs_topdir
625 else
626 mcs_topdir=$(cd "$srcdir/$mcsdir" && pwd)
627 mcs_topdir_from_srcdir='$(top_builddir)'/$mcsdir
628 fi
629
630 # Convert mcs_topdir* paths to Windows syntax.
631 if test x$cross_compiling$host_win32 = xnoyes; then
632   mcs_topdir=$(cygpath -m $mcs_topdir)
633   case $mcs_topdir_from_srcdir in
634     /cygdrive/*)
635         mcs_topdir_from_srcdir=$(cygpath -m $mcs_topdir_from_srcdir)
636         ;;
637   esac
638 fi
639
640 AC_SUBST([mcs_topdir])
641 AC_SUBST([mcs_topdir_from_srcdir])
642
643 # gettext: prepare the translation directories. 
644 # we do not configure the full gettext, as we consume it dynamically from C#
645 AM_PO_SUBDIRS
646
647 if test "x$USE_NLS" = "xyes"; then
648    AC_CHECK_PROG(HAVE_MSGFMT, msgfmt,yes,no)
649
650    if test "x$HAVE_MSGFMT" = "xno"; then
651           AC_MSG_ERROR([msgfmt not found. You need to install the 'gettext' package, or pass --enable-nls=no to configure.])
652    fi
653 fi
654
655 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
656
657 pkg_config_path=
658 AC_ARG_WITH(crosspkgdir, [  --with-crosspkgdir=/path/to/pkg-config/dir      Change pkg-config dir to custom dir],
659         if test x$with_crosspkgdir = "x"; then
660                 if test -s $PKG_CONFIG_PATH; then
661                         pkg_config_path=$PKG_CONFIG_PATH
662                 fi
663         else
664                 pkg_config_path=$with_crosspkgdir
665                 PKG_CONFIG_PATH=$pkg_config_path
666                 export PKG_CONFIG_PATH
667         fi
668 )
669
670 AC_ARG_ENABLE(werror, [  --enable-werror Pass -Werror to the C compiler], werror_flag=$enableval, werror_flag=no)
671 if test x$werror_flag = xyes; then
672         WERROR_CFLAGS="-Werror"
673 fi
674 AC_SUBST([WERROR_CFLAGS])
675 AC_SUBST([SHARED_CFLAGS])
676
677 ac_configure_args="$ac_configure_args \"CPPFLAGS_FOR_EGLIB=$EGLIB_CPPFLAGS\" \"CFLAGS_FOR_EGLIB=$CFLAGS_FOR_EGLIB\""
678 AC_CONFIG_SUBDIRS(eglib)
679
680 GLIB_CFLAGS='-I$(top_srcdir)/eglib/src -I$(top_builddir)/eglib/src'
681 GLIB_LIBS='-L$(top_builddir)/eglib/src -leglib -lm'
682   
683 AC_SUBST(GLIB_CFLAGS)
684 AC_SUBST(GLIB_LIBS)
685
686 # Enable support for fast thread-local storage
687 # Some systems have broken support, so we allow to disable it.
688 AC_ARG_WITH(tls, [  --with-tls=__thread,pthread    select Thread Local Storage implementation (defaults to __thread)],[],[with_tls=__thread])
689
690 # Enable support for using sigaltstack for SIGSEGV and stack overflow handling
691 # This does not work on some platforms (bug #55253)
692 AC_ARG_WITH(sigaltstack, [  --with-sigaltstack=yes,no      enable/disable support for sigaltstack (defaults to yes)],[],[with_sigaltstack=yes])
693
694 AC_ARG_WITH(static_mono, [  --with-static_mono=yes,no      link mono statically to libmono (faster) (defaults to yes)],[],[with_static_mono=yes])
695 AC_ARG_WITH(shared_mono, [  --with-shared_mono=yes,no      build a shared libmono library (defaults to yes)],[],[with_shared_mono=yes])
696 # Same as --with-shared_mono=no
697 AC_ARG_ENABLE(libraries, [  --disable-libraries disable the build of libmono], enable_libraries=$enableval, enable_libraries=yes)
698
699 if test "x$enable_static" = "xno"; then
700    with_static_mono=no
701 fi
702
703 if test "x$enable_shared" = "xno"; then
704    with_shared_mono=no
705 fi
706
707 if test "x$enable_libraries" = "xno"; then
708    with_shared_mono=no
709 fi
710
711 AM_CONDITIONAL(DISABLE_LIBRARIES, test x$enable_libraries = xno)
712
713 case $host in
714 *nacl* ) with_shared_mono=yes;;
715 esac
716
717 if test "x$host_win32" = "xyes"; then
718    # Boehm GC requires the runtime to be in its own dll
719    with_static_mono=no
720 fi
721
722 AM_CONDITIONAL(STATIC_MONO, test x$with_static_mono != xno)
723 AM_CONDITIONAL(SHARED_MONO, test x$with_shared_mono != xno)
724 AC_ARG_ENABLE(mcs-build, [  --disable-mcs-build disable the build of the mcs directory], try_mcs_build=$enableval, enable_mcs_build=yes)
725
726 AC_ARG_WITH(xen_opt,   [  --with-xen_opt=yes,no          Enable Xen-specific behaviour (defaults to yes)],[],[with_xen_opt=yes])
727 if test "x$with_xen_opt" = "xyes" -a "x$mono_cv_clang" = "xno"; then
728         AC_DEFINE(MONO_XEN_OPT, 1, [Xen-specific behaviour])
729         ORIG_CFLAGS=$CFLAGS
730         CFLAGS="$CFLAGS -mno-tls-direct-seg-refs"
731         AC_MSG_CHECKING(for -mno-tls-direct-seg-refs option to gcc)
732         AC_TRY_COMPILE([], [
733                 return 0;
734         ], [
735            AC_MSG_RESULT(yes)
736            # Pass it to libgc as well
737            CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC -mno-tls-direct-seg-refs"
738         ], [
739            AC_MSG_RESULT(no)
740            CFLAGS=$ORIG_CFLAGS
741         ])
742 fi
743
744 AC_ARG_ENABLE(small-config, [  --enable-small-config Enable tweaks to reduce requirements (and capabilities)], enable_small_config=$enableval, enable_small_config=no)
745
746 if test x$enable_small_config = xyes; then
747         AC_DEFINE(MONO_SMALL_CONFIG,1,[Reduce runtime requirements (and capabilities)])
748         CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC -DSMALL_CONFIG"
749 fi
750
751 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)
752
753 DISABLED_FEATURES=none
754
755 #
756 # Set the build profiles and options before things which use them
757 #
758
759 AC_ARG_WITH(profile4_x,      [  --with-profile4=yes,no          If you want to install the 4.x FX (defaults to yes)],                 [], [with_profile4_x=default])
760 AC_ARG_WITH(monodroid,       [  --with-monodroid=yes,no         If you want to build the MonoDroid assemblies (defaults to no)],      [], [with_monodroid=default])
761 AC_ARG_WITH(monotouch,       [  --with-monotouch=yes,no         If you want to build the Xamarin.iOS assemblies (defaults to no)],    [], [with_monotouch=default])
762 AC_ARG_WITH(monotouch_watch, [  --with-monotouch_watch=yes,no   If you want to build the Xamarin.WatchOS assemblies (defaults to no)],[], [with_monotouch_watch=default])
763 AC_ARG_WITH(monotouch_tv,    [  --with-monotouch_tv=yes,no      If you want to build the Xamarin.TVOS assemblies (defaults to no)],   [], [with_monotouch_tv=default])
764 AC_ARG_WITH(bitcode,         [  --with-bitcode=yes,no           If bitcode is enabled (defaults to no)],                              [], [with_bitcode=default])
765 AC_ARG_WITH(xammac,          [  --with-xammac=yes,no            If you want to build the Xamarin.Mac assemblies (defaults to no)],    [], [with_xammac=default])
766 AC_ARG_WITH(mobile_static,   [  --with-mobile_static=yes,no     If you want to build the mobile_static assemblies (defaults to no)],  [], [with_mobile_static=default])
767
768 AC_ARG_WITH(runtime_preset, [  --with-runtime_preset=net_4_x,all,mobile_static,bitcode_mobile_static   Which default profile to build (defaults to net_4_x)],  [], [with_runtime_preset=net_4_x])
769
770 dnl
771 dnl Profile defaults
772 dnl
773 TEST_PROFILE=default
774 enable_llvm_default=no
775
776 INVARIANT_AOT_OPTIONS=nimt-trampolines=900,ntrampolines=8000,nrgctx-fetch-trampolines=256,ngsharedvt-trampolines=2800
777
778 if test x$cross_compiling = xyes -o x$enable_mcs_build = xno; then
779    DISABLE_MCS_DOCS_default=yes
780    with_profile4_x_default=no
781    with_monodroid_default=no
782    with_monotouch_default=no
783    with_monotouch_watch_default=no
784    with_monotouch_tv_default=no
785    with_xammac_default=no
786    with_mobile_static_default=no
787    with_bitcode_default=no
788    with_cooperative_gc_default=no
789 elif test x$with_runtime_preset = xnet_4_x; then
790    with_cooperative_gc_default=no
791    with_profile4_x_default=yes
792    with_monodroid_default=no
793    with_monotouch_default=no
794    with_monotouch_watch_default=no
795    with_monotouch_tv_default=no
796    with_xammac_default=no
797    with_mobile_static_default=no
798    with_bitcode_default=no
799 elif test x$with_runtime_preset = xall; then
800    with_cooperative_gc_default=no
801    with_profile4_x_default=yes
802    with_monodroid_default=yes
803    with_monotouch_default=yes
804    with_monotouch_watch_default=yes
805    with_monotouch_tv_default=yes
806    with_xammac_default=yes
807    with_mobile_static_default=no
808    with_bitcode_default=no
809 elif test x$with_runtime_preset = xmobile_static; then
810    DISABLE_MCS_DOCS_default=yes
811    with_cooperative_gc_default=no
812    with_profile4_x_default=no
813    with_monodroid_default=no
814    with_monotouch_default=no
815    with_monotouch_watch_default=no
816    with_monotouch_tv_default=no
817    with_xammac_default=no
818    with_mobile_static_default=yes
819    with_bitcode_default=no
820    with_cooperative_gc_default=no
821    TEST_PROFILE=mobile_static 
822
823    mono_feature_disable_com='yes'
824    mono_feature_disable_remoting='yes'
825    mono_feature_disable_reflection_emit_save='yes'
826    mono_feature_disable_reflection_emit='yes'
827    mono_feature_disable_appdomains='yes'
828
829    AOT_BUILD_FLAGS="-O=gsharedvt --aot=full,$INVARIANT_AOT_OPTIONS"
830    AOT_RUN_FLAGS="--full-aot"
831 elif test x$with_runtime_preset = xbitcode_mobile_static; then
832    DISABLE_MCS_DOCS_default=yes
833    with_profile4_x_default=no
834    with_monodroid_default=no
835    with_monotouch_default=no
836    with_monotouch_watch_default=no
837    with_monotouch_tv_default=no
838    with_xammac_default=no
839    with_mobile_static_default=yes
840    with_bitcode_default=yes
841    with_cooperative_gc_default=yes
842    TEST_PROFILE=mobile_static 
843    enable_llvm_default=yes
844
845    mono_feature_disable_com='yes'
846    mono_feature_disable_remoting='yes'
847    mono_feature_disable_reflection_emit_save='yes'
848    mono_feature_disable_reflection_emit='yes'
849    mono_feature_disable_appdomains='yes'
850
851    AOT_BUILD_FLAGS="--aot=llvmonly,$INVARIANT_AOT_OPTIONS"
852    AOT_RUN_FLAGS="--llvmonly"
853 else
854    with_profile4_x_default=yes
855    with_monodroid_default=no
856    with_monotouch_default=no
857    with_monotouch_watch_default=no
858    with_monotouch_tv_default=no
859    with_bitcode_default=no
860    with_xammac_default=no
861    with_mobile_static_default=no
862    with_cooperative_gc_default=no
863 fi
864
865 if test "x$AOT_BUILD_FLAGS" != "x"; then :
866    AC_SUBST(AOT_BUILD_FLAGS)
867    AC_SUBST(AOT_RUN_FLAGS)
868    # For llvmonlycheck + fullaotcheck
869    AC_SUBST(INVARIANT_AOT_OPTIONS)
870 fi
871
872 AC_SUBST(TEST_PROFILE)
873
874 if test "x$with_profile4_x" = "xdefault"; then
875    with_profile4_x=$with_profile4_x_default
876 fi
877 if test "x$with_monodroid" = "xdefault"; then
878    with_monodroid=$with_monodroid_default
879 fi
880 if test "x$with_monotouch" = "xdefault"; then
881    with_monotouch=$with_monotouch_default
882 fi
883 if test "x$with_monotouch_watch" = "xdefault"; then
884    with_monotouch_watch=$with_monotouch_watch_default
885 fi
886 if test "x$with_monotouch_tv" = "xdefault"; then
887    with_monotouch_tv=$with_monotouch_tv_default
888 fi
889 if test "x$with_bitcode" = "xdefault"; then
890    with_bitcode=$with_bitcode_default
891 fi
892 if test "x$with_xammac" = "xdefault"; then
893    with_xammac=$with_xammac_default
894 fi
895 if test "x$with_mobile_static" = "xdefault"; then
896    with_mobile_static=$with_mobile_static_default
897 fi
898
899 AM_CONDITIONAL(INSTALL_4_x, [test "x$with_profile4_x" = "xyes"])
900 AM_CONDITIONAL(INSTALL_MONODROID, [test "x$with_monodroid" != "xno"])
901 AM_CONDITIONAL(INSTALL_MONOTOUCH, [test "x$with_monotouch" != "xno"])
902 AM_CONDITIONAL(INSTALL_MONOTOUCH_WATCH, [test "x$with_monotouch_watch" != "xno"])
903 AM_CONDITIONAL(INSTALL_MONOTOUCH_TV, [test "x$with_monotouch_tv" != "xno"])
904 AM_CONDITIONAL(BITCODE, test "x$with_bitcode" = "xyes")
905 AM_CONDITIONAL(INSTALL_XAMMAC, [test "x$with_xammac" != "xno"])
906 AM_CONDITIONAL(INSTALL_MOBILE_STATIC, [test "x$with_mobile_static" != "xno"])
907
908 AC_SUBST(INSTALL_MOBILE_STATIC)
909
910 default_profile=net_4_x
911 if test -z "$INSTALL_MONODROID_TRUE"; then :
912    default_profile=monodroid
913 fi
914 if test -z "$INSTALL_MONOTOUCH_TRUE"; then :
915    default_profile=monotouch
916 fi
917 if test -z "$INSTALL_XAMMAC_TRUE"; then :
918    default_profile=xammac
919 fi
920 if test -z "$INSTALL_MOBILE_STATIC_TRUE"; then :
921    default_profile=mobile_static
922 fi
923 if test -z "$INSTALL_4_x_TRUE"; then :
924    default_profile=net_4_x
925 fi
926 DEFAULT_PROFILE=$default_profile
927 AC_SUBST(DEFAULT_PROFILE)
928
929 #
930 # End build profile configuration
931 #
932
933 if test x$USE_NLS = xprofile_default; then
934
935 if test x$host_darwin = xyes; then
936 # We make the default value for USE_NLS
937 # "no" on OSX because it isn't available on most
938 # default OSX installs. The most common configurations will
939 # all disable it, so this saves us typing.
940   USE_NLS=no
941   AC_SUBST([USE_NLS])
942   AC_MSG_RESULT([$USE_NLS])
943 else
944   USE_NLS=yes
945   AC_SUBST([USE_NLS])
946   AC_MSG_RESULT([$USE_NLS])
947 fi
948
949 fi
950
951 AC_ARG_ENABLE(minimal, [  --enable-minimal=LIST      drop support for LIST subsystems.
952      LIST is a comma-separated list from: aot, profiler, decimal, pinvoke, debug, appdomains, verifier, 
953      reflection_emit, reflection_emit_save, large_code, logging, com, ssa, generics, attach, jit, simd, soft_debug, perfcounters, normalization, assembly_remapping, shared_perfcounters, remoting,
954          security, sgen_remset, sgen_marksweep_par, sgen_marksweep_fixed, sgen_marksweep_fixed_par, sgen_copying.],
955 [
956         for feature in `echo "$enable_minimal" | sed -e "s/,/ /g"`; do
957                 eval "mono_feature_disable_$feature='yes'"
958         done
959         DISABLED_FEATURES=$enable_minimal
960         disabled="Disabled:      $enable_minimal"
961 ],[])
962
963 AC_DEFINE_UNQUOTED(DISABLED_FEATURES, "$DISABLED_FEATURES", [String of disabled features])
964
965 if test "x$mono_feature_disable_aot" = "xyes"; then
966         AC_DEFINE(DISABLE_AOT, 1, [Disable AOT Compiler])
967         enable_system_aot=no
968         AC_MSG_NOTICE([Disabled AOT compiler])
969 fi
970
971 if test "x$mono_feature_disable_profiler" = "xyes"; then
972         AC_DEFINE(DISABLE_PROFILER, 1, [Disable default profiler support])
973         AC_MSG_NOTICE([Disabled support for the profiler])
974 fi
975 AM_CONDITIONAL(DISABLE_PROFILER, test x$mono_feature_disable_profiler = xyes)
976
977 if test "x$mono_feature_disable_decimal" = "xyes"; then
978         AC_DEFINE(DISABLE_DECIMAL, 1, [Disable System.Decimal support])
979         AC_MSG_NOTICE([Disabled support for decimal])
980 fi
981
982 if test "x$mono_feature_disable_pinvoke" = "xyes"; then
983         AC_DEFINE(DISABLE_PINVOKE, 1, [Disable P/Invoke support])
984         AC_MSG_NOTICE([Disabled support for P/Invoke])
985 fi
986
987 if test "x$mono_feature_disable_debug" = "xyes"; then
988         AC_DEFINE(DISABLE_DEBUG, 1, [Disable runtime debugging support])
989         AC_MSG_NOTICE([Disabled support for runtime debugging])
990 fi
991
992 if test "x$mono_feature_disable_reflection_emit" = "xyes"; then
993         AC_DEFINE(DISABLE_REFLECTION_EMIT, 1, [Disable reflection emit support])
994         mono_feature_disable_reflection_emit_save=yes
995         AC_MSG_NOTICE([Disabled support for Reflection.Emit])
996 fi
997
998 if test "x$mono_feature_disable_reflection_emit_save" = "xyes"; then
999         AC_DEFINE(DISABLE_REFLECTION_EMIT_SAVE, 1, [Disable assembly saving support in reflection emit])
1000         AC_MSG_NOTICE([Disabled support for Reflection.Emit.Save])
1001 fi
1002
1003 if test "x$mono_feature_disable_large_code" = "xyes"; then
1004         AC_DEFINE(DISABLE_LARGE_CODE, 1, [Disable support for huge assemblies])
1005         AC_MSG_NOTICE([Disabled support for large assemblies])
1006 fi
1007
1008 if test "x$mono_feature_disable_logging" = "xyes"; then
1009         AC_DEFINE(DISABLE_LOGGING, 1, [Disable support debug logging])
1010         AC_MSG_NOTICE([Disabled support for logging])
1011 fi
1012
1013 if test "x$mono_feature_disable_com" = "xyes"; then
1014         AC_DEFINE(DISABLE_COM, 1, [Disable COM support])
1015         AC_MSG_NOTICE([Disabled COM support])
1016 fi
1017
1018 if test "x$mono_feature_disable_ssa" = "xyes"; then
1019         AC_DEFINE(DISABLE_SSA, 1, [Disable advanced SSA JIT optimizations])
1020         AC_MSG_NOTICE([Disabled SSA JIT optimizations])
1021 fi
1022
1023 if test "x$mono_feature_disable_generics" = "xyes"; then
1024         AC_DEFINE(DISABLE_GENERICS, 1, [Disable generics support])
1025         AC_MSG_NOTICE([Disabled Generics Support])
1026 fi
1027
1028 if test "x$mono_feature_disable_shadowcopy" = "xyes"; then
1029         AC_DEFINE(DISABLE_SHADOW_COPY, 1, [Disable Shadow Copy for AppDomains])
1030         AC_MSG_NOTICE([Disabled Shadow copy for AppDomains])
1031 fi
1032
1033 if test "x$mono_feature_disable_portability" = "xyes"; then
1034         AC_DEFINE(DISABLE_PORTABILITY, 1, [Disables the IO portability layer])
1035         AC_MSG_NOTICE([Disabled IO Portability layer])
1036 fi
1037
1038 if test "x$mono_feature_disable_attach" = "xyes"; then
1039         AC_DEFINE(DISABLE_ATTACH, 1, [Disable agent attach support])
1040         AC_MSG_NOTICE([Disabled agent attach])
1041 fi
1042
1043 if test "x$mono_feature_disable_full_messages" = "xyes"; then
1044         AC_DEFINE(DISABLE_FULL_MESSAGES, 1, [Disables building in the full table of WAPI messages])
1045         AC_MSG_NOTICE([Disabled full messages for Win32 errors, only core message strings shipped])
1046 fi
1047
1048 if test "x$mono_feature_disable_verifier" = "xyes"; then
1049         AC_DEFINE(DISABLE_VERIFIER, 1, [Disables the verifier])
1050         AC_MSG_NOTICE([Disabled the metadata and IL verifiers])
1051 fi
1052
1053 if test "x$mono_feature_disable_jit" = "xyes"; then
1054         AC_DEFINE(DISABLE_JIT, 1, [Disable the JIT, only full-aot mode will be supported by the runtime.])
1055         AC_MSG_NOTICE([Disabled the JIT engine, only full AOT will be supported])
1056 fi
1057
1058 AM_CONDITIONAL(DISABLE_JIT, test x$mono_feature_disable_jit = xyes)
1059
1060 if test "x$mono_feature_disable_simd" = "xyes"; then
1061         AC_DEFINE(DISABLE_SIMD, 1, [Disable SIMD intrinsics related optimizations.])
1062         AC_MSG_NOTICE([Disabled SIMD support])
1063 fi
1064
1065 if test "x$mono_feature_disable_soft_debug" = "xyes"; then
1066         AC_DEFINE(DISABLE_SOFT_DEBUG, 1, [Disable Soft Debugger Agent.])
1067         AC_MSG_NOTICE([Disabled Soft Debugger.])
1068 fi
1069
1070 if test "x$mono_feature_disable_perfcounters" = "xyes"; then
1071         AC_DEFINE(DISABLE_PERFCOUNTERS, 1, [Disable Performance Counters.])
1072         AC_MSG_NOTICE([Disabled Performance Counters.])
1073 fi
1074 if test "x$mono_feature_disable_normalization" = "xyes"; then
1075         AC_DEFINE(DISABLE_NORMALIZATION, 1, [Disable String normalization support.])
1076         AC_MSG_NOTICE([Disabled String normalization support.])
1077 fi
1078
1079 if test "x$mono_feature_disable_assembly_remapping" = "xyes"; then
1080         AC_DEFINE(DISABLE_ASSEMBLY_REMAPPING, 1, [Disable assembly remapping.])
1081         AC_MSG_NOTICE([Disabled Assembly remapping.])
1082 fi
1083
1084 if test "x$mono_feature_disable_shared_perfcounters" = "xyes"; then
1085         AC_DEFINE(DISABLE_SHARED_PERFCOUNTERS, 1, [Disable shared perfcounters.])
1086         AC_MSG_NOTICE([Disabled Shared perfcounters.])
1087 fi
1088
1089 if test "x$mono_feature_disable_appdomains" = "xyes"; then
1090         AC_DEFINE(DISABLE_APPDOMAINS, 1, [Disable support for multiple appdomains.])
1091         AC_MSG_NOTICE([Disabled support for multiple appdomains.])
1092 fi
1093
1094 if test "x$mono_feature_disable_remoting" = "xyes"; then
1095         AC_DEFINE(DISABLE_REMOTING, 1, [Disable remoting support (This disables type proxies and make com non-functional)])
1096         AC_MSG_NOTICE([Disabled remoting])
1097 fi
1098
1099 if test "x$mono_feature_disable_security" = "xyes"; then
1100         AC_DEFINE(DISABLE_SECURITY, 1, [Disable CAS/CoreCLR security])
1101         AC_MSG_NOTICE([Disabled CAS/CoreCLR security manager (used e.g. for Moonlight)])
1102 fi
1103
1104 if test "x$mono_feature_disable_sgen_remset" = "xyes"; then
1105         AC_DEFINE(DISABLE_SGEN_REMSET, 1, [Disable wbarrier=remset support in SGEN.])
1106         AC_MSG_NOTICE([Disabled wbarrier=remset support in SGEN.])
1107 fi
1108
1109 if test "x$mono_feature_disable_sgen_marksweep_par" = "xyes"; then
1110         AC_DEFINE(DISABLE_SGEN_MAJOR_MARKSWEEP_PAR, 1, [Disable major=marksweep-par support in SGEN.])
1111         AC_MSG_NOTICE([Disabled major=marksweep-par support in SGEN.])
1112 fi
1113
1114 if test "x$mono_feature_disable_sgen_marksweep_fixed" = "xyes"; then
1115         AC_DEFINE(DISABLE_SGEN_MAJOR_MARKSWEEP_FIXED, 1, [Disable major=marksweep-fixed support in SGEN.])
1116         AC_MSG_NOTICE([Disabled major=marksweep-fixed support in SGEN.])
1117 fi
1118
1119 if test "x$mono_feature_disable_sgen_marksweep_fixed_par" = "xyes"; then
1120         AC_DEFINE(DISABLE_SGEN_MAJOR_MARKSWEEP_FIXED_PAR, 1, [Disable major=marksweep-fixed-par support in SGEN.])
1121         AC_MSG_NOTICE([Disabled major=marksweep-fixed-par support in SGEN.])
1122 fi
1123
1124 if test "x$mono_feature_disable_sgen_copying" = "xyes"; then
1125         AC_DEFINE(DISABLE_SGEN_MAJOR_COPYING, 1, [Disable major=copying support in SGEN.])
1126         AC_MSG_NOTICE([Disabled major=copying support in SGEN.])
1127 fi
1128
1129 AC_ARG_ENABLE(executables, [  --disable-executables disable the build of the runtime executables], enable_executables=$enableval, enable_executables=yes)
1130 AM_CONDITIONAL(DISABLE_EXECUTABLES, test x$enable_executables = xno)
1131
1132 has_extension_module=no
1133 AC_ARG_ENABLE(extension-module, [  --enable-extension-module=LIST enable the core-extensions from LIST],
1134 [
1135         for extension in `echo "$enable_extension_module" | sed -e "s/,/ /g"`; do
1136                 if test x$extension = xdefault ; then
1137                         has_extension_module=yes;
1138                 fi
1139         done
1140         if test x$enable_extension_module = xyes; then
1141                 has_extension_module=yes;
1142         fi
1143 ], [])
1144
1145 AM_CONDITIONAL([HAS_EXTENSION_MODULE], [test x$has_extension_module != xno])
1146
1147 if test x$has_extension_module != xno ; then
1148         AC_DEFINE([ENABLE_EXTENSION_MODULE], 1, [Extension module enabled])
1149         AC_MSG_NOTICE([Enabling mono extension module.])
1150 fi
1151
1152 # Deprecated
1153 AC_ARG_ENABLE(gsharedvt, [  --enable-gsharedvt Enable generic valuetype sharing (Deprecated)], enable_gsharedvt=$enableval, enable_gsharedvt=no)
1154
1155 AC_MSG_CHECKING(for visibility __attribute__)
1156 AC_COMPILE_IFELSE([
1157         AC_LANG_SOURCE([[
1158                 void __attribute__ ((visibility ("hidden"))) doit (void) {}
1159                 int main () { doit (); return 0; }
1160         ]])
1161 ], [
1162    have_visibility_hidden=yes
1163    AC_MSG_RESULT(yes)
1164 ], [
1165    have_visibility_hidden=no
1166    AC_MSG_RESULT(no)
1167 ])
1168
1169 dnl
1170 dnl Boehm GC configuration
1171 dnl
1172
1173 AC_ARG_WITH(libgc,   [  --with-gc=included,none  Controls the Boehm GC config, default=included],[libgc=$with_gc],[libgc=included])
1174
1175 AC_ARG_ENABLE(boehm, [  --disable-boehm            Disable the Boehm GC.], support_boehm=$enableval,support_boehm=${support_boehm:-yes})
1176 AM_CONDITIONAL(SUPPORT_BOEHM, test x$support_boehm = xyes)
1177
1178 if test "x$support_boehm" = "xyes"; then
1179
1180         AC_ARG_ENABLE(parallel-mark, [  --enable-parallel-mark     Enables Boehm GC Parallel Marking], enable_parallel_mark=$enableval, enable_parallel_mark=$parallel_mark)
1181         if test x$enable_parallel_mark = xyes; then
1182                 libgc_configure_args="$libgc_configure_args --enable-parallel-mark"
1183         fi
1184
1185         gc_msg=""
1186         LIBGC_CPPFLAGS=
1187         LIBGC_LIBS=
1188         LIBGC_STATIC_LIBS=
1189         libgc_dir=
1190         case "x$libgc" in
1191                 xincluded)
1192                         if test "x$support_boehm" = "xyes"; then
1193                                 libgc_dir=libgc
1194                         fi
1195
1196                         LIBGC_CPPFLAGS='-I$(top_srcdir)/libgc/include'
1197                         LIBGC_LIBS='$(top_builddir)/libgc/libmonogc.la'
1198                         LIBGC_STATIC_LIBS='$(top_builddir)/libgc/libmonogc-static.la'
1199
1200                         BOEHM_DEFINES="-DHAVE_BOEHM_GC"
1201
1202                         if test x$target_win32 = xyes; then
1203                                 BOEHM_DEFINES="$BOEHM_DEFINES -DGC_NOT_DLL"
1204                                 CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC -DGC_BUILD -DGC_NOT_DLL"
1205                         fi
1206
1207                         gc_msg="Included Boehm GC with typed GC"
1208                         if test x$enable_parallel_mark = xyes; then
1209                                 AC_DEFINE_UNQUOTED(DEFAULT_GC_NAME, "Included Boehm (with typed GC and Parallel Mark)", [GC description])
1210                                 gc_msg="$gc_msg and parallel mark"
1211                         else
1212                                 AC_DEFINE_UNQUOTED(DEFAULT_GC_NAME, "Included Boehm (with typed GC)", [GC description])
1213                         fi
1214                         ;;
1215
1216                 xboehm|xbohem|xyes)
1217                         AC_MSG_WARN("External Boehm is no longer supported")
1218                         ;;
1219
1220                 xsgen)
1221                         AC_MSG_WARN("Use --with-sgen instead, --with-gc= controls Boehm configuration")
1222                         ;;
1223
1224                 xnone)
1225                         AC_MSG_WARN("Compiling mono without GC.")
1226                         AC_DEFINE_UNQUOTED(DEFAULT_GC_NAME, "none", [GC description])
1227                         AC_DEFINE(HAVE_NULL_GC,1,[No GC support.])
1228                         gc_msg="none"
1229                         ;;
1230                 *)
1231                         AC_MSG_ERROR([Invalid argument to --with-gc.])
1232                         ;;
1233         esac
1234
1235         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])
1236         if test "x$large_heap" = "xyes"; then
1237            CPPFLAGS="$CPPFLAGS -DLARGE_CONFIG"
1238         fi
1239
1240         AC_SUBST(LIBGC_CPPFLAGS)
1241         AC_SUBST(LIBGC_LIBS)
1242         AC_SUBST(LIBGC_STATIC_LIBS)
1243         AC_SUBST(libgc_dir)
1244         AC_SUBST(BOEHM_DEFINES)
1245
1246 fi
1247
1248 dnl
1249 dnl End of Boehm GC Configuration
1250 dnl
1251
1252 dnl *************************************
1253 dnl *** Checks for zero length arrays ***
1254 dnl *************************************
1255 AC_MSG_CHECKING(whether $CC supports zero length arrays)
1256 AC_TRY_COMPILE([
1257         struct s {
1258                 int  length;
1259                 char data [0];
1260         };
1261 ], [], [
1262         AC_MSG_RESULT(yes)
1263         AC_DEFINE_UNQUOTED(MONO_ZERO_LEN_ARRAY, 0, [Length of zero length arrays])
1264 ], [
1265         AC_MSG_RESULT(no)
1266         AC_DEFINE_UNQUOTED(MONO_ZERO_LEN_ARRAY, 1, [Length of zero length arrays])
1267 ])
1268
1269 AC_CHECK_HEADERS(nacl/nacl_dyncode.h)
1270
1271 dnl ***********************************
1272 dnl *** Checks for signals
1273 dnl ***********************************
1274 AC_CHECK_HEADERS(signal.h)
1275 AC_CHECK_FUNCS(sigaction)
1276 AC_CHECK_FUNCS(kill)
1277 AC_CHECK_FUNCS(signal)
1278
1279 # signal() is declared inline in Android headers
1280 # so we need to workaround it by overriding the check.
1281 if test x$platform_android = xyes; then
1282         AC_DEFINE(HAVE_SIGNAL,1)
1283 fi
1284
1285 if test x$host_win32 = xno; then
1286
1287         dnl hires monotonic clock support
1288         AC_SEARCH_LIBS(clock_gettime, rt)
1289         AC_CHECK_FUNCS(clock_nanosleep)
1290
1291         dnl dynamic loader support
1292         AC_CHECK_FUNC(dlopen, DL_LIB="",
1293                 AC_CHECK_LIB(dl, dlopen, DL_LIB="-ldl", dl_support=no)
1294         )
1295         if test x$dl_support = xno; then
1296                 AC_MSG_WARN([No dynamic loading support available])
1297         else
1298                 LIBS="$LIBS $DL_LIB"
1299                 AC_DEFINE(HAVE_DL_LOADER,1,[dlopen-based dynamic loader available])
1300                 dnl from glib's configure.ac
1301                 AC_CACHE_CHECK([for preceeding underscore in symbols],
1302                         mono_cv_uscore,[
1303                         AC_TRY_RUN([#include <dlfcn.h>
1304                         int mono_underscore_test (void) { return 42; }
1305                         int main() {
1306                           void *f1 = (void*)0, *f2 = (void*)0, *handle;
1307                           handle = dlopen ((void*)0, 0);
1308                           if (handle) {
1309                             f1 = dlsym (handle, "mono_underscore_test");
1310                             f2 = dlsym (handle, "_mono_underscore_test");
1311                           } return (!f2 || f1);
1312                         }],
1313                                 [mono_cv_uscore=yes],
1314                                 [mono_cv_uscore=no],
1315                         [])
1316                 ])
1317                 if test "x$mono_cv_uscore" = "xyes"; then
1318                         MONO_DL_NEED_USCORE=1
1319                 else
1320                         MONO_DL_NEED_USCORE=0
1321                 fi
1322                 AC_SUBST(MONO_DL_NEED_USCORE)
1323                 AC_CHECK_FUNC(dlerror)
1324         fi
1325
1326         dnl ******************************************************************
1327         dnl *** Checks for the IKVM JNI interface library                  ***
1328         dnl ******************************************************************
1329         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])
1330
1331         ikvm_native_dir=
1332         if test x$with_ikvm_native = xyes; then
1333                 ikvm_native_dir=ikvm-native
1334                 jdk_headers_found="IKVM Native"
1335         fi
1336
1337         AC_SUBST(ikvm_native_dir)
1338
1339         AC_CHECK_HEADERS(execinfo.h)
1340
1341         AC_CHECK_HEADERS(sys/auxv.h sys/resource.h)
1342
1343         AC_CHECK_FUNCS(getgrgid_r)
1344         AC_CHECK_FUNCS(getgrnam_r)
1345         AC_CHECK_FUNCS(getpwnam_r)
1346         AC_CHECK_FUNCS(getpwuid_r)
1347         AC_CHECK_FUNCS(getresuid)
1348         AC_CHECK_FUNCS(setresuid)
1349         AC_CHECK_FUNCS(kqueue)
1350         AC_CHECK_FUNCS(backtrace_symbols)
1351         AC_CHECK_FUNCS(mkstemp)
1352         AC_CHECK_FUNCS(mmap)
1353         AC_CHECK_FUNCS(madvise)
1354         AC_CHECK_FUNCS(getrusage)
1355         AC_CHECK_FUNCS(getpriority)
1356         AC_CHECK_FUNCS(setpriority)
1357         AC_CHECK_FUNCS(dl_iterate_phdr)
1358         AC_CHECK_FUNCS(dladdr)
1359         AC_CHECK_FUNCS(sysconf)
1360         AC_CHECK_FUNCS(getrlimit)
1361         AC_CHECK_FUNCS(prctl)
1362
1363         AC_CHECK_FUNCS(sched_getaffinity)
1364         AC_CHECK_FUNCS(sched_setaffinity)
1365         AC_CHECK_FUNCS(sched_getcpu)
1366
1367         dnl ****************************************************************
1368         dnl *** Check for sched_setaffinity from glibc versions before   ***
1369         dnl *** 2.3.4. The older versions of the function only take 2    ***
1370         dnl *** parameters, not 3.                                       ***
1371         dnl ***                                                          ***
1372         dnl *** Because the interface change was not made in a minor     ***
1373         dnl *** version rev, the __GLIBC__ and __GLIBC_MINOR__ macros    ***
1374         dnl *** won't always indicate the interface sched_affinity has.  ***
1375         dnl ****************************************************************
1376         AC_MSG_CHECKING(for sched_setaffinity from glibc < 2.3.4)
1377         AC_TRY_COMPILE([#include <sched.h>], [
1378             int mask = 1; 
1379             sched_setaffinity(0, &mask);
1380                         return 0;
1381         ], [
1382                 # Yes, we have it...
1383                 AC_MSG_RESULT(yes)
1384                 AC_DEFINE(GLIBC_BEFORE_2_3_4_SCHED_SETAFFINITY, 1, [Have GLIBC_BEFORE_2_3_4_SCHED_SETAFFINITY])
1385         ], [
1386                 # We have the new, three-parameter version
1387                 AC_MSG_RESULT(no)
1388         ])
1389
1390
1391         dnl ******************************************************************
1392         dnl *** Check for large file support                               ***
1393         dnl *** (If we were using autoconf 2.50 we'd use AC_SYS_LARGEFILE) ***
1394         dnl ******************************************************************
1395         
1396         # Check that off_t can represent 2**63 - 1 correctly, working around
1397         # potential compiler bugs.  Defines LARGE_FILE_SUPPORT, adds $1 to
1398         # CPPFLAGS and sets $large_offt to yes if the test succeeds
1399         large_offt=no
1400         AC_DEFUN([LARGE_FILES], [
1401                 large_CPPFLAGS=$CPPFLAGS
1402                 CPPFLAGS="$CPPFLAGS $1"
1403                 AC_TRY_COMPILE([
1404                         #include <sys/types.h>
1405                         #include <limits.h>
1406                 ], [
1407                         /* Lifted this compile time assert method from: http://www.jaggersoft.com/pubs/CVu11_3.html */
1408                         #define COMPILE_TIME_ASSERT(pred) \
1409                                 switch(0){case 0:case pred:;}
1410                         COMPILE_TIME_ASSERT(sizeof(off_t) * CHAR_BIT == 64);
1411                 ], [
1412                         AC_MSG_RESULT(ok)
1413                         AC_DEFINE(HAVE_LARGE_FILE_SUPPORT, 1, [Have large file support])
1414                         large_CPPFLAGS="$large_CPPFLAGS $1"
1415                         large_offt=yes
1416                 ], [
1417                         AC_MSG_RESULT(no)
1418                 ])
1419                 CPPFLAGS=$large_CPPFLAGS
1420         ])
1421
1422         AC_MSG_CHECKING(if off_t is 64 bits wide)
1423         LARGE_FILES("")
1424         if test $large_offt = no; then
1425                 AC_MSG_CHECKING(if _FILE_OFFSET_BITS=64 gives 64 bit off_t)
1426                 LARGE_FILES("-D_FILE_OFFSET_BITS=64")
1427         fi
1428         if test $large_offt = no; then
1429                 AC_MSG_WARN([No 64 bit file size support available])
1430         fi
1431         
1432         dnl *****************************
1433         dnl *** Checks for libsocket  ***
1434         dnl *****************************
1435         AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
1436
1437         case "$host" in
1438                 *-*-*freebsd*)
1439                         dnl *****************************
1440                         dnl *** Checks for libinotify ***
1441                         dnl *****************************
1442                         AC_CHECK_LIB(inotify, inotify_init, LIBS="$LIBS -linotify")
1443         esac
1444
1445         dnl *******************************
1446         dnl *** Checks for MSG_NOSIGNAL ***
1447         dnl *******************************
1448         AC_MSG_CHECKING(for MSG_NOSIGNAL)
1449         AC_TRY_COMPILE([#include <sys/socket.h>], [
1450                 int f = MSG_NOSIGNAL;
1451         ], [
1452                 # Yes, we have it...
1453                 AC_MSG_RESULT(yes)
1454                 AC_DEFINE(HAVE_MSG_NOSIGNAL, 1, [Have MSG_NOSIGNAL])
1455         ], [
1456                 # We'll have to use signals
1457                 AC_MSG_RESULT(no)
1458         ])
1459
1460         dnl *****************************
1461         dnl *** Checks for IPPROTO_IP ***
1462         dnl *****************************
1463         AC_MSG_CHECKING(for IPPROTO_IP)
1464         AC_TRY_COMPILE([#include <netinet/in.h>], [
1465                 int level = IPPROTO_IP;
1466         ], [
1467                 # Yes, we have it...
1468                 AC_MSG_RESULT(yes)
1469                 AC_DEFINE(HAVE_IPPROTO_IP, 1, [Have IPPROTO_IP])
1470         ], [
1471                 # We'll have to use getprotobyname
1472                 AC_MSG_RESULT(no)
1473         ])
1474
1475         dnl *******************************
1476         dnl *** Checks for IPPROTO_IPV6 ***
1477         dnl *******************************
1478         AC_MSG_CHECKING(for IPPROTO_IPV6)
1479         AC_TRY_COMPILE([#include <netinet/in.h>], [
1480                 int level = IPPROTO_IPV6;
1481         ], [
1482                 # Yes, we have it...
1483                 AC_MSG_RESULT(yes)
1484                 AC_DEFINE(HAVE_IPPROTO_IPV6, 1, [Have IPPROTO_IPV6])
1485         ], [
1486                 # We'll have to use getprotobyname
1487                 AC_MSG_RESULT(no)
1488         ])
1489
1490         dnl ******************************
1491         dnl *** Checks for IPPROTO_TCP ***
1492         dnl ******************************
1493         AC_MSG_CHECKING(for IPPROTO_TCP)
1494         AC_TRY_COMPILE([#include <netinet/in.h>], [
1495                 int level = IPPROTO_TCP;
1496         ], [
1497                 # Yes, we have it...
1498                 AC_MSG_RESULT(yes)
1499                 AC_DEFINE(HAVE_IPPROTO_TCP, 1, [Have IPPROTO_TCP])
1500         ], [
1501                 # We'll have to use getprotobyname
1502                 AC_MSG_RESULT(no)
1503         ])
1504
1505         dnl *****************************
1506         dnl *** Checks for SOL_IP     ***
1507         dnl *****************************
1508         AC_MSG_CHECKING(for SOL_IP)
1509         AC_TRY_COMPILE([#include <netdb.h>], [
1510                 int level = SOL_IP;
1511         ], [
1512                 # Yes, we have it...
1513                 AC_MSG_RESULT(yes)
1514                 AC_DEFINE(HAVE_SOL_IP, 1, [Have SOL_IP])
1515         ], [
1516                 # We'll have to use getprotobyname
1517                 AC_MSG_RESULT(no)
1518         ])
1519
1520         dnl *****************************
1521         dnl *** Checks for SOL_IPV6     ***
1522         dnl *****************************
1523         AC_MSG_CHECKING(for SOL_IPV6)
1524         AC_TRY_COMPILE([#include <netdb.h>], [
1525                 int level = SOL_IPV6;
1526         ], [
1527                 # Yes, we have it...
1528                 AC_MSG_RESULT(yes)
1529                 AC_DEFINE(HAVE_SOL_IPV6, 1, [Have SOL_IPV6])
1530         ], [
1531                 # We'll have to use getprotobyname
1532                 AC_MSG_RESULT(no)
1533         ])
1534
1535         dnl *****************************
1536         dnl *** Checks for SOL_TCP    ***
1537         dnl *****************************
1538         AC_MSG_CHECKING(for SOL_TCP)
1539         AC_TRY_COMPILE([#include <netdb.h>], [
1540                 int level = SOL_TCP;
1541         ], [
1542                 # Yes, we have it...
1543                 AC_MSG_RESULT(yes)
1544                 AC_DEFINE(HAVE_SOL_TCP, 1, [Have SOL_TCP])
1545         ], [
1546                 # We'll have to use getprotobyname
1547                 AC_MSG_RESULT(no)
1548         ])
1549
1550         dnl *****************************
1551         dnl *** Checks for IP_PKTINFO ***
1552         dnl *****************************
1553         AC_MSG_CHECKING(for IP_PKTINFO)
1554         AC_TRY_COMPILE([#include <linux/in.h>], [
1555                 int level = IP_PKTINFO;
1556         ], [
1557                 # Yes, we have it...
1558                 AC_MSG_RESULT(yes)
1559                 AC_DEFINE(HAVE_IP_PKTINFO, 1, [Have IP_PKTINFO])
1560         ], [
1561                 AC_MSG_RESULT(no)
1562         ])
1563
1564         dnl *****************************
1565         dnl *** Checks for IPV6_PKTINFO ***
1566         dnl *****************************
1567         AC_MSG_CHECKING(for IPV6_PKTINFO)
1568         AC_TRY_COMPILE([#include <netdb.h>], [
1569                 int level = IPV6_PKTINFO;
1570         ], [
1571                 # Yes, we have it...
1572                 AC_MSG_RESULT(yes)
1573                 AC_DEFINE(HAVE_IPV6_PKTINFO, 1, [Have IPV6_PKTINFO])
1574         ], [
1575                 AC_MSG_RESULT(no)
1576         ])
1577
1578         dnl **********************************
1579         dnl *** Checks for IP_DONTFRAG     ***
1580         dnl **********************************
1581         AC_MSG_CHECKING(for IP_DONTFRAG)
1582         AC_TRY_COMPILE([#include <netinet/in.h>], [
1583                 int level = IP_DONTFRAG;
1584         ], [
1585                 # Yes, we have it...
1586                 AC_MSG_RESULT(yes)
1587                 AC_DEFINE(HAVE_IP_DONTFRAG, 1, [Have IP_DONTFRAG])
1588         ], [
1589                 AC_MSG_RESULT(no)
1590         ])
1591
1592         dnl **********************************
1593         dnl *** Checks for IP_DONTFRAGMENT ***
1594         dnl **********************************
1595         AC_MSG_CHECKING(for IP_DONTFRAGMENT)
1596         AC_TRY_COMPILE([#include <Ws2ipdef.h>], [
1597                 int level = IP_DONTFRAGMENT;
1598         ], [
1599                 # Yes, we have it...
1600                 AC_MSG_RESULT(yes)
1601                 AC_DEFINE(HAVE_IP_DONTFRAGMENT, 1, [Have IP_DONTFRAGMENT])
1602         ], [
1603                 AC_MSG_RESULT(no)
1604         ])
1605
1606         dnl **********************************
1607         dnl *** Checks for IP_MTU_DISCOVER ***
1608         dnl **********************************
1609         AC_MSG_CHECKING(for IP_MTU_DISCOVER)
1610         AC_TRY_COMPILE([#include <linux/in.h>], [
1611                 int level = IP_MTU_DISCOVER;
1612         ], [
1613                 # Yes, we have it...
1614                 AC_MSG_RESULT(yes)
1615                 AC_DEFINE(HAVE_IP_MTU_DISCOVER, 1, [Have IP_MTU_DISCOVER])
1616         ], [
1617                 AC_MSG_RESULT(no)
1618         ])
1619
1620         dnl **********************************
1621         dnl *** Checks for  IP_PMTUDISC_DO ***
1622         dnl **********************************
1623         AC_MSG_CHECKING(for IP_PMTUDISC_DO)
1624         AC_TRY_COMPILE([#include <linux/in.h>], [
1625                 int level = IP_PMTUDISC_DO;
1626         ], [
1627                 # Yes, we have it...
1628                 AC_MSG_RESULT(yes)
1629                 AC_DEFINE(HAVE_IP_PMTUDISC_DO, 1, [Have IP_PMTUDISC_DO])
1630         ], [
1631                 AC_MSG_RESULT(no)
1632         ])
1633
1634         dnl *********************************
1635         dnl *** Check for struct ip_mreqn ***
1636         dnl *********************************
1637         AC_MSG_CHECKING(for struct ip_mreqn)
1638         AC_TRY_COMPILE([#include <netinet/in.h>], [
1639                 struct ip_mreqn mreq;
1640                 mreq.imr_address.s_addr = 0;
1641         ], [
1642                 # Yes, we have it...
1643                 AC_MSG_RESULT(yes)
1644                 AC_DEFINE(HAVE_STRUCT_IP_MREQN, 1, [Have struct ip_mreqn])
1645         ], [
1646                 # We'll just have to try and use struct ip_mreq
1647                 AC_MSG_RESULT(no)
1648                 AC_MSG_CHECKING(for struct ip_mreq)
1649                 AC_TRY_COMPILE([#include <netinet/in.h>], [
1650                         struct ip_mreq mreq;
1651                         mreq.imr_interface.s_addr = 0;
1652                 ], [
1653                         # Yes, we have it...
1654                         AC_MSG_RESULT(yes)
1655                         AC_DEFINE(HAVE_STRUCT_IP_MREQ, 1, [Have struct ip_mreq])
1656                 ], [
1657                         # No multicast support
1658                         AC_MSG_RESULT(no)
1659                 ])
1660         ])
1661         
1662         dnl **********************************
1663         dnl *** Check for getaddrinfo ***
1664         dnl **********************************
1665         AC_MSG_CHECKING(for getaddrinfo)
1666                 AC_TRY_LINK([
1667                 #include <stdio.h>
1668                 #include <netdb.h>
1669         ], [
1670                 getaddrinfo(NULL,NULL,NULL,NULL);
1671         ], [
1672                 # Yes, we have it...
1673                 AC_MSG_RESULT(yes)
1674                 AC_DEFINE(HAVE_GETADDRINFO, 1, [Have getaddrinfo])
1675         ], [
1676                 AC_MSG_RESULT(no)
1677         ])
1678
1679         dnl **********************************
1680         dnl *** Check for gethostbyname2_r ***
1681         dnl **********************************
1682         AC_MSG_CHECKING(for gethostbyname2_r)
1683                 AC_TRY_LINK([
1684                 #include <stdio.h>
1685                 #include <netdb.h>
1686         ], [
1687
1688                 gethostbyname2_r(NULL,0,NULL,NULL,0,NULL,NULL);
1689         ], [
1690                 # Yes, we have it...
1691                 AC_MSG_RESULT(yes)
1692                 AC_DEFINE(HAVE_GETHOSTBYNAME2_R, 1, [Have gethostbyname2_r])
1693         ], [
1694                 AC_MSG_RESULT(no)
1695         ])
1696
1697         dnl **********************************
1698         dnl *** Check for gethostbyname2 ***
1699         dnl **********************************
1700         AC_MSG_CHECKING(for gethostbyname2)
1701                 AC_TRY_LINK([
1702                 #include <stdio.h>
1703                 #include <netdb.h>
1704         ], [
1705                 gethostbyname2(NULL,0);
1706         ], [
1707                 # Yes, we have it...
1708                 AC_MSG_RESULT(yes)
1709                 AC_DEFINE(HAVE_GETHOSTBYNAME2, 1, [Have gethostbyname2])
1710         ], [
1711                 AC_MSG_RESULT(no)
1712         ])
1713
1714         dnl **********************************
1715         dnl *** Check for gethostbyname ***
1716         dnl **********************************
1717         AC_MSG_CHECKING(for gethostbyname)
1718                 AC_TRY_LINK([
1719                 #include <stdio.h>
1720                 #include <netdb.h>
1721         ], [
1722                 gethostbyname(NULL);
1723         ], [
1724                 # Yes, we have it...
1725                 AC_MSG_RESULT(yes)
1726                 AC_DEFINE(HAVE_GETHOSTBYNAME, 1, [Have gethostbyname])
1727         ], [
1728                 AC_MSG_RESULT(no)
1729         ])
1730
1731         dnl **********************************
1732         dnl *** Check for getprotobyname ***
1733         dnl **********************************
1734         AC_MSG_CHECKING(for getprotobyname)
1735                 AC_TRY_LINK([
1736                 #include <stdio.h>
1737                 #include <netdb.h>
1738         ], [
1739                 getprotobyname(NULL);
1740         ], [
1741                 # Yes, we have it...
1742                 AC_MSG_RESULT(yes)
1743                 AC_DEFINE(HAVE_GETPROTOBYNAME, 1, [Have getprotobyname])
1744         ], [
1745                 AC_MSG_RESULT(no)
1746         ])
1747
1748         dnl **********************************
1749         dnl *** Check for getnameinfo ***
1750         dnl **********************************
1751         AC_MSG_CHECKING(for getnameinfo)
1752                 AC_TRY_LINK([
1753                 #include <stdio.h>
1754                 #include <netdb.h>
1755         ], [
1756                 getnameinfo (NULL, 0, NULL, 0, NULL, 0, 0);
1757         ], [
1758                 # Yes, we have it...
1759                 AC_MSG_RESULT(yes)
1760                 AC_DEFINE(HAVE_GETNAMEINFO, 1, [Have getnameinfo])
1761         ], [
1762                 AC_MSG_RESULT(no)
1763         ])
1764
1765
1766         dnl **********************************
1767         dnl *** Check for inet_ntop ***
1768         dnl **********************************
1769         AC_MSG_CHECKING(for inet_ntop)
1770                 AC_TRY_LINK([
1771                 #include <stdio.h>
1772                 #include <arpa/inet.h>
1773         ], [
1774                 inet_ntop (0, NULL, NULL, 0);
1775         ], [
1776                 # Yes, we have it...
1777                 AC_MSG_RESULT(yes)
1778                 AC_DEFINE(HAVE_INET_NTOP, 1, [Have inet_ntop])
1779         ], [
1780                 AC_MSG_RESULT(no)
1781         ])
1782
1783         dnl *****************************
1784         dnl *** Checks for libnsl     ***
1785         dnl *****************************
1786         AC_CHECK_FUNC(gethostbyaddr, , AC_CHECK_LIB(nsl, gethostbyaddr, LIBS="$LIBS -lnsl"))
1787
1788         AC_CHECK_FUNCS(inet_pton inet_aton)
1789
1790         dnl *****************************
1791         dnl *** Checks for libxnet    ***
1792         dnl *****************************
1793         case "${host}" in
1794                 *solaris* )
1795                         AC_MSG_CHECKING(for Solaris XPG4 support)
1796                         if test -f /usr/lib/libxnet.so; then
1797                                 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=500"
1798                                 CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__"
1799                                 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE_EXTENDED=1"
1800                                 LIBS="$LIBS -lxnet"
1801                                 AC_MSG_RESULT(yes)
1802                         else
1803                                 AC_MSG_RESULT(no)
1804                         fi
1805
1806                         if test "$GCC" = "yes"; then
1807                                 CFLAGS="$CFLAGS -Wno-char-subscripts"
1808                         fi
1809                 ;;
1810         esac
1811
1812         dnl *****************************
1813         dnl *** Checks for libpthread ***
1814         dnl *****************************
1815 # on FreeBSD -STABLE, the pthreads functions all reside in libc_r
1816 # and libpthread does not exist
1817 #
1818         case "${host}" in
1819                 *-*-*freebsd*)
1820                         AC_CHECK_LIB(pthread, main, LIBS="$LIBS -pthread")
1821                 ;;
1822                 *-*-*openbsd*)
1823                         AC_CHECK_LIB(pthread, main, LIBS="$LIBS -pthread")
1824                 ;;
1825                 *)
1826                         AC_CHECK_LIB(pthread, main, LIBS="$LIBS -lpthread")
1827                 ;;
1828         esac
1829         AC_CHECK_HEADERS(pthread.h)
1830         AC_CHECK_HEADERS(pthread_np.h)
1831         AC_CHECK_FUNCS(pthread_mutex_timedlock)
1832         AC_CHECK_FUNCS(pthread_getattr_np pthread_attr_get_np pthread_setname_np)
1833         AC_CHECK_FUNCS(pthread_kill)
1834         AC_MSG_CHECKING(for PTHREAD_MUTEX_RECURSIVE)
1835         AC_TRY_COMPILE([ #include <pthread.h>], [
1836                 pthread_mutexattr_t attr;
1837                 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
1838         ], [
1839                 AC_MSG_RESULT(ok)
1840         ], [
1841                 AC_MSG_RESULT(no)
1842                 AC_ERROR(Posix system lacks support for recursive mutexes)
1843         ])
1844         AC_CHECK_FUNCS(pthread_attr_setstacksize)
1845         AC_CHECK_FUNCS(pthread_attr_getstack pthread_attr_getstacksize)
1846         AC_CHECK_FUNCS(pthread_get_stacksize_np pthread_get_stackaddr_np)
1847
1848         dnl **********************************
1849         dnl *** Check for mincore ***
1850         dnl **********************************
1851         AC_MSG_CHECKING(for mincore)
1852                 AC_TRY_LINK([
1853                 #include <stdio.h>
1854                 #include <sys/types.h>
1855                 #include <sys/mman.h>
1856         ], [
1857                 mincore(NULL, 0, NULL);
1858         ], [
1859                 # Yes, we have it...
1860                 AC_MSG_RESULT(yes)
1861                 AC_DEFINE(HAVE_MINCORE, 1, [Have mincore])
1862         ], [
1863                 AC_MSG_RESULT(no)
1864         ])
1865
1866         dnl ***********************************
1867         dnl *** Checks for working __thread ***
1868         dnl ***********************************
1869         AC_MSG_CHECKING(for working __thread)
1870         if test "x$with_tls" != "x__thread"; then
1871                 AC_MSG_RESULT(disabled)
1872         elif test "x$cross_compiling" = "xyes"; then
1873                 AC_MSG_RESULT(cross compiling, assuming yes)
1874         else
1875                 AC_TRY_RUN([
1876                         #if defined(__APPLE__) && defined(__clang__)
1877                         #error "__thread does not currently work with clang on Mac OS X"
1878                         #endif
1879                         
1880                         #include <pthread.h>
1881                         __thread int i;
1882                         static int res1, res2;
1883
1884                         void thread_main (void *arg)
1885                         {
1886                                 i = arg;
1887                                 sleep (1);
1888                                 if (arg == 1)
1889                                         res1 = (i == arg);
1890                                 else
1891                                         res2 = (i == arg);
1892                         }
1893
1894                         int main () {
1895                                 pthread_t t1, t2;
1896
1897                                 i = 5;
1898
1899                                 pthread_create (&t1, NULL, thread_main, 1);
1900                                 pthread_create (&t2, NULL, thread_main, 2);
1901
1902                                 pthread_join (t1, NULL);
1903                                 pthread_join (t2, NULL);
1904
1905                                 return !(res1 + res2 == 2);
1906                         }
1907                 ], [
1908                                 AC_MSG_RESULT(yes)
1909                 ], [
1910                                 AC_MSG_RESULT(no)
1911                                 with_tls=pthread
1912                 ])
1913         fi
1914
1915         dnl **************************************
1916         dnl *** Checks for working sigaltstack ***
1917         dnl **************************************
1918         AC_MSG_CHECKING(for working sigaltstack)
1919         if test "x$with_sigaltstack" != "xyes"; then
1920                 AC_MSG_RESULT(disabled)
1921         elif test "x$cross_compiling" = "xyes"; then
1922                 AC_MSG_RESULT(cross compiling, assuming yes)
1923         else
1924                 AC_TRY_RUN([
1925                         #include <stdio.h>
1926                         #include <stdlib.h>
1927                         #include <unistd.h>
1928                         #include <signal.h>
1929                         #include <pthread.h>
1930                         #include <sys/wait.h>
1931                         #if defined(__FreeBSD__) || defined(__NetBSD__)
1932                         #define SA_STACK SA_ONSTACK
1933                         #endif
1934                         static void
1935                         sigsegv_signal_handler (int _dummy, siginfo_t *info, void *context)
1936                         {
1937                                 exit (0);
1938                         }
1939
1940                         volatile char*__ptr = NULL;
1941                         static void *
1942                         loop (void *ignored)
1943                         {
1944                                 *__ptr = 0;
1945                                 return NULL;
1946                         }
1947
1948                         static void
1949                         child ()
1950                         {
1951                                 struct sigaction sa;
1952                         #ifdef __APPLE__
1953                                 stack_t sas;
1954                         #else
1955                                 struct sigaltstack sas;
1956                         #endif
1957                                 pthread_t id;
1958                                 pthread_attr_t attr;
1959
1960                                 sa.sa_sigaction = sigsegv_signal_handler;
1961                                 sigemptyset (&sa.sa_mask);
1962                                 sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
1963                                 if (sigaction (SIGSEGV, &sa, NULL) == -1) {
1964                                         perror ("sigaction");
1965                                         return;
1966                                 }
1967
1968                                 /* x86 darwin deliver segfaults using SIGBUS */
1969                                 if (sigaction (SIGBUS, &sa, NULL) == -1) {
1970                                         perror ("sigaction");
1971                                         return;
1972                                 }
1973                                 sas.ss_sp = malloc (SIGSTKSZ);
1974                                 sas.ss_size = SIGSTKSZ;
1975                                 sas.ss_flags = 0;
1976                                 if (sigaltstack (&sas, NULL) == -1) {
1977                                         perror ("sigaltstack");
1978                                         return;
1979                                 }
1980
1981                                 pthread_attr_init (&attr);
1982                                 if (pthread_create(&id, &attr, loop, &attr) != 0) {
1983                                         printf ("pthread_create\n");
1984                                         return;
1985                                 }
1986
1987                                 sleep (100);
1988                         }
1989
1990                         int
1991                         main ()
1992                         {
1993                                 pid_t son;
1994                                 int status;
1995                                 int i;
1996
1997                                 son = fork ();
1998                                 if (son == -1) {
1999                                         return 1;
2000                                 }
2001
2002                                 if (son == 0) {
2003                                         child ();
2004                                         return 0;
2005                                 }
2006
2007                                 for (i = 0; i < 300; ++i) {
2008                                         waitpid (son, &status, WNOHANG);
2009                                         if (WIFEXITED (status) && WEXITSTATUS (status) == 0)
2010                                                 return 0;
2011                                         usleep (10000);
2012                                 }
2013
2014                                 kill (son, SIGKILL);
2015                                 return 1;
2016                         }
2017
2018                 ], [
2019                                 AC_MSG_RESULT(yes)
2020                                 AC_DEFINE(HAVE_WORKING_SIGALTSTACK, 1, [Have a working sigaltstack])
2021                 ], [
2022                                 with_sigaltstack=no
2023                                 AC_MSG_RESULT(no)
2024                 ])
2025         fi
2026
2027         dnl ********************************
2028         dnl *** Checks for semaphore lib ***
2029         dnl ********************************
2030         # 'Real Time' functions on Solaris
2031         # posix4 on Solaris 2.6
2032         # pthread (first!) on Linux
2033         AC_SEARCH_LIBS(sem_init, pthread rt posix4) 
2034
2035         AC_SEARCH_LIBS(shm_open, pthread rt posix4) 
2036         AC_CHECK_FUNCS(shm_open)
2037
2038         dnl ********************************
2039         dnl *** Checks for timezone stuff **
2040         dnl ********************************
2041         AC_CACHE_CHECK(for tm_gmtoff in struct tm, ac_cv_struct_tm_gmtoff,
2042                 AC_TRY_COMPILE([
2043                         #include <time.h>
2044                         ], [
2045                         struct tm tm;
2046                         tm.tm_gmtoff = 1;
2047                         ], ac_cv_struct_tm_gmtoff=yes, ac_cv_struct_tm_gmtoff=no))
2048         if test $ac_cv_struct_tm_gmtoff = yes; then
2049                 AC_DEFINE(HAVE_TM_GMTOFF, 1, [Have tm_gmtoff])
2050         else
2051                 AC_CACHE_CHECK(for timezone variable, ac_cv_var_timezone,
2052                         AC_TRY_COMPILE([
2053                                 #include <time.h>
2054                         ], [
2055                                 timezone = 1;
2056                         ], ac_cv_var_timezone=yes, ac_cv_var_timezone=no))
2057                 if test $ac_cv_var_timezone = yes; then
2058                         AC_DEFINE(HAVE_TIMEZONE, 1, [Have timezone variable])
2059                 else
2060                         AC_ERROR(unable to find a way to determine timezone)
2061                 fi
2062         fi
2063
2064         dnl *********************************
2065         dnl *** Checks for math functions ***
2066         dnl *********************************
2067         AC_SEARCH_LIBS(sqrtf, m)
2068         if test "x$has_broken_apple_cpp" != "xyes"; then
2069                 AC_CHECK_FUNCS(finite, , AC_MSG_CHECKING(for finite in math.h)
2070                         AC_TRY_LINK([#include <math.h>], 
2071                         [ finite(0.0); ], 
2072                         AC_DEFINE(HAVE_FINITE, 1, [Have finite in -lm]) AC_MSG_RESULT(yes),
2073                         AC_MSG_RESULT(no)))
2074         fi
2075         AC_CHECK_FUNCS(isfinite, , AC_MSG_CHECKING(for isfinite in math.h)
2076                 AC_TRY_LINK([#include <math.h>], 
2077                 [ isfinite(0.0); ], 
2078                 AC_DEFINE(HAVE_ISFINITE, 1, [Have isfinite]) AC_MSG_RESULT(yes),
2079                 AC_MSG_RESULT(no)))
2080
2081         dnl ****************************************************************
2082         dnl *** Checks for working poll() (macosx defines it but doesn't ***
2083         dnl *** have it in the library (duh))                            ***
2084         dnl ****************************************************************
2085         AC_CHECK_FUNCS(poll)
2086
2087         dnl *************************
2088         dnl *** Check for signbit ***
2089         dnl *************************
2090         AC_MSG_CHECKING(for signbit)
2091         AC_TRY_LINK([#include <math.h>], [
2092                 int s = signbit(1.0);
2093         ], [
2094                 AC_MSG_RESULT(yes)
2095                 AC_DEFINE(HAVE_SIGNBIT, 1, [Have signbit])
2096         ], [
2097                 AC_MSG_RESULT(no)
2098         ]) 
2099
2100         dnl **********************************
2101         dnl *** epoll                      ***
2102         dnl **********************************
2103         if test "x$ac_cv_header_nacl_nacl_dyncode_h" = "xno"; then
2104                 AC_CHECK_HEADERS(sys/epoll.h)
2105                 haveepoll=no
2106                 AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], )
2107                 if test "x$haveepoll" = "xyes" -a "x$ac_cv_header_sys_epoll_h" = "xyes"; then
2108                         AC_DEFINE(HAVE_EPOLL, 1, [epoll supported])
2109                 fi
2110         fi
2111
2112         havekqueue=no
2113
2114         AC_CHECK_HEADERS(sys/event.h)
2115         AC_CHECK_FUNCS(kqueue, [havekqueue=yes], )
2116
2117         dnl **************************************
2118         dnl * Darwin has a race that prevents us from using reliably:
2119         dnl * http://lists.apple.com/archives/darwin-dev/2011/Jun/msg00016.html
2120         dnl * Since kqueue is mostly used for scaling large web servers, 
2121         dnl * and very few folks run Mono on large web servers on OSX, falling
2122         dnl * back 
2123         dnl **************************************
2124         if test "x$havekqueue" = "xyes" -a "x$ac_cv_header_sys_event_h" = "xyes"; then
2125                 if test "x$host_darwin" = "xno"; then
2126                         AC_DEFINE(USE_KQUEUE_FOR_THREADPOOL, 1, [Use kqueue for the threadpool])
2127                 fi
2128         fi
2129
2130         dnl ******************************
2131         dnl *** Checks for SIOCGIFCONF ***
2132         dnl ******************************
2133         AC_CHECK_HEADERS(sys/ioctl.h)
2134         AC_CHECK_HEADERS(net/if.h, [], [],
2135            [
2136            #ifdef HAVE_SYS_TYPES_H
2137            # include <sys/types.h>
2138            #endif
2139            #ifdef HAVE_SYS_SOCKET_H
2140            # include <sys/socket.h>
2141            #endif
2142            ])
2143         AC_MSG_CHECKING(for ifreq)
2144         AC_TRY_COMPILE([
2145                 #include <stdio.h>
2146                 #include <sys/ioctl.h>
2147                 #include <net/if.h>
2148                 ], [
2149                 struct ifconf ifc;
2150                 struct ifreq *ifr;
2151                 void *x;
2152                 ifc.ifc_len = 0;
2153                 ifc.ifc_buf = NULL;
2154                 x = (void *) &ifr->ifr_addr;
2155                 ],[
2156                         AC_MSG_RESULT(yes)
2157                         AC_DEFINE(HAVE_SIOCGIFCONF, 1, [Can get interface list])
2158                 ], [
2159                         AC_MSG_RESULT(no)
2160                 ])
2161         dnl **********************************
2162         dnl ***     Checks for sin_len     ***
2163         dnl **********************************
2164         AC_MSG_CHECKING(for sockaddr_in.sin_len)
2165         AC_TRY_COMPILE([
2166                 #include <netinet/in.h>
2167                 ], [
2168                 struct sockaddr_in saddr;
2169                 saddr.sin_len = sizeof (saddr);
2170                 ],[
2171                         AC_MSG_RESULT(yes)
2172                         AC_DEFINE(HAVE_SOCKADDR_IN_SIN_LEN, 1, [sockaddr_in has sin_len])
2173                 ], [
2174                         AC_MSG_RESULT(no)
2175                 ])      
2176         dnl **********************************
2177         dnl ***    Checks for sin6_len     ***
2178         dnl **********************************
2179         AC_MSG_CHECKING(for sockaddr_in6.sin6_len)
2180         AC_TRY_COMPILE([
2181                 #include <netinet/in.h>
2182                 ], [
2183                 struct sockaddr_in6 saddr6;
2184                 saddr6.sin6_len = sizeof (saddr6);
2185                 ],[
2186                         AC_MSG_RESULT(yes)
2187                         AC_DEFINE(HAVE_SOCKADDR_IN6_SIN_LEN, 1, [sockaddr_in6 has sin6_len])
2188                 ], [
2189                         AC_MSG_RESULT(no)
2190                 ])
2191         dnl **********************************
2192         dnl *** Check for getifaddrs       ***
2193         dnl **********************************
2194         AC_MSG_CHECKING(for getifaddrs)
2195                 AC_TRY_LINK([
2196                 #include <stdio.h>
2197                 #include <sys/types.h>
2198                 #include <sys/socket.h>
2199                 #include <ifaddrs.h>
2200         ], [
2201                 getifaddrs(NULL);
2202         ], [
2203                 # Yes, we have it...
2204                 AC_MSG_RESULT(yes)
2205                 AC_DEFINE(HAVE_GETIFADDRS, 1, [Have getifaddrs])
2206         ], [
2207                 AC_MSG_RESULT(no)
2208         ])
2209         dnl **********************************
2210         dnl *** Check for if_nametoindex   ***
2211         dnl **********************************
2212         AC_MSG_CHECKING(for if_nametoindex)
2213                 AC_TRY_LINK([
2214                 #include <stdio.h>
2215                 #include <sys/types.h>
2216                 #include <sys/socket.h>
2217                 #include <net/if.h>
2218         ], [
2219                 if_nametoindex(NULL);
2220         ], [
2221                 # Yes, we have it...
2222                 AC_MSG_RESULT(yes)
2223                 AC_DEFINE(HAVE_IF_NAMETOINDEX, 1, [Have if_nametoindex])
2224         ], [
2225                 AC_MSG_RESULT(no)
2226         ])
2227                         
2228         dnl **********************************
2229         dnl *** Checks for MonoPosixHelper ***
2230         dnl **********************************
2231         AC_CHECK_HEADERS(checklist.h)
2232         AC_CHECK_HEADERS(pathconf.h)
2233         AC_CHECK_HEADERS(fstab.h)
2234         AC_CHECK_HEADERS(attr/xattr.h)
2235         AC_CHECK_HEADERS(sys/extattr.h)
2236         AC_CHECK_HEADERS(sys/sendfile.h)
2237         AC_CHECK_HEADERS(sys/statvfs.h)
2238         AC_CHECK_HEADERS(sys/statfs.h)
2239         AC_CHECK_HEADERS(sys/vfstab.h)
2240         AC_CHECK_HEADERS(sys/xattr.h)
2241         AC_CHECK_HEADERS(sys/mman.h)
2242         AC_CHECK_HEADERS(sys/param.h)
2243         AC_CHECK_HEADERS(sys/mount.h, [], [],
2244                 [
2245                 #ifdef HAVE_SYS_PARAM_H
2246                 # include <sys/param.h>
2247                 #endif
2248                 ])
2249         AC_CHECK_HEADERS(sys/mount.h)
2250         AC_CHECK_FUNCS(confstr)
2251         AC_CHECK_FUNCS(seekdir telldir)
2252         AC_CHECK_FUNCS(getdomainname)
2253         AC_CHECK_FUNCS(setdomainname)
2254         AC_CHECK_FUNCS(endgrent getgrent fgetgrent setgrent)
2255         AC_CHECK_FUNCS(setgroups)
2256         AC_CHECK_FUNCS(endpwent getpwent fgetpwent setpwent)
2257         AC_CHECK_FUNCS(getfsstat)
2258         AC_CHECK_FUNCS(lutimes futimes)
2259         AC_CHECK_FUNCS(mremap)
2260         AC_CHECK_FUNCS(remap_file_pages)
2261         AC_CHECK_FUNCS(posix_fadvise)
2262         AC_CHECK_FUNCS(posix_fallocate)
2263         AC_CHECK_FUNCS(posix_madvise)
2264         AC_CHECK_FUNCS(vsnprintf)
2265         AC_CHECK_FUNCS(sendfile)
2266         AC_CHECK_FUNCS(gethostid sethostid)
2267         AC_CHECK_FUNCS(sethostname)
2268         AC_CHECK_FUNCS(statfs)
2269         AC_CHECK_FUNCS(fstatfs)
2270         AC_CHECK_FUNCS(statvfs)
2271         AC_CHECK_FUNCS(fstatvfs)
2272         AC_CHECK_FUNCS(stime)
2273         AC_CHECK_FUNCS(strerror_r)
2274         AC_CHECK_FUNCS(ttyname_r)
2275         AC_CHECK_FUNCS(psignal)
2276         AC_CHECK_FUNCS(getlogin_r)
2277         AC_CHECK_FUNCS(lockf)
2278         AC_CHECK_FUNCS(swab)
2279         AC_CHECK_FUNCS(setusershell endusershell)
2280         AC_CHECK_FUNCS(futimens utimensat)
2281         AC_CHECK_FUNCS(fstatat mknodat readlinkat)
2282         AC_CHECK_FUNCS(readv writev preadv pwritev)
2283         AC_CHECK_FUNCS(setpgid)
2284         AC_CHECK_FUNCS(system)
2285         AC_CHECK_FUNCS(fork execv execve)
2286         AC_CHECK_FUNCS(accept4)
2287         AC_CHECK_SIZEOF(size_t)
2288         AC_CHECK_TYPES([blksize_t], [AC_DEFINE(HAVE_BLKSIZE_T)], , 
2289                 [#include <sys/types.h>
2290                  #include <sys/stat.h>
2291                  #include <unistd.h>])
2292         AC_CHECK_TYPES([blkcnt_t], [AC_DEFINE(HAVE_BLKCNT_T)], ,
2293                 [#include <sys/types.h>
2294                  #include <sys/stat.h>
2295                  #include <unistd.h>])
2296         AC_CHECK_TYPES([suseconds_t], [AC_DEFINE(HAVE_SUSECONDS_T)], ,
2297                 [#include <sys/time.h>])
2298         AC_CHECK_TYPES([struct cmsghdr], [AC_DEFINE(HAVE_STRUCT_CMSGHDR)], ,
2299                 [#include <sys/socket.h>])
2300         AC_CHECK_TYPES([struct flock], [AC_DEFINE(HAVE_STRUCT_FLOCK)], ,
2301                 [#include <unistd.h>
2302                  #include <fcntl.h>])
2303         AC_CHECK_TYPES([struct iovec], [AC_DEFINE(HAVE_STRUCT_IOVEC)], ,
2304                 [#include <sys/uio.h>])
2305         AC_CHECK_TYPES([struct linger], [AC_DEFINE(HAVE_STRUCT_LINGER)], ,
2306                 [#include <sys/socket.h>])
2307         AC_CHECK_TYPES([struct pollfd], [AC_DEFINE(HAVE_STRUCT_POLLFD)], ,
2308                 [#include <sys/poll.h>])
2309         AC_CHECK_TYPES([struct sockaddr], [AC_DEFINE(HAVE_STRUCT_SOCKADDR)], ,
2310                 [#include <sys/socket.h>])
2311         AC_CHECK_TYPES([struct sockaddr_storage], [AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE)], ,
2312                 [#include <sys/socket.h>])
2313         AC_CHECK_TYPES([struct sockaddr_in], [AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN)], ,
2314                 [#include <netinet/in.h>])
2315         AC_CHECK_TYPES([struct sockaddr_in6], [AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6)], ,
2316                 [#include <netinet/in.h>])
2317         AC_CHECK_TYPES([struct sockaddr_un], [AC_DEFINE(HAVE_STRUCT_SOCKADDR_UN)], ,
2318                 [#include <sys/un.h>])
2319         AC_CHECK_TYPES([struct stat], [AC_DEFINE(HAVE_STRUCT_STAT)], ,
2320                 [#include <sys/types.h>
2321                  #include <sys/stat.h>
2322                  #include <unistd.h>])
2323         AC_CHECK_TYPES([struct timespec], [AC_DEFINE(HAVE_STRUCT_TIMESPEC)], ,
2324                 [#include <time.h>])
2325         AC_CHECK_TYPES([struct timeval], [AC_DEFINE(HAVE_STRUCT_TIMEVAL)], ,
2326                 [#include <sys/time.h>
2327                  #include <sys/types.h>
2328                  #include <utime.h>])
2329         AC_CHECK_TYPES([struct timezone], [AC_DEFINE(HAVE_STRUCT_TIMEZONE)], ,
2330                 [#include <sys/time.h>])
2331         AC_CHECK_TYPES([struct utimbuf], [AC_DEFINE(HAVE_STRUCT_UTIMBUF)], ,
2332                 [#include <sys/types.h>
2333                  #include <utime.h>])
2334         AC_CHECK_MEMBERS(
2335                 [struct dirent.d_off, struct dirent.d_reclen, struct dirent.d_type],,, 
2336                 [#include <sys/types.h>
2337                  #include <dirent.h>])
2338         AC_CHECK_MEMBERS(
2339                 [struct passwd.pw_gecos],,, 
2340                 [#include <sys/types.h>
2341                  #include <pwd.h>])
2342         AC_CHECK_MEMBERS(
2343                 [struct statfs.f_flags],,, 
2344                 [#include <sys/types.h>
2345                  #include <sys/vfs.h>])
2346         AC_CHECK_MEMBERS(
2347                 [struct stat.st_atim, struct stat.st_mtim, struct stat.st_ctim],,, 
2348                 [#include <sys/types.h>
2349                  #include <sys/stat.h>
2350                  #include <unistd.h>])
2351
2352         dnl Favour xattr through glibc, but use libattr if we have to
2353         AC_CHECK_FUNC(lsetxattr, ,
2354                 AC_CHECK_LIB(attr, lsetxattr, XATTR_LIB="-lattr",)
2355         )
2356         AC_SUBST(XATTR_LIB)
2357
2358         dnl kinfo_proc.kp_proc works on darwin but fails on other simil-bsds
2359         AC_CHECK_MEMBERS(
2360                 [struct kinfo_proc.kp_proc],,, 
2361                 [#include <sys/types.h>
2362                  #include <sys/param.h>
2363                  #include <sys/sysctl.h>
2364                  #include <sys/proc.h>
2365                  ])
2366
2367         dnl *********************************
2368         dnl *** Checks for Windows compilation ***
2369         dnl *********************************
2370         AC_CHECK_HEADERS(sys/time.h)
2371         AC_CHECK_HEADERS(sys/param.h)
2372         AC_CHECK_HEADERS(dirent.h)
2373
2374         dnl ******************************************
2375         dnl *** Checks for OSX and iOS compilation ***
2376         dnl ******************************************
2377         AC_CHECK_HEADERS(CommonCrypto/CommonDigest.h)
2378
2379         dnl *********************************
2380         dnl *** Check for Console 2.0 I/O ***
2381         dnl *********************************
2382         AC_CHECK_HEADERS([curses.h])
2383         AC_CHECK_HEADERS([term.h], [], [],
2384         [#if HAVE_CURSES_H
2385          #include <curses.h>
2386          #endif
2387         ])
2388         AC_CHECK_HEADERS([termios.h])
2389 else
2390         dnl *********************************
2391         dnl *** Checks for Windows compilation ***
2392         dnl *********************************
2393         AC_CHECK_HEADERS(winternl.h)
2394
2395         jdk_headers_found=no
2396         AC_CHECK_LIB(ws2_32, main, LIBS="$LIBS -lws2_32", AC_ERROR(bad mingw install?))
2397         AC_CHECK_LIB(psapi, main, LIBS="$LIBS -lpsapi", AC_ERROR(bad mingw install?))
2398         AC_CHECK_LIB(ole32, main, LIBS="$LIBS -lole32", AC_ERROR(bad mingw install?))
2399         AC_CHECK_LIB(winmm, main, LIBS="$LIBS -lwinmm", AC_ERROR(bad mingw install?))
2400         AC_CHECK_LIB(oleaut32, main, LIBS="$LIBS -loleaut32", AC_ERROR(bad mingw install?))
2401         AC_CHECK_LIB(advapi32, main, LIBS="$LIBS -ladvapi32", AC_ERROR(bad mingw install?))
2402         AC_CHECK_LIB(version, main, LIBS="$LIBS -lversion", AC_ERROR(bad mingw install?))
2403
2404         dnl *********************************
2405         dnl *** Check for struct ip_mreqn ***
2406         dnl *********************************
2407         AC_MSG_CHECKING(for struct ip_mreqn)
2408         AC_TRY_COMPILE([#include <ws2tcpip.h>], [
2409                 struct ip_mreqn mreq;
2410                 mreq.imr_address.s_addr = 0;
2411         ], [
2412                 # Yes, we have it...
2413                 AC_MSG_RESULT(yes)
2414                 AC_DEFINE(HAVE_STRUCT_IP_MREQN)
2415         ], [
2416                 # We'll just have to try and use struct ip_mreq
2417                 AC_MSG_RESULT(no)
2418                 AC_MSG_CHECKING(for struct ip_mreq)
2419                 AC_TRY_COMPILE([#include <ws2tcpip.h>], [
2420                         struct ip_mreq mreq;
2421                         mreq.imr_interface.s_addr = 0;
2422                 ], [
2423                         # Yes, we have it...
2424                         AC_MSG_RESULT(yes)
2425                         AC_DEFINE(HAVE_STRUCT_IP_MREQ)
2426                 ], [
2427                         # No multicast support
2428                         AC_MSG_RESULT(no)
2429                 ])
2430         ])
2431
2432         dnl **********************************
2433         dnl *** Check for getaddrinfo ***
2434         dnl **********************************
2435         AC_MSG_CHECKING(for getaddrinfo)
2436                 AC_TRY_LINK([
2437                 #include <stdio.h>
2438                 #include <winsock2.h>
2439                 #include <ws2tcpip.h>
2440         ], [
2441                 getaddrinfo(NULL,NULL,NULL,NULL);
2442         ], [
2443                 # Yes, we have it...
2444                 AC_MSG_RESULT(yes)
2445                 AC_DEFINE(HAVE_GETADDRINFO, 1, [Have getaddrinfo])
2446         ], [
2447                 AC_MSG_RESULT(no)
2448         ])
2449
2450         dnl **********************************
2451         dnl *** Check for gethostbyname ***
2452         dnl **********************************
2453         AC_MSG_CHECKING(for gethostbyname)
2454                 AC_TRY_LINK([
2455                 #include <stdio.h>
2456                 #include <winsock2.h>
2457                 #include <ws2tcpip.h>
2458         ], [
2459                 gethostbyname(NULL);
2460         ], [
2461                 # Yes, we have it...
2462                 AC_MSG_RESULT(yes)
2463                 AC_DEFINE(HAVE_GETHOSTBYNAME, 1, [Have gethostbyname])
2464         ], [
2465                 AC_MSG_RESULT(no)
2466         ])
2467
2468         dnl **********************************
2469         dnl *** Check for getprotobyname ***
2470         dnl **********************************
2471         AC_MSG_CHECKING(for getprotobyname)
2472                 AC_TRY_LINK([
2473                 #include <stdio.h>
2474                 #include <winsock2.h>
2475                 #include <ws2tcpip.h>
2476         ], [
2477                 getprotobyname(NULL);
2478         ], [
2479                 # Yes, we have it...
2480                 AC_MSG_RESULT(yes)
2481                 AC_DEFINE(HAVE_GETPROTOBYNAME, 1, [Have getprotobyname])
2482         ], [
2483                 AC_MSG_RESULT(no)
2484         ])
2485
2486         dnl **********************************
2487         dnl *** Check for getnameinfo ***
2488         dnl **********************************
2489         AC_MSG_CHECKING(for getnameinfo)
2490                 AC_TRY_LINK([
2491                 #include <stdio.h>
2492                 #include <winsock2.h>
2493                 #include <ws2tcpip.h>
2494         ], [
2495                 getnameinfo (NULL, 0, NULL, 0, NULL, 0, 0);
2496         ], [
2497                 # Yes, we have it...
2498                 AC_MSG_RESULT(yes)
2499                 AC_DEFINE(HAVE_GETNAMEINFO, 1, [Have getnameinfo])
2500         ], [
2501                 AC_MSG_RESULT(no)
2502         ])
2503
2504         dnl **********************************
2505         dnl *** Check for inet_ntop ***
2506         dnl **********************************
2507         AC_MSG_CHECKING(for inet_ntop)
2508                 AC_TRY_LINK([
2509                 #include <stdio.h>
2510                 #include <winsock2.h>
2511                 #include <ws2tcpip.h>
2512         ], [
2513                 inet_ntop (0, NULL, NULL, 0);
2514         ], [
2515                 # Yes, we have it...
2516                 AC_MSG_RESULT(yes)
2517                 AC_DEFINE(HAVE_INET_NTOP, 1, [Have inet_ntop])
2518         ], [
2519                 AC_MSG_RESULT(no)
2520         ])
2521
2522         dnl **********************************
2523         dnl *** Check for inet_pton ***
2524         dnl **********************************
2525         AC_MSG_CHECKING(for inet_pton)
2526                 AC_TRY_LINK([
2527                 #include <stdio.h>
2528                 #include <winsock2.h>
2529                 #include <ws2tcpip.h>
2530         ], [
2531                 #ifndef inet_pton
2532                 (void) inet_pton;
2533                 #endif
2534                 inet_pton (0, NULL, NULL);
2535         ], [
2536                 # Yes, we have it...
2537                 AC_MSG_RESULT(yes)
2538                 AC_DEFINE(HAVE_INET_PTON, 1, [Have inet_pton])
2539         ], [
2540                 AC_MSG_RESULT(no)
2541         ])
2542
2543         AC_CHECK_DECLS(InterlockedExchange64, [], [], [[#include <windows.h>]])
2544         AC_CHECK_DECLS(InterlockedCompareExchange64, [], [], [[#include <windows.h>]])
2545         AC_CHECK_DECLS(InterlockedDecrement64, [], [], [[#include <windows.h>]])
2546         AC_CHECK_DECLS(InterlockedIncrement64, [], [], [[#include <windows.h>]])
2547         AC_CHECK_DECLS(InterlockedAdd, [], [], [[#include <windows.h>]])
2548         AC_CHECK_DECLS(InterlockedAdd64, [], [], [[#include <windows.h>]])
2549         AC_CHECK_DECLS(__readfsdword, [], [], [[#include <windows.h>]])
2550 fi
2551
2552 dnl socklen_t check
2553 AC_MSG_CHECKING(for socklen_t)
2554 AC_TRY_COMPILE([
2555 #include <sys/types.h>
2556 #include <sys/socket.h>
2557 ],[
2558   socklen_t foo;
2559 ],[
2560 ac_cv_c_socklen_t=yes
2561         AC_DEFINE(HAVE_SOCKLEN_T, 1, [Have socklen_t])
2562         AC_MSG_RESULT(yes)
2563 ],[
2564         AC_MSG_RESULT(no)
2565 ])
2566
2567 AC_MSG_CHECKING(for array element initializer support)
2568 AC_TRY_COMPILE([#include <sys/socket.h>], [
2569         const int array[] = {[1] = 2,};
2570 ], [
2571         # Yes, we have it...
2572         AC_MSG_RESULT(yes)
2573         AC_DEFINE(HAVE_ARRAY_ELEM_INIT,1,[Supports C99 array initialization])
2574 ], [
2575         # We'll have to use signals
2576         AC_MSG_RESULT(no)
2577 ])
2578
2579 AC_CHECK_FUNCS(trunc, , AC_MSG_CHECKING(for trunc in math.h)
2580         # Simply calling trunc (0.0) is no good since gcc will optimize the call away
2581         AC_TRY_LINK([#include <math.h>], 
2582         [ static void *p = &trunc; ],
2583         [
2584                 AC_DEFINE(HAVE_TRUNC) 
2585                 AC_MSG_RESULT(yes)
2586                 ac_cv_trunc=yes
2587         ],
2588         AC_MSG_RESULT(no)))
2589
2590 if test "x$ac_cv_truncl" != "xyes"; then
2591    AC_CHECK_LIB(sunmath, aintl, [ AC_DEFINE(HAVE_AINTL, 1, [Has the 'aintl' function]) LIBS="$LIBS -lsunmath"])
2592 fi
2593
2594 AC_CHECK_FUNCS(execvp)
2595
2596 dnl ****************************
2597 dnl *** Look for /dev/random ***
2598 dnl ****************************
2599
2600 AC_MSG_CHECKING([if usage of random device is requested])
2601 AC_ARG_ENABLE(dev-random,
2602 [  --disable-dev-random    disable the use of the random device (enabled by default)],
2603 try_dev_random=$enableval, try_dev_random=yes)
2604
2605 AC_MSG_RESULT($try_dev_random)
2606
2607 case "{$build}" in
2608     *-openbsd*)
2609     NAME_DEV_RANDOM="/dev/srandom"
2610     ;;
2611
2612 dnl Win32 does not have /dev/random, they have their own method...
2613
2614     *-mingw*|*-*-cygwin*)
2615     ac_cv_have_dev_random=no
2616     ;;
2617
2618 dnl Everywhere else, it's /dev/random
2619
2620     *)
2621     NAME_DEV_RANDOM="/dev/random"
2622     ;;
2623 esac
2624
2625 AC_DEFINE_UNQUOTED(NAME_DEV_RANDOM, "$NAME_DEV_RANDOM", [Name of /dev/random])
2626
2627 dnl Now check if the device actually exists
2628
2629 if test "x$try_dev_random" = "xyes"; then
2630     AC_CACHE_CHECK(for random device, ac_cv_have_dev_random,
2631     [if test -r "$NAME_DEV_RANDOM" ; then
2632         ac_cv_have_dev_random=yes; else ac_cv_have_dev_random=no; fi])
2633     if test "x$ac_cv_have_dev_random" = "xyes"; then
2634         AC_DEFINE(HAVE_CRYPT_RNG, 1, [Have /dev/random])
2635     fi
2636 else
2637     AC_MSG_CHECKING(for random device)
2638     ac_cv_have_dev_random=no
2639     AC_MSG_RESULT(has been disabled)
2640 fi
2641
2642 if test "x$host_win32" = "xyes"; then
2643     AC_DEFINE(HAVE_CRYPT_RNG)
2644 fi
2645
2646 if test "x$ac_cv_have_dev_random" = "xno" \
2647     && test "x$host_win32" = "xno"; then
2648     AC_MSG_WARN([[
2649 ***
2650 *** A system-provided entropy source was not found on this system.
2651 *** Because of this, the System.Security.Cryptography random number generator
2652 *** will throw a NotImplemented exception.
2653 ***
2654 *** If you are seeing this message, and you know your system DOES have an
2655 *** entropy collection in place, please contact <crichton@gimp.org> and
2656 *** provide information about the system and how to access the random device.
2657 ***
2658 *** Otherwise you can install either egd or prngd and set the environment
2659 *** variable MONO_EGD_SOCKET to point to the daemon's socket to use that.
2660 ***]])
2661 fi
2662
2663 AC_ARG_ENABLE(bcl-opt, [  --disable-bcl-opt     BCL is compiled with no optimizations (allows accurate BCL debugging)], test_bcl_opt=$enableval, test_bcl_opt=yes)
2664
2665 AC_MSG_CHECKING([if big-arrays are to be enabled])
2666 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)
2667 if test "x$enable_big_arrays" = "xyes" ; then
2668     if  test "x$ac_cv_sizeof_void_p" = "x8"; then
2669         AC_DEFINE(MONO_BIG_ARRAYS,1,[Enable the allocation and indexing of arrays greater than Int32.MaxValue])
2670     else
2671         AC_MSG_ERROR([The allocation and indexing of arrays greater than Int32.MaxValue is not supported on this platform.])
2672     fi
2673 fi
2674 AC_MSG_RESULT($enable_big_arrays)
2675
2676 dnl **************
2677 dnl *** DTRACE ***
2678 dnl **************
2679
2680 AC_ARG_ENABLE(dtrace,[  --enable-dtrace Enable DTrace probes], enable_dtrace=$enableval, enable_dtrace=$has_dtrace)
2681
2682 if test "x$enable_dtrace" = "xyes"; then
2683    if test "x$has_dtrace" = "xno"; then
2684           AC_MSG_ERROR([DTrace probes are not supported on this platform.])
2685    fi
2686    AC_PATH_PROG(DTRACE, [dtrace], [no], [$PATH:/usr/sbin])
2687    if test "x$DTRACE" = "xno"; then
2688           AC_MSG_RESULT([dtrace utility not found, dtrace support disabled.])
2689           enable_dtrace=no
2690    elif ! $DTRACE -h -s $srcdir/data/mono.d > /dev/null 2>&1; then
2691           AC_MSG_RESULT([dtrace doesn't support -h option, dtrace support disabled.])
2692           enable_dtrace=no
2693    fi
2694 fi
2695
2696 dtrace_g=no
2697 if test "x$enable_dtrace" = "xyes"; then
2698         AC_DEFINE(ENABLE_DTRACE, 1, [Enable DTrace probes])
2699         DTRACEFLAGS=
2700         if test "x$ac_cv_sizeof_void_p" = "x8"; then
2701                 case "$host" in
2702                         powerpc-*-darwin*)
2703                         DTRACEFLAGS="-arch ppc64"
2704                         ;;
2705                         i*86-*-darwin*)
2706                         DTRACEFLAGS="-arch x86_64"
2707                         ;;
2708                         *)
2709                         DTRACEFLAGS=-64
2710                         ;;
2711                 esac
2712         else
2713                 case "$host" in
2714                         powerpc-*-darwin*)
2715                         DTRACEFLAGS="-arch ppc"
2716                         ;;
2717                         i*86-*-darwin*)
2718                         DTRACEFLAGS="-arch i386"
2719                         ;;
2720                         *)
2721                         DTRACEFLAGS=-32
2722                         ;;
2723                 esac
2724         fi
2725         AC_SUBST(DTRACEFLAGS)
2726         case "$host" in
2727                 *-*-solaris*)
2728                 dtrace_g=yes
2729                 ;;
2730         esac
2731         AC_CHECK_HEADERS([sys/sdt.h])
2732 fi
2733 AM_CONDITIONAL(ENABLE_DTRACE, [test x$enable_dtrace = xyes])
2734 AM_CONDITIONAL(DTRACE_G_REQUIRED, [test x$dtrace_g = xyes])
2735
2736 dnl **************
2737 dnl ***  NaCl  ***
2738 dnl **************
2739
2740 AC_ARG_ENABLE(nacl_codegen, [  --enable-nacl-codegen      Enable Native Client code generation], enable_nacl_codegen=$enableval, enable_nacl_codegen=no)
2741 AC_ARG_ENABLE(nacl_gc, [  --enable-nacl-gc           Enable Native Client garbage collection], enable_nacl_gc=$enableval, enable_nacl_gc=no)
2742
2743 AM_CONDITIONAL(NACL_CODEGEN, test x$enable_nacl_codegen != xno)
2744
2745 dnl
2746 dnl Hack to use system mono for operations in build/install not allowed in NaCl.
2747 dnl
2748 nacl_self_host=""
2749 if test "x$ac_cv_header_nacl_nacl_dyncode_h" = "xyes"; then
2750    nacl_self_host="nacl_self_host"
2751 fi
2752 AC_SUBST(nacl_self_host)
2753
2754 if test "x$enable_nacl_codegen" = "xyes"; then
2755    MONO_NACL_ALIGN_MASK_OFF=1
2756    AC_DEFINE(TARGET_NACL, 1, [...])
2757    AC_DEFINE(__native_client_codegen__, 1, [...])
2758 fi
2759 if test "x$enable_nacl_gc" = "xyes"; then
2760    if test "x$TARGET" = "xAMD64" -o "x$TARGET" = "xX86"; then
2761       INSTRUMENT_CFLAG="-finstrument-for-thread-suspension"
2762    else
2763       # Not yet implemented
2764       INSTRUMENT_CFLAG=""
2765    fi
2766    CPPFLAGS="$CPPFLAGS $INSTRUMENT_CFLAG -D__native_client_gc__"
2767 fi
2768 AC_SUBST(MONO_NACL_ALIGN_MASK_OFF)
2769
2770 dnl **************************
2771 dnl *** AOT cross offsets  ***
2772 dnl **************************
2773
2774 AC_ARG_WITH(cross-offsets, [  --with-cross-offsets=<offsets file path>    Explicit AOT cross offsets file],
2775     AC_DEFINE_UNQUOTED(MONO_OFFSETS_FILE, "$withval", [AOT cross offsets file]))
2776
2777 dnl **************
2778 dnl ***  LLVM  ***
2779 dnl **************
2780
2781 AC_ARG_ENABLE(llvm,[  --enable-llvm     Enable the LLVM back-end], enable_llvm=$enableval, enable_llvm=default)
2782 AC_ARG_ENABLE(loadedllvm,[  --enable-loadedllvm Load the LLVM back-end dynamically], enable_llvm=$enableval && enable_loadedllvm=$enableval, enable_loadedllvm=no)
2783 AC_ARG_ENABLE(llvm-version-check,[  --enable-llvm-version-check Check that the LLVM matches the version expected by mono], enable_llvm_version_check=$enableval, enable_llvm_version_check=no)
2784 AC_ARG_ENABLE(llvm-runtime,[  --enable-llvm-runtime     Enable runtime support for llvmonly code], enable_llvm_runtime=$enableval, enable_llvm_runtime=no)
2785
2786 AC_ARG_WITH(llvm, [  --with-llvm=<llvm prefix>    Enable the LLVM back-end], enable_llvm=yes,)
2787
2788 if test "x$enable_llvm" = "xdefault"; then
2789    enable_llvm=$enable_llvm_default
2790 fi
2791
2792 if test "x$enable_llvm" = "xyes"; then
2793    if test "x$with_llvm" != "x"; then
2794           LLVM_CONFIG=$with_llvm/bin/llvm-config
2795           if test x$host_win32 = xyes; then
2796                 LLVM_CONFIG=$LLVM_CONFIG.exe
2797           fi
2798           if test ! -x $LLVM_CONFIG; then
2799                  AC_MSG_ERROR([LLVM executable $LLVM_CONFIG not found.])
2800       fi
2801    else
2802       AC_PATH_PROG(LLVM_CONFIG, llvm-config, no)
2803       if test "x$LLVM_CONFIG" = "xno"; then
2804              AC_MSG_ERROR([llvm-config not found.])
2805       fi
2806    fi
2807
2808    llvm_codegen="x86codegen"
2809    case "$target" in
2810    arm*)
2811                 llvm_codegen="armcodegen"
2812                 ;;
2813    esac
2814
2815    if test "x$host_win32" = "xno"; then
2816
2817    # Should be something like '2.6' or '2.7svn'
2818    llvm_version=`$LLVM_CONFIG --version`
2819    llvm_api_version=`$LLVM_CONFIG --mono-api-version 2>/dev/null`
2820    AC_MSG_CHECKING(LLVM version)
2821    AC_MSG_RESULT($llvm_version $llvm_api_version)
2822    if echo $llvm_version | grep -q 'mono'; then
2823           if test "x$enable_llvm_version_check" = "xyes"; then
2824                  if test "$llvm_version" != "$expected_llvm_version"; then
2825                         AC_MSG_ERROR([Expected llvm version $expected_llvm_version, but llvm-config --version returned $llvm_version"])
2826                  fi
2827           fi
2828    else
2829           AC_MSG_ERROR([Compiling with stock LLVM is not supported, please use the Mono LLVM repo at https://github.com/mono/llvm, with the GIT branch which matches this version of mono, i.e. 'mono-2-10' for Mono 2.10.])
2830    fi
2831
2832    # The output of --cflags seems to include optimizations flags too
2833    if test $llvm_api_version -gt 100; then
2834           # The --cflags argument includes all kinds of warnings -pendantic etc.
2835           LLVM_CFLAGS="-I$with_llvm/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
2836           LLVM_CXXFLAGS="-I$with_llvm/include -std=c++11 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
2837    else
2838           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'`
2839       LLVM_CXXFLAGS=`$LLVM_CONFIG --cxxflags | sed -e 's/-O2//g' | sed -e 's/-O0//g' | sed -e 's/-fomit-frame-pointer//g' | sed -e 's/-fPIC//g'`
2840    fi
2841    # LLVM is compiled with -fno-rtti, so we need this too, since our classes inherit
2842    # from LLVM classes.
2843    LLVM_CXXFLAGS="$LLVM_CXXFLAGS -fno-rtti -fexceptions"
2844    LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags`
2845    # This might include empty lines
2846    LLVM_SYSTEM_LIBS=`$LLVM_CONFIG --system-libs 2>/dev/null | grep -- -`
2847    llvm_jit_supported=yes
2848    llvm_jit_libs="jit mcjit $llvm_codegen"
2849    if test "x$host" != "x$target"; then
2850       # No need for jit libs
2851           llvm_jit_supported=no
2852       llvm_jit_libs=""
2853    elif test $llvm_api_version -gt 100; then
2854       llvm_jit_libs="orcjit $llvm_codegen"
2855    fi
2856    LLVM_LIBS=`$LLVM_CONFIG --libs analysis core bitwriter $llvm_jit_libs`
2857    if test "x$LLVM_LIBS" = "x"; then
2858           echo "$LLVM_CONFIG --libs failed."
2859           exit 1
2860    fi
2861    LLVM_LIBS="$LLVM_LIBS $LLVM_LDFLAGS $LLVM_SYSTEM_LIBS"
2862    # The c++ standard library used by llvm doesn't show up in $LLVM_SYSTEM_LIBS so add it manually
2863    if echo $LLVM_CXXFLAGS | grep -q -- '-stdlib=libc++'; then
2864       LLVM_LIBS="$LLVM_LIBS -lc++"
2865    else
2866       LLVM_LIBS="$LLVM_LIBS -lstdc++"
2867    fi
2868
2869    expected_llvm_version="3.4svn-mono-mono/e656cac"
2870
2871    else
2872        LLVM_CFLAGS="-I$with_llvm/include -DNDEBUG -D__NO_CTYPE_INLINE -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
2873        LLVM_CXXFLAGS="$LLVM_CFLAGS -std=gnu++11 -fvisibility-inlines-hidden -fno-rtti -Woverloaded-virtual -Wcast-qual"
2874        LLVM_LDFLAGS="-L$with_llvm/lib"
2875        LLVM_SYSTEM_LIBS="-lshell32 -lpsapi -limagehlp -ldbghelp -lm"
2876        LLVM_LIBS="-lLLVMLTO -lLLVMObjCARCOpts -lLLVMLinker -lLLVMipo -lLLVMVectorize -lLLVMBitWriter \
2877          -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo \
2878          -lLLVMARMAsmPrinter -lLLVMTableGen -lLLVMDebugInfo -lLLVMOption -lLLVMX86Disassembler \
2879          -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMX86Desc \
2880          -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMJIT \
2881          -lLLVMAnalysis -lLLVMTarget \
2882          -lLLVMIRReader -lLLVMAsmParser -lLLVMLineEditor -lLLVMMCAnalysis -lLLVMInstrumentation \
2883          -lLLVMInterpreter -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils \
2884          -lLLVMipa -lLLVMAnalysis -lLLVMProfileData -lLLVMMCJIT -lLLVMTarget -lLLVMRuntimeDyld \
2885          -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMExecutionEngine -lLLVMMC -lLLVMCore \
2886          -lLLVMSupport -lstdc++"
2887        LLVM_LIBS="$LLVM_LIBS $LLVM_SYSTEM_LIBS"
2888
2889        llvm_config_path=$with_llvm/include/llvm/Config/llvm-config.h
2890        llvm_api_version=`awk '/MONO_API_VERSION/ { print $3 }' $llvm_config_path`
2891    fi  
2892
2893    if test "x$llvm_api_version" = "x"; then
2894           LLVM_CFLAGS="$LLVM_CFLAGS -DLLVM_API_VERSION=0"
2895           LLVM_CXXFLAGS="$LLVM_CXXFLAGS -DLLVM_API_VERSION=0"
2896    else
2897           LLVM_CFLAGS="$LLVM_CFLAGS -DLLVM_API_VERSION=$llvm_api_version"
2898           LLVM_CXXFLAGS="$LLVM_CXXFLAGS -DLLVM_API_VERSION=$llvm_api_version"
2899    fi   
2900
2901    AC_DEFINE_UNQUOTED(LLVM_VERSION, "$llvm_version", [Full version of LLVM libraties])
2902
2903    AC_SUBST(LLVM_CFLAGS)
2904    AC_SUBST(LLVM_CXXFLAGS)
2905    AC_SUBST(LLVM_LIBS)
2906    AC_SUBST(LLVM_LDFLAGS)
2907    AC_DEFINE(ENABLE_LLVM, 1, [Enable the LLVM back end])
2908 fi
2909
2910 AM_CONDITIONAL(ENABLE_LLVM, [test x$enable_llvm = xyes])
2911 if test "x$enable_loadedllvm" = "xyes"; then
2912    AC_DEFINE(MONO_LLVM_LOADED, 1, [The LLVM back end is dynamically loaded])
2913 fi
2914 AM_CONDITIONAL(LOADED_LLVM, [test x$enable_loadedllvm = xyes])
2915
2916 if test "x$enable_llvm" = "xyes"; then
2917    enable_llvm_runtime=yes
2918 fi
2919 if test "x$enable_llvm_runtime" = "xyes"; then
2920    AC_DEFINE(ENABLE_LLVM_RUNTIME, 1, [Runtime support code for llvm enabled])
2921 fi
2922 AM_CONDITIONAL(ENABLE_LLVM_RUNTIME, [test x$enable_llvm_runtime = xyes])
2923
2924 TARGET="unknown"
2925 ACCESS_UNALIGNED="yes"
2926
2927 LIBC="libc.so.6"
2928 INTL="libc.so.6"
2929 SQLITE="libsqlite.so.0"
2930 SQLITE3="libsqlite3.so.0"
2931 X11="libX11.so"
2932 GDKX11="libgdk-x11-2.0.so.0"
2933 GTKX11="libgtk-x11-2.0.so.0"
2934 XINERAMA="libXinerama.so.1"
2935
2936 sizeof_register="SIZEOF_VOID_P"
2937
2938 jit_wanted=true
2939 boehm_supported=true
2940 BTLS_SUPPORTED=no
2941 BTLS_PLATFORM=
2942 case "$host" in
2943         mips*)
2944                 TARGET=MIPS;
2945                 arch_target=mips;
2946                 with_tls=pthread;
2947                 ACCESS_UNALIGNED="no"
2948
2949                 AC_MSG_CHECKING(for mips n32)
2950                 AC_TRY_COMPILE([],[
2951                 #if _MIPS_SIM != _ABIN32
2952                 #error Not mips n32
2953                 #endif
2954                 return 0;
2955                 ],[
2956                 AC_MSG_RESULT(yes)
2957                 sizeof_register=8
2958                 ],[
2959                 AC_MSG_RESULT(no)
2960                 ])
2961                 ;;
2962         i*86-*-*)
2963                 TARGET=X86;
2964                 arch_target=x86;
2965                 case $host_os in
2966                   solaris*)
2967                         LIBC="libc.so"
2968                         INTL="libintl.so"
2969                         if test "x$ac_cv_sizeof_void_p" = "x8"; then
2970                                 TARGET=AMD64
2971                                 arch_target=amd64
2972                         fi
2973
2974                         # On solaris 10 x86, gcc prints a warning saying 'visibility attribute not supported on this configuration; ignored', but linking fails. A test case:
2975                         # int astruct __attribute__ ((visibility ("hidden")));
2976                         # void foo ()
2977                         # {
2978                         #       void *p = &astruct;
2979                         # }
2980                         # gcc -fPIC --shared -o libfoo.so foo.c
2981                         # yields:
2982                         # foo.c:6: warning: visibility attribute not supported in this configuration; ignored
2983                         # ld: fatal: relocation error: R_386_GOTOFF: file /var/tmp//ccxYR96k.o: symbol astruct: relocation must bind locally
2984                         have_visibility_hidden=no
2985                         ;;
2986                   mingw*|cygwin*)
2987                         have_visibility_hidden=no                 
2988                         ;;
2989                   haiku*)
2990                         LIBC=libroot.so
2991                         ;;
2992                   linux*)
2993                         AOT_SUPPORTED="yes"
2994                         BTLS_SUPPORTED=yes
2995                         BTLS_PLATFORM=i386
2996                         ;;
2997                   darwin*)
2998                         AOT_SUPPORTED="yes"
2999                         BTLS_SUPPORTED=yes
3000                         BTLS_PLATFORM=i386
3001                         ;;
3002                   openbsd*|freebsd*|kfreebsd-gnu*)
3003                         ;;
3004                 esac
3005                 ;;
3006         x86_64-*-* | amd64-*-*)
3007                 TARGET=AMD64;
3008                 arch_target=amd64;
3009                 if test "x$ac_cv_sizeof_void_p" = "x4"; then
3010                         AC_DEFINE(__mono_ilp32__, 1, [64 bit mode with 4 byte longs and pointers])
3011                         sizeof_register=8
3012                 fi
3013                 case $host_os in
3014                   linux*)
3015                         AOT_SUPPORTED="yes"
3016                         BTLS_SUPPORTED=yes
3017                         BTLS_PLATFORM=x86_64
3018                         ;;
3019                   darwin*)
3020                         AOT_SUPPORTED="yes"
3021                         BTLS_SUPPORTED=yes
3022                         BTLS_PLATFORM=x86_64
3023                         ;;
3024                   openbsd*|freebsd*|kfreebsd-gnu*)
3025                         ;;
3026                   mingw*)
3027                         ;;
3028                 esac
3029                 case "$host" in
3030                         x86_64-*-nacl*)
3031                                 AC_DEFINE(__mono_ilp32__, 1, [64 bit mode with 4 byte longs and pointers])
3032                                 sizeof_register=8
3033                                 ;;
3034                 esac
3035                 ;;
3036         ia64-*-*)
3037                 TARGET=IA64
3038                 arch_target=ia64
3039                 ACCESS_UNALIGNED="no"
3040                 LIBC="libc.so.6.1"
3041                 INTL="libc.so.6.1"
3042                 AC_CHECK_LIB(unwind, _U_dyn_register, [], [AC_MSG_ERROR(library libunwind not found)])
3043                 libmono_ldflags="-lunwind"
3044                 ;;
3045         sparc*-*-*)
3046                 if test "x$ac_cv_sizeof_void_p" = "x8"; then
3047                    TARGET=SPARC64
3048                 else
3049                         TARGET=SPARC
3050                 fi
3051                 arch_target=sparc;
3052                 ACCESS_UNALIGNED="no"
3053                 case $host_os in
3054                   linux*) ;;
3055                   *)
3056                         LIBC="libc.so"
3057                         INTL="libintl.so"
3058                 esac
3059                 if test x"$GCC" = xyes; then
3060                         # We don't support v8 cpus
3061                         CFLAGS="$CFLAGS -Wno-cast-align -mcpu=v9"
3062                 fi
3063                 if test x"$AR" = xfalse; then
3064                         AC_MSG_ERROR([The required utility 'ar' is not found in your PATH. Usually it can be found in /usr/ccs/bin.])
3065                 fi
3066                 ;;
3067         *-mingw*|*-*-cygwin*)
3068                 # When this is enabled, it leads to very strange crashes at runtime (gcc-3.4.4)
3069                 have_visibility_hidden=no
3070                 INTL="intl"
3071                 ;;
3072         macppc-*-openbsd* | powerpc*-*-linux* | powerpc-*-openbsd* | \
3073         powerpc-*-sysv* | powerpc-*-darwin* | powerpc-*-netbsd* | powerpc-*-freebsd* )
3074                 if test "x$ac_cv_sizeof_void_p" = "x8"; then
3075                         TARGET=POWERPC64;
3076                         CPPFLAGS="$CPPFLAGS -D__mono_ppc__ -D__mono_ppc64__"
3077                         CFLAGS="$CFLAGS -mminimal-toc"
3078                 else
3079                         TARGET=POWERPC;
3080                         CPPFLAGS="$CPPFLAGS -D__mono_ppc__"
3081                 fi
3082                 arch_target=ppc;
3083                 case $host_os in
3084                   linux*|darwin*)
3085                         ;;
3086                 esac
3087                 ;;
3088         armv7k-*-darwin*)
3089                 TARGET=ARM;
3090                 TARGET_SYS=WATCHOS
3091                 arch_target=arm;
3092                 arm_fpu=VFP_HARD
3093                 ACCESS_UNALIGNED="no"
3094                 CPPFLAGS="$CPPFLAGS -D__ARM_EABI__"
3095                 ;;
3096
3097         arm*-darwin*)
3098                 TARGET=ARM;
3099                 arch_target=arm;
3100                 ACCESS_UNALIGNED="no"
3101                 CPPFLAGS="$CPPFLAGS -D__ARM_EABI__"
3102                 ;;
3103         arm*-linux*)
3104                 TARGET=ARM;
3105                 arch_target=arm;
3106                 ACCESS_UNALIGNED="no"
3107                 AOT_SUPPORTED="yes"
3108                 CPPFLAGS="$CPPFLAGS -D__ARM_EABI__"
3109                 ;;
3110         arm*-netbsd*-eabi*)
3111                 TARGET=ARM;
3112                 arch_target=arm;
3113                 ACCESS_UNALIGNED="no"
3114                 CPPFLAGS="$CPPFLAGS -D__ARM_EABI__"
3115                 ;;
3116 # TODO: make proper support for NaCl host.
3117 #        arm*-*nacl)
3118 #               TARGET=ARM;
3119 #               arch_target=arm;
3120 #               ACCESS_UNALIGNED="no"
3121 #               AOT_SUPPORTED="no"
3122 #               ;;
3123         aarch64-*)
3124                 # https://lkml.org/lkml/2012/7/15/133
3125                 TARGET=ARM64
3126                 arch_target=arm64
3127                 boehm_supported=false
3128                 AOT_SUPPORTED="yes"
3129                 ;;
3130         s390x-*-linux*)
3131                 TARGET=S390X;
3132                 arch_target=s390x;
3133                 ACCESS_UNALIGNED="yes"
3134                 CFLAGS="$CFLAGS -mbackchain -D__USE_STRING_INLINES"
3135                 ;;
3136 esac
3137
3138 HOST=$TARGET
3139
3140 if test "x$host" != "x$target"; then
3141    AC_DEFINE(MONO_CROSS_COMPILE,1,[The runtime is compiled for cross-compiling mode])
3142    enable_mcs_build=no
3143    BTLS_SUPPORTED=no
3144    case "$target" in
3145    arm*-darwin*)
3146                 TARGET=ARM;
3147                 arch_target=arm;
3148                 ACCESS_UNALIGNED="no"
3149                 CPPFLAGS="$CPPFLAGS -D__ARM_EABI__"
3150                 # Can't use tls, since it depends on the runtime detection of tls offsets
3151                 # in mono-compiler.h
3152                 with_tls=pthread
3153                 case "$target" in
3154                 armv7k-*)
3155                         arm_fpu=VFP_HARD
3156                         AC_DEFINE(TARGET_WATCHOS, 1, [...])
3157                         ;;
3158                 esac            
3159                 ;;
3160    powerpc64-ps3-linux-gnu)
3161                 TARGET=POWERPC64
3162                 arch_target=powerpc64
3163                 AC_DEFINE(TARGET_PS3, 1, [...])
3164                 # It would be better to just use TARGET_POWERPC64, but lots of code already
3165                 # uses this define
3166                 AC_DEFINE(__mono_ppc64__, 1, [...])
3167                 AC_DEFINE(__mono_ilp32__, 1, [64 bit mode with 4 byte longs and pointers])
3168                 sizeof_register=8
3169                 target_byte_order=G_BIG_ENDIAN
3170                 ;;
3171    powerpc64-xbox360-linux-gnu)
3172                 TARGET=POWERPC64
3173                 arch_target=powerpc64
3174                 AC_DEFINE(TARGET_XBOX360, 1, [...])
3175                 # It would be better to just use TARGET_POWERPC64, but lots of code already
3176                 # uses this define
3177                 sizeof_register=8
3178                 target_byte_order=G_BIG_ENDIAN
3179                 ;;
3180    x86_64-*-nacl)
3181                 TARGET=AMD64
3182                 arch_target=amd64
3183                 AC_DEFINE(TARGET_AMD64, 1, [...])
3184                 AC_DEFINE(__mono_ilp32__, 1, [64 bit mode with 4 byte longs and pointers])
3185                 sizeof_register=8
3186                 ;;
3187 # TODO: make proper support for NaCl target.
3188 #   arm*-*nacl)
3189 #               TARGET=ARM
3190 #               arch_target=arm
3191 #               AC_DEFINE(TARGET_ARM, 1, [...])
3192 #               ACCESS_UNALIGNED="no"
3193 #               sizeof_register=4
3194 #               CPPFLAGS="$CPPFLAGS \
3195 #                    -D__ARM_EABI__ \
3196 #                    -D__arm__ \
3197 #                    -D__portable_native_client__ \
3198 #                    -Dtimezone=_timezone \
3199 #                    -DDISABLE_SOCKETS \
3200 #                    -DDISABLE_ATTACH \
3201 #                    -DUSE_NEWLIB"
3202                 # Can't use tls, since it depends on the runtime detection of tls offsets
3203                 # in mono-compiler.h
3204 #               with_tls=pthread
3205 #               ;;
3206    i686-*-nacl)
3207                 TARGET=X86
3208                 arch_target=x86
3209                 AC_DEFINE(TARGET_X86, 1, [...])
3210                 sizeof_register=4
3211                 ;;
3212    arm*-linux-*)
3213                 TARGET=ARM;
3214                 arch_target=arm;
3215                 AC_DEFINE(TARGET_ARM, 1, [...])
3216                 AC_DEFINE(TARGET_ANDROID, 1, [...])
3217                 ACCESS_UNALIGNED="no"
3218                 CPPFLAGS="$CPPFLAGS -D__ARM_EABI__"
3219                 # Can't use tls, since it depends on the runtime detection of tls offsets
3220                 # in mono-compiler.h
3221                 with_tls=pthread
3222                 target_mach=no
3223                 case "$target" in
3224                 armv7l-unknown-linux-gnueabi*)
3225                         # TEGRA
3226                         CPPFLAGS="$CPPFLAGS"
3227                         ;;
3228                 armv5-*-linux-androideabi*)
3229                         CPPFLAGS="$CPPFLAGS"
3230                         ;;
3231                 esac
3232                 ;;
3233    arm*-netbsd*-eabi*)
3234                 TARGET=ARM;
3235                 arch_target=arm;
3236                 AC_DEFINE(TARGET_ARM, 1, [...])
3237                 ACCESS_UNALIGNED="no"
3238                 CPPFLAGS="$CPPFLAGS -D__ARM_EABI__"
3239                 # Can't use tls, since it depends on the runtime detection of tls offsets
3240                 # in mono-compiler.h
3241                 with_tls=pthread
3242                 target_mach=no
3243                 ;;
3244    i686*-linux-*)
3245                 TARGET=X86;
3246                 arch_target=x86;
3247                 AC_DEFINE(TARGET_X86, 1, [...])
3248                 AC_DEFINE(TARGET_ANDROID, 1, [...])
3249                 CPPFLAGS="$CPPFLAGS"
3250                 # Can't use tls, since it depends on the runtime detection of tls offsets
3251                 # in mono-compiler.h            
3252                 with_tls=pthread
3253                 target_mach=no
3254                 ;;
3255    x86_64*-linux-*)
3256                 TARGET=AMD64;
3257                 arch_target=amd64;
3258                 AC_DEFINE(TARGET_AMD64, 1, [...])
3259                 AC_DEFINE(TARGET_ANDROID, 1, [...])
3260                 CPPFLAGS="$CPPFLAGS"
3261                 # Can't use tls, since it depends on the runtime detection of tls offsets
3262                 # in mono-compiler.h
3263                 with_tls=pthread
3264                 target_mach=no
3265                 ;;
3266    x86_64-ps4-freebsd)
3267                 TARGET=AMD64;
3268                 arch_target=amd64;
3269                 AC_DEFINE(TARGET_AMD64, 1, [...])
3270                 AC_DEFINE(TARGET_PS4, 1, [...])
3271                 AC_DEFINE(DISABLE_HW_TRAPS, 1, [...])
3272                 CPPFLAGS="$CPPFLAGS"
3273                 # Can't use tls, since it depends on the runtime detection of tls offsets
3274                 # in mono-compiler.h
3275                 with_tls=pthread
3276                 target_mach=no
3277                 target_win32=no
3278                 ;;
3279    aarch64*-linux-*)
3280                 TARGET=ARM64;
3281                 arch_target=arm64;
3282                 AC_DEFINE(TARGET_ARM64, 1, [...])
3283                 AC_DEFINE(TARGET_ANDROID, 1, [...])
3284                 CPPFLAGS="$CPPFLAGS"
3285                 # Can't use tls, since it depends on the runtime detection of tls offsets
3286                 # in mono-compiler.h
3287                 with_tls=pthread
3288                 target_mach=no
3289                 ;;
3290         aarch64-*)
3291                 TARGET=ARM64
3292                 ;;
3293         *)
3294                 AC_MSG_ERROR([Cross compiling is not supported for target $target])
3295         esac
3296 fi
3297
3298 case "$TARGET" in
3299 X86)
3300         AC_DEFINE(TARGET_X86, 1, [...])
3301         ;;
3302 AMD64)
3303         AC_DEFINE(TARGET_AMD64, 1, [...])
3304         ;;
3305 ARM)
3306         AC_DEFINE(TARGET_ARM, 1, [...])
3307         ;;
3308 ARM64)
3309         AC_DEFINE(TARGET_ARM64, 1, [...])
3310         ;;
3311 POWERPC)
3312         AC_DEFINE(TARGET_POWERPC, 1, [...])
3313         ;;
3314 POWERPC64)
3315         AC_DEFINE(TARGET_POWERPC, 1, [...])
3316         AC_DEFINE(TARGET_POWERPC64, 1, [...])
3317         ;;
3318 S390X)
3319         AC_DEFINE(TARGET_S390X, 1, [...])
3320         ;;
3321 MIPS)
3322         AC_DEFINE(TARGET_MIPS, 1, [...])
3323         ;;
3324 IA64)
3325         AC_DEFINE(TARGET_IA64, 1, [...])
3326         ;;
3327 SPARC)
3328         AC_DEFINE(TARGET_SPARC, 1, [...])
3329         ;;
3330 SPARC64)
3331         AC_DEFINE(TARGET_SPARC64, 1, [...])
3332         ;;
3333 esac
3334
3335 case "$HOST" in
3336 X86)
3337         AC_DEFINE(HOST_X86, 1, [...])
3338         ;;
3339 AMD64)
3340         AC_DEFINE(HOST_AMD64, 1, [...])
3341         ;;
3342 ARM)
3343         AC_DEFINE(HOST_ARM, 1, [...])
3344         ;;
3345 ARM64)
3346         AC_DEFINE(HOST_ARM64, 1, [...])
3347         ;;
3348 POWERPC)
3349         AC_DEFINE(HOST_POWERPC, 1, [...])
3350         ;;
3351 POWERPC64)
3352         AC_DEFINE(HOST_POWERPC, 1, [...])
3353         AC_DEFINE(HOST_POWERPC64, 1, [...])
3354         ;;
3355 S390X)
3356         AC_DEFINE(HOST_S390X, 1, [...])
3357         ;;
3358 MIPS)
3359         AC_DEFINE(HOST_MIPS, 1, [...])
3360         ;;
3361 IA64)
3362         AC_DEFINE(HOST_IA64, 1, [...])
3363         ;;
3364 SPARC)
3365         AC_DEFINE(HOST_SPARC, 1, [...])
3366         ;;
3367 SPARC64)
3368         AC_DEFINE(HOST_SPARC64, 1, [...])
3369         ;;
3370 esac
3371
3372
3373
3374 dnl *************
3375 dnl *** VTUNE ***
3376 dnl *************
3377
3378 AC_ARG_ENABLE(vtune,[  --enable-vtune   Enable the VTUNE back-end], enable_vtune=$enableval, enable_vtune=no)
3379 AC_ARG_WITH(vtune, [  --with-vtune=<vtune prefix>       Enable jit vtune profiling], enable_vtune=yes,)
3380
3381 AM_CONDITIONAL(HAVE_VTUNE, test x$enable_vtune = xyes)
3382
3383 if test "x$enable_vtune" = "xyes"; then
3384         if test "x$with_vtune" = "x"; then
3385                 VTUNE_PATH=/opt/intel/vtune_amplifier_xe
3386         else
3387                 VTUNE_PATH=$with_vtune
3388         fi
3389         VTUNE_INCLUDE=$VTUNE_PATH/include
3390         case "$TARGET" in
3391         X86)
3392                 VTUNE_LIB=$VTUNE_PATH/lib32
3393                 ;;
3394         AMD64)
3395                 VTUNE_LIB=$VTUNE_PATH/lib64
3396                 ;;
3397         *)
3398                 AC_MSG_ERROR([Unsupported target $TARGET for VTUNE.])
3399                 ;;
3400         esac
3401         if test ! -f $VTUNE_INCLUDE/jitprofiling.h; then
3402                 AC_MSG_ERROR([VTUNE $VTUNE_INCLUDE/jitprofiling.h not found.])
3403         fi
3404         if test ! -f $VTUNE_LIB/libjitprofiling.a; then
3405                 AC_MSG_ERROR([VTUNE $VTUNE_LIB/libjitprofiling.a not found.])
3406         fi
3407
3408         VTUNE_CFLAGS=-I$VTUNE_INCLUDE
3409         VTUNE_LIBS="-L/$VTUNE_LIB/ -ljitprofiling"
3410
3411         AC_SUBST(VTUNE_LIBS)
3412         AC_SUBST(VTUNE_CFLAGS)
3413 fi
3414 dnl Use GCC atomic ops if they work on the target.
3415 if test x$GCC = "xyes"; then
3416         case $TARGET in
3417         X86 | AMD64 | ARM | ARM64 | POWERPC | POWERPC64 | MIPS | S390X | SPARC | SPARC64)
3418                 AC_DEFINE(USE_GCC_ATOMIC_OPS, 1, [...])
3419                 ;;
3420         esac
3421 fi
3422
3423 if test "x$target_mach" = "xyes"; then
3424
3425    if test "x$TARGET_SYS" = "xWATCHOS"; then
3426           AC_DEFINE(TARGET_WATCHOS,1,[The JIT/AOT targets WatchOS])
3427           CPPFLAGS_FOR_LIBGC="$CPPFLAGS_FOR_LIBGC -DTARGET_WATCHOS"
3428           CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC -DTARGET_WATCHOS"
3429           BTLS_SUPPORTED=no
3430    elif test "x$TARGET" = "xARM" -o "x$TARGET" = "xARM64"; then
3431           AC_DEFINE(TARGET_IOS,1,[The JIT/AOT targets iOS])
3432           CPPFLAGS_FOR_LIBGC="$CPPFLAGS_FOR_LIBGC -DTARGET_IOS"
3433           CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC -DTARGET_IOS"
3434           BTLS_SUPPORTED=no
3435    else
3436        AC_TRY_COMPILE([#include "TargetConditionals.h"],[
3437        #if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1
3438        #error fail this for ios
3439        #endif
3440        return 0;
3441        ], [
3442                   AC_DEFINE(TARGET_OSX,1,[The JIT/AOT targets OSX])
3443           CPPFLAGS_FOR_LIBGC="$CPPFLAGS_FOR_LIBGC -DTARGET_OSX"
3444           CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC -DTARGET_OSX"
3445        ], [
3446           AC_DEFINE(TARGET_IOS,1,[The JIT/AOT targets iOS])
3447           CPPFLAGS_FOR_LIBGC="$CPPFLAGS_FOR_LIBGC -DTARGET_IOS"
3448           CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC -DTARGET_IOS"
3449           BTLS_SUPPORTED=no
3450        ])
3451         fi
3452    AC_DEFINE(TARGET_MACH,1,[The JIT/AOT targets Apple platforms])
3453 fi
3454
3455 if test "x$sizeof_register" = "x4"; then
3456    AC_DEFINE(SIZEOF_REGISTER,4,[size of machine integer registers])
3457 elif test "x$sizeof_register" = "x8"; then
3458    AC_DEFINE(SIZEOF_REGISTER,8,[size of machine integer registers])
3459 else
3460    AC_DEFINE(SIZEOF_REGISTER,SIZEOF_VOID_P,[size of machine integer registers])
3461 fi
3462
3463 if test "x$target_byte_order" = "xG_BIG_ENDIAN"; then
3464    AC_DEFINE(TARGET_BYTE_ORDER,G_BIG_ENDIAN,[byte order of target])
3465 elif test "x$target_byte_order" = "xG_LITTLE_ENDIAN"; then
3466    AC_DEFINE(TARGET_BYTE_ORDER,G_LITTLE_ENDIAN,[byte order of target])
3467 else
3468    AC_DEFINE(TARGET_BYTE_ORDER,G_BYTE_ORDER,[byte order of target])
3469 fi
3470
3471 if test "x$have_visibility_hidden" = "xyes"; then
3472    AC_DEFINE(HAVE_VISIBILITY_HIDDEN, 1, [Support for the visibility ("hidden") attribute])
3473 fi
3474
3475 if test "x$have_deprecated" = "xyes"; then
3476    AC_DEFINE(HAVE_DEPRECATED, 1, [Support for the deprecated attribute])
3477 fi
3478
3479 dnl 
3480 dnl Simple Generational checks (sgen)
3481 dnl
3482 SGEN_DEFINES=
3483 AC_ARG_WITH(sgen,                    [  --with-sgen=yes,no             Extra Generational GC, default=yes],[buildsgen=$with_sgen],[buildsgen=yes])
3484 AC_ARG_WITH(sgen-default-concurrent, [  --with-sgen-default-concurrent=yes,no             Use Concurrent GC, default=no],[],[with_sgen_default_concurrent=no])
3485 if test x$buildsgen = xyes; then
3486    AC_DEFINE(HAVE_MOVING_COLLECTOR, 1, [Moving collector])
3487    SGEN_DEFINES="-DHAVE_SGEN_GC"
3488
3489         conc_gc_msg=""
3490    if test x$with_sgen_default_concurrent != xno; then
3491        AC_DEFINE(HAVE_CONC_GC_AS_DEFAULT, 1, [Defaults to concurrent GC])
3492            conc_gc_msg=" (concurrent by default)"
3493    fi
3494
3495    if test "x$gc_msg" = "x"; then
3496       gc_msg="sgen$conc_gc_msg"
3497    else
3498       gc_msg="sgen$conc_gc_msg and $gc_msg"
3499    fi
3500 fi
3501 AC_SUBST(SGEN_DEFINES)
3502 AM_CONDITIONAL(SUPPORT_SGEN, test x$buildsgen = xyes)
3503
3504 jit_status="Building and using the JIT"
3505
3506 libsuffix=".so"
3507
3508 case "$host" in
3509      *-*-darwin*)
3510         libsuffix=".dylib"
3511         LIBC="libc.dylib"
3512         INTL="libintl.dylib"
3513         SQLITE="libsqlite.0.dylib"
3514         SQLITE3="libsqlite3.0.dylib"
3515         X11="libX11.dylib"
3516         GDKX11="libgdk-x11-2.0.dylib"
3517         GTKX11="libgtk-x11-2.0.dylib"
3518         ;;
3519      *-*-*netbsd*)
3520         LIBC="libc.so"
3521         INTL="libintl.so"
3522         SQLITE="libsqlite.so"
3523         SQLITE3="libsqlite3.so"
3524         ;;
3525      *-*-kfreebsd*-gnu)
3526         LIBC="libc.so.0.1"
3527         INTL="libc.so.0.1"
3528         X11="libX11.so.6"
3529         ;;
3530     *-*-*freebsd*)
3531         LIBC="libc.so.7"
3532         INTL="libintl.so"
3533         SQLITE="libsqlite.so"
3534         SQLITE3="libsqlite3.so"
3535         ;;
3536     *-*-*openbsd*)
3537         LIBC="libc.so"
3538         INTL="libintl.so"
3539         SQLITE="libsqlite.so"
3540         SQLITE3="libsqlite3.so"
3541         ;;
3542     *-*-*linux*)
3543         AC_PATH_X
3544         dlsearch_path=`(libtool --config ; echo eval echo \\$sys_lib_dlsearch_path_spec) | sh`
3545         AC_MSG_CHECKING(for the soname of libX11.so)
3546         for i in $x_libraries $dlsearch_path; do
3547                 for r in 4 5 6; do
3548                         if test -f $i/libX11.so.$r; then
3549                                 X11=libX11.so.$r
3550                                 AC_MSG_RESULT($X11)
3551                         fi
3552                 done
3553         done
3554         
3555         if test "x$X11" = "xlibX11.so"; then
3556                 AC_MSG_WARN([Could not find libX11.so. Do you have X.org or XFree86 installed? Assuming libX11.so.6...]);
3557                 X11=libX11.so.6
3558         fi
3559         ;;
3560 esac
3561
3562
3563 AC_SUBST(libsuffix)
3564
3565 AC_ARG_WITH([libgdiplus],
3566         [  --with-libgdiplus=installed|sibling|<path>   Override the libgdiplus used for System.Drawing tests (defaults to installed)],
3567         [], [with_libgdiplus=installed])
3568
3569 # default install location
3570 libgdiplus_install_loc=libgdiplus${libsuffix}
3571 case "$host" in
3572     *-*-*linux*)
3573     libgdiplus_install_loc=libgdiplus${libsuffix}.0
3574     ;;
3575 esac
3576
3577 case $with_libgdiplus in
3578     no|installed)
3579     libgdiplus_loc=
3580     ;;
3581
3582     yes|sibling)
3583     libgdiplus_loc=`cd ../libgdiplus && pwd`/src/libgdiplus.la
3584     ;;
3585
3586     /*) # absolute path, assume it is an install location
3587     libgdiplus_loc=$with_libgdiplus
3588     libgdiplus_install_loc=$with_libgdiplus
3589     ;;
3590
3591     *)
3592     libgdiplus_loc=`pwd`/$with_libgdiplus
3593     ;;
3594 esac
3595 AC_SUBST([libgdiplus_loc])
3596 AC_SUBST([libgdiplus_install_loc])
3597
3598 AC_ARG_ENABLE(icall-symbol-map,[  --enable-icall-symbol-map Generate tables which map icall functions to their C symbols], icall_symbol_map=$enableval, icall_symbol_map=no)
3599 if test "x$icall_symbol_map" = "xyes"; then
3600    AC_DEFINE(ENABLE_ICALL_SYMBOL_MAP, 1, [Icall symbol map enabled])
3601 fi
3602
3603 AC_ARG_ENABLE(icall-export,[  --enable-icall-export Export icall functions], icall_export=$enableval, icall_export=no)
3604 if test "x$icall_export" = "xyes"; then
3605    AC_DEFINE(ENABLE_ICALL_EXPORT, 1, [Icall export enabled])
3606 fi
3607
3608 AC_ARG_ENABLE(icall-tables,[  --disable-icall-tables Disable the runtime lookup of icalls], icall_tables=$enableval, icall_tables=yes)
3609 if test "x$icall_tables" = "xno"; then
3610    AC_DEFINE(DISABLE_ICALL_TABLES, 1, [Icall tables disabled])
3611 fi
3612
3613 if test "x$with_tls" = "x__thread"; then
3614         AC_DEFINE(HAVE_KW_THREAD, 1, [Have __thread keyword])
3615         # Pass the information to libgc
3616         CPPFLAGS="$CPPFLAGS -DUSE_COMPILER_TLS"
3617         AC_MSG_CHECKING(if the tls_model attribute is supported)
3618         AC_TRY_COMPILE([static __thread int foo __attribute__((tls_model("initial-exec")));], [
3619                 ], [
3620                         AC_MSG_RESULT(yes)
3621                         AC_DEFINE(HAVE_TLS_MODEL_ATTR, 1, [tls_model available])
3622                 ], [
3623                         AC_MSG_RESULT(no)
3624         ])
3625 fi
3626
3627 if test ${TARGET} = ARM; then
3628         dnl ******************************************
3629         dnl *** Check to see what FPU is available ***
3630         dnl ******************************************
3631         AC_MSG_CHECKING(which FPU to use)
3632
3633         #
3634         # This is a bit tricky:
3635         #
3636         # if (__ARM_PCS_VFP) {
3637         #       /* mfloat-abi=hard == VFP with hard ABI */
3638         # } elif (!__SOFTFP__) {
3639         #       /* mfloat-abi=softfp == VFP with soft ABI */
3640         # } else {
3641         #       /* mfloat-abi=soft == no VFP */
3642         # }
3643         #
3644         # The exception is iOS (w/ GCC) where none of the above
3645         # are defined (but iOS always uses the 'softfp' ABI).
3646         #
3647         # No support for FPA.
3648         #
3649
3650         fpu=NONE
3651
3652         # iOS GCC always uses the 'softfp' ABI.
3653         if test x"$GCC" = xyes && test x$host_darwin = xyes; then
3654                 fpu=VFP
3655         fi
3656
3657         # Are we using the 'hard' ABI?
3658         if test x$fpu = xNONE; then
3659                 AC_TRY_COMPILE([], [
3660                         #ifndef __ARM_PCS_VFP
3661                         #error "Float ABI is not 'hard'"
3662                         #endif
3663                         return 0;
3664                 ], [
3665                         fpu=VFP_HARD
3666                 ], [
3667                         fpu=NONE
3668                 ])
3669         fi
3670
3671         # No 'hard' ABI. 'soft' or 'softfp'?
3672         if test x$fpu = xNONE; then
3673                 AC_TRY_COMPILE([], [
3674                         #ifdef __SOFTFP__
3675                         #error "Float ABI is not 'softfp'"
3676                         #endif
3677                         return 0;
3678                 ], [
3679                         fpu=VFP
3680                 ], [
3681                         fpu=NONE
3682                 ])
3683         fi
3684
3685         if test x$arm_fpu != x; then
3686            fpu=$arm_fpu
3687         fi
3688
3689         AC_MSG_RESULT($fpu)
3690         CPPFLAGS="$CPPFLAGS -DARM_FPU_$fpu=1"
3691         unset fpu
3692
3693         dnl *********************************************
3694         dnl *** Check which ARM version(s) we can use ***
3695         dnl *********************************************
3696         AC_MSG_CHECKING(which ARM version to use)
3697
3698         AC_TRY_COMPILE([], [
3699                 #if !defined(__ARM_ARCH_5T__) && !defined(__ARM_ARCH_5TE__) && !defined(__ARM_ARCH_5TEJ__)
3700                 #error Not on ARM v5.
3701                 #endif
3702                 return 0;
3703         ], [
3704                 arm_v5=yes
3705
3706                 arm_ver=ARMv5
3707         ], [])
3708
3709         AC_TRY_COMPILE([], [
3710                 #if !defined(__ARM_ARCH_6J__) && !defined(__ARM_ARCH_6ZK__) && !defined(__ARM_ARCH_6K__) && !defined(__ARM_ARCH_6T2__) && !defined(__ARM_ARCH_6M__)
3711                 #error Not on ARM v6.
3712                 #endif
3713                 return 0;
3714         ], [
3715                 arm_v5=yes
3716                 arm_v6=yes
3717
3718                 arm_ver=ARMv6
3719         ], [])
3720
3721         AC_TRY_COMPILE([], [
3722                 #if !defined(__ARM_ARCH_7A__) && !defined(__ARM_ARCH_7R__) && !defined(__ARM_ARCH_7EM__) && !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7S__)
3723                 #error Not on ARM v7.
3724                 #endif
3725                 return 0;
3726         ], [
3727                 arm_v5=yes
3728                 arm_v6=yes
3729                 arm_v7=yes
3730
3731                 arm_ver=ARMv7
3732         ], [])
3733
3734         AC_MSG_RESULT($arm_ver)
3735
3736         if test x$arm_v5 = xyes; then
3737                 AC_DEFINE(HAVE_ARMV5, 1, [ARM v5])
3738                 CPPFLAGS_FOR_LIBGC="$CPPFLAGS_FOR_LIBGC -DHAVE_ARMV5=1"
3739         fi
3740
3741         if test x$arm_v6 = xyes; then
3742                 AC_DEFINE(HAVE_ARMV6, 1, [ARM v6])
3743                 CPPFLAGS_FOR_LIBGC="$CPPFLAGS_FOR_LIBGC -DHAVE_ARMV6=1"
3744         fi
3745
3746         if test x$arm_v7 = xyes; then
3747                 AC_DEFINE(HAVE_ARMV7, 1, [ARM v7])
3748                 CPPFLAGS_FOR_LIBGC="$CPPFLAGS_FOR_LIBGC -DHAVE_ARMV7=1"
3749         fi
3750 fi
3751
3752 if test ${TARGET} = unknown; then
3753         CPPFLAGS="$CPPFLAGS -DNO_PORT"
3754         AC_MSG_WARN("mono has not been ported to $host: some things may not work.")
3755 fi
3756
3757 if test "x$platform_android" = "xyes"; then
3758         case "x${TARGET}" in
3759         xARM)
3760                 case "x$arm_ver" in
3761                 xARMv5)
3762                         BTLS_SUPPORTED=yes
3763                         BTLS_PLATFORM=android-armv5
3764                         ;;
3765                 xARMv6)
3766                         BTLS_SUPPORTED=yes
3767                         BTLS_PLATFORM=android-armv6
3768                         ;;
3769                 xARMv7)
3770                         BTLS_SUPPORTED=yes
3771                         BTLS_PLATFORM=android-armv7
3772                         ;;
3773                 *)
3774                         BTLS_SUPPORTED=no
3775                         ;;
3776                 esac
3777                 ;;
3778         xARM64)
3779                 BTLS_SUPPORTED=yes
3780                 BTLS_PLATFORM=android-v8a
3781                 ;;
3782         xX86)
3783                 BTLS_SUPPORTED=yes
3784                 BTLS_PLATFORM=android-x86
3785                 ;;
3786         xAMD64)
3787                 BTLS_SUPPORTED=yes
3788                 BTLS_PLATFORM=android-x64
3789                 ;;
3790         *)
3791                 BTLS_SUPPORTED=no
3792                 ;;
3793         esac
3794 fi
3795
3796 if test ${ACCESS_UNALIGNED} = no; then
3797         CPPFLAGS="$CPPFLAGS -DNO_UNALIGNED_ACCESS"
3798 fi
3799
3800 case "x$libgc" in
3801         xincluded)
3802                 # Pass CPPFLAGS to libgc configure
3803                 # We should use a separate variable for this to avoid passing useless and
3804                 # potentially problematic defines to libgc (like -D_FILE_OFFSET_BITS=64)
3805                 # This should be executed late so we pick up the final version of CPPFLAGS
3806                 # The problem with this approach, is that during a reconfigure, the main
3807                 # configure scripts gets invoked with these arguments, so we use separate
3808                 # variables understood by libgc's configure to pass CPPFLAGS and CFLAGS.
3809                 TMP_CPPFLAGS="$CPPFLAGS $CPPFLAGS_FOR_LIBGC"
3810                 if test x$TARGET = xSPARC -o x$TARGET = xSPARC64; then
3811                         TMP_CPPFLAGS=`echo $TMP_CPPFLAGS | sed -e 's/-D_FILE_OFFSET_BITS=64//g'`
3812                 fi
3813                 # Don't pass -finstrument-for-thread-suspension in, 
3814                 # if these are instrumented it will be very bad news 
3815                 # (infinite recursion, undefined parking behavior, etc)
3816                 TMP_CPPFLAGS=`echo $TMP_CPPFLAGS | sed -e 's/-finstrument-for-thread-suspension//g'`
3817                 ac_configure_args="$ac_configure_args --disable-embed-check --with-libgc-threads=$libgc_threads $libgc_configure_args \"CPPFLAGS_FOR_LIBGC=$TMP_CPPFLAGS\" \"CFLAGS_FOR_LIBGC=$CFLAGS_FOR_LIBGC\""
3818                 if test "x$support_boehm" = "xyes"; then
3819                         AC_CONFIG_SUBDIRS(libgc)
3820                 fi
3821                 ;;
3822 esac
3823
3824 MALLOC_MEMPOOLS=no
3825 AC_ARG_WITH(malloc_mempools,[  --with-malloc-mempools=yes,no  Use malloc for each single mempool allocation (only for runtime debugging, defaults to no)],[
3826         if test x$with_malloc_mempools = xyes; then
3827                 MALLOC_MEMPOOLS=yes
3828                 AC_DEFINE(USE_MALLOC_FOR_MEMPOOLS,1,[Use malloc for each single mempool allocation])
3829         fi
3830 ])
3831
3832
3833 DISABLE_MCS_DOCS=default
3834 AC_ARG_WITH(mcs_docs,[  --with-mcs-docs=yes,no         If you want to build the documentation under mcs (defaults to yes)],[
3835         if test x$with_mcs_docs != xyes; then
3836                 DISABLE_MCS_DOCS=yes
3837         fi
3838 ])
3839 if test -n "$INSTALL_4_x_TRUE"; then :
3840         DISABLE_MCS_DOCS=yes
3841 fi
3842 if test "x$DISABLE_MCS_DOCS" = "xdefault"; then
3843    DISABLE_MCS_DOCS=$DISABLE_MCS_DOCS_default
3844 fi
3845
3846 AC_ARG_WITH(lazy_gc_thread_creation, [  --with-lazy-gc-thread-creation=yes|no      Enable lazy runtime thread creation, embedding host must do it explicitly (defaults to no)],[
3847         if test x$with_lazy_gc_thread_creation != xno ; then
3848                 AC_DEFINE(LAZY_GC_THREAD_CREATION,1,[Enable lazy gc thread creation by the embedding host.])
3849         fi
3850 ], [with_lazy_gc_thread_creation=no])
3851
3852 AC_ARG_WITH(cooperative_gc, [  --with-cooperative-gc=yes|no      Enable cooperative stop-the-world garbage collection (sgen only) (defaults to no)], [], [with_cooperative_gc=default])
3853
3854 if test x$with_cooperative_gc = xdefault; then
3855         with_cooperative_gc=$with_cooperative_gc_default
3856 fi
3857
3858 if test x$with_cooperative_gc != xno; then
3859         AC_DEFINE(USE_COOP_GC,1,[Enable cooperative stop-the-world garbage collection.])
3860 fi
3861
3862 AM_CONDITIONAL([ENABLE_COOP], [test x$with_cooperative_gc != xno])
3863
3864 AC_ARG_ENABLE(checked_build, [  --enable-checked-build=LIST      To enable checked build (expensive asserts), configure with a comma-separated LIST of checked build modules and then include that same list in the environment variable MONO_CHECK_MODE at runtime. Recognized checked build modules: all, gc, metadata, thread],[
3865
3866         if test x$enable_checked_build != x ; then
3867                 AC_DEFINE(ENABLE_CHECKED_BUILD,1,[Enable checked build])
3868         fi
3869         for feature in `echo "$enable_checked_build" | sed -e "s/,/ /g"`; do
3870                 eval "mono_checked_build_test_enable_$feature='yes'"
3871         done
3872
3873         if test "x$mono_checked_build_test_enable_all" = "xyes"; then
3874                 eval "mono_checked_build_test_enable_gc='yes'"
3875                 eval "mono_checked_build_test_enable_metadata='yes'"
3876                 eval "mono_checked_build_test_enable_thread='yes'"
3877         fi
3878
3879         if test "x$mono_checked_build_test_enable_gc" = "xyes"; then
3880                 AC_DEFINE(ENABLE_CHECKED_BUILD_GC, 1, [Enable GC checked build])
3881         fi
3882
3883         if test "x$mono_checked_build_test_enable_metadata" = "xyes"; then
3884                 AC_DEFINE(ENABLE_CHECKED_BUILD_METADATA, 1, [Enable metadata checked build])
3885         fi
3886
3887         if test "x$mono_checked_build_test_enable_thread" = "xyes"; then
3888                 AC_DEFINE(ENABLE_CHECKED_BUILD_THREAD, 1, [Enable thread checked build])
3889         fi
3890
3891 ], [])
3892
3893 AC_CHECK_HEADER([malloc.h], 
3894                 [AC_DEFINE([HAVE_USR_INCLUDE_MALLOC_H], [1], 
3895                         [Define to 1 if you have /usr/include/malloc.h.])],,)
3896
3897 if test x"$GCC" = xyes; then
3898         # Implicit function declarations are not 64 bit safe
3899         # Do this late, since this causes lots of configure tests to fail
3900         CFLAGS="$CFLAGS -Werror-implicit-function-declaration"
3901         # jay has a lot of implicit declarations
3902         JAY_CFLAGS="-Wno-implicit-function-declaration"
3903 fi
3904
3905 # When --disable-shared is used, libtool transforms libmono-2.0.la into libmono-2.0.so
3906 # instead of libmono-static.a
3907 if test "x$enable_shared" = "xno" -a "x$enable_executables" = "xyes"; then
3908    LIBMONO_LA=libmini-static.la
3909 else
3910    if test x$buildsgen = xyes; then
3911       LIBMONO_LA=libmonosgen-$API_VER.la
3912    else
3913       LIBMONO_LA=libmonoboehm-$API_VER.la
3914    fi
3915 fi
3916 AC_SUBST(LIBMONO_LA)
3917
3918 dnl **************
3919 dnl ***  Btls  ***
3920 dnl **************
3921
3922 AC_ARG_ENABLE(btls, [  --disable-btls             Disable the BoringTls provider], enable_btls=$enableval, enable_btls=$BTLS_SUPPORTED)
3923 AC_ARG_WITH(btls_android_ndk, [  --with-btls-android-ndk        Android NDK for BoringTls])
3924
3925 AM_CONDITIONAL(BTLS, test x$enable_btls = xyes)
3926
3927 btls_android=no
3928 if test "x$enable_btls" = "xyes"; then
3929         AC_PATH_PROG(CMAKE, [cmake], [no], [$PATH:/Applications/CMake.app/Contents/bin:/usr/local/bin])
3930         if test "x$CMAKE" = "xno"; then
3931                 AC_MSG_ERROR("cmake not found")
3932         fi
3933
3934         BTLS_ROOT=`cd $srcdir && pwd`/external/boringssl
3935         AC_SUBST(BTLS_ROOT)
3936
3937         btls_arch=
3938         btls_cflags=
3939         BTLS_CMAKE_ARGS=
3940
3941         case "$BTLS_PLATFORM" in
3942         i386)
3943                 btls_arch=i386
3944                 btls_cflags="-m32"
3945                 case $host_os in
3946                         darwin*)
3947                                 btls_cflags="$btls_cflags -arch i386"
3948                 esac
3949                 ;;
3950         x86_64)
3951                 btls_arch=x86_64
3952                 ;;
3953         android-armv5)
3954                 BTLS_CMAKE_ARGS="-DANDROID_ABI=\"armeabi\" -DANDROID_NATIVE_API_LEVEL=12"
3955                 ;;
3956         android-armv6)
3957                 BTLS_CMAKE_ARGS="-DANDROID_ABI=\"armeabi\" -DANDROID_NATIVE_API_LEVEL=12"
3958                 ;;
3959         android-armv7)
3960                 BTLS_CMAKE_ARGS="-DANDROID_ABI=\"armeabi-v7a\" -DANDROID_NATIVE_API_LEVEL=12"
3961                 ;;
3962         android-v8a)
3963                 BTLS_CMAKE_ARGS="-DANDROID_ABI=\"arm64-v8a\" -DANDROID_NATIVE_API_LEVEL=12"
3964                 ;;
3965         android-x86)
3966                 BTLS_CMAKE_ARGS="-DANDROID_ABI=\"x86\" -DANDROID_NATIVE_API_LEVEL=12"
3967                 ;;
3968         android-x64)
3969                 BTLS_CMAKE_ARGS="-DANDROID_ABI=\"x86_64\" -DANDROID_NATIVE_API_LEVEL=12"
3970                 ;;
3971         *)
3972                 AC_MSG_ERROR(Invalid BTLS platform)
3973         esac
3974
3975         if test "x$platform_android" = "xyes"; then
3976                 btls_android=yes
3977                 BTLS_CMAKE_ARGS="$BTLS_CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=$BTLS_ROOT/util/android-cmake/android.toolchain.cmake"
3978                 if test "x$with_btls_android_ndk" != "x"; then
3979                         BTLS_CMAKE_ARGS="$BTLS_CMAKE_ARGS -DANDROID_NDK=\"$with_btls_android_ndk\""
3980                 fi
3981         fi
3982
3983         if test "x$btls_arch" != "x"; then
3984                 BTLS_CMAKE_ARGS="$BTLS_CMAKE_ARGS -DBTLS_ARCH=\"$btls_arch\""
3985         fi
3986
3987         BTLS_CFLAGS="$CPPFLAGS_FOR_BTLS $btls_cflags"
3988         AC_SUBST(BTLS_ARCH)
3989         AC_SUBST(BTLS_CFLAGS)
3990         AC_SUBST(BTLS_PLATFORM)
3991         AC_SUBST(BTLS_CMAKE_ARGS)
3992
3993         AC_DEFINE(HAVE_BTLS, 1, [BoringTls is supported])
3994 else
3995         enable_btls=no
3996 fi
3997
3998 AM_CONDITIONAL(BTLS_ANDROID, test x$btls_android = xyes)
3999
4000 if test x$DISABLE_MCS_DOCS = xyes; then
4001    docs_dir=""
4002 else
4003    docs_dir=docs
4004 fi
4005 AC_SUBST(docs_dir)
4006
4007 ## Maybe should also disable if mcsdir is invalid.  Let's punt the issue for now.
4008 AM_CONDITIONAL(BUILD_MCS, [test x$cross_compiling = xno && test x$enable_mcs_build != xno])
4009
4010 libmono_ldflags="$libmono_ldflags $LIBS"
4011
4012 AM_CONDITIONAL(MIPS_GCC, test ${TARGET}${ac_cv_prog_gcc} = MIPSyes)
4013 AM_CONDITIONAL(MIPS_SGI, test ${TARGET}${ac_cv_prog_gcc} = MIPSno)
4014 AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
4015 AM_CONDITIONAL(SPARC64, test x$TARGET = xSPARC64)
4016 AM_CONDITIONAL(X86, test x$TARGET = xX86)
4017 AM_CONDITIONAL(AMD64, test x$TARGET = xAMD64)
4018 AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
4019 AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS)
4020 AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
4021 AM_CONDITIONAL(POWERPC64, test x$TARGET = xPOWERPC64)
4022 AM_CONDITIONAL(ARM, test x$TARGET = xARM)
4023 AM_CONDITIONAL(ARM64, test x$TARGET = xARM64)
4024 AM_CONDITIONAL(S390X, test x$TARGET = xS390X)
4025 AM_CONDITIONAL(HOST_X86, test x$HOST = xX86)
4026 AM_CONDITIONAL(HOST_AMD64, test x$HOST = xAMD64)
4027 AM_CONDITIONAL(HOST_ARM, test x$HOST = xARM)
4028 AM_CONDITIONAL(HOST_ARM64, test x$HOST = xARM64)
4029 AM_CONDITIONAL(CROSS_COMPILE, test "x$host" != "x$target")
4030
4031 AC_SUBST(LIBC)
4032 AC_SUBST(INTL)
4033 AC_SUBST(SQLITE)
4034 AC_SUBST(SQLITE3)
4035 AC_SUBST(X11)
4036 AC_SUBST(GDKX11)
4037 AC_SUBST(GTKX11)
4038 AC_SUBST(XINERAMA)
4039 AC_DEFINE_UNQUOTED(MONO_ARCHITECTURE,"$arch_target",[The architecture this is running on])
4040 AC_SUBST(arch_target)
4041 AC_SUBST(CFLAGS)
4042 AC_SUBST(CPPFLAGS)
4043 AC_SUBST(LDFLAGS)
4044
4045 #This must always be defined when building the runtime
4046 AC_DEFINE(MONO_INSIDE_RUNTIME,1, [Disable banned functions from being used by the runtime])
4047
4048 mono_build_root=`pwd`
4049 AC_SUBST(mono_build_root)
4050
4051 mono_runtime=mono/mini/mono
4052 AC_SUBST(mono_runtime)
4053
4054 mono_cfg_root=$mono_build_root/runtime
4055 if test x$host_win32 = xyes; then
4056   if test "x$cross_compiling" = "xno"; then
4057     mono_cfg_dir=`cygpath -w -a $mono_cfg_root`\\etc
4058   else
4059     mono_cfg_dir=`echo $mono_cfg_root | tr '/' '\\'`\\etc
4060   fi
4061 else
4062   mono_cfg_dir=$mono_cfg_root/etc
4063 fi
4064 AC_SUBST(mono_cfg_dir)
4065
4066 AC_CONFIG_FILES([po/mcs/Makefile.in])
4067
4068 AC_CONFIG_FILES([runtime/mono-wrapper],[chmod +x runtime/mono-wrapper])
4069 AC_CONFIG_FILES([runtime/monodis-wrapper],[chmod +x runtime/monodis-wrapper])
4070
4071 AC_CONFIG_COMMANDS([runtime/etc/mono/1.0/machine.config],
4072 [   depth=../../../..
4073     case $srcdir in
4074     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
4075     .) reldir=$depth ;;
4076     *) reldir=$depth/$srcdir ;;
4077     esac
4078     $ac_aux_dir/install-sh -d runtime/etc/mono/1.0
4079     cd runtime/etc/mono/1.0
4080     rm -f machine.config
4081     $LN_S $reldir/data/net_1_1/machine.config machine.config
4082     cd $depth
4083 ],[LN_S='$LN_S'])
4084
4085 AC_CONFIG_COMMANDS([runtime/etc/mono/2.0/machine.config],
4086 [   depth=../../../..
4087     case $srcdir in
4088     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
4089     .) reldir=$depth ;;
4090     *) reldir=$depth/$srcdir ;;
4091     esac
4092     $ac_aux_dir/install-sh -d runtime/etc/mono/2.0
4093     cd runtime/etc/mono/2.0
4094     rm -f machine.config
4095     $LN_S $reldir/data/net_2_0/machine.config machine.config
4096     cd $depth
4097 ],[LN_S='$LN_S'])
4098
4099 AC_CONFIG_COMMANDS([runtime/etc/mono/2.0/web.config],
4100 [   depth=../../../..
4101     case $srcdir in
4102     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
4103     .) reldir=$depth ;;
4104     *) reldir=$depth/$srcdir ;;
4105     esac
4106     $ac_aux_dir/install-sh -d runtime/etc/mono/2.0
4107     cd runtime/etc/mono/2.0
4108     rm -f web.config
4109     $LN_S $reldir/data/net_2_0/web.config web.config
4110     cd $depth
4111 ],[LN_S='$LN_S'])
4112
4113 AC_CONFIG_COMMANDS([runtime/etc/mono/browscap.ini],
4114 [   depth=../../..
4115     case $srcdir in
4116     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
4117     .) reldir=$depth ;;
4118     *) reldir=$depth/$srcdir ;;
4119     esac
4120     $ac_aux_dir/install-sh -d runtime/etc/mono/
4121     cd runtime/etc/mono/
4122     rm -f browscap.ini
4123     $LN_S $reldir/data/browscap.ini browscap.ini
4124     cd $depth
4125 ],[LN_S='$LN_S'])
4126
4127 AC_CONFIG_COMMANDS([runtime/etc/mono/2.0/Browsers/Compat.browser],
4128 [   depth=../../../../..
4129     case $srcdir in
4130     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
4131     .) reldir=$depth ;;
4132     *) reldir=$depth/$srcdir ;;
4133     esac
4134     $ac_aux_dir/install-sh -d runtime/etc/mono/2.0/Browsers/
4135     cd runtime/etc/mono/2.0/Browsers
4136     rm -f Compat.browser
4137     $LN_S $reldir/data/Browsers/Compat.browser Compat.browser
4138     cd $depth
4139 ],[LN_S='$LN_S'])
4140
4141 AC_CONFIG_COMMANDS([runtime/etc/mono/4.0/Browsers/Compat.browser],
4142 [   depth=../../../../..
4143     case $srcdir in
4144     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
4145     .) reldir=$depth ;;
4146     *) reldir=$depth/$srcdir ;;
4147     esac
4148     $ac_aux_dir/install-sh -d runtime/etc/mono/4.0/Browsers/
4149     cd runtime/etc/mono/4.0/Browsers
4150     rm -f Compat.browser
4151     $LN_S $reldir/data/Browsers/Compat.browser Compat.browser
4152     cd $depth
4153 ],[LN_S='$LN_S'])
4154
4155 AC_CONFIG_COMMANDS([runtime/etc/mono/4.5/Browsers/Compat.browser],
4156 [   depth=../../../../..
4157     case $srcdir in
4158     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
4159     .) reldir=$depth ;;
4160     *) reldir=$depth/$srcdir ;;
4161     esac
4162     $ac_aux_dir/install-sh -d runtime/etc/mono/4.5/Browsers/
4163     cd runtime/etc/mono/4.5/Browsers
4164     rm -f Compat.browser
4165     $LN_S $reldir/data/Browsers/Compat.browser Compat.browser
4166     cd $depth
4167 ],[LN_S='$LN_S'])
4168
4169 AC_CONFIG_COMMANDS([runtime/etc/mono/4.0/machine.config],
4170 [   depth=../../../..
4171     case $srcdir in
4172     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
4173     .) reldir=$depth ;;
4174     *) reldir=$depth/$srcdir ;;
4175     esac
4176     $ac_aux_dir/install-sh -d runtime/etc/mono/4.0
4177     cd runtime/etc/mono/4.0
4178     rm -f machine.config
4179     $LN_S $reldir/data/net_4_0/machine.config machine.config
4180     cd $depth
4181 ],[LN_S='$LN_S'])
4182
4183 AC_CONFIG_COMMANDS([runtime/etc/mono/4.0/web.config],
4184 [   depth=../../../..
4185     case $srcdir in
4186     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
4187     .) reldir=$depth ;;
4188     *) reldir=$depth/$srcdir ;;
4189     esac
4190     $ac_aux_dir/install-sh -d runtime/etc/mono/4.0
4191     cd runtime/etc/mono/4.0
4192     rm -f web.config
4193     $LN_S $reldir/data/net_4_0/web.config web.config
4194     cd $depth
4195 ],[LN_S='$LN_S'])
4196
4197 AC_CONFIG_COMMANDS([runtime/etc/mono/4.5/machine.config],
4198 [   depth=../../../..
4199     case $srcdir in
4200     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
4201     .) reldir=$depth ;;
4202     *) reldir=$depth/$srcdir ;;
4203     esac
4204     $ac_aux_dir/install-sh -d runtime/etc/mono/4.5
4205     cd runtime/etc/mono/4.5
4206     rm -f machine.config
4207     $LN_S $reldir/data/net_4_5/machine.config machine.config
4208     cd $depth
4209 ],[LN_S='$LN_S'])
4210
4211 AC_CONFIG_COMMANDS([runtime/etc/mono/4.5/web.config],
4212 [   depth=../../../..
4213     case $srcdir in
4214     [[\\/$]]* | ?:[[\\/]]* ) reldir=$srcdir ;;
4215     .) reldir=$depth ;;
4216     *) reldir=$depth/$srcdir ;;
4217     esac
4218     $ac_aux_dir/install-sh -d runtime/etc/mono/4.5
4219     cd runtime/etc/mono/4.5
4220     rm -f web.config
4221     $LN_S $reldir/data/net_4_5/web.config web.config
4222     cd $depth
4223 ],[LN_S='$LN_S'])
4224
4225 AC_CONFIG_COMMANDS([quiet-libtool], [sed -e 's/echo "copying selected/# "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])
4226 AC_CONFIG_COMMANDS([nolock-libtool], [sed -e 's/lock_old_archive_extraction=yes/lock_old_archive_extraction=no/g' < libtool > libtool.tmp && mv libtool.tmp libtool && chmod a+x libtool])
4227
4228 AC_OUTPUT([
4229 Makefile
4230 mono-uninstalled.pc
4231 acceptance-tests/Makefile
4232 llvm/Makefile
4233 scripts/mono-find-provides
4234 scripts/mono-find-requires
4235 mono/Makefile
4236 mono/btls/Makefile
4237 mono/utils/Makefile
4238 mono/metadata/Makefile
4239 mono/dis/Makefile
4240 mono/cil/Makefile
4241 mono/arch/Makefile
4242 mono/arch/x86/Makefile
4243 mono/arch/amd64/Makefile
4244 mono/arch/ppc/Makefile
4245 mono/arch/sparc/Makefile
4246 mono/arch/s390x/Makefile
4247 mono/arch/arm/Makefile
4248 mono/arch/arm64/Makefile
4249 mono/arch/ia64/Makefile
4250 mono/arch/mips/Makefile
4251 mono/sgen/Makefile
4252 mono/tests/Makefile
4253 mono/tests/tests-config
4254 mono/tests/assemblyresolve/Makefile
4255 mono/tests/gc-descriptors/Makefile
4256 mono/unit-tests/Makefile
4257 mono/benchmark/Makefile
4258 mono/io-layer/Makefile
4259 mono/mini/Makefile
4260 mono/profiler/Makefile
4261 m4/Makefile
4262 ikvm-native/Makefile
4263 scripts/Makefile
4264 man/Makefile
4265 docs/Makefile
4266 data/Makefile
4267 data/net_2_0/Makefile
4268 data/net_4_0/Makefile
4269 data/net_4_5/Makefile
4270 data/net_2_0/Browsers/Makefile
4271 data/net_4_0/Browsers/Makefile
4272 data/net_4_5/Browsers/Makefile
4273 data/mint.pc
4274 data/mono-2.pc
4275 data/monosgen-2.pc
4276 data/mono.pc
4277 data/mono-cairo.pc
4278 data/mono-nunit.pc
4279 data/mono-options.pc
4280 data/mono-lineeditor.pc
4281 data/monodoc.pc
4282 data/dotnet.pc
4283 data/dotnet35.pc
4284 data/wcf.pc
4285 data/cecil.pc
4286 data/system.web.extensions_1.0.pc
4287 data/system.web.extensions.design_1.0.pc
4288 data/system.web.mvc.pc
4289 data/system.web.mvc2.pc
4290 data/system.web.mvc3.pc
4291 data/aspnetwebstack.pc
4292 data/reactive.pc
4293 samples/Makefile
4294 support/Makefile
4295 data/config
4296 tools/Makefile
4297 tools/locale-builder/Makefile
4298 tools/sgen/Makefile
4299 tools/monograph/Makefile
4300 tools/pedump/Makefile
4301 runtime/Makefile
4302 msvc/Makefile
4303 po/Makefile
4304 ])
4305
4306 # Update all submodules recursively to ensure everything is checked out
4307 $srcdir/scripts/update_submodules
4308
4309 if test x$host_win32 = xyes; then
4310    # Get rid of 'cyg' prefixes in library names
4311    sed -e "s/\/cyg\//\/\//" libtool > libtool.new; mv libtool.new libtool; chmod 755 libtool
4312    # libtool seems to inherit -mno-cygwin from our CFLAGS, and uses it to compile its executable
4313    # wrapper scripts which use exec(). gcc has no problem compiling+linking this, but the resulting
4314    # executable doesn't work...
4315    sed -e "s,-mno-cygwin,,g" libtool > libtool.new; mv libtool.new libtool; chmod 755 libtool
4316 fi
4317
4318 if test x$host_darwin = xyes; then
4319    # This doesn't seem to be required and it slows down parallel builds
4320    sed -e 's,lock_old_archive_extraction=yes,lock_old_archive_extraction=no,g' < libtool > libtool.new && mv libtool.new libtool && chmod +x libtool
4321 fi
4322
4323 (
4324   case $prefix in
4325   NONE) prefix=$ac_default_prefix ;;
4326   esac
4327   case $exec_prefix in
4328   NONE) exec_prefix='${prefix}' ;;
4329   esac
4330
4331   #
4332   # If we are cross compiling, we don't build in the mcs/ tree.  Let us not clobber
4333   # any existing config.make.  This allows people to share the same source tree
4334   # with different build directories, one native and one cross
4335   #
4336   if test x$cross_compiling = xno && test x$enable_mcs_build != xno; then
4337
4338     test -w $mcs_topdir/build || chmod +w $mcs_topdir/build
4339
4340     echo "prefix=$prefix" > $mcs_topdir/build/config.make
4341     echo "exec_prefix=$exec_prefix" >> $mcs_topdir/build/config.make
4342     echo "sysconfdir=$sysconfdir" >> $mcs_topdir/build/config.make
4343     echo 'mono_libdir=${exec_prefix}/lib' >> $mcs_topdir/build/config.make
4344     echo 'IL_FLAGS = /debug' >> $mcs_topdir/build/config.make
4345     echo "RUNTIME = $mono_build_root/runtime/mono-wrapper" >> $mcs_topdir/build/config.make
4346     echo "ILDISASM = $mono_build_root/runtime/monodis-wrapper" >> $mcs_topdir/build/config.make
4347     echo "JAY_CFLAGS = $JAY_CFLAGS" >> $mcs_topdir/build/config.make
4348
4349     case $INSTALL in
4350     [[\\/$]]* | ?:[[\\/]]* ) mcs_INSTALL=$INSTALL ;;
4351     *) mcs_INSTALL=$mono_build_root/$INSTALL ;;
4352     esac
4353
4354     echo "INSTALL = $mcs_INSTALL" >> $mcs_topdir/build/config.make
4355
4356     export VERSION
4357     [myver=$($AWK 'BEGIN {
4358       split (ENVIRON["VERSION"] ".0.0.0", vsplit, ".")
4359       if(length(vsplit [1]) > 4) {
4360         split (substr(ENVIRON["VERSION"], 0, 4) "." substr(ENVIRON["VERSION"], 5) ".0.0", vsplit, ".")
4361       }
4362       print vsplit [1] "." vsplit [2] "." vsplit [3] "." vsplit [4]
4363     }')]
4364
4365     echo "MONO_VERSION = $myver" >> $mcs_topdir/build/config.make
4366
4367     if test x$host_darwin = xyes; then
4368       echo "PLATFORM = darwin" >> $mcs_topdir/build/config.make
4369     fi
4370
4371     if test "x$PLATFORM_AOT_SUFFIX" != "x"; then
4372       echo "PLATFORM_AOT_SUFFIX = $PLATFORM_AOT_SUFFIX" >> $mcs_topdir/build/config.make
4373     fi
4374
4375         if test x$AOT_SUPPORTED = xyes -a x$enable_system_aot = xdefault; then
4376            enable_system_aot=yes
4377         fi
4378
4379     if test x$host_win32 = xno -a x$enable_system_aot = xyes; then
4380       echo "ENABLE_AOT = 1" >> $mcs_topdir/build/config.make
4381     fi
4382
4383     if test x$DISABLE_MCS_DOCS = xyes; then
4384       echo "DISABLE_MCS_DOCS = yes" >> $mcs_topdir/build/config.make
4385     fi
4386
4387     if test x$has_extension_module != xno; then
4388         echo "EXTENSION_MODULE = 1" >> $srcdir/$mcsdir/build/config.make
4389     fi
4390     
4391     echo "DEFAULT_PROFILE = $default_profile" >> $srcdir/$mcsdir/build/config.make
4392     
4393     if test "x$test_bcl_opt" = "xyes"; then    
4394       echo "BCL_OPTIMIZE = 1" >> $srcdir/$mcsdir/build/config.make
4395     fi
4396
4397     if test "x$AOT_BUILD_FLAGS" != "x" ; then
4398       echo "AOT_RUN_FLAGS=$AOT_RUN_FLAGS" >> $srcdir/$mcsdir/build/config.make
4399       echo "AOT_BUILD_FLAGS=$AOT_BUILD_FLAGS" >> $srcdir/$mcsdir/build/config.make
4400     fi
4401
4402   fi
4403
4404 )
4405
4406 libgdiplus_msg=${libgdiplus_loc:-assumed to be installed}
4407
4408 btls_platform_string=
4409 if test x$enable_btls = xyes; then
4410         if test x$btls_android = xyes; then
4411                 btls_platform_string=" (android:$BTLS_PLATFORM)"
4412         else
4413                 btls_platform_string=" ($BTLS_PLATFORM)"
4414         fi
4415 fi
4416
4417 echo "
4418         mcs source:    $mcsdir
4419
4420    Engine:
4421         Host:          $host
4422         Target:        $target
4423         GC:            $gc_msg 
4424         TLS:           $with_tls
4425         SIGALTSTACK:   $with_sigaltstack
4426         Engine:        $jit_status
4427         BigArrays:     $enable_big_arrays
4428         DTrace:        $enable_dtrace
4429         LLVM Back End: $enable_llvm (dynamically loaded: $enable_loadedllvm)
4430
4431    Libraries:
4432         .NET 4.x:        $with_profile4_x
4433         Xamarin.Android: $with_monodroid
4434         Xamarin.iOS:     $with_monotouch
4435         Xamarin.WatchOS: $with_monotouch_watch
4436         Xamarin.TVOS:    $with_monotouch_tv
4437         Xamarin.Mac:     $with_xammac
4438         mobile_static:   $with_mobile_static
4439         JNI support:     $jdk_headers_found
4440         libgdiplus:      $libgdiplus_msg
4441         zlib:            $zlib_msg
4442         BTLS:            $enable_btls$btls_platform_string
4443         $disabled
4444 "
4445 if test x$with_static_mono = xno -a "x$host_win32" != "xyes"; then
4446    AC_MSG_WARN(Turning off static Mono is a risk, you might run into unexpected bugs)
4447 fi