xref: /freebsd/contrib/bmake/mk/meta.sys.mk (revision fe6060f10f634930ff71b7c50291ddc610da2475)
1# $Id: meta.sys.mk,v 1.38 2020/08/19 17:51:53 sjg Exp $
2
3#
4#	@(#) Copyright (c) 2010-2020, 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.MAKE.MODE ?= ${META_MODE}
34
35.if ${.MAKE.LEVEL} == 0
36_make_mode := ${.MAKE.MODE} ${META_MODE}
37.if ${_make_mode:M*read*} != "" || ${_make_mode:M*nofilemon*} != ""
38# tell everyone we are not updating Makefile.depend*
39UPDATE_DEPENDFILE = NO
40.export UPDATE_DEPENDFILE
41.endif
42.if ${UPDATE_DEPENDFILE:Uyes:tl} == "no" && !exists(/dev/filemon)
43# we should not get upset
44META_MODE += nofilemon
45.export META_MODE
46.endif
47.endif
48
49.if !defined(NO_SILENT)
50.if ${MAKE_VERSION} > 20110818
51# only be silent when we have a .meta file
52META_MODE += silent=yes
53.else
54.SILENT:
55.endif
56.endif
57
58# we use the pseudo machine "host" for the build host.
59# this should be taken care of before we get here
60.if ${OBJTOP:Ua} == ${HOST_OBJTOP:Ub}
61MACHINE = host
62.endif
63
64.if !defined(MACHINE0)
65# it can be handy to know which MACHINE kicked off the build
66# for example, if using Makefild.depend for multiple machines,
67# allowing only MACHINE0 to update can keep things simple.
68MACHINE0 := ${MACHINE}
69.export MACHINE0
70.endif
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
90.if !defined(SB) && defined(SRCTOP)
91SB = ${SRCTOP:H}
92.endif
93ERROR_LOGDIR ?= ${SB}/error
94meta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log
95
96# we are not interested in make telling us a failure happened elsewhere
97.ERROR: _metaError
98_metaError: .NOMETA .NOTMAIN
99	-@[ "${.ERROR_META_FILE}" ] && { \
100	grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \
101	mkdir -p ${meta_error_log:H}; \
102	cp ${.ERROR_META_FILE} ${meta_error_log}; \
103	echo "ERROR: log ${meta_error_log}" >&2; }; :
104
105.endif
106
107# Are we, after all, in meta mode?
108.if ${.MAKE.MODE:Uno:Mmeta*} != ""
109MKDEP_MK = meta.autodep.mk
110
111.if ${.MAKE.MAKEFILES:M*sys.dependfile.mk} == ""
112# this does all the smarts of setting .MAKE.DEPENDFILE
113.-include <sys.dependfile.mk>
114# check if we got anything sane
115.if ${.MAKE.DEPENDFILE} == ".depend"
116.undef .MAKE.DEPENDFILE
117.endif
118.MAKE.DEPENDFILE ?= Makefile.depend
119.endif
120
121# we can afford to use cookies to prevent some targets
122# re-running needlessly
123META_COOKIE_TOUCH?= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET:T}}
124META_NOPHONY=
125META_NOECHO= :
126
127# some targets involve old pre-built targets
128# ignore mtime of shell
129# and mtime of makefiles does not matter in meta mode
130.MAKE.META.IGNORE_PATHS += \
131	${MAKEFILE} \
132	${MAKE_SHELL} \
133	${SHELL} \
134	${SYS_MK_DIR} \
135
136
137.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no"
138.if ${.MAKEFLAGS:Uno:M-k} != ""
139# make this more obvious
140.warning Setting UPDATE_DEPENDFILE=NO due to -k
141UPDATE_DEPENDFILE= NO
142.export UPDATE_DEPENDFILE
143.elif !exists(/dev/filemon)
144.error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded.
145.endif
146.endif
147
148.if ${.MAKE.LEVEL} == 0
149# make sure dirdeps target exists and do it first
150all: dirdeps .WAIT
151dirdeps:
152.NOPATH: dirdeps
153
154.if defined(ALL_MACHINES)
155# the first .MAIN: is what counts
156# by default dirdeps is all we want at level0
157.MAIN: dirdeps
158.endif
159
160.endif
161.else
162META_COOKIE_TOUCH=
163# some targets need to be .PHONY in non-meta mode
164META_NOPHONY= .PHONY
165META_NOECHO= echo
166.endif
167.endif
168