Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 1 | # Copyright 2018-present Open Networking Foundation |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2 | # |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 6 | # |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 8 | # |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 14 | |
| 15 | ######################################################################## |
| 16 | ## |
| 17 | ## |
| 18 | ## Config |
| 19 | ## |
| 20 | ## |
| 21 | TOP_DIR=`pwd` |
| 22 | OPENOLTDEVICE ?= asfvolt16 |
| 23 | |
Burak Gurdag | eb4ca2e | 2020-06-15 07:48:26 +0000 | [diff] [blame^] | 24 | OPENOLT_PROTO_VER ?= v3.3.9 |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 25 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 26 | GTEST_VER ?= release-1.8.0 |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 27 | gtest-target = /usr/local/lib/libgtest.a |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 28 | |
| 29 | CMOCK_VER ?= 0207b30 |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 30 | cmock-target = /usr/local/include/cmock/cmock.h |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 31 | |
| 32 | GMOCK_GLOBAL_VER ?= 1.0.2 |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 33 | gmock-global-target = /usr/local/include/gmock-global/gmock-global.h |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 34 | |
| 35 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 36 | # GRPC installation |
| 37 | GRPC_ADDR = https://github.com/grpc/grpc |
| 38 | GRPC_DST = /tmp/grpc |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 39 | GRPC_VER ?= v1.10.x |
| 40 | grpc-cpp-plugin-bin = /usr/local/bin/grpc_cpp_plugin |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 41 | |
| 42 | # Protobuf installation |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 43 | PROTOBUF_VER ?= 3.5.0 |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 44 | PROTOBUF_ADDR = https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOBUF_VER)/protobuf-cpp-$(PROTOBUF_VER).tar.gz |
| 45 | PROTOBUF_DST = /tmp/protobuf-$(PROTOBUF_VER) |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 46 | protoc-bin = /usr/local/bin/protoc |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 47 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 48 | # |
| 49 | ######################################################################## |
| 50 | ## |
| 51 | ## |
| 52 | ## Install prerequisites |
| 53 | ## |
| 54 | ## |
| 55 | |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 56 | CXX = g++ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 57 | CXXFLAGS += -g -O2 |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 58 | CXXFLAGS += `pkg-config --cflags-only-I grpc++` |
| 59 | CPPFLAGS += `pkg-config --cflags protobuf grpc` |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 60 | CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix |
| 61 | CXXFLAGS += -DTEST_MODE -DENABLE_LOG |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 62 | LDFLAGS += -lpthread -lm `pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 63 | CXXFLAGSDEVICE = -I../device -I../device/$(OPENOLTDEVICE) -I../device/generic |
| 64 | |
| 65 | export CXX CXXFLAGS OPENOLT_PROTO_VER |
| 66 | |
Jason Huang | c636279 | 2020-03-04 16:33:19 +0800 | [diff] [blame] | 67 | BAL_API_VER ?= bal-api-3.4.3.3 |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 68 | BAL_API_DIR=$(BAL_API_VER) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 69 | BALLIBNAME=bcm_host_api_stubs |
| 70 | BALLIBDIR=$(BAL_API_DIR)/stubs |
| 71 | BAL_INC = -I$(BAL_API_DIR)/include \ |
| 72 | -I$(BAL_API_DIR)/include/object_model |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 73 | CXXFLAGS += $(BAL_INC) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 74 | |
| 75 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 76 | prereqs-system: |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 77 | sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev unzip docker.io |
| 78 | sudo apt-get install -y build-essential autoconf libssl-dev gawk debhelper dh-systemd init-system-helpers curl cmake ccache g++-4.9 |
| 79 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 80 | prereqs-local: $(protoc-bin) $(grpc-cpp-plugin-bin) prereqs-test-lib |
| 81 | |
| 82 | $(protoc-bin): |
| 83 | # Install protobuf |
| 84 | rm -rf $(PROTOBUF_DST) |
| 85 | cd /tmp && wget $(PROTOBUF_ADDR) |
| 86 | cd /tmp && tar -zxvf protobuf-cpp-$(PROTOBUF_VER).tar.gz |
| 87 | cd $(PROTOBUF_DST) && ./autogen.sh |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 88 | cd $(PROTOBUF_DST) && ./configure |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 89 | make -C $(PROTOBUF_DST) |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 90 | sudo make -C $(PROTOBUF_DST) install |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 91 | |
| 92 | $(grpc-cpp-plugin-bin): |
| 93 | # Install GRPC, protoc |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 94 | rm -rf $(GRPC_DST) |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 95 | cd /tmp && git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 96 | cd $(GRPC_DST) && git submodule update --init |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 97 | make -C $(GRPC_DST) |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 98 | sudo make -C $(GRPC_DST) install |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 99 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 100 | prereqs-test-lib: $(gtest-target) $(cmock-target) $(gmock-global-target) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 101 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 102 | $(gtest-target): |
| 103 | # Install gtest |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 104 | rm -rf /tmp/googletest && cd /tmp && git clone https://github.com/google/googletest.git |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 105 | cd /tmp/googletest && git checkout $(GTEST_VER) |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 106 | cd /tmp/googletest && cmake CMakeLists.txt |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 107 | make -C /tmp/googletest |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 108 | sudo make -C /tmp/googletest install |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 109 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 110 | $(cmock-target): |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 111 | # Install c-mock |
| 112 | rm -rf /tmp/C-Mock && cd /tmp && git clone https://github.com/hjagodzinski/C-Mock.git |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 113 | cd /tmp/C-Mock && git checkout $(CMOCK_VER) |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 114 | sudo make -C /tmp/C-Mock install |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 115 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 116 | $(gmock-global-target): |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 117 | # Install gmock-global |
| 118 | rm -rf /tmp/gmock-global && cd /tmp && git clone https://github.com/apriorit/gmock-global.git |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 119 | cd /tmp/gmock-global && git checkout $(GMOCK_GLOBAL_VER) |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 120 | sudo cp -rf /tmp/gmock-global/include/gmock-global /usr/local/include/ |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 121 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 122 | ######################################################################## |
| 123 | ## |
| 124 | ## |
| 125 | ## build |
| 126 | ## |
| 127 | ## |
| 128 | |
| 129 | .DEFAULT_GOAL := all |
| 130 | |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 131 | .PHONY = bcm_host_api_stubs build clean prereqs-system prereqs-local |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 132 | |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 133 | OPENOLT_PROTOS_DIR = ../../protos |
| 134 | OPENOLT_API_LIB = lib/libopenoltapi.a |
| 135 | OPENOLT_LIB = lib/libopenolt.a |
| 136 | |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 137 | # Set the OPENOLT_ROOT_DIR variable to "/app" folder inside the docker container, if not already set. |
| 138 | ifeq ($(OPENOLT_ROOT_DIR),) |
| 139 | OPENOLT_ROOT_DIR := /app |
| 140 | endif |
| 141 | |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 142 | all: bcm_host_api_stubs $(OPENOLT_API_LIB) $(OPENOLT_LIB) build |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 143 | |
| 144 | # test |
| 145 | TEST_OPENOLT_LIB_DIR=./lib |
| 146 | TEST_BIN=test_openolt |
| 147 | # The below way of getting source files is not working |
| 148 | #TEST_SRCS = $($(filter-out src/bal_stub.cc, $(wildcard src/*.cc))) |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 149 | TEST_SRCS = src/main_test.cc src/bal_mocker.cc src/test_core.cc |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 150 | TEST_OBJS = $(TEST_SRCS:.cc=.o) |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 151 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 152 | build: $(TEST_OBJS) |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 153 | $(CXX) $(shell cmock-config --libs) -L$(TEST_OPENOLT_LIB_DIR) -L/usr/lib/ -I/usr/include -I./inc -I../src -o $(TEST_BIN) $(TEST_OBJS) -lgmock -lgtest -lopenolt -lopenoltapi $(LDFLAGS) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 154 | src/%.o: src/%.cc |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 155 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I./inc -I../common -I../src -I/usr/include -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 156 | |
| 157 | |
| 158 | # bcm_host_api_stubs |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 159 | bcm_host_api_stubs: |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 160 | echo $(OPENOLT_ROOT_DIR); \ |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 161 | # TODO: This is temporary hack below to introduce the definition BAL IEs that are missing in https://github.com/balapi/bal-api-<BAL-VER> |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 162 | if [ -d $(BAL_API_DIR) ]; then \ |
| 163 | echo "$(BAL_API_DIR) exists"; \ |
| 164 | else \ |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 165 | git clone https://github.com/balapi/$(BAL_API_VER).git ;\ |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 166 | sed -i "\$$i #include \"$(OPENOLT_ROOT_DIR)/agent/test/inc/bcmos_system_test.h\"" ./$(BAL_API_DIR)/include/bcmos_system.h; \ |
| 167 | sed -i "\$$i #include \"$(OPENOLT_ROOT_DIR)/agent/test/inc/bcmos_common_test.h\"" ./$(BAL_API_DIR)/include/bcmos_common.h; \ |
| 168 | sed -i "\$$i #include \"$(OPENOLT_ROOT_DIR)/agent/test/inc/bcmolt_api_model_api_structs_test.h\"" ./$(BAL_API_DIR)/include/object_model/bcmolt_api_model_api_structs.h; \ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 169 | fi |
| 170 | |
| 171 | # openoltapi |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 172 | CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 173 | $(OPENOLT_API_LIB): $(wildcard $(OPENOLT_PROTOS_DIR)/*.proto) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 174 | make -C $(OPENOLT_PROTOS_DIR) all |
| 175 | mkdir -p lib |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 176 | cp $(OPENOLT_PROTOS_DIR)/libopenoltapi.a lib/ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 177 | libproto-clean: |
| 178 | make -C $(OPENOLT_PROTOS_DIR) clean |
| 179 | |
| 180 | # openolt |
| 181 | OPENOLT_SRCS = $(wildcard ../src/*.cc) ../common/server.cc $(wildcard ../device/$(OPENOLTDEVICE)/*.cc) src/bal_stub.cc |
| 182 | OPENOLT_OBJS = $(OPENOLT_SRCS:.cc=.o) |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 183 | $(OPENOLT_LIB): $(OPENOLT_OBJS) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 184 | mkdir -p lib |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 185 | ar cr $@ $^ |
| 186 | ranlib $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 187 | ../common/%.o: ../common/%.cc |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 188 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 189 | ../src/%.o: ../src/%.cc |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 190 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 191 | src/%.o: src/%.cc |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 192 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 193 | ../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 194 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 195 | |
| 196 | test: all |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 197 | ./test_openolt --gtest_output="xml:./test_openolt_report_xunit.xml" |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 198 | |
| 199 | clean: |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 200 | rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./test_openolt_report_xunit.xml |