This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
bisect-runner.pl should fix Makefile.SH to remove remove GNU make-isms.
[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 2048
67bec938
NC
2049 if ($major == 15 && $^O !~ /^(linux|darwin|.*bsd)$/
2050 && extract_from_file('Makefile.SH', qr/^V.* \?= /)) {
2051 # Remove the GNU-make-ism (which the BSD makes also support, but
2052 # most other makes choke on)
2053 apply_patch(<<'EOPATCH');
2054diff --git a/Makefile.SH b/Makefile.SH
2055index 94952bd..13e9001 100755
2056--- a/Makefile.SH
2057+++ b/Makefile.SH
2058@@ -338,8 +338,8 @@ linux*|darwin)
2059 $spitshell >>$Makefile <<!GROK!THIS!
2060 # If you're going to use valgrind and it can't be invoked as plain valgrind
2061 # then you'll need to change this, or override it on the make command line.
2062-VALGRIND ?= valgrind
2063-VG_TEST ?= ./perl -e 1 2>/dev/null
2064+VALGRIND = valgrind
2065+VG_TEST = ./perl -e 1 2>/dev/null
2066
2067 !GROK!THIS!
2068 ;;
2069EOPATCH
2070 }
2071
c0960282
NC
2072 if ($major == 11) {
2073 if (extract_from_file('patchlevel.h',
2074 qr/^#include "unpushed\.h"/)) {
2075 # I had thought it easier to detect when building one of the 52
2076 # commits with the original method of incorporating the git
2077 # revision and drop parallel make flags. Commits shown by
2078 # git log 46807d8e809cc127^..dcff826f70bf3f64^ ^d4fb0a1f15d1a1c4
2079 # However, it's not actually possible to make miniperl for that
2080 # configuration as-is, because the file .patchnum is only made
2081 # as a side effect of target 'all'
2082 # I also don't think that it's "safe" to simply run
2083 # make_patchnum.sh before the build. We need the proper
2084 # dependency rules in the Makefile to *stop* it being run again
2085 # at the wrong time.
2086 # This range is important because contains the commit that
2087 # merges Schwern's y2038 work.
2088 apply_patch(<<'EOPATCH');
2089diff --git a/Makefile.SH b/Makefile.SH
2090index 9ad8b6f..106e721 100644
2091--- a/Makefile.SH
2092+++ b/Makefile.SH
2093@@ -540,9 +544,14 @@ sperl.i: perl.c $(h)
2094
2095 .PHONY: all translators utilities make_patchnum
2096
2097-make_patchnum:
2098+make_patchnum: lib/Config_git.pl
2099+
2100+lib/Config_git.pl: make_patchnum.sh
2101 sh $(shellflags) make_patchnum.sh
2102
2103+# .patchnum, unpushed.h and lib/Config_git.pl are built by make_patchnum.sh
2104+unpushed.h .patchnum: lib/Config_git.pl
2105+
2106 # make sure that we recompile perl.c if .patchnum changes
2107 perl$(OBJ_EXT): .patchnum unpushed.h
2108
2109EOPATCH
2110 } elsif (-f '.gitignore'
2111 && extract_from_file('.gitignore', qr/^\.patchnum$/)) {
2112 # 8565263ab8a47cda to 46807d8e809cc127^ inclusive.
2113 edit_file('Makefile.SH', sub {
2114 my $code = shift;
2115 $code =~ s/^make_patchnum:\n/make_patchnum: .patchnum
2116
2117.sha1: .patchnum
2118
2119.patchnum: make_patchnum.sh
2120/m;
2121 return $code;
2122 });
74adbdfa
NC
2123 } elsif (-f 'lib/.gitignore'
2124 && extract_from_file('lib/.gitignore',
2125 qr!^/Config_git.pl!)
2126 && !extract_from_file('Makefile.SH',
2127 qr/^uudmap\.h.*:bitcount.h$/)) {
2128 # Between commits and dcff826f70bf3f64 and 0f13ebd5d71f8177^
2129 edit_file('Makefile.SH', sub {
2130 my $code = shift;
2131 # Bug introduced by 344af494c35a9f0f
2132 # fixed in 0f13ebd5d71f8177
2133 $code =~ s{^(pod/perlapi\.pod) (pod/perlintern\.pod): }
2134 {$1: $2\n\n$2: }m;
2135 # Bug introduced by efa50c51e3301a2c
2136 # fixed in 0f13ebd5d71f8177
2137 $code =~ s{^(uudmap\.h) (bitcount\.h): }
2138 {$1: $2\n\n$2: }m;
93a0b6a3
NC
2139
2140 # The rats nest of getting git_version.h correct
2141
2142 if ($code =~ s{git_version\.h: stock_git_version\.h
2143\tcp stock_git_version\.h git_version\.h}
2144 {}m) {
2145 # before 486cd780047ff224
2146
2147 # We probably can't build between
2148 # 953f6acfa20ec275^ and 8565263ab8a47cda
2149 # inclusive, but all commits in that range
2150 # relate to getting make_patchnum.sh working,
2151 # so it is extremely unlikely to be an
2152 # interesting bisect target. They will skip.
2153
2154 # No, don't spawn a submake if
2155 # make_patchnum.sh or make_patchnum.pl fails
2156 $code =~ s{\|\| \$\(MAKE\) miniperl.*}
2157 {}m;
2158 $code =~ s{^\t(sh.*make_patchnum\.sh.*)}
2159 {\t-$1}m;
2160
2161 # Use an external perl to run make_patchnum.pl
2162 # because miniperl still depends on
2163 # git_version.h
2164 $code =~ s{^\t.*make_patchnum\.pl}
2165 {\t-$^X make_patchnum.pl}m;
2166
2167
2168 # "Truth in advertising" - running
2169 # make_patchnum generates 2 files.
2170 $code =~ s{^make_patchnum:.*}{
2171make_patchnum: lib/Config_git.pl
2172
2173git_version.h: lib/Config_git.pl
2174
2175perlmini\$(OBJ_EXT): git_version.h
2176
2177lib/Config_git.pl:}m;
2178 }
356fb8dd
NC
2179 # Right, now we've corrected Makefile.SH to
2180 # correctly describe how lib/Config_git.pl and
2181 # git_version.h are made, we need to fix the rest
2182
2183 # This emulates commit 2b63e250843b907e
2184 # This might duplicate the rule stating that
2185 # git_version.h depends on lib/Config_git.pl
2186 # This is harmless.
2187 $code =~ s{^(?:lib/Config_git\.pl )?git_version\.h: (.* make_patchnum\.pl.*)}
2188 {git_version.h: lib/Config_git.pl
2189
2190lib/Config_git.pl: $1}m;
2191
97897675
NC
2192 # This emulates commits 0f13ebd5d71f8177 and
2193 # and a04d4598adc57886. It ensures that
2194 # lib/Config_git.pl is built before configpm,
2195 # and that configpm is run exactly once.
2196 $code =~ s{^(\$\(.*?\) )?(\$\(CONFIGPOD\))(: .*? configpm Porting/Glossary)( lib/Config_git\.pl)?}{
2197 # If present, other files depend on $(CONFIGPOD)
2198 ($1 ? "$1: $2\n\n" : '')
2199 # Then the rule we found
2200 . $2 . $3
2201 # Add dependency if not there
2202 . ($4 ? $4 : ' lib/Config_git.pl')
2203 }me;
2204
74adbdfa
NC
2205 return $code;
2206 });
c0960282
NC
2207 }
2208 }
2209
bb723266
NC
2210 if ($major < 14) {
2211 # Commits dc0655f797469c47 and d11a62fe01f2ecb2
2212 edit_file('Makefile.SH', sub {
2213 my $code = shift;
2214 foreach my $ext (qw(Encode SDBM_File)) {
2215 next if $code =~ /\b$ext\) extra_dep=/s;
2216 $code =~ s!(\) extra_dep="\$extra_dep
2217\$this_target: .*?" ;;)
2218( esac
2219)!$1
2220 $ext) extra_dep="\$extra_dep
2221\$this_target: lib/auto/Cwd/Cwd.\$dlext" ;;
2222$2!;
2223 }
2224 return $code;
2225 });
2226 }
2227 }
2228
2229 if ($major == 7) {
2230 # Remove commits 9fec149bb652b6e9 and 5bab1179608f81d8, which add/amend
2231 # rules to automatically run regen scripts that rebuild C headers. These
2232 # cause problems because a git checkout doesn't preserve relative file
2233 # modification times, hence the regen scripts may fire. This will
2234 # obscure whether the repository had the correct generated headers
2235 # checked in.
2236 # Also, the dependency rules for running the scripts were not correct,
2237 # which could cause spurious re-builds on re-running make, and can cause
2238 # complete build failures for a parallel make.
2239 if (extract_from_file('Makefile.SH',
2240 qr/Writing it this way gives make a big hint to always run opcode\.pl before/)) {
2241 apply_commit('70c6e6715e8fec53');
2242 } elsif (extract_from_file('Makefile.SH',
2243 qr/^opcode\.h opnames\.h pp_proto\.h pp\.sym: opcode\.pl$/)) {
2244 revert_commit('9fec149bb652b6e9');
2245 }
2246 }
2247
e628fd8c
NC
2248 if ($^O eq 'aix' && $major >= 11 && $major <= 15
2249 && extract_from_file('makedef.pl', qr/^use Config/)) {
2250 edit_file('Makefile.SH', sub {
2251 # The AIX part of commit e6807d8ab22b761c
2252 # It's safe to substitute lib/Config.pm for config.sh
2253 # as lib/Config.pm depends on config.sh
2254 # If the tree is post e6807d8ab22b761c, the substitution
2255 # won't match, which is harmless.
2256 my $code = shift;
2257 $code =~ s{^(perl\.exp:.* )config\.sh(\b.*)}
2258 {$1 . '$(CONFIGPM)' . $2}me;
2259 return $code;
2260 });
2261 }
2262
bb723266
NC
2263 # There was a bug in makedepend.SH which was fixed in version 96a8704c.
2264 # Symptom was './makedepend: 1: Syntax error: Unterminated quoted string'
2265 # Remove this if you're actually bisecting a problem related to
2266 # makedepend.SH
2267 # If you do this, you may need to add in code to correct the output of older
2268 # makedepends, which don't correctly filter newer gcc output such as
2269 # <built-in>
2270 checkout_file('makedepend.SH');
2271
2272 if ($major < 4 && -f 'config.sh'
2273 && !extract_from_file('config.sh', qr/^trnl=/)) {
2274 # This seems to be necessary to avoid makedepend becoming confused,
2275 # and hanging on stdin. Seems that the code after
2276 # make shlist || ...here... is never run.
2277 edit_file('makedepend.SH', sub {
2278 my $code = shift;
2279 $code =~ s/^trnl='\$trnl'$/trnl='\\n'/m;
2280 return $code;
2281 });
2282 }
2283}
2284
2285sub patch_C {
2286 # This is ordered by $major, as it's likely that different platforms may
2287 # well want to share code.
2288
2289 if ($major == 2 && extract_from_file('perl.c', qr/^\tfclose\(e_fp\);$/)) {
2290 # need to patch perl.c to avoid calling fclose() twice on e_fp when
2291 # using -e
2292 # This diff is part of commit ab821d7fdc14a438. The second close was
2293 # introduced with perl-5.002, commit a5f75d667838e8e7
2294 # Might want a6c477ed8d4864e6 too, for the corresponding change to
2295 # pp_ctl.c (likely without this, eval will have "fun")
2296 apply_patch(<<'EOPATCH');
2297diff --git a/perl.c b/perl.c
2298index 03c4d48..3c814a2 100644
2299--- a/perl.c
2300+++ b/perl.c
2301@@ -252,6 +252,7 @@ setuid perl scripts securely.\n");
2302 #ifndef VMS /* VMS doesn't have environ array */
2303 origenviron = environ;
2304 #endif
2305+ e_tmpname = Nullch;
2306
2307 if (do_undump) {
2308
2309@@ -405,6 +406,7 @@ setuid perl scripts securely.\n");
2310 if (e_fp) {
2311 if (Fflush(e_fp) || ferror(e_fp) || fclose(e_fp))
2312 croak("Can't write to temp file for -e: %s", Strerror(errno));
2313+ e_fp = Nullfp;
2314 argc++,argv--;
2315 scriptname = e_tmpname;
2316 }
2317@@ -470,10 +472,10 @@ setuid perl scripts securely.\n");
2318 curcop->cop_line = 0;
2319 curstash = defstash;
2320 preprocess = FALSE;
2321- if (e_fp) {
2322- fclose(e_fp);
2323- e_fp = Nullfp;
2324+ if (e_tmpname) {
2325 (void)UNLINK(e_tmpname);
2326+ Safefree(e_tmpname);
2327+ e_tmpname = Nullch;
2328 }
2329
2330 /* now that script is parsed, we can modify record separator */
2331@@ -1369,7 +1371,7 @@ SV *sv;
2332 scriptname = xfound;
2333 }
2334
2335- origfilename = savepv(e_fp ? "-e" : scriptname);
2336+ origfilename = savepv(e_tmpname ? "-e" : scriptname);
2337 curcop->cop_filegv = gv_fetchfile(origfilename);
2338 if (strEQ(origfilename,"-"))
2339 scriptname = "";
2340
2341EOPATCH
2342 }
2343
2344 if ($major < 3 && $^O eq 'openbsd'
2345 && !extract_from_file('pp_sys.c', qr/BSD_GETPGRP/)) {
2346 # Part of commit c3293030fd1b7489
2347 apply_patch(<<'EOPATCH');
2348diff --git a/pp_sys.c b/pp_sys.c
2349index 4608a2a..f0c9d1d 100644
2350--- a/pp_sys.c
2351+++ b/pp_sys.c
2352@@ -2903,8 +2903,8 @@ PP(pp_getpgrp)
2353 pid = 0;
2354 else
2355 pid = SvIVx(POPs);
2356-#ifdef USE_BSDPGRP
2357- value = (I32)getpgrp(pid);
2358+#ifdef BSD_GETPGRP
2359+ value = (I32)BSD_GETPGRP(pid);
2360 #else
2361 if (pid != 0)
2362 DIE("POSIX getpgrp can't take an argument");
2363@@ -2933,8 +2933,8 @@ PP(pp_setpgrp)
2364 }
2365
2366 TAINT_PROPER("setpgrp");
2367-#ifdef USE_BSDPGRP
2368- SETi( setpgrp(pid, pgrp) >= 0 );
2369+#ifdef BSD_SETPGRP
2370+ SETi( BSD_SETPGRP(pid, pgrp) >= 0 );
2371 #else
2372 if ((pgrp != 0) || (pid != 0)) {
2373 DIE("POSIX setpgrp can't take an argument");
2374EOPATCH
2375 }
2376
2377 if ($major < 4 && $^O eq 'openbsd') {
2378 my $bad;
2379 # Need changes from commit a6e633defa583ad5.
2380 # Commits c07a80fdfe3926b5 and f82b3d4130164d5f changed the same part
2381 # of perl.h
2382
2383 if (extract_from_file('perl.h',
2384 qr/^#ifdef HAS_GETPGRP2$/)) {
2385 $bad = <<'EOBAD';
2386***************
2387*** 57,71 ****
2388 #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s)
2389 #define TAINT_ENV() if (tainting) taint_env()
2390
2391! #ifdef HAS_GETPGRP2
2392! # ifndef HAS_GETPGRP
2393! # define HAS_GETPGRP
2394! # endif
2395! #endif
2396!
2397! #ifdef HAS_SETPGRP2
2398! # ifndef HAS_SETPGRP
2399! # define HAS_SETPGRP
2400! # endif
2401 #endif
2402
2403EOBAD
2404 } elsif (extract_from_file('perl.h',
2405 qr/Gack, you have one but not both of getpgrp2/)) {
2406 $bad = <<'EOBAD';
2407***************
2408*** 56,76 ****
2409 #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s)
2410 #define TAINT_ENV() if (tainting) taint_env()
2411
2412! #if defined(HAS_GETPGRP2) && defined(HAS_SETPGRP2)
2413! # define getpgrp getpgrp2
2414! # define setpgrp setpgrp2
2415! # ifndef HAS_GETPGRP
2416! # define HAS_GETPGRP
2417! # endif
2418! # ifndef HAS_SETPGRP
2419! # define HAS_SETPGRP
2420! # endif
2421! # ifndef USE_BSDPGRP
2422! # define USE_BSDPGRP
2423! # endif
2424! #else
2425! # if defined(HAS_GETPGRP2) || defined(HAS_SETPGRP2)
2426! #include "Gack, you have one but not both of getpgrp2() and setpgrp2()."
2427! # endif
2428 #endif
2429
2430EOBAD
2431 } elsif (extract_from_file('perl.h',
2432 qr/^#ifdef USE_BSDPGRP$/)) {
2433 $bad = <<'EOBAD'
2434***************
2435*** 91,116 ****
2436 #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s)
2437 #define TAINT_ENV() if (tainting) taint_env()
2438
2439! #ifdef USE_BSDPGRP
2440! # ifdef HAS_GETPGRP
2441! # define BSD_GETPGRP(pid) getpgrp((pid))
2442! # endif
2443! # ifdef HAS_SETPGRP
2444! # define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
2445! # endif
2446! #else
2447! # ifdef HAS_GETPGRP2
2448! # define BSD_GETPGRP(pid) getpgrp2((pid))
2449! # ifndef HAS_GETPGRP
2450! # define HAS_GETPGRP
2451! # endif
2452! # endif
2453! # ifdef HAS_SETPGRP2
2454! # define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
2455! # ifndef HAS_SETPGRP
2456! # define HAS_SETPGRP
2457! # endif
2458! # endif
2459 #endif
2460
2461 #ifndef _TYPES_ /* If types.h defines this it's easy. */
2462EOBAD
2463 }
2464 if ($bad) {
2465 apply_patch(<<"EOPATCH");
2466*** a/perl.h 2011-10-21 09:46:12.000000000 +0200
2467--- b/perl.h 2011-10-21 09:46:12.000000000 +0200
2468$bad--- 91,144 ----
2469 #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s)
2470 #define TAINT_ENV() if (tainting) taint_env()
2471
2472! /* XXX All process group stuff is handled in pp_sys.c. Should these
2473! defines move there? If so, I could simplify this a lot. --AD 9/96.
2474! */
2475! /* Process group stuff changed from traditional BSD to POSIX.
2476! perlfunc.pod documents the traditional BSD-style syntax, so we'll
2477! try to preserve that, if possible.
2478! */
2479! #ifdef HAS_SETPGID
2480! # define BSD_SETPGRP(pid, pgrp) setpgid((pid), (pgrp))
2481! #else
2482! # if defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP)
2483! # define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
2484! # else
2485! # ifdef HAS_SETPGRP2 /* DG/UX */
2486! # define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
2487! # endif
2488! # endif
2489! #endif
2490! #if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP)
2491! # define HAS_SETPGRP /* Well, effectively it does . . . */
2492! #endif
2493!
2494! /* getpgid isn't POSIX, but at least Solaris and Linux have it, and it makes
2495! our life easier :-) so we'll try it.
2496! */
2497! #ifdef HAS_GETPGID
2498! # define BSD_GETPGRP(pid) getpgid((pid))
2499! #else
2500! # if defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP)
2501! # define BSD_GETPGRP(pid) getpgrp((pid))
2502! # else
2503! # ifdef HAS_GETPGRP2 /* DG/UX */
2504! # define BSD_GETPGRP(pid) getpgrp2((pid))
2505! # endif
2506! # endif
2507! #endif
2508! #if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP)
2509! # define HAS_GETPGRP /* Well, effectively it does . . . */
2510! #endif
2511!
2512! /* These are not exact synonyms, since setpgrp() and getpgrp() may
2513! have different behaviors, but perl.h used to define USE_BSDPGRP
2514! (prior to 5.003_05) so some extension might depend on it.
2515! */
2516! #if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP)
2517! # ifndef USE_BSDPGRP
2518! # define USE_BSDPGRP
2519! # endif
2520 #endif
2521
2522 #ifndef _TYPES_ /* If types.h defines this it's easy. */
2523EOPATCH
2524 }
2525 }
2526
8245f086
NC
2527 if ($major < 4 && $^O eq 'hpux'
2528 && extract_from_file('sv.c', qr/i = _filbuf\(/)) {
2529 apply_patch(<<'EOPATCH');
2530diff --git a/sv.c b/sv.c
2531index a1f1d60..0a806f1 100644
2532--- a/sv.c
2533+++ b/sv.c
2534@@ -2641,7 +2641,7 @@ I32 append;
2535
2536 FILE_cnt(fp) = cnt; /* deregisterize cnt and ptr */
2537 FILE_ptr(fp) = ptr;
2538- i = _filbuf(fp); /* get more characters */
2539+ i = __filbuf(fp); /* get more characters */
2540 cnt = FILE_cnt(fp);
2541 ptr = FILE_ptr(fp); /* reregisterize cnt and ptr */
2542
2543
2544EOPATCH
2545 }
2546
bb723266
NC
2547 if ($major == 4 && extract_from_file('scope.c', qr/\(SV\*\)SSPOPINT/)) {
2548 # [PATCH] 5.004_04 +MAINT_TRIAL_1 broken when sizeof(int) != sizeof(void)
2549 # Fixes a bug introduced in 161b7d1635bc830b
2550 apply_commit('9002cb76ec83ef7f');
2551 }
2552
2553 if ($major == 4 && extract_from_file('av.c', qr/AvARRAY\(av\) = 0;/)) {
2554 # Fixes a bug introduced in 1393e20655efb4bc
2555 apply_commit('e1c148c28bf3335b', 'av.c');
2556 }
2557
6626a474
NC
2558 if ($major == 4) {
2559 my $rest = extract_from_file('perl.c', qr/delimcpy(.*)/);
2560 if (defined $rest and $rest !~ /,$/) {
2561 # delimcpy added in fc36a67e8855d031, perl.c refactored to use it.
2562 # bug introduced in 2a92aaa05aa1acbf, fixed in 8490252049bf42d3
2563 # code then moved to util.c in commit 491527d0220de34e
2564 apply_patch(<<'EOPATCH');
bb723266
NC
2565diff --git a/perl.c b/perl.c
2566index 4eb69e3..54bbb00 100644
2567--- a/perl.c
2568+++ b/perl.c
2569@@ -1735,7 +1735,7 @@ SV *sv;
2570 if (len < sizeof tokenbuf)
2571 tokenbuf[len] = '\0';
2572 #else /* ! (atarist || DOSISH) */
2573- s = delimcpy(tokenbuf, tokenbuf + sizeof tokenbuf, s, bufend
2574+ s = delimcpy(tokenbuf, tokenbuf + sizeof tokenbuf, s, bufend,
2575 ':',
2576 &len);
2577 #endif /* ! (atarist || DOSISH) */
2578EOPATCH
6626a474 2579 }
bb723266
NC
2580 }
2581
2582 if ($major == 4 && $^O eq 'linux') {
2583 # Whilst this is fixed properly in f0784f6a4c3e45e1 which provides the
2584 # Configure probe, it's easier to back out the problematic changes made
2585 # in these previous commits:
2586 if (extract_from_file('doio.c',
2587 qr!^/\* XXX REALLY need metaconfig test \*/$!)) {
2588 revert_commit('4682965a1447ea44', 'doio.c');
2589 }
2590 if (my $token = extract_from_file('doio.c',
2591 qr!^#if (defined\(__sun(?:__)?\)) && defined\(__svr4__\) /\* XXX Need metaconfig test \*/$!)) {
2592 my $patch = `git show -R 9b599b2a63d2324d doio.c`;
2593 $patch =~ s/defined\(__sun__\)/$token/g;
2594 apply_patch($patch);
2595 }
2596 if (extract_from_file('doio.c',
2597 qr!^/\* linux \(and Solaris2\?\) uses :$!)) {
2598 revert_commit('8490252049bf42d3', 'doio.c');
2599 }
2600 if (extract_from_file('doio.c',
2601 qr/^ unsemds.buf = &semds;$/)) {
2602 revert_commit('8e591e46b4c6543e');
2603 }
2604 if (extract_from_file('doio.c',
2605 qr!^#ifdef __linux__ /\* XXX Need metaconfig test \*/$!)) {
2606 # Reverts part of commit 3e3baf6d63945cb6
2607 apply_patch(<<'EOPATCH');
2608diff --git b/doio.c a/doio.c
2609index 62b7de9..0d57425 100644
2610--- b/doio.c
2611+++ a/doio.c
2612@@ -1333,9 +1331,6 @@ SV **sp;
2613 char *a;
2614 I32 id, n, cmd, infosize, getinfo;
2615 I32 ret = -1;
2616-#ifdef __linux__ /* XXX Need metaconfig test */
2617- union semun unsemds;
2618-#endif
2619
2620 id = SvIVx(*++mark);
2621 n = (optype == OP_SEMCTL) ? SvIVx(*++mark) : 0;
2622@@ -1364,29 +1359,11 @@ SV **sp;
2623 infosize = sizeof(struct semid_ds);
2624 else if (cmd == GETALL || cmd == SETALL)
2625 {
2626-#ifdef __linux__ /* XXX Need metaconfig test */
2627-/* linux uses :
2628- int semctl (int semid, int semnun, int cmd, union semun arg)
2629-
2630- union semun {
2631- int val;
2632- struct semid_ds *buf;
2633- ushort *array;
2634- };
2635-*/
2636- union semun semds;
2637- if (semctl(id, 0, IPC_STAT, semds) == -1)
2638-#else
2639 struct semid_ds semds;
2640 if (semctl(id, 0, IPC_STAT, &semds) == -1)
2641-#endif
2642 return -1;
2643 getinfo = (cmd == GETALL);
2644-#ifdef __linux__ /* XXX Need metaconfig test */
2645- infosize = semds.buf->sem_nsems * sizeof(short);
2646-#else
2647 infosize = semds.sem_nsems * sizeof(short);
2648-#endif
2649 /* "short" is technically wrong but much more portable
2650 than guessing about u_?short(_t)? */
2651 }
2652@@ -1429,12 +1406,7 @@ SV **sp;
2653 #endif
2654 #ifdef HAS_SEM
2655 case OP_SEMCTL:
2656-#ifdef __linux__ /* XXX Need metaconfig test */
2657- unsemds.buf = (struct semid_ds *)a;
2658- ret = semctl(id, n, cmd, unsemds);
2659-#else
2660 ret = semctl(id, n, cmd, (struct semid_ds *)a);
2661-#endif
2662 break;
2663 #endif
2664 #ifdef HAS_SHM
2665EOPATCH
2666 }
2667 # Incorrect prototype added as part of 8ac853655d9b7447, fixed as part
2668 # of commit dc45a647708b6c54, with at least one intermediate
2669 # modification. Correct prototype for gethostbyaddr has socklen_t
2670 # second. Linux has uint32_t first for getnetbyaddr.
2671 # Easiest just to remove, instead of attempting more complex patching.
2672 # Something similar may be needed on other platforms.
2673 edit_file('pp_sys.c', sub {
2674 my $code = shift;
2675 $code =~ s/^ struct hostent \*(?:PerlSock_)?gethostbyaddr\([^)]+\);$//m;
2676 $code =~ s/^ struct netent \*getnetbyaddr\([^)]+\);$//m;
2677 return $code;
2678 });
2679 }
2680
d1ac19b7
NC
2681 if ($major < 5 && $^O eq 'aix'
2682 && !extract_from_file('pp_sys.c',
2683 qr/defined\(HOST_NOT_FOUND\) && !defined\(h_errno\)/)) {
2684 # part of commit dc45a647708b6c54
2685 # Andy Dougherty's configuration patches (Config_63-01 up to 04).
2686 apply_patch(<<'EOPATCH')
2687diff --git a/pp_sys.c b/pp_sys.c
2688index c2fcb6f..efa39fb 100644
2689--- a/pp_sys.c
2690+++ b/pp_sys.c
2691@@ -54,7 +54,7 @@ extern "C" int syscall(unsigned long,...);
2692 #endif
2693 #endif
2694
2695-#ifdef HOST_NOT_FOUND
2696+#if defined(HOST_NOT_FOUND) && !defined(h_errno)
2697 extern int h_errno;
2698 #endif
2699
2700EOPATCH
2701 }
2702
df01cf53 2703 if ($major == 5
31940c07
NC
2704 && `git rev-parse HEAD` eq "22c35a8c2392967a5ba6b5370695be464bd7012c\n") {
2705 # Commit 22c35a8c2392967a is significant,
2706 # "phase 1 of somewhat major rearrangement of PERL_OBJECT stuff"
2707 # but doesn't build due to 2 simple errors. blead in this broken state
2708 # was merged to the cfgperl branch, and then these were immediately
2709 # corrected there. cfgperl (with the fixes) was merged back to blead.
2710 # The resultant rather twisty maze of commits looks like this:
2711
911bfca9 2712=begin comment
31940c07
NC
2713
2714* | | commit 137225782c183172f360c827424b9b9f8adbef0e
2715|\ \ \ Merge: 22c35a8 2a8ee23
2716| |/ / Author: Gurusamy Sarathy <gsar@cpan.org>
2717| | | Date: Fri Oct 30 17:38:36 1998 +0000
2718| | |
2719| | | integrate cfgperl tweaks into mainline
2720| | |
2721| | | p4raw-id: //depot/perl@2144
2722| | |
2723| * | commit 2a8ee23279873759693fa83eca279355db2b665c
2724| | | Author: Jarkko Hietaniemi <jhi@iki.fi>
2725| | | Date: Fri Oct 30 13:27:39 1998 +0000
2726| | |
2727| | | There can be multiple yacc/bison errors.
2728| | |
2729| | | p4raw-id: //depot/cfgperl@2143
2730| | |
2731| * | commit 93fb2ac393172fc3e2c14edb20b718309198abbc
2732| | | Author: Jarkko Hietaniemi <jhi@iki.fi>
2733| | | Date: Fri Oct 30 13:18:43 1998 +0000
2734| | |
2735| | | README.posix-bc update.
2736| | |
2737| | | p4raw-id: //depot/cfgperl@2142
2738| | |
2739| * | commit 4ec43091e8e6657cb260b5e563df30aaa154effe
2740| | | Author: Jarkko Hietaniemi <jhi@iki.fi>
2741| | | Date: Fri Oct 30 09:12:59 1998 +0000
2742| | |
2743| | | #2133 fallout.
2744| | |
2745| | | p4raw-id: //depot/cfgperl@2141
2746| | |
2747| * | commit 134ca994cfefe0f613d43505a885e4fc2100b05c
2748| |\ \ Merge: 7093112 22c35a8
2749| |/ / Author: Jarkko Hietaniemi <jhi@iki.fi>
2750|/| | Date: Fri Oct 30 08:43:18 1998 +0000
2751| | |
2752| | | Integrate from mainperl.
2753| | |
2754| | | p4raw-id: //depot/cfgperl@2140
2755| | |
2756* | | commit 22c35a8c2392967a5ba6b5370695be464bd7012c
2757| | | Author: Gurusamy Sarathy <gsar@cpan.org>
2758| | | Date: Fri Oct 30 02:51:39 1998 +0000
2759| | |
2760| | | phase 1 of somewhat major rearrangement of PERL_OBJECT stuff
2761| | | (objpp.h is gone, embed.pl now does some of that); objXSUB.h
2762| | | should soon be automated also; the global variables that
2763| | | escaped the PL_foo conversion are now reined in; renamed
2764| | | MAGIC in regcomp.h to REG_MAGIC to avoid collision with the
2765| | | type of same name; duplicated lists of pp_things in various
2766| | | places is now gone; result has only been tested on win32
2767| | |
2768| | | p4raw-id: //depot/perl@2133
2769
911bfca9
NC
2770=end comment
2771
31940c07
NC
2772=cut
2773
2774 # and completely confuses git bisect (and at least me), causing it to
2775 # the bisect run to confidently return the wrong answer, an unrelated
2776 # commit on the cfgperl branch.
2777
2778 apply_commit('4ec43091e8e6657c');
2779 }
2780
2781 if ($major == 5
df01cf53
NC
2782 && extract_from_file('pp_sys.c', qr/PERL_EFF_ACCESS_R_OK/)
2783 && !extract_from_file('pp_sys.c', qr/XXX Configure test needed for eaccess/)) {
2784 # Between 5ff3f7a4e03a6b10 and c955f1177b2e311d^
2785 # This is the meat of commit c955f1177b2e311d (without the other
2786 # indenting changes that would cause a conflict).
2787 # Without this 538 revisions won't build on (at least) Linux
2788 apply_patch(<<'EOPATCH');
2789diff --git a/pp_sys.c b/pp_sys.c
2790index d60c8dc..867dee4 100644
2791--- a/pp_sys.c
2792+++ b/pp_sys.c
2793@@ -198,9 +198,18 @@ static char zero_but_true[ZBTLEN + 1] = "0 but true";
2794 # if defined(I_SYS_SECURITY)
2795 # include <sys/security.h>
2796 # endif
2797-# define PERL_EFF_ACCESS_R_OK(p) (eaccess((p), R_OK, ACC_SELF))
2798-# define PERL_EFF_ACCESS_W_OK(p) (eaccess((p), W_OK, ACC_SELF))
2799-# define PERL_EFF_ACCESS_X_OK(p) (eaccess((p), X_OK, ACC_SELF))
2800+ /* XXX Configure test needed for eaccess */
2801+# ifdef ACC_SELF
2802+ /* HP SecureWare */
2803+# define PERL_EFF_ACCESS_R_OK(p) (eaccess((p), R_OK, ACC_SELF))
2804+# define PERL_EFF_ACCESS_W_OK(p) (eaccess((p), W_OK, ACC_SELF))
2805+# define PERL_EFF_ACCESS_X_OK(p) (eaccess((p), X_OK, ACC_SELF))
2806+# else
2807+ /* SCO */
2808+# define PERL_EFF_ACCESS_R_OK(p) (eaccess((p), R_OK))
2809+# define PERL_EFF_ACCESS_W_OK(p) (eaccess((p), W_OK))
2810+# define PERL_EFF_ACCESS_X_OK(p) (eaccess((p), X_OK))
2811+# endif
2812 #endif
2813
2814 #if !defined(PERL_EFF_ACCESS_R_OK) && defined(HAS_ACCESSX) && defined(ACC_SELF)
2815EOPATCH
2816 }
2817
bb35dd48
NC
2818 if ($major == 5
2819 && extract_from_file('mg.c', qr/If we're still on top of the stack, pop us off/)
af6a5d0e 2820 && !extract_from_file('mg.c', qr/PL_savestack_ix -= popval/)) {
bb35dd48
NC
2821 # Fix up commit 455ece5e082708b1:
2822 # SSNEW() API for allocating memory on the savestack
2823 # Message-Id: <tqemtae338.fsf@puma.genscan.com>
2824 # Subject: [PATCH 5.005_51] (was: why SAVEDESTRUCTOR()...)
2825 apply_commit('3c8a44569607336e', 'mg.c');
2826 }
2827
6863570c
NC
2828 if ($major == 5) {
2829 if (extract_from_file('doop.c', qr/croak\(no_modify\);/)
2830 && extract_from_file('doop.c', qr/croak\(PL_no_modify\);/)) {
2831 # Whilst the log suggests that this would only fix 5 commits, in
2832 # practice this area of history is a complete tarpit, and git bisect
2833 # gets very confused by the skips in the middle of the back and
2834 # forth merging between //depot/perl and //depot/cfgperl
2835 apply_commit('6393042b638dafd3');
2836 }
2837
2838 # One error "fixed" with another:
2839 if (extract_from_file('pp_ctl.c',
2840 qr/\Qstatic void *docatch_body _((void *o));\E/)) {
2841 apply_commit('5b51e982882955fe');
2842 }
2843 # Which is then fixed by this:
2844 if (extract_from_file('pp_ctl.c',
2845 qr/\Qstatic void *docatch_body _((valist\E/)) {
2846 apply_commit('47aa779ee4c1a50e');
2847 }
2848
2849 if (extract_from_file('thrdvar.h', qr/PERLVARI\(Tprotect/)
2850 && !extract_from_file('embedvar.h', qr/PL_protect/)) {
2851 # Commit 312caa8e97f1c7ee didn't update embedvar.h
2852 apply_commit('e0284a306d2de082', 'embedvar.h');
2853 }
2854 }
2855
2856 if ($major == 5
2857 && extract_from_file('sv.c',
2858 qr/PerlDir_close\(IoDIRP\((?:\(IO\*\))?sv\)\);/)
2859 && !(extract_from_file('toke.c',
2860 qr/\QIoDIRP(FILTER_DATA(AvFILLp(PL_rsfp_filters))) = NULL\E/)
2861 || extract_from_file('toke.c',
2862 qr/\QIoDIRP(datasv) = (DIR*)NULL;\E/))) {
2863 # Commit 93578b34124e8a3b, //depot/perl@3298
2864 # close directory handles properly when localized,
2865 # tweaked slightly by commit 1236053a2c722e2b,
2866 # add test case for change#3298
2867 #
2868 # The fix is the last part of:
2869 #
2870 # various fixes for clean build and test on win32; configpm broken,
2871 # needed to open myconfig.SH rather than myconfig; sundry adjustments
2872 # to bytecode stuff; tweaks to DYNAMIC_ENV_FETCH code to make it
2873 # work under win32; getenv_sv() changed to getenv_len() since SVs
2874 # aren't visible in the lower echelons; remove bogus exports from
2875 # config.sym; PERL_OBJECT-ness for C++ exception support; null out
2876 # IoDIRP in filter_del() or sv_free() will attempt to close it
2877 #
2878 # The changed code is modified subsequently by commit e0c198038146b7a4
2879 apply_commit('a6c403648ecd5cc7', 'toke.c');
2880 }
2881
bb723266
NC
2882 if ($major < 6 && $^O eq 'netbsd'
2883 && !extract_from_file('unixish.h',
2884 qr/defined\(NSIG\).*defined\(__NetBSD__\)/)) {
2885 apply_patch(<<'EOPATCH')
2886diff --git a/unixish.h b/unixish.h
2887index 2a6cbcd..eab2de1 100644
2888--- a/unixish.h
2889+++ b/unixish.h
2890@@ -89,7 +89,7 @@
2891 */
2892 /* #define ALTERNATE_SHEBANG "#!" / **/
2893
2894-#if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
2895+#if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX) || defined(__NetBSD__)
2896 # include <signal.h>
2897 #endif
2898
2899EOPATCH
2900 }
2901
2902 if (($major >= 7 || $major <= 9) && $^O eq 'openbsd'
2903 && `uname -m` eq "sparc64\n"
2904 # added in 2000 by commit cb434fcc98ac25f5:
2905 && extract_from_file('regexec.c',
2906 qr!/\* No need to save/restore up to this paren \*/!)
2907 # re-indented in 2006 by commit 95b2444054382532:
2908 && extract_from_file('regexec.c', qr/^\t\tCURCUR cc;$/)) {
2909 # Need to work around a bug in (at least) OpenBSD's 4.6's sparc64 #
2910 # compiler ["gcc (GCC) 3.3.5 (propolice)"]. Between commits
2911 # 3ec562b0bffb8b8b (2002) and 1a4fad37125bac3e^ (2005) the darling thing
2912 # fails to compile any code for the statement cc.oldcc = PL_regcc;
2913 #
2914 # If you refactor the code to "fix" that, or force the issue using set
2915 # in the debugger, the stack smashing detection code fires on return
2916 # from S_regmatch(). Turns out that the compiler doesn't allocate any
2917 # (or at least enough) space for cc.
2918 #
2919 # Restore the "uninitialised" value for cc before function exit, and the
2920 # stack smashing code is placated. "Fix" 3ec562b0bffb8b8b (which
2921 # changes the size of auto variables used elsewhere in S_regmatch), and
2922 # the crash is visible back to bc517b45fdfb539b (which also changes
2923 # buffer sizes). "Unfix" 1a4fad37125bac3e and the crash is visible until
2924 # 5b47454deb66294b. Problem goes away if you compile with -O, or hack
2925 # the code as below.
2926 #
2927 # Hence this turns out to be a bug in (old) gcc. Not a security bug we
2928 # still need to fix.
2929 apply_patch(<<'EOPATCH');
2930diff --git a/regexec.c b/regexec.c
2931index 900b491..6251a0b 100644
2932--- a/regexec.c
2933+++ b/regexec.c
2934@@ -2958,7 +2958,11 @@ S_regmatch(pTHX_ regnode *prog)
2935 I,I
2936 *******************************************************************/
2937 case CURLYX: {
2938- CURCUR cc;
2939+ union {
2940+ CURCUR hack_cc;
2941+ char hack_buff[sizeof(CURCUR) + 1];
2942+ } hack;
2943+#define cc hack.hack_cc
2944 CHECKPOINT cp = PL_savestack_ix;
2945 /* No need to save/restore up to this paren */
2946 I32 parenfloor = scan->flags;
2947@@ -2983,6 +2987,7 @@ S_regmatch(pTHX_ regnode *prog)
2948 n = regmatch(PREVOPER(next)); /* start on the WHILEM */
2949 regcpblow(cp);
2950 PL_regcc = cc.oldcc;
2951+#undef cc
2952 saySAME(n);
2953 }
2954 /* NOT REACHED */
2955EOPATCH
2956}
2957
2958 if ($major < 8 && $^O eq 'openbsd'
2959 && !extract_from_file('perl.h', qr/include <unistd\.h>/)) {
2960 # This is part of commit 3f270f98f9305540, applied at a slightly
2961 # different location in perl.h, where the context is stable back to
2962 # 5.000
2963 apply_patch(<<'EOPATCH');
2964diff --git a/perl.h b/perl.h
2965index 9418b52..b8b1a7c 100644
2966--- a/perl.h
2967+++ b/perl.h
2968@@ -496,6 +496,10 @@ register struct op *Perl_op asm(stringify(OP_IN_REGISTER));
2969 # include <sys/param.h>
2970 #endif
2971
2972+/* If this causes problems, set i_unistd=undef in the hint file. */
2973+#ifdef I_UNISTD
2974+# include <unistd.h>
2975+#endif
2976
2977 /* Use all the "standard" definitions? */
2978 #if defined(STANDARD_C) && defined(I_STDLIB)
2979EOPATCH
2980 }
2981}
2982
f2f0a0ff
NC
2983sub patch_ext {
2984 if (-f 'ext/POSIX/Makefile.PL'
2985 && extract_from_file('ext/POSIX/Makefile.PL',
2986 qr/Explicitly avoid including/)) {
2987 # commit 6695a346c41138df, which effectively reverts 170888cff5e2ffb7
2988
2989 # PERL5LIB is populated by make_ext.pl with paths to the modules we need
2990 # to run, don't override this with "../../lib" since that may not have
2991 # been populated yet in a parallel build.
2992 apply_commit('6695a346c41138df');
2993 }
2994
06cebb71
NC
2995 if (-f 'ext/Hash/Util/Makefile.PL'
2996 && extract_from_file('ext/Hash/Util/Makefile.PL',
2997 qr/\bDIR\b.*'FieldHash'/)) {
2998 # ext/Hash/Util/Makefile.PL should not recurse to FieldHash's Makefile.PL
2999 # *nix, VMS and Win32 all know how to (and have to) call the latter directly.
3000 # As is, targets in ext/Hash/Util/FieldHash get called twice, which may result
3001 # in race conditions, and certainly messes up make clean; make distclean;
3002 apply_commit('550428fe486b1888');
3003 }
3004
f2f0a0ff
NC
3005 if ($major < 8 && $^O eq 'darwin' && !-f 'ext/DynaLoader/dl_dyld.xs') {
3006 checkout_file('ext/DynaLoader/dl_dyld.xs', 'f556e5b971932902');
3007 apply_patch(<<'EOPATCH');
3008diff -u a/ext/DynaLoader/dl_dyld.xs~ a/ext/DynaLoader/dl_dyld.xs
3009--- a/ext/DynaLoader/dl_dyld.xs~ 2011-10-11 21:41:27.000000000 +0100
3010+++ b/ext/DynaLoader/dl_dyld.xs 2011-10-11 21:42:20.000000000 +0100
3011@@ -41,6 +41,35 @@
3012 #include "perl.h"
3013 #include "XSUB.h"
3014
3015+#ifndef pTHX
3016+# define pTHX void
3017+# define pTHX_
3018+#endif
3019+#ifndef aTHX
3020+# define aTHX
3021+# define aTHX_
3022+#endif
3023+#ifndef dTHX
3024+# define dTHXa(a) extern int Perl___notused(void)
3025+# define dTHX extern int Perl___notused(void)
3026+#endif
3027+
3028+#ifndef Perl_form_nocontext
3029+# define Perl_form_nocontext form
3030+#endif
3031+
3032+#ifndef Perl_warn_nocontext
3033+# define Perl_warn_nocontext warn
3034+#endif
3035+
3036+#ifndef PTR2IV
3037+# define PTR2IV(p) (IV)(p)
3038+#endif
3039+
3040+#ifndef get_av
3041+# define get_av perl_get_av
3042+#endif
3043+
3044 #define DL_LOADONCEONLY
3045
3046 #include "dlutils.c" /* SaveError() etc */
3047@@ -185,7 +191,7 @@
3048 CODE:
3049 DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s,%x):\n", filename,flags));
3050 if (flags & 0x01)
3051- Perl_warn(aTHX_ "Can't make loaded symbols global on this platform while loading %s",filename);
3052+ Perl_warn_nocontext("Can't make loaded symbols global on this platform while loading %s",filename);
3053 RETVAL = dlopen(filename, mode) ;
3054 DLDEBUG(2,PerlIO_printf(Perl_debug_log, " libref=%x\n", RETVAL));
3055 ST(0) = sv_newmortal() ;
3056EOPATCH
3057 if ($major < 4 && !extract_from_file('util.c', qr/^form/m)) {
3058 apply_patch(<<'EOPATCH');
3059diff -u a/ext/DynaLoader/dl_dyld.xs~ a/ext/DynaLoader/dl_dyld.xs
3060--- a/ext/DynaLoader/dl_dyld.xs~ 2011-10-11 21:56:25.000000000 +0100
3061+++ b/ext/DynaLoader/dl_dyld.xs 2011-10-11 22:00:00.000000000 +0100
3062@@ -60,6 +60,18 @@
3063 # define get_av perl_get_av
3064 #endif
3065
3066+static char *
3067+form(char *pat, ...)
3068+{
3069+ char *retval;
3070+ va_list args;
3071+ va_start(args, pat);
3072+ vasprintf(&retval, pat, &args);
3073+ va_end(args);
3074+ SAVEFREEPV(retval);
3075+ return retval;
3076+}
3077+
3078 #define DL_LOADONCEONLY
3079
3080 #include "dlutils.c" /* SaveError() etc */
3081EOPATCH
3082 }
3083 }
3084
3085 if ($major < 10) {
3086 if (!extract_from_file('ext/DB_File/DB_File.xs',
3087 qr!^#else /\* Berkeley DB Version > 2 \*/$!)) {
3088 # This DB_File.xs is really too old to patch up.
3089 # Skip DB_File, unless we're invoked with an explicit -Unoextensions
3090 if (!exists $defines{noextensions}) {
3091 $defines{noextensions} = 'DB_File';
3092 } elsif (defined $defines{noextensions}) {
3093 $defines{noextensions} .= ' DB_File';
3094 }
3095 } elsif (!extract_from_file('ext/DB_File/DB_File.xs',
3096 qr/^#ifdef AT_LEAST_DB_4_1$/)) {
3097 # This line is changed by commit 3245f0580c13b3ab
3098 my $line = extract_from_file('ext/DB_File/DB_File.xs',
3099 qr/^( status = \(?RETVAL->dbp->open\)?\(RETVAL->dbp, name, NULL, RETVAL->type, $)/);
3100 apply_patch(<<"EOPATCH");
3101diff --git a/ext/DB_File/DB_File.xs b/ext/DB_File/DB_File.xs
3102index 489ba96..fba8ded 100644
3103--- a/ext/DB_File/DB_File.xs
3104+++ b/ext/DB_File/DB_File.xs
3105\@\@ -183,4 +187,8 \@\@
3106 #endif
3107
3108+#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
3109+# define AT_LEAST_DB_4_1
3110+#endif
3111+
3112 /* map version 2 features & constants onto their version 1 equivalent */
3113
3114\@\@ -1334,7 +1419,12 \@\@ SV * sv ;
3115 #endif
3116
3117+#ifdef AT_LEAST_DB_4_1
3118+ status = (RETVAL->dbp->open)(RETVAL->dbp, NULL, name, NULL, RETVAL->type,
3119+ Flags, mode) ;
3120+#else
3121 $line
3122 Flags, mode) ;
3123+#endif
3124 /* printf("open returned %d %s\\n", status, db_strerror(status)) ; */
3125
3126EOPATCH
3127 }
3128 }
3129
3130 if ($major < 10 and -f 'ext/IPC/SysV/SysV.xs') {
3131 edit_file('ext/IPC/SysV/SysV.xs', sub {
3132 my $xs = shift;
3133 my $fixed = <<'EOFIX';
3134
3135#include <sys/types.h>
3136#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
3137#ifndef HAS_SEM
3138# include <sys/ipc.h>
3139#endif
3140# ifdef HAS_MSG
3141# include <sys/msg.h>
3142# endif
3143# ifdef HAS_SHM
3144# if defined(PERL_SCO) || defined(PERL_ISC)
3145# include <sys/sysmacros.h> /* SHMLBA */
3146# endif
3147# include <sys/shm.h>
3148# ifndef HAS_SHMAT_PROTOTYPE
3149 extern Shmat_t shmat (int, char *, int);
3150# endif
3151# if defined(HAS_SYSCONF) && defined(_SC_PAGESIZE)
3152# undef SHMLBA /* not static: determined at boot time */
3153# define SHMLBA sysconf(_SC_PAGESIZE)
3154# elif defined(HAS_GETPAGESIZE)
3155# undef SHMLBA /* not static: determined at boot time */
3156# define SHMLBA getpagesize()
3157# endif
3158# endif
3159#endif
3160EOFIX
3161 $xs =~ s!
3162#include <sys/types\.h>
3163.*
3164(#ifdef newCONSTSUB|/\* Required)!$fixed$1!ms;
3165 return $xs;
3166 });
3167 }
3168}
3169
df14fc13
NC
3170sub apply_fixups {
3171 my $fixups = shift;
3172 return unless $fixups;
3173 foreach my $file (@$fixups) {
3174 my $fh = open_or_die($file);
3175 my $line = <$fh>;
3176 close_or_die($fh);
3177 if ($line =~ /^#!perl\b/) {
3178 system $^X, $file
3179 and die_255("$^X $file failed: \$!=$!, \$?=$?");
3180 } elsif ($line =~ /^#!(\/\S+)/) {
3181 system $file
3182 and die_255("$file failed: \$!=$!, \$?=$?");
3183 } else {
3184 if (my ($target, $action, $pattern)
3185 = $line =~ m#^(\S+) ([=!])~ /(.*)/#) {
3186 if (length $pattern) {
3187 next unless -f $target;
3188 if ($action eq '=') {
3189 next unless extract_from_file($target, $pattern);
3190 } else {
3191 next if extract_from_file($target, $pattern);
3192 }
3193 } else {
3194 # Avoid the special case meaning of the empty pattern,
3195 # and instead use this to simply test for the file being
3196 # present or absent
3197 if ($action eq '=') {
3198 next unless -f $target;
3199 } else {
3200 next if -f $target;
3201 }
3202 }
3203 }
3204 system_or_die("patch -p1 <$file");
3205 }
3206 }
3207}
3208
9a999a97
NC
3209# Local variables:
3210# cperl-indent-level: 4
3211# indent-tabs-mode: nil
3212# End:
3213#
3214# ex: set ts=8 sts=4 sw=4 et: