1# $Id: cc-wrap.mk,v 1.5 2022/02/07 19:02:55 sjg Exp $ 2# 3# @(#) Copyright (c) 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.if ${MAKE_VERSION} >= 20220126 17# which targets are we interested in? 18CC_WRAP_TARGETS ?= ${OBJS:U} ${POBJS:U} ${SOBJS:U} 19 20.if !empty(CC_WRAP_TARGETS) 21# cleanup 22# all the target assignments below are effectively := anyway 23# so we might as well do this once 24CC_WRAP_TARGETS := ${CC_WRAP_TARGETS:O:u} 25 26# what do we wrap? 27CC_WRAP_LIST += CC CXX 28CC_WRAP_LIST := ${CC_WRAP_LIST:O:u} 29 30# what might we wrap them with? 31CC_WRAPPERS += ccache distcc icecc 32CC_WRAPPERS := ${CC_WRAPPERS:O:u} 33# $W can be as simple or complicated as you like (default is just $w) 34# eg. 35# CCACHE ?= ${CCACHE_ENV_VARS:@v@$v='${$v}'@} ${CCACHE_CMD} ${CCACHE_FLAGS} 36# or if you want global vars to be used modifiable after this include: 37# CCACHE ?= $${CCACHE_ENV_VARS:@v@$$v='$${$$v}'@} $${CCACHE_CMD} $${CCACHE_FLAGS} 38.for w in ${CC_WRAPPERS} 39${w:tu} ?= $w 40.endfor 41 42# we do not want to make all these targets out-of-date 43# just because one of the above wrappers are enabled/disabled 44${CC_WRAP_TARGETS}: .MAKE.META.CMP_FILTER = ${CC_WRAPPERS:tu:@W@${$W}@:S,^,N,} 45 46# some object src types we should not wrap 47CC_WRAP_SKIP_EXTS += s 48 49# We add the sequence we care about - excluding CC_WRAP_SKIP_EXTS 50# but prior filters can apply to full value of .IMPSRC 51CC_WRAP_FILTER += E:tl:${CC_WRAP_SKIP_EXTS:${M_ListToSkip}} 52CC_WRAP_FILTER := ${CC_WRAP_FILTER:ts:} 53 54# last one enabled wins! 55.for W in ${CC_WRAPPERS:tu} 56.if ${MK_$W:U} == "yes" 57.for C in ${CC_WRAP_LIST} 58# we have to protect the check of .IMPSRC from Global expansion 59${CC_WRAP_TARGETS}: $C = $${"$${.IMPSRC:${CC_WRAP_FILTER}}":?${$W}:} ${$C} 60.endfor 61.endif 62.endfor 63 64.endif 65.endif 66 67