1 # Create global symbol declarations, transfer vector, and
2 # linker options files for PerlShr.
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.
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
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
20 # PerlShr_Bld.Opt - declares universal symbols for PerlShr.Exe
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.
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)?
36 # Author: Charles Bailey bailey@genetics.upenn.edu
37 # Revised: 01-Mar-1995
41 $debug = $ENV{'GEN_SHRFLS_DEBUG'};
42 $cc_cmd = shift @ARGV;
43 print "Input \$cc_cmd: \\$cc_cmd\\\n" if $debug;
44 $docc = ($cc_cmd !~ /~~NOCC~~/);
45 print "\$docc = $docc\n" if $debug;
48 # put quotes back onto defines - they were removed by DCL on the way in
49 if (($prefix,$defines,$suffix) =
50 ($cc_cmd =~ m#(.*)/Define=(.*?)([/\s].*)#i)) {
51 $defines =~ s/^\((.*)\)$/$1/;
52 @defines = split(/,/,$defines);
53 $cc_cmd = "$prefix/Define=(" . join(',',grep($_ = "\"$_\"",@defines))
56 print "Filtered \$cc_cmd: \\$cc_cmd\\\n" if $debug;
58 if (-f 'perl.h') { $dir = '[]'; }
59 elsif (-f '[-]perl.h') { $dir = '[-]'; }
60 else { die "$0: Can't find perl.h\n"; }
62 else { ($cpp_file) = ($cc_cmd =~ /~~NOCC~~(.*)/) }
64 $objsuffix = shift @ARGV;
65 print "\$objsuffix: \\$objsuffix\\\n" if $debug;
66 $dbgprefix = shift @ARGV;
67 print "\$dbgprefix: \\$dbgprefix\\\n" if $debug;
68 $olbsuffix = shift @ARGV;
69 print "\$olbsuffix: \\$olbsuffix\\\n" if $debug;
70 $libperl = "${dbgprefix}libperl$olbsuffix";
71 $extnames = shift @ARGV;
72 print "\$extnames: \\$extnames\\\n" if $debug;
73 $rtlopt = shift @ARGV;
74 print "\$rtlopt: \\$rtlopt\\\n" if $debug;
76 # Someday, we'll have $GetSyI built into perl . . .
77 $isvax = `\$ Write Sys\$Output F\$GetSyI(\"HW_MODEL\")` <= 1024;
78 print "\$isvax: \\$isvax\\\n" if $debug;
83 print "\tchecking for global variable\n" if $debug > 1;
84 $line =~ s/INIT\(.*\)//;
87 $line =~ s/\W*;?\s*$//;
88 print "\tfiltered to \\$line\\\n" if $debug > 1;
89 if ($line =~ /(\w+)$/) {
90 print "\tvar name is \\$1\\\n" if $debug > 1;
98 print "\tchecking for global routine\n" if $debug > 1;
100 print "\troutine name is \\$1\\\n" if $debug > 1;
101 if ($1 eq 'main' || $1 eq 'perl_init_ext') {
102 print "\tskipped\n" if $debug > 1;
104 else { $funcs{$1}++ }
109 open(CPP,"${cc_cmd}/NoObj/PreProc=Sys\$Output ${dir}perl.h|")
110 or die "$0: Can't preprocess ${dir}perl.h: $!\n";
113 open(CPP,"$cpp_file") or die "$0: Can't read $cpp_file: $!\n";
115 LINE: while (<CPP>) {
116 while (/^#.*vmsish\.h/i .. /^#.*perl\.h/i) {
117 while (/__VMS_PROTOTYPES__/i .. /__VMS_SEPYTOTORP__/i) {
118 print "vms_proto>> $_" if $debug > 2;
120 if (/^EXT/) { &scan_var($_); }
121 last LINE unless $_ = <CPP>;
123 print "vmsish.h>> $_" if $debug > 2;
124 if (/^EXT/) { &scan_var($_); }
125 last LINE unless $_ = <CPP>;
127 while (/^#.*opcode\.h/i .. /^#.*perl\.h/i) {
128 print "opcode.h>> $_" if $debug > 2;
129 if (/^OP \*\s/) { &scan_func($_); }
130 if (/^EXT/) { &scan_var($_); }
131 last LINE unless $_ = <CPP>;
133 while (/^#.*proto\.h/i .. /^#.*perl\.h/i) {
134 print "proto.h>> $_" if $debug > 2;
136 if (/^EXT/) { &scan_var($_); }
137 last LINE unless $_ = <CPP>;
139 print $_ if $debug > 3;
140 if (/^EXT/) { &scan_var($_); }
146 ($key,$array) = split('=',$_);
147 print "Adding $key to \%$array list\n" if $debug > 1;
150 foreach (split /\s+/, $extnames) {
152 $pkgname =~ s/::/__/g;
153 $funcs{"boot_$pkgname"}++;
154 print "Adding boot_$pkgname to \%funcs (for extension $_)\n" if $debug;
157 # Eventually, we'll check against existing copies here, so we can add new
158 # symbols to an existing options file in an upwardly-compatible manner.
161 open(OPTBLD,">${dir}${dbgprefix}perlshr_bld.opt")
162 or die "$0: Can't write to ${dir}${dbgprefix}perlshr_bld.opt: $!\n";
163 open(OPTATTR,">${dir}perlshr_attr.opt")
164 or die "$0: Can't write to ${dir}perlshr_attr.opt: $!\n";
166 open(MAR,">${dir}perlshr_gbl${marord}.mar")
167 or die "$0: Can't write to ${dir}perlshr_gbl${marord}.mar: $!\n";
168 print MAR "\t.title perlshr_gbl$marord\n";
170 print OPTATTR "PSECT_ATTR=\$CHAR_STRING_CONSTANTS,PIC,SHR,NOEXE,RD,NOWRT\n";
171 foreach $var (sort keys %vars) {
172 print OPTATTR "PSECT_ATTR=${var},PIC,OVR,RD,NOEXE,WRT,NOSHR\n";
173 if ($isvax) { print OPTBLD "UNIVERSAL=$var\n"; }
174 else { print OPTBLD "SYMBOL_VECTOR=($var=DATA)\n"; }
176 if ($count++ > 200) { # max 254 psects/file
177 print MAR "\t.end\n";
180 open(MAR,">${dir}perlshr_gbl${marord}.mar")
181 or die "$0: Can't write to ${dir}perlshr_gbl${marord}.mar: $!\n";
182 print MAR "\t.title perlshr_gbl$marord\n";
185 # This hack brought to you by the lack of a globaldef in gcc.
186 print MAR "\t.psect ${var},long,pic,ovr,rd,wrt,noexe,noshr\n";
187 print MAR "\t${var}:: .blkl 1\n";
191 print MAR "\t.psect \$transfer_vec,pic,rd,nowrt,exe,shr\n" if ($isvax);
192 foreach $func (sort keys %funcs) {
194 print MAR "\t.transfer $func\n";
195 print MAR "\t.mask $func\n";
196 print MAR "\tjmp L\^${func}+2\n";
198 else { print OPTBLD "SYMBOL_VECTOR=($func=PROCEDURE)\n"; }
202 $incstr = 'perl,globals';
204 print MAR "\t.end\n";
206 $drvrname = "Compile_shrmars.tmp_".time;
207 open (DRVR,">$drvrname") or die "$0: Can't write to $drvrname: $!\n";
208 print DRVR "\$ Set NoOn\n";
209 print DRVR "\$ Delete/NoLog/NoConfirm $drvrname;\n";
210 print DRVR "\$ old_proc_vfy = F\$Environment(\"VERIFY_PROCEDURE\")\n";
211 print DRVR "\$ old_img_vfy = F\$Environment(\"VERIFY_IMAGE\")\n";
212 print DRVR "\$ MCR $^X -e \"\$ENV{'LIBPERL_RDT'} = (stat('$libperl'))[9]\"\n";
213 print DRVR "\$ Set Verify\n";
214 print DRVR "\$ If F\$Search(\"$libperl\").eqs.\"\" Then Library/Object/Create $libperl\n";
216 $incstr .= ",perlshr_gbl$marord";
217 print DRVR "\$ Macro/NoDebug/Object=PerlShr_Gbl${marord}$objsuffix PerlShr_Gbl$marord.Mar\n";
218 print DRVR "\$ Library/Object/Replace/Log $libperl PerlShr_Gbl${marord}$objsuffix\n";
220 # We had to have a working miniperl to run this program; it's probably the
221 # one we just built. It depended on LibPerl, which will be changed when
222 # the PerlShr_Gbl* modules get inserted, so miniperl will be out of date,
223 # and so, therefore, will all of its dependents . . .
224 # We touch LibPerl here so it'll be back 'in date', and we won't rebuild
225 # miniperl etc., and therefore LibPerl, the next time we invoke MM[KS].
226 print DRVR "\$ old_proc_vfy = F\$Verify(old_proc_vfy,old_img_vfy)\n";
227 print DRVR "\$ MCR $^X -e \"utime 0, \$ENV{'LIBPERL_RDT'}, '$libperl'\"\n";
231 # Include object modules and RTLs in options file
232 # Linker wants /Include and /Library on different lines
233 print OPTBLD "$libperl/Include=($incstr)\n";
234 print OPTBLD "$libperl/Library\n";
235 open(RTLOPT,$rtlopt) or die "$0: Can't read $rtlopt: $!\n";
236 while (<RTLOPT>) { print OPTBLD; }
240 exec "\$ \@$drvrname" if $isvax;
245 # Oddball cases, so we can keep the perl.h scan above simple
246 error=vars # declared in perl.h only when DOINIT defined by INTERN.h
247 rcsid=vars # declared in perl.c
248 regarglen=vars # declared in regcomp.h
249 regdummy=vars # declared in regcomp.h
250 regkind=vars # declared in regcomp.h
251 simple=vars # declared in regcomp.h
252 varies=vars # declared in regcomp.h
253 watchaddr=vars # declared in run.c
254 watchok=vars # declared in run.c
255 yychar=vars # generated by byacc in perly.c
256 yycheck=vars # generated by byacc in perly.c
257 yydebug=vars # generated by byacc in perly.c
258 yydefred=vars # generated by byacc in perly.c
259 yydgoto=vars # generated by byacc in perly.c
260 yyerrflag=vars # generated by byacc in perly.c
261 yygindex=vars # generated by byacc in perly.c
262 yylen=vars # generated by byacc in perly.c
263 yylhs=vars # generated by byacc in perly.c
264 yylval=vars # generated by byacc in perly.c
265 yyname=vars # generated by byacc in perly.c
266 yynerrs=vars # generated by byacc in perly.c
267 yyrindex=vars # generated by byacc in perly.c
268 yyrule=vars # generated by byacc in perly.c
269 yysindex=vars # generated by byacc in perly.c
270 yytable=vars # generated by byacc in perly.c
271 yyval=vars # generated by byacc in perly.c