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.
9 # Last Modified: 28-Jun-1996 Luther Huffman lutherh@stratcom.com
10 # Last Modified: May 2020 David Romano unobe@cpan.org
15 #==== Locations of installed Perl components
16 $p9pvers="_P9P_VERSION";
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";
24 $installprivlib="/sys/lib/perl/$p9pvers";
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";
31 unshift(@INC,'lib'); # In case someone didn't define Perl_Root
34 if ($ARGV[0] eq '-f') {
36 open(ARGS,'<',$ARGV[1]) or die "Can't read data from $ARGV[1]: $!\n";
39 push(@ARGV,split(/\|/,$_));
43 my @extensions = @ARGV;
45 if (-f "config.h") { $infile = "config.h"; $outdir = "../"; }
46 elsif (-f "plan9/config.h") { $infile = "plan9/config.h"; $outdir = "./"; }
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.
56 open(IN,'<',$infile) || die "Can't open $infile: $!\n";
57 open(OUT,'>',"${outdir}config.sh") || die "Can't open ${outdir}config.sh: $!\n";
60 $cf_by = $ENV{'user'};
61 ($vers = $]) =~ tr/./_/;
63 # 9front as Plan 9, 5th edition.
66 print OUT <<EndOfIntro;
67 # This file generated by genconfig.pl on a Plan 9 system.
68 # Input obtained from:
79 libpth='$installprivlib'
106 extensions='@extensions'
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'
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'
126 # Plan 9 compiler stuff
127 print OUT "cc='pcc'\n";
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";
135 print OUT "d_socket='define'\n";
136 print OUT "d_sockpair='define'\n";
137 print OUT "d_static_inline='undef'\n";
138 print OUT "perl_static_inline='static'\n";
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') {
149 elsif ($p9p_objtype eq '68020') {
154 elsif ($p9p_objtype eq 'mips') {
159 elsif ($p9p_objtype eq 'sparc') {
164 print OUT "obj_ext='$objext'\n";
165 print OUT "alignbytes='$alignbytes'\n";
166 print OUT "castflags='$cstflags'\n";
168 $myname = $ENV{'site'} ;
169 ($myhostname,$mydomain) = split(/\./,$myname,2);
170 print OUT "myhostname='$myhostname'\n" if $myhostname;
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";
177 print OUT "perladmin='$cf_by'\n";
178 print OUT "cf_email='$cf_by'\n";
180 print OUT "myuname='Plan9 $myname $osvers $p9p_objtype'\n";
182 # Before we read the C header file, find out what config.sh constants are
183 # equivalent to the C preprocessor macros
184 if (open(SH,'<',"${outdir}config_h.SH")) {
186 # suicide @ regcomp.c:22117
187 #next unless m%^#(?!if).*\$%;
188 next unless !index($_, '#') && index($_, '#if') == -1 && rindex($_, '$') == length($_)-1;
189 s/^#//; s!(.*?)\s*/\*.*!$1!;
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
198 foreach $word (@words) {
199 next unless $word =~ m!\$(\w+)!;
200 $val_vars{$token} = $1;
207 elsif ($VERBOSE) { warn "Couldn't read ${outfile}config_h.SH: $!\n"; }
208 $pp_vars{PLAN9} = 'define'; #Plan 9 specific
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/;
217 while (/\\\s*$/) { # pick up continuation lines
224 next unless my ($blocked,$un,$token,$val) =
225 m%^(\/\*)?\s*\#\s*(un)?def\w*\s+([A-Za-z0-9]\w+)\S*\s*(.*)%;
227 delete $pp_vars{$token} if exists $pp_vars{$token};
228 delete $val_vars{$token} if exists $val_vars{$token};
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};
238 $state = ($blocked || $un) ? 'undef' : 'define';
239 if ($pp_vars{$token}) {
240 print OUT "$pp_vars{$token}='$state'\n";
241 delete $pp_vars{$token};
243 elsif (not length $val and not $had_val) {
244 # Wups -- should have been shell var for C preprocessor directive
245 warn "Constant $token not found in config_h.SH\n" if $VERBOSE;
246 $token =~ tr/A-Z/a-z/;
247 $token = "d_$token" unless $token =~ /^i_/;
248 print OUT "$token='$state'\n";
250 next unless length $val;
251 $val =~ s/^"//; $val =~ s/"$//; # remove end quotes
252 $val =~ s/","/ /g; # make signal list look nice
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};
259 elsif (!$pp_vars{$token}) { # Haven't seen it previously, either
260 warn "Constant $token not found in config_h.SH (val=|$val|)\n" if $VERBOSE;
261 $token =~ tr/A-Z/a-z/;
262 print OUT "$token='$val'\n";
263 if ($token =~ s/exp$//) {print OUT "$token='$val'\n";}
269 foreach (sort keys %pp_vars) {
270 warn "Didn't see $_ in $infile\n";
272 foreach (sort keys %val_vars) {
273 warn "Didn't see $_ in $infile(val)\n";
277 # print OUT "libs='",join(' ',@libs),"'\n";
278 # print OUT "libc='",join(' ',@crtls),"'\n";
280 if (open(PL,'<',"${outdir}patchlevel.h")) {
282 if (/^#define PERL_VERSION\s+(\S+)/) {
283 print OUT "PERL_VERSION='$1'\n";
284 print OUT "PATCHLEVEL='$1'\n"; # XXX compat
286 elsif (/^#define PERL_SUBVERSION\s+(\S+)/) {
287 print OUT "PERL_SUBVERSION='$1'\n";
288 print OUT "SUBVERSION='$1'\n"; # XXX compat
293 elsif ($VERBOSE) { warn "Can't read ${outdir}patchlevel.h - skipping 'PERL_VERSION'" }
295 print OUT "pager='/bin/p'\n";