xref: /spdk/dpdkbuild/Makefile (revision 58549382d02320e5d13bd57a16e33c39dc648848)
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_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)
62DPDK_LDFLAGS += -L$(IPSEC_MB_DIR)
63endif
64endif
65
66ifeq ($(CONFIG_VBDEV_COMPRESS),y)
67DPDK_DRIVERS += compress compress/isal
68ifeq ($(CONFIG_VBDEV_COMPRESS_MLX5),y)
69DPDK_DRIVERS += compress/mlx5
70endif
71DPDK_CFLAGS += -I$(ISAL_DIR)
72DPDK_LDFLAGS += -L$(ISAL_DIR)/.libs -lisal
73endif
74
75# crypto & compress deps
76DPDK_LIBS += reorder cryptodev
77DPDK_LIBS += compressdev
78DPDK_LIBS += security
79
80# vhost and deps
81DPDK_LIBS += cryptodev mbuf cmdline meter hash vhost dmadev
82
83# raid5 deps
84DPDK_LIBS += hash rcu
85
86DPDK_OPTS += -Dcpu_instruction_set=$(TARGET_ARCHITECTURE)
87
88ifneq ($(CONFIG_CROSS_PREFIX),)
89ifeq ($(findstring mingw,$(CONFIG_CROSS_PREFIX)),mingw)
90DPDK_OPTS += --cross-file $(SPDK_ROOT_DIR)/dpdk/config/x86/cross-mingw
91else
92$(error Automatic DPDK cross build is not supported. Please compile DPDK manually \
93with e.g. `meson build --cross-file config/arm/arm64_armv8_linux_gcc`)
94endif
95endif
96
97DPDK_CFLAGS += -fPIC
98
99ifeq ($(CONFIG_WERROR),y)
100DPDK_CFLAGS += -Werror
101else
102DPDK_CFLAGS += -Wno-error
103endif
104
105ifeq ($(CONFIG_CET),y)
106DPDK_CFLAGS += -fcf-protection
107DPDK_LDFLAGS += -fcf-protection
108endif
109
110ifdef EXTRA_DPDK_CFLAGS
111$(warning EXTRA_DPDK_CFLAGS defined, possibly to work around an unsupported compiler version)
112$(shell sleep 1)
113endif
114
115# Allow users to specify EXTRA_DPDK_CFLAGS if they want to build DPDK using unsupported compiler versions
116DPDK_CFLAGS += $(EXTRA_DPDK_CFLAGS)
117
118ifeq ($(CC_TYPE),gcc)
119GCC_MAJOR = $(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
120ifeq ($(shell test $(GCC_MAJOR) -ge 10 && echo 1), 1)
121#1. gcc 10 complains on operations with zero size arrays in rte_cryptodev.c, so
122#disable this warning
123#2. gcc 10 disables fcommon by default and complains on multiple definition of
124#aesni_mb_logtype_driver symbol which is defined in header file and presented in several
125#translation units
126DPDK_CFLAGS += -Wno-stringop-overflow -fcommon
127ifeq ($(shell test $(GCC_MAJOR) -ge 12 && echo 1), 1)
128# 3. gcc 12 reports reading incorect size from a region. Seems like false positive,
129# see issue #2460
130DPDK_CFLAGS += -Wno-stringop-overread
131# 4. gcc 12 reports array subscript * is outside array bounds. Seems like false positive,
132# see issue #2668
133DPDK_CFLAGS += -Wno-array-bounds
134endif
135endif
136endif
137
138# Force-disable scan-build
139SUB_CC = $(patsubst %ccc-analyzer,$(DEFAULT_CC),$(CC))
140
141DPDK_ALL_LIB_DIRS = $(shell find $(SPDK_ROOT_DIR)/dpdk/lib -mindepth 1 -maxdepth 1 -type d)
142DPDK_ALL_LIBS = $(DPDK_ALL_LIB_DIRS:$(SPDK_ROOT_DIR)/dpdk/lib/%=%)
143DPDK_DISABLED_LIBS = $(filter-out $(DPDK_LIBS),$(DPDK_ALL_LIBS))
144
145ifneq ($(OS),FreeBSD)
146SED_INPLACE_FLAG = "-i"
147MESON_PREFIX = $(SPDK_ROOT_DIR)/dpdk/build
148else
149SED_INPLACE_FLAG = "-i ''"
150MESON_PREFIX = "/"
151endif
152
153# Some ninja versions come with a (broken?) jobserver which defaults to use
154# only 1 thread for the build. We workaround this by specifying -j to ninja
155# with the same value as top-makefile. This is OK as long as DPDK is not built
156# in parallel with anything else, which is the case for now.
157ifeq ($(MAKE_PID),)
158MAKE_PID := $(shell echo $$PPID)
159endif
160
161MAKE_NUMJOBS := $(shell ps T | sed -nE 's/[[:space:]]*$(MAKE_PID)[[:space:]].* (-j|--jobs=)( *[0-9]+).*/\1\2/p')
162
163all: $(SPDK_ROOT_DIR)/dpdk/build-tmp
164	$(Q)# DPDK doesn't handle nested make calls, so unset MAKEFLAGS
165	$(Q)env -u MAKEFLAGS ninja -C $(SPDK_ROOT_DIR)/dpdk/build-tmp $(MAKE_NUMJOBS)
166	$(Q) \
167	# Meson on FreeBSD sometimes appends --prefix value to the default DESTDIR (which is e.g. \
168	# /usr/local) instead of replacing it. --prefix needs to be an absolute path, so we set \
169	# it to / and then set DESTDIR directly, so libs and headers are copied to "DESTDIR//". \
170	# DPDK kernel modules are set to install in $DESTDIR/boot/modules, but we move them \
171	# to DESTDIR/kmod to be consistent with the makefile build. \
172	# \
173	# Also use meson install --only-changed instead of ninja install so that the shared \
174	# libraries don't get reinstalled when they haven't been rebuilt - this avoids all of \
175	# our applications getting relinked even when nothing has changed.
176	$(Q)if [ "$(OS)" = "FreeBSD" ]; then \
177		env -u MAKEFLAGS DESTDIR=$(SPDK_ROOT_DIR)/dpdk/build ninja -C $(SPDK_ROOT_DIR)/dpdk/build-tmp $(MAKE_NUMJOBS) install > /dev/null && \
178		mv $(SPDK_ROOT_DIR)/dpdk/build/boot/modules $(SPDK_ROOT_DIR)/dpdk/build/kmod; \
179	else \
180		env -u MAKEFLAGS meson install -C $(SPDK_ROOT_DIR)/dpdk/build-tmp --only-changed > /dev/null; \
181	fi
182
183$(SPDK_ROOT_DIR)/dpdk/build-tmp: $(SPDK_ROOT_DIR)/mk/cc.mk $(SPDK_ROOT_DIR)/include/spdk/config.h
184	$(Q)rm -rf $(SPDK_ROOT_DIR)/dpdk/build $(SPDK_ROOT_DIR)/dpdk/build-tmp
185	$(Q)cd "$(SPDK_ROOT_DIR)/dpdk"; CC="$(SUB_CC)" meson --prefix="$(MESON_PREFIX)" --libdir lib -Dc_args="$(DPDK_CFLAGS)" -Dc_link_args="$(DPDK_LDFLAGS)" $(DPDK_OPTS) -Denable_drivers="$(shell echo $(DPDK_DRIVERS) | sed -E "s/ +/,/g")" -Ddisable_libs="$(shell echo $(DPDK_DISABLED_LIBS) | sed -E "s/ +/,/g")" $(DPDKBUILD_FLAGS) build-tmp
186	$(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
187	$(Q) \
188	# TODO Meson build adds libbsd and/or libarchive dependency when it's available. This means any app will be \
189	# forced to link with -lbsd and/or -larchive, but only if it's available on the system. The clean way to \
190	# handle this would be to rely on DPDK's pkg-config file which will contain the -lbsd/-larchive when \
191	# required. For now just remove the dependencies. DPDK will fallback to its internal functions.
192	$(Q)sed $(SED_INPLACE_FLAG) 's/#define RTE_USE_LIBBSD .*//g' $(SPDK_ROOT_DIR)/dpdk/build-tmp/rte_build_config.h
193	$(Q)sed $(SED_INPLACE_FLAG) 's/#define RTE_HAS_LIBARCHIVE .*//g' $(SPDK_ROOT_DIR)/dpdk/build-tmp/rte_build_config.h
194
195clean:
196	$(Q)rm -rf $(SPDK_ROOT_DIR)/dpdk/build $(SPDK_ROOT_DIR)/dpdk/build-tmp
197
198install:
199	@:
200
201uninstall:
202	@:
203