Skip to content

Instantly share code, notes, and snippets.

@bvk
Last active December 14, 2017 21:57
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 bvk/0e0ddbc73b92d42f18029472896c320e to your computer and use it in GitHub Desktop.
Save bvk/0e0ddbc73b92d42f18029472896c320e to your computer and use it in GitHub Desktop.
Run any shell command through Make environment
# 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