Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

ExtUtils::MakeMaker, Makefile.PL: modify existing targets like "all" (as in make all) or "install"

by bliako (Abbot)
on Sep 17, 2025 at 13:48 UTC ( [id://11166251]=perlquestion: print w/replies, xml ) Need Help??

bliako has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monkees,

I am using ExtUtils::MakeMaker for all of my projects just because it is how I started. I know how to create custom targets with it using the "postamble". Now I need to modify certain targets like all in order to add more tasks during making. For example, I have need to create special files before compilation, let's call this target translations (because it translates various strings to various languages and provides multilingual strings). This target should be called prior to whatever target all does. How do I achieve this?

Of course I can add a new target allall as

allall : translations all
But since my ability and will to remember special cases diminishes with time, I would prefer to always use standard targets.

bw, bliako

  • Comment on ExtUtils::MakeMaker, Makefile.PL: modify existing targets like "all" (as in make all) or "install"
  • Select or Download Code

Replies are listed 'Best First'.
Re: ExtUtils::MakeMaker, Makefile.PL: modify existing targets like "all" (as in make all) or "install"
by Corion (Patriarch) on Sep 17, 2025 at 14:08 UTC

    Looking through ExtUtils::MM_Unix, the all target is created by the method all_target, so you should be able to add to the all target by writing your own implementation in the MY namespace (in Makefile.PL):

    sub MY::all_target { my $self = shift; return <<'MAKE_EXT'; all :: pure_all translations manifypods $(NOECHO) $(NOOP) MAKE_EXT }

    Alternatively, you can actually use inheritance and then munge the result from the overloaded method:

    sub MY::all_target { my $self = shift; my $orig_all = $self->SUPER::all_target(); $orig_all =~ s/\bpure_all\b/pure_all translations/; return $orig_all }

      OK, but do I have to run the overwritten method explicitly? It seems to do nothing:

      use 5.006; use strict; use warnings; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( NAME => 'A::B', AUTHOR => q{ah <abc@abc.abc>}, VERSION_FROM => 'lib/A/B.pm', ABSTRACT_FROM => 'lib/A/B.pm', LICENSE => 'artistic_2', MIN_PERL_VERSION => '5.006', CONFIGURE_REQUIRES => { 'ExtUtils::MakeMaker' => '0', }, TEST_REQUIRES => { 'Test::More' => '0', }, PREREQ_PM => { #'ABC' => '1.6', #'Foo::Bar::Module' => '5.0401', }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'A-B-*' }, ); # Compatibility with old versions of ExtUtils::MakeMaker unless (eval { ExtUtils::MakeMaker->VERSION('6.64'); 1 }) { my $test_requires = delete $WriteMakefileArgs{TEST_REQUIRES} || {} +; @{$WriteMakefileArgs{PREREQ_PM}}{keys %$test_requires} = values %$ +test_requires; } unless (eval { ExtUtils::MakeMaker->VERSION('6.55_03'); 1 }) { my $build_requires = delete $WriteMakefileArgs{BUILD_REQUIRES} || +{}; @{$WriteMakefileArgs{PREREQ_PM}}{keys %$build_requires} = values % +$build_requires; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION('6.52'); 1 }; delete $WriteMakefileArgs{MIN_PERL_VERSION} unless eval { ExtUtils::MakeMaker->VERSION('6.48'); 1 }; delete $WriteMakefileArgs{LICENSE} unless eval { ExtUtils::MakeMaker->VERSION('6.31'); 1 }; WriteMakefile(%WriteMakefileArgs); sub MY::all_target { my $self = shift; die 123; return <<'MAKE_EXT'; all :: pure_all translations manifypods $(NOECHO) $(NOOP) MAKE_EXT }

      Also, no change if placed before WriteMakefile()

        Weird. I was going from Overriding MakeMaker Methods, where it claims that stuffing things into MY:: will make them override the rest.

        This is somewhat mildly corroborated by the EU:MM object hierarchy but I have to shamefully admit that I did not test this.

        You were supposed to subclass the ExtUtils::MakeMaker into the MY class, if I understand it correctly. Do I?

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: ExtUtils::MakeMaker, Makefile.PL: modify existing targets like "all" (as in make all) or "install"
by choroba (Cardinal) on Sep 17, 2025 at 14:16 UTC
    I'm not sure I understand the documentation correctly, but what about
    depend => {all => 'translations'},
    (unless all is given a double-colon rule.)
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      yes, I do not know who gave all a double-colon rule but it has one: *** target file 'all' has both : and :: entries.  Stop.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11166251]
Approved by choroba
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2025-12-04 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (83 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.