| 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 |
my $headerpath; |
| 10 |
if ($core) { |
| 11 |
$headerpath = File::Spec->catdir(File::Spec->updir, File::Spec->updir); |
| 12 |
} else { |
| 13 |
require Config; |
| 14 |
$headerpath = File::Spec->catdir($Config::Config{archlibexp}, "CORE"); |
| 15 |
} |
| 16 |
|
| 17 |
my @names = ({ name => 'HEf_SVKEY', macro => 1, type => "IV" }, |
| 18 |
qw(SVTYPEMASK SVt_PVGV SVt_PVHV PAD_FAKELEX_ANON |
| 19 |
PAD_FAKELEX_MULTI SVpad_STATE SVpad_TYPED SVpad_OUR)); |
| 20 |
|
| 21 |
my @depend; |
| 22 |
|
| 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. |
| 27 |
foreach my $tuple (['cop.h'], |
| 28 |
['cv.h', 'CVf'], |
| 29 |
['gv.h', 'G[PV]f'], |
| 30 |
['op.h'], |
| 31 |
['opcode.h', 'OPp'], |
| 32 |
['op_reg_common.h','(?:(?:RXf_)?PMf_)'], |
| 33 |
['pad.h','PADNAMEf_'], |
| 34 |
['regexp.h','RXf_'], |
| 35 |
['sv.h', 'SV(?:[fps]|pad)_'], |
| 36 |
) { |
| 37 |
my $file = $tuple->[0]; |
| 38 |
my $pfx = $tuple->[1] || ''; |
| 39 |
my $path = File::Spec->catfile($headerpath, $file); |
| 40 |
push @depend, $path; |
| 41 |
open my $fh, '<', $path or die "Cannot open $path: $!"; |
| 42 |
while (<$fh>) { |
| 43 |
push @names, $1 if (/ ^ \s* \# \s* define \s+ ( $pfx \w+ ) \s+ |
| 44 |
( [()|\dx]+ [UuLl]{0,2} # Parens, '|', digits, 'x', |
| 45 |
# followed by optional long, |
| 46 |
# unsigned qualifiers |
| 47 |
| 0x[0-9a-fA-F]+ # hex values |
| 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); |
| 53 |
} |
| 54 |
close $fh; |
| 55 |
} |
| 56 |
|
| 57 |
WriteMakefile( |
| 58 |
NAME => "B", |
| 59 |
VERSION_FROM => "B.pm", |
| 60 |
realclean => {FILES=> 'const-c.inc const-xs.inc'}, |
| 61 |
depend => {'Makefile' => "@depend"}, |
| 62 |
); |
| 63 |
|
| 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. |
| 66 |
WriteConstants( |
| 67 |
PROXYSUBS => {push => 'EXPORT_OK'}, |
| 68 |
NAME => 'B', |
| 69 |
NAMES => [map {ref $_ ? $_ : {name=>$_, macro=>1, type=>"UV"}} @names], |
| 70 |
XS_SUBNAME => undef, |
| 71 |
); |