blob: 4f86165252368524f5e6cf9ff7b06b38c625c57c [file] [log] [blame]
Jason Huang5d9ab1a2020-04-15 16:53:49 +08001 # Copyright 2018-present Open Networking Foundation
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002#
Girish Gowdraa707e7c2019-11-07 11:36:13 +05303# 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
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00006#
Girish Gowdraa707e7c2019-11-07 11:36:13 +05307# http://www.apache.org/licenses/LICENSE-2.0
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00008#
Girish Gowdraa707e7c2019-11-07 11:36:13 +05309# 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.
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000014
15########################################################################
16##
17##
18## Config
19##
20##
21TOP_DIR=`pwd`
22OPENOLTDEVICE ?= asfvolt16
23
Burak Gurdageb4ca2e2020-06-15 07:48:26 +000024OPENOLT_PROTO_VER ?= v3.3.9
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000025
Girish Gowdraddf9a162020-01-27 12:56:27 +053026GTEST_VER ?= release-1.8.0
Girish Gowdra489425a2020-02-22 13:07:42 +053027gtest-target = /usr/local/lib/libgtest.a
Girish Gowdraddf9a162020-01-27 12:56:27 +053028
29CMOCK_VER ?= 0207b30
Girish Gowdra489425a2020-02-22 13:07:42 +053030cmock-target = /usr/local/include/cmock/cmock.h
Girish Gowdraddf9a162020-01-27 12:56:27 +053031
32GMOCK_GLOBAL_VER ?= 1.0.2
Girish Gowdra489425a2020-02-22 13:07:42 +053033gmock-global-target = /usr/local/include/gmock-global/gmock-global.h
Girish Gowdraddf9a162020-01-27 12:56:27 +053034
35
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000036# GRPC installation
37GRPC_ADDR = https://github.com/grpc/grpc
38GRPC_DST = /tmp/grpc
Girish Gowdra489425a2020-02-22 13:07:42 +053039GRPC_VER ?= v1.10.x
40grpc-cpp-plugin-bin = /usr/local/bin/grpc_cpp_plugin
Girish Gowdraddf9a162020-01-27 12:56:27 +053041
42# Protobuf installation
Girish Gowdra489425a2020-02-22 13:07:42 +053043PROTOBUF_VER ?= 3.5.0
Girish Gowdraddf9a162020-01-27 12:56:27 +053044PROTOBUF_ADDR = https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOBUF_VER)/protobuf-cpp-$(PROTOBUF_VER).tar.gz
45PROTOBUF_DST = /tmp/protobuf-$(PROTOBUF_VER)
Girish Gowdra489425a2020-02-22 13:07:42 +053046protoc-bin = /usr/local/bin/protoc
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000047
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000048#
49########################################################################
50##
51##
52## Install prerequisites
53##
54##
55
Girish Gowdra489425a2020-02-22 13:07:42 +053056CXX = g++
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000057CXXFLAGS += -g -O2
Girish Gowdra489425a2020-02-22 13:07:42 +053058CXXFLAGS += `pkg-config --cflags-only-I grpc++`
59CPPFLAGS += `pkg-config --cflags protobuf grpc`
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000060CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix
61CXXFLAGS += -DTEST_MODE -DENABLE_LOG
Girish Gowdra489425a2020-02-22 13:07:42 +053062LDFLAGS += -lpthread -lm `pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000063CXXFLAGSDEVICE = -I../device -I../device/$(OPENOLTDEVICE) -I../device/generic
64
65export CXX CXXFLAGS OPENOLT_PROTO_VER
66
Jason Huangc6362792020-03-04 16:33:19 +080067BAL_API_VER ?= bal-api-3.4.3.3
Girish Gowdraddf9a162020-01-27 12:56:27 +053068BAL_API_DIR=$(BAL_API_VER)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000069BALLIBNAME=bcm_host_api_stubs
70BALLIBDIR=$(BAL_API_DIR)/stubs
71BAL_INC = -I$(BAL_API_DIR)/include \
72 -I$(BAL_API_DIR)/include/object_model
Girish Gowdra489425a2020-02-22 13:07:42 +053073CXXFLAGS += $(BAL_INC)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000074
75
Girish Gowdraddf9a162020-01-27 12:56:27 +053076prereqs-system:
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000077 sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev unzip docker.io
78 sudo apt-get install -y build-essential autoconf libssl-dev gawk debhelper dh-systemd init-system-helpers curl cmake ccache g++-4.9
79
Girish Gowdraddf9a162020-01-27 12:56:27 +053080prereqs-local: $(protoc-bin) $(grpc-cpp-plugin-bin) prereqs-test-lib
81
82$(protoc-bin):
83 # Install protobuf
84 rm -rf $(PROTOBUF_DST)
85 cd /tmp && wget $(PROTOBUF_ADDR)
86 cd /tmp && tar -zxvf protobuf-cpp-$(PROTOBUF_VER).tar.gz
87 cd $(PROTOBUF_DST) && ./autogen.sh
Girish Gowdra489425a2020-02-22 13:07:42 +053088 cd $(PROTOBUF_DST) && ./configure
Girish Gowdraddf9a162020-01-27 12:56:27 +053089 make -C $(PROTOBUF_DST)
Girish Gowdra489425a2020-02-22 13:07:42 +053090 sudo make -C $(PROTOBUF_DST) install
Girish Gowdraddf9a162020-01-27 12:56:27 +053091
92$(grpc-cpp-plugin-bin):
93 # Install GRPC, protoc
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000094 rm -rf $(GRPC_DST)
Girish Gowdraddf9a162020-01-27 12:56:27 +053095 cd /tmp && git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000096 cd $(GRPC_DST) && git submodule update --init
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000097 make -C $(GRPC_DST)
Girish Gowdra489425a2020-02-22 13:07:42 +053098 sudo make -C $(GRPC_DST) install
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000099
Girish Gowdraddf9a162020-01-27 12:56:27 +0530100prereqs-test-lib: $(gtest-target) $(cmock-target) $(gmock-global-target)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000101
Girish Gowdraddf9a162020-01-27 12:56:27 +0530102$(gtest-target):
103 # Install gtest
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000104 rm -rf /tmp/googletest && cd /tmp && git clone https://github.com/google/googletest.git
Girish Gowdraddf9a162020-01-27 12:56:27 +0530105 cd /tmp/googletest && git checkout $(GTEST_VER)
Girish Gowdra489425a2020-02-22 13:07:42 +0530106 cd /tmp/googletest && cmake CMakeLists.txt
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000107 make -C /tmp/googletest
Girish Gowdra489425a2020-02-22 13:07:42 +0530108 sudo make -C /tmp/googletest install
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000109
Girish Gowdraddf9a162020-01-27 12:56:27 +0530110$(cmock-target):
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000111 # Install c-mock
112 rm -rf /tmp/C-Mock && cd /tmp && git clone https://github.com/hjagodzinski/C-Mock.git
Girish Gowdraddf9a162020-01-27 12:56:27 +0530113 cd /tmp/C-Mock && git checkout $(CMOCK_VER)
Girish Gowdra489425a2020-02-22 13:07:42 +0530114 sudo make -C /tmp/C-Mock install
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000115
Girish Gowdraddf9a162020-01-27 12:56:27 +0530116$(gmock-global-target):
Jason Huangbf45ffb2019-10-30 17:29:02 +0800117 # Install gmock-global
118 rm -rf /tmp/gmock-global && cd /tmp && git clone https://github.com/apriorit/gmock-global.git
Girish Gowdraddf9a162020-01-27 12:56:27 +0530119 cd /tmp/gmock-global && git checkout $(GMOCK_GLOBAL_VER)
Girish Gowdra489425a2020-02-22 13:07:42 +0530120 sudo cp -rf /tmp/gmock-global/include/gmock-global /usr/local/include/
Girish Gowdraddf9a162020-01-27 12:56:27 +0530121
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000122########################################################################
123##
124##
125## build
126##
127##
128
129.DEFAULT_GOAL := all
130
Girish Gowdra489425a2020-02-22 13:07:42 +0530131.PHONY = bcm_host_api_stubs build clean prereqs-system prereqs-local
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000132
Girish Gowdra489425a2020-02-22 13:07:42 +0530133OPENOLT_PROTOS_DIR = ../../protos
134OPENOLT_API_LIB = lib/libopenoltapi.a
135OPENOLT_LIB = lib/libopenolt.a
136
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800137# Set the OPENOLT_ROOT_DIR variable to "/app" folder inside the docker container, if not already set.
138ifeq ($(OPENOLT_ROOT_DIR),)
139OPENOLT_ROOT_DIR := /app
140endif
141
Girish Gowdra489425a2020-02-22 13:07:42 +0530142all: bcm_host_api_stubs $(OPENOLT_API_LIB) $(OPENOLT_LIB) build
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000143
144# test
145TEST_OPENOLT_LIB_DIR=./lib
146TEST_BIN=test_openolt
147# The below way of getting source files is not working
148#TEST_SRCS = $($(filter-out src/bal_stub.cc, $(wildcard src/*.cc)))
Girish Gowdra489425a2020-02-22 13:07:42 +0530149TEST_SRCS = src/main_test.cc src/bal_mocker.cc src/test_core.cc
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000150TEST_OBJS = $(TEST_SRCS:.cc=.o)
Girish Gowdraddf9a162020-01-27 12:56:27 +0530151
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000152build: $(TEST_OBJS)
Girish Gowdra489425a2020-02-22 13:07:42 +0530153 $(CXX) $(shell cmock-config --libs) -L$(TEST_OPENOLT_LIB_DIR) -L/usr/lib/ -I/usr/include -I./inc -I../src -o $(TEST_BIN) $(TEST_OBJS) -lgmock -lgtest -lopenolt -lopenoltapi $(LDFLAGS)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000154src/%.o: src/%.cc
Girish Gowdra489425a2020-02-22 13:07:42 +0530155 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I./inc -I../common -I../src -I/usr/include -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000156
157
158# bcm_host_api_stubs
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400159bcm_host_api_stubs:
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800160 echo $(OPENOLT_ROOT_DIR); \
Girish Gowdra489425a2020-02-22 13:07:42 +0530161 # TODO: This is temporary hack below to introduce the definition BAL IEs that are missing in https://github.com/balapi/bal-api-<BAL-VER>
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000162 if [ -d $(BAL_API_DIR) ]; then \
163 echo "$(BAL_API_DIR) exists"; \
164 else \
Girish Gowdraddf9a162020-01-27 12:56:27 +0530165 git clone https://github.com/balapi/$(BAL_API_VER).git ;\
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800166 sed -i "\$$i #include \"$(OPENOLT_ROOT_DIR)/agent/test/inc/bcmos_system_test.h\"" ./$(BAL_API_DIR)/include/bcmos_system.h; \
167 sed -i "\$$i #include \"$(OPENOLT_ROOT_DIR)/agent/test/inc/bcmos_common_test.h\"" ./$(BAL_API_DIR)/include/bcmos_common.h; \
168 sed -i "\$$i #include \"$(OPENOLT_ROOT_DIR)/agent/test/inc/bcmolt_api_model_api_structs_test.h\"" ./$(BAL_API_DIR)/include/object_model/bcmolt_api_model_api_structs.h; \
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000169 fi
170
171# openoltapi
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000172CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens
Girish Gowdra489425a2020-02-22 13:07:42 +0530173$(OPENOLT_API_LIB): $(wildcard $(OPENOLT_PROTOS_DIR)/*.proto)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000174 make -C $(OPENOLT_PROTOS_DIR) all
175 mkdir -p lib
Girish Gowdra489425a2020-02-22 13:07:42 +0530176 cp $(OPENOLT_PROTOS_DIR)/libopenoltapi.a lib/
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000177libproto-clean:
178 make -C $(OPENOLT_PROTOS_DIR) clean
179
180# openolt
181OPENOLT_SRCS = $(wildcard ../src/*.cc) ../common/server.cc $(wildcard ../device/$(OPENOLTDEVICE)/*.cc) src/bal_stub.cc
182OPENOLT_OBJS = $(OPENOLT_SRCS:.cc=.o)
Girish Gowdra489425a2020-02-22 13:07:42 +0530183$(OPENOLT_LIB): $(OPENOLT_OBJS)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000184 mkdir -p lib
Girish Gowdra489425a2020-02-22 13:07:42 +0530185 ar cr $@ $^
186 ranlib $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000187../common/%.o: ../common/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530188 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000189../src/%.o: ../src/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530190 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000191src/%.o: src/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530192 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000193../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530194 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000195
196test: all
Girish Gowdraddf9a162020-01-27 12:56:27 +0530197 ./test_openolt --gtest_output="xml:./test_openolt_report_xunit.xml"
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000198
199clean:
Girish Gowdraddf9a162020-01-27 12:56:27 +0530200 rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./test_openolt_report_xunit.xml