blob: 1211afaccce90f1da3e81e8126521c3a27e0f8ba [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.
Shad Ansaricb004c52018-05-30 18:07:23 +000028BAL_MAJOR_VER = 02.06
29BAL_VER = 2.6.0.1
Shad Ansari01b0e652018-04-05 21:02:53 +000030SDK_VER = 6.5.7
Shad Ansaricb004c52018-05-30 18:07:23 +000031ACCTON_VER = 201804301043
Shad Ansari01b0e652018-04-05 21:02:53 +000032#
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
Shad Ansari2cddc552018-06-26 20:34:27 +000044
45USER := $(shell echo $(USER))
Luca Pretee75aaa52018-04-13 12:19:12 -070046#
Shad Ansari01b0e652018-04-05 21:02:53 +000047########################################################################
48##
49##
Luca Prete08e6f802018-04-17 11:49:45 -070050## Install prerequisites
Shad Ansari01b0e652018-04-05 21:02:53 +000051##
52##
53HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
54SYSTEM ?= $(HOST_SYSTEM)
Luca Pretee75aaa52018-04-13 12:19:12 -070055
Shad Ansari01b0e652018-04-05 21:02:53 +000056CXX = g++
57CPPFLAGS += `pkg-config --cflags protobuf grpc`
58CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix
Shad Ansari2cddc552018-06-26 20:34:27 +000059#ifeq ($(SYSTEM),Darwin)
60#LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
61# -lgrpc++_reflection\
62# -ldl
63#else
64#LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
65# -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\
66# -ldl
67#endif
68LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc` -ldl
Luca Pretee75aaa52018-04-13 12:19:12 -070069
Luca Prete08e6f802018-04-17 11:49:45 -070070prereq:
nick6fa80732018-05-22 14:47:10 -040071 sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev unzip docker.io
72 sudo apt-get install -y build-essential autoconf libssl-dev gawk debhelper dh-systemd init-system-helpers
Luca Pretee75aaa52018-04-13 12:19:12 -070073
74 # Install GRPC plugins
75 rm -rf $(GRPC_DST)
76 git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST)
77 cd $(GRPC_DST) && git submodule update --init
78 make -C $(GRPC_DST)
79 sudo make -C $(GRPC_DST) install
80 # Install libprotobuf and protoc
Luca Prete08e6f802018-04-17 11:49:45 -070081 cd $(GRPC_DST)/third_party/protobuf && ./autogen.sh
82 cd $(GRPC_DST)/third_party/protobuf && ./configure
83 make -C $(GRPC_DST)/third_party/protobuf
84 sudo make -C $(GRPC_DST)/third_party/protobuf install
85 sudo ldconfig
Shad Ansari01b0e652018-04-05 21:02:53 +000086
Shad Ansaricb004c52018-05-30 18:07:23 +000087 # libunwind (needed by glog)
88 rm -rf /tmp/libunwind-1.2
89 wget http://download.savannah.nongnu.org/releases/libunwind/libunwind-1.2.tar.gz -P /tmp
90 cd /tmp && tar -xzvf libunwind-1.2.tar.gz
91 cd /tmp/libunwind-1.2 && ./configure
92 make -C /tmp/libunwind-1.2
93 sudo make -C /tmp/libunwind-1.2 install
94
95 # cmake (needed by glog)
96 sudo apt-get remove cmake cmake-data
97 sudo -E add-apt-repository -y ppa:george-edison55/cmake-3.x
98 sudo -E apt-get update
99 sudo apt-get install -y cmake
100
101 # glog
102 rm -rf /tmp/glog
103 git clone https://github.com/google/glog.git /tmp/glog
104 cd /tmp/glog && cmake -H. -Bbuild -G "Unix Makefiles" && cmake --build build && sudo cmake --build build --target install
105
Shad Ansari2cddc552018-06-26 20:34:27 +0000106docker:
107 echo $(USER)
108 sudo groupadd -f docker
109ifneq "$(USER)" ""
110 sudo usermod -aG docker $(USER)
111endif
112
Shad Ansari01b0e652018-04-05 21:02:53 +0000113########################################################################
114##
115##
Luca Pretee75aaa52018-04-13 12:19:12 -0700116## ONL
Shad Ansari01b0e652018-04-05 21:02:53 +0000117##
118##
119ONL_KERN_VER = $(ONL_KERN_VER_MAJOR).$(ONL_KERN_VER_MINOR)
120ONL_REPO = $(DEVICE)-onl
121ONL_DIR = $(BUILD_DIR)/$(ONL_REPO)
Shad Ansari01b0e652018-04-05 21:02:53 +0000122onl:
123 if [ ! -d "$(ONL_DIR)/OpenNetworkLinux" ]; then \
124 mkdir -p $(ONL_DIR); \
Luca Preteb7886282018-04-06 15:34:08 -0700125 git clone https://gerrit.opencord.org/$(ONL_REPO) $(ONL_DIR); \
Shad Ansari01b0e652018-04-05 21:02:53 +0000126 make -C $(ONL_DIR) $(DEVICE)-$(ONL_KERN_VER_MAJOR); \
127 fi;
128onl-force:
129 make -C $(ONL_DIR) $(DEVICE)-$(ONL_KERN_VER_MAJOR)
Shad Ansari01b0e652018-04-05 21:02:53 +0000130distclean-onl:
131 sudo rm -rf $(ONL_DIR)
132
133########################################################################
134##
135##
Luca Pretee75aaa52018-04-13 12:19:12 -0700136## BAL
Shad Ansari01b0e652018-04-05 21:02:53 +0000137##
138##
139BAL_ZIP = SW-BCM68620_$(subst .,_,$(BAL_VER)).zip
140SDK_ZIP = sdk-all-$(SDK_VER).tar.gz
141ACCTON_PATCH = ACCTON_BAL_$(BAL_VER)-V$(ACCTON_VER).patch
142OPENOLT_BAL_PATCH = OPENOLT_BAL_$(BAL_VER).patch
143BAL_DIR = $(BUILD_DIR)/$(DEVICE)-bal
144ONL_KERNDIR = $(PWD)/$(ONL_DIR)/OpenNetworkLinux/packages/base/amd64/kernels/kernel-$(ONL_KERN_VER_MAJOR)-x86-64-all/builds
145MAPLE_KERNDIR = $(BAL_DIR)/bcm68620_release/$(DEVICE)/kernels
146BCM_SDK = $(BAL_DIR)/bal_release/3rdparty/bcm-sdk
Shad Ansaricb004c52018-05-30 18:07:23 +0000147BALLIBDIR = $(BAL_DIR)/bal_release/build/core/src/apps/bal_api_dist_shared_lib
Shad Ansari01b0e652018-04-05 21:02:53 +0000148BALLIBNAME = bal_api_dist
149BAL_INC = -I$(BAL_DIR)/bal_release/src/common/os_abstraction \
150 -I$(BAL_DIR)/bal_release/src/common/os_abstraction/posix \
151 -I$(BAL_DIR)/bal_release/src/common/config \
152 -I$(BAL_DIR)/bal_release/src/core/platform \
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400153 -I$(BAL_DIR)/bal_release/src/core/main \
Shad Ansari01b0e652018-04-05 21:02:53 +0000154 -I$(BAL_DIR)/bal_release/src/common/include \
155 -I$(BAL_DIR)/bal_release/src/lib/libbalapi \
Shad Ansari01b0e652018-04-05 21:02:53 +0000156 -I$(BAL_DIR)/bal_release/src/balapiend \
157 -I$(BAL_DIR)/bal_release/src/common/dev_log \
158 -I$(BAL_DIR)/bal_release/src/common/bal_dist_utils \
159 -I$(BAL_DIR)/bal_release/src/lib/libtopology \
Shad Ansari01b0e652018-04-05 21:02:53 +0000160 -I$(BAL_DIR)/bal_release/src/lib/libcmdline \
161 -I$(BAL_DIR)/bal_release/src/lib/libutils \
Shad Ansaricb004c52018-05-30 18:07:23 +0000162 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/utils \
163 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/model \
164 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/api \
Shad Ansari01b0e652018-04-05 21:02:53 +0000165 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_reference/cli
Shad Ansaricb004c52018-05-30 18:07:23 +0000166# -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_customized/os_abstraction
167# -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_customized/os_abstraction/posix
168# -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/config
Shad Ansari01b0e652018-04-05 21:02:53 +0000169CXXFLAGS += $(BAL_INC) -I $(BAL_DIR)/lib/cmdline
Shad Ansaricb004c52018-05-30 18:07:23 +0000170CXXFLAGS += -DBCMOS_MSG_QUEUE_DOMAIN_SOCKET -DBCMOS_MSG_QUEUE_UDP_SOCKET -DBCMOS_MEM_CHECK -DBCMOS_SYS_UNITTEST
171
172sdk: onl
Shad Ansari01b0e652018-04-05 21:02:53 +0000173ifeq ("$(wildcard $(BAL_DIR))","")
174 mkdir $(BAL_DIR)
175 unzip download/$(BAL_ZIP) -d $(BAL_DIR)
176 cp download/$(SDK_ZIP) $(BCM_SDK)
177 chmod -R 744 $(BAL_DIR)
178 cat download/$(ACCTON_PATCH) | patch -p1 -d $(BAL_DIR)
179 mkdir -p $(MAPLE_KERNDIR)
180 ln -s $(ONL_KERNDIR)/linux-$(ONL_KERN_VER) $(MAPLE_KERNDIR)/linux-$(ONL_KERN_VER)
181 ln -s $(ONL_DIR)/OpenNetworkLinux/packages/base/any/kernels/archives/linux-$(ONL_KERN_VER).tar.xz $(MAPLE_KERNDIR)/linux-$(ONL_KERN_VER).tar.xz
182 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
183 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk_dir
184 cat download/$(OPENOLT_BAL_PATCH) | patch -p1 -d $(BAL_DIR)
185 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk
186 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk_dir
187 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk
188 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
189 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) bal
Shad Ansaricb004c52018-05-30 18:07:23 +0000190 echo 'auto_create_interface_tm=y' >> $(BAL_DIR)/bal_release/3rdparty/maple/cur/$(DEVICE)/board_files/broadcom/bal_config.ini
Shad Ansari01b0e652018-04-05 21:02:53 +0000191 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) release_board
Shad Ansari01b0e652018-04-05 21:02:53 +0000192endif
Shad Ansaricb004c52018-05-30 18:07:23 +0000193
194bal: sdk
Shad Ansari01b0e652018-04-05 21:02:53 +0000195 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) bal
Shad Ansaricb004c52018-05-30 18:07:23 +0000196 echo 'auto_create_interface_tm=y' >> $(BAL_DIR)/bal_release/3rdparty/maple/cur/asfvolt16/board_files/broadcom/bal_config.ini
Shad Ansari01b0e652018-04-05 21:02:53 +0000197 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) release_board
Shad Ansaricb004c52018-05-30 18:07:23 +0000198
199bal-clean:
200 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) clean_bal
Shad Ansari01b0e652018-04-05 21:02:53 +0000201
202########################################################################
203##
204##
Luca Pretee75aaa52018-04-13 12:19:12 -0700205## OpenOLT API
Shad Ansari01b0e652018-04-05 21:02:53 +0000206##
207##
Shad Ansari19249582018-04-30 04:31:00 +0000208OPENOLT_PROTOS_DIR = ./protos
209OPENOLT_API_LIB = $(OPENOLT_PROTOS_DIR)/libopenoltapi.a
210CXXFLAGS += -I./$(OPENOLT_PROTOS_DIR) -I $(OPENOLT_PROTOS_DIR)/googleapis/gens
Shad Ansari19249582018-04-30 04:31:00 +0000211protos:
212 make -C $(OPENOLT_PROTOS_DIR) all
Shad Ansaricc01de12018-05-21 22:54:45 +0000213protos-clean:
Shad Ansari19249582018-04-30 04:31:00 +0000214 -make -C $(OPENOLT_PROTOS_DIR) clean
Shad Ansari01b0e652018-04-05 21:02:53 +0000215
216########################################################################
217##
218##
Luca Pretee75aaa52018-04-13 12:19:12 -0700219## Main
Shad Ansari01b0e652018-04-05 21:02:53 +0000220##
221##
222SRCS = $(wildcard src/*.cc)
223OBJS = $(SRCS:.cc=.o)
224DEPS = $(SRCS:.cc=.d)
225.DEFAULT_GOAL := all
226all: $(BUILD_DIR)/openolt
Shad Ansaricb004c52018-05-30 18:07:23 +0000227$(BUILD_DIR)/openolt: sdk protos $(OBJS)
Shad Ansari2cddc552018-06-26 20:34:27 +0000228 $(CXX) $(OBJS) $(OPENOLT_API_LIB) -o $@ -L$(BALLIBDIR) -l$(BALLIBNAME) $(LDFLAGS)
Shad Ansaricb004c52018-05-30 18:07:23 +0000229 ln -sf $(PWD)/$(BAL_DIR)/bcm68620_release/$(DEVICE)/release/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz $(BUILD_DIR)/.
230 ln -sf $(PWD)/$(BAL_DIR)/bcm68620_release/$(DEVICE)/release/broadcom/libbal_api_dist.so $(BUILD_DIR)/.
231 ln -sf $(PWD)/$(BAL_DIR)/bal_release/build/core/src/apps/bal_core_dist/bal_core_dist $(BUILD_DIR)/.
Shad Ansari2cb6e862018-05-04 03:57:42 +0000232 ln -sf $(shell ldconfig -p | grep libgrpc.so.6 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc.so.6
233 ln -sf $(shell ldconfig -p | grep libgrpc++.so.1 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc++.so.1
234 ln -sf $(shell ldconfig -p | grep libgrpc++_reflection.so.1 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc++_reflection.so.1
Shad Ansari01b0e652018-04-05 21:02:53 +0000235
Shad Ansari6cd46a62018-05-13 23:20:51 +0000236deb:
Shad Ansaricb004c52018-05-30 18:07:23 +0000237 cp $(BUILD_DIR)/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz mkdebian/debian
Shad Ansari9fb007d2018-05-14 18:31:38 +0000238 cp $(BUILD_DIR)/openolt mkdebian/debian
239 cp $(BUILD_DIR)/libgrpc.so.6 mkdebian/debian
240 cp $(BUILD_DIR)/libgrpc++.so.1 mkdebian/debian
241 cp $(BUILD_DIR)/libgrpc++_reflection.so.1 mkdebian/debian
Shad Ansaricb004c52018-05-30 18:07:23 +0000242 cd mkdebian && ./build_$(DEVICE)_deb.sh
Shad Ansari6cd46a62018-05-13 23:20:51 +0000243 mv *.deb $(BUILD_DIR)/openolt.deb
Shad Ansaricb004c52018-05-30 18:07:23 +0000244 make deb-cleanup
Shad Ansari6cd46a62018-05-13 23:20:51 +0000245
Shad Ansari01b0e652018-04-05 21:02:53 +0000246src/%.o: %.cpp
247 $(CXX) -MMD -c $< -o $@
248
Shad Ansaricb004c52018-05-30 18:07:23 +0000249deb-cleanup:
250 rm -f mkdebian/debian/$(DEVICE).debhelper.log
251 rm -f mkdebian/debian/$(DEVICE).postinst.debhelper
252 rm -f mkdebian/debian/$(DEVICE).postrm.debhelper
253 rm -f mkdebian/debian/$(DEVICE).substvars
254 rm -rf mkdebian/debian/$(DEVICE)/
Shad Ansaricc01de12018-05-21 22:54:45 +0000255 rm -f mkdebian/debian/libgrpc++.so.1
256 rm -f mkdebian/debian/libgrpc++_reflection.so.1
257 rm -f mkdebian/debian/libgrpc.so.6
258 rm -f mkdebian/debian/openolt
Shad Ansaricb004c52018-05-30 18:07:23 +0000259 rm -f mkdebian/debian/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz
Shad Ansaricc01de12018-05-21 22:54:45 +0000260 rm -rf mkdebian/debian/tmp/
Shad Ansaricb004c52018-05-30 18:07:23 +0000261 rm -f $(DEVICE)_$(BAL_VER)+edgecore-V$(ACCTON_VER)_amd64.changes
Shad Ansaricc01de12018-05-21 22:54:45 +0000262
Shad Ansaricb004c52018-05-30 18:07:23 +0000263clean: protos-clean deb-cleanup
Shad Ansari19249582018-04-30 04:31:00 +0000264 rm -f $(OBJS) $(DEPS)
Shad Ansaricb004c52018-05-30 18:07:23 +0000265 rm -rf protos/googleapis
Shad Ansaria0eeec52018-04-18 22:05:38 +0000266 rm -f $(BUILD_DIR)/libgrpc.so.6 $(BUILD_DIR)/libgrpc++.so.1 $(BUILD_DIR)/libgrpc++_reflection.so.1
Shad Ansaricb004c52018-05-30 18:07:23 +0000267 rm -f $(BUILD_DIR)/libbal_api_dist.so
268 rm -f $(BUILD_DIR)/openolt
269 rm -f $(BUILD_DIR)/bal_core_dist
270 rm -f $(BUILD_DIR)/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz
271 rm -f $(BUILD_DIR)/openolt.deb
Shad Ansari19249582018-04-30 04:31:00 +0000272
273distclean:
Shad Ansari01b0e652018-04-05 21:02:53 +0000274 rm -rf $(BUILD_DIR)
Shad Ansaricb004c52018-05-30 18:07:23 +0000275
276.PHONY: onl sdk bal protos prereq