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