blob: 4ef3f1c9ef3cbd76309444ca6bd0bdb96c933617 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001ifeq ($(GOPATH),)
2$(error "***** Please set your GOPATH environment variable")
3endif
4
5ifneq ($(GOPATH)/src/github.com/ciena/voltctl,$(shell pwd))
6$(warning "***** Your GOPATH environment variable may not be set correctly. Your current directory should be $$GOPATH/src/github.com/ciena/voltctl")
7endif
8
9help:
10
11internal/pkg/commands/voltha_v1_pb.go: assets/protosets/voltha_v1.pb
12 @echo "package commands" > $@
13 @echo "" >> $@
14 @echo "var V1Descriptor = []byte{" >> $@
15 hexdump -ve '1/1 "0x%02x,"' assets/protosets/voltha_v1.pb | fold -w 60 -s >> $@
16 @echo "}" >> $@
17 @go fmt $@
18
19internal/pkg/commands/voltha_v2_pb.go: assets/protosets/voltha_v2.pb
20 @echo "package commands" > $@
21 @echo "" >> $@
22 @echo "var V2Descriptor = []byte{" >> $@
23 hexdump -ve '1/1 "0x%02x,"' assets/protosets/voltha_v2.pb | fold -w 60 -s >> $@
24 @echo "}" >> $@
25 @go fmt $@
26
27encode-protosets: internal/pkg/commands/voltha_v1_pb.go internal/pkg/commands/voltha_v2_pb.go
28
29VERSION=$(shell cat $(GOPATH)/src/github.com/ciena/voltctl/VERSION)
30GITCOMMIT=$(shell git rev-parse HEAD)
31ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
32GITDIRTY=false
33else
34GITDIRTY=true
35endif
36GOVERSION=$(shell go version 2>&1 | sed -E 's/.*(go[0-9]+\.[0-9]+\.[0-9]+).*/\1/g')
37HOST_OS=$(shell uname -s | tr A-Z a-z)
38ifeq ($(shell uname -m),x86_64)
39 HOST_ARCH ?= amd64
40else
41 HOST_ARCH ?= $(shell uname -m)
42endif
43BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
44
45LDFLAGS=-ldflags \
46 '-X "github.com/ciena/voltctl/internal/pkg/cli/version.Version=$(VERSION)" \
47 -X "github.com/ciena/voltctl/internal/pkg/cli/version.VcsRef=$(GITCOMMIT)" \
48 -X "github.com/ciena/voltctl/internal/pkg/cli/version.VcsDirty=$(GITDIRTY)" \
49 -X "github.com/ciena/voltctl/internal/pkg/cli/version.GoVersion=$(GOVERSION)" \
50 -X "github.com/ciena/voltctl/internal/pkg/cli/version.Os=$(HOST_OS)" \
51 -X "github.com/ciena/voltctl/internal/pkg/cli/version.Arch=$(HOST_ARCH)" \
52 -X "github.com/ciena/voltctl/internal/pkg/cli/version.BuildTime=$(BUILDTIME)"'
53
54# Release related items
55# Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH
56# Inspired by: https://github.com/kubernetes/minikube/releases
57RELEASE_DIR ?= release
58RELEASE_NAME ?= voltctl
59RELEASE_OS_ARCH ?= linux-amd64 windows-amd64 darwin-amd64
60RELEASE_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_NAME)-$(subst -dev,_dev,$(VERSION))-$(rel))
61
62# Functions to extract the OS/ARCH
63rel_ver = $(word 2, $(subst -, ,$(notdir $@)))
64rel_os = $(word 3, $(subst -, ,$(notdir $@)))
65rel_arch = $(word 4, $(subst -, ,$(notdir $@)))
66
67dependencies:
68 [ -d "vendor" ] || dep ensure
69
70$(RELEASE_BINS): dependencies
71 mkdir -p $(RELEASE_DIR)
72 GOPATH=$(GOPATH) GOOS=$(rel_os) GOARCH=$(rel_arch) \
73 go build -v $(LDFLAGS) -o "$@" cmd/voltctl/voltctl.go
74
75release: $(RELEASE_BINS)
76
77build: dependencies
78 GOPATH=$(GOPATH) \
79 go build $(LDFLAGS) \
80 cmd/voltctl/voltctl.go
81
82install: dependencies
83 GOPATH=$(GOPATH) GOBIN=$(GOPATH)/bin go install $(LDFLAGS) \
84 cmd/voltctl/voltctl.go
85
86run: dependencies
87 GOPATH=$(GOPATH) go run $(LDFLAGS) github.com/ciena/voltctl/cmd/voltctl $(CMD)
88
89lint: dependencies
90 GOPATH=$(GOPATH) find $(GOPATH)/src/github.com/ciena/voltctl -name "*.go" -not -path '$(GOPATH)/src/github.com/ciena/voltctl/vendor/*' | xargs gofmt -l
91 GOPATH=$(GOPATH) go vet github.com/ciena/voltctl/...
92 dep check
93
94test: dependencies
95 GOPATH=$(GOPATH) go test $(TEST_ARGS) -cover -coverprofile=voltctl.cp github.com/ciena/voltctl/...
96
97view-coverage:
98 GOPATH=$(GOPATH) go tool cover -html voltctl.cp
99
100clean:
101 rm -rf voltctl voltctl.cp release