diff --git a/Makefile b/Makefile index 5c919f75..bff35124 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ check: -@./bin/setup SUBDIRS := $(dir $(wildcard */Makefile)) -TARGETS := install clean test test-ci lint lint-ci build push # whatever else, but must not contain '/' +TARGETS := install clean test test-ci lint lint-ci # whatever else, but must not contain '/' # foo/.all bar/.all foo/.clean bar/.clean SUBDIRS_TARGETS := \ @@ -23,3 +23,29 @@ $(TARGETS): %: $(addsuffix %,$(SUBDIRS)) # $(@F:.%=%) is just all $(SUBDIRS_TARGETS): $(MAKE) --no-print-directory -C $(@D) $(@F:.%=%) + +DIFF := $(lastword $(subst /, ,${CIRCLE_COMPARE_URL})) +CHANGES := $(filter $(dir $(shell git diff --name-only $(DIFF))), $(SUBDIRS)) +.PHONY: diff +diff: + echo $(CHANGES) + +BUILDS := build push + +# foo/.all bar/.all foo/.clean bar/.clean +BUILDS_TARGETS := \ + $(foreach t,$(BUILDS),$(addsuffix $t,$(CHANGES))) + +.PHONY: $(BUILDS) $(BUILDS_TARGETS) + +# static pattern rule, expands into: +# all clean: %: foo/.% bar/.% +$(BUILDS): %: $(addsuffix %,$(CHANGES)) + @echo 'Done "$*" target' + +# here, for foo/.all: +# $(@D) is foo +# $(@F) is .all, with leading period +# $(@F:.%=%) is just all +$(BUILDS_TARGETS): + $(MAKE) --no-print-directory -C $(@D) $(@F:.%=%)