2024-07-25 14:23:49 +02:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
GOFLAGS = -tags='fts5,libsqlite3' -ldflags="-s -w -X main.compiledOn=$(SOURCE_DATE_EPOCH)"
|
2018-08-07 09:31:26 +02:00
|
|
|
|
2024-07-25 14:23:49 +02:00
|
|
|
.PHONY: all
|
|
|
|
all: bin/magneticod bin/magneticow
|
2017-11-03 00:15:13 +01:00
|
|
|
|
2024-07-25 14:23:49 +02:00
|
|
|
bin/magneticod:
|
|
|
|
go install $(GOFLAGS) ./cmd/magneticod
|
2017-11-03 00:15:13 +01:00
|
|
|
|
2024-07-25 14:23:49 +02:00
|
|
|
bin/magneticow:
|
2022-08-08 01:05:13 +02:00
|
|
|
# TODO: minify /data/* files!
|
2024-07-25 14:23:49 +02:00
|
|
|
go install $(GOFLAGS) ./cmd/magneticow
|
2018-08-27 10:15:01 +02:00
|
|
|
|
2024-07-25 14:23:49 +02:00
|
|
|
.PHONY: vet
|
2018-12-30 06:21:56 +01:00
|
|
|
vet:
|
2019-05-19 18:22:22 +02:00
|
|
|
go vet ./...
|
2018-08-27 10:15:01 +02:00
|
|
|
|
2024-07-25 14:23:49 +02:00
|
|
|
.PHONY: check
|
|
|
|
check:
|
|
|
|
go test $(GOFLAGS) ./...
|
|
|
|
|
|
|
|
.PHONY: install
|
|
|
|
install: bin/magneticod bin/magneticow
|
|
|
|
install -m 555 -Dt "$(PREFIX)/bin/" bin/magnetico{w,d}
|
2018-08-27 10:15:01 +02:00
|
|
|
|
2024-07-25 14:23:49 +02:00
|
|
|
.PHONY: format
|
2018-08-03 14:40:04 +02:00
|
|
|
format:
|
2019-05-19 18:22:22 +02:00
|
|
|
gofmt -w ./cmd/
|
|
|
|
gofmt -w ./pkg/
|
2018-12-30 06:21:56 +01:00
|
|
|
|
|
|
|
# Formatting Errors
|
|
|
|
# Since gofmt returns zero even if there are files to be formatted, we use:
|
|
|
|
#
|
|
|
|
# ! gofmt -d ${GOPATH}/path/ 2>&1 | read
|
|
|
|
#
|
|
|
|
# to return 1 if there are files to be formatted, and 0 if not.
|
|
|
|
# https://groups.google.com/forum/#!topic/Golang-Nuts/pdrN4zleUio
|
|
|
|
#
|
|
|
|
# How can I use Bash syntax in Makefile targets?
|
|
|
|
# Because `read` is a bash command.
|
|
|
|
# https://stackoverflow.com/a/589300/4466589
|
|
|
|
#
|
2020-11-27 20:49:26 +01:00
|
|
|
# How to ignore bindata.go
|
|
|
|
# Due to irrational insistence of some Go developers, gofmt, like many
|
|
|
|
# other tools of Go ecosystem, does not have flags for common scenarios
|
|
|
|
# such as ignoring certain files by pattern etc. Thus we use `go list`
|
|
|
|
# and grep together to achieve the desired result.
|
|
|
|
#
|
|
|
|
# The original query is this:
|
|
|
|
# gofmt -l $(go list -f $'{{range .GoFiles}}{{$.Dir}}/{{.}}\n{{end}}' ./... | grep -v bindata.go)
|
|
|
|
#
|
|
|
|
# The original query is then escaped for Makefile (by repeating dollar signs $ -> $$).
|
2024-07-25 14:23:49 +02:00
|
|
|
.PHONY: check-formatting
|
2018-12-30 06:21:56 +01:00
|
|
|
check-formatting: SHELL:=/bin/bash # HERE: this is setting the shell for check-formatting only
|
|
|
|
check-formatting:
|
2020-11-27 20:49:26 +01:00
|
|
|
! gofmt -l $$(go list -f $$'{{range .GoFiles}}{{$$.Dir}}/{{.}}\n{{end}}' ./... | grep -v bindata.go) 2>&1 | tee /dev/fd/2 | read
|
|
|
|
! gofmt -l $$(go list -f $$'{{range .GoFiles}}{{$$.Dir}}/{{.}}\n{{end}}' ./... | grep -v bindata.go) 2>&1 | tee /dev/fd/2 | read
|