1284345Ssjg# $FreeBSD$
2294742Sbdrewery# $Id: meta.subdir.mk,v 1.11 2015/11/24 22:26:51 sjg Exp $
3284345Ssjg
4284345Ssjg#
5284345Ssjg#	@(#) Copyright (c) 2010, Simon J. Gerraty
6284345Ssjg#
7284345Ssjg#	This file is provided in the hope that it will
8284345Ssjg#	be of use.  There is absolutely NO WARRANTY.
9284345Ssjg#	Permission to copy, redistribute or otherwise
10284345Ssjg#	use this file is hereby granted provided that 
11284345Ssjg#	the above copyright notice and this notice are
12284345Ssjg#	left intact. 
13284345Ssjg#      
14284345Ssjg#	Please send copies of changes and bug-fixes to:
15284345Ssjg#	sjg@crufty.net
16284345Ssjg#
17284345Ssjg
18284345Ssjg.if !defined(NO_SUBDIR) && !empty(SUBDIR)
19284345Ssjg.if make(destroy*) || make(clean*)
20284345Ssjg.MAKE.MODE = compat
21284345Ssjg.if !commands(destroy)
22284345Ssjg.-include <bsd.obj.mk>
23284345Ssjg.endif
24284345Ssjg.elif ${.MAKE.LEVEL} == 0
25284345Ssjg
26284345Ssjg.MAIN: all
27284345Ssjg
28284345Ssjg.if !exists(${.CURDIR}/${.MAKE.DEPENDFILE:T}) || make(gendirdeps)
29284345Ssjg# start with this
30284345SsjgDIRDEPS = ${SUBDIR:N.WAIT:O:u:@d@${RELDIR}/$d@}
31284345Ssjg
32284345Ssjg.if make(gendirdeps)
33284345Ssjg.include <meta.autodep.mk>
34284345Ssjg.else
35284345Ssjg# this is the cunning bit
36284345Ssjg# actually it is probably a bit risky 
37284345Ssjg# since we may pickup subdirs which are not relevant
38284345Ssjg# the alternative is a walk through the tree though
39284345Ssjg# which is difficult without a sub-make.
40284345Ssjg
41284345Ssjg.if defined(BOOTSTRAP_DEPENDFILES)
42284345Ssjg_find_name = ${.MAKE.MAKEFILE_PREFERENCE:@m@-o -name $m@:S,^-o,,1}
43284345SsjgDIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@}
44284345Ssjg.elif ${.MAKE.DEPENDFILE:E} == ${MACHINE} && defined(ALL_MACHINES)
45284345Ssjg# we want to find Makefile.depend.* ie for all machines
46284345Ssjg# and turn the dirs into dir.<machine>
47284345Ssjg_find_name = -name '${.MAKE.DEPENDFILE:T:R}*'
48284345SsjgDIRDEPS = ${_subdeps:O:u:${NIgnoreFiles}:@d@${RELDIR}/${d:H}.${d:E}@:S,.${MACHINE}$,,:S,.depend$,,}
49284345Ssjg.else
50284345Ssjg# much simpler
51284345Ssjg_find_name = -name ${.MAKE.DEPENDFILE:T}
52284345Ssjg.if ${.MAKE.DEPENDFILE:E} == ${MACHINE}
53284345Ssjg_find_name += -o -name ${.MAKE.DEPENDFILE:T:R}
54284345Ssjg.endif
55284345SsjgDIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@}
56284345Ssjg.endif
57284345Ssjg
58284345Ssjg_subdeps != cd ${.CURDIR} && \
59284345Ssjg	find ${SUBDIR:N.WAIT} -type f \( ${_find_name} \) -print -o \
60284345Ssjg	-name .svn -prune 2> /dev/null; echo
61284345Ssjg
62284345Ssjg.if empty(_subdeps)
63284345SsjgDIRDEPS =
64284345Ssjg.else
65284345Ssjg# clean up if needed
66294742SbdreweryDIRDEPS := ${DIRDEPS:S,^./,,:S,/./,/,g:${SUBDIRDEPS_FILTER:Uu}}
67284345Ssjg.endif
68284345Ssjg# we just dealt with it, if we leave it defined,
69284345Ssjg# dirdeps.mk will compute some interesting combinations.
70284345Ssjg.undef ALL_MACHINES
71284345Ssjg
72284345SsjgDEP_RELDIR = ${RELDIR}
73284345Ssjg.include <dirdeps.mk>
74284345Ssjg.endif
75284345Ssjg.endif
76284345Ssjg.else
77284345Ssjgall: .PHONY
78284345Ssjg.endif
79284345Ssjg
80284345Ssjg.endif
81