blob: 542a94f2fe6d0f4b27dd83bb0cdc027a06e886dd [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:
David Bainbridgec4029aa2019-09-26 18:56:39 +000010 @echo "dependencies - update dependencies if a vendor directory does not exist"
11 @echo "release - build binaries using cross compliing for the support architectures"
12 @echo "build - build the binary as a local executable"
13 @echo "install - build and install the binary into \$$GOPATH/bin"
14 @echo "run - runs voltctl using the command specified as \$$CMD"
15 @echo "lint - run static code analysis, requires \$$GOPATH to be set correctly"
16 @echo "test - run unity tests, requires \$$GOPATH to be set correctly"
17 @echo "clean - remove temporary and generated files"
Zack Williamse940c7a2019-08-21 14:25:39 -070018
19internal/pkg/commands/voltha_v1_pb.go: assets/protosets/voltha_v1.pb
Scott Baker2b0ad652019-08-21 14:57:07 -070020 @echo "/*" > $@
21 @echo " * Copyright 2019-present Open Networking Foundation" >> $@
22 @echo " *" >> $@
23 @echo " * Licensed under the Apache License, Version 2.0 (the "License");" >> $@
24 @echo " * you may not use this file except in compliance with the License." >> $@
25 @echo " * You may obtain a copy of the License at" >> $@
26 @echo " *" >> $@
27 @echo " * http://www.apache.org/licenses/LICENSE-2.0" >> $@
28 @echo " *" >> $@
29 @echo " * Unless required by applicable law or agreed to in writing, software" >> $@
30 @echo " * distributed under the License is distributed on an "AS IS" BASIS," >> $@
31 @echo " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." >> $@
32 @echo " * See the License for the specific language governing permissions and" >> $@
33 @echo " * limitations under the License." >> $@
34 @echo " */" >> $@
35 @echo "package commands" >> $@
Zack Williamse940c7a2019-08-21 14:25:39 -070036 @echo "" >> $@
37 @echo "var V1Descriptor = []byte{" >> $@
38 hexdump -ve '1/1 "0x%02x,"' assets/protosets/voltha_v1.pb | fold -w 60 -s >> $@
39 @echo "}" >> $@
40 @go fmt $@
41
42internal/pkg/commands/voltha_v2_pb.go: assets/protosets/voltha_v2.pb
Scott Baker2b0ad652019-08-21 14:57:07 -070043 @echo "/*" > $@
44 @echo " * Copyright 2019-present Open Networking Foundation" >> $@
45 @echo " *" >> $@
46 @echo " * Licensed under the Apache License, Version 2.0 (the "License");" >> $@
47 @echo " * you may not use this file except in compliance with the License." >> $@
48 @echo " * You may obtain a copy of the License at" >> $@
49 @echo " *" >> $@
50 @echo " * http://www.apache.org/licenses/LICENSE-2.0" >> $@
51 @echo " *" >> $@
52 @echo " * Unless required by applicable law or agreed to in writing, software" >> $@
53 @echo " * distributed under the License is distributed on an "AS IS" BASIS," >> $@
54 @echo " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." >> $@
55 @echo " * See the License for the specific language governing permissions and" >> $@
56 @echo " * limitations under the License." >> $@
57 @echo " */" >> $@
58 @echo "package commands" >> $@
Zack Williamse940c7a2019-08-21 14:25:39 -070059 @echo "" >> $@
60 @echo "var V2Descriptor = []byte{" >> $@
61 hexdump -ve '1/1 "0x%02x,"' assets/protosets/voltha_v2.pb | fold -w 60 -s >> $@
62 @echo "}" >> $@
63 @go fmt $@
64
65encode-protosets: internal/pkg/commands/voltha_v1_pb.go internal/pkg/commands/voltha_v2_pb.go
66
Scott Baker2b0ad652019-08-21 14:57:07 -070067VERSION=$(shell cat $(GOPATH)/src/github.com/opencord/voltctl/VERSION)
Zack Williamse940c7a2019-08-21 14:25:39 -070068GITCOMMIT=$(shell git rev-parse HEAD)
69ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
70GITDIRTY=false
71else
72GITDIRTY=true
73endif
74GOVERSION=$(shell go version 2>&1 | sed -E 's/.*(go[0-9]+\.[0-9]+\.[0-9]+).*/\1/g')
75HOST_OS=$(shell uname -s | tr A-Z a-z)
76ifeq ($(shell uname -m),x86_64)
77 HOST_ARCH ?= amd64
78else
79 HOST_ARCH ?= $(shell uname -m)
80endif
81BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
82
83LDFLAGS=-ldflags \
Scott Baker2b0ad652019-08-21 14:57:07 -070084 '-X "github.com/opencord/voltctl/internal/pkg/cli/version.Version=$(VERSION)" \
85 -X "github.com/opencord/voltctl/internal/pkg/cli/version.VcsRef=$(GITCOMMIT)" \
86 -X "github.com/opencord/voltctl/internal/pkg/cli/version.VcsDirty=$(GITDIRTY)" \
87 -X "github.com/opencord/voltctl/internal/pkg/cli/version.GoVersion=$(GOVERSION)" \
88 -X "github.com/opencord/voltctl/internal/pkg/cli/version.Os=$(HOST_OS)" \
89 -X "github.com/opencord/voltctl/internal/pkg/cli/version.Arch=$(HOST_ARCH)" \
90 -X "github.com/opencord/voltctl/internal/pkg/cli/version.BuildTime=$(BUILDTIME)"'
Zack Williamse940c7a2019-08-21 14:25:39 -070091
92# Release related items
93# Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH
94# Inspired by: https://github.com/kubernetes/minikube/releases
95RELEASE_DIR ?= release
96RELEASE_NAME ?= voltctl
97RELEASE_OS_ARCH ?= linux-amd64 windows-amd64 darwin-amd64
98RELEASE_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_NAME)-$(subst -dev,_dev,$(VERSION))-$(rel))
99
100# Functions to extract the OS/ARCH
101rel_ver = $(word 2, $(subst -, ,$(notdir $@)))
102rel_os = $(word 3, $(subst -, ,$(notdir $@)))
103rel_arch = $(word 4, $(subst -, ,$(notdir $@)))
104
105dependencies:
106 [ -d "vendor" ] || dep ensure
107
108$(RELEASE_BINS): dependencies
109 mkdir -p $(RELEASE_DIR)
110 GOPATH=$(GOPATH) GOOS=$(rel_os) GOARCH=$(rel_arch) \
111 go build -v $(LDFLAGS) -o "$@" cmd/voltctl/voltctl.go
112
113release: $(RELEASE_BINS)
114
115build: dependencies
116 GOPATH=$(GOPATH) \
117 go build $(LDFLAGS) \
118 cmd/voltctl/voltctl.go
119
120install: dependencies
121 GOPATH=$(GOPATH) GOBIN=$(GOPATH)/bin go install $(LDFLAGS) \
122 cmd/voltctl/voltctl.go
123
124run: dependencies
Scott Baker2b0ad652019-08-21 14:57:07 -0700125 GOPATH=$(GOPATH) go run $(LDFLAGS) github.com/opencord/voltctl/cmd/voltctl $(CMD)
Zack Williamse940c7a2019-08-21 14:25:39 -0700126
127lint: dependencies
Scott Baker2b0ad652019-08-21 14:57:07 -0700128 GOPATH=$(GOPATH) find $(GOPATH)/src/github.com/opencord/voltctl -name "*.go" -not -path '$(GOPATH)/src/github.com/opencord/voltctl/vendor/*' | xargs gofmt -l
129 GOPATH=$(GOPATH) go vet ./...
Zack Williamse940c7a2019-08-21 14:25:39 -0700130 dep check
131
132test: dependencies
Scott Baker2b0ad652019-08-21 14:57:07 -0700133 @mkdir -p ./tests/results
134 @set +e; \
135 GOPATH=$(GOPATH) go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
136 RETURN=$$? ;\
137 go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
138 gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
139 exit $$RETURN
Zack Williamse940c7a2019-08-21 14:25:39 -0700140
141view-coverage:
Scott Baker2b0ad652019-08-21 14:57:07 -0700142 GOPATH=$(GOPATH) go tool cover -html ./tests/results/go-test-coverage.out
Zack Williamse940c7a2019-08-21 14:25:39 -0700143
144clean:
145 rm -rf voltctl voltctl.cp release