Add support to build with ccache in the build system
[coreboot.git] / Makefile
index f2fa6fc313f0f7039918b9c9ba779a45b49318c6..2e594e3ffde714424dcaa0d40bcdd28091d0b5b7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -61,6 +61,7 @@ endif
 endif
 
 CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
+ROMCC:= $(obj)/romcc
 HOSTCC = gcc
 HOSTCXX = g++
 HOSTCFLAGS := -I$(srck) -I$(objk) -g
@@ -85,6 +86,17 @@ HOSTCC:=clang
 endif
 endif
 
+ifeq ($(CONFIG_CCACHE),y)
+CCACHE:=CCACHE_COMPILERCHECK=content $(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH))))
+ifeq ($(CCACHE),)
+$(error ccache selected, but not found in PATH)
+endif
+CC := $(CCACHE) $(CC)
+HOSTCC := $(CCACHE) $(HOSTCC)
+HOSTCXX := $(CCACHE) $(HOSTCXX)
+ROMCC := $(CCACHE) $(ROMCC)
+endif
+
 strip_quotes = $(subst ",,$(subst \",,$(1)))
 
 ARCHDIR-$(CONFIG_ARCH_X86)    := i386