Beerappa S M | 7af96e5 | 2021-04-20 18:57:54 +0000 | [diff] [blame^] | 1 | #Copyright 2021-present Open Networking Foundation |
| 2 | # |
| 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 |
| 6 | # |
| 7 | #http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 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. |
| 14 | |
| 15 | ################################################################################## |
| 16 | |
| 17 | # This makefile builds a opendm-agent and libdmi_grpc library |
| 18 | # Please refer ./README.md and ./BUILDING.md file for more details |
| 19 | |
| 20 | CURDIR := $(shell pwd) |
| 21 | TARCHDIR ?= x86_64 |
| 22 | BUILD_DIR := build |
| 23 | OBJDIR := $(CURDIR) |
| 24 | DMI_SOURCE_DIR := $(BUILD_DIR)/device-management-interface/ |
| 25 | |
| 26 | ifeq ($(DEB_CODENAME),jessie) |
| 27 | CXX = g++-4.9 |
| 28 | else |
| 29 | CXX = g++ |
| 30 | endif |
| 31 | |
| 32 | DOCKER ?= docker |
| 33 | DOCKER_REGISTRY ?= |
| 34 | DOCKER_REPOSITORY ?= voltha/ |
| 35 | DOCKER_EXTRA_ARGS ?= |
| 36 | DOCKER_TAG ?= 2.1.1 |
| 37 | IMAGENAME = ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}openolt-test:${DOCKER_TAG} |
| 38 | |
| 39 | # Version of Open Network Linux (ONL). |
| 40 | ONL_KERN_VER_MAJOR = 4.19 |
| 41 | |
| 42 | CXXFLAGS += -ggdb -Werror -Wall -std=c++11 |
| 43 | CXXFLAGS += $(shell pkg-config --cflags-only-I grpc++) |
| 44 | GRPCFLAGS += `pkg-config --libs grpc++ grpc` |
| 45 | CXXFLAGS += -std=c++11 -fpermissive -Wno-write-strings -Wno-literal-suffix -I/usr/local/lib/ |
| 46 | LDFLAGS += -L./build/ |
| 47 | LDFLAGS += -lgrpc++_reflection -Wl,--as-needed -ldmi_grpc -lprotobuf -lpthread -ldl |
| 48 | |
| 49 | DMIAGENT_SRCS = src/main.cc \ |
| 50 | src/dmi_phycomp_factory.cc \ |
| 51 | src/dmi_hw_mgmt.cc \ |
| 52 | src/dmi_sw_mgmt.cc \ |
| 53 | src/dmi_server.cc |
| 54 | |
| 55 | DMIAGENT_INC = -I./inc/ \ |
| 56 | -I./protos/ \ |
| 57 | -I./protos/dmi/ |
| 58 | |
| 59 | |
| 60 | DMIAGENT_OBJS = $(DMIAGENT_SRCS:.cc=.o) |
| 61 | |
| 62 | all: onl opendm-agent |
| 63 | mv opendm-agent $(BUILD_DIR) |
| 64 | |
| 65 | opendm-agent: protos-lib $(DMIAGENT_OBJS) |
| 66 | $(CXX) $(CXXFLAGS) $(DMIAGENT_OBJS) $(GRPCFLAGS) $(LDFLAGS) -o $@ |
| 67 | |
| 68 | src/%.o: src/%.cc |
| 69 | $(CXX) $(CXXFLAGS) $(LDFLAGS) $(DMIAGENT_INC) -c $< -o $@ |
| 70 | |
| 71 | protos-lib: prereq |
| 72 | echo "Creating the libdmi_grpc.so using auto generated cpp-protos" |
| 73 | if [ ! -e "$(OBJDIR)/protos/" ]; then \ |
| 74 | mkdir -p $(OBJDIR)/protos/; \ |
| 75 | cp -r $(DMI_SOURCE_DIR)/cpp/dmi $(OBJDIR)/protos; \ |
| 76 | g++ -shared -fPIC -g -ggdb -std=c++11 `pkg-config --cflags protobuf grpc` -I$(OBJDIR)/protos/ `find $(OBJDIR)/protos/ -name "*.cc"` -o $(OBJDIR)/$(BUILD_DIR)/libdmi_grpc.so; \ |
| 77 | cp $(OBJDIR)/$(BUILD_DIR)/libdmi_grpc.so /usr/local/lib/; \ |
| 78 | fi; |
| 79 | |
| 80 | prereq: device-management-interface |
| 81 | |
| 82 | device-management-interface: |
| 83 | if [ ! -e "$(DMI_SOURCE_DIR)" ]; then \ |
| 84 | git clone https://github.com/opencord/device-management-interface.git $(DMI_SOURCE_DIR); \ |
| 85 | fi; |
| 86 | |
| 87 | ######################################################################### |
| 88 | ## |
| 89 | ## |
| 90 | ## ONL Target refered from openolt agent |
| 91 | ## |
| 92 | ### |
| 93 | ONL_REPO = onl |
| 94 | ONL_DIR = $(BUILD_DIR)/$(ONL_REPO) |
| 95 | |
| 96 | onl: |
| 97 | if [ ! -d "$(ONL_DIR)/OpenNetworkLinux" ]; then \ |
| 98 | mkdir -p $(ONL_DIR); \ |
| 99 | git clone https://github.com/opencomputeproject/OpenNetworkLinux.git $(ONL_DIR)/OpenNetworkLinux; \ |
| 100 | cp download/Makefile.onl $(ONL_DIR)/Makefile; \ |
| 101 | install -m 755 download/build-onl.sh $(ONL_DIR)/OpenNetworkLinux; \ |
| 102 | make -C $(ONL_DIR) onl-$(ONL_KERN_VER_MAJOR) INBAND=n; \ |
| 103 | else \ |
| 104 | if [ "$(INBAND)" = n -a "$$(grep "inband" $(ONL_DIR)/onl_build.mode | cut -d= -f 2)" = y ]; then \ |
| 105 | make -C $(ONL_DIR) onl-$(ONL_KERN_VER_MAJOR) INBAND=n; \ |
| 106 | fi; \ |
| 107 | fi; |
| 108 | |
| 109 | test: |
| 110 | ${DOCKER} run --rm -v $(shell pwd):/app $(shell test -t 0 && echo "-it") ${IMAGENAME} make -C unit_test test |
| 111 | |
| 112 | clean: |
| 113 | rm -rf $(OBJDIR)/protos/ |
| 114 | rm -rf $(OBJDIR)/src/*.o |
| 115 | rm -rf $(BUILD_DIR)/*.so |
| 116 | rm -rf $(BUILD_DIR)/opendm-agent |
| 117 | rm -rf $(DMIAGENT_OBJS) |