1 ########################################################################
2 # Copyright (C) 2021 Alejandro Colomar <alx.manpages@gmail.com>
3 # SPDX-License-Identifier: GPL-2.0 OR LGPL-2.0
4 ########################################################################
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 # - Lowercase variables, when referring files, refer to system files.
11 # - Variables starting with '_' refer to absolute paths, including $(DESTDIR).
12 # - Variables ending with '_' refer to a subdir of their parent dir, which
13 # is in a variable of the same name but without the '_'. The subdir is
14 # named after this project: <*/man>.
15 # - Variables ending in '_rm' refer to files that can be removed (exist).
16 # - Variables ending in '_rmdir' refer to dirs that can be removed (exist).
17 # - Targets of the form '%-rm' remove their corresponding file '%'.
18 # - Targets of the form '%/.-rmdir' remove their corresponding dir '%/'.
19 # - Targets of the form '%/.' create their corresponding directory '%/'.
20 # - Every file or directory to be created depends on its parent directory.
21 # This avoids race conditions caused by `mkdir -p`. Only the root
22 # directories are created with parents.
23 # - The 'FORCE' target is used to make phony some variables that can't be
24 # .PHONY to avoid some optimizations.
26 ########################################################################
28 MAKEFLAGS
+= --no-print-directory
30 MAKEFLAGS
+= --warn-undefined-variables
33 htmlbuilddir
:= $(CURDIR
)/.html
38 datarootdir
:= $(prefix)/share
39 docdir
:= $(datarootdir
)/doc
41 mandir := $(datarootdir
)/man
42 MAN1DIR
:= $(MANDIR
)/man1
43 MAN2DIR
:= $(MANDIR
)/man2
44 MAN3DIR
:= $(MANDIR
)/man3
45 MAN4DIR
:= $(MANDIR
)/man4
46 MAN5DIR
:= $(MANDIR
)/man5
47 MAN6DIR
:= $(MANDIR
)/man6
48 MAN7DIR
:= $(MANDIR
)/man7
49 MAN8DIR
:= $(MANDIR
)/man8
50 man1dir := $(mandir)/man1
51 man2dir := $(mandir)/man2
52 man3dir := $(mandir)/man3
53 man4dir := $(mandir)/man4
54 man5dir := $(mandir)/man5
55 man6dir := $(mandir)/man6
56 man7dir := $(mandir)/man7
57 man8dir := $(mandir)/man8
68 htmldir_
:= $(htmldir
)/man
72 INSTALL_DATA
:= $(INSTALL
) -m
644
73 INSTALL_DIR
:= $(INSTALL
) -m
755 -d
75 RMDIR
:= rmdir
--ignore-fail-on-non-empty
77 MAN_SECTIONS
:= 1 2 3 4 5 6 7 8
87 $(info - INSTALL
$(@D
))
100 install: install-man |
installdirs
104 installdirs: | installdirs-man
107 .PHONY
: uninstall remove
108 uninstall remove
: uninstall-man
115 rm -f
"$(htmlbuilddir)/$$f".
*; \
118 ########################################################################
121 MANPAGES
:= $(sort $(shell find
$(MANDIR
)/man?
/ -type f | grep
'$(manext)$$'))
122 _manpages
:= $(patsubst $(MANDIR
)/%,$(DESTDIR
)$(mandir)/%,$(MANPAGES
))
123 _man1pages
:= $(filter %$(man1ext),$(_manpages
))
124 _man2pages
:= $(filter %$(man2ext),$(_manpages
))
125 _man3pages
:= $(filter %$(man3ext),$(_manpages
))
126 _man4pages
:= $(filter %$(man4ext),$(_manpages
))
127 _man5pages
:= $(filter %$(man5ext),$(_manpages
))
128 _man6pages
:= $(filter %$(man6ext),$(_manpages
))
129 _man7pages
:= $(filter %$(man7ext),$(_manpages
))
130 _man8pages
:= $(filter %$(man8ext),$(_manpages
))
132 MANDIRS
:= $(sort $(shell find
$(MANDIR
)/man?
-type d
))
133 _mandirs
:= $(patsubst $(MANDIR
)/%,$(DESTDIR
)$(mandir)/%/.
,$(MANDIRS
))
134 _man1dir
:= $(filter %man1
/.
,$(_mandirs
))
135 _man2dir
:= $(filter %man2
/.
,$(_mandirs
))
136 _man3dir
:= $(filter %man3
/.
,$(_mandirs
))
137 _man4dir
:= $(filter %man4
/.
,$(_mandirs
))
138 _man5dir
:= $(filter %man5
/.
,$(_mandirs
))
139 _man6dir
:= $(filter %man6
/.
,$(_mandirs
))
140 _man7dir
:= $(filter %man7
/.
,$(_mandirs
))
141 _man8dir
:= $(filter %man8
/.
,$(_mandirs
))
142 _mandir
:= $(DESTDIR
)$(mandir)/.
144 _manpages_rm
:= $(addsuffix -rm,$(wildcard $(_manpages
)))
145 _man1pages_rm
:= $(filter %$(man1ext)-rm,$(_manpages_rm
))
146 _man2pages_rm
:= $(filter %$(man2ext)-rm,$(_manpages_rm
))
147 _man3pages_rm
:= $(filter %$(man3ext)-rm,$(_manpages_rm
))
148 _man4pages_rm
:= $(filter %$(man4ext)-rm,$(_manpages_rm
))
149 _man5pages_rm
:= $(filter %$(man5ext)-rm,$(_manpages_rm
))
150 _man6pages_rm
:= $(filter %$(man6ext)-rm,$(_manpages_rm
))
151 _man7pages_rm
:= $(filter %$(man7ext)-rm,$(_manpages_rm
))
152 _man8pages_rm
:= $(filter %$(man8ext)-rm,$(_manpages_rm
))
154 _mandirs_rmdir
:= $(addsuffix -rmdir
,$(wildcard $(_mandirs
)))
155 _man1dir_rmdir
:= $(addsuffix -rmdir
,$(wildcard $(_man1dir
)))
156 _man2dir_rmdir
:= $(addsuffix -rmdir
,$(wildcard $(_man2dir
)))
157 _man3dir_rmdir
:= $(addsuffix -rmdir
,$(wildcard $(_man3dir
)))
158 _man4dir_rmdir
:= $(addsuffix -rmdir
,$(wildcard $(_man4dir
)))
159 _man5dir_rmdir
:= $(addsuffix -rmdir
,$(wildcard $(_man5dir
)))
160 _man6dir_rmdir
:= $(addsuffix -rmdir
,$(wildcard $(_man6dir
)))
161 _man7dir_rmdir
:= $(addsuffix -rmdir
,$(wildcard $(_man7dir
)))
162 _man8dir_rmdir
:= $(addsuffix -rmdir
,$(wildcard $(_man8dir
)))
163 _mandir_rmdir
:= $(addsuffix -rmdir
,$(wildcard $(_mandir
)))
165 install_manX
:= $(foreach x
,$(MAN_SECTIONS
),install-man
$(x
))
166 installdirs_manX
:= $(foreach x
,$(MAN_SECTIONS
),installdirs-man
$(x
))
167 uninstall_manX
:= $(foreach x
,$(MAN_SECTIONS
),uninstall-man
$(x
))
171 $(_manpages
): $(DESTDIR
)$(mandir)/man
%: $(MANDIR
)/man
% |
$$(@D
)/.
173 $(INSTALL_DATA
) -T
$< $@
175 $(_mandirs
): %/.
: |
$$(dir %).
$(_mandir
)
177 $(_mandirs_rmdir
): $(DESTDIR
)$(mandir)/man
%/.
-rmdir
: $$(_man
%pages_rm
) FORCE
178 $(_mandir_rmdir
): $(uninstall_manX
) FORCE
181 .PHONY
: $(install_manX
)
182 $(install_manX
): install-man
%: $$(_man
%pages
) | installdirs-man
%
186 install-man
: $(install_manX
)
189 .PHONY
: $(installdirs_manX
)
190 $(installdirs_manX
): installdirs-man
%: $$(_man
%dir) $(_mandir
)
193 .PHONY
: installdirs-man
194 installdirs-man
: $(installdirs_manX
)
197 .PHONY
: $(uninstall_manX
)
198 $(uninstall_manX
): uninstall-man
%: $$(_man
%pages_rm
) $$(_man
%dir_rmdir
)
201 .PHONY
: uninstall-man
202 uninstall-man
: $(_mandir_rmdir
) $(uninstall_manX
)
206 ########################################################################
210 # make HTOPTS=whatever html
211 # The sed removes the lines "Content-type: text/html\n\n"
213 html
: | builddirs-html
216 man2html
$(HTOPTS
) "$$f" \
218 >"$(htmlbuilddir)/$${f}$(htmlext)" \
222 .PHONY
: builddirs-html
226 $(INSTALL_DIR
) "$(htmlbuilddir)/$$d" || exit
$$?
; \
230 install-html
: | installdirs-html
231 cd
$(htmlbuilddir
) && \
234 $(INSTALL_DATA
) -T
"$$f" "$(DESTDIR)$(htmldir_)/$$f" || exit
$$?
; \
237 .PHONY
: installdirs-html
241 $(INSTALL_DIR
) "$(DESTDIR)$(htmldir_)/$$d" || exit
$$?
; \
244 .PHONY
: uninstall-html
248 rm -f
"$(DESTDIR)$(htmldir_)/$$f".
* || exit
$$?
; \
252 ########################################################################
255 # Check if groff reports warnings (may be words of sentences not displayed)
256 # from https://lintian.debian.org/tags/groff-message.html
257 .PHONY
: check-groff-warnings
258 check-groff-warnings
:
259 GROFF_LOG
="$$(mktemp --tmpdir manpages-checksXXXX)" || exit
$$?
; \
260 for i in man?
/*.
[1-9]; \
262 if grep
-q
'SH.*NAME' "$$i"; then \
263 LC_ALL
=en_US.UTF-8 MANWIDTH
=80 man
--warnings
-E UTF-8
-l
"$$i" > /dev
/null
2>|
"$$GROFF_LOG"; \
264 [ -s
"$$GROFF_LOG" ] && { echo
"$$i: "; cat
"$$GROFF_LOG"; echo
; }; \
269 # someone might also want to look at /var/catman/cat2 or so ...
270 # a problem is that the location of cat pages varies a lot
272 ########################################################################