xref: /freebsd/contrib/bmake/mk/meta.sys.mk (revision 2830819497fb2deae3dd71574592ace55f2fbdba)
1# $Id: meta.sys.mk,v 1.22 2015/06/16 06:31:05 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# make defaults .MAKE.DEPENDFILE to .depend
55# that won't work for us.
56.if ${.MAKE.DEPENDFILE} == ".depend"
57.undef .MAKE.DEPENDFILE
58.endif
59
60# if you don't cross build for multiple MACHINEs concurrently, then
61# .MAKE.DEPENDFILE = Makefile.depend
62# probably makes sense - you can set that in local.sys.mk
63.MAKE.DEPENDFILE ?= Makefile.depend.${MACHINE}
64
65# we use the pseudo machine "host" for the build host.
66# this should be taken care of before we get here
67.if ${OBJTOP:Ua} == ${HOST_OBJTOP:Ub}
68MACHINE = host
69.endif
70
71.if ${.MAKE.LEVEL} == 0
72# it can be handy to know which MACHINE kicked off the build
73# for example, if using Makefild.depend for multiple machines,
74# allowing only MACHINE0 to update can keep things simple.
75MACHINE0 := ${MACHINE}
76.export MACHINE0
77
78.if defined(PYTHON) && exists(${PYTHON})
79# we prefer the python version of this - it is much faster
80META2DEPS ?= ${.PARSEDIR}/meta2deps.py
81.else
82META2DEPS ?= ${.PARSEDIR}/meta2deps.sh
83.endif
84META2DEPS := ${META2DEPS}
85.export META2DEPS
86.endif
87
88MAKE_PRINT_VAR_ON_ERROR += \
89	.ERROR_TARGET \
90	.ERROR_META_FILE \
91	.MAKE.LEVEL \
92	MAKEFILE \
93	.MAKE.MODE
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
112# Are we, after all, in meta mode?
113.if ${.MAKE.MODE:Mmeta*} != ""
114MKDEP_MK = meta.autodep.mk
115
116.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no"
117.if ${.MAKEFLAGS:Uno:M-k} != ""
118# make this more obvious
119.warning Setting UPDATE_DEPENDFILE=NO due to -k
120UPDATE_DEPENDFILE= NO
121.export UPDATE_DEPENDFILE
122.elif !exists(/dev/filemon)
123.error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded.
124.endif
125.endif
126
127.if ${.MAKE.LEVEL} == 0
128# make sure dirdeps target exists and do it first
129all: dirdeps .WAIT
130dirdeps:
131.NOPATH: dirdeps
132
133.if defined(ALL_MACHINES)
134# the first .MAIN: is what counts
135# by default dirdeps is all we want at level0
136.MAIN: dirdeps
137# tell dirdeps.mk what we want
138BUILD_AT_LEVEL0 = no
139.endif
140.if ${.TARGETS:Nall} == ""
141# it works best if we do everything via sub-makes
142BUILD_AT_LEVEL0 ?= no
143.endif
144
145.endif
146.endif
147.endif
148