-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
61 lines (48 loc) · 1.47 KB
/
Makefile
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
BASE_DIR := $(shell git rev-parse --show-toplevel 2>/dev/null)
GITCOMMIT := $(shell git rev-parse --short HEAD 2>/dev/null)
GIT_TAG := $(shell git describe --tags 2>/dev/null)
LDFLAGS := -X main.commit=${GITCOMMIT}
LDFLAGS := ${LDFLAGS} -X main.tag=${GIT_TAG}
OUTFILE ?= s3backup
.PHONY: precommit
precommit: clean generate format lint test compile
.PHONY: build
build: clean compile
.PHONY: commit
commit: clean test cross-compile
ls -lha target/
.PHONY: clean
clean:
rm -rf target
target:
mkdir target
.PHONY: format
format:
goimports -w -local github.com/tomcz/s3backup cmd/ internal/ tools/
.PHONY: lint
lint:
golangci-lint run
.PHONY: test
test:
go test -race -cover ./...
.PHONY: generate
generate:
go generate ./internal/...
./tools/stubs.sh
.PHONY: compile
compile: target
go build -ldflags "${LDFLAGS}" -o target/${OUTFILE} ./cmd/s3backup/...
gzip -k target/${OUTFILE}
.PHONY: cross-compile
cross-compile:
OUTFILE=s3backup-linux-amd64 GOOS=linux GOARCH=amd64 $(MAKE) compile
OUTFILE=s3backup-linux-nocgo CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(MAKE) compile
OUTFILE=s3backup-osx-amd64 GOOS=darwin GOARCH=amd64 $(MAKE) compile
OUTFILE=s3backup-osx-arm64 GOOS=darwin GOARCH=arm64 $(MAKE) compile
OUTFILE=s3backup-win-amd64.exe GOOS=windows GOARCH=amd64 $(MAKE) compile
OUTFILE=s3backup-win-386.exe GOOS=windows GOARCH=386 $(MAKE) compile
(cd target && find . -name '*.gz' -exec sha256sum {} \;) > target/verify.sha256
.PHONY: vendor
vendor:
go mod tidy
go mod vendor