-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
67 lines (55 loc) · 1.89 KB
/
Copy pathMakefile
File metadata and controls
67 lines (55 loc) · 1.89 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
BINARY := cc-switch-cli
MODULE := github.com/bigwhite/cc-switch-cli
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME:= $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
LDFLAGS := -s -w \
-X '$(MODULE)/cmd.Version=$(VERSION)' \
-X '$(MODULE)/cmd.Commit=$(COMMIT)' \
-X '$(MODULE)/cmd.BuildTime=$(BUILD_TIME)'
# Platforms for cross-compilation (CGO_ENABLED=0)
PLATFORMS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64
.PHONY: all build clean test lint install cross-build help
all: build
## build: Build binary for current OS/arch
build:
CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BINARY) .
## install: Install binary to $GOPATH/bin
install:
CGO_ENABLED=0 go install -ldflags "$(LDFLAGS)" .
## test: Run all tests
test:
go test -race -count=1 ./...
## test-cover: Run tests with coverage report
test-cover:
go test -race -coverprofile=coverage.out -count=1 ./...
go tool cover -func=coverage.out
## lint: Run go vet
lint:
go vet ./...
## clean: Remove build artifacts
clean:
rm -f $(BINARY) coverage.out
rm -rf dist/
## cross-build: Build for all target platforms
cross-build: clean
@mkdir -p dist
@for platform in $(PLATFORMS); do \
os=$${platform%/*}; \
arch=$${platform#*/}; \
output=dist/$(BINARY)-$${os}-$${arch}; \
if [ "$$os" = "windows" ]; then output=$${output}.exe; fi; \
echo "Building $$output ..."; \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build -ldflags "$(LDFLAGS)" -o $$output . ; \
done
@echo "Done. Binaries in dist/"
@ls -lh dist/
## release: Cross-build + show checksums
release: cross-build
@cd dist && sha256sum * > sha256sums.txt
@cat dist/sha256sums.txt
## help: Show this help
help:
@echo "Usage: make <target>"
@echo ""
@sed -n 's/^## //p' $(MAKEFILE_LIST) | column -t -s ':'