summaryrefslogtreecommitdiff
path: root/Setup.hs
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-08-09 23:45:40 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-08-09 23:45:40 +0000
commit28828979a6df073182bf039333cb46f8ad922b19 (patch)
tree02205c01432cb6bc737ee9c3268ecdba693fc2cf /Setup.hs
parente36ff78b5e6f4cfd0af50f6a599648c580d1a0b8 (diff)
Moved more of the build process from Makefile to Setup.hs:
+ tarball target now calls 'sdist' + Added to "Extra-source-files" and "Extra-tmp-files" in pandoc.cabal, so 'sdist' and 'clean' will work properly. + Makefile no longer generates man pages or reference.odt. + Setup.hs now generates man pages in a postbuild hook. + Added dependency-checking to Setup.hs, so it only rebuilds things that need rebuilding. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1389 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'Setup.hs')
-rw-r--r--Setup.hs76
1 files changed, 58 insertions, 18 deletions
diff --git a/Setup.hs b/Setup.hs
index 9bcbaa78a..54d1bff85 100644
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,44 +1,84 @@
import Distribution.Simple
import Distribution.PackageDescription ( emptyHookedBuildInfo )
import Control.Exception ( bracket_ )
-import System.Process ( runCommand, waitForProcess )
-import System.FilePath ( (</>) )
-import System.Directory ( getCurrentDirectory, setCurrentDirectory, findExecutable, doesFileExist )
+import System.Process ( runCommand, runProcess, waitForProcess )
+import System.FilePath ( (</>), (<.>) )
+import System.Directory
import System.IO ( stderr )
import System.Exit
-import Data.Maybe ( fromJust )
+import System.Time
+import System.IO.Error ( isDoesNotExistError )
+import Data.Maybe ( fromJust, isNothing, catMaybes )
-main = defaultMainWithHooks (simpleUserHooks {runTests = runTestSuite, preConf = checkReferenceODT})
+main = defaultMainWithHooks $
+ simpleUserHooks { runTests = runTestSuite
+ , preConf = checkReferenceODT
+ , postBuild = makeManPages }
-- | Run test suite.
runTestSuite _ _ _ _ = do
inDirectory "tests" $ runCommand "runhaskell RunTests.hs" >>= waitForProcess
return ()
--- | If reference.odt does not exist, build it.
-checkReferenceODT _ _ = do
- refODTexists <- doesFileExist ("odt-styles" </> "reference.odt")
- if refODTexists
+-- | If reference.odt needs rebuilding, build it.
+checkReferenceODT _ _ = inDirectory "odt-styles" $ do
+ let refodt = "reference.odt"
+ let deps = [ "meta.xml", "content.xml", "settings.xml", "META-INF/manifest.xml",
+ "Thumbnails/thumbnail.png", "styles.xml", "mimetype" ]
+ modifiedDeps <- modifiedDependencies refodt deps
+ if null modifiedDeps
then return ()
- else makeReferenceODT
+ else makeReferenceODT modifiedDeps
return emptyHookedBuildInfo
-- | Create reference.odt by zipping up sources in odt-styles directory.
-makeReferenceODT :: IO ()
-makeReferenceODT = do
+makeReferenceODT :: [FilePath] -> IO ()
+makeReferenceODT sources = do
zipPathMaybe <- findExecutable "zip"
- if zipPathMaybe == Nothing
+ if isNothing zipPathMaybe
then error $ "The 'zip' command, which is needed to build reference.odt\n" ++
"from sources in the odt-styles directory, was not found.\n" ++
"Try again after installing zip (http://www.info-zip.org/Zip.html).\n" ++
"Or use the pandoc source tarball, which contains a prebuilt reference.odt."
else do
putStrLn "Creating reference.odt:"
- inDirectory "odt-styles" $ do
- ec <- runCommand "zip -9 -r reference.odt *" >>= waitForProcess
- case ec of
- ExitSuccess -> putStrLn "Done."
- _ -> error "Error creating ODT."
+ ec <- runProcess (fromJust zipPathMaybe) (["-9", "-r", "reference.odt"] ++ sources)
+ Nothing Nothing Nothing Nothing (Just stderr) >>= waitForProcess
+ case ec of
+ ExitSuccess -> return ()
+ _ -> error "Error creating ODT."
+
+-- | Build man pages from markdown sources in man/man1/.
+makeManPages _ _ _ _ = do
+ mapM makeManPage ["pandoc.1", "hsmarkdown.1", "markdown2pdf.1", "html2markdown.1"]
+ return ()
+
+-- | Build a man page from markdown source in man/man1.
+makeManPage manpage = do
+ let manDir = "man" </> "man1"
+ let pandoc = "dist" </> "build" </> "pandoc" </> "pandoc"
+ let page = manDir </> manpage
+ let source = manDir </> manpage <.> "md"
+ modifiedDeps <- modifiedDependencies page [source]
+ if null modifiedDeps
+ then return ()
+ else do
+ ec <- runProcess pandoc ["-s", "-r", "markdown", "-w", "man", "-o", page, source]
+ Nothing Nothing Nothing Nothing (Just stderr) >>= waitForProcess
+ case ec of
+ ExitSuccess -> putStrLn $ "Created " ++ manDir </> manpage
+ _ -> error $ "Error creating " ++ manDir </> manpage
+
+-- | Returns a list of 'dependencies' that have been modified after 'file'.
+modifiedDependencies :: FilePath -> [FilePath] -> IO [FilePath]
+modifiedDependencies file dependencies = do
+ fileModTime <- catch (getModificationTime file) $
+ \e -> if isDoesNotExistError e
+ then return (TOD 0 0) -- the minimum ClockTime
+ else ioError e
+ depModTimes <- mapM getModificationTime dependencies
+ let modified = zipWith (\dep time -> if time > fileModTime then Just dep else Nothing) dependencies depModTimes
+ return $ catMaybes modified
-- | Perform an IO action in a directory.
inDirectory :: FilePath -> IO a -> IO a