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