build system: Check for and work-around broken Perl_load_module().
authorSebastian Harl <sh@tokkee.org>
Mon, 2 Feb 2009 11:28:43 +0000 (11:28 +0000)
committerSebastian Harl <sh@tokkee.org>
Thu, 5 Feb 2009 20:10:25 +0000 (21:10 +0100)
Configure now checks for a broken Perl_load_module() definition as introduced
in Perl 5.10 which incorrectly uses __attribute__nonnull__(3). If that has been
detected, the perl plugin will now be built using -Wno-nonnull, thus ignoring
the warning / error produced by the nonnull attribute.

References: #41
Resolves: #42

configure.in
src/Makefile.am

index c86b711..18a83b0 100644 (file)
@@ -1949,6 +1949,43 @@ then
        CFLAGS=$SAVE_CFLAGS
        LDFLAGS=$SAVE_LDFLAGS
 fi
+
+if test "x$with_libperl" = "xyes"
+then
+       SAVE_CFLAGS=$CFLAGS
+       SAVE_LDFLAGS=$LDFLAGS
+       # trigger an error if Perl_load_module*() uses __attribute__nonnull__(3)
+       # (see issues #41 and #42)
+       CFLAGS="$CFLAGS $PERL_CFLAGS -Wall -Werror"
+       LDFLAGS="$LDFLAGS $PERL_LDFLAGS"
+
+       AC_CACHE_CHECK([for broken Perl_load_module()],
+               [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);
+                       ]]),
+                       [have_broken_perl_load_module="no"],
+                       [have_broken_perl_load_module="yes"]
+               )
+       )
+
+       AM_CONDITIONAL(HAVE_BROKEN_PERL_LOAD_MODULE,
+                       test "x$have_broken_perl_load_module" = "xyes")
+
+       CFLAGS=$SAVE_CFLAGS
+       LDFLAGS=$SAVE_LDFLAGS
+fi
 # }}}
 
 # --with-libpq {{{
index 26db76d..935ed7b 100644 (file)
@@ -604,6 +604,11 @@ perl_la_CPPFLAGS = $(AM_CPPFLAGS) -DHAS_BOOL=1
 perl_la_CFLAGS  = $(AM_CFLAGS) \
                $(PERL_CFLAGS) \
                -DXS_VERSION=\"$(VERSION)\" -DVERSION=\"$(VERSION)\"
+# Work-around for issues #41 and #42 - Perl 5.10 incorrectly introduced
+# __attribute__nonnull__(3) for Perl_load_module().
+if HAVE_BROKEN_PERL_LOAD_MODULE
+perl_la_CFLAGS += -Wno-nonnull
+endif
 perl_la_LDFLAGS = -module -avoid-version \
                $(PERL_LDFLAGS)
 collectd_LDADD += "-dlopen" perl.la