Since I use Dist::Zilla to help manage my Perl distributions, I wanted to use it with the XS package that I am working on. This post is just a small note how how to do that if you are using Alien::Base to build your native library.

Dist::Zilla usually writes it's own Makefile.PL so that ExtUtils::MakeMaker will know how to build, test, and install the code. However, since I'm using Alien::Base, I need to pass the compiler and linker flags to ExtUtils::MakeMaker as well. To do that, I grabbed the Dist::Zilla::Plugin::MakeMaker::Awesome plugin. Setting that up in your dist.ini is relatively straightforward:

Posted Sun 28 Sep 2014 06:55:29 PM UTC

The line [=inc::MyLibMakeMaker] specifies that the code that will be used to generate the Makefile.PL will be in a module called inc/MyLibMakeMaker.pm. Now, in that file, I'll need to specify the compilation flags by calling the cflags and libs methods on my Alien::Base subclass (Alien::MyLib). But this needs to happen when Makefile.PL is run by the user, not when Dist::Zilla writes out the file. The following code does that by appending our own options to the string we write out to in Makefile.PL.

Posted Sun 28 Sep 2014 06:55:29 PM UTC

We use the CONFIGURE option to set CCFLAGS and LIBS instead of setting CCFLAGS and LIBS directly because these need to be set after the Alien::MyLib prerequisite has been met.