Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / share / mk / subdir.mk
blob33831650f18f78736c202224d63a7f127b21c963
1 # $Id: subdir.mk,v 1.16 2017/02/08 22:16:59 sjg Exp $
2 # skip missing directories...
4 # $NetBSD: bsd.subdir.mk,v 1.11 1996/04/04 02:05:06 jtc Exp $
5 # @(#)bsd.subdir.mk 5.9 (Berkeley) 2/1/91
7 .if ${.MAKE.LEVEL} == 0 && ${.MAKE.MODE:Uno:Mmeta*} != ""
8 .include <meta.subdir.mk>
9 # keep everyone happy
10 _SUBDIRUSE:
11 .elif !commands(_SUBDIRUSE) && !defined(NO_SUBDIR) && !defined(NOSUBDIR)
12 .-include <${.CURDIR}/Makefile.inc>
13 .if !target(.MAIN)
14 .MAIN: all
15 .endif
17 ECHO_DIR ?= echo
18 .ifdef SUBDIR_MUST_EXIST
19 MISSING_DIR=echo "Missing ===> ${.CURDIR}/$${entry}"; exit 1
20 .else
21 MISSING_DIR=echo "Skipping ===> ${.CURDIR}/$${entry}"; continue
22 .endif
24 _SUBDIRUSE: .USE
25 .if defined(SUBDIR)
26 @Exists() { test -f $$1; }; \
27 for entry in ${SUBDIR}; do \
28 (set -e; \
29 if Exists ${.CURDIR}/$${entry}.${MACHINE}/[mM]akefile; then \
30 _newdir_="$${entry}.${MACHINE}"; \
31 elif Exists ${.CURDIR}/$${entry}/[mM]akefile; then \
32 _newdir_="$${entry}"; \
33 else \
34 ${MISSING_DIR}; \
35 fi; \
36 if test X"${_THISDIR_}" = X""; then \
37 _nextdir_="$${_newdir_}"; \
38 else \
39 _nextdir_="$${_THISDIR_}/$${_newdir_}"; \
40 fi; \
41 ${ECHO_DIR} "===> $${_nextdir_}"; \
42 cd ${.CURDIR}/$${_newdir_}; \
43 ${.MAKE} _THISDIR_="$${_nextdir_}" \
44 ${.TARGET:S/realinstall/install/:S/.depend/depend/}) || exit 1; \
45 done
46 .endif
48 .if !target(install)
49 .if !target(beforeinstall)
50 beforeinstall:
51 .endif
52 .if !target(afterinstall)
53 afterinstall:
54 .endif
55 install: maninstall
56 maninstall: afterinstall
57 afterinstall: realinstall
58 realinstall: beforeinstall _SUBDIRUSE
59 .endif
61 .if defined(SRCS)
62 etags: ${SRCS}
63 -cd ${.CURDIR}; etags `echo ${.ALLSRC:N*.h} | sed 's;${.CURDIR}/;;'`
64 .endif
66 SUBDIR_TARGETS += \
67 all \
68 clean \
69 cleandir \
70 includes \
71 depend \
72 lint \
73 obj \
74 tags \
75 etags
77 # this parallelizes, unlike _SUBDIRUSE, but is only in effect if the
78 # SUBDIR_TARGETS target (eg. "all") has not been defined before (eg. in
79 # prog.mk)
80 .for t in ${SUBDIR_TARGETS:O:u}
81 .if !target($t) && make($t)
82 $t: ${SUBDIR}
83 .for sd in ${SUBDIR}
84 ${sd}::
85 @set -e; _r=${.CURDIR}/; \
86 if test -z "${sd:M/*}"; then \
87 if test -d ${.CURDIR}/${sd}.${MACHINE}; then \
88 _newdir_=${sd}.${MACHINE}; \
89 else \
90 _newdir_=${sd}; \
91 fi; \
92 else \
93 _r= _newdir_=${sd}; \
94 fi; \
95 ${ECHO_DIR} "===> $${_newdir_}"; \
96 cd $${_r}$${_newdir_}; \
97 ${.MAKE} _THISDIR_="$${_newdir_}" ${t:S/realinstall/install/:S/.depend/depend/}
98 .endfor
99 .endif
100 .endfor
102 .include <own.mk>
103 .endif
104 # make sure this exists
105 all: