-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
165 lines (140 loc) · 4.62 KB
/
Makefile
File metadata and controls
165 lines (140 loc) · 4.62 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
# Makefile for webshell-detect
# Variables
APP_NAME := webshell-detect
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
GO_VERSION := $(shell go version | awk '{print $$3}')
# Build flags
LDFLAGS := -ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME) -X main.GitCommit=$(GIT_COMMIT) -X main.GoVersion=$(GO_VERSION) -w -s"
# Directories
CMD_DIR := ./cmd/$(APP_NAME)
OUTPUT_DIR := ./output
CONFIG_DIR := ./config
# Default target
.PHONY: all
all: clean build
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(OUTPUT_DIR)
@mkdir -p $(OUTPUT_DIR)
# Build for current platform
.PHONY: build
build:
@echo "Building $(APP_NAME) for current platform..."
@go build $(LDFLAGS) -o $(OUTPUT_DIR)/$(APP_NAME) $(CMD_DIR)
# Build for Linux
.PHONY: build-linux
build-linux:
@echo "Building $(APP_NAME) for Linux..."
@GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(OUTPUT_DIR)/$(APP_NAME)-linux $(CMD_DIR)
# Build for macOS
.PHONY: build-macos
build-macos:
@echo "Building $(APP_NAME) for macOS..."
@GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(OUTPUT_DIR)/$(APP_NAME)-macos $(CMD_DIR)
# Build for Windows
.PHONY: build-windows
build-windows:
@echo "Building $(APP_NAME) for Windows..."
@GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o $(OUTPUT_DIR)/$(APP_NAME)-windows.exe $(CMD_DIR)
# Build for all platforms
.PHONY: build-all
build-all: build-linux build-macos build-windows
# Package Linux build
.PHONY: package-linux
package-linux: build-linux
@echo "Packaging Linux build..."
@tar -czf $(OUTPUT_DIR)/$(APP_NAME)-linux-default-x86_64-$(VERSION).tar.gz -C $(OUTPUT_DIR) $(APP_NAME)-linux -C ../$(CONFIG_DIR) conf.yaml mock.php
# Package macOS build
.PHONY: package-macos
package-macos: build-macos
@echo "Packaging macOS build..."
@tar -czf $(OUTPUT_DIR)/$(APP_NAME)-macos-default-x86_64-$(VERSION).tar.gz -C $(OUTPUT_DIR) $(APP_NAME)-macos -C ../$(CONFIG_DIR) conf.yaml mock.php
# Package Windows build
.PHONY: package-windows
package-windows: build-windows
@echo "Packaging Windows build..."
@cd $(OUTPUT_DIR) && zip $(APP_NAME)-windows-default-x86_64-$(VERSION).zip $(APP_NAME)-windows.exe ../$(CONFIG_DIR)/conf.yaml ../$(CONFIG_DIR)/mock.php
# Package all builds
.PHONY: package-all
package-all: package-linux package-macos package-windows
# Release (build and package all)
.PHONY: release
release: clean build-all package-all
@echo "Release $(VERSION) completed!"
@ls -la $(OUTPUT_DIR)/
# Test
.PHONY: test
test:
@echo "Running tests..."
@go test -v ./...
# Test with coverage
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
@go test -v -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out -o coverage.html
# Lint
.PHONY: lint
lint:
@echo "Running linter..."
@golangci-lint run
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
@go fmt ./...
# Tidy dependencies
.PHONY: tidy
tidy:
@echo "Tidying dependencies..."
@go mod tidy
# Install dependencies
.PHONY: deps
deps:
@echo "Installing dependencies..."
@go mod download
# Development build (with race detection)
.PHONY: dev
dev:
@echo "Building development version..."
@go build -race $(LDFLAGS) -o $(OUTPUT_DIR)/$(APP_NAME)-dev $(CMD_DIR)
# Run the application
.PHONY: run
run: build
@echo "Running $(APP_NAME)..."
@$(OUTPUT_DIR)/$(APP_NAME)
# Show version info
.PHONY: version
version:
@echo "Version: $(VERSION)"
@echo "Build Time: $(BUILD_TIME)"
@echo "Git Commit: $(GIT_COMMIT)"
@echo "Go Version: $(GO_VERSION)"
# Help
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Clean and build for current platform"
@echo " build - Build for current platform"
@echo " build-linux - Build for Linux"
@echo " build-macos - Build for macOS"
@echo " build-windows- Build for Windows"
@echo " build-all - Build for all platforms"
@echo " package-* - Package builds for specific platforms"
@echo " package-all - Package all builds"
@echo " release - Build and package everything"
@echo " test - Run tests"
@echo " test-coverage- Run tests with coverage"
@echo " lint - Run linter"
@echo " fmt - Format code"
@echo " tidy - Tidy dependencies"
@echo " deps - Install dependencies"
@echo " dev - Development build with race detection"
@echo " run - Build and run the application"
@echo " clean - Clean build artifacts"
@echo " version - Show version information"
@echo " help - Show this help"