die on error! -- Alex
[rrdtool.git] / acinclude.m4
index 329501d..8228d39 100644 (file)
@@ -9,8 +9,8 @@ dnl if this check fails set the environment variable EX_CHECK_ALL_ERR to YES
 dnl and prints out a helful message
 dnl
 dnl
-dnl EX_CHECK_ALL(library, function, header, pkgconf name, tested-version, homepage)
-dnl              $1       $2        $3      $4            $5              $6
+dnl EX_CHECK_ALL(library, function, header, pkgconf name, tested-version, homepage, cppflags)
+dnl              $1       $2        $3      $4            $5              $6        $7
 dnl
 dnl
 AC_DEFUN([EX_CHECK_ALL],
@@ -19,7 +19,10 @@ AC_DEFUN([EX_CHECK_ALL],
  EX_CHECK_STATE=NO
  ex_check_save_LIBS=${LIBS}
  ex_check_save_CPPFLAGS=${CPPFLAGS}
- ex_check_save_LDFLAGS=${LDPFLAGS}
+ ex_check_save_LDFLAGS=${LDFLAGS}
+ if test "x$7" != "x"; then
+   CPPFLAGS="$CPPFLAGS -I$7"
+ fi
  dnl try compiling naked first
  AC_CHECK_LIB($1,$2, [
     AC_CHECK_HEADER($3,[LIBS="-l$1 ${LIBS}";EX_CHECK_STATE=YES],[])],[])
@@ -34,7 +37,10 @@ AC_DEFUN([EX_CHECK_ALL],
              LIBS=${LIBS}" "`$PKGCONFIG --libs-only-l $4`
             dnl remove the cached value and test again
             unset ac_cv_lib_$1_$2
-             AC_CHECK_LIB($1,$2,[ AC_CHECK_HEADER($3,[EX_CHECK_STATE=YES],[])],[])
+             AC_CHECK_LIB($1,$2,[
+                unset ac_cv_header_`echo $3 | sed ['s/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/']`
+                AC_CHECK_HEADER($3,[EX_CHECK_STATE=YES],[])
+            ],[])
           else
              AC_MSG_WARN([
 ----------------------------------------------------------------------------
@@ -77,6 +83,7 @@ AC_DEFUN([EX_CHECK_ALL],
     AC_LANG_POP(C)
 ]
 )
+
 dnl
 dnl  Ptherad check from http://autoconf-archive.cryp.to/acx_pthread.m4
 dnl
@@ -240,11 +247,9 @@ for flag in $acx_pthread_flags; do
         # pthread_cleanup_push because it is one of the few pthread
         # functions on Solaris that doesn't have a non-functional libc stub.
         # We try pthread_create on general principles.
-        AC_TRY_LINK([#include <pthread.h>],
-                    [pthread_t th; pthread_join(th, 0);
+        AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]], [[pthread_t th; pthread_join(th, 0);
                      pthread_attr_init(0); pthread_cleanup_push(0, 0);
-                     pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
-                    [acx_pthread_ok=yes])
+                     pthread_create(0,0,0,0); pthread_cleanup_pop(0); ]])],[acx_pthread_ok=yes],[])
 
         LIBS="$save_LIBS"
         CFLAGS="$save_CFLAGS"
@@ -270,8 +275,7 @@ if test "x$acx_pthread_ok" = xyes; then
        AC_MSG_CHECKING([for joinable pthread attribute])
        attr_name=unknown
        for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
-           AC_TRY_LINK([#include <pthread.h>], [int attr=$attr;],
-                        [attr_name=$attr; break])
+           AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]], [[int attr=$attr;]])],[attr_name=$attr; break],[])
        done
         AC_MSG_RESULT($attr_name)
         if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
@@ -281,14 +285,20 @@ if test "x$acx_pthread_ok" = xyes; then
         fi
 
         AC_MSG_CHECKING([if more special flags are required for pthreads])
-        flag=no
+        x_rflag=no
         case "${host_cpu}-${host_os}" in
-            *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
-            *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
+            *-aix* | *-freebsd* | *-darwin*) x_rflag="-D_THREAD_SAFE";;
+            *solaris* | *-osf* | *-hpux*) x_rflag="-D_REENTRANT";;
+            *-linux*)
+            if test x"$PTHREAD_CFLAGS" = "x-pthread"; then
+                # For Linux/gcc "-pthread" implies "-lpthread". We need, however, to make this explicit
+                # in PTHREAD_LIBS such that a shared library to be built properly depends on libpthread.
+                PTHREAD_LIBS="-lpthread $PTHREAD_LIBS"
+            fi;;
         esac
-        AC_MSG_RESULT(${flag})
-        if test "x$flag" != xno; then
-            PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
+        AC_MSG_RESULT(${x_rflag})
+        if test "x$x_rflag" != xno; then
+            PTHREAD_CFLAGS="$x_rflag $PTHREAD_CFLAGS"
         fi
 
         LIBS="$save_LIBS"
@@ -322,6 +332,9 @@ dnl AC_IEEE(MESSAGE, set rd_cv_ieee_[var] variable, INCLUDES,
 dnl   FUNCTION-BODY, [ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]])
 dnl
 
+dnl substitute them in all the files listed in AC_OUTPUT
+AC_SUBST(PERLFLAGS)
+
 AC_DEFUN([AC_IEEE], [
 AC_MSG_CHECKING([if IEEE math works $1])
 AC_CACHE_VAL([rd_cv_ieee_$2],
@@ -437,3 +450,31 @@ Check config.log to see what went wrong ...
 AC_LANG_POP(C)
 
 ])
+
+
+dnl a macro to check for ability to create python extensions
+dnl  AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
+dnl function also defines PYTHON_INCLUDES
+AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
+[AC_REQUIRE([AM_PATH_PYTHON])
+AC_MSG_CHECKING(for headers required to compile python extensions)
+dnl deduce PYTHON_INCLUDES
+py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
+py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
+PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
+if test "$py_prefix" != "$py_exec_prefix"; then
+  PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
+fi
+AC_SUBST(PYTHON_INCLUDES)
+dnl check if the headers exist:
+save_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
+AC_TRY_CPP([#include <Python.h>],dnl
+[AC_MSG_RESULT(found)
+$1],dnl
+[AC_MSG_RESULT(not found)
+$2])
+CPPFLAGS="$save_CPPFLAGS"
+])
+
+