2 # Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
12 use File::Spec::Functions;
24 'sourcedir=s', # Source directory
25 'subdir=s%', # Subdirectories to look through,
26 # with associated section numbers
27 'destdir=s', # Destination directory
28 #'in=s@', # Explicit files to process (ignores sourcedir)
29 #'section=i', # Default section used for --in files
30 'type=s', # The result type, 'man' or 'html'
31 'remove', # To remove files rather than writing them
32 'dry-run|n', # Only output file names on STDOUT
36 unless ($options{subdir}) {
37 $options{subdir} = { apps => '1',
41 unless ($options{sourcedir}) {
42 $options{sourcedir} = catdir($config{sourcedir}, "doc");
44 pod2usage(1) unless ( defined $options{subdir}
45 && defined $options{sourcedir}
46 && defined $options{destdir}
47 && defined $options{type}
48 && ($options{type} eq 'man'
49 || $options{type} eq 'html') );
51 if ($options{debug}) {
52 print STDERR "DEBUG: options:\n";
53 print STDERR "DEBUG: --sourcedir = $options{sourcedir}\n"
54 if defined $options{sourcedir};
55 print STDERR "DEBUG: --destdir = $options{destdir}\n"
56 if defined $options{destdir};
57 print STDERR "DEBUG: --type = $options{type}\n"
58 if defined $options{type};
59 foreach (keys %{$options{subdir}}) {
60 print STDERR "DEBUG: --subdir = $_=$options{subdir}->{$_}\n";
62 print STDERR "DEBUG: --remove = $options{remove}\n"
63 if defined $options{remove};
64 print STDERR "DEBUG: --debug = $options{debug}\n"
65 if defined $options{debug};
66 print STDERR "DEBUG: --dry-run = $options{\"dry-run\"}\n"
67 if defined $options{"dry-run"};
70 my $symlink_exists = eval { symlink("",""); 1 };
72 foreach my $subdir (keys %{$options{subdir}}) {
73 my $section = $options{subdir}->{$subdir};
74 my $podsourcedir = catfile($options{sourcedir}, $subdir);
75 my $podglob = catfile($podsourcedir, "*.pod");
77 foreach my $podfile (glob "$podglob") {
78 my $podname = basename($podfile, ".pod");
79 my $podpath = catfile($podfile);
80 my %podinfo = ( section => $section );
82 print STDERR "DEBUG: Reading $podpath\n" if $options{debug};
83 open my $pod_fh, $podpath or die "Trying to read $podpath: $!\n";
86 if (m|^=for\s+comment\s+openssl_manual_section:\s*([0-9])\s*$|) {
87 print STDERR "Found section number $1\n" if $options{debug};
88 $podinfo{section} = $1;
91 && defined $podinfo{lastsect}
92 && $podinfo{lastsect} eq "NAME");
93 if (m|^=head1\s*(.*)|) {
94 $podinfo{lastsect} = $1;
95 $podinfo{lastsect} =~ s/\s+$//;
96 $podinfo{lastsecttext} = "";
98 next if (m|^=| || m|^\s*$|);
99 $podinfo{lastsecttext} .= " " if $podinfo{lastsecttext};
100 $podinfo{lastsecttext} .= $_;
103 $podinfo{lastsecttext} =~ s| - .*$||;
104 print STDERR "DEBUG: Done reading $podpath\n" if $options{debug};
107 grep { $_ ne $podname }
109 split(m|,|, $podinfo{lastsecttext});
112 my $name = uc $podname;
113 my $suffix = { man => ".$podinfo{section}",
114 html => ".html" } -> {$options{type}};
115 my $generate = { man => "pod2man --name=$name --section=$podinfo{section} --center=OpenSSL --release=$config{version} \"$podpath\"",
116 html => "pod2html \"--podroot=$options{sourcedir}\" --htmldir=$updir --podpath=apps:crypto:ssl \"--infile=$podpath\" \"--title=$podname\""
117 } -> {$options{type}};
118 my $output_dir = catdir($options{destdir}, "man$podinfo{section}");
119 my $output_file = $podname . $suffix;
120 my $output_path = catfile($output_dir, $output_file);
122 if (! $options{remove}) {
124 print STDERR "DEBUG: Processing, using \"$generate\"\n"
126 unless ($options{"dry-run"}) {
127 @output = `$generate`;
128 map { s|href="http://man\.he\.net/man|href="../man|g; } @output
129 if $options{type} eq "html";
131 print STDERR "DEBUG: Done processing\n" if $options{debug};
133 if (! -d $output_dir) {
134 print STDERR "DEBUG: Creating directory $output_dir\n" if $options{debug};
135 unless ($options{"dry-run"}) {
137 or die "Trying to create directory $output_dir: $!\n";
140 print STDERR "DEBUG: Writing $output_path\n" if $options{debug};
141 unless ($options{"dry-run"}) {
142 open my $output_fh, '>', $output_path
143 or die "Trying to write to $output_path: $!\n";
149 print STDERR "DEBUG: Done writing $output_path\n" if $options{debug};
151 print STDERR "DEBUG: Removing $output_path\n" if $options{debug};
152 unless ($options{"dry-run"}) {
153 while (unlink $output_path) {}
156 print "$output_path\n";
158 foreach (@podfiles) {
159 my $link_file = $_ . $suffix;
160 my $link_path = catfile($output_dir, $link_file);
161 if (! $options{remove}) {
162 if ($symlink_exists) {
163 print STDERR "DEBUG: Linking $link_path -> $output_file\n"
165 unless ($options{"dry-run"}) {
166 symlink $output_file, $link_path;
169 print STDERR "DEBUG: Copying $output_path to link_path\n"
171 unless ($options{"dry-run"}) {
172 copy $output_path, $link_path;
176 print STDERR "DEBUG: Removing $link_path\n" if $options{debug};
177 unless ($options{"dry-run"}) {
178 while (unlink $link_path) {}
181 print "$link_path -> $output_path\n";
192 process_docs.pl - A script to process OpenSSL docs
197 [B<--sourcedir>=I<dir>]
199 B<--type>=B<man>|B<html>
206 This script looks for .pod files in the subdirectories 'apps', 'crypto'
207 and 'ssl' under the given source directory.
209 The OpenSSL configuration data file F<configdata.pm> I<must> reside in
210 the current directory, I<or> perl must have the directory it resides in
211 in its inclusion array. For the latter variant, a call like this would
214 perl -I../foo util/process_docs.pl {options ...}
220 =item B<--sourcedir>=I<dir>
222 Top directory where the source files are found.
224 =item B<--destdir>=I<dir>
226 Top directory where the resulting files should end up
228 =item B<--type>=B<man>|B<html>
230 Type of output to produce. Currently supported are man pages and HTML files.
234 Instead of writing the files, remove them.
236 =item B<--dry-run>|B<-n>
238 Do not perform any file writing, directory creation or file removal.
240 =item B<--debug>|B<-D>
242 Print extra debugging output.
248 Copyright 2013-2016 The OpenSSL Project Authors. All Rights Reserved.
250 Licensed under the OpenSSL license (the "License"). You may not use
251 this file except in compliance with the License. You can obtain a copy
252 in the file LICENSE in the source distribution or at
253 https://www.openssl.org/source/license.html