chiark / gitweb /
build-sys: create Makefile-man.am automatically
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 3 Feb 2013 03:47:47 +0000 (22:47 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 Feb 2013 04:16:16 +0000 (23:16 -0500)
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.

40 files changed:
Makefile-man.am
Makefile.am
make-directive-index.py
make-man-index.py
make-man-rules.py [new file with mode: 0644]
man/binfmt.d.xml
man/bootchart.conf.xml
man/crypttab.xml
man/hostnamectl.xml
man/localectl.xml
man/loginctl.xml
man/logind.conf.xml
man/modules-load.d.xml
man/nss-myhostname.xml
man/sd-login.xml
man/sd-readahead.xml
man/sd_get_seats.xml
man/sd_login_monitor_new.xml
man/sd_pid_get_session.xml
man/sd_readahead.xml
man/sd_seat_get_active.xml
man/sd_session_is_active.xml
man/sd_uid_get_state.xml
man/systemd-binfmt.service.xml
man/systemd-bootchart.xml
man/systemd-cryptsetup-generator.xml
man/systemd-cryptsetup@.service.xml
man/systemd-hostnamed.service.xml
man/systemd-journal-gatewayd.service.xml
man/systemd-localed.service.xml
man/systemd-logind.service.xml
man/systemd-modules-load.service.xml
man/systemd-quotacheck.service.xml
man/systemd-random-seed-load.service.xml
man/systemd-readahead-replay.service.xml
man/systemd-timedated.service.xml
man/systemd-user-sessions.service.xml
man/systemd-vconsole-setup.service.xml
man/timedatectl.xml
man/vconsole.conf.xml

index 76b794a..d54d67c 100644 (file)
@@ -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
index ba55a7e..f73e8a6 100644 (file)
@@ -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) $^ > $@
index ab40997..b06a54c 100755 (executable)
@@ -23,7 +23,7 @@ import xml.etree.ElementTree as tree
 import re
 
 TEMPLATE = '''\
-<refentry id="systemd.directives">
+<refentry id="systemd.directives" conditional="HAVE_PYTHON">
 
         <refentryinfo>
                 <title>systemd.directives</title>
index 2dbc2da..f829d98 100755 (executable)
@@ -24,7 +24,7 @@ import sys
 MDASH = ' — ' if sys.version_info.major >= 3 else ' -- '
 
 TEMPLATE = '''\
-<refentry id="systemd.index">
+<refentry id="systemd.index" conditional="HAVE_PYTHON">
 
   <refentryinfo>
     <title>systemd.index</title>
diff --git a/make-man-rules.py b/make-man-rules.py
new file mode 100644 (file)
index 0000000..b88b43a
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+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='')
index 07ae0ac..8c5083c 100644 (file)
@@ -19,7 +19,7 @@
   You should have received a copy of the GNU Lesser General Public License
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
-<refentry id="binfmt.d">
+<refentry id="binfmt.d" conditional='ENABLE_BINFMT'>
 
         <refentryinfo>
                 <title>binfmt.d</title>
index d2b0963..419554e 100644 (file)
@@ -25,7 +25,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="bootchart.conf">
+<refentry id="bootchart.conf" conditional='ENABLE_BOOTCHART'>
         <refentryinfo>
                 <title>bootchart.conf</title>
                 <productname>systemd</productname>
index f976bda..a94163b 100644 (file)
@@ -25,7 +25,7 @@
   The Red Hat version has been written by Miloslav Trmac <mitr@redhat.com>.
 
 -->
-<refentry id="crypttab">
+<refentry id="crypttab" conditional='HAVE_LIBCRYPTSETUP'>
 
         <refentryinfo>
                 <title>crypttab</title>
index a29d2f5..07d3634 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="hostnamectl">
+<refentry id="hostnamectl" conditional='ENABLE_HOSTNAMED'>
 
         <refentryinfo>
                 <title>hostnamectl</title>
index 7563eb5..3e5b812 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="localectl">
+<refentry id="localectl" conditional='ENABLE_LOCALED'>
 
         <refentryinfo>
                 <title>localectl</title>
index 90b6f1e..ba0352c 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="loginctl">
+<refentry id="loginctl" conditional='HAVE_PAM'>
 
         <refentryinfo>
                 <title>loginctl</title>
