git.iko.soy/typeable/pandoc
on 1.15.0.3 help sign in
typeable/pandoc/Setup.hs
75 lines 3.2 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.InstallDirs (mandir)
22import Distribution.PackageDescription (PackageDescription(..), Executable(..))
23import System.Process ( rawSystem )
24import System.FilePath ( (</>) )
25import System.Directory ( findExecutable )
26import Distribution.Simple.Utils (info, notice, rawSystemExit, installOrdinaryFiles)
27import Distribution.Simple.Setup
28import Distribution.Simple.LocalBuildInfo
29import Distribution.Verbosity
31main :: IO ()
32main = defaultMainWithHooks $ simpleUserHooks {
33 -- enable hsb2hs preprocessor for .hsb files
34 hookedPreProcessors = [ppBlobSuffixHandler]
35 , postBuild = \args bf pkgdescr lbi ->
36 makeManPage args bf pkgdescr lbi
38 , postCopy = \_ flags pkg lbi ->
39 installManpage pkg lbi (fromFlag $ copyVerbosity flags)
40 NoCopyDest
41 }
43ppBlobSuffixHandler :: PPSuffixHandler
44ppBlobSuffixHandler = ("hsb", \_ _ ->
45 PreProcessor {
46 platformIndependent = True,
47 runPreProcessor = mkSimplePreProcessor $ \infile outfile verbosity ->
48 do info verbosity $ "Preprocessing " ++ infile ++ " to " ++ outfile
49 hsb2hsPath <- findExecutable "hsb2hs"
50 case hsb2hsPath of
51 Just p -> rawSystem p [infile, infile, outfile]
52 Nothing -> error "hsb2hs is needed to build this program: cabal install hsb2hs"
53 return ()
54 })
56makeManPage :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo
57 -> IO ()
58makeManPage _ bf _ LocalBuildInfo{buildDir=buildDir}
59 = do notice verbosity "Creating man/pandoc.1"
60 rawSystemExit verbosity progPath args
61 where verbosity = fromFlagOrDefault normal $ buildVerbosity bf
62 progPath = buildDir </> "pandoc" </> "pandoc"
63 args = ["README", "-t", "man", "-s",
64 "--template", "man/pandoc.1.template",
65 "--filter", "man/capitalizeHeaders.hs",
66 "--filter", "man/removeNotes.hs",
67 "--filter", "man/removeLinks.hs",
68 "-o", "man/pandoc.1"]
70installManpage :: PackageDescription -> LocalBuildInfo
71 -> Verbosity -> CopyDest -> IO ()
72installManpage pkg lbi verbosity copy = do
73 let mandest = mandir (absoluteInstallDirs pkg lbi copy) </> "man1"
74 notice verbosity $ "Copying man page to " ++ mandest
75 installOrdinaryFiles verbosity mandest [("man", "pandoc.1")]