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