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",
- },
- wiki => {
- "pve-usbstick.adoc" => "pve-usbstick-plain.html",
- "getting-help.adoc" => "getting-help-plain.html",
- "pve-system-requirements.adoc" => "pve-system-requirements-plain.html",
- "pve-network.adoc" => "pve-network-plain.html",
- "pve-package-repos.adoc" => "pve-package-repos-plain.html",
- "system-software-updates.adoc" => "system-software-updates-plain.html",
- "pve-disk-health-monitoring.adoc" => "pve-disk-health-monitoring-plain.html",
- "local-lvm.adoc" => "local-lvm-plain.html",
- "local-zfs.adoc" => "local-zfs-plain.html",
- "system-timesync.adoc" => "system-timesync-plain.html",
- "pve-installation.adoc" => "pve-installation-plain.html",
- "sysadmin.adoc" => "sysadmin-plain.html",
- "pvecm.adoc" => "pvecm-plain.html",
- "pmxcfs.adoc" => "pmxcfs-plain.html",
- "pvesm.adoc" => "pvesm-plain.html",
- "qm.adoc" => "qm-plain.html",
- "pve-firewall.adoc" => "pve-firewall-plain.html",
- "pveum.adoc" => "pveum-plain.html",
- "pct.adoc" => "pct-plain.html",
- "ha-manager.adoc" => "ha-manager-plain.html",
- "vzdump.adoc" => "vzdump-plain.html",
- "pve-faq.adoc" => "pve-faq-plain.html",
- "pve-bibliography.adoc" => "pve-bibliography-plain.html",
- "pve-storage-dir.adoc" => "pve-storage-dir-plain.html",
- "pve-storage-glusterfs.adoc" => "pve-storage-glusterfs-plain.html",
- "pve-storage-iscsi.adoc" => "pve-storage-iscsi-plain.html",
- "pve-storage-iscsidirect.adoc" => "pve-storage-iscsidirect-plain.html",
- "pve-storage-lvm.adoc" => "pve-storage-lvm-plain.html",
- "pve-storage-lvmthin.adoc" => "pve-storage-lvmthin-plain.html",
- "pve-storage-nfs.adoc" => "pve-storage-nfs-plain.html",
- "pve-storage-rbd.adoc" => "pve-storage-rbd-plain.html",
- "pve-storage-zfspool.adoc" => "pve-storage-zfspool-plain.html",
- },
- },
-};
+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;
}
}
# try to detect titles
foreach my $e (@{$env_stack->[-1]}) {
- if ($line =~ m/^=====+$/) {
+ if ($line =~ m/^===+$/) {
register_title($filename, $e, 0, $env_last_line->{$e},
$env_last_blockid->{$e});
- } elsif ($line =~ m/^-----+$/) {
+ } elsif ($line =~ m/^---+$/) {
register_title($filename, $e, 1, $env_last_line->{$e},
$env_last_blockid->{$e});
- } elsif ($line =~ m/^~~~~~+$/) {
+ } elsif ($line =~ m/^~~~+$/) {
register_title($filename, $e, 2, $env_last_line->{$e},
$env_last_blockid->{$e});
- } elsif ($line =~ m/^\^\^\^\^\^+$/) {
+ } elsif ($line =~ m/^\^\^\^+$/) {
register_title($filename, $e, 3, $env_last_line->{$e},
$env_last_blockid->{$e});
} elsif ($line =~ m/^= +(\S.*?)( +=)?$/) {
my $scanned_files = {};
while (my $filename = shift) {
next if $filename !~ m/\.adoc$/; # skip attributes.txt
+ next if $filename =~ m/-(opts|synopsis)\.adoc$/;
next if $scanned_files->{$filename};
scan_adoc_file($filename);
return $filename;
}
+
+# try to generate output file mapping
+foreach my $e (@$start_env) {
+ my $toplevel_hash = $fileinfo->{toplevel}->{$e};
+ foreach my $fn (sort keys %$toplevel_hash) {
+ my $mansection = $fileinfo->{mansection}->{manvolnum}->{$fn};
+ if ($e eq 'wiki') {
+ my $realfn = $fn;
+ $realfn =~ s/\.adoc$//;
+ if (defined($mansection) && ($mansection == 5)) {
+ $realfn .= ".$mansection";
+ }
+ $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;
+ }
+ }
+}
+
# now resolve blockids
foreach my $e (@$start_env) {
my $blockid_hash = $fileinfo->{blockid}->{$e};
$title =~ s/\s/_/g;
die "found not title for '$fn' in env '$e'" if !$title;
$fileinfo->{blockid_target}->{$e}->{$blockid} = "link:/wiki/$title#$blockid";
+
+ # we do not produce wiki pages for all content
+ #my $realfn = $fileinfo->{outfile}->{$e}->{$fn};
+ #warn "no output file mapping for '$fn' ($e)\n" if !$realfn;
+
} elsif ($e eq 'default') {
my $realfn = $fileinfo->{outfile}->{$e}->{$fn} ||
die "no output file mapping for '$fn'\n";
}
}
+my $makevar_hash = {};
+
+sub makevar_define {
+ my ($varname) = @_;
+
+ die "makefile variable '$varname' already defined\n"
+ if exists($makevar_hash->{$varname});
+
+ $makevar_hash->{$varname} = {};
+}
+
+sub makevar_list_add {
+ my ($varname, $value) = @_;
+
+ die "makefile variable '$varname' not defined\n"
+ if !exists($makevar_hash->{$varname});
+
+ $makevar_hash->{$varname}->{$value} = 1;
+}
+
+sub makevar_dump {
+ my $txt = '';
+
+ foreach my $varname (sort keys %$makevar_hash) {
+ $txt .= "$varname =";
+ foreach my $value (sort keys %{$makevar_hash->{$varname}}) {
+ $txt .= " \\\n\t$value";
+ }
+ $txt .= "\n\n";
+ }
+
+ return $txt;
+}
+
+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};
+
+ my $add_depends;
+
+ $add_depends = sub {
+ my ($fn, $dep) = @_;
+
+ $depends->{$fn}->{$dep} = 1;
+ foreach my $nd (keys %{$env_data->{$dep}}) {
+ &$add_depends($fn, $nd);
+ }
+ };
+
+ foreach my $fn (keys %$env_data) {
+ foreach my $dep (keys %{$env_data->{$fn}}) {
+ &$add_depends($fn, $dep);
+ }
+ }
+ }
+
+ 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 $varname1 = "${basename}_ADOCSOURCES";
+ my $varname2 = "${basename}_ADOCDEPENDS";
+
+ makevar_define($varname1);
+ makevar_define($varname2);
+
+ $depend_varname_hash->{$fn} = $varname2;
+
+ makevar_list_add($varname1, $fn);
+ makevar_list_add($varname2, "\$\{$varname1\}");
+
+ foreach my $dep (sort keys %{$depends->{$fn}}) {
+ if ($dep =~ m/-(opts|synopsis).adoc$/) {
+ makevar_list_add($varname2, $dep);
+ } else {
+ makevar_list_add($varname1, $dep);
+ }
+ }
+ }
+
+ my $man_sources_hash = {};
+ foreach my $sourcefile (keys %{$fileinfo->{outfile}->{manvolnum}}) {
+ $man_sources_hash->{$sourcefile} = 1;
+ my $ihash = $fileinfo->{include}->{manvolnum}->{$sourcefile};
+ foreach my $include (keys %$ihash) {
+ if ($include !~ m/-(opts|synopsis).adoc$/) {
+ $man_sources_hash->{$include} = 1;
+ }
+ }
+ }
+
+ my $varname = "MANUAL_SOURCES";
+ makevar_define($varname);
+ foreach my $sourcefile (sort keys %$man_sources_hash) {
+ makevar_list_add($varname, $sourcefile);
+ }
+
+ $varname = "CHAPTER_LIST";
+ makevar_define($varname);
+ my $filelist = $fileinfo->{outfile}->{default};
+ foreach my $sourcefile (sort keys %$filelist) {
+ my $target = $filelist->{$sourcefile};
+ makevar_list_add($varname, $target);
+ }
+
+ $varname = "MANUAL_PAGES";
+ makevar_define($varname);
+ $filelist = $fileinfo->{outfile}->{manvolnum};
+ foreach my $manpage (sort keys %$filelist) {
+ my $target = $filelist->{$manpage};
+ makevar_list_add($varname, $target);
+ }
+
+ $varname = "WIKI_IMPORTS";
+ makevar_define($varname);
+ $filelist = $fileinfo->{outfile}->{wiki};
+ foreach my $sourcefile (sort keys %$filelist) {
+ my $target = $filelist->{$sourcefile};
+ makevar_list_add($varname, $target);
+ }
+
+ my $res = makevar_dump();
+
+ my $make_targets = {};
+ foreach my $e (@$start_env) {
+ my $filelist = $fileinfo->{outfile}->{$e};
+ foreach my $sourcefile (sort keys %$filelist) {
+ my $varname = $depend_varname_hash->{$sourcefile};
+ next if !defined($varname);
+ my $target = $filelist->{$sourcefile};
+ my $dep = "\$\{$varname\}";
+ $make_targets->{$target} = $dep;
+ if ($e eq 'manvolnum') {
+ $make_targets->{"$target.html"} = $dep;
+ $make_targets->{"$target-plain.html"} = $dep;
+ }
+ }
+ }
+ foreach my $target (sort keys%$make_targets) {
+ my $dep = $make_targets->{$target};
+ $res .= "$target: $dep\n\n";
+ }
+
+ print $outfh $res;
+ close($outfh);
+
+ rename($tmpfilename, $generate_depends) ||
+ die "rename failed - $!";
+}
print to_json($fileinfo, { pretty => 1, canonical => 1 } );