2021-01-31 17:48:31 +01:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use autodie qw( :all );
|
|
|
|
|
|
|
|
use FindBin qw( $Bin );
|
|
|
|
|
|
|
|
use File::Path qw( mkpath );
|
2021-08-22 19:15:19 +02:00
|
|
|
use File::Slurp qw( edit_file read_file );
|
2021-01-31 17:48:31 +01:00
|
|
|
use File::Which qw( which );
|
|
|
|
|
|
|
|
sub main {
|
|
|
|
my $target = shift || "$Bin/..";
|
|
|
|
|
2021-08-22 19:15:19 +02:00
|
|
|
my @translators = qw ( lowdown pandoc );
|
|
|
|
my $translator;
|
|
|
|
foreach my $p (@translators) {
|
|
|
|
if ( defined which($p) ) {
|
|
|
|
$translator = $p;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unless ( defined $translator ) {
|
|
|
|
die "\n You must install one of "
|
|
|
|
. join( ', ', @translators )
|
|
|
|
. " in order to generate the man pages.\n\n";
|
|
|
|
}
|
2021-01-31 17:48:31 +01:00
|
|
|
|
2021-08-22 19:15:19 +02:00
|
|
|
_make_man( $translator, $target, 'libmaxminddb', 3 );
|
2021-01-31 17:48:31 +01:00
|
|
|
_make_lib_man_links($target);
|
|
|
|
|
2021-08-22 19:15:19 +02:00
|
|
|
_make_man( $translator, $target, 'mmdblookup', 1 );
|
2021-01-31 17:48:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub _make_man {
|
2021-08-22 19:15:19 +02:00
|
|
|
my $translator = shift;
|
|
|
|
my $target = shift;
|
|
|
|
my $name = shift;
|
|
|
|
my $section = shift;
|
2021-01-31 17:48:31 +01:00
|
|
|
|
2021-08-22 19:15:19 +02:00
|
|
|
my $input = "$Bin/../doc/$name.md";
|
2021-01-31 17:48:31 +01:00
|
|
|
my $man_dir = "$target/man/man$section";
|
|
|
|
mkpath($man_dir);
|
2021-08-22 19:15:19 +02:00
|
|
|
my $output = "$man_dir/$name.$section";
|
|
|
|
|
|
|
|
if ( $translator eq 'pandoc' ) {
|
|
|
|
system(
|
|
|
|
'pandoc',
|
|
|
|
'-s',
|
|
|
|
'-f', 'markdown_mmd+backtick_code_blocks',
|
|
|
|
'-t', 'man',
|
|
|
|
'-M', "title:$name",
|
|
|
|
'-M', "section:$section",
|
|
|
|
$input,
|
|
|
|
'-o', $output,
|
|
|
|
);
|
|
|
|
_pandoc_postprocess($output);
|
|
|
|
}
|
|
|
|
elsif ( $translator eq 'lowdown' ) {
|
|
|
|
system(
|
|
|
|
'lowdown',
|
|
|
|
'-s',
|
|
|
|
'--out-no-smarty',
|
|
|
|
'-Tman',
|
|
|
|
'-M', "title:$name",
|
|
|
|
'-M', "section:$section",
|
|
|
|
$input,
|
|
|
|
'-o', $output,
|
|
|
|
);
|
|
|
|
}
|
2021-01-31 17:48:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub _make_lib_man_links {
|
|
|
|
my $target = shift;
|
|
|
|
|
|
|
|
my $header = read_file("$Bin/../include/maxminddb.h");
|
2021-08-22 19:15:19 +02:00
|
|
|
for my $proto ( $header =~ /^ *extern.+?(MMDB_\w+)\(/gsm ) {
|
2021-01-31 17:48:31 +01:00
|
|
|
open my $fh, '>', "$target/man/man3/$proto.3";
|
|
|
|
print {$fh} ".so man3/libmaxminddb.3\n";
|
|
|
|
close $fh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# AFAICT there's no way to control the indentation depth for code blocks with
|
|
|
|
# Pandoc.
|
2021-08-22 19:15:19 +02:00
|
|
|
sub _pandoc_postprocess {
|
2021-01-31 17:48:31 +01:00
|
|
|
my $file = shift;
|
|
|
|
|
|
|
|
edit_file(
|
|
|
|
sub {
|
|
|
|
s/^\.IP\n\.nf/.IP "" 4\n.nf/gm;
|
2021-08-22 19:15:19 +02:00
|
|
|
s/(Automatically generated by Pandoc)(.+)$/$1/m;
|
2021-01-31 17:48:31 +01:00
|
|
|
},
|
|
|
|
$file
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
main(shift);
|