OSDN Git Service

libgo: Define CC_FOR_BUILD in Makefile.
[pf3gnuchains/gcc-fork.git] / libgo / configure.ac
index db74974..a11dc4d 100644 (file)
@@ -42,6 +42,9 @@ AM_PROG_LIBTOOL
 AC_SUBST(enable_shared)
 AC_SUBST(enable_static)
 
+CC_FOR_BUILD=${CC_FOR_BUILD:-gcc}
+AC_SUBST(CC_FOR_BUILD)
+
 WARN_FLAGS='-Wall -Wextra -Wwrite-strings -Wcast-qual'
 AC_SUBST(WARN_FLAGS)
 
@@ -114,53 +117,181 @@ AC_SUBST(LIBFFIINCS)
 
 is_darwin=no
 is_freebsd=no
+is_irix=no
 is_linux=no
 is_rtems=no
+is_solaris=no
+GOOS=unknown
 case ${host} in
-  *-*-darwin*) is_darwin=yes ;;
-  *-*-freebsd*) is_freebsd=yes ;;
-  *-*-linux*)  is_linux=yes  ;;
-  *-*-rtems*)  is_rtems=yes  ;;
+  *-*-darwin*)   is_darwin=yes;  GOOS=darwin ;;
+  *-*-freebsd*)  is_freebsd=yes; GOOS=freebsd ;;
+  *-*-irix6*)    is_irix=yes;    GOOS=irix ;;
+  *-*-linux*)    is_linux=yes;   GOOS=linux ;;
+  *-*-rtems*)    is_rtems=yes;   GOOS=rtems ;;
+  *-*-solaris2*) is_solaris=yes; GOOS=solaris ;;
 esac
 AM_CONDITIONAL(LIBGO_IS_DARWIN, test $is_darwin = yes)
 AM_CONDITIONAL(LIBGO_IS_FREEBSD, test $is_freebsd = yes)
+AM_CONDITIONAL(LIBGO_IS_IRIX, test $is_irix = yes)
 AM_CONDITIONAL(LIBGO_IS_LINUX, test $is_linux = yes)
 AM_CONDITIONAL(LIBGO_IS_RTEMS, test $is_rtems = yes)
+AM_CONDITIONAL(LIBGO_IS_SOLARIS, test $is_solaris = yes)
+AC_SUBST(GOOS)
 
+dnl N.B. Keep in sync with gcc/testsuite/go.test/go-test.exp (go-set-goarch).
 is_386=no
-is_x86_64=no
+is_alpha=no
 is_arm=no
+is_m68k=no
+mips_abi=unknown
+is_ppc=no
+is_ppc64=no
+is_sparc=no
+is_sparc64=no
+is_x86_64=no
+GOARCH=unknown
 case ${host} in
+  alpha*-*-*)
+    is_alpha=yes
+    GOARCH=alpha
+    ;;
+  arm*-*-* | strongarm*-*-* | ep9312*-*-* | xscale-*-*)
+    is_arm=yes
+    GOARCH=arm
+    ;;
 changequote(,)dnl
-  i[34567]86-*-*)
+  i[34567]86-*-* | x86_64-*-*)
 changequote([,])dnl
-    is_386=yes
+    AC_COMPILE_IFELSE([
+#ifdef __x86_64__
+#error 64-bit
+#endif],
+[is_386=yes], [is_x86_64=yes])
+    if test "$is_386" = "yes"; then
+      GOARCH=386
+    else
+      GOARCH=amd64
+    fi
+    ;;
+  m68k*-*-*)
+    is_m68k=yes
+    GOARCH=m68k
+    ;;
+  mips*-*-*)
+    AC_COMPILE_IFELSE([
+#if _MIPS_SIM != _ABIO32
+#error not o32
+#endif],
+[mips_abi="o32"],
+       [AC_COMPILE_IFELSE([
+#if _MIPS_SIM != _ABIN32
+#error not n32
+#endif],
+[mips_abi="n32"],
+       [AC_COMPILE_IFELSE([
+#if _MIPS_SIM != _ABI64
+#error not n64
+#endif],
+[mips_abi="n64"],
+       [AC_COMPILE_IFELSE([
+#if _MIPS_SIM != _ABIO64
+#error not o64
+#endif],
+[mips_abi="o64"],
+       [AC_MSG_ERROR([unknown MIPS ABI])
+[mips_abi="n32"]])])])])
+    case "$mips_abi" in
+    "o32") GOARCH=mipso32 ;;
+    "n32") GOARCH=mipsn32 ;;
+    "n64") GOARCH=mipsn64 ;;
+    "o64") GOARCH=mipso64 ;;
+    esac
     ;;
