This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Expose all GV flags matching qr/GVf_/ as constants in B.
[perl5.git] / ext / B / Makefile.PL
CommitLineData
a8a597b2 1use ExtUtils::MakeMaker;
b1826b71 2use ExtUtils::Constant 0.23 'WriteConstants';
29fc1735 3use File::Spec;
b1826b71
NC
4use strict;
5use warnings;
6
b7254abc 7my $core = grep { $_ eq 'PERL_CORE=1' } @ARGV;
a8a597b2
MB
8
9WriteMakefile(
51a5edaf
RGS
10 NAME => "B",
11 VERSION_FROM => "B.pm",
b1826b71 12 realclean => {FILES=> 'const-c.inc const-xs.inc'},
51a5edaf 13);
a8a597b2 14
b1826b71
NC
15my $headerpath;
16if ($core) {
17 $headerpath = File::Spec->catdir(File::Spec->updir, File::Spec->updir);
18} else {
4a46fe99 19 require Config;
b1826b71 20 $headerpath = File::Spec->catdir($Config::Config{archlibexp}, "CORE");
29fc1735
JH
21}
22
655d9c75 23my @names = qw(HEf_SVKEY
b1826b71 24 SVTYPEMASK SVt_PVGV SVt_PVHV
b1826b71 25 PAD_FAKELEX_ANON PAD_FAKELEX_MULTI);
b7254abc 26
675cfc4e 27if ($] < 5.009) {
b1826b71
NC
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
170a6a5f 32 push @names, {name=>"OPpPAD_STATE", default=>["IV", "0"]};
a8a597b2 33}
b7254abc 34
b1826b71
NC
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.
61bc5e5c 39foreach my $tuple (['cop.h'],
675cfc4e 40 ['cv.h', 'CVf'],
655d9c75 41 ['gv.h', 'GVf'],
61bc5e5c
NC
42 ['op.h'],
43 ['op_reg_common.h','(?:(?:RXf_)?PMf_)'],
44 ['regexp.h','RXf_'],
9489b85a 45 ['sv.h', 'SV(?:[fps]|pad)_'],
61bc5e5c 46 ) {
b1826b71
NC
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;
b7254abc 59}
b1826b71
NC
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.
63WriteConstants(
64 PROXYSUBS => {push => 'EXPORT_OK'},
65 NAME => 'B',
170a6a5f 66 NAMES => [map {ref $_ ? $_ : {name=>$_, macro=>1}} @names],
b1826b71
NC
67 XS_SUBNAME => undef,
68);