This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Builds and passes tests with -DMULTIPLICITY and -DCRIPPLED_CC
[perl5.git] / embed.pl
CommitLineData
5f05dabc 1#!/usr/bin/perl -w
e50aee73 2
5f05dabc 3require 5.003;
4
5sub readsyms (\%$) {
6 my ($syms, $file) = @_;
7 %$syms = ();
8 local (*FILE, $_);
9 open(FILE, "< $file")
10 or die "embed.pl: Can't open $file: $!\n";
11 while (<FILE>) {
12 s/[ \t]*#.*//; # Delete comments.
13 if (/^\s*(\S+)\s*$/) {
14 $$syms{$1} = 1;
15 }
16 }
17 close(FILE);
18}
19
20readsyms %global, 'global.sym';
21readsyms %interp, 'interp.sym';
5f05dabc 22
d4cce5f1
NIS
23sub readvars(\%$$) {
24 my ($syms, $file,$pre) = @_;
25 %$syms = ();
26 local (*FILE, $_);
27 open(FILE, "< $file")
28 or die "embed.pl: Can't open $file: $!\n";
29 while (<FILE>) {
30 s/[ \t]*#.*//; # Delete comments.
3fe35a81 31 if (/PERLVARI?C?\($pre(\w+)/) {
22239a37 32 $$syms{$1} = 1;
d4cce5f1
NIS
33 }
34 }
35 close(FILE);
36}
37
38my %intrp;
39my %thread;
40
41readvars %intrp, 'intrpvar.h','I';
42readvars %thread, 'thrdvar.h','T';
22239a37 43readvars %globvar, 'perlvars.h','G';
d4cce5f1
NIS
44
45foreach my $sym (sort keys %intrp)
46 {
47 warn "$sym not in interp.sym\n" unless exists $interp{$sym};
48 if (exists $global{$sym})
49 {
50 delete $global{$sym};
51 warn "$sym in global.sym as well as interp\n";
52 }
53 }
54
22239a37
NIS
55foreach my $sym (sort keys %globvar)
56 {
57 if (exists $global{$sym})
58 {
59 delete $global{$sym};
60 warn "$sym in global.sym as well as perlvars.h\n";
61 }
62 }
63
d4cce5f1
NIS
64foreach my $sym (keys %interp)
65 {
66 warn "extra $sym in interp.sym\n"
67 unless exists $intrp{$sym} || exists $thread{$sym};
68 }
69
70foreach my $sym (sort keys %thread)
71 {
72 warn "$sym in intrpvar.h\n" if exists $intrp{$sym};
73 if (exists $global{$sym})
74 {
75 delete $global{$sym};
76 warn "$sym in global.sym as well as thread\n";
77 }
78 }
79
5f05dabc 80sub hide ($$) {
81 my ($from, $to) = @_;
82 my $t = int(length($from) / 8);
83 "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
84}
85sub embed ($) {
86 my ($sym) = @_;
87 hide($sym, "Perl_$sym");
88}
3280af22
NIS
89sub embedvar ($) {
90 my ($sym) = @_;
91# hide($sym, "Perl_$sym");
92 return '';
93}
94
d4cce5f1
NIS
95sub multon ($$$) {
96 my ($sym,$pre,$ptr) = @_;
3280af22 97 hide("PL_$sym", "($ptr$pre$sym)");
5f05dabc 98}
d4cce5f1
NIS
99sub multoff ($$) {
100 my ($sym,$pre) = @_;
8f872242
NIS
101# hide("$pre$sym", "PL_$sym");
102 return '';
5f05dabc 103}
104
105unlink 'embed.h';
106open(EM, '> embed.h')
107 or die "Can't create embed.h: $!\n";
e50aee73
AD
108
109print EM <<'END';
76b72cf1 110/* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
d4cce5f1
NIS
111 This file is built by embed.pl from global.sym, intrpvar.h,
112 and thrdvar.h. Any changes made here will be lost!
76b72cf1 113*/
e50aee73
AD
114
115/* (Doing namespace management portably in C is really gross.) */
116
820c3be9 117/* EMBED has no run-time penalty, but helps keep the Perl namespace
118 from colliding with that used by other libraries pulled in
119 by extensions or by embedding perl. Allow a cc -DNO_EMBED
120 override, however, to keep binary compatability with previous
121 versions of perl.
122*/
123#ifndef NO_EMBED
124# define EMBED 1
125#endif
126
5f05dabc 127/* Hide global symbols? */
128
e50aee73
AD
129#ifdef EMBED
130
e50aee73
AD
131END
132
5f05dabc 133for $sym (sort keys %global) {
dc86dda3 134 print EM embed($sym);
e50aee73
AD
135}
136
e50aee73
AD
137print EM <<'END';
138
139#endif /* EMBED */
140
d4cce5f1
NIS
141END
142
143close(EM);
144
145unlink 'embedvar.h';
146open(EM, '> embedvar.h')
147 or die "Can't create embedvar.h: $!\n";
148
149print EM <<'END';
150/* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
151 This file is built by embed.pl from global.sym, intrpvar.h,
152 and thrdvar.h. Any changes made here will be lost!
153*/
154
155/* (Doing namespace management portably in C is really gross.) */
156
157/* EMBED has no run-time penalty, but helps keep the Perl namespace
158 from colliding with that used by other libraries pulled in
159 by extensions or by embedding perl. Allow a cc -DNO_EMBED
160 override, however, to keep binary compatability with previous
161 versions of perl.
162*/
163
164
5f05dabc 165/* Put interpreter-specific symbols into a struct? */
e50aee73
AD
166
167#ifdef MULTIPLICITY
168
d4cce5f1
NIS
169#ifndef USE_THREADS
170/* If we do not have threads then per-thread vars are per-interpreter */
171
e50aee73
AD
172END
173
d4cce5f1 174for $sym (sort keys %thread) {
8f872242 175 print EM multon($sym,'T','PL_curinterp->');
d4cce5f1
NIS
176}
177
178print EM <<'END';
179
180#endif /* !USE_THREADS */
181
182/* These are always per-interpreter if there is more than one */
183
184END
185
186for $sym (sort keys %intrp) {
8f872242 187 print EM multon($sym,'I','PL_curinterp->');
760ac839 188}
760ac839 189
55497cff 190print EM <<'END';
191
5f05dabc 192#else /* !MULTIPLICITY */
55497cff 193
194END
760ac839 195
d4cce5f1
NIS
196for $sym (sort keys %intrp) {
197 print EM multoff($sym,'I');
e50aee73 198}
e50aee73 199
56d28764
CS
200print EM <<'END';
201
d4cce5f1
NIS
202#ifndef USE_THREADS
203
204END
205
206for $sym (sort keys %thread) {
207 print EM multoff($sym,'T');
208}
209
210print EM <<'END';
211
212#endif /* USE_THREADS */
213
214/* Hide what would have been interpreter-specific symbols? */
5f05dabc 215
56d28764
CS
216#ifdef EMBED
217
218END
e50aee73 219
d4cce5f1 220for $sym (sort keys %intrp) {
3280af22 221 print EM embedvar($sym);
d4cce5f1
NIS
222}
223
224print EM <<'END';
225
226#ifndef USE_THREADS
227
228END
229
230for $sym (sort keys %thread) {
3280af22 231 print EM embedvar($sym);
5f05dabc 232}
233
234print EM <<'END';
235
d4cce5f1 236#endif /* USE_THREADS */
56d28764 237#endif /* EMBED */
e50aee73 238#endif /* MULTIPLICITY */
d4cce5f1
NIS
239
240/* Now same trickey for per-thread variables */
241
242#ifdef USE_THREADS
243
244END
245
246for $sym (sort keys %thread) {
22239a37 247 print EM multon($sym,'T','thr->');
d4cce5f1
NIS
248}
249
250print EM <<'END';
251
252#endif /* USE_THREADS */
253
22239a37
NIS
254#ifdef PERL_GLOBAL_STRUCT
255
256END
257
258for $sym (sort keys %globvar) {
259 print EM multon($sym,'G','Perl_Vars.');
260}
261
262print EM <<'END';
263
264#else /* !PERL_GLOBAL_STRUCT */
265
266END
267
268for $sym (sort keys %globvar) {
269 print EM multoff($sym,'G');
270}
271
272print EM <<'END';
273
274#ifdef EMBED
275
276END
277
278for $sym (sort keys %globvar) {
3280af22 279 print EM embedvar($sym);
22239a37
NIS
280}
281
282print EM <<'END';
283
284#endif /* EMBED */
285#endif /* PERL_GLOBAL_STRUCT */
286
e50aee73
AD
287END
288
3fe35a81 289close(EM);