1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2013-02-02 22:47:47 -05:00
parent 823eb4e64e
commit 56ba3c78ae
40 changed files with 148 additions and 37 deletions

View 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

View 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) $^ > $@

View File

@ -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>

View File

@ -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>

92
make-man-rules.py Normal file
View File

@ -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='')

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>