Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
303 lines (244 loc) · 13.1 KB
/
Copy pathMakefile
File metadata and controls
303 lines (244 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# generated with CMTools 0.0.0 f50285c
#
# Simple Makefile for Golang based Projects built under POSIX.
#
PROJECT = fdx
GIT_GROUP = rsdoiel
PROGRAMS = fdx2txt txt2fdx
RELEASE_DATE = $(shell date +%Y-%m-%d)
RELEASE_HASH=$(shell git log --pretty=format:'%h' -n 1)
MAN_PAGES_1 = $(shell ls -1 *.1.md | sed -E 's/.1.md/.1/g')
# None of these projects has a section 3 or 7 man page; uncomment to add one.
#MAN_PAGES_3 = $(shell ls -1 *.3.md | sed -E 's/.3.md/.3/g')
#MAN_PAGES_7 = $(shell ls -1 *.7.md | sed -E 's/.7.md/.7/g')
HTML_PAGES = $(shell find . -type f -not -path './bin/*' -not -path './.git/*' | grep -E '\.html$$')
DOCS = $(shell ls -1 *.?.md)
# version.go is left out: it has a rule (cmt, under generate), and listing it
# here would make every build run cmt through that rule.
PACKAGE = $(filter-out version.go,$(shell ls -1 *.go))
VERSION = $(shell grep '"version":' codemeta.json | cut -d\" -f 4)
BRANCH = $(shell git branch --show-current)
OS = $(shell uname)
#PREFIX = /usr/local/bin
PREFIX = $(HOME)
ifneq ($(prefix),)
PREFIX = $(prefix)
endif
EXT =
ifeq ($(OS), Windows)
EXT = .exe
endif
# build compiles the programs and regenerates the help text and man pages. It
# does not run cmt: version.go, CITATION.cff, about.md and the installers are
# generated from codemeta.json by `make generate`, so the version and release
# hash change only when that is asked for (the release target does).
build: $(PROGRAMS) man
# generate runs cmt over codemeta.json. Run it when the version, the release
# notes or the metadata change, and before a release; a plain `make` leaves
# the committed version.go, about.md and friends alone.
generate: version.go CITATION.cff about.md installer.sh installer.ps1
version.go: .FORCE
cmt codemeta.json version.go
hash: .FORCE
git log --pretty=format:'%h' -n 1
man: $(MAN_PAGES_1) # $(MAN_PAGES_3) $(MAN_PAGES_7)
$(MAN_PAGES_1): .FORCE
mkdir -p man/man1
pandoc $@.md --from markdown --to man -s >man/man1/$@
#$(MAN_PAGES_3): .FORCE
# mkdir -p man/man3
# pandoc $@.md --from markdown --to man -s >man/man3/$@
#$(MAN_PAGES_7): .FORCE
# mkdir -p man/man7
# pandoc $@.md --from markdown --to man -s >man/man7/$@
$(PROGRAMS): $(PACKAGE)
@mkdir -p bin
go build -o "bin/$@$(EXT)" cmd/$@/*.go
@./bin/$@ -help >$@.1.md
CITATION.cff: .FORCE
cmt codemeta.json CITATION.cff
about.md: codemeta.json $(PROGRAMS)
cmt codemeta.json about.md
installer.sh: .FORCE
cmt codemeta.json installer.sh
installer.ps1: .FORCE
cmt codemeta.json installer.ps1
# check reports files gofmt would change, and vets; it rewrites nothing.
check: .FORCE
@UNFORMATTED="$$(gofmt -l $(filter-out version.go,$(shell ls -1 *.go)) cmd)"; if [ "$$UNFORMATTED" != "" ]; then echo "gofmt would change:"; echo "$$UNFORMATTED"; fi
go vet ./...
test: $(PACKAGE)
go test -cover ./...
website: clean-website .FORCE
make -f website.mak
status:
git status
save:
@if [ "$(msg)" != "" ]; then git commit -am "$(msg)"; else git commit -am "Quick Save"; fi
git push origin $(BRANCH)
refresh:
git fetch origin
git pull origin $(BRANCH)
publish: build website .FORCE
./publish.bash
clean:
@if [ -f version.go ]; then rm version.go; fi
@if [ -d bin ]; then rm -fR bin; fi
@if [ -d dist ]; then rm -fR dist; fi
@if [ -d man ]; then rm -fR man; fi
@if [ -d testout ]; then rm -fR testout; fi
clean-website:
@for FNAME in $(HTML_PAGES); do if [ -f "$${FNAME}" ]; then rm "$${FNAME}"; fi; done
install: build
@echo "Installing programs in $(PREFIX)/bin"
@for FNAME in $(PROGRAMS); do if [ -f "./bin/$${FNAME}$(EXT)" ]; then mv -v "./bin/$${FNAME}$(EXT)" "$(PREFIX)/bin/$${FNAME}$(EXT)"; fi; done
@echo ""
@echo "Make sure $(PREFIX)/bin is in your PATH"
@echo "Installing man page in $(PREFIX)/man"
@mkdir -p $(PREFIX)/man/man1
@for FNAME in $(MAN_PAGES_1); do if [ -f "./man/man1/$${FNAME}" ]; then cp -v "./man/man1/$${FNAME}" "$(PREFIX)/man/man1/$${FNAME}"; fi; done
# @mkdir -p $(PREFIX)/man/man3
# @for FNAME in $(MAN_PAGES_3); do if [ -f "./man/man3/$${FNAME}" ]; then cp -v "./man/man3/$${FNAME}" "$(PREFIX)/man/man3/$${FNAME}"; fi; done
# @mkdir -p $(PREFIX)/man/man7
# @for FNAME in $(MAN_PAGES_7); do if [ -f "./man/man7/$${FNAME}" ]; then cp -v "./man/man7/$${FNAME}" "$(PREFIX)/man/man7/$${FNAME}"; fi; done
@echo ""
@echo "Make sure $(PREFIX)/man is in your MANPATH"
uninstall: .FORCE
@echo "Removing programs in $(PREFIX)/bin"
@for FNAME in $(PROGRAMS); do if [ -f "$(PREFIX)/bin/$${FNAME}$(EXT)" ]; then rm -v "$(PREFIX)/bin/$${FNAME}$(EXT)"; fi; done
@echo "Removing man pages in $(PREFIX)/man"
@for FNAME in $(MAN_PAGES_1); do if [ -f "$(PREFIX)/man/man1/$${FNAME}" ]; then rm -v "$(PREFIX)/man/man1/$${FNAME}"; fi; done
# @for FNAME in $(MAN_PAGES_3); do if [ -f "$(PREFIX)/man/man3/$${FNAME}" ]; then rm -v "$(PREFIX)/man/man3/$${FNAME}"; fi; done
# @for FNAME in $(MAN_PAGES_7); do if [ -f "$(PREFIX)/man/man7/$${FNAME}" ]; then rm -v "$(PREFIX)/man/man7/$${FNAME}"; fi; done
setup_dist: .FORCE
@mkdir -p dist
@rm -fR dist/
dist/Linux-x86_64: $(PROGRAMS)
@mkdir -p dist/bin
@for FNAME in $(PROGRAMS); do env GOOS=linux GOARCH=amd64 go build -o "dist/bin/$${FNAME}" cmd/$${FNAME}/*.go; done
@cd dist && zip -r $(PROJECT)-v$(VERSION)-Linux-x86_64.zip LICENSE codemeta.json CITATION.cff *.md bin/* man/* $(DOCS)
@rm -fR dist/bin
dist/Linux-aarch64: $(PROGRAMS)
@mkdir -p dist/bin
@for FNAME in $(PROGRAMS); do env GOOS=linux GOARCH=arm64 go build -o "dist/bin/$${FNAME}" cmd/$${FNAME}/*.go; done
@cd dist && zip -r $(PROJECT)-v$(VERSION)-Linux-aarch64.zip LICENSE codemeta.json CITATION.cff *.md bin/* man/* $(DOCS)
@rm -fR dist/bin
dist/macOS-x86_64: $(PROGRAMS)
@mkdir -p dist/bin
@for FNAME in $(PROGRAMS); do env GOOS=darwin GOARCH=amd64 go build -o "dist/bin/$${FNAME}" cmd/$${FNAME}/*.go; done
@cd dist && zip -r $(PROJECT)-v$(VERSION)-macOS-x86_64.zip LICENSE codemeta.json CITATION.cff *.md bin/* man/* $(DOCS)
@rm -fR dist/bin
dist/macOS-arm64: $(PROGRAMS)
@mkdir -p dist/bin
@for FNAME in $(PROGRAMS); do env GOOS=darwin GOARCH=arm64 go build -o "dist/bin/$${FNAME}" cmd/$${FNAME}/*.go; done
@cd dist && zip -r $(PROJECT)-v$(VERSION)-macOS-arm64.zip LICENSE codemeta.json CITATION.cff *.md bin/* man/* $(DOCS)
@rm -fR dist/bin
dist/Windows-x86_64: $(PROGRAMS)
@mkdir -p dist/bin
@for FNAME in $(PROGRAMS); do env GOOS=windows GOARCH=amd64 go build -o "dist/bin/$${FNAME}.exe" cmd/$${FNAME}/*.go; done
@cd dist && zip -r $(PROJECT)-v$(VERSION)-Windows-x86_64.zip LICENSE codemeta.json CITATION.cff *.md bin/* man/* $(DOCS)
@rm -fR dist/bin
dist/Windows-arm64: $(PROGRAMS)
@mkdir -p dist/bin
@for FNAME in $(PROGRAMS); do env GOOS=windows GOARCH=arm64 go build -o "dist/bin/$${FNAME}.exe" cmd/$${FNAME}/*.go; done
@cd dist && zip -r $(PROJECT)-v$(VERSION)-Windows-arm64.zip LICENSE codemeta.json CITATION.cff *.md bin/* man/* $(DOCS)
@rm -fR dist/bin
distribute_docs:
@mkdir -p dist/
@cp -v codemeta.json dist/
@cp -v CITATION.cff dist/
@cp -v README.md dist/
@cp -v LICENSE dist/
@cp -v INSTALL.md dist/
@cp -vR man dist/
@for DNAME in $(DOCS); do cp -vR $$DNAME dist/; done
# check-go-version enforces the Go version policy (workspace Go version policy): the minimum Go is
# the highest version the release was built with, and every file that states it agrees.
# It writes nothing. It fails when
# - the go line of go.mod is lower than the Go in use (go env GOVERSION),
# - the "Go >= " line of codemeta.json is not the go line of go.mod,
# A go line without a patch ("1.27") is read as 1.27.0. check-release runs it.
check-go-version: .FORCE
@FAIL=0; \
bad() { echo "check-go-version: $$1"; FAIL=1; }; \
full() { case "$$1" in *.*.*) echo "$$1";; *) echo "$$1.0";; esac; }; \
TC="$$(go env GOVERSION | sed 's/^go//')"; \
case "$$TC" in [0-9]*.[0-9]*) ;; *) TC="";; esac; \
case "$$TC" in *[!0-9.]*) TC="";; esac; \
if [ -z "$$TC" ]; then bad "cannot read the Go version from go env GOVERSION (a release is built with a tagged Go)"; \
else \
TC="$$(full "$$TC")"; \
GM="$$(full "$$(sed -n 's/^go \([0-9.]*\).*/\1/p' go.mod | head -1)")"; \
LOW="$$(printf '%s\n%s\n' "$$GM" "$$TC" | sort -V | head -1)"; \
[ "$$GM" = "$$TC" ] || [ "$$LOW" != "$$GM" ] || bad "go.mod says go $$GM, the Go in use is $$TC: the minimum is the highest version the release is built with"; \
CM="$$(jq -r '[.softwareRequirements[]? | select(startswith("Go >= "))][0] // empty | sub("Go >= "; "")' codemeta.json)"; \
[ -n "$$CM" ] || bad "codemeta.json has no \"Go >= \" line in softwareRequirements"; \
[ -z "$$CM" ] || [ "$$(full "$$CM")" = "$$GM" ] || bad "codemeta.json says Go >= $$CM, go.mod says go $$GM"; \
fi; \
if [ $$FAIL -ne 0 ]; then exit 1; fi; \
echo "check-go-version: Go $$GM is consistent"
# check-committed (workspace DR-0012) makes a release come from one known commit:
# it fails when tracked files have uncommitted changes, or when HEAD is not the
# tip of the branch on origin (unpushed, or behind). Untracked files (bin/, dist/,
# man/) are ignored, as git ignores them. It writes nothing.
check-committed: .FORCE
@FAIL=0; \
bad() { echo "check-committed: $$1"; FAIL=1; }; \
DIRTY="$$(git status --porcelain --untracked-files=no)"; \
[ -z "$$DIRTY" ] || { bad "tracked files have uncommitted changes (commit and push them):"; echo "$$DIRTY"; }; \
REMOTE="$$(git ls-remote origin "refs/heads/$(BRANCH)" 2>/dev/null | cut -f1)"; \
[ -n "$$REMOTE" ] || bad "cannot find branch $(BRANCH) on origin (push it)"; \
[ -z "$$REMOTE" ] || [ "$$REMOTE" = "$$(git rev-parse HEAD)" ] || bad "HEAD is not the tip of origin/$(BRANCH) (push, or pull first)"; \
if [ $$FAIL -ne 0 ]; then exit 1; fi; \
echo "check-committed: $$(git rev-parse --short HEAD) is committed and pushed"
# check-release reads the files a release is cut from and fails when they
# disagree; it writes nothing. Run it before `make release` (the release target
# runs it too). It fails when
# - version.go, CITATION.cff or an installer carries a version other than codemeta.json's,
# or CITATION.cff's date-released is not datePublished (run `make generate`),
# - datePublished is not today's date, the release day,
# - v$(VERSION) is already tagged here or on origin (codemeta.json was not bumped),
# - releaseNotes are the same as the last tag's (not written for this release),
# - softwareRequirements names a github.com/rsdoiel module at a version go.mod does not require,
# - the Go version policy fails (check-go-version),
# - the tree is not committed and pushed (check-committed, workspace DR-0012).
check-release: .FORCE
@FAIL=0; V="$(VERSION)"; TODAY="$$(date +%Y-%m-%d)"; \
bad() { echo "check-release: $$1"; FAIL=1; }; \
[ -n "$$V" ] || bad "codemeta.json has no version"; \
GOV="$$(sed -n 's/^ *Version = "\(.*\)".*/\1/p' version.go | head -1)"; \
[ "$$GOV" = "$$V" ] || bad "version.go has '$$GOV', codemeta.json has '$$V' (run make generate)"; \
CFF="$$(sed -n 's/^version: *//p' CITATION.cff | head -1)"; \
[ "$$CFF" = "$$V" ] || bad "CITATION.cff has '$$CFF', codemeta.json has '$$V' (run make generate)"; \
DR="$$(sed -n 's/^date-released: *//p' CITATION.cff | head -1)"; \
PUB="$$(jq -r '.datePublished // empty' codemeta.json)"; \
[ "$$DR" = "$$PUB" ] || bad "CITATION.cff date-released is '$$DR', datePublished is '$$PUB' (run make generate)"; \
[ "$$PUB" = "$$TODAY" ] || bad "datePublished is '$$PUB', today is '$$TODAY': set datePublished and dateModified to the release day"; \
for F in installer.sh installer.ps1; do \
[ -f "$$F" ] || continue; \
IV="$$(grep -m1 'VERSION *= *"' "$$F" | sed 's/.*VERSION *= *"\([^"]*\)".*/\1/')"; \
[ "$$IV" = "$$V" ] || bad "$$F has '$$IV', codemeta.json has '$$V' (run make generate)"; \
done; \
if git rev-parse -q --verify "refs/tags/v$$V" >/dev/null; then bad "v$$V is already tagged here: codemeta.json was not bumped"; fi; \
if git ls-remote --exit-code --tags origin "refs/tags/v$$V" >/dev/null 2>&1; then bad "v$$V is already tagged on origin: codemeta.json was not bumped"; fi; \
NEW="$$(jq -r '.releaseNotes // empty' codemeta.json)"; \
[ -n "$$NEW" ] || bad "codemeta.json has no releaseNotes"; \
LAST="$$(git tag --list 'v*' --sort=-v:refname | head -1)"; \
if [ -n "$$LAST" ] && [ "$$LAST" != "v$$V" ]; then \
OLD="$$(git show "$$LAST:codemeta.json" 2>/dev/null | jq -r '.releaseNotes // empty')"; \
[ "$$NEW" != "$$OLD" ] || bad "releaseNotes are the same as $$LAST's: write them for v$$V"; \
fi; \
for REQ in $$(jq -r '.softwareRequirements[]? | select(startswith("github.com/rsdoiel/")) | gsub(" "; "@")' codemeta.json); do \
M="$${REQ%%@*}"; MIN="$${REQ##*@}"; \
GM="$$(grep -o "$$M v[^ ]*" go.mod | head -1 | sed 's/.* v//')"; \
[ -n "$$GM" ] || { bad "softwareRequirements names $$M, which go.mod does not require"; continue; }; \
[ "$$GM" = "$$MIN" ] || bad "softwareRequirements says $$M >= $$MIN, go.mod requires v$$GM"; \
done; \
$(MAKE) -s check-go-version || FAIL=1; \
$(MAKE) -s check-committed || FAIL=1; \
if [ $$FAIL -ne 0 ]; then echo "check-release: v$$V is NOT ready to release"; exit 1; fi; \
echo "check-release: v$$V is consistent"
release: check-release build setup_dist distribute_docs dist/Linux-x86_64 dist/Linux-aarch64 dist/macOS-x86_64 dist/macOS-arm64 dist/Windows-x86_64 dist/Windows-arm64
@$(MAKE) -s check-committed
@printf "\nready to run\n\n\trelease.bash\n\n"
.FORCE: