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