Haddock.hs 2.48 KB
Newer Older
1
module Settings.Builders.Haddock (haddockBuilderArgs) where
2

3
import Settings.Builders.Common
4
5
import Settings.Builders.Ghc

6
7
8
9
10
11
-- | Given a version string such as "2.16.2" produce an integer equivalent.
versionToInt :: String -> Int
versionToInt s = major * 1000 + minor * 10 + patch
  where
    [major, minor, patch] = map read . words $ replaceEq '.' ' ' s

12
13
haddockBuilderArgs :: Args
haddockBuilderArgs = builder Haddock ? do
14
    output   <- getOutput
15
    pkg      <- getPackage
16
    path     <- getBuildPath
17
18
19
20
    version  <- getPkgData Version
    synopsis <- getPkgData Synopsis
    deps     <- getPkgDataList Deps
    depNames <- getPkgDataList DepNames
21
    hVersion <- lift . pkgData . Version $ buildPath (vanillaContext Stage2 haddock)
22
23
    ghcOpts  <- fromDiffExpr commonGhcArgs
    mconcat
24
        [ arg $ "--odir=" ++ takeDirectory output
Andrey Mokhov's avatar
Andrey Mokhov committed
25
        , arg "--verbosity=0"
26
        , arg "--no-tmp-comp-dir"
27
        , arg $ "--dump-interface=" ++ output
28
29
        , arg "--html"
        , arg "--hoogle"
30
        , arg $ "--title=" ++ pkgNameString pkg ++ "-" ++ version ++ ": " ++ synopsis
31
        , arg $ "--prologue=" ++ path -/- "haddock-prologue.txt"
32
        , arg $ "--optghc=-D__HADDOCK_VERSION__=" ++ show (versionToInt hVersion)
Andrey Mokhov's avatar
Andrey Mokhov committed
33
        , append . map ("--hide=" ++) =<< getPkgDataList HiddenModules
34
35
        , append $ [ "--read-interface=../" ++ dep
                     ++ ",../" ++ dep ++ "/src/%{MODULE/./-}.html\\#%{NAME},"
Andrey Mokhov's avatar
Andrey Mokhov committed
36
                     ++ pkgHaddockFile (vanillaContext Stage1 depPkg)
37
                   | (dep, depName) <- zip deps depNames
38
39
                   , Just depPkg <- [findKnownPackage $ PackageName depName]
                   , depPkg /= rts ]
40
        , append [ "--optghc=" ++ opt | opt <- ghcOpts ]
41
42
43
        , isSpecified HsColour ?
          append [ "--source-module=src/%{MODULE/./-}.html"
                 , "--source-entity=src/%{MODULE/./-}.html\\#%{NAME}" ]
44
        , append =<< getInputs
45
        , arg "+RTS"
46
        , arg $ "-t" ++ path -/- "haddock.t"
47
48
        , arg "--machine-readable"
        , arg "-RTS" ]
49
50
51
52
53
54
55
56
57
58
59
60
61
62

-- From ghc.mk:
-- # -----------------------------------------------
-- # Haddock-related bits

-- # Build the Haddock contents and index
-- ifeq "$(HADDOCK_DOCS)" "YES"
-- libraries/dist-haddock/index.html: $(haddock_INPLACE) $(ALL_HADDOCK_FILES)
--     cd libraries && sh gen_contents_index --intree
-- ifeq "$(phase)" "final"
-- $(eval $(call all-target,library_doc_index,libraries/dist-haddock/index.html))
-- endif
-- INSTALL_LIBRARY_DOCS += libraries/dist-haddock/*
-- endif