1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00

refactor(mkdockerbuild): extracts common parts (#24)

* fixes mount of project in wrapper scripts, when not running in container

* refactors makefile in preparation to extract common parts

* refactors makefiles and scripts

* fix git ignore matches

* adds support to disable fetch

* update

* fixes docker warning about unused build argument

* adds support to force offline build

fixes shell escaping
changes paths to relative where possible

* moves make docker builder support files

* removes unnecessary configuration elements

* fixes initial download directory creation

* adds missing rule for initial download directory creation

* fixes docker error: unable to prepare context

copies dockerfile to build context, in order to remove dependency to
unsupported/new docker feature
This commit is contained in:
nosamad 2019-04-17 17:25:56 +02:00 committed by Falk Werner
parent 500353115c
commit 979ff1e689
18 changed files with 518 additions and 353 deletions

View File

@ -14,7 +14,7 @@
</extensions> </extensions>
</storageModule> </storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> <storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.2091678410" name="amd64-ubuntu" parent="org.eclipse.cdt.build.core.emptycfg"> <configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.2091678410" name="amd64-ubuntu" optionalBuildProperties="" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.base.2091678410.118484177" name="/" resourcePath=""> <folderInfo id="cdt.managedbuild.toolchain.gnu.base.2091678410.118484177" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.base.1517489953" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.base"> <toolChain id="cdt.managedbuild.toolchain.gnu.base.1517489953" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.base.971240548" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/> <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.base.971240548" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>

8
.gitignore vendored
View File

@ -1,4 +1,4 @@
.vscode /.vscode/
.build /.build/
.deps /.deps/
.settings/language.settings.xml /.settings/language.settings.xml

396
Makefile
View File

@ -1,145 +1,104 @@
MAKEFLAGS += $(_PARALLELMFLAGS) --no-builtin-rules MAKEFLAGS += $(_PARALLELMFLAGS) --no-builtin-rules
MAKEFILE := $(lastword $(MAKEFILE_LIST))
SHELL := /bin/sh
.SUFFIXES:
.PHONY: default .PHONY: default
default: all default: all
# Overridable defaults #######################################################################################################################
# Project macros
DOCKER ?= docker filter_targets = $(shell echo '$2' | sed -e 's@\s@\n@g' | sed -n$(foreach REGEX,$1, -e 's@$(REGEX)@\0@p'))
DOCKER_BUILDKIT ?=
PARALLELMFLAGS ?= regex_march_distro = '$1-$2-.*'
NPROC ?= $(shell echo '$(PARALLELMFLAGS)' | sed -n -e 's@.*-j.*\([0-9]\+\)@\1@p')
VERBOSE ?= #######################################################################################################################
BUILDVERBOSE ?= # Overridable project defaults
$(MARCH)BUILDTARGET ?= amd64-ubuntu-builder PROJECTNAME ?= webfuse
PROJECTDIR ?= $(patsubst %/,%,$(dir $(MAKEFILE)))
SCRIPTDIR ?= $(PROJECTDIR)/build/mkdocker
OUTDIR ?= $(PROJECTDIR)/.build
FETCHDIR ?= $(PROJECTDIR)/.deps
BUILDTYPE ?= Debug BUILDTYPE ?= Debug
MARCH ?= $(call march,$(BUILDTARGET))
DISTRO ?=
PROJECT_NAME ?= webfuse SKIP_FETCH ?=
PROJECT_ROOT ?= .
OUT ?= $(PROJECT_ROOT)/.build
VERSION ?= $(shell cat $(PROJECT_ROOT)/VERSION) SKIP_DEFAULT_BUILDTARGET ?= $(or $(MARCH),$(DISTRO))
VERSION := $(VERSION) $(SKIP_DEFAULT_BUILDTARGET)BUILDTARGET ?= amd64-ubuntu-builder
MARCH ?= '.*'
USERID ?= $(shell id -u) DISTRO ?= '.*'
USERID := $(USERID) FILTER ?= $(call regex_march_distro,$(MARCH),$(DISTRO))
CONTAINER_USER ?= user CONTAINER_USER ?= user
CONTAINER_GROUP ?= user CONTAINER_GROUP ?= user
CONTAINER_CGROUP_PARENT ?=
HOST_CONTAINER ?= $(shell $(PROJECT_ROOT)/build/get_container_id.sh)
HOST_CONTAINER := $(HOST_CONTAINER)
UBUNTU_CODENAME ?= bionic UBUNTU_CODENAME ?= bionic
DEBIAN_CODENAME ?= testing-slim DEBIAN_CODENAME ?= testing-slim
SOURCE_DATE_EPOCH ?= $(shell $(PROJECT_ROOT)/build/get_source_date_epoch.sh) SKIP_MD5SUM ?= $(call filter_out_command,md5sum)
SOURCE_DATE_EPOCH := $(SOURCE_DATE_EPOCH) SKIP_MD5SUM := $(SKIP_MD5SUM)
export SOURCE_DATE_EPOCH
BUILDTIME ?= $(shell date -u -d '@$(SOURCE_DATE_EPOCH)' --rfc-3339 ns 2>/dev/null | sed -e 's/ /T/')
BUILDTIME := $(BUILDTIME)
export BUILDTIME
$(HOST_CONTAINER)PORTABLE_WORSPACE ?=
CONTAINER_PROJECT_ROOT ?= /workspace/src
CONTAINER_OUT ?= /workspace/out
$(PORTABLE_WORSPACE)CONTAINER_PROJECT_ROOT = $(abspath $(PROJECT_ROOT))
$(PORTABLE_WORSPACE)CONTAINER_OUT = $(abspath $(OUT))
filter_out_command = $(filter $1,$(foreach CMD,$1,$(shell command -v $(CMD) 2>&1 1>/dev/null || echo $(CMD))))
DISABLE_MD5SUM ?= $(call filter_out_command,md5sum)
DISABLE_MD5SUM := $(DISABLE_MD5SUM)
#######################################################################################################################
# Project dependencies # Project dependencies
DUMB_INIT_VERSION ?= 1.2.2 DUMB_INIT_VERSION ?= 1.2.2
DOCKER_BUILDARGS += DUMB_INIT_VERSION=$(DUMB_INIT_VERSION) DOCKER_BUILDARGS += DUMB_INIT_VERSION=$(DUMB_INIT_VERSION)
FETCH_TARGETS += $(OUT)/dumb-init-$(DUMB_INIT_VERSION).tar.gz FETCH_TARGETS += $(FETCHDIR)/dumb-init-$(DUMB_INIT_VERSION).tar.gz
$(OUT)/dumb-init-$(DUMB_INIT_VERSION).tar.gz: URL := https://github.com/Yelp/dumb-init/archive/v${DUMB_INIT_VERSION}.tar.gz $(FETCHDIR)/dumb-init-$(DUMB_INIT_VERSION).tar.gz: URL := https://github.com/Yelp/dumb-init/archive/v${DUMB_INIT_VERSION}.tar.gz
$(DISABLE_MD5SUM)$(OUT)/dumb-init-$(DUMB_INIT_VERSION).tar.gz: MD5 := 6166084b05772cdcf615a762c6f3b32e $(SKIP_MD5SUM)$(FETCHDIR)/dumb-init-$(DUMB_INIT_VERSION).tar.gz: MD5 := 6166084b05772cdcf615a762c6f3b32e
GTEST_VERSION ?= 1.8.1 GTEST_VERSION ?= 1.8.1
DOCKER_BUILDARGS += GTEST_VERSION=$(GTEST_VERSION) DOCKER_BUILDARGS += GTEST_VERSION=$(GTEST_VERSION)
FETCH_TARGETS += $(OUT)/googletest-release-$(GTEST_VERSION).tar.gz FETCH_TARGETS += $(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz
$(OUT)/googletest-release-$(GTEST_VERSION).tar.gz: URL := https://github.com/google/googletest/archive/release-$(GTEST_VERSION).tar.gz $(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: URL := https://github.com/google/googletest/archive/release-$(GTEST_VERSION).tar.gz
$(DISABLE_MD5SUM)$(OUT)/googletest-release-$(GTEST_VERSION).tar.gz: MD5 := 2e6fbeb6a91310a16efe181886c59596 $(SKIP_MD5SUM)$(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: MD5 := 2e6fbeb6a91310a16efe181886c59596
FUSE_VERSION ?= 3.1.1 FUSE_VERSION ?= 3.1.1
DOCKER_BUILDARGS += FUSE_VERSION=$(FUSE_VERSION) DOCKER_BUILDARGS += FUSE_VERSION=$(FUSE_VERSION)
FETCH_TARGETS += $(OUT)/libfuse-fuse-$(FUSE_VERSION).tar.gz FETCH_TARGETS += $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz
$(OUT)/libfuse-fuse-$(FUSE_VERSION).tar.gz: URL := https://github.com/libfuse/libfuse/archive/fuse-$(FUSE_VERSION).tar.gz $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: URL := https://github.com/libfuse/libfuse/archive/fuse-$(FUSE_VERSION).tar.gz
$(DISABLE_MD5SUM)$(OUT)/libfuse-fuse-$(FUSE_VERSION).tar.gz: MD5 := 097f194856938afdd98bea1a5c046edd $(SKIP_MD5SUM)$(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: MD5 := 097f194856938afdd98bea1a5c046edd
WEBSOCKETS_VERSION ?= 3.1.0 WEBSOCKETS_VERSION ?= 3.1.0
DOCKER_BUILDARGS += WEBSOCKETS_VERSION=$(WEBSOCKETS_VERSION) DOCKER_BUILDARGS += WEBSOCKETS_VERSION=$(WEBSOCKETS_VERSION)
FETCH_TARGETS += $(OUT)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz FETCH_TARGETS += $(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz
$(OUT)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: URL := https://github.com/warmcat/libwebsockets/archive/v$(WEBSOCKETS_VERSION).tar.gz $(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: URL := https://github.com/warmcat/libwebsockets/archive/v$(WEBSOCKETS_VERSION).tar.gz
$(DISABLE_MD5SUM)$(OUT)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: MD5 := 325359a25d5f6d22725ff5d086db1c76 $(SKIP_MD5SUM)$(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: MD5 := 325359a25d5f6d22725ff5d086db1c76
JANSSON_VERSION ?= 2.12 JANSSON_VERSION ?= 2.12
DOCKER_BUILDARGS += JANSSON_VERSION=$(JANSSON_VERSION) DOCKER_BUILDARGS += JANSSON_VERSION=$(JANSSON_VERSION)
FETCH_TARGETS += $(OUT)/jansson-$(JANSSON_VERSION).tar.gz FETCH_TARGETS += $(FETCHDIR)/jansson-$(JANSSON_VERSION).tar.gz
$(OUT)/jansson-$(JANSSON_VERSION).tar.gz: URL := https://github.com/akheron/jansson/archive/v$(JANSSON_VERSION).tar.gz $(FETCHDIR)/jansson-$(JANSSON_VERSION).tar.gz: URL := https://github.com/akheron/jansson/archive/v$(JANSSON_VERSION).tar.gz
$(DISABLE_MD5SUM)$(OUT)/jansson-$(JANSSON_VERSION).tar.gz: MD5 := c4b106528d5ffb521178565de1ba950d $(SKIP_MD5SUM)$(FETCHDIR)/jansson-$(JANSSON_VERSION).tar.gz: MD5 := c4b106528d5ffb521178565de1ba950d
QEMU_VERSION ?= v3.1.0-2 QEMU_VERSION ?= v3.1.0-2
DOCKER_BUILDARGS += QEMU_VERSION_=$(QEMU_VERSION) DOCKER_BUILDARGS += QEMU_VERSION_=$(QEMU_VERSION)
FETCH_TARGETS += $(OUT)/docker/qemu-arm-static-$(QEMU_VERSION) FETCH_TARGETS += $(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION)
$(OUT)/docker/qemu-arm-static-$(QEMU_VERSION): URL := https://github.com/multiarch/qemu-user-static/releases/download/$(QEMU_VERSION)/qemu-arm-static $(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION): URL := https://github.com/multiarch/qemu-user-static/releases/download/$(QEMU_VERSION)/qemu-arm-static
$(DISABLE_MD5SUM)$(OUT)/docker/qemu-arm-static-$(QEMU_VERSION): MD5 := 8ebd24e63fdfa07c557d45373bd831b1 $(SKIP_MD5SUM)$(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION): MD5 := 8ebd24e63fdfa07c557d45373bd831b1
#######################################################################################################################
# Architecture-specific rule target configuration # Architecture-specific rule target configuration
march = $(shell echo '$1' | sed -n -e 's@\([^-]*\)-.*@\1@p') CMAKE_TARGETS += amd64-ubuntu-builder
CMAKE_TARGETS += amd64-debian-builder
CMAKE_TARGETS += arm32v7-ubuntu-builder
CMAKE_TARGETS += arm32v7-debian-builder
TARGETS += $(BUILDTARGET) MEMCHECK_FILTER = $(call regex_march_distro,'$(HOST_MARCH)','.*')
MARCH := $(MARCH)
DISABLE_AMD64 := $(filter-out amd64,$(MARCH)) UBUNTU_FILTER = $(call regex_march_distro,'.*','ubuntu')
$(DISABLE_AMD64)MARCHS += amd64 UBUNTU_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(UBUNTU_FILTER),$(TARGETS)))
$(DISABLE_AMD64)$(BUILDTARGET)TARGETS += amd64-ubuntu-builder DEBIAN_FILTER = $(call regex_march_distro,'.*','debian')
$(OUT)/amd64-ubuntu-builder/rules.mk: TARGET := amd64-ubuntu-builder DEBIAN_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(DEBIAN_FILTER),$(TARGETS)))
$(DISABLE_AMD64)$(BUILDTARGET)TARGETS += amd64-debian-builder
$(OUT)/amd64-debian-builder/rules.mk: TARGET := amd64-debian-builder
DISABLE_ARM32V7 := $(filter-out arm32v7,$(MARCH))
$(DISABLE_ARM32V7)MARCHS += arm32v7
$(DISABLE_ARM32V7)$(BUILDTARGET)TARGETS += arm32v7-ubuntu-builder
$(OUT)/arm32v7-ubuntu-builder/rules.mk: TARGET := arm32v7-ubuntu-builder
$(DISABLE_ARM32V7)$(BUILDTARGET)TARGETS += arm32v7-debian-builder
$(OUT)/arm32v7-debian-builder/rules.mk: TARGET := arm32v7-debian-builder
$(DISABLE_AMD64)MEMCHECK_TARGETS += $(addprefix memcheck-,$(TARGETS))
ARM_TARGETS = $(filter arm%,$(TARGETS))
$(addprefix $(OUT)/docker/,$(ARM_TARGETS)): $(OUT)/docker/qemu-arm-static-$(QEMU_VERSION)
UBUNTU_TARGETS = $(filter $(addsuffix -ubuntu%,$(MARCHS)),$(TARGETS))
$(addprefix $(OUT)/docker/,$(UBUNTU_TARGETS)): CODENAME := $(UBUNTU_CODENAME)
DEBIAN_TARGETS = $(filter $(addsuffix -debian%,$(MARCHS)),$(TARGETS))
$(addprefix $(OUT)/docker/,$(DEBIAN_TARGETS)): CODENAME := $(DEBIAN_CODENAME)
#######################################################################################################################
# Common rule target configuration # Common rule target configuration
CMAKEFLAGS += '-GNinja'
CMAKEFLAGS += '-DCMAKE_BUILD_TYPE=$(BUILDTYPE)'
BUILDSILENT := $(if $(BUILDVERBOSE),,1)
$(BUILDSILENT)NINJAFLAGS += -v
CURLFLAGS += -s CURLFLAGS += -s
DOCKER_RUNFLAGS += --device /dev/fuse DOCKER_RUNFLAGS += --device /dev/fuse
@ -149,247 +108,58 @@ DOCKER_RUNFLAGS += --security-opt apparmor:unconfined
DOCKER_RUNFLAGS += --cap-add SYS_PTRACE DOCKER_RUNFLAGS += --cap-add SYS_PTRACE
DOCKER_RUNFLAGS += --security-opt seccomp=unconfined DOCKER_RUNFLAGS += --security-opt seccomp=unconfined
DOCKER_RUNFLAGS += --user $(CONTAINER_USER):$(CONTAINER_GROUP)
DOCKER_RUNFLAGS += --env SOURCE_DATE_EPOCH
DOCKER_RUNFLAGS += --env BUILDTIME
DOCKER_RUNFLAGS += --env NINJA_STATUS
DOCKER_BUILDARGS += CODENAME=$(CODENAME) DOCKER_BUILDARGS += CODENAME=$(CODENAME)
DOCKER_BUILDARGS += PARALLELMFLAGS=$(_PARALLELMFLAGS)
DOCKER_BUILDARGS += USERID=$(USERID)
DOCKER_BUILDARGS += PROJECT_ROOT=$(CONTAINER_PROJECT_ROOT)
DOCKER_BUILDARGS += OUT=$(CONTAINER_OUT)
DOCKER_BUILDARGS += REGISTRY_PREFIX=$(REGISTRY_PREFIX)
DOCKER_BUILDFLAGS += $(addprefix --build-arg ,$(DOCKER_BUILDARGS)) OUTDIRS += $(OUTDIR)/src
OUT_TARGETS += $(addprefix $(OUT)/,$(TARGETS)) EXTRACT_TARGETS += $(OUTDIR)/docker/qemu-arm-static-$(QEMU_VERSION)
EXTRACT_TARGETS += $(patsubst $(FETCHDIR)/%.tar.gz,$(OUTDIR)/src/%,$(FETCH_TARGETS))
OUT_DIRS += $(OUT)
OUT_DIRS += $(OUT)/docker
OUT_DIRS += $(OUT)/src
OUT_DIRS += $(addsuffix /$(BUILDTYPE),$(OUT_TARGETS))
BUILD_TARGETS += $(addprefix build-,$(TARGETS))
CHECK_TARGETS += $(addprefix check-,$(TARGETS))
CLEAN_TARGETS += $(addprefix clean-,$(TARGETS))
RUN_TARGETS += $(addprefix run-,$(firstword $(TARGETS)))
EXTRACT_TARGETS += $(patsubst $(OUT)/%.tar.gz,$(OUT)/src/%,$(FETCH_TARGETS))
DISCOVER_CC_TARGETS += $(addprefix discover-cc-,$(firstword $(TARGETS)))
RULE_TARGETS += $(addsuffix /rules.mk,$(OUT_TARGETS))
uc = $(shell echo '$1' | sed -e 's/.*/\U&/g')
DISTRO_PREFIX = $(addsuffix _,$(call uc,$(DISTRO)))
MARCHS := $(sort $(MARCHS))
TARGETS := $(sort $($(DISTRO_PREFIX)TARGETS))
TASKS := $(words $(if $(TARGETS),$(TARGETS),_))
DISBALE_OSYNC ?= $(filter 1,$(TASKS))
$(DISBALE_OSYNC)GNUMAKEFLAGS += --output-sync
_NPROC = $(NPROC)
ifeq ($(strip $(_NPROC)),)
_NPROC = $(shell nproc)
endif
_PARALLELMFLAGS := $(addprefix -j,$(shell echo "$$(($(_NPROC)/$(TASKS)))"))
# Common macros
echo_if_silent = VERBOSE=1
$(VERBOSE)echo_if_silent = echo $1
$(VERBOSE)SILENT := @
curl = $(call echo_if_silent,curl -fSL $(CURLFLAGS) -o $1 $2) \
&& curl -fSL $(CURLFLAGS) -o $1 $2 \
&& { \
if [ -n "$3" ]; then \
echo "$3\t$1" > $1.md5; \
md5sum -c $1.md5; \
else \
echo 'warning:$1: no md5 skipping verification' 1>&2; \
fi; \
}
$(HOST_CONTAINER)image_run_volumes += --volume '$(realpath $(PROJECT_ROOT)):$(CONTAINER_PROJECT_ROOT):cached'
$(HOST_CONTAINER)image_run_volumes += --volume '$(realpath $(OUT)/$1):$(CONTAINER_OUT)/$1:delegated'
image_run_volumes += $(addprefix --volumes-from ,$2)
image_name = $(REGISTRY_PREFIX)$(subst -,/,$1)/$(PROJECT_NAME):$(VERSION)
image_run = $(DOCKER) run --rm --interactive $(DOCKER_RUNFLAGS) \
$(call image_run_volumes,$1,$(HOST_CONTAINER)) \
$(addprefix --cgroup-parent ,$(CONTAINER_CGROUP_PARENT)) \
--workdir '$(CONTAINER_OUT)/$1/$(BUILDTYPE)' \
$3 \
$(call image_name,$1) \
$2
image_rule = \
$$(OUT)/docker/$1: $$(OUT)/docker/$1.dockerfile $$(EXTRACT_TARGETS) $$(PROJECT_ROOT)/Makefile; \
$$(SILENT)$$(call image,$1)
image = \
$(call echo_if_silent,TARGET=$1 docker build $(call image_name,$1) $(OUT)) \
&& $(DOCKER) build --rm $(DOCKER_BUILDFLAGS) --iidfile $@ --file $< --tag $(call image_name,$1) $(OUT)
configure_rule = \
$$(OUT)/$1/$$(BUILDTYPE)/CMakeCache.txt: $$(PROJECT_ROOT)/CMakeLists.txt $$(OUT)/docker/$1 | $$(OUT)/$1/$$(BUILDTYPE)/gdbserver; \
$$(SILENT)$$(call configure,$1)
configure = \
$(call run,$1,sh -c 'cmake $(CMAKEFLAGS) $(CONTAINER_PROJECT_ROOT) && $(CONTAINER_PROJECT_ROOT)/build/discover_cc_settings.sh $(notdir $@) $(realpath $(dir $@))') \
&& touch $(addprefix $(dir $@)/,include_dirs.txt) $@
build_rule = \
build-$1: $$(OUT)/$1/$$(BUILDTYPE)/CMakeCache.txt; \
$$(SILENT)$$(call build,$1)
build = $(call run,$1,ninja $(_PARALLELMFLAGS) $(NINJAFLAGS) $(GOALS))
check_rule = \
check-$1: build-$1;
memcheck_rule = \
memcheck-$1: build-$1; \
$$(SILENT)$$(call memcheck,$1)
memcheck = $(call run,$1,ctest -T memcheck $(CTESTFLAGS))
run_rule = \
run-$1: $$(OUT)/docker/$1; \
$$(SILENT)$$(call run,$1,bash,--tty) || true
run = $(call echo_if_silent,TARGET=$1 BUILDTYPE=$(BUILDTYPE) $2) && $(call image_run,$1,$2,$3)
clean_rule = \
clean-$1: ; \
$$(SILENT)-$$(call clean,$1)
clean = rm -rf $(OUT)/$1
discover_cc_settings_rule = \
$$(OUT)/$1/$$(BUILDTYPE)/include_dirs.txt: $$(OUT)/$1/$$(BUILDTYPE)/CMakeCache.txt; \
$$(SILENT)$$(call discover_cc_settings,$1)
discover_cc_settings = \
$(call run,$1,$(CONTAINER_PROJECT_ROOT)/build/discover_cc_settings.sh $(notdir $<) $(realpath $(dir $<)))
discover_cc_rule = \
discover-cc-$1: $$(OUT)/$1/$$(BUILDTYPE)/include_dirs.txt; \
$$(SILENT)$$(call discover_cc,$1)
discover_cc = cat $<
wrapper_rule = \
$$(OUT)/$1/$$(BUILDTYPE)/gdbserver: $$(PROJECT_ROOT)/build/run_image.sh.template $$(OUT)/docker/$1; \
$$(SILENT)$$(call wrapper,$1)
wrapper = \
$(call echo_if_silent,generating $@) \
&& sed \
-e 's@%PROJECT_ROOT%@$(abspath $(PROJECT_ROOT))@g' \
-e 's@%DOCKER%@$(DOCKER)@g' \
-e 's@%RUNFLAGS%@$(DOCKER_RUNFLAGS) $(call image_run_volumes,$1)@g' \
-e 's@%IMAGE%@$(call image_name,$1)@g' \
-e 's@%RUNCMD%@$(notdir $@)@g' \
$< > $@ \
&& chmod +x $@
#######################################################################################################################
# Makefile dependencies # Makefile dependencies
MAKEDEPS += $(DOCKER) $(SKIP_FETCH)MAKEFILE_DEPS += curl
MAKEDEPS += id MAKEFILE_DEPS += gunzip
MAKEDEPS += cat MAKEFILE_DEPS += tar
MAKEDEPS += cp MAKEFILE_DEPS += chmod
MAKEDEPS += rm MAKEFILE_DEPS += touch
MAKEDEPS += mkdir MAKEFILE_DEPS += test
MAKEDEPS += sed MAKEFILE_DEPS += cp
MAKEDEPS += chmod MAKEFILE_DEPS += sed
MAKEDEPS += test
MAKEDEPS += touch
MAKEDEPS += curl
MAKEDEPS += tar
MAKEDEPS += gunzip
MISSING_MAKEDEPS += $(call filter_out_command,$(MAKEDEPS))
#######################################################################################################################
# Rules # Rules
ifneq ($(MAKECMDGOALS),distclean) include $(SCRIPTDIR)/cmake.mk
-include $(RULE_TARGETS) include $(SCRIPTDIR)/docker.mk
endif include $(SCRIPTDIR)/standardrules.mk
$(RULE_TARGETS): $(PROJECT_ROOT)/Makefile | $(MISSING_MAKEDEPS) $(OUT_DIRS)
$(SILENT) \
{ \
echo '$(call image_rule,$(TARGET))'; \
echo; \
echo '$(call configure_rule,$(TARGET))'; \
echo; \
echo '$(call build_rule,$(TARGET))'; \
echo; \
echo '$(call check_rule,$(TARGET))'; \
echo; \
echo '$(call memcheck_rule,$(TARGET))'; \
echo; \
echo '$(call run_rule,$(TARGET))'; \
echo; \
echo '$(call clean_rule,$(TARGET))'; \
echo; \
echo '$(call discover_cc_settings_rule,$(TARGET))'; \
echo; \
echo '$(call discover_cc_rule,$(TARGET))'; \
echo; \
echo '$(call wrapper_rule,$(TARGET))'; \
} > $@
.PHONY: all build-%
all: $(BUILD_TARGETS);
.PHONY: check check-%
check: $(CHECK_TARGETS);
.PHONY: memcheck memcheck-%
memcheck: $(MEMCHECK_TARGETS);
.PHONY: lint lint-%
lint: $(LINT_TARGETS);
.PHONY: run run-%
run: $(RUN_TARGETS);
.PHONY: clean clean-%
clean: $(CLEAN_TARGETS);
.PHONY: get-deps get-deps-%
get-deps: $(EXTRACT_TARGETS);
.PHONY: discover-cc discover-cc-%
discover-cc: $(DISCOVER_CC_TARGETS);
.PHONY: distclean
distclean:
$(SILENT)-rm -rf $(OUT_DIRS)
.PHONY: debug-print-%
debug-print-%:
@printf '%s\n' '$*:' $($*)
$(CHECK_TARGETS): GOALS := test $(CHECK_TARGETS): GOALS := test
$(OUT)/docker/% : $(PROJECT_ROOT)/build/% | $(OUT_DIRS) $(UBUNTU_TARGETS): CODENAME := $(UBUNTU_CODENAME)
cp $< $@
$(OUT)/docker/qemu-arm-static-$(QEMU_VERSION): $(PROJECT_ROOT)/Makefile $(DEBIAN_TARGETS): CODENAME := $(DEBIAN_CODENAME)
$(SILENT)$(call curl,$@,$(URL),$(MD5)) && chmod +x $@
$(OUT)/%.tar.gz: $(PROJECT_ROOT)/Makefile | $(OUT_DIRS) $(FETCH_TARGETS): | $(FETCHDIR)
$(SILENT)$(call curl,$@,$(URL),$(MD5)) $(SILENT)$(call curl,$@,$(URL),$(MD5))
$(OUT)/src/%: $(OUT)/%.tar.gz | $(OUT_DIRS) $(OUTDIR)/docker/%.dockerfile : $(PROJECTDIR)/build/%.dockerfile | $(OUTDIRS)
cp $< $@
$(OUTDIR)/docker/qemu-arm-static-$(QEMU_VERSION) : $(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION) | $(OUTDIRS)
$(SILENT) \
$(call echo_if_silent,cp $< $@) \
&& cp $< $@ \
&& chmod +x $@
$(OUTDIR)/src/%: $(FETCHDIR)/%.tar.gz | $(OUTDIRS)
$(SILENT) \ $(SILENT) \
$(call echo_if_silent,tar -C $(dir $@) -xf $<) \ $(call echo_if_silent,tar -C $(dir $@) -xf $<) \
&& tar -C $(dir $@) -xf $< \ && tar -C $(dir $@) -xf $< \
&& touch $@ && touch $@
$(OUT_DIRS): $(FETCHDIR):
$(SILENT)mkdir -p $@ $(SILENT)mkdir -p $@
$(MISSING_MAKEDEPS):
$(error 'required commands $(MISSING_MAKEDEPS) not found; install appropriate packages e.g. docker-ce, busybox and curl')
.DELETE_ON_ERROR: $(FETCH_TARGETS) .DELETE_ON_ERROR: $(FETCH_TARGETS)

View File

@ -90,15 +90,19 @@ ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
ARG USERID=1000 ARG USERID=1000
ARG PROJECT_ROOT=/workspace/src ARG PROJECTDIR=/workspace/src
ARG OUT=/workspace/out ARG OUTDIR=/workspace/out
ARG SCRIPTDIR=/workspace/bin
RUN set -x \ RUN set -x \
&& useradd -u "$USERID" -ms /bin/bash user \ && useradd -u "$USERID" -ms /bin/bash user \
&& mkdir -p "$PROJECT_ROOT" "$OUT" \ && mkdir -p "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" \
&& chown user:user "$PROJECT_ROOT" "$OUT" && chown user:user "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR"
WORKDIR "$OUT" WORKDIR "$OUTDIR"
ENTRYPOINT ["dumb-init", "--"] ENTRYPOINT ["dumb-init", "--"]
# unused
ARG QEMU_VERSION_=v3.1.0-2

View File

@ -90,15 +90,19 @@ ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
ARG USERID=1000 ARG USERID=1000
ARG PROJECT_ROOT=/workspace/src ARG PROJECTDIR=/workspace/src
ARG OUT=/workspace/out ARG OUTDIR=/workspace/out
ARG SCRIPTDIR=/workspace/bin
RUN set -x \ RUN set -x \
&& useradd -u "$USERID" -ms /bin/bash user \ && useradd -u "$USERID" -ms /bin/bash user \
&& mkdir -p "$PROJECT_ROOT" "$OUT" \ && mkdir -p "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" \
&& chown user:user "$PROJECT_ROOT" "$OUT" && chown user:user "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR"
WORKDIR "$OUT" WORKDIR "$OUTDIR"
ENTRYPOINT ["dumb-init", "--"] ENTRYPOINT ["dumb-init", "--"]
# unused
ARG QEMU_VERSION_=v3.1.0-2

View File

@ -93,15 +93,16 @@ ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
ARG USERID=1000 ARG USERID=1000
ARG PROJECT_ROOT=/workspace/src ARG PROJECTDIR=/workspace/src
ARG OUT=/workspace/out ARG OUTDIR=/workspace/out
ARG SCRIPTDIR=/workspace/bin
RUN set -x \ RUN set -x \
&& useradd -u "$USERID" -ms /bin/bash user \ && useradd -u "$USERID" -ms /bin/bash user \
&& mkdir -p "$PROJECT_ROOT" "$OUT" \ && mkdir -p "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" \
&& chown user:user "$PROJECT_ROOT" "$OUT" && chown user:user "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR"
WORKDIR "$OUT" WORKDIR "$OUTDIR"
ENTRYPOINT ["dumb-init", "--"] ENTRYPOINT ["dumb-init", "--"]

View File

@ -93,15 +93,16 @@ ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
ARG USERID=1000 ARG USERID=1000
ARG PROJECT_ROOT=/workspace/src ARG PROJECTDIR=/workspace/src
ARG OUT=/workspace/out ARG OUTDIR=/workspace/out
ARG SCRIPTDIR=/workspace/bin
RUN set -x \ RUN set -x \
&& useradd -u "$USERID" -ms /bin/bash user \ && useradd -u "$USERID" -ms /bin/bash user \
&& mkdir -p "$PROJECT_ROOT" "$OUT" \ && mkdir -p "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" \
&& chown user:user "$PROJECT_ROOT" "$OUT" && chown user:user "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR"
WORKDIR "$OUT" WORKDIR "$OUTDIR"
ENTRYPOINT ["dumb-init", "--"] ENTRYPOINT ["dumb-init", "--"]

View File

@ -4,12 +4,15 @@ set -e
DOCKER="${DOCKER:-docker}" DOCKER="${DOCKER:-docker}"
DOCKER_HOST="${DOCKER_HOST:-/var/run/docker.sock}" DOCKER_HOST="${DOCKER_HOST:-/var/run/docker.sock}"
IMAGE="${IMAGE:-${REGISTRY_PREFIX}docker/compose:1.24.0}" VERSION="${VERSION:-1.24.0}"
IMAGE="${IMAGE:-${REGISTRY_PREFIX}docker/compose:${VERSION}}"
NETWORK="${NETWORK:-host}" NETWORK="${NETWORK:-host}"
USERID="${USERID:-$(id -u)}" USERID="${USERID:-$(id -u)}"
SCRIPT_ROOT="${SCRIPT_ROOT:-"$(cd "$(dirname "$0")" && echo "$PWD")"}" SCRIPTDIR="${SCRIPTDIR:-"$(cd "$(dirname "$0")" && echo "$PWD")"}"
PROJECTDIR="${PROJECTDIR:-"$PWD"}"
ENTRYPOINT="${ENTRYPOINT:-docker-compose}" ENTRYPOINT="${ENTRYPOINT:-docker-compose}"
HOST_ENVFILTER="${HOST_ENVFILTER:-^DOCKER_\|^COMPOSE_}" HOST_ENVFILTER="${HOST_ENVFILTER:-^DOCKER_\|^COMPOSE_}"
PATH="${SCRIPTDIR}:$PATH"
set -- --entrypoint "$ENTRYPOINT" "$IMAGE" "$@" set -- --entrypoint "$ENTRYPOINT" "$IMAGE" "$@"
set -- --user "$USERID:$USERID" --network "$NETWORK" --workdir "$PWD" "$@" set -- --user "$USERID:$USERID" --network "$NETWORK" --workdir "$PWD" "$@"
@ -22,9 +25,11 @@ if [ -n "$CONTAINER_CGROUP_PARENT" ]; then
set -- --cgroup-parent "$CONTAINER_CGROUP_PARENT" "$@" set -- --cgroup-parent "$CONTAINER_CGROUP_PARENT" "$@"
fi fi
HOST_CONTAINER="${HOST_CONTAINER:-"$("$SCRIPT_ROOT/get_container_id.sh")"}" || true HOST_CONTAINER="${HOST_CONTAINER:-"$(get_container_id.sh)"}" || true
if [ -n "$HOST_CONTAINER" ]; then if [ -n "$HOST_CONTAINER" ]; then
set -- --volumes-from "$HOST_CONTAINER" "$@" set -- --volumes-from "$HOST_CONTAINER" "$@"
else
set -- --volume "$PROJECTDIR:$PROJECTDIR:cached" "$@"
fi fi
# setup options for connection to docker host # setup options for connection to docker host
@ -35,7 +40,7 @@ else
set -- -e DOCKER_HOST -e DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH "$@" set -- -e DOCKER_HOST -e DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH "$@"
fi fi
if [ -t 0 ] && ! "$SCRIPT_ROOT/is_running_in_bg.sh" $$; then if [ -t 0 ] && ! is_running_in_bg.sh $$; then
set -- --interactive "$@" set -- --interactive "$@"
fi fi

113
build/mkdocker/cmake.mk Normal file
View File

@ -0,0 +1,113 @@
CURRENT_MAKEFILE := $(lastword $(MAKEFILE_LIST)))
#######################################################################################################################
# Overridable CMake defaults
filter_targets ?= $2
CMAKE_BUILD_TYPE ?= $(BUILDTYPE)
CMAKE_MEMCHECK_FILTER ?= $(MEMCHECK_FILTER)
CMAKE_PROJECTDIR ?= $(CONTAINER_PROJECTDIR)
CMAKE_SCRIPTDIR ?= $(CONTAINER_SCRIPTDIR)
ifndef _INCLUDE_DEFAULTS
include $(patsubst %/,%,$(dir $(CURRENT_MAKEFILE)))/defaults.mk
endif
#######################################################################################################################
# CMake macros
cmake_configure_rule = \
$$(OUTDIR)/$1/$$(CMAKE_BUILD_TYPE)/CMakeCache.txt: $$(PROJECTDIR)/CMakeLists.txt $$(OUTDIR)/docker/$1 | $$(OUTDIR)/$1/$$(CMAKE_BUILD_TYPE)/gdbserver; \
$$(SILENT)$$(call cmake_configure,$1)
cmake_configure = \
$(call run,$1,sh -c 'cmake $(CMAKEFLAGS) $(CMAKE_PROJECTDIR) && $(CMAKE_SCRIPTDIR)/bin/cmake_discover_cc_settings.sh $(notdir $@) "$(realpath $(dir $@))"') \
&& touch $(addprefix $(dir $@)/,include_dirs.txt) $@
cmake_discover_cc_settings_rule = \
$$(OUTDIR)/$1/$$(CMAKE_BUILD_TYPE)/include_dirs.txt: $$(OUTDIR)/$1/$$(CMAKE_BUILD_TYPE)/CMakeCache.txt; \
$$(SILENT)$$(call cmake_discover_cc_settings,$1)
cmake_discover_cc_settings = \
$(call run,$1,$(CMAKE_SCRIPTDIR)/bin/cmake_discover_cc_settings.sh $(notdir $<) '$(realpath $(dir $<))')
ninja_build_rule = \
build-$1: $$(OUTDIR)/$1/$$(CMAKE_BUILD_TYPE)/CMakeCache.txt; \
$$(SILENT)$$(call ninja_build,$1)
ninja_build = $(call run,$1,ninja $(_PARALLELMFLAGS) $(NINJAFLAGS) $(GOALS))
ctest_memcheck_rule = \
memcheck-$1: build-$1; \
$$(SILENT)$$(call ctest_memcheck,$1)
ctest_memcheck = $(call run,$1,ctest -T memcheck $(CTESTFLAGS))
#######################################################################################################################
# CMake rule target configuration
$(BUILDSILENT)NINJAFLAGS += -v
DOCKER_RUNFLAGS += --env NINJA_STATUS
CMAKEFLAGS += '-GNinja'
CMAKEFLAGS += '-DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE)'
CMAKE_TARGETS := $(CMAKE_TARGETS)
CMAKE_TARGET := $(filter $(BUILDTARGET),$(CMAKE_TARGETS))
$(CMAKE_TARGET)CMAKE_ACTIVE_TARGETS += $(CMAKE_TARGETS)
CMAKE_ACTIVE_TARGETS += $(CMAKE_TARGET)
CMAKE_ACTIVE_TARGETS := $(call filter_targets,$(FILTER),$(CMAKE_ACTIVE_TARGETS))
CMAKE_BUILD_TARGETS += $(addprefix build-,$(CMAKE_ACTIVE_TARGETS))
CMAKE_CLEAN_TARGETS += $(addprefix clean-,$(CMAKE_ACTIVE_TARGETS))
CMAKE_CHECK_TARGETS += $(addprefix check-,$(CMAKE_ACTIVE_TARGETS))
CMAKE_MEMCHECK_TARGETS += $(addprefix memcheck-,$(call filter_targets,$(CMAKE_MEMCHECK_FILTER),$(CMAKE_ACTIVE_TARGETS)))
CMAKE_RUN_TARGETS += $(addprefix run-,$(firstword $(CMAKE_ACTIVE_TARGETS)))
CMAKE_DISCOVER_CC_TARGETS += $(addprefix discover-cc-,$(firstword $(CMAKE_ACTIVE_TARGETS)))
CMAKE_OUTDIRS += $(addsuffix /$(CMAKE_BUILD_TYPE),$(addprefix $(OUTDIR)/,$(CMAKE_ACTIVE_TARGETS)))
CMAKE_RULE_TARGETS += $(addsuffix /cmakerules.mk,$(OUTDIR))
BUILD_TARGETS += $(CMAKE_BUILD_TARGETS)
CHECK_TARGETS += $(CMAKE_CHECK_TARGETS)
MEMCHECK_TARGETS += $(CMAKE_MEMCHECK_TARGETS)
CLEAN_TARGETS += $(CMAKE_CLEAN_TARGETS)
RUN_TARGETS += $(CMAKE_RUN_TARGETS)
DISCOVER_CC_TARGETS += $(CMAKE_DISCOVER_CC_TARGETS)
RULE_TARGETS += $(CMAKE_RULE_TARGETS)
TARGETS += $(CMAKE_ACTIVE_TARGETS)
OUTDIRS += $(CMAKE_OUTDIRS)
#######################################################################################################################
# Makefile dependencies
MAKEFILE_DEPS += touch
MAKEFILE_DEPS += echo
#######################################################################################################################
# CMake rules
$(CMAKE_RULE_TARGETS):
$(SILENT) \
{ \
$(foreach TARGET,$(CMAKE_TARGETS),\
echo; \
echo '$(call image_rule,$(TARGET))'; \
echo; \
echo '$(call cmake_configure_rule,$(TARGET))'; \
echo; \
echo '$(call ninja_build_rule,$(TARGET))'; \
echo; \
echo '$(call check_rule,$(TARGET))'; \
echo; \
echo '$(call ctest_memcheck_rule,$(TARGET))'; \
echo; \
echo '$(call run_rule,$(TARGET))'; \
echo; \
echo '$(call clean_rule,$(TARGET))'; \
echo; \
echo '$(call cmake_discover_cc_settings_rule,$(TARGET))'; \
echo; \
echo '$(call discover_cc_rule,$(TARGET))'; \
echo; \
echo '$(call wrapper_rule,$(TARGET))'; \
) \
} > $@

View File

@ -0,0 +1,57 @@
CURRENT_MAKEFILE := $(lastword $(MAKEFILE_LIST)))
_INCLUDE_DEFAULTS := T
#######################################################################################################################
# Overridable common defaults
# NOTE: default assumes first loaded makefile is located in root directory of project
MAKEFILE ?= $(firstword $(MAKEFILE_LIST))
MAKEFILE := $(MAKEFILE)
PROJECTDIR ?= $(patsubst %/,%,$(dir $(MAKEFILE)))
SCRIPTDIR ?= $(patsubst %/,%,$(dir $(CURRENT_MAKEFILE)))
OUTDIR ?= $(PROJECTDIR)/.build
BUILDTYPE ?= Debug
BUILDVERBOSE ?=
BUILDSILENT := $(if $(BUILDVERBOSE),,1)
VERSION ?= $(shell cat $(PROJECTDIR)/VERSION)
VERSION := $(VERSION)
USERID ?= $(shell id -u)
USERID := $(USERID)
HOST_MARCH ?= $(shell dpkg --print-architecture 2>/dev/null)
HOST_CONTAINER ?= $(shell $(SCRIPTDIR)/bin/get_container_id.sh)
HOST_CONTAINER := $(HOST_CONTAINER)
$(HOST_CONTAINER)PORTABLE_WORSPACE ?=
CONTAINER_PROJECTDIR ?= /workspace/src
CONTAINER_SCRIPTDIR ?= /workspace/bin
CONTAINER_OUTDIR ?= /workspace/out
$(PORTABLE_WORSPACE)CONTAINER_PROJECTDIR = $(abspath $(PROJECTDIR))
$(PORTABLE_WORSPACE)CONTAINER_SCRIPTDIR = $(abspath $(SCRIPTDIR))
$(PORTABLE_WORSPACE)CONTAINER_OUTDIR = $(abspath $(OUTDIR))
SOURCE_DATE_EPOCH ?= $(shell $(SCRIPTDIR)/bin/get_source_date_epoch.sh)
SOURCE_DATE_EPOCH := $(SOURCE_DATE_EPOCH)
export SOURCE_DATE_EPOCH
BUILDTIME ?= $(shell date -u -d '@$(SOURCE_DATE_EPOCH)' --rfc-3339 ns 2>/dev/null | sed -e 's/ /T/')
BUILDTIME := $(BUILDTIME)
export BUILDTIME
VERBOSE ?=
PARALLELMFLAGS ?=
NPROC ?= $(shell echo '$(PARALLELMFLAGS)' | sed -n -e 's@.*-j.*\([0-9]\+\)@\1@p')
#######################################################################################################################
# Makefile dependencies
MAKEFILE_DEPS += cat
MAKEFILE_DEPS += id
MAKEFILE_DEPS += echo
MAKEFILE_DEPS += sed

