MAKEFILES = $(wildcard */Makefile) SUBDIRS = $(MAKEFILES:%/Makefile=%) all: build check build: $(SUBDIRS:%=build-%) check: $(SUBDIRS:%=check-%) build-%: $(MAKE) -C $* check-%: ! grep ^test: $*/Makefile || $(MAKE) -C $* test ! grep ^check: $*/Makefile || $(MAKE) -C $* check