Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 1 | ifeq ($(GOPATH),) |
| 2 | $(error Please set your GOPATH) |
| 3 | endif |
| 4 | |
| 5 | VERSION=$(shell cat $(GOPATH)/src/github.com/opencord/cordctl/VERSION) |
| 6 | GITCOMMIT=$(shell git log --pretty=format:"%h" -n 1) |
Scott Baker | 63ce82e | 2019-05-15 09:01:42 -0700 | [diff] [blame^] | 7 | ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 8 | GITDIRTY=false |
| 9 | else |
| 10 | GITDIRTY=true |
| 11 | endif |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 12 | GOVERSION=$(shell go version 2>&1 | sed -E 's/.*(go[0-9]+\.[0-9]+\.[0-9]+).*/\1/g') |
| 13 | OSTYPE=$(shell uname -s | tr A-Z a-z) |
| 14 | OSARCH=$(shell uname -p | tr A-Z a-z) |
| 15 | BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 16 | |
| 17 | LDFLAGS=-ldflags \ |
| 18 | '-X "github.com/opencord/cordctl/cli/version.Version=$(VERSION)" \ |
| 19 | -X "github.com/opencord/cordctl/cli/version.GitCommit=$(GITCOMMIT)" \ |
Scott Baker | 63ce82e | 2019-05-15 09:01:42 -0700 | [diff] [blame^] | 20 | -X "github.com/opencord/cordctl/cli/version.GitDirty=$(GITDIRTY)" \ |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 21 | -X "github.com/opencord/cordctl/cli/version.GoVersion=$(GOVERSION)" \ |
| 22 | -X "github.com/opencord/cordctl/cli/version.Os=$(OSTYPE)" \ |
| 23 | -X "github.com/opencord/cordctl/cli/version.Arch=$(OSARCH)" \ |
Scott Baker | 63ce82e | 2019-05-15 09:01:42 -0700 | [diff] [blame^] | 24 | -X "github.com/opencord/cordctl/cli/version.BuildTime=$(BUILDTIME)"' |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 25 | |
| 26 | help: |
| 27 | |
| 28 | build: dependencies |
| 29 | go build $(LDFLAGS) cmd/cordctl.go |
| 30 | |
| 31 | dependencies: |
Scott Baker | 6cf525a | 2019-05-09 12:25:08 -0700 | [diff] [blame] | 32 | [ -d "vendor" ] || dep ensure |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 33 | |
| 34 | lint: dependencies |
| 35 | find $(GOPATH)/src/github.com/opencord/cordctl -name "*.go" -not -path '$(GOPATH)/src/github.com/opencord/cordctl/vendor/*' | xargs gofmt -l |
| 36 | go vet ./... |
| 37 | dep check |
| 38 | |
| 39 | test: dependencies |
| 40 | @mkdir -p ./tests/results |
| 41 | @go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\ |
| 42 | RETURN=$$? ;\ |
| 43 | go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\ |
| 44 | gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\ |
| 45 | exit $$RETURN |
Scott Baker | 6cf525a | 2019-05-09 12:25:08 -0700 | [diff] [blame] | 46 | |
| 47 | clean: |
| 48 | rm -f cordctl |
| 49 | rm -rf vendor |
| 50 | rm -f Gopkg.lock |