MAKEFILE(0)
π MAKEFILE(0) π
okay so bestie, we're in MAKEFILE(0) β section zero, because this isn't a command you run, it's a whole entire makefile that builds the manual pages themselves π and honestly? she's the main character of the man page pipeline and nobody ever thanks her.
πΈ NAME πΈ
Makefile β the build recipe that chews through the man page sources and spits out ${MAN0SRCS}: the file lists, the PostScript, the PDF, and the tarballs of both β¨
π¦ SYNOPSIS π¦
make all
make all.files
make man${_S}pages.files
make man${_S}pages.ps
make man${_S}pages.pdf
make man.tgz
π DESCRIPTION π
so like. this Makefile is the group chat admin of the man page build. <hotpink>all</hotpink> depends on ${MAN0SRCS}, and ${MAN0SRCS} is a stack of ${SECTIONS:@S@...@} loops β one pass for .files, one for .ps, one for .pdf β so you get a man1pages.files, a man1pages.ps, a man1pages.pdf, and so on for every section in ${SECTIONS} π₯
the whole thing is one long <cyan>find | grep | sed | groff | grops</cyan> bender that ends in a tarball, and every single step writes to a .tmp and then ${MV}-s it into place, because we do not ship half-written files in this house π
ββοΈ
β οΈ heads up bestie:# # Note: Needs ps2pdf to convert .ps to .pdf #β if you don't have ps2pdf installed, the PDF target is not gonna slay, she's gonna flop π and that note is sitting right there in a#comment at the top of the file, iykyk.
π§ VARIABLES π§
FILESβ justmakewhatis.sed, one lone icon.FILESDIRβ/usr/share/man, where she lives.SECTIONS?= 1 2 3 4 5 6 7 8 9β the manual sections she walks through. it's?=so you can totally override it, no cap.MANSRCDIRS=β"${.CURDIR}/../../.." ../../..β the two spotsfindgoes digging in.OPTIMIZE_PDF?=β the sed glow-up, with three-eexpressions:
OPTIMIZE_PDF?= -e '/^level0 0 def/d' -e '/^level0 save/d' -e '/^level0 restore/d'
the comment above it says it "Takes out some fluff from the PostScript files created by grops which does some VM saving/restoring that bloats the PDF file pdf2ps generates. By uwe@NetBSD.org." β so, legendary uwe@NetBSD.org said the PostScript was giving bloated and we're deleting the fluff. periodt π
MAN0SRCS=β built up with+=, in this exact order:
MAN0SRCS=
MAN0SRCS+= all.files
MAN0SRCS+= ${SECTIONS:@S@man${S}pages.files@}
MAN0SRCS+= ${SECTIONS:@S@man${S}pages.ps@}
MAN0SRCS+= ${SECTIONS:@S@man${S}pages.pdf@}
that @S@ thing? it's a loop variable, bestie β ${S} gets stamped into every section number π
CLEANFILES+=β the cleanup crew:
CLEANFILES+= ${MAN0SRCS}
CLEANFILES+= *.tmp
CLEANFILES+= toc? tocx?
π₯ TARGETS π₯
π all
all: ${MAN0SRCS}
the one true default. builds literally everything in ${MAN0SRCS} π«Ά
π all.files
all.files:
${_MKTARGET_CREATE}
find ${MANSRCDIRS} -name '*.[1-9]' -print | xargs ${TOOL_MKMAGIC} | ${TOOL_GREP} troff | ${TOOL_SED} 's/:[ ]*.*$$//' | ${TOOL_GREP} -F -v -f "${.CURDIR}/noman" | ${TOOL_GREP} -v '#' | ${TOOL_GREP} -v '/obj.' | ${TOOL_GREP} -v '/destdir.' | ${TOOL_GREP} -v '/tooldir.' > ${.TARGET}.tmp && ${MV} ${.TARGET}.tmp ${.TARGET} ; rm -f ${.TARGET}.tmp
this is the big one π€ she finds ${MANSRCDIRS} for '*.[1-9]', pipes through ${TOOL_MKMAGIC}, keeps only the troff hits, ${TOOL_SED} chops off everything after the colon with 's/:[ ]*.*$$//', then a wall of ${TOOL_GREP} exclusions:
-F -v -f "${.CURDIR}/noman"β anything listed in thenomanfile, begone-v '#'β no comment lines-v '/obj.'β noobj.paths-v '/destdir.'β nodestdir.paths-v '/tooldir.'β notooldir.paths
then > ${.TARGET}.tmp && ${MV} ${.TARGET}.tmp ${.TARGET} ; rm -f ${.TARGET}.tmp β atomic-ish, iconic, no crumbs left behind π§Ή
π man${_S}pages.files
man${_S}pages.files: all.files
${_MKTARGET_CREATE}
cat ${.ALLSRC} | ${TOOL_GREP} "${_S}" | ${TOOL_SED} 's,//]*,2 12,' | sort | ${TOOL_SED} 's/^.* //' > ${.TARGET}.tmp && ${MV} ${.TARGET}.tmp ${.TARGET} ; rm -f ${.TARGET}.tmp
takes all.files, ${TOOL_GREP}-filters for the section "${_S}", runs a ${TOOL_SED} substitution 's,//]*,2 12,', sorts it (obvi), then another ${TOOL_SED} 's/^.* //' to strip the leading bits, and again: .tmp β ${MV} β ${TARGET}, then rm -f ${.TARGET}.tmp β¨
π man${_S}pages.ps
man${_S}pages.ps: man${_S}pages.files
${_MKTARGET_CREATE}
for f in `${TOOL_GREP} "${_S}" "${.CURDIR}/intros"` `cat ${.ALLSRC}` ; do if [ ! -f $${f} ]; then continue ; fi ; if ${TOOL_GREP} -q ^\.TS "${.CURDIR}/back" ; then ${_MKSHMSG_FORMAT} >&2 $${f} ; cat $${f} | ${TOOL_TBL} | ${TOOL_GROFF} -Z -msafer -man -Tps ${ROFF_PAGESIZE}; else ${_MKSHMSG_FORMAT} >&2 $${f} "(tbl)"; cat $${f} | ${TOOL_GROFF} -Z -msafer -man -Tps ${ROFF_PAGESIZE}; fi ; done > ${.TARGET}.troff.tmp && cat ${.TARGET}.troff.tmp | ${TOOL_GREP} -v '^x stop' | ${TOOL_GROPS} > ${.TARGET}.tmp && ${MV} ${.TARGET}.tmp ${.TARGET} ; rm -f ${.TARGET}.tmp ${.TARGET}.troff.tmp
the drama of it all π she loops over `${TOOL_GREP} "${_S}" "${.CURDIR}/intros"` plus `cat ${.ALLSRC}` β and:
- if
[ ! -f $${f} ], shecontinues, she does not have the energy - if
${TOOL_GREP} -q ^\.TS "${.CURDIR}/back"says yes, she prints${_MKSHMSG_FORMAT} >&2 $${f}and pipescat $${f} | ${TOOL_TBL} | ${TOOL_GROFF} -Z -msafer -man -Tps ${ROFF_PAGESIZE} - otherwise she prints
${_MKSHMSG_FORMAT} >&2 $${f} "(tbl)"and runscat $${f} | ${TOOL_GROFF} -Z -msafer -man -Tps ${ROFF_PAGESIZE}withouttbl
everything lands in ${.TARGET}.troff.tmp, then cat ${.TARGET}.troff.tmp | ${TOOL_GREP} -v '^x stop' | ${TOOL_GROPS} > ${.TARGET}.tmp (yes, those ^x stop lines get evicted), && ${MV} into place, and rm -f ${.TARGET}.tmp ${.TARGET}.troff.tmp π
π man${_S}pages.pdf
man${_S}pages.pdf: man${_S}pages.ps
${_MKTARGET_CREATE}
cat ${.ALLSRC} | ${TOOL_SED} ${OPTIMIZE_PDF} | ps2pdf - - > ${.TARGET}.tmp && ${MV} ${.TARGET}.tmp ${.TARGET} ; rm -f ${.TARGET}.tmp
cat β ${TOOL_SED} ${OPTIMIZE_PDF} (the de-fluffing) β ps2pdf - - β .tmp β ${MV} β ${TARGET} β rm -f ${.TARGET}.tmp. and remember: needs ps2pdf or this whole target is a no π
π man.tgz
man.tgz:
tar plzvcf manpages-ps.tgz man?pages.ps
tar plzvcf manpages-pdf.tgz man?pages.pdf
the finale π two tarballs, manpages-ps.tgz from man?pages.ps and manpages-pdf.tgz from man?pages.pdf, both with tar plzvcf. she ate.
β little notes because they're in the file and we don't skip β
- there's a comment at the top that's literally
# # Note: Needs ps2pdf to convert .ps to .pdf #β nested hashes, highkey adorable π₯Ί - the fluff-removal comment credits uwe@NetBSD.org by name, so shoutout uwe π«Ά
π signing off π
and that's the whole vibe, bestie β she's <purple>@(#)Makefile 5.9 (Berkeley) 7/1/91</purple> at heart and <lavender>$NetBSD: Makefile,v 1.19 2024/04/05 23:05:53 christos Exp $</lavender> in her latest era, so go build your man pages, ship your tarballs, and remember: .tmpfirst,${MV}` after, always πβ¨π
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms