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_DOWNLOAD_DIR ?= $(HOME)/Downloads
25 B := $(DPDK_BUILD_DIR)
26 I := $(DPDK_INSTALL_DIR)
28 DPDK_BASE_URL ?= http://fast.dpdk.org/rel
29 DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.xz
30 DPDK_TAR_URL := $(DPDK_BASE_URL)/$(DPDK_TARBALL)
31 DPDK_16.07_TARBALL_MD5_CKSUM := 690a2bb570103e58d12f9806e8bf21be
32 DPDK_16.11_TARBALL_MD5_CKSUM := 06c1c577795360719d0b4fafaeee21e9
33 DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
35 ifneq (,$(findstring clang,$(CC)))
42 ifeq (,$(DPDK_TARGET))
43 DPDK_TARGET := x86_64-native-linuxapp-$(DPDK_CC)
46 JOBS := $(shell grep processor /proc/cpuinfo | wc -l)
48 # compiler/linker custom arguments
49 DPDK_CPU_CFLAGS := -pie -fPIC
51 DPDK_EXTRA_LDFLAGS := -g
53 ifeq ($(DPDK_DEBUG),n)
54 DPDK_EXTRA_CFLAGS := -g -mtune=$(DPDK_TUNE)
56 DPDK_EXTRA_CFLAGS := -g -O0
59 # translate gcc march values to DPDK arch
60 ifeq ($(DPDK_MARCH),native)
61 DPDK_MACHINE:=native # autodetect host CPU
62 else ifeq ($(DPDK_MARCH),corei7)
63 DPDK_MACHINE:=nhm # Nehalem / Westmere
64 else ifeq ($(DPDK_MARCH),corei7-avx)
65 DPDK_MACHINE:=snb # Sandy Bridge
66 else ifeq ($(DPDK_MARCH),core-avx-i)
67 DPDK_MACHINE:=ivb # Ivy Bridge
68 else ifeq ($(DPDK_MARCH),core-avx2)
69 DPDK_MACHINE:=hsw # Haswell
70 else ifeq ($(DPDK_MARCH),armv7a)
71 DPDK_MACHINE:=armv7a # ARMv7
72 else ifeq ($(DPDK_MARCH),armv8a)
73 DPDK_MACHINE:=armv8a # ARMv8
75 $(error Unknown DPDK_MARCH)
78 # assemble DPDK make arguments
79 DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
81 RTE_CONFIG_TEMPLATE=../custom-config \
83 EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
84 EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
85 CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
86 CPU_LDFLAGS="$(DPDK_CPU_LDFLAGS)" \
87 $(DPDK_MAKE_EXTRA_ARGS)
89 DPDK_SOURCE_FILES := $(shell [ -e $(DPDK_SOURCE) ] && find $(DPDK_SOURCE) -name "*.[chS]")
92 @if grep -q CONFIG_$1 $@ ; \
93 then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
94 else echo CONFIG_$1=$2 >> $@ ; \
100 $(B)/custom-config: $(B)/.patch.ok Makefile
101 @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) ---
102 @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@
103 $(call set,RTE_MACHINE,$(DPDK_MACHINE))
105 $(call set,RTE_MAX_LCORE,256)
106 $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
107 $(call set,RTE_LIBEAL_USE_HPET,y)
108 $(call set,RTE_BUILD_COMBINE_LIBS,y)
109 $(call set,RTE_LIBRTE_I40E_16BYTE_RX_DESC,y)
110 $(call set,RTE_PCI_CONFIG,y)
111 $(call set,RTE_PCI_EXTENDED_TAG,"on")
112 $(call set,RTE_PCI_MAX_READ_REQUEST_SIZE,4096)
113 @# enable debug init for device drivers
114 $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
115 $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
116 $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
117 $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
118 $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
119 $(call set,RTE_LIBRTE_PMD_BOND,y)
120 $(call set,RTE_LIBRTE_IP_FRAG,y)
122 $(call set,RTE_LIBRTE_TIMER,n)
123 $(call set,RTE_LIBRTE_CFGFILE,n)
124 $(call set,RTE_LIBRTE_LPM,n)
125 $(call set,RTE_LIBRTE_ACL,n)
126 $(call set,RTE_LIBRTE_POWER,n)
127 $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
128 $(call set,RTE_LIBRTE_REORDER,n)
129 $(call set,RTE_LIBRTE_PORT,n)
130 $(call set,RTE_LIBRTE_TABLE,n)
131 $(call set,RTE_LIBRTE_PIPELINE,n)
132 $(call set,RTE_KNI_KMOD,n)
135 $(CURDIR)/$(DPDK_TARBALL):
137 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
138 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
139 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
141 @rm -f $(B)/.download.ok
143 $(B)/.download.ok: $(CURDIR)/$(DPDK_TARBALL)
144 @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
145 @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
146 ( echo "Bad Checksum! Please remove $< and retry" && \
147 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
151 download: $(B)/.download.ok
153 $(B)/.extract.ok: $(B)/.download.ok
154 @echo --- extracting $(DPDK_TARBALL) ---
155 @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL)
159 extract: $(B)/.extract.ok
161 $(B)/.patch.ok: $(B)/.extract.ok
162 ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
163 @echo --- patching ---
164 for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
165 echo Applying patch: $$(basename $$f) ; \
166 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
172 patch: $(B)/.patch.ok
174 $(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
175 @make $(DPDK_MAKE_ARGS) config
179 config: $(B)/.config.ok
181 $(B)/.build.ok: $(DPDK_SOURCE_FILES)
182 @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
183 @make $(DPDK_MAKE_ARGS) install
184 @dkms/create_deb_manifest.sh $(DPDK_VERSION) $(subst $(realpath ..)/,,$(B))
188 build: $(B)/.build.ok