index b602e2a..d223514 100644 (file)
@@ -22,7 +22,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="logind.conf">
+<refentry id="logind.conf" conditional='HAVE_PAM'>
         <refentryinfo>
                 <title>logind.conf</title>
                 <productname>systemd</productname>
index bcc4d12..ea4f524 100644 (file)
@@ -19,7 +19,7 @@
   You should have received a copy of the GNU Lesser General Public License
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
-<refentry id="modules-load.d">
+<refentry id="modules-load.d" conditional='HAVE_KMOD'>
 
         <refentryinfo>
                 <title>modules-load.d</title>
index bd3f635..46b7471 100644 (file)
@@ -22,7 +22,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="nss-myhostname">
+<refentry id="nss-myhostname" conditional='HAVE_MYHOSTNAME'>
 
         <refentryinfo>
                 <title>nss-myhostname</title>
index c02ad0c..6972595 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="sd-login">
+<refentry id="sd-login" conditional='HAVE_PAM'>
 
         <refentryinfo>
                 <title>sd-login</title>
index cebaa5d..ee7c936 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="sd-daemon">
+<refentry id="sd-daemon" conditional='ENABLE_READAHEAD'>
 
         <refentryinfo>
                 <title>sd-readahead</title>
index 17adcef..a300a05 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="sd_get_seats">
+<refentry id="sd_get_seats" conditional='HAVE_PAM'>
 
         <refentryinfo>
                 <title>sd_get_seats</title>
index 35cb6b3..2c4d05d 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="sd_login_monitor_new">
+<refentry id="sd_login_monitor_new" conditional='HAVE_PAM'>
 
         <refentryinfo>
                 <title>sd_login_monitor_new</title>
index 9517795..511fcf3 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="sd_pid_get_session">
+<refentry id="sd_pid_get_session" conditional='HAVE_PAM'>
 
         <refentryinfo>
                 <title>sd_pid_get_session</title>
index a1fc6f1..39e3469 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="sd_notify">
+<refentry id="sd_notify" conditional='ENABLE_READAHEAD'>
 
         <refentryinfo>
                 <title>sd_readahead</title>
index b1d6d20..07e018d 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="sd_seat_get_active">
+<refentry id="sd_seat_get_active" conditional='HAVE_PAM'>
 
         <refentryinfo>
                 <title>sd_seat_get_active</title>
index 1fa7457..76f6f95 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="sd_session_is_active">
+<refentry id="sd_session_is_active" conditional='HAVE_PAM'>
 
         <refentryinfo>
                 <title>sd_session_is_active</title>
index b7bc944..cc8fc0f 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="sd_uid_get_state">
+<refentry id="sd_uid_get_state" conditional='HAVE_PAM'>
 
         <refentryinfo>
                 <title>sd_uid_get_state</title>
index 1db735a..748e417 100644 (file)
@@ -19,7 +19,7 @@
   You should have received a copy of the GNU Lesser General Public License
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
-<refentry id="systemd-binfmt.service">
+<refentry id="systemd-binfmt.service" conditional='ENABLE_BINFMT'>
 
         <refentryinfo>
                 <title>systemd-binfmt.service</title>
index 0df7c4b..f31d4a0 100644 (file)
@@ -25,7 +25,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="systemd-bootchart">
+<refentry id="systemd-bootchart" conditional='ENABLE_BOOTCHART'>
         <refentryinfo>
                 <title>systemd-bootchart</title>
                 <productname>systemd</productname>
index c5f8d2a..292e967 100644 (file)
@@ -19,7 +19,7 @@
   You should have received a copy of the GNU Lesser General Public License
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
-<refentry id="systemd-cryptsetup-generator">
+<refentry id="systemd-cryptsetup-generator" conditional='HAVE_LIBCRYPTSETUP'>
 
         <refentryinfo>
                 <title>systemd-cryptsetup-generator</title>
index abbb9d7..6fa2e0c 100644 (file)
@@ -19,7 +19,7 @@
   You should have received a copy of the GNU Lesser General Public License
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
-<refentry id="systemd-cryptsetup@.service">
+<refentry id="systemd-cryptsetup@.service" conditional='HAVE_LIBCRYPTSETUP'>
 
         <refentryinfo>
                 <title>systemd-cryptsetup@.service</title>
