From f879b99ad14588ef0585d580158040ae11a1a3e8 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Mon, 31 Jan 2011 09:34:15 -0800
Subject: [PATCH] Setup.hs: Don't call MakeManPage.hs unless the man pages need
 making.

---
 Setup.hs | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/Setup.hs b/Setup.hs
index 231b62bbd..e942b0da2 100644
--- a/Setup.hs
+++ b/Setup.hs
@@ -9,6 +9,7 @@ import Distribution.Verbosity ( Verbosity, silent )
 import Distribution.Simple.InstallDirs (mandir, bindir, CopyDest (NoCopyDest))
 import Distribution.Simple.Utils (copyFiles)
 import Control.Exception ( bracket_ )
+import Control.Monad ( unless )
 import System.Process ( rawSystem, runCommand, waitForProcess )
 import System.FilePath ( (</>) )
 import System.Directory
@@ -50,11 +51,19 @@ runTestSuite args _ pkg lbi = do
 makeManPages :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
 makeManPages _ flags _ _ = do
   let verbosity = fromFlag $ buildVerbosity flags
+  ds1 <- modifiedDependencies (manDir </> "man1" </> "pandoc.1")
+    ["README", manDir </> "man1" </> "pandoc.1.template"]
+  ds2 <- modifiedDependencies (manDir </> "man1" </> "markdown2pdf.1")
+    [manDir </> "man1" </> "markdown2pdf.1.md"]
+  ds3 <- modifiedDependencies (manDir </> "man5" </> "pandoc_markdown.5")
+    ["README", manDir </> "man5" </> "pandoc_markdown.5.template"]
   let cmd  = "runghc -package-conf=dist/package.conf.inplace MakeManPage.hs"
   let cmd' = if verbosity == silent
                 then cmd
                 else cmd ++ " --verbose"
-  runCommand cmd' >>= waitForProcess >>= exitWith
+  -- Don't run MakeManPage.hs unless we have to
+  unless (null ds1 && null ds2 && null ds3) $
+    runCommand cmd' >>= waitForProcess >>= exitWith
 
 manpages :: [FilePath]
 manpages = ["man1" </> "pandoc.1"