2012-09-21 16:41:04 +02:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
import Distribution.Simple
|
2013-01-23 17:33:45 +01:00
|
|
|
import Distribution.Simple.PreProcess
|
2010-01-12 08:02:30 +01:00
|
|
|
import Distribution.Simple.Setup
|
2013-10-20 21:36:26 +02:00
|
|
|
(copyDest, copyVerbosity, fromFlag, installVerbosity, BuildFlags(..),
|
|
|
|
TestFlags(..))
|
2013-10-09 05:52:56 +02:00
|
|
|
import Distribution.PackageDescription (PackageDescription(..), Executable(..))
|
2010-01-12 08:02:30 +01:00
|
|
|
import Distribution.Simple.LocalBuildInfo
|
2010-01-17 01:28:36 +01:00
|
|
|
(LocalBuildInfo(..), absoluteInstallDirs)
|
2010-01-17 01:28:42 +01:00
|
|
|
import Distribution.Verbosity ( Verbosity, silent )
|
2013-10-20 21:36:26 +02:00
|
|
|
import Distribution.Simple.InstallDirs (mandir, CopyDest (NoCopyDest), toPathTemplate)
|
2013-01-23 17:33:45 +01:00
|
|
|
import Distribution.Simple.Utils (installOrdinaryFiles, info)
|
2013-10-20 21:36:26 +02:00
|
|
|
import Distribution.Simple.Test (test)
|
2012-07-25 04:28:51 +02:00
|
|
|
import Prelude hiding (catch)
|
2012-10-16 06:26:24 +02:00
|
|
|
import System.Process ( rawSystem )
|
2011-01-28 20:55:11 +01:00
|
|
|
import System.FilePath ( (</>) )
|
2013-01-23 17:33:45 +01:00
|
|
|
import System.Directory ( findExecutable )
|
2008-08-09 20:14:20 +02:00
|
|
|
import System.Exit
|
2008-08-09 18:51:08 +02:00
|
|
|
|
2010-01-17 01:28:36 +01:00
|
|
|
main :: IO ()
|
2008-10-27 22:52:31 +01:00
|
|
|
main = do
|
2010-01-12 08:02:30 +01:00
|
|
|
defaultMainWithHooks $ simpleUserHooks {
|
2013-10-09 05:52:56 +02:00
|
|
|
postBuild = makeManPages
|
2013-10-20 21:36:26 +02:00
|
|
|
, testHook = \pkg lbi _ flags ->
|
|
|
|
-- pass build directory as first argument to test program
|
|
|
|
test pkg lbi flags{ testOptions =
|
|
|
|
toPathTemplate (buildDir lbi) : testOptions flags }
|
2012-01-21 06:22:51 +01:00
|
|
|
, postCopy = \ _ flags pkg lbi ->
|
2010-01-12 08:02:36 +01:00
|
|
|
installManpages pkg lbi (fromFlag $ copyVerbosity flags)
|
|
|
|
(fromFlag $ copyDest flags)
|
2012-01-21 06:22:51 +01:00
|
|
|
, postInst = \ _ flags pkg lbi ->
|
2010-01-12 08:02:36 +01:00
|
|
|
installManpages pkg lbi (fromFlag $ installVerbosity flags) NoCopyDest
|
2013-10-09 05:52:56 +02:00
|
|
|
, copyHook = \pkgdescr ->
|
|
|
|
(copyHook simpleUserHooks) pkgdescr{ executables =
|
|
|
|
[x | x <- executables pkgdescr, exeName x /= "make-pandoc-man-pages"] }
|
|
|
|
, instHook = \pkgdescr ->
|
|
|
|
(instHook simpleUserHooks) pkgdescr{ executables =
|
|
|
|
[x | x <- executables pkgdescr, exeName x /= "make-pandoc-man-pages"] }
|
2013-01-23 17:33:45 +01:00
|
|
|
, hookedPreProcessors = [ppBlobSuffixHandler]
|
2010-01-12 08:02:30 +01:00
|
|
|
}
|
2008-10-27 22:52:31 +01:00
|
|
|
exitWith ExitSuccess
|
2008-08-09 18:51:08 +02:00
|
|
|
|
2011-01-28 20:55:11 +01:00
|
|
|
-- | Build man pages from markdown sources in man/
|
2010-01-17 01:28:36 +01:00
|
|
|
makeManPages :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
|
2012-11-07 20:57:17 +01:00
|
|
|
makeManPages _ flags _ lbi = do
|
2012-10-16 06:26:24 +02:00
|
|
|
let verbosity = fromFlag $ buildVerbosity flags
|
|
|
|
let args = ["--verbose" | verbosity /= silent]
|
2012-11-07 20:57:17 +01:00
|
|
|
rawSystem (buildDir lbi </> "make-pandoc-man-pages" </> "make-pandoc-man-pages")
|
2012-10-16 06:26:24 +02:00
|
|
|
args >>= exitWith
|
2010-01-12 08:02:30 +01:00
|
|
|
|
|
|
|
manpages :: [FilePath]
|
2011-01-28 20:55:11 +01:00
|
|
|
manpages = ["man1" </> "pandoc.1"
|
|
|
|
,"man5" </> "pandoc_markdown.5"]
|
2010-01-12 08:02:30 +01:00
|
|
|
|
|
|
|
manDir :: FilePath
|
2011-01-28 20:55:11 +01:00
|
|
|
manDir = "man"
|
2008-08-10 01:45:40 +02:00
|
|
|
|
2010-01-12 08:02:36 +01:00
|
|
|
installManpages :: PackageDescription -> LocalBuildInfo
|
|
|
|
-> Verbosity -> CopyDest -> IO ()
|
|
|
|
installManpages pkg lbi verbosity copy =
|
2012-03-09 22:30:14 +01:00
|
|
|
installOrdinaryFiles verbosity (mandir (absoluteInstallDirs pkg lbi copy))
|
2010-01-12 08:02:30 +01:00
|
|
|
(zip (repeat manDir) manpages)
|
|
|
|
|
2013-01-23 17:33:45 +01:00
|
|
|
ppBlobSuffixHandler :: PPSuffixHandler
|
|
|
|
ppBlobSuffixHandler = ("hsb", \_ _ ->
|
|
|
|
PreProcessor {
|
|
|
|
platformIndependent = True,
|
|
|
|
runPreProcessor = mkSimplePreProcessor $ \infile outfile verbosity ->
|
|
|
|
do info verbosity $ "Preprocessing " ++ infile ++ " to " ++ outfile
|
|
|
|
hsb2hsPath <- findExecutable "hsb2hs"
|
|
|
|
case hsb2hsPath of
|
|
|
|
Just p -> rawSystem p [infile, infile, outfile]
|
|
|
|
Nothing -> error "hsb2hs is needed to build this program: cabal install hsb2hs"
|
|
|
|
return ()
|
|
|
|
|
|
|
|
})
|