/[XML-Feed]/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 /inc/Module/Install/Makefile.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations)
Sun Mar 16 19:47:49 2008 UTC (16 years, 1 month ago) by dpavlin
File size: 5413 byte(s)
import XML::Feed 0.12 from CPAN

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

  ViewVC Help
Powered by ViewVC 1.1.26