make: Fix parallel building with some container platforms (VPP-880)
[vpp.git] / dpdk / Makefile
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:
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
15 SHELL := /bin/bash
16
17 DPDK_BUILD_DIR        ?= $(CURDIR)/_build
18 DPDK_INSTALL_DIR      ?= $(CURDIR)/_install
19 DPDK_PKTMBUF_HEADROOM ?= 128
20 DPDK_DOWNLOAD_DIR     ?= $(HOME)/Downloads
21 DPDK_DEBUG            ?= n
22 DPDK_CRYPTO_SW_PMD    ?= n
23 DPDK_MLX4_PMD         ?= n
24 DPDK_MLX5_PMD         ?= n
25
26 B := $(DPDK_BUILD_DIR)
27 I := $(DPDK_INSTALL_DIR)
28 DPDK_VERSION ?= 17.05
29 PKG_SUFFIX ?= vpp5
30 DPDK_BASE_URL ?= http://fast.dpdk.org/rel
31 DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.xz
32 DPDK_TAR_URL := $(DPDK_BASE_URL)/$(DPDK_TARBALL)
33 DPDK_17.02_TARBALL_MD5_CKSUM := 6b9f7387c35641f4e8dbba3e528f2376
34 DPDK_17.05_TARBALL_MD5_CKSUM := 0a68c31cd6a6cabeed0a4331073e4c05
35 DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
36
37 ifeq ($(DPDK_CRYPTO_SW_PMD),y)
38 AESNIMB_LIB_TARBALL := v0.44-gcm.2.tar.gz
39 AESNIMB_LIB_TARBALL_URL := http://github.com/01org/intel-ipsec-mb/archive/$(AESNIMB_LIB_TARBALL)
40 AESNIMB_LIB_SOURCE := $(B)/intel-ipsec-mb-0.44-gcm.2
41 ISA_L_CRYPTO_LIB_TARBALL := isa_l_crypto.tar.gz
42 ISA_L_CRYPTO_LIB_TARBALL_URL := http://github.com/01org/isa-l_crypto/archive/master.tar.gz
43 ISA_L_CRYPTO_LIB_SOURCE := $(B)/isa-l_crypto-master
44 endif
45
46 ifneq (,$(findstring clang,$(CC)))
47 DPDK_CC=clang
48 else ifneq (,$(findstring icc,$(CC)))
49 DPDK_CC=icc
50 else
51 DPDK_CC=gcc
52 endif
53
54 MACHINE=$(shell uname -m)
55
56 ##############################################################################
57 # Intel x86
58 ##############################################################################
59 ifeq ($(MACHINE),$(filter $(MACHINE),x86_64 i686))
60 DPDK_TARGET           ?= $(MACHINE)-native-linuxapp-$(DPDK_CC)
61 DPDK_MACHINE          ?= nhm
62 DPDK_TUNE             ?= core-avx2
63
64 ##############################################################################
65 # Cavium ThunderX
66 ##############################################################################
67 else ifneq (,$(findstring thunder,$(shell cat /sys/bus/pci/devices/0000:00:01.0/uevent | grep cavium)))
68 export CROSS=""
69 DPDK_TARGET           ?= arm64-thunderx-linuxapp-$(DPDK_CC)
70 DPDK_MACHINE          ?= thunderx
71 DPDK_TUNE             ?= generic
72
73 ##############################################################################
74 # Unknown platofrm
75 ##############################################################################
76 else
77 $(error unknown platform)
78 endif
79
80 # /proc/cpuinfo does not exist on platforms without a /proc and on some
81 # platforms, notably inside containers, it has no content. In those cases
82 # we assume there's 1 processor; we use 2*ncpu for the -j option.
83 # NB: GNU Make 4.2 will let us use '$(file </proc/cpuinfo)' to both test
84 # for file presence and content; for now this will have to do.
85 JOBS := $(if $(shell [ -f /proc/cpuinfo ] && head /proc/cpuinfo),\
86         $(shell expr 2 '*' $$(grep -c ^processor /proc/cpuinfo)), 2)
87
88 # compiler/linker custom arguments
89 DPDK_CPU_CFLAGS := -pie -fPIC
90 DPDK_EXTRA_LDFLAGS := -g
91
92 ifeq ($(DPDK_DEBUG),n)
93 DPDK_EXTRA_CFLAGS := -g -mtune=$(DPDK_TUNE)
94 else
95 DPDK_EXTRA_CFLAGS := -g -O0
96 endif
97
98 ifeq ($(DPDK_CRYPTO_SW_PMD),y)
99 DPDK_EXTRA_CFLAGS += -I$(I)/include
100 DPDK_EXTRA_LDFLAGS += -L$(I)/lib
101 DPDK_MAKE_EXTRA_ARGS += AESNI_MULTI_BUFFER_LIB_PATH=$(AESNIMB_LIB_SOURCE)
102 endif
103
104 # assemble DPDK make arguments
105 DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
106         T=$(DPDK_TARGET) \
107         RTE_CONFIG_TEMPLATE=../custom-config \
108         EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
109         EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
110         CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
111         DESTDIR=$(I) \
112         $(DPDK_MAKE_EXTRA_ARGS)
113
114 DPDK_SOURCE_FILES := $(shell  [ -e $(DPDK_SOURCE) ] && find $(DPDK_SOURCE) -name "*.[chS]")
115
116 define set
117 @if grep -q CONFIG_$1 $@ ; \
118         then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
119         else echo CONFIG_$1=$2 >> $@ ; \
120 fi
121 endef
122
123 all: build
124
125 $(B)/custom-config: $(B)/.patch.ok Makefile
126         @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) ---
127         @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@
128         $(call set,RTE_MACHINE,$(DPDK_MACHINE))
129         @# modify options
130         $(call set,RTE_MAX_LCORE,256)
131         $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
132         $(call set,RTE_LIBEAL_USE_HPET,y)
133         $(call set,RTE_BUILD_COMBINE_LIBS,y)
134         $(call set,RTE_PCI_CONFIG,y)
135         $(call set,RTE_PCI_EXTENDED_TAG,"on")
136         $(call set,RTE_PCI_MAX_READ_REQUEST_SIZE,4096)
137         @# enable debug init for device drivers
138         $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
139         $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
140         $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
141         $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
142         $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
143         $(call set,RTE_LIBRTE_PMD_BOND,y)
144         $(call set,RTE_LIBRTE_IP_FRAG,y)
145         $(call set,RTE_LIBRTE_PMD_QAT,y)
146         $(call set,RTE_LIBRTE_PMD_AESNI_MB,$(DPDK_CRYPTO_SW_PMD))
147         $(call set,RTE_LIBRTE_PMD_AESNI_GCM,$(DPDK_CRYPTO_SW_PMD))
148         $(call set,RTE_LIBRTE_MLX4_PMD,$(DPDK_MLX4_PMD))
149         $(call set,RTE_LIBRTE_MLX5_PMD,$(DPDK_MLX5_PMD))
150         @# not needed
151         $(call set,RTE_LIBRTE_TIMER,n)
152         $(call set,RTE_LIBRTE_CFGFILE,n)
153         $(call set,RTE_LIBRTE_LPM,n)
154         $(call set,RTE_LIBRTE_ACL,n)
155         $(call set,RTE_LIBRTE_POWER,n)
156         $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
157         $(call set,RTE_LIBRTE_PORT,n)
158         $(call set,RTE_LIBRTE_TABLE,n)
159         $(call set,RTE_LIBRTE_PIPELINE,n)
160         $(call set,RTE_KNI_KMOD,n)
161         $(call set,RTE_EAL_IGB_UIO,n)
162         @rm -f .config.ok
163
164 $(CURDIR)/$(DPDK_TARBALL):
165         @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
166                 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
167                 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
168         fi
169         @rm -f $(B)/.download.ok
170
171 $(CURDIR)/$(AESNIMB_LIB_TARBALL):
172         @if [ -e $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) ] ; \
173                 then cp $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) $(CURDIR) ; \
174                 else curl -o $@ -LO $(AESNIMB_LIB_TARBALL_URL) ; \
175         fi
176
177 $(CURDIR)/$(ISA_L_CRYPTO_LIB_TARBALL):
178         @if [ -e $(DPDK_DOWNLOAD_DIR)/$(ISA_L_CRYPTO_LIB_TARBALL) ] ; \
179                 then cp $(DPDK_DOWNLOAD_DIR)/$(ISA_L_CRYPTO_LIB_TARBALL) $(CURDIR) ; \
180                 else curl -o $@ -LO $(ISA_L_CRYPTO_LIB_TARBALL_URL) ; \
181         fi
182
183 DPDK_DOWNLOADS = $(CURDIR)/$(DPDK_TARBALL)
184 ifeq ($(DPDK_CRYPTO_SW_PMD),y)
185 DPDK_DOWNLOADS += $(CURDIR)/$(AESNIMB_LIB_TARBALL)
186 DPDK_DOWNLOADS += $(CURDIR)/$(ISA_L_CRYPTO_LIB_TARBALL)
187 endif
188
189 $(B)/.download.ok: $(DPDK_DOWNLOADS)
190         @mkdir -p $(B)
191         @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
192         @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
193         ( echo "Bad Checksum! Please remove $< and retry" && \
194                 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
195         @touch $@
196
197 .PHONY: download
198 download: $(B)/.download.ok
199
200 $(B)/.extract.ok: $(B)/.download.ok
201         @echo --- extracting $(DPDK_TARBALL) ---
202         @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL)
203 ifeq ($(DPDK_CRYPTO_SW_PMD),y)
204         @echo --- extracting $(AESNIMB_LIB_TARBALL) ---
205         @tar --directory $(B) --extract --file $(CURDIR)/$(AESNIMB_LIB_TARBALL)
206         @echo --- extracting $(ISA_L_CRYPTO_LIB_TARBALL) ---
207         @tar --directory $(B) --extract --file $(CURDIR)/$(ISA_L_CRYPTO_LIB_TARBALL)
208 endif
209         @touch $@
210
211 .PHONY: extract
212 extract: $(B)/.extract.ok
213
214 $(B)/.patch.ok: $(B)/.extract.ok
215 ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
216         @echo --- patching ---
217         @for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
218                 echo Applying patch: $$(basename $$f) ; \
219                 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
220         done
221 endif
222         @touch $@
223
224 .PHONY: patch
225 patch: $(B)/.patch.ok
226
227 $(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
228         @make $(DPDK_MAKE_ARGS) config
229         @touch $@
230
231 .PHONY: config
232 config: $(B)/.config.ok
233
234 $(B)/.build.ok: $(DPDK_SOURCE_FILES)
235         @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
236 ifeq ($(DPDK_CRYPTO_SW_PMD),y)
237         # Build IPsec_MB library
238         mkdir -p $(I)/lib/
239         make -C $(AESNIMB_LIB_SOURCE) -j NO_GCM=y
240         cp $(AESNIMB_LIB_SOURCE)/libIPSec_MB.a $(I)/lib/
241         # Build ISA-L Crypto library
242         cd $(ISA_L_CRYPTO_LIB_SOURCE) && ./autogen.sh && ./configure --prefix=$(I)
243         make -C $(ISA_L_CRYPTO_LIB_SOURCE) -j install
244 endif
245         @make $(DPDK_MAKE_ARGS) install
246         @touch $@
247
248 .PHONY: build
249 build: $(B)/.build.ok
250
251 .PHONY: install
252 install: $(B)/.build.ok
253
254 .PHONY: clean
255 clean:
256         @rm -rf $(B) $(I)
257
258 ##############################################################################
259 # .deb packaging
260 ##############################################################################
261
262 DEB_ARCH=$(shell dpkg --print-architecture 2> /dev/null)
263 DEV_DEB=vpp-dpdk-dev_$(DPDK_VERSION)-$(PKG_SUFFIX)_$(DEB_ARCH).deb
264 INSTALLED_DEB_VER=$(shell dpkg-query --showformat='$${Version}' --show vpp-dpdk-dev 2> /dev/null)
265
266 .PHONY: build-deb install-deb check-deb
267
268 deb/debian/changelog: Makefile
269         @echo "vpp-dpdk ($(DPDK_VERSION)-$(PKG_SUFFIX)) unstable; urgency=low" > $@
270         @echo "" >> $@
271         @echo "  * DPDK Release $(DPDK_VERSION)" >> $@
272         @echo "" >> $@
273         @echo " -- VPP Dev <vpp-dev@lists.fd.io>  $(shell date -R)" >> $@
274
275 $(DEV_DEB): deb/debian/changelog
276         @cd deb && dpkg-buildpackage -b -uc -us
277         git clean -fdx deb
278
279 build-deb: $(DEV_DEB)
280
281 install-deb:
282 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
283         @make $(DEV_DEB)
284         @sudo dpkg -i $(DEV_DEB)
285 else
286         @echo "=========================================================="
287         @echo " Up-to-date DPDK package already installed"
288         @echo "=========================================================="
289 endif
290
291 check-deb:
292 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
293         @echo "=========================================================="
294         @echo " Outdated DPDK package detected:"
295         @echo "  Installed: vpp-dpdk-dev $(INSTALLED_DEB_VER)"
296         @echo "  Current:   vpp-dpdk-dev $(DPDK_VERSION)-$(PKG_SUFFIX)"
297         @echo ""
298         @echo " Please upgrade by invoking 'make dpdk-install-dev'"
299         @echo " from the top level directory."
300         @echo "=========================================================="
301 endif
302
303 ##############################################################################
304 # .rpm packaging
305 ##############################################################################
306
307 RPM_ARCH=$(shell rpm --eval "%{_arch}" 2> /dev/null)
308 DEV_RPM=vpp-dpdk-devel-$(DPDK_VERSION)-$(PKG_SUFFIX).$(RPM_ARCH).rpm
309 INSTALLED_RPM_VER=$(shell rpm -q --queryformat '%{VERSION}-%{RELEASE}' vpp-dpdk-devel 2> /dev/null | grep -v "not inst")
310
311 .PHONY: build-rpm install-rpm check-rpm
312
313 $(DEV_RPM): Makefile rpm/vpp-dpdk.spec
314         @rpmbuild -bb \
315           --define "_topdir $(CURDIR)/rpm" \
316           --define "_version $(DPDK_VERSION)" \
317           --define "_release $(PKG_SUFFIX)" \
318           $(CURDIR)/rpm/vpp-dpdk.spec
319         mv rpm/RPMS/$(RPM_ARCH)/*.rpm .
320         git clean -fdx rpm
321
322 build-rpm: $(DEV_RPM)
323
324 install-rpm:
325 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
326         @make $(DEV_RPM)
327         sudo rpm -Uih $(DEV_RPM)
328 else
329         @echo "=========================================================="
330         @echo " Up-to-date DPDK package already installed"
331         @echo "=========================================================="
332 endif
333
334 check-rpm:
335 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
336         @echo "=========================================================="
337         @echo " Outdated DPDK package detected:"
338         @echo "  Installed: vpp-dpdk-devel $(INSTALLED_RPM_VER)"
339         @echo "  Current:   vpp-dpdk-devel $(DPDK_VERSION)-$(PKG_SUFFIX)"
340         @echo ""
341         @echo " Please upgrade by invoking 'make dpdk-install-dev'"
342         @echo " from the top level directory."
343         @echo "=========================================================="
344 endif
345
346 ##############################################################################
347 # ebuild support
348 ##############################################################################
349
350 .PHONY: ebuild-build ebuild-install
351
352 ebuild-build:
353 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
354         @echo "=========================================================="
355         @echo "Building DPDK from source. Consider installing development"
356         @echo "package by invoking 'make dpdk-install-dev' from the"
357         @echo "top level directory"
358         @echo "=========================================================="
359         make config
360 else
361 ifneq ($(INSTALLED_DEB_VER),)
362         make check-deb
363 endif
364 ifneq ($(INSTALLED_RPM_VER),)
365         make check-rpm
366 endif
367 endif
368
369 ebuild-install:
370 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
371         make install
372 endif