configure.in: Don't use `test -a'.
[collectd.git] / configure.in
index 9701085..d9dd13a 100644 (file)
@@ -28,6 +28,7 @@ AC_LIBTOOL_DLOPEN
 AC_PROG_LIBTOOL
 AC_PROG_LEX
 AC_PROG_YACC
+PKG_PROG_PKG_CONFIG
 AC_CONFIG_SUBDIRS(libltdl)
 
 AC_MSG_CHECKING([for kernel type ($host_os)])
@@ -55,7 +56,7 @@ AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
 AC_HEADER_DIRENT
 
-AC_CHECK_HEADERS(stdint.h stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h)
+AC_CHECK_HEADERS(stdint.h stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h endian.h)
 
 # For ping library
 AC_CHECK_HEADERS(netinet/in_systm.h, [], [],
@@ -355,11 +356,6 @@ have_termios_h="no"
 AC_CHECK_HEADERS(termios.h, [have_termios_h="yes"])
 
 #
-# Checking for libraries
-#
-AC_CHECK_LIB(m, ext)
-
-#
 # Checks for typedefs, structures, and compiler characteristics.
 #
 AC_C_CONST
@@ -376,8 +372,69 @@ AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr
 
 AC_FUNC_STRERROR_R
 
-AC_CHECK_FUNCS(getpwnam_r)
-AC_CHECK_FUNCS(getgrnam_r)
+AC_CACHE_CHECK([for strtok_r],
+  [have_strtok_r_default],
+  AC_LINK_IFELSE(
+    AC_LANG_PROGRAM(
+    [[[[
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+    ]]]],
+    [[[[
+      char buffer[] = "foo,bar,baz";
+      char *token;
+      char *dummy;
+      char *saveptr;
+
+      dummy = buffer;
+      saveptr = NULL;
+      while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
+      {
+       dummy = NULL;
+        printf ("token = %s;\n", token);
+      }
+    ]]]]),
+    [have_strtok_r_default="yes"],
+    [have_strtok_r_default="no"]
+  )
+)
+
+if test "x$have_strtok_r_default" = "xno"
+then
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -D_REENTRANT=1"
+
+  AC_CACHE_CHECK([if strtok_r needs _REENTRANT],
+    [have_strtok_r_reentrant],
+    AC_LINK_IFELSE(
+      AC_LANG_PROGRAM(
+      [[[[
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+      ]]]],
+      [[[[
+        char buffer[] = "foo,bar,baz";
+        char *token;
+        char *dummy;
+        char *saveptr;
+
+        dummy = buffer;
+        saveptr = NULL;
+        while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
+        {
+         dummy = NULL;
+          printf ("token = %s;\n", token);
+        }
+      ]]]]),
+      [have_strtok_r_reentrant="yes"],
+      [AC_MSG_FAILURE([strtok_r isn't available. Please file a bugreport!])]
+    )
+  )
+fi
+
+AC_CHECK_FUNCS(getpwnam_r getgrnam_r setgroups regcomp regerror regexec regfree)
 
 socket_needs_socket="no"
 AC_CHECK_FUNCS(socket, [], AC_CHECK_LIB(socket, socket, [socket_needs_socket="yes"], AC_MSG_ERROR(cannot find socket)))
@@ -387,8 +444,6 @@ nanosleep_needs_rt="no"
 AC_CHECK_FUNCS(nanosleep, [], AC_CHECK_LIB(rt, nanosleep, [nanosleep_needs_rt="yes"], AC_MSG_ERROR(cannot find nanosleep)))
 AM_CONDITIONAL(BUILD_WITH_LIBRT, test "x$nanosleep_needs_rt" = "xyes")
 
-AC_CHECK_FUNCS(regcomp regerror regexec regfree)
-
 AC_CHECK_FUNCS(sysctlbyname, [have_sysctlbyname="yes"], [have_sysctlbyname="no"])
 AC_CHECK_FUNCS(host_statistics, [have_host_statistics="yes"], [have_host_statistics="no"])
 AC_CHECK_FUNCS(processor_info, [have_processor_info="yes"], [have_processor_info="no"])
@@ -512,8 +567,160 @@ else
   AC_MSG_ERROR([Didn't find out how to statically initialize variables to NAN. Sorry.])
 fi; fi; fi
 
-# For mount interface
-#AC_CHECK_FUNCS(getfsent getvfsent)
+AC_ARG_WITH(fp-layout, [AS_HELP_STRING([--with-fp-layout], [set the memory layout of doubles. For crosscompiling only.])],
+[
+ if test "x$withval" = "xnothing"; then
+       fp_layout_type="nothing"
+ else if test "x$withval" = "xendianflip"; then
+       fp_layout_type="endianflip"
+ else if test "x$withval" = "xintswap"; then
+       fp_layout_type="intswap"
+ else
+       AC_MSG_ERROR([Invalid argument for --with-fp-layout. Valid arguments are: nothing, endianflip, intswap]);
+fi; fi; fi
+],
+[fp_layout_type="unknown"])
+
+if test "x$fp_layout_type" = "xunknown"; then
+  AC_CACHE_CHECK([if doubles are stored in x86 representation],
+    [fp_layout_need_nothing],
+    AC_RUN_IFELSE(
+      AC_LANG_PROGRAM(
+      [[[[
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+      ]]]],
+      [[[[
+       uint64_t i0;
+       uint64_t i1;
+       uint8_t c[8];
+       double d;
+
+       d = 8.642135e130; 
+       memcpy ((void *) &i0, (void *) &d, 8);
+
+       i1 = i0;
+       memcpy ((void *) c, (void *) &i1, 8);
+
+       if ((c[0] == 0x2f) && (c[1] == 0x25)
+                       && (c[2] == 0xc0) && (c[3] == 0xc7)
+                       && (c[4] == 0x43) && (c[5] == 0x2b)
+                       && (c[6] == 0x1f) && (c[7] == 0x5b))
+               return (0);
+       else
+               return (1);
+      ]]]]),
+      [fp_layout_need_nothing="yes"],
+      [fp_layout_need_nothing="no"]
+    )
+  )
+  if test "x$fp_layout_need_nothing" = "xyes"; then
+    fp_layout_type="nothing"
+  fi
+fi
+if test "x$fp_layout_type" = "xunknown"; then
+  AC_CACHE_CHECK([if endianflip converts to x86 representation],
+    [fp_layout_need_endianflip],
+    AC_RUN_IFELSE(
+      AC_LANG_PROGRAM(
+      [[[[
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#define endianflip(A) ((((uint64_t)(A) & 0xff00000000000000LL) >> 56) | \
+                       (((uint64_t)(A) & 0x00ff000000000000LL) >> 40) | \
+                       (((uint64_t)(A) & 0x0000ff0000000000LL) >> 24) | \
+                       (((uint64_t)(A) & 0x000000ff00000000LL) >> 8)  | \
+                       (((uint64_t)(A) & 0x00000000ff000000LL) << 8)  | \
+                       (((uint64_t)(A) & 0x0000000000ff0000LL) << 24) | \
+                       (((uint64_t)(A) & 0x000000000000ff00LL) << 40) | \
+                       (((uint64_t)(A) & 0x00000000000000ffLL) << 56))
+      ]]]],
+      [[[[
+       uint64_t i0;
+       uint64_t i1;
+       uint8_t c[8];
+       double d;
+
+       d = 8.642135e130; 
+       memcpy ((void *) &i0, (void *) &d, 8);
+
+       i1 = endianflip (i0);
+       memcpy ((void *) c, (void *) &i1, 8);
+
+       if ((c[0] == 0x2f) && (c[1] == 0x25)
+                       && (c[2] == 0xc0) && (c[3] == 0xc7)
+                       && (c[4] == 0x43) && (c[5] == 0x2b)
+                       && (c[6] == 0x1f) && (c[7] == 0x5b))
+               return (0);
+       else
+               return (1);
+      ]]]]),
+      [fp_layout_need_endianflip="yes"],
+      [fp_layout_need_endianflip="no"]
+    )
+  )
+  if test "x$fp_layout_need_endianflip" = "xyes"; then
+    fp_layout_type="endianflip"
+  fi
+fi
+if test "x$fp_layout_type" = "xunknown"; then
+  AC_CACHE_CHECK([if intswap converts to x86 representation],
+    [fp_layout_need_intswap],
+    AC_RUN_IFELSE(
+      AC_LANG_PROGRAM(
+      [[[[
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#define intswap(A)    ((((uint64_t)(A) & 0xffffffff00000000LL) >> 32) | \
+                       (((uint64_t)(A) & 0x00000000ffffffffLL) << 32))
+      ]]]],
+      [[[[
+       uint64_t i0;
+       uint64_t i1;
+       uint8_t c[8];
+       double d;
+
+       d = 8.642135e130; 
+       memcpy ((void *) &i0, (void *) &d, 8);
+
+       i1 = intswap (i0);
+       memcpy ((void *) c, (void *) &i1, 8);
+
+       if ((c[0] == 0x2f) && (c[1] == 0x25)
+                       && (c[2] == 0xc0) && (c[3] == 0xc7)
+                       && (c[4] == 0x43) && (c[5] == 0x2b)
+                       && (c[6] == 0x1f) && (c[7] == 0x5b))
+               return (0);
+       else
+               return (1);
+      ]]]]),
+      [fp_layout_need_intswap="yes"],
+      [fp_layout_need_intswap="no"]
+    )
+  )
+  if test "x$fp_layout_need_intswap" = "xyes"; then
+    fp_layout_type="intswap"
+  fi
+fi
+
+if test "x$fp_layout_type" = "xnothing"; then
+  AC_DEFINE(FP_LAYOUT_NEED_NOTHING, 1,
+  [Define if doubles are stored in x86 representation.])
+else if test "x$fp_layout_type" = "xendianflip"; then
+  AC_DEFINE(FP_LAYOUT_NEED_ENDIANFLIP, 1,
+  [Define if endianflip is needed to convert to x86 representation.])
+else if test "x$fp_layout_type" = "xintswap"; then
+  AC_DEFINE(FP_LAYOUT_NEED_INTSWAP, 1,
+  [Define if intswap is needed to convert to x86 representation.])
+else
+  AC_MSG_ERROR([Didn't find out how doubles are stored in memory. Sorry.])
+fi; fi; fi
 
 have_getfsstat="no"
 AC_CHECK_FUNCS(getfsstat, [have_getfsstat="yes"])
@@ -666,6 +873,9 @@ AC_CHECK_MEMBERS([kstat_io_t.nwritten, kstat_io_t.writes, kstat_io_t.nwrites, ks
 #endif
        ])
 
+#
+# Checks for libraries begin here
+#
 with_libresolv="yes"
 AC_CHECK_LIB(resolv, res_search,
 [
@@ -692,19 +902,25 @@ AC_ARG_WITH(rrdtool, [AS_HELP_STRING([--with-rrdtool@<:@=PREFIX@:>@], [Path to r
 ], [with_rrdtool="yes"])
 if test "x$with_rrdtool" = "xyes"
 then
-       SAVE_CFLAGS="$CFLAGS"
+       SAVE_CPPFLAGS="$CPPFLAGS"
        SAVE_LDFLAGS="$LDFLAGS"
 
-       CFLAGS="$CFLAGS $librrd_cflags"
+       CPPFLAGS="$CPPFLAGS $librrd_cflags"
        LDFLAGS="$LDFLAGS $librrd_ldflags"
 
        AC_CHECK_HEADERS(rrd.h,, [with_rrdtool="no (rrd.h not found)"])
 
-       CFLAGS="$SAVE_CFLAGS"
+       CPPFLAGS="$SAVE_CPPFLAGS"
        LDFLAGS="$SAVE_LDFLAGS"
 fi
 if test "x$with_rrdtool" = "xyes"
 then
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       SAVE_LDFLAGS="$LDFLAGS"
+
+       CPPFLAGS="$CPPFLAGS $librrd_cflags"
+       LDFLAGS="$LDFLAGS $librrd_ldflags"
+
        AC_CHECK_LIB(rrd_th, rrd_update_r,
        [with_rrdtool="yes"
         librrd_ldflags="$librrd_ldflags -lrrd_th -lm"
@@ -716,8 +932,11 @@ then
         ],
         [with_rrdtool="no (symbol 'rrd_update' not found)"],
         [-lm])
-       ]
+       ],
        [-lm])
+
+       CPPFLAGS="$SAVE_CPPFLAGS"
+       LDFLAGS="$SAVE_LDFLAGS"
 fi
 if test "x$with_rrdtool" = "xyes"
 then
@@ -732,7 +951,8 @@ then
 fi
 
 AC_ARG_WITH(libpthread, [AS_HELP_STRING([--with-libpthread=@<:@=PREFIX@:>@], [Path to libpthread.])],
-[      if test "x$withval" != "xno" -a "x$withval" != "xyes"
+[      if test "x$withval" != "xno" \
+               && test "x$withval" != "xyes"
        then
                LDFLAGS="$LDFLAGS -L$withval/lib"
                CPPFLAGS="$CPPFLAGS -I$withval/include"
@@ -825,12 +1045,12 @@ then
        then
                with_libcurl="no ($with_curl_config failed)"
        else
-               SAVE_CFLAGS=$CFLAGS
-               CFLAGS="$CFLAGS $with_curl_cflags"
+               SAVE_CPPFLAGS="$CPPFLAGS"
+               CPPFLAGS="$CPPFLAGS $with_curl_cflags"
 
                AC_CHECK_HEADERS(curl/curl.h, [], [with_libcurl="no (curl/curl.h not found)"], [])
 
-               CFLAGS="$SAVE_CFLAGS"
+               CPPFLAGS="$SAVE_CPPFLAGS"
        fi
 fi
 if test "x$with_libcurl" = "xyes"
@@ -859,60 +1079,123 @@ AM_CONDITIONAL(BUILD_WITH_LIBCURL, test "x$with_libcurl" = "xyes")
 ### END of check for libcurl ###
 
 with_libiokit="no"
-collectd_libiokit=0
 AC_CHECK_LIB(IOKit, IOServiceGetMatchingServices,
 [
        with_libiokit="yes"
-       collectd_libiokit=1
 ], 
 [
        with_libiokit="no"
-       collectd_libiokit=0
 ])
-AC_DEFINE_UNQUOTED(COLLECT_LIBIOKIT, [$collect_libiokit], [Wether or not to use the IOKit library])
 AM_CONDITIONAL(BUILD_WITH_LIBIOKIT, test "x$with_libiokit" = "xyes")
 
-with_libstatgrab="yes"
-with_libdevstat="no"
+with_libstatgrab_cflags=""
+with_libstatgrab_ldflags=""
 AC_ARG_WITH(libstatgrab, [AS_HELP_STRING([--with-libstatgrab@<:@=PREFIX@:>@], [Path to libstatgrab.])],
 [
-       if test "x$withval" != "xno" -a "x$withval" != "xyes"
+       if test "x$withval" != "xno" \
+               && test "x$withval" != "xyes"
        then
-               LDFLAGS="$LDFLAGS -L$withval/lib"
-               CPPFLAGS="$CPPFLAGS -I$withval/include"
+               with_libstatgrab_cflags="-I$withval/include"
+               with_libstatgrab_ldflags="-L$withval/lib"
                with_libstatgrab="yes"
        fi
 ],
 [
-       if test "x$ac_system" == "xunknown"
+       if test "x$ac_system" = "xunknown"
        then
                with_libstatgrab="yes"
        else
                with_libstatgrab="no"
        fi
 ])
-if test "x$with_libstatgrab" = "xyes"
+with_libstatgrab_pkg_config="yes"
+if test "x$with_libstatgrab" = "xyes" \
+  && test "x$PKG_CONFIG" != "x"
+then
+  AC_MSG_CHECKING([pkg-config for libstatgrab])
+  temp_result="found"
+  $PKG_CONFIG --exists libstatgrab 2>/dev/null
+  if test "$?" != "0"
+  then
+    with_libstatgrab_pkg_config="no"
+    temp_result="not found"
+  fi
+  AC_MSG_RESULT([$temp_result])
+else
+  AC_MSG_NOTICE([pkg-config not available, trying to guess flags for the statgrab library.])
+  with_libstatgrab_pkg_config="no"
+  with_libstatgrab_ldflags="$with_libstatgrab_ldflags -lstatgrab"
+fi
+
+if test "x$with_libstatgrab" = "xyes" \
+  && test "x$with_libstatgrab_pkg_config" = "xyes" \
+  && test "x$with_libstatgrab_cflags" = "x"
 then
-       AC_CHECK_LIB(statgrab, sg_init, [with_libstatgrab="yes"], [with_libstatgrab="no (libstatgrab not found)"])
+  AC_MSG_CHECKING([for libstatgrab CFLAGS])
+  temp_result="`$PKG_CONFIG --cflags libstatgrab`"
+  if test "$?" = "0"
+  then
+    with_libstatgrab_cflags="$temp_result"
+  else
+    with_libstatgrab="no ($PKG_CONFIG --cflags libstatgrab failed)"
+    temp_result="$PKG_CONFIG --cflags libstatgrab failed"
+  fi
+  AC_MSG_RESULT([$temp_result])
 fi
-if test "x$with_libstatgrab" = "xyes"
+
+if test "x$with_libstatgrab" = "xyes" \
+  && test "x$with_libstatgrab_pkg_config" = "xyes" \
+  && test "x$with_libstatgrab_ldflags" = "x"
 then
-       AC_CHECK_HEADERS(statgrab.h,,    [with_libstatgrab="no (statgrab.h not found)"])
+  AC_MSG_CHECKING([for libstatgrab LDFLAGS])
+  temp_result="`$PKG_CONFIG --libs libstatgrab`"
+  if test "$?" = "0"
+  then
+    with_libstatgrab_ldflags="$temp_result"
+  else
+    with_libstatgrab="no ($PKG_CONFIG --libs libstatgrab failed)"
+    temp_result="$PKG_CONFIG --libs libstatgrab failed"
+  fi
+  AC_MSG_RESULT([$temp_result])
 fi
+
 if test "x$with_libstatgrab" = "xyes"
 then
-       AC_CHECK_LIB(devstat, getdevs, [with_libdevstat="yes"], [with_libdevstat="no"])
+  SAVE_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $with_libstatgrab_cflags"
+
+  AC_CHECK_HEADERS(statgrab.h,
+                  [with_libstatgrab="yes"],
+                  [with_libstatgrab="no (statgrab.h not found)"])
+
+  CPPFLAGS="$SAVE_CPPFLAGS"
 fi
+
 if test "x$with_libstatgrab" = "xyes"
 then
-       collect_libstatgrab=1
-else
-       collect_libstatgrab=0
+  SAVE_CFLAGS="$CFLAGS"
+  SAVE_LDFLAGS="$LDFLAGS"
+
+  CFLAGS="$CFLAGS $with_libstatgrab_cflags"
+  LDFLAGS="$LDFLAGS $with_libstatgrab_ldflags"
+
+  AC_CHECK_LIB(statgrab, sg_init,
+              [with_libstatgrab="yes"],
+              [with_libstatgrab="no (symbol sg_init not found)"])
+
+  CFLAGS="$SAVE_CFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
 fi
-AC_DEFINE_UNQUOTED(COLLECT_LIBSTATGRAB, [$collect_libstatgrab],
-       [Wether or not to use statgrab library])
+
 AM_CONDITIONAL(BUILD_WITH_LIBSTATGRAB, test "x$with_libstatgrab" = "xyes")
-AM_CONDITIONAL(BUILD_WITH_LIBDEVSTAT,  test "x$with_libdevstat"  = "xyes")
+if test "x$with_libstatgrab" = "xyes"
+then
+  AC_DEFINE(HAVE_LIBSTATGRAB, 1, [Define to 1 if you have the 'statgrab' library (-lstatgrab)])
+  BUILD_WITH_LIBSTATGRAB_CFLAGS="$with_libstatgrab_cflags"
+  BUILD_WITH_LIBSTATGRAB_LDFLAGS="$with_libstatgrab_ldflags"
+  AC_SUBST(BUILD_WITH_LIBSTATGRAB_CFLAGS)
+  AC_SUBST(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
+fi
 
 AC_CHECK_LIB(kvm, kvm_getswapinfo, [with_libkvm="yes"], [with_libkvm="no"])
 if test "x$with_libkvm" = "xyes"
@@ -921,13 +1204,21 @@ then
 fi
 AM_CONDITIONAL(BUILD_WITH_LIBKVM, test "x$with_libkvm" = "xyes")
 
+with_sensors_cflags=""
+with_sensors_ldflags=""
 AC_ARG_WITH(lm-sensors, [AS_HELP_STRING([--with-lm-sensors@<:@=PREFIX@:>@], [Path to lm_sensors.])],
 [
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
+       if test "x$withval" = "xno"
        then
-               LDFLAGS="$LDFLAGS -L$withval/lib"
-               CPPFLAGS="$CPPFLAGS -I$withval/include"
+               with_lm_sensors="no"
+       else
                with_lm_sensors="yes"
+               if test "x$withval" != "xyes"
+               then
+                       with_sensors_cflags="-I$withval/include"
+                       with_sensors_ldflags="-L$withval/lib"
+                       with_lm_sensors="yes"
+               fi
        fi
 ],
 [
@@ -940,28 +1231,41 @@ AC_ARG_WITH(lm-sensors, [AS_HELP_STRING([--with-lm-sensors@<:@=PREFIX@:>@], [Pat
 ])
 if test "x$with_lm_sensors" = "xyes"
 then
-       AC_CHECK_LIB(sensors, sensors_init,
-       [
-               AC_DEFINE(HAVE_LIBSENSORS, 1, [Define to 1 if you have the sensors library (-lsensors).])
-       ],
-       [with_lm_sensors="no (libsensors not found)"])
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       CPPFLAGS="$CPPFLAGS $with_sensors_cflags"
+
+#      AC_CHECK_HEADERS(sensors/sensors.h,
+#      [
+#              AC_DEFINE(HAVE_SENSORS_SENSORS_H, 1, [Define to 1 if you have the <sensors/sensors.h> header file.])
+#      ],
+#      [with_lm_sensors="no (sensors/sensors.h not found)"])
+       AC_CHECK_HEADERS(sensors/sensors.h, [], [with_lm_sensors="no (sensors/sensors.h not found)"])
+
+       CPPFLAGS="$SAVE_CPPFLAGS"
 fi
 if test "x$with_lm_sensors" = "xyes"
 then
-       AC_CHECK_HEADERS(sensors/sensors.h,
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       SAVE_LDFLAGS="$LDFLAGS"
+       CPPFLAGS="$CPPFLAGS $with_sensors_cflags"
+       LDFLAGS="$LDFLAGS $with_sensors_ldflags"
+
+       AC_CHECK_LIB(sensors, sensors_init,
        [
-               AC_DEFINE(HAVE_SENSORS_SENSORS_H, 1, [Define to 1 if you have the <sensors/sensors.h> header file.])
+               AC_DEFINE(HAVE_LIBSENSORS, 1, [Define to 1 if you have the sensors library (-lsensors).])
        ],
-       [with_lm_sensors="no (sensors/sensors.h not found)"])
+       [with_lm_sensors="no (libsensors not found)"])
+
+       CPPFLAGS="$SAVE_CPPFLAGS"
+       LDFLAGS="$SAVE_LDFLAGS"
 fi
 if test "x$with_lm_sensors" = "xyes"
 then
-       collect_lm_sensors=1
-else
-       collect_lm_sensors=0
+       BUILD_WITH_LIBSENSORS_CFLAGS="$with_sensors_cflags"
+       BUILD_WITH_LIBSENSORS_LDFLAGS="$with_sensors_ldflags"
+       AC_SUBST(BUILD_WITH_LIBSENSORS_CFLAGS)
+       AC_SUBST(BUILD_WITH_LIBSENSORS_LDFLAGS)
 fi
-AC_DEFINE_UNQUOTED(COLLECT_LM_SENSORS, [$collect_lm_sensors],
-       [Wether or not to use sensors library])
 AM_CONDITIONAL(BUILD_WITH_LM_SENSORS, test "x$with_lm_sensors" = "xyes")
 
 with_mysql_config="mysql_config"
@@ -998,12 +1302,12 @@ then
        then
                with_libmysql="no"
        else
-               SAVE_CFLAGS=$CFLAGS
-               CFLAGS="$CFLAGS $with_mysql_cflags"
+               SAVE_CPPFLAGS="$CPPFLAGS"
+               CPPFLAGS="$CPPFLAGS $with_mysql_cflags"
 
                AC_CHECK_HEADERS(mysql/mysql.h, [], [with_libmysql="no (mysql/mysql.h not found)"], [])
 
-               CFLAGS="$SAVE_CFLAGS"
+               CPPFLAGS="$SAVE_CPPFLAGS"
        fi
 fi
 if test "x$with_libmysql" = "xyes"
@@ -1177,9 +1481,20 @@ AC_ARG_WITH(libperl, [AS_HELP_STRING([--with-libperl@<:@=PREFIX@:>@], [Path to l
        with_libperl="yes"
 ])
 
+AC_MSG_CHECKING([for perl])
+perl_interpreter=`which "$perl_interpreter" 2> /dev/null`
+if test -x "$perl_interpreter"
+then
+       AC_MSG_RESULT([yes])
+else
+       perl_interpreter=""
+       AC_MSG_RESULT([no])
+fi
+
 AC_SUBST(PERL, "$perl_interpreter")
 
-if test "x$with_libperl" = "xyes"
+if test "x$with_libperl" = "xyes" \
+       && test -n "$perl_interpreter"
 then
   SAVE_CFLAGS=$CFLAGS
   SAVE_LDFLAGS=$LDFLAGS
@@ -1219,7 +1534,10 @@ then
 
   CFLAGS=$SAVE_CFLAGS
   LDFLAGS=$SAVE_LDFLAGS
-fi
+else if test -z "$perl_interpreter"; then
+  with_libperl="no (no perl interpreter found)"
+  have_libperl="no"
+fi; fi
 AM_CONDITIONAL(BUILD_WITH_LIBPERL, test "x$with_libperl" = "xyes")
 
 AC_ARG_WITH(libiptc, [AS_HELP_STRING([--with-libiptc@<:@=PREFIX@:>@], [Path to libiptc.])],
@@ -1269,7 +1587,7 @@ AC_ARG_WITH(libnetsnmp, [AS_HELP_STRING([--with-libnetsnmp@<:@=PREFIX@:>@], [Pat
        if test "x$withval" = "xno"
        then
                with_libnetsnmp="no"
-       else if "x$withval" = "xyes"
+       else if test "x$withval" = "xyes"
        then
                with_libnetsnmp="yes"
        else
@@ -1293,12 +1611,12 @@ then
        then
                with_libnetsnmp="no ($with_snmp_config failed)"
        else
-               SAVE_CFLAGS=$CFLAGS
-               CFLAGS="$CFLAGS $with_snmp_cflags"
+               SAVE_CPPFLAGS="$CPPFLAGS"
+               CPPFLAGS="$CPPFLAGS $with_snmp_cflags"
                
                AC_CHECK_HEADERS(net-snmp/net-snmp-config.h, [], [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"])
 
-               CFLAGS="$SAVE_CFLAGS"
+               CPPFLAGS="$SAVE_CPPFLAGS"
        fi
 fi
 if test "x$with_libnetsnmp" = "xyes"
@@ -1361,12 +1679,12 @@ then
 fi
 if test "x$with_libupsclient" = "xyes"
 then
-       SAVE_CFLAGS="$CFLAGS"
-       CFLAGS="$CFLAGS $with_upsclient_cflags"
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       CPPFLAGS="$CPPFLAGS $with_upsclient_cflags"
 
        AC_CHECK_HEADERS(upsclient.h, [], [with_libupsclient="no (upsclient.h not found)"])
 
-       CFLAGS="$SAVE_CFLAGS"
+       CPPFLAGS="$SAVE_CPPFLAGS"
 fi
 if test "x$with_libupsclient" = "xyes"
 then
@@ -1393,10 +1711,15 @@ then
 fi
 if test "x$with_libupsclient" = "xyes"
 then
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       CPPFLAGS="$CPPFLAGS $with_upsclient_cflags"
+
        AC_CHECK_TYPES([UPSCONN_t, UPSCONN], [], [], 
 [#include <stdlib.h>
 #include <stdio.h>
 #include <upsclient.h>])
+
+       CPPFLAGS="$SAVE_CPPFLAGS"
 fi
 AM_CONDITIONAL(BUILD_WITH_LIBUPSCLIENT, test "x$with_libupsclient" = "xyes")
 
@@ -1406,7 +1729,8 @@ with_xmms_cflags=""
 with_xmms_libs=""
 AC_ARG_WITH(libxmms, [AS_HELP_STRING([--with-libxmms@<:@=PREFIX@:>@], [Path to libxmms.])],
 [
-       if test "x$withval" != "xno" -a "x$withval" != "xyes"
+       if test "x$withval" != "xno" \
+               && test "x$withval" != "xyes"
        then
                if test -f "$withval" && test -x "$withval";
                then
@@ -1865,7 +2189,8 @@ AC_PLUGIN([wireless],    [$plugin_wireless],   [Wireless statistics])
 AC_PLUGIN([xmms],        [$with_libxmms],      [XMMS statistics])
 
 dnl ip_vs.h
-if test "x$ac_system" = "xLinux" -a "x$have_net_ip_vs_h$have_ip_vs_h" = "xnono"
+if test "x$ac_system" = "xLinux" \
+       && test "x$have_net_ip_vs_h$have_ip_vs_h" = "xnono"
 then
        enable_ipvs="$enable_ipvs (ip_vs.h not found)"
 fi
@@ -1877,11 +2202,19 @@ AC_ARG_WITH(perl-bindings, [AS_HELP_STRING([--with-perl-bindings@<:@=OPTIONS@:>@
        then
                PERL_BINDINGS_OPTIONS="$withval"
                with_perl_bindings="yes"
+       else
+               PERL_BINDINGS_OPTIONS=""
+               with_perl_bindings="$withval"
        fi
 ],
 [
        PERL_BINDINGS_OPTIONS=""
-       with_perl_bindings="yes"
+       if test -n "$perl_interpreter"
+       then
+               with_perl_bindings="yes"
+       else
+               with_perl_bindings="no (no perl interpreter found)"
+       fi
 ])
 if test "x$with_perl_bindings" = "xyes"
 then
@@ -1894,7 +2227,8 @@ AC_SUBST(PERL_BINDINGS_OPTIONS)
 
 AC_OUTPUT(Makefile src/Makefile src/collectd.conf src/liboconfig/Makefile src/liboping/Makefile bindings/Makefile)
 
-if test "x$with_liboping" = "xyes" -a "x$with_own_liboping" = "xyes"
+if test "x$with_liboping" = "xyes" \
+       && test "x$with_own_liboping" = "xyes"
 then
        with_liboping="yes (shipped version)"
 fi
@@ -1906,7 +2240,8 @@ else
        enable_perl="no (needs libperl)"
 fi
 
-if test "x$with_perl_bindings" = "xyes" -a "x$PERL_BINDINGS_OPTIONS" != "x"
+if test "x$with_perl_bindings" = "xyes" \
+       && test "x$PERL_BINDINGS_OPTIONS" != "x"
 then
        with_perl_bindings="yes ($PERL_BINDINGS_OPTIONS)"
 fi
@@ -1976,6 +2311,7 @@ Configuration:
     perl  . . . . . . . $enable_perl
     ping  . . . . . . . $enable_ping
     processes . . . . . $enable_processes
+    rrdtool . . . . . . $enable_rrdtool
     sensors . . . . . . $enable_sensors
     serial  . . . . . . $enable_serial
     snmp  . . . . . . . $enable_snmp