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