blob: 9c6aa7f03bde096deecd861104b5125a3df99dfe [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001ifeq ($(GOPATH),)
2$(error "***** Please set your GOPATH environment variable")
3endif
4
Scott Baker2b0ad652019-08-21 14:57:07 -07005ifneq ($(GOPATH)/src/github.com/opencord/voltctl,$(shell pwd))
6$(warning "***** Your GOPATH environment variable may not be set correctly. Your current directory should be $$GOPATH/src/github.com/opencord/voltctl")
Zack Williamse940c7a2019-08-21 14:25:39 -07007endif
8
9help:
10
11internal/pkg/commands/voltha_v1_pb.go: assets/protosets/voltha_v1.pb
Scott Baker2b0ad652019-08-21 14:57:07 -070012 @echo "/*" > $@
13 @echo " * Copyright 2019-present Open Networking Foundation" >> $@
14 @echo " *" >> $@
15 @echo " * Licensed under the Apache License, Version 2.0 (the "License");" >> $@
16 @echo " * you may not use this file except in compliance with the License." >> $@
17 @echo " * You may obtain a copy of the License at" >> $@
18 @echo " *" >> $@
19 @echo " * http://www.apache.org/licenses/LICENSE-2.0" >> $@
20 @echo " *" >> $@
21 @echo " * Unless required by applicable law or agreed to in writing, software" >> $@
22 @echo " * distributed under the License is distributed on an "AS IS" BASIS," >> $@
23 @echo " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." >> $@
24 @echo " * See the License for the specific language governing permissions and" >> $@
25 @echo " * limitations under the License." >> $@
26 @echo " */" >> $@
27 @echo "package commands" >> $@
Zack Williamse940c7a2019-08-21 14:25:39 -070028 @echo "" >> $@
29 @echo "var V1Descriptor = []byte{" >> $@
30 hexdump -ve '1/1 "0x%02x,"' assets/protosets/voltha_v1.pb | fold -w 60 -s >> $@
31 @echo "}" >> $@
32 @go fmt $@
33
34internal/pkg/commands/voltha_v2_pb.go: assets/protosets/voltha_v2.pb
Scott Baker2b0ad652019-08-21 14:57:07 -070035 @echo "/*" > $@
36 @echo " * Copyright 2019-present Open Networking Foundation" >> $@
37 @echo " *" >> $@
38 @echo " * Licensed under the Apache License, Version 2.0 (the "License");" >> $@
39 @echo " * you may not use this file except in compliance with the License." >> $@
40 @echo " * You may obtain a copy of the License at" >> $@
41 @echo " *" >> $@
42 @echo " * http://www.apache.org/licenses/LICENSE-2.0" >> $@
43 @echo " *" >> $@
44 @echo " * Unless required by applicable law or agreed to in writing, software" >> $@
45 @echo " * distributed under the License is distributed on an "AS IS" BASIS," >> $@
46 @echo " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." >> $@
47 @echo " * See the License for the specific language governing permissions and" >> $@
48 @echo " * limitations under the License." >> $@
49 @echo " */" >> $@
50 @echo "package commands" >> $@
Zack Williamse940c7a2019-08-21 14:25:39 -070051 @echo "" >> $@
52 @echo "var V2Descriptor = []byte{" >> $@
53 hexdump -ve '1/1 "0x%02x,"' assets/protosets/voltha_v2.pb | fold -w 60 -s >> $@
54 @echo "}" >> $@
55 @go fmt $@
56
57encode-protosets: internal/pkg/commands/voltha_v1_pb.go internal/pkg/commands/voltha_v2_pb.go
58
Scott Baker2b0ad652019-08-21 14:57:07 -070059VERSION=$(shell cat $(GOPATH)/src/github.com/opencord/voltctl/VERSION)
Zack Williamse940c7a2019-08-21 14:25:39 -070060GITCOMMIT=$(shell git rev-parse HEAD)
61ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
62GITDIRTY=false
63else
64GITDIRTY=true
65endif
66GOVERSION=$(shell go version 2>&1 | sed -E 's/.*(go[0-9]+\.[0-9]+\.[0-9]+).*/\1/g')
67HOST_OS=$(shell uname -s | tr A-Z a-z)
68ifeq ($(shell uname -m),x86_64)
69 HOST_ARCH ?= amd64
70else
71 HOST_ARCH ?= $(shell uname -m)
72endif
73BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
74
75LDFLAGS=-ldflags \
Scott Baker2b0ad652019-08-21 14:57:07 -070076 '-X "github.com/opencord/voltctl/internal/pkg/cli/version.Version=$(VERSION)" \
77 -X "github.com/opencord/voltctl/internal/pkg/cli/version.VcsRef=$(GITCOMMIT)" \
78 -X "github.com/opencord/voltctl/internal/pkg/cli/version.VcsDirty=$(GITDIRTY)" \
79 -X "github.com/opencord/voltctl/internal/pkg/cli/version.GoVersion=$(GOVERSION)" \
80 -X "github.com/opencord/voltctl/internal/pkg/cli/version.Os=$(HOST_OS)" \
81 -X "github.com/opencord/voltctl/internal/pkg/cli/version.Arch=$(HOST_ARCH)" \
82 -X "github.com/opencord/voltctl/internal/pkg/cli/version.BuildTime=$(BUILDTIME)"'
Zack Williamse940c7a2019-08-21 14:25:39 -070083
84# Release related items
85# Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH
86# Inspired by: https://github.com/kubernetes/minikube/releases
87RELEASE_DIR ?= release
88RELEASE_NAME ?= voltctl
89RELEASE_OS_ARCH ?= linux-amd64 windows-amd64 darwin-amd64
90RELEASE_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_NAME)-$(subst -dev,_dev,$(VERSION))-$(rel))
91
92# Functions to extract the OS/ARCH
93rel_ver = $(word 2, $(subst -, ,$(notdir $@)))
94rel_os = $(word 3, $(subst -, ,$(notdir $@)))
95rel_arch = $(word 4, $(subst -, ,$(notdir $@)))
96
97dependencies:
98 [ -d "vendor" ] || dep ensure
99
100$(RELEASE_BINS): dependencies
101 mkdir -p $(RELEASE_DIR)
102 GOPATH=$(GOPATH) GOOS=$(rel_os) GOARCH=$(rel_arch) \
103 go build -v $(LDFLAGS) -o "$@" cmd/voltctl/voltctl.go
104
105release: $(RELEASE_BINS)
106
107build: dependencies
108 GOPATH=$(GOPATH) \
109 go build $(LDFLAGS) \
110 cmd/voltctl/voltctl.go
111
112install: dependencies
113 GOPATH=$(GOPATH) GOBIN=$(GOPATH)/bin go install $(LDFLAGS) \
114 cmd/voltctl/voltctl.go
115
116run: dependencies
Scott Baker2b0ad652019-08-21 14:57:07 -0700117 GOPATH=$(GOPATH) go run $(LDFLAGS) github.com/opencord/voltctl/cmd/voltctl $(CMD)
Zack Williamse940c7a2019-08-21 14:25:39 -0700118
119lint: dependencies
Scott Baker2b0ad652019-08-21 14:57:07 -0700120 GOPATH=$(GOPATH) find $(GOPATH)/src/github.com/opencord/voltctl -name "*.go" -not -path '$(GOPATH)/src/github.com/opencord/voltctl/vendor/*' | xargs gofmt -l
121 GOPATH=$(GOPATH) go vet ./...
Zack Williamse940c7a2019-08-21 14:25:39 -0700122 dep check
123
124test: dependencies
Scott Baker2b0ad652019-08-21 14:57:07 -0700125 @mkdir -p ./tests/results
126 @set +e; \
127 GOPATH=$(GOPATH) go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
128 RETURN=$$? ;\
129 go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
130 gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
131 exit $$RETURN
Zack Williamse940c7a2019-08-21 14:25:39 -0700132
133view-coverage:
Scott Baker2b0ad652019-08-21 14:57:07 -0700134 GOPATH=$(GOPATH) go tool cover -html ./tests/results/go-test-coverage.out
Zack Williamse940c7a2019-08-21 14:25:39 -0700135
136clean:
137 rm -rf voltctl voltctl.cp release