-  x86_64-*-*)
-    if test "$with_multisubdir" = "32"; then
-      is_386=yes
+  rs6000*-*-* | powerpc*-*-*)
+    AC_COMPILE_IFELSE([
+#ifdef _ARCH_PPC64
+#error 64-bit
+#endif],
+[is_ppc=yes], [is_ppc64=yes])
+    if test "$is_ppc" = "yes"; then
+      GOARCH=ppc
     else
-      is_x86_64=yes
+      GOARCH=ppc64
     fi
     ;;
-  arm*-*-* | strongarm*-*-* | ep9312*-*-* | xscale-*-*)
-    is_arm=yes
+  sparc*-*-*)
+    AC_COMPILE_IFELSE([
+#if defined(__sparcv9) || defined(__arch64__)
+#error 64-bit
+#endif],
+[is_sparc=yes], [is_sparc64=yes])
+    if test "$is_sparc" = "yes"; then
+      GOARCH=sparc
+    else
+      GOARCH=sparc64
+    fi
     ;;
 esac
 AM_CONDITIONAL(LIBGO_IS_386, test $is_386 = yes)
-AM_CONDITIONAL(LIBGO_IS_X86_64, test $is_x86_64 = yes)
+AM_CONDITIONAL(LIBGO_IS_ALPHA, test $is_alpha = yes)
 AM_CONDITIONAL(LIBGO_IS_ARM, test $is_arm = yes)
+AM_CONDITIONAL(LIBGO_IS_M68K, test $is_m68k = yes)
+AM_CONDITIONAL(LIBGO_IS_MIPS, test $mips_abi != unknown)
+AM_CONDITIONAL(LIBGO_IS_MIPSO32, test $mips_abi = o32)
+AM_CONDITIONAL(LIBGO_IS_MIPSN32, test $mips_abi = n32)
+AM_CONDITIONAL(LIBGO_IS_MIPSN64, test $mips_abi = n64)
+AM_CONDITIONAL(LIBGO_IS_MIPSO64, test $mips_abi = o64)
+AM_CONDITIONAL(LIBGO_IS_PPC, test $is_ppc = yes)
+AM_CONDITIONAL(LIBGO_IS_PPC64, test $is_ppc64 = yes)
+AM_CONDITIONAL(LIBGO_IS_SPARC, test $is_sparc = yes)
+AM_CONDITIONAL(LIBGO_IS_SPARC64, test $is_sparc64 = yes)
+AM_CONDITIONAL(LIBGO_IS_X86_64, test $is_x86_64 = yes)
+AC_SUBST(GOARCH)
+
+dnl Some files are only present when needed for specific architectures.
+GO_SYSCALLS_SYSCALL_OS_ARCH_FILE=
+if test -f ${srcdir}/syscalls/syscall_${GOOS}_${GOARCH}.go; then
+  GO_SYSCALLS_SYSCALL_OS_ARCH_FILE=syscalls/syscall_${GOOS}_${GOARCH}.go
+fi
+AC_SUBST(GO_SYSCALLS_SYSCALL_OS_ARCH_FILE)
+
+GO_DEBUG_PROC_REGS_OS_ARCH_FILE=
+if test -f ${srcdir}/go/debug/proc/regs_${GOOS}_${GOARCH}.go; then
+  GO_DEBUG_PROC_REGS_OS_ARCH_FILE=go/debug/proc/regs_${GOOS}_${GOARCH}.go
+fi
+AC_SUBST(GO_DEBUG_PROC_REGS_OS_ARCH_FILE)
+
+dnl Some targets need special flags to build sysinfo.go.
+case "$target" in
+    mips-sgi-irix6.5*)
+       # IRIX 6 needs _XOPEN_SOURCE=500 for the XPG5 version of struct
+       # msghdr in <sys/socket.h>.
+       OSCFLAGS='-D_XOPEN_SOURCE=500'
+       ;;
+    *-*-solaris2.[[89]])
+       # Solaris 8/9 need this so struct msghdr gets the msg_control
+       # etc. fields in <sys/socket.h> (_XPG4_2).
+       OSCFLAGS='-D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D__EXTENSIONS__'
+       ;;
+    *-*-solaris2.1[[01]])
+       # Solaris 10+ needs this so struct msghdr gets the msg_control
+       # etc. fields in <sys/socket.h> (_XPG4_2).  _XOPEN_SOURCE=500 as
+       # above doesn't work with C99.
+       OSCFLAGS='-D_XOPEN_SOURCE=600 -D__EXTENSIONS__'
+       ;;
+esac
+AC_SUBST(OSCFLAGS)
 
 dnl Use -fsplit-stack when compiling C code if available.
 AC_CACHE_CHECK([whether -fsplit-stack is supported],
-[ac_cv_libgo_split_stack_supported],
+[libgo_cv_c_split_stack_supported],
 [CFLAGS_hold=$CFLAGS
 CFLAGS="$CFLAGS -fsplit-stack"
 AC_COMPILE_IFELSE([[int i;]],
-[ac_cv_libgo_split_stack_supported=yes],
-[ac_cv_libgo_split_stack_supported=no])
+[libgo_cv_c_split_stack_supported=yes],
+[libgo_cv_c_split_stack_supported=no])
 CFLAGS=$CFLAGS_hold])
