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