1 package Module::Install::Makefile;
4 use ExtUtils::MakeMaker ();
5 use Module::Install::Base ();
7 use vars qw{$VERSION @ISA $ISCORE};
10 @ISA = '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, @_ );
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 # Check the current Perl version
117 my $perl_version = $self->perl_version;
118 if ( $perl_version ) {
119 eval "use $perl_version; 1"
120 or die "ERROR: perl: Version $] is installed, "
121 . "but we need version >= $perl_version";
124 # Make sure we have a new enough MakeMaker
125 require ExtUtils::MakeMaker;
127 if ( $perl_version and $self->_cmp($perl_version, '5.006') >= 0 ) {
128 # MakeMaker can complain about module versions that include
129 # an underscore, even though its own version may contain one!
130 # Hence the funny regexp to get rid of it. See RT #35800
132 $self->build_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/ );
133 $self->configure_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/ );
135 # Allow legacy-compatibility with 5.005 by depending on the
136 # most recent EU:MM that supported 5.005.
137 $self->build_requires( 'ExtUtils::MakeMaker' => 6.42 );
138 $self->configure_requires( 'ExtUtils::MakeMaker' => 6.42 );
141 # Generate the MakeMaker params
142 my $args = $self->makemaker_args;
143 $args->{DISTNAME} = $self->name;
144 $args->{NAME} = $self->module_name || $self->name;
145 $args->{VERSION} = $self->version;
146 $args->{NAME} =~ s/-/::/g;
147 if ( $self->tests ) {
148 $args->{test} = { TESTS => $self->tests };
151 $args->{ABSTRACT} = $self->abstract;
152 $args->{AUTHOR} = $self->author;
154 if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) {
155 $args->{NO_META} = 1;
157 if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) {
160 unless ( $self->is_admin ) {
161 delete $args->{SIGN};
164 # Merge both kinds of requires into prereq_pm
165 my $prereq = ($args->{PREREQ_PM} ||= {});
166 %$prereq = ( %$prereq,
170 ($self->configure_requires, $self->build_requires, $self->requires)
173 # Remove any reference to perl, PREREQ_PM doesn't support it
174 delete $args->{PREREQ_PM}->{perl};
176 # merge both kinds of requires into prereq_pm
177 my $subdirs = ($args->{DIR} ||= []);
178 if ($self->bundles) {
179 foreach my $bundle (@{ $self->bundles }) {
180 my ($file, $dir) = @$bundle;
181 push @$subdirs, $dir if -d $dir;
182 delete $prereq->{$file};
186 if ( my $perl_version = $self->perl_version ) {
187 eval "use $perl_version; 1"
188 or die "ERROR: perl: Version $] is installed, "
189 . "but we need version >= $perl_version";
192 $args->{INSTALLDIRS} = $self->installdirs;
194 my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args;
196 my $user_preop = delete $args{dist}->{PREOP};
197 if (my $preop = $self->admin->preop($user_preop)) {
198 foreach my $key ( keys %$preop ) {
199 $args{dist}->{$key} = $preop->{$key};
203 my $mm = ExtUtils::MakeMaker::WriteMakefile(%args);
204 $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile');
207 sub fix_up_makefile {
209 my $makefile_name = shift;
210 my $top_class = ref($self->_top) || '';
211 my $top_version = $self->_top->VERSION || '';
213 my $preamble = $self->preamble
214 ? "# Preamble by $top_class $top_version\n"
217 my $postamble = "# Postamble by $top_class $top_version\n"
218 . ($self->postamble || '');
221 open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
222 my $makefile = do { local $/; <MAKEFILE> };
223 close MAKEFILE or die $!;
225 $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /;
226 $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g;
227 $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g;
228 $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m;
229 $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m;
231 # Module::Install will never be used to build the Core Perl
232 # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks
233 # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist
234 $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m;
235 #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m;
237 # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well.
238 $makefile =~ s/(\"?)-I\$\(PERL_LIB\)\1//g;
240 # XXX - This is currently unused; not sure if it breaks other MM-users
241 # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg;
243 open MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
244 print MAKEFILE "$preamble$makefile$postamble" or die $!;
245 close MAKEFILE or die $!;
251 my ($self, $text) = @_;
252 $self->{preamble} = $text . $self->{preamble} if defined $text;
257 my ($self, $text) = @_;
258 $self->{postamble} ||= $self->admin->postamble;
259 $self->{postamble} .= $text if defined $text;
271 Module::Install::MakeMaker - Extension Rules for ExtUtils::MakeMaker
275 In your F<Makefile.PL>:
277 use inc::Module::Install;
282 This module is a wrapper around B<ExtUtils::MakeMaker>. It exports
283 two functions: C<prompt> (an alias for C<ExtUtils::MakeMaker::prompt>)
284 and C<WriteMakefile>.
286 The C<WriteMakefile> function will pass on keyword/value pair functions
287 to C<ExtUtils::MakeMaker::WriteMakefile>. The required parameters
288 C<NAME> and C<VERSION> (or C<VERSION_FROM>) are not necessary if
289 it can find them unambiguously in your code.
291 =head1 CONFIGURATION OPTIONS
293 This module also adds some Configuration parameters of its own:
297 The NAME parameter is required by B<ExtUtils::MakeMaker>. If you have a
298 single module in your distribution, or if the module name indicated by
299 the current directory exists under F<lib/>, this module will use the
300 guessed package name as the default.
302 If this module can't find a default for C<NAME> it will ask you to specify
307 B<ExtUtils::MakeMaker> requires either the C<VERSION> or C<VERSION_FROM>
308 parameter. If this module can guess the package's C<NAME>, it will attempt
309 to parse the C<VERSION> from it.
311 If this module can't find a default for C<VERSION> it will ask you to
316 B<ExtUtils::MakeMaker> provides you with many useful C<make> targets. A
317 C<make> B<target> is the word you specify after C<make>, like C<test>
318 for C<make test>. Some of the more useful targets are:
324 This is the default target. When you type C<make> it is the same as
325 entering C<make all>. This target builds all of your code and stages it
326 in the C<blib> directory.
330 Run your distribution's test suite.
334 Copy the contents of the C<blib> directory into the appropriate
335 directories in your Perl installation.
339 Create a distribution tarball, ready for uploading to CPAN or sharing
342 =item * clean distclean purge
344 Remove the files created by C<perl Makefile.PL> and C<make>.
348 Same as typing C<perldoc ExtUtils::MakeMaker>.
352 This module modifies the behaviour of some of these targets, depending
353 on your requirements, and also adds the following targets to your Makefile:
359 Just like purge, except that it also deletes the files originally added
360 by this module itself.
364 Short cut for typing C<perldoc Module::Install>.
368 Short cut for typing C<cpansign -s>, for B<Module::Signature> users to
369 sign the distribution before release.
375 L<Module::Install>, L<CPAN::MakeMaker>, L<CPAN::MakeMaker::Philosophy>
379 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
381 Audrey Tang E<lt>autrijus@autrijus.orgE<gt>
383 Brian Ingerson E<lt>INGY@cpan.orgE<gt>
387 Some parts copyright 2008 - 2009 Adam Kennedy.
389 Copyright 2002, 2003, 2004 Audrey Tang and Brian Ingerson.
391 This program is free software; you can redistribute it and/or modify it
392 under the same terms as Perl itself.