github.com/iter8-tools/iter8@v1.1.2/Makefile (about) 1 BINDIR := $(CURDIR)/bin 2 INSTALL_PATH ?= /usr/local/bin 3 BINNAME ?= iter8 4 5 GOBIN = $(shell go env GOBIN) 6 ifeq ($(GOBIN),) 7 GOBIN = $(shell go env GOPATH)/bin 8 endif 9 10 # go options 11 TAGS := 12 LDFLAGS := -w -s 13 GOFLAGS := 14 15 # Rebuild the binary if any of these files change 16 SRC := $(shell find . -type f -name '*.(go|proto|tpl)' -print) go.mod go.sum 17 18 # Required for globs to work correctly 19 SHELL = /usr/bin/env bash 20 21 GIT_COMMIT = $(shell git rev-parse HEAD) 22 GIT_TAG = $(shell git describe --tags --dirty) 23 24 ifdef VERSION 25 BINARY_VERSION = $(VERSION) 26 endif 27 BINARY_VERSION ?= ${GIT_TAG} 28 29 # Only set Version if GIT_TAG or VERSION is set 30 ifneq ($(BINARY_VERSION),) 31 LDFLAGS += -X github.com/iter8-tools/iter8/base.Version=${BINARY_VERSION} 32 endif 33 34 35 LDFLAGS += -X github.com/iter8-tools/iter8/cmd.gitCommit=${GIT_COMMIT} 36 37 .PHONY: all 38 all: build 39 40 # ------------------------------------------------------------------------------ 41 # build 42 43 .PHONY: build 44 build: $(BINDIR)/$(BINNAME) 45 46 $(BINDIR)/$(BINNAME): $(SRC) 47 GO111MODULE=on go build $(GOFLAGS) -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o '$(BINDIR)'/$(BINNAME) ./ 48 49 # ------------------------------------------------------------------------------ 50 # install 51 52 .PHONY: install 53 install: build 54 @install "$(BINDIR)/$(BINNAME)" "$(INSTALL_PATH)/$(BINNAME)" 55 56 # ------------------------------------------------------------------------------ 57 # dependencies 58 59 .PHONY: clean 60 clean: 61 @rm -rf '$(BINDIR)' 62 63 # ------------------------------------------------------------------------------ 64 # test 65 66 .PHONY: fmt 67 fmt: ## Run go fmt against code. 68 go fmt ./... 69 70 .PHONY: vet 71 vet: ## Run go vet against code 72 go vet ./... 73 74 .PHONY: golangci-lint 75 golangci-lint: 76 golangci-lint run ./... 77 78 .PHONY: lint 79 lint: vet golangci-lint 80 81 .PHONY: test 82 test: fmt vet ## Run tests. 83 go test -v ./... -coverprofile=coverage.out 84 85 .PHONY: coverage 86 coverage: test 87 @echo "test coverage: $(shell go tool cover -func coverage.out | grep total | awk '{print substr($$3, 1, length($$3)-1)}')" 88 89 .PHONY: htmlcov 90 htmlcov: coverage 91 go tool cover -html=coverage.out