Last Updated: February 25, 2016
·
950
· colinkeith

Creating a Custom Makefile.PL with Perl's Dist::Zilla

Dist::Zilla automatically creates most of the standard files needed in a Perl distribution. However in some situations you may need a custom Makefile.PL. The most common use-case is when writing XS modules when you need to link against a specific library.

To help you with this there are a number of D:Z:P::MakeMaker::* modules.

One module that lets you easily manage INC and LIBS is Dist::Zilla::Plugin::MakeMaker::Awesome. You manipulate the contents of Makefile.PL using a module that you write yourself. Most of which is boiler-plate.

For example here is my tweak for INC and LIBS to link against libssl and libcrypto. I've simplified to code to have static values for INC and LIBS;

package inc::Your::Module::Name;
use Moose;

extends 'Dist::Zilla::Plugin::MakeMaker::Awesome';

override _build_WriteMakefile_args => sub {
  my $LIBS = '-L/usr/local/openssl/lib -lssl -lcrypto';
  my $INC = '-I/usr/local/include/openssl';

  +{
    %{super()},
    LIBS => $LIBS,
    INC  => $INC,
  };
};

__PACKAGE__->meta->make_immutable;

Only the lines with $LIBS or $INC are not boiler-plate, so you can see that it is pretty easy. As it is not part of the distribution it is placed into the inc/ directory. Then you change the dist.ini to exclude the MakeMaker plugin from the @Basic plugin bundle and load your module:

dist.ini example for custom MakeFile.PL generator

name = your-module-name
author = your name <you@example.com>
license = Artistic_2_0
version = 0.04

[Prereqs]
My::Module = 0

[@Filter]
-bundle = @Basic
-remove = License
-remove = MakeMaker

[=inc::Your::Module::Name]

1 Response
Add your response

Could you explain a little more how the custom ini works? What does that least header do?

over 1 year ago ·