blob: 6296c965432b6feec9ab9eb33553d5ed900cbe39 [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
24
25B := $(DPDK_BUILD_DIR)
26I := $(DPDK_INSTALL_DIR)
Dave Barachfed985c2016-04-25 08:51:21 -040027DPDK_VERSION ?= 16.04
Thomas Monjalon96e10b52016-06-02 14:52:32 +020028DPDK_BASE_URL ?= http://fast.dpdk.org/rel
29DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.xz
Damjan Mariondab123b2016-03-29 16:43:58 +020030DPDK_TAR_URL := $(DPDK_BASE_URL)/$(DPDK_TARBALL)
Thomas Monjalon96e10b52016-06-02 14:52:32 +020031DPDK_2.1.0_TARBALL_MD5_CKSUM := a0d69f78f360e03dbdf38ae93fad32d4
32DPDK_2.2.0_TARBALL_MD5_CKSUM := bfa10283b49d56264c82519d130458cc
33DPDK_16.04_TARBALL_MD5_CKSUM := d1f82e7d7589b3b2f623c155442b8306
Ed Warnickecb9cada2015-12-08 15:45:58 -070034DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
Damjan Marione39a7b82016-04-26 14:54:57 +020035
36ifneq (,$(findstring clang,$(CC)))
37DPDK_CC=clang
38else
39DPDK_CC=gcc
40endif
41
Christophe Fontaine737547e2016-05-11 08:40:33 +000042
43ifeq (,$(DPDK_TARGET))
Damjan Marione39a7b82016-04-26 14:54:57 +020044DPDK_TARGET := x86_64-native-linuxapp-$(DPDK_CC)
Christophe Fontaine737547e2016-05-11 08:40:33 +000045endif
46
Ed Warnickecb9cada2015-12-08 15:45:58 -070047JOBS := $(shell grep processor /proc/cpuinfo | wc -l)
48
49# compiler/linker custom arguments
50DPDK_CPU_CFLAGS := -pie -fPIC
Jean-Mickael Guerin966a8b82016-03-02 19:05:05 +010051DPDK_CPU_LDFLAGS :=
Ed Warnickecb9cada2015-12-08 15:45:58 -070052DPDK_EXTRA_LDFLAGS := -g
53
54ifeq ($(DPDK_DEBUG),n)
Damjan Marion1c80e832016-05-11 23:07:18 +020055DPDK_EXTRA_CFLAGS := -g -mtune=$(DPDK_TUNE)
Ed Warnickecb9cada2015-12-08 15:45:58 -070056else
Damjan Marione39a7b82016-04-26 14:54:57 +020057DPDK_EXTRA_CFLAGS := -g -O0
Ed Warnickecb9cada2015-12-08 15:45:58 -070058endif
59
60# translate gcc march values to DPDK arch
61ifeq ($(DPDK_MARCH),native)
62DPDK_MACHINE:=native # autodetect host CPU
63else ifeq ($(DPDK_MARCH),corei7)
64DPDK_MACHINE:=nhm # Nehalem / Westmere
65else ifeq ($(DPDK_MARCH),corei7-avx)
66DPDK_MACHINE:=snb # Sandy Bridge
67else ifeq ($(DPDK_MARCH),core-avx-i)
68DPDK_MACHINE:=ivb # Ivy Bridge
69else ifeq ($(DPDK_MARCH),core-avx2)
70DPDK_MACHINE:=hsw # Haswell
Christophe Fontaine737547e2016-05-11 08:40:33 +000071else ifeq ($(DPDK_MARCH),armv7a)
72DPDK_MACHINE:=armv7a # ARMv7
73else ifeq ($(DPDK_MARCH),armv8a)
74DPDK_MACHINE:=armv8a # ARMv8
Ed Warnickecb9cada2015-12-08 15:45:58 -070075else
76$(error Unknown DPDK_MARCH)
77endif
78
79# assemble DPDK make arguments
80DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
81 T=$(DPDK_TARGET) \
82 RTE_CONFIG_TEMPLATE=../custom-config \
83 RTE_OUTPUT=$(I) \
84 EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
85 EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
86 CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
Christophe Fontaine737547e2016-05-11 08:40:33 +000087 CPU_LDFLAGS="$(DPDK_CPU_LDFLAGS)" \
88 $(DPDK_MAKE_EXTRA_ARGS)
Ed Warnickecb9cada2015-12-08 15:45:58 -070089
90DPDK_SOURCE_FILES := $(shell [ -e $(DPDK_SOURCE) ] && find $(DPDK_SOURCE) -name "*.[chS]")
91
92define set
93@if grep -q CONFIG_$1 $@ ; \
94 then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
95 else echo CONFIG_$1=$2 >> $@ ; \
96fi
97endef
98
99all: build
100
101$(B)/custom-config: $(B)/.patch.ok Makefile
Damjan Marion106f0ed2016-04-26 10:44:28 +0200102 @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) ---
103 @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@
Ed Warnickecb9cada2015-12-08 15:45:58 -0700104 $(call set,RTE_MACHINE,$(DPDK_MACHINE))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700105 @# modify options
Damjan Marion13f07182016-02-05 06:44:54 -0800106 $(call set,RTE_MAX_LCORE,256)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700107 $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
108 $(call set,RTE_LIBEAL_USE_HPET,y)
109 $(call set,RTE_BUILD_COMBINE_LIBS,y)
110 $(call set,RTE_LIBRTE_I40E_16BYTE_RX_DESC,y)
Damjan Mariona1556802016-06-26 20:12:40 +0200111 $(call set,RTE_PCI_CONFIG,y)
112 $(call set,RTE_PCI_EXTENDED_TAG,"on")
113 $(call set,RTE_PCI_MAX_READ_REQUEST_SIZE,4096)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700114 @# enable debug init for device drivers
115 $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
116 $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
117 $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
118 $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
119 $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
John Lod9bf9ab2016-02-25 11:17:55 -0500120 $(call set,RTE_LIBRTE_PMD_BOND,y)
121 $(call set,RTE_LIBRTE_IP_FRAG,y)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700122 @# not needed
Ed Warnickecb9cada2015-12-08 15:45:58 -0700123 $(call set,RTE_LIBRTE_TIMER,n)
124 $(call set,RTE_LIBRTE_CFGFILE,n)
125 $(call set,RTE_LIBRTE_LPM,n)
126 $(call set,RTE_LIBRTE_ACL,n)
127 $(call set,RTE_LIBRTE_POWER,n)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128 $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
129 $(call set,RTE_LIBRTE_REORDER,n)
130 $(call set,RTE_LIBRTE_PORT,n)
131 $(call set,RTE_LIBRTE_TABLE,n)
132 $(call set,RTE_LIBRTE_PIPELINE,n)
133 $(call set,RTE_KNI_KMOD,n)
134 @rm -f .config.ok
135
136$(CURDIR)/$(DPDK_TARBALL):
137 @mkdir -p $(B)
138 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
139 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
140 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
141 fi
142 @rm -f $(B)/.download.ok
143
144$(B)/.download.ok: $(CURDIR)/$(DPDK_TARBALL)
145 @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
Damjan Marionbce6b6a2015-12-16 04:27:37 +0100146 @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700147 ( echo "Bad Checksum! Please remove $< and retry" && \
148 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
149 @touch $@
150
151.PHONY: download
152download: $(B)/.download.ok
153
154$(B)/.extract.ok: $(B)/.download.ok
155 @echo --- extracting $(DPDK_TARBALL) ---
Thomas Monjalon96e10b52016-06-02 14:52:32 +0200156 @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700157 @touch $@
158
159.PHONY: extract
160extract: $(B)/.extract.ok
161
162$(B)/.patch.ok: $(B)/.extract.ok
Damjan Marion0df78dd2016-03-29 22:37:02 +0200163ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700164 @echo --- patching ---
165 for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
166 echo Applying patch: $$(basename $$f) ; \
167 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
168 done
Damjan Marion0df78dd2016-03-29 22:37:02 +0200169endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170 @touch $@
171
172.PHONY: patch
173patch: $(B)/.patch.ok
174
175$(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
176 @make $(DPDK_MAKE_ARGS) config
177 @touch $@
178
179.PHONY: config
180config: $(B)/.config.ok
181
182$(B)/.build.ok: $(DPDK_SOURCE_FILES)
183 @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
184 @make $(DPDK_MAKE_ARGS) install
185 @dkms/create_deb_manifest.sh $(DPDK_VERSION) $(subst $(realpath ..)/,,$(B))
186 @touch $@
187
188.PHONY: build
189build: $(B)/.build.ok
190
191.PHONY: clean
192clean:
193 @rm -rf $(B) $(I)
194