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