ccache.mk 2.9 KB

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