1#	$OpenBSD: bsd.subdir.mk,v 1.22 2016/10/08 09:43:46 schwarze Exp $
2#	$NetBSD: bsd.subdir.mk,v 1.11 1996/04/04 02:05:06 jtc Exp $
3#	@(#)bsd.subdir.mk	5.9 (Berkeley) 2/1/91
4
5.if !target(.MAIN)
6.MAIN: all
7.endif
8
9# Make sure this is defined
10SKIPDIR?=
11
12_SUBDIRUSE: .USE
13.if defined(SUBDIR)
14	@for entry in ${SUBDIR}; do \
15		set -e; if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
16			_newdir_="$${entry}.${MACHINE}"; \
17		else \
18			_newdir_="$${entry}"; \
19		fi; \
20		if test X"${_THISDIR_}" = X""; then \
21			_nextdir_="$${_newdir_}"; \
22		else \
23			_nextdir_="$${_THISDIR_}/$${_newdir_}"; \
24		fi; \
25		_makefile_spec_=""; \
26		if [ -e ${.CURDIR}/$${_newdir_}/Makefile.bsd-wrapper ]; then \
27			_makefile_spec_="-f Makefile.bsd-wrapper"; \
28		fi; \
29		subskipdir=''; \
30		for skipdir in ${SKIPDIR}; do \
31			subentry=$${skipdir#$${entry}}; \
32			if [ X$${subentry} != X$${skipdir} ]; then \
33				if [ X$${subentry} = X ]; then \
34					echo "($${_nextdir_} skipped)"; \
35					break; \
36				fi; \
37				subskipdir="$${subskipdir} $${subentry#/}"; \
38			fi; \
39		done; \
40		if [ X$${skipdir} = X -o X$${subentry} != X ]; then \
41			echo "===> $${_nextdir_}"; \
42			${MAKE} -C ${.CURDIR}/$${_newdir_} \
43			    SKIPDIR="$${subskipdir}" \
44			    $${_makefile_spec_} _THISDIR_="$${_nextdir_}" \
45			    ${MAKE_FLAGS} \
46			    ${.TARGET:S/^real//}; \
47		fi; \
48	done
49
50${SUBDIR}::
51	@set -e; if test -d ${.CURDIR}/${.TARGET}.${MACHINE}; then \
52		_newdir_=${.TARGET}.${MACHINE}; \
53	else \
54		_newdir_=${.TARGET}; \
55	fi; \
56	_makefile_spec_=""; \
57	if [ -f ${.CURDIR}/$${_newdir_}/Makefile.bsd-wrapper ]; then \
58		_makefile_spec_="-f Makefile.bsd-wrapper"; \
59	fi; \
60	echo "===> $${_newdir_}"; \
61	exec ${MAKE} -C ${.CURDIR}/$${_newdir_} ${MAKE_FLAGS} \
62	    $${_makefile_spec_} _THISDIR_="$${_newdir_}" all
63.endif
64
65.if !target(install)
66.  if !target(beforeinstall)
67beforeinstall:
68.  endif
69.  if !target(afterinstall)
70afterinstall:
71.  endif
72install: maninstall
73maninstall: afterinstall
74afterinstall: realinstall
75realinstall: beforeinstall _SUBDIRUSE
76.endif
77
78
79.for t in all cleandir includes depend obj tags manlint
80.  if !target($t)
81$t: _SUBDIRUSE
82.  endif
83.endfor
84.if !target(regress) && empty(.TARGETS:Mall)
85regress: _SUBDIRUSE
86.endif
87.if !target(clean) && empty(.TARGETS:Mcleandir)
88clean: _SUBDIRUSE
89.endif
90
91.if !defined(BSD_OWN_MK)
92.  include <bsd.own.mk>
93.endif
94