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