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