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