xref: /spdk/dpdkbuild/Makefile (revision 355312bfcd3751f9af17fbefc90373fb8a269614)
1#  SPDX-License-Identifier: BSD-3-Clause
2#  Copyright (C) 2017 Intel Corporation.
3#  All rights reserved.
4#  Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5#
6
7SPDK_ROOT_DIR := $(abspath $(CURDIR)/..)
8include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
9
10.PHONY: all clean install uninstall
11
12DPDK_OPTS = -Denable_docs=false
13DPDK_OPTS += -Dtests=false
14DPDK_CFLAGS =
15
16ifeq ($(shell uname -m),aarch64)
17ifeq ($(shell uname -p),unknown)
18# Unknown ARM platform. ARM doesn't do platform=native which is DPDK's default. So change it.
19DPDK_OPTS += -Dplatform=generic
20endif
21endif
22
23DPDK_KMODS = false
24ifeq ($(OS),FreeBSD)
25DPDK_KMODS = true
26endif
27DPDK_OPTS += -Denable_kmods=$(DPDK_KMODS)
28
29ifeq ($(CONFIG_DEBUG),y)
30DPDK_OPTS += --buildtype=debug
31endif
32
33ifeq ($(CONFIG_SHARED),y)
34DPDK_OPTS += --default-library=shared
35else
36DPDK_OPTS += --default-library=static
37endif
38
39ifeq ($(CONFIG_LTO),y)
40# dpdk complains about compiler not supporting fat LTO objects when clang is in use so don't enable it in such a instance
41ifneq ($(CC_TYPE),clang)
42DPDK_OPTS += -Db_lto=true
43endif
44endif
45
46# the drivers we use
47DPDK_DRIVERS = bus bus/pci bus/vdev mempool/ring
48
49# Core DPDK libs
50DPDK_LIBS = eal ring mempool pci
51DPDK_LIBS += log kvargs telemetry
52# Governor required libs
53DPDK_LIBS += power timer ethdev net
54
55# common crypto/compress drivers
56ifeq ($(findstring y,$(CONFIG_DPDK_COMPRESSDEV)$(CONFIG_CRYPTO)$(CONFIG_VBDEV_COMPRESS)),y)
57DPDK_DRIVERS += crypto/qat compress/qat common/qat
58endif
59
60# common mlx5 libs
61ifeq ($(findstring y,$(CONFIG_CRYPTO_MLX5)$(CONFIG_VBDEV_COMPRESS_MLX5)),y)
62DPDK_DRIVERS += common/mlx5 bus/auxiliary
63endif
64
65ifeq ($(CONFIG_CRYPTO),y)
66DPDK_DRIVERS += crypto
67# aesni_mb is name of the PMD in DPDK 21.08 and earlier
68DPDK_DRIVERS += crypto/aesni_mb
69ifeq ($(CONFIG_CRYPTO_MLX5),y)
70DPDK_DRIVERS += crypto/mlx5
71endif
72ifeq ($(CONFIG_IPSEC_MB),y)
73DPDK_DRIVERS += crypto/ipsec_mb
74DPDK_CFLAGS += -I$(IPSEC_MB_DIR)
75# Workaround for DPDK 22.07 and DPDK 22.11.1,
76# will be able to remove starting with DPDK 23.03.
77ifeq ($(shell grep "define NO_COMPAT_IMB_API_053" $(SPDK_ROOT_DIR)/dpdk/drivers/crypto/qat/qat_sym_session.c), )
78DPDK_CFLAGS += -DNO_COMPAT_IMB_API_053
79endif
80DPDK_LDFLAGS += -L$(IPSEC_MB_DIR)
81endif
82endif
83
84ifeq ($(findstring y,$(CONFIG_DPDK_COMPRESSDEV)$(CONFIG_VBDEV_COMPRESS)),y)
85DPDK_DRIVERS += compress compress/isal
86ifeq ($(CONFIG_VBDEV_COMPRESS_MLX5),y)
87DPDK_DRIVERS += compress/mlx5
88endif
89DPDK_CFLAGS += -I$(ISAL_DIR)
90DPDK_LDFLAGS += -L$(ISAL_DIR)/.libs -lisal
91endif
92
93DPDK_ENABLED_DRIVERS = $(shell echo $(DPDK_DRIVERS) | sed -E "s/ +/,/g")
94
95# crypto & compress deps
96DPDK_LIBS += reorder cryptodev
97DPDK_LIBS += compressdev
98DPDK_LIBS += security
99
100# vhost and deps
101DPDK_LIBS += cryptodev mbuf cmdline meter hash vhost dmadev
102
103# raid5 deps
104DPDK_LIBS += hash rcu
105
106DPDK_OPTS += -Dcpu_instruction_set=$(TARGET_ARCHITECTURE)
107
108ifneq ($(CONFIG_CROSS_PREFIX),)
109ifeq ($(findstring mingw,$(CONFIG_CROSS_PREFIX)),mingw)
110DPDK_OPTS += --cross-file $(SPDK_ROOT_DIR)/dpdk/config/x86/cross-mingw
111else
112$(error Automatic DPDK cross build is not supported. Please compile DPDK manually \
113with e.g. `meson build --cross-file config/arm/arm64_armv8_linux_gcc`)
114endif
115endif
116
117# DPDK supports ASAN since version 21.11
118ifeq ($(CONFIG_ASAN),y)
119ifneq ($(OS),Windows)
120DPDK_OPTS += -Db_sanitize=address
121ifeq ($(CC_TYPE),clang)
122DPDK_OPTS += -Db_lundef=false
123endif
124endif
125endif
126
127DPDK_CFLAGS += -fPIC
128
129ifneq ($(CONFIG_MAX_LCORES),)
130DPDK_OPTS += -Dmax_lcores=$(CONFIG_MAX_LCORES)
131endif
132
133ifeq ($(CONFIG_WERROR),y)
134DPDK_CFLAGS += -Werror
135else
136DPDK_CFLAGS += -Wno-error
137endif
138
139ifeq ($(CONFIG_CET),y)
140DPDK_CFLAGS += -fcf-protection
141DPDK_LDFLAGS += -fcf-protection
142endif
143
144ifdef EXTRA_DPDK_CFLAGS
145$(warning EXTRA_DPDK_CFLAGS defined, possibly to work around an unsupported compiler version)
146$(shell sleep 1)
147endif
148
149# Allow users to specify EXTRA_DPDK_CFLAGS if they want to build DPDK using unsupported compiler versions
150DPDK_CFLAGS += $(EXTRA_DPDK_CFLAGS)
151
152ifeq ($(CC_TYPE),gcc)
153GCC_MAJOR = $(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
154ifeq ($(shell test $(GCC_MAJOR) -ge 10 && echo 1), 1)
155#1. gcc 10 complains on operations with zero size arrays in rte_cryptodev.c, so
156#disable this warning
157#2. gcc 10 disables fcommon by default and complains on multiple definition of
158#aesni_mb_logtype_driver symbol which is defined in header file and presented in several
159#translation units
160DPDK_CFLAGS += -Wno-stringop-overflow -fcommon
161ifeq ($(shell test $(GCC_MAJOR) -ge 12 && echo 1), 1)
162# 3. gcc 12 reports reading incorect size from a region. Seems like false positive,
163# see issue #2460
164DPDK_CFLAGS += -Wno-stringop-overread
165# 4. gcc 12 reports array subscript * is outside array bounds. Seems like false positive,
166# see issue #2668
167DPDK_CFLAGS += -Wno-array-bounds
168endif
169endif
170endif
171
172# Force-disable scan-build
173SUB_CC = $(patsubst %ccc-analyzer,$(DEFAULT_CC),$(CC))
174
175DPDK_ALL_LIB_DIRS = $(shell find $(SPDK_ROOT_DIR)/dpdk/lib -mindepth 1 -maxdepth 1 -type d)
176DPDK_ALL_LIBS = $(DPDK_ALL_LIB_DIRS:$(SPDK_ROOT_DIR)/dpdk/lib/%=%)
177DPDK_DISABLED_LIBS = $(shell echo $(filter-out $(DPDK_LIBS),$(DPDK_ALL_LIBS)) | sed -E "s/ +/,/g")
178
179ifeq ($(shell grep -q disable_apps $(SPDK_ROOT_DIR)/dpdk/meson_options.txt && echo 1), 1)
180DPDK_ALL_APP_DIRS = $(shell find $(SPDK_ROOT_DIR)/dpdk/app -mindepth 1 -maxdepth 1 -type d)
181DPDK_ALL_APPS = $(DPDK_ALL_APP_DIRS:$(SPDK_ROOT_DIR)/dpdk/app/%=%)
182DPDK_DISABLED_APPS = -Ddisable_apps="$(shell echo $(DPDK_ALL_APPS) | sed -E "s/ +/,/g")"
183endif
184
185ifneq ($(OS),FreeBSD)
186SED_INPLACE_FLAG = "-i"
187MESON_PREFIX = $(SPDK_ROOT_DIR)/dpdk/build
188else
189SED_INPLACE_FLAG = "-i ''"
190MESON_PREFIX = "/"
191endif
192
193# Some ninja versions come with a (broken?) jobserver which defaults to use
194# only 1 thread for the build. We workaround this by specifying -j to ninja
195# with the same value as top-makefile. This is OK as long as DPDK is not built
196# in parallel with anything else, which is the case for now.
197ifeq ($(MAKE_PID),)
198MAKE_PID := $(shell echo $$PPID)
199endif
200
201MAKE_NUMJOBS := $(shell ps T | sed -nE 's/[[:space:]]*$(MAKE_PID)[[:space:]].* (-j|--jobs=)( *[0-9]+).*/\1\2/p')
202
203all: $(SPDK_ROOT_DIR)/dpdk/build-tmp
204	$(Q)# DPDK doesn't handle nested make calls, so unset MAKEFLAGS
205	$(Q)env -u MAKEFLAGS meson compile -C $(SPDK_ROOT_DIR)/dpdk/build-tmp $(MAKE_NUMJOBS)
206	$(Q) \
207	# Meson on FreeBSD sometimes appends --prefix value to the default DESTDIR (which is e.g. \
208	# /usr/local) instead of replacing it. --prefix needs to be an absolute path, so we set \
209	# it to / and then set DESTDIR directly, so libs and headers are copied to "DESTDIR//". \
210	# DPDK kernel modules are set to install in $DESTDIR/boot/modules, but we move them \
211	# to DESTDIR/kmod to be consistent with the makefile build. \
212	# \
213	# Also use meson install --only-changed instead of ninja install so that the shared \
214	# libraries don't get reinstalled when they haven't been rebuilt - this avoids all of \
215	# our applications getting relinked even when nothing has changed.
216	$(Q)if [ "$(OS)" = "FreeBSD" ]; then \
217		env -u MAKEFLAGS DESTDIR=$(SPDK_ROOT_DIR)/dpdk/build ninja -C $(SPDK_ROOT_DIR)/dpdk/build-tmp $(MAKE_NUMJOBS) install > /dev/null && \
218		mv $(SPDK_ROOT_DIR)/dpdk/build/boot/modules $(SPDK_ROOT_DIR)/dpdk/build/kmod; \
219	else \
220		env -u MAKEFLAGS meson install -C $(SPDK_ROOT_DIR)/dpdk/build-tmp --only-changed > /dev/null; \
221	fi
222
223$(SPDK_ROOT_DIR)/dpdk/build-tmp: $(SPDK_ROOT_DIR)/mk/cc.mk $(SPDK_ROOT_DIR)/include/spdk/config.h
224	$(Q)rm -rf $(SPDK_ROOT_DIR)/dpdk/build $(SPDK_ROOT_DIR)/dpdk/build-tmp
225	$(Q)cd "$(SPDK_ROOT_DIR)/dpdk"; CC="$(SUB_CC)" meson setup --prefix="$(MESON_PREFIX)" --libdir lib -Dc_args="$(DPDK_CFLAGS)" -Dc_link_args="$(DPDK_LDFLAGS)" $(DPDK_OPTS) -Denable_drivers="$(DPDK_ENABLED_DRIVERS)" -Ddisable_libs="$(DPDK_DISABLED_LIBS)" $(DPDK_DISABLED_APPS) $(DPDKBUILD_FLAGS) build-tmp
226	$(Q)sed $(SED_INPLACE_FLAG) 's/#define RTE_EAL_PMD_PATH .*/#define RTE_EAL_PMD_PATH ""/g' $(SPDK_ROOT_DIR)/dpdk/build-tmp/rte_build_config.h
227
228clean:
229	$(Q)rm -rf $(SPDK_ROOT_DIR)/dpdk/build $(SPDK_ROOT_DIR)/dpdk/build-tmp
230
231install:
232	$(Q)cd "$(SPDK_ROOT_DIR)/dpdk"; CC="$(SUB_CC)" meson setup --prefix="$(CONFIG_PREFIX)" --reconfigure build-tmp
233	$(Q)env -u MAKEFLAGS meson install -C $(SPDK_ROOT_DIR)/dpdk/build-tmp --no-rebuild
234	$(Q)cd "$(SPDK_ROOT_DIR)/dpdk"; CC="$(SUB_CC)" meson setup --prefix="$(MESON_PREFIX)" --reconfigure build-tmp
235
236
237# meson has no uninstall target. We'll just do our best.
238uninstall:
239	$(Q)rm -rf $(DESTDIR)$(CONFIG_PREFIX)/share/dpdk
240	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/bin/dpdk-*.py
241	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/include/rte_*.h
242	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/include/generic/rte_*.h
243	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/lib/librte_*
244	$(Q)rm -rf $(DESTDIR)$(CONFIG_PREFIX)/lib/dpdk
245	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/lib/pkgconfig/libdpdk*
246	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/include/cmdline_parse_portlist.h
247	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/include/cmdline_cirbuf.h
248	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/include/cmdline_socket.h
249	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/include/cmdline_vt100.h
250	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/include/cmdline_rdline.h
251	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/include/cmdline_parse_string.h
252	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/include/cmdline_parse_etheraddr.h
253	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/include/cmdline_parse_ipaddr.h
254	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/include/cmdline_parse_num.h
255	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/include/cmdline_parse.h
256	$(Q)rm -f $(DESTDIR)$(CONFIG_PREFIX)/include/cmdline.h
257