Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
52 lines (39 loc) · 2.03 KB
/
Copy pathMakefile
File metadata and controls
52 lines (39 loc) · 2.03 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
BIN := gitnotesync
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
LDFLAGS := -s -w -X github.com/kvth/gitnotesync/cmd.Version=$(VERSION)
# Packages are for ARCH (Go's name: amd64, arm64, ...) and built from a release:
# their version is the vX.Y.Z tag on HEAD, with the tree clean
ARCH ?= $(shell go env GOARCH)
PKG_VERSION = $(patsubst v%,%,$(VERSION))
# nfpm installed by install-deps; nfpm from PATH is used if there is one
NFPM_VERSION ?= v2.47.0
GO_BIN = $(or $(shell go env GOBIN 2>/dev/null),$(shell go env GOPATH 2>/dev/null)/bin)
NFPM ?= $(or $(shell command -v nfpm 2>/dev/null),$(GO_BIN)/nfpm)
.PHONY: build test vet fmt packages deb rpm package-files check-version install-deps clean
build:
go build -ldflags '$(LDFLAGS)' -o $(BIN) .
test:
go test ./...
vet:
go vet ./...
fmt:
gofmt -l -w .
packages: deb rpm
deb rpm: package-files
ARCH=$(ARCH) PKG_VERSION=$(PKG_VERSION) $(NFPM) package -p $@ -t build/
# What nfpm.yaml packs: a static binary for ARCH, completions generated by a
# host build (the ARCH one may not run here), and the unit started from /usr/bin
package-files: check-version
mkdir -p build/completions
CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -trimpath -ldflags '$(LDFLAGS)' -o build/$(BIN) .
for sh in bash zsh fish; do go run . completion $$sh > build/completions/$(BIN).$$sh || exit 1; done
sed 's|%h/\.local/bin/$(BIN)|/usr/bin/$(BIN)|' contrib/systemd/$(BIN)@.service > build/$(BIN)@.service
@grep -q '^ExecStart=/usr/bin/$(BIN) ' build/$(BIN)@.service || { echo "ExecStart in contrib/systemd/$(BIN)@.service not rewritten to /usr/bin" >&2; exit 1; }
check-version:
@echo '$(PKG_VERSION)' | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$$' || { echo "version '$(VERSION)' is not a release: tag it with git tag vX.Y.Z and commit any changes" >&2; exit 1; }
install-deps:
@command -v go >/dev/null || { echo "go missing: install Go first, e.g. apt install golang-go" >&2; exit 1; }
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@$(NFPM_VERSION)
clean:
rm -f $(BIN)
rm -rf build