Commit | Line | Data |
---|---|---|
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 | |
748a9306 | 37 | # Revised: 01-Mar-1995 |
a0d0e21e LW |
38 | |
39 | require 5.000; | |
40 | ||
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; | |
46 | ||
47 | if ($docc) { | |
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)) | |
54 | . ')' . $suffix; | |
55 | } | |
56 | print "Filtered \$cc_cmd: \\$cc_cmd\\\n" if $debug; | |
57 | ||
58 | if (-f 'perl.h') { $dir = '[]'; } | |
59 | elsif (-f '[-]perl.h') { $dir = '[-]'; } | |
60 | else { die "$0: Can't find perl.h\n"; } | |
61 | } | |
62 | else { ($cpp_file) = ($cc_cmd =~ /~~NOCC~~(.*)/) } | |
63 | ||
64 | $objsuffix = shift @ARGV; | |
65 | print "\$objsuffix: \\$objsuffix\\\n" if $debug; | |
748a9306 LW |
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; | |
a0d0e21e LW |
75 | |
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; | |
79 | ||
80 | sub scan_var { | |
81 | my($line) = @_; | |
82 | ||
748a9306 | 83 | print "\tchecking for global variable\n" if $debug > 1; |
a0d0e21e LW |
84 | $line =~ s/INIT\(.*\)//; |
85 | $line =~ s/\[.*//; | |
86 | $line =~ s/=.*//; | |
87 | $line =~ s/\W*;?\s*$//; | |
748a9306 | 88 | print "\tfiltered to \\$line\\\n" if $debug > 1; |
a0d0e21e | 89 | if ($line =~ /(\w+)$/) { |
748a9306 | 90 | print "\tvar name is \\$1\\\n" if $debug > 1; |
a0d0e21e LW |
91 | $vars{$1}++; |
92 | } | |
93 | } | |
94 | ||
95 | sub scan_func { | |
96 | my($line) = @_; | |
97 | ||
748a9306 | 98 | print "\tchecking for global routine\n" if $debug > 1; |
a0d0e21e | 99 | if ( /(\w+)\s+\(/ ) { |
748a9306 | 100 | print "\troutine name is \\$1\\\n" if $debug > 1; |
a0d0e21e | 101 | if ($1 eq 'main' || $1 eq 'perl_init_ext') { |
748a9306 | 102 | print "\tskipped\n" if $debug > 1; |
a0d0e21e LW |
103 | } |
104 | else { $funcs{$1}++ } | |
105 | } | |
106 | } | |
107 | ||
108 | if ($docc) { | |
109 | open(CPP,"${cc_cmd}/NoObj/PreProc=Sys\$Output ${dir}perl.h|") | |
110 | or die "$0: Can't preprocess ${dir}perl.h: $!\n"; | |
111 | } | |
112 | else { | |
113 | open(CPP,"$cpp_file") or die "$0: Can't read $cpp_file: $!\n"; | |
114 | } | |
115 | LINE: while (<CPP>) { | |
116 | while (/^#.*vmsish\.h/i .. /^#.*perl\.h/i) { | |
117 | while (/__VMS_PROTOTYPES__/i .. /__VMS_SEPYTOTORP__/i) { | |
748a9306 | 118 | print "vms_proto>> $_" if $debug > 2; |
a0d0e21e LW |
119 | &scan_func($_); |
120 | if (/^EXT/) { &scan_var($_); } | |
121 | last LINE unless $_ = <CPP>; | |
122 | } | |
748a9306 | 123 | print "vmsish.h>> $_" if $debug > 2; |
a0d0e21e LW |
124 | if (/^EXT/) { &scan_var($_); } |
125 | last LINE unless $_ = <CPP>; | |
126 | } | |
127 | while (/^#.*opcode\.h/i .. /^#.*perl\.h/i) { | |
748a9306 | 128 | print "opcode.h>> $_" if $debug > 2; |
a0d0e21e LW |
129 | if (/^OP \*\s/) { &scan_func($_); } |
130 | if (/^EXT/) { &scan_var($_); } | |
131 | last LINE unless $_ = <CPP>; | |
132 | } | |
133 | while (/^#.*proto\.h/i .. /^#.*perl\.h/i) { | |
748a9306 | 134 | print "proto.h>> $_" if $debug > 2; |
a0d0e21e LW |
135 | &scan_func($_); |
136 | if (/^EXT/) { &scan_var($_); } | |
137 | last LINE unless $_ = <CPP>; | |
138 | } | |
748a9306 | 139 | print $_ if $debug > 3; |
a0d0e21e LW |
140 | if (/^EXT/) { &scan_var($_); } |
141 | } | |
142 | close CPP; | |
143 | while (<DATA>) { | |
144 | next if /^#/; | |
145 | s/\s+#.*\n//; | |
146 | ($key,$array) = split('=',$_); | |
748a9306 | 147 | print "Adding $key to \%$array list\n" if $debug > 1; |
a0d0e21e LW |
148 | ${$array}{$key}++; |
149 | } | |
748a9306 LW |
150 | foreach (split /\s+/, $extnames) { |
151 | my($pkgname) = $_; | |
152 | $pkgname =~ s/::/__/g; | |
153 | $funcs{"boot_$pkgname"}++; | |
154 | print "Adding boot_$pkgname to \%funcs (for extension $_)\n" if $debug; | |
155 | } | |
a0d0e21e LW |
156 | |
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. | |
159 | ||
160 | $marord++; | |
748a9306 LW |
161 | open(OPTBLD,">${dir}${dbgprefix}perlshr_bld.opt") |
162 | or die "$0: Can't write to ${dir}${dbgprefix}perlshr_bld.opt: $!\n"; | |
a0d0e21e LW |
163 | open(OPTATTR,">${dir}perlshr_attr.opt") |
164 | or die "$0: Can't write to ${dir}perlshr_attr.opt: $!\n"; | |
165 | if ($isvax) { | |
166 | open(MAR,">${dir}perlshr_gbl${marord}.mar") | |
167 | or die "$0: Can't write to ${dir}perlshr_gbl${marord}.mar: $!\n"; | |
748a9306 | 168 | print MAR "\t.title perlshr_gbl$marord\n"; |
a0d0e21e LW |
169 | } |
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"; | |
748a9306 LW |
173 | if ($isvax) { print OPTBLD "UNIVERSAL=$var\n"; } |
174 | else { print OPTBLD "SYMBOL_VECTOR=($var=DATA)\n"; } | |
a0d0e21e LW |
175 | if ($isvax) { |
176 | if ($count++ > 200) { # max 254 psects/file | |
177 | print MAR "\t.end\n"; | |
178 | close MAR; | |
179 | $marord++; | |
180 | open(MAR,">${dir}perlshr_gbl${marord}.mar") | |
181 | or die "$0: Can't write to ${dir}perlshr_gbl${marord}.mar: $!\n"; | |
748a9306 | 182 | print MAR "\t.title perlshr_gbl$marord\n"; |
a0d0e21e LW |
183 | $count = 0; |
184 | } | |
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"; | |
188 | } | |
189 | } | |
190 | ||
191 | print MAR "\t.psect \$transfer_vec,pic,rd,nowrt,exe,shr\n" if ($isvax); | |
192 | foreach $func (sort keys %funcs) { | |
193 | if ($isvax) { | |
194 | print MAR "\t.transfer $func\n"; | |
195 | print MAR "\t.mask $func\n"; | |
196 | print MAR "\tjmp L\^${func}+2\n"; | |
197 | } | |
748a9306 | 198 | else { print OPTBLD "SYMBOL_VECTOR=($func=PROCEDURE)\n"; } |
a0d0e21e LW |
199 | } |
200 | ||
a0d0e21e | 201 | close OPTATTR; |
748a9306 | 202 | $incstr = 'perl,globals'; |
a0d0e21e LW |
203 | if ($isvax) { |
204 | print MAR "\t.end\n"; | |
205 | close MAR; | |
a0d0e21e LW |
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"; | |
748a9306 | 212 | print DRVR "\$ MCR $^X -e \"\$ENV{'LIBPERL_RDT'} = (stat('$libperl'))[9]\"\n"; |
a0d0e21e | 213 | print DRVR "\$ Set Verify\n"; |
748a9306 | 214 | print DRVR "\$ If F\$Search(\"$libperl\").eqs.\"\" Then Library/Object/Create $libperl\n"; |
a0d0e21e | 215 | do { |
748a9306 | 216 | $incstr .= ",perlshr_gbl$marord"; |
a0d0e21e | 217 | print DRVR "\$ Macro/NoDebug/Object=PerlShr_Gbl${marord}$objsuffix PerlShr_Gbl$marord.Mar\n"; |
748a9306 | 218 | print DRVR "\$ Library/Object/Replace/Log $libperl PerlShr_Gbl${marord}$objsuffix\n"; |
a0d0e21e | 219 | } while (--$marord); |
748a9306 LW |
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]. | |
a0d0e21e | 226 | print DRVR "\$ old_proc_vfy = F\$Verify(old_proc_vfy,old_img_vfy)\n"; |
748a9306 | 227 | print DRVR "\$ MCR $^X -e \"utime 0, \$ENV{'LIBPERL_RDT'}, '$libperl'\"\n"; |
a0d0e21e | 228 | close DRVR; |
a0d0e21e | 229 | } |
748a9306 LW |
230 | |
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; } | |
237 | close RTLOPT; | |
238 | close OPTBLD; | |
239 | ||
240 | exec "\$ \@$drvrname" if $isvax; | |
241 | ||
242 | ||
a0d0e21e LW |
243 | __END__ |
244 | ||
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 |