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