xref: /freebsd/contrib/bmake/mk/cc-wrap.mk (revision c59c3bf3)
1c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause
2c59c3bf3SSimon J. Gerraty#
3c59c3bf3SSimon J. Gerraty# $Id: cc-wrap.mk,v 1.7 2024/02/17 17:26:57 sjg Exp $
49f45a3c8SSimon J. Gerraty#
59f45a3c8SSimon J. Gerraty#	@(#) Copyright (c) 2022, Simon J. Gerraty
69f45a3c8SSimon J. Gerraty#
79f45a3c8SSimon J. Gerraty#	This file is provided in the hope that it will
89f45a3c8SSimon J. Gerraty#	be of use.  There is absolutely NO WARRANTY.
99f45a3c8SSimon J. Gerraty#	Permission to copy, redistribute or otherwise
109f45a3c8SSimon J. Gerraty#	use this file is hereby granted provided that
119f45a3c8SSimon J. Gerraty#	the above copyright notice and this notice are
129f45a3c8SSimon J. Gerraty#	left intact.
139f45a3c8SSimon J. Gerraty#
149f45a3c8SSimon J. Gerraty#	Please send copies of changes and bug-fixes to:
159f45a3c8SSimon J. Gerraty#	sjg@crufty.net
169f45a3c8SSimon J. Gerraty#
179f45a3c8SSimon J. Gerraty
189f45a3c8SSimon J. Gerraty.if ${MAKE_VERSION} >= 20220126
199f45a3c8SSimon J. Gerraty# which targets are we interested in?
209f45a3c8SSimon J. GerratyCC_WRAP_TARGETS ?= ${OBJS:U} ${POBJS:U} ${SOBJS:U}
219f45a3c8SSimon J. Gerraty
229f45a3c8SSimon J. Gerraty.if !empty(CC_WRAP_TARGETS)
239f45a3c8SSimon J. Gerraty# cleanup
249f45a3c8SSimon J. Gerraty# all the target assignments below are effectively := anyway
259f45a3c8SSimon J. Gerraty# so we might as well do this once
269f45a3c8SSimon J. GerratyCC_WRAP_TARGETS := ${CC_WRAP_TARGETS:O:u}
279f45a3c8SSimon J. Gerraty
289f45a3c8SSimon J. Gerraty# what do we wrap?
299f45a3c8SSimon J. GerratyCC_WRAP_LIST += CC CXX
309f45a3c8SSimon J. GerratyCC_WRAP_LIST := ${CC_WRAP_LIST:O:u}
319f45a3c8SSimon J. Gerraty
329f45a3c8SSimon J. Gerraty# what might we wrap them with?
339f45a3c8SSimon J. GerratyCC_WRAPPERS += ccache distcc icecc
349f45a3c8SSimon J. GerratyCC_WRAPPERS := ${CC_WRAPPERS:O:u}
35a6f0e10bSSimon J. Gerraty# $W can be as simple or complicated as you like (default is just $w)
36a6f0e10bSSimon J. Gerraty# eg.
37a6f0e10bSSimon J. Gerraty# CCACHE ?= ${CCACHE_ENV_VARS:@v@$v='${$v}'@} ${CCACHE_CMD} ${CCACHE_FLAGS}
38a6f0e10bSSimon J. Gerraty# or if you want global vars to be used modifiable after this include:
39a6f0e10bSSimon J. Gerraty# CCACHE ?= $${CCACHE_ENV_VARS:@v@$$v='$${$$v}'@} $${CCACHE_CMD} $${CCACHE_FLAGS}
409f45a3c8SSimon J. Gerraty.for w in ${CC_WRAPPERS}
419f45a3c8SSimon J. Gerraty${w:tu} ?= $w
429f45a3c8SSimon J. Gerraty.endfor
439f45a3c8SSimon J. Gerraty
449f45a3c8SSimon J. Gerraty# we do not want to make all these targets out-of-date
459f45a3c8SSimon J. Gerraty# just because one of the above wrappers are enabled/disabled
46c4bf04f4SSimon J. Gerraty${CC_WRAP_TARGETS}: .MAKE.META.CMP_FILTER = ${CC_WRAPPERS:tu:@W@${$W}@:S,^,N,}
479f45a3c8SSimon J. Gerraty
489f45a3c8SSimon J. Gerraty# some object src types we should not wrap
499f45a3c8SSimon J. GerratyCC_WRAP_SKIP_EXTS += s
509f45a3c8SSimon J. Gerraty
519f45a3c8SSimon J. Gerraty# We add the sequence we care about - excluding CC_WRAP_SKIP_EXTS
529f45a3c8SSimon J. Gerraty# but prior filters can apply to full value of .IMPSRC
539f45a3c8SSimon J. GerratyCC_WRAP_FILTER += E:tl:${CC_WRAP_SKIP_EXTS:${M_ListToSkip}}
549f45a3c8SSimon J. GerratyCC_WRAP_FILTER := ${CC_WRAP_FILTER:ts:}
559f45a3c8SSimon J. Gerraty
569f45a3c8SSimon J. Gerraty# last one enabled wins!
579f45a3c8SSimon J. Gerraty.for W in ${CC_WRAPPERS:tu}
589f45a3c8SSimon J. Gerraty.if ${MK_$W:U} == "yes"
599f45a3c8SSimon J. Gerraty.for C in ${CC_WRAP_LIST}
609f45a3c8SSimon J. Gerraty# we have to protect the check of .IMPSRC from Global expansion
619f45a3c8SSimon J. Gerraty${CC_WRAP_TARGETS}: $C = $${"$${.IMPSRC:${CC_WRAP_FILTER}}":?${$W}:} ${$C}
629f45a3c8SSimon J. Gerraty.endfor
639f45a3c8SSimon J. Gerraty.endif
649f45a3c8SSimon J. Gerraty.endfor
659f45a3c8SSimon J. Gerraty
669f45a3c8SSimon J. Gerraty.endif
679f45a3c8SSimon J. Gerraty.endif
689f45a3c8SSimon J. Gerraty
69