4 use Getopt::Long qw(:config bundling no_auto_abbrev);
6 my @targets = qw(config.sh miniperl lib/Config.pm perl test_prep);
10 target => 'test_prep',
13 clean => 1, # mostly for debugging this
16 my @paths = qw(/usr/local/lib64 /lib64 /usr/lib64);
28 die "$0: [--target=...] [-j4] [--expect-pass=0|1] thing to test";
31 unless(GetOptions(\%options,
32 'target=s', 'jobs|j=i', 'expect-pass=i',
33 'expect-fail' => sub { $options{'expect-pass'} = 0; },
34 'clean!', 'one-liner|e=s', 'match=s', 'force-manifest',
35 'test-build', 'check-args', 'A=s@', 'verbose+',
37 my (undef, $val) = @_;
38 if ($val =~ /\A([^=]+)=(.*)/s) {
39 $defines{$1} = length $2 ? $2 : "\0";
45 $defines{$_[1]} = undef;
51 my ($target, $j, $match) = @options{qw(target jobs match)};
53 my $exe = $target eq 'perl' || $target eq 'test_prep' ? 'perl' : 'miniperl';
54 my $expected = $target eq 'test_prep' ? 'perl' : $target;
56 unshift @ARGV, "./$exe", '-Ilib', '-e', $options{'one-liner'}
57 if defined $options{'one-liner'};
59 usage() unless @ARGV || $match || $options{'test-build'};
60 exit 0 if $options{'check-args'};
62 die "$0: Can't build $target" unless grep {@targets} $target;
64 $j = "-j$j" if $j =~ /\A\d+\z/;
66 # Sadly, however hard we try, I don't think that it will be possible to build
67 # modules in ext/ on x86_64 Linux before commit e1666bf5602ae794 on 1999/12/29,
68 # which updated to MakeMaker 3.7, which changed from using a hard coded ld
69 # in the Makefile to $(LD). On x86_64 Linux the "linker" is gcc.
71 sub extract_from_file {
72 my ($file, $rx, $default) = @_;
73 open my $fh, '<', $file or die "Can't open $file: $!";
76 return wantarray ? @got : $got[0]
79 return $default if defined $default;
84 if ($options{clean}) {
85 # Needed, because files that are build products in this checked out
86 # version might be in git in the next desired version.
87 system 'git clean -dxf';
88 # Needed, because at some revisions the build alters checked out files.
89 # (eg pod/perlapi.pod). Also undoes any changes to makedepend.SH
90 system 'git reset --hard HEAD';
97 warn "skipping - $reason";
101 sub report_and_exit {
102 my ($ret, $pass, $fail, $desc) = @_;
106 my $got = ($options{'expect-pass'} ? !$ret : $ret) ? 'good' : 'bad';
108 print "$got - $fail $desc\n";
110 print "$got - $pass $desc\n";
119 open my $fh, '|-', 'patch' or die "Can't run patch: $!";
121 close $fh or die "Can't patch perl.c: $?, $!";
124 # Not going to assume that system perl is yet new enough to have autodie
125 system 'git clean -dxf' and die;
130 foreach my $file (`git ls-files`) {
132 open my $fh, '<', $file or die "Can't open $file: $!";
136 $_ .= "\n" unless /\n\z/;
140 close $fh or die "Can't close $file: $!";
142 report_and_exit(!$matches, 'matches for', 'no matches for', $match);
145 skip('no Configure - is this the //depot/perlext/Compiler branch?')
146 unless -f 'Configure';
148 # This changes to PERL_VERSION in 4d8076ea25903dcb in 1999
150 = extract_from_file('patchlevel.h',
151 qr/^#define\s+(?:PERL_VERSION|PATCHLEVEL)\s+(\d+)\s/,
155 if (extract_from_file('Configure',
156 qr/^ \*=\*\) echo "\$1" >> \$optdef;;$/)) {
157 # This is " Spaces now allowed in -D command line options.",
158 # part of commit ecfc54246c2a6f42
159 apply_patch(<<'EOPATCH');
160 diff --git a/Configure b/Configure
161 index 3d3b38d..78ffe16 100755
164 @@ -652,7 +777,8 @@ while test $# -gt 0; do
165 echo "$me: use '-U symbol=', not '-D symbol='." >&2
166 echo "$me: ignoring -D $1" >&2
168 - *=*) echo "$1" >> $optdef;;
170 + sed -e "s/'/'\"'\"'/g" -e "s/=\(.*\)/='\1'/" >> $optdef;;
171 *) echo "$1='define'" >> $optdef;;
176 if (extract_from_file('Configure', qr/^if \$contains 'd_namlen' \$xinc\b/)) {
177 # Configure's original simple "grep" for d_namlen falls foul of the
178 # approach taken by the glibc headers:
179 # #ifdef _DIRENT_HAVE_D_NAMLEN
180 # # define _D_EXACT_NAMLEN(d) ((d)->d_namlen)
182 # where _DIRENT_HAVE_D_NAMLEN is not defined on Linux.
183 # This is also part of commit ecfc54246c2a6f42
184 apply_patch(<<'EOPATCH');
185 diff --git a/Configure b/Configure
186 index 3d3b38d..78ffe16 100755
189 @@ -3935,7 +4045,8 @@ $rm -f try.c
191 : see if the directory entry stores field length
193 -if $contains 'd_namlen' $xinc >/dev/null 2>&1; then
194 +$cppstdin $cppflags $cppminus < "$xinc" > try.c
195 +if $contains 'd_namlen' try.c >/dev/null 2>&1; then
196 echo "Good, your directory entry keeps length information in d_namlen." >&4
203 # There was a bug in makedepend.SH which was fixed in version 96a8704c.
204 # Symptom was './makedepend: 1: Syntax error: Unterminated quoted string'
205 # Remove this if you're actually bisecting a problem related to makedepend.SH
206 system 'git show blead:makedepend.SH > makedepend.SH' and die;
208 # if Encode is not needed for the test, you can speed up the bisect by
209 # excluding it from the runs with -Dnoextensions=Encode
210 # ccache is an easy win. Remove it if it causes problems.
211 # Commit 1cfa4ec74d4933da adds ignore_versioned_solibs to Configure, and sets it
212 # to true in hints/linux.sh
213 # On dromedary, from that point on, Configure (by default) fails to find any
214 # libraries, because it scans /usr/local/lib /lib /usr/lib, which only contain
215 # versioned libraries. Without -lm, the build fails.
216 # Telling /usr/local/lib64 /lib64 /usr/lib64 works from that commit onwards,
217 # until commit faae14e6e968e1c0 adds it to the hints.
218 # However, prior to 1cfa4ec74d4933da telling Configure the truth doesn't work,
219 # because it will spot versioned libraries, pass them to the compiler, and then
220 # bail out pretty early on. Configure won't let us override libswanted, but it
221 # will let us override the entire libs list.
223 unless (extract_from_file('Configure', 'ignore_versioned_solibs')) {
224 # Before 1cfa4ec74d4933da, so force the libs list.
227 # This is the current libswanted list from Configure, less the libs removed
228 # by current hints/linux.sh
229 foreach my $lib (qw(sfio socket inet nsl nm ndbm gdbm dbm db malloc dl dld
230 ld sun m crypt sec util c cposix posix ucb BSD)) {
231 foreach my $dir (@paths) {
232 next unless -f "$dir/lib$lib.so";
233 push @libs, "-l$lib";
237 $defines{libs} = \@libs unless exists $defines{libs};
240 # This seems to be necessary to avoid makedepend becoming confused, and hanging
241 # on stdin. Seems that the code after make shlist || ...here... is never run.
242 $defines{trnl} = q{'\n'}
243 if $major < 4 && !exists $defines{trnl};
245 $defines{usenm} = undef
246 if $major < 2 && !exists $defines{usenm};
248 my (@missing, @created_dirs);
250 if ($options{'force-manifest'}) {
251 open my $fh, '<', 'MANIFEST'
252 or die "Could not open MANIFEST: $!";
254 next unless /^(\S+)/;
258 close $fh or die "Can't close MANIFEST: $!";
260 foreach my $pathname (@missing) {
261 my @parts = split '/', $pathname;
262 my $leaf = pop @parts;
265 $path .= '/' . shift @parts;
267 mkdir $path, 0700 or die "Can't create $path: $!";
268 unshift @created_dirs, $path;
270 open $fh, '>', $pathname or die "Can't open $pathname: $!";
271 close $fh or die "Can't close $pathname: $!";
272 chmod 0, $pathname or die "Can't chmod 0 $pathname: $!";
276 my @ARGS = $target eq 'config.sh' ? '-dEs' : '-des';
277 foreach my $key (sort keys %defines) {
278 my $val = $defines{$key};
280 push @ARGS, "-D$key=@$val";
281 } elsif (!defined $val) {
282 push @ARGS, "-U$key";
283 } elsif (!length $val) {
284 push @ARGS, "-D$key";
286 $val = "" if $val eq "\0";
287 push @ARGS, "-D$key=$val";
290 push @ARGS, map {"-A$_"} @{$options{A}};
292 # </dev/null because it seems that some earlier versions of Configure can
293 # call commands in a way that now has them reading from stdin (and hanging)
295 die "Can't fork: $!" unless defined $pid;
297 # Before dfe9444ca7881e71, Configure would refuse to run if stdin was not a
298 # tty. With that commit, the tty requirement was dropped for -de and -dE
300 open STDIN, '<', '/dev/null';
301 } elsif (!$options{'force-manifest'}) {
302 # If a file in MANIFEST is missing, Configure asks if you want to
303 # continue (the default being 'n'). With stdin closed or /dev/null,
304 # it exit immediately and the check for config.sh below will skip.
305 # To avoid a hang, we need to check MANIFEST for ourselves, and skip
306 # if anything is missing.
307 open my $fh, '<', 'MANIFEST';
308 skip("Could not open MANIFEST: $!")
311 next unless /^(\S+)/;
312 skip("$1 from MANIFEST doesn't exist")
315 close $fh or die "Can't close MANIFEST: $!";
317 exec './Configure', @ARGS;
318 die "Failed to start Configure: $!";
321 or die "wait for Configure, pid $pid failed: $!";
323 if ($target eq 'config.sh') {
324 report_and_exit(!-f $target, 'could build', 'could not build', $target);
325 } elsif (!-f 'config.sh') {
326 # Skip if something went wrong with Configure
328 skip('could not build config.sh');
331 # This is probably way too paranoid:
335 foreach my $file (@missing) {
336 my (undef, undef, $mode, undef, undef, undef, undef, $size)
338 if (!defined $mode) {
339 push @errors, "Added file $file has been deleted by Configure";
342 if (Fcntl::S_IMODE($mode) != 0) {
344 sprintf 'Added file %s had mode changed by Configure to %03o',
349 "Added file $file had sized changed by Configure to $size";
351 unlink $file or die "Can't unlink $file: $!";
353 foreach my $dir (@created_dirs) {
354 rmdir $dir or die "Can't rmdir $dir: $!";
360 # Correct makefile for newer GNU gcc
361 # Only really needed if you comment out the use of blead's makedepend.SH
364 local @ARGV = qw(makefile x2p/makefile);
366 print unless /<(?:built-in|command|stdin)/;
370 if ($major == 2 && extract_from_file('perl.c', qr/^ fclose\(e_fp\);$/)) {
371 # need to patch perl.c to avoid calling fclose() twice on e_fp when using -e
372 # This diff is part of commit ab821d7fdc14a438. The second close was
373 # introduced with perl-5.002, commit a5f75d667838e8e7
374 # Might want a6c477ed8d4864e6 too, for the corresponding change to pp_ctl.c
375 # (likely without this, eval will have "fun")
376 apply_patch(<<'EOPATCH');
377 diff --git a/perl.c b/perl.c
378 index 03c4d48..3c814a2 100644
381 @@ -252,6 +252,7 @@ setuid perl scripts securely.\n");
382 #ifndef VMS /* VMS doesn't have environ array */
383 origenviron = environ;
385 + e_tmpname = Nullch;
389 @@ -405,6 +406,7 @@ setuid perl scripts securely.\n");
391 if (Fflush(e_fp) || ferror(e_fp) || fclose(e_fp))
392 croak("Can't write to temp file for -e: %s", Strerror(errno));
395 scriptname = e_tmpname;
397 @@ -470,10 +472,10 @@ setuid perl scripts securely.\n");
398 curcop->cop_line = 0;
405 (void)UNLINK(e_tmpname);
406 + Safefree(e_tmpname);
407 + e_tmpname = Nullch;
410 /* now that script is parsed, we can modify record separator */
411 @@ -1369,7 +1371,7 @@ SV *sv;
415 - origfilename = savepv(e_fp ? "-e" : scriptname);
416 + origfilename = savepv(e_tmpname ? "-e" : scriptname);
417 curcop->cop_filegv = gv_fetchfile(origfilename);
418 if (strEQ(origfilename,"-"))
424 # Parallel build for miniperl is safe
425 system "make $j miniperl";
427 if ($target ne 'miniperl') {
428 # Nearly all parallel build issues fixed by 5.10.0. Untrustworthy before that.
429 $j = '' unless $major > 10;
431 if ($target eq 'test_prep') {
433 # test-prep was added in 5.004_01, 3e3baf6d63945cb6.
434 # renamed to test_prep in 2001 in 5fe84fd29acaf55c.
435 # earlier than that, just make test. It will be fast enough.
436 $target = extract_from_file('Makefile.SH', qr/^(test[-_]prep):/,
441 system "make $j $target";
444 my $missing_target = $expected =~ /perl$/ ? !-x $expected : !-r $expected;
446 if ($options{'test-build'}) {
447 report_and_exit($missing_target, 'could build', 'could not build', $target);
448 } elsif ($missing_target) {
449 skip("could not build $target");
452 # This is what we came here to run:
453 my $ret = system @ARGV;
455 report_and_exit($ret, 'zero exit from', 'non-zero exit from', "@ARGV");
458 # cperl-indent-level: 4
459 # indent-tabs-mode: nil
462 # ex: set ts=8 sts=4 sw=4 et: