1291978Ssjg# $Id: meta.subdir.mk,v 1.11 2015/11/24 22:26:51 sjg Exp $
2246149Ssjg
3246149Ssjg#
4246149Ssjg#	@(#) Copyright (c) 2010, Simon J. Gerraty
5246149Ssjg#
6246149Ssjg#	This file is provided in the hope that it will
7246149Ssjg#	be of use.  There is absolutely NO WARRANTY.
8246149Ssjg#	Permission to copy, redistribute or otherwise
9246149Ssjg#	use this file is hereby granted provided that 
10246149Ssjg#	the above copyright notice and this notice are
11246149Ssjg#	left intact. 
12246149Ssjg#      
13246149Ssjg#	Please send copies of changes and bug-fixes to:
14246149Ssjg#	sjg@crufty.net
15246149Ssjg#
16246149Ssjg
17246149Ssjg.if !defined(NO_SUBDIR) && !empty(SUBDIR)
18246149Ssjg.if make(destroy*) || make(clean*)
19246149Ssjg.MAKE.MODE = compat
20246149Ssjg.if !commands(destroy)
21246149Ssjg.-include <bsd.obj.mk>
22246149Ssjg.endif
23246149Ssjg.elif ${.MAKE.LEVEL} == 0
24246149Ssjg
25246149Ssjg.MAIN: all
26246149Ssjg
27246149Ssjg.if !exists(${.CURDIR}/${.MAKE.DEPENDFILE:T}) || make(gendirdeps)
28246149Ssjg# start with this
29246149SsjgDIRDEPS = ${SUBDIR:N.WAIT:O:u:@d@${RELDIR}/$d@}
30246149Ssjg
31246149Ssjg.if make(gendirdeps)
32246149Ssjg.include <meta.autodep.mk>
33246149Ssjg.else
34246149Ssjg# this is the cunning bit
35246149Ssjg# actually it is probably a bit risky 
36246149Ssjg# since we may pickup subdirs which are not relevant
37246149Ssjg# the alternative is a walk through the tree though
38246149Ssjg# which is difficult without a sub-make.
39246149Ssjg
40246149Ssjg.if defined(BOOTSTRAP_DEPENDFILES)
41246149Ssjg_find_name = ${.MAKE.MAKEFILE_PREFERENCE:@m@-o -name $m@:S,^-o,,1}
42246149SsjgDIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@}
43246149Ssjg.elif ${.MAKE.DEPENDFILE:E} == ${MACHINE} && defined(ALL_MACHINES)
44246149Ssjg# we want to find Makefile.depend.* ie for all machines
45246149Ssjg# and turn the dirs into dir.<machine>
46246149Ssjg_find_name = -name '${.MAKE.DEPENDFILE:T:R}*'
47246149SsjgDIRDEPS = ${_subdeps:O:u:${NIgnoreFiles}:@d@${RELDIR}/${d:H}.${d:E}@:S,.${MACHINE}$,,:S,.depend$,,}
48246149Ssjg.else
49246149Ssjg# much simpler
50246149Ssjg_find_name = -name ${.MAKE.DEPENDFILE:T}
51246149Ssjg.if ${.MAKE.DEPENDFILE:E} == ${MACHINE}
52246149Ssjg_find_name += -o -name ${.MAKE.DEPENDFILE:T:R}
53246149Ssjg.endif
54246149SsjgDIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@}
55246149Ssjg.endif
56246149Ssjg
57246149Ssjg_subdeps != cd ${.CURDIR} && \
58246149Ssjg	find ${SUBDIR:N.WAIT} -type f \( ${_find_name} \) -print -o \
59246149Ssjg	-name .svn -prune 2> /dev/null; echo
60246149Ssjg
61246149Ssjg.if empty(_subdeps)
62246149SsjgDIRDEPS =
63246149Ssjg.else
64246149Ssjg# clean up if needed
65291978SsjgDIRDEPS := ${DIRDEPS:S,^./,,:S,/./,/,g:${SUBDIRDEPS_FILTER:Uu}}
66246149Ssjg.endif
67246149Ssjg# we just dealt with it, if we leave it defined,
68246149Ssjg# dirdeps.mk will compute some interesting combinations.
69246149Ssjg.undef ALL_MACHINES
70246149Ssjg
71246149SsjgDEP_RELDIR = ${RELDIR}
72246149Ssjg.include <dirdeps.mk>
73246149Ssjg.endif
74246149Ssjg.endif
75246149Ssjg.else
76246149Ssjgall: .PHONY
77246149Ssjg.endif
78246149Ssjg
79246149Ssjg.endif
80