vppctl: Do not use sudo if already root
[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 WS_ROOT=$(CURDIR)
15 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 DEB_DEPENDS  = curl build-essential autoconf automake bison libssl-dev ccache
34 DEB_DEPENDS += debhelper dkms git libtool libganglia1-dev libapr1-dev dh-systemd
35 DEB_DEPENDS += libconfuse-dev git-review exuberant-ctags cscope
36 DEB_DEPENDS += python-dev python-virtualenv
37 ifeq ($(OS_VERSION_ID),14.04)
38         DEB_DEPENDS += openjdk-8-jdk-headless
39 else
40         DEB_DEPENDS += default-jdk-headless
41 endif
42
43 RPM_DEPENDS_GROUPS = 'Development Tools'
44 RPM_DEPENDS  = redhat-lsb glibc-static java-1.8.0-openjdk-devel yum-utils
45 RPM_DEPENDS += openssl-devel https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm apr-devel
46 RPM_DEPENDS += python-devel
47 EPEL_DEPENDS = libconfuse-devel ganglia-devel
48
49 ifneq ($(wildcard $(STARTUP_DIR)/startup.conf),)
50         STARTUP_CONF ?= $(STARTUP_DIR)/startup.conf
51 endif
52
53 ifeq ($(findstring y,$(UNATTENDED)),y)
54 CONFIRM=-y
55 FORCE=--force-yes
56 endif
57
58 .PHONY: help bootstrap wipe wipe-release build build-release rebuild rebuild-release
59 .PHONY: run run-release debug debug-release build-vat run-vat pkg-deb pkg-rpm
60 .PHONY: ctags cscope plugins plugins-release build-vpp-api
61 .PHONY: test test-debug retest retest-debug test-doc test-wipe-doc test-help test-wipe
62
63 help:
64         @echo "Make Targets:"
65         @echo " bootstrap           - prepare tree for build"
66         @echo " install-dep         - install software dependencies"
67         @echo " wipe                - wipe all products of debug build "
68         @echo " wipe-release        - wipe all products of release build "
69         @echo " build               - build debug binaries"
70         @echo " build-release       - build release binaries"
71         @echo " plugins             - build debug plugin binaries"
72         @echo " plugins-release     - build release plugin binaries"
73         @echo " rebuild             - wipe and build debug binares"
74         @echo " rebuild-release     - wipe and build release binares"
75         @echo " run                 - run debug binary"
76         @echo " run-release         - run release binary"
77         @echo " debug               - run debug binary with debugger"
78         @echo " debug-release       - run release binary with debugger"
79         @echo " test                - build and run functional tests"
80         @echo " test-debug          - build and run functional tests (debug build)"
81         @echo " test-wipe           - wipe files generated by unit tests"
82         @echo " retest              - run functional tests"
83         @echo " retest-debug        - run functional tests (debug build)"
84         @echo " test-help           - show help on test framework"
85         @echo " build-vat           - build vpp-api-test tool"
86         @echo " build-vpp-api       - build vpp-api"
87         @echo " run-vat             - run vpp-api-test tool"
88         @echo " pkg-deb             - build DEB packages"
89         @echo " pkg-rpm             - build RPM packages"
90         @echo " ctags               - (re)generate ctags database"
91         @echo " gtags               - (re)generate gtags database"
92         @echo " cscope              - (re)generate cscope database"
93         @echo " checkstyle          - check coding style"
94         @echo " fixstyle            - fix coding style"
95         @echo " doxygen             - (re)generate documentation"
96         @echo " bootstrap-doxygen   - setup Doxygen dependencies"
97         @echo " wipe-doxygen        - wipe all generated documentation"
98         @echo " test-doc            - generate documentation for test framework"
99         @echo " test-wipe-doc       - wipe documentation for test framework"
100         @echo ""
101         @echo "Make Arguments:"
102         @echo " V=[0|1]             - set build verbosity level"
103         @echo " STARTUP_CONF=<path> - startup configuration file"
104         @echo "                       (e.g. /etc/vpp/startup.conf)"
105         @echo " STARTUP_DIR=<path>  - startup drectory (e.g. /etc/vpp)"
106         @echo "                       It also sets STARTUP_CONF if"
107         @echo "                       startup.conf file is present"
108         @echo " GDB=<path>          - gdb binary to use for debugging"
109         @echo " PLATFORM=<name>     - target platform. default is vpp"
110         @echo " TEST=<name>         - only run specific test"
111         @echo ""
112         @echo "Current Argument Values:"
113         @echo " V            = $(V)"
114         @echo " STARTUP_CONF = $(STARTUP_CONF)"
115         @echo " STARTUP_DIR  = $(STARTUP_DIR)"
116         @echo " GDB          = $(GDB)"
117         @echo " PLATFORM     = $(PLATFORM)"
118         @echo " DPDK_VERSION = $(DPDK_VERSION)"
119
120 $(BR)/.bootstrap.ok:
121 ifeq ($(OS_ID),ubuntu)
122         @MISSING=$$(apt-get install -y -qq -s $(DEB_DEPENDS) | grep "^Inst ") ; \
123         if [ -n "$$MISSING" ] ; then \
124           echo "\nPlease install missing packages: \n$$MISSING\n" ; \
125           echo "by executing \"make install-dep\"\n" ; \
126           exit 1 ; \
127         fi ; \
128         exit 0
129 endif
130         @echo "SOURCE_PATH = $(WS_ROOT)"                   > $(BR)/build-config.mk
131         @echo "#!/bin/bash\n"                              > $(BR)/path_setup
132         @echo 'export PATH=$(BR)/tools/ccache-bin:$$PATH' >> $(BR)/path_setup
133         @echo 'export PATH=$(BR)/tools/bin:$$PATH'        >> $(BR)/path_setup
134         @echo 'export CCACHE_DIR=$(CCACHE_DIR)'           >> $(BR)/path_setup
135
136 ifeq ("$(wildcard /usr/bin/ccache )","")
137         @echo "WARNING: Please install ccache AYEC and re-run this script"
138 else
139         @rm -rf $(BR)/tools/ccache-bin
140         @mkdir -p $(BR)/tools/ccache-bin
141         @ln -s /usr/bin/ccache $(BR)/tools/ccache-bin/gcc
142         @ln -s /usr/bin/ccache $(BR)/tools/ccache-bin/g++
143 endif
144         @make -C $(BR) V=$(V) is_build_tool=yes vppapigen-install
145         @touch $@
146
147 bootstrap: $(BR)/.bootstrap.ok
148
149 install-dep:
150 ifeq ($(OS_ID),ubuntu)
151 ifeq ($(OS_VERSION_ID),14.04)
152         @sudo -E apt-get $(CONFIRM) $(FORCE) install software-properties-common
153         @sudo -E add-apt-repository ppa:openjdk-r/ppa $(CONFIRM)
154         @sudo -E apt-get update
155 endif
156         @sudo -E apt-get $(CONFIRM) $(FORCE) install $(DEB_DEPENDS)
157 else ifneq ("$(wildcard /etc/redhat-release)","")
158         @sudo yum groupinstall $(CONFIRM) $(RPM_DEPENDS_GROUPS)
159         @sudo yum install $(CONFIRM) $(RPM_DEPENDS)
160         @sudo yum install $(CONFIRM) --enablerepo=epel $(EPEL_DEPENDS)
161         @sudo 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
162 else
163         $(error "This option currently works only on Ubuntu or Centos systems")
164 endif
165
166 define make
167         @make -C $(BR) PLATFORM=$(PLATFORM) TAG=$(1) $(2)
168 endef
169
170 build: $(BR)/.bootstrap.ok
171         $(call make,$(PLATFORM)_debug,vpp-install)
172
173 wipe: $(BR)/.bootstrap.ok
174         $(call make,$(PLATFORM)_debug,vpp-wipe)
175
176 rebuild: wipe build
177
178 build-release: $(BR)/.bootstrap.ok
179         $(call make,$(PLATFORM),vpp-install)
180
181 wipe-release: $(BR)/.bootstrap.ok
182         $(call make,$(PLATFORM),vpp-wipe)
183
184 rebuild-release: wipe-release build-release
185
186 plugins: $(BR)/.bootstrap.ok
187         $(call make,$(PLATFORM)_debug,plugins-install)
188
189 plugins-release: $(BR)/.bootstrap.ok
190         $(call make,$(PLATFORM),plugins-install)
191
192 build-vpp-api: $(BR)/.bootstrap.ok
193         $(call make,$(PLATFORM)_debug,vpp-api-install)
194
195 VPP_PYTHON_PREFIX=$(BR)/python
196
197 define test
198         $(if $(filter-out $(3),retest),make -C $(BR) PLATFORM=$(1) TAG=$(2) vpp-api-install plugins-install vpp-install vpp-api-test-install,)
199         make -C test \
200           VPP_TEST_BIN=$(BR)/install-$(2)-native/vpp/bin/vpp \
201           VPP_TEST_API_TEST_BIN=$(BR)/install-$(2)-native/vpp-api-test/bin/vpp_api_test \
202           VPP_TEST_PLUGIN_PATH=$(BR)/install-$(2)-native/plugins/lib64/vpp_plugins \
203           LD_LIBRARY_PATH=$(BR)/install-$(2)-native/vpp-api/lib64/ \
204           WS_ROOT=$(WS_ROOT) V=$(V) TEST=$(TEST) VPP_PYTHON_PREFIX=$(VPP_PYTHON_PREFIX) $(3)
205 endef
206
207 test: bootstrap
208         $(call test,vpp_lite,vpp_lite,test)
209
210 test-debug: bootstrap
211         $(call test,vpp_lite,vpp_lite_debug,test)
212
213 test-help:
214         @make -C test help
215
216 test-wipe:
217         @make -C test wipe
218
219 test-doc:
220         @make -C test WS_ROOT=$(WS_ROOT) BR=$(BR) VPP_PYTHON_PREFIX=$(VPP_PYTHON_PREFIX) doc
221
222 test-wipe-doc:
223         @make -C test wipe-doc BR=$(BR)
224
225 retest:
226         $(call test,vpp_lite,vpp_lite,retest)
227
228 retest-debug:
229         $(call test,vpp_lite,vpp_lite_debug,retest)
230
231 STARTUP_DIR ?= $(PWD)
232 ifeq ("$(wildcard $(STARTUP_CONF))","")
233 define run
234         @echo "WARNING: STARTUP_CONF not defined or file doesn't exist."
235         @echo "         Running with minimal startup config: $(MINIMAL_STARTUP_CONF)\n"
236         @cd $(STARTUP_DIR) && \
237           sudo $(2) $(1)/vpp/bin/vpp $(MINIMAL_STARTUP_CONF) plugin_path $(1)/plugins/lib64/vpp_plugins
238 endef
239 else
240 define run
241         @cd $(STARTUP_DIR) && \
242           sudo $(2) $(1)/vpp/bin/vpp $(shell cat $(STARTUP_CONF) | sed -e 's/#.*//') plugin_path $(1)/plugins/lib64/vpp_plugins
243 endef
244 endif
245
246 %.files: .FORCE
247         @find . \( -name '*\.[chyS]' -o -name '*\.java' -o -name '*\.lex' \) -and \
248                 \( -not -path './build-root*' -o -path \
249                 './build-root/build-vpp_debug-native/dpdk*' \) > $@
250
251 .FORCE:
252
253 run:
254         $(call run, $(BR)/install-$(PLATFORM)_debug-native)
255
256 run-release:
257         $(call run, $(BR)/install-$(PLATFORM)-native)
258
259 debug:
260         $(call run, $(BR)/install-$(PLATFORM)_debug-native,$(GDB) $(GDB_ARGS) --args)
261
262 debug-release:
263         $(call run, $(BR)/install-$(PLATFORM)-native,$(GDB) $(GDB_ARGS) --args)
264
265 build-vat:
266         $(call make,$(PLATFORM)_debug,vpp-api-test-install)
267
268 run-vat:
269         @sudo $(BR)/install-$(PLATFORM)_debug-native/vpp-api-test/bin/vpp_api_test
270
271 pkg-deb:
272         $(call make,$(PLATFORM),install-deb)
273
274 pkg-rpm:
275         $(call make,$(PLATFORM),install-rpm)
276
277 ctags: ctags.files
278         @ctags --totals --tag-relative -L $<
279         @rm $<
280
281 gtags: ctags
282         @gtags --gtagslabel=ctags
283
284 cscope: cscope.files
285         @cscope -b -q -v
286
287 checkstyle:
288         @build-root/scripts/checkstyle.sh
289
290 fixstyle:
291         @build-root/scripts/checkstyle.sh --fix
292
293 #
294 # Build the documentation
295 #
296
297 # Doxygen configuration and our utility scripts
298 export DOXY_DIR ?= $(WS_ROOT)/doxygen
299
300 define make-doxy
301         @OS_ID="$(OS_ID)" WS_ROOT="$(WS_ROOT)" BR="$(BR)" make -C $(DOXY_DIR) $@
302 endef
303
304 .PHONY: bootstrap-doxygen doxygen wipe-doxygen
305
306 bootstrap-doxygen:
307         $(call make-doxy)
308
309 doxygen:
310         $(call make-doxy)
311
312 wipe-doxygen:
313         $(call make-doxy)
314