4 use vars qw($masterpodfile %Build %Targets $Verbose $Up %Ignore
5 @Master %Readmes %Pods %Aux %Readmepods %Pragmata %Modules
16 $Up = File::Spec->updir;
17 $masterpodfile = File::Spec->catdir($Up, "pod.lst");
19 # Generate any/all of these files
20 # --verbose gives slightly more output
21 # --build-all tries to build everything
22 # --build-foo updates foo as follows
23 # --showfiles shows the files to be changed
28 manifest => File::Spec->catdir($Up, "MANIFEST"),
29 perlpod => "perl.pod",
30 vms => File::Spec->catdir($Up, "vms", "descrip_mms.template"),
31 nmake => File::Spec->catdir($Up, "win32", "Makefile"),
32 dmake => File::Spec->catdir($Up, "win32", "makefile.mk"),
33 podmak => File::Spec->catdir($Up, "win32", "pod.mak"),
34 # plan9 => File::Spec->catdir($Up, "plan9", "mkfile"),
35 unix => File::Spec->catdir($Up, "Makefile.SH"),
39 my @files = keys %Targets;
40 my $filesopts = join(" | ", map { "--build-$_" } "all", sort @files);
43 $0: Usage: $0 [--verbose] [--showfiles] $filesopts
46 && GetOptions (verbose => \$Verbose,
47 showfiles => \$showfiles,
48 map {+"build-$_", \$Build{$_}} @files, 'all');
49 # Set them all to true
50 @Build{@files} = @files if ($Build{all});
54 sort { lc $a cmp lc $b }
56 my ($v, $d, $f) = File::Spec->splitpath($_);
58 @d = defined $d ? File::Spec->splitdir($d) : ();
60 File::Spec->catfile(@d ?
61 (@d == 1 && $d[0] eq '' ? () : @d)
63 } @Targets{grep { $_ ne 'all' && $Build{$_} } keys %Build}),
69 # Don't copy these top level READMEs
78 print "I'm building $_\n" foreach grep {$Build{$_}} keys %Build;
81 chdir $FindBin::Bin or die "$0: Can't chdir $FindBin::Bin: $!";
83 open MASTER, $masterpodfile or die "$0: Can't open $masterpodfile: $!";
85 my ($delta_source, $delta_target);
90 # At least one upper case letter somewhere in the first group
91 if (/^(\S+)\s(.*)/ && $1 =~ tr/h//) {
95 my %flags = (header => 1);
96 $flags{toc_omit} = 1 if $flags =~ tr/o//d;
97 $flags{aux} = 1 if $flags =~ tr/a//d;
98 die "$0: Unknown flag found in heading line: $_" if length $flags;
99 push @Master, [\%flags, $2];
101 } elsif (/^(\S*)\s+(\S+)\s+(.*)/) {
103 my ($flags, $filename, $desc) = ($1, $2, $3);
105 my %flags = (indent => 0);
106 $flags{indent} = $1 if $flags =~ s/(\d+)//;
107 $flags{toc_omit} = 1 if $flags =~ tr/o//d;
108 $flags{aux} = 1 if $flags =~ tr/a//d;
110 if ($flags =~ tr/D//d) {
111 $flags{perlpod_omit} = 1;
112 $delta_source = "$filename.pod";
114 if ($flags =~ tr/d//d) {
115 $flags{manifest_omit} = 1;
116 $delta_target = "$filename.pod";
119 if ($flags =~ tr/r//d) {
120 my $readme = $filename;
121 $readme =~ s/^perl//;
122 $Readmepods{$filename} = $Readmes{$readme} = $desc;
124 } elsif ($flags{aux}) {
125 $Aux{$filename} = $desc;
127 $Pods{$filename} = $desc;
129 die "$0: Unknown flag found in section line: $_" if length $flags;
130 push @Master, [\%flags, $filename, $desc];
134 die "$0: Malformed line: $_" if $1 =~ tr/A-Z//;
137 if (defined $delta_source) {
138 if (defined $delta_target) {
139 # This way round so that keys can act as a MANIFEST skip list
140 # Targets will aways be in the pod directory. Currently we can only cope
141 # with sources being in the same directory. Fix this and do perlvms.pod
143 $Copies{$delta_target} = $delta_source;
145 die "$0: delta source defined but not target";
147 } elsif (defined $delta_target) {
148 die "$0: delta target defined but not target";
155 my (%disk_pods, @disk_pods);
156 my (@manipods, %manipods);
157 my (@manireadmes, %manireadmes);
158 my (@perlpods, %perlpods);
162 # Convert these to a list of filenames.
163 foreach (keys %Pods, keys %Readmepods) {
164 $our_pods{"$_.pod"}++;
167 # None of these filenames will be boolean false
168 @disk_pods = glob("*.pod");
169 @disk_pods{@disk_pods} = @disk_pods;
171 # Things we copy from won't be in perl.pod
172 # Things we copy to won't be in MANIFEST
173 @sources{values %Copies} = ();
175 open(MANI, "../MANIFEST") || die "$0: opening ../MANIFEST failed: $!";
177 if (m!^pod/([^.]+\.pod)\s+!i) {
179 } elsif (m!^README\.(\S+)\s+!i) {
181 push @manireadmes, "perl$1.pod";
185 @manipods{@manipods} = @manipods;
186 @manireadmes{@manireadmes} = @manireadmes;
188 open(PERLPOD, "perl.pod") || die "$0: opening perl.pod failed: $!\n";
190 if (/^For ease of access, /../^\(If you're intending /) {
191 if (/^\s+(perl\S*)\s+\w/) {
192 push @perlpods, "$1.pod";
197 die "$0: could not find the pod listing of perl.pod\n"
199 @perlpods{@perlpods} = @perlpods;
201 foreach my $i (sort keys %disk_pods) {
202 warn "$0: $i exists but is unknown by buildtoc\n"
203 unless $our_pods{$i};
204 warn "$0: $i exists but is unknown by ../MANIFEST\n"
205 if !$manipods{$i} && !$manireadmes{$i} && !$Copies{$i};
206 warn "$0: $i exists but is unknown by perl.pod\n"
207 if !$perlpods{$i} && !exists $sources{$i};
209 foreach my $i (sort keys %our_pods) {
210 warn "$0: $i is known by buildtoc but does not exist\n"
211 unless $disk_pods{$i};
213 foreach my $i (sort keys %manipods) {
214 warn "$0: $i is known by ../MANIFEST but does not exist\n"
215 unless $disk_pods{$i};
217 foreach my $i (sort keys %perlpods) {
218 warn "$0: $i is known by perl.pod but does not exist\n"
219 unless $disk_pods{$i};
223 # Find all the mdoules
226 find \&getpods => qw(../lib ../ext);
230 my $file = $File::Find::name;
231 return if $file eq '../lib/Pod/Functions.pm'; # Used only by pod itself
232 return if $file =~ m!(?:^|/)t/!;
233 return if $file =~ m!lib/Attribute/Handlers/demo/!;
234 return if $file =~ m!lib/Net/FTP/.+\.pm!; # Hi, Graham! :-)
235 return if $file =~ m!lib/Math/BigInt/t/!;
236 return if $file =~ m!/Devel/PPPort/[Hh]arness|lib/Devel/Harness!i;
237 return if $file =~ m!XS/(?:APItest|Typemap)!;
239 return if $pod =~ s/pm$/pod/ && -e $pod;
240 die "$0: tut $File::Find::name" if $file =~ /TUT/;
241 unless (open (F, "< $_\0")) {
242 warn "$0: bogus <$file>: $!";
243 system "ls", "-l", $file;
247 while ($line = <F>) {
248 if ($line =~ /^=head1\s+NAME\b/) {
249 push @modpods, $file;
250 #warn "GOOD $file\n";
254 warn "$0: $file: cannot find =head1 NAME\n";
259 die "$0: no pods" unless @modpods;
263 #($name) = /(\w+)\.p(m|od)$/;
264 my $name = path2modname($_);
265 if ($name =~ /^[a-z]/) {
266 $Pragmata{$name} = $_;
268 if ($done{$name}++) {
269 # warn "already did $_\n";
272 $Modules{$name} = $_;
277 # OK. Now a lot of ancillay function definitions follow
278 # Main program returns at "Do stuff"
292 open(OUT, ">perltoc.pod") || die "$0: creating perltoc.pod failed: $!";
296 ($_= <<"EOPOD2B") =~ s/^\t//gm && output($_);
298 # !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
299 # This file is autogenerated by buildtoc from all the other pods.
300 # Edit those files and run buildtoc --build-toc to effect changes.
304 perltoc - perl documentation table of contents
308 This page provides a brief table of contents for the rest of the Perl
309 documentation set. It is meant to be scanned quickly or grepped
310 through to locate the proper section you're looking for.
312 =head1 BASIC DOCUMENTATION
317 # All the things in the master list that happen to be pod filenames
318 podset(map {"$_->[1].pod"} grep {defined $_ && @$_ == 3 && !$_->[0]{toc_omit}} @Master);
321 ($_= <<"EOPOD2B") =~ s/^\t//gm && output($_);
325 =head1 PRAGMA DOCUMENTATION
329 podset(sort values %Pragmata);
331 ($_= <<"EOPOD2B") =~ s/^\t//gm && output($_);
335 =head1 MODULE DOCUMENTATION
339 podset( @Modules{ sort keys %Modules } );
344 =head1 AUXILIARY DOCUMENTATION
346 Here should be listed all the extra programs' documentation, but they
347 don't all have manual pages yet:
353 $_ .= join "\n", map {"\t=item $_\n"} sort keys %Aux;
360 Larry Wall <F<larry\@wall.org>>, with the help of oodles
368 output "\n"; # flush $LINE
371 # Below are all the auxiliary routines for generating perltoc.pod
373 my ($inhead1, $inhead2, $initem);
381 if (s/^=head1 (NAME)\s*/=head2 /) {
382 $pod = path2modname($ARGV);
384 output "\n \n\n=head2 ";
386 if ( /^\s*$pod\b/ ) {
387 s/$pod\.pm/$pod/; # '.pm' in NAME !?
395 if (s/^=head1 (.*)/=item $1/) {
397 output "=over 4\n\n" unless $inhead1;
399 output $_; nl(); next;
401 if (s/^=head2 (.*)/=item $1/) {
403 output "=over 4\n\n" unless $inhead2;
405 output $_; nl(); next;
407 if (s/^=item ([^=].*)/$1/) {
408 next if $pod eq 'perldiag';
409 s/^\s*\*\s*$// && next;
414 next if $pod eq 'perlmodlib' && /^ftp:/;
415 ##print "=over 4\n\n" unless $initem;
416 output ", " if $initem;
422 if (s/^=cut\s*\n//) {
432 output "\n\n=back\n\n";
440 output "\n\n=back\n\n";
448 ##print "\n\n=back\n\n";
457 my $NEWLINE = 0; # how many newlines have we seen recently
458 my $LINE; # what remains to be printed
461 for (split /(\n)/, shift) {
464 print OUT wrap('', '', $LINE);
467 if (($NEWLINE) < 2) {
472 elsif (/\S/ && length) {
479 # End of original buildtoc. From here on are routines to generate new sections
480 # for and inplace edit other files
482 sub generate_perlpod {
487 next if $flags->{aux};
488 next if $flags->{perlpod_omit};
492 push @output, "=head2 $_->[1]\n";
495 my $start = " " x (4 + $flags->{indent}) . $_->[1];
496 $maxlength = length $start if length ($start) > $maxlength;
497 push @output, [$start, $_->[2]];
502 die "$0: Illegal length " . scalar @$_;
505 # want at least 2 spaces padding
507 $maxlength = ($maxlength + 3) & ~3;
508 # sprintf gives $1.....$2 where ... are spaces:
509 return unexpand (map {ref $_ ? sprintf "%-${maxlength}s%s\n", @$_ : $_}
514 sub generate_manifest {
515 # Annyoingly unexpand doesn't consider it good form to replace a single
516 # space before a tab with a tab
517 # Annoyingly (2) it returns read only values.
518 my @temp = unexpand (map {sprintf "%-32s%s\n", @$_} @_);
519 map {s/ \t/\t\t/g; $_} @temp;
521 sub generate_manifest_pod {
522 generate_manifest map {["pod/$_.pod", $Pods{$_}]}
523 grep {!$Copies{"$_.pod"}} sort keys %Pods;
525 sub generate_manifest_readme {
526 generate_manifest map {["README.$_", $Readmes{$_}]} sort keys %Readmes;
529 sub generate_roffitall {
530 (map ({"\t\$maindir/$_.1\t\\"}sort keys %Pods),
532 map ({"\t\$maindir/$_.1\t\\"}sort keys %Aux),
534 map ({"\t\$libdir/$_.3\t\\"}sort keys %Pragmata),
536 map ({"\t\$libdir/$_.3\t\\"}sort keys %Modules),
540 sub generate_descrip_mms_1 {
541 local $Text::Wrap::columns = 150;
543 my @lines = map {"pod" . $count++ . " = $_"}
544 split /\n/, wrap('', '', join " ", map "[.lib.pod]$_.pod",
545 sort keys %Pods, keys %Readmepods);
546 @lines, "pod = " . join ' ', map {"\$(pod$_)"} 0 .. $count - 1;
549 sub generate_descrip_mms_2 {
550 map {sprintf <<'SNIP', $_, $_ eq 'perlvms' ? 'vms' : 'pod', $_}
551 [.lib.pod]%s.pod : [.%s]%s.pod
552 @ If F$Search("[.lib]pod.dir").eqs."" Then Create/Directory [.lib.pod]
553 Copy/NoConfirm/Log $(MMS$SOURCE) [.lib.pod]
555 sort keys %Pods, keys %Readmepods;
558 sub generate_nmake_1 {
559 # XXX Fix this with File::Spec
560 (map {sprintf "\tcopy ..\\README.%-8s ..\\pod\\perl$_.pod\n", $_}
562 (map {"\tcopy ..\\pod\\$Copies{$_} ..\\pod\\$_\n"} sort keys %Copies);
565 # This doesn't have a trailing newline
566 sub generate_nmake_2 {
567 # Spot the special case
568 local $Text::Wrap::columns = 76;
569 my $line = wrap ("\t ", "\t ",
570 join " ", sort keys %Copies,
571 map {"perl$_.pod"} "vms", keys %Readmes);
576 sub generate_pod_mak {
577 my $variable = shift;
579 my $line = join "\\\n", "\U$variable = ",
580 map {"\t$_.$variable\t"} sort keys %Pods;
582 $line =~ s/.*perltoc.html.*\n//m;
589 grep {! m!^pod/[^.]+\.pod.*\n!}
590 grep {! m!^README\.(\S+)! || $Ignore{$1}} @_;
591 # Dictionary order - fold and handle non-word chars as nothing
593 sort { $a->[1] cmp $b->[1] || $a->[0] cmp $b->[0] }
594 map { my $f = lc $_; $f =~ s/[^a-z0-9\s]//g; [ $_, $f ] }
596 &generate_manifest_pod(),
597 &generate_manifest_readme();
602 my $makefile = join '', @_;
603 die "$0: $name contains NUL bytes" if $makefile =~ /\0/;
604 $makefile =~ s/^\tcopy \.\.\\README.*\n/\0/gm;
605 my $sections = () = $makefile =~ m/\0+/g;
606 die "$0: $name contains no README copies" if $sections < 1;
607 die "$0: $name contains discontiguous README copies" if $sections > 1;
608 # Now remove the other copies that follow
609 1 while $makefile =~ s/\0\tcopy .*\n/\0/gm;
610 $makefile =~ s/\0+/join ("", &generate_nmake_1)/se;
612 $makefile =~ s{(del /f [^\n]+checkpods[^\n]+).*?(pod2html)}
613 {"$1\n" . &generate_nmake_2."\n\t $2"}se;
617 # shut up used only once warning
618 *do_dmake = *do_dmake = \&do_nmake;
622 my $pod = join '', @_;
624 unless ($pod =~ s{(For\ ease\ of\ access,\ .*\n)
625 (?:\s+[a-z]{4,}.*\n # fooo
626 |=head.*\n # =head foo
630 {$1 . join "", &generate_perlpod}mxe) {
631 die "$0: Failed to insert ammendments in do_perlpod";
638 my $body = join '', @_;
639 foreach my $variable (qw(pod man html tex)) {
640 die "$0: could not find $variable in $name"
641 unless $body =~ s{\n\U$variable\E = (?:[^\n]*\\\n)*[^\n]*}
642 {"\n" . generate_pod_mak ($variable)}se;
649 my $makefile = join '', @_;
650 die "$0: $name contains NUL bytes" if $makefile =~ /\0/;
651 $makefile =~ s/\npod\d* =[^\n]*/\0/gs;
652 my $sections = () = $makefile =~ m/\0+/g;
653 die "$0: $name contains no pod assignments" if $sections < 1;
654 die "$0: $name contains $sections discontigous pod assignments"
656 $makefile =~ s/\0+/join "\n", '', &generate_descrip_mms_1/se;
658 die "$0: $name contains NUL bytes" if $makefile =~ /\0/;
660 # Looking for rules like this
661 # [.lib.pod]perl.pod : [.pod]perl.pod
662 # @ If F$Search("[.lib]pod.dir").eqs."" Then Create/Directory [.lib.pod]
663 # Copy/NoConfirm/Log $(MMS$SOURCE) [.lib.pod]
665 $makefile =~ s/\n\Q[.lib.pod]\Eperl[^\n\.]*\.pod[^\n]+\n
666 [^\n]+\n # Another line
667 [^\n]+\Q[.lib.pod]\E\n # ends [.lib.pod]
669 $sections = () = $makefile =~ m/\0+/g;
670 die "$0: $name contains no copy rules" if $sections < 1;
671 die "$0: $name contains $sections discontigous copy rules"
673 $makefile =~ s/\0+/join "\n", '', &generate_descrip_mms_2/se;
679 my $makefile_SH = join '', @_;
680 die "$0: $name contains NUL bytes" if $makefile_SH =~ /\0/;
682 $makefile_SH =~ s/\n\s+-\@test -f \S+ && cd pod && \$\(LNS\) \S+ \S+ && cd \.\. && echo "\S+" >> extra.pods \# See buildtoc\n/\0/gm;
684 my $sections = () = $makefile_SH =~ m/\0+/g;
686 die "$0: $name contains no copy rules" if $sections < 1;
687 die "$0: $name contains $sections discontigous copy rules"
690 my @copy_rules = map "\t-\@test -f pod/$Copies{$_} && cd pod && \$(LNS) $Copies{$_} $_ && cd .. && echo \"pod/$_\" >> extra.pods # See buildtoc",
693 $makefile_SH =~ s/\0+/join "\n", '', @copy_rules, ''/se;
701 while (my ($target, $name) = each %Targets) {
702 next unless $Build{$target};
704 if ($target eq "toc") {
705 print "Now processing $name\n" if $Verbose;
707 print "Finished\n" if $Verbose;
710 print "Now processing $name\n" if $Verbose;
711 open THING, $name or die "Can't open $name: $!";
713 my $orig = join '', @orig;
717 &{"do_$target"}($target, @orig);
719 my $new = join '', @new;
721 print "Was not modified\n" if $Verbose;
724 rename $name, "$name.old" or die "$0: Can't rename $name to $name.old: $!";
725 open THING, ">$name" or die "$0: Can't open $name for writing: $!";
726 print THING $new or die "$0: print to $name failed: $!";
727 close THING or die die "$0: close $name failed: $!";
730 warn "$0: was not instructed to build anything\n" unless $built;