perl build module with c source from other module

118 views Asked by At

I am working on a module that I would like to have two backends, a Module(::PerlArray) and Module::PDL (which can will depend on Module). Both need access to a functions.c/.h file for building. This file has the rather complicated logic needed for the module. Rather than distribute it separately with each module, is there some way to keep it with the Module::PP on the system and then add it to the appropriate build flags in EU::MM or M::B (given the complexity here probably the latter)?

To put it more visually

--Module--
Module.pm
Module/PerlArray.pm
Module/PerlArray.xs (#include functions.h
              #include perlarray_backend.h)
Module/src/functions.c
Module/src/perlarray_backend.c
Module/inc/functions.h
Module/inc/perlarray_backend.h

--Module::PDL--
Module/PDL.pm
Module/PDL.xs (#include functions.h /*from Module*/
               #include pdl_backend.h)
Module/src/pdl_backend.c
Module/inc/pdl_backend.h

and the compilation makes functions.o and links. I'm sure I can figure out how to set the flags appropriately but how can I make Module keep the functions.c file while installing, and how can I then find it when installing Module::PDL? Is there some location I can place the functions.c/.h?

2

There are 2 answers

1
Jonathan Leffler On

Modules should be independently installable. That is, providing I have the pre-requisite Perl modules installed (but not necessarily still lying around in source form), then it should be possible to install all the modules in one distributed tar file without reference to the source for any other module.

You have options. One is to have a single source directory create several distributed tar balls, and they can each have a copy of the shared function.[ch] in the distributed source.

The other main option is to bundle both modules into a single distributed tar ball.

0
Tanktalus On

Have you looked at DBI? It does what you suggest: it installs some .h file(s) that the DBD drivers can #include in their XS code, as well as a library that the DBD drivers can call.