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