blob: c33cf63ccf5cefb0e8fb3f93e359379bf8febe8d [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
19DPDK_PKTMBUF_HEADROOM ?= 256
20DPDK_DOWNLOAD_DIR ?= $(HOME)/Downloads
21DPDK_MARCH ?= native
22DPDK_DEBUG ?= n
23
24B := $(DPDK_BUILD_DIR)
25I := $(DPDK_INSTALL_DIR)
26DPDK_VERSION := 2.1.0
27DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.gz
28DPDK_TAR_URL := http://dpdk.org/browse/dpdk/snapshot/$(DPDK_TARBALL)
29DPDK_TARBALL_MD5_CKSUM := 205a0d12bfd6eb717d57506272f43519
30DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
31DPDK_TARGET := x86_64-native-linuxapp-gcc
32JOBS := $(shell grep processor /proc/cpuinfo | wc -l)
33
34# compiler/linker custom arguments
35DPDK_CPU_CFLAGS := -pie -fPIC
36DPDK_CPU_LDFLAGS := -pie -fPIC
37DPDK_EXTRA_LDFLAGS := -g
38
39ifeq ($(DPDK_DEBUG),n)
40DPDK_EXTRA_CFLAGS := -g
41else
42DPDK_EXTRA_CFLAGS := -g -O0
43endif
44
45# translate gcc march values to DPDK arch
46ifeq ($(DPDK_MARCH),native)
47DPDK_MACHINE:=native # autodetect host CPU
48else ifeq ($(DPDK_MARCH),corei7)
49DPDK_MACHINE:=nhm # Nehalem / Westmere
50else ifeq ($(DPDK_MARCH),corei7-avx)
51DPDK_MACHINE:=snb # Sandy Bridge
52else ifeq ($(DPDK_MARCH),core-avx-i)
53DPDK_MACHINE:=ivb # Ivy Bridge
54else ifeq ($(DPDK_MARCH),core-avx2)
55DPDK_MACHINE:=hsw # Haswell
56else
57$(error Unknown DPDK_MARCH)
58endif
59
60# assemble DPDK make arguments
61DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
62 T=$(DPDK_TARGET) \
63 RTE_CONFIG_TEMPLATE=../custom-config \
64 RTE_OUTPUT=$(I) \
65 EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
66 EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
67 CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
68 CPU_LDFLAGS="$(DPDK_CPU_LDFLAGS)"
69
70DPDK_SOURCE_FILES := $(shell [ -e $(DPDK_SOURCE) ] && find $(DPDK_SOURCE) -name "*.[chS]")
71
72define set
73@if grep -q CONFIG_$1 $@ ; \
74 then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
75 else echo CONFIG_$1=$2 >> $@ ; \
76fi
77endef
78
79all: build
80
81$(B)/custom-config: $(B)/.patch.ok Makefile
82 @echo --- generating custom config from $(DPDK_SOURCE)/config/common_linuxapp ---
83 @cp $(DPDK_SOURCE)/config/common_linuxapp $@
84 $(call set,RTE_MACHINE,$(DPDK_MACHINE))
85 $(call set,RTE_ARCH,"x86_64")
86 $(call set,RTE_ARCH_X86_64,y)
87 $(call set,RTE_ARCH_64,y)
88 $(call set,RTE_TOOLCHAIN_GCC,y)
89 $(call set,RTE_TOOLCHAIN,"gcc")
90 @# modify options
91 $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
92 $(call set,RTE_LIBEAL_USE_HPET,y)
93 $(call set,RTE_BUILD_COMBINE_LIBS,y)
94 $(call set,RTE_LIBRTE_I40E_16BYTE_RX_DESC,y)
95 $(call set,RTE_LIBRTE_I40E_ITR_INTERVAL,16)
96 @# enable debug init for device drivers
97 $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
98 $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
99 $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
100 $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
101 $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
102 @# not needed
103 $(call set,RTE_LIBRTE_PMD_BOND,n)
104 $(call set,RTE_LIBRTE_TIMER,n)
105 $(call set,RTE_LIBRTE_CFGFILE,n)
106 $(call set,RTE_LIBRTE_LPM,n)
107 $(call set,RTE_LIBRTE_ACL,n)
108 $(call set,RTE_LIBRTE_POWER,n)
109 $(call set,RTE_LIBRTE_IP_FRAG,n)
110 $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
111 $(call set,RTE_LIBRTE_REORDER,n)
112 $(call set,RTE_LIBRTE_PORT,n)
113 $(call set,RTE_LIBRTE_TABLE,n)
114 $(call set,RTE_LIBRTE_PIPELINE,n)
115 $(call set,RTE_KNI_KMOD,n)
116 @rm -f .config.ok
117
118$(CURDIR)/$(DPDK_TARBALL):
119 @mkdir -p $(B)
120 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
121 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
122 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
123 fi
124 @rm -f $(B)/.download.ok
125
126$(B)/.download.ok: $(CURDIR)/$(DPDK_TARBALL)
127 @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
128 @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_TARBALL_MD5_CKSUM)" ] || \
129 ( echo "Bad Checksum! Please remove $< and retry" && \
130 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
131 @touch $@
132
133.PHONY: download
134download: $(B)/.download.ok
135
136$(B)/.extract.ok: $(B)/.download.ok
137 @echo --- extracting $(DPDK_TARBALL) ---
138 @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL) --gzip
139 @touch $@
140
141.PHONY: extract
142extract: $(B)/.extract.ok
143
144$(B)/.patch.ok: $(B)/.extract.ok
145 @echo --- patching ---
146 for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
147 echo Applying patch: $$(basename $$f) ; \
148 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
149 done
150 @touch $@
151
152.PHONY: patch
153patch: $(B)/.patch.ok
154
155$(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
156 @make $(DPDK_MAKE_ARGS) config
157 @touch $@
158
159.PHONY: config
160config: $(B)/.config.ok
161
162$(B)/.build.ok: $(DPDK_SOURCE_FILES)
163 @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
164 @make $(DPDK_MAKE_ARGS) install
165 @dkms/create_deb_manifest.sh $(DPDK_VERSION) $(subst $(realpath ..)/,,$(B))
166 @touch $@
167
168.PHONY: build
169build: $(B)/.build.ok
170
171.PHONY: clean
172clean:
173 @rm -rf $(B) $(I)
174