Skip to content

Instantly share code, notes, and snippets.

@rottenbytes
Created April 21, 2017 10:03
Show Gist options
  • Save rottenbytes/ec7ddf95f1331d0e468da212d132a5af to your computer and use it in GitHub Desktop.
Save rottenbytes/ec7ddf95f1331d0e468da212d132a5af to your computer and use it in GitHub Desktop.
Makefile with loops
OS = $(shell uname -s)
CONFIGS = $(wildcard *.js)
empty =
tab = $(empty)$(shell printf '\t')$(empty)
define execute-command
$(tab)$(1)
endef
what = $(foreach a,$(CONFIGS),./bin/dnscontrol-$(OS) -js $(a) preview${\n})
fetch-binary: ## fetch dns control binary for your OS
@echo "Please wait while fetching your binary. It will be placed in bin/"
@mkdir -p bin
@curl -s -o bin/dnscontrol-$(OS) -L https://github.com/StackExchange/dnscontrol/releases/download/latest/dnscontrol-$(OS)
preview: ## preview changes for all files
@$(foreach a,$(CONFIGS),$(call execute-command,./bin/dnscontrol-$(OS) -js $(a) preview))
push: ## push changes for all files
@$(foreach a,$(CONFIGS),$(call execute-command,./bin/dnscontrol-$(OS) -js $(a) push))
.PHONY: help preview
.DEFAULT_GOAL := help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment