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