--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 206B0431FAE\r
+ for <notmuch@notmuchmail.org>; Wed, 5 Mar 2014 06:57:22 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id asdFv7V0EVDO for <notmuch@notmuchmail.org>;\r
+ Wed, 5 Mar 2014 06:57:18 -0800 (PST)\r
+Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
+ (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 5BCE2431FBF\r
+ for <notmuch@notmuchmail.org>; Wed, 5 Mar 2014 06:56:54 -0800 (PST)\r
+Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1WLDFe-0004AX-0m; Wed, 05 Mar 2014 10:56:54 -0400\r
+Received: (nullmailer pid 10383 invoked by uid 1000); Wed, 05 Mar 2014\r
+ 14:56:36 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/4] doc: add target rst2man to build man pages using rst2man\r
+Date: Wed, 5 Mar 2014 10:56:33 -0400\r
+Message-Id: <1394031395-8014-3-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.8.5.3\r
+In-Reply-To: <1394031395-8014-1-git-send-email-david@tethera.net>\r
+References: <1394031395-8014-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 05 Mar 2014 14:57:22 -0000\r
+\r
+Many people have docutils installed, but not sphinx. Allow these\r
+people to build the man pages.\r
+---\r
+ doc/Makefile.local | 7 ++++++\r
+ doc/prerst2man.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 2 files changed, 69 insertions(+)\r
+ create mode 100644 doc/prerst2man.py\r
+\r
+diff --git a/doc/Makefile.local b/doc/Makefile.local\r
+index ec23012..4719247 100644\r
+--- a/doc/Makefile.local\r
++++ b/doc/Makefile.local\r
+@@ -7,10 +7,13 @@ SPHINXOPTS := -q -c $(dir)\r
+ SPHINXBUILD = sphinx-build\r
+ DOCBUILDDIR := $(dir)/_build\r
+ \r
++prerst2man := python $(dir)/prerst2man.py\r
++\r
+ # Internal variables.\r
+ ALLSPHINXOPTS := -d $(DOCBUILDDIR)/doctrees $(SPHINXOPTS) $(dir)\r
+ \r
+ .PHONY: sphinx-html sphinx-man sphinx-texinfo sphinx-info\r
++.PHONY: rst2man\r
+ \r
+ sphinx-html:\r
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(DOCBUILDDIR)/html\r
+@@ -24,4 +27,8 @@ sphinx-texinfo:\r
+ sphinx-info: sphinx-texinfo\r
+ make -C $(DOCBUILDDIR)/texinfo info\r
+ \r
++# fallback target in case sphinx not installed\r
++rst2man:\r
++ $(prerst2man) $(DOCBUILDDIR)/.. $(DOCBUILDDIR)/man\r
++\r
+ CLEAN := $(CLEAN) $(DOCBUILDDIR)\r
+diff --git a/doc/prerst2man.py b/doc/prerst2man.py\r
+new file mode 100644\r
+index 0000000..720deb6\r
+--- /dev/null\r
++++ b/doc/prerst2man.py\r
+@@ -0,0 +1,62 @@\r
++from sys import argv\r
++from datetime import date\r
++from os.path import dirname, isdir\r
++from os import makedirs, system\r
++import re\r
++\r
++sourcedir = argv[1]\r
++outdir = argv[2]\r
++\r
++if not isdir(outdir):\r
++ makedirs(outdir, 0755)\r
++\r
++execfile(sourcedir + "/conf.py")\r
++\r
++\r
++def header(file, startdocname, command, description, authors, section):\r
++ file.write("""\r
++{0:s}\r
++{1:s}\r
++{2:s}\r
++\r
++:Date: {3:s}\r
++:Version: {4:s}\r
++:Manual section: {5:d}\r
++:Manual group: {6:s}\r
++\r
++""".format(\r
++'-' * len(description),\r
++description,\r
++'-' * len(description),\r
++date.today().isoformat(), release, section, project))\r
++\r
++blankre = re.compile("^\s*$")\r
++for page in man_pages:\r
++ outdirname = outdir + '/' + dirname(page[0])\r
++ if not isdir(outdirname):\r
++ makedirs(outdirname, 0755)\r
++ filename = outdir + '/' + page[0] + '.rst'\r
++ outfile = open(filename, 'w')\r
++ infile = open(sourcedir + '/' + page[0] + '.rst', 'r')\r
++\r
++ # this is a crude hack. We look for the first blank line, and\r
++ # insert the rst2man header there.\r
++ #\r
++ # XXX consider really parsing input\r
++\r
++ count = 0\r
++ lines = infile.readlines()\r
++ for line in lines:\r
++ outfile.write(line)\r
++ if (blankre.match(line)):\r
++ break\r
++ count = count + 1\r
++\r
++ del lines[0:count + 1]\r
++\r
++ header(outfile, *page)\r
++\r
++ outfile.write("".join(lines))\r
++ outfile.close()\r
++\r
++ os.system('set -x; rst2man {0} {1}'.format(filename, outdir + '/' + page[0] + '.' + str(page[4])))\r
+-- \r
+1.8.5.3\r
+\r