sub apply_patch {
my $patch = shift;
- my ($file) = $patch =~ qr!^diff.*a/(\S+) b/\1!;
+ my ($file) = $patch =~ qr!^--- a/(\S+)\n\+\+\+ b/\1!sm;
open my $fh, '|-', 'patch', '-p1' or die "Can't run patch: $!";
print $fh $patch;
return if close $fh;
die "Can't apply revert $commit";
}
+sub checkout_file {
+ my ($file, $commit) = @_;
+ $commit ||= 'blead';
+ system "git show $commit:$file > $file </dev/null"
+ and die "Could not extract $file at revision $commit";
+}
+
sub clean {
if ($options{clean}) {
# Needed, because files that are build products in this checked out
}
}
+if ($major < 6 && !extract_from_file('Configure',
+ qr!^\t-A\)$!)) {
+ # This adds the -A option to Configure, which is incredibly useful
+ # Effectively this is commits 02e93a22d20fc9a5, 5f83a3e9d818c3ad,
+ # bde6b06b2c493fef, f7c3111703e46e0c and 2 lines of trailing whitespace
+ # removed by 613d6c3e99b9decc, but applied at slightly different locations
+ # to ensure a clean patch back to 5.000
+ # Note, if considering patching to the intermediate revisions to fix bugs
+ # in -A handling, f7c3111703e46e0c is from 2002, and hence $major == 8
+
+ # To add to the fun, early patches add -K and -O options, and it's not
+ # trivial to get patch to put the C<. ./posthint.sh> in the right place
+ edit_file('Configure', sub {
+ my $code = shift;
+ $code =~ s/(optstr = ")([^"]+";\s*# getopt-style specification)/$1A:$2/
+ or die "Substitution failed";
+ $code =~ s!^(: who configured the system)!
+touch posthint.sh
+. ./posthint.sh
+
+$1!ms
+ or die "Substitution failed";
+ return $code;
+ });
+ apply_patch(<<'EOPATCH');
+diff --git a/Configure b/Configure
+index 4b55fa6..60c3c64 100755
+--- a/Configure
++++ b/Configure
+@@ -1150,6 +1150,7 @@ set X `for arg in "$@"; do echo "X$arg"; done |
+ eval "set $*"
+ shift
+ rm -f options.awk
++rm -f posthint.sh
+
+ : set up default values
+ fastread=''
+@@ -1172,6 +1173,56 @@ while test $# -gt 0; do
+ case "$1" in
+ -d) shift; fastread=yes;;
+ -e) shift; alldone=cont;;
++ -A)
++ shift
++ xxx=''
++ yyy="$1"
++ zzz=''
++ uuu=undef
++ case "$yyy" in
++ *=*) zzz=`echo "$yyy"|sed 's!=.*!!'`
++ case "$zzz" in
++ *:*) zzz='' ;;
++ *) xxx=append
++ zzz=" "`echo "$yyy"|sed 's!^[^=]*=!!'`
++ yyy=`echo "$yyy"|sed 's!=.*!!'` ;;
++ esac
++ ;;
++ esac
++ case "$xxx" in
++ '') case "$yyy" in
++ *:*) xxx=`echo "$yyy"|sed 's!:.*!!'`
++ yyy=`echo "$yyy"|sed 's!^[^:]*:!!'`
++ zzz=`echo "$yyy"|sed 's!^[^=]*=!!'`
++ yyy=`echo "$yyy"|sed 's!=.*!!'` ;;
++ *) xxx=`echo "$yyy"|sed 's!:.*!!'`
++ yyy=`echo "$yyy"|sed 's!^[^:]*:!!'` ;;
++ esac
++ ;;
++ esac
++ case "$xxx" in
++ append)
++ echo "$yyy=\"\${$yyy}$zzz\"" >> posthint.sh ;;
++ clear)
++ echo "$yyy=''" >> posthint.sh ;;
++ define)
++ case "$zzz" in
++ '') zzz=define ;;
++ esac
++ echo "$yyy='$zzz'" >> posthint.sh ;;
++ eval)
++ echo "eval \"$yyy=$zzz\"" >> posthint.sh ;;
++ prepend)
++ echo "$yyy=\"$zzz\${$yyy}\"" >> posthint.sh ;;
++ undef)
++ case "$zzz" in
++ '') zzz="$uuu" ;;
++ esac
++ echo "$yyy=$zzz" >> posthint.sh ;;
++ *) echo "$me: unknown -A command '$xxx', ignoring -A $1" >&2 ;;
++ esac
++ shift
++ ;;
+ -f)
+ shift
+ cd ..
+EOPATCH
+}
+
if ($major < 8 && !extract_from_file('Configure',
qr/^\t\tif test ! -t 0; then$/)) {
# Before dfe9444ca7881e71, Configure would refuse to run if stdin was not a
# There was a bug in makedepend.SH which was fixed in version 96a8704c.
# Symptom was './makedepend: 1: Syntax error: Unterminated quoted string'
# Remove this if you're actually bisecting a problem related to makedepend.SH
-system 'git show blead:makedepend.SH > makedepend.SH </dev/null' and die;
+checkout_file('makedepend.SH');
if ($^O eq 'freebsd') {
# There are rather too many version-specific FreeBSD hints fixes to patch
# instead of treating previous versions' behaviour explicitly and changing
# the default to cater for the current behaviour. (As strangely, future
# versions inherit the current behaviour.)
- system 'git show blead:hints/freebsd.sh > hints/freebsd.sh </dev/null'
- and die;
+ checkout_file('hints/freebsd.sh');
} elsif ($^O eq 'darwin') {
if ($major < 8) {
my $faking_it;
# f556e5b971932902 - before it, hints bugs would be "fixed", after
# it they'd resurface. This way, we should give the illusion of
# monotonic bug fixing.
- system "git show f556e5b971932902:$_ >$_"
- and die "while attempting to extract $_";
+ checkout_file($_, 'f556e5b971932902');
}
if ($faking_it) {
apply_patch(<<'EOPATCH');
}
}
} elsif ($^O eq 'openbsd') {
- if (!-f 'hints/openbsd.sh') {
- system 'git show 43051805d53a3e4c:hints/openbsd.sh > hints/openbsd.sh'
- and die;
- }
+ checkout_file('hints/openbsd.sh', '43051805d53a3e4c')
+ unless -f 'hints/openbsd.sh';
if ($major < 8) {
my $which = extract_from_file('hints/openbsd.sh',
EOPATCH
}
+if ($major == 4 && !extract_from_file('perl.c', qr/delimcpy.*,$/)) {
+ # bug introduced in 2a92aaa05aa1acbf, fixed in 8490252049bf42d3
+ apply_patch(<<'EOPATCH');
+diff --git a/perl.c b/perl.c
+index 4eb69e3..54bbb00 100644
+--- a/perl.c
++++ b/perl.c
+@@ -1735,7 +1735,7 @@ SV *sv;
+ if (len < sizeof tokenbuf)
+ tokenbuf[len] = '\0';
+ #else /* ! (atarist || DOSISH) */
+- s = delimcpy(tokenbuf, tokenbuf + sizeof tokenbuf, s, bufend
++ s = delimcpy(tokenbuf, tokenbuf + sizeof tokenbuf, s, bufend,
+ ':',
+ &len);
+ #endif /* ! (atarist || DOSISH) */
+EOPATCH
+}
+
if (($major >= 7 || $major <= 9) && $^O eq 'openbsd'
&& `uname -m` eq "sparc64\n"
# added in 2000 by commit cb434fcc98ac25f5: