1dnl
2dnl This file contains macros for testing linkage.
3dnl
4
5dnl
6dnl Check to see if the (math function) argument passed is
7dnl declared when using the c++ compiler
8dnl ASSUMES argument is a math function with ONE parameter
9dnl
10dnl GLIBCXX_CHECK_MATH_DECL_1
11AC_DEFUN([GLIBCXX_CHECK_MATH_DECL_1], [
12  AC_MSG_CHECKING([for $1 declaration])
13  if test x${glibcxx_cv_func_$1_use+set} != xset; then
14    AC_CACHE_VAL(glibcxx_cv_func_$1_use, [
15      AC_LANG_SAVE
16      AC_LANG_CPLUSPLUS
17      AC_TRY_COMPILE([#include <math.h>
18		      #ifdef HAVE_IEEEFP_H
19		      #include <ieeefp.h>
20		      #endif
21		     ],
22                     [ $1(0);],
23                      [glibcxx_cv_func_$1_use=yes], [glibcxx_cv_func_$1_use=no])
24      AC_LANG_RESTORE
25    ])
26  fi
27  AC_MSG_RESULT($glibcxx_cv_func_$1_use)
28])
29
30
31dnl
32dnl Define autoheader template for using the underscore functions
33dnl For each parameter, create a macro where if func doesn't exist,
34dnl but _func does, then it will "#define func _func".
35dnl
36dnl GLIBCXX_MAYBE_UNDERSCORED_FUNCS
37AC_DEFUN([GLIBCXX_MAYBE_UNDERSCORED_FUNCS],
38[AC_FOREACH([glibcxx_ufunc], [$1],
39  [AH_VERBATIM(_[]glibcxx_ufunc,
40[#if defined (]AS_TR_CPP(HAVE__[]glibcxx_ufunc)[) && ! defined (]AS_TR_CPP(HAVE_[]glibcxx_ufunc)[)
41# define ]AS_TR_CPP(HAVE_[]glibcxx_ufunc)[ 1
42# define ]glibcxx_ufunc[ _]glibcxx_ufunc[
43#endif])])
44])
45
46
47dnl
48dnl Check to see if the (math function) argument passed is
49dnl 1) declared when using the c++ compiler
50dnl 2) has "C" linkage
51dnl 3) if not, see if 1) and 2) for argument prepended with '_'
52dnl
53dnl Define HAVE_CARGF etc if "cargf" is declared and links
54dnl
55dnl argument 1 is name of function to check
56dnl
57dnl ASSUMES argument is a math function with ONE parameter
58dnl
59dnl GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1
60AC_DEFUN([GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1], [
61  GLIBCXX_CHECK_MATH_DECL_1($1)
62  if test x$glibcxx_cv_func_$1_use = x"yes"; then
63    AC_CHECK_FUNCS($1)
64  else
65    GLIBCXX_CHECK_MATH_DECL_1(_$1)
66    if test x$glibcxx_cv_func__$1_use = x"yes"; then
67      AC_CHECK_FUNCS(_$1)
68    fi
69  fi
70  GLIBCXX_MAYBE_UNDERSCORED_FUNCS($1)
71])
72
73
74dnl
75dnl Like GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1, but does a bunch of
76dnl of functions at once.  It's an all-or-nothing check -- either
77dnl HAVE_XYZ is defined for each of the functions, or for none of them.
78dnl Doing it this way saves significant configure time.
79AC_DEFUN([GLIBCXX_CHECK_MATH_DECLS_AND_LINKAGES_1], [
80  define([funclist],patsubst($3,\(\w+\)\(\W*\),\1 ))dnl
81  AC_MSG_CHECKING([for $1 functions])
82  AC_CACHE_VAL(glibcxx_cv_func_$2_use, [
83    AC_LANG_SAVE
84    AC_LANG_CPLUSPLUS
85    AC_TRY_COMPILE([#include <math.h>],
86                   patsubst(funclist,[\w+],[\& (0);]),
87                   [glibcxx_cv_func_$2_use=yes],
88                   [glibcxx_cv_func_$2_use=no])
89    AC_LANG_RESTORE])
90  AC_MSG_RESULT($glibcxx_cv_func_$2_use)
91  if test x$glibcxx_cv_func_$2_use = x"yes"; then
92    AC_CHECK_FUNCS(funclist)
93  else
94    AC_MSG_CHECKING([for _$1 functions])
95    AC_CACHE_VAL(glibcxx_cv_func__$2_use, [
96      AC_LANG_SAVE
97      AC_LANG_CPLUSPLUS
98      AC_TRY_COMPILE([#include <math.h>],
99                     patsubst(funclist,[\w+],[_\& (0);]),
100                     [glibcxx_cv_func__$2_use=yes],
101                     [glibcxx_cv_func__$2_use=no])
102      AC_LANG_RESTORE])
103    AC_MSG_RESULT($glibcxx_cv_func__$2_use)
104    if test x$glibcxx_cv_func__$2_use = x"yes"; then
105      AC_CHECK_FUNCS(patsubst(funclist,[\w+],[_\&]))
106    fi
107  fi
108  GLIBCXX_MAYBE_UNDERSCORED_FUNCS(funclist)
109  undefine([funclist])
110])
111
112dnl
113dnl Check to see if the (math function) argument passed is
114dnl declared when using the c++ compiler
115dnl ASSUMES argument is a math function with TWO parameters
116dnl
117dnl GLIBCXX_CHECK_MATH_DECL_2
118AC_DEFUN([GLIBCXX_CHECK_MATH_DECL_2], [
119  AC_MSG_CHECKING([for $1 declaration])
120  if test x${glibcxx_cv_func_$1_use+set} != xset; then
121    AC_CACHE_VAL(glibcxx_cv_func_$1_use, [
122      AC_LANG_SAVE
123      AC_LANG_CPLUSPLUS
124      AC_TRY_COMPILE([#include <math.h>],
125                     [ $1(0, 0);],
126                     [glibcxx_cv_func_$1_use=yes], [glibcxx_cv_func_$1_use=no])
127      AC_LANG_RESTORE
128    ])
129  fi
130  AC_MSG_RESULT($glibcxx_cv_func_$1_use)
131])
132
133dnl
134dnl Check to see if the (math function) argument passed is
135dnl 1) declared when using the c++ compiler
136dnl 2) has "C" linkage
137dnl
138dnl Define HAVE_CARGF etc if "cargf" is declared and links
139dnl
140dnl argument 1 is name of function to check
141dnl
142dnl ASSUMES argument is a math function with TWO parameters
143dnl
144dnl GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2
145AC_DEFUN([GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2], [
146  GLIBCXX_CHECK_MATH_DECL_2($1)
147  if test x$glibcxx_cv_func_$1_use = x"yes"; then
148    AC_CHECK_FUNCS($1)
149  else
150    GLIBCXX_CHECK_MATH_DECL_2(_$1)
151    if test x$glibcxx_cv_func__$1_use = x"yes"; then
152      AC_CHECK_FUNCS(_$1)
153    fi
154  fi
155  GLIBCXX_MAYBE_UNDERSCORED_FUNCS($1)
156])
157
158
159dnl
160dnl Check to see if the (math function) argument passed is
161dnl declared when using the c++ compiler
162dnl ASSUMES argument is a math function with THREE parameters
163dnl
164dnl GLIBCXX_CHECK_MATH_DECL_3
165AC_DEFUN([GLIBCXX_CHECK_MATH_DECL_3], [
166  AC_MSG_CHECKING([for $1 declaration])
167  if test x${glibcxx_cv_func_$1_use+set} != xset; then
168    AC_CACHE_VAL(glibcxx_cv_func_$1_use, [
169      AC_LANG_SAVE
170      AC_LANG_CPLUSPLUS
171      AC_TRY_COMPILE([#include <math.h>],
172                     [ $1(0, 0, 0);],
173                     [glibcxx_cv_func_$1_use=yes], [glibcxx_cv_func_$1_use=no])
174      AC_LANG_RESTORE
175    ])
176  fi
177  AC_MSG_RESULT($glibcxx_cv_func_$1_use)
178])
179
180dnl
181dnl Check to see if the (math function) argument passed is
182dnl 1) declared when using the c++ compiler
183dnl 2) has "C" linkage
184dnl
185dnl Define HAVE_CARGF etc if "cargf" is declared and links
186dnl
187dnl argument 1 is name of function to check
188dnl
189dnl ASSUMES argument is a math function with THREE parameters
190dnl
191dnl GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_3
192AC_DEFUN([GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_3], [
193  GLIBCXX_CHECK_MATH_DECL_3($1)
194  if test x$glibcxx_cv_func_$1_use = x"yes"; then
195    AC_CHECK_FUNCS($1)
196  else
197    GLIBCXX_CHECK_MATH_DECL_3(_$1)
198    if test x$glibcxx_cv_func__$1_use = x"yes"; then
199      AC_CHECK_FUNCS(_$1)
200    fi
201  fi
202  GLIBCXX_MAYBE_UNDERSCORED_FUNCS($1)
203])
204
205
206dnl
207dnl Check to see if the (stdlib function) argument passed is
208dnl 1) declared when using the c++ compiler
209dnl 2) has "C" linkage
210dnl
211dnl argument 1 is name of function to check
212dnl
213dnl ASSUMES argument is a stdlib function without parameters
214dnl
215dnl GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_0
216AC_DEFUN([GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_0], [
217  AC_MSG_CHECKING([for $1 declaration])
218  if test x${glibcxx_cv_func_$1_use+set} != xset; then
219    AC_CACHE_VAL(glibcxx_cv_func_$1_use, [
220      AC_LANG_SAVE
221      AC_LANG_CPLUSPLUS
222      AC_TRY_COMPILE([#include <stdlib.h>],
223                     [ $1();],
224                     [glibcxx_cv_func_$1_use=yes], [glibcxx_cv_func_$1_use=no])
225      AC_LANG_RESTORE
226    ])
227  fi
228  AC_MSG_RESULT($glibcxx_cv_func_$1_use)
229  if test x$glibcxx_cv_func_$1_use = x"yes"; then
230    AC_CHECK_FUNCS($1)
231  fi
232])
233
234
235dnl
236dnl Check to see if the (stdlib function) argument passed is
237dnl 1) declared when using the c++ compiler
238dnl 2) has "C" linkage
239dnl
240dnl argument 1 is name of function to check
241dnl
242dnl ASSUMES argument is a stdlib function with ONE parameter
243dnl
244dnl GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_1
245AC_DEFUN([GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_1], [
246  AC_MSG_CHECKING([for $1 declaration])
247  if test x${glibcxx_cv_func_$1_use+set} != xset; then
248    AC_CACHE_VAL(glibcxx_cv_func_$1_use, [
249      AC_LANG_SAVE
250      AC_LANG_CPLUSPLUS
251      AC_TRY_COMPILE([#include <stdlib.h>],
252                     [ $1(0);],
253                     [glibcxx_cv_func_$1_use=yes], [glibcxx_cv_func_$1_use=no])
254      AC_LANG_RESTORE
255    ])
256  fi
257  AC_MSG_RESULT($glibcxx_cv_func_$1_use)
258  if test x$glibcxx_cv_func_$1_use = x"yes"; then
259    AC_CHECK_FUNCS($1)
260  fi
261])
262
263
264dnl
265dnl Check to see if the (stdlib function) argument passed is
266dnl 1) declared when using the c++ compiler
267dnl 2) has "C" linkage
268dnl
269dnl argument 1 is name of function to check
270dnl
271dnl ASSUMES argument is a stdlib function with TWO parameters
272dnl
273dnl GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_2
274AC_DEFUN([GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_2], [
275  AC_MSG_CHECKING([for $1 declaration])
276  if test x${glibcxx_cv_func_$1_use+set} != xset; then
277    AC_CACHE_VAL(glibcxx_cv_func_$1_use, [
278      AC_LANG_SAVE
279      AC_LANG_CPLUSPLUS
280      AC_TRY_COMPILE([#include <stdlib.h>],
281                     [ $1(0, 0);],
282                     [glibcxx_cv_func_$1_use=yes], [glibcxx_cv_func_$1_use=no])
283      AC_LANG_RESTORE
284    ])
285  fi
286  AC_MSG_RESULT($glibcxx_cv_func_$1_use)
287  if test x$glibcxx_cv_func_$1_use = x"yes"; then
288    AC_CHECK_FUNCS($1)
289  fi
290  GLIBCXX_MAYBE_UNDERSCORED_FUNCS($1)
291])
292
293
294dnl
295dnl Check to see if the (stdlib function) argument passed is
296dnl 1) declared when using the c++ compiler
297dnl 2) has "C" linkage
298dnl
299dnl argument 1 is name of function to check
300dnl
301dnl ASSUMES argument is a stdlib function with THREE parameters
302dnl
303dnl GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_3
304AC_DEFUN([GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_3], [
305  AC_MSG_CHECKING([for $1 declaration])
306  if test x${glibcxx_cv_func_$1_use+set} != xset; then
307    AC_CACHE_VAL(glibcxx_cv_func_$1_use, [
308      AC_LANG_SAVE
309      AC_LANG_CPLUSPLUS
310      AC_TRY_COMPILE([#include <stdlib.h>],
311                     [ $1(0, 0, 0);],
312                     [glibcxx_cv_func_$1_use=yes], [glibcxx_cv_func_$1_use=no])
313      AC_LANG_RESTORE
314    ])
315  fi
316  AC_MSG_RESULT($glibcxx_cv_func_$1_use)
317  if test x$glibcxx_cv_func_$1_use = x"yes"; then
318    AC_CHECK_FUNCS($1)
319  fi
320])
321
322dnl
323dnl Check to see what the underlying c library is like
324dnl These checks need to do two things:
325dnl 1) make sure the name is declared when using the c++ compiler
326dnl 2) make sure the name has "C" linkage
327dnl This might seem like overkill but experience has shown that it's not...
328dnl
329dnl Define HAVE_STRTOLD if "strtold" is declared and links
330dnl Define HAVE_STRTOF if "strtof" is declared and links
331dnl
332dnl GLIBCXX_CHECK_STDLIB_SUPPORT
333AC_DEFUN([GLIBCXX_CHECK_STDLIB_SUPPORT], [
334  ac_test_CXXFLAGS="${CXXFLAGS+set}"
335  ac_save_CXXFLAGS="$CXXFLAGS"
336  CXXFLAGS='-fno-builtin -D_GNU_SOURCE'
337
338  GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_1(at_quick_exit)
339  GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_1(quick_exit)
340  GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_2(strtold)
341  GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_2(strtof)
342
343  CXXFLAGS="$ac_save_CXXFLAGS"
344])
345
346dnl
347dnl Check to see what the underlying c library or math library is like.
348dnl These checks need to do two things:
349dnl 1) make sure the name is declared when using the c++ compiler
350dnl 2) make sure the name has "C" linkage
351dnl This might seem like overkill but experience has shown that it's not...
352dnl
353dnl Define HAVE_CARGF etc if "cargf" is found.
354dnl
355dnl GLIBCXX_CHECK_MATH_SUPPORT
356AC_DEFUN([GLIBCXX_CHECK_MATH_SUPPORT], [
357  ac_test_CXXFLAGS="${CXXFLAGS+set}"
358  ac_save_CXXFLAGS="$CXXFLAGS"
359  CXXFLAGS='-fno-builtin -D_GNU_SOURCE'
360
361  dnl Check libm
362  AC_CHECK_LIB(m, sin, libm="-lm")
363  ac_save_LIBS="$LIBS"
364  LIBS="$LIBS $libm"
365
366  dnl Check to see if certain C math functions exist.
367  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(isinf)
368  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(isnan)
369  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(finite)
370  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_3(sincos)
371  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(fpclass)
372  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(qfpclass)
373  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(hypot)
374
375  dnl Check to see if basic C math functions have float versions.
376  GLIBCXX_CHECK_MATH_DECLS_AND_LINKAGES_1(float trig,
377                                          float_trig,
378                                          acosf asinf atanf \
379                                          cosf sinf tanf \
380                                          coshf sinhf tanhf)
381  GLIBCXX_CHECK_MATH_DECLS_AND_LINKAGES_1(float round,
382                                          float_round,
383                                          ceilf floorf)
384  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(expf)
385  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(isnanf)
386  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(isinff)
387  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(atan2f)
388  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(fabsf)
389  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(fmodf)
390  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(frexpf)
391  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(hypotf)
392  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(ldexpf)
393  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(logf)
394  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(log10f)
395  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(modff)
396  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(modf)
397  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(powf)
398  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(sqrtf)
399  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_3(sincosf)
400  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(finitef)
401
402  dnl Check to see if basic C math functions have long double versions.
403  GLIBCXX_CHECK_MATH_DECLS_AND_LINKAGES_1(long double trig,
404                                          long_double_trig,
405                                          acosl asinl atanl \
406                                          cosl sinl tanl \
407                                          coshl sinhl tanhl)
408  GLIBCXX_CHECK_MATH_DECLS_AND_LINKAGES_1(long double round,
409                                          long_double_round,
410                                          ceill floorl)
411  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(isnanl)
412  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(isinfl)
413  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(atan2l)
414  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(expl)
415  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(fabsl)
416  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(fmodl)
417  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(frexpl)
418  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(hypotl)
419  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(ldexpl)
420  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(logl)
421  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(log10l)
422  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(modfl)
423  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2(powl)
424  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(sqrtl)
425  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_3(sincosl)
426  GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1(finitel)
427
428  LIBS="$ac_save_LIBS"
429  CXXFLAGS="$ac_save_CXXFLAGS"
430])
431