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