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