This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update IO-Compress to CPAN version 2.040
[perl5.git] / pod / buildtoc
index af9f525..96163c4 100644 (file)
@@ -13,6 +13,7 @@ use Getopt::Long;
 use Carp;
 
 no locale;
+require 5.010;
 
 {
   my $Top = File::Spec->catdir($FindBin::Bin, File::Spec->updir);
@@ -24,6 +25,17 @@ no locale;
   }
 }
 
+# make it clearer when we haven't run to completion, as we can be quite
+# noisy when things are working ok
+
+sub my_die {
+    print STDERR "$0: ", @_;
+    print STDERR "\n" unless $_[-1] =~ /\n\z/;
+    print STDERR "ABORTED\n";
+    exit 255;
+}
+
+
 $masterpodfile = abs_from_top('pod.lst');
 
 # Generate any/all of these files
@@ -32,8 +44,8 @@ $masterpodfile = abs_from_top('pod.lst');
 # --build-all tries to build everything
 # --build-foo updates foo as follows
 # --showfiles shows the files to be changed
-# --test exit early, exit if perl.pod, pod.lst, MANIFEST are
-#   consistent, die otherwise.
+# --test exit if perl.pod, pod.lst, MANIFEST are consistent, and regenerated
+#   files are up to date, die otherwise.
 
 %Targets
   = (
@@ -53,10 +65,13 @@ foreach (values %Targets) {
   $_ = abs_from_top($_);
 }
 
+# process command-line switches
+
 {
   my @files = keys %Targets;
   my $filesopts = join(" | ", map { "--build-$_" } "all", sort @files);
   my $showfiles;
+  my %build_these;
   die <<__USAGE__
 $0: Usage: $0 [--verbose] [--showfiles] $filesopts
 __USAGE__
@@ -65,9 +80,14 @@ __USAGE__
                       quiet => \$Quiet,
                       showfiles => \$showfiles,
                       test => \$Test,
-                      map {+"build-$_", \$Build{$_}} @files, 'all');
-  # Set them all to true
-  @Build{@files} = @files if ($Build{all});
+                      map {+"build-$_", \$build_these{$_}} @files, 'all');
+  if ($build_these{all}) {
+    %Build = %Targets;
+  } else {
+    while (my ($file, $want) = each %build_these) {
+      $Build{$file} = $Targets{$file} if $want;
+    }
+  }
   if ($showfiles) {
       print
          join(" ",
@@ -80,7 +100,7 @@ __USAGE__
                   File::Spec->catfile(@d ?
                                       (@d == 1 && $d[0] eq '' ? () : @d)
                                       : "pod", $f);
-              } @Targets{grep { $_ ne 'all' && $Build{$_} } keys %Build}),
+              } @Targets{@files}),
           "\n";
       exit(0);
   }
@@ -94,14 +114,33 @@ __USAGE__
      );
 
 if ($Verbose) {
-  print "I'm building $_\n" foreach grep {$Build{$_}} keys %Build;
+  print "I will be building $_\n" foreach keys %Build;
+}
+
+my $delta_target;
+
+{
+    my $source = 'perldelta.pod';
+    my $filename = abs_from_top("pod/$source");
+    open my $fh, '<', $filename or my_die "Can't open $filename: $!";
+    local $/;
+    my $contents = <$fh>;
+    my @want =
+       $contents =~ /perldelta - what is new for perl v5\.(\d+)\.(\d+)\n/;
+    die "Can't extract version from $filename" unless @want;
+    $delta_target = "perl5$want[0]$want[1]delta.pod";
+
+    # This way round so that keys can act as a MANIFEST skip list
+    # Targets will always be in the pod directory. Currently we can only cope
+    # with sources being in the same directory.
+    $Copies{$delta_target} = $source;
 }
 
-open MASTER, $masterpodfile or die "$0: Can't open $masterpodfile: $!";
+# process pod.lst
 
-my ($delta_source, $delta_target);
+open my $master, '<', $masterpodfile or my_die "Can't open $masterpodfile: $!";
 
