diff --git a/Makefile.docker b/Makefile.docker
index 02b087b1ded254e0c600a2407ab72e2f9a8838d0..725656d482e8af84a9483f1f1091647d6e5619cd 100644
--- a/Makefile.docker
+++ b/Makefile.docker
@@ -86,6 +86,7 @@ DOCKER_ENVIRONMENT_CMDLINE := $(strip $(DOCKER_ENVIRONMENT_CMDLINE))
 	    -v '$(RIOTPROJECT):$(DOCKER_BUILD_ROOT)/riotproject' \
 	    -v /etc/localtime:/etc/localtime:ro \
 	    -e 'RIOTBASE=$(DOCKER_BUILD_ROOT)/riotbase' \
+	    -e 'CCACHE_BASEDIR=$(DOCKER_BUILD_ROOT)/riotbase' \
 	    -e 'RIOTCPU=$(DOCKER_BUILD_ROOT)/riotcpu' \
 	    -e 'RIOTBOARD=$(DOCKER_BUILD_ROOT)/riotboard' \
 	    -e 'RIOTPROJECT=$(DOCKER_BUILD_ROOT)/riotproject' \
diff --git a/Makefile.include b/Makefile.include
index 013c80be18ad69b0909a99fd1916de24ad67bec2..da21c6a2cf37ebc6576ab00236643454da170327 100644
--- a/Makefile.include
+++ b/Makefile.include
@@ -4,6 +4,8 @@ all:
 RIOTBASE ?= $(shell dirname "$(lastword $(MAKEFILE_LIST))")
 RIOTBASE := $(abspath $(RIOTBASE))
 
+CCACHE_BASEDIR := $(RIOTBASE)
+
 RIOTCPU ?= $(RIOTBASE)/cpu
 RIOTCPU := $(abspath $(RIOTCPU))
 
diff --git a/Makefile.vars b/Makefile.vars
index 2b67ff7fe731f6c640c9c5a309017501ea8078e4..56cad8ebb5ba567d356894b68cab85ef94fb826e 100644
--- a/Makefile.vars
+++ b/Makefile.vars
@@ -53,6 +53,9 @@ export DEBUGSERVER_FLAGS     # The parameters to supply to DEBUGSERVER.
 export RESET                 # The command to call on "make reset", this command resets/reboots the target.
 export RESET_FLAGS           # The parameters to supply to RESET.
 
+export CCACHE_BASEDIR        # ccache basedir, allows multiple riot build
+                             # directories to share a ccache directory
+
 export DOWNLOAD_TO_FILE      # Use `$(DOWNLOAD_TO_FILE) $(DESTINATION) $(URL)` to download `$(URL)` to `$(DESTINATION)`.
 export DOWNLOAD_TO_STDOUT    # Use `$(DOWNLOAD_TO_STDOUT) $(URL)` to download `$(URL)` output `$(URL)` to stdout, e.g. to be piped into `tar xz`.
 export UNZIP_HERE            # Use `cd $(SOME_FOLDER) && $(UNZIP_HERE) $(SOME_FILE)` to extract the contents of the zip file `$(SOME_FILE)` into `$(SOME_FOLDER)`.