-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
132 lines (106 loc) · 4.43 KB
/
Makefile
File metadata and controls
132 lines (106 loc) · 4.43 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
.PHONY: build build-all test lint clean run help
# Build variables
BINARY_NAME=houndoom
BUILD_DIR=bin
VERSION?=1.0.0
COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildTime=$(BUILD_TIME)"
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=$(GOCMD) fmt
GOVET=$(GOCMD) vet
help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Available targets:'
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
build: ## Build the binary for current platform
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) cmd/scanner/main.go
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
build-all: ## Build for all platforms (Linux, Windows, macOS)
@echo "Building for all platforms..."
@mkdir -p $(BUILD_DIR)
@echo "Building for Linux amd64..."
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 cmd/scanner/main.go
@echo "Building for Linux arm64..."
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 cmd/scanner/main.go
@echo "Building for Windows amd64..."
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe cmd/scanner/main.go
@echo "Building for macOS amd64..."
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 cmd/scanner/main.go
@echo "Building for macOS arm64..."
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 cmd/scanner/main.go
@echo "Build complete for all platforms!"
test: ## Run tests
@echo "Running tests..."
$(GOTEST) -v -race -coverprofile=coverage.txt -covermode=atomic ./...
@echo "Tests complete!"
test-coverage: ## Run tests with coverage report
@echo "Running tests with coverage..."
$(GOTEST) -v -race -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
bench: ## Run benchmarks
@echo "Running benchmarks..."
$(GOTEST) -bench=. -benchmem ./...
lint: ## Run linter
@echo "Running linter..."
@which golangci-lint > /dev/null || (echo "Installing golangci-lint..." && go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest)
golangci-lint run ./...
@echo "Linting complete!"
fmt: ## Format code
@echo "Formatting code..."
$(GOFMT) ./...
@echo "Formatting complete!"
vet: ## Run go vet
@echo "Running go vet..."
$(GOVET) ./...
@echo "Vetting complete!"
deps: ## Download dependencies
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
@echo "Dependencies downloaded!"
clean: ## Clean build artifacts
@echo "Cleaning..."
$(GOCLEAN)
rm -rf $(BUILD_DIR)
rm -f coverage.txt coverage.out coverage.html
@echo "Clean complete!"
run: build ## Build and run the scanner
@echo "Running $(BINARY_NAME)..."
./$(BUILD_DIR)/$(BINARY_NAME) --help
run-scan: build ## Build and run a test scan
@echo "Running test scan..."
./$(BUILD_DIR)/$(BINARY_NAME) scan . --mode=fast
install: build ## Install the binary to GOPATH/bin
@echo "Installing $(BINARY_NAME)..."
cp $(BUILD_DIR)/$(BINARY_NAME) $(GOPATH)/bin/
@echo "Installation complete!"
docker-build: ## Build Docker image
@echo "Building Docker image..."
docker build -t houndoom:$(VERSION) .
@echo "Docker build complete!"
docker-run: docker-build ## Run in Docker container
@echo "Running in Docker..."
docker run --rm -v $(PWD):/scan houndoom:$(VERSION) scan /scan
release: ## Create a release (requires VERSION environment variable)
@echo "Creating release $(VERSION)..."
@mkdir -p $(BUILD_DIR)/release
@make build-all
@cd $(BUILD_DIR) && \
tar -czf release/$(BINARY_NAME)-$(VERSION)-linux-amd64.tar.gz $(BINARY_NAME)-linux-amd64 && \
tar -czf release/$(BINARY_NAME)-$(VERSION)-linux-arm64.tar.gz $(BINARY_NAME)-linux-arm64 && \
tar -czf release/$(BINARY_NAME)-$(VERSION)-darwin-amd64.tar.gz $(BINARY_NAME)-darwin-amd64 && \
tar -czf release/$(BINARY_NAME)-$(VERSION)-darwin-arm64.tar.gz $(BINARY_NAME)-darwin-arm64 && \
zip -q release/$(BINARY_NAME)-$(VERSION)-windows-amd64.zip $(BINARY_NAME)-windows-amd64.exe
@echo "Release $(VERSION) created in $(BUILD_DIR)/release/"
.DEFAULT_GOAL := help