From 1bb38796ad296fb15143281a018a2803c6041b0c Mon Sep 17 00:00:00 2001 From: Christos Kontas Date: Thu, 1 Feb 2018 09:53:16 +0100 Subject: [PATCH 1/6] Makefile: simplify `clean' rule There is a special rule in make(1) to denote that we don't care about the result of a command. Additionally, we can also instruct rm(1) not to complain when it didn't find a file/directory to remove. As a final touch, there is no point of having 2 shell executions to remove 2 or more files. We can compress these 2 recipes into a single one. Reference: https://www.gnu.org/software/make/manual/html_node/Errors.html --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e58f442..d2d7d5a 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,7 @@ endif all: bin/pomo clean: - rm -v bin/* 2> /dev/null || true - rm -v docs/* 2> /dev/null || true + -rm -fv bin/* docs/* bindata.go: go-bindata -pkg main -o $@ tomato-icon.png From 295f0d024ab04540953958e2072dc633173c2c98 Mon Sep 17 00:00:00 2001 From: Christos Kontas Date: Thu, 1 Feb 2018 10:00:51 +0100 Subject: [PATCH 2/6] Makefile: add missing dependency for `www/data' --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d2d7d5a..669fd55 100644 --- a/Makefile +++ b/Makefile @@ -29,5 +29,8 @@ release: bindata.go docs: readme cd www && hugo -d ../docs -readme: +readme: www/data cat README.md | python -c 'import json,sys; print(json.dumps({"content": sys.stdin.read()}))' > www/data/readme.json + +www/data: + mkdir -p $@ From f8a7c65bf30f7c59fcc32f0c9b9bd9e8d22be97a Mon Sep 17 00:00:00 2001 From: Christos Kontas Date: Thu, 1 Feb 2018 10:06:05 +0100 Subject: [PATCH 3/6] Makefile: explicitly create bin/, if necessary Most of the go(1) tools will create the missing directory. Yet, it is better to define this dependency explicitly to make(1), to avoid unnecessary surprises. Another useful feature of make(1) is the multiple targets per rule. This way, we can have the same action and it is the target the variable of the rule, anymore. --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 669fd55..05bca0e 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,7 @@ test: go test ./... go vet ./... -release: bindata.go - @echo mkdir bin 2>/dev/null || true +release: bin bindata.go go build -ldflags "-X main.Version=$(VERSION)" -o bin/pomo-$(VERSION)-linux docs: readme @@ -32,5 +31,5 @@ docs: readme readme: www/data cat README.md | python -c 'import json,sys; print(json.dumps({"content": sys.stdin.read()}))' > www/data/readme.json -www/data: +www/data bin: mkdir -p $@ From 858872bab80ea4adb22e80f5212acf34628b1168 Mon Sep 17 00:00:00 2001 From: Christos Kontas Date: Thu, 1 Feb 2018 10:10:24 +0100 Subject: [PATCH 4/6] Makefile: split the target from the PHONY rule A PHONY rule is executed always. The target of the `readme' rule is to create the `www/data/readme.json', which depends only on `README.md'. If we specify these dependencies separately, make(1) won't build the `readme.json', if it's not necessary. And yet, we can refer to this creation by typing `make readme'. --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 05bca0e..ccbb8d6 100644 --- a/Makefile +++ b/Makefile @@ -28,8 +28,9 @@ release: bin bindata.go docs: readme cd www && hugo -d ../docs -readme: www/data - cat README.md | python -c 'import json,sys; print(json.dumps({"content": sys.stdin.read()}))' > www/data/readme.json +readme: www/data/readme.json +www/data/readme.json: www/data README.md + cat README.md | python -c 'import json,sys; print(json.dumps({"content": sys.stdin.read()}))' > www/data/readme.json www/data bin: mkdir -p $@ From a9172824a2bcbc4a5cefa7982a8b0544b82a830f Mon Sep 17 00:00:00 2001 From: Christos Kontas Date: Thu, 1 Feb 2018 10:13:39 +0100 Subject: [PATCH 5/6] Makefile: shorten recipe using default target var --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ccbb8d6..b9812e2 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,6 @@ docs: readme readme: www/data/readme.json www/data/readme.json: www/data README.md - cat README.md | python -c 'import json,sys; print(json.dumps({"content": sys.stdin.read()}))' > www/data/readme.json + cat README.md | python -c 'import json,sys; print(json.dumps({"content": sys.stdin.read()}))' > $@ www/data bin: mkdir -p $@ From abed8fd61c8633e64b1f26dc22b8d8383d99a040 Mon Sep 17 00:00:00 2001 From: Christos Kontas Date: Thu, 1 Feb 2018 10:20:12 +0100 Subject: [PATCH 6/6] Makefile: use automatic variables for bindata.go This change can easily let us expand the rule by adding more files as a dependency. Even better, we can define a variable to hold all these external, binary resources. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b9812e2..3016449 100644 --- a/Makefile +++ b/Makefile @@ -15,8 +15,8 @@ all: bin/pomo clean: -rm -fv bin/* docs/* -bindata.go: - go-bindata -pkg main -o $@ tomato-icon.png +bindata.go: tomato-icon.png + go-bindata -pkg main -o $@ $^ test: go test ./...