7d3100cb7a6fb840e037aa79f284f694121263f7
[mono.git] / configure.in
1 AC_INIT(README)
2 AC_CANONICAL_SYSTEM
3 AM_CONFIG_HEADER(config.h)
4 AM_INIT_AUTOMAKE(mono, 0.15)
5 AM_MAINTAINER_MODE
6
7 dnl ****************************************
8 dnl *** Check if we're building on win32 ***
9 dnl ****************************************
10 AC_MSG_CHECKING([if building for some Win32 platform])
11 case "$host" in
12         *-*-mingw*|*-*-cygwin*)
13                 platform_win32=yes
14                 AC_DEFINE(PLATFORM_WIN32)
15                 CC="gcc -mno-cygwin"
16                 HOST_CC="gcc"
17                 libdl=
18                 ;;
19         *)
20                 platform_win32=no
21                 libdl="-ldl"
22                 ;;
23 esac
24 AC_MSG_RESULT($platform_win32)
25 AM_CONDITIONAL(PLATFORM_WIN32, test x$platform_win32 = xyes)
26
27 AC_CHECK_TOOL(CC, gcc, gcc)
28 AC_PROG_CC
29 AM_PROG_CC_STDC
30 AC_PROG_INSTALL
31
32 AC_CHECK_PROG(BISON, bison,yes,no)
33 if test "x$BISON" = "xno";
34 then
35         AC_MSG_ERROR([You need to install bison])
36 fi
37
38 dnl may require a specific autoconf version
39 dnl AC_PROG_CC_FOR_BUILD
40 dnl CC_FOR_BUILD not automatically detected
41 CC_FOR_BUILD=$CC
42 BUILD_EXEEXT=
43 if test "x$cross_compiling" = "xyes"; then
44         CC_FOR_BUILD=cc
45         BUILD_EXEEXT=""
46 fi
47 AC_SUBST(CC_FOR_BUILD)
48 AC_SUBST(HOST_CC)
49 AC_SUBST(BUILD_EXEEXT)
50
51 # Set STDC_HEADERS
52 AC_HEADER_STDC
53 AC_LIBTOOL_WIN32_DLL
54 AM_PROG_LIBTOOL
55
56 AC_CHECK_HEADERS(sys/filio.h sys/sockio.h netdb.h utime.h)
57
58 # for mono/metadata/debug-symfile.c
59 AC_CHECK_HEADERS(elf.h)
60
61 # for mono/dis
62 AC_CHECK_HEADERS(wchar.h)
63
64 # not 64 bit clean in cross-compile
65 AC_CHECK_SIZEOF(void *, 4)
66
67 CFLAGS='-g -Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes  -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wno-cast-qual -Wcast-align -Wwrite-strings'
68
69 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
70 if test "x$PKG_CONFIG" = "xno"; then
71         AC_MSG_ERROR([You need to install pkg-config])
72 fi
73
74 dnl for use on the build system
75 dnl pkg-config is stupid
76 BUILD_GLIB_CFLAGS=`$PKG_CONFIG --cflags glib-2.0`
77 BUILD_GLIB_LIBS=`$PKG_CONFIG --libs glib-2.0`
78 AC_SUBST(BUILD_GLIB_CFLAGS)
79 AC_SUBST(BUILD_GLIB_LIBS)
80
81 PKG_PATH=
82 AC_ARG_WITH(crosspkgdir, [  --with-crosspkgdir=/path/to/pkg-config/dir],
83         if test x$with_crosspkgdir = "x"; then
84                 if test -s $PKG_CONFIG_PATH; then
85                         PKG_PATH=$PKG_CONFIG_PATH
86                 fi
87         else
88                 PKG_PATH=$with_crosspkgdir
89                 PKG_CONFIG_PATH=$PKG_PATH
90                 export PKG_CONFIG_PATH
91         fi
92 )
93
94 ## Versions of dependencies
95 GLIB_REQUIRED_VERSION=1.3.11
96
97 PKG_CHECK_MODULES(BASE_DEPENDENCIES, glib-2.0 >= $GLIB_REQUIRED_VERSION)
98
99 GLIB_CFLAGS=`$PKG_CONFIG --cflags glib-2.0`
100 GLIB_LIBS=`$PKG_CONFIG --libs glib-2.0`
101 GMODULE_CFLAGS=`$PKG_CONFIG --cflags gmodule-2.0`
102 GMODULE_LIBS=`$PKG_CONFIG --libs gmodule-2.0`
103
104 AC_SUBST(GLIB_CFLAGS)
105 AC_SUBST(GLIB_LIBS)
106 AC_SUBST(GMODULE_CFLAGS)
107 AC_SUBST(GMODULE_LIBS)
108
109 AC_CHECK_LIB(gc, GC_malloc, found_boehm="yes",,$libdl)
110 gc=auto
111 AC_ARG_WITH(gc, [  --with-gc=boehm,none],[gc=$with_gc])
112
113 case "x$gc" in
114         xboehm|xyes)
115                 if test "x$found_boehm" != "xyes"; then
116                         AC_MSG_ERROR("GC requested but libgc not found!")
117                 fi
118
119                 AC_DEFINE(HAVE_BOEHM_GC)
120                 AC_SUBST(HAVE_BOEHM_GC)
121                 LIBS="$LIBS -lgc $libdl"
122                 ;;
123         xnone)
124                 AC_MSG_WARN("Compiling mono without GC.")
125                 ;;
126         *)
127 dnl When the JIT works with libgc, use this chunk.
128 dnl             # If libgc was found, use it.  Otherwise just warn.
129                 if test "x$found_boehm" != "xyes"; then
130                         AC_MSG_WARN("Compiling mono without GC.")
131                 else
132                         AC_DEFINE(HAVE_BOEHM_GC)
133                         AC_SUBST(HAVE_BOEHM_GC)
134                         LIBS="$LIBS -lgc $libdl"
135                         gc="boehm"
136                 fi
137 dnl             AC_MSG_WARN("Compiling mono without GC.")
138                 ;;
139 esac
140
141 if test x$platform_win32 = xno; then
142         dnl ******************************************************************
143         dnl *** Check for large file support                               ***
144         dnl *** (If we were using autoconf 2.50 we'd use AC_SYS_LARGEFILE) ***
145         dnl ******************************************************************
146         
147         # Check that off_t can represent 2**63 - 1 correctly, working around
148         # potential compiler bugs.  Defines LARGE_FILE_SUPPORT, adds $1 to
149         # CPPFLAGS and sets $large_offt to yes if the test succeeds
150         large_offt=no
151         AC_DEFUN(LARGE_FILES, [
152                 large_CPPFLAGS=$CPPFLAGS
153                 CPPFLAGS="$CPPFLAGS $1"
154                 AC_TRY_RUN([
155                         #include <sys/types.h>
156
157                         #define BIG_OFF_T (((off_t)1<<62)-1+((off_t)1<<62))
158
159                         int main(void) {
160                                 int big_off_t=((BIG_OFF_T%2147483629==721) &&
161                                                (BIG_OFF_T%2147483647==1));
162                                 if(big_off_t) {
163                                         exit(0);
164                                 } else {
165                                         exit(1);
166                                 }
167                         }
168                 ], [
169                         AC_MSG_RESULT(ok)
170                         AC_DEFINE(HAVE_LARGE_FILE_SUPPORT)
171                         large_CPPFLAGS="$large_CPPFLAGS $1"
172                         large_offt=yes
173                 ], [
174                         AC_MSG_RESULT(no)
175                 ], "")
176                 CPPFLAGS=$large_CPPFLAGS
177         ])
178
179         AC_MSG_CHECKING(if off_t is 64 bits wide)
180         LARGE_FILES("")
181         if test $large_offt = no; then
182                 AC_MSG_CHECKING(if _FILE_OFFSET_BITS=64 gives 64 bit off_t)
183                 LARGE_FILES("-D_FILE_OFFSET_BITS=64")
184         fi
185         if test $large_offt = no; then
186                 AC_MSG_WARN([No 64 bit file size support available])
187         fi
188         
189         dnl *****************************
190         dnl *** Checks for libsocket  ***
191         dnl *****************************
192         AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
193
194         dnl *******************************
195         dnl *** Checks for MSG_NOSIGNAL ***
196         dnl *******************************
197         AC_MSG_CHECKING(for MSG_NOSIGNAL)
198         AC_TRY_COMPILE([#include <sys/socket.h>], [
199                 int f = MSG_NOSIGNAL;
200         ], [
201                 # Yes, we have it...
202                 AC_MSG_RESULT(yes)
203                 AC_DEFINE(HAVE_MSG_NOSIGNAL)
204         ], [
205                 # We'll have to use signals
206                 AC_MSG_RESULT(no)
207         ])
208
209         dnl *****************************
210         dnl *** Checks for SOL_IP     ***
211         dnl *****************************
212         AC_MSG_CHECKING(for SOL_IP)
213         AC_TRY_COMPILE([#include <netdb.h>], [
214                 int level = SOL_IP;
215         ], [
216                 # Yes, we have it...
217                 AC_MSG_RESULT(yes)
218                 AC_DEFINE(HAVE_SOL_IP)
219         ], [
220                 # We'll have to use getprotobyname
221                 AC_MSG_RESULT(no)
222         ])
223
224         dnl *****************************
225         dnl *** Checks for SOL_TCP    ***
226         dnl *****************************
227         AC_MSG_CHECKING(for SOL_TCP)
228         AC_TRY_COMPILE([#include <netdb.h>], [
229                 int level = SOL_TCP;
230         ], [
231                 # Yes, we have it...
232                 AC_MSG_RESULT(yes)
233                 AC_DEFINE(HAVE_SOL_TCP)
234         ], [
235                 # We'll have to use getprotobyname
236                 AC_MSG_RESULT(no)
237         ])
238
239         dnl *****************************
240         dnl *** Checks for IP_PKTINFO ***
241         dnl *****************************
242         AC_MSG_CHECKING(for IP_PKTINFO)
243         AC_TRY_COMPILE([#include <netdb.h>], [
244                 int level = IP_PKTINFO;
245         ], [
246                 # Yes, we have it...
247                 AC_MSG_RESULT(yes)
248                 AC_DEFINE(HAVE_IP_PKTINFO)
249         ], [
250                 AC_MSG_RESULT(no)
251         ])
252
253         dnl *********************************
254         dnl *** Check for struct ip_mreqn ***
255         dnl *********************************
256         AC_MSG_CHECKING(for struct ip_mreqn)
257         AC_TRY_COMPILE([#include <netinet/in.h>], [
258                 struct ip_mreqn mreq;
259                 mreq.imr_address.s_addr = 0;
260         ], [
261                 # Yes, we have it...
262                 AC_MSG_RESULT(yes)
263                 AC_DEFINE(HAVE_STRUCT_IP_MREQN)
264         ], [
265                 # We'll just have to use struct ip_mreq
266                 AC_MSG_RESULT(no)
267         ])
268
269         dnl *****************************
270         dnl *** Checks for libnsl     ***
271         dnl *****************************
272         AC_CHECK_LIB(nsl, gethostbyaddr, LIBS="$LIBS -lnsl")
273
274         AC_CHECK_FUNCS(inet_pton inet_aton)
275
276         dnl ***********************************************
277         dnl *** Checks for size of sockaddr_un.sun_path ***
278         dnl ***********************************************
279         # AC_CHECK_SIZEOF can't cope with struct members :-(
280         AC_MSG_CHECKING(size of sockaddr_un.sun_path)
281         AC_CACHE_VAL(cv_mono_sizeof_sunpath,
282                 [AC_TRY_RUN([
283                         #include <stdio.h>
284                         #include <sys/un.h>
285
286                         int main(void) {
287                                 struct sockaddr_un sock_un;
288                                 FILE *f=fopen("conftestval", "w");
289                                 if(!f) exit(1);
290                                 fprintf(f, "%d\n", sizeof(sock_un.sun_path));
291                                 exit(0);
292                         }
293                 ], cv_mono_sizeof_sunpath=`cat conftestval`,
294                    cv_mono_sizeof_sunpath=0,
295                    cv_mono_sizeof_sunpath=0)])dnl
296         AC_MSG_RESULT($cv_mono_sizeof_sunpath)
297         AC_DEFINE_UNQUOTED(MONO_SIZEOF_SUNPATH, $cv_mono_sizeof_sunpath)
298
299         dnl *****************************
300         dnl *** Checks for libpthread ***
301         dnl *****************************
302         AC_SEARCH_LIBS(pthread_create, pthread c_r, [
303                 AM_CONDITIONAL(THREADS_PTHREAD, true)
304                 AC_DEFINE(HAVE_PTHREAD)
305
306                 # Need pthread_mutex_timedlock
307                 pthread_CFLAGS=""
308                 orig_CPPFLAGS=$CPPFLAGS
309                 # This is a gcc-specific error, but we already set
310                 # gcc-specific options in CFLAGS
311                 CPPFLAGS="$CPPFLAGS -Werror-implicit-function-declaration"
312                 AC_MSG_CHECKING(for pthread_mutex_timedlock)
313                 AC_TRY_COMPILE([ #include <pthread.h>], [
314                         pthread_mutex_t mut=PTHREAD_MUTEX_INITIALIZER;
315                         pthread_mutex_timedlock(&mut, NULL);
316                 ], [
317                         # Works!
318                         AC_MSG_RESULT(yes)
319                         AC_DEFINE(HAVE_PTHREAD_MUTEX_TIMEDLOCK)
320                 ], [
321                         AC_MSG_RESULT(no)
322
323                         # glibc requires -D_GNU_SOURCE before it will declare
324                         # this function
325                         AC_MSG_CHECKING(whether _GNU_SOURCE is needed for pthread_mutex_timedlock)
326                         CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
327                         AC_TRY_COMPILE([ #include <pthread.h>], [
328                                 pthread_mutex_t mut=PTHREAD_MUTEX_INITIALIZER;
329                                 pthread_mutex_timedlock(&mut, NULL);
330                         ], [
331                                 AC_MSG_RESULT(yes)
332                                 pthread_CFLAGS="-D_GNU_SOURCE"
333                                 AC_DEFINE(HAVE_PTHREAD_MUTEX_TIMEDLOCK)
334                         ], [
335                                 AC_MSG_RESULT(no)
336                                 dnl Add other variants here
337                                 AC_MSG_WARN(Working around pthread_mutex_timedlock)
338                         ])
339                 ])
340                 CPPFLAGS=$orig_CPPFLAGS
341                 CPPFLAGS="$CPPFLAGS $pthread_CFLAGS"
342
343                 # Need PTHREAD_MUTEX_RECURSIVE
344                 pthread_CFLAGS=""
345                 orig_CPPFLAGS=$CPPFLAGS
346                 # This is a gcc-specific error, but we already set
347                 # gcc-specific options in CFLAGS
348                 CPPFLAGS="$CPPFLAGS -Werror-implicit-function-declaration"
349                 AC_MSG_CHECKING(for PTHREAD_MUTEX_RECURSIVE)
350                 AC_TRY_COMPILE([ #include <pthread.h>], [
351                         pthread_mutexattr_t attr;
352                         pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
353                 ], [
354                         # Works!
355                         AC_MSG_RESULT(ok)
356                 ], [
357                         AC_MSG_RESULT(no)
358
359                         # glibc requires -D_GNU_SOURCE before it will declare
360                         # this macro
361                         AC_MSG_CHECKING(whether _GNU_SOURCE is needed for PTHREAD_MUTEX_RECURSIVE)
362                         CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
363                         AC_TRY_COMPILE([ #include <pthread.h>], [
364                                 pthread_mutexattr_t attr;
365                                 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
366                         ], [
367                                 AC_MSG_RESULT(ok)
368                                 pthread_CFLAGS="-D_GNU_SOURCE"
369                         ], [
370                                 AC_MSG_RESULT(no)
371                                 dnl Add other variants here
372                                 AC_MSG_WARN(Using mono_mutex_t for recursive mutexes)
373                                 AC_DEFINE(USE_MONO_MUTEX)
374                         ])
375                 ])
376                 CPPFLAGS=$orig_CPPFLAGS
377                 CPPFLAGS="$CPPFLAGS -D_REENTRANT $pthread_CFLAGS"
378         ], [
379                 AC_MSG_ERROR([libpthread is required on non-win32 hosts])
380         ])
381
382         dnl ********************************
383         dnl *** Checks for semaphore lib ***
384         dnl ********************************
385         AC_CHECK_LIB(rt, sem_init, LIBS="$LIBS -lrt")
386
387         dnl ********************************
388         dnl *** Checks for timezone stuff **
389         dnl ********************************
390         AC_CACHE_CHECK(for timezone variable, ac_cv_var_timezone,
391                 AC_TRY_COMPILE([
392                         #include <time.h>
393                 ], [
394                         timezone = 1;
395                 ], ac_cv_var_timezone=yes, ac_cv_var_timezone=no))
396         if test $ac_cv_var_timezone = yes; then
397                 AC_DEFINE(HAVE_TIMEZONE)
398         else
399                 AC_CACHE_CHECK(for tm_gmtoff in struct tm, ac_cv_struct_tm_gmtoff,
400                         AC_TRY_COMPILE([
401                                 #include <time.h>
402                                 ], [
403                                 struct tm tm;
404                                 tm.tm_gmtoff = 1;
405                                 ], ac_cv_struct_tm_gmtoff=yes, ac_cv_struct_tm_gmtoff=no))
406                 if test $ac_cv_struct_tm_gmtoff = yes; then
407                         AC_DEFINE(HAVE_TM_GMTOFF)
408                 else
409                         AC_ERROR(unable to find a way to determine timezone)
410                 fi
411         fi
412 else
413         AM_CONDITIONAL(THREADS_PTHREAD, false)
414         # This is a kludge, we really ought to test for libws2_32, but
415         # I can't make AC_CHECK_LIB link (the symbols seem to be mangled
416         # with @num suffixes)
417         LIBS="$LIBS -lws2_32"
418         CFLAGS="$CFLAGS -mno-cygwin"
419 fi
420
421 dnl ****************************
422 dnl *** Look for /dev/random ***
423 dnl ****************************
424
425 AC_MSG_CHECKING([if usage of random device is requested])
426 AC_ARG_ENABLE(dev-random,
427 [  --disable-dev-random    disable the use of the random device],
428 try_dev_random=$enableval, try_dev_random=yes)
429 AC_MSG_RESULT($try_dev_random)
430
431 case "{$target}" in
432     *-openbsd*)
433     NAME_DEV_RANDOM="/dev/srandom"
434     ;;
435
436 dnl Win32 does not have /dev/random, they have their own method...
437
438     *-*-mingw*|*-*-cygwin*)
439     ac_cv_have_dev_random = no
440     ;;
441
442 dnl Everywhere else, it's /dev/random
443
444     *)
445     NAME_DEV_RANDOM="/dev/random"
446     ;;
447 esac
448
449 AC_DEFINE_UNQUOTED(NAME_DEV_RANDOM, "$NAME_DEV_RANDOM")
450
451 dnl Now check if the device actually exists
452
453 if test "x$try_dev_random" = "xyes"; then
454     AC_CACHE_CHECK(for random device, ac_cv_have_dev_random,
455     [if test -r "$NAME_DEV_RANDOM" ; then
456         ac_cv_have_dev_random=yes; else ac_cv_have_dev_random=no; fi])
457     if test "x$ac_cv_have_dev_random" = "xyes"; then
458         AC_DEFINE(HAVE_CRYPT_RNG)
459     fi
460 else
461     AC_MSG_CHECKING(for random device)
462     ac_cv_have_dev_random=no
463     AC_MSG_RESULT(has been disabled)
464 fi
465
466 if test "x$platform_win32" = "xyes"; then
467     AC_DEFINE(HAVE_CRYPT_RNG)
468 fi
469
470 if test "x$ac_cv_have_dev_random" = "xno" \
471     && test "x$platform_win32" = "xno"; then
472     AC_MSG_WARN([[
473 ***
474 *** A system-provided entropy source was not found on this system.
475 *** Because of this, the System.Security.Cryptography random number generator
476 *** will throw a NotImplemented exception.
477 ***
478 *** If you are seeing this message, and you know your system DOES have an
479 *** entropy collection in place, please contact <crichton@gimp.org> and
480 *** provide information about the system and how to access the random device.
481 ***
482 *** For those systems who lack a random device, EGD support is forthcoming.
483 ***]])
484 fi
485  
486 AC_MSG_CHECKING([if inter-process shared handles are requested])
487 AC_ARG_ENABLE(shared-handles, [  --disable-shared-handles disable inter-process shared handles], try_shared_handles=$enableval, try_shared_handles=yes)
488 AC_MSG_RESULT($try_shared_handles)
489 if test "x$try_shared_handles" != "xyes"; then
490         AC_DEFINE(DISABLE_SHARED_HANDLES)
491         AC_SUBST(DISABLE_SHARED_HANDLES)
492 fi
493
494 TARGET="unknown"
495 ACCESS_UNALIGNED="yes"
496
497 case "$host" in
498 #mips-sgi-irix5.* | mips-sgi-irix6.*) TARGET=MIPS; ACCESS_UNALIGNED="no";;
499 i*86-*-*) TARGET=X86; arch_target=x86;;
500 sparc*-*-*) TARGET=SPARC; arch_target=sparc; ACCESS_UNALIGNED="no";;
501 #alpha*-*-linux* | alpha*-*-osf*) TARGET=ALPHA; ACCESS_UNALIGNED="no";;
502 #m68k-*-linux*) TARGET=M68K;;
503 macppc-*-openbsd* | powerpc-*-linux* | powerpc-*-openbsd* | powerpc-*-sysv*) TARGET=POWERPC; arch_target=ppc;;
504 arm-*-linux-* | armv4l-*-linux-*) TARGET=ARM; arch_target=arm; ACCESS_UNALIGNED="no";;
505 esac
506
507 if test ${TARGET} = unknown; then
508         CPPFLAGS="$CPPFLAGS -DNO_PORT"
509         AC_MSG_WARN("mono has not been ported to $host: some things may not work.")
510 fi
511
512 if test ${ACCESS_UNALIGNED} = no; then
513         CPPFLAGS="$CPPFLAGS -DNO_UNALIGNED_ACCESS"
514 fi
515
516 AM_CONDITIONAL(MIPS_GCC, test ${TARGET}${ac_cv_prog_gcc} = MIPSyes)
517 AM_CONDITIONAL(MIPS_SGI, test ${TARGET}${ac_cv_prog_gcc} = MIPSno)
518 AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
519 AM_CONDITIONAL(X86, test x$TARGET = xX86)
520 AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
521 AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
522 AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
523 AM_CONDITIONAL(ARM, test x$TARGET = xARM)
524
525 LIBC="libc.so.6"
526 AC_SUBST(LIBC)
527
528 AC_SUBST(arch_target)
529 AC_SUBST(CFLAGS)
530 AC_SUBST(CPPFLAGS)
531
532 AC_OUTPUT([
533 Makefile
534 mono.pc
535 mono/Makefile
536 mono/utils/Makefile
537 mono/metadata/Makefile
538 mono/dis/Makefile
539 mono/cil/Makefile
540 mono/arch/Makefile
541 mono/os/Makefile
542 mono/os/win32/Makefile
543 mono/os/unix/Makefile
544 mono/arch/x86/Makefile
545 mono/arch/ppc/Makefile
546 mono/arch/sparc/Makefile
547 mono/arch/arm/Makefile
548 mono/interpreter/Makefile
549 mono/tests/Makefile
550 mono/benchmark/Makefile
551 mono/monoburg/Makefile
552 mono/monograph/Makefile
553 mono/jit/Makefile
554 mono/io-layer/Makefile
555 mono/handles/Makefile
556 runtime/Makefile
557 scripts/Makefile
558 man/Makefile
559 doc/Makefile
560 docs/Makefile
561 data/Makefile
562 mono.spec
563 ])
564
565 echo "
566
567         GC:     $gc
568
569 "