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.

Signed-off-by: Roman Yeryomin <ro...@advem.lv>
---
 .gitignore            | 1 +
 Makefile              | 3 +++
 include/host-build.mk | 4 +++-
 include/package.mk    | 4 +++-
 include/toplevel.mk   | 1 +
 rules.mk              | 3 +++
 6 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index 6549af83be..b6bfe1a525 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,3 +28,4 @@ TAGS*~
 git-src
 .project
 .cproject
+.ccache
diff --git a/Makefile b/Makefile
index 32c050bb48..dfeaf83e2c 100644
--- a/Makefile
+++ b/Makefile
@@ -119,6 +119,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
 
diff --git a/include/host-build.mk b/include/host-build.mk
index 9fc14241c6..4adac0883e 100644
--- a/include/host-build.mk
+++ b/include/host-build.mk
@@ -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:=$(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
diff --git a/include/package.mk b/include/package.mk
index 0575692742..eee5bbbf80 100644
--- a/include/package.mk
+++ b/include/package.mk
@@ -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:=$(TOPDIR)/.ccache)
+  $(if $(CONFIG_CCACHE),$(1) : export CCACHE_COMPILERCHECK:=%compiler% 
-dumpmachine; %compiler% -dumpversion)
 endef
 Build/Exports=$(Build/Exports/Default)
 
diff --git a/include/toplevel.mk b/include/toplevel.mk
index 5cf93ce7ef..f4a9dccd5e 100644
--- a/include/toplevel.mk
+++ b/include/toplevel.mk
@@ -253,6 +253,7 @@ help:
 
 distclean:
        rm -rf bin build_dir .config* dl feeds key-build* logs package/feeds 
package/openwrt-packages staging_dir tmp
+       rm -rf $(TOPDIR)/.ccache
        @$(_SINGLE)$(SUBMAKE) -C scripts/config clean
 
 ifeq ($(findstring v,$(DEBUG)),)
diff --git a/rules.mk b/rules.mk
index 66ddea2883..fb2f6bf57f 100644
--- a/rules.mk
+++ b/rules.mk
@@ -298,6 +298,9 @@ ifneq ($(CONFIG_CCACHE),)
   TARGET_CXX:= ccache_cxx
   HOSTCC:= ccache $(HOSTCC)
   HOSTCXX:= ccache $(HOSTCXX)
+  export CCACHE_BASEDIR:=$(TOPDIR)
+  export CCACHE_DIR:=$(TOPDIR)/.ccache
+  export CCACHE_COMPILERCHECK:=%compiler% -dumpmachine; %compiler% -dumpversion
 endif
 
 TARGET_CONFIGURE_OPTS = \
-- 
2.20.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to