xref: /freebsd/contrib/bmake/mk/meta.sys.mk (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1# $Id: meta.sys.mk,v 1.51 2023/05/11 20:05:32 sjg Exp $
2
3#
4#	@(#) Copyright (c) 2010-2023, 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# absolute path to what we are reading.
21_PARSEDIR ?= ${.PARSEDIR:tA}
22
23.-include <local.meta.sys.env.mk>
24
25.if !defined(SYS_MK_DIR)
26SYS_MK_DIR := ${_PARSEDIR}
27.endif
28
29.if !target(.ERROR)
30
31META_MODE += meta
32.if empty(.MAKEFLAGS:M-s)
33META_MODE += verbose
34.endif
35.if ${MAKE_VERSION:U0} > 20130323 && empty(.MAKE.PATH_FILEMON)
36# we do not support filemon
37META_MODE += nofilemon
38MKDEP_MK ?= auto.dep.mk
39.endif
40
41.MAKE.MODE ?= ${META_MODE}
42
43_filemon := ${.MAKE.PATH_FILEMON:U/dev/filemon}
44
45.if empty(UPDATE_DEPENDFILE)
46_make_mode := ${.MAKE.MODE} ${META_MODE}
47.if ${_make_mode:M*read*} != "" || ${_make_mode:M*nofilemon*} != ""
48# tell everyone we are not updating Makefile.depend*
49UPDATE_DEPENDFILE = NO
50.export UPDATE_DEPENDFILE
51.endif
52.if ${_filemon:T:Mfilemon} == "filemon"
53.if ${UPDATE_DEPENDFILE:Uyes:tl} == "no" && !exists(${_filemon})
54# we should not get upset
55META_MODE += nofilemon
56.export META_MODE
57.endif
58.endif
59.endif
60
61.if !defined(NO_SILENT)
62.if ${MAKE_VERSION} > 20110818
63# only be silent when we have a .meta file
64META_MODE += silent=yes
65.else
66.SILENT:
67.endif
68.endif
69
70.if ${MK_DIRDEPS_BUILD:Uno} == "yes"
71
72.if !defined(META2DEPS)
73.if defined(PYTHON) && exists(${PYTHON})
74# we prefer the python version of this - it is much faster
75META2DEPS ?= ${.PARSEDIR}/meta2deps.py
76.else
77META2DEPS ?= ${.PARSEDIR}/meta2deps.sh
78.endif
79META2DEPS := ${META2DEPS}
80.export META2DEPS
81.endif
82
83MAKE_PRINT_VAR_ON_ERROR += \
84	.ERROR_TARGET \
85	.ERROR_META_FILE \
86	.MAKE.LEVEL \
87	MAKEFILE \
88	.MAKE.MODE
89
90MK_META_ERROR_TARGET = yes
91.endif
92
93.if ${MK_META_ERROR_TARGET:Uno} == "yes"
94
95.if !defined(SB) && defined(SRCTOP)
96SB = ${SRCTOP:H}
97.endif
98ERROR_LOGDIR ?= ${SB}/error
99meta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log
100
101# we are not interested in make telling us a failure happened elsewhere
102.ERROR: _metaError
103_metaError: .NOMETA .NOTMAIN
104	-@[ "${.ERROR_META_FILE}" ] && { \
105	grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \
106	mkdir -p ${meta_error_log:H}; \
107	cp ${.ERROR_META_FILE} ${meta_error_log}; \
108	echo "ERROR: log ${meta_error_log}" >&2; }; :
109
110.endif
111.endif
112
113# Are we, after all, in meta mode?
114.if ${.MAKE.MODE:Uno:Mmeta*} != ""
115MKDEP_MK ?= meta.autodep.mk
116
117# we can afford to use cookies to prevent some targets
118# re-running needlessly
119META_COOKIE_TOUCH?= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET:T}}
120META_NOPHONY=
121META_NOECHO= :
122
123# some targets involve old pre-built targets
124# ignore mtime of shell
125# and mtime of makefiles does not matter in meta mode
126.MAKE.META.IGNORE_PATHS += \
127	${MAKEFILE} \
128	${MAKE_SHELL} \
129	${SHELL} \
130	${SYS_MK_DIR} \
131
132
133.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no"
134.if ${.MAKEFLAGS:Uno:M-k} != ""
135# make this more obvious
136.warning Setting UPDATE_DEPENDFILE=NO due to -k
137UPDATE_DEPENDFILE= NO
138.export UPDATE_DEPENDFILE
139.elif ${_filemon:T} == "filemon" && !exists(${_filemon})
140.error ${.newline}ERROR: The filemon module (${_filemon}) is not loaded.
141.endif
142.endif
143
144.else				# in meta mode?
145
146META_COOKIE_TOUCH=
147# some targets need to be .PHONY in non-meta mode
148META_NOPHONY= .PHONY
149META_NOECHO= echo
150
151.endif				# in meta mode?
152
153.-include <local.meta.sys.mk>
154