This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
ext/B/Makefile.PL: spot hex defines
[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 8
b1826b71
NC
9my $headerpath;
10if ($core) {
11 $headerpath = File::Spec->catdir(File::Spec->updir, File::Spec->updir);
12} else {
4a46fe99 13 require Config;
b1826b71 14 $headerpath = File::Spec->catdir($Config::Config{archlibexp}, "CORE");
29fc1735
JH
15}
16
ecbafe5d 17my @names = ({ name => 'HEf_SVKEY', macro => 1, type => "IV" },
0f94cb1f
FC
18 qw(SVTYPEMASK SVt_PVGV SVt_PVHV PAD_FAKELEX_ANON
19 PAD_FAKELEX_MULTI SVpad_STATE SVpad_TYPED SVpad_OUR));
b7254abc 20
0f0d5355 21my @depend;
b7254abc 22
b1826b71
NC
23# First element in each tuple is the file; second is a regex snippet
24# giving the prefix to limit the names of symbols to define that come
25# from that file. If none, all symbols will be defined whose values
26# match the pattern below.
61bc5e5c 27foreach my $tuple (['cop.h'],
675cfc4e 28 ['cv.h', 'CVf'],
bb1efdce 29 ['gv.h', 'G[PV]f'],
61bc5e5c 30 ['op.h'],
f3574cc6 31 ['opcode.h', 'OPp'],
61bc5e5c 32 ['op_reg_common.h','(?:(?:RXf_)?PMf_)'],
0f94cb1f 33 ['pad.h','PADNAMEt_'],
61bc5e5c 34 ['regexp.h','RXf_'],
9489b85a 35 ['sv.h', 'SV(?:[fps]|pad)_'],
61bc5e5c 36 ) {
b1826b71
NC
37 my $file = $tuple->[0];
38 my $pfx = $tuple->[1] || '';
39 my $path = File::Spec->catfile($headerpath, $file);
0f0d5355 40 push @depend, $path;
b1826b71
NC
41 open my $fh, '<', $path or die "Cannot open $path: $!";
42 while (<$fh>) {
43 push @names, $1 if (/ \#define \s+ ( $pfx \w+ ) \s+
ad51dc19
KW
44 ( [()|\dx]+ [UuLl]{0,2} # Parens, '|', digits, 'x',
45 # followed by optional long,
46 # unsigned qualifiers
a644a388 47 | 0x[0-9a-fA-F]+ # hex values
ad51dc19
KW
48 | \(? \d+ [UuLl]{0,2} \s* << .*? # digits left shifted by anything
49 # followed by optional
50 # long, unsigned qualifiers
51 ) \s* (?: $| \/ \* ) # ending at comment or $
52 /x);
b1826b71
NC
53 }
54 close $fh;
b7254abc 55}
b1826b71 56
0f0d5355
FC
57WriteMakefile(
58 NAME => "B",
59 VERSION_FROM => "B.pm",
60 realclean => {FILES=> 'const-c.inc const-xs.inc'},
61 depend => {'Makefile' => "@depend"},
62);
63
b1826b71
NC
64# Currently only SVt_PVGV and SVt_PVHV aren't macros, but everything we name
65# should exist, so ensure that the C compile breaks if anything does not.
66WriteConstants(
67 PROXYSUBS => {push => 'EXPORT_OK'},
68 NAME => 'B',
ecbafe5d 69 NAMES => [map {ref $_ ? $_ : {name=>$_, macro=>1, type=>"UV"}} @names],
b1826b71
NC
70 XS_SUBNAME => undef,
71);