-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
154 lines (114 loc) · 3.32 KB
/
Makefile
File metadata and controls
154 lines (114 loc) · 3.32 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
ROOT = gone
APPNAME ?= $(ROOT)
AUTHOR ?= drduh
GIT ?= github.com/$(AUTHOR)
VERSION ?= $(shell date +"%Y.%m.%d")
CMD = cmd
SRC = $(CMD)/main.go
OUT = release
GO ?= go
GODOC ?= ${HOME}/go/bin/godoc
GOLINT ?= golangci-lint
BUILDPKG = $(GIT)/$(APPNAME)/version
BUILDARCH = $(shell $(GO) env GOHOSTARCH)
BUILDVERS = $(shell $(GO) env GOVERSION)
BUILDOS = $(shell $(GO) env GOHOSTOS)
BUILDGIT = $(shell git log -1 --format=%h \
2>/dev/null || printf "0000000")
BUILDTIME = $(shell date +"%Y-%m-%dT%H:%M:%S")
BUILDFLAG = \
-X "$(BUILDPKG).Arch=$(BUILDARCH)" \
-X "$(BUILDPKG).Commit=$(BUILDGIT)" \
-X "$(BUILDPKG).Go=$(BUILDVERS)" \
-X "$(BUILDPKG).Host=$(shell hostname -f)" \
-X "$(BUILDPKG).Id=$(APPNAME)" \
-X "$(BUILDPKG).Path=$(shell pwd)" \
-X "$(BUILDPKG).System=$(BUILDOS)" \
-X "$(BUILDPKG).Time=$(BUILDTIME)" \
-X "$(BUILDPKG).User=$(shell whoami)" \
-X "$(BUILDPKG).Version=$(VERSION)"
BUILDCMD = $(GO) build -ldflags '-s -w $(BUILDFLAG)'
BINNAME = $(APPNAME)-$(BUILDOS)-$(BUILDARCH)-$(VERSION)
GOBUILD = GOOS=$(BUILDOS) GOARCH=$(BUILDARCH) $(BUILDCMD) \
-o "$(OUT)/$(BINNAME)" "$(SRC)"
GORACE = GOOS=$(BUILDOS) GOARCH=$(BUILDARCH) $(BUILDCMD) \
-race -o "$(OUT)/$(BINNAME)-race" "$(SRC)"
SERVICE = $(APPNAME).service
ASSET_CSS = assets/style.css
SETTINGS = settings/defaultSettings.json
CONF_DIR ?= /etc/$(APPNAME)
DEST_BIN = /usr/local/bin/$(APPNAME)
DEST_CONF = $(CONF_DIR)/config
DEST_CSS = $(CONF_DIR)/$(ASSET_CSS)
DEST_SERV = /etc/systemd/system/$(SERVICE)
MOD_BIN = 0755
MOD_FILE = 0644
TESTCOVER = testCoverage
WARN = tput setaf 3 ; printf "%s\n" "${1}" ; tput sgr0
all: fmt build test lint
prep:
@mkdir -p $(OUT)
build: prep
@$(GOBUILD)
release: build
@printf "built: %s\n" "$$(file $(OUT)/$(BINNAME))"
run: build
@$(OUT)/$(BINNAME)
debug: build
@$(OUT)/$(BINNAME) -debug
version: build
@$(OUT)/$(BINNAME) -version
install: install-assets install-bin install-config install-service \
reload-service
install-assets:
@sudo install -Dm $(MOD_FILE) $(ASSET_CSS) $(DEST_CSS)
@printf "Installed $(DEST_CSS)\n"
install-bin: build
@sudo install -Dm $(MOD_BIN) $(OUT)/$(BINNAME) $(DEST_BIN)
@printf "Installed $(DEST_BIN)\n"
install-config:
@sudo install -Dm $(MOD_FILE) $(SETTINGS) $(DEST_CONF)
@printf "Installed $(DEST_CONF)\n"
install-service:
@sudo install -Dm $(MOD_FILE) $(SERVICE) $(DEST_SERV)
@sudo systemctl enable $(SERVICE)
@printf "Installed $(DEST_SERV)\n"
reload-service:
@printf "Restarting services ...\n"
@sudo systemctl daemon-reload
@sudo systemctl restart $(SERVICE)
fmt:
@$(GO) fmt ./...
test:
@$(GO) test ./...
test-race:
@$(GO) test -race ./...
test-verbose:
@$(GO) test -v ./...
test-cover:
@$(GO) test -coverprofile=$(TESTCOVER) ./...
lint:
@if command -v $(GOLINT) >/dev/null 2>&1 ; then \
$(GOLINT) run ./... ; \
else \
$(call WARN,skipping lint - '$(GOLINT)' not found); \
fi
lint-verbose:
@$(GOLINT) run -v ./...
build-race: prep
@$(GORACE)
race: build-race
@$(OUT)/$(BINNAME)-race -debug
cover: test-cover
@$(GO) tool cover -html=$(TESTCOVER) -o $(TESTCOVER).html
@printf "cover: %s\n" "$$(file $(TESTCOVER).html)"
doc:
@$(GODOC) -http :8000
clean:
@rm -rf $(OUT) $(TESTCOVER) $(TESTCOVER).html
clena: clean
coverage: cover
prod: release
tset: test
urn: run
verbose: debug