blob: 67ad5145993f7f2b8eff76affca8376218bd7970 [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##
Jason Huangaf7f6472019-05-04 03:19:07 +080022TOP_DIR=`pwd`
Shad Ansari9acc9732018-10-30 18:01:44 +000023OPENOLTDEVICE ?= generic
Craig Lutgen88a22ad2018-10-04 12:30:46 -050024
Shad Ansari01b0e652018-04-05 21:02:53 +000025#
26# Three vendor proprietary source files are required to build BAL.
27# SW-BCM68620_<VER>.zip - Broadcom BAL source and Maple SDK.
28# sdk-all-<SDK_VER>.tar.gz - Broadcom Qumran SDK.
Craig Lutgenf040dba2018-09-27 11:21:43 -050029# ACCTON_BAL_<BAL_VER>-<DEV_VER>.patch - Accton/Edgecore's patch.
Jason Huangaf7f6472019-05-04 03:19:07 +080030BAL_MAJOR_VER = 03.00
31BAL_VER = 3.0.3.3
32SDK_VER = 6.5.13
33DEV_VER ?= 201904171432
Shad Ansari01b0e652018-04-05 21:02:53 +000034#
35# Version of Open Network Linux (ONL).
Jason Huangaf7f6472019-05-04 03:19:07 +080036ONL_KERN_VER_MAJOR = 4.14
37ONL_KERN_VER_MINOR = 49
Shad Ansari01b0e652018-04-05 21:02:53 +000038#
39# Build directory
40BUILD_DIR = build
Luca Pretee75aaa52018-04-13 12:19:12 -070041#
42# GRPC installation
43GRPC_ADDR = https://github.com/grpc/grpc
44GRPC_DST = /tmp/grpc
45GRPC_VER = v1.10.x
Shad Ansari2cddc552018-06-26 20:34:27 +000046
47USER := $(shell echo $(USER))
Luca Pretee75aaa52018-04-13 12:19:12 -070048#
Shad Ansari01b0e652018-04-05 21:02:53 +000049########################################################################
50##
51##
Luca Prete08e6f802018-04-17 11:49:45 -070052## Install prerequisites
Shad Ansari01b0e652018-04-05 21:02:53 +000053##
54##
55HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
56SYSTEM ?= $(HOST_SYSTEM)
Luca Pretee75aaa52018-04-13 12:19:12 -070057
Craig Lutgenf040dba2018-09-27 11:21:43 -050058LIBGRPC_PATH=$(shell pkg-config --libs-only-L grpc | sed s/-L// | sed s/\ //g)
59LIBPROTOBUF_PATH=$(shell PKG_CONFIG_ALLOW_SYSTEM_LIBS=true pkg-config --libs-only-L protobuf | sed s/-L// | sed s/\ //g)
60
61CXX = @CXX@
62CXXFLAGS += @CXXFLAGS@
63CXXFLAGS += $(shell pkg-config --cflags-only-I grpc++)
Shad Ansari01b0e652018-04-05 21:02:53 +000064CPPFLAGS += `pkg-config --cflags protobuf grpc`
Craig Lutgen7ebee132018-11-16 15:31:11 -060065CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix
Craig Lutgenf040dba2018-09-27 11:21:43 -050066LDFLAGS += @LDFLAGS@
67LDFLAGS += `pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr
Shad Ansari9acc9732018-10-30 18:01:44 +000068CXXFLAGSDEVICE = -I./device -I./device/$(OPENOLTDEVICE) -I./device/generic
Craig Lutgenf040dba2018-09-27 11:21:43 -050069
70export CXX CXXFLAGS
Luca Pretee75aaa52018-04-13 12:19:12 -070071
Luca Prete08e6f802018-04-17 11:49:45 -070072prereq:
nick6fa80732018-05-22 14:47:10 -040073 sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev unzip docker.io
74 sudo apt-get install -y build-essential autoconf libssl-dev gawk debhelper dh-systemd init-system-helpers
Luca Pretee75aaa52018-04-13 12:19:12 -070075
Shad Ansari563ea822018-06-28 14:56:27 +000076 # Install GRPC, libprotobuf and protoc
Luca Pretee75aaa52018-04-13 12:19:12 -070077 rm -rf $(GRPC_DST)
78 git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST)
79 cd $(GRPC_DST) && git submodule update --init
Shad Ansari563ea822018-06-28 14:56:27 +000080 cd $(GRPC_DST)/third_party/protobuf && ./autogen.sh && ./configure
Luca Prete08e6f802018-04-17 11:49:45 -070081 make -C $(GRPC_DST)/third_party/protobuf
82 sudo make -C $(GRPC_DST)/third_party/protobuf install
83 sudo ldconfig
Shad Ansari563ea822018-06-28 14:56:27 +000084 make -C $(GRPC_DST)
85 sudo make -C $(GRPC_DST) install
86 sudo ldconfig
Shad Ansaricb004c52018-05-30 18:07:23 +000087
Shad Ansari2cddc552018-06-26 20:34:27 +000088docker:
89 echo $(USER)
90 sudo groupadd -f docker
91ifneq "$(USER)" ""
92 sudo usermod -aG docker $(USER)
93endif
94
Shad Ansari01b0e652018-04-05 21:02:53 +000095########################################################################
96##
97##
Luca Pretee75aaa52018-04-13 12:19:12 -070098## ONL
Shad Ansari01b0e652018-04-05 21:02:53 +000099##
100##
101ONL_KERN_VER = $(ONL_KERN_VER_MAJOR).$(ONL_KERN_VER_MINOR)
Shad Ansari9acc9732018-10-30 18:01:44 +0000102ONL_REPO = $(OPENOLTDEVICE)-onl
Shad Ansari01b0e652018-04-05 21:02:53 +0000103ONL_DIR = $(BUILD_DIR)/$(ONL_REPO)
Shad Ansari01b0e652018-04-05 21:02:53 +0000104onl:
105 if [ ! -d "$(ONL_DIR)/OpenNetworkLinux" ]; then \
106 mkdir -p $(ONL_DIR); \
Jason Huangaf7f6472019-05-04 03:19:07 +0800107 git clone https://github.com/opencomputeproject/OpenNetworkLinux.git $(ONL_DIR)/OpenNetworkLinux; \
108 cp download/Makefile.onl $(ONL_DIR)/Makefile; \
109 install -m 755 download/build-asfvolt16.sh $(ONL_DIR)/OpenNetworkLinux; \
Shad Ansari9acc9732018-10-30 18:01:44 +0000110 make -C $(ONL_DIR) $(OPENOLTDEVICE)-$(ONL_KERN_VER_MAJOR); \
Shad Ansari01b0e652018-04-05 21:02:53 +0000111 fi;
112onl-force:
Shad Ansari9acc9732018-10-30 18:01:44 +0000113 make -C $(ONL_DIR) $(OPENOLTDEVICE)-$(ONL_KERN_VER_MAJOR)
Shad Ansari01b0e652018-04-05 21:02:53 +0000114distclean-onl:
115 sudo rm -rf $(ONL_DIR)
116
117########################################################################
118##
119##
Luca Pretee75aaa52018-04-13 12:19:12 -0700120## BAL
Shad Ansari01b0e652018-04-05 21:02:53 +0000121##
122##
Jason Huangaf7f6472019-05-04 03:19:07 +0800123BAL_ZIP = SW-BCM68620_$(subst .,_,$(BAL_VER)).tgz
Shad Ansari01b0e652018-04-05 21:02:53 +0000124SDK_ZIP = sdk-all-$(SDK_VER).tar.gz
Craig Lutgenf040dba2018-09-27 11:21:43 -0500125ACCTON_PATCH = ACCTON_BAL_$(BAL_VER)-V$(DEV_VER).patch
Shad Ansari01b0e652018-04-05 21:02:53 +0000126OPENOLT_BAL_PATCH = OPENOLT_BAL_$(BAL_VER).patch
Shad Ansari9acc9732018-10-30 18:01:44 +0000127BAL_DIR = $(BUILD_DIR)/$(OPENOLTDEVICE)-bal
Jason Huangaf7f6472019-05-04 03:19:07 +0800128BCM_SDK = $(BAL_DIR)/switch_sdk/6.5.13
129BALLIBDIR = $(BAL_DIR)/build/asfvolt16-bal/build/lib/libbal_core.so
130BALLIBNAME = bal_core.so
Shad Ansari01b0e652018-04-05 21:02:53 +0000131BAL_INC = -I$(BAL_DIR)/bal_release/src/common/os_abstraction \
132 -I$(BAL_DIR)/bal_release/src/common/os_abstraction/posix \
133 -I$(BAL_DIR)/bal_release/src/common/config \
134 -I$(BAL_DIR)/bal_release/src/core/platform \
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400135 -I$(BAL_DIR)/bal_release/src/core/main \
Shad Ansari01b0e652018-04-05 21:02:53 +0000136 -I$(BAL_DIR)/bal_release/src/common/include \
137 -I$(BAL_DIR)/bal_release/src/lib/libbalapi \
Shad Ansari01b0e652018-04-05 21:02:53 +0000138 -I$(BAL_DIR)/bal_release/src/balapiend \
139 -I$(BAL_DIR)/bal_release/src/common/dev_log \
140 -I$(BAL_DIR)/bal_release/src/common/bal_dist_utils \
141 -I$(BAL_DIR)/bal_release/src/lib/libtopology \
Shad Ansari01b0e652018-04-05 21:02:53 +0000142 -I$(BAL_DIR)/bal_release/src/lib/libcmdline \
143 -I$(BAL_DIR)/bal_release/src/lib/libutils \
Shad Ansaricb004c52018-05-30 18:07:23 +0000144 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/utils \
145 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/model \
146 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/api \
Shad Ansari01b0e652018-04-05 21:02:53 +0000147 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_reference/cli
148CXXFLAGS += $(BAL_INC) -I $(BAL_DIR)/lib/cmdline
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400149CXXFLAGS += -DBCMOS_MSG_QUEUE_DOMAIN_SOCKET -DBCMOS_MSG_QUEUE_UDP_SOCKET -DBCMOS_MEM_CHECK -DBCMOS_SYS_UNITTEST -DENABLE_LOG
Shad Ansaricb004c52018-05-30 18:07:23 +0000150
151sdk: onl
Shad Ansari01b0e652018-04-05 21:02:53 +0000152ifeq ("$(wildcard $(BAL_DIR))","")
153 mkdir $(BAL_DIR)
Jason Huangaf7f6472019-05-04 03:19:07 +0800154 tar zxvf download/$(BAL_ZIP) --strip 1 -C $(BAL_DIR)
Shad Ansari01b0e652018-04-05 21:02:53 +0000155 cp download/$(SDK_ZIP) $(BCM_SDK)
156 chmod -R 744 $(BAL_DIR)
157 cat download/$(ACCTON_PATCH) | patch -p1 -d $(BAL_DIR)
Jason Huangaf7f6472019-05-04 03:19:07 +0800158 make -C $(BAL_DIR) BOARD=$(OPENOLTDEVICE) ONL_DIR=$(TOP_DIR)/$(ONL_DIR)/OpenNetworkLinux SW_UTIL_SHELL=y
159 echo 'auto_create_interface_tm=y' >> $(BAL_DIR)/build/fs/$(OPENOLTDEVICE)/board_files/broadcom/bal_config.ini
160 make -C $(BAL_DIR) BOARD=$(OPENOLTDEVICE) release_board
Shad Ansari01b0e652018-04-05 21:02:53 +0000161endif
Shad Ansaricb004c52018-05-30 18:07:23 +0000162
Jason Huangaf7f6472019-05-04 03:19:07 +0800163bal-release: sdk
164 echo 'auto_create_interface_tm=y' >> $(BAL_DIR)/build/fs/$(OPENOLTDEVICE)/board_files/broadcom/bal_config.ini
165 make -C $(BAL_DIR) BOARD=$(OPENOLTDEVICE) release_board
Shad Ansaricb004c52018-05-30 18:07:23 +0000166
167bal-clean:
Jason Huangaf7f6472019-05-04 03:19:07 +0800168 make -C $(BAL_DIR) BOARD=$(OPENOLTDEVICE) clean
Shad Ansari01b0e652018-04-05 21:02:53 +0000169
170########################################################################
171##
172##
Luca Pretee75aaa52018-04-13 12:19:12 -0700173## OpenOLT API
Shad Ansari01b0e652018-04-05 21:02:53 +0000174##
175##
Shad Ansari56c8ea42018-10-30 19:34:35 +0000176OPENOLT_PROTOS_DIR = ../protos
Shad Ansari19249582018-04-30 04:31:00 +0000177OPENOLT_API_LIB = $(OPENOLT_PROTOS_DIR)/libopenoltapi.a
Shad Ansari627b5782018-08-13 22:49:32 +0000178CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens
Shad Ansari19249582018-04-30 04:31:00 +0000179protos:
180 make -C $(OPENOLT_PROTOS_DIR) all
Shad Ansaricc01de12018-05-21 22:54:45 +0000181protos-clean:
Shad Ansari19249582018-04-30 04:31:00 +0000182 -make -C $(OPENOLT_PROTOS_DIR) clean
Shad Ansari01b0e652018-04-05 21:02:53 +0000183
184########################################################################
185##
186##
Shad Ansari627b5782018-08-13 22:49:32 +0000187## common
Shad Ansari7193ae22018-08-08 22:23:18 +0000188##
189##
Shad Ansari627b5782018-08-13 22:49:32 +0000190common/%.o: common/%.cc
191 $(CXX) $(CXXFLAGS) -I./common -c $< -o $@
Shad Ansari7193ae22018-08-08 22:23:18 +0000192
193########################################################################
194##
195##
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500196## device
197##
198##
Shad Ansari9acc9732018-10-30 18:01:44 +0000199device/$(OPENOLTDEVICE)/%.o: device/$(OPENOLTDEVICE)/%.cc
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500200 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -c $< -o $@
201
202device/generic/%.o: device/generic/%.cc
203 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -c $< -o $@
204
205########################################################################
206##
207##
Shad Ansari627b5782018-08-13 22:49:32 +0000208## sim
Shad Ansari01b0e652018-04-05 21:02:53 +0000209##
210##
Shad Ansari627b5782018-08-13 22:49:32 +0000211SIM_SRCS = $(wildcard sim/*.cc) $(wildcard common/*.cc)
212SIM_OBJS = $(SIM_SRCS:.cc=.o)
213SIM_DEPS = $(SIM_SRCS:.cc=.d)
214sim: sim/openoltsim
215sim/openoltsim: protos $(SIM_OBJS)
216 $(CXX) -pthread -L/usr/local/lib $(SIM_OBJS) $(OPENOLT_API_LIB) /usr/local/lib/libprotobuf.a -o $@ -lgrpc++ -lgrpc -lpthread -ldl
217sim/%.o: sim/%.cc
218 $(CXX) -std=c++11 -fpermissive -Wno-literal-suffix -I./common -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens -c $< -o $@
219clean-sim:
220 rm -f sim/openoltsim $(SIM_OBJS) $(SIM_DEPS)
221
222########################################################################
223##
224##
225## openolt
226##
227##
Shad Ansari9acc9732018-10-30 18:01:44 +0000228SRCS = $(wildcard src/*.cc) $(wildcard common/*.cc) $(wildcard device/$(OPENOLTDEVICE)/*.cc)
Shad Ansari01b0e652018-04-05 21:02:53 +0000229OBJS = $(SRCS:.cc=.o)
230DEPS = $(SRCS:.cc=.d)
231.DEFAULT_GOAL := all
Jason Huangaf7f6472019-05-04 03:19:07 +0800232#all: $(BUILD_DIR)/openolt
233all: notes onl sdk
234notes:
235 echo "\033[1;31m!!! The OpenOLT source codes is not yet support the BAL V3.0, so ignoring to build !!!\033[0m"
Shad Ansaricb004c52018-05-30 18:07:23 +0000236$(BUILD_DIR)/openolt: sdk protos $(OBJS)
Shad Ansari06a13322018-09-29 01:55:33 +0000237 $(CXX) $(LDFLAGS) -L$(BALLIBDIR) $(OBJS) $(OPENOLT_API_LIB) $(LIBPROTOBUF_PATH)/libprotobuf.a -o $@ -l$(BALLIBNAME) $(shell pkg-config --libs protobuf grpc++ grpc)
Shad Ansari9acc9732018-10-30 18:01:44 +0000238 ln -sf $(PWD)/$(BAL_DIR)/bcm68620_release/$(OPENOLTDEVICE)/release/release_$(OPENOLTDEVICE)_V$(BAL_MAJOR_VER).$(DEV_VER).tar.gz $(BUILD_DIR)/.
239 ln -sf $(PWD)/$(BAL_DIR)/bcm68620_release/$(OPENOLTDEVICE)/release/broadcom/libbal_api_dist.so $(BUILD_DIR)/.
Shad Ansaricb004c52018-05-30 18:07:23 +0000240 ln -sf $(PWD)/$(BAL_DIR)/bal_release/build/core/src/apps/bal_core_dist/bal_core_dist $(BUILD_DIR)/.
Craig Lutgenf040dba2018-09-27 11:21:43 -0500241 ln -sf $(LIBGRPC_PATH)/libgrpc.so.6 $(BUILD_DIR)/libgrpc.so.6
242 ln -sf $(LIBGRPC_PATH)/libgrpc++.so.1 $(BUILD_DIR)/libgrpc++.so.1
Shad Ansari627b5782018-08-13 22:49:32 +0000243src/%.o: src/%.cc
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500244 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I./common -c $< -o $@
Shad Ansari01b0e652018-04-05 21:02:53 +0000245
Shad Ansari6cd46a62018-05-13 23:20:51 +0000246deb:
Shad Ansari9acc9732018-10-30 18:01:44 +0000247 cp $(BUILD_DIR)/release_$(OPENOLTDEVICE)_V$(BAL_MAJOR_VER).$(DEV_VER).tar.gz mkdebian/debian
Shad Ansari9fb007d2018-05-14 18:31:38 +0000248 cp $(BUILD_DIR)/openolt mkdebian/debian
249 cp $(BUILD_DIR)/libgrpc.so.6 mkdebian/debian
250 cp $(BUILD_DIR)/libgrpc++.so.1 mkdebian/debian
Shad Ansarid0eaf752018-08-16 00:26:12 +0000251 cp -a scripts/init.d mkdebian/debian
Shad Ansari9acc9732018-10-30 18:01:44 +0000252 cd mkdebian && ./build_$(OPENOLTDEVICE)_deb.sh
Shad Ansari6cd46a62018-05-13 23:20:51 +0000253 mv *.deb $(BUILD_DIR)/openolt.deb
Shad Ansaricb004c52018-05-30 18:07:23 +0000254 make deb-cleanup
Shad Ansari6cd46a62018-05-13 23:20:51 +0000255
Shad Ansari01b0e652018-04-05 21:02:53 +0000256src/%.o: %.cpp
257 $(CXX) -MMD -c $< -o $@
258
Shad Ansaricb004c52018-05-30 18:07:23 +0000259deb-cleanup:
Shad Ansari9acc9732018-10-30 18:01:44 +0000260 rm -f mkdebian/debian/$(OPENOLTDEVICE).debhelper.log
261 rm -f mkdebian/debian/$(OPENOLTDEVICE).postinst.debhelper
262 rm -f mkdebian/debian/$(OPENOLTDEVICE).postrm.debhelper
263 rm -f mkdebian/debian/$(OPENOLTDEVICE).substvars
264 rm -rf mkdebian/debian/$(OPENOLTDEVICE)/
Shad Ansaricc01de12018-05-21 22:54:45 +0000265 rm -f mkdebian/debian/libgrpc++.so.1
Shad Ansaricc01de12018-05-21 22:54:45 +0000266 rm -f mkdebian/debian/libgrpc.so.6
267 rm -f mkdebian/debian/openolt
Shad Ansari9acc9732018-10-30 18:01:44 +0000268 rm -f mkdebian/debian/release_$(OPENOLTDEVICE)_V$(BAL_MAJOR_VER).$(DEV_VER).tar.gz
Shad Ansaricc01de12018-05-21 22:54:45 +0000269 rm -rf mkdebian/debian/tmp/
Shad Ansari9acc9732018-10-30 18:01:44 +0000270 rm -f $(OPENOLTDEVICE)_$(BAL_VER)+edgecore-V$(DEV_VER)_amd64.changes
Shad Ansaricc01de12018-05-21 22:54:45 +0000271
Shad Ansaricb004c52018-05-30 18:07:23 +0000272clean: protos-clean deb-cleanup
Shad Ansari19249582018-04-30 04:31:00 +0000273 rm -f $(OBJS) $(DEPS)
Craig Lutgen19512312018-11-02 10:14:46 -0500274 rm -rf $(OPENOLT_PROTOS_DIR)/googleapis
Shad Ansari563ea822018-06-28 14:56:27 +0000275 rm -f $(BUILD_DIR)/libgrpc.so.6 $(BUILD_DIR)/libgrpc++.so.1
Shad Ansaricb004c52018-05-30 18:07:23 +0000276 rm -f $(BUILD_DIR)/libbal_api_dist.so
277 rm -f $(BUILD_DIR)/openolt
278 rm -f $(BUILD_DIR)/bal_core_dist
Shad Ansari9acc9732018-10-30 18:01:44 +0000279 rm -f $(BUILD_DIR)/release_$(OPENOLTDEVICE)_V$(BAL_MAJOR_VER).$(DEV_VER).tar.gz
Shad Ansaricb004c52018-05-30 18:07:23 +0000280 rm -f $(BUILD_DIR)/openolt.deb
Shad Ansari19249582018-04-30 04:31:00 +0000281
282distclean:
Shad Ansari01b0e652018-04-05 21:02:53 +0000283 rm -rf $(BUILD_DIR)
Shad Ansaricb004c52018-05-30 18:07:23 +0000284
Shad Ansari627b5782018-08-13 22:49:32 +0000285.PHONY: onl sdk bal protos prereq sim