xref: /OK3568_Linux_fs/buildroot/package/ccache/ccache.mk (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun################################################################################
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# ccache
4*4882a593Smuzhiyun#
5*4882a593Smuzhiyun################################################################################
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunCCACHE_VERSION = 3.7.12
8*4882a593SmuzhiyunCCACHE_SITE = https://github.com/ccache/ccache/releases/download/v$(CCACHE_VERSION)
9*4882a593SmuzhiyunCCACHE_SOURCE = ccache-$(CCACHE_VERSION).tar.xz
10*4882a593SmuzhiyunCCACHE_LICENSE = GPL-3.0+, others
11*4882a593SmuzhiyunCCACHE_LICENSE_FILES = LICENSE.adoc GPL-3.0.txt
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun# Force ccache to use its internal zlib. The problem is that without
14*4882a593Smuzhiyun# this, ccache would link against the zlib of the build system, but we
15*4882a593Smuzhiyun# might build and install a different version of zlib in $(O)/host
16*4882a593Smuzhiyun# afterwards, which ccache will pick up. This might break if there is
17*4882a593Smuzhiyun# a version mismatch. A solution would be to add host-zlib has a
18*4882a593Smuzhiyun# dependency of ccache, but it would require tuning the zlib .mk file
19*4882a593Smuzhiyun# to use HOSTCC_NOCCACHE as the compiler. Instead, we take the easy
20*4882a593Smuzhiyun# path: tell ccache to use its internal copy of zlib, so that ccache
21*4882a593Smuzhiyun# has zero dependency besides the C library.
22*4882a593SmuzhiyunHOST_CCACHE_CONF_OPTS += --with-bundled-zlib
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun# We are ccache, so we can't use ccache
25*4882a593SmuzhiyunHOST_CCACHE_CONF_ENV = \
26*4882a593Smuzhiyun	CC="$(HOSTCC_NOCCACHE)" \
27*4882a593Smuzhiyun	CXX="$(HOSTCXX_NOCCACHE)"
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun# Patch host-ccache as follows:
30*4882a593Smuzhiyun#  - Use BR_CACHE_DIR instead of CCACHE_DIR, because CCACHE_DIR
31*4882a593Smuzhiyun#    is already used by autotargets for the ccache package.
32*4882a593Smuzhiyun#    BR_CACHE_DIR is exported by Makefile based on config option
33*4882a593Smuzhiyun#    BR2_CCACHE_DIR.
34*4882a593Smuzhiyun#  - Change hard-coded last-ditch default to match path in .config, to avoid
35*4882a593Smuzhiyun#    the need to specify BR_CACHE_DIR when invoking ccache directly.
36*4882a593Smuzhiyun#    CCache replaces "%s" with the home directory of the current user,
37*4882a593Smuzhiyun#    So rewrite BR_CACHE_DIR to take that into consideration for SDK purpose
38*4882a593SmuzhiyunHOST_CCACHE_DEFAULT_CCACHE_DIR = $(patsubst $(HOME)/%,\%s/%,$(BR_CACHE_DIR))
39*4882a593Smuzhiyun
40*4882a593Smuzhiyundefine HOST_CCACHE_PATCH_CONFIGURATION
41*4882a593Smuzhiyun	sed -i 's,getenv("CCACHE_DIR"),getenv("BR_CACHE_DIR"),' $(@D)/src/ccache.c
42*4882a593Smuzhiyun	sed -i 's,"%s/.ccache","$(HOST_CCACHE_DEFAULT_CCACHE_DIR)",' $(@D)/src/conf.c
43*4882a593Smuzhiyunendef
44*4882a593Smuzhiyun
45*4882a593SmuzhiyunHOST_CCACHE_POST_PATCH_HOOKS += HOST_CCACHE_PATCH_CONFIGURATION
46*4882a593Smuzhiyun
47*4882a593Smuzhiyundefine HOST_CCACHE_MAKE_CACHE_DIR
48*4882a593Smuzhiyun	mkdir -p $(BR_CACHE_DIR)
49*4882a593Smuzhiyunendef
50*4882a593Smuzhiyun
51*4882a593SmuzhiyunHOST_CCACHE_POST_INSTALL_HOOKS += HOST_CCACHE_MAKE_CACHE_DIR
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun# Provide capability to do initial ccache setup (e.g. increase default size)
54*4882a593SmuzhiyunBR_CCACHE_INITIAL_SETUP = $(call qstrip,$(BR2_CCACHE_INITIAL_SETUP))
55*4882a593Smuzhiyunifneq ($(BR_CCACHE_INITIAL_SETUP),)
56*4882a593Smuzhiyundefine HOST_CCACHE_DO_INITIAL_SETUP
57*4882a593Smuzhiyun	@$(call MESSAGE,"Applying initial settings")
58*4882a593Smuzhiyun	$(CCACHE) $(BR_CCACHE_INITIAL_SETUP)
59*4882a593Smuzhiyun	$(CCACHE) -s
60*4882a593Smuzhiyunendef
61*4882a593Smuzhiyun
62*4882a593SmuzhiyunHOST_CCACHE_POST_INSTALL_HOOKS += HOST_CCACHE_DO_INITIAL_SETUP
63*4882a593Smuzhiyunendif
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun$(eval $(host-autotools-package))
66*4882a593Smuzhiyun
67*4882a593Smuzhiyunifeq ($(BR2_CCACHE),y)
68*4882a593Smuzhiyunccache-stats: host-ccache
69*4882a593Smuzhiyun	$(Q)$(CCACHE) -s
70*4882a593Smuzhiyun
71*4882a593Smuzhiyunccache-options: host-ccache
72*4882a593Smuzhiyunifeq ($(CCACHE_OPTIONS),)
73*4882a593Smuzhiyun	$(Q)echo "Usage: make ccache-options CCACHE_OPTIONS=\"opts\""
74*4882a593Smuzhiyun	$(Q)echo "where 'opts' corresponds to one or more valid ccache options" \
75*4882a593Smuzhiyun	"(see ccache help text below)"
76*4882a593Smuzhiyun	$(Q)echo
77*4882a593Smuzhiyunendif
78*4882a593Smuzhiyun	$(Q)$(CCACHE) $(CCACHE_OPTIONS)
79*4882a593Smuzhiyunendif
80