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