xref: /freebsd/contrib/bmake/mk/meta.sys.mk (revision 96190b4fef3b4a0cc3ca0606b0c4e3e69a5e6717)
1# SPDX-License-Identifier: BSD-2-Clause
2#
3# $Id: meta.sys.mk,v 1.54 2024/03/10 15:53:51 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.MAKE.MODE ?= ${META_MODE}
44
45_filemon := ${.MAKE.PATH_FILEMON:U/dev/filemon}
46
47.if empty(UPDATE_DEPENDFILE)
48_make_mode := ${.MAKE.MODE} ${META_MODE}
49.if ${_make_mode:M*read*} != "" || ${_make_mode:M*nofilemon*} != ""
50# tell everyone we are not updating Makefile.depend*
51UPDATE_DEPENDFILE = NO
52.export UPDATE_DEPENDFILE
53.endif
54.if ${_filemon:T:Mfilemon} == "filemon"
55.if ${UPDATE_DEPENDFILE:Uyes:tl} == "no" && !exists(${_filemon})
56# we should not get upset
57META_MODE += nofilemon
58.export META_MODE
59.endif
60.endif
61.endif
62
63.if !defined(NO_SILENT)
64.if ${MAKE_VERSION} > 20110818
65# only be silent when we have a .meta file
66META_MODE += silent=yes
67.else
68.SILENT:
69.endif
70.endif
71
72.if ${MK_DIRDEPS_BUILD:Uno} == "yes"
73
74.if !defined(META2DEPS)
75.if defined(PYTHON) && exists(${PYTHON})
76# we prefer the python version of this - it is much faster
77META2DEPS ?= ${.PARSEDIR}/meta2deps.py
78.else
79META2DEPS ?= ${.PARSEDIR}/meta2deps.sh
80.endif
81META2DEPS := ${META2DEPS}
82.export META2DEPS
83.endif
84
85MAKE_PRINT_VAR_ON_ERROR += \
86	.ERROR_TARGET \
87	.ERROR_EXIT \
88	.ERROR_META_FILE \
89	.MAKE.LEVEL \
90	MAKEFILE \
91	.MAKE.MODE
92
93MK_META_ERROR_TARGET = yes
94.endif
95
96.if ${MK_META_ERROR_TARGET:Uno} == "yes"
97
98.if !defined(SB) && defined(SRCTOP)
99SB = ${SRCTOP:H}
100.endif
101ERROR_LOGDIR ?= ${SB}/error
102meta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log
103
104.ERROR: _metaError
105# We are interested here in the target(s) that caused the build to fail.
106# We want to ignore targets that were "aborted" due to failure
107# elsewhere per the message below or a sub-make may just exit 6.
108_metaError: .NOMETA .NOTMAIN
109	-@[ ${.ERROR_EXIT:U0} = 6 ] && exit 0; \
110	[ "${.ERROR_META_FILE}" ] && { \
111	grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \
112	mkdir -p ${meta_error_log:H}; \
113	cp ${.ERROR_META_FILE} ${meta_error_log}; \
114	echo "ERROR: log ${meta_error_log}" >&2; }; :
115
116.endif
117.endif
118
119# Are we, after all, in meta mode?
120.if ${.MAKE.MODE:Uno:Mmeta*} != ""
121MKDEP_MK ?= meta.autodep.mk
122
123# we can afford to use cookies to prevent some targets
124# re-running needlessly
125META_COOKIE_TOUCH?= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET:T}}
126META_NOPHONY=
127META_NOECHO= :
128
129# some targets involve old pre-built targets
130# ignore mtime of shell
131# and mtime of makefiles does not matter in meta mode
132.MAKE.META.IGNORE_PATHS += \
133	${MAKEFILE} \
134	${MAKE_SHELL} \
135	${SHELL} \
136	${SYS_MK_DIR} \
137
138
139.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no"
140.if ${.MAKEFLAGS:Uno:M-k} != ""
141# make this more obvious
142.warning Setting UPDATE_DEPENDFILE=NO due to -k
143UPDATE_DEPENDFILE= NO
144.export UPDATE_DEPENDFILE
145.elif ${_filemon:T} == "filemon" && !exists(${_filemon})
146.error ${.newline}ERROR: The filemon module (${_filemon}) is not loaded.
147.endif
148.endif
149
150.else				# in meta mode?
151
152META_COOKIE_TOUCH=
153# some targets need to be .PHONY in non-meta mode
154META_NOPHONY= .PHONY
155META_NOECHO= echo
156
157.endif				# in meta mode?
158
159.-include <local.meta.sys.mk>
160