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