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