mlisting

Mailing list service

git clone git://git.lin.moe/go/mlisting.git

 1APP_BIN = mlisting
 2VERSION = 0.1
 3PREFIX ?= /usr/local
 4BINDIR ?= $(PREFIX)/bin
 5AIR_PACKAGE ?= github.com/air-verse/air@v1
 6GOFLAGS := -buildmode=pie -modcacherw -trimpath -buildvcs=false
 7GO_TAGS := fts5
 8
 9ifeq "$(shell pkg-config sqlite3; echo $$?)" "0"
10	GO_TAGS += libsqlite3
11endif
12
13space := $(subst ,, )
14comma=,
15GOFLAGS += -tags=$(subst $(space),$(comma),$(strip $(GO_TAGS)))
16
17BUILD_LDFLAGS="-X git.lin.moe/go/mlisting/cmd.VERSION=$(VERSION)"
18.PHONY: build
19build: ## Compile the project
20	go build $(GOFLAGS) -ldflags $(BUILD_LDFLAGS) -o $(APP_BIN)
21
22.PHONY: install
23install: build ## Install binary
24	install -Dm755 $(APP_BIN) -t $(DESTDIR)$(BINDIR)/
25
26.PHONY: clean
27clean: ## Remove compiled file and test database
28	go clean
29	rm -f $(APP_BIN) mlisting.db
30	rm -rf ./tmp/
31
32.PHONY: watch
33watch: testdata ## Start development environment, watch and reload when code changed
34	go run $(AIR_PACKAGE) \
35            -build.include_file="config.example.toml" \
36            -build.cmd 'make build' \
37            -build.args_bin 'serve --config ./config.example.toml' \
38            -build.bin "./$(APP_BIN)"
39
40TEST_DB="/tmp/mlisting_test.db"
41TEST_LDFLAGS="-X git.lin.moe/go/mlisting/storage/sqlite.TESTDSN=$(TEST_DB)"
42.PHONY: testdata
43testdata: ## Initialize data for watch and check targets
44	rm -f $(TEST_DB)
45	go run $(GOFLAGS) ./tools/gentestdata.go -db $(TEST_DB)
46
47GOTESTFLAGS := -v
48GOTESTFLAGS += -tags=$(subst $(space),$(comma),$(strip $(GO_TAGS)))
49.PHONY: check
50check: testdata ## Run testsuit
51	go test $(GOTESTFLAGS) -ldflags $(TEST_LDFLAGS) ./...
52
53.PHONY: help
54help: ## Print this message
55	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "%-20s %s\n", $$1, $$2}'