use Getopt::Long;
use Carp;
-# Generate the sections of files listed in %Targets from pod.lst
+# Generate the sections of files listed in %Targets from pod/perl.pod
# Mostly these are rules in Makefiles
#
# --verbose gives slightly more output
# --build-all tries to build everything
# --build-foo updates foo as follows
# --showfiles shows the files to be changed
-# --test exit if perl.pod, pod.lst, MANIFEST are consistent, and regenerated
+# --test exit if perl.pod, MANIFEST are consistent, and regenerated
# files are up to date, die otherwise.
%Targets = (
manifest => 'MANIFEST',
- perlpod => 'pod/perl.pod',
vms => 'vms/descrip_mms.template',
nmake => 'win32/Makefile',
dmake => 'win32/makefile.mk',
print "I will be building $_\n" foreach keys %Build;
}
+my $test = 1;
# For testing, generated files must be present and we're rebuilding nothing.
# For normal rebuilding, generated files may not be present, and we mute
# warnings about inconsistencies in any file we're about to rebuild.
-my $state = get_pod_metadata($Test ? () : (1, values %Build));
-
-my $test = 1;
-if ($Test) {
- printf "1..%d\n", 1 + scalar keys %Build;
- if (@{$state->{inconsistent}}) {
- print "not ok $test\n";
- die @{$state->{inconsistent}};
- }
- print "ok $test\n";
-}
-else {
- warn @{$state->{inconsistent}} if @{$state->{inconsistent}};
-}
-
-sub generate_perlpod {
- my @output;
- my $maxlength = 0;
- foreach (@{$state->{master}}) {
- my $flags = $_->[0];
- next if $flags->{aux};
- next if $flags->{perlpod_omit};
-
- if (@$_ == 2) {
- # Heading
- push @output, "=head2 $_->[1]\n";
- } elsif (@$_ == 5) {
- # Section
- my $start = " " x (4 + $flags->{indent}) . $_->[4];
- $maxlength = length $start if length ($start) > $maxlength;
- push @output, [$start, $_->[3]];
- } elsif (@$_ == 0) {
- # blank line
- push @output, "\n";
- } else {
- my_die "Illegal length " . scalar @$_;
- }
- }
- # want at least 2 spaces padding
- $maxlength += 2;
- $maxlength = ($maxlength + 3) & ~3;
- # sprintf gives $1.....$2 where ... are spaces:
- return unexpand (map {ref $_ ? sprintf "%-${maxlength}s%s\n", @$_ : $_}
- @output);
-}
+my $state = $Test
+ ? get_pod_metadata(0, sub {
+ printf "1..%d\n", 1 + scalar keys %Build;
+ if (@_) {
+ print "not ok $test\n";
+ die @_;
+ }
+ print "ok $test\n";
+ })
+ : get_pod_metadata(1, sub { warn @_ if @_ }, values %Build);
sub generate_manifest {
# Annoyingly, unexpand doesn't consider it good form to replace a single
sub do_manifest {
my ($name, $prev) = @_;
my @manifest =
- grep {! m!^pod/[^.]+\.pod.*!}
+ grep {! m!^pod/[^. \t]+\.pod.*!}
grep {! m!^README\.(\S+)! || $state->{ignore}{$1}} split "\n", $prev;
join "\n", (
# Dictionary order - fold and handle non-word chars as nothing
# shut up used only once warning
*do_dmake = *do_dmake = \&do_nmake;
-sub do_perlpod {
- my ($name, $pod) = @_;
-
- unless ($pod =~ s{(For\ ease\ of\ access,\ .*\n)
- (?:\s+[a-z]{4,}.*\n # fooo
- |=head.*\n # =head foo
- |\s*\n # blank line
- )+
- }
- {$1 . join "", &generate_perlpod}mxe) {
- my_die "Failed to insert amendments in do_perlpod";
- }
- $pod;
-}
-
sub do_podmak {
my ($name, $body) = @_;
foreach my $variable (qw(pod man html tex)) {
# pod/perl511delta.pod: pod/perldelta.pod
# cd pod && $(LNS) perldelta.pod perl511delta.pod
+ # although it seems that HP-UX make gets confused, always tried to
+ # regenerate the symlink, and then the ln -s fails, as the target exists.
+
$makefile_SH =~ s!(
pod/perl[a-z0-9_]+\.pod: pod/perl[a-z0-9_]+\.pod
+ \$\(RMS\) pod/perl[a-z0-9_]+\.pod
\$\(LNS\) perl[a-z0-9_]+\.pod pod/perl[a-z0-9_]+\.pod
)+!\0!gm;
my @copy_rules = map "
pod/$_: pod/$state->{copies}{$_}
+ \$(RMS) pod/$_
\$(LNS) $state->{copies}{$_} pod/$_
", keys %{$state->{copies}};
}
# Do stuff
-while (my ($target, $name) = each %Targets) {
+while (my ($target, $name) = each %Build) {
print "Now processing $name\n" if $Verbose;
- my $fh = open_or_die($name);
- binmode $fh;
- local $/;
- my $orig = <$fh>;
+ my $orig = slurp_or_die($name);
my_die "$name contains NUL bytes" if $orig =~ /\0/;
my $new = do {
my $mode = (stat $name)[2] // my_die "Can't stat $name: $!";
rename $name, "$name.old" or my_die "Can't rename $name to $name.old: $!";
- open $fh, '>', $name or my_die "Can't open $name for writing: $!";
- binmode $fh;
- print $fh $new or my_die "print to $name failed: $!";
- close $fh or my_die "close $name failed: $!";
+ write_or_die($name, $new);
chmod $mode & 0777, $name or my_die "can't chmod $mode $name: $!";
}