xref: /openbsd/gnu/usr.bin/perl/plan9/genconfig.pl (revision eac174f2)
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# Last Modified: May 2020 David Romano	unobe@cpan.org
11#
12
13my $VERBOSE = 0;
14
15#==== Locations of installed Perl components
16$p9pvers="_P9P_VERSION";
17$version="$p9pvers";
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";
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";
30
31unshift(@INC,'lib');  # In case someone didn't define Perl_Root
32                      # before the build
33
34if ($ARGV[0] eq '-f') {
35  shift @ARGV;
36  open(ARGS,'<',$ARGV[1]) or die "Can't read data from $ARGV[1]: $!\n";
37  shift @ARGV;
38  while (<ARGS>) {
39    push(@ARGV,split(/\|/,$_));
40  }
41  close ARGS;
42}
43my @extensions = @ARGV;
44
45if (-f "config.h") { $infile = "config.h"; $outdir = "../"; }
46elsif (-f "plan9/config.h") { $infile = "plan9/config.h";  $outdir = "./"; }
47
48if ($infile) { print "Generating config.sh from $infile . . .\n"; }
49else { die <<EndOfGasp;
50Can't find config.h to read!
51	Please run this script from the perl source directory or
52	the plan9 subdirectory in the distribution.
53EndOfGasp
54}
55$outdir = '';
56open(IN,'<',$infile) || die "Can't open $infile: $!\n";
57open(OUT,'>',"${outdir}config.sh") || die "Can't open ${outdir}config.sh: $!\n";
58
59$time = localtime;
60$cf_by = $ENV{'user'};
61($vers = $]) =~ tr/./_/;
62
63# 9front as Plan 9, 5th edition.
64$osvers = '5';
65
66print 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
73package='perl5'
74PERL_CONFIG_SH='true'
75cf_time='$time'
76cf_by='$cf_by'
77ccdlflags=''
78cccdlflags=''
79libpth='$installprivlib'
80ld='pcc'
81cppflags=''
82cppstdin='cpp'
83lddlflags=''
84ranlib=''
85ar='ar'
86nroff='/bin/nroff'
87eunicefix=':'
88hint='none'
89hintfile=''
90intsize='4'
91longsize='4'
92shortsize='2'
93shrplib='define'
94usemymalloc='n'
95usevfork='true'
96useposix='true'
97spitshell='cat'
98dlsrc='dl_none.c'
99binexp='$installbin'
100man1ext=''
101man3ext=''
102arch='$archname'
103archname='$archname'
104osname='plan9'
105version='$p9pvers'
106extensions='@extensions'
107osvers='$osvers'
108sig_maxsig='19'
109sig_name='ZERO HUP INT QUIT ILL ABRT FPE KILL SEGV PIPE ALRM TERM USR1 USR2 CHLD CONT STOP TSTP TTIN TTOU'
110sig_num='0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19'
111sig_numsig='20'
112prefix='$prefix'
113builddir='$builddir'
114installbin='$installbin'
115installman1dir='$installman1dir'
116installman3dir='$installman3dir'
117installprivlib='$installprivlib'
118installarchlib='$installarchlib'
119installsitelib='$installsitelib'
120installsitearch='$installsitearch'
121installscript='$installscript'
122scriptdir='$installscript'
123scriptdirexp='$installscript'
124EndOfIntro
125
126# Plan 9 compiler stuff
127print OUT "cc='pcc'\n";
128print OUT "d_attribute_format='undef'\n";
129print OUT "d_attribute_malloc='undef'\n";
130print OUT "d_attribute_nonnull='undef'\n";
131print OUT "d_attribute_noreturn='undef'\n";
132print OUT "d_attribute_pure='undef'\n";
133print OUT "d_attribute_unused='undef'\n";
134print OUT "d_attribute_warn_unused_result='undef'\n";
135print OUT "d_socket='define'\n";
136print OUT "d_sockpair='define'\n";
137print OUT "d_static_inline='undef'\n";
138print OUT "perl_static_inline='static'\n";
139print OUT "d_sigsetjmp='define'\n";
140print OUT "sigjmp_buf='sigjmp_buf'\n";
141print OUT "sigsetjmp='sigsetjmp(buf,save_mask)'\n";
142print OUT "siglongjmp='siglongjmp(buf,retval) '\n";
143print OUT "exe_ext=''\n";
144if ($p9p_objtype eq '386') {
145	$objext = '.8';
146	$alignbytes = '4';
147	$cstflags = 2;
148}
149elsif ($p9p_objtype eq '68020') {
150	$objext = '.2';
151	$alignbytes = '2';
152	$cstflags = 0;
153}
154elsif ($p9p_objtype eq 'mips') {
155	$objext = '.v';
156	$alignbytes = '8';
157	$cstflags = 0;
158}
159elsif ($p9p_objtype eq 'sparc') {
160	$objext = '.k';
161	$alignbytes = '4';
162	$cstflags = 0;
163}
164print OUT "obj_ext='$objext'\n";
165print OUT "alignbytes='$alignbytes'\n";
166print OUT "castflags='$cstflags'\n";
167
168$myname = $ENV{'site'} ;
169($myhostname,$mydomain) = split(/\./,$myname,2);
170print OUT "myhostname='$myhostname'\n" if $myhostname;
171if ($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}
176else {
177  print OUT "perladmin='$cf_by'\n";
178  print OUT "cf_email='$cf_by'\n";
179}
180print 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
184if (open(SH,'<',"${outdir}config_h.SH")) {
185  while (<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!;
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}
207elsif ($VERBOSE) { warn "Couldn't read ${outfile}config_h.SH: $!\n"; }
208$pp_vars{PLAN9} = 'define'; #Plan 9 specific
209
210# OK, now read the C header file, and retcon statements into config.sh
211while (<IN>) {  # roll through the comment header in config.h
212  last if /config-start/;
213}
214
215while (<IN>) {
216  chop;
217  while (/\\\s*$/) {  # pick up continuation lines
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
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";
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
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";}
264  }
265}
266close IN;
267
268if ($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  }
275}
276
277# print OUT "libs='",join(' ',@libs),"'\n";
278# print OUT "libc='",join(' ',@crtls),"'\n";
279
280if (open(PL,'<',"${outdir}patchlevel.h")) {
281  while (<PL>) {
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    }
290  }
291  close PL;
292}
293elsif ($VERBOSE) { warn "Can't read ${outdir}patchlevel.h - skipping 'PERL_VERSION'" }
294
295print OUT "pager='/bin/p'\n";
296
297close OUT;
298