DEV Community

Yuki Kimoto
Yuki Kimoto

Posted on

2 1

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.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (1)

Collapse
 
jonasbn profile image
Jonas Brømsø •

Thanks for sharing

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More