blob: 586d242536383ee57d9b2c57132dcb42fa90cf3a [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001# Copyright (c) 2015 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# Scripts require non-POSIX parts of bash
15SHELL := /bin/bash
16
17DPDK_BUILD_DIR ?= $(CURDIR)/_build
18DPDK_INSTALL_DIR ?= $(CURDIR)/_install
Damjan Marion19010202016-03-24 17:17:47 +010019DPDK_PKTMBUF_HEADROOM ?= 128
Ed Warnickecb9cada2015-12-08 15:45:58 -070020DPDK_DOWNLOAD_DIR ?= $(HOME)/Downloads
21DPDK_MARCH ?= native
Damjan Marion1c80e832016-05-11 23:07:18 +020022DPDK_TUNE ?= generic
Ed Warnickecb9cada2015-12-08 15:45:58 -070023DPDK_DEBUG ?= n
Damjan Marion696f1ad2016-12-23 22:42:41 +010024DPDK_CRYPTO_PMD ?= n
25DPDK_MLX5_PMD ?= n
Ed Warnickecb9cada2015-12-08 15:45:58 -070026
27B := $(DPDK_BUILD_DIR)
28I := $(DPDK_INSTALL_DIR)
Damjan Marione0a2d172016-11-08 20:39:21 +010029DPDK_VERSION ?= 16.11
Damjan Marion2ce7f982017-01-09 20:24:50 +010030PKG_SUFFIX ?= vpp1
Thomas Monjalon96e10b52016-06-02 14:52:32 +020031DPDK_BASE_URL ?= http://fast.dpdk.org/rel
32DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.xz
Damjan Mariondab123b2016-03-29 16:43:58 +020033DPDK_TAR_URL := $(DPDK_BASE_URL)/$(DPDK_TARBALL)
Sachin734d2912016-08-02 11:35:48 +053034DPDK_16.07_TARBALL_MD5_CKSUM := 690a2bb570103e58d12f9806e8bf21be
Damjan Mariond4895d52016-11-14 21:45:20 +010035DPDK_16.11_TARBALL_MD5_CKSUM := 06c1c577795360719d0b4fafaeee21e9
Ed Warnickecb9cada2015-12-08 15:45:58 -070036DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
Damjan Marione39a7b82016-04-26 14:54:57 +020037
38ifneq (,$(findstring clang,$(CC)))
39DPDK_CC=clang
40else
41DPDK_CC=gcc
42endif
43
Christophe Fontaine737547e2016-05-11 08:40:33 +000044
45ifeq (,$(DPDK_TARGET))
Damjan Marione39a7b82016-04-26 14:54:57 +020046DPDK_TARGET := x86_64-native-linuxapp-$(DPDK_CC)
Christophe Fontaine737547e2016-05-11 08:40:33 +000047endif
48
Ed Warnickecb9cada2015-12-08 15:45:58 -070049JOBS := $(shell grep processor /proc/cpuinfo | wc -l)
50
51# compiler/linker custom arguments
52DPDK_CPU_CFLAGS := -pie -fPIC
Jean-Mickael Guerin966a8b82016-03-02 19:05:05 +010053DPDK_CPU_LDFLAGS :=
Ed Warnickecb9cada2015-12-08 15:45:58 -070054DPDK_EXTRA_LDFLAGS := -g
55
56ifeq ($(DPDK_DEBUG),n)
Damjan Marion1c80e832016-05-11 23:07:18 +020057DPDK_EXTRA_CFLAGS := -g -mtune=$(DPDK_TUNE)
Ed Warnickecb9cada2015-12-08 15:45:58 -070058else
Damjan Marione39a7b82016-04-26 14:54:57 +020059DPDK_EXTRA_CFLAGS := -g -O0
Ed Warnickecb9cada2015-12-08 15:45:58 -070060endif
61
62# translate gcc march values to DPDK arch
63ifeq ($(DPDK_MARCH),native)
64DPDK_MACHINE:=native # autodetect host CPU
65else ifeq ($(DPDK_MARCH),corei7)
66DPDK_MACHINE:=nhm # Nehalem / Westmere
67else ifeq ($(DPDK_MARCH),corei7-avx)
68DPDK_MACHINE:=snb # Sandy Bridge
69else ifeq ($(DPDK_MARCH),core-avx-i)
70DPDK_MACHINE:=ivb # Ivy Bridge
71else ifeq ($(DPDK_MARCH),core-avx2)
72DPDK_MACHINE:=hsw # Haswell
Christophe Fontaine737547e2016-05-11 08:40:33 +000073else ifeq ($(DPDK_MARCH),armv7a)
74DPDK_MACHINE:=armv7a # ARMv7
75else ifeq ($(DPDK_MARCH),armv8a)
76DPDK_MACHINE:=armv8a # ARMv8
Ed Warnickecb9cada2015-12-08 15:45:58 -070077else
78$(error Unknown DPDK_MARCH)
79endif
80
81# assemble DPDK make arguments
82DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
83 T=$(DPDK_TARGET) \
84 RTE_CONFIG_TEMPLATE=../custom-config \
Ed Warnickecb9cada2015-12-08 15:45:58 -070085 EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
86 EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
87 CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
Christophe Fontaine737547e2016-05-11 08:40:33 +000088 CPU_LDFLAGS="$(DPDK_CPU_LDFLAGS)" \
Damjan Marion2ce7f982017-01-09 20:24:50 +010089 DESTDIR=$(I) \
Christophe Fontaine737547e2016-05-11 08:40:33 +000090 $(DPDK_MAKE_EXTRA_ARGS)
Ed Warnickecb9cada2015-12-08 15:45:58 -070091
92DPDK_SOURCE_FILES := $(shell [ -e $(DPDK_SOURCE) ] && find $(DPDK_SOURCE) -name "*.[chS]")
93
94define set
95@if grep -q CONFIG_$1 $@ ; \
96 then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
97 else echo CONFIG_$1=$2 >> $@ ; \
98fi
99endef
100
101all: build
102
103$(B)/custom-config: $(B)/.patch.ok Makefile
Damjan Marion106f0ed2016-04-26 10:44:28 +0200104 @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) ---
105 @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@
Ed Warnickecb9cada2015-12-08 15:45:58 -0700106 $(call set,RTE_MACHINE,$(DPDK_MACHINE))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700107 @# modify options
Damjan Marion13f07182016-02-05 06:44:54 -0800108 $(call set,RTE_MAX_LCORE,256)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700109 $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
110 $(call set,RTE_LIBEAL_USE_HPET,y)
111 $(call set,RTE_BUILD_COMBINE_LIBS,y)
112 $(call set,RTE_LIBRTE_I40E_16BYTE_RX_DESC,y)
Damjan Mariona1556802016-06-26 20:12:40 +0200113 $(call set,RTE_PCI_CONFIG,y)
114 $(call set,RTE_PCI_EXTENDED_TAG,"on")
115 $(call set,RTE_PCI_MAX_READ_REQUEST_SIZE,4096)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700116 @# enable debug init for device drivers
117 $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
118 $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
119 $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
120 $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
121 $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
John Lod9bf9ab2016-02-25 11:17:55 -0500122 $(call set,RTE_LIBRTE_PMD_BOND,y)
123 $(call set,RTE_LIBRTE_IP_FRAG,y)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000124 $(call set,RTE_LIBRTE_PMD_AESNI_MB,$(DPDK_CRYPTO_PMD))
125 $(call set,RTE_LIBRTE_PMD_AESNI_GCM,$(DPDK_CRYPTO_PMD))
126 $(call set,RTE_LIBRTE_PMD_QAT,$(DPDK_CRYPTO_PMD))
Damjan Marion696f1ad2016-12-23 22:42:41 +0100127 $(call set,RTE_LIBRTE_MLX5_PMD,$(DPDK_MLX5_PMD))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128 @# not needed
Ed Warnickecb9cada2015-12-08 15:45:58 -0700129 $(call set,RTE_LIBRTE_TIMER,n)
130 $(call set,RTE_LIBRTE_CFGFILE,n)
131 $(call set,RTE_LIBRTE_LPM,n)
132 $(call set,RTE_LIBRTE_ACL,n)
133 $(call set,RTE_LIBRTE_POWER,n)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700134 $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
135 $(call set,RTE_LIBRTE_REORDER,n)
136 $(call set,RTE_LIBRTE_PORT,n)
137 $(call set,RTE_LIBRTE_TABLE,n)
138 $(call set,RTE_LIBRTE_PIPELINE,n)
139 $(call set,RTE_KNI_KMOD,n)
Damjan Marion68fda1c2017-01-01 16:53:22 +0100140 $(call set,RTE_EAL_IGB_UIO,n)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141 @rm -f .config.ok
142
143$(CURDIR)/$(DPDK_TARBALL):
Ed Warnickecb9cada2015-12-08 15:45:58 -0700144 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
145 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
146 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
147 fi
148 @rm -f $(B)/.download.ok
149
150$(B)/.download.ok: $(CURDIR)/$(DPDK_TARBALL)
Damjan Marion2ce7f982017-01-09 20:24:50 +0100151 @mkdir -p $(B)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700152 @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
Damjan Marionbce6b6a2015-12-16 04:27:37 +0100153 @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700154 ( echo "Bad Checksum! Please remove $< and retry" && \
155 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
156 @touch $@
157
158.PHONY: download
159download: $(B)/.download.ok
160
161$(B)/.extract.ok: $(B)/.download.ok
162 @echo --- extracting $(DPDK_TARBALL) ---
Thomas Monjalon96e10b52016-06-02 14:52:32 +0200163 @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700164 @touch $@
165
166.PHONY: extract
167extract: $(B)/.extract.ok
168
169$(B)/.patch.ok: $(B)/.extract.ok
Damjan Marion0df78dd2016-03-29 22:37:02 +0200170ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700171 @echo --- patching ---
Damjan Marion2ce7f982017-01-09 20:24:50 +0100172 @for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700173 echo Applying patch: $$(basename $$f) ; \
174 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
175 done
Damjan Marion0df78dd2016-03-29 22:37:02 +0200176endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700177 @touch $@
178
179.PHONY: patch
180patch: $(B)/.patch.ok
181
182$(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
183 @make $(DPDK_MAKE_ARGS) config
184 @touch $@
185
186.PHONY: config
187config: $(B)/.config.ok
188
189$(B)/.build.ok: $(DPDK_SOURCE_FILES)
190 @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
191 @make $(DPDK_MAKE_ARGS) install
Ed Warnickecb9cada2015-12-08 15:45:58 -0700192 @touch $@
193
194.PHONY: build
195build: $(B)/.build.ok
196
Damjan Marion2ce7f982017-01-09 20:24:50 +0100197.PHONY: install
198install: $(B)/.build.ok
199
Ed Warnickecb9cada2015-12-08 15:45:58 -0700200.PHONY: clean
201clean:
202 @rm -rf $(B) $(I)
203
Damjan Marion2ce7f982017-01-09 20:24:50 +0100204##############################################################################
205# .deb packaging
206##############################################################################
207
208DEB_ARCH=$(shell dpkg --print-architecture 2> /dev/null)
209DEV_DEB=vpp-dpdk-dev_$(DPDK_VERSION)-$(PKG_SUFFIX)_$(DEB_ARCH).deb
210INSTALLED_DEB_VER=$(shell dpkg-query --showformat='$${Version}' --show vpp-dpdk-dev 2> /dev/null)
211
212.PHONY: build-deb install-deb check-deb
213
214deb/debian/changelog: Makefile
215 @echo "vpp-dpdk ($(DPDK_VERSION)-$(PKG_SUFFIX)) unstable; urgency=low" > $@
216 @echo "" >> $@
217 @echo " * DPDK Release $(DPDK_VERSION)" >> $@
218 @echo "" >> $@
219 @echo " -- VPP Dev <vpp-dev@lists.fd.io> $(shell date -R)" >> $@
220
221$(DEV_DEB): deb/debian/changelog
222 @cd deb && dpkg-buildpackage -b -uc -us
223 git clean -fdx deb
224
225build-deb: $(DEV_DEB)
226
227install-deb:
228ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
229 @make $(DEV_DEB)
230 @sudo dpkg -i $(DEV_DEB)
231else
232 @echo "=========================================================="
233 @echo " Up-to-date DPDK package already installed"
234 @echo "=========================================================="
235endif
236
237check-deb:
238ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
239 @echo "=========================================================="
240 @echo " Outdated DPDK package detected:"
241 @echo " Installed: vpp-dpdk-dev $(INSTALLED_DEB_VER)"
242 @echo " Current: vpp-dpdk-dev $(DPDK_VERSION)-$(PKG_SUFFIX)"
243 @echo ""
244 @echo " Please upgrade by invoking 'make dpdk-install-dev'"
245 @echo " from the top level directory."
246 @echo "=========================================================="
247endif
248
249##############################################################################
250# .rpm packaging
251##############################################################################
252
253RPM_ARCH=$(shell rpm --eval "%{_arch}" 2> /dev/null)
254DEV_RPM=vpp-dpdk-devel-$(DPDK_VERSION)-$(PKG_SUFFIX).$(RPM_ARCH).rpm
Damjan Marion248968b2017-01-20 23:59:28 +0100255INSTALLED_RPM_VER=$(shell rpm -q --queryformat '%{VERSION}-%{RELEASE}' vpp-dpdk-devel 2> /dev/null | grep -v "not inst")
Damjan Marion2ce7f982017-01-09 20:24:50 +0100256
257.PHONY: build-rpm install-rpm check-rpm
258
259$(DEV_RPM): Makefile rpm/vpp-dpdk.spec
260 @rpmbuild -bb \
261 --define "_topdir $(CURDIR)/rpm" \
262 --define "_version $(DPDK_VERSION)" \
263 --define "_release $(PKG_SUFFIX)" \
264 $(CURDIR)/rpm/vpp-dpdk.spec
265 mv rpm/RPMS/$(RPM_ARCH)/*.rpm .
266 git clean -fdx rpm
267
268build-rpm: $(DEV_RPM)
269
270install-rpm:
271ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
272 @make $(DEV_RPM)
273 sudo rpm -Uih $(DEV_RPM)
274else
275 @echo "=========================================================="
276 @echo " Up-to-date DPDK package already installed"
277 @echo "=========================================================="
278endif
279
280check-rpm:
281ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
282 @echo "=========================================================="
283 @echo " Outdated DPDK package detected:"
284 @echo " Installed: vpp-dpdk-devel $(INSTALLED_RPM_VER)"
285 @echo " Current: vpp-dpdk-devel $(DPDK_VERSION)-$(PKG_SUFFIX)"
286 @echo ""
287 @echo " Please upgrade by invoking 'make dpdk-install-dev'"
288 @echo " from the top level directory."
289 @echo "=========================================================="
290endif
291
292##############################################################################
293# ebuild support
294##############################################################################
295
296.PHONY: ebuild-build ebuild-install
297
298ebuild-build:
299ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
300 @echo "=========================================================="
301 @echo "Building DPDK from source. Consider installing development"
302 @echo "package by invoking 'make dpdk-install-dev' from the"
303 @echo "top level directory"
304 @echo "=========================================================="
305 make config
306else
307ifneq ($(INSTALLED_DEB_VER),)
308 make check-deb
309endif
310ifneq ($(INSTALLED_RPM_VER),)
311 make check-rpm
312endif
313endif
314
315ebuild-install:
316ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
317 make install
318endif