Skip to content

Commit 1223466

Browse files
blink-so[bot]f0ssel
andcommitted
add Makefile with build, clean, test targets
Added comprehensive Makefile with targets: - make build: Build for current platform - make build-all: Cross-platform builds - make test: Run tests - make clean: Clean artifacts - make install/uninstall: System installation - make help: Show all targets Includes version injection, coverage reports, and development tools. Co-authored-by: f0ssel <[email protected]>
1 parent f84740e commit 1223466

File tree

2 files changed

+163
-1
lines changed

2 files changed

+163
-1
lines changed

Makefile

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Makefile for jail
2+
3+
# Variables
4+
BINARY_NAME := jail
5+
BUILD_DIR := build
6+
VERSION := $(shell git describe --tags --exact-match 2>/dev/null || echo "dev-$(shell git rev-parse --short HEAD)")
7+
LDFLAGS := -s -w -X main.version=$(VERSION)
8+
9+
# Default target
10+
.PHONY: all
11+
all: build
12+
13+
# Build for current platform
14+
.PHONY: build
15+
build:
16+
@echo "Building $(BINARY_NAME) for current platform..."
17+
@echo "Version: $(VERSION)"
18+
go build -ldflags="$(LDFLAGS)" -o $(BINARY_NAME) .
19+
@echo "✓ Built $(BINARY_NAME)"
20+
21+
# Build for all supported platforms
22+
.PHONY: build-all
23+
build-all:
24+
@echo "Building $(BINARY_NAME) for all platforms..."
25+
@echo "Version: $(VERSION)"
26+
@mkdir -p $(BUILD_DIR)
27+
@echo "Building Linux amd64..."
28+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 .
29+
@echo "Building Linux arm64..."
30+
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 .
31+
@echo "Building macOS amd64..."
32+
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 .
33+
@echo "Building macOS arm64..."
34+
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 .
35+
@echo "✓ All binaries built successfully!"
36+
@echo "Binaries are in the '$(BUILD_DIR)' directory:"
37+
@ls -la $(BUILD_DIR)/
38+
39+
# Run tests
40+
.PHONY: test
41+
test:
42+
@echo "Running tests..."
43+
go test -v -race ./...
44+
@echo "✓ All tests passed!"
45+
46+
# Run tests with coverage
47+
.PHONY: test-coverage
48+
test-coverage:
49+
@echo "Running tests with coverage..."
50+
go test -v -race -coverprofile=coverage.out ./...
51+
go tool cover -html=coverage.out -o coverage.html
52+
@echo "✓ Coverage report generated: coverage.html"
53+
54+
# Clean build artifacts
55+
.PHONY: clean
56+
clean:
57+
@echo "Cleaning build artifacts..."
58+
rm -f $(BINARY_NAME)
59+
rm -rf $(BUILD_DIR)
60+
rm -f coverage.out coverage.html
61+
@echo "✓ Clean complete!"
62+
63+
# Install binary to system PATH
64+
.PHONY: install
65+
install: build
66+
@echo "Installing $(BINARY_NAME) to /usr/local/bin..."
67+
sudo cp $(BINARY_NAME) /usr/local/bin/
68+
@echo "$(BINARY_NAME) installed successfully!"
69+
70+
# Uninstall binary from system PATH
71+
.PHONY: uninstall
72+
uninstall:
73+
@echo "Uninstalling $(BINARY_NAME) from /usr/local/bin..."
74+
sudo rm -f /usr/local/bin/$(BINARY_NAME)
75+
@echo "$(BINARY_NAME) uninstalled successfully!"
76+
77+
# Format code
78+
.PHONY: fmt
79+
fmt:
80+
@echo "Formatting code..."
81+
go fmt ./...
82+
@echo "✓ Code formatted!"
83+
84+
# Lint code
85+
.PHONY: lint
86+
lint:
87+
@echo "Linting code..."
88+
@if command -v golangci-lint >/dev/null 2>&1; then \
89+
golangci-lint run; \
90+
else \
91+
echo "golangci-lint not found, running go vet instead..."; \
92+
go vet ./...; \
93+
fi
94+
@echo "✓ Linting complete!"
95+
96+
# Tidy dependencies
97+
.PHONY: tidy
98+
tidy:
99+
@echo "Tidying dependencies..."
100+
go mod tidy
101+
go mod verify
102+
@echo "✓ Dependencies tidied!"
103+
104+
# Development setup
105+
.PHONY: dev-setup
106+
dev-setup:
107+
@echo "Setting up development environment..."
108+
go mod download
109+
go mod verify
110+
@if ! command -v golangci-lint >/dev/null 2>&1; then \
111+
echo "Installing golangci-lint..."; \
112+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
113+
fi
114+
@echo "✓ Development environment ready!"
115+
116+
# Show help
117+
.PHONY: help
118+
help:
119+
@echo "Available targets:"
120+
@echo " build - Build binary for current platform"
121+
@echo " build-all - Build binaries for all supported platforms"
122+
@echo " test - Run tests"
123+
@echo " test-coverage- Run tests with coverage report"
124+
@echo " clean - Clean build artifacts"
125+
@echo " install - Install binary to /usr/local/bin"
126+
@echo " uninstall - Remove binary from /usr/local/bin"
127+
@echo " fmt - Format code"
128+
@echo " lint - Lint code (requires golangci-lint)"
129+
@echo " tidy - Tidy and verify dependencies"
130+
@echo " dev-setup - Set up development environment"
131+
@echo " help - Show this help message"
132+
@echo ""
133+
@echo "Examples:"
134+
@echo " make build # Build for current platform"
135+
@echo " make build-all # Build for all platforms"
136+
@echo " make test # Run tests"
137+
@echo " make clean # Clean build artifacts"
138+
@echo " make install # Install to system PATH"

RELEASES.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ Artifacts are kept for 30 days.
4242

4343
## Local Development
4444

45+
### Using Makefile (Recommended)
46+
47+
The project includes a Makefile with common development tasks:
48+
49+
```bash
50+
# Build for current platform
51+
make build
52+
53+
# Build for all platforms
54+
make build-all
55+
56+
# Run tests
57+
make test
58+
59+
# Clean build artifacts
60+
make clean
61+
62+
# Install to system PATH
63+
make install
64+
65+
# Show all available targets
66+
make help
67+
```
68+
4569
### Quick Build
4670

4771
Build for your current platform:
@@ -50,7 +74,7 @@ Build for your current platform:
5074
go build -o jail .
5175
```
5276

53-
### Cross-Platform Build
77+
### Cross-Platform Build Script
5478

5579
Use the provided script to build for all platforms:
5680

0 commit comments

Comments
 (0)