1import Distribution.Simple
2import Distribution.Simple.Setup
3 (copyDest, copyVerbosity, fromFlag, installVerbosity, BuildFlags(..))
4import Distribution.PackageDescription
5 (PackageDescription(..), Executable(..), BuildInfo(..))
6import Distribution.Simple.LocalBuildInfo
7 (LocalBuildInfo(..), absoluteInstallDirs)
8import Distribution.Verbosity ( Verbosity, silent )
9import Distribution.Simple.GHC (ghcPackageDbOptions)
10import Distribution.Simple.InstallDirs (mandir, bindir, CopyDest (NoCopyDest))
11import Distribution.Simple.Utils (installOrdinaryFiles)
12import Prelude hiding (catch)
13import Control.Exception ( bracket_, catch )
14import Control.Monad ( unless )
15import System.Process ( rawSystem, runCommand, waitForProcess )
16import System.FilePath ( (</>) )
17import System.Directory
20import System.IO.Error ( isDoesNotExistError )
21import Data.Maybe ( catMaybes )
22import Data.List ( (\\) )
26 defaultMainWithHooks $ simpleUserHooks {
27 postBuild = makeManPages
28 , postCopy = \ _ flags pkg lbi ->
29 installManpages pkg lbi (fromFlag $ copyVerbosity flags)
30 (fromFlag $ copyDest flags)
31 , postInst = \ _ flags pkg lbi ->
32 installManpages pkg lbi (fromFlag $ installVerbosity flags) NoCopyDest
36-- | Build man pages from markdown sources in man/
37makeManPages :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
38makeManPages _ flags _ lbi = do
39 ds1 <- modifiedDependencies (manDir </> "man1" </> "pandoc.1")
40 ["README", manDir </> "man1" </> "pandoc.1.template"]
41 ds2 <- modifiedDependencies (manDir </> "man5" </> "pandoc_markdown.5")
42 ["README", manDir </> "man5" </> "pandoc_markdown.5.template"]
44 let distPref = fromFlag (buildDistPref flags)
47 ++ [SpecificPackageDB $ distPref </> "package.conf.inplace"]
49 verbosity = fromFlag $ buildVerbosity flags
51 args = makeGhcArgs (ghcPackageDbOptions packageDB)
53 args' = if verbosity == silent
55 else args ++ ["--verbose"]
56 -- Don't run MakeManPage.hs unless we have to
57 unless (null ds1 && null ds2) $ do
58 rawSystem "runghc" args' >>= exitWith
60-- format arguments to runghc that we wish to pass to ghc
61-- normally runghc gets it right, unless the argument does
62-- not begin with a '-' charecter, so we need to give clear
64makeGhcArgs :: [String] -> [String]
65makeGhcArgs = map ("--ghc-arg="++)
68manpages = ["man1" </> "pandoc.1"
69 ,"man5" </> "pandoc_markdown.5"]
74installManpages :: PackageDescription -> LocalBuildInfo
75 -> Verbosity -> CopyDest -> IO ()
76installManpages pkg lbi verbosity copy =
77 installOrdinaryFiles verbosity (mandir (absoluteInstallDirs pkg lbi copy))
78 (zip (repeat manDir) manpages)
80-- | Returns a list of 'dependencies' that have been modified after 'file'.
81modifiedDependencies :: FilePath -> [FilePath] -> IO [FilePath]
82modifiedDependencies file dependencies = do
83 fileModTime <- catch (getModificationTime file) $
84 \e -> if isDoesNotExistError e
85 then return (TOD 0 0) -- the minimum ClockTime
87 depModTimes <- mapM getModificationTime dependencies
88 let modified = zipWith (\dep time -> if time > fileModTime then Just dep else Nothing) dependencies depModTimes
89 return $ catMaybes modified
91-- | Perform an IO action in a directory.
92inDirectory :: FilePath -> IO a -> IO a
93inDirectory dir action = do
94 oldDir <- getCurrentDirectory
95 bracket_ (setCurrentDirectory dir) (setCurrentDirectory oldDir) action
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list