+ $self->{$key} = $value eq 'undef' ? undef : $value; # cache it
+}
+EOT
+
+} else {
+ # We only have ' delimted.
+
+$fetch_string .= <<'EOT';
+ return undef unless $Config_SH_expanded =~ /\n$key=\'(.*?)\'\n/s;
+ # So we can say "if $Config{'foo'}".
+ $self->{$key} = $1 eq 'undef' ? undef : $1;
+}
+EOT
+
+}
+
+eval $fetch_string;
+die if $@;
+
+# 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_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);
+our \$byteorder = join('', unpack('$format', pack('$f', \$i)));
+EOT
+} else {
+ $byteorder_code = "our \$byteorder = '?'x$s;\n";
+}
+
+my @need_relocation;
+
+if (fetch_string({},'userelocatableinc')) {
+ foreach my $what (qw(prefixexp
+
+ archlibexp
+ html1direxp
+ html3direxp
+ man1direxp
+ man3direxp
+ privlibexp
+ scriptdirexp
+ sitearchexp
+ sitebinexp
+ sitehtml1direxp
+ sitehtml3direxp
+ sitelibexp
+ siteman1direxp
+ siteman3direxp
+ sitescriptexp
+ vendorarchexp
+ vendorbinexp
+ vendorhtml1direxp
+ vendorhtml3direxp
+ vendorlibexp
+ vendorman1direxp
+ vendorman3direxp
+ vendorscriptexp
+
+ siteprefixexp
+ sitelib_stem
+ vendorlib_stem
+
+ installarchlib
+ installhtml1dir
+ installhtml3dir
+ installman1dir
+ installman3dir
+ installprefix
+ installprefixexp
+ installprivlib
+ installscript
+ installsitearch
+ installsitebin
+ installsitehtml1dir
+ installsitehtml3dir
+ installsitelib
+ installsiteman1dir
+ installsiteman3dir
+ installsitescript
+ installvendorarch
+ installvendorbin
+ installvendorhtml1dir
+ installvendorhtml3dir
+ installvendorlib
+ installvendorman1dir
+ installvendorman3dir
+ installvendorscript
+ )) {
+ push @need_relocation, $what if fetch_string({}, $what) =~ m!^\.\.\./!;
+ }
+}
+
+my %need_relocation;
+@need_relocation{@need_relocation} = @need_relocation;
+
+# This can have .../ anywhere:
+if (fetch_string({}, 'otherlibdirs') =~ m!\.\.\./!) {
+ $need_relocation{otherlibdirs} = 'otherlibdirs';
+}
+
+my $relocation_code = <<'EOT';
+
+sub relocate_inc {
+ my $libdir = shift;
+ return $libdir unless $libdir =~ s!^\.\.\./!!;
+ my $prefix = $^X;
+ if ($prefix =~ s!/[^/]*$!!) {
+ while ($libdir =~ m!^\.\./!) {
+ # Loop while $libdir starts "../" and $prefix still has a trailing
+ # directory
+ last unless $prefix =~ s!/([^/]+)$!!;
+ # but bail out if the directory we picked off the end of $prefix is .
+ # or ..
+ if ($1 eq '.' or $1 eq '..') {
+ # Undo! This should be rare, hence code it this way rather than a
+ # check each time before the s!!! above.
+ $prefix = "$prefix/$1";
+ last;
+ }
+ # Remove that leading ../ and loop again
+ substr ($libdir, 0, 3, '');
+ }
+ $libdir = "$prefix/$libdir";
+ }
+ $libdir;
+}
+EOT
+
+if (%need_relocation) {
+ my $relocations_in_common;
+ # otherlibdirs only features in the hash
+ foreach (keys %need_relocation) {
+ $relocations_in_common++ if $Common{$_};
+ }
+ if ($relocations_in_common) {
+ $config_txt .= $relocation_code;
+ } else {
+ $heavy_txt .= $relocation_code;
+ }
+}
+
+$heavy_txt .= join('', @non_v) . "\n";
+
+# copy config summary format from the myconfig.SH script
+$heavy_txt .= "our \$summary = <<'!END!';\n";
+open(MYCONFIG,"<myconfig.SH") || die "open myconfig.SH failed: $!";
+1 while defined($_ = <MYCONFIG>) && !/^Summary of/;
+do { $heavy_txt .= $_ } until !defined($_ = <MYCONFIG>) || /^\s*$/;
+close(MYCONFIG);
+
+$heavy_txt .= "\n!END!\n" . <<'EOT';
+my $summary_expanded;
+
+sub myconfig {
+ return $summary_expanded if $summary_expanded;
+ ($summary_expanded = $summary) =~ s{\$(\w+)}
+ {
+ my $c;
+ if ($1 eq 'git_ancestor_line') {
+ if ($Config::Config{git_ancestor}) {
+ $c= "\n Ancestor: $Config::Config{git_ancestor}";
+ } else {
+ $c= "";
+ }
+ } else {
+ $c = $Config::Config{$1};
+ }
+ defined($c) ? $c : 'undef'
+ }ge;
+ $summary_expanded;
+}
+
+local *_ = \my $a;
+$_ = <<'!END!';
+EOT
+
+$heavy_txt .= join('', sort @v_others) . "!END!\n";
+
+# Only need the dynamic byteorder code in Config.pm if 'byteorder' is one of
+# the precached keys
+if ($Common{byteorder}) {
+ $config_txt .= $byteorder_code;
+} else {
+ $heavy_txt .= $byteorder_code;
+}
+
+if (@need_relocation) {
+$heavy_txt .= 'foreach my $what (qw(' . join (' ', @need_relocation) .
+ ")) {\n" . <<'EOT';
+ s/^($what=)(['"])(.*?)\2/$1 . $2 . relocate_inc($3) . $2/me;
+}
+EOT
+# Currently it only makes sense to do the ... relocation on Unix, so there's
+# no need to emulate the "which separator for this platform" logic in perl.c -
+# ':' will always be applicable
+if ($need_relocation{otherlibdirs}) {
+$heavy_txt .= << 'EOT';
+s{^(otherlibdirs=)(['"])(.*?)\2}
+ {$1 . $2 . join ':', map {relocate_inc($_)} split ':', $3 . $2}me;
+EOT