Debian Codegraph @

api_docgen/odoc/Makefile

raw symbols SCIP
1 #**************************************************************************
2 #* *
3 #* OCaml *
4 #* *
5 #* Florian Angeletti, projet Cambium, Inria Paris *
6 #* *
7 #* Copyright 2020 Institut National de Recherche en Informatique et *
8 #* en Automatique. *
9 #* *
10 #* All rights reserved. This file is distributed under the terms of *
11 #* the GNU Lesser General Public License version 2.1, with the *
12 #* special exception on linking described in the file LICENSE. *
13 #* *
14 #**************************************************************************
15
16 # Used by included Makefiles
17 ROOTDIR = ../..
18
19 include ../Makefile.common
20
21 vpath %.cmti ../../stdlib $(DOC_COMPILERLIBS_DIRS) $(DOC_STDLIB_DIRS)
22 vpath %.cmt ../../stdlib
23
24 ifeq ($(DOCUMENTATION_TOOL),odoc)
25 odoc ?= $(DOCUMENTATION_TOOL_CMD)
26 else
27 odoc ?= odoc
28 endif
29
30 libref = $(STDLIB) $(otherlibref)
31
32 # odoc needs a "page-" prefix for a mld documentation file
33 define page_name
34 $(dir $1)page-$(notdir $1)
35 endef
36
37 define stdlib_prefix
38 $(if $(filter-out stdlib camlinternal%,$1),\
39 Stdlib.$(call capitalize,$1),\
40 $(call capitalize, $1))
41 endef
42
43 # define the right conditional for the manual
44 build/latex/ifocamldoc.tex: | build/latex
45 $(V_GEN)printf '\\newif\\ifocamldoc\\ocamldocfalse\n' > $@
46
47
48 # \input{} all modules in the stdlib for the latex api manual
49 stdlib_INPUT= $(foreach module,\
50 $(filter-out stdlib camlinternal%, $(STDLIB:stdlib__%=%)),\
51 \\input{libref/Stdlib.$(call capitalize,$(module)).tex}\
52 )
53
54 build/latex/stdlib_input.tex: | build/latex
55 $(V_GEN)echo $(stdlib_INPUT)> $@
56
57 build/latex/compilerlibs_input.tex: | build/latex
58 $(V_GEN)echo $(compilerlibref_C:%=\\input{compilerlibref/%})> $@
59
60 # The build process for odoc has 3 phases:
61 # 1. generation of internal individual documentation files (.odoc)
62 # 2. generation of linked documentation files (.odocl)
63 # 3. generation of the actual (.tex,.html,.3o) documentation
64
65 # rules for the mld files
66 $(libref_TEXT:%=build/libref/page-%.odoc):
67 build/libref/page-%.odoc: build/%.mld | build/libref
68 $(V_ODOC)$(odoc) compile -I build/libref --package libref $< -o $@
69
70 $(compilerlibref_TEXT:%=build/compilerlibref/page-%.odoc):\
71 build/compilerlibref/page-%.odoc: build/%.mld | build/compilerlibref
72 $(V_ODOC)$(odoc) compile -I build/libref --package compilerlibref $< -o $@
73
74 # rules for the stdlib and otherlibs .doc files
75 $(libref:%=build/libref/%.odoc):\
76 build/libref/%.odoc: %.cmti | build/libref
77 $(V_ODOC)$(odoc) compile -I build/libref --package libref $< -o $@
78
79 # pervasives is handled separately due to the lack of cmti file
80 $(libref_EXTRA:%=build/libref/%.odoc):build/libref/%.odoc:%.cmt
81 $(V_ODOC)$(odoc) compile -I build/libref --package libref $< -o $@
82
83 # rules for the compilerlib documentation
84 $(compilerlibref:%=build/compilerlibref/%.odoc):\
85 build/compilerlibref/%.odoc: %.cmti $(libref:%=build/libref/%.odoc) \
86 | build/compilerlibref
87 $(V_ODOC)$(odoc) compile -I build/libref -I build/compilerlibref \
88 --package compilerlibref $< -o $@
89
90 ALL_TEXT = $(libref_TEXT:%=libref/%) $(compilerlibref_TEXT:%=compilerlibref/%)
91 ALL_PAGE_TEXT=$(foreach mld,$(ALL_TEXT),$(call page_name,$(mld)))
92 TARGET_UNITS= \
93 $(compilerlibref:%=compilerlibref/%) \
94 libref/stdlib $(otherlibref:%=libref/%) \
95 $(addprefix libref/,$(filter camlinternal%,$(STDLIB)))
96 ALL_UNITS = $(compilerlibref:%=compilerlibref/%) $(libref:%=libref/%)
97 ALL_PAGED_DOC = $(TARGET_UNITS) $(ALL_PAGE_TEXT)
98
99 # rules for odocl generation
100 # Note that we are using a dependency on the whole phase 1 rather than tracking
101 # the individual file dependencies
102 %.odocl:%.odoc \
103 | $(ALL_PAGED_DOC:%=build/%.odoc)
104 $(V_ODOC)$(odoc) link -I build/libref -I build/compilerlibref $(ODOC_LINK_ARGS) $<
105
106 %.odocl:%.odoc \
107 | $(ALL_PAGED_DOC:%=build/%.odoc)
108 $(V_ODOC)$(odoc) link -I build/libref -I build/compilerlibref $(ODOC_LINK_ARGS) $<
109
110 build/libref/stdlib.odocl: ODOC_LINK_ARGS+=--open=""
111
112 # Rules for all three backends:
113
114 ALL_HTML = $(ALL_PAGED_DOC:%=build/%.html.stamp)
115 ALL_MAN = $(ALL_PAGED_DOC:%=build/%.3o.stamp)
116 ALL_LATEX = $(ALL_PAGED_DOC:%=build/%.tex.stamp)
117
118 build/libref/stdlib.html.stamp: $(STDLIB:%=build/libref/%.odocl) | build/libref
119 build/libref/stdlib.3o.stamp: $(STDLIB:%=build/libref/%.odocl) | build/libref
120 build/libref/stdlib.tex.stamp: $(STDLIB:%=build/libref/%.odocl) | build/libref
121
122 man: $(ALL_MAN)
123 html: $(ALL_HTML) build/html/odoc.css
124 html: build/libref/index.html.stamp build/compilerlibref/index.html.stamp
125
126 # Html rules
127 $(ALL_HTML): %.html.stamp: %.odocl | build/html
128 $(V_ODOC)$(odoc) html-generate --output-dir build/html $<
129 touch $@
130
131 build/html/odoc.css: | build/html
132 $(V_ODOC)$(odoc) support-files --output-dir build/html
133
134 $(build/libref.html.stamp build/compilerlibref.html.stamp):
135 %.html.stamp: %.mld | build/
136 $(V_ODOC)$(odoc) html-generate --output-dir build/html $<
137 touch $@
138
139 # Html indexes for the api documentation
140
141 # The stdlib index is generated from the list of stdlib modules.
142 stdlib_INDEX=\
143 $(foreach m,$(stdlib_UNPREFIXED),$(call stdlib_prefix,$m))\
144 $(call capitalize, $(otherlibref))
145 build/libref.mld:
146 ( echo "{0 OCaml standard library}"; \
147 echo "{!modules:$(stdlib_INDEX)}" ) > $@
148
149 build/libref/index.html.stamp: $(ALL_HTML) build/libref.mld \
150 | build/libref build/html/libref
151 $(odoc) compile --package libref build/libref.mld
152 $(odoc) link -I build/libref build/page-libref.odoc
153 $(odoc) html-generate build/page-libref.odocl --output-dir build/html
154 mv build/html/libref/libref.html build/html/libref/index.html
155 touch $@
156
157 build/compilerlibref/index.html.stamp: $(ALL_HTML) \
158 build/compilerlibref/page-Compiler_libs.html.stamp | build/html/compilerlibref
159 cp build/html/compilerlibref/Compiler_libs.html \
160 build/html/compilerlibref/index.html
161 touch $@
162
163 # Latex rules
164
165 latex: $(ALL_LATEX)
166
167
168 build/latex/alldoc.pdf: $(ALL_LATEX) build/latex/alldoc.tex \
169 build/latex/stdlib_input.tex build/latex/compilerlibs_input.tex \
170 | build/latex
171 cd build/latex && pdflatex alldoc.tex
172 cd build/latex && pdflatex alldoc.tex
173
174 # We include children pages directly except for the root Stdlib module
175 NOT_STDLIB=$(filter-out libref/stdlib,$(ALL_PAGED_DOC))
176 $(NOT_STDLIB:%=build/%.tex.stamp):\
177 build/%.tex.stamp: build/%.odocl | build/
178 $(odoc) latex-generate --with-children=true --output-dir build/latex $<
179 touch $@
180
181 # Stdlib latex page: we manually integrate stdlib module
182 build/libref/stdlib.tex.stamp: build/libref/stdlib.odocl | build/libref
183 $(odoc) latex-generate --with-children=false --output-dir build/latex $<
184 touch $@
185
186 # Man pages
187 $(ALL_PAGED_DOC:%=build/%.3o.stamp):build/%.3o.stamp:build/%.odocl | build/
188 $(odoc) man-generate --output-dir build/man $<
189 touch $@
190
191 # Man pages are the only installed documentation
192 .PHONY: install
193 install:
194 $(MKDIR) "$(INSTALL_LIBRARIES_MAN_DIR)"
195 if test -d build/man/libref ; then \
196 $(INSTALL_DATA) build/man/libref/* "$(INSTALL_LIBRARIES_MAN_DIR)"; \
197 fi
198 if test -d build/man/compilerlibref ; then \
199 $(INSTALL_DATA) build/man/libref/* "$(INSTALL_LIBRARIES_MAN_DIR)"; \
200 fi
201
202 # Dependencies for stdlib modules.
203 # Use the same dependencies used for compiling .cmx files.
204 # The existing rules look like this:
205 # stdlib__X.cmx: x.ml \
206 # stdlib__Y.cmx \
207 # stdlib__X.cmi
208 # We want:
209 # build/libref/stdlib__X.odoc: \
210 # build/libref/stdlib__Y.odoc \
211 # stdlib__X.cmti
212 build/.depend: ../../stdlib/.depend | build/
213 sed \
214 -e ':l; /\\ *$$/ { N; bl }; # Read lines separated by \\' \
215 -e '/^\S*\.cmx *:/! d; # Keep only rules to .cmx' \
216 -e 's#\<\(\w*\)\.cmx\>#build/libref/\1.odoc#g; # .cmx -> .odoc' \
217 -e 's/\.cmi\>/.cmti/g; # .cmi -> .cmti' \
218 -e 's/\<\S*\.ml\>//g; # .ml -> removed' \
219 $< > $@
220
221 include build/.depend