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