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