xref: /freebsd/share/mk/dirdeps-targets.mk (revision f974ced3)
1f974ced3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause
2f974ced3SSimon J. Gerraty#
3312809feSSimon J. Gerraty# RCSid:
4f974ced3SSimon J. Gerraty#       $Id: dirdeps-targets.mk,v 1.27 2024/02/25 19:12:13 sjg Exp $
5312809feSSimon J. Gerraty#
6960b77beSSimon J. Gerraty#       @(#) Copyright (c) 2019-2020 Simon J. Gerraty
7312809feSSimon J. Gerraty#
8312809feSSimon J. Gerraty#       This file is provided in the hope that it will
9312809feSSimon J. Gerraty#       be of use.  There is absolutely NO WARRANTY.
10312809feSSimon J. Gerraty#       Permission to copy, redistribute or otherwise
11312809feSSimon J. Gerraty#       use this file is hereby granted provided that
12312809feSSimon J. Gerraty#       the above copyright notice and this notice are
13312809feSSimon J. Gerraty#       left intact.
14312809feSSimon J. Gerraty#
15312809feSSimon J. Gerraty#       Please send copies of changes and bug-fixes to:
16312809feSSimon J. Gerraty#       sjg@crufty.net
17312809feSSimon J. Gerraty#
18312809feSSimon J. Gerraty
19312809feSSimon J. Gerraty##
20312809feSSimon J. Gerraty# This makefile is used to set initial DIRDEPS for top-level build
21312809feSSimon J. Gerraty# targets.
22312809feSSimon J. Gerraty#
23312809feSSimon J. Gerraty# The basic idea is that we have a list of directories in
24312809feSSimon J. Gerraty# DIRDEPS_TARGETS_DIRS which are relative to SRCTOP.
25312809feSSimon J. Gerraty# When asked to make 'foo' we look for any directory named 'foo'
26312809feSSimon J. Gerraty# under DIRDEPS_TARGETS_DIRS.
27312809feSSimon J. Gerraty# We then search those dirs for any Makefile.depend*
28312809feSSimon J. Gerraty# Finally we select any that match conditions like REQUESTED_MACHINE
29312809feSSimon J. Gerraty# or TARGET_SPEC and initialize DIRDEPS accordingly.
30312809feSSimon J. Gerraty#
31960b77beSSimon J. Gerraty# We will check each of the initial DIRDEPS for Makefile.dirdeps.options
32960b77beSSimon J. Gerraty# and include any found.
33960b77beSSimon J. Gerraty# This makes it feasible to tweak options like MK_DIRDEPS_CACHE
34960b77beSSimon J. Gerraty# for a specific target.
35960b77beSSimon J. Gerraty#
36960b77beSSimon J. Gerraty# If MK_STATIC_DIRDEPS_CACHE is defined we will check if the
37960b77beSSimon J. Gerraty# initial DIRDEPS has a static cache (Makefile.dirdeps.cache).
38960b77beSSimon J. Gerraty# This only makes sense for seriously expensive targets.
39960b77beSSimon J. Gerraty#
40312809feSSimon J. Gerraty
41312809feSSimon J. Gerraty.if ${.MAKE.LEVEL} == 0
42312809feSSimon J. Gerraty# pickup customizations
43312809feSSimon J. Gerraty.-include <local.dirdeps-targets.mk>
44312809feSSimon J. Gerraty
45f974ced3SSimon J. Gerraty# this is what we are here for
46f974ced3SSimon J. Gerraty.MAIN: dirdeps
47f974ced3SSimon J. Gerraty
48312809feSSimon J. Gerraty# for DIRDEPS_BUILD this is how we prime the pump
493b26e5a4SSimon J. Gerraty# include . to allow any directory to work as a target
50312809feSSimon J. GerratyDIRDEPS_TARGETS_DIRS ?= targets targets/pseudo
51312809feSSimon J. Gerraty# these prefixes can modify how we behave
52312809feSSimon J. Gerraty# they need to be stripped when looking for target dirs
53312809feSSimon J. GerratyDIRDEPS_TARGETS_PREFIX_LIST ?= pkg- build-
54312809feSSimon J. Gerraty
55960b77beSSimon J. Gerraty# some .TARGETS need filtering
56960b77beSSimon J. GerratyDIRDEPS_TARGETS_FILTER += Nall
57960b77beSSimon J. Gerraty
58312809feSSimon J. Gerraty# matching target dirs if any
59960b77beSSimon 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:}@}
60312809feSSimon J. Gerraty
61312809feSSimon J. Gerraty.if !empty(DEBUG_DIRDEPS_TARGETS)
62312809feSSimon J. Gerraty.info tdirs=${tdirs}
63312809feSSimon J. Gerraty.endif
64312809feSSimon J. Gerraty
65312809feSSimon J. Gerraty.if !empty(tdirs)
66312809feSSimon J. Gerraty# some things we know we want to ignore
67312809feSSimon J. GerratyDIRDEPS_TARGETS_SKIP_LIST += \
68312809feSSimon J. Gerraty	*~ \
69312809feSSimon J. Gerraty	*.bak \
70312809feSSimon J. Gerraty	*.inc \
71312809feSSimon J. Gerraty	*.old \
72312809feSSimon J. Gerraty	*.options \
73312809feSSimon J. Gerraty	*.orig \
74312809feSSimon J. Gerraty	*.rej \
75312809feSSimon J. Gerraty
76312809feSSimon J. Gerraty# the list of MACHINEs we consider
77312809feSSimon J. GerratyDIRDEPS_TARGETS_MACHINE_LIST += \
78312809feSSimon J. Gerraty	${ALL_MACHINE_LIST:U} \
79312809feSSimon J. Gerraty	${PSEUDO_MACHINE_LIST:Ucommon host host32} \
80312809feSSimon J. Gerraty	${TARGET_MACHINE_LIST}
81312809feSSimon J. Gerraty
82312809feSSimon J. GerratyDIRDEPS_TARGETS_MACHINE_LIST := ${DIRDEPS_TARGETS_MACHINE_LIST:O:u}
83312809feSSimon J. Gerraty
84312809feSSimon J. Gerraty# raw Makefile.depend* list
853b26e5a4SSimon J. Gerratytdeps != 'cd' ${SRCTOP} && 'ls' -1 ${tdirs:O:u:@d@$d/${.MAKE.DEPENDFILE_PREFIX}*@:S,^./,,} 2> /dev/null; echo
86312809feSSimon J. Gerraty.if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != ""
87312809feSSimon J. Gerraty.info tdeps=${tdeps}
88312809feSSimon J. Gerraty.endif
89312809feSSimon J. Gerraty# remove things we know we don't want
90312809feSSimon J. Gerratytdeps := ${tdeps:${DIRDEPS_TARGETS_SKIP_LIST:${M_ListToSkip}}}
91312809feSSimon J. Gerraty.if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != ""
92312809feSSimon J. Gerraty.info tdeps=${tdeps}
93312809feSSimon J. Gerraty.endif
94312809feSSimon J. Gerraty
95312809feSSimon J. Gerraty# plain entries (no qualifiers) these apply to any TARGET_SPEC
96312809feSSimon J. Gerratyptdeps := ${tdeps:M*${.MAKE.DEPENDFILE_PREFIX}:S,/${.MAKE.DEPENDFILE_PREFIX},,}
97312809feSSimon J. Gerraty
98312809feSSimon J. Gerraty# MACHINE qualified entries
99312809feSSimon J. Gerratymqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
100312809feSSimon J. Gerraty
101312809feSSimon J. Gerratytqtdeps =
102312809feSSimon J. Gerraty.if ${TARGET_SPEC_VARS:[#]} > 1
103312809feSSimon J. Gerraty# TARGET_SPEC qualified entries
104312809feSSimon J. Gerraty.if !empty(TARGET_SPEC_LIST)
105312809feSSimon J. Gerraty# we have a list of valid TARGET_SPECS; use it
106312809feSSimon J. Gerratytqtdeps := ${TARGET_SPEC_LIST:U:O:u:@t@${tdeps:M*.$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
107312809feSSimon J. Gerraty.else
108312809feSSimon J. Gerraty# do we have a list of valid tuple members for at least
109312809feSSimon J. Gerraty# the last tupple element? if so match on that
110312809feSSimon J. GerratyTARGET_SPEC_LAST_LIST ?= ${${TARGET_SPEC_VARS:[-1]}_LIST}
111312809feSSimon J. Gerraty.if !empty(TARGET_SPEC_LAST_LIST)
112312809feSSimon J. Gerratytqtdeps := ${TARGET_SPEC_LAST_LIST:U:O:u:@t@${tdeps:M*,$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
113312809feSSimon J. Gerraty.else
114312809feSSimon J. Gerraty# this is sub-optimal match MACHINE,
115312809feSSimon J. Gerratytqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m,*}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
116312809feSSimon J. Gerraty.endif
117312809feSSimon J. Gerraty.endif
118312809feSSimon J. Gerraty.endif
119312809feSSimon J. Gerraty
120312809feSSimon J. Gerraty# now work out what we want in DIRDEPS
12140b9b299SSimon J. GerratyDIRDEPS = ${ptdeps}
122312809feSSimon J. Gerraty.if empty(REQUESTED_MACHINE)
123312809feSSimon J. Gerraty# we want them all just as found
12440b9b299SSimon J. GerratyDIRDEPS += ${mqtdeps} ${tqtdeps}
125312809feSSimon J. Gerraty.else
126312809feSSimon J. Gerraty# we only want those that match REQUESTED_MACHINE/REQUESTED_TARGET_SPEC
127312809feSSimon J. Gerraty# or REQUESTED_TARGET_SPEC (TARGET_SPEC)
12840b9b299SSimon J. GerratyDIRDEPS += \
129312809feSSimon J. Gerraty	${mqtdeps:M*.${REQUESTED_MACHINE}} \
13040b9b299SSimon J. Gerraty	${tqtdeps:M*.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC}}} \
13140b9b299SSimon J. Gerraty
132312809feSSimon J. Gerraty.endif
133312809feSSimon J. Gerraty# clean up
134312809feSSimon J. GerratyDIRDEPS := ${DIRDEPS:O:u}
135312809feSSimon J. Gerraty
136312809feSSimon J. Gerraty.if !empty(DEBUG_DIRDEPS_TARGETS)
137312809feSSimon J. Gerraty.for x in tdeps ptdeps mqtdeps tqtdeps DIRDEPS
138312809feSSimon J. Gerraty.info $x=${$x}
139312809feSSimon J. Gerraty.endfor
140312809feSSimon J. Gerraty.endif
141312809feSSimon J. Gerraty.endif
142312809feSSimon J. Gerraty# if we got DIRDEPS get to work
143312809feSSimon J. Gerraty.if !empty(DIRDEPS)
144960b77beSSimon J. GerratyDIRDEPS.dirs := ${DIRDEPS:S,^,${SRCTOP}/,:@d@${exists($d):?$d:${d:R}}@}
1453b26e5a4SSimon J. Gerraty# some targets want to tweak options we might want to process now
146960b77beSSimon J. Gerraty.for m in ${DIRDEPS.dirs:S,$,/Makefile.dirdeps.options,}
147960b77beSSimon J. Gerraty.-include <$m>
148960b77beSSimon J. Gerraty.endfor
149960b77beSSimon J. Gerraty.if defined(MK_STATIC_DIRDEPS_CACHE)
150960b77beSSimon J. Gerraty# some targets are very expensive to compute dirdeps for
151960b77beSSimon J. Gerraty# so we may have a static cache
152960b77beSSimon J. Gerraty.for c in ${DIRDEPS.dirs:S,$,/Makefile.dirdeps.cache,}
153960b77beSSimon J. Gerraty.if exists($c)
154960b77beSSimon J. GerratySTATIC_DIRDEPS_CACHE ?= $c
155960b77beSSimon J. Gerraty.if ${MK_STATIC_DIRDEPS_CACHE} == "yes"
156960b77beSSimon J. GerratyDIRDEPS_CACHE ?= $c
157960b77beSSimon J. GerratyMK_DIRDEPS_CACHE = yes
158960b77beSSimon J. Gerraty.endif
159960b77beSSimon J. Gerraty.endif
160960b77beSSimon J. Gerraty.endfor
161960b77beSSimon J. Gerraty.if defined(STATIC_DIRDEPS_CACHE)
162960b77beSSimon J. Gerraty.export STATIC_DIRDEPS_CACHE
163960b77beSSimon J. Gerraty.endif
164960b77beSSimon J. Gerraty.endif
165960b77beSSimon J. Gerraty
166960b77beSSimon J. Gerraty# allow a top-level makefile to do other stuff
167960b77beSSimon J. Gerraty# before including dirdeps.mk
168960b77beSSimon J. Gerraty.if ${MK_DIRDEPS_TARGETS_INCLUDE_DIRDEPS:Uyes} == "yes"
169312809feSSimon J. Gerraty.include <dirdeps.mk>
170960b77beSSimon J. Gerraty.endif
171312809feSSimon J. Gerraty
172312809feSSimon J. GerratyDIRDEPS_TARGETS_SKIP += all clean* destroy*
173312809feSSimon J. Gerraty
174312809feSSimon J. Gerraty.for t in ${.TARGETS:${DIRDEPS_TARGETS_SKIP:${M_ListToSkip}}}
175312809feSSimon J. Gerraty$t: dirdeps
176312809feSSimon J. Gerraty.endfor
177312809feSSimon J. Gerraty.endif
178312809feSSimon J. Gerraty.endif
179