This repository has been archived by the owner on Apr 30, 2021. It is now read-only.
/
Setup.hs
46 lines (41 loc) · 1.77 KB
/
Setup.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{-# LANGUAGE CPP #-}
import Distribution.Simple
import Distribution.Simple.PreProcess
import Distribution.PackageDescription (PackageDescription(..))
import Distribution.Simple.Program (simpleProgram, Program(..))
import Distribution.Simple.Utils ( rawSystemExitCode, findProgramVersion )
import System.Exit
import Distribution.Simple.Utils (info, notice, installOrdinaryFiles)
import Distribution.Simple.Setup
import Distribution.Simple.LocalBuildInfo
main :: IO ()
main =
defaultMainWithHooks $ simpleUserHooks {
-- enable hsb2hs preprocessor for .hsb files
hookedPreProcessors = [ppBlobSuffixHandler]
, hookedPrograms = [(simpleProgram "hsb2hs"){
programFindVersion = \verbosity fp ->
findProgramVersion "--version" id verbosity fp }]
, postCopy = installManPage
}
installManPage :: Args -> CopyFlags
-> PackageDescription -> LocalBuildInfo -> IO ()
installManPage _ flags pkg lbi = do
let verbosity = fromFlag (copyVerbosity flags)
let copydest = fromFlag (copyDest flags)
let mandest = mandir (absoluteInstallDirs pkg lbi copydest)
++ "/man1"
notice verbosity $ "Copying man page to " ++ mandest
installOrdinaryFiles verbosity mandest
[("man/man1", "pandoc-citeproc.1")]
ppBlobSuffixHandler :: PPSuffixHandler
ppBlobSuffixHandler = ("hsb", \_ _ ->
PreProcessor {
platformIndependent = True,
runPreProcessor = mkSimplePreProcessor $ \infile outfile verbosity ->
do info verbosity $ "Preprocessing " ++ infile ++ " to " ++ outfile
ec <- rawSystemExitCode verbosity "hsb2hs" [infile, infile, outfile]
case ec of
ExitSuccess -> return ()
ExitFailure _ -> error "hsb2hs is needed to build this program"
})