blob: fadbb26831efe0aa42acd463559597ef6ae74260 [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
22DPDK_DEBUG ?= n
23
24B := $(DPDK_BUILD_DIR)
25I := $(DPDK_INSTALL_DIR)
Dave Barachfed985c2016-04-25 08:51:21 -040026DPDK_VERSION ?= 16.04
Damjan Mariondab123b2016-03-29 16:43:58 +020027DPDK_BASE_URL ?= http://dpdk.org/browse/dpdk/snapshot
Ed Warnickecb9cada2015-12-08 15:45:58 -070028DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.gz
Damjan Mariondab123b2016-03-29 16:43:58 +020029DPDK_TAR_URL := $(DPDK_BASE_URL)/$(DPDK_TARBALL)
Damjan Marionbce6b6a2015-12-16 04:27:37 +010030DPDK_2.1.0_TARBALL_MD5_CKSUM := 205a0d12bfd6eb717d57506272f43519
31DPDK_2.2.0_TARBALL_MD5_CKSUM := 22e2fd68cd5504f43fe9a5a6fd6dd938
Damjan Marionc42552d2016-04-12 05:10:25 +020032DPDK_16.04_TARBALL_MD5_CKSUM := 0728d506d7f56eb64233e824fa3c098a
Ed Warnickecb9cada2015-12-08 15:45:58 -070033DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
Damjan Marione39a7b82016-04-26 14:54:57 +020034
35ifneq (,$(findstring clang,$(CC)))
36DPDK_CC=clang
37else
38DPDK_CC=gcc
39endif
40
41DPDK_TARGET := x86_64-native-linuxapp-$(DPDK_CC)
Ed Warnickecb9cada2015-12-08 15:45:58 -070042JOBS := $(shell grep processor /proc/cpuinfo | wc -l)
43
44# compiler/linker custom arguments
45DPDK_CPU_CFLAGS := -pie -fPIC
Jean-Mickael Guerin966a8b82016-03-02 19:05:05 +010046DPDK_CPU_LDFLAGS :=
Ed Warnickecb9cada2015-12-08 15:45:58 -070047DPDK_EXTRA_LDFLAGS := -g
48
49ifeq ($(DPDK_DEBUG),n)
Damjan Marione39a7b82016-04-26 14:54:57 +020050DPDK_EXTRA_CFLAGS := -g
Ed Warnickecb9cada2015-12-08 15:45:58 -070051else
Damjan Marione39a7b82016-04-26 14:54:57 +020052DPDK_EXTRA_CFLAGS := -g -O0
Ed Warnickecb9cada2015-12-08 15:45:58 -070053endif
54
55# translate gcc march values to DPDK arch
56ifeq ($(DPDK_MARCH),native)
57DPDK_MACHINE:=native # autodetect host CPU
58else ifeq ($(DPDK_MARCH),corei7)
59DPDK_MACHINE:=nhm # Nehalem / Westmere
60else ifeq ($(DPDK_MARCH),corei7-avx)
61DPDK_MACHINE:=snb # Sandy Bridge
62else ifeq ($(DPDK_MARCH),core-avx-i)
63DPDK_MACHINE:=ivb # Ivy Bridge
64else ifeq ($(DPDK_MARCH),core-avx2)
65DPDK_MACHINE:=hsw # Haswell
66else
67$(error Unknown DPDK_MARCH)
68endif
69
70# assemble DPDK make arguments
71DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
72 T=$(DPDK_TARGET) \
73 RTE_CONFIG_TEMPLATE=../custom-config \
74 RTE_OUTPUT=$(I) \
75 EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
76 EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
77 CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
78 CPU_LDFLAGS="$(DPDK_CPU_LDFLAGS)"
79
80DPDK_SOURCE_FILES := $(shell [ -e $(DPDK_SOURCE) ] && find $(DPDK_SOURCE) -name "*.[chS]")
81
82define set
83@if grep -q CONFIG_$1 $@ ; \
84 then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
85 else echo CONFIG_$1=$2 >> $@ ; \
86fi
87endef
88
89all: build
90
91$(B)/custom-config: $(B)/.patch.ok Makefile
Damjan Marion106f0ed2016-04-26 10:44:28 +020092 @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) ---
93 @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@
Ed Warnickecb9cada2015-12-08 15:45:58 -070094 $(call set,RTE_MACHINE,$(DPDK_MACHINE))
Ed Warnickecb9cada2015-12-08 15:45:58 -070095 @# modify options
Damjan Marion13f07182016-02-05 06:44:54 -080096 $(call set,RTE_MAX_LCORE,256)
Ed Warnickecb9cada2015-12-08 15:45:58 -070097 $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
98 $(call set,RTE_LIBEAL_USE_HPET,y)
99 $(call set,RTE_BUILD_COMBINE_LIBS,y)
100 $(call set,RTE_LIBRTE_I40E_16BYTE_RX_DESC,y)
101 $(call set,RTE_LIBRTE_I40E_ITR_INTERVAL,16)
102 @# enable debug init for device drivers
103 $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
104 $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
105 $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
106 $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
107 $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
John Lod9bf9ab2016-02-25 11:17:55 -0500108 $(call set,RTE_LIBRTE_PMD_BOND,y)
109 $(call set,RTE_LIBRTE_IP_FRAG,y)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700110 @# not needed
Ed Warnickecb9cada2015-12-08 15:45:58 -0700111 $(call set,RTE_LIBRTE_TIMER,n)
112 $(call set,RTE_LIBRTE_CFGFILE,n)
113 $(call set,RTE_LIBRTE_LPM,n)
114 $(call set,RTE_LIBRTE_ACL,n)
115 $(call set,RTE_LIBRTE_POWER,n)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700116 $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
117 $(call set,RTE_LIBRTE_REORDER,n)
118 $(call set,RTE_LIBRTE_PORT,n)
119 $(call set,RTE_LIBRTE_TABLE,n)
120 $(call set,RTE_LIBRTE_PIPELINE,n)
121 $(call set,RTE_KNI_KMOD,n)
122 @rm -f .config.ok
123
124$(CURDIR)/$(DPDK_TARBALL):
125 @mkdir -p $(B)
126 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
127 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
128 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
129 fi
130 @rm -f $(B)/.download.ok
131
132$(B)/.download.ok: $(CURDIR)/$(DPDK_TARBALL)
133 @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
Damjan Marionbce6b6a2015-12-16 04:27:37 +0100134 @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700135 ( echo "Bad Checksum! Please remove $< and retry" && \
136 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
137 @touch $@
138
139.PHONY: download
140download: $(B)/.download.ok
141
142$(B)/.extract.ok: $(B)/.download.ok
143 @echo --- extracting $(DPDK_TARBALL) ---
144 @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL) --gzip
145 @touch $@
146
147.PHONY: extract
148extract: $(B)/.extract.ok
149
150$(B)/.patch.ok: $(B)/.extract.ok
Damjan Marion0df78dd2016-03-29 22:37:02 +0200151ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700152 @echo --- patching ---
153 for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
154 echo Applying patch: $$(basename $$f) ; \
155 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
156 done
Damjan Marion0df78dd2016-03-29 22:37:02 +0200157endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158 @touch $@
159
160.PHONY: patch
161patch: $(B)/.patch.ok
162
163$(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
164 @make $(DPDK_MAKE_ARGS) config
165 @touch $@
166
167.PHONY: config
168config: $(B)/.config.ok
169
170$(B)/.build.ok: $(DPDK_SOURCE_FILES)
171 @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
172 @make $(DPDK_MAKE_ARGS) install
173 @dkms/create_deb_manifest.sh $(DPDK_VERSION) $(subst $(realpath ..)/,,$(B))
174 @touch $@
175
176.PHONY: build
177build: $(B)/.build.ok
178
179.PHONY: clean
180clean:
181 @rm -rf $(B) $(I)
182