xref: /freebsd/contrib/bmake/mk/meta.sys.mk (revision 640235e2c2ba32947f7c59d168437ffa1280f1e6)
1# $Id: meta.sys.mk,v 1.28 2016/04/05 15:58:37 sjg Exp $
2
3#
4#	@(#) Copyright (c) 2010, 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# absoulte path to what we are reading.
26_PARSEDIR = ${.PARSEDIR:tA}
27
28META_MODE += meta verbose
29.MAKE.MODE ?= ${META_MODE}
30
31.if ${.MAKE.LEVEL} == 0
32_make_mode := ${.MAKE.MODE} ${META_MODE}
33.if ${_make_mode:M*read*} != "" || ${_make_mode:M*nofilemon*} != ""
34# tell everyone we are not updating Makefile.depend*
35UPDATE_DEPENDFILE = NO
36.export UPDATE_DEPENDFILE
37.endif
38.if ${UPDATE_DEPENDFILE:Uyes:tl} == "no" && !exists(/dev/filemon)
39# we should not get upset
40META_MODE += nofilemon
41.export META_MODE
42.endif
43.endif
44
45.if !defined(NO_SILENT)
46.if ${MAKE_VERSION} > 20110818
47# only be silent when we have a .meta file
48META_MODE += silent=yes
49.else
50.SILENT:
51.endif
52.endif
53
54# we use the pseudo machine "host" for the build host.
55# this should be taken care of before we get here
56.if ${OBJTOP:Ua} == ${HOST_OBJTOP:Ub}
57MACHINE = host
58.endif
59
60.if ${.MAKE.LEVEL} == 0
61# it can be handy to know which MACHINE kicked off the build
62# for example, if using Makefild.depend for multiple machines,
63# allowing only MACHINE0 to update can keep things simple.
64MACHINE0 := ${MACHINE}
65.export MACHINE0
66
67.if defined(PYTHON) && exists(${PYTHON})
68# we prefer the python version of this - it is much faster
69META2DEPS ?= ${.PARSEDIR}/meta2deps.py
70.else
71META2DEPS ?= ${.PARSEDIR}/meta2deps.sh
72.endif
73META2DEPS := ${META2DEPS}
74.export META2DEPS
75.endif
76
77MAKE_PRINT_VAR_ON_ERROR += \
78	.ERROR_TARGET \
79	.ERROR_META_FILE \
80	.MAKE.LEVEL \
81	MAKEFILE \
82	.MAKE.MODE
83
84.if !defined(SB) && defined(SRCTOP)
85SB = ${SRCTOP:H}
86.endif
87ERROR_LOGDIR ?= ${SB}/error
88meta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log
89
90# we are not interested in make telling us a failure happened elsewhere
91.ERROR: _metaError
92_metaError: .NOMETA .NOTMAIN
93	-@[ "${.ERROR_META_FILE}" ] && { \
94	grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \
95	mkdir -p ${meta_error_log:H}; \
96	cp ${.ERROR_META_FILE} ${meta_error_log}; \
97	echo "ERROR: log ${meta_error_log}" >&2; }; :
98
99.endif
100
101META_COOKIE_TOUCH=
102# some targets need to be .PHONY in non-meta mode
103META_NOPHONY= .PHONY
104# Are we, after all, in meta mode?
105.if ${.MAKE.MODE:Uno:Mmeta*} != ""
106MKDEP_MK = meta.autodep.mk
107
108.if ${.MAKE.MAKEFILES:M*sys.dependfile.mk} == ""
109# this does all the smarts of setting .MAKE.DEPENDFILE
110.-include <sys.dependfile.mk>
111# check if we got anything sane
112.if ${.MAKE.DEPENDFILE} == ".depend"
113.undef .MAKE.DEPENDFILE
114.endif
115.MAKE.DEPENDFILE ?= Makefile.depend
116.endif
117
118# we can afford to use cookies to prevent some targets
119# re-running needlessly
120META_COOKIE_TOUCH= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET}}
121META_NOPHONY=
122.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no"
123.if ${.MAKEFLAGS:Uno:M-k} != ""
124# make this more obvious
125.warning Setting UPDATE_DEPENDFILE=NO due to -k
126UPDATE_DEPENDFILE= NO
127.export UPDATE_DEPENDFILE
128.elif !exists(/dev/filemon)
129.error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded.
130.endif
131.endif
132
133.if ${.MAKE.LEVEL} == 0
134# make sure dirdeps target exists and do it first
135all: dirdeps .WAIT
136dirdeps:
137.NOPATH: dirdeps
138
139.if defined(ALL_MACHINES)
140# the first .MAIN: is what counts
141# by default dirdeps is all we want at level0
142.MAIN: dirdeps
143# tell dirdeps.mk what we want
144BUILD_AT_LEVEL0 = no
145.endif
146.if ${.TARGETS:Nall} == ""
147# it works best if we do everything via sub-makes
148BUILD_AT_LEVEL0 ?= no
149.endif
150
151.endif
152.endif
153.endif
154