Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
76 lines (65 loc) · 2.86 KB
/
Copy pathMakefile
File metadata and controls
76 lines (65 loc) · 2.86 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
# DrivePulse Makefile
APP_NAME := DrivePulse
SRC_DIR := ./src
BUILDS_DIR := builds
BIN_WINDOWS := $(APP_NAME)_Windows_x64.exe
BIN_LINUX := $(APP_NAME)_Linux_x64
VERSION ?= 1.0.0
ifeq ($(OS),Windows_NT)
BUILD_DATE := $(shell powershell -NoProfile -Command "Get-Date -Format 'yyyy-MM-dd'")
else
BUILD_DATE := $(shell date +'%Y-%m-%d')
endif
# Go linker flags
LDFLAGS_WINDOWS := -H=windowsgui -s -w -X 'main.Version=$(VERSION)' -X 'main.BuildDate=$(BUILD_DATE)'
LDFLAGS_LINUX := -s -w -X 'main.Version=$(VERSION)' -X 'main.BuildDate=$(BUILD_DATE)'
.PHONY: help clean setup lint format test run build
## help: Show available targets
help:
@echo $(APP_NAME) Build Targets:
@echo make clean - Remove $(BUILDS_DIR)/ directory
@echo make setup - Download and tidy Go dependencies
@echo make lint - Run static analysis without modifying files
@echo make format - Format code, organize imports, and run deep static analysis
@echo make test - Run unit tests with code coverage
@echo make run - Run locally directly from source
@echo make build - Compile Windows and Linux binaries and patch PE resources
## clean: Remove build artifacts
clean:
ifeq ($(OS),Windows_NT)
@powershell -NoProfile -Command "if (Test-Path '$(BUILDS_DIR)') { Get-ChildItem -Path '$(BUILDS_DIR)' -Recurse | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue; Remove-Item -Path '$(BUILDS_DIR)' -Force -ErrorAction SilentlyContinue; exit 0 }"
else
@rm -rf $(BUILDS_DIR)
endif
## setup: Download and tidy Go dependencies
setup:
go mod download
go mod tidy
## lint: Run static analysis and vet checks
lint:
go vet ./...
go tool staticcheck ./...
## format: Format code, organize imports, and run deep static analysis
format:
gofmt -s -w .
go tool goimports -w .
$(MAKE) lint
## test: Run unit tests with code coverage
test:
go test -v -cover ./...
## run: Run locally directly from source
run:
go run $(SRC_DIR) -in-place
## build: Cross-compile for Windows and Linux and patch Windows PE resources
build:
ifeq ($(OS),Windows_NT)
@if not exist $(BUILDS_DIR) mkdir $(BUILDS_DIR)
powershell -NoProfile -Command "$$env:CGO_ENABLED='0'; $$env:GOOS='windows'; $$env:GOARCH='amd64'; go build -ldflags=\"$(LDFLAGS_WINDOWS)\" -o $(BUILDS_DIR)/$(BIN_WINDOWS) $(SRC_DIR)"
go tool go-winres patch --in src/winres/winres.json --no-backup $(BUILDS_DIR)/$(BIN_WINDOWS)
powershell -NoProfile -Command "$$env:CGO_ENABLED='0'; $$env:GOOS='linux'; $$env:GOARCH='amd64'; go build -ldflags=\"$(LDFLAGS_LINUX)\" -o $(BUILDS_DIR)/$(BIN_LINUX) $(SRC_DIR)"
else
mkdir -p $(BUILDS_DIR)
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="$(LDFLAGS_WINDOWS)" -o $(BUILDS_DIR)/$(BIN_WINDOWS) $(SRC_DIR)
go tool go-winres patch --in src/winres/winres.json --no-backup $(BUILDS_DIR)/$(BIN_WINDOWS)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS_LINUX)" -o $(BUILDS_DIR)/$(BIN_LINUX) $(SRC_DIR)
endif