blob: e54da02866810ecc1d73cb86d25aad5f10421a12 [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
Girish Gowdra252f4972020-09-07 21:24:01 -070024OPENOLT_PROTO_VER ?= v4.0.2
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000025
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000026########################################################################
27##
28##
29## Install prerequisites
30##
31##
32
Girish Gowdra489425a2020-02-22 13:07:42 +053033CXX = g++
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000034CXXFLAGS += -g -O2
Girish Gowdra489425a2020-02-22 13:07:42 +053035CXXFLAGS += `pkg-config --cflags-only-I grpc++`
36CPPFLAGS += `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 Gowdra489425a2020-02-22 13:07:42 +053039LDFLAGS += -lpthread -lm `pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr
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 Gowdra3b0ae452020-09-28 10:53:18 -070044BAL_API_VER ?= bal-api-3.4.7.5
Girish Gowdraddf9a162020-01-27 12:56:27 +053045BAL_API_DIR=$(BAL_API_VER)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000046BALLIBNAME=bcm_host_api_stubs
47BALLIBDIR=$(BAL_API_DIR)/stubs
48BAL_INC = -I$(BAL_API_DIR)/include \
49 -I$(BAL_API_DIR)/include/object_model
Girish Gowdra489425a2020-02-22 13:07:42 +053050CXXFLAGS += $(BAL_INC)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000051
52
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000053########################################################################
54##
55##
56## build
57##
58##
59
60.DEFAULT_GOAL := all
61
Girish Gowdra489425a2020-02-22 13:07:42 +053062.PHONY = bcm_host_api_stubs build clean prereqs-system prereqs-local
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000063
Girish Gowdra489425a2020-02-22 13:07:42 +053064OPENOLT_PROTOS_DIR = ../../protos
65OPENOLT_API_LIB = lib/libopenoltapi.a
66OPENOLT_LIB = lib/libopenolt.a
67
Jason Huang5d9ab1a2020-04-15 16:53:49 +080068# Set the OPENOLT_ROOT_DIR variable to "/app" folder inside the docker container, if not already set.
69ifeq ($(OPENOLT_ROOT_DIR),)
70OPENOLT_ROOT_DIR := /app
71endif
72
Girish Gowdra489425a2020-02-22 13:07:42 +053073all: bcm_host_api_stubs $(OPENOLT_API_LIB) $(OPENOLT_LIB) build
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000074
75# test
76TEST_OPENOLT_LIB_DIR=./lib
77TEST_BIN=test_openolt
78# The below way of getting source files is not working
79#TEST_SRCS = $($(filter-out src/bal_stub.cc, $(wildcard src/*.cc)))
Girish Gowdra489425a2020-02-22 13:07:42 +053080TEST_SRCS = src/main_test.cc src/bal_mocker.cc src/test_core.cc
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000081TEST_OBJS = $(TEST_SRCS:.cc=.o)
Girish Gowdraddf9a162020-01-27 12:56:27 +053082
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000083build: $(TEST_OBJS)
Girish Gowdra489425a2020-02-22 13:07:42 +053084 $(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 +000085src/%.o: src/%.cc
Girish Gowdra489425a2020-02-22 13:07:42 +053086 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I./inc -I../common -I../src -I/usr/include -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000087
88
89# bcm_host_api_stubs
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -040090bcm_host_api_stubs:
Jason Huang5d9ab1a2020-04-15 16:53:49 +080091 echo $(OPENOLT_ROOT_DIR); \
Girish Gowdra489425a2020-02-22 13:07:42 +053092 # 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 +000093 if [ -d $(BAL_API_DIR) ]; then \
94 echo "$(BAL_API_DIR) exists"; \
95 else \
Girish Gowdraddf9a162020-01-27 12:56:27 +053096 git clone https://github.com/balapi/$(BAL_API_VER).git ;\
Jason Huang5d9ab1a2020-04-15 16:53:49 +080097 sed -i "\$$i #include \"$(OPENOLT_ROOT_DIR)/agent/test/inc/bcmos_system_test.h\"" ./$(BAL_API_DIR)/include/bcmos_system.h; \
98 sed -i "\$$i #include \"$(OPENOLT_ROOT_DIR)/agent/test/inc/bcmos_common_test.h\"" ./$(BAL_API_DIR)/include/bcmos_common.h; \
99 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 +0000100 fi
101
102# openoltapi
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000103CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens
Girish Gowdra489425a2020-02-22 13:07:42 +0530104$(OPENOLT_API_LIB): $(wildcard $(OPENOLT_PROTOS_DIR)/*.proto)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000105 make -C $(OPENOLT_PROTOS_DIR) all
106 mkdir -p lib
Girish Gowdra489425a2020-02-22 13:07:42 +0530107 cp $(OPENOLT_PROTOS_DIR)/libopenoltapi.a lib/
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000108libproto-clean:
109 make -C $(OPENOLT_PROTOS_DIR) clean
110
111# openolt
112OPENOLT_SRCS = $(wildcard ../src/*.cc) ../common/server.cc $(wildcard ../device/$(OPENOLTDEVICE)/*.cc) src/bal_stub.cc
113OPENOLT_OBJS = $(OPENOLT_SRCS:.cc=.o)
Girish Gowdra489425a2020-02-22 13:07:42 +0530114$(OPENOLT_LIB): $(OPENOLT_OBJS)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000115 mkdir -p lib
Girish Gowdra489425a2020-02-22 13:07:42 +0530116 ar cr $@ $^
117 ranlib $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000118../common/%.o: ../common/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530119 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000120../src/%.o: ../src/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530121 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000122src/%.o: src/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530123 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000124../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc
Girish Gowdraddf9a162020-01-27 12:56:27 +0530125 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000126
127test: all
Girish Gowdraddf9a162020-01-27 12:56:27 +0530128 ./test_openolt --gtest_output="xml:./test_openolt_report_xunit.xml"
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000129
130clean:
Girish Gowdraddf9a162020-01-27 12:56:27 +0530131 rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./test_openolt_report_xunit.xml