1# $Id: meta.sys.mk,v 1.42 2021/12/13 05:50:55 sjg Exp $ 2 3# 4# @(#) Copyright (c) 2010-2021, Simon J. Gerraty 5# 6# This file is provided in the hope that it will 7# be of use. There is absolutely NO WARRANTY. 8# Permission to copy, redistribute or otherwise 9# use this file is hereby granted provided that 10# the above copyright notice and this notice are 11# left intact. 12# 13# Please send copies of changes and bug-fixes to: 14# sjg@crufty.net 15# 16 17# include this if you want to enable meta mode 18# for maximum benefit, requires filemon(4) driver. 19 20.if ${MAKE_VERSION:U0} > 20100901 21.if !target(.ERROR) 22 23.-include <local.meta.sys.mk> 24 25# absolute path to what we are reading. 26_PARSEDIR = ${.PARSEDIR:tA} 27 28.if !defined(SYS_MK_DIR) 29SYS_MK_DIR := ${_PARSEDIR} 30.endif 31 32META_MODE += meta verbose 33.if ${MAKE_VERSION:U0} > 20130323 && empty(.MAKE.PATH_FILEMON) 34# we do not support filemon 35META_MODE += nofilemon 36MKDEP_MK ?= auto.dep.mk 37.endif 38 39.MAKE.MODE ?= ${META_MODE} 40 41_filemon := ${.MAKE.PATH_FILEMON:U/dev/filemon} 42 43.if empty(UPDATE_DEPENDFILE) 44_make_mode := ${.MAKE.MODE} ${META_MODE} 45.if ${_make_mode:M*read*} != "" || ${_make_mode:M*nofilemon*} != "" 46# tell everyone we are not updating Makefile.depend* 47UPDATE_DEPENDFILE = NO 48.export UPDATE_DEPENDFILE 49.endif 50.if ${_filemon:T:Mfilemon} == "filemon" 51.if ${UPDATE_DEPENDFILE:Uyes:tl} == "no" && !exists(${_filemon}) 52# we should not get upset 53META_MODE += nofilemon 54.export META_MODE 55.endif 56.endif 57.endif 58 59.if !defined(NO_SILENT) 60.if ${MAKE_VERSION} > 20110818 61# only be silent when we have a .meta file 62META_MODE += silent=yes 63.else 64.SILENT: 65.endif 66.endif 67 68# we use the pseudo machine "host" for the build host. 69# this should be taken care of before we get here 70.if ${OBJTOP:Ua} == ${HOST_OBJTOP:Ub} 71MACHINE = host 72.endif 73 74.if !defined(MACHINE0) 75# it can be handy to know which MACHINE kicked off the build 76# for example, if using Makefild.depend for multiple machines, 77# allowing only MACHINE0 to update can keep things simple. 78MACHINE0 := ${MACHINE} 79.export MACHINE0 80.endif 81 82.if !defined(META2DEPS) 83.if defined(PYTHON) && exists(${PYTHON}) 84# we prefer the python version of this - it is much faster 85META2DEPS ?= ${.PARSEDIR}/meta2deps.py 86.else 87META2DEPS ?= ${.PARSEDIR}/meta2deps.sh 88.endif 89META2DEPS := ${META2DEPS} 90.export META2DEPS 91.endif 92 93MAKE_PRINT_VAR_ON_ERROR += \ 94 .ERROR_TARGET \ 95 .ERROR_META_FILE \ 96 .MAKE.LEVEL \ 97 MAKEFILE \ 98 .MAKE.MODE 99 100.if !defined(SB) && defined(SRCTOP) 101SB = ${SRCTOP:H} 102.endif 103ERROR_LOGDIR ?= ${SB}/error 104meta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log 105 106# we are not interested in make telling us a failure happened elsewhere 107.ERROR: _metaError 108_metaError: .NOMETA .NOTMAIN 109 -@[ "${.ERROR_META_FILE}" ] && { \ 110 grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \ 111 mkdir -p ${meta_error_log:H}; \ 112 cp ${.ERROR_META_FILE} ${meta_error_log}; \ 113 echo "ERROR: log ${meta_error_log}" >&2; }; : 114 115.endif 116 117# Are we, after all, in meta mode? 118.if ${.MAKE.MODE:Uno:Mmeta*} != "" 119MKDEP_MK ?= meta.autodep.mk 120 121.if ${.MAKE.MAKEFILES:M*sys.dependfile.mk} == "" 122# this does all the smarts of setting .MAKE.DEPENDFILE 123.-include <sys.dependfile.mk> 124# check if we got anything sane 125.if ${.MAKE.DEPENDFILE} == ".depend" 126.undef .MAKE.DEPENDFILE 127.endif 128.MAKE.DEPENDFILE ?= Makefile.depend 129.endif 130 131# we can afford to use cookies to prevent some targets 132# re-running needlessly 133META_COOKIE_TOUCH?= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET:T}} 134META_NOPHONY= 135META_NOECHO= : 136 137# some targets involve old pre-built targets 138# ignore mtime of shell 139# and mtime of makefiles does not matter in meta mode 140.MAKE.META.IGNORE_PATHS += \ 141 ${MAKEFILE} \ 142 ${MAKE_SHELL} \ 143 ${SHELL} \ 144 ${SYS_MK_DIR} \ 145 146 147.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no" 148.if ${.MAKEFLAGS:Uno:M-k} != "" 149# make this more obvious 150.warning Setting UPDATE_DEPENDFILE=NO due to -k 151UPDATE_DEPENDFILE= NO 152.export UPDATE_DEPENDFILE 153.elif ${_filemon:T} == "filemon" && !exists(${_filemon}) 154.error ${.newline}ERROR: The filemon module (${_filemon}) is not loaded. 155.endif 156.endif 157 158.if ${.MAKE.LEVEL} == 0 159.if ${MK_DIRDEPS_BUILD:Uyes} == "yes" 160# make sure dirdeps target exists and do it first 161all: dirdeps .WAIT 162dirdeps: 163.NOPATH: dirdeps 164 165.if defined(ALL_MACHINES) 166# the first .MAIN: is what counts 167# by default dirdeps is all we want at level0 168.MAIN: dirdeps 169.endif 170.endif 171 172.endif 173.else 174META_COOKIE_TOUCH= 175# some targets need to be .PHONY in non-meta mode 176META_NOPHONY= .PHONY 177META_NOECHO= echo 178.endif 179.endif 180