1284345Ssjg# $FreeBSD$
2284345Ssjg# $Id: meta.sys.mk,v 1.19 2014/08/02 23:16:02 sjg Exp $
3284345Ssjg
4284345Ssjg#
5284345Ssjg#	@(#) Copyright (c) 2010, Simon J. Gerraty
6284345Ssjg#
7284345Ssjg#	This file is provided in the hope that it will
8284345Ssjg#	be of use.  There is absolutely NO WARRANTY.
9284345Ssjg#	Permission to copy, redistribute or otherwise
10284345Ssjg#	use this file is hereby granted provided that 
11284345Ssjg#	the above copyright notice and this notice are
12284345Ssjg#	left intact. 
13284345Ssjg#      
14284345Ssjg#	Please send copies of changes and bug-fixes to:
15284345Ssjg#	sjg@crufty.net
16284345Ssjg#
17284345Ssjg
18284345Ssjg# include this if you want to enable meta mode
19284345Ssjg# for maximum benefit, requires filemon(4) driver.
20284345Ssjg
21284345Ssjg.if ${MAKE_VERSION:U0} > 20100901
22284345Ssjg.if !target(.ERROR)
23284345Ssjg
24284345Ssjg.-include "local.meta.sys.mk"
25284345Ssjg
26284345Ssjg# absoulte path to what we are reading.
27284345Ssjg_PARSEDIR = ${.PARSEDIR:tA}
28284345Ssjg
29284345SsjgMETA_MODE += meta verbose
30284345Ssjg.MAKE.MODE ?= ${META_MODE}
31284345Ssjg
32284345Ssjg.if ${.MAKE.LEVEL} == 0
33284345Ssjg_make_mode := ${.MAKE.MODE} ${META_MODE}
34284345Ssjg.if ${_make_mode:M*read*} != "" || ${_make_mode:M*nofilemon*} != ""
35284345Ssjg# tell everyone we are not updating Makefile.depend*
36284345SsjgUPDATE_DEPENDFILE = NO
37284345Ssjg.export UPDATE_DEPENDFILE
38284345Ssjg.endif
39284345Ssjg.if ${UPDATE_DEPENDFILE:Uyes:tl} == "no" && !exists(/dev/filemon)
40284345Ssjg# we should not get upset
41284345SsjgMETA_MODE += nofilemon
42284345Ssjg.export META_MODE
43284345Ssjg.endif
44284345Ssjg.endif
45284345Ssjg
46284345Ssjg.if !defined(NO_SILENT)
47284345Ssjg.if ${MAKE_VERSION} > 20110818
48284345Ssjg# only be silent when we have a .meta file
49284345SsjgMETA_MODE += silent=yes
50284345Ssjg.else
51284345Ssjg.SILENT:
52284345Ssjg.endif
53284345Ssjg.endif
54284345Ssjg
55284345Ssjg# make defaults .MAKE.DEPENDFILE to .depend
56284345Ssjg# that won't work for us.
57284345Ssjg.if ${.MAKE.DEPENDFILE} == ".depend"
58284345Ssjg.undef .MAKE.DEPENDFILE
59284345Ssjg.endif
60284345Ssjg
61284345Ssjg# if you don't cross build for multiple MACHINEs concurrently, then
62284345Ssjg# .MAKE.DEPENDFILE = Makefile.depend
63284345Ssjg# probably makes sense - you can set that in local.sys.mk 
64284345Ssjg.MAKE.DEPENDFILE ?= Makefile.depend.${MACHINE}
65284345Ssjg
66284345Ssjg# we use the pseudo machine "host" for the build host.
67284345Ssjg# this should be taken care of before we get here
68284345Ssjg.if ${OBJTOP:Ua} == ${HOST_OBJTOP:Ub}
69284345SsjgMACHINE = host
70284345Ssjg.endif
71284345Ssjg
72284345Ssjg.if ${.MAKE.LEVEL} == 0
73284345Ssjg# it can be handy to know which MACHINE kicked off the build
74284345Ssjg# for example, if using Makefild.depend for multiple machines,
75284345Ssjg# allowing only MACHINE0 to update can keep things simple.
76284345SsjgMACHINE0 := ${MACHINE}
77284345Ssjg.export MACHINE0
78284345Ssjg
79284345Ssjg.if defined(PYTHON) && exists(${PYTHON})
80284345Ssjg# we prefer the python version of this - it is much faster
81284345SsjgMETA2DEPS ?= ${.PARSEDIR}/meta2deps.py
82284345Ssjg.else
83284345SsjgMETA2DEPS ?= ${.PARSEDIR}/meta2deps.sh
84284345Ssjg.endif
85284345SsjgMETA2DEPS := ${META2DEPS}
86284345Ssjg.export META2DEPS
87284345Ssjg.endif
88284345Ssjg
89284345SsjgMAKE_PRINT_VAR_ON_ERROR += \
90284345Ssjg	.ERROR_TARGET \
91284345Ssjg	.ERROR_META_FILE \
92284345Ssjg	.MAKE.LEVEL \
93284345Ssjg	MAKEFILE \
94284345Ssjg	.MAKE.MODE
95284345Ssjg
96284345Ssjg.if !defined(SB) && defined(SRCTOP)
97284345SsjgSB = ${SRCTOP:H}
98284345Ssjg.endif
99284345SsjgERROR_LOGDIR ?= ${SB}/error
100284345Ssjgmeta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log
101284345Ssjg
102284345Ssjg# we are not interested in make telling us a failure happened elsewhere
103284345Ssjg.ERROR: _metaError
104284345Ssjg_metaError: .NOMETA .NOTMAIN
105284345Ssjg	-@[ "${.ERROR_META_FILE}" ] && { \
106284345Ssjg	grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \
107284345Ssjg	mkdir -p ${meta_error_log:H}; \
108284345Ssjg	cp ${.ERROR_META_FILE} ${meta_error_log}; \
109284345Ssjg	echo "ERROR: log ${meta_error_log}" >&2; }; :
110284345Ssjg
111284345Ssjg.endif
112284345Ssjg
113284345Ssjg# Are we, after all, in meta mode?
114296637Ssjg.if ${.MAKE.MODE:Uno:Mmeta*} != ""
115284345SsjgMKDEP_MK = meta.autodep.mk
116284345Ssjg
117284345Ssjg# if we think we are updating dependencies, 
118284345Ssjg# then filemon had better be present
119284345Ssjg.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no" && !exists(/dev/filemon)
120284345Ssjg.error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded.
121284345Ssjg.endif
122284345Ssjg
123284345Ssjg.if ${.MAKE.LEVEL} == 0
124284345Ssjg# make sure dirdeps target exists and do it first
125284345Ssjgall: dirdeps .WAIT
126284345Ssjgdirdeps:
127284345Ssjg.NOPATH: dirdeps
128284345Ssjg
129284345Ssjg.if defined(ALL_MACHINES)
130284345Ssjg# the first .MAIN: is what counts
131284345Ssjg# by default dirdeps is all we want at level0
132284345Ssjg.MAIN: dirdeps
133284345Ssjg# tell dirdeps.mk what we want
134284345SsjgBUILD_AT_LEVEL0 = no
135284345Ssjg.endif
136284345Ssjg.if ${.TARGETS:Nall} == "" 
137284345Ssjg# it works best if we do everything via sub-makes
138284345SsjgBUILD_AT_LEVEL0 ?= no
139284345Ssjg.endif
140284345Ssjg
141284345Ssjg.endif
142284345Ssjg.endif
143284345Ssjg.endif
144