This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Bump B's VERSION and note the changes in perldelta.pod.
[perl5.git] / ext / B / Makefile.PL
1 use ExtUtils::MakeMaker;
2 use ExtUtils::Constant 0.23 'WriteConstants';
3 use File::Spec;
4 use strict;
5 use warnings;
6
7 my $core = grep { $_ eq 'PERL_CORE=1' } @ARGV;
8
9 WriteMakefile(
10     NAME            => "B",
11     VERSION_FROM    => "B.pm",
12     realclean       => {FILES=> 'const-c.inc const-xs.inc'},
13 );
14
15 my $headerpath;
16 if ($core) {
17     $headerpath = File::Spec->catdir(File::Spec->updir, File::Spec->updir);
18 } else {
19         require Config;
20     $headerpath = File::Spec->catdir($Config::Config{archlibexp}, "CORE");
21 }
22
23 my @names = qw(HEf_SVKEY
24                SVTYPEMASK SVt_PVGV SVt_PVHV
25                PAD_FAKELEX_ANON PAD_FAKELEX_MULTI);
26
27 if ($] < 5.009) {
28     # Constant not present after 5.8.x
29     push @names, 'AVf_REAL';
30     # This is only present in 5.10, but it's useful to B::Deparse to be able
31     # to import a dummy value from B
32     push @names, {name=>"OPpPAD_STATE", default=>["IV", "0"]};
33 }
34
35 # First element in each tuple is the file; second is a regex snippet
36 # giving the prefix to limit the names of symbols to define that come
37 # from that file.  If none, all symbols will be defined whose values
38 # match the pattern below.
39 foreach my $tuple (['cop.h'],
40                    ['cv.h', 'CVf'],
41                    ['gv.h', 'GVf'],
42                    ['op.h'],
43                    ['op_reg_common.h','(?:(?:RXf_)?PMf_)'],
44                    ['regexp.h','RXf_'],
45                    ['sv.h', 'SV(?:[fps]|pad)_'],
46                   ) {
47     my $file = $tuple->[0];
48     my $pfx = $tuple->[1] || '';
49     my $path = File::Spec->catfile($headerpath, $file);
50     open my $fh, '<', $path or die "Cannot open $path: $!";
51     while (<$fh>) {
52         push @names, $1 if (/ \#define \s+ ( $pfx \w+ ) \s+
53                               ( [()|\dx]+             # Parens, '|', digits, 'x'
54                               | \(? \d+ \s* << .*?    # digits left shifted by anything
55                               ) \s* (?: $| \/ \* )    # ending at comment or $
56                             /x);
57     }
58     close $fh;
59 }
60
61 # Currently only SVt_PVGV and SVt_PVHV aren't macros, but everything we name
62 # should exist, so ensure that the C compile breaks if anything does not.
63 WriteConstants(
64     PROXYSUBS => {push => 'EXPORT_OK'},
65     NAME => 'B',
66     NAMES => [map {ref $_ ? $_ : {name=>$_, macro=>1}} @names],
67     XS_SUBNAME => undef,
68 );