-if test "$ac_cv_libgo_split_stack_supported" = yes; then
+if test "$libgo_cv_c_split_stack_supported" = yes; then
   SPLIT_STACK=-fsplit-stack
   AC_DEFINE(USING_SPLIT_STACK, 1,
                [Define if the compiler supports -fsplit-stack])
@@ -169,7 +300,7 @@ else
 fi
 AC_SUBST(SPLIT_STACK)
 AM_CONDITIONAL(USING_SPLIT_STACK,
-       test "$ac_cv_libgo_split_stack_supported" = yes)
+       test "$libgo_cv_c_split_stack_supported" = yes)
 
 dnl Check whether the linker does stack munging when calling from
 dnl split-stack into non-split-stack code.  We check this by looking
@@ -177,27 +308,63 @@ dnl at the --help output.  FIXME: This is only half right: it's
 dnl possible for the linker to support this for some targets but not
 dnl others.
 AC_CACHE_CHECK([whether linker supports split stack],
-[ac_cv_libgo_linker_supports_split_stack],
-ac_cv_libgo_linker_supports_split_stack=no
+[libgo_cv_c_linker_supports_split_stack],
+libgo_cv_c_linker_supports_split_stack=no
 if $LD --help 2>/dev/null | grep split-stack-adjust-size >/dev/null 2>&1; then
-  ac_cv_libgo_linker_supports_split_stack=yes
+  libgo_cv_c_linker_supports_split_stack=yes
 fi)
-if test "$ac_cv_libgo_linker_supports_split_stack" = yes; then
+if test "$libgo_cv_c_linker_supports_split_stack" = yes; then
   AC_DEFINE(LINKER_SUPPORTS_SPLIT_STACK, 1,
            [Define if the linker support split stack adjustments])
 fi
 
