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 | |
| 5 | ifneq ($(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") |
| 7 | endif |
| 8 | |
| 9 | help: |
| 10 | |
| 11 | internal/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 | |
| 19 | internal/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 | |
| 27 | encode-protosets: internal/pkg/commands/voltha_v1_pb.go internal/pkg/commands/voltha_v2_pb.go |
| 28 | |
| 29 | VERSION=$(shell cat $(GOPATH)/src/github.com/ciena/voltctl/VERSION) |
| 30 | GITCOMMIT=$(shell git rev-parse HEAD) |
| 31 | ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 32 | GITDIRTY=false |
| 33 | else |
| 34 | GITDIRTY=true |
| 35 | endif |
| 36 | GOVERSION=$(shell go version 2>&1 | sed -E 's/.*(go[0-9]+\.[0-9]+\.[0-9]+).*/\1/g') |
| 37 | HOST_OS=$(shell uname -s | tr A-Z a-z) |
| 38 | ifeq ($(shell uname -m),x86_64) |
| 39 | HOST_ARCH ?= amd64 |
| 40 | else |
| 41 | HOST_ARCH ?= $(shell uname -m) |
| 42 | endif |
| 43 | BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 44 | |
| 45 | LDFLAGS=-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 |
| 57 | RELEASE_DIR ?= release |
| 58 | RELEASE_NAME ?= voltctl |
| 59 | RELEASE_OS_ARCH ?= linux-amd64 windows-amd64 darwin-amd64 |
| 60 | RELEASE_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_NAME)-$(subst -dev,_dev,$(VERSION))-$(rel)) |
| 61 | |
| 62 | # Functions to extract the OS/ARCH |
| 63 | rel_ver = $(word 2, $(subst -, ,$(notdir $@))) |
| 64 | rel_os = $(word 3, $(subst -, ,$(notdir $@))) |
| 65 | rel_arch = $(word 4, $(subst -, ,$(notdir $@))) |
| 66 | |
| 67 | dependencies: |
| 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 | |
| 75 | release: $(RELEASE_BINS) |
| 76 | |
| 77 | build: dependencies |
| 78 | GOPATH=$(GOPATH) \ |
| 79 | go build $(LDFLAGS) \ |
| 80 | cmd/voltctl/voltctl.go |
| 81 | |
| 82 | install: dependencies |
| 83 | GOPATH=$(GOPATH) GOBIN=$(GOPATH)/bin go install $(LDFLAGS) \ |
| 84 | cmd/voltctl/voltctl.go |
| 85 | |
| 86 | run: dependencies |
| 87 | GOPATH=$(GOPATH) go run $(LDFLAGS) github.com/ciena/voltctl/cmd/voltctl $(CMD) |
| 88 | |
| 89 | lint: 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 | |
| 94 | test: dependencies |
| 95 | GOPATH=$(GOPATH) go test $(TEST_ARGS) -cover -coverprofile=voltctl.cp github.com/ciena/voltctl/... |
| 96 | |
| 97 | view-coverage: |
| 98 | GOPATH=$(GOPATH) go tool cover -html voltctl.cp |
| 99 | |
| 100 | clean: |
| 101 | rm -rf voltctl voltctl.cp release |