aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: cf9768dd5dcb8b369427fcd9369ddacf61d2ac0a (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
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
BIN?=lens
PREFIX?=/usr/local
BINDIR?=$(PREFIX)/bin

OUT=./bin/$(BIN)
SERVER=./cmd/server/main.go

GO_TEST=go test -v -timeout 100ms -shuffle on -parallel `nproc`
GO_BUILD=go build -v -ldflags '-w -s'
GO_RUN=go run -v

# Development setup
DB_TYPE?=sqlite
DB_CON?=main.db
LOG_LEVEL?=error
SCHEDULER_COUNT?=`nproc`
CACHE_PATH?=$(HOME)/cache
AES_KEY?=`openssl rand -rand /dev/urandom 32 | base64`

ifneq (,$(wildcard ./.env))
    include .env
    export
endif

all: build

install: build
	install -Dm755 $(OUT) $(BINDIR)/$(BIN)

build: sass tmpl
	$(GO_BUILD) -o $(OUT) $(SERVER)

compress: build
	upx -1 $(OUT)

compress_into_oblivion: build
	upx --best --ultra-brute $(OUT)

run: sass tmpl
	$(GO_RUN) $(SERVER) \
		--db-type=$(DB_TYPE) \
		--db-con="$(DB_CON)" \
		--log-level=$(LOG_LEVEL) \
		--scheduler-count=$(SCHEDULER_COUNT) \
		--cache-path="$(CACHE_PATH)" \
		--aes-key="$(AES_KEY)"

sass:
	@mkdir -p static
	sassc \
		-I scss scss/main.scss static/main.css \
		--style compressed

tmpl:
	cd ./templates && \
	qtc *

test: test.unit test.integration

test.all: gci test.unit test.integration lint

test.integration:
	$(GO_TEST) -tags=integration ./...

test.unit:
	$(GO_TEST) -tags=unit ./...

gen:
	go run -v \
		./cmd/ggen/...

cover.%:
	$(GO_TEST) \
		-tags=$* \
		-coverprofile=bin/cover \
		./...
	go tool cover \
		-html=bin/cover \
		-o bin/cover.html
	echo "open bin/cover.html"

lint:
	golangci-lint run \
	--fix \
	--config golangci.yml \
	--verbose \
	./...

fix: gci alignment

gci:
	find . \
		-type f \
		-name "*.go" \
		-not -path "./vendor/*" \
		-exec gci write -s standard -s default -s "prefix(git.sr.ht/~gabrielgio/img)" {} +

alignment:
	betteralign -apply ./...

watch:
	find . \( ! -name "*.qtpl.go" -a \( -name "*.go" -o -name "*.qtpl" -o -name "main.scss" \) \) | \
		entr -sr 'make run'