1 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # This file is part of systemd.
5 # Copyright 2013 Zbigniew Jędrzejewski-Szmek
7 # systemd is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or
10 # (at your option) any later version.
12 # systemd is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 from __future__ import print_function
24 from xml_helper import *
44 # Do not edit. Generated by make-man-rules.py.
45 # Regenerate with 'make all update-man-list'.
49 HTML_ALIAS_RULE = '''\
60 def man(page, number):
61 return 'man/{}.{}'.format(page, number)
64 return 'man/{}'.format(os.path.basename(file))
66 def add_rules(rules, name):
68 # print('parsing {}'.format(name), file=sys.stderr)
69 conditional = xml.getroot().get('conditional') or ''
70 rulegroup = rules[conditional]
71 refmeta = xml.find('./refmeta')
72 title = refmeta.find('./refentrytitle').text
73 number = refmeta.find('./manvolnum').text
74 refnames = xml.findall('./refnamediv/refname')
75 target = man(refnames[0].text, number)
76 if title != refnames[0].text:
77 raise ValueError('refmeta and refnamediv disagree: ' + name)
78 for refname in refnames:
79 assert all(refname not in group
80 for group in rules.values()), "duplicate page name"
81 alias = man(refname.text, number)
82 rulegroup[alias] = target
83 # print('{} => {} [{}]'.format(alias, target, conditional), file=sys.stderr)
85 def create_rules(xml_files):
86 " {conditional => {alias-name => source-name}} "
87 rules = collections.defaultdict(dict)
88 for name in xml_files:
89 add_rules(rules, name)
93 return ' \\\n\t'.join(sorted(files) or '#')
95 def make_makefile(rules, files):
96 return HEADER + '\n'.join(
97 (CONDITIONAL if conditional else SECTION).format(
98 manpages=mjoin(set(rulegroup.values())),
99 aliases=mjoin(k for k,v in rulegroup.items() if k != v),
100 rules='\n'.join('{}: {}'.format(k,v)
101 for k,v in sorted(rulegroup.items())
103 htmlrules='\n'.join(HTML_ALIAS_RULE.format(k[:-2],v[:-2])
104 for k,v in sorted(rulegroup.items())
106 conditional=conditional)
107 for conditional,rulegroup in sorted(rules.items())
108 ) + FOOTER.format(files=mjoin(sorted(files)))
110 if __name__ == '__main__':
111 rules = create_rules(sys.argv[1:])
112 files = (xml(file) for file in sys.argv[1:])
113 print(make_makefile(rules, files), end='')