lens @ 29e9fd3136f2e2fe301cbe07967fb3bb4ffcee2a

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