87
build/mkdocker/docker.mk Normal file
View File

@ -0,0 +1,87 @@
CURRENT_MAKEFILE := $(lastword $(MAKEFILE_LIST))
#######################################################################################################################
# Overridable docker defaults
DOCKER ?= docker
DOCKER_BUILDKIT ?=
CONTAINER_CGROUP_PARENT ?=
CONTAINER_USER ?= $(USERID)
CONTAINER_GROUP ?= $(USERID)
ifndef _INCLUDE_DEFAULTS
include $(patsubst %/,%,$(dir $(CURRENT_MAKEFILE)))/defaults.mk
endif
#######################################################################################################################
# Docker macros
image_run_volumes += $(addprefix --volumes-from ,$2)
image_name = $(REGISTRY_PREFIX)$(subst -,/,$1)/$(PROJECTNAME)$(addprefix :,$(VERSION))
image_run = $(DOCKER) run --rm --interactive $(DOCKER_RUNFLAGS) \
$(call image_run_volumes,$1,$(HOST_CONTAINER)) \
$(addprefix --cgroup-parent ,$(CONTAINER_CGROUP_PARENT)) \
--workdir '$(CONTAINER_OUTDIR)/$1/$(BUILDTYPE)' \
$3 \
$(call image_name,$1) \
$2
image_rule = \
$$(OUTDIR)/docker/$1: $$(OUTDIR)/docker/$1.dockerfile $$(EXTRACT_TARGETS) $$(MAKEFILE_LIST); \
$$(SILENT)$$(call image,$1)
image = \
$(call echo_if_silent,TARGET=$1 docker build --file $< --tag $(call image_name,$1) $(OUTDIR)) \
&& $(DOCKER) build --rm $(DOCKER_BUILDFLAGS) --iidfile $@ --file $< --tag $(call image_name,$1) $(OUTDIR)
run_rule = \
run-$1: $$(OUTDIR)/docker/$1; \
$$(SILENT)$$(call run,$1,bash,--tty) || true
run = $(call echo_if_silent,TARGET=$1 $(addprefix BUILDTYPE=,$(BUILDTYPE)) $2) && $(call image_run,$1,$2,$3)
wrapper_rule = \
$$(OUTDIR)/$1/$$(BUILDTYPE)/gdbserver: $$(SCRIPTDIR)/resources/run_image.sh.template $$(OUTDIR)/docker/$1; \
$$(SILENT)$$(call wrapper,$1)
wrapper = \
$(call echo_if_silent,generating $@) \
&& sed \
-e 's@%PROJECTDIR%@$(abspath $(PROJECTDIR))@g' \
-e 's@%SCRIPTDIR%@$(abspath $(SCRIPTDIR))@g' \
-e 's@%DOCKER%@$(DOCKER)@g' \
-e 's@%RUNFLAGS%@$(DOCKER_RUNFLAGS) $(call image_run_volumes,$1)@g' \
-e 's@%IMAGE%@$(call image_name,$1)@g' \
-e 's@%RUNCMD%@$(notdir $@)@g' \
$< > $@ \
&& chmod +x $@
#######################################################################################################################
# Docker rule target configuration
DOCKER_RUNFLAGS += --env SOURCE_DATE_EPOCH
DOCKER_RUNFLAGS += --env BUILDTIME
DOCKER_RUNFLAGS += --user '$(CONTAINER_USER):$(CONTAINER_GROUP)'
DOCKER_BUILDARGS += 'USERID=$(USERID)'
DOCKER_BUILDARGS += 'PARALLELMFLAGS=$(_PARALLELMFLAGS)'
DOCKER_BUILDARGS += 'PROJECTDIR=$(CONTAINER_PROJECTDIR)'
DOCKER_BUILDARGS += 'SCRIPTDIR=$(CONTAINER_SCRIPTDIR)'
DOCKER_BUILDARGS += 'OUTDIR=$(CONTAINER_OUTDIR)'
DOCKER_BUILDARGS += 'REGISTRY_PREFIX=$(REGISTRY_PREFIX)'
DOCKER_BUILDFLAGS += $(addprefix --build-arg ,$(DOCKER_BUILDARGS))
OUTDIRS += $(OUTDIR)/docker
$(HOST_CONTAINER)image_run_volumes += --volume '$(realpath $(PROJECTDIR)):$(CONTAINER_PROJECTDIR):cached'
$(HOST_CONTAINER)image_run_volumes += --volume '$(realpath $(SCRIPTDIR)):$(CONTAINER_SCRIPTDIR):cached'
$(HOST_CONTAINER)image_run_volumes += --volume '$(realpath $(OUTDIR)/$1):$(CONTAINER_OUTDIR)/$1:delegated'
#######################################################################################################################
# Makefile dependencies
MAKEFILE_DEPS += $(DOCKER)
MAKEFILE_DEPS += sed
MAKEFILE_DEPS += chmod

