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