OSDN Git Service

2002-02-12 Adam Megacz <adam@xwt.org>
[pf3gnuchains/gcc-fork.git] / libjava / configure.in
1 dnl Process this with autoconf to create configure
2 AC_INIT(java/lang/System.java)
3
4 AC_PROG_LN_S
5
6 dnl We use these options to decide which functions to include.
7 AC_ARG_WITH(target-subdir,
8 [  --with-target-subdir=SUBDIR
9                            configuring in a subdirectory])
10 AC_ARG_WITH(cross-host,
11 [  --with-cross-host=HOST  configuring with a cross compiler])
12
13 LIBGCJ_CONFIGURE(.)
14
15 AM_CONFIG_HEADER(include/config.h gcj/libgcj-config.h)
16
17 # Only use libltdl for native builds.
18 if test -z "${with_cross_host}"; then
19    AC_LIBLTDL_CONVENIENCE
20    AC_LIBTOOL_DLOPEN
21    DIRLTDL=libltdl
22    AC_DEFINE(USE_LTDL)
23    # Sigh.  Libtool's macro doesn't do the right thing.
24    INCLTDL="-I\$(top_srcdir)/libltdl $INCLTDL"
25    # FIXME: this is a hack.
26    sub_auxdir="`cd $ac_aux_dir && pwd`"
27    ac_configure_args="$ac_configure_args --with-auxdir=$sub_auxdir"
28 fi
29 AC_SUBST(INCLTDL)
30 AC_SUBST(LIBLTDL)
31 AC_SUBST(DIRLTDL)
32 AM_PROG_LIBTOOL
33 AC_CONFIG_SUBDIRS($DIRLTDL)
34
35 if test -z "$with_target_subdir" || test "$with_target_subdir" = "."; then
36    COMPPATH=.
37 else
38    COMPPATH=..
39 fi
40 AC_SUBST(COMPPATH)
41
42 dnl The -no-testsuite modules omit the test subdir.
43 AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
44
45 dnl See whether the user prefers size or speed for Character.
46 dnl The default is size.
47 AC_ARG_ENABLE(fast-character,
48 [  --enable-fast-character prefer speed over size for Character],
49 # Nothing
50 , AC_DEFINE(COMPACT_CHARACTER))
51
52 dnl Should the runtime set system properties by examining the 
53 dnl environment variable GCJ_PROPERTIES?
54 AC_ARG_ENABLE(getenv-properties,
55 [  --disable-getenv-properties
56                           don't set system properties from GCJ_PROPERTIES])
57
58 dnl Whether GCJ_PROPERTIES is used depends on the target.
59 if test -z "$enable_getenv_properties"; then
60    enable_getenv_properties=${enable_getenv_properties_default-yes}
61 fi
62 if test "$enable_getenv_properties" = no; then
63    AC_DEFINE(DISABLE_GETENV_PROPERTIES)
64 fi
65
66 dnl Whether we should use arguments to main()
67 if test -z "$enable_main_args"; then
68    enable_main_args=${enable_main_args_default-yes}
69 fi
70 if test "$enable_main_args" = no; then
71    AC_DEFINE(DISABLE_MAIN_ARGS)
72 fi
73
74
75 dnl Should we use hashtable-based synchronization?
76 dnl Currently works only for Linux X86/ia64
77 dnl Typically faster and more space-efficient
78 AC_ARG_ENABLE(hash-synchronization,
79 [  --enable-hash-synchronization
80                           Use global hash table for monitor locks])
81
82 if test -z "$enable_hash_synchronization"; then
83    enable_hash_synchronization=$enable_hash_synchronization_default
84 fi
85
86
87 dnl See if the user has requested runtime debugging.
88 LIBGCJDEBUG="false"
89 AC_SUBST(LIBGCJDEBUG)
90 AC_ARG_ENABLE(libgcj-debug,
91 [  --enable-libgcj-debug   enable runtime debugging code],
92   if test "$enable_libgcj_debug" = yes; then
93     AC_DEFINE(DEBUG)
94     LIBGCJDEBUG="true"
95   fi)
96
97 dnl See if the user has the interpreter included.
98 AC_ARG_ENABLE(interpreter,
99 [  --enable-interpreter    enable interpreter],
100   if test "$enable_interpreter" = yes; then
101     # This can also be set in configure.host.
102     libgcj_interpreter=yes
103   elif test "$enable_interpreter" = no; then
104     libgcj_interpreter=no
105   fi)
106
107 if test "$libgcj_interpreter" = yes; then
108    AC_DEFINE(INTERPRETER)
109 fi
110
111 AC_MSG_CHECKING([for exception model to use])
112 AC_LANG_SAVE
113 AC_LANG_CPLUSPLUS
114 AC_ARG_ENABLE(sjlj-exceptions,
115 [  --enable-sjlj-exceptions  force use of builtin_setjmp for exceptions],
116 [:],
117 [dnl Botheration.  Now we've got to detect the exception model.
118 dnl Link tests against libgcc.a are problematic since -- at least
119 dnl as of this writing -- we've not been given proper -L bits for
120 dnl single-tree newlib and libgloss.
121 dnl
122 dnl This is what AC_TRY_COMPILE would do if it didn't delete the
123 dnl conftest files before we got a change to grep them first.
124 cat > conftest.$ac_ext << EOF
125 [#]line __oline__ "configure"
126 struct S { ~S(); };
127 void bar();
128 void foo()
129 {
130   S s;
131   bar();
132 }
133 EOF
134 old_CXXFLAGS="$CXXFLAGS"  
135 CXXFLAGS=-S
136 if AC_TRY_EVAL(ac_compile); then
137   if grep _Unwind_SjLj_Resume conftest.s >/dev/null 2>&1 ; then
138     enable_sjlj_exceptions=yes
139   elif grep _Unwind_Resume conftest.s >/dev/null 2>&1 ; then
140     enable_sjlj_exceptions=no
141   fi
142 fi
143 CXXFLAGS="$old_CXXFLAGS"
144 rm -f conftest*])
145 if test x$enable_sjlj_exceptions = xyes; then
146   AC_DEFINE(SJLJ_EXCEPTIONS, 1,
147         [Define if the compiler is configured for setjmp/longjmp exceptions.])
148   ac_exception_model_name=sjlj
149 elif test x$enable_sjlj_exceptions = xno; then
150   ac_exception_model_name="call frame"
151 else
152   AC_MSG_ERROR([unable to detect exception model])
153 fi
154 AC_LANG_RESTORE
155 AC_MSG_RESULT($ac_exception_model_name)
156
157 dnl See if the user wants to disable java.net.  This is the mildly
158 dnl ugly way that we admit that target-side configuration sucks.
159 AC_ARG_ENABLE(java-net,
160 [  --disable-java-net      disable java.net])
161
162 dnl Whether java.net is built by default can depend on the target.
163 if test -z "$enable_java_net"; then
164    enable_java_net=${enable_java_net_default-yes}
165 fi
166 if test "$enable_java_net" = no; then
167    AC_DEFINE(DISABLE_JAVA_NET)
168 fi
169
170 dnl See if the user wants to configure without libffi.  Some
171 dnl architectures don't support it, and default values are set in 
172 dnl configure.host.
173 AC_ARG_WITH(libffi,
174 [  --without-libffi        don't use libffi],,with_libffi=${with_libffi_default-yes})
175
176 LIBFFI=
177 LIBFFIINCS=
178 if test "$with_libffi" != no; then
179    AC_DEFINE(USE_LIBFFI)
180    LIBFFI=../libffi/libfficonvenience.la
181    LIBFFIINCS='-I$(top_srcdir)/../libffi/include -I$(MULTIBUILDTOP)../libffi/include'
182 fi
183 AC_SUBST(LIBFFI)
184 AC_SUBST(LIBFFIINCS)
185
186 dnl See if the user wants to disable JVMPI support.
187 AC_ARG_ENABLE(jvmpi,
188 [  --disable-jvmpi         disable JVMPI support])
189
190 if test "$enable_jvmpi" != no; then
191     AC_DEFINE(ENABLE_JVMPI)
192 fi
193
194 dnl If the target is an eCos system, use the appropriate eCos
195 dnl I/O routines.
196 dnl FIXME: this should not be a local option but a global target
197 dnl system; at present there is no eCos target.
198 TARGET_ECOS=${PROCESS-"no"}
199 AC_ARG_WITH(ecos,
200 [  --with-ecos             enable runtime eCos target support],
201 TARGET_ECOS="$with_ecos"
202 )
203
204 PLATFORMOBJS=
205 case "$TARGET_ECOS" in
206    no) case "$host" in
207       *mingw*)
208             PLATFORM=Win32
209             PLATFORMOBJS=win32.lo
210             PLATFORMH=win32.h
211       ;;
212       *)
213             PLATFORM=Posix
214             PLATFORMOBJS=posix.lo
215             PLATFORMH=posix.h
216       ;;
217       esac
218       ;;
219    *)
220       PLATFORM=Ecos
221       AC_DEFINE(ECOS)
222       PLATFORMOBJS=posix.lo
223       PLATFORMH=posix.h
224       ;;
225 esac
226 AC_SUBST(PLATFORMOBJS)
227 AC_LINK_FILES(include/$PLATFORMH, include/platform.h)
228
229 AC_EGREP_HEADER(uint32_t, stdint.h, AC_DEFINE(HAVE_INT32_DEFINED))
230 AC_EGREP_HEADER(uint32_t, inttypes.h, AC_DEFINE(HAVE_INT32_DEFINED))
231 AC_EGREP_HEADER(u_int32_t, sys/types.h, AC_DEFINE(HAVE_BSD_INT32_DEFINED))
232 AC_EGREP_HEADER(u_int32_t, sys/config.h, AC_DEFINE(HAVE_BSD_INT32_DEFINED))
233
234
235 dnl These may not be defined in a non-ANS conformant embedded system.
236 dnl FIXME: Should these case a runtime exception in that case?
237 AC_EGREP_HEADER(mktime, time.h, AC_DEFINE(HAVE_MKTIME))
238 AC_EGREP_HEADER(localtime, time.h, AC_DEFINE(HAVE_LOCALTIME))
239
240 dnl Create the subdirectory for natFileDescriptor.cc, or the attempt
241 dnl to create the link will fail.
242 test -d java || mkdir java
243 test -d java/io || mkdir java/io
244 test -d gnu || mkdir gnu
245 AC_LINK_FILES(java/io/natFile${PLATFORM}.cc, java/io/natFile.cc)
246 AC_LINK_FILES(java/io/natFileDescriptor${PLATFORM}.cc, java/io/natFileDescriptor.cc)
247
248 dnl Likewise for ConcreteProcess.java and natConcreteProcess.cc.
249 test -d java/lang || mkdir java/lang
250 AC_LINK_FILES(java/lang/${PLATFORM}Process.java, java/lang/ConcreteProcess.java)
251 AC_LINK_FILES(java/lang/nat${PLATFORM}Process.cc, java/lang/natConcreteProcess.cc)
252
253 case "${host}" in
254     *mingw*)
255       SYSTEMSPEC="-lgdi32 -lwsock32 -lws2_32"
256     ;;
257     *)
258       SYSTEMSPEC=
259     ;;
260 esac
261 AC_SUBST(SYSTEMSPEC)
262
263 LIBGCJTESTSPEC="-L`pwd`/.libs -rpath `pwd`/.libs"
264 AC_SUBST(LIBGCJTESTSPEC)
265
266 AC_ARG_WITH(system-zlib,
267 [  --with-system-zlib      use installed libz])
268 ZLIBSPEC=
269 AC_SUBST(ZLIBSPEC)
270 ZLIBTESTSPEC=
271 AC_SUBST(ZLIBTESTSPEC)
272
273 dnl FIXME: this should be _libs on some hosts.
274 libsubdir=.libs
275
276 dnl Allow the GC to be disabled.  Can be useful when debugging.
277 AC_MSG_CHECKING([for garbage collector to use])
278 AC_ARG_ENABLE(java-gc,
279 changequote(<<,>>)dnl
280 <<  --enable-java-gc=TYPE   choose garbage collector [boehm]>>,
281 changequote([,])
282   GC=$enableval,
283   GC=boehm)
284 GCLIBS=
285 GCINCS=
286 GCDEPS=
287 GCOBJS=
288 GCSPEC=
289 JC1GCSPEC=
290 GCTESTSPEC=
291 case "$GC" in
292  boehm)
293     AC_MSG_RESULT(boehm)
294     GCDEPS='$(top_builddir)/../boehm-gc/libgcjgc.la'
295     # We include the path to the boehm-gc build directory.
296     # See Makefile.am to understand why.
297     GCLIBS="$GCDEPS -L\$(here)/../boehm-gc/$libsubdir"
298     GCINCS='-I$(top_srcdir)/../boehm-gc/include'
299     GCSPEC='-lgcjgc'
300     JC1GCSPEC='-fuse-boehm-gc'
301     GCTESTSPEC="-L`pwd`/../boehm-gc/.libs -rpath `pwd`/../boehm-gc/.libs"
302     dnl We also want to pick up some cpp flags required when including
303     dnl boehm-config.h.  Yuck.
304     GCINCS="$GCINCS `cat ../boehm-gc/boehm-cflags`"
305     GCOBJS=boehm.lo
306     GCHDR=boehm-gc.h
307     dnl The POSIX thread support needs to know this.
308     AC_DEFINE(HAVE_BOEHM_GC)
309     ;;
310  no)
311     AC_MSG_RESULT(none)
312     GCOBJS=nogc.lo
313     GCHDR=no-gc.h
314     ;;
315  *)
316     AC_MSG_ERROR(unrecognized collector \"$GC\")
317     ;;
318 esac
319 AC_SUBST(GCLIBS)
320 AC_SUBST(GCINCS)
321 AC_SUBST(GCDEPS)
322 AC_SUBST(GCOBJS)
323 AC_SUBST(GCSPEC)
324 AC_SUBST(JC1GCSPEC)
325 AC_SUBST(GCTESTSPEC)
326 AC_LINK_FILES(include/$GCHDR, include/java-gc.h)
327
328
329 AC_MSG_CHECKING([for thread model used by GCC])
330 THREADS=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
331 AC_MSG_RESULT([$THREADS])
332
333 case "$THREADS" in
334  no | none | single)
335     THREADS=none
336     ;;
337  posix | pthreads)
338     THREADS=posix
339     case "$host" in
340      *-*-linux*)
341         AC_DEFINE(LINUX_THREADS)
342         ;;
343     esac
344     ;;
345  win32)
346     ;;
347  decosf1 | irix | mach | os2 | solaris | dce | vxworks)
348     AC_MSG_ERROR(thread package $THREADS not yet supported)
349     ;;
350  *)
351     AC_MSG_ERROR($THREADS is an unknown thread package)
352     ;;
353 esac
354
355 THREADLIBS=
356 THREADINCS=
357 THREADDEPS=
358 THREADOBJS=
359 THREADH=
360 THREADSPEC=
361 case "$THREADS" in
362  posix)
363     case "$host" in
364      *-*-cygwin*)
365         # Don't set THREADLIBS here.  Cygwin doesn't have -lpthread.
366         ;;
367 changequote(<<,>>)   
368      *-*-freebsd[1234]*)
369 changequote([,])   
370         # Before FreeBSD 5, it didn't have -lpthread (or any library which
371         # merely adds pthread_* functions) but it does have a -pthread switch
372         # which is required at link-time to select -lc_r *instead* of -lc.
373         THREADLIBS=-pthread
374         # Don't set THREADSPEC here as might be expected since -pthread is
375         # not processed when found within a spec file, it must come from
376         # the command line.  For now, the user must provide the -pthread
377         # switch to link code compiled with gcj.  In future, consider adding
378         # support for weak references to pthread_* functions ala gthr.h API.
379         THREADSPEC='%{!pthread: %eUnder this configuration, the user must provide -pthread when linking.}'
380         ;;
381      *-*-freebsd*)
382         # FreeBSD 5 implements a model much closer to other modern UNIX
383         # which support threads.  However, it still does not support
384         # -lpthread.
385         THREADLIBS=-pthread
386         THREADSPEC=-lc_r
387         ;;
388      *)
389         THREADLIBS=-lpthread
390         THREADSPEC=-lpthread
391         ;;
392     esac
393     THREADOBJS=posix-threads.lo
394     THREADH=posix-threads.h
395     # MIT pthreads doesn't seem to have the mutexattr functions.
396     # But for now we don't check for it.  We just assume you aren't
397     # using MIT pthreads.
398     AC_DEFINE(HAVE_PTHREAD_MUTEXATTR_INIT)
399
400     # If we're using the Boehm GC, then we happen to know that it
401     # defines _REENTRANT, so we don't bother.  Eww.
402     if test "$GC" != boehm; then
403        AC_DEFINE(_REENTRANT, 1, [Required define if using POSIX threads])
404     fi
405     AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1, [Required define if using POSIX threads])
406     ;;
407
408  win32)
409     THREADOBJS=win32-threads.lo
410     THREADH=win32-threads.h
411     ;;
412
413  none)
414     THREADOBJS=no-threads.lo
415     THREADH=no-threads.h
416     ;;
417 esac
418 AC_LINK_FILES(include/$THREADH, include/java-threads.h)
419 AC_SUBST(THREADLIBS)
420 AC_SUBST(THREADINCS)
421 AC_SUBST(THREADDEPS)
422 AC_SUBST(THREADOBJS)
423 AC_SUBST(THREADSPEC)
424
425 HASH_SYNC_SPEC=
426 # Hash synchronization is only useful with posix threads right now.
427 if test "$enable_hash_synchronization" = yes && test "$THREADS" = "posix"; then
428    HASH_SYNC_SPEC=-fhash-synchronization
429    AC_DEFINE(JV_HASH_SYNCHRONIZATION, 1, [Define if hash synchronization is in use])
430 fi
431 AC_SUBST(HASH_SYNC_SPEC)
432
433
434 AM_CONDITIONAL(USING_GCC, test "$GCC" = yes)
435
436 CANADIAN=no
437 NULL_TARGET=no
438 NATIVE=yes
439
440 # We're in the tree with gcc, and need to include some of its headers.
441 GCC_UNWIND_INCLUDE='-I$(libgcj_basedir)/../gcc'
442
443 if test -n "${with_cross_host}"; then
444    # We are being configured with a cross compiler.  AC_REPLACE_FUNCS
445    # may not work correctly, because the compiler may not be able to
446    # link executables.
447
448    # We assume newlib.  This lets us hard-code the functions we know
449    # we'll have.
450    AC_DEFINE(HAVE_MEMMOVE)
451    AC_DEFINE(HAVE_MEMCPY)
452    AC_DEFINE(HAVE_STRERROR)
453    AC_DEFINE(HAVE_GMTIME_R)
454    AC_DEFINE(HAVE_LOCALTIME_R)
455    dnl This is only for POSIX threads.
456    AC_DEFINE(HAVE_PTHREAD_MUTEXATTR_INIT)
457    dnl We also assume we are using gcc, which provides alloca.
458    AC_DEFINE(HAVE_ALLOCA)
459
460    dnl Assume we do not have getuid and friends.
461    AC_DEFINE(NO_GETUID)
462
463    ZLIBSPEC=-lzgcj
464    ZLIBTESTSPEC="-L`pwd`/../zlib/.libs -rpath `pwd`/../zlib/.libs"
465
466    # If Canadian cross, then don't pick up tools from the build
467    # directory.
468    if test x"$build" != x"$with_cross_host" && x"$build" != x"$target"; then
469       CANADIAN=yes
470       GCC_UNWIND_INCLUDE=
471       GCJ="${target_alias}-gcj"
472    fi
473    NATIVE=no
474 else
475    AC_CHECK_FUNCS(strerror ioctl select fstat open fsync sleep opendir)
476    AC_CHECK_FUNCS(gmtime_r localtime_r readdir_r getpwuid_r getcwd)
477    AC_CHECK_FUNCS(access stat mkdir rename rmdir unlink realpath utime chmod)
478    AC_CHECK_FUNCS(nl_langinfo setlocale)
479    AC_CHECK_FUNCS(inet_aton inet_addr, break)
480    AC_CHECK_FUNCS(inet_pton uname inet_ntoa)
481    AC_CHECK_FUNCS(backtrace fork execvp pipe sigaction)
482    AC_CHECK_HEADERS(execinfo.h unistd.h dlfcn.h) 
483    AC_CHECK_LIB(dl, dladdr, [
484      AC_DEFINE(HAVE_DLADDR)])
485    AC_CHECK_FILES(/proc/self/exe, [
486      AC_DEFINE(HAVE_PROC_SELF_EXE)])
487
488    AM_ICONV
489    AM_LC_MESSAGES
490    AC_STRUCT_TIMEZONE
491
492    AC_CHECK_FUNCS(gethostbyname_r, [
493      AC_DEFINE(HAVE_GETHOSTBYNAME_R)
494      # There are two different kinds of gethostbyname_r.
495      # We look for the one that returns `int'.
496      # Hopefully this check is robust enough.
497      AC_EGREP_HEADER(int.*gethostbyname_r, netdb.h, [
498        AC_DEFINE(GETHOSTBYNAME_R_RETURNS_INT)])
499
500      case " $GCINCS " in
501      *" -D_REENTRANT "*) ;;
502      *)
503         dnl On DU4.0, gethostbyname_r is only declared with -D_REENTRANT
504         AC_CACHE_CHECK([whether gethostbyname_r declaration requires -D_REENTRANT],
505         [libjava_cv_gethostbyname_r_needs_reentrant],
506         [ AC_LANG_SAVE
507           AC_LANG_CPLUSPLUS
508           AC_TRY_COMPILE([#include <netdb.h>],
509             [gethostbyname_r("", 0, 0);],
510             [libjava_cv_gethostbyname_r_needs_reentrant=no], [dnl
511                 CPPFLAGS_SAVE="$CPPFLAGS"
512                 CPPFLAGS="$CPPFLAGS -D_REENTRANT"
513                 AC_TRY_COMPILE([#include <netdb.h>], [gethostbyname_r("", 0, 0);],
514                     [libjava_cv_gethostbyname_r_needs_reentrant=yes],
515                     [libjava_cv_gethostbyname_r_needs_reentrant=fail])
516                 CPPFLAGS="$CPPFLAGS_SAVE"
517           ])
518           AC_LANG_RESTORE
519         ])
520         if test "x$libjava_cv_gethostbyname_r_needs_reentrant" = xyes; then
521           AC_DEFINE(_REENTRANT, 1, [Required define if using POSIX threads])
522         fi
523      ;;
524      esac
525
526      AC_CACHE_CHECK([for struct hostent_data],
527         [libjava_cv_struct_hostent_data], [dnl
528         AC_TRY_COMPILE([
529 #if GETHOSTBYNAME_R_NEEDS_REENTRANT && !defined(_REENTRANT)
530 # define _REENTRANT 1
531 #endif
532 #include <netdb.h>], [struct hostent_data data;],
533           [libjava_cv_struct_hostent_data=yes],
534           [libjava_cv_struct_hostent_data=no])])
535      if test "x$libjava_cv_struct_hostent_data" = xyes; then
536        AC_DEFINE(HAVE_STRUCT_HOSTENT_DATA, 1,
537          [Define if struct hostent_data is defined in netdb.h])
538      fi
539    ])
540
541    # FIXME: libjava source code expects to find a prototype for
542    # gethostbyaddr_r in netdb.h.  The outer check ensures that
543    # HAVE_GETHOSTBYADDR_R will not be defined if the prototype fails
544    # to exist where expected.  (The root issue: AC_CHECK_FUNCS assumes C
545    # linkage check is enough, yet C++ code requires proper prototypes.)
546    AC_EGREP_HEADER(gethostbyaddr_r, netdb.h, [
547    AC_CHECK_FUNCS(gethostbyaddr_r, [
548      AC_DEFINE(HAVE_GETHOSTBYADDR_R)
549      # There are two different kinds of gethostbyaddr_r.
550      # We look for the one that returns `int'.
551      # Hopefully this check is robust enough.
552      AC_EGREP_HEADER(int.*gethostbyaddr_r, netdb.h, [
553        AC_DEFINE(GETHOSTBYADDR_R_RETURNS_INT)])])])
554
555    AC_CHECK_FUNCS(gethostname, [
556      AC_DEFINE(HAVE_GETHOSTNAME)
557      AC_EGREP_HEADER(gethostname, unistd.h, [
558        AC_DEFINE(HAVE_GETHOSTNAME_DECL)])])
559
560    # Look for these functions in the thread library, but only bother
561    # if using POSIX threads.
562    if test "$THREADS" = posix; then
563       save_LIBS="$LIBS"
564       LIBS="$LIBS $THREADLIBS"
565       # Some POSIX thread systems don't have pthread_mutexattr_settype.
566       # E.g., Solaris.
567       AC_CHECK_FUNCS(pthread_mutexattr_settype pthread_mutexattr_setkind_np)
568
569       # Look for sched_yield.  Up to Solaris 2.6, it is in libposix4, since
570       # Solaris 7 the name librt is preferred.
571       AC_CHECK_FUNCS(sched_yield, , [
572         AC_CHECK_LIB(rt, sched_yield, [
573           AC_DEFINE(HAVE_SCHED_YIELD)
574           THREADLIBS="$THREADLIBS -lrt"
575           THREADSPEC="$THREADSPEC -lrt"], [
576           AC_CHECK_LIB(posix4, sched_yield, [
577             AC_DEFINE(HAVE_SCHED_YIELD)
578             THREADLIBS="$THREADLIBS -lposix4"
579             THREADSPEC="$THREADSPEC -lposix4"])])])
580       LIBS="$save_LIBS"
581
582       # We can save a little space at runtime if the mutex has m_count
583       # or __m_count.  This is a nice hack for Linux.
584       AC_TRY_COMPILE([#include <pthread.h>], [
585           extern pthread_mutex_t *mutex; int q = mutex->m_count;
586         ], AC_DEFINE(PTHREAD_MUTEX_HAVE_M_COUNT), [
587         AC_TRY_COMPILE([#include <pthread.h>], [
588             extern pthread_mutex_t *mutex; int q = mutex->__m_count;
589           ], AC_DEFINE(PTHREAD_MUTEX_HAVE___M_COUNT))])
590    fi
591
592    # We require a way to get the time.
593    time_found=no
594    AC_CHECK_FUNCS(gettimeofday time ftime, time_found=yes)
595    if test "$time_found" = no; then
596       AC_MSG_ERROR([no function found to get the time])
597    fi
598
599    AC_CHECK_FUNCS(memmove)
600
601    # We require memcpy.
602    memcpy_found=no
603    AC_CHECK_FUNCS(memcpy, memcpy_found=yes)
604    if test "$memcpy_found" = no; then
605       AC_MSG_ERROR([memcpy is required])
606    fi
607
608    AC_CHECK_LIB(dl, dlopen, [
609        AC_DEFINE(HAVE_DLOPEN, 1, [Define if dlopen is available])])
610
611    # Some library-finding code we stole from Tcl.
612    #--------------------------------------------------------------------
613    #    Check for the existence of the -lsocket and -lnsl libraries.
614    #    The order here is important, so that they end up in the right
615    #    order in the command line generated by make.  Here are some
616    #    special considerations:
617    #    1. Use "connect" and "accept" to check for -lsocket, and
618    #       "gethostbyname" to check for -lnsl.
619    #    2. Use each function name only once:  can't redo a check because
620    #       autoconf caches the results of the last check and won't redo it.
621    #    3. Use -lnsl and -lsocket only if they supply procedures that
622    #       aren't already present in the normal libraries.  This is because
623    #       IRIX 5.2 has libraries, but they aren't needed and they're
624    #       bogus:  they goof up name resolution if used.
625    #    4. On some SVR4 systems, can't use -lsocket without -lnsl too.
626    #       To get around this problem, check for both libraries together
627    #       if -lsocket doesn't work by itself.
628    #--------------------------------------------------------------------
629
630    AC_CACHE_CHECK([for socket libraries], gcj_cv_lib_sockets,
631     [gcj_cv_lib_sockets=
632      gcj_checkBoth=0
633      unset ac_cv_func_connect
634      AC_CHECK_FUNC(connect, gcj_checkSocket=0, gcj_checkSocket=1)
635      if test "$gcj_checkSocket" = 1; then
636          unset ac_cv_func_connect
637          AC_CHECK_LIB(socket, main, gcj_cv_lib_sockets="-lsocket",
638                       gcj_checkBoth=1)
639      fi
640      if test "$gcj_checkBoth" = 1; then
641          gcj_oldLibs=$LIBS
642          LIBS="$LIBS -lsocket -lnsl"
643          unset ac_cv_func_accept
644          AC_CHECK_FUNC(accept,
645                        [gcj_checkNsl=0
646                         gcj_cv_lib_sockets="-lsocket -lnsl"])
647          unset ac_cv_func_accept
648          LIBS=$gcj_oldLibs
649      fi
650      unset ac_cv_func_gethostbyname
651      gcj_oldLibs=$LIBS
652      LIBS="$LIBS $gcj_cv_lib_sockets"
653      AC_CHECK_FUNC(gethostbyname, ,
654                    [AC_CHECK_LIB(nsl, main,
655                                  [gcj_cv_lib_sockets="$gcj_cv_lib_sockets -lnsl"])])
656      unset ac_cv_func_gethostbyname
657      LIBS=$gcj_oldLIBS
658    ])
659    SYSTEMSPEC="$SYSTEMSPEC $gcj_cv_lib_sockets"
660
661    if test "$with_system_zlib" = yes; then
662       AC_CHECK_LIB(z, deflate, ZLIBSPEC=-lz, ZLIBSPEC=-lzgcj)
663    else
664       ZLIBSPEC=-lzgcj
665       ZLIBTESTSPEC="-L`pwd`/../zlib/.libs -rpath `pwd`/../zlib/.libs"
666    fi
667
668    # On Solaris, and maybe other architectures, the Boehm collector
669    # requires -ldl.
670    if test "$GC" = boehm; then
671       AC_CHECK_LIB(dl, main, SYSTEMSPEC="$SYSTEMSPEC -ldl")
672    fi
673
674    if test -z "${with_multisubdir}"; then
675       builddotdot=.
676    else
677 changequote(<<,>>)
678       builddotdot=`echo ${with_multisubdir} | sed -e 's:[^/][^/]*:..:g'`
679 changequote([,])
680    fi
681    if test -x "${builddotdot}/../../gcc/gcj"; then
682       dir="`cd ${builddotdot}/../../gcc && pwd`"
683       GCJ="$dir/gcj -B`pwd`/ -B$dir/"
684    else
685       CANADIAN=yes
686       NULL_TARGET=yes
687       GCJ="gcj -B`pwd`/"
688    fi
689 fi
690
691 # Create it, so that compile/link tests don't fail
692 test -f libgcj.spec || touch libgcj.spec
693
694 # We must search the source tree for java.lang, since we still don't
695 # have libgcj.jar nor java/lang/*.class
696 GCJ_SAVE_CPPFLAGS=$CPPFLAGS
697 CPPFLAGS="$CPPFLAGS -I`pwd` -I`cd $srcdir && pwd`"
698
699 # Since some classes depend on this one, we need its source available
700 # before we can do any GCJ compilation test :-(
701 if test ! -f gnu/classpath/Configuration.java; then
702   test -d gnu || mkdir gnu
703   test -d gnu/classpath || mkdir gnu/classpath
704   sed 's,@LIBGCJDEBUG@,$LIBGCJDEBUG,' \
705         < $srcdir/gnu/classpath/Configuration.java.in \
706         > gnu/classpath/Configuration.java
707   # We do not want to redirect the output of the grep below to /dev/null,
708   # but we add /dev/null to the input list so that grep will print the
709   # filename of Configuration.java in case it finds any matches.
710   if grep @ gnu/classpath/Configuration.java /dev/null; then
711     AC_MSG_ERROR([configure.in is missing the substitutions above])
712   fi
713 fi
714
715 LT_AC_PROG_GCJ
716
717 CPPFLAGS=$GCJ_SAVE_CPPFLAGS
718
719 AC_COMPILE_CHECK_SIZEOF(void *)
720
721 ZLIBS=
722 ZDEPS=
723 ZINCS=
724 if test "x$ZLIBSPEC" = "x-lzgcj"; then
725    # We include the path to the zlib build directory.
726    # See Makefile.am to understand why.
727    ZDEPS='$(top_builddir)/../zlib/libzgcj.la'
728    ZLIBS="$ZDEPS -L\$(here)/../zlib/$libsubdir"
729    ZINCS='-I$(top_srcdir)/../zlib'
730 else
731    ZLIBS="$ZLIBSPEC"
732 fi
733 AC_SUBST(ZLIBS)
734 AC_SUBST(ZDEPS)
735 AC_SUBST(ZINCS)
736 AC_SUBST(DIVIDESPEC)
737 AC_SUBST(EXCEPTIONSPEC)
738
739 AM_CONDITIONAL(CANADIAN, test "$CANADIAN" = yes)
740 AM_CONDITIONAL(NULL_TARGET, test "$NULL_TARGET" = yes)
741 AM_CONDITIONAL(NATIVE, test "$NATIVE" = yes || test "$NULL_TARGET" = yes)
742 AM_CONDITIONAL(USE_LIBDIR, test -z "$with_cross_host")
743 AM_CONDITIONAL(NEEDS_DATA_START, test "$NEEDS_DATA_START" = yes && test "$NATIVE" = yes)
744 AC_SUBST(GCC_UNWIND_INCLUDE)
745
746 # Determine gcj version number.
747 changequote(<<,>>)
748 gcjvers="`$GCJ -v 2>&1 | sed -n 's/^.*version \([^ ]*\).*$/\1/p'`"
749 changequote([,])
750 AC_DEFINE_UNQUOTED(GCJVERSION, "$gcjvers")
751 AC_SUBST(GCJVERSION)
752
753 AC_SUBST(AM_RUNTESTFLAGS)
754
755 dnl Work around a g++ bug.  Reported to gcc-bugs@gcc.gnu.org on Jan 22, 2000.
756 AC_MSG_CHECKING([for g++ -ffloat-store bug])
757 save_CFLAGS="$CFLAGS"
758 CFLAGS="-x c++ -O2 -ffloat-store"
759 AC_TRY_COMPILE([#include <math.h>], , 
760   [AC_MSG_RESULT(no)],
761   [AC_DEFINE(__NO_MATH_INLINES)
762    AC_MSG_RESULT(yes)])
763 CFLAGS="$save_CFLAGS"
764
765 dnl We check for sys/filio.h because Solaris 2.5 defines FIONREAD there.
766 dnl On that system, sys/ioctl.h will not include sys/filio.h unless
767 dnl BSD_COMP is defined; just including sys/filio.h is simpler.
768 AC_CHECK_HEADERS(unistd.h bstring.h sys/time.h sys/types.h fcntl.h sys/ioctl.h sys/filio.h sys/stat.h sys/select.h sys/socket.h netinet/in.h arpa/inet.h netdb.h pwd.h sys/config.h stdint.h langinfo.h locale.h)
769 dnl We avoid AC_HEADER_DIRENT since we really only care about dirent.h
770 dnl for now.  If you change this, you also must update natFile.cc.
771 AC_CHECK_HEADERS(dirent.h)
772 AC_CHECK_HEADERS(inttypes.h, [
773     AC_DEFINE(HAVE_INTTYPES_H, 1, [Define if <inttypes.h> is available])
774     AC_DEFINE(JV_HAVE_INTTYPES_H, 1, [Define if <inttypes.h> is available])
775 ])
776 AC_HEADER_SYS_WAIT
777
778 AC_CHECK_TYPE([ssize_t], [int])
779
780 AC_MSG_CHECKING([for in_addr_t])
781 AC_TRY_COMPILE([#include <sys/types.h>
782 #if STDC_HEADERS
783 #include <stdlib.h>
784 #include <stddef.h>
785 #endif
786 #if HAVE_NETINET_IN_H
787 #include <netinet/in.h>
788 #endif], [in_addr_t foo;],
789   [AC_DEFINE([HAVE_IN_ADDR_T])
790    AC_MSG_RESULT(yes)],
791   [AC_MSG_RESULT(no)])
792
793 AC_MSG_CHECKING([whether struct ip_mreq is in netinet/in.h])
794 AC_TRY_COMPILE([#include <netinet/in.h>], [struct ip_mreq mreq;],
795   [AC_DEFINE(HAVE_STRUCT_IP_MREQ)
796    AC_MSG_RESULT(yes)],
797   [AC_MSG_RESULT(no)])
798
799 AC_MSG_CHECKING([whether struct ipv6_mreq is in netinet/in.h])
800 AC_TRY_COMPILE([#include <netinet/in.h>], [struct ipv6_mreq mreq6;],
801   [AC_DEFINE(HAVE_STRUCT_IPV6_MREQ)
802    AC_MSG_RESULT(yes)],
803   [AC_MSG_RESULT(no)])
804
805 AC_MSG_CHECKING([whether struct sockaddr_in6 is in netinet/in.h])
806 AC_TRY_COMPILE([#include <netinet/in.h>], [struct sockaddr_in6 addr6;],
807   [AC_DEFINE(HAVE_INET6)
808    AC_MSG_RESULT(yes)],
809   [AC_MSG_RESULT(no)])
810
811 AC_MSG_CHECKING([for socklen_t in sys/socket.h])
812 AC_TRY_COMPILE([#define _POSIX_PII_SOCKET
813 #include <sys/types.h>
814 #include <sys/socket.h>], [socklen_t x = 5;],
815   [AC_DEFINE(HAVE_SOCKLEN_T)
816    AC_MSG_RESULT(yes)],
817   [AC_MSG_RESULT(no)])
818
819 AC_MSG_CHECKING([for tm_gmtoff in struct tm])
820 AC_TRY_COMPILE([#include <time.h>], [struct tm tim; tim.tm_gmtoff = 0;],
821   [AC_DEFINE(STRUCT_TM_HAS_GMTOFF)
822    AC_MSG_RESULT(yes)],
823   [AC_MSG_RESULT(no)
824    AC_MSG_CHECKING([for global timezone variable])
825    dnl FIXME: we don't want a link check here because that won't work
826    dnl when cross-compiling.  So instead we make an assumption that
827    dnl the header file will mention timezone if it exists.
828    AC_TRY_COMPILE([#include <time.h>], [long z2 = timezone;],
829      [AC_DEFINE(HAVE_TIMEZONE)
830       AC_MSG_RESULT(yes)],
831      [AC_MSG_RESULT(no)])])
832
833 AC_FUNC_ALLOCA
834
835 AC_CHECK_PROGS(PERL, perl, false)
836
837 SYSDEP_SOURCES=
838
839 case "${host}" in
840  i?86-*-linux*)
841     SIGNAL_HANDLER=include/i386-signal.h
842     ;;
843  sparc-sun-solaris*)
844     SIGNAL_HANDLER=include/sparc-signal.h
845     ;;
846 # ia64-*)
847 #    SYSDEP_SOURCES=sysdep/ia64.c
848 #    test -d sysdep || mkdir sysdep
849 #    ;;
850  powerpc-*-linux*)
851     SIGNAL_HANDLER=include/dwarf2-signal.h
852     ;;
853  alpha*-*-linux*)
854     SIGNAL_HANDLER=include/dwarf2-signal.h
855     ;;
856  *mingw*)
857     SIGNAL_HANDLER=include/win32-signal.h
858     ;;
859  *)
860     SIGNAL_HANDLER=include/default-signal.h
861     ;;
862 esac
863
864 # If we're using sjlj exceptions, forget what we just learned.
865 if test "$enable_sjlj_exceptions" = yes; then
866    SIGNAL_HANDLER=include/default-signal.h
867 fi
868
869 AC_SUBST(SYSDEP_SOURCES)
870
871 AC_LINK_FILES($SIGNAL_HANDLER, include/java-signal.h)
872
873 if test "${multilib}" = "yes"; then
874   multilib_arg="--enable-multilib"
875 else
876   multilib_arg=
877 fi
878
879 AC_PATH_XTRA
880
881 dnl Determine which AWT peer libraries to build
882 AC_ARG_ENABLE(java-awt,
883 [  --enable-java-awt       list of AWT peer implementations to be built])
884
885 peerlibs="`echo ${enable_java_awt} | tr ',' ' '`"
886 use_xlib_awt=""
887 use_gtk_awt=""
888
889 for peer in $peerlibs ; do
890   case $peer in
891     xlib)
892       if [test "$no_x" = yes]; then
893         echo "*** xlib peers requested but no X library available" 1>&2
894         exit 1
895       else
896         use_xlib_awt="yes"
897       fi
898       ;;
899     gtk)
900       # Nothing, yet...
901       ;;
902     no)
903       use_xlib_awt=
904       use_gtk_awt=
905       break
906       ;;
907     *)
908       echo "*** unrecognised argument \"${peer}\" for --enable-java-awt" 1>&2
909       exit 1
910   esac
911 done
912
913 AM_CONDITIONAL(XLIB_AWT, test "$use_xlib_awt" = yes)
914 AM_CONDITIONAL(GTK_AWT, test "$use_gtk_awt" = yes)
915
916
917 here=`pwd`
918 AC_SUBST(here)
919
920 # We get this from the environment.
921 AC_SUBST(GCJFLAGS)
922
923 AC_OUTPUT(Makefile libgcj.spec libgcj-test.spec gnu/classpath/Configuration.java gcj/Makefile include/Makefile testsuite/Makefile,
924 [# Only add multilib support code if we just rebuilt top-level Makefile.
925 case " $CONFIG_FILES " in
926  *" Makefile "*)
927    ac_file=Makefile . ${libgcj_basedir}/../config-ml.in
928    ;;
929 esac
930
931 # Make subdirectories and `.d' files.  Look in both srcdir and
932 # builddir for the .java files.
933 h=`pwd`
934 : > deps.mk
935 ( (cd $srcdir && find . \( -name '*.java' -o -name '*.cc' \) -print) ;
936   find . \( -name '*.java' -o -name '*.cc' \) -print) | \
937    fgrep -v testsuite | \
938    sed -e 's/\.java/.d/'\;'s/\.cc/.d/' | \
939    while read f; do
940       echo "include $f" >> deps.mk
941       test -f $f || {
942 changequote(<<,>>)
943          d=`echo $f | sed -e 's,/[^/]*$,,'`
944 changequote([,])
945          if test ! -d $d; then
946            $libgcj_basedir/../mkinstalldirs $d
947          fi;
948          echo > $f
949       }
950    done
951 ],
952 srcdir=${srcdir}
953 host=${host}
954 target=${target}
955 with_multisubdir=${with_multisubdir}
956 ac_configure_args="${multilib_arg} ${ac_configure_args}"
957 CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
958 libgcj_basedir=${libgcj_basedir}
959 CC="${CC}"
960 CXX="${CXX}"
961 )