This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Makefile.PL: Fix so works on early perls
[perl5.git] / dist / Devel-PPPort / Makefile.PL
CommitLineData
adfe19db
MHM
1################################################################################
2#
3# Makefile.PL -- generate Makefile
4#
5################################################################################
6#
b2049988 7# Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz.
adfe19db
MHM
8# Version 2.x, Copyright (C) 2001, Paul Marquess.
9# Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
10#
11# This program is free software; you can redistribute it and/or
12# modify it under the same terms as Perl itself.
13#
14################################################################################
15
adfe19db 16require 5.003;
0a7c7f4f 17
56093a11 18use strict;
872f2dc8
P
19BEGIN { $^W = 1; }
20
56093a11 21use ExtUtils::MakeMaker;
bb851449 22use Config;
56093a11
MHM
23
24use vars '%opt'; # needs to be global, and we can't use 'our'
25
adfe19db
MHM
26unless ($ENV{'PERL_CORE'}) {
27 $ENV{'PERL_CORE'} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV;
9fdbfc11 28}
adfe19db 29
56093a11 30@ARGV = map { /^--with-(apicheck)$/ && ++$opt{$1} ? () : $_ } @ARGV;
0d0f8426 31
f89bdec0 32my %mf = (
adfe19db
MHM
33 NAME => 'Devel::PPPort',
34 VERSION_FROM => 'PPPort_pm.PL',
adfe19db 35 PM => { 'PPPort.pm' => '$(INST_LIBDIR)/PPPort.pm' },
adfe19db 36 H => [ qw(ppport.h) ],
78b4ff79 37 OBJECT => 'RealPPPort$(OBJ_EXT) $(O_FILES)',
adfe19db 38 XSPROTOARG => '-noprototypes',
236afa0a 39 CONFIGURE => \&configure,
0a7c7f4f 40);
f89bdec0 41WriteMakefile(%mf);
adfe19db 42
236afa0a
MHM
43sub configure
44{
c94f8a39 45 my @clean = qw{ $(H_FILES) RealPPPort.xs RealPPPort.c PPPort.pm };
12efe483
P
46 my %depend = (
47 '$(OBJECT)' => '$(H_FILES)',
48 'Makefile' => '$(VERSION_FROM)',
49 );
236afa0a
MHM
50 my @C_FILES = qw{ module2.c module3.c },
51 my %PL_FILES = (
52 'ppport_h.PL' => 'ppport.h',
53 'PPPort_pm.PL' => 'PPPort.pm',
3bfe1c68 54 'RealPPPort_xs.PL' => 'RealPPPort.xs',
14dfa0eb 55 'mktests.PL' => 't/01_test.t',
236afa0a
MHM
56 );
57 my @moreopts;
58
342f707b 59 if (eval { ExtUtils::MakeMaker->VERSION(6) }) {
236afa0a 60 push @moreopts, AUTHOR => 'Marcus Holland-Moritz <mhx@cpan.org>';
c94f8a39 61 push @moreopts, ABSTRACT_FROM => 'PPPort_pm.PL';
236afa0a
MHM
62 }
63
342f707b 64 if (eval { ExtUtils::MakeMaker->VERSION(6.30_01) }) {
236afa0a
MHM
65 print "Setting license tag...\n";
66 push @moreopts, LICENSE => 'perl';
67 }
68
a970b26d
P
69 if (eval { ExtUtils::MakeMaker->VERSION (6.46) }) {
70 open FH, '<PPPort_pm.PL' or die "cannot open PPPort_pm.PL for reading: $!";
71 my $version;
1c721467
KW
72 my $line;
73 while ($line = <FH>) {
a970b26d
P
74 ($version) = $line =~ /^\$VERSION = '([\d.]+)';$/ and last;
75 };
76 die 'failed to extract $VERSION from PPPort_pm.PL' if not $version;
77 close FH;
78 print "Adding META_MERGE...\n";
79 push @moreopts, META_MERGE => {
80 'meta-spec' => { version => 2 },
81 provides => {
82 'Devel::PPPort' => {
83 file => 'PPPort_pm.PL',
84 version => $version,
85 },
86 },
87 resources => {
88 bugtracker => {
89 web => 'https://rt.perl.org/rt3/',
90 },
91 repository => {
92 type => 'git',
93 url => 'git://perl5.git.perl.org/perl.git',
94 web => 'https://perl5.git.perl.org/perl.git',
95 },
96 },
97 };
98 }
99
c94f8a39 100 if (not $ENV{'PERL_CORE'}) {
236afa0a 101 # Devel::PPPort is in the core since 5.7.3
b2049988
MHM
102 # 5.11.0+ has site before perl
103 push @moreopts, INSTALLDIRS => (
f551177d 104 ("$]" >= 5.007003 and "$]" < 5.011)
b2049988
MHM
105 ? 'perl'
106 : 'site'
107 );
236afa0a
MHM
108 }
109
110 if ($opt{'apicheck'}) {
111 $PL_FILES{'apicheck_c.PL'} = 'apicheck.c';
112 push @C_FILES, qw{ apicheck.c };
113 push @clean, qw{ apicheck.c apicheck.i };
114 $depend{'apicheck.i'} = 'ppport.h';
115 }
116
bb851449
P
117 if ($Config{gccversion}) {
118 my $define = '-W -Wall';
119 $define .= ' -Wdeclaration-after-statement' if $Config{gccversion} =~ /^(\d+\.\d+)\./ && $1 >= 3.4;
120 push @moreopts, DEFINE => $define;
121 }
122
236afa0a
MHM
123 return {
124 C => \@C_FILES,
78b4ff79 125 XS => { 'RealPPPort.xs' => 'RealPPPort.c' },
236afa0a
MHM
126 PL_FILES => \%PL_FILES,
127 depend => \%depend,
128 clean => { FILES => "@clean" },
129 @moreopts,
130 };
131}
132
133sub MY::postamble
134{
adfe19db
MHM
135 package MY;
136 my $post = shift->SUPER::postamble(@_);
137 $post .= <<'POSTAMBLE';
138
139purge_all: realclean
78b4ff79 140 @$(RM_F) PPPort.pm t/*.t
adfe19db 141
78b4ff79 142regen_pm:
adfe19db 143 $(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) PPPort_pm.PL
78b4ff79
MHM
144
145regen_xs:
3bfe1c68 146 $(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) RealPPPort_xs.PL
78b4ff79
MHM
147
148regen_tests:
adfe19db 149 $(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) mktests.PL
78b4ff79
MHM
150
151regen_h:
adfe19db
MHM
152 $(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) ppport_h.PL
153
78b4ff79
MHM
154regen: regen_pm regen_xs regen_tests regen_h
155
adfe19db
MHM
156POSTAMBLE
157 return $post;
158}
159
4b471f50
P
160sub MY::processPL
161{
162 package MY;
163 my $original = shift->SUPER::processPL(@_);
164
165 require "./parts/ppptools.pl";
166 my $includes = join ' ', all_files_in_dir('parts/inc');
167
168 my $updated = '';
169 my @rules = split( m{^\s*$}m, $original );
1c721467
KW
170 my $rule;
171 foreach $rule ( @rules ) {
4b471f50
P
172 if ( $rule =~ m{^\s*^PPPort\.pm\s+:}m ) {
173 $rule =~ s{^(\s*^PPPort\.pm\s+:.*)}{$1 $includes}m; # PPPort.pm depends on all files from parts/inc
174 $rule =~ s{pm_to_blib}{}m; # PPPort.pm must not depend on built PPPort.pm in blib/
175 } elsif ( $rule =~ m{^\s*^ppport\.h\s+:}m ) {
176 $rule =~ s{^(\s*^ppport\.h\s+:.*)}{$1 PPPort.pm}m; # ppport.h depends on PPPort.pm
177 $rule =~ s{pm_to_blib}{}m; # ppport.h is used to build RealPPPort.xs so cannot depend on built PPPort in blib/
178 } elsif ( $rule =~ m{^\s*^RealPPPort\.xs\s+:}m ) {
179 $rule =~ s{^(\s*^RealPPPort\.xs\s+:.*)}{$1 ppport.h}m; # RealPPPort.xs depends on ppport.h
180 $rule =~ s{pm_to_blib}{}m; # RealPPPort.xs is used to build PPPort binary, so it cannot depend on it
6bdd6a87
CB
181 } elsif ( $rule =~ m{^\s*\S+\b01_test\.t\s+:}m ) {
182 $rule =~ s{^(\s*^\S+\b01_test\.t\s+:.*)}{$1 $includes}m; # all tests in t/ depends on all files from parts/inc
4b471f50
P
183 $rule =~ s{pm_to_blib}{}m; # Generating test files does not depend on built PPPort in blib/
184 }
185 $updated .= $rule;
186 }
187
4b471f50
P
188 return $updated;
189}
190
aadf4f9e
N
191sub MY::dist_core
192{
193 package MY;
194 my $dist = shift->SUPER::dist_core(@_);
195
196 my $updated = '';
197 my @rules = split( m{^\s*$}m, $dist );
1c721467
KW
198 my $rule;
199 foreach $rule ( @rules ) {
aadf4f9e 200 if ( $rule =~ m{^\s*^dist\s+:}m ) {
a134887e 201 $rule =~ s{:}{: manifest}; # make sure we regenerate the manifest
aadf4f9e
N
202 $rule .= qq[\t].q[$(NOECHO) $(ECHO) "Warning: Please check '__MAX_PERL__' value in PPPort_pm.PL"].qq[\n];
203 }
204 $updated .= $rule;
205 }
206
207 return $updated;
208}
209
210
236afa0a
MHM
211sub MY::c_o
212{
ba120f6f
MHM
213 package MY;
214 my $co = shift->SUPER::c_o(@_);
215
56093a11
MHM
216 if ($::opt{'apicheck'} && $co !~ /^\.c\.i:/m) {
217 print "Adding custom rule for preprocessed apicheck file...\n";
218
219 $co .= <<'CO'
ba120f6f
MHM
220
221.SUFFIXES: .i
222
223.c.i:
224 $(CCCMD) -E -I$(PERL_INC) $(DEFINE) $*.c > $*.i
225CO
56093a11 226 }
ba120f6f
MHM
227
228 return $co;
229}