Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [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 | |
| 24 | # OpenOLT Proto version. |
| 25 | # This specifies the GIT tag in https://github.com/opencord/voltha-protos |
| 26 | # repo that we need to refer to, to pick the right version of |
| 27 | # openolt.proto and tech_profile.proto |
| 28 | OPENOLT_PROTO_VER ?= v1.0.3 |
| 29 | |
| 30 | # GRPC installation |
| 31 | GRPC_ADDR = https://github.com/grpc/grpc |
| 32 | GRPC_DST = /tmp/grpc |
| 33 | GRPC_VER = v1.10.x |
| 34 | |
| 35 | USER := $(shell echo $(USER)) |
| 36 | # |
| 37 | ######################################################################## |
| 38 | ## |
| 39 | ## |
| 40 | ## Install prerequisites |
| 41 | ## |
| 42 | ## |
| 43 | |
| 44 | CXX = g++-4.9 |
| 45 | CXXFLAGS += -g -O2 |
| 46 | CXXFLAGS += $(shell pkg-config --cflags-only-I grpc++) |
| 47 | CPPFLAGS += `pkg-config --cflags protobuf grpc` |
| 48 | CXXFLAGS += -std=c++11 -fpermissive -Wno-literal-suffix |
| 49 | CXXFLAGS += -DTEST_MODE -DENABLE_LOG |
| 50 | LDFLAGS += |
| 51 | LDFLAGS += `pkg-config --libs protobuf grpc++ grpc` -ldl -lgpr |
| 52 | CXXFLAGSDEVICE = -I../device -I../device/$(OPENOLTDEVICE) -I../device/generic |
| 53 | |
| 54 | export CXX CXXFLAGS OPENOLT_PROTO_VER |
| 55 | |
| 56 | BAL_API_DIR=bal-api-3.1.0 |
| 57 | BALLIBNAME=bcm_host_api_stubs |
| 58 | BALLIBDIR=$(BAL_API_DIR)/stubs |
| 59 | BAL_INC = -I$(BAL_API_DIR)/include \ |
| 60 | -I$(BAL_API_DIR)/include/object_model |
| 61 | CXXFLAGS += $(BAL_INC) |
| 62 | |
| 63 | |
| 64 | |
| 65 | prereq: |
| 66 | sudo apt-get -q -y install git pkg-config build-essential autoconf libtool libgflags-dev libgtest-dev clang libc++-dev unzip docker.io |
| 67 | sudo apt-get install -y build-essential autoconf libssl-dev gawk debhelper dh-systemd init-system-helpers curl cmake ccache g++-4.9 |
| 68 | |
| 69 | # Install GRPC, libprotobuf and protoc |
| 70 | rm -rf $(GRPC_DST) |
| 71 | git clone -b $(GRPC_VER) $(GRPC_ADDR) $(GRPC_DST) |
| 72 | cd $(GRPC_DST) && git submodule update --init |
| 73 | cd $(GRPC_DST)/third_party/protobuf && ./autogen.sh && ./configure |
| 74 | make -C $(GRPC_DST)/third_party/protobuf |
| 75 | sudo make -C $(GRPC_DST)/third_party/protobuf install |
| 76 | sudo ldconfig |
| 77 | make -C $(GRPC_DST) |
| 78 | sudo make -C $(GRPC_DST) install |
| 79 | sudo ldconfig |
| 80 | |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 81 | prereq-mock-lib: gtest cmock gmock-global |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 82 | |
| 83 | gtest: |
| 84 | # Install gtest and gmock |
| 85 | rm -rf /tmp/googletest && cd /tmp && git clone https://github.com/google/googletest.git |
| 86 | cd /tmp/googletest && git checkout release-1.8.0 |
| 87 | cd /tmp/googletest && cmake CMakeLists.txt |
| 88 | make -C /tmp/googletest |
| 89 | sudo make -C /tmp/googletest install |
| 90 | |
| 91 | cmock: |
| 92 | # Install c-mock |
| 93 | rm -rf /tmp/C-Mock && cd /tmp && git clone https://github.com/hjagodzinski/C-Mock.git |
| 94 | cd /tmp/C-Mock && git checkout 0207b3026f04bbdf0bd9d9f8dfd00945a4318251 |
| 95 | make -C /tmp/C-Mock |
| 96 | sudo make -C /tmp/C-Mock install |
| 97 | |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 98 | gmock-global: |
| 99 | # Install gmock-global |
| 100 | rm -rf /tmp/gmock-global && cd /tmp && git clone https://github.com/apriorit/gmock-global.git |
| 101 | cd /tmp/gmock-global && git checkout 1.0.2 |
| 102 | sudo cp -rf /tmp/gmock-global/include/gmock-global /usr/local/include/ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 103 | ######################################################################## |
| 104 | ## |
| 105 | ## |
| 106 | ## build |
| 107 | ## |
| 108 | ## |
| 109 | |
| 110 | .DEFAULT_GOAL := all |
| 111 | |
| 112 | .PHONY = bcm_host_api_stubs libopenoltapi.a libopenolt.a build clean |
| 113 | |
| 114 | all: bcm_host_api_stubs libopenoltapi.a libopenolt.a build |
| 115 | |
| 116 | # test |
| 117 | TEST_OPENOLT_LIB_DIR=./lib |
| 118 | TEST_BIN=test_openolt |
| 119 | # The below way of getting source files is not working |
| 120 | #TEST_SRCS = $($(filter-out src/bal_stub.cc, $(wildcard src/*.cc))) |
| 121 | TEST_SRCS = src/main_test.cc src/bal_mocker.cc src/test_enable_olt.cc |
| 122 | TEST_OBJS = $(TEST_SRCS:.cc=.o) |
| 123 | build: $(TEST_OBJS) |
| 124 | $(CXX) $(shell cmock-config --libs) -L$(TEST_OPENOLT_LIB_DIR) -L/usr/lib/ -I/usr/include -I./inc -o $(TEST_BIN) $(TEST_OBJS) -lgmock -lgtest -lopenolt -lopenoltapi $(LDFLAGS) |
| 125 | src/%.o: src/%.cc |
| 126 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I./inc -I../common -I/usr/include -c $< -o $@ |
| 127 | |
| 128 | |
| 129 | # bcm_host_api_stubs |
| 130 | BAL_API_DIR=bal-api-3.1.0 |
| 131 | bcm_host_api_stubs: |
| 132 | # TODO: There is temporary hack below to introduce the definition of bcmos_mutex. |
| 133 | # This should ideally come as part of bal-api-3.1.0 |
| 134 | if [ -d $(BAL_API_DIR) ]; then \ |
| 135 | echo "$(BAL_API_DIR) exists"; \ |
| 136 | else \ |
| 137 | git clone https://github.com/balapi/bal-api-3.1.0.git ;\ |
| 138 | sed -i "\$$i #define BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT 0" ./bal-api-3.1.0/include/bcmos_system.h; \ |
| 139 | sed -i "\$$i struct bcmos_mutex \{ pthread_mutex_t m; };" ./bal-api-3.1.0/include/bcmos_system.h; \ |
| 140 | fi |
| 141 | |
| 142 | # openoltapi |
| 143 | OPENOLT_PROTOS_DIR = ../../protos |
| 144 | OPENOLT_API_LIB = $(OPENOLT_PROTOS_DIR)/libopenoltapi.a |
| 145 | CXXFLAGS += -I$(OPENOLT_PROTOS_DIR) -I$(OPENOLT_PROTOS_DIR)/googleapis/gens |
| 146 | libopenoltapi.a: |
| 147 | make -C $(OPENOLT_PROTOS_DIR) all |
| 148 | mkdir -p lib |
| 149 | cp $(OPENOLT_PROTOS_DIR)/$@ lib/ |
| 150 | libproto-clean: |
| 151 | make -C $(OPENOLT_PROTOS_DIR) clean |
| 152 | |
| 153 | # openolt |
| 154 | OPENOLT_SRCS = $(wildcard ../src/*.cc) ../common/server.cc $(wildcard ../device/$(OPENOLTDEVICE)/*.cc) src/bal_stub.cc |
| 155 | OPENOLT_OBJS = $(OPENOLT_SRCS:.cc=.o) |
| 156 | libopenolt.a: $(OPENOLT_OBJS) |
| 157 | mkdir -p lib |
| 158 | ar cr lib/$@ $^ |
| 159 | ranlib lib/$@ |
| 160 | ../common/%.o: ../common/%.cc |
| 161 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@ |
| 162 | ../src/%.o: ../src/%.cc |
| 163 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@ |
| 164 | src/%.o: src/%.cc |
| 165 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@ |
| 166 | ../device/$(OPENOLTDEVICE)/%.o: ../device/$(OPENOLTDEVICE)/%.cc |
| 167 | $(CXX) $(CXXFLAGS) $(CXXFLAGSDEVICE) -I../common -I./inc -I./device/$(OPENOLTDEVICE) -c $< -o $@ |
| 168 | |
| 169 | test: all |
| 170 | ./test_openolt --gtest_output="xml:./test_openolt_report.xml" |
| 171 | |
| 172 | clean: |
| 173 | rm -f src/*.o lib/*.a ../src/*.o ../common/*.o ./test_openolt ./test_openolt_report.xml |