DIRS=externals Utils Database all: $(DIRS) clean: clean-dirs clean-dirs: for i in $(DIRS) ; do $(MAKE) -C $$i clean ; done .PHONY: $(DIRS) define DIR_template $(1): $$(MAKE) -C $$@ endef $(foreach dir, $(DIRS), $(eval $(call DIR_template, $(dir))))