# If the first argument is "run"...
ifeq (run,$(firstword $(MAKECMDGOALS)))
# use the rest as arguments for "run"
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
$(eval $(RUN_ARGS):;@:)
endif
prog: # ...
# ...
.PHONY: run
run : prog
@echo prog $(RUN_ARGS)
# the other technique to invalidate other targets is still required, see linked post
run:
@echo ./prog $(-*-command-variables-*-) $(filter-out $@,$(MAKECMDGOALS))`
并使用它与(显式地混合参数的顺序):
make run -- config --xyz-enabled=false over=9000 --foo=bar show isit=alwaysreversed? --help
返回:
./prog isit=alwaysreversed? --foo=bar over=9000 --xyz-enabled=false config show --help
my-target: res := $(call fetch_parameter)
my-target: ## Example target. Usage: make my-target <value>
echo The value: $($@_value)
my-target2: res := $(call fetch_parameter)
my-target2: ## Example target. Usage: make my-target2 <value>
echo The value: $($@_value)