Skip to content

Instantly share code, notes, and snippets.

@stavxyz
Created November 1, 2019 16:17
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 stavxyz/47c2770a9c7215d4083e307c192c7dcd to your computer and use it in GitHub Desktop.
Save stavxyz/47c2770a9c7215d4083e307c192c7dcd to your computer and use it in GitHub Desktop.
makefile, act like a CLI
#
# HACKS TO MAKE THIS BEHAVE MORE LIKE A CLI
#
PASS_ARGS_COMMANDS := run-command next-command-not-yet-implemented
FIRST_TARGET := $(firstword $(MAKECMDGOALS))
ifneq ($(filter $(FIRST_TARGET),$(PASS_ARGS_COMMANDS)),)
# use the rest as arguments to pass to subcommand
$(info $(FIRST_TARGET) is a pass-args command)
PASS_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
$(eval $(PASS_ARGS):dummy;@:)
PASS_ARGS := $(if $(PASS_ARGS),$(PASS_ARGS),-h)
endif
# </HACKS>
.PHONY: run-command
run-command:
$(info executing --> $@ $(PASS_ARGS))
command $(PASS_ARGS)
@stavxyz
Copy link
Author

stavxyz commented Nov 1, 2019

usage

make -- run-command --with somearg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment