aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: a0cccac681801d1e9c97f0bdf4731fb2e0222b1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# Copyright (c) 2018 Intel and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#  Main Dependencies:
#  netopeer2 -> libyang
#            -> libnetconf2 -> libyang
#                           -> libssh (>=0.6.4)
#
#  gnmi      -> libsysrepo
#            -> protobuf (>=3)
#            -> libjsoncpp
#
#  sysrepo   -> libyang
#            -> libredblack or libavl
#            -> libev
#            -> protobuf-c

export WS_ROOT=$(CURDIR)
export BR=$(WS_ROOT)/build-root
PLATFORM?=sweetcomb
export VPP_VERSION?=release
export REBUILD_DOCKER_IMAGE?=no

##############
#OS Detection#
##############
ifneq ($(shell uname),Darwin)
OS_ID        = $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
OS_VERSION_ID= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
endif

ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID))
PKG=deb
cmake=cmake
else ifeq ($(filter rhel centos fedora opensuse opensuse-leap opensuse-tumbleweed,$(OS_ID)),$(OS_ID))
PKG=rpm
cmake=cmake3
endif

#####
#DEB#
#####
#Dependencies to build
BUILD_DEB = curl build-essential autoconf automake ccache git cmake wget coreutils
#Dependencies for netopeer2
NETOPEER2_DEB = libssl-dev pkgconf
#Dependencies for checkstyle
CHECKSTYLE_DEB = indent
#Dependencies for scvpp
SCVPP_DEB = libcmocka-dev
#Dependencies for sysrepo (swig required for sysrepo python, lua, java)
SYSREPO_DEB = libev-dev libavl-dev bison flex libpcre3-dev libprotobuf-c-dev protobuf-c-compiler
#Dependencies of libssh
LIBSSH_DEB = zlib1g-dev
#Sum dependencies
DEB_DEPENDS = ${BUILD_DEB} ${NETOPEER2_DEB} ${CHECKSTYLE_DEB} ${SCVPP_DEB} ${SYSREPO_DEB} ${LIBSSH_DEB}

#Dependencies for grpc
DEB_GNMI_DEPENDS = libpugixml-dev libjsoncpp-dev libtool pkg-config

#Dependencies for automatic test
DEB_TEST_DEPENDS = python3-pip python-pip libcurl4-openssl-dev libssh-dev \
libxml2-dev libxslt1-dev libtool-bin

#####
#RPM#
#####
#Dependencies to build
BUILD_RPM = curl autoconf automake ccache cmake3 wget gcc gcc-c++ git
#Dependencies for netopeer2
NETOPEER2_RPM = openssl-devel
#Dependencies for checkstyle
CHECKSTYLE_RPM = indent
#Dependencies for scvpp
SCVPP_RPM = libcmocka-devel
#Dependencies for sysrepo
SYSREPO_RPM = libev-devel bison flex pcre-devel protobuf-c-devel protobuf-c-compiler

RPM_DEPENDS = ${BUILD_RPM} ${NETOPEER2_RPM} ${CHECKSTYLE_RPM} ${SCVPP_RPM} \
	      ${SYSREPO_RPM}

#Dependencies for grpc
RPM_GNMI_DEPENDS = pugixml jsoncpp libtool pugixml-devel jsoncpp-devel ${GRPC_RPM}

#Dependencies for automatic test
RPM_TEST_DEPENDS = python36-devel python36-pip python-pip libxml2-devel \
libxslt-devel libtool which cmake3

.PHONY: help install-dep install-dep-extra install-vpp install-models uninstall-models \
    install-dep-gnmi-extra build-scvpp build-plugins build-gnmi build-package docker \
    docker-test test clean distclean _clean_dl _libssh _libyang _libnetconf2 _sysrepo _netopeer2

help:
	@echo "Make Targets:"
	@echo " install-dep            - install software dependencies"
	@echo " install-dep-extra      - install software extra dependencies from source code"
	@echo " install-vpp            - install released vpp"
	@echo " install-models         - install YANG models"
	@echo " uninstall-models       - uninstall YANG models"
	@echo " install-dep-gnmi-extra - install software extra dependencips from source code for gNMI"
	@echo " install-test-extra     - install software extra dependencies from source code for YDK"
	@echo " build-scvpp            - build scvpp"
	@echo " test-scvpp             - unit test for scvpp"
	@echo " build-plugins          - build plugins"
	@echo " test-plugins           - integration test for sweetcomb plugins"
	@echo " build-gnmi             - build gNMIServer"
	@echo " build-package          - build rpm or deb package"
	@echo " docker                 - build sweetcomb in docker enviroment, with optional arguments :"
	@echo "                          VPP_VERSION=release [master|release] specifies VPP version to be used"
	@echo "                          REBUILD_DOCKER_IMAGE=no [yes|no] force rebuild docker image"
	@echo " docker-test            - run test in docker enviroment, with optional argument :"
	@echo "                          REBUILD_DOCKER_IMAGE=no [yes|no] force rebuild docker image"
	@echo " clean                  - clean all build"
	@echo " distclean              - remove all build directory"
	@echo " checkstyle             - check coding style"

