| 1 |
#line 1 |
| 2 |
package Module::Install::Makefile; |
| 3 |
|
| 4 |
use strict 'vars'; |
| 5 |
use Module::Install::Base; |
| 6 |
use ExtUtils::MakeMaker (); |
| 7 |
|
| 8 |
use vars qw{$VERSION $ISCORE @ISA}; |
| 9 |
BEGIN { |
| 10 |
$VERSION = '0.63'; |
| 11 |
$ISCORE = 1; |
| 12 |
@ISA = qw{Module::Install::Base}; |
| 13 |
} |
| 14 |
|
| 15 |
sub Makefile { $_[0] } |
| 16 |
|
| 17 |
my %seen = (); |
| 18 |
|
| 19 |
sub prompt { |
| 20 |
shift; |
| 21 |
|
| 22 |
# Infinite loop protection |
| 23 |
my @c = caller(); |
| 24 |
if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) { |
| 25 |
die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])"; |
| 26 |
} |
| 27 |
|
| 28 |
# In automated testing, always use defaults |
| 29 |
if ( $ENV{AUTOMATED_TESTING} and ! $ENV{PERL_MM_USE_DEFAULT} ) { |
| 30 |
local $ENV{PERL_MM_USE_DEFAULT} = 1; |
| 31 |
goto &ExtUtils::MakeMaker::prompt; |
| 32 |
} else { |
| 33 |
goto &ExtUtils::MakeMaker::prompt; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
sub makemaker_args { |
| 38 |
my $self = shift; |
| 39 |
my $args = ($self->{makemaker_args} ||= {}); |
| 40 |
%$args = ( %$args, @_ ) if @_; |
| 41 |
$args; |
| 42 |
} |
| 43 |
|
| 44 |
# For mm args that take multiple space-seperated args, |
| 45 |
# append an argument to the current list. |
| 46 |
sub makemaker_append { |
| 47 |
my $self = shift; |
| 48 |
my $name = shift; |
| 49 |
my $args = $self->makemaker_args; |
| 50 |
$args->{name} = defined $args->{$name} |
| 51 |
? join( ' ', $args->{name}, @_ ) |
| 52 |
: join( ' ', @_ ); |
| 53 |
} |
| 54 |
|
| 55 |
sub build_subdirs { |
| 56 |
my $self = shift; |
| 57 |
my $subdirs = $self->makemaker_args->{DIR} ||= []; |
| 58 |
for my $subdir (@_) { |
| 59 |
push @$subdirs, $subdir; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
sub clean_files { |
| 64 |
my $self = shift; |
| 65 |
my $clean = $self->makemaker_args->{clean} ||= {}; |
| 66 |
%$clean = ( |
| 67 |
%$clean, |
| 68 |
FILES => join(' ', grep length, $clean->{FILES}, @_), |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
sub realclean_files { |
| 73 |
my $self = shift; |
| 74 |
my $realclean = $self->makemaker_args->{realclean} ||= {}; |
| 75 |
%$realclean = ( |
| 76 |
%$realclean, |
| 77 |
FILES => join(' ', grep length, $realclean->{FILES}, @_), |
| 78 |
); |
| 79 |
} |
| 80 |
|
| 81 |
sub libs { |
| 82 |
my $self = shift; |
| 83 |
my $libs = ref $_[0] ? shift : [ shift ]; |
| 84 |
$self->makemaker_args( LIBS => $libs ); |
| 85 |
} |
| 86 |
|
| 87 |
sub inc { |
| 88 |
my $self = shift; |
| 89 |
$self->makemaker_args( INC => shift ); |
| 90 |
} |
| 91 |
|
| 92 |
sub write { |
| 93 |
my $self = shift; |
| 94 |
die "&Makefile->write() takes no arguments\n" if @_; |
| 95 |
|
| 96 |
my $args = $self->makemaker_args; |
| 97 |
$args->{DISTNAME} = $self->name; |
| 98 |
$args->{NAME} = $self->module_name || $self->name || $self->determine_NAME($args); |
| 99 |
$args->{VERSION} = $self->version || $self->determine_VERSION($args); |
| 100 |
$args->{NAME} =~ s/-/::/g; |
| 101 |
if ( $self->tests ) { |
| 102 |
$args->{test} = { TESTS => $self->tests }; |
| 103 |
} |
| 104 |
if ($] >= 5.005) { |
| 105 |
$args->{ABSTRACT} = $self->abstract; |
| 106 |
$args->{AUTHOR} = $self->author; |
| 107 |
} |
| 108 |
if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) { |
| 109 |
$args->{NO_META} = 1; |
| 110 |
} |
| 111 |
if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) { |
| 112 |
$args->{SIGN} = 1; |
| 113 |
} |
| 114 |
unless ( $self->is_admin ) { |
| 115 |
delete $args->{SIGN}; |
| 116 |
} |
| 117 |
|
| 118 |
# merge both kinds of requires into prereq_pm |
| 119 |
my $prereq = ($args->{PREREQ_PM} ||= {}); |
| 120 |
%$prereq = ( %$prereq, map { @$_ } map { @$_ } grep $_, |
| 121 |
($self->build_requires, $self->requires) ); |
| 122 |
|
| 123 |
# merge both kinds of requires into prereq_pm |
| 124 |
my $subdirs = ($args->{DIR} ||= []); |
| 125 |
if ($self->bundles) { |
| 126 |
foreach my $bundle (@{ $self->bundles }) { |
| 127 |
my ($file, $dir) = @$bundle; |
| 128 |
push @$subdirs, $dir if -d $dir; |
| 129 |
delete $prereq->{$file}; |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
if ( my $perl_version = $self->perl_version ) { |
| 134 |
eval "use $perl_version; 1" |
| 135 |
or die "ERROR: perl: Version $] is installed, " |
| 136 |
. "but we need version >= $perl_version"; |
| 137 |
} |
| 138 |
|
| 139 |
my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args; |
| 140 |
if ($self->admin->preop) { |
| 141 |
$args{dist} = $self->admin->preop; |
| 142 |
} |
| 143 |
|
| 144 |
my $mm = ExtUtils::MakeMaker::WriteMakefile(%args); |
| 145 |
$self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile'); |
| 146 |
} |
| 147 |
|
| 148 |
sub fix_up_makefile { |
| 149 |
my $self = shift; |
| 150 |
my $makefile_name = shift; |
| 151 |
my $top_class = ref($self->_top) || ''; |
| 152 |
my $top_version = $self->_top->VERSION || ''; |
| 153 |
|
| 154 |
my $preamble = $self->preamble |
| 155 |
? "# Preamble by $top_class $top_version\n" |
| 156 |
. $self->preamble |
| 157 |
: ''; |
| 158 |
my $postamble = "# Postamble by $top_class $top_version\n" |
| 159 |
. ($self->postamble || ''); |
| 160 |
|
| 161 |
local *MAKEFILE; |
| 162 |
open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; |
| 163 |
my $makefile = do { local $/; <MAKEFILE> }; |
| 164 |
close MAKEFILE or die $!; |
| 165 |
|
| 166 |
$makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; |
| 167 |
$makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; |
| 168 |
$makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; |
| 169 |
$makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; |
| 170 |
$makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; |
| 171 |
|
| 172 |
# Module::Install will never be used to build the Core Perl |
| 173 |
# Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks |
| 174 |
# PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist |
| 175 |
$makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m; |
| 176 |
#$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m; |
| 177 |
|
| 178 |
# Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well. |
| 179 |
$makefile =~ s/("?)-I\$\(PERL_LIB\)\1//g; |
| 180 |
|
| 181 |
# XXX - This is currently unused; not sure if it breaks other MM-users |
| 182 |
# $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg; |
| 183 |
|
| 184 |
open MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; |
| 185 |
print MAKEFILE "$preamble$makefile$postamble" or die $!; |
| 186 |
close MAKEFILE or die $!; |
| 187 |
|
| 188 |
1; |
| 189 |
} |
| 190 |
|
| 191 |
sub preamble { |
| 192 |
my ($self, $text) = @_; |
| 193 |
$self->{preamble} = $text . $self->{preamble} if defined $text; |
| 194 |
$self->{preamble}; |
| 195 |
} |
| 196 |
|
| 197 |
sub postamble { |
| 198 |
my ($self, $text) = @_; |
| 199 |
$self->{postamble} ||= $self->admin->postamble; |
| 200 |
$self->{postamble} .= $text if defined $text; |
| 201 |
$self->{postamble} |
| 202 |
} |
| 203 |
|
| 204 |
1; |
| 205 |
|
| 206 |
__END__ |
| 207 |
|
| 208 |
#line 334 |