/[vz-tools]/trunk/inc/Module/Install/Makefile.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/inc/Module/Install/Makefile.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 52 - (hide annotations)
Fri Aug 15 09:59:29 2008 UTC (15 years, 9 months ago) by dpavlin
File size: 6444 byte(s)
update Module::Install
1 dpavlin 34 #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 dpavlin 52 $VERSION = '0.76';
11 dpavlin 34 $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 dpavlin 52 my $args = ( $self->{makemaker_args} ||= {} );
40     %$args = ( %$args, @_ );
41     return $args;
42 dpavlin 34 }
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 = sShift;
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 dpavlin 52 %$clean = (
67 dpavlin 34 %$clean,
68 dpavlin 52 FILES => join ' ', grep { length $_ } ($clean->{FILES} || (), @_),
69 dpavlin 34 );
70     }
71    
72     sub realclean_files {
73 dpavlin 52 my $self = shift;
74 dpavlin 34 my $realclean = $self->makemaker_args->{realclean} ||= {};
75 dpavlin 52 %$realclean = (
76 dpavlin 34 %$realclean,
77 dpavlin 52 FILES => join ' ', grep { length $_ } ($realclean->{FILES} || (), @_),
78 dpavlin 34 );
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     my %test_dir = ();
93    
94     sub _wanted_t {
95     /\.t$/ and -f $_ and $test_dir{$File::Find::dir} = 1;
96     }
97    
98     sub tests_recursive {
99     my $self = shift;
100     if ( $self->tests ) {
101     die "tests_recursive will not work if tests are already defined";
102     }
103     my $dir = shift || 't';
104     unless ( -d $dir ) {
105     die "tests_recursive dir '$dir' does not exist";
106     }
107 dpavlin 52 %test_dir = ();
108 dpavlin 34 require File::Find;
109     File::Find::find( \&_wanted_t, $dir );
110     $self->tests( join ' ', map { "$_/*.t" } sort keys %test_dir );
111     }
112    
113     sub write {
114     my $self = shift;
115     die "&Makefile->write() takes no arguments\n" if @_;
116    
117 dpavlin 52 # Make sure we have a new enough
118     require ExtUtils::MakeMaker;
119    
120     # MakeMaker can complain about module versions that include
121     # an underscore, even though its own version may contain one!
122     # Hence the funny regexp to get rid of it. See RT #35800
123     # for details.
124    
125     $self->configure_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/ );
126    
127     # Generate the
128 dpavlin 34 my $args = $self->makemaker_args;
129     $args->{DISTNAME} = $self->name;
130 dpavlin 52 $args->{NAME} = $self->module_name || $self->name;
131     $args->{VERSION} = $self->version;
132 dpavlin 34 $args->{NAME} =~ s/-/::/g;
133     if ( $self->tests ) {
134     $args->{test} = { TESTS => $self->tests };
135     }
136     if ($] >= 5.005) {
137     $args->{ABSTRACT} = $self->abstract;
138     $args->{AUTHOR} = $self->author;
139     }
140     if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) {
141     $args->{NO_META} = 1;
142     }
143     if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) {
144     $args->{SIGN} = 1;
145     }
146     unless ( $self->is_admin ) {
147     delete $args->{SIGN};
148     }
149    
150     # merge both kinds of requires into prereq_pm
151     my $prereq = ($args->{PREREQ_PM} ||= {});
152     %$prereq = ( %$prereq,
153     map { @$_ }
154     map { @$_ }
155     grep $_,
156 dpavlin 52 ($self->configure_requires, $self->build_requires, $self->requires)
157 dpavlin 34 );
158    
159 dpavlin 52 # Remove any reference to perl, PREREQ_PM doesn't support it
160     delete $args->{PREREQ_PM}->{perl};
161    
162 dpavlin 34 # merge both kinds of requires into prereq_pm
163     my $subdirs = ($args->{DIR} ||= []);
164     if ($self->bundles) {
165     foreach my $bundle (@{ $self->bundles }) {
166     my ($file, $dir) = @$bundle;
167     push @$subdirs, $dir if -d $dir;
168     delete $prereq->{$file};
169     }
170     }
171    
172     if ( my $perl_version = $self->perl_version ) {
173     eval "use $perl_version; 1"
174     or die "ERROR: perl: Version $] is installed, "
175     . "but we need version >= $perl_version";
176     }
177    
178     $args->{INSTALLDIRS} = $self->installdirs;
179    
180     my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args;
181    
182     my $user_preop = delete $args{dist}->{PREOP};
183     if (my $preop = $self->admin->preop($user_preop)) {
184     $args{dist} = $preop;
185     }
186    
187     my $mm = ExtUtils::MakeMaker::WriteMakefile(%args);
188     $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile');
189     }
190    
191     sub fix_up_makefile {
192     my $self = shift;
193     my $makefile_name = shift;
194     my $top_class = ref($self->_top) || '';
195     my $top_version = $self->_top->VERSION || '';
196    
197     my $preamble = $self->preamble
198     ? "# Preamble by $top_class $top_version\n"
199     . $self->preamble
200     : '';
201     my $postamble = "# Postamble by $top_class $top_version\n"
202     . ($self->postamble || '');
203    
204     local *MAKEFILE;
205     open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
206     my $makefile = do { local $/; <MAKEFILE> };
207     close MAKEFILE or die $!;
208    
209     $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /;
210     $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g;
211     $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g;
212     $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m;
213     $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m;
214    
215     # Module::Install will never be used to build the Core Perl
216     # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks
217     # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist
218     $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m;
219     #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m;
220    
221     # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well.
222 dpavlin 52 $makefile =~ s/(\"?)-I\$\(PERL_LIB\)\1//g;
223 dpavlin 34
224     # XXX - This is currently unused; not sure if it breaks other MM-users
225     # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg;
226    
227     open MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
228     print MAKEFILE "$preamble$makefile$postamble" or die $!;
229     close MAKEFILE or die $!;
230    
231     1;
232     }
233    
234     sub preamble {
235     my ($self, $text) = @_;
236     $self->{preamble} = $text . $self->{preamble} if defined $text;
237     $self->{preamble};
238     }
239    
240     sub postamble {
241     my ($self, $text) = @_;
242     $self->{postamble} ||= $self->admin->postamble;
243     $self->{postamble} .= $text if defined $text;
244     $self->{postamble}
245     }
246    
247     1;
248    
249     __END__
250    
251 dpavlin 52 #line 377

  ViewVC Help
Powered by ViewVC 1.1.26