xref: /freebsd/contrib/bmake/mk/subdir.mk (revision 55141f2c8991b2a6adbf30bb0fe3e6cbc303f06d)
1#	$Id: subdir.mk,v 1.16 2017/02/08 22:16:59 sjg Exp $
2#	skip missing directories...
3
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
6
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
16
17ECHO_DIR ?= echo
18.ifdef SUBDIR_MUST_EXIST
19MISSING_DIR=echo "Missing ===> ${.CURDIR}/$${entry}"; exit 1
20.else
21MISSING_DIR=echo "Skipping ===> ${.CURDIR}/$${entry}"; continue
22.endif
23
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
47${SUBDIR}::
48	@set -e; _r=${.CURDIR}/; \
49	if test -z "${.TARGET:M/*}"; then \
50		if test -d ${.CURDIR}/${.TARGET}.${MACHINE}; then \
51			_newdir_=${.TARGET}.${MACHINE}; \
52		else \
53			_newdir_=${.TARGET}; \
54		fi; \
55	else \
56		_r= _newdir_=${.TARGET}; \
57	fi; \
58	${ECHO_DIR} "===> $${_newdir_}"; \
59	cd $${_r}$${_newdir_}; \
60	${.MAKE} _THISDIR_="$${_newdir_}" all
61.endif
62
63.if !target(install)
64.if !target(beforeinstall)
65beforeinstall:
66.endif
67.if !target(afterinstall)
68afterinstall:
69.endif
70install: maninstall
71maninstall: afterinstall
72afterinstall: realinstall
73realinstall: beforeinstall _SUBDIRUSE
74.endif
75
76.if defined(SRCS)
77etags: ${SRCS}
78	-cd ${.CURDIR}; etags `echo ${.ALLSRC:N*.h} | sed 's;${.CURDIR}/;;'`
79.endif
80
81SUBDIR_TARGETS += \
82	all \
83	clean \
84	cleandir \
85	includes \
86	depend \
87	lint \
88	obj \
89	tags \
90	etags
91
92.for t in ${SUBDIR_TARGETS:O:u}
93$t: _SUBDIRUSE
94.endfor
95
96.include <own.mk>
97.if make(destroy*)
98.include <obj.mk>
99.endif
100.endif
101# make sure this exists
102all:
103