1 # $Id: Makefile,v 1.435 2014/08/10 02:45:04 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 # 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
60 BUILD_TARGETS += db-build
62 # The remaining settings in this section
63 # are only relevant if db-build is enabled.
64 # Otherwise, they have no effect either way.
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.
70 #CFLAGS += -DUSE_MANPATH
72 # On some systems, SQLite3 may be installed below /usr/local.
73 # In that case, uncomment the following two lines.
75 #CFLAGS += -I/usr/local/include
76 #DBLIB += -L/usr/local/lib
78 # OpenBSD has the ohash functions in libutil.
79 # Comment the following line if your system doesn't.
83 SBINDIR = $(PREFIX)/sbin
85 # --- user settings related to man.cgi ---------------------------------
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.
91 #BUILD_TARGETS += cgi-build
93 # The remaining settings in this section
94 # are only relevant if cgi-build is enabled.
95 # Otherwise, they have no effect either way.
97 # If your system does not support static binaries, comment this,
98 # for example on Mac OS X.
102 # Linux requires -pthread for statical linking.
107 HTDOCDIR = $(WWWPREFIX)/htdocs
108 CGIBINDIR = $(WWWPREFIX)/cgi-bin
110 # === END OF USER SETTINGS =============================================
112 INSTALL_TARGETS = $(BUILD_TARGETS:-build=-install)
114 BASEBIN = mandoc preconv demandoc
115 DBBIN = apropos makewhatis
120 TESTSRCS = test-fgetln.c \
124 test-reallocarray.c \
125 test-sqlite3_errstr.c \
140 compat_reallocarray.c \
141 compat_sqlite3_errstr.c \
142 compat_strcasestr.c \
193 DISTFILES = INSTALL \
252 LIBMAN_OBJS = man.o \
257 LIBMDOC_OBJS = arch.o \
268 LIBROFF_OBJS = eqn.o \
275 LIBMANDOC_OBJS = $(LIBMAN_OBJS) \
284 COMPAT_OBJS = compat_fgetln.o \
287 compat_reallocarray.o \
288 compat_sqlite3_errstr.o \
289 compat_strcasestr.o \
294 MANDOC_HTML_OBJS = eqn_html.o \
300 MANDOC_MAN_OBJS = mdoc_man.o
302 MANDOC_TERM_OBJS = eqn_term.o \
310 MANDOC_OBJS = $(MANDOC_HTML_OBJS) \
312 $(MANDOC_TERM_OBJS) \
317 MAKEWHATIS_OBJS = mandocdb.o mansearch_const.o manpath.o
319 PRECONV_OBJS = preconv.o
321 APROPOS_OBJS = apropos.o mansearch.o mansearch_const.o manpath.o
323 CGI_OBJS = $(MANDOC_HTML_OBJS) \
329 MANPAGE_OBJS = manpage.o mansearch.o mansearch_const.o manpath.o
331 DEMANDOC_OBJS = demandoc.o
333 WWW_MANS = apropos.1.html \
338 mandoc_escape.3.html \
340 mandoc_malloc.3.html \
342 mchars_alloc.3.html \
360 WWW_OBJS = mdocml.tar.gz \
363 # === DEPENDENCY HANDLING ==============================================
365 all: base-build $(BUILD_TARGETS)
367 base-build: $(BASEBIN)
373 install: base-install $(INSTALL_TARGETS)
375 www: $(WWW_OBJS) $(WWW_MANS)
377 include Makefile.depend
379 # === TARGETS CONTAINING SHELL COMMANDS ================================
382 rm -f libmandoc.a $(LIBMANDOC_OBJS)
383 rm -f apropos $(APROPOS_OBJS)
384 rm -f makewhatis $(MAKEWHATIS_OBJS)
385 rm -f preconv $(PRECONV_OBJS)
386 rm -f man.cgi $(CGI_OBJS)
387 rm -f manpage $(MANPAGE_OBJS)
388 rm -f demandoc $(DEMANDOC_OBJS)
389 rm -f mandoc $(MANDOC_OBJS)
390 rm -f config.log $(COMPAT_OBJS)
391 rm -f $(WWW_MANS) $(WWW_OBJS)
394 base-install: base-build
395 mkdir -p $(DESTDIR)$(BINDIR)
396 mkdir -p $(DESTDIR)$(EXAMPLEDIR)
397 mkdir -p $(DESTDIR)$(LIBDIR)
398 mkdir -p $(DESTDIR)$(INCLUDEDIR)
399 mkdir -p $(DESTDIR)$(MANDIR)/man1
400 mkdir -p $(DESTDIR)$(MANDIR)/man3
401 mkdir -p $(DESTDIR)$(MANDIR)/man7
402 $(INSTALL_PROGRAM) $(BASEBIN) $(DESTDIR)$(BINDIR)
403 $(INSTALL_LIB) libmandoc.a $(DESTDIR)$(LIBDIR)
404 $(INSTALL_LIB) man.h mandoc.h mandoc_aux.h mdoc.h \
405 $(DESTDIR)$(INCLUDEDIR)
406 $(INSTALL_MAN) mandoc.1 preconv.1 demandoc.1 $(DESTDIR)$(MANDIR)/man1
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
411 $(INSTALL_DATA) example.style.css $(DESTDIR)$(EXAMPLEDIR)
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
430 cgi-install: cgi-build
431 mkdir -p $(DESTDIR)$(CGIBINDIR)
432 mkdir -p $(DESTDIR)$(HTDOCDIR)
433 mkdir -p $(DESTDIR)$(WWWPREFIX)/man/mandoc/man1
434 mkdir -p $(DESTDIR)$(WWWPREFIX)/man/mandoc/man8
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)
438 $(INSTALL_MAN) apropos.1 $(DESTDIR)$(WWWPREFIX)/man/mandoc/man1/
439 $(INSTALL_MAN) man.cgi.8 $(DESTDIR)$(WWWPREFIX)/man/mandoc/man8/
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
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
456 libmandoc.a: $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
457 $(AR) rs $@ $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
459 mandoc: $(MANDOC_OBJS) libmandoc.a
460 $(CC) $(LDFLAGS) -o $@ $(MANDOC_OBJS) libmandoc.a
462 makewhatis: $(MAKEWHATIS_OBJS) libmandoc.a
463 $(CC) $(LDFLAGS) -o $@ $(MAKEWHATIS_OBJS) libmandoc.a $(DBLIB)
465 preconv: $(PRECONV_OBJS)
466 $(CC) $(LDFLAGS) -o $@ $(PRECONV_OBJS)
468 manpage: $(MANPAGE_OBJS) libmandoc.a
469 $(CC) $(LDFLAGS) -o $@ $(MANPAGE_OBJS) libmandoc.a $(DBLIB)
471 apropos: $(APROPOS_OBJS) libmandoc.a
472 $(CC) $(LDFLAGS) -o $@ $(APROPOS_OBJS) libmandoc.a $(DBLIB)
474 man.cgi: $(CGI_OBJS) libmandoc.a
475 $(CC) $(LDFLAGS) $(STATIC) -o $@ $(CGI_OBJS) libmandoc.a $(DBLIB)
477 demandoc: $(DEMANDOC_OBJS) libmandoc.a
478 $(CC) $(LDFLAGS) -o $@ $(DEMANDOC_OBJS) libmandoc.a
480 mdocml.sha256: mdocml.tar.gz
481 sha256 mdocml.tar.gz > $@
483 mdocml.tar.gz: $(DISTFILES)
484 mkdir -p .dist/mdocml-$(VERSION)/
485 $(INSTALL_SOURCE) $(DISTFILES) .dist/mdocml-$(VERSION)
486 chmod 755 .dist/mdocml-$(VERSION)/configure
487 ( cd .dist/ && tar zcf ../$@ mdocml-$(VERSION) )
490 config.h: configure config.h.pre config.h.post $(TESTSRCS)
492 CC="$(CC)" CFLAGS="$(CFLAGS)" DBLIB="$(DBLIB)" \
493 VERSION="$(VERSION)" ./configure
495 .PHONY: base-install cgi-install db-install install www-install
497 .SUFFIXES: .1 .3 .5 .7 .8 .h
498 .SUFFIXES: .1.html .3.html .5.html .7.html .8.html .h.html
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 $< > $@