[Module-build-general] EU::ModuleMaker patch
Status: Beta
Brought to you by:
kwilliams
|
From: Dave R. <au...@ur...> - 2003-03-15 09:33:47
|
Hi, Geoff, this patch adds support for Module::Build to EU::MM. Also, I'd like to suggest a new name for the module. The ExtUtils prefix is really for code designed to interface with external (non-Perl) utilities, like make or compilers. I think a better name would be Module::Maker or something like that. Also, you should talk to Hugo about putting this module in the core as a replacement for using h2xs for the same thing, because h2xs is not the right tool for this job. The patch is below my sig. -dave /*======================= House Absolute Consulting www.houseabsolute.com =======================*/ diff -ur ../ExtUtils-ModuleMaker-0.31229/lib/ExtUtils/ModuleMaker.pm ./lib/ExtUtils/ModuleMaker.pm --- ../ExtUtils-ModuleMaker-0.31229/lib/ExtUtils/ModuleMaker.pm 2003-02-15 12:08:26.000000000 -0600 +++ ./lib/ExtUtils/ModuleMaker.pm 2003-03-15 03:25:13.000000000 -0600 @@ -112,8 +112,7 @@ =item ABSTRACT -A short description of the module, this will be passed on to MakeMaker through Makefile.PL. -CPAN likes to use this feature to describe the module. +A short description of the module. CPAN likes to use this feature to describe the module. =item VERSION @@ -132,6 +131,17 @@ Some licenses include placeholders that will be replaced with AUTHOR information. +=item BUILD_SYSTEM + +This can take one of three values. These are 'ExtUtils::MakeMaker', +'Module::Build', and 'Module::Build and Proxy'. The first generates a +basic Makefile.PL file for your module. The second creates a Build.PL +file, and the last creates a Build.PL along with a proxy Makefile.PL +script that attempts to install Module::Build if necessary, and then +runs the Build.PL script. This option is recommended if you want to +use Module::Build as your build system. See Module::Build::Compat for +more details. + =item AUTHOR A hash containing information about the author to pass on to all the @@ -271,6 +281,7 @@ EMAIL => 'a.u.thor@a.galaxy.far.far.away', NAME => 'A. U. Thor', }, + BUILD_SYSTEM => 'ExtUtils::MakeMaker', COMPACT => 0, VERBOSE => 0, INTERACTIVE => 0, @@ -361,7 +372,15 @@ } #Makefile must be created after generate_pm_file which sets $self->{FILE} - $self->print_file ('Makefile.PL', $self->FileText_Makefile ()); + if ($self->{BUILD_SYSTEM} eq 'ExtUtils::MakeMaker') { + $self->print_file ('Makefile.PL', $self->FileText_Makefile ()); + } else { + $self->print_file ('Build.PL', $self->FileText_Buildfile ()); + if ($self->{BUILD_SYSTEM} eq 'Module::Build and proxy Makefile.PL') { + $self->print_file ('Makefile.PL', $self->FileText_Proxy_Makefile ()); + } + } + $self->print_file ('MANIFEST', join ("\n", @{$self->{MANIFEST}})); } @@ -417,13 +436,13 @@ =head2 sample_function - Usage : How to use this function/method + Usage : How to use this function/method Purpose : What it does Returns : What it returns Argument : What it wants to know - Throws : Exceptions and other anomolies + Throws : Exceptions and other anomolies Comments : This is a sample subroutine header. - : It is polite to include more pod and fewer comments. + : It is polite to include more pod and fewer comments. See Also : @@ -459,14 +478,14 @@ =head2 Create_Base_Directory - Usage : + Usage : Purpose : - Create the directory where all the files will be created. + Create the directory where all the files will be created. Returns : - $DIR = directory name where the files will live + $DIR = directory name where the files will live Argument : - $package_name = name of module separated by '::' - Throws : + $package_name = name of module separated by '::' + Throws : Comments : See Also : Check_Dir @@ -962,6 +981,23 @@ { my ($self) = @_; +my $build_instructions; +if ($self->{BUILD_SYSTEM} eq 'ExtUtils::MakeMaker') { +$build_instructions = <<EOF; +perl Makefile.PL +make +make test +make install +EOF +} else { +$build_instructions = <<EOF; +perl Build.PL +./Build +./Build test +./Build install +EOF +} + my $page = <<EOF; pod2text $self->{NAME}.pm > README @@ -972,10 +1008,7 @@ At the very least you should be able to use this set of instructions to install the module... -perl Makefile.PL -make -make test -make install +$build_instructions If you are on a windows box you should use 'nmake' rather than 'make'. EOF @@ -1101,6 +1134,106 @@ ################################################ subroutine header begin ## +=head2 FileText_Buildfile + + Usage : $self->FileText_Buildfile () + Purpose : Build a supporting file + Returns : Text of the file being built + Argument : n/a + Throws : n/a + Comments : This method is a likely candidate for alteration in a subclass + +See Also : + +=cut + +################################################## subroutine header end ## + +sub FileText_Buildfile +{ + my ($self) = @_; + + # As of 0.15, Module::Build only allows a few licenses + my $license_line = 1 if $self->{LICENSE} =~ /^(?:perl|gpl|artistic)$/; + +my $page = <<EOF; +use Module::Build; +# See perldoc Module::Build for details of how this works + +Module::Build->new + ( module_name => '$self->{NAME}', +EOF + if ($license_line) { +$page .= <<EOF; + license => '$self->{LICENSE}', +EOF + } + +$page .= <<EOF; + )->create_build_script; +EOF + + return ($page); + +} + +################################################ subroutine header begin ## + +=head2 FileText_Proxy_Makefile + + Usage : $self->FileText_Proxy_Makefile () + Purpose : Build a supporting file + Returns : Text of the file being built + Argument : n/a + Throws : n/a + Comments : This method is a likely candidate for alteration in a subclass + +See Also : + +=cut + +################################################## subroutine header end ## + +sub FileText_Proxy_Makefile +{ + my ($self) = @_; + +# This comes directly from the docs for Module::Build::Compat +my $page = <<'EOF'; +unless (eval "use Module::Build::Compat 0.02; 1" ) { + print "This module requires Module::Build to install itself.\n"; + + require ExtUtils::MakeMaker; + my $yn = ExtUtils::MakeMaker::prompt + (' Install Module::Build from CPAN?', 'y'); + + if ($yn =~ /^y/i) { + require Cwd; + require File::Spec; + require CPAN; + + # Save this 'cause CPAN will chdir all over the place. + my $cwd = Cwd::cwd(); + my $makefile = File::Spec->rel2abs($0); + + CPAN::Shell->install('Module::Build::Compat'); + + chdir $cwd or die "Cannot chdir() back to $cwd: $!"; + exec $^X, $makefile, @ARGV; # Redo now that we have Module::Build + } else { + warn " *** Cannot install without Module::Build. Exiting ...\n"; + exit 1; + } +} +Module::Build::Compat->run_build_pl(args => \@ARGV); +Module::Build::Compat->write_makefile(); +EOF + + return ($page); +} + +################################################ subroutine header begin ## + =head2 FileText_Test Usage : $self->FileText_Test () diff -ur ../ExtUtils-ModuleMaker-0.31229/scripts/modulemaker ./scripts/modulemaker --- ../ExtUtils-ModuleMaker-0.31229/scripts/modulemaker 2003-02-15 12:08:26.000000000 -0600 +++ ./scripts/modulemaker 2003-03-15 03:29:21.000000000 -0600 @@ -39,6 +39,7 @@ my $string = $messages{'Main Menu'}; $string =~ s|##name##|$MOD->{NAME}|; $string =~ s|##license##|$MOD->{LICENSE}|; + $string =~ s|##build##|$MOD->{BUILD_SYSTEM}|; my $response = Question_User ($string, 'menu'); @@ -167,6 +168,32 @@ return ('License Menu'); } + +################################################ subroutine header begin ## +################################################## subroutine header end ## + +my %Build_Menu = ( + E => 'ExtUtils::MakeMaker', + B => 'Module::Build', + P => 'Module::Build and proxy Makefile.PL', + ); + +sub Build_Menu +{ + my $MOD = shift; + + my $string = $messages{Build_Menu}; + $string =~ s|##Build Here##|$MOD->{BUILD_SYSTEM}|; + + my $response = Question_User ($string, 'menu'); + return ($destinations{'Build Menu'}{$response}) if (exists $destinations{'Build Menu'}{$response}); + + $MOD->{BUILD_SYSTEM} = $Build_Menu{$response} if exists $Build_Menu{$response}; + + return ('Build Menu'); +} + + ################################################ subroutine header begin ## ################################################## subroutine header end ## @@ -269,6 +296,7 @@ -l Specify a license for this extension. -n Specify a name to use for the extension (required). -v Specify a version number for this extension. + -b Specify a build system for this extension. -P Omit the stub POD section. -C Omit creating the Changes file, add HISTORY heading to stub POD. -I Disable INTERACTIVE mode, the command line arguments better be complete @@ -296,6 +324,7 @@ A => 'Author Menu', L => 'License Menu', D => 'Directives_Menu', + B => 'Build Menu', Q => 'done', }, 'Author Menu' => { @@ -313,6 +342,11 @@ Q => 'done', P => 'License Menu', }, + + 'Build Menu' => { + R => 'Main Menu', + Q => 'done', + }, ); ########################################################################### @@ -330,6 +364,7 @@ A - Author information L - License '##license##' D - Directives +B - Build system '##build##' G - Generate module Q - Quit program @@ -412,12 +447,27 @@ EOF #--------------------------------------------------------------------- + + Build_Menu => <<EOF, +Here is the current build system: + +##Build Here## + +E - ExtUtils::MakeMaker +B - Module::Build +P - Module::Build and proxy Makefile.PL +R - Return to main menu + +Please choose which build system you would like to use: +EOF + + #--------------------------------------------------------------------- ); ########################################################################### ########################################################################### -getopts ("dhCIPVcn:v:l:", \%opts); +getopts ("bdhCIPVcn:v:l:", \%opts); die Usage () if ($opts{h}); my $where = 'Main Menu'; @@ -425,6 +475,8 @@ ( NAME => $opts{n}, + (($opts{b}) ? (BUILD_SYSTEM => $opts{b}) : ()), + COMPACT => (($opts{c}) ? 1 : 0), VERBOSE => (($opts{V}) ? 1 : 0), CHANGES_IN_POD => (($opts{C}) ? 1 : 0), @@ -457,6 +509,8 @@ $where = Copyright_Display ($MOD); } elsif ($where eq 'Directives_Menu') { $where = Directives_Menu ($MOD); + } elsif ($where eq 'Build Menu') { + $where = Build_Menu ($MOD); } else { $where = Main_Menu ($MOD); } |