git.iko.soy/typeable/pandoc
on 91128aa help sign in
typeable/pandoc/Setup.hs
76 lines 3.2 kB history raw
1{-
2Copyright (C) 2006-2014 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.PackageDescription (PackageDescription(..), Executable(..))
22import System.Process ( rawSystem )
23import System.FilePath ( (</>) )
24import System.Directory ( findExecutable )
25import Distribution.Simple.Utils (info, rawSystemExit)
26import Distribution.Simple.Setup
27import Distribution.Simple.LocalBuildInfo
28import Distribution.Verbosity
30main :: IO ()
31main = defaultMainWithHooks $ simpleUserHooks {
32 -- enable hsb2hs preprocessor for .hsb files
33 hookedPreProcessors = [ppBlobSuffixHandler]
34 -- ensure that make-pandoc-man-pages doesn't get installed to bindir
35 , copyHook = \pkgdescr ->
36 copyHook simpleUserHooks pkgdescr{ executables =
37 [x | x <- executables pkgdescr, exeName x `notElem` noInstall] }
38 , instHook = \pkgdescr ->
39 instHook simpleUserHooks pkgdescr{ executables =
40 [x | x <- executables pkgdescr, exeName x `notElem` noInstall] }
41 , postBuild = \args bf pkgdescr lbi -> do
42 makeManPages args bf pkgdescr lbi
43 makeReferenceFiles args bf pkgdescr lbi
44 }
45 where
46 noInstall = ["make-pandoc-man-pages","make-reference-files"]
48ppBlobSuffixHandler :: PPSuffixHandler
49ppBlobSuffixHandler = ("hsb", \_ _ ->
50 PreProcessor {
51 platformIndependent = True,
52 runPreProcessor = mkSimplePreProcessor $ \infile outfile verbosity ->
53 do info verbosity $ "Preprocessing " ++ infile ++ " to " ++ outfile
54 hsb2hsPath <- findExecutable "hsb2hs"
55 case hsb2hsPath of
56 Just p -> rawSystem p [infile, infile, outfile]
57 Nothing -> error "hsb2hs is needed to build this program: cabal install hsb2hs"
58 return ()
59 })
61makeManPages :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
62makeManPages _ bf _ LocalBuildInfo{buildDir=buildDir}
63 = rawSystemExit verbosity progPath []
64 where
65 verbosity = fromFlagOrDefault normal $ buildVerbosity bf
66 progPath = buildDir </> "make-pandoc-man-pages" </> "make-pandoc-man-pages"
68makeReferenceFiles :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
69makeReferenceFiles _ bf _ LocalBuildInfo{buildDir=buildDir}
70 = mapM_
71 (rawSystemExit verbosity progPath . return)
72 referenceFormats
73 where
74 verbosity = fromFlagOrDefault normal $ buildVerbosity bf
75 progPath = buildDir </> "make-reference-files" </> "make-reference-files"
76 referenceFormats = ["docx", "odt"]