1 package Module::Install::Makefile;
4 use Module::Install::Base;
5 use ExtUtils::MakeMaker ();
7 use vars qw{$VERSION $ISCORE @ISA};
11 @ISA = qw{Module::Install::Base};
14 sub Makefile { $_[0] }
21 # Infinite loop protection
23 if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) {
24 die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])";
27 # In automated testing, always use defaults
28 if ( $ENV{AUTOMATED_TESTING} and ! $ENV{PERL_MM_USE_DEFAULT} ) {
29 local $ENV{PERL_MM_USE_DEFAULT} = 1;
30 goto &ExtUtils::MakeMaker::prompt;
32 goto &ExtUtils::MakeMaker::prompt;
38 my $args = ($self->{makemaker_args} ||= {});
39 %$args = ( %$args, @_ ) if @_;
43 # For mm args that take multiple space-seperated args,
44 # append an argument to the current list.
45 sub makemaker_append {
48 my $args = $self->makemaker_args;
49 $args->{name} = defined $args->{$name}
50 ? join( ' ', $args->{name}, @_ )
56 my $subdirs = $self->makemaker_args->{DIR} ||= [];
58 push @$subdirs, $subdir;
64 my $clean = $self->makemaker_args->{clean} ||= {};
67 FILES => join ' ', grep { length $_ } ($clean->{FILES} || (), @_),
73 my $realclean = $self->makemaker_args->{realclean} ||= {};
76 FILES => join ' ', grep { length $_ } ($realclean->{FILES} || (), @_),
82 my $libs = ref $_[0] ? shift : [ shift ];
83 $self->makemaker_args( LIBS => $libs );
88 $self->makemaker_args( INC => shift );
94 /\.t$/ and -f $_ and $test_dir{$File::Find::dir} = 1;
100 die "tests_recursive will not work if tests are already defined";
102 my $dir = shift || 't';
104 die "tests_recursive dir '$dir' does not exist";
108 File::Find::find( \&_wanted_t, $dir );
109 $self->tests( join ' ', map { "$_/*.t" } sort keys %test_dir );
114 die "&Makefile->write() takes no arguments\n" if @_;
116 # Make sure we have a new enough
117 require ExtUtils::MakeMaker;
118 $self->configure_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION );
121 my $args = $self->makemaker_args;
122 $args->{DISTNAME} = $self->name;
123 $args->{NAME} = $self->module_name || $self->name;
124 $args->{VERSION} = $self->version;
125 $args->{NAME} =~ s/-/::/g;
126 if ( $self->tests ) {
127 $args->{test} = { TESTS => $self->tests };
130 $args->{ABSTRACT} = $self->abstract;
131 $args->{AUTHOR} = $self->author;
133 if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) {
134 $args->{NO_META} = 1;
136 if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) {
139 unless ( $self->is_admin ) {
140 delete $args->{SIGN};
143 # merge both kinds of requires into prereq_pm
144 my $prereq = ($args->{PREREQ_PM} ||= {});
145 %$prereq = ( %$prereq,
149 ($self->configure_requires, $self->build_requires, $self->requires)
152 # Remove any reference to perl, PREREQ_PM doesn't support it
153 delete $args->{PREREQ_PM}->{perl};
155 # merge both kinds of requires into prereq_pm
156 my $subdirs = ($args->{DIR} ||= []);
157 if ($self->bundles) {
158 foreach my $bundle (@{ $self->bundles }) {
159 my ($file, $dir) = @$bundle;
160 push @$subdirs, $dir if -d $dir;
161 delete $prereq->{$file};
165 if ( my $perl_version = $self->perl_version ) {
166 eval "use $perl_version; 1"
167 or die "ERROR: perl: Version $] is installed, "
168 . "but we need version >= $perl_version";
171 $args->{INSTALLDIRS} = $self->installdirs;
173 my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args;
175 my $user_preop = delete $args{dist}->{PREOP};
176 if (my $preop = $self->admin->preop($user_preop)) {
177 $args{dist} = $preop;
180 my $mm = ExtUtils::MakeMaker::WriteMakefile(%args);
181 $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile');
184 sub fix_up_makefile {
186 my $makefile_name = shift;
187 my $top_class = ref($self->_top) || '';
188 my $top_version = $self->_top->VERSION || '';
190 my $preamble = $self->preamble
191 ? "# Preamble by $top_class $top_version\n"
194 my $postamble = "# Postamble by $top_class $top_version\n"
195 . ($self->postamble || '');
198 open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
199 my $makefile = do { local $/; <MAKEFILE> };
200 close MAKEFILE or die $!;
202 $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /;
203 $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g;
204 $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g;
205 $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m;
206 $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m;
208 # Module::Install will never be used to build the Core Perl
209 # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks
210 # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist
211 $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m;
212 #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m;
214 # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well.
215 $makefile =~ s/(\"?)-I\$\(PERL_LIB\)\1//g;
217 # XXX - This is currently unused; not sure if it breaks other MM-users
218 # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg;
220 open MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
221 print MAKEFILE "$preamble$makefile$postamble" or die $!;
222 close MAKEFILE or die $!;
228 my ($self, $text) = @_;
229 $self->{preamble} = $text . $self->{preamble} if defined $text;
234 my ($self, $text) = @_;
235 $self->{postamble} ||= $self->admin->postamble;
236 $self->{postamble} .= $text if defined $text;
248 Module::Install::MakeMaker - Extension Rules for ExtUtils::MakeMaker
252 In your F<Makefile.PL>:
254 use inc::Module::Install;
259 This module is a wrapper around B<ExtUtils::MakeMaker>. It exports
260 two functions: C<prompt> (an alias for C<ExtUtils::MakeMaker::prompt>)
261 and C<WriteMakefile>.
263 The C<WriteMakefile> function will pass on keyword/value pair functions
264 to C<ExtUtils::MakeMaker::WriteMakefile>. The required parameters
265 C<NAME> and C<VERSION> (or C<VERSION_FROM>) are not necessary if
266 it can find them unambiguously in your code.
268 =head1 CONFIGURATION OPTIONS
270 This module also adds some Configuration parameters of its own:
274 The NAME parameter is required by B<ExtUtils::MakeMaker>. If you have a
275 single module in your distribution, or if the module name indicated by
276 the current directory exists under F<lib/>, this module will use the
277 guessed package name as the default.
279 If this module can't find a default for C<NAME> it will ask you to specify
284 B<ExtUtils::MakeMaker> requires either the C<VERSION> or C<VERSION_FROM>
285 parameter. If this module can guess the package's C<NAME>, it will attempt
286 to parse the C<VERSION> from it.
288 If this module can't find a default for C<VERSION> it will ask you to
293 B<ExtUtils::MakeMaker> provides you with many useful C<make> targets. A
294 C<make> B<target> is the word you specify after C<make>, like C<test>
295 for C<make test>. Some of the more useful targets are:
301 This is the default target. When you type C<make> it is the same as
302 entering C<make all>. This target builds all of your code and stages it
303 in the C<blib> directory.
307 Run your distribution's test suite.
311 Copy the contents of the C<blib> directory into the appropriate
312 directories in your Perl installation.
316 Create a distribution tarball, ready for uploading to CPAN or sharing
319 =item * clean distclean purge
321 Remove the files created by C<perl Makefile.PL> and C<make>.
325 Same as typing C<perldoc ExtUtils::MakeMaker>.
329 This module modifies the behaviour of some of these targets, depending
330 on your requirements, and also adds the following targets to your Makefile:
336 Just like purge, except that it also deletes the files originally added
337 by this module itself.
341 Short cut for typing C<perldoc Module::Install>.
345 Short cut for typing C<cpansign -s>, for B<Module::Signature> users to
346 sign the distribution before release.
352 L<Module::Install>, L<CPAN::MakeMaker>, L<CPAN::MakeMaker::Philosophy>
356 Audrey Tang E<lt>autrijus@autrijus.orgE<gt>
358 Based on original works by Brian Ingerson E<lt>INGY@cpan.orgE<gt>
362 Copyright 2002, 2003, 2004 by
363 Audrey Tang E<lt>autrijus@autrijus.orgE<gt>,
364 Brian Ingerson E<lt>ingy@cpan.orgE<gt>
366 This program is free software; you can redistribute it and/or modify it
367 under the same terms as Perl itself.
369 See L<http://www.perl.com/perl/misc/Artistic.html>