xref: /freebsd/contrib/bmake/mk/subdir.mk (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1#	$Id: subdir.mk,v 1.14 2012/11/12 04:34:33 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.if exists(${.CURDIR}/Makefile.inc)
13.include "Makefile.inc"
14.endif
15.if !target(.MAIN)
16.MAIN: all
17.endif
18
19ECHO_DIR ?= echo
20.ifdef SUBDIR_MUST_EXIST
21MISSING_DIR=echo "Missing ===> ${.CURDIR}/$${entry}"; exit 1
22.else
23MISSING_DIR=echo "Skipping ===> ${.CURDIR}/$${entry}"; continue
24.endif
25
26_SUBDIRUSE: .USE
27.if defined(SUBDIR)
28	@Exists() { test -f $$1; }; \
29	for entry in ${SUBDIR}; do \
30		(set -e; \
31		if Exists ${.CURDIR}/$${entry}.${MACHINE}/[mM]akefile; then \
32			_newdir_="$${entry}.${MACHINE}"; \
33		elif  Exists ${.CURDIR}/$${entry}/[mM]akefile; then \
34			_newdir_="$${entry}"; \
35		else \
36			${MISSING_DIR}; \
37		fi; \
38		if test X"${_THISDIR_}" = X""; then \
39			_nextdir_="$${_newdir_}"; \
40		else \
41			_nextdir_="$${_THISDIR_}/$${_newdir_}"; \
42		fi; \
43		${ECHO_DIR} "===> $${_nextdir_}"; \
44		cd ${.CURDIR}/$${_newdir_}; \
45		${.MAKE} _THISDIR_="$${_nextdir_}" \
46		    ${.TARGET:S/realinstall/install/:S/.depend/depend/}) || exit 1; \
47	done
48
49${SUBDIR}::
50	@set -e; if test -d ${.CURDIR}/${.TARGET}.${MACHINE}; then \
51		_newdir_=${.TARGET}.${MACHINE}; \
52	else \
53		_newdir_=${.TARGET}; \
54	fi; \
55	${ECHO_DIR} "===> $${_newdir_}"; \
56	cd ${.CURDIR}/$${_newdir_}; \
57	${.MAKE} _THISDIR_="$${_newdir_}" all
58.endif
59
60.if !target(install)
61.if !target(beforeinstall)
62beforeinstall:
63.endif
64.if !target(afterinstall)
65afterinstall:
66.endif
67install: maninstall
68maninstall: afterinstall
69afterinstall: realinstall
70realinstall: beforeinstall _SUBDIRUSE
71.endif
72
73.if defined(SRCS)
74etags: ${SRCS}
75	-cd ${.CURDIR}; etags `echo ${.ALLSRC:N*.h} | sed 's;${.CURDIR}/;;'`
76.endif
77
78SUBDIR_TARGETS += \
79	all \
80	clean \
81	cleandir \
82	includes \
83	depend \
84	lint \
85	obj \
86	tags \
87	etags
88
89.for t in ${SUBDIR_TARGETS:O:u}
90$t: _SUBDIRUSE
91.endfor
92
93.include <own.mk>
94.if make(destroy*)
95.include <obj.mk>
96.endif
97.endif
98# make sure this exists
99all:
100