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