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