xref: /freebsd/share/mk/bsd.init.mk (revision d6eb98610fa65663bf0df4574b7cb2c5c4ffda71)
1# $FreeBSD$
2
3# The include file <bsd.init.mk> includes <bsd.opts.mk>,
4# ../Makefile.inc and <bsd.own.mk>; this is used at the
5# top of all <bsd.*.mk> files that actually "build something".
6# bsd.opts.mk is included early so Makefile.inc can use the
7# MK_FOO variables.
8
9.if !target(__<bsd.init.mk>__)
10__<bsd.init.mk>__:
11.include <bsd.opts.mk>
12.-include "local.init.mk"
13
14.if ${MK_AUTO_OBJ} == "yes"
15# This is also done in bsd.obj.mk
16.if defined(NO_OBJ) && ${.OBJDIR} != ${.CURDIR}
17.OBJDIR: ${.CURDIR}
18.endif
19.endif
20
21.if exists(${.CURDIR}/../Makefile.inc)
22.include "${.CURDIR}/../Makefile.inc"
23.endif
24.include <bsd.own.mk>
25.MAIN: all
26
27# This is used in bsd.{dep,lib,prog}.mk as ${OBJS_SRCS_FILTER:ts:}
28# Some makefiles may want T as well to avoid nested objdirs.
29OBJS_SRCS_FILTER+= R
30
31# Handle INSTALL_AS_USER here to maximize the chance that
32# it has final authority over fooOWN and fooGRP.
33.if ${MK_INSTALL_AS_USER} != "no"
34.if !defined(_uid)
35_uid!=	id -u
36.export _uid
37.endif
38.if ${_uid} != 0
39.if !defined(_gid)
40_gid!=	id -g
41.export _gid
42.endif
43.for x in BIN CONF DOC DTB INFO KMOD LIB MAN NLS SHARE
44$xOWN=	${_uid}
45$xGRP=	${_gid}
46.endfor
47.endif
48.endif
49
50# Some targets need to know when something may build.  This is used to
51# optimize targets that are only needed when building something, such as
52# (not) reading in depend files.  For DIRDEPS_BUILD, it will only calculate
53# the dependency graph at .MAKE.LEVEL==0, so nothing should be built there.
54# Skip "build" logic if:
55# - DIRDEPS_BUILD at MAKELEVEL 0
56# - make -V is used without an override
57# - make install is used without other targets.  This is to avoid breaking
58#   things like 'make all install' or 'make foo install'.
59# - non-build targets are called
60.if ${MK_DIRDEPS_BUILD} == "yes" && ${.MAKE.LEVEL:U1} == 0 && \
61    ${BUILD_AT_LEVEL0:Uyes:tl} == "no" && !make(clean*) && !make(*clean)
62_SKIP_BUILD=	not building at level 0
63.elif !empty(.MAKEFLAGS:M-V${_V_DO_BUILD}) || \
64    ${.TARGETS:M*install*} == ${.TARGETS} || \
65    ${.TARGETS:Mclean*} == ${.TARGETS} || \
66    ${.TARGETS:M*clean} == ${.TARGETS} || \
67    ${.TARGETS:Mdestroy*} == ${.TARGETS} || \
68    ${.TARGETS:Mobj} == ${.TARGETS} || \
69    make(analyze) || make(print-dir)
70# Skip building, but don't show a warning.
71_SKIP_BUILD=
72.endif
73.if ${MK_DIRDEPS_BUILD} == "yes" && ${.MAKE.LEVEL} > 0 && !empty(_SKIP_BUILD)
74.warning ${_SKIP_BUILD}
75.endif
76
77beforebuild: .PHONY .NOTMAIN
78.if !defined(_SKIP_BUILD)
79all: beforebuild .WAIT
80.endif
81
82.if ${MK_META_MODE} == "yes"
83.if !exists(/dev/filemon) && \
84    ${UPDATE_DEPENDFILE:Uyes:tl} != "no" && !defined(NO_FILEMON) && \
85    !make(test-system-*) && !make(showconfig) && !make(print-dir) && \
86    ${.MAKEFLAGS:M-V} == ""
87.warning The filemon module (/dev/filemon) is not loaded.
88.warning META_MODE is less useful for incremental builds without filemon.
89.warning 'kldload filemon' or pass -DNO_FILEMON to suppress this warning.
90.endif
91.endif	# ${MK_META_MODE} == "yes"
92
93.endif	# !target(__<bsd.init.mk>__)
94