blob: b8fee222c1aaa9633aa311fd7d5c6e5e569d8d23 [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
56BAL_API_DIR=bal-api-3.1.0
57BALLIBNAME=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)))
121TEST_SRCS = src/main_test.cc src/bal_mocker.cc src/test_enable_olt.cc
122TEST_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
130BAL_API_DIR=bal-api-3.1.0
131bcm_host_api_stubs:
132 # TODO: There is temporary hack below to introduce the definition of bcmos_mutex.
133 # This should ideally come as part of bal-api-3.1.0
134 if [ -d $(BAL_API_DIR) ]; then \
135 echo "$(BAL_API_DIR) exists"; \
136 else \
137 git clone https://github.com/balapi/bal-api-3.1.0.git ;\
138 sed -i "\$$i #define BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT 0" ./bal-api-3.1.0/include/bcmos_system.h; \
139 sed -i "\$$i struct bcmos_mutex \{ pthread_mutex_t m; };" ./bal-api-3.1.0/include/bcmos_system.h; \
140 fi
141
142# openoltapi
143OPENOLT_PROTOS_DIR = ../../protos
144OPENOLT_API_LIB = $(OPENOLT_PROTOS_DIR)/libopenoltapi.a
145CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens
146libopenoltapi.a:
147 make -C $(OPENOLT_PROTOS_DIR) all
148 mkdir -p lib
149 cp $(OPENOLT_PROTOS_DIR)/$@ lib/
150libproto-clean:
151 make -C $(OPENOLT_PROTOS_DIR) clean
152
153# openolt
154OPENOLT_SRCS = $(wildcard ../src/*.cc) ../common/server.cc $(wildcard ../device/$(OPENOLTDEVICE)/*.cc) src/bal_stub.cc
155OPENOLT_OBJS = $(OPENOLT_SRCS:.cc=.o)
156libopenolt.a: $(OPENOLT_OBJS)
157 mkdir -p lib
158 ar cr lib/$@ $^
159 ranlib lib/$@
160../common/%.o: ../common/%.cc
161 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
162../src/%.o: ../src/%.cc
163 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
164src/%.o: src/%.cc
165 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
166../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc
167 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
168
169test: all
170 ./test_openolt --gtest_output="xml:./test_openolt_report.xml"
171
172clean:
173 rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./test_openolt_report.xml