Commit | Line | Data |
5f05dabc |
1 | #!/usr/bin/perl -w |
e50aee73 |
2 | |
5f05dabc |
3 | require 5.003; |
4 | |
5 | sub 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 | |
20 | readsyms %global, 'global.sym'; |
21 | readsyms %interp, 'interp.sym'; |
22 | readsyms %compat3, 'compat3.sym'; |
23 | |
24 | sub hide ($$) { |
25 | my ($from, $to) = @_; |
26 | my $t = int(length($from) / 8); |
27 | "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n"; |
28 | } |
29 | sub embed ($) { |
30 | my ($sym) = @_; |
31 | hide($sym, "Perl_$sym"); |
32 | } |
33 | sub multon ($) { |
34 | my ($sym) = @_; |
35 | hide($sym, "(curinterp->I$sym)"); |
36 | } |
37 | sub multoff ($) { |
38 | my ($sym) = @_; |
39 | hide("I$sym", $sym); |
40 | } |
41 | |
42 | unlink 'embed.h'; |
43 | open(EM, '> embed.h') |
44 | or die "Can't create embed.h: $!\n"; |
e50aee73 |
45 | |
46 | print EM <<'END'; |
76b72cf1 |
47 | /* !!!!!!! DO NOT EDIT THIS FILE !!!!!!! |
5f05dabc |
48 | This file is built by embed.pl from global.sym, interp.sym, |
49 | and compat3.sym. Any changes made here will be lost! |
76b72cf1 |
50 | */ |
e50aee73 |
51 | |
52 | /* (Doing namespace management portably in C is really gross.) */ |
53 | |
820c3be9 |
54 | /* EMBED has no run-time penalty, but helps keep the Perl namespace |
55 | from colliding with that used by other libraries pulled in |
56 | by extensions or by embedding perl. Allow a cc -DNO_EMBED |
57 | override, however, to keep binary compatability with previous |
58 | versions of perl. |
59 | */ |
60 | #ifndef NO_EMBED |
61 | # define EMBED 1 |
62 | #endif |
63 | |
5f05dabc |
64 | /* Hide global symbols? */ |
65 | |
e50aee73 |
66 | #ifdef EMBED |
67 | |
e50aee73 |
68 | END |
69 | |
5f05dabc |
70 | for $sym (sort keys %global) { |
71 | print EM embed($sym) unless $compat3{$sym}; |
e50aee73 |
72 | } |
73 | |
5f05dabc |
74 | print EM <<'END'; |
75 | |
76 | /* Hide global symbols that 5.003 revealed? */ |
77 | |
78 | #ifndef BINCOMPAT3 |
79 | |
80 | END |
81 | |
82 | for $sym (sort keys %global) { |
83 | print EM embed($sym) if $compat3{$sym}; |
84 | } |
e50aee73 |
85 | |
86 | print EM <<'END'; |
87 | |
5f05dabc |
88 | #endif /* !BINCOMPAT3 */ |
89 | |
e50aee73 |
90 | #endif /* EMBED */ |
91 | |
5f05dabc |
92 | /* Put interpreter-specific symbols into a struct? */ |
e50aee73 |
93 | |
94 | #ifdef MULTIPLICITY |
95 | |
96 | END |
97 | |
5f05dabc |
98 | for $sym (sort keys %interp) { |
99 | print EM multon($sym); |
760ac839 |
100 | } |
760ac839 |
101 | |
55497cff |
102 | print EM <<'END'; |
103 | |
5f05dabc |
104 | #else /* !MULTIPLICITY */ |
55497cff |
105 | |
106 | END |
760ac839 |
107 | |
5f05dabc |
108 | for $sym (sort keys %interp) { |
109 | print EM multoff($sym); |
e50aee73 |
110 | } |
e50aee73 |
111 | |
56d28764 |
112 | print EM <<'END'; |
113 | |
5f05dabc |
114 | /* Hide interpreter-specific symbols? */ |
115 | |
56d28764 |
116 | #ifdef EMBED |
117 | |
118 | END |
e50aee73 |
119 | |
5f05dabc |
120 | for $sym (sort keys %interp) { |
121 | print EM embed($sym) if $compat3{$sym}; |
e50aee73 |
122 | } |
e50aee73 |
123 | |
124 | print EM <<'END'; |
125 | |
5f05dabc |
126 | /* Hide interpreter symbols that 5.003 revealed? */ |
127 | |
128 | #ifndef BINCOMPAT3 |
129 | |
130 | END |
131 | |
132 | for $sym (sort keys %interp) { |
133 | print EM embed($sym) unless $compat3{$sym}; |
134 | } |
135 | |
136 | print EM <<'END'; |
137 | |
138 | #endif /* !BINCOMPAT3 */ |
139 | |
56d28764 |
140 | #endif /* EMBED */ |
141 | |
e50aee73 |
142 | #endif /* MULTIPLICITY */ |
143 | END |
144 | |