diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ef00bb7 --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +BINARY ?= librenotes +OUTDIR ?= . +CMD_PKG ?= ./cmd/librenotes +GO ?= go +GOFLAGS ?= +LDFLAGS ?= -X git.librete.ch/public/librenotes/internal/notesium.gitversion=$(shell git describe --tags --always --dirty 2>/dev/null || echo dev) \ + -X git.librete.ch/public/librenotes/internal/notesium.buildtime=$(shell date -u +%Y-%m-%dT%H:%M:%SZ) +TESTFLAGS ?= -race -count=1 + +.PHONY: all build test lint run clean help + +all: build + +build: + $(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(OUTDIR)/$(BINARY) $(CMD_PKG) + +test: + $(GO) test $(TESTFLAGS) ./... + +lint: + $(GO) vet ./... + @command -v staticcheck >/dev/null 2>&1 && staticcheck ./... || echo "staticcheck not installed, skipping" + +run: build + $(OUTDIR)/$(BINARY) $(ARGS) + +clean: + rm -f $(OUTDIR)/$(BINARY) + rm -f *.test *.out coverage.out + +help: + @echo "Targets:" + @echo " build - compile binary to \$$OUTDIR/\$$BINARY (default ./librenotes)" + @echo " test - run all Go tests with race detector" + @echo " lint - run go vet (+ staticcheck if installed)" + @echo " run - build and run; pass args via ARGS=\"...\"" + @echo " clean - remove build artifacts"