LISP: fix IID in decap
[vpp.git] / Makefile
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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 export WS_ROOT=$(CURDIR)
15 export BR=$(WS_ROOT)/build-root
16 CCACHE_DIR?=$(BR)/.ccache
17 GDB?=gdb
18 PLATFORM?=vpp
19
20 MINIMAL_STARTUP_CONF="unix { interactive }"
21
22 GDB_ARGS= -ex "handle SIGUSR1 noprint nostop"
23
24 #
25 # OS Detection
26 #
27 # We allow Darwin (MacOS) for docs generation; VPP build will still fail.
28 ifneq ($(shell uname),Darwin)
29 OS_ID        = $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
30 OS_VERSION_ID= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
31 endif
32
33 ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID))
34 PKG=deb
35 else ifeq ($(filter rhel centos,$(OS_ID)),$(OS_ID))
36 PKG=rpm
37 endif
38
39 DEB_DEPENDS  = curl build-essential autoconf automake bison libssl-dev ccache
40 DEB_DEPENDS += debhelper dkms git libtool libganglia1-dev libapr1-dev dh-systemd
41 DEB_DEPENDS += libconfuse-dev git-review exuberant-ctags cscope pkg-config
42 DEB_DEPENDS += lcov chrpath autoconf nasm
43 DEB_DEPENDS += python-all python-dev python-virtualenv python-pip libffi6
44 ifeq ($(OS_VERSION_ID),14.04)
45         DEB_DEPENDS += openjdk-8-jdk-headless
46 else
47         DEB_DEPENDS += default-jdk-headless
48 endif
49
50 RPM_DEPENDS_GROUPS = 'Development Tools'
51 RPM_DEPENDS  = redhat-lsb glibc-static java-1.8.0-openjdk-devel yum-utils
52 RPM_DEPENDS += openssl-devel https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm apr-devel
53 RPM_DEPENDS += python-devel python-virtualenv lcov chrpath libffi-devel
54 RPM_DEPENDS += https://kojipkgs.fedoraproject.org//packages/nasm/2.12.02/2.fc26/x86_64/nasm-2.12.02-2.fc26.x86_64.rpm
55 EPEL_DEPENDS = libconfuse-devel ganglia-devel epel-rpm-macros
56
57 ifneq ($(wildcard $(STARTUP_DIR)/startup.conf),)
58         STARTUP_CONF ?= $(STARTUP_DIR)/startup.conf
59 endif
60
61 ifeq ($(findstring y,$(UNATTENDED)),y)
62 CONFIRM=-y
63 FORCE=--force-yes
64 endif
65
66 .PHONY: help bootstrap wipe wipe-release build build-release rebuild rebuild-release
67 .PHONY: run run-release debug debug-release build-vat run-vat pkg-deb pkg-rpm
68 .PHONY: ctags cscope
69 .PHONY: test test-debug retest retest-debug test-doc test-wipe-doc test-help test-wipe
70 .PHONY: test-cov test-wipe-cov
71
72 help:
73         @echo "Make Targets:"
74         @echo " bootstrap           - prepare tree for build"
75         @echo " install-dep         - install software dependencies"
76         @echo " wipe                - wipe all products of debug build "
77         @echo " wipe-release        - wipe all products of release build "
78         @echo " build               - build debug binaries"
79         @echo " build-release       - build release binaries"
80         @echo " build-coverity      - build coverity artifacts"
81         @echo " rebuild             - wipe and build debug binares"
82         @echo " rebuild-release     - wipe and build release binares"
83         @echo " run                 - run debug binary"
84         @echo " run-release         - run release binary"
85         @echo " debug               - run debug binary with debugger"
86         @echo " debug-release       - run release binary with debugger"
87         @echo " test                - build and run (basic) functional tests"
88         @echo " test-debug          - build and run (basic) functional tests (debug build)"
89         @echo " test-all            - build and run (all) functional tests"
90         @echo " test-all-debug      - build and run (all) functional tests (debug build)"
91         @echo " test-shell          - enter shell with test environment"
92         @echo " test-shell-debug    - enter shell with test environment (debug build)"
93         @echo " test-wipe           - wipe files generated by unit tests"
94         @echo " retest              - run functional tests"
95         @echo " retest-debug        - run functional tests (debug build)"
96         @echo " test-help           - show help on test framework"
97         @echo " run-vat             - run vpp-api-test tool"
98         @echo " pkg-deb             - build DEB packages"
99         @echo " pkg-rpm             - build RPM packages"
100         @echo " dpdk-install-dev    - install DPDK development packages"
101         @echo " ctags               - (re)generate ctags database"
102         @echo " gtags               - (re)generate gtags database"
103         @echo " cscope              - (re)generate cscope database"
104         @echo " checkstyle          - check coding style"
105         @echo " fixstyle            - fix coding style"
106         @echo " doxygen             - (re)generate documentation"
107         @echo " bootstrap-doxygen   - setup Doxygen dependencies"
108         @echo " wipe-doxygen        - wipe all generated documentation"
109         @echo " test-doc            - generate documentation for test framework"
110         @echo " test-wipe-doc       - wipe documentation for test framework"
111         @echo " test-cov            - generate code coverage report for test framework"
112         @echo " test-wipe-cov       - wipe code coverage report for test framework"
113         @echo " test-checkstyle     - check PEP8 compliance for test framework"
114         @echo ""
115         @echo "Make Arguments:"
116         @echo " V=[0|1]             - set build verbosity level"
117         @echo " STARTUP_CONF=<path> - startup configuration file"
118         @echo "                       (e.g. /etc/vpp/startup.conf)"
119         @echo " STARTUP_DIR=<path>  - startup drectory (e.g. /etc/vpp)"
120         @echo "                       It also sets STARTUP_CONF if"
121         @echo "                       startup.conf file is present"
122         @echo " GDB=<path>          - gdb binary to use for debugging"
123         @echo " PLATFORM=<name>     - target platform. default is vpp"
124         @echo " TEST=<filter>       - apply filter to test set, see test-help"
125         @echo ""
126         @echo "Current Argument Values:"
127         @echo " V            = $(V)"
128         @echo " STARTUP_CONF = $(STARTUP_CONF)"
129         @echo " STARTUP_DIR  = $(STARTUP_DIR)"
130         @echo " GDB          = $(GDB)"
131         @echo " PLATFORM     = $(PLATFORM)"
132         @echo " DPDK_VERSION = $(DPDK_VERSION)"
133
134 $(BR)/.bootstrap.ok:
135 ifeq ($(findstring y,$(UNATTENDED)),y)
136         make install-dep
137 endif
138 ifeq ($(OS_ID),ubuntu)
139         @MISSING=$$(apt-get install -y -qq -s $(DEB_DEPENDS) | grep "^Inst ") ; \
140         if [ -n "$$MISSING" ] ; then \
141           echo "\nPlease install missing packages: \n$$MISSING\n" ; \
142           echo "by executing \"make install-dep\"\n" ; \
143           exit 1 ; \
144         fi ; \
145         exit 0
146 else ifneq ("$(wildcard /etc/redhat-release)","")
147         @for i in $(RPM_DEPENDS) $(EPEL_DEPENDS) ; do \
148             RPM=$$(basename -s .rpm "$${i##*/}" | cut -d- -f1,2,3)  ;   \
149             if [[ "$$RPM" =~ "epel-release-latest" ]] ; then            \
150                 MISSING+=$$(rpm -q epel-release | grep "^package") ;    \
151             else                                                        \
152                 MISSING+=$$(rpm -q $$RPM | grep "^package")        ;    \
153             fi                                                     ;    \
154         done                                                       ;    \
155         if [ -n "$$MISSING" ] ; then \
156           echo "Please install missing RPMs: \n$$MISSING\n" ; \
157           echo "by executing \"make install-dep\"\n" ; \
158           exit 1 ; \
159         fi ; \
160         exit 0
161 endif
162         @echo "SOURCE_PATH = $(WS_ROOT)"                   > $(BR)/build-config.mk
163         @echo "#!/bin/bash\n"                              > $(BR)/path_setup
164         @echo 'export PATH=$(BR)/tools/ccache-bin:$$PATH' >> $(BR)/path_setup
165         @echo 'export PATH=$(BR)/tools/bin:$$PATH'        >> $(BR)/path_setup
166         @echo 'export CCACHE_DIR=$(CCACHE_DIR)'           >> $(BR)/path_setup
167
168 ifeq ("$(wildcard /usr/bin/ccache )","")
169         @echo "WARNING: Please install ccache AYEC and re-run this script"
170 else
171         @rm -rf $(BR)/tools/ccache-bin
172         @mkdir -p $(BR)/tools/ccache-bin
173         @ln -s /usr/bin/ccache $(BR)/tools/ccache-bin/gcc
174         @ln -s /usr/bin/ccache $(BR)/tools/ccache-bin/g++
175 endif
176         @make -C $(BR) V=$(V) is_build_tool=yes tools-install
177         @touch $@
178
179 bootstrap: $(BR)/.bootstrap.ok
180
181 install-dep:
182 ifeq ($(OS_ID),ubuntu)
183 ifeq ($(OS_VERSION_ID),14.04)
184         @sudo -E apt-get $(CONFIRM) $(FORCE) install software-properties-common
185         @sudo -E add-apt-repository ppa:openjdk-r/ppa $(CONFIRM)
186 endif
187         @sudo -E apt-get update
188         @sudo -E apt-get $(CONFIRM) $(FORCE) install $(DEB_DEPENDS)
189 else ifneq ("$(wildcard /etc/redhat-release)","")
190         @sudo -E yum groupinstall $(CONFIRM) $(RPM_DEPENDS_GROUPS)
191         @sudo -E yum install $(CONFIRM) $(RPM_DEPENDS)
192         @sudo -E yum install $(CONFIRM) --enablerepo=epel $(EPEL_DEPENDS)
193         @sudo -E debuginfo-install $(CONFIRM) glibc-2.17-106.el7_2.4.x86_64 openssl-libs-1.0.1e-51.el7_2.4.x86_64 zlib-1.2.7-15.el7.x86_64
194 else
195         $(error "This option currently works only on Ubuntu or Centos systems")
196 endif
197
198 define make
199         @make -C $(BR) PLATFORM=$(PLATFORM) TAG=$(1) $(2)
200 endef
201
202 $(BR)/scripts/.version:
203 ifneq ("$(wildcard /etc/redhat-release)","")
204         $(shell $(BR)/scripts/version rpm-string > $(BR)/scripts/.version)
205 else
206         $(shell $(BR)/scripts/version > $(BR)/scripts/.version)
207 endif
208
209 dist:   $(BR)/scripts/.version
210         $(MAKE) verstring=$(PLATFORM)-$(shell cat $(BR)/scripts/.version) prefix=$(PLATFORM) distversion
211
212 distversion:    $(BR)/scripts/.version
213         $(BR)/scripts/verdist ${BR} ${prefix}-$(shell $(BR)/scripts/version rpm-version) ${verstring}
214         mv $(verstring).tar.gz $(BR)/rpm
215
216 build: $(BR)/.bootstrap.ok
217         $(call make,$(PLATFORM)_debug,vpp-install)
218
219 wipedist:
220         $(RM) $(BR)/scripts/.version $(BR)/rpm/*.tar.gz
221
222 wipe: wipedist $(BR)/.bootstrap.ok
223         $(call make,$(PLATFORM)_debug,vpp-wipe)
224
225 rebuild: wipe build
226
227 build-release: $(BR)/.bootstrap.ok
228         $(call make,$(PLATFORM),vpp-install)
229
230 wipe-release: $(BR)/.bootstrap.ok
231         $(call make,$(PLATFORM),vpp-wipe)
232
233 rebuild-release: wipe-release build-release
234
235 export VPP_PYTHON_PREFIX=$(BR)/python
236
237 define test
238         $(if $(filter-out $(3),retest),make -C $(BR) PLATFORM=$(1) TAG=$(2) vpp-install,)
239         make -C test \
240           TEST_DIR=$(WS_ROOT)/test \
241           VPP_TEST_BUILD_DIR=$(BR)/build-$(2)-native \
242           VPP_TEST_BIN=$(BR)/install-$(2)-native/vpp/bin/vpp \
243           VPP_TEST_PLUGIN_PATH=$(BR)/install-$(2)-native/vpp/lib64/vpp_plugins \
244           VPP_TEST_INSTALL_PATH=$(BR)/install-$(2)-native/ \
245           LD_LIBRARY_PATH=$(BR)/install-$(2)-native/vpp/lib64/ \
246           EXTENDED_TESTS=$(EXTENDED_TESTS) \
247           $(3)
248 endef
249
250 test: bootstrap
251         $(call test,vpp,vpp,test)
252
253 test-debug: bootstrap
254         $(call test,vpp,vpp_debug,test)
255
256 test-all: bootstrap
257         $(eval EXTENDED_TESTS=yes)
258         $(call test,vpp,vpp,test)
259
260 test-all-debug: bootstrap
261         $(eval EXTENDED_TESTS=yes)
262         $(call test,vpp,vpp_debug,test)
263
264 test-help:
265         @make -C test help
266
267 test-wipe:
268         @make -C test wipe
269
270 test-shell: bootstrap
271         $(call test,vpp,vpp,shell)
272
273 test-shell-debug: bootstrap
274         $(call test,vpp,vpp_debug,shell)
275
276 test-doc:
277         @make -C test doc
278
279 test-wipe-doc:
280         @make -C test wipe-doc
281
282 test-cov: bootstrap
283         $(eval EXTENDED_TESTS=yes)
284         $(call test,vpp,vpp_gcov,cov)
285
286 test-wipe-cov:
287         @make -C test wipe-cov
288
289 test-checkstyle:
290         @make -C test checkstyle
291
292 retest:
293         $(call test,vpp,vpp,retest)
294
295 retest-debug:
296         $(call test,vpp,vpp_debug,retest)
297
298 STARTUP_DIR ?= $(PWD)
299 ifeq ("$(wildcard $(STARTUP_CONF))","")
300 define run
301         @echo "WARNING: STARTUP_CONF not defined or file doesn't exist."
302         @echo "         Running with minimal startup config: $(MINIMAL_STARTUP_CONF)\n"
303         @cd $(STARTUP_DIR) && \
304           sudo $(2) $(1)/vpp/bin/vpp $(MINIMAL_STARTUP_CONF) plugin_path $(1)/vpp/lib64/vpp_plugins
305 endef
306 else
307 define run
308         @cd $(STARTUP_DIR) && \
309           sudo $(2) $(1)/vpp/bin/vpp $(shell cat $(STARTUP_CONF) | sed -e 's/#.*//') plugin_path $(1)/vpp/lib64/vpp_plugins
310 endef
311 endif
312
313 %.files: .FORCE
314         @find . \( -name '*\.[chyS]' -o -name '*\.java' -o -name '*\.lex' \) -and \
315                 \( -not -path './build-root*' -o -path \
316                 './build-root/build-vpp_debug-native/dpdk*' \) > $@
317
318 .FORCE:
319
320 run:
321         $(call run, $(BR)/install-$(PLATFORM)_debug-native)
322
323 run-release:
324         $(call run, $(BR)/install-$(PLATFORM)-native)
325
326 debug:
327         $(call run, $(BR)/install-$(PLATFORM)_debug-native,$(GDB) $(GDB_ARGS) --args)
328
329 build-coverity: 
330         $(call make,$(PLATFORM)_coverity,install-packages)
331
332 debug-release:
333         $(call run, $(BR)/install-$(PLATFORM)-native,$(GDB) $(GDB_ARGS) --args)
334
335 build-vat:
336         $(call make,$(PLATFORM)_debug,vpp-api-test-install)
337
338 run-vat:
339         @sudo $(BR)/install-$(PLATFORM)_debug-native/vpp/bin/vpp_api_test
340
341 pkg-deb:
342         $(call make,$(PLATFORM),install-deb)
343
344 pkg-rpm: dist
345         $(call make,$(PLATFORM),install-rpm)
346
347 dpdk-install-dev:
348         make -C dpdk install-$(PKG)
349
350 ctags: ctags.files
351         @ctags --totals --tag-relative -L $<
352         @rm $<
353
354 gtags: ctags
355         @gtags --gtagslabel=ctags
356
357 cscope: cscope.files
358         @cscope -b -q -v
359
360 checkstyle:
361         @build-root/scripts/checkstyle.sh
362
363 fixstyle:
364         @build-root/scripts/checkstyle.sh --fix
365
366 #
367 # Build the documentation
368 #
369
370 # Doxygen configuration and our utility scripts
371 export DOXY_DIR ?= $(WS_ROOT)/doxygen
372
373 define make-doxy
374         @OS_ID="$(OS_ID)" make -C $(DOXY_DIR) $@
375 endef
376
377 .PHONY: bootstrap-doxygen doxygen wipe-doxygen
378
379 bootstrap-doxygen:
380         $(call make-doxy)
381
382 doxygen:
383         $(call make-doxy)
384
385 wipe-doxygen:
386         $(call make-doxy)
387
388 define banner
389         @echo "========================================================================"
390         @echo " $(1)"
391         @echo "========================================================================"
392         @echo " "
393 endef
394
395 verify: install-dep $(BR)/.bootstrap.ok dpdk-install-dev
396         $(call banner,"Building for PLATFORM=vpp using gcc")
397         @make -C build-root PLATFORM=vpp TAG=vpp wipe-all install-packages
398 ifeq ($(OS_ID)-$(OS_VERSION_ID),ubuntu-16.04)
399         $(call banner,"Installing dependencies")
400         @sudo -E apt-get update
401         @sudo -E apt-get $(CONFIRM) $(FORCE) install clang
402         $(call banner,"Building for PLATFORM=vpp using clang")
403         @make -C build-root CC=clang PLATFORM=vpp TAG=vpp_clang wipe-all install-packages
404 endif
405         $(call banner,"Building $(PKG) packages")
406         @make pkg-$(PKG)
407         @make test-all
408
409