I should probably mention that in FreeBSD these same hooks have evolved to a quite useful model.
*.mk includes local.*.mk which includes src.*.mk and site.*.mk bsd.init.mk [-> <local.init.mk> -> [src.init.mk, site.init.mk]] src.*.mk contain customizations specific to building /usr/src site.*.mk allows downstream consumers to further customize At work we leverage site.*.mk extensively - we normally only build using the DIRDEPS_BUILD (MK_DIRDEPS_BUILD=yes) On Sun, 26 Jul 2026 13:57:56 -0700, Simon J Gerraty writes: >Having finally replaced the dead power supply in my NetBSD server, >and again have a useful box running 11.0 >I'd like to commit a few .-include <local.*.mk> as per the patch below. > >These provide a hook for customizing build behavior. >For example as described in >https://www.crufty.net/sjg/docs/netbsd-meta-mode.htm Latest update to that, I have the native (build.sh) build working in meta mode - did require a fix to filemon_ktrace.c Which is a useful outcome all by itself. It did require a change to how tools nbmake is built. I'll tidy that up and share. >I put similar changes into FreeBSD in 2015, though in that case >I also committed local.*.mk as well as a bunch of makefiles >that are distributed with bmake. Lots of FreeBSD devs use META_MODE >even with the traditional build targets. > >For NetBSD I'm currently using: > >MAKESYSPATH=.../share/mk:${HOME}/nb:${HOME}/share/mk Actually without additional changes to sys.mk that needs to be MAKESYSPATH=${SRCTOP}/share/mk:${HOME}/nb:${HOME}/share/mk to prevent some dirs finding ${HOME}/share/mk/sys.mk >where local.*.mk are found in ${HOME}/nb and these include >makefiles like *dirdeps*.mk from ${HOME}/share/mk > >This just keeps the tree clean. > >If anyone is interested I can post the current state of the local.*.mk >I'm using: > >/homes/sjg/nb/local.dirdeps-build.mk >/homes/sjg/nb/local.dirdeps-missing.mk >/homes/sjg/nb/local.dirdeps.mk >/homes/sjg/nb/local.final.mk >/homes/sjg/nb/local.gendirdeps.mk >/homes/sjg/nb/local.init.mk >/homes/sjg/nb/local.meta.sys.mk >/homes/sjg/nb/local.sys.dirdeps.env.mk >/homes/sjg/nb/local.sys.dirdeps.mk >/homes/sjg/nb/local.sys.env.mk >/homes/sjg/nb/local.sys.machine.mk >/homes/sjg/nb/local.sys.mk > >everything else is distributed with bmake > >https://www.crufty.net/ftp/pub/sjg/bmake.tar.gz > >or found in > >https://www.crufty.net/ftp/pub/sjg/mk.tar.gz > >--------------------8<-------------------- > >Add optional includes of local.*.mk > >local.*.mk provide a means of customizing the build for downstream >projects without impacting normal builds. > >The intent is that these makefiles are not installed to /usr/share/mk/ >nor need they even exist in the src tree. > >The target 'beforebuild' provides a hook for running targets before >normal build activity. This is useful for generating headers and >similar. > >--------------------8<-------------------- > >Index: share/mk/bsd.README >=================================================================== >RCS file: /cvsroot/src/share/mk/bsd.README,v >retrieving revision 1.465 >diff -u -p -r1.465 bsd.README >--- share/mk/bsd.README 28 Apr 2026 15:06:40 -0000 1.465 >+++ share/mk/bsd.README 26 Jul 2026 19:34:43 -0000 >@@ -2045,5 +2045,12 @@ kernel, including "ioconf.c", "ioconf.h" > > TODO: variables > >+=-=-=-=-= local.*.mk =-=-=-=-= >+ >+These makefiles are not installed in /usr/share/mk >+and may not even exist in the src tree. >+ >+The includes of these makefiles provide hooks for customizing the build >+for downstream projects. > > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= >Index: share/mk/bsd.init.mk >=================================================================== >RCS file: /cvsroot/src/share/mk/bsd.init.mk,v >retrieving revision 1.2 >diff -u -p -r1.2 bsd.init.mk >--- share/mk/bsd.init.mk 28 Jul 2003 02:38:33 -0000 1.2 >+++ share/mk/bsd.init.mk 26 Jul 2026 19:34:43 -0000 >@@ -6,8 +6,11 @@ > .if !defined(_BSD_INIT_MK_) > _BSD_INIT_MK_=1 > >+.-include "local.init.mk" >+ > .-include "${.CURDIR}/../Makefile.inc" > .include <bsd.own.mk> > .MAIN: all >+beforebuild: > > .endif # !defined(_BSD_INIT_MK_) >Index: share/mk/bsd.lib.mk >=================================================================== >RCS file: /cvsroot/src/share/mk/bsd.lib.mk,v >retrieving revision 1.427 >diff -u -p -r1.427 bsd.lib.mk >--- share/mk/bsd.lib.mk 21 Jan 2026 17:57:27 -0000 1.427 >+++ share/mk/bsd.lib.mk 26 Jul 2026 19:34:43 -0000 >@@ -550,7 +550,11 @@ _YLSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YH > > .NOPATH: ${ALLOBJS} ${_LIBS} ${_YLSRCS} > >-realall: ${SRCS} ${ALLOBJS:O} ${_LIBS} ${_LIB.so.debug} >+.if empty(_SKIP_BUILD) >+realall: beforebuild .WAIT ${SRCS} ${ALLOBJS:O} ${_LIBS} ${_LIB.so.debug} >+.else >+realall: >+.endif > > .if ${MKARZERO} == "yes" > _ARFL=crsD >Index: share/mk/bsd.prog.mk >=================================================================== >RCS file: /cvsroot/src/share/mk/bsd.prog.mk,v >retrieving revision 1.364 >diff -u -p -r1.364 bsd.prog.mk >--- share/mk/bsd.prog.mk 14 Feb 2026 16:07:25 -0000 1.364 >+++ share/mk/bsd.prog.mk 26 Jul 2026 19:34:43 -0000 >@@ -562,7 +562,11 @@ MAN.${_P}= ${_P}.1 > MAN+= ${MAN.${_P}} > .endif > >-realall: ${_P} ${_PROGDEBUG.${_P}} >+.if empty(_SKIP_BUILD) >+realall: beforebuild .WAIT ${_P} ${_PROGDEBUG.${_P}} >+.else >+realall: >+.endif > > CLEANFILES+= ${_P} ${_PROGDEBUG.${_P}} > >Index: share/mk/sys.mk >=================================================================== >RCS file: /cvsroot/src/share/mk/sys.mk,v >retrieving revision 1.152 >diff -u -p -r1.152 sys.mk >--- share/mk/sys.mk 18 Jan 2026 08:30:33 -0000 1.152 >+++ share/mk/sys.mk 26 Jul 2026 19:34:43 -0000 >@@ -7,6 +7,8 @@ > > unix?= We run NetBSD. > >+.-include <local.sys.env.mk> >+ > .SUFFIXES: .a .o .ln .s .S .c .cc .cpp .cxx .C .r .p .l .y .sh > _FORTRAN_SUFFIXES_NOCPP=.f .for .ftn .f90 .f95 .f03 .f08 > _FORTRAN_SUFFIXES_CPP= .F .FOR .fpp .FPP .FTN .F90 .F95 .F03 .F08 >@@ -252,3 +254,5 @@ ${_FORTRAN_SUFFIXES_CPP:=.a}: > rm -f ${.TARGET} > cp ${.IMPSRC} ${.TARGET} > chmod a+x ${.TARGET} >+ >+.-include <local.sys.mk>
