blob: 8c75e17992aad5a3116db60d1f61e6ecf3b9495f [file] [log] [blame]
Beerappa S M7af96e52021-04-20 18:57:54 +00001#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
20CURDIR := $(shell pwd)
21TARCHDIR ?= x86_64
22BUILD_DIR := build
23OBJDIR := $(CURDIR)
24DMI_SOURCE_DIR := $(BUILD_DIR)/device-management-interface/
25
26ifeq ($(DEB_CODENAME),jessie)
27CXX = g++-4.9
28else
29CXX = g++
30endif
31
32DOCKER ?= docker
33DOCKER_REGISTRY ?=
34DOCKER_REPOSITORY ?= voltha/
35DOCKER_EXTRA_ARGS ?=
36DOCKER_TAG ?= 2.1.1
37IMAGENAME = ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}openolt-test:${DOCKER_TAG}
38
39# Version of Open Network Linux (ONL).
40ONL_KERN_VER_MAJOR = 4.19
41
42CXXFLAGS += -ggdb -Werror -Wall -std=c++11
43CXXFLAGS += $(shell pkg-config --cflags-only-I grpc++)
44GRPCFLAGS += `pkg-config --libs grpc++ grpc`
45CXXFLAGS += -std=c++11 -fpermissive -Wno-write-strings -Wno-literal-suffix -I/usr/local/lib/
46LDFLAGS += -L./build/
47LDFLAGS += -lgrpc++_reflection -Wl,--as-needed -ldmi_grpc -lprotobuf -lpthread -ldl
48
49DMIAGENT_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
55DMIAGENT_INC = -I./inc/ \
56 -I./protos/ \
57 -I./protos/dmi/
58
59
60DMIAGENT_OBJS = $(DMIAGENT_SRCS:.cc=.o)
61
62all: onl opendm-agent
63 mv opendm-agent $(BUILD_DIR)
64
65opendm-agent: protos-lib $(DMIAGENT_OBJS)
66 $(CXX) $(CXXFLAGS) $(DMIAGENT_OBJS) $(GRPCFLAGS) $(LDFLAGS) -o $@
67
68src/%.o: src/%.cc
69 $(CXX) $(CXXFLAGS) $(LDFLAGS) $(DMIAGENT_INC) -c $< -o $@
70
71protos-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
80prereq: device-management-interface
81
82device-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###
93ONL_REPO = onl
94ONL_DIR = $(BUILD_DIR)/$(ONL_REPO)
95
96onl:
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
109test:
110 ${DOCKER} run --rm -v $(shell pwd):/app $(shell test -t 0 && echo "-it") ${IMAGENAME} make -C unit_test test
111
112clean:
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)