xref: /freebsd/contrib/bmake/mk/dirdeps-options.mk (revision c59c3bf34db360695f07735bebc76a768cac5afc)
1*c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause
2*c59c3bf3SSimon J. Gerraty#
3*c59c3bf3SSimon J. Gerraty# $Id: dirdeps-options.mk,v 1.22 2024/02/17 17:26:57 sjg Exp $
4494f7191SSimon J. Gerraty#
51d3f2ddcSSimon J. Gerraty#	@(#) Copyright (c) 2018-2022, Simon J. Gerraty
6494f7191SSimon J. Gerraty#
7494f7191SSimon J. Gerraty#	This file is provided in the hope that it will
8494f7191SSimon J. Gerraty#	be of use.  There is absolutely NO WARRANTY.
9494f7191SSimon J. Gerraty#	Permission to copy, redistribute or otherwise
10494f7191SSimon J. Gerraty#	use this file is hereby granted provided that
11494f7191SSimon J. Gerraty#	the above copyright notice and this notice are
12494f7191SSimon J. Gerraty#	left intact.
13494f7191SSimon J. Gerraty#
14494f7191SSimon J. Gerraty#	Please send copies of changes and bug-fixes to:
15494f7191SSimon J. Gerraty#	sjg@crufty.net
16494f7191SSimon J. Gerraty#
17494f7191SSimon J. Gerraty
18494f7191SSimon J. Gerraty##
19494f7191SSimon J. Gerraty#
20494f7191SSimon J. Gerraty# This makefile is used to deal with optional DIRDEPS.
21494f7191SSimon J. Gerraty#
22494f7191SSimon J. Gerraty# It is to be included by Makefile.depend.options in a
23494f7191SSimon J. Gerraty# directory which has DIRDEPS affected by optional features.
24494f7191SSimon J. Gerraty# Makefile.depend.options should set DIRDEPS_OPTIONS and
25494f7191SSimon J. Gerraty# may also set specific DIRDEPS.* for those options.
26494f7191SSimon J. Gerraty#
27494f7191SSimon J. Gerraty# If a Makefile.depend.options file exists, it will be included by
28494f7191SSimon J. Gerraty# dirdeps.mk and meta.autodep.mk
29494f7191SSimon J. Gerraty#
302eae894cSSimon J. Gerraty# We include local.dirdeps-options.mk which may also define DIRDEPS.*
31494f7191SSimon J. Gerraty# for options.
32494f7191SSimon J. Gerraty#
33494f7191SSimon J. Gerraty# Thus a directory, that is affected by an option FOO would have
34494f7191SSimon J. Gerraty# a Makefile.depend.options that sets
35494f7191SSimon J. Gerraty# DIRDEPS_OPTIONS= FOO
36494f7191SSimon J. Gerraty# It can also set either/both of
37494f7191SSimon J. Gerraty# DIRDEPS.FOO.yes
38494f7191SSimon J. Gerraty# DIRDEPS.FOO.no
39494f7191SSimon J. Gerraty# to whatever applies for that dir, or it can rely on globals
402eae894cSSimon J. Gerraty# set in local.dirdeps-options.mk
41494f7191SSimon J. Gerraty# Either way, we will .undef DIRDEPS.* when done.
422c3632d1SSimon J. Gerraty#
432c3632d1SSimon J. Gerraty# In some cases the value of MK_FOO might depend on TARGET_SPEC
442c3632d1SSimon J. Gerraty# so we qualify MK_FOO with .${TARGET_SPEC} and each component
452c3632d1SSimon J. Gerraty# TARGET_SPEC_VAR (in reverse order) before using MK_FOO.
462c3632d1SSimon J. Gerraty#
474fde40d9SSimon J. Gerraty# Because Makefile.depend.options are processed at both level 0 (when
484fde40d9SSimon J. Gerraty# computing DIRDEPS to build) and higher (when updating
494fde40d9SSimon J. Gerraty# Makefile.depend* after successful build), it is important that
504fde40d9SSimon J. Gerraty# all references to TARGET_SPEC_VARs should use the syntax
514fde40d9SSimon J. Gerraty# ${DEP_${TARGET_SPEC_VAR}:U${TARGET_SPEC_VAR}} to ensure correct
524fde40d9SSimon J. Gerraty# behavior.
534fde40d9SSimon J. Gerraty#
54494f7191SSimon J. Gerraty
55494f7191SSimon J. Gerraty# This should have been set by Makefile.depend.options
56494f7191SSimon J. Gerraty# before including us
57494f7191SSimon J. GerratyDIRDEPS_OPTIONS ?=
58494f7191SSimon J. Gerraty
59494f7191SSimon J. Gerraty# pickup any DIRDEPS.* we need
602eae894cSSimon J. Gerraty.-include <local.dirdeps-options.mk>
61494f7191SSimon J. Gerraty
62494f7191SSimon J. Gerraty.if ${.MAKE.LEVEL} == 0
63494f7191SSimon J. Gerraty# :U below avoids potential errors when we :=
642c3632d1SSimon J. Gerraty# some options can depend on TARGET_SPEC!
652c3632d1SSimon J. GerratyDIRDEPS_OPTIONS_QUALIFIER_LIST ?= \
661d3f2ddcSSimon J. Gerraty	${DEP_RELDIR} \
672c3632d1SSimon J. Gerraty	${DEP_TARGET_SPEC:U${TARGET_SPEC}} \
682c3632d1SSimon J. Gerraty	${TARGET_SPEC_VARSr:U${TARGET_SPEC_VARS}:@v@${DEP_$v:U${$v}}@}
692c3632d1SSimon J. Gerraty# note that we need to include $o in the variable _o$o
702c3632d1SSimon J. Gerraty# to ensure correct evaluation.
712c3632d1SSimon J. Gerraty.for o in ${DIRDEPS_OPTIONS}
7206b9b3e0SSimon J. Gerraty.undef _o$o
7306b9b3e0SSimon J. Gerraty.undef _v$o
741d3f2ddcSSimon J. Gerraty.for x in ${DIRDEPS_OPTIONS_QUALIFIER_LIST:S,^,${DEP_RELDIR}.,} \
751d3f2ddcSSimon J. Gerraty	${DIRDEPS_OPTIONS_QUALIFIER_LIST}
761d3f2ddcSSimon J. Gerraty#.info MK_$o.$x=${MK_$o.$x:Uundefined}
772c3632d1SSimon J. Gerraty.if defined(MK_$o.$x)
782c3632d1SSimon J. Gerraty_o$o ?= MK_$o.$x
792c3632d1SSimon J. Gerraty_v$o ?= ${MK_$o.$x}
802c3632d1SSimon J. Gerraty.endif
812c3632d1SSimon J. Gerraty.endfor
822c3632d1SSimon J. Gerraty_v$o ?= ${MK_$o}
832c3632d1SSimon J. Gerraty.if ${_debug_reldir:U0}
842c3632d1SSimon J. Gerraty.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}
852c3632d1SSimon J. Gerraty.endif
862c3632d1SSimon J. GerratyDIRDEPS += ${DIRDEPS.$o.${_v$o:U}:U}
87494f7191SSimon J. Gerraty.endfor
88494f7191SSimon J. GerratyDIRDEPS := ${DIRDEPS:O:u}
892c3632d1SSimon J. Gerraty.if ${_debug_reldir:U0}
902c3632d1SSimon J. Gerraty.info ${DEP_RELDIR:U${RELDIR}}: DIRDEPS=${DIRDEPS}
912c3632d1SSimon J. Gerraty.endif
92494f7191SSimon J. Gerraty# avoid cross contamination
932c3632d1SSimon J. Gerraty.for o in ${DIRDEPS_OPTIONS}
942eae894cSSimon J. Gerraty.undef DIRDEPS.$o.yes
952eae894cSSimon J. Gerraty.undef DIRDEPS.$o.no
962c3632d1SSimon J. Gerraty.undef _o$o
972c3632d1SSimon J. Gerraty.undef _v$o
982eae894cSSimon J. Gerraty.endfor
99494f7191SSimon J. Gerraty.else
100494f7191SSimon J. Gerraty# whether options are enabled or not,
101494f7191SSimon J. Gerraty# we want to filter out the relevant DIRDEPS.*
102494f7191SSimon J. Gerraty# we should only be included by meta.autodep.mk
103494f7191SSimon J. Gerraty# if dependencies are to be updated
1042c3632d1SSimon J. Gerraty.for o in ${DIRDEPS_OPTIONS}
105494f7191SSimon J. Gerraty.for d in ${DIRDEPS.$o.yes} ${DIRDEPS.$o.no}
106494f7191SSimon J. Gerraty.if exists(${SRCTOP}/$d)
107494f7191SSimon J. GerratyGENDIRDEPS_FILTER += N$d*
108494f7191SSimon J. Gerraty.elif exists(${SRCTOP}/${d:R})
109494f7191SSimon J. GerratyGENDIRDEPS_FILTER += N${d:R}*
110494f7191SSimon J. Gerraty.endif
111494f7191SSimon J. Gerraty.endfor
112494f7191SSimon J. Gerraty.endfor
113494f7191SSimon J. Gerraty.endif
114