blob: 2f06b03e60ee95b98d7195e49afe278cfbc0f303 [file] [log] [blame]
Zack Williams86f87202018-10-05 10:36:32 -07001# Copyright 2018-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15BBSIM_DEPS = $(wildcard ./*.go)
Kailash3150a012019-07-02 12:27:44 -070016DOCKER_TAG ?= "latest"
Matteo Scandolo88e91892018-11-06 16:29:19 -080017REGISTRY ?= ""
Zack Williams86f87202018-10-05 10:36:32 -070018
Kailashd88258b2019-07-01 21:27:48 -070019## Docker related
20DOCKER_REGISTRY ?=
21DOCKER_REPOSITORY ?=
22DOCKER_BUILD_ARGS ?=
23DOCKER_TAG ?= ${VERSION}
24DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${SYNCHRONIZER_NAME}:${DOCKER_TAG}
25
26## Docker labels. Only set ref and commit date if committed
27DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
28DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
29DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
30DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
31
Zack Williams86f87202018-10-05 10:36:32 -070032.PHONY: dep test clean docker
33
Shad Ansari573dfb82018-11-12 21:51:00 -080034prereq:
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020035 go get -v google.golang.org/grpc
Shad Ansari573dfb82018-11-12 21:51:00 -080036 go get -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
37 go get -v github.com/golang/protobuf/protoc-gen-go
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020038 go get -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
Shad Ansari573dfb82018-11-12 21:51:00 -080039 go get -v github.com/google/gopacket
Shad Ansari3f525132019-06-23 06:16:28 +000040 go get -u -v github.com/opencord/omci-sim
Shad Ansari573dfb82018-11-12 21:51:00 -080041
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020042bbsim: prereq protos/openolt.pb.go bbsimapi dep
Zack Williams86f87202018-10-05 10:36:32 -070043 go build -i -v -o $@
44
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020045dep: protos/openolt.pb.go bbsimapi
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090046 go get -v -d ./...
Zack Williams86f87202018-10-05 10:36:32 -070047
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090048protos/openolt.pb.go: openolt.proto
Zack Williams86f87202018-10-05 10:36:32 -070049 @protoc -I . \
50 -I${GOPATH}/src \
51 -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090052 --go_out=plugins=grpc:protos/ \
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090053 $<
Zack Williams86f87202018-10-05 10:36:32 -070054
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020055bbsimapi: api/bbsim.proto
56 @protoc -I ./api \
57 -I${GOPATH}/src \
58 -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
59 -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway \
60 --go_out=plugins=grpc:api/ \
61 --grpc-gateway_out=logtostderr=true,allow_delete_body=true:api/ \
Shad Ansari3f525132019-06-23 06:16:28 +000062 api/bbsim.proto
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020063
64swagger: ## Generate swagger documentation for BBsim API
65 @protoc -I ./api \
66 -I${GOPATH}/src \
67 -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
68 -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway \
69 --swagger_out=logtostderr=true,allow_delete_body=true:api/swagger/ \
70 bbsim.proto
71
Zack Williams86f87202018-10-05 10:36:32 -070072test:
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090073 go test -v ./...
74 go test -v ./... -cover
75
76fmt:
77 go fmt ./...
78
79vet:
80 go vet ./...
81
82lint:
83 gometalinter --vendor --exclude ../../golang.org --skip protos --sort path --sort line ./...
Zack Williams86f87202018-10-05 10:36:32 -070084
85clean:
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020086 @rm -vf bbsim \
87 protos/openolt.pb.go \
88 api/bbsim.pb.go \
89 api/bbsim.pb.gw.go \
90 api/swagger/*.json
Zack Williams86f87202018-10-05 10:36:32 -070091
Kailashd88258b2019-07-01 21:27:48 -070092docker-build:
Matteo Scandolo88e91892018-11-06 16:29:19 -080093 docker build -t ${REGISTRY}voltha/voltha-bbsim:${DOCKERTAG} .
Kailash3150a012019-07-02 12:27:44 -070094 docker save voltha/voltha-bbsim:${DOCKER_TAG} -o voltha-bbsim_${DOCKERTAG}.tgz
Kailashd88258b2019-07-01 21:27:48 -070095
96docker-push:
97 docker push ${DOCKER_IMAGENAME}