MAKEFILE(0)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸŽ€ 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 β€” just makewhatis.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 spots find goes digging in.
  • OPTIMIZE_PDF?= β€” the sed glow-up, with three -e expressions:
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 the noman file, begone
  • -v '#' β€” no comment lines
  • -v '/obj.' β€” no obj. paths
  • -v '/destdir.' β€” no destdir. paths
  • -v '/tooldir.' β€” no tooldir. 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} ], she continues, she does not have the energy
  • if ${TOOL_GREP} -q ^\.TS "${.CURDIR}/back" says yes, she prints ${_MKSHMSG_FORMAT} >&2 $${f} and pipes cat $${f} | ${TOOL_TBL} | ${TOOL_GROFF} -Z -msafer -man -Tps ${ROFF_PAGESIZE}
  • otherwise she prints ${_MKSHMSG_FORMAT} >&2 $${f} "(tbl)" and runs cat $${f} | ${TOOL_GROFF} -Z -msafer -man -Tps ${ROFF_PAGESIZE} without tbl

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