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