Mention the FreeBSD Perl policy change.
[p5sagit/p5-mst-13.2.git] / pod / buildtoc.PL
CommitLineData
4755096e 1#!/usr/local/bin/perl
2
3use Config;
4use File::Basename qw(&basename &dirname);
5use Cwd;
6
7# List explicitly here the variables you want Configure to
8# generate. Metaconfig only looks for shell variables, so you
9# have to mention them as if they were shell variables, not
10# %Config entries. Thus you write
11# $startperl
12# to ensure Configure will look for $Config{startperl}.
13
14# This forces PL files to create target in same directory as PL file.
15# This is so that make depend always knows where to find PL derivatives.
16$origdir = cwd;
17chdir(dirname($0));
18($file = basename($0)) =~ s/\.PL$//;
19$file =~ s/\.pl$// if ($^O eq 'os2' or $^O eq 'dos'); # "case-forgiving"
20$file =~ s/\.pl$/.com/ if ($^O eq 'VMS'); # "case-forgiving"
21
22open OUT,">$file" or die "Can't create $file: $!";
23
24print "Extracting $file (with variable substitutions)\n";
25
26# In this section, perl variables will be expanded during extraction.
27# You can use $Config{...} to use Configure variables.
28
29print OUT <<"!GROK!THIS!";
30$Config{'startperl'}
31 eval 'exec perl -S \$0 "\$@"'
32 if 0;
33!GROK!THIS!
34
35# In the following, perl variables are not expanded during extraction.
36
37print OUT <<'!NO!SUBS!';
38
39#
40# buildtoc
41#
42# !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
43# This file is autogenerated by buildtoc.PL.
44# Edit that file and run it to effect changes.
45#
46# Builds perltoc.pod and sanity checks the list of pods against all
47# of the MANIFEST, perl.pod, and ourselves.
48#
49
50use File::Find;
51use Cwd;
52use Text::Wrap;
53
54@PODS = glob("*.pod");
55
56sub output ($);
57
58if (-d "pod") {
59 die "$0: failed to chdir('pod'): $!\n" unless chdir("pod");
60}
61
a83b6f46 62@ARCHPODS = qw(
63 perlaix
64 perlapollo
65 perlamiga
66 perlbeos
67 perlbs2000
a1f19229 68 perlce
a83b6f46 69 perlcygwin
70 perldgux
71 perldos
72 perlepoc
73 perlhpux
74 perlhurd
75 perlmachten
76 perlmacos
77 perlmint
78 perlmpeix
9038e305 79 perlnetware
a83b6f46 80 perlos2
81 perlos390
82 perlqnx
83 perlplan9
84 perlsolaris
85 perltru64
91144103 86 perluts
a83b6f46 87 perlvmesa
88 perlvms
89 perlvos
90 perlwin32
91 );
92
d8416318 93@CJKPODS = qw(
94 perlcn
95 perljp
96 perlko
97 perltw
98 );
99
a83b6f46 100@pods =
101 (
102 qw(
103
c2e66d9e 104 perl
10151d09 105 perlintro
c2e66d9e 106 perlfaq
107 perltoc
108 perlbook
109
110 perlsyn
111 perldata
112 perlop
113 perlsub
114 perlfunc
115 perlreftut
116 perldsc
117 perlrequick
118 perlpod
8a93676d 119 perlpodspec
c2e66d9e 120 perlstyle
121 perltrap
122
123 perlrun
124 perldiag
125 perllexwarn
10862624 126 perldebtut
c2e66d9e 127 perldebug
128
129 perlvar
130 perllol
131 perlopentut
34babc16 132 perlpacktut
c2e66d9e 133 perlretut
134
c2e66d9e 135 perlre
d396a558 136 perlref
137
c2e66d9e 138 perlform
d396a558 139
140 perlboot
141 perltoot
890a53b9 142 perltooc
d396a558 143 perlobj
144 perlbot
145 perltie
c2e66d9e 146
147 perlipc
148 perlfork
149 perlnumber
53d7eaa8 150
c2e66d9e 151 perlthrtut
53d7eaa8 152 perlothrtut
c2e66d9e 153
154 perlport
d396a558 155 perllocale
07fcf8ff 156 perluniintro
d396a558 157 perlunicode
158 perlebcdic
c2e66d9e 159
d396a558 160 perlsec
c2e66d9e 161
162 perlmod
c2e66d9e 163 perlmodinstall
35bf961c 164 perlmodlib
165 perlmodstyle
c2e66d9e 166 perlnewmod
167
4755096e 168 perlfaq1
169 perlfaq2
170 perlfaq3
171 perlfaq4
172 perlfaq5
173 perlfaq6
174 perlfaq7
175 perlfaq8
176 perlfaq9
177
178 perlcompile
179
180 perlembed
181 perldebguts
182 perlxstut
183 perlxs
f40a6c71 184 perlclib
4755096e 185 perlguts
186 perlcall
187 perlutil
188 perlfilter
189 perldbmfilter
190 perlapi
191 perlintern
dc5c060f 192 perliol
4755096e 193 perlapio
194 perltodo
195 perlhack
196
197 perlhist
198 perldelta
245d750e 199 perl572delta
1db9e106 200 perl571delta
201 perl570delta
493a87da 202 perl561delta
4755096e 203 perl56delta
204 perl5005delta
205 perl5004delta
206
a83b6f46 207 ),
208
d8416318 209 @ARCHPODS,
a83b6f46 210
211 );
4755096e 212
4755096e 213for (@ARCHPODS) { s/$/.pod/ }
214@ARCHPODS{@ARCHPODS} = ();
215
d8416318 216for (@CJKPODS) { s/$/.pod/ }
217@CJKPODS{@CJKPODS} = ();
218
4755096e 219for (@pods) { s/$/.pod/ }
220@pods{@pods} = ();
221@PODS{@PODS} = ();
222
223open(MANI, "../MANIFEST") || die "$0: opening ../MANIFEST failed: $!";
224while (<MANI>) {
225 if (m!^pod/([^.]+\.pod)\s+!i) {
226 push @MANIPODS, $1;
227 }
228}
229close(MANI);
230@MANIPODS{@MANIPODS} = ();
231
232open(PERLPOD, "perl.pod") || die "$0: opening perl.pod failed: $!\n";
233while (<PERLPOD>) {
234 if (/^For ease of access, /../^\(If you're intending /) {
c2e66d9e 235 if (/^\s+(perl\S*)\s+\w/) {
4755096e 236 push @PERLPODS, "$1.pod";
237 }
238 }
239}
240close(PERLPOD);
241die "$0: could not find the pod listing of perl.pod\n"
242 unless @PERLPODS;
243@PERLPODS{@PERLPODS} = ();
244
d8416318 245# Delete the CJK because we cannot mix their encodings.
246delete @PERLPODS{@CJKPODS};
247delete @PODS{@CJKPODS};
248delete @pods{@CJKPODS};
249
4755096e 250# Cross-check against ourselves
251# Cross-check against the MANIFEST
252# Cross-check against the perl.pod
253
254foreach my $i (sort keys %PODS) {
255 warn "$0: $i exists but is unknown by buildtoc\n"
256 unless exists $pods{$i};
257 warn "$0: $i exists but is unknown by ../MANIFEST\n"
d8416318 258 if !exists $MANIPODS{$i} && !exists $ARCHPODS{$i} && !exists $CJKPODS{$i};
4755096e 259 warn "$0: $i exists but is unknown by perl.pod\n"
260 unless exists $PERLPODS{$i};
261}
262foreach my $i (sort keys %pods) {
263 warn "$0: $i is known by buildtoc but does not exist\n"
264 unless exists $PODS{$i};
265}
266foreach my $i (sort keys %MANIPODS) {
267 warn "$0: $i is known by ../MANIFEST but does not exist\n"
268 unless exists $PODS{$i};
269}
270foreach my $i (sort keys %PERLPODS) {
271 warn "$0: $i is known by perl.pod but does not exist\n"
272 unless exists $PODS{$i};
273}
274
275# We are ready to rock.
276open(OUT, ">perltoc.pod") || die "$0: creating perltoc.pod failed: $!";
277
278$/ = '';
279@ARGV = @pods;
280
281($_= <<EOPOD2B) =~ s/^\t//gm && output($_);
282
283 =head1 NAME
284
285 perltoc - perl documentation table of contents
286
287 =head1 DESCRIPTION
288
289 This page provides a brief table of contents for the rest of the Perl
290 documentation set. It is meant to be scanned quickly or grepped
291 through to locate the proper section you're looking for.
292
293 =head1 BASIC DOCUMENTATION
294
295EOPOD2B
296#' make emacs happy
297
298podset(@pods);
299
300find \&getpods => qw(../lib ../ext);
301
302sub getpods {
303 if (/\.p(od|m)$/) {
4755096e 304 my $file = $File::Find::name;
305 return if $file eq '../lib/Pod/Functions.pm'; # Used only by pod itself
a83b6f46 306 return if $file =~ m!lib/Attribute/Handlers/demo/!;
bc3d371b 307 return if $file =~ m!lib/Net/FTP/.+\.pm!; # Hi, Graham! :-)
ba62762e 308 return if $file =~ m!lib/Math/BigInt/t/!;
34babc16 309 return if $file =~ m!/Devel/PPPort/[Hh]arness|lib/Devel/Harness!i;
4755096e 310 die "tut $name" if $file =~ /TUT/;
311 unless (open (F, "< $_\0")) {
312 warn "bogus <$file>: $!";
313 system "ls", "-l", $file;
314 }
315 else {
316 my $line;
317 while ($line = <F>) {
318 if ($line =~ /^=head1\s+NAME\b/) {
319 push @modpods, $file;
320 #warn "GOOD $file\n";
321 return;
322 }
323 }
324 warn "$0: $file: cannot find =head1 NAME\n";
325 }
326 }
327}
328
329die "no pods" unless @modpods;
330
331for (@modpods) {
332 #($name) = /(\w+)\.p(m|od)$/;
333 $name = path2modname($_);
334 if ($name =~ /^[a-z]/) {
335 push @pragmata, $_;
336 } else {
337 if ($done{$name}++) {
338 # warn "already did $_\n";
339 next;
340 }
341 push @modules, $_;
342 push @modname, $name;
343 }
344}
345
346($_= <<EOPOD2B) =~ s/^\t//gm && output($_);
347
348
349
350 =head1 PRAGMA DOCUMENTATION
351
352EOPOD2B
353
354podset(sort @pragmata);
355
356($_= <<EOPOD2B) =~ s/^\t//gm && output($_);
357
358
359
360 =head1 MODULE DOCUMENTATION
361
362EOPOD2B
363
364podset( @modules[ sort { $modname[$a] cmp $modname[$b] } 0 .. $#modules ] );
365
366($_= <<EOPOD2B) =~ s/^\t//gm;
367
368
369 =head1 AUXILIARY DOCUMENTATION
370
371 Here should be listed all the extra programs' documentation, but they
372 don't all have manual pages yet:
373
13a2d996 374 =over 4
4755096e 375
376 =item a2p
377
378 =item s2p
379
380 =item find2perl
381
382 =item h2ph
383
384 =item c2ph
385
386 =item h2xs
387
388 =item xsubpp
389
390 =item pod2man
391
392 =item wrapsuid
393
394 =back
395
396 =head1 AUTHOR
397
398 Larry Wall <F<larry\@wall.org>>, with the help of oodles
399 of other folks.
400
401
402EOPOD2B
403output $_;
404output "\n"; # flush $LINE
405exit;
406
407sub podset {
408 local @ARGV = @_;
409
410 while(<>) {
411 if (s/^=head1 (NAME)\s*/=head2 /) {
412 $pod = path2modname($ARGV);
413 unhead1();
414 output "\n \n\n=head2 ";
415 $_ = <>;
416 if ( /^\s*$pod\b/ ) {
417 s/$pod\.pm/$pod/; # '.pm' in NAME !?
418 output $_;
419 } else {
420 s/^/$pod, /;
421 output $_;
422 }
423 next;
424 }
425 if (s/^=head1 (.*)/=item $1/) {
426 unhead2();
13a2d996 427 output "=over 4\n\n" unless $inhead1;
4755096e 428 $inhead1 = 1;
429 output $_; nl(); next;
430 }
431 if (s/^=head2 (.*)/=item $1/) {
432 unitem();
13a2d996 433 output "=over 4\n\n" unless $inhead2;
4755096e 434 $inhead2 = 1;
435 output $_; nl(); next;
436 }
437 if (s/^=item ([^=].*)/$1/) {
438 next if $pod eq 'perldiag';
439 s/^\s*\*\s*$// && next;
440 s/^\s*\*\s*//;
441 s/\n/ /g;
442 s/\s+$//;
443 next if /^[\d.]+$/;
444 next if $pod eq 'perlmodlib' && /^ftp:/;
13a2d996 445 ##print "=over 4\n\n" unless $initem;
4755096e 446 output ", " if $initem;
447 $initem = 1;
448 s/\.$//;
449 s/^-X\b/-I<X>/;
450 output $_; next;
451 }
452 if (s/^=cut\s*\n//) {
453 unhead1();
454 next;
455 }
456 }
457}
458
459sub path2modname {
460 local $_ = shift;
461 s/\.p(m|od)$//;
462 s-.*?/(lib|ext)/--;
463 s-/-::-g;
464 s/(\w+)::\1/$1/;
465 return $_;
466}
467
468sub unhead1 {
469 unhead2();
470 if ($inhead1) {
471 output "\n\n=back\n\n";
472 }
473 $inhead1 = 0;
474}
475
476sub unhead2 {
477 unitem();
478 if ($inhead2) {
479 output "\n\n=back\n\n";
480 }
481 $inhead2 = 0;
482}
483
484sub unitem {
485 if ($initem) {
486 output "\n\n";
487 ##print "\n\n=back\n\n";
488 }
489 $initem = 0;
490}
491
492sub nl {
493 output "\n";
494}
495
496my $NEWLINE; # how many newlines have we seen recently
497my $LINE; # what remains to be printed
498
499sub output ($) {
500 for (split /(\n)/, shift) {
501 if ($_ eq "\n") {
502 if ($LINE) {
503 print OUT wrap('', '', $LINE);
504 $LINE = '';
505 }
506 if ($NEWLINE < 2) {
507 print OUT;
508 $NEWLINE++;
509 }
510 }
511 elsif (/\S/ && length) {
512 $LINE .= $_;
513 $NEWLINE = 0;
514 }
515 }
516}
517
518!NO!SUBS!
519
6bbf1b34 520close OUT or die "Can't close $file: $!";
521chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
522exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
523chdir $origdir;