2023-04-04 16:42:46 +00:00
|
|
|
lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
|
|
|
|
altarch = $(subst x86_64,amd64,$(subst aarch64,arm64,$1))
|
|
|
|
|
2023-05-02 23:02:33 +00:00
|
|
|
TOOLCHAIN_VOLUME := $(PWD):/home/build
|
|
|
|
TOOLCHAIN_WORKDIR := /home/build
|
2023-02-03 05:30:11 +00:00
|
|
|
DEFAULT_GOAL := $(or $(DEFAULT_GOAL),toolchain)
|
|
|
|
ARCH := $(or $(ARCH),x86_64)
|
|
|
|
TARGET := $(or $(TARGET),$(ARCH))
|
2023-05-03 20:04:10 +00:00
|
|
|
|
|
|
|
normarch = $(subst arm64,aarch64,$(subst amd64,x86_64,$1))
|
|
|
|
HOST_ARCH := $(call normarch,$(call lc,$(shell uname -m)))
|
2023-04-04 16:42:46 +00:00
|
|
|
HOST_ARCH_ALT := $(call altarch,$(HOST_ARCH))
|
2023-05-03 20:04:10 +00:00
|
|
|
|
2023-04-04 16:42:46 +00:00
|
|
|
HOST_OS := $(call lc,$(shell uname -s))
|
2023-02-06 20:54:17 +00:00
|
|
|
PLATFORM := $(or $(PLATFORM),linux)
|
2023-02-13 20:36:17 +00:00
|
|
|
NAME := $(shell basename $(shell git rev-parse --show-toplevel | tr A-Z a-z ))
|
2023-03-08 02:09:52 +00:00
|
|
|
UID := $(shell id -u)
|
|
|
|
GID := $(shell id -g)
|
|
|
|
USER := $(UID):$(GID)
|
2023-05-02 21:55:45 +00:00
|
|
|
CPUS := $(shell docker run debian nproc)
|
2023-09-03 09:46:55 +00:00
|
|
|
ARCHIVE_SOURCES := true
|
2023-02-10 20:57:10 +00:00
|
|
|
GIT_REF := $(shell git log -1 --format=%H)
|
|
|
|
GIT_AUTHOR := $(shell git log -1 --format=%an)
|
|
|
|
GIT_KEY := $(shell git log -1 --format=%GP)
|
2023-02-13 05:36:05 +00:00
|
|
|
GIT_TIMESTAMP := $(shell git log -1 --format=%cd --date=iso)
|
2023-03-08 02:09:52 +00:00
|
|
|
, := ,
|
2023-10-03 19:10:22 +00:00
|
|
|
empty :=
|
|
|
|
space := $(empty) $(empty)
|
2023-01-28 00:05:03 +00:00
|
|
|
ifeq ($(strip $(shell git status --porcelain 2>/dev/null)),)
|
|
|
|
GIT_STATE=clean
|
|
|
|
else
|
|
|
|
GIT_STATE=dirty
|
|
|
|
endif
|
2023-02-11 00:37:22 +00:00
|
|
|
VERSION := $(shell TZ=UTC0 git show --quiet --date='format-local:%Y.%m.%d' --format="%cd")
|
2023-02-09 01:07:23 +00:00
|
|
|
DIST_DIR := dist
|
2023-01-28 00:05:03 +00:00
|
|
|
CONFIG_DIR := config
|
2023-02-03 05:30:11 +00:00
|
|
|
CACHE_DIR_ROOT := cache
|
2023-06-09 23:08:03 +00:00
|
|
|
FETCH_DIR := fetch
|
2023-02-03 05:30:11 +00:00
|
|
|
ifeq ($(TARGET),$(ARCH))
|
|
|
|
CACHE_DIR := $(CACHE_DIR_ROOT)/$(TARGET)
|
|
|
|
else
|
|
|
|
CACHE_DIR := $(CACHE_DIR_ROOT)/$(TARGET)/$(ARCH)
|
|
|
|
endif
|
|
|
|
BIN_DIR := $(CACHE_DIR_ROOT)/bin
|
2023-01-28 00:05:03 +00:00
|
|
|
SRC_DIR := src
|
2023-06-22 01:28:27 +00:00
|
|
|
KEY_DIR := fetch/keys
|
2023-01-28 00:05:03 +00:00
|
|
|
OUT_DIR := out
|
2023-09-28 00:22:01 +00:00
|
|
|
IMAGE := toolchain/$(shell git ls-files -s $(CONFIG_DIR) | git hash-object --stdin)
|
2023-01-28 00:05:03 +00:00
|
|
|
docker = docker
|
|
|
|
|
2023-09-03 10:29:28 +00:00
|
|
|
PATH_PREFIX := /home/build/.local/bin:/home/build/$(CACHE_DIR)/bin:/home/build/$(OUT_DIR)/linux/x86_64
|
|
|
|
PREFIX := $(HOME)/.local
|
2023-09-03 09:46:55 +00:00
|
|
|
XDG_CONFIG_HOME := $(HOME)/.config
|
|
|
|
|
2023-10-09 21:55:37 +00:00
|
|
|
ifneq ($(TOOLCHAIN_PROFILE),false)
|
|
|
|
mkc := $(shell mkdir -p $(CACHE_DIR_ROOT))
|
|
|
|
ifndef TOOLCHAIN_PROFILE_RUNNING
|
|
|
|
rmp := $(shell rm -f $(CACHE_DIR_ROOT)/toolchain-profile.csv)
|
2023-10-10 00:03:44 +00:00
|
|
|
TOOLCHAIN_PROFILE_INIT := $(shell date +%s)
|
2023-10-09 21:55:37 +00:00
|
|
|
TOOLCHAIN_PROFILE_START := 0
|
2023-10-10 00:03:44 +00:00
|
|
|
TOOLCHAIN_PROFILE_TOTAL := 0
|
|
|
|
TOOLCHAIN_PROFILE_TRACKED := 0
|
|
|
|
TOOLCHAIN_PROFILE_UNTRACKED := 0
|
2023-10-09 21:55:37 +00:00
|
|
|
TOOLCHAIN_PROFILE_RUNNING := true
|
2023-10-10 00:03:44 +00:00
|
|
|
export TOOLCHAIN_PROFILE_RUNNING TOOLCHAIN_PROFILE_START TOOLCHAIN_PROFILE_TOTAL TOOLCHAIN_PROFILE_UNTRACKED TOOLCHAIN_PROFILE_TRACKED
|
2023-10-09 21:55:37 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
.PHONY: toolchain-profile
|
|
|
|
toolchain-profile:
|
2023-10-10 00:03:44 +00:00
|
|
|
$(call toolchain-profile-total)
|
|
|
|
$(call toolchain-profile-tracked)
|
|
|
|
$(call toolchain-profile-untracked)
|
|
|
|
@printf "unprofiled,%s\n" "$(TOOLCHAIN_PROFILE_UNTRACKED)" >> $(CACHE_DIR_ROOT)/toolchain-profile.csv
|
|
|
|
@printf "total,%s" "$(TOOLCHAIN_PROFILE_TOTAL)" >> $(CACHE_DIR_ROOT)/toolchain-profile.csv
|
|
|
|
@echo Build times:
|
|
|
|
@column -c 80 -s, -t < $(CACHE_DIR_ROOT)/toolchain-profile.csv
|
2023-10-09 21:55:37 +00:00
|
|
|
endif
|
|
|
|
|
2023-10-10 00:03:44 +00:00
|
|
|
define toolchain-profile-total
|
|
|
|
$(eval TOOLCHAIN_PROFILE_TOTAL=$(shell date -d@$$(($(shell date +%s)-$(TOOLCHAIN_PROFILE_INIT))) -u +%s))
|
|
|
|
endef
|
|
|
|
|
|
|
|
define toolchain-profile-tracked
|
|
|
|
$(eval TOOLCHAIN_PROFILE_TRACKED=$(shell cat $(CACHE_DIR_ROOT)/toolchain-profile.csv | cut -d ',' -f2 | awk '{ sum += $$1 } END { print sum }'))
|
|
|
|
endef
|
|
|
|
|
|
|
|
define toolchain-profile-untracked
|
|
|
|
$(eval TOOLCHAIN_PROFILE_UNTRACKED=$(shell printf $$(($(TOOLCHAIN_PROFILE_TOTAL)-$(TOOLCHAIN_PROFILE_TRACKED))) -u +%s))
|
|
|
|
endef
|
|
|
|
|
|
|
|
define toolchain-profile-start
|
2023-10-09 21:55:37 +00:00
|
|
|
$(eval TOOLCHAIN_PROFILE_START=$(shell date +%s))
|
|
|
|
@printf "%s," "$@" >> $(CACHE_DIR_ROOT)/toolchain-profile.csv
|
|
|
|
endef
|
|
|
|
|
2023-10-10 00:03:44 +00:00
|
|
|
define toolchain-profile-end
|
|
|
|
printf "%s\n" "$$(($$(date +%s)-$(TOOLCHAIN_PROFILE_START)))" >> $(CACHE_DIR_ROOT)/toolchain-profile.csv
|
2023-10-09 21:55:37 +00:00
|
|
|
endef
|
|
|
|
|
2023-06-08 12:37:19 +00:00
|
|
|
export
|
|
|
|
|
2023-06-18 22:04:53 +00:00
|
|
|
include $(CONFIG_DIR)/make.env
|
|
|
|
export $(shell sed 's/=.*//' $(CONFIG_DIR)/make.env)
|
2023-01-28 00:05:03 +00:00
|
|
|
|
|
|
|
## Use env vars from existing release if present
|
2023-09-21 23:00:21 +00:00
|
|
|
ifeq ($(TOOLCHAIN_REPRODUCE),true)
|
|
|
|
include $(DIST_DIR)/release.env
|
|
|
|
export
|
2023-01-28 00:05:03 +00:00
|
|
|
endif
|
|
|
|
|
2023-05-01 21:10:33 +00:00
|
|
|
executables = $(docker) git git-lfs patch
|
2023-01-28 00:05:03 +00:00
|
|
|
|
|
|
|
.PHONY: toolchain
|
2023-02-03 05:30:11 +00:00
|
|
|
toolchain: \
|
|
|
|
$(CACHE_DIR) \
|
|
|
|
$(FETCH_DIR) \
|
|
|
|
$(BIN_DIR) \
|
|
|
|
$(OUT_DIR) \
|
2023-02-15 21:57:45 +00:00
|
|
|
$(CACHE_DIR_ROOT)/toolchain.state \
|
2023-06-18 22:04:53 +00:00
|
|
|
$(CACHE_DIR_ROOT)/container.env
|
2023-01-28 00:05:03 +00:00
|
|
|
|
|
|
|
# Launch a shell inside the toolchain container
|
|
|
|
.PHONY: toolchain-shell
|
|
|
|
toolchain-shell: toolchain
|
2023-04-27 20:40:31 +00:00
|
|
|
$(call toolchain,bash --norc,--interactive)
|
2023-01-28 00:05:03 +00:00
|
|
|
|
|
|
|
.PHONY: toolchain-update
|
|
|
|
toolchain-update:
|
2023-06-16 19:58:05 +00:00
|
|
|
rm -rf \
|
2023-06-16 06:23:10 +00:00
|
|
|
$(CONFIG_DIR)/apt-pins-x86_64.list \
|
|
|
|
$(CONFIG_DIR)/apt-sources-x86_64.list \
|
2023-06-16 19:58:05 +00:00
|
|
|
$(CONFIG_DIR)/apt-hashes-x86_64.list \
|
|
|
|
$(FETCH_DIR)/apt
|
2023-06-18 22:04:53 +00:00
|
|
|
$(MAKE) $(CONFIG_DIR)/apt-hashes-x86_64.list
|
2023-06-16 19:58:05 +00:00
|
|
|
|
2023-09-21 17:55:57 +00:00
|
|
|
.PHONY: toolchain-restore-mtime
|
|
|
|
toolchain-restore-mtime:
|
|
|
|
$(call toolchain," \
|
|
|
|
git restore-mtime \
|
|
|
|
&& echo "Git mtime restored" \
|
|
|
|
")
|
|
|
|
|
|
|
|
.PHONY: toolchain-dist-cache
|
|
|
|
toolchain-dist-cache:
|
2023-09-24 12:17:39 +00:00
|
|
|
mkdir -p $(OUT_DIR)
|
2023-09-21 17:55:57 +00:00
|
|
|
cp -Rp $(DIST_DIR)/* $(OUT_DIR)/
|
|
|
|
|
2023-06-16 19:58:05 +00:00
|
|
|
$(CONFIG_DIR)/apt-base.list:
|
|
|
|
touch $(CONFIG_DIR)/apt-base.list
|
|
|
|
|
2023-06-16 06:23:10 +00:00
|
|
|
# Regenerate toolchain dependency packages to latest versions
|
|
|
|
$(CONFIG_DIR)/apt-pins-x86_64.list \
|
|
|
|
$(CONFIG_DIR)/apt-sources-x86_64.list \
|
2023-06-16 19:58:05 +00:00
|
|
|
$(CONFIG_DIR)/apt-hashes-x86_64.list: \
|
|
|
|
$(CONFIG_DIR)/apt-base.list
|
2023-10-10 00:03:44 +00:00
|
|
|
$(call toolchain-profile-start)
|
2023-06-16 06:23:10 +00:00
|
|
|
mkdir -p $(FETCH_DIR)/apt \
|
|
|
|
&& docker run \
|
2023-01-28 00:05:03 +00:00
|
|
|
--rm \
|
2023-03-08 02:09:52 +00:00
|
|
|
--tty \
|
2023-01-28 00:05:03 +00:00
|
|
|
--platform=linux/$(ARCH) \
|
2023-03-08 02:09:52 +00:00
|
|
|
--env LOCAL_USER=$(UID):$(GID) \
|
2023-01-28 00:05:03 +00:00
|
|
|
--volume $(PWD)/$(CONFIG_DIR):/config \
|
|
|
|
--volume $(PWD)/$(SRC_DIR)/toolchain/scripts:/usr/local/bin \
|
2023-03-08 02:09:52 +00:00
|
|
|
--cpus $(CPUS) \
|
2023-05-02 23:02:33 +00:00
|
|
|
--volume $(TOOLCHAIN_VOLUME) \
|
|
|
|
--workdir $(TOOLCHAIN_WORKDIR) \
|
2023-01-28 00:05:03 +00:00
|
|
|
debian@sha256:$(DEBIAN_HASH) \
|
2023-03-08 02:09:52 +00:00
|
|
|
/usr/local/bin/packages-update
|
2023-10-10 00:03:44 +00:00
|
|
|
$(call toolchain-profile-end)
|
2023-01-28 00:05:03 +00:00
|
|
|
|
2023-06-16 06:23:10 +00:00
|
|
|
# Pin all packages in toolchain container to latest versions
|
2023-06-30 19:55:08 +00:00
|
|
|
$(FETCH_DIR)/apt/Packages.bz2: $(CONFIG_DIR)/apt-hashes-x86_64.list
|
2023-10-10 00:03:44 +00:00
|
|
|
$(call toolchain-profile-start)
|
2023-06-16 06:23:10 +00:00
|
|
|
docker run \
|
|
|
|
--rm \
|
|
|
|
--tty \
|
|
|
|
--platform=linux/$(ARCH) \
|
|
|
|
--env LOCAL_USER=$(UID):$(GID) \
|
|
|
|
--env FETCH_DIR="$(FETCH_DIR)" \
|
2023-09-03 09:46:55 +00:00
|
|
|
--env ARCHIVE_SOURCES=$(ARCHIVE_SOURCES) \
|
2023-06-16 06:23:10 +00:00
|
|
|
--volume $(PWD)/$(CONFIG_DIR):/config \
|
|
|
|
--volume $(PWD)/$(SRC_DIR)/toolchain/scripts:/usr/local/bin \
|
|
|
|
--volume $(PWD)/$(FETCH_DIR):/fetch \
|
|
|
|
--cpus $(CPUS) \
|
|
|
|
--volume $(TOOLCHAIN_VOLUME) \
|
|
|
|
--workdir $(TOOLCHAIN_WORKDIR) \
|
|
|
|
debian@sha256:$(DEBIAN_HASH) \
|
|
|
|
/usr/local/bin/packages-fetch
|
2023-10-10 00:03:44 +00:00
|
|
|
$(call toolchain-profile-end)
|
2023-06-16 06:23:10 +00:00
|
|
|
|
2023-02-03 11:43:24 +00:00
|
|
|
.PHONY: toolchain-clean
|
|
|
|
toolchain-clean:
|
2023-04-27 20:40:31 +00:00
|
|
|
if [ -d "$(CACHE_DIR_ROOT)" ]; then \
|
|
|
|
chmod -R u+w $(CACHE_DIR_ROOT); \
|
|
|
|
rm -rf $(CACHE_DIR_ROOT); \
|
|
|
|
fi
|
|
|
|
if [ -d "$(OUT_DIR)" ]; then \
|
|
|
|
rm -rf $(OUT_DIR); \
|
|
|
|
fi
|
|
|
|
docker image rm -f $(IMAGE) || :
|
2023-02-03 11:43:24 +00:00
|
|
|
|
2023-09-21 17:55:57 +00:00
|
|
|
.PHONY: toolchain-reproduce
|
|
|
|
toolchain-reproduce: toolchain-clean
|
2023-02-10 21:07:12 +00:00
|
|
|
mkdir -p $(OUT_DIR)
|
2023-09-21 17:55:57 +00:00
|
|
|
$(MAKE) TOOLCHAIN_REPRODUCE="true"
|
2023-05-04 19:10:38 +00:00
|
|
|
diff -q $(OUT_DIR) $(DIST_DIR) \
|
2023-04-04 21:52:04 +00:00
|
|
|
&& echo "Success: $(OUT_DIR) and $(DIST_DIR) are identical"
|
2023-01-28 00:05:03 +00:00
|
|
|
|
2023-09-21 17:55:57 +00:00
|
|
|
.PHONY: toolchain-dist
|
2023-09-28 02:22:08 +00:00
|
|
|
toolchain-dist:
|
2023-09-09 01:35:33 +00:00
|
|
|
git ls-files -o --exclude-standard | grep . \
|
|
|
|
&& { echo "Error: Git has untracked files present"; exit 1; } || :
|
|
|
|
git diff --name-only | grep . \
|
|
|
|
&& { echo "Error: Git has unstaged changes present"; exit 1; } || :
|
2023-10-03 17:52:51 +00:00
|
|
|
$(MAKE) toolchain-clean toolchain-restore-mtime toolchain-dist-cache default
|
2023-09-21 22:50:23 +00:00
|
|
|
cp -Rp $(OUT_DIR)/* $(DIST_DIR)/
|
2023-01-28 00:05:03 +00:00
|
|
|
|
2023-02-03 05:30:11 +00:00
|
|
|
$(BIN_DIR):
|
|
|
|
mkdir -p $@
|
|
|
|
|
2023-01-28 00:05:03 +00:00
|
|
|
$(CACHE_DIR):
|
|
|
|
mkdir -p $@
|
|
|
|
|
2023-02-03 05:30:11 +00:00
|
|
|
$(FETCH_DIR):
|
|
|
|
mkdir -p $@
|
|
|
|
|
2023-01-28 00:05:03 +00:00
|
|
|
$(OUT_DIR):
|
|
|
|
mkdir -p $@
|
|
|
|
|
2023-06-18 22:04:53 +00:00
|
|
|
$(CACHE_DIR_ROOT)/container.env: \
|
|
|
|
$(CONFIG_DIR)/make.env \
|
2023-06-02 01:04:41 +00:00
|
|
|
$(CACHE_DIR_ROOT)/toolchain.state
|
|
|
|
docker run \
|
|
|
|
--rm \
|
|
|
|
--env UID=$(UID) \
|
|
|
|
--env GID=$(GID) \
|
2023-06-15 19:42:16 +00:00
|
|
|
--env NAME="$(NAME)" \
|
|
|
|
--env IMAGE="$(IMAGE)" \
|
|
|
|
--env USER="$(USER)" \
|
|
|
|
--env ARCH="$(ARCH)" \
|
|
|
|
--env HOST_ARCH="$(HOST_ARCH)" \
|
|
|
|
--env HOST_ARCH_ALT="$(HOST_ARCH_ALT)" \
|
|
|
|
--env HOST_OS="$(HOST_OS)" \
|
|
|
|
--env PLATFORM="$(PLATFORM)" \
|
|
|
|
--env CPUS="$(CPUS)" \
|
|
|
|
--env TARGET="$(TARGET)" \
|
|
|
|
--env GIT_REF="$(GIT_REF)" \
|
|
|
|
--env GIT_AUTHOR="$(GIT_AUTHOR)" \
|
|
|
|
--env GIT_KEY="$(GIT_KEY)" \
|
|
|
|
--env GIT_TIMESTAMP="$(GIT_TIMESTAMP)" \
|
|
|
|
--env VERSION="$(VERSION)" \
|
|
|
|
--env DIST_DIR="$(DIST_DIR)" \
|
|
|
|
--env FETCH_DIR="$(FETCH_DIR)" \
|
|
|
|
--env KEY_DIR="$(KEY_DIR)" \
|
2023-06-18 10:21:57 +00:00
|
|
|
--env BIN_DIR="$(BIN_DIR)" \
|
2023-06-15 19:42:16 +00:00
|
|
|
--env OUT_DIR="$(OUT_DIR)" \
|
|
|
|
--env SRC_DIR="$(SRC_DIR)" \
|
|
|
|
--env CACHE_DIR="$(CACHE_DIR)" \
|
|
|
|
--env CACHE_DIR_ROOT="$(CACHE_DIR_ROOT)" \
|
|
|
|
--env CONFIG_DIR="$(CONFIG_DIR)" \
|
|
|
|
--env TOOLCHAIN_VOLUME="$(TOOLCHAIN_VOLUME)" \
|
|
|
|
--env TOOLCHAIN_WORKDIR="$(TOOLCHAIN_WORKDIR)" \
|
2023-06-02 01:04:41 +00:00
|
|
|
--platform=linux/$(ARCH) \
|
|
|
|
--volume $(TOOLCHAIN_VOLUME) \
|
|
|
|
--workdir $(TOOLCHAIN_WORKDIR) \
|
|
|
|
$(shell cat cache/toolchain.state 2> /dev/null) \
|
2023-06-18 22:04:53 +00:00
|
|
|
$(SRC_DIR)/toolchain/scripts/environment > $@
|
2023-02-03 05:30:11 +00:00
|
|
|
|
2023-09-27 21:49:17 +00:00
|
|
|
$(CACHE_DIR_ROOT)/toolchain.tgz: \
|
2023-06-18 22:04:53 +00:00
|
|
|
$(CONFIG_DIR)/make.env \
|
2023-02-03 05:30:11 +00:00
|
|
|
$(SRC_DIR)/toolchain/Dockerfile \
|
2023-06-16 06:23:10 +00:00
|
|
|
$(CONFIG_DIR)/apt-base.list \
|
|
|
|
$(CONFIG_DIR)/apt-sources-$(ARCH).list \
|
|
|
|
$(CONFIG_DIR)/apt-pins-$(ARCH).list \
|
|
|
|
$(CONFIG_DIR)/apt-hashes-$(ARCH).list \
|
2023-08-07 21:33:01 +00:00
|
|
|
| $(FETCH_DIR)/apt/Packages.bz2
|
2023-10-10 00:03:44 +00:00
|
|
|
$(call toolchain-profile-start)
|
2023-01-28 00:05:03 +00:00
|
|
|
mkdir -p $(CACHE_DIR)
|
|
|
|
DOCKER_BUILDKIT=1 \
|
|
|
|
docker build \
|
|
|
|
--tag $(IMAGE) \
|
|
|
|
--build-arg DEBIAN_HASH=$(DEBIAN_HASH) \
|
|
|
|
--build-arg CONFIG_DIR=$(CONFIG_DIR) \
|
2023-06-16 06:23:10 +00:00
|
|
|
--build-arg FETCH_DIR=$(PWD)/$(FETCH_DIR) \
|
2023-01-28 00:05:03 +00:00
|
|
|
--build-arg SCRIPTS_DIR=$(SRC_DIR)/toolchain/scripts \
|
|
|
|
--platform=linux/$(ARCH) \
|
|
|
|
-f $(SRC_DIR)/toolchain/Dockerfile \
|
|
|
|
.
|
2023-09-27 21:49:17 +00:00
|
|
|
docker save "$(IMAGE)" | gzip > "$@"
|
2023-10-10 00:03:44 +00:00
|
|
|
$(call toolchain-profile-end)
|
2023-01-28 00:05:03 +00:00
|
|
|
|
2023-02-15 21:57:45 +00:00
|
|
|
$(CACHE_DIR_ROOT)/toolchain.state: \
|
2023-09-27 21:49:17 +00:00
|
|
|
$(CACHE_DIR_ROOT)/toolchain.tgz
|
|
|
|
docker load -i $(CACHE_DIR_ROOT)/toolchain.tgz
|
2023-02-15 21:57:45 +00:00
|
|
|
docker images --no-trunc --quiet $(IMAGE) > $@
|
|
|
|
|
2023-09-19 00:38:31 +00:00
|
|
|
$(OUT_DIR)/release.env: $(shell git ls-files)
|
2023-02-13 05:36:05 +00:00
|
|
|
echo 'VERSION=$(VERSION)' > $(OUT_DIR)/release.env
|
|
|
|
echo 'GIT_REF=$(GIT_REF)' >> $(OUT_DIR)/release.env
|
|
|
|
echo 'GIT_AUTHOR=$(GIT_AUTHOR)' >> $(OUT_DIR)/release.env
|
|
|
|
echo 'GIT_KEY=$(GIT_KEY)' >> $(OUT_DIR)/release.env
|
|
|
|
echo 'GIT_TIMESTAMP=$(GIT_TIMESTAMP)' >> $(OUT_DIR)/release.env
|
2023-01-28 00:05:03 +00:00
|
|
|
|
|
|
|
check_executables := $(foreach exec,$(executables),\$(if \
|
|
|
|
$(shell which $(exec)),some string,$(error "No $(exec) in PATH")))
|
|
|
|
|
2023-06-09 23:08:03 +00:00
|
|
|
define sha256_file
|
|
|
|
$$(openssl sha256 $(1) | awk '{ print $$2}')
|
|
|
|
endef
|
|
|
|
|
|
|
|
define fetch_file
|
|
|
|
bash -c " \
|
|
|
|
echo \"Fetching $(1)\" \
|
|
|
|
&& curl \
|
|
|
|
--location $(1) \
|
|
|
|
--output $(CACHE_DIR)/$(notdir $@) \
|
|
|
|
&& [[ "\""$(call sha256_file,$(CACHE_DIR)/$(notdir $@))"\"" == "\""$(2)"\"" ]] \
|
|
|
|
|| { echo 'Error: Hash check failed'; exit 1; } \
|
|
|
|
&& mv $(CACHE_DIR)/$(notdir $@) $@; \
|
|
|
|
"
|
|
|
|
endef
|
|
|
|
|
2023-06-22 09:50:56 +00:00
|
|
|
define git_archive
|
|
|
|
$(call git_clone,$(CACHE_DIR)/$(notdir $@),$(1),$(2)) \
|
|
|
|
&& tar \
|
|
|
|
-C $(CACHE_DIR)/$(notdir $@) \
|
|
|
|
--sort=name \
|
|
|
|
--mtime='@0' \
|
|
|
|
--owner=0 \
|
|
|
|
--group=0 \
|
|
|
|
--numeric-owner \
|
|
|
|
-cvf - \
|
|
|
|
. \
|
|
|
|
| gzip -n > $@ \
|
|
|
|
&& rm -rf $(CACHE_DIR)/$(notdir $@)
|
|
|
|
endef
|
|
|
|
|
2023-01-28 00:05:03 +00:00
|
|
|
define git_clone
|
2023-02-17 05:15:10 +00:00
|
|
|
[ -d $(1) ] || \
|
2023-06-22 09:50:56 +00:00
|
|
|
mkdir -p $(1).tmp && \
|
2023-02-17 05:15:10 +00:00
|
|
|
git -C $(1).tmp init && \
|
|
|
|
git -C $(1).tmp remote add origin $(2) && \
|
|
|
|
git -C $(1).tmp fetch origin $(3) && \
|
|
|
|
git -C $(1).tmp -c advice.detachedHead=false checkout $(3) && \
|
2023-06-22 09:50:56 +00:00
|
|
|
git -C $(1).tmp submodule update --init && \
|
2023-02-17 05:15:10 +00:00
|
|
|
git -C $(1).tmp rev-parse --verify HEAD | grep -q $(3) || { \
|
|
|
|
echo 'Error: Git ref/branch collision.'; exit 1; \
|
|
|
|
} && \
|
2023-06-22 09:50:56 +00:00
|
|
|
mv $(1).tmp $(1)
|
2023-01-28 00:05:03 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
define apply_patches
|
2023-03-08 02:09:52 +00:00
|
|
|
[ -d $(2) ] && $(call toolchain," \
|
2023-01-28 00:05:03 +00:00
|
|
|
cd $(1); \
|
|
|
|
git restore .; \
|
|
|
|
find /$(2) -type f -iname '*.patch' -print0 \
|
|
|
|
| xargs -t -0 -n 1 patch -p1 --no-backup-if-mismatch -i ; \
|
|
|
|
")
|
|
|
|
endef
|
|
|
|
|
2023-02-03 05:30:11 +00:00
|
|
|
define fetch_pgp_key
|
|
|
|
mkdir -p $(KEY_DIR) && \
|
2023-03-17 03:11:43 +00:00
|
|
|
$(call toolchain,' \
|
|
|
|
for server in \
|
|
|
|
keys.openpgp.org \
|
|
|
|
hkp://keyserver.ubuntu.com:80 \
|
|
|
|
hkp://p80.pool.sks-keyservers.net:80 \
|
|
|
|
ha.pool.sks-keyservers.net \
|
|
|
|
pgp.mit.edu \
|
|
|
|
; do \
|
|
|
|
echo "Trying: $${server}"; \
|
|
|
|
gpg \
|
|
|
|
--keyserver "$${server}" \
|
|
|
|
--keyserver-options timeout=10 \
|
|
|
|
--recv-keys "$(1)" \
|
|
|
|
&& break; \
|
|
|
|
done; \
|
2023-06-22 01:28:27 +00:00
|
|
|
gpg --export -a $(1) > $@; \
|
2023-03-17 03:11:43 +00:00
|
|
|
')
|
2023-02-03 05:30:11 +00:00
|
|
|
endef
|
|
|
|
|
2023-01-28 00:05:03 +00:00
|
|
|
define toolchain
|
2023-09-09 01:35:33 +00:00
|
|
|
$(MAKE) toolchain \
|
|
|
|
&& docker run \
|
|
|
|
--rm \
|
|
|
|
--tty \
|
2023-05-02 21:55:45 +00:00
|
|
|
$(2) \
|
|
|
|
--env UID=$(UID) \
|
|
|
|
--env GID=$(GID) \
|
2023-07-21 01:24:42 +00:00
|
|
|
--env PATH_PREFIX=$(PATH_PREFIX) \
|
2023-05-02 21:55:45 +00:00
|
|
|
--platform=linux/$(ARCH) \
|
|
|
|
--privileged \
|
|
|
|
--cpus $(CPUS) \
|
|
|
|
--volume $(TOOLCHAIN_VOLUME) \
|
|
|
|
--workdir $(TOOLCHAIN_WORKDIR) \
|
2023-06-08 12:37:19 +00:00
|
|
|
--env-file=$(CACHE_DIR_ROOT)/container.env \
|
2023-09-09 01:35:33 +00:00
|
|
|
$$(cat $(CACHE_DIR_ROOT)/toolchain.state 2> /dev/null) \
|
2023-05-02 21:55:45 +00:00
|
|
|
$(SRC_DIR)/toolchain/scripts/host-env bash -c $(1)
|
2023-01-28 00:05:03 +00:00
|
|
|
endef
|