xref: /freebsd/share/mk/local.sys.mk (revision bdd1243d)
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 || true) 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# this will be set via local.meta.sys.env.mk if appropriate
83MK_host_egacy?= no
84
85.if ${.MAKE.MODE:Mmeta*} != ""
86# we can afford to use cookies to prevent some targets
87# re-running needlessly but only when using filemon.
88# Targets that should support the meta mode cookie handling should just be
89# added to META_TARGETS.  If bsd.sys.mk cannot be included then ${META_DEPS}
90# should be added as a target dependency as well.  Otherwise the target
91# is added to in bsd.sys.mk since it comes last.
92.if ${.MAKE.MODE:Mnofilemon} == ""
93# Prepend .OBJDIR if not already there.
94_META_COOKIE_COND=	"${.TARGET:M${.OBJDIR}/*}" == ""
95_META_COOKIE_DEFAULT=	${${_META_COOKIE_COND}:?${.OBJDIR}/${.TARGET}:${.TARGET}}
96# Use the default if COOKIE.${.TARGET} is not defined.
97META_COOKIE=		${COOKIE.${.TARGET}:U${_META_COOKIE_DEFAULT}}
98META_COOKIE_RM=		@rm -f ${META_COOKIE}
99META_COOKIE_TOUCH=	@touch ${META_COOKIE}
100CLEANFILES+=		${META_TARGETS}
101_meta_dep_before:	.USEBEFORE .NOTMAIN
102	${META_COOKIE_RM}
103_meta_dep_after:	.USE .NOTMAIN
104	${META_COOKIE_TOUCH}
105# Attach this to a target to allow it to benefit from meta mode's
106# not rerunning a command if it doesn't need to be considering its
107# metafile/filemon-tracked dependencies.
108META_DEPS=	_meta_dep_before _meta_dep_after .META
109.endif
110.else
111# some targets need to be .PHONY - but not in meta mode
112META_NOPHONY=	.PHONY
113.endif
114META_NOPHONY?=
115META_COOKIE_RM?=
116META_COOKIE_TOUCH?=
117META_DEPS+=	${META_NOPHONY}
118
119.endif
120