blob: 2122266327814ec08c2325b5246f774e44fba4b3 [file] [log] [blame]
Girish Gowdrae538dfd2019-09-30 11:07:30 +05301# 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
Girish Gowdra897f5ab2019-10-17 17:05:31 +053025# 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
Girish Gowdrae538dfd2019-09-30 11:07:30 +053030
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
Girish Gowdra897f5ab2019-10-17 17:05:31 +053055export CXX CXXFLAGS OPENOLT_PROTO_VER
Girish Gowdrae538dfd2019-09-30 11:07:30 +053056
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
82prereq-mock-lib: gtest cmock
83
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
99########################################################################
100##
101##
102## build
103##
104##
105
106.DEFAULT_GOAL := all
107
108.PHONY = bcm_host_api_stubs libopenoltapi.a libopenolt.a build clean
109
110all: bcm_host_api_stubs libopenoltapi.a libopenolt.a build
111
112# test
113TEST_OPENOLT_LIB_DIR=./lib
114TEST_BIN=test_openolt
115# The below way of getting source files is not working
116#TEST_SRCS = $($(filter-out src/bal_stub.cc, $(wildcard src/*.cc)))
117TEST_SRCS = src/main_test.cc src/bal_mocker.cc src/test_enable_olt.cc
118TEST_OBJS = $(TEST_SRCS:.cc=.o)
119build: $(TEST_OBJS)
120 $(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)
121src/%.o: src/%.cc
122 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I./inc -I../common -I/usr/include -c $< -o $@
123
124
125# bcm_host_api_stubs
126BAL_API_DIR=bal-api-3.1.0
127bcm_host_api_stubs:
128 # TODO: There is temporary hack below to introduce the definition of bcmos_mutex.
129 # This should ideally come as part of bal-api-3.1.0
130 if [ -d $(BAL_API_DIR) ]; then \
131 echo "$(BAL_API_DIR) exists"; \
132 else \
133 git clone https://github.com/balapi/bal-api-3.1.0.git ;\
Girish Gowdra3de9d342019-10-10 19:46:04 +0530134 sed -i "\$$i #define BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT 0" ./bal-api-3.1.0/include/bcmos_system.h; \
Girish Gowdrae538dfd2019-09-30 11:07:30 +0530135 sed -i "\$$i struct bcmos_mutex \{ pthread_mutex_t m; };" ./bal-api-3.1.0/include/bcmos_system.h; \
136 fi
137
138# openoltapi
139OPENOLT_PROTOS_DIR = ../../protos
140OPENOLT_API_LIB = $(OPENOLT_PROTOS_DIR)/libopenoltapi.a
141CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens
142libopenoltapi.a:
143 make -C $(OPENOLT_PROTOS_DIR) all
144 mkdir -p lib
145 cp $(OPENOLT_PROTOS_DIR)/$@ lib/
146libproto-clean:
147 make -C $(OPENOLT_PROTOS_DIR) clean
148
149# openolt
150OPENOLT_SRCS = $(wildcard ../src/*.cc) ../common/server.cc $(wildcard ../device/$(OPENOLTDEVICE)/*.cc) src/bal_stub.cc
151OPENOLT_OBJS = $(OPENOLT_SRCS:.cc=.o)
152libopenolt.a: $(OPENOLT_OBJS)
153 mkdir -p lib
154 ar cr lib/$@ $^
155 ranlib lib/$@
156../common/%.o: ../common/%.cc
157 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
158../src/%.o: ../src/%.cc
159 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
160src/%.o: src/%.cc
161 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
162../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc
163 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
164
165test: all
Girish Gowdrad18f0d32019-10-11 20:46:15 +0530166 ./test_openolt --gtest_output="xml:./test_openolt_report.xml"
Girish Gowdrae538dfd2019-09-30 11:07:30 +0530167
168clean:
Girish Gowdrad18f0d32019-10-11 20:46:15 +0530169 rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./test_openolt_report.xml