-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
59 lines (43 loc) · 1.8 KB
/
Copy pathMakefile
File metadata and controls
59 lines (43 loc) · 1.8 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
.PHONY: build install test lint fmt clean release help
# Variables
BINARY_NAME=howtfdoi
VERSION?=dev
BUILD_FLAGS=-ldflags="-s -w -X main.version=$(VERSION)"
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
build: ## Build the binary
go build $(BUILD_FLAGS) -o $(BINARY_NAME)
install: ## Install to GOPATH/bin
go install $(BUILD_FLAGS)
test: ## Run tests
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
lint: ## Run linters
golangci-lint run
fmt: ## Format code
go fmt ./...
goimports -w .
clean: ## Remove build artifacts
rm -f $(BINARY_NAME)
rm -f coverage.txt
rm -f howtfdoi-*
run: build ## Build and run
./$(BINARY_NAME)
# Cross-compilation targets
build-linux: ## Build for Linux
GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o $(BINARY_NAME)-linux-amd64
build-darwin: ## Build for macOS
GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAGS) -o $(BINARY_NAME)-darwin-amd64
GOOS=darwin GOARCH=arm64 go build $(BUILD_FLAGS) -o $(BINARY_NAME)-darwin-arm64
build-windows: ## Build for Windows
GOOS=windows GOARCH=amd64 go build $(BUILD_FLAGS) -o $(BINARY_NAME)-windows-amd64.exe
build-all: build-linux build-darwin build-windows ## Build for all platforms
release: clean build-all ## Create release artifacts
tar czf $(BINARY_NAME)-linux-amd64.tar.gz $(BINARY_NAME)-linux-amd64
tar czf $(BINARY_NAME)-darwin-amd64.tar.gz $(BINARY_NAME)-darwin-amd64
tar czf $(BINARY_NAME)-darwin-arm64.tar.gz $(BINARY_NAME)-darwin-arm64
zip $(BINARY_NAME)-windows-amd64.zip $(BINARY_NAME)-windows-amd64.exe
pre-commit-install: ## Install pre-commit hooks
pre-commit install
pre-commit install --hook-type commit-msg
pre-commit-run: ## Run pre-commit on all files
pre-commit run --all-files