From ecedd4ee2c32b5f6c0cc9ea4913cc8f0b743a720 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Tue, 10 Nov 2020 14:49:51 +0100 Subject: [PATCH] Reorganize Makefiles --- Makefile | 85 ++++++++-------------------------------------- Makefile.inc | 60 ++++++++++++++++++++++++++++++++ provision/Makefile | 8 ++--- store/Makefile | 2 ++ 4 files changed, 79 insertions(+), 76 deletions(-) create mode 100644 Makefile.inc diff --git a/Makefile b/Makefile index fc83ba5d7..4322729f9 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,6 @@ .PHONY: pack build help qa critic vet codegen provision docs build -GO = go -GOGET = $(GO) get -u -GOFLAGS ?= -mod=vendor -GOPATH ?= $(HOME)/go - -CGO_ENABLED = 1 - -export GOFLAGS -export CGO_ENABLED +include Makefile.inc BUILD_FLAVOUR ?= corteza BUILD_TIME ?= $(shell date +%FT%T%z) @@ -60,38 +52,20 @@ DEV_MAILHOG_HTTP_ADDR ?= 8025 DOCKER ?= docker -######################################################################################################################## -# Tool bins -GOCRITIC = $(GOPATH)/bin/gocritic -MOCKGEN = $(GOPATH)/bin/mockgen -GOTEST = $(GOPATH)/bin/gotest -STATICCHECK = $(GOPATH)/bin/staticcheck -PROTOGEN = $(GOPATH)/bin/protoc-gen-go -PROTOGEN_GRPC = $(GOPATH)/bin/protoc-gen-go-grpc -GIN = $(GOPATH)/bin/gin -STATIK = $(GOPATH)/bin/statik -CODEGEN = build/codegen - -PROTOC = /usr/local/bin/protoc -FSWATCH = /usr/local/bin/fswatch - -# fswatch is intentionally left out... -BINS = $(GOCRITIC) $(MOCKGEN) $(GOTEST) $(STATICCHECK) $(PROTOGEN) $(GIN) $(STATIK) $(CODEGEN) - help: - @echo - @echo Usage: make [target] - @echo - @echo - build build all apps - @echo - build. build a specific app - @echo - vet run go vet on all code - @echo - critic run go critic on all code - @echo - test.all run all tests - @echo - test.unit run all unit tests - @echo - test.integration run all integration tests - @echo - @echo See tests/README.md for more info on running tests - @echo + @echo "" + @echo " Usage: make [target]" + @echo "" + @echo " - build build all apps" + @echo " - build. build a specific app" + @echo " - vet run go vet on all code" + @echo " - critic run go critic on all code" + @echo " - test.all run all tests" + @echo " - test.unit run all unit tests" + @echo " - test.integration run all integration tests" + @echo "" + @echo " See tests/README.md for more info on running tests" + @echo "" ######################################################################################################################## # Building & packing @@ -218,37 +192,6 @@ qa: vet critic test mocks: $(MOCKGEN) $(MOCKGEN) -package mail -source pkg/mail/mail.go -destination pkg/mail/mail_mock_test.go -######################################################################################################################## -# Go Toolset -$(GOCRITIC): - $(GOGET) github.com/go-critic/go-critic/... - -$(MOCKGEN): - $(GOGET) github.com/golang/mock/mockgen - -$(STATICCHECK): - $(GOGET) honnef.co/go/tools/cmd/staticcheck - -$(PROTOGEN): - $(GOGET) github.com/golang/protobuf/protoc-gen-go - -$(PROTOGEN_GRPC): - $(GOGET) google.golang.org/grpc/cmd/protoc-gen-go-grpc - -$(GIN): - $(GOGET) github.com/codegangsta/gin - -$(GOTEST): - $(GOGET) github.com/rakyll/gotest - -$(STATIK): - $(GOGET) github.com/goware/statik - -$(CODEGEN): - $(GO) build -o $@ cmd/codegen/main.go - -clean: - rm -f $(BINS) ######################################################################################################################## # Toolset diff --git a/Makefile.inc b/Makefile.inc new file mode 100644 index 000000000..36f6c7b0b --- /dev/null +++ b/Makefile.inc @@ -0,0 +1,60 @@ +GO = go +GOGET = $(GO) get -u +GOFLAGS ?= -mod=vendor +GOPATH ?= $(HOME)/go + +CGO_ENABLED = 1 + +export GOFLAGS +export CGO_ENABLED + +######################################################################################################################## +# Tool bins +GOCRITIC = $(GOPATH)/bin/gocritic +MOCKGEN = $(GOPATH)/bin/mockgen +GOTEST = $(GOPATH)/bin/gotest +STATICCHECK = $(GOPATH)/bin/staticcheck +PROTOGEN = $(GOPATH)/bin/protoc-gen-go +PROTOGEN_GRPC = $(GOPATH)/bin/protoc-gen-go-grpc +GIN = $(GOPATH)/bin/gin +STATIK = $(GOPATH)/bin/statik +CODEGEN = build/codegen + +PROTOC = /usr/local/bin/protoc +FSWATCH = /usr/local/bin/fswatch + +# fswatch is intentionally left out... +BINS = $(GOCRITIC) $(MOCKGEN) $(GOTEST) $(STATICCHECK) $(PROTOGEN) $(GIN) $(STATIK) $(CODEGEN) + + +######################################################################################################################## +# Go Toolset +$(GOCRITIC): + $(GOGET) github.com/go-critic/go-critic/... + +$(MOCKGEN): + $(GOGET) github.com/golang/mock/mockgen + +$(STATICCHECK): + $(GOGET) honnef.co/go/tools/cmd/staticcheck + +$(PROTOGEN): + $(GOGET) github.com/golang/protobuf/protoc-gen-go + +$(PROTOGEN_GRPC): + $(GOGET) google.golang.org/grpc/cmd/protoc-gen-go-grpc + +$(GIN): + $(GOGET) github.com/codegangsta/gin + +$(GOTEST): + $(GOGET) github.com/rakyll/gotest + +$(STATIK): + $(GOGET) github.com/goware/statik + +$(CODEGEN): + $(GO) build -o $@ cmd/codegen/main.go + +clean-tools: + rm -f $(BINS) diff --git a/provision/Makefile b/provision/Makefile index d1610e2cc..6030dff46 100644 --- a/provision/Makefile +++ b/provision/Makefile @@ -1,8 +1,9 @@ -.PHONY: clean +.PHONY: clean all + +include ../Makefile.inc PARTS ?= compose messaging system OUTPUTS ?= $(addsuffix /static.go, $(PARTS)) -STATIK = $(GOPATH)/bin/statik all: $(OUTPUTS) @@ -11,6 +12,3 @@ all: $(OUTPUTS) clean: rm -f $(OUTPUTS) - -$(STATIK): - $(MAKE) --directory=../ $(STATIK) diff --git a/store/Makefile b/store/Makefile index c333419de..d3c713e4b 100644 --- a/store/Makefile +++ b/store/Makefile @@ -1,4 +1,6 @@ +include ../Makefile.inc + GOTOOL ?= go tool GOTEST ?= go test GOFLAGS ?= -mod=vendor