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 # afterinstall, all, all-man, beforeinstall, checkdpadd, clean,
29 # cleandepend, cleandir, cleanilinks depend, install, lint,
30 # maninstall, manlint, obj, objlink, realinstall, test, tags
33 .if !target(__<bsd.subdir.mk>__)
36 .include <bsd.init.mk>
38 .if !defined(NEED_SUBDIR)
39 .if ${.MAKE.LEVEL} == 0 && ${MK_META_MODE} == "yes" && !empty(SUBDIR) && !(make(clean*) || make(destroy*))
40 .include <meta.subdir.mk>
48 SUBDIR:=${SUBDIR} ${SUBDIR.yes}
53 .if !target(distribute)
55 .for dist in ${DISTRIBUTION}
56 ${_+_}cd ${.CURDIR}; \
57 ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
62 .if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
63 @${_+_}for entry in ${SUBDIR:N.WAIT}; do \
64 if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \
65 ${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH} (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
66 edir=$${entry}.${MACHINE_ARCH}; \
67 cd ${.CURDIR}/$${edir}; \
69 ${ECHODIR} "===> ${DIRPRFX}$$entry (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
71 cd ${.CURDIR}/$${edir}; \
73 ${MAKE} ${.TARGET:S,realinstall,install,:S,^_sub.,,} \
74 DIRPRFX=${DIRPRFX}$$edir/; \
78 ${SUBDIR:N.WAIT}: .PHONY .MAKE
79 ${_+_}@if test -d ${.TARGET}.${MACHINE_ARCH}; then \
80 cd ${.CURDIR}/${.TARGET}.${MACHINE_ARCH}; \
82 cd ${.CURDIR}/${.TARGET}; \
86 # Work around parsing of .if nested in .for by putting .WAIT string into a var.
88 .for __target in all all-man checkdpadd clean cleandepend cleandir \
89 cleanilinks depend distribute lint maninstall manlint obj objlink \
90 realinstall regress tags test ${SUBDIR_TARGETS}
91 .ifdef SUBDIR_PARALLEL
93 .for __dir in ${SUBDIR}
94 .if ${__wait} == ${__dir}
95 __subdir_targets+= .WAIT
97 __subdir_targets+= ${__target}_subdir_${__dir}
99 .for __dep in ${SUBDIR_DEPEND_${__dir}}
100 __deps+= ${__target}_subdir_${__dep}
102 ${__target}_subdir_${__dir}: .MAKE ${__deps}
103 .if !defined(NO_SUBDIR)
104 @${_+_}if test -d ${.CURDIR}/${__dir}.${MACHINE_ARCH}; then \
105 ${ECHODIR} "===> ${DIRPRFX}${__dir}.${MACHINE_ARCH} (${__target:realinstall=install})"; \
106 edir=${__dir}.${MACHINE_ARCH}; \
107 cd ${.CURDIR}/$${edir}; \
109 ${ECHODIR} "===> ${DIRPRFX}${__dir} (${__target:realinstall=install})"; \
111 cd ${.CURDIR}/$${edir}; \
113 ${MAKE} ${__target:realinstall=install} \
114 DIRPRFX=${DIRPRFX}$$edir/
118 ${__target}: ${__subdir_targets}
120 ${__target}: _sub.${__target}
121 _sub.${__target}: _SUBDIR
125 .for __target in files includes
126 .for __stage in build install
127 ${__stage}${__target}:
128 .if make(${__stage}${__target})
129 ${__stage}${__target}: _sub.${__stage}${__target}
130 _sub.${__stage}${__target}: _SUBDIR
133 .if !target(${__target})
135 ${_+_}cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target}
142 .if !target(beforeinstall)
145 .if !target(afterinstall)
148 install: beforeinstall realinstall afterinstall
149 .ORDER: beforeinstall realinstall afterinstall