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