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