Import mdocml-1.12.2
[dragonfly.git] / contrib / mdocml / Makefile
1 .PHONY:          clean install installwww
2 .SUFFIXES:       .sgml .html .md5 .h .h.html
3 .SUFFIXES:       .1       .3       .7       .8
4 .SUFFIXES:       .1.html  .3.html  .7.html  .8.html
5
6 # Specify this if you want to hard-code the operating system to appear
7 # in the lower-left hand corner of -mdoc manuals.
8 #
9 # CFLAGS        += -DOSNAME="\"OpenBSD 5.4\""
10
11 VERSION          = 1.12.2
12 VDATE            = 05 October 2013
13
14 # IFF your system supports multi-byte functions (setlocale(), wcwidth(),
15 # putwchar()) AND has __STDC_ISO_10646__ (that is, wchar_t is simply a
16 # UCS-4 value) should you define USE_WCHAR.  If you define it and your
17 # system DOESN'T support this, -Tlocale will produce garbage.
18 # If you don't define it, -Tlocale is a synonym for -Tacsii.
19 #
20 CFLAGS          += -DUSE_WCHAR
21
22 # If your system has manpath(1), uncomment this.  This is most any
23 # system that's not OpenBSD or NetBSD.  If uncommented, apropos(1),
24 # mandocdb(8), and man.cgi will popen(3) manpath(1) to get the MANPATH
25 # variable.
26 #CFLAGS         += -DUSE_MANPATH
27
28 # If your system does not support static binaries, comment this,
29 # for example on Mac OS X.
30 STATIC           = -static
31 # Linux requires -pthread to statically link with libdb.
32 #STATIC         += -pthread
33
34 CFLAGS          += -g -DHAVE_CONFIG_H -DVERSION="\"$(VERSION)\""
35 CFLAGS          += -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings
36 PREFIX           = /usr/local
37 WWWPREFIX        = /var/www
38 HTDOCDIR         = $(WWWPREFIX)/htdocs
39 CGIBINDIR        = $(WWWPREFIX)/cgi-bin
40 BINDIR           = $(PREFIX)/bin
41 INCLUDEDIR       = $(PREFIX)/include/mandoc
42 LIBDIR           = $(PREFIX)/lib/mandoc
43 MANDIR           = $(PREFIX)/man
44 EXAMPLEDIR       = $(PREFIX)/share/examples/mandoc
45 INSTALL          = install
46 INSTALL_PROGRAM  = $(INSTALL) -m 0755
47 INSTALL_DATA     = $(INSTALL) -m 0444
48 INSTALL_LIB      = $(INSTALL) -m 0644
49 INSTALL_SOURCE   = $(INSTALL) -m 0644
50 INSTALL_MAN      = $(INSTALL_DATA)
51
52 # Non-BSD systems (Linux, etc.) need -ldb to compile mandocdb and
53 # apropos.
54 # However, if you don't have -ldb at all (or it's not native), then
55 # comment out apropos and mandocdb. 
56 #
57 #DBLIB           = -ldb
58 DBBIN            = apropos mandocdb man.cgi catman whatis
59 DBLN             = llib-lapropos.ln llib-lmandocdb.ln llib-lman.cgi.ln llib-lcatman.ln
60
61 all: mandoc preconv demandoc $(DBBIN)
62
63 SRCS             = Makefile \
64                    NEWS \
65                    TODO \
66                    apropos.1 \
67                    apropos.c \
68                    apropos_db.c \
69                    apropos_db.h \
70                    arch.c \
71                    arch.in \
72                    att.c \
73                    att.in \
74                    catman.8 \
75                    catman.c \
76                    cgi.c \
77                    chars.c \
78                    chars.in \
79                    compat_fgetln.c \
80                    compat_getsubopt.c \
81                    compat_strlcat.c \
82                    compat_strlcpy.c \
83                    config.h.post \
84                    config.h.pre \
85                    demandoc.1 \
86                    demandoc.c \
87                    eqn.7 \
88                    eqn.c \
89                    eqn_html.c \
90                    eqn_term.c \
91                    example.style.css \
92                    external.png \
93                    gmdiff \
94                    html.c \
95                    html.h \
96                    index.css \
97                    index.sgml \
98                    lib.c \
99                    lib.in \
100                    libman.h \
101                    libmandoc.h \
102                    libmdoc.h \
103                    libroff.h \
104                    main.c \
105                    main.h \
106                    man.7 \
107                    man.c \
108                    man.cgi.7 \
109                    man-cgi.css \
110                    man.h \
111                    man_hash.c \
112                    man_html.c \
113                    man_macro.c \
114                    man_term.c \
115                    man_validate.c \
116                    mandoc.1 \
117                    mandoc.3 \
118                    mandoc.c \
119                    mandoc.h \
120                    mandoc_char.7 \
121                    mandocdb.8 \
122                    mandocdb.c \
123                    mandocdb.h \
124                    manpath.c \
125                    manpath.h \
126                    mdoc.7 \
127                    mdoc.c \
128                    mdoc.h \
129                    mdoc_argv.c \
130                    mdoc_hash.c \
131                    mdoc_html.c \
132                    mdoc_macro.c \
133                    mdoc_man.c \
134                    mdoc_term.c \
135                    mdoc_validate.c \
136                    msec.c \
137                    msec.in \
138                    out.c \
139                    out.h \
140                    preconv.1 \
141                    preconv.c \
142                    predefs.in \
143                    read.c \
144                    roff.7 \
145                    roff.c \
146                    st.c \
147                    st.in \
148                    style.css \
149                    tbl.3 \
150                    tbl.7 \
151                    tbl.c \
152                    tbl_data.c \
153                    tbl_html.c \
154                    tbl_layout.c \
155                    tbl_opts.c \
156                    tbl_term.c \
157                    term.c \
158                    term.h \
159                    term_ascii.c \
160                    term_ps.c \
161                    test-betoh64.c \
162                    test-fgetln.c \
163                    test-getsubopt.c \
164                    test-mmap.c \
165                    test-strlcat.c \
166                    test-strlcpy.c \
167                    test-strptime.c \
168                    tree.c \
169                    vol.c \
170                    vol.in \
171                    whatis.1
172
173 LIBMAN_OBJS      = man.o \
174                    man_hash.o \
175                    man_macro.o \
176                    man_validate.o
177
178 LIBMDOC_OBJS     = arch.o \
179                    att.o \
180                    lib.o \
181                    mdoc.o \
182                    mdoc_argv.o \
183                    mdoc_hash.o \
184                    mdoc_macro.o \
185                    mdoc_validate.o \
186                    st.o \
187                    vol.o
188
189 LIBROFF_OBJS     = eqn.o \
190                    roff.o \
191                    tbl.o \
192                    tbl_data.o \
193                    tbl_layout.o \
194                    tbl_opts.o
195
196 LIBMANDOC_OBJS   = $(LIBMAN_OBJS) \
197                    $(LIBMDOC_OBJS) \
198                    $(LIBROFF_OBJS) \
199                    chars.o \
200                    mandoc.o \
201                    msec.o \
202                    read.o
203
204 COMPAT_OBJS      = compat_fgetln.o \
205                    compat_getsubopt.o \
206                    compat_strlcat.o \
207                    compat_strlcpy.o
208
209 arch.o: arch.in
210 att.o: att.in
211 chars.o: chars.in
212 lib.o: lib.in
213 msec.o: msec.in
214 roff.o: predefs.in
215 st.o: st.in
216 vol.o: vol.in
217
218 $(LIBMAN_OBJS): libman.h
219 $(LIBMDOC_OBJS): libmdoc.h
220 $(LIBROFF_OBJS): libroff.h
221 $(LIBMANDOC_OBJS): mandoc.h mdoc.h man.h libmandoc.h config.h
222 $(COMPAT_OBJS): config.h
223
224 MANDOC_HTML_OBJS = eqn_html.o \
225                    html.o \
226                    man_html.o \
227                    mdoc_html.o \
228                    tbl_html.o
229 $(MANDOC_HTML_OBJS): html.h
230
231 MANDOC_MAN_OBJS  = mdoc_man.o
232
233 MANDOC_TERM_OBJS = eqn_term.o \
234                    man_term.o \
235                    mdoc_term.o \
236                    term.o \
237                    term_ascii.o \
238                    term_ps.o \
239                    tbl_term.o
240 $(MANDOC_TERM_OBJS): term.h
241
242 MANDOC_OBJS      = $(MANDOC_HTML_OBJS) \
243                    $(MANDOC_MAN_OBJS) \
244                    $(MANDOC_TERM_OBJS) \
245                    main.o \
246                    out.o \
247                    tree.o
248 $(MANDOC_OBJS): main.h mandoc.h mdoc.h man.h config.h out.h
249
250 MANDOCDB_OBJS    = mandocdb.o manpath.o
251 $(MANDOCDB_OBJS): mandocdb.h mandoc.h mdoc.h man.h config.h manpath.h
252
253 PRECONV_OBJS     = preconv.o
254 $(PRECONV_OBJS): config.h
255
256 APROPOS_OBJS     = apropos.o apropos_db.o manpath.o
257 $(APROPOS_OBJS): config.h mandoc.h apropos_db.h manpath.h mandocdb.h
258
259 CGI_OBJS         = $(MANDOC_HTML_OBJS) \
260                    $(MANDOC_MAN_OBJS) \
261                    $(MANDOC_TERM_OBJS) \
262                    cgi.o \
263                    apropos_db.o \
264                    manpath.o \
265                    out.o \
266                    tree.o
267 $(CGI_OBJS): main.h mdoc.h man.h out.h config.h mandoc.h apropos_db.h manpath.h mandocdb.h
268
269 CATMAN_OBJS      = catman.o manpath.o
270 $(CATMAN_OBJS): config.h mandoc.h manpath.h mandocdb.h
271
272 DEMANDOC_OBJS    = demandoc.o
273 $(DEMANDOC_OBJS): config.h
274
275 INDEX_MANS       = apropos.1.html \
276                    catman.8.html \
277                    demandoc.1.html \
278                    mandoc.1.html \
279                    whatis.1.html \
280                    mandoc.3.html \
281                    tbl.3.html \
282                    eqn.7.html \
283                    man.7.html \
284                    man.cgi.7.html \
285                    mandoc_char.7.html \
286                    mdoc.7.html \
287                    preconv.1.html \
288                    roff.7.html \
289                    tbl.7.html \
290                    mandocdb.8.html
291
292 $(INDEX_MANS): mandoc
293
294 INDEX_OBJS       = $(INDEX_MANS) \
295                    man.h.html \
296                    mandoc.h.html \
297                    mdoc.h.html \
298                    mdocml.tar.gz \
299                    mdocml.md5
300
301 www: index.html
302
303 clean:
304         rm -f libmandoc.a $(LIBMANDOC_OBJS)
305         rm -f mandocdb $(MANDOCDB_OBJS)
306         rm -f preconv $(PRECONV_OBJS)
307         rm -f apropos whatis $(APROPOS_OBJS)
308         rm -f man.cgi $(CGI_OBJS)
309         rm -f catman $(CATMAN_OBJS)
310         rm -f demandoc $(DEMANDOC_OBJS)
311         rm -f mandoc $(MANDOC_OBJS)
312         rm -f config.h config.log $(COMPAT_OBJS)
313         rm -f mdocml.tar.gz
314         rm -f index.html $(INDEX_OBJS)
315         rm -rf *.dSYM
316
317 install: all
318         mkdir -p $(DESTDIR)$(BINDIR)
319         mkdir -p $(DESTDIR)$(EXAMPLEDIR)
320         mkdir -p $(DESTDIR)$(LIBDIR)
321         mkdir -p $(DESTDIR)$(INCLUDEDIR)
322         mkdir -p $(DESTDIR)$(MANDIR)/man1
323         mkdir -p $(DESTDIR)$(MANDIR)/man3
324         mkdir -p $(DESTDIR)$(MANDIR)/man7
325         $(INSTALL_PROGRAM) mandoc preconv demandoc $(DESTDIR)$(BINDIR)
326         $(INSTALL_LIB) libmandoc.a $(DESTDIR)$(LIBDIR)
327         $(INSTALL_LIB) man.h mdoc.h mandoc.h $(DESTDIR)$(INCLUDEDIR)
328         $(INSTALL_MAN) mandoc.1 preconv.1 demandoc.1 $(DESTDIR)$(MANDIR)/man1
329         $(INSTALL_MAN) mandoc.3 tbl.3 $(DESTDIR)$(MANDIR)/man3
330         $(INSTALL_MAN) man.7 mdoc.7 roff.7 eqn.7 tbl.7 mandoc_char.7 $(DESTDIR)$(MANDIR)/man7
331         $(INSTALL_DATA) example.style.css $(DESTDIR)$(EXAMPLEDIR)
332
333 installcgi: all
334         mkdir -p $(DESTDIR)$(CGIBINDIR)
335         mkdir -p $(DESTDIR)$(HTDOCDIR)
336         $(INSTALL_PROGRAM) man.cgi $(DESTDIR)$(CGIBINDIR)
337         $(INSTALL_DATA) example.style.css $(DESTDIR)$(HTDOCDIR)/man.css
338         $(INSTALL_DATA) man-cgi.css $(DESTDIR)$(HTDOCDIR)
339
340 installwww: www
341         mkdir -p $(PREFIX)/snapshots
342         mkdir -p $(PREFIX)/binaries
343         $(INSTALL_DATA) index.html external.png index.css $(PREFIX)
344         $(INSTALL_DATA) $(INDEX_MANS) style.css $(PREFIX)
345         $(INSTALL_DATA) mandoc.h.html man.h.html mdoc.h.html $(PREFIX)
346         $(INSTALL_DATA) mdocml.tar.gz $(PREFIX)/snapshots
347         $(INSTALL_DATA) mdocml.md5 $(PREFIX)/snapshots
348         $(INSTALL_DATA) mdocml.tar.gz $(PREFIX)/snapshots/mdocml-$(VERSION).tar.gz
349         $(INSTALL_DATA) mdocml.md5 $(PREFIX)/snapshots/mdocml-$(VERSION).md5
350
351 libmandoc.a: $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
352         $(AR) rs $@ $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
353
354 mandoc: $(MANDOC_OBJS) libmandoc.a
355         $(CC) $(LDFLAGS) -o $@ $(MANDOC_OBJS) libmandoc.a
356
357 mandocdb: $(MANDOCDB_OBJS) libmandoc.a
358         $(CC) $(LDFLAGS) -o $@ $(MANDOCDB_OBJS) libmandoc.a $(DBLIB)
359
360 preconv: $(PRECONV_OBJS)
361         $(CC) $(LDFLAGS) -o $@ $(PRECONV_OBJS)
362
363 whatis: apropos
364         cp -f apropos whatis
365
366 apropos: $(APROPOS_OBJS) libmandoc.a
367         $(CC) $(LDFLAGS) -o $@ $(APROPOS_OBJS) libmandoc.a $(DBLIB)
368
369 catman: $(CATMAN_OBJS) libmandoc.a
370         $(CC) $(LDFLAGS) -o $@ $(CATMAN_OBJS) libmandoc.a $(DBLIB)
371
372 man.cgi: $(CGI_OBJS) libmandoc.a
373         $(CC) $(LDFLAGS) $(STATIC) -o $@ $(CGI_OBJS) libmandoc.a $(DBLIB)
374
375 demandoc: $(DEMANDOC_OBJS) libmandoc.a
376         $(CC) $(LDFLAGS) -o $@ $(DEMANDOC_OBJS) libmandoc.a
377
378 mdocml.md5: mdocml.tar.gz
379         md5 mdocml.tar.gz >$@
380
381 mdocml.tar.gz: $(SRCS)
382         mkdir -p .dist/mdocml-$(VERSION)/
383         $(INSTALL_SOURCE) $(SRCS) .dist/mdocml-$(VERSION)
384         ( cd .dist/ && tar zcf ../$@ ./ )
385         rm -rf .dist/
386
387 index.html: $(INDEX_OBJS)
388
389 config.h: config.h.pre config.h.post
390         rm -f config.log
391         ( cat config.h.pre; \
392           echo; \
393           if $(CC) $(CFLAGS) -Werror -o test-fgetln test-fgetln.c >> config.log 2>&1; then \
394                 echo '#define HAVE_FGETLN'; \
395                 rm test-fgetln; \
396           fi; \
397           if $(CC) $(CFLAGS) -Werror -o test-strptime test-strptime.c >> config.log 2>&1; then \
398                 echo '#define HAVE_STRPTIME'; \
399                 rm test-strptime; \
400           fi; \
401           if $(CC) $(CFLAGS) -Werror -o test-getsubopt test-getsubopt.c >> config.log 2>&1; then \
402                 echo '#define HAVE_GETSUBOPT'; \
403                 rm test-getsubopt; \
404           fi; \
405           if $(CC) $(CFLAGS) -Werror -o test-strlcat test-strlcat.c >> config.log 2>&1; then \
406                 echo '#define HAVE_STRLCAT'; \
407                 rm test-strlcat; \
408           fi; \
409           if $(CC) $(CFLAGS) -Werror -o test-mmap test-mmap.c >> config.log 2>&1; then \
410                 echo '#define HAVE_MMAP'; \
411                 rm test-mmap; \
412           fi; \
413           if $(CC) $(CFLAGS) -Werror -o test-strlcpy test-strlcpy.c >> config.log 2>&1; then \
414                 echo '#define HAVE_STRLCPY'; \
415                 rm test-strlcpy; \
416           fi; \
417           if $(CC) $(CFLAGS) -Werror -o test-betoh64 test-betoh64.c >> config.log 2>&1; then \
418                 echo '#define HAVE_BETOH64'; \
419                 rm test-betoh64; \
420           fi; \
421           echo; \
422           cat config.h.post \
423         ) > $@
424
425 .h.h.html:
426         highlight -I $< >$@
427
428 .1.1.html .3.3.html .7.7.html .8.8.html:
429         ./mandoc -Thtml -Wall,stop -Ostyle=style.css,man=%N.%S.html,includes=%I.html $< >$@
430
431 .sgml.html:
432         validate --warn $<
433         sed -e "s!@VERSION@!$(VERSION)!" -e "s!@VDATE@!$(VDATE)!" $< >$@