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