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