1*6eef5f0cSAntonio Huete Jimenez# $Id: cc-wrap.mk,v 1.6 2022/02/16 17:41:52 sjg Exp $ 2*6eef5f0cSAntonio Huete Jimenez# 3*6eef5f0cSAntonio Huete Jimenez# @(#) Copyright (c) 2022, Simon J. Gerraty 4*6eef5f0cSAntonio Huete Jimenez# 5*6eef5f0cSAntonio Huete Jimenez# This file is provided in the hope that it will 6*6eef5f0cSAntonio Huete Jimenez# be of use. There is absolutely NO WARRANTY. 7*6eef5f0cSAntonio Huete Jimenez# Permission to copy, redistribute or otherwise 8*6eef5f0cSAntonio Huete Jimenez# use this file is hereby granted provided that 9*6eef5f0cSAntonio Huete Jimenez# the above copyright notice and this notice are 10*6eef5f0cSAntonio Huete Jimenez# left intact. 11*6eef5f0cSAntonio Huete Jimenez# 12*6eef5f0cSAntonio Huete Jimenez# Please send copies of changes and bug-fixes to: 13*6eef5f0cSAntonio Huete Jimenez# sjg@crufty.net 14*6eef5f0cSAntonio Huete Jimenez# 15*6eef5f0cSAntonio Huete Jimenez 16*6eef5f0cSAntonio Huete Jimenez.if ${MAKE_VERSION} >= 20220126 17*6eef5f0cSAntonio Huete Jimenez# which targets are we interested in? 18*6eef5f0cSAntonio Huete JimenezCC_WRAP_TARGETS ?= ${OBJS:U} ${POBJS:U} ${SOBJS:U} 19*6eef5f0cSAntonio Huete Jimenez 20*6eef5f0cSAntonio Huete Jimenez.if !empty(CC_WRAP_TARGETS) 21*6eef5f0cSAntonio Huete Jimenez# cleanup 22*6eef5f0cSAntonio Huete Jimenez# all the target assignments below are effectively := anyway 23*6eef5f0cSAntonio Huete Jimenez# so we might as well do this once 24*6eef5f0cSAntonio Huete JimenezCC_WRAP_TARGETS := ${CC_WRAP_TARGETS:O:u} 25*6eef5f0cSAntonio Huete Jimenez 26*6eef5f0cSAntonio Huete Jimenez# what do we wrap? 27*6eef5f0cSAntonio Huete JimenezCC_WRAP_LIST += CC CXX 28*6eef5f0cSAntonio Huete JimenezCC_WRAP_LIST := ${CC_WRAP_LIST:O:u} 29*6eef5f0cSAntonio Huete Jimenez 30*6eef5f0cSAntonio Huete Jimenez# what might we wrap them with? 31*6eef5f0cSAntonio Huete JimenezCC_WRAPPERS += ccache distcc icecc 32*6eef5f0cSAntonio Huete JimenezCC_WRAPPERS := ${CC_WRAPPERS:O:u} 33*6eef5f0cSAntonio Huete Jimenez# $W can be as simple or complicated as you like (default is just $w) 34*6eef5f0cSAntonio Huete Jimenez# eg. 35*6eef5f0cSAntonio Huete Jimenez# CCACHE ?= ${CCACHE_ENV_VARS:@v@$v='${$v}'@} ${CCACHE_CMD} ${CCACHE_FLAGS} 36*6eef5f0cSAntonio Huete Jimenez# or if you want global vars to be used modifiable after this include: 37*6eef5f0cSAntonio Huete Jimenez# CCACHE ?= $${CCACHE_ENV_VARS:@v@$$v='$${$$v}'@} $${CCACHE_CMD} $${CCACHE_FLAGS} 38*6eef5f0cSAntonio Huete Jimenez.for w in ${CC_WRAPPERS} 39*6eef5f0cSAntonio Huete Jimenez${w:tu} ?= $w 40*6eef5f0cSAntonio Huete Jimenez.endfor 41*6eef5f0cSAntonio Huete Jimenez 42*6eef5f0cSAntonio Huete Jimenez# we do not want to make all these targets out-of-date 43*6eef5f0cSAntonio Huete Jimenez# just because one of the above wrappers are enabled/disabled 44*6eef5f0cSAntonio Huete Jimenez${CC_WRAP_TARGETS}: .MAKE.META.CMP_FILTER = ${CC_WRAPPERS:tu:@W@${$W}@:S,^,N,} 45*6eef5f0cSAntonio Huete Jimenez 46*6eef5f0cSAntonio Huete Jimenez# some object src types we should not wrap 47*6eef5f0cSAntonio Huete JimenezCC_WRAP_SKIP_EXTS += s 48*6eef5f0cSAntonio Huete Jimenez 49*6eef5f0cSAntonio Huete Jimenez# We add the sequence we care about - excluding CC_WRAP_SKIP_EXTS 50*6eef5f0cSAntonio Huete Jimenez# but prior filters can apply to full value of .IMPSRC 51*6eef5f0cSAntonio Huete JimenezCC_WRAP_FILTER += E:tl:${CC_WRAP_SKIP_EXTS:${M_ListToSkip}} 52*6eef5f0cSAntonio Huete JimenezCC_WRAP_FILTER := ${CC_WRAP_FILTER:ts:} 53*6eef5f0cSAntonio Huete Jimenez 54*6eef5f0cSAntonio Huete Jimenez# last one enabled wins! 55*6eef5f0cSAntonio Huete Jimenez.for W in ${CC_WRAPPERS:tu} 56*6eef5f0cSAntonio Huete Jimenez.if ${MK_$W:U} == "yes" 57*6eef5f0cSAntonio Huete Jimenez.for C in ${CC_WRAP_LIST} 58*6eef5f0cSAntonio Huete Jimenez# we have to protect the check of .IMPSRC from Global expansion 59*6eef5f0cSAntonio Huete Jimenez${CC_WRAP_TARGETS}: $C = $${"$${.IMPSRC:${CC_WRAP_FILTER}}":?${$W}:} ${$C} 60*6eef5f0cSAntonio Huete Jimenez.endfor 61*6eef5f0cSAntonio Huete Jimenez.endif 62*6eef5f0cSAntonio Huete Jimenez.endfor 63*6eef5f0cSAntonio Huete Jimenez 64*6eef5f0cSAntonio Huete Jimenez.endif 65*6eef5f0cSAntonio Huete Jimenez.endif 66*6eef5f0cSAntonio Huete Jimenez 67