aboutsummaryrefslogtreecommitdiff
path: root/share/mk/bsd.subdir.mk
blob: f9b9e979c2a694c583467d58e4af4b58c6c70630 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#	from: @(#)bsd.subdir.mk	5.9 (Berkeley) 2/1/91
# $FreeBSD$
#
# The include file <bsd.subdir.mk> contains the default targets
# for building subdirectories.
#
# For all of the directories listed in the variable SUBDIRS, the
# specified directory will be visited and the target made. There is
# also a default target which allows the command "make subdir" where
# subdir is any directory listed in the variable SUBDIRS.
#
#
# +++ variables +++
#
# DISTRIBUTION	Name of distribution. [base]
#
# SUBDIR	A list of subdirectories that should be built as well.
#		Each of the targets will execute the same target in the
#		subdirectories. SUBDIR.yes is automatically appeneded
#		to this list.
#
# +++ targets +++
#
#	distribute:
# 		This is a variant of install, which will
# 		put the stuff into the right "distribution".
#
# 	See ALL_SUBDIR_TARGETS for list of targets that will recurse.
# 	Custom targets can be added to SUBDIR_TARGETS in src.conf.
#
# 	Targets defined in STANDALONE_SUBDIR_TARGETS will always be ran
# 	with SUBDIR_PARALLEL and will not respect .WAIT or SUBDIR_DEPEND_
# 	values.
#

.if !target(__<bsd.subdir.mk>__)
__<bsd.subdir.mk>__:

ALL_SUBDIR_TARGETS= all all-man buildconfig checkdpadd clean cleandepend \
		    cleandir cleanilinks cleanobj depend distribute \
		    installconfig lint maninstall manlint obj objlink \
		    realinstall regress tags \
		    ${SUBDIR_TARGETS}

# Described above.
STANDALONE_SUBDIR_TARGETS?= obj checkdpadd clean cleandepend cleandir \
			    cleanilinks cleanobj

.include <bsd.init.mk>

.if !defined(NEED_SUBDIR)
.if ${.MAKE.LEVEL} == 0 && ${MK_META_MODE} == "yes" && !empty(SUBDIR) && !(make(clean*) || make(destroy*))
.include <meta.subdir.mk>
# ignore this
_SUBDIR:
.endif
.endif
.if !target(_SUBDIR)

.if defined(SUBDIR)
SUBDIR:=${SUBDIR} ${SUBDIR.yes}
SUBDIR:=${SUBDIR:u}
.endif

DISTRIBUTION?=	base
.if !target(distribute)
distribute: .MAKE
.for dist in ${DISTRIBUTION}
	${_+_}cd ${.CURDIR}; \
	    ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
.endfor
.endif

# Subdir code shared among 'make <subdir>', 'make <target>' and SUBDIR_PARALLEL.
_SUBDIR_SH=	\
		if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \
			dir=$${dir}.${MACHINE_ARCH}; \
		fi; \
		${ECHODIR} "===> ${DIRPRFX}$${dir} ($${target})"; \
		cd ${.CURDIR}/$${dir}; \
		${MAKE} $${target} DIRPRFX=${DIRPRFX}$${dir}/

_SUBDIR: .USEBEFORE
.if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
	@${_+_}target=${.TARGET:S,realinstall,install,}; \
	    for dir in ${SUBDIR:N.WAIT}; do ( ${_SUBDIR_SH} ); done
.endif

${SUBDIR:N.WAIT}: .PHONY .MAKE
	${_+_}@target=all; \
	    dir=${.TARGET}; \
	    ${_SUBDIR_SH};

# Work around parsing of .if nested in .for by putting .WAIT string into a var.
__wait= .WAIT
.for __target in ${ALL_SUBDIR_TARGETS}
# Can ordering be skipped for this and SUBDIR_PARALLEL forced?
.if make(${__target}) && ${STANDALONE_SUBDIR_TARGETS:M${__target}}
_is_standalone_target=	1
SUBDIR:=	${SUBDIR:N.WAIT}
.else
_is_standalone_target=	0
.endif
.if defined(SUBDIR_PARALLEL) || ${_is_standalone_target} == 1
__subdir_targets=
.for __dir in ${SUBDIR}
.if ${__wait} == ${__dir}
__subdir_targets+= .WAIT
.else
__subdir_targets+= ${__target}_subdir_${__dir}
__deps=
.if ${_is_standalone_target} == 0
.for __dep in ${SUBDIR_DEPEND_${__dir}}
__deps+= ${__target}_subdir_${__dep}
.endfor
.endif
${__target}_subdir_${__dir}: .PHONY .MAKE ${__deps}
.if !defined(NO_SUBDIR)
	@${_+_}target=${__target:realinstall=install}; \
	    dir=${__dir}; \
	    ${_SUBDIR_SH};
.endif
.endif
.endfor	# __dir in ${SUBDIR}
${__target}: ${__subdir_targets}
.else
${__target}: _SUBDIR
.endif	# SUBDIR_PARALLEL || _is_standalone_target
.endfor	# __target in ${ALL_SUBDIR_TARGETS}

# This is to support 'make includes' calling 'make buildincludes' and
# 'make installincludes' in the proper order, and to support these
# targets as SUBDIR_TARGETS.
.for __target in files includes
.for __stage in build install
${__stage}${__target}:
.if make(${__stage}${__target})
${__stage}${__target}: _SUBDIR
.endif
.endfor
.if !target(${__target})
${__target}: .MAKE
	${_+_}cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target}
.endif
.endfor

.endif

.if !target(install)
.if !target(beforeinstall)
beforeinstall:
.endif
.if !target(afterinstall)
afterinstall:
.endif
install: beforeinstall realinstall afterinstall
.ORDER: beforeinstall realinstall afterinstall
.endif

.endif