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

First off, I'm a make/build newbie with only basic experience in the area, so if some of this is obvious I apologize. I have tried to search here prior to asking and have read into MakeMaker and Module::Build documentation.

I have a project made of multiple modules. I'd like them all to be build from the upper most make/build file, but I haven't been able to figure out how to do that.

I've used ExtUtils::ModuleMaker to create the initial project skeleton. I've also checked out h2xs. I've noticed they create the base directory structure differently.

For example, assume I'm working on a module Foo, and a module Foo::Bar required by Foo all located in my 'project' directory. If I use h2xs to start both modules, I end up with a project/Foo/ directory and a project/Foo-Bar/ directory that are independent of each other. Modulemaker on the other hand creates a project/Foo/ directory (containing Changes, MANIFEST, t, lib, etc) and then a project/Foo/Bar directory (also with its own t, lib, etc.)for the second module, tying the second module into the first. Is one of these preferred over the other? The modules are being co-developed and Foo must have Foo::Bar to work.

Next question: I would like to build both modules from the uppermost Foo build file as Foo::Bar is really just a sub part of that module. I've checked out MakeMaker and Module::Build documentation, and I can see how to declare the Foo::Bar module as a prereq, but not how to actually tell it to go build the other module.

So from a methodology standpoint, should I have one make file for Foo that handles both modules; two make files with the Foo makefile executing the Foo::Bar makefile; or two completely independent files that must both be make, test, installed? The second seems like the right way to do it.

Finally, how do you ensure the Foo::Bar makefile is executed from the Foo makefile? I'd be interested in how this is done from a Makefile.PL as well as a Build.PL file.

Replies are listed 'Best First'.
Re: Building a multi module project
by Corion (Patriarch) on Jan 21, 2011 at 19:25 UTC

    Personally, I would keep Foo.pm and Foo/Bar.pm in the same distribution, if they are so closely tied together. I like to put my modules into a lib directory, so I'd have lib/Foo.pm and lib/Foo/Bar.pm.

    For building/installing a distribution and its prerequisites, it pays off to have a Makefile.PL even for your internal distributions, because then cpan . or cpanm . Just Works and will install the prerequisites listed in this local Makefile.PL for you (as long as they are on CPAN or CPAN::Mini).

      I think the lightbulb clicked on. I was thinking that every module needed its own makefile. In reality, the distribution needs a makefile and all modules in that distribution will be in the distribution's lib directory. That makes a lot of sense. Thanks for the reply :)
Re: Building a multi module project
by tj_thompson (Monk) on Jan 21, 2011 at 19:27 UTC
    Or is the proper way to do it to create the base project/Foo directory, then add Bar.pm to this module as project/Foo/lib/Foo/Bar.pm and add it to the Foo module's MANIFEST? In this case the Bar.pm file could be found during build of Foo.pm and I can still put tests for Foo::Bar into project/Foo/t/. In addition, the files would be installed correctly as well since they are part of Foo.