blob: cee6f34dbf3e2461c090f0eaa38a10fdc90ee3c2 [file] [log] [blame]
# Copyright (C) 2018 Open Networking Foundation
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
########################################################################
##
##
## Config
##
##
TOP_DIR=`pwd`
OPENOLTDEVICE ?= generic
#
# Three vendor proprietary source files are required to build BAL.
# SW-BCM68620_<VER>.zip - Broadcom BAL source and Maple SDK.
# sdk-all-<SDK_VER>.tar.gz - Broadcom Qumran SDK.
# ACCTON_BAL_<BAL_VER>-<DEV_VER>.patch - Accton/Edgecore's patch.
BAL_MAJOR_VER = 3
BAL_MINOR_VER = 1
BAL_REV_A_VER = 1
BAL_REV_B_VER = 1
BAL_API_VER = $(BAL_MAJOR_VER).$(BAL_MINOR_VER).$(BAL_REV_A_VER)
BAL_VER = $(BAL_MAJOR_VER).$(BAL_MINOR_VER).$(BAL_REV_A_VER).$(BAL_REV_B_VER)
SDK_VER = 6.5.13
DEV_VER ?= 201908010203
#
# Version of Open Network Linux (ONL).
ONL_KERN_VER_MAJOR = 4.14
# OpenOLT Proto version.
# This specifies the GIT tag in https://github.com/opencord/voltha-protos
# repo that we need to refer to, to pick the right version of
# openolt.proto and tech_profile.proto
OPENOLT_PROTO_VER ?= v1.0.3
#
# Build directory
BUILD_DIR = build
#
# GRPC installation
GRPC_ADDR = https://github.com/grpc/grpc
GRPC_DST = /tmp/grpc
GRPC_VER = v1.10.x
USER := $(shell echo $(USER))
#
########################################################################
##
##
## Install prerequisites
##
##
HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
SYSTEM ?= $(HOST_SYSTEM)
VERSION ?= $(shell cat ../VERSION)
#set ref and commit date only if committed
LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
LABEL_VCS_REF = $(shell git rev-parse HEAD)
LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
LIBGRPC_PATH=$(shell pkg-config --libs-only-L grpc | sed s/-L// | sed s/\ //g)
LIBPROTOBUF_PATH=$(shell PKG_CONFIG_ALLOW_SYSTEM_LIBS=true pkg-config --libs-only-L protobuf | sed s/-L// | sed s/\ //g)
CXX = @CXX@-4.9
CXXFLAGS += @CXXFLAGS@
CXXFLAGS += $(shell pkg-config --cflags-only-I grpc++)
CPPFLAGS += @CPPFLAGS@
CPPFLAGS += `pkg-config --cflags protobuf grpc`
CPPFLAGS += -DVERSION=\"$(VERSION)\" -DBAL_VER=\"$(BAL_VER)\" -DLABEL_VCS_URL=\"$(LABEL_VCS_URL)\" \
-DLABEL_VCS_REF=\"$(LABEL_VCS_REF)\" -DLABEL_BUILD_DATE=\"$(LABEL_BUILD_DATE)\" \
-DLABEL_COMMIT_DATE=\"$(LABEL_COMMIT_DATE)\"
CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix
LDFLAGS += @LDFLAGS@
LDFLAGS += `pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr
CXXFLAGSDEVICE = -I./device -I./device/$(OPENOLTDEVICE) -I./device/generic
export CXX CXXFLAGS OPENOLT_PROTO_VER
prereq:
sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev unzip docker.io
sudo apt-get install -y build-essential autoconf libssl-dev gawk debhelper dh-systemd init-system-helpers curl cmake ccache g++-4.9
# Install GRPC, libprotobuf and protoc
rm -rf $(GRPC_DST)
git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST)
cd $(GRPC_DST) && git submodule update --init
cd $(GRPC_DST)/third_party/protobuf && ./autogen.sh && ./configure
make -C $(GRPC_DST)/third_party/protobuf
sudo make -C $(GRPC_DST)/third_party/protobuf install
sudo ldconfig
make -C $(GRPC_DST)
sudo make -C $(GRPC_DST) install
sudo ldconfig
docker:
echo $(USER)
sudo groupadd -f docker
ifneq "$(USER)" ""
sudo usermod -aG docker $(USER)
endif
########################################################################
##
##
## ONL
##
##
ONL_REPO = onl
ONL_DIR = $(BUILD_DIR)/$(ONL_REPO)
onl:
if [ ! -d "$(ONL_DIR)/OpenNetworkLinux" ]; then \
mkdir -p $(ONL_DIR); \
git clone https://github.com/opencomputeproject/OpenNetworkLinux.git $(ONL_DIR)/OpenNetworkLinux; \
cp download/Makefile.onl $(ONL_DIR)/Makefile; \
install -m 755 download/build-onl.sh $(ONL_DIR)/OpenNetworkLinux; \
make -C $(ONL_DIR) onl-$(ONL_KERN_VER_MAJOR); \
fi;
onl-force:
make -C $(ONL_DIR) $(OPENOLTDEVICE)-$(ONL_KERN_VER_MAJOR)
distclean-onl:
sudo rm -rf $(ONL_DIR)
########################################################################
##
##
## Broadcom LIBRARY APIs
##
##
BAL_API_DIR = $(BUILD_DIR)/bal-api-$(BAL_API_VER)
bal-api-$(BAL_API_VER):
if [ ! -d "$(BAL_API_DIR)" ]; then \
mkdir -p $(BAL_API_DIR); \
git clone https://github.com/balapi/bal-api-$(BAL_API_VER).git $(BAL_API_DIR); \
fi;
bal-api-clean:
rm $(BAL_API_DIR)
########################################################################
##
##
## BAL
##
##
BAL_ZIP = SW-BCM68620_$(subst .,_,$(BAL_VER)).tgz
SDK_ZIP = sdk-all-$(SDK_VER).tar.gz
ACCTON_PATCH = ACCTON_BAL_$(BAL_VER)-V$(DEV_VER).patch
BAL_DIR = $(BUILD_DIR)/$(OPENOLTDEVICE)-bal
BCM_SDK = $(BAL_DIR)/switch_sdk/$(SDK_VER)
BALLIBDIR = $(BAL_DIR)/build/host_reference/host_api
BALLIBNAME = bal_host_api
BAL_INC = -I$(BAL_DIR)/host_driver/bal/bal_include \
-I$(BAL_DIR)/host_driver/topology \
-I$(BAL_DIR)/host_driver/utils \
-I$(BAL_DIR)/host_driver/api \
-I$(BAL_DIR)/host_customized/os_abstraction \
-I$(BAL_DIR)/host_customized/os_abstraction/posix \
-I$(BAL_DIR)/host_customized/config \
-I$(BAL_DIR)/host_driver/api_conn_mgr \
-I$(BAL_DIR)/host_driver/conn_mgr \
-I$(BAL_DIR)/host_driver/api/host/topology \
-I$(BAL_DIR)/host_reference/cli \
-I$(BAL_DIR)/host_reference/api_cli \
-I$(BAL_API_DIR)/include \
-I$(BAL_API_DIR)/include/object_model
CXXFLAGS += $(BAL_INC) -I $(BAL_DIR)/lib/cmdline
CXXFLAGS += -DBCMOS_MSG_QUEUE_DOMAIN_SOCKET -DBCMOS_MSG_QUEUE_UDP_SOCKET -DBCMOS_MEM_CHECK -DBCMOS_SYS_UNITTEST -DENABLE_LOG -DENABLE_CLI
sdk: onl bal-api-$(BAL_API_VER)
ifeq ("$(wildcard $(BAL_DIR))","")
mkdir $(BAL_DIR)
tar zxvf download/$(BAL_ZIP) --strip 1 -C $(BAL_DIR)
cp download/$(SDK_ZIP) $(BCM_SDK)
chmod -R 744 $(BAL_DIR)
cat download/$(ACCTON_PATCH) | patch -p1 -d $(BAL_DIR)
make -C $(BAL_DIR) BOARD=$(OPENOLTDEVICE) ONL_DIR=$(TOP_DIR)/$(ONL_DIR)/OpenNetworkLinux OPEN_SOURCE=y
make -C $(BAL_DIR) BOARD=$(OPENOLTDEVICE) release_board
endif
bal-release: sdk
make -C $(BAL_DIR) BOARD=$(OPENOLTDEVICE) release_board
bal-clean:
make -C $(BAL_DIR) BOARD=$(OPENOLTDEVICE) clean_all
########################################################################
##
##
## OpenOLT API
##
##
OPENOLT_PROTOS_DIR = ../protos
OPENOLT_API_LIB = $(OPENOLT_PROTOS_DIR)/libopenoltapi.a
CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens
protos:
make -C $(OPENOLT_PROTOS_DIR) all
protos-clean:
-make -C $(OPENOLT_PROTOS_DIR) clean
########################################################################
##
##
## common
##
##
common/%.o: common/%.cc
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -I./common -c $< -o $@
########################################################################
##
##
## device
##
##
device/$(OPENOLTDEVICE)/%.o: device/$(OPENOLTDEVICE)/%.cc
$(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -c $< -o $@
device/generic/%.o: device/generic/%.cc
$(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -c $< -o $@
########################################################################
##
##
## sim
##
##
SIM_SRCS = $(wildcard sim/*.cc) $(wildcard common/*.cc)
SIM_OBJS = $(SIM_SRCS:.cc=.o)
SIM_DEPS = $(SIM_SRCS:.cc=.d)
sim: sim/openoltsim
sim/openoltsim: protos $(SIM_OBJS)
$(CXX) -pthread -L/usr/local/lib $(SIM_OBJS) $(OPENOLT_API_LIB) /usr/local/lib/libprotobuf.a -o $@ -lgrpc++ -lgrpc -lpthread -ldl
sim/%.o: sim/%.cc
$(CXX) -std=c++11 -fpermissive -Wno-literal-suffix -I./common -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens -c $< -o $@
clean-sim:
rm -f sim/openoltsim $(SIM_OBJS) $(SIM_DEPS)
########################################################################
##
##
## openolt
##
##
SRCS = $(wildcard src/*.cc) $(wildcard common/*.cc) $(wildcard device/$(OPENOLTDEVICE)/*.cc)
OBJS = $(SRCS:.cc=.o)
DEPS = $(SRCS:.cc=.d)
.DEFAULT_GOAL := all
all: $(BUILD_DIR)/openolt
$(BUILD_DIR)/openolt: sdk protos $(OBJS)
$(CXX) $(LDFLAGS) -L$(BALLIBDIR) $(OBJS) $(OPENOLT_API_LIB) $(LIBPROTOBUF_PATH)/libprotobuf.a -o $@ -l$(BALLIBNAME) $(shell pkg-config --libs protobuf grpc++ grpc)
ln -sf $(TOP_DIR)/$(BAL_DIR)/build/fs/$(OPENOLTDEVICE)/release/release_$(OPENOLTDEVICE)_V$(BAL_MAJOR_VER).$(BAL_MINOR_VER).$(BAL_REV_A_VER).$(DEV_VER).tar.gz $(BUILD_DIR)/.
ln -sf $(TOP_DIR)/$(BAL_DIR)/build/host_reference/host_api/strip/libbal_host_api.so $(BUILD_DIR)/.
ln -sf $(TOP_DIR)/$(BAL_DIR)/build/host_driver/dev_mgmt_daemon/dev_mgmt_daemon $(BUILD_DIR)/.
ln -sf $(LIBGRPC_PATH)/libgrpc.so.6 $(BUILD_DIR)/libgrpc.so.6
ln -sf $(LIBGRPC_PATH)/libgrpc++.so.1 $(BUILD_DIR)/libgrpc++.so.1
ln -sf /usr/lib/x86_64-linux-gnu/libstdc++.so.6 $(BUILD_DIR)/libstdc++.so.6
strip $(BUILD_DIR)/openolt
src/%.o: src/%.cc
$(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) $(CPPFLAGS) -I./common -c $< -o $@
deb:
cp $(BUILD_DIR)/release_$(OPENOLTDEVICE)_V$(BAL_MAJOR_VER).$(BAL_MINOR_VER).$(BAL_REV_A_VER).$(DEV_VER).tar.gz device/$(OPENOLTDEVICE)/mkdebian/debian
cp $(BUILD_DIR)/openolt device/$(OPENOLTDEVICE)/mkdebian/debian
cp $(BUILD_DIR)/libgrpc.so.6 device/$(OPENOLTDEVICE)/mkdebian/debian
cp $(BUILD_DIR)/libgrpc++.so.1 device/$(OPENOLTDEVICE)/mkdebian/debian
cp $(BUILD_DIR)/libstdc++.so.6 device/$(OPENOLTDEVICE)/mkdebian/debian
cp $(BUILD_DIR)/libbal_host_api.so device/$(OPENOLTDEVICE)/mkdebian/debian
cp -a scripts/init.d device/$(OPENOLTDEVICE)/mkdebian/debian
cd device/$(OPENOLTDEVICE)/mkdebian && ./build_$(OPENOLTDEVICE)_deb.sh
mv device/$(OPENOLTDEVICE)/*.deb $(BUILD_DIR)/openolt_$(OPENOLTDEVICE).deb
make deb-cleanup
src/%.o: %.cpp
$(CXX) -MMD -c $< -o $@
deb-cleanup:
@rm -f device/$(OPENOLTDEVICE)/mkdebian/debian/$(OPENOLTDEVICE).debhelper.log
@rm -f device/$(OPENOLTDEVICE)/mkdebian/debian/$(OPENOLTDEVICE).postinst.debhelper
@rm -f device/$(OPENOLTDEVICE)/mkdebian/debian/$(OPENOLTDEVICE).postrm.debhelper
@rm -f device/$(OPENOLTDEVICE)/mkdebian/debian/$(OPENOLTDEVICE).substvars
@rm -rf device/$(OPENOLTDEVICE)/mkdebian/debian/$(OPENOLTDEVICE)/
@rm -f device/$(OPENOLTDEVICE)/mkdebian/debian/debhelper-build-stamp
@rm -f device/$(OPENOLTDEVICE)/mkdebian/debian/libgrpc++.so.1
@rm -f device/$(OPENOLTDEVICE)/mkdebian/debian/libgrpc.so.6
@rm -f device/$(OPENOLTDEVICE)/mkdebian/debian/libstdc++.so.6
@rm -f device/$(OPENOLTDEVICE)/mkdebian/debian/libbal_host_api.so
@rm -rf device/$(OPENOLTDEVICE)/mkdebian/debian/init.d/
@rm -f device/$(OPENOLTDEVICE)/mkdebian/debian/openolt
@rm -f device/$(OPENOLTDEVICE)/mkdebian/debian/release_$(OPENOLTDEVICE)_V$(BAL_MAJOR_VER).$(BAL_MINOR_VER).$(BAL_REV_A_VER).$(DEV_VER).tar.gz
@rm -rf device/$(OPENOLTDEVICE)/mkdebian/debian/tmp/
@rm -f device/$(OPENOLTDEVICE)/$(OPENOLTDEVICE)_$(BAL_VER)+edgecore-V$(DEV_VER)_amd64.changes
clean: protos-clean deb-cleanup
@rm -f $(OBJS) $(DEPS)
@rm -rf $(OPENOLT_PROTOS_DIR)/googleapis
@rm -f $(BUILD_DIR)/libgrpc.so.6 $(BUILD_DIR)/libgrpc++.so.1
@rm -f $(BUILD_DIR)/libbal_api_dist.so
@rm -f $(BUILD_DIR)/openolt
@rm -f $(BUILD_DIR)/bal_core_dist
@rm -f $(BUILD_DIR)/release_$(OPENOLTDEVICE)_V$(BAL_MAJOR_VER).$(DEV_VER).tar.gz
@rm -f $(BUILD_DIR)/openolt.deb
clean-src: protos-clean
@rm -f $(OBJS) $(DEPS)
distclean: clean-src clean
@rm -rf $(BUILD_DIR)
.PHONY: onl sdk bal protos prereq sim