install-dep:
ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID))
ifeq ($(OS_VERSION_ID),14.04)
	@sudo -E apt-get -y --force-yes install software-properties-common
	@sudo -E add-apt-repository ppa:openjdk-r/ppa -y
endif
	@sudo -E apt-get update
	@sudo -E apt-get $(APT_ARGS) -y --force-yes install $(DEB_DEPENDS)
else ifeq ($(OS_ID),centos)
	@sudo -E yum install -y $(RPM_DEPENDS) epel-release centos-release-scl devtoolset-7
	@sudo -E yum remove -y libavl libavl-devel
	@sudo -E yum install -y http://ftp.nohats.ca/libavl/libavl-0.3.5-1.fc17.x86_64.rpm http://ftp.nohats.ca/libavl/libavl-devel-0.3.5-1.fc17.x86_64.rpm
else
	$(error "This option currently works only on Ubuntu, Debian, Centos or openSUSE systems")
endif

_libssh:
ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID))
	mkdir -p $(BR)/downloads/&&cd $(BR)/downloads/\
	&&wget https://git.libssh.org/projects/libssh.git/snapshot/libssh-0.7.7.tar.gz\
	&&tar xvf libssh-0.7.7.tar.gz && cd libssh-0.7.7 && mkdir build && cd build\
	&&cmake -DZLIB_LIBRARY=/usr/lib/x86_64-linux-gnu/libz.so -DZLIB_INCLUDE_DIR=/usr/include/ -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr ..\
	&&make -j$(nproc) &&sudo make install && sudo ldconfig&&cd ../../;
else ifeq ($(OS_ID),centos)
	mkdir -p $(BR)/downloads/&&cd $(BR)/downloads/\
	&&wget https://git.libssh.org/projects/libssh.git/snapshot/libssh-0.7.7.tar.gz\
	&&tar xvf libssh-0.7.7.tar.gz && cd libssh-0.7.7 && mkdir build && cd build\
	&&cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr ..\
	&&make -j$(nproc) &&sudo make install && sudo ldconfig&&cd ../../;
endif

_libyang:
	@mkdir -p $(BR)/downloads/&&cd $(BR)/downloads/\
	&&wget https://github.com/CESNET/libyang/archive/v0.16-r3.tar.gz\
	&&tar xvf v0.16-r3.tar.gz && cd libyang-0.16-r3 && mkdir -p build&& cd build\
	&&cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr \
	-DGEN_LANGUAGE_BINDINGS=OFF -DGEN_CPP_BINDINGS=ON \
	-DGEN_PYTHON_BINDINGS=OFF -DBUILD_EXAMPLES=OFF \
	-DENABLE_BUILD_TESTS=OFF .. \
	&&make -j$(nproc) &&make install&&cd ../../ \
	&& mv v0.16-r3.tar.gz libyang-0.16-r3.tar.gz

_libnetconf2:
	@mkdir -p $(BR)/downloads/&&cd $(BR)/downloads/\
	&&git clone https://github.com/CESNET/libnetconf2.git&&cd libnetconf2\
	&&git checkout 7e5f7b05f10cb32a546c42355481c7d87e0409b8&& mkdir -p build&& cd build\
	&&cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_BUILD_TESTS=OFF\
	-DCMAKE_INSTALL_PREFIX:PATH=/usr ..\
	&&make -j $(nproc) &&make install&&ldconfig\
	&&cd ../../\

_sysrepo:
	@mkdir -p $(BR)/downloads/&&cd $(BR)/downloads/\
	&&wget https://github.com/sysrepo/sysrepo/archive/v0.7.7.tar.gz\
	&&tar xvf v0.7.7.tar.gz && cd sysrepo-0.7.7 && mkdir -p build && cd build\
	&&cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr \
	-DGEN_LANGUAGE_BINDINGS=OFF -DGEN_CPP_BINDINGS=ON -DGEN_LUA_BINDINGS=OFF \
	-DGEN_PYTHON_BINDINGS=OFF -DGEN_JAVA_BINDINGS=OFF -DBUILD_EXAMPLES=OFF \
	-DENABLE_TESTS=OFF ..\
	&&make -j$(nproc) &&make install&&cd ../../&& mv v0.7.7.tar.gz sysrepo-0.7.7.tar.gz

