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