build - Support concurrent SUBDIR traversal, fix make depend bug
[dragonfly.git] / share / mk / bsd.subdir.mk
... / ...
CommitLineData
1# The include file <bsd.subdir.mk> contains the default targets
2# for building subdirectories.
3#
4# For all of the directories listed in the variable SUBDIRS, the
5# specified directory will be visited and the target made. There is
6# also a default target which allows the command "make subdir" where
7# subdir is any directory listed in the variable SUBDIRS.
8#
9#
10# +++ variables +++
11#
12# SUBDIR A list of subdirectories that should be built as well.
13# Each of the targets will execute the same target in the
14# subdirectories.
15#
16# SUBDIR_ORDERED A list of subdirectories which also must be included in
17# in SUBDIR which have ordering requirements. If this
18# Make variable does not exist then all subdirectories are
19# assumed to be strictly ordered.
20#
21# +++ targets +++
22#
23# afterinstall, all, all-man, beforeinstall, checkdpadd,
24# clean, cleandepend, cleandir, depend, install, lint, maninstall,
25# manlint, obj, objlink, realinstall, regress, tags
26#
27
28.include <bsd.init.mk>
29
30# If SUBDIR_ORDERED not specified we default strongly ordering all
31# subdirectories.
32#
33SUBDIR_ORDERED?= ${SUBDIR}
34
35__targets= \
36 checkdpadd clean cleandepend cleandir cleanobj \
37 obj objlink tags depend all all-man \
38 maninstall realinstall \
39 lint manlint regress \
40 buildfiles buildincludes installfiles installincludes
41
42.for __target in ${__targets}
43
44.if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
45
46_SUBDIR_${__target}: ${SUBDIR:S/^/_SUBDIR_${__target}_/}
47
48# Now create the command set for each subdirectory and target
49#
50
51.for entry in ${SUBDIR}
52_SUBDIR_${__target}_${entry}:
53 @(if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
54 ${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH}"; \
55 edir=${entry}.${MACHINE_ARCH}; \
56 cd ${.CURDIR}/$${edir}; \
57 else \
58 ${ECHODIR} "===> ${DIRPRFX}${entry}"; \
59 edir=${entry}; \
60 cd ${.CURDIR}/$${edir}; \
61 fi; \
62 ${MAKE} ${__target:realinstall=install} \
63 DIRPRFX=${DIRPRFX}$$edir/;)
64
65.endfor
66
67# order subdirectories for each target, set up dependency
68#
69.ORDER: ${SUBDIR_ORDERED:S/^/_SUBDIR_${__target}_/}
70
71.else
72
73_SUBDIR_${__target}: .USE
74
75.endif
76
77.endfor
78
79${SUBDIR}::
80 @if test -d ${.TARGET}.${MACHINE_ARCH}; then \
81 cd ${.CURDIR}/${.TARGET}.${MACHINE_ARCH}; \
82 else \
83 cd ${.CURDIR}/${.TARGET}; \
84 fi; \
85 ${MAKE} all
86
87
88.for __target in ${__targets}
89${__target}: _SUBDIR_${__target}
90.endfor
91
92.for __target in files includes
93.for __stage in build install
94${__stage}${__target}:
95.if make(${__stage}${__target})
96${__stage}${__target}: _SUBDIR_${__stage}${__target}
97.endif
98.endfor
99${__target}:
100 cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target}
101.endfor
102
103.if !target(install)
104.if !target(beforeinstall)
105beforeinstall:
106.endif
107.if !target(afterinstall)
108afterinstall:
109.endif
110install: beforeinstall realinstall afterinstall
111.ORDER: beforeinstall realinstall afterinstall
112.endif
113
114.ORDER: ${__targets:S/^/_SUBDIR_/}