1# $Id: Makefile,v 1.516 2017/07/20 16:24:53 schwarze Exp $
2#
3# Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
4# Copyright (c) 2011, 2013-2017 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.14.3
19
20# === LIST OF FILES ====================================================
21
22TESTSRCS	 = test-be32toh.c \
23		   test-cmsg.c \
24		   test-dirent-namlen.c \
25		   test-EFTYPE.c \
26		   test-err.c \
27		   test-fts.c \
28		   test-getline.c \
29		   test-getsubopt.c \
30		   test-isblank.c \
31		   test-mkdtemp.c \
32		   test-nanosleep.c \
33		   test-ntohl.c \
34		   test-O_DIRECTORY.c \
35		   test-ohash.c \
36		   test-PATH_MAX.c \
37		   test-pledge.c \
38		   test-progname.c \
39		   test-recvmsg.c \
40		   test-reallocarray.c \
41		   test-recallocarray.c \
42		   test-rewb-bsd.c \
43		   test-rewb-sysv.c \
44		   test-sandbox_init.c \
45		   test-strcasestr.c \
46		   test-stringlist.c \
47		   test-strlcat.c \
48		   test-strlcpy.c \
49		   test-strptime.c \
50		   test-strsep.c \
51		   test-strtonum.c \
52		   test-vasprintf.c \
53		   test-wchar.c
54
55SRCS		 = att.c \
56		   catman.c \
57		   cgi.c \
58		   chars.c \
59		   compat_err.c \
60		   compat_fts.c \
61		   compat_getline.c \
62		   compat_getsubopt.c \
63		   compat_isblank.c \
64		   compat_mkdtemp.c \
65		   compat_ohash.c \
66		   compat_progname.c \
67		   compat_reallocarray.c \
68		   compat_recallocarray.c \
69		   compat_strcasestr.c \
70		   compat_stringlist.c \
71		   compat_strlcat.c \
72		   compat_strlcpy.c \
73		   compat_strsep.c \
74		   compat_strtonum.c \
75		   compat_vasprintf.c \
76		   dba.c \
77		   dba_array.c \
78		   dba_read.c \
79		   dba_write.c \
80		   dbm.c \
81		   dbm_map.c \
82		   demandoc.c \
83		   eqn.c \
84		   eqn_html.c \
85		   eqn_term.c \
86		   html.c \
87		   lib.c \
88		   main.c \
89		   man.c \
90		   man_html.c \
91		   man_macro.c \
92		   man_term.c \
93		   man_validate.c \
94		   mandoc.c \
95		   mandoc_aux.c \
96		   mandoc_ohash.c \
97		   mandoc_xr.c \
98		   mandocd.c \
99		   mandocdb.c \
100		   manpath.c \
101		   mansearch.c \
102		   mdoc.c \
103		   mdoc_argv.c \
104		   mdoc_html.c \
105		   mdoc_macro.c \
106		   mdoc_man.c \
107		   mdoc_markdown.c \
108		   mdoc_state.c \
109		   mdoc_term.c \
110		   mdoc_validate.c \
111		   msec.c \
112		   out.c \
113		   preconv.c \
114		   read.c \
115		   roff.c \
116		   roff_html.c \
117		   roff_term.c \
118		   roff_validate.c \
119		   soelim.c \
120		   st.c \
121		   tag.c \
122		   tbl.c \
123		   tbl_data.c \
124		   tbl_html.c \
125		   tbl_layout.c \
126		   tbl_opts.c \
127		   tbl_term.c \
128		   term.c \
129		   term_ascii.c \
130		   term_ps.c \
131		   term_tab.c \
132		   tree.c
133
134DISTFILES	 = INSTALL \
135		   LICENSE \
136		   Makefile \
137		   Makefile.depend \
138		   NEWS \
139		   TODO \
140		   apropos.1 \
141		   catman.8 \
142		   cgi.h.example \
143		   compat_fts.h \
144		   compat_ohash.h \
145		   compat_stringlist.h \
146		   configure \
147		   configure.local.example \
148		   dba.h \
149		   dba_array.h \
150		   dba_write.h \
151		   dbm.h \
152		   dbm_map.h \
153		   demandoc.1 \
154		   eqn.7 \
155		   gmdiff \
156		   html.h \
157		   lib.in \
158		   libman.h \
159		   libmandoc.h \
160		   libmdoc.h \
161		   libroff.h \
162		   main.h \
163		   makewhatis.8 \
164		   man.1 \
165		   man.7 \
166		   man.cgi.3 \
167		   man.cgi.8 \
168		   man.conf.5 \
169		   man.h \
170		   man.options.1 \
171		   manconf.h \
172		   mandoc.1 \
173		   mandoc.3 \
174		   mandoc.css \
175		   mandoc.db.5 \
176		   mandoc.h \
177		   mandoc_aux.h \
178		   mandoc_char.7 \
179		   mandoc_escape.3 \
180		   mandoc_headers.3 \
181		   mandoc_html.3 \
182		   mandoc_malloc.3 \
183		   mandoc_ohash.h \
184		   mandoc_xr.h \
185		   mandocd.8 \
186		   mansearch.3 \
187		   mansearch.h \
188		   mchars_alloc.3 \
189		   mdoc.7 \
190		   mdoc.h \
191		   msec.in \
192		   out.h \
193		   predefs.in \
194		   roff.7 \
195		   roff.h \
196		   roff_int.h \
197		   soelim.1 \
198		   st.in \
199		   tag.h \
200		   tbl.3 \
201		   tbl.7 \
202		   term.h \
203		   $(SRCS) \
204		   $(TESTSRCS)
205
206LIBMAN_OBJS	 = man.o \
207		   man_macro.o \
208		   man_validate.o
209
210LIBMDOC_OBJS	 = att.o \
211		   lib.o \
212		   mdoc.o \
213		   mdoc_argv.o \
214		   mdoc_macro.o \
215		   mdoc_state.o \
216		   mdoc_validate.o \
217		   st.o
218
219LIBROFF_OBJS	 = eqn.o \
220		   roff.o \
221		   roff_validate.o \
222		   tbl.o \
223		   tbl_data.o \
224		   tbl_layout.o \
225		   tbl_opts.o
226
227LIBMANDOC_OBJS	 = $(LIBMAN_OBJS) \
228		   $(LIBMDOC_OBJS) \
229		   $(LIBROFF_OBJS) \
230		   chars.o \
231		   mandoc.o \
232		   mandoc_aux.o \
233		   mandoc_ohash.o \
234		   mandoc_xr.o \
235		   msec.o \
236		   preconv.o \
237		   read.o
238
239COMPAT_OBJS	 = compat_err.o \
240		   compat_fts.o \
241		   compat_getline.o \
242		   compat_getsubopt.o \
243		   compat_isblank.o \
244		   compat_mkdtemp.o \
245		   compat_ohash.o \
246		   compat_progname.o \
247		   compat_reallocarray.o \
248		   compat_recallocarray.o \
249		   compat_strcasestr.o \
250		   compat_strlcat.o \
251		   compat_strlcpy.o \
252		   compat_strsep.o \
253		   compat_strtonum.o \
254		   compat_vasprintf.o
255
256MANDOC_HTML_OBJS = eqn_html.o \
257		   html.o \
258		   man_html.o \
259		   mdoc_html.o \
260		   roff_html.o \
261		   tbl_html.o
262
263MANDOC_TERM_OBJS = eqn_term.o \
264		   man_term.o \
265		   mdoc_term.o \
266		   roff_term.o \
267		   term.o \
268		   term_ascii.o \
269		   term_ps.o \
270		   term_tab.o \
271		   tbl_term.o
272
273DBM_OBJS	 = dbm.o \
274		   dbm_map.o \
275		   mansearch.o
276
277DBA_OBJS	 = dba.o \
278		   dba_array.o \
279		   dba_read.o \
280		   dba_write.o \
281		   mandocdb.o
282
283MAIN_OBJS	 = $(MANDOC_HTML_OBJS) \
284		   $(MANDOC_MAN_OBJS) \
285		   $(MANDOC_TERM_OBJS) \
286		   $(DBM_OBJS) \
287		   $(DBA_OBJS) \
288		   main.o \
289		   manpath.o \
290		   mdoc_man.o \
291		   mdoc_markdown.o \
292		   out.o \
293		   tag.o \
294		   tree.o
295
296CGI_OBJS	 = $(MANDOC_HTML_OBJS) \
297		   $(DBM_OBJS) \
298		   cgi.o \
299		   out.o
300
301MANDOCD_OBJS	 = $(MANDOC_HTML_OBJS) \
302		   $(MANDOC_TERM_OBJS) \
303		   mandocd.o \
304		   out.o \
305		   tag.o
306
307DEMANDOC_OBJS	 = demandoc.o
308
309SOELIM_OBJS	 = soelim.o \
310		   compat_err.o \
311		   compat_getline.o \
312		   compat_progname.o \
313		   compat_reallocarray.o \
314		   compat_stringlist.o
315
316WWW_MANS	 = apropos.1.html \
317		   demandoc.1.html \
318		   man.1.html \
319		   mandoc.1.html \
320		   soelim.1.html \
321		   man.cgi.3.html \
322		   mandoc.3.html \
323		   mandoc_escape.3.html \
324		   mandoc_headers.3.html \
325		   mandoc_html.3.html \
326		   mandoc_malloc.3.html \
327		   mansearch.3.html \
328		   mchars_alloc.3.html \
329		   tbl.3.html \
330		   man.conf.5.html \
331		   mandoc.db.5.html \
332		   eqn.7.html \
333		   man.7.html \
334		   mandoc_char.7.html \
335		   mandocd.8.html \
336		   mdoc.7.html \
337		   roff.7.html \
338		   tbl.7.html \
339		   catman.8.html \
340		   makewhatis.8.html \
341		   man.cgi.8.html \
342		   man.h.html \
343		   manconf.h.html \
344		   mandoc.h.html \
345		   mandoc_aux.h.html \
346		   mansearch.h.html \
347		   mdoc.h.html \
348		   roff.h.html
349
350# === USER CONFIGURATION ===============================================
351
352include Makefile.local
353
354# === DEPENDENCY HANDLING ==============================================
355
356all: mandoc demandoc soelim $(BUILD_TARGETS) Makefile.local
357
358install: base-install $(INSTALL_TARGETS)
359
360www: $(WWW_MANS)
361
362$(WWW_MANS): mandoc
363
364.PHONY: base-install cgi-install install www-install
365.PHONY: clean distclean depend
366
367include Makefile.depend
368
369# === TARGETS CONTAINING SHELL COMMANDS ================================
370
371distclean: clean
372	rm -f Makefile.local config.h config.h.old config.log config.log.old
373
374clean:
375	rm -f libmandoc.a $(LIBMANDOC_OBJS) $(COMPAT_OBJS)
376	rm -f mandoc $(MAIN_OBJS)
377	rm -f man.cgi $(CGI_OBJS)
378	rm -f mandocd catman catman.o $(MANDOCD_OBJS)
379	rm -f demandoc $(DEMANDOC_OBJS)
380	rm -f soelim $(SOELIM_OBJS)
381	rm -f $(WWW_MANS) mandoc.tar.gz mandoc.sha256
382	rm -rf *.dSYM
383
384base-install: mandoc demandoc soelim
385	mkdir -p $(DESTDIR)$(BINDIR)
386	mkdir -p $(DESTDIR)$(SBINDIR)
387	mkdir -p $(DESTDIR)$(MANDIR)/man1
388	mkdir -p $(DESTDIR)$(MANDIR)/man5
389	mkdir -p $(DESTDIR)$(MANDIR)/man7
390	mkdir -p $(DESTDIR)$(MANDIR)/man8
391	$(INSTALL_PROGRAM) mandoc demandoc $(DESTDIR)$(BINDIR)
392	$(INSTALL_PROGRAM) soelim $(DESTDIR)$(BINDIR)/$(BINM_SOELIM)
393	cd $(DESTDIR)$(BINDIR) && $(LN) mandoc $(BINM_MAN)
394	cd $(DESTDIR)$(BINDIR) && $(LN) mandoc $(BINM_APROPOS)
395	cd $(DESTDIR)$(BINDIR) && $(LN) mandoc $(BINM_WHATIS)
396	cd $(DESTDIR)$(SBINDIR) && \
397		$(LN) ${BIN_FROM_SBIN}/mandoc $(BINM_MAKEWHATIS)
398	$(INSTALL_MAN) mandoc.1 demandoc.1 $(DESTDIR)$(MANDIR)/man1
399	$(INSTALL_MAN) soelim.1 $(DESTDIR)$(MANDIR)/man1/$(BINM_SOELIM).1
400	$(INSTALL_MAN) man.1 $(DESTDIR)$(MANDIR)/man1/$(BINM_MAN).1
401	$(INSTALL_MAN) apropos.1 $(DESTDIR)$(MANDIR)/man1/$(BINM_APROPOS).1
402	cd $(DESTDIR)$(MANDIR)/man1 && $(LN) $(BINM_APROPOS).1 $(BINM_WHATIS).1
403	$(INSTALL_MAN) man.conf.5 $(DESTDIR)$(MANDIR)/man5/$(MANM_MANCONF).5
404	$(INSTALL_MAN) mandoc.db.5 $(DESTDIR)$(MANDIR)/man5
405	$(INSTALL_MAN) man.7 $(DESTDIR)$(MANDIR)/man7/$(MANM_MAN).7
406	$(INSTALL_MAN) mdoc.7 $(DESTDIR)$(MANDIR)/man7/$(MANM_MDOC).7
407	$(INSTALL_MAN) roff.7 $(DESTDIR)$(MANDIR)/man7/$(MANM_ROFF).7
408	$(INSTALL_MAN) eqn.7 $(DESTDIR)$(MANDIR)/man7/$(MANM_EQN).7
409	$(INSTALL_MAN) tbl.7 $(DESTDIR)$(MANDIR)/man7/$(MANM_TBL).7
410	$(INSTALL_MAN) mandoc_char.7 $(DESTDIR)$(MANDIR)/man7
411	$(INSTALL_MAN) makewhatis.8 \
412		$(DESTDIR)$(MANDIR)/man8/$(BINM_MAKEWHATIS).8
413
414lib-install: libmandoc.a
415	mkdir -p $(DESTDIR)$(LIBDIR)
416	mkdir -p $(DESTDIR)$(INCLUDEDIR)
417	mkdir -p $(DESTDIR)$(MANDIR)/man3
418	$(INSTALL_LIB) libmandoc.a $(DESTDIR)$(LIBDIR)
419	$(INSTALL_LIB) man.h mandoc.h mandoc_aux.h mdoc.h roff.h \
420		$(DESTDIR)$(INCLUDEDIR)
421	$(INSTALL_MAN) mandoc.3 mandoc_escape.3 mandoc_malloc.3 \
422		mansearch.3 mchars_alloc.3 tbl.3 $(DESTDIR)$(MANDIR)/man3
423
424cgi-install: man.cgi
425	mkdir -p $(DESTDIR)$(CGIBINDIR)
426	mkdir -p $(DESTDIR)$(HTDOCDIR)
427	$(INSTALL_PROGRAM) man.cgi $(DESTDIR)$(CGIBINDIR)
428	$(INSTALL_DATA) mandoc.css $(DESTDIR)$(HTDOCDIR)
429
430catman-install: mandocd catman
431	mkdir -p $(DESTDIR)$(SBINDIR)
432	mkdir -p $(DESTDIR)$(MANDIR)/man8
433	$(INSTALL_PROGRAM) mandocd $(DESTDIR)$(SBINDIR)
434	$(INSTALL_PROGRAM) catman $(DESTDIR)$(SBINDIR)/$(BINM_CATMAN)
435	$(INSTALL_MAN) mandocd.8 $(DESTDIR)$(MANDIR)/man8
436	$(INSTALL_MAN) catman.8 $(DESTDIR)$(MANDIR)/man8/$(BINM_CATMAN).8
437
438uninstall:
439	rm -f $(DESTDIR)$(BINDIR)/mandoc
440	rm -f $(DESTDIR)$(BINDIR)/demandoc
441	rm -f $(DESTDIR)$(BINDIR)/$(BINM_SOELIM)
442	rm -f $(DESTDIR)$(BINDIR)/$(BINM_MAN)
443	rm -f $(DESTDIR)$(BINDIR)/$(BINM_APROPOS)
444	rm -f $(DESTDIR)$(BINDIR)/$(BINM_WHATIS)
445	rm -f $(DESTDIR)$(SBINDIR)/$(BINM_MAKEWHATIS)
446	rm -f $(DESTDIR)$(MANDIR)/man1/mandoc.1
447	rm -f $(DESTDIR)$(MANDIR)/man1/demandoc.1
448	rm -f $(DESTDIR)$(MANDIR)/man1/$(BINM_SOELIM).1
449	rm -f $(DESTDIR)$(MANDIR)/man1/$(BINM_MAN).1
450	rm -f $(DESTDIR)$(MANDIR)/man1/$(BINM_APROPOS).1
451	rm -f $(DESTDIR)$(MANDIR)/man1/$(BINM_WHATIS).1
452	rm -f $(DESTDIR)$(MANDIR)/man5/$(MANM_MANCONF).5
453	rm -f $(DESTDIR)$(MANDIR)/man5/mandoc.db.5
454	rm -f $(DESTDIR)$(MANDIR)/man7/$(MANM_MAN).7
455	rm -f $(DESTDIR)$(MANDIR)/man7/$(MANM_MDOC).7
456	rm -f $(DESTDIR)$(MANDIR)/man7/$(MANM_ROFF).7
457	rm -f $(DESTDIR)$(MANDIR)/man7/$(MANM_EQN).7
458	rm -f $(DESTDIR)$(MANDIR)/man7/$(MANM_TBL).7
459	rm -f $(DESTDIR)$(MANDIR)/man7/mandoc_char.7
460	rm -f $(DESTDIR)$(MANDIR)/man8/$(BINM_MAKEWHATIS).8
461	rm -f $(DESTDIR)$(CGIBINDIR)/man.cgi
462	rm -f $(DESTDIR)$(HTDOCDIR)/mandoc.css
463	rm -f $(DESTDIR)$(SBINDIR)/mandocd
464	rm -f $(DESTDIR)$(SBINDIR)/$(BINM_CATMAN)
465	rm -f $(DESTDIR)$(MANDIR)/man8/mandocd.8
466	rm -f $(DESTDIR)$(MANDIR)/man8/$(BINM_CATMAN).8
467	rm -f $(DESTDIR)$(LIBDIR)/libmandoc.a
468	rm -f $(DESTDIR)$(MANDIR)/man3/mandoc.3
469	rm -f $(DESTDIR)$(MANDIR)/man3/mandoc_escape.3
470	rm -f $(DESTDIR)$(MANDIR)/man3/mandoc_malloc.3
471	rm -f $(DESTDIR)$(MANDIR)/man3/mansearch.3
472	rm -f $(DESTDIR)$(MANDIR)/man3/mchars_alloc.3
473	rm -f $(DESTDIR)$(MANDIR)/man3/tbl.3
474	rm -f $(DESTDIR)$(INCLUDEDIR)/man.h
475	rm -f $(DESTDIR)$(INCLUDEDIR)/mandoc.h
476	rm -f $(DESTDIR)$(INCLUDEDIR)/mandoc_aux.h
477	rm -f $(DESTDIR)$(INCLUDEDIR)/mdoc.h
478	rm -f $(DESTDIR)$(INCLUDEDIR)/roff.h
479	[ ! -e $(DESTDIR)$(INCLUDEDIR) ] || rmdir $(DESTDIR)$(INCLUDEDIR)
480
481regress: all
482	cd regress && ./regress.pl
483
484regress-clean:
485	cd regress && ./regress.pl . clean
486
487Makefile.local config.h: configure $(TESTSRCS)
488	@echo "$@ is out of date; please run ./configure"
489	@exit 1
490
491libmandoc.a: $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
492	ar rs $@ $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
493
494mandoc: $(MAIN_OBJS) libmandoc.a
495	$(CC) -o $@ $(LDFLAGS) $(MAIN_OBJS) libmandoc.a $(LDADD)
496
497man.cgi: $(CGI_OBJS) libmandoc.a
498	$(CC) $(STATIC) -o $@ $(LDFLAGS) $(CGI_OBJS) libmandoc.a $(LDADD)
499
500mandocd: $(MANDOCD_OBJS) libmandoc.a
501	$(CC) -o $@ $(LDFLAGS) $(MANDOCD_OBJS) libmandoc.a $(LDADD)
502
503catman: catman.o libmandoc.a
504	$(CC) -o $@ $(LDFLAGS) catman.o libmandoc.a $(LDADD)
505
506demandoc: $(DEMANDOC_OBJS) libmandoc.a
507	$(CC) -o $@ $(LDFLAGS) $(DEMANDOC_OBJS) libmandoc.a $(LDADD)
508
509soelim: $(SOELIM_OBJS)
510	$(CC) -o $@ $(LDFLAGS) $(SOELIM_OBJS)
511
512# --- maintainer targets ---
513
514www-install: www
515	$(INSTALL_DATA) $(WWW_MANS) mandoc.css $(HTDOCDIR)
516
517depend: config.h
518	mkdep -f Makefile.depend $(CFLAGS) $(SRCS)
519	perl -e 'undef $$/; $$_ = <>; s|/usr/include/\S+||g; \
520		s|\\\n||g; s|  +| |g; s| $$||mg; print;' \
521		Makefile.depend > Makefile.tmp
522	mv Makefile.tmp Makefile.depend
523
524regress-distclean:
525	@find regress \
526		-name '.#*' -o \
527		-name '*.orig' -o \
528		-name '*.rej' -o \
529		-name '*.core' \
530		-exec rm -i {} \;
531
532regress-distcheck:
533	@find regress ! -type d ! -type f
534	@find regress -type f \
535		! -path '*/CVS/*' \
536		! -name Makefile \
537		! -name Makefile.inc \
538		! -name '*.in' \
539		! -name '*.out_ascii' \
540		! -name '*.out_utf8' \
541		! -name '*.out_html' \
542		! -name '*.out_markdown' \
543		! -name '*.out_lint' \
544		! -path regress/regress.pl \
545		! -path regress/regress.pl.1
546
547dist: mandoc.sha256
548
549mandoc.sha256: mandoc.tar.gz
550	sha256 mandoc.tar.gz > $@
551
552mandoc.tar.gz: $(DISTFILES)
553	ls regress/*/*/*.mandoc_* && exit 1 || true
554	mkdir -p .dist/mandoc-$(VERSION)/
555	$(INSTALL) -m 0644 $(DISTFILES) .dist/mandoc-$(VERSION)
556	cp -pR regress .dist/mandoc-$(VERSION)
557	find .dist/mandoc-$(VERSION)/regress \
558	    -type d -name CVS -print0 | xargs -0 rm -rf
559	chmod 755 .dist/mandoc-$(VERSION)/configure
560	( cd .dist/ && tar zcf ../$@ mandoc-$(VERSION) )
561	rm -rf .dist/
562
563# === SUFFIX RULES =====================================================
564
565.SUFFIXES:	 .1       .3       .5       .7       .8       .h
566.SUFFIXES:	 .1.html  .3.html  .5.html  .7.html  .8.html  .h.html
567
568.h.h.html:
569	highlight -I $< > $@
570
571.1.1.html .3.3.html .5.5.html .7.7.html .8.8.html: mandoc
572	./mandoc -Thtml -Wall,stop \
573		-Ostyle=mandoc.css,man=%N.%S.html,includes=%I.html $< > $@
574