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