Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 1 | # 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 | ## |
| 19 | ## Config |
| 20 | ## |
| 21 | ## |
| 22 | DEVICE = 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. |
| 28 | BAL_MAJOR_VER = 02.04 |
| 29 | BAL_VER = 2.4.3.6 |
| 30 | SDK_VER = 6.5.7 |
| 31 | ACCTON_VER = 201710131639 |
| 32 | # |
| 33 | # Version of Open Network Linux (ONL). |
| 34 | ONL_KERN_VER_MAJOR = 3.7 |
| 35 | ONL_KERN_VER_MINOR = 10 |
| 36 | # |
| 37 | # Build directory |
| 38 | BUILD_DIR = build |
| 39 | |
| 40 | ######################################################################## |
| 41 | ## |
| 42 | ## |
| 43 | ## Check |
| 44 | ## |
| 45 | ## |
| 46 | HOST_SYSTEM = $(shell uname | cut -f 1 -d_) |
| 47 | SYSTEM ?= $(HOST_SYSTEM) |
| 48 | CXX = g++ |
| 49 | CPPFLAGS += `pkg-config --cflags protobuf grpc` |
| 50 | CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix |
| 51 | ifeq ($(SYSTEM),Darwin) |
| 52 | LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\ |
| 53 | -lgrpc++_reflection\ |
| 54 | -ldl |
| 55 | else |
| 56 | LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\ |
| 57 | -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\ |
| 58 | -ldl |
| 59 | endif |
| 60 | PROTOC = protoc |
| 61 | GRPC_CPP_PLUGIN = grpc_cpp_plugin |
| 62 | GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)` |
| 63 | GRPC_CPP_VER ?= `command curl -L https://grpc.io/release` |
| 64 | PROTOC_CMD = which $(PROTOC) |
| 65 | PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3 |
| 66 | PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN) |
| 67 | HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false) |
| 68 | ifeq ($(HAS_PROTOC),true) |
| 69 | HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false) |
| 70 | endif |
| 71 | HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false) |
| 72 | check: |
| 73 | sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev |
| 74 | ifneq ($(HAS_VALID_PROTOC),true) |
| 75 | mkdir -p /tmp/$(PROTOC_NAME) |
| 76 | wget -P /tmp/$(PROTOC_NAME) $(PROTOC_DOWNLOAD_URL)/v$(PROTOC_VERSION)/$(PROTOC_NAME).zip |
| 77 | unzip -o /tmp/$(PROTOC_NAME)/$(PROTOC_NAME) -d /tmp/$(PROTOC_NAME) |
| 78 | mkdir -p $(PWD)/bin |
| 79 | cp -f /tmp/$(PROTOC_NAME)/bin/protoc $(PWD)/bin/. |
| 80 | mkdir -p $(PWD)/include |
| 81 | cp -rf /tmp/$(PROTOC_NAME)/include/* $(PWD)/include/. |
| 82 | rm -rf /tmp/$(PROTOC_NAME) |
| 83 | endif |
| 84 | ifneq ($(HAS_PLUGIN),true) |
| 85 | rm -rf /tmp/grpc |
| 86 | git clone -b $(GRPC_CPP_VER) https://github.com/grpc/grpc /tmp/grpc |
| 87 | cd /tmp/grpc && git submodule update --init |
| 88 | make -C /tmp/grpc |
| 89 | sudo make -C /tmp/grpc install |
| 90 | make -C /tmp/grpc/third_party/protobuf |
| 91 | sudo make -C /tmp/grpc/third_party/protobuf install |
| 92 | rm -rf /tmp/grpc |
| 93 | endif |
| 94 | |
| 95 | ######################################################################## |
| 96 | ## |
| 97 | ## |
| 98 | ## ONL |
| 99 | ## |
| 100 | ## |
| 101 | ONL_KERN_VER = $(ONL_KERN_VER_MAJOR).$(ONL_KERN_VER_MINOR) |
| 102 | ONL_REPO = $(DEVICE)-onl |
| 103 | ONL_DIR = $(BUILD_DIR)/$(ONL_REPO) |
| 104 | .PHONY: onl |
| 105 | onl: |
| 106 | if [ ! -d "$(ONL_DIR)/OpenNetworkLinux" ]; then \ |
| 107 | mkdir -p $(ONL_DIR); \ |
Luca Prete | b788628 | 2018-04-06 15:34:08 -0700 | [diff] [blame^] | 108 | git clone https://gerrit.opencord.org/$(ONL_REPO) $(ONL_DIR); \ |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 109 | make -C $(ONL_DIR) $(DEVICE)-$(ONL_KERN_VER_MAJOR); \ |
| 110 | fi; |
| 111 | onl-force: |
| 112 | make -C $(ONL_DIR) $(DEVICE)-$(ONL_KERN_VER_MAJOR) |
| 113 | clean-onl: |
| 114 | distclean-onl: |
| 115 | sudo rm -rf $(ONL_DIR) |
| 116 | |
| 117 | ######################################################################## |
| 118 | ## |
| 119 | ## |
| 120 | ## BAL |
| 121 | ## |
| 122 | ## |
| 123 | BAL_ZIP = SW-BCM68620_$(subst .,_,$(BAL_VER)).zip |
| 124 | SDK_ZIP = sdk-all-$(SDK_VER).tar.gz |
| 125 | ACCTON_PATCH = ACCTON_BAL_$(BAL_VER)-V$(ACCTON_VER).patch |
| 126 | OPENOLT_BAL_PATCH = OPENOLT_BAL_$(BAL_VER).patch |
| 127 | BAL_DIR = $(BUILD_DIR)/$(DEVICE)-bal |
| 128 | ONL_KERNDIR = $(PWD)/$(ONL_DIR)/OpenNetworkLinux/packages/base/amd64/kernels/kernel-$(ONL_KERN_VER_MAJOR)-x86-64-all/builds |
| 129 | MAPLE_KERNDIR = $(BAL_DIR)/bcm68620_release/$(DEVICE)/kernels |
| 130 | BCM_SDK = $(BAL_DIR)/bal_release/3rdparty/bcm-sdk |
| 131 | BALLIBDIR = $(BAL_DIR)/bal_release/build/core/lib |
| 132 | BALLIBNAME = bal_api_dist |
| 133 | BAL_INC = -I$(BAL_DIR)/bal_release/src/common/os_abstraction \ |
| 134 | -I$(BAL_DIR)/bal_release/src/common/os_abstraction/posix \ |
| 135 | -I$(BAL_DIR)/bal_release/src/common/config \ |
| 136 | -I$(BAL_DIR)/bal_release/src/core/platform \ |
| 137 | -I$(BAL_DIR)/bal_release/src/common/include \ |
| 138 | -I$(BAL_DIR)/bal_release/src/lib/libbalapi \ |
| 139 | -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/utils \ |
| 140 | -I$(BAL_DIR)/bal_release/src/balapiend \ |
| 141 | -I$(BAL_DIR)/bal_release/src/common/dev_log \ |
| 142 | -I$(BAL_DIR)/bal_release/src/common/bal_dist_utils \ |
| 143 | -I$(BAL_DIR)/bal_release/src/lib/libtopology \ |
| 144 | -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/model \ |
| 145 | -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/api \ |
| 146 | -I$(BAL_DIR)/bal_release/src/lib/libcmdline \ |
| 147 | -I$(BAL_DIR)/bal_release/src/lib/libutils \ |
| 148 | -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_reference/cli |
| 149 | CXXFLAGS += $(BAL_INC) -I $(BAL_DIR)/lib/cmdline |
| 150 | .PHONY: get-$(BAL_DIR) |
| 151 | get-$(BAL_DIR): |
| 152 | # if [ ! -e "download/$(BAL_ZIP)" ]; then \ |
| 153 | # rm -rf /tmp/broadcom-proprietary; \ |
| 154 | # git clone git@github.com:shadansari/broadcom-proprietary.git /tmp/broadcom-proprietary; \ |
| 155 | # mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(BAL_ZIP) ./download; \ |
| 156 | # mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(SDK_ZIP) ./download; \ |
| 157 | # mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(ACCTON_PATCH) ./download; \ |
| 158 | # mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(OPENOLT_BAL_PATCH) ./download; \ |
| 159 | # rm -rf /tmp/broadcom-proprietary; \ |
| 160 | # fi; |
| 161 | .PHONY: bal |
| 162 | bal: onl get-$(BAL_DIR) |
| 163 | ifeq ("$(wildcard $(BAL_DIR))","") |
| 164 | mkdir $(BAL_DIR) |
| 165 | unzip download/$(BAL_ZIP) -d $(BAL_DIR) |
| 166 | cp download/$(SDK_ZIP) $(BCM_SDK) |
| 167 | chmod -R 744 $(BAL_DIR) |
| 168 | cat download/$(ACCTON_PATCH) | patch -p1 -d $(BAL_DIR) |
| 169 | mkdir -p $(MAPLE_KERNDIR) |
| 170 | ln -s $(ONL_KERNDIR)/linux-$(ONL_KERN_VER) $(MAPLE_KERNDIR)/linux-$(ONL_KERN_VER) |
| 171 | ln -s $(ONL_DIR)/OpenNetworkLinux/packages/base/any/kernels/archives/linux-$(ONL_KERN_VER).tar.xz $(MAPLE_KERNDIR)/linux-$(ONL_KERN_VER).tar.xz |
| 172 | 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 |
| 173 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk_dir |
| 174 | cat download/$(OPENOLT_BAL_PATCH) | patch -p1 -d $(BAL_DIR) |
| 175 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk |
| 176 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk_dir |
| 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) |
| 187 | endif |
| 188 | bal-rebuild: |
| 189 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk |
| 190 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk |
| 191 | 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 |
| 192 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) bal |
| 193 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) release_board |
| 194 | ln -s -f $(PWD)/$(BAL_DIR)/bcm68620_release/asfvolt16/release/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz . |
| 195 | ln -s -f $(PWD)/$(BAL_DIR)/bal_release/build/core/lib/libbal_api_dist.so . |
| 196 | ln -s -f $(PWD)/$(BAL_DIR)/bal_release/build/core/src/apps/bal_core_dist/bal_core_dist . |
| 197 | mv -f release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz $(BUILD_DIR) |
| 198 | mv -f libbal_api_dist.so $(BUILD_DIR) |
| 199 | mv -f bal_core_dist $(BUILD_DIR) |
| 200 | clean-bal: clean-onl |
| 201 | distclean-bal: distclean-onl |
| 202 | sudo rm -rf $(BAL_DIR) |
| 203 | rm -f build/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz |
| 204 | |
| 205 | ######################################################################## |
| 206 | ## |
| 207 | ## |
| 208 | ## OpenOLT API |
| 209 | ## |
| 210 | ## |
| 211 | OPENOLT_API_DIR = $(BUILD_DIR)/openolt-api |
| 212 | OPENOLT_API_LIB = $(OPENOLT_API_DIR)/libopenoltapi.a |
| 213 | CXXFLAGS += -I./$(OPENOLT_API_DIR) -I $(OPENOLT_API_DIR)/googleapis/gens |
| 214 | .PHONY: openolt-api |
| 215 | openolt-api: |
| 216 | if [ ! -e "$(OPENOLT_API_DIR)" ]; then \ |
| 217 | mkdir -p $(BUILD_DIR); \ |
Luca Prete | b788628 | 2018-04-06 15:34:08 -0700 | [diff] [blame^] | 218 | git clone https://gerrit.opencord.org/openolt-api $(OPENOLT_API_DIR); \ |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 219 | fi; |
| 220 | make -C $(OPENOLT_API_DIR) all |
| 221 | clean-openolt-api: |
| 222 | -make -C $(OPENOLT_API_DIR) clean |
| 223 | distclean-openolt-api: |
| 224 | |
| 225 | ######################################################################## |
| 226 | ## |
| 227 | ## |
| 228 | ## Main |
| 229 | ## |
| 230 | ## |
| 231 | SRCS = $(wildcard src/*.cc) |
| 232 | OBJS = $(SRCS:.cc=.o) |
| 233 | DEPS = $(SRCS:.cc=.d) |
| 234 | .DEFAULT_GOAL := all |
| 235 | all: $(BUILD_DIR)/openolt |
| 236 | $(BUILD_DIR)/openolt: check openolt-api bal $(OBJS) |
| 237 | $(CXX) $(OBJS) $(LDFLAGS) $(OPENOLT_API_LIB) -o $@ -L$(BALLIBDIR) -l$(BALLIBNAME) |
| 238 | ln -s $(shell ldconfig -p | grep libgrpc.so.5 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc.so.5 |
| 239 | ln -s $(shell ldconfig -p | grep libgrpc++.so.1 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc++.so.1 |
| 240 | ln -s $(shell ldconfig -p | grep libgrpc++_reflection.so.1 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc++_reflection.so.1 |
| 241 | |
| 242 | src/%.o: %.cpp |
| 243 | $(CXX) -MMD -c $< -o $@ |
| 244 | |
| 245 | clean: clean-bal |
| 246 | rm -f $(OBJS) $(DEPS) $(BUILD_DIR)/openolt |
| 247 | rm -rf $(OPENOLT_API_DIR) |
| 248 | distclean: distclean-openolt-api distclean-bal |
| 249 | rm -rf $(BUILD_DIR) |
| 250 | -include $(DEPS) |