1 # from: @(#)bsd.subdir.mk 5.9 (Berkeley) 2/1/91
4 # The include file <bsd.subdir.mk> contains the default targets
5 # for building subdirectories.
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.
15 # DISTRIBUTION Name of distribution. [base]
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
25 # This is a variant of install, which will
26 # put the stuff into the right "distribution".
28 # See ALL_SUBDIR_TARGETS for list of targets that will recurse.
29 # Custom targets can be added to SUBDIR_TARGETS in src.conf.
31 # Targets defined in STANDALONE_SUBDIR_TARGETS will always be ran
32 # with SUBDIR_PARALLEL and will not respect .WAIT or SUBDIR_DEPEND_
36 .if !target(__<bsd.subdir.mk>__)
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 \
46 STANDALONE_SUBDIR_TARGETS?= obj checkdpadd clean cleandepend cleandir \
49 .include <bsd.init.mk>
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>
61 SUBDIR:=${SUBDIR} ${SUBDIR.yes}
66 .if !target(distribute)
68 .for dist in ${DISTRIBUTION}
69 ${_+_}cd ${.CURDIR}; \
70 ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
74 # Subdir code shared among 'make <subdir>', 'make <target>' and SUBDIR_PARALLEL.
76 if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \
77 dir=$${dir}.${MACHINE_ARCH}; \
79 ${ECHODIR} "===> ${DIRPRFX}$${dir} ($${target})"; \
80 cd ${.CURDIR}/$${dir}; \
81 ${MAKE} $${target} DIRPRFX=${DIRPRFX}$${dir}/
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
89 ${SUBDIR:N.WAIT}: .PHONY .MAKE
94 # Work around parsing of .if nested in .for by putting .WAIT string into a var.
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}
102 _is_standalone_target= 0
104 .if defined(SUBDIR_PARALLEL) || ${_is_standalone_target} == 1
106 .for __dir in ${SUBDIR}
107 .if ${__wait} == ${__dir}
108 __subdir_targets+= .WAIT
110 __subdir_targets+= ${__target}_subdir_${__dir}
112 .if ${_is_standalone_target} == 0
113 .for __dep in ${SUBDIR_DEPEND_${__dir}}
114 __deps+= ${__target}_subdir_${__dep}
117 ${__target}_subdir_${__dir}: .PHONY .MAKE ${__deps}
118 .if !defined(NO_SUBDIR)
119 @${_+_}target=${__target:realinstall=install}; \
124 .endfor # __dir in ${SUBDIR}
125 ${__target}: ${__subdir_targets}
128 .endif # SUBDIR_PARALLEL || _is_standalone_target
129 .endfor # __target in ${ALL_SUBDIR_TARGETS}
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
141 .if !target(${__target})
143 ${_+_}cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target}
150 .if !target(beforeinstall)
153 .if !target(afterinstall)
156 install: beforeinstall realinstall afterinstall
157 .ORDER: beforeinstall realinstall afterinstall