]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.subdir.mk
zfs: merge openzfs/zfs@10e36e176
[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 and SUBDIR.yes.yes are
20 #               automatically appended 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 SUBDIR_TARGETS for list of targets that will recurse.
29 #
30 #       Targets defined in STANDALONE_SUBDIR_TARGETS will always be ran
31 #       with SUBDIR_PARALLEL and will not respect .WAIT or SUBDIR_DEPEND_
32 #       values.
33 #
34 #       SUBDIR_TARGETS and STANDALONE_SUBDIR_TARGETS can be appended to
35 #       via make.conf or src.conf.
36 #
37
38 .if !target(__<bsd.subdir.mk>__)
39 __<bsd.subdir.mk>__:
40
41 .if ${MK_AUTO_OBJ} == "no"
42 _obj=   obj
43 .endif
44
45 SUBDIR_TARGETS+= \
46                 all all-man analyze buildconfig buildfiles buildincludes \
47                 checkdpadd clean cleandepend cleandir cleanilinks \
48                 cleanobj depend distribute files includes installconfig \
49                 installdirs \
50                 installfiles installincludes print-dir realinstall \
51                 maninstall manlint ${_obj} objlink tags \
52
53 # Described above.
54 STANDALONE_SUBDIR_TARGETS+= \
55                 all-man buildconfig buildfiles buildincludes check checkdpadd \
56                 clean cleandepend cleandir cleanilinks cleanobj files includes \
57                 installconfig installdirs installincludes installfiles print-dir \
58                 maninstall manlint obj objlink
59
60 # It is safe to install in parallel when staging.
61 .if defined(NO_ROOT) || !empty(SYSROOT)
62 STANDALONE_SUBDIR_TARGETS+= realinstall
63 .endif
64
65 .include <bsd.init.mk>
66
67 .if ${MK_META_MODE} == "yes"
68 .MAKE.JOB.PREFIX=
69 ECHODIR=        :
70 .endif
71
72 .if make(print-dir)
73 NEED_SUBDIR=    1
74 ECHODIR=        :
75 .SILENT:
76 .if ${RELDIR:U.} != "."
77 print-dir:      .PHONY
78         @echo ${RELDIR}
79 .endif
80 .endif
81
82 .if ${MK_AUTO_OBJ} == "yes" && !target(obj)
83 obj: .PHONY
84 .endif
85
86 .if !defined(NEED_SUBDIR)
87 # .MAKE.DEPENDFILE==/dev/null is set by bsd.dep.mk to avoid reading
88 # Makefile.depend
89 .if ${.MAKE.LEVEL} == 0 && ${MK_DIRDEPS_BUILD} == "yes" && !empty(SUBDIR) && \
90     ${.MAKE.DEPENDFILE} != "/dev/null"
91 .include <meta.subdir.mk>
92 # ignore this
93 _SUBDIR:
94 .endif
95 .endif
96
97 DISTRIBUTION?=  base
98 .if !target(distribute)
99 distribute: .MAKE
100 .for dist in ${DISTRIBUTION}
101         ${_+_}cd ${.CURDIR}; \
102             ${MAKE} install installconfig -DNO_SUBDIR DISTBASE=/${dist} DESTDIR=${DISTDIR}/${dist} SHARED=copies
103 .endfor
104 .endif
105 # Convenience targets to run 'build${target}' and 'install${target}' when
106 # calling 'make ${target}'.
107 .for __target in files includes
108 .if !target(${__target})
109 ${__target}:    build${__target} install${__target}
110 .ORDER:         build${__target} install${__target}
111 .endif
112 .endfor
113
114 # Make 'install' supports a before and after target.  Actual install
115 # hooks are placed in 'realinstall'.
116 .if !target(install)
117 .for __stage in before real after
118 .if !target(${__stage}install)
119 ${__stage}install:
120 .endif
121 .endfor
122 install:        beforeinstall realinstall afterinstall
123 .ORDER:         beforeinstall realinstall afterinstall
124 .endif
125 .ORDER: all install
126
127 # SUBDIR recursing may be disabled for MK_DIRDEPS_BUILD
128 .if !target(_SUBDIR)
129
130 .if defined(SUBDIR) || defined(SUBDIR.yes) || defined(SUBDIR.yes.yes)
131 SUBDIR:=${SUBDIR} ${SUBDIR.yes} ${SUBDIR.yes.yes}
132 SUBDIR:=${SUBDIR:u}
133 .endif
134
135 .if defined(SUBDIR.)
136 .error ${.CURDIR}: Found variable SUBDIR. with value "${SUBDIR.}". This was \
137         probably caused by using SUBDIR.$${MK_FOO} without including \
138         <src.opts.mk> or by using an invalid $${MK_FOO} option.
139 .endif
140
141 # Subdir code shared among 'make <subdir>', 'make <target>' and SUBDIR_PARALLEL.
142 _SUBDIR_SH=     \
143                 if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \
144                         dir=$${dir}.${MACHINE_ARCH}; \
145                 fi; \
146                 ${ECHODIR} "===> ${DIRPRFX}$${dir} ($${target})"; \
147                 cd ${.CURDIR}/$${dir}; \
148                 ${MAKE} $${target} DIRPRFX=${DIRPRFX}$${dir}/
149
150 # This is kept for compatibility only.  The normal handling of attaching to
151 # SUBDIR_TARGETS will create a target for each directory.
152 _SUBDIR: .USEBEFORE
153 .if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
154         @${_+_}target=${.TARGET:realinstall=install}; \
155             for dir in ${SUBDIR:N.WAIT}; do ( ${_SUBDIR_SH} ); done
156 .endif
157
158 # Create 'make subdir' targets to run the real 'all' target.
159 .for __dir in ${SUBDIR:N.WAIT}
160 ${__dir}: all_subdir_${DIRPRFX}${__dir} .PHONY
161 .endfor
162
163 .for __target in ${SUBDIR_TARGETS}
164 # Can ordering be skipped for this and SUBDIR_PARALLEL forced?
165 .if ${STANDALONE_SUBDIR_TARGETS:M${__target}}
166 _is_standalone_target=  1
167 _subdir_filter= N.WAIT
168 .else
169 _is_standalone_target=  0
170 _subdir_filter=
171 .endif
172 __subdir_targets=
173 .for __dir in ${SUBDIR:${_subdir_filter}}
174 .if ${__dir} == .WAIT
175 __subdir_targets+= .WAIT
176 .else
177 __deps=
178 .if ${_is_standalone_target} == 0
179 .if defined(SUBDIR_PARALLEL)
180 # Apply SUBDIR_DEPEND dependencies for SUBDIR_PARALLEL.
181 .for __dep in ${SUBDIR_DEPEND_${__dir}}
182 __deps+= ${__target}_subdir_${DIRPRFX}${__dep}
183 .endfor
184 .else
185 # For non-parallel builds, directories depend on all targets before them.
186 __deps:= ${__subdir_targets}
187 .endif  # defined(SUBDIR_PARALLEL)
188 .endif  # ${_is_standalone_target} == 0
189 ${__target}_subdir_${DIRPRFX}${__dir}: .PHONY .MAKE .SILENT ${__deps}
190         @${_+_}target=${__target:realinstall=install}; \
191             dir=${__dir}; \
192             ${_SUBDIR_SH};
193 __subdir_targets+= ${__target}_subdir_${DIRPRFX}${__dir}
194 .endif  # ${__dir} == .WAIT
195 .endfor # __dir in ${SUBDIR}
196
197 # Attach the subdir targets to the real target.
198 # Only recurse on directly-called targets.  I.e., don't recurse on dependencies
199 # such as 'install' becoming {before,real,after}install, just recurse
200 # 'install'.  Despite that, 'realinstall' is special due to ordering issues
201 # with 'afterinstall'.
202 .if !defined(NO_SUBDIR) && (make(${__target}) || \
203     (${__target} == realinstall && make(install)))
204 ${__target}: ${__subdir_targets} .PHONY
205 .endif  # make(${__target})
206 .endfor # __target in ${SUBDIR_TARGETS}
207
208 .endif  # !target(_SUBDIR)
209
210 # Ensure all targets exist
211 .for __target in ${SUBDIR_TARGETS}
212 .if !target(${__target})
213 ${__target}:
214 .endif
215 .endfor
216
217 .endif