OSDN Git Service

a1356bd7b06cb33dfdd122b114cdd4ec100e28f8
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / acinclude.m4
1
2 dnl
3 dnl GLIBCXX_CONDITIONAL (NAME, SHELL-TEST)
4 dnl
5 dnl Exactly like AM_CONDITIONAL, but delays evaluation of the test until the
6 dnl end of configure.  This lets tested variables be reassigned, and the
7 dnl conditional will depend on the final state of the variable.  For a simple
8 dnl example of why this is needed, see GLIBCXX_ENABLE_HOSTED.
9 dnl
10 m4_define([_m4_divert(glibcxx_diversion)], 8000)dnl
11 AC_DEFUN([GLIBCXX_CONDITIONAL], [dnl
12   m4_divert_text([glibcxx_diversion],dnl
13    AM_CONDITIONAL([$1],[$2])
14   )dnl
15 ])dnl
16 AC_DEFUN([GLIBCXX_EVALUATE_CONDITIONALS], [m4_undivert([glibcxx_diversion])])dnl
17
18
19 dnl
20 dnl Check to see what architecture and operating system we are compiling
21 dnl for.  Also, if architecture- or OS-specific flags are required for
22 dnl compilation, pick them up here.
23 dnl
24 AC_DEFUN([GLIBCXX_CHECK_HOST], [
25   . $glibcxx_srcdir/configure.host
26   AC_MSG_NOTICE([CPU config directory is $cpu_include_dir])
27   AC_MSG_NOTICE([OS config directory is $os_include_dir])
28 ])
29
30 dnl
31 dnl Initialize the rest of the library configury.  At this point we have
32 dnl variables like $host.
33 dnl
34 dnl Sets:
35 dnl  SUBDIRS
36 dnl Substs:
37 dnl  glibcxx_builddir     (absolute path)
38 dnl  glibcxx_srcdir       (absolute path)
39 dnl  toplevel_srcdir      (absolute path)
40 dnl  with_cross_host
41 dnl  with_newlib
42 dnl  with_target_subdir
43 dnl plus
44 dnl  - the variables in GLIBCXX_CHECK_HOST / configure.host
45 dnl  - default settings for all AM_CONFITIONAL test variables
46 dnl  - lots of tools, like CC and CXX
47 dnl
48 AC_DEFUN([GLIBCXX_CONFIGURE], [
49   # Keep these sync'd with the list in Makefile.am.  The first provides an
50   # expandable list at autoconf time; the second provides an expandable list
51   # (i.e., shell variable) at configure time.
52   m4_define([glibcxx_SUBDIRS],[include libmath libsupc++ src doc po testsuite])
53   SUBDIRS='glibcxx_SUBDIRS'
54
55   # These need to be absolute paths, yet at the same time need to
56   # canonicalize only relative paths, because then amd will not unmount
57   # drives. Thus the use of PWDCMD: set it to 'pawd' or 'amq -w' if using amd.
58   glibcxx_builddir=`${PWDCMD-pwd}`
59   case $srcdir in
60     [\\/$]* | ?:[\\/]*) glibcxx_srcdir=${srcdir} ;;
61     *) glibcxx_srcdir=`cd "$srcdir" && ${PWDCMD-pwd} || echo "$srcdir"` ;;
62   esac
63   toplevel_srcdir=${glibcxx_srcdir}/..
64   AC_SUBST(glibcxx_builddir)
65   AC_SUBST(glibcxx_srcdir)
66   AC_SUBST(toplevel_srcdir)
67
68   # We use these options to decide which functions to include.  They are
69   # set from the top level.
70   AC_ARG_WITH([target-subdir],
71     AC_HELP_STRING([--with-target-subdir=SUBDIR],
72                    [configuring in a subdirectory]))
73
74   AC_ARG_WITH([cross-host],
75     AC_HELP_STRING([--with-cross-host=HOST],
76                    [configuring with a cross compiler]))
77
78   AC_ARG_WITH([newlib],
79     AC_HELP_STRING([--with-newlib],
80                    [assume newlib as a system C library]))
81
82   # We're almost certainly being configured before anything else which uses
83   # C++, so all of our AC_PROG_* discoveries will be cached.  It's vital that
84   # we not cache the value of CXX that we "discover" here, because it's set
85   # to something unique for us and libjava.  Other target libraries need to
86   # find CXX for themselves.  We yank the rug out from under the normal AC_*
87   # process by sneakily renaming the cache variable.  This also lets us debug
88   # the value of "our" CXX in postmortems.
89   #
90   # We must also force CXX to /not/ be a precious variable, otherwise the
91   # wrong (non-multilib-adjusted) value will be used in multilibs.  This
92   # little trick also affects CPPFLAGS, CXXFLAGS, and LDFLAGS.  And as a side
93   # effect, CXXFLAGS is no longer automagically subst'd, so we have to do
94   # that ourselves.  Un-preciousing AC_PROG_CC also affects CC and CFLAGS.
95   #
96   # -fno-builtin must be present here so that a non-conflicting form of
97   # std::exit can be guessed by AC_PROG_CXX, and used in later tests.
98
99   m4_define([ac_cv_prog_CXX],[glibcxx_cv_prog_CXX])
100   m4_rename([_AC_ARG_VAR_PRECIOUS],[glibcxx_PRECIOUS])
101   m4_define([_AC_ARG_VAR_PRECIOUS],[])
102   save_CXXFLAGS="$CXXFLAGS"
103   CXXFLAGS="$CXXFLAGS -fno-builtin"
104   AC_PROG_CC
105   AC_PROG_CXX
106   CXXFLAGS="$save_CXXFLAGS"
107   m4_rename([glibcxx_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
108   AC_SUBST(CFLAGS)
109   AC_SUBST(CXXFLAGS)
110
111   # Will set LN_S to either 'ln -s', 'ln', or 'cp -p' (if linking isn't
112   # available).  Uncomment the next line to force a particular method.
113   AC_PROG_LN_S
114   #LN_S='cp -p'
115
116   AC_CHECK_TOOL(AS, as)
117   AC_CHECK_TOOL(AR, ar)
118   AC_CHECK_TOOL(RANLIB, ranlib, ranlib-not-found-in-path-error)
119
120   AM_MAINTAINER_MODE
121
122   # Set up safe default values for all subsequent AM_CONDITIONAL tests
123   # which are themselves conditionally expanded.
124   ## (Right now, this only matters for enable_wchar_t, but nothing prevents
125   ## other macros from doing the same.  This should be automated.)  -pme
126   need_libmath=no
127
128   # Check for uClibc since Linux platforms use different configuration
129   # directories depending on the C library in use.
130   AC_EGREP_CPP([_using_uclibc], [
131   #include <stdio.h>
132   #if __UCLIBC__
133     _using_uclibc
134   #endif
135   ], uclibc=yes, uclibc=no)
136
137   # Find platform-specific directories containing configuration info.
138   # Also possibly modify flags used elsewhere, as needed by the platform.
139   GLIBCXX_CHECK_HOST
140 ])
141
142
143 dnl
144 dnl Tests for newer compiler features, or features that are present in newer
145 dnl compiler versions but not older compiler versions still in use, should
146 dnl be placed here.
147 dnl
148 dnl Defines:
149 dnl  WERROR='-Werror' if requested and possible; g++'s that lack the
150 dnl   new inlining code or the new system_header pragma will die on -Werror.
151 dnl   Leave it out by default and use maint-mode to use it.
152 dnl  SECTION_FLAGS='-ffunction-sections -fdata-sections' if
153 dnl   compiler supports it and the user has not requested debug mode.
154 dnl
155 AC_DEFUN([GLIBCXX_CHECK_COMPILER_FEATURES], [
156   # All these tests are for C++; save the language and the compiler flags.
157   # The CXXFLAGS thing is suspicious, but based on similar bits previously
158   # found in GLIBCXX_CONFIGURE.
159   AC_LANG_SAVE
160   AC_LANG_CPLUSPLUS
161   ac_test_CXXFLAGS="${CXXFLAGS+set}"
162   ac_save_CXXFLAGS="$CXXFLAGS"
163
164   # Check for maintainer-mode bits.
165   if test x"$USE_MAINTAINER_MODE" = xno; then
166     WERROR=''
167   else
168     WERROR='-Werror'
169   fi
170
171   # Check for -ffunction-sections -fdata-sections
172   AC_MSG_CHECKING([for g++ that supports -ffunction-sections -fdata-sections])
173   CXXFLAGS='-g -Werror -ffunction-sections -fdata-sections'
174   AC_TRY_COMPILE([int foo; void bar() { };],, [ac_fdsections=yes], [ac_fdsections=no])
175   if test "$ac_test_CXXFLAGS" = set; then
176     CXXFLAGS="$ac_save_CXXFLAGS"
177   else
178     # this is the suspicious part
179     CXXFLAGS=''
180   fi
181   if test x"$ac_fdsections" = x"yes"; then
182     SECTION_FLAGS='-ffunction-sections -fdata-sections'
183   fi
184   AC_MSG_RESULT($ac_fdsections)
185
186   AC_LANG_RESTORE
187   AC_SUBST(WERROR)
188   AC_SUBST(SECTION_FLAGS)
189 ])
190
191
192 dnl
193 dnl If GNU ld is in use, check to see if tricky linker opts can be used.  If
194 dnl the native linker is in use, all variables will be defined to something
195 dnl safe (like an empty string).
196 dnl
197 dnl Defines:
198 dnl  SECTION_LDFLAGS='-Wl,--gc-sections' if possible
199 dnl  OPT_LDFLAGS='-Wl,-O1' and '-z,relro' if possible
200 dnl  LD (as a side effect of testing)
201 dnl Sets:
202 dnl  with_gnu_ld
203 dnl  glibcxx_ld_is_gold (set to "no" or "yes")
204 dnl  glibcxx_gnu_ld_version (possibly)
205 dnl
206 dnl The last will be a single integer, e.g., version 1.23.45.0.67.89 will
207 dnl set glibcxx_gnu_ld_version to 12345.  Zeros cause problems.
208 dnl
209 AC_DEFUN([GLIBCXX_CHECK_LINKER_FEATURES], [
210   # If we're not using GNU ld, then there's no point in even trying these
211   # tests.  Check for that first.  We should have already tested for gld
212   # by now (in libtool), but require it now just to be safe...
213   test -z "$SECTION_LDFLAGS" && SECTION_LDFLAGS=''
214   test -z "$OPT_LDFLAGS" && OPT_LDFLAGS=''
215   AC_REQUIRE([AC_PROG_LD])
216   AC_REQUIRE([AC_PROG_AWK])
217
218   # The name set by libtool depends on the version of libtool.  Shame on us
219   # for depending on an impl detail, but c'est la vie.  Older versions used
220   # ac_cv_prog_gnu_ld, but now it's lt_cv_prog_gnu_ld, and is copied back on
221   # top of with_gnu_ld (which is also set by --with-gnu-ld, so that actually
222   # makes sense).  We'll test with_gnu_ld everywhere else, so if that isn't
223   # set (hence we're using an older libtool), then set it.
224   if test x${with_gnu_ld+set} != xset; then
225     if test x${ac_cv_prog_gnu_ld+set} != xset; then
226       # We got through "ac_require(ac_prog_ld)" and still not set?  Huh?
227       with_gnu_ld=no
228     else
229       with_gnu_ld=$ac_cv_prog_gnu_ld
230     fi
231   fi
232
233   # Start by getting the version number.  I think the libtool test already
234   # does some of this, but throws away the result.
235   glibcxx_ld_is_gold=no
236   if test x"$with_gnu_ld" = x"yes"; then
237     AC_MSG_CHECKING([for ld version])
238     changequote(,)
239     if $LD --version 2>/dev/null | grep 'GNU gold' >/dev/null 2>&1; then
240       glibcxx_ld_is_gold=yes
241     fi
242     ldver=`$LD --version 2>/dev/null | head -1 | \
243            sed -e 's/GNU \(go\)\{0,1\}ld \(version \)\{0,1\}\(([^)]*) \)\{0,1\}\([0-9.][0-9.]*\).*/\4/'`
244     changequote([,])
245     glibcxx_gnu_ld_version=`echo $ldver | \
246            $AWK -F. '{ if (NF<3) [$]3=0; print ([$]1*100+[$]2)*100+[$]3 }'`
247     AC_MSG_RESULT($glibcxx_gnu_ld_version)
248   fi
249
250   # Set --gc-sections.
251   glibcxx_have_gc_sections=no
252   if test "$glibcxx_ld_is_gold" = "yes"; then
253     if $LD --help 2>/dev/null | grep gc-sections >/dev/null 2>&1; then
254       glibcxx_have_gc_sections=yes
255     fi
256   else
257     glibcxx_gcsections_min_ld=21602
258     if test x"$with_gnu_ld" = x"yes" && 
259         test $glibcxx_gnu_ld_version -gt $glibcxx_gcsections_min_ld ; then
260       glibcxx_have_gc_sections=yes
261     fi
262   fi
263   if test "$glibcxx_have_gc_sections" = "yes"; then
264     # Sufficiently young GNU ld it is!  Joy and bunny rabbits!
265     # NB: This flag only works reliably after 2.16.1. Configure tests
266     # for this are difficult, so hard wire a value that should work.
267
268     ac_test_CFLAGS="${CFLAGS+set}"
269     ac_save_CFLAGS="$CFLAGS"
270     CFLAGS='-Wl,--gc-sections'
271
272     # Check for -Wl,--gc-sections
273     AC_MSG_CHECKING([for ld that supports -Wl,--gc-sections])
274     AC_TRY_LINK([ int one(void) { return 1; }
275      int two(void) { return 2; }
276         ], [ two(); ] , [ac_gcsections=yes], [ac_gcsections=no])
277     if test "$ac_gcsections" = "yes"; then
278       rm -f conftest.c
279       touch conftest.c
280       if $CC -c conftest.c; then
281         if $LD --gc-sections -o conftest conftest.o 2>&1 | \
282            grep "Warning: gc-sections option ignored" > /dev/null; then
283           ac_gcsections=no
284         fi
285       fi
286       rm -f conftest.c conftest.o conftest
287     fi
288     if test "$ac_gcsections" = "yes"; then
289       SECTION_LDFLAGS="-Wl,--gc-sections $SECTION_LDFLAGS"
290     fi
291     AC_MSG_RESULT($ac_gcsections)
292
293     if test "$ac_test_CFLAGS" = set; then
294       CFLAGS="$ac_save_CFLAGS"
295     else
296       # this is the suspicious part
297       CFLAGS=''
298     fi
299   fi
300
301   # Set -z,relro.
302   # Note this is only for shared objects.
303   ac_ld_relro=no
304   if test x"$with_gnu_ld" = x"yes"; then
305     AC_MSG_CHECKING([for ld that supports -Wl,-z,relro])
306     cxx_z_relo=`$LD -v --help 2>/dev/null | grep "z relro"`
307     if test -n "$cxx_z_relo"; then
308       OPT_LDFLAGS="-Wl,-z,relro"
309       ac_ld_relro=yes
310     fi
311     AC_MSG_RESULT($ac_ld_relro)
312   fi
313
314   # Set linker optimization flags.
315   if test x"$with_gnu_ld" = x"yes"; then
316     OPT_LDFLAGS="-Wl,-O1 $OPT_LDFLAGS"
317   fi
318
319   AC_SUBST(SECTION_LDFLAGS)
320   AC_SUBST(OPT_LDFLAGS)
321 ])
322
323
324 dnl
325 dnl Check for headers for, and arguments to, the setrlimit() function.
326 dnl Used only in testsuite_hooks.h.  Called from GLIBCXX_CONFIGURE_TESTSUITE.
327 dnl
328 dnl Defines:
329 dnl  _GLIBCXX_RES_LIMITS if we can set artificial resource limits 
330 dnl  various HAVE_LIMIT_* for individual limit names
331 dnl
332 AC_DEFUN([GLIBCXX_CHECK_SETRLIMIT_ancilliary], [
333   AC_MSG_CHECKING([for RLIMIT_$1])
334   AC_TRY_COMPILE(
335     [#include <unistd.h>
336      #include <sys/time.h>
337      #include <sys/resource.h>
338     ],
339     [ int f = RLIMIT_$1 ; ],
340     [glibcxx_mresult=1], [glibcxx_mresult=0])
341   AC_DEFINE_UNQUOTED(HAVE_LIMIT_$1, $glibcxx_mresult,
342                      [Only used in build directory testsuite_hooks.h.])
343   if test $glibcxx_mresult = 1 ; then res=yes ; else res=no ; fi
344   AC_MSG_RESULT($res)
345 ])
346
347 AC_DEFUN([GLIBCXX_CHECK_SETRLIMIT], [
348   setrlimit_have_headers=yes
349   AC_CHECK_HEADERS(unistd.h sys/time.h sys/resource.h,
350                    [],
351                    [setrlimit_have_headers=no])
352   # If don't have the headers, then we can't run the tests now, and we
353   # won't be seeing any of these during testsuite compilation.
354   if test $setrlimit_have_headers = yes; then
355     # Can't do these in a loop, else the resulting syntax is wrong.
356     GLIBCXX_CHECK_SETRLIMIT_ancilliary(DATA)
357     GLIBCXX_CHECK_SETRLIMIT_ancilliary(RSS)
358     GLIBCXX_CHECK_SETRLIMIT_ancilliary(VMEM)
359     GLIBCXX_CHECK_SETRLIMIT_ancilliary(AS)
360     GLIBCXX_CHECK_SETRLIMIT_ancilliary(FSIZE)
361
362     # Check for rlimit, setrlimit.
363     AC_CACHE_VAL(glibcxx_cv_setrlimit, [
364       AC_TRY_COMPILE(
365         [#include <unistd.h>
366          #include <sys/time.h>
367          #include <sys/resource.h>
368         ],
369         [struct rlimit r;
370          setrlimit(0, &r);],
371         [glibcxx_cv_setrlimit=yes], [glibcxx_cv_setrlimit=no])
372     ])
373   fi
374
375   AC_MSG_CHECKING([for testsuite resource limits support])
376   if test $setrlimit_have_headers = yes && test $glibcxx_cv_setrlimit = yes; then
377     ac_res_limits=yes
378     AC_DEFINE(_GLIBCXX_RES_LIMITS, 1,
379               [Define if using setrlimit to set resource limits during
380               "make check"])
381   else
382     ac_res_limits=no
383   fi
384   AC_MSG_RESULT($ac_res_limits)
385 ])
386
387
388 dnl
389 dnl Check whether S_ISREG (Posix) or S_IFREG is available in <sys/stat.h>.
390 dnl Define HAVE_S_ISREG / HAVE_S_IFREG appropriately.
391 dnl
392 AC_DEFUN([GLIBCXX_CHECK_S_ISREG_OR_S_IFREG], [
393
394   AC_LANG_SAVE
395   AC_LANG_CPLUSPLUS
396   ac_save_CXXFLAGS="$CXXFLAGS"
397   CXXFLAGS="$CXXFLAGS -fno-exceptions"
398
399   AC_MSG_CHECKING([for S_ISREG or S_IFREG])
400   AC_CACHE_VAL(glibcxx_cv_S_ISREG, [
401     GCC_TRY_COMPILE_OR_LINK(
402       [#include <sys/stat.h>],
403       [struct stat buffer;
404        fstat(0, &buffer);
405        S_ISREG(buffer.st_mode);],
406       [glibcxx_cv_S_ISREG=yes],
407       [glibcxx_cv_S_ISREG=no])
408   ])
409   AC_CACHE_VAL(glibcxx_cv_S_IFREG, [
410     GCC_TRY_COMPILE_OR_LINK(
411       [#include <sys/stat.h>],
412       [struct stat buffer;
413        fstat(0, &buffer);
414        S_IFREG & buffer.st_mode;],
415       [glibcxx_cv_S_IFREG=yes],
416       [glibcxx_cv_S_IFREG=no])
417   ])
418   res=no
419   if test $glibcxx_cv_S_ISREG = yes; then
420     AC_DEFINE(HAVE_S_ISREG, 1, 
421               [Define if S_IFREG is available in <sys/stat.h>.])
422     res=S_ISREG
423   elif test $glibcxx_cv_S_IFREG = yes; then
424     AC_DEFINE(HAVE_S_IFREG, 1,
425               [Define if S_IFREG is available in <sys/stat.h>.])
426     res=S_IFREG
427   fi
428   AC_MSG_RESULT($res)
429
430   CXXFLAGS="$ac_save_CXXFLAGS"
431   AC_LANG_RESTORE
432 ])
433
434
435 dnl
436 dnl Check whether poll is available in <poll.h>, and define HAVE_POLL.
437 dnl
438 AC_DEFUN([GLIBCXX_CHECK_POLL], [
439
440   AC_LANG_SAVE
441   AC_LANG_CPLUSPLUS
442   ac_save_CXXFLAGS="$CXXFLAGS"
443   CXXFLAGS="$CXXFLAGS -fno-exceptions"
444
445   AC_MSG_CHECKING([for poll])
446   AC_CACHE_VAL(glibcxx_cv_POLL, [
447     GCC_TRY_COMPILE_OR_LINK(
448       [#include <poll.h>],
449       [struct pollfd pfd[1];
450        pfd[0].events = POLLIN;
451        poll(pfd, 1, 0);],
452       [glibcxx_cv_POLL=yes],
453       [glibcxx_cv_POLL=no])
454   ])
455   if test $glibcxx_cv_POLL = yes; then
456     AC_DEFINE(HAVE_POLL, 1, [Define if poll is available in <poll.h>.])
457   fi
458   AC_MSG_RESULT($glibcxx_cv_POLL)
459
460   CXXFLAGS="$ac_save_CXXFLAGS"
461   AC_LANG_RESTORE
462 ])
463
464
465 dnl
466 dnl Check whether writev is available in <sys/uio.h>, and define HAVE_WRITEV.
467 dnl
468 AC_DEFUN([GLIBCXX_CHECK_WRITEV], [
469
470   AC_LANG_SAVE
471   AC_LANG_CPLUSPLUS
472   ac_save_CXXFLAGS="$CXXFLAGS"
473   CXXFLAGS="$CXXFLAGS -fno-exceptions"
474
475   AC_MSG_CHECKING([for writev])
476   AC_CACHE_VAL(glibcxx_cv_WRITEV, [
477     GCC_TRY_COMPILE_OR_LINK(
478       [#include <sys/uio.h>],
479       [struct iovec iov[2];
480        writev(0, iov, 0);],
481       [glibcxx_cv_WRITEV=yes],
482       [glibcxx_cv_WRITEV=no])
483   ])
484   if test $glibcxx_cv_WRITEV = yes; then
485     AC_DEFINE(HAVE_WRITEV, 1, [Define if writev is available in <sys/uio.h>.])
486   fi
487   AC_MSG_RESULT($glibcxx_cv_WRITEV)
488
489   CXXFLAGS="$ac_save_CXXFLAGS"
490   AC_LANG_RESTORE
491 ])
492
493
494 dnl
495 dnl Check whether int64_t is available in <stdint.h>, and define HAVE_INT64_T.
496 dnl Also check whether int64_t is actually a typedef to long or long long.
497 dnl
498 AC_DEFUN([GLIBCXX_CHECK_INT64_T], [
499
500   AC_LANG_SAVE
501   AC_LANG_CPLUSPLUS
502
503   AC_MSG_CHECKING([for int64_t])
504   AC_CACHE_VAL(glibcxx_cv_INT64_T, [
505     AC_TRY_COMPILE(
506       [#include <stdint.h>],
507       [int64_t var;],
508       [glibcxx_cv_INT64_T=yes],
509       [glibcxx_cv_INT64_T=no])
510   ])
511
512   if test $glibcxx_cv_INT64_T = yes; then
513     AC_DEFINE(HAVE_INT64_T, 1, [Define if int64_t is available in <stdint.h>.])
514     AC_MSG_RESULT($glibcxx_cv_INT64_T)
515
516     AC_MSG_CHECKING([for int64_t as long])
517     AC_CACHE_VAL(glibcxx_cv_int64_t_long, [
518       AC_TRY_COMPILE(
519         [#include <stdint.h>
520         template<typename, typename> struct same { enum { value = -1 }; };
521         template<typename Tp> struct same<Tp, Tp> { enum { value = 1 }; };
522         int array[same<int64_t, long>::value];], [],
523         [glibcxx_cv_int64_t_long=yes], [glibcxx_cv_int64_t_long=no])
524     ])
525
526     if test $glibcxx_cv_int64_t_long = yes; then
527       AC_DEFINE(HAVE_INT64_T_LONG, 1, [Define if int64_t is a long.])
528       AC_MSG_RESULT($glibcxx_cv_int64_t_long)
529     fi
530
531     AC_MSG_CHECKING([for int64_t as long long])
532     AC_CACHE_VAL(glibcxx_cv_int64_t_long_long, [
533       AC_TRY_COMPILE(
534         [#include <stdint.h>
535         template<typename, typename> struct same { enum { value = -1 }; };
536         template<typename Tp> struct same<Tp, Tp> { enum { value = 1 }; };
537         int array[same<int64_t, long long>::value];], [],
538         [glibcxx_cv_int64_t_long_long=yes], [glibcxx_cv_int64_t_long_long=no])
539     ])
540
541     if test $glibcxx_cv_int64_t_long_long = yes; then
542       AC_DEFINE(HAVE_INT64_T_LONG_LONG, 1, [Define if int64_t is a long long.])
543       AC_MSG_RESULT($glibcxx_cv_int64_t_long_long)
544     fi
545   fi
546
547   AC_LANG_RESTORE
548 ])
549
550
551 dnl
552 dnl Check whether LFS support is available.
553 dnl
554 AC_DEFUN([GLIBCXX_CHECK_LFS], [
555   AC_LANG_SAVE
556   AC_LANG_CPLUSPLUS
557   ac_save_CXXFLAGS="$CXXFLAGS"
558   CXXFLAGS="$CXXFLAGS -fno-exceptions"  
559   AC_MSG_CHECKING([for LFS support])
560   AC_CACHE_VAL(glibcxx_cv_LFS, [
561     GCC_TRY_COMPILE_OR_LINK(
562       [#include <unistd.h>
563        #include <stdio.h>
564        #include <sys/stat.h>
565       ],
566       [FILE* fp;
567        fopen64("t", "w");
568        fseeko64(fp, 0, SEEK_CUR);
569        ftello64(fp);
570        lseek64(1, 0, SEEK_CUR);
571        struct stat64 buf;
572        fstat64(1, &buf);],
573       [glibcxx_cv_LFS=yes],
574       [glibcxx_cv_LFS=no])
575   ])
576   if test $glibcxx_cv_LFS = yes; then
577     AC_DEFINE(_GLIBCXX_USE_LFS, 1, [Define if LFS support is available.])
578   fi
579   AC_MSG_RESULT($glibcxx_cv_LFS)
580   CXXFLAGS="$ac_save_CXXFLAGS"
581   AC_LANG_RESTORE
582 ])
583
584
585 dnl
586 dnl Check for whether a fully dynamic basic_string implementation should
587 dnl be turned on, that does not put empty objects in per-process static
588 dnl memory (mostly useful together with shared memory allocators, see PR
589 dnl libstdc++/16612 for details).
590 dnl
591 dnl --enable-fully-dynamic-string defines _GLIBCXX_FULLY_DYNAMIC_STRING
592 dnl --disable-fully-dynamic-string leaves _GLIBCXX_FULLY_DYNAMIC_STRING undefined
593 dnl  +  Usage:  GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING[(DEFAULT)]
594 dnl       Where DEFAULT is either `yes' or `no'.
595 dnl
596 AC_DEFUN([GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING], [
597   GLIBCXX_ENABLE(fully-dynamic-string,$1,,[do not put empty strings in per-process static memory])
598   if test $enable_fully_dynamic_string = yes; then
599     AC_DEFINE(_GLIBCXX_FULLY_DYNAMIC_STRING, 1,
600               [Define if a fully dynamic basic_string is wanted.])
601   fi
602 ])
603
604
605 dnl
606 dnl Does any necessary configuration of the testsuite directory.  Generates
607 dnl the testsuite_hooks.h header.
608 dnl
609 dnl GLIBCXX_ENABLE_SYMVERS and GLIBCXX_IS_NATIVE must be done before this.
610 dnl
611 dnl Sets:
612 dnl  enable_abi_check 
613 dnl  GLIBCXX_TEST_WCHAR_T
614 dnl  GLIBCXX_TEST_THREAD
615 dnl Substs:
616 dnl  baseline_dir
617 dnl
618 AC_DEFUN([GLIBCXX_CONFIGURE_TESTSUITE], [
619   if $GLIBCXX_IS_NATIVE ; then
620     # Do checks for resource limit functions.
621     GLIBCXX_CHECK_SETRLIMIT
622
623     # Look for setenv, so that extended locale tests can be performed.
624     GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_3(setenv)
625   fi
626
627   if $GLIBCXX_IS_NATIVE && test $is_hosted = yes &&
628      test $enable_symvers != no; then
629     case "$host" in
630       *-*-cygwin*)
631         enable_abi_check=no ;;
632       *)
633         enable_abi_check=yes ;;
634     esac
635   else
636     # Only build this as native, since automake does not understand
637     # CXX_FOR_BUILD.
638     enable_abi_check=no
639   fi
640   
641   # Export file names for ABI checking.
642   baseline_dir="$glibcxx_srcdir/config/abi/post/${abi_baseline_pair}\$(MULTISUBDIR)"
643   AC_SUBST(baseline_dir)
644 ])
645
646
647 dnl
648 dnl Set up *_INCLUDES variables for all sundry Makefile.am's.
649 dnl
650 dnl Substs:
651 dnl  GLIBCXX_INCLUDES
652 dnl  TOPLEVEL_INCLUDES
653 dnl
654 AC_DEFUN([GLIBCXX_EXPORT_INCLUDES], [
655   # Used for every C++ compile we perform.
656   GLIBCXX_INCLUDES="\
657 -I$glibcxx_builddir/include/$host_alias \
658 -I$glibcxx_builddir/include \
659 -I$glibcxx_srcdir/libsupc++"
660
661   # For Canadian crosses, pick this up too.
662   if test $CANADIAN = yes; then
663     GLIBCXX_INCLUDES="$GLIBCXX_INCLUDES -I\${includedir}"
664   fi
665
666   # Stuff in the actual top level.  Currently only used by libsupc++ to
667   # get unwind* headers from the gcc dir.
668   #TOPLEVEL_INCLUDES='-I$(toplevel_srcdir)/gcc -I$(toplevel_srcdir)/include'
669   TOPLEVEL_INCLUDES='-I$(toplevel_srcdir)/gcc'
670
671   # Now, export this to all the little Makefiles....
672   AC_SUBST(GLIBCXX_INCLUDES)
673   AC_SUBST(TOPLEVEL_INCLUDES)
674 ])
675
676
677 dnl
678 dnl Set up *_FLAGS and *FLAGS variables for all sundry Makefile.am's.
679 dnl (SECTION_FLAGS is done under CHECK_COMPILER_FEATURES.)
680 dnl
681 dnl Substs:
682 dnl  OPTIMIZE_CXXFLAGS
683 dnl  WARN_FLAGS
684 dnl
685 AC_DEFUN([GLIBCXX_EXPORT_FLAGS], [
686   # Optimization flags that are probably a good idea for thrill-seekers. Just
687   # uncomment the lines below and make, everything else is ready to go...
688   # Alternatively OPTIMIZE_CXXFLAGS can be set in configure.host.
689   # OPTIMIZE_CXXFLAGS = -O3 -fstrict-aliasing -fvtable-gc
690   AC_SUBST(OPTIMIZE_CXXFLAGS)
691
692   WARN_FLAGS='-Wall -Wextra -Wwrite-strings -Wcast-qual'
693   AC_SUBST(WARN_FLAGS)
694 ])
695
696
697 dnl
698 dnl All installation directory information is determined here.
699 dnl
700 dnl Substs:
701 dnl  gxx_install_dir
702 dnl  glibcxx_prefixdir
703 dnl  glibcxx_toolexecdir
704 dnl  glibcxx_toolexeclibdir
705 dnl
706 dnl Assumes cross_compiling bits already done, and with_cross_host in
707 dnl particular.
708 dnl
709 dnl This logic must match gcc/configure.ac's setting of gcc_gxx_include_dir.
710 dnl config/gxx-include-dir.m4 must be kept consistant with this as well.
711 AC_DEFUN([GLIBCXX_EXPORT_INSTALL_INFO], [
712   glibcxx_toolexecdir=no
713   glibcxx_toolexeclibdir=no
714   glibcxx_prefixdir=$prefix
715
716   AC_MSG_CHECKING([for gxx-include-dir])
717   AC_ARG_WITH([gxx-include-dir],
718     AC_HELP_STRING([--with-gxx-include-dir=DIR],
719                    [installation directory for include files]),
720     [case "$withval" in
721       yes) AC_MSG_ERROR([Missing directory for --with-gxx-include-dir]) ;;
722       no)  gxx_include_dir=no ;;
723       *)   gxx_include_dir=$withval ;;
724      esac],
725     [gxx_include_dir=no])
726   AC_MSG_RESULT($gxx_include_dir)
727
728   AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
729   AC_ARG_ENABLE([version-specific-runtime-libs],
730     AC_HELP_STRING([--enable-version-specific-runtime-libs],
731                    [Specify that runtime libraries should be installed in a compiler-specific directory]),
732     [case "$enableval" in
733       yes) version_specific_libs=yes ;;
734       no)  version_specific_libs=no ;;
735       *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
736      esac],
737     [version_specific_libs=no])
738   AC_MSG_RESULT($version_specific_libs)
739
740   # Default case for install directory for include files.
741   if test $version_specific_libs = no && test $gxx_include_dir = no; then
742     gxx_include_dir='include/c++/${gcc_version}'
743     if test -n "$with_cross_host" && 
744        test x"$with_cross_host" != x"no"; then  
745       gxx_include_dir='${prefix}/${target_alias}/'"$gxx_include_dir"
746     else
747       gxx_include_dir='${prefix}/'"$gxx_include_dir"
748     fi
749   fi
750
751   # Version-specific runtime libs processing.
752   if test $version_specific_libs = yes; then
753     # Need the gcc compiler version to know where to install libraries
754     # and header files if --enable-version-specific-runtime-libs option
755     # is selected.  FIXME: these variables are misnamed, there are
756     # no executables installed in _toolexecdir or _toolexeclibdir.
757     if test x"$gxx_include_dir" = x"no"; then
758       gxx_include_dir='${libdir}/gcc/${host_alias}/${gcc_version}/include/c++'
759     fi
760     glibcxx_toolexecdir='${libdir}/gcc/${host_alias}'
761     glibcxx_toolexeclibdir='${toolexecdir}/${gcc_version}$(MULTISUBDIR)'
762   fi
763
764   # Calculate glibcxx_toolexecdir, glibcxx_toolexeclibdir
765   # Install a library built with a cross compiler in tooldir, not libdir.
766   if test x"$glibcxx_toolexecdir" = x"no"; then
767     if test -n "$with_cross_host" &&
768        test x"$with_cross_host" != x"no"; then
769       glibcxx_toolexecdir='${exec_prefix}/${host_alias}'
770       glibcxx_toolexeclibdir='${toolexecdir}/lib'
771     else
772       glibcxx_toolexecdir='${libdir}/gcc/${host_alias}'
773       glibcxx_toolexeclibdir='${libdir}'
774     fi
775     multi_os_directory=`$CXX -print-multi-os-directory`
776     case $multi_os_directory in
777       .) ;; # Avoid trailing /.
778       *) glibcxx_toolexeclibdir=$glibcxx_toolexeclibdir/$multi_os_directory ;;
779     esac
780   fi
781
782   AC_MSG_CHECKING([for install location])
783   AC_MSG_RESULT($gxx_include_dir)
784
785   AC_SUBST(glibcxx_prefixdir)
786   AC_SUBST(gxx_include_dir)
787   AC_SUBST(glibcxx_toolexecdir)
788   AC_SUBST(glibcxx_toolexeclibdir)
789 ])
790
791
792 dnl
793 dnl GLIBCXX_ENABLE
794 dnl    (FEATURE, DEFAULT, HELP-ARG, HELP-STRING)
795 dnl    (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, permit a|b|c)
796 dnl    (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, SHELL-CODE-HANDLER)
797 dnl
798 dnl See docs/html/17_intro/configury.html#enable for documentation.
799 dnl
800 m4_define([GLIBCXX_ENABLE],[dnl
801 m4_define([_g_switch],[--enable-$1])dnl
802 m4_define([_g_help],[AC_HELP_STRING(_g_switch$3,[$4 @<:@default=$2@:>@])])dnl
803  AC_ARG_ENABLE($1,_g_help,
804   m4_bmatch([$5],
805    [^permit ],
806      [[
807       case "$enableval" in
808        m4_bpatsubst([$5],[permit ])) ;;
809        *) AC_MSG_ERROR(Unknown argument to enable/disable $1) ;;
810           dnl Idea for future:  generate a URL pointing to
811           dnl "onlinedocs/configopts.html#whatever"
812       esac
813      ]],
814    [^$],
815      [[
816       case "$enableval" in
817        yes|no) ;;
818        *) AC_MSG_ERROR(Argument to enable/disable $1 must be yes or no) ;;
819       esac
820      ]],
821    [[$5]]),
822   [enable_]m4_bpatsubst([$1],-,_)[=][$2])
823 m4_undefine([_g_switch])dnl
824 m4_undefine([_g_help])dnl
825 ])
826
827
828 dnl
829 dnl Check for ISO/IEC 9899:1999 "C99" support.
830 dnl
831 dnl --enable-c99 defines _GLIBCXX_USE_C99
832 dnl --disable-c99 leaves _GLIBCXX_USE_C99 undefined
833 dnl  +  Usage:  GLIBCXX_ENABLE_C99[(DEFAULT)]
834 dnl       Where DEFAULT is either `yes' or `no'.
835 dnl  +  If 'C99' stuff is not available, ignores DEFAULT and sets `no'.
836 dnl
837 AC_DEFUN([GLIBCXX_ENABLE_C99], [
838   GLIBCXX_ENABLE(c99,$1,,[turns on ISO/IEC 9899:1999 support])
839
840   if test x"$enable_c99" = x"yes"; then
841
842   AC_LANG_SAVE
843   AC_LANG_CPLUSPLUS
844
845   # Use -std=c++98 because the default (-std=gnu++98) leaves __STRICT_ANSI__
846   # undefined and fake C99 facilities - like pre-standard snprintf - may be
847   # spuriously enabled.
848   # Long term, -std=c++0x could be even better, could manage to explicitely
849   # request C99 facilities to the underlying C headers.
850   ac_save_CXXFLAGS="$CXXFLAGS"
851   CXXFLAGS="$CXXFLAGS -std=c++98"
852   ac_save_LIBS="$LIBS"
853   ac_save_gcc_no_link="$gcc_no_link"
854
855   if test x$gcc_no_link != xyes; then
856     # Use -fno-exceptions to that the C driver can link these tests without
857     # hitting undefined references to personality routines.
858     CXXFLAGS="$CXXFLAGS -fno-exceptions"
859     AC_CHECK_LIB(m, sin, [
860       LIBS="$LIBS -lm"
861     ], [
862       # Use the default compile-only tests in GCC_TRY_COMPILE_OR_LINK
863       gcc_no_link=yes
864     ])
865   fi
866
867   # Check for the existence of <math.h> functions used if C99 is enabled.
868   AC_MSG_CHECKING([for ISO C99 support in <math.h>])
869   AC_CACHE_VAL(glibcxx_cv_c99_math, [
870   GCC_TRY_COMPILE_OR_LINK(
871      [#include <math.h>
872       volatile double d1, d2;
873       volatile int i;],
874      [i = fpclassify(d1);
875       i = isfinite(d1);
876       i = isinf(d1);
877       i = isnan(d1);
878       i = isnormal(d1);
879       i = signbit(d1);
880       i = isgreater(d1, d2);
881       i = isgreaterequal(d1, d2);
882       i = isless(d1, d2);
883       i = islessequal(d1, d2);
884       i = islessgreater(d1, d2);
885       i = islessgreater(d1, d2);
886       i = isunordered(d1, d2);
887      ],[glibcxx_cv_c99_math=yes], [glibcxx_cv_c99_math=no])
888   ])
889   AC_MSG_RESULT($glibcxx_cv_c99_math)
890   if test x"$glibcxx_cv_c99_math" = x"yes"; then
891     AC_DEFINE(_GLIBCXX_USE_C99_MATH, 1,
892               [Define if C99 functions or macros in <math.h> should be imported
893               in <cmath> in namespace std.])
894   fi
895
896   # Check for the existence of <complex.h> complex math functions.
897   # This is necessary even though libstdc++ uses the builtin versions
898   # of these functions, because if the builtin cannot be used, a reference
899   # to the library function is emitted.
900   AC_CHECK_HEADERS(tgmath.h, ac_has_tgmath_h=yes, ac_has_tgmath_h=no)
901   AC_CHECK_HEADERS(complex.h, ac_has_complex_h=yes, ac_has_complex_h=no)
902   glibcxx_cv_c99_complex=no;
903   if test x"$ac_has_complex_h" = x"yes"; then
904     AC_MSG_CHECKING([for ISO C99 support in <complex.h>])
905     GCC_TRY_COMPILE_OR_LINK(
906        [#include <complex.h>
907         typedef __complex__ float float_type;
908         typedef __complex__ double double_type;
909         typedef __complex__ long double ld_type;
910         volatile float_type tmpf;
911         volatile double_type tmpd;
912         volatile ld_type tmpld;
913         volatile float f;
914         volatile double d;
915         volatile long double ld;],
916        [f = cabsf(tmpf);
917         f = cargf(tmpf);
918         tmpf = ccosf(tmpf);
919         tmpf = ccoshf(tmpf);
920         tmpf = cexpf(tmpf);
921         tmpf = clogf(tmpf);
922         tmpf = csinf(tmpf);
923         tmpf = csinhf(tmpf);
924         tmpf = csqrtf(tmpf);
925         tmpf = ctanf(tmpf);
926         tmpf = ctanhf(tmpf);
927         tmpf = cpowf(tmpf, tmpf);
928         tmpf = cprojf(tmpf);
929         d = cabs(tmpd);
930         d = carg(tmpd);
931         tmpd = ccos(tmpd);
932         tmpd = ccosh(tmpd);
933         tmpd = cexp(tmpd);
934         tmpd = clog(tmpd);
935         tmpd = csin(tmpd);
936         tmpd = csinh(tmpd);
937         tmpd = csqrt(tmpd);
938         tmpd = ctan(tmpd);
939         tmpd = ctanh(tmpd);
940         tmpd = cpow(tmpd, tmpd);
941         tmpd = cproj(tmpd);
942         ld = cabsl(tmpld);
943         ld = cargl(tmpld);
944         tmpld = ccosl(tmpld);
945         tmpld = ccoshl(tmpld);
946         tmpld = cexpl(tmpld);
947         tmpld = clogl(tmpld);
948         tmpld = csinl(tmpld);
949         tmpld = csinhl(tmpld);
950         tmpld = csqrtl(tmpld);
951         tmpld = ctanl(tmpld);
952         tmpld = ctanhl(tmpld);
953         tmpld = cpowl(tmpld, tmpld);
954         tmpld = cprojl(tmpld);
955        ],[glibcxx_cv_c99_complex=yes], [glibcxx_cv_c99_complex=no])
956   fi
957   AC_MSG_RESULT($glibcxx_cv_c99_complex)
958   if test x"$glibcxx_cv_c99_complex" = x"yes"; then
959     AC_DEFINE(_GLIBCXX_USE_C99_COMPLEX, 1,
960               [Define if C99 functions in <complex.h> should be used in
961               <complex>. Using compiler builtins for these functions requires
962               corresponding C99 library functions to be present.])
963   fi
964
965   # Check for the existence in <stdio.h> of vscanf, et. al.
966   AC_MSG_CHECKING([for ISO C99 support in <stdio.h>])
967   AC_CACHE_VAL(glibcxx_cv_c99_stdio, [
968   GCC_TRY_COMPILE_OR_LINK(
969      [#include <stdio.h>
970       #include <stdarg.h>
971       void foo(char* fmt, ...)
972       {
973         va_list args; va_start(args, fmt);
974         vfscanf(stderr, "%i", args); 
975         vscanf("%i", args);
976         vsnprintf(fmt, 0, "%i", args);
977         vsscanf(fmt, "%i", args);
978       }],
979      [snprintf("12", 0, "%i");],
980      [glibcxx_cv_c99_stdio=yes], [glibcxx_cv_c99_stdio=no])
981   ])
982   AC_MSG_RESULT($glibcxx_cv_c99_stdio)
983
984   # Check for the existence in <stdlib.h> of lldiv_t, et. al.
985   AC_MSG_CHECKING([for ISO C99 support in <stdlib.h>])
986   AC_CACHE_VAL(glibcxx_cv_c99_stdlib, [
987   GCC_TRY_COMPILE_OR_LINK(
988      [#include <stdlib.h>
989       volatile float f;
990       volatile long double ld;
991       volatile unsigned long long ll;
992       lldiv_t mydivt;],
993      [char* tmp;
994       f = strtof("gnu", &tmp);
995       ld = strtold("gnu", &tmp);
996       ll = strtoll("gnu", &tmp, 10);
997       ll = strtoull("gnu", &tmp, 10);
998       ll = llabs(10);
999       mydivt = lldiv(10,1);
1000       ll = mydivt.quot;
1001       ll = mydivt.rem;
1002       ll = atoll("10");
1003       _Exit(0);
1004       ],[glibcxx_cv_c99_stdlib=yes], [glibcxx_cv_c99_stdlib=no])
1005   ])
1006   AC_MSG_RESULT($glibcxx_cv_c99_stdlib)
1007
1008   # Check for the existence in <wchar.h> of wcstold, etc.
1009   glibcxx_cv_c99_wchar=no;
1010   if test x"$ac_has_wchar_h" = xyes &&
1011      test x"$ac_has_wctype_h" = xyes; then
1012     AC_MSG_CHECKING([for ISO C99 support in <wchar.h>]) 
1013     AC_TRY_COMPILE([#include <wchar.h>
1014                     namespace test
1015                     {
1016                       using ::wcstold;
1017                       using ::wcstoll;
1018                       using ::wcstoull;
1019                     }
1020                    ],[],[glibcxx_cv_c99_wchar=yes], [glibcxx_cv_c99_wchar=no])
1021
1022     # Checks for wide character functions that may not be present.
1023     # Injection of these is wrapped with guard macros.
1024     # NB: only put functions here, instead of immediately above, if
1025     # absolutely necessary.
1026     AC_TRY_COMPILE([#include <wchar.h>
1027                     namespace test { using ::vfwscanf; } ], [],
1028                    [AC_DEFINE(HAVE_VFWSCANF,1,
1029                         [Defined if vfwscanf exists.])],[])
1030
1031     AC_TRY_COMPILE([#include <wchar.h>
1032                     namespace test { using ::vswscanf; } ], [],
1033                    [AC_DEFINE(HAVE_VSWSCANF,1,
1034                         [Defined if vswscanf exists.])],[])
1035
1036     AC_TRY_COMPILE([#include <wchar.h>
1037                     namespace test { using ::vwscanf; } ], [],
1038                    [AC_DEFINE(HAVE_VWSCANF,1,[Defined if vwscanf exists.])],[])
1039
1040     AC_TRY_COMPILE([#include <wchar.h>
1041                     namespace test { using ::wcstof; } ], [],
1042                    [AC_DEFINE(HAVE_WCSTOF,1,[Defined if wcstof exists.])],[])
1043
1044     AC_TRY_COMPILE([#include <wctype.h>],
1045                    [ wint_t t; int i = iswblank(t);], 
1046                    [AC_DEFINE(HAVE_ISWBLANK,1,
1047                         [Defined if iswblank exists.])],[])
1048
1049     AC_MSG_RESULT($glibcxx_cv_c99_wchar)
1050   fi
1051
1052   # Option parsed, now set things appropriately.
1053   if test x"$glibcxx_cv_c99_math" = x"no" ||
1054      test x"$glibcxx_cv_c99_complex" = x"no" ||
1055      test x"$glibcxx_cv_c99_stdio" = x"no" ||
1056      test x"$glibcxx_cv_c99_stdlib" = x"no" ||
1057      test x"$glibcxx_cv_c99_wchar" = x"no"; then
1058     enable_c99=no;
1059   else
1060     AC_DEFINE(_GLIBCXX_USE_C99, 1,
1061     [Define if C99 functions or macros from <wchar.h>, <math.h>,
1062     <complex.h>, <stdio.h>, and <stdlib.h> can be used or exposed.])
1063   fi
1064
1065   gcc_no_link="$ac_save_gcc_no_link"
1066   LIBS="$ac_save_LIBS"
1067   CXXFLAGS="$ac_save_CXXFLAGS"
1068   AC_LANG_RESTORE
1069   fi    
1070
1071   AC_MSG_CHECKING([for fully enabled ISO C99 support])
1072   AC_MSG_RESULT($enable_c99)
1073 ])
1074
1075
1076 dnl
1077 dnl Check for clock_gettime clocks, used in the implementation of 20.8.5
1078 dnl [time.clock] in the current C++0x working draft.
1079 dnl
1080 dnl --enable-clock-gettime
1081 dnl --enable-clock-gettime=yes
1082 dnl        checks for the availability of monotonic and realtime clocks
1083 dnl        in libc and libposix4 and in case links the latter
1084 dnl --enable-clock-gettime=rt
1085 dnl        also searches (and, in case, links) librt.  Note that this is
1086 dnl        not always desirable because, in glibc, for example, in turn it
1087 dnl        triggers the linking of libpthread too, which activates locking,
1088 dnl        a large overhead for single-thread programs.
1089 dnl --enable-clock-gettime=no
1090 dnl --disable-clock-gettime
1091 dnl        disables the checks completely
1092 dnl
1093 AC_DEFUN([GLIBCXX_ENABLE_CLOCK_GETTIME], [
1094
1095   AC_MSG_CHECKING([for clock_gettime clocks])                                    
1096   GLIBCXX_ENABLE(clock-gettime,$1,[=KIND],
1097     [use KIND for check type],
1098     [permit yes|no|rt])
1099
1100   AC_LANG_SAVE
1101   AC_LANG_CPLUSPLUS
1102   ac_save_CXXFLAGS="$CXXFLAGS"
1103   CXXFLAGS="$CXXFLAGS -fno-exceptions"
1104   ac_save_LIBS="$LIBS"
1105
1106   ac_has_clock_monotonic=no;  
1107   ac_has_clock_realtime=no;
1108
1109   if test x"$enable_clock_gettime" != x"no"; then
1110
1111     if test x"$enable_clock_gettime" = x"rt"; then
1112       AC_SEARCH_LIBS(clock_gettime, [rt posix4])
1113     else
1114       AC_SEARCH_LIBS(clock_gettime, [posix4])
1115     fi
1116
1117     case "$ac_cv_search_clock_gettime" in
1118       -l*) GLIBCXX_LIBS=$ac_cv_search_clock_gettime
1119     esac
1120
1121     AC_CHECK_HEADERS(unistd.h, ac_has_unistd_h=yes, ac_has_unistd_h=no)
1122
1123     if test x"$ac_has_unistd_h" = x"yes"; then
1124       AC_MSG_CHECKING([for monotonic clock])
1125       AC_TRY_LINK(
1126         [#include <unistd.h>
1127          #include <time.h>
1128         ],
1129         [#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK)
1130           timespec tp;     
1131          #endif
1132           clock_gettime(CLOCK_MONOTONIC, &tp);
1133         ], [ac_has_clock_monotonic=yes], [ac_has_clock_monotonic=no])
1134
1135       AC_MSG_RESULT($ac_has_clock_monotonic)   
1136     
1137       AC_MSG_CHECKING([for realtime clock])
1138       AC_TRY_LINK(
1139         [#include <unistd.h>
1140          #include <time.h>
1141         ],
1142         [#if _POSIX_TIMERS > 0
1143           timespec tp;      
1144          #endif
1145           clock_gettime(CLOCK_REALTIME, &tp);
1146         ], [ac_has_clock_realtime=yes], [ac_has_clock_realtime=no])
1147
1148       AC_MSG_RESULT($ac_has_clock_realtime)
1149     fi
1150
1151   fi
1152
1153   if test x"$ac_has_clock_monotonic" = x"yes"; then
1154     AC_DEFINE(_GLIBCXX_USE_CLOCK_MONOTONIC, 1,
1155       [ Defined if clock_gettime has monotonic clock support. ])
1156   fi
1157
1158   if test x"$ac_has_clock_realtime" = x"yes"; then
1159     AC_DEFINE(_GLIBCXX_USE_CLOCK_REALTIME, 1,
1160       [ Defined if clock_gettime has realtime clock support. ])
1161   fi
1162
1163   AC_SUBST(GLIBCXX_LIBS)
1164
1165   CXXFLAGS="$ac_save_CXXFLAGS"
1166   LIBS="$ac_save_LIBS"
1167   AC_LANG_RESTORE
1168 ])
1169
1170 dnl
1171 dnl Check for gettimeofday, used in the implementation of 20.8.5
1172 dnl [time.clock] in the current C++0x working draft.
1173 dnl
1174 AC_DEFUN([GLIBCXX_CHECK_GETTIMEOFDAY], [
1175   
1176   AC_MSG_CHECKING([for gettimeofday])
1177
1178   AC_LANG_SAVE
1179   AC_LANG_CPLUSPLUS
1180   ac_save_CXXFLAGS="$CXXFLAGS"
1181   CXXFLAGS="$CXXFLAGS -fno-exceptions"
1182   
1183   ac_has_gettimeofday=no;
1184   AC_CHECK_HEADERS(sys/time.h, ac_has_sys_time_h=yes, ac_has_sys_time_h=no)
1185   if test x"$ac_has_sys_time_h" = x"yes"; then
1186     AC_MSG_CHECKING([for gettimeofday])
1187     GCC_TRY_COMPILE_OR_LINK([#include <sys/time.h>],
1188       [timeval tv; gettimeofday(&tv, 0);],
1189       [ac_has_gettimeofday=yes], [ac_has_gettimeofday=no])
1190     
1191     AC_MSG_RESULT($ac_has_gettimeofday)
1192   fi
1193   
1194   if test x"$ac_has_gettimeofday" = x"yes"; then
1195     AC_DEFINE(_GLIBCXX_USE_GETTIMEOFDAY, 1,
1196       [ Defined if gettimeofday is available. ])
1197   fi
1198   
1199   CXXFLAGS="$ac_save_CXXFLAGS"
1200   AC_LANG_RESTORE
1201 ])
1202
1203 dnl
1204 dnl Check for nanosleep, used in the implementation of 30.2.2
1205 dnl [thread.thread.this] in the current C++0x working draft.
1206 dnl
1207 AC_DEFUN([GLIBCXX_CHECK_NANOSLEEP], [
1208
1209   AC_MSG_CHECKING([for nanosleep])
1210
1211   AC_LANG_SAVE
1212   AC_LANG_CPLUSPLUS
1213   ac_save_CXXFLAGS="$CXXFLAGS"
1214   CXXFLAGS="$CXXFLAGS -fno-exceptions"
1215
1216   ac_has_nanosleep=no;
1217   AC_CHECK_HEADERS(time.h, ac_has_time_h=yes, ac_has_time_h=no)
1218   if test x"$ac_has_time_h" = x"yes"; then
1219     AC_MSG_CHECKING([for nanosleep])
1220     AC_TRY_COMPILE([#include <time.h>],                                                                                                         
1221       [timespec ts; nanosleep(&ts, 0);],
1222       [ac_has_nanosleep=yes], [ac_has_nanosleep=no])
1223
1224     AC_MSG_RESULT($ac_has_nanosleep)
1225   fi
1226
1227   if test x"$ac_has_nanosleep" = x"yes"; then
1228     AC_DEFINE(_GLIBCXX_USE_NANOSLEEP, 1,
1229       [ Defined if nanosleep is available. ])
1230   fi
1231
1232   CXXFLAGS="$ac_save_CXXFLAGS"
1233   AC_LANG_RESTORE
1234 ])
1235
1236 dnl
1237 dnl Check for ISO/IEC 9899:1999 "C99" support to ISO/IEC DTR 19768 "TR1"
1238 dnl facilities in Chapter 8, "C compatibility".
1239 dnl
1240 AC_DEFUN([GLIBCXX_CHECK_C99_TR1], [
1241
1242   AC_LANG_SAVE
1243   AC_LANG_CPLUSPLUS
1244
1245   # Use -std=c++98 because the default (-std=gnu++98) leaves __STRICT_ANSI__
1246   # undefined and fake C99 facilities may be spuriously enabled.
1247   ac_save_CXXFLAGS="$CXXFLAGS"
1248   CXXFLAGS="$CXXFLAGS -std=c++98"
1249
1250   # Check for the existence of <complex.h> complex math functions used
1251   # by tr1/complex.
1252   AC_CHECK_HEADERS(complex.h, ac_has_complex_h=yes, ac_has_complex_h=no)
1253   ac_c99_complex_tr1=no;
1254   if test x"$ac_has_complex_h" = x"yes"; then
1255     AC_MSG_CHECKING([for ISO C99 support to TR1 in <complex.h>])
1256     AC_TRY_COMPILE([#include <complex.h>],
1257                    [typedef __complex__ float float_type; float_type tmpf;
1258                     cacosf(tmpf);
1259                     casinf(tmpf);
1260                     catanf(tmpf);
1261                     cacoshf(tmpf);
1262                     casinhf(tmpf);
1263                     catanhf(tmpf);
1264                     typedef __complex__ double double_type; double_type tmpd;
1265                     cacos(tmpd);
1266                     casin(tmpd);
1267                     catan(tmpd);
1268                     cacosh(tmpd);
1269                     casinh(tmpd);
1270                     catanh(tmpd);
1271                     typedef __complex__ long double ld_type; ld_type tmpld;
1272                     cacosl(tmpld);
1273                     casinl(tmpld);
1274                     catanl(tmpld);
1275                     cacoshl(tmpld);
1276                     casinhl(tmpld);
1277                     catanhl(tmpld);
1278                    ],[ac_c99_complex_tr1=yes], [ac_c99_complex_tr1=no])
1279   fi
1280   AC_MSG_RESULT($ac_c99_complex_tr1)
1281   if test x"$ac_c99_complex_tr1" = x"yes"; then
1282     AC_DEFINE(_GLIBCXX_USE_C99_COMPLEX_TR1, 1,
1283               [Define if C99 functions in <complex.h> should be used in
1284               <tr1/complex>. Using compiler builtins for these functions
1285               requires corresponding C99 library functions to be present.])
1286   fi
1287
1288   # Check for the existence of <ctype.h> functions.
1289   AC_MSG_CHECKING([for ISO C99 support to TR1 in <ctype.h>])
1290   AC_CACHE_VAL(glibcxx_cv_c99_ctype_tr1, [
1291   AC_TRY_COMPILE([#include <ctype.h>],
1292                  [int ch;
1293                   int ret;
1294                   ret = isblank(ch);
1295                  ],[glibcxx_cv_c99_ctype_tr1=yes],
1296                    [glibcxx_cv_c99_ctype_tr1=no])
1297   ])
1298   AC_MSG_RESULT($glibcxx_cv_c99_ctype_tr1)
1299   if test x"$glibcxx_cv_c99_ctype_tr1" = x"yes"; then
1300     AC_DEFINE(_GLIBCXX_USE_C99_CTYPE_TR1, 1,
1301               [Define if C99 functions in <ctype.h> should be imported in
1302               <tr1/cctype> in namespace std::tr1.])
1303   fi
1304
1305   # Check for the existence of <fenv.h> functions.
1306   AC_CHECK_HEADERS(fenv.h, ac_has_fenv_h=yes, ac_has_fenv_h=no)
1307   ac_c99_fenv_tr1=no;
1308   if test x"$ac_has_fenv_h" = x"yes"; then
1309     AC_MSG_CHECKING([for ISO C99 support to TR1 in <fenv.h>])
1310     AC_TRY_COMPILE([#include <fenv.h>],
1311                    [int except, mode;
1312                     fexcept_t* pflag;
1313                     fenv_t* penv;
1314                     int ret;
1315                     ret = feclearexcept(except);
1316                     ret = fegetexceptflag(pflag, except);
1317                     ret = feraiseexcept(except);
1318                     ret = fesetexceptflag(pflag, except);
1319                     ret = fetestexcept(except);
1320                     ret = fegetround();
1321                     ret = fesetround(mode);
1322                     ret = fegetenv(penv);
1323                     ret = feholdexcept(penv);
1324                     ret = fesetenv(penv);
1325                     ret = feupdateenv(penv);
1326                    ],[ac_c99_fenv_tr1=yes], [ac_c99_fenv_tr1=no])
1327   fi
1328   AC_MSG_RESULT($ac_c99_fenv_tr1)
1329   if test x"$ac_c99_fenv_tr1" = x"yes"; then
1330     AC_DEFINE(_GLIBCXX_USE_C99_FENV_TR1, 1,
1331               [Define if C99 functions in <fenv.h> should be imported in
1332               <tr1/cfenv> in namespace std::tr1.])
1333   fi
1334
1335   # Check for the existence of <stdint.h> types.
1336   AC_MSG_CHECKING([for ISO C99 support to TR1 in <stdint.h>])
1337   AC_CACHE_VAL(glibcxx_cv_c99_stdint_tr1, [
1338   AC_TRY_COMPILE([#define __STDC_LIMIT_MACROS
1339                   #define __STDC_CONSTANT_MACROS
1340                   #include <stdint.h>],
1341                  [typedef int8_t          my_int8_t;
1342                   my_int8_t               i8 = INT8_MIN;
1343                   i8 = INT8_MAX;
1344                   typedef int16_t         my_int16_t;
1345                   my_int16_t              i16 = INT16_MIN;
1346                   i16 = INT16_MAX;
1347                   typedef int32_t         my_int32_t;
1348                   my_int32_t              i32 = INT32_MIN;
1349                   i32 = INT32_MAX;
1350                   typedef int64_t         my_int64_t;
1351                   my_int64_t              i64 = INT64_MIN;
1352                   i64 = INT64_MAX;
1353                   typedef int_fast8_t     my_int_fast8_t;
1354                   my_int_fast8_t          if8 = INT_FAST8_MIN;
1355                   if8 = INT_FAST8_MAX;
1356                   typedef int_fast16_t    my_int_fast16_t;
1357                   my_int_fast16_t         if16 = INT_FAST16_MIN;
1358                   if16 = INT_FAST16_MAX;
1359                   typedef int_fast32_t    my_int_fast32_t;
1360                   my_int_fast32_t         if32 = INT_FAST32_MIN;
1361                   if32 = INT_FAST32_MAX;
1362                   typedef int_fast64_t    my_int_fast64_t;
1363                   my_int_fast64_t         if64 = INT_FAST64_MIN;
1364                   if64 = INT_FAST64_MAX;
1365                   typedef int_least8_t    my_int_least8_t;
1366                   my_int_least8_t         il8 = INT_LEAST8_MIN;
1367                   il8 = INT_LEAST8_MAX;
1368                   typedef int_least16_t   my_int_least16_t;
1369                   my_int_least16_t        il16 = INT_LEAST16_MIN;
1370                   il16 = INT_LEAST16_MAX;
1371                   typedef int_least32_t   my_int_least32_t;
1372                   my_int_least32_t        il32 = INT_LEAST32_MIN;
1373                   il32 = INT_LEAST32_MAX;
1374                   typedef int_least64_t   my_int_least64_t;
1375                   my_int_least64_t        il64 = INT_LEAST64_MIN;
1376                   il64 = INT_LEAST64_MAX;
1377                   typedef intmax_t        my_intmax_t;
1378                   my_intmax_t             im = INTMAX_MAX;
1379                   im = INTMAX_MIN;
1380                   typedef intptr_t        my_intptr_t;
1381                   my_intptr_t             ip = INTPTR_MAX;
1382                   ip = INTPTR_MIN;
1383                   typedef uint8_t         my_uint8_t;
1384                   my_uint8_t              ui8 = UINT8_MAX;
1385                   ui8 = UINT8_MAX;
1386                   typedef uint16_t        my_uint16_t;
1387                   my_uint16_t             ui16 = UINT16_MAX;
1388                   ui16 = UINT16_MAX;
1389                   typedef uint32_t        my_uint32_t;
1390                   my_uint32_t             ui32 = UINT32_MAX;
1391                   ui32 = UINT32_MAX;
1392                   typedef uint64_t        my_uint64_t;
1393                   my_uint64_t             ui64 = UINT64_MAX;
1394                   ui64 = UINT64_MAX;
1395                   typedef uint_fast8_t    my_uint_fast8_t;
1396                   my_uint_fast8_t         uif8 = UINT_FAST8_MAX;
1397                   uif8 = UINT_FAST8_MAX;
1398                   typedef uint_fast16_t   my_uint_fast16_t;
1399                   my_uint_fast16_t        uif16 = UINT_FAST16_MAX;
1400                   uif16 = UINT_FAST16_MAX;
1401                   typedef uint_fast32_t   my_uint_fast32_t;
1402                   my_uint_fast32_t        uif32 = UINT_FAST32_MAX;
1403                   uif32 = UINT_FAST32_MAX;
1404                   typedef uint_fast64_t   my_uint_fast64_t;
1405                   my_uint_fast64_t        uif64 = UINT_FAST64_MAX;
1406                   uif64 = UINT_FAST64_MAX;
1407                   typedef uint_least8_t   my_uint_least8_t;
1408                   my_uint_least8_t        uil8 = UINT_LEAST8_MAX;
1409                   uil8 = UINT_LEAST8_MAX;
1410                   typedef uint_least16_t  my_uint_least16_t;
1411                   my_uint_least16_t       uil16 = UINT_LEAST16_MAX;
1412                   uil16 = UINT_LEAST16_MAX;
1413                   typedef uint_least32_t  my_uint_least32_t;
1414                   my_uint_least32_t       uil32 = UINT_LEAST32_MAX;
1415                   uil32 = UINT_LEAST32_MAX;
1416                   typedef uint_least64_t  my_uint_least64_t;
1417                   my_uint_least64_t       uil64 = UINT_LEAST64_MAX;
1418                   uil64 = UINT_LEAST64_MAX;
1419                   typedef uintmax_t       my_uintmax_t;
1420                   my_uintmax_t            uim = UINTMAX_MAX;
1421                   uim = UINTMAX_MAX;
1422                   typedef uintptr_t       my_uintptr_t;
1423                   my_uintptr_t            uip = UINTPTR_MAX;
1424                   uip = UINTPTR_MAX;
1425                  ],[glibcxx_cv_c99_stdint_tr1=yes],
1426                    [glibcxx_cv_c99_stdint_tr1=no])
1427   ])
1428   AC_MSG_RESULT($glibcxx_cv_c99_stdint_tr1)
1429   if test x"$glibcxx_cv_c99_stdint_tr1" = x"yes"; then
1430     AC_DEFINE(_GLIBCXX_USE_C99_STDINT_TR1, 1,
1431               [Define if C99 types in <stdint.h> should be imported in
1432               <tr1/cstdint> in namespace std::tr1.])
1433   fi
1434
1435   # Check for the existence of <math.h> functions.
1436   AC_MSG_CHECKING([for ISO C99 support to TR1 in <math.h>])
1437   AC_CACHE_VAL(glibcxx_cv_c99_math_tr1, [
1438   AC_TRY_COMPILE([#include <math.h>],
1439                  [typedef double_t  my_double_t;
1440                   typedef float_t   my_float_t;
1441                   acosh(0.0);
1442                   acoshf(0.0f);
1443                   acoshl(0.0l);
1444                   asinh(0.0);
1445                   asinhf(0.0f);
1446                   asinhl(0.0l);
1447                   atanh(0.0);
1448                   atanhf(0.0f);
1449                   atanhl(0.0l);
1450                   cbrt(0.0);
1451                   cbrtf(0.0f);
1452                   cbrtl(0.0l);
1453                   copysign(0.0, 0.0);
1454                   copysignf(0.0f, 0.0f);
1455                   copysignl(0.0l, 0.0l);
1456                   erf(0.0);
1457                   erff(0.0f);
1458                   erfl(0.0l);
1459                   erfc(0.0);
1460                   erfcf(0.0f);
1461                   erfcl(0.0l);
1462                   exp2(0.0);
1463                   exp2f(0.0f);
1464                   exp2l(0.0l);
1465                   expm1(0.0);
1466                   expm1f(0.0f);
1467                   expm1l(0.0l);
1468                   fdim(0.0, 0.0);
1469                   fdimf(0.0f, 0.0f);
1470                   fdiml(0.0l, 0.0l);
1471                   fma(0.0, 0.0, 0.0);
1472                   fmaf(0.0f, 0.0f, 0.0f);
1473                   fmal(0.0l, 0.0l, 0.0l);
1474                   fmax(0.0, 0.0);
1475                   fmaxf(0.0f, 0.0f);
1476                   fmaxl(0.0l, 0.0l);
1477                   fmin(0.0, 0.0);
1478                   fminf(0.0f, 0.0f);
1479                   fminl(0.0l, 0.0l);
1480                   hypot(0.0, 0.0);
1481                   hypotf(0.0f, 0.0f);
1482                   hypotl(0.0l, 0.0l);
1483                   ilogb(0.0);
1484                   ilogbf(0.0f);
1485                   ilogbl(0.0l);
1486                   lgamma(0.0);
1487                   lgammaf(0.0f);
1488                   lgammal(0.0l);
1489                   llrint(0.0);
1490                   llrintf(0.0f);
1491                   llrintl(0.0l);
1492                   llround(0.0);
1493                   llroundf(0.0f);
1494                   llroundl(0.0l);
1495                   log1p(0.0);
1496                   log1pf(0.0f);
1497                   log1pl(0.0l);
1498                   log2(0.0);
1499                   log2f(0.0f);
1500                   log2l(0.0l);
1501                   logb(0.0);
1502                   logbf(0.0f);
1503                   logbl(0.0l);
1504                   lrint(0.0);
1505                   lrintf(0.0f);
1506                   lrintl(0.0l);
1507                   lround(0.0);
1508                   lroundf(0.0f);
1509                   lroundl(0.0l);
1510                   nan(0);
1511                   nanf(0);
1512                   nanl(0);
1513                   nearbyint(0.0);
1514                   nearbyintf(0.0f);
1515                   nearbyintl(0.0l);
1516                   nextafter(0.0, 0.0);
1517                   nextafterf(0.0f, 0.0f);
1518                   nextafterl(0.0l, 0.0l);
1519                   nexttoward(0.0, 0.0);
1520                   nexttowardf(0.0f, 0.0f);
1521                   nexttowardl(0.0l, 0.0l);
1522                   remainder(0.0, 0.0);
1523                   remainderf(0.0f, 0.0f);
1524                   remainderl(0.0l, 0.0l);
1525                   remquo(0.0, 0.0, 0);
1526                   remquof(0.0f, 0.0f, 0);
1527                   remquol(0.0l, 0.0l, 0);
1528                   rint(0.0);
1529                   rintf(0.0f);
1530                   rintl(0.0l);
1531                   round(0.0);
1532                   roundf(0.0f);
1533                   roundl(0.0l);
1534                   scalbln(0.0, 0l);
1535                   scalblnf(0.0f, 0l);
1536                   scalblnl(0.0l, 0l);
1537                   scalbn(0.0, 0);
1538                   scalbnf(0.0f, 0);
1539                   scalbnl(0.0l, 0);
1540                   tgamma(0.0);
1541                   tgammaf(0.0f);
1542                   tgammal(0.0l);
1543                   trunc(0.0);
1544                   truncf(0.0f);
1545                   truncl(0.0l);
1546                  ],[glibcxx_cv_c99_math_tr1=yes], [glibcxx_cv_c99_math_tr1=no])
1547   ])
1548   AC_MSG_RESULT($glibcxx_cv_c99_math_tr1)
1549   if test x"$glibcxx_cv_c99_math_tr1" = x"yes"; then
1550     AC_DEFINE(_GLIBCXX_USE_C99_MATH_TR1, 1,
1551               [Define if C99 functions or macros in <math.h> should be imported
1552               in <tr1/cmath> in namespace std::tr1.])
1553   fi
1554
1555   # Check for the existence of <inttypes.h> functions (NB: doesn't make
1556   # sense if the glibcxx_cv_c99_stdint_tr1 check fails, per C99, 7.8/1).
1557   ac_c99_inttypes_tr1=no;
1558   if test x"$glibcxx_cv_c99_stdint_tr1" = x"yes"; then
1559     AC_MSG_CHECKING([for ISO C99 support to TR1 in <inttypes.h>])
1560     AC_TRY_COMPILE([#include <inttypes.h>],
1561                    [intmax_t i, numer, denom, base;
1562                     const char* s;
1563                     char** endptr;
1564                     intmax_t ret = imaxabs(i);
1565                     imaxdiv_t dret = imaxdiv(numer, denom);
1566                     ret = strtoimax(s, endptr, base);
1567                     uintmax_t uret = strtoumax(s, endptr, base);
1568                    ],[ac_c99_inttypes_tr1=yes], [ac_c99_inttypes_tr1=no])
1569   fi
1570   AC_MSG_RESULT($ac_c99_inttypes_tr1)
1571   if test x"$ac_c99_inttypes_tr1" = x"yes"; then
1572     AC_DEFINE(_GLIBCXX_USE_C99_INTTYPES_TR1, 1,
1573               [Define if C99 functions in <inttypes.h> should be imported in
1574               <tr1/cinttypes> in namespace std::tr1.])
1575   fi
1576
1577   # Check for the existence of whcar_t <inttypes.h> functions (NB: doesn't
1578   # make sense if the glibcxx_cv_c99_stdint_tr1 check fails, per C99, 7.8/1).
1579   ac_c99_inttypes_wchar_t_tr1=no;
1580   if test x"$glibcxx_cv_c99_stdint_tr1" = x"yes"; then
1581     AC_MSG_CHECKING([for wchar_t ISO C99 support to TR1 in <inttypes.h>])
1582     AC_TRY_COMPILE([#include <inttypes.h>],
1583                    [intmax_t base;
1584                     const wchar_t* s;
1585                     wchar_t** endptr;
1586                     intmax_t ret = wcstoimax(s, endptr, base);
1587                     uintmax_t uret = wcstoumax(s, endptr, base);
1588                    ],[ac_c99_inttypes_wchar_t_tr1=yes],
1589                      [ac_c99_inttypes_wchar_t_tr1=no])
1590   fi
1591   AC_MSG_RESULT($ac_c99_inttypes_wchar_t_tr1)
1592   if test x"$ac_c99_inttypes_wchar_t_tr1" = x"yes"; then
1593     AC_DEFINE(_GLIBCXX_USE_C99_INTTYPES_WCHAR_T_TR1, 1,
1594               [Define if wchar_t C99 functions in <inttypes.h> should be
1595               imported in <tr1/cinttypes> in namespace std::tr1.])
1596   fi
1597
1598   # Check for the existence of the <stdbool.h> header.  
1599   AC_CHECK_HEADERS(stdbool.h)
1600
1601   CXXFLAGS="$ac_save_CXXFLAGS"
1602   AC_LANG_RESTORE
1603 ])
1604
1605 dnl
1606 dnl Check whether "/dev/random" and "/dev/urandom" are available for the
1607 dnl random_device of "TR1" (Chapter 5.1, "Random number generation").
1608 dnl
1609 AC_DEFUN([GLIBCXX_CHECK_RANDOM_TR1], [
1610
1611   AC_MSG_CHECKING([for "/dev/random" and "/dev/urandom" for TR1 random_device])
1612   AC_CACHE_VAL(glibcxx_cv_random_tr1, [
1613     if test -r /dev/random && test -r /dev/urandom; then
1614       glibcxx_cv_random_tr1=yes;
1615     else
1616       glibcxx_cv_random_tr1=no;
1617     fi
1618   ])
1619   AC_MSG_RESULT($glibcxx_cv_random_tr1)
1620
1621   if test x"$glibcxx_cv_random_tr1" = x"yes"; then
1622     AC_DEFINE(_GLIBCXX_USE_RANDOM_TR1, 1,
1623               [Define if /dev/random and /dev/urandom are available for
1624                the random_device of TR1 (Chapter 5.1).])
1625   fi
1626
1627 ])
1628
1629 dnl
1630 dnl Check whether EOF, SEEK_CUR, and SEEK_END have the most common values:
1631 dnl in that case including <cstdio> in some C++ headers can be avoided.
1632 dnl
1633 AC_DEFUN([GLIBCXX_CHECK_STDIO_MACROS], [
1634
1635   AC_MSG_CHECKING([for EOF == -1, SEEK_CUR == 1, SEEK_END == 2])
1636   AC_CACHE_VAL(glibcxx_cv_stdio_macros, [
1637   AC_TRY_COMPILE([#include <stdio.h>],
1638                  [#if ((EOF != -1) || (SEEK_CUR != 1) || (SEEK_END != 2))
1639                     unusual values...
1640                   #endif
1641                  ], [glibcxx_cv_stdio_macros=yes],
1642                     [glibcxx_cv_stdio_macros=no])
1643   ])
1644   AC_MSG_RESULT($glibcxx_cv_stdio_macros)
1645   if test x"$glibcxx_cv_stdio_macros" = x"yes"; then
1646     AC_DEFINE(_GLIBCXX_STDIO_MACROS, 1,
1647               [Define if EOF == -1, SEEK_CUR == 1, SEEK_END == 2.])
1648   fi
1649
1650 ])
1651
1652 dnl
1653 dnl Check whether macros, etc are present for <system_error>
1654 dnl
1655 AC_DEFUN([GLIBCXX_CHECK_SYSTEM_ERROR], [
1656
1657 m4_pushdef([n_syserr], [1])dnl
1658 m4_foreach([syserr], [EOWNERDEAD, ENOTRECOVERABLE, ENOLINK, EPROTO, ENODATA,
1659                       ENOSR, ENOSTR, ETIME, EBADMSG, ECANCELED,
1660                       EOVERFLOW, ENOTSUP, EIDRM, ETXTBSY],
1661 [m4_pushdef([SYSERR], m4_toupper(syserr))dnl
1662 AC_MSG_CHECKING([for syserr])
1663 AC_CACHE_VAL([glibcxx_cv_system_error[]n_syserr], [
1664 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <errno.h>]],
1665                                    [int i = syserr;])],
1666                   [glibcxx_cv_system_error[]n_syserr=yes],
1667                   [glibcxx_cv_system_error[]n_syserr=no])
1668 ])
1669 AC_MSG_RESULT([$glibcxx_cv_system_error[]n_syserr])
1670 if test x"$glibcxx_cv_system_error[]n_syserr" = x"yes"; then
1671   AC_DEFINE([HAVE_]SYSERR, 1, [Define if ]syserr[ exists.])
1672 fi
1673 m4_define([n_syserr], m4_incr(n_syserr))dnl
1674 m4_popdef([SYSERR])dnl
1675 ])
1676 m4_popdef([n_syserr])dnl
1677 ])
1678
1679 dnl
1680 dnl Check for what type of C headers to use.
1681 dnl
1682 dnl --enable-cheaders= [does stuff].
1683 dnl --disable-cheaders [does not do anything, really].
1684 dnl  +  Usage:  GLIBCXX_ENABLE_CHEADERS[(DEFAULT)]
1685 dnl       Where DEFAULT is either 'c' or 'c_std' or 'c_global'.
1686 dnl
1687 AC_DEFUN([GLIBCXX_ENABLE_CHEADERS], [
1688   GLIBCXX_ENABLE(cheaders,$1,[=KIND],
1689     [construct "C" headers for g++], [permit c|c_std|c_global])
1690   AC_MSG_NOTICE("C" header strategy set to $enable_cheaders)
1691
1692   C_INCLUDE_DIR='${glibcxx_srcdir}/include/'$enable_cheaders
1693
1694   # Allow overrides to configure.host here.
1695   if test $enable_cheaders = c_global; then
1696      c_compatibility=yes
1697   fi
1698
1699   if test $enable_cheaders = c_global || test $enable_cheaders = c_std; then
1700      c_extra=yes
1701   fi
1702
1703   AC_SUBST(C_INCLUDE_DIR)
1704   GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_C, test $enable_cheaders = c)
1705   GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_C_STD, test $enable_cheaders = c_std)
1706   GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_C_GLOBAL, test $enable_cheaders = c_global)
1707   GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_COMPATIBILITY, test $c_compatibility = yes)
1708   GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_EXTRA, test $c_extra = yes)
1709 ])
1710
1711
1712 dnl
1713 dnl Check for which locale library to use.  The choice is mapped to
1714 dnl a subdirectory of config/locale.
1715 dnl
1716 dnl Default is generic.
1717 dnl
1718 AC_DEFUN([GLIBCXX_ENABLE_CLOCALE], [
1719   GLIBCXX_ENABLE(clocale,auto,[@<:@=MODEL@:>@],
1720     [use MODEL for target locale package],
1721     [permit generic|gnu|ieee_1003.1-2001|yes|no|auto])
1722
1723   # Deal with gettext issues.  Default to not using it (=no) until we detect
1724   # support for it later.  Let the user turn it off via --e/d, but let that
1725   # default to on for easier handling.
1726   USE_NLS=no
1727   AC_ARG_ENABLE(nls,
1728     AC_HELP_STRING([--enable-nls],[use Native Language Support (default)]),
1729     [],
1730     [enable_nls=yes])
1731   
1732   # Either a known packaage, or "auto"
1733   if test $enable_clocale = no || test $enable_clocale = yes; then
1734      enable_clocale=auto
1735   fi
1736   enable_clocale_flag=$enable_clocale
1737
1738   # Probe for locale model to use if none specified.
1739   # Default to "generic".
1740   if test $enable_clocale_flag = auto; then
1741     case ${target_os} in
1742       linux* | gnu* | kfreebsd*-gnu | knetbsd*-gnu)
1743         enable_clocale_flag=gnu 
1744         ;;
1745       darwin* | freebsd*)
1746         enable_clocale_flag=darwin
1747         ;;
1748       *)
1749         enable_clocale_flag=generic
1750         ;;
1751     esac
1752   fi
1753
1754   # Sanity check model, and test for special functionality.
1755   if test $enable_clocale_flag = gnu; then
1756     AC_EGREP_CPP([_GLIBCXX_ok], [
1757     #include <features.h>
1758     #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
1759       _GLIBCXX_ok
1760     #endif
1761     ], enable_clocale_flag=gnu, enable_clocale_flag=generic)
1762
1763     if test $enable_clocale = auto; then
1764       # Test for bugs early in glibc-2.2.x series
1765       AC_TRY_RUN([
1766       #define _GNU_SOURCE 1
1767       #include <locale.h>
1768       #include <string.h>
1769       #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
1770       extern __typeof(newlocale) __newlocale;
1771       extern __typeof(duplocale) __duplocale;
1772       extern __typeof(strcoll_l) __strcoll_l;
1773       #endif
1774       int main()
1775       {
1776         const char __one[] = "Äuglein Augmen";
1777         const char __two[] = "Äuglein";
1778         int i;
1779         int j;
1780         __locale_t        loc;
1781         __locale_t        loc_dup;
1782         loc = __newlocale(1 << LC_ALL, "de_DE", 0);
1783         loc_dup = __duplocale(loc);
1784         i = __strcoll_l(__one, __two, loc);
1785         j = __strcoll_l(__one, __two, loc_dup);
1786         return 0;
1787       }
1788       ],
1789       [enable_clocale_flag=gnu],[enable_clocale_flag=generic],
1790       [enable_clocale_flag=generic])
1791     fi
1792
1793     # Set it to scream when it hurts.
1794     ac_save_CFLAGS="$CFLAGS"    
1795     CFLAGS="-Wimplicit-function-declaration -Werror"
1796
1797     # Use strxfrm_l if available.
1798     AC_TRY_COMPILE([#define _GNU_SOURCE 1
1799                     #include <string.h>
1800                     #include <locale.h>],
1801                     [char s[128]; __locale_t loc; strxfrm_l(s, "C", 5, loc);], 
1802                     AC_DEFINE(HAVE_STRXFRM_L, 1, 
1803                     [Define if strxfrm_l is available in <string.h>.]),)
1804     
1805     # Use strerror_l if available.
1806     AC_TRY_COMPILE([#define _GNU_SOURCE 1
1807                     #include <string.h>
1808                     #include <locale.h>],
1809                     [__locale_t loc; strerror_l(5, loc);], 
1810                     AC_DEFINE(HAVE_STRERROR_L, 1, 
1811                     [Define if strerror_l is available in <string.h>.]),)
1812
1813     CFLAGS="$ac_save_CFLAGS"
1814   fi
1815
1816   # Perhaps use strerror_r if available, and strerror_l isn't.
1817   ac_save_CFLAGS="$CFLAGS"      
1818   CFLAGS="-Wimplicit-function-declaration -Werror"
1819   AC_TRY_COMPILE([#define _GNU_SOURCE 1
1820                   #include <string.h>
1821                   #include <locale.h>],
1822                   [char s[128]; strerror_r(5, s, 128);], 
1823                   AC_DEFINE(HAVE_STRERROR_R, 1, 
1824                   [Define if strerror_r is available in <string.h>.]),)
1825   CFLAGS="$ac_save_CFLAGS"
1826
1827   # Set configure bits for specified locale package
1828   AC_MSG_CHECKING([for C locale to use])
1829   case ${enable_clocale_flag} in
1830     generic)
1831       AC_MSG_RESULT(generic)
1832
1833       CLOCALE_H=config/locale/generic/c_locale.h
1834       CLOCALE_CC=config/locale/generic/c_locale.cc
1835       CCODECVT_CC=config/locale/generic/codecvt_members.cc
1836       CCOLLATE_CC=config/locale/generic/collate_members.cc
1837       CCTYPE_CC=config/locale/generic/ctype_members.cc
1838       CMESSAGES_H=config/locale/generic/messages_members.h
1839       CMESSAGES_CC=config/locale/generic/messages_members.cc
1840       CMONEY_CC=config/locale/generic/monetary_members.cc
1841       CNUMERIC_CC=config/locale/generic/numeric_members.cc
1842       CTIME_H=config/locale/generic/time_members.h
1843       CTIME_CC=config/locale/generic/time_members.cc
1844       CLOCALE_INTERNAL_H=config/locale/generic/c++locale_internal.h
1845       ;;
1846     darwin)
1847       AC_MSG_RESULT(darwin or freebsd)
1848
1849       CLOCALE_H=config/locale/generic/c_locale.h
1850       CLOCALE_CC=config/locale/generic/c_locale.cc
1851       CCODECVT_CC=config/locale/generic/codecvt_members.cc
1852       CCOLLATE_CC=config/locale/generic/collate_members.cc
1853       CCTYPE_CC=config/locale/darwin/ctype_members.cc
1854       CMESSAGES_H=config/locale/generic/messages_members.h
1855       CMESSAGES_CC=config/locale/generic/messages_members.cc
1856       CMONEY_CC=config/locale/generic/monetary_members.cc
1857       CNUMERIC_CC=config/locale/generic/numeric_members.cc
1858       CTIME_H=config/locale/generic/time_members.h
1859       CTIME_CC=config/locale/generic/time_members.cc
1860       CLOCALE_INTERNAL_H=config/locale/generic/c++locale_internal.h
1861       ;;
1862         
1863     gnu)
1864       AC_MSG_RESULT(gnu)
1865
1866       # Declare intention to use gettext, and add support for specific
1867       # languages.
1868       # For some reason, ALL_LINGUAS has to be before AM-GNU-GETTEXT
1869       ALL_LINGUAS="de fr"
1870
1871       # Don't call AM-GNU-GETTEXT here. Instead, assume glibc.
1872       AC_CHECK_PROG(check_msgfmt, msgfmt, yes, no)
1873       if test x"$check_msgfmt" = x"yes" && test x"$enable_nls" = x"yes"; then
1874         USE_NLS=yes
1875       fi
1876       # Export the build objects.
1877       for ling in $ALL_LINGUAS; do \
1878         glibcxx_MOFILES="$glibcxx_MOFILES $ling.mo"; \
1879         glibcxx_POFILES="$glibcxx_POFILES $ling.po"; \
1880       done
1881       AC_SUBST(glibcxx_MOFILES)
1882       AC_SUBST(glibcxx_POFILES)
1883
1884       CLOCALE_H=config/locale/gnu/c_locale.h
1885       CLOCALE_CC=config/locale/gnu/c_locale.cc
1886       CCODECVT_CC=config/locale/gnu/codecvt_members.cc
1887       CCOLLATE_CC=config/locale/gnu/collate_members.cc
1888       CCTYPE_CC=config/locale/gnu/ctype_members.cc
1889       CMESSAGES_H=config/locale/gnu/messages_members.h
1890       CMESSAGES_CC=config/locale/gnu/messages_members.cc
1891       CMONEY_CC=config/locale/gnu/monetary_members.cc
1892       CNUMERIC_CC=config/locale/gnu/numeric_members.cc
1893       CTIME_H=config/locale/gnu/time_members.h
1894       CTIME_CC=config/locale/gnu/time_members.cc
1895       CLOCALE_INTERNAL_H=config/locale/gnu/c++locale_internal.h
1896       ;;
1897     ieee_1003.1-2001)
1898       AC_MSG_RESULT(IEEE 1003.1)
1899
1900       CLOCALE_H=config/locale/ieee_1003.1-2001/c_locale.h
1901       CLOCALE_CC=config/locale/ieee_1003.1-2001/c_locale.cc
1902       CCODECVT_CC=config/locale/generic/codecvt_members.cc
1903       CCOLLATE_CC=config/locale/generic/collate_members.cc
1904       CCTYPE_CC=config/locale/generic/ctype_members.cc
1905       CMESSAGES_H=config/locale/ieee_1003.1-2001/messages_members.h
1906       CMESSAGES_CC=config/locale/ieee_1003.1-2001/messages_members.cc
1907       CMONEY_CC=config/locale/generic/monetary_members.cc
1908       CNUMERIC_CC=config/locale/generic/numeric_members.cc
1909       CTIME_H=config/locale/generic/time_members.h
1910       CTIME_CC=config/locale/generic/time_members.cc
1911       CLOCALE_INTERNAL_H=config/locale/generic/c++locale_internal.h
1912       ;;
1913   esac
1914
1915   # This is where the testsuite looks for locale catalogs, using the
1916   # -DLOCALEDIR define during testsuite compilation.
1917   glibcxx_localedir=${glibcxx_builddir}/po/share/locale
1918   AC_SUBST(glibcxx_localedir)
1919
1920   # A standalone libintl (e.g., GNU libintl) may be in use.
1921   if test $USE_NLS = yes; then
1922     AC_CHECK_HEADERS([libintl.h], [], USE_NLS=no)
1923     AC_SEARCH_LIBS(gettext, intl, [], USE_NLS=no)
1924   fi
1925   if test $USE_NLS = yes; then
1926     AC_DEFINE(_GLIBCXX_USE_NLS, 1, 
1927               [Define if NLS translations are to be used.])
1928   fi
1929
1930   AC_SUBST(USE_NLS)
1931   AC_SUBST(CLOCALE_H)
1932   AC_SUBST(CMESSAGES_H)
1933   AC_SUBST(CCODECVT_CC)
1934   AC_SUBST(CCOLLATE_CC)
1935   AC_SUBST(CCTYPE_CC)
1936   AC_SUBST(CMESSAGES_CC)
1937   AC_SUBST(CMONEY_CC)
1938   AC_SUBST(CNUMERIC_CC)
1939   AC_SUBST(CTIME_H)
1940   AC_SUBST(CTIME_CC)
1941   AC_SUBST(CLOCALE_CC)
1942   AC_SUBST(CLOCALE_INTERNAL_H)
1943 ])
1944
1945
1946 dnl
1947 dnl Check for which std::allocator base class to use.  The choice is
1948 dnl mapped from a subdirectory of include/ext.
1949 dnl
1950 dnl Default is new.
1951 dnl
1952 AC_DEFUN([GLIBCXX_ENABLE_ALLOCATOR], [
1953   AC_MSG_CHECKING([for std::allocator base class])
1954   GLIBCXX_ENABLE(libstdcxx-allocator,auto,[=KIND],
1955     [use KIND for target std::allocator base],
1956     [permit new|malloc|mt|bitmap|pool|yes|no|auto])
1957
1958   # If they didn't use this option switch, or if they specified --enable
1959   # with no specific model, we'll have to look for one.  If they
1960   # specified --disable (???), do likewise.
1961   if test $enable_libstdcxx_allocator = no ||
1962      test $enable_libstdcxx_allocator = yes;
1963   then
1964      enable_libstdcxx_allocator=auto
1965   fi
1966
1967   # Either a known package, or "auto". Auto implies the default choice
1968   # for a particular platform.
1969   enable_libstdcxx_allocator_flag=$enable_libstdcxx_allocator
1970
1971   # Probe for host-specific support if no specific model is specified.
1972   # Default to "new".
1973   if test $enable_libstdcxx_allocator_flag = auto; then
1974     case ${target_os} in
1975       linux* | gnu* | kfreebsd*-gnu | knetbsd*-gnu)
1976         enable_libstdcxx_allocator_flag=new
1977         ;;
1978       *)
1979         enable_libstdcxx_allocator_flag=new
1980         ;;
1981     esac
1982   fi
1983   AC_MSG_RESULT($enable_libstdcxx_allocator_flag)
1984   
1985
1986   # Set configure bits for specified locale package
1987   case ${enable_libstdcxx_allocator_flag} in
1988     bitmap)
1989       ALLOCATOR_H=config/allocator/bitmap_allocator_base.h
1990       ALLOCATOR_NAME=__gnu_cxx::bitmap_allocator
1991       ;;
1992     malloc)
1993       ALLOCATOR_H=config/allocator/malloc_allocator_base.h
1994       ALLOCATOR_NAME=__gnu_cxx::malloc_allocator
1995       ;;
1996     mt)
1997       ALLOCATOR_H=config/allocator/mt_allocator_base.h
1998       ALLOCATOR_NAME=__gnu_cxx::__mt_alloc
1999       ;;
2000     new)
2001       ALLOCATOR_H=config/allocator/new_allocator_base.h
2002       ALLOCATOR_NAME=__gnu_cxx::new_allocator
2003       ;;
2004     pool)
2005       ALLOCATOR_H=config/allocator/pool_allocator_base.h
2006       ALLOCATOR_NAME=__gnu_cxx::__pool_alloc
2007       ;;        
2008   esac
2009
2010   AC_SUBST(ALLOCATOR_H)
2011   AC_SUBST(ALLOCATOR_NAME)
2012 ])
2013
2014
2015 dnl
2016 dnl Check for whether the Boost-derived checks should be turned on.
2017 dnl
2018 dnl --enable-concept-checks turns them on.
2019 dnl --disable-concept-checks leaves them off.
2020 dnl  +  Usage:  GLIBCXX_ENABLE_CONCEPT_CHECKS[(DEFAULT)]
2021 dnl       Where DEFAULT is either `yes' or `no'.
2022 dnl
2023 AC_DEFUN([GLIBCXX_ENABLE_CONCEPT_CHECKS], [
2024   GLIBCXX_ENABLE(concept-checks,$1,,[use Boost-derived template checks])
2025   if test $enable_concept_checks = yes; then
2026     AC_DEFINE(_GLIBCXX_CONCEPT_CHECKS, 1,
2027               [Define to use concept checking code from the boost libraries.])
2028   fi
2029 ])
2030
2031 dnl
2032 dnl Check for parallel mode pre-requisites, including OpenMP support.
2033 dnl
2034 dnl  +  Usage:  GLIBCXX_ENABLE_PARALLEL
2035 dnl
2036 AC_DEFUN([GLIBCXX_ENABLE_PARALLEL], [
2037
2038   enable_parallel=no;
2039
2040   # See if configured libgomp/omp.h exists. (libgomp may be in
2041   # noconfigdirs but not explicitly disabled.)
2042   if test -f $glibcxx_builddir/../libgomp/omp.h; then
2043     enable_parallel=yes;
2044   else
2045     AC_MSG_NOTICE([$glibcxx_builddir/../libgomp/omp.h not found])
2046   fi
2047
2048   AC_MSG_CHECKING([for parallel mode support])
2049   AC_MSG_RESULT([$enable_parallel])
2050   GLIBCXX_CONDITIONAL(ENABLE_PARALLEL, test $enable_parallel = yes)
2051 ])
2052
2053
2054 dnl
2055 dnl Check for which I/O library to use:  stdio, or something specific.
2056 dnl
2057 dnl Default is stdio.
2058 dnl
2059 AC_DEFUN([GLIBCXX_ENABLE_CSTDIO], [
2060   AC_MSG_CHECKING([for underlying I/O to use])
2061   GLIBCXX_ENABLE(cstdio,stdio,[=PACKAGE],
2062     [use target-specific I/O package], [permit stdio])
2063
2064   # Now that libio has been removed, you can have any color you want as long
2065   # as it's black.  This is one big no-op until other packages are added, but
2066   # showing the framework never hurts.
2067   case ${enable_cstdio} in
2068     stdio)
2069       CSTDIO_H=config/io/c_io_stdio.h
2070       BASIC_FILE_H=config/io/basic_file_stdio.h
2071       BASIC_FILE_CC=config/io/basic_file_stdio.cc
2072       AC_MSG_RESULT(stdio)
2073       ;;
2074   esac
2075
2076   AC_SUBST(CSTDIO_H)
2077   AC_SUBST(BASIC_FILE_H)
2078   AC_SUBST(BASIC_FILE_CC)
2079 ])
2080
2081
2082 dnl
2083 dnl Check for "unusual" flags to pass to the compiler while building.
2084 dnl
2085 dnl --enable-cxx-flags='-foo -bar -baz' is a general method for passing
2086 dnl     experimental flags such as -fpch, -fIMI, -Dfloat=char, etc.
2087 dnl --disable-cxx-flags passes nothing.
2088 dnl  +  See http://gcc.gnu.org/ml/libstdc++/2000-q2/msg00131.html
2089 dnl         http://gcc.gnu.org/ml/libstdc++/2000-q2/msg00284.html
2090 dnl         http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00035.html
2091 dnl  +  Usage:  GLIBCXX_ENABLE_CXX_FLAGS(default flags)
2092 dnl       If "default flags" is an empty string, the effect is the same
2093 dnl       as --disable or --enable=no.
2094 dnl
2095 AC_DEFUN([GLIBCXX_ENABLE_CXX_FLAGS], [dnl
2096   AC_MSG_CHECKING([for extra compiler flags for building])
2097   GLIBCXX_ENABLE(cxx-flags,$1,[=FLAGS],
2098     [pass compiler FLAGS when building library],
2099     [case "x$enable_cxx_flags" in
2100       xno | x)   enable_cxx_flags= ;;
2101       x-*)       ;;
2102       *)         AC_MSG_ERROR(_g_switch needs compiler flags as arguments) ;;
2103      esac])
2104
2105   # Run through flags (either default or command-line) and set anything
2106   # extra (e.g., #defines) that must accompany particular g++ options.
2107   if test -n "$enable_cxx_flags"; then
2108     for f in $enable_cxx_flags; do
2109       case "$f" in
2110         -fhonor-std)  ;;
2111         -*)  ;;
2112         *)   # and we're trying to pass /what/ exactly?
2113              AC_MSG_ERROR([compiler flags start with a -]) ;;
2114       esac
2115     done
2116   fi
2117
2118   EXTRA_CXX_FLAGS="$enable_cxx_flags"
2119   AC_MSG_RESULT($EXTRA_CXX_FLAGS)
2120   AC_SUBST(EXTRA_CXX_FLAGS)
2121 ])
2122
2123
2124 dnl
2125 dnl Check to see if debugging libraries are to be built.
2126 dnl
2127 dnl --enable-libstdcxx-debug
2128 dnl builds a separate set of debugging libraries in addition to the
2129 dnl normal (shared, static) libstdc++ binaries.
2130 dnl
2131 dnl --disable-libstdcxx-debug
2132 dnl builds only one (non-debug) version of libstdc++.
2133 dnl
2134 dnl --enable-libstdcxx-debug-flags=FLAGS
2135 dnl iff --enable-debug == yes, then use FLAGS to build the debug library.
2136 dnl
2137 dnl  +  Usage:  GLIBCXX_ENABLE_DEBUG[(DEFAULT)]
2138 dnl       Where DEFAULT is either `yes' or `no'.
2139 dnl
2140 AC_DEFUN([GLIBCXX_ENABLE_DEBUG], [
2141   AC_MSG_CHECKING([for additional debug build])
2142   GLIBCXX_ENABLE(libstdcxx-debug,$1,,[build extra debug library])
2143   AC_MSG_RESULT($enable_libstdcxx_debug)
2144   GLIBCXX_CONDITIONAL(GLIBCXX_BUILD_DEBUG, test $enable_libstdcxx_debug = yes)
2145 ])
2146
2147
2148 dnl
2149 dnl Check for explicit debug flags.
2150 dnl
2151 dnl --enable-libstdcxx-debug-flags='-O1'
2152 dnl is a general method for passing flags to be used when
2153 dnl building debug libraries with --enable-debug.
2154 dnl
2155 dnl --disable-libstdcxx-debug-flags does nothing.
2156 dnl  +  Usage:  GLIBCXX_ENABLE_DEBUG_FLAGS(default flags)
2157 dnl       If "default flags" is an empty string, the effect is the same
2158 dnl       as --disable or --enable=no.
2159 dnl
2160 AC_DEFUN([GLIBCXX_ENABLE_DEBUG_FLAGS], [
2161   GLIBCXX_ENABLE(libstdcxx-debug-flags,[$1],[=FLAGS],
2162     [pass compiler FLAGS when building debug library],
2163     [case "x$enable_libstdcxx_debug_flags" in
2164       xno | x)    enable_libstdcxx_debug_flags= ;;
2165       x-*)        ;;
2166       *)          AC_MSG_ERROR(_g_switch needs compiler flags as arguments) ;;
2167      esac])
2168
2169   # Option parsed, now set things appropriately
2170   DEBUG_FLAGS="$enable_libstdcxx_debug_flags"
2171   AC_SUBST(DEBUG_FLAGS)
2172
2173   AC_MSG_NOTICE([Debug build flags set to $DEBUG_FLAGS])
2174 ])
2175
2176
2177 dnl
2178 dnl Check if the user only wants a freestanding library implementation.
2179 dnl
2180 dnl --disable-hosted-libstdcxx will turn off most of the library build,
2181 dnl installing only the headers required by [17.4.1.3] and the language
2182 dnl support library.  More than that will be built (to keep the Makefiles
2183 dnl conveniently clean), but not installed.
2184 dnl
2185 dnl Sets:
2186 dnl  is_hosted  (yes/no)
2187 dnl
2188 dnl Defines:
2189 dnl  _GLIBCXX_HOSTED   (always defined, either to 1 or 0)
2190 dnl
2191 AC_DEFUN([GLIBCXX_ENABLE_HOSTED], [
2192   AC_ARG_ENABLE([hosted-libstdcxx],
2193     AC_HELP_STRING([--disable-hosted-libstdcxx],
2194                    [only build freestanding C++ runtime support]),,
2195     [case "$host" in
2196         arm*-*-symbianelf*) 
2197             enable_hosted_libstdcxx=no
2198             ;;
2199         *) 
2200             enable_hosted_libstdcxx=yes
2201             ;;
2202      esac])
2203   if test "$enable_hosted_libstdcxx" = no; then
2204     AC_MSG_NOTICE([Only freestanding libraries will be built])
2205     is_hosted=no
2206     hosted_define=0
2207     enable_abi_check=no
2208     enable_libstdcxx_pch=no
2209   else
2210     is_hosted=yes
2211     hosted_define=1
2212   fi
2213   GLIBCXX_CONDITIONAL(GLIBCXX_HOSTED, test $is_hosted = yes)
2214   AC_DEFINE_UNQUOTED(_GLIBCXX_HOSTED, $hosted_define,
2215     [Define to 1 if a full hosted library is built, or 0 if freestanding.])
2216 ])
2217
2218
2219 dnl
2220 dnl Check for template specializations for the 'long long' type.
2221 dnl The result determines only whether 'long long' I/O is enabled; things
2222 dnl like numeric_limits<> specializations are always available.
2223 dnl
2224 dnl --enable-long-long defines _GLIBCXX_USE_LONG_LONG
2225 dnl --disable-long-long leaves _GLIBCXX_USE_LONG_LONG undefined
2226 dnl  +  Usage:  GLIBCXX_ENABLE_LONG_LONG[(DEFAULT)]
2227 dnl       Where DEFAULT is either `yes' or `no'.
2228 dnl
2229 AC_DEFUN([GLIBCXX_ENABLE_LONG_LONG], [
2230   GLIBCXX_ENABLE(long-long,$1,,[enable template specializations for 'long long'])
2231   if test $enable_long_long = yes; then
2232     AC_DEFINE(_GLIBCXX_USE_LONG_LONG, 1, 
2233               [Define if code specialized for long long should be used.])
2234   fi
2235   AC_MSG_CHECKING([for enabled long long specializations])
2236   AC_MSG_RESULT([$enable_long_long])
2237 ])
2238
2239
2240 dnl
2241 dnl Check for template specializations for the 'wchar_t' type.
2242 dnl
2243 dnl --enable-wchar_t defines _GLIBCXX_USE_WCHAR_T
2244 dnl --disable-wchar_t leaves _GLIBCXX_USE_WCHAR_T undefined
2245 dnl  +  Usage:  GLIBCXX_ENABLE_WCHAR_T[(DEFAULT)]
2246 dnl       Where DEFAULT is either `yes' or `no'.
2247 dnl
2248 dnl Necessary support must also be present.
2249 dnl
2250 AC_DEFUN([GLIBCXX_ENABLE_WCHAR_T], [
2251   GLIBCXX_ENABLE(wchar_t,$1,,[enable template specializations for 'wchar_t'])
2252
2253   # Test wchar.h for mbstate_t, which is needed for char_traits and fpos.
2254   AC_CHECK_HEADERS(wchar.h, ac_has_wchar_h=yes, ac_has_wchar_h=no)
2255   AC_MSG_CHECKING([for mbstate_t])
2256   AC_TRY_COMPILE([#include <wchar.h>],
2257   [mbstate_t teststate;],
2258   have_mbstate_t=yes, have_mbstate_t=no)
2259   AC_MSG_RESULT($have_mbstate_t)
2260   if test x"$have_mbstate_t" = xyes; then
2261     AC_DEFINE(HAVE_MBSTATE_T,1,[Define if mbstate_t exists in wchar.h.])
2262   fi
2263
2264   # Test it always, for use in GLIBCXX_ENABLE_C99, together with
2265   # ac_has_wchar_h.
2266   AC_CHECK_HEADERS(wctype.h, ac_has_wctype_h=yes, ac_has_wctype_h=no)
2267   
2268   if test x"$enable_wchar_t" = x"yes"; then
2269
2270     AC_LANG_SAVE
2271     AC_LANG_CPLUSPLUS
2272     
2273     if test x"$ac_has_wchar_h" = xyes &&
2274        test x"$ac_has_wctype_h" = xyes; then
2275       AC_TRY_COMPILE([#include <wchar.h>
2276                       #include <stddef.h>
2277                       wint_t i;
2278                       long l = WEOF;
2279                       long j = WCHAR_MIN;
2280                       long k = WCHAR_MAX;
2281                       namespace test
2282                       {
2283                         using ::btowc;
2284                         using ::fgetwc;
2285                         using ::fgetws;
2286                         using ::fputwc;
2287                         using ::fputws;
2288                         using ::fwide;
2289                         using ::fwprintf; 
2290                         using ::fwscanf;
2291                         using ::getwc;
2292                         using ::getwchar;
2293                         using ::mbrlen; 
2294                         using ::mbrtowc; 
2295                         using ::mbsinit; 
2296                         using ::mbsrtowcs; 
2297                         using ::putwc;
2298                         using ::putwchar;
2299                         using ::swprintf; 
2300                         using ::swscanf; 
2301                         using ::ungetwc;
2302                         using ::vfwprintf; 
2303                         using ::vswprintf; 
2304                         using ::vwprintf; 
2305                         using ::wcrtomb; 
2306                         using ::wcscat; 
2307                         using ::wcschr; 
2308                         using ::wcscmp; 
2309                         using ::wcscoll; 
2310                         using ::wcscpy; 
2311                         using ::wcscspn; 
2312                         using ::wcsftime; 
2313                         using ::wcslen;
2314                         using ::wcsncat; 
2315                         using ::wcsncmp; 
2316                         using ::wcsncpy; 
2317                         using ::wcspbrk;
2318                         using ::wcsrchr; 
2319                         using ::wcsrtombs; 
2320                         using ::wcsspn; 
2321                         using ::wcsstr;
2322                         using ::wcstod; 
2323                         using ::wcstok; 
2324                         using ::wcstol;
2325                         using ::wcstoul; 
2326                         using ::wcsxfrm; 
2327                         using ::wctob; 
2328                         using ::wmemchr;
2329                         using ::wmemcmp;
2330                         using ::wmemcpy;
2331                         using ::wmemmove;
2332                         using ::wmemset;
2333                         using ::wprintf; 
2334                         using ::wscanf; 
2335                       }
2336                      ],[],[], [enable_wchar_t=no])
2337     else
2338       enable_wchar_t=no
2339     fi
2340
2341     AC_LANG_RESTORE
2342   fi
2343
2344   if test x"$enable_wchar_t" = x"yes"; then
2345     AC_DEFINE(_GLIBCXX_USE_WCHAR_T, 1,
2346               [Define if code specialized for wchar_t should be used.])
2347   fi
2348
2349   AC_MSG_CHECKING([for enabled wchar_t specializations])
2350   AC_MSG_RESULT([$enable_wchar_t])
2351 ])
2352
2353
2354 dnl
2355 dnl Check to see if building and using a C++ precompiled header can be done.
2356 dnl
2357 dnl --enable-libstdcxx-pch=yes
2358 dnl default, this shows intent to use stdc++.h.gch If it looks like it
2359 dnl may work, after some light-hearted attempts to puzzle out compiler
2360 dnl support, flip bits on in include/Makefile.am
2361 dnl
2362 dnl --disable-libstdcxx-pch
2363 dnl turns off attempts to use or build stdc++.h.gch.
2364 dnl
2365 dnl Substs:
2366 dnl  glibcxx_PCHFLAGS
2367 dnl
2368 AC_DEFUN([GLIBCXX_ENABLE_PCH], [
2369   GLIBCXX_ENABLE(libstdcxx-pch,$1,,[build pre-compiled libstdc++ headers])
2370   if test $enable_libstdcxx_pch = yes; then
2371     AC_CACHE_CHECK([for compiler with PCH support],
2372       [glibcxx_cv_prog_CXX_pch],
2373       [ac_save_CXXFLAGS="$CXXFLAGS"
2374        CXXFLAGS="$CXXFLAGS -Werror -Winvalid-pch -Wno-deprecated"
2375        AC_LANG_SAVE
2376        AC_LANG_CPLUSPLUS
2377        echo '#include <math.h>' > conftest.h
2378        if $CXX $CXXFLAGS $CPPFLAGS -x c++-header conftest.h \
2379                           -o conftest.h.gch 1>&5 2>&1 &&
2380                 echo '#error "pch failed"' > conftest.h &&
2381           echo '#include "conftest.h"' > conftest.cc &&
2382                $CXX -c $CXXFLAGS $CPPFLAGS conftest.cc 1>&5 2>&1 ;
2383        then
2384          glibcxx_cv_prog_CXX_pch=yes
2385        else
2386          glibcxx_cv_prog_CXX_pch=no
2387        fi
2388        rm -f conftest*
2389        CXXFLAGS=$ac_save_CXXFLAGS
2390        AC_LANG_RESTORE
2391       ])
2392     enable_libstdcxx_pch=$glibcxx_cv_prog_CXX_pch
2393   fi
2394
2395   AC_MSG_CHECKING([for enabled PCH])
2396   AC_MSG_RESULT([$enable_libstdcxx_pch])
2397
2398   GLIBCXX_CONDITIONAL(GLIBCXX_BUILD_PCH, test $enable_libstdcxx_pch = yes)
2399   if test $enable_libstdcxx_pch = yes; then
2400     glibcxx_PCHFLAGS="-include bits/stdc++.h"
2401   else
2402     glibcxx_PCHFLAGS=""
2403   fi
2404   AC_SUBST(glibcxx_PCHFLAGS)
2405 ])
2406
2407
2408 dnl
2409 dnl Check for atomic builtins.
2410 dnl See:
2411 dnl http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html#Atomic-Builtins
2412 dnl
2413 dnl This checks to see if the host supports the compiler-generated
2414 dnl builtins for atomic operations for various integral sizes. Note, this 
2415 dnl is intended to be an all-or-nothing switch, so all the atomic operations
2416 dnl that are used should be checked.
2417 dnl
2418 dnl Note:
2419 dnl libgomp and libgfortran do this with a link test, instead of an asm test.
2420 dnl see: CHECK_SYNC_FETCH_AND_ADD
2421 dnl
2422 dnl Defines:
2423 dnl  _GLIBCXX_ATOMIC_BUILTINS_1 
2424 dnl  _GLIBCXX_ATOMIC_BUILTINS_2
2425 dnl  _GLIBCXX_ATOMIC_BUILTINS_4
2426 dnl  _GLIBCXX_ATOMIC_BUILTINS_8
2427 dnl
2428 AC_DEFUN([GLIBCXX_ENABLE_ATOMIC_BUILTINS], [
2429   AC_LANG_SAVE
2430   AC_LANG_CPLUSPLUS
2431   old_CXXFLAGS="$CXXFLAGS"
2432   
2433   # Compile unoptimized.
2434   CXXFLAGS='-O0 -S'
2435
2436   # Fake what AC_TRY_COMPILE does, without linking as this is
2437   # unnecessary for a builtins test.
2438
2439     cat > conftest.$ac_ext << EOF
2440 [#]line __oline__ "configure"
2441 int main()
2442 {
2443   typedef bool atomic_type;
2444   atomic_type c1;
2445   atomic_type c2;
2446   const atomic_type c3(0);
2447   __sync_fetch_and_add(&c1, c2);
2448   __sync_val_compare_and_swap(&c1, c3, c2);
2449   __sync_lock_test_and_set(&c1, c3);
2450   __sync_lock_release(&c1);
2451   __sync_synchronize();
2452   return 0;
2453 }
2454 EOF
2455
2456     AC_MSG_CHECKING([for atomic builtins for bool])
2457     if AC_TRY_EVAL(ac_compile); then
2458       if grep __sync_ conftest.s >/dev/null 2>&1 ; then
2459         enable_atomic_builtinsb=no
2460       else
2461       AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_1, 1,
2462       [Define if builtin atomic operations for bool are supported on this host.])
2463         enable_atomic_builtinsb=yes
2464       fi
2465     fi
2466     AC_MSG_RESULT($enable_atomic_builtinsb)
2467     rm -f conftest*
2468
2469     cat > conftest.$ac_ext << EOF
2470 [#]line __oline__ "configure"
2471 int main()
2472 {
2473   typedef short atomic_type;
2474   atomic_type c1;
2475   atomic_type c2;
2476   const atomic_type c3(0);
2477   __sync_fetch_and_add(&c1, c2);
2478   __sync_val_compare_and_swap(&c1, c3, c2);
2479   __sync_lock_test_and_set(&c1, c3);
2480   __sync_lock_release(&c1);
2481   __sync_synchronize();
2482   return 0;
2483 }
2484 EOF
2485
2486     AC_MSG_CHECKING([for atomic builtins for short])
2487     if AC_TRY_EVAL(ac_compile); then
2488       if grep __sync_ conftest.s >/dev/null 2>&1 ; then
2489         enable_atomic_builtinss=no
2490       else
2491       AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_2, 1,
2492       [Define if builtin atomic operations for short are supported on this host.])
2493         enable_atomic_builtinss=yes
2494       fi
2495     fi
2496     AC_MSG_RESULT($enable_atomic_builtinss)
2497     rm -f conftest*
2498
2499     cat > conftest.$ac_ext << EOF
2500 [#]line __oline__ "configure"
2501 int main()
2502 {
2503   // NB: _Atomic_word not necessarily int. 
2504   typedef int atomic_type;
2505   atomic_type c1;
2506   atomic_type c2;
2507   const atomic_type c3(0);
2508   __sync_fetch_and_add(&c1, c2);
2509   __sync_val_compare_and_swap(&c1, c3, c2);
2510   __sync_lock_test_and_set(&c1, c3);
2511   __sync_lock_release(&c1);
2512   __sync_synchronize();
2513   return 0;
2514 }
2515 EOF
2516
2517     AC_MSG_CHECKING([for atomic builtins for int])
2518     if AC_TRY_EVAL(ac_compile); then
2519       if grep __sync_ conftest.s >/dev/null 2>&1 ; then
2520         enable_atomic_builtinsi=no
2521       else
2522       AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_4, 1,
2523         [Define if builtin atomic operations for int are supported on this host.])
2524         enable_atomic_builtinsi=yes
2525       fi
2526     fi
2527     AC_MSG_RESULT($enable_atomic_builtinsi)
2528     rm -f conftest*
2529
2530     cat > conftest.$ac_ext << EOF
2531 [#]line __oline__ "configure"
2532 int main()
2533 {
2534   typedef long long atomic_type;
2535   atomic_type c1;
2536   atomic_type c2;
2537   const atomic_type c3(0);
2538   __sync_fetch_and_add(&c1, c2);
2539   __sync_val_compare_and_swap(&c1, c3, c2);
2540   __sync_lock_test_and_set(&c1, c3);
2541   __sync_lock_release(&c1);
2542   __sync_synchronize();
2543   return 0;
2544 }
2545 EOF
2546
2547     AC_MSG_CHECKING([for atomic builtins for long long])
2548     if AC_TRY_EVAL(ac_compile); then
2549       if grep __sync_ conftest.s >/dev/null 2>&1 ; then
2550         enable_atomic_builtinsll=no
2551       else
2552       AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_8, 1,
2553       [Define if builtin atomic operations for long long are supported on this host.])
2554         enable_atomic_builtinsll=yes
2555       fi
2556     fi
2557     AC_MSG_RESULT($enable_atomic_builtinsll)
2558     rm -f conftest*
2559
2560
2561   CXXFLAGS="$old_CXXFLAGS"
2562   AC_LANG_RESTORE
2563
2564   # Set atomicity_dir to builtins if either of above tests pass.
2565   if test $enable_atomic_builtinsi = yes || test $enable_atomic_builtinsb = yes ; then
2566     atomicity_dir=cpu/generic/atomicity_builtins
2567   fi
2568
2569   # If still generic, set to mutex.
2570   if test $atomicity_dir = "cpu/generic" ; then
2571     atomicity_dir=cpu/generic/atomicity_mutex
2572     AC_MSG_WARN([No native atomic operations are provided for this platform.])
2573       if test $target_thread_file = single; then
2574         AC_MSG_WARN([They cannot be faked when thread support is disabled.])
2575         AC_MSG_WARN([Thread-safety of certain classes is not guaranteed.])
2576       else
2577         AC_MSG_WARN([They will be faked using a mutex.])
2578         AC_MSG_WARN([Performance of certain classes will degrade as a result.])
2579       fi
2580   fi
2581
2582 ])
2583
2584
2585 dnl
2586 dnl Check for exception handling support.  If an explicit enable/disable
2587 dnl sjlj exceptions is given, we don't have to detect.  Otherwise the
2588 dnl target may or may not support call frame exceptions.
2589 dnl
2590 dnl --enable-sjlj-exceptions forces the use of builtin setjmp.
2591 dnl --disable-sjlj-exceptions forces the use of call frame unwinding.
2592 dnl Neither one forces an attempt at detection.
2593 dnl
2594 dnl Defines:
2595 dnl  _GLIBCXX_SJLJ_EXCEPTIONS if the compiler is configured for it
2596 dnl
2597 AC_DEFUN([GLIBCXX_ENABLE_SJLJ_EXCEPTIONS], [
2598   AC_MSG_CHECKING([for exception model to use])
2599   AC_LANG_SAVE
2600   AC_LANG_CPLUSPLUS
2601   GLIBCXX_ENABLE(sjlj-exceptions,auto,,
2602     [force use of builtin_setjmp for exceptions],
2603     [permit yes|no|auto])
2604
2605   if test $enable_sjlj_exceptions = auto; then
2606     # Botheration.  Now we've got to detect the exception model.  Link tests
2607     # against libgcc.a are problematic since we've not been given proper -L
2608     # bits for single-tree newlib and libgloss.
2609     #
2610     # Fake what AC_TRY_COMPILE does.  XXX Look at redoing this new-style.
2611     cat > conftest.$ac_ext << EOF
2612 [#]line __oline__ "configure"
2613 struct S { ~S(); };
2614 void bar();
2615 void foo()
2616 {
2617   S s;
2618   bar();
2619 }
2620 EOF
2621     old_CXXFLAGS="$CXXFLAGS"
2622     CXXFLAGS=-S
2623     if AC_TRY_EVAL(ac_compile); then
2624       if grep _Unwind_SjLj_Resume conftest.s >/dev/null 2>&1 ; then
2625         enable_sjlj_exceptions=yes
2626       elif grep _Unwind_Resume conftest.s >/dev/null 2>&1 ; then
2627         enable_sjlj_exceptions=no
2628       elif grep __cxa_end_cleanup conftest.s >/dev/null 2>&1 ; then
2629         enable_sjlj_exceptions=no
2630       fi
2631     fi
2632     CXXFLAGS="$old_CXXFLAGS"
2633     rm -f conftest*
2634   fi
2635
2636   # This is a tad weird, for hysterical raisins.  We have to map
2637   # enable/disable to two different models.
2638   case $enable_sjlj_exceptions in
2639     yes)
2640       AC_DEFINE(_GLIBCXX_SJLJ_EXCEPTIONS, 1,
2641         [Define if the compiler is configured for setjmp/longjmp exceptions.])
2642       ac_exception_model_name=sjlj
2643       ;;
2644     no)
2645       ac_exception_model_name="call frame"
2646       ;;
2647     *)
2648       AC_MSG_ERROR([unable to detect exception model])
2649       ;;
2650   esac
2651  AC_LANG_RESTORE
2652  AC_MSG_RESULT($ac_exception_model_name)
2653 ])
2654
2655
2656 dnl
2657 dnl Allow visibility attributes to be used on namespaces, objects, etc.
2658 dnl
2659 dnl --enable-visibility enables attempt to use visibility attributes.
2660 dnl --disable-visibility turns off all use of visibility attributes.
2661 dnl  +  Usage:  GLIBCXX_ENABLE_VISIBILITY[(DEFAULT)]
2662 dnl       Where DEFAULT is 'yes'.
2663 dnl
2664 AC_DEFUN([GLIBCXX_ENABLE_VISIBILITY], [
2665 GLIBCXX_ENABLE(visibility,$1,,[enables visibility safe usage])
2666
2667 if test x$enable_visibility = xyes ; then
2668   dnl all hail libgfortran
2669   dnl Check whether the target supports hidden visibility.
2670   AC_CACHE_CHECK([whether the target supports hidden visibility],
2671                  glibcxx_cv_have_attribute_visibility, [
2672   save_CFLAGS="$CFLAGS"
2673   CFLAGS="$CFLAGS -Werror"
2674   AC_TRY_COMPILE([void __attribute__((visibility("hidden"))) foo(void) { }],
2675                  [], glibcxx_cv_have_attribute_visibility=yes,
2676                  glibcxx_cv_have_attribute_visibility=no)
2677   CFLAGS="$save_CFLAGS"])
2678   if test $glibcxx_cv_have_attribute_visibility = no; then
2679     enable_visibility=no
2680   fi
2681 fi
2682
2683 GLIBCXX_CONDITIONAL(ENABLE_VISIBILITY, test $enable_visibility = yes)
2684 AC_MSG_NOTICE([visibility supported: $enable_visibility])
2685 ])
2686
2687
2688 dnl
2689 dnl Add version tags to symbols in shared library (or not), additionally
2690 dnl marking other symbols as private/local (or not).
2691 dnl
2692 dnl --enable-symvers=style adds a version script to the linker call when
2693 dnl       creating the shared library.  The choice of version script is
2694 dnl       controlled by 'style'.
2695 dnl --disable-symvers does not.
2696 dnl  +  Usage:  GLIBCXX_ENABLE_SYMVERS[(DEFAULT)]
2697 dnl       Where DEFAULT is either 'yes' or 'no'.  Passing `yes' tries to
2698 dnl       choose a default style based on linker characteristics.  Passing
2699 dnl       'no' disables versioning.
2700 dnl
2701 AC_DEFUN([GLIBCXX_ENABLE_SYMVERS], [
2702
2703 GLIBCXX_ENABLE(symvers,$1,[=STYLE],
2704   [enables symbol versioning of the shared library],
2705   [permit yes|no|gnu|gnu-versioned-namespace|darwin|darwin-export])
2706
2707 # If we never went through the GLIBCXX_CHECK_LINKER_FEATURES macro, then we
2708 # don't know enough about $LD to do tricks...
2709 AC_REQUIRE([GLIBCXX_CHECK_LINKER_FEATURES])
2710
2711 # Turn a 'yes' into a suitable default.
2712 if test x$enable_symvers = xyes ; then
2713   if test $enable_shared = no || test "x$LD" = x || test x$gcc_no_link = xyes; then
2714     enable_symvers=no
2715   else
2716     if test $with_gnu_ld = yes ; then
2717       case ${target_os} in
2718         cygwin* | pe | mingw32*)
2719           enable_symvers=no ;;
2720         *)
2721           enable_symvers=gnu ;;
2722       esac
2723     else
2724       case ${target_os} in
2725         darwin*)
2726           enable_symvers=darwin ;;
2727         *)
2728           enable_symvers=no ;;
2729       esac
2730     fi
2731   fi
2732 fi
2733
2734 # Check to see if 'darwin' or 'darwin-export' can win.
2735 if test x$enable_symvers = xdarwin-export ; then
2736     enable_symvers=darwin
2737 fi
2738
2739 # Check to see if 'gnu' can win.
2740 if test $enable_symvers = gnu || test $enable_symvers = gnu-versioned-namespace; then
2741   # Check to see if libgcc_s exists, indicating that shared libgcc is possible.
2742   AC_MSG_CHECKING([for shared libgcc])
2743   ac_save_CFLAGS="$CFLAGS"
2744   CFLAGS=' -lgcc_s'
2745   AC_TRY_LINK(, [return 0;], glibcxx_shared_libgcc=yes, glibcxx_shared_libgcc=no)
2746   CFLAGS="$ac_save_CFLAGS"
2747   if test $glibcxx_shared_libgcc = no; then
2748     cat > conftest.c <<EOF
2749 int main (void) { return 0; }
2750 EOF
2751 changequote(,)dnl
2752     glibcxx_libgcc_s_suffix=`${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS \
2753                              -shared -shared-libgcc -o conftest.so \
2754                              conftest.c -v 2>&1 >/dev/null \
2755                              | sed -n 's/^.* -lgcc_s\([^ ]*\) .*$/\1/p'`
2756 changequote([,])dnl
2757     rm -f conftest.c conftest.so
2758     if test x${glibcxx_libgcc_s_suffix+set} = xset; then
2759       CFLAGS=" -lgcc_s$glibcxx_libgcc_s_suffix"
2760       AC_TRY_LINK(, [return 0;], glibcxx_shared_libgcc=yes)
2761       CFLAGS="$ac_save_CFLAGS"
2762     fi
2763   fi
2764   AC_MSG_RESULT($glibcxx_shared_libgcc)
2765
2766   # For GNU ld, we need at least this version.  The format is described in
2767   # GLIBCXX_CHECK_LINKER_FEATURES above.
2768   glibcxx_min_gnu_ld_version=21400
2769
2770   # If no shared libgcc, can't win.
2771   if test $glibcxx_shared_libgcc != yes; then
2772       AC_MSG_WARN([=== You have requested GNU symbol versioning, but])
2773       AC_MSG_WARN([=== you are not building a shared libgcc_s.])
2774       AC_MSG_WARN([=== Symbol versioning will be disabled.])
2775       enable_symvers=no
2776   elif test $with_gnu_ld != yes ; then
2777     # just fail for now
2778     AC_MSG_WARN([=== You have requested GNU symbol versioning, but])
2779     AC_MSG_WARN([=== you are not using the GNU linker.])
2780     AC_MSG_WARN([=== Symbol versioning will be disabled.])
2781     enable_symvers=no
2782   elif test $glibcxx_ld_is_gold = yes ; then
2783     : All versions of gold support symbol versioning.
2784   elif test $glibcxx_gnu_ld_version -lt $glibcxx_min_gnu_ld_version ; then
2785     # The right tools, the right setup, but too old.  Fallbacks?
2786     AC_MSG_WARN(=== Linker version $glibcxx_gnu_ld_version is too old for)
2787     AC_MSG_WARN(=== full symbol versioning support in this release of GCC.)
2788     AC_MSG_WARN(=== You would need to upgrade your binutils to version)
2789     AC_MSG_WARN(=== $glibcxx_min_gnu_ld_version or later and rebuild GCC.)
2790     AC_MSG_WARN([=== Symbol versioning will be disabled.])
2791     enable_symvers=no
2792   fi
2793 fi
2794
2795 # Everything parsed; figure out what file to use.
2796 case $enable_symvers in
2797   no)
2798     SYMVER_FILE=config/abi/pre/none.ver
2799     ;;
2800   gnu)
2801     SYMVER_FILE=config/abi/pre/gnu.ver
2802     AC_DEFINE(_GLIBCXX_SYMVER_GNU, 1, 
2803               [Define to use GNU versioning in the shared library.])
2804     ;;
2805   gnu-versioned-namespace)
2806     SYMVER_FILE=config/abi/pre/gnu-versioned-namespace.ver
2807     AC_DEFINE(_GLIBCXX_SYMVER_GNU_NAMESPACE, 1, 
2808               [Define to use GNU namespace versioning in the shared library.])
2809     ;;
2810   darwin)
2811     SYMVER_FILE=config/abi/pre/gnu.ver
2812     AC_DEFINE(_GLIBCXX_SYMVER_DARWIN, 1, 
2813               [Define to use darwin versioning in the shared library.])
2814     ;;
2815 esac
2816
2817 if test x$enable_symvers != xno ; then
2818   AC_DEFINE(_GLIBCXX_SYMVER, 1,
2819          [Define to use symbol versioning in the shared library.])
2820 fi
2821
2822 AC_SUBST(SYMVER_FILE)
2823 AC_SUBST(port_specific_symbol_files)
2824 GLIBCXX_CONDITIONAL(ENABLE_SYMVERS, test $enable_symvers != no)
2825 GLIBCXX_CONDITIONAL(ENABLE_SYMVERS_GNU, test $enable_symvers = gnu)
2826 GLIBCXX_CONDITIONAL(ENABLE_SYMVERS_GNU_NAMESPACE, test $enable_symvers = gnu-versioned-namespace)
2827 GLIBCXX_CONDITIONAL(ENABLE_SYMVERS_DARWIN, test $enable_symvers = darwin)
2828 AC_MSG_NOTICE(versioning on shared library symbols is $enable_symvers)
2829
2830 # Now, set up compatibility support, if any.
2831 # In addition, need this to deal with std::size_t mangling in
2832 # src/compatibility.cc.  In a perfect world, could use
2833 # typeid(std::size_t).name()[0] to do direct substitution.
2834 AC_MSG_CHECKING([for size_t as unsigned int])
2835 ac_save_CFLAGS="$CFLAGS"
2836 CFLAGS="-Werror"
2837 AC_TRY_COMPILE(, [__SIZE_TYPE__* stp; unsigned int* uip; stp = uip;], 
2838                  [glibcxx_size_t_is_i=yes], [glibcxx_size_t_is_i=no])
2839 CFLAGS=$ac_save_CFLAGS
2840 if test "$glibcxx_size_t_is_i" = yes; then
2841   AC_DEFINE(_GLIBCXX_SIZE_T_IS_UINT, 1, [Define if size_t is unsigned int.])
2842 fi
2843 AC_MSG_RESULT([$glibcxx_size_t_is_i])
2844
2845 AC_MSG_CHECKING([for ptrdiff_t as int])
2846 ac_save_CFLAGS="$CFLAGS"
2847 CFLAGS="-Werror"
2848 AC_TRY_COMPILE(, [__PTRDIFF_TYPE__* ptp; int* ip; ptp = ip;], 
2849                  [glibcxx_ptrdiff_t_is_i=yes], [glibcxx_ptrdiff_t_is_i=no])
2850 CFLAGS=$ac_save_CFLAGS
2851 if test "$glibcxx_ptrdiff_t_is_i" = yes; then
2852   AC_DEFINE(_GLIBCXX_PTRDIFF_T_IS_INT, 1, [Define if ptrdiff_t is int.])
2853 fi
2854 AC_MSG_RESULT([$glibcxx_ptrdiff_t_is_i])
2855 ])
2856
2857
2858 dnl
2859 dnl Setup to use the gcc gthr.h thread-specific memory and mutex model.
2860 dnl We must stage the required headers so that they will be installed
2861 dnl with the library (unlike libgcc, the STL implementation is provided
2862 dnl solely within headers).  Since we must not inject random user-space
2863 dnl macro names into user-provided C++ code, we first stage into <file>-in
2864 dnl and process to <file> with an output command.  The reason for a two-
2865 dnl stage process here is to correctly handle $srcdir!=$objdir without
2866 dnl having to write complex code (the sed commands to clean the macro
2867 dnl namespace are complex and fragile enough as it is).  We must also
2868 dnl add a relative path so that -I- is supported properly.
2869 dnl
2870 dnl Substs:
2871 dnl  glibcxx_thread_h
2872 dnl
2873 dnl Defines:
2874 dnl  HAVE_GTHR_DEFAULT
2875 dnl
2876 AC_DEFUN([GLIBCXX_ENABLE_THREADS], [
2877   AC_MSG_CHECKING([for thread model used by GCC])
2878   target_thread_file=`$CXX -v 2>&1 | sed -n 's/^Thread model: //p'`
2879   AC_MSG_RESULT([$target_thread_file])
2880
2881   if test $target_thread_file != single; then
2882     AC_DEFINE(HAVE_GTHR_DEFAULT, 1,
2883               [Define if gthr-default.h exists 
2884               (meaning that threading support is enabled).])
2885   fi
2886
2887   glibcxx_thread_h=gthr-$target_thread_file.h
2888
2889   dnl Check for __GTHREADS define.
2890   gthread_file=${toplevel_srcdir}/gcc/${glibcxx_thread_h}
2891   if grep __GTHREADS $gthread_file >/dev/null 2>&1 ; then
2892     enable_thread=yes
2893   else
2894    enable_thread=no
2895   fi
2896
2897   AC_SUBST(glibcxx_thread_h)
2898 ])
2899
2900
2901 dnl
2902 dnl Check if gthread implementation defines the types and functions
2903 dnl required by the c++0x thread library.  Conforming gthread
2904 dnl implementations can define __GTHREADS_CXX0X to enable use with c++0x.
2905 dnl
2906 AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
2907   AC_LANG_SAVE
2908   AC_LANG_CPLUSPLUS
2909
2910   ac_save_CXXFLAGS="$CXXFLAGS"
2911   CXXFLAGS="$CXXFLAGS -fno-exceptions -I${toplevel_srcdir}/gcc"
2912
2913   target_thread_file=`$CXX -v 2>&1 | sed -n 's/^Thread model: //p'`
2914   case $target_thread_file in
2915     posix)
2916       CXXFLAGS="$CXXFLAGS -DSUPPORTS_WEAK -DGTHREAD_USE_WEAK -D_PTHREADS"
2917   esac
2918
2919   AC_MSG_CHECKING([for gthreads library])
2920
2921   AC_TRY_COMPILE([#include "gthr.h"],
2922     [
2923       #ifndef __GTHREADS_CXX0X
2924       #error
2925       #endif
2926
2927       // In case of POSIX threads check _POSIX_TIMEOUTS too.
2928       #if (defined(_PTHREADS) \
2929            && (!defined(_POSIX_TIMEOUTS) || _POSIX_TIMEOUTS <= 0))
2930       #error
2931       #endif
2932     ], [ac_has_gthreads=yes], [ac_has_gthreads=no])
2933
2934   AC_MSG_RESULT([$ac_has_gthreads])
2935
2936   if test x"$ac_has_gthreads" = x"yes"; then
2937     AC_DEFINE(_GLIBCXX_HAS_GTHREADS, 1,
2938               [Define if gthreads library is available.])
2939   fi
2940
2941   CXXFLAGS="$ac_save_CXXFLAGS"
2942   AC_LANG_RESTORE
2943 ])
2944
2945
2946 # Check whether LC_MESSAGES is available in <locale.h>.
2947 # Ulrich Drepper <drepper@cygnus.com>, 1995.
2948 #
2949 # This file file be copied and used freely without restrictions.  It can
2950 # be used in projects which are not available under the GNU Public License
2951 # but which still want to provide support for the GNU gettext functionality.
2952 # Please note that the actual code is *not* freely available.
2953 AC_DEFUN([AC_LC_MESSAGES], [
2954   AC_CHECK_HEADER(locale.h, [
2955     AC_CACHE_CHECK([for LC_MESSAGES], ac_cv_val_LC_MESSAGES,
2956       [AC_TRY_COMPILE([#include <locale.h>], [return LC_MESSAGES],
2957        ac_cv_val_LC_MESSAGES=yes, ac_cv_val_LC_MESSAGES=no)])
2958     if test $ac_cv_val_LC_MESSAGES = yes; then
2959       AC_DEFINE(HAVE_LC_MESSAGES, 1, 
2960                 [Define if LC_MESSAGES is available in <locale.h>.])
2961     fi
2962   ])
2963 ])
2964
2965 # Macros from the top-level gcc directory.
2966 m4_include([../config/tls.m4])
2967