]> git.cameronkatri.com Git - mandoc.git/blob - Makefile
Improve build system and autodetection.
[mandoc.git] / Makefile
1 # $Id: Makefile,v 1.440 2014/08/16 19:00:01 schwarze Exp $
2 #
3 # Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
4 # Copyright (c) 2011, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
5 #
6 # Permission to use, copy, modify, and distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
18 BASEBIN = mandoc preconv demandoc
19 DBBIN = apropos makewhatis
20 CGIBIN = man.cgi
21
22 TESTSRCS = test-dirent-namlen.c \
23 test-fgetln.c \
24 test-fts.c \
25 test-getsubopt.c \
26 test-mmap.c \
27 test-ohash.c \
28 test-reallocarray.c \
29 test-sqlite3.c \
30 test-sqlite3_errstr.c \
31 test-strcasestr.c \
32 test-strlcat.c \
33 test-strlcpy.c \
34 test-strptime.c \
35 test-strsep.c \
36 test-wchar.c
37
38 SRCS = apropos.c \
39 arch.c \
40 att.c \
41 cgi.c \
42 chars.c \
43 compat_fgetln.c \
44 compat_fts.c \
45 compat_getsubopt.c \
46 compat_ohash.c \
47 compat_reallocarray.c \
48 compat_sqlite3_errstr.c \
49 compat_strcasestr.c \
50 compat_strlcat.c \
51 compat_strlcpy.c \
52 compat_strsep.c \
53 demandoc.c \
54 eqn.c \
55 eqn_html.c \
56 eqn_term.c \
57 html.c \
58 lib.c \
59 main.c \
60 man.c \
61 man_hash.c \
62 man_html.c \
63 man_macro.c \
64 man_term.c \
65 man_validate.c \
66 mandoc.c \
67 mandoc_aux.c \
68 mandocdb.c \
69 manpage.c \
70 manpath.c \
71 mansearch.c \
72 mansearch_const.c \
73 mdoc.c \
74 mdoc_argv.c \
75 mdoc_hash.c \
76 mdoc_html.c \
77 mdoc_macro.c \
78 mdoc_man.c \
79 mdoc_term.c \
80 mdoc_validate.c \
81 msec.c \
82 out.c \
83 preconv.c \
84 read.c \
85 roff.c \
86 st.c \
87 tbl.c \
88 tbl_data.c \
89 tbl_html.c \
90 tbl_layout.c \
91 tbl_opts.c \
92 tbl_term.c \
93 term.c \
94 term_ascii.c \
95 term_ps.c \
96 tree.c \
97 vol.c \
98 $(TESTSRCS)
99
100 DISTFILES = INSTALL \
101 LICENSE \
102 Makefile \
103 Makefile.depend \
104 NEWS \
105 TODO \
106 apropos.1 \
107 arch.in \
108 att.in \
109 cgi.h.example \
110 chars.in \
111 compat_fts.h \
112 compat_ohash.h \
113 configure \
114 configure.local.example \
115 demandoc.1 \
116 eqn.7 \
117 example.style.css \
118 gmdiff \
119 html.h \
120 lib.in \
121 libman.h \
122 libmandoc.h \
123 libmdoc.h \
124 libroff.h \
125 main.h \
126 makewhatis.8 \
127 man-cgi.css \
128 man.7 \
129 man.cgi.8 \
130 man.h \
131 mandoc.1 \
132 mandoc.3 \
133 mandoc.db.5 \
134 mandoc.h \
135 mandoc_aux.h \
136 mandoc_char.7 \
137 mandoc_escape.3 \
138 mandoc_html.3 \
139 mandoc_malloc.3 \
140 manpath.h \
141 mansearch.3 \
142 mansearch.h \
143 mchars_alloc.3 \
144 mdoc.7 \
145 mdoc.h \
146 msec.in \
147 out.h \
148 preconv.1 \
149 predefs.in \
150 roff.7 \
151 st.in \
152 style.css \
153 tbl.3 \
154 tbl.7 \
155 term.h \
156 vol.in \
157 $(SRCS)
158
159 LIBMAN_OBJS = man.o \
160 man_hash.o \
161 man_macro.o \
162 man_validate.o
163
164 LIBMDOC_OBJS = arch.o \
165 att.o \
166 lib.o \
167 mdoc.o \
168 mdoc_argv.o \
169 mdoc_hash.o \
170 mdoc_macro.o \
171 mdoc_validate.o \
172 st.o \
173 vol.o
174
175 LIBROFF_OBJS = eqn.o \
176 roff.o \
177 tbl.o \
178 tbl_data.o \
179 tbl_layout.o \
180 tbl_opts.o
181
182 LIBMANDOC_OBJS = $(LIBMAN_OBJS) \
183 $(LIBMDOC_OBJS) \
184 $(LIBROFF_OBJS) \
185 chars.o \
186 mandoc.o \
187 mandoc_aux.o \
188 msec.o \
189 read.o
190
191 COMPAT_OBJS = compat_fgetln.o \
192 compat_fts.o \
193 compat_getsubopt.o \
194 compat_ohash.o \
195 compat_reallocarray.o \
196 compat_sqlite3_errstr.o \
197 compat_strcasestr.o \
198 compat_strlcat.o \
199 compat_strlcpy.o \
200 compat_strsep.o
201
202 MANDOC_HTML_OBJS = eqn_html.o \
203 html.o \
204 man_html.o \
205 mdoc_html.o \
206 tbl_html.o
207
208 MANDOC_MAN_OBJS = mdoc_man.o
209
210 MANDOC_TERM_OBJS = eqn_term.o \
211 man_term.o \
212 mdoc_term.o \
213 term.o \
214 term_ascii.o \
215 term_ps.o \
216 tbl_term.o
217
218 MANDOC_OBJS = $(MANDOC_HTML_OBJS) \
219 $(MANDOC_MAN_OBJS) \
220 $(MANDOC_TERM_OBJS) \
221 main.o \
222 out.o \
223 tree.o
224
225 MAKEWHATIS_OBJS = mandocdb.o mansearch_const.o manpath.o
226
227 PRECONV_OBJS = preconv.o
228
229 APROPOS_OBJS = apropos.o mansearch.o mansearch_const.o manpath.o
230
231 CGI_OBJS = $(MANDOC_HTML_OBJS) \
232 cgi.o \
233 mansearch.o \
234 mansearch_const.o \
235 out.o
236
237 MANPAGE_OBJS = manpage.o mansearch.o mansearch_const.o manpath.o
238
239 DEMANDOC_OBJS = demandoc.o
240
241 WWW_MANS = apropos.1.html \
242 demandoc.1.html \
243 mandoc.1.html \
244 preconv.1.html \
245 mandoc.3.html \
246 mandoc_escape.3.html \
247 mandoc_html.3.html \
248 mandoc_malloc.3.html \
249 mansearch.3.html \
250 mchars_alloc.3.html \
251 tbl.3.html \
252 mandoc.db.5.html \
253 eqn.7.html \
254 man.7.html \
255 mandoc_char.7.html \
256 mdoc.7.html \
257 roff.7.html \
258 tbl.7.html \
259 makewhatis.8.html \
260 man.cgi.8.html \
261 man.h.html \
262 mandoc.h.html \
263 mandoc_aux.h.html \
264 manpath.h.html \
265 mansearch.h.html \
266 mdoc.h.html
267
268 WWW_OBJS = mdocml.tar.gz \
269 mdocml.sha256
270
271 include Makefile.local
272
273 INSTALL_TARGETS = $(BUILD_TARGETS:-build=-install)
274
275 # === DEPENDENCY HANDLING ==============================================
276
277 all: base-build $(BUILD_TARGETS) Makefile.local
278
279 base-build: $(BASEBIN)
280
281 db-build: $(DBBIN)
282
283 cgi-build: $(CGIBIN)
284
285 install: base-install $(INSTALL_TARGETS)
286
287 www: $(WWW_OBJS) $(WWW_MANS)
288
289 include Makefile.depend
290
291 # === TARGETS CONTAINING SHELL COMMANDS ================================
292
293 distclean: clean
294 rm -f Makefile.local config.h config.h.old config.log config.log.old
295
296 clean:
297 rm -f libmandoc.a $(LIBMANDOC_OBJS) $(COMPAT_OBJS)
298 rm -f apropos $(APROPOS_OBJS)
299 rm -f makewhatis $(MAKEWHATIS_OBJS)
300 rm -f preconv $(PRECONV_OBJS)
301 rm -f man.cgi $(CGI_OBJS)
302 rm -f manpage $(MANPAGE_OBJS)
303 rm -f demandoc $(DEMANDOC_OBJS)
304 rm -f mandoc $(MANDOC_OBJS)
305 rm -f $(WWW_MANS) $(WWW_OBJS)
306 rm -rf *.dSYM
307
308 base-install: base-build
309 mkdir -p $(DESTDIR)$(BINDIR)
310 mkdir -p $(DESTDIR)$(EXAMPLEDIR)
311 mkdir -p $(DESTDIR)$(LIBDIR)
312 mkdir -p $(DESTDIR)$(INCLUDEDIR)
313 mkdir -p $(DESTDIR)$(MANDIR)/man1
314 mkdir -p $(DESTDIR)$(MANDIR)/man3
315 mkdir -p $(DESTDIR)$(MANDIR)/man7
316 $(INSTALL_PROGRAM) $(BASEBIN) $(DESTDIR)$(BINDIR)
317 $(INSTALL_LIB) libmandoc.a $(DESTDIR)$(LIBDIR)
318 $(INSTALL_LIB) man.h mandoc.h mandoc_aux.h mdoc.h \
319 $(DESTDIR)$(INCLUDEDIR)
320 $(INSTALL_MAN) mandoc.1 preconv.1 demandoc.1 $(DESTDIR)$(MANDIR)/man1
321 $(INSTALL_MAN) mandoc.3 mandoc_escape.3 mandoc_malloc.3 \
322 mchars_alloc.3 tbl.3 $(DESTDIR)$(MANDIR)/man3
323 $(INSTALL_MAN) man.7 mdoc.7 roff.7 eqn.7 tbl.7 mandoc_char.7 \
324 $(DESTDIR)$(MANDIR)/man7
325 $(INSTALL_DATA) example.style.css $(DESTDIR)$(EXAMPLEDIR)
326
327 db-install: db-build
328 mkdir -p $(DESTDIR)$(BINDIR)
329 mkdir -p $(DESTDIR)$(SBINDIR)
330 mkdir -p $(DESTDIR)$(MANDIR)/man1
331 mkdir -p $(DESTDIR)$(MANDIR)/man3
332 mkdir -p $(DESTDIR)$(MANDIR)/man5
333 mkdir -p $(DESTDIR)$(MANDIR)/man8
334 $(INSTALL_PROGRAM) apropos $(DESTDIR)$(BINDIR)
335 ln -f $(DESTDIR)$(BINDIR)/apropos $(DESTDIR)$(BINDIR)/whatis
336 $(INSTALL_PROGRAM) makewhatis $(DESTDIR)$(SBINDIR)
337 $(INSTALL_MAN) apropos.1 $(DESTDIR)$(MANDIR)/man1
338 ln -f $(DESTDIR)$(MANDIR)/man1/apropos.1 \
339 $(DESTDIR)$(MANDIR)/man1/whatis.1
340 $(INSTALL_MAN) mansearch.3 $(DESTDIR)$(MANDIR)/man3
341 $(INSTALL_MAN) mandoc.db.5 $(DESTDIR)$(MANDIR)/man5
342 $(INSTALL_MAN) makewhatis.8 $(DESTDIR)$(MANDIR)/man8
343
344 cgi-install: cgi-build
345 mkdir -p $(DESTDIR)$(CGIBINDIR)
346 mkdir -p $(DESTDIR)$(HTDOCDIR)
347 mkdir -p $(DESTDIR)$(WWWPREFIX)/man/mandoc/man1
348 mkdir -p $(DESTDIR)$(WWWPREFIX)/man/mandoc/man8
349 $(INSTALL_PROGRAM) man.cgi $(DESTDIR)$(CGIBINDIR)
350 $(INSTALL_DATA) example.style.css $(DESTDIR)$(HTDOCDIR)/man.css
351 $(INSTALL_DATA) man-cgi.css $(DESTDIR)$(HTDOCDIR)
352 $(INSTALL_MAN) apropos.1 $(DESTDIR)$(WWWPREFIX)/man/mandoc/man1/
353 $(INSTALL_MAN) man.cgi.8 $(DESTDIR)$(WWWPREFIX)/man/mandoc/man8/
354
355 www-install: www
356 mkdir -p $(DESTDIR)$(HTDOCDIR)/snapshots
357 $(INSTALL_DATA) $(WWW_MANS) style.css $(DESTDIR)$(HTDOCDIR)
358 $(INSTALL_DATA) $(WWW_OBJS) $(DESTDIR)$(HTDOCDIR)/snapshots
359 $(INSTALL_DATA) mdocml.tar.gz \
360 $(DESTDIR)$(HTDOCDIR)/snapshots/mdocml-$(VERSION).tar.gz
361 $(INSTALL_DATA) mdocml.sha256 \
362 $(DESTDIR)$(HTDOCDIR)/snapshots/mdocml-$(VERSION).sha256
363
364 Makefile.local config.h: configure ${TESTSRCS}
365 @echo "$@ is out of date; please run ./configure"
366 @exit 1
367
368 depend: config.h
369 mkdep -f Makefile.depend $(CFLAGS) $(SRCS)
370 perl -e 'undef $$/; $$_ = <>; s|/usr/include/\S+||g; \
371 s|\\\n||g; s| +| |g; print;' Makefile.depend > Makefile.tmp
372 mv Makefile.tmp Makefile.depend
373
374 libmandoc.a: $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
375 $(AR) rs $@ $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
376
377 mandoc: $(MANDOC_OBJS) libmandoc.a
378 $(CC) $(LDFLAGS) -o $@ $(MANDOC_OBJS) libmandoc.a
379
380 makewhatis: $(MAKEWHATIS_OBJS) libmandoc.a
381 $(CC) $(LDFLAGS) -o $@ $(MAKEWHATIS_OBJS) libmandoc.a $(DBLIB)
382
383 preconv: $(PRECONV_OBJS)
384 $(CC) $(LDFLAGS) -o $@ $(PRECONV_OBJS)
385
386 manpage: $(MANPAGE_OBJS) libmandoc.a
387 $(CC) $(LDFLAGS) -o $@ $(MANPAGE_OBJS) libmandoc.a $(DBLIB)
388
389 apropos: $(APROPOS_OBJS) libmandoc.a
390 $(CC) $(LDFLAGS) -o $@ $(APROPOS_OBJS) libmandoc.a $(DBLIB)
391
392 man.cgi: $(CGI_OBJS) libmandoc.a
393 $(CC) $(LDFLAGS) $(STATIC) -o $@ $(CGI_OBJS) libmandoc.a $(DBLIB)
394
395 demandoc: $(DEMANDOC_OBJS) libmandoc.a
396 $(CC) $(LDFLAGS) -o $@ $(DEMANDOC_OBJS) libmandoc.a
397
398 mdocml.sha256: mdocml.tar.gz
399 sha256 mdocml.tar.gz > $@
400
401 mdocml.tar.gz: $(DISTFILES)
402 mkdir -p .dist/mdocml-$(VERSION)/
403 $(INSTALL) -m 0644 $(DISTFILES) .dist/mdocml-$(VERSION)
404 chmod 755 .dist/mdocml-$(VERSION)/configure
405 ( cd .dist/ && tar zcf ../$@ mdocml-$(VERSION) )
406 rm -rf .dist/
407
408 .PHONY: base-install cgi-install db-install install www-install
409 .PHONY: clean distclean depend
410 .SUFFIXES: .1 .3 .5 .7 .8 .h
411 .SUFFIXES: .1.html .3.html .5.html .7.html .8.html .h.html
412
413 .h.h.html:
414 highlight -I $< > $@
415
416 .1.1.html .3.3.html .5.5.html .7.7.html .8.8.html: mandoc
417 ./mandoc -Thtml -Wall,stop \
418 -Ostyle=style.css,man=%N.%S.html,includes=%I.html $< > $@