index d9c1911..fe64a62 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="systemd-hostnamed.service">
+<refentry id="systemd-hostnamed.service" conditional='ENABLE_HOSTNAMED'>
 
         <refentryinfo>
                 <title>systemd-hostnamed.service</title>
index 44cd616..0b6fd70 100644 (file)
@@ -21,7 +21,7 @@ You should have received a copy of the GNU Lesser General Public License
 along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="systemd-journal-gatewayd.service">
+<refentry id="systemd-journal-gatewayd.service" conditional='HAVE_MICROHTTPD'>
 
   <refentryinfo>
     <title>systemd-journal-gatewayd.service</title>
index 6cefc42..1551e6a 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="systemd-localed.service">
+<refentry id="systemd-localed.service" conditional='ENABLE_LOCALED'>
 
         <refentryinfo>
                 <title>systemd-localed.service</title>
index 00f3405..523a63b 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="systemd-logind.service">
+<refentry id="systemd-logind.service" conditional='HAVE_PAM'>
 
         <refentryinfo>
                 <title>systemd-logind.service</title>
index ea10be2..1d33b8e 100644 (file)
@@ -19,7 +19,7 @@
   You should have received a copy of the GNU Lesser General Public License
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
-<refentry id="systemd-modules-load.service">
+<refentry id="systemd-modules-load.service" conditional='HAVE_KMOD'>
 
         <refentryinfo>
                 <title>systemd-modules-load.service</title>
index 2ffee91..ff04e58 100644 (file)
@@ -19,7 +19,7 @@
   You should have received a copy of the GNU Lesser General Public License
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
-<refentry id="systemd-quotacheck.service">
+<refentry id="systemd-quotacheck.service" conditional='ENABLE_QUOTACHECK'>
 
         <refentryinfo>
                 <title>systemd-quotacheck.service</title>
index 87f563e..693c008 100644 (file)
@@ -19,7 +19,7 @@
   You should have received a copy of the GNU Lesser General Public License
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
-<refentry id="systemd-random-seed-load.service">
+<refentry id="systemd-random-seed-load.service" conditional='ENABLE_RANDOMSEED'>
 
         <refentryinfo>
                 <title>systemd-random-seed-load.service</title>
index 66d2534..3d7d9f5 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="systemd-readahead-replay.service">
+<refentry id="systemd-readahead-replay.service" conditional='ENABLE_READAHEAD'>
 
         <refentryinfo>
                 <title>systemd-readahead-replay.service</title>
index ea2abc5..c82c0ff 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="systemd-timedated.service">
+<refentry id="systemd-timedated.service" conditional='ENABLE_TIMEDATED'>
 
         <refentryinfo>
                 <title>systemd-timedated.service</title>
index 9214ec9..fc93e2d 100644 (file)
@@ -19,7 +19,7 @@
   You should have received a copy of the GNU Lesser General Public License
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
-<refentry id="systemd-user-sessions.service">
+<refentry id="systemd-user-sessions.service" conditional='HAVE_PAM'>
 
         <refentryinfo>
                 <title>systemd-user-sessions.service</title>
index df1b1a1..3c50799 100644 (file)
@@ -19,7 +19,7 @@
   You should have received a copy of the GNU Lesser General Public License
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
-<refentry id="systemd-vconsole-setup.service">
+<refentry id="systemd-vconsole-setup.service" conditional='ENABLE_VCONSOLE'>
 
         <refentryinfo>
                 <title>systemd-vconsole-setup.service</title>
index 4f34bb7..a8e78ae 100644 (file)
@@ -21,7 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="timedatectl">
+<refentry id="timedatectl" conditional='ENABLE_TIMEDATED'>
 
         <refentryinfo>
                 <title>timedatectl</title>
index 45156b7..f60b571 100644 (file)
@@ -22,7 +22,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 -->
 
-<refentry id="vconsole.conf">
+<refentry id="vconsole.conf" conditional='ENABLE_VCONSOLE'>
         <refentryinfo>
                 <title>vconsole.conf</title>
                 <productname>systemd</productname>