-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
86 lines (70 loc) · 2.36 KB
/
Makefile
File metadata and controls
86 lines (70 loc) · 2.36 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
# Makefile for hashpwd2
# Binary name
BINARY_NAME=hashpwd2
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
# Version information from git
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Linker flags to inject version information
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"
.PHONY: all build clean test run deps install help
# Default target
all: build
# Build the binary
build:
@echo "Building $(BINARY_NAME) $(VERSION)..."
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) -v
# Build with optimizations (smaller binary)
build-optimized:
@echo "Building optimized $(BINARY_NAME) $(VERSION)..."
$(GOBUILD) $(LDFLAGS) -ldflags="-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)" -o $(BINARY_NAME) -v
# Clean build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
rm -f $(BINARY_NAME)
# Run tests
test:
@echo "Running tests..."
$(GOTEST) -v ./...
# Run the application
run: build
./$(BINARY_NAME)
# Download dependencies
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
# Install to $GOPATH/bin or $GOBIN
install:
@echo "Installing $(BINARY_NAME) $(VERSION)..."
$(GOCMD) install $(LDFLAGS) -v
# Install to system location (requires sudo)
install-system: build
@echo "Installing $(BINARY_NAME) to /usr/local/bin..."
sudo install -m 755 $(BINARY_NAME) /usr/local/bin/
# Display version information
version:
@echo "Version: $(VERSION)"
@echo "Commit: $(COMMIT)"
@echo "Date: $(DATE)"
# Help target
help:
@echo "Available targets:"
@echo " make build - Build the binary"
@echo " make build-optimized - Build optimized binary (smaller size)"
@echo " make clean - Remove build artifacts"
@echo " make test - Run tests"
@echo " make run - Build and run the application"
@echo " make deps - Download and tidy dependencies"
@echo " make install - Install to GOPATH/bin"
@echo " make install-system - Install to /usr/local/bin (requires sudo)"
@echo " make version - Display version information"
@echo " make help - Show this help message"