Following the license change, modify the boilerplates in util/, tools/
[openssl.git] / util / process_docs.pl
index 2b7f3227d3c8a0510506209281eb1540f528f65b..d2fef5dedf3153f15c8cd69673597cfcc311e323 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env perl
-# Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+# Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
 #
-# Licensed under the OpenSSL license (the "License").  You may not use
+# Licensed under the Apache License 2.0 (the "License").  You may not use
 # this file except in compliance with the License.  You can obtain a copy
 # in the file LICENSE in the source distribution or at
 # https://www.openssl.org/source/license.html
@@ -29,7 +29,7 @@ use OpenSSL::Util::Pod;
 
 my %options = ();
 GetOptions(\%options,
-           'sourcedir=s',       # Source directory
+           'sourcedir=s@',      # Source directories
            'section=i@',        # Subdirectories to look through,
                                 # with associated section numbers
            'destdir=s',         # Destination directory
@@ -46,7 +46,8 @@ unless ($options{section}) {
     $options{section} = [ 1, 3, 5, 7 ];
 }
 unless ($options{sourcedir}) {
-    $options{sourcedir} = catdir($config{sourcedir}, "doc");
+    $options{sourcedir} = [ catdir($config{sourcedir}, "doc"),
+                            catdir($config{builddir}, "doc") ];
 }
 pod2usage(1) unless ( defined $options{section}
                       && defined $options{sourcedir}
@@ -59,8 +60,9 @@ pod2usage(1) if ( $options{type} eq 'html'
 
 if ($options{debug}) {
     print STDERR "DEBUG: options:\n";
-    print STDERR "DEBUG:   --sourcedir = $options{sourcedir}\n"
-        if defined $options{sourcedir};
+    foreach (sort @{$options{sourcedir}}) {
+        print STDERR "DEBUG:   --sourcedir   = $_\n";
+    }
     print STDERR "DEBUG:   --destdir   = $options{destdir}\n"
         if defined $options{destdir};
     print STDERR "DEBUG:   --type      = $options{type}\n"
@@ -82,10 +84,10 @@ my $symlink_exists = eval { symlink("",""); 1 };
 
 foreach my $section (sort @{$options{section}}) {
     my $subdir = "man$section";
-    my $podsourcedir = catfile($options{sourcedir}, $subdir);
-    my $podglob = catfile($podsourcedir, "*.pod");
+    my @podsourcedirs = map { catfile($_, $subdir); } @{$options{sourcedir}};
+    my @podglobs = map { catfile($_, "*.pod"); } @podsourcedirs;
 
-    foreach my $podfile (glob $podglob) {
+    foreach my $podfile (map { glob $_ } @podglobs) {
         my $podname = basename($podfile, ".pod");
         my $podpath = catfile($podfile);
         my %podinfo = extract_pod_info($podpath,
@@ -98,7 +100,7 @@ foreach my $section (sort @{$options{section}}) {
         my $suffix = { man  => ".$podinfo{section}".($options{suffix} // ""),
                        html => ".html" } -> {$options{type}};
         my $generate = { man  => "pod2man --name=$name --section=$podinfo{section} --center=OpenSSL --release=$config{version} \"$podpath\"",
-                         html => "pod2html \"--podroot=$options{sourcedir}\" --htmldir=$updir --podpath=man1:man3:man5:man7 \"--infile=$podpath\" \"--title=$podname\""
+                         html => "pod2html \"--podroot=$options{sourcedir}\" --htmldir=$updir --podpath=man1:man3:man5:man7 \"--infile=$podpath\" \"--title=$podname\" --quiet"
                          } -> {$options{type}};
         my $output_dir = catdir($options{destdir}, "man$podinfo{section}");
         my $output_file = $podname . $suffix;
@@ -112,6 +114,32 @@ foreach my $section (sort @{$options{section}}) {
                 @output = `$generate`;
                 map { s|href="http://man\.he\.net/(man\d/[^"]+)(?:\.html)?"|href="../$1.html"|g; } @output
                     if $options{type} eq "html";
+                if ($options{type} eq "man") {
+                    # Because some *roff parsers are more strict than others,
+                    # multiple lines in the NAME section must be merged into
+                    # one.
+                    my $in_name = 0;
+                    my $name_line = "";
+                    my @newoutput = ();
+                    foreach (@output) {
+                        if ($in_name) {
+                            if (/^\.SH "/) {
+                                $in_name = 0;
+                                push @newoutput, $name_line."\n";
+                            } else {
+                                chomp (my $x = $_);
+                                $name_line .= " " if $name_line;
+                                $name_line .= $x;
+                                next;
+                            }
+                        }
+                        if (/^\.SH +"NAME" *$/) {
+                            $in_name = 1;
+                        }
+                        push @newoutput, $_;
+                    }
+                    @output = @newoutput;
+                }
             }
             print STDERR "DEBUG: Done processing\n" if $options{debug};
 
@@ -235,9 +263,9 @@ Print extra debugging output.
 
 =head1 COPYRIGHT
 
-Copyright 2013-2016 The OpenSSL Project Authors. All Rights Reserved.
+Copyright 2013-2018 The OpenSSL Project Authors. All Rights Reserved.
 
-Licensed under the OpenSSL license (the "License").  You may not use
+Licensed under the Apache License 2.0 (the "License").  You may not use
 this file except in compliance with the License.  You can obtain a copy
 in the file LICENSE in the source distribution or at
 https://www.openssl.org/source/license.html