diff options
Diffstat (limited to 'tools/make-man-rules.py')
-rwxr-xr-x[-rw-r--r--] | tools/make-man-rules.py | 66 |
1 files changed, 43 insertions, 23 deletions
diff --git a/tools/make-man-rules.py b/tools/make-man-rules.py index 5e61917d60..582e0f1132 100644..100755 --- a/tools/make-man-rules.py +++ b/tools/make-man-rules.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # This file is part of systemd. @@ -24,16 +25,15 @@ import os.path from xml_helper import * SECTION = '''\ -MANPAGES += \\ +sdman.MANPAGES += \\ {manpages} -MANPAGES_ALIAS += \\ +sdman.MANPAGES_ALIAS += \\ {aliases} {rules} -{htmlrules} ''' CONDITIONAL = '''\ -if {conditional} +ifneq ($({conditional}),) ''' \ + SECTION + \ '''\ @@ -52,27 +52,33 @@ HEADER = '''\ # to <refentry> element. ''' -HTML_ALIAS_RULE = '''\ -{}.html: {}.html - $(html-alias) +RULE_XSLT = ''' +$(outdir)/{refname}.{section}: $(srcdir)/{refname}.xml $(topsrcdir)/man/custom-man.xsl {deps} + $(sdman.man-xslt) +$(outdir)/{refname}.html: $(srcdir)/{refname}.xml $(topsrcdir)/man/custom-html.xsl {deps} + $(sdman.html-xslt) +''' + +RULE_ALIAS = '''\ +$(outdir)/{refname}.{section}: $(outdir)/{srcrefname}.{srcsection} + $(sdman.man-alias) +$(outdir)/{refname}.html: $(outdir)/{srcrefname}.html + $(sdman.html-alias) ''' FOOTER = '''\ # Really, do not edit this file. - -EXTRA_DIST += \\ - {dist_files} ''' def man(page, number): - return 'man/{}.{}'.format(page, number) + return '{}.{}'.format(page, number) def xml(file): - return 'man/{}'.format(os.path.basename(file)) + return '{}'.format(os.path.basename(file)) def add_rules(rules, name): - xml = xml_parse(name) + xml, deps = xml_parse(name) # print('parsing {}'.format(name), file=sys.stderr) if xml.getroot().tag != 'refentry': return @@ -89,11 +95,17 @@ def add_rules(rules, name): assert all(refname not in group for group in rules.values()), "duplicate page name" alias = man(refname.text, number) - rulegroup[alias] = target + if alias == target: + rulegroup[alias] = deps + else: + rulegroup[alias] = target # print('{} => {} [{}]'.format(alias, target, conditional), file=sys.stderr) def create_rules(xml_files): - " {conditional => {alias-name => source-name}} " + """ + {conditional => {alias-name => source-name, + page-name => [sources...]}} + """ rules = collections.defaultdict(dict) for name in xml_files: try: @@ -106,17 +118,25 @@ def create_rules(xml_files): def mjoin(files): return ' \\\n\t'.join(sorted(files) or '#') +def make_makefile_rule(k, v): + if isinstance(v, str): + return RULE_ALIAS.format( + refname=k[:-2], + section=k[-1:], + srcrefname=v[:-2], + srcsection=v[-1:]) + else: + return RULE_XSLT.format( + refname=k[:-2], + section=k[-1:], + deps=' '.join(v)) + def make_makefile(rules, dist_files): return HEADER + '\n'.join( (CONDITIONAL if conditional else SECTION).format( - manpages=mjoin(set(rulegroup.values())), - aliases=mjoin(k for k,v in rulegroup.items() if k != v), - rules='\n'.join('{}: {}'.format(k,v) - for k,v in sorted(rulegroup.items()) - if k != v), - htmlrules='\n'.join(HTML_ALIAS_RULE.format(k[:-2],v[:-2]) - for k,v in sorted(rulegroup.items()) - if k != v), + manpages=mjoin(k for k,v in rulegroup.items() if not isinstance(v, str)), + aliases=mjoin(k for k,v in rulegroup.items() if isinstance(v, str)), + rules='\n'.join(make_makefile_rule(k, v) for k,v in sorted(rulegroup.items())), conditional=conditional) for conditional,rulegroup in sorted(rules.items()) ) + FOOTER.format(dist_files=mjoin(sorted(dist_files))) |