xref: /freebsd/share/mk/bsd.subdir.mk (revision ee7b0571c2c18bdec848ed2044223cc88db29bd8)
1#	from: @(#)bsd.subdir.mk	5.9 (Berkeley) 2/1/91
2# $FreeBSD$
3#
4# The include file <bsd.subdir.mk> contains the default targets
5# for building subdirectories.
6#
7# For all of the directories listed in the variable SUBDIRS, the
8# specified directory will be visited and the target made. There is
9# also a default target which allows the command "make subdir" where
10# subdir is any directory listed in the variable SUBDIRS.
11#
12#
13# +++ variables +++
14#
15# DISTRIBUTION	Name of distribution. [base]
16#
17# SUBDIR	A list of subdirectories that should be built as well.
18#		Each of the targets will execute the same target in the
19#		subdirectories.
20#
21# +++ targets +++
22#
23#	distribute:
24# 		This is a variant of install, which will
25# 		put the stuff into the right "distribution".
26#
27#	afterinstall, all, all-man, beforeinstall, checkdpadd, clean,
28#	cleandepend, cleandir, cleanilinks depend, install, lint,
29#	maninstall, manlint, obj, objlink, realinstall, regress, tags
30#
31
32.if !target(__<bsd.subdir.mk>__)
33__<bsd.subdir.mk>__:
34
35.include <bsd.init.mk>
36
37.if defined(.PARSEDIR) && !defined(NEED_SUBDIR)
38.if ${.MAKE.LEVEL} == 0 && ${.MAKE.MODE:Mmeta*} != "" && !empty(SUBDIR) && !(make(clean*) || make(destroy*))
39.include <meta.subdir.mk>
40# ignore this
41_SUBDIR:
42.endif
43.endif
44.if !target(_SUBDIR)
45
46DISTRIBUTION?=	base
47.if !target(distribute)
48distribute: .MAKE
49.for dist in ${DISTRIBUTION}
50	${_+_}cd ${.CURDIR}; \
51	    ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
52.endfor
53.endif
54
55_SUBDIR: .USE .MAKE
56.if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
57	@${_+_}set -e; for entry in ${SUBDIR:N.WAIT}; do \
58		if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \
59			${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH} (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
60			edir=$${entry}.${MACHINE_ARCH}; \
61			cd ${.CURDIR}/$${edir}; \
62		else \
63			${ECHODIR} "===> ${DIRPRFX}$$entry (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
64			edir=$${entry}; \
65			cd ${.CURDIR}/$${edir}; \
66		fi; \
67		${MAKE} ${.TARGET:S,realinstall,install,:S,^_sub.,,} \
68		    DIRPRFX=${DIRPRFX}$$edir/; \
69	done
70.endif
71
72${SUBDIR:N.WAIT}: .PHONY .MAKE
73	${_+_}@if test -d ${.TARGET}.${MACHINE_ARCH}; then \
74		cd ${.CURDIR}/${.TARGET}.${MACHINE_ARCH}; \
75	else \
76		cd ${.CURDIR}/${.TARGET}; \
77	fi; \
78	${MAKE} all
79
80# Work around parsing of .if nested in .for by putting .WAIT string into a var.
81__wait= .WAIT
82.for __target in all all-man checkdpadd clean cleandepend cleandir \
83    cleanilinks depend distribute lint maninstall manlint obj objlink \
84    realinstall regress tags ${SUBDIR_TARGETS}
85.ifdef SUBDIR_PARALLEL
86__subdir_targets=
87.for __dir in ${SUBDIR}
88.if ${__wait} == ${__dir}
89__subdir_targets+= .WAIT
90.else
91__subdir_targets+= ${__target}_subdir_${__dir}
92__deps=
93.for __dep in ${SUBDIR_DEPEND_${__dir}}
94__deps+= ${__target}_subdir_${__dep}
95.endfor
96${__target}_subdir_${__dir}: .MAKE ${__deps}
97.if !defined(NO_SUBDIR)
98	@${_+_}set -e; \
99		if test -d ${.CURDIR}/${__dir}.${MACHINE_ARCH}; then \
100			${ECHODIR} "===> ${DIRPRFX}${__dir}.${MACHINE_ARCH} (${__target:realinstall=install})"; \
101			edir=${__dir}.${MACHINE_ARCH}; \
102			cd ${.CURDIR}/$${edir}; \
103		else \
104			${ECHODIR} "===> ${DIRPRFX}${__dir} (${__target:realinstall=install})"; \
105			edir=${__dir}; \
106			cd ${.CURDIR}/$${edir}; \
107		fi; \
108		${MAKE} ${__target:realinstall=install} \
109		    DIRPRFX=${DIRPRFX}$$edir/
110.endif
111.endif
112.endfor
113${__target}: ${__subdir_targets}
114.else
115${__target}: _sub.${__target}
116_sub.${__target}: _SUBDIR
117.endif
118.endfor
119
120.for __target in files includes
121.for __stage in build install
122${__stage}${__target}:
123.if make(${__stage}${__target})
124${__stage}${__target}: _sub.${__stage}${__target}
125_sub.${__stage}${__target}: _SUBDIR
126.endif
127.endfor
128.if !target(${__target})
129${__target}: .MAKE
130	${_+_}set -e; cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target}
131.endif
132.endfor
133
134.endif
135
136.if !target(install)
137.if !target(beforeinstall)
138beforeinstall:
139.endif
140.if !target(afterinstall)
141afterinstall:
142.endif
143install: beforeinstall realinstall afterinstall
144.ORDER: beforeinstall realinstall afterinstall
145.endif
146
147.endif
148