blob: 319710fc7dd64843027fa1a297feee0bdf6eb2ba [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}
Matteo Scandolo5daa2ab2019-10-08 08:27:18 -070021DOCKER_REPOSITORY ?= ""
Matteo Scandolo4747d292019-08-05 11:50:18 -070022DOCKER_REGISTRY ?= ""
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070023DOCKER_RUN_ARGS ?= ""
Matteo Scandolo4747d292019-08-05 11:50:18 -070024
25# Public targets
26
27all: help
28
Matteo Scandolod54283a2019-08-13 16:22:31 -070029protos: api/bbsim/bbsim.pb.go # @HELP Build proto files
Matteo Scandolo4747d292019-08-05 11:50:18 -070030
Matteo Scandolo11006992019-08-28 11:29:46 -070031dep: # @HELP Download the dependencies to the vendor folder
32 GO111MODULE=on go mod vendor
33
Matteo Scandolo38305492019-10-11 11:36:00 -070034build: fmt dep protos build-bbsim build-bbsimctl# @HELP Build the binary
Matteo Scandolo4747d292019-08-05 11:50:18 -070035
Matteo Scandolo38305492019-10-11 11:36:00 -070036test: fmt dep protos # @HELP Execute unit tests
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070037 GO111MODULE=on go test -v -mod vendor ./... -covermode count -coverprofile ./tests/results/go-test-coverage.out 2>&1 | tee ./tests/results/go-test-results.out
Matteo Scandolo11006992019-08-28 11:29:46 -070038 go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml
39 gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml
Matteo Scandolo4747d292019-08-05 11:50:18 -070040
Matteo Scandolo38305492019-10-11 11:36:00 -070041fmt:
42 go fmt ./...
43
Matteo Scandolo84f7d482019-08-08 19:00:47 -070044docker-build: # @HELP Build a docker container
Matteo Scandolo82c16d02019-09-24 09:34:32 -070045 docker build -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} -f build/package/Dockerfile .
Matteo Scandolo4747d292019-08-05 11:50:18 -070046
Matteo Scandolo84f7d482019-08-08 19:00:47 -070047docker-push: # @HELP Push a docker container to a registry
Matteo Scandolo4747d292019-08-05 11:50:18 -070048 docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG}
49
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070050docker-run: # @HELP Run the container locally (intended for development purposes: DOCKER_RUN_ARGS="-pon 2 -onu 2" make docker-run)
51 docker run -p 50070:50070 -p 50060:50060 --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS}
52
Matteo Scandolo4747d292019-08-05 11:50:18 -070053help: # @HELP Print the command options
54 @echo
55 @echo "\033[0;31m BroadBand Simulator (BBSim) \033[0m"
56 @echo
57 @echo Emulates the control plane of an openolt compatible device
58 @echo Useful for development and scale testing
59 @echo
60 @grep -E '^.*: .* *# *@HELP' $(MAKEFILE_LIST) \
61 | sort \
62 | awk ' \
63 BEGIN {FS = ": .* *# *@HELP"}; \
64 {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}; \
65 '
66
67
68# Internals
Matteo Scandolo8df63df2019-09-12 10:34:32 -070069build-bbsim:
70 GO111MODULE=on go build -i -v -mod vendor \
71 -ldflags "-X main.buildTime=$(shell date +ā€%Y/%m/%d-%H:%M:%Sā€) \
72 -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
73 -X main.gitStatus=${GIT_STATUS} \
74 -X main.version=${VERSION}" \
Matteo Scandolo82c16d02019-09-24 09:34:32 -070075 ./cmd/bbsim
Matteo Scandolo8df63df2019-09-12 10:34:32 -070076
77build-bbsimctl:
78 GO111MODULE=on go build -i -v -mod vendor \
Matteo Scandolo82c16d02019-09-24 09:34:32 -070079 -ldflags "-X github.com/opencord/bbsim/internal/bbsimctl/config.BuildTime=$(shell date +ā€%Y/%m/%d-%H:%M:%Sā€) \
80 -X github.com/opencord/bbsim/internal/bbsimctl/config.CommitHash=$(shell git log --pretty=format:%H -n 1) \
81 -X github.com/opencord/bbsim/internal/bbsimctl/config.GitStatus=${GIT_STATUS} \
82 -X github.com/opencord/bbsim/internal/bbsimctl/config.Version=${VERSION}" \
83 ./cmd/bbsimctl
Matteo Scandolo4747d292019-08-05 11:50:18 -070084
Matteo Scandolo84f7d482019-08-08 19:00:47 -070085api/openolt/openolt.pb.go: api/openolt/openolt.proto
86 @protoc -I . \
87 -I${GOPATH}/src \
88 -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
89 --go_out=plugins=grpc:./ \
90 $<
91
92api/bbsim/bbsim.pb.go: api/bbsim/bbsim.proto
Matteo Scandolo4747d292019-08-05 11:50:18 -070093 @protoc -I . \
94 -I${GOPATH}/src \
95 -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
96 --go_out=plugins=grpc:./ \
97 $<
98