-perl_interpreter="perl"
-AC_ARG_WITH(libperl, [AS_HELP_STRING([--with-libperl@<:@=PREFIX@:>@], [Path to libperl.])],
-[
- if test -f "$withval" && test -x "$withval"
- then
- perl_interpreter="$withval"
- with_libperl="yes"
- else if test "x$withval" != "xno" && test "x$withval" != "xyes"
- then
- LDFLAGS="$LDFLAGS -L$withval/lib"
- CPPFLAGS="$CPPFLAGS -I$withval/include"
- perl_interpreter="$withval/bin/perl"
- with_libperl="yes"
- else
- with_libperl="$withval"
- fi; fi
-],
-[
- with_libperl="yes"
-])
+AC_ARG_WITH([libperl],
+ [AS_HELP_STRING([--with-libperl@<:@=PREFIX@:>@], [Path to libperl.])],
+ [
+ if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+ LDFLAGS="$LDFLAGS -L$withval/lib"
+ CPPFLAGS="$CPPFLAGS -I$withval/include"
+ with_libperl="yes"
+ else
+ with_libperl="$withval"
+ fi
+ ],
+ [with_libperl="yes"]
+)
+
+AC_ARG_VAR([PERL], [path to Perl interpreter])
+AC_PATH_PROG([PERL], [perl])
+
+if test "x$PERL" = "x"; then
+ with_libperl="no (no Perl interpreter found)"
+fi
+
+if test "x$with_libperl" = "xyes"; then
+ SAVE_CFLAGS="$CFLAGS"
+ SAVE_LIBS="$LIBS"
+ dnl ARCHFLAGS="" -> disable multi -arch on OSX (see Config_heavy.pl:fetch_string)
+ PERL_CFLAGS=`ARCHFLAGS="" $PERL -MExtUtils::Embed -e perl_inc`
+ PERL_LIBS=`ARCHFLAGS="" $PERL -MExtUtils::Embed -e ldopts`
+ CFLAGS="$CFLAGS $PERL_CFLAGS"
+ LIBS="$LIBS $PERL_LIBS"
+
+ AC_CACHE_CHECK([for libperl],
+ [c_cv_have_libperl],
+ [
+ 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_libperl="yes"],
+ [c_cv_have_libperl="no"]
+ )
+ ]
+ )
+
+ CFLAGS="$SAVE_CFLAGS"
+ LIBS="$SAVE_LIBS"
+
+ if test "x$c_cv_have_libperl" = "xno"; then
+ with_libperl="no"
+ fi
+fi
+
+if test "x$with_libperl" = "xyes"; then
+ SAVE_CFLAGS="$CFLAGS"
+ SAVE_LIBS="$LIBS"
+ CFLAGS="$CFLAGS $PERL_CFLAGS"
+ LIBS="$LIBS $PERL_LIBS"
+
+ AC_CACHE_CHECK([if Perl supports ithreads],
+ [c_cv_have_perl_ithreads],
+ [
+ AC_LINK_IFELSE(
+ [
+ AC_LANG_PROGRAM(
+ [[
+ #include <EXTERN.h>
+ #include <perl.h>
+ #include <XSUB.h>
+
+ #if !defined(USE_ITHREADS)
+ # error "Perl does not support ithreads!"
+ #endif /* !defined(USE_ITHREADS) */
+ ]],
+ []
+ )
+ ],
+ [c_cv_have_perl_ithreads="yes"],
+ [c_cv_have_perl_ithreads="no"]
+ )
+ ]
+ )
+
+ CFLAGS="$SAVE_CFLAGS"
+ LIBS="$SAVE_LIBS"
+fi
+
+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"]
+ )
+ ]
+ )