source: perl/modules/Twitter/inc/Module/Install/Makefile.pm @ fa981f3

release-1.10release-1.7release-1.8release-1.9
Last change on this file since fa981f3 was d27ecf3, checked in by Nelson Elhage <nelhage@mit.edu>, 14 years ago
Check in Module::Install for Twitter
  • Property mode set to 100644
File size: 7.0 KB
Line 
1#line 1
2package Module::Install::Makefile;
3
4use strict 'vars';
5use ExtUtils::MakeMaker   ();
6use Module::Install::Base ();
7
8use vars qw{$VERSION @ISA $ISCORE};
9BEGIN {
10        $VERSION = '0.91';
11        @ISA     = 'Module::Install::Base';
12        $ISCORE  = 1;
13}
14
15sub Makefile { $_[0] }
16
17my %seen = ();
18
19sub 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
37sub makemaker_args {
38        my $self = shift;
39        my $args = ( $self->{makemaker_args} ||= {} );
40        %$args = ( %$args, @_ );
41        return $args;
42}
43
44# For mm args that take multiple space-seperated args,
45# append an argument to the current list.
46sub 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
55sub build_subdirs {
56        my $self    = shift;
57        my $subdirs = $self->makemaker_args->{DIR} ||= [];
58        for my $subdir (@_) {
59                push @$subdirs, $subdir;
60        }
61}
62
63sub 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
72sub 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
81sub libs {
82        my $self = shift;
83        my $libs = ref $_[0] ? shift : [ shift ];
84        $self->makemaker_args( LIBS => $libs );
85}
86
87sub inc {
88        my $self = shift;
89        $self->makemaker_args( INC => shift );
90}
91
92my %test_dir = ();
93
94sub _wanted_t {
95        /\.t$/ and -f $_ and $test_dir{$File::Find::dir} = 1;
96}
97
98sub 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        %test_dir = ();
108        require File::Find;
109        File::Find::find( \&_wanted_t, $dir );
110        $self->tests( join ' ', map { "$_/*.t" } sort keys %test_dir );
111}
112
113sub write {
114        my $self = shift;
115        die "&Makefile->write() takes no arguments\n" if @_;
116
117        # Check the current Perl version
118        my $perl_version = $self->perl_version;
119        if ( $perl_version ) {
120                eval "use $perl_version; 1"
121                        or die "ERROR: perl: Version $] is installed, "
122                        . "but we need version >= $perl_version";
123        }
124
125        # Make sure we have a new enough MakeMaker
126        require ExtUtils::MakeMaker;
127
128        if ( $perl_version and $self->_cmp($perl_version, '5.006') >= 0 ) {
129                # MakeMaker can complain about module versions that include
130                # an underscore, even though its own version may contain one!
131                # Hence the funny regexp to get rid of it.  See RT #35800
132                # for details.
133                $self->build_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/ );
134                $self->configure_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/ );
135        } else {
136                # Allow legacy-compatibility with 5.005 by depending on the
137                # most recent EU:MM that supported 5.005.
138                $self->build_requires( 'ExtUtils::MakeMaker' => 6.42 );
139                $self->configure_requires( 'ExtUtils::MakeMaker' => 6.42 );
140        }
141
142        # Generate the MakeMaker params
143        my $args = $self->makemaker_args;
144        $args->{DISTNAME} = $self->name;
145        $args->{NAME}     = $self->module_name || $self->name;
146        $args->{VERSION}  = $self->version;
147        $args->{NAME}     =~ s/-/::/g;
148        if ( $self->tests ) {
149                $args->{test} = { TESTS => $self->tests };
150        }
151        if ( $] >= 5.005 ) {
152                $args->{ABSTRACT} = $self->abstract;
153                $args->{AUTHOR}   = $self->author;
154        }
155        if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) {
156                $args->{NO_META} = 1;
157        }
158        if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) {
159                $args->{SIGN} = 1;
160        }
161        unless ( $self->is_admin ) {
162                delete $args->{SIGN};
163        }
164
165        # Merge both kinds of requires into prereq_pm
166        my $prereq = ($args->{PREREQ_PM} ||= {});
167        %$prereq = ( %$prereq,
168                map { @$_ }
169                map { @$_ }
170                grep $_,
171                ($self->configure_requires, $self->build_requires, $self->requires)
172        );
173
174        # Remove any reference to perl, PREREQ_PM doesn't support it
175        delete $args->{PREREQ_PM}->{perl};
176
177        # merge both kinds of requires into prereq_pm
178        my $subdirs = ($args->{DIR} ||= []);
179        if ($self->bundles) {
180                foreach my $bundle (@{ $self->bundles }) {
181                        my ($file, $dir) = @$bundle;
182                        push @$subdirs, $dir if -d $dir;
183                        delete $prereq->{$file};
184                }
185        }
186
187        if ( my $perl_version = $self->perl_version ) {
188                eval "use $perl_version; 1"
189                        or die "ERROR: perl: Version $] is installed, "
190                        . "but we need version >= $perl_version";
191        }
192
193        $args->{INSTALLDIRS} = $self->installdirs;
194
195        my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args;
196
197        my $user_preop = delete $args{dist}->{PREOP};
198        if (my $preop = $self->admin->preop($user_preop)) {
199                foreach my $key ( keys %$preop ) {
200                        $args{dist}->{$key} = $preop->{$key};
201                }
202        }
203
204        my $mm = ExtUtils::MakeMaker::WriteMakefile(%args);
205        $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile');
206}
207
208sub fix_up_makefile {
209        my $self          = shift;
210        my $makefile_name = shift;
211        my $top_class     = ref($self->_top) || '';
212        my $top_version   = $self->_top->VERSION || '';
213
214        my $preamble = $self->preamble
215                ? "# Preamble by $top_class $top_version\n"
216                        . $self->preamble
217                : '';
218        my $postamble = "# Postamble by $top_class $top_version\n"
219                . ($self->postamble || '');
220
221        local *MAKEFILE;
222        open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
223        my $makefile = do { local $/; <MAKEFILE> };
224        close MAKEFILE or die $!;
225
226        $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /;
227        $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g;
228        $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g;
229        $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m;
230        $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m;
231
232        # Module::Install will never be used to build the Core Perl
233        # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks
234        # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist
235        $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m;
236        #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m;
237
238        # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well.
239        $makefile =~ s/(\"?)-I\$\(PERL_LIB\)\1//g;
240
241        # XXX - This is currently unused; not sure if it breaks other MM-users
242        # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg;
243
244        open  MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
245        print MAKEFILE  "$preamble$makefile$postamble" or die $!;
246        close MAKEFILE  or die $!;
247
248        1;
249}
250
251sub preamble {
252        my ($self, $text) = @_;
253        $self->{preamble} = $text . $self->{preamble} if defined $text;
254        $self->{preamble};
255}
256
257sub postamble {
258        my ($self, $text) = @_;
259        $self->{postamble} ||= $self->admin->postamble;
260        $self->{postamble} .= $text if defined $text;
261        $self->{postamble}
262}
263
2641;
265
266__END__
267
268#line 394
Note: See TracBrowser for help on using the repository browser.