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