lens @ a1f09d1f143012570a62bcb2a8fe51c439ad68fb

 1BIN=lens
 2OUT=./bin/$(BIN)
 3SERVER=./cmd/server/main.go
 4
 5GO_TEST=go test -v -timeout 100ms -shuffle on -parallel `nproc`
 6GO_BUILD=go build -v -ldflags '-w -s'
 7GO_RUN=go run -v
 8
 9# Development setup
10DB_TYPE?=sqlite
11DB_CON?=main.db
12LOG_LEVEL?=error
13SCHEDULER_COUNT?=`nproc`
14CACHE_PATH?=$(HOME)/cache
15AES_KEY?=`openssl rand -rand /dev/urandom 32 | base64`
16
17ifneq (,$(wildcard ./.env))
18    include .env
19    export
20endif
21
22all: build
23
24build: sass tmpl
25	$(GO_BUILD) -o $(OUT) $(SERVER)
26
27compress: build
28	upx -1 $(OUT)
29
30compress_into_oblivion: build
31	upx --best --ultra-brute $(OUT)
32
33run: sass tmpl
34	$(GO_RUN) $(SERVER) \
35		--db-type=$(DB_TYPE) \
36		--db-con="$(DB_CON)" \
37		--log-level=$(LOG_LEVEL) \
38		--scheduler-count=$(SCHEDULER_COUNT) \
39		--cache-path="$(CACHE_PATH)" \
40		--aes-key="$(AES_KEY)"
41
42sass:
43	@mkdir -p static
44	sassc \
45		-I scss scss/main.scss static/main.css \
46		--style compressed
47
48tmpl:
49	cd ./templates && \
50	qtc *
51
52test: test.unit test.integration
53
54test.all: gci test.unit test.integration lint
55
56test.integration:
57	$(GO_TEST) -tags=integration ./...
58
59test.unit:
60	$(GO_TEST) -tags=unit ./...
61
62gen:
63	go run -v \
64		./cmd/ggen/...
65
66cover.%:
67	$(GO_TEST) \
68		-tags=$* \
69		-coverprofile=bin/cover \
70		./...
71	go tool cover \
72		-html=bin/cover \
73		-o bin/cover.html
74	echo "open bin/cover.html"
75
76lint:
77	golangci-lint run \
78	--fix \
79	--config golangci.yml \
80	--verbose \
81	./...
82
83fix: gci alignment
84
85gci:
86	find . \
87		-type f \
88		-name "*.go" \
89		-not -path "./vendor/*" \
90		-exec gci write -s standard -s default -s "prefix(git.sr.ht/~gabrielgio/img)" {} +
91
92alignment:
93	betteralign -apply ./...
94
95watch:
96	find . \( ! -name "*.qtpl.go" -a \( -name "*.go" -o -name "*.qtpl" -o -name "main.scss" \) \) | \
97		entr -sr 'make run'