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. | |
9 | # | |
10 | # Output: | |
11 | # PerlShr_Attr.Opt - linker options file which speficies that global vars | |
12 | # be placed in NOSHR,WRT psects. Use when linking any object files | |
13 | # against PerlShr.Exe, since cc places global vars in SHR,WRT psects | |
14 | # by default. | |
15 | # PerlShr_Sym.Opt - declares universal symbols for PerlShr.Exe | |
16 | # Perlshr_Gbl*.Mar, Perlshr_Gbl*.Obj (VAX only) - declares global symbols | |
17 | # for global vars (done here because gcc can't globaldef) and creates | |
18 | # transfer vectors for routines on a VAX. | |
19 | # PerlShr_Gbl.Opt (VAX only) - list of PerlShr_Gbl*.Obj, used for input | |
20 | # to the linker when building PerlShr.Exe. | |
21 | # | |
22 | # To do: | |
23 | # - figure out a good way to collect global vars in one psect, given that | |
24 | # we can't use globaldef because of gcc. | |
25 | # - then, check for existing files and preserve symbol and transfer vector | |
26 | # order for upward compatibility | |
27 | # - then, add GSMATCH to options file - but how do we insure that new | |
28 | # library has everything old one did | |
29 | # (i.e. /Define=DEBUGGING,EMBED,MULTIPLICITY)? | |
30 | # | |
31 | # Author: Charles Bailey bailey@genetics.upenn.edu | |
32 | # Revised: 21-Sep-1994 | |
33 | ||
34 | require 5.000; | |
35 | ||
36 | $debug = $ENV{'GEN_SHRFLS_DEBUG'}; | |
37 | $cc_cmd = shift @ARGV; | |
38 | print "Input \$cc_cmd: \\$cc_cmd\\\n" if $debug; | |
39 | $docc = ($cc_cmd !~ /~~NOCC~~/); | |
40 | print "\$docc = $docc\n" if $debug; | |
41 | ||
42 | if ($docc) { | |
43 | # put quotes back onto defines - they were removed by DCL on the way in | |
44 | if (($prefix,$defines,$suffix) = | |
45 | ($cc_cmd =~ m#(.*)/Define=(.*?)([/\s].*)#i)) { | |
46 | $defines =~ s/^\((.*)\)$/$1/; | |
47 | @defines = split(/,/,$defines); | |
48 | $cc_cmd = "$prefix/Define=(" . join(',',grep($_ = "\"$_\"",@defines)) | |
49 | . ')' . $suffix; | |
50 | } | |
51 | print "Filtered \$cc_cmd: \\$cc_cmd\\\n" if $debug; | |
52 | ||
53 | if (-f 'perl.h') { $dir = '[]'; } | |
54 | elsif (-f '[-]perl.h') { $dir = '[-]'; } | |
55 | else { die "$0: Can't find perl.h\n"; } | |
56 | } | |
57 | else { ($cpp_file) = ($cc_cmd =~ /~~NOCC~~(.*)/) } | |
58 | ||
59 | $objsuffix = shift @ARGV; | |
60 | print "\$objsuffix: \\$objsuffix\\\n" if $debug; | |
61 | ||
62 | # Someday, we'll have $GetSyI built into perl . . . | |
63 | $isvax = `\$ Write Sys\$Output F\$GetSyI(\"HW_MODEL\")` <= 1024; | |
64 | print "\$isvax: \\$isvax\\\n" if $debug; | |
65 | ||
66 | sub scan_var { | |
67 | my($line) = @_; | |
68 | ||
69 | print "\tchecking for global variable\n" if $debug; | |
70 | $line =~ s/INIT\(.*\)//; | |
71 | $line =~ s/\[.*//; | |
72 | $line =~ s/=.*//; | |
73 | $line =~ s/\W*;?\s*$//; | |
74 | print "\tfiltered to \\$line\\\n" if $debug; | |
75 | if ($line =~ /(\w+)$/) { | |
76 | print "\tvar name is \\$1\\\n" if $debug; | |
77 | $vars{$1}++; | |
78 | } | |
79 | } | |
80 | ||
81 | sub scan_func { | |
82 | my($line) = @_; | |
83 | ||
84 | print "\tchecking for global routine\n" if $debug; | |
85 | if ( /(\w+)\s+\(/ ) { | |
86 | print "\troutine name is \\$1\\\n" if $debug; | |
87 | if ($1 eq 'main' || $1 eq 'perl_init_ext') { | |
88 | print "\tskipped\n" if $debug; | |
89 | } | |
90 | else { $funcs{$1}++ } | |
91 | } | |
92 | } | |
93 | ||
94 | if ($docc) { | |
95 | open(CPP,"${cc_cmd}/NoObj/PreProc=Sys\$Output ${dir}perl.h|") | |
96 | or die "$0: Can't preprocess ${dir}perl.h: $!\n"; | |
97 | } | |
98 | else { | |
99 | open(CPP,"$cpp_file") or die "$0: Can't read $cpp_file: $!\n"; | |
100 | } | |
101 | LINE: while (<CPP>) { | |
102 | while (/^#.*vmsish\.h/i .. /^#.*perl\.h/i) { | |
103 | while (/__VMS_PROTOTYPES__/i .. /__VMS_SEPYTOTORP__/i) { | |
104 | print "vms_proto>> $_" if $debug; | |
105 | &scan_func($_); | |
106 | if (/^EXT/) { &scan_var($_); } | |
107 | last LINE unless $_ = <CPP>; | |
108 | } | |
109 | print "vmsish.h>> $_" if $debug; | |
110 | if (/^EXT/) { &scan_var($_); } | |
111 | last LINE unless $_ = <CPP>; | |
112 | } | |
113 | while (/^#.*opcode\.h/i .. /^#.*perl\.h/i) { | |
114 | print "opcode.h>> $_" if $debug; | |
115 | if (/^OP \*\s/) { &scan_func($_); } | |
116 | if (/^EXT/) { &scan_var($_); } | |
117 | last LINE unless $_ = <CPP>; | |
118 | } | |
119 | while (/^#.*proto\.h/i .. /^#.*perl\.h/i) { | |
120 | print "proto.h>> $_" if $debug; | |
121 | &scan_func($_); | |
122 | if (/^EXT/) { &scan_var($_); } | |
123 | last LINE unless $_ = <CPP>; | |
124 | } | |
125 | print $_ if $debug; | |
126 | if (/^EXT/) { &scan_var($_); } | |
127 | } | |
128 | close CPP; | |
129 | while (<DATA>) { | |
130 | next if /^#/; | |
131 | s/\s+#.*\n//; | |
132 | ($key,$array) = split('=',$_); | |
133 | print "Adding $key to \%$array list\n" if $debug; | |
134 | ${$array}{$key}++; | |
135 | } | |
136 | ||
137 | # Eventually, we'll check against existing copies here, so we can add new | |
138 | # symbols to an existing options file in an upwardly-compatible manner. | |
139 | ||
140 | $marord++; | |
141 | open(OPTSYM,">${dir}perlshr_sym.opt") | |
142 | or die "$0: Can't write to ${dir}perlshr_sym.opt: $!\n"; | |
143 | open(OPTATTR,">${dir}perlshr_attr.opt") | |
144 | or die "$0: Can't write to ${dir}perlshr_attr.opt: $!\n"; | |
145 | if ($isvax) { | |
146 | open(MAR,">${dir}perlshr_gbl${marord}.mar") | |
147 | or die "$0: Can't write to ${dir}perlshr_gbl${marord}.mar: $!\n"; | |
148 | } | |
149 | print OPTATTR "PSECT_ATTR=\$CHAR_STRING_CONSTANTS,PIC,SHR,NOEXE,RD,NOWRT\n"; | |
150 | foreach $var (sort keys %vars) { | |
151 | print OPTATTR "PSECT_ATTR=${var},PIC,OVR,RD,NOEXE,WRT,NOSHR\n"; | |
152 | if ($isvax) { print OPTSYM "UNIVERSAL=$var\n"; } | |
153 | else { print OPTSYM "SYMBOL_VECTOR=($var=DATA)\n"; } | |
154 | if ($isvax) { | |
155 | if ($count++ > 200) { # max 254 psects/file | |
156 | print MAR "\t.end\n"; | |
157 | close MAR; | |
158 | $marord++; | |
159 | open(MAR,">${dir}perlshr_gbl${marord}.mar") | |
160 | or die "$0: Can't write to ${dir}perlshr_gbl${marord}.mar: $!\n"; | |
161 | $count = 0; | |
162 | } | |
163 | # This hack brought to you by the lack of a globaldef in gcc. | |
164 | print MAR "\t.psect ${var},long,pic,ovr,rd,wrt,noexe,noshr\n"; | |
165 | print MAR "\t${var}:: .blkl 1\n"; | |
166 | } | |
167 | } | |
168 | ||
169 | print MAR "\t.psect \$transfer_vec,pic,rd,nowrt,exe,shr\n" if ($isvax); | |
170 | foreach $func (sort keys %funcs) { | |
171 | if ($isvax) { | |
172 | print MAR "\t.transfer $func\n"; | |
173 | print MAR "\t.mask $func\n"; | |
174 | print MAR "\tjmp L\^${func}+2\n"; | |
175 | } | |
176 | else { print OPTSYM "SYMBOL_VECTOR=($func=PROCEDURE)\n"; } | |
177 | } | |
178 | ||
179 | close OPTSYM; | |
180 | close OPTATTR; | |
181 | if ($isvax) { | |
182 | print MAR "\t.end\n"; | |
183 | close MAR; | |
184 | open (GBLOPT,">PerlShr_Gbl.Opt") or die "$0: Can't write to PerlShr_Gbl.Opt: $!\n"; | |
185 | $drvrname = "Compile_shrmars.tmp_".time; | |
186 | open (DRVR,">$drvrname") or die "$0: Can't write to $drvrname: $!\n"; | |
187 | print DRVR "\$ Set NoOn\n"; | |
188 | print DRVR "\$ Delete/NoLog/NoConfirm $drvrname;\n"; | |
189 | print DRVR "\$ old_proc_vfy = F\$Environment(\"VERIFY_PROCEDURE\")\n"; | |
190 | print DRVR "\$ old_img_vfy = F\$Environment(\"VERIFY_IMAGE\")\n"; | |
191 | print DRVR "\$ Set Verify\n"; | |
192 | do { | |
193 | print GBLOPT "PerlShr_Gbl${marord}$objsuffix\n"; | |
194 | print DRVR "\$ Macro/NoDebug/Object=PerlShr_Gbl${marord}$objsuffix PerlShr_Gbl$marord.Mar\n"; | |
195 | } while (--$marord); | |
196 | print DRVR "\$ old_proc_vfy = F\$Verify(old_proc_vfy,old_img_vfy)\n"; | |
197 | close DRVR; | |
198 | close GBLOPT; | |
199 | exec "\$ \@$drvrname"; | |
200 | } | |
201 | __END__ | |
202 | ||
203 | # Oddball cases, so we can keep the perl.h scan above simple | |
204 | error=vars # declared in perl.h only when DOINIT defined by INTERN.h | |
205 | rcsid=vars # declared in perl.c | |
206 | regarglen=vars # declared in regcomp.h | |
207 | regdummy=vars # declared in regcomp.h | |
208 | regkind=vars # declared in regcomp.h | |
209 | simple=vars # declared in regcomp.h | |
210 | varies=vars # declared in regcomp.h | |
211 | watchaddr=vars # declared in run.c | |
212 | watchok=vars # declared in run.c | |
213 | yychar=vars # generated by byacc in perly.c | |
214 | yycheck=vars # generated by byacc in perly.c | |
215 | yydebug=vars # generated by byacc in perly.c | |
216 | yydefred=vars # generated by byacc in perly.c | |
217 | yydgoto=vars # generated by byacc in perly.c | |
218 | yyerrflag=vars # generated by byacc in perly.c | |
219 | yygindex=vars # generated by byacc in perly.c | |
220 | yylen=vars # generated by byacc in perly.c | |
221 | yylhs=vars # generated by byacc in perly.c | |
222 | yylval=vars # generated by byacc in perly.c | |
223 | yyname=vars # generated by byacc in perly.c | |
224 | yynerrs=vars # generated by byacc in perly.c | |
225 | yyrindex=vars # generated by byacc in perly.c | |
226 | yyrule=vars # generated by byacc in perly.c | |
227 | yysindex=vars # generated by byacc in perly.c | |
228 | yytable=vars # generated by byacc in perly.c | |
229 | yyval=vars # generated by byacc in perly.c |