2015-05-06 13:54:57 +02:00
|
|
|
export DOCKER_IMAGE ?= riot/riotbuild:latest
|
|
|
|
export DOCKER_BUILD_ROOT ?= /data/riotbuild
|
|
|
|
export DOCKER_FLAGS ?= --rm
|
|
|
|
# List of Docker-enabled make goals
|
|
|
|
export DOCKER_MAKECMDGOALS_POSSIBLE = \
|
|
|
|
all \
|
2015-05-06 13:57:40 +02:00
|
|
|
buildtest \
|
2015-07-21 11:32:47 +02:00
|
|
|
scan-build \
|
|
|
|
scan-build-analyze \
|
2016-07-14 06:15:01 +02:00
|
|
|
tests-% \
|
2015-05-06 13:54:57 +02:00
|
|
|
#
|
2016-07-14 06:14:39 +02:00
|
|
|
export DOCKER_MAKECMDGOALS = $(filter $(DOCKER_MAKECMDGOALS_POSSIBLE),$(MAKECMDGOALS))
|
2015-05-06 13:54:57 +02:00
|
|
|
|
2015-07-21 11:30:03 +02:00
|
|
|
# Docker creates the files .dockerinit and .dockerenv in the root directory of
|
|
|
|
# the container, we check for the files to determine if we are inside a container.
|
|
|
|
ifneq (,$(wildcard /.dockerinit /.dockerenv))
|
|
|
|
export INSIDE_DOCKER := 1
|
|
|
|
else
|
|
|
|
export INSIDE_DOCKER := 0
|
|
|
|
endif
|
|
|
|
|
2015-05-06 13:54:57 +02:00
|
|
|
# Default target for building inside a Docker container if nothing was given
|
|
|
|
export DOCKER_MAKECMDGOALS ?= all
|
|
|
|
# List of all exported environment variables that shall be passed on to the
|
|
|
|
# Docker container, they will only be passed if they are set from the
|
|
|
|
# environment, not if they are only default Makefile values.
|
|
|
|
export DOCKER_ENV_VARS = \
|
|
|
|
APPDIR \
|
2015-07-21 11:34:26 +02:00
|
|
|
AR \
|
|
|
|
ARFLAGS \
|
|
|
|
AS \
|
|
|
|
ASFLAGS \
|
2015-05-06 13:54:57 +02:00
|
|
|
BINDIR \
|
2015-07-21 11:34:26 +02:00
|
|
|
BINDIRBASE \
|
|
|
|
BOARD \
|
2015-05-06 13:54:57 +02:00
|
|
|
BUILDRELPATH \
|
2015-07-21 11:34:26 +02:00
|
|
|
BUILDTEST_MCU_GROUP \
|
|
|
|
BUILDTEST_VERBOSE \
|
2015-05-06 13:54:57 +02:00
|
|
|
CC \
|
|
|
|
CFLAGS \
|
2015-07-21 11:34:26 +02:00
|
|
|
CPPMIX \
|
|
|
|
CXX \
|
2015-05-06 13:54:57 +02:00
|
|
|
CXXEXFLAGS \
|
2015-07-21 11:34:26 +02:00
|
|
|
CXXUWFLAGS \
|
|
|
|
ELFFILE \
|
|
|
|
HEXFILE \
|
2015-05-06 13:54:57 +02:00
|
|
|
LINK \
|
2015-07-21 11:34:26 +02:00
|
|
|
LINKFLAGPREFIX \
|
2015-05-06 13:54:57 +02:00
|
|
|
LINKFLAGS \
|
2015-07-10 11:43:17 +02:00
|
|
|
LTO \
|
2015-05-06 13:54:57 +02:00
|
|
|
OBJCOPY \
|
|
|
|
OFLAGS \
|
2015-07-21 11:34:26 +02:00
|
|
|
PREFIX \
|
|
|
|
QUIET \
|
2015-07-21 07:05:14 +02:00
|
|
|
WERROR \
|
2015-07-21 11:34:26 +02:00
|
|
|
RIOT_VERSION \
|
|
|
|
SCANBUILD_ARGS \
|
|
|
|
SCANBUILD_OUTPUTDIR \
|
2015-05-06 13:54:57 +02:00
|
|
|
SIZE \
|
2015-07-21 11:31:17 +02:00
|
|
|
TOOLCHAIN \
|
2015-07-21 11:34:26 +02:00
|
|
|
UNDEF \
|
2015-05-06 13:54:57 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
# Find which variables were set using the command line or the environment and
|
|
|
|
# pass those to Docker.
|
|
|
|
# DOCKER_ENVIRONMENT_CMDLINE must be immediately assigned (:=) or otherwise some
|
|
|
|
# of the environment variables will be overwritten by Makefile.include and their
|
|
|
|
# origin is changed to "file"
|
|
|
|
DOCKER_ENVIRONMENT_CMDLINE := $(foreach varname,$(DOCKER_ENV_VARS), \
|
2015-07-21 11:31:17 +02:00
|
|
|
$(if $(filter environment command,$(origin $(varname))), \
|
|
|
|
-e '$(varname)=$(subst ','\'',$($(varname)))', \
|
|
|
|
))
|
2015-05-06 13:54:57 +02:00
|
|
|
DOCKER_ENVIRONMENT_CMDLINE := $(strip $(DOCKER_ENVIRONMENT_CMDLINE))
|
2015-07-10 12:02:06 +02:00
|
|
|
# The variables set on the command line will also be passed on the command line
|
|
|
|
# in Docker
|
|
|
|
DOCKER_OVERRIDE_CMDLINE := $(foreach varname,$(DOCKER_ENV_VARS), \
|
|
|
|
$(if $(filter command,$(origin $(varname))), \
|
|
|
|
'$(varname)=$($(varname))', \
|
|
|
|
))
|
|
|
|
DOCKER_OVERRIDE_CMDLINE := $(strip $(DOCKER_OVERRIDE_CMDLINE))
|
2015-05-06 13:54:57 +02:00
|
|
|
|
2018-07-25 17:29:04 +02:00
|
|
|
# Overwrite if you want to use `docker` with sudo
|
|
|
|
DOCKER ?= docker
|
|
|
|
|
2015-05-06 13:54:57 +02:00
|
|
|
# This will execute `make $(DOCKER_MAKECMDGOALS)` inside a Docker container.
|
|
|
|
# We do not push the regular $(MAKECMDGOALS) to the container's make command in
|
|
|
|
# order to only perform building inside the container and defer executing any
|
|
|
|
# extra commands such as flashing or debugging until after leaving the
|
|
|
|
# container.
|
|
|
|
# The `flash`, `term`, `debugserver` etc. targets usually require access to
|
|
|
|
# hardware which may not be reachable from inside the container.
|
|
|
|
..in-docker-container:
|
2018-03-22 16:20:19 +01:00
|
|
|
@$(COLOR_ECHO) '$(COLOR_GREEN)Launching build container using image "$(DOCKER_IMAGE)".$(COLOR_RESET)'
|
2018-07-25 17:29:04 +02:00
|
|
|
$(DOCKER) run $(DOCKER_FLAGS) -t -u "$$(id -u)" \
|
2015-05-06 13:54:57 +02:00
|
|
|
-v '$(RIOTBASE):$(DOCKER_BUILD_ROOT)/riotbase' \
|
|
|
|
-v '$(RIOTCPU):$(DOCKER_BUILD_ROOT)/riotcpu' \
|
|
|
|
-v '$(RIOTBOARD):$(DOCKER_BUILD_ROOT)/riotboard' \
|
2016-01-27 10:47:12 +01:00
|
|
|
-v '$(RIOTMAKE):$(DOCKER_BUILD_ROOT)/riotmake' \
|
2015-05-06 13:54:57 +02:00
|
|
|
-v '$(RIOTPROJECT):$(DOCKER_BUILD_ROOT)/riotproject' \
|
2015-07-21 11:31:38 +02:00
|
|
|
-v /etc/localtime:/etc/localtime:ro \
|
2015-05-06 13:54:57 +02:00
|
|
|
-e 'RIOTBASE=$(DOCKER_BUILD_ROOT)/riotbase' \
|
2015-08-14 00:31:36 +02:00
|
|
|
-e 'CCACHE_BASEDIR=$(DOCKER_BUILD_ROOT)/riotbase' \
|
2015-05-06 13:54:57 +02:00
|
|
|
-e 'RIOTCPU=$(DOCKER_BUILD_ROOT)/riotcpu' \
|
|
|
|
-e 'RIOTBOARD=$(DOCKER_BUILD_ROOT)/riotboard' \
|
2016-01-27 10:47:12 +01:00
|
|
|
-e 'RIOTMAKE=$(DOCKER_BUILD_ROOT)/riotmake' \
|
2015-05-06 13:54:57 +02:00
|
|
|
-e 'RIOTPROJECT=$(DOCKER_BUILD_ROOT)/riotproject' \
|
|
|
|
$(DOCKER_ENVIRONMENT_CMDLINE) \
|
|
|
|
-w '$(DOCKER_BUILD_ROOT)/riotproject/$(BUILDRELPATH)' \
|
2015-07-10 12:02:06 +02:00
|
|
|
'$(DOCKER_IMAGE)' make $(DOCKER_MAKECMDGOALS) $(DOCKER_OVERRIDE_CMDLINE)
|