aboutsummaryrefslogtreecommitdiff
path: root/mk/bsd.subdir.mk
blob: f69faeaef9d623d8c11d6da9c922f17c20713067 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
MAKEOBJDIR?=	obj

.TOPDIR?=	..
.OBJDIR?=	${MAKEOBJDIR}
.SRCDIR?=	.
.CURDIR?=	.
.RELDIR:=	$(.SRCDIR:.%=$(.TOPDIR)/../%)

SUBDIR_MFLAGS=	--no-print-directory \
		-I$(.NEXTTOP)/mk \
		-C ${.OBJDIR}/$$nextdir \
		-f ${.RELDIR}/$$nextdir/Makefile \
		.OBJDIR=. \
		.TOPDIR=${.TOPDIR}/.. \
		.CURDIR=${.RELDIR}/$$nextdir \
		.SRCDIR=${.SRCDIR}/$$nextdir \
		MAKEOBJDIR=${.TOPDIR}/${MAKEOBJDIR} \
		_THISDIR_=$$nextdir
		


SUBDIR_TARGETS = all install clean cleandir includes depend regress obj tags manlint

$(SUBDIR_TARGETS): _SUBDIRUSE

define __SUBDIRUSE
for nextdir in $(SUBDIR); do                                                   \
	b=; for s in $(SKIPDIR); do                                            \
		[ "$$s" = "$$nextdir" ] && b=1 && break;                       \
	done;                                                                  \
	[ -n "$$b" ] && echo "($$nextdir skipped)" && continue;                \
	echo "===> $${_THISDIR_:+$${_THISDIR_}/}$$nextdir";                    \
	mkdir -p "${.OBJDIR}/$$nextdir"                                        \
	&& $(MAKE) $(SUBDIR_MFLAGS) $(MAKECMDGOALS) || exit 1;                 \
done
endef

_SUBDIRUSE:
ifneq ($(SUBDIR),)
	+@$(__SUBDIRUSE)

$(SUBDIR):
	+@nextdir="$@"; \
	echo "===> $$nextdir"; \
	mkdir -p "${.OBJDIR}/$$nextdir" \
	&& $(MAKE) $(SUBDIR_MFLAGS) all || exit 1
endif

.PHONY: _SUBDIRUSE $(SUBDIR_TARGETS) $(SUBDIR)