-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
155 lines (131 loc) · 4.67 KB
/
Copy pathMakefile
File metadata and controls
155 lines (131 loc) · 4.67 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Makefile for respec
# Metadata
BINARY := respec
VERSION ?= $(shell git describe --tags --always --dirty)
COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Platforms to build for (OS-ARCH)
PLATFORMS := linux-amd64 linux-arm64 darwin-amd64 darwin-arm64 windows-amd64
# Output directory
DIST := dist
# Installation directory
INSTALL_PREFIX ?= $(HOME)/.local
INSTALL_DIR := $(INSTALL_PREFIX)/bin
# Go module name from go.mod
MODULE := $(shell go list -m)
# ldflags to inject version info into the binary
LDFLAGS := -s -w -buildid= -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)'
.PHONY: all build clean release version install uninstall debug test lint fmt tidy deps dev-setup help
# Default target builds for the current OS/architecture
build: $(DIST)/$(BINARY)
# Local build target
$(DIST)/$(BINARY):
@mkdir -p $(DIST)
go build -trimpath -ldflags="$(LDFLAGS)" -o $(DIST)/$(BINARY) ./cmd/respec
# Debug build - builds and installs to local system
debug: build install
@echo "✅ Debug build installed to $(INSTALL_DIR)/$(BINARY)"
@echo "💡 Run with: $(BINARY) --help"
# Install the binary to local system
install:
@echo "📦 Installing $(BINARY) to $(INSTALL_DIR)..."
@mkdir -p $(INSTALL_DIR)
@cp $(DIST)/$(BINARY) $(INSTALL_DIR)/
@chmod +x $(INSTALL_DIR)/$(BINARY)
@echo "✅ Installed $(BINARY) to $(INSTALL_DIR)"
@echo "💡 Make sure $(INSTALL_DIR) is in your PATH"
@echo " export PATH=\"$(INSTALL_DIR):\$$PATH\""
# Uninstall the binary from local system
uninstall:
@echo "🗑️ Removing $(BINARY) from $(INSTALL_DIR)..."
@rm -f $(INSTALL_DIR)/$(BINARY)
@echo "✅ Uninstalled $(BINARY)"
# Cross-platform builds for all defined platforms
all: $(PLATFORMS:%=$(DIST)/$(BINARY)-%)
$(DIST)/$(BINARY)-%:
@platform="$*"; \
os=$${platform%-*}; arch=$${platform#*-}; \
outfile="$(DIST)/$(BINARY)-$$os-$$arch"; \
if [ "$$os" = "windows" ]; then outfile="$$outfile.exe"; fi; \
mkdir -p $(DIST); \
echo "--> Building for $$os/$$arch..."; \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 \
go build -trimpath -ldflags="$(LDFLAGS)" -o "$$outfile" ./cmd/respec
# Clean the dist directory
clean:
@rm -rf $(DIST)
# The release target builds all platforms, zips the artifacts, and creates a checksum file.
release: clean all
@echo "--> Zipping release artifacts...";
@for platform in $(PLATFORMS); do \
os=$${platform%-*}; arch=$${platform#*-}; \
base="$(DIST)/$(BINARY)-$$os-$$arch"; \
out="$$base"; \
if [ "$$os" = "windows" ]; then out="$$base.exe"; fi; \
zipfile="$$base.zip"; \
zip -j "$$zipfile" "$$out"; \
done
@echo "--> Generating checksums...";
@cd $(DIST) && (command -v sha256sum >/dev/null && sha256sum *.zip > SHA256SUMS || shasum -a 256 *.zip > SHA256SUMS)
# Show version info
version:
@echo "Version: $(VERSION)"
@echo "Commit: $(COMMIT)"
@echo "BuildDate: $(DATE)"
# Run tests
test:
@echo "🧪 Running tests..."
go test -v ./...
# Run linter
lint:
@echo "🔍 Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "⚠️ golangci-lint not found. Install it with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
go vet ./...; \
fi
# Format code
fmt:
@echo "🎨 Formatting code..."
go fmt ./...
# Tidy dependencies
tidy:
@echo "🧹 Tidying dependencies..."
go mod tidy
# Download dependencies
deps:
@echo "📦 Downloading dependencies..."
go mod download
# Development setup
dev-setup: deps
@echo "🛠️ Setting up development environment..."
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "📦 Installing golangci-lint..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
fi
@echo "✅ Development environment ready!"
@echo "💡 Run 'make debug' to build and install locally"
# Show help
help:
@echo "respec - OpenAPI Generator for Go"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo " build Build the binary for the current platform"
@echo " debug Build and install to local system ($(INSTALL_DIR))"
@echo " install Install the built binary to local system"
@echo " uninstall Remove the binary from local system"
@echo " all Cross-compile for all platforms"
@echo " release Cross-compile for all platforms and zip outputs"
@echo " clean Remove build artifacts"
@echo " test Run tests"
@echo " lint Run linter"
@echo " fmt Format code"
@echo " tidy Tidy dependencies"
@echo " deps Download dependencies"
@echo " dev-setup Setup development environment"
@echo " version Show version metadata"
@echo " help Show this help message"
@echo ""