Created
November 1, 2019 16:17
-
-
Save stavxyz/47c2770a9c7215d4083e307c192c7dcd to your computer and use it in GitHub Desktop.
makefile, act like a CLI
This file contains 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
# | |
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage