Skip to content

Commit

Permalink
shared_lib: Update shared lib build and install
Browse files Browse the repository at this point in the history
Updates build and install of shared lib to conform with
standard naming conventions for shared libraries, including
the setting of the lib's soname.

Change-Id: Ib46d298ab5f77fd8c32b7c04022b546446189428
Signed-off-by: Lance Hartmann <[email protected]>
Reviewed-on: https://review.gerrithub.io/421936
Tested-by: SPDK CI Jenkins <[email protected]>
Chandler-Test-Pool: SPDK Automated Test System <[email protected]>
Reviewed-by: Ben Walker <[email protected]>
Reviewed-by: Jim Harris <[email protected]>
  • Loading branch information
lhoswdev authored and jimharris committed Aug 16, 2018
1 parent aec9c3c commit 3f6f569
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*.o
*.pyc
*.so
*.so.*
*.swp
*.DS_Store
ut_coverage/
Expand Down
45 changes: 40 additions & 5 deletions mk/spdk.common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,25 @@ LINK_CXX=\
$(Q)echo " LINK $S/$@"; \
$(CXX) -o $@ $(CPPFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) $(SYS_LIBS)

#
# Variables to use for versioning shared libs
#
SO_VER := 1
SO_MINOR := 0
SO_SUFFIX_ALL := $(SO_VER).$(SO_MINOR)

# Provide function to ease build of a shared lib
define spdk_build_realname_shared_lib
$(CC) -o $@ -shared $(CPPFLAGS) $(LDFLAGS) \
-Wl,--soname,$(patsubst %.so.$(SO_SUFFIX_ALL),%.so.$(SO_VER),$(notdir $@)) \
-Wl,--whole-archive $(1) -Wl,--no-whole-archive \
-Wl,--version-script=$(2) \
$(3)
endef

BUILD_LINKERNAME_LIB=\
ln -sf $(notdir $<) $@

# Archive $(OBJS) into $@ (.a)
LIB_C=\
$(Q)echo " LIB $(notdir $@)"; \
Expand All @@ -243,11 +262,27 @@ 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)/"
ifeq ($(OS),FreeBSD)
INSTALL_REL_SYMLINK := install -l rs
else
INSTALL_REL_SYMLINK := ln -sf -r
endif

define spdk_install_lib_symlink
$(INSTALL_REL_SYMLINK) $(DESTDIR)$(libdir)/$(1).$(SO_SUFFIX_ALL) $(DESTDIR)$(libdir)/$(1)
endef

# Install shared library(s)
define spdk_install_shared_libs
$(Q)echo " INSTALL $(DESTDIR)$(libdir)/$(notdir $(1))"
install -d -m 755 $(DESTDIR)$(libdir)
@for l in $(1); do \
bln=$${l##*/}; \
rn=$$l.$(SO_SUFFIX_ALL); \
install -m 755 $$rn $(DESTDIR)$(libdir)/; \
$(call spdk_install_lib_symlink,$$bln); \
done
endef

# Install an app binary
INSTALL_APP=\
Expand Down
21 changes: 10 additions & 11 deletions shared_lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ 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
COMBINED_LINKERNAME_LIB = $(SPDK_ROOT_DIR)/build/lib/libspdk.so
COMBINED_SHARED_LIB = $(COMBINED_LINKERNAME_LIB).$(SO_SUFFIX_ALL)

SPDK_LIB_LIST += app_rpc
SPDK_LIB_LIST += bdev
Expand Down Expand Up @@ -85,24 +86,22 @@ LIBS += $(ENV_LINKER_ARGS)

comma := ,

$(SHARED_LIB): $(SPDK_LIB_FILES) $(SPDK_WHOLE_LIBS) $(BLOCKDEV_MODULES_FILES) $(COPY_MODULES_FILES) $(SOCK_MODULES_FILES) $(LINKER_MODULES) $(ENV_LIBS) $(MAKEFILE_LIST) spdk.map
$(COMBINED_SHARED_LIB): $(SPDK_LIB_FILES) $(SPDK_WHOLE_LIBS) $(BLOCKDEV_MODULES_FILES) $(COPY_MODULES_FILES) $(SOCK_MODULES_FILES) $(LINKER_MODULES) $(ENV_LIBS) $(MAKEFILE_LIST) spdk.map
$(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 \
-Wl,--version-script=spdk.map \
$(SYS_LIBS)
$(call spdk_build_realname_shared_lib,$(filter-out -Wl$(comma)--no-whole-archive,$(LIBS)),spdk.map,$(SYS_LIBS))

$(COMBINED_LINKERNAME_LIB) : %.so : %.so.$(SO_SUFFIX_ALL)
$(BUILD_LINKERNAME_LIB)

.PHONY: all clean $(DIRS-y)

all: $(SHARED_LIB)
all: $(COMBINED_SHARED_LIB) $(COMBINED_LINKERNAME_LIB)

clean:
$(CLEAN_C) $(SHARED_LIB)
$(CLEAN_C) $(COMBINED_SHARED_LIB) $(COMBINED_LINKERNAME_LIB)

install:
$(INSTALL_SHARED_LIB)
$(call spdk_install_shared_libs, $(COMBINED_LINKERNAME_LIB))

include $(SPDK_ROOT_DIR)/mk/spdk.subdirs.mk

0 comments on commit 3f6f569

Please sign in to comment.