From 3f20fb3f9f8ccb2e6476e116e196b7e70ac559bb Mon Sep 17 00:00:00 2001
From: John MacFarlane <fiddlosopher@gmail.com>
Date: Sat, 28 Mar 2015 15:37:02 -0700
Subject: [PATCH] Always build man pages.  Removed make-pandoc-man-pages flag.

Updated INSTALL instructions.

Makefile:  removed man target, now that we generate man pages by default.
---
 INSTALL      |  7 +------
 Makefile     |  8 --------
 Setup.hs     | 11 ++++++++++-
 pandoc.cabal |  9 +--------
 4 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/INSTALL b/INSTALL
index a8ba3ddef..d5821339a 100644
--- a/INSTALL
+++ b/INSTALL
@@ -66,11 +66,7 @@ Quick install
          --extra-include-dirs=/usr/local/Cellar/icu4c/51.1/include \
          -funicode_collation text-icu pandoc-citeproc
 
-The cabal installation procedure does not generate man pages.
-To build the `pandoc` man pages, build pandoc with the
-`make-pandoc-man-pages` flag, and then use the command
-`make-pandoc-man-pages` from the pandoc source directory.
-This will create the man pages in `man/man1` and `man/man5`.
+The build process will create man pages in `man/man1` and `man/man5`.
 
 To build the `pandoc-citeproc` man pages, go to the pandoc-citeproc
 build directory, and
@@ -209,4 +205,3 @@ To use a smaller sample size so the benchmarks run faster:
 To run just the markdown benchmarks:
 
     cabal bench --benchmark-options='markdown'
-
diff --git a/Makefile b/Makefile
index b30ec7eea..ce7d0a6ad 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,5 @@
 version=$(shell grep '^Version:' pandoc.cabal | awk '{print $$2;}')
-makemanpages=$(shell find dist -type f -name make-pandoc-man-pages)
-ifeq "${makemanpages}" ""
-	makemanpages=@echo "You need to 'cabal configure -fmake-pandoc-man-pages && cabal build'" && exit 1
-endif
 setup=dist/setup/setup
-MANPAGES=man/man1/pandoc.1 man/man5/pandoc_markdown.5
 PREFIX ?= /usr/local
 
 quick:
@@ -43,8 +38,6 @@ dist: man
 debpkg:
 	./make_deb.sh
 
-man: $(MANPAGES)
-
 osxpkg:
 	./make_osx_package.sh
 
@@ -56,7 +49,6 @@ osxpkg:
 
 clean:
 	cabal clean
-	-rm $(MANPAGES)
 	-rm -rf $(BINDIST) $(BINDIST).tar.gz
 
 .PHONY: deps quick full install man clean test bench haddock osxpkg dist bindist prof
diff --git a/Setup.hs b/Setup.hs
index 868fe901e..c45ee69d3 100644
--- a/Setup.hs
+++ b/Setup.hs
@@ -38,7 +38,9 @@ main = defaultMainWithHooks $ simpleUserHooks {
     , instHook = \pkgdescr ->
          instHook simpleUserHooks pkgdescr{ executables =
             [x | x <- executables pkgdescr, exeName x `notElem` noInstall] }
-    , postBuild = makeReferenceFiles
+    , postBuild = \args bf pkgdescr lbi -> do
+            makeManPages args bf pkgdescr lbi
+            makeReferenceFiles args bf pkgdescr lbi
     }
   where
     noInstall = ["make-pandoc-man-pages","make-reference-files"]
@@ -56,6 +58,13 @@ ppBlobSuffixHandler = ("hsb", \_ _ ->
          return ()
   })
 
+makeManPages :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
+makeManPages _ bf _ LocalBuildInfo{buildDir=buildDir}
+  = rawSystemExit verbosity progPath []
+  where
+    verbosity = fromFlagOrDefault normal $ buildVerbosity bf
+    progPath = buildDir </> "make-pandoc-man-pages" </> "make-pandoc-man-pages"
+
 makeReferenceFiles :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
 makeReferenceFiles _ bf _ LocalBuildInfo{buildDir=buildDir}
   = mapM_
diff --git a/pandoc.cabal b/pandoc.cabal
index 52b8d82a8..c9f583c68 100644
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -231,10 +231,6 @@ Flag https
   Description:   Enable support for downloading of resources over https.
   Default:       True
 
-Flag make-pandoc-man-pages
-  Description:   Build program to regenerate pandoc man pages from README.
-  Default:       False
-
 Flag network-uri
   Description:   Get Network.URI from the network-uri package
   Default:       True
@@ -442,10 +438,7 @@ Executable make-pandoc-man-pages
                  old-time >= 1.0 && < 1.2,
                  time >= 1.2 && < 1.6
   Default-Language: Haskell98
-  if flag(make-pandoc-man-pages)
-    Buildable:   True
-  else
-    Buildable:   False
+  Buildable:   True
 
 Executable make-reference-files
   Main-Is:       make-reference-files.hs