1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 export WS_ROOT=$(CURDIR)
15 export BR=$(WS_ROOT)/build-root
16 CCACHE_DIR?=$(BR)/.ccache
20 MACHINE=$(shell uname -m)
22 ifeq ($(MACHINE),$(filter $(MACHINE),x86_64))
29 define disable_plugins
32 $(patsubst %,"plugin %_plugin.so { disable }",$(subst $(,), ,$(1))) \
37 MINIMAL_STARTUP_CONF=" \
40 cli-listen /run/vpp/cli.sock \
42 $(if $(wildcard startup.vpp),"exec startup.vpp",) \
44 $(if $(DPDK_CONFIG), "dpdk { $(DPDK_CONFIG) }",) \
45 $(call disable_plugins,$(DISABLED_PLUGINS)) \
48 GDB_ARGS= -ex "handle SIGUSR1 noprint nostop"
53 # We allow Darwin (MacOS) for docs generation; VPP build will still fail.
54 ifneq ($(shell uname),Darwin)
55 OS_ID = $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
56 OS_VERSION_ID= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
59 ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID))
61 else ifeq ($(filter rhel centos fedora opensuse,$(OS_ID)),$(OS_ID))
65 # +libganglia1-dev if building the gmond plugin
67 DEB_DEPENDS = curl build-essential autoconf automake bison ccache
68 DEB_DEPENDS += debhelper dkms git libtool libapr1-dev dh-systemd
69 DEB_DEPENDS += libconfuse-dev git-review exuberant-ctags cscope pkg-config
70 DEB_DEPENDS += lcov chrpath autoconf nasm indent clang-format libnuma-dev
71 DEB_DEPENDS += python-all python-dev python-virtualenv python-pip libffi6 check
72 DEB_DEPENDS += libboost-all-dev
73 ifeq ($(OS_VERSION_ID),14.04)
74 DEB_DEPENDS += openjdk-8-jdk-headless
75 DEB_DEPENDS += libssl-dev
76 else ifeq ($(OS_ID)-$(OS_VERSION_ID),debian-8)
77 DEB_DEPENDS += openjdk-8-jdk-headless
78 DEB_DEPENDS += libssl-dev
79 APT_ARGS = -t jessie-backports
80 else ifeq ($(OS_ID)-$(OS_VERSION_ID),debian-9)
81 DEB_DEPENDS += default-jdk-headless
82 DEB_DEPENDS += libssl1.0-dev
84 DEB_DEPENDS += default-jdk-headless
85 DEB_DEPENDS += libssl-dev
88 RPM_DEPENDS = redhat-lsb glibc-static java-1.8.0-openjdk-devel yum-utils
89 RPM_DEPENDS += apr-devel
90 RPM_DEPENDS += numactl-devel
91 RPM_DEPENDS += check check-devel
92 RPM_DEPENDS += boost boost-devel
94 ifeq ($(OS_ID)-$(OS_VERSION_ID),fedora-25)
95 RPM_DEPENDS += subunit subunit-devel
96 RPM_DEPENDS += openssl-devel
97 RPM_DEPENDS += python-devel
98 RPM_DEPENDS += python2-virtualenv
99 RPM_DEPENDS_GROUPS = 'C Development Tools and Libraries'
100 else ifeq ($(shell if [ "$(OS_ID)" = "fedora" ]; then test $(OS_VERSION_ID) -gt 25; echo $$?; fi),0)
101 RPM_DEPENDS += subunit subunit-devel
102 RPM_DEPENDS += compat-openssl10-devel
103 RPM_DEPENDS += python2-devel
104 RPM_DEPENDS += python2-virtualenv
105 RPM_DEPENDS_GROUPS = 'C Development Tools and Libraries'
107 RPM_DEPENDS += openssl-devel
108 RPM_DEPENDS += python-devel
109 RPM_DEPENDS += python-virtualenv
110 RPM_DEPENDS_GROUPS = 'Development Tools'
113 # +ganglia-devel if building the ganglia plugin
115 RPM_DEPENDS += chrpath libffi-devel rpm-build
116 ifeq ($(OS_ID),fedora)
118 else ifeq ($(findstring y,$(AESNI)),y)
119 RPM_DEPENDS += https://kojipkgs.fedoraproject.org//packages/nasm/2.12.02/2.fc26/x86_64/nasm-2.12.02-2.fc26.x86_64.rpm
122 SUSE_NAME= $(shell grep '^NAME=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g' | cut -d' ' -f2)
123 RPM_SUSE_BUILDTOOLS_DEPS = autoconf automake bison ccache check-devel chrpath clang indent libtool make
124 RPM_SUSE_DEVEL_DEPS = glibc-devel-static java-1_8_0-openjdk-devel libnuma-devel libopenssl-devel openssl-devel
125 RPM_SUSE_PYTHON_DEPS = python-devel python3-devel python-pip python3-pip python-rpm-macros python3-rpm-macros
126 RPM_SUSE_PLATFORM_DEPS = distribution-release shadow rpm-build
128 ifeq ($(OS_ID),opensuse)
129 ifneq ($(SUSE_NAME),Tumbleweed)
130 RPM_SUSE_DEVEL_DEPS += boost_1_61-devel gcc6
131 RPM_SUSE_PYTHON_DEPS += python-virtualenv
132 RPM_SUSE_BUILDTOOL_DEPS += https://download.opensuse.org/tumbleweed/repo/oss/suse/x86_64/nasm-2.13.01-2.2.x86_64.rpm
134 RPM_SUSE_DEVEL_DEPS += boost_1_65-devel gcc
135 RPM_SUSE_PYTHON_DEPS += python2-virtualenv
136 RPM_SUSE_BUILDTOOL_DEPS += nasm
140 RPM_SUSE_DEPENDS += $(RPM_SUSE_BUILDTOOLS_DEPS) $(RPM_SUSE_DEVEL_DEPS) $(RPM_SUSE_PYTHON_DEPS) $(RPM_SUSE_PLATFORM_DEPS)
142 ifneq ($(wildcard $(STARTUP_DIR)/startup.conf),)
143 STARTUP_CONF ?= $(STARTUP_DIR)/startup.conf
146 ifeq ($(findstring y,$(UNATTENDED)),y)
153 ifneq ($(SAMPLE_PLUGIN),no)
154 TARGETS += sample-plugin
157 .PHONY: help bootstrap wipe wipe-release build build-release rebuild rebuild-release
158 .PHONY: run run-release debug debug-release build-vat run-vat pkg-deb pkg-rpm
160 .PHONY: test test-debug retest retest-debug test-doc test-wipe-doc test-help test-wipe
161 .PHONY: test-cov test-wipe-cov
164 @echo "Make Targets:"
165 @echo " bootstrap - prepare tree for build"
166 @echo " install-dep - install software dependencies"
167 @echo " wipe - wipe all products of debug build "
168 @echo " wipe-release - wipe all products of release build "
169 @echo " build - build debug binaries"
170 @echo " build-release - build release binaries"
171 @echo " build-coverity - build coverity artifacts"
172 @echo " rebuild - wipe and build debug binares"
173 @echo " rebuild-release - wipe and build release binares"
174 @echo " run - run debug binary"
175 @echo " run-release - run release binary"
176 @echo " debug - run debug binary with debugger"
177 @echo " debug-release - run release binary with debugger"
178 @echo " test - build and run (basic) functional tests"
179 @echo " test-debug - build and run (basic) functional tests (debug build)"
180 @echo " test-all - build and run (all) functional tests"
181 @echo " test-all-debug - build and run (all) functional tests (debug build)"
182 @echo " test-shell - enter shell with test environment"
183 @echo " test-shell-debug - enter shell with test environment (debug build)"
184 @echo " test-wipe - wipe files generated by unit tests"
185 @echo " retest - run functional tests"
186 @echo " retest-debug - run functional tests (debug build)"
187 @echo " test-help - show help on test framework"
188 @echo " run-vat - run vpp-api-test tool"
189 @echo " pkg-deb - build DEB packages"
190 @echo " pkg-rpm - build RPM packages"
191 @echo " dpdk-install-dev - install DPDK development packages"
192 @echo " ctags - (re)generate ctags database"
193 @echo " gtags - (re)generate gtags database"
194 @echo " cscope - (re)generate cscope database"
195 @echo " checkstyle - check coding style"
196 @echo " fixstyle - fix coding style"
197 @echo " doxygen - (re)generate documentation"
198 @echo " bootstrap-doxygen - setup Doxygen dependencies"
199 @echo " wipe-doxygen - wipe all generated documentation"
200 @echo " test-doc - generate documentation for test framework"
201 @echo " test-wipe-doc - wipe documentation for test framework"
202 @echo " test-cov - generate code coverage report for test framework"
203 @echo " test-wipe-cov - wipe code coverage report for test framework"
204 @echo " test-checkstyle - check PEP8 compliance for test framework"
206 @echo "Make Arguments:"
207 @echo " V=[0|1] - set build verbosity level"
208 @echo " STARTUP_CONF=<path> - startup configuration file"
209 @echo " (e.g. /etc/vpp/startup.conf)"
210 @echo " STARTUP_DIR=<path> - startup drectory (e.g. /etc/vpp)"
211 @echo " It also sets STARTUP_CONF if"
212 @echo " startup.conf file is present"
213 @echo " GDB=<path> - gdb binary to use for debugging"
214 @echo " PLATFORM=<name> - target platform. default is vpp"
215 @echo " TEST=<filter> - apply filter to test set, see test-help"
216 @echo " DPDK_CONFIG=<conf> - add specified dpdk config commands to"
217 @echo " autogenerated startup.conf"
218 @echo " (e.g. \"no-pci\" )"
219 @echo " SAMPLE_PLUGIN=yes - in addition build/run/debug sample plugin"
220 @echo " DISABLED_PLUGINS=<list> - comma separated list of plugins which"
221 @echo " should not be loaded"
223 @echo "Current Argument Values:"
225 @echo " STARTUP_CONF = $(STARTUP_CONF)"
226 @echo " STARTUP_DIR = $(STARTUP_DIR)"
227 @echo " GDB = $(GDB)"
228 @echo " PLATFORM = $(PLATFORM)"
229 @echo " DPDK_VERSION = $(DPDK_VERSION)"
230 @echo " DPDK_CONFIG = $(DPDK_CONFIG)"
231 @echo " SAMPLE_PLUGIN = $(SAMPLE_PLUGIN)"
232 @echo " DISABLED_PLUGINS = $(DISABLED_PLUGINS)"
235 ifeq ($(findstring y,$(UNATTENDED)),y)
238 ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID))
239 @MISSING=$$(apt-get install -y -qq -s $(DEB_DEPENDS) | grep "^Inst ") ; \
240 if [ -n "$$MISSING" ] ; then \
241 echo "\nPlease install missing packages: \n$$MISSING\n" ; \
242 echo "by executing \"make install-dep\"\n" ; \
246 else ifneq ("$(wildcard /etc/redhat-release)","")
247 @for i in $(RPM_DEPENDS) ; do \
248 RPM=$$(basename -s .rpm "$${i##*/}" | cut -d- -f1,2,3) ; \
249 MISSING+=$$(rpm -q $$RPM | grep "^package") ; \
251 if [ -n "$$MISSING" ] ; then \
252 echo "Please install missing RPMs: \n$$MISSING\n" ; \
253 echo "by executing \"make install-dep\"\n" ; \
258 @echo "SOURCE_PATH = $(WS_ROOT)" > $(BR)/build-config.mk
259 @echo "#!/bin/bash\n" > $(BR)/path_setup
260 @echo 'export PATH=$(BR)/tools/ccache-bin:$$PATH' >> $(BR)/path_setup
261 @echo 'export PATH=$(BR)/tools/bin:$$PATH' >> $(BR)/path_setup
262 @echo 'export CCACHE_DIR=$(CCACHE_DIR)' >> $(BR)/path_setup
264 ifeq ("$(wildcard /usr/bin/ccache )","")
265 @echo "WARNING: Please install ccache AYEC and re-run this script"
267 @rm -rf $(BR)/tools/ccache-bin
268 @mkdir -p $(BR)/tools/ccache-bin
269 @ln -s /usr/bin/ccache $(BR)/tools/ccache-bin/gcc
270 @ln -s /usr/bin/ccache $(BR)/tools/ccache-bin/g++
272 @make -C $(BR) V=$(V) is_build_tool=yes tools-install
275 bootstrap: $(BR)/.bootstrap.ok
278 ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID))
279 ifeq ($(OS_VERSION_ID),14.04)
280 @sudo -E apt-get $(CONFIRM) $(FORCE) install software-properties-common
281 @sudo -E add-apt-repository ppa:openjdk-r/ppa $(CONFIRM)
283 ifeq ($(OS_ID)-$(OS_VERSION_ID),debian-8)
284 @grep -q jessie-backports /etc/apt/sources.list /etc/apt/sources.list.d/* 2> /dev/null \
285 || ( echo "Please install jessie-backports" ; exit 1 )
287 @sudo -E apt-get update
288 @sudo -E apt-get $(APT_ARGS) $(CONFIRM) $(FORCE) install $(DEB_DEPENDS)
289 else ifneq ("$(wildcard /etc/redhat-release)","")
290 @sudo -E yum groupinstall $(CONFIRM) $(RPM_DEPENDS_GROUPS)
291 @sudo -E yum install $(CONFIRM) $(RPM_DEPENDS)
292 @sudo -E debuginfo-install $(CONFIRM) glibc openssl-libs zlib
293 else ifeq ($(filter opensuse,$(OS_ID)),$(OS_ID))
294 @sudo -E zypper refresh
295 @sudo -E zypper install -y $(RPM_SUSE_DEPENDS)
297 $(error "This option currently works only on Ubuntu, Debian, Centos or openSUSE systems")
301 @make -C $(BR) PLATFORM=$(PLATFORM) TAG=$(1) $(2)
304 $(BR)/scripts/.version:
305 ifneq ("$(wildcard /etc/redhat-release)","")
306 $(shell $(BR)/scripts/version rpm-string > $(BR)/scripts/.version)
308 $(shell $(BR)/scripts/version > $(BR)/scripts/.version)
311 DIST_FILE = $(BR)/vpp-$(shell src/scripts/version).tar
312 DIST_SUBDIR = vpp-$(shell src/scripts/version|cut -f1 -d-)
315 @if git rev-parse 2> /dev/null ; then \
317 --prefix=$(DIST_SUBDIR)/ \
321 git describe > $(BR)/.version ; \
323 (cd .. ; tar -cf $(DIST_FILE) $(DIST_SUBDIR) --exclude=*.tar) ; \
324 src/scripts/version > $(BR)/.version ; \
327 --file $(DIST_FILE) \
328 --transform='s,.*/.version,$(DIST_SUBDIR)/src/scripts/.version,' \
330 @$(RM) $(BR)/.version $(DIST_FILE).xz
331 @xz -v --threads=0 $(DIST_FILE)
332 @$(RM) $(BR)/vpp-latest.tar.xz
333 @ln -rs $(DIST_FILE).xz $(BR)/vpp-latest.tar.xz
335 build: $(BR)/.bootstrap.ok
336 $(call make,$(PLATFORM)_debug,$(addsuffix -install,$(TARGETS)))
339 @$(RM) $(BR)/*.tar.xz
341 wipe: wipedist $(BR)/.bootstrap.ok
342 $(call make,$(PLATFORM)_debug,$(addsuffix -wipe,$(TARGETS)))
346 build-release: $(BR)/.bootstrap.ok
347 $(call make,$(PLATFORM),$(addsuffix -install,$(TARGETS)))
349 wipe-release: $(BR)/.bootstrap.ok
350 $(call make,$(PLATFORM),$(addsuffix -wipe,$(TARGETS)))
352 rebuild-release: wipe-release build-release
354 export VPP_PYTHON_PREFIX=$(BR)/python
356 libexpand = $(subst $(subst ,, ),:,$(foreach lib,$(1),$(BR)/install-$(2)-native/vpp/$(lib)/$(3)))
359 $(if $(filter-out $(3),retest),make -C $(BR) PLATFORM=$(1) TAG=$(2) vpp-install,)
360 $(eval libs:=lib lib64)
362 TEST_DIR=$(WS_ROOT)/test \
363 VPP_TEST_BUILD_DIR=$(BR)/build-$(2)-native \
364 VPP_TEST_BIN=$(BR)/install-$(2)-native/vpp/bin/vpp \
365 VPP_TEST_PLUGIN_PATH=$(call libexpand,$(libs),$(2),vpp_plugins) \
366 VPP_TEST_INSTALL_PATH=$(BR)/install-$(2)-native/ \
367 LD_LIBRARY_PATH=$(call libexpand,$(libs),$(2),) \
368 EXTENDED_TESTS=$(EXTENDED_TESTS) \
375 $(call test,vpp,vpp,test)
377 test-debug: bootstrap
378 $(call test,vpp,vpp_debug,test)
381 $(eval EXTENDED_TESTS=yes)
382 $(call test,vpp,vpp,test)
384 test-all-debug: bootstrap
385 $(eval EXTENDED_TESTS=yes)
386 $(call test,vpp,vpp_debug,test)
394 test-shell: bootstrap
395 $(call test,vpp,vpp,shell)
397 test-shell-debug: bootstrap
398 $(call test,vpp,vpp_debug,shell)
404 @make -C test wipe-doc
407 $(eval EXTENDED_TESTS=yes)
408 $(call test,vpp,vpp_gcov,cov)
411 @make -C test wipe-cov
414 @make -C test checkstyle
417 $(call test,vpp,vpp,retest)
420 $(call test,vpp,vpp_debug,retest)
422 STARTUP_DIR ?= $(PWD)
423 ifeq ("$(wildcard $(STARTUP_CONF))","")
425 @echo "WARNING: STARTUP_CONF not defined or file doesn't exist."
426 @echo " Running with minimal startup config: $(MINIMAL_STARTUP_CONF)\n"
427 @cd $(STARTUP_DIR) && \
428 sudo $(2) $(1)/vpp/bin/vpp $(MINIMAL_STARTUP_CONF) \
429 plugin_path $(subst $(subst ,, ),:,$(wildcard $(1)/*/lib*/vpp_plugins))
433 @cd $(STARTUP_DIR) && \
434 sudo $(2) $(1)/vpp/bin/vpp $(shell cat $(STARTUP_CONF) | sed -e 's/#.*//') \
435 plugin_path $(subst $(subst ,, ),:,$(wildcard $(1)/*/lib*/vpp_plugins))
440 @find . \( -name '*\.[chyS]' -o -name '*\.java' -o -name '*\.lex' \) -and \
441 \( -not -path './build-root*' -o -path \
442 './build-root/build-vpp_debug-native/dpdk*' \) > $@
447 $(call run, $(BR)/install-$(PLATFORM)_debug-native)
450 $(call run, $(BR)/install-$(PLATFORM)-native)
453 $(call run, $(BR)/install-$(PLATFORM)_debug-native,$(GDB) $(GDB_ARGS) --args)
456 $(call make,$(PLATFORM)_coverity,install-packages)
459 $(call run, $(BR)/install-$(PLATFORM)-native,$(GDB) $(GDB_ARGS) --args)
462 $(call make,$(PLATFORM)_debug,vpp-api-test-install)
465 @sudo $(BR)/install-$(PLATFORM)_debug-native/vpp/bin/vpp_api_test
468 $(call make,$(PLATFORM),install-deb)
474 make -C extras/rpm srpm
477 make -C dpdk install-$(PKG)
480 @ctags --totals --tag-relative -L $<
484 @gtags --gtagslabel=ctags
490 @build-root/scripts/checkstyle.sh
493 @build-root/scripts/checkstyle.sh --fix
496 # Build the documentation
499 # Doxygen configuration and our utility scripts
500 export DOXY_DIR ?= $(WS_ROOT)/doxygen
503 @OS_ID="$(OS_ID)" make -C $(DOXY_DIR) $@
506 .PHONY: bootstrap-doxygen doxygen wipe-doxygen
518 @echo "========================================================================"
520 @echo "========================================================================"
524 verify: install-dep $(BR)/.bootstrap.ok dpdk-install-dev
525 $(call banner,"Building for PLATFORM=vpp using gcc")
526 @make -C build-root PLATFORM=vpp TAG=vpp wipe-all install-packages
527 ifeq ($(OS_ID)-$(OS_VERSION_ID),ubuntu-16.04)
528 $(call banner,"Installing dependencies")
529 @sudo -E apt-get update
530 @sudo -E apt-get $(CONFIRM) $(FORCE) install clang
531 $(call banner,"Building for PLATFORM=vpp using clang")
532 @make -C build-root CC=clang PLATFORM=vpp TAG=vpp_clang wipe-all install-packages
534 $(call banner,"Building sample-plugin")
535 @make -C build-root PLATFORM=vpp TAG=vpp sample-plugin-install
536 $(call banner,"Building $(PKG) packages")
538 ifeq ($(OS_ID)-$(OS_VERSION_ID),ubuntu-16.04)
539 @make COMPRESS_FAILED_TEST_LOGS=yes RETRIES=3 test