1# configure.ac -- Go library configure script.
2
3# Copyright 2009 The Go Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style
5# license that can be found in the LICENSE file.
6
7# Process this file with autoreconf to produce configure.
8
9AC_PREREQ(2.64)
10AC_INIT(package-unused, version-unused,, libgo)
11AC_CONFIG_SRCDIR(Makefile.am)
12AC_CONFIG_HEADER(config.h)
13
14libtool_VERSION=5:0:0
15AC_SUBST(libtool_VERSION)
16
17AM_ENABLE_MULTILIB(, ..)
18
19AC_CANONICAL_SYSTEM
20target_alias=${target_alias-$host_alias}
21
22AM_INIT_AUTOMAKE([1.9.3 no-define foreign no-dist -Wall -Wno-portability])
23AH_TEMPLATE(PACKAGE, [Name of package])
24AH_TEMPLATE(VERSION, [Version number of package])
25
26m4_rename([_AC_ARG_VAR_PRECIOUS],[glibgo_PRECIOUS])
27m4_define([_AC_ARG_VAR_PRECIOUS],[])
28AC_PROG_CC
29AC_PROG_GO
30m4_rename_force([glibgo_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
31
32AC_SUBST(CFLAGS)
33
34AM_MAINTAINER_MODE
35
36AC_PROG_LD
37AC_PROG_RANLIB
38AC_CHECK_TOOL(OBJCOPY, objcopy, missing-objcopy)
39
40AC_LIBTOOL_DLOPEN
41AM_PROG_LIBTOOL
42AC_SUBST(enable_shared)
43AC_SUBST(enable_static)
44
45CC_FOR_BUILD=${CC_FOR_BUILD:-gcc}
46AC_SUBST(CC_FOR_BUILD)
47
48AC_PROG_AWK
49
50WARN_FLAGS='-Wall -Wextra -Wwrite-strings -Wcast-qual'
51AC_SUBST(WARN_FLAGS)
52
53AC_ARG_ENABLE(werror, [AS_HELP_STRING([--enable-werror],
54                                      [turns on -Werror @<:@default=yes@:>@])])
55if test "x$enable_werror" != "xno"; then
56  WERROR="-Werror"
57fi
58AC_SUBST(WERROR)
59
60glibgo_toolexecdir=no
61glibgo_toolexeclibdir=no
62
63AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
64AC_ARG_ENABLE([version-specific-runtime-libs],
65  AC_HELP_STRING([--enable-version-specific-runtime-libs],
66                 [Specify that runtime libraries should be installed in a compiler-specific directory]),
67  [case "$enableval" in
68    yes) version_specific_libs=yes ;;
69    no)  version_specific_libs=no ;;
70    *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
71   esac],
72  [version_specific_libs=no])
73AC_MSG_RESULT($version_specific_libs)
74
75# Version-specific runtime libs processing.
76if test $version_specific_libs = yes; then
77  glibgo_toolexecdir='${libdir}/gcc/${host_alias}'
78  glibgo_toolexeclibdir='${toolexecdir}/${gcc_version}$(MULTISUBDIR)'
79fi
80
81# Calculate glibgo_toolexecdir, glibgo_toolexeclibdir
82# Install a library built with a cross compiler in tooldir, not libdir.
83if test -n "$with_cross_host" &&
84   test x"$with_cross_host" != x"no"; then
85  nover_glibgo_toolexecdir='${exec_prefix}/${host_alias}'
86  nover_glibgo_toolexeclibdir='${toolexecdir}/lib'
87else
88  nover_glibgo_toolexecdir='${libdir}/gcc/${host_alias}'
89  nover_glibgo_toolexeclibdir='${libdir}'
90fi
91multi_os_directory=`$CC -print-multi-os-directory`
92case $multi_os_directory in
93  .) ;; # Avoid trailing /.
94  *) nover_glibgo_toolexeclibdir=${nover_glibgo_toolexeclibdir}/${multi_os_directory} ;;
95esac
96
97if test x"$glibgo_toolexecdir" = x"no"; then
98  glibgo_toolexecdir="${nover_glibgo_toolexecdir}"
99  glibgo_toolexeclibdir="${nover_glibgo_toolexeclibdir}"
100fi
101
102AC_SUBST(glibgo_toolexecdir)
103AC_SUBST(glibgo_toolexeclibdir)
104AC_SUBST(nover_glibgo_toolexeclibdir)
105
106# See if the user wants to configure without libffi.  Some
107# architectures don't support it.  FIXME: We should set a default
108# based on the host.
109AC_ARG_WITH(libffi,
110  AS_HELP_STRING([--without-libffi],
111                 [don't use libffi]),
112  [:],
113  [with_libffi=${with_libffi_default-yes}])
114
115LIBFFI=
116LIBFFIINCS=
117if test "$with_libffi" != no; then
118   AC_DEFINE(USE_LIBFFI, 1, [Define if we're to use libffi.])
119   LIBFFI=../libffi/libffi_convenience.la
120   LIBFFIINCS='-I$(top_srcdir)/../libffi/include -I../libffi/include'
121fi
122AC_SUBST(LIBFFI)
123AC_SUBST(LIBFFIINCS)
124
125# Used to tell GNU make to include a file without telling automake to
126# include it.
127go_include="-include"
128AC_SUBST(go_include)
129
130is_darwin=no
131is_freebsd=no
132is_irix=no
133is_linux=no
134is_netbsd=no
135is_openbsd=no
136is_dragonfly=no
137is_rtems=no
138is_solaris=no
139GOOS=unknown
140case ${host} in
141  *-*-darwin*)   is_darwin=yes;  GOOS=darwin ;;
142  *-*-freebsd*)  is_freebsd=yes; GOOS=freebsd ;;
143  *-*-irix6*)    is_irix=yes;    GOOS=irix ;;
144  *-*-linux*)    is_linux=yes;   GOOS=linux ;;
145  *-*-netbsd*)	 is_netbsd=yes;  GOOS=netbsd ;;
146  *-*-openbsd*)  is_openbsd=yes; GOOS=openbsd ;;
147  *-*-dragonfly*) is_dragonfly=yes; GOOS=dragonfly ;;
148  *-*-rtems*)    is_rtems=yes;   GOOS=rtems ;;
149  *-*-solaris2*) is_solaris=yes; GOOS=solaris ;;
150esac
151AM_CONDITIONAL(LIBGO_IS_DARWIN, test $is_darwin = yes)
152AM_CONDITIONAL(LIBGO_IS_FREEBSD, test $is_freebsd = yes)
153AM_CONDITIONAL(LIBGO_IS_IRIX, test $is_irix = yes)
154AM_CONDITIONAL(LIBGO_IS_LINUX, test $is_linux = yes)
155AM_CONDITIONAL(LIBGO_IS_NETBSD, test $is_netbsd = yes)
156AM_CONDITIONAL(LIBGO_IS_OPENBSD, test $is_openbsd = yes)
157AM_CONDITIONAL(LIBGO_IS_DRAGONFLY, test $is_dragonfly = yes)
158AM_CONDITIONAL(LIBGO_IS_RTEMS, test $is_rtems = yes)
159AM_CONDITIONAL(LIBGO_IS_SOLARIS, test $is_solaris = yes)
160AC_SUBST(GOOS)
161
162dnl Test whether we need to use DejaGNU or whether we can use the
163dnl simpler gotest approach.  We can only use gotest for a native
164dnl build.
165USE_DEJAGNU=no
166case ${host} in
167  *-*-rtems*) USE_DEJAGNU=yes ;;
168  ${build}) ;;
169  *) USE_DEJAGNU=yes ;;
170esac
171AC_SUBST(USE_DEJAGNU)
172
173dnl N.B. Keep in sync with gcc/testsuite/go.test/go-test.exp (go-set-goarch).
174is_386=no
175is_alpha=no
176is_arm=no
177is_arm64=no
178is_m68k=no
179mips_abi=unknown
180is_ppc=no
181is_ppc64=no
182is_sparc=no
183is_sparc64=no
184is_x86_64=no
185GOARCH=unknown
186case ${host} in
187  alpha*-*-*)
188    is_alpha=yes
189    GOARCH=alpha
190    ;;
191  aarch64-*-*)
192    is_arm64=yes
193    GOARCH=arm64
194    ;;
195  arm*-*-* | strongarm*-*-* | ep9312*-*-* | xscale-*-*)
196    is_arm=yes
197    GOARCH=arm
198    ;;
199changequote(,)dnl
200  i[34567]86-*-* | x86_64-*-*)
201changequote([,])dnl
202    AC_COMPILE_IFELSE([
203#ifdef __x86_64__
204#error 64-bit
205#endif],
206[is_386=yes], [is_x86_64=yes])
207    if test "$is_386" = "yes"; then
208      GOARCH=386
209    else
210      GOARCH=amd64
211    fi
212    ;;
213  m68k*-*-*)
214    is_m68k=yes
215    GOARCH=m68k
216    ;;
217  mips*-*-*)
218    AC_COMPILE_IFELSE([
219#if _MIPS_SIM != _ABIO32
220#error not o32
221#endif],
222[mips_abi="o32"],
223	[AC_COMPILE_IFELSE([
224#if _MIPS_SIM != _ABIN32
225#error not n32
226#endif],
227[mips_abi="n32"],
228	[AC_COMPILE_IFELSE([
229#if _MIPS_SIM != _ABI64
230#error not n64
231#endif],
232[mips_abi="n64"],
233	[AC_COMPILE_IFELSE([
234#if _MIPS_SIM != _ABIO64
235#error not o64
236#endif],
237[mips_abi="o64"],
238	[AC_MSG_ERROR([unknown MIPS ABI])
239[mips_abi="n32"]])])])])
240    case "$mips_abi" in
241    "o32") GOARCH=mipso32 ;;
242    "n32") GOARCH=mipsn32 ;;
243    "n64") GOARCH=mipsn64 ;;
244    "o64") GOARCH=mipso64 ;;
245    esac
246    ;;
247  rs6000*-*-* | powerpc*-*-*)
248    AC_COMPILE_IFELSE([
249#ifdef _ARCH_PPC64
250#error 64-bit
251#endif],
252[is_ppc=yes], [is_ppc64=yes])
253    if test "$is_ppc" = "yes"; then
254      GOARCH=ppc
255    else
256      GOARCH=ppc64
257    fi
258    ;;
259  sparc*-*-*)
260    AC_COMPILE_IFELSE([
261#if defined(__sparcv9) || defined(__arch64__)
262#error 64-bit
263#endif],
264[is_sparc=yes], [is_sparc64=yes])
265    if test "$is_sparc" = "yes"; then
266      GOARCH=sparc
267    else
268      GOARCH=sparc64
269    fi
270    ;;
271esac
272AM_CONDITIONAL(LIBGO_IS_386, test $is_386 = yes)
273AM_CONDITIONAL(LIBGO_IS_ALPHA, test $is_alpha = yes)
274AM_CONDITIONAL(LIBGO_IS_ARM, test $is_arm = yes)
275AM_CONDITIONAL(LIBGO_IS_ARM64, test $is_arm64 = yes)
276AM_CONDITIONAL(LIBGO_IS_M68K, test $is_m68k = yes)
277AM_CONDITIONAL(LIBGO_IS_MIPS, test $mips_abi != unknown)
278AM_CONDITIONAL(LIBGO_IS_MIPSO32, test $mips_abi = o32)
279AM_CONDITIONAL(LIBGO_IS_MIPSN32, test $mips_abi = n32)
280AM_CONDITIONAL(LIBGO_IS_MIPSN64, test $mips_abi = n64)
281AM_CONDITIONAL(LIBGO_IS_MIPSO64, test $mips_abi = o64)
282AM_CONDITIONAL(LIBGO_IS_PPC, test $is_ppc = yes)
283AM_CONDITIONAL(LIBGO_IS_PPC64, test $is_ppc64 = yes)
284AM_CONDITIONAL(LIBGO_IS_SPARC, test $is_sparc = yes)
285AM_CONDITIONAL(LIBGO_IS_SPARC64, test $is_sparc64 = yes)
286AM_CONDITIONAL(LIBGO_IS_X86_64, test $is_x86_64 = yes)
287AC_SUBST(GOARCH)
288
289dnl Some files are only present when needed for specific architectures.
290GO_LIBCALL_OS_FILE=
291GO_LIBCALL_OS_ARCH_FILE=
292GO_SYSCALL_OS_FILE=
293GO_SYSCALL_OS_ARCH_FILE=
294if test -f ${srcdir}/go/syscall/libcall_${GOOS}.go; then
295  GO_LIBCALL_OS_FILE=go/syscall/libcall_${GOOS}.go
296fi
297if test -f ${srcdir}/go/syscall/libcall_${GOOS}_${GOARCH}.go; then
298  GO_LIBCALL_OS_ARCH_FILE=go/syscall/libcall_${GOOS}_${GOARCH}.go
299fi
300if test -f ${srcdir}/go/syscall/syscall_${GOOS}.go; then
301  GO_SYSCALL_OS_FILE=go/syscall/syscall_${GOOS}.go
302fi
303if test -f ${srcdir}/go/syscall/syscall_${GOOS}_${GOARCH}.go; then
304  GO_SYSCALL_OS_ARCH_FILE=go/syscall/syscall_${GOOS}_${GOARCH}.go
305fi
306AC_SUBST(GO_LIBCALL_OS_FILE)
307AC_SUBST(GO_LIBCALL_OS_ARCH_FILE)
308AC_SUBST(GO_SYSCALL_OS_FILE)
309AC_SUBST(GO_SYSCALL_OS_ARCH_FILE)
310
311dnl Special flags used to generate sysinfo.go.
312OSCFLAGS="-D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
313case "$target" in
314    mips-sgi-irix6.5*)
315	# IRIX 6 needs _XOPEN_SOURCE=500 for the XPG5 version of struct
316	# msghdr in <sys/socket.h>.
317	OSCFLAGS="$OSCFLAGS -D_XOPEN_SOURCE=500"
318	;;
319    *-*-solaris2.[[89]])
320	# Solaris 8/9 need this so struct msghdr gets the msg_control
321	# etc. fields in <sys/socket.h> (_XPG4_2).
322	OSCFLAGS="$OSCFLAGS -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D__EXTENSIONS__"
323	;;
324    *-*-solaris2.1[[01]])
325	# Solaris 10+ needs this so struct msghdr gets the msg_control
326	# etc. fields in <sys/socket.h> (_XPG4_2).  _XOPEN_SOURCE=600 as
327	# above doesn't work with C99.
328	OSCFLAGS="$OSCFLAGS -std=gnu99 -D_XOPEN_SOURCE=600 -D__EXTENSIONS__"
329	;;
330esac
331AC_SUBST(OSCFLAGS)
332
333dnl Use -fsplit-stack when compiling C code if available.
334AC_CACHE_CHECK([whether -fsplit-stack is supported],
335[libgo_cv_c_split_stack_supported],
336[CFLAGS_hold=$CFLAGS
337CFLAGS="$CFLAGS -fsplit-stack"
338AC_COMPILE_IFELSE([[int i;]],
339[libgo_cv_c_split_stack_supported=yes],
340[libgo_cv_c_split_stack_supported=no])
341CFLAGS=$CFLAGS_hold])
342if test "$libgo_cv_c_split_stack_supported" = yes; then
343  SPLIT_STACK=-fsplit-stack
344  AC_DEFINE(USING_SPLIT_STACK, 1,
345		[Define if the compiler supports -fsplit-stack])
346else
347  SPLIT_STACK=
348fi
349AC_SUBST(SPLIT_STACK)
350AM_CONDITIONAL(USING_SPLIT_STACK,
351	test "$libgo_cv_c_split_stack_supported" = yes)
352
353dnl Check whether the linker does stack munging when calling from
354dnl split-stack into non-split-stack code.  We check this by looking
355dnl at the --help output.  FIXME: This is only half right: it's
356dnl possible for the linker to support this for some targets but not
357dnl others.
358AC_CACHE_CHECK([whether linker supports split stack],
359[libgo_cv_c_linker_supports_split_stack],
360[libgo_cv_c_linker_supports_split_stack=no
361if $GOC -Wl,--help 2>/dev/null | grep split-stack-adjust-size >/dev/null 2>&1; then
362  libgo_cv_c_linker_supports_split_stack=yes
363fi])
364if test "$libgo_cv_c_linker_supports_split_stack" = yes; then
365  AC_DEFINE(LINKER_SUPPORTS_SPLIT_STACK, 1,
366	    [Define if the linker support split stack adjustments])
367fi
368
369dnl Test for the -lm library.
370MATH_LIBS=
371AC_CHECK_LIB([m], [sqrt], MATH_LIBS=-lm)
372AC_SUBST(MATH_LIBS)
373
374dnl Test for -lsocket and -lnsl.  Copied from libjava/configure.ac.
375AC_CACHE_CHECK([for socket libraries], libgo_cv_lib_sockets,
376  [libgo_cv_lib_sockets=
377   libgo_check_both=no
378   AC_CHECK_FUNC(connect, libgo_check_socket=no, libgo_check_socket=yes)
379   if test "$libgo_check_socket" = "yes"; then
380     unset ac_cv_func_connect
381     AC_CHECK_LIB(socket, main, libgo_cv_lib_sockets="-lsocket",
382     		  libgo_check_both=yes)
383   fi
384   if test "$libgo_check_both" = "yes"; then
385     libgo_old_libs=$LIBS
386     LIBS="$LIBS -lsocket -lnsl"
387     unset ac_cv_func_accept
388     AC_CHECK_FUNC(accept,
389		   [libgo_check_nsl=no
390		    libgo_cv_lib_sockets="-lsocket -lnsl"])
391     unset ac_cv_func_accept
392     LIBS=$libgo_old_libs
393   fi
394   unset ac_cv_func_gethostbyname
395   libgo_old_libs="$LIBS"
396   AC_CHECK_FUNC(gethostbyname, ,
397		 [AC_CHECK_LIB(nsl, main,
398		 	[libgo_cv_lib_sockets="$libgo_cv_lib_sockets -lnsl"])])
399   unset ac_cv_func_gethostbyname
400   LIBS=$libgo_old_libs
401])
402NET_LIBS="$libgo_cv_lib_sockets"
403AC_SUBST(NET_LIBS)
404
405dnl Test whether the compiler supports the -pthread option.
406AC_CACHE_CHECK([whether -pthread is supported],
407[libgo_cv_lib_pthread],
408[CFLAGS_hold=$CFLAGS
409CFLAGS="$CFLAGS -pthread"
410AC_COMPILE_IFELSE([[int i;]],
411[libgo_cv_lib_pthread=yes],
412[libgo_cv_lib_pthread=no])
413CFLAGS=$CFLAGS_hold])
414PTHREAD_CFLAGS=
415if test "$libgo_cv_lib_pthread" = yes; then
416  PTHREAD_CFLAGS=-pthread
417fi
418AC_SUBST(PTHREAD_CFLAGS)
419
420dnl Test for the -lpthread library.
421PTHREAD_LIBS=
422AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS=-lpthread)
423AC_SUBST(PTHREAD_LIBS)
424
425dnl Test if -lrt is required for sched_yield and/or nanosleep.
426AC_SEARCH_LIBS([sched_yield], [rt])
427AC_SEARCH_LIBS([nanosleep], [rt])
428
429AC_C_BIGENDIAN
430
431GCC_CHECK_UNWIND_GETIPINFO
432
433AC_ARG_ENABLE(sjlj-exceptions,
434  AC_HELP_STRING([--enable-sjlj-exceptions],
435		 [force use of builtin_setjmp for exceptions]),
436  [case "$enableval" in
437   yes|no|auto) ;;
438   *) AC_MSG_ERROR([unknown argument to --enable-sjlj-exceptions]) ;;
439   esac],
440  [enable_sjlj_exceptions=auto])
441
442AC_CACHE_CHECK([whether to use setjmp/longjmp exceptions],
443[libgo_cv_lib_sjlj_exceptions],
444[AC_LANG_CONFTEST(
445  [AC_LANG_SOURCE([
446void bar ();
447void clean (int *);
448void foo ()
449{
450  int i __attribute__ ((cleanup (clean)));
451  bar();
452}
453])])
454CFLAGS_hold=$CFLAGS
455CFLAGS="--save-temps -fexceptions"
456libgo_cv_lib_sjlj_exceptions=unknown
457AS_IF([ac_fn_c_try_compile],
458  [if grep _Unwind_SjLj_Resume conftest.s >/dev/null 2>&1; then
459    libgo_cv_lib_sjlj_exceptions=yes
460  elif grep _Unwind_Resume conftest.s >/dev/null 2>&1; then
461    libgo_cv_lib_sjlj_exceptions=no
462  fi])
463CFLAGS=$CFLAGS_hold
464rm -f conftest*
465])
466
467if test "$enable_sjlj_exceptions" = "auto"; then
468  enable_sjlj_exceptions=$libgo_cv_lib_sjlj_exceptions
469fi
470
471case $enable_sjlj_exceptions in
472yes)
473  AC_DEFINE(LIBGO_SJLJ_EXCEPTIONS, 1,
474	[Define if the C++ compiler is configured for setjmp/longjmp exceptions.])
475  ;;
476no)
477  ;;
478*)
479  AC_MSG_ERROR([unable to detect exception model])
480  ;;
481esac
482
483AC_CHECK_HEADERS(sched.h sys/file.h sys/mman.h syscall.h sys/epoll.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/if.h net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h linux/fs.h linux/reboot.h netinet/icmp6.h netinet/in_syst.h netinet/ip.h netinet/ip_mroute.h netinet/if_ether.h)
484
485AC_CHECK_HEADERS([linux/filter.h linux/if_addr.h linux/if_ether.h linux/if_tun.h linux/netlink.h linux/rtnetlink.h], [], [],
486[#ifdef HAVE_SYS_SOCKET_H
487#include <sys/socket.h>
488#endif
489])
490
491AC_CACHE_CHECK([whether <ustat.h> can be used],
492[libgo_cv_c_ustat_h],
493[CFLAGS_hold=$CFLAGS
494CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE $OSCFLAGS"
495AC_COMPILE_IFELSE(
496[AC_LANG_SOURCE([
497#include <sys/types.h>
498#ifdef HAVE_LINUX_FILTER_H
499#include <linux/filter.h>
500#endif
501#include <ustat.h>
502])], [libgo_cv_c_ustat_h=yes], [libgo_cv_c_ustat_h=no])
503CFLAGS=$CFLAGS_hold])
504if test $libgo_cv_c_ustat_h = yes; then
505  AC_DEFINE(HAVE_USTAT_H, 1,
506    [Define to 1 if you have the <ustat.h> header file and it works.])
507fi
508
509AM_CONDITIONAL(HAVE_SYS_MMAN_H, test "$ac_cv_header_sys_mman_h" = yes)
510
511AC_CHECK_FUNCS(strerror_r strsignal wait4 mincore setenv dl_iterate_phdr)
512AM_CONDITIONAL(HAVE_STRERROR_R, test "$ac_cv_func_strerror_r" = yes)
513AM_CONDITIONAL(HAVE_WAIT4, test "$ac_cv_func_wait4" = yes)
514
515AC_CHECK_FUNCS(accept4 dup3 epoll_create1 faccessat fallocate fchmodat fchownat futimesat getxattr inotify_add_watch inotify_init inotify_init1 inotify_rm_watch listxattr mkdirat mknodat open64 openat pipe2 removexattr renameat setxattr sync_file_range splice tee unlinkat unshare utimensat)
516AC_TYPE_OFF_T
517AC_CHECK_TYPES([loff_t])
518
519LIBS_hold="$LIBS"
520LIBS="$LIBS -lm"
521AC_CHECK_FUNCS(cosl expl logl sinl tanl acosl asinl atanl atan2l expm1l ldexpl log10l log1pl)
522LIBS="$LIBS_hold"
523
524CFLAGS_hold="$CFLAGS"
525CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
526LIBS_hold="$LIBS"
527LIBS="$LIBS $PTHREAD_LIBS"
528AC_CHECK_FUNCS(sem_timedwait)
529CFLAGS="$CFLAGS_hold"
530LIBS="$LIBS_hold"
531
532LIBS_hold="$LIBS"
533LIBS="$LIBS $MATH_LIBS"
534AC_CHECK_FUNCS(matherr)
535LIBS="$LIBS_hold"
536
537AC_CACHE_CHECK([for __sync_bool_compare_and_swap_4],
538[libgo_cv_func___sync_bool_compare_and_swap_4],
539[AC_LINK_IFELSE([
540typedef unsigned int uint32  __attribute__ ((mode (SI)));
541uint32 i;
542int main() { return __sync_bool_compare_and_swap (&i, 0, 1); }
543],
544[libgo_cv_func___sync_bool_compare_and_swap_4=yes],
545[libgo_cv_func___sync_bool_compare_and_swap_4=no])])
546if test "$libgo_cv_func___sync_bool_compare_and_swap_4" = "yes"; then
547  AC_DEFINE(HAVE_SYNC_BOOL_COMPARE_AND_SWAP_4, 1,
548    [Define to 1 if the compiler provides the __sync_bool_compare_and_swap function for uint32])
549fi
550
551AC_CACHE_CHECK([for __sync_bool_compare_and_swap_8],
552[libgo_cv_func___sync_bool_compare_and_swap_8],
553[AC_LINK_IFELSE([
554typedef unsigned int uint64  __attribute__ ((mode (DI)));
555uint64 i;
556int main() { return __sync_bool_compare_and_swap (&i, 0, 1); }
557],
558[libgo_cv_func___sync_bool_compare_and_swap_8=yes],
559[libgo_cv_func___sync_bool_compare_and_swap_8=no])])
560if test "$libgo_cv_func___sync_bool_compare_and_swap_8" = "yes"; then
561  AC_DEFINE(HAVE_SYNC_BOOL_COMPARE_AND_SWAP_8, 1,
562    [Define to 1 if the compiler provides the __sync_bool_compare_and_swap function for uint64])
563fi
564
565AC_CACHE_CHECK([for __sync_fetch_and_add_4],
566[libgo_cv_func___sync_fetch_and_add_4],
567[AC_LINK_IFELSE([
568typedef unsigned int uint32  __attribute__ ((mode (SI)));
569uint32 i;
570int main() { return __sync_fetch_and_add (&i, 1); }
571],
572[libgo_cv_func___sync_fetch_and_add_4=yes],
573[libgo_cv_func___sync_fetch_and_add_4=no])])
574if test "$libgo_cv_func___sync_fetch_and_add_4" = "yes"; then
575  AC_DEFINE(HAVE_SYNC_FETCH_AND_ADD_4, 1,
576    [Define to 1 if the compiler provides the __sync_fetch_and_add function for uint32])
577fi
578
579AC_CACHE_CHECK([for __sync_add_and_fetch_8],
580[libgo_cv_func___sync_add_and_fetch_8],
581[AC_LINK_IFELSE([
582typedef unsigned int uint64  __attribute__ ((mode (DI)));
583uint64 i;
584int main() { return __sync_add_and_fetch (&i, 1); }
585],
586[libgo_cv_func___sync_add_and_fetch_8=yes],
587[libgo_cv_func___sync_add_and_fetch_8=no])])
588if test "$libgo_cv_func___sync_add_and_fetch_8" = "yes"; then
589  AC_DEFINE(HAVE_SYNC_ADD_AND_FETCH_8, 1,
590    [Define to 1 if the compiler provides the __sync_add_and_fetch function for uint64])
591fi
592
593dnl For x86 we want to use the -minline-all-stringops option to avoid
594dnl forcing a stack split when calling memcpy and friends.
595AC_CACHE_CHECK([whether compiler supports -minline-all-stringops],
596[libgo_cv_c_stringops],
597[CFLAGS_hold=$CFLAGS
598CFLAGS="$CFLAGS -minline-all-stringops"
599AC_COMPILE_IFELSE([int i;],
600[libgo_cv_c_stringops=yes],
601[libgo_cv_c_stringops=no])
602CFLAGS=$CFLAGS_hold])
603STRINGOPS_FLAG=
604if test "$libgo_cv_c_stringops" = yes; then
605  STRINGOPS_FLAG=-minline-all-stringops
606fi
607AC_SUBST(STRINGOPS_FLAG)
608
609dnl For x86 we want to compile the math library with -mfancy-math-387
610dnl -funsafe-math-optimizations so that we can use the builtin
611dnl instructions directly.
612AC_CACHE_CHECK([whether compiler supports -mfancy-math-387],
613[libgo_cv_c_fancymath],
614[CFLAGS_hold=$CFLAGS
615CFLAGS="$CFLAGS -mfancy-math-387"
616AC_COMPILE_IFELSE([int i;],
617[libgo_cv_c_fancymath=yes],
618[libgo_cv_c_fancymath=no])
619CFLAGS=$CFLAGS_hold])
620MATH_FLAG=
621if test "$libgo_cv_c_fancymath" = yes; then
622  MATH_FLAG="-mfancy-math-387 -funsafe-math-optimizations"
623else
624  MATH_FLAG="-ffp-contract=off"
625fi
626AC_SUBST(MATH_FLAG)
627
628CFLAGS_hold=$CFLAGS
629CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"
630AC_CHECK_TYPES([off64_t])
631CFLAGS=$CFLAGS_hold
632
633dnl Work out the size of the epoll_events struct on GNU/Linux.
634AC_CACHE_CHECK([epoll_event size],
635[libgo_cv_c_epoll_event_size],
636[AC_COMPUTE_INT(libgo_cv_c_epoll_event_size,
637[sizeof (struct epoll_event)],
638[#include <sys/epoll.h>],
639[libgo_cv_c_epoll_event_size=0])])
640SIZEOF_STRUCT_EPOLL_EVENT=${libgo_cv_c_epoll_event_size}
641AC_SUBST(SIZEOF_STRUCT_EPOLL_EVENT)
642
643dnl Work out the offset of the fd field in the epoll_events struct on
644dnl GNU/Linux.
645AC_CACHE_CHECK([epoll_event data.fd offset],
646[libgo_cv_c_epoll_event_fd_offset],
647[AC_COMPUTE_INT(libgo_cv_c_epoll_event_fd_offset,
648[offsetof (struct epoll_event, data.fd)],
649[#include <stddef.h>
650#include <sys/epoll.h>],
651[libgo_cv_c_epoll_event_fd_offset=0])])
652STRUCT_EPOLL_EVENT_FD_OFFSET=${libgo_cv_c_epoll_event_fd_offset}
653AC_SUBST(STRUCT_EPOLL_EVENT_FD_OFFSET)
654
655dnl See if struct exception is defined in <math.h>.
656AC_CHECK_TYPE([struct exception],
657[libgo_has_struct_exception=yes],
658[libgo_has_struct_exception=no],
659[#include <math.h>])
660if test "$libgo_has_struct_exception" = "yes"; then
661  AC_DEFINE(HAVE_STRUCT_EXCEPTION, 1,
662            [Define to 1 if <math.h> defines struct exception])
663fi
664
665dnl Check if makecontext expects the uc_stack member of ucontext to point
666dnl to the top of the stack.
667case "$target" in
668  sparc*-*-solaris2.[[89]]*)
669    libgo_cv_lib_makecontext_stack_top=yes
670    ;;
671  *)
672    libgo_cv_lib_makecontext_stack_top=no
673    ;;
674esac
675if test "$libgo_cv_lib_makecontext_stack_top" = "yes"; then
676  AC_DEFINE(MAKECONTEXT_STACK_TOP, 1,
677	    [Define if makecontext expects top of stack in uc_stack.])
678fi
679
680dnl See whether setcontext changes the value of TLS variables.
681AC_CACHE_CHECK([whether setcontext clobbers TLS variables],
682[libgo_cv_lib_setcontext_clobbers_tls],
683[CFLAGS_hold="$CFLAGS"
684CFLAGS="$PTHREAD_CFLAGS"
685LIBS_hold="$LIBS"
686LIBS="$LIBS $PTHREAD_LIBS"
687AC_CHECK_SIZEOF([void *])
688AS_VAR_ARITH([ptr_type_size], [$ac_cv_sizeof_void_p \* 8])
689AC_RUN_IFELSE(
690  [AC_LANG_SOURCE([
691#include <pthread.h>
692#include <stdlib.h>
693#include <ucontext.h>
694#include <unistd.h>
695
696__thread int tls;
697
698static char stack[[10 * 1024 * 1024]];
699static ucontext_t c;
700
701/* Called via makecontext/setcontext.  */
702
703static void
704cfn (void)
705{
706  exit (tls);
707}
708
709/* Called via pthread_create.  */
710
711static void *
712tfn (void *dummy)
713{
714  /* The thread should still see this value after calling
715     setcontext.  */
716  tls = 0;
717
718  setcontext (&c);
719
720  /* The call to setcontext should not return.  */
721  abort ();
722}
723
724int
725main ()
726{
727  pthread_t tid;
728
729  /* The thread should not see this value.  */
730  tls = 1;
731
732  if (getcontext (&c) < 0)
733    abort ();
734
735  c.uc_stack.ss_sp = stack;
736#ifdef MAKECONTEXT_STACK_TOP
737  c.uc_stack.ss_sp += sizeof stack;
738#endif
739  c.uc_stack.ss_flags = 0;
740  c.uc_stack.ss_size = sizeof stack;
741  c.uc_link = NULL;
742  makecontext (&c, cfn, 0);
743
744  if (pthread_create (&tid, NULL, tfn, NULL) != 0)
745    abort ();
746
747  if (pthread_join (tid, NULL) != 0)
748    abort ();
749
750  /* The thread should have called exit.  */
751  abort ();
752}
753])],
754[libgo_cv_lib_setcontext_clobbers_tls=no],
755[libgo_cv_lib_setcontext_clobbers_tls=yes],
756[case "$target:$ptr_type_size" in
757  i?86-*-solaris2.1[[01]]:64 | x86_64*-*-solaris2.1[[01]]:64)
758    libgo_cv_lib_setcontext_clobbers_tls=yes ;;
759  *)
760    libgo_cv_lib_setcontext_clobbers_tls=no ;;
761 esac
762])
763CFLAGS="$CFLAGS_hold"
764LIBS="$LIBS_hold"
765])
766if test "$libgo_cv_lib_setcontext_clobbers_tls" = "yes"; then
767  AC_DEFINE(SETCONTEXT_CLOBBERS_TLS, 1,
768	    [Define if setcontext clobbers TLS variables])
769fi
770
771AC_CACHE_CHECK([whether .eh_frame section should be read-only],
772libgo_cv_ro_eh_frame, [
773libgo_cv_ro_eh_frame=no
774echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
775if $CC $CFLAGS -S -fpic -fexceptions -o conftest.s conftest.c > /dev/null 2>&1; then
776  if grep '.section.*eh_frame.*"a"' conftest.s > /dev/null; then
777    libgo_cv_ro_eh_frame=yes
778  elif grep '.section.*eh_frame.*#alloc' conftest.c \
779       | grep -v '#write' > /dev/null; then
780    libgo_cv_ro_eh_frame=yes
781  fi
782fi
783rm -f conftest.*
784])
785if test "x$libgo_cv_ro_eh_frame" = xyes; then
786  AC_DEFINE(EH_FRAME_FLAGS, "a",
787	    [Define to the flags needed for the .section .eh_frame directive.])
788else
789  AC_DEFINE(EH_FRAME_FLAGS, "aw",
790	    [Define to the flags needed for the .section .eh_frame directive.])
791fi
792
793AC_CACHE_CHECK([if assembler supports GNU comdat group syntax],
794libgo_cv_as_comdat_gnu, [
795echo '.section .text,"axG",@progbits,.foo,comdat' > conftest.s
796if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then
797  libgo_cv_as_comdat_gnu=yes
798else
799  libgo_cv_as_comdat_gnu=no
800fi
801])
802if test "x$libgo_cv_as_comdat_gnu" = xyes; then
803  AC_DEFINE(HAVE_AS_COMDAT_GAS, 1,
804	    [Define if your assembler supports GNU comdat group syntax.])
805fi
806
807AC_CACHE_CHECK([assembler supports pc related relocs],
808libgo_cv_as_x86_pcrel, [
809libgo_cv_as_x86_pcrel=yes
810echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
811if $CC $CFLAGS -c conftest.s 2>&1 | $EGREP -i 'illegal|warning' > /dev/null; then
812    libgo_cv_as_x86_pcrel=no
813fi
814])
815if test "x$libgo_cv_as_x86_pcrel" = xyes; then
816  AC_DEFINE(HAVE_AS_X86_PCREL, 1,
817	    [Define if your assembler supports PC relative relocs.])
818fi
819
820AC_CACHE_CHECK([assembler supports unwind section type],
821libgo_cv_as_x86_64_unwind_section_type, [
822libgo_cv_as_x86_64_unwind_section_type=yes
823echo '.section .eh_frame,"a",@unwind' > conftest.s
824if $CC $CFLAGS -c conftest.s 2>&1 | grep -i warning > /dev/null; then
825    libgo_cv_as_x86_64_unwind_section_type=no
826fi
827])
828if test "x$libgo_cv_as_x86_64_unwind_section_type" = xyes; then
829  AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
830	    [Define if your assembler supports unwind section type.])
831fi
832
833AC_CACHE_SAVE
834
835if test ${multilib} = yes; then
836  multilib_arg="--enable-multilib"
837else
838  multilib_arg=
839fi
840
841AC_CONFIG_FILES(Makefile testsuite/Makefile)
842
843AC_CONFIG_COMMANDS([default],
844[if test -n "$CONFIG_FILES"; then
845   # Multilibs need MULTISUBDIR defined correctly in certain makefiles so
846   # that multilib installs will end up installed in the correct place.
847   # The testsuite needs it for multilib-aware ABI baseline files.
848   # To work around this not being passed down from config-ml.in ->
849   # srcdir/Makefile.am -> srcdir/{src,libsupc++,...}/Makefile.am, manually
850   # append it here.  Only modify Makefiles that have just been created.
851   #
852   # Also, get rid of this simulated-VPATH thing that automake does.
853   cat > vpsed << \_EOF
854s!`test -f '$<' || echo '$(srcdir)/'`!!
855_EOF
856   for i in $SUBDIRS; do
857    case $CONFIG_FILES in
858     *${i}/Makefile*)
859       #echo "Adding MULTISUBDIR to $i/Makefile"
860       sed -f vpsed $i/Makefile > tmp
861       grep '^MULTISUBDIR =' Makefile >> tmp
862       mv tmp $i/Makefile
863       ;;
864    esac
865   done
866   rm vpsed
867 fi
868],
869[
870# Variables needed in config.status (file generation) which aren't already
871# passed by autoconf.
872SUBDIRS="$SUBDIRS"
873])
874
875AC_OUTPUT
876