Skip to content

Instantly share code, notes, and snippets.

@trinitronx

trinitronx/Makefile

Last active Feb 28, 2018
Embed
What would you like to do?
grc + make + read bash builtin bug reproduction test case
.PHONY: help list clean
UID := $(shell id -u)
interactive := $(shell [ -t 0 ] && echo 1)
ifeq (1,$(interactive))
INTERACTIVE_SHELL := true
endif
define set-env
$(eval SOME_ENV_VAR := $(shell \
if [[ -z "$(SOME_ENV_VAR)" ]]; then
read -r -p "Enter SOME_ENV_VAR (eg 'bar') (set environment variable SOME_ENV_VAR to skip this prompt): "; \
echo $$REPLY;
fi;
))
@if [[ -z "$(SOME_ENV_VAR)" ]]; then \
echo "You must specify SOME_ENV_VAR or set env variable SOME_ENV_VAR !"; \
false; \
fi;
endef
# Auto-documented Makefile
# Source: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## Shows this generated help info for Makefile targets
@grep -Eh '^[a-zA-Z_-]+:.*?(## )?.*$$' $(MAKEFILE_LIST) | sort | awk '{ if ( $$0 ~ /^[a-zA-Z_-]+:.*?## ?.*$$/ ) { split($$0,resultArr,/:.*## /) ; printf "\033[36m%-30s\033[0m %s\n", resultArr[1], resultArr[2] } else if ( $$0 ~ /^[a-zA-Z_-]+:.*$$/ ) { split($$0,resultArr,/:.*?/); printf "\033[36m%-30s\033[0m\n", resultArr[1] } } '
list: ## Just list all Makefile targets without help
@$(MAKE) -pRrq $(addprefix -f ,$(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs
test: ## run terraform plan with given parameters
$(set-env)
@$(MAKE) SOME_ENV_VAR=$(SOME_ENV_VAR) foo
foo:
echo "SOME_ENV_VAR is $(SOME_ENV_VAR)"
echo "INTERACTIVE_SHELL is $(INTERACTIVE_SHELL)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.