Skip to content

Instantly share code, notes, and snippets.

@ydnar
Created January 28, 2020 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ydnar/2096c5198f31d86f8d520fb7e5658fd8 to your computer and use it in GitHub Desktop.
Save ydnar/2096c5198f31d86f8d520fb7e5658fd8 to your computer and use it in GitHub Desktop.
Recursive make with positional arguments
# 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