Re: [Module-build-general] A better passthrough Makefile.PL
Status: Beta
Brought to you by:
kwilliams
|
From: Ken W. <ke...@ma...> - 2002-11-01 05:11:24
|
On Thursday, October 3, 2002, at 06:54 PM, Dave Rolsky wrote:
> I wanted to create a Makefile.PL that would pass all functionality
> through
> to Module::Build, _and_ that would make sure that Module::Build got
> installed if necessary. I also wanted to make sure that the user did
> not
> have to run "perl Makefile.PL" twice, once for installing Module::Build,
> and once to install the desired module. Having to do this basically
> makes
> the install fail with CPAN or CPANPLUS.
>
> Here's what I came up with:
>
>
> use Cwd;
> use File::Spec;
>
> unless (eval { require Module::Build::Compat; 1 }) {
> require ExtUtils::MakeMaker;
>
> print "This module required Module::Build to install itself.\n";
>
> my $yn = ExtUtils::MakeMaker::prompt( ' Install Module::Build',
> 'y' );
>
> if ($yn =~ /^y(es)?/i) {
> # save this cause CPAN will chdir all over the place.
> my $cwd = cwd();
> my $makefile = File::Spec->rel2abs($0);
>
> require CPAN;
> CPAN->install('Module::Build');
>
> chdir $cwd
> or die "Cannot chdir to $cwd: $!";
>
> exec( $^X, $makefile, @ARGV )
> } else {
> warn "Cannot install Thesaurus without Module::Build. Exiting
> ...\n";
> exit 0;
> }
> }
>
> require Module::Build::Compat;
> Module::Build::Compat->run_build_pl( args => \@args );
> Module::Build::Compat->write_makefile;
I think this is a decent change. Autrijus, I think it's better to use
ExtUtils::MakeMaker here than ExtUtils::AutoInstall, simply because the
user will have the former but probably not the latter.
Actually, I just had an idea - would the following small change work
(note the 'touch' line, "open $0")?
unless (eval "use Module::Build::Compat 0.02; 1" ) {
# Workaround with old CPAN.pm and CPANPLUS.pm
require ExtUtils::MakeMaker;
ExtUtils::MakeMaker::WriteMakefile(
PREREQ_PM => { 'Module::Build::Compat' => 0.02 }
);
warn "Warning: prerequisite Module::Build::Compat is not found.\n";
sleep 2; # Wait a couple seconds after writing Makefile
open my($fh), ">> $0" # Change modification date
or warn "You may have to run 'perl Makefile.PL' again.";
exit(0);
}
Module::Build::Compat->run_build_pl(args => \@ARGV);
Module::Build::Compat->write_makefile();
The idea is that it changes the modification time for Makefile.PL to be
after the Makefile's, so that Makefile.PL gets re-run. This is kind of
tough to test out - Dave, how did you test this before?
-Ken
|