blob: 7915e27135a24f4f157318a3203161dce5b23c74 [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##
Craig Lutgen88a22ad2018-10-04 12:30:46 -050022DEVICE ?= generic
23
Shad Ansari01b0e652018-04-05 21:02:53 +000024#
25# Three vendor proprietary source files are required to build BAL.
26# SW-BCM68620_<VER>.zip - Broadcom BAL source and Maple SDK.
27# sdk-all-<SDK_VER>.tar.gz - Broadcom Qumran SDK.
Craig Lutgenf040dba2018-09-27 11:21:43 -050028# ACCTON_BAL_<BAL_VER>-<DEV_VER>.patch - Accton/Edgecore's patch.
Shad Ansaricb004c52018-05-30 18:07:23 +000029BAL_MAJOR_VER = 02.06
30BAL_VER = 2.6.0.1
Shad Ansari01b0e652018-04-05 21:02:53 +000031SDK_VER = 6.5.7
Craig Lutgenf040dba2018-09-27 11:21:43 -050032DEV_VER ?= 201804301043
Shad Ansari01b0e652018-04-05 21:02:53 +000033#
34# Version of Open Network Linux (ONL).
35ONL_KERN_VER_MAJOR = 3.7
36ONL_KERN_VER_MINOR = 10
37#
38# Build directory
39BUILD_DIR = build
Luca Pretee75aaa52018-04-13 12:19:12 -070040#
41# GRPC installation
42GRPC_ADDR = https://github.com/grpc/grpc
43GRPC_DST = /tmp/grpc
44GRPC_VER = v1.10.x
Shad Ansari2cddc552018-06-26 20:34:27 +000045
46USER := $(shell echo $(USER))
Luca Pretee75aaa52018-04-13 12:19:12 -070047#
Shad Ansari01b0e652018-04-05 21:02:53 +000048########################################################################
49##
50##
Luca Prete08e6f802018-04-17 11:49:45 -070051## Install prerequisites
Shad Ansari01b0e652018-04-05 21:02:53 +000052##
53##
54HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
55SYSTEM ?= $(HOST_SYSTEM)
Luca Pretee75aaa52018-04-13 12:19:12 -070056
Craig Lutgenf040dba2018-09-27 11:21:43 -050057LIBGRPC_PATH=$(shell pkg-config --libs-only-L grpc | sed s/-L// | sed s/\ //g)
58LIBPROTOBUF_PATH=$(shell PKG_CONFIG_ALLOW_SYSTEM_LIBS=true pkg-config --libs-only-L protobuf | sed s/-L// | sed s/\ //g)
59
60CXX = @CXX@
61CXXFLAGS += @CXXFLAGS@
62CXXFLAGS += $(shell pkg-config --cflags-only-I grpc++)
Shad Ansari01b0e652018-04-05 21:02:53 +000063CPPFLAGS += `pkg-config --cflags protobuf grpc`
64CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix
Craig Lutgenf040dba2018-09-27 11:21:43 -050065LDFLAGS += @LDFLAGS@
66LDFLAGS += `pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr
Craig Lutgen88a22ad2018-10-04 12:30:46 -050067CXXFLAGSDEVICE = -I./device -I./device/$(DEVICE) -I./device/generic
Craig Lutgenf040dba2018-09-27 11:21:43 -050068
69export CXX CXXFLAGS
Luca Pretee75aaa52018-04-13 12:19:12 -070070
Luca Prete08e6f802018-04-17 11:49:45 -070071prereq:
nick6fa80732018-05-22 14:47:10 -040072 sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev unzip docker.io
73 sudo apt-get install -y build-essential autoconf libssl-dev gawk debhelper dh-systemd init-system-helpers
Luca Pretee75aaa52018-04-13 12:19:12 -070074
Shad Ansari563ea822018-06-28 14:56:27 +000075 # Install GRPC, libprotobuf and protoc
Luca Pretee75aaa52018-04-13 12:19:12 -070076 rm -rf $(GRPC_DST)
77 git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST)
78 cd $(GRPC_DST) && git submodule update --init
Shad Ansari563ea822018-06-28 14:56:27 +000079 cd $(GRPC_DST)/third_party/protobuf && ./autogen.sh && ./configure
Luca Prete08e6f802018-04-17 11:49:45 -070080 make -C $(GRPC_DST)/third_party/protobuf
81 sudo make -C $(GRPC_DST)/third_party/protobuf install
82 sudo ldconfig
Shad Ansari563ea822018-06-28 14:56:27 +000083 make -C $(GRPC_DST)
84 sudo make -C $(GRPC_DST) install
85 sudo ldconfig
Shad Ansaricb004c52018-05-30 18:07:23 +000086
Shad Ansari2cddc552018-06-26 20:34:27 +000087docker:
88 echo $(USER)
89 sudo groupadd -f docker
90ifneq "$(USER)" ""
91 sudo usermod -aG docker $(USER)
92endif
93
Shad Ansari01b0e652018-04-05 21:02:53 +000094########################################################################
95##
96##
Luca Pretee75aaa52018-04-13 12:19:12 -070097## ONL
Shad Ansari01b0e652018-04-05 21:02:53 +000098##
99##
100ONL_KERN_VER = $(ONL_KERN_VER_MAJOR).$(ONL_KERN_VER_MINOR)
101ONL_REPO = $(DEVICE)-onl
102ONL_DIR = $(BUILD_DIR)/$(ONL_REPO)
Shad Ansari01b0e652018-04-05 21:02:53 +0000103onl:
104 if [ ! -d "$(ONL_DIR)/OpenNetworkLinux" ]; then \
105 mkdir -p $(ONL_DIR); \
Luca Preteb7886282018-04-06 15:34:08 -0700106 git clone https://gerrit.opencord.org/$(ONL_REPO) $(ONL_DIR); \
Shad Ansari01b0e652018-04-05 21:02:53 +0000107 make -C $(ONL_DIR) $(DEVICE)-$(ONL_KERN_VER_MAJOR); \
108 fi;
109onl-force:
110 make -C $(ONL_DIR) $(DEVICE)-$(ONL_KERN_VER_MAJOR)
Shad Ansari01b0e652018-04-05 21:02:53 +0000111distclean-onl:
112 sudo rm -rf $(ONL_DIR)
113
114########################################################################
115##
116##
Luca Pretee75aaa52018-04-13 12:19:12 -0700117## BAL
Shad Ansari01b0e652018-04-05 21:02:53 +0000118##
119##
120BAL_ZIP = SW-BCM68620_$(subst .,_,$(BAL_VER)).zip
121SDK_ZIP = sdk-all-$(SDK_VER).tar.gz
Craig Lutgenf040dba2018-09-27 11:21:43 -0500122ACCTON_PATCH = ACCTON_BAL_$(BAL_VER)-V$(DEV_VER).patch
Shad Ansari01b0e652018-04-05 21:02:53 +0000123OPENOLT_BAL_PATCH = OPENOLT_BAL_$(BAL_VER).patch
124BAL_DIR = $(BUILD_DIR)/$(DEVICE)-bal
125ONL_KERNDIR = $(PWD)/$(ONL_DIR)/OpenNetworkLinux/packages/base/amd64/kernels/kernel-$(ONL_KERN_VER_MAJOR)-x86-64-all/builds
126MAPLE_KERNDIR = $(BAL_DIR)/bcm68620_release/$(DEVICE)/kernels
127BCM_SDK = $(BAL_DIR)/bal_release/3rdparty/bcm-sdk
Shad Ansaricb004c52018-05-30 18:07:23 +0000128BALLIBDIR = $(BAL_DIR)/bal_release/build/core/src/apps/bal_api_dist_shared_lib
Shad Ansari01b0e652018-04-05 21:02:53 +0000129BALLIBNAME = bal_api_dist
130BAL_INC = -I$(BAL_DIR)/bal_release/src/common/os_abstraction \
131 -I$(BAL_DIR)/bal_release/src/common/os_abstraction/posix \
132 -I$(BAL_DIR)/bal_release/src/common/config \
133 -I$(BAL_DIR)/bal_release/src/core/platform \
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400134 -I$(BAL_DIR)/bal_release/src/core/main \
Shad Ansari01b0e652018-04-05 21:02:53 +0000135 -I$(BAL_DIR)/bal_release/src/common/include \
136 -I$(BAL_DIR)/bal_release/src/lib/libbalapi \
Shad Ansari01b0e652018-04-05 21:02:53 +0000137 -I$(BAL_DIR)/bal_release/src/balapiend \
138 -I$(BAL_DIR)/bal_release/src/common/dev_log \
139 -I$(BAL_DIR)/bal_release/src/common/bal_dist_utils \
140 -I$(BAL_DIR)/bal_release/src/lib/libtopology \
Shad Ansari01b0e652018-04-05 21:02:53 +0000141 -I$(BAL_DIR)/bal_release/src/lib/libcmdline \
142 -I$(BAL_DIR)/bal_release/src/lib/libutils \
Shad Ansaricb004c52018-05-30 18:07:23 +0000143 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/utils \
144 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/model \
145 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/api \
Shad Ansari01b0e652018-04-05 21:02:53 +0000146 -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_reference/cli
147CXXFLAGS += $(BAL_INC) -I $(BAL_DIR)/lib/cmdline
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400148CXXFLAGS += -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 +0000149
150sdk: onl
Shad Ansari01b0e652018-04-05 21:02:53 +0000151ifeq ("$(wildcard $(BAL_DIR))","")
152 mkdir $(BAL_DIR)
153 unzip download/$(BAL_ZIP) -d $(BAL_DIR)
154 cp download/$(SDK_ZIP) $(BCM_SDK)
155 chmod -R 744 $(BAL_DIR)
156 cat download/$(ACCTON_PATCH) | patch -p1 -d $(BAL_DIR)
157 mkdir -p $(MAPLE_KERNDIR)
158 ln -s $(ONL_KERNDIR)/linux-$(ONL_KERN_VER) $(MAPLE_KERNDIR)/linux-$(ONL_KERN_VER)
159 ln -s $(ONL_DIR)/OpenNetworkLinux/packages/base/any/kernels/archives/linux-$(ONL_KERN_VER).tar.xz $(MAPLE_KERNDIR)/linux-$(ONL_KERN_VER).tar.xz
160 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
161 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk_dir
162 cat download/$(OPENOLT_BAL_PATCH) | patch -p1 -d $(BAL_DIR)
163 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk
164 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk_dir
165 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk
166 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
167 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) bal
Shad Ansaricb004c52018-05-30 18:07:23 +0000168 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 +0000169 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) release_board
Shad Ansari01b0e652018-04-05 21:02:53 +0000170endif
Shad Ansaricb004c52018-05-30 18:07:23 +0000171
172bal: sdk
Shad Ansari01b0e652018-04-05 21:02:53 +0000173 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) bal
Shad Ansaricb004c52018-05-30 18:07:23 +0000174 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 +0000175 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) release_board
Shad Ansaricb004c52018-05-30 18:07:23 +0000176
177bal-clean:
178 make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) clean_bal
Shad Ansari01b0e652018-04-05 21:02:53 +0000179
180########################################################################
181##
182##
Luca Pretee75aaa52018-04-13 12:19:12 -0700183## OpenOLT API
Shad Ansari01b0e652018-04-05 21:02:53 +0000184##
185##
Shad Ansari19249582018-04-30 04:31:00 +0000186OPENOLT_PROTOS_DIR = ./protos
187OPENOLT_API_LIB = $(OPENOLT_PROTOS_DIR)/libopenoltapi.a
Shad Ansari627b5782018-08-13 22:49:32 +0000188CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens
Shad Ansari19249582018-04-30 04:31:00 +0000189protos:
190 make -C $(OPENOLT_PROTOS_DIR) all
Shad Ansaricc01de12018-05-21 22:54:45 +0000191protos-clean:
Shad Ansari19249582018-04-30 04:31:00 +0000192 -make -C $(OPENOLT_PROTOS_DIR) clean
Shad Ansari01b0e652018-04-05 21:02:53 +0000193
194########################################################################
195##
196##
Shad Ansari627b5782018-08-13 22:49:32 +0000197## common
Shad Ansari7193ae22018-08-08 22:23:18 +0000198##
199##
Shad Ansari627b5782018-08-13 22:49:32 +0000200common/%.o: common/%.cc
201 $(CXX) $(CXXFLAGS) -I./common -c $< -o $@
Shad Ansari7193ae22018-08-08 22:23:18 +0000202
203########################################################################
204##
205##
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500206## device
207##
208##
209device/$(DEVICE)/%.o: device/$(DEVICE)/%.cc
210 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -c $< -o $@
211
212device/generic/%.o: device/generic/%.cc
213 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -c $< -o $@
214
215########################################################################
216##
217##
Shad Ansari627b5782018-08-13 22:49:32 +0000218## sim
Shad Ansari01b0e652018-04-05 21:02:53 +0000219##
220##
Shad Ansari627b5782018-08-13 22:49:32 +0000221SIM_SRCS = $(wildcard sim/*.cc) $(wildcard common/*.cc)
222SIM_OBJS = $(SIM_SRCS:.cc=.o)
223SIM_DEPS = $(SIM_SRCS:.cc=.d)
224sim: sim/openoltsim
225sim/openoltsim: protos $(SIM_OBJS)
226 $(CXX) -pthread -L/usr/local/lib $(SIM_OBJS) $(OPENOLT_API_LIB) /usr/local/lib/libprotobuf.a -o $@ -lgrpc++ -lgrpc -lpthread -ldl
227sim/%.o: sim/%.cc
228 $(CXX) -std=c++11 -fpermissive -Wno-literal-suffix -I./common -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens -c $< -o $@
229clean-sim:
230 rm -f sim/openoltsim $(SIM_OBJS) $(SIM_DEPS)
231
232########################################################################
233##
234##
235## openolt
236##
237##
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500238SRCS = $(wildcard src/*.cc) $(wildcard common/*.cc) $(wildcard device/$(DEVICE)/*.cc)
Shad Ansari01b0e652018-04-05 21:02:53 +0000239OBJS = $(SRCS:.cc=.o)
240DEPS = $(SRCS:.cc=.d)
241.DEFAULT_GOAL := all
242all: $(BUILD_DIR)/openolt
Shad Ansaricb004c52018-05-30 18:07:23 +0000243$(BUILD_DIR)/openolt: sdk protos $(OBJS)
Shad Ansari06a13322018-09-29 01:55:33 +0000244 $(CXX) $(LDFLAGS) -L$(BALLIBDIR) $(OBJS) $(OPENOLT_API_LIB) $(LIBPROTOBUF_PATH)/libprotobuf.a -o $@ -l$(BALLIBNAME) $(shell pkg-config --libs protobuf grpc++ grpc)
Craig Lutgenf040dba2018-09-27 11:21:43 -0500245 ln -sf $(PWD)/$(BAL_DIR)/bcm68620_release/$(DEVICE)/release/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(DEV_VER).tar.gz $(BUILD_DIR)/.
Shad Ansaricb004c52018-05-30 18:07:23 +0000246 ln -sf $(PWD)/$(BAL_DIR)/bcm68620_release/$(DEVICE)/release/broadcom/libbal_api_dist.so $(BUILD_DIR)/.
247 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 -0500248 ln -sf $(LIBGRPC_PATH)/libgrpc.so.6 $(BUILD_DIR)/libgrpc.so.6
249 ln -sf $(LIBGRPC_PATH)/libgrpc++.so.1 $(BUILD_DIR)/libgrpc++.so.1
Shad Ansari627b5782018-08-13 22:49:32 +0000250src/%.o: src/%.cc
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500251 $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I./common -c $< -o $@
Shad Ansari01b0e652018-04-05 21:02:53 +0000252
Shad Ansari6cd46a62018-05-13 23:20:51 +0000253deb:
Craig Lutgenf040dba2018-09-27 11:21:43 -0500254 cp $(BUILD_DIR)/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(DEV_VER).tar.gz mkdebian/debian
Shad Ansari9fb007d2018-05-14 18:31:38 +0000255 cp $(BUILD_DIR)/openolt mkdebian/debian
256 cp $(BUILD_DIR)/libgrpc.so.6 mkdebian/debian
257 cp $(BUILD_DIR)/libgrpc++.so.1 mkdebian/debian
Shad Ansarid0eaf752018-08-16 00:26:12 +0000258 cp -a scripts/init.d mkdebian/debian
Shad Ansaricb004c52018-05-30 18:07:23 +0000259 cd mkdebian && ./build_$(DEVICE)_deb.sh
Shad Ansari6cd46a62018-05-13 23:20:51 +0000260 mv *.deb $(BUILD_DIR)/openolt.deb
Shad Ansaricb004c52018-05-30 18:07:23 +0000261 make deb-cleanup
Shad Ansari6cd46a62018-05-13 23:20:51 +0000262
Shad Ansari01b0e652018-04-05 21:02:53 +0000263src/%.o: %.cpp
264 $(CXX) -MMD -c $< -o $@
265
Shad Ansaricb004c52018-05-30 18:07:23 +0000266deb-cleanup:
267 rm -f mkdebian/debian/$(DEVICE).debhelper.log
268 rm -f mkdebian/debian/$(DEVICE).postinst.debhelper
269 rm -f mkdebian/debian/$(DEVICE).postrm.debhelper
270 rm -f mkdebian/debian/$(DEVICE).substvars
271 rm -rf mkdebian/debian/$(DEVICE)/
Shad Ansaricc01de12018-05-21 22:54:45 +0000272 rm -f mkdebian/debian/libgrpc++.so.1
Shad Ansaricc01de12018-05-21 22:54:45 +0000273 rm -f mkdebian/debian/libgrpc.so.6
274 rm -f mkdebian/debian/openolt
Craig Lutgenf040dba2018-09-27 11:21:43 -0500275 rm -f mkdebian/debian/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(DEV_VER).tar.gz
Shad Ansaricc01de12018-05-21 22:54:45 +0000276 rm -rf mkdebian/debian/tmp/
Craig Lutgenf040dba2018-09-27 11:21:43 -0500277 rm -f $(DEVICE)_$(BAL_VER)+edgecore-V$(DEV_VER)_amd64.changes
Shad Ansaricc01de12018-05-21 22:54:45 +0000278
Shad Ansaricb004c52018-05-30 18:07:23 +0000279clean: protos-clean deb-cleanup
Shad Ansari19249582018-04-30 04:31:00 +0000280 rm -f $(OBJS) $(DEPS)
Shad Ansaricb004c52018-05-30 18:07:23 +0000281 rm -rf protos/googleapis
Shad Ansari563ea822018-06-28 14:56:27 +0000282 rm -f $(BUILD_DIR)/libgrpc.so.6 $(BUILD_DIR)/libgrpc++.so.1
Shad Ansaricb004c52018-05-30 18:07:23 +0000283 rm -f $(BUILD_DIR)/libbal_api_dist.so
284 rm -f $(BUILD_DIR)/openolt
285 rm -f $(BUILD_DIR)/bal_core_dist
Craig Lutgenf040dba2018-09-27 11:21:43 -0500286 rm -f $(BUILD_DIR)/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(DEV_VER).tar.gz
Shad Ansaricb004c52018-05-30 18:07:23 +0000287 rm -f $(BUILD_DIR)/openolt.deb
Shad Ansari19249582018-04-30 04:31:00 +0000288
289distclean:
Shad Ansari01b0e652018-04-05 21:02:53 +0000290 rm -rf $(BUILD_DIR)
Shad Ansaricb004c52018-05-30 18:07:23 +0000291
Shad Ansari627b5782018-08-13 22:49:32 +0000292.PHONY: onl sdk bal protos prereq sim