Skip to content

Commit 2ca084c

Browse files
Roman Yeryominynezz
authored andcommitted
build: improve ccache support
Set CCACHE_DIR to $(TOPDIR)/.ccache and CCACHE_BASEDIR to $(TOPDIR). This allows to do clean and dirclean. Cache hit rate for test build after dirclean is ~65%. If CCACHE is enabled stats are printed out at the end of building process. CCACHE_DIR config variable allows to override default, which could be useful when sharing cache with many builds. cacheclean make target allows to clean the cache. Changes from v1: - remove ccache directory using CCACHE_DIR variable - remove ccache leftovers from sdk and toolchain make files - introduce CONFIG_CCACHE_DIR variable - introduce cacheclean make target Signed-off-by: Roman Yeryomin <roman@advem.lv>
1 parent 23de93a commit 2ca084c

File tree

9 files changed

+29
-10
lines changed

9 files changed

+29
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ TAGS*~
2828
git-src
2929
.project
3030
.cproject
31+
.ccache

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ dirclean: clean
6262
rm -rf $(TMP_DIR)
6363
$(MAKE) -C $(TOPDIR)/scripts/config clean
6464

65+
cacheclean:
66+
ifneq ($(CONFIG_CCACHE),)
67+
rm -rf $(if $(call qstrip,$(CONFIG_CCACHE_DIR)),$(call qstrip,$(CONFIG_CCACHE_DIR)),$(TOPDIR)/.ccache)
68+
endif
69+
6570
ifndef DUMP_TARGET_DB
6671
$(BUILD_DIR)/.prepared: Makefile
6772
@mkdir -p $$(dirname $@)
@@ -119,6 +124,9 @@ world: prepare $(target/stamp-compile) $(package/stamp-compile) $(package/stamp-
119124
$(_SINGLE)$(SUBMAKE) -r package/index
120125
$(_SINGLE)$(SUBMAKE) -r json_overview_image_info
121126
$(_SINGLE)$(SUBMAKE) -r checksum
127+
ifneq ($(CONFIG_CCACHE),)
128+
$(STAGING_DIR_HOST)/bin/ccache -s
129+
endif
122130

123131
.PHONY: clean dirclean prereq prepare world package/symlinks package/symlinks-install package/symlinks-clean
124132

config/Config-devel.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ menuconfig DEVEL
6969
help
7070
Compiler cache; see https://ccache.samba.org/
7171

72+
config CCACHE_DIR
73+
string "Set ccache directory" if CCACHE
74+
default ""
75+
help
76+
Store ccache in this directory.
77+
If not set, uses './.ccache'
78+
7279
config EXTERNAL_KERNEL_TREE
7380
string "Use external kernel tree" if DEVEL
7481
default ""

include/host-build.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ define Host/Exports/Default
132132
$(1) : export STAGING_PREFIX=$$(HOST_BUILD_PREFIX)
133133
$(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig:$$(HOST_BUILD_PREFIX)/lib/pkgconfig
134134
$(1) : export PKG_CONFIG_LIBDIR=$$(HOST_BUILD_PREFIX)/lib/pkgconfig
135-
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_DIR:=$(STAGING_DIR_HOST)/ccache)
135+
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_BASEDIR:=$(TOPDIR))
136+
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_DIR:=$(if $(call qstrip,$(CONFIG_CCACHE_DIR)),$(call qstrip,$(CONFIG_CCACHE_DIR)),$(TOPDIR)/.ccache))
137+
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_COMPILERCHECK:=%compiler% -dumpmachine; %compiler% -dumpversion)
136138
$(if $(HOST_CONFIG_SITE),$(1) : export CONFIG_SITE:=$(HOST_CONFIG_SITE))
137139
$(if $(IS_PACKAGE_BUILD),$(1) : export PATH=$$(TARGET_PATH_PKG))
138140
endef

include/package.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ define Build/Exports/Default
173173
$(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
174174
$(1) : export PKG_CONFIG_PATH:=$$(PKG_CONFIG_PATH)
175175
$(1) : export PKG_CONFIG_LIBDIR:=$$(PKG_CONFIG_PATH)
176-
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_DIR:=$(STAGING_DIR)/ccache)
176+
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_BASEDIR:=$(TOPDIR))
177+
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_DIR:=$(if $(call qstrip,$(CONFIG_CCACHE_DIR)),$(call qstrip,$(CONFIG_CCACHE_DIR)),$(TOPDIR)/.ccache))
178+
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_COMPILERCHECK:=%compiler% -dumpmachine; %compiler% -dumpversion)
177179
endef
178180
Build/Exports=$(Build/Exports/Default)
179181

include/toplevel.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ package/symlinks-clean:
262262
help:
263263
cat README
264264

265-
distclean:
265+
distclean: cacheclean
266266
rm -rf bin build_dir .config* dl feeds key-build* logs package/feeds package/openwrt-packages staging_dir tmp
267267
@$(_SINGLE)$(SUBMAKE) -C scripts/config clean
268268

rules.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ ifneq ($(CONFIG_CCACHE),)
298298
TARGET_CXX:= ccache_cxx
299299
HOSTCC:= ccache $(HOSTCC)
300300
HOSTCXX:= ccache $(HOSTCXX)
301+
export CCACHE_BASEDIR:=$(TOPDIR)
302+
export CCACHE_DIR:=$(if $(call qstrip,$(CONFIG_CCACHE_DIR)),$(call qstrip,$(CONFIG_CCACHE_DIR)),$(TOPDIR)/.ccache)
303+
export CCACHE_COMPILERCHECK:=%compiler% -dumpmachine; %compiler% -dumpversion
301304
endif
302305

303306
TARGET_CONFIGURE_OPTS = \

target/sdk/Makefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ STAGING_SUBDIR_HOST := staging_dir/host
2020
STAGING_SUBDIR_TARGET := staging_dir/$(TARGET_DIR_NAME)
2121
STAGING_SUBDIR_TOOLCHAIN := staging_dir/toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)_$(LIBC)$(if $(CONFIG_arm),_eabi)
2222

23-
EXCLUDE_DIRS:=*/ccache/* \
23+
EXCLUDE_DIRS:= \
2424
*/stamp \
2525
*/stampfiles \
2626
*/man \
@@ -135,11 +135,7 @@ $(BIN_DIR)/$(SDK_NAME).tar.xz: clean
135135
$(TOPDIR)/package/kernel/linux \
136136
$(SDK_BUILD_DIR)/package/
137137

138-
-rm -rf \
139-
$(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/ccache \
140-
$(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TARGET)/ccache \
141-
$(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/ccache \
142-
$(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/.prereq-build
138+
-rm -rf $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/.prereq-build
143139

144140
-rm -f $(SDK_BUILD_DIR)/feeds.conf.default
145141
$(if $(BASE_FEED),echo "$(BASE_FEED)" > $(SDK_BUILD_DIR)/feeds.conf.default)

target/toolchain/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ override MAKEFLAGS=
1515

1616
TOOLCHAIN_NAME:=$(VERSION_DIST_SANITIZED)-toolchain-$(if $(CONFIG_VERSION_FILENAMES),$(VERSION_NUMBER)-)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))_gcc-$(GCCV)$(DIR_SUFFIX).$(HOST_OS)-$(HOST_ARCH)
1717
TOOLCHAIN_BUILD_DIR:=$(BUILD_DIR)/$(TOOLCHAIN_NAME)
18-
EXCLUDE_DIRS:=*/ccache \
18+
EXCLUDE_DIRS:= \
1919
*/initial \
2020
*/stamp \
2121
*/stampfiles \

0 commit comments

Comments
 (0)