blob: 515273bbb6b4b268e7a87159cbf338205a2cdbbf [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001help:
David Bainbridgec4029aa2019-09-26 18:56:39 +00002 @echo "release - build binaries using cross compliing for the support architectures"
3 @echo "build - build the binary as a local executable"
4 @echo "install - build and install the binary into \$$GOPATH/bin"
5 @echo "run - runs voltctl using the command specified as \$$CMD"
David Bainbridge86971522019-09-26 22:09:39 +00006 @echo "lint - run static code analysis"
7 @echo "test - run unity tests"
David Bainbridgec4029aa2019-09-26 18:56:39 +00008 @echo "clean - remove temporary and generated files"
Zack Williamse940c7a2019-08-21 14:25:39 -07009
10internal/pkg/commands/voltha_v1_pb.go: assets/protosets/voltha_v1.pb
Scott Baker2b0ad652019-08-21 14:57:07 -070011 @echo "/*" > $@
12 @echo " * Copyright 2019-present Open Networking Foundation" >> $@
13 @echo " *" >> $@
14 @echo " * Licensed under the Apache License, Version 2.0 (the "License");" >> $@
15 @echo " * you may not use this file except in compliance with the License." >> $@
16 @echo " * You may obtain a copy of the License at" >> $@
17 @echo " *" >> $@
18 @echo " * http://www.apache.org/licenses/LICENSE-2.0" >> $@
19 @echo " *" >> $@
20 @echo " * Unless required by applicable law or agreed to in writing, software" >> $@
21 @echo " * distributed under the License is distributed on an "AS IS" BASIS," >> $@
22 @echo " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." >> $@
23 @echo " * See the License for the specific language governing permissions and" >> $@
24 @echo " * limitations under the License." >> $@
25 @echo " */" >> $@
26 @echo "package commands" >> $@
Zack Williamse940c7a2019-08-21 14:25:39 -070027 @echo "" >> $@
28 @echo "var V1Descriptor = []byte{" >> $@
29 hexdump -ve '1/1 "0x%02x,"' assets/protosets/voltha_v1.pb | fold -w 60 -s >> $@
30 @echo "}" >> $@
31 @go fmt $@
32
33internal/pkg/commands/voltha_v2_pb.go: assets/protosets/voltha_v2.pb
Scott Baker2b0ad652019-08-21 14:57:07 -070034 @echo "/*" > $@
35 @echo " * Copyright 2019-present Open Networking Foundation" >> $@
36 @echo " *" >> $@
37 @echo " * Licensed under the Apache License, Version 2.0 (the "License");" >> $@
38 @echo " * you may not use this file except in compliance with the License." >> $@
39 @echo " * You may obtain a copy of the License at" >> $@
40 @echo " *" >> $@
41 @echo " * http://www.apache.org/licenses/LICENSE-2.0" >> $@
42 @echo " *" >> $@
43 @echo " * Unless required by applicable law or agreed to in writing, software" >> $@
44 @echo " * distributed under the License is distributed on an "AS IS" BASIS," >> $@
45 @echo " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." >> $@
46 @echo " * See the License for the specific language governing permissions and" >> $@
47 @echo " * limitations under the License." >> $@
48 @echo " */" >> $@
49 @echo "package commands" >> $@
Zack Williamse940c7a2019-08-21 14:25:39 -070050 @echo "" >> $@
51 @echo "var V2Descriptor = []byte{" >> $@
52 hexdump -ve '1/1 "0x%02x,"' assets/protosets/voltha_v2.pb | fold -w 60 -s >> $@
53 @echo "}" >> $@
54 @go fmt $@
55
56encode-protosets: internal/pkg/commands/voltha_v1_pb.go internal/pkg/commands/voltha_v2_pb.go
57
David Bainbridge86971522019-09-26 22:09:39 +000058VERSION=$(shell cat ./VERSION)
Zack Williamse940c7a2019-08-21 14:25:39 -070059GITCOMMIT=$(shell git rev-parse HEAD)
60ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
61GITDIRTY=false
62else
63GITDIRTY=true
64endif
65GOVERSION=$(shell go version 2>&1 | sed -E 's/.*(go[0-9]+\.[0-9]+\.[0-9]+).*/\1/g')
66HOST_OS=$(shell uname -s | tr A-Z a-z)
67ifeq ($(shell uname -m),x86_64)
68 HOST_ARCH ?= amd64
69else
70 HOST_ARCH ?= $(shell uname -m)
71endif
72BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
73
74LDFLAGS=-ldflags \
Scott Baker2b0ad652019-08-21 14:57:07 -070075 '-X "github.com/opencord/voltctl/internal/pkg/cli/version.Version=$(VERSION)" \
76 -X "github.com/opencord/voltctl/internal/pkg/cli/version.VcsRef=$(GITCOMMIT)" \
77 -X "github.com/opencord/voltctl/internal/pkg/cli/version.VcsDirty=$(GITDIRTY)" \
78 -X "github.com/opencord/voltctl/internal/pkg/cli/version.GoVersion=$(GOVERSION)" \
79 -X "github.com/opencord/voltctl/internal/pkg/cli/version.Os=$(HOST_OS)" \
80 -X "github.com/opencord/voltctl/internal/pkg/cli/version.Arch=$(HOST_ARCH)" \
81 -X "github.com/opencord/voltctl/internal/pkg/cli/version.BuildTime=$(BUILDTIME)"'
Zack Williamse940c7a2019-08-21 14:25:39 -070082
83# Release related items
84# Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH
85# Inspired by: https://github.com/kubernetes/minikube/releases
86RELEASE_DIR ?= release
87RELEASE_NAME ?= voltctl
88RELEASE_OS_ARCH ?= linux-amd64 windows-amd64 darwin-amd64
89RELEASE_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_NAME)-$(subst -dev,_dev,$(VERSION))-$(rel))
90
91# Functions to extract the OS/ARCH
92rel_ver = $(word 2, $(subst -, ,$(notdir $@)))
93rel_os = $(word 3, $(subst -, ,$(notdir $@)))
94rel_arch = $(word 4, $(subst -, ,$(notdir $@)))
95
David Bainbridge86971522019-09-26 22:09:39 +000096# Default is GO111MODULE=auto, which will refuse to use go mod if running
97# go less than 1.13.0 and repo is checked out in gopath. For now, force
98# module usage.
99export GO111MODULE=on
Zack Williamse940c7a2019-08-21 14:25:39 -0700100
David Bainbridge86971522019-09-26 22:09:39 +0000101$(RELEASE_BINS):
Zack Williamse940c7a2019-08-21 14:25:39 -0700102 mkdir -p $(RELEASE_DIR)
David Bainbridge86971522019-09-26 22:09:39 +0000103 GOOS=$(rel_os) GOARCH=$(rel_arch) \
104 go build -mod=vendor -v $(LDFLAGS) -o "$@" cmd/voltctl/voltctl.go
Zack Williamse940c7a2019-08-21 14:25:39 -0700105
106release: $(RELEASE_BINS)
107
David Bainbridge86971522019-09-26 22:09:39 +0000108build:
109 go build -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go
Zack Williamse940c7a2019-08-21 14:25:39 -0700110
David Bainbridge86971522019-09-26 22:09:39 +0000111install:
112 go install -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go
Zack Williamse940c7a2019-08-21 14:25:39 -0700113
David Bainbridge86971522019-09-26 22:09:39 +0000114run:
115 go run -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go $(CMD)
Zack Williamse940c7a2019-08-21 14:25:39 -0700116
David Bainbridge86971522019-09-26 22:09:39 +0000117lint-style:
118ifeq (,$(shell which gofmt))
119 go get -u github.com/golang/go/src/cmd/gofmt
120endif
121 @echo -n "Running style check ... "
122 @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\
123 if [ ! -z "$$gofmt_out" ]; then \
124 echo "$$gofmt_out" ;\
125 echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\
126 exit 1 ;\
127 fi
128 @echo "OK"
Zack Williamse940c7a2019-08-21 14:25:39 -0700129
David Bainbridge86971522019-09-26 22:09:39 +0000130lint-sanity:
131 @echo -n "Running sanity check ... "
132 @go vet -mod=vendor ./...
133 @echo "OK"
134
135lint: lint-style lint-sanity
136
137test:
Scott Baker2b0ad652019-08-21 14:57:07 -0700138 @mkdir -p ./tests/results
139 @set +e; \
David Bainbridge86971522019-09-26 22:09:39 +0000140 go test -mod=vendor -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
Scott Baker2b0ad652019-08-21 14:57:07 -0700141 RETURN=$$? ;\
142 go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
143 gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
144 exit $$RETURN
Zack Williamse940c7a2019-08-21 14:25:39 -0700145
146view-coverage:
David Bainbridge86971522019-09-26 22:09:39 +0000147 go tool cover -html ./tests/results/go-test-coverage.out
Zack Williamse940c7a2019-08-21 14:25:39 -0700148
149clean:
150 rm -rf voltctl voltctl.cp release