blob: 8e34d129fcd5c52d96b80a50a033c56ae2050315 [file] [log] [blame]
Matteo Scandolo4747d292019-08-05 11:50:18 -07001# Copyright 2019-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
15VERSION ?= $(shell cat ./VERSION)
Matteo Scandolo84f7d482019-08-08 19:00:47 -070016DIFF ?= $(git diff --shortstat 2> /dev/null | tail -n1)
17GIT_STATUS ?= $(shell [[ $DIFF != "" ]] && echo "Dirty" || echo "Clean")
Matteo Scandolo4747d292019-08-05 11:50:18 -070018
19## Docker related
20DOCKER_TAG ?= ${VERSION}
21DOCKER_REPOSITORY ?= voltha/
22DOCKER_REGISTRY ?= ""
Matteo Scandolo4747d292019-08-05 11:50:18 -070023
24# Public targets
25
26all: help
27
Matteo Scandolod54283a2019-08-13 16:22:31 -070028protos: api/bbsim/bbsim.pb.go # @HELP Build proto files
Matteo Scandolo4747d292019-08-05 11:50:18 -070029
30build: protos # @HELP Build the binary
Matteo Scandoloc559ef12019-08-20 13:24:21 -070031 GO111MODULE=on go build -i -v -mod vendor \
Matteo Scandolo84f7d482019-08-08 19:00:47 -070032 -ldflags "-X main.buildTime=$(shell date +ā€%Y/%m/%d-%H:%M:%Sā€) \
33 -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
34 -X main.gitStatus=${GIT_STATUS} \
35 -X main.version=${VERSION}" \
36 -o ./cmd/bbsim ./internal/bbsim
Matteo Scandolo4747d292019-08-05 11:50:18 -070037
38test: protos # @HELP Execute unit tests
39 GO111MODULE=on go test ./internal/bbsim
40
Matteo Scandolo84f7d482019-08-08 19:00:47 -070041docker-build: # @HELP Build a docker container
42 docker build --build-arg GIT_STATUS=${GIT_STATUS} -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} -f build/package/Dockerfile .
Matteo Scandolo4747d292019-08-05 11:50:18 -070043
Matteo Scandolo84f7d482019-08-08 19:00:47 -070044docker-push: # @HELP Push a docker container to a registry
Matteo Scandolo4747d292019-08-05 11:50:18 -070045 docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG}
46
47help: # @HELP Print the command options
48 @echo
49 @echo "\033[0;31m BroadBand Simulator (BBSim) \033[0m"
50 @echo
51 @echo Emulates the control plane of an openolt compatible device
52 @echo Useful for development and scale testing
53 @echo
54 @grep -E '^.*: .* *# *@HELP' $(MAKEFILE_LIST) \
55 | sort \
56 | awk ' \
57 BEGIN {FS = ": .* *# *@HELP"}; \
58 {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}; \
59 '
60
61
62# Internals
63
Matteo Scandolo84f7d482019-08-08 19:00:47 -070064api/openolt/openolt.pb.go: api/openolt/openolt.proto
65 @protoc -I . \
66 -I${GOPATH}/src \
67 -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
68 --go_out=plugins=grpc:./ \
69 $<
70
71api/bbsim/bbsim.pb.go: api/bbsim/bbsim.proto
Matteo Scandolo4747d292019-08-05 11:50:18 -070072 @protoc -I . \
73 -I${GOPATH}/src \
74 -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
75 --go_out=plugins=grpc:./ \
76 $<
77