-
Notifications
You must be signed in to change notification settings - Fork 33
/
Makefile
166 lines (128 loc) · 5.44 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
BINS := bin/lavinmq bin/lavinmqctl bin/lavinmqperf
SOURCES := $(shell find src/lavinmq src/stdlib -name '*.cr' 2> /dev/null)
VIEW_SOURCES := $(wildcard views/*.ecr)
VIEW_TARGETS := $(patsubst views/%.ecr,static/views/%.html,$(VIEW_SOURCES))
VIEW_PARTIALS := $(wildcard views/partials/*.ecr)
JS := static/js/lib/chunks/helpers.segment.js static/js/lib/chart.js static/js/lib/amqp-websocket-client.mjs static/js/lib/amqp-websocket-client.mjs.map static/js/lib/luxon.js static/js/lib/chartjs-adapter-luxon.esm.js static/js/lib/elements-8.2.0.js static/js/lib/elements-8.2.0.css
CRYSTAL_FLAGS := --release --stats
override CRYSTAL_FLAGS += --error-on-warnings --link-flags=-pie
.DEFAULT_GOAL := all
.PHONY: livereload
livereload:
@echo "Starting livereload server..."
@which livereload > /dev/null || npm install -g livereload
@(pid=$$!; trap 'kill -TERM $$pid' INT; livereload static &)
.PHONY: views
views: $(VIEW_TARGETS)
.PHONY: watch-views
watch-views:
while true; do $(MAKE) -q -s views || $(MAKE) -j views; sleep 0.5; done
.PHONY: dev-ui
dev-ui:
@trap '$(MAKE) clean-views; trap - EXIT' EXIT INT TERM; \
$(MAKE) livereload & \
livereload_pid=$$!; \
$(MAKE) -s watch-views; \
wait $$livereload_pid
static/views/%.html: views/%.ecr $(VIEW_PARTIALS)
@mkdir -p static/views
@TEMP_FILE=$$(mktemp) && \
INPUT=$< crystal run views/_render.cr > $$TEMP_FILE && \
mv $$TEMP_FILE $@ && \
echo "Rendered $< to $@"
.PHONY: clean-views
clean-views:
$(RM) $(VIEW_TARGETS)
.PHONY: all
all: $(BINS)
bin/%: src/%.cr $(SOURCES) lib $(JS) $(DOCS) | bin
crystal build $< -o $@ $(CRYSTAL_FLAGS)
bin/%-debug: src/%.cr $(SOURCES) lib $(JS) $(DOCS) | bin
crystal build $< -o $@ --debug $(CRYSTAL_FLAGS)
bin/lavinmqperf: src/lavinmqperf.cr lib | bin
crystal build $< -o $@ -Dpreview_mt $(CRYSTAL_FLAGS)
bin/lavinmqctl: src/lavinmqctl.cr lib | bin
crystal build $< -o $@ -Dgc_none $(CRYSTAL_FLAGS)
lib: shard.yml shard.lock
shards install --production $(if $(nocolor),--no-color)
bin static/js/lib man1 static/js/lib/chunks:
mkdir -p $@
static/js/lib/%: | static/js/lib
curl --retry 5 -sLo $@ https://github.com/cloudamqp/amqp-client.js/releases/download/v3.1.1/$(@F)
static/js/lib/chart.js: | static/js/lib
curl --retry 5 -sL https://github.com/chartjs/Chart.js/releases/download/v4.0.1/chart.js-4.0.1.tgz | \
tar -zxOf- package/dist/chart.js > $@
static/js/lib/chunks/helpers.segment.js: | static/js/lib/chunks
curl --retry 5 -sL https://github.com/chartjs/Chart.js/releases/download/v4.0.1/chart.js-4.0.1.tgz | \
tar -zxOf- package/dist/chunks/helpers.segment.js > $@
static/js/lib/luxon.js: | static/js/lib
curl --retry 5 -sLo $@ https://moment.github.io/luxon/es6/luxon.js
static/js/lib/chartjs-adapter-luxon.esm.js: | static/js/lib
curl --retry 5 -sLo $@ https://cdn.jsdelivr.net/npm/[email protected]/dist/chartjs-adapter-luxon.esm.js
sed -i'' -e "s|\(import { _adapters } from\).*|\1 './chart.js'|; s|\(import { DateTime } from\).*|\1 './luxon.js'|" $@
static/js/lib/elements-8.2.0.js: | static/js/lib
curl --retry 5 -sLo $@ https://unpkg.com/@stoplight/[email protected]/web-components.min.js
static/js/lib/elements-8.2.0.css: | static/js/lib
curl --retry 5 -sLo $@ https://unpkg.com/@stoplight/[email protected]/styles.min.css
man1/lavinmq.1: bin/lavinmq | man1
help2man -Nn "fast and advanced message queue server" $< -o $@
man1/lavinmqctl.1: bin/lavinmqctl | man1
help2man -Nn "control utility for lavinmq server" $< -o $@
man1/lavinmqperf.1: bin/lavinmqperf | man1
help2man -Nn "performance testing tool for amqp servers" $< -o $@
MANPAGES := man1/lavinmq.1 man1/lavinmqctl.1 man1/lavinmqperf.1
.PHONY: man
man: $(MANPAGES)
.PHONY: js
js: $(JS)
.PHONY: deps
deps: js lib
.PHONY: lint
lint: lib
lib/ameba/bin/ameba src/
.PHONY: lint-js
lint-js:
npx standard static/js
.PHONY: lint-openapi
lint-openapi:
npx --package=@stoplight/spectral-cli spectral --ruleset openapi/.spectral.json lint static/docs/openapi.yaml
.PHONY: test
test: lib
crystal spec --order random $(if $(nocolor),--no-color) --verbose
.PHONY: format
format:
crystal tool format --check
DESTDIR :=
PREFIX := /usr
BINDIR := $(PREFIX)/bin
DOCDIR := $(PREFIX)/share/doc
MANDIR := $(PREFIX)/share/man
SYSCONFDIR := /etc
UNITDIR := /lib/systemd/system
SHAREDSTATEDIR := /var/lib
.PHONY: install
install: $(BINS) $(MANPAGES) extras/lavinmq.ini extras/lavinmq.service README.md CHANGELOG.md NOTICE
install -D -m 0755 -t $(DESTDIR)$(BINDIR) $(BINS)
install -D -m 0644 -t $(DESTDIR)$(MANDIR)/man1 $(MANPAGES)
install -D -m 0644 extras/lavinmq.ini $(DESTDIR)$(SYSCONFDIR)/lavinmq/lavinmq.ini
install -D -m 0644 extras/lavinmq.service $(DESTDIR)$(UNITDIR)/lavinmq.service
install -D -m 0644 -t $(DESTDIR)$(DOCDIR)/lavinmq README.md NOTICE
install -D -m 0644 CHANGELOG.md $(DESTDIR)$(DOCDIR)/lavinmq/changelog
install -d -m 0755 $(DESTDIR)$(SHAREDSTATEDIR)/lavinmq
.PHONY: uninstall
uninstall:
$(RM) $(DESTDIR)$(BINDIR)/lavinmq{,ctl,perf}
$(RM) $(DESTDIR)$(MANDIR)/man1/lavinmq{,ctl,perf}.1
$(RM) $(DESTDIR)$(SYSCONFDIR)/lavinmq/lavinmq.ini
$(RM) $(DESTDIR)$(UNITDIR)/lavinmq.service
$(RM) $(DESTDIR)$(DOCDIR)/{lavinmq,README.md,CHANGELOG.md,NOTICE}
$(RM) $(DESTDIR)$(SHAREDSTATEDIR)/lavinmq
.PHONY: rpm
rpm:
rpmdev-setuptree
git archive --prefix lavinmq/ --output ~/rpmbuild/SOURCES/lavinmq.tar.gz HEAD
sed -E "s/^(Version:).*/\1 $(shell ./rpm-version)/" lavinmq.spec > ~/rpmbuild/SPECS/lavinmq.spec
rpmbuild -bb ~/rpmbuild/SPECS/lavinmq.spec
.PHONY: clean
clean:
$(RM) $(BINS) $(DOCS) $(JS) $(MANPAGES) $(VIEW_TARGETS)