]> git.ipfire.org Git - thirdparty/man-pages.git/blob - Makefile
Makefile: Add -t to GROFFFLAGS to run tbl(1)
[thirdparty/man-pages.git] / Makefile
1 ########################################################################
2 # Copyright (C) 2021 Alejandro Colomar <alx.manpages@gmail.com>
3 # SPDX-License-Identifier: GPL-2.0 OR LGPL-2.0
4 ########################################################################
5 # Conventions:
6 #
7 # - Follow "Makefile Conventions" from the "GNU Coding Standards" closely.
8 # However, when something could be improved, don't follow those.
9 # - Uppercase variables, when referring files, refer to files in this repo,
10 # or temporary files produced in $builddir.
11 # - Lowercase variables, when referring files, refer to system files.
12 # - Variables starting with '_' refer to absolute paths, including $(DESTDIR).
13 # - Variables ending with '_' refer to a subdir of their parent dir, which
14 # is in a variable of the same name but without the '_'. The subdir is
15 # named after this project: <*/man>.
16 # - Variables ending in '_rm' refer to files that can be removed (exist).
17 # - Variables ending in '_rmdir' refer to dirs that can be removed (exist).
18 # - Targets of the form '%-rm' remove their corresponding file '%'.
19 # - Targets of the form '%/.-rmdir' remove their corresponding dir '%/'.
20 # - Targets of the form '%/.' create their corresponding directory '%/'.
21 # - Every file or directory to be created depends on its parent directory.
22 # This avoids race conditions caused by `mkdir -p`. Only the root
23 # directories are created with parents.
24 # - The 'FORCE' target is used to make phony some variables that can't be
25 # .PHONY to avoid some optimizations.
26 #
27 ########################################################################
28
29 MAKEFLAGS += --no-print-directory
30 MAKEFLAGS += --warn-undefined-variables
31
32
33 srcdir := .
34 builddir := tmp
35 LINTDIR := $(builddir)/lint
36 HTMLDIR := $(builddir)/html
37
38 DESTDIR :=
39 prefix := /usr/local
40 SYSCONFDIR := $(srcdir)/etc
41 TMACDIR := $(SYSCONFDIR)/groff/tmac
42 datarootdir := $(prefix)/share
43 docdir := $(datarootdir)/doc
44 MANDIR := $(srcdir)
45 mandir := $(datarootdir)/man
46 MAN0DIR := $(MANDIR)/man0
47 MAN1DIR := $(MANDIR)/man1
48 MAN2DIR := $(MANDIR)/man2
49 MAN3DIR := $(MANDIR)/man3
50 MAN4DIR := $(MANDIR)/man4
51 MAN5DIR := $(MANDIR)/man5
52 MAN6DIR := $(MANDIR)/man6
53 MAN7DIR := $(MANDIR)/man7
54 MAN8DIR := $(MANDIR)/man8
55 man0dir := $(mandir)/man0
56 man1dir := $(mandir)/man1
57 man2dir := $(mandir)/man2
58 man3dir := $(mandir)/man3
59 man4dir := $(mandir)/man4
60 man5dir := $(mandir)/man5
61 man6dir := $(mandir)/man6
62 man7dir := $(mandir)/man7
63 man8dir := $(mandir)/man8
64 manext := \.[0-9]
65 man0ext := .0
66 man1ext := .1
67 man2ext := .2
68 man3ext := .3
69 man4ext := .4
70 man5ext := .5
71 man6ext := .6
72 man7ext := .7
73 man8ext := .8
74 htmldir := $(docdir)
75 htmldir_ := $(htmldir)/man
76 htmlext := .html
77
78 TMACFILES := $(sort $(shell find $(TMACDIR) -not -type d))
79 TMACNAMES := $(basename $(notdir $(TMACFILES)))
80 GROFF_CHECKSTYLE_LVL := 3
81 DEFAULT_GROFFFLAGS := -man
82 DEFAULT_GROFFFLAGS += -t
83 DEFAULT_GROFFFLAGS += -M $(TMACDIR)
84 DEFAULT_GROFFFLAGS += $(foreach x,$(TMACNAMES),-m $(x))
85 DEFAULT_GROFFFLAGS += -rCHECKSTYLE=$(GROFF_CHECKSTYLE_LVL)
86 EXTRA_GROFFFLAGS :=
87 GROFFFLAGS := $(DEFAULT_GROFFFLAGS) $(EXTRA_GROFFFLAGS)
88
89 DEFAULT_MAN2HTMLFLAGS :=
90 EXTRA_MAN2HTMLFLAGS :=
91 MAN2HTMLFLAGS := $(DEFAULT_MAN2HTMLFLAGS) $(EXTRA_MAN2HTMLFLAGS)
92
93 INSTALL := install
94 INSTALL_DATA := $(INSTALL) -m 644
95 INSTALL_DIR := $(INSTALL) -m 755 -d
96 RM := rm
97 RMDIR := rmdir --ignore-fail-on-non-empty
98 GROFF := groff
99 MAN2HTML := man2html
100
101 MAN_SECTIONS := 0 1 2 3 4 5 6 7 8
102
103
104 .PHONY: all
105 all:
106 $(MAKE) uninstall
107 $(MAKE) install
108
109
110 %/.:
111 $(info INSTALL $(@D)/)
112 $(INSTALL_DIR) $(@D)
113
114 %-rm:
115 $(info RM $*)
116 $(RM) $*
117
118 %-rmdir:
119 $(info RMDIR $(@D))
120 $(RMDIR) $(@D)
121
122
123 .PHONY: install
124 install: install-man | installdirs
125 @:
126
127 .PHONY: installdirs
128 installdirs: | installdirs-man
129 @:
130
131 .PHONY: uninstall remove
132 uninstall remove: uninstall-man
133 @:
134
135 .PHONY: clean
136 clean:
137 $(RM) -rf $(builddir)
138
139 ########################################################################
140 # man
141
142 MANPAGES := $(sort $(shell find $(MANDIR)/man?/ -type f | grep '$(manext)$$'))
143 HTMLPAGES := $(patsubst $(MANDIR)/%,$(HTMLDIR)/%.html,$(MANPAGES))
144 _htmlpages := $(patsubst $(HTMLDIR)/%,$(DESTDIR)$(htmldir_)/%,$(HTMLPAGES))
145 _manpages := $(patsubst $(MANDIR)/%,$(DESTDIR)$(mandir)/%,$(MANPAGES))
146 _man0pages := $(filter %$(man0ext),$(_manpages))
147 _man1pages := $(filter %$(man1ext),$(_manpages))
148 _man2pages := $(filter %$(man2ext),$(_manpages))
149 _man3pages := $(filter %$(man3ext),$(_manpages))
150 _man4pages := $(filter %$(man4ext),$(_manpages))
151 _man5pages := $(filter %$(man5ext),$(_manpages))
152 _man6pages := $(filter %$(man6ext),$(_manpages))
153 _man7pages := $(filter %$(man7ext),$(_manpages))
154 _man8pages := $(filter %$(man8ext),$(_manpages))
155 LINT_groff := $(patsubst $(MANDIR)/%,$(LINTDIR)/%.lint.groff.touch,$(MANPAGES))
156
157 MANDIRS := $(sort $(shell find $(MANDIR)/man? -type d))
158 HTMLDIRS := $(patsubst $(MANDIR)/%,$(HTMLDIR)/%/.,$(MANDIRS))
159 LINTDIRS := $(patsubst $(MANDIR)/%,$(LINTDIR)/%/.,$(MANDIRS))
160 _htmldirs := $(patsubst $(HTMLDIR)/%,$(DESTDIR)$(htmldir_)/%,$(HTMLDIRS))
161 _mandirs := $(patsubst $(MANDIR)/%,$(DESTDIR)$(mandir)/%/.,$(MANDIRS))
162 _man0dir := $(filter %man0/.,$(_mandirs))
163 _man1dir := $(filter %man1/.,$(_mandirs))
164 _man2dir := $(filter %man2/.,$(_mandirs))
165 _man3dir := $(filter %man3/.,$(_mandirs))
166 _man4dir := $(filter %man4/.,$(_mandirs))
167 _man5dir := $(filter %man5/.,$(_mandirs))
168 _man6dir := $(filter %man6/.,$(_mandirs))
169 _man7dir := $(filter %man7/.,$(_mandirs))
170 _man8dir := $(filter %man8/.,$(_mandirs))
171 _mandir := $(DESTDIR)$(mandir)/.
172 _htmldir := $(DESTDIR)$(htmldir_)/.
173
174 _htmlpages_rm := $(addsuffix -rm,$(wildcard $(_htmlpages)))
175 _manpages_rm := $(addsuffix -rm,$(wildcard $(_manpages)))
176 _man0pages_rm := $(filter %$(man0ext)-rm,$(_manpages_rm))
177 _man1pages_rm := $(filter %$(man1ext)-rm,$(_manpages_rm))
178 _man2pages_rm := $(filter %$(man2ext)-rm,$(_manpages_rm))
179 _man3pages_rm := $(filter %$(man3ext)-rm,$(_manpages_rm))
180 _man4pages_rm := $(filter %$(man4ext)-rm,$(_manpages_rm))
181 _man5pages_rm := $(filter %$(man5ext)-rm,$(_manpages_rm))
182 _man6pages_rm := $(filter %$(man6ext)-rm,$(_manpages_rm))
183 _man7pages_rm := $(filter %$(man7ext)-rm,$(_manpages_rm))
184 _man8pages_rm := $(filter %$(man8ext)-rm,$(_manpages_rm))
185
186 _htmldirs_rmdir := $(addsuffix -rmdir,$(wildcard $(_htmldirs)))
187 _mandirs_rmdir := $(addsuffix -rmdir,$(wildcard $(_mandirs)))
188 _man0dir_rmdir := $(addsuffix -rmdir,$(wildcard $(_man0dir)))
189 _man1dir_rmdir := $(addsuffix -rmdir,$(wildcard $(_man1dir)))
190 _man2dir_rmdir := $(addsuffix -rmdir,$(wildcard $(_man2dir)))
191 _man3dir_rmdir := $(addsuffix -rmdir,$(wildcard $(_man3dir)))
192 _man4dir_rmdir := $(addsuffix -rmdir,$(wildcard $(_man4dir)))
193 _man5dir_rmdir := $(addsuffix -rmdir,$(wildcard $(_man5dir)))
194 _man6dir_rmdir := $(addsuffix -rmdir,$(wildcard $(_man6dir)))
195 _man7dir_rmdir := $(addsuffix -rmdir,$(wildcard $(_man7dir)))
196 _man8dir_rmdir := $(addsuffix -rmdir,$(wildcard $(_man8dir)))
197 _mandir_rmdir := $(addsuffix -rmdir,$(wildcard $(_mandir)))
198 _htmldir_rmdir := $(addsuffix -rmdir,$(wildcard $(_htmldir)))
199
200 install_manX := $(foreach x,$(MAN_SECTIONS),install-man$(x))
201 installdirs_manX := $(foreach x,$(MAN_SECTIONS),installdirs-man$(x))
202 uninstall_manX := $(foreach x,$(MAN_SECTIONS),uninstall-man$(x))
203
204
205 .SECONDEXPANSION:
206 $(_manpages): $(DESTDIR)$(mandir)/man%: $(MANDIR)/man% | $$(@D)/.
207 $(info INSTALL $@)
208 $(INSTALL_DATA) -T $< $@
209
210 $(_mandirs): %/.: | $$(dir %). $(_mandir)
211
212 $(_mandirs_rmdir): $(DESTDIR)$(mandir)/man%/.-rmdir: $$(_man%pages_rm) FORCE
213 $(_mandir_rmdir): $(uninstall_manX) FORCE
214
215
216 .PHONY: $(install_manX)
217 $(install_manX): install-man%: $$(_man%pages) | installdirs-man%
218 @:
219
220 .PHONY: install-man
221 install-man: $(install_manX)
222 @:
223
224 .PHONY: $(installdirs_manX)
225 $(installdirs_manX): installdirs-man%: $$(_man%dir)
226 @:
227
228 .PHONY: installdirs-man
229 installdirs-man: $(installdirs_manX)
230 @:
231
232 .PHONY: $(uninstall_manX)
233 $(uninstall_manX): uninstall-man%: $$(_man%pages_rm) $$(_man%dir_rmdir)
234 @:
235
236 .PHONY: uninstall-man
237 uninstall-man: $(_mandir_rmdir) $(uninstall_manX)
238 @:
239
240
241 ########################################################################
242 # lint
243
244 linters := groff
245 lint := $(foreach x,$(linters),lint-$(x))
246
247 $(LINT_groff): $(LINTDIR)/%.lint.groff.touch: $(MANDIR)/% | $$(@D)/.
248 $(info LINT (groff) $@)
249 $(GROFF) $(GROFFFLAGS) -z $<
250 touch $@
251
252 $(LINTDIRS): %/.: | $$(dir %). $(LINTDIR)/.
253
254 .PHONY: lint-groff
255 lint-groff: $(LINT_groff) | lintdirs
256 @:
257
258 .PHONY: lintdirs
259 lintdirs: $(LINTDIRS)
260 @:
261
262 .PHONY: lint
263 lint: $(lint)
264 @:
265
266
267 ########################################################################
268 # html
269
270 # Use with
271 # make MAN2HTMLFLAGS=whatever html
272 # The sed removes the lines "Content-type: text/html\n\n"
273 $(HTMLPAGES): $(HTMLDIR)/%.html: $(MANDIR)/% | $$(@D)/.
274 $(info MAN2HTML $@)
275 $(MAN2HTML) $(MAN2HTMLFLAGS) $< | sed -e 1,2d >$@ || exit $$?
276
277 $(HTMLDIRS): %/.: | $$(dir %). $(HTMLDIR)/.
278
279 $(_htmlpages): $(DESTDIR)$(htmldir_)/%: $(HTMLDIR)/% | $$(@D)/.
280 $(info INSTALL $@)
281 $(INSTALL_DATA) -T $< $@
282
283 $(_htmldirs): %/.: | $$(dir %). $(_htmldir)
284
285
286 .PHONY: build-html html
287 build-html html: $(HTMLPAGES) | builddirs-html
288 @:
289
290 .PHONY: builddirs-html
291 builddirs-html: $(HTMLDIRS)
292 @:
293
294 .PHONY: install-html
295 install-html: $(_htmlpages) | installdirs-html
296 @:
297
298 .PHONY: installdirs-html
299 installdirs-html: $(_htmldirs)
300 @:
301
302 .PHONY: uninstall-html
303 uninstall-html: $(_htmldir_rmdir) $(_htmldirs_rmdir) $(_htmlpages_rm)
304 @:
305
306
307 ########################################################################
308 # tests
309
310 # Check if groff reports warnings (may be words of sentences not displayed)
311 # from https://lintian.debian.org/tags/groff-message.html
312 .PHONY: check-groff-warnings
313 check-groff-warnings:
314 GROFF_LOG="$$(mktemp --tmpdir manpages-checksXXXX)" || exit $$?; \
315 for i in man?/*.[0-9]; \
316 do \
317 if grep -q 'SH.*NAME' "$$i"; then \
318 LC_ALL=en_US.UTF-8 MANWIDTH=80 man --warnings -E UTF-8 -l "$$i" > /dev/null 2>| "$$GROFF_LOG"; \
319 [ -s "$$GROFF_LOG" ] && { echo "$$i: "; cat "$$GROFF_LOG"; echo; }; \
320 fi; \
321 done; \
322 rm -f "$$GROFF_LOG"
323
324 # someone might also want to look at /var/catman/cat2 or so ...
325 # a problem is that the location of cat pages varies a lot
326
327 ########################################################################
328
329 $(V).SILENT:
330 FORCE: