Overhauled llvm/clang docs builds. Closes PR6613.
[oota-llvm.git] / docs / mk / main.mk
1 ##===- docs/mk/main.mk -------------------------------------*- Makefile -*-===##
2
3 #                     The LLVM Compiler Infrastructure
4 #
5 # This file is distributed under the University of Illinois Open Source
6 # License. See LICENSE.TXT for details.
7
8 ##===----------------------------------------------------------------------===##
9 #
10 # Main HTML documentation support module.
11 #
12 # The following variables must be defined before including this makefile:
13 #
14 #       HTML.Project  formal project name. eg. LLVM or Clang.
15 #       HTML.project  filesystem project name. eg. llvm or clang.
16 #
17 ##===----------------------------------------------------------------------===##
18
19 include $(LLVM_SRC_ROOT)/docs/mk/common.defs.mk
20
21 MAIN.in/   = $(PROJ_SRC_DIR)/
22 MAIN.out/  = ./
23
24 MAIN.html/        = $(MAIN.out/)html/
25 MAIN.html.tar     = $(MAIN.out/)html.tar.gz
26 MAIN.html.cp.ext  = .html .css .txt .png .jpg .gif
27 MAIN.html.cp.in   = $(patsubst $(MAIN.in/)%,%, \
28   $(sort $(wildcard $(foreach x,$(MAIN.html.cp.ext), $(MAIN.in/)*$(x)     ))) \
29   $(sort $(wildcard $(foreach x,$(MAIN.html.cp.ext), $(MAIN.in/)*/*$(x)   ))) \
30   $(sort $(wildcard $(foreach x,$(MAIN.html.cp.ext), $(MAIN.in/)*/*/*$(x) ))) )
31 MAIN.html.cp.out  = $(MAIN.html.cp.in:%=$(MAIN.html/)%)
32 MAIN.html.pod.in  = $(patsubst $(MAIN.in/)%,%, \
33                                     $(sort $(wildcard $(MAIN.in/)*.pod     )) \
34                                     $(sort $(wildcard $(MAIN.in/)*.pod     )) \
35                                     $(sort $(wildcard $(MAIN.in/)*/*.pod   )) \
36                                     $(sort $(wildcard $(MAIN.in/)*/*/*.pod )) )
37 MAIN.html.pod.out = $(MAIN.html.pod.in:%.pod=$(MAIN.html/)%.html)
38
39 MAIN.html.files   = $(MAIN.html.cp.out) \
40                     $(MAIN.html.pod.out)
41
42 MAIN.man/    = $(MAIN.out/)man/man1/
43 MAIN.man.in  = $(sort $(wildcard $(MAIN.in/)*.pod     )) \
44                $(sort $(wildcard $(MAIN.in/)*/*.pod   )) \
45                $(sort $(wildcard $(MAIN.in/)*/*/*.pod ))
46 MAIN.man.out = $(patsubst %.pod,$(MAIN.man/)%.1,$(notdir $(MAIN.man.in)))
47
48 MAIN.ps/     = $(MAIN.out/)ps/
49 MAIN.ps.out  = $(patsubst %.1,$(MAIN.ps/)%.ps,$(notdir $(MAIN.man.out)))
50
51 MAIN.pdf/    = $(MAIN.out/)pdf/
52 MAIN.pdf.out = $(patsubst %.1,$(MAIN.pdf/)%.pdf,$(notdir $(MAIN.man.out)))
53
54 MAIN.files += $(MAIN.html.tar)
55 MAIN.files += $(MAIN.html.cp.out)
56 MAIN.files += $(MAIN.html.pod.out)
57 MAIN.files += $(MAIN.man.out)
58 MAIN.files += $(MAIN.ps.out)
59 MAIN.files += $(MAIN.pdf.out)
60
61 DOCS.mkdir.files += $(MAIN.files)
62
63 ##===----------------------------------------------------------------------===##
64
65 INSTALL.out/     = $(PROJ_prefix)/share/
66 INSTALL.doc/     = $(INSTALL.out/)doc/$(MAIN.project)/
67
68 INSTALL.html/    = $(INSTALL.doc/)html/
69 INSTALL.html.tar = $(INSTALL.doc/)$(notdir $(MAIN.html.tar))
70 INSTALL.html.out = $(MAIN.html.files:$(MAIN.html/)%=$(INSTALL.html/)%)
71
72 INSTALL.man/     = $(PROJ_mandir)/man1/
73 INSTALL.man.out  = $(MAIN.man.out:$(MAIN.man/)%=$(INSTALL.man/)%)
74
75 INSTALL.ps/      = $(INSTALL.doc/)ps/
76 INSTALL.ps.out   = $(MAIN.ps.out:$(MAIN.ps/)%=$(INSTALL.ps/)%)
77
78 INSTALL.pdf/     = $(INSTALL.doc/)pdf/
79 INSTALL.pdf.out  = $(MAIN.pdf.out:$(MAIN.pdf/)%=$(INSTALL.pdf/)%)
80
81 INSTALL.files += $(INSTALL.html.tar)
82 INSTALL.files += $(INSTALL.html.out)
83 INSTALL.files += $(INSTALL.man.out)
84 INSTALL.files += $(INSTALL.ps.out)
85 INSTALL.files += $(INSTALL.pdf.out)
86
87 DOCS.mkdir.files += $(INSTALL.out/)file-placebo
88 DOCS.mkdir.files += $(INSTALL.files)
89
90 ##===----------------------------------------------------------------------===##
91
92 clean-local::
93         -$(Verb) $(RM) -f $(MAIN.files)
94
95 all:: docs docs-tar
96 install-local:: install-docs
97 uninstall-local:: uninstall-docs
98
99 ##===----------------------------------------------------------------------===##
100
101 .PHONY: docs-tar
102 docs-tar: $(MAIN.html.tar)
103
104 .PHONY: docs
105 docs: $(MAIN.html.files)
106 docs: $(MAIN.man.out)
107 ifneq (,$(GROFF))
108 docs: $(MAIN.ps.out)
109 endif
110 ifneq (,$(PDFROFF))
111 docs: $(MAIN.pdf.out)
112 endif
113
114 $(MAIN.html.tar): | $(dir $(MAIN.html.tar))
115 $(MAIN.html.tar): $(MAIN.html.files)
116         $(Echo) Creating $(MAIN.Project) MAIN documentation tarball
117         $(Verb) (set -e; cd $(MAIN.out/); $(TAR) cf - html) \
118         $(call fn.PIPE.COMP,$@) > $@
119
120 $(MAIN.html.cp.out): | $(dir $(MAIN.html.cp.out))
121 $(MAIN.html.cp.out): $(MAIN.html/)%: %
122         $(Echo) Copying to $(@:$(PROJ_OBJ_ROOT)/%=%)
123         $(Verb) $(CP) $< $@
124
125 $(MAIN.html.pod.out): | $(dir $(MAIN.html.pod.out))
126 $(MAIN.html.pod.out): $(MAIN.html/)%.html: %.pod
127         $(Echo) Converting pod to $(@:$(PROJ_OBJ_ROOT)/%=%)
128         $(Verb) $(CAT) $< | (set -e; cd $(MAIN.in/); $(POD2HTML) --title=$(*F) \
129           --noindex --css=manpage.css \
130           --htmlroot=. --podpath=. --podroot=$(<D)) > $@
131
132 $(MAIN.man.out): | $(dir $(MAIN.man.out))
133 $(MAIN.man.out): $(MAIN.man/)%.1: %.pod
134         $(Echo) Converting pod to $(@:$(PROJ_OBJ_ROOT)/%=%)
135         $(Verb) $(POD2MAN) --release=$(PROJ_VERSION) --center="$(MAIN.man.center)" $< $@
136
137 $(MAIN.ps.out): | $(dir $(MAIN.ps.out))
138 $(MAIN.ps.out): $(MAIN.ps/)%.ps: $(MAIN.man/)%.1
139         $(Echo) Converting man to $(@:$(PROJ_OBJ_ROOT)/%=%)
140         $(Verb) $(GROFF) -Tps -man $< > $@
141
142 $(MAIN.pdf.out): | $(dir $(MAIN.pdf.out))
143 $(MAIN.pdf.out): $(MAIN.pdf/)%.pdf: $(MAIN.man/)%.1
144         $(Echo) Converting man to $(@:$(PROJ_OBJ_ROOT)/%=%)
145         $(Verb) $(PDFROFF) -man --no-toc-relocation $< > $@
146
147 # Mapping of src pod files is not always direct so we need a search vpath.
148 # This solution works because no man page filenames (without dir) collide.
149 vpath %.pod $(sort $(dir $(MAIN.man.in)))
150
151 ##===----------------------------------------------------------------------===##
152
153 .PHONY: install-docs
154 install-docs: $(INSTALL.html.tar)
155 install-docs: $(INSTALL.html.out)
156 install-docs: $(INSTALL.man.out)
157 ifneq (,$(GROFF))
158 install-docs: $(INSTALL.ps.out)
159 endif
160 ifneq (,$(PDFROFF))
161 install-docs: $(INSTALL.pdf.out)
162 endif
163
164 $(INSTALL.html.tar): | $(dir $(INSTALL.html.tar))
165 $(INSTALL.html.tar): $(MAIN.html.tar)
166         $(Echo) Installing $(MAIN.Project) MAIN documentation tarball
167         $(Verb) $(DataInstall) $< $@
168
169 $(INSTALL.html.out): | $(dir $(INSTALL.html.out))
170 $(INSTALL.html.out): $(INSTALL.html/)%: $(MAIN.html/)%
171         $(Echo) Installing $(@:$(INSTALL.out/)%=%)
172         $(Verb) $(DataInstall) $< $@
173
174 $(INSTALL.man.out): | $(dir $(INSTALL.man.out))
175 $(INSTALL.man.out): $(INSTALL.man/)%: $(MAIN.man/)%
176         $(Echo) Installing $(@:$(INSTALL.out/)%=%)
177         $(Verb) $(DataInstall) $< $@
178
179 $(INSTALL.ps.out): | $(dir $(INSTALL.ps.out))
180 $(INSTALL.ps.out): $(INSTALL.ps/)%: $(MAIN.ps/)%
181         $(Echo) Installing $(@:$(INSTALL.out/)%=%)
182         $(Verb) $(DataInstall) $< $@
183
184 $(INSTALL.pdf.out): | $(dir $(INSTALL.pdf.out))
185 $(INSTALL.pdf.out): $(INSTALL.pdf/)%: $(MAIN.pdf/)%
186         $(Echo) Installing $(@:$(INSTALL.out/)%=%)
187         $(Verb) $(DataInstall) $< $@
188
189 uninstall-docs:
190         $(Echo) Uninstalling $(MAIN.Project) MAIN documentation
191         -$(Verb) $(RM) -f $(INSTALL.files)
192
193 ##===----------------------------------------------------------------------===##
194
195 DOCS.vars.mandatory += MAIN.Project MAIN.project MAIN.man.center
196 DOCS.vars.print     += $(sort $(filter INSTALL.%/,$(.VARIABLES)))
197
198 HELP.sections += MAIN.help
199
200 define MAIN.help
201   MAIN Documentation Module. This module is objdir build-friendly.
202
203   ------------------------------------------------------------------------------
204   TARGET          NOTES
205   ------------------------------------------------------------------------------
206  *all             invokes target docs
207  *install         invokes target install-docs
208  *uninstall       invokes target uninstall-docs
209   ------------------------------------------------------------------------------
210   docs            copy MAIN docs from
211                   $(MAIN.in/)
212                   with extensions { $(MAIN.html.cp.ext) }
213
214                   and perform conversions:
215
216                   FROM     TO    DESTINATION
217                   --------------------------------------------------------------
218                   html ->  html  $(MAIN.html/)
219                   pod  ->  man   $(MAIN.man/)
220                   man  ->  ps    $(MAIN.ps/)
221                   man  ->  pdf   $(MAIN.pdf/)
222   ------------------------------------------------------------------------------
223   docs-tar        create docs tarball $(MAIN.html.tar)
224   clean           remove built files
225   install-docs    install MAIN docs:
226
227                   FROM     TO    DESTINATION
228                   --------------------------------------------------------------
229                   html ->  html  $(INSTALL.html/)
230                   pod  ->  man   $(INSTALL.man/)
231                   man  ->  ps    $(INSTALL.ps/)
232                   man  ->  pdf   $(INSTALL.pdf/)
233   ------------------------------------------------------------------------------
234   uninstall-docs  remove installed files
235   ------------------------------------------------------------------------------
236   (targets marked with '*' require configure --enable-doxygen)
237 endef
238
239 include $(LLVM_SRC_ROOT)/docs/mk/common.rules.mk