Home | History | Annotate | Line # | Download | only in mk
bsd.doc.mk revision 1.65
      1 #	$NetBSD: bsd.doc.mk,v 1.65 2014/07/05 19:22:04 dholland 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 "bsd.doc.mk: SECTION must be defined"
     47 .endif
     48 .if target(paper.ps)
     49 .error "bsd.doc.mk: target(paper.ps) is true -- 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"
     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 		> ${.TARGET}
    136 
    137 ${SA}.pdf: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
    138 	${_MKTARGET_FORMAT}
    139 	${TOOL_ROFF_PDF} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
    140 		> ${.TARGET}
    141 
    142 ${SA}.html: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
    143 	${_MKTARGET_FORMAT}
    144 	${TOOL_ROFF_DOCHTML} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
    145 		-P -I -P ${SA} \
    146 		> ${.TARGET}
    147 
    148 ${SA}.ps.gz: ${SA}.ps
    149 	${TOOL_GZIP} -9 -c ${.ALLSRC} > ${.TARGET}
    150 
    151 .endfor # SUBARTICLES
    152 
    153 ##### Install
    154 
    155 DOCINST:=
    156 .for SA in ${SUBARTICLES}
    157 DOCINST+=${SA}.txt ${SA}.${PRINTABLE}
    158 .if ${MKHTML} != "no"
    159 DOCINST+=${SA}.html
    160 .endif
    161 .endfor
    162 DOCINST+=${EXTRAHTMLFILES}
    163 
    164 .if ${MKDOC} != "no"
    165 docinstall:
    166 .for D in ${DOCINST}
    167 	${_MKTARGET_INSTALL}
    168 	${INSTALL_FILE} -o ${DOCOWN} -g ${DOCGRP} -m ${DOCMODE} ${D} \
    169 		${DESTDIR}${DOCDIR}/${SECTION}/${ARTICLE}/${D}
    170 .endfor
    171 .else
    172 docinstall: ;
    173 .endif
    174 
    175 .PHONY: docinstall
    176 realinstall: docinstall
    177 
    178 ##### Clean
    179 
    180 cleandoc:
    181 .for SA in ${SUBARTICLES}
    182 	rm -f ${SA}.txt ${SA}.ps ${SA}.ps.gz ${SA}.html
    183 .endfor
    184 	rm -f ${EXTRAHTMLFILES} [eE]rrs mklog ${CLEANFILES}
    185 
    186 .PHONY: cleandoc
    187 clean: cleandoc
    188 
    189 ##### Extra custom rules
    190 
    191 .if !target(print)
    192 print: ;
    193 .PHONY: print
    194 .for SA in ${SUBARTICLES}
    195 print: print.${SA}
    196 .PHONY: print.{SA}
    197 print.${SA}: ${SA}.ps
    198 	lpr -P${PRINTER} ${.ALLSRC}
    199 .endfor
    200 .endif
    201 
    202 spell: ;
    203 .PHONY: spell
    204 .for SA in ${SUBARTICLES}
    205 spell: spell.${SA}
    206 .PHONY: spell.{SA}
    207 spell.${SA}: ${SRCS2} ${DEPSRCS2}
    208 	spell ${SRCS2} | sort | comm -23 - spell.ok > paper.spell
    209 .endfor
    210 
    211 ##### Pull in related .mk logic
    212 
    213 .include <bsd.obj.mk>
    214 .include <bsd.sys.mk>
    215 
    216 ${TARGETS}:	# ensure existence
    217