_netopeer2:
	@mkdir -p $(BR)/downloads/&&cd $(BR)/downloads/\
	&&wget https://github.com/CESNET/Netopeer2/archive/v0.7-r1.tar.gz\
	&&tar xvf v0.7-r1.tar.gz\
	&& echo "Netopeer2:keystored" \
	&& cd Netopeer2-0.7-r1/keystored && mkdir -p build && cd build\
	&&cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr ..\
	&&make -j$(nproc) && make install && sudo ldconfig\
	&& echo "Netopeer2:server" \
	&&cd ../../server/ && mkdir -p build && cd build\
	&&cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_BUILD_TESTS=OFF\
	-DCMAKE_INSTALL_PREFIX:PATH=/usr ..\
	&&make -j$(nproc) && make install && ldconfig\
	&& echo "Netopeer2:cli" \
	&&cd ../../cli && mkdir -p build && cd build\
	&&cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr ..\
	&&make -j$(nproc) && make install && sudo ldconfig\
	&&cd ../../../ && mv v0.7-r1.tar.gz Netopeer2-0.7-r1.tar.gz\

_test_python:
ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID))
	@sudo -E apt-get $(APT_ARGS) -y --force-yes install $(DEB_TEST_DEPENDS)
ifeq ($(OS_VERSION_ID), 16.04)
	# Need update libssh library, because netopeer ssh communication does not work with old library
	@echo "deb http://archive.ubuntu.com/ubuntu/ bionic main restricted" >> /etc/apt/sources.list\
	&&apt-get update && apt-get -y install libssh-4
endif
else ifeq ($(OS_ID),centos)
# compiler return me this error and I don't know hot to fix it, yet
#  Found Doxygen: /usr/bin/doxygen (found version "1.8.5") found components:  doxygen dot
#  CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
#
# 	@sudo -E yum install -y epel-release
# 	@sudo -E yum install -y $(RPM_TEST_DEPENDS)
else
	$(error "This option currently works only on Ubuntu, Debian systems")
endif
	@pip3 install pexpect pyroute2 psutil

_ydk:
	@mkdir -p $(BR)/downloads/&&cd $(BR)/downloads/\
	&&wget https://github.com/CiscoDevNet/ydk-gen/archive/0.8.3.tar.gz\
	&&tar xvf 0.8.3.tar.gz && cd ydk-gen-0.8.3 && pip install -r requirements.txt\
	&&./generate.py --libydk -i && ./generate.py --python --core\
	&&pip3 install gen-api/python/ydk/dist/ydk*.tar.gz\
	&&./generate.py --python --bundle profiles/bundles/ietf_0_1_5.json\
	&&./generate.py --python --bundle profiles/bundles/openconfig_0_1_5.json\
	&&pip3 install gen-api/python/ietf-bundle/dist/ydk*.tar.gz\
	&&pip3 install gen-api/python/openconfig-bundle/dist/ydk*.tar.gz\
	&&cd ../\

_clean_dl:
	@rm -rf $(BR)/downloads

install-dep-extra: _clean_dl _libssh _libyang _libnetconf2 _sysrepo _netopeer2
	@cd ../ && rm -rf $(BR)/downloads

#Protobuf must not be compiled with multiple core, it requires too much memory
#gRPC can be compiled with cmake or autotools. autotools has been choosen
#if cmake is choosen use SSL, ZLIB distribution package and compile protobuf separately
install-dep-gnmi-extra:
ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID))
	@sudo -E apt-get $(APT_ARGS) -y --force-yes install $(DEB_GNMI_DEPENDS)
else ifeq ($(OS_ID),centos)
	@sudo -E yum install -y $(RPM_GNMI_DEPENDS)
else
	$(error "This option currently works only on Ubuntu, Debian, Centos or openSUSE systems")
endif
	@rm -rf $(BR)/downloads
	@mkdir -p $(BR)/downloads/&&cd $(BR)/downloads/\
	&& git clone --depth=1 -b v1.16.1 https://github.com/grpc/grpc \
	&& cd grpc && git submodule update --init \
	&& cd third_party/protobuf \
	&& ./autogen.sh && ./configure && make install \
	&& cd ../.. make && make install \
	&&cd .. && rm -rf $(BR)/downloads

install-vpp:
	@echo "please install vpp as vpp's guide from source if failed"
ifeq ($(PKG),deb)
#	@curl -s https://packagecloud.io/install/repositories/fdio/release/script.deb.sh | sudo bash
	@sudo -E apt-get -y --force-yes install vpp libvppinfra* vpp-plugin-* vpp-dev
