-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
95 lines (80 loc) · 2 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
.DEFAULT_GOAL := help
GOCMD := env GO111MODULE=on go
GOMOD := $(GOCMD) mod
GOBUILD := $(GOCMD) build
GOINSTALL := $(GOCMD) install
GOCLEAN := $(GOCMD) clean
GOTEST := $(GOCMD) test
GOGET := $(GOCMD) get
NAME := pa
CURRENT := $(shell pwd)
BUILDDIR := ./build
BINDIR := $(BUILDDIR)/bin
PKGDIR := $(BUILDDIR)/pkg
DISTDIR := $(BUILDDIR)/dist
VERSION := $(shell git describe --tags --abbrev=0)
LDFLAGS := -X 'github.com/ebc-2in2crc/$(NAME)/cmd.version=$(VERSION)'
GOXOS := "darwin windows linux"
GOXARCH := "386 amd64"
GOXOUTPUT := "$(PKGDIR)/$(NAME)_{{.OS}}_{{.Arch}}/{{.Dir}}"
export GO111MODULE=on
.PHONY: deps
## Install dependencies
deps:
$(GOMOD) download
.PHONY: devel-deps
## Install dependencies for develop
devel-deps: deps
$(GOGET) \
golang.org/x/tools/cmd/goimports \
golang.org/x/lint/golint \
github.com/Songmu/make2help/cmd/make2help \
github.com/mitchellh/gox \
github.com/tcnksm/ghr
.PHONY: build
## Build binaries
build: deps
$(GOBUILD) -ldflags "$(LDFLAGS)" -o $(BINDIR)/$(NAME) ./cmd/$(NAME)
.PHONY: cross-build
## Cross build binaries
cross-build:
rm -rf $(PKGDIR)
gox -os=$(GOXOS) -arch=$(GOXARCH) -ldflags "$(LDFLAGS)" -output=$(GOXOUTPUT) ./cmd/$(NAME)
.PHONY: package
## Make package
package: cross-build
rm -rf $(DISTDIR)
mkdir $(DISTDIR)
pushd $(PKGDIR) > /dev/null && \
for P in `ls | xargs basename`; do zip -r $(CURRENT)/$(DISTDIR)/$$P.zip $$P; done && \
popd > /dev/null
.PHONY: release
## Release package to Github
release: package
ghr $(VERSION) $(DISTDIR)
.PHONY: zsh_completion
## Generate ZSH completion
zsh_completion: build
$(BINDIR)/$(NAME) completion zsh > ~/.zsh/completions/_$(NAME)
. ~/.zsh/completions/_$(NAME)
.PHONY: test
## Run tests
test: deps
$(GOTEST) -v ./...
.PHONY: lint
## Lint
lint: devel-deps
go vet ./...
golint -set_exit_status ./...
.PHONY: fmt
## Format source codes
fmt: deps
find . -name "*.go" -not -path "./vendor/*" | xargs goimports -w
.PHONY: clean
clean:
$(GOCLEAN)
rm -rf $(BUILDDIR)
.PHONY: help
## Show help
help:
@make2help $(MAKEFILE_LIST)