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