Commit | Line | Data |
---|---|---|
396e9e6f | 1 | #!../miniperl |
2 | # Habit . . . | |
3 | # | |
4 | # Extract info from config.h, and add extra data here, to generate config.sh | |
5 | # Edit the static information after __END__ to reflect your site and options | |
6 | # that went into your perl binary. In addition, values which change from run | |
7 | # to run may be supplied on the command line as key=val pairs. | |
8 | # | |
9 | # Last Modified: 28-Jun-1996 Luther Huffman lutherh@stratcom.com | |
a123eb89 | 10 | # Last Modified: May 2020 David Romano unobe@cpan.org |
396e9e6f | 11 | # |
12 | ||
a123eb89 R |
13 | my $VERBOSE = 0; |
14 | ||
396e9e6f | 15 | #==== Locations of installed Perl components |
760ac839 | 16 | $p9pvers="_P9P_VERSION"; |
a123eb89 | 17 | $version="$p9pvers"; |
396e9e6f | 18 | $prefix=''; |
19 | $p9p_objtype=$ENV{'objtype'}; | |
20 | $builddir="/sys/src/cmd/perl/$p9pvers"; | |
21 | $installbin="/$p9p_objtype/bin"; | |
22 | $installman1dir="/sys/man/1"; | |
23 | $installman3dir="/sys/man/2"; | |
a123eb89 | 24 | $installprivlib="/sys/lib/perl/$p9pvers"; |
396e9e6f | 25 | $installarchlib = "/$p9p_objtype/lib/perl/$p9pvers"; |
26 | $archname="plan9_$p9p_objtype"; | |
27 | $installsitelib="$installprivlib/site_perl"; | |
28 | $installsitearch="$installarchlib/site_perl"; | |
29 | $installscript="/bin"; | |
30 | ||
31 | unshift(@INC,'lib'); # In case someone didn't define Perl_Root | |
32 | # before the build | |
33 | ||
34 | if ($ARGV[0] eq '-f') { | |
a123eb89 | 35 | shift @ARGV; |
1ae6ead9 | 36 | open(ARGS,'<',$ARGV[1]) or die "Can't read data from $ARGV[1]: $!\n"; |
a123eb89 | 37 | shift @ARGV; |
396e9e6f | 38 | while (<ARGS>) { |
39 | push(@ARGV,split(/\|/,$_)); | |
40 | } | |
41 | close ARGS; | |
42 | } | |
a123eb89 | 43 | my @extensions = @ARGV; |
396e9e6f | 44 | |
45 | if (-f "config.h") { $infile = "config.h"; $outdir = "../"; } | |
46 | elsif (-f "plan9/config.h") { $infile = "plan9/config.h"; $outdir = "./"; } | |
47 | ||
48 | if ($infile) { print "Generating config.sh from $infile . . .\n"; } | |
49 | else { die <<EndOfGasp; | |
50 | Can't find config.h to read! | |
51 | Please run this script from the perl source directory or | |
52 | the plan9 subdirectory in the distribution. | |
53 | EndOfGasp | |
54 | } | |
55 | $outdir = ''; | |
1ae6ead9 JL |
56 | open(IN,'<',$infile) || die "Can't open $infile: $!\n"; |
57 | open(OUT,'>',"${outdir}config.sh") || die "Can't open ${outdir}config.sh: $!\n"; | |
396e9e6f | 58 | |
59 | $time = localtime; | |
60 | $cf_by = $ENV{'user'}; | |
61 | ($vers = $]) =~ tr/./_/; | |
62 | ||
a123eb89 R |
63 | # 9front as Plan 9, 5th edition. |
64 | $osvers = '5'; | |
65 | ||
396e9e6f | 66 | print OUT <<EndOfIntro; |
67 | # This file generated by genconfig.pl on a Plan 9 system. | |
68 | # Input obtained from: | |
69 | # $infile | |
70 | # $0 | |
71 | # Time: $time | |
72 | ||
73 | package='perl5' | |
a123eb89 | 74 | PERL_CONFIG_SH='true' |
396e9e6f | 75 | cf_time='$time' |
76 | cf_by='$cf_by' | |
77 | ccdlflags='' | |
78 | cccdlflags='' | |
79 | libpth='$installprivlib' | |
80 | ld='pcc' | |
a123eb89 R |
81 | cppflags='' |
82 | cppstdin='cpp' | |
396e9e6f | 83 | lddlflags='' |
84 | ranlib='' | |
85 | ar='ar' | |
86 | nroff='/bin/nroff' | |
87 | eunicefix=':' | |
88 | hint='none' | |
89 | hintfile='' | |
90 | intsize='4' | |
82488b82 CS |
91 | longsize='4' |
92 | shortsize='2' | |
396e9e6f | 93 | shrplib='define' |
94 | usemymalloc='n' | |
95 | usevfork='true' | |
96 | useposix='true' | |
97 | spitshell='cat' | |
98 | dlsrc='dl_none.c' | |
99 | binexp='$installbin' | |
100 | man1ext='' | |
101 | man3ext='' | |
102 | arch='$archname' | |
103 | archname='$archname' | |
104 | osname='plan9' | |
a123eb89 R |
105 | version='$p9pvers' |
106 | extensions='@extensions' | |
396e9e6f | 107 | osvers='$osvers' |
108 | sig_maxsig='19' | |
109 | sig_name='ZERO HUP INT QUIT ILL ABRT FPE KILL SEGV PIPE ALRM TERM USR1 USR2 CHLD CONT STOP TSTP TTIN TTOU' | |
110 | sig_num='0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19' | |
111 | sig_numsig='20' | |
112 | prefix='$prefix' | |
113 | builddir='$builddir' | |
114 | installbin='$installbin' | |
115 | installman1dir='$installman1dir' | |
116 | installman3dir='$installman3dir' | |
117 | installprivlib='$installprivlib' | |
118 | installarchlib='$installarchlib' | |
119 | installsitelib='$installsitelib' | |
120 | installsitearch='$installsitearch' | |
121 | installscript='$installscript' | |
122 | scriptdir='$installscript' | |
123 | scriptdirexp='$installscript' | |
124 | EndOfIntro | |
125 | ||
126 | # Plan 9 compiler stuff | |
127 | print OUT "cc='pcc'\n"; | |
0dbb1585 AL |
128 | print OUT "d_attribute_format='undef'\n"; |
129 | print OUT "d_attribute_malloc='undef'\n"; | |
130 | print OUT "d_attribute_nonnull='undef'\n"; | |
131 | print OUT "d_attribute_noreturn='undef'\n"; | |
132 | print OUT "d_attribute_pure='undef'\n"; | |
133 | print OUT "d_attribute_unused='undef'\n"; | |
134 | print OUT "d_attribute_warn_unused_result='undef'\n"; | |
396e9e6f | 135 | print OUT "d_socket='define'\n"; |
136 | print OUT "d_sockpair='define'\n"; | |
3db6ecf2 AD |
137 | print OUT "d_static_inline='undef'\n"; |
138 | print OUT "perl_static_inline='static'\n"; | |
396e9e6f | 139 | print OUT "d_sigsetjmp='define'\n"; |
140 | print OUT "sigjmp_buf='sigjmp_buf'\n"; | |
141 | print OUT "sigsetjmp='sigsetjmp(buf,save_mask)'\n"; | |
142 | print OUT "siglongjmp='siglongjmp(buf,retval) '\n"; | |
143 | print OUT "exe_ext=''\n"; | |
144 | if ($p9p_objtype eq '386') { | |
145 | $objext = '.8'; | |
16da7c01 LH |
146 | $alignbytes = '4'; |
147 | $cstflags = 2; | |
396e9e6f | 148 | } |
149 | elsif ($p9p_objtype eq '68020') { | |
150 | $objext = '.2'; | |
16da7c01 LH |
151 | $alignbytes = '2'; |
152 | $cstflags = 0; | |
396e9e6f | 153 | } |
154 | elsif ($p9p_objtype eq 'mips') { | |
155 | $objext = '.v'; | |
16da7c01 LH |
156 | $alignbytes = '8'; |
157 | $cstflags = 0; | |
396e9e6f | 158 | } |
159 | elsif ($p9p_objtype eq 'sparc') { | |
160 | $objext = '.k'; | |
16da7c01 | 161 | $alignbytes = '4'; |
396e9e6f | 162 | $cstflags = 0; |
163 | } | |
16da7c01 LH |
164 | print OUT "obj_ext='$objext'\n"; |
165 | print OUT "alignbytes='$alignbytes'\n"; | |
396e9e6f | 166 | print OUT "castflags='$cstflags'\n"; |
167 | ||
168 | $myname = $ENV{'site'} ; | |
169 | ($myhostname,$mydomain) = split(/\./,$myname,2); | |
170 | print OUT "myhostname='$myhostname'\n" if $myhostname; | |
171 | if ($mydomain) { | |
172 | print OUT "mydomain='.$mydomain'\n"; | |
173 | print OUT "perladmin='$cf_by\@$myhostname.$mydomain'\n"; | |
174 | print OUT "cf_email='$cf_by\@$myhostname.$mydomain'\n"; | |
175 | } | |
176 | else { | |
177 | print OUT "perladmin='$cf_by'\n"; | |
178 | print OUT "cf_email='$cf_by'\n"; | |
179 | } | |
180 | print OUT "myuname='Plan9 $myname $osvers $p9p_objtype'\n"; | |
181 | ||
182 | # Before we read the C header file, find out what config.sh constants are | |
183 | # equivalent to the C preprocessor macros | |
1ae6ead9 | 184 | if (open(SH,'<',"${outdir}config_h.SH")) { |
396e9e6f | 185 | while (<SH>) { |
a123eb89 R |
186 | # suicide @ regcomp.c:22117 |
187 | #next unless m%^#(?!if).*\$%; | |
188 | next unless !index($_, '#') && index($_, '#if') == -1 && rindex($_, '$') == length($_)-1; | |
396e9e6f | 189 | s/^#//; s!(.*?)\s*/\*.*!$1!; |
190 | my(@words) = split; | |
191 | $words[1] =~ s/\(.*//; # Clip off args from macro | |
192 | # Did we use a shell variable for the preprocessor directive? | |
193 | if ($words[0] =~ m!^\$(\w+)!) { $pp_vars{$words[1]} = $1; } | |
194 | if (@words > 2) { # We may also have a shell var in the value | |
195 | shift @words; # Discard preprocessor directive | |
196 | my($token) = shift @words; # and keep constant name | |
197 | my($word); | |
198 | foreach $word (@words) { | |
199 | next unless $word =~ m!\$(\w+)!; | |
200 | $val_vars{$token} = $1; | |
201 | last; | |
202 | } | |
203 | } | |
204 | } | |
205 | close SH; | |
206 | } | |
a123eb89 | 207 | elsif ($VERBOSE) { warn "Couldn't read ${outfile}config_h.SH: $!\n"; } |
396e9e6f | 208 | $pp_vars{PLAN9} = 'define'; #Plan 9 specific |
209 | ||
210 | # OK, now read the C header file, and retcon statements into config.sh | |
211 | while (<IN>) { # roll through the comment header in config.h | |
212 | last if /config-start/; | |
213 | } | |
214 | ||
215 | while (<IN>) { | |
216 | chop; | |
7237a61d | 217 | while (/\\\s*$/) { # pick up continuation lines |
396e9e6f | 218 | my $line = $_; |
219 | $line =~ s/\\\s*$//; | |
220 | $_ = <IN>; | |
221 | s/^\s*//; | |
222 | $_ = $line . $_; | |
223 | } | |
224 | next unless my ($blocked,$un,$token,$val) = | |
225 | m%^(\/\*)?\s*\#\s*(un)?def\w*\s+([A-Za-z0-9]\w+)\S*\s*(.*)%; | |
226 | if (/config-skip/) { | |
227 | delete $pp_vars{$token} if exists $pp_vars{$token}; | |
228 | delete $val_vars{$token} if exists $val_vars{$token}; | |
229 | next; | |
230 | } | |
231 | $val =~ s!\s*/\*.*!!; # strip off trailing comment | |
232 | my($had_val); # Maybe a macro with args that we just #undefd or commented | |
233 | if (!length($val) and $val_vars{$token} and ($un || $blocked)) { | |
234 | print OUT "$val_vars{$token}=''\n"; | |
235 | delete $val_vars{$token}; | |
236 | $had_val = 1; | |
237 | } | |
238 | $state = ($blocked || $un) ? 'undef' : 'define'; | |
239 | if ($pp_vars{$token}) { | |
240 | print OUT "$pp_vars{$token}='$state'\n"; | |
241 | delete $pp_vars{$token}; | |
242 | } | |
243 | elsif (not length $val and not $had_val) { | |
244 | # Wups -- should have been shell var for C preprocessor directive | |
a123eb89 | 245 | warn "Constant $token not found in config_h.SH\n" if $VERBOSE; |
396e9e6f | 246 | $token =~ tr/A-Z/a-z/; |
247 | $token = "d_$token" unless $token =~ /^i_/; | |
248 | print OUT "$token='$state'\n"; | |
249 | } | |
250 | next unless length $val; | |
251 | $val =~ s/^"//; $val =~ s/"$//; # remove end quotes | |
252 | $val =~ s/","/ /g; # make signal list look nice | |
253 | ||
254 | if ($val_vars{$token}) { | |
255 | print OUT "$val_vars{$token}='$val'\n"; | |
256 | if ($val_vars{$token} =~ s/exp$//) {print OUT "$val_vars{$token}='$val'\n";} | |
257 | delete $val_vars{$token}; | |
258 | } | |
259 | elsif (!$pp_vars{$token}) { # Haven't seen it previously, either | |
a123eb89 | 260 | warn "Constant $token not found in config_h.SH (val=|$val|)\n" if $VERBOSE; |
396e9e6f | 261 | $token =~ tr/A-Z/a-z/; |
262 | print OUT "$token='$val'\n"; | |
263 | if ($token =~ s/exp$//) {print OUT "$token='$val'\n";} | |
264 | } | |
265 | } | |
266 | close IN; | |
267 | ||
a123eb89 R |
268 | if ($VERBOSE) { |
269 | foreach (sort keys %pp_vars) { | |
270 | warn "Didn't see $_ in $infile\n"; | |
271 | } | |
272 | foreach (sort keys %val_vars) { | |
273 | warn "Didn't see $_ in $infile(val)\n"; | |
274 | } | |
396e9e6f | 275 | } |
276 | ||
396e9e6f | 277 | # print OUT "libs='",join(' ',@libs),"'\n"; |
278 | # print OUT "libc='",join(' ',@crtls),"'\n"; | |
279 | ||
1ae6ead9 | 280 | if (open(PL,'<',"${outdir}patchlevel.h")) { |
396e9e6f | 281 | while (<PL>) { |
cceca5ed GS |
282 | if (/^#define PERL_VERSION\s+(\S+)/) { |
283 | print OUT "PERL_VERSION='$1'\n"; | |
284 | print OUT "PATCHLEVEL='$1'\n"; # XXX compat | |
285 | } | |
286 | elsif (/^#define PERL_SUBVERSION\s+(\S+)/) { | |
287 | print OUT "PERL_SUBVERSION='$1'\n"; | |
288 | print OUT "SUBVERSION='$1'\n"; # XXX compat | |
289 | } | |
396e9e6f | 290 | } |
291 | close PL; | |
292 | } | |
a123eb89 | 293 | elsif ($VERBOSE) { warn "Can't read ${outdir}patchlevel.h - skipping 'PERL_VERSION'" } |
396e9e6f | 294 | |
295 | print OUT "pager='/bin/p'\n"; | |
296 | ||
297 | close OUT; |