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