blob: 1a65d48dd77c4362aeb30cc2c5b7c6585f7526d4 [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##
Luca Pretee75aaa52018-04-13 12:19:12 -070019## Config
Shad Ansari01b0e652018-04-05 21:02:53 +000020##
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
Luca Pretee75aaa52018-04-13 12:19:12 -070039#
40# GRPC installation
41GRPC_ADDR = https://github.com/grpc/grpc
42GRPC_DST = /tmp/grpc
43GRPC_VER = v1.10.x
44#
Shad Ansari01b0e652018-04-05 21:02:53 +000045########################################################################
46##
47##
Luca Prete08e6f802018-04-17 11:49:45 -070048## Install prerequisites
Shad Ansari01b0e652018-04-05 21:02:53 +000049##
50##
51HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
52SYSTEM ?= $(HOST_SYSTEM)
Luca Pretee75aaa52018-04-13 12:19:12 -070053
Shad Ansari01b0e652018-04-05 21:02:53 +000054CXX = g++
55CPPFLAGS += `pkg-config --cflags protobuf grpc`
56CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix
57ifeq ($(SYSTEM),Darwin)
58LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
Luca Pretee75aaa52018-04-13 12:19:12 -070059 -lgrpc++_reflection\
60 -ldl
Shad Ansari01b0e652018-04-05 21:02:53 +000061else
62LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
Luca Pretee75aaa52018-04-13 12:19:12 -070063 -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\
64 -ldl
Shad Ansari01b0e652018-04-05 21:02:53 +000065endif
Luca Pretee75aaa52018-04-13 12:19:12 -070066
Luca Prete08e6f802018-04-17 11:49:45 -070067prereq:
Shad Ansari01b0e652018-04-05 21:02:53 +000068 sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev
Luca Pretee75aaa52018-04-13 12:19:12 -070069
70 # Install GRPC plugins
71 rm -rf $(GRPC_DST)
72 git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST)
73 cd $(GRPC_DST) && git submodule update --init
74 make -C $(GRPC_DST)
75 sudo make -C $(GRPC_DST) install
76 # Install libprotobuf and protoc
Luca Prete08e6f802018-04-17 11:49:45 -070077 cd $(GRPC_DST)/third_party/protobuf && ./autogen.sh
78 cd $(GRPC_DST)/third_party/protobuf && ./configure
79 make -C $(GRPC_DST)/third_party/protobuf
80 sudo make -C $(GRPC_DST)/third_party/protobuf install
81 sudo ldconfig
Shad Ansari01b0e652018-04-05 21:02:53 +000082
83########################################################################
84##
85##
Luca Pretee75aaa52018-04-13 12:19:12 -070086## ONL
Shad Ansari01b0e652018-04-05 21:02:53 +000087##
88##
89ONL_KERN_VER = $(ONL_KERN_VER_MAJOR).$(ONL_KERN_VER_MINOR)
90ONL_REPO = $(DEVICE)-onl
91ONL_DIR = $(BUILD_DIR)/$(ONL_REPO)
92.PHONY: onl
93onl:
94 if [ ! -d "$(ONL_DIR)/OpenNetworkLinux" ]; then \
95 mkdir -p $(ONL_DIR); \
Luca Preteb7886282018-04-06 15:34:08 -070096 git clone https://gerrit.opencord.org/$(ONL_REPO) $(ONL_DIR); \
Shad Ansari01b0e652018-04-05 21:02:53 +000097 make -C $(ONL_DIR) $(DEVICE)-$(ONL_KERN_VER_MAJOR); \
98 fi;
99onl-force:
100 make -C $(ONL_DIR) $(DEVICE)-$(ONL_KERN_VER_MAJOR)
Shad Ansari01b0e652018-04-05 21:02:53 +0000101distclean-onl:
102 sudo rm -rf $(ONL_DIR)
103
104########################################################################
105##
106##
Luca Pretee75aaa52018-04-13 12:19:12 -0700107## BAL
Shad Ansari01b0e652018-04-05 21:02:53 +0000108##
109##
110BAL_ZIP = SW-BCM68620_$(subst .,_,$(BAL_VER)).zip
111SDK_ZIP = sdk-all-$(SDK_VER).tar.gz
112ACCTON_PATCH = ACCTON_BAL_$(BAL_VER)-V$(ACCTON_VER).patch
113OPENOLT_BAL_PATCH = OPENOLT_BAL_$(BAL_VER).patch
114BAL_DIR = $(BUILD_DIR)/$(DEVICE)-bal
115ONL_KERNDIR = $(PWD)/$(ONL_DIR)/OpenNetworkLinux/packages/base/amd64/kernels/kernel-$(ONL_KERN_VER_MAJOR)-x86-64-all/builds
116MAPLE_KERNDIR = $(BAL_DIR)/bcm68620_release/$(DEVICE)/kernels
117BCM_SDK = $(BAL_DIR)/bal_release/3rdparty/bcm-sdk
118BALLIBDIR = $(BAL_DIR)/bal_release/build/core/lib
119BALLIBNAME = bal_api_dist
120BAL_INC = -I$(BAL_DIR)/bal_release/src/common/os_abstraction \
121 -I$(BAL_DIR)/bal_release/src/common/os_abstraction/posix \
122 -I$(BAL_DIR)/bal_release/src/common/config \
123 -I$(BAL_DIR)/bal_release/src/core/platform \
124 -I$(BAL_DIR)/bal_release/src/common/include \
125 -I$(BAL_DIR)/bal_release/src/lib/libbalapi \
126 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/utils \
127 -I$(BAL_DIR)/bal_release/src/balapiend \
128 -I$(BAL_DIR)/bal_release/src/common/dev_log \
129 -I$(BAL_DIR)/bal_release/src/common/bal_dist_utils \
130 -I$(BAL_DIR)/bal_release/src/lib/libtopology \
131 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/model \
132 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/api \
133 -I$(BAL_DIR)/bal_release/src/lib/libcmdline \
134 -I$(BAL_DIR)/bal_release/src/lib/libutils \
135 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_reference/cli
136CXXFLAGS += $(BAL_INC) -I $(BAL_DIR)/lib/cmdline
137.PHONY: get-$(BAL_DIR)
138get-$(BAL_DIR):
Luca Pretee75aaa52018-04-13 12:19:12 -0700139# if [ ! -e "download/$(BAL_ZIP)" ]; then \
140# rm -rf /tmp/broadcom-proprietary; \
141# git clone git@github.com:shadansari/broadcom-proprietary.git /tmp/broadcom-proprietary; \
142# mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(BAL_ZIP) ./download; \
143# mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(SDK_ZIP) ./download; \
144# mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(ACCTON_PATCH) ./download; \
145# mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(OPENOLT_BAL_PATCH) ./download; \
146# rm -rf /tmp/broadcom-proprietary; \
147# fi;
Shad Ansari01b0e652018-04-05 21:02:53 +0000148.PHONY: bal
149bal: onl get-$(BAL_DIR)
150ifeq ("$(wildcard $(BAL_DIR))","")
151 mkdir $(BAL_DIR)
152 unzip download/$(BAL_ZIP) -d $(BAL_DIR)
153 cp download/$(SDK_ZIP) $(BCM_SDK)
154 chmod -R 744 $(BAL_DIR)
155 cat download/$(ACCTON_PATCH) | patch -p1 -d $(BAL_DIR)
156 mkdir -p $(MAPLE_KERNDIR)
157 ln -s $(ONL_KERNDIR)/linux-$(ONL_KERN_VER) $(MAPLE_KERNDIR)/linux-$(ONL_KERN_VER)
158 ln -s $(ONL_DIR)/OpenNetworkLinux/packages/base/any/kernels/archives/linux-$(ONL_KERN_VER).tar.xz $(MAPLE_KERNDIR)/linux-$(ONL_KERN_VER).tar.xz
159 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
160 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk_dir
161 cat download/$(OPENOLT_BAL_PATCH) | patch -p1 -d $(BAL_DIR)
162 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk
163 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk_dir
164 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk
165 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
166 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) bal
167 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) release_board
168 ln -s -f $(PWD)/$(BAL_DIR)/bcm68620_release/asfvolt16/release/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz .
169 ln -s -f $(PWD)/$(BAL_DIR)/bal_release/build/core/lib/libbal_api_dist.so .
170 ln -s -f $(PWD)/$(BAL_DIR)/bal_release/build/core/src/apps/bal_core_dist/bal_core_dist
171 mv -f release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz $(BUILD_DIR)
172 mv -f libbal_api_dist.so $(BUILD_DIR)
173 mv -f bal_core_dist $(BUILD_DIR)
174endif
175bal-rebuild:
176 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk
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)
Shad Ansari19249582018-04-30 04:31:00 +0000187distclean-bal:
Shad Ansari01b0e652018-04-05 21:02:53 +0000188 sudo rm -rf $(BAL_DIR)
189 rm -f build/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz
190
191########################################################################
192##
193##
Luca Pretee75aaa52018-04-13 12:19:12 -0700194## OpenOLT API
Shad Ansari01b0e652018-04-05 21:02:53 +0000195##
196##
Shad Ansari19249582018-04-30 04:31:00 +0000197OPENOLT_PROTOS_DIR = ./protos
198OPENOLT_API_LIB = $(OPENOLT_PROTOS_DIR)/libopenoltapi.a
199CXXFLAGS += -I./$(OPENOLT_PROTOS_DIR) -I $(OPENOLT_PROTOS_DIR)/googleapis/gens
200.PHONY: protos
201protos:
202 make -C $(OPENOLT_PROTOS_DIR) all
203clean-protos:
204 -make -C $(OPENOLT_PROTOS_DIR) clean
Shad Ansari01b0e652018-04-05 21:02:53 +0000205
206########################################################################
207##
208##
Luca Pretee75aaa52018-04-13 12:19:12 -0700209## Main
Shad Ansari01b0e652018-04-05 21:02:53 +0000210##
211##
212SRCS = $(wildcard src/*.cc)
213OBJS = $(SRCS:.cc=.o)
214DEPS = $(SRCS:.cc=.d)
215.DEFAULT_GOAL := all
216all: $(BUILD_DIR)/openolt
Shad Ansari19249582018-04-30 04:31:00 +0000217$(BUILD_DIR)/openolt: protos bal $(OBJS)
Shad Ansari01b0e652018-04-05 21:02:53 +0000218 $(CXX) $(OBJS) $(LDFLAGS) $(OPENOLT_API_LIB) -o $@ -L$(BALLIBDIR) -l$(BALLIBNAME)
Shad Ansaria0eeec52018-04-18 22:05:38 +0000219 ln -s $(shell ldconfig -p | grep libgrpc.so.6 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc.so.6
Shad Ansari01b0e652018-04-05 21:02:53 +0000220 ln -s $(shell ldconfig -p | grep libgrpc++.so.1 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc++.so.1
221 ln -s $(shell ldconfig -p | grep libgrpc++_reflection.so.1 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc++_reflection.so.1
222
223src/%.o: %.cpp
224 $(CXX) -MMD -c $< -o $@
225
Shad Ansari19249582018-04-30 04:31:00 +0000226clean: clean-protos
227 rm -f $(OBJS) $(DEPS)
Shad Ansaria0eeec52018-04-18 22:05:38 +0000228 rm -f $(BUILD_DIR)/libgrpc.so.6 $(BUILD_DIR)/libgrpc++.so.1 $(BUILD_DIR)/libgrpc++_reflection.so.1
Shad Ansari19249582018-04-30 04:31:00 +0000229
230distclean:
Shad Ansari01b0e652018-04-05 21:02:53 +0000231 rm -rf $(BUILD_DIR)