aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 4e8f321f93d5cc0cac84edecd4a6386227e1fe70 (plain)
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
VERSION?=	$(shell git describe --tags --always)
BINARY=	$(patsubst %,dist/%,$(shell find cmd/* -maxdepth 0 -type d -exec basename {} \;))
SRC=	$(shell find . -type f -name '*.go')
SQL=	$(shell find sql -type f)
EXTRAS=	cmd/server/migrations.go \
	counter/sws.min.js \
	cmd/server/counter.go \
	cmd/server/static.go \
	cmd/server/templates.go
TMPL=	$(shell find templates -type f -name '*.tmpl')
STATIC=	$(shell find static -type f)

.PHONY: build
build: $(BINARY)

dist/%: $(SRC) $(EXTRAS)
	go build -ldflags "-X main.Version=$(VERSION)" -o $@ ./cmd/$*

cmd/server/static.go: $(STATIC)
	go generate ./static >$@

cmd/server/templates.go: $(TMPL)
	go generate ./templates >$@

cmd/server/migrations.go: $(SQL)
	go generate ./sql >$@

cmd/server/counter.go: counter/sws.min.js
	printf "package main\n\nconst counter = \`" >$@
	cat $< >>$@
	printf "\`\n" >>$@

%.min.js: %.js node_modules
	yarn run -s uglifyjs -c -m -o $@ $<

node_modules: package.json
	yarn -s

.PHONY: test
test: lint
	go test -v -short -coverprofile=coverage.out -cover ./... \
		&& go tool cover -html=coverage.out -o coverage.html

.PHONY: lint
lint:
	go vet ./...

.PHONY: clean
clean:
	rm -fr dist
	rm -f client/sws.min.js
	rm -f $(EXTRAS)
	rm -fr coverage*

.PHONY: dist-clean
dist-clean: clean
	rm -fr node_modules