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