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 117endif 118endif 119 120# Force-disable scan-build 121SUB_CC = $(patsubst %ccc-analyzer,$(DEFAULT_CC),$(CC)) 122 123DPDK_ALL_LIB_DIRS = $(shell find $(SPDK_ROOT_DIR)/dpdk/lib -mindepth 1 -maxdepth 1 -type d) 124DPDK_ALL_LIBS = $(DPDK_ALL_LIB_DIRS:$(SPDK_ROOT_DIR)/dpdk/lib/%=%) 125DPDK_DISABLED_LIBS = $(filter-out $(DPDK_LIBS),$(DPDK_ALL_LIBS)) 126 127ifneq ($(OS),FreeBSD) 128SED_INPLACE_FLAG = "-i" 129MESON_PREFIX = $(SPDK_ROOT_DIR)/dpdk/build 130else 131SED_INPLACE_FLAG = "-i ''" 132MESON_PREFIX = "/" 133endif 134 135# Some ninja versions come with a (broken?) jobserver which defaults to use 136# only 1 thread for the build. We workaround this by specifying -j to ninja 137# with the same value as top-makefile. This is OK as long as DPDK is not built 138# in parallel with anything else, which is the case for now. 139ifeq ($(MAKE_PID),) 140MAKE_PID := $(shell echo $$PPID) 141endif 142 143MAKE_NUMJOBS := $(shell ps T | sed -nE 's/[[:space:]]*$(MAKE_PID)[[:space:]].* (-j|--jobs=)( *[0-9]+).*/\1\2/p') 144 145all: $(SPDK_ROOT_DIR)/dpdk/build-tmp 146 $(Q)# DPDK doesn't handle nested make calls, so unset MAKEFLAGS 147 $(Q)env -u MAKEFLAGS ninja -C $(SPDK_ROOT_DIR)/dpdk/build-tmp $(MAKE_NUMJOBS) 148 $(Q) \ 149 # Meson on FreeBSD sometimes appends --prefix value to the default DESTDIR (which is e.g. \ 150 # /usr/local) instead of replacing it. --prefix needs to be an absolute path, so we set \ 151 # it to / and then set DESTDIR directly, so libs and headers are copied to "DESTDIR//". \ 152 # DPDK kernel modules are set to install in $DESTDIR/boot/modules, but we move them \ 153 # to DESTDIR/kmod to be consistent with the makefile build. \ 154 # \ 155 # Also use meson install --only-changed instead of ninja install so that the shared \ 156 # libraries don't get reinstalled when they haven't been rebuilt - this avoids all of \ 157 # our applications getting relinked even when nothing has changed. 158 $(Q)if [ "$(OS)" = "FreeBSD" ]; then \ 159 env -u MAKEFLAGS DESTDIR=$(SPDK_ROOT_DIR)/dpdk/build ninja -C $(SPDK_ROOT_DIR)/dpdk/build-tmp $(MAKE_NUMJOBS) install > /dev/null && \ 160 mv $(SPDK_ROOT_DIR)/dpdk/build/boot/modules $(SPDK_ROOT_DIR)/dpdk/build/kmod; \ 161 else \ 162 env -u MAKEFLAGS meson install -C $(SPDK_ROOT_DIR)/dpdk/build-tmp --only-changed > /dev/null; \ 163 fi 164 165$(SPDK_ROOT_DIR)/dpdk/build-tmp: $(SPDK_ROOT_DIR)/mk/cc.mk $(SPDK_ROOT_DIR)/include/spdk/config.h 166 $(Q)rm -rf $(SPDK_ROOT_DIR)/dpdk/build $(SPDK_ROOT_DIR)/dpdk/build-tmp 167 $(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 168 $(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 169 $(Q) \ 170 # TODO Meson build adds libbsd and/or libarchive dependency when it's available. This means any app will be \ 171 # forced to link with -lbsd and/or -larchive, but only if it's available on the system. The clean way to \ 172 # handle this would be to rely on DPDK's pkg-config file which will contain the -lbsd/-larchive when \ 173 # required. For now just remove the dependencies. DPDK will fallback to its internal functions. 174 $(Q)sed $(SED_INPLACE_FLAG) 's/#define RTE_USE_LIBBSD .*//g' $(SPDK_ROOT_DIR)/dpdk/build-tmp/rte_build_config.h 175 $(Q)sed $(SED_INPLACE_FLAG) 's/#define RTE_HAS_LIBARCHIVE .*//g' $(SPDK_ROOT_DIR)/dpdk/build-tmp/rte_build_config.h 176 177clean: 178 $(Q)rm -rf $(SPDK_ROOT_DIR)/dpdk/build $(SPDK_ROOT_DIR)/dpdk/build-tmp 179 180install: 181 @: 182 183uninstall: 184 @: 185