use strict;
use warnings;
+use Getopt::Long;
use IO::File;
use JSON;
use Data::Dumper;
+my $generate_depends;
+
+GetOptions("depends=s" => \$generate_depends) or
+ die("Error in command line arguments\n");
+
+
my $environments = {
default => 1,
wiki => 1,
pvelogo => 0, # ignore
};
-my $fileinfo = {
- outfile => {
- default => {
- "pve-admin-guide.adoc" => "pve-admin-guide.html",
- "datacenter.cfg.adoc" => "datacenter.cfg.5.html",
- "ha-manager.adoc" => "chapter-ha-manager.html",
- "pct.adoc" => "chapter-pct.html",
- "pve-bibliography.adoc" => "chapter-pve-bibliography.html",
- "pve-firewall.adoc" => "chapter-pve-firewall.html",
- "pve-installation.adoc" => "chapter-pve-installation.html",
- "pvecm.adoc" => "chapter-pvecm.html",
- "pvesm.adoc" => "chapter-pvesm.html",
- "pveum.adoc" => "chapter-pveum.html",
- "qm.adoc" => "chapter-qm.html",
- "sysadmin.adoc" => "chapter-sysadmin.html",
- "vzdump.adoc" => "chapter-vzdump.html",
- "pmxcfs.adoc" => "chapter-pmxcfs.html",
- "pve-faq.adoc" => "chapter-pve-faq.html",
- },
- manvolnum => {
- "ha-manager.adoc" => "ha-manager.1",
- "pct.adoc" => "pct.1",
- "pveam.adoc" => "pveam.1",
- "pveceph.adoc" => "pveceph.1",
- "pvecm.adoc" => "pvecm.1",
- "pveperf.adoc" => "pveperf.1",
- "pvesm.adoc" => "pvesm.1",
- "pvesubscription.adoc" => "pvesubscription.1",
- "pveum.adoc" => "pveum.1",
- "qm.adoc" => "qm.1",
- "qmrestore.adoc" => "qmrestore.1",
- "vzdump.adoc" => "vzdump.1",
- "datacenter.cfg.adoc" => "datacenter.cfg.5",
- "pct.conf.adoc" => "pct.conf.5",
- "qm.conf.adoc" => "qm.conf.5",
- "pmxcfs.adoc" => "pmxcfs.8",
- "pvedaemon.adoc" => "pvedaemon.8",
- "pve-firewall.adoc" => "pve-firewall.8",
- "pve-ha-crm.adoc" => "pve-ha-crm.8",
- "pve-ha-lrm.adoc" => "pve-ha-lrm.8",
- "pveproxy.adoc" => "pveproxy.8",
- "pvestatd.adoc" => "pvestatd.8",
- "spiceproxy.adoc" => "spiceproxy.8",
- },
- },
-};
+my $fileinfo = {};
my $start_env = [];
foreach my $e (keys %$environments) {
sub register_include {
my ($filename, $include_filename, $env_list) = @_;
- return if $include_filename !~ m/\.adoc$/; # skip attributes.txt
-
foreach my $e (@$env_list) {
$fileinfo->{include}->{$e}->{$filename}->{$include_filename} = 1;
}
die "unable to change title (no doctype)"
if !defined($fileinfo->{doctype}->{$env}->{$filename});
}
+ } elsif (!defined($doctype)) {
+ # change title via :title: attribute
+ $fileinfo->{titles}->{$env}->{$filename} = $title;
+ }
- if (defined($doctype) && ($env eq 'manvolnum') && ($doctype == 0)) {
- if ($title =~ m/.*\(([1-8])\)\s*$/) {
- $fileinfo->{mansection}->{$env}->{$filename} = $1;
- }
+ if (defined($doctype) && ($env eq 'manvolnum') && ($doctype == 0)) {
+ if ($title =~ m/.*\(([1-8])\)\s*$/) {
+ $fileinfo->{mansection}->{$env}->{$filename} = $1;
}
}
if (defined($mansection) && ($mansection == 5)) {
$realfn .= ".$mansection";
}
- my $realfn = "$realfn-plain.html";
+ $realfn = "$realfn-plain.html";
+ $fileinfo->{outfile}->{$e}->{$fn} = $realfn;
+ } elsif ($e eq 'manvolnum') {
+ my $realfn = $fn;
+ $realfn =~ s/\.adoc$//;
+ die "toplevel file '$fn' is not marked as manual page!" if !$mansection;
+ $realfn .= ".$mansection";
+ $fileinfo->{outfile}->{$e}->{$fn} = $realfn;
+ } elsif ($e eq 'default') {
+ my $realfn = $fn;
+ $realfn =~ s/\.adoc$//;
+ if (defined($mansection) && ($mansection == 5)) {
+ $realfn .= ".$mansection";
+ $realfn = "$realfn.html";
+ } else {
+ if (($fn ne 'pve-admin-guide.adoc') &&
+ $fileinfo->{doctype}->{$e}->{$fn} == 0) {
+ $realfn = "chapter-$realfn.html";
+ } else {
+ $realfn = "$realfn.html";
+ }
+ }
$fileinfo->{outfile}->{$e}->{$fn} = $realfn;
}
}
}
}
+if ($generate_depends) {
+
+ my $tmpfilename = "${generate_depends}.tmp";
+ my $outfh = IO::File->new($tmpfilename, "w") ||
+ die "unable to open temporary file '$tmpfilename'\n";
+
+ my $depends = {};
+ foreach my $e (@$start_env) {
+ my $env_data = $fileinfo->{include}->{$e};
+ foreach my $fn (keys %$env_data) {
+ foreach my $dep (keys %{$env_data->{$fn}}) {
+ $depends->{$fn}->{$dep} = 1;
+ }
+ }
+ }
+
+ my $res = '';
+
+ my $depend_varname_hash = {};
+
+ foreach my $fn (sort keys %$depends) {
+ my $basename = uc($fn);
+ $basename =~s/\.adoc$//i;
+ $basename =~s/[^A-Za-z0-9]/_/g;
+
+ my $var1text = "${basename}_ADOCSOURCES =";
+ my $var2text = "${basename}_ADOCDEPENDS = \$\{${basename}_ADOCSOURCES\}";
+ $depend_varname_hash->{$fn} = "${basename}_ADOCDEPENDS";
+
+ foreach my $dep (sort keys %{$depends->{$fn}}) {
+ if ($dep =~ m/-(opts|synopsis).adoc$/) {
+ $var2text .= " \\\n\t$dep";
+ } else {
+ $var1text .= " \\\n\t$dep";
+ }
+ }
+ $res .= "$var1text\n\n";
+ $res .= "$var2text\n\n";
+ }
+
+ my $man_sources_hash = {};
+ foreach my $e (@$start_env) {
+ my $filelist = $fileinfo->{outfile}->{$e};
+ foreach my $sourcefile (sort keys %$filelist) {
+ my $varname = $depend_varname_hash->{$sourcefile};
+ my $target = $filelist->{$sourcefile};
+ $res .= "$target: \$\{$varname\}\n\n";
+
+ if ($e eq 'manvolnum') {
+ $man_sources_hash->{$sourcefile} = 1;
+
+ $res .= "$target.html: \$\{$varname\}\n\n";
+ $res .= "$target-plain.html: \$\{$varname\}\n\n";
+ }
+ }
+ }
+
+ my $varname = "MANUAL_SOURCES";
+ $res .= "$varname =";
+ foreach my $sourcefile (sort keys %$man_sources_hash) {
+ $res .= " \\\n\t$sourcefile";
+ }
+ $res .= "\n\n";
+
+ $varname = "CHAPTER_LIST";
+ $res .= "$varname =";
+ my $filelist = $fileinfo->{outfile}->{default};
+ foreach my $sourcefile (sort keys %$filelist) {
+ my $target = $filelist->{$sourcefile};
+ $res .= " \\\n\t$target";
+ }
+ $res .= "\n\n";
+
+ $varname = "MANUAL_PAGES";
+ $res .= "$varname =";
+ $filelist = $fileinfo->{outfile}->{manvolnum};
+ foreach my $manpage (sort keys %$filelist) {
+ my $target = $filelist->{$manpage};
+ $res .= " \\\n\t$target";
+ }
+ $res .= "\n\n";
+
+ $varname = "WIKI_IMPORTS";
+ $res .= "$varname =";
+ $filelist = $fileinfo->{outfile}->{wiki};
+ foreach my $sourcefile (sort keys %$filelist) {
+ my $target = $filelist->{$sourcefile};
+ $res .= " \\\n\t$target";
+ }
+ $res .= "\n\n";
+
+ print $outfh $res;
+ close($outfh);
+
+ rename($tmpfilename, $generate_depends) ||
+ die "rename failed - $!";
+}
print to_json($fileinfo, { pretty => 1, canonical => 1 } );