Makefile revision 3395610e
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
15SHELL := /bin/bash
16
17DPDK_VERSION ?= 16.04
18DPDK_BUILD_DIR        ?= $(CURDIR)/_build
19DPDK_INSTALL_DIR      ?= $(DPDK_BUILD_DIR)/dpdk-$(DPDK_VERSION)/$(RTE_TARGET)
20DPDK_PKTMBUF_HEADROOM ?= 128
21DPDK_DOWNLOAD_DIR     ?= $(HOME)/Downloads
22DPDK_MARCH            ?= native
23DPDK_TUNE             ?= generic
24DPDK_DEBUG            ?= n
25
26B := $(DPDK_BUILD_DIR)
27I := $(DPDK_INSTALL_DIR)
28DPDK_BASE_URL ?= https://nexus.fd.io/content/repositories/thirdparty/
29DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.gz
30DPDK_TAR_URL := $(DPDK_BASE_URL)/$(DPDK_TARBALL)
31DPDK_2.1.0_TARBALL_MD5_CKSUM := 205a0d12bfd6eb717d57506272f43519
32DPDK_2.2.0_TARBALL_MD5_CKSUM := 22e2fd68cd5504f43fe9a5a6fd6dd938
33DPDK_16.04_TARBALL_MD5_CKSUM := 0728d506d7f56eb64233e824fa3c098a
34DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
35
36ifneq (,$(findstring clang,$(CC)))
37DPDK_CC=clang
38else
39DPDK_CC=gcc
40endif
41
42
43ifeq (,$(DPDK_TARGET))
44DPDK_TARGET := x86_64-native-linuxapp-$(DPDK_CC)
45endif
46
47JOBS := $(shell grep processor /proc/cpuinfo | wc -l)
48
49# compiler/linker custom arguments
50DPDK_CPU_CFLAGS := -pie -fPIC
51DPDK_CPU_LDFLAGS :=
52DPDK_EXTRA_LDFLAGS := -g
53
54ifeq ($(DPDK_DEBUG),n)
55DPDK_EXTRA_CFLAGS := -g -mtune=$(DPDK_TUNE)
56else
57DPDK_EXTRA_CFLAGS := -g -O0
58endif
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
71else ifeq ($(DPDK_MARCH),armv7a)
72DPDK_MACHINE:=armv7a                     # ARMv7
73else ifeq ($(DPDK_MARCH),armv8a)
74DPDK_MACHINE:=armv8a                     # ARMv8
75else
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)" \
87	CPU_LDFLAGS="$(DPDK_CPU_LDFLAGS)" \
88        $(DPDK_MAKE_EXTRA_ARGS)
89
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
102	@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) $@
104	$(call set,RTE_MACHINE,$(DPDK_MACHINE))
105	@# modify options
106	$(call set,RTE_MAX_LCORE,256)
107	$(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)
111	$(call set,RTE_LIBRTE_I40E_ITR_INTERVAL,16)
112	@# enable debug init for device drivers
113	$(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
114	$(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
115	$(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
116	$(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
117	$(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
118	$(call set,RTE_LIBRTE_PMD_BOND,y)
119	$(call set,RTE_LIBRTE_IP_FRAG,y)
120	@# not needed
121	$(call set,RTE_LIBRTE_TIMER,n)
122	$(call set,RTE_LIBRTE_CFGFILE,n)
123	$(call set,RTE_LIBRTE_LPM,y)
124	$(call set,RTE_LIBRTE_ACL,n)
125	$(call set,RTE_LIBRTE_POWER,n)
126	$(call set,RTE_LIBRTE_DISTRIBUTOR,n)
127	$(call set,RTE_LIBRTE_REORDER,n)
128	$(call set,RTE_LIBRTE_PORT,n)
129	$(call set,RTE_LIBRTE_TABLE,n)
130	$(call set,RTE_LIBRTE_PIPELINE,n)
131	$(call set,RTE_KNI_KMOD,n)
132	@rm -f .config.ok
133
134$(CURDIR)/$(DPDK_TARBALL):
135	@mkdir -p $(B)
136	@if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
137		then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
138		else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
139	fi
140	@rm -f $(B)/.download.ok
141
142$(B)/.download.ok: $(CURDIR)/$(DPDK_TARBALL)
143	@openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
144	@([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
145	( echo "Bad Checksum! Please remove $< and retry" && \
146		rm $(B)/$(DPDK_TARBALL).md5sum && false ))
147	@touch $@
148
149.PHONY: download
150download: $(B)/.download.ok
151
152$(B)/.extract.ok: $(B)/.download.ok
153	@echo --- extracting $(DPDK_TARBALL) ---
154	@tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL) --gzip
155	@touch $@
156
157.PHONY: extract
158extract: $(B)/.extract.ok
159
160$(B)/.patch.ok: $(B)/.extract.ok
161ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
162	@echo --- patching ---
163	for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
164		echo Applying patch: $$(basename $$f) ; \
165		patch -p1 -d $(DPDK_SOURCE) < $$f ; \
166	done
167endif
168	@touch $@
169
170.PHONY: patch
171patch: $(B)/.patch.ok
172
173$(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
174	@make $(DPDK_MAKE_ARGS) config
175	@touch $@
176
177.PHONY: config
178config: $(B)/.config.ok
179
180$(B)/.build.ok: $(DPDK_SOURCE_FILES)
181	@if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
182	@make $(DPDK_MAKE_ARGS) install
183	@cp $(I)/.config $(B)/.config
184	@touch $@
185
186.PHONY: build
187build: $(B)/.build.ok
188
189.PHONY: clean
190clean:
191	@rm -rf $(B) $(I)
192
193