-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
159 lines (131 loc) · 4.49 KB
/
Makefile
File metadata and controls
159 lines (131 loc) · 4.49 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
156
157
158
159
.PHONY: build build-all test test-verbose clean install uninstall help
# Variables
APP_NAME := dot
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_DIR := build
DIST_DIR := dist
# Go build flags
LDFLAGS := -ldflags "-X main.version=$(VERSION) -s -w"
GOFLAGS := -trimpath
# Default target
help: ## Show this help message
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
build: ## Build for current platform
@echo "Building $(APP_NAME) v$(VERSION) for current platform..."
@mkdir -p $(BUILD_DIR)
go build $(GOFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME) ./cmd/dot
build-all: ## Build for all supported platforms
@echo "Building $(APP_NAME) v$(VERSION) for all platforms..."
@mkdir -p $(DIST_DIR)
# macOS amd64
GOOS=darwin GOARCH=amd64 go build $(GOFLAGS) $(LDFLAGS) -o $(DIST_DIR)/$(APP_NAME)-darwin-amd64 ./cmd/dot
# macOS arm64
GOOS=darwin GOARCH=arm64 go build $(GOFLAGS) $(LDFLAGS) -o $(DIST_DIR)/$(APP_NAME)-darwin-arm64 ./cmd/dot
# Linux amd64
GOOS=linux GOARCH=amd64 go build $(GOFLAGS) $(LDFLAGS) -o $(DIST_DIR)/$(APP_NAME)-linux-amd64 ./cmd/dot
# Linux arm64
GOOS=linux GOARCH=arm64 go build $(GOFLAGS) $(LDFLAGS) -o $(DIST_DIR)/$(APP_NAME)-linux-arm64 ./cmd/dot
# Linux arm
GOOS=linux GOARCH=arm go build $(GOFLAGS) $(LDFLAGS) -o $(DIST_DIR)/$(APP_NAME)-linux-arm ./cmd/dot
@echo "Built binaries:"
@ls -la $(DIST_DIR)/
test: ## Run tests
@echo "Running tests..."
go test ./...
test-verbose: ## Run tests with verbose output
@echo "Running tests with verbose output..."
go test -v ./...
test-coverage: ## Run tests with coverage
@echo "Running tests with coverage..."
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
clean: ## Clean build artifacts
@echo "Cleaning build artifacts..."
rm -rf $(BUILD_DIR) $(DIST_DIR) coverage.out coverage.html
install: build ## Install to ~/.local/bin
@echo "Installing $(APP_NAME) to ~/.local/bin..."
@mkdir -p ~/.local/bin
cp $(BUILD_DIR)/$(APP_NAME) ~/.local/bin/$(APP_NAME)
@echo "Installed $(APP_NAME) to ~/.local/bin/$(APP_NAME)"
@echo "Make sure ~/.local/bin is in your PATH"
uninstall: ## Uninstall from ~/.local/bin
@echo "Uninstalling $(APP_NAME) from ~/.local/bin..."
rm -f ~/.local/bin/$(APP_NAME)
@echo "Uninstalled $(APP_NAME)"
format: ## Format Go code using gofmt
@echo "Formatting Go code..."
gofmt -w .
lint: ## Run linter
@echo "Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not found, running basic checks..."; \
go vet ./...; \
go fmt ./...; \
fi
tidy: ## Tidy up go modules
@echo "Tidying up go modules..."
go mod tidy
deps: ## Download dependencies
@echo "Downloading dependencies..."
go mod download
# Development targets
dev-deps: ## Install development dependencies
@echo "Installing development dependencies..."
@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
run: build ## Build and run with example config
@echo "Running $(APP_NAME)..."
./$(BUILD_DIR)/$(APP_NAME) --help
# Release targets
release-check: ## Check if ready for release
@echo "Checking if ready for release..."
@if [ -z "$(shell git status --porcelain)" ]; then \
echo "✓ Working directory is clean"; \
else \
echo "✗ Working directory has uncommitted changes"; \
exit 1; \
fi
@echo "✓ Ready for release"
# Example/demo targets
example: ## Create example configuration
@echo "Creating example dot.yaml..."
@cat > dot.yaml << 'EOF'
profiles:
"*":
bash:
link:
"bash/.bashrc": "~/.bashrc"
"bash/.bash_profile": "~/.bash_profile"
git:
link:
"git/.gitconfig": "~/.gitconfig"
install:
brew: "brew install git"
apt: "apt install -y git"
work:
ssh:
link:
"ssh/config": "~/.ssh/config"
vpn:
install:
brew: "brew install --cask viscosity"
apt: "apt install -y openvpn"
os: ["mac", "linux"]
laptop:
battery:
install:
brew: "brew install --cask battery-guardian"
os: ["mac"]
EOF
@echo "Created example dot.yaml"
demo: example build ## Create example config and run demo
@echo "Running demo..."
./$(BUILD_DIR)/$(APP_NAME) --profiles
@echo ""
@echo "Try: ./$(BUILD_DIR)/$(APP_NAME) --dry-run work"