-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
74 lines (60 loc) · 1.9 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
PACKAGE := github.com/urfave/gfmrun
ALL_PACKAGES := $(PACKAGE) $(PACKAGE)/cmd/...
GIT ?= git
GO ?= go
GOLANGCI_LINT?= golangci-lint
PYTHON ?= python
VERSION_VAR := $(PACKAGE).VersionString
VERSION_VALUE ?= $(shell $(GIT) describe --always --dirty --tags 2>/dev/null)
REV_VAR := $(PACKAGE).RevisionString
REV_VALUE ?= $(shell $(GIT) rev-parse HEAD 2>/dev/null || echo "'???'")
GENERATED_VAR := $(PACKAGE).GeneratedString
GENERATED_VALUE ?= $(shell $(PYTHON) ./plz date)
COPYRIGHT_VAR := $(PACKAGE).CopyrightString
COPYRIGHT_VALUE ?= $(shell $(PYTHON) ./plz copyright)
GOBUILD_LDFLAGS ?= \
-X '$(VERSION_VAR)=$(VERSION_VALUE)' \
-X '$(REV_VAR)=$(REV_VALUE)' \
-X '$(GENERATED_VAR)=$(GENERATED_VALUE)' \
-X '$(COPYRIGHT_VAR)=$(COPYRIGHT_VALUE)'
.PHONY: all
all: clean test
.PHONY: test
test: deps build coverage.html selftest
.PHONY: test-no-cover
test-no-cover:
$(GO) test -v -x -ldflags "$(GOBUILD_LDFLAGS)" $(ALL_PACKAGES)
.PHONY: test-race
test-race: deps
$(GO) test -v -race -x -ldflags "$(GOBUILD_LDFLAGS)" $(ALL_PACKAGES)
.PHONY: selftest
selftest:
$(GO) run ./cmd/gfmrun/main.go -D -c $(shell $(PYTHON) ./plz test-count README.md)
coverage.html: coverage.coverprofile
$(GO) tool cover -html=$^ -o $@
coverage.coverprofile:
$(GO) test -v -x -cover -coverprofile=$@ -ldflags "$(GOBUILD_LDFLAGS)" $(PACKAGE)
$(GO) tool cover -func=$@
.PHONY: lint
lint:
$(GOLANGCI_LINT) run
.PHONY: build
build: deps
GOOS=linux GOARCH=amd64 $(GO) build \
-o gfmrun-linux-amd64-$(VERSION_VALUE) \
-ldflags "$(GOBUILD_LDFLAGS)" \
./cmd/gfmrun/main.go && \
GOOS=darwin GOARCH=amd64 $(GO) build \
-o gfmrun-darwin-amd64-$(VERSION_VALUE) \
-ldflags "$(GOBUILD_LDFLAGS)" \
./cmd/gfmrun/main.go && \
GOOS=windows GOARCH=amd64 $(GO) build \
-o gfmrun-windows-amd64-$(VERSION_VALUE).exe \
-ldflags "$(GOBUILD_LDFLAGS)" \
./cmd/gfmrun/main.go
.PHONY: deps
deps:
go get ./...
.PHONY: clean
clean:
$(PYTHON) ./plz clean