else ifeq ($(PKG),rpm)
#	@curl -s https://packagecloud.io/install/repositories/fdio/release/script.rpm.sh | sudo bash
ifeq ($(OS_ID),centos)
	@sudo yum -y install vpp vpp-lib vpp-plugin* vpp-devel
endif
endif

install-test-extra: _clean_dl _libssh _test_python _ydk
	@cd ../ && rm -rf $(BR)/downloads

build-scvpp:
	@mkdir -p $(BR)/build-scvpp/; cd $(BR)/build-scvpp; \
	cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=/usr $(WS_ROOT)/src/scvpp/;\
	make install
	@# NEW INSTRUCTIONS TO BUILD-SCVPP MUST BE DECLARED ON A NEW LINE WITH '@'

test-scvpp: build-scvpp
	@cd $(BR)/build-scvpp; make test

build-plugins:
	@mkdir -p $(BR)/build-plugins/; cd $(BR)/build-plugins/; \
	cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=/usr $(WS_ROOT)/src/plugins/; \
	make install
	@# NEW INSTRUCTIONS TO BUILD-PLUGINS MUST BE DECLARED ON A NEW LINE WITH '@'

test-plugins: install-models
	@test/run_test.py --dir ./test/

build-gnmi:
	@mkdir -p $(BR)/build-gnmi/; cd $(BR)/build-gnmi/; \
	cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=/usr $(WS_ROOT)/src/gnmi/;make; \
	make install;
	@# NEW INSTRUCTIONS TO BUILD-GNMI MUST BE DECLARED ON A NEW LINE WITH '@'

build-package:
	@mkdir -p $(BR)/build-package/; cd $(BR)/build-package/;\
	$(cmake) -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr \
	-DENABLE_TESTS=OFF $(WS_ROOT)/src/; make package;
	@# NEW INSTRUCTIONS TO BUILD-PACKAGE MUST BE DECLARED ON A NEW LINE WITH
	@# '@' NOT WITH ';' ELSE BUILD-PACKAGE WILL NOT RETURN THE CORRECT
	@# RETURN CODE FOR JENKINS CI
	@rm -rf $(BR)/build-package/_CPack_Packages;

install-models:
	@cd src/plugins/yang/ietf; \
	sysrepoctl --install --yang=iana-if-type@2017-01-19.yang > /dev/null; \
	sysrepoctl --install --yang=ietf-interfaces@2018-02-20.yang > /dev/null; \
	sysrepoctl --install --yang=ietf-ip@2014-06-16.yang > /dev/null; \
	sysrepoctl --install --yang=ietf-nat@2017-11-16.yang > /dev/null; \
	sysrepoctl -e if-mib -m ietf-interfaces;
	@cd src/plugins/yang/openconfig; \
	sysrepoctl -S --install --yang=openconfig-local-routing@2017-05-15.yang > /dev/null; \
	sysrepoctl -S --install --yang=openconfig-interfaces@2018-08-07.yang > /dev/null; \
	sysrepoctl -S --install --yang=openconfig-if-ip@2018-01-05.yang > /dev/null; \
	sysrepoctl -S --install --yang=openconfig-acl@2018-11-21.yang > /dev/null;

uninstall-models:
	@ sysrepoctl -u -m ietf-ip > /dev/null; \
	sysrepoctl -u -m openconfig-acl > /dev/null; \
	sysrepoctl -u -m openconfig-if-ip > /dev/null; \
	sysrepoctl -u -m openconfig-local-routing > /dev/null; \
	sysrepoctl -u -m openconfig-if-aggregate > /dev/null; \
	sysrepoctl -u -m openconfig-interfaces > /dev/null; \
	sysrepoctl -u -m ietf-nat > /dev/null; \
	sysrepoctl -u -m iana-if-type > /dev/null; \
	sysrepoctl -u -m ietf-interfaces > /dev/null; \
	sysrepoctl -u -m openconfig-vlan-types > /dev/null;

clean:
	@if [ -d $(BR)/build-scvpp ] ;   then cd $(BR)/build-scvpp   && make clean; fi
	@if [ -d $(BR)/build-plugins ] ; then cd $(BR)/build-plugins && make clean; fi
	@if [ -d $(BR)/build-package ] ; then cd $(BR)/build-package && make clean; fi
	@if [ -d $(BR)/build-gnmi ] ;    then cd $(BR)/build-gnmi    && make clean; fi

distclean:
	@rm -rf $(BR)/build-scvpp
	@rm -rf $(BR)/build-plugins
	@rm -rf $(BR)/build-package
	@rm -rf $(BR)/build-gnmi

docker:
	@scripts/docker.sh

docker-test:
	@scripts/run_test.sh