1246149Ssjg# $Id: meta.sys.mk,v 1.16 2012/07/03 05:26:00 sjg Exp $
2246149Ssjg
3246149Ssjg#
4246149Ssjg#	@(#) Copyright (c) 2010, Simon J. Gerraty
5246149Ssjg#
6246149Ssjg#	This file is provided in the hope that it will
7246149Ssjg#	be of use.  There is absolutely NO WARRANTY.
8246149Ssjg#	Permission to copy, redistribute or otherwise
9246149Ssjg#	use this file is hereby granted provided that 
10246149Ssjg#	the above copyright notice and this notice are
11246149Ssjg#	left intact. 
12246149Ssjg#      
13246149Ssjg#	Please send copies of changes and bug-fixes to:
14246149Ssjg#	sjg@crufty.net
15246149Ssjg#
16246149Ssjg
17246149Ssjg# include this if you want to enable meta mode
18246149Ssjg# for maximum benefit, requires filemon(4) driver.
19246149Ssjg
20246149Ssjg.if ${MAKE_VERSION:U0} > 20100901
21246149Ssjg.if !target(.ERROR)
22246149Ssjg
23246149Ssjg
24246149SsjgMETA_MODE += meta verbose
25246149Ssjg.MAKE.MODE ?= ${META_MODE}
26246149Ssjg
27246149Ssjg.if ${.MAKE.LEVEL} == 0
28246149Ssjg_make_mode := ${.MAKE.MODE} ${META_MODE}
29246149Ssjg.if ${_make_mode:M*read*} != "" || ${_make_mode:M*nofilemon*} != ""
30246149Ssjg# tell everyone we are not updating Makefile.depend*
31246149SsjgUPDATE_DEPENDFILE = NO
32246149Ssjg.export UPDATE_DEPENDFILE
33246149Ssjg.endif
34246149Ssjg.if ${UPDATE_DEPENDFILE:Uyes:tl} == "no" && !exists(/dev/filemon)
35246149Ssjg# we should not get upset
36246149SsjgMETA_MODE += nofilemon
37246149Ssjg.export META_MODE
38246149Ssjg.endif
39246149Ssjg.endif
40246149Ssjg
41246149Ssjg.if !defined(NO_SILENT)
42246149Ssjg.if ${MAKE_VERSION} > 20110818
43246149Ssjg# only be silent when we have a .meta file
44246149SsjgMETA_MODE += silent=yes
45246149Ssjg.else
46246149Ssjg.SILENT:
47246149Ssjg.endif
48246149Ssjg.endif
49246149Ssjg
50246149Ssjg# make defaults .MAKE.DEPENDFILE to .depend
51246149Ssjg# that won't work for us.
52246149Ssjg.if ${.MAKE.DEPENDFILE} == ".depend"
53246149Ssjg.undef .MAKE.DEPENDFILE
54246149Ssjg.endif
55246149Ssjg
56246149Ssjg# if you don't cross build for multiple MACHINEs concurrently, then
57246149Ssjg# .MAKE.DEPENDFILE = Makefile.depend
58246149Ssjg# probably makes sense - you can set that in local.sys.mk 
59246149Ssjg.MAKE.DEPENDFILE ?= Makefile.depend.${MACHINE}
60246149Ssjg
61246149Ssjg# we use the pseudo machine "host" for the build host.
62246149Ssjg# this should be taken care of before we get here
63246149Ssjg.if ${OBJTOP:Ua} == ${HOST_OBJTOP:Ub}
64246149SsjgMACHINE = host
65246149Ssjg.endif
66246149Ssjg
67246149Ssjg.if ${.MAKE.LEVEL} == 0
68246149Ssjg# it can be handy to know which MACHINE kicked off the build
69246149Ssjg# for example, if using Makefild.depend for multiple machines,
70246149Ssjg# allowing only MACHINE0 to update can keep things simple.
71246149SsjgMACHINE0 := ${MACHINE}
72246149Ssjg
73246149Ssjg.if defined(PYTHON) && exists(${PYTHON})
74246149Ssjg# we prefer the python version of this - it is much faster
75246149SsjgMETA2DEPS ?= ${.PARSEDIR}/meta2deps.py
76246149Ssjg.else
77246149SsjgMETA2DEPS ?= ${.PARSEDIR}/meta2deps.sh
78246149Ssjg.endif
79246149SsjgMETA2DEPS := ${META2DEPS}
80246149Ssjg.export META2DEPS
81246149Ssjg.endif
82246149Ssjg
83246149SsjgMAKE_PRINT_VAR_ON_ERROR += \
84246149Ssjg	.ERROR_TARGET \
85246149Ssjg	.ERROR_META_FILE \
86246149Ssjg	.MAKE.LEVEL \
87246149Ssjg	MAKEFILE \
88246149Ssjg	.MAKE.MODE
89246149Ssjg
90246149Ssjg.if !defined(SB) && defined(SRCTOP)
91246149SsjgSB = ${SRCTOP:H}
92246149Ssjg.endif
93246149SsjgERROR_LOGDIR ?= ${SB}/error
94246149Ssjgmeta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log
95246149Ssjg
96246149Ssjg# we are not interested in make telling us a failure happened elsewhere
97246149Ssjg.ERROR: _metaError
98246149Ssjg_metaError: .NOMETA .NOTMAIN
99246149Ssjg	-@[ "${.ERROR_META_FILE}" ] && { \
100246149Ssjg	grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \
101246149Ssjg	mkdir -p ${meta_error_log:H}; \
102246149Ssjg	cp ${.ERROR_META_FILE} ${meta_error_log}; \
103246149Ssjg	echo "ERROR: log ${meta_error_log}" >&2; }; :
104246149Ssjg
105246149Ssjg.endif
106246149Ssjg
107246149Ssjg# Are we, after all, in meta mode?
108246149Ssjg.if ${.MAKE.MODE:Mmeta*} != ""
109246149SsjgMKDEP = meta.autodep
110246149Ssjg
111246149Ssjg.if ${.MAKE.LEVEL} == 0
112246149Ssjg# make sure dirdeps target exists and do it first
113246149Ssjgall: dirdeps .WAIT
114246149Ssjgdirdeps:
115246149Ssjg.NOPATH: dirdeps
116246149Ssjg
117246149Ssjg.if defined(ALL_MACHINES)
118246149Ssjg# the first .MAIN: is what counts
119246149Ssjg# by default dirdeps is all we want at level0
120246149Ssjg.MAIN: dirdeps
121246149Ssjg# tell dirdeps.mk what we want
122246149SsjgBUILD_AT_LEVEL0 = no
123246149Ssjg.endif
124246149Ssjg
125246149Ssjg.if ${.MAKE.DEPENDFILE:E} == ${MACHINE}
126246149Ssjg# it works best if we do everything via sub-makes
127246149SsjgBUILD_AT_LEVEL0 ?= no
128246149Ssjg.endif
129246149SsjgBUILD_AT_LEVEL0 ?= yes
130246149Ssjg.endif
131246149Ssjg
132246149Ssjg# if we think we are updating dependencies, 
133246149Ssjg# then filemon had better be present
134246149Ssjg.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no" && !exists(/dev/filemon)
135246149Ssjg.error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded.
136246149Ssjg.endif
137246149Ssjg
138246149Ssjg.endif
139246149Ssjg.endif
140