+dnl Test for the -lm library.
+MATH_LIBS=
+AC_CHECK_LIB([m], [sqrt], MATH_LIBS=-lm)
+AC_SUBST(MATH_LIBS)
+
+dnl Test for -lsocket and -lnsl.  Copied from libjava/configure.ac.
+AC_CACHE_CHECK([for socket libraries], libgo_cv_lib_sockets,
+  [libgo_cv_lib_sockets=
+   libgo_check_both=no
+   AC_CHECK_FUNC(connect, libgo_check_socket=no, libgo_check_socket=yes)
+   if test "$libgo_check_socket" = "yes"; then
+     unset ac_cv_func_connect
+     AC_CHECK_LIB(socket, main, libgo_cv_lib_sockets="-lsocket",
+                 libgo_check_both=yes)
+   fi
+   if test "$libgo_check_both" = "yes"; then
+     libgo_old_libs=$LIBS
+     LIBS="$LIBS -lsocket -lnsl"
+     unset ac_cv_func_accept
+     AC_CHECK_FUNC(accept,
+                  [libgo_check_nsl=no
+                   libgo_cv_lib_sockets="-lsocket -lnsl"])
+     unset ac_cv_func_accept
+     LIBS=$libgo_old_libs
+   fi
+   unset ac_cv_func_gethostbyname
+   libgo_old_libs="$LIBS"
+   AC_CHECK_FUNC(gethostbyname, ,
+                [AC_CHECK_LIB(nsl, main,
+                       [libgo_cv_lib_sockets="$libgo_cv_lib_sockets -lnsl"])])
+   unset ac_cv_func_gethostbyname
+   LIBS=$libgo_old_libs
+])
+NET_LIBS="$libgo_cv_lib_sockets"
+AC_SUBST(NET_LIBS)
+
 dnl Test whether the compiler supports the -pthread option.
 AC_CACHE_CHECK([whether -pthread is supported],
-[ac_cv_libgo_pthread_supported],
+[libgo_cv_lib_pthread],
 [CFLAGS_hold=$CFLAGS
 CFLAGS="$CFLAGS -pthread"
 AC_COMPILE_IFELSE([[int i;]],
-[ac_cv_libgo_pthread_supported=yes],
-[ac_cv_libgo_pthread_supported=no])
+[libgo_cv_lib_pthread=yes],
+[libgo_cv_lib_pthread=no])
 CFLAGS=$CFLAGS_hold])
 PTHREAD_CFLAGS=
-if test "$ac_cv_libgo_pthread_supported" = yes; then
+if test "$libgo_cv_lib_pthread" = yes; then
   PTHREAD_CFLAGS=-pthread
 fi
 AC_SUBST(PTHREAD_CFLAGS)
@@ -207,26 +374,110 @@ PTHREAD_LIBS=
 AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS=-lpthread)
 AC_SUBST(PTHREAD_LIBS)
 
+dnl Test if -lrt is required for sched_yield.
+AC_SEARCH_LIBS([sched_yield], [rt])
+
 AC_C_BIGENDIAN
 
 GCC_CHECK_UNWIND_GETIPINFO
 
-AC_CHECK_HEADERS(sys/mman.h syscall.h sys/epoll.h sys/ptrace.h sys/user.h sys/utsname.h)
+AC_ARG_ENABLE(sjlj-exceptions,
+  AC_HELP_STRING([--enable-sjlj-exceptions],
+                [force use of builtin_setjmp for exceptions]),
+  [case "$enableval" in
+   yes|no|auto) ;;
+   *) AC_MSG_ERROR([unknown argument to --enable-sjlj-exceptions]) ;;
+   esac],
+  [enable_sjlj_exceptions=auto])
+
+AC_CACHE_CHECK([whether to use setjmp/longjmp exceptions],
+[libgo_cv_lib_sjlj_exceptions],
+[AC_LANG_CONFTEST(
+  [AC_LANG_SOURCE([
+void bar ();
+void clean (int *);
+void foo ()
+{
+  int i __attribute__ ((cleanup (clean)));
+  bar();
+}
+])])
+CFLAGS_hold=$CFLAGS
+CFLAGS="--save-temps -fexceptions"
+libgo_cv_lib_sjlj_exceptions=unknown
+AS_IF([ac_fn_c_try_compile],
+  [if grep _Unwind_SjLj_Resume conftest.s >/dev/null 2>&1; then
+    libgo_cv_lib_sjlj_exceptions=yes
+  elif grep _Unwind_Resume conftest.s >/dev/null 2>&1; then
+    libgo_cv_lib_sjlj_exceptions=no
+  fi])
+CFLAGS=$CFLAGS_hold
+rm -f conftest*
+])
+
+if test "$enable_sjlj_exceptions" = "auto"; then
+  enable_sjlj_exceptions=$libgo_cv_lib_sjlj_exceptions
+fi
+
+case $enable_sjlj_exceptions in
+yes)
+  AC_DEFINE(LIBGO_SJLJ_EXCEPTIONS, 1,
+       [Define if the C++ compiler is configured for setjmp/longjmp exceptions.])
+  ;;
+no)
+  ;;
+*)
+  AC_MSG_ERROR([unable to detect exception model])
+  ;;
+esac
+
+AC_CHECK_HEADERS(sys/mman.h syscall.h sys/epoll.h sys/ptrace.h sys/syscall.h sys/user.h sys/utsname.h sys/select.h)
 AM_CONDITIONAL(HAVE_SYS_MMAN_H, test "$ac_cv_header_sys_mman_h" = yes)
