A perl-version portable fix for B coping with CVf_LOCKED being removed in 5.11.
[p5sagit/p5-mst-13.2.git] / ext / B / defsubs_h.PL
1 # Do not remove the following line; MakeMaker relies on it to identify
2 # this file as a template for defsubs.h
3 # Extracting defsubs.h (with variable substitutions)
4 #!perl -w
5 use File::Spec;
6 my (undef, $headerpath) = @ARGV;
7 my ($out) = __FILE__ =~ /(^.*)\.PL/i;
8 $out =~ s/_h$/.h/;
9 unlink $out if -l $out;
10 open(OUT,">$out") || die "Cannot open $file:$!";
11 print "Extracting $out...\n";
12 print OUT <<"END";
13 /*
14  !!! Don't modify this file - it's autogenerated from $0 !!!
15  */
16 END
17
18 foreach my $const (qw(
19                       CVf_ANON
20                       CVf_CLONE
21                       CVf_CLONED
22                       CVf_CONST
23                       CVf_LVALUE
24                       CVf_METHOD
25                       CVf_NODEBUG
26                       CVf_UNIQUE
27                       CVf_WEAKOUTSIDE
28                       GVf_IMPORTED_AV
29                       GVf_IMPORTED_CV
30                       GVf_IMPORTED_HV
31                       GVf_IMPORTED_SV
32                       HEf_SVKEY
33                       SVTYPEMASK
34                       SVf_FAKE
35                       SVf_IOK
36                       SVf_IVisUV
37                       SVf_NOK
38                       SVf_POK
39                       SVf_READONLY
40                       SVf_ROK
41                       SVp_IOK
42                       SVp_NOK
43                       SVp_POK
44                       SVpad_OUR
45                       SVs_RMG
46                       SVs_SMG
47                       SVt_PVGV
48                       SVt_PVHV
49                       PAD_FAKELEX_ANON
50                       PAD_FAKELEX_MULTI
51                       ))
52  {
53   doconst($const);
54  }
55
56 if ($] < 5.009) {
57     # This is only present in 5.10, but it's useful to B::Deparse to be able
58     # to import a dummy value from B
59     doconst(OPpPAD_STATE);
60 }
61
62 if ($] >= 5.009) {
63     # Constant not present in 5.8.x
64     doconst(CVf_ISXSUB);
65 } else {
66     # Constant not present after 5.8.x
67     doconst(AVf_REAL);
68 }  
69
70 if ($] < 5.011) {
71     # Constant not present after 5.10.x
72     doconst(CVf_LOCKED);
73 }
74
75 foreach my $tuple (['op.h'],['cop.h'],['regexp.h','RXf_'])
76  {
77   my $file = $tuple->[0];
78   my $pfx = $tuple->[1] || '';
79   my $path = File::Spec->catfile($headerpath, $file);
80   open(OPH,"$path") || die "Cannot open $path:$!";
81   while (<OPH>)
82    {  
83     doconst($1) if (/#define\s+($pfx\w+)\s+([\(\)\|\dx]+)\s*(?:$|\/\*)/);
84    }  
85   close(OPH);
86  }
87 close(OUT);
88                
89 sub doconst
90 {
91  my $sym = shift;
92  my $l = length($sym);
93  print OUT <<"END";
94  newCONSTSUB(stash,"$sym",newSViv($sym)); 
95  av_push(export_ok,newSVpvn("$sym",$l));
96 END
97 }