refactor(Makefile): allow overriding default go program (#270)

* refactor(Makefile): allow overriding default go program

* fix typo

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2017-08-15 12:16:04 +08:00 committed by GitHub
parent 2bcc17de51
commit 770aee9859
1 changed files with 23 additions and 23 deletions

View File

@ -1,13 +1,14 @@
DIST := dist DIST := dist
EXECUTABLE := gorush EXECUTABLE := gorush
GO ?= go
DEPLOY_ACCOUNT := appleboy DEPLOY_ACCOUNT := appleboy
DEPLOY_IMAGE := $(EXECUTABLE) DEPLOY_IMAGE := $(EXECUTABLE)
GOFMT ?= gofmt "-s" GOFMT ?= gofmt "-s"
TARGETS ?= linux darwin windows TARGETS ?= linux darwin windows
ARCHS ?= amd64 386 ARCHS ?= amd64 386
PACKAGES ?= $(shell go list ./... | grep -v /vendor/) PACKAGES ?= $(shell $(GO) list ./... | grep -v /vendor/)
GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*") GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*")
SOURCES ?= $(shell find . -name "*.go" -type f) SOURCES ?= $(shell find . -name "*.go" -type f)
TAGS ?= TAGS ?=
@ -46,7 +47,6 @@ fmt:
.PHONY: fmt-check .PHONY: fmt-check
fmt-check: fmt-check:
# get all go files and run go fmt on them
@diff=$$($(GOFMT) -d $(GOFILES)); \ @diff=$$($(GOFMT) -d $(GOFILES)); \
if [ -n "$$diff" ]; then \ if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \ echo "Please run 'make fmt' and commit the result:"; \
@ -55,63 +55,63 @@ fmt-check:
fi; fi;
vet: vet:
go vet $(PACKAGES) $(GO) vet $(PACKAGES)
deps: deps:
go get github.com/campoy/embedmd $(GO) get github.com/campoy/embedmd
embedmd: embedmd:
embedmd -d *.md embedmd -d *.md
errcheck: errcheck:
@hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/kisielk/errcheck; \ $(GO) get -u github.com/kisielk/errcheck; \
fi fi
errcheck $(PACKAGES) errcheck $(PACKAGES)
lint: lint:
@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/golang/lint/golint; \ $(GO) get -u github.com/golang/lint/golint; \
fi fi
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done; for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
unconvert: unconvert:
@hash unconvert > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ @hash unconvert > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/mdempsky/unconvert; \ $(GO) get -u github.com/mdempsky/unconvert; \
fi fi
for PKG in $(PACKAGES); do unconvert -v $$PKG || exit 1; done; for PKG in $(PACKAGES); do unconvert -v $$PKG || exit 1; done;
.PHONY: install .PHONY: install
install: $(SOURCES) install: $(SOURCES)
go install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' $(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
.PHONY: build .PHONY: build
build: $(EXECUTABLE) build: $(EXECUTABLE)
$(EXECUTABLE): $(SOURCES) $(EXECUTABLE): $(SOURCES)
go build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@ $(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
.PHONY: misspell-check .PHONY: misspell-check
misspell-check: misspell-check:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/client9/misspell/cmd/misspell; \ $(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi fi
misspell -error $(GOFILES) misspell -error $(GOFILES)
.PHONY: misspell .PHONY: misspell
misspell: misspell:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/client9/misspell/cmd/misspell; \ $(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi fi
misspell -w $(GOFILES) misspell -w $(GOFILES)
test: fmt-check test: fmt-check
for PKG in $(PACKAGES); do go test -v -cover -coverprofile $$GOPATH/src/$$PKG/coverage.txt $$PKG || exit 1; done; for PKG in $(PACKAGES); do $(GO) test -v -cover -coverprofile $$GOPATH/src/$$PKG/coverage.txt $$PKG || exit 1; done;
.PHONY: test-vendor .PHONY: test-vendor
test-vendor: test-vendor:
@hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ @hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/kardianos/govendor; \ $(GO) get -u github.com/kardianos/govendor; \
fi fi
govendor list +unused | tee "$(TMPDIR)/wc-gitea-unused" govendor list +unused | tee "$(TMPDIR)/wc-gitea-unused"
[ $$(cat "$(TMPDIR)/wc-gitea-unused" | wc -l) -eq 0 ] || echo "Warning: /!\\ Some vendor are not used /!\\" [ $$(cat "$(TMPDIR)/wc-gitea-unused" | wc -l) -eq 0 ] || echo "Warning: /!\\ Some vendor are not used /!\\"
@ -122,25 +122,25 @@ test-vendor:
govendor status || exit 1 govendor status || exit 1
redis_test: init redis_test: init
go test -v -cover ./storage/redis/... $(GO) test -v -cover ./storage/redis/...
boltdb_test: init boltdb_test: init
go test -v -cover ./storage/boltdb/... $(GO) test -v -cover ./storage/boltdb/...
memory_test: init memory_test: init
go test -v -cover ./storage/memory/... $(GO) test -v -cover ./storage/memory/...
buntdb_test: init buntdb_test: init
go test -v -cover ./storage/buntdb/... $(GO) test -v -cover ./storage/buntdb/...
leveldb_test: init leveldb_test: init
go test -v -cover ./storage/leveldb/... $(GO) test -v -cover ./storage/leveldb/...
config_test: init config_test: init
go test -v -cover ./config/... $(GO) test -v -cover ./config/...
html: html:
go tool cover -html=.cover/coverage.txt $(GO) tool cover -html=.cover/coverage.txt
release: release-dirs release-build release-copy release-check release: release-dirs release-build release-copy release-check
@ -149,7 +149,7 @@ release-dirs:
release-build: release-build:
@hash gox > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ @hash gox > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/mitchellh/gox; \ $(GO) get -u github.com/mitchellh/gox; \
fi fi
gox -os="$(TARGETS)" -arch="$(ARCHS)" -tags="$(TAGS)" -ldflags="$(EXTLDFLAGS)-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}" gox -os="$(TARGETS)" -arch="$(ARCHS)" -tags="$(TAGS)" -ldflags="$(EXTLDFLAGS)-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
@ -160,7 +160,7 @@ release-check:
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;) cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
docker_build: docker_build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags '$(TAGS)' -ldflags "$(EXTLDFLAGS)-s -w $(LDFLAGS)" -o bin/$(EXECUTABLE) CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags "$(EXTLDFLAGS)-s -w $(LDFLAGS)" -o bin/$(EXECUTABLE)
docker_image: docker_image:
docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) -f Dockerfile . docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) -f Dockerfile .
@ -176,7 +176,7 @@ endif
docker push $(DEPLOY_ACCOUNT)/$(EXECUTABLE):$(tag) docker push $(DEPLOY_ACCOUNT)/$(EXECUTABLE):$(tag)
clean: clean:
go clean -x -i ./... $(GO) clean -x -i ./...
find . -name coverage.txt -delete find . -name coverage.txt -delete
find . -name *.tar.gz -delete find . -name *.tar.gz -delete
find . -name *.db -delete find . -name *.db -delete