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

Hi, I'm trying to learn about module installation with Makefile.pl. As a matter of fact, I'm trying to install more than a module, as I want to ship along a config file as well, to go in $PREFIX/etc/my_config.

I can't seem to find a way to do that. In the manifest, I can get it included in the distribution tarball, but how to make "make install" put my_config in /etc seems hard. "make install" only seems to install perl modules and their doc files.

Any advice, wise and generous perl monks?

Replies are listed 'Best First'.
Re: Install "other files" with Makefile.pl
by DrHyde (Prior) on May 10, 2011 at 10:06 UTC

    You can install scripts using WriteMakefile's EXE_FILES option.

    To install anything else, you'll need to override ExtUtils::MakeMaker methods. See here, but beware that this gets really really ugly. I prefer to embed data in modules - for example, Number::Phone::UK::Data has an embedded DBM::Deep database. If you'd rather not do that, then I suggest using Module::Build and its add_build_element method.

Re: Install "other files" with Makefile.pl
by Anonymous Monk on May 10, 2011 at 10:12 UTC
    In Makefile.PL use File::ShareDir::Install, in your module/program use File::ShareDir to locate the default config file, File::HomeDir for user config overrides ...

    If you want a ExtUtils::MakeMaker generated file to install something in /etc, you have to write a "postamble" (in make syntax)

    FWIW, I haven't seen any CPAN modules that write in /etc, and AFAIK, that is best left to administrators

      Thank you both for your suggestions. I have tried to look into the options presented, but as they involve somewhat complicated changes, I will need to spend a good deal of time on this to understand it and do it correctly.

      I actually have not only the config file, but also a directory of data files that I would like to have installed along with the modules. I am hoping to find a way to do that too, and perhaps I can by following your advice above.

      Naively, I hoped I could somehow write a piece of Makefile somewhere, with just this in it, and get it executed by some general install-hook:

      install: cp -r data/ $PREFIX/share/my-data
Re: Install "other files" with Makefile.pl
by danb (Friar) on May 10, 2011 at 18:39 UTC
    I used MY::postamble to do that with Business::Shipping (a CPAN module), and I asked the user where they wanted to put it (default of /usr/local/<module>/). But now I think it's better to just put the configuration in a .pm file using __DATA__ and install it like everything else.

    --Daniel