From 56ba3c78ae35065064c4289a0c8e22a81256af20 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 2 Feb 2013 22:47:47 -0500 Subject: [PATCH] build-sys: create Makefile-man.am automatically man rules were repeating the same information in too many places, which was error prone. Those rules can be easily generated from .xml files. For efficiency and because python is not a required dependency, Makefile-man.am is only regenerated when requested with make update-man-list If no metadata in man/*.xml changed, this file should not change. So only when a new man page or a new alias is added, this file should show up in 'git diff'. The change should then be committed. If the support for building from git without python was dropped, we could drop Makefile-man.am from version control. This would also increase the partial build time (since more stuff would be rebuild whenever sources in man/*.xml would be modified), so it would probably wouldn't be worth it. --- Makefile-man.am | 12 ++++ Makefile.am | 7 ++ make-directive-index.py | 2 +- make-man-index.py | 2 +- make-man-rules.py | 92 ++++++++++++++++++++++++ man/binfmt.d.xml | 2 +- man/bootchart.conf.xml | 2 +- man/crypttab.xml | 2 +- man/hostnamectl.xml | 2 +- man/localectl.xml | 2 +- man/loginctl.xml | 2 +- man/logind.conf.xml | 2 +- man/modules-load.d.xml | 2 +- man/nss-myhostname.xml | 2 +- man/sd-login.xml | 2 +- man/sd-readahead.xml | 2 +- man/sd_get_seats.xml | 2 +- man/sd_login_monitor_new.xml | 2 +- man/sd_pid_get_session.xml | 2 +- man/sd_readahead.xml | 2 +- man/sd_seat_get_active.xml | 2 +- man/sd_session_is_active.xml | 2 +- man/sd_uid_get_state.xml | 2 +- man/systemd-binfmt.service.xml | 2 +- man/systemd-bootchart.xml | 2 +- man/systemd-cryptsetup-generator.xml | 2 +- man/systemd-cryptsetup@.service.xml | 2 +- man/systemd-hostnamed.service.xml | 2 +- man/systemd-journal-gatewayd.service.xml | 2 +- man/systemd-localed.service.xml | 2 +- man/systemd-logind.service.xml | 2 +- man/systemd-modules-load.service.xml | 2 +- man/systemd-quotacheck.service.xml | 2 +- man/systemd-random-seed-load.service.xml | 2 +- man/systemd-readahead-replay.service.xml | 2 +- man/systemd-timedated.service.xml | 2 +- man/systemd-user-sessions.service.xml | 2 +- man/systemd-vconsole-setup.service.xml | 2 +- man/timedatectl.xml | 2 +- man/vconsole.conf.xml | 2 +- 40 files changed, 148 insertions(+), 37 deletions(-) create mode 100644 make-man-rules.py diff --git a/Makefile-man.am b/Makefile-man.am index 76b794a27..d54d67cf1 100644 --- a/Makefile-man.am +++ b/Makefile-man.am @@ -1,3 +1,6 @@ +# Do not edit. Generated by make-man-rules.py. +# Regenerate with 'make man-list-update'. + MANPAGES += \ man/bootup.7 \ man/daemon.7 \ @@ -292,6 +295,9 @@ if ENABLE_BOOTCHART MANPAGES += \ man/bootchart.conf.5 \ man/systemd-bootchart.1 +MANPAGES_ALIAS += \ + # + endif if ENABLE_HOSTNAMED @@ -396,6 +402,9 @@ endif if HAVE_MYHOSTNAME MANPAGES += \ man/nss-myhostname.8 +MANPAGES_ALIAS += \ + # + endif if HAVE_PAM @@ -464,4 +473,7 @@ if HAVE_PYTHON MANPAGES += \ man/systemd.directives.7 \ man/systemd.index.7 +MANPAGES_ALIAS += \ + # + endif diff --git a/Makefile.am b/Makefile.am index ba55a7e1b..f73e8a6e7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -502,6 +502,13 @@ CLEANFILES += \ if HAVE_PYTHON NON_INDEX_XML_FILES = $(filter-out man/systemd.index.xml,$(XML_FILES)) + +XML_GLOB = $(wildcard $(top_srcdir)/man/*.xml) +update-man-list: make-man-rules.py $(XML_GLOB) + $(AM_V_GEN)$(PYTHON) $^ > $(top_srcdir)/Makefile-man.tmp + $(AM_V_at)mv $(top_srcdir)/Makefile-man.tmp $(top_srcdir)/Makefile-man.am + @echo "Makefile-man.am has been regenerated" + man/systemd.index.xml: make-man-index.py $(NON_INDEX_XML_FILES) $(AM_V_at)$(MKDIR_P) $(dir $@) $(AM_V_GEN)$(PYTHON) $^ > $@ diff --git a/make-directive-index.py b/make-directive-index.py index ab40997a9..b06a54c1d 100755 --- a/make-directive-index.py +++ b/make-directive-index.py @@ -23,7 +23,7 @@ import xml.etree.ElementTree as tree import re TEMPLATE = '''\ - + systemd.directives diff --git a/make-man-index.py b/make-man-index.py index 2dbc2da99..f829d98b6 100755 --- a/make-man-index.py +++ b/make-man-index.py @@ -24,7 +24,7 @@ import sys MDASH = ' — ' if sys.version_info.major >= 3 else ' -- ' TEMPLATE = '''\ - + systemd.index diff --git a/make-man-rules.py b/make-man-rules.py new file mode 100644 index 000000000..b88b43ac3 --- /dev/null +++ b/make-man-rules.py @@ -0,0 +1,92 @@ +# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ +# +# This file is part of systemd. +# +# Copyright 2013 Zbigniew Jędrzejewski-Szmek +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# systemd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with systemd; If not, see . + +from __future__ import print_function +import xml.etree.ElementTree as tree +import collections +import sys + +SECTION = '''\ +MANPAGES += \\ + {manpages} +MANPAGES_ALIAS += \\ + {aliases} +{rules} +''' + +CONDITIONAL = '''\ +if {conditional} +''' \ ++ SECTION + \ +'''\ +endif +''' + +HEADER = '''\ +# Do not edit. Generated by make-man-rules.py. +# Regenerate with 'make update-man-list'. + +''' + +def man(page, number): + return 'man/{}.{}'.format(page, number) + +def add_rules(rules, name): + xml = tree.parse(name) + # print('parsing {}'.format(name), file=sys.stderr) + conditional = xml.getroot().get('conditional') or '' + rulegroup = rules[conditional] + refmeta = xml.find('./refmeta') + title = refmeta.find('./refentrytitle').text + number = refmeta.find('./manvolnum').text + refnames = xml.findall('./refnamediv/refname') + target = man(refnames[0].text, number) + if title != refnames[0].text: + raise ValueError('refmeta and refnamediv disagree: ' + name) + for refname in refnames: + assert all(refname not in group + for group in rules.values()), "duplicate page name" + alias = man(refname.text, number) + rulegroup[alias] = target + # print('{} => {} [{}]'.format(alias, target, conditional), file=sys.stderr) + +def create_rules(*xml_files): + " {conditional => {alias-name => source-name}} " + rules = collections.defaultdict(dict) + for name in xml_files: + add_rules(rules, name) + return rules + +def mjoin(files): + return ' \\\n\t'.join(sorted(files) or '#') + +def make_makefile(rules): + 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), + conditional=conditional) + for conditional,rulegroup in sorted(rules.items())) + +if __name__ == '__main__': + rules = create_rules(*sys.argv[1:]) + print(make_makefile(rules), end='') diff --git a/man/binfmt.d.xml b/man/binfmt.d.xml index 07ae0ac23..8c5083caf 100644 --- a/man/binfmt.d.xml +++ b/man/binfmt.d.xml @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . --> - + binfmt.d diff --git a/man/bootchart.conf.xml b/man/bootchart.conf.xml index d2b09638c..419554e2d 100644 --- a/man/bootchart.conf.xml +++ b/man/bootchart.conf.xml @@ -25,7 +25,7 @@ along with systemd; If not, see . --> - + bootchart.conf systemd diff --git a/man/crypttab.xml b/man/crypttab.xml index f976bdaa2..a94163b4b 100644 --- a/man/crypttab.xml +++ b/man/crypttab.xml @@ -25,7 +25,7 @@ The Red Hat version has been written by Miloslav Trmac . --> - + crypttab diff --git a/man/hostnamectl.xml b/man/hostnamectl.xml index a29d2f5b7..07d363420 100644 --- a/man/hostnamectl.xml +++ b/man/hostnamectl.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + hostnamectl diff --git a/man/localectl.xml b/man/localectl.xml index 7563eb513..3e5b812da 100644 --- a/man/localectl.xml +++ b/man/localectl.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + localectl diff --git a/man/loginctl.xml b/man/loginctl.xml index 90b6f1e11..ba0352cf6 100644 --- a/man/loginctl.xml +++ b/man/loginctl.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + loginctl diff --git a/man/logind.conf.xml b/man/logind.conf.xml index b602e2a5f..d223514e0 100644 --- a/man/logind.conf.xml +++ b/man/logind.conf.xml @@ -22,7 +22,7 @@ along with systemd; If not, see . --> - + logind.conf systemd diff --git a/man/modules-load.d.xml b/man/modules-load.d.xml index bcc4d1256..ea4f52404 100644 --- a/man/modules-load.d.xml +++ b/man/modules-load.d.xml @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . --> - + modules-load.d diff --git a/man/nss-myhostname.xml b/man/nss-myhostname.xml index bd3f63569..46b7471b0 100644 --- a/man/nss-myhostname.xml +++ b/man/nss-myhostname.xml @@ -22,7 +22,7 @@ along with systemd; If not, see . --> - + nss-myhostname diff --git a/man/sd-login.xml b/man/sd-login.xml index c02ad0c14..697259564 100644 --- a/man/sd-login.xml +++ b/man/sd-login.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + sd-login diff --git a/man/sd-readahead.xml b/man/sd-readahead.xml index cebaa5da2..ee7c93681 100644 --- a/man/sd-readahead.xml +++ b/man/sd-readahead.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + sd-readahead diff --git a/man/sd_get_seats.xml b/man/sd_get_seats.xml index 17adcef74..a300a0575 100644 --- a/man/sd_get_seats.xml +++ b/man/sd_get_seats.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + sd_get_seats diff --git a/man/sd_login_monitor_new.xml b/man/sd_login_monitor_new.xml index 35cb6b368..2c4d05dcb 100644 --- a/man/sd_login_monitor_new.xml +++ b/man/sd_login_monitor_new.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + sd_login_monitor_new diff --git a/man/sd_pid_get_session.xml b/man/sd_pid_get_session.xml index 9517795f7..511fcf3ed 100644 --- a/man/sd_pid_get_session.xml +++ b/man/sd_pid_get_session.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + sd_pid_get_session diff --git a/man/sd_readahead.xml b/man/sd_readahead.xml index a1fc6f178..39e34698d 100644 --- a/man/sd_readahead.xml +++ b/man/sd_readahead.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + sd_readahead diff --git a/man/sd_seat_get_active.xml b/man/sd_seat_get_active.xml index b1d6d20ed..07e018de1 100644 --- a/man/sd_seat_get_active.xml +++ b/man/sd_seat_get_active.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + sd_seat_get_active diff --git a/man/sd_session_is_active.xml b/man/sd_session_is_active.xml index 1fa7457f7..76f6f9544 100644 --- a/man/sd_session_is_active.xml +++ b/man/sd_session_is_active.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + sd_session_is_active diff --git a/man/sd_uid_get_state.xml b/man/sd_uid_get_state.xml index b7bc944b1..cc8fc0f5b 100644 --- a/man/sd_uid_get_state.xml +++ b/man/sd_uid_get_state.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + sd_uid_get_state diff --git a/man/systemd-binfmt.service.xml b/man/systemd-binfmt.service.xml index 1db735a82..748e41780 100644 --- a/man/systemd-binfmt.service.xml +++ b/man/systemd-binfmt.service.xml @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . --> - + systemd-binfmt.service diff --git a/man/systemd-bootchart.xml b/man/systemd-bootchart.xml index 0df7c4bcf..f31d4a0a6 100644 --- a/man/systemd-bootchart.xml +++ b/man/systemd-bootchart.xml @@ -25,7 +25,7 @@ along with systemd; If not, see . --> - + systemd-bootchart systemd diff --git a/man/systemd-cryptsetup-generator.xml b/man/systemd-cryptsetup-generator.xml index c5f8d2a9d..292e967be 100644 --- a/man/systemd-cryptsetup-generator.xml +++ b/man/systemd-cryptsetup-generator.xml @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . --> - + systemd-cryptsetup-generator diff --git a/man/systemd-cryptsetup@.service.xml b/man/systemd-cryptsetup@.service.xml index abbb9d78f..6fa2e0cdd 100644 --- a/man/systemd-cryptsetup@.service.xml +++ b/man/systemd-cryptsetup@.service.xml @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . --> - + systemd-cryptsetup@.service diff --git a/man/systemd-hostnamed.service.xml b/man/systemd-hostnamed.service.xml index d9c191101..fe64a62fb 100644 --- a/man/systemd-hostnamed.service.xml +++ b/man/systemd-hostnamed.service.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + systemd-hostnamed.service diff --git a/man/systemd-journal-gatewayd.service.xml b/man/systemd-journal-gatewayd.service.xml index 44cd6167f..0b6fd706a 100644 --- a/man/systemd-journal-gatewayd.service.xml +++ b/man/systemd-journal-gatewayd.service.xml @@ -21,7 +21,7 @@ You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . --> - + systemd-journal-gatewayd.service diff --git a/man/systemd-localed.service.xml b/man/systemd-localed.service.xml index 6cefc4265..1551e6a2b 100644 --- a/man/systemd-localed.service.xml +++ b/man/systemd-localed.service.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + systemd-localed.service diff --git a/man/systemd-logind.service.xml b/man/systemd-logind.service.xml index 00f34051a..523a63b4f 100644 --- a/man/systemd-logind.service.xml +++ b/man/systemd-logind.service.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + systemd-logind.service diff --git a/man/systemd-modules-load.service.xml b/man/systemd-modules-load.service.xml index ea10be223..1d33b8eec 100644 --- a/man/systemd-modules-load.service.xml +++ b/man/systemd-modules-load.service.xml @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . --> - + systemd-modules-load.service diff --git a/man/systemd-quotacheck.service.xml b/man/systemd-quotacheck.service.xml index 2ffee9158..ff04e582d 100644 --- a/man/systemd-quotacheck.service.xml +++ b/man/systemd-quotacheck.service.xml @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . --> - + systemd-quotacheck.service diff --git a/man/systemd-random-seed-load.service.xml b/man/systemd-random-seed-load.service.xml index 87f563e29..693c008a2 100644 --- a/man/systemd-random-seed-load.service.xml +++ b/man/systemd-random-seed-load.service.xml @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . --> - + systemd-random-seed-load.service diff --git a/man/systemd-readahead-replay.service.xml b/man/systemd-readahead-replay.service.xml index 66d253454..3d7d9f542 100644 --- a/man/systemd-readahead-replay.service.xml +++ b/man/systemd-readahead-replay.service.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + systemd-readahead-replay.service diff --git a/man/systemd-timedated.service.xml b/man/systemd-timedated.service.xml index ea2abc576..c82c0ff43 100644 --- a/man/systemd-timedated.service.xml +++ b/man/systemd-timedated.service.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + systemd-timedated.service diff --git a/man/systemd-user-sessions.service.xml b/man/systemd-user-sessions.service.xml index 9214ec9c3..fc93e2dc2 100644 --- a/man/systemd-user-sessions.service.xml +++ b/man/systemd-user-sessions.service.xml @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . --> - + systemd-user-sessions.service diff --git a/man/systemd-vconsole-setup.service.xml b/man/systemd-vconsole-setup.service.xml index df1b1a16b..3c50799cb 100644 --- a/man/systemd-vconsole-setup.service.xml +++ b/man/systemd-vconsole-setup.service.xml @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . --> - + systemd-vconsole-setup.service diff --git a/man/timedatectl.xml b/man/timedatectl.xml index 4f34bb7b7..a8e78ae8d 100644 --- a/man/timedatectl.xml +++ b/man/timedatectl.xml @@ -21,7 +21,7 @@ along with systemd; If not, see . --> - + timedatectl diff --git a/man/vconsole.conf.xml b/man/vconsole.conf.xml index 45156b744..f60b571b7 100644 --- a/man/vconsole.conf.xml +++ b/man/vconsole.conf.xml @@ -22,7 +22,7 @@ along with systemd; If not, see . --> - + vconsole.conf systemd -- 2.30.2