xref: /freebsd/contrib/bmake/mk/meta.subdir.mk (revision 548bfc56eb0b2cefa0fb8dc2478240bfef610309)
1c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause
2c59c3bf3SSimon J. Gerraty#
3*548bfc56SSimon J. Gerraty# $Id: meta.subdir.mk,v 1.15 2024/04/19 15:10:22 sjg Exp $
43cbdda60SSimon J. Gerraty
53cbdda60SSimon J. Gerraty#
63cbdda60SSimon J. Gerraty#	@(#) Copyright (c) 2010, Simon J. Gerraty
73cbdda60SSimon J. Gerraty#
83cbdda60SSimon J. Gerraty#	This file is provided in the hope that it will
93cbdda60SSimon J. Gerraty#	be of use.  There is absolutely NO WARRANTY.
103cbdda60SSimon J. Gerraty#	Permission to copy, redistribute or otherwise
113cbdda60SSimon J. Gerraty#	use this file is hereby granted provided that
123cbdda60SSimon J. Gerraty#	the above copyright notice and this notice are
133cbdda60SSimon J. Gerraty#	left intact.
143cbdda60SSimon J. Gerraty#
153cbdda60SSimon J. Gerraty#	Please send copies of changes and bug-fixes to:
163cbdda60SSimon J. Gerraty#	sjg@crufty.net
173cbdda60SSimon J. Gerraty#
183cbdda60SSimon J. Gerraty
193cbdda60SSimon J. Gerraty.if !defined(NO_SUBDIR) && !empty(SUBDIR)
203cbdda60SSimon J. Gerraty.if make(destroy*) || make(clean*)
213cbdda60SSimon J. Gerraty.MAKE.MODE = compat
2206b9b3e0SSimon J. Gerraty.if !commands(obj)
233cbdda60SSimon J. Gerraty.-include <bsd.obj.mk>
243cbdda60SSimon J. Gerraty.endif
253cbdda60SSimon J. Gerraty.elif ${.MAKE.LEVEL} == 0
263cbdda60SSimon J. Gerraty
273cbdda60SSimon J. Gerraty.MAIN: all
283cbdda60SSimon J. Gerraty
293cbdda60SSimon J. Gerraty.if !exists(${.CURDIR}/${.MAKE.DEPENDFILE:T}) || make(gendirdeps)
303cbdda60SSimon J. Gerraty# start with this
313cbdda60SSimon J. GerratyDIRDEPS = ${SUBDIR:N.WAIT:O:u:@d@${RELDIR}/$d@}
323cbdda60SSimon J. Gerraty
333cbdda60SSimon J. Gerraty.if make(gendirdeps)
343cbdda60SSimon J. Gerraty.include <meta.autodep.mk>
353cbdda60SSimon J. Gerraty.else
363cbdda60SSimon J. Gerraty# this is the cunning bit
373cbdda60SSimon J. Gerraty# actually it is probably a bit risky
383cbdda60SSimon J. Gerraty# since we may pickup subdirs which are not relevant
393cbdda60SSimon J. Gerraty# the alternative is a walk through the tree though
403cbdda60SSimon J. Gerraty# which is difficult without a sub-make.
413cbdda60SSimon J. Gerraty
423cbdda60SSimon J. Gerraty.if defined(BOOTSTRAP_DEPENDFILES)
433cbdda60SSimon J. Gerraty_find_name = ${.MAKE.MAKEFILE_PREFERENCE:@m@-o -name $m@:S,^-o,,1}
443cbdda60SSimon J. GerratyDIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@}
453cbdda60SSimon J. Gerraty.elif ${.MAKE.DEPENDFILE:E} == ${MACHINE} && defined(ALL_MACHINES)
463cbdda60SSimon J. Gerraty# we want to find Makefile.depend.* ie for all machines
473cbdda60SSimon J. Gerraty# and turn the dirs into dir.<machine>
483cbdda60SSimon J. Gerraty_find_name = -name '${.MAKE.DEPENDFILE:T:R}*'
493cbdda60SSimon J. GerratyDIRDEPS = ${_subdeps:O:u:${NIgnoreFiles}:@d@${RELDIR}/${d:H}.${d:E}@:S,.${MACHINE}$,,:S,.depend$,,}
503cbdda60SSimon J. Gerraty.else
513cbdda60SSimon J. Gerraty# much simpler
523cbdda60SSimon J. Gerraty_find_name = -name ${.MAKE.DEPENDFILE:T}
533cbdda60SSimon J. Gerraty.if ${.MAKE.DEPENDFILE:E} == ${MACHINE}
543cbdda60SSimon J. Gerraty_find_name += -o -name ${.MAKE.DEPENDFILE:T:R}
553cbdda60SSimon J. Gerraty.endif
563cbdda60SSimon J. GerratyDIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@}
573cbdda60SSimon J. Gerraty.endif
583cbdda60SSimon J. Gerraty
593cbdda60SSimon J. Gerraty_subdeps != cd ${.CURDIR} && \
603cbdda60SSimon J. Gerraty	find ${SUBDIR:N.WAIT} -type f \( ${_find_name} \) -print -o \
613cbdda60SSimon J. Gerraty	-name .svn -prune 2> /dev/null; echo
623cbdda60SSimon J. Gerraty
633cbdda60SSimon J. Gerraty.if empty(_subdeps)
643cbdda60SSimon J. GerratyDIRDEPS =
653cbdda60SSimon J. Gerraty.else
663cbdda60SSimon J. Gerraty# clean up if needed
67ac3446e9SSimon J. GerratyDIRDEPS := ${DIRDEPS:S,^./,,:S,/./,/,g:${SUBDIRDEPS_FILTER:Uu}}
683cbdda60SSimon J. Gerraty.endif
693cbdda60SSimon J. Gerraty# we just dealt with it, if we leave it defined,
703cbdda60SSimon J. Gerraty# dirdeps.mk will compute some interesting combinations.
713cbdda60SSimon J. Gerraty.undef ALL_MACHINES
723cbdda60SSimon J. Gerraty
733cbdda60SSimon J. Gerraty.include <dirdeps.mk>
743cbdda60SSimon J. Gerraty.endif
753cbdda60SSimon J. Gerraty.endif
763cbdda60SSimon J. Gerraty.else
773cbdda60SSimon J. Gerratyall: .PHONY
783cbdda60SSimon J. Gerraty.endif
793cbdda60SSimon J. Gerraty
803cbdda60SSimon J. Gerraty.endif
81