View File

@ -0,0 +1 @@
%MD5% %FILE%

View File

@ -5,14 +5,10 @@ set -e
DOCKER="${DOCKER:-%DOCKER%}" DOCKER="${DOCKER:-%DOCKER%}"
IMAGE="${IMAGE:-%IMAGE%}" IMAGE="${IMAGE:-%IMAGE%}"
NETWORK="${NETWORK:-host}" NETWORK="${NETWORK:-host}"
PROJECT_ROOT="${PROJECT_ROOT:-%PROJECT_ROOT%}" PROJECTDIR="${PROJECTDIR:-%PROJECTDIR%}"
SCRIPT_ROOT="${SCRIPT_ROOT:-"$PROJECT_ROOT/build"}" SCRIPTDIR="${SCRIPTDIR:-%SCRIPTDIR%/bin}"
ENTRYPOINT="${ENTRYPOINT:-%RUNCMD%}" ENTRYPOINT="${ENTRYPOINT:-%RUNCMD%}"
PATH="${SCRIPTDIR}:$PATH"
if [ ! -d "$SCRIPT_ROOT" ]; then
echo "error:$0: $SCRIPT_ROOT not found; set project root (PROJECT_ROOT=)" 1>&2
exit 1
fi
set -- --entrypoint "$ENTRYPOINT" "$IMAGE" "$@" set -- --entrypoint "$ENTRYPOINT" "$IMAGE" "$@"
set -- --network "$NETWORK" --workdir "$PWD" "$@" set -- --network "$NETWORK" --workdir "$PWD" "$@"
@ -29,14 +25,16 @@ if [ -n "$CONTAINER_CGROUP_PARENT" ]; then
set -- --cgroup-parent "$CONTAINER_CGROUP_PARENT" "$@" set -- --cgroup-parent "$CONTAINER_CGROUP_PARENT" "$@"
fi fi
HOST_CONTAINER="${HOST_CONTAINER:-"$("$SCRIPT_ROOT/get_container_id.sh")"}" || true HOST_CONTAINER="${HOST_CONTAINER:-"$(get_container_id.sh)"}" || true
if [ -n "$HOST_CONTAINER" ]; then if [ -n "$HOST_CONTAINER" ]; then
set -- --volumes-from "$HOST_CONTAINER" "$@" set -- --volumes-from "$HOST_CONTAINER" "$@"
else
set -- --volume "$PROJECTDIR:$PROJECTDIR:cached" "$@"
fi fi
set -- %RUNFLAGS% "$@" set -- %RUNFLAGS% "$@"
if [ -t 0 ] && ! "$SCRIPT_ROOT/is_running_in_bg.sh" $$; then if [ -t 0 ] && ! is_running_in_bg.sh $$; then
set -- --interactive "$@" set -- --interactive "$@"
fi fi

