DEV Community

Yuki Kimoto
Yuki Kimoto

Posted on

How to customize Makefile created by ExtUtils::MakeMaker

How to customize Makefile created by ExtUtils::MakeMaker?

The answer is to define a "My::postamble" subroutine that return added the content of the Makefile.

See current SPVM Makefile.PL.

dynamic section is used if you want to do something just after the default process of "make"

sub MY::postamble {

  # The content of Makefile
  my $make_rule = '';

  # Compile native and precompile codes of standard modules
  unless (grep { $_ eq '-DSPVM_DONT_COMPILE_CORE_MODULES' } @defines) {
    # Native compile make rule
    $make_rule .= SPVM::Builder::Util::create_make_rule_native('Fn');
    $make_rule .= SPVM::Builder::Util::create_make_rule_native('Hash');
    $make_rule .= SPVM::Builder::Util::create_make_rule_native('Time');
    $make_rule .= SPVM::Builder::Util::create_make_rule_native('Unicode');

    # Precompile make rule
    $make_rule .= SPVM::Builder::Util::create_make_rule_precompile('Fn');
    $make_rule .= SPVM::Builder::Util::create_make_rule_precompile('List');
    $make_rule .= SPVM::Builder::Util::create_make_rule_precompile('ByteList');
    $make_rule .= SPVM::Builder::Util::create_make_rule_precompile('ShortList');
    $make_rule .= SPVM::Builder::Util::create_make_rule_precompile('IntList');
    $make_rule .= SPVM::Builder::Util::create_make_rule_precompile('LongList');
    $make_rule .= SPVM::Builder::Util::create_make_rule_precompile('FloatList');
    $make_rule .= SPVM::Builder::Util::create_make_rule_precompile('DoubleList');
    $make_rule .= SPVM::Builder::Util::create_make_rule_precompile('StringList');
    $make_rule .= SPVM::Builder::Util::create_make_rule_precompile('StringBuffer');
    $make_rule .= SPVM::Builder::Util::create_make_rule_precompile('Hash');
    $make_rule .= SPVM::Builder::Util::create_make_rule_precompile('Unicode');
    $make_rule .= SPVM::Builder::Util::create_make_rule_precompile('Regex');
  }

  # Create precompile tests
  my @test_files;
  find(
    sub {
      if (-f $File::Find::name) {
        my $rel_path = $File::Find::name;
        $rel_path =~ s|^\Q$FindBin::Bin/||;
        if ($rel_path =~ /(\.t|\.pm|\.spvm|\.c|\.cpp|\.h)$/) {
          push @test_files, $rel_path;
        }
      }
    },
    "$FindBin::Bin/t/default"
  );
  my $test_files_str = join(' ', @test_files);
  $make_rule .= "dynamic :: $test_files_str\n";
  $make_rule .= "\tperl t/copy_default_to_precompile.pl\n";

  return $make_rule;
}

1;
Enter fullscreen mode Exit fullscreen mode

In case of other useful modules such as Dist::Zilla, I don't know the way. If you know it, write the comments.

Top comments (1)

Collapse
 
jonasbn profile image
Jonas Brømsø

Thanks for sharing