-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
94 lines (80 loc) · 3.01 KB
/
Makefile
File metadata and controls
94 lines (80 loc) · 3.01 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
# File: Makefile
# Purpose: Build automation for devsetup Go binary
# Problem: Need consistent commands for building, testing, and installing
# Role: Provides make targets for common development tasks
# Usage: Run `make` or `make build` to compile, `make install` to install globally
# Design choices: Uses Go build with version injection; supports multiple architectures
# Assumptions: Go 1.21+ installed; running on macOS
.PHONY: all build install clean test lint help
# Version info (injected at build time)
GIT_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "v0.1.0")
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
VERSION := $(GIT_TAG)+$(GIT_COMMIT)
BUILD_TIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
# Build flags
LDFLAGS := -ldflags "-X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME) -X main.gitCommit=$(GIT_COMMIT)"
# Binary name
BINARY_NAME := devsetup
# Default target
all: build
## build: Build the devsetup binary for current architecture
build:
@echo "Building $(BINARY_NAME) (version: $(VERSION))..."
go build $(LDFLAGS) -o $(BINARY_NAME) ./cmd/devsetup
@echo "✅ Built: ./$(BINARY_NAME)"
## build-all: Build binaries for all supported architectures
build-all:
@echo "Building for all architectures..."
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BINARY_NAME)-darwin-amd64 ./cmd/devsetup
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o $(BINARY_NAME)-darwin-arm64 ./cmd/devsetup
@echo "✅ Built:"
@echo " - $(BINARY_NAME)-darwin-amd64 (Intel Mac)"
@echo " - $(BINARY_NAME)-darwin-arm64 (Apple Silicon)"
## install: Build and install to ~/.local/bin
install: build
@echo "Installing $(BINARY_NAME) to ~/.local/bin..."
@mkdir -p ~/.local/bin
@cp $(BINARY_NAME) ~/.local/bin/$(BINARY_NAME)
@chmod +x ~/.local/bin/$(BINARY_NAME)
@echo "✅ Installed: ~/.local/bin/$(BINARY_NAME)"
@echo ""
@echo "Ensure ~/.local/bin is in your PATH:"
@echo ' export PATH="$$HOME/.local/bin:$$PATH"'
## test: Run all tests
test:
@echo "Running tests..."
go test -v -race -coverprofile=coverage.out ./...
@echo "✅ Tests passed"
## lint: Run linters (requires golangci-lint)
lint:
@echo "Running linters..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./... && \
echo "✅ Linting passed"; \
else \
echo "⚠️ golangci-lint not installed. Install with:"; \
echo " brew install golangci-lint"; \
fi
## clean: Remove build artifacts
clean:
@echo "Cleaning build artifacts..."
rm -f $(BINARY_NAME) $(BINARY_NAME)-*
rm -f coverage.out
@echo "✅ Cleaned"
## run: Build and run with install command
run: build
@echo "Running $(BINARY_NAME) install..."
./$(BINARY_NAME) install
## dry-run: Build and run in dry-run mode
dry-run: build
@echo "Running $(BINARY_NAME) install --dry-run..."
./$(BINARY_NAME) install --dry-run
## help: Show this help message
help:
@echo "devsetup Makefile"
@echo ""
@echo "Usage:"
@echo " make <target>"
@echo ""
@echo "Targets:"
@sed -n 's/^##//p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /'