-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
228 lines (189 loc) · 8.57 KB
/
Copy pathMakefile
File metadata and controls
228 lines (189 loc) · 8.57 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
BINARY_NAME=bbpts
CMD_PATH=./cmd/bbpts
INSTALL_PATH=/usr/local/bin
BINARY_DIR=bin
VERSION=v1.5.0
COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
LDFLAGS=-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)
ifeq ($(OS),Windows_NT)
BINARY_EXT=.exe
else
BINARY_EXT=
endif
.PHONY: all build build-full build-fleet build-release dist test test-short test-race bench \
lint vet fmt security doctor validate validate-framework clean install \
install-user uninstall uninstall-user setup help coverage docker
all: build
build:
@echo " Building $(BINARY_NAME)$(BINARY_EXT)..."
@mkdir -p $(BINARY_DIR)
go build -ldflags "$(LDFLAGS)" -o $(BINARY_DIR)/$(BINARY_NAME)$(BINARY_EXT) $(CMD_PATH)
@echo " Build complete: ./$(BINARY_DIR)/$(BINARY_NAME)$(BINARY_EXT)"
build-full:
@echo " Building with NATS + Redis support..."
@mkdir -p $(BINARY_DIR)
go build -tags nats,redis -ldflags "$(LDFLAGS)" -o $(BINARY_DIR)/$(BINARY_NAME)$(BINARY_EXT) $(CMD_PATH)
@echo " Full build complete: ./$(BINARY_DIR)/$(BINARY_NAME)$(BINARY_EXT)"
build-fleet:
@echo " Building fleet-enabled binary (NATS + Redis + Playwright)..."
@mkdir -p $(BINARY_DIR)
go build -tags nats,redis,playwright -ldflags "$(LDFLAGS)" -o $(BINARY_DIR)/$(BINARY_NAME)-fleet$(BINARY_EXT) $(CMD_PATH)
@echo " Fleet build complete: ./$(BINARY_DIR)/$(BINARY_NAME)-fleet$(BINARY_EXT)"
build-release:
@echo " Building release binary with optimizations..."
@mkdir -p $(BINARY_DIR)
CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -trimpath -o $(BINARY_DIR)/$(BINARY_NAME)$(BINARY_EXT) $(CMD_PATH)
dist:
@echo " Building all platform binaries → dist/"
@mkdir -p dist
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -trimpath -o dist/bbpts_linux_amd64 $(CMD_PATH)
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -trimpath -o dist/bbpts_linux_arm64 $(CMD_PATH)
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "$(LDFLAGS)" -trimpath -o dist/bbpts_linux_386 $(CMD_PATH)
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -trimpath -o dist/bbpts_darwin_amd64 $(CMD_PATH)
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -trimpath -o dist/bbpts_darwin_arm64 $(CMD_PATH)
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -trimpath -o dist/bbpts_windows_amd64.exe $(CMD_PATH)
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -trimpath -o dist/bbpts_windows_arm64.exe $(CMD_PATH)
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -trimpath -o dist/bbpts_freebsd_amd64 $(CMD_PATH)
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -trimpath -o dist/bbpts_freebsd_arm64 $(CMD_PATH)
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags "$(LDFLAGS)" -trimpath -o dist/bbpts_freebsd_386 $(CMD_PATH)
CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -trimpath -o dist/bbpts_openbsd_amd64 $(CMD_PATH)
CGO_ENABLED=0 GOOS=openbsd GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -trimpath -o dist/bbpts_openbsd_arm64 $(CMD_PATH)
@echo " All binaries written to ./dist/"
@ls -lh dist/
test:
@echo " Running all tests..."
go test -v -count=1 ./...
test-short:
@echo " Running short tests..."
go test -short ./...
test-race:
@echo " Running tests with race detector..."
go test -v -race -count=1 ./...
coverage:
@echo " Generating coverage report..."
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo " Coverage report: coverage.html"
bench:
@echo " Running benchmarks..."
go test -bench=. -benchmem -run=^$$ ./... | tee benchmark.txt
@echo " Benchmark results: benchmark.txt"
lint:
@echo " Running linter..."
golangci-lint run --timeout=5m ./...
vet:
@echo " Running go vet..."
go vet ./...
fmt:
@echo " Formatting code..."
gofmt -s -w .
@echo " Code formatted"
security:
@echo " Running security scan..."
@which gosec > /dev/null 2>&1 || (echo "Installing gosec..." && go install github.com/securego/gosec/v2/cmd/gosec@latest)
gosec -fmt=json -out=gosec-report.json ./... || true
@echo " Security report: gosec-report.json"
@echo " Running govulncheck..."
@which govulncheck > /dev/null 2>&1 || (echo "Installing govulncheck..." && go install golang.org/x/vuln/cmd/govulncheck@latest)
govulncheck ./... || true
doctor: build
@echo " Running environment diagnostics..."
./$(BINARY_DIR)/$(BINARY_NAME)$(BINARY_EXT) -doctor
validate: build
@echo " Validating configuration..."
./$(BINARY_DIR)/$(BINARY_NAME)$(BINARY_EXT) -validate-config
validate-framework: build
@echo " Running full deterministic validation framework..."
bash tests/test.sh
install: build setup
ifeq ($(OS),Windows_NT)
@echo "Install target not fully supported on Windows via Makefile. Please copy $(BINARY_DIR)/$(BINARY_NAME).exe to your PATH."
else
@echo " Installing $(BINARY_NAME) to $(INSTALL_PATH)..."
@if [ -w $(INSTALL_PATH) ] || sudo cp $(BINARY_DIR)/$(BINARY_NAME) $(INSTALL_PATH); then \
echo " Installed to $(INSTALL_PATH)"; \
else \
echo " Failed to install to $(INSTALL_PATH). Trying $(HOME)/.local/bin..."; \
mkdir -p $(HOME)/.local/bin && cp $(BINARY_DIR)/$(BINARY_NAME) $(HOME)/.local/bin/; \
echo " Installed to $(HOME)/.local/bin"; \
fi
@echo " Setting up global configurations in $(HOME)/.bbpts..."
@mkdir -p $(HOME)/.bbpts/wordlists $(HOME)/.bbpts/state
@cp -n configs/config.json $(HOME)/.bbpts/ 2>/dev/null || true
@cp -n configs/rules.json $(HOME)/.bbpts/ 2>/dev/null || true
@cp -r wordlists/* $(HOME)/.bbpts/wordlists/
endif
install-user: build setup
@echo " Installing $(BINARY_NAME) to $(HOME)/.local/bin..."
@mkdir -p $(HOME)/.local/bin
@cp $(BINARY_DIR)/$(BINARY_NAME) $(HOME)/.local/bin/
@echo " Installed to $(HOME)/.local/bin"
@echo " Setting up global configurations in $(HOME)/.bbpts..."
@mkdir -p $(HOME)/.bbpts/wordlists $(HOME)/.bbpts/state
@cp -n configs/config.json $(HOME)/.bbpts/ 2>/dev/null || true
@cp -n configs/rules.json $(HOME)/.bbpts/ 2>/dev/null || true
@cp -r wordlists/* $(HOME)/.bbpts/wordlists/
@echo " Make sure '$(HOME)/.local/bin' is in your PATH to use '$(BINARY_NAME)' globally."
uninstall-user:
@echo " Removing $(BINARY_NAME) from $(HOME)/.local/bin..."
@rm -f $(HOME)/.local/bin/$(BINARY_NAME)
@echo " Removed"
uninstall:
ifeq ($(OS),Windows_NT)
@echo "Uninstall target not supported on Windows via Makefile."
else
@echo " Removing $(BINARY_NAME) from $(INSTALL_PATH)..."
@sudo rm -f $(INSTALL_PATH)/$(BINARY_NAME)
@echo " Removed from $(INSTALL_PATH)"
endif
setup:
@echo " Running cross-platform setup..."
bash scripts/setup.sh
docker:
@echo " Building Docker image..."
docker build -t $(BINARY_NAME):$(VERSION) -t $(BINARY_NAME):latest .
@echo " Docker image built: $(BINARY_NAME):$(VERSION)"
clean:
@echo " Cleaning up..."
rm -rf $(BINARY_DIR) coverage.out coverage.html benchmark.txt gosec-report.json
go clean
@echo " Clean"
help:
@echo ""
@echo "╔══════════════════════════════════════════════╗"
@echo "║ BBPTS Makefile Targets ║"
@echo "╚══════════════════════════════════════════════╝"
@echo ""
@echo " Build:"
@echo " build Build the binary (debug)"
@echo " build-full Build with NATS + Redis support"
@echo " build-fleet Build with NATS + Redis + Playwright"
@echo " build-release Build optimized release binary (current platform)"
@echo " dist Cross-compile for Linux/macOS/Windows → dist/"
@echo " docker Build Docker image"
@echo ""
@echo " Test:"
@echo " test Run all tests with verbose output"
@echo " test-short Run short tests only"
@echo " test-race Run tests with race detector"
@echo " coverage Generate HTML coverage report"
@echo " bench Run performance benchmarks"
@echo ""
@echo " Code Quality:"
@echo " lint Run golangci-lint"
@echo " vet Run go vet"
@echo " fmt Format all Go code"
@echo " security Run gosec + govulncheck"
@echo ""
@echo " Diagnostics:"
@echo " doctor Check tool availability & system health"
@echo " validate Validate config file"
@echo " validate-framework Run deterministic validation lab and benchmarks"
@echo ""
@echo " Lifecycle:"
@echo " setup Install system dependencies"
@echo " install Build and install to $(INSTALL_PATH)"
@echo " uninstall Remove from $(INSTALL_PATH)"
@echo " clean Remove build artifacts"
@echo ""