Last active
December 14, 2017 21:57
-
-
Save bvk/0e0ddbc73b92d42f18029472896c320e to your computer and use it in GitHub Desktop.
Run any shell command through Make environment
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
# The following section enables users to execute arbitrary commands | |
# under Makefile environment. Users are expected run commands with | |
# 'make run' prefix. For example, | |
# | |
# $ make run go env | |
# | |
# Users can pass command-line options as follows: | |
# | |
# $ make run -- ls -l | |
# | |
# NOTE: As per http://savannah.gnu.org/bugs/?712 GNU Make doesn't | |
# handle spaces well, so this trick doesn't work when command | |
# arguments have spaces. For example, the following doesn't work: | |
# | |
# $ make run -- ls "file name" ## DOESN'T WORK | |
# | |
ifeq ($(firstword $(MAKECMDGOALS)),run) | |
.SILENT: | |
.PHONY: $(MAKECMDGOALS) | |
$(wordlist 2, 1024, $(MAKECMDGOALS)): ; | |
run: $(wordlist 2, 1024, $(MAKECMDGOALS)) | |
$^ | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment