Home | History | Annotate | Line # | Download | only in mk
      1  1.69    rillig #	$NetBSD: bsd.doc.mk,v 1.69 2025/04/11 19:15:42 rillig Exp $
      2  1.19       cgd #	@(#)bsd.doc.mk	8.1 (Berkeley) 8/14/93
      3   1.1       cgd 
      4  1.53        tv .include <bsd.init.mk>
      5  1.28   mycroft 
      6  1.65  dholland # The makefile should set these:
      7  1.65  dholland #   SECTION		one of usd, smm, or psd (lower-case)
      8  1.65  dholland #   ARTICLE		name of this document
      9  1.65  dholland #   SRCS		roff source files
     10  1.65  dholland #   DEPSRCS		additional roff source files implicitly included
     11  1.65  dholland #   MACROS		name(s) of roff macro packages, including the -m
     12  1.65  dholland #   ROFF_PIC		set to "yes" to use pic(1)
     13  1.65  dholland #   ROFF_EQN		set to "yes" to use eqn(1)
     14  1.65  dholland #   ROFF_TBL		set to "yes" to use tbl(1)
     15  1.65  dholland #   ROFF_REFER		set to "yes" to use refer(1)
     16  1.65  dholland #   EXTRAHTMLFILES	additional files emitted as part of HTML build
     17  1.65  dholland #
     18  1.65  dholland #   PAGES		unknown (XXX)
     19  1.65  dholland #   EXTRA		extra files to install (XXX)
     20  1.65  dholland #
     21  1.65  dholland # If there are multiple docs to be generated, set these:
     22  1.65  dholland #   SUBARTICLES=	name1 name2 ...
     23  1.65  dholland #   SRCS.name1=		roff source files
     24  1.65  dholland #   SRCS.name2=		more roff source files
     25  1.65  dholland #   SRCS.  :  =		  :
     26  1.65  dholland #   DEPSRCS.name1=	additional included roff source files
     27  1.65  dholland #   DEPSRCS.name2=	more additional included roff source files
     28  1.65  dholland #   DEPSRCS.  :  =	  :
     29  1.65  dholland #
     30  1.65  dholland # I'm hoping that MACROS and ROFF_* can be uniform across all
     31  1.65  dholland # subarticles.
     32  1.65  dholland 
     33  1.65  dholland 
     34  1.65  dholland # Old bsd.doc.mk files tend to invoke tbl and other preprocessors
     35  1.65  dholland # directly; they should be changed to set ROFF_* instead.
     36  1.65  dholland #
     37  1.65  dholland # Also they set e.g. DIR=usd/72.mydocument; this should be changed
     38  1.65  dholland # to SECTION=usd and ARTICLE=mydocument. The article numbers are
     39  1.65  dholland # no longer present in the file system and do not need to be known
     40  1.65  dholland # at build time.
     41  1.65  dholland #
     42  1.65  dholland 
     43  1.65  dholland # 20130908 dholland: Make sure all makefiles have been converted to the
     44  1.65  dholland # new scheme.
     45  1.65  dholland .if !defined(SECTION)
     46  1.69    rillig .error SECTION must be defined
     47  1.65  dholland .endif
     48  1.65  dholland .if target(paper.ps)
     49  1.69    rillig .error target(paper.ps) is defined -- this is not allowed
     50  1.65  dholland .endif
     51  1.65  dholland 
     52  1.65  dholland # 20130908 dholland: right now we cannot generate pdf from roff sources,
     53  1.65  dholland # so build compressed postscript instead. XXX. (and: yech)
     54  1.65  dholland TOOL_ROFF_PDF?=false "No roff pdf support"
     55  1.65  dholland PRINTABLE=ps.gz
     56  1.65  dholland #PRINTABLE=ps
     57  1.65  dholland #PRINTABLE=pdf
     58  1.65  dholland 
     59  1.65  dholland # If there aren't subarticles, we generate one doc that has the same
     60  1.65  dholland # name as the top-level article.
     61  1.65  dholland SUBARTICLES?=${ARTICLE}
     62  1.65  dholland SRCS.${ARTICLE}?=${SRCS}
     63  1.65  dholland DEPSRCS.${ARTICLE}?=${DEPSRCS}
     64  1.65  dholland 
     65  1.65  dholland ##### Build
     66   1.8       cgd 
     67  1.65  dholland .for SA in ${SUBARTICLES}
     68  1.65  dholland .if ${MKDOC} != "no"
     69  1.65  dholland realall: ${SA}.txt
     70  1.65  dholland realall: ${SA}.${PRINTABLE}
     71  1.67  dholland .if ${MKHTML} != "no" && ${MKGROFFHTMLDOC} != "no"
     72  1.65  dholland realall: ${SA}.html
     73  1.65  dholland .endif
     74  1.65  dholland .endif
     75  1.65  dholland .endfor # SUBARTICLES
     76  1.65  dholland 
     77  1.65  dholland .if defined(ROFF_PIC) && ${ROFF_PIC} != "no"
     78  1.65  dholland ROFFFLAGS+=-p
     79  1.65  dholland .endif
     80  1.65  dholland .if defined(ROFF_EQN) && ${ROFF_EQN} != "no"
     81  1.65  dholland ROFFFLAGS+=-e
     82  1.65  dholland .endif
     83  1.65  dholland .if defined(ROFF_TBL) && ${ROFF_TBL} != "no"
     84  1.65  dholland ROFFFLAGS+=-t
     85  1.65  dholland .endif
     86  1.65  dholland .if defined(ROFF_REFER) && ${ROFF_REFER} != "no"
     87  1.65  dholland ROFFFLAGS+=-R
     88  1.65  dholland .endif
     89  1.65  dholland ROFFFLAGS+=-I${.CURDIR}
     90  1.65  dholland 
     91  1.65  dholland .for SA in ${SUBARTICLES}
     92  1.65  dholland 
     93  1.65  dholland #
     94  1.65  dholland # Find the sources.
     95  1.65  dholland #
     96  1.65  dholland # We can't use .IMPSRC in the rules because they aren't suffix rules
     97  1.65  dholland # (they could be for some docs, but not others) and we can't use
     98  1.65  dholland # .ALLSRC because that includes DEPSRCS.
     99  1.65  dholland #
    100  1.65  dholland # As far as I know, the only ways to get the path discovered via .PATH
    101  1.65  dholland # are those two magic variables or the P modifier.
    102  1.65  dholland #
    103  1.65  dholland # For some reason the P modifier finds the path to a variable name,
    104  1.65  dholland # not the path to a word in a variable.
    105  1.65  dholland #
    106   1.1       cgd 
    107  1.65  dholland .for S in ${SRCS.${SA}}
    108  1.65  dholland SRCS2.${SA}+=${${S}:P}
    109  1.65  dholland .endfor
    110  1.65  dholland .for S in ${DEPSRCS.${SA}}
    111  1.65  dholland DEPSRCS2.${SA}+=${${S}:P}
    112  1.65  dholland .endfor
    113  1.63     lukem 
    114  1.65  dholland #
    115  1.65  dholland # Note: we use TOOL_ROFF_DOCASCII because TOOL_ROFF_ASCII invokes
    116  1.65  dholland # the nroff wrapper instead of groff directly, and that doesn't
    117  1.65  dholland # understand -I.
    118  1.65  dholland #
    119  1.65  dholland # We use TOOL_ROFF_DOCHTML because TOOL_ROFF_HTML uses -mdoc2html,
    120  1.65  dholland # which is great if it works but doesn't work with at least some of
    121  1.65  dholland # the non-mdoc docs. (e.g. the curses one) TOOL_ROFF_DOCHTML uses
    122  1.65  dholland # groff -Thtml, which produces fairly blah output but works with these
    123  1.65  dholland # docs. It might end up being necessary to choose one or the other on
    124  1.65  dholland # a per-document basis... sigh.
    125  1.65  dholland #
    126  1.14   mycroft 
    127  1.65  dholland ${SA}.txt: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
    128  1.65  dholland 	${_MKTARGET_FORMAT}
    129  1.65  dholland 	${TOOL_ROFF_DOCASCII} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
    130  1.65  dholland 		> ${.TARGET}
    131  1.46   mycroft 
    132  1.65  dholland ${SA}.ps: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
    133  1.65  dholland 	${_MKTARGET_FORMAT}
    134  1.65  dholland 	${TOOL_ROFF_PS} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
    135  1.68  dholland 		| ${TOOL_SED} -e '/^%%CreationDate:/d' \
    136  1.65  dholland 		> ${.TARGET}
    137  1.46   mycroft 
    138  1.65  dholland ${SA}.pdf: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
    139  1.65  dholland 	${_MKTARGET_FORMAT}
    140  1.65  dholland 	${TOOL_ROFF_PDF} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
    141  1.65  dholland 		> ${.TARGET}
    142  1.48   mycroft 
    143  1.65  dholland ${SA}.html: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
    144  1.65  dholland 	${_MKTARGET_FORMAT}
    145  1.65  dholland 	${TOOL_ROFF_DOCHTML} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
    146  1.65  dholland 		-P -I -P ${SA} \
    147  1.65  dholland 		> ${.TARGET}
    148  1.65  dholland 
    149  1.65  dholland ${SA}.ps.gz: ${SA}.ps
    150  1.68  dholland 	${TOOL_GZIP} -9 -c -n ${.ALLSRC} > ${.TARGET}
    151  1.65  dholland 
    152  1.65  dholland .endfor # SUBARTICLES
    153  1.65  dholland 
    154  1.65  dholland ##### Install
    155  1.65  dholland 
    156  1.65  dholland DOCINST:=
    157  1.65  dholland .for SA in ${SUBARTICLES}
    158  1.65  dholland DOCINST+=${SA}.txt ${SA}.${PRINTABLE}
    159  1.67  dholland .if ${MKHTML} != "no" && ${MKGROFFHTMLDOC} != "no"
    160  1.65  dholland DOCINST+=${SA}.html
    161  1.57   mycroft .endif
    162  1.65  dholland .endfor
    163  1.67  dholland .if ${MKHTML} != "no" && ${MKGROFFHTMLDOC} != "no"
    164  1.65  dholland DOCINST+=${EXTRAHTMLFILES}
    165  1.66  dholland .endif
    166  1.65  dholland 
    167  1.65  dholland .if ${MKDOC} != "no"
    168  1.65  dholland docinstall:
    169  1.65  dholland .for D in ${DOCINST}
    170  1.65  dholland 	${_MKTARGET_INSTALL}
    171  1.65  dholland 	${INSTALL_FILE} -o ${DOCOWN} -g ${DOCGRP} -m ${DOCMODE} ${D} \
    172  1.65  dholland 		${DESTDIR}${DOCDIR}/${SECTION}/${ARTICLE}/${D}
    173  1.65  dholland .endfor
    174  1.57   mycroft .else
    175  1.65  dholland docinstall: ;
    176  1.57   mycroft .endif
    177  1.57   mycroft 
    178  1.65  dholland .PHONY: docinstall
    179  1.65  dholland realinstall: docinstall
    180  1.65  dholland 
    181  1.65  dholland ##### Clean
    182  1.65  dholland 
    183  1.65  dholland cleandoc:
    184  1.65  dholland .for SA in ${SUBARTICLES}
    185  1.65  dholland 	rm -f ${SA}.txt ${SA}.ps ${SA}.ps.gz ${SA}.html
    186  1.23  christos .endfor
    187  1.65  dholland 	rm -f ${EXTRAHTMLFILES} [eE]rrs mklog ${CLEANFILES}
    188  1.28   mycroft 
    189  1.65  dholland .PHONY: cleandoc
    190  1.65  dholland clean: cleandoc
    191  1.53        tv 
    192  1.65  dholland ##### Extra custom rules
    193  1.53        tv 
    194  1.53        tv .if !target(print)
    195  1.65  dholland print: ;
    196  1.65  dholland .PHONY: print
    197  1.65  dholland .for SA in ${SUBARTICLES}
    198  1.65  dholland print: print.${SA}
    199  1.69    rillig .PHONY: print.${SA}
    200  1.65  dholland print.${SA}: ${SA}.ps
    201  1.69    rillig 	lpr ${PRINTER:D-P${PRINTER}} ${.ALLSRC}
    202  1.65  dholland .endfor
    203  1.22     perry .endif
    204   1.1       cgd 
    205  1.65  dholland spell: ;
    206  1.65  dholland .PHONY: spell
    207  1.65  dholland .for SA in ${SUBARTICLES}
    208  1.65  dholland spell: spell.${SA}
    209  1.69    rillig .PHONY: spell.${SA}
    210  1.69    rillig spell.${SA}: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
    211  1.69    rillig 	spell ${SRCS2.${SA}} | sort | comm -23 - spell.ok > paper.spell
    212  1.65  dholland .endfor
    213  1.31   mycroft 
    214  1.53        tv ##### Pull in related .mk logic
    215  1.65  dholland 
    216  1.53        tv .include <bsd.obj.mk>
    217  1.55     bjh21 .include <bsd.sys.mk>
    218  1.45      tron 
    219  1.53        tv ${TARGETS}:	# ensure existence
    220