-foreach (<MASTER>) {
+foreach (<$master>) {
   next if /^\#/;
 
   # At least one upper case letter somewhere in the first group
@@ -112,60 +151,44 @@ foreach (<MASTER>) {
     my %flags = (header => 1);
     $flags{toc_omit} = 1 if $flags =~ tr/o//d;
     $flags{aux} = 1 if $flags =~ tr/a//d;
-    die "$0: Unknown flag found in heading line: $_" if length $flags;
+    my_die "Unknown flag found in heading line: $_" if length $flags;
     push @Master, [\%flags, $2];
 
   } elsif (/^(\S*)\s+(\S+)\s+(.*)/) {
     # it's a section
-    my ($flags, $filename, $desc) = ($1, $2, $3);
+    my ($flags, $podname, $desc) = ($1, $2, $3);
+    my $filename = "${podname}.pod";
+    $filename = "pod/${filename}" if $filename !~ m{/};
 
     my %flags = (indent => 0);
     $flags{indent} = $1 if $flags =~ s/(\d+)//;
     $flags{toc_omit} = 1 if $flags =~ tr/o//d; 
     $flags{aux} = 1 if $flags =~ tr/a//d;
+    $flags{perlpod_omit} = "$podname.pod" eq $delta_target;
 
-    if ($flags =~ tr/D//d) {
-      $flags{manifest_omit} = 1;
-      $delta_source = "$filename.pod";
-    }
-    if ($flags =~ tr/d//d) {
-      $flags{perlpod_omit} = 1;
-      $delta_target = "$filename.pod";
-    }
-    $Generated{"$filename.pod"}++ if $flags =~ tr/g//d;
+    $Generated{"$podname.pod"}++ if $flags =~ tr/g//d;
 
     if ($flags =~ tr/r//d) {
-      my $readme = $filename;
+      my $readme = $podname;
       $readme =~ s/^perl//;
-      $Readmepods{$filename} = $Readmes{$readme} = $desc;
+      $Readmepods{$podname} = $Readmes{$readme} = $desc;
       $flags{readme} = 1;
     } elsif ($flags{aux}) {
-      $Aux{$filename} = $desc;
+      $Aux{$podname} = $desc;
     } else {
-      $Pods{$filename} = $desc;
+      $Pods{$podname} = $desc;
     }
-    die "$0: Unknown flag found in section line: $_" if length $flags;
-    push @Master, [\%flags, $filename, $desc];
+    my_die "Unknown flag found in section line: $_" if length $flags;
+    my $shortname = $podname =~ s{.*/}{}r;
+    push @Master, [\%flags, $podname, $filename, $desc, $shortname];
   } elsif (/^$/) {
     push @Master, undef;
   } else {
-    die "$0: Malformed line: $_" if $1 =~ tr/A-Z//;
-  }
-}
-if (defined $delta_source) {
-  if (defined $delta_target) {
-    # This way round so that keys can act as a MANIFEST skip list
-    # Targets will aways be in the pod directory. Currently we can only cope
-    # with sources being in the same directory.
-    $Copies{$delta_target} = $delta_source;
-  } else {
-    die "$0: delta source defined but not target";
+    my_die "Malformed line: $_" if $1 =~ tr/A-Z//;
   }
-} elsif (defined $delta_target) {
-  die "$0: delta target defined but not target";
 }
 
-close MASTER;
+close $master;
 
 # Sanity cross check
 {
@@ -173,15 +196,22 @@ close MASTER;
   my (@manipods, %manipods);
   my (@manireadmes, %manireadmes);
   my (@perlpods, %perlpods);
+  my (@cpanpods, %cpanpods, %cpanpods_short);
   my (%our_pods);
 
+  # These are stub files for deleted documents. We don't want them to show up
+  # in perl.pod, they just exist so that if someone types "perldoc perltoot"
+  # they get some sort of pointer to the new docs.
+  my %ignoredpods
+      = map { ( "$_.pod" => 1 ) } qw( perlboot perlbot perltooc perltoot );
+
   # Convert these to a list of filenames.
   foreach (keys %Pods, keys %Readmepods) {
     $our_pods{"$_.pod"}++;
   }
 
   opendir my $dh, abs_from_top('pod/');
-  while (readdir $dh) {
+  while (defined ($_ = readdir $dh)) {
     next unless /\.pod\z/;
     push @disk_pods, $_;
     ++$disk_pods{$_};
@@ -191,21 +221,29 @@ close MASTER;
   # Things we copy to won't be in MANIFEST
 
   my $filename = abs_from_top('MANIFEST');
-  open my $mani, '<', $filename or die "$0: opening $filename failed: $!";
+  open my $mani, '<', $filename or my_die "opening $filename failed: $!";
   while (<$mani>) {
-    if (m!^pod/([^.]+\.pod)\s+!i) {
+    chomp;
+    s/\s+.*$//;
+    if (m!^pod/([^.]+\.pod)!i) {
       push @manipods, $1;
-    } elsif (m!^README\.(\S+)\s+!i) {
+    } elsif (m!^README\.(\S+)!i) {
       next if $Ignore{$1};
       push @manireadmes, "perl$1.pod";
+    } elsif (exists $our_pods{$_}) {
+      push @cpanpods, $_;
+      $disk_pods{$_}++
+        if -e $_;
     }
   }
-  close $mani or die $!;
+  close $mani or my_die "close MANIFEST: $!\n";
   @manipods{@manipods} = @manipods;
   @manireadmes{@manireadmes} = @manireadmes;
+  @cpanpods{@cpanpods} = map { s/.*\///r } @cpanpods;
+  %cpanpods_short = reverse %cpanpods;
 
   $filename = abs_from_top('pod/perl.pod');
-  open my $perlpod, '<', $filename or die "$0: opening $filename failed: $!\n";
+  open my $perlpod, '<', $filename or my_die "opening $filename failed: $!\n";
   while (<$perlpod>) {
     if (/^For ease of access, /../^\(If you're intending /) {
       if (/^\s+(perl\S*)\s+\w/) {
@@ -213,8 +251,8 @@ close MASTER;
       }
     }
   }
-  close $perlpod or die $!;
-  die "$0: could not find the pod listing of perl.pod\n"
+  close $perlpod or my_die "close perlpod: $!\n";
+  my_die "could not find the pod listing of perl.pod\n"
     unless @perlpods;
   @perlpods{@perlpods} = @perlpods;
 
@@ -223,13 +261,15 @@ close MASTER;
     push @inconsistent, "$0: $i exists but is unknown by buildtoc\n"
       unless $our_pods{$i};
     push @inconsistent, "$0: $i exists but is unknown by ../MANIFEST\n"
-      if !$manipods{$i} && !$manireadmes{$i} && !$Copies{$i} && !$Generated{$i};
+      if !$manipods{$i} && !$manireadmes{$i} && !$Copies{$i} && !$Generated{$i} && !$cpanpods{$i};
     push @inconsistent, "$0: $i exists but is unknown by perl.pod\n"
-       if !$perlpods{$i} && !exists $Copies{$i};
+      if !$perlpods{$i} && !exists $Copies{$i} && !$cpanpods{$i} && !$ignoredpods{$i};
   }
-  my @BuildTargets = grep {defined} @Targets{grep $_ ne 'all', keys %Build};
   my %BuildFiles;
-  @BuildFiles{@BuildTargets} = @BuildTargets;
+  foreach my $path (values %Build) {
+    (undef, undef, my $file) = File::Spec->splitpath($path);
+    ++$BuildFiles{$file}
+  }
 
   foreach my $i (sort keys %our_pods) {
     push @inconsistent, "$0: $i is known by buildtoc but does not exist\n"
@@ -243,16 +283,16 @@ close MASTER;
   }
   foreach my $i (sort keys %perlpods) {
     push @inconsistent, "$0: $i is known by perl.pod but does not exist\n"
-      unless $disk_pods{$i} or $BuildFiles{$i};
+      unless $disk_pods{$i} or $BuildFiles{$i} or $cpanpods_short{$i};
   }
   if ($Test) {
-    print "1..1\n";
+    delete $Build{toc};
+    printf "1..%d\n", 1 + scalar keys %Build;
     if (@inconsistent) {
       print "not ok 1\n";
       die @inconsistent
     }
     print "ok 1\n";
-    exit;
   }
   else {
     warn @inconsistent if @inconsistent;
@@ -260,7 +300,7 @@ close MASTER;
 }
 
 # Find all the modules
-{
+if ($Build{toc}) {
   my @modpods;
   find \&getpods => abs_from_top('lib/');
 
@@ -276,26 +316,24 @@ close MASTER;
       return if $file =~ m!XS/(?:APItest|Typemap)!;
       my $pod = $file;
       return if $pod =~ s/pm$/pod/ && -e $pod;
-      unless (open (F, "< $_\0")) {
+      unless (open my $f, '<', $_) {
        warn "$0: bogus <$file>: $!";
        system "ls", "-l", $file;
       }
       else {
        my $line;
-       while ($line = <F>) {
+       while ($line = <$f>) {
          if ($line =~ /^=head1\s+NAME\b/) {
            push @modpods, $file;
-           close F;
            return;
          }
        }
-       close F;
-       warn "$0: $file: cannot find =head1 NAME\n" unless $Quiet;
+       warn "$0: NOTE: cannot find '=head1 NAME' in:\n  $file\n" unless $Quiet;
       }
     }
   }
 
-  die "$0: no pods" unless @modpods;
+  my_die "Can't find any pods!\n" unless @modpods;
 
   my %done;
   for (@modpods) {
@@ -303,7 +341,6 @@ close MASTER;
     $name =~ s/\.p(m|od)$//;
     $name =~ s-.*?/lib/--;
     $name =~ s-/-::-g;
-    $name =~ s/(\w+)::\1/$1/;
     next if $done{$name}++;
 
     if ($name =~ /^[a-z]/) {
@@ -317,16 +354,12 @@ close MASTER;
 # OK. Now a lot of ancillary function definitions follow
 # Main program returns at "Do stuff"
 
-sub output ($);
-
 my $OUT;
 
-sub output_perltoc {
+sub do_toc {
   my $filename = shift;
 
-  local $/ = '';
-
-  ($_= <<"EOPOD2B") =~ s/^\t//gm && output($_);
+  ($_= <<"EOPOD2B") =~ s/^\t//gm and $OUT .= $_;
 
        # !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
        # This file is autogenerated by buildtoc from all the other pods.
@@ -349,11 +382,11 @@ EOPOD2B
 
   # All the things in the master list that happen to be pod filenames
   foreach (grep {defined $_ && @$_ == 3 && !$_->[0]{toc_omit}} @Master) {
-    podset($_->[1], abs_from_top("pod/$_->[1].pod"));
+    podset($_->[1], abs_from_top($_->[2]));
   }
 
 
-  ($_= <<"EOPOD2B") =~ s/^\t//gm && output($_);
+  ($_= <<"EOPOD2B") =~ s/^\t//gm and $OUT .= $_;
 
 
 
@@ -365,7 +398,7 @@ EOPOD2B
     podset($_, $Pragmata{$_});
   }
 
-  ($_= <<"EOPOD2B") =~ s/^\t//gm && output($_);
+  ($_= <<"EOPOD2B") =~ s/^\t//gm and $OUT .= $_;
 
 
 
@@ -403,13 +436,14 @@ EOPOD2B
 EOPOD2B
 
   s/^\t//gm;
-  output $_;
-  output "\n";                    # flush $LINE
+  $OUT .= "$_\n";
 
+  $OUT =~ s/\n\s+\n/\n\n/gs;
   $OUT =~ s/\n{3,}/\n\n/g;
-  open OUT, '>', $filename or die "$0: creating $filename failed: $!";
-  print OUT $OUT;
-  close OUT;
+
+  $OUT =~ s/([^\n]+)/wrap('', '', $1)/ge;
+
+  return $OUT;
 }
 
 # Below are all the auxiliary routines for generating perltoc.pod
@@ -419,38 +453,37 @@ my ($inhead1, $inhead2, $initem);
 sub podset {
     my ($pod, $file) = @_;
 
-    open my $fh, '<', $file or die "Can't open file '$file' for $pod: $!";
+    local $/ = '';
+
+    open my $fh, '<', $file or my_die "Can't open file '$file' for $pod: $!";
 
     while(<$fh>) {
        tr/\015//d;
        if (s/^=head1 (NAME)\s*/=head2 /) {
            unhead1();
-           output "\n\n=head2 ";
+           $OUT .= "\n\n=head2 ";
            $_ = <$fh>;
            # Remove svn keyword expansions from the Perl FAQ
            s/ \(\$Revision: \d+ \$\)//g;
            if ( /^\s*\Q$pod\E\b/ ) {
                s/$pod\.pm/$pod/;       # '.pm' in NAME !?
-               output $_;
            } else {
                s/^/$pod, /;
-               output $_;
            }
-           next;
        }
-       if (s/^=head1 (.*)/=item $1/) {
+       elsif (s/^=head1 (.*)/=item $1/) {
            unhead2();
-           output "=over 4\n\n" unless $inhead1;
+           $OUT .= "=over 4\n\n" unless $inhead1;
            $inhead1 = 1;
-           output "$_\n"; next;
+           $_ .= "\n";
        }
-       if (s/^=head2 (.*)/=item $1/) {
+       elsif (s/^=head2 (.*)/=item $1/) {
            unitem();
-           output "=over 4\n\n" unless $inhead2;
+           $OUT .= "=over 4\n\n" unless $inhead2;
            $inhead2 = 1;
-           output "$_\n"; next;
+           $_ .= "\n";
        }
-       if (s/^=item ([^=].*)/$1/) {
+       elsif (s/^=item ([^=].*)/$1/) {
            next if $pod eq 'perldiag';
            s/^\s*\*\s*$// && next;
            s/^\s*\*\s*//;
@@ -458,23 +491,23 @@ sub podset {
            s/\s+$//;
            next if /^[\d.]+$/;
            next if $pod eq 'perlmodlib' && /^ftp:/;
-           output ", " if $initem;
+           $OUT .= ", " if $initem;
            $initem = 1;
            s/\.$//;
            s/^-X\b/-I<X>/;
-           output $_; next;
        }
-       if (s/^=cut\s*\n//) {
-           unhead1();
+       else {
+           unhead1() if /^=cut\s*\n/;
            next;
        }
+       $OUT .= $_;
     }
 }
 
 sub unhead1 {
     unhead2();
     if ($inhead1) {
-       output "\n\n=back\n\n";
+       $OUT .= "\n\n=back\n\n";
     }
     $inhead1 = 0;
 }
@@ -482,35 +515,18 @@ sub unhead1 {
 sub unhead2 {
     unitem();
     if ($inhead2) {
-       output "\n\n=back\n\n";
+       $OUT .= "\n\n=back\n\n";
     }
     $inhead2 = 0;
 }
 
 sub unitem {
     if ($initem) {
-       output "\n\n";
+       $OUT .= "\n\n";
     }
     $initem = 0;
 }
 
-my $LINE;              # what remains to be printed
-
-sub output ($) {
-    for (split /(\n)/, shift) {
-       if ($_ eq "\n") {
-           if ($LINE) {
-               $OUT .=  wrap('', '', $LINE);
-               $LINE = '';
-           }
-           $OUT .= $_;
-       }
-       elsif (/\S/) {
-           $LINE .= $_;
-       }
-    }
-}
-
 # End of original buildtoc. From here on are routines to generate new sections
 # for and inplace edit other files
 
@@ -525,16 +541,16 @@ sub generate_perlpod {
     if (@$_ == 2) {
       # Heading
       push @output, "=head2 $_->[1]\n";
-    } elsif (@$_ == 3) {
+    } elsif (@$_ == 5) {
       # Section
-      my $start = " " x (4 + $flags->{indent}) . $_->[1];
+      my $start = " " x (4 + $flags->{indent}) . $_->[4];
       $maxlength = length $start if length ($start) > $maxlength;
-      push @output, [$start, $_->[2]];
+      push @output, [$start, $_->[3]];
     } elsif (@$_ == 0) {
       # blank line
       push @output, "\n";
     } else {
-      die "$0: Illegal length " . scalar @$_;
+      my_die "Illegal length " . scalar @$_;
     }
   }
   # want at least 2 spaces padding
@@ -550,12 +566,14 @@ sub generate_manifest {
   # Annoyingly, unexpand doesn't consider it good form to replace a single
   # space before a tab with a tab
   # Annoyingly (2) it returns read only values.
-  my @temp = unexpand (map {sprintf "%-32s%s\n", @$_} @_);
+  my @temp = unexpand (map {sprintf "%-32s%s", @$_} @_);
   map {s/ \t/\t\t/g; $_} @temp;
 }
 sub generate_manifest_pod {
   generate_manifest map {["pod/$_.pod", $Pods{$_}]}
-    sort grep {!$Copies{"$_.pod"}} grep {!$Generated{"$_.pod"}} keys %Pods;
+    sort grep {
+       !$Copies{"$_.pod"} && !$Generated{"$_.pod"} && !-e "$_.pod"
+    } keys %Pods;
 }
 sub generate_manifest_readme {
   generate_manifest sort {$a->[0] cmp $b->[0]}
@@ -574,29 +592,6 @@ sub generate_roffitall {
   )
 }
 
-sub generate_descrip_mms_1 {
-  local $Text::Wrap::columns = 150;
-  my $count = 0;
-  my @lines = map {"pod" . $count++ . " = $_"}
-    split /\n/, wrap('', '', join " ", map "[.lib.pods]$_.pod",
-                    sort keys %Pods, keys %Readmepods);
-  @lines, "pod = " . join ' ', map {"\$(pod$_)"} 0 .. $count - 1;
-}
-
-sub generate_descrip_mms_2 {
-  map {<<"SNIP"}
-[.lib.pods]$_.pod : [.pod]$_.pod
-       \@ If F\$Search("[.lib]pods.dir").eqs."" Then Create/Directory [.lib.pods]
-       Copy/NoConfirm/Log \$(MMS\$SOURCE) [.lib.pods]
-SNIP
-   sort keys %Pods, keys %Readmepods;
-}
-
-sub generate_descrip_mms_3 {
-  map qq{\t- If F\$Search("[.pod]$_").nes."" Then Delete/NoConfirm/Log [.pod]$_;*},
-    sort keys %Generated, keys %Copies;
-}
-
 sub generate_nmake_1 {
   # XXX Fix this with File::Spec
   (map {sprintf "\tcopy ..\\README.%-8s ..\\pod\\perl$_.pod\n", $_}
@@ -619,8 +614,8 @@ sub generate_nmake_2 {
 sub generate_pod_mak {
   my $variable = shift;
   my @lines;
-  my $line = join "\\\n", "\U$variable = ",
-    map {"\t$_.$variable\t"} sort keys %Pods;
+  my $line = "\U$variable = " . join "\t\\\n\t",
+    map {"$_.$variable"} sort grep { $_ !~ m{/} } keys %Pods;
   # Special case
   $line =~ s/.*perltoc.html.*\n//m;
   $line;
@@ -634,23 +629,22 @@ sub verify_contiguous {
 }
 
 sub do_manifest {
-  my $name = shift;
+  my ($name, $prev) = @_;
   my @manifest =
-    grep {! m!^pod/[^.]+\.pod.*\n!}
-      grep {! m!^README\.(\S+)! || $Ignore{$1}} @_;
-  # Dictionary order - fold and handle non-word chars as nothing
-  map  { $_->[0] }
-  sort { $a->[1] cmp $b->[1] || $a->[0] cmp $b->[0] }
-  map  { my $f = lc $_; $f =~ s/[^a-z0-9\s]//g; [ $_, $f ] }
-    @manifest,
-      &generate_manifest_pod(),
-       &generate_manifest_readme();
+    grep {! m!^pod/[^.]+\.pod.*!}
+      grep {! m!^README\.(\S+)! || $Ignore{$1}} split "\n", $prev;
+  join "\n", (
+             # Dictionary order - fold and handle non-word chars as nothing
+             map  { $_->[0] }
+             sort { $a->[1] cmp $b->[1] || $a->[0] cmp $b->[0] }
+             map  { my $f = lc $_; $f =~ s/[^a-z0-9\s]//g; [ $_, $f ] }
+             @manifest,
+             &generate_manifest_pod(),
+             &generate_manifest_readme()), '';
 }
 
 sub do_nmake {
-  my $name = shift;
-  my $makefile = join '', @_;
-  die "$0: $name contains NUL bytes" if $makefile =~ /\0/;
+  my ($name, $makefile) = @_;
   $makefile =~ s/^\tcopy \.\.\\README.*\n/\0/gm;
   verify_contiguous($name, $makefile, 'README copies');
   # Now remove the other copies that follow
@@ -666,8 +660,7 @@ sub do_nmake {
 *do_dmake = *do_dmake = \&do_nmake;
 
 sub do_perlpod {
-  my $name = shift;
-  my $pod = join '', @_;
+  my ($name, $pod) = @_;
 
   unless ($pod =~ s{(For\ ease\ of\ access,\ .*\n)
                    (?:\s+[a-z]{4,}.*\n #   fooo
@@ -676,16 +669,15 @@ sub do_perlpod {
                   )+
                  }
          {$1 . join "", &generate_perlpod}mxe) {
-    die "$0: Failed to insert amendments in do_perlpod";
+    my_die "Failed to insert amendments in do_perlpod";
   }
   $pod;
 }
 
 sub do_podmak {
-  my $name = shift;
-  my $body = join '', @_;
+  my ($name, $body) = @_;
   foreach my $variable (qw(pod man html tex)) {
-    die "$0: could not find $variable in $name"
+    my_die "could not find $variable in $name"
       unless $body =~ s{\n\U$variable\E = (?:[^\n]*\\\n)*[^\n]*}
        {"\n" . generate_pod_mak ($variable)}se;
   }
@@ -693,40 +685,21 @@ sub do_podmak {
 }
 
 sub do_vms {
-  my $name = shift;
-  my $makefile = join '', @_;
-  die "$0: $name contains NUL bytes" if $makefile =~ /\0/;
-  $makefile =~ s/\npod\d* =[^\n]*/\0/gs;
-  verify_contiguous($name, $makefile, 'pod assignments');
-  $makefile =~ s/\0+/join "\n", '', &generate_descrip_mms_1/se;
-
-  die "$0: $name contains NUL bytes" if $makefile =~ /\0/;
-
-# Looking for rules like this
-# [.lib.pods]perl.pod : [.pod]perl.pod
-#      @ If F$Search("[.lib]pods.dir").eqs."" Then Create/Directory [.lib.pods]
-#      Copy/NoConfirm/Log $(MMS$SOURCE) [.lib.pods]
-
-  $makefile =~ s/\n\Q[.lib.pods]\Eperl[^\n\.]*\.pod[^\n]+\n
-                [^\n]+\n       # Another line
-                [^\n]+\Q[.lib.pods]\E\n                # ends [.lib.pods]
-                   /\0/gsx;
-  verify_contiguous($name, $makefile, 'copy rules');
-  $makefile =~ s/\0+/join "\n", '', &generate_descrip_mms_2/se;
-
-# Looking for rules like this:
-#      - If F$Search("[.pod]perldelta.pod").nes."" Then Delete/NoConfirm/Log [.pod]perldelta.pod;*
-  $makefile =~ s!(?:\t- If F\$Search\("\[\.pod\]perl\d*[a-z]+\Q.pod").nes."" Then Delete/NoConfirm/Log [.pod]perl\E\d*[a-z]+\.pod;\*\n)+!\0!sg;
-  verify_contiguous($name, $makefile, 'delete rules');
-  $makefile =~ s/\0+/join "\n", &generate_descrip_mms_3, ''/se;
+  my ($name, $makefile) = @_;
+
+# Looking for the macro defining the current perldelta:
+#PERLDELTA_CURRENT = [.pod]perl5139delta.pod
+
+  $makefile =~ s/\nPERLDELTA_CURRENT\s+=\s+\Q[.pod]perl\E\d+delta\.pod\n
+                   /\0/sx;
+  verify_contiguous($name, $makefile, 'current perldelta macro');
+  $makefile =~ s/\0+/join "\n", '', "PERLDELTA_CURRENT = [.pod]$delta_target", ''/se;
 
   $makefile;
 }
 
 sub do_unix {
-  my $name = shift;
-  my $makefile_SH = join '', @_;
-  die "$0: $name contains NUL bytes" if $makefile_SH =~ /\0/;
+  my ($name, $makefile_SH) = @_;
 
   $makefile_SH =~ s{^(perltoc_pod_prereqs = extra.pods).*}
                   {join ' ', $1, map "pod/$_",
@@ -760,34 +733,44 @@ while (my ($target, $name) = each %Targets) {
   print "Working on target $target\n" if $Verbose;
   next unless $Build{$target};
   $built++;
-  if ($target eq "toc") {
-    print "Now processing $name\n" if $Verbose;
-    output_perltoc($name);
-    print "Finished\n" if $Verbose;
-    next;
-  }
+  my ($orig, $mode);
   print "Now processing $name\n" if $Verbose;
-  open THING, $name or die "Can't open $name: $!";
-  binmode THING;
-  my @orig = <THING>;
-  my $orig = join '', @orig;
-  close THING;
-  my @new = do {
+  if ($target ne "toc") {
+    local $/;
+    open my $thing, '<', $name or my_die "Can't open $name: $!";
+    binmode $thing;
+    $orig = <$thing>;
+    my_die "$name contains NUL bytes" if $orig =~ /\0/;
+  }
+
+  my $new = do {
     no strict 'refs';
-    &{"do_$target"}($target, @orig);
+    &{"do_$target"}($target, $orig);
   };
-  my $new = join '', @new;
-  if ($new eq $orig) {
-    print "Was not modified\n" if $Verbose;
-    next;
+
+  if (defined $orig) {
+    if ($new eq $orig) {
+      if ($Test) {
+       printf "ok %d # $name is up to date\n", $built + 1;
+      } elsif ($Verbose) {
+       print "Was not modified\n";
+      }
+      next;
+    } elsif ($Test) {
+      printf "not ok %d # $name is up to date\n", $built + 1;
+      next;
+    }
+    $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 my $thing, '>', $name or my_die "Can't open $name for writing: $!";
+  binmode $thing;
+  print $thing $new or my_die "print to $name failed: $!";
+  close $thing or my_die "close $name failed: $!";
+  if (defined $mode) {
+    chmod $mode & 0777, $name or my_die "can't chmod $mode $name: $!";
   }
-  my $mode = (stat $name)[2] // die "$0: Can't stat $name: $!";
-  rename $name, "$name.old" or die "$0: Can't rename $name to $name.old: $!";
-  open THING, ">$name" or die "$0: Can't open $name for writing: $!";
-  binmode THING;
-  print THING $new or die "$0: print to $name failed: $!";
-  close THING or die "$0: close $name failed: $!";
-  chmod $mode & 0777, $name or die "$0: can't chmod $mode $name: $!";
 }
 
-warn "$0: was not instructed to build anything\n" unless $built;
+warn "$0: was not instructed to build anything\n" unless $built || $Test;