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