-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
75 lines (56 loc) · 2.03 KB
/
Makefile
File metadata and controls
75 lines (56 loc) · 2.03 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
# Version information
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "v0.1.0")
GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
# Binary names
BINARY_NAME=trs
BINARY_UNIX=$(BINARY_NAME)_unix
# Build flags
LDFLAGS=-ldflags "-X altlinux.space/amakeenk/trs/internal/version.Version=$(VERSION) \
-X altlinux.space/amakeenk/trs/internal/version.GitCommit=$(GIT_COMMIT) \
-X altlinux.space/amakeenk/trs/internal/version.BuildDate=$(BUILD_DATE)"
.PHONY: all build clean test coverage install install-man uninstall uninstall-man version
all: clean build
build:
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) .
test:
$(GOTEST) ./... -v
coverage:
$(GOTEST) ./... -coverprofile=coverage.out -covermode=atomic
go tool cover -func=coverage.out
coverage-html:
$(GOTEST) ./... -coverprofile=coverage.out -covermode=atomic
go tool cover -html=coverage.out
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f coverage.out
install:
$(GOBUILD) $(LDFLAGS) -o $(GOPATH)/bin/$(BINARY_NAME) .
install-man:
install -d $(DESTDIR)/usr/share/man/man1
install -m 644 man/trs.1 $(DESTDIR)/usr/share/man/man1/
uninstall:
rm -f $(GOPATH)/bin/$(BINARY_NAME)
uninstall-man:
rm -f $(DESTDIR)/usr/share/man/man1/trs.1
# Build for multiple platforms
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o bin/$(BINARY_NAME)-linux-amd64 .
build-darwin:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o bin/$(BINARY_NAME)-darwin-amd64 .
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o bin/$(BINARY_NAME)-darwin-arm64 .
build-windows:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o bin/$(BINARY_NAME)-windows-amd64.exe .
build-all: build-linux build-darwin build-windows
# Show version
version:
@echo "Version: $(VERSION)"
@echo "Git Commit: $(GIT_COMMIT)"
@echo "Build Date: $(BUILD_DATE)"