From 5766f1bb2d616a031fa7b17c638ddf1bd2ec0bed Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Sat, 27 Jun 2020 19:31:58 +0200 Subject: [PATCH] ALL: Let user choose which platforms he wants to enable and build --- Makefile | 158 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 117 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index f7dfaf0..101ed10 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,13 @@ BUILDBOT_VERSION := 2.7.0 +# Without toolchains/ part, all is a placeholder for all detected toolchains +TOOLCHAINS_ENABLED := all +TOOLCHAINS_BUILT := all + +# Without workers/ part, all is a placeholder for all detected workers +WORKERS_ENABLED := all +WORKERS_BUILT := all + DOCKER_REGISTRY := lephilousophe/scummvm DOCKER_SEPARATOR := : @@ -24,6 +32,13 @@ $(BUILDDIR)/$(1): \ $(BUILDDIR)/$(dir $(1))common \ ) endef +# Create a dependency for $(1) on another image $(2) only if $(1) is present in $(3) +define DEPEND_IMAGE +$(BUILDDIR)/$(strip $(1)): \ + $(if $(filter $(1),$(3)), \ + $(BUILDDIR)/$(strip $(2)) \ + ) +endef # Create a dependency on the toolchain of same name if it exists (used by workers) define DEPEND_TOOLCHAIN $(BUILDDIR)/$(1): \ @@ -34,6 +49,24 @@ endef # Return the docker URL with path sanitized build_docker_url = $(DOCKER_REGISTRY)$(DOCKER_SEPARATOR)$(subst /,.,$(1)) +# Let's create a list taking whitelist and blacklist into account +# First create a positive list: that takes all words which don't start with a dash, +# if it's the word all, replace it with the 2nd argument, +# else prepend the word with the 3rd argument +positive_list = $(foreach item,$(filter-out -%,$(1)), \ + $(if $(subst xall,,x$(item))$(subst x$(item),,xall), \ + $(3)$(item), \ + $(2) \ + )) +# Build the list of negative terms, do not take -all as a special term +# Take only words starting with a dash, remove it and return +negative_list = $(patsubst -%,$(2)%,$(filter -%,$(1))) +# Build a whitelist of all words based on the first argument +# Use the 2nd argument for the all keyword +# Remove the negative terms from the resulting list +# Use the 3rd argument as a prefix +filter_list = $(filter-out $(call negative_list,$(1),$(3)),$(call positive_list,$(1),$(2),$(3))) + # All these targets are directories that should be made $(BUILDDIR) $(BUILDDIR)/toolchains $(BUILDDIR)/workers: %: mkdir -p $@ @@ -42,13 +75,19 @@ $(BUILDDIR) $(BUILDDIR)/toolchains $(BUILDDIR)/workers: %: status: @echo "Buildbot version: " $(BUILDBOT_VERSION) @echo "Timestamps directory: " $(BUILDDIR) - @echo "Toolchains to preprocess: " $(TOOLCHAINS_M4) - @echo "Toolchains without preprocessing: " $(TOOLCHAINS_DOC) - @echo "All toolchains: " $(TOOLCHAINS) + @echo "Toolchains to preprocess: " $(ALL_TOOLCHAINS_M4) + @echo "Toolchains without preprocessing: " $(ALL_TOOLCHAINS_DOC) + @echo "All toolchains: " $(ALL_TOOLCHAINS) + @echo "Toolchains enabled: " $(TOOLCHAINS_ENABLED) + @echo "Toolchains to build: " $(TOOLCHAINS_BUILT) + @echo "Toolchains to download: " $(TOOLCHAINS_DOWNLOADED) @echo "Toolchains timestamps: " $(TOOLCHAINS_TS) - @echo "Workers to preprocess: " $(WORKERS_M4) - @echo "Workers without preprocessing: " $(WORKERS_DOC) - @echo "All workers: " $(WORKERS) + @echo "Workers to preprocess: " $(ALL_WORKERS_M4) + @echo "Workers without preprocessing: " $(ALL_WORKERS_DOC) + @echo "All workers: " $(ALL_WORKERS) + @echo "Workers enabled: " $(WORKERS_ENABLED) + @echo "Workers to build: " $(WORKERS_BUILT) + @echo "Workers to download: " $(WORKERS_DOWNLOADED) @echo "Workers timestamps: " $(WORKERS_TS) # Debug ccache used by workers @@ -87,27 +126,34 @@ master/buildbot.tac: $(BUILDDIR)/buildbot_installed # Toolchains rules # List all toolchains: m4 based and raw Dockerfile based -TOOLCHAINS_M4 := $(patsubst %/,%,$(dir $(wildcard toolchains/*/Dockerfile.m4))) -TOOLCHAINS_DOC := $(patsubst %/,%,$(dir $(wildcard toolchains/*/Dockerfile))) -TOOLCHAINS := $(TOOLCHAINS_M4) $(TOOLCHAINS_DOC) +ALL_TOOLCHAINS_M4 := $(patsubst %/,%,$(dir $(wildcard toolchains/*/Dockerfile.m4))) +ALL_TOOLCHAINS_DOC := $(patsubst %/,%,$(dir $(wildcard toolchains/*/Dockerfile))) +ALL_TOOLCHAINS := $(ALL_TOOLCHAINS_M4) $(ALL_TOOLCHAINS_DOC) + +# Override because we use the provided value and calculate the real one +override TOOLCHAINS_ENABLED := $(call filter_list,$(TOOLCHAINS_ENABLED),$(ALL_TOOLCHAINS),toolchains/) +override TOOLCHAINS_BUILT := $(call filter_list,$(TOOLCHAINS_BUILT),$(TOOLCHAINS_ENABLED),toolchains/) +TOOLCHAINS_DOWNLOADED := $(filter-out $(TOOLCHAINS_BUILT),$(TOOLCHAINS_ENABLED)) # Build timestamps files generated as a marker -TOOLCHAINS_M4_TS := $(foreach i,$(TOOLCHAINS_M4),$(BUILDDIR)/$(i)) -TOOLCHAINS_DOC_TS := $(foreach i,$(TOOLCHAINS_DOC),$(BUILDDIR)/$(i)) -TOOLCHAINS_TS := $(TOOLCHAINS_M4_TS) $(TOOLCHAINS_DOC_TS) +TOOLCHAINS_M4_TS := $(foreach i,$(filter $(TOOLCHAINS_BUILT),$(ALL_TOOLCHAINS_M4)),$(BUILDDIR)/$(i)) +TOOLCHAINS_DOC_TS := $(foreach i,$(filter $(TOOLCHAINS_BUILT),$(ALL_TOOLCHAINS_DOC)),$(BUILDDIR)/$(i)) +TOOLCHAINS_DL_TS := $(foreach i,$(TOOLCHAINS_DOWNLOADED),$(BUILDDIR)/$(i)) +TOOLCHAINS_TS := $(TOOLCHAINS_M4_TS) $(TOOLCHAINS_DOC_TS) $(TOOLCHAINS_DL_TS) # Build clean/push/pull rules -TOOLCHAINS_CLEAN := $(foreach i,$(TOOLCHAINS),$(i)/clean) -TOOLCHAINS_PUSH := $(foreach i,$(TOOLCHAINS),$(i)/push) -TOOLCHAINS_PULL := $(foreach i,$(TOOLCHAINS),$(i)/pull) +TOOLCHAINS_CLEAN := $(foreach i,$(TOOLCHAINS_ENABLED),$(i)/clean) +TOOLCHAINS_PUSH := $(foreach i,$(TOOLCHAINS_ENABLED),$(i)/push) +TOOLCHAINS_PULL := $(foreach i,$(TOOLCHAINS_ENABLED),$(i)/pull) # Phony rules to manage all toolchains easily -toolchains : $(TOOLCHAINS) +toolchains : $(TOOLCHAINS_ENABLED) clean-toolchains: $(TOOLCHAINS_CLEAN) push-toolchains : $(TOOLCHAINS_PUSH) pull-toolchains : $(TOOLCHAINS_PULL) -$(TOOLCHAINS): %: $(BUILDDIR)/% +# Phony rule to build one toolchain +$(TOOLCHAINS_ENABLED): %: $(BUILDDIR)/% # Phony rule to clean toolchains $(TOOLCHAINS_CLEAN): %/clean: @@ -129,7 +175,7 @@ $(TOOLCHAINS_PULL): %/pull: touch -d `docker inspect -f '{{ .Created }}' $*` $(BUILDDIR)/$* .PHONY: toolchains push-toolchains pull-toolchains clean-toolchains \ - $(TOOLCHAINS) $(TOOLCHAINS_CLEAN) $(TOOLCHAINS_PUSH) $(TOOLCHAINS_PULL) + $(TOOLCHAINS_ENABLED) $(TOOLCHAINS_CLEAN) $(TOOLCHAINS_PUSH) $(TOOLCHAINS_PULL) # Raw Dockerfile toolchains are just built using docker # They generate a timestamp file in $(BUILDDIR) @@ -152,43 +198,67 @@ endif docker build -t $* -f - $(