1 dnl Helper Functions for the RRDtool configure.ac script
3 dnl this file gets included into aclocal.m4 when runnning aclocal
7 dnl Check for the presence of a particular library and its header files
8 dnl if this check fails set the environment variable EX_CHECK_ALL_ERR to YES
9 dnl and prints out a helful message
12 dnl EX_CHECK_ALL(library, function, header, pkgconf name, tested-version, homepage)
16 AC_DEFUN([EX_CHECK_ALL],
20 ex_check_save_LIBS=${LIBS}
21 ex_check_save_CPPFLAGS=${CPPFLAGS}
22 ex_check_save_LDFLAGS=${LDPFLAGS}
23 dnl try compiling naked first
25 AC_CHECK_HEADER($3,[LIBS="-l$1 ${LIBS}";EX_CHECK_STATE=YES],[])],[])
26 if test $EX_CHECK_STATE = NO; then
27 dnl now asking pkg-config for help
28 AC_CHECK_PROGS(PKGCONFIG,[pkg-config],no)
29 if test "$PKGCONFIG" != "no"; then
30 if $PKGCONFIG --exists $4; then
31 CPPFLAGS=${CPPFLAGS}" "`$PKGCONFIG --cflags $4`
32 LDFLAGS=${LDFLAGS}" "`$PKGCONFIG --libs-only-L $4`
33 LDFLAGS=${LDFLAGS}" "`$PKGCONFIG --libs-only-other $4`
34 LIBS=${LIBS}" "`$PKGCONFIG --libs-only-l $4`
35 dnl remove the cached value and test again
37 AC_CHECK_LIB($1,$2,[ AC_CHECK_HEADER($3,[EX_CHECK_STATE=YES],[])],[])
40 ----------------------------------------------------------------------------
41 * I found a copy of pkgconfig, but there is no $4.pc file around.
42 You may want to set the PKG_CONFIG_PATH variable to point to its
44 ----------------------------------------------------------------------------
50 if test ${EX_CHECK_STATE} = NO; then
52 ----------------------------------------------------------------------------
53 * I could not find a working copy of $4. Check config.log for hints on why
54 this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
55 so that compiler and the linker can find lib$1 and its header files. If
56 you have not installed $4, you can get it either from its original home on
60 You can find also find an archive copy on
62 http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/pub/libs
64 The last tested version of $4 is $5.
70 ----------------------------------------------------------------------------
73 LIBS="${ex_check_save_LIBS}"
74 CPPFLAGS="${ex_check_save_CPPFLAGS}"
75 LDFLAGS="${ex_check_save_LDFLAGS}"
81 dnl Ptherad check from http://autoconf-archive.cryp.to/acx_pthread.m4
83 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
85 dnl This macro figures out how to build C programs using POSIX threads.
86 dnl It sets the PTHREAD_LIBS output variable to the threads library and
87 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
88 dnl C compiler flags that are needed. (The user can also force certain
89 dnl compiler flags/libs to be tested by setting these environment
92 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
93 dnl multi-threaded programs (defaults to the value of CC otherwise).
94 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
96 dnl NOTE: You are assumed to not only compile your program with these
97 dnl flags, but also link it with them as well. e.g. you should link
98 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
101 dnl If you are only building threads programs, you may wish to use
102 dnl these variables in your default LIBS, CFLAGS, and CC:
104 dnl LIBS="$PTHREAD_LIBS $LIBS"
105 dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
108 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
109 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
110 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
112 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
113 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
114 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
115 dnl default action will define HAVE_PTHREAD.
117 dnl Please let the authors know if this macro fails on any platform, or
118 dnl if you have any other suggestions or comments. This macro was based
119 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
120 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
121 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
122 dnl We are also grateful for the helpful feedback of numerous users.
124 dnl @category InstalledPackages
125 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
126 dnl @version 2005-01-14
127 dnl @license GPLWithACException
129 AC_DEFUN([ACX_PTHREAD], [
130 AC_REQUIRE([AC_CANONICAL_HOST])
134 # We used to check for pthread.h first, but this fails if pthread.h
135 # requires special compiler flags (e.g. on True64 or Sequent).
136 # It gets checked for in the link test anyway.
138 # First of all, check if the user has set any of the PTHREAD_LIBS,
139 # etcetera environment variables, and if threads linking works using
141 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
142 save_CFLAGS="$CFLAGS"
143 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
145 LIBS="$PTHREAD_LIBS $LIBS"
146 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
147 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
148 AC_MSG_RESULT($acx_pthread_ok)
149 if test x"$acx_pthread_ok" = xno; then
154 CFLAGS="$save_CFLAGS"
157 # We must check for the threads library under a number of different
158 # names; the ordering is very important because some systems
159 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
160 # libraries is broken (non-POSIX).
162 # Create a list of thread flags to try. Items starting with a "-" are
163 # C compiler flags, and other items are library names, except for "none"
164 # which indicates that we try without any flags at all, and "pthread-config"
165 # which is a program returning the flags for the Pth emulation library.
167 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
169 # The ordering *is* (sometimes) important. Some notes on the
170 # individual items follow:
172 # pthreads: AIX (must check this before -lpthread)
173 # none: in case threads are in libc; should be tried before -Kthread and
174 # other compiler flags to prevent continual compiler warnings
175 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
176 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
177 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
178 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
179 # -pthreads: Solaris/gcc
180 # -mthreads: Mingw32/gcc, Lynx/gcc
181 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
182 # doesn't hurt to check since this sometimes defines pthreads too;
183 # also defines -D_REENTRANT)
184 # pthread: Linux, etcetera
185 # --thread-safe: KAI C++
186 # pthread-config: use pthread-config program (for GNU Pth library)
188 case "${host_cpu}-${host_os}" in
191 # On Solaris (at least, for some versions), libc contains stubbed
192 # (non-functional) versions of the pthreads routines, so link-based
193 # tests will erroneously succeed. (We need to link with -pthread or
194 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
195 # a function called by this macro, so we could check for that, but
196 # who knows whether they'll stub that too in a future libc.) So,
197 # we'll just look for -pthreads and -lpthread first:
199 acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags"
203 if test x"$acx_pthread_ok" = xno; then
204 for flag in $acx_pthread_flags; do
208 AC_MSG_CHECKING([whether pthreads work without any flags])
212 AC_MSG_CHECKING([whether pthreads work with $flag])
213 PTHREAD_CFLAGS="$flag"
217 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
218 if test x"$acx_pthread_config" = xno; then continue; fi
219 PTHREAD_CFLAGS="`pthread-config --cflags`"
220 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
224 AC_MSG_CHECKING([for the pthreads library -l$flag])
225 PTHREAD_LIBS="-l$flag"
230 save_CFLAGS="$CFLAGS"
231 LIBS="$PTHREAD_LIBS $LIBS"
232 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
234 # Check for various functions. We must include pthread.h,
235 # since some functions may be macros. (On the Sequent, we
236 # need a special flag -Kthread to make this header compile.)
237 # We check for pthread_join because it is in -lpthread on IRIX
238 # while pthread_create is in libc. We check for pthread_attr_init
239 # due to DEC craziness with -lpthreads. We check for
240 # pthread_cleanup_push because it is one of the few pthread
241 # functions on Solaris that doesn't have a non-functional libc stub.
242 # We try pthread_create on general principles.
243 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]], [[pthread_t th; pthread_join(th, 0);
244 pthread_attr_init(0); pthread_cleanup_push(0, 0);
245 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ]])],[acx_pthread_ok=yes],[])
248 CFLAGS="$save_CFLAGS"
250 AC_MSG_RESULT($acx_pthread_ok)
251 if test "x$acx_pthread_ok" = xyes; then
260 # Various other checks:
261 if test "x$acx_pthread_ok" = xyes; then
263 LIBS="$PTHREAD_LIBS $LIBS"
264 save_CFLAGS="$CFLAGS"
265 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
267 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
268 AC_MSG_CHECKING([for joinable pthread attribute])
270 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
271 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]], [[int attr=$attr;]])],[attr_name=$attr; break],[])
273 AC_MSG_RESULT($attr_name)
274 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
275 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
276 [Define to necessary symbol if this constant
277 uses a non-standard name on your system.])
280 AC_MSG_CHECKING([if more special flags are required for pthreads])
282 case "${host_cpu}-${host_os}" in
283 *-aix* | *-freebsd* | *-darwin*) x_rflag="-D_THREAD_SAFE";;
284 *solaris* | *-osf* | *-hpux*) x_rflag="-D_REENTRANT";;
286 AC_MSG_RESULT(${x_rflag})
287 if test "x$x_rflag" != xno; then
288 PTHREAD_CFLAGS="$x_rflag $PTHREAD_CFLAGS"
292 CFLAGS="$save_CFLAGS"
294 # More AIX lossage: must compile with cc_r
295 AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})
300 AC_SUBST(PTHREAD_LIBS)
301 AC_SUBST(PTHREAD_CFLAGS)
304 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
305 if test x"$acx_pthread_ok" = xyes; then
306 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
317 dnl determine how to get IEEE math working
318 dnl AC_IEEE(MESSAGE, set rd_cv_ieee_[var] variable, INCLUDES,
319 dnl FUNCTION-BODY, [ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]])
322 dnl substitute them in all the files listed in AC_OUTPUT
325 AC_DEFUN([AC_IEEE], [
326 AC_MSG_CHECKING([if IEEE math works $1])
327 AC_CACHE_VAL([rd_cv_ieee_$2],
328 [AC_RUN_IFELSE([AC_LANG_SOURCE([[$3
343 # include <fp_class.h>
347 #if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASS))
348 # define HAVE_ISINF 1
349 # define isinf(a) (fpclass(a) == FP_NINF || fpclass(a) == FP_PINF)
353 #if (! defined(HAVE_ISINF) && defined(HAVE_FP_CLASS) && defined(HAVE_FP_CLASS_H))
354 # define HAVE_ISINF 1
355 # define isinf(a) (fp_class(a) == FP_NEG_INF || fp_class(a) == FP_POS_INF)
359 #if (! defined(HAVE_ISINF) && defined(HAVE_CLASS))
360 # define HAVE_ISINF 1
361 # define isinf(a) (class(a) == FP_MINUS_INF || class(a) == FP_PLUS_INF)
364 #if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASSIFY) && defined(FP_PLUS_INF) && defined(FP_MINUS_INF))
365 # define HAVE_ISINF 1
366 # define isinf(a) (fpclassify(a) == FP_MINUS_INF || fpclassify(a) == FP_PLUS_INF)
369 #if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASSIFY) && defined(FP_INFINITE))
370 # define HAVE_ISINF 1
371 # define isinf(a) (fpclassify(a) == FP_INFINITE)
376 double nan,inf,c,zero;
378 /* some math to see if we get a floating point exception */
379 zero=sin(0.0); /* don't let the compiler optimize us away */
380 nan=0.0/zero; /* especially here */
381 inf=1.0/zero; /* and here. I want to know if it can do the magic */
382 /* at run time without sig fpe */
385 if (! isnan(nan)) {printf ("not isnan(NaN) ... "); return 1;}
386 if (nan == nan) {printf ("nan == nan ... "); return 1;}
387 if (! isinf(inf)) {printf ("not isinf(oo) ... "); return 1;}
388 if (! isinf(-inf)) {printf ("not isinf(-oo) ... "); return 1;}
389 if (! inf > 0) {printf ("not inf > 0 ... "); return 1;}
390 if (! -inf < 0) {printf ("not -inf < 0 ... "); return 1;}
392 }]])],[rd_cv_ieee_$2=yes],[rd_cv_ieee_$2=no],[:])])
393 dnl these we run regardles is cached or not
394 if test x${rd_cv_ieee_$2} = "xyes"; then
404 AC_DEFUN([AC_FULL_IEEE],[
407 AC_IEEE([out of the box], works, , , ,
408 [CFLAGS="$_cflags -ieee"
409 AC_IEEE([with the -ieee switch], switch, , , ,
410 [CFLAGS="$_cflags -qfloat=nofold"
411 AC_IEEE([with the -qfloat=nofold switch], nofold, , , ,
412 [CFLAGS="$_cflags -w -qflttrap=enable:zerodivide"
413 AC_IEEE([with the -w -qflttrap=enable:zerodivide], flttrap, , , ,
414 [CFLAGS="$_cflags -mieee"
415 AC_IEEE([with the -mieee switch], mswitch, , , ,
416 [CFLAGS="$_cflags -q float=rndsngl"
417 AC_IEEE([with the -q float=rndsngl switch], qswitch, , , ,
418 [CFLAGS="$_cflags -OPT:IEEE_NaN_inf=ON"
419 AC_IEEE([with the -OPT:IEEE_NaN_inf=ON switch], ieeenaninfswitch, , , ,
420 [CFLAGS="$_cflags -OPT:IEEE_comparisons=ON"
421 AC_IEEE([with the -OPT:IEEE_comparisons=ON switch], ieeecmpswitch, , , ,
423 AC_IEEE([with fpsetmask(0)], mask,
424 [#include <floatingpoint.h>], [fpsetmask(0)],
425 [AC_DEFINE(MUST_DISABLE_FPMASK)
426 PERLFLAGS="CCFLAGS=-DMUST_DISABLE_FPMASK"],
427 [AC_IEEE([with signal(SIGFPE,SIG_IGN)], sigfpe,
428 [#include <signal.h>], [signal(SIGFPE,SIG_IGN)],
429 [AC_DEFINE(MUST_DISABLE_SIGFPE)
430 PERLFLAGS="CCFLAGS=-DMUST_DISABLE_SIGFPE"],
432 Your Compiler does not do propper IEEE math ... Please find out how to
433 make IEEE math work with your compiler and let me know (oetiker@ee.ethz.ch).
434 Check config.log to see what went wrong ...
435 ]))])])])])])])])])])