GOPKGSRC ?= $(wildcard *.go) GOTESTSRC ?= $(wildcard *_test.go) GOSRC ?= $(filter-out $(GOTESTSRC),$(GOPKGSRC)) GOTESTDATA ?= $(shell test ! -d testdata || find testdata) GOMAINSRC ?= $(wildcard cmd/*/main.go) GOBIN ?= $(patsubst cmd/%/main.go,%,$(GOMAINSRC)) GOCOVERAGE ?= go.coverage GOBENCHMARK ?= go.benchmark %: cmd/%/main.go $(GOPKGSRC) go build -o $@ $(GOBUILDFLAGS) $< test:: $(GOCOVERAGE).out $(GOCOVERAGE).out: GOTESTFLAGS ?= -race $(GOCOVERAGE).out: $(GOPKGSRC) $(GOTESTSRC) $(GOTESTDATA) go.mod go test -coverprofile=$@ $(GOTESTFLAGS) ./... $(GOCOVERAGE).html: $(GOCOVERAGE).out go tool cover -html $< -o $@ bench:: $(GOBENCHMARK) $(GOBENCHMARK): GOBENCHFLAGS ?= -benchmem $(GOBENCHMARK): $(GOPKGSRC) $(GOTESTSRC) $(GOTESTDATA) go.mod go test -bench . $(GOBENCHFLAGS) | tee $@ clean:: $(RM) $(GOCOVERAGE).{html,out} $(GOBENCHMARK) $(GOBIN) .PHONY: clean test $(GOCOVERAGE) .DELETE_ON_ERROR: