I posted a while back asking for a good solution to building perl
modules inside an automake/autoconf-based package.  The only real
response I got was 'I thought everybody used MakeMaker to do that...'

So, I looked at how to combine MakeMaker w/ automake/autoconf, and
here's what I came up with (this example is contrived, not tested
directly):

First, this requires perl be available, so I created a autoconf macro
to define PERL.  The AC_OUTPUT includes:
  src/lib/Makefile
  src/perl/Makefile
  src/perl/Makefile.PL

In the src/lib/Makefile.am it builds the C++ API for my module.  The
src/perl/Makefile.am is for building the perl extension that wraps the
C++ API (using SWIG in my case).  There isn't a
src/perl/Makefile.PL.am, but rather a src/perl/Makefile.PL.in:

--- src/perl/Makefile.am -----------------------
noinst_DATA = .made_mod

.made_mode = MyMod.C Makefile.perl
        $(MAKE) -fMakefile.perl
        touch $@

MyMod.C: MyMod.i
         $(SWIG) $(SWIGFLAGS) -o $@ $^

Makefile.perl: Makefile.PL
        $(PERL) $< MAKEFILE=$@

install-data-local:
        $(MAKE) -fMakefile.perl PREFIX=$(prefix) install

CLEANFILES = *~ .made_mod MyMod.C MyMod.pm
clean-local:
        if test -f Makefile.perl; them $(MAKE) -fMakefile.perl realclean; fi
        rm -f Makefile.perl Makefile.perl.old
------------------------------------------------

--- src/perl/Makefile.PL.in -----------------------
use ExtUtils::MakeMaker;
WriteMakefile ( NAME => 'MyMod',
                DEFINE => '@DEFS@',
                INC => '-I@top_srcdir@/src/lib @CPPFLAGS@',
                LIBS => '-L@top_srcdir@/src/lib -lMyAPI_PIC ',
                INSTALLDIRS => 'perl' );
---------------------------------------------------

The Makefile.PL.in gets processed by autoconf to expand useful macros
like @top_srcdir@.  At build time, the Makefile.perl gets generated
from the Makefile.PL, and then Makefile.perl is used to build and
install the extension in the normal MakeMaker-defined way.

This method isn't foolproof, super robust.  For building the perl
extension, most of the 'configuration' comes from the perl Config.pm,
so whatever is configured in the various other Makefiles is not
reflected in the Makefile.perl.  Perhaps that's not an issue -- what
do the experts think?  

Happy to have comments on this...

Jeremy
-- 
Jeremy Slade
Hewlett-Packard Company  VLSI Technology Center - http://cpus.hp.com/
[EMAIL PROTECTED]            (970) 898-7881


Reply via email to