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