From 6f46e272c3c0be23a0ccfd440e3970b5933fba48 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 11 Jun 2018 12:40:29 -0700 Subject: [PATCH] build: add combined shared library (libspdk.so) Change-Id: If48df087c145a3fd278c0ae04558d8352b01cc1a Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/414687 Reviewed-by: Jim Harris Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto Tested-by: SPDK Automated Test System --- CHANGELOG.md | 9 ++++ Makefile | 3 +- dpdkbuild/Makefile | 2 - mk/spdk.common.mk | 6 +++ shared_lib/Makefile | 106 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 shared_lib/Makefile diff --git a/CHANGELOG.md b/CHANGELOG.md index 2770a8f75e..ccc86ab709 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ ## v18.07: (Upcoming Release) +### Build System + +The build system now generates a combined shared library (libspdk.so) that may be used +in place of the individual static libraries (libspdk_*.a). +The combined library includes all components of SPDK and is intended to make linking +against SPDK easier. +The static libraries are also still provided for users that prefer to link only the +minimal set of components required. + ### RPC The `start_nbd_disk` RPC method now returns the path to the kernel NBD device node diff --git a/Makefile b/Makefile index 25b1fbab85..cb0585afb4 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ S := SPDK_ROOT_DIR := $(CURDIR) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -DIRS-y += lib examples app include +DIRS-y += lib shared_lib examples app include DIRS-$(CONFIG_TESTS) += test .PHONY: all clean $(DIRS-y) config.h CONFIG.local mk/cc.mk cc_version cxx_version @@ -56,6 +56,7 @@ clean: $(DIRS-y) install: all $(Q)echo "Installed to $(DESTDIR)$(CONFIG_PREFIX)" +shared_lib: lib lib: $(DPDKBUILD) app: lib test: lib diff --git a/dpdkbuild/Makefile b/dpdkbuild/Makefile index cc611156bf..21a37474e5 100644 --- a/dpdkbuild/Makefile +++ b/dpdkbuild/Makefile @@ -58,9 +58,7 @@ else DPDK_CONFIG := $(DPDK_CONFIG)-gcc endif -ifeq ($(CONFIG_FIO_PLUGIN),y) DPDK_CFLAGS = -fPIC -endif ifeq ($(CONFIG_DEBUG),y) DPDK_CFLAGS += -O0 -g diff --git a/mk/spdk.common.mk b/mk/spdk.common.mk index da2070e10c..28bec9d6cd 100644 --- a/mk/spdk.common.mk +++ b/mk/spdk.common.mk @@ -238,6 +238,12 @@ INSTALL_LIB=\ install -d -m 755 "$(DESTDIR)$(libdir)"; \ install -m 644 "$(LIB)" "$(DESTDIR)$(libdir)/" +# Install a shared library +INSTALL_SHARED_LIB=\ + $(Q)echo " INSTALL $(DESTDIR)$(libdir)/$(notdir $(SHARED_LIB))"; \ + install -d -m 755 "$(DESTDIR)$(libdir)"; \ + install -m 644 "$(SHARED_LIB)" "$(DESTDIR)$(libdir)/" + # Install an app binary INSTALL_APP=\ $(Q)echo " INSTALL $(DESTDIR)$(bindir)/$(APP)"; \ diff --git a/shared_lib/Makefile b/shared_lib/Makefile new file mode 100644 index 0000000000..5819af1494 --- /dev/null +++ b/shared_lib/Makefile @@ -0,0 +1,106 @@ +# +# BSD LICENSE +# +# Copyright (c) Intel Corporation. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +SPDK_ROOT_DIR := $(abspath $(CURDIR)/..) +include $(SPDK_ROOT_DIR)/mk/spdk.common.mk +include $(SPDK_ROOT_DIR)/mk/spdk.app.mk +include $(SPDK_ROOT_DIR)/mk/spdk.modules.mk + +# Build combined libspdk.so shared library +SHARED_LIB = $(SPDK_ROOT_DIR)/build/lib/libspdk.so + +SPDK_LIB_LIST += app_rpc +SPDK_LIB_LIST += bdev +SPDK_LIB_LIST += bdev_rpc +SPDK_LIB_LIST += blobfs +SPDK_LIB_LIST += conf +SPDK_LIB_LIST += copy +SPDK_LIB_LIST += event +SPDK_LIB_LIST += event_bdev +SPDK_LIB_LIST += event_copy +SPDK_LIB_LIST += event_iscsi +SPDK_LIB_LIST += event_net +SPDK_LIB_LIST += event_nvmf +SPDK_LIB_LIST += event_scsi +SPDK_LIB_LIST += iscsi +SPDK_LIB_LIST += json +SPDK_LIB_LIST += jsonrpc +SPDK_LIB_LIST += log +SPDK_LIB_LIST += log_rpc +SPDK_LIB_LIST += nvmf +SPDK_LIB_LIST += rpc +SPDK_LIB_LIST += scsi +SPDK_LIB_LIST += trace +SPDK_LIB_LIST += util + +ifeq ($(OS),Linux) +SPDK_LIB_LIST += event_nbd +SPDK_LIB_LIST += nbd + +ifeq ($(CONFIG_VHOST),y) +SPDK_LIB_LIST += event_vhost +SPDK_LIB_LIST += rte_vhost +SPDK_LIB_LIST += vhost +endif + +endif + +LIBS += $(BLOCKDEV_MODULES_LINKER_ARGS) +LIBS += $(COPY_MODULES_LINKER_ARGS) +LIBS += $(NET_MODULES_LINKER_ARGS) +LIBS += $(SPDK_LIB_LINKER_ARGS) +LIBS += $(ENV_LINKER_ARGS) + +comma := , + +$(SHARED_LIB): $(SPDK_LIB_FILES) $(SPDK_WHOLE_LIBS) $(BLOCKDEV_MODULES_FILES) $(COPY_MODULES_FILES) $(NET_MODULES_FILES) $(LINKER_MODULES) $(ENV_LIBS) $(MAKEFILE_LIST) + $(Q)echo " SO $(notdir $@)"; \ + rm -f $@; \ + $(CC) -o $@ -shared $(CPPFLAGS) $(LDFLAGS) \ + -Wl,--whole-archive \ + $(filter-out -Wl$(comma)--no-whole-archive,$(LIBS)) \ + -Wl,--no-whole-archive \ + -lcrypto \ + $(SYS_LIBS) + +.PHONY: all clean $(DIRS-y) + +all: $(SHARED_LIB) + +clean: + $(CLEAN_C) $(SHARED_LIB) + +install: + $(INSTALL_SHARED_LIB) + +include $(SPDK_ROOT_DIR)/mk/spdk.subdirs.mk