X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=make-man-rules.py;h=0d1ca244c467d0b8bba7fdd85d42bc0f9703eee9;hp=9f53b55bbd3ff32ceeefe44d9febf3e9360dd279;hb=d711a957780932a2705d9ae9a1fc1b6fa7200b75;hpb=87cfe600c7a5c0632f8dcc7713b0b1e3825b75cc diff --git a/make-man-rules.py b/make-man-rules.py index 9f53b55bb..0d1ca244c 100644 --- a/make-man-rules.py +++ b/make-man-rules.py @@ -18,10 +18,10 @@ # along with systemd; If not, see . from __future__ import print_function -import xml.etree.ElementTree as tree import collections import sys -import os +import os.path +from xml_helper import * SECTION = '''\ MANPAGES += \\ @@ -46,22 +46,25 @@ HEADER = '''\ ''' -CLEANFILES = '''\ - -CLEANFILES += \\ - {cleanfiles} -''' - HTML_ALIAS_RULE = '''\ {}.html: {}.html $(html-alias) ''' +FOOTER = '''\ + +EXTRA_DIST += \\ + {files} +''' + def man(page, number): return 'man/{}.{}'.format(page, number) +def xml(file): + return 'man/{}'.format(os.path.basename(file)) + def add_rules(rules, name): - xml = tree.parse(name) + xml = xml_parse(name) # print('parsing {}'.format(name), file=sys.stderr) conditional = xml.getroot().get('conditional') or '' rulegroup = rules[conditional] @@ -79,7 +82,7 @@ def add_rules(rules, name): rulegroup[alias] = target # print('{} => {} [{}]'.format(alias, target, conditional), file=sys.stderr) -def create_rules(*xml_files): +def create_rules(xml_files): " {conditional => {alias-name => source-name}} " rules = collections.defaultdict(dict) for name in xml_files: @@ -89,7 +92,7 @@ def create_rules(*xml_files): def mjoin(files): return ' \\\n\t'.join(sorted(files) or '#') -def make_makefile(rules, cleanfiles): +def make_makefile(rules, files): return HEADER + '\n'.join( (CONDITIONAL if conditional else SECTION).format( manpages=mjoin(set(rulegroup.values())), @@ -101,13 +104,10 @@ def make_makefile(rules, cleanfiles): for k,v in sorted(rulegroup.items()) if k != v), conditional=conditional) - for conditional,rulegroup in sorted(rules.items())) + \ - CLEANFILES.format(cleanfiles=mjoin(cleanfiles)) + for conditional,rulegroup in sorted(rules.items()) + ) + FOOTER.format(files=mjoin(sorted(files))) if __name__ == '__main__': - sources = set(sys.argv[1:]) - basenames = [os.path.basename(source) for source in sources] - spares = set([source for source in sources - if os.path.basename(source) + '.in' in basenames]) - rules = create_rules(*(sources - spares)) - print(make_makefile(rules, spares), end='') + rules = create_rules(sys.argv[1:]) + files = (xml(file) for file in sys.argv[1:]) + print(make_makefile(rules, files), end='')