blob: c9f3e83502713a021a3dfc966b6f4b19846625e5 [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
25
26# GRPC installation
27GRPC_ADDR = https://github.com/grpc/grpc
28GRPC_DST = /tmp/grpc
29GRPC_VER = v1.10.x
30
31USER := $(shell echo $(USER))
32#
33########################################################################
34##
35##
36## Install prerequisites
37##
38##
39
40CXX = g++-4.9
41CXXFLAGS += -g -O2
42CXXFLAGS += $(shell pkg-config --cflags-only-I grpc++)
43CPPFLAGS += `pkg-config --cflags protobuf grpc`
44CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix
45CXXFLAGS += -DTEST_MODE -DENABLE_LOG
46LDFLAGS +=
47LDFLAGS += `pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr
48CXXFLAGSDEVICE = -I../device -I../device/$(OPENOLTDEVICE) -I../device/generic
49
50export CXX CXXFLAGS
51
52BAL_API_DIR=bal-api-3.1.0
53BALLIBNAME=bcm_host_api_stubs
54BALLIBDIR=$(BAL_API_DIR)/stubs
55BAL_INC = -I$(BAL_API_DIR)/include \
56 -I$(BAL_API_DIR)/include/object_model
57CXXFLAGS += $(BAL_INC)
58
59
60
61prereq:
62 sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev unzip docker.io
63 sudo apt-get install -y build-essential autoconf libssl-dev gawk debhelper dh-systemd init-system-helpers curl cmake ccache g++-4.9
64
65 # Install GRPC, libprotobuf and protoc
66 rm -rf $(GRPC_DST)
67 git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST)
68 cd $(GRPC_DST) && git submodule update --init
69 cd $(GRPC_DST)/third_party/protobuf && ./autogen.sh && ./configure
70 make -C $(GRPC_DST)/third_party/protobuf
71 sudo make -C $(GRPC_DST)/third_party/protobuf install
72 sudo ldconfig
73 make -C $(GRPC_DST)
74 sudo make -C $(GRPC_DST) install
75 sudo ldconfig
76
77prereq-mock-lib: gtest cmock
78
79gtest:
80 # Install gtest and gmock
81 rm -rf /tmp/googletest && cd /tmp && git clone https://github.com/google/googletest.git
82 cd /tmp/googletest && git checkout release-1.8.0
83 cd /tmp/googletest && cmake CMakeLists.txt
84 make -C /tmp/googletest
85 sudo make -C /tmp/googletest install
86
87cmock:
88 # Install c-mock
89 rm -rf /tmp/C-Mock && cd /tmp && git clone https://github.com/hjagodzinski/C-Mock.git
90 cd /tmp/C-Mock && git checkout 0207b3026f04bbdf0bd9d9f8dfd00945a4318251
91 make -C /tmp/C-Mock
92 sudo make -C /tmp/C-Mock install
93
94########################################################################
95##
96##
97## build
98##
99##
100
101.DEFAULT_GOAL := all
102
103.PHONY = bcm_host_api_stubs libopenoltapi.a libopenolt.a build clean
104
105all: bcm_host_api_stubs libopenoltapi.a libopenolt.a build
106
107# test
108TEST_OPENOLT_LIB_DIR=./lib
109TEST_BIN=test_openolt
110# The below way of getting source files is not working
111#TEST_SRCS = $($(filter-out src/bal_stub.cc, $(wildcard src/*.cc)))
112TEST_SRCS = src/main_test.cc src/bal_mocker.cc src/test_enable_olt.cc
113TEST_OBJS = $(TEST_SRCS:.cc=.o)
114build: $(TEST_OBJS)
115 $(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)
116src/%.o: src/%.cc
117 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I./inc -I../common -I/usr/include -c $< -o $@
118
119
120# bcm_host_api_stubs
121BAL_API_DIR=bal-api-3.1.0
122bcm_host_api_stubs:
123 # TODO: There is temporary hack below to introduce the definition of bcmos_mutex.
124 # This should ideally come as part of bal-api-3.1.0
125 if [ -d $(BAL_API_DIR) ]; then \
126 echo "$(BAL_API_DIR) exists"; \
127 else \
128 git clone https://github.com/balapi/bal-api-3.1.0.git ;\
129 sed -i "\$$i struct bcmos_mutex \{ pthread_mutex_t m; };" ./bal-api-3.1.0/include/bcmos_system.h; \
130 fi
131
132# openoltapi
133OPENOLT_PROTOS_DIR = ../../protos
134OPENOLT_API_LIB = $(OPENOLT_PROTOS_DIR)/libopenoltapi.a
135CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens
136libopenoltapi.a:
137 make -C $(OPENOLT_PROTOS_DIR) all
138 mkdir -p lib
139 cp $(OPENOLT_PROTOS_DIR)/$@ lib/
140libproto-clean:
141 make -C $(OPENOLT_PROTOS_DIR) clean
142
143# openolt
144OPENOLT_SRCS = $(wildcard ../src/*.cc) ../common/server.cc $(wildcard ../device/$(OPENOLTDEVICE)/*.cc) src/bal_stub.cc
145OPENOLT_OBJS = $(OPENOLT_SRCS:.cc=.o)
146libopenolt.a: $(OPENOLT_OBJS)
147 mkdir -p lib
148 ar cr lib/$@ $^
149 ranlib lib/$@
150../common/%.o: ../common/%.cc
151 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
152../src/%.o: ../src/%.cc
153 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
154src/%.o: src/%.cc
155 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
156../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc
157 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@
158
159test: all
160 ./test_openolt --gtest_output="xml:./openolt_test_results.xml"
161
162clean:
163 rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./openolt_test_results.xml