2018-11-07 19:42:43 -08:00
|
|
|
###
|
|
|
|
# Find OS and Go environment
|
|
|
|
# GO contains the Go binary
|
|
|
|
# FS contains the OS file separator
|
|
|
|
###
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
|
|
GO := $(shell where go.exe 2> NUL)
|
|
|
|
FS := \\
|
|
|
|
else
|
|
|
|
GO := $(shell command -v go 2> /dev/null)
|
|
|
|
FS := /
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(GO),)
|
|
|
|
$(error could not find go. Is it in PATH? $(GO))
|
|
|
|
endif
|
|
|
|
|
|
|
|
GOPATH ?= $(shell $(GO) env GOPATH)
|
|
|
|
GITHUBDIR := $(GOPATH)$(FS)src$(FS)github.com
|
2019-05-06 09:50:05 -07:00
|
|
|
GOLANGCI_LINT_VERSION := v1.16.0
|
2019-03-19 09:52:43 -07:00
|
|
|
GOLANGCI_LINT_HASHSUM := ac897cadc180bf0c1a4bf27776c410debad27205b22856b861d41d39d06509cf
|
2018-11-07 19:42:43 -08:00
|
|
|
|
|
|
|
###
|
|
|
|
# Functions
|
|
|
|
###
|
|
|
|
|
|
|
|
go_get = $(if $(findstring Windows_NT,$(OS)),\
|
|
|
|
IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS) ( mkdir $(GITHUBDIR)$(FS)$(1) ) else (cd .) &\
|
|
|
|
IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS)$(2)$(FS) ( cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2) ) else (cd .) &\
|
|
|
|
,\
|
|
|
|
mkdir -p $(GITHUBDIR)$(FS)$(1) &&\
|
|
|
|
(test ! -d $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2)) || true &&\
|
|
|
|
)\
|
|
|
|
cd $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && git fetch origin && git checkout -q $(3)
|
|
|
|
|
|
|
|
go_install = $(call go_get,$(1),$(2),$(3)) && cd $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && $(GO) install
|
|
|
|
|
2019-03-19 09:52:43 -07:00
|
|
|
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
|
|
|
|
mkfile_dir := $(shell cd $(shell dirname $(mkfile_path)); pwd)
|
|
|
|
|
2018-11-07 19:42:43 -08:00
|
|
|
###
|
2018-12-20 10:03:59 -08:00
|
|
|
# tools
|
2018-11-07 19:42:43 -08:00
|
|
|
###
|
2019-04-29 07:47:43 -07:00
|
|
|
|
|
|
|
GOLANGCI_LINT = $(GOBIN)/golangci-lint
|
|
|
|
STATIK = $(GOBIN)/statik
|
|
|
|
GOIMPORTS = $(GOBIN)/goimports
|
|
|
|
GOSUM = $(GOBIN)/gosum
|
|
|
|
CLOG = $(GOBIN)/clog
|
|
|
|
|
2018-12-20 10:03:59 -08:00
|
|
|
all: tools
|
2018-11-07 19:42:43 -08:00
|
|
|
|
2019-03-19 09:52:43 -07:00
|
|
|
tools: tools-stamp
|
2019-04-29 07:47:43 -07:00
|
|
|
tools-stamp: $(GOLANGCI_LINT) $(STATIK) $(GOIMPORTS) $(GOSUM) $(CLOG)
|
2019-03-19 09:52:43 -07:00
|
|
|
touch $@
|
|
|
|
|
2019-04-29 07:47:43 -07:00
|
|
|
$(GOLANGCI_LINT): $(mkfile_dir)/install-golangci-lint.sh $(GOSUM)
|
2019-04-15 06:00:28 -07:00
|
|
|
bash $(mkfile_dir)/install-golangci-lint.sh $(GOBIN) $(GOLANGCI_LINT_VERSION) $(GOLANGCI_LINT_HASHSUM)
|
2018-11-07 19:42:43 -08:00
|
|
|
|
2019-04-29 07:47:43 -07:00
|
|
|
$(STATIK):
|
2018-11-07 19:42:43 -08:00
|
|
|
$(call go_install,rakyll,statik,v0.1.5)
|
|
|
|
|
2019-04-29 07:47:43 -07:00
|
|
|
$(GOIMPORTS):
|
2019-03-18 05:45:25 -07:00
|
|
|
go get golang.org/x/tools/cmd/goimports@v0.0.0-20190114222345-bf090417da8b
|
|
|
|
|
2019-04-29 07:47:43 -07:00
|
|
|
$(GOSUM): ./contrib/devtools/gosum/main.go
|
|
|
|
go install -mod=readonly ./$(<D)/
|
2019-03-19 09:52:43 -07:00
|
|
|
|
2019-05-02 09:15:17 -07:00
|
|
|
$(CLOG):
|
|
|
|
$(call go_install,alessio,clog,1)
|
2018-11-26 11:20:43 -08:00
|
|
|
|
2019-01-29 16:02:39 -08:00
|
|
|
tools-clean:
|
2019-04-29 07:47:43 -07:00
|
|
|
rm -f $(GOLANGCI_LINT) $(STATIK) $(GOIMPORTS) $(GOSUM) $(CLOG)
|
2019-03-19 09:52:43 -07:00
|
|
|
rm -f tools-stamp
|
2019-01-29 16:02:39 -08:00
|
|
|
|
2019-03-19 09:52:43 -07:00
|
|
|
.PHONY: all tools tools-clean
|