View File

@ -0,0 +1,124 @@
#######################################################################################################################
# Overridable defaults
ifndef _INCLUDE_DEFAULTS
include $(patsubst %/,%,$(dir $(CURRENT_MAKEFILE)))/defaults.mk
endif
#######################################################################################################################
# Standard macros
echo_if_silent = VERBOSE=1
$(VERBOSE)echo_if_silent = echo $1
$(VERBOSE)SILENT := @
filter_out_command ?= $(filter $1,$(foreach CMD,$1,$(shell command -v $(CMD) 2>&1 1>/dev/null || echo $(CMD))))
md5sum = { \
if [ -n "$2" ]; then \
sed -e 's@%MD5%@$2@g' -e 's@%FILE%@$1@g' $(SCRIPTDIR)/resources/md5sum.txt.template > $1.md5; \
md5sum -c $1.md5; \
else \
echo 'warning:$1: no md5 skipping verification' 1>&2; \
fi; \
}
$(SKIP_FETCH)curl = $(call echo_if_silent,curl -fSL $(CURLFLAGS) -o $1 $2) \
&& curl -fSL $(CURLFLAGS) -o $1 $2 \
&& $(call md5sum,$1,$3)
curl ?= echo 'warning:$1: download skipped (SKIP_FETCH=$(SKIP_FETCH))'
check_rule = \
check-$1: build-$1;
clean_rule = \
clean-$1: ; \
$$(SILENT)-$$(call clean,$1)
clean = rm -rf $(OUTDIR)/$1
discover_cc_rule = \
discover-cc-$1: $$(OUTDIR)/$1/$$(BUILDTYPE)/include_dirs.txt; \
$$(SILENT)$$(call discover_cc,$1)
discover_cc = cat $<
#######################################################################################################################
# Standard rule target configuration
OUTDIRS += $(OUTDIR)
OUTDIRS := $(sort $(OUTDIRS))
TARGETS := $(sort $(TARGETS))
TASKS := $(words $(if $(TARGETS),$(TARGETS),_))
DISBALE_OSYNC ?= $(filter 1,$(TASKS))
$(DISBALE_OSYNC)GNUMAKEFLAGS += --output-sync
_NPROC = $(NPROC)
ifeq ($(strip $(_NPROC)),)
_NPROC = $(shell nproc)
endif
_PARALLELMFLAGS := $(addprefix -j,$(shell echo "$$(($(_NPROC)/$(TASKS)))"))
#######################################################################################################################
# Makefile dependencies
MAKEFILE_DEPS += cp
MAKEFILE_DEPS += rm
MAKEFILE_DEPS += mkdir
MAKEFILE_DEPS += echo
MAKEFILE_DEPS := $(sort $(MAKEFILE_DEPS))
UNSATISFIED_MAKEFILE_DEPS := $(call filter_out_command,$(MAKEFILE_DEPS))
RULE_TARGETS_DEPS := $(filter-out $(RULE_TARGETS) $(addprefix $(PROJECTDIR),$(RULE_TARGETS)),$(MAKEFILE_LIST))
#######################################################################################################################
# Standard rules
ifneq ($(MAKECMDGOALS),distclean)
-include $(RULE_TARGETS)
endif
.PHONY: all build-%
all: $(BUILD_TARGETS);
.PHONY: check check-%
check: $(CHECK_TARGETS);
.PHONY: memcheck memcheck-%
memcheck: $(MEMCHECK_TARGETS);
.PHONY: lint lint-%
lint: $(LINT_TARGETS);
.PHONY: run run-%
run: $(RUN_TARGETS);
.PHONY: clean clean-%
clean: $(CLEAN_TARGETS);
.PHONY: get-deps get-deps-%
get-deps: $(EXTRACT_TARGETS);
.PHONY: discover-cc discover-cc-%
discover-cc: $(DISCOVER_CC_TARGETS);
.PHONY: distclean
distclean:
$(SILENT)-rm -rf $(OUTDIRS)
.PHONY: debug-print-%
debug-print-%:
@printf '%s\n' '$*:' $($*)
$(RULE_TARGETS): $(RULE_TARGETS_DEPS) | $(UNSATISFIED_MAKEFILE_DEPS) $(OUTDIRS)
$(OUTDIRS):
$(SILENT)mkdir -p $@
$(UNSATISFIED_MAKEFILE_DEPS):
$(error 'required commands $(UNSATISFIED_MAKEFILE_DEPS) not found; install appropriate packages e.g. docker-ce, busybox and curl')