git.iko.soy/typeable/pandoc
on 1.12.1 help sign in
typeable/pandoc/Setup.hs
77 lines 3.1 kB history raw
1{-# LANGUAGE CPP #-}
3import Distribution.Simple
4import Distribution.Simple.PreProcess
5import Distribution.Simple.Setup
6 (copyDest, copyVerbosity, fromFlag, installVerbosity, BuildFlags(..),
7 TestFlags(..))
8import Distribution.PackageDescription (PackageDescription(..), Executable(..))
9import Distribution.Simple.LocalBuildInfo
10 (LocalBuildInfo(..), absoluteInstallDirs)
11import Distribution.Verbosity ( Verbosity, silent )
12import Distribution.Simple.InstallDirs (mandir, CopyDest (NoCopyDest), toPathTemplate)
13import Distribution.Simple.Utils (installOrdinaryFiles, info)
14import Distribution.Simple.Test (test)
15import Prelude hiding (catch)
16import System.Process ( rawSystem )
17import System.FilePath ( (</>) )
18import System.Directory ( findExecutable )
19import System.Exit
21main :: IO ()
22main = do
23 defaultMainWithHooks $ simpleUserHooks {
24 postBuild = makeManPages
25 , testHook = \pkg lbi _ flags ->
26 -- pass build directory as first argument to test program
27 test pkg lbi flags{ testOptions =
28 toPathTemplate (buildDir lbi) : testOptions flags }
29 , postCopy = \ _ flags pkg lbi ->
30 installManpages pkg lbi (fromFlag $ copyVerbosity flags)
31 (fromFlag $ copyDest flags)
32 , postInst = \ _ flags pkg lbi ->
33 installManpages pkg lbi (fromFlag $ installVerbosity flags) NoCopyDest
34 , copyHook = \pkgdescr ->
35 (copyHook simpleUserHooks) pkgdescr{ executables =
36 [x | x <- executables pkgdescr, exeName x /= "make-pandoc-man-pages"] }
37 , instHook = \pkgdescr ->
38 (instHook simpleUserHooks) pkgdescr{ executables =
39 [x | x <- executables pkgdescr, exeName x /= "make-pandoc-man-pages"] }
40 , hookedPreProcessors = [ppBlobSuffixHandler]
41 }
42 exitWith ExitSuccess
44-- | Build man pages from markdown sources in man/
45makeManPages :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
46makeManPages _ flags _ lbi = do
47 let verbosity = fromFlag $ buildVerbosity flags
48 let args = ["--verbose" | verbosity /= silent]
49 rawSystem (buildDir lbi </> "make-pandoc-man-pages" </> "make-pandoc-man-pages")
50 args >>= exitWith
52manpages :: [FilePath]
53manpages = ["man1" </> "pandoc.1"
54 ,"man5" </> "pandoc_markdown.5"]
56manDir :: FilePath
57manDir = "man"
59installManpages :: PackageDescription -> LocalBuildInfo
60 -> Verbosity -> CopyDest -> IO ()
61installManpages pkg lbi verbosity copy =
62 installOrdinaryFiles verbosity (mandir (absoluteInstallDirs pkg lbi copy))
63 (zip (repeat manDir) manpages)
65ppBlobSuffixHandler :: PPSuffixHandler
66ppBlobSuffixHandler = ("hsb", \_ _ ->
67 PreProcessor {
68 platformIndependent = True,
69 runPreProcessor = mkSimplePreProcessor $ \infile outfile verbosity ->
70 do info verbosity $ "Preprocessing " ++ infile ++ " to " ++ outfile
71 hsb2hsPath <- findExecutable "hsb2hs"
72 case hsb2hsPath of
73 Just p -> rawSystem p [infile, infile, outfile]
74 Nothing -> error "hsb2hs is needed to build this program: cabal install hsb2hs"
75 return ()
77 })