xref: /freebsd/share/mk/meta.sys.mk (revision 3c5ba95ad12285ad37c182a4bfc1b240ec6d18a7)
1# $FreeBSD$
2# $Id: meta.sys.mk,v 1.32 2017/06/11 03:24:04 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 ${.MAKE.LEVEL} == 0
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
72.if defined(PYTHON) && exists(${PYTHON})
73# we prefer the python version of this - it is much faster
74META2DEPS ?= ${.PARSEDIR}/meta2deps.py
75.else
76META2DEPS ?= ${.PARSEDIR}/meta2deps.sh
77.endif
78META2DEPS := ${META2DEPS}
79.export META2DEPS
80.endif
81
82MAKE_PRINT_VAR_ON_ERROR += \
83	.ERROR_TARGET \
84	.ERROR_META_FILE \
85	.MAKE.LEVEL \
86	MAKEFILE \
87	.MAKE.MODE
88
89.if !defined(SB) && defined(SRCTOP)
90SB = ${SRCTOP:H}
91.endif
92ERROR_LOGDIR ?= ${SB}/error
93meta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log
94
95# we are not interested in make telling us a failure happened elsewhere
96.ERROR: _metaError
97_metaError: .NOMETA .NOTMAIN
98	-@[ "${.ERROR_META_FILE}" ] && { \
99	grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \
100	mkdir -p ${meta_error_log:H}; \
101	cp ${.ERROR_META_FILE} ${meta_error_log}; \
102	echo "ERROR: log ${meta_error_log}" >&2; }; :
103
104.endif
105
106# Are we, after all, in meta mode?
107.if ${.MAKE.MODE:Uno:Mmeta*} != ""
108MKDEP_MK = meta.autodep.mk
109
110.if ${.MAKE.MAKEFILES:M*sys.dependfile.mk} == ""
111# this does all the smarts of setting .MAKE.DEPENDFILE
112.-include <sys.dependfile.mk>
113# check if we got anything sane
114.if ${.MAKE.DEPENDFILE} == ".depend"
115.undef .MAKE.DEPENDFILE
116.endif
117.MAKE.DEPENDFILE ?= Makefile.depend
118.endif
119
120# we can afford to use cookies to prevent some targets
121# re-running needlessly
122META_COOKIE_TOUCH?= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET:T}}
123META_NOPHONY=
124META_NOECHO= :
125
126# some targets involve old pre-built targets
127# ignore mtime of shell
128# and mtime of makefiles does not matter in meta mode
129.MAKE.META.IGNORE_PATHS += \
130        ${MAKEFILE} \
131        ${SHELL} \
132        ${SYS_MK_DIR}
133
134.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no"
135.if ${.MAKEFLAGS:Uno:M-k} != ""
136# make this more obvious
137.warning Setting UPDATE_DEPENDFILE=NO due to -k
138UPDATE_DEPENDFILE= NO
139.export UPDATE_DEPENDFILE
140.elif !exists(/dev/filemon)
141.error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded.
142.endif
143.endif
144
145.if ${.MAKE.LEVEL} == 0
146# make sure dirdeps target exists and do it first
147all: dirdeps .WAIT
148dirdeps:
149.NOPATH: dirdeps
150
151.if defined(ALL_MACHINES)
152# the first .MAIN: is what counts
153# by default dirdeps is all we want at level0
154.MAIN: dirdeps
155# tell dirdeps.mk what we want
156BUILD_AT_LEVEL0 = no
157.endif
158.if ${.TARGETS:Nall} == ""
159# it works best if we do everything via sub-makes
160BUILD_AT_LEVEL0 ?= no
161.endif
162
163.endif
164.else
165META_COOKIE_TOUCH=
166# some targets need to be .PHONY in non-meta mode
167META_NOPHONY= .PHONY
168META_NOECHO= echo
169.endif
170.endif
171