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