Commit | Line | Data |
---|---|---|
6a8dbfd7 NC |
1 | #!/usr/bin/perl -w |
2 | use strict; | |
3 | ||
390a69a9 | 4 | use Getopt::Long qw(:config bundling no_auto_abbrev); |
77ae6092 | 5 | use Pod::Usage; |
2526f4b8 | 6 | use Config; |
69bf9aba | 7 | use Carp; |
6a8dbfd7 | 8 | |
2526f4b8 NC |
9 | my @targets |
10 | = qw(config.sh config.h miniperl lib/Config.pm Fcntl perl test_prep); | |
6a8dbfd7 | 11 | |
e4516dd0 NC |
12 | my $cpus; |
13 | if (open my $fh, '<', '/proc/cpuinfo') { | |
14 | while (<$fh>) { | |
15 | ++$cpus if /^processor\s+:\s+\d+$/; | |
16 | } | |
d64af352 NC |
17 | } elsif (-x '/sbin/sysctl') { |
18 | $cpus = 1 + $1 if `/sbin/sysctl hw.ncpu` =~ /^hw\.ncpu: (\d+)$/; | |
da83cd31 NC |
19 | } elsif (-x '/usr/bin/getconf') { |
20 | $cpus = 1 + $1 if `/usr/bin/getconf _NPROCESSORS_ONLN` =~ /^(\d+)$/; | |
e4516dd0 NC |
21 | } |
22 | ||
f4800c99 NC |
23 | my %options = |
24 | ( | |
e4516dd0 | 25 | jobs => defined $cpus ? $cpus + 1 : 2, |
f4800c99 NC |
26 | 'expect-pass' => 1, |
27 | clean => 1, # mostly for debugging this | |
28 | ); | |
6a8dbfd7 | 29 | |
fdbac266 NC |
30 | my $linux64 = `uname -sm` eq "Linux x86_64\n" ? '64' : ''; |
31 | ||
599ee4f7 NC |
32 | my @paths; |
33 | ||
34 | if ($^O eq 'linux') { | |
35 | # This is the search logic for a multi-arch library layout | |
36 | # added to linux.sh in commits 40f026236b9959b7 and dcffd848632af2c7. | |
37 | my $gcc = -x '/usr/bin/gcc' ? '/usr/bin/gcc' : 'gcc'; | |
38 | ||
39 | foreach (`$gcc -print-search-dirs`) { | |
40 | next unless /^libraries: =(.*)/; | |
41 | foreach (split ':', $1) { | |
42 | next if m/gcc/; | |
43 | next unless -d $_; | |
44 | s!/$!!; | |
45 | push @paths, $_; | |
46 | } | |
47 | } | |
48 | } | |
49 | ||
50 | push @paths, map {$_ . $linux64} qw(/usr/local/lib /lib /usr/lib); | |
390a69a9 NC |
51 | |
52 | my %defines = | |
53 | ( | |
54 | usedevel => '', | |
55 | optimize => '-g', | |
9913adee NC |
56 | cc => 'ccache cc', |
57 | ld => 'cc', | |
fdbac266 | 58 | ($linux64 ? (libpth => \@paths) : ()), |
390a69a9 NC |
59 | ); |
60 | ||
f4800c99 NC |
61 | unless(GetOptions(\%options, |
62 | 'target=s', 'jobs|j=i', 'expect-pass=i', | |
63 | 'expect-fail' => sub { $options{'expect-pass'} = 0; }, | |
64 | 'clean!', 'one-liner|e=s', 'match=s', 'force-manifest', | |
bfa52998 NC |
65 | 'force-regen', 'test-build', 'check-args', 'A=s@', |
66 | 'usage|help|?', | |
390a69a9 NC |
67 | 'D=s@' => sub { |
68 | my (undef, $val) = @_; | |
69 | if ($val =~ /\A([^=]+)=(.*)/s) { | |
70 | $defines{$1} = length $2 ? $2 : "\0"; | |
71 | } else { | |
72 | $defines{$val} = ''; | |
73 | } | |
74 | }, | |
75 | 'U=s@' => sub { | |
76 | $defines{$_[1]} = undef; | |
77 | }, | |
6a8dbfd7 | 78 | )) { |
77ae6092 | 79 | pod2usage(exitval => 255, verbose => 1); |
6a8dbfd7 NC |
80 | } |
81 | ||
f4800c99 | 82 | my ($target, $j, $match) = @options{qw(target jobs match)}; |
e295b7be | 83 | |
77ae6092 NC |
84 | pod2usage(exitval => 255, verbose => 1) if $options{usage}; |
85 | pod2usage(exitval => 255, verbose => 1) | |
86 | unless @ARGV || $match || $options{'test-build'} || defined $options{'one-liner'}; | |
6a8dbfd7 | 87 | |
f4800c99 | 88 | exit 0 if $options{'check-args'}; |
6a8dbfd7 | 89 | |
77ae6092 NC |
90 | =head1 NAME |
91 | ||
92 | bisect.pl - use git bisect to pinpoint changes | |
93 | ||
94 | =head1 SYNOPSIS | |
95 | ||
96 | # When did this become an error? | |
97 | .../Porting/bisect.pl -e 'my $a := 2;' | |
71d80638 | 98 | # When did this stop being an error? |
77ae6092 NC |
99 | .../Porting/bisect.pl --expect-fail -e '1 // 2' |
100 | # When did this stop matching? | |
101 | .../Porting/bisect.pl --match '\b(?:PL_)hash_seed_set\b' | |
102 | # When did this start matching? | |
103 | .../Porting/bisect.pl --expect-fail --match '\buseithreads\b' | |
104 | # When did this test program stop working? | |
d398528a | 105 | .../Porting/bisect.pl -- ./perl -Ilib ../test_prog.pl |
77ae6092 NC |
106 | # When did this first become valid syntax? |
107 | .../Porting/bisect.pl --target=miniperl --end=v5.10.0 \ | |
108 | --expect-fail -e 'my $a := 2;' | |
109 | # What was the last revision to build with these options? | |
110 | .../Porting/bisect.pl --test-build -Dd_dosuid | |
111 | ||
112 | =head1 DESCRIPTION | |
113 | ||
facd1b88 | 114 | Together F<bisect.pl> and F<bisect-runner.pl> attempt to automate the use |
77ae6092 NC |
115 | of C<git bisect> as much as possible. With one command (and no other files) |
116 | it's easy to find out | |
117 | ||
118 | =over 4 | |
119 | ||
120 | =item * | |
121 | ||
122 | Which commit caused this example code to break? | |
123 | ||
124 | =item * | |
125 | ||
126 | Which commit caused this example code to start working? | |
127 | ||
128 | =item * | |
129 | ||
130 | Which commit added the first to match this regex? | |
131 | ||
132 | =item * | |
133 | ||
134 | Which commit removed the last to match this regex? | |
135 | ||
136 | =back | |
137 | ||
138 | usually without needing to know which versions of perl to use as start and | |
139 | end revisions. | |
140 | ||
facd1b88 | 141 | By default F<bisect.pl> will process all options, then use the rest of the |
77ae6092 NC |
142 | command line as arguments to list C<system> to run a test case. By default, |
143 | the test case should pass (exit with 0) on earlier perls, and fail (exit | |
facd1b88 | 144 | non-zero) on I<blead>. F<bisect.pl> will use F<bisect-runner.pl> to find the |
77ae6092 | 145 | earliest stable perl version on which the test case passes, check that it |
facd1b88 | 146 | fails on blead, and then use F<bisect-runner.pl> with C<git bisect run> to |
77ae6092 NC |
147 | find the commit which caused the failure. |
148 | ||
149 | Because the test case is the complete argument to C<system>, it is easy to | |
150 | run something other than the F<perl> built, if necessary. If you need to run | |
151 | the perl built, you'll probably need to invoke it as C<./perl -Ilib ...> | |
152 | ||
5842706e NC |
153 | You need a clean checkout to run a bisect, and you can't use the checkout |
154 | which contains F<Porting/bisect.pl> (because C<git bisect>) will check out | |
155 | a revision before F<Porting/bisect-runner.pl> was added, which | |
156 | C<git bisect run> needs). If your working checkout is called F<perl>, the | |
157 | simplest solution is to make a local clone, and run from that. I<i.e.>: | |
158 | ||
159 | cd .. | |
160 | git clone perl perl2 | |
161 | cd perl2 | |
162 | ../perl/Porting/bisect.pl ... | |
163 | ||
facd1b88 | 164 | By default, F<bisect-runner.pl> will automatically disable the build of |
cfadff5f NC |
165 | L<DB_File> for commits earlier than ccb44e3bf3be2c30, as it's not practical |
166 | to patch DB_File 1.70 and earlier to build with current Berkeley DB headers. | |
167 | (ccb44e3bf3be2c30 was in September 1999, between 5.005_62 and 5.005_63.) | |
168 | If your F<db.h> is old enough you can override this with C<-Unoextensions>. | |
169 | ||
77ae6092 NC |
170 | =head1 OPTIONS |
171 | ||
172 | =over 4 | |
173 | ||
174 | =item * | |
175 | ||
176 | --start I<commit-ish> | |
177 | ||
178 | Earliest revision to test, as a I<commit-ish> (a tag, commit or anything | |
facd1b88 | 179 | else C<git> understands as a revision). If not specified, F<bisect.pl> will |
77ae6092 NC |
180 | search stable perl releases from 5.002 to 5.14.0 until it finds one where |
181 | the test case passes. | |
182 | ||
183 | =item * | |
184 | ||
185 | --end I<commit-ish> | |
186 | ||
187 | Most recent revision to test, as a I<commit-ish>. If not specified, defaults | |
b4f0ec5f | 188 | to I<blead>. |
77ae6092 NC |
189 | |
190 | =item * | |
191 | ||
192 | --target I<target> | |
193 | ||
194 | F<Makefile> target (or equivalent) needed, to run the test case. If specified, | |
195 | this should be one of | |
196 | ||
197 | =over 4 | |
198 | ||
199 | =item * | |
200 | ||
201 | I<config.sh> | |
202 | ||
facd1b88 | 203 | Just run F<./Configure> |
77ae6092 NC |
204 | |
205 | =item * | |
206 | ||
207 | I<config.h> | |
208 | ||
209 | Run the various F<*.SH> files to generate F<Makefile>, F<config.h>, I<etc>. | |
210 | ||
211 | =item * | |
212 | ||
213 | I<miniperl> | |
214 | ||
215 | Build F<miniperl>. | |
216 | ||
217 | =item * | |
218 | ||
219 | I<lib/Config.pm> | |
220 | ||
221 | Use F<miniperl> to build F<lib/Config.pm> | |
222 | ||
223 | =item * | |
224 | ||
2526f4b8 NC |
225 | I<Fcntl> |
226 | ||
227 | Build F<lib/auto/Fcntl/Fnctl.so> (strictly, C<.$Config{so}>). As L<Fcntl> | |
228 | is simple XS module present since 5.000, this provides a fast test of | |
b4f0ec5f | 229 | whether XS modules can be built. Note, XS modules are built by F<miniperl>, |
2526f4b8 NC |
230 | hence this target will not build F<perl>. |
231 | ||
232 | =item * | |
233 | ||
77ae6092 NC |
234 | I<perl> |
235 | ||
236 | Build F<perl>. This also builds pure-Perl modules in F<cpan>, F<dist> and | |
2526f4b8 NC |
237 | F<ext>. XS modules (such as L<Fcntl>) are not built. |
238 | ||
239 | =item * | |
240 | ||
77ae6092 NC |
241 | I<test_prep> |
242 | ||
243 | Build everything needed to run the tests. This is the default if we're | |
244 | running test code, but is time consuming, as it means building all | |
b4f0ec5f | 245 | XS modules. For older F<Makefile>s, the previous name of C<test-prep> |
77ae6092 NC |
246 | is automatically substituted. For very old F<Makefile>s, C<make test> is |
247 | run, as there is no target provided to just get things ready, and for 5.004 | |
248 | and earlier the tests run very quickly. | |
249 | ||
250 | =back | |
251 | ||
252 | =item * | |
253 | ||
254 | --one-liner 'code to run' | |
255 | ||
256 | =item * | |
257 | ||
258 | -e 'code to run' | |
259 | ||
a1756669 | 260 | Example code to run, just like you'd use with C<perl -e>. |
77ae6092 NC |
261 | |
262 | This prepends C<./perl -Ilib -e 'code to run'> to the test case given, | |
facd1b88 | 263 | or F<./miniperl> if I<target> is C<miniperl>. |
77ae6092 NC |
264 | |
265 | (Usually you'll use C<-e> instead of providing a test case in the | |
facd1b88 | 266 | non-option arguments to F<bisect.pl>) |
77ae6092 NC |
267 | |
268 | C<-E> intentionally isn't supported, as it's an error in 5.8.0 and earlier, | |
269 | which interferes with detecting errors in the example code itself. | |
270 | ||
271 | =item * | |
272 | ||
273 | --expect-fail | |
274 | ||
275 | The test case should fail for the I<start> revision, and pass for the I<end> | |
276 | revision. The bisect run will find the first commit where it passes. | |
277 | ||
278 | =item * | |
279 | ||
af7c500f | 280 | -Dnoextensions=Encode |
77ae6092 NC |
281 | |
282 | =item * | |
283 | ||
284 | -Uusedevel | |
285 | ||
286 | =item * | |
287 | ||
288 | -Accflags=-DNO_MATHOMS | |
289 | ||
290 | Arguments to pass to F<Configure>. Repeated C<-A> arguments are passed | |
291 | through as is. C<-D> and C<-U> are processed in order, and override | |
af7c500f NC |
292 | previous settings for the same parameter. F<bisect-runner.pl> emulates |
293 | C<-Dnoextensions> when F<Configure> itself does not provide it, as it's | |
294 | often very useful to be able to disable some XS extensions. | |
77ae6092 NC |
295 | |
296 | =item * | |
297 | ||
b4f0ec5f | 298 | --jobs I<jobs> |
77ae6092 NC |
299 | |
300 | =item * | |
301 | ||
b4f0ec5f | 302 | -j I<jobs> |
77ae6092 | 303 | |
da83cd31 NC |
304 | Number of C<make> jobs to run in parallel. If F</proc/cpuinfo> exists and |
305 | can be parsed, or F</sbin/sysctl> exists and reports C<hw.ncpu>, or | |
306 | F</usr/bin/getconf> exists and reports C<_NPROCESSORS_ONLN> defaults to 1 + | |
307 | I<number of CPUs>. Otherwise defaults to 2. | |
77ae6092 NC |
308 | |
309 | =item * | |
310 | ||
b4f0ec5f | 311 | --match pattern |
77ae6092 NC |
312 | |
313 | Instead of running a test program to determine I<pass> or I<fail>, pass | |
314 | if the given regex matches, and hence search for the commit that removes | |
315 | the last matching file. | |
316 | ||
317 | If no I<target> is specified, the match is against all files in the | |
318 | repository (which is fast). If a I<target> is specified, that target is | |
319 | built, and the match is against only the built files. C<--expect-fail> can | |
320 | be used with C<--match> to search for a commit that adds files that match. | |
321 | ||
322 | =item * | |
323 | ||
324 | --test-build | |
325 | ||
326 | Test that the build completes, without running any test case. | |
327 | ||
328 | By default, if the build for the desired I<target> fails to complete, | |
329 | F<bisect-runner.pl> reports a I<skip> back to C<git bisect>, the assumption | |
330 | being that one wants to find a commit which changed state "builds && passes" | |
331 | to "builds && fails". If instead one is interested in which commit broke the | |
332 | build (possibly for particular F<Configure> options), use I<--test-build> | |
333 | to treat a build failure as a failure, not a "skip". | |
334 | ||
b4f0ec5f NC |
335 | Often this option isn't as useful as it first seems, because I<any> build |
336 | failure will be reported to C<git bisect> as a failure, not just the failure | |
337 | that you're interested in. Generally, to debug a particular problem, it's | |
338 | more useful to use a I<target> that builds properly at the point of interest, | |
339 | and then a test case that runs C<make>. For example: | |
340 | ||
341 | .../Porting/bisect.pl --start=perl-5.000 --end=perl-5.002 \ | |
342 | --expect-fail --force-manifest --target=miniperl make perl | |
343 | ||
facd1b88 NC |
344 | will find the first revision capable of building L<DynaLoader> and then |
345 | F<perl>, without becoming confused by revisions where F<miniperl> won't | |
b4f0ec5f NC |
346 | even link. |
347 | ||
77ae6092 NC |
348 | =item * |
349 | ||
b4f0ec5f NC |
350 | --force-manifest |
351 | ||
77ae6092 NC |
352 | By default, a build will "skip" if any files listed in F<MANIFEST> are not |
353 | present. Usually this is useful, as it avoids false-failures. However, there | |
354 | are some long ranges of commits where listed files are missing, which can | |
355 | cause a bisect to abort because all that remain are skipped revisions. | |
356 | ||
357 | In these cases, particularly if the test case uses F<miniperl> and no modules, | |
358 | it may be more useful to force the build to continue, even if files | |
359 | F<MANIFEST> are missing. | |
360 | ||
361 | =item * | |
362 | ||
bfa52998 NC |
363 | --force-regen |
364 | ||
365 | Run C<make regen_headers> before building F<miniperl>. This may fix a build | |
366 | that otherwise would skip because the generated headers at that revision | |
367 | are stale. It's not the default because it conceals this error in the true | |
368 | state of such revisions. | |
369 | ||
370 | =item * | |
371 | ||
77ae6092 NC |
372 | --expect-pass [0|1] |
373 | ||
374 | C<--expect-pass=0> is equivalent to C<--expect-fail>. I<1> is the default. | |
375 | ||
376 | =item * | |
377 | ||
378 | --no-clean | |
379 | ||
380 | Tell F<bisect-runner.pl> not to clean up after the build. This allows one | |
381 | to use F<bisect-runner.pl> to build the current particular perl revision for | |
382 | interactive testing, or for debugging F<bisect-runner.pl>. | |
383 | ||
384 | Passing this to F<bisect.pl> will likely cause the bisect to fail badly. | |
385 | ||
386 | =item * | |
387 | ||
195ed8b1 NC |
388 | --validate |
389 | ||
3f14869b NC |
390 | Test that all stable revisions can be built. By default, attempts to build |
391 | I<blead>, I<v5.14.0> .. I<perl-5.002>. Stops at the first failure, without | |
392 | cleaning the checkout. Use I<--start> to specify the earliest revision to | |
393 | test, I<--end> to specify the most recent. Useful for validating a new | |
195ed8b1 NC |
394 | OS/CPU/compiler combination. For example |
395 | ||
396 | ../perl/Porting/bisect.pl --validate -e'print "Hello from $]\n"' | |
397 | ||
398 | =item * | |
399 | ||
77ae6092 NC |
400 | --check-args |
401 | ||
402 | Validate the options and arguments, and exit silently if they are valid. | |
403 | ||
404 | =item * | |
405 | ||
406 | --usage | |
407 | ||
408 | =item * | |
409 | ||
410 | --help | |
411 | ||
412 | =item * | |
413 | ||
414 | -? | |
415 | ||
416 | Display the usage information and exit. | |
417 | ||
418 | =back | |
419 | ||
420 | =cut | |
421 | ||
0afef97d | 422 | die "$0: Can't build $target" if defined $target && !grep {@targets} $target; |
6a8dbfd7 NC |
423 | |
424 | $j = "-j$j" if $j =~ /\A\d+\z/; | |
425 | ||
0142f0ce NC |
426 | # Sadly, however hard we try, I don't think that it will be possible to build |
427 | # modules in ext/ on x86_64 Linux before commit e1666bf5602ae794 on 1999/12/29, | |
428 | # which updated to MakeMaker 3.7, which changed from using a hard coded ld | |
429 | # in the Makefile to $(LD). On x86_64 Linux the "linker" is gcc. | |
430 | ||
69bf9aba NC |
431 | sub open_or_die { |
432 | my $file = shift; | |
433 | my $mode = @_ ? shift : '<'; | |
434 | open my $fh, $mode, $file or croak("Can't open $file: $!"); | |
435 | ${*$fh{SCALAR}} = $file; | |
436 | return $fh; | |
437 | } | |
438 | ||
439 | sub close_or_die { | |
440 | my $fh = shift; | |
441 | return if close $fh; | |
442 | croak("Can't close: $!") unless ref $fh eq 'GLOB'; | |
443 | croak("Can't close ${*$fh{SCALAR}}: $!"); | |
444 | } | |
445 | ||
6a8dbfd7 NC |
446 | sub extract_from_file { |
447 | my ($file, $rx, $default) = @_; | |
69bf9aba | 448 | my $fh = open_or_die($file); |
6a8dbfd7 NC |
449 | while (<$fh>) { |
450 | my @got = $_ =~ $rx; | |
451 | return wantarray ? @got : $got[0] | |
452 | if @got; | |
453 | } | |
454 | return $default if defined $default; | |
455 | return; | |
456 | } | |
457 | ||
c59e8fd6 NC |
458 | sub edit_file { |
459 | my ($file, $munger) = @_; | |
460 | local $/; | |
69bf9aba | 461 | my $fh = open_or_die($file); |
c59e8fd6 NC |
462 | my $orig = <$fh>; |
463 | die "Can't read $file: $!" unless defined $orig && close $fh; | |
464 | my $new = $munger->($orig); | |
465 | return if $new eq $orig; | |
69bf9aba | 466 | $fh = open_or_die($file, '>'); |
c59e8fd6 | 467 | print $fh $new or die "Can't print to $file: $!"; |
69bf9aba | 468 | close_or_die($fh); |
c59e8fd6 NC |
469 | } |
470 | ||
471 | sub apply_patch { | |
472 | my $patch = shift; | |
473 | ||
05cd3ce5 | 474 | my ($file) = $patch =~ qr!^--- a/(\S+)\n\+\+\+ b/\1!sm; |
c59e8fd6 NC |
475 | open my $fh, '|-', 'patch', '-p1' or die "Can't run patch: $!"; |
476 | print $fh $patch; | |
5fceabf3 NC |
477 | return if close $fh; |
478 | print STDERR "Patch is <<'EOPATCH'\n${patch}EOPATCH\n"; | |
479 | die "Can't patch $file: $?, $!"; | |
c59e8fd6 NC |
480 | } |
481 | ||
4e540a4e NC |
482 | sub apply_commit { |
483 | my ($commit, @files) = @_; | |
484 | return unless system "git show $commit @files | patch -p1"; | |
485 | die "Can't apply commit $commit to @files" if @files; | |
486 | die "Can't apply commit $commit"; | |
487 | } | |
488 | ||
489 | sub revert_commit { | |
490 | my ($commit, @files) = @_; | |
491 | return unless system "git show -R $commit @files | patch -p1"; | |
492 | die "Can't apply revert $commit from @files" if @files; | |
493 | die "Can't apply revert $commit"; | |
494 | } | |
495 | ||
91ad6f8a NC |
496 | sub checkout_file { |
497 | my ($file, $commit) = @_; | |
498 | $commit ||= 'blead'; | |
499 | system "git show $commit:$file > $file </dev/null" | |
500 | and die "Could not extract $file at revision $commit"; | |
501 | } | |
502 | ||
ab4a15f9 | 503 | sub clean { |
f4800c99 | 504 | if ($options{clean}) { |
ab4a15f9 NC |
505 | # Needed, because files that are build products in this checked out |
506 | # version might be in git in the next desired version. | |
9da8cb0a | 507 | system 'git clean -dxf </dev/null'; |
ab4a15f9 NC |
508 | # Needed, because at some revisions the build alters checked out files. |
509 | # (eg pod/perlapi.pod). Also undoes any changes to makedepend.SH | |
9da8cb0a | 510 | system 'git reset --hard HEAD </dev/null'; |
ab4a15f9 NC |
511 | } |
512 | } | |
513 | ||
514 | sub skip { | |
515 | my $reason = shift; | |
516 | clean(); | |
517 | warn "skipping - $reason"; | |
518 | exit 125; | |
519 | } | |
520 | ||
f1050811 NC |
521 | sub report_and_exit { |
522 | my ($ret, $pass, $fail, $desc) = @_; | |
523 | ||
524 | clean(); | |
525 | ||
f4800c99 | 526 | my $got = ($options{'expect-pass'} ? !$ret : $ret) ? 'good' : 'bad'; |
f1050811 NC |
527 | if ($ret) { |
528 | print "$got - $fail $desc\n"; | |
529 | } else { | |
530 | print "$got - $pass $desc\n"; | |
531 | } | |
532 | ||
533 | exit($got eq 'bad'); | |
534 | } | |
535 | ||
0afef97d NC |
536 | sub match_and_exit { |
537 | my $target = shift; | |
538 | my $matches = 0; | |
539 | my $re = qr/$match/; | |
540 | my @files; | |
541 | ||
542 | { | |
543 | local $/ = "\0"; | |
544 | @files = defined $target ? `git ls-files -o -z`: `git ls-files -z`; | |
545 | chomp @files; | |
546 | } | |
547 | ||
548 | foreach my $file (@files) { | |
69bf9aba | 549 | my $fh = open_or_die($file); |
0afef97d NC |
550 | while (<$fh>) { |
551 | if ($_ =~ $re) { | |
552 | ++$matches; | |
553 | if (tr/\t\r\n -~\200-\377//c) { | |
554 | print "Binary file $file matches\n"; | |
555 | } else { | |
556 | $_ .= "\n" unless /\n\z/; | |
557 | print "$file: $_"; | |
558 | } | |
559 | } | |
560 | } | |
69bf9aba | 561 | close_or_die($fh); |
0afef97d NC |
562 | } |
563 | report_and_exit(!$matches, | |
564 | $matches == 1 ? '1 match for' : "$matches matches for", | |
565 | 'no matches for', $match); | |
566 | } | |
567 | ||
6a8dbfd7 | 568 | # Not going to assume that system perl is yet new enough to have autodie |
9da8cb0a | 569 | system 'git clean -dxf </dev/null' and die; |
6a8dbfd7 | 570 | |
0afef97d NC |
571 | if (!defined $target) { |
572 | match_and_exit() if $match; | |
573 | $target = 'test_prep'; | |
bc96a05a NC |
574 | } |
575 | ||
4b081584 NC |
576 | skip('no Configure - is this the //depot/perlext/Compiler branch?') |
577 | unless -f 'Configure'; | |
578 | ||
dbcdc176 NC |
579 | # This changes to PERL_VERSION in 4d8076ea25903dcb in 1999 |
580 | my $major | |
581 | = extract_from_file('patchlevel.h', | |
582 | qr/^#define\s+(?:PERL_VERSION|PATCHLEVEL)\s+(\d+)\s/, | |
583 | 0); | |
584 | ||
750ce942 NC |
585 | patch_Configure(); |
586 | patch_hints(); | |
587 | ||
6a8dbfd7 NC |
588 | # if Encode is not needed for the test, you can speed up the bisect by |
589 | # excluding it from the runs with -Dnoextensions=Encode | |
590 | # ccache is an easy win. Remove it if it causes problems. | |
6a8dbfd7 NC |
591 | # Commit 1cfa4ec74d4933da adds ignore_versioned_solibs to Configure, and sets it |
592 | # to true in hints/linux.sh | |
593 | # On dromedary, from that point on, Configure (by default) fails to find any | |
594 | # libraries, because it scans /usr/local/lib /lib /usr/lib, which only contain | |
595 | # versioned libraries. Without -lm, the build fails. | |
596 | # Telling /usr/local/lib64 /lib64 /usr/lib64 works from that commit onwards, | |
597 | # until commit faae14e6e968e1c0 adds it to the hints. | |
598 | # However, prior to 1cfa4ec74d4933da telling Configure the truth doesn't work, | |
599 | # because it will spot versioned libraries, pass them to the compiler, and then | |
600 | # bail out pretty early on. Configure won't let us override libswanted, but it | |
601 | # will let us override the entire libs list. | |
602 | ||
603 | unless (extract_from_file('Configure', 'ignore_versioned_solibs')) { | |
604 | # Before 1cfa4ec74d4933da, so force the libs list. | |
605 | ||
606 | my @libs; | |
607 | # This is the current libswanted list from Configure, less the libs removed | |
608 | # by current hints/linux.sh | |
609 | foreach my $lib (qw(sfio socket inet nsl nm ndbm gdbm dbm db malloc dl dld | |
610 | ld sun m crypt sec util c cposix posix ucb BSD)) { | |
611 | foreach my $dir (@paths) { | |
612 | next unless -f "$dir/lib$lib.so"; | |
613 | push @libs, "-l$lib"; | |
614 | last; | |
615 | } | |
616 | } | |
390a69a9 | 617 | $defines{libs} = \@libs unless exists $defines{libs}; |
6a8dbfd7 NC |
618 | } |
619 | ||
390a69a9 NC |
620 | $defines{usenm} = undef |
621 | if $major < 2 && !exists $defines{usenm}; | |
0142f0ce | 622 | |
05ec8abc NC |
623 | my ($missing, $created_dirs); |
624 | ($missing, $created_dirs) = force_manifest() | |
625 | if $options{'force-manifest'}; | |
67382a3b | 626 | |
af7c500f | 627 | my @ARGS = '-dEs'; |
390a69a9 NC |
628 | foreach my $key (sort keys %defines) { |
629 | my $val = $defines{$key}; | |
630 | if (ref $val) { | |
631 | push @ARGS, "-D$key=@$val"; | |
632 | } elsif (!defined $val) { | |
633 | push @ARGS, "-U$key"; | |
634 | } elsif (!length $val) { | |
635 | push @ARGS, "-D$key"; | |
636 | } else { | |
637 | $val = "" if $val eq "\0"; | |
638 | push @ARGS, "-D$key=$val"; | |
639 | } | |
640 | } | |
641 | push @ARGS, map {"-A$_"} @{$options{A}}; | |
642 | ||
6a8dbfd7 NC |
643 | # </dev/null because it seems that some earlier versions of Configure can |
644 | # call commands in a way that now has them reading from stdin (and hanging) | |
645 | my $pid = fork; | |
646 | die "Can't fork: $!" unless defined $pid; | |
647 | if (!$pid) { | |
7c22f158 NC |
648 | open STDIN, '<', '/dev/null'; |
649 | # If a file in MANIFEST is missing, Configure asks if you want to | |
650 | # continue (the default being 'n'). With stdin closed or /dev/null, | |
651 | # it exits immediately and the check for config.sh below will skip. | |
6a8dbfd7 NC |
652 | exec './Configure', @ARGS; |
653 | die "Failed to start Configure: $!"; | |
654 | } | |
655 | waitpid $pid, 0 | |
656 | or die "wait for Configure, pid $pid failed: $!"; | |
657 | ||
bb723266 NC |
658 | patch_SH(); |
659 | ||
af7c500f | 660 | if (-f 'config.sh') { |
05ec8abc NC |
661 | # Emulate noextensions if Configure doesn't support it. |
662 | fake_noextensions() | |
663 | if $major < 10 && $defines{noextensions}; | |
af7c500f NC |
664 | system './Configure -S </dev/null' and die; |
665 | } | |
666 | ||
0afef97d NC |
667 | if ($target =~ /config\.s?h/) { |
668 | match_and_exit($target) if $match && -f $target; | |
30a13282 NC |
669 | report_and_exit(!-f $target, 'could build', 'could not build', $target) |
670 | if $options{'test-build'}; | |
671 | ||
672 | my $ret = system @ARGV; | |
673 | report_and_exit($ret, 'zero exit from', 'non-zero exit from', "@ARGV"); | |
dd4e46d7 NC |
674 | } elsif (!-f 'config.sh') { |
675 | # Skip if something went wrong with Configure | |
676 | ||
677 | skip('could not build config.sh'); | |
678 | } | |
6a8dbfd7 | 679 | |
05ec8abc NC |
680 | force_manifest_cleanup($missing, $created_dirs) |
681 | if $missing; | |
67382a3b | 682 | |
bfa52998 NC |
683 | if($options{'force-regen'} |
684 | && extract_from_file('Makefile', qr/\bregen_headers\b/)) { | |
685 | # regen_headers was added in e50aee73b3d4c555, patch.1m for perl5.001 | |
686 | # It's not worth faking it for earlier revisions. | |
687 | system "make regen_headers </dev/null" | |
688 | and die; | |
689 | } | |
690 | ||
bb723266 | 691 | patch_C(); |
f2f0a0ff | 692 | patch_ext(); |
750ce942 NC |
693 | |
694 | # Parallel build for miniperl is safe | |
695 | system "make $j miniperl </dev/null"; | |
696 | ||
697 | my $expected = $target =~ /^test/ ? 't/perl' | |
698 | : $target eq 'Fcntl' ? "lib/auto/Fcntl/Fcntl.$Config{so}" | |
699 | : $target; | |
700 | my $real_target = $target eq 'Fcntl' ? $expected : $target; | |
701 | ||
702 | if ($target ne 'miniperl') { | |
703 | # Nearly all parallel build issues fixed by 5.10.0. Untrustworthy before that. | |
704 | $j = '' if $major < 10; | |
705 | ||
706 | if ($real_target eq 'test_prep') { | |
707 | if ($major < 8) { | |
708 | # test-prep was added in 5.004_01, 3e3baf6d63945cb6. | |
709 | # renamed to test_prep in 2001 in 5fe84fd29acaf55c. | |
710 | # earlier than that, just make test. It will be fast enough. | |
711 | $real_target = extract_from_file('Makefile.SH', | |
712 | qr/^(test[-_]prep):/, | |
713 | 'test'); | |
714 | } | |
715 | } | |
716 | ||
717 | system "make $j $real_target </dev/null"; | |
6f8c21fa NC |
718 | } |
719 | ||
750ce942 NC |
720 | my $missing_target = $expected =~ /perl$/ ? !-x $expected : !-r $expected; |
721 | ||
722 | if ($options{'test-build'}) { | |
723 | report_and_exit($missing_target, 'could build', 'could not build', | |
724 | $real_target); | |
725 | } elsif ($missing_target) { | |
726 | skip("could not build $real_target"); | |
f50dca98 NC |
727 | } |
728 | ||
750ce942 NC |
729 | match_and_exit($real_target) if $match; |
730 | ||
731 | if (defined $options{'one-liner'}) { | |
732 | my $exe = $target =~ /^(?:perl$|test)/ ? 'perl' : 'miniperl'; | |
733 | unshift @ARGV, "./$exe", '-Ilib', '-e', $options{'one-liner'}; | |
f50dca98 NC |
734 | } |
735 | ||
750ce942 NC |
736 | # This is what we came here to run: |
737 | ||
738 | if (exists $Config{ldlibpthname}) { | |
739 | require Cwd; | |
740 | my $varname = $Config{ldlibpthname}; | |
741 | my $cwd = Cwd::getcwd(); | |
742 | if (defined $ENV{$varname}) { | |
743 | $ENV{$varname} = $cwd . $Config{path_sep} . $ENV{$varname}; | |
744 | } else { | |
745 | $ENV{$varname} = $cwd; | |
f50dca98 | 746 | } |
750ce942 NC |
747 | } |
748 | ||
749 | my $ret = system @ARGV; | |
750 | ||
751 | report_and_exit($ret, 'zero exit from', 'non-zero exit from', "@ARGV"); | |
752 | ||
f2f0a0ff NC |
753 | ############################################################################ |
754 | # | |
05ec8abc | 755 | # Patching, editing and faking routines only below here. |
f2f0a0ff NC |
756 | # |
757 | ############################################################################ | |
758 | ||
05ec8abc NC |
759 | sub fake_noextensions { |
760 | edit_file('config.sh', sub { | |
761 | my @lines = split /\n/, shift; | |
762 | my @ext = split /\s+/, $defines{noextensions}; | |
763 | foreach (@lines) { | |
764 | next unless /^extensions=/ || /^dynamic_ext/; | |
765 | foreach my $ext (@ext) { | |
766 | s/\b$ext( )?\b/$1/; | |
767 | } | |
768 | } | |
769 | return join "\n", @lines; | |
770 | }); | |
771 | } | |
772 | ||
773 | sub force_manifest { | |
774 | my (@missing, @created_dirs); | |
775 | my $fh = open_or_die('MANIFEST'); | |
776 | while (<$fh>) { | |
777 | next unless /^(\S+)/; | |
778 | # -d is special case needed (at least) between 27332437a2ed1941 and | |
779 | # bf3d9ec563d25054^ inclusive, as manifest contains ext/Thread/Thread | |
780 | push @missing, $1 | |
781 | unless -f $1 || -d $1; | |
782 | } | |
783 | close_or_die($fh); | |
784 | ||
785 | foreach my $pathname (@missing) { | |
786 | my @parts = split '/', $pathname; | |
787 | my $leaf = pop @parts; | |
788 | my $path = '.'; | |
789 | while (@parts) { | |
790 | $path .= '/' . shift @parts; | |
791 | next if -d $path; | |
792 | mkdir $path, 0700 or die "Can't create $path: $!"; | |
793 | unshift @created_dirs, $path; | |
794 | } | |
795 | $fh = open_or_die($pathname, '>'); | |
796 | close_or_die($fh); | |
797 | chmod 0, $pathname or die "Can't chmod 0 $pathname: $!"; | |
798 | } | |
799 | return \@missing, \@created_dirs; | |
800 | } | |
801 | ||
802 | sub force_manifest_cleanup { | |
803 | my ($missing, $created_dirs) = @_; | |
804 | # This is probably way too paranoid: | |
805 | my @errors; | |
806 | require Fcntl; | |
807 | foreach my $file (@$missing) { | |
808 | my (undef, undef, $mode, undef, undef, undef, undef, $size) | |
809 | = stat $file; | |
810 | if (!defined $mode) { | |
811 | push @errors, "Added file $file has been deleted by Configure"; | |
812 | next; | |
813 | } | |
814 | if (Fcntl::S_IMODE($mode) != 0) { | |
815 | push @errors, | |
816 | sprintf 'Added file %s had mode changed by Configure to %03o', | |
817 | $file, $mode; | |
818 | } | |
819 | if ($size != 0) { | |
820 | push @errors, | |
821 | "Added file $file had sized changed by Configure to $size"; | |
822 | } | |
823 | unlink $file or die "Can't unlink $file: $!"; | |
824 | } | |
825 | foreach my $dir (@$created_dirs) { | |
826 | rmdir $dir or die "Can't rmdir $dir: $!"; | |
827 | } | |
828 | skip("@errors") | |
829 | if @errors; | |
830 | } | |
831 | ||
750ce942 NC |
832 | sub patch_Configure { |
833 | if ($major < 1) { | |
834 | if (extract_from_file('Configure', | |
835 | qr/^\t\t\*=\*\) echo "\$1" >> \$optdef;;$/)) { | |
836 | # This is " Spaces now allowed in -D command line options.", | |
837 | # part of commit ecfc54246c2a6f42 | |
838 | apply_patch(<<'EOPATCH'); | |
839 | diff --git a/Configure b/Configure | |
840 | index 3d3b38d..78ffe16 100755 | |
841 | --- a/Configure | |
842 | +++ b/Configure | |
843 | @@ -652,7 +777,8 @@ while test $# -gt 0; do | |
844 | echo "$me: use '-U symbol=', not '-D symbol='." >&2 | |
845 | echo "$me: ignoring -D $1" >&2 | |
846 | ;; | |
847 | - *=*) echo "$1" >> $optdef;; | |
848 | + *=*) echo "$1" | \ | |
849 | + sed -e "s/'/'\"'\"'/g" -e "s/=\(.*\)/='\1'/" >> $optdef;; | |
850 | *) echo "$1='define'" >> $optdef;; | |
851 | esac | |
852 | shift | |
853 | EOPATCH | |
854 | } | |
855 | ||
856 | if (extract_from_file('Configure', qr/^if \$contains 'd_namlen' \$xinc\b/)) { | |
857 | # Configure's original simple "grep" for d_namlen falls foul of the | |
858 | # approach taken by the glibc headers: | |
859 | # #ifdef _DIRENT_HAVE_D_NAMLEN | |
860 | # # define _D_EXACT_NAMLEN(d) ((d)->d_namlen) | |
861 | # | |
862 | # where _DIRENT_HAVE_D_NAMLEN is not defined on Linux. | |
863 | # This is also part of commit ecfc54246c2a6f42 | |
864 | apply_patch(<<'EOPATCH'); | |
865 | diff --git a/Configure b/Configure | |
866 | index 3d3b38d..78ffe16 100755 | |
867 | --- a/Configure | |
868 | +++ b/Configure | |
869 | @@ -3935,7 +4045,8 @@ $rm -f try.c | |
870 | ||
871 | : see if the directory entry stores field length | |
872 | echo " " | |
873 | -if $contains 'd_namlen' $xinc >/dev/null 2>&1; then | |
874 | +$cppstdin $cppflags $cppminus < "$xinc" > try.c | |
875 | +if $contains 'd_namlen' try.c >/dev/null 2>&1; then | |
876 | echo "Good, your directory entry keeps length information in d_namlen." >&4 | |
877 | val="$define" | |
878 | else | |
879 | EOPATCH | |
880 | } | |
f50dca98 | 881 | } |
750ce942 NC |
882 | |
883 | if ($major < 2 | |
884 | && !extract_from_file('Configure', | |
885 | qr/Try to guess additional flags to pick up local libraries/)) { | |
886 | my $mips = extract_from_file('Configure', | |
887 | qr!(''\) if (?:\./)?mips; then)!); | |
888 | # This is part of perl-5.001n. It's needed, to add -L/usr/local/lib to | |
889 | # theld flags if libraries are found there. It shifts the code to set up | |
890 | # libpth earlier, and then adds the code to add libpth entries to | |
891 | # ldflags | |
892 | # mips was changed to ./mips in ecfc54246c2a6f42, perl5.000 patch.0g | |
893 | apply_patch(sprintf <<'EOPATCH', $mips); | |
894 | diff --git a/Configure b/Configure | |
895 | index 53649d5..0635a6e 100755 | |
896 | --- a/Configure | |
897 | +++ b/Configure | |
898 | @@ -2749,6 +2749,52 @@ EOM | |
899 | ;; | |
900 | esac | |
f50dca98 | 901 | |
750ce942 NC |
902 | +: Set private lib path |
903 | +case "$plibpth" in | |
904 | +'') if ./mips; then | |
905 | + plibpth="$incpath/usr/lib /usr/local/lib /usr/ccs/lib" | |
906 | + fi;; | |
907 | +esac | |
908 | +case "$libpth" in | |
909 | +' ') dlist='';; | |
910 | +'') dlist="$plibpth $glibpth";; | |
911 | +*) dlist="$libpth";; | |
912 | +esac | |
913 | + | |
914 | +: Now check and see which directories actually exist, avoiding duplicates | |
915 | +libpth='' | |
916 | +for xxx in $dlist | |
917 | +do | |
918 | + if $test -d $xxx; then | |
919 | + case " $libpth " in | |
920 | + *" $xxx "*) ;; | |
921 | + *) libpth="$libpth $xxx";; | |
922 | + esac | |
923 | + fi | |
924 | +done | |
925 | +$cat <<'EOM' | |
926 | + | |
927 | +Some systems have incompatible or broken versions of libraries. Among | |
928 | +the directories listed in the question below, please remove any you | |
929 | +know not to be holding relevant libraries, and add any that are needed. | |
930 | +Say "none" for none. | |
931 | + | |
932 | +EOM | |
933 | +case "$libpth" in | |
934 | +'') dflt='none';; | |
935 | +*) | |
936 | + set X $libpth | |
937 | + shift | |
938 | + dflt=${1+"$@"} | |
939 | + ;; | |
940 | +esac | |
941 | +rp="Directories to use for library searches?" | |
942 | +. ./myread | |
943 | +case "$ans" in | |
944 | +none) libpth=' ';; | |
945 | +*) libpth="$ans";; | |
946 | +esac | |
947 | + | |
948 | : flags used in final linking phase | |
949 | case "$ldflags" in | |
950 | '') if ./venix; then | |
951 | @@ -2765,6 +2811,23 @@ case "$ldflags" in | |
952 | ;; | |
953 | *) dflt="$ldflags";; | |
954 | esac | |
955 | + | |
956 | +: Possible local library directories to search. | |
957 | +loclibpth="/usr/local/lib /opt/local/lib /usr/gnu/lib" | |
958 | +loclibpth="$loclibpth /opt/gnu/lib /usr/GNU/lib /opt/GNU/lib" | |
959 | + | |
960 | +: Try to guess additional flags to pick up local libraries. | |
961 | +for thislibdir in $libpth; do | |
962 | + case " $loclibpth " in | |
963 | + *" $thislibdir "*) | |
964 | + case "$dflt " in | |
965 | + "-L$thislibdir ") ;; | |
966 | + *) dflt="$dflt -L$thislibdir" ;; | |
967 | + esac | |
968 | + ;; | |
969 | + esac | |
970 | +done | |
971 | + | |
972 | echo " " | |
973 | rp="Any additional ld flags (NOT including libraries)?" | |
974 | . ./myread | |
975 | @@ -2828,52 +2891,6 @@ n) echo "OK, that should do.";; | |
976 | esac | |
977 | $rm -f try try.* core | |
978 | ||
979 | -: Set private lib path | |
980 | -case "$plibpth" in | |
981 | -%s | |
982 | - plibpth="$incpath/usr/lib /usr/local/lib /usr/ccs/lib" | |
983 | - fi;; | |
984 | -esac | |
985 | -case "$libpth" in | |
986 | -' ') dlist='';; | |
987 | -'') dlist="$plibpth $glibpth";; | |
988 | -*) dlist="$libpth";; | |
989 | -esac | |
990 | - | |
991 | -: Now check and see which directories actually exist, avoiding duplicates | |
992 | -libpth='' | |
993 | -for xxx in $dlist | |
994 | -do | |
995 | - if $test -d $xxx; then | |
996 | - case " $libpth " in | |
997 | - *" $xxx "*) ;; | |
998 | - *) libpth="$libpth $xxx";; | |
999 | - esac | |
1000 | - fi | |
1001 | -done | |
1002 | -$cat <<'EOM' | |
f50dca98 | 1003 | - |
750ce942 NC |
1004 | -Some systems have incompatible or broken versions of libraries. Among |
1005 | -the directories listed in the question below, please remove any you | |
1006 | -know not to be holding relevant libraries, and add any that are needed. | |
1007 | -Say "none" for none. | |
1008 | - | |
1009 | -EOM | |
1010 | -case "$libpth" in | |
1011 | -'') dflt='none';; | |
1012 | -*) | |
1013 | - set X $libpth | |
1014 | - shift | |
1015 | - dflt=${1+"$@"} | |
1016 | - ;; | |
1017 | -esac | |
1018 | -rp="Directories to use for library searches?" | |
1019 | -. ./myread | |
1020 | -case "$ans" in | |
1021 | -none) libpth=' ';; | |
1022 | -*) libpth="$ans";; | |
1023 | -esac | |
1024 | - | |
1025 | : compute shared library extension | |
1026 | case "$so" in | |
1027 | '') | |
f50dca98 NC |
1028 | EOPATCH |
1029 | } | |
686af304 | 1030 | |
750ce942 NC |
1031 | if ($major < 5 && extract_from_file('Configure', |
1032 | qr!if \$cc \$ccflags try\.c -o try >/dev/null 2>&1; then!)) { | |
1033 | # Analogous to the more general fix of dfe9444ca7881e71 | |
1034 | # Without this flags such as -m64 may not be passed to this compile, | |
1035 | # which results in a byteorder of '1234' instead of '12345678', which | |
1036 | # can then cause crashes. | |
686af304 | 1037 | |
750ce942 NC |
1038 | if (extract_from_file('Configure', qr/xxx_prompt=y/)) { |
1039 | # 8e07c86ebc651fe9 or later | |
1040 | # ("This is my patch patch.1n for perl5.001.") | |
1041 | apply_patch(<<'EOPATCH'); | |
1042 | diff --git a/Configure b/Configure | |
1043 | index 62249dd..c5c384e 100755 | |
1044 | --- a/Configure | |
1045 | +++ b/Configure | |
1046 | @@ -8247,7 +8247,7 @@ main() | |
1047 | } | |
1048 | EOCP | |
1049 | xxx_prompt=y | |
1050 | - if $cc $ccflags try.c -o try >/dev/null 2>&1 && ./try > /dev/null; then | |
1051 | + if $cc $ccflags $ldflags try.c -o try >/dev/null 2>&1 && ./try > /dev/null; then | |
1052 | dflt=`./try` | |
1053 | case "$dflt" in | |
1054 | [1-4][1-4][1-4][1-4]|12345678|87654321) | |
1055 | EOPATCH | |
1056 | } else { | |
1057 | apply_patch(<<'EOPATCH'); | |
1058 | diff --git a/Configure b/Configure | |
1059 | index 53649d5..f1cd64a 100755 | |
1060 | --- a/Configure | |
1061 | +++ b/Configure | |
1062 | @@ -6362,7 +6362,7 @@ main() | |
1063 | printf("\n"); | |
1064 | } | |
1065 | EOCP | |
1066 | - if $cc $ccflags try.c -o try >/dev/null 2>&1 ; then | |
1067 | + if $cc $ccflags $ldflags try.c -o try >/dev/null 2>&1 ; then | |
1068 | dflt=`./try` | |
1069 | case "$dflt" in | |
1070 | ????|????????) echo "(The test program ran ok.)";; | |
1071 | EOPATCH | |
1072 | } | |
1073 | } | |
9a999a97 | 1074 | |
750ce942 NC |
1075 | if ($major < 6 && !extract_from_file('Configure', |
1076 | qr!^\t-A\)$!)) { | |
1077 | # This adds the -A option to Configure, which is incredibly useful | |
1078 | # Effectively this is commits 02e93a22d20fc9a5, 5f83a3e9d818c3ad, | |
1079 | # bde6b06b2c493fef, f7c3111703e46e0c and 2 lines of trailing whitespace | |
1080 | # removed by 613d6c3e99b9decc, but applied at slightly different | |
1081 | # locations to ensure a clean patch back to 5.000 | |
1082 | # Note, if considering patching to the intermediate revisions to fix | |
1083 | # bugs in -A handling, f7c3111703e46e0c is from 2002, and hence | |
1084 | # $major == 8 | |
1085 | ||
1086 | # To add to the fun, early patches add -K and -O options, and it's not | |
1087 | # trivial to get patch to put the C<. ./posthint.sh> in the right place | |
1088 | edit_file('Configure', sub { | |
1089 | my $code = shift; | |
1090 | $code =~ s/(optstr = ")([^"]+";\s*# getopt-style specification)/$1A:$2/ | |
1091 | or die "Substitution failed"; | |
1092 | $code =~ s!^(: who configured the system)! | |
1093 | touch posthint.sh | |
1094 | . ./posthint.sh | |
2526f4b8 | 1095 | |
750ce942 NC |
1096 | $1!ms |
1097 | or die "Substitution failed"; | |
1098 | return $code; | |
1099 | }); | |
1100 | apply_patch(<<'EOPATCH'); | |
1101 | diff --git a/Configure b/Configure | |
1102 | index 4b55fa6..60c3c64 100755 | |
1103 | --- a/Configure | |
1104 | +++ b/Configure | |
1105 | @@ -1150,6 +1150,7 @@ set X `for arg in "$@"; do echo "X$arg"; done | | |
1106 | eval "set $*" | |
1107 | shift | |
1108 | rm -f options.awk | |
1109 | +rm -f posthint.sh | |
1110 | ||
1111 | : set up default values | |
1112 | fastread='' | |
1113 | @@ -1172,6 +1173,56 @@ while test $# -gt 0; do | |
1114 | case "$1" in | |
1115 | -d) shift; fastread=yes;; | |
1116 | -e) shift; alldone=cont;; | |
1117 | + -A) | |
1118 | + shift | |
1119 | + xxx='' | |
1120 | + yyy="$1" | |
1121 | + zzz='' | |
1122 | + uuu=undef | |
1123 | + case "$yyy" in | |
1124 | + *=*) zzz=`echo "$yyy"|sed 's!=.*!!'` | |
1125 | + case "$zzz" in | |
1126 | + *:*) zzz='' ;; | |
1127 | + *) xxx=append | |
1128 | + zzz=" "`echo "$yyy"|sed 's!^[^=]*=!!'` | |
1129 | + yyy=`echo "$yyy"|sed 's!=.*!!'` ;; | |
1130 | + esac | |
1131 | + ;; | |
1132 | + esac | |
1133 | + case "$xxx" in | |
1134 | + '') case "$yyy" in | |
1135 | + *:*) xxx=`echo "$yyy"|sed 's!:.*!!'` | |
1136 | + yyy=`echo "$yyy"|sed 's!^[^:]*:!!'` | |
1137 | + zzz=`echo "$yyy"|sed 's!^[^=]*=!!'` | |
1138 | + yyy=`echo "$yyy"|sed 's!=.*!!'` ;; | |
1139 | + *) xxx=`echo "$yyy"|sed 's!:.*!!'` | |
1140 | + yyy=`echo "$yyy"|sed 's!^[^:]*:!!'` ;; | |
1141 | + esac | |
1142 | + ;; | |
1143 | + esac | |
1144 | + case "$xxx" in | |
1145 | + append) | |
1146 | + echo "$yyy=\"\${$yyy}$zzz\"" >> posthint.sh ;; | |
1147 | + clear) | |
1148 | + echo "$yyy=''" >> posthint.sh ;; | |
1149 | + define) | |
1150 | + case "$zzz" in | |
1151 | + '') zzz=define ;; | |
1152 | + esac | |
1153 | + echo "$yyy='$zzz'" >> posthint.sh ;; | |
1154 | + eval) | |
1155 | + echo "eval \"$yyy=$zzz\"" >> posthint.sh ;; | |
1156 | + prepend) | |
1157 | + echo "$yyy=\"$zzz\${$yyy}\"" >> posthint.sh ;; | |
1158 | + undef) | |
1159 | + case "$zzz" in | |
1160 | + '') zzz="$uuu" ;; | |
1161 | + esac | |
1162 | + echo "$yyy=$zzz" >> posthint.sh ;; | |
1163 | + *) echo "$me: unknown -A command '$xxx', ignoring -A $1" >&2 ;; | |
1164 | + esac | |
1165 | + shift | |
1166 | + ;; | |
1167 | -f) | |
1168 | shift | |
1169 | cd .. | |
1170 | EOPATCH | |
1171 | } | |
9a999a97 | 1172 | |
750ce942 NC |
1173 | if ($major < 8 && !extract_from_file('Configure', |
1174 | qr/^\t\tif test ! -t 0; then$/)) { | |
1175 | # Before dfe9444ca7881e71, Configure would refuse to run if stdin was | |
1176 | # not a tty. With that commit, the tty requirement was dropped for -de | |
1177 | # and -dE | |
1178 | # Commit aaeb8e512e8e9e14 dropped the tty requirement for -S | |
1179 | # For those older versions, it's probably easiest if we simply remove | |
1180 | # the sanity test. | |
1181 | edit_file('Configure', sub { | |
1182 | my $code = shift; | |
1183 | $code =~ s/test ! -t 0/test Perl = rules/; | |
1184 | return $code; | |
1185 | }); | |
6a8dbfd7 | 1186 | } |
6a8dbfd7 | 1187 | |
750ce942 NC |
1188 | if ($major == 8 || $major == 9) { |
1189 | # Fix symbol detection to that of commit 373dfab3839ca168 if it's any | |
1190 | # intermediate version 5129fff43c4fe08c or later, as the intermediate | |
1191 | # versions don't work correctly on (at least) Sparc Linux. | |
1192 | # 5129fff43c4fe08c adds the first mention of mistrustnm. | |
1193 | # 373dfab3839ca168 removes the last mention of lc="" | |
1194 | edit_file('Configure', sub { | |
1195 | my $code = shift; | |
1196 | return $code | |
1197 | if $code !~ /\btc="";/; # 373dfab3839ca168 or later | |
1198 | return $code | |
1199 | if $code !~ /\bmistrustnm\b/; # before 5129fff43c4fe08c | |
1200 | my $fixed = <<'EOC'; | |
6a8dbfd7 | 1201 | |
750ce942 NC |
1202 | : is a C symbol defined? |
1203 | csym='tlook=$1; | |
1204 | case "$3" in | |
1205 | -v) tf=libc.tmp; tdc="";; | |
1206 | -a) tf=libc.tmp; tdc="[]";; | |
1207 | *) tlook="^$1\$"; tf=libc.list; tdc="()";; | |
1208 | esac; | |
1209 | tx=yes; | |
1210 | case "$reuseval-$4" in | |
1211 | true-) ;; | |
1212 | true-*) tx=no; eval "tval=\$$4"; case "$tval" in "") tx=yes;; esac;; | |
1213 | esac; | |
1214 | case "$tx" in | |
1215 | yes) | |
1216 | tval=false; | |
1217 | if $test "$runnm" = true; then | |
1218 | if $contains $tlook $tf >/dev/null 2>&1; then | |
1219 | tval=true; | |
1220 | elif $test "$mistrustnm" = compile -o "$mistrustnm" = run; then | |
1221 | echo "void *(*(p()))$tdc { extern void *$1$tdc; return &$1; } int main() { if(p()) return(0); else return(1); }"> try.c; | |
1222 | $cc -o try $optimize $ccflags $ldflags try.c >/dev/null 2>&1 $libs && tval=true; | |
1223 | $test "$mistrustnm" = run -a -x try && { $run ./try$_exe >/dev/null 2>&1 || tval=false; }; | |
1224 | $rm -f try$_exe try.c core core.* try.core; | |
1225 | fi; | |
1226 | else | |
1227 | echo "void *(*(p()))$tdc { extern void *$1$tdc; return &$1; } int main() { if(p()) return(0); else return(1); }"> try.c; | |
1228 | $cc -o try $optimize $ccflags $ldflags try.c $libs >/dev/null 2>&1 && tval=true; | |
1229 | $rm -f try$_exe try.c; | |
1230 | fi; | |
1231 | ;; | |
1232 | *) | |
1233 | case "$tval" in | |
1234 | $define) tval=true;; | |
1235 | *) tval=false;; | |
1236 | esac; | |
1237 | ;; | |
1238 | esac; | |
1239 | eval "$2=$tval"' | |
67382a3b | 1240 | |
750ce942 NC |
1241 | EOC |
1242 | $code =~ s/\n: is a C symbol defined\?\n.*?\neval "\$2=\$tval"'\n\n/$fixed/sm | |
1243 | or die "substitution failed"; | |
1244 | return $code; | |
1245 | }); | |
1246 | } | |
1247 | ||
1248 | if ($major < 10 | |
1249 | && extract_from_file('Configure', qr/^set malloc\.h i_malloc$/)) { | |
1250 | # This is commit 01d07975f7ef0e7d, trimmed, with $compile inlined as | |
1251 | # prior to bd9b35c97ad661cc Configure had the malloc.h test before the | |
1252 | # definition of $compile. | |
1253 | apply_patch(<<'EOPATCH'); | |
1254 | diff --git a/Configure b/Configure | |
1255 | index 3d2e8b9..6ce7766 100755 | |
1256 | --- a/Configure | |
1257 | +++ b/Configure | |
1258 | @@ -6743,5 +6743,22 @@ set d_dosuid | |
1259 | ||
1260 | : see if this is a malloc.h system | |
1261 | -set malloc.h i_malloc | |
1262 | -eval $inhdr | |
1263 | +: we want a real compile instead of Inhdr because some systems have a | |
1264 | +: malloc.h that just gives a compile error saying to use stdlib.h instead | |
1265 | +echo " " | |
1266 | +$cat >try.c <<EOCP | |
1267 | +#include <stdlib.h> | |
1268 | +#include <malloc.h> | |
1269 | +int main () { return 0; } | |
1270 | +EOCP | |
1271 | +set try | |
1272 | +if $cc $optimize $ccflags $ldflags -o try $* try.c $libs > /dev/null 2>&1; then | |
1273 | + echo "<malloc.h> found." >&4 | |
1274 | + val="$define" | |
1275 | +else | |
1276 | + echo "<malloc.h> NOT found." >&4 | |
1277 | + val="$undef" | |
1278 | +fi | |
1279 | +$rm -f try.c try | |
1280 | +set i_malloc | |
1281 | +eval $setvar | |
1282 | ||
1283 | EOPATCH | |
1284 | } | |
67382a3b | 1285 | } |
6a8dbfd7 | 1286 | |
750ce942 NC |
1287 | sub patch_hints { |
1288 | if ($^O eq 'freebsd') { | |
1289 | # There are rather too many version-specific FreeBSD hints fixes to | |
1290 | # patch individually. Also, more than once the FreeBSD hints file has | |
1291 | # been written in what turned out to be a rather non-future-proof style, | |
1292 | # with case statements treating the most recent version as the | |
1293 | # exception, instead of treating previous versions' behaviour explicitly | |
1294 | # and changing the default to cater for the current behaviour. (As | |
1295 | # strangely, future versions inherit the current behaviour.) | |
1296 | checkout_file('hints/freebsd.sh'); | |
1297 | } elsif ($^O eq 'darwin') { | |
1298 | if ($major < 8) { | |
1299 | # We can't build on darwin without some of the data in the hints | |
1300 | # file. Probably less surprising to use the earliest version of | |
1301 | # hints/darwin.sh and then edit in place just below, than use | |
1302 | # blead's version, as that would create a discontinuity at | |
1303 | # f556e5b971932902 - before it, hints bugs would be "fixed", after | |
1304 | # it they'd resurface. This way, we should give the illusion of | |
1305 | # monotonic bug fixing. | |
1306 | my $faking_it; | |
1307 | if (!-f 'hints/darwin.sh') { | |
1308 | checkout_file('hints/darwin.sh', 'f556e5b971932902'); | |
1309 | ++$faking_it; | |
1310 | } | |
0afef97d | 1311 | |
750ce942 NC |
1312 | edit_file('hints/darwin.sh', sub { |
1313 | my $code = shift; | |
1314 | # Part of commit 8f4f83badb7d1ba9, which mostly undoes | |
1315 | # commit 0511a818910f476c. | |
1316 | $code =~ s/^cppflags='-traditional-cpp';$/cppflags="\${cppflags} -no-cpp-precomp"/m; | |
1317 | # commit 14c11978e9b52e08/803bb6cc74d36a3f | |
1318 | # Without this, code in libperl.bundle links against op.o | |
1319 | # in preference to opmini.o on the linker command line, | |
1320 | # and hence miniperl tries to use File::Glob instead of | |
1321 | # csh | |
1322 | $code =~ s/^(lddlflags=)/ldflags="\${ldflags} -flat_namespace"\n$1/m; | |
1323 | # f556e5b971932902 also patches Makefile.SH with some | |
1324 | # special case code to deal with useshrplib for darwin. | |
1325 | # Given that post 5.8.0 the darwin hints default was | |
1326 | # changed to false, and it would be very complex to splice | |
1327 | # in that code in various versions of Makefile.SH back | |
1328 | # to 5.002, lets just turn it off. | |
1329 | $code =~ s/^useshrplib='true'/useshrplib='false'/m | |
1330 | if $faking_it; | |
1331 | return $code; | |
1332 | }); | |
1333 | } | |
1334 | } elsif ($^O eq 'netbsd') { | |
1335 | if ($major < 6) { | |
1336 | # These are part of commit 099685bc64c7dbce | |
1337 | edit_file('hints/netbsd.sh', sub { | |
1338 | my $code = shift; | |
1339 | my $fixed = <<'EOC'; | |
1340 | case "$osvers" in | |
1341 | 0.9|0.8*) | |
1342 | usedl="$undef" | |
1343 | ;; | |
1344 | *) | |
1345 | if [ -f /usr/libexec/ld.elf_so ]; then | |
1346 | d_dlopen=$define | |
1347 | d_dlerror=$define | |
1348 | ccdlflags="-Wl,-E -Wl,-R${PREFIX}/lib $ccdlflags" | |
1349 | cccdlflags="-DPIC -fPIC $cccdlflags" | |
1350 | lddlflags="--whole-archive -shared $lddlflags" | |
1351 | elif [ "`uname -m`" = "pmax" ]; then | |
1352 | # NetBSD 1.3 and 1.3.1 on pmax shipped an `old' ld.so, which will not work. | |
1353 | d_dlopen=$undef | |
1354 | elif [ -f /usr/libexec/ld.so ]; then | |
1355 | d_dlopen=$define | |
1356 | d_dlerror=$define | |
1357 | ccdlflags="-Wl,-R${PREFIX}/lib $ccdlflags" | |
1358 | # we use -fPIC here because -fpic is *NOT* enough for some of the | |
1359 | # extensions like Tk on some netbsd platforms (the sparc is one) | |
1360 | cccdlflags="-DPIC -fPIC $cccdlflags" | |
1361 | lddlflags="-Bforcearchive -Bshareable $lddlflags" | |
1362 | else | |
1363 | d_dlopen=$undef | |
1364 | fi | |
1365 | ;; | |
1366 | esac | |
1367 | EOC | |
1368 | $code =~ s/^case "\$osvers" in\n0\.9\|0\.8.*?^esac\n/$fixed/ms; | |
1369 | return $code; | |
1370 | }); | |
1371 | } | |
1372 | } elsif ($^O eq 'openbsd') { | |
1373 | if ($major < 8) { | |
1374 | checkout_file('hints/openbsd.sh', '43051805d53a3e4c') | |
1375 | unless -f 'hints/openbsd.sh'; | |
1376 | my $which = extract_from_file('hints/openbsd.sh', | |
1377 | qr/# from (2\.8|3\.1) onwards/, | |
1378 | ''); | |
1379 | if ($which eq '') { | |
1380 | my $was = extract_from_file('hints/openbsd.sh', | |
1381 | qr/(lddlflags="(?:-Bforcearchive )?-Bshareable)/); | |
1382 | # This is commit 154d43cbcf57271c and parts of 5c75dbfa77b0949c | |
1383 | # and 29b5585702e5e025 | |
1384 | apply_patch(sprintf <<'EOPATCH', $was); | |
1385 | diff --git a/hints/openbsd.sh b/hints/openbsd.sh | |
1386 | index a7d8bf2..5b79709 100644 | |
1387 | --- a/hints/openbsd.sh | |
1388 | +++ b/hints/openbsd.sh | |
1389 | @@ -37,7 +37,25 @@ OpenBSD.alpha|OpenBSD.mips|OpenBSD.powerpc|OpenBSD.vax) | |
1390 | # we use -fPIC here because -fpic is *NOT* enough for some of the | |
1391 | # extensions like Tk on some OpenBSD platforms (ie: sparc) | |
1392 | cccdlflags="-DPIC -fPIC $cccdlflags" | |
1393 | - %s $lddlflags" | |
1394 | + case "$osvers" in | |
1395 | + [01].*|2.[0-7]|2.[0-7].*) | |
1396 | + lddlflags="-Bshareable $lddlflags" | |
1397 | + ;; | |
1398 | + 2.[8-9]|3.0) | |
1399 | + ld=${cc:-cc} | |
1400 | + lddlflags="-shared -fPIC $lddlflags" | |
1401 | + ;; | |
1402 | + *) # from 3.1 onwards | |
1403 | + ld=${cc:-cc} | |
1404 | + lddlflags="-shared -fPIC $lddlflags" | |
1405 | + libswanted=`echo $libswanted | sed 's/ dl / /'` | |
1406 | + ;; | |
1407 | + esac | |
1408 | + | |
1409 | + # We need to force ld to export symbols on ELF platforms. | |
1410 | + # Without this, dlopen() is crippled. | |
1411 | + ELF=`${cc:-cc} -dM -E - </dev/null | grep __ELF__` | |
1412 | + test -n "$ELF" && ldflags="-Wl,-E $ldflags" | |
1413 | ;; | |
1414 | esac | |
1415 | ||
1416 | EOPATCH | |
1417 | } elsif ($which eq '2.8') { | |
1418 | # This is parts of 5c75dbfa77b0949c and 29b5585702e5e025, and | |
1419 | # possibly eb9cd59d45ad2908 | |
1420 | my $was = extract_from_file('hints/openbsd.sh', | |
1421 | qr/lddlflags="(-shared(?: -fPIC)?) \$lddlflags"/); | |
0afef97d | 1422 | |
750ce942 NC |
1423 | apply_patch(sprintf <<'EOPATCH', $was); |
1424 | --- a/hints/openbsd.sh 2011-10-21 17:25:20.000000000 +0200 | |
1425 | +++ b/hints/openbsd.sh 2011-10-21 16:58:43.000000000 +0200 | |
1426 | @@ -44,11 +44,21 @@ | |
1427 | [01].*|2.[0-7]|2.[0-7].*) | |
1428 | lddlflags="-Bshareable $lddlflags" | |
1429 | ;; | |
1430 | - *) # from 2.8 onwards | |
1431 | + 2.[8-9]|3.0) | |
1432 | ld=${cc:-cc} | |
1433 | - lddlflags="%s $lddlflags" | |
1434 | + lddlflags="-shared -fPIC $lddlflags" | |
1435 | + ;; | |
1436 | + *) # from 3.1 onwards | |
1437 | + ld=${cc:-cc} | |
1438 | + lddlflags="-shared -fPIC $lddlflags" | |
1439 | + libswanted=`echo $libswanted | sed 's/ dl / /'` | |
1440 | ;; | |
1441 | esac | |
1442 | + | |
1443 | + # We need to force ld to export symbols on ELF platforms. | |
1444 | + # Without this, dlopen() is crippled. | |
1445 | + ELF=`${cc:-cc} -dM -E - </dev/null | grep __ELF__` | |
1446 | + test -n "$ELF" && ldflags="-Wl,-E $ldflags" | |
1447 | ;; | |
1448 | esac | |
1449 | ||
1450 | EOPATCH | |
1451 | } elsif ($which eq '3.1' | |
1452 | && !extract_from_file('hints/openbsd.sh', | |
1453 | qr/We need to force ld to export symbols on ELF platforms/)) { | |
1454 | # This is part of 29b5585702e5e025 | |
1455 | apply_patch(<<'EOPATCH'); | |
1456 | diff --git a/hints/openbsd.sh b/hints/openbsd.sh | |
1457 | index c6b6bc9..4839d04 100644 | |
1458 | --- a/hints/openbsd.sh | |
1459 | +++ b/hints/openbsd.sh | |
1460 | @@ -54,6 +54,11 @@ alpha-2.[0-8]|mips-*|vax-*|powerpc-2.[0-7]|m88k-*) | |
1461 | libswanted=`echo $libswanted | sed 's/ dl / /'` | |
1462 | ;; | |
1463 | esac | |
1464 | + | |
1465 | + # We need to force ld to export symbols on ELF platforms. | |
1466 | + # Without this, dlopen() is crippled. | |
1467 | + ELF=`${cc:-cc} -dM -E - </dev/null | grep __ELF__` | |
1468 | + test -n "$ELF" && ldflags="-Wl,-E $ldflags" | |
1469 | ;; | |
1470 | esac | |
1471 | ||
1472 | EOPATCH | |
1473 | } | |
1474 | } | |
1475 | } elsif ($^O eq 'linux') { | |
1476 | if ($major < 1) { | |
1477 | # sparc linux seems to need the -Dbool=char -DHAS_BOOL part of | |
1478 | # perl5.000 patch.0n: [address Configure and build issues] | |
1479 | edit_file('hints/linux.sh', sub { | |
1480 | my $code = shift; | |
1481 | $code =~ s!-I/usr/include/bsd!-Dbool=char -DHAS_BOOL!g; | |
1482 | return $code; | |
1483 | }); | |
1484 | } | |
915f531b | 1485 | |
750ce942 NC |
1486 | if ($major <= 9) { |
1487 | if (`uname -sm` =~ qr/^Linux sparc/) { | |
1488 | if (extract_from_file('hints/linux.sh', qr/sparc-linux/)) { | |
1489 | # Be sure to use -fPIC not -fpic on Linux/SPARC | |
1490 | apply_commit('f6527d0ef0c13ad4'); | |
1491 | } elsif(!extract_from_file('hints/linux.sh', | |
1492 | qr/^sparc-linux\)$/)) { | |
1493 | my $fh = open_or_die('hints/linux.sh', '>>'); | |
1494 | print $fh <<'EOT' or die $!; | |
1495 | ||
1496 | case "`uname -m`" in | |
1497 | sparc*) | |
1498 | case "$cccdlflags" in | |
1499 | *-fpic*) cccdlflags="`echo $cccdlflags|sed 's/-fpic/-fPIC/'`" ;; | |
1500 | *) cccdlflags="$cccdlflags -fPIC" ;; | |
1501 | esac | |
1502 | ;; | |
1503 | esac | |
1504 | EOT | |
1505 | close_or_die($fh); | |
1506 | } | |
1507 | } | |
1508 | } | |
915f531b NC |
1509 | } |
1510 | } | |
1511 | ||
bb723266 NC |
1512 | sub patch_SH { |
1513 | # Cwd.xs added in commit 0d2079faa739aaa9. Cwd.pm moved to ext/ 8 years | |
1514 | # later in commit 403f501d5b37ebf0 | |
1515 | if ($major > 0 && <*/Cwd/Cwd.xs>) { | |
1516 | if ($major < 10 | |
1517 | && !extract_from_file('Makefile.SH', qr/^extra_dep=''$/)) { | |
1518 | # The Makefile.PL for Unicode::Normalize needs | |
1519 | # lib/unicore/CombiningClass.pl. Even without a parallel build, we | |
1520 | # need a dependency to ensure that it builds. This is a variant of | |
1521 | # commit 9f3ef600c170f61e. Putting this for earlier versions gives | |
1522 | # us a spot on which to hang the edits below | |
1523 | apply_patch(<<'EOPATCH'); | |
1524 | diff --git a/Makefile.SH b/Makefile.SH | |
1525 | index f61d0db..6097954 100644 | |
1526 | --- a/Makefile.SH | |
1527 | +++ b/Makefile.SH | |
1528 | @@ -155,10 +155,20 @@ esac | |
1529 | ||
1530 | : Prepare dependency lists for Makefile. | |
1531 | dynamic_list=' ' | |
1532 | +extra_dep='' | |
1533 | for f in $dynamic_ext; do | |
1534 | : the dependency named here will never exist | |
1535 | base=`echo "$f" | sed 's/.*\///'` | |
1536 | - dynamic_list="$dynamic_list lib/auto/$f/$base.$dlext" | |
1537 | + this_target="lib/auto/$f/$base.$dlext" | |
1538 | + dynamic_list="$dynamic_list $this_target" | |
1539 | + | |
1540 | + : Parallel makes reveal that we have some interdependencies | |
1541 | + case $f in | |
1542 | + Math/BigInt/FastCalc) extra_dep="$extra_dep | |
1543 | +$this_target: lib/auto/List/Util/Util.$dlext" ;; | |
1544 | + Unicode/Normalize) extra_dep="$extra_dep | |
1545 | +$this_target: lib/unicore/CombiningClass.pl" ;; | |
1546 | + esac | |
1547 | done | |
1548 | ||
1549 | static_list=' ' | |
1550 | @@ -987,2 +997,9 @@ n_dummy $(nonxs_ext): miniperl$(EXE_EXT) preplibrary $(DYNALOADER) FORCE | |
1551 | @$(LDLIBPTH) sh ext/util/make_ext nonxs $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL) | |
1552 | +!NO!SUBS! | |
1553 | + | |
1554 | +$spitshell >>Makefile <<EOF | |
1555 | +$extra_dep | |
1556 | +EOF | |
1557 | + | |
1558 | +$spitshell >>Makefile <<'!NO!SUBS!' | |
1559 | ||
1560 | EOPATCH | |
1561 | } | |
1562 | if ($major < 14) { | |
1563 | # Commits dc0655f797469c47 and d11a62fe01f2ecb2 | |
1564 | edit_file('Makefile.SH', sub { | |
1565 | my $code = shift; | |
1566 | foreach my $ext (qw(Encode SDBM_File)) { | |
1567 | next if $code =~ /\b$ext\) extra_dep=/s; | |
1568 | $code =~ s!(\) extra_dep="\$extra_dep | |
1569 | \$this_target: .*?" ;;) | |
1570 | ( esac | |
1571 | )!$1 | |
1572 | $ext) extra_dep="\$extra_dep | |
1573 | \$this_target: lib/auto/Cwd/Cwd.\$dlext" ;; | |
1574 | $2!; | |
1575 | } | |
1576 | return $code; | |
1577 | }); | |
1578 | } | |
1579 | } | |
1580 | ||
1581 | if ($major == 7) { | |
1582 | # Remove commits 9fec149bb652b6e9 and 5bab1179608f81d8, which add/amend | |
1583 | # rules to automatically run regen scripts that rebuild C headers. These | |
1584 | # cause problems because a git checkout doesn't preserve relative file | |
1585 | # modification times, hence the regen scripts may fire. This will | |
1586 | # obscure whether the repository had the correct generated headers | |
1587 | # checked in. | |
1588 | # Also, the dependency rules for running the scripts were not correct, | |
1589 | # which could cause spurious re-builds on re-running make, and can cause | |
1590 | # complete build failures for a parallel make. | |
1591 | if (extract_from_file('Makefile.SH', | |
1592 | qr/Writing it this way gives make a big hint to always run opcode\.pl before/)) { | |
1593 | apply_commit('70c6e6715e8fec53'); | |
1594 | } elsif (extract_from_file('Makefile.SH', | |
1595 | qr/^opcode\.h opnames\.h pp_proto\.h pp\.sym: opcode\.pl$/)) { | |
1596 | revert_commit('9fec149bb652b6e9'); | |
1597 | } | |
1598 | } | |
1599 | ||
1600 | # There was a bug in makedepend.SH which was fixed in version 96a8704c. | |
1601 | # Symptom was './makedepend: 1: Syntax error: Unterminated quoted string' | |
1602 | # Remove this if you're actually bisecting a problem related to | |
1603 | # makedepend.SH | |
1604 | # If you do this, you may need to add in code to correct the output of older | |
1605 | # makedepends, which don't correctly filter newer gcc output such as | |
1606 | # <built-in> | |
1607 | checkout_file('makedepend.SH'); | |
1608 | ||
1609 | if ($major < 4 && -f 'config.sh' | |
1610 | && !extract_from_file('config.sh', qr/^trnl=/)) { | |
1611 | # This seems to be necessary to avoid makedepend becoming confused, | |
1612 | # and hanging on stdin. Seems that the code after | |
1613 | # make shlist || ...here... is never run. | |
1614 | edit_file('makedepend.SH', sub { | |
1615 | my $code = shift; | |
1616 | $code =~ s/^trnl='\$trnl'$/trnl='\\n'/m; | |
1617 | return $code; | |
1618 | }); | |
1619 | } | |
1620 | } | |
1621 | ||
1622 | sub patch_C { | |
1623 | # This is ordered by $major, as it's likely that different platforms may | |
1624 | # well want to share code. | |
1625 | ||
1626 | if ($major == 2 && extract_from_file('perl.c', qr/^\tfclose\(e_fp\);$/)) { | |
1627 | # need to patch perl.c to avoid calling fclose() twice on e_fp when | |
1628 | # using -e | |
1629 | # This diff is part of commit ab821d7fdc14a438. The second close was | |
1630 | # introduced with perl-5.002, commit a5f75d667838e8e7 | |
1631 | # Might want a6c477ed8d4864e6 too, for the corresponding change to | |
1632 | # pp_ctl.c (likely without this, eval will have "fun") | |
1633 | apply_patch(<<'EOPATCH'); | |
1634 | diff --git a/perl.c b/perl.c | |
1635 | index 03c4d48..3c814a2 100644 | |
1636 | --- a/perl.c | |
1637 | +++ b/perl.c | |
1638 | @@ -252,6 +252,7 @@ setuid perl scripts securely.\n"); | |
1639 | #ifndef VMS /* VMS doesn't have environ array */ | |
1640 | origenviron = environ; | |
1641 | #endif | |
1642 | + e_tmpname = Nullch; | |
1643 | ||
1644 | if (do_undump) { | |
1645 | ||
1646 | @@ -405,6 +406,7 @@ setuid perl scripts securely.\n"); | |
1647 | if (e_fp) { | |
1648 | if (Fflush(e_fp) || ferror(e_fp) || fclose(e_fp)) | |
1649 | croak("Can't write to temp file for -e: %s", Strerror(errno)); | |
1650 | + e_fp = Nullfp; | |
1651 | argc++,argv--; | |
1652 | scriptname = e_tmpname; | |
1653 | } | |
1654 | @@ -470,10 +472,10 @@ setuid perl scripts securely.\n"); | |
1655 | curcop->cop_line = 0; | |
1656 | curstash = defstash; | |
1657 | preprocess = FALSE; | |
1658 | - if (e_fp) { | |
1659 | - fclose(e_fp); | |
1660 | - e_fp = Nullfp; | |
1661 | + if (e_tmpname) { | |
1662 | (void)UNLINK(e_tmpname); | |
1663 | + Safefree(e_tmpname); | |
1664 | + e_tmpname = Nullch; | |
1665 | } | |
1666 | ||
1667 | /* now that script is parsed, we can modify record separator */ | |
1668 | @@ -1369,7 +1371,7 @@ SV *sv; | |
1669 | scriptname = xfound; | |
1670 | } | |
1671 | ||
1672 | - origfilename = savepv(e_fp ? "-e" : scriptname); | |
1673 | + origfilename = savepv(e_tmpname ? "-e" : scriptname); | |
1674 | curcop->cop_filegv = gv_fetchfile(origfilename); | |
1675 | if (strEQ(origfilename,"-")) | |
1676 | scriptname = ""; | |
1677 | ||
1678 | EOPATCH | |
1679 | } | |
1680 | ||
1681 | if ($major < 3 && $^O eq 'openbsd' | |
1682 | && !extract_from_file('pp_sys.c', qr/BSD_GETPGRP/)) { | |
1683 | # Part of commit c3293030fd1b7489 | |
1684 | apply_patch(<<'EOPATCH'); | |
1685 | diff --git a/pp_sys.c b/pp_sys.c | |
1686 | index 4608a2a..f0c9d1d 100644 | |
1687 | --- a/pp_sys.c | |
1688 | +++ b/pp_sys.c | |
1689 | @@ -2903,8 +2903,8 @@ PP(pp_getpgrp) | |
1690 | pid = 0; | |
1691 | else | |
1692 | pid = SvIVx(POPs); | |
1693 | -#ifdef USE_BSDPGRP | |
1694 | - value = (I32)getpgrp(pid); | |
1695 | +#ifdef BSD_GETPGRP | |
1696 | + value = (I32)BSD_GETPGRP(pid); | |
1697 | #else | |
1698 | if (pid != 0) | |
1699 | DIE("POSIX getpgrp can't take an argument"); | |
1700 | @@ -2933,8 +2933,8 @@ PP(pp_setpgrp) | |
1701 | } | |
1702 | ||
1703 | TAINT_PROPER("setpgrp"); | |
1704 | -#ifdef USE_BSDPGRP | |
1705 | - SETi( setpgrp(pid, pgrp) >= 0 ); | |
1706 | +#ifdef BSD_SETPGRP | |
1707 | + SETi( BSD_SETPGRP(pid, pgrp) >= 0 ); | |
1708 | #else | |
1709 | if ((pgrp != 0) || (pid != 0)) { | |
1710 | DIE("POSIX setpgrp can't take an argument"); | |
1711 | EOPATCH | |
1712 | } | |
1713 | ||
1714 | if ($major < 4 && $^O eq 'openbsd') { | |
1715 | my $bad; | |
1716 | # Need changes from commit a6e633defa583ad5. | |
1717 | # Commits c07a80fdfe3926b5 and f82b3d4130164d5f changed the same part | |
1718 | # of perl.h | |
1719 | ||
1720 | if (extract_from_file('perl.h', | |
1721 | qr/^#ifdef HAS_GETPGRP2$/)) { | |
1722 | $bad = <<'EOBAD'; | |
1723 | *************** | |
1724 | *** 57,71 **** | |
1725 | #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s) | |
1726 | #define TAINT_ENV() if (tainting) taint_env() | |
1727 | ||
1728 | ! #ifdef HAS_GETPGRP2 | |
1729 | ! # ifndef HAS_GETPGRP | |
1730 | ! # define HAS_GETPGRP | |
1731 | ! # endif | |
1732 | ! #endif | |
1733 | ! | |
1734 | ! #ifdef HAS_SETPGRP2 | |
1735 | ! # ifndef HAS_SETPGRP | |
1736 | ! # define HAS_SETPGRP | |
1737 | ! # endif | |
1738 | #endif | |
1739 | ||
1740 | EOBAD | |
1741 | } elsif (extract_from_file('perl.h', | |
1742 | qr/Gack, you have one but not both of getpgrp2/)) { | |
1743 | $bad = <<'EOBAD'; | |
1744 | *************** | |
1745 | *** 56,76 **** | |
1746 | #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s) | |
1747 | #define TAINT_ENV() if (tainting) taint_env() | |
1748 | ||
1749 | ! #if defined(HAS_GETPGRP2) && defined(HAS_SETPGRP2) | |
1750 | ! # define getpgrp getpgrp2 | |
1751 | ! # define setpgrp setpgrp2 | |
1752 | ! # ifndef HAS_GETPGRP | |
1753 | ! # define HAS_GETPGRP | |
1754 | ! # endif | |
1755 | ! # ifndef HAS_SETPGRP | |
1756 | ! # define HAS_SETPGRP | |
1757 | ! # endif | |
1758 | ! # ifndef USE_BSDPGRP | |
1759 | ! # define USE_BSDPGRP | |
1760 | ! # endif | |
1761 | ! #else | |
1762 | ! # if defined(HAS_GETPGRP2) || defined(HAS_SETPGRP2) | |
1763 | ! #include "Gack, you have one but not both of getpgrp2() and setpgrp2()." | |
1764 | ! # endif | |
1765 | #endif | |
1766 | ||
1767 | EOBAD | |
1768 | } elsif (extract_from_file('perl.h', | |
1769 | qr/^#ifdef USE_BSDPGRP$/)) { | |
1770 | $bad = <<'EOBAD' | |
1771 | *************** | |
1772 | *** 91,116 **** | |
1773 | #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s) | |
1774 | #define TAINT_ENV() if (tainting) taint_env() | |
1775 | ||
1776 | ! #ifdef USE_BSDPGRP | |
1777 | ! # ifdef HAS_GETPGRP | |
1778 | ! # define BSD_GETPGRP(pid) getpgrp((pid)) | |
1779 | ! # endif | |
1780 | ! # ifdef HAS_SETPGRP | |
1781 | ! # define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp)) | |
1782 | ! # endif | |
1783 | ! #else | |
1784 | ! # ifdef HAS_GETPGRP2 | |
1785 | ! # define BSD_GETPGRP(pid) getpgrp2((pid)) | |
1786 | ! # ifndef HAS_GETPGRP | |
1787 | ! # define HAS_GETPGRP | |
1788 | ! # endif | |
1789 | ! # endif | |
1790 | ! # ifdef HAS_SETPGRP2 | |
1791 | ! # define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp)) | |
1792 | ! # ifndef HAS_SETPGRP | |
1793 | ! # define HAS_SETPGRP | |
1794 | ! # endif | |
1795 | ! # endif | |
1796 | #endif | |
1797 | ||
1798 | #ifndef _TYPES_ /* If types.h defines this it's easy. */ | |
1799 | EOBAD | |
1800 | } | |
1801 | if ($bad) { | |
1802 | apply_patch(<<"EOPATCH"); | |
1803 | *** a/perl.h 2011-10-21 09:46:12.000000000 +0200 | |
1804 | --- b/perl.h 2011-10-21 09:46:12.000000000 +0200 | |
1805 | $bad--- 91,144 ---- | |
1806 | #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s) | |
1807 | #define TAINT_ENV() if (tainting) taint_env() | |
1808 | ||
1809 | ! /* XXX All process group stuff is handled in pp_sys.c. Should these | |
1810 | ! defines move there? If so, I could simplify this a lot. --AD 9/96. | |
1811 | ! */ | |
1812 | ! /* Process group stuff changed from traditional BSD to POSIX. | |
1813 | ! perlfunc.pod documents the traditional BSD-style syntax, so we'll | |
1814 | ! try to preserve that, if possible. | |
1815 | ! */ | |
1816 | ! #ifdef HAS_SETPGID | |
1817 | ! # define BSD_SETPGRP(pid, pgrp) setpgid((pid), (pgrp)) | |
1818 | ! #else | |
1819 | ! # if defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP) | |
1820 | ! # define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp)) | |
1821 | ! # else | |
1822 | ! # ifdef HAS_SETPGRP2 /* DG/UX */ | |
1823 | ! # define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp)) | |
1824 | ! # endif | |
1825 | ! # endif | |
1826 | ! #endif | |
1827 | ! #if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP) | |
1828 | ! # define HAS_SETPGRP /* Well, effectively it does . . . */ | |
1829 | ! #endif | |
1830 | ! | |
1831 | ! /* getpgid isn't POSIX, but at least Solaris and Linux have it, and it makes | |
1832 | ! our life easier :-) so we'll try it. | |
1833 | ! */ | |
1834 | ! #ifdef HAS_GETPGID | |
1835 | ! # define BSD_GETPGRP(pid) getpgid((pid)) | |
1836 | ! #else | |
1837 | ! # if defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP) | |
1838 | ! # define BSD_GETPGRP(pid) getpgrp((pid)) | |
1839 | ! # else | |
1840 | ! # ifdef HAS_GETPGRP2 /* DG/UX */ | |
1841 | ! # define BSD_GETPGRP(pid) getpgrp2((pid)) | |
1842 | ! # endif | |
1843 | ! # endif | |
1844 | ! #endif | |
1845 | ! #if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP) | |
1846 | ! # define HAS_GETPGRP /* Well, effectively it does . . . */ | |
1847 | ! #endif | |
1848 | ! | |
1849 | ! /* These are not exact synonyms, since setpgrp() and getpgrp() may | |
1850 | ! have different behaviors, but perl.h used to define USE_BSDPGRP | |
1851 | ! (prior to 5.003_05) so some extension might depend on it. | |
1852 | ! */ | |
1853 | ! #if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP) | |
1854 | ! # ifndef USE_BSDPGRP | |
1855 | ! # define USE_BSDPGRP | |
1856 | ! # endif | |
1857 | #endif | |
1858 | ||
1859 | #ifndef _TYPES_ /* If types.h defines this it's easy. */ | |
1860 | EOPATCH | |
1861 | } | |
1862 | } | |
1863 | ||
1864 | if ($major == 4 && extract_from_file('scope.c', qr/\(SV\*\)SSPOPINT/)) { | |
1865 | # [PATCH] 5.004_04 +MAINT_TRIAL_1 broken when sizeof(int) != sizeof(void) | |
1866 | # Fixes a bug introduced in 161b7d1635bc830b | |
1867 | apply_commit('9002cb76ec83ef7f'); | |
1868 | } | |
1869 | ||
1870 | if ($major == 4 && extract_from_file('av.c', qr/AvARRAY\(av\) = 0;/)) { | |
1871 | # Fixes a bug introduced in 1393e20655efb4bc | |
1872 | apply_commit('e1c148c28bf3335b', 'av.c'); | |
1873 | } | |
1874 | ||
1875 | if ($major == 4 && !extract_from_file('perl.c', qr/delimcpy.*,$/)) { | |
1876 | # bug introduced in 2a92aaa05aa1acbf, fixed in 8490252049bf42d3 | |
1877 | apply_patch(<<'EOPATCH'); | |
1878 | diff --git a/perl.c b/perl.c | |
1879 | index 4eb69e3..54bbb00 100644 | |
1880 | --- a/perl.c | |
1881 | +++ b/perl.c | |
1882 | @@ -1735,7 +1735,7 @@ SV *sv; | |
1883 | if (len < sizeof tokenbuf) | |
1884 | tokenbuf[len] = '\0'; | |
1885 | #else /* ! (atarist || DOSISH) */ | |
1886 | - s = delimcpy(tokenbuf, tokenbuf + sizeof tokenbuf, s, bufend | |
1887 | + s = delimcpy(tokenbuf, tokenbuf + sizeof tokenbuf, s, bufend, | |
1888 | ':', | |
1889 | &len); | |
1890 | #endif /* ! (atarist || DOSISH) */ | |
1891 | EOPATCH | |
1892 | } | |
1893 | ||
1894 | if ($major == 4 && $^O eq 'linux') { | |
1895 | # Whilst this is fixed properly in f0784f6a4c3e45e1 which provides the | |
1896 | # Configure probe, it's easier to back out the problematic changes made | |
1897 | # in these previous commits: | |
1898 | if (extract_from_file('doio.c', | |
1899 | qr!^/\* XXX REALLY need metaconfig test \*/$!)) { | |
1900 | revert_commit('4682965a1447ea44', 'doio.c'); | |
1901 | } | |
1902 | if (my $token = extract_from_file('doio.c', | |
1903 | qr!^#if (defined\(__sun(?:__)?\)) && defined\(__svr4__\) /\* XXX Need metaconfig test \*/$!)) { | |
1904 | my $patch = `git show -R 9b599b2a63d2324d doio.c`; | |
1905 | $patch =~ s/defined\(__sun__\)/$token/g; | |
1906 | apply_patch($patch); | |
1907 | } | |
1908 | if (extract_from_file('doio.c', | |
1909 | qr!^/\* linux \(and Solaris2\?\) uses :$!)) { | |
1910 | revert_commit('8490252049bf42d3', 'doio.c'); | |
1911 | } | |
1912 | if (extract_from_file('doio.c', | |
1913 | qr/^ unsemds.buf = &semds;$/)) { | |
1914 | revert_commit('8e591e46b4c6543e'); | |
1915 | } | |
1916 | if (extract_from_file('doio.c', | |
1917 | qr!^#ifdef __linux__ /\* XXX Need metaconfig test \*/$!)) { | |
1918 | # Reverts part of commit 3e3baf6d63945cb6 | |
1919 | apply_patch(<<'EOPATCH'); | |
1920 | diff --git b/doio.c a/doio.c | |
1921 | index 62b7de9..0d57425 100644 | |
1922 | --- b/doio.c | |
1923 | +++ a/doio.c | |
1924 | @@ -1333,9 +1331,6 @@ SV **sp; | |
1925 | char *a; | |
1926 | I32 id, n, cmd, infosize, getinfo; | |
1927 | I32 ret = -1; | |
1928 | -#ifdef __linux__ /* XXX Need metaconfig test */ | |
1929 | - union semun unsemds; | |
1930 | -#endif | |
1931 | ||
1932 | id = SvIVx(*++mark); | |
1933 | n = (optype == OP_SEMCTL) ? SvIVx(*++mark) : 0; | |
1934 | @@ -1364,29 +1359,11 @@ SV **sp; | |
1935 | infosize = sizeof(struct semid_ds); | |
1936 | else if (cmd == GETALL || cmd == SETALL) | |
1937 | { | |
1938 | -#ifdef __linux__ /* XXX Need metaconfig test */ | |
1939 | -/* linux uses : | |
1940 | - int semctl (int semid, int semnun, int cmd, union semun arg) | |
1941 | - | |
1942 | - union semun { | |
1943 | - int val; | |
1944 | - struct semid_ds *buf; | |
1945 | - ushort *array; | |
1946 | - }; | |
1947 | -*/ | |
1948 | - union semun semds; | |
1949 | - if (semctl(id, 0, IPC_STAT, semds) == -1) | |
1950 | -#else | |
1951 | struct semid_ds semds; | |
1952 | if (semctl(id, 0, IPC_STAT, &semds) == -1) | |
1953 | -#endif | |
1954 | return -1; | |
1955 | getinfo = (cmd == GETALL); | |
1956 | -#ifdef __linux__ /* XXX Need metaconfig test */ | |
1957 | - infosize = semds.buf->sem_nsems * sizeof(short); | |
1958 | -#else | |
1959 | infosize = semds.sem_nsems * sizeof(short); | |
1960 | -#endif | |
1961 | /* "short" is technically wrong but much more portable | |
1962 | than guessing about u_?short(_t)? */ | |
1963 | } | |
1964 | @@ -1429,12 +1406,7 @@ SV **sp; | |
1965 | #endif | |
1966 | #ifdef HAS_SEM | |
1967 | case OP_SEMCTL: | |
1968 | -#ifdef __linux__ /* XXX Need metaconfig test */ | |
1969 | - unsemds.buf = (struct semid_ds *)a; | |
1970 | - ret = semctl(id, n, cmd, unsemds); | |
1971 | -#else | |
1972 | ret = semctl(id, n, cmd, (struct semid_ds *)a); | |
1973 | -#endif | |
1974 | break; | |
1975 | #endif | |
1976 | #ifdef HAS_SHM | |
1977 | EOPATCH | |
1978 | } | |
1979 | # Incorrect prototype added as part of 8ac853655d9b7447, fixed as part | |
1980 | # of commit dc45a647708b6c54, with at least one intermediate | |
1981 | # modification. Correct prototype for gethostbyaddr has socklen_t | |
1982 | # second. Linux has uint32_t first for getnetbyaddr. | |
1983 | # Easiest just to remove, instead of attempting more complex patching. | |
1984 | # Something similar may be needed on other platforms. | |
1985 | edit_file('pp_sys.c', sub { | |
1986 | my $code = shift; | |
1987 | $code =~ s/^ struct hostent \*(?:PerlSock_)?gethostbyaddr\([^)]+\);$//m; | |
1988 | $code =~ s/^ struct netent \*getnetbyaddr\([^)]+\);$//m; | |
1989 | return $code; | |
1990 | }); | |
1991 | } | |
1992 | ||
1993 | if ($major < 6 && $^O eq 'netbsd' | |
1994 | && !extract_from_file('unixish.h', | |
1995 | qr/defined\(NSIG\).*defined\(__NetBSD__\)/)) { | |
1996 | apply_patch(<<'EOPATCH') | |
1997 | diff --git a/unixish.h b/unixish.h | |
1998 | index 2a6cbcd..eab2de1 100644 | |
1999 | --- a/unixish.h | |
2000 | +++ b/unixish.h | |
2001 | @@ -89,7 +89,7 @@ | |
2002 | */ | |
2003 | /* #define ALTERNATE_SHEBANG "#!" / **/ | |
2004 | ||
2005 | -#if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX) | |
2006 | +#if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX) || defined(__NetBSD__) | |
2007 | # include <signal.h> | |
2008 | #endif | |
2009 | ||
2010 | EOPATCH | |
2011 | } | |
2012 | ||
2013 | if (($major >= 7 || $major <= 9) && $^O eq 'openbsd' | |
2014 | && `uname -m` eq "sparc64\n" | |
2015 | # added in 2000 by commit cb434fcc98ac25f5: | |
2016 | && extract_from_file('regexec.c', | |
2017 | qr!/\* No need to save/restore up to this paren \*/!) | |
2018 | # re-indented in 2006 by commit 95b2444054382532: | |
2019 | && extract_from_file('regexec.c', qr/^\t\tCURCUR cc;$/)) { | |
2020 | # Need to work around a bug in (at least) OpenBSD's 4.6's sparc64 # | |
2021 | # compiler ["gcc (GCC) 3.3.5 (propolice)"]. Between commits | |
2022 | # 3ec562b0bffb8b8b (2002) and 1a4fad37125bac3e^ (2005) the darling thing | |
2023 | # fails to compile any code for the statement cc.oldcc = PL_regcc; | |
2024 | # | |
2025 | # If you refactor the code to "fix" that, or force the issue using set | |
2026 | # in the debugger, the stack smashing detection code fires on return | |
2027 | # from S_regmatch(). Turns out that the compiler doesn't allocate any | |
2028 | # (or at least enough) space for cc. | |
2029 | # | |
2030 | # Restore the "uninitialised" value for cc before function exit, and the | |
2031 | # stack smashing code is placated. "Fix" 3ec562b0bffb8b8b (which | |
2032 | # changes the size of auto variables used elsewhere in S_regmatch), and | |
2033 | # the crash is visible back to bc517b45fdfb539b (which also changes | |
2034 | # buffer sizes). "Unfix" 1a4fad37125bac3e and the crash is visible until | |
2035 | # 5b47454deb66294b. Problem goes away if you compile with -O, or hack | |
2036 | # the code as below. | |
2037 | # | |
2038 | # Hence this turns out to be a bug in (old) gcc. Not a security bug we | |
2039 | # still need to fix. | |
2040 | apply_patch(<<'EOPATCH'); | |
2041 | diff --git a/regexec.c b/regexec.c | |
2042 | index 900b491..6251a0b 100644 | |
2043 | --- a/regexec.c | |
2044 | +++ b/regexec.c | |
2045 | @@ -2958,7 +2958,11 @@ S_regmatch(pTHX_ regnode *prog) | |
2046 | I,I | |
2047 | *******************************************************************/ | |
2048 | case CURLYX: { | |
2049 | - CURCUR cc; | |
2050 | + union { | |
2051 | + CURCUR hack_cc; | |
2052 | + char hack_buff[sizeof(CURCUR) + 1]; | |
2053 | + } hack; | |
2054 | +#define cc hack.hack_cc | |
2055 | CHECKPOINT cp = PL_savestack_ix; | |
2056 | /* No need to save/restore up to this paren */ | |
2057 | I32 parenfloor = scan->flags; | |
2058 | @@ -2983,6 +2987,7 @@ S_regmatch(pTHX_ regnode *prog) | |
2059 | n = regmatch(PREVOPER(next)); /* start on the WHILEM */ | |
2060 | regcpblow(cp); | |
2061 | PL_regcc = cc.oldcc; | |
2062 | +#undef cc | |
2063 | saySAME(n); | |
2064 | } | |
2065 | /* NOT REACHED */ | |
2066 | EOPATCH | |
2067 | } | |
2068 | ||
2069 | if ($major < 8 && $^O eq 'openbsd' | |
2070 | && !extract_from_file('perl.h', qr/include <unistd\.h>/)) { | |
2071 | # This is part of commit 3f270f98f9305540, applied at a slightly | |
2072 | # different location in perl.h, where the context is stable back to | |
2073 | # 5.000 | |
2074 | apply_patch(<<'EOPATCH'); | |
2075 | diff --git a/perl.h b/perl.h | |
2076 | index 9418b52..b8b1a7c 100644 | |
2077 | --- a/perl.h | |
2078 | +++ b/perl.h | |
2079 | @@ -496,6 +496,10 @@ register struct op *Perl_op asm(stringify(OP_IN_REGISTER)); | |
2080 | # include <sys/param.h> | |
2081 | #endif | |
2082 | ||
2083 | +/* If this causes problems, set i_unistd=undef in the hint file. */ | |
2084 | +#ifdef I_UNISTD | |
2085 | +# include <unistd.h> | |
2086 | +#endif | |
2087 | ||
2088 | /* Use all the "standard" definitions? */ | |
2089 | #if defined(STANDARD_C) && defined(I_STDLIB) | |
2090 | EOPATCH | |
2091 | } | |
2092 | } | |
2093 | ||
f2f0a0ff NC |
2094 | sub patch_ext { |
2095 | if (-f 'ext/POSIX/Makefile.PL' | |
2096 | && extract_from_file('ext/POSIX/Makefile.PL', | |
2097 | qr/Explicitly avoid including/)) { | |
2098 | # commit 6695a346c41138df, which effectively reverts 170888cff5e2ffb7 | |
2099 | ||
2100 | # PERL5LIB is populated by make_ext.pl with paths to the modules we need | |
2101 | # to run, don't override this with "../../lib" since that may not have | |
2102 | # been populated yet in a parallel build. | |
2103 | apply_commit('6695a346c41138df'); | |
2104 | } | |
2105 | ||
2106 | if ($major < 8 && $^O eq 'darwin' && !-f 'ext/DynaLoader/dl_dyld.xs') { | |
2107 | checkout_file('ext/DynaLoader/dl_dyld.xs', 'f556e5b971932902'); | |
2108 | apply_patch(<<'EOPATCH'); | |
2109 | diff -u a/ext/DynaLoader/dl_dyld.xs~ a/ext/DynaLoader/dl_dyld.xs | |
2110 | --- a/ext/DynaLoader/dl_dyld.xs~ 2011-10-11 21:41:27.000000000 +0100 | |
2111 | +++ b/ext/DynaLoader/dl_dyld.xs 2011-10-11 21:42:20.000000000 +0100 | |
2112 | @@ -41,6 +41,35 @@ | |
2113 | #include "perl.h" | |
2114 | #include "XSUB.h" | |
2115 | ||
2116 | +#ifndef pTHX | |
2117 | +# define pTHX void | |
2118 | +# define pTHX_ | |
2119 | +#endif | |
2120 | +#ifndef aTHX | |
2121 | +# define aTHX | |
2122 | +# define aTHX_ | |
2123 | +#endif | |
2124 | +#ifndef dTHX | |
2125 | +# define dTHXa(a) extern int Perl___notused(void) | |
2126 | +# define dTHX extern int Perl___notused(void) | |
2127 | +#endif | |
2128 | + | |
2129 | +#ifndef Perl_form_nocontext | |
2130 | +# define Perl_form_nocontext form | |
2131 | +#endif | |
2132 | + | |
2133 | +#ifndef Perl_warn_nocontext | |
2134 | +# define Perl_warn_nocontext warn | |
2135 | +#endif | |
2136 | + | |
2137 | +#ifndef PTR2IV | |
2138 | +# define PTR2IV(p) (IV)(p) | |
2139 | +#endif | |
2140 | + | |
2141 | +#ifndef get_av | |
2142 | +# define get_av perl_get_av | |
2143 | +#endif | |
2144 | + | |
2145 | #define DL_LOADONCEONLY | |
2146 | ||
2147 | #include "dlutils.c" /* SaveError() etc */ | |
2148 | @@ -185,7 +191,7 @@ | |
2149 | CODE: | |
2150 | DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s,%x):\n", filename,flags)); | |
2151 | if (flags & 0x01) | |
2152 | - Perl_warn(aTHX_ "Can't make loaded symbols global on this platform while loading %s",filename); | |
2153 | + Perl_warn_nocontext("Can't make loaded symbols global on this platform while loading %s",filename); | |
2154 | RETVAL = dlopen(filename, mode) ; | |
2155 | DLDEBUG(2,PerlIO_printf(Perl_debug_log, " libref=%x\n", RETVAL)); | |
2156 | ST(0) = sv_newmortal() ; | |
2157 | EOPATCH | |
2158 | if ($major < 4 && !extract_from_file('util.c', qr/^form/m)) { | |
2159 | apply_patch(<<'EOPATCH'); | |
2160 | diff -u a/ext/DynaLoader/dl_dyld.xs~ a/ext/DynaLoader/dl_dyld.xs | |
2161 | --- a/ext/DynaLoader/dl_dyld.xs~ 2011-10-11 21:56:25.000000000 +0100 | |
2162 | +++ b/ext/DynaLoader/dl_dyld.xs 2011-10-11 22:00:00.000000000 +0100 | |
2163 | @@ -60,6 +60,18 @@ | |
2164 | # define get_av perl_get_av | |
2165 | #endif | |
2166 | ||
2167 | +static char * | |
2168 | +form(char *pat, ...) | |
2169 | +{ | |
2170 | + char *retval; | |
2171 | + va_list args; | |
2172 | + va_start(args, pat); | |
2173 | + vasprintf(&retval, pat, &args); | |
2174 | + va_end(args); | |
2175 | + SAVEFREEPV(retval); | |
2176 | + return retval; | |
2177 | +} | |
2178 | + | |
2179 | #define DL_LOADONCEONLY | |
2180 | ||
2181 | #include "dlutils.c" /* SaveError() etc */ | |
2182 | EOPATCH | |
2183 | } | |
2184 | } | |
2185 | ||
2186 | if ($major < 10) { | |
2187 | if (!extract_from_file('ext/DB_File/DB_File.xs', | |
2188 | qr!^#else /\* Berkeley DB Version > 2 \*/$!)) { | |
2189 | # This DB_File.xs is really too old to patch up. | |
2190 | # Skip DB_File, unless we're invoked with an explicit -Unoextensions | |
2191 | if (!exists $defines{noextensions}) { | |
2192 | $defines{noextensions} = 'DB_File'; | |
2193 | } elsif (defined $defines{noextensions}) { | |
2194 | $defines{noextensions} .= ' DB_File'; | |
2195 | } | |
2196 | } elsif (!extract_from_file('ext/DB_File/DB_File.xs', | |
2197 | qr/^#ifdef AT_LEAST_DB_4_1$/)) { | |
2198 | # This line is changed by commit 3245f0580c13b3ab | |
2199 | my $line = extract_from_file('ext/DB_File/DB_File.xs', | |
2200 | qr/^( status = \(?RETVAL->dbp->open\)?\(RETVAL->dbp, name, NULL, RETVAL->type, $)/); | |
2201 | apply_patch(<<"EOPATCH"); | |
2202 | diff --git a/ext/DB_File/DB_File.xs b/ext/DB_File/DB_File.xs | |
2203 | index 489ba96..fba8ded 100644 | |
2204 | --- a/ext/DB_File/DB_File.xs | |
2205 | +++ b/ext/DB_File/DB_File.xs | |
2206 | \@\@ -183,4 +187,8 \@\@ | |
2207 | #endif | |
2208 | ||
2209 | +#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) | |
2210 | +# define AT_LEAST_DB_4_1 | |
2211 | +#endif | |
2212 | + | |
2213 | /* map version 2 features & constants onto their version 1 equivalent */ | |
2214 | ||
2215 | \@\@ -1334,7 +1419,12 \@\@ SV * sv ; | |
2216 | #endif | |
2217 | ||
2218 | +#ifdef AT_LEAST_DB_4_1 | |
2219 | + status = (RETVAL->dbp->open)(RETVAL->dbp, NULL, name, NULL, RETVAL->type, | |
2220 | + Flags, mode) ; | |
2221 | +#else | |
2222 | $line | |
2223 | Flags, mode) ; | |
2224 | +#endif | |
2225 | /* printf("open returned %d %s\\n", status, db_strerror(status)) ; */ | |
2226 | ||
2227 | EOPATCH | |
2228 | } | |
2229 | } | |
2230 | ||
2231 | if ($major < 10 and -f 'ext/IPC/SysV/SysV.xs') { | |
2232 | edit_file('ext/IPC/SysV/SysV.xs', sub { | |
2233 | my $xs = shift; | |
2234 | my $fixed = <<'EOFIX'; | |
2235 | ||
2236 | #include <sys/types.h> | |
2237 | #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) | |
2238 | #ifndef HAS_SEM | |
2239 | # include <sys/ipc.h> | |
2240 | #endif | |
2241 | # ifdef HAS_MSG | |
2242 | # include <sys/msg.h> | |
2243 | # endif | |
2244 | # ifdef HAS_SHM | |
2245 | # if defined(PERL_SCO) || defined(PERL_ISC) | |
2246 | # include <sys/sysmacros.h> /* SHMLBA */ | |
2247 | # endif | |
2248 | # include <sys/shm.h> | |
2249 | # ifndef HAS_SHMAT_PROTOTYPE | |
2250 | extern Shmat_t shmat (int, char *, int); | |
2251 | # endif | |
2252 | # if defined(HAS_SYSCONF) && defined(_SC_PAGESIZE) | |
2253 | # undef SHMLBA /* not static: determined at boot time */ | |
2254 | # define SHMLBA sysconf(_SC_PAGESIZE) | |
2255 | # elif defined(HAS_GETPAGESIZE) | |
2256 | # undef SHMLBA /* not static: determined at boot time */ | |
2257 | # define SHMLBA getpagesize() | |
2258 | # endif | |
2259 | # endif | |
2260 | #endif | |
2261 | EOFIX | |
2262 | $xs =~ s! | |
2263 | #include <sys/types\.h> | |
2264 | .* | |
2265 | (#ifdef newCONSTSUB|/\* Required)!$fixed$1!ms; | |
2266 | return $xs; | |
2267 | }); | |
2268 | } | |
2269 | } | |
2270 | ||
9a999a97 NC |
2271 | # Local variables: |
2272 | # cperl-indent-level: 4 | |
2273 | # indent-tabs-mode: nil | |
2274 | # End: | |
2275 | # | |
2276 | # ex: set ts=8 sts=4 sw=4 et: |