Commit | Line | Data |
a0d0e21e |
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 |
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 |
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 |
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 |
a5f75d66 |
37 | # Revised: 20-Feb-1996 |
a0d0e21e |
38 | |
39 | require 5.000; |
40 | |
41 | $debug = $ENV{'GEN_SHRFLS_DEBUG'}; |
a5f75d66 |
42 | |
43 | if ($ARGV[0] eq '-f') { |
44 | open(INP,$ARGV[1]) or die "Can't read input file $ARGV[1]: $!\n"; |
45 | print "Input taken from file $ARGV[1]\n" if $debug; |
46 | @ARGV = (); |
47 | while (<INP>) { |
48 | chomp; |
49 | push(@ARGV,split(/\|/,$_)); |
50 | } |
51 | close INP; |
52 | print "Read input data | ",join(' | ',@ARGV)," |\n" if $debug > 1; |
53 | } |
54 | |
a0d0e21e |
55 | $cc_cmd = shift @ARGV; |
4633a7c4 |
56 | |
57 | # Someday, we'll have $GetSyI built into perl . . . |
58 | $isvax = `\$ Write Sys\$Output F\$GetSyI(\"HW_MODEL\")` <= 1024; |
59 | print "\$isvax: \\$isvax\\\n" if $debug; |
60 | |
a0d0e21e |
61 | print "Input \$cc_cmd: \\$cc_cmd\\\n" if $debug; |
4633a7c4 |
62 | $docc = ($cc_cmd !~ /^~~/); |
a0d0e21e |
63 | print "\$docc = $docc\n" if $debug; |
64 | |
65 | if ($docc) { |
66 | # put quotes back onto defines - they were removed by DCL on the way in |
67 | if (($prefix,$defines,$suffix) = |
68 | ($cc_cmd =~ m#(.*)/Define=(.*?)([/\s].*)#i)) { |
69 | $defines =~ s/^\((.*)\)$/$1/; |
70 | @defines = split(/,/,$defines); |
71 | $cc_cmd = "$prefix/Define=(" . join(',',grep($_ = "\"$_\"",@defines)) |
72 | . ')' . $suffix; |
73 | } |
74 | print "Filtered \$cc_cmd: \\$cc_cmd\\\n" if $debug; |
75 | |
4633a7c4 |
76 | # check for gcc - if present, we'll need to use MACRO hack to |
77 | # define global symbols for shared variables |
78 | $isvaxc = 0; |
79 | $isgcc = `$cc_cmd _nla0:/Version` =~ /GNU/ |
80 | or 0; # make debug output nice |
e518068a |
81 | $isvaxc = (!$isgcc && $isvax && `$cc_cmd /prefix=all _nla0:` =~ /IVQUAL/) |
4633a7c4 |
82 | or 0; # again, make debug output nice |
83 | print "\$isgcc: $isgcc\n" if $debug; |
84 | print "\$isvaxc: $isvaxc\n" if $debug; |
85 | |
a0d0e21e |
86 | if (-f 'perl.h') { $dir = '[]'; } |
87 | elsif (-f '[-]perl.h') { $dir = '[-]'; } |
88 | else { die "$0: Can't find perl.h\n"; } |
89 | } |
4633a7c4 |
90 | else { |
a5f75d66 |
91 | ($junk,$junk,$cpp_file,$cc_cmd) = split(/~~/,$cc_cmd,4); |
482b294c |
92 | $isgcc = $cc_cmd =~ /case_hack/i |
4633a7c4 |
93 | or 0; # for nice debug output |
482b294c |
94 | $isvaxc = (!$isgcc && $cc_cmd !~ /standard=/i) |
4633a7c4 |
95 | or 0; # again, for nice debug output |
96 | print "\$isgcc: \\$isgcc\\\n" if $debug; |
97 | print "\$isvaxc: \\$isvaxc\\\n" if $debug; |
98 | print "Not running cc, preprocesor output in \\$cpp_file\\\n" if $debug; |
99 | } |
a0d0e21e |
100 | |
101 | $objsuffix = shift @ARGV; |
102 | print "\$objsuffix: \\$objsuffix\\\n" if $debug; |
748a9306 |
103 | $dbgprefix = shift @ARGV; |
104 | print "\$dbgprefix: \\$dbgprefix\\\n" if $debug; |
105 | $olbsuffix = shift @ARGV; |
106 | print "\$olbsuffix: \\$olbsuffix\\\n" if $debug; |
107 | $libperl = "${dbgprefix}libperl$olbsuffix"; |
108 | $extnames = shift @ARGV; |
109 | print "\$extnames: \\$extnames\\\n" if $debug; |
110 | $rtlopt = shift @ARGV; |
111 | print "\$rtlopt: \\$rtlopt\\\n" if $debug; |
a0d0e21e |
112 | |
e518068a |
113 | # This part gets tricky. VAXC creates global symbols for each of the |
4633a7c4 |
114 | # constants in an enum if that enum is ever used as the data type of a |
115 | # global[dr]ef. We have to detect enums which are used in this way, so we |
116 | # can set up the constants as universal symbols, since anything which |
117 | # #includes perl.h will want to resolve these global symbols. |
118 | # We're using a weak test here - we basically know that the only enums |
119 | # we need to handle now are the big one in opcode.h, and the |
120 | # "typedef enum { ... } expectation" in perl.h, so we hard code |
121 | # appropriate tests below. Since we can't know in general whether a given |
122 | # enum will be used elsewhere in a globaldef, it's hard to decide a |
123 | # priori whether its constants need to be treated as global symbols. |
124 | sub scan_enum { |
125 | my($line) = @_; |
126 | |
127 | return unless $isvaxc; |
128 | |
129 | return unless /^\s+(OP|X)/; # we only want opcode and expectation enums |
130 | print "\tchecking for enum constant\n" if $debug > 1; |
131 | $line =~ s#/\*.+##; |
132 | $line =~ s/,?\s*\n?$//; |
133 | print "\tfiltered to \\$line\\\n" if $debug > 1; |
134 | if ($line =~ /(\w+)$/) { |
c07a80fd |
135 | print "\tconstant name is \\$1\\\n" if $debug > 1; |
136 | $enums{$1}++; |
4633a7c4 |
137 | } |
138 | } |
a0d0e21e |
139 | |
140 | sub scan_var { |
141 | my($line) = @_; |
142 | |
748a9306 |
143 | print "\tchecking for global variable\n" if $debug > 1; |
a0d0e21e |
144 | $line =~ s/INIT\(.*\)//; |
145 | $line =~ s/\[.*//; |
146 | $line =~ s/=.*//; |
147 | $line =~ s/\W*;?\s*$//; |
748a9306 |
148 | print "\tfiltered to \\$line\\\n" if $debug > 1; |
a0d0e21e |
149 | if ($line =~ /(\w+)$/) { |
748a9306 |
150 | print "\tvar name is \\$1\\\n" if $debug > 1; |
a0d0e21e |
151 | $vars{$1}++; |
152 | } |
153 | } |
154 | |
155 | sub scan_func { |
156 | my($line) = @_; |
157 | |
748a9306 |
158 | print "\tchecking for global routine\n" if $debug > 1; |
b9f71c63 |
159 | if ( $line =~ /(\w+)\s+\(/ ) { |
748a9306 |
160 | print "\troutine name is \\$1\\\n" if $debug > 1; |
a0d0e21e |
161 | if ($1 eq 'main' || $1 eq 'perl_init_ext') { |
748a9306 |
162 | print "\tskipped\n" if $debug > 1; |
a0d0e21e |
163 | } |
4633a7c4 |
164 | else { $fcns{$1}++ } |
a0d0e21e |
165 | } |
166 | } |
167 | |
c07a80fd |
168 | $used_expectation_enum = $used_opcode_enum = 0; # avoid warnings |
a0d0e21e |
169 | if ($docc) { |
170 | open(CPP,"${cc_cmd}/NoObj/PreProc=Sys\$Output ${dir}perl.h|") |
171 | or die "$0: Can't preprocess ${dir}perl.h: $!\n"; |
172 | } |
173 | else { |
a5f75d66 |
174 | open(CPP,"$cpp_file") or die "$0: Can't read preprocessed file $cpp_file: $!\n"; |
a0d0e21e |
175 | } |
176 | LINE: while (<CPP>) { |
177 | while (/^#.*vmsish\.h/i .. /^#.*perl\.h/i) { |
178 | while (/__VMS_PROTOTYPES__/i .. /__VMS_SEPYTOTORP__/i) { |
748a9306 |
179 | print "vms_proto>> $_" if $debug > 2; |
b9f71c63 |
180 | if (/^EXT/) { &scan_var($_); } |
181 | else { &scan_func($_); } |
a0d0e21e |
182 | last LINE unless $_ = <CPP>; |
183 | } |
748a9306 |
184 | print "vmsish.h>> $_" if $debug > 2; |
a0d0e21e |
185 | if (/^EXT/) { &scan_var($_); } |
186 | last LINE unless $_ = <CPP>; |
187 | } |
188 | while (/^#.*opcode\.h/i .. /^#.*perl\.h/i) { |
748a9306 |
189 | print "opcode.h>> $_" if $debug > 2; |
a0d0e21e |
190 | if (/^OP \*\s/) { &scan_func($_); } |
191 | if (/^EXT/) { &scan_var($_); } |
4633a7c4 |
192 | if (/^\s+OP_/) { &scan_enum($_); } |
193 | last LINE unless $_ = <CPP>; |
194 | } |
195 | while (/^typedef enum/ .. /^\}/) { |
196 | print "global enum>> $_" if $debug > 2; |
197 | &scan_enum($_); |
a0d0e21e |
198 | last LINE unless $_ = <CPP>; |
199 | } |
200 | while (/^#.*proto\.h/i .. /^#.*perl\.h/i) { |
748a9306 |
201 | print "proto.h>> $_" if $debug > 2; |
b9f71c63 |
202 | if (/^EXT/) { &scan_var($_); } |
203 | else { &scan_func($_); } |
a0d0e21e |
204 | last LINE unless $_ = <CPP>; |
205 | } |
748a9306 |
206 | print $_ if $debug > 3; |
c07a80fd |
207 | if (($type) = /^EXT\s+(\w+)/) { |
208 | if ($isvaxc) { |
209 | if ($type eq 'expectation') { |
210 | $used_expectation_enum++; |
211 | print "\tsaw global use of enum \"expectation\"\n" if $debug > 1; |
212 | } |
213 | if ($type eq 'opcode') { |
214 | $used_opcode_enum++; |
215 | print "\tsaw global use of enum \"opcode\"\n" if $debug > 1; |
216 | } |
217 | } |
218 | &scan_var($_); |
219 | } |
a0d0e21e |
220 | } |
221 | close CPP; |
b9f71c63 |
222 | |
223 | |
224 | # Kluge to determine whether we need to add EMBED prefix to |
740ce14c |
225 | # symbols read from local list. vmsreaddirversions() is a VMS- |
b9f71c63 |
226 | # specific function whose Perl_ prefix is added in vmsish.h |
227 | # if EMBED is #defined. |
740ce14c |
228 | $embed = exists($fcns{'Perl_vmsreaddirversions'}) ? 'Perl_' : ''; |
a0d0e21e |
229 | while (<DATA>) { |
230 | next if /^#/; |
231 | s/\s+#.*\n//; |
4633a7c4 |
232 | next if /^\s*$/; |
a0d0e21e |
233 | ($key,$array) = split('=',$_); |
b9f71c63 |
234 | $key = "$embed$key"; |
748a9306 |
235 | print "Adding $key to \%$array list\n" if $debug > 1; |
a0d0e21e |
236 | ${$array}{$key}++; |
237 | } |
748a9306 |
238 | foreach (split /\s+/, $extnames) { |
239 | my($pkgname) = $_; |
240 | $pkgname =~ s/::/__/g; |
4633a7c4 |
241 | $fcns{"boot_$pkgname"}++; |
242 | print "Adding boot_$pkgname to \%fcns (for extension $_)\n" if $debug; |
748a9306 |
243 | } |
a0d0e21e |
244 | |
c07a80fd |
245 | # If we're using VAXC, fold in the names of the constants for enums |
246 | # we've seen as the type of global vars. |
247 | if ($isvaxc) { |
248 | foreach (keys %enums) { |
249 | if (/^OP/) { |
250 | $vars{$_}++ if $used_opcode_enum; |
251 | next; |
252 | } |
253 | if (/^X/) { |
254 | $vars{$_}++ if $used_expectation_enum; |
255 | next; |
256 | } |
257 | print STDERR "Unrecognized enum constant \"$_\" ignored\n"; |
258 | } |
259 | } |
cbb1213b |
260 | elsif ($isgcc) { |
261 | # gcc creates this as a SHR,WRT psect in globals.c, but we |
262 | # don't see it in the perl.h scan, since it's only declared |
263 | # if DOINIT is #defined. Bleah. It's cheaper to just add |
264 | # it by hand than to add /Define=DOINIT to the preprocessing |
265 | # run and wade through all the extra junk. |
266 | $vars{'Error'}++; |
267 | } |
c07a80fd |
268 | |
a0d0e21e |
269 | # Eventually, we'll check against existing copies here, so we can add new |
270 | # symbols to an existing options file in an upwardly-compatible manner. |
271 | |
272 | $marord++; |
748a9306 |
273 | open(OPTBLD,">${dir}${dbgprefix}perlshr_bld.opt") |
274 | or die "$0: Can't write to ${dir}${dbgprefix}perlshr_bld.opt: $!\n"; |
a0d0e21e |
275 | if ($isvax) { |
276 | open(MAR,">${dir}perlshr_gbl${marord}.mar") |
277 | or die "$0: Can't write to ${dir}perlshr_gbl${marord}.mar: $!\n"; |
748a9306 |
278 | print MAR "\t.title perlshr_gbl$marord\n"; |
a0d0e21e |
279 | } |
a0d0e21e |
280 | foreach $var (sort keys %vars) { |
748a9306 |
281 | if ($isvax) { print OPTBLD "UNIVERSAL=$var\n"; } |
282 | else { print OPTBLD "SYMBOL_VECTOR=($var=DATA)\n"; } |
4633a7c4 |
283 | # This hack brought to you by the lack of a globaldef in gcc. |
284 | if ($isgcc) { |
a0d0e21e |
285 | if ($count++ > 200) { # max 254 psects/file |
286 | print MAR "\t.end\n"; |
287 | close MAR; |
288 | $marord++; |
289 | open(MAR,">${dir}perlshr_gbl${marord}.mar") |
290 | or die "$0: Can't write to ${dir}perlshr_gbl${marord}.mar: $!\n"; |
748a9306 |
291 | print MAR "\t.title perlshr_gbl$marord\n"; |
a0d0e21e |
292 | $count = 0; |
293 | } |
a0d0e21e |
294 | print MAR "\t.psect ${var},long,pic,ovr,rd,wrt,noexe,noshr\n"; |
295 | print MAR "\t${var}:: .blkl 1\n"; |
296 | } |
297 | } |
298 | |
299 | print MAR "\t.psect \$transfer_vec,pic,rd,nowrt,exe,shr\n" if ($isvax); |
4633a7c4 |
300 | foreach $func (sort keys %fcns) { |
a0d0e21e |
301 | if ($isvax) { |
302 | print MAR "\t.transfer $func\n"; |
303 | print MAR "\t.mask $func\n"; |
4633a7c4 |
304 | print MAR "\tjmp G\^${func}+2\n"; |
a0d0e21e |
305 | } |
748a9306 |
306 | else { print OPTBLD "SYMBOL_VECTOR=($func=PROCEDURE)\n"; } |
a0d0e21e |
307 | } |
4633a7c4 |
308 | if ($isvax) { |
309 | print MAR "\t.end\n"; |
310 | close MAR; |
311 | } |
a0d0e21e |
312 | |
4633a7c4 |
313 | open(OPTATTR,">${dir}perlshr_attr.opt") |
314 | or die "$0: Can't write to ${dir}perlshr_attr.opt: $!\n"; |
315 | print OPTATTR "PSECT_ATTR=\$CHAR_STRING_CONSTANTS,PIC,SHR,NOEXE,RD,NOWRT\n"; |
316 | foreach $var (sort keys %vars) { |
317 | print OPTATTR "PSECT_ATTR=${var},PIC,OVR,RD,NOEXE,WRT,NOSHR\n"; |
318 | } |
a0d0e21e |
319 | close OPTATTR; |
4633a7c4 |
320 | |
748a9306 |
321 | $incstr = 'perl,globals'; |
a0d0e21e |
322 | if ($isvax) { |
a0d0e21e |
323 | $drvrname = "Compile_shrmars.tmp_".time; |
324 | open (DRVR,">$drvrname") or die "$0: Can't write to $drvrname: $!\n"; |
325 | print DRVR "\$ Set NoOn\n"; |
326 | print DRVR "\$ Delete/NoLog/NoConfirm $drvrname;\n"; |
327 | print DRVR "\$ old_proc_vfy = F\$Environment(\"VERIFY_PROCEDURE\")\n"; |
328 | print DRVR "\$ old_img_vfy = F\$Environment(\"VERIFY_IMAGE\")\n"; |
748a9306 |
329 | print DRVR "\$ MCR $^X -e \"\$ENV{'LIBPERL_RDT'} = (stat('$libperl'))[9]\"\n"; |
a0d0e21e |
330 | print DRVR "\$ Set Verify\n"; |
748a9306 |
331 | print DRVR "\$ If F\$Search(\"$libperl\").eqs.\"\" Then Library/Object/Create $libperl\n"; |
a0d0e21e |
332 | do { |
748a9306 |
333 | $incstr .= ",perlshr_gbl$marord"; |
a0d0e21e |
334 | print DRVR "\$ Macro/NoDebug/Object=PerlShr_Gbl${marord}$objsuffix PerlShr_Gbl$marord.Mar\n"; |
748a9306 |
335 | print DRVR "\$ Library/Object/Replace/Log $libperl PerlShr_Gbl${marord}$objsuffix\n"; |
a0d0e21e |
336 | } while (--$marord); |
748a9306 |
337 | # We had to have a working miniperl to run this program; it's probably the |
338 | # one we just built. It depended on LibPerl, which will be changed when |
339 | # the PerlShr_Gbl* modules get inserted, so miniperl will be out of date, |
340 | # and so, therefore, will all of its dependents . . . |
341 | # We touch LibPerl here so it'll be back 'in date', and we won't rebuild |
342 | # miniperl etc., and therefore LibPerl, the next time we invoke MM[KS]. |
a0d0e21e |
343 | print DRVR "\$ old_proc_vfy = F\$Verify(old_proc_vfy,old_img_vfy)\n"; |
748a9306 |
344 | print DRVR "\$ MCR $^X -e \"utime 0, \$ENV{'LIBPERL_RDT'}, '$libperl'\"\n"; |
a0d0e21e |
345 | close DRVR; |
a0d0e21e |
346 | } |
748a9306 |
347 | |
348 | # Include object modules and RTLs in options file |
349 | # Linker wants /Include and /Library on different lines |
350 | print OPTBLD "$libperl/Include=($incstr)\n"; |
351 | print OPTBLD "$libperl/Library\n"; |
a5f75d66 |
352 | open(RTLOPT,$rtlopt) or die "$0: Can't read options file $rtlopt: $!\n"; |
748a9306 |
353 | while (<RTLOPT>) { print OPTBLD; } |
354 | close RTLOPT; |
355 | close OPTBLD; |
356 | |
357 | exec "\$ \@$drvrname" if $isvax; |
358 | |
359 | |
a0d0e21e |
360 | __END__ |
361 | |
362 | # Oddball cases, so we can keep the perl.h scan above simple |
a0d0e21e |
363 | rcsid=vars # declared in perl.c |
364 | regarglen=vars # declared in regcomp.h |
365 | regdummy=vars # declared in regcomp.h |
366 | regkind=vars # declared in regcomp.h |
367 | simple=vars # declared in regcomp.h |
368 | varies=vars # declared in regcomp.h |
369 | watchaddr=vars # declared in run.c |
370 | watchok=vars # declared in run.c |
371 | yychar=vars # generated by byacc in perly.c |
372 | yycheck=vars # generated by byacc in perly.c |
373 | yydebug=vars # generated by byacc in perly.c |
374 | yydefred=vars # generated by byacc in perly.c |
375 | yydgoto=vars # generated by byacc in perly.c |
376 | yyerrflag=vars # generated by byacc in perly.c |
377 | yygindex=vars # generated by byacc in perly.c |
378 | yylen=vars # generated by byacc in perly.c |
379 | yylhs=vars # generated by byacc in perly.c |
380 | yylval=vars # generated by byacc in perly.c |
381 | yyname=vars # generated by byacc in perly.c |
382 | yynerrs=vars # generated by byacc in perly.c |
383 | yyrindex=vars # generated by byacc in perly.c |
384 | yyrule=vars # generated by byacc in perly.c |
385 | yysindex=vars # generated by byacc in perly.c |
386 | yytable=vars # generated by byacc in perly.c |
387 | yyval=vars # generated by byacc in perly.c |