Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
90 lines (69 loc) · 2.65 KB
/
Copy pathMakefile
File metadata and controls
90 lines (69 loc) · 2.65 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
# diskcli Makefile
APP = diskcli
GO = go
BUILD_DIR = ./dist
# Version info (passed via ldflags at build time).
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS = -s -w \
-X main.version=$(VERSION) \
-X main.commit=$(COMMIT) \
-X main.date=$(DATE)
# ---------------------------------------------------------------------------
# Build
# ---------------------------------------------------------------------------
.PHONY: all
all: build
.PHONY: build
build:
$(GO) build -trimpath -ldflags="$(LDFLAGS)" -o $(APP) ./cmd/$(APP)
# Cross-compile for multiple platforms.
.PHONY: build-all
build-all:
GOOS=linux GOARCH=amd64 $(GO) build -trimpath -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(APP)-linux-amd64 ./cmd/$(APP)
GOOS=linux GOARCH=arm64 $(GO) build -trimpath -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(APP)-linux-arm64 ./cmd/$(APP)
GOOS=darwin GOARCH=amd64 $(GO) build -trimpath -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(APP)-darwin-amd64 ./cmd/$(APP)
GOOS=darwin GOARCH=arm64 $(GO) build -trimpath -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(APP)-darwin-arm64 ./cmd/$(APP)
GOOS=windows GOARCH=amd64 $(GO) build -trimpath -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(APP)-windows-amd64.exe ./cmd/$(APP)
@echo "✓ All binaries built in $(BUILD_DIR)/"
# ---------------------------------------------------------------------------
# Test & lint
# ---------------------------------------------------------------------------
.PHONY: test
test:
$(GO) test ./... -count=1
.PHONY: test-cover
test-cover:
$(GO) test ./... -coverprofile=coverage.out
.PHONY: vet
vet:
$(GO) vet ./...
.PHONY: lint
lint:
golangci-lint run ./...
.PHONY: check
check: vet lint test
@echo "✓ All checks passed"
# ---------------------------------------------------------------------------
# Docker
# ---------------------------------------------------------------------------
.PHONY: docker-build
docker-build:
docker build -t diskcli .
.PHONY: docker-buildx
docker-buildx:
docker buildx build --platform linux/amd64,linux/arm64 -t diskcli .
# ---------------------------------------------------------------------------
# Clean
# ---------------------------------------------------------------------------
.PHONY: clean
clean:
rm -rf $(APP) $(BUILD_DIR) coverage.out
# ---------------------------------------------------------------------------
# Install
# ---------------------------------------------------------------------------
.PHONY: install
install:
$(GO) install -ldflags="$(LDFLAGS)" ./cmd/$(APP)
.DEFAULT_GOAL := all