git.iko.soy/typeable/pandoc
on mallard help sign in
typeable/pandoc/Setup.hs
70 lines 3.0 kB history raw
1{-
2Copyright (C) 2006-2015 John MacFarlane <jgm@berkeley.edu>
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or
7(at your option) any later version.
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17-}
19import Distribution.Simple
20import Distribution.Simple.PreProcess
21import Distribution.Simple.Setup (ConfigFlags(..))
22import Distribution.PackageDescription (PackageDescription(..), FlagName(..))
23import Distribution.Simple.Utils ( rawSystemExitCode, findProgramVersion )
24import System.Exit
25import Distribution.Verbosity ( Verbosity )
26import Distribution.Simple.Utils (info, notice, installOrdinaryFiles)
27import Distribution.Simple.Setup
28import Distribution.Simple.Program (simpleProgram, Program(..))
29import Distribution.Simple.LocalBuildInfo
30import Data.Version
31import Control.Monad (when)
32import qualified Control.Exception as E
34main :: IO ()
35main = defaultMainWithHooks $ simpleUserHooks {
36 -- enable hsb2hs preprocessor for .hsb files
37 hookedPreProcessors = [ppBlobSuffixHandler]
38 , hookedPrograms = [(simpleProgram "hsb2hs"){
39 programFindVersion = \verbosity fp ->
40 findProgramVersion "--version" id verbosity fp }]
41 , postCopy = installManPage
42 }
44ppBlobSuffixHandler :: PPSuffixHandler
45ppBlobSuffixHandler = ("hsb", \_ lbi ->
46 PreProcessor {
47 platformIndependent = True,
48 runPreProcessor = mkSimplePreProcessor $ \infile outfile verbosity ->
49 do let embedData = case lookup (FlagName "embed_data_files")
50 (configConfigurationsFlags (configFlags lbi)) of
51 Just True -> True
52 _ -> False
53 when embedData $
54 do info verbosity $ "Preprocessing " ++ infile ++ " to " ++ outfile
55 ec <- rawSystemExitCode verbosity "hsb2hs"
56 [infile, infile, outfile]
57 case ec of
58 ExitSuccess -> return ()
59 ExitFailure _ -> error "hsb2hs is needed to build this program"
60 })
62installManPage :: Args -> CopyFlags
63 -> PackageDescription -> LocalBuildInfo -> IO ()
64installManPage _ flags pkg lbi = do
65 let verbosity = fromFlag (copyVerbosity flags)
66 let copydest = fromFlag (copyDest flags)
67 let mandest = mandir (absoluteInstallDirs pkg lbi copydest)
68 ++ "/man1"
69 notice verbosity $ "Copying man page to " ++ mandest
70 installOrdinaryFiles verbosity mandest [("man", "pandoc.1")]