Created
August 27, 2022 16:05
-
-
Save ostrolucky/44e2de0938231eefff80145705b550c8 to your computer and use it in GitHub Desktop.
Makefile with dynamic jobs (separate job for each subdir). Great for monorepo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SUBDIRS := $(wildcard fe-*) | |
PROXIED_COMPOSER_COMMANDS := install build lint test | |
MAKEFLAGS := --jobs=$(words $(SUBDIRS)) | |
define make-composer-dot-rules | |
$1.$2:: | |
cd $1 && composer $2 | |
endef | |
define make-composer-rules | |
$1:: $(addsuffix .$1, $(SUBDIRS)) | |
endef | |
outer-loop = $(foreach $i,$1,$(call inner-loop,$($i),$2)) | |
inner-loop = $(foreach $i,$2,$(call make-composer-dot-rules,$1,$($i))) | |
# define rules for eg. make fe-bl-service.install | |
$(foreach SUBDIR,$(SUBDIRS),$(eval $(call outer-loop,$(SUBDIRS),$(PROXIED_COMPOSER_COMMANDS)))) | |
# define rules for eg. make install | |
$(foreach COMMAND,$(PROXIED_COMPOSER_COMMANDS),$(eval $(call make-composer-rules,$(COMMAND)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment