1 # $Id: Makefile,v 1.430 2014/08/05 05:48:56 schwarze Exp $
3 # Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
4 # Copyright (c) 2011, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
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.
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.
20 # === USER SETTINGS ====================================================
22 # --- user settings relevant for all builds ----------------------------
24 # Specify this if you want to hard-code the operating system to appear
25 # in the lower-left hand corner of -mdoc manuals.
27 # CFLAGS += -DOSNAME="\"OpenBSD 5.5\""
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.
37 CFLAGS += -g -DHAVE_CONFIG_H
38 CFLAGS += -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings
40 BINDIR = $(PREFIX)/bin
41 INCLUDEDIR = $(PREFIX)/include/mandoc
42 LIBDIR = $(PREFIX)/lib/mandoc
43 MANDIR = $(PREFIX)/man
44 EXAMPLEDIR = $(PREFIX)/share/examples/mandoc
47 INSTALL_PROGRAM = $(INSTALL) -m 0555
48 INSTALL_DATA = $(INSTALL) -m 0444
49 INSTALL_LIB = $(INSTALL) -m 0444
50 INSTALL_SOURCE = $(INSTALL) -m 0644
51 INSTALL_MAN = $(INSTALL_DATA)
53 # --- user settings related to database support ------------------------
55 # If you want to build without database support, for example to avoid
56 # the dependency on SQLite3, comment the following line.
57 # However, you won't get apropos(1) and makewhatis(8) in that case.
59 BUILD_TARGETS += db-build
61 # The remaining settings in this section
62 # are only relevant if db-build is enabled.
63 # Otherwise, they have no effect either way.
65 # If your system has manpath(1), uncomment this. This is most any
66 # system that's not OpenBSD or NetBSD. If uncommented, apropos(1)
67 # and makewhatis(8) will use manpath(1) to get the MANPATH variable.
69 #CFLAGS += -DUSE_MANPATH
71 # On some systems, SQLite3 may be installed below /usr/local.
72 # In that case, uncomment the following two lines.
74 #CFLAGS += -I/usr/local/include
75 #DBLIB += -L/usr/local/lib
77 # OpenBSD has the ohash functions in libutil.
78 # Comment the following line if your system doesn't.
82 SBINDIR = $(PREFIX)/sbin
84 # --- user settings related to man.cgi ---------------------------------
86 # To build man.cgi, copy cgi.h.example to cgi.h, edit it,
87 # and enable the following line.
88 # Obviously, this requires that db-build is enabled, too.
90 #BUILD_TARGETS += cgi-build
92 # The remaining settings in this section
93 # are only relevant if cgi-build is enabled.
94 # Otherwise, they have no effect either way.
96 # If your system does not support static binaries, comment this,
97 # for example on Mac OS X.
101 # Linux requires -pthread for statical linking.
106 HTDOCDIR = $(WWWPREFIX)/htdocs
107 CGIBINDIR = $(WWWPREFIX)/cgi-bin
109 # === END OF USER SETTINGS =============================================
111 INSTALL_TARGETS = $(BUILD_TARGETS:-build=-install)
113 BASEBIN = mandoc preconv demandoc
114 DBBIN = apropos makewhatis
119 TESTSRCS = test-fgetln.c \
123 test-reallocarray.c \
138 compat_reallocarray.c \
139 compat_strcasestr.c \
190 DISTFILES = LICENSE \
248 LIBMAN_OBJS = man.o \
253 LIBMDOC_OBJS = arch.o \
264 LIBROFF_OBJS = eqn.o \
271 LIBMANDOC_OBJS = $(LIBMAN_OBJS) \
280 COMPAT_OBJS = compat_fgetln.o \
283 compat_reallocarray.o \
284 compat_strcasestr.o \
289 MANDOC_HTML_OBJS = eqn_html.o \
295 MANDOC_MAN_OBJS = mdoc_man.o
297 MANDOC_TERM_OBJS = eqn_term.o \
305 MANDOC_OBJS = $(MANDOC_HTML_OBJS) \
307 $(MANDOC_TERM_OBJS) \
312 MAKEWHATIS_OBJS = mandocdb.o mansearch_const.o manpath.o
314 PRECONV_OBJS = preconv.o
316 APROPOS_OBJS = apropos.o mansearch.o mansearch_const.o manpath.o
318 CGI_OBJS = $(MANDOC_HTML_OBJS) \
324 MANPAGE_OBJS = manpage.o mansearch.o mansearch_const.o manpath.o
326 DEMANDOC_OBJS = demandoc.o
328 WWW_MANS = apropos.1.html \
333 mandoc_escape.3.html \
335 mandoc_malloc.3.html \
337 mchars_alloc.3.html \
355 WWW_OBJS = mdocml.tar.gz \
358 # === DEPENDENCY HANDLING ==============================================
360 all: base-build $(BUILD_TARGETS)
362 base-build: $(BASEBIN)
368 install: base-install $(INSTALL_TARGETS)
370 www: $(WWW_OBJS) $(WWW_MANS)
372 .include "Makefile.depend"
374 # === TARGETS CONTAINING SHELL COMMANDS ================================
377 rm -f libmandoc.a $(LIBMANDOC_OBJS)
378 rm -f apropos $(APROPOS_OBJS)
379 rm -f makewhatis $(MAKEWHATIS_OBJS)
380 rm -f preconv $(PRECONV_OBJS)
381 rm -f man.cgi $(CGI_OBJS)
382 rm -f manpage $(MANPAGE_OBJS)
383 rm -f demandoc $(DEMANDOC_OBJS)
384 rm -f mandoc $(MANDOC_OBJS)
385 rm -f config.h config.log $(COMPAT_OBJS)
386 rm -f $(WWW_MANS) $(WWW_OBJS)
389 base-install: base-build
390 mkdir -p $(DESTDIR)$(BINDIR)
391 mkdir -p $(DESTDIR)$(EXAMPLEDIR)
392 mkdir -p $(DESTDIR)$(LIBDIR)
393 mkdir -p $(DESTDIR)$(INCLUDEDIR)
394 mkdir -p $(DESTDIR)$(MANDIR)/man1
395 mkdir -p $(DESTDIR)$(MANDIR)/man3
396 mkdir -p $(DESTDIR)$(MANDIR)/man7
397 $(INSTALL_PROGRAM) $(BASEBIN) $(DESTDIR)$(BINDIR)
398 $(INSTALL_LIB) libmandoc.a $(DESTDIR)$(LIBDIR)
399 $(INSTALL_LIB) man.h mandoc.h mandoc_aux.h mdoc.h \
400 $(DESTDIR)$(INCLUDEDIR)
401 $(INSTALL_MAN) mandoc.1 preconv.1 demandoc.1 $(DESTDIR)$(MANDIR)/man1
402 $(INSTALL_MAN) mandoc.3 mandoc_escape.3 mandoc_malloc.3 \
403 mchars_alloc.3 tbl.3 $(DESTDIR)$(MANDIR)/man3
404 $(INSTALL_MAN) man.7 mdoc.7 roff.7 eqn.7 tbl.7 mandoc_char.7 \
405 $(DESTDIR)$(MANDIR)/man7
406 $(INSTALL_DATA) example.style.css $(DESTDIR)$(EXAMPLEDIR)
409 mkdir -p $(DESTDIR)$(BINDIR)
410 mkdir -p $(DESTDIR)$(SBINDIR)
411 mkdir -p $(DESTDIR)$(MANDIR)/man1
412 mkdir -p $(DESTDIR)$(MANDIR)/man3
413 mkdir -p $(DESTDIR)$(MANDIR)/man5
414 mkdir -p $(DESTDIR)$(MANDIR)/man8
415 $(INSTALL_PROGRAM) apropos $(DESTDIR)$(BINDIR)
416 ln -f $(DESTDIR)$(BINDIR)/apropos $(DESTDIR)$(BINDIR)/whatis
417 $(INSTALL_PROGRAM) makewhatis $(DESTDIR)$(SBINDIR)
418 $(INSTALL_MAN) apropos.1 $(DESTDIR)$(MANDIR)/man1
419 ln -f $(DESTDIR)$(MANDIR)/man1/apropos.1 \
420 $(DESTDIR)$(MANDIR)/man1/whatis.1
421 $(INSTALL_MAN) mansearch.3 $(DESTDIR)$(MANDIR)/man3
422 $(INSTALL_MAN) mandoc.db.5 $(DESTDIR)$(MANDIR)/man5
423 $(INSTALL_MAN) makewhatis.8 $(DESTDIR)$(MANDIR)/man8
425 cgi-install: cgi-build
426 mkdir -p $(DESTDIR)$(CGIBINDIR)
427 mkdir -p $(DESTDIR)$(HTDOCDIR)
428 mkdir -p $(DESTDIR)$(WWWPREFIX)/man/mandoc/man1
429 mkdir -p $(DESTDIR)$(WWWPREFIX)/man/mandoc/man8
430 $(INSTALL_PROGRAM) man.cgi $(DESTDIR)$(CGIBINDIR)
431 $(INSTALL_DATA) example.style.css $(DESTDIR)$(HTDOCDIR)/man.css
432 $(INSTALL_DATA) man-cgi.css $(DESTDIR)$(HTDOCDIR)
433 $(INSTALL_MAN) apropos.1 $(DESTDIR)$(WWWPREFIX)/man/mandoc/man1/
434 $(INSTALL_MAN) man.cgi.8 $(DESTDIR)$(WWWPREFIX)/man/mandoc/man8/
437 mkdir -p $(DESTDIR)$(HTDOCDIR)/snapshots
438 $(INSTALL_DATA) $(WWW_MANS) style.css $(DESTDIR)$(HTDOCDIR)
439 $(INSTALL_DATA) $(WWW_OBJS) $(DESTDIR)$(HTDOCDIR)/snapshots
440 $(INSTALL_DATA) mdocml.tar.gz \
441 $(DESTDIR)$(HTDOCDIR)/snapshots/mdocml-$(VERSION).tar.gz
442 $(INSTALL_DATA) mdocml.sha256 \
443 $(DESTDIR)$(HTDOCDIR)/snapshots/mdocml-$(VERSION).sha256
445 Makefile.depend: $(SRCS) config.h Makefile
446 mkdep -f Makefile.depend $(CFLAGS) $(SRCS)
447 perl -e 'undef $$/; $$_ = <>; s|/usr/include/\S+||g; \
448 s|\\\n||g; s| +| |g; print;' Makefile.depend > Makefile.tmp
449 mv Makefile.tmp Makefile.depend
451 libmandoc.a: $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
452 $(AR) rs $@ $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
454 mandoc: $(MANDOC_OBJS) libmandoc.a
455 $(CC) $(LDFLAGS) -o $@ $(MANDOC_OBJS) libmandoc.a
457 makewhatis: $(MAKEWHATIS_OBJS) libmandoc.a
458 $(CC) $(LDFLAGS) -o $@ $(MAKEWHATIS_OBJS) libmandoc.a $(DBLIB)
460 preconv: $(PRECONV_OBJS)
461 $(CC) $(LDFLAGS) -o $@ $(PRECONV_OBJS)
463 manpage: $(MANPAGE_OBJS) libmandoc.a
464 $(CC) $(LDFLAGS) -o $@ $(MANPAGE_OBJS) libmandoc.a $(DBLIB)
466 apropos: $(APROPOS_OBJS) libmandoc.a
467 $(CC) $(LDFLAGS) -o $@ $(APROPOS_OBJS) libmandoc.a $(DBLIB)
469 man.cgi: $(CGI_OBJS) libmandoc.a
470 $(CC) $(LDFLAGS) $(STATIC) -o $@ $(CGI_OBJS) libmandoc.a $(DBLIB)
472 demandoc: $(DEMANDOC_OBJS) libmandoc.a
473 $(CC) $(LDFLAGS) -o $@ $(DEMANDOC_OBJS) libmandoc.a
475 mdocml.sha256: mdocml.tar.gz
476 sha256 mdocml.tar.gz > $@
478 mdocml.tar.gz: $(DISTFILES)
479 mkdir -p .dist/mdocml-$(VERSION)/
480 $(INSTALL_SOURCE) $(DISTFILES) .dist/mdocml-$(VERSION)
481 chmod 755 .dist/mdocml-$(VERSION)/configure
482 ( cd .dist/ && tar zcf ../$@ mdocml-$(VERSION) )
485 config.h: configure config.h.pre config.h.post $(TESTSRCS)
487 CC="$(CC)" CFLAGS="$(CFLAGS)" VERSION="$(VERSION)" ./configure
489 .PHONY: base-install clean cgi-install db-install install www-install
490 .SUFFIXES: .1 .3 .5 .7 .8 .h
491 .SUFFIXES: .1.html .3.html .5.html .7.html .8.html .h.html
496 .1.1.html .3.3.html .5.5.html .7.7.html .8.8.html: mandoc
497 ./mandoc -Thtml -Wall,stop \
498 -Ostyle=style.css,man=%N.%S.html,includes=%I.html $< > $@