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