Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Maddingue (5320)

  (email not shown publicly)

Journal of Maddingue (5320)

Monday October 15, 2007
01:06 PM

Extending ExtUtils::MakeMaker

[ #34682 ]

Just sharing some code to extend ExtUtils::MakeMaker.

I wanted two things: 1. apply the PM_FILTER on the EXE_FILES as well, 2. install a file in /etc.

After reading the documentation, looking at EU::MM source and numerous tries-and-errors, I ended up with the following sub which is, I think, generic enough to be reused by others:

sub MY::postamble {
    my ($mm, %args) = @_;
    my $postamble = "";

    # apply the filter to the EXE_FILES as well
    for my $exe (@{ $mm->{EXE_FILES} }) {
        my $old_rule = '$(CP) '.$exe.' $(INST_SCRIPT)/'.$exe;
        my $new_rule = '$(PM_FILTER) <'.$exe.' >$(INST_SCRIPT)/'.$exe;

        for my $makeline (@{ $mm->{RESULT} }) {
            $makeline =~ s/\Q$old_rule/$new_rule/;

    # add testcover target if available
    $postamble .= eval {
        require ExtUtils::MakeMaker::Coverage;
    } || "";

    # install data files (in /etc, /usr/share, ...)
    # first, we must add a target in install::
    for my $makeline (@{ $mm->{RESULT} }) {
        $makeline =~ s/(install *::.+)\n/$1 priv_data_files\n/;

    # then, declare the target with the files
    $postamble .= "\nINSTALL = install -D -p\n\npriv_data_files:\n";

    for my $file (@{ $args{files} }) {
        $postamble .= "\t\$(INSTALL) $file /$file\n";

    return $postamble

The first code chunk is the part that applies the filter on the executables. I was afraid that replacing CP with the filter could have wrong consequences, so I have to read through the already rendered Makefile, stored in RESULT, in order to replace the good rules.

The second chunk manually add the testcover provided by Steve Peters' ExtUtils::MakeMaker::Coverage, as I'm redefining my own postamble().

The last chunk is the one that install generic data files. It expect files to have been passed to WriteMakefile() this way:

    postamble => { files => [ ... ] },

Unless I've missed something, such features are not directly available in EU::MM or in a CPAN module. Do you people think these could be useful as modules?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • This exchange from Soldier [] pretty much sums up my feelings when I see MakeMaker extensions.

    Sandra: You must *feel* something?
    Todd: [silence]
    Todd: Fear
    Sandra: Fear?
    Todd: Fear and discipline.
    Sandra: Now?
    Todd: Always.