Skip to content

Instantly share code, notes, and snippets.

@hatappo
Last active Nov 13, 2021
Embed
What would you like to do?
A template of what to write when creating a simple task runner in Makefile. / Makefileで簡易的なタスク・ランナー作るときによく書くことの雛形。
.DEFAULT_GOAL := help
TS := $(shell date +%Y%m%d%H%M%S)
.PHONY: help
help: ## print main target list with descriptions
@grep -E '^[a-zA-Z][a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help_all
help_all: ## print ALL target list with descriptions
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: _sample_confirm
_sample_confirm: ## Confirmation prompt example
@read -p "Are you sure you want to continue (Y/n) " r; if [ "$$r" != "Y" ]; then exit 1; fi
echo $(TS) "Something critical task."
.PHONY: run
run: ## Run the server on local
go run server.go
.PHONY: browse_local_app
browse_local_app: ## Open the local app in a default browser
open http://127.0.0.1:1111
.PHONY: browse_production_app
browse_production_app: ## Open the production app in a default browser
open https://example.com/
$ make
browse_local_app Open the local app in a default browser
browse_production_app Open the production app in a default browser
help print main target list with descriptions
help_all print ALL target list with descriptions
run Run the server on local
$ make help_all
_sample_confirm Confirmation prompt example
browse_local_app Open the local app in a default browser
browse_production_app Open the production app in a default browser
help print main target list with descriptions
help_all print ALL target list with descriptions
run Run the server on local
@hatappo
Copy link
Author

hatappo commented May 20, 2016

nodejs なら npm script ( npm run user_defined_task )使ったほうがシンプルかな

@hatappo
Copy link
Author

hatappo commented Nov 13, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment