xref: /freebsd/contrib/bmake/mk/dirdeps-targets.mk (revision 6a7405f5a6b639682cacf01e35d561411ff556aa)
1c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause
2c59c3bf3SSimon J. Gerraty#
349caa483SSimon J. Gerraty# RCSid:
4*6a7405f5SSimon J. Gerraty#       $Id: dirdeps-targets.mk,v 1.28 2024/10/19 00:47:38 sjg Exp $
549caa483SSimon J. Gerraty#
6ef0b2538SSimon J. Gerraty#       @(#) Copyright (c) 2019-2020 Simon J. Gerraty
749caa483SSimon J. Gerraty#
849caa483SSimon J. Gerraty#       This file is provided in the hope that it will
949caa483SSimon J. Gerraty#       be of use.  There is absolutely NO WARRANTY.
1049caa483SSimon J. Gerraty#       Permission to copy, redistribute or otherwise
1149caa483SSimon J. Gerraty#       use this file is hereby granted provided that
1249caa483SSimon J. Gerraty#       the above copyright notice and this notice are
1349caa483SSimon J. Gerraty#       left intact.
1449caa483SSimon J. Gerraty#
1549caa483SSimon J. Gerraty#       Please send copies of changes and bug-fixes to:
1649caa483SSimon J. Gerraty#       sjg@crufty.net
1749caa483SSimon J. Gerraty#
1849caa483SSimon J. Gerraty
1949caa483SSimon J. Gerraty##
2049caa483SSimon J. Gerraty# This makefile is used to set initial DIRDEPS for top-level build
2149caa483SSimon J. Gerraty# targets.
2249caa483SSimon J. Gerraty#
2349caa483SSimon J. Gerraty# The basic idea is that we have a list of directories in
2449caa483SSimon J. Gerraty# DIRDEPS_TARGETS_DIRS which are relative to SRCTOP.
2549caa483SSimon J. Gerraty# When asked to make 'foo' we look for any directory named 'foo'
2649caa483SSimon J. Gerraty# under DIRDEPS_TARGETS_DIRS.
2749caa483SSimon J. Gerraty# We then search those dirs for any Makefile.depend*
2849caa483SSimon J. Gerraty# Finally we select any that match conditions like REQUESTED_MACHINE
2949caa483SSimon J. Gerraty# or TARGET_SPEC and initialize DIRDEPS accordingly.
3049caa483SSimon J. Gerraty#
312c3632d1SSimon J. Gerraty# We will check each of the initial DIRDEPS for Makefile.dirdeps.options
322c3632d1SSimon J. Gerraty# and include any found.
332c3632d1SSimon J. Gerraty# This makes it feasible to tweak options like MK_DIRDEPS_CACHE
342c3632d1SSimon J. Gerraty# for a specific target.
352c3632d1SSimon J. Gerraty#
362c3632d1SSimon J. Gerraty# If MK_STATIC_DIRDEPS_CACHE is defined we will check if the
372c3632d1SSimon J. Gerraty# initial DIRDEPS has a static cache (Makefile.dirdeps.cache).
382c3632d1SSimon J. Gerraty# This only makes sense for seriously expensive targets.
392c3632d1SSimon J. Gerraty#
4049caa483SSimon J. Gerraty
4149caa483SSimon J. Gerraty.if ${.MAKE.LEVEL} == 0
4249caa483SSimon J. Gerraty# pickup customizations
4349caa483SSimon J. Gerraty.-include <local.dirdeps-targets.mk>
4449caa483SSimon J. Gerraty
45c59c3bf3SSimon J. Gerraty# this is what we are here for
46c59c3bf3SSimon J. Gerraty.MAIN: dirdeps
47c59c3bf3SSimon J. Gerraty
4849caa483SSimon J. Gerraty# for DIRDEPS_BUILD this is how we prime the pump
4906b9b3e0SSimon J. Gerraty# include . to allow any directory to work as a target
5049caa483SSimon J. GerratyDIRDEPS_TARGETS_DIRS ?= targets targets/pseudo
5149caa483SSimon J. Gerraty# these prefixes can modify how we behave
5249caa483SSimon J. Gerraty# they need to be stripped when looking for target dirs
5349caa483SSimon J. GerratyDIRDEPS_TARGETS_PREFIX_LIST ?= pkg- build-
5449caa483SSimon J. Gerraty
55ef0b2538SSimon J. Gerraty# some .TARGETS need filtering
56ef0b2538SSimon J. GerratyDIRDEPS_TARGETS_FILTER += Nall
57ef0b2538SSimon J. Gerraty
5849caa483SSimon J. Gerraty# matching target dirs if any
59ef0b2538SSimon J. Gerratytdirs := ${.TARGETS:${DIRDEPS_TARGETS_FILTER:ts:}:${DIRDEPS_TARGETS_PREFIX_LIST:@p@S,^$p,,@:ts:}:@t@${DIRDEPS_TARGETS_DIRS:@d@$d/$t@}@:@d@${exists(${SRCTOP}/$d):?$d:}@}
6049caa483SSimon J. Gerraty
6149caa483SSimon J. Gerraty.if !empty(DEBUG_DIRDEPS_TARGETS)
6249caa483SSimon J. Gerraty.info tdirs=${tdirs}
6349caa483SSimon J. Gerraty.endif
6449caa483SSimon J. Gerraty
6549caa483SSimon J. Gerraty.if !empty(tdirs)
6649caa483SSimon J. Gerraty# some things we know we want to ignore
6749caa483SSimon J. GerratyDIRDEPS_TARGETS_SKIP_LIST += \
6849caa483SSimon J. Gerraty	*~ \
6949caa483SSimon J. Gerraty	*.bak \
7049caa483SSimon J. Gerraty	*.inc \
7149caa483SSimon J. Gerraty	*.old \
7249caa483SSimon J. Gerraty	*.options \
7349caa483SSimon J. Gerraty	*.orig \
7449caa483SSimon J. Gerraty	*.rej \
7549caa483SSimon J. Gerraty
7649caa483SSimon J. Gerraty# the list of MACHINEs we consider
7749caa483SSimon J. GerratyDIRDEPS_TARGETS_MACHINE_LIST += \
7849caa483SSimon J. Gerraty	${ALL_MACHINE_LIST:U} \
7949caa483SSimon J. Gerraty	${PSEUDO_MACHINE_LIST:Ucommon host host32} \
8049caa483SSimon J. Gerraty	${TARGET_MACHINE_LIST}
8149caa483SSimon J. Gerraty
8249caa483SSimon J. GerratyDIRDEPS_TARGETS_MACHINE_LIST := ${DIRDEPS_TARGETS_MACHINE_LIST:O:u}
8349caa483SSimon J. Gerraty
8449caa483SSimon J. Gerraty# raw Makefile.depend* list
8506b9b3e0SSimon J. Gerratytdeps != 'cd' ${SRCTOP} && 'ls' -1 ${tdirs:O:u:@d@$d/${.MAKE.DEPENDFILE_PREFIX}*@:S,^./,,} 2> /dev/null; echo
8649caa483SSimon J. Gerraty.if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != ""
8749caa483SSimon J. Gerraty.info tdeps=${tdeps}
8849caa483SSimon J. Gerraty.endif
8949caa483SSimon J. Gerraty# remove things we know we don't want
9049caa483SSimon J. Gerratytdeps := ${tdeps:${DIRDEPS_TARGETS_SKIP_LIST:${M_ListToSkip}}}
9149caa483SSimon J. Gerraty.if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != ""
9249caa483SSimon J. Gerraty.info tdeps=${tdeps}
9349caa483SSimon J. Gerraty.endif
9449caa483SSimon J. Gerraty
9549caa483SSimon J. Gerraty# plain entries (no qualifiers) these apply to any TARGET_SPEC
9649caa483SSimon J. Gerratyptdeps := ${tdeps:M*${.MAKE.DEPENDFILE_PREFIX}:S,/${.MAKE.DEPENDFILE_PREFIX},,}
9749caa483SSimon J. Gerraty
9849caa483SSimon J. Gerraty# MACHINE qualified entries
9949caa483SSimon J. Gerratymqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
10049caa483SSimon J. Gerraty
10149caa483SSimon J. Gerratytqtdeps =
10249caa483SSimon J. Gerraty.if ${TARGET_SPEC_VARS:[#]} > 1
10349caa483SSimon J. Gerraty# TARGET_SPEC qualified entries
10449caa483SSimon J. Gerraty.if !empty(TARGET_SPEC_LIST)
10549caa483SSimon J. Gerraty# we have a list of valid TARGET_SPECS; use it
10649caa483SSimon J. Gerratytqtdeps := ${TARGET_SPEC_LIST:U:O:u:@t@${tdeps:M*.$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
10749caa483SSimon J. Gerraty.else
10849caa483SSimon J. Gerraty# do we have a list of valid tuple members for at least
10949caa483SSimon J. Gerraty# the last tupple element? if so match on that
11049caa483SSimon J. GerratyTARGET_SPEC_LAST_LIST ?= ${${TARGET_SPEC_VARS:[-1]}_LIST}
11149caa483SSimon J. Gerraty.if !empty(TARGET_SPEC_LAST_LIST)
11249caa483SSimon J. Gerratytqtdeps := ${TARGET_SPEC_LAST_LIST:U:O:u:@t@${tdeps:M*,$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
11349caa483SSimon J. Gerraty.else
11449caa483SSimon J. Gerraty# this is sub-optimal match MACHINE,
11549caa483SSimon J. Gerratytqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m,*}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
11649caa483SSimon J. Gerraty.endif
11749caa483SSimon J. Gerraty.endif
11849caa483SSimon J. Gerraty.endif
11949caa483SSimon J. Gerraty
12049caa483SSimon J. Gerraty# now work out what we want in DIRDEPS
121c1d01b5fSSimon J. GerratyDIRDEPS = ${ptdeps}
12249caa483SSimon J. Gerraty.if empty(REQUESTED_MACHINE)
12349caa483SSimon J. Gerraty# we want them all just as found
124c1d01b5fSSimon J. GerratyDIRDEPS += ${mqtdeps} ${tqtdeps}
12549caa483SSimon J. Gerraty.else
12649caa483SSimon J. Gerraty# we only want those that match REQUESTED_MACHINE/REQUESTED_TARGET_SPEC
12749caa483SSimon J. Gerraty# or REQUESTED_TARGET_SPEC (TARGET_SPEC)
128c1d01b5fSSimon J. GerratyDIRDEPS += \
12949caa483SSimon J. Gerraty	${mqtdeps:M*.${REQUESTED_MACHINE}} \
130c1d01b5fSSimon J. Gerraty	${tqtdeps:M*.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC}}} \
131c1d01b5fSSimon J. Gerraty
13249caa483SSimon J. Gerraty.endif
13349caa483SSimon J. Gerraty# clean up
13449caa483SSimon J. GerratyDIRDEPS := ${DIRDEPS:O:u}
13549caa483SSimon J. Gerraty
13649caa483SSimon J. Gerraty.if !empty(DEBUG_DIRDEPS_TARGETS)
13749caa483SSimon J. Gerraty.for x in tdeps ptdeps mqtdeps tqtdeps DIRDEPS
13849caa483SSimon J. Gerraty.info $x=${$x}
13949caa483SSimon J. Gerraty.endfor
14049caa483SSimon J. Gerraty.endif
14149caa483SSimon J. Gerraty.endif
14249caa483SSimon J. Gerraty# if we got DIRDEPS get to work
14349caa483SSimon J. Gerraty.if !empty(DIRDEPS)
1442c3632d1SSimon J. GerratyDIRDEPS.dirs := ${DIRDEPS:S,^,${SRCTOP}/,:@d@${exists($d):?$d:${d:R}}@}
14506b9b3e0SSimon J. Gerraty# some targets want to tweak options we might want to process now
1462c3632d1SSimon J. Gerraty.for m in ${DIRDEPS.dirs:S,$,/Makefile.dirdeps.options,}
1472c3632d1SSimon J. Gerraty.-include <$m>
1482c3632d1SSimon J. Gerraty.endfor
1492c3632d1SSimon J. Gerraty.if defined(MK_STATIC_DIRDEPS_CACHE)
1502c3632d1SSimon J. Gerraty# some targets are very expensive to compute dirdeps for
1512c3632d1SSimon J. Gerraty# so we may have a static cache
1522c3632d1SSimon J. Gerraty.for c in ${DIRDEPS.dirs:S,$,/Makefile.dirdeps.cache,}
1532c3632d1SSimon J. Gerraty.if exists($c)
1542c3632d1SSimon J. GerratySTATIC_DIRDEPS_CACHE ?= $c
1552c3632d1SSimon J. Gerraty.if ${MK_STATIC_DIRDEPS_CACHE} == "yes"
1562c3632d1SSimon J. GerratyDIRDEPS_CACHE ?= $c
1572c3632d1SSimon J. GerratyMK_DIRDEPS_CACHE = yes
1582c3632d1SSimon J. Gerraty.endif
1592c3632d1SSimon J. Gerraty.endif
1602c3632d1SSimon J. Gerraty.endfor
1612c3632d1SSimon J. Gerraty.if defined(STATIC_DIRDEPS_CACHE)
1622c3632d1SSimon J. Gerraty.export STATIC_DIRDEPS_CACHE
163*6a7405f5SSimon J. Gerraty.if !empty(DEBUG_DIRDEPS_TARGETS)
164*6a7405f5SSimon J. Gerraty.info STATIC_DIRDEPS_CACHE=${STATIC_DIRDEPS_CACHE:S,${SRCTOP}/,,}
165*6a7405f5SSimon J. Gerraty.endif
1662c3632d1SSimon J. Gerraty.endif
1672c3632d1SSimon J. Gerraty.endif
1682c3632d1SSimon J. Gerraty
1692c3632d1SSimon J. Gerraty# allow a top-level makefile to do other stuff
1702c3632d1SSimon J. Gerraty# before including dirdeps.mk
1712c3632d1SSimon J. Gerraty.if ${MK_DIRDEPS_TARGETS_INCLUDE_DIRDEPS:Uyes} == "yes"
17249caa483SSimon J. Gerraty.include <dirdeps.mk>
1732c3632d1SSimon J. Gerraty.endif
17449caa483SSimon J. Gerraty
17549caa483SSimon J. GerratyDIRDEPS_TARGETS_SKIP += all clean* destroy*
17649caa483SSimon J. Gerraty
17749caa483SSimon J. Gerraty.for t in ${.TARGETS:${DIRDEPS_TARGETS_SKIP:${M_ListToSkip}}}
17849caa483SSimon J. Gerraty$t: dirdeps
17949caa483SSimon J. Gerraty.endfor
18049caa483SSimon J. Gerraty.endif
18149caa483SSimon J. Gerraty.endif
182