xref: /freebsd/share/mk/local.sys.mk (revision 0468e89cb35936d608cd2760135a791350f2f161)
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(*-jobs) && empty(JOB_MAX)
63# provide a reasonable? default for JOB_MAX based on ncpu
64JOB_MAX_FACTOR?= 1.33
65NPROC?= ${(type nproc) 2> /dev/null:L:sh:M/*:[1]}
66NPROC:= ${NPROC}
67.if !empty(NPROC)
68ncpu!= ${NPROC}
69.elif ${.MAKE.OS:NDarwin:NFreeBSD} == ""
70ncpu!= sysctl -n hw.ncpu
71.endif
72.if ${ncpu:U0} > 1
73.if ${JOB_MAX_FACTOR} == 1
74JOB_MAX:= ${ncpu}
75.else
76jm!= echo ${ncpu} \* ${JOB_MAX_FACTOR} | bc
77JOB_MAX:= ${jm:R}
78.endif
79.endif
80.endif
81
82.if ${.MAKE.MODE:Mmeta*} != ""
83# we can afford to use cookies to prevent some targets
84# re-running needlessly but only when using filemon.
85# Targets that should support the meta mode cookie handling should just be
86# added to META_TARGETS.  If bsd.sys.mk cannot be included then ${META_DEPS}
87# should be added as a target dependency as well.  Otherwise the target
88# is added to in bsd.sys.mk since it comes last.
89.if ${.MAKE.MODE:Mnofilemon} == ""
90# Prepend .OBJDIR if not already there.
91_META_COOKIE_COND=	"${.TARGET:M${.OBJDIR}/*}" == ""
92_META_COOKIE_DEFAULT=	${${_META_COOKIE_COND}:?${.OBJDIR}/${.TARGET}:${.TARGET}}
93# Use the default if COOKIE.${.TARGET} is not defined.
94META_COOKIE=		${COOKIE.${.TARGET}:U${_META_COOKIE_DEFAULT}}
95META_COOKIE_RM=		@rm -f ${META_COOKIE}
96META_COOKIE_TOUCH=	@touch ${META_COOKIE}
97CLEANFILES+=		${META_TARGETS}
98_meta_dep_before:	.USEBEFORE .NOTMAIN
99	${META_COOKIE_RM}
100_meta_dep_after:	.USE .NOTMAIN
101	${META_COOKIE_TOUCH}
102# Attach this to a target to allow it to benefit from meta mode's
103# not rerunning a command if it doesn't need to be considering its
104# metafile/filemon-tracked dependencies.
105META_DEPS=	_meta_dep_before _meta_dep_after .META
106.endif
107.else
108# some targets need to be .PHONY - but not in meta mode
109META_NOPHONY=	.PHONY
110.endif
111META_NOPHONY?=
112META_COOKIE_RM?=
113META_COOKIE_TOUCH?=
114META_DEPS+=	${META_NOPHONY}
115
116.endif
117