Commit | Line | Data |
---|---|---|
a8a597b2 | 1 | use ExtUtils::MakeMaker; |
b1826b71 | 2 | use ExtUtils::Constant 0.23 'WriteConstants'; |
29fc1735 | 3 | use File::Spec; |
b1826b71 NC |
4 | use strict; |
5 | use warnings; | |
6 | ||
b7254abc | 7 | my $core = grep { $_ eq 'PERL_CORE=1' } @ARGV; |
a8a597b2 MB |
8 | |
9 | WriteMakefile( | |
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 |
15 | my $headerpath; |
16 | if ($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 | 23 | my @names = qw(HEf_SVKEY |
b1826b71 | 24 | SVTYPEMASK SVt_PVGV SVt_PVHV |
b1826b71 | 25 | PAD_FAKELEX_ANON PAD_FAKELEX_MULTI); |
b7254abc | 26 | |
b7254abc | 27 | |
b1826b71 NC |
28 | # First element in each tuple is the file; second is a regex snippet |
29 | # giving the prefix to limit the names of symbols to define that come | |
30 | # from that file. If none, all symbols will be defined whose values | |
31 | # match the pattern below. | |
61bc5e5c | 32 | foreach my $tuple (['cop.h'], |
675cfc4e | 33 | ['cv.h', 'CVf'], |
655d9c75 | 34 | ['gv.h', 'GVf'], |
61bc5e5c NC |
35 | ['op.h'], |
36 | ['op_reg_common.h','(?:(?:RXf_)?PMf_)'], | |
37 | ['regexp.h','RXf_'], | |
9489b85a | 38 | ['sv.h', 'SV(?:[fps]|pad)_'], |
61bc5e5c | 39 | ) { |
b1826b71 NC |
40 | my $file = $tuple->[0]; |
41 | my $pfx = $tuple->[1] || ''; | |
42 | my $path = File::Spec->catfile($headerpath, $file); | |
43 | open my $fh, '<', $path or die "Cannot open $path: $!"; | |
44 | while (<$fh>) { | |
45 | push @names, $1 if (/ \#define \s+ ( $pfx \w+ ) \s+ | |
46 | ( [()|\dx]+ # Parens, '|', digits, 'x' | |
47 | | \(? \d+ \s* << .*? # digits left shifted by anything | |
48 | ) \s* (?: $| \/ \* ) # ending at comment or $ | |
49 | /x); | |
50 | } | |
51 | close $fh; | |
b7254abc | 52 | } |
b1826b71 NC |
53 | |
54 | # Currently only SVt_PVGV and SVt_PVHV aren't macros, but everything we name | |
55 | # should exist, so ensure that the C compile breaks if anything does not. | |
56 | WriteConstants( | |
57 | PROXYSUBS => {push => 'EXPORT_OK'}, | |
58 | NAME => 'B', | |
170a6a5f | 59 | NAMES => [map {ref $_ ? $_ : {name=>$_, macro=>1}} @names], |
b1826b71 NC |
60 | XS_SUBNAME => undef, |
61 | ); |