This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.002gamma: utils/h2xs.PL
[perl5.git] / vms / gen_shrfls.pl
CommitLineData
a0d0e21e
LW
1# Create global symbol declarations, transfer vector, and
2# linker options files for PerlShr.
3#
4# Input:
5# $cflags - command line qualifiers passed to cc when preprocesing perl.h
6# Note: A rather simple-minded attempt is made to restore quotes to
7# a /Define clause - use with care.
8# $objsuffix - file type (including '.') used for object files.
748a9306
LW
9# $libperl - Perl object library.
10# $extnames - package names for static extensions (used to generate
11# linker options file entries for boot functions)
12# $rtlopt - name of options file specifying RTLs to which PerlShr.Exe
13# must be linked
a0d0e21e
LW
14#
15# Output:
16# PerlShr_Attr.Opt - linker options file which speficies that global vars
17# be placed in NOSHR,WRT psects. Use when linking any object files
18# against PerlShr.Exe, since cc places global vars in SHR,WRT psects
19# by default.
748a9306 20# PerlShr_Bld.Opt - declares universal symbols for PerlShr.Exe
a0d0e21e
LW
21# Perlshr_Gbl*.Mar, Perlshr_Gbl*.Obj (VAX only) - declares global symbols
22# for global vars (done here because gcc can't globaldef) and creates
23# transfer vectors for routines on a VAX.
24# PerlShr_Gbl.Opt (VAX only) - list of PerlShr_Gbl*.Obj, used for input
25# to the linker when building PerlShr.Exe.
26#
27# To do:
28# - figure out a good way to collect global vars in one psect, given that
29# we can't use globaldef because of gcc.
30# - then, check for existing files and preserve symbol and transfer vector
31# order for upward compatibility
32# - then, add GSMATCH to options file - but how do we insure that new
33# library has everything old one did
34# (i.e. /Define=DEBUGGING,EMBED,MULTIPLICITY)?
35#
36# Author: Charles Bailey bailey@genetics.upenn.edu
e518068a 37# Revised: 4-Dec-1995
a0d0e21e
LW
38
39require 5.000;
40
41$debug = $ENV{'GEN_SHRFLS_DEBUG'};
42$cc_cmd = shift @ARGV;
4633a7c4
LW
43
44# Someday, we'll have $GetSyI built into perl . . .
45$isvax = `\$ Write Sys\$Output F\$GetSyI(\"HW_MODEL\")` <= 1024;
46print "\$isvax: \\$isvax\\\n" if $debug;
47
a0d0e21e 48print "Input \$cc_cmd: \\$cc_cmd\\\n" if $debug;
4633a7c4 49$docc = ($cc_cmd !~ /^~~/);
a0d0e21e
LW
50print "\$docc = $docc\n" if $debug;
51
52if ($docc) {
53 # put quotes back onto defines - they were removed by DCL on the way in
54 if (($prefix,$defines,$suffix) =
55 ($cc_cmd =~ m#(.*)/Define=(.*?)([/\s].*)#i)) {
56 $defines =~ s/^\((.*)\)$/$1/;
57 @defines = split(/,/,$defines);
58 $cc_cmd = "$prefix/Define=(" . join(',',grep($_ = "\"$_\"",@defines))
59 . ')' . $suffix;
60 }
61 print "Filtered \$cc_cmd: \\$cc_cmd\\\n" if $debug;
62
4633a7c4
LW
63 # check for gcc - if present, we'll need to use MACRO hack to
64 # define global symbols for shared variables
65 $isvaxc = 0;
66 $isgcc = `$cc_cmd _nla0:/Version` =~ /GNU/
67 or 0; # make debug output nice
e518068a 68 $isvaxc = (!$isgcc && $isvax && `$cc_cmd /prefix=all _nla0:` =~ /IVQUAL/)
4633a7c4
LW
69 or 0; # again, make debug output nice
70 print "\$isgcc: $isgcc\n" if $debug;
71 print "\$isvaxc: $isvaxc\n" if $debug;
72
a0d0e21e
LW
73 if (-f 'perl.h') { $dir = '[]'; }
74 elsif (-f '[-]perl.h') { $dir = '[-]'; }
75 else { die "$0: Can't find perl.h\n"; }
76}
4633a7c4 77else {
482b294c
PP
78 ($junk,$ccvers,$cpp_file,$cc_cmd) = split(/~~/,$cc_cmd,4);
79 $isgcc = $cc_cmd =~ /case_hack/i
4633a7c4 80 or 0; # for nice debug output
482b294c 81 $isvaxc = (!$isgcc && $cc_cmd !~ /standard=/i)
4633a7c4
LW
82 or 0; # again, for nice debug output
83 print "\$isgcc: \\$isgcc\\\n" if $debug;
84 print "\$isvaxc: \\$isvaxc\\\n" if $debug;
85 print "Not running cc, preprocesor output in \\$cpp_file\\\n" if $debug;
86}
a0d0e21e
LW
87
88$objsuffix = shift @ARGV;
89print "\$objsuffix: \\$objsuffix\\\n" if $debug;
748a9306
LW
90$dbgprefix = shift @ARGV;
91print "\$dbgprefix: \\$dbgprefix\\\n" if $debug;
92$olbsuffix = shift @ARGV;
93print "\$olbsuffix: \\$olbsuffix\\\n" if $debug;
94$libperl = "${dbgprefix}libperl$olbsuffix";
95$extnames = shift @ARGV;
96print "\$extnames: \\$extnames\\\n" if $debug;
97$rtlopt = shift @ARGV;
98print "\$rtlopt: \\$rtlopt\\\n" if $debug;
a0d0e21e 99
e518068a 100# This part gets tricky. VAXC creates global symbols for each of the
4633a7c4
LW
101# constants in an enum if that enum is ever used as the data type of a
102# global[dr]ef. We have to detect enums which are used in this way, so we
103# can set up the constants as universal symbols, since anything which
104# #includes perl.h will want to resolve these global symbols.
105# We're using a weak test here - we basically know that the only enums
106# we need to handle now are the big one in opcode.h, and the
107# "typedef enum { ... } expectation" in perl.h, so we hard code
108# appropriate tests below. Since we can't know in general whether a given
109# enum will be used elsewhere in a globaldef, it's hard to decide a
110# priori whether its constants need to be treated as global symbols.
111sub scan_enum {
112 my($line) = @_;
113
114 return unless $isvaxc;
115
116 return unless /^\s+(OP|X)/; # we only want opcode and expectation enums
117 print "\tchecking for enum constant\n" if $debug > 1;
118 $line =~ s#/\*.+##;
119 $line =~ s/,?\s*\n?$//;
120 print "\tfiltered to \\$line\\\n" if $debug > 1;
121 if ($line =~ /(\w+)$/) {
c07a80fd
PP
122 print "\tconstant name is \\$1\\\n" if $debug > 1;
123 $enums{$1}++;
4633a7c4
LW
124 }
125}
a0d0e21e
LW
126
127sub scan_var {
128 my($line) = @_;
129
748a9306 130 print "\tchecking for global variable\n" if $debug > 1;
a0d0e21e
LW
131 $line =~ s/INIT\(.*\)//;
132 $line =~ s/\[.*//;
133 $line =~ s/=.*//;
134 $line =~ s/\W*;?\s*$//;
748a9306 135 print "\tfiltered to \\$line\\\n" if $debug > 1;
a0d0e21e 136 if ($line =~ /(\w+)$/) {
748a9306 137 print "\tvar name is \\$1\\\n" if $debug > 1;
a0d0e21e
LW
138 $vars{$1}++;
139 }
140}
141
142sub scan_func {
143 my($line) = @_;
144
748a9306 145 print "\tchecking for global routine\n" if $debug > 1;
a0d0e21e 146 if ( /(\w+)\s+\(/ ) {
748a9306 147 print "\troutine name is \\$1\\\n" if $debug > 1;
a0d0e21e 148 if ($1 eq 'main' || $1 eq 'perl_init_ext') {
748a9306 149 print "\tskipped\n" if $debug > 1;
a0d0e21e 150 }
4633a7c4 151 else { $fcns{$1}++ }
a0d0e21e
LW
152 }
153}
154
c07a80fd 155$used_expectation_enum = $used_opcode_enum = 0; # avoid warnings
a0d0e21e
LW
156if ($docc) {
157 open(CPP,"${cc_cmd}/NoObj/PreProc=Sys\$Output ${dir}perl.h|")
158 or die "$0: Can't preprocess ${dir}perl.h: $!\n";
159}
160else {
161 open(CPP,"$cpp_file") or die "$0: Can't read $cpp_file: $!\n";
162}
163LINE: while (<CPP>) {
164 while (/^#.*vmsish\.h/i .. /^#.*perl\.h/i) {
165 while (/__VMS_PROTOTYPES__/i .. /__VMS_SEPYTOTORP__/i) {
748a9306 166 print "vms_proto>> $_" if $debug > 2;
a0d0e21e
LW
167 &scan_func($_);
168 if (/^EXT/) { &scan_var($_); }
169 last LINE unless $_ = <CPP>;
170 }
748a9306 171 print "vmsish.h>> $_" if $debug > 2;
a0d0e21e
LW
172 if (/^EXT/) { &scan_var($_); }
173 last LINE unless $_ = <CPP>;
174 }
175 while (/^#.*opcode\.h/i .. /^#.*perl\.h/i) {
748a9306 176 print "opcode.h>> $_" if $debug > 2;
a0d0e21e
LW
177 if (/^OP \*\s/) { &scan_func($_); }
178 if (/^EXT/) { &scan_var($_); }
4633a7c4
LW
179 if (/^\s+OP_/) { &scan_enum($_); }
180 last LINE unless $_ = <CPP>;
181 }
182 while (/^typedef enum/ .. /^\}/) {
183 print "global enum>> $_" if $debug > 2;
184 &scan_enum($_);
a0d0e21e
LW
185 last LINE unless $_ = <CPP>;
186 }
187 while (/^#.*proto\.h/i .. /^#.*perl\.h/i) {
748a9306 188 print "proto.h>> $_" if $debug > 2;
a0d0e21e
LW
189 &scan_func($_);
190 if (/^EXT/) { &scan_var($_); }
191 last LINE unless $_ = <CPP>;
192 }
748a9306 193 print $_ if $debug > 3;
c07a80fd
PP
194 if (($type) = /^EXT\s+(\w+)/) {
195 if ($isvaxc) {
196 if ($type eq 'expectation') {
197 $used_expectation_enum++;
198 print "\tsaw global use of enum \"expectation\"\n" if $debug > 1;
199 }
200 if ($type eq 'opcode') {
201 $used_opcode_enum++;
202 print "\tsaw global use of enum \"opcode\"\n" if $debug > 1;
203 }
204 }
205 &scan_var($_);
206 }
a0d0e21e
LW
207}
208close CPP;
209while (<DATA>) {
210 next if /^#/;
211 s/\s+#.*\n//;
4633a7c4 212 next if /^\s*$/;
a0d0e21e 213 ($key,$array) = split('=',$_);
748a9306 214 print "Adding $key to \%$array list\n" if $debug > 1;
a0d0e21e
LW
215 ${$array}{$key}++;
216}
748a9306
LW
217foreach (split /\s+/, $extnames) {
218 my($pkgname) = $_;
219 $pkgname =~ s/::/__/g;
4633a7c4
LW
220 $fcns{"boot_$pkgname"}++;
221 print "Adding boot_$pkgname to \%fcns (for extension $_)\n" if $debug;
748a9306 222}
a0d0e21e 223
c07a80fd
PP
224# If we're using VAXC, fold in the names of the constants for enums
225# we've seen as the type of global vars.
226if ($isvaxc) {
227 foreach (keys %enums) {
228 if (/^OP/) {
229 $vars{$_}++ if $used_opcode_enum;
230 next;
231 }
232 if (/^X/) {
233 $vars{$_}++ if $used_expectation_enum;
234 next;
235 }
236 print STDERR "Unrecognized enum constant \"$_\" ignored\n";
237 }
238}
239
a0d0e21e
LW
240# Eventually, we'll check against existing copies here, so we can add new
241# symbols to an existing options file in an upwardly-compatible manner.
242
243$marord++;
748a9306
LW
244open(OPTBLD,">${dir}${dbgprefix}perlshr_bld.opt")
245 or die "$0: Can't write to ${dir}${dbgprefix}perlshr_bld.opt: $!\n";
a0d0e21e
LW
246if ($isvax) {
247 open(MAR,">${dir}perlshr_gbl${marord}.mar")
248 or die "$0: Can't write to ${dir}perlshr_gbl${marord}.mar: $!\n";
748a9306 249 print MAR "\t.title perlshr_gbl$marord\n";
a0d0e21e 250}
a0d0e21e 251foreach $var (sort keys %vars) {
748a9306
LW
252 if ($isvax) { print OPTBLD "UNIVERSAL=$var\n"; }
253 else { print OPTBLD "SYMBOL_VECTOR=($var=DATA)\n"; }
4633a7c4
LW
254 # This hack brought to you by the lack of a globaldef in gcc.
255 if ($isgcc) {
a0d0e21e
LW
256 if ($count++ > 200) { # max 254 psects/file
257 print MAR "\t.end\n";
258 close MAR;
259 $marord++;
260 open(MAR,">${dir}perlshr_gbl${marord}.mar")
261 or die "$0: Can't write to ${dir}perlshr_gbl${marord}.mar: $!\n";
748a9306 262 print MAR "\t.title perlshr_gbl$marord\n";
a0d0e21e
LW
263 $count = 0;
264 }
a0d0e21e
LW
265 print MAR "\t.psect ${var},long,pic,ovr,rd,wrt,noexe,noshr\n";
266 print MAR "\t${var}:: .blkl 1\n";
267 }
268}
269
270print MAR "\t.psect \$transfer_vec,pic,rd,nowrt,exe,shr\n" if ($isvax);
4633a7c4 271foreach $func (sort keys %fcns) {
a0d0e21e
LW
272 if ($isvax) {
273 print MAR "\t.transfer $func\n";
274 print MAR "\t.mask $func\n";
4633a7c4 275 print MAR "\tjmp G\^${func}+2\n";
a0d0e21e 276 }
748a9306 277 else { print OPTBLD "SYMBOL_VECTOR=($func=PROCEDURE)\n"; }
a0d0e21e 278}
4633a7c4
LW
279if ($isvax) {
280 print MAR "\t.end\n";
281 close MAR;
282}
a0d0e21e 283
4633a7c4
LW
284open(OPTATTR,">${dir}perlshr_attr.opt")
285 or die "$0: Can't write to ${dir}perlshr_attr.opt: $!\n";
286print OPTATTR "PSECT_ATTR=\$CHAR_STRING_CONSTANTS,PIC,SHR,NOEXE,RD,NOWRT\n";
287foreach $var (sort keys %vars) {
288 print OPTATTR "PSECT_ATTR=${var},PIC,OVR,RD,NOEXE,WRT,NOSHR\n";
289}
a0d0e21e 290close OPTATTR;
4633a7c4 291
748a9306 292$incstr = 'perl,globals';
a0d0e21e 293if ($isvax) {
a0d0e21e
LW
294 $drvrname = "Compile_shrmars.tmp_".time;
295 open (DRVR,">$drvrname") or die "$0: Can't write to $drvrname: $!\n";
296 print DRVR "\$ Set NoOn\n";
297 print DRVR "\$ Delete/NoLog/NoConfirm $drvrname;\n";
298 print DRVR "\$ old_proc_vfy = F\$Environment(\"VERIFY_PROCEDURE\")\n";
299 print DRVR "\$ old_img_vfy = F\$Environment(\"VERIFY_IMAGE\")\n";
748a9306 300 print DRVR "\$ MCR $^X -e \"\$ENV{'LIBPERL_RDT'} = (stat('$libperl'))[9]\"\n";
a0d0e21e 301 print DRVR "\$ Set Verify\n";
748a9306 302 print DRVR "\$ If F\$Search(\"$libperl\").eqs.\"\" Then Library/Object/Create $libperl\n";
a0d0e21e 303 do {
748a9306 304 $incstr .= ",perlshr_gbl$marord";
a0d0e21e 305 print DRVR "\$ Macro/NoDebug/Object=PerlShr_Gbl${marord}$objsuffix PerlShr_Gbl$marord.Mar\n";
748a9306 306 print DRVR "\$ Library/Object/Replace/Log $libperl PerlShr_Gbl${marord}$objsuffix\n";
a0d0e21e 307 } while (--$marord);
748a9306
LW
308 # We had to have a working miniperl to run this program; it's probably the
309 # one we just built. It depended on LibPerl, which will be changed when
310 # the PerlShr_Gbl* modules get inserted, so miniperl will be out of date,
311 # and so, therefore, will all of its dependents . . .
312 # We touch LibPerl here so it'll be back 'in date', and we won't rebuild
313 # miniperl etc., and therefore LibPerl, the next time we invoke MM[KS].
a0d0e21e 314 print DRVR "\$ old_proc_vfy = F\$Verify(old_proc_vfy,old_img_vfy)\n";
748a9306 315 print DRVR "\$ MCR $^X -e \"utime 0, \$ENV{'LIBPERL_RDT'}, '$libperl'\"\n";
a0d0e21e 316 close DRVR;
a0d0e21e 317}
748a9306
LW
318
319# Include object modules and RTLs in options file
320# Linker wants /Include and /Library on different lines
321print OPTBLD "$libperl/Include=($incstr)\n";
322print OPTBLD "$libperl/Library\n";
323open(RTLOPT,$rtlopt) or die "$0: Can't read $rtlopt: $!\n";
324while (<RTLOPT>) { print OPTBLD; }
325close RTLOPT;
326close OPTBLD;
327
328exec "\$ \@$drvrname" if $isvax;
329
330
a0d0e21e
LW
331__END__
332
333# Oddball cases, so we can keep the perl.h scan above simple
334error=vars # declared in perl.h only when DOINIT defined by INTERN.h
335rcsid=vars # declared in perl.c
336regarglen=vars # declared in regcomp.h
337regdummy=vars # declared in regcomp.h
338regkind=vars # declared in regcomp.h
339simple=vars # declared in regcomp.h
340varies=vars # declared in regcomp.h
341watchaddr=vars # declared in run.c
342watchok=vars # declared in run.c
343yychar=vars # generated by byacc in perly.c
344yycheck=vars # generated by byacc in perly.c
345yydebug=vars # generated by byacc in perly.c
346yydefred=vars # generated by byacc in perly.c
347yydgoto=vars # generated by byacc in perly.c
348yyerrflag=vars # generated by byacc in perly.c
349yygindex=vars # generated by byacc in perly.c
350yylen=vars # generated by byacc in perly.c
351yylhs=vars # generated by byacc in perly.c
352yylval=vars # generated by byacc in perly.c
353yyname=vars # generated by byacc in perly.c
354yynerrs=vars # generated by byacc in perly.c
355yyrindex=vars # generated by byacc in perly.c
356yyrule=vars # generated by byacc in perly.c
357yysindex=vars # generated by byacc in perly.c
358yytable=vars # generated by byacc in perly.c
359yyval=vars # generated by byacc in perly.c