xref: /freebsd/contrib/bmake/mk/dirdeps-options.mk (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
1# SPDX-License-Identifier: BSD-2-Clause
2#
3# $Id: dirdeps-options.mk,v 1.22 2024/02/17 17:26:57 sjg Exp $
4#
5#	@(#) Copyright (c) 2018-2022, Simon J. Gerraty
6#
7#	This file is provided in the hope that it will
8#	be of use.  There is absolutely NO WARRANTY.
9#	Permission to copy, redistribute or otherwise
10#	use this file is hereby granted provided that
11#	the above copyright notice and this notice are
12#	left intact.
13#
14#	Please send copies of changes and bug-fixes to:
15#	sjg@crufty.net
16#
17
18##
19#
20# This makefile is used to deal with optional DIRDEPS.
21#
22# It is to be included by Makefile.depend.options in a
23# directory which has DIRDEPS affected by optional features.
24# Makefile.depend.options should set DIRDEPS_OPTIONS and
25# may also set specific DIRDEPS.* for those options.
26#
27# If a Makefile.depend.options file exists, it will be included by
28# dirdeps.mk and meta.autodep.mk
29#
30# We include local.dirdeps-options.mk which may also define DIRDEPS.*
31# for options.
32#
33# Thus a directory, that is affected by an option FOO would have
34# a Makefile.depend.options that sets
35# DIRDEPS_OPTIONS= FOO
36# It can also set either/both of
37# DIRDEPS.FOO.yes
38# DIRDEPS.FOO.no
39# to whatever applies for that dir, or it can rely on globals
40# set in local.dirdeps-options.mk
41# Either way, we will .undef DIRDEPS.* when done.
42#
43# In some cases the value of MK_FOO might depend on TARGET_SPEC
44# so we qualify MK_FOO with .${TARGET_SPEC} and each component
45# TARGET_SPEC_VAR (in reverse order) before using MK_FOO.
46#
47# Because Makefile.depend.options are processed at both level 0 (when
48# computing DIRDEPS to build) and higher (when updating
49# Makefile.depend* after successful build), it is important that
50# all references to TARGET_SPEC_VARs should use the syntax
51# ${DEP_${TARGET_SPEC_VAR}:U${TARGET_SPEC_VAR}} to ensure correct
52# behavior.
53#
54
55# This should have been set by Makefile.depend.options
56# before including us
57DIRDEPS_OPTIONS ?=
58
59# pickup any DIRDEPS.* we need
60.-include <local.dirdeps-options.mk>
61
62.if ${.MAKE.LEVEL} == 0
63# :U below avoids potential errors when we :=
64# some options can depend on TARGET_SPEC!
65DIRDEPS_OPTIONS_QUALIFIER_LIST ?= \
66	${DEP_RELDIR} \
67	${DEP_TARGET_SPEC:U${TARGET_SPEC}} \
68	${TARGET_SPEC_VARSr:U${TARGET_SPEC_VARS}:@v@${DEP_$v:U${$v}}@}
69# note that we need to include $o in the variable _o$o
70# to ensure correct evaluation.
71.for o in ${DIRDEPS_OPTIONS}
72.undef _o$o
73.undef _v$o
74.for x in ${DIRDEPS_OPTIONS_QUALIFIER_LIST:S,^,${DEP_RELDIR}.,} \
75	${DIRDEPS_OPTIONS_QUALIFIER_LIST}
76#.info MK_$o.$x=${MK_$o.$x:Uundefined}
77.if defined(MK_$o.$x)
78_o$o ?= MK_$o.$x
79_v$o ?= ${MK_$o.$x}
80.endif
81.endfor
82_v$o ?= ${MK_$o}
83.if ${_debug_reldir:U0}
84.info ${DEP_RELDIR:U${RELDIR}}.${DEP_TARGET_SPEC:U${TARGET_SPEC}}: o=$o ${_o$o:UMK_$o}=${_v$o:U} DIRDEPS += ${DIRDEPS.$o.${_v$o:U}:U}
85.endif
86DIRDEPS += ${DIRDEPS.$o.${_v$o:U}:U}
87.endfor
88DIRDEPS := ${DIRDEPS:O:u}
89.if ${_debug_reldir:U0}
90.info ${DEP_RELDIR:U${RELDIR}}: DIRDEPS=${DIRDEPS}
91.endif
92# avoid cross contamination
93.for o in ${DIRDEPS_OPTIONS}
94.undef DIRDEPS.$o.yes
95.undef DIRDEPS.$o.no
96.undef _o$o
97.undef _v$o
98.endfor
99.else
100# whether options are enabled or not,
101# we want to filter out the relevant DIRDEPS.*
102# we should only be included by meta.autodep.mk
103# if dependencies are to be updated
104.for o in ${DIRDEPS_OPTIONS}
105.for d in ${DIRDEPS.$o.yes} ${DIRDEPS.$o.no}
106.if exists(${SRCTOP}/$d)
107GENDIRDEPS_FILTER += N$d*
108.elif exists(${SRCTOP}/${d:R})
109GENDIRDEPS_FILTER += N${d:R}*
110.endif
111.endfor
112.endfor
113.endif
114