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