blob: 94e08291550ddd82af6938d1ec046dfaba39d4f8 [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`
Girish Gowdra5287fde2021-07-31 00:41:45 +000022OPENOLTDEVICE ?= sim
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000023
Elia Battiston869a5de2022-02-08 11:40:58 +010024OPENOLT_PROTO_VER ?= v5.2.1
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000025
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000026########################################################################
27##
28##
29## Install prerequisites
30##
31##
32
Thiyagarajan Subramania2c2c5a2021-05-18 14:47:52 +053033CXX != if [ "$(OPENOLTDEVICE)" = "rlt-3200g-w" ]; then echo "g++-6"; else echo "g++-4.9"; fi
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000034CXXFLAGS += -g -O2
Girish Gowdra1935e6a2020-10-31 21:48:22 -070035CXXFLAGS += `pkg-config --cflags-only-I grpc++` -I/usr/local/include/pcapplusplus/
Girish Gowdra489425a2020-02-22 13:07:42 +053036CPPFLAGS += `pkg-config --cflags protobuf grpc`
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000037CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix
38CXXFLAGS += -DTEST_MODE -DENABLE_LOG
Girish Gowdra1935e6a2020-10-31 21:48:22 -070039LDFLAGS += -lpthread -lm `pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr -lPcap++ -lPacket++ -lCommon++
Girish Gowdra252f4972020-09-07 21:24:01 -070040CXXFLAGSDEVICE = -I../device -I../device/$(OPENOLTDEVICE)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000041
42export CXX CXXFLAGS OPENOLT_PROTO_VER
43
Girish Gowdra5287fde2021-07-31 00:41:45 +000044BAL_MAJOR_VER = 3
45BAL_MINOR_VER = 10
46BAL_REV_HOST_VER = 2
47BAL_REV_EMBEDDED_VER = 2
48BAL_API_SO_VER = $(BAL_MAJOR_VER).$(BAL_MINOR_VER).$(BAL_REV_HOST_VER)
49BAL_API_VER = $(BAL_API_SO_VER).$(BAL_REV_EMBEDDED_VER)
50
51BAL_API_DIR=bal-oss-api-$(BAL_API_VER)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000052BALLIBNAME=bcm_host_api_stubs
53BALLIBDIR=$(BAL_API_DIR)/stubs
54BAL_INC = -I$(BAL_API_DIR)/include \
55 -I$(BAL_API_DIR)/include/object_model
Girish Gowdra489425a2020-02-22 13:07:42 +053056CXXFLAGS += $(BAL_INC)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000057
58
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000059########################################################################
60##
61##
62## build
63##
64##
65
66.DEFAULT_GOAL := all
67
Girish Gowdra489425a2020-02-22 13:07:42 +053068.PHONY = bcm_host_api_stubs build clean prereqs-system prereqs-local
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000069
Girish Gowdra489425a2020-02-22 13:07:42 +053070OPENOLT_PROTOS_DIR = ../../protos
71OPENOLT_API_LIB = lib/libopenoltapi.a
72OPENOLT_LIB = lib/libopenolt.a
73
Jason Huang5d9ab1a2020-04-15 16:53:49 +080074# Set the OPENOLT_ROOT_DIR variable to "/app" folder inside the docker container, if not already set.
75ifeq ($(OPENOLT_ROOT_DIR),)
76OPENOLT_ROOT_DIR := /app
77endif
78
Girish Gowdra489425a2020-02-22 13:07:42 +053079all: bcm_host_api_stubs $(OPENOLT_API_LIB) $(OPENOLT_LIB) build
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000080
81# test
82TEST_OPENOLT_LIB_DIR=./lib
83TEST_BIN=test_openolt
84# The below way of getting source files is not working
85#TEST_SRCS = $($(filter-out src/bal_stub.cc, $(wildcard src/*.cc)))
Girish Gowdra489425a2020-02-22 13:07:42 +053086TEST_SRCS = src/main_test.cc src/bal_mocker.cc src/test_core.cc
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000087TEST_OBJS = $(TEST_SRCS:.cc=.o)
Girish Gowdraddf9a162020-01-27 12:56:27 +053088
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000089build: $(TEST_OBJS)
Girish Gowdra489425a2020-02-22 13:07:42 +053090 $(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 +000091src/%.o: src/%.cc
Girish Gowdra489425a2020-02-22 13:07:42 +053092 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I./inc -I../common -I../src -I/usr/include -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000093
94
95# bcm_host_api_stubs
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -040096bcm_host_api_stubs:
Jason Huang5d9ab1a2020-04-15 16:53:49 +080097 echo $(OPENOLT_ROOT_DIR); \
Girish Gowdra489425a2020-02-22 13:07:42 +053098 # 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 +000099 if [ -d $(BAL_API_DIR) ]; then \
100 echo "$(BAL_API_DIR) exists"; \
101 else \
Girish Gowdra5287fde2021-07-31 00:41:45 +0000102 mkdir -p $(BAL_API_DIR); \
103 mkdir -p lib; \
104 cd $(BAL_API_DIR); \
105 git clone https://github.com/balapi/bal-sdk.git -b $(BAL_API_VER); \
106 mv bal-sdk bal-sdk-$(BAL_API_VER); \
107 cd bal-sdk-$(BAL_API_VER); \
108 make BOARD=$(OPENOLTDEVICE); \
109 cp build/fs/libbal_host_api-oss.$(BAL_API_SO_VER).so ../../lib/libbal_host_api-oss.so; \
110 cd .. && ln -s bal-sdk-$(BAL_API_VER)/build/fs/include include; \
111 sed -i 's/BUG_ON_PRINT((condition),/printf(/g' include/bcmos_system.h; \
112 cd ..;\
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000113 fi
114
115# openoltapi
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000116CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens
Girish Gowdra489425a2020-02-22 13:07:42 +0530117$(OPENOLT_API_LIB): $(wildcard $(OPENOLT_PROTOS_DIR)/*.proto)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000118 make -C $(OPENOLT_PROTOS_DIR) all
119 mkdir -p lib
Girish Gowdra489425a2020-02-22 13:07:42 +0530120 cp $(OPENOLT_PROTOS_DIR)/libopenoltapi.a lib/
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000121libproto-clean:
122 make -C $(OPENOLT_PROTOS_DIR) clean
123
124# openolt
Girish Gowdrab0337eb2022-03-25 16:44:21 -0700125OPENOLT_SRCS = $(wildcard ../src/*.cc) ../common/server.cc ../device/device.cc $(wildcard ../device/$(OPENOLTDEVICE)/*.cc) src/bal_stub.cc
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000126OPENOLT_OBJS = $(OPENOLT_SRCS:.cc=.o)
Girish Gowdra489425a2020-02-22 13:07:42 +0530127$(OPENOLT_LIB): $(OPENOLT_OBJS)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000128 mkdir -p lib
Girish Gowdra489425a2020-02-22 13:07:42 +0530129 ar cr $@ $^
130 ranlib $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000131../common/%.o: ../common/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530132 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000133../src/%.o: ../src/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530134 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000135src/%.o: src/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530136 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Girish Gowdrab0337eb2022-03-25 16:44:21 -0700137../device/%.o: ../device/%.cc
138 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000139../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530140 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000141
142test: all
Girish Gowdraddf9a162020-01-27 12:56:27 +0530143 ./test_openolt --gtest_output="xml:./test_openolt_report_xunit.xml"
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000144
145clean:
Girish Gowdrab0337eb2022-03-25 16:44:21 -0700146 rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ../device/device.o ./test_openolt ./test_openolt_report_xunit.xml