Skip to content

Commit

Permalink
build: improve ccache support
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Roman Yeryomin authored and ynezz committed Jul 11, 2020
1 parent 23de93a commit 2ca084c
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ TAGS*~
git-src
.project
.cproject
.ccache
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ dirclean: clean
rm -rf $(TMP_DIR)
$(MAKE) -C $(TOPDIR)/scripts/config clean

cacheclean:
ifneq ($(CONFIG_CCACHE),)
rm -rf $(if $(call qstrip,$(CONFIG_CCACHE_DIR)),$(call qstrip,$(CONFIG_CCACHE_DIR)),$(TOPDIR)/.ccache)
endif

ifndef DUMP_TARGET_DB
$(BUILD_DIR)/.prepared: Makefile
@mkdir -p $$(dirname $@)
Expand Down Expand Up @@ -119,6 +124,9 @@ world: prepare $(target/stamp-compile) $(package/stamp-compile) $(package/stamp-
$(_SINGLE)$(SUBMAKE) -r package/index
$(_SINGLE)$(SUBMAKE) -r json_overview_image_info
$(_SINGLE)$(SUBMAKE) -r checksum
ifneq ($(CONFIG_CCACHE),)
$(STAGING_DIR_HOST)/bin/ccache -s
endif

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

Expand Down
7 changes: 7 additions & 0 deletions config/Config-devel.in
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ menuconfig DEVEL
help
Compiler cache; see https://ccache.samba.org/

config CCACHE_DIR
string "Set ccache directory" if CCACHE
default ""
help
Store ccache in this directory.
If not set, uses './.ccache'

config EXTERNAL_KERNEL_TREE
string "Use external kernel tree" if DEVEL
default ""
Expand Down
4 changes: 3 additions & 1 deletion include/host-build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ define Host/Exports/Default
$(1) : export STAGING_PREFIX=$$(HOST_BUILD_PREFIX)
$(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig:$$(HOST_BUILD_PREFIX)/lib/pkgconfig
$(1) : export PKG_CONFIG_LIBDIR=$$(HOST_BUILD_PREFIX)/lib/pkgconfig
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_DIR:=$(STAGING_DIR_HOST)/ccache)
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_BASEDIR:=$(TOPDIR))
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_DIR:=$(if $(call qstrip,$(CONFIG_CCACHE_DIR)),$(call qstrip,$(CONFIG_CCACHE_DIR)),$(TOPDIR)/.ccache))
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_COMPILERCHECK:=%compiler% -dumpmachine; %compiler% -dumpversion)
$(if $(HOST_CONFIG_SITE),$(1) : export CONFIG_SITE:=$(HOST_CONFIG_SITE))
$(if $(IS_PACKAGE_BUILD),$(1) : export PATH=$$(TARGET_PATH_PKG))
endef
Expand Down
4 changes: 3 additions & 1 deletion include/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ define Build/Exports/Default
$(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
$(1) : export PKG_CONFIG_PATH:=$$(PKG_CONFIG_PATH)
$(1) : export PKG_CONFIG_LIBDIR:=$$(PKG_CONFIG_PATH)
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_DIR:=$(STAGING_DIR)/ccache)
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_BASEDIR:=$(TOPDIR))
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_DIR:=$(if $(call qstrip,$(CONFIG_CCACHE_DIR)),$(call qstrip,$(CONFIG_CCACHE_DIR)),$(TOPDIR)/.ccache))
$(if $(CONFIG_CCACHE),$(1) : export CCACHE_COMPILERCHECK:=%compiler% -dumpmachine; %compiler% -dumpversion)
endef
Build/Exports=$(Build/Exports/Default)

Expand Down
2 changes: 1 addition & 1 deletion include/toplevel.mk
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ package/symlinks-clean:
help:
cat README

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

Expand Down
3 changes: 3 additions & 0 deletions rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ ifneq ($(CONFIG_CCACHE),)
TARGET_CXX:= ccache_cxx
HOSTCC:= ccache $(HOSTCC)
HOSTCXX:= ccache $(HOSTCXX)
export CCACHE_BASEDIR:=$(TOPDIR)
export CCACHE_DIR:=$(if $(call qstrip,$(CONFIG_CCACHE_DIR)),$(call qstrip,$(CONFIG_CCACHE_DIR)),$(TOPDIR)/.ccache)
export CCACHE_COMPILERCHECK:=%compiler% -dumpmachine; %compiler% -dumpversion
endif

TARGET_CONFIGURE_OPTS = \
Expand Down
8 changes: 2 additions & 6 deletions target/sdk/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ STAGING_SUBDIR_HOST := staging_dir/host
STAGING_SUBDIR_TARGET := staging_dir/$(TARGET_DIR_NAME)
STAGING_SUBDIR_TOOLCHAIN := staging_dir/toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)_$(LIBC)$(if $(CONFIG_arm),_eabi)

EXCLUDE_DIRS:=*/ccache/* \
EXCLUDE_DIRS:= \
*/stamp \
*/stampfiles \
*/man \
Expand Down Expand Up @@ -135,11 +135,7 @@ $(BIN_DIR)/$(SDK_NAME).tar.xz: clean
$(TOPDIR)/package/kernel/linux \
$(SDK_BUILD_DIR)/package/

-rm -rf \
$(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/ccache \
$(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TARGET)/ccache \
$(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/ccache \
$(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/.prereq-build
-rm -rf $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/.prereq-build

-rm -f $(SDK_BUILD_DIR)/feeds.conf.default
$(if $(BASE_FEED),echo "$(BASE_FEED)" > $(SDK_BUILD_DIR)/feeds.conf.default)
Expand Down
2 changes: 1 addition & 1 deletion target/toolchain/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ override MAKEFLAGS=

TOOLCHAIN_NAME:=$(VERSION_DIST_SANITIZED)-toolchain-$(if $(CONFIG_VERSION_FILENAMES),$(VERSION_NUMBER)-)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))_gcc-$(GCCV)$(DIR_SUFFIX).$(HOST_OS)-$(HOST_ARCH)
TOOLCHAIN_BUILD_DIR:=$(BUILD_DIR)/$(TOOLCHAIN_NAME)
EXCLUDE_DIRS:=*/ccache \
EXCLUDE_DIRS:= \
*/initial \
*/stamp \
*/stampfiles \
Expand Down

0 comments on commit 2ca084c

Please sign in to comment.