rules/haddock: Set __HADDOCK_VERSION__
[ghc.git] / rules / haddock.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009 The University of Glasgow
4 #
5 # This file is part of the GHC build system.
6 #
7 # To understand how the build system works and how to modify it, see
8 # http://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://ghc.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13 HADDOCK_VER := $(shell grep "^version:" utils/haddock/haddock.cabal | sed "s/^version: \+//")
14 HADDOCK_MAJOR_VER := $(shell echo $(HADDOCK_VER) | sed 's/\([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1/')
15 HADDOCK_MINOR_VER := $(shell echo $(HADDOCK_VER) | sed 's/\([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\2/')
16 HADDOCK_PATCH_VER := $(shell echo $(HADDOCK_VER) | sed 's/\([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\3/')
17 HADDOCK_VERSION_STRING := $(shell echo $$(($(HADDOCK_MAJOR_VER) * 1000 + $(HADDOCK_MINOR_VER) * 10 + $(HADDOCK_PATCH_VER))))
18
19 define haddock # args: $1 = dir, $2 = distdir
20 $(call trace, haddock($1,$2))
21 $(call profStart, haddock($1,$2))
22
23 ifeq "$$($1_$2_DO_HADDOCK)" "YES"
24
25 ifeq "$$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE)" ""
26 $$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE = $1/$2/doc/html/$$($1_PACKAGE)/$$($1_PACKAGE).haddock
27 ALL_HADDOCK_FILES += $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE)
28 else
29 $$(error Already got a haddock file for $$($1_PACKAGE))
30 endif
31
32 haddock: html_$1
33
34 ifeq "$$(HADDOCK_DOCS)" "YES"
35 $(call all-target,$1_$2_haddock,html_$1)
36 endif
37
38 .PHONY: html_$1
39 html_$1 : $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE)
40
41 $$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_DEPS = $$(foreach n,$$($1_$2_DEPS),$$($$n_HADDOCK_FILE) $$($$n_dist-install_$$(HADDOCK_WAY)_LIB))
42
43 ifeq "$$(HSCOLOUR_SRCS)" "YES"
44 $1_$2_HADDOCK_FLAGS += --source-module=src/%{MODULE/./-}.html --source-entity=src/%{MODULE/./-}.html\#%{NAME}
45 endif
46
47 ifneq "$$(BINDIST)" "YES"
48
49 # We need the quadruple dollars for the dependencies, as it isn't
50 # guaranteed that we are processing the packages in dependency order,
51 # so we don't want to expand it yet.
52 $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) : $$$$(haddock_INPLACE) $$$$(ghc-cabal_INPLACE) $$($1_$2_HS_SRCS) $$$$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_DEPS) | $$$$(dir $$$$@)/.
53 ifeq "$$(HSCOLOUR_SRCS)" "YES"
54 "$$(ghc-cabal_INPLACE)" hscolour $1 $2
55 endif
56 "$$(TOP)/$$(INPLACE_BIN)/haddock" \
57 --verbosity=0 \
58 --odir="$1/$2/doc/html/$$($1_PACKAGE)" \
59 --no-tmp-comp-dir \
60 --dump-interface=$$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) \
61 --html \
62 --hoogle \
63 --title="$$($1_PACKAGE)-$$($1_$2_VERSION)$$(if $$(strip $$($1_$2_SYNOPSIS)),: $$(strip $$($1_$2_SYNOPSIS)),)" \
64 --prologue="$1/$2/haddock-prologue.txt" \
65 --optghc="-D__HADDOCK_VERSION__=$$(HADDOCK_VERSION_STRING)" \
66 $$(foreach mod,$$($1_$2_HIDDEN_MODULES),--hide=$$(mod)) \
67 $$(foreach pkg,$$($1_$2_DEPS),$$(if $$($$(pkg)_HADDOCK_FILE),--read-interface=../$$(pkg)$$(comma)../$$(pkg)/src/%{MODULE/./-}.html\#%{NAME}$$(comma)$$($$(pkg)_HADDOCK_FILE))) \
68 $$(foreach opt,$$($1_$2_$$(HADDOCK_WAY)_ALL_HC_OPTS),--optghc=$$(opt)) \
69 $$($1_$2_HADDOCK_FLAGS) $$($1_$2_HADDOCK_OPTS) \
70 $$($1_$2_HS_SRCS) \
71 $$($1_$2_EXTRA_HADDOCK_SRCS) \
72 +RTS -t"$1/$2/haddock.t" --machine-readable
73
74 # --no-tmp-comp-dir above is important: it saves a few minutes in a
75 # validate. This flag lets Haddock use the pre-compiled object files
76 # for the package rather than rebuilding the modules of the package in
77 # a temporary directory. Haddock needs to build the package when it
78 # uses the Template Haskell or Annotations extensions, for example.
79
80 # Make the haddocking depend on the library .a file, to ensure
81 # that we wait until the library is fully built before we haddock it
82 $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) : $$($1_$2_$$(HADDOCK_WAY)_LIB)
83 endif
84
85 endif # $1_$2_DO_HADDOCK
86
87 $(call profEnd, haddock($1,$2))
88 endef
89