-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathMakefile
105 lines (86 loc) · 2.29 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
PREFIX ?= $(shell pwd)
NAME = fsql
PKG = github.com/kashav/$(NAME)
MAIN = $(PKG)/cmd/$(NAME)
DIST_DIR := ${PREFIX}/dist
DIST_DIRS := find . -type d | sed "s|^\./||" | grep -v \\. | tr '\n' '\0' | xargs -0 -I '{}'
SRCS := $(shell find . -type f -name '*.go')
PKGS := $(shell go list ./...)
VERSION := $(shell cat VERSION)
GITCOMMIT := $(shell git rev-parse --short HEAD)
ifneq ($(shell git status --porcelain --untracked-files=no),)
GITCOMMIT := $(GITCOMMIT)-dirty
endif
LDFLAGS := ${LDFLAGS} \
-X $(PKG)/meta.GITCOMMIT=${GITCOMMIT} \
-X $(PKG)/meta.VERSION=${VERSION}
.PHONY: all
all: $(NAME)
$(NAME): $(SRCS) VERSION
@echo "+ $@"
@go build -ldflags "${LDFLAGS}" -o $(NAME) -v $(MAIN)
.PHONY: install
install:
@echo "+ $@"
@go install $(PKGS)
.PHONY: get-tools
get-tools:
@echo "+ $@"
@go get -u -v golang.org/x/lint/golint
.PHONY: clean
clean:
@echo "+ $@"
$(RM) $(NAME)
$(RM) -r $(DIST_DIR)
.PHONY: fmt
fmt:
@echo "+ $@"
@test -z "$$(gofmt -s -l . 2>&1 | tee /dev/stderr)" || \
(echo >&2 "+ please format Go code with 'gofmt -s', or use 'make fmt-save'" && false)
.PHONY: fmt-save
fmt-save:
@echo "+ $@"
@gofmt -s -l . 2>&1 | xargs gofmt -s -l -w
.PHONY: vet
vet:
@echo "+ $@"
@go vet $(PKGS)
.PHONY: lint
lint:
@echo "+ $@"
$(if $(shell which golint || echo ''),, \
$(error Please install golint: `make get-tools`))
@test -z "$$(golint ./... 2>&1 | grep -v mock/ | tee /dev/stderr)"
.PHONY: test
test:
@echo "+ $@"
@go test -race $(PKGS)
.PHONY: coverage
coverage:
@echo "+ $@"
@for pkg in $(PKGS); do \
go test -test.short -race -coverprofile="../../../$$pkg/coverage.txt" $${pkg} || exit 1; \
done
.PHONY: bootstrap-dist
bootstrap-dist:
@echo "+ $@"
@go get -u -v github.com/franciscocpg/gox
.PHONY: build-all
build-all: $(SRCS) VERSION
@echo "+ $@"
@gox -verbose \
-ldflags "${LDFLAGS}" \
-os="darwin freebsd netbsd openbsd linux solaris windows" \
-arch="386 amd64 arm arm64" \
-osarch="!darwin/386 !darwin/arm" \
-output="$(DIST_DIR)/$(NAME)-{{.OS}}-{{.Arch}}/{{.Dir}}" $(MAIN)
.PHONY: dist
dist: clean build-all
@echo "+ $@"
@cd $(DIST_DIR) && \
$(DIST_DIRS) cp ../LICENSE {} && \
$(DIST_DIRS) cp ../README.md {} && \
$(DIST_DIRS) tar -zcf fsql-${VERSION}-{}.tar.gz {} && \
$(DIST_DIRS) zip -r -q fsql-${VERSION}-{}.zip {} && \
$(DIST_DIRS) rm -rf {} && \
cd ..