xref: /freebsd/share/mk/meta.sys.mk (revision 63d1fd5970ec814904aa0f4580b10a0d302d08b2)
1# $FreeBSD$
2# $Id: meta.sys.mk,v 1.19 2014/08/02 23:16:02 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# absoulte 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# make defaults .MAKE.DEPENDFILE to .depend
60# that won't work for us.
61.if ${.MAKE.DEPENDFILE} == ".depend"
62.undef .MAKE.DEPENDFILE
63.endif
64
65# if you don't cross build for multiple MACHINEs concurrently, then
66# .MAKE.DEPENDFILE = Makefile.depend
67# probably makes sense - you can set that in local.sys.mk
68.MAKE.DEPENDFILE ?= Makefile.depend.${MACHINE}
69
70# we use the pseudo machine "host" for the build host.
71# this should be taken care of before we get here
72.if ${OBJTOP:Ua} == ${HOST_OBJTOP:Ub}
73MACHINE = host
74.endif
75
76.if ${.MAKE.LEVEL} == 0
77# it can be handy to know which MACHINE kicked off the build
78# for example, if using Makefild.depend for multiple machines,
79# allowing only MACHINE0 to update can keep things simple.
80MACHINE0 := ${MACHINE}
81.export MACHINE0
82
83.if defined(PYTHON) && exists(${PYTHON})
84# we prefer the python version of this - it is much faster
85META2DEPS ?= ${.PARSEDIR}/meta2deps.py
86.else
87META2DEPS ?= ${.PARSEDIR}/meta2deps.sh
88.endif
89META2DEPS := ${META2DEPS}
90.export META2DEPS
91.endif
92
93MAKE_PRINT_VAR_ON_ERROR += \
94	.ERROR_TARGET \
95	.ERROR_META_FILE \
96	.MAKE.LEVEL \
97	MAKEFILE \
98	.MAKE.MODE
99
100.if !defined(SB) && defined(SRCTOP)
101SB = ${SRCTOP:H}
102.endif
103ERROR_LOGDIR ?= ${SB}/error
104meta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log
105
106# we are not interested in make telling us a failure happened elsewhere
107.ERROR: _metaError
108_metaError: .NOMETA .NOTMAIN
109	-@[ "${.ERROR_META_FILE}" ] && { \
110	grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \
111	mkdir -p ${meta_error_log:H}; \
112	cp ${.ERROR_META_FILE} ${meta_error_log}; \
113	echo "ERROR: log ${meta_error_log}" >&2; }; :
114
115.endif
116
117# Are we, after all, in meta mode?
118.if ${.MAKE.MODE:Uno:Mmeta*} != ""
119MKDEP_MK = meta.autodep.mk
120
121# we can afford to use cookies to prevent some targets
122# re-running needlessly
123META_COOKIE_TOUCH?= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET:T}}
124META_NOPHONY=
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 we think we are updating dependencies,
135# then filemon had better be present
136.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no" && !exists(/dev/filemon)
137.error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded.
138.endif
139
140.if ${.MAKE.LEVEL} == 0
141# make sure dirdeps target exists and do it first
142all: dirdeps .WAIT
143dirdeps:
144.NOPATH: dirdeps
145
146.if defined(ALL_MACHINES)
147# the first .MAIN: is what counts
148# by default dirdeps is all we want at level0
149.MAIN: dirdeps
150# tell dirdeps.mk what we want
151BUILD_AT_LEVEL0 = no
152.endif
153.if ${.TARGETS:Nall} == ""
154# it works best if we do everything via sub-makes
155BUILD_AT_LEVEL0 ?= no
156.endif
157
158.endif
159.else
160META_COOKIE_TOUCH=
161# some targets need to be .PHONY in non-meta mode
162META_NOPHONY= .PHONY
163.endif
164.endif
165