On Thu, Apr 8, 2010 at 7:31 PM, Bill Moseley <[email protected]> wrote:
> At times we must make do with what we have:
> I'm working with a team of C++ programmers. To provide Perl access to their
> code they are using SWIG, which produces a .pm and a (big fat) .so file.
> The question is how to turn this into a distribution that can be installed
> in the correct place.
> Target platform is all the same so no real concern about portability at this
> time (famous last words). We can just copy into @INC I suppose, although
> the plan is to use cpan2rpm so really would like a distribution (with a
> Makefile.PL).
>
> I've always used XS before that builds a "real" distribution where the .xs
> is compiled and linked at build time and MakeMaker figures out where to
> install. But, that's just not what I have, unfortunately.
> To get by could I just make a normal distribution and add in the .so file
> into the lib directory? Then let MakeMaker install? That seems ugly (not
> to mention platform dependent).
> Any other suggestions how to package up these so they can be installed in a
> normal "make install" for a stop-gap measure for now?
> My suggestion is to move to autoconf to build libraries and use thin XS
> wrappers, but that's a bigger project than anyone is willing to take on
> right now.
> BTW -- poking around Google there seems to be debate about SWIG vs. XS (and
> Inline), and often it seems like SWIG is preferred. Hard to believe since
> it makes such odd code with werid naming (use "foo"; $foo = foo::Foo->new)
> and sub TIEHASH.
>
> --
> Bill Moseley
> [email protected]
>
I used swig in making up Math-Cephes:
http://cpansearch.perl.org/src/RKOBES/Math-Cephes-0.47/
In a nutshell, I placed the "wrapper" file Cephes_wrap.c that swig
generates at the top-level, and all the .c and .h files used to build
the C library under the libmd/ directory. The top-level Makefile.PL
had attributes like
NAME => 'Math::Cephes',
MYEXTLIB => "$libmd/libmd\$(LIB_EXT)",
VERSION_FROM => 'lib/Math/Cephes.pm',
OBJECT => 'Cephes_wrap.o arrays.o',
INC => "-I$libmd",
where arrays.c was a self-made .c helper file and $libmd = catdir
$cwd, 'libmd'). Under libmd/ was a Makefile.PL that built the libmd
library via attributes like
NAME => 'Math::Cephes::libmd',
VERSION_FROM => '../lib/Math/Cephes.pm', # finds $VERSION
OBJECT => join(' ', @objs),
SKIP => [ qw( dynamic test ) ] ,
LINKTYPE => 'static',
clean => {FILES => 'libmd$(LIB_EXT)'}
where the object files were found from
opendir(DIR, '.') or die "Cannot opendir '.': $!\n";
my @objs = map {s/\.c$/.o/; $_} grep { /\.c$/ } readdir DIR;
closedir DIR;
This turned out to be a fairly portable solution across different platforms.
--
best regards,
Randy