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); \ |
| 108 | git clone git@github.com:shadansari/$(ONL_REPO).git $(ONL_DIR); \ |
Shad Ansari | 7f794ce | 2018-04-06 15:08:53 -0700 | [diff] [blame^] | 109 | sed -i 's/onlbuilder/onlbuilder --non-interactive/g' $(ONL_DIR)/Makefile; \ |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 110 | make -C $(ONL_DIR) $(DEVICE)-$(ONL_KERN_VER_MAJOR); \ |
| 111 | fi; |
| 112 | onl-force: |
| 113 | make -C $(ONL_DIR) $(DEVICE)-$(ONL_KERN_VER_MAJOR) |
| 114 | clean-onl: |
| 115 | distclean-onl: |
| 116 | sudo rm -rf $(ONL_DIR) |
| 117 | |
| 118 | ######################################################################## |
| 119 | ## |
| 120 | ## |
| 121 | ## BAL |
| 122 | ## |
| 123 | ## |
| 124 | BAL_ZIP = SW-BCM68620_$(subst .,_,$(BAL_VER)).zip |
| 125 | SDK_ZIP = sdk-all-$(SDK_VER).tar.gz |
| 126 | ACCTON_PATCH = ACCTON_BAL_$(BAL_VER)-V$(ACCTON_VER).patch |
| 127 | OPENOLT_BAL_PATCH = OPENOLT_BAL_$(BAL_VER).patch |
| 128 | BAL_DIR = $(BUILD_DIR)/$(DEVICE)-bal |
| 129 | ONL_KERNDIR = $(PWD)/$(ONL_DIR)/OpenNetworkLinux/packages/base/amd64/kernels/kernel-$(ONL_KERN_VER_MAJOR)-x86-64-all/builds |
| 130 | MAPLE_KERNDIR = $(BAL_DIR)/bcm68620_release/$(DEVICE)/kernels |
| 131 | BCM_SDK = $(BAL_DIR)/bal_release/3rdparty/bcm-sdk |
| 132 | BALLIBDIR = $(BAL_DIR)/bal_release/build/core/lib |
| 133 | BALLIBNAME = bal_api_dist |
| 134 | BAL_INC = -I$(BAL_DIR)/bal_release/src/common/os_abstraction \ |
| 135 | -I$(BAL_DIR)/bal_release/src/common/os_abstraction/posix \ |
| 136 | -I$(BAL_DIR)/bal_release/src/common/config \ |
| 137 | -I$(BAL_DIR)/bal_release/src/core/platform \ |
| 138 | -I$(BAL_DIR)/bal_release/src/common/include \ |
| 139 | -I$(BAL_DIR)/bal_release/src/lib/libbalapi \ |
| 140 | -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/utils \ |
| 141 | -I$(BAL_DIR)/bal_release/src/balapiend \ |
| 142 | -I$(BAL_DIR)/bal_release/src/common/dev_log \ |
| 143 | -I$(BAL_DIR)/bal_release/src/common/bal_dist_utils \ |
| 144 | -I$(BAL_DIR)/bal_release/src/lib/libtopology \ |
| 145 | -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/model \ |
| 146 | -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_driver/api \ |
| 147 | -I$(BAL_DIR)/bal_release/src/lib/libcmdline \ |
| 148 | -I$(BAL_DIR)/bal_release/src/lib/libutils \ |
| 149 | -I$(BAL_DIR)/bal_release/3rdparty/maple/sdk/host_reference/cli |
| 150 | CXXFLAGS += $(BAL_INC) -I $(BAL_DIR)/lib/cmdline |
| 151 | .PHONY: get-$(BAL_DIR) |
| 152 | get-$(BAL_DIR): |
| 153 | # if [ ! -e "download/$(BAL_ZIP)" ]; then \ |
| 154 | # rm -rf /tmp/broadcom-proprietary; \ |
| 155 | # git clone git@github.com:shadansari/broadcom-proprietary.git /tmp/broadcom-proprietary; \ |
| 156 | # mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(BAL_ZIP) ./download; \ |
| 157 | # mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(SDK_ZIP) ./download; \ |
| 158 | # mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(ACCTON_PATCH) ./download; \ |
| 159 | # mv -f /tmp/broadcom-proprietary/$(BAL_VER)/$(OPENOLT_BAL_PATCH) ./download; \ |
| 160 | # rm -rf /tmp/broadcom-proprietary; \ |
| 161 | # fi; |
| 162 | .PHONY: bal |
| 163 | bal: onl get-$(BAL_DIR) |
| 164 | ifeq ("$(wildcard $(BAL_DIR))","") |
| 165 | mkdir $(BAL_DIR) |
| 166 | unzip download/$(BAL_ZIP) -d $(BAL_DIR) |
| 167 | cp download/$(SDK_ZIP) $(BCM_SDK) |
| 168 | chmod -R 744 $(BAL_DIR) |
| 169 | cat download/$(ACCTON_PATCH) | patch -p1 -d $(BAL_DIR) |
| 170 | mkdir -p $(MAPLE_KERNDIR) |
| 171 | ln -s $(ONL_KERNDIR)/linux-$(ONL_KERN_VER) $(MAPLE_KERNDIR)/linux-$(ONL_KERN_VER) |
| 172 | ln -s $(ONL_DIR)/OpenNetworkLinux/packages/base/any/kernels/archives/linux-$(ONL_KERN_VER).tar.xz $(MAPLE_KERNDIR)/linux-$(ONL_KERN_VER).tar.xz |
| 173 | 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 |
| 174 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk_dir |
| 175 | cat download/$(OPENOLT_BAL_PATCH) | patch -p1 -d $(BAL_DIR) |
| 176 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk |
| 177 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk_dir |
| 178 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk |
| 179 | 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 |
| 180 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) bal |
| 181 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) release_board |
| 182 | ln -s -f $(PWD)/$(BAL_DIR)/bcm68620_release/asfvolt16/release/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz . |
| 183 | ln -s -f $(PWD)/$(BAL_DIR)/bal_release/build/core/lib/libbal_api_dist.so . |
| 184 | ln -s -f $(PWD)/$(BAL_DIR)/bal_release/build/core/src/apps/bal_core_dist/bal_core_dist |
| 185 | mv -f release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz $(BUILD_DIR) |
| 186 | mv -f libbal_api_dist.so $(BUILD_DIR) |
| 187 | mv -f bal_core_dist $(BUILD_DIR) |
| 188 | endif |
| 189 | bal-rebuild: |
| 190 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) maple_sdk |
| 191 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) switch_sdk |
| 192 | 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 |
| 193 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) bal |
| 194 | make -C $(BAL_DIR)/bal_release BOARD=$(DEVICE) release_board |
| 195 | ln -s -f $(PWD)/$(BAL_DIR)/bcm68620_release/asfvolt16/release/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz . |
| 196 | ln -s -f $(PWD)/$(BAL_DIR)/bal_release/build/core/lib/libbal_api_dist.so . |
| 197 | ln -s -f $(PWD)/$(BAL_DIR)/bal_release/build/core/src/apps/bal_core_dist/bal_core_dist . |
| 198 | mv -f release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz $(BUILD_DIR) |
| 199 | mv -f libbal_api_dist.so $(BUILD_DIR) |
| 200 | mv -f bal_core_dist $(BUILD_DIR) |
| 201 | clean-bal: clean-onl |
| 202 | distclean-bal: distclean-onl |
| 203 | sudo rm -rf $(BAL_DIR) |
| 204 | rm -f build/release_$(DEVICE)_V$(BAL_MAJOR_VER).$(ACCTON_VER).tar.gz |
| 205 | |
| 206 | ######################################################################## |
| 207 | ## |
| 208 | ## |
| 209 | ## OpenOLT API |
| 210 | ## |
| 211 | ## |
| 212 | OPENOLT_API_DIR = $(BUILD_DIR)/openolt-api |
| 213 | OPENOLT_API_LIB = $(OPENOLT_API_DIR)/libopenoltapi.a |
| 214 | CXXFLAGS += -I./$(OPENOLT_API_DIR) -I $(OPENOLT_API_DIR)/googleapis/gens |
| 215 | .PHONY: openolt-api |
| 216 | openolt-api: |
| 217 | if [ ! -e "$(OPENOLT_API_DIR)" ]; then \ |
| 218 | mkdir -p $(BUILD_DIR); \ |
| 219 | git clone git@github.com:shadansari/openolt-api.git $(OPENOLT_API_DIR); \ |
| 220 | fi; |
| 221 | make -C $(OPENOLT_API_DIR) all |
| 222 | clean-openolt-api: |
| 223 | -make -C $(OPENOLT_API_DIR) clean |
| 224 | distclean-openolt-api: |
| 225 | |
| 226 | ######################################################################## |
| 227 | ## |
| 228 | ## |
| 229 | ## Main |
| 230 | ## |
| 231 | ## |
| 232 | SRCS = $(wildcard src/*.cc) |
| 233 | OBJS = $(SRCS:.cc=.o) |
| 234 | DEPS = $(SRCS:.cc=.d) |
| 235 | .DEFAULT_GOAL := all |
| 236 | all: $(BUILD_DIR)/openolt |
| 237 | $(BUILD_DIR)/openolt: check openolt-api bal $(OBJS) |
| 238 | $(CXX) $(OBJS) $(LDFLAGS) $(OPENOLT_API_LIB) -o $@ -L$(BALLIBDIR) -l$(BALLIBNAME) |
| 239 | ln -s $(shell ldconfig -p | grep libgrpc.so.5 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc.so.5 |
| 240 | ln -s $(shell ldconfig -p | grep libgrpc++.so.1 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc++.so.1 |
| 241 | ln -s $(shell ldconfig -p | grep libgrpc++_reflection.so.1 | tr ' ' '\n' | grep /) $(BUILD_DIR)/libgrpc++_reflection.so.1 |
| 242 | |
| 243 | src/%.o: %.cpp |
| 244 | $(CXX) -MMD -c $< -o $@ |
| 245 | |
| 246 | clean: clean-bal |
| 247 | rm -f $(OBJS) $(DEPS) $(BUILD_DIR)/openolt |
| 248 | rm -rf $(OPENOLT_API_DIR) |
| 249 | distclean: distclean-openolt-api distclean-bal |
| 250 | rm -rf $(BUILD_DIR) |
| 251 | -include $(DEPS) |