@@ -1,6 +1,7 @@
11import Distribution.Simple
22import Distribution.PackageDescription ( emptyHookedBuildInfo )
33import Control.Exception ( bracket_ )
4+import Control.Monad ( unless )
45import System.Process ( runCommand, runProcess, waitForProcess )
56import System.FilePath ( (</>), (<.>) )
67import System.Directory
@@ -10,9 +11,10 @@ import System.Time
1011import System.IO.Error ( isDoesNotExistError )
1112import Data.Maybe ( fromJust, isNothing, catMaybes )
1213
13−main = defaultMainWithHooks $
14− simpleUserHooks { runTests = runTestSuite
15− , postBuild = makeManPages }
14+main = do
15+ defaultMainWithHooks $ simpleUserHooks { runTests = runTestSuite
16+ , postBuild = makeManPages }
17+ exitWith ExitSuccess
1618
1719-- | Run test suite.
1820runTestSuite _ _ _ _ = do
@@ -20,8 +22,7 @@ runTestSuite _ _ _ _ = do
2022
2123-- | Build man pages from markdown sources in man/man1/.
2224makeManPages _ _ _ _ = do
23− mapM makeManPage ["pandoc.1", "hsmarkdown.1", "html2markdown.1", "markdown2pdf.1"]
24− return ()
25+ mapM_ makeManPage ["pandoc.1", "hsmarkdown.1", "html2markdown.1", "markdown2pdf.1"]
2526
2627-- | Build a man page from markdown source in man/man1.
2728makeManPage manpage = do
@@ -30,14 +31,13 @@ makeManPage manpage = do
3031 let page = manDir </> manpage
3132 let source = manDir </> manpage <.> "md"
3233 modifiedDeps <- modifiedDependencies page [source]
33− if null modifiedDeps
34− then return ()
35− else do
36− ec <- runProcess pandoc ["-s", "-S", "-r", "markdown", "-w", "man", "-o", page, source]
37− Nothing Nothing Nothing Nothing (Just stderr) >>= waitForProcess
38− case ec of
39− ExitSuccess -> putStrLn $ "Created " ++ manDir </> manpage
40− _ -> error $ "Error creating " ++ manDir </> manpage
34+ unless (null modifiedDeps) $ do
35+ ec <- runProcess pandoc ["-s", "-S", "-r", "markdown", "-w", "man", "-o", page, source]
36+ Nothing Nothing Nothing Nothing (Just stderr) >>= waitForProcess
37+ case ec of
38+ ExitSuccess -> putStrLn $ "Created " ++ manDir </> manpage
39+ _ -> do putStrLn $ "Error creating " ++ manDir </> manpage
40+ exitWith ec
4141
4242-- | Returns a list of 'dependencies' that have been modified after 'file'.
4343modifiedDependencies :: FilePath -> [FilePath] -> IO [FilePath]