1# 2# BSD LICENSE 3# 4# Copyright (c) Intel Corporation. 5# All rights reserved. 6# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions 10# are met: 11# 12# * Redistributions of source code must retain the above copyright 13# notice, this list of conditions and the following disclaimer. 14# * Redistributions in binary form must reproduce the above copyright 15# notice, this list of conditions and the following disclaimer in 16# the documentation and/or other materials provided with the 17# distribution. 18# * Neither the name of Intel Corporation nor the names of its 19# contributors may be used to endorse or promote products derived 20# from this software without specific prior written permission. 21# 22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33# 34 35SPDK_ROOT_DIR := $(abspath $(CURDIR)/..) 36include $(SPDK_ROOT_DIR)/mk/spdk.common.mk 37 38.PHONY: all clean install uninstall 39 40DPDK_OPTS = -Denable_docs=false 41DPDK_OPTS += -Dtests=false 42DPDK_CFLAGS = 43 44DPDK_KMODS = false 45ifeq ($(OS),FreeBSD) 46DPDK_KMODS = true 47endif 48DPDK_OPTS += -Denable_kmods=$(DPDK_KMODS) 49 50ifeq ($(CONFIG_DEBUG),y) 51DPDK_OPTS += --buildtype=debug 52endif 53 54# the drivers we use 55DPDK_DRIVERS = bus bus/pci bus/vdev mempool/ring 56 57# Core DPDK libs 58DPDK_LIBS = eal ring mempool pci 59DPDK_LIBS += kvargs telemetry 60# Governor required libs 61DPDK_LIBS += power timer ethdev net 62 63# common crypto/reduce drivers 64ifeq ($(findstring y,$(CONFIG_CRYPTO)$(CONFIG_REDUCE)),y) 65DPDK_DRIVERS += crypto/qat compress/qat common/qat 66endif 67 68ifeq ($(CONFIG_CRYPTO),y) 69DPDK_DRIVERS += crypto crypto/ipsec_mb 70# aesni_mb is name of the PMD in DPDK 21.08 and earlier 71DPDK_DRIVERS += crypto/aesni_mb 72DPDK_CFLAGS += -I$(IPSEC_MB_DIR) 73DPDK_LDFLAGS += -L$(IPSEC_MB_DIR) 74endif 75 76ifeq ($(CONFIG_REDUCE),y) 77DPDK_DRIVERS += compress compress/isal 78ifeq ($(CONFIG_REDUCE_MLX5),y) 79DPDK_DRIVERS += common/mlx5 compress/mlx5 bus/auxiliary 80endif 81DPDK_CFLAGS += -I$(ISAL_DIR) 82DPDK_LDFLAGS += -L$(ISAL_DIR)/.libs -lisal 83endif 84 85# crypto & compress deps 86DPDK_LIBS += reorder cryptodev 87DPDK_LIBS += compressdev 88DPDK_LIBS += security 89 90# vhost and deps 91DPDK_LIBS += cryptodev mbuf cmdline meter hash vhost 92 93# raid5 deps 94DPDK_LIBS += hash rcu 95 96DPDK_OPTS += -Dmachine=$(TARGET_ARCHITECTURE) 97 98ifneq ($(CONFIG_CROSS_PREFIX),) 99ifeq ($(findstring mingw,$(CONFIG_CROSS_PREFIX)),mingw) 100DPDK_OPTS += --cross-file $(SPDK_ROOT_DIR)/dpdk/config/x86/cross-mingw 101else 102$(error Automatic DPDK cross build is not supported. Please compile DPDK manually \ 103with e.g. `meson build --cross-file config/arm/arm64_armv8_linux_gcc`) 104endif 105endif 106 107DPDK_CFLAGS += -fPIC 108 109ifeq ($(CONFIG_WERROR),y) 110DPDK_CFLAGS += -Werror 111else 112DPDK_CFLAGS += -Wno-error 113endif 114 115ifeq ($(CONFIG_CET),y) 116DPDK_CFLAGS += -fcf-protection 117DPDK_LDFLAGS += -fcf-protection 118endif 119 120ifdef EXTRA_DPDK_CFLAGS 121$(warning EXTRA_DPDK_CFLAGS defined, possibly to work around an unsupported compiler version) 122$(shell sleep 1) 123endif 124 125# Allow users to specify EXTRA_DPDK_CFLAGS if they want to build DPDK using unsupported compiler versions 126DPDK_CFLAGS += $(EXTRA_DPDK_CFLAGS) 127 128ifeq ($(CC_TYPE),gcc) 129GCC_MAJOR = $(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1) 130ifeq ($(shell test $(GCC_MAJOR) -ge 10 && echo 1), 1) 131#1. gcc 10 complains on operations with zero size arrays in rte_cryptodev.c, so 132#disable this warning 133#2. gcc 10 disables fcommon by default and complains on multiple definition of 134#aesni_mb_logtype_driver symbol which is defined in header file and presented in several 135#translation units 136DPDK_CFLAGS += -Wno-stringop-overflow -fcommon 137endif 138endif 139 140# Force-disable scan-build 141SUB_CC = $(patsubst %ccc-analyzer,$(DEFAULT_CC),$(CC)) 142 143DPDK_ALL_LIB_DIRS = $(shell find $(SPDK_ROOT_DIR)/dpdk/lib -mindepth 1 -maxdepth 1 -type d) 144DPDK_ALL_LIBS = $(DPDK_ALL_LIB_DIRS:$(SPDK_ROOT_DIR)/dpdk/lib/%=%) 145DPDK_DISABLED_LIBS = $(filter-out $(DPDK_LIBS),$(DPDK_ALL_LIBS)) 146 147ifneq ($(OS),FreeBSD) 148SED_INPLACE_FLAG = "-i" 149MESON_PREFIX = $(SPDK_ROOT_DIR)/dpdk/build 150else 151SED_INPLACE_FLAG = "-i ''" 152MESON_PREFIX = "/" 153endif 154 155# Some ninja versions come with a (broken?) jobserver which defaults to use 156# only 1 thread for the build. We workaround this by specifying -j to ninja 157# with the same value as top-makefile. This is OK as long as DPDK is not built 158# in parallel with anything else, which is the case for now. 159ifeq ($(MAKE_PID),) 160MAKE_PID := $(shell echo $$PPID) 161endif 162 163MAKE_NUMJOBS := $(shell ps T | sed -nE 's/[[:space:]]*$(MAKE_PID)[[:space:]].* (-j|--jobs=)( *[0-9]+).*/\1\2/p') 164 165all: $(SPDK_ROOT_DIR)/dpdk/build-tmp 166 $(Q)# DPDK doesn't handle nested make calls, so unset MAKEFLAGS 167 $(Q)env -u MAKEFLAGS ninja -C $(SPDK_ROOT_DIR)/dpdk/build-tmp $(MAKE_NUMJOBS) 168 $(Q) \ 169 # Meson on FreeBSD sometimes appends --prefix value to the default DESTDIR (which is e.g. \ 170 # /usr/local) instead of replacing it. --prefix needs to be an absolute path, so we set \ 171 # it to / and then set DESTDIR directly, so libs and headers are copied to "DESTDIR//". \ 172 # DPDK kernel modules are set to install in $DESTDIR/boot/modules, but we move them \ 173 # to DESTDIR/kmod to be consistent with the makefile build. \ 174 # \ 175 # Also use meson install --only-changed instead of ninja install so that the shared \ 176 # libraries don't get reinstalled when they haven't been rebuilt - this avoids all of \ 177 # our applications getting relinked even when nothing has changed. 178 $(Q)if [ "$(OS)" = "FreeBSD" ]; then \ 179 env -u MAKEFLAGS DESTDIR=$(SPDK_ROOT_DIR)/dpdk/build ninja -C $(SPDK_ROOT_DIR)/dpdk/build-tmp $(MAKE_NUMJOBS) install > /dev/null && \ 180 mv $(SPDK_ROOT_DIR)/dpdk/build/boot/modules $(SPDK_ROOT_DIR)/dpdk/build/kmod; \ 181 else \ 182 env -u MAKEFLAGS meson install -C $(SPDK_ROOT_DIR)/dpdk/build-tmp --only-changed > /dev/null; \ 183 fi 184 185$(SPDK_ROOT_DIR)/dpdk/build-tmp: $(SPDK_ROOT_DIR)/mk/cc.mk $(SPDK_ROOT_DIR)/include/spdk/config.h 186 $(Q)rm -rf $(SPDK_ROOT_DIR)/dpdk/build $(SPDK_ROOT_DIR)/dpdk/build-tmp 187 $(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")" build-tmp 188 $(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 189 $(Q) \ 190 # TODO Meson build adds libbsd dependency when it's available. This means any app will be \ 191 # forced to link with -lbsd, but only if it's available on the system. The clean way to \ 192 # handle this would be to rely on DPDK's pkg-config file which will contain the -lbsd when \ 193 # required. For now just remove the libbsd dependency. DPDK will fallback to its internal \ 194 # functions. 195 $(Q)sed $(SED_INPLACE_FLAG) 's/#define RTE_USE_LIBBSD .*//g' $(SPDK_ROOT_DIR)/dpdk/build-tmp/rte_build_config.h 196 197clean: 198 $(Q)rm -rf $(SPDK_ROOT_DIR)/dpdk/build $(SPDK_ROOT_DIR)/dpdk/build-tmp 199 200install: 201 @: 202 203uninstall: 204 @: 205