xref: /freebsd/share/mk/meta.subdir.mk (revision a2b67d4a6e364586ae7180cc4696609e8960f955)
1# SPDX-License-Identifier: BSD-2-Clause
2#
3# $Id: meta.subdir.mk,v 1.15 2024/04/19 15:10:22 sjg Exp $
4
5#
6#	@(#) Copyright (c) 2010, Simon J. Gerraty
7#
8#	This file is provided in the hope that it will
9#	be of use.  There is absolutely NO WARRANTY.
10#	Permission to copy, redistribute or otherwise
11#	use this file is hereby granted provided that
12#	the above copyright notice and this notice are
13#	left intact.
14#
15#	Please send copies of changes and bug-fixes to:
16#	sjg@crufty.net
17#
18
19.if !defined(NO_SUBDIR) && !empty(SUBDIR)
20.if make(destroy*) || make(clean*)
21.MAKE.MODE = compat
22.if !commands(obj)
23.-include <bsd.obj.mk>
24.endif
25.elif ${.MAKE.LEVEL} == 0
26
27.MAIN: all
28
29.if !exists(${.CURDIR}/${.MAKE.DEPENDFILE:T}) || make(gendirdeps)
30# start with this
31DIRDEPS = ${SUBDIR:N.WAIT:O:u:@d@${RELDIR}/$d@}
32
33.if make(gendirdeps)
34.include <meta.autodep.mk>
35.else
36# this is the cunning bit
37# actually it is probably a bit risky
38# since we may pickup subdirs which are not relevant
39# the alternative is a walk through the tree though
40# which is difficult without a sub-make.
41
42.if defined(BOOTSTRAP_DEPENDFILES)
43_find_name = ${.MAKE.MAKEFILE_PREFERENCE:@m@-o -name $m@:S,^-o,,1}
44DIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@}
45.elif ${.MAKE.DEPENDFILE:E} == ${MACHINE} && defined(ALL_MACHINES)
46# we want to find Makefile.depend.* ie for all machines
47# and turn the dirs into dir.<machine>
48_find_name = -name '${.MAKE.DEPENDFILE:T:R}*'
49DIRDEPS = ${_subdeps:O:u:${NIgnoreFiles}:@d@${RELDIR}/${d:H}.${d:E}@:S,.${MACHINE}$,,:S,.depend$,,}
50.else
51# much simpler
52_find_name = -name ${.MAKE.DEPENDFILE:T}
53.if ${.MAKE.DEPENDFILE:E} == ${MACHINE}
54_find_name += -o -name ${.MAKE.DEPENDFILE:T:R}
55.endif
56DIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@}
57.endif
58
59_subdeps != cd ${.CURDIR} && \
60	find ${SUBDIR:N.WAIT} -type f \( ${_find_name} \) -print -o \
61	-name .svn -prune 2> /dev/null; echo
62
63.if empty(_subdeps)
64DIRDEPS =
65.else
66# clean up if needed
67DIRDEPS := ${DIRDEPS:S,^./,,:S,/./,/,g:${SUBDIRDEPS_FILTER:Uu}}
68.endif
69# we just dealt with it, if we leave it defined,
70# dirdeps.mk will compute some interesting combinations.
71.undef ALL_MACHINES
72
73.include <dirdeps.mk>
74.endif
75.endif
76.else
77all: .PHONY
78.endif
79
80.endif
81