Created
January 28, 2020 17:30
-
-
Save ydnar/2096c5198f31d86f8d520fb7e5658fd8 to your computer and use it in GitHub Desktop.
Recursive make with positional arguments
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
# To make a sandwich: | |
# $ make <track> sandwich | |
# e.g.: make alpha sandwich | |
# | |
# This works by rewriting MAKECMDGOALS by stripping the argument from the list | |
# and recursively calling make with a variable assignment (e.g. track=alpha) | |
# and the remaining goal(s). | |
# | |
# The ifeq below ensures that the “real” goals aren’t executed unless the | |
# track variable is set. The @: command silences the “Nothing to be done” | |
# warning. | |
alpha beta: track = $@ | |
alpha beta: goals = $(patsubst $@,,$(MAKECMDGOALS)) | |
alpha beta: | |
@$(MAKE) track=$(track) $(goals) | |
ifeq ($(track),) | |
sandwich: | |
@: | |
else | |
sandwich_type = sandwich-$(track) | |
sandwich: | |
@test $(track) | |
@echo Making $(sandwich_type) | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment