-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
129 lines (110 loc) · 3.57 KB
/
Makefile
File metadata and controls
129 lines (110 loc) · 3.57 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Devstrap Makefile
# Cross-platform build and release automation
# Variables
BINARY_NAME := devstrap
MODULE := github.com/codoworks/devstrap
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_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS := -ldflags "-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildDate=$(BUILD_DATE)"
# Directories
DIST_DIR := dist
SCRIPTS_DIR := scripts
# Platforms for cross-compilation
PLATFORMS := darwin/amd64 darwin/arm64 linux/amd64 linux/arm64
# Go commands
GO := go
GOTEST := $(GO) test
GOBUILD := $(GO) build
GOCLEAN := $(GO) clean
GOMOD := $(GO) mod
# Default target
.DEFAULT_GOAL := build
# Phony targets
.PHONY: all build build-all test test-coverage lint clean install uninstall release checksums help
## help: Show this help message
help:
@echo "Devstrap Makefile"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## / /'
## build: Build for current platform
build:
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) .
## build-all: Build for all platforms
build-all: clean
@mkdir -p $(DIST_DIR)
@for platform in $(PLATFORMS); do \
GOOS=$${platform%/*} GOARCH=$${platform#*/} \
$(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)_$${platform%/*}_$${platform#*/} . ; \
echo "Built: $(DIST_DIR)/$(BINARY_NAME)_$${platform%/*}_$${platform#*/}" ; \
done
## test: Run all tests
test:
$(GOTEST) -v ./...
## test-coverage: Run tests with coverage report
test-coverage:
$(GOTEST) -v -coverprofile=coverage.out ./...
$(GO) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
## lint: Run linter (requires golangci-lint)
lint:
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed. Install with: brew install golangci-lint"; \
exit 1; \
fi
## clean: Remove build artifacts
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -rf $(DIST_DIR)
rm -f coverage.out coverage.html
## install: Install to /usr/local/bin
install: build
@echo "Installing $(BINARY_NAME) to /usr/local/bin..."
@if [ -w /usr/local/bin ]; then \
cp $(BINARY_NAME) /usr/local/bin/$(BINARY_NAME); \
else \
sudo cp $(BINARY_NAME) /usr/local/bin/$(BINARY_NAME); \
fi
@echo "Installed successfully"
## uninstall: Remove from /usr/local/bin
uninstall:
@echo "Removing $(BINARY_NAME) from /usr/local/bin..."
@if [ -w /usr/local/bin ]; then \
rm -f /usr/local/bin/$(BINARY_NAME); \
else \
sudo rm -f /usr/local/bin/$(BINARY_NAME); \
fi
@echo "Uninstalled successfully"
## release: Create release tarballs for all platforms
release: build-all checksums
@echo "Creating release tarballs..."
@cd $(DIST_DIR) && for platform in $(PLATFORMS); do \
GOOS=$${platform%/*}; \
GOARCH=$${platform#*/}; \
ARCHIVE=$(BINARY_NAME)_$(VERSION)_$${GOOS}_$${GOARCH}.tar.gz; \
tar -czf $$ARCHIVE $(BINARY_NAME)_$${GOOS}_$${GOARCH}; \
rm $(BINARY_NAME)_$${GOOS}_$${GOARCH}; \
echo "Created: $(DIST_DIR)/$$ARCHIVE"; \
done
@cd $(DIST_DIR) && shasum -a 256 *.tar.gz > checksums.txt
@echo "Created: $(DIST_DIR)/checksums.txt"
## checksums: Generate SHA256 checksums
checksums:
@if [ -d $(DIST_DIR) ]; then \
cd $(DIST_DIR) && shasum -a 256 $(BINARY_NAME)_* > checksums.txt 2>/dev/null || true; \
fi
## deps: Download and tidy dependencies
deps:
$(GOMOD) download
$(GOMOD) tidy
## version: Show version information
version:
@echo "Version: $(VERSION)"
@echo "Commit: $(COMMIT)"
@echo "Date: $(BUILD_DATE)"