Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1 | ifeq ($(GOPATH),) |
| 2 | $(error "***** Please set your GOPATH environment variable") |
| 3 | endif |
| 4 | |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 5 | ifneq ($(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 Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 7 | endif |
| 8 | |
| 9 | help: |
David Bainbridge | c4029aa | 2019-09-26 18:56:39 +0000 | [diff] [blame^] | 10 | @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 Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 18 | |
| 19 | internal/pkg/commands/voltha_v1_pb.go: assets/protosets/voltha_v1.pb |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 20 | @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 Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 36 | @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 | |
| 42 | internal/pkg/commands/voltha_v2_pb.go: assets/protosets/voltha_v2.pb |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 43 | @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 Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 59 | @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 | |
| 65 | encode-protosets: internal/pkg/commands/voltha_v1_pb.go internal/pkg/commands/voltha_v2_pb.go |
| 66 | |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 67 | VERSION=$(shell cat $(GOPATH)/src/github.com/opencord/voltctl/VERSION) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 68 | GITCOMMIT=$(shell git rev-parse HEAD) |
| 69 | ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 70 | GITDIRTY=false |
| 71 | else |
| 72 | GITDIRTY=true |
| 73 | endif |
| 74 | GOVERSION=$(shell go version 2>&1 | sed -E 's/.*(go[0-9]+\.[0-9]+\.[0-9]+).*/\1/g') |
| 75 | HOST_OS=$(shell uname -s | tr A-Z a-z) |
| 76 | ifeq ($(shell uname -m),x86_64) |
| 77 | HOST_ARCH ?= amd64 |
| 78 | else |
| 79 | HOST_ARCH ?= $(shell uname -m) |
| 80 | endif |
| 81 | BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 82 | |
| 83 | LDFLAGS=-ldflags \ |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 84 | '-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 Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 91 | |
| 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 |
| 95 | RELEASE_DIR ?= release |
| 96 | RELEASE_NAME ?= voltctl |
| 97 | RELEASE_OS_ARCH ?= linux-amd64 windows-amd64 darwin-amd64 |
| 98 | RELEASE_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_NAME)-$(subst -dev,_dev,$(VERSION))-$(rel)) |
| 99 | |
| 100 | # Functions to extract the OS/ARCH |
| 101 | rel_ver = $(word 2, $(subst -, ,$(notdir $@))) |
| 102 | rel_os = $(word 3, $(subst -, ,$(notdir $@))) |
| 103 | rel_arch = $(word 4, $(subst -, ,$(notdir $@))) |
| 104 | |
| 105 | dependencies: |
| 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 | |
| 113 | release: $(RELEASE_BINS) |
| 114 | |
| 115 | build: dependencies |
| 116 | GOPATH=$(GOPATH) \ |
| 117 | go build $(LDFLAGS) \ |
| 118 | cmd/voltctl/voltctl.go |
| 119 | |
| 120 | install: dependencies |
| 121 | GOPATH=$(GOPATH) GOBIN=$(GOPATH)/bin go install $(LDFLAGS) \ |
| 122 | cmd/voltctl/voltctl.go |
| 123 | |
| 124 | run: dependencies |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 125 | GOPATH=$(GOPATH) go run $(LDFLAGS) github.com/opencord/voltctl/cmd/voltctl $(CMD) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 126 | |
| 127 | lint: dependencies |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 128 | 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 Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 130 | dep check |
| 131 | |
| 132 | test: dependencies |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 133 | @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 Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 140 | |
| 141 | view-coverage: |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 142 | GOPATH=$(GOPATH) go tool cover -html ./tests/results/go-test-coverage.out |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 143 | |
| 144 | clean: |
| 145 | rm -rf voltctl voltctl.cp release |