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