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