-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
85 lines (74 loc) · 2.28 KB
/
Makefile
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
# Project Metadata
PROJECT_NAME := asus-numpad-driver
BUILD_DIR := build
SRC_DIR := .
GO := go
# Flags
GO_FLAGS := -mod=vendor
LDFLAGS := -s -w
# Default Target
.PHONY: all
all: build
# Build the project
.PHONY: build
build:
@echo "🔨 Building $(PROJECT_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GO) build $(GO_FLAGS) -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(PROJECT_NAME) $(SRC_DIR)
@echo "✅ Build complete: $(BUILD_DIR)/$(PROJECT_NAME)"
# Run the project (requires sudo for uinput and evdev access)
.PHONY: run
run: build
@echo "🚀 Running $(PROJECT_NAME)..."
@sudo ./$(BUILD_DIR)/$(PROJECT_NAME)
# Test the project
.PHONY: test
test:
@echo "🧪 Running tests..."
$(GO) test $(GO_FLAGS) ./...
@echo "✅ Tests complete."
# Lint the project using golangci-lint (install if not present)
.PHONY: lint
lint:
@echo "🔍 Linting code..."
@command -v golangci-lint >/dev/null 2>&1 || { echo >&2 "golangci-lint not found. Installing..."; go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; }
golangci-lint run
@echo "✅ Linting complete."
# Format the codebase
.PHONY: fmt
fmt:
@echo "🛠️ Formatting code..."
$(GO) fmt ./...
@echo "✅ Formatting complete."
# Clean up build artifacts
.PHONY: clean
clean:
@echo "🧹 Cleaning up..."
@rm -rf $(BUILD_DIR)
@echo "✅ Cleanup complete."
# Install the project binary globally
.PHONY: install
install: build
@echo "📦 Installing $(PROJECT_NAME)..."
@sudo mv $(BUILD_DIR)/$(PROJECT_NAME) /usr/local/bin/
@echo "✅ $(PROJECT_NAME) installed to /usr/local/bin."
# Uninstall the project binary
.PHONY: uninstall
uninstall:
@echo "❌ Uninstalling $(PROJECT_NAME)..."
@sudo rm -f /usr/local/bin/$(PROJECT_NAME)
@echo "✅ $(PROJECT_NAME) uninstalled."
# Display help message
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Build the project (default)"
@echo " build - Build the project binary"
@echo " run - Build and run the project with sudo"
@echo " test - Run tests"
@echo " lint - Run linter on the codebase"
@echo " fmt - Format the codebase"
@echo " clean - Remove build artifacts"
@echo " install - Install the project binary globally"
@echo " uninstall - Remove the installed binary"
@echo " help - Show this help message"