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
12 #==== Locations of installed Perl components
13 $p9pvers="_P9P_VERSION";
15 $p9p_objtype=$ENV{'objtype'};
16 $builddir="/sys/src/cmd/perl/$p9pvers";
17 $installbin="/$p9p_objtype/bin";
18 $installman1dir="/sys/man/1";
19 $installman3dir="/sys/man/2";
20 $installprivlib="/sys/lib/perl";
21 $installarchlib = "/$p9p_objtype/lib/perl/$p9pvers";
22 $archname="plan9_$p9p_objtype";
23 $installsitelib="$installprivlib/site_perl";
24 $installsitearch="$installarchlib/site_perl";
25 $installscript="/bin";
27 unshift(@INC,'lib'); # In case someone didn't define Perl_Root
30 if ($ARGV[0] eq '-f') {
31 open(ARGS,$ARGV[1]) or die "Can't read data from $ARGV[1]: $!\n";
34 push(@ARGV,split(/\|/,$_));
39 if (-f "config.h") { $infile = "config.h"; $outdir = "../"; }
40 elsif (-f "plan9/config.h") { $infile = "plan9/config.h"; $outdir = "./"; }
42 if ($infile) { print "Generating config.sh from $infile . . .\n"; }
43 else { die <<EndOfGasp;
44 Can't find config.h to read!
45 Please run this script from the perl source directory or
46 the plan9 subdirectory in the distribution.
50 open(IN,"$infile") || die "Can't open $infile: $!\n";
51 open(OUT,">${outdir}config.sh") || die "Can't open ${outdir}config.sh: $!\n";
54 $cf_by = $ENV{'user'};
55 ($vers = $]) =~ tr/./_/;
57 # Plan 9 doesn't actually use version numbering. Following the original Unix
58 # precedent of assigning a Unix edition number based on the edition number
59 # of the manuals, I am referring to this as Plan 9, 1st edition.
62 print OUT <<EndOfIntro;
63 # This file generated by genconfig.pl on a Plan 9 system.
64 # Input obtained from:
75 libpth='$installprivlib'
98 extensions='IO Socket Opcode Fcntl POSIX DynaLoader FileHandle'
101 sig_name='ZERO HUP INT QUIT ILL ABRT FPE KILL SEGV PIPE ALRM TERM USR1 USR2 CHLD CONT STOP TSTP TTIN TTOU'
102 sig_num='0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19'
106 installbin='$installbin'
107 installman1dir='$installman1dir'
108 installman3dir='$installman3dir'
109 installprivlib='$installprivlib'
110 installarchlib='$installarchlib'
111 installsitelib='$installsitelib'
112 installsitearch='$installsitearch'
113 installscript='$installscript'
114 scriptdir='$installscript'
115 scriptdirexp='$installscript'
118 # Plan 9 compiler stuff
119 print OUT "cc='pcc'\n";
120 print OUT "d_attribut='undef'\n";
121 print OUT "d_socket='define'\n";
122 print OUT "d_sockpair='define'\n";
123 print OUT "d_sigsetjmp='define'\n";
124 print OUT "sigjmp_buf='sigjmp_buf'\n";
125 print OUT "sigsetjmp='sigsetjmp(buf,save_mask)'\n";
126 print OUT "siglongjmp='siglongjmp(buf,retval) '\n";
127 print OUT "exe_ext=''\n";
128 if ($p9p_objtype eq '386') {
131 elsif ($p9p_objtype eq '68020') {
134 elsif ($p9p_objtype eq 'mips') {
137 elsif ($p9p_objtype eq 'sparc') {
140 print OUT "obj_ext='$objext'\n";
142 if ($p9p_objtype eq '386') {
148 print OUT "castflags='$cstflags'\n";
150 $myname = $ENV{'site'} ;
151 ($myhostname,$mydomain) = split(/\./,$myname,2);
152 print OUT "myhostname='$myhostname'\n" if $myhostname;
154 print OUT "mydomain='.$mydomain'\n";
155 print OUT "perladmin='$cf_by\@$myhostname.$mydomain'\n";
156 print OUT "cf_email='$cf_by\@$myhostname.$mydomain'\n";
159 print OUT "perladmin='$cf_by'\n";
160 print OUT "cf_email='$cf_by'\n";
162 print OUT "myuname='Plan9 $myname $osvers $p9p_objtype'\n";
164 # Before we read the C header file, find out what config.sh constants are
165 # equivalent to the C preprocessor macros
166 if (open(SH,"${outdir}config_h.SH")) {
168 next unless m%^#(?!if).*\$%;
169 s/^#//; s!(.*?)\s*/\*.*!$1!;
171 $words[1] =~ s/\(.*//; # Clip off args from macro
172 # Did we use a shell variable for the preprocessor directive?
173 if ($words[0] =~ m!^\$(\w+)!) { $pp_vars{$words[1]} = $1; }
174 if (@words > 2) { # We may also have a shell var in the value
175 shift @words; # Discard preprocessor directive
176 my($token) = shift @words; # and keep constant name
178 foreach $word (@words) {
179 next unless $word =~ m!\$(\w+)!;
180 $val_vars{$token} = $1;
187 else { warn "Couldn't read ${outfile}config_h.SH: $!\n"; }
188 $pp_vars{PLAN9} = 'define'; #Plan 9 specific
190 # OK, now read the C header file, and retcon statements into config.sh
191 while (<IN>) { # roll through the comment header in config.h
192 last if /config-start/;
197 while (/\\\s*$/) { # pick up contination lines
204 next unless my ($blocked,$un,$token,$val) =
205 m%^(\/\*)?\s*\#\s*(un)?def\w*\s+([A-Za-z0-9]\w+)\S*\s*(.*)%;
207 delete $pp_vars{$token} if exists $pp_vars{$token};
208 delete $val_vars{$token} if exists $val_vars{$token};
211 $val =~ s!\s*/\*.*!!; # strip off trailing comment
212 my($had_val); # Maybe a macro with args that we just #undefd or commented
213 if (!length($val) and $val_vars{$token} and ($un || $blocked)) {
214 print OUT "$val_vars{$token}=''\n";
215 delete $val_vars{$token};
218 $state = ($blocked || $un) ? 'undef' : 'define';
219 if ($pp_vars{$token}) {
220 print OUT "$pp_vars{$token}='$state'\n";
221 delete $pp_vars{$token};
223 elsif (not length $val and not $had_val) {
224 # Wups -- should have been shell var for C preprocessor directive
225 warn "Constant $token not found in config_h.SH\n";
226 $token =~ tr/A-Z/a-z/;
227 $token = "d_$token" unless $token =~ /^i_/;
228 print OUT "$token='$state'\n";
230 next unless length $val;
231 $val =~ s/^"//; $val =~ s/"$//; # remove end quotes
232 $val =~ s/","/ /g; # make signal list look nice
234 if ($val_vars{$token}) {
235 print OUT "$val_vars{$token}='$val'\n";
236 if ($val_vars{$token} =~ s/exp$//) {print OUT "$val_vars{$token}='$val'\n";}
237 delete $val_vars{$token};
239 elsif (!$pp_vars{$token}) { # Haven't seen it previously, either
240 warn "Constant $token not found in config_h.SH (val=|$val|)\n";
241 $token =~ tr/A-Z/a-z/;
242 print OUT "$token='$val'\n";
243 if ($token =~ s/exp$//) {print OUT "$token='$val'\n";}
248 foreach (sort keys %pp_vars) {
249 warn "Didn't see $_ in $infile\n";
251 foreach (sort keys %val_vars) {
252 warn "Didn't see $_ in $infile(val)\n";
256 # print OUT "libs='",join(' ',@libs),"'\n";
257 # print OUT "libc='",join(' ',@crtls),"'\n";
259 if (open(PL,"${outdir}patchlevel.h")) {
261 if (/^#define PATCHLEVEL\s+(\S+)/) { print OUT "PATCHLEVEL='$1'\n"; }
262 elsif (/^#define SUBVERSION\s+(\S+)/) { print OUT "SUBVERSION='$1'\n"; }
266 else { warn "Can't read ${outdir}patchlevel.h - skipping 'PATCHLEVEL'"; }
268 print OUT "pager='/bin/p'\n";