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 | |
Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 24 | OPENOLT_PROTO_VER ?= v4.0.3 |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 25 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 26 | ######################################################################## |
| 27 | ## |
| 28 | ## |
| 29 | ## Install prerequisites |
| 30 | ## |
| 31 | ## |
| 32 | |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 33 | CXX = g++ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 34 | CXXFLAGS += -g -O2 |
Girish Gowdra | 1935e6a | 2020-10-31 21:48:22 -0700 | [diff] [blame] | 35 | CXXFLAGS += `pkg-config --cflags-only-I grpc++` -I/usr/local/include/pcapplusplus/ |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 36 | CPPFLAGS += `pkg-config --cflags protobuf grpc` |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 37 | CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix |
| 38 | CXXFLAGS += -DTEST_MODE -DENABLE_LOG |
Girish Gowdra | 1935e6a | 2020-10-31 21:48:22 -0700 | [diff] [blame] | 39 | LDFLAGS += -lpthread -lm `pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr -lPcap++ -lPacket++ -lCommon++ |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 40 | CXXFLAGSDEVICE = -I../device -I../device/$(OPENOLTDEVICE) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 41 | |
| 42 | export CXX CXXFLAGS OPENOLT_PROTO_VER |
| 43 | |
Girish Gowdra | 3b0ae45 | 2020-09-28 10:53:18 -0700 | [diff] [blame] | 44 | BAL_API_VER ?= bal-api-3.4.7.5 |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 45 | BAL_API_DIR=$(BAL_API_VER) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 46 | BALLIBNAME=bcm_host_api_stubs |
| 47 | BALLIBDIR=$(BAL_API_DIR)/stubs |
| 48 | BAL_INC = -I$(BAL_API_DIR)/include \ |
| 49 | -I$(BAL_API_DIR)/include/object_model |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 50 | CXXFLAGS += $(BAL_INC) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 51 | |
| 52 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 53 | ######################################################################## |
| 54 | ## |
| 55 | ## |
| 56 | ## build |
| 57 | ## |
| 58 | ## |
| 59 | |
| 60 | .DEFAULT_GOAL := all |
| 61 | |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 62 | .PHONY = bcm_host_api_stubs build clean prereqs-system prereqs-local |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 63 | |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 64 | OPENOLT_PROTOS_DIR = ../../protos |
| 65 | OPENOLT_API_LIB = lib/libopenoltapi.a |
| 66 | OPENOLT_LIB = lib/libopenolt.a |
| 67 | |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 68 | # Set the OPENOLT_ROOT_DIR variable to "/app" folder inside the docker container, if not already set. |
| 69 | ifeq ($(OPENOLT_ROOT_DIR),) |
| 70 | OPENOLT_ROOT_DIR := /app |
| 71 | endif |
| 72 | |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 73 | all: bcm_host_api_stubs $(OPENOLT_API_LIB) $(OPENOLT_LIB) build |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 74 | |
| 75 | # test |
| 76 | TEST_OPENOLT_LIB_DIR=./lib |
| 77 | TEST_BIN=test_openolt |
| 78 | # The below way of getting source files is not working |
| 79 | #TEST_SRCS = $($(filter-out src/bal_stub.cc, $(wildcard src/*.cc))) |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 80 | 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] | 81 | TEST_OBJS = $(TEST_SRCS:.cc=.o) |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 82 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 83 | build: $(TEST_OBJS) |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 84 | $(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] | 85 | src/%.o: src/%.cc |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 86 | $(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] | 87 | |
| 88 | |
| 89 | # bcm_host_api_stubs |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 90 | bcm_host_api_stubs: |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 91 | echo $(OPENOLT_ROOT_DIR); \ |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 92 | # 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] | 93 | if [ -d $(BAL_API_DIR) ]; then \ |
| 94 | echo "$(BAL_API_DIR) exists"; \ |
| 95 | else \ |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 96 | git clone https://github.com/balapi/$(BAL_API_VER).git ;\ |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 97 | sed -i "\$$i #include \"$(OPENOLT_ROOT_DIR)/agent/test/inc/bcmos_system_test.h\"" ./$(BAL_API_DIR)/include/bcmos_system.h; \ |
| 98 | sed -i "\$$i #include \"$(OPENOLT_ROOT_DIR)/agent/test/inc/bcmos_common_test.h\"" ./$(BAL_API_DIR)/include/bcmos_common.h; \ |
| 99 | 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] | 100 | fi |
| 101 | |
| 102 | # openoltapi |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 103 | CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 104 | $(OPENOLT_API_LIB): $(wildcard $(OPENOLT_PROTOS_DIR)/*.proto) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 105 | make -C $(OPENOLT_PROTOS_DIR) all |
| 106 | mkdir -p lib |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 107 | cp $(OPENOLT_PROTOS_DIR)/libopenoltapi.a lib/ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 108 | libproto-clean: |
| 109 | make -C $(OPENOLT_PROTOS_DIR) clean |
| 110 | |
| 111 | # openolt |
| 112 | OPENOLT_SRCS = $(wildcard ../src/*.cc) ../common/server.cc $(wildcard ../device/$(OPENOLTDEVICE)/*.cc) src/bal_stub.cc |
| 113 | OPENOLT_OBJS = $(OPENOLT_SRCS:.cc=.o) |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 114 | $(OPENOLT_LIB): $(OPENOLT_OBJS) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 115 | mkdir -p lib |
Girish Gowdra | 489425a | 2020-02-22 13:07:42 +0530 | [diff] [blame] | 116 | ar cr $@ $^ |
| 117 | ranlib $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 118 | ../common/%.o: ../common/%.cc |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 119 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 120 | ../src/%.o: ../src/%.cc |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 121 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 122 | src/%.o: src/%.cc |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 123 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 124 | ../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 125 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I../src -c $< -o $@ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 126 | |
| 127 | test: all |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 128 | ./test_openolt --gtest_output="xml:./test_openolt_report_xunit.xml" |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 129 | |
| 130 | clean: |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 131 | rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./test_openolt_report_xunit.xml |