1 # 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:
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 # Scripts require non-POSIX parts of bash
17 DPDK_BUILD_DIR ?= $(CURDIR)/_build
18 DPDK_INSTALL_DIR ?= $(CURDIR)/_install
19 DPDK_PKTMBUF_HEADROOM ?= 128
20 DPDK_CACHE_LINE_SIZE ?= 64
21 DPDK_DOWNLOAD_DIR ?= $(HOME)/Downloads
26 DPDK_FAILSAFE_PMD ?= n
28 B := $(DPDK_BUILD_DIR)
29 I := $(DPDK_INSTALL_DIR)
31 PKG_VERSION ?= $(shell git describe --abbrev=0 | cut -d- -f1 | cut -dv -f2)
32 PKG_SUFFIX ?= $(shell git log --oneline $$(git describe --abbrev=0).. . | wc -l)
33 DPDK_BASE_URL ?= http://fast.dpdk.org/rel
34 DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.xz
35 DPDK_TAR_URL := $(DPDK_BASE_URL)/$(DPDK_TARBALL)
36 DPDK_18.05_TARBALL_MD5_CKSUM := 9fc86367cd9407ff6a8dfea56c4eddc4
37 DPDK_18.08_TARBALL_MD5_CKSUM := da5e7fb25ab063c47e53929fb8c58be5
38 MACHINE=$(shell uname -m)
40 # replace dot with space, and if 3rd word exists we deal with stable dpdk rel
41 ifeq ($(word 3,$(subst ., ,$(DPDK_VERSION))),)
42 DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
44 DPDK_SOURCE := $(B)/dpdk-stable-$(DPDK_VERSION)
47 NASM_BASE_URL := http://www.nasm.us/pub/nasm/releasebuilds
49 NASM_TARBALL := nasm-$(NASM_VER).tar.xz
50 NASM_TAR_URL := $(NASM_BASE_URL)/$(NASM_VER)/$(NASM_TARBALL)
51 NASM_SOURCE := $(B)/nasm-$(NASM_VER)
53 ifneq (,$(findstring 18.02,$(DPDK_VERSION)))
59 ifeq ($(MACHINE),$(filter $(MACHINE),x86_64))
61 $(info Building IPSec-MB $(IPSEC_MB_VER) library)
66 AESNIMB_LIB_TARBALL := v$(IPSEC_MB_VER).tar.gz
67 AESNIMB_LIB_TARBALL_URL := http://github.com/01org/intel-ipsec-mb/archive/$(AESNIMB_LIB_TARBALL)
68 AESNIMB_LIB_SOURCE := $(B)/intel-ipsec-mb-$(IPSEC_MB_VER)
70 ifneq (,$(findstring clang,$(CC)))
72 else ifneq (,$(findstring icc,$(CC)))
78 ##############################################################################
80 ##############################################################################
81 ifeq ($(MACHINE),$(filter $(MACHINE),x86_64 i686))
82 DPDK_TARGET ?= $(MACHINE)-native-linuxapp-$(DPDK_CC)
84 DPDK_TUNE ?= core-avx2
86 ##############################################################################
88 ##############################################################################
89 else ifeq ($(MACHINE),aarch64)
92 DPDK_TARGET ?= arm64-armv8a-linuxapp-$(DPDK_CC)
93 DPDK_MACHINE ?= armv8a
99 CPU_PART_ARM_CORTEX_A53 = 0xd03
100 CPU_PART_ARM_CORTEX_A57 = 0xd07
101 CPU_PART_ARM_CORTEX_A72 = 0xd08
102 CPU_PART_ARM_CORTEX_A73 = 0xd09
104 CPU_PART_CAVIUM_THUNDERX = 0x0a1
105 CPU_PART_CAVIUM_THUNDERX_81XX = 0x0a2
106 CPU_PART_CAVIUM_THUNDERX_83XX = 0x0a3
108 MIDR_IMPLEMENTER=$(shell awk '/implementer/ {print $$4;exit}' /proc/cpuinfo)
109 MIDR_PARTNUM=$(shell awk '/part/ {print $$4;exit}' /proc/cpuinfo)
111 ifeq ($(MIDR_IMPLEMENTER),$(CPU_IMP_ARM))
112 ##############################################################################
114 ##############################################################################
115 CPU_PART_ARM_TUNE := $(CPU_PART_ARM_CORTEX_A53)/cortex-a53 \
116 $(CPU_PART_ARM_CORTEX_A57)/cortex-a57 \
117 $(CPU_PART_ARM_CORTEX_A72)/cortex-a72 \
118 $(CPU_PART_ARM_CORTEX_A73)/cortex-a73
119 CPU_TUNE = $(notdir $(filter $(MIDR_PARTNUM)/%,$(CPU_PART_ARM_TUNE)))
121 DPDK_TUNE = $(CPU_TUNE)
123 $(warning Unknown Arm CPU)
126 else ifeq ($(MIDR_IMPLEMENTER),$(CPU_IMP_CAVIUM))
127 ##############################################################################
129 ##############################################################################
130 ifneq (,$(findstring $(MIDR_PARTNUM),$(CPU_PART_CAVIUM_THUNDERX) \
131 $(CPU_PART_CAVIUM_THUNDERX_81XX) $(CPU_PART_CAVIUM_THUNDERX_83XX)))
132 DPDK_TARGET = arm64-thunderx-linuxapp-$(DPDK_CC)
133 DPDK_MACHINE = thunderx
134 DPDK_CACHE_LINE_SIZE := 128
136 $(warning Unknown Cavium CPU)
140 ##############################################################################
142 ##############################################################################
144 $(error Unknown platform)
147 # /proc/cpuinfo does not exist on platforms without a /proc and on some
148 # platforms, notably inside containers, it has no content. In those cases
149 # we assume there's 1 processor; we use 2*ncpu for the -j option.
150 # NB: GNU Make 4.2 will let us use '$(file </proc/cpuinfo)' to both test
151 # for file presence and content; for now this will have to do.
152 JOBS := $(if $(shell [ -f /proc/cpuinfo ] && head /proc/cpuinfo),\
153 $(shell grep -c ^processor /proc/cpuinfo), 2)
155 # compiler/linker custom arguments
156 ifeq ($(DPDK_CC),clang)
157 DPDK_CPU_CFLAGS := -fPIE -fPIC
159 DPDK_CPU_CFLAGS := -pie -fPIC
162 ifeq ($(DPDK_DEBUG),n)
163 DPDK_EXTRA_CFLAGS := -g -mtune=$(DPDK_TUNE)
165 DPDK_EXTRA_CFLAGS := -g -O0
168 # -Wimplicit-fallthrough was introduced starting from GCC 7,
169 # and it requires newer version of ccache.
170 # Disable fallthrough warning for old ccache version.
171 ifeq ($(DPDK_CC),gcc)
173 CCACHE_VER_V = "3.4.1"
174 GCC_VER = $(shell gcc --version | grep ^gcc | sed 's/^.* //g')
175 CCACHE_VER = $(shell ccache --version | grep ^ccache | sed 's/^.* //g')
176 ifeq ($(shell expr "$(GCC_VER)" ">=" "$(GCC_VER_V)"),1)
177 ifeq ($(shell expr "$(CCACHE_VER)" "<" "$(CCACHE_VER_V)"),1)
178 DPDK_EXTRA_CFLAGS += -Wimplicit-fallthrough=0
184 IPSEC_MB_BUILD_PATH := $(B)/intel-ipsec-mb-$(IPSEC_MB_VER)
185 DPDK_EXTRA_CFLAGS += -L$(IPSEC_MB_BUILD_PATH) -I$(IPSEC_MB_BUILD_PATH)
188 DPDK_MAKE_EXTRA_ARGS += AESNI_MULTI_BUFFER_LIB_PATH=$(AESNIMB_LIB_SOURCE)
190 # assemble DPDK make arguments
191 DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
193 RTE_CONFIG_TEMPLATE=../custom-config \
194 EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
195 EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
196 CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
198 $(DPDK_MAKE_EXTRA_ARGS)
201 @if grep -q CONFIG_$1 $@ ; \
202 then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
203 else echo CONFIG_$1=$2 >> $@ ; \
209 $(B)/custom-config: $(B)/.patch.ok Makefile
210 @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) ---
211 @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@
212 $(call set,RTE_MACHINE,$(DPDK_MACHINE))
214 $(call set,RTE_MAX_LCORE,256)
215 $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
216 $(call set,RTE_CACHE_LINE_SIZE,$(DPDK_CACHE_LINE_SIZE))
217 $(call set,RTE_LIBEAL_USE_HPET,y)
218 $(call set,RTE_BUILD_COMBINE_LIBS,y)
219 $(call set,RTE_PCI_CONFIG,y)
220 $(call set,RTE_PCI_EXTENDED_TAG,"on")
221 $(call set,RTE_PCI_MAX_READ_REQUEST_SIZE,4096)
222 @# enable debug init for device drivers
223 $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
224 $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
225 $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
226 $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
227 $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
228 $(call set,RTE_LIBRTE_PMD_BOND,y)
229 $(call set,RTE_LIBRTE_IP_FRAG,y)
230 $(call set,RTE_LIBRTE_PMD_QAT,y)
231 $(call set,RTE_LIBRTE_PMD_AESNI_MB,$(AESNI))
232 $(call set,RTE_LIBRTE_PMD_AESNI_GCM,$(AESNI))
233 $(call set,RTE_LIBRTE_MLX4_PMD,$(DPDK_MLX4_PMD))
234 $(call set,RTE_LIBRTE_MLX5_PMD,$(DPDK_MLX5_PMD))
235 $(call set,RTE_LIBRTE_PMD_SOFTNIC,n)
236 $(call set,RTE_LIBRTE_MLX4_DLOPEN_DEPS,$(DPDK_MLX4_PMD))
237 $(call set,RTE_LIBRTE_MLX5_DLOPEN_DEPS,$(DPDK_MLX5_PMD))
238 $(call set,RTE_LIBRTE_PMD_TAP,$(DPDK_TAP_PMD))
239 $(call set,RTE_LIBRTE_PMD_FAILSAFE,$(DPDK_FAILSAFE_PMD))
241 $(call set,RTE_LIBRTE_CFGFILE,n)
242 $(call set,RTE_LIBRTE_LPM,n)
243 $(call set,RTE_LIBRTE_ACL,n)
244 $(call set,RTE_LIBRTE_POWER,n)
245 $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
246 $(call set,RTE_LIBRTE_PORT,n)
247 $(call set,RTE_LIBRTE_TABLE,n)
248 $(call set,RTE_LIBRTE_PIPELINE,n)
249 $(call set,RTE_LIBRTE_FLOW_CLASSIFY,n)
250 $(call set,RTE_KNI_KMOD,n)
251 $(call set,RTE_EAL_IGB_UIO,n)
252 @# currently broken in 18.02
253 $(call set,RTE_LIBRTE_DPAA_BUS,n)
254 $(call set,RTE_LIBRTE_DPAA_MEMPOOL,n)
255 $(call set,RTE_LIBRTE_DPAA_PMD,n)
256 $(call set,RTE_LIBRTE_PMD_DPAA_SEC,n)
257 $(call set,RTE_LIBRTE_PMD_DPAA_EVENTDEV,n)
260 $(CURDIR)/$(DPDK_TARBALL):
261 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
262 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
263 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
265 @rm -f $(B)/.download.ok
267 $(CURDIR)/$(NASM_TARBALL):
268 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(NASM_TARBALL) ] ; \
269 then cp $(DPDK_DOWNLOAD_DIR)/$(NASM_TARBALL) $(CURDIR) ; \
270 else curl -o $(CURDIR)/$(NASM_TARBALL) -LO $(NASM_TAR_URL) ; \
273 $(CURDIR)/$(AESNIMB_LIB_TARBALL):
274 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) ] ; \
275 then cp $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) $(CURDIR) ; \
276 else curl -o $@ -LO $(AESNIMB_LIB_TARBALL_URL) ; \
279 DPDK_DOWNLOADS = $(CURDIR)/$(DPDK_TARBALL)
281 DPDK_DOWNLOADS += $(CURDIR)/$(NASM_TARBALL)
282 DPDK_DOWNLOADS += $(CURDIR)/$(AESNIMB_LIB_TARBALL)
285 $(B)/.download.ok: $(DPDK_DOWNLOADS)
287 @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
288 @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
289 ( echo "Bad Checksum! Please remove $< and retry" && \
290 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
294 download: $(B)/.download.ok
296 $(B)/.extract.ok: $(B)/.download.ok
297 @echo --- extracting $(DPDK_TARBALL) ---
298 @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL)
300 @echo --- extracting $(NASM_TARBALL) ---
301 @tar --directory $(B) --extract --file $(CURDIR)/$(NASM_TARBALL)
302 @echo --- extracting $(AESNIMB_LIB_TARBALL) ---
303 @tar --directory $(B) --extract --file $(CURDIR)/$(AESNIMB_LIB_TARBALL)
308 extract: $(B)/.extract.ok
310 $(B)/.patch.ok: $(B)/.extract.ok
311 ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
312 @echo --- patching ---
313 @for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
314 echo Applying patch: $$(basename $$f) ; \
315 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
321 patch: $(B)/.patch.ok
323 $(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
324 @make $(DPDK_MAKE_ARGS) config
328 config: $(B)/.config.ok
332 cd $(NASM_SOURCE) && sh configure && make -j
334 .PHONY: build-ipsec-mb
337 # Do not build GCM stuff if we are building ISA_L
338 make -C $(AESNIMB_LIB_SOURCE) -j SHARED=n \
339 EXTRA_CFLAGS=-fPIC NASM=$(NASM_SOURCE)/nasm
340 cp $(AESNIMB_LIB_SOURCE)/libIPSec_MB.a $(I)/lib/
344 @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
345 @make $(DPDK_MAKE_ARGS) install
349 BUILD_TARGETS += build-nasm
350 BUILD_TARGETS += build-ipsec-mb
352 BUILD_TARGETS += build-dpdk
354 $(B)/.build.ok: $(BUILD_TARGETS)
358 build: $(B)/.build.ok
361 install: $(B)/.build.ok
367 ##############################################################################
369 ##############################################################################
371 DEB_VER := $(PKG_VERSION)
372 DEB_ARCH=$(shell dpkg --print-architecture 2> /dev/null)
373 DEV_DEB=vpp-ext-deps_$(DEB_VER)-$(PKG_SUFFIX)_$(DEB_ARCH).deb
374 INSTALLED_VER=$(shell dpkg-query --showformat='$${Version}' --show vpp-ext-deps 2> /dev/null)
376 .PHONY: build-deb install-deb check-deb
378 deb/debian/changelog: Makefile
379 @echo "vpp-ext-deps ($(DEB_VER)-$(PKG_SUFFIX)) unstable; urgency=low" > $@
381 @echo " * Version $(DEB_VER)" >> $@
383 @echo " -- VPP Dev <vpp-dev@lists.fd.io> $(shell date -R)" >> $@
385 $(DEV_DEB): deb/debian/changelog
386 @cd deb && dpkg-buildpackage -b -uc -us
389 build-deb: $(DEV_DEB)
392 ifneq ($(INSTALLED_VER),$(DEB_VER)-$(PKG_SUFFIX))
393 @echo "=========================================================="
394 @echo " Out of date vpp-ext-deps package installed."
395 @echo " Installed: $(INSTALLED_VER)"
396 @echo " Needed: $(DEB_VER)-$(PKG_SUFFIX)"
397 @echo "=========================================================="
399 @sudo dpkg -i $(DEV_DEB)
401 @echo "=========================================================="
402 @echo " Up-to-date vpp-ext-deps package already installed"
403 @echo "=========================================================="
407 ifneq ($(INSTALLED_VER),$(DEB_VER)-$(PKG_SUFFIX))
408 @echo "=========================================================="
409 @echo " Outdated DPDK package detected:"
410 @echo " Installed: vpp-ext-deps $(INSTALLED_VER)"
411 @echo " Current: vpp-ext-deps $(DEB_VER)-$(PKG_SUFFIX)"
413 @echo " Please upgrade by invoking 'make install-ext-deps'"
414 @echo " from the top level directory."
415 @echo "=========================================================="
418 ##############################################################################
420 ##############################################################################
422 RPM_VER := $(PKG_VERSION)
423 RPM_ARCH=$(shell rpm --eval "%{_arch}" 2> /dev/null)
424 DEV_RPM=vpp-ext-deps-$(RPM_VER)-$(PKG_SUFFIX).$(RPM_ARCH).rpm
425 INSTALLED_RPM_VER=$(shell rpm -q --queryformat '%{VERSION}-%{RELEASE}' vpp-ext-deps 2> /dev/null | grep -v "not inst")
427 .PHONY: build-rpm install-rpm check-rpm
429 $(DEV_RPM): Makefile rpm/vpp-ext-deps.spec
431 --define "_topdir $(CURDIR)/rpm" \
432 --define "_version $(RPM_VER)" \
433 --define "_release $(PKG_SUFFIX)" \
434 $(CURDIR)/rpm/vpp-ext-deps.spec
435 mv rpm/RPMS/$(RPM_ARCH)/*.rpm .
438 build-rpm: $(DEV_RPM)
441 ifneq ($(INSTALLED_RPM_VER),$(PRM_VER)-$(PKG_SUFFIX))
443 sudo rpm -Uih $(DEV_RPM)
445 @echo "=========================================================="
446 @echo " Up-to-date DPDK package already installed"
447 @echo "=========================================================="
451 ifneq ($(INSTALLED_RPM_VER),$(RPM_VER)-$(PKG_SUFFIX))
452 @echo "=========================================================="
453 @echo " Outdated DPDK package detected:"
454 @echo " Installed: vpp-ext-deps $(INSTALLED_RPM_VER)"
455 @echo " Current: vpp-ext-deps $(RPM_VER)-$(PKG_SUFFIX)"
457 @echo " Please upgrade by invoking 'make install-ext-deps'"
458 @echo " from the top level directory."
459 @echo "=========================================================="
462 ##############################################################################
464 ##############################################################################
466 .PHONY: ebuild-build ebuild-install
469 ifeq ($(INSTALLED_VER)$(INSTALLED_RPM_VER),)
470 @echo "=========================================================="
471 @echo "Building DPDK from source. Consider installing development"
472 @echo "package by invoking 'make install-ext-deps' from the"
473 @echo "top level directory"
474 @echo "=========================================================="
477 ifneq ($(INSTALLED_VER),)
480 ifneq ($(INSTALLED_RPM_VER),)
486 ifeq ($(INSTALLED_VER)$(INSTALLED_RPM_VER),)