xref: /freebsd/share/mk/local.sys.mk (revision cd0d51baaa4509a1db83251a601d34404d20c990)
1# $FreeBSD$
2
3.if ${MK_DIRDEPS_BUILD} == "yes" || ${MK_META_MODE} == "yes"
4
5# Not in the below list as it may make sense for non-meta mode
6# eventually.  meta.sys.mk (DIRDEPS_BUILD) also already adds these in.
7.if ${MK_DIRDEPS_BUILD} == "no" && ${MK_META_MODE} == "yes"
8MAKE_PRINT_VAR_ON_ERROR += \
9	.ERROR_TARGET \
10	.ERROR_META_FILE \
11	.MAKE.LEVEL \
12	MAKEFILE \
13	.MAKE.MODE
14.endif
15
16_ERROR_CMD_EXEC=	${sed -n '/^CMD/s,^CMD \(.*\),\1;,p' ${.ERROR_META_FILE}:L:sh}
17_ERROR_CMD=		${!empty(.ERROR_META_FILE):?${_ERROR_CMD_EXEC}:.PHONY}
18MAKE_PRINT_VAR_ON_ERROR+= \
19	_ERROR_CMD \
20	.CURDIR \
21	.MAKE \
22	.OBJDIR \
23	.TARGETS \
24	DESTDIR \
25	LD_LIBRARY_PATH \
26	MACHINE \
27	MACHINE_ARCH \
28	MAKEOBJDIRPREFIX \
29	MAKESYSPATH \
30	MAKE_VERSION \
31	PATH \
32	SRCTOP \
33	OBJTOP \
34	${MAKE_PRINT_VAR_ON_ERROR_XTRAS}
35
36# Meta mode may rebuild targets that then fail. The next build won't detect
37# the meta mode change. Not all targets have a 'rm ${.TARGET}' in them
38# so force it.
39.DELETE_ON_ERROR:
40
41.if ${.MAKE.LEVEL} > 0
42MAKE_PRINT_VAR_ON_ERROR += .MAKE.MAKEFILES .PATH
43.endif
44.endif
45
46.if !empty(.OBJDIR)
47OBJTOP?= ${.OBJDIR:S,${.CURDIR},,}${SRCTOP}
48.endif
49
50.if !empty(LIBDIR)
51_PREMK_LIBDIR:=	${LIBDIR}
52.endif
53
54.include "src.sys.mk"
55
56.if ${.MAKE.MODE:Mmeta*} != ""
57# we can afford to use cookies to prevent some targets
58# re-running needlessly but only when using filemon.
59# Targets that should support the meta mode cookie handling should just be
60# added to META_TARGETS.  If bsd.sys.mk cannot be included then ${META_DEPS}
61# should be added as a target dependency as well.  Otherwise the target
62# is added to in bsd.sys.mk since it comes last.
63.if ${.MAKE.MODE:Mnofilemon} == ""
64# Prepend .OBJDIR if not already there.
65_META_COOKIE_COND=	"${.TARGET:M${.OBJDIR}/*}" == ""
66_META_COOKIE_DEFAULT=	${${_META_COOKIE_COND}:?${.OBJDIR}/${.TARGET}:${.TARGET}}
67# Use the default if COOKIE.${.TARGET} is not defined.
68META_COOKIE=		${COOKIE.${.TARGET}:U${_META_COOKIE_DEFAULT}}
69META_COOKIE_RM=		@rm -f ${META_COOKIE}
70META_COOKIE_TOUCH=	@touch ${META_COOKIE}
71CLEANFILES+=		${META_TARGETS}
72_meta_dep_before:	.USEBEFORE .NOTMAIN
73	${META_COOKIE_RM}
74_meta_dep_after:	.USE .NOTMAIN
75	${META_COOKIE_TOUCH}
76# Attach this to a target to allow it to benefit from meta mode's
77# not rerunning a command if it doesn't need to be considering its
78# metafile/filemon-tracked dependencies.
79META_DEPS=	_meta_dep_before _meta_dep_after .META
80.endif
81.else
82# some targets need to be .PHONY - but not in meta mode
83META_NOPHONY=	.PHONY
84.endif
85META_NOPHONY?=
86META_COOKIE_RM?=
87META_COOKIE_TOUCH?=
88META_DEPS+=	${META_NOPHONY}
89