my $marker = "$key=";
# Check for the common case, ' delimited
- my $start = index($Config_SH, "\n$marker$quote_type");
+ my $start = index($Config_SH_expanded, "\n$marker$quote_type");
# If that failed, check for " delimited
if ($start == -1) {
$quote_type = '"';
- $start = index($Config_SH, "\n$marker$quote_type");
- }
- return undef if ( ($start == -1) && # in case it's first
- (substr($Config_SH, 0, length($marker)) ne $marker) );
- if ($start == -1) {
- # It's the very first thing we found. Skip $start forward
- # and figure out the quote mark after the =.
- $start = length($marker) + 1;
- $quote_type = substr($Config_SH, $start - 1, 1);
- }
- else {
- $start += length($marker) + 2;
+ $start = index($Config_SH_expanded, "\n$marker$quote_type");
}
+ # Start can never be -1 now, as we've rigged the long string we're
+ # searching with an initial dummy newline.
+ return undef if $start == -1;
- my $value = substr($Config_SH, $start,
- index($Config_SH, "$quote_type\n", $start) - $start);
+ $start += length($marker) + 2;
+
+ my $value = substr($Config_SH_expanded, $start,
+ index($Config_SH_expanded, "$quote_type\n", $start)
+ - $start);
# If we had a double-quote, we'd better eval it so escape
# sequences and such can be interpolated. Since the incoming
}
close CONFIG_SH;
+# Calculation for the keys for byteorder
+# This is somewhat grim, but I need to run fetch_string here.
+our $Config_SH_expanded = join "\n", '', @v_fast, @v_others;
+
+my $t = fetch_string ({}, 'ivtype');
+my $s = fetch_string ({}, 'ivsize');
+
+# byteorder does exist on its own but we overlay a virtual
+# dynamically recomputed value.
+
+# However, ivtype and ivsize will not vary for sane fat binaries
+
+my $f = $t eq 'long' ? 'L!' : $s == 8 ? 'Q': 'I';
+
+my $byteorder_code;
+if ($s == 4 || $s == 8) {
+ my $list = join ',', reverse(2..$s);
+ my $format = 'a'x$s;
+ $byteorder_code = <<"EOT";
+my \$i = 0;
+foreach my \$c ($list) { \$i |= ord(\$c); \$i <<= 8 }
+\$i |= ord(1);
+my \$byteorder = join('', unpack('$format', pack('$f', \$i)));
+EOT
+} else {
+ $byteorder_code = "my \$byteorder = '?'x$s;\n";
+}
+
print CONFIG @non_v, "\n";
# copy config summary format from the myconfig.SH script
do { print CONFIG $_ } until !defined($_ = <MYCONFIG>) || /^\s*$/;
close(MYCONFIG);
-print CONFIG "\n!END!\n", <<'EOT';
-my $summary_expanded = 0;
+# NB. as $summary is unique, we need to copy it in a lexical variable
+# before expanding it, because may have been made readonly if a perl
+# interpreter has been cloned.
+
+print CONFIG "\n!END!\n", $byteorder_code, <<'EOT';
+my $summary_expanded;
sub myconfig {
- return $summary if $summary_expanded;
- $summary =~ s{\$(\w+)}
+ return $summary_expanded if $summary_expanded;
+ ($summary_expanded = $summary) =~ s{\$(\w+)}
{ my $c = $Config{$1}; defined($c) ? $c : 'undef' }ge;
- $summary_expanded = 1;
- $summary;
+ $summary_expanded;
}
-our $Config_SH : unique = <<'!END!';
+local *_ = \my $a;
+$_ = <<'!END!';
EOT
print CONFIG join("", @v_fast, sort @v_others);
-print CONFIG "!END!\n", $fetch_string;
+print CONFIG <<'EOT';
+!END!
+s/(byteorder=)(['"]).*?\2/$1$2$byteorder$2/m;
+our $Config_SH : unique = $_;
-print CONFIG <<'ENDOFEND';
+our $Config_SH_expanded : unique = "\n$_" . << 'EOVIRTUAL';
+EOT
-sub fetch_virtual {
- my($self, $key) = @_;
+foreach my $prefix (qw(ccflags ldflags)) {
+ my $value = fetch_string ({}, $prefix);
+ my $withlargefiles = fetch_string ({}, $prefix . "_uselargefiles");
+ $value =~ s/\Q$withlargefiles\E\b//;
+ print CONFIG "${prefix}_nolargefiles='$value'\n";
+}
- my $value;
-
- if ($key =~ /^((?:cc|ld)flags|libs(?:wanted)?)_nolargefiles/) {
- # These are purely virtual, they do not exist, but need to
- # be computed on demand for largefile-incapable extensions.
- my $new_key = "${1}_uselargefiles";
- $value = $Config{$1};
- my $withlargefiles = $Config{$new_key};
- if ($new_key =~ /^(?:cc|ld)flags_/) {
- $value =~ s/\Q$withlargefiles\E\b//;
- } elsif ($new_key =~ /^libs/) {
- my @lflibswanted = split(' ', $Config{libswanted_uselargefiles});
- if (@lflibswanted) {
- my %lflibswanted;
- @lflibswanted{@lflibswanted} = ();
- if ($new_key =~ /^libs_/) {
- my @libs = grep { /^-l(.+)/ &&
- not exists $lflibswanted{$1} }
- split(' ', $Config{libs});
- $Config{libs} = join(' ', @libs);
- } elsif ($new_key =~ /^libswanted_/) {
- my @libswanted = grep { not exists $lflibswanted{$_} }
- split(' ', $Config{libswanted});
- $Config{libswanted} = join(' ', @libswanted);
- }
- }
+foreach my $prefix (qw(libs libswanted)) {
+ my $value = fetch_string ({}, $prefix);
+ my @lflibswanted
+ = split(' ', fetch_string ({}, 'libswanted_uselargefiles'));
+ if (@lflibswanted) {
+ my %lflibswanted;
+ @lflibswanted{@lflibswanted} = ();
+ if ($prefix eq 'libs') {
+ my @libs = grep { /^-l(.+)/ &&
+ not exists $lflibswanted{$1} }
+ split(' ', fetch_string ({}, 'libs'));
+ $value = join(' ', @libs);
+ } else {
+ my @libswanted = grep { not exists $lflibswanted{$_} }
+ split(' ', fetch_string ({}, 'libswanted'));
+ $value = join(' ', @libswanted);
}
}
-
- $self->{$key} = $value;
+ print CONFIG "${prefix}_nolargefiles='$value'\n";
}
+print CONFIG "EOVIRTUAL\n";
+
+print CONFIG $fetch_string;
+
+print CONFIG <<'ENDOFEND';
+
sub FETCH {
my($self, $key) = @_;
# check for cached value (which may be undef so we use exists not defined)
return $self->{$key} if exists $self->{$key};
- $self->fetch_string($key);
- return $self->{$key} if exists $self->{$key};
- $self->fetch_virtual($key);
-
- # Might not exist, in which undef is correct.
- return $self->{$key};
+ return $self->fetch_string($key);
}
my $prevpos = 0;
sub FIRSTKEY {
$prevpos = 0;
- substr($Config_SH, 0, index($Config_SH, '=') );
+ substr($Config_SH_expanded, 0, index($Config_SH_expanded, '=') );
}
sub NEXTKEY {
# Find out how the current key's quoted so we can skip to its end.
- my $quote = substr($Config_SH, index($Config_SH, "=", $prevpos)+1, 1);
- my $pos = index($Config_SH, qq($quote\n), $prevpos) + 2;
- my $len = index($Config_SH, "=", $pos) - $pos;
+ my $quote = substr($Config_SH_expanded,
+ index($Config_SH_expanded, "=", $prevpos)+1, 1);
+ my $pos = index($Config_SH_expanded, qq($quote\n), $prevpos) + 2;
+ my $len = index($Config_SH_expanded, "=", $pos) - $pos;
$prevpos = $pos;
- $len > 0 ? substr($Config_SH, $pos, $len) : undef;
+ $len > 0 ? substr($Config_SH_expanded, $pos, $len) : undef;
}
sub EXISTS {
return 1 if exists($_[0]->{$_[1]});
- return(index($Config_SH, "\n$_[1]='") != -1 or
- substr($Config_SH, 0, length($_[1])+2) eq "$_[1]='" or
- index($Config_SH, "\n$_[1]=\"") != -1 or
- substr($Config_SH, 0, length($_[1])+2) eq "$_[1]=\"" or
+ return(index($Config_SH_expanded, "\n$_[1]='") != -1 or
+ substr($Config_SH_expanded, 0, length($_[1])+2) eq "$_[1]='" or
+ index($Config_SH_expanded, "\n$_[1]=\"") != -1 or
+ substr($Config_SH_expanded, 0, length($_[1])+2) eq "$_[1]=\"" or
$_[1] =~ /^(?:(?:cc|ld)flags|libs(?:wanted)?)_nolargefiles$/
);
}
sub config_re {
my $re = shift;
- return map { chomp; $_ } grep /^$re=/, split /^/, $Config_SH;
+ return map { chomp; $_ } grep eval{ /^(?:$re)=/ }, split /^/,
+ $Config_SH_expanded;
}
sub config_vars {
+ # implements -V:cfgvar option (see perlrun -V:)
foreach (@_) {
- if (/\W/) {
- my @matches = config_re($_);
- print map "$_\n", @matches ? @matches : "$_: not found";
+ # find optional leading, trailing colons; and query-spec
+ my ($notag,$qry,$lncont) = m/^(:)?(.*?)(:)?$/; # flags fore and aft,
+ # map colon-flags to print decorations
+ my $prfx = $notag ? '': "$qry="; # tag-prefix for print
+ my $lnend = $lncont ? ' ' : ";\n"; # line ending for print
+
+ # all config-vars are by definition \w only, any \W means regex
+ if ($qry =~ /\W/) {
+ my @matches = config_re($qry);
+ print map "$_$lnend", @matches ? @matches : "$qry: not found" if !$notag;
+ print map { s/\w+=//; "$_$lnend" } @matches ? @matches : "$qry: not found" if $notag;
} else {
- my $v = (exists $Config{$_}) ? $Config{$_} : 'UNKNOWN';
+ my $v = (exists $Config{$qry}) ? $Config{$qry} : 'UNKNOWN';
$v = 'undef' unless defined $v;
- print "$_='$v';\n";
+ print "${prfx}'${v}'$lnend";
}
}
}
print CONFIG <<'ENDOFSET';
my %preconfig;
if ($OS2::is_aout) {
- my ($value, $v) = $Config_SH =~ m/^used_aout='(.*)'\s*$/m;
+ my ($value, $v) = $Config_SH_expanded =~ m/^used_aout='(.*)'\s*$/m;
for (split ' ', $value) {
- ($v) = $Config_SH =~ m/^aout_$_='(.*)'\s*$/m;
+ ($v) = $Config_SH_expanded =~ m/^aout_$_='(.*)'\s*$/m;
$preconfig{$_} = $v eq 'undef' ? undef : $v;
}
}
ENDOFSET
}
-
-# Calculation for the keys for byteorder
-# This is somewhat grim, but I need to run fetch_string here.
-our $Config_SH = join "\n", @v_fast, @v_others;
-
-my $t = fetch_string ({}, 'ivtype');
-my $s = fetch_string ({}, 'ivsize');
-
-# byteorder does exist on its own but we overlay a virtual
-# dynamically recomputed value.
-
-# However, ivtype and ivsize will not vary for sane fat binaries
-
-my $f = $t eq 'long' ? 'L!' : $s == 8 ? 'Q': 'I';
-
-my $byteorder_code;
-if ($s == 4 || $s == 8) {
- my $list = join ',', reverse(2..$s);
- my $format = 'a'x$s;
- $byteorder_code = <<"EOT";
-my \$i = 0;
-foreach my \$c ($list) { \$i |= ord(\$c); \$i <<= 8 }
-\$i |= ord(1);
-my \$value = join('', unpack('$format', pack('$f', \$i)));
-EOT
-} else {
- $byteorder_code = "\$value = '?'x$s;\n";
-}
-
my $fast_config = join '', map { " $_,\n" }
- sort values (%v_fast), 'byteorder => $value' ;
+ sort values (%v_fast), 'byteorder => $byteorder' ;
-print CONFIG sprintf <<'ENDOFTIE', $byteorder_code, $fast_config;
+print CONFIG sprintf <<'ENDOFTIE', $fast_config;
# avoid Config..Exporter..UNIVERSAL search for DESTROY then AUTOLOAD
sub DESTROY { }
-%s
-
tie %%Config, 'Config', {
%s
};
=head1 SYNOPSIS
use Config;
- if ($Config{'cc'} =~ /gcc/) {
- print "built by gcc\n";
+ if ($Config{usethreads}) {
+ print "has thread support\n"
}
use Config qw(myconfig config_sh config_vars config_re);