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