bsd.man.mk revision 1.121 1 # $NetBSD: bsd.man.mk,v 1.121 2020/11/08 14:52:35 kamil Exp $
2 # @(#)bsd.man.mk 8.1 (Berkeley) 6/8/93
3
4 .include <bsd.init.mk>
5
6 ##### Basic targets
7 .PHONY: maninstall manpages manlinks
8 .PHONY: htmlinstall htmlpages htmllinks
9 .PHONY: lintmanpages
10 realinstall: ${MANINSTALL}
11
12 # If our install destination is case-preserving, but case-insensitive
13 # then we do filesystem comparisons in lower case to make sure that
14 # we always refresh the target when needed. In general we don't
15 # want to do this, otherwise things like _exit.2 -> _Exit.2 get
16 # installed on each build even when they don't need to. Note that
17 # the CASE_INSENSITIVE_DEST macro is currently not defined anywhere,
18 # and the expansion does not really work because of make(1).
19 .if defined(CASE_INSENSITIVE_DEST)
20 _FLATTEN?=tl:
21 .endif
22
23 ##### Default values
24 .if ${USETOOLS} == "yes"
25 TMACDEPDIR?= ${TOOLDIR}/share/groff/tmac
26 .else
27 TMACDEPDIR?= /usr/share/tmac
28 .endif
29
30 HTMLDIR?= ${DESTDIR}${MANDIR}
31
32 MAN?=
33 MLINKS?=
34 _MSECTIONS= 1 2 3 4 5 6 7 8 9
35 _MSECTIONS+= 3lua 9lua
36 _MSECTIONREGEX= ${_MSECTIONS:ts|} # e.g. 1|2|3|...
37 .SUFFIXES: ${_MSECTIONS:@N@.$N@}
38
39 .if ${MKMANZ} == "no"
40 MANCOMPRESS?=
41 MANSUFFIX?=
42 .else
43 MANCOMPRESS?= ${TOOL_GZIP_N} -cf
44 MANSUFFIX?= .gz
45 .endif
46
47 # make MANCOMPRESS a filter, so it can be inserted on an as-needed basis
48 .if !empty(MANCOMPRESS)
49 MANCOMPRESS:= | ${MANCOMPRESS}
50 .endif
51
52 __installpage: .USE
53 @cmp -s ${.ALLSRC} ${.TARGET} > /dev/null 2>&1 || \
54 (${_MKSHMSG_INSTALL} ${.TARGET}; \
55 ${_MKSHECHO} "${INSTALL_FILE} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} \
56 ${.ALLSRC} ${.TARGET}" && \
57 ${INSTALL_FILE} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} \
58 ${.ALLSRC} ${.TARGET})
59
60 # XXX consider including bsd.links.mk and using __linkinstall instead
61 __linkinstallpage: .USE
62 ${_MKSHMSG_INSTALL} ${.TARGET}; \
63 ${_MKSHECHO} "${INSTALL_LINK} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} \
64 ${.ALLSRC} ${.TARGET}" && \
65 ${INSTALL_LINK} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} \
66 ${.ALLSRC} ${.TARGET}
67
68 ##### Build and install rules (source form pages)
69
70 .if ${MKMAN} != "no"
71 maninstall: manpages manlinks
72 manpages:: # ensure target exists
73 MANPAGES= ${MAN:C/.$/&${MANSUFFIX}/}
74
75 realall: ${MANPAGES}
76 .if !empty(MANSUFFIX)
77 .NOPATH: ${MANPAGES}
78 .SUFFIXES: ${_MSECTIONS:@N@.$N${MANSUFFIX}@}
79
80 ${_MSECTIONS:@N@.$N.$N${MANSUFFIX}@}: # build rule
81 ${_MKTARGET_FORMAT}
82 cat ${.IMPSRC} ${MANCOMPRESS} > ${.TARGET}.tmp && ${MV} ${.TARGET}.tmp ${.TARGET}
83 .endif # !empty(MANSUFFIX)
84
85 .for F in ${MANPAGES:S/${MANSUFFIX}$//:O:u}
86 _F:= ${DESTDIR}${MANDIR}/man${F:T:E}${MANSUBDIR}/${F}${MANSUFFIX}
87
88 .if ${MKUPDATE} == "no"
89 ${_F}! ${F}${MANSUFFIX} __installpage # install rule
90 .if !defined(BUILD) && !make(all) && !make(${F})
91 ${_F}! .MADE # no build at install
92 .endif
93 .else
94 ${_F}: ${F}${MANSUFFIX} __installpage # install rule
95 .if !defined(BUILD) && !make(all) && !make(${F})
96 ${_F}: .MADE # no build at install
97 .endif
98 .endif
99
100 manpages:: ${_F}
101 .PRECIOUS: ${_F} # keep if install fails
102 .endfor
103
104 manlinks:: # link install
105
106 .for _src _dst in ${MLINKS}
107 _l:=${DESTDIR}${MANDIR}/man${_src:T:E}${MANSUBDIR}/${_src}${MANSUFFIX}
108 _t:=${DESTDIR}${MANDIR}/man${_dst:T:E}${MANSUBDIR}/${_dst}${MANSUFFIX}
109
110 # Handle case conflicts carefully, when _dst occurs
111 # more than once after case flattening
112 .if ${MKUPDATE} == "no" || ${MLINKS:${_FLATTEN}M${_dst:${_FLATTEN}Q}:[\#]} > 1
113 ${_t}! ${_l} __linkinstallpage
114 .else
115 ${_t}: ${_l} __linkinstallpage
116 .endif
117
118 manlinks:: ${_t}
119 .PRECIOUS: ${_t}
120 .endfor
121 .endif # ${MKMAN} != "no"
122
123 ##### Build and install rules (HTML pages)
124
125 .if (${MKHTML} != "no") && (${MKMAN} != "no") # {
126 htmlinstall: htmlpages htmllinks
127 htmlpages:: # ensure target exists
128 HTMLPAGES= ${MAN:C/\.(${_MSECTIONREGEX})\$/.html\1/}
129
130 HTMLLINKS= ${MANSUBDIR:?../:}../html%S/%N.html
131 HTMLSTYLE= ${MANSUBDIR:?../:}../style.css
132
133 realall: ${HTMLPAGES}
134 .NOPATH: ${HTMLPAGES}
135 .SUFFIXES: ${_MSECTIONS:@N@.html$N@}
136
137 ${_MSECTIONS:@N@.$N.html$N@}: # build rule
138 ${_MKTARGET_FORMAT}
139 .if ${MKMANDOC} == yes && !defined(NOMANDOC)
140 if test ""${NOMANDOC.${.IMPSRC:T}:tl:Q} != "yes"; then \
141 ${TOOL_MANDOC_HTML} -Oman=${HTMLLINKS},style=${HTMLSTYLE} \
142 ${.IMPSRC} > ${.TARGET}.tmp && \
143 ${MV} ${.TARGET}.tmp ${.TARGET}; \
144 else \
145 ${TOOL_ROFF_HTML} ${.IMPSRC} ${MANCOMPRESS} \
146 > ${.TARGET}.tmp && ${MV} ${.TARGET}.tmp ${.TARGET}; \
147 fi
148 .elif defined(USETBL)
149 ${TOOL_TBL} ${.IMPSRC} | ${TOOL_ROFF_HTML} ${MANCOMPRESS} \
150 > ${.TARGET}.tmp && ${MV} ${.TARGET}.tmp ${.TARGET}
151 .else
152 ${TOOL_ROFF_HTML} ${.IMPSRC} ${MANCOMPRESS} \
153 > ${.TARGET}.tmp && ${MV} ${.TARGET}.tmp ${.TARGET}
154 .endif
155
156 .for F in ${HTMLPAGES:O:u}
157 # construct installed path
158 _F:= ${HTMLDIR}/${F:T:E}${MANSUBDIR}/${F:R:S-/index$-/x&-}.html
159
160 .if ${MKUPDATE} == "no"
161 ${_F}! ${F} __installpage # install rule
162 .if !defined(BUILD) && !make(all) && !make(${F})
163 ${_F}! .MADE # no build at install
164 .endif
165 .else
166 ${_F}: ${F} __installpage # install rule
167 .if !defined(BUILD) && !make(all) && !make(${F})
168 ${_F}: .MADE # no build at install
169 .endif
170 .endif
171
172 htmlpages:: ${_F}
173 .PRECIOUS: ${_F} # keep if install fails
174 .endfor
175
176 htmllinks:: # link install
177
178 .for _src _dst in ${MLINKS}
179 _l:=${HTMLDIR}/html${_src:T:E}${MANSUBDIR}/${_src:R:S-/index$-/x&-}.html
180 _t:=${HTMLDIR}/html${_dst:T:E}${MANSUBDIR}/${_dst:R:S-/index$-/x&-}.html
181
182 # Handle case conflicts carefully, when _dst occurs
183 # more than once after case flattening
184 .if ${MKUPDATE} == "no" || ${MLINKS:${_FLATTEN}M${_dst:${_FLATTEN}Q}:[\#]} > 1
185 ${_t}! ${_l} __linkinstallpage
186 .else
187 ${_t}: ${_l} __linkinstallpage
188 .endif
189
190 htmllinks:: ${_t}
191 .PRECIOUS: ${_t}
192 .endfor
193
194 .endif # }
195
196 ##### Clean rules
197 .undef _F
198
199 .if !empty(MAN) && (${MKMAN} != "no")
200 .if !empty(MANSUFFIX)
201 CLEANDIRFILES+= ${MANPAGES}
202 .endif
203 .if ${MKHTML} != "no"
204 CLEANDIRFILES+= ${HTMLPAGES}
205 .endif
206 .endif
207
208 .if !empty(MANPAGES)
209 lintmanpages: ${MANPAGES}
210 ${TOOL_MANDOC_LINT} -Tlint -fstrict -Wall,stop ${.ALLSRC}
211 .endif
212
213 ##### describe
214 describe:
215 .for _M in ${MANPAGES}
216 @echo $$(basename ${_M}) - \
217 $$(${TOOL_SED} < ${${_M}:P} -n -e '/^\.Nd /{;s/^....//;p;}')
218 .endfor
219
220
221 ##### Pull in related .mk logic
222 .include <bsd.obj.mk>
223 .include <bsd.files.mk>
224 .include <bsd.sys.mk>
225 .include <bsd.clean.mk>
226
227 ${TARGETS} maninstall htmlinstall: # ensure existence
228