Fix compile errors reported by clang
[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 ?= 16.04
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
35 ifneq (,$(findstring clang,$(CC)))
36 DPDK_CC=clang
37 else
38 DPDK_CC=gcc
39 endif
40
41 DPDK_TARGET := x86_64-native-linuxapp-$(DPDK_CC)
42 JOBS := $(shell grep processor /proc/cpuinfo | wc -l)
43
44 # compiler/linker custom arguments
45 DPDK_CPU_CFLAGS := -pie -fPIC
46 DPDK_CPU_LDFLAGS :=
47 DPDK_EXTRA_LDFLAGS := -g
48
49 ifeq ($(DPDK_DEBUG),n)
50 DPDK_EXTRA_CFLAGS := -g
51 else
52 DPDK_EXTRA_CFLAGS := -g -O0
53 endif
54
55 # translate gcc march values to DPDK arch
56 ifeq ($(DPDK_MARCH),native)
57 DPDK_MACHINE:=native                     # autodetect host CPU
58 else ifeq ($(DPDK_MARCH),corei7)
59 DPDK_MACHINE:=nhm                        # Nehalem / Westmere
60 else ifeq ($(DPDK_MARCH),corei7-avx)
61 DPDK_MACHINE:=snb                        # Sandy Bridge
62 else ifeq ($(DPDK_MARCH),core-avx-i)
63 DPDK_MACHINE:=ivb                        # Ivy Bridge
64 else ifeq ($(DPDK_MARCH),core-avx2)
65 DPDK_MACHINE:=hsw                        # Haswell
66 else
67 $(error Unknown DPDK_MARCH)
68 endif
69
70 # assemble DPDK make arguments
71 DPDK_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
80 DPDK_SOURCE_FILES := $(shell  [ -e $(DPDK_SOURCE) ] && find $(DPDK_SOURCE) -name "*.[chS]")  
81
82 define set
83 @if grep -q CONFIG_$1 $@ ; \
84         then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
85         else echo CONFIG_$1=$2 >> $@ ; \
86 fi
87 endef
88
89 all: build
90
91 $(B)/custom-config: $(B)/.patch.ok Makefile
92         @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) $@
94         $(call set,RTE_MACHINE,$(DPDK_MACHINE))
95         @# modify options
96         $(call set,RTE_MAX_LCORE,256)
97         $(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))
108         $(call set,RTE_LIBRTE_PMD_BOND,y)
109         $(call set,RTE_LIBRTE_IP_FRAG,y)
110         @# not needed
111         $(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)
116         $(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
134         @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
135         ( echo "Bad Checksum! Please remove $< and retry" && \
136                 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
137         @touch $@
138
139 .PHONY: download
140 download: $(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
148 extract: $(B)/.extract.ok
149
150 $(B)/.patch.ok: $(B)/.extract.ok
151 ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
152         @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
157 endif
158         @touch $@
159
160 .PHONY: patch
161 patch: $(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
168 config: $(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
177 build: $(B)/.build.ok
178
179 .PHONY: clean
180 clean:
181         @rm -rf $(B) $(I)
182