1*0Sstevel@tonic-gate#!./miniperl -w 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gate# commonly used names to put first (and hence lookup fastest) 4*0Sstevel@tonic-gatemy %Common = map {($_,$_)} 5*0Sstevel@tonic-gate qw(archname osname osvers prefix libs libpth 6*0Sstevel@tonic-gate dynamic_ext static_ext dlsrc so 7*0Sstevel@tonic-gate cc ccflags cppflags 8*0Sstevel@tonic-gate privlibexp archlibexp installprivlib installarchlib 9*0Sstevel@tonic-gate sharpbang startsh shsharp 10*0Sstevel@tonic-gate ); 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gate# names of things which may need to have slashes changed to double-colons 13*0Sstevel@tonic-gatemy %Extensions = map {($_,$_)} 14*0Sstevel@tonic-gate qw(dynamic_ext static_ext extensions known_extensions); 15*0Sstevel@tonic-gate 16*0Sstevel@tonic-gate# allowed opts as well as specifies default and initial values 17*0Sstevel@tonic-gatemy %Allowed_Opts = ( 18*0Sstevel@tonic-gate 'cross' => '', # --cross=PALTFORM - crosscompiling for PLATFORM 19*0Sstevel@tonic-gate 'glossary' => 1, # --no-glossary - no glossary file inclusion, 20*0Sstevel@tonic-gate # for compactness 21*0Sstevel@tonic-gate); 22*0Sstevel@tonic-gate 23*0Sstevel@tonic-gatesub opts { 24*0Sstevel@tonic-gate # user specified options 25*0Sstevel@tonic-gate my %given_opts = ( 26*0Sstevel@tonic-gate # --opt=smth 27*0Sstevel@tonic-gate (map {/^--([\-_\w]+)=(.*)$/} @ARGV), 28*0Sstevel@tonic-gate # --opt --no-opt --noopt 29*0Sstevel@tonic-gate (map {/^no-?(.*)$/i?($1=>0):($_=>1)} map {/^--([\-_\w]+)$/} @ARGV), 30*0Sstevel@tonic-gate ); 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate my %opts = (%Allowed_Opts, %given_opts); 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate for my $opt (grep {!exists $Allowed_Opts{$_}} keys %given_opts) { 35*0Sstevel@tonic-gate die "option '$opt' is not recognized"; 36*0Sstevel@tonic-gate } 37*0Sstevel@tonic-gate @ARGV = grep {!/^--/} @ARGV; 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate return %opts; 40*0Sstevel@tonic-gate} 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gatemy %Opts = opts(); 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gatemy $Config_PM; 46*0Sstevel@tonic-gatemy $Glossary = $ARGV[1] || 'Porting/Glossary'; 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gateif ($Opts{cross}) { 49*0Sstevel@tonic-gate # creating cross-platform config file 50*0Sstevel@tonic-gate mkdir "xlib"; 51*0Sstevel@tonic-gate mkdir "xlib/$Opts{cross}"; 52*0Sstevel@tonic-gate $Config_PM = $ARGV[0] || "xlib/$Opts{cross}/Config.pm"; 53*0Sstevel@tonic-gate} 54*0Sstevel@tonic-gateelse { 55*0Sstevel@tonic-gate $Config_PM = $ARGV[0] || 'lib/Config.pm'; 56*0Sstevel@tonic-gate} 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate 59*0Sstevel@tonic-gateopen CONFIG, ">$Config_PM" or die "Can't open $Config_PM: $!\n"; 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gatemy $myver = sprintf "v%vd", $^V; 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gateprintf CONFIG <<'ENDOFBEG', ($myver) x 3; 64*0Sstevel@tonic-gate# This file was created by configpm when Perl was built. Any changes 65*0Sstevel@tonic-gate# made to this file will be lost the next time perl is built. 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gatepackage Config; 68*0Sstevel@tonic-gate@EXPORT = qw(%%Config); 69*0Sstevel@tonic-gate@EXPORT_OK = qw(myconfig config_sh config_vars config_re); 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gatemy %%Export_Cache = map {($_ => 1)} (@EXPORT, @EXPORT_OK); 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate# Define our own import method to avoid pulling in the full Exporter: 74*0Sstevel@tonic-gatesub import { 75*0Sstevel@tonic-gate my $pkg = shift; 76*0Sstevel@tonic-gate @_ = @EXPORT unless @_; 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate my @funcs = grep $_ ne '%%Config', @_; 79*0Sstevel@tonic-gate my $export_Config = @funcs < @_ ? 1 : 0; 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate my $callpkg = caller(0); 82*0Sstevel@tonic-gate foreach my $func (@funcs) { 83*0Sstevel@tonic-gate die sprintf qq{"%%s" is not exported by the %%s module\n}, 84*0Sstevel@tonic-gate $func, __PACKAGE__ unless $Export_Cache{$func}; 85*0Sstevel@tonic-gate *{$callpkg.'::'.$func} = \&{$func}; 86*0Sstevel@tonic-gate } 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate *{"$callpkg\::Config"} = \%%Config if $export_Config; 89*0Sstevel@tonic-gate return; 90*0Sstevel@tonic-gate} 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gatedie "Perl lib version (%s) doesn't match executable version ($])" 93*0Sstevel@tonic-gate unless $^V; 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate$^V eq %s 96*0Sstevel@tonic-gate or die "Perl lib version (%s) doesn't match executable version (" . 97*0Sstevel@tonic-gate sprintf("v%%vd",$^V) . ")"; 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gateENDOFBEG 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gatemy @non_v = (); 103*0Sstevel@tonic-gatemy @v_fast = (); 104*0Sstevel@tonic-gatemy %v_fast = (); 105*0Sstevel@tonic-gatemy @v_others = (); 106*0Sstevel@tonic-gatemy $in_v = 0; 107*0Sstevel@tonic-gatemy %Data = (); 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gate# This is somewhat grim, but I want the code for parsing config.sh here and 110*0Sstevel@tonic-gate# now so that I can expand $Config{ivsize} and $Config{ivtype} 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gatemy $fetch_string = <<'EOT'; 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gate# Search for it in the big string 115*0Sstevel@tonic-gatesub fetch_string { 116*0Sstevel@tonic-gate my($self, $key) = @_; 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate my $quote_type = "'"; 119*0Sstevel@tonic-gate my $marker = "$key="; 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate # Check for the common case, ' delimited 122*0Sstevel@tonic-gate my $start = index($Config_SH, "\n$marker$quote_type"); 123*0Sstevel@tonic-gate # If that failed, check for " delimited 124*0Sstevel@tonic-gate if ($start == -1) { 125*0Sstevel@tonic-gate $quote_type = '"'; 126*0Sstevel@tonic-gate $start = index($Config_SH, "\n$marker$quote_type"); 127*0Sstevel@tonic-gate } 128*0Sstevel@tonic-gate return undef if ( ($start == -1) && # in case it's first 129*0Sstevel@tonic-gate (substr($Config_SH, 0, length($marker)) ne $marker) ); 130*0Sstevel@tonic-gate if ($start == -1) { 131*0Sstevel@tonic-gate # It's the very first thing we found. Skip $start forward 132*0Sstevel@tonic-gate # and figure out the quote mark after the =. 133*0Sstevel@tonic-gate $start = length($marker) + 1; 134*0Sstevel@tonic-gate $quote_type = substr($Config_SH, $start - 1, 1); 135*0Sstevel@tonic-gate } 136*0Sstevel@tonic-gate else { 137*0Sstevel@tonic-gate $start += length($marker) + 2; 138*0Sstevel@tonic-gate } 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate my $value = substr($Config_SH, $start, 141*0Sstevel@tonic-gate index($Config_SH, "$quote_type\n", $start) - $start); 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate # If we had a double-quote, we'd better eval it so escape 144*0Sstevel@tonic-gate # sequences and such can be interpolated. Since the incoming 145*0Sstevel@tonic-gate # value is supposed to follow shell rules and not perl rules, 146*0Sstevel@tonic-gate # we escape any perl variable markers 147*0Sstevel@tonic-gate if ($quote_type eq '"') { 148*0Sstevel@tonic-gate $value =~ s/\$/\\\$/g; 149*0Sstevel@tonic-gate $value =~ s/\@/\\\@/g; 150*0Sstevel@tonic-gate eval "\$value = \"$value\""; 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate # So we can say "if $Config{'foo'}". 154*0Sstevel@tonic-gate $value = undef if $value eq 'undef'; 155*0Sstevel@tonic-gate $self->{$key} = $value; # cache it 156*0Sstevel@tonic-gate} 157*0Sstevel@tonic-gateEOT 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gateeval $fetch_string; 160*0Sstevel@tonic-gatedie if $@; 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gateopen(CONFIG_SH, 'config.sh') || die "Can't open config.sh: $!"; 163*0Sstevel@tonic-gatewhile (<CONFIG_SH>) { 164*0Sstevel@tonic-gate next if m:^#!/bin/sh:; 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate # Catch PERL_CONFIG_SH=true and PERL_VERSION=n line from Configure. 167*0Sstevel@tonic-gate s/^(\w+)=(true|\d+)\s*$/$1='$2'\n/ or m/^(\w+)='(.*)'$/; 168*0Sstevel@tonic-gate my($k, $v) = ($1, $2); 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate # grandfather PATCHLEVEL and SUBVERSION and CONFIG 171*0Sstevel@tonic-gate if ($k) { 172*0Sstevel@tonic-gate if ($k eq 'PERL_VERSION') { 173*0Sstevel@tonic-gate push @v_others, "PATCHLEVEL='$v'\n"; 174*0Sstevel@tonic-gate } 175*0Sstevel@tonic-gate elsif ($k eq 'PERL_SUBVERSION') { 176*0Sstevel@tonic-gate push @v_others, "SUBVERSION='$v'\n"; 177*0Sstevel@tonic-gate } 178*0Sstevel@tonic-gate elsif ($k eq 'PERL_CONFIG_SH') { 179*0Sstevel@tonic-gate push @v_others, "CONFIG='$v'\n"; 180*0Sstevel@tonic-gate } 181*0Sstevel@tonic-gate } 182*0Sstevel@tonic-gate 183*0Sstevel@tonic-gate # We can delimit things in config.sh with either ' or ". 184*0Sstevel@tonic-gate unless ($in_v or m/^(\w+)=(['"])(.*\n)/){ 185*0Sstevel@tonic-gate push(@non_v, "#$_"); # not a name='value' line 186*0Sstevel@tonic-gate next; 187*0Sstevel@tonic-gate } 188*0Sstevel@tonic-gate $quote = $2; 189*0Sstevel@tonic-gate if ($in_v) { 190*0Sstevel@tonic-gate $val .= $_; 191*0Sstevel@tonic-gate } 192*0Sstevel@tonic-gate else { 193*0Sstevel@tonic-gate ($name,$val) = ($1,$3); 194*0Sstevel@tonic-gate } 195*0Sstevel@tonic-gate $in_v = $val !~ /$quote\n/; 196*0Sstevel@tonic-gate next if $in_v; 197*0Sstevel@tonic-gate 198*0Sstevel@tonic-gate s,/,::,g if $Extensions{$name}; 199*0Sstevel@tonic-gate 200*0Sstevel@tonic-gate $val =~ s/$quote\n?\z//; 201*0Sstevel@tonic-gate 202*0Sstevel@tonic-gate my $line = "$name=$quote$val$quote\n"; 203*0Sstevel@tonic-gate if (!$Common{$name}){ 204*0Sstevel@tonic-gate push(@v_others, $line); 205*0Sstevel@tonic-gate } 206*0Sstevel@tonic-gate else { 207*0Sstevel@tonic-gate push(@v_fast, $line); 208*0Sstevel@tonic-gate $v_fast{$name} = "'$name' => $quote$val$quote"; 209*0Sstevel@tonic-gate } 210*0Sstevel@tonic-gate} 211*0Sstevel@tonic-gateclose CONFIG_SH; 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gateprint CONFIG @non_v, "\n"; 214*0Sstevel@tonic-gate 215*0Sstevel@tonic-gate# copy config summary format from the myconfig.SH script 216*0Sstevel@tonic-gateprint CONFIG "our \$summary : unique = <<'!END!';\n"; 217*0Sstevel@tonic-gateopen(MYCONFIG,"<myconfig.SH") || die "open myconfig.SH failed: $!"; 218*0Sstevel@tonic-gate1 while defined($_ = <MYCONFIG>) && !/^Summary of/; 219*0Sstevel@tonic-gatedo { print CONFIG $_ } until !defined($_ = <MYCONFIG>) || /^\s*$/; 220*0Sstevel@tonic-gateclose(MYCONFIG); 221*0Sstevel@tonic-gate 222*0Sstevel@tonic-gate# NB. as $summary is unique, we need to copy it in a lexical variable 223*0Sstevel@tonic-gate# before expanding it, because may have been made readonly if a perl 224*0Sstevel@tonic-gate# interpreter has been cloned. 225*0Sstevel@tonic-gate 226*0Sstevel@tonic-gateprint CONFIG "\n!END!\n", <<'EOT'; 227*0Sstevel@tonic-gatemy $summary_expanded; 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gatesub myconfig { 230*0Sstevel@tonic-gate return $summary_expanded if $summary_expanded; 231*0Sstevel@tonic-gate ($summary_expanded = $summary) =~ s{\$(\w+)} 232*0Sstevel@tonic-gate { my $c = $Config{$1}; defined($c) ? $c : 'undef' }ge; 233*0Sstevel@tonic-gate $summary_expanded; 234*0Sstevel@tonic-gate} 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gateour $Config_SH : unique = <<'!END!'; 237*0Sstevel@tonic-gateEOT 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gateprint CONFIG join("", @v_fast, sort @v_others); 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gateprint CONFIG "!END!\n", $fetch_string; 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gateprint CONFIG <<'ENDOFEND'; 244*0Sstevel@tonic-gate 245*0Sstevel@tonic-gatesub fetch_virtual { 246*0Sstevel@tonic-gate my($self, $key) = @_; 247*0Sstevel@tonic-gate 248*0Sstevel@tonic-gate my $value; 249*0Sstevel@tonic-gate 250*0Sstevel@tonic-gate if ($key =~ /^((?:cc|ld)flags|libs(?:wanted)?)_nolargefiles/) { 251*0Sstevel@tonic-gate # These are purely virtual, they do not exist, but need to 252*0Sstevel@tonic-gate # be computed on demand for largefile-incapable extensions. 253*0Sstevel@tonic-gate my $new_key = "${1}_uselargefiles"; 254*0Sstevel@tonic-gate $value = $Config{$1}; 255*0Sstevel@tonic-gate my $withlargefiles = $Config{$new_key}; 256*0Sstevel@tonic-gate if ($new_key =~ /^(?:cc|ld)flags_/) { 257*0Sstevel@tonic-gate $value =~ s/\Q$withlargefiles\E\b//; 258*0Sstevel@tonic-gate } elsif ($new_key =~ /^libs/) { 259*0Sstevel@tonic-gate my @lflibswanted = split(' ', $Config{libswanted_uselargefiles}); 260*0Sstevel@tonic-gate if (@lflibswanted) { 261*0Sstevel@tonic-gate my %lflibswanted; 262*0Sstevel@tonic-gate @lflibswanted{@lflibswanted} = (); 263*0Sstevel@tonic-gate if ($new_key =~ /^libs_/) { 264*0Sstevel@tonic-gate my @libs = grep { /^-l(.+)/ && 265*0Sstevel@tonic-gate not exists $lflibswanted{$1} } 266*0Sstevel@tonic-gate split(' ', $Config{libs}); 267*0Sstevel@tonic-gate $Config{libs} = join(' ', @libs); 268*0Sstevel@tonic-gate } elsif ($new_key =~ /^libswanted_/) { 269*0Sstevel@tonic-gate my @libswanted = grep { not exists $lflibswanted{$_} } 270*0Sstevel@tonic-gate split(' ', $Config{libswanted}); 271*0Sstevel@tonic-gate $Config{libswanted} = join(' ', @libswanted); 272*0Sstevel@tonic-gate } 273*0Sstevel@tonic-gate } 274*0Sstevel@tonic-gate } 275*0Sstevel@tonic-gate } 276*0Sstevel@tonic-gate 277*0Sstevel@tonic-gate $self->{$key} = $value; 278*0Sstevel@tonic-gate} 279*0Sstevel@tonic-gate 280*0Sstevel@tonic-gatesub FETCH { 281*0Sstevel@tonic-gate my($self, $key) = @_; 282*0Sstevel@tonic-gate 283*0Sstevel@tonic-gate # check for cached value (which may be undef so we use exists not defined) 284*0Sstevel@tonic-gate return $self->{$key} if exists $self->{$key}; 285*0Sstevel@tonic-gate 286*0Sstevel@tonic-gate $self->fetch_string($key); 287*0Sstevel@tonic-gate return $self->{$key} if exists $self->{$key}; 288*0Sstevel@tonic-gate $self->fetch_virtual($key); 289*0Sstevel@tonic-gate 290*0Sstevel@tonic-gate # Might not exist, in which undef is correct. 291*0Sstevel@tonic-gate return $self->{$key}; 292*0Sstevel@tonic-gate} 293*0Sstevel@tonic-gate 294*0Sstevel@tonic-gatemy $prevpos = 0; 295*0Sstevel@tonic-gate 296*0Sstevel@tonic-gatesub FIRSTKEY { 297*0Sstevel@tonic-gate $prevpos = 0; 298*0Sstevel@tonic-gate substr($Config_SH, 0, index($Config_SH, '=') ); 299*0Sstevel@tonic-gate} 300*0Sstevel@tonic-gate 301*0Sstevel@tonic-gatesub NEXTKEY { 302*0Sstevel@tonic-gate # Find out how the current key's quoted so we can skip to its end. 303*0Sstevel@tonic-gate my $quote = substr($Config_SH, index($Config_SH, "=", $prevpos)+1, 1); 304*0Sstevel@tonic-gate my $pos = index($Config_SH, qq($quote\n), $prevpos) + 2; 305*0Sstevel@tonic-gate my $len = index($Config_SH, "=", $pos) - $pos; 306*0Sstevel@tonic-gate $prevpos = $pos; 307*0Sstevel@tonic-gate $len > 0 ? substr($Config_SH, $pos, $len) : undef; 308*0Sstevel@tonic-gate} 309*0Sstevel@tonic-gate 310*0Sstevel@tonic-gatesub EXISTS { 311*0Sstevel@tonic-gate return 1 if exists($_[0]->{$_[1]}); 312*0Sstevel@tonic-gate 313*0Sstevel@tonic-gate return(index($Config_SH, "\n$_[1]='") != -1 or 314*0Sstevel@tonic-gate substr($Config_SH, 0, length($_[1])+2) eq "$_[1]='" or 315*0Sstevel@tonic-gate index($Config_SH, "\n$_[1]=\"") != -1 or 316*0Sstevel@tonic-gate substr($Config_SH, 0, length($_[1])+2) eq "$_[1]=\"" or 317*0Sstevel@tonic-gate $_[1] =~ /^(?:(?:cc|ld)flags|libs(?:wanted)?)_nolargefiles$/ 318*0Sstevel@tonic-gate ); 319*0Sstevel@tonic-gate} 320*0Sstevel@tonic-gate 321*0Sstevel@tonic-gatesub STORE { die "\%Config::Config is read-only\n" } 322*0Sstevel@tonic-gate*DELETE = \&STORE; 323*0Sstevel@tonic-gate*CLEAR = \&STORE; 324*0Sstevel@tonic-gate 325*0Sstevel@tonic-gate 326*0Sstevel@tonic-gatesub config_sh { 327*0Sstevel@tonic-gate $Config_SH 328*0Sstevel@tonic-gate} 329*0Sstevel@tonic-gate 330*0Sstevel@tonic-gatesub config_re { 331*0Sstevel@tonic-gate my $re = shift; 332*0Sstevel@tonic-gate return map { chomp; $_ } grep /^$re=/, split /^/, $Config_SH; 333*0Sstevel@tonic-gate} 334*0Sstevel@tonic-gate 335*0Sstevel@tonic-gatesub config_vars { 336*0Sstevel@tonic-gate foreach (@_) { 337*0Sstevel@tonic-gate if (/\W/) { 338*0Sstevel@tonic-gate my @matches = config_re($_); 339*0Sstevel@tonic-gate print map "$_\n", @matches ? @matches : "$_: not found"; 340*0Sstevel@tonic-gate } else { 341*0Sstevel@tonic-gate my $v = (exists $Config{$_}) ? $Config{$_} : 'UNKNOWN'; 342*0Sstevel@tonic-gate $v = 'undef' unless defined $v; 343*0Sstevel@tonic-gate print "$_='$v';\n"; 344*0Sstevel@tonic-gate } 345*0Sstevel@tonic-gate } 346*0Sstevel@tonic-gate} 347*0Sstevel@tonic-gate 348*0Sstevel@tonic-gateENDOFEND 349*0Sstevel@tonic-gate 350*0Sstevel@tonic-gateif ($^O eq 'os2') { 351*0Sstevel@tonic-gate print CONFIG <<'ENDOFSET'; 352*0Sstevel@tonic-gatemy %preconfig; 353*0Sstevel@tonic-gateif ($OS2::is_aout) { 354*0Sstevel@tonic-gate my ($value, $v) = $Config_SH =~ m/^used_aout='(.*)'\s*$/m; 355*0Sstevel@tonic-gate for (split ' ', $value) { 356*0Sstevel@tonic-gate ($v) = $Config_SH =~ m/^aout_$_='(.*)'\s*$/m; 357*0Sstevel@tonic-gate $preconfig{$_} = $v eq 'undef' ? undef : $v; 358*0Sstevel@tonic-gate } 359*0Sstevel@tonic-gate} 360*0Sstevel@tonic-gate$preconfig{d_fork} = undef unless $OS2::can_fork; # Some funny cases can't 361*0Sstevel@tonic-gatesub TIEHASH { bless {%preconfig} } 362*0Sstevel@tonic-gateENDOFSET 363*0Sstevel@tonic-gate # Extract the name of the DLL from the makefile to avoid duplication 364*0Sstevel@tonic-gate my ($f) = grep -r, qw(GNUMakefile Makefile); 365*0Sstevel@tonic-gate my $dll; 366*0Sstevel@tonic-gate if (open my $fh, '<', $f) { 367*0Sstevel@tonic-gate while (<$fh>) { 368*0Sstevel@tonic-gate $dll = $1, last if /^PERL_DLL_BASE\s*=\s*(\S*)\s*$/; 369*0Sstevel@tonic-gate } 370*0Sstevel@tonic-gate } 371*0Sstevel@tonic-gate print CONFIG <<ENDOFSET if $dll; 372*0Sstevel@tonic-gate\$preconfig{dll_name} = '$dll'; 373*0Sstevel@tonic-gateENDOFSET 374*0Sstevel@tonic-gate} else { 375*0Sstevel@tonic-gate print CONFIG <<'ENDOFSET'; 376*0Sstevel@tonic-gatesub TIEHASH { 377*0Sstevel@tonic-gate bless $_[1], $_[0]; 378*0Sstevel@tonic-gate} 379*0Sstevel@tonic-gateENDOFSET 380*0Sstevel@tonic-gate} 381*0Sstevel@tonic-gate 382*0Sstevel@tonic-gate 383*0Sstevel@tonic-gate# Calculation for the keys for byteorder 384*0Sstevel@tonic-gate# This is somewhat grim, but I need to run fetch_string here. 385*0Sstevel@tonic-gateour $Config_SH = join "\n", @v_fast, @v_others; 386*0Sstevel@tonic-gate 387*0Sstevel@tonic-gatemy $t = fetch_string ({}, 'ivtype'); 388*0Sstevel@tonic-gatemy $s = fetch_string ({}, 'ivsize'); 389*0Sstevel@tonic-gate 390*0Sstevel@tonic-gate# byteorder does exist on its own but we overlay a virtual 391*0Sstevel@tonic-gate# dynamically recomputed value. 392*0Sstevel@tonic-gate 393*0Sstevel@tonic-gate# However, ivtype and ivsize will not vary for sane fat binaries 394*0Sstevel@tonic-gate 395*0Sstevel@tonic-gatemy $f = $t eq 'long' ? 'L!' : $s == 8 ? 'Q': 'I'; 396*0Sstevel@tonic-gate 397*0Sstevel@tonic-gatemy $byteorder_code; 398*0Sstevel@tonic-gateif ($s == 4 || $s == 8) { 399*0Sstevel@tonic-gate my $list = join ',', reverse(2..$s); 400*0Sstevel@tonic-gate my $format = 'a'x$s; 401*0Sstevel@tonic-gate $byteorder_code = <<"EOT"; 402*0Sstevel@tonic-gatemy \$i = 0; 403*0Sstevel@tonic-gateforeach my \$c ($list) { \$i |= ord(\$c); \$i <<= 8 } 404*0Sstevel@tonic-gate\$i |= ord(1); 405*0Sstevel@tonic-gatemy \$value = join('', unpack('$format', pack('$f', \$i))); 406*0Sstevel@tonic-gateEOT 407*0Sstevel@tonic-gate} else { 408*0Sstevel@tonic-gate $byteorder_code = "\$value = '?'x$s;\n"; 409*0Sstevel@tonic-gate} 410*0Sstevel@tonic-gate 411*0Sstevel@tonic-gatemy $fast_config = join '', map { " $_,\n" } 412*0Sstevel@tonic-gate sort values (%v_fast), 'byteorder => $value' ; 413*0Sstevel@tonic-gate 414*0Sstevel@tonic-gateprint CONFIG sprintf <<'ENDOFTIE', $byteorder_code, $fast_config; 415*0Sstevel@tonic-gate 416*0Sstevel@tonic-gate# avoid Config..Exporter..UNIVERSAL search for DESTROY then AUTOLOAD 417*0Sstevel@tonic-gatesub DESTROY { } 418*0Sstevel@tonic-gate 419*0Sstevel@tonic-gate%s 420*0Sstevel@tonic-gate 421*0Sstevel@tonic-gatetie %%Config, 'Config', { 422*0Sstevel@tonic-gate%s 423*0Sstevel@tonic-gate}; 424*0Sstevel@tonic-gate 425*0Sstevel@tonic-gate1; 426*0Sstevel@tonic-gateENDOFTIE 427*0Sstevel@tonic-gate 428*0Sstevel@tonic-gate 429*0Sstevel@tonic-gateopen(CONFIG_POD, ">lib/Config.pod") or die "Can't open lib/Config.pod: $!"; 430*0Sstevel@tonic-gateprint CONFIG_POD <<'ENDOFTAIL'; 431*0Sstevel@tonic-gate=head1 NAME 432*0Sstevel@tonic-gate 433*0Sstevel@tonic-gateConfig - access Perl configuration information 434*0Sstevel@tonic-gate 435*0Sstevel@tonic-gate=head1 SYNOPSIS 436*0Sstevel@tonic-gate 437*0Sstevel@tonic-gate use Config; 438*0Sstevel@tonic-gate if ($Config{'cc'} =~ /gcc/) { 439*0Sstevel@tonic-gate print "built by gcc\n"; 440*0Sstevel@tonic-gate } 441*0Sstevel@tonic-gate 442*0Sstevel@tonic-gate use Config qw(myconfig config_sh config_vars config_re); 443*0Sstevel@tonic-gate 444*0Sstevel@tonic-gate print myconfig(); 445*0Sstevel@tonic-gate 446*0Sstevel@tonic-gate print config_sh(); 447*0Sstevel@tonic-gate 448*0Sstevel@tonic-gate print config_re(); 449*0Sstevel@tonic-gate 450*0Sstevel@tonic-gate config_vars(qw(osname archname)); 451*0Sstevel@tonic-gate 452*0Sstevel@tonic-gate 453*0Sstevel@tonic-gate=head1 DESCRIPTION 454*0Sstevel@tonic-gate 455*0Sstevel@tonic-gateThe Config module contains all the information that was available to 456*0Sstevel@tonic-gatethe C<Configure> program at Perl build time (over 900 values). 457*0Sstevel@tonic-gate 458*0Sstevel@tonic-gateShell variables from the F<config.sh> file (written by Configure) are 459*0Sstevel@tonic-gatestored in the readonly-variable C<%Config>, indexed by their names. 460*0Sstevel@tonic-gate 461*0Sstevel@tonic-gateValues stored in config.sh as 'undef' are returned as undefined 462*0Sstevel@tonic-gatevalues. The perl C<exists> function can be used to check if a 463*0Sstevel@tonic-gatenamed variable exists. 464*0Sstevel@tonic-gate 465*0Sstevel@tonic-gate=over 4 466*0Sstevel@tonic-gate 467*0Sstevel@tonic-gate=item myconfig() 468*0Sstevel@tonic-gate 469*0Sstevel@tonic-gateReturns a textual summary of the major perl configuration values. 470*0Sstevel@tonic-gateSee also C<-V> in L<perlrun/Switches>. 471*0Sstevel@tonic-gate 472*0Sstevel@tonic-gate=item config_sh() 473*0Sstevel@tonic-gate 474*0Sstevel@tonic-gateReturns the entire perl configuration information in the form of the 475*0Sstevel@tonic-gateoriginal config.sh shell variable assignment script. 476*0Sstevel@tonic-gate 477*0Sstevel@tonic-gate=item config_re($regex) 478*0Sstevel@tonic-gate 479*0Sstevel@tonic-gateLike config_sh() but returns, as a list, only the config entries who's 480*0Sstevel@tonic-gatenames match the $regex. 481*0Sstevel@tonic-gate 482*0Sstevel@tonic-gate=item config_vars(@names) 483*0Sstevel@tonic-gate 484*0Sstevel@tonic-gatePrints to STDOUT the values of the named configuration variable. Each is 485*0Sstevel@tonic-gateprinted on a separate line in the form: 486*0Sstevel@tonic-gate 487*0Sstevel@tonic-gate name='value'; 488*0Sstevel@tonic-gate 489*0Sstevel@tonic-gateNames which are unknown are output as C<name='UNKNOWN';>. 490*0Sstevel@tonic-gateSee also C<-V:name> in L<perlrun/Switches>. 491*0Sstevel@tonic-gate 492*0Sstevel@tonic-gate=back 493*0Sstevel@tonic-gate 494*0Sstevel@tonic-gate=head1 EXAMPLE 495*0Sstevel@tonic-gate 496*0Sstevel@tonic-gateHere's a more sophisticated example of using %Config: 497*0Sstevel@tonic-gate 498*0Sstevel@tonic-gate use Config; 499*0Sstevel@tonic-gate use strict; 500*0Sstevel@tonic-gate 501*0Sstevel@tonic-gate my %sig_num; 502*0Sstevel@tonic-gate my @sig_name; 503*0Sstevel@tonic-gate unless($Config{sig_name} && $Config{sig_num}) { 504*0Sstevel@tonic-gate die "No sigs?"; 505*0Sstevel@tonic-gate } else { 506*0Sstevel@tonic-gate my @names = split ' ', $Config{sig_name}; 507*0Sstevel@tonic-gate @sig_num{@names} = split ' ', $Config{sig_num}; 508*0Sstevel@tonic-gate foreach (@names) { 509*0Sstevel@tonic-gate $sig_name[$sig_num{$_}] ||= $_; 510*0Sstevel@tonic-gate } 511*0Sstevel@tonic-gate } 512*0Sstevel@tonic-gate 513*0Sstevel@tonic-gate print "signal #17 = $sig_name[17]\n"; 514*0Sstevel@tonic-gate if ($sig_num{ALRM}) { 515*0Sstevel@tonic-gate print "SIGALRM is $sig_num{ALRM}\n"; 516*0Sstevel@tonic-gate } 517*0Sstevel@tonic-gate 518*0Sstevel@tonic-gate=head1 WARNING 519*0Sstevel@tonic-gate 520*0Sstevel@tonic-gateBecause this information is not stored within the perl executable 521*0Sstevel@tonic-gateitself it is possible (but unlikely) that the information does not 522*0Sstevel@tonic-gaterelate to the actual perl binary which is being used to access it. 523*0Sstevel@tonic-gate 524*0Sstevel@tonic-gateThe Config module is installed into the architecture and version 525*0Sstevel@tonic-gatespecific library directory ($Config{installarchlib}) and it checks the 526*0Sstevel@tonic-gateperl version number when loaded. 527*0Sstevel@tonic-gate 528*0Sstevel@tonic-gateThe values stored in config.sh may be either single-quoted or 529*0Sstevel@tonic-gatedouble-quoted. Double-quoted strings are handy for those cases where you 530*0Sstevel@tonic-gateneed to include escape sequences in the strings. To avoid runtime variable 531*0Sstevel@tonic-gateinterpolation, any C<$> and C<@> characters are replaced by C<\$> and 532*0Sstevel@tonic-gateC<\@>, respectively. This isn't foolproof, of course, so don't embed C<\$> 533*0Sstevel@tonic-gateor C<\@> in double-quoted strings unless you're willing to deal with the 534*0Sstevel@tonic-gateconsequences. (The slashes will end up escaped and the C<$> or C<@> will 535*0Sstevel@tonic-gatetrigger variable interpolation) 536*0Sstevel@tonic-gate 537*0Sstevel@tonic-gate=head1 GLOSSARY 538*0Sstevel@tonic-gate 539*0Sstevel@tonic-gateMost C<Config> variables are determined by the C<Configure> script 540*0Sstevel@tonic-gateon platforms supported by it (which is most UNIX platforms). Some 541*0Sstevel@tonic-gateplatforms have custom-made C<Config> variables, and may thus not have 542*0Sstevel@tonic-gatesome of the variables described below, or may have extraneous variables 543*0Sstevel@tonic-gatespecific to that particular port. See the port specific documentation 544*0Sstevel@tonic-gatein such cases. 545*0Sstevel@tonic-gate 546*0Sstevel@tonic-gateENDOFTAIL 547*0Sstevel@tonic-gate 548*0Sstevel@tonic-gateif ($Opts{glossary}) { 549*0Sstevel@tonic-gate open(GLOS, "<$Glossary") or die "Can't open $Glossary: $!"; 550*0Sstevel@tonic-gate} 551*0Sstevel@tonic-gate%seen = (); 552*0Sstevel@tonic-gate$text = 0; 553*0Sstevel@tonic-gate$/ = ''; 554*0Sstevel@tonic-gate 555*0Sstevel@tonic-gatesub process { 556*0Sstevel@tonic-gate if (s/\A(\w*)\s+\(([\w.]+)\):\s*\n(\t?)/=item C<$1>\n\nFrom F<$2>:\n\n/m) { 557*0Sstevel@tonic-gate my $c = substr $1, 0, 1; 558*0Sstevel@tonic-gate unless ($seen{$c}++) { 559*0Sstevel@tonic-gate print CONFIG_POD <<EOF if $text; 560*0Sstevel@tonic-gate=back 561*0Sstevel@tonic-gate 562*0Sstevel@tonic-gateEOF 563*0Sstevel@tonic-gate print CONFIG_POD <<EOF; 564*0Sstevel@tonic-gate=head2 $c 565*0Sstevel@tonic-gate 566*0Sstevel@tonic-gate=over 4 567*0Sstevel@tonic-gate 568*0Sstevel@tonic-gateEOF 569*0Sstevel@tonic-gate $text = 1; 570*0Sstevel@tonic-gate } 571*0Sstevel@tonic-gate } 572*0Sstevel@tonic-gate elsif (!$text || !/\A\t/) { 573*0Sstevel@tonic-gate warn "Expected a Configure variable header", 574*0Sstevel@tonic-gate ($text ? " or another paragraph of description" : () ); 575*0Sstevel@tonic-gate } 576*0Sstevel@tonic-gate s/n't/n\00t/g; # leave can't, won't etc untouched 577*0Sstevel@tonic-gate s/^\t\s+(.*)/\n$1/gm; # Indented lines ===> new paragraph 578*0Sstevel@tonic-gate s/^(?<!\n\n)\t(.*)/$1/gm; # Not indented lines ===> text 579*0Sstevel@tonic-gate s{([\'\"])(?=[^\'\"\s]*[./][^\'\"\s]*\1)([^\'\"\s]+)\1}(F<$2>)g; # '.o' 580*0Sstevel@tonic-gate s{([\'\"])([^\'\"\s]+)\1}(C<$2>)g; # "date" command 581*0Sstevel@tonic-gate s{\'([A-Za-z_\- *=/]+)\'}(C<$1>)g; # 'ln -s' 582*0Sstevel@tonic-gate s{ 583*0Sstevel@tonic-gate (?<! [\w./<\'\"] ) # Only standalone file names 584*0Sstevel@tonic-gate (?! e \. g \. ) # Not e.g. 585*0Sstevel@tonic-gate (?! \. \. \. ) # Not ... 586*0Sstevel@tonic-gate (?! \d ) # Not 5.004 587*0Sstevel@tonic-gate (?! read/ ) # Not read/write 588*0Sstevel@tonic-gate (?! etc\. ) # Not etc. 589*0Sstevel@tonic-gate (?! I/O ) # Not I/O 590*0Sstevel@tonic-gate ( 591*0Sstevel@tonic-gate \$ ? # Allow leading $ 592*0Sstevel@tonic-gate [\w./]* [./] [\w./]* # Require . or / inside 593*0Sstevel@tonic-gate ) 594*0Sstevel@tonic-gate (?<! \. (?= [\s)] ) ) # Do not include trailing dot 595*0Sstevel@tonic-gate (?! [\w/] ) # Include all of it 596*0Sstevel@tonic-gate } 597*0Sstevel@tonic-gate (F<$1>)xg; # /usr/local 598*0Sstevel@tonic-gate s/((?<=\s)~\w*)/F<$1>/g; # ~name 599*0Sstevel@tonic-gate s/(?<![.<\'\"])\b([A-Z_]{2,})\b(?![\'\"])/C<$1>/g; # UNISTD 600*0Sstevel@tonic-gate s/(?<![.<\'\"])\b(?!the\b)(\w+)\s+macro\b/C<$1> macro/g; # FILE_cnt macro 601*0Sstevel@tonic-gate s/n[\0]t/n't/g; # undo can't, won't damage 602*0Sstevel@tonic-gate} 603*0Sstevel@tonic-gate 604*0Sstevel@tonic-gateif ($Opts{glossary}) { 605*0Sstevel@tonic-gate <GLOS>; # Skip the "DO NOT EDIT" 606*0Sstevel@tonic-gate <GLOS>; # Skip the preamble 607*0Sstevel@tonic-gate while (<GLOS>) { 608*0Sstevel@tonic-gate process; 609*0Sstevel@tonic-gate print CONFIG_POD; 610*0Sstevel@tonic-gate } 611*0Sstevel@tonic-gate} 612*0Sstevel@tonic-gate 613*0Sstevel@tonic-gateprint CONFIG_POD <<'ENDOFTAIL'; 614*0Sstevel@tonic-gate 615*0Sstevel@tonic-gate=back 616*0Sstevel@tonic-gate 617*0Sstevel@tonic-gate=head1 NOTE 618*0Sstevel@tonic-gate 619*0Sstevel@tonic-gateThis module contains a good example of how to use tie to implement a 620*0Sstevel@tonic-gatecache and an example of how to make a tied variable readonly to those 621*0Sstevel@tonic-gateoutside of it. 622*0Sstevel@tonic-gate 623*0Sstevel@tonic-gate=cut 624*0Sstevel@tonic-gate 625*0Sstevel@tonic-gateENDOFTAIL 626*0Sstevel@tonic-gate 627*0Sstevel@tonic-gateclose(CONFIG); 628*0Sstevel@tonic-gateclose(GLOS); 629*0Sstevel@tonic-gateclose(CONFIG_POD); 630*0Sstevel@tonic-gate 631*0Sstevel@tonic-gate# Now create Cross.pm if needed 632*0Sstevel@tonic-gateif ($Opts{cross}) { 633*0Sstevel@tonic-gate open CROSS, ">lib/Cross.pm" or die "Can not open >lib/Cross.pm: $!"; 634*0Sstevel@tonic-gate my $cross = <<'EOS'; 635*0Sstevel@tonic-gate# typical invocation: 636*0Sstevel@tonic-gate# perl -MCross Makefile.PL 637*0Sstevel@tonic-gate# perl -MCross=wince -V:cc 638*0Sstevel@tonic-gatepackage Cross; 639*0Sstevel@tonic-gate 640*0Sstevel@tonic-gatesub import { 641*0Sstevel@tonic-gate my ($package,$platform) = @_; 642*0Sstevel@tonic-gate unless (defined $platform) { 643*0Sstevel@tonic-gate # if $platform is not specified, then use last one when 644*0Sstevel@tonic-gate # 'configpm; was invoked with --cross option 645*0Sstevel@tonic-gate $platform = '***replace-marker***'; 646*0Sstevel@tonic-gate } 647*0Sstevel@tonic-gate @INC = map {/\blib\b/?(do{local $_=$_;s/\blib\b/xlib\/$platform/;$_},$_):($_)} @INC; 648*0Sstevel@tonic-gate $::Cross::platform = $platform; 649*0Sstevel@tonic-gate} 650*0Sstevel@tonic-gate 651*0Sstevel@tonic-gate1; 652*0Sstevel@tonic-gateEOS 653*0Sstevel@tonic-gate $cross =~ s/\*\*\*replace-marker\*\*\*/$Opts{cross}/g; 654*0Sstevel@tonic-gate print CROSS $cross; 655*0Sstevel@tonic-gate close CROSS; 656*0Sstevel@tonic-gate} 657*0Sstevel@tonic-gate 658*0Sstevel@tonic-gate# Now do some simple tests on the Config.pm file we have created 659*0Sstevel@tonic-gateunshift(@INC,'lib'); 660*0Sstevel@tonic-gaterequire $Config_PM; 661*0Sstevel@tonic-gateimport Config; 662*0Sstevel@tonic-gate 663*0Sstevel@tonic-gatedie "$0: $Config_PM not valid" 664*0Sstevel@tonic-gate unless $Config{'PERL_CONFIG_SH'} eq 'true'; 665*0Sstevel@tonic-gate 666*0Sstevel@tonic-gatedie "$0: error processing $Config_PM" 667*0Sstevel@tonic-gate if defined($Config{'an impossible name'}) 668*0Sstevel@tonic-gate or $Config{'PERL_CONFIG_SH'} ne 'true' # test cache 669*0Sstevel@tonic-gate ; 670*0Sstevel@tonic-gate 671*0Sstevel@tonic-gatedie "$0: error processing $Config_PM" 672*0Sstevel@tonic-gate if eval '$Config{"cc"} = 1' 673*0Sstevel@tonic-gate or eval 'delete $Config{"cc"}' 674*0Sstevel@tonic-gate ; 675*0Sstevel@tonic-gate 676*0Sstevel@tonic-gate 677*0Sstevel@tonic-gateexit 0; 678