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.
32 .if !target(__<bsd.subdir.mk>__)
35 ALL_SUBDIR_TARGETS= all all-man buildconfig checkdpadd clean cleandepend \
36 cleandir cleanilinks cleanobj depend distribute \
37 installconfig lint maninstall manlint obj objlink \
38 realinstall regress tags \
41 .include <bsd.init.mk>
43 .if !defined(NEED_SUBDIR)
44 .if ${.MAKE.LEVEL} == 0 && ${MK_META_MODE} == "yes" && !empty(SUBDIR) && !(make(clean*) || make(destroy*))
45 .include <meta.subdir.mk>
53 SUBDIR:=${SUBDIR} ${SUBDIR.yes}
58 .if !target(distribute)
60 .for dist in ${DISTRIBUTION}
61 ${_+_}cd ${.CURDIR}; \
62 ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
67 .if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
68 @${_+_}for entry in ${SUBDIR:N.WAIT}; do \
69 if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \
70 ${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH} (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
71 edir=$${entry}.${MACHINE_ARCH}; \
72 cd ${.CURDIR}/$${edir}; \
74 ${ECHODIR} "===> ${DIRPRFX}$$entry (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
76 cd ${.CURDIR}/$${edir}; \
78 ${MAKE} ${.TARGET:S,realinstall,install,:S,^_sub.,,} \
79 DIRPRFX=${DIRPRFX}$$edir/; \
83 ${SUBDIR:N.WAIT}: .PHONY .MAKE
84 ${_+_}@if test -d ${.TARGET}.${MACHINE_ARCH}; then \
85 cd ${.CURDIR}/${.TARGET}.${MACHINE_ARCH}; \
87 cd ${.CURDIR}/${.TARGET}; \
91 # Work around parsing of .if nested in .for by putting .WAIT string into a var.
93 .for __target in ${ALL_SUBDIR_TARGETS}
94 .ifdef SUBDIR_PARALLEL
96 .for __dir in ${SUBDIR}
97 .if ${__wait} == ${__dir}
98 __subdir_targets+= .WAIT
100 __subdir_targets+= ${__target}_subdir_${__dir}
102 .for __dep in ${SUBDIR_DEPEND_${__dir}}
103 __deps+= ${__target}_subdir_${__dep}
105 ${__target}_subdir_${__dir}: .PHONY .MAKE ${__deps}
106 .if !defined(NO_SUBDIR)
107 @${_+_}if test -d ${.CURDIR}/${__dir}.${MACHINE_ARCH}; then \
108 ${ECHODIR} "===> ${DIRPRFX}${__dir}.${MACHINE_ARCH} (${__target:realinstall=install})"; \
109 edir=${__dir}.${MACHINE_ARCH}; \
110 cd ${.CURDIR}/$${edir}; \
112 ${ECHODIR} "===> ${DIRPRFX}${__dir} (${__target:realinstall=install})"; \
114 cd ${.CURDIR}/$${edir}; \
116 ${MAKE} ${__target:realinstall=install} \
117 DIRPRFX=${DIRPRFX}$$edir/
121 ${__target}: ${__subdir_targets}
123 ${__target}: _sub.${__target}
124 _sub.${__target}: _SUBDIR
128 # This is to support 'make includes' calling 'make buildincludes' and
129 # 'make installincludes' in the proper order, and to support these
130 # targets as SUBDIR_TARGETS.
131 .for __target in files includes
132 .for __stage in build install
133 ${__stage}${__target}:
134 .if make(${__stage}${__target})
135 ${__stage}${__target}: _sub.${__stage}${__target}
136 _sub.${__stage}${__target}: _SUBDIR
139 .if !target(${__target})
141 ${_+_}cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target}
148 .if !target(beforeinstall)
151 .if !target(afterinstall)
154 install: beforeinstall realinstall afterinstall
155 .ORDER: beforeinstall realinstall afterinstall