fe55e0db3e7ecf97bd69a02037327f3aaf50bec8
[hadrian.git] / src / Settings / Builders / Haddock.hs
1 module Settings.Builders.Haddock (haddockArgs) where
2
3 import Builder
4 import Package
5 import Expression
6 import Predicates (builder, package, stage1)
7 import Oracles.PackageData
8 import Settings.Util
9 import Settings.Packages
10 import Settings.Builders.Ghc
11
12 haddockArgs :: Args
13 haddockArgs = builder Haddock ? do
14 file <- getFile
15 srcs <- getSources
16 pkg <- getPackage
17 path <- getTargetPath
18 version <- getPkgData Version
19 synopsis <- getPkgData Synopsis
20 hidden <- getPkgDataList HiddenModules
21 deps <- getPkgDataList Deps
22 depNames <- getPkgDataList DepNames
23 ghcOpts <- fromDiffExpr commonGhcArgs
24 mconcat
25 [ arg $ "--odir=" ++ takeDirectory file
26 , arg "--verbosity=0"
27 , arg "--no-tmp-comp-dir"
28 , arg $ "--dump-interface=" ++ file
29 , arg "--html"
30 , arg "--hoogle"
31 , arg $ "--title=" ++ pkgName pkg ++ "-" ++ version ++ ": " ++ synopsis
32 , arg $ "--prologue=" ++ path -/- "haddock-prologue.txt"
33 , append $ map ("--hide=" ++) hidden
34 , append $ [ "--read-interface=../" ++ dep
35 ++ ",../" ++ dep ++ "/src/%{MODULE/./-}.html\\#%{NAME},"
36 ++ pkgHaddockFile depPkg
37 | (dep, depName) <- zip deps depNames
38 , Just depPkg <- [findKnownPackage depName] ]
39 , append [ "--optghc=" ++ opt | opt <- ghcOpts ]
40 , specified HsColour ?
41 arg "--source-module=src/%{MODULE/./-}.html"
42 , specified HsColour ?
43 arg "--source-entity=src/%{MODULE/./-}.html\\#%{NAME}"
44 , customPackageArgs
45 , append srcs
46 , arg "+RTS"
47 , arg $ "-t" ++ path </> "haddock.t"
48 , arg "--machine-readable" ]
49
50 customPackageArgs :: Args
51 customPackageArgs = mconcat
52 [ package compiler ? stage1 ?
53 arg "--optghc=-DSTAGE=2" ]
54 -- TODO: move to getPackageSources
55 -- , package ghcPrim ? stage1 ?
56 -- arg "libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs" ]
57
58 -- From ghc.mk:
59 -- # -----------------------------------------------
60 -- # Haddock-related bits
61
62 -- # Build the Haddock contents and index
63 -- ifeq "$(HADDOCK_DOCS)" "YES"
64 -- libraries/dist-haddock/index.html: $(haddock_INPLACE) $(ALL_HADDOCK_FILES)
65 -- cd libraries && sh gen_contents_index --intree
66 -- ifeq "$(phase)" "final"
67 -- $(eval $(call all-target,library_doc_index,libraries/dist-haddock/index.html))
68 -- endif
69 -- INSTALL_LIBRARY_DOCS += libraries/dist-haddock/*
70 -- endif