-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
200 lines (175 loc) · 6.26 KB
/
Copy pathMakefile
File metadata and controls
200 lines (175 loc) · 6.26 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
# SecScan Makefile
#
# NOTE: This Makefile is designed for Linux/macOS systems.
# Windows users should use install.ps1 instead, or the universal installer: go run installer/install.go
#
# The install/install-local targets use Unix-specific paths and commands.
# Variables
BINARY_NAME=secscan
VERSION=2.2.0
BUILD_DIR=build
INSTALL_PATH=/usr/local/bin
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
# Build flags
LDFLAGS=-ldflags "-X main.Version=$(VERSION) -s -w"
.PHONY: all build clean test install uninstall run help install-local
## help: Display this help message
help:
@echo "SecScan v$(VERSION) - Makefile Commands"
@echo ""
@echo "⚠️ IMPORTANT: This Makefile is for Linux/macOS only"
@echo " Windows users should use: install.ps1"
@echo " Or use the universal installer: go run installer/install.go"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "⚡ Quick Start:"
@echo " make install - Build and install globally (recommended, requires sudo)"
@echo " make install-local - Build and install to ~/.local/bin (no sudo)"
@echo ""
@echo "Targets:"
@grep -E '^##' Makefile | sed 's/##//g'
## all: Build for all platforms
all: clean build-linux build-darwin build-windows
## build-all: Build for all platforms (alias for all)
build-all: all
## build: Build for current platform
build:
@echo "Building $(BINARY_NAME) v$(VERSION)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) main.go
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
## build-linux: Build for Linux (amd64)
build-linux:
@echo "Building for Linux..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 main.go
@echo "Linux build complete"
## build-darwin: Build for macOS (amd64 and arm64)
build-darwin:
@echo "Building for macOS..."
@mkdir -p $(BUILD_DIR)
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 main.go
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 main.go
@echo "macOS builds complete"
## build-windows: Build for Windows (amd64)
build-windows:
@echo "Building for Windows..."
@mkdir -p $(BUILD_DIR)
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe main.go
@echo "Windows build complete"
## test: Run tests
test:
@echo "Running tests..."
$(GOTEST) -v -cover ./...
## clean: Remove build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
@rm -rf $(BUILD_DIR)
@rm -f $(BINARY_NAME)
@rm -f *.json
@echo "Clean complete"
## install: Install to system (requires sudo) - RECOMMENDED
install: build
@echo "Installing $(BINARY_NAME) to $(INSTALL_PATH)..."
@if [ -f ~/.local/bin/$(BINARY_NAME) ]; then \
echo "Warning: $(BINARY_NAME) already exists in ~/.local/bin"; \
echo " Removing old version from ~/.local/bin..."; \
rm -f ~/.local/bin/$(BINARY_NAME); \
fi
@sudo cp $(BUILD_DIR)/$(BINARY_NAME) $(INSTALL_PATH)/
@sudo chmod +x $(INSTALL_PATH)/$(BINARY_NAME)
@echo "✓ Installed successfully to $(INSTALL_PATH)/$(BINARY_NAME)"
@echo ""
@echo "Verify installation:"
@echo " $(BINARY_NAME) -version"
@echo " which $(BINARY_NAME)"
## install-local: Install to ~/.local/bin (no sudo required)
install-local: build
@echo "Installing $(BINARY_NAME) to ~/.local/bin..."
@if [ -f $(INSTALL_PATH)/$(BINARY_NAME) ]; then \
echo "Warning: $(BINARY_NAME) already exists in $(INSTALL_PATH)"; \
echo " You may want to run 'sudo make uninstall' first"; \
echo " Continuing with local installation..."; \
echo ""; \
fi
@mkdir -p ~/.local/bin
@cp $(BUILD_DIR)/$(BINARY_NAME) ~/.local/bin/
@chmod +x ~/.local/bin/$(BINARY_NAME)
@echo "✓ Installed successfully to ~/.local/bin/$(BINARY_NAME)"
@echo ""
@if echo $$PATH | grep -q "$$HOME/.local/bin"; then \
echo "~/.local/bin is already in your PATH"; \
echo "Verify installation:"; \
echo " $(BINARY_NAME) -version"; \
else \
echo "~/.local/bin is NOT in your PATH"; \
echo "Add this line to your ~/.bashrc or ~/.zshrc:"; \
echo " export PATH=\"\$$HOME/.local/bin:\$$PATH\""; \
echo "Then run: source ~/.bashrc (or ~/.zshrc)"; \
fi
## uninstall: Remove from system (requires sudo)
uninstall:
@echo "Uninstalling $(BINARY_NAME)..."
@if [ -f $(INSTALL_PATH)/$(BINARY_NAME) ]; then \
sudo rm -f $(INSTALL_PATH)/$(BINARY_NAME); \
echo "✓ Removed $(INSTALL_PATH)/$(BINARY_NAME)"; \
else \
echo " $(BINARY_NAME) not found in $(INSTALL_PATH)"; \
fi
@if [ -f ~/.local/bin/$(BINARY_NAME) ]; then \
rm -f ~/.local/bin/$(BINARY_NAME); \
echo "✓ Removed ~/.local/bin/$(BINARY_NAME)"; \
else \
echo " $(BINARY_NAME) not found in ~/.local/bin"; \
fi
@echo "Uninstall complete"
## run: Build and run with default options
run: build
@echo "Running $(BINARY_NAME)..."
@$(BUILD_DIR)/$(BINARY_NAME)
## run-verbose: Build and run with verbose output
run-verbose: build
@$(BUILD_DIR)/$(BINARY_NAME) -verbose
## run-fast: Build and run without git history
run-fast: build
@$(BUILD_DIR)/$(BINARY_NAME) -history=false
## fmt: Format Go code
fmt:
@echo "Formatting code..."
@gofmt -s -w main.go
@echo "Format complete"
## lint: Run linter
lint:
@echo "Running linter..."
@if command -v golangci-lint > /dev/null; then \
golangci-lint run; \
else \
echo "golangci-lint not installed. Install from https://golangci-lint.run/"; \
fi
## deps: Download dependencies
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
@echo "Dependencies updated"
## release: Create release builds for all platforms
release: clean all
@echo "Creating release archives..."
@mkdir -p $(BUILD_DIR)/releases
@cd $(BUILD_DIR) && tar -czf releases/$(BINARY_NAME)-$(VERSION)-linux-amd64.tar.gz $(BINARY_NAME)-linux-amd64
@cd $(BUILD_DIR) && tar -czf releases/$(BINARY_NAME)-$(VERSION)-darwin-amd64.tar.gz $(BINARY_NAME)-darwin-amd64
@cd $(BUILD_DIR) && tar -czf releases/$(BINARY_NAME)-$(VERSION)-darwin-arm64.tar.gz $(BINARY_NAME)-darwin-arm64
@cd $(BUILD_DIR) && zip -q releases/$(BINARY_NAME)-$(VERSION)-windows-amd64.zip $(BINARY_NAME)-windows-amd64.exe
@echo "Release archives created in $(BUILD_DIR)/releases/"
## version: Display version information
version:
@echo "SecScan v$(VERSION)"
.DEFAULT_GOAL := help