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