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