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