[RFC PATCH v4 2/3] doc: add target rst2man to build man pages using rst2man

David Bremner david at tethera.net
Tue Feb 25 03:53:00 PST 2014


Many people have docutils installed, but not sphinx. Allow these
people to build the man pages.
---
 Makefile                   |  2 +-
 doc/conf.py                |  2 +-
 doc/rst2man/Makefile       |  5 +++++
 doc/rst2man/Makefile.local | 37 ++++++++++++++++++++++++++++++++
 doc/rst2man/prerst2man.py  | 53 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 97 insertions(+), 2 deletions(-)
 create mode 100644 doc/rst2man/Makefile
 create mode 100644 doc/rst2man/Makefile.local
 create mode 100644 doc/rst2man/prerst2man.py

diff --git a/Makefile b/Makefile
index 39f0e62..3c7f0be 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ all:
 # List all subdirectories here. Each contains its own Makefile.local.
 # Use of '=', without '+=', seems to be required for out-of-tree
 # builds to work.
-subdirs = compat completion doc emacs lib man parse-time-string performance-test util test
+subdirs = compat completion doc doc/rst2man emacs lib man parse-time-string performance-test util test
 
 # We make all targets depend on the Makefiles themselves.
 global_deps = Makefile Makefile.config Makefile.local \
diff --git a/doc/conf.py b/doc/conf.py
index d80b2af..9180d86 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -21,7 +21,7 @@ release = '0.17'
 
 # List of patterns, relative to source directory, that match files and
 # directories to ignore when looking for source files.
-exclude_patterns = ['_build']
+exclude_patterns = ['_build','rst2man']
 
 # The name of the Pygments (syntax highlighting) style to use.
 pygments_style = 'sphinx'
diff --git a/doc/rst2man/Makefile b/doc/rst2man/Makefile
new file mode 100644
index 0000000..0a0815d
--- /dev/null
+++ b/doc/rst2man/Makefile
@@ -0,0 +1,5 @@
+all:
+	$(MAKE) -C ../.. all
+
+.DEFAULT:
+	$(MAKE) -C ../.. $@
diff --git a/doc/rst2man/Makefile.local b/doc/rst2man/Makefile.local
new file mode 100644
index 0000000..bc821fe
--- /dev/null
+++ b/doc/rst2man/Makefile.local
@@ -0,0 +1,37 @@
+# -*- Makefile -*-
+dir := doc/rst2man
+
+prerst2man := python $(dir)/prerst2man.py $(dir)/.. $(dir)
+
+%.1 :%.rst
+	rst2man $< > $@
+
+%.5 :%.rst
+	rst2man $< > $@
+
+%.7: %.rst
+	rst2man $< > $@
+
+# actual source files
+RST1SRC := $(wildcard doc/man1/*.rst)
+RST5SRC	:= $(wildcard doc/man5/*.rst)
+RST7SRC := $(wildcard doc/man7/*.rst)
+
+RST2MAN1SRC := $(patsubst doc/man1/%,doc/rst2man/man1/%,$(RST1SRC))
+RST2MAN5SRC := $(patsubst doc/man5/%,doc/rst2man/man5/%,$(RST5SRC))
+RST2MAN7SRC := $(patsubst doc/man7/%,doc/rst2man/man7/%,$(RST7SRC))
+
+RST2MANSRC := ${RST2MAN1SRC} ${RST2MAN5SRC} ${RST2MAN7SRC}
+
+MAN1SRC := $(patsubst $(dir)/man1/%.rst,$(dir)/man1/%.1,${RST2MAN1SRC})
+MAN5SRC := $(patsubst $(dir)/man5/%.rst,$(dir)/man5/%.5,${RST2MAN5SRC})
+MAN7SRC := $(patsubst $(dir)/man7/%.rst,$(dir)/man7/%.7,${RST2MAN7SRC})
+MANSRC := ${MAN1SRC} ${MAN5SRC} ${MAN7SRC}
+
+rst2man: ${MANSRC}
+
+${RST2MANSRC}: ${RSTSRC}
+	mkdir -p doc/rst2man/man1 doc/rst2man/man5 doc/rst2man/man7
+	$(prerst2man)
+
+CLEAN := ${CLEAN} ${RST2MANSRC} ${MANSRC}
diff --git a/doc/rst2man/prerst2man.py b/doc/rst2man/prerst2man.py
new file mode 100644
index 0000000..797dd20
--- /dev/null
+++ b/doc/rst2man/prerst2man.py
@@ -0,0 +1,53 @@
+from sys import argv
+from datetime import date
+import re
+
+sourcedir=argv[1]
+outdir=argv[2]
+
+execfile(sourcedir+"/conf.py");
+
+
+
+
+def header(file,startdocname, command, description, authors, section):
+    file.write("""
+{:s}
+{:s}
+{:s}
+
+:Date:   {:s}
+:Version: {:s}
+:Manual section: {:d}
+:Manual group: {:s}
+
+""".format(
+'-' * len(description),
+description,
+'-' * len(description),
+date.today().isoformat(),release,section,project))
+
+blankre = re.compile("^\s*$")
+for page in man_pages:
+    outfile = open(outdir+"/"+page[0]+'.rst','w')
+    infile = open(sourcedir+"/"+page[0]+".rst",'r')
+
+
+    # this is a crude hack. We look for the first blank line, and
+    # insert the rst2man header there.
+    #
+    # XXX consider really parsing input
+
+    count=0
+    lines = infile.readlines()
+    for line in lines:
+        outfile.write(line);
+        if (blankre.match(line)):
+            break
+        count = count + 1
+
+    del lines[0:count+1]
+
+    header(outfile,*page)
+
+    outfile.write("".join(lines))
-- 
1.8.5.3



More information about the notmuch mailing list