+if test "x$with_libperl" = "xyes"; then
+ # trigger an error if Perl_load_module*() uses __attribute__nonnull__(3)
+ # (see issues #41 and #42)
+ SAVE_CFLAGS="$CFLAGS"
+ SAVE_LIBS="$LIBS"
+ CFLAGS="$CFLAGS $PERL_CFLAGS -Wall -Werror"
+ LIBS="$LIBS $PERL_LIBS"
+
+ AC_CACHE_CHECK([for broken Perl_load_module()],
+ [c_cv_have_broken_perl_load_module],
+ [
+ AC_LINK_IFELSE(
+ [
+ AC_LANG_PROGRAM(
+ [[
+ #define PERL_NO_GET_CONTEXT
+ #include <EXTERN.h>
+ #include <perl.h>
+ #include <XSUB.h>
+ ]],
+ [[
+ dTHX;
+ load_module (PERL_LOADMOD_NOIMPORT,
+ newSVpv ("Collectd::Plugin::FooBar", 24),
+ Nullsv);
+ ]]
+ )
+ ],
+ [c_cv_have_broken_perl_load_module="no"],
+ [c_cv_have_broken_perl_load_module="yes"]
+ )
+ ]
+ )
+
+ CFLAGS="$SAVE_CFLAGS"
+ LIBS="$SAVE_LIBS"
+fi
+
+if test "x$c_cv_have_broken_perl_load_module" = "xyes"; then
+ PERL_CFLAGS="$PERL_CFLAGS -Wno-nonnull"
+fi
+
+if test "x$with_libperl" = "xyes"; then
+ SAVE_CFLAGS="$CFLAGS"
+ SAVE_LIBS="$LIBS"
+ CFLAGS="$CFLAGS $PERL_CFLAGS"
+ LIBS="$LIBS $PERL_LIBS"
+
+ AC_CHECK_MEMBER(
+ [struct mgvtbl.svt_local],
+ [have_struct_mgvtbl_svt_local="yes"],
+ [have_struct_mgvtbl_svt_local="no"],
+ [[
+ #include <EXTERN.h>
+ #include <perl.h>
+ #include <XSUB.h>
+ ]]
+ )
+
+ if test "x$have_struct_mgvtbl_svt_local" = "xyes"; then
+ AC_DEFINE([HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL], [1], [Define if Perls struct mgvtbl has member svt_local.])
+ fi
+
+ CFLAGS="$SAVE_CFLAGS"
+ LIBS="$SAVE_LIBS"
+fi
+AC_SUBST([PERL_CFLAGS])
+AC_SUBST([PERL_LIBS])
+
+# }}}
+
+# --with-libpq {{{
+with_pg_config="pg_config"
+AC_ARG_WITH([libpq],
+ [AS_HELP_STRING([--with-libpq@<:@=PREFIX@:>@], [Path to libpq.])],
+ [
+ if test "x$withval" = "xno" || test "x$withval" = "xyes"; then
+ with_libpq="$withval"
+ else
+ if test -f "$withval" && test -x "$withval"; then
+ with_pg_config="$withval"
+ else if test -x "$withval/bin/pg_config"; then
+ with_pg_config="$withval/bin/pg_config"
+ fi; fi
+ with_libpq="yes"
+ fi
+ ],
+ [with_libpq="yes"]
+)
+
+if test "x$with_libpq" = "xyes"; then
+ with_libpq_includedir=`$with_pg_config --includedir 2> /dev/null`
+ pg_config_status=$?
+
+ if test $pg_config_status -eq 0; then
+ if test -n "$with_libpq_includedir"; then
+ for dir in $with_libpq_includedir; do
+ with_libpq_cppflags="$with_libpq_cppflags -I$dir"
+ done
+ fi
+ else
+ AC_MSG_WARN([$with_pg_config returned with status $pg_config_status])
+ fi
+
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_libpq_cppflags"
+
+ AC_CHECK_HEADERS([libpq-fe.h],
+ [with_libpq="yes"],
+ [with_libpq="no (libpq-fe.h not found)"]
+ )
+
+ CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+
+if test "x$with_libpq" = "xyes"; then
+ with_libpq_libdir=`$with_pg_config --libdir 2> /dev/null`
+ pg_config_status=$?
+
+ if test $pg_config_status -eq 0
+ then
+ if test -n "$with_libpq_libdir"; then
+ for dir in $with_libpq_libdir; do
+ with_libpq_ldflags="$with_libpq_ldflags -L$dir"
+ done
+ fi
+ else
+ AC_MSG_WARN([$with_pg_config returned with status $pg_config_status])
+ fi
+
+ SAVE_LDFLAGS="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $with_libpq_ldflags"
+
+ AC_CHECK_LIB([pq], [PQserverVersion],
+ [with_libpq="yes"],
+ [with_libpq="no (symbol 'PQserverVersion' not found)"])
+
+ LDFLAGS="$SAVE_LDFLAGS"
+fi
+
+if test "x$with_libpq" = "xyes"; then
+ BUILD_WITH_LIBPQ_CPPFLAGS="$with_libpq_cppflags"
+ BUILD_WITH_LIBPQ_LDFLAGS="$with_libpq_ldflags"
+ BUILD_WITH_LIBPQ_LIBS="-lpq"
+fi
+
+AC_SUBST([BUILD_WITH_LIBPQ_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBPQ_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBPQ_LIBS])
+# }}}
+
+# --with-libpqos {{{
+AC_ARG_WITH([libpqos],
+ [AS_HELP_STRING([--with-libpqos@<:@=PREFIX@:>@], [Path to libpqos.])],
+ [
+ if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+ with_libpqos_cppflags="-I$withval/include"
+ with_libpqos_ldflags="-L$withval/lib"
+ with_libpqos="yes"
+ else
+ with_libpqos="$withval"
+ fi
+ ],
+ [with_libpqos="yes"]
+)