-AC_CHECK_FUNCS(srandom random strsignal)
+
+AC_CHECK_FUNCS(srandom random strerror_r strsignal wait4 mincore setenv)
+AM_CONDITIONAL(HAVE_STRERROR_R, test "$ac_cv_func_strerror_r" = yes)
+AM_CONDITIONAL(HAVE_WAIT4, test "$ac_cv_func_wait4" = yes)
+
+AC_CACHE_CHECK([for __sync_bool_compare_and_swap_4],
+[libgo_cv_func___sync_bool_compare_and_swap_4],
+[AC_LINK_IFELSE([
+typedef unsigned int uint32  __attribute__ ((mode (SI)));
+uint32 i;
+int main() { return __sync_bool_compare_and_swap (&i, 0, 1); }
+],
+[libgo_cv_func___sync_bool_compare_and_swap_4=yes],
+[libgo_cv_func___sync_bool_compare_and_swap_4=no])])
+if test "$libgo_cv_func___sync_bool_compare_and_swap_4" = "yes"; then
+  AC_DEFINE(HAVE_SYNC_BOOL_COMPARE_AND_SWAP_4, 1,
+    [Define to 1 if the compiler provides the __sync_bool_compare_and_swap function for uint32])
+fi
+
+AC_CACHE_CHECK([for __sync_fetch_and_add_4],
+[libgo_cv_func___sync_fetch_and_add_4],
+[AC_LINK_IFELSE([
+typedef unsigned int uint32  __attribute__ ((mode (SI)));
+uint32 i;
+int main() { return __sync_fetch_and_add (&i, 1); }
+],
+[libgo_cv_func___sync_fetch_and_add_4=yes],
+[libgo_cv_func___sync_fetch_and_add_4=no])])
+if test "$libgo_cv_func___sync_fetch_and_add_4" = "yes"; then
+  AC_DEFINE(HAVE_SYNC_FETCH_AND_ADD_4, 1,
+    [Define to 1 if the compiler provides the __sync_fetch_and_add function for uint32])
+fi
 
 dnl For x86 we want to use the -minline-all-stringops option to avoid
 dnl forcing a stack split when calling memcpy and friends.
 AC_CACHE_CHECK([whether compiler supports -minline-all-stringops],
-[ac_cv_libgo_compiler_supports_inline_all_stringops],
+[libgo_cv_c_stringops],
 [CFLAGS_hold=$CFLAGS
 CFLAGS="$CFLAGS -minline-all-stringops"
 AC_COMPILE_IFELSE([int i;],
-[ac_cv_libgo_compiler_supports_inline_all_stringops=yes],
-[ac_cv_libgo_compiler_supports_inline_all_stringops=no])
+[libgo_cv_c_stringops=yes],
+[libgo_cv_c_stringops=no])
 CFLAGS=$CFLAGS_hold])
 STRINGOPS_FLAG=
-if test "$ac_cv_libgo_compiler_supports_inline_all_stringops" = yes; then
+if test "$libgo_cv_c_stringops" = yes; then
   STRINGOPS_FLAG=-minline-all-stringops
 fi
 AC_SUBST(STRINGOPS_FLAG)