blob: f3f0e5e96423843e2b5036ca424255e8ad8e7b4b [file] [log] [blame]
Girish Gowdraa707e7c2019-11-07 11:36:13 +05301# 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
24# OpenOLT Proto version.
25# This specifies the GIT tag in https://github.com/opencord/voltha-protos
26# repo that we need to refer to, to pick the right version of
27# openolt.proto and tech_profile.proto
28OPENOLT_PROTO_VER ?= v1.0.3
29
30# GRPC installation
31GRPC_ADDR = https://github.com/grpc/grpc
32GRPC_DST = /tmp/grpc
33GRPC_VER = v1.10.x
34
35USER := $(shell echo $(USER))
36#
37########################################################################
38##
39##
40## Install prerequisites
41##
42##
43
44CXX = g++-4.9
45CXXFLAGS += -g -O2
46CXXFLAGS += $(shell pkg-config --cflags-only-I grpc++)
47CPPFLAGS += `pkg-config --cflags protobuf grpc`
48CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix
49CXXFLAGS += -DTEST_MODE -DENABLE_LOG
50LDFLAGS +=
51LDFLAGS += `pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr
52CXXFLAGSDEVICE = -I../device -I../device/$(OPENOLTDEVICE) -I../device/generic
53
54export CXX CXXFLAGS OPENOLT_PROTO_VER
55
Jason Huang09b73ea2020-01-08 17:52:05 +080056BAL_API_DIR=bal-api-3.2.3.2
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000057BALLIBNAME=bcm_host_api_stubs
58BALLIBDIR=$(BAL_API_DIR)/stubs
59BAL_INC = -I$(BAL_API_DIR)/include \
60 -I$(BAL_API_DIR)/include/object_model
61CXXFLAGS += $(BAL_INC)
62
63
64
65prereq:
66 sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev unzip docker.io
67 sudo apt-get install -y build-essential autoconf libssl-dev gawk debhelper dh-systemd init-system-helpers curl cmake ccache g++-4.9
68
69 # Install GRPC, libprotobuf and protoc
70 rm -rf $(GRPC_DST)
71 git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST)
72 cd $(GRPC_DST) && git submodule update --init
73 cd $(GRPC_DST)/third_party/protobuf && ./autogen.sh && ./configure
74 make -C $(GRPC_DST)/third_party/protobuf
75 sudo make -C $(GRPC_DST)/third_party/protobuf install
76 sudo ldconfig
77 make -C $(GRPC_DST)
78 sudo make -C $(GRPC_DST) install
79 sudo ldconfig
80
Jason Huangbf45ffb2019-10-30 17:29:02 +080081prereq-mock-lib: gtest cmock gmock-global
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000082
83gtest:
84 # Install gtest and gmock
85 rm -rf /tmp/googletest && cd /tmp && git clone https://github.com/google/googletest.git
86 cd /tmp/googletest && git checkout release-1.8.0
87 cd /tmp/googletest && cmake CMakeLists.txt
88 make -C /tmp/googletest
89 sudo make -C /tmp/googletest install
90
91cmock:
92 # Install c-mock
93 rm -rf /tmp/C-Mock && cd /tmp && git clone https://github.com/hjagodzinski/C-Mock.git
94 cd /tmp/C-Mock && git checkout 0207b3026f04bbdf0bd9d9f8dfd00945a4318251
95 make -C /tmp/C-Mock
96 sudo make -C /tmp/C-Mock install
97
Jason Huangbf45ffb2019-10-30 17:29:02 +080098gmock-global:
99 # Install gmock-global
100 rm -rf /tmp/gmock-global && cd /tmp && git clone https://github.com/apriorit/gmock-global.git
101 cd /tmp/gmock-global && git checkout 1.0.2
102 sudo cp -rf /tmp/gmock-global/include/gmock-global /usr/local/include/
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000103########################################################################
104##
105##
106## build
107##
108##
109
110.DEFAULT_GOAL := all
111
112.PHONY = bcm_host_api_stubs libopenoltapi.a libopenolt.a build clean
113
114all: bcm_host_api_stubs libopenoltapi.a libopenolt.a build
115
116# test
117TEST_OPENOLT_LIB_DIR=./lib
118TEST_BIN=test_openolt
119# The below way of getting source files is not working
120#TEST_SRCS = $($(filter-out src/bal_stub.cc, $(wildcard src/*.cc)))
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000121TEST_SRCS = src/main_test.cc src/bal_mocker.cc src/test_core.cc
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000122TEST_OBJS = $(TEST_SRCS:.cc=.o)
123build: $(TEST_OBJS)
124 $(CXX) $(shell cmock-config --libs) -L$(TEST_OPENOLT_LIB_DIR) -L/usr/lib/ -I/usr/include -I./inc -o $(TEST_BIN) $(TEST_OBJS) -lgmock -lgtest -lopenolt -lopenoltapi $(LDFLAGS)
125src/%.o: src/%.cc
126 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I./inc -I../common -I/usr/include -c $< -o $@
127
128
129# bcm_host_api_stubs
Jason Huang09b73ea2020-01-08 17:52:05 +0800130BAL_API_DIR=bal-api-3.2.3.2
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400131bcm_host_api_stubs:
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000132 # TODO: There is temporary hack below to introduce the definition of bcmos_mutex.
Jason Huang09b73ea2020-01-08 17:52:05 +0800133 # This should ideally come as part of bal-api-3.2.3.2
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000134 if [ -d $(BAL_API_DIR) ]; then \
135 echo "$(BAL_API_DIR) exists"; \
136 else \
Jason Huang09b73ea2020-01-08 17:52:05 +0800137 git clone https://github.com/balapi/bal-api-3.2.3.2.git ;\
138 sed -i "\$$i #define BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT 0" ./bal-api-3.2.3.2/include/bcmos_system.h; \
139 sed -i "\$$i struct bcmos_mutex \{ pthread_mutex_t m; };" ./bal-api-3.2.3.2/include/bcmos_system.h; \
140 sed -i "\$$i extern void* bcmos_calloc(uint32_t size);" ./bal-api-3.2.3.2/include/bcmos_common.h; \
141 sed -i "\$$i #define BCMOLT_INTERFACE_TYPE_EPON_1_G 3" ./bal-api-3.2.3.2/include/bcmos_common.h; \
142 sed -i "\$$i #define BCMOLT_INTERFACE_TYPE_EPON_10_G 4" ./bal-api-3.2.3.2/include/bcmos_common.h; \
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000143 fi
144
145# openoltapi
146OPENOLT_PROTOS_DIR = ../../protos
147OPENOLT_API_LIB = $(OPENOLT_PROTOS_DIR)/libopenoltapi.a
148CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens
149libopenoltapi.a:
150 make -C $(OPENOLT_PROTOS_DIR) all
151 mkdir -p lib
152 cp $(OPENOLT_PROTOS_DIR)/$@ lib/
153libproto-clean:
154 make -C $(OPENOLT_PROTOS_DIR) clean
155
156# openolt
157OPENOLT_SRCS = $(wildcard ../src/*.cc) ../common/server.cc $(wildcard ../device/$(OPENOLTDEVICE)/*.cc) src/bal_stub.cc
158OPENOLT_OBJS = $(OPENOLT_SRCS:.cc=.o)
159libopenolt.a: $(OPENOLT_OBJS)
160 mkdir -p lib
161 ar cr lib/$@ $^
162 ranlib lib/$@
163../common/%.o: ../common/%.cc
164 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
165../src/%.o: ../src/%.cc
166 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
167src/%.o: src/%.cc
168 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
169../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc
170 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
171
172test: all
173 ./test_openolt --gtest_output="xml:./test_openolt_report.xml"
174
175clean:
176 rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./test_openolt_report.xml