Last active
November 13, 2021 21:22
-
-
Save hatappo/687df87ebaae92a2394ab249ee406bb3 to your computer and use it in GitHub Desktop.
A template of what to write when creating a simple task runner in Makefile. / Makefileで簡易的なタスク・ランナー作るときによく書くことの雛形。
This file contains 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
.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/ |
This file contains 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
$ 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考 - https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html