blob: 3f8eaf983bb713f0bd438dd57608ecf4647eebd3 [file] [log] [blame]
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001# Copyright (C) 2018 Open Networking Foundation
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16########################################################################
17##
18##
19## Config
20##
21##
22TOP_DIR=`pwd`
23OPENOLTDEVICE ?= asfvolt16
24
25# OpenOLT Proto version.
26# This specifies the GIT tag in https://github.com/opencord/voltha-protos
27# repo that we need to refer to, to pick the right version of
28# openolt.proto and tech_profile.proto
29OPENOLT_PROTO_VER ?= v1.0.3
30
31# GRPC installation
32GRPC_ADDR = https://github.com/grpc/grpc
33GRPC_DST = /tmp/grpc
34GRPC_VER = v1.10.x
35
36USER := $(shell echo $(USER))
37#
38########################################################################
39##
40##
41## Install prerequisites
42##
43##
44
45CXX = g++-4.9
46CXXFLAGS += -g -O2
47CXXFLAGS += $(shell pkg-config --cflags-only-I grpc++)
48CPPFLAGS += `pkg-config --cflags protobuf grpc`
49CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix
50CXXFLAGS += -DTEST_MODE -DENABLE_LOG
51LDFLAGS +=
52LDFLAGS += `pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr
53CXXFLAGSDEVICE = -I../device -I../device/$(OPENOLTDEVICE) -I../device/generic
54
55export CXX CXXFLAGS OPENOLT_PROTO_VER
56
57BAL_API_DIR=bal-api-3.1.0
58BALLIBNAME=bcm_host_api_stubs
59BALLIBDIR=$(BAL_API_DIR)/stubs
60BAL_INC = -I$(BAL_API_DIR)/include \
61 -I$(BAL_API_DIR)/include/object_model
62CXXFLAGS += $(BAL_INC)
63
64
65
66prereq:
67 sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev unzip docker.io
68 sudo apt-get install -y build-essential autoconf libssl-dev gawk debhelper dh-systemd init-system-helpers curl cmake ccache g++-4.9
69
70 # Install GRPC, libprotobuf and protoc
71 rm -rf $(GRPC_DST)
72 git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST)
73 cd $(GRPC_DST) && git submodule update --init
74 cd $(GRPC_DST)/third_party/protobuf && ./autogen.sh && ./configure
75 make -C $(GRPC_DST)/third_party/protobuf
76 sudo make -C $(GRPC_DST)/third_party/protobuf install
77 sudo ldconfig
78 make -C $(GRPC_DST)
79 sudo make -C $(GRPC_DST) install
80 sudo ldconfig
81
Jason Huangbf45ffb2019-10-30 17:29:02 +080082prereq-mock-lib: gtest cmock gmock-global
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000083
84gtest:
85 # Install gtest and gmock
86 rm -rf /tmp/googletest && cd /tmp && git clone https://github.com/google/googletest.git
87 cd /tmp/googletest && git checkout release-1.8.0
88 cd /tmp/googletest && cmake CMakeLists.txt
89 make -C /tmp/googletest
90 sudo make -C /tmp/googletest install
91
92cmock:
93 # Install c-mock
94 rm -rf /tmp/C-Mock && cd /tmp && git clone https://github.com/hjagodzinski/C-Mock.git
95 cd /tmp/C-Mock && git checkout 0207b3026f04bbdf0bd9d9f8dfd00945a4318251
96 make -C /tmp/C-Mock
97 sudo make -C /tmp/C-Mock install
98
Jason Huangbf45ffb2019-10-30 17:29:02 +080099gmock-global:
100 # Install gmock-global
101 rm -rf /tmp/gmock-global && cd /tmp && git clone https://github.com/apriorit/gmock-global.git
102 cd /tmp/gmock-global && git checkout 1.0.2
103 sudo cp -rf /tmp/gmock-global/include/gmock-global /usr/local/include/
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000104########################################################################
105##
106##
107## build
108##
109##
110
111.DEFAULT_GOAL := all
112
113.PHONY = bcm_host_api_stubs libopenoltapi.a libopenolt.a build clean
114
115all: bcm_host_api_stubs libopenoltapi.a libopenolt.a build
116
117# test
118TEST_OPENOLT_LIB_DIR=./lib
119TEST_BIN=test_openolt
120# The below way of getting source files is not working
121#TEST_SRCS = $($(filter-out src/bal_stub.cc, $(wildcard src/*.cc)))
122TEST_SRCS = src/main_test.cc src/bal_mocker.cc src/test_enable_olt.cc
123TEST_OBJS = $(TEST_SRCS:.cc=.o)
124build: $(TEST_OBJS)
125 $(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)
126src/%.o: src/%.cc
127 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I./inc -I../common -I/usr/include -c $< -o $@
128
129
130# bcm_host_api_stubs
131BAL_API_DIR=bal-api-3.1.0
132bcm_host_api_stubs:
133 # TODO: There is temporary hack below to introduce the definition of bcmos_mutex.
134 # This should ideally come as part of bal-api-3.1.0
135 if [ -d $(BAL_API_DIR) ]; then \
136 echo "$(BAL_API_DIR) exists"; \
137 else \
138 git clone https://github.com/balapi/bal-api-3.1.0.git ;\
139 sed -i "\$$i #define BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT 0" ./bal-api-3.1.0/include/bcmos_system.h; \
140 sed -i "\$$i struct bcmos_mutex \{ pthread_mutex_t m; };" ./bal-api-3.1.0/include/bcmos_system.h; \
141 fi
142
143# openoltapi
144OPENOLT_PROTOS_DIR = ../../protos
145OPENOLT_API_LIB = $(OPENOLT_PROTOS_DIR)/libopenoltapi.a
146CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens
147libopenoltapi.a:
148 make -C $(OPENOLT_PROTOS_DIR) all
149 mkdir -p lib
150 cp $(OPENOLT_PROTOS_DIR)/$@ lib/
151libproto-clean:
152 make -C $(OPENOLT_PROTOS_DIR) clean
153
154# openolt
155OPENOLT_SRCS = $(wildcard ../src/*.cc) ../common/server.cc $(wildcard ../device/$(OPENOLTDEVICE)/*.cc) src/bal_stub.cc
156OPENOLT_OBJS = $(OPENOLT_SRCS:.cc=.o)
157libopenolt.a: $(OPENOLT_OBJS)
158 mkdir -p lib
159 ar cr lib/$@ $^
160 ranlib lib/$@
161../common/%.o: ../common/%.cc
162 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
163../src/%.o: ../src/%.cc
164 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
165src/%.o: src/%.cc
166 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
167../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc
168 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
169
170test: all
171 ./test_openolt --gtest_output="xml:./test_openolt_report.xml"
172
173clean:
174 rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./test_openolt_report.xml