-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
233 lines (165 loc) · 6.4 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
## SPDX-FileCopyrightText: 2018 M. Shulhan <[email protected]>
## SPDX-License-Identifier: GPL-3.0-or-later
.FORCE:
CGO_ENABLED:=$(shell go env CGO_ENABLED)
GOOS:=$(shell go env GOOS)
GOARCH:=$(shell go env GOARCH)
VERSION=$(shell git describe --long | sed 's/\([^-]*-g\)/r\1/;s/-/./g')
COVER_OUT:=cover.out
COVER_HTML:=cover.html
CPU_PROF:=cpu.prof
MEM_PROF:=mem.prof
DEBUG=
LD_FLAGS=
RESCACHED_BIN=_bin/$(GOOS)_$(GOARCH)/rescached
RESOLVER_BIN=_bin/$(GOOS)_$(GOARCH)/resolver
RESOLVERBENCH_BIN=_bin/$(GOOS)_$(GOARCH)/resolverbench
RESCACHED_MAN:=_sys/usr/share/man/man1/rescached.1.gz
RESCACHED_CFG_MAN:=_sys/usr/share/man/man5/rescached.cfg.5.gz
RESOLVER_MAN:=_sys/usr/share/man/man1/resolver.1.gz
DIR_BIN=/usr/bin
DIR_MAN=/usr/share/man
DIR_RESCACHED=/usr/share/rescached
##---- Tasks for testing, linting, and building program.
.PHONY: all
all: lint test resolver rescached
.PHONY: build
build: resolver rescached
## Build with race detection.
.PHONY: debug
debug: CGO_ENABLED=1
debug: DEBUG=-race -v
debug: test build
.PHONY: resolver
resolver: LD_FLAGS =-X 'main.Usage=$$(go tool doc ./cmd/resolver)'
resolver: LD_FLAGS+=-X 'git.sr.ht/~shulhan/rescached.Version=$(VERSION)'
resolver:
mkdir -p _bin/$(GOOS)_$(GOARCH)
go build $(DEBUG) -ldflags="$(LD_FLAGS)" -o _bin/$(GOOS)_$(GOARCH)/ ./cmd/resolver
.PHONY: rescached
rescached: LD_FLAGS+=-X 'git.sr.ht/~shulhan/rescached.Version=$(VERSION)'
rescached:
mkdir -p _bin/$(GOOS)_$(GOARCH)
go run ./cmd/rescached embed
go build $(DEBUG) -ldflags="$(LD_FLAGS)" -o _bin/$(GOOS)_$(GOARCH)/ ./cmd/rescached
.PHONY: test
test:
go test $(DEBUG) -count=1 -coverprofile=$(COVER_OUT) ./...
go tool cover -html=$(COVER_OUT) -o $(COVER_HTML)
.PHONY: test.prof
test.prof:
go test $(DEBUG) -count=1 \
-cpuprofile $(CPU_PROF) \
-memprofile $(MEM_PROF) ./...
.PHONY: lint
lint:
-fieldalignment ./...
-shadow ./...
-golangci-lint run \
--presets bugs,metalinter,performance,unused \
--disable bodyclose \
--disable exhaustive \
--disable musttag \
./...
-reuse --suppress-deprecation lint
##---- Cleaning up.
.PHONY: clean distclean
distclean: clean
go clean -i ./...
clean:
rm -f cmd/rescached/memfs.go
rm -f testdata/rescached.pid
rm -f $(COVER_OUT) $(COVER_HTML)
rm -f $(RESCACHED_BIN) $(RESOLVER_BIN) $(RESOLVERBENCH_BIN)
##---- Documentation tasks.
.PHONY: doc
doc: $(RESCACHED_MAN) $(RESCACHED_CFG_MAN) $(RESOLVER_MAN)
$(RESCACHED_MAN): README.adoc
asciidoctor --backend=manpage --destination-dir=_sys/usr/share/man/man1/ $<
gzip -f _sys/usr/share/man/man1/rescached.1
$(RESCACHED_CFG_MAN): _www/doc/rescached.cfg.adoc
asciidoctor --backend=manpage --destination-dir=_sys/usr/share/man/man5/ $<
gzip -f _sys/usr/share/man/man5/rescached.cfg.5
$(RESOLVER_MAN): _www/doc/resolver.adoc
asciidoctor --backend=manpage --destination-dir=_sys/usr/share/man/man1/ $<
gzip -f _sys/usr/share/man/man1/resolver.1
##---- Development tasks
.PHONY: dev
dev:
go run ./cmd/rescached -dir-base=./_test -config=etc/rescached/rescached.cfg dev
##---- Common tasks for installing and uninstalling program.
.PHONY: install-common uninstall-common
install-common:
mkdir -p $(PREFIX)/etc/rescached
mkdir -p $(PREFIX)/etc/rescached/hosts.d
mkdir -p $(PREFIX)/etc/rescached/zone.d
cp -f _sys/etc/rescached/rescached.cfg $(PREFIX)/etc/rescached/
cp -f _sys/etc/rescached/localhost.pem $(PREFIX)/etc/rescached/
cp -f _sys/etc/rescached/localhost.pem.key $(PREFIX)/etc/rescached/
mkdir -p $(PREFIX)/etc/rescached/block.d
cp -f _sys/etc/rescached/block.d/.pgl.yoyo.org $(PREFIX)/etc/rescached/block.d/
cp -f _sys/etc/rescached/block.d/.someonewhocares.org $(PREFIX)/etc/rescached/block.d/
cp -f _sys/etc/rescached/block.d/.winhelp2002.mvps.org $(PREFIX)/etc/rescached/block.d/
mkdir -p $(PREFIX)$(DIR_BIN)
cp -f $(RESCACHED_BIN) $(PREFIX)$(DIR_BIN)
cp -f $(RESOLVER_BIN) $(PREFIX)$(DIR_BIN)
mkdir -p $(PREFIX)$(DIR_MAN)/man1
mkdir -p $(PREFIX)$(DIR_MAN)/man5
cp $(RESCACHED_MAN) $(PREFIX)$(DIR_MAN)/man1/
cp $(RESOLVER_MAN) $(PREFIX)$(DIR_MAN)/man1/
cp $(RESCACHED_CFG_MAN) $(PREFIX)$(DIR_MAN)/man5/
mkdir -p $(PREFIX)$(DIR_RESCACHED)
cp COPYING $(PREFIX)$(DIR_RESCACHED)
uninstall-common:
rm -f $(PREFIX)$(DIR_RESCACHED)/COPYING
rm -f $(PREFIX)$(DIR_MAN)/man5/$(RESCACHED_CFG_MAN)
rm -f $(PREFIX)$(DIR_MAN)/man1/$(RESOLVER_MAN)
rm -f $(PREFIX)$(DIR_MAN)/man1/$(RESCACHED_MAN)
rm -f $(PREFIX)$(DIR_BIN)/resolver
rm -f $(PREFIX)$(DIR_BIN)/rescached
##---- Tasks for installing and uninstalling on GNU/Linux with systemd.
.PHONY: install deploy uninstall
install: build install-common
mkdir -p $(PREFIX)/usr/lib/systemd/system
cp _sys/usr/lib/systemd/system/rescached.service $(PREFIX)/usr/lib/systemd/system/
uninstall: uninstall-common
systemctl stop rescached
systemctl disable rescached
rm -f /usr/lib/systemd/system/rescached.service
deploy: build
sudo rsync _bin/$(GOOS)_$(GOARCH)/rescached $(DIR_BIN)/
sudo rsync _bin/$(GOOS)_$(GOARCH)/resolver $(DIR_BIN)/
sudo systemctl restart rescached
##---- Tasks for installing and uninstalling service on macOS.
.PHONY: install-macos deploy-macos uninstall-macos
install-macos: DIR_BIN=/usr/local/bin
install-macos: DIR_MAN=/usr/local/share/man
install-macos: DIR_RESCACHED=/usr/local/share/rescached
install-macos: build install-common
cp _sys/Library/LaunchDaemons/info.kilabit.rescached.plist /Library/LaunchDaemons/
deploy-macos: DIR_BIN=/usr/local/bin
deploy-macos: build
sudo cp _bin/$(GOOS)_$(GOARCH)/rescached $(DIR_BIN)/
sudo cp _bin/$(GOOS)_$(GOARCH)/resolver $(DIR_BIN)/
sudo launchctl stop info.kilabit.rescached
uninstall-macos: DIR_BIN=/usr/local/bin
uninstall-macos: DIR_MAN=/usr/local/share/man
uninstall-macos: DIR_RESCACHED=/usr/local/share/rescached
uninstall-macos: uninstall-common
launchctl stop info.kilabit.rescached
launchctl unload info.kilabit.rescached
rm -f /Library/LaunchDaemons/info.kilabit.rescached.plist
##---- Tasks for deploying to public DNS server.
.PHONY: deploy-personal-server
build-linux-amd64: CGO_ENABLED=0
build-linux-amd64: GOOS=linux
build-linux-amd64: GOARCH=amd64
build-linux-amd64: build
deploy-personal-server: build-linux-amd64
rsync --progress _bin/linux_amd64/rescached personal-server:~/bin/rescached
ssh personal-server "sudo rsync ~/bin/rescached /usr/bin/rescached; sudo systemctl restart rescached.service"
#---- Development.
## Run web server to test WUI.
.PHONY: dev.www
dev.www:
go run ./internal/cmd/www