]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.subdir.mk
Add missing .PHONY for parallel subdir target.
[FreeBSD/FreeBSD.git] / share / mk / bsd.subdir.mk
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. SUBDIR.yes is automatically appeneded
20 #               to this list.
21 #
22 # +++ targets +++
23 #
24 #       distribute:
25 #               This is a variant of install, which will
26 #               put the stuff into the right "distribution".
27 #
28 #       See ALL_SUBDIR_TARGETS for list of targets that will recurse.
29 #       Custom targets can be added to SUBDIR_TARGETS in src.conf.
30 #
31
32 .if !target(__<bsd.subdir.mk>__)
33 __<bsd.subdir.mk>__:
34
35 ALL_SUBDIR_TARGETS= all all-man buildconfig checkdpadd clean cleandepend \
36                     cleandir cleanilinks cleanobj depend distribute \
37                     installconfig lint maninstall manlint obj objlink \
38                     realinstall regress tags \
39                     ${SUBDIR_TARGETS}
40
41 .include <bsd.init.mk>
42
43 .if !defined(NEED_SUBDIR)
44 .if ${.MAKE.LEVEL} == 0 && ${MK_META_MODE} == "yes" && !empty(SUBDIR) && !(make(clean*) || make(destroy*))
45 .include <meta.subdir.mk>
46 # ignore this
47 _SUBDIR:
48 .endif
49 .endif
50 .if !target(_SUBDIR)
51
52 .if defined(SUBDIR)
53 SUBDIR:=${SUBDIR} ${SUBDIR.yes}
54 SUBDIR:=${SUBDIR:u}
55 .endif
56
57 DISTRIBUTION?=  base
58 .if !target(distribute)
59 distribute: .MAKE
60 .for dist in ${DISTRIBUTION}
61         ${_+_}cd ${.CURDIR}; \
62             ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
63 .endfor
64 .endif
65
66 _SUBDIR: .USE .MAKE
67 .if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
68         @${_+_}for entry in ${SUBDIR:N.WAIT}; do \
69                 if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \
70                         ${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH} (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
71                         edir=$${entry}.${MACHINE_ARCH}; \
72                         cd ${.CURDIR}/$${edir}; \
73                 else \
74                         ${ECHODIR} "===> ${DIRPRFX}$$entry (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
75                         edir=$${entry}; \
76                         cd ${.CURDIR}/$${edir}; \
77                 fi; \
78                 ${MAKE} ${.TARGET:S,realinstall,install,:S,^_sub.,,} \
79                     DIRPRFX=${DIRPRFX}$$edir/; \
80         done
81 .endif
82
83 ${SUBDIR:N.WAIT}: .PHONY .MAKE
84         ${_+_}@if test -d ${.TARGET}.${MACHINE_ARCH}; then \
85                 cd ${.CURDIR}/${.TARGET}.${MACHINE_ARCH}; \
86         else \
87                 cd ${.CURDIR}/${.TARGET}; \
88         fi; \
89         ${MAKE} all
90
91 # Work around parsing of .if nested in .for by putting .WAIT string into a var.
92 __wait= .WAIT
93 .for __target in ${ALL_SUBDIR_TARGETS}
94 .ifdef SUBDIR_PARALLEL
95 __subdir_targets=
96 .for __dir in ${SUBDIR}
97 .if ${__wait} == ${__dir}
98 __subdir_targets+= .WAIT
99 .else
100 __subdir_targets+= ${__target}_subdir_${__dir}
101 __deps=
102 .for __dep in ${SUBDIR_DEPEND_${__dir}}
103 __deps+= ${__target}_subdir_${__dep}
104 .endfor
105 ${__target}_subdir_${__dir}: .PHONY .MAKE ${__deps}
106 .if !defined(NO_SUBDIR)
107         @${_+_}if test -d ${.CURDIR}/${__dir}.${MACHINE_ARCH}; then \
108                         ${ECHODIR} "===> ${DIRPRFX}${__dir}.${MACHINE_ARCH} (${__target:realinstall=install})"; \
109                         edir=${__dir}.${MACHINE_ARCH}; \
110                         cd ${.CURDIR}/$${edir}; \
111                 else \
112                         ${ECHODIR} "===> ${DIRPRFX}${__dir} (${__target:realinstall=install})"; \
113                         edir=${__dir}; \
114                         cd ${.CURDIR}/$${edir}; \
115                 fi; \
116                 ${MAKE} ${__target:realinstall=install} \
117                     DIRPRFX=${DIRPRFX}$$edir/
118 .endif
119 .endif
120 .endfor
121 ${__target}: ${__subdir_targets}
122 .else
123 ${__target}: _sub.${__target}
124 _sub.${__target}: _SUBDIR
125 .endif
126 .endfor
127
128 # This is to support 'make includes' calling 'make buildincludes' and
129 # 'make installincludes' in the proper order, and to support these
130 # targets as SUBDIR_TARGETS.
131 .for __target in files includes
132 .for __stage in build install
133 ${__stage}${__target}:
134 .if make(${__stage}${__target})
135 ${__stage}${__target}: _sub.${__stage}${__target}
136 _sub.${__stage}${__target}: _SUBDIR
137 .endif
138 .endfor
139 .if !target(${__target})
140 ${__target}: .MAKE
141         ${_+_}cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target}
142 .endif
143 .endfor
144
145 .endif
146
147 .if !target(install)
148 .if !target(beforeinstall)
149 beforeinstall:
150 .endif
151 .if !target(afterinstall)
152 afterinstall:
153 .endif
154 install: beforeinstall realinstall afterinstall
155 .ORDER: beforeinstall realinstall afterinstall
156 .endif
157
158 .endif