Import mdocml-1.13.1
[dragonfly.git] / contrib / mdocml / Makefile
CommitLineData
070c62a6
FF
1# $Id: Makefile,v 1.435 2014/08/10 02:45:04 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
18VERSION = 1.13.1
19
20# === USER SETTINGS ====================================================
21
22# --- user settings relevant for all builds ----------------------------
80387638
SW
23
24# Specify this if you want to hard-code the operating system to appear
25# in the lower-left hand corner of -mdoc manuals.
36342e81 26#
070c62a6 27# CFLAGS += -DOSNAME="\"OpenBSD 5.5\""
36342e81 28
a4c7eb57
SW
29# IFF your system supports multi-byte functions (setlocale(), wcwidth(),
30# putwchar()) AND has __STDC_ISO_10646__ (that is, wchar_t is simply a
31# UCS-4 value) should you define USE_WCHAR. If you define it and your
32# system DOESN'T support this, -Tlocale will produce garbage.
33# If you don't define it, -Tlocale is a synonym for -Tacsii.
36342e81
SW
34#
35CFLAGS += -DUSE_WCHAR
36
7888c61d 37CFLAGS += -g -DHAVE_CONFIG_H
60e1e752
SW
38CFLAGS += -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings
39PREFIX = /usr/local
40BINDIR = $(PREFIX)/bin
41INCLUDEDIR = $(PREFIX)/include/mandoc
42LIBDIR = $(PREFIX)/lib/mandoc
43MANDIR = $(PREFIX)/man
44EXAMPLEDIR = $(PREFIX)/share/examples/mandoc
070c62a6 45
60e1e752 46INSTALL = install
070c62a6 47INSTALL_PROGRAM = $(INSTALL) -m 0555
60e1e752 48INSTALL_DATA = $(INSTALL) -m 0444
070c62a6 49INSTALL_LIB = $(INSTALL) -m 0444
36342e81 50INSTALL_SOURCE = $(INSTALL) -m 0644
60e1e752
SW
51INSTALL_MAN = $(INSTALL_DATA)
52
070c62a6
FF
53# --- user settings related to database support ------------------------
54
55# Building apropos(1) and makewhatis(8) requires both SQLite3 and fts(3).
56# To avoid those dependencies, comment the following line.
57# Be careful: the fts(3) implementation in glibc is broken on 32bit
58# machines, see: https://sourceware.org/bugzilla/show_bug.cgi?id=15838
36342e81 59#
070c62a6 60BUILD_TARGETS += db-build
36342e81 61
070c62a6
FF
62# The remaining settings in this section
63# are only relevant if db-build is enabled.
64# Otherwise, they have no effect either way.
60e1e752 65
070c62a6
FF
66# If your system has manpath(1), uncomment this. This is most any
67# system that's not OpenBSD or NetBSD. If uncommented, apropos(1)
68# and makewhatis(8) will use manpath(1) to get the MANPATH variable.
69#
70#CFLAGS += -DUSE_MANPATH
71
72# On some systems, SQLite3 may be installed below /usr/local.
73# In that case, uncomment the following two lines.
74#
75#CFLAGS += -I/usr/local/include
76#DBLIB += -L/usr/local/lib
77
78# OpenBSD has the ohash functions in libutil.
79# Comment the following line if your system doesn't.
80#
81DBLIB += -lutil
82
83SBINDIR = $(PREFIX)/sbin
84
85# --- user settings related to man.cgi ---------------------------------
86
87# To build man.cgi, copy cgi.h.example to cgi.h, edit it,
88# and enable the following line.
89# Obviously, this requires that db-build is enabled, too.
90#
91#BUILD_TARGETS += cgi-build
92
93# The remaining settings in this section
94# are only relevant if cgi-build is enabled.
95# Otherwise, they have no effect either way.
96
97# If your system does not support static binaries, comment this,
98# for example on Mac OS X.
99#
100STATIC = -static
101
102# Linux requires -pthread for statical linking.
103#
104#STATIC += -pthread
105
106WWWPREFIX = /var/www
107HTDOCDIR = $(WWWPREFIX)/htdocs
108CGIBINDIR = $(WWWPREFIX)/cgi-bin
109
110# === END OF USER SETTINGS =============================================
111
112INSTALL_TARGETS = $(BUILD_TARGETS:-build=-install)
113
114BASEBIN = mandoc preconv demandoc
115DBBIN = apropos makewhatis
116CGIBIN = man.cgi
117
118DBLIB += -lsqlite3
119
120TESTSRCS = test-fgetln.c \
121 test-getsubopt.c \
122 test-mmap.c \
123 test-ohash.c \
124 test-reallocarray.c \
125 test-sqlite3_errstr.c \
126 test-strcasestr.c \
127 test-strlcat.c \
128 test-strlcpy.c \
129 test-strptime.c \
130 test-strsep.c
131
132SRCS = apropos.c \
60e1e752 133 arch.c \
60e1e752 134 att.c \
36342e81 135 cgi.c \
60e1e752 136 chars.c \
36342e81
SW
137 compat_fgetln.c \
138 compat_getsubopt.c \
070c62a6
FF
139 compat_ohash.c \
140 compat_reallocarray.c \
141 compat_sqlite3_errstr.c \
142 compat_strcasestr.c \
36342e81
SW
143 compat_strlcat.c \
144 compat_strlcpy.c \
070c62a6 145 compat_strsep.c \
36342e81 146 demandoc.c \
60e1e752 147 eqn.c \
36342e81
SW
148 eqn_html.c \
149 eqn_term.c \
60e1e752 150 html.c \
60e1e752 151 lib.c \
60e1e752 152 main.c \
60e1e752
SW
153 man.c \
154 man_hash.c \
155 man_html.c \
156 man_macro.c \
157 man_term.c \
158 man_validate.c \
60e1e752 159 mandoc.c \
070c62a6 160 mandoc_aux.c \
36342e81 161 mandocdb.c \
070c62a6 162 manpage.c \
36342e81 163 manpath.c \
070c62a6
FF
164 mansearch.c \
165 mansearch_const.c \
60e1e752
SW
166 mdoc.c \
167 mdoc_argv.c \
168 mdoc_hash.c \
169 mdoc_html.c \
170 mdoc_macro.c \
36342e81 171 mdoc_man.c \
60e1e752
SW
172 mdoc_term.c \
173 mdoc_validate.c \
174 msec.c \
60e1e752 175 out.c \
a4c7eb57 176 preconv.c \
60e1e752 177 read.c \
60e1e752
SW
178 roff.c \
179 st.c \
60e1e752
SW
180 tbl.c \
181 tbl_data.c \
182 tbl_html.c \
183 tbl_layout.c \
184 tbl_opts.c \
185 tbl_term.c \
186 term.c \
60e1e752
SW
187 term_ascii.c \
188 term_ps.c \
60e1e752
SW
189 tree.c \
190 vol.c \
070c62a6
FF
191 $(TESTSRCS)
192
193DISTFILES = INSTALL \
194 LICENSE \
195 Makefile \
196 Makefile.depend \
197 NEWS \
198 TODO \
199 apropos.1 \
200 arch.in \
201 att.in \
202 cgi.h.example \
203 chars.in \
204 compat_ohash.h \
205 config.h.post \
206 config.h.pre \
207 configure \
208 demandoc.1 \
209 eqn.7 \
210 example.style.css \
211 gmdiff \
212 html.h \
213 lib.in \
214 libman.h \
215 libmandoc.h \
216 libmdoc.h \
217 libroff.h \
218 main.h \
219 makewhatis.8 \
220 man-cgi.css \
221 man.7 \
222 man.cgi.8 \
223 man.h \
224 mandoc.1 \
225 mandoc.3 \
226 mandoc.db.5 \
227 mandoc.h \
228 mandoc_aux.h \
229 mandoc_char.7 \
230 mandoc_escape.3 \
231 mandoc_html.3 \
232 mandoc_malloc.3 \
233 manpath.h \
234 mansearch.3 \
235 mansearch.h \
236 mchars_alloc.3 \
237 mdoc.7 \
238 mdoc.h \
239 msec.in \
240 out.h \
241 preconv.1 \
242 predefs.in \
243 roff.7 \
244 st.in \
245 style.css \
246 tbl.3 \
247 tbl.7 \
248 term.h \
36342e81 249 vol.in \
070c62a6 250 $(SRCS)
60e1e752
SW
251
252LIBMAN_OBJS = man.o \
253 man_hash.o \
254 man_macro.o \
255 man_validate.o
60e1e752
SW
256
257LIBMDOC_OBJS = arch.o \
258 att.o \
259 lib.o \
260 mdoc.o \
261 mdoc_argv.o \
262 mdoc_hash.o \
263 mdoc_macro.o \
264 mdoc_validate.o \
60e1e752
SW
265 st.o \
266 vol.o
60e1e752
SW
267
268LIBROFF_OBJS = eqn.o \
269 roff.o \
270 tbl.o \
271 tbl_data.o \
272 tbl_layout.o \
273 tbl_opts.o
60e1e752
SW
274
275LIBMANDOC_OBJS = $(LIBMAN_OBJS) \
276 $(LIBMDOC_OBJS) \
277 $(LIBROFF_OBJS) \
a4c7eb57 278 chars.o \
60e1e752 279 mandoc.o \
070c62a6 280 mandoc_aux.o \
36342e81 281 msec.o \
60e1e752 282 read.o
60e1e752 283
36342e81
SW
284COMPAT_OBJS = compat_fgetln.o \
285 compat_getsubopt.o \
070c62a6
FF
286 compat_ohash.o \
287 compat_reallocarray.o \
288 compat_sqlite3_errstr.o \
289 compat_strcasestr.o \
36342e81 290 compat_strlcat.o \
070c62a6
FF
291 compat_strlcpy.o \
292 compat_strsep.o
36342e81
SW
293
294MANDOC_HTML_OBJS = eqn_html.o \
295 html.o \
60e1e752
SW
296 man_html.o \
297 mdoc_html.o \
298 tbl_html.o
60e1e752 299
36342e81 300MANDOC_MAN_OBJS = mdoc_man.o
36342e81
SW
301
302MANDOC_TERM_OBJS = eqn_term.o \
303 man_term.o \
60e1e752
SW
304 mdoc_term.o \
305 term.o \
306 term_ascii.o \
307 term_ps.o \
308 tbl_term.o
60e1e752
SW
309
310MANDOC_OBJS = $(MANDOC_HTML_OBJS) \
36342e81 311 $(MANDOC_MAN_OBJS) \
60e1e752 312 $(MANDOC_TERM_OBJS) \
60e1e752
SW
313 main.o \
314 out.o \
315 tree.o
60e1e752 316
070c62a6 317MAKEWHATIS_OBJS = mandocdb.o mansearch_const.o manpath.o
60e1e752 318
a4c7eb57 319PRECONV_OBJS = preconv.o
a4c7eb57 320
070c62a6 321APROPOS_OBJS = apropos.o mansearch.o mansearch_const.o manpath.o
36342e81
SW
322
323CGI_OBJS = $(MANDOC_HTML_OBJS) \
36342e81 324 cgi.o \
070c62a6
FF
325 mansearch.o \
326 mansearch_const.o \
327 out.o
36342e81 328
070c62a6 329MANPAGE_OBJS = manpage.o mansearch.o mansearch_const.o manpath.o
36342e81
SW
330
331DEMANDOC_OBJS = demandoc.o
36342e81 332
070c62a6 333WWW_MANS = apropos.1.html \
36342e81 334 demandoc.1.html \
a4c7eb57 335 mandoc.1.html \
070c62a6 336 preconv.1.html \
60e1e752 337 mandoc.3.html \
070c62a6
FF
338 mandoc_escape.3.html \
339 mandoc_html.3.html \
340 mandoc_malloc.3.html \
341 mansearch.3.html \
342 mchars_alloc.3.html \
f88b6c16 343 tbl.3.html \
070c62a6 344 mandoc.db.5.html \
60e1e752 345 eqn.7.html \
60e1e752 346 man.7.html \
60e1e752 347 mandoc_char.7.html \
60e1e752 348 mdoc.7.html \
60e1e752 349 roff.7.html \
60e1e752 350 tbl.7.html \
070c62a6
FF
351 makewhatis.8.html \
352 man.cgi.8.html \
60e1e752
SW
353 man.h.html \
354 mandoc.h.html \
070c62a6
FF
355 mandoc_aux.h.html \
356 manpath.h.html \
357 mansearch.h.html \
358 mdoc.h.html
359
360WWW_OBJS = mdocml.tar.gz \
361 mdocml.sha256
362
363# === DEPENDENCY HANDLING ==============================================
364
365all: base-build $(BUILD_TARGETS)
366
367base-build: $(BASEBIN)
368
369db-build: $(DBBIN)
370
371cgi-build: $(CGIBIN)
372
373install: base-install $(INSTALL_TARGETS)
60e1e752 374
070c62a6
FF
375www: $(WWW_OBJS) $(WWW_MANS)
376
377include Makefile.depend
378
379# === TARGETS CONTAINING SHELL COMMANDS ================================
60e1e752 380
80387638 381clean:
60e1e752 382 rm -f libmandoc.a $(LIBMANDOC_OBJS)
070c62a6
FF
383 rm -f apropos $(APROPOS_OBJS)
384 rm -f makewhatis $(MAKEWHATIS_OBJS)
a4c7eb57 385 rm -f preconv $(PRECONV_OBJS)
36342e81 386 rm -f man.cgi $(CGI_OBJS)
070c62a6 387 rm -f manpage $(MANPAGE_OBJS)
36342e81 388 rm -f demandoc $(DEMANDOC_OBJS)
60e1e752 389 rm -f mandoc $(MANDOC_OBJS)
f88b6c16 390 rm -f config.h config.log $(COMPAT_OBJS)
070c62a6 391 rm -f $(WWW_MANS) $(WWW_OBJS)
f88b6c16 392 rm -rf *.dSYM
60e1e752 393
070c62a6 394base-install: base-build
80387638
SW
395 mkdir -p $(DESTDIR)$(BINDIR)
396 mkdir -p $(DESTDIR)$(EXAMPLEDIR)
a4c7eb57
SW
397 mkdir -p $(DESTDIR)$(LIBDIR)
398 mkdir -p $(DESTDIR)$(INCLUDEDIR)
80387638 399 mkdir -p $(DESTDIR)$(MANDIR)/man1
60e1e752 400 mkdir -p $(DESTDIR)$(MANDIR)/man3
80387638 401 mkdir -p $(DESTDIR)$(MANDIR)/man7
070c62a6 402 $(INSTALL_PROGRAM) $(BASEBIN) $(DESTDIR)$(BINDIR)
60e1e752 403 $(INSTALL_LIB) libmandoc.a $(DESTDIR)$(LIBDIR)
070c62a6
FF
404 $(INSTALL_LIB) man.h mandoc.h mandoc_aux.h mdoc.h \
405 $(DESTDIR)$(INCLUDEDIR)
36342e81 406 $(INSTALL_MAN) mandoc.1 preconv.1 demandoc.1 $(DESTDIR)$(MANDIR)/man1
070c62a6
FF
407 $(INSTALL_MAN) mandoc.3 mandoc_escape.3 mandoc_malloc.3 \
408 mchars_alloc.3 tbl.3 $(DESTDIR)$(MANDIR)/man3
409 $(INSTALL_MAN) man.7 mdoc.7 roff.7 eqn.7 tbl.7 mandoc_char.7 \
410 $(DESTDIR)$(MANDIR)/man7
80387638
SW
411 $(INSTALL_DATA) example.style.css $(DESTDIR)$(EXAMPLEDIR)
412
070c62a6
FF
413db-install: db-build
414 mkdir -p $(DESTDIR)$(BINDIR)
415 mkdir -p $(DESTDIR)$(SBINDIR)
416 mkdir -p $(DESTDIR)$(MANDIR)/man1
417 mkdir -p $(DESTDIR)$(MANDIR)/man3
418 mkdir -p $(DESTDIR)$(MANDIR)/man5
419 mkdir -p $(DESTDIR)$(MANDIR)/man8
420 $(INSTALL_PROGRAM) apropos $(DESTDIR)$(BINDIR)
421 ln -f $(DESTDIR)$(BINDIR)/apropos $(DESTDIR)$(BINDIR)/whatis
422 $(INSTALL_PROGRAM) makewhatis $(DESTDIR)$(SBINDIR)
423 $(INSTALL_MAN) apropos.1 $(DESTDIR)$(MANDIR)/man1
424 ln -f $(DESTDIR)$(MANDIR)/man1/apropos.1 \
425 $(DESTDIR)$(MANDIR)/man1/whatis.1
426 $(INSTALL_MAN) mansearch.3 $(DESTDIR)$(MANDIR)/man3
427 $(INSTALL_MAN) mandoc.db.5 $(DESTDIR)$(MANDIR)/man5
428 $(INSTALL_MAN) makewhatis.8 $(DESTDIR)$(MANDIR)/man8
429
430cgi-install: cgi-build
36342e81
SW
431 mkdir -p $(DESTDIR)$(CGIBINDIR)
432 mkdir -p $(DESTDIR)$(HTDOCDIR)
070c62a6
FF
433 mkdir -p $(DESTDIR)$(WWWPREFIX)/man/mandoc/man1
434 mkdir -p $(DESTDIR)$(WWWPREFIX)/man/mandoc/man8
36342e81
SW
435 $(INSTALL_PROGRAM) man.cgi $(DESTDIR)$(CGIBINDIR)
436 $(INSTALL_DATA) example.style.css $(DESTDIR)$(HTDOCDIR)/man.css
437 $(INSTALL_DATA) man-cgi.css $(DESTDIR)$(HTDOCDIR)
070c62a6
FF
438 $(INSTALL_MAN) apropos.1 $(DESTDIR)$(WWWPREFIX)/man/mandoc/man1/
439 $(INSTALL_MAN) man.cgi.8 $(DESTDIR)$(WWWPREFIX)/man/mandoc/man8/
440
441www-install: www
442 mkdir -p $(DESTDIR)$(HTDOCDIR)/snapshots
443 $(INSTALL_DATA) $(WWW_MANS) style.css $(DESTDIR)$(HTDOCDIR)
444 $(INSTALL_DATA) $(WWW_OBJS) $(DESTDIR)$(HTDOCDIR)/snapshots
445 $(INSTALL_DATA) mdocml.tar.gz \
446 $(DESTDIR)$(HTDOCDIR)/snapshots/mdocml-$(VERSION).tar.gz
447 $(INSTALL_DATA) mdocml.sha256 \
448 $(DESTDIR)$(HTDOCDIR)/snapshots/mdocml-$(VERSION).sha256
449
450depend: config.h
451 mkdep -f Makefile.depend $(CFLAGS) $(SRCS)
452 perl -e 'undef $$/; $$_ = <>; s|/usr/include/\S+||g; \
453 s|\\\n||g; s| +| |g; print;' Makefile.depend > Makefile.tmp
454 mv Makefile.tmp Makefile.depend
80387638 455
36342e81
SW
456libmandoc.a: $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
457 $(AR) rs $@ $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
80387638 458
60e1e752 459mandoc: $(MANDOC_OBJS) libmandoc.a
36342e81 460 $(CC) $(LDFLAGS) -o $@ $(MANDOC_OBJS) libmandoc.a
80387638 461
070c62a6
FF
462makewhatis: $(MAKEWHATIS_OBJS) libmandoc.a
463 $(CC) $(LDFLAGS) -o $@ $(MAKEWHATIS_OBJS) libmandoc.a $(DBLIB)
a4c7eb57 464
a4c7eb57 465preconv: $(PRECONV_OBJS)
36342e81
SW
466 $(CC) $(LDFLAGS) -o $@ $(PRECONV_OBJS)
467
070c62a6
FF
468manpage: $(MANPAGE_OBJS) libmandoc.a
469 $(CC) $(LDFLAGS) -o $@ $(MANPAGE_OBJS) libmandoc.a $(DBLIB)
36342e81
SW
470
471apropos: $(APROPOS_OBJS) libmandoc.a
472 $(CC) $(LDFLAGS) -o $@ $(APROPOS_OBJS) libmandoc.a $(DBLIB)
a4c7eb57 473
36342e81
SW
474man.cgi: $(CGI_OBJS) libmandoc.a
475 $(CC) $(LDFLAGS) $(STATIC) -o $@ $(CGI_OBJS) libmandoc.a $(DBLIB)
476
36342e81
SW
477demandoc: $(DEMANDOC_OBJS) libmandoc.a
478 $(CC) $(LDFLAGS) -o $@ $(DEMANDOC_OBJS) libmandoc.a
479
070c62a6
FF
480mdocml.sha256: mdocml.tar.gz
481 sha256 mdocml.tar.gz > $@
80387638 482
070c62a6 483mdocml.tar.gz: $(DISTFILES)
60e1e752 484 mkdir -p .dist/mdocml-$(VERSION)/
070c62a6
FF
485 $(INSTALL_SOURCE) $(DISTFILES) .dist/mdocml-$(VERSION)
486 chmod 755 .dist/mdocml-$(VERSION)/configure
487 ( cd .dist/ && tar zcf ../$@ mdocml-$(VERSION) )
80387638
SW
488 rm -rf .dist/
489
070c62a6 490config.h: configure config.h.pre config.h.post $(TESTSRCS)
60e1e752 491 rm -f config.log
070c62a6
FF
492 CC="$(CC)" CFLAGS="$(CFLAGS)" DBLIB="$(DBLIB)" \
493 VERSION="$(VERSION)" ./configure
80387638 494
070c62a6
FF
495.PHONY: base-install cgi-install db-install install www-install
496.PHONY: clean depend
497.SUFFIXES: .1 .3 .5 .7 .8 .h
498.SUFFIXES: .1.html .3.html .5.html .7.html .8.html .h.html
80387638 499
070c62a6
FF
500.h.h.html:
501 highlight -I $< > $@
80387638 502
070c62a6
FF
503.1.1.html .3.3.html .5.5.html .7.7.html .8.8.html: mandoc
504 ./mandoc -Thtml -Wall,stop \
505 -Ostyle=style.css,man=%N.%S.html,includes=%I.html $< > $@