bsd.subdir.mk revision 1.43 1 # $NetBSD: bsd.subdir.mk,v 1.43 2001/09/21 20:50:23 tv Exp $
2 # @(#)bsd.subdir.mk 8.1 (Berkeley) 6/8/93
3
4 .if !target(__initialized__)
5 __initialized__:
6 .if exists(${.CURDIR}/../Makefile.inc)
7 .include "${.CURDIR}/../Makefile.inc"
8 .endif
9 .include <bsd.own.mk>
10 .MAIN: all
11 .endif
12
13 .for dir in ${SUBDIR}
14 .if exists(${dir}.${MACHINE})
15 __REALSUBDIR+=${dir}.${MACHINE}
16 .else
17 __REALSUBDIR+=${dir}
18 .endif
19 .endfor
20
21 .if defined(DESTDIR) && exists(${DESTDIR}/usr/share/mk/sys.mk)
22 _M=-m ${DESTDIR}/usr/share/mk
23 .else
24 _M=
25 .endif
26
27 __recurse: .USE
28 @targ=${.TARGET:C/-.*$//};dir=${.TARGET:C/^[^-]*-//}; \
29 case "$$dir" in /*) \
30 echo "$$targ ===> $$dir"; \
31 cd "$$dir"; \
32 ${MAKE} ${_M} "_THISDIR_=$$dir/" $$targ; \
33 ;; \
34 *) \
35 echo "$$targ ===> ${_THISDIR_}$$dir"; \
36 cd "${.CURDIR}/$$dir"; \
37 ${MAKE} ${_M} "_THISDIR_=${_THISDIR_}$$dir/" $$targ; \
38 ;; \
39 esac
40
41 .if make(cleandir)
42 __RECURSETARG= ${TARGETS:Nclean}
43 .else
44 __RECURSETARG= ${TARGETS}
45 .endif
46
47 # for obscure reasons, we can't do a simple .if ${dir} == ".WAIT"
48 # but have to assign to __TARGDIR first.
49 .for targ in ${__RECURSETARG}
50 .for dir in ${__REALSUBDIR}
51 __TARGDIR := ${dir}
52 .if ${__TARGDIR} == ".WAIT"
53 SUBDIR_${targ} += .WAIT
54 .elif !commands(${targ}-${dir})
55 .PHONY: ${targ}-${dir}
56 ${targ}-${dir}: .MAKE __recurse
57 SUBDIR_${targ} += ${targ}-${dir}
58 .endif
59 .endfor
60 .if defined(__REALSUBDIR)
61 .PHONY: subdir-${targ}
62 subdir-${targ}: ${SUBDIR_${targ}}
63 ${targ}: subdir-${targ}
64 .endif
65 .endfor
66
67 # Make sure all of the standard targets are defined, even if they do nothing.
68 ${TARGETS}:
69