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

Hey Dudes,

I have a couple of deeply nested (directory wise and namespace) XS files that I want to include in an already long developed perl module. h2xs is not my friend in this case as it tends to like creating new files...

(names have been changed for simplification)

The XS file (which has all of the c code in it) has a name of lib/MyModule/Drv/MyCode.xs and contain the lines

MODULE = MyModule::Drv::MyCode PACKAGE = MyModule::Drv::MyCode PROTOTYPES: DISABLE

and the rest of the normal code.

My corosponding lib/MyModule/Drv/MyCode.pm contains

package MyModule::Drv::MyCode; use strict; use Carp; use vars qw($VERSION @ISA @EXPORT); require DynaLoader; @ISA = qw(DynaLoader); $VERSION = '0.1'; bootstrap MyModule::Drv::MyCode $VERSION;
and the rest of the normal code.

My MANIFEST file in the root directory contains

lib/Device/ParallelPort/drv/linux.pm lib/Device/ParallelPort/drv/linux.xs
amoung other lines Finally my Makefile.PL complete, looks like this:
use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'MyModule', 'VERSION_FROM' => 'lib/MyModule.pm', 'LIBS' => [''], 'DEFINE' => $dflags, 'INC' => '', );
I have tried varying things like adding
'XS' => { 'lib/MyModule/Drv/MyCode.xs' => 'lib/MyModule/Drv/MyCode.c', },
The problem is that the resulting Makefile from "perl Makefile.PL" does not compile my .xs file. Sometimes (depending on the many tests I have tried) it compiles MyModule.xs - which does not exist.

I can only get it to work if the .xs file is in the root directory.

Does anyone have any idea how I can fix this.

Much Appreciated in advance :-)

Scott

Replies are listed 'Best First'.
Using h2xs
by scottp (Initiate) on May 01, 2002 at 00:39 UTC
    If I use h2xs to generate a file (see below)
    $ h2xs lib/MyModule/Drv/MyCode.h Writing MyCode/MyCode.pm Writing MyCode/MyCode.xs Writing MyCode/Makefile.PL Writing MyCode/README Writing MyCode/test.pl Writing MyCode/Changes Writing MyCode/MANIFEST
    What I require is a Makefile.PL, README, MANIFEST etc into the current directory I am in, and to put the .xs file in the lib/MyModule/Drv/MyCode.h.

    As I mentioned before this is because the directory I am in is an already existing perl module that has been worked on for a while, I am just trying to add a single XS file to it.

    Taking the results of this and hacking it into my existing Makefile.PL does not seem to work. It seems that ExtUtils::MakeMaker only wants to make Makefiles that build .xs files if they are in the same directory.

    Ahhh... Still stuck :-(

Re: XS compile in Makefile.PL
by ferrency (Deacon) on Apr 30, 2002 at 20:55 UTC
    If the only reason you're not using h2xs is because it creates new files (blowing away the ones you already have), then the solution might be easy. Copy your .xs, etc. files into a new, safe location, and run h2xs on them there, to generate a sample Makefile.PL. Then steal the clues from that Makefile.PL, and paste them into your hand-built Makefile.PL.

    Of course, I say this not understanding your file/directory structure: it may be too complicated to get completely useful results. But perhaps you could pull out just enough of your code to give h2xs the clues it needs to help you?

    Alan