blob: ac5a351f5d1bb64cea256cb135c80aec2d4c2017 [file] [log] [blame]
Shad Ansari01b0e652018-04-05 21:02:53 +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##
22DEVICE = asfvolt16
23#
24# Three vendor proprietary source files are required to build BAL.
25# SW-BCM68620_<VER>.zip - Broadcom BAL source and Maple SDK.
26# sdk-all-<SDK_VER>.tar.gz - Broadcom Qumran SDK.
27# ACCTON_BAL_<BAL_VER>-<ACCTON_VER>.patch - Accton/Edgecore's patch.
28BAL_MAJOR_VER = 02.04
29BAL_VER = 2.4.3.6
30SDK_VER = 6.5.7
31ACCTON_VER = 201710131639
32#
33# Version of Open Network Linux (ONL).
34ONL_KERN_VER_MAJOR = 3.7
35ONL_KERN_VER_MINOR = 10
36#
37# Build directory
38BUILD_DIR = build
39
40########################################################################
41##
42##
43## Check
44##
45##
46HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
47SYSTEM ?= $(HOST_SYSTEM)
48CXX = g++
49CPPFLAGS += `pkg-config --cflags protobuf grpc`
50CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix
51ifeq ($(SYSTEM),Darwin)
52LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
53 -lgrpc++_reflection\
54 -ldl
55else
56LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
57 -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\
58 -ldl
59endif
60PROTOC = protoc
61GRPC_CPP_PLUGIN = grpc_cpp_plugin
62GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
63GRPC_CPP_VER ?= `command curl -L https://grpc.io/release`
64PROTOC_CMD = which $(PROTOC)
65PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3
66PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN)
67HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
68ifeq ($(HAS_PROTOC),true)
69HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
70endif
71HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false)
72check:
73 sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev
74ifneq ($(HAS_VALID_PROTOC),true)
75 mkdir -p /tmp/$(PROTOC_NAME)
76 wget -P /tmp/$(PROTOC_NAME) $(PROTOC_DOWNLOAD_URL)/v$(PROTOC_VERSION)/$(PROTOC_NAME).zip
77 unzip -o /tmp/$(PROTOC_NAME)/$(PROTOC_NAME) -d /tmp/$(PROTOC_NAME)
78 mkdir -p $(PWD)/bin
79 cp -f /tmp/$(PROTOC_NAME)/bin/protoc $(PWD)/bin/.
80 mkdir -p $(PWD)/include
81 cp -rf /tmp/$(PROTOC_NAME)/include/* $(PWD)/include/.
82 rm -rf /tmp/$(PROTOC_NAME)
83endif
84ifneq ($(HAS_PLUGIN),true)
85 rm -rf /tmp/grpc
86 git clone -b $(GRPC_CPP_VER) https://github.com/grpc/grpc /tmp/grpc
87 cd /tmp/grpc && git submodule update --init
88 make -C /tmp/grpc
89 sudo make -C /tmp/grpc install
90 make -C /tmp/grpc/third_party/protobuf
91 sudo make -C /tmp/grpc/third_party/protobuf install
92 rm -rf /tmp/grpc
93endif
94
95########################################################################
96##
97##
98## ONL
99##
100##
101ONL_KERN_VER = $(ONL_KERN_VER_MAJOR).$(ONL_KERN_VER_MINOR)
102ONL_REPO = $(DEVICE)-onl
103ONL_DIR = $(BUILD_DIR)/$(ONL_REPO)
104.PHONY: onl
105onl:
106 if [ ! -d "$(ONL_DIR)/OpenNetworkLinux" ]; then \
107 mkdir -p $(ONL_DIR); \
108 git clone git@github.com:shadansari/$(ONL_REPO).git $(ONL_DIR); \
Shad Ansari01b0e652018-04-05 21:02:53 +0000109 make -C $(ONL_DIR) $(DEVICE)-$(ONL_KERN_VER_MAJOR); \
110 fi;
111onl-force:
112 make -C $(ONL_DIR) $(DEVICE)-$(ONL_KERN_VER_MAJOR)
113clean-onl:
114distclean-onl:
115 sudo rm -rf $(ONL_DIR)
116
117########################################################################
118##
119##
120## BAL
121##
122##
123BAL_ZIP = SW-BCM68620_$(subst .,_,$(BAL_VER)).zip
124SDK_ZIP = sdk-all-$(SDK_VER).tar.gz
125ACCTON_PATCH = ACCTON_BAL_$(BAL_VER)-V$(ACCTON_VER).patch
126OPENOLT_BAL_PATCH = OPENOLT_BAL_$(BAL_VER).patch
127BAL_DIR = $(BUILD_DIR)/$(DEVICE)-bal
128ONL_KERNDIR = $(PWD)/$(ONL_DIR)/OpenNetworkLinux/packages/base/amd64/kernels/kernel-$(ONL_KERN_VER_MAJOR)-x86-64-all/builds
129MAPLE_KERNDIR = $(BAL_DIR)/bcm68620_release/$(DEVICE)/kernels
130BCM_SDK = $(BAL_DIR)/bal_release/3rdparty/bcm-sdk
131BALLIBDIR = $(BAL_DIR)/bal_release/build/core/lib
132BALLIBNAME = bal_api_dist
133BAL_INC = -I$(BAL_DIR)/bal_release/src/common/os_abstraction \
134 -I$(BAL_DIR)/bal_release/src/common/os_abstraction/posix \
135 -I$(BAL_DIR)/bal_release/src/common/config \
136 -I$(BAL_DIR)/bal_release/src/core/platform \
137 -I$(BAL_DIR)/bal_release/src/common/include \
138 -I$(BAL_DIR)/bal_release/src/lib/libbalapi \
139 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/utils \
140 -I$(BAL_DIR)/bal_release/src/balapiend \
141 -I$(BAL_DIR)/bal_release/src/common/dev_log \
142 -I$(BAL_DIR)/bal_release/src/common/bal_dist_utils \
143 -I$(BAL_DIR)/bal_release/src/lib/libtopology \
144 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/model \
145 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/api \
146 -I$(BAL_DIR)/bal_release/src/lib/libcmdline \
147 -I$(BAL_DIR)/bal_release/src/lib/libutils \
148 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_reference/cli
149CXXFLAGS += $(BAL_INC) -I $(BAL_DIR)/lib/cmdline
150.PHONY: get-$(BAL_DIR)
151get-$(BAL_DIR):
152# if [ ! -e "download/$(BAL_ZIP)" ]; then \
153# rm -rf /tmp/broadcom-proprietary; \
154# git clone git@github.com:shadansari/broadcom-proprietary.git /tmp/broadcom-proprietary; \
155# mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(BAL_ZIP) ./download; \
156# mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(SDK_ZIP) ./download; \
157# mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(ACCTON_PATCH) ./download; \
158# mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(OPENOLT_BAL_PATCH) ./download; \
159# rm -rf /tmp/broadcom-proprietary; \
160# fi;
161.PHONY: bal
162bal: onl get-$(BAL_DIR)
163ifeq ("$(wildcard $(BAL_DIR))","")
164 mkdir $(BAL_DIR)
165 unzip download/$(BAL_ZIP) -d $(BAL_DIR)
166 cp download/$(SDK_ZIP) $(BCM_SDK)
167 chmod -R 744 $(BAL_DIR)
168 cat download/$(ACCTON_PATCH) | patch -p1 -d $(BAL_DIR)
169 mkdir -p $(MAPLE_KERNDIR)
170 ln -s $(ONL_KERNDIR)/linux-$(ONL_KERN_VER) $(MAPLE_KERNDIR)/linux-$(ONL_KERN_VER)
171 ln -s $(ONL_DIR)/OpenNetworkLinux/packages/base/any/kernels/archives/linux-$(ONL_KERN_VER).tar.xz $(MAPLE_KERNDIR)/linux-$(ONL_KERN_VER).tar.xz
172 ln -s $(ONL_DIR)/OpenNetworkLinux/packages/base/any/kernels/$(ONL_KERN_VER_MAJOR)/configs/x86_64-all/x86_64-all.config $(MAPLE_KERNDIR)/x86_64-all.config
173 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk_dir
174 cat download/$(OPENOLT_BAL_PATCH) | patch -p1 -d $(BAL_DIR)
175 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk
176 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk_dir
177 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk
178 KERNDIR=$(ONL_KERNDIR)/linux-$(ONL_KERN_VER) BOARD=$(DEVICE) ARCH=x86_64 SDKBUILD=build_bcm_user make -C $(BCM_SDK)/build-$(DEVICE)/sdk-all-$(SDK_VER)/systems/linux/user/x86-generic_64-2_6
179 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) bal
180 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) release_board
181 ln -s -f $(PWD)/$(BAL_DIR)/bcm68620_release/asfvolt16/release/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz .
182 ln -s -f $(PWD)/$(BAL_DIR)/bal_release/build/core/lib/libbal_api_dist.so .
183 ln -s -f $(PWD)/$(BAL_DIR)/bal_release/build/core/src/apps/bal_core_dist/bal_core_dist
184 mv -f release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz $(BUILD_DIR)
185 mv -f libbal_api_dist.so $(BUILD_DIR)
186 mv -f bal_core_dist $(BUILD_DIR)
187endif
188bal-rebuild:
189 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk
190 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk
191 KERNDIR=$(ONL_KERNDIR)/linux-$(ONL_KERN_VER) BOARD=$(DEVICE) ARCH=x86_64 SDKBUILD=build_bcm_user make -C $(BCM_SDK)/build-$(DEVICE)/sdk-all-$(SDK_VER)/systems/linux/user/x86-generic_64-2_6
192 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) bal
193 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) release_board
194 ln -s -f $(PWD)/$(BAL_DIR)/bcm68620_release/asfvolt16/release/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz .
195 ln -s -f $(PWD)/$(BAL_DIR)/bal_release/build/core/lib/libbal_api_dist.so .
196 ln -s -f $(PWD)/$(BAL_DIR)/bal_release/build/core/src/apps/bal_core_dist/bal_core_dist .
197 mv -f release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz $(BUILD_DIR)
198 mv -f libbal_api_dist.so $(BUILD_DIR)
199 mv -f bal_core_dist $(BUILD_DIR)
200clean-bal: clean-onl
201distclean-bal: distclean-onl
202 sudo rm -rf $(BAL_DIR)
203 rm -f build/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz
204
205########################################################################
206##
207##
208## OpenOLT API
209##
210##
211OPENOLT_API_DIR = $(BUILD_DIR)/openolt-api
212OPENOLT_API_LIB = $(OPENOLT_API_DIR)/libopenoltapi.a
213CXXFLAGS += -I./$(OPENOLT_API_DIR) -I $(OPENOLT_API_DIR)/googleapis/gens
214.PHONY: openolt-api
215openolt-api:
216 if [ ! -e "$(OPENOLT_API_DIR)" ]; then \
217 mkdir -p $(BUILD_DIR); \
218 git clone git@github.com:shadansari/openolt-api.git $(OPENOLT_API_DIR); \
219 fi;
220 make -C $(OPENOLT_API_DIR) all
221clean-openolt-api:
222 -make -C $(OPENOLT_API_DIR) clean
223distclean-openolt-api:
224
225########################################################################
226##
227##
228## Main
229##
230##
231SRCS = $(wildcard src/*.cc)
232OBJS = $(SRCS:.cc=.o)
233DEPS = $(SRCS:.cc=.d)
234.DEFAULT_GOAL := all
235all: $(BUILD_DIR)/openolt
236$(BUILD_DIR)/openolt: check openolt-api bal $(OBJS)
237 $(CXX) $(OBJS) $(LDFLAGS) $(OPENOLT_API_LIB) -o $@ -L$(BALLIBDIR) -l$(BALLIBNAME)
238 ln -s $(shell ldconfig -p | grep libgrpc.so.5 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc.so.5
239 ln -s $(shell ldconfig -p | grep libgrpc++.so.1 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc++.so.1
240 ln -s $(shell ldconfig -p | grep libgrpc++_reflection.so.1 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc++_reflection.so.1
241
242src/%.o: %.cpp
243 $(CXX) -MMD -c $< -o $@
244
245clean: clean-bal
246 rm -f $(OBJS) $(DEPS) $(BUILD_DIR)/openolt
247 rm -rf $(OPENOLT_API_DIR)
248distclean: distclean-openolt-api distclean-bal
249 rm -rf $(BUILD_DIR)
250-include $(DEPS)