blob: c7ca01758919eb920a0ec8a14047943b3fb29daf [file] [log] [blame]
Scott Baker2c0ebda2019-05-06 16:55:47 -07001ifeq ($(GOPATH),)
2$(error Please set your GOPATH)
3endif
4
5VERSION=$(shell cat $(GOPATH)/src/github.com/opencord/cordctl/VERSION)
6GITCOMMIT=$(shell git log --pretty=format:"%h" -n 1)
Scott Baker63ce82e2019-05-15 09:01:42 -07007ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
8GITDIRTY=false
9else
10GITDIRTY=true
11endif
Scott Baker2c0ebda2019-05-06 16:55:47 -070012GOVERSION=$(shell go version 2>&1 | sed -E 's/.*(go[0-9]+\.[0-9]+\.[0-9]+).*/\1/g')
13OSTYPE=$(shell uname -s | tr A-Z a-z)
14OSARCH=$(shell uname -p | tr A-Z a-z)
15BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
16
17LDFLAGS=-ldflags \
18 '-X "github.com/opencord/cordctl/cli/version.Version=$(VERSION)" \
19 -X "github.com/opencord/cordctl/cli/version.GitCommit=$(GITCOMMIT)" \
Scott Baker63ce82e2019-05-15 09:01:42 -070020 -X "github.com/opencord/cordctl/cli/version.GitDirty=$(GITDIRTY)" \
Scott Baker2c0ebda2019-05-06 16:55:47 -070021 -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 Baker63ce82e2019-05-15 09:01:42 -070024 -X "github.com/opencord/cordctl/cli/version.BuildTime=$(BUILDTIME)"'
Scott Baker2c0ebda2019-05-06 16:55:47 -070025
26help:
27
28build: dependencies
29 go build $(LDFLAGS) cmd/cordctl.go
30
31dependencies:
Scott Baker6cf525a2019-05-09 12:25:08 -070032 [ -d "vendor" ] || dep ensure
Scott Baker2c0ebda2019-05-06 16:55:47 -070033
34lint: 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
39test: 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 Baker6cf525a2019-05-09 12:25:08 -070046
47clean:
48 rm -f cordctl
49 rm -rf vendor
50 rm -f Gopkg.lock