-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
87 lines (71 loc) · 1.98 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
86
87
# Project metadata
APP_NAME := gomocku
VERSION := 1.0.0
BUILD_DIR := build
RELEASE_DIR := $(BUILD_DIR)/release
MAIN_FILE := ./cmd/gomocku/main.go
# Go settings
GO ?= go
GOFLAGS := -mod=vendor
LDFLAGS := -X main.version=$(VERSION)
# Define platforms and architectures
PLATFORMS := linux darwin windows
ARCHS := amd64 arm64
all: build
build:
mkdir -p $(BUILD_DIR)
$(GO) build -o $(BUILD_DIR)/$(APP_NAME) -ldflags "$(LDFLAGS)" $(MAIN_FILE);
release:
mkdir -p $(RELEASE_DIR)
@for platform in $(PLATFORMS); do \
for arch in $(ARCHS); do \
echo "Building $(APP_NAME)-$$platform-$$arch..."; \
extension=""; \
if [ "$$platform" = "windows" ]; then \
extension=".exe"; \
fi; \
GOOS=$$platform GOARCH=$$arch $(GO) build -o $(RELEASE_DIR)/$(APP_NAME)-$$platform-$$arch$$extension -ldflags "$(LDFLAGS)" $(MAIN_FILE); \
done; \
done
echo "Generating SHA256 Sum..."
cd $(RELEASE_DIR) && sha256sum --binary ./* > sha256sum.txt
test:
@echo "Running tests..."
$(GO) test ./...
run: build
@echo "Running $(APP_NAME)..."
./$(BUILD_DIR)/$(APP_NAME)
clean:
@echo "Cleaning up..."
rm -rf $(BUILD_DIR)
fmt:
@echo "Formatting code..."
$(GO) fmt ./...
lint:
@echo "Linting code..."
golangci-lint run
vet:
@echo "Running go vet..."
$(GO) vet ./...
deps:
@echo "Installing dependencies..."
$(GO) mod tidy
$(GO) mod vendor
# Help documentation
help:
@echo "Usage: make [target]"
@echo
@echo "Targets:"
@echo " all Build the project (default target)"
@echo " build Build the binary"
@echo " release Build the binary for all platforms and architectures"
@echo " test Run all tests"
@echo " run Run the application"
@echo " clean Remove build artifacts"
@echo " fmt Format Go source files"
@echo " lint Lint the code (requires golangci-lint)"
@echo " vet Run go vet to check for issues"
@echo " deps Install and tidy dependencies"
@echo " help Show this help"
# Targets
.PHONY: all build test run clean fmt lint vet