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
16require 5.003;
17
18use strict;
19use ExtUtils::MakeMaker;
20
21use vars '%opt';  # needs to be global, and we can't use 'our'
22
23unless ($ENV{'PERL_CORE'}) {
24  $ENV{'PERL_CORE'} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV;
25}
26
27@ARGV = map { /^--with-(apicheck)$/ && ++$opt{$1} ? () : $_ } @ARGV;
28
29my %mf = (
30  NAME          => 'Devel::PPPort',
31  VERSION_FROM  => 'PPPort_pm.PL',
32  PM            => { 'PPPort.pm' => '$(INST_LIBDIR)/PPPort.pm' },
33  H             => [ qw(ppport.h) ],
34  OBJECT        => 'RealPPPort$(OBJ_EXT) $(O_FILES)',
35  XSPROTOARG    => '-noprototypes',
36  CONFIGURE     => \&configure,
37);
38delete $mf{META_MERGE} unless eval { ExtUtils::MakeMaker->VERSION (6.46) };
39WriteMakefile(%mf);
40
41sub configure
42{
43  my @clean    = qw{ $(H_FILES) RealPPPort.xs RealPPPort.c PPPort.pm };
44  my %depend   = ('$(OBJECT)' => '$(H_FILES)');
45  my @C_FILES  = qw{ module2.c module3.c },
46  my %PL_FILES = (
47    'ppport_h.PL'  => 'ppport.h',
48    'PPPort_pm.PL' => 'PPPort.pm',
49    'PPPort_xs.PL' => 'RealPPPort.xs',
50  );
51  my @moreopts;
52
53  if (eval $ExtUtils::MakeMaker::VERSION >= 6) {
54    push @moreopts, AUTHOR => 'Marcus Holland-Moritz <mhx@cpan.org>';
55    push @moreopts, ABSTRACT_FROM => 'PPPort_pm.PL';
56  }
57
58  if (eval $ExtUtils::MakeMaker::VERSION >= 6.30_01) {
59    print "Setting license tag...\n";
60    push @moreopts, LICENSE => 'perl';
61  }
62
63  if (not $ENV{'PERL_CORE'}) {
64    # Devel::PPPort is in the core since 5.7.3
65    # 5.11.0+ has site before perl
66    push @moreopts, INSTALLDIRS => (
67      ("$]" >= 5.007003 and "$]" < 5.011)
68        ? 'perl'
69        : 'site'
70    );
71  }
72
73  if ($opt{'apicheck'}) {
74    $PL_FILES{'apicheck_c.PL'} = 'apicheck.c';
75    push @C_FILES, qw{ apicheck.c };
76    push @clean,   qw{ apicheck.c apicheck.i };
77    $depend{'apicheck.i'} = 'ppport.h';
78  }
79
80  open my $fh, '<', 'PPPort_pm.PL' or die "cannot open PPPort_pm.PL for reading: $!";
81  my $version;
82  while (my $line = <$fh>) {
83    ($version) = $line =~ /^\$VERSION = '([\d.]+)';$/ and last;
84  };
85  die 'failed to extract $VERSION from PPPort_pm.PL' if not $version;
86  close $fh;
87
88  return {
89    C        => \@C_FILES,
90    XS       => { 'RealPPPort.xs' => 'RealPPPort.c' },
91    PL_FILES => \%PL_FILES,
92    depend   => \%depend,
93    clean    => { FILES => "@clean" },
94    META_MERGE    => {
95      'meta-spec' => { version => 2 },
96      provides => {
97        'Devel::PPPort' => {
98          file    => 'PPPort_pm.PL',
99          version => $version,
100        },
101      },
102      resources => {
103        bugtracker => {
104          web => 'https://rt.perl.org/rt3/',
105        },
106        repository => {
107          type => 'git',
108          url  => 'git://perl5.git.perl.org/perl.git',
109          web  => 'https://perl5.git.perl.org/perl.git',
110        },
111      },
112    },
113    @moreopts,
114  };
115}
116
117sub MY::postamble
118{
119  package MY;
120  my $post = shift->SUPER::postamble(@_);
121  $post .= <<'POSTAMBLE';
122
123purge_all: realclean
124	@$(RM_F) PPPort.pm t/*.t
125
126regen_pm:
127	$(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) PPPort_pm.PL
128
129regen_xs:
130	$(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) PPPort_xs.PL
131
132regen_tests:
133	$(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) mktests.PL
134
135regen_h:
136	$(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) ppport_h.PL
137
138regen: regen_pm regen_xs regen_tests regen_h
139
140POSTAMBLE
141  return $post;
142}
143
144sub MY::dist_core
145{
146  package MY;
147  my $dist = shift->SUPER::dist_core(@_);
148
149  my $updated = '';
150  my @rules = split( m{^\s*$}m, $dist );
151  foreach my $rule ( @rules ) {
152    if ( $rule =~ m{^\s*^dist\s+:}m ) {
153        $rule .= qq[\t].q[$(NOECHO) $(ECHO) "Warning: Please check '__MAX_PERL__' value in PPPort_pm.PL"].qq[\n];
154    }
155    $updated .= $rule;
156  }
157
158  return $updated;
159}
160
161
162sub MY::c_o
163{
164  package MY;
165  my $co = shift->SUPER::c_o(@_);
166
167  if ($::opt{'apicheck'} && $co !~ /^\.c\.i:/m) {
168    print "Adding custom rule for preprocessed apicheck file...\n";
169
170    $co .= <<'CO'
171
172.SUFFIXES: .i
173
174.c.i:
175	$(CCCMD) -E -I$(PERL_INC) $(DEFINE) $*.c > $*.i
176CO
177  }
178
179  return $co;
180}
181