This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add -c option to bisect-runner.pl, for use with -e
[perl5.git] / Porting / bisect-runner.pl
CommitLineData
6a8dbfd7
NC
1#!/usr/bin/perl -w
2use strict;
3
390a69a9 4use Getopt::Long qw(:config bundling no_auto_abbrev);
77ae6092 5use Pod::Usage;
2526f4b8 6use Config;
69bf9aba 7use Carp;
6a8dbfd7 8
2526f4b8
NC
9my @targets
10 = qw(config.sh config.h miniperl lib/Config.pm Fcntl perl test_prep);
6a8dbfd7 11
e4516dd0
NC
12my $cpus;
13if (open my $fh, '<', '/proc/cpuinfo') {
14 while (<$fh>) {
15 ++$cpus if /^processor\s+:\s+\d+$/;
16 }
d64af352
NC
17} elsif (-x '/sbin/sysctl') {
18 $cpus = 1 + $1 if `/sbin/sysctl hw.ncpu` =~ /^hw\.ncpu: (\d+)$/;
da83cd31
NC
19} elsif (-x '/usr/bin/getconf') {
20 $cpus = 1 + $1 if `/usr/bin/getconf _NPROCESSORS_ONLN` =~ /^(\d+)$/;
e4516dd0
NC
21}
22
f4800c99
NC
23my %options =
24 (
e4516dd0 25 jobs => defined $cpus ? $cpus + 1 : 2,
f4800c99
NC
26 'expect-pass' => 1,
27 clean => 1, # mostly for debugging this
28 );
6a8dbfd7 29
fdbac266
NC
30my $linux64 = `uname -sm` eq "Linux x86_64\n" ? '64' : '';
31
599ee4f7
NC
32my @paths;
33
34if ($^O eq 'linux') {
35 # This is the search logic for a multi-arch library layout
36 # added to linux.sh in commits 40f026236b9959b7 and dcffd848632af2c7.
37 my $gcc = -x '/usr/bin/gcc' ? '/usr/bin/gcc' : 'gcc';
38
39 foreach (`$gcc -print-search-dirs`) {
40 next unless /^libraries: =(.*)/;
41 foreach (split ':', $1) {
42 next if m/gcc/;
43 next unless -d $_;
44 s!/$!!;
45 push @paths, $_;
46 }
47 }
48}
49
50push @paths, map {$_ . $linux64} qw(/usr/local/lib /lib /usr/lib);
390a69a9
NC
51
52my %defines =
53 (
54 usedevel => '',
55 optimize => '-g',
63f9ec30 56 cc => (`ccache --version`, $?) ? 'cc' : 'ccache cc',
9913adee 57 ld => 'cc',
fdbac266 58 ($linux64 ? (libpth => \@paths) : ()),
390a69a9
NC
59 );
60
f4800c99 61unless(GetOptions(\%options,
32ffe018 62 'target=s', 'make=s', 'jobs|j=i', 'expect-pass=i',
f4800c99 63 'expect-fail' => sub { $options{'expect-pass'} = 0; },
529d2ac2 64 'clean!', 'one-liner|e=s', 'c', 'l', 'w', 'match=s',
66b521dd
NC
65 'no-match=s' => sub {
66 $options{match} = $_[1];
67 $options{'expect-pass'} = 0;
68 },
69 'force-manifest', 'force-regen', 'test-build', 'validate',
70 'check-args', 'check-shebang!', 'usage|help|?', 'A=s@',
390a69a9
NC
71 'D=s@' => sub {
72 my (undef, $val) = @_;
73 if ($val =~ /\A([^=]+)=(.*)/s) {
74 $defines{$1} = length $2 ? $2 : "\0";
75 } else {
76 $defines{$val} = '';
77 }
78 },
79 'U=s@' => sub {
80 $defines{$_[1]} = undef;
81 },
6a8dbfd7 82 )) {
77ae6092 83 pod2usage(exitval => 255, verbose => 1);
6a8dbfd7
NC
84}
85
f4800c99 86my ($target, $j, $match) = @options{qw(target jobs match)};
e295b7be 87
b826a648
NC
88@ARGV = ('sh', '-c', 'cd t && ./perl TEST base/*.t')
89 if $options{validate} && !@ARGV;
90
0ed3b851 91pod2usage(exitval => 0, verbose => 1) if $options{usage};
77ae6092
NC
92pod2usage(exitval => 255, verbose => 1)
93 unless @ARGV || $match || $options{'test-build'} || defined $options{'one-liner'};
fc4401c6
NC
94pod2usage(exitval => 255, verbose => 1)
95 if !$options{'one-liner'} && ($options{l} || $options{w});
6a8dbfd7 96
bf8fb529
NC
97check_shebang($ARGV[0])
98 if $options{'check-shebang'} && @ARGV && !$options{match};
7cffc32d 99
f4800c99 100exit 0 if $options{'check-args'};
6a8dbfd7 101
77ae6092
NC
102=head1 NAME
103
104bisect.pl - use git bisect to pinpoint changes
105
106=head1 SYNOPSIS
107
108 # When did this become an error?
109 .../Porting/bisect.pl -e 'my $a := 2;'
71d80638 110 # When did this stop being an error?
77ae6092
NC
111 .../Porting/bisect.pl --expect-fail -e '1 // 2'
112 # When did this stop matching?
113 .../Porting/bisect.pl --match '\b(?:PL_)hash_seed_set\b'
114 # When did this start matching?
115 .../Porting/bisect.pl --expect-fail --match '\buseithreads\b'
116 # When did this test program stop working?
d398528a 117 .../Porting/bisect.pl -- ./perl -Ilib ../test_prog.pl
77ae6092
NC
118 # When did this first become valid syntax?
119 .../Porting/bisect.pl --target=miniperl --end=v5.10.0 \
120 --expect-fail -e 'my $a := 2;'
121 # What was the last revision to build with these options?
122 .../Porting/bisect.pl --test-build -Dd_dosuid
123
124=head1 DESCRIPTION
125
facd1b88 126Together F<bisect.pl> and F<bisect-runner.pl> attempt to automate the use
77ae6092
NC
127of C<git bisect> as much as possible. With one command (and no other files)
128it's easy to find out
129
130=over 4
131
132=item *
133
134Which commit caused this example code to break?
135
136=item *
137
138Which commit caused this example code to start working?
139
140=item *
141
142Which commit added the first to match this regex?
143
144=item *
145
146Which commit removed the last to match this regex?
147
148=back
149
150usually without needing to know which versions of perl to use as start and
151end revisions.
152
facd1b88 153By default F<bisect.pl> will process all options, then use the rest of the
77ae6092
NC
154command line as arguments to list C<system> to run a test case. By default,
155the test case should pass (exit with 0) on earlier perls, and fail (exit
facd1b88 156non-zero) on I<blead>. F<bisect.pl> will use F<bisect-runner.pl> to find the
77ae6092 157earliest stable perl version on which the test case passes, check that it
facd1b88 158fails on blead, and then use F<bisect-runner.pl> with C<git bisect run> to
77ae6092
NC
159find the commit which caused the failure.
160
161Because the test case is the complete argument to C<system>, it is easy to
162run something other than the F<perl> built, if necessary. If you need to run
163the perl built, you'll probably need to invoke it as C<./perl -Ilib ...>
164
5842706e
NC
165You need a clean checkout to run a bisect, and you can't use the checkout
166which contains F<Porting/bisect.pl> (because C<git bisect>) will check out
167a revision before F<Porting/bisect-runner.pl> was added, which
168C<git bisect run> needs). If your working checkout is called F<perl>, the
169simplest solution is to make a local clone, and run from that. I<i.e.>:
170
171 cd ..
172 git clone perl perl2
173 cd perl2
174 ../perl/Porting/bisect.pl ...
175
facd1b88 176By default, F<bisect-runner.pl> will automatically disable the build of
cfadff5f
NC
177L<DB_File> for commits earlier than ccb44e3bf3be2c30, as it's not practical
178to patch DB_File 1.70 and earlier to build with current Berkeley DB headers.
179(ccb44e3bf3be2c30 was in September 1999, between 5.005_62 and 5.005_63.)
180If your F<db.h> is old enough you can override this with C<-Unoextensions>.
181
77ae6092
NC
182=head1 OPTIONS
183
184=over 4
185
186=item *
187
188--start I<commit-ish>
189
190Earliest revision to test, as a I<commit-ish> (a tag, commit or anything
facd1b88 191else C<git> understands as a revision). If not specified, F<bisect.pl> will
3ffe2687
NC
192search stable perl releases until it finds one where the test case passes.
193The default is to search from 5.002 to 5.14.0. If F<bisect.pl> detects that
194the checkout is on a case insensitive file system, it will search from
1955.005 to 5.14.0
77ae6092
NC
196
197=item *
198
199--end I<commit-ish>
200
201Most recent revision to test, as a I<commit-ish>. If not specified, defaults
b4f0ec5f 202to I<blead>.
77ae6092
NC
203
204=item *
205
206--target I<target>
207
208F<Makefile> target (or equivalent) needed, to run the test case. If specified,
209this should be one of
210
211=over 4
212
213=item *
214
215I<config.sh>
216
facd1b88 217Just run F<./Configure>
77ae6092
NC
218
219=item *
220
221I<config.h>
222
223Run the various F<*.SH> files to generate F<Makefile>, F<config.h>, I<etc>.
224
225=item *
226
227I<miniperl>
228
229Build F<miniperl>.
230
231=item *
232
233I<lib/Config.pm>
234
235Use F<miniperl> to build F<lib/Config.pm>
236
237=item *
238
2526f4b8
NC
239I<Fcntl>
240
241Build F<lib/auto/Fcntl/Fnctl.so> (strictly, C<.$Config{so}>). As L<Fcntl>
242is simple XS module present since 5.000, this provides a fast test of
b4f0ec5f 243whether XS modules can be built. Note, XS modules are built by F<miniperl>,
2526f4b8
NC
244hence this target will not build F<perl>.
245
246=item *
247
77ae6092
NC
248I<perl>
249
250Build F<perl>. This also builds pure-Perl modules in F<cpan>, F<dist> and
2526f4b8
NC
251F<ext>. XS modules (such as L<Fcntl>) are not built.
252
253=item *
254
77ae6092
NC
255I<test_prep>
256
257Build everything needed to run the tests. This is the default if we're
258running test code, but is time consuming, as it means building all
b4f0ec5f 259XS modules. For older F<Makefile>s, the previous name of C<test-prep>
77ae6092
NC
260is automatically substituted. For very old F<Makefile>s, C<make test> is
261run, as there is no target provided to just get things ready, and for 5.004
262and earlier the tests run very quickly.
263
264=back
265
266=item *
267
268--one-liner 'code to run'
269
270=item *
271
272-e 'code to run'
273
a1756669 274Example code to run, just like you'd use with C<perl -e>.
77ae6092
NC
275
276This prepends C<./perl -Ilib -e 'code to run'> to the test case given,
facd1b88 277or F<./miniperl> if I<target> is C<miniperl>.
77ae6092
NC
278
279(Usually you'll use C<-e> instead of providing a test case in the
facd1b88 280non-option arguments to F<bisect.pl>)
77ae6092
NC
281
282C<-E> intentionally isn't supported, as it's an error in 5.8.0 and earlier,
283which interferes with detecting errors in the example code itself.
284
285=item *
286
529d2ac2
NC
287-c
288
289Add C<-c> to the command line, to cause perl to exit after syntax checking.
290
291=item *
292
fc4401c6
NC
293-l
294
295Add C<-l> to the command line with C<-e>
296
297This will automatically append a newline to every output line of your testcase.
298Note that you can't specify an argument to F<perl>'s C<-l> with this, as it's
299not feasible to emulate F<perl>'s somewhat quirky switch parsing with
300L<Getopt::Long>. If you need the full flexibility of C<-l>, you need to write
301a full test case, instead of using C<bisect.pl>'s C<-e> shortcut.
302
303=item *
304
305-w
306
307Add C<-w> to the command line with C<-e>
308
529d2ac2
NC
309It's not valid to pass C<-c>, C<-l> or C<-w> to C<bisect.pl> unless you are
310also using C<-e>
fc4401c6
NC
311
312=item *
313
77ae6092
NC
314--expect-fail
315
316The test case should fail for the I<start> revision, and pass for the I<end>
317revision. The bisect run will find the first commit where it passes.
318
319=item *
320
af7c500f 321-Dnoextensions=Encode
77ae6092
NC
322
323=item *
324
325-Uusedevel
326
327=item *
328
329-Accflags=-DNO_MATHOMS
330
331Arguments to pass to F<Configure>. Repeated C<-A> arguments are passed
332through as is. C<-D> and C<-U> are processed in order, and override
af7c500f
NC
333previous settings for the same parameter. F<bisect-runner.pl> emulates
334C<-Dnoextensions> when F<Configure> itself does not provide it, as it's
335often very useful to be able to disable some XS extensions.
77ae6092
NC
336
337=item *
338
32ffe018
NC
339--make I<make-prog>
340
341The C<make> command to use. If this not set, F<make> is used. If this is
342set, it also adds a C<-Dmake=...> else some recursive make invocations
343in extensions may fail. Typically one would use this as C<--make gmake>
344to use F<gmake> in place of the system F<make>.
345
346=item *
347
b4f0ec5f 348--jobs I<jobs>
77ae6092
NC
349
350=item *
351
b4f0ec5f 352-j I<jobs>
77ae6092 353
da83cd31
NC
354Number of C<make> jobs to run in parallel. If F</proc/cpuinfo> exists and
355can be parsed, or F</sbin/sysctl> exists and reports C<hw.ncpu>, or
356F</usr/bin/getconf> exists and reports C<_NPROCESSORS_ONLN> defaults to 1 +
357I<number of CPUs>. Otherwise defaults to 2.
77ae6092
NC
358
359=item *
360
b4f0ec5f 361--match pattern
77ae6092 362
66b521dd
NC
363=item *
364
365--no-match pattern
366
367Instead of running a test program to determine I<pass> or I<fail>,
368C<--match> will pass if the given regex matches, and hence search for the
369commit that removes the last matching file. C<--no-match> inverts the test,
370to search for the first commit that adds files that match.
bf8fb529
NC
371
372The remaining command line arguments are treated as glob patterns for files
373to match against. If none are specified, then they default as follows:
374
375=over 4
376
377=item *
77ae6092
NC
378
379If no I<target> is specified, the match is against all files in the
bf8fb529
NC
380repository (which is fast).
381
382=item *
383
384If a I<target> is specified, that target is built, and the match is against
385only the built files.
386
387=back
388
389Treating the command line arguments as glob patterns should not cause
390problems, as the perl distribution has never shipped or built files with
391names that contain characters which are globbing metacharacters.
392
393Anything which is not a readable file is ignored, instead of generating an
394error. (If you want an error, run C<grep> or C<ack> as a test case). This
395permits one to easily search in a file that changed its name. For example:
396
397 .../Porting/bisect.pl --match 'Pod.*Functions' 'pod/buildtoc*'
77ae6092 398
66b521dd
NC
399C<--no-match ...> is implemented as C<--expect-fail --match ...>
400
77ae6092
NC
401=item *
402
403--test-build
404
405Test that the build completes, without running any test case.
406
407By default, if the build for the desired I<target> fails to complete,
408F<bisect-runner.pl> reports a I<skip> back to C<git bisect>, the assumption
409being that one wants to find a commit which changed state "builds && passes"
410to "builds && fails". If instead one is interested in which commit broke the
411build (possibly for particular F<Configure> options), use I<--test-build>
412to treat a build failure as a failure, not a "skip".
413
b4f0ec5f
NC
414Often this option isn't as useful as it first seems, because I<any> build
415failure will be reported to C<git bisect> as a failure, not just the failure
416that you're interested in. Generally, to debug a particular problem, it's
417more useful to use a I<target> that builds properly at the point of interest,
418and then a test case that runs C<make>. For example:
419
420 .../Porting/bisect.pl --start=perl-5.000 --end=perl-5.002 \
421 --expect-fail --force-manifest --target=miniperl make perl
422
facd1b88
NC
423will find the first revision capable of building L<DynaLoader> and then
424F<perl>, without becoming confused by revisions where F<miniperl> won't
b4f0ec5f
NC
425even link.
426
77ae6092
NC
427=item *
428
b4f0ec5f
NC
429--force-manifest
430
77ae6092
NC
431By default, a build will "skip" if any files listed in F<MANIFEST> are not
432present. Usually this is useful, as it avoids false-failures. However, there
433are some long ranges of commits where listed files are missing, which can
434cause a bisect to abort because all that remain are skipped revisions.
435
436In these cases, particularly if the test case uses F<miniperl> and no modules,
437it may be more useful to force the build to continue, even if files
438F<MANIFEST> are missing.
439
440=item *
441
bfa52998
NC
442--force-regen
443
444Run C<make regen_headers> before building F<miniperl>. This may fix a build
445that otherwise would skip because the generated headers at that revision
446are stale. It's not the default because it conceals this error in the true
447state of such revisions.
448
449=item *
450
77ae6092
NC
451--expect-pass [0|1]
452
453C<--expect-pass=0> is equivalent to C<--expect-fail>. I<1> is the default.
454
455=item *
456
457--no-clean
458
459Tell F<bisect-runner.pl> not to clean up after the build. This allows one
460to use F<bisect-runner.pl> to build the current particular perl revision for
461interactive testing, or for debugging F<bisect-runner.pl>.
462
463Passing this to F<bisect.pl> will likely cause the bisect to fail badly.
464
465=item *
466
195ed8b1
NC
467--validate
468
3f14869b 469Test that all stable revisions can be built. By default, attempts to build
3ffe2687
NC
470I<blead>, I<v5.14.0> .. I<perl-5.002> (or I<perl5.005> on a case insensitive
471file system). Stops at the first failure, without
3f14869b
NC
472cleaning the checkout. Use I<--start> to specify the earliest revision to
473test, I<--end> to specify the most recent. Useful for validating a new
195ed8b1
NC
474OS/CPU/compiler combination. For example
475
fc4401c6 476 ../perl/Porting/bisect.pl --validate -le 'print "Hello from $]"'
195ed8b1 477
e2760528
NC
478If no testcase is specified, the default is to use F<t/TEST> to run
479F<t/base/*.t>
480
195ed8b1
NC
481=item *
482
77ae6092
NC
483--check-args
484
485Validate the options and arguments, and exit silently if they are valid.
486
487=item *
488
7cffc32d
NC
489--check-shebang
490
491Validate that the test case isn't an executable file with a
492C<#!/usr/bin/perl> line (or similar). As F<bisect-runner.pl> does B<not>
493prepend C<./perl> to the test case, a I<#!> line specifying an external
494F<perl> binary will cause the test case to always run with I<that> F<perl>,
495not the F<perl> built by the bisect runner. Likely this is not what you
496wanted. If your test case is actually a wrapper script to run other
497commands, you should run it with an explicit interpreter, to be clear. For
498example, instead of C<../perl/Porting/bisect.pl ~/test/testcase.pl> you'd
499run C<../perl/Porting/bisect.pl /usr/bin/perl ~/test/testcase.pl>
500
501=item *
502
77ae6092
NC
503--usage
504
505=item *
506
507--help
508
509=item *
510
511-?
512
513Display the usage information and exit.
514
515=back
516
517=cut
518
0afef97d 519die "$0: Can't build $target" if defined $target && !grep {@targets} $target;
6a8dbfd7
NC
520
521$j = "-j$j" if $j =~ /\A\d+\z/;
522
32ffe018
NC
523if (exists $options{make}) {
524 if (!exists $defines{make}) {
525 $defines{make} = $options{make};
526 }
527} else {
528 $options{make} = 'make';
529}
530
0142f0ce
NC
531# Sadly, however hard we try, I don't think that it will be possible to build
532# modules in ext/ on x86_64 Linux before commit e1666bf5602ae794 on 1999/12/29,
533# which updated to MakeMaker 3.7, which changed from using a hard coded ld
534# in the Makefile to $(LD). On x86_64 Linux the "linker" is gcc.
535
69bf9aba
NC
536sub open_or_die {
537 my $file = shift;
538 my $mode = @_ ? shift : '<';
539 open my $fh, $mode, $file or croak("Can't open $file: $!");
540 ${*$fh{SCALAR}} = $file;
541 return $fh;
542}
543
544sub close_or_die {
545 my $fh = shift;
546 return if close $fh;
547 croak("Can't close: $!") unless ref $fh eq 'GLOB';
548 croak("Can't close ${*$fh{SCALAR}}: $!");
549}
550
6a8dbfd7
NC
551sub extract_from_file {
552 my ($file, $rx, $default) = @_;
69bf9aba 553 my $fh = open_or_die($file);
6a8dbfd7
NC
554 while (<$fh>) {
555 my @got = $_ =~ $rx;
556 return wantarray ? @got : $got[0]
557 if @got;
558 }
559 return $default if defined $default;
560 return;
561}
562
c59e8fd6
NC
563sub edit_file {
564 my ($file, $munger) = @_;
565 local $/;
69bf9aba 566 my $fh = open_or_die($file);
c59e8fd6
NC
567 my $orig = <$fh>;
568 die "Can't read $file: $!" unless defined $orig && close $fh;
569 my $new = $munger->($orig);
570 return if $new eq $orig;
69bf9aba 571 $fh = open_or_die($file, '>');
c59e8fd6 572 print $fh $new or die "Can't print to $file: $!";
69bf9aba 573 close_or_die($fh);
c59e8fd6
NC
574}
575
6fe55cbd
NC
576# AIX supplies a pre-historic patch program, which certainly predates Linux
577# and is probably older than NT. It can't cope with unified diffs. Meanwhile,
578# it's hard enough to get git diff to output context diffs, let alone git show,
579# and nearly all the patches embedded here are unified. So it seems that the
580# path of least resistance is to convert unified diffs to context diffs:
581
582sub process_hunk {
583 my ($from_out, $to_out, $has_from, $has_to, $delete, $add) = @_;
584 ++$$has_from if $delete;
585 ++$$has_to if $add;
586
587 if ($delete && $add) {
588 $$from_out .= "! $_\n" foreach @$delete;
589 $$to_out .= "! $_\n" foreach @$add;
590 } elsif ($delete) {
591 $$from_out .= "- $_\n" foreach @$delete;
592 } elsif ($add) {
593 $$to_out .= "+ $_\n" foreach @$add;
594 }
595}
596
597# This isn't quite general purpose, as it can't cope with
598# '\ No newline at end of file'
599sub ud2cd {
600 my $diff_in = shift;
601 my $diff_out = '';
602
603 # Stuff before the diff
604 while ($diff_in =~ s/\A(?!\*\*\* )(?!--- )([^\n]*\n?)//ms && length $1) {
605 $diff_out .= $1;
606 }
607
608 if (!length $diff_in) {
609 die "That didn't seem to be a diff";
610 }
611
612 if ($diff_in =~ /\A\*\*\* /ms) {
613 warn "Seems to be a context diff already\n";
614 return $diff_out . $diff_in;
615 }
616
617 # Loop for files
618 FILE: while (1) {
619 if ($diff_in =~ s/\A((?:diff |index )[^\n]+\n)//ms) {
620 $diff_out .= $1;
621 next;
622 }
623 if ($diff_in !~ /\A--- /ms) {
624 # Stuff after the diff;
625 return $diff_out . $diff_in;
626 }
627 $diff_in =~ s/\A([^\n]+\n?)//ms;
628 my $line = $1;
629 die "Can't parse '$line'" unless $line =~ s/\A--- /*** /ms;
630 $diff_out .= $line;
631 $diff_in =~ s/\A([^\n]+\n?)//ms;
632 $line = $1;
633 die "Can't parse '$line'" unless $line =~ s/\A\+\+\+ /--- /ms;
634 $diff_out .= $line;
635
636 # Loop for hunks
637 while (1) {
638 next FILE
639 unless $diff_in =~ s/\A\@\@ (-([0-9]+),([0-9]+) \+([0-9]+),([0-9]+)) \@\@[^\n]*\n?//;
640 my ($hunk, $from_start, $from_count, $to_start, $to_count)
641 = ($1, $2, $3, $4, $5);
642 my $from_end = $from_start + $from_count - 1;
643 my $to_end = $to_start + $to_count - 1;
644 my ($from_out, $to_out, $has_from, $has_to, $add, $delete);
645 while (length $diff_in && ($from_count || $to_count)) {
646 die "Confused in $hunk" unless $diff_in =~ s/\A([^\n]*)\n//ms;
647 my $line = $1;
648 $line = ' ' unless length $line;
649 if ($line =~ /^ .*/) {
650 process_hunk(\$from_out, \$to_out, \$has_from, \$has_to,
651 $delete, $add);
652 undef $delete;
653 undef $add;
654 $from_out .= " $line\n";
655 $to_out .= " $line\n";
656 --$from_count;
657 --$to_count;
658 } elsif ($line =~ /^-(.*)/) {
659 push @$delete, $1;
660 --$from_count;
661 } elsif ($line =~ /^\+(.*)/) {
662 push @$add, $1;
663 --$to_count;
664 } else {
665 die "Can't parse '$line' as part of hunk $hunk";
666 }
667 }
668 process_hunk(\$from_out, \$to_out, \$has_from, \$has_to,
669 $delete, $add);
670 die "No lines in hunk $hunk"
671 unless length $from_out || length $to_out;
672 die "No changes in hunk $hunk"
673 unless $has_from || $has_to;
674 $diff_out .= "***************\n";
675 $diff_out .= "*** $from_start,$from_end ****\n";
676 $diff_out .= $from_out if $has_from;
677 $diff_out .= "--- $to_start,$to_end ----\n";
678 $diff_out .= $to_out if $has_to;
679 }
680 }
681}
682
683{
684 my $use_context;
685
686 sub placate_patch_prog {
687 my $patch = shift;
688
689 if (!defined $use_context) {
690 my $version = `patch -v 2>&1`;
691 die "Can't run `patch -v`, \$?=$?, bailing out"
692 unless defined $version;
693 if ($version =~ /Free Software Foundation/) {
694 $use_context = 0;
695 } elsif ($version =~ /Header: patch\.c,v.*\blwall\b/) {
696 # The system patch is older than Linux, and probably older than
697 # Windows NT.
698 $use_context = 1;
699 } else {
700 # Don't know.
701 $use_context = 0;
702 }
703 }
704
705 return $use_context ? ud2cd($patch) : $patch;
706 }
707}
708
c59e8fd6 709sub apply_patch {
58a28a53
NC
710 my ($patch, $what, $files) = @_;
711 $what = 'patch' unless defined $what;
712 unless (defined $files) {
713 $patch =~ m!^--- a/(\S+)\n\+\+\+ b/\1!sm;
714 $files = " $1";
715 }
6fe55cbd 716 my $patch_to_use = placate_patch_prog($patch);
c59e8fd6 717 open my $fh, '|-', 'patch', '-p1' or die "Can't run patch: $!";
6fe55cbd 718 print $fh $patch_to_use;
5fceabf3
NC
719 return if close $fh;
720 print STDERR "Patch is <<'EOPATCH'\n${patch}EOPATCH\n";
56a20cc1
NC
721 print STDERR "\nConverted to a context diff <<'EOCONTEXT'\n${patch_to_use}EOCONTEXT\n"
722 if $patch_to_use ne $patch;
58a28a53 723 die "Can't $what$files: $?, $!";
c59e8fd6
NC
724}
725
4e540a4e
NC
726sub apply_commit {
727 my ($commit, @files) = @_;
58a28a53
NC
728 my $patch = `git show $commit @files`;
729 if (!defined $patch) {
730 die "Can't get commit $commit for @files: $?" if @files;
731 die "Can't get commit $commit: $?";
732 }
733 apply_patch($patch, "patch $commit", @files ? " for @files" : '');
4e540a4e
NC
734}
735
736sub revert_commit {
737 my ($commit, @files) = @_;
58a28a53
NC
738 my $patch = `git show -R $commit @files`;
739 if (!defined $patch) {
740 die "Can't get revert commit $commit for @files: $?" if @files;
741 die "Can't get revert commit $commit: $?";
742 }
743 apply_patch($patch, "revert $commit", @files ? " for @files" : '');
4e540a4e
NC
744}
745
91ad6f8a
NC
746sub checkout_file {
747 my ($file, $commit) = @_;
748 $commit ||= 'blead';
749 system "git show $commit:$file > $file </dev/null"
750 and die "Could not extract $file at revision $commit";
751}
752
7cffc32d
NC
753sub check_shebang {
754 my $file = shift;
755 return unless -e $file;
756 if (!-x $file) {
757 die "$file is not executable.
758system($file, ...) is always going to fail.
759
760Bailing out";
761 }
762 my $fh = open_or_die($file);
763 my $line = <$fh>;
764 return unless $line =~ m{\A#!(/\S+/perl\S*)\s};
765 die "$file will always be run by $1
766It won't be tested by the ./perl we build.
767If you intended to run it with that perl binary, please change your
768test case to
769
770 $1 @ARGV
771
772If you intended to test it with the ./perl we build, please change your
773test case to
774
775 ./perl -Ilib @ARGV
776
777[You may also need to add -- before ./perl to prevent that -Ilib as being
778parsed as an argument to bisect.pl]
779
780Bailing out";
781}
782
ab4a15f9 783sub clean {
f4800c99 784 if ($options{clean}) {
ab4a15f9
NC
785 # Needed, because files that are build products in this checked out
786 # version might be in git in the next desired version.
9da8cb0a 787 system 'git clean -dxf </dev/null';
ab4a15f9
NC
788 # Needed, because at some revisions the build alters checked out files.
789 # (eg pod/perlapi.pod). Also undoes any changes to makedepend.SH
9da8cb0a 790 system 'git reset --hard HEAD </dev/null';
ab4a15f9
NC
791 }
792}
793
794sub skip {
795 my $reason = shift;
796 clean();
797 warn "skipping - $reason";
798 exit 125;
799}
800
f1050811
NC
801sub report_and_exit {
802 my ($ret, $pass, $fail, $desc) = @_;
803
804 clean();
805
f4800c99 806 my $got = ($options{'expect-pass'} ? !$ret : $ret) ? 'good' : 'bad';
f1050811
NC
807 if ($ret) {
808 print "$got - $fail $desc\n";
809 } else {
810 print "$got - $pass $desc\n";
811 }
812
813 exit($got eq 'bad');
814}
815
0afef97d 816sub match_and_exit {
bf8fb529 817 my ($target, @globs) = @_;
0afef97d
NC
818 my $matches = 0;
819 my $re = qr/$match/;
820 my @files;
821
bf8fb529
NC
822 if (@globs) {
823 require File::Glob;
824 foreach (sort map { File::Glob::bsd_glob($_)} @globs) {
825 if (!-f $_ || !-r _) {
826 warn "Skipping matching '$_' as it is not a readable file\n";
827 } else {
828 push @files, $_;
829 }
830 }
831 } else {
0afef97d
NC
832 local $/ = "\0";
833 @files = defined $target ? `git ls-files -o -z`: `git ls-files -z`;
834 chomp @files;
835 }
836
837 foreach my $file (@files) {
69bf9aba 838 my $fh = open_or_die($file);
0afef97d
NC
839 while (<$fh>) {
840 if ($_ =~ $re) {
841 ++$matches;
842 if (tr/\t\r\n -~\200-\377//c) {
843 print "Binary file $file matches\n";
844 } else {
845 $_ .= "\n" unless /\n\z/;
846 print "$file: $_";
847 }
848 }
849 }
69bf9aba 850 close_or_die($fh);
0afef97d
NC
851 }
852 report_and_exit(!$matches,
853 $matches == 1 ? '1 match for' : "$matches matches for",
854 'no matches for', $match);
855}
856
6a8dbfd7 857# Not going to assume that system perl is yet new enough to have autodie
9da8cb0a 858system 'git clean -dxf </dev/null' and die;
6a8dbfd7 859
0afef97d 860if (!defined $target) {
bf8fb529 861 match_and_exit(undef, @ARGV) if $match;
0afef97d 862 $target = 'test_prep';
bc96a05a
NC
863}
864
4b081584
NC
865skip('no Configure - is this the //depot/perlext/Compiler branch?')
866 unless -f 'Configure';
867
1f1c8096
NC
868my $case_insensitive;
869{
870 my ($dev_C, $ino_C) = stat 'Configure';
871 die "Could not stat Configure: $!" unless defined $dev_C;
872 my ($dev_c, $ino_c) = stat 'configure';
873 ++$case_insensitive
874 if defined $dev_c && $dev_C == $dev_c && $ino_C == $ino_c;
875}
876
dbcdc176
NC
877# This changes to PERL_VERSION in 4d8076ea25903dcb in 1999
878my $major
879 = extract_from_file('patchlevel.h',
880 qr/^#define\s+(?:PERL_VERSION|PATCHLEVEL)\s+(\d+)\s/,
881 0);
882
750ce942
NC
883patch_Configure();
884patch_hints();
885
6a8dbfd7
NC
886# if Encode is not needed for the test, you can speed up the bisect by
887# excluding it from the runs with -Dnoextensions=Encode
888# ccache is an easy win. Remove it if it causes problems.
6a8dbfd7
NC
889# Commit 1cfa4ec74d4933da adds ignore_versioned_solibs to Configure, and sets it
890# to true in hints/linux.sh
891# On dromedary, from that point on, Configure (by default) fails to find any
892# libraries, because it scans /usr/local/lib /lib /usr/lib, which only contain
893# versioned libraries. Without -lm, the build fails.
894# Telling /usr/local/lib64 /lib64 /usr/lib64 works from that commit onwards,
895# until commit faae14e6e968e1c0 adds it to the hints.
896# However, prior to 1cfa4ec74d4933da telling Configure the truth doesn't work,
897# because it will spot versioned libraries, pass them to the compiler, and then
898# bail out pretty early on. Configure won't let us override libswanted, but it
899# will let us override the entire libs list.
900
901unless (extract_from_file('Configure', 'ignore_versioned_solibs')) {
902 # Before 1cfa4ec74d4933da, so force the libs list.
903
904 my @libs;
905 # This is the current libswanted list from Configure, less the libs removed
906 # by current hints/linux.sh
907 foreach my $lib (qw(sfio socket inet nsl nm ndbm gdbm dbm db malloc dl dld
908 ld sun m crypt sec util c cposix posix ucb BSD)) {
909 foreach my $dir (@paths) {
910 next unless -f "$dir/lib$lib.so";
911 push @libs, "-l$lib";
912 last;
913 }
914 }
390a69a9 915 $defines{libs} = \@libs unless exists $defines{libs};
6a8dbfd7
NC
916}
917
390a69a9
NC
918$defines{usenm} = undef
919 if $major < 2 && !exists $defines{usenm};
0142f0ce 920
05ec8abc
NC
921my ($missing, $created_dirs);
922($missing, $created_dirs) = force_manifest()
923 if $options{'force-manifest'};
67382a3b 924
af7c500f 925my @ARGS = '-dEs';
390a69a9
NC
926foreach my $key (sort keys %defines) {
927 my $val = $defines{$key};
928 if (ref $val) {
929 push @ARGS, "-D$key=@$val";
930 } elsif (!defined $val) {
931 push @ARGS, "-U$key";
932 } elsif (!length $val) {
933 push @ARGS, "-D$key";
934 } else {
935 $val = "" if $val eq "\0";
936 push @ARGS, "-D$key=$val";
937 }
938}
939push @ARGS, map {"-A$_"} @{$options{A}};
940
6a8dbfd7
NC
941# </dev/null because it seems that some earlier versions of Configure can
942# call commands in a way that now has them reading from stdin (and hanging)
943my $pid = fork;
944die "Can't fork: $!" unless defined $pid;
945if (!$pid) {
7c22f158
NC
946 open STDIN, '<', '/dev/null';
947 # If a file in MANIFEST is missing, Configure asks if you want to
948 # continue (the default being 'n'). With stdin closed or /dev/null,
949 # it exits immediately and the check for config.sh below will skip.
6a8dbfd7
NC
950 exec './Configure', @ARGS;
951 die "Failed to start Configure: $!";
952}
953waitpid $pid, 0
954 or die "wait for Configure, pid $pid failed: $!";
955
bb723266
NC
956patch_SH();
957
af7c500f 958if (-f 'config.sh') {
05ec8abc
NC
959 # Emulate noextensions if Configure doesn't support it.
960 fake_noextensions()
961 if $major < 10 && $defines{noextensions};
af7c500f
NC
962 system './Configure -S </dev/null' and die;
963}
964
0afef97d 965if ($target =~ /config\.s?h/) {
bf8fb529 966 match_and_exit($target, @ARGV) if $match && -f $target;
30a13282
NC
967 report_and_exit(!-f $target, 'could build', 'could not build', $target)
968 if $options{'test-build'};
969
18815322
NC
970 skip("could not build $target") unless -f $target;
971
30a13282
NC
972 my $ret = system @ARGV;
973 report_and_exit($ret, 'zero exit from', 'non-zero exit from', "@ARGV");
dd4e46d7
NC
974} elsif (!-f 'config.sh') {
975 # Skip if something went wrong with Configure
976
977 skip('could not build config.sh');
978}
6a8dbfd7 979
05ec8abc
NC
980force_manifest_cleanup($missing, $created_dirs)
981 if $missing;
67382a3b 982
bfa52998
NC
983if($options{'force-regen'}
984 && extract_from_file('Makefile', qr/\bregen_headers\b/)) {
985 # regen_headers was added in e50aee73b3d4c555, patch.1m for perl5.001
986 # It's not worth faking it for earlier revisions.
987 system "make regen_headers </dev/null"
988 and die;
989}
990
bb723266 991patch_C();
f2f0a0ff 992patch_ext();
750ce942
NC
993
994# Parallel build for miniperl is safe
32ffe018 995system "$options{make} $j miniperl </dev/null";
750ce942 996
6c2d645d
NC
997# This is the file we expect make to create
998my $expected_file = $target =~ /^test/ ? 't/perl'
750ce942
NC
999 : $target eq 'Fcntl' ? "lib/auto/Fcntl/Fcntl.$Config{so}"
1000 : $target;
6c2d645d
NC
1001# This is the target we tell make to build in order to get $expected_file
1002my $real_target = $target eq 'Fcntl' ? $expected_file : $target;
750ce942
NC
1003
1004if ($target ne 'miniperl') {
1005 # Nearly all parallel build issues fixed by 5.10.0. Untrustworthy before that.
1006 $j = '' if $major < 10;
1007
1008 if ($real_target eq 'test_prep') {
1009 if ($major < 8) {
1010 # test-prep was added in 5.004_01, 3e3baf6d63945cb6.
1011 # renamed to test_prep in 2001 in 5fe84fd29acaf55c.
1012 # earlier than that, just make test. It will be fast enough.
1013 $real_target = extract_from_file('Makefile.SH',
1014 qr/^(test[-_]prep):/,
1015 'test');
1016 }
1017 }
1018
32ffe018 1019 system "$options{make} $j $real_target </dev/null";
6f8c21fa
NC
1020}
1021
6c2d645d
NC
1022my $expected_file_found = $expected_file =~ /perl$/
1023 ? -x $expected_file : -r $expected_file;
750ce942 1024
63af1e78
NC
1025if ($expected_file_found && $expected_file eq 't/perl') {
1026 # Check that it isn't actually pointing to ../miniperl, which will happen
1027 # if the sanity check ./miniperl -Ilib -MExporter -e '<?>' fails, and
1028 # Makefile tries to run minitest.
1029
1030 # Of course, helpfully sometimes it's called ../perl, other times .././perl
1031 # and who knows if that list is exhaustive...
1032 my ($dev0, $ino0) = stat 't/perl';
1033 my ($dev1, $ino1) = stat 'perl';
1034 unless (defined $dev0 && defined $dev1 && $dev0 == $dev1 && $ino0 == $ino1) {
1035 undef $expected_file_found;
1036 my $link = readlink $expected_file;
1037 warn "'t/perl' => '$link', not 'perl'";
1038 die "Could not realink t/perl: $!" unless defined $link;
1039 }
1040}
1041
750ce942 1042if ($options{'test-build'}) {
6c2d645d 1043 report_and_exit(!$expected_file_found, 'could build', 'could not build',
750ce942 1044 $real_target);
6c2d645d 1045} elsif (!$expected_file_found) {
750ce942 1046 skip("could not build $real_target");
f50dca98
NC
1047}
1048
bf8fb529 1049match_and_exit($real_target, @ARGV) if $match;
750ce942
NC
1050
1051if (defined $options{'one-liner'}) {
1052 my $exe = $target =~ /^(?:perl$|test)/ ? 'perl' : 'miniperl';
fc4401c6 1053 unshift @ARGV, '-e', $options{'one-liner'};
529d2ac2
NC
1054 foreach (qw(c l w)) {
1055 unshift @ARGV, "-$_" if $options{$_};
1056 }
fc4401c6 1057 unshift @ARGV, "./$exe", '-Ilib';
f50dca98
NC
1058}
1059
750ce942
NC
1060# This is what we came here to run:
1061
1062if (exists $Config{ldlibpthname}) {
1063 require Cwd;
1064 my $varname = $Config{ldlibpthname};
1065 my $cwd = Cwd::getcwd();
1066 if (defined $ENV{$varname}) {
1067 $ENV{$varname} = $cwd . $Config{path_sep} . $ENV{$varname};
1068 } else {
1069 $ENV{$varname} = $cwd;
f50dca98 1070 }
750ce942
NC
1071}
1072
1073my $ret = system @ARGV;
1074
1075report_and_exit($ret, 'zero exit from', 'non-zero exit from', "@ARGV");
1076
f2f0a0ff
NC
1077############################################################################
1078#
05ec8abc 1079# Patching, editing and faking routines only below here.
f2f0a0ff
NC
1080#
1081############################################################################
1082
05ec8abc
NC
1083sub fake_noextensions {
1084 edit_file('config.sh', sub {
1085 my @lines = split /\n/, shift;
1086 my @ext = split /\s+/, $defines{noextensions};
1087 foreach (@lines) {
1088 next unless /^extensions=/ || /^dynamic_ext/;
1089 foreach my $ext (@ext) {
1090 s/\b$ext( )?\b/$1/;
1091 }
1092 }
1093 return join "\n", @lines;
1094 });
1095}
1096
1097sub force_manifest {
1098 my (@missing, @created_dirs);
1099 my $fh = open_or_die('MANIFEST');
1100 while (<$fh>) {
1101 next unless /^(\S+)/;
1102 # -d is special case needed (at least) between 27332437a2ed1941 and
1103 # bf3d9ec563d25054^ inclusive, as manifest contains ext/Thread/Thread
1104 push @missing, $1
1105 unless -f $1 || -d $1;
1106 }
1107 close_or_die($fh);
1108
1109 foreach my $pathname (@missing) {
1110 my @parts = split '/', $pathname;
1111 my $leaf = pop @parts;
1112 my $path = '.';
1113 while (@parts) {
1114 $path .= '/' . shift @parts;
1115 next if -d $path;
1116 mkdir $path, 0700 or die "Can't create $path: $!";
1117 unshift @created_dirs, $path;
1118 }
1119 $fh = open_or_die($pathname, '>');
1120 close_or_die($fh);
1121 chmod 0, $pathname or die "Can't chmod 0 $pathname: $!";
1122 }
1123 return \@missing, \@created_dirs;
1124}
1125
1126sub force_manifest_cleanup {
1127 my ($missing, $created_dirs) = @_;
1128 # This is probably way too paranoid:
1129 my @errors;
1130 require Fcntl;
1131 foreach my $file (@$missing) {
1132 my (undef, undef, $mode, undef, undef, undef, undef, $size)
1133 = stat $file;
1134 if (!defined $mode) {
1135 push @errors, "Added file $file has been deleted by Configure";
1136 next;
1137 }
1138 if (Fcntl::S_IMODE($mode) != 0) {
1139 push @errors,
1140 sprintf 'Added file %s had mode changed by Configure to %03o',
1141 $file, $mode;
1142 }
1143 if ($size != 0) {
1144 push @errors,
1145 "Added file $file had sized changed by Configure to $size";
1146 }
1147 unlink $file or die "Can't unlink $file: $!";
1148 }
1149 foreach my $dir (@$created_dirs) {
1150 rmdir $dir or die "Can't rmdir $dir: $!";
1151 }
1152 skip("@errors")
1153 if @errors;
1154}
1155
750ce942
NC
1156sub patch_Configure {
1157 if ($major < 1) {
1158 if (extract_from_file('Configure',
1159 qr/^\t\t\*=\*\) echo "\$1" >> \$optdef;;$/)) {
1160 # This is " Spaces now allowed in -D command line options.",
1161 # part of commit ecfc54246c2a6f42
1162 apply_patch(<<'EOPATCH');
1163diff --git a/Configure b/Configure
1164index 3d3b38d..78ffe16 100755
1165--- a/Configure
1166+++ b/Configure
1167@@ -652,7 +777,8 @@ while test $# -gt 0; do
1168 echo "$me: use '-U symbol=', not '-D symbol='." >&2
1169 echo "$me: ignoring -D $1" >&2
1170 ;;
1171- *=*) echo "$1" >> $optdef;;
1172+ *=*) echo "$1" | \
1173+ sed -e "s/'/'\"'\"'/g" -e "s/=\(.*\)/='\1'/" >> $optdef;;
1174 *) echo "$1='define'" >> $optdef;;
1175 esac
1176 shift
1177EOPATCH
1178 }
1179
1180 if (extract_from_file('Configure', qr/^if \$contains 'd_namlen' \$xinc\b/)) {
1181 # Configure's original simple "grep" for d_namlen falls foul of the
1182 # approach taken by the glibc headers:
1183 # #ifdef _DIRENT_HAVE_D_NAMLEN
1184 # # define _D_EXACT_NAMLEN(d) ((d)->d_namlen)
1185 #
1186 # where _DIRENT_HAVE_D_NAMLEN is not defined on Linux.
1187 # This is also part of commit ecfc54246c2a6f42
1188 apply_patch(<<'EOPATCH');
1189diff --git a/Configure b/Configure
1190index 3d3b38d..78ffe16 100755
1191--- a/Configure
1192+++ b/Configure
1193@@ -3935,7 +4045,8 @@ $rm -f try.c
1194
1195 : see if the directory entry stores field length
1196 echo " "
1197-if $contains 'd_namlen' $xinc >/dev/null 2>&1; then
1198+$cppstdin $cppflags $cppminus < "$xinc" > try.c
1199+if $contains 'd_namlen' try.c >/dev/null 2>&1; then
1200 echo "Good, your directory entry keeps length information in d_namlen." >&4
1201 val="$define"
1202 else
1203EOPATCH
1204 }
f50dca98 1205 }
750ce942
NC
1206
1207 if ($major < 2
1208 && !extract_from_file('Configure',
1209 qr/Try to guess additional flags to pick up local libraries/)) {
1210 my $mips = extract_from_file('Configure',
1211 qr!(''\) if (?:\./)?mips; then)!);
1212 # This is part of perl-5.001n. It's needed, to add -L/usr/local/lib to
1213 # theld flags if libraries are found there. It shifts the code to set up
1214 # libpth earlier, and then adds the code to add libpth entries to
1215 # ldflags
1216 # mips was changed to ./mips in ecfc54246c2a6f42, perl5.000 patch.0g
1217 apply_patch(sprintf <<'EOPATCH', $mips);
1218diff --git a/Configure b/Configure
1219index 53649d5..0635a6e 100755
1220--- a/Configure
1221+++ b/Configure
1222@@ -2749,6 +2749,52 @@ EOM
1223 ;;
1224 esac
f50dca98 1225
750ce942
NC
1226+: Set private lib path
1227+case "$plibpth" in
1228+'') if ./mips; then
1229+ plibpth="$incpath/usr/lib /usr/local/lib /usr/ccs/lib"
1230+ fi;;
1231+esac
1232+case "$libpth" in
1233+' ') dlist='';;
1234+'') dlist="$plibpth $glibpth";;
1235+*) dlist="$libpth";;
1236+esac
1237+
1238+: Now check and see which directories actually exist, avoiding duplicates
1239+libpth=''
1240+for xxx in $dlist
1241+do
1242+ if $test -d $xxx; then
1243+ case " $libpth " in
1244+ *" $xxx "*) ;;
1245+ *) libpth="$libpth $xxx";;
1246+ esac
1247+ fi
1248+done
1249+$cat <<'EOM'
1250+
1251+Some systems have incompatible or broken versions of libraries. Among
1252+the directories listed in the question below, please remove any you
1253+know not to be holding relevant libraries, and add any that are needed.
1254+Say "none" for none.
1255+
1256+EOM
1257+case "$libpth" in
1258+'') dflt='none';;
1259+*)
1260+ set X $libpth
1261+ shift
1262+ dflt=${1+"$@"}
1263+ ;;
1264+esac
1265+rp="Directories to use for library searches?"
1266+. ./myread
1267+case "$ans" in
1268+none) libpth=' ';;
1269+*) libpth="$ans";;
1270+esac
1271+
1272 : flags used in final linking phase
1273 case "$ldflags" in
1274 '') if ./venix; then
1275@@ -2765,6 +2811,23 @@ case "$ldflags" in
1276 ;;
1277 *) dflt="$ldflags";;
1278 esac
1279+
1280+: Possible local library directories to search.
1281+loclibpth="/usr/local/lib /opt/local/lib /usr/gnu/lib"
1282+loclibpth="$loclibpth /opt/gnu/lib /usr/GNU/lib /opt/GNU/lib"
1283+
1284+: Try to guess additional flags to pick up local libraries.
1285+for thislibdir in $libpth; do
1286+ case " $loclibpth " in
1287+ *" $thislibdir "*)
1288+ case "$dflt " in
1289+ "-L$thislibdir ") ;;
1290+ *) dflt="$dflt -L$thislibdir" ;;
1291+ esac
1292+ ;;
1293+ esac
1294+done
1295+
1296 echo " "
1297 rp="Any additional ld flags (NOT including libraries)?"
1298 . ./myread
1299@@ -2828,52 +2891,6 @@ n) echo "OK, that should do.";;
1300 esac
1301 $rm -f try try.* core
1302
1303-: Set private lib path
1304-case "$plibpth" in
1305-%s
1306- plibpth="$incpath/usr/lib /usr/local/lib /usr/ccs/lib"
1307- fi;;
1308-esac
1309-case "$libpth" in
1310-' ') dlist='';;
1311-'') dlist="$plibpth $glibpth";;
1312-*) dlist="$libpth";;
1313-esac
1314-
1315-: Now check and see which directories actually exist, avoiding duplicates
1316-libpth=''
1317-for xxx in $dlist
1318-do
1319- if $test -d $xxx; then
1320- case " $libpth " in
1321- *" $xxx "*) ;;
1322- *) libpth="$libpth $xxx";;
1323- esac
1324- fi
1325-done
1326-$cat <<'EOM'
f50dca98 1327-
750ce942
NC
1328-Some systems have incompatible or broken versions of libraries. Among
1329-the directories listed in the question below, please remove any you
1330-know not to be holding relevant libraries, and add any that are needed.
1331-Say "none" for none.
1332-
1333-EOM
1334-case "$libpth" in
1335-'') dflt='none';;
1336-*)
1337- set X $libpth
1338- shift
1339- dflt=${1+"$@"}
1340- ;;
1341-esac
1342-rp="Directories to use for library searches?"
1343-. ./myread
1344-case "$ans" in
1345-none) libpth=' ';;
1346-*) libpth="$ans";;
1347-esac
1348-
1349 : compute shared library extension
1350 case "$so" in
1351 '')
f50dca98
NC
1352EOPATCH
1353 }
686af304 1354
750ce942
NC
1355 if ($major < 5 && extract_from_file('Configure',
1356 qr!if \$cc \$ccflags try\.c -o try >/dev/null 2>&1; then!)) {
1357 # Analogous to the more general fix of dfe9444ca7881e71
1358 # Without this flags such as -m64 may not be passed to this compile,
1359 # which results in a byteorder of '1234' instead of '12345678', which
1360 # can then cause crashes.
686af304 1361
750ce942
NC
1362 if (extract_from_file('Configure', qr/xxx_prompt=y/)) {
1363 # 8e07c86ebc651fe9 or later
1364 # ("This is my patch patch.1n for perl5.001.")
1365 apply_patch(<<'EOPATCH');
1366diff --git a/Configure b/Configure
1367index 62249dd..c5c384e 100755
1368--- a/Configure
1369+++ b/Configure
1370@@ -8247,7 +8247,7 @@ main()
1371 }
1372 EOCP
1373 xxx_prompt=y
1374- if $cc $ccflags try.c -o try >/dev/null 2>&1 && ./try > /dev/null; then
1375+ if $cc $ccflags $ldflags try.c -o try >/dev/null 2>&1 && ./try > /dev/null; then
1376 dflt=`./try`
1377 case "$dflt" in
1378 [1-4][1-4][1-4][1-4]|12345678|87654321)
1379EOPATCH
1380 } else {
1381 apply_patch(<<'EOPATCH');
1382diff --git a/Configure b/Configure
1383index 53649d5..f1cd64a 100755
1384--- a/Configure
1385+++ b/Configure
1386@@ -6362,7 +6362,7 @@ main()
1387 printf("\n");
1388 }
1389 EOCP
1390- if $cc $ccflags try.c -o try >/dev/null 2>&1 ; then
1391+ if $cc $ccflags $ldflags try.c -o try >/dev/null 2>&1 ; then
1392 dflt=`./try`
1393 case "$dflt" in
1394 ????|????????) echo "(The test program ran ok.)";;
1395EOPATCH
1396 }
1397 }
9a999a97 1398
750ce942
NC
1399 if ($major < 6 && !extract_from_file('Configure',
1400 qr!^\t-A\)$!)) {
1401 # This adds the -A option to Configure, which is incredibly useful
1402 # Effectively this is commits 02e93a22d20fc9a5, 5f83a3e9d818c3ad,
1403 # bde6b06b2c493fef, f7c3111703e46e0c and 2 lines of trailing whitespace
1404 # removed by 613d6c3e99b9decc, but applied at slightly different
1405 # locations to ensure a clean patch back to 5.000
1406 # Note, if considering patching to the intermediate revisions to fix
1407 # bugs in -A handling, f7c3111703e46e0c is from 2002, and hence
1408 # $major == 8
1409
1410 # To add to the fun, early patches add -K and -O options, and it's not
1411 # trivial to get patch to put the C<. ./posthint.sh> in the right place
1412 edit_file('Configure', sub {
1413 my $code = shift;
1414 $code =~ s/(optstr = ")([^"]+";\s*# getopt-style specification)/$1A:$2/
1415 or die "Substitution failed";
1416 $code =~ s!^(: who configured the system)!
1417touch posthint.sh
1418. ./posthint.sh
2526f4b8 1419
750ce942
NC
1420$1!ms
1421 or die "Substitution failed";
1422 return $code;
1423 });
1424 apply_patch(<<'EOPATCH');
1425diff --git a/Configure b/Configure
1426index 4b55fa6..60c3c64 100755
1427--- a/Configure
1428+++ b/Configure
1429@@ -1150,6 +1150,7 @@ set X `for arg in "$@"; do echo "X$arg"; done |
1430 eval "set $*"
1431 shift
1432 rm -f options.awk
1433+rm -f posthint.sh
1434
1435 : set up default values
1436 fastread=''
1437@@ -1172,6 +1173,56 @@ while test $# -gt 0; do
1438 case "$1" in
1439 -d) shift; fastread=yes;;
1440 -e) shift; alldone=cont;;
1441+ -A)
1442+ shift
1443+ xxx=''
1444+ yyy="$1"
1445+ zzz=''
1446+ uuu=undef
1447+ case "$yyy" in
1448+ *=*) zzz=`echo "$yyy"|sed 's!=.*!!'`
1449+ case "$zzz" in
1450+ *:*) zzz='' ;;
1451+ *) xxx=append
1452+ zzz=" "`echo "$yyy"|sed 's!^[^=]*=!!'`
1453+ yyy=`echo "$yyy"|sed 's!=.*!!'` ;;
1454+ esac
1455+ ;;
1456+ esac
1457+ case "$xxx" in
1458+ '') case "$yyy" in
1459+ *:*) xxx=`echo "$yyy"|sed 's!:.*!!'`
1460+ yyy=`echo "$yyy"|sed 's!^[^:]*:!!'`
1461+ zzz=`echo "$yyy"|sed 's!^[^=]*=!!'`
1462+ yyy=`echo "$yyy"|sed 's!=.*!!'` ;;
1463+ *) xxx=`echo "$yyy"|sed 's!:.*!!'`
1464+ yyy=`echo "$yyy"|sed 's!^[^:]*:!!'` ;;
1465+ esac
1466+ ;;
1467+ esac
1468+ case "$xxx" in
1469+ append)
1470+ echo "$yyy=\"\${$yyy}$zzz\"" >> posthint.sh ;;
1471+ clear)
1472+ echo "$yyy=''" >> posthint.sh ;;
1473+ define)
1474+ case "$zzz" in
1475+ '') zzz=define ;;
1476+ esac
1477+ echo "$yyy='$zzz'" >> posthint.sh ;;
1478+ eval)
1479+ echo "eval \"$yyy=$zzz\"" >> posthint.sh ;;
1480+ prepend)
1481+ echo "$yyy=\"$zzz\${$yyy}\"" >> posthint.sh ;;
1482+ undef)
1483+ case "$zzz" in
1484+ '') zzz="$uuu" ;;
1485+ esac
1486+ echo "$yyy=$zzz" >> posthint.sh ;;
1487+ *) echo "$me: unknown -A command '$xxx', ignoring -A $1" >&2 ;;
1488+ esac
1489+ shift
1490+ ;;
1491 -f)
1492 shift
1493 cd ..
1494EOPATCH
1495 }
9a999a97 1496
d1ac19b7
NC
1497 if ($major < 8 && $^O eq 'aix') {
1498 edit_file('Configure', sub {
1499 my $code = shift;
1500 # Replicate commit a8c676c69574838b
1501 # Whitespace allowed at the ends of /lib/syscalls.exp lines
1502 # and half of commit c6912327ae30e6de
1503 # AIX syscalls.exp scan: the syscall might be marked 32, 3264, or 64
1504 $code =~ s{(\bsed\b.*\bsyscall)(?:\[0-9\]\*)?(\$.*/lib/syscalls\.exp)}
1505 {$1 . "[0-9]*[ \t]*" . $2}e;
1506 return $code;
1507 });
1508 }
1509
750ce942
NC
1510 if ($major < 8 && !extract_from_file('Configure',
1511 qr/^\t\tif test ! -t 0; then$/)) {
1512 # Before dfe9444ca7881e71, Configure would refuse to run if stdin was
1513 # not a tty. With that commit, the tty requirement was dropped for -de
1514 # and -dE
1515 # Commit aaeb8e512e8e9e14 dropped the tty requirement for -S
1516 # For those older versions, it's probably easiest if we simply remove
1517 # the sanity test.
1518 edit_file('Configure', sub {
1519 my $code = shift;
1520 $code =~ s/test ! -t 0/test Perl = rules/;
1521 return $code;
1522 });
6a8dbfd7 1523 }
6a8dbfd7 1524
750ce942
NC
1525 if ($major == 8 || $major == 9) {
1526 # Fix symbol detection to that of commit 373dfab3839ca168 if it's any
1527 # intermediate version 5129fff43c4fe08c or later, as the intermediate
1528 # versions don't work correctly on (at least) Sparc Linux.
1529 # 5129fff43c4fe08c adds the first mention of mistrustnm.
1530 # 373dfab3839ca168 removes the last mention of lc=""
1531 edit_file('Configure', sub {
1532 my $code = shift;
1533 return $code
1534 if $code !~ /\btc="";/; # 373dfab3839ca168 or later
1535 return $code
1536 if $code !~ /\bmistrustnm\b/; # before 5129fff43c4fe08c
1537 my $fixed = <<'EOC';
6a8dbfd7 1538
750ce942
NC
1539: is a C symbol defined?
1540csym='tlook=$1;
1541case "$3" in
1542-v) tf=libc.tmp; tdc="";;
1543-a) tf=libc.tmp; tdc="[]";;
1544*) tlook="^$1\$"; tf=libc.list; tdc="()";;
1545esac;
1546tx=yes;
1547case "$reuseval-$4" in
1548true-) ;;
1549true-*) tx=no; eval "tval=\$$4"; case "$tval" in "") tx=yes;; esac;;
1550esac;
1551case "$tx" in
1552yes)
1553 tval=false;
1554 if $test "$runnm" = true; then
1555 if $contains $tlook $tf >/dev/null 2>&1; then
1556 tval=true;
1557 elif $test "$mistrustnm" = compile -o "$mistrustnm" = run; then
1558 echo "void *(*(p()))$tdc { extern void *$1$tdc; return &$1; } int main() { if(p()) return(0); else return(1); }"> try.c;
1559 $cc -o try $optimize $ccflags $ldflags try.c >/dev/null 2>&1 $libs && tval=true;
1560 $test "$mistrustnm" = run -a -x try && { $run ./try$_exe >/dev/null 2>&1 || tval=false; };
1561 $rm -f try$_exe try.c core core.* try.core;
1562 fi;
1563 else
1564 echo "void *(*(p()))$tdc { extern void *$1$tdc; return &$1; } int main() { if(p()) return(0); else return(1); }"> try.c;
1565 $cc -o try $optimize $ccflags $ldflags try.c $libs >/dev/null 2>&1 && tval=true;
1566 $rm -f try$_exe try.c;
1567 fi;
1568 ;;
1569*)
1570 case "$tval" in
1571 $define) tval=true;;
1572 *) tval=false;;
1573 esac;
1574 ;;
1575esac;
1576eval "$2=$tval"'
67382a3b 1577
750ce942
NC
1578EOC
1579 $code =~ s/\n: is a C symbol defined\?\n.*?\neval "\$2=\$tval"'\n\n/$fixed/sm
1580 or die "substitution failed";
1581 return $code;
1582 });
1583 }
1584
1585 if ($major < 10
1586 && extract_from_file('Configure', qr/^set malloc\.h i_malloc$/)) {
1587 # This is commit 01d07975f7ef0e7d, trimmed, with $compile inlined as
1588 # prior to bd9b35c97ad661cc Configure had the malloc.h test before the
1589 # definition of $compile.
1590 apply_patch(<<'EOPATCH');
1591diff --git a/Configure b/Configure
1592index 3d2e8b9..6ce7766 100755
1593--- a/Configure
1594+++ b/Configure
1595@@ -6743,5 +6743,22 @@ set d_dosuid
1596
1597 : see if this is a malloc.h system
1598-set malloc.h i_malloc
1599-eval $inhdr
1600+: we want a real compile instead of Inhdr because some systems have a
1601+: malloc.h that just gives a compile error saying to use stdlib.h instead
1602+echo " "
1603+$cat >try.c <<EOCP
1604+#include <stdlib.h>
1605+#include <malloc.h>
1606+int main () { return 0; }
1607+EOCP
1608+set try
1609+if $cc $optimize $ccflags $ldflags -o try $* try.c $libs > /dev/null 2>&1; then
1610+ echo "<malloc.h> found." >&4
1611+ val="$define"
1612+else
1613+ echo "<malloc.h> NOT found." >&4
1614+ val="$undef"
1615+fi
1616+$rm -f try.c try
1617+set i_malloc
1618+eval $setvar
1619
1620EOPATCH
1621 }
67382a3b 1622}
6a8dbfd7 1623
750ce942
NC
1624sub patch_hints {
1625 if ($^O eq 'freebsd') {
1626 # There are rather too many version-specific FreeBSD hints fixes to
1627 # patch individually. Also, more than once the FreeBSD hints file has
1628 # been written in what turned out to be a rather non-future-proof style,
1629 # with case statements treating the most recent version as the
1630 # exception, instead of treating previous versions' behaviour explicitly
1631 # and changing the default to cater for the current behaviour. (As
1632 # strangely, future versions inherit the current behaviour.)
1633 checkout_file('hints/freebsd.sh');
1634 } elsif ($^O eq 'darwin') {
1635 if ($major < 8) {
1636 # We can't build on darwin without some of the data in the hints
1637 # file. Probably less surprising to use the earliest version of
1638 # hints/darwin.sh and then edit in place just below, than use
1639 # blead's version, as that would create a discontinuity at
1640 # f556e5b971932902 - before it, hints bugs would be "fixed", after
1641 # it they'd resurface. This way, we should give the illusion of
1642 # monotonic bug fixing.
1643 my $faking_it;
1644 if (!-f 'hints/darwin.sh') {
1645 checkout_file('hints/darwin.sh', 'f556e5b971932902');
1646 ++$faking_it;
1647 }
0afef97d 1648
750ce942
NC
1649 edit_file('hints/darwin.sh', sub {
1650 my $code = shift;
1651 # Part of commit 8f4f83badb7d1ba9, which mostly undoes
1652 # commit 0511a818910f476c.
1653 $code =~ s/^cppflags='-traditional-cpp';$/cppflags="\${cppflags} -no-cpp-precomp"/m;
1654 # commit 14c11978e9b52e08/803bb6cc74d36a3f
1655 # Without this, code in libperl.bundle links against op.o
1656 # in preference to opmini.o on the linker command line,
1657 # and hence miniperl tries to use File::Glob instead of
1658 # csh
1659 $code =~ s/^(lddlflags=)/ldflags="\${ldflags} -flat_namespace"\n$1/m;
1660 # f556e5b971932902 also patches Makefile.SH with some
1661 # special case code to deal with useshrplib for darwin.
1662 # Given that post 5.8.0 the darwin hints default was
1663 # changed to false, and it would be very complex to splice
1664 # in that code in various versions of Makefile.SH back
1665 # to 5.002, lets just turn it off.
1666 $code =~ s/^useshrplib='true'/useshrplib='false'/m
1667 if $faking_it;
1f1c8096
NC
1668
1669 # Part of commit d235852b65d51c44
1670 # Don't do this on a case sensitive HFS+ partition, as it
1671 # breaks the build for 5.003 and earlier.
1672 if ($case_insensitive
1673 && $code !~ /^firstmakefile=GNUmakefile/) {
1674 $code .= "\nfirstmakefile=GNUmakefile;\n";
1675 }
1676
750ce942
NC
1677 return $code;
1678 });
1679 }
1680 } elsif ($^O eq 'netbsd') {
1681 if ($major < 6) {
1682 # These are part of commit 099685bc64c7dbce
1683 edit_file('hints/netbsd.sh', sub {
1684 my $code = shift;
1685 my $fixed = <<'EOC';
1686case "$osvers" in
16870.9|0.8*)
1688 usedl="$undef"
1689 ;;
1690*)
1691 if [ -f /usr/libexec/ld.elf_so ]; then
1692 d_dlopen=$define
1693 d_dlerror=$define
1694 ccdlflags="-Wl,-E -Wl,-R${PREFIX}/lib $ccdlflags"
1695 cccdlflags="-DPIC -fPIC $cccdlflags"
1696 lddlflags="--whole-archive -shared $lddlflags"
1697 elif [ "`uname -m`" = "pmax" ]; then
9f1d18fe 1698# NetBSD 1.3 and 1.3.1 on pmax shipped an 'old' ld.so, which will not work.
750ce942
NC
1699 d_dlopen=$undef
1700 elif [ -f /usr/libexec/ld.so ]; then
1701 d_dlopen=$define
1702 d_dlerror=$define
1703 ccdlflags="-Wl,-R${PREFIX}/lib $ccdlflags"
1704# we use -fPIC here because -fpic is *NOT* enough for some of the
1705# extensions like Tk on some netbsd platforms (the sparc is one)
1706 cccdlflags="-DPIC -fPIC $cccdlflags"
1707 lddlflags="-Bforcearchive -Bshareable $lddlflags"
1708 else
1709 d_dlopen=$undef
1710 fi
1711 ;;
1712esac
1713EOC
1714 $code =~ s/^case "\$osvers" in\n0\.9\|0\.8.*?^esac\n/$fixed/ms;
1715 return $code;
1716 });
1717 }
1718 } elsif ($^O eq 'openbsd') {
1719 if ($major < 8) {
1720 checkout_file('hints/openbsd.sh', '43051805d53a3e4c')
1721 unless -f 'hints/openbsd.sh';
1722 my $which = extract_from_file('hints/openbsd.sh',
1723 qr/# from (2\.8|3\.1) onwards/,
1724 '');
1725 if ($which eq '') {
1726 my $was = extract_from_file('hints/openbsd.sh',
1727 qr/(lddlflags="(?:-Bforcearchive )?-Bshareable)/);
1728 # This is commit 154d43cbcf57271c and parts of 5c75dbfa77b0949c
1729 # and 29b5585702e5e025
1730 apply_patch(sprintf <<'EOPATCH', $was);
1731diff --git a/hints/openbsd.sh b/hints/openbsd.sh
1732index a7d8bf2..5b79709 100644
1733--- a/hints/openbsd.sh
1734+++ b/hints/openbsd.sh
1735@@ -37,7 +37,25 @@ OpenBSD.alpha|OpenBSD.mips|OpenBSD.powerpc|OpenBSD.vax)
1736 # we use -fPIC here because -fpic is *NOT* enough for some of the
1737 # extensions like Tk on some OpenBSD platforms (ie: sparc)
1738 cccdlflags="-DPIC -fPIC $cccdlflags"
1739- %s $lddlflags"
1740+ case "$osvers" in
1741+ [01].*|2.[0-7]|2.[0-7].*)
1742+ lddlflags="-Bshareable $lddlflags"
1743+ ;;
1744+ 2.[8-9]|3.0)
1745+ ld=${cc:-cc}
1746+ lddlflags="-shared -fPIC $lddlflags"
1747+ ;;
1748+ *) # from 3.1 onwards
1749+ ld=${cc:-cc}
1750+ lddlflags="-shared -fPIC $lddlflags"
1751+ libswanted=`echo $libswanted | sed 's/ dl / /'`
1752+ ;;
1753+ esac
1754+
1755+ # We need to force ld to export symbols on ELF platforms.
1756+ # Without this, dlopen() is crippled.
1757+ ELF=`${cc:-cc} -dM -E - </dev/null | grep __ELF__`
1758+ test -n "$ELF" && ldflags="-Wl,-E $ldflags"
1759 ;;
1760 esac
1761
1762EOPATCH
1763 } elsif ($which eq '2.8') {
1764 # This is parts of 5c75dbfa77b0949c and 29b5585702e5e025, and
1765 # possibly eb9cd59d45ad2908
1766 my $was = extract_from_file('hints/openbsd.sh',
1767 qr/lddlflags="(-shared(?: -fPIC)?) \$lddlflags"/);
0afef97d 1768
750ce942
NC
1769 apply_patch(sprintf <<'EOPATCH', $was);
1770--- a/hints/openbsd.sh 2011-10-21 17:25:20.000000000 +0200
1771+++ b/hints/openbsd.sh 2011-10-21 16:58:43.000000000 +0200
1772@@ -44,11 +44,21 @@
1773 [01].*|2.[0-7]|2.[0-7].*)
1774 lddlflags="-Bshareable $lddlflags"
1775 ;;
1776- *) # from 2.8 onwards
1777+ 2.[8-9]|3.0)
1778 ld=${cc:-cc}
1779- lddlflags="%s $lddlflags"
1780+ lddlflags="-shared -fPIC $lddlflags"
1781+ ;;
1782+ *) # from 3.1 onwards
1783+ ld=${cc:-cc}
1784+ lddlflags="-shared -fPIC $lddlflags"
1785+ libswanted=`echo $libswanted | sed 's/ dl / /'`
1786 ;;
1787 esac
1788+
1789+ # We need to force ld to export symbols on ELF platforms.
1790+ # Without this, dlopen() is crippled.
1791+ ELF=`${cc:-cc} -dM -E - </dev/null | grep __ELF__`
1792+ test -n "$ELF" && ldflags="-Wl,-E $ldflags"
1793 ;;
1794 esac
1795
1796EOPATCH
1797 } elsif ($which eq '3.1'
1798 && !extract_from_file('hints/openbsd.sh',
1799 qr/We need to force ld to export symbols on ELF platforms/)) {
1800 # This is part of 29b5585702e5e025
1801 apply_patch(<<'EOPATCH');
1802diff --git a/hints/openbsd.sh b/hints/openbsd.sh
1803index c6b6bc9..4839d04 100644
1804--- a/hints/openbsd.sh
1805+++ b/hints/openbsd.sh
1806@@ -54,6 +54,11 @@ alpha-2.[0-8]|mips-*|vax-*|powerpc-2.[0-7]|m88k-*)
1807 libswanted=`echo $libswanted | sed 's/ dl / /'`
1808 ;;
1809 esac
1810+
1811+ # We need to force ld to export symbols on ELF platforms.
1812+ # Without this, dlopen() is crippled.
1813+ ELF=`${cc:-cc} -dM -E - </dev/null | grep __ELF__`
1814+ test -n "$ELF" && ldflags="-Wl,-E $ldflags"
1815 ;;
1816 esac
1817
1818EOPATCH
1819 }
1820 }
1821 } elsif ($^O eq 'linux') {
1822 if ($major < 1) {
1823 # sparc linux seems to need the -Dbool=char -DHAS_BOOL part of
1824 # perl5.000 patch.0n: [address Configure and build issues]
1825 edit_file('hints/linux.sh', sub {
1826 my $code = shift;
1827 $code =~ s!-I/usr/include/bsd!-Dbool=char -DHAS_BOOL!g;
1828 return $code;
1829 });
1830 }
915f531b 1831
750ce942
NC
1832 if ($major <= 9) {
1833 if (`uname -sm` =~ qr/^Linux sparc/) {
1834 if (extract_from_file('hints/linux.sh', qr/sparc-linux/)) {
1835 # Be sure to use -fPIC not -fpic on Linux/SPARC
1836 apply_commit('f6527d0ef0c13ad4');
1837 } elsif(!extract_from_file('hints/linux.sh',
1838 qr/^sparc-linux\)$/)) {
1839 my $fh = open_or_die('hints/linux.sh', '>>');
1840 print $fh <<'EOT' or die $!;
1841
1842case "`uname -m`" in
1843sparc*)
1844 case "$cccdlflags" in
1845 *-fpic*) cccdlflags="`echo $cccdlflags|sed 's/-fpic/-fPIC/'`" ;;
1846 *) cccdlflags="$cccdlflags -fPIC" ;;
1847 esac
1848 ;;
1849esac
1850EOT
1851 close_or_die($fh);
1852 }
1853 }
1854 }
915f531b
NC
1855 }
1856}
1857
bb723266
NC
1858sub patch_SH {
1859 # Cwd.xs added in commit 0d2079faa739aaa9. Cwd.pm moved to ext/ 8 years
1860 # later in commit 403f501d5b37ebf0
1861 if ($major > 0 && <*/Cwd/Cwd.xs>) {
1862 if ($major < 10
1863 && !extract_from_file('Makefile.SH', qr/^extra_dep=''$/)) {
1864 # The Makefile.PL for Unicode::Normalize needs
1865 # lib/unicore/CombiningClass.pl. Even without a parallel build, we
1866 # need a dependency to ensure that it builds. This is a variant of
1867 # commit 9f3ef600c170f61e. Putting this for earlier versions gives
1868 # us a spot on which to hang the edits below
1869 apply_patch(<<'EOPATCH');
1870diff --git a/Makefile.SH b/Makefile.SH
1871index f61d0db..6097954 100644
1872--- a/Makefile.SH
1873+++ b/Makefile.SH
1874@@ -155,10 +155,20 @@ esac
1875
1876 : Prepare dependency lists for Makefile.
1877 dynamic_list=' '
1878+extra_dep=''
1879 for f in $dynamic_ext; do
1880 : the dependency named here will never exist
1881 base=`echo "$f" | sed 's/.*\///'`
1882- dynamic_list="$dynamic_list lib/auto/$f/$base.$dlext"
1883+ this_target="lib/auto/$f/$base.$dlext"
1884+ dynamic_list="$dynamic_list $this_target"
1885+
1886+ : Parallel makes reveal that we have some interdependencies
1887+ case $f in
1888+ Math/BigInt/FastCalc) extra_dep="$extra_dep
1889+$this_target: lib/auto/List/Util/Util.$dlext" ;;
1890+ Unicode/Normalize) extra_dep="$extra_dep
1891+$this_target: lib/unicore/CombiningClass.pl" ;;
1892+ esac
1893 done
1894
1895 static_list=' '
1896@@ -987,2 +997,9 @@ n_dummy $(nonxs_ext): miniperl$(EXE_EXT) preplibrary $(DYNALOADER) FORCE
1897 @$(LDLIBPTH) sh ext/util/make_ext nonxs $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL)
1898+!NO!SUBS!
1899+
1900+$spitshell >>Makefile <<EOF
1901+$extra_dep
1902+EOF
1903+
1904+$spitshell >>Makefile <<'!NO!SUBS!'
1905
1906EOPATCH
1907 }
c0960282
NC
1908
1909 if ($major == 11) {
1910 if (extract_from_file('patchlevel.h',
1911 qr/^#include "unpushed\.h"/)) {
1912 # I had thought it easier to detect when building one of the 52
1913 # commits with the original method of incorporating the git
1914 # revision and drop parallel make flags. Commits shown by
1915 # git log 46807d8e809cc127^..dcff826f70bf3f64^ ^d4fb0a1f15d1a1c4
1916 # However, it's not actually possible to make miniperl for that
1917 # configuration as-is, because the file .patchnum is only made
1918 # as a side effect of target 'all'
1919 # I also don't think that it's "safe" to simply run
1920 # make_patchnum.sh before the build. We need the proper
1921 # dependency rules in the Makefile to *stop* it being run again
1922 # at the wrong time.
1923 # This range is important because contains the commit that
1924 # merges Schwern's y2038 work.
1925 apply_patch(<<'EOPATCH');
1926diff --git a/Makefile.SH b/Makefile.SH
1927index 9ad8b6f..106e721 100644
1928--- a/Makefile.SH
1929+++ b/Makefile.SH
1930@@ -540,9 +544,14 @@ sperl.i: perl.c $(h)
1931
1932 .PHONY: all translators utilities make_patchnum
1933
1934-make_patchnum:
1935+make_patchnum: lib/Config_git.pl
1936+
1937+lib/Config_git.pl: make_patchnum.sh
1938 sh $(shellflags) make_patchnum.sh
1939
1940+# .patchnum, unpushed.h and lib/Config_git.pl are built by make_patchnum.sh
1941+unpushed.h .patchnum: lib/Config_git.pl
1942+
1943 # make sure that we recompile perl.c if .patchnum changes
1944 perl$(OBJ_EXT): .patchnum unpushed.h
1945
1946EOPATCH
1947 } elsif (-f '.gitignore'
1948 && extract_from_file('.gitignore', qr/^\.patchnum$/)) {
1949 # 8565263ab8a47cda to 46807d8e809cc127^ inclusive.
1950 edit_file('Makefile.SH', sub {
1951 my $code = shift;
1952 $code =~ s/^make_patchnum:\n/make_patchnum: .patchnum
1953
1954.sha1: .patchnum
1955
1956.patchnum: make_patchnum.sh
1957/m;
1958 return $code;
1959 });
74adbdfa
NC
1960 } elsif (-f 'lib/.gitignore'
1961 && extract_from_file('lib/.gitignore',
1962 qr!^/Config_git.pl!)
1963 && !extract_from_file('Makefile.SH',
1964 qr/^uudmap\.h.*:bitcount.h$/)) {
1965 # Between commits and dcff826f70bf3f64 and 0f13ebd5d71f8177^
1966 edit_file('Makefile.SH', sub {
1967 my $code = shift;
1968 # Bug introduced by 344af494c35a9f0f
1969 # fixed in 0f13ebd5d71f8177
1970 $code =~ s{^(pod/perlapi\.pod) (pod/perlintern\.pod): }
1971 {$1: $2\n\n$2: }m;
1972 # Bug introduced by efa50c51e3301a2c
1973 # fixed in 0f13ebd5d71f8177
1974 $code =~ s{^(uudmap\.h) (bitcount\.h): }
1975 {$1: $2\n\n$2: }m;
93a0b6a3
NC
1976
1977 # The rats nest of getting git_version.h correct
1978
1979 if ($code =~ s{git_version\.h: stock_git_version\.h
1980\tcp stock_git_version\.h git_version\.h}
1981 {}m) {
1982 # before 486cd780047ff224
1983
1984 # We probably can't build between
1985 # 953f6acfa20ec275^ and 8565263ab8a47cda
1986 # inclusive, but all commits in that range
1987 # relate to getting make_patchnum.sh working,
1988 # so it is extremely unlikely to be an
1989 # interesting bisect target. They will skip.
1990
1991 # No, don't spawn a submake if
1992 # make_patchnum.sh or make_patchnum.pl fails
1993 $code =~ s{\|\| \$\(MAKE\) miniperl.*}
1994 {}m;
1995 $code =~ s{^\t(sh.*make_patchnum\.sh.*)}
1996 {\t-$1}m;
1997
1998 # Use an external perl to run make_patchnum.pl
1999 # because miniperl still depends on
2000 # git_version.h
2001 $code =~ s{^\t.*make_patchnum\.pl}
2002 {\t-$^X make_patchnum.pl}m;
2003
2004
2005 # "Truth in advertising" - running
2006 # make_patchnum generates 2 files.
2007 $code =~ s{^make_patchnum:.*}{
2008make_patchnum: lib/Config_git.pl
2009
2010git_version.h: lib/Config_git.pl
2011
2012perlmini\$(OBJ_EXT): git_version.h
2013
2014lib/Config_git.pl:}m;
2015 }
356fb8dd
NC
2016 # Right, now we've corrected Makefile.SH to
2017 # correctly describe how lib/Config_git.pl and
2018 # git_version.h are made, we need to fix the rest
2019
2020 # This emulates commit 2b63e250843b907e
2021 # This might duplicate the rule stating that
2022 # git_version.h depends on lib/Config_git.pl
2023 # This is harmless.
2024 $code =~ s{^(?:lib/Config_git\.pl )?git_version\.h: (.* make_patchnum\.pl.*)}
2025 {git_version.h: lib/Config_git.pl
2026
2027lib/Config_git.pl: $1}m;
2028
97897675
NC
2029 # This emulates commits 0f13ebd5d71f8177 and
2030 # and a04d4598adc57886. It ensures that
2031 # lib/Config_git.pl is built before configpm,
2032 # and that configpm is run exactly once.
2033 $code =~ s{^(\$\(.*?\) )?(\$\(CONFIGPOD\))(: .*? configpm Porting/Glossary)( lib/Config_git\.pl)?}{
2034 # If present, other files depend on $(CONFIGPOD)
2035 ($1 ? "$1: $2\n\n" : '')
2036 # Then the rule we found
2037 . $2 . $3
2038 # Add dependency if not there
2039 . ($4 ? $4 : ' lib/Config_git.pl')
2040 }me;
2041
74adbdfa
NC
2042 return $code;
2043 });
c0960282
NC
2044 }
2045 }
2046
bb723266
NC
2047 if ($major < 14) {
2048 # Commits dc0655f797469c47 and d11a62fe01f2ecb2
2049 edit_file('Makefile.SH', sub {
2050 my $code = shift;
2051 foreach my $ext (qw(Encode SDBM_File)) {
2052 next if $code =~ /\b$ext\) extra_dep=/s;
2053 $code =~ s!(\) extra_dep="\$extra_dep
2054\$this_target: .*?" ;;)
2055( esac
2056)!$1
2057 $ext) extra_dep="\$extra_dep
2058\$this_target: lib/auto/Cwd/Cwd.\$dlext" ;;
2059$2!;
2060 }
2061 return $code;
2062 });
2063 }
2064 }
2065
2066 if ($major == 7) {
2067 # Remove commits 9fec149bb652b6e9 and 5bab1179608f81d8, which add/amend
2068 # rules to automatically run regen scripts that rebuild C headers. These
2069 # cause problems because a git checkout doesn't preserve relative file
2070 # modification times, hence the regen scripts may fire. This will
2071 # obscure whether the repository had the correct generated headers
2072 # checked in.
2073 # Also, the dependency rules for running the scripts were not correct,
2074 # which could cause spurious re-builds on re-running make, and can cause
2075 # complete build failures for a parallel make.
2076 if (extract_from_file('Makefile.SH',
2077 qr/Writing it this way gives make a big hint to always run opcode\.pl before/)) {
2078 apply_commit('70c6e6715e8fec53');
2079 } elsif (extract_from_file('Makefile.SH',
2080 qr/^opcode\.h opnames\.h pp_proto\.h pp\.sym: opcode\.pl$/)) {
2081 revert_commit('9fec149bb652b6e9');
2082 }
2083 }
2084
e628fd8c
NC
2085 if ($^O eq 'aix' && $major >= 11 && $major <= 15
2086 && extract_from_file('makedef.pl', qr/^use Config/)) {
2087 edit_file('Makefile.SH', sub {
2088 # The AIX part of commit e6807d8ab22b761c
2089 # It's safe to substitute lib/Config.pm for config.sh
2090 # as lib/Config.pm depends on config.sh
2091 # If the tree is post e6807d8ab22b761c, the substitution
2092 # won't match, which is harmless.
2093 my $code = shift;
2094 $code =~ s{^(perl\.exp:.* )config\.sh(\b.*)}
2095 {$1 . '$(CONFIGPM)' . $2}me;
2096 return $code;
2097 });
2098 }
2099
bb723266
NC
2100 # There was a bug in makedepend.SH which was fixed in version 96a8704c.
2101 # Symptom was './makedepend: 1: Syntax error: Unterminated quoted string'
2102 # Remove this if you're actually bisecting a problem related to
2103 # makedepend.SH
2104 # If you do this, you may need to add in code to correct the output of older
2105 # makedepends, which don't correctly filter newer gcc output such as
2106 # <built-in>
2107 checkout_file('makedepend.SH');
2108
2109 if ($major < 4 && -f 'config.sh'
2110 && !extract_from_file('config.sh', qr/^trnl=/)) {
2111 # This seems to be necessary to avoid makedepend becoming confused,
2112 # and hanging on stdin. Seems that the code after
2113 # make shlist || ...here... is never run.
2114 edit_file('makedepend.SH', sub {
2115 my $code = shift;
2116 $code =~ s/^trnl='\$trnl'$/trnl='\\n'/m;
2117 return $code;
2118 });
2119 }
2120}
2121
2122sub patch_C {
2123 # This is ordered by $major, as it's likely that different platforms may
2124 # well want to share code.
2125
2126 if ($major == 2 && extract_from_file('perl.c', qr/^\tfclose\(e_fp\);$/)) {
2127 # need to patch perl.c to avoid calling fclose() twice on e_fp when
2128 # using -e
2129 # This diff is part of commit ab821d7fdc14a438. The second close was
2130 # introduced with perl-5.002, commit a5f75d667838e8e7
2131 # Might want a6c477ed8d4864e6 too, for the corresponding change to
2132 # pp_ctl.c (likely without this, eval will have "fun")
2133 apply_patch(<<'EOPATCH');
2134diff --git a/perl.c b/perl.c
2135index 03c4d48..3c814a2 100644
2136--- a/perl.c
2137+++ b/perl.c
2138@@ -252,6 +252,7 @@ setuid perl scripts securely.\n");
2139 #ifndef VMS /* VMS doesn't have environ array */
2140 origenviron = environ;
2141 #endif
2142+ e_tmpname = Nullch;
2143
2144 if (do_undump) {
2145
2146@@ -405,6 +406,7 @@ setuid perl scripts securely.\n");
2147 if (e_fp) {
2148 if (Fflush(e_fp) || ferror(e_fp) || fclose(e_fp))
2149 croak("Can't write to temp file for -e: %s", Strerror(errno));
2150+ e_fp = Nullfp;
2151 argc++,argv--;
2152 scriptname = e_tmpname;
2153 }
2154@@ -470,10 +472,10 @@ setuid perl scripts securely.\n");
2155 curcop->cop_line = 0;
2156 curstash = defstash;
2157 preprocess = FALSE;
2158- if (e_fp) {
2159- fclose(e_fp);
2160- e_fp = Nullfp;
2161+ if (e_tmpname) {
2162 (void)UNLINK(e_tmpname);
2163+ Safefree(e_tmpname);
2164+ e_tmpname = Nullch;
2165 }
2166
2167 /* now that script is parsed, we can modify record separator */
2168@@ -1369,7 +1371,7 @@ SV *sv;
2169 scriptname = xfound;
2170 }
2171
2172- origfilename = savepv(e_fp ? "-e" : scriptname);
2173+ origfilename = savepv(e_tmpname ? "-e" : scriptname);
2174 curcop->cop_filegv = gv_fetchfile(origfilename);
2175 if (strEQ(origfilename,"-"))
2176 scriptname = "";
2177
2178EOPATCH
2179 }
2180
2181 if ($major < 3 && $^O eq 'openbsd'
2182 && !extract_from_file('pp_sys.c', qr/BSD_GETPGRP/)) {
2183 # Part of commit c3293030fd1b7489
2184 apply_patch(<<'EOPATCH');
2185diff --git a/pp_sys.c b/pp_sys.c
2186index 4608a2a..f0c9d1d 100644
2187--- a/pp_sys.c
2188+++ b/pp_sys.c
2189@@ -2903,8 +2903,8 @@ PP(pp_getpgrp)
2190 pid = 0;
2191 else
2192 pid = SvIVx(POPs);
2193-#ifdef USE_BSDPGRP
2194- value = (I32)getpgrp(pid);
2195+#ifdef BSD_GETPGRP
2196+ value = (I32)BSD_GETPGRP(pid);
2197 #else
2198 if (pid != 0)
2199 DIE("POSIX getpgrp can't take an argument");
2200@@ -2933,8 +2933,8 @@ PP(pp_setpgrp)
2201 }
2202
2203 TAINT_PROPER("setpgrp");
2204-#ifdef USE_BSDPGRP
2205- SETi( setpgrp(pid, pgrp) >= 0 );
2206+#ifdef BSD_SETPGRP
2207+ SETi( BSD_SETPGRP(pid, pgrp) >= 0 );
2208 #else
2209 if ((pgrp != 0) || (pid != 0)) {
2210 DIE("POSIX setpgrp can't take an argument");
2211EOPATCH
2212 }
2213
2214 if ($major < 4 && $^O eq 'openbsd') {
2215 my $bad;
2216 # Need changes from commit a6e633defa583ad5.
2217 # Commits c07a80fdfe3926b5 and f82b3d4130164d5f changed the same part
2218 # of perl.h
2219
2220 if (extract_from_file('perl.h',
2221 qr/^#ifdef HAS_GETPGRP2$/)) {
2222 $bad = <<'EOBAD';
2223***************
2224*** 57,71 ****
2225 #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s)
2226 #define TAINT_ENV() if (tainting) taint_env()
2227
2228! #ifdef HAS_GETPGRP2
2229! # ifndef HAS_GETPGRP
2230! # define HAS_GETPGRP
2231! # endif
2232! #endif
2233!
2234! #ifdef HAS_SETPGRP2
2235! # ifndef HAS_SETPGRP
2236! # define HAS_SETPGRP
2237! # endif
2238 #endif
2239
2240EOBAD
2241 } elsif (extract_from_file('perl.h',
2242 qr/Gack, you have one but not both of getpgrp2/)) {
2243 $bad = <<'EOBAD';
2244***************
2245*** 56,76 ****
2246 #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s)
2247 #define TAINT_ENV() if (tainting) taint_env()
2248
2249! #if defined(HAS_GETPGRP2) && defined(HAS_SETPGRP2)
2250! # define getpgrp getpgrp2
2251! # define setpgrp setpgrp2
2252! # ifndef HAS_GETPGRP
2253! # define HAS_GETPGRP
2254! # endif
2255! # ifndef HAS_SETPGRP
2256! # define HAS_SETPGRP
2257! # endif
2258! # ifndef USE_BSDPGRP
2259! # define USE_BSDPGRP
2260! # endif
2261! #else
2262! # if defined(HAS_GETPGRP2) || defined(HAS_SETPGRP2)
2263! #include "Gack, you have one but not both of getpgrp2() and setpgrp2()."
2264! # endif
2265 #endif
2266
2267EOBAD
2268 } elsif (extract_from_file('perl.h',
2269 qr/^#ifdef USE_BSDPGRP$/)) {
2270 $bad = <<'EOBAD'
2271***************
2272*** 91,116 ****
2273 #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s)
2274 #define TAINT_ENV() if (tainting) taint_env()
2275
2276! #ifdef USE_BSDPGRP
2277! # ifdef HAS_GETPGRP
2278! # define BSD_GETPGRP(pid) getpgrp((pid))
2279! # endif
2280! # ifdef HAS_SETPGRP
2281! # define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
2282! # endif
2283! #else
2284! # ifdef HAS_GETPGRP2
2285! # define BSD_GETPGRP(pid) getpgrp2((pid))
2286! # ifndef HAS_GETPGRP
2287! # define HAS_GETPGRP
2288! # endif
2289! # endif
2290! # ifdef HAS_SETPGRP2
2291! # define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
2292! # ifndef HAS_SETPGRP
2293! # define HAS_SETPGRP
2294! # endif
2295! # endif
2296 #endif
2297
2298 #ifndef _TYPES_ /* If types.h defines this it's easy. */
2299EOBAD
2300 }
2301 if ($bad) {
2302 apply_patch(<<"EOPATCH");
2303*** a/perl.h 2011-10-21 09:46:12.000000000 +0200
2304--- b/perl.h 2011-10-21 09:46:12.000000000 +0200
2305$bad--- 91,144 ----
2306 #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s)
2307 #define TAINT_ENV() if (tainting) taint_env()
2308
2309! /* XXX All process group stuff is handled in pp_sys.c. Should these
2310! defines move there? If so, I could simplify this a lot. --AD 9/96.
2311! */
2312! /* Process group stuff changed from traditional BSD to POSIX.
2313! perlfunc.pod documents the traditional BSD-style syntax, so we'll
2314! try to preserve that, if possible.
2315! */
2316! #ifdef HAS_SETPGID
2317! # define BSD_SETPGRP(pid, pgrp) setpgid((pid), (pgrp))
2318! #else
2319! # if defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP)
2320! # define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
2321! # else
2322! # ifdef HAS_SETPGRP2 /* DG/UX */
2323! # define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
2324! # endif
2325! # endif
2326! #endif
2327! #if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP)
2328! # define HAS_SETPGRP /* Well, effectively it does . . . */
2329! #endif
2330!
2331! /* getpgid isn't POSIX, but at least Solaris and Linux have it, and it makes
2332! our life easier :-) so we'll try it.
2333! */
2334! #ifdef HAS_GETPGID
2335! # define BSD_GETPGRP(pid) getpgid((pid))
2336! #else
2337! # if defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP)
2338! # define BSD_GETPGRP(pid) getpgrp((pid))
2339! # else
2340! # ifdef HAS_GETPGRP2 /* DG/UX */
2341! # define BSD_GETPGRP(pid) getpgrp2((pid))
2342! # endif
2343! # endif
2344! #endif
2345! #if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP)
2346! # define HAS_GETPGRP /* Well, effectively it does . . . */
2347! #endif
2348!
2349! /* These are not exact synonyms, since setpgrp() and getpgrp() may
2350! have different behaviors, but perl.h used to define USE_BSDPGRP
2351! (prior to 5.003_05) so some extension might depend on it.
2352! */
2353! #if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP)
2354! # ifndef USE_BSDPGRP
2355! # define USE_BSDPGRP
2356! # endif
2357 #endif
2358
2359 #ifndef _TYPES_ /* If types.h defines this it's easy. */
2360EOPATCH
2361 }
2362 }
2363
2364 if ($major == 4 && extract_from_file('scope.c', qr/\(SV\*\)SSPOPINT/)) {
2365 # [PATCH] 5.004_04 +MAINT_TRIAL_1 broken when sizeof(int) != sizeof(void)
2366 # Fixes a bug introduced in 161b7d1635bc830b
2367 apply_commit('9002cb76ec83ef7f');
2368 }
2369
2370 if ($major == 4 && extract_from_file('av.c', qr/AvARRAY\(av\) = 0;/)) {
2371 # Fixes a bug introduced in 1393e20655efb4bc
2372 apply_commit('e1c148c28bf3335b', 'av.c');
2373 }
2374
6626a474
NC
2375 if ($major == 4) {
2376 my $rest = extract_from_file('perl.c', qr/delimcpy(.*)/);
2377 if (defined $rest and $rest !~ /,$/) {
2378 # delimcpy added in fc36a67e8855d031, perl.c refactored to use it.
2379 # bug introduced in 2a92aaa05aa1acbf, fixed in 8490252049bf42d3
2380 # code then moved to util.c in commit 491527d0220de34e
2381 apply_patch(<<'EOPATCH');
bb723266
NC
2382diff --git a/perl.c b/perl.c
2383index 4eb69e3..54bbb00 100644
2384--- a/perl.c
2385+++ b/perl.c
2386@@ -1735,7 +1735,7 @@ SV *sv;
2387 if (len < sizeof tokenbuf)
2388 tokenbuf[len] = '\0';
2389 #else /* ! (atarist || DOSISH) */
2390- s = delimcpy(tokenbuf, tokenbuf + sizeof tokenbuf, s, bufend
2391+ s = delimcpy(tokenbuf, tokenbuf + sizeof tokenbuf, s, bufend,
2392 ':',
2393 &len);
2394 #endif /* ! (atarist || DOSISH) */
2395EOPATCH
6626a474 2396 }
bb723266
NC
2397 }
2398
2399 if ($major == 4 && $^O eq 'linux') {
2400 # Whilst this is fixed properly in f0784f6a4c3e45e1 which provides the
2401 # Configure probe, it's easier to back out the problematic changes made
2402 # in these previous commits:
2403 if (extract_from_file('doio.c',
2404 qr!^/\* XXX REALLY need metaconfig test \*/$!)) {
2405 revert_commit('4682965a1447ea44', 'doio.c');
2406 }
2407 if (my $token = extract_from_file('doio.c',
2408 qr!^#if (defined\(__sun(?:__)?\)) && defined\(__svr4__\) /\* XXX Need metaconfig test \*/$!)) {
2409 my $patch = `git show -R 9b599b2a63d2324d doio.c`;
2410 $patch =~ s/defined\(__sun__\)/$token/g;
2411 apply_patch($patch);
2412 }
2413 if (extract_from_file('doio.c',
2414 qr!^/\* linux \(and Solaris2\?\) uses :$!)) {
2415 revert_commit('8490252049bf42d3', 'doio.c');
2416 }
2417 if (extract_from_file('doio.c',
2418 qr/^ unsemds.buf = &semds;$/)) {
2419 revert_commit('8e591e46b4c6543e');
2420 }
2421 if (extract_from_file('doio.c',
2422 qr!^#ifdef __linux__ /\* XXX Need metaconfig test \*/$!)) {
2423 # Reverts part of commit 3e3baf6d63945cb6
2424 apply_patch(<<'EOPATCH');
2425diff --git b/doio.c a/doio.c
2426index 62b7de9..0d57425 100644
2427--- b/doio.c
2428+++ a/doio.c
2429@@ -1333,9 +1331,6 @@ SV **sp;
2430 char *a;
2431 I32 id, n, cmd, infosize, getinfo;
2432 I32 ret = -1;
2433-#ifdef __linux__ /* XXX Need metaconfig test */
2434- union semun unsemds;
2435-#endif
2436
2437 id = SvIVx(*++mark);
2438 n = (optype == OP_SEMCTL) ? SvIVx(*++mark) : 0;
2439@@ -1364,29 +1359,11 @@ SV **sp;
2440 infosize = sizeof(struct semid_ds);
2441 else if (cmd == GETALL || cmd == SETALL)
2442 {
2443-#ifdef __linux__ /* XXX Need metaconfig test */
2444-/* linux uses :
2445- int semctl (int semid, int semnun, int cmd, union semun arg)
2446-
2447- union semun {
2448- int val;
2449- struct semid_ds *buf;
2450- ushort *array;
2451- };
2452-*/
2453- union semun semds;
2454- if (semctl(id, 0, IPC_STAT, semds) == -1)
2455-#else
2456 struct semid_ds semds;
2457 if (semctl(id, 0, IPC_STAT, &semds) == -1)
2458-#endif
2459 return -1;
2460 getinfo = (cmd == GETALL);
2461-#ifdef __linux__ /* XXX Need metaconfig test */
2462- infosize = semds.buf->sem_nsems * sizeof(short);
2463-#else
2464 infosize = semds.sem_nsems * sizeof(short);
2465-#endif
2466 /* "short" is technically wrong but much more portable
2467 than guessing about u_?short(_t)? */
2468 }
2469@@ -1429,12 +1406,7 @@ SV **sp;
2470 #endif
2471 #ifdef HAS_SEM
2472 case OP_SEMCTL:
2473-#ifdef __linux__ /* XXX Need metaconfig test */
2474- unsemds.buf = (struct semid_ds *)a;
2475- ret = semctl(id, n, cmd, unsemds);
2476-#else
2477 ret = semctl(id, n, cmd, (struct semid_ds *)a);
2478-#endif
2479 break;
2480 #endif
2481 #ifdef HAS_SHM
2482EOPATCH
2483 }
2484 # Incorrect prototype added as part of 8ac853655d9b7447, fixed as part
2485 # of commit dc45a647708b6c54, with at least one intermediate
2486 # modification. Correct prototype for gethostbyaddr has socklen_t
2487 # second. Linux has uint32_t first for getnetbyaddr.
2488 # Easiest just to remove, instead of attempting more complex patching.
2489 # Something similar may be needed on other platforms.
2490 edit_file('pp_sys.c', sub {
2491 my $code = shift;
2492 $code =~ s/^ struct hostent \*(?:PerlSock_)?gethostbyaddr\([^)]+\);$//m;
2493 $code =~ s/^ struct netent \*getnetbyaddr\([^)]+\);$//m;
2494 return $code;
2495 });
2496 }
2497
d1ac19b7
NC
2498 if ($major < 5 && $^O eq 'aix'
2499 && !extract_from_file('pp_sys.c',
2500 qr/defined\(HOST_NOT_FOUND\) && !defined\(h_errno\)/)) {
2501 # part of commit dc45a647708b6c54
2502 # Andy Dougherty's configuration patches (Config_63-01 up to 04).
2503 apply_patch(<<'EOPATCH')
2504diff --git a/pp_sys.c b/pp_sys.c
2505index c2fcb6f..efa39fb 100644
2506--- a/pp_sys.c
2507+++ b/pp_sys.c
2508@@ -54,7 +54,7 @@ extern "C" int syscall(unsigned long,...);
2509 #endif
2510 #endif
2511
2512-#ifdef HOST_NOT_FOUND
2513+#if defined(HOST_NOT_FOUND) && !defined(h_errno)
2514 extern int h_errno;
2515 #endif
2516
2517EOPATCH
2518 }
2519
df01cf53 2520 if ($major == 5
31940c07
NC
2521 && `git rev-parse HEAD` eq "22c35a8c2392967a5ba6b5370695be464bd7012c\n") {
2522 # Commit 22c35a8c2392967a is significant,
2523 # "phase 1 of somewhat major rearrangement of PERL_OBJECT stuff"
2524 # but doesn't build due to 2 simple errors. blead in this broken state
2525 # was merged to the cfgperl branch, and then these were immediately
2526 # corrected there. cfgperl (with the fixes) was merged back to blead.
2527 # The resultant rather twisty maze of commits looks like this:
2528
911bfca9 2529=begin comment
31940c07
NC
2530
2531* | | commit 137225782c183172f360c827424b9b9f8adbef0e
2532|\ \ \ Merge: 22c35a8 2a8ee23
2533| |/ / Author: Gurusamy Sarathy <gsar@cpan.org>
2534| | | Date: Fri Oct 30 17:38:36 1998 +0000
2535| | |
2536| | | integrate cfgperl tweaks into mainline
2537| | |
2538| | | p4raw-id: //depot/perl@2144
2539| | |
2540| * | commit 2a8ee23279873759693fa83eca279355db2b665c
2541| | | Author: Jarkko Hietaniemi <jhi@iki.fi>
2542| | | Date: Fri Oct 30 13:27:39 1998 +0000
2543| | |
2544| | | There can be multiple yacc/bison errors.
2545| | |
2546| | | p4raw-id: //depot/cfgperl@2143
2547| | |
2548| * | commit 93fb2ac393172fc3e2c14edb20b718309198abbc
2549| | | Author: Jarkko Hietaniemi <jhi@iki.fi>
2550| | | Date: Fri Oct 30 13:18:43 1998 +0000
2551| | |
2552| | | README.posix-bc update.
2553| | |
2554| | | p4raw-id: //depot/cfgperl@2142
2555| | |
2556| * | commit 4ec43091e8e6657cb260b5e563df30aaa154effe
2557| | | Author: Jarkko Hietaniemi <jhi@iki.fi>
2558| | | Date: Fri Oct 30 09:12:59 1998 +0000
2559| | |
2560| | | #2133 fallout.
2561| | |
2562| | | p4raw-id: //depot/cfgperl@2141
2563| | |
2564| * | commit 134ca994cfefe0f613d43505a885e4fc2100b05c
2565| |\ \ Merge: 7093112 22c35a8
2566| |/ / Author: Jarkko Hietaniemi <jhi@iki.fi>
2567|/| | Date: Fri Oct 30 08:43:18 1998 +0000
2568| | |
2569| | | Integrate from mainperl.
2570| | |
2571| | | p4raw-id: //depot/cfgperl@2140
2572| | |
2573* | | commit 22c35a8c2392967a5ba6b5370695be464bd7012c
2574| | | Author: Gurusamy Sarathy <gsar@cpan.org>
2575| | | Date: Fri Oct 30 02:51:39 1998 +0000
2576| | |
2577| | | phase 1 of somewhat major rearrangement of PERL_OBJECT stuff
2578| | | (objpp.h is gone, embed.pl now does some of that); objXSUB.h
2579| | | should soon be automated also; the global variables that
2580| | | escaped the PL_foo conversion are now reined in; renamed
2581| | | MAGIC in regcomp.h to REG_MAGIC to avoid collision with the
2582| | | type of same name; duplicated lists of pp_things in various
2583| | | places is now gone; result has only been tested on win32
2584| | |
2585| | | p4raw-id: //depot/perl@2133
2586
911bfca9
NC
2587=end comment
2588
31940c07
NC
2589=cut
2590
2591 # and completely confuses git bisect (and at least me), causing it to
2592 # the bisect run to confidently return the wrong answer, an unrelated
2593 # commit on the cfgperl branch.
2594
2595 apply_commit('4ec43091e8e6657c');
2596 }
2597
2598 if ($major == 5
df01cf53
NC
2599 && extract_from_file('pp_sys.c', qr/PERL_EFF_ACCESS_R_OK/)
2600 && !extract_from_file('pp_sys.c', qr/XXX Configure test needed for eaccess/)) {
2601 # Between 5ff3f7a4e03a6b10 and c955f1177b2e311d^
2602 # This is the meat of commit c955f1177b2e311d (without the other
2603 # indenting changes that would cause a conflict).
2604 # Without this 538 revisions won't build on (at least) Linux
2605 apply_patch(<<'EOPATCH');
2606diff --git a/pp_sys.c b/pp_sys.c
2607index d60c8dc..867dee4 100644
2608--- a/pp_sys.c
2609+++ b/pp_sys.c
2610@@ -198,9 +198,18 @@ static char zero_but_true[ZBTLEN + 1] = "0 but true";
2611 # if defined(I_SYS_SECURITY)
2612 # include <sys/security.h>
2613 # endif
2614-# define PERL_EFF_ACCESS_R_OK(p) (eaccess((p), R_OK, ACC_SELF))
2615-# define PERL_EFF_ACCESS_W_OK(p) (eaccess((p), W_OK, ACC_SELF))
2616-# define PERL_EFF_ACCESS_X_OK(p) (eaccess((p), X_OK, ACC_SELF))
2617+ /* XXX Configure test needed for eaccess */
2618+# ifdef ACC_SELF
2619+ /* HP SecureWare */
2620+# define PERL_EFF_ACCESS_R_OK(p) (eaccess((p), R_OK, ACC_SELF))
2621+# define PERL_EFF_ACCESS_W_OK(p) (eaccess((p), W_OK, ACC_SELF))
2622+# define PERL_EFF_ACCESS_X_OK(p) (eaccess((p), X_OK, ACC_SELF))
2623+# else
2624+ /* SCO */
2625+# define PERL_EFF_ACCESS_R_OK(p) (eaccess((p), R_OK))
2626+# define PERL_EFF_ACCESS_W_OK(p) (eaccess((p), W_OK))
2627+# define PERL_EFF_ACCESS_X_OK(p) (eaccess((p), X_OK))
2628+# endif
2629 #endif
2630
2631 #if !defined(PERL_EFF_ACCESS_R_OK) && defined(HAS_ACCESSX) && defined(ACC_SELF)
2632EOPATCH
2633 }
2634
bb35dd48
NC
2635 if ($major == 5
2636 && extract_from_file('mg.c', qr/If we're still on top of the stack, pop us off/)
af6a5d0e 2637 && !extract_from_file('mg.c', qr/PL_savestack_ix -= popval/)) {
bb35dd48
NC
2638 # Fix up commit 455ece5e082708b1:
2639 # SSNEW() API for allocating memory on the savestack
2640 # Message-Id: <tqemtae338.fsf@puma.genscan.com>
2641 # Subject: [PATCH 5.005_51] (was: why SAVEDESTRUCTOR()...)
2642 apply_commit('3c8a44569607336e', 'mg.c');
2643 }
2644
6863570c
NC
2645 if ($major == 5) {
2646 if (extract_from_file('doop.c', qr/croak\(no_modify\);/)
2647 && extract_from_file('doop.c', qr/croak\(PL_no_modify\);/)) {
2648 # Whilst the log suggests that this would only fix 5 commits, in
2649 # practice this area of history is a complete tarpit, and git bisect
2650 # gets very confused by the skips in the middle of the back and
2651 # forth merging between //depot/perl and //depot/cfgperl
2652 apply_commit('6393042b638dafd3');
2653 }
2654
2655 # One error "fixed" with another:
2656 if (extract_from_file('pp_ctl.c',
2657 qr/\Qstatic void *docatch_body _((void *o));\E/)) {
2658 apply_commit('5b51e982882955fe');
2659 }
2660 # Which is then fixed by this:
2661 if (extract_from_file('pp_ctl.c',
2662 qr/\Qstatic void *docatch_body _((valist\E/)) {
2663 apply_commit('47aa779ee4c1a50e');
2664 }
2665
2666 if (extract_from_file('thrdvar.h', qr/PERLVARI\(Tprotect/)
2667 && !extract_from_file('embedvar.h', qr/PL_protect/)) {
2668 # Commit 312caa8e97f1c7ee didn't update embedvar.h
2669 apply_commit('e0284a306d2de082', 'embedvar.h');
2670 }
2671 }
2672
2673 if ($major == 5
2674 && extract_from_file('sv.c',
2675 qr/PerlDir_close\(IoDIRP\((?:\(IO\*\))?sv\)\);/)
2676 && !(extract_from_file('toke.c',
2677 qr/\QIoDIRP(FILTER_DATA(AvFILLp(PL_rsfp_filters))) = NULL\E/)
2678 || extract_from_file('toke.c',
2679 qr/\QIoDIRP(datasv) = (DIR*)NULL;\E/))) {
2680 # Commit 93578b34124e8a3b, //depot/perl@3298
2681 # close directory handles properly when localized,
2682 # tweaked slightly by commit 1236053a2c722e2b,
2683 # add test case for change#3298
2684 #
2685 # The fix is the last part of:
2686 #
2687 # various fixes for clean build and test on win32; configpm broken,
2688 # needed to open myconfig.SH rather than myconfig; sundry adjustments
2689 # to bytecode stuff; tweaks to DYNAMIC_ENV_FETCH code to make it
2690 # work under win32; getenv_sv() changed to getenv_len() since SVs
2691 # aren't visible in the lower echelons; remove bogus exports from
2692 # config.sym; PERL_OBJECT-ness for C++ exception support; null out
2693 # IoDIRP in filter_del() or sv_free() will attempt to close it
2694 #
2695 # The changed code is modified subsequently by commit e0c198038146b7a4
2696 apply_commit('a6c403648ecd5cc7', 'toke.c');
2697 }
2698
bb723266
NC
2699 if ($major < 6 && $^O eq 'netbsd'
2700 && !extract_from_file('unixish.h',
2701 qr/defined\(NSIG\).*defined\(__NetBSD__\)/)) {
2702 apply_patch(<<'EOPATCH')
2703diff --git a/unixish.h b/unixish.h
2704index 2a6cbcd..eab2de1 100644
2705--- a/unixish.h
2706+++ b/unixish.h
2707@@ -89,7 +89,7 @@
2708 */
2709 /* #define ALTERNATE_SHEBANG "#!" / **/
2710
2711-#if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
2712+#if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX) || defined(__NetBSD__)
2713 # include <signal.h>
2714 #endif
2715
2716EOPATCH
2717 }
2718
2719 if (($major >= 7 || $major <= 9) && $^O eq 'openbsd'
2720 && `uname -m` eq "sparc64\n"
2721 # added in 2000 by commit cb434fcc98ac25f5:
2722 && extract_from_file('regexec.c',
2723 qr!/\* No need to save/restore up to this paren \*/!)
2724 # re-indented in 2006 by commit 95b2444054382532:
2725 && extract_from_file('regexec.c', qr/^\t\tCURCUR cc;$/)) {
2726 # Need to work around a bug in (at least) OpenBSD's 4.6's sparc64 #
2727 # compiler ["gcc (GCC) 3.3.5 (propolice)"]. Between commits
2728 # 3ec562b0bffb8b8b (2002) and 1a4fad37125bac3e^ (2005) the darling thing
2729 # fails to compile any code for the statement cc.oldcc = PL_regcc;
2730 #
2731 # If you refactor the code to "fix" that, or force the issue using set
2732 # in the debugger, the stack smashing detection code fires on return
2733 # from S_regmatch(). Turns out that the compiler doesn't allocate any
2734 # (or at least enough) space for cc.
2735 #
2736 # Restore the "uninitialised" value for cc before function exit, and the
2737 # stack smashing code is placated. "Fix" 3ec562b0bffb8b8b (which
2738 # changes the size of auto variables used elsewhere in S_regmatch), and
2739 # the crash is visible back to bc517b45fdfb539b (which also changes
2740 # buffer sizes). "Unfix" 1a4fad37125bac3e and the crash is visible until
2741 # 5b47454deb66294b. Problem goes away if you compile with -O, or hack
2742 # the code as below.
2743 #
2744 # Hence this turns out to be a bug in (old) gcc. Not a security bug we
2745 # still need to fix.
2746 apply_patch(<<'EOPATCH');
2747diff --git a/regexec.c b/regexec.c
2748index 900b491..6251a0b 100644
2749--- a/regexec.c
2750+++ b/regexec.c
2751@@ -2958,7 +2958,11 @@ S_regmatch(pTHX_ regnode *prog)
2752 I,I
2753 *******************************************************************/
2754 case CURLYX: {
2755- CURCUR cc;
2756+ union {
2757+ CURCUR hack_cc;
2758+ char hack_buff[sizeof(CURCUR) + 1];
2759+ } hack;
2760+#define cc hack.hack_cc
2761 CHECKPOINT cp = PL_savestack_ix;
2762 /* No need to save/restore up to this paren */
2763 I32 parenfloor = scan->flags;
2764@@ -2983,6 +2987,7 @@ S_regmatch(pTHX_ regnode *prog)
2765 n = regmatch(PREVOPER(next)); /* start on the WHILEM */
2766 regcpblow(cp);
2767 PL_regcc = cc.oldcc;
2768+#undef cc
2769 saySAME(n);
2770 }
2771 /* NOT REACHED */
2772EOPATCH
2773}
2774
2775 if ($major < 8 && $^O eq 'openbsd'
2776 && !extract_from_file('perl.h', qr/include <unistd\.h>/)) {
2777 # This is part of commit 3f270f98f9305540, applied at a slightly
2778 # different location in perl.h, where the context is stable back to
2779 # 5.000
2780 apply_patch(<<'EOPATCH');
2781diff --git a/perl.h b/perl.h
2782index 9418b52..b8b1a7c 100644
2783--- a/perl.h
2784+++ b/perl.h
2785@@ -496,6 +496,10 @@ register struct op *Perl_op asm(stringify(OP_IN_REGISTER));
2786 # include <sys/param.h>
2787 #endif
2788
2789+/* If this causes problems, set i_unistd=undef in the hint file. */
2790+#ifdef I_UNISTD
2791+# include <unistd.h>
2792+#endif
2793
2794 /* Use all the "standard" definitions? */
2795 #if defined(STANDARD_C) && defined(I_STDLIB)
2796EOPATCH
2797 }
2798}
2799
f2f0a0ff
NC
2800sub patch_ext {
2801 if (-f 'ext/POSIX/Makefile.PL'
2802 && extract_from_file('ext/POSIX/Makefile.PL',
2803 qr/Explicitly avoid including/)) {
2804 # commit 6695a346c41138df, which effectively reverts 170888cff5e2ffb7
2805
2806 # PERL5LIB is populated by make_ext.pl with paths to the modules we need
2807 # to run, don't override this with "../../lib" since that may not have
2808 # been populated yet in a parallel build.
2809 apply_commit('6695a346c41138df');
2810 }
2811
06cebb71
NC
2812 if (-f 'ext/Hash/Util/Makefile.PL'
2813 && extract_from_file('ext/Hash/Util/Makefile.PL',
2814 qr/\bDIR\b.*'FieldHash'/)) {
2815 # ext/Hash/Util/Makefile.PL should not recurse to FieldHash's Makefile.PL
2816 # *nix, VMS and Win32 all know how to (and have to) call the latter directly.
2817 # As is, targets in ext/Hash/Util/FieldHash get called twice, which may result
2818 # in race conditions, and certainly messes up make clean; make distclean;
2819 apply_commit('550428fe486b1888');
2820 }
2821
f2f0a0ff
NC
2822 if ($major < 8 && $^O eq 'darwin' && !-f 'ext/DynaLoader/dl_dyld.xs') {
2823 checkout_file('ext/DynaLoader/dl_dyld.xs', 'f556e5b971932902');
2824 apply_patch(<<'EOPATCH');
2825diff -u a/ext/DynaLoader/dl_dyld.xs~ a/ext/DynaLoader/dl_dyld.xs
2826--- a/ext/DynaLoader/dl_dyld.xs~ 2011-10-11 21:41:27.000000000 +0100
2827+++ b/ext/DynaLoader/dl_dyld.xs 2011-10-11 21:42:20.000000000 +0100
2828@@ -41,6 +41,35 @@
2829 #include "perl.h"
2830 #include "XSUB.h"
2831
2832+#ifndef pTHX
2833+# define pTHX void
2834+# define pTHX_
2835+#endif
2836+#ifndef aTHX
2837+# define aTHX
2838+# define aTHX_
2839+#endif
2840+#ifndef dTHX
2841+# define dTHXa(a) extern int Perl___notused(void)
2842+# define dTHX extern int Perl___notused(void)
2843+#endif
2844+
2845+#ifndef Perl_form_nocontext
2846+# define Perl_form_nocontext form
2847+#endif
2848+
2849+#ifndef Perl_warn_nocontext
2850+# define Perl_warn_nocontext warn
2851+#endif
2852+
2853+#ifndef PTR2IV
2854+# define PTR2IV(p) (IV)(p)
2855+#endif
2856+
2857+#ifndef get_av
2858+# define get_av perl_get_av
2859+#endif
2860+
2861 #define DL_LOADONCEONLY
2862
2863 #include "dlutils.c" /* SaveError() etc */
2864@@ -185,7 +191,7 @@
2865 CODE:
2866 DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s,%x):\n", filename,flags));
2867 if (flags & 0x01)
2868- Perl_warn(aTHX_ "Can't make loaded symbols global on this platform while loading %s",filename);
2869+ Perl_warn_nocontext("Can't make loaded symbols global on this platform while loading %s",filename);
2870 RETVAL = dlopen(filename, mode) ;
2871 DLDEBUG(2,PerlIO_printf(Perl_debug_log, " libref=%x\n", RETVAL));
2872 ST(0) = sv_newmortal() ;
2873EOPATCH
2874 if ($major < 4 && !extract_from_file('util.c', qr/^form/m)) {
2875 apply_patch(<<'EOPATCH');
2876diff -u a/ext/DynaLoader/dl_dyld.xs~ a/ext/DynaLoader/dl_dyld.xs
2877--- a/ext/DynaLoader/dl_dyld.xs~ 2011-10-11 21:56:25.000000000 +0100
2878+++ b/ext/DynaLoader/dl_dyld.xs 2011-10-11 22:00:00.000000000 +0100
2879@@ -60,6 +60,18 @@
2880 # define get_av perl_get_av
2881 #endif
2882
2883+static char *
2884+form(char *pat, ...)
2885+{
2886+ char *retval;
2887+ va_list args;
2888+ va_start(args, pat);
2889+ vasprintf(&retval, pat, &args);
2890+ va_end(args);
2891+ SAVEFREEPV(retval);
2892+ return retval;
2893+}
2894+
2895 #define DL_LOADONCEONLY
2896
2897 #include "dlutils.c" /* SaveError() etc */
2898EOPATCH
2899 }
2900 }
2901
2902 if ($major < 10) {
2903 if (!extract_from_file('ext/DB_File/DB_File.xs',
2904 qr!^#else /\* Berkeley DB Version > 2 \*/$!)) {
2905 # This DB_File.xs is really too old to patch up.
2906 # Skip DB_File, unless we're invoked with an explicit -Unoextensions
2907 if (!exists $defines{noextensions}) {
2908 $defines{noextensions} = 'DB_File';
2909 } elsif (defined $defines{noextensions}) {
2910 $defines{noextensions} .= ' DB_File';
2911 }
2912 } elsif (!extract_from_file('ext/DB_File/DB_File.xs',
2913 qr/^#ifdef AT_LEAST_DB_4_1$/)) {
2914 # This line is changed by commit 3245f0580c13b3ab
2915 my $line = extract_from_file('ext/DB_File/DB_File.xs',
2916 qr/^( status = \(?RETVAL->dbp->open\)?\(RETVAL->dbp, name, NULL, RETVAL->type, $)/);
2917 apply_patch(<<"EOPATCH");
2918diff --git a/ext/DB_File/DB_File.xs b/ext/DB_File/DB_File.xs
2919index 489ba96..fba8ded 100644
2920--- a/ext/DB_File/DB_File.xs
2921+++ b/ext/DB_File/DB_File.xs
2922\@\@ -183,4 +187,8 \@\@
2923 #endif
2924
2925+#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
2926+# define AT_LEAST_DB_4_1
2927+#endif
2928+
2929 /* map version 2 features & constants onto their version 1 equivalent */
2930
2931\@\@ -1334,7 +1419,12 \@\@ SV * sv ;
2932 #endif
2933
2934+#ifdef AT_LEAST_DB_4_1
2935+ status = (RETVAL->dbp->open)(RETVAL->dbp, NULL, name, NULL, RETVAL->type,
2936+ Flags, mode) ;
2937+#else
2938 $line
2939 Flags, mode) ;
2940+#endif
2941 /* printf("open returned %d %s\\n", status, db_strerror(status)) ; */
2942
2943EOPATCH
2944 }
2945 }
2946
2947 if ($major < 10 and -f 'ext/IPC/SysV/SysV.xs') {
2948 edit_file('ext/IPC/SysV/SysV.xs', sub {
2949 my $xs = shift;
2950 my $fixed = <<'EOFIX';
2951
2952#include <sys/types.h>
2953#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
2954#ifndef HAS_SEM
2955# include <sys/ipc.h>
2956#endif
2957# ifdef HAS_MSG
2958# include <sys/msg.h>
2959# endif
2960# ifdef HAS_SHM
2961# if defined(PERL_SCO) || defined(PERL_ISC)
2962# include <sys/sysmacros.h> /* SHMLBA */
2963# endif
2964# include <sys/shm.h>
2965# ifndef HAS_SHMAT_PROTOTYPE
2966 extern Shmat_t shmat (int, char *, int);
2967# endif
2968# if defined(HAS_SYSCONF) && defined(_SC_PAGESIZE)
2969# undef SHMLBA /* not static: determined at boot time */
2970# define SHMLBA sysconf(_SC_PAGESIZE)
2971# elif defined(HAS_GETPAGESIZE)
2972# undef SHMLBA /* not static: determined at boot time */
2973# define SHMLBA getpagesize()
2974# endif
2975# endif
2976#endif
2977EOFIX
2978 $xs =~ s!
2979#include <sys/types\.h>
2980.*
2981(#ifdef newCONSTSUB|/\* Required)!$fixed$1!ms;
2982 return $xs;
2983 });
2984 }
2985}
2986
9a999a97
NC
2987# Local variables:
2988# cperl-indent-level: 4
2989# indent-tabs-mode: nil
2990# End:
2991#
2992# ex: set ts=8 sts=4 sw=4 et: