1use ExtUtils::MakeMaker; 2use ExtUtils::Constant 0.23 'WriteConstants'; 3use File::Spec; 4use strict; 5use warnings; 6 7my $core = grep { $_ eq 'PERL_CORE=1' } @ARGV; 8 9WriteMakefile( 10 NAME => "B", 11 VERSION_FROM => "B.pm", 12 realclean => {FILES=> 'const-c.inc const-xs.inc'}, 13); 14 15my $headerpath; 16if ($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 23my @names = qw(CVf_ANON CVf_CLONE CVf_CLONED CVf_CONST CVf_LVALUE CVf_METHOD 24 CVf_NODEBUG CVf_UNIQUE CVf_WEAKOUTSIDE 25 GVf_IMPORTED_AV GVf_IMPORTED_CV GVf_IMPORTED_HV GVf_IMPORTED_SV 26 HEf_SVKEY 27 SVTYPEMASK SVt_PVGV SVt_PVHV 28 SVf_FAKE SVf_IOK SVf_IVisUV SVf_NOK SVf_POK SVf_READONLY 29 SVf_ROK SVp_IOK SVp_NOK SVp_POK SVpad_OUR SVs_RMG SVs_SMG 30 PAD_FAKELEX_ANON PAD_FAKELEX_MULTI); 31 32if ($] >= 5.009) { 33 push @names, 'CVf_ISXSUB'; 34} else { 35 # Constant not present after 5.8.x 36 push @names, 'AVf_REAL'; 37 # This is only present in 5.10, but it's useful to B::Deparse to be able 38 # to import a dummy value from B 39 push @names, {name=>"OPpPAD_STATE", default=>["IV", "0"]}; 40} 41 42if ($] < 5.011) { 43 # Constant not present after 5.10.x 44 push @names, 'CVf_LOCKED'; 45} 46 47# First element in each tuple is the file; second is a regex snippet 48# giving the prefix to limit the names of symbols to define that come 49# from that file. If none, all symbols will be defined whose values 50# match the pattern below. 51foreach my $tuple (['op_reg_common.h','(?:(?:RXf_)?PMf_)'], 52 ['op.h'], 53 ['cop.h'], 54 ['regexp.h','RXf_']) { 55 my $file = $tuple->[0]; 56 my $pfx = $tuple->[1] || ''; 57 my $path = File::Spec->catfile($headerpath, $file); 58 open my $fh, '<', $path or die "Cannot open $path: $!"; 59 while (<$fh>) { 60 push @names, $1 if (/ \#define \s+ ( $pfx \w+ ) \s+ 61 ( [()|\dx]+ # Parens, '|', digits, 'x' 62 | \(? \d+ \s* << .*? # digits left shifted by anything 63 ) \s* (?: $| \/ \* ) # ending at comment or $ 64 /x); 65 } 66 close $fh; 67} 68 69# Currently only SVt_PVGV and SVt_PVHV aren't macros, but everything we name 70# should exist, so ensure that the C compile breaks if anything does not. 71WriteConstants( 72 PROXYSUBS => {push => 'EXPORT_OK'}, 73 NAME => 'B', 74 NAMES => [map {ref $_ ? $_ : {name=>$_, macro=>1}} @names], 75 XS_SUBNAME => undef, 76); 77