blob: cbceb9e2dfc9b302f8992ea4c801a8e9f24ad4a4 [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 Scandolo01d41ce2019-10-28 15:42:47 -070034_build: dep protos fmt build-bbsim build-bbsimctl build-bbr
35
36build: # @HELP Build the binaries (it runs inside a docker container and output the built code on your local file system)
37 docker build -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim-builder:${DOCKER_TAG} -f build/ci/Dockerfile.builder .
38 docker run --rm -v $(shell pwd):/bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim-builder:${DOCKER_TAG} /bin/sh -c "cd /bbsim; make build"
Matteo Scandolo4747d292019-08-05 11:50:18 -070039
William Kurkianc7966c72019-10-16 14:00:00 -040040test: dep protos fmt # @HELP Execute unit tests
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070041 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 -070042 go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml
43 gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml
Matteo Scandolo4747d292019-08-05 11:50:18 -070044
Matteo Scandolo38305492019-10-11 11:36:00 -070045fmt:
46 go fmt ./...
47
Matteo Scandolo01d41ce2019-10-28 15:42:47 -070048docker-build: # @HELP Build the BBSim docker container (contains BBSimCtl too)
Matteo Scandolo82c16d02019-09-24 09:34:32 -070049 docker build -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} -f build/package/Dockerfile .
Matteo Scandolo4747d292019-08-05 11:50:18 -070050
Matteo Scandolo01d41ce2019-10-28 15:42:47 -070051docker-push: # @HELP Push the docker container to a registry
Matteo Scandolo4747d292019-08-05 11:50:18 -070052 docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG}
53
Matteo Scandoloe383d5d2019-10-25 14:47:27 -070054docker-run: # @HELP Runs the container locally (available options: DOCKER_RUN_ARGS="-pon 2 -onu 2" make docker-run)
Matteo Scandoloecbd6a12019-10-21 10:51:03 -070055 docker run -d -p 50070:50070 -p 50060:50060 --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS}
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070056
Matteo Scandoloe383d5d2019-10-25 14:47:27 -070057docker-run-dev: # @HELP Runs the container locally (intended for development purposes, not in detached mode)
58 docker run -p 50070:50070 -p 50060:50060 --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS}
59
Matteo Scandolo40e067f2019-10-16 16:59:41 -070060.PHONY: docs
Matteo Scandolo9f619492019-10-25 13:11:58 -070061docs: # @HELP Generate docs and opens them in the browser
62 pushd docs; make doc_venv; make html; popd
63 open docs/build/html/index.html
Matteo Scandolo40e067f2019-10-16 16:59:41 -070064
Matteo Scandolo8dea3992019-10-22 10:54:25 -070065# Release related items
66# Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH
67# Inspired by: https://github.com/kubernetes/minikube/releases
68RELEASE_DIR ?= release
69RELEASE_OS_ARCH ?= linux-amd64 linux-arm64 windows-amd64 darwin-amd64
70
71RELEASE_BBR_NAME ?= bbr
72RELEASE_BBR_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_BBR_NAME)-$(rel))
73RELEASE_BBSIM_NAME ?= bbsimctl
74RELEASE_BBSIM_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_BBSIM_NAME)-$(rel))
75
76$(RELEASE_BBR_BINS):
77 export GOOS=$(rel_os) ;\
78 export GOARCH=$(rel_arch) ;\
79 GO111MODULE=on go build -i -v -mod vendor \
80 -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
81 -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
82 -X main.gitStatus=${GIT_STATUS} \
83 -X main.version=${VERSION}" \
84 -o "$@" ./cmd/bbr
85
86$(RELEASE_BBSIM_BINS):
87 export GOOS=$(rel_os) ;\
88 export GOARCH=$(rel_arch) ;\
89 GO111MODULE=on go build -i -v -mod vendor \
90 -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
91 -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
92 -X main.gitStatus=${GIT_STATUS} \
93 -X main.version=${VERSION}" \
94 -o "$@" ./cmd/bbsim
95
96.PHONY: release $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS)
Matteo Scandolo01d41ce2019-10-28 15:42:47 -070097release: dep protos $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS) # @HELP Creates release ready bynaries for BBSimctl and BBR artifacts
Matteo Scandolo8dea3992019-10-22 10:54:25 -070098
Matteo Scandolo4747d292019-08-05 11:50:18 -070099help: # @HELP Print the command options
100 @echo
101 @echo "\033[0;31m BroadBand Simulator (BBSim) \033[0m"
102 @echo
103 @echo Emulates the control plane of an openolt compatible device
104 @echo Useful for development and scale testing
105 @echo
106 @grep -E '^.*: .* *# *@HELP' $(MAKEFILE_LIST) \
107 | sort \
108 | awk ' \
109 BEGIN {FS = ": .* *# *@HELP"}; \
110 {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}; \
111 '
112
113
114# Internals
Matteo Scandolo8dea3992019-10-22 10:54:25 -0700115
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700116build-bbr:
117 GO111MODULE=on go build -i -v -mod vendor \
118 -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
119 -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
120 -X main.gitStatus=${GIT_STATUS} \
121 -X main.version=${VERSION}" \
122 ./cmd/bbr
123
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700124build-bbsim:
125 GO111MODULE=on go build -i -v -mod vendor \
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700126 -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700127 -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
128 -X main.gitStatus=${GIT_STATUS} \
129 -X main.version=${VERSION}" \
Matteo Scandolo82c16d02019-09-24 09:34:32 -0700130 ./cmd/bbsim
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700131
132build-bbsimctl:
133 GO111MODULE=on go build -i -v -mod vendor \
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700134 -ldflags "-w -X github.com/opencord/bbsim/internal/bbsimctl/config.BuildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
Matteo Scandolo82c16d02019-09-24 09:34:32 -0700135 -X github.com/opencord/bbsim/internal/bbsimctl/config.CommitHash=$(shell git log --pretty=format:%H -n 1) \
136 -X github.com/opencord/bbsim/internal/bbsimctl/config.GitStatus=${GIT_STATUS} \
137 -X github.com/opencord/bbsim/internal/bbsimctl/config.Version=${VERSION}" \
138 ./cmd/bbsimctl
Matteo Scandolo4747d292019-08-05 11:50:18 -0700139
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700140api/openolt/openolt.pb.go: api/openolt/openolt.proto
141 @protoc -I . \
142 -I${GOPATH}/src \
143 -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
144 --go_out=plugins=grpc:./ \
145 $<
146
147api/bbsim/bbsim.pb.go: api/bbsim/bbsim.proto
Matteo Scandolo4747d292019-08-05 11:50:18 -0700148 @protoc -I . \
149 -I${GOPATH}/src \
150 -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
151 --go_out=plugins=grpc:./ \
152 $<
153