eyepopslikeamosquito has asked for the wisdom of the Perl Monks concerning the following question:

By default, Compress::Zlib builds exactly the way I want. By bundling the zlib C library, the normal:

perl Makefile.PL make make test make install

just works and the resulting Zlib.so (Zlib.dll on Windows) contains the zlib C code -- and so is independent of any zlib library that happens to be installed on the target system, works even if zlib is not installed on the target system, and can be installed without requiring root permissions.

I'd like to do the same thing with XML::Parser (and its companion C expat library) but, being a MakeMaker novice, I'm struggling.

I started by installing the expat C library. I then installed XML::Parser with:

perl Makefile.PL EXPATLIBPATH=/usr/local/lib EXPATINCPATH=/usr/local/i +nclude make make test make install
All tests passed. So far, so good. Now, as a test, I removed the expat C library from /usr/local/lib and XML::Parser failed on AIX and Solaris. Curiously, it continued to work fine on Linux.

What I want is to ensure the expat C code gets stuffed into Expat.so (just as the zlib C code gets stuffed into Zlib.so). I was able to achieve that by crudely changing this section of code in Expat/Makefile.PL:

WriteMakefile( NAME => 'XML::Parser::Expat', C => ['Expat.c'], LIBS => $libs, XSPROTOARG => '-noprototypes', VERSION_FROM => 'Expat.pm', @extras );
from:
LIBS => $libs,
to:
OBJECT => "Expat.o /usr/local/lib/libexpat.a",
Anyone know a better way to do it?

Replies are listed 'Best First'.
Re: Building XML::Parser and expat standalone
by PodMaster (Abbot) on Feb 17, 2005 at 07:20 UTC
    ..and the resulting Zlib.so (Zlib.dll on Windows) contains the zlib C code ...
    There is no c code in there :) What happens is that libzlib is compiled "statically", which is what you need to do with libexpat.

    update: You can also copy libexpat.$Config{dlext} to blib/arch/auto/XML/Parser/Expat/ so that it gets installed alongside Expat.$Config{dlext} upon make install. When loading Expat.dll, the OS should look for libexpat.dll there first (auto/XML/Parser/Expat/).

    Or you can also put libexpat.dll in $Config{installsitebin}, which works fine for win32, but may not for other platforms.

    update:  perl -V:obj_ext

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.