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:
parent
500353115c
commit
979ff1e689
@ -14,7 +14,7 @@
|
||||
</extensions>
|
||||
</storageModule>
|
||||
<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="">
|
||||
<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"/>
|
||||
|
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
.vscode
|
||||
.build
|
||||
.deps
|
||||
.settings/language.settings.xml
|
||||
/.vscode/
|
||||
/.build/
|
||||
/.deps/
|
||||
/.settings/language.settings.xml
|
||||
|
396
Makefile
396
Makefile
@ -1,145 +1,104 @@
|
||||
MAKEFLAGS += $(_PARALLELMFLAGS) --no-builtin-rules
|
||||
MAKEFILE := $(lastword $(MAKEFILE_LIST))
|
||||
SHELL := /bin/sh
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
.PHONY: default
|
||||
default: all
|
||||
|
||||
# Overridable defaults
|
||||
#######################################################################################################################
|
||||
# Project macros
|
||||
|
||||
DOCKER ?= docker
|
||||
DOCKER_BUILDKIT ?=
|
||||
filter_targets = $(shell echo '$2' | sed -e 's@\s@\n@g' | sed -n$(foreach REGEX,$1, -e 's@$(REGEX)@\0@p'))
|
||||
|
||||
PARALLELMFLAGS ?=
|
||||
NPROC ?= $(shell echo '$(PARALLELMFLAGS)' | sed -n -e 's@.*-j.*\([0-9]\+\)@\1@p')
|
||||
regex_march_distro = '$1-$2-.*'
|
||||
|
||||
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
|
||||
MARCH ?= $(call march,$(BUILDTARGET))
|
||||
DISTRO ?=
|
||||
|
||||
PROJECT_NAME ?= webfuse
|
||||
PROJECT_ROOT ?= .
|
||||
OUT ?= $(PROJECT_ROOT)/.build
|
||||
SKIP_FETCH ?=
|
||||
|
||||
VERSION ?= $(shell cat $(PROJECT_ROOT)/VERSION)
|
||||
VERSION := $(VERSION)
|
||||
|
||||
USERID ?= $(shell id -u)
|
||||
USERID := $(USERID)
|
||||
SKIP_DEFAULT_BUILDTARGET ?= $(or $(MARCH),$(DISTRO))
|
||||
$(SKIP_DEFAULT_BUILDTARGET)BUILDTARGET ?= amd64-ubuntu-builder
|
||||
MARCH ?= '.*'
|
||||
DISTRO ?= '.*'
|
||||
FILTER ?= $(call regex_march_distro,$(MARCH),$(DISTRO))
|
||||
|
||||
CONTAINER_USER ?= user
|
||||
CONTAINER_GROUP ?= user
|
||||
CONTAINER_CGROUP_PARENT ?=
|
||||
|
||||
HOST_CONTAINER ?= $(shell $(PROJECT_ROOT)/build/get_container_id.sh)
|
||||
HOST_CONTAINER := $(HOST_CONTAINER)
|
||||
|
||||
UBUNTU_CODENAME ?= bionic
|
||||
DEBIAN_CODENAME ?= testing-slim
|
||||
|
||||
SOURCE_DATE_EPOCH ?= $(shell $(PROJECT_ROOT)/build/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
|
||||
|
||||
$(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)
|
||||
SKIP_MD5SUM ?= $(call filter_out_command,md5sum)
|
||||
SKIP_MD5SUM := $(SKIP_MD5SUM)
|
||||
|
||||
#######################################################################################################################
|
||||
# Project dependencies
|
||||
|
||||
DUMB_INIT_VERSION ?= 1.2.2
|
||||
DOCKER_BUILDARGS += DUMB_INIT_VERSION=$(DUMB_INIT_VERSION)
|
||||
FETCH_TARGETS += $(OUT)/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
|
||||
$(DISABLE_MD5SUM)$(OUT)/dumb-init-$(DUMB_INIT_VERSION).tar.gz: MD5 := 6166084b05772cdcf615a762c6f3b32e
|
||||
FETCH_TARGETS += $(FETCHDIR)/dumb-init-$(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
|
||||
$(SKIP_MD5SUM)$(FETCHDIR)/dumb-init-$(DUMB_INIT_VERSION).tar.gz: MD5 := 6166084b05772cdcf615a762c6f3b32e
|
||||
|
||||
GTEST_VERSION ?= 1.8.1
|
||||
DOCKER_BUILDARGS += GTEST_VERSION=$(GTEST_VERSION)
|
||||
FETCH_TARGETS += $(OUT)/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
|
||||
$(DISABLE_MD5SUM)$(OUT)/googletest-release-$(GTEST_VERSION).tar.gz: MD5 := 2e6fbeb6a91310a16efe181886c59596
|
||||
FETCH_TARGETS += $(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz
|
||||
$(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: URL := https://github.com/google/googletest/archive/release-$(GTEST_VERSION).tar.gz
|
||||
$(SKIP_MD5SUM)$(FETCHDIR)/googletest-release-$(GTEST_VERSION).tar.gz: MD5 := 2e6fbeb6a91310a16efe181886c59596
|
||||
|
||||
FUSE_VERSION ?= 3.1.1
|
||||
DOCKER_BUILDARGS += FUSE_VERSION=$(FUSE_VERSION)
|
||||
FETCH_TARGETS += $(OUT)/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
|
||||
$(DISABLE_MD5SUM)$(OUT)/libfuse-fuse-$(FUSE_VERSION).tar.gz: MD5 := 097f194856938afdd98bea1a5c046edd
|
||||
FETCH_TARGETS += $(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz
|
||||
$(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: URL := https://github.com/libfuse/libfuse/archive/fuse-$(FUSE_VERSION).tar.gz
|
||||
$(SKIP_MD5SUM)$(FETCHDIR)/libfuse-fuse-$(FUSE_VERSION).tar.gz: MD5 := 097f194856938afdd98bea1a5c046edd
|
||||
|
||||
WEBSOCKETS_VERSION ?= 3.1.0
|
||||
DOCKER_BUILDARGS += WEBSOCKETS_VERSION=$(WEBSOCKETS_VERSION)
|
||||
FETCH_TARGETS += $(OUT)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz
|
||||
$(OUT)/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
|
||||
FETCH_TARGETS += $(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz
|
||||
$(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: URL := https://github.com/warmcat/libwebsockets/archive/v$(WEBSOCKETS_VERSION).tar.gz
|
||||
$(SKIP_MD5SUM)$(FETCHDIR)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: MD5 := 325359a25d5f6d22725ff5d086db1c76
|
||||
|
||||
JANSSON_VERSION ?= 2.12
|
||||
DOCKER_BUILDARGS += JANSSON_VERSION=$(JANSSON_VERSION)
|
||||
FETCH_TARGETS += $(OUT)/jansson-$(JANSSON_VERSION).tar.gz
|
||||
$(OUT)/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
|
||||
FETCH_TARGETS += $(FETCHDIR)/jansson-$(JANSSON_VERSION).tar.gz
|
||||
$(FETCHDIR)/jansson-$(JANSSON_VERSION).tar.gz: URL := https://github.com/akheron/jansson/archive/v$(JANSSON_VERSION).tar.gz
|
||||
$(SKIP_MD5SUM)$(FETCHDIR)/jansson-$(JANSSON_VERSION).tar.gz: MD5 := c4b106528d5ffb521178565de1ba950d
|
||||
|
||||
QEMU_VERSION ?= v3.1.0-2
|
||||
DOCKER_BUILDARGS += QEMU_VERSION_=$(QEMU_VERSION)
|
||||
FETCH_TARGETS += $(OUT)/docker/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
|
||||
$(DISABLE_MD5SUM)$(OUT)/docker/qemu-arm-static-$(QEMU_VERSION): MD5 := 8ebd24e63fdfa07c557d45373bd831b1
|
||||
FETCH_TARGETS += $(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION)
|
||||
$(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION): URL := https://github.com/multiarch/qemu-user-static/releases/download/$(QEMU_VERSION)/qemu-arm-static
|
||||
$(SKIP_MD5SUM)$(FETCHDIR)/qemu-arm-static-$(QEMU_VERSION): MD5 := 8ebd24e63fdfa07c557d45373bd831b1
|
||||
|
||||
#######################################################################################################################
|
||||
# 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)
|
||||
MARCH := $(MARCH)
|
||||
MEMCHECK_FILTER = $(call regex_march_distro,'$(HOST_MARCH)','.*')
|
||||
|
||||
DISABLE_AMD64 := $(filter-out amd64,$(MARCH))
|
||||
$(DISABLE_AMD64)MARCHS += amd64
|
||||
UBUNTU_FILTER = $(call regex_march_distro,'.*','ubuntu')
|
||||
UBUNTU_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(UBUNTU_FILTER),$(TARGETS)))
|
||||
|
||||
$(DISABLE_AMD64)$(BUILDTARGET)TARGETS += amd64-ubuntu-builder
|
||||
$(OUT)/amd64-ubuntu-builder/rules.mk: TARGET := amd64-ubuntu-builder
|
||||
|
||||
$(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)
|
||||
DEBIAN_FILTER = $(call regex_march_distro,'.*','debian')
|
||||
DEBIAN_TARGETS = $(addprefix $(OUTDIR)/docker/,$(call filter_targets,$(DEBIAN_FILTER),$(TARGETS)))
|
||||
|
||||
#######################################################################################################################
|
||||
# Common rule target configuration
|
||||
|
||||
CMAKEFLAGS += '-GNinja'
|
||||
CMAKEFLAGS += '-DCMAKE_BUILD_TYPE=$(BUILDTYPE)'
|
||||
|
||||
BUILDSILENT := $(if $(BUILDVERBOSE),,1)
|
||||
$(BUILDSILENT)NINJAFLAGS += -v
|
||||
|
||||
CURLFLAGS += -s
|
||||
|
||||
DOCKER_RUNFLAGS += --device /dev/fuse
|
||||
@ -149,247 +108,58 @@ DOCKER_RUNFLAGS += --security-opt apparmor:unconfined
|
||||
DOCKER_RUNFLAGS += --cap-add SYS_PTRACE
|
||||
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 += 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))
|
||||
|
||||
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 $@
|
||||
EXTRACT_TARGETS += $(OUTDIR)/docker/qemu-arm-static-$(QEMU_VERSION)
|
||||
EXTRACT_TARGETS += $(patsubst $(FETCHDIR)/%.tar.gz,$(OUTDIR)/src/%,$(FETCH_TARGETS))
|
||||
|
||||
#######################################################################################################################
|
||||
# Makefile dependencies
|
||||
|
||||
MAKEDEPS += $(DOCKER)
|
||||
MAKEDEPS += id
|
||||
MAKEDEPS += cat
|
||||
MAKEDEPS += cp
|
||||
MAKEDEPS += rm
|
||||
MAKEDEPS += mkdir
|
||||
MAKEDEPS += sed
|
||||
MAKEDEPS += chmod
|
||||
MAKEDEPS += test
|
||||
MAKEDEPS += touch
|
||||
MAKEDEPS += curl
|
||||
MAKEDEPS += tar
|
||||
MAKEDEPS += gunzip
|
||||
|
||||
MISSING_MAKEDEPS += $(call filter_out_command,$(MAKEDEPS))
|
||||
$(SKIP_FETCH)MAKEFILE_DEPS += curl
|
||||
MAKEFILE_DEPS += gunzip
|
||||
MAKEFILE_DEPS += tar
|
||||
MAKEFILE_DEPS += chmod
|
||||
MAKEFILE_DEPS += touch
|
||||
MAKEFILE_DEPS += test
|
||||
MAKEFILE_DEPS += cp
|
||||
MAKEFILE_DEPS += sed
|
||||
|
||||
#######################################################################################################################
|
||||
# Rules
|
||||
|
||||
ifneq ($(MAKECMDGOALS),distclean)
|
||||
-include $(RULE_TARGETS)
|
||||
endif
|
||||
|
||||
$(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' '$*:' $($*)
|
||||
include $(SCRIPTDIR)/cmake.mk
|
||||
include $(SCRIPTDIR)/docker.mk
|
||||
include $(SCRIPTDIR)/standardrules.mk
|
||||
|
||||
$(CHECK_TARGETS): GOALS := test
|
||||
|
||||
$(OUT)/docker/% : $(PROJECT_ROOT)/build/% | $(OUT_DIRS)
|
||||
cp $< $@
|
||||
$(UBUNTU_TARGETS): CODENAME := $(UBUNTU_CODENAME)
|
||||
|
||||
$(OUT)/docker/qemu-arm-static-$(QEMU_VERSION): $(PROJECT_ROOT)/Makefile
|
||||
$(SILENT)$(call curl,$@,$(URL),$(MD5)) && chmod +x $@
|
||||
$(DEBIAN_TARGETS): CODENAME := $(DEBIAN_CODENAME)
|
||||
|
||||
$(OUT)/%.tar.gz: $(PROJECT_ROOT)/Makefile | $(OUT_DIRS)
|
||||
$(FETCH_TARGETS): | $(FETCHDIR)
|
||||
$(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) \
|
||||
$(call echo_if_silent,tar -C $(dir $@) -xf $<) \
|
||||
&& tar -C $(dir $@) -xf $< \
|
||||
&& touch $@
|
||||
|
||||
$(OUT_DIRS):
|
||||
$(FETCHDIR):
|
||||
$(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)
|
||||
|
||||
|
@ -90,15 +90,19 @@ ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
|
||||
|
||||
ARG USERID=1000
|
||||
|
||||
ARG PROJECT_ROOT=/workspace/src
|
||||
ARG OUT=/workspace/out
|
||||
ARG PROJECTDIR=/workspace/src
|
||||
ARG OUTDIR=/workspace/out
|
||||
ARG SCRIPTDIR=/workspace/bin
|
||||
|
||||
RUN set -x \
|
||||
&& useradd -u "$USERID" -ms /bin/bash user \
|
||||
&& mkdir -p "$PROJECT_ROOT" "$OUT" \
|
||||
&& chown user:user "$PROJECT_ROOT" "$OUT"
|
||||
&& mkdir -p "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" \
|
||||
&& chown user:user "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR"
|
||||
|
||||
WORKDIR "$OUT"
|
||||
WORKDIR "$OUTDIR"
|
||||
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
|
||||
# unused
|
||||
ARG QEMU_VERSION_=v3.1.0-2
|
||||
|
||||
|
@ -90,15 +90,19 @@ ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
|
||||
|
||||
ARG USERID=1000
|
||||
|
||||
ARG PROJECT_ROOT=/workspace/src
|
||||
ARG OUT=/workspace/out
|
||||
ARG PROJECTDIR=/workspace/src
|
||||
ARG OUTDIR=/workspace/out
|
||||
ARG SCRIPTDIR=/workspace/bin
|
||||
|
||||
RUN set -x \
|
||||
&& useradd -u "$USERID" -ms /bin/bash user \
|
||||
&& mkdir -p "$PROJECT_ROOT" "$OUT" \
|
||||
&& chown user:user "$PROJECT_ROOT" "$OUT"
|
||||
&& mkdir -p "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" \
|
||||
&& chown user:user "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR"
|
||||
|
||||
WORKDIR "$OUT"
|
||||
WORKDIR "$OUTDIR"
|
||||
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
|
||||
# unused
|
||||
ARG QEMU_VERSION_=v3.1.0-2
|
||||
|
||||
|
@ -93,15 +93,16 @@ ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
|
||||
|
||||
ARG USERID=1000
|
||||
|
||||
ARG PROJECT_ROOT=/workspace/src
|
||||
ARG OUT=/workspace/out
|
||||
ARG PROJECTDIR=/workspace/src
|
||||
ARG OUTDIR=/workspace/out
|
||||
ARG SCRIPTDIR=/workspace/bin
|
||||
|
||||
RUN set -x \
|
||||
&& useradd -u "$USERID" -ms /bin/bash user \
|
||||
&& mkdir -p "$PROJECT_ROOT" "$OUT" \
|
||||
&& chown user:user "$PROJECT_ROOT" "$OUT"
|
||||
&& mkdir -p "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" \
|
||||
&& chown user:user "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR"
|
||||
|
||||
WORKDIR "$OUT"
|
||||
WORKDIR "$OUTDIR"
|
||||
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
|
||||
|
@ -93,15 +93,16 @@ ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
|
||||
|
||||
ARG USERID=1000
|
||||
|
||||
ARG PROJECT_ROOT=/workspace/src
|
||||
ARG OUT=/workspace/out
|
||||
ARG PROJECTDIR=/workspace/src
|
||||
ARG OUTDIR=/workspace/out
|
||||
ARG SCRIPTDIR=/workspace/bin
|
||||
|
||||
RUN set -x \
|
||||
&& useradd -u "$USERID" -ms /bin/bash user \
|
||||
&& mkdir -p "$PROJECT_ROOT" "$OUT" \
|
||||
&& chown user:user "$PROJECT_ROOT" "$OUT"
|
||||
&& mkdir -p "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR" \
|
||||
&& chown user:user "$PROJECTDIR" "$OUTDIR" "$SCRIPTDIR"
|
||||
|
||||
WORKDIR "$OUT"
|
||||
WORKDIR "$OUTDIR"
|
||||
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
|
||||
|
@ -4,12 +4,15 @@ set -e
|
||||
|
||||
DOCKER="${DOCKER:-docker}"
|
||||
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}"
|
||||
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}"
|
||||
HOST_ENVFILTER="${HOST_ENVFILTER:-^DOCKER_\|^COMPOSE_}"
|
||||
PATH="${SCRIPTDIR}:$PATH"
|
||||
|
||||
set -- --entrypoint "$ENTRYPOINT" "$IMAGE" "$@"
|
||||
set -- --user "$USERID:$USERID" --network "$NETWORK" --workdir "$PWD" "$@"
|
||||
@ -22,9 +25,11 @@ if [ -n "$CONTAINER_CGROUP_PARENT" ]; then
|
||||
set -- --cgroup-parent "$CONTAINER_CGROUP_PARENT" "$@"
|
||||
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
|
||||
set -- --volumes-from "$HOST_CONTAINER" "$@"
|
||||
else
|
||||
set -- --volume "$PROJECTDIR:$PROJECTDIR:cached" "$@"
|
||||
fi
|
||||
|
||||
# setup options for connection to docker host
|
||||
@ -35,7 +40,7 @@ else
|
||||
set -- -e DOCKER_HOST -e DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH "$@"
|
||||
fi
|
||||
|
||||
if [ -t 0 ] && ! "$SCRIPT_ROOT/is_running_in_bg.sh" $$; then
|
||||
if [ -t 0 ] && ! is_running_in_bg.sh $$; then
|
||||
set -- --interactive "$@"
|
||||
fi
|
||||
|
113
build/mkdocker/cmake.mk
Normal file
113
build/mkdocker/cmake.mk
Normal 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))'; \
|
||||
) \
|
||||
} > $@
|
||||
|
57
build/mkdocker/defaults.mk
Normal file
57
build/mkdocker/defaults.mk
Normal 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
87
build/mkdocker/docker.mk
Normal 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
|
||||
|
1
build/mkdocker/resources/md5sum.txt.template
Normal file
1
build/mkdocker/resources/md5sum.txt.template
Normal file
@ -0,0 +1 @@
|
||||
%MD5% %FILE%
|
@ -5,14 +5,10 @@ set -e
|
||||
DOCKER="${DOCKER:-%DOCKER%}"
|
||||
IMAGE="${IMAGE:-%IMAGE%}"
|
||||
NETWORK="${NETWORK:-host}"
|
||||
PROJECT_ROOT="${PROJECT_ROOT:-%PROJECT_ROOT%}"
|
||||
SCRIPT_ROOT="${SCRIPT_ROOT:-"$PROJECT_ROOT/build"}"
|
||||
PROJECTDIR="${PROJECTDIR:-%PROJECTDIR%}"
|
||||
SCRIPTDIR="${SCRIPTDIR:-%SCRIPTDIR%/bin}"
|
||||
ENTRYPOINT="${ENTRYPOINT:-%RUNCMD%}"
|
||||
|
||||
if [ ! -d "$SCRIPT_ROOT" ]; then
|
||||
echo "error:$0: $SCRIPT_ROOT not found; set project root (PROJECT_ROOT=)" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
PATH="${SCRIPTDIR}:$PATH"
|
||||
|
||||
set -- --entrypoint "$ENTRYPOINT" "$IMAGE" "$@"
|
||||
set -- --network "$NETWORK" --workdir "$PWD" "$@"
|
||||
@ -29,14 +25,16 @@ if [ -n "$CONTAINER_CGROUP_PARENT" ]; then
|
||||
set -- --cgroup-parent "$CONTAINER_CGROUP_PARENT" "$@"
|
||||
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
|
||||
set -- --volumes-from "$HOST_CONTAINER" "$@"
|
||||
else
|
||||
set -- --volume "$PROJECTDIR:$PROJECTDIR:cached" "$@"
|
||||
fi
|
||||
|
||||
set -- %RUNFLAGS% "$@"
|
||||
|
||||
if [ -t 0 ] && ! "$SCRIPT_ROOT/is_running_in_bg.sh" $$; then
|
||||
if [ -t 0 ] && ! is_running_in_bg.sh $$; then
|
||||
set -- --interactive "$@"
|
||||
fi
|
||||
|
124
build/mkdocker/standardrules.mk
Normal file
124
build/mkdocker/standardrules.mk
Normal 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')
|
Loading…
Reference in New Issue
Block a user