summaryrefslogtreecommitdiff
path: root/hadrian/src/Hadrian/Builder/Sphinx.hs
blob: 5e4fa9fac46f1683701aabc2f03e91162347d4f7 (plain)
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
-----------------------------------------------------------------------------
-- |
-- Module     : Hadrian.Builder.Sphinx
-- Copyright  : (c) Andrey Mokhov 2014-2017
-- License    : MIT (see the file LICENSE)
-- Maintainer : andrey.mokhov@gmail.com
-- Stability  : experimental
--
-- Support for invoking the documentation utility Sphinx.
-----------------------------------------------------------------------------
module Hadrian.Builder.Sphinx (SphinxMode (..), args) where

import Development.Shake         hiding (Verbosity(..))
import Development.Shake.Classes
import GHC.Generics
import Hadrian.Expression
import Hadrian.Utilities

-- | Sphinx can be used in three different modes to convert reStructuredText
-- documents into HTML, LaTeX or Man pages.
data SphinxMode = Info | Html | Latex | Man deriving (Eq, Generic, Show)

instance Binary   SphinxMode
instance Hashable SphinxMode
instance NFData   SphinxMode

-- | Default command line arguments for invoking the archiving utility @tar@.
args :: (ShakeValue c, ShakeValue b) => SphinxMode -> Args c b
args mode = do
    outPath <- getOutput
    mconcat [ arg "-b", arg modeString
            , arg "-d", arg $ outPath -/- (".doctrees-" ++ modeString)
            , arg "-n" -- nit-picky mode to ensure missing references are caught
            , arg "-w", arg $ outPath -/- ".log" -- dump warnings to log file
            , arg =<< getInput
            , arg outPath ]
  where
    modeString = case mode of
        Info  -> "texinfo"
        Html  -> "html"
        Latex -> "latex"
        Man   -> "man"