Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
111 lines (93 loc) · 3.7 KB
/
Copy pathMakefile
File metadata and controls
111 lines (93 loc) · 3.7 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
.PHONY: build build-all clean test test-coverage lint fmt install uninstall release release-snapshot help
# Version and build info
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 "-X github.com/munichmade/devproxy/cmd/devproxy/cmd.Version=$(VERSION) -X github.com/munichmade/devproxy/cmd/devproxy/cmd.Commit=$(COMMIT) -X github.com/munichmade/devproxy/cmd/devproxy/cmd.BuildDate=$(BUILD_DATE)"
# Binary info
BINARY := devproxy
BUILD_DIR := bin
INSTALL_DIR := /opt/homebrew/bin
# Platforms for cross-compilation
PLATFORMS := darwin/amd64 darwin/arm64 linux/amd64 linux/arm64
# Default target
.DEFAULT_GOAL := build
## help: Show this help message
help:
@echo "DevProxy - Local Development Reverse Proxy"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## / /'
## build: Build binary for current platform
build:
@mkdir -p $(BUILD_DIR)
go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY) ./cmd/devproxy
## build-all: Build for all platforms (darwin/linux, amd64/arm64)
build-all:
@mkdir -p $(BUILD_DIR)
@for platform in $(PLATFORMS); do \
GOOS=$${platform%/*} GOARCH=$${platform#*/} \
go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY)-$${platform%/*}-$${platform#*/} ./cmd/devproxy; \
echo "Built $(BINARY)-$${platform%/*}-$${platform#*/}"; \
done
## clean: Remove build artifacts
clean:
rm -rf $(BUILD_DIR)
go clean -cache -testcache
## test: Run tests
test:
go test -v ./...
## test-coverage: Run tests with coverage report
test-coverage:
@mkdir -p $(BUILD_DIR)
go test -v -coverprofile=$(BUILD_DIR)/coverage.out ./...
go tool cover -html=$(BUILD_DIR)/coverage.out -o $(BUILD_DIR)/coverage.html
@echo "Coverage report: $(BUILD_DIR)/coverage.html"
## lint: Run golangci-lint
lint:
@which golangci-lint > /dev/null || (echo "Installing golangci-lint..." && go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest)
golangci-lint run ./...
## fmt: Format code
fmt:
go fmt ./...
@which goimports > /dev/null && goimports -local github.com/munichmade/devproxy -w . || true
## install: Build and install to /usr/local/bin
install: build
@echo "Installing $(BINARY) to $(INSTALL_DIR)..."
@rm $(INSTALL_DIR)/$(BINARY) || echo "No install yet"
@cp $(BUILD_DIR)/$(BINARY) $(INSTALL_DIR)/$(BINARY)
@chmod +x $(INSTALL_DIR)/$(BINARY)
@echo "Installed successfully"
## uninstall: Remove from /usr/local/bin
uninstall:
@echo "Removing $(BINARY) from $(INSTALL_DIR)..."
@sudo rm -f $(INSTALL_DIR)/$(BINARY)
@echo "Uninstalled successfully"
## release: Create release archives for all platforms
release: build-all
@mkdir -p $(BUILD_DIR)/release
@for platform in $(PLATFORMS); do \
os=$${platform%/*}; \
arch=$${platform#*/}; \
name=$(BINARY)-$(VERSION)-$$os-$$arch; \
if [ "$$os" = "windows" ]; then \
zip -j $(BUILD_DIR)/release/$$name.zip $(BUILD_DIR)/$(BINARY)-$$os-$$arch; \
else \
tar -czf $(BUILD_DIR)/release/$$name.tar.gz -C $(BUILD_DIR) $(BINARY)-$$os-$$arch; \
fi; \
echo "Created $$name archive"; \
done
@echo "Release archives in $(BUILD_DIR)/release/"
## run: Run the daemon in foreground
run: build
$(BUILD_DIR)/$(BINARY) run
## dev: Run with live reload (requires entr)
dev:
@which entr > /dev/null || (echo "Please install entr: brew install entr" && exit 1)
find . -name '*.go' | entr -r make run
## release-snapshot: Test release locally without publishing (uses goreleaser)
release-snapshot:
@which goreleaser > /dev/null || (echo "Installing goreleaser..." && go install github.com/goreleaser/goreleaser/v2@latest)
goreleaser release --snapshot --clean