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#      https://gitlab.haskell.org/ghc/ghc/wikis/building/architecture
9#      https://gitlab.haskell.org/ghc/ghc/wikis/building/modifying
10#
11# -----------------------------------------------------------------------------
12
13ifneq "$(BINDIST)" "YES"
14HADDOCK_VER := $(shell grep "^version:" utils/haddock/haddock.cabal | sed "s/version: *//")
15HADDOCK_MAJOR_VER := $(shell echo $(HADDOCK_VER) | sed 's/\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)/\1/')
16HADDOCK_MINOR_VER := $(shell echo $(HADDOCK_VER) | sed 's/\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)/\2/')
17HADDOCK_PATCH_VER := $(shell echo $(HADDOCK_VER) | sed 's/\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)/\3/')
18HADDOCK_VERSION_STRING := $(shell echo $$(($(HADDOCK_MAJOR_VER) * 1000 + $(HADDOCK_MINOR_VER) * 10 + $(HADDOCK_PATCH_VER))))
19endif
20
21define haddock  # args: $1 = dir,  $2 = distdir
22$(call trace, haddock($1,$2))
23$(call profStart, haddock($1,$2))
24
25ifeq "$$($1_$2_DO_HADDOCK)" "YES"
26
27ifeq "$$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE)" ""
28$$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE = $1/$2/doc/html/$$($1_PACKAGE)/$$($1_PACKAGE).haddock
29ALL_HADDOCK_FILES += $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE)
30else
31$$(error Already got a haddock file for $$($1_PACKAGE))
32endif
33
34haddock: html_$1
35
36ifeq "$$(HADDOCK_DOCS)" "YES"
37$(call all-target,$1_$2_haddock,html_$1)
38endif
39
40.PHONY: html_$1
41html_$1 : $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE)
42
43$$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_DEPS = $$(foreach n,$$($1_$2_DEPS),$$($$n_HADDOCK_FILE) $$($$n_dist-install_$$(HADDOCK_WAY)_LIB))
44
45# We don't pass -dcore-lint to haddock because it caused a performance regression in #13789
46$1_$2_HADDOCK_GHC_OPTS = $$(foreach opt, $$(filter-out -dcore-lint,$$($1_$2_$$(HADDOCK_WAY)_ALL_HC_OPTS)),--optghc=$$(opt))
47
48ifeq "$$(HSCOLOUR_SRCS)" "YES"
49$1_$2_HADDOCK_FLAGS += --source-module=src/%{MODULE/./-}.html --source-entity=src/%{MODULE/./-}.html\#%{NAME}
50endif
51
52ifneq "$$(BINDIST)" "YES"
53
54# We need the quadruple dollars for the dependencies, as it isn't
55# guaranteed that we are processing the packages in dependency order,
56# so we don't want to expand it yet.
57$$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) : $$$$(haddock_INPLACE) $$$$(ghc-cabal_INPLACE) $$($1_$2_HS_SRCS) $$$$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_DEPS) | $$$$(dir $$$$@)/.
58ifeq "$$(HSCOLOUR_SRCS)" "YES"
59	"$$(ghc-cabal_INPLACE)" hscolour $1 $2
60endif
61	# N.B. in a source tree from tarball the testsuite/ directory may not exist
62	mkdir -p $$(TOP)/testsuite/tests/perf/haddock
63	"$$(TOP)/$$(INPLACE_BIN)/haddock" \
64		--verbosity=0 \
65		--odir="$1/$2/doc/html/$$($1_PACKAGE)" \
66		--no-tmp-comp-dir \
67		--dump-interface=$$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) \
68		--html \
69		--hoogle \
70		--quickjump \
71		--title="$$($1_PACKAGE)-$$($1_$2_VERSION)$$(if $$(strip $$($1_$2_SYNOPSIS)),: $$(strip $$($1_$2_SYNOPSIS)),)" \
72		--prologue="$1/$2/haddock-prologue.txt" \
73		--optghc="-D__HADDOCK_VERSION__=$$(HADDOCK_VERSION_STRING)" \
74		$$(foreach mod,$$($1_$2_HIDDEN_MODULES),--hide=$$(mod)) \
75		$$(foreach pkg,$$($1_$2_DEPS),$$(if $$($$(pkg)_HADDOCK_FILE),--read-interface=../$$(pkg)$$(comma)../$$(pkg)/src/%{MODULE/./-}.html\#%{NAME}$$(comma)$$($$(pkg)_HADDOCK_FILE))) \
76		$$($1_$2_HADDOCK_GHC_OPTS) \
77		$$($1_$2_HADDOCK_FLAGS) $$($1_$2_HADDOCK_OPTS) \
78		$$($1_$2_HS_SRCS) \
79		$$($1_$2_EXTRA_HADDOCK_SRCS) \
80		$$(EXTRA_HADDOCK_OPTS) \
81		+RTS -t"$$(TOP)/testsuite/tests/perf/haddock/$$($1_PACKAGE).t" --machine-readable
82
83# --no-tmp-comp-dir above is important: it saves a few minutes in a
84# validate.  This flag lets Haddock use the pre-compiled object files
85# for the package rather than rebuilding the modules of the package in
86# a temporary directory.  Haddock needs to build the package when it
87# uses the Template Haskell or Annotations extensions, for example.
88
89# Make the haddocking depend on the library .a file, to ensure
90# that we wait until the library is fully built before we haddock it
91$$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) : $$($1_$2_$$(HADDOCK_WAY)_LIB)
92endif
93
94endif # $1_$2_DO_HADDOCK
95
96$(call profEnd, haddock($1,$2))
97endef
98