Commit 79f9a7f5 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

build: generate pkg-config files for SPDK



Users can now generate the necessary linker args for their
own applications using something like:

PKG_CONFIG_PATH=build/lib/pkgconfig pkg-config --libs spdk_nvme

Dependencies between libraries are included in the generated
.pc files, so the user only needs to pass the top-level subsystems
or individual SPDK libraries they are using in their application.

Modules will automatically be added to the output if the associated
library is specified.  For example, specifying "spdk_bdev" will include
the libraries not only for spdk_bdev, but also all of the bdev modules.

Users still need to supply the -Wl,--no-as-needed or -Wl,--whole-archive
flags. They cannot be added to the .pc files without increasing the length
of the argument string by a factor of 15x to 20x.

Modify the test/external_code/hello_world Makefile to use pkg-config to
ensure this gets tested at some level in our autotest environment.

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: Ie48a75f11969d5d775d514cf10bcb82d197eabfd
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4371


Community-CI: Broadcom CI
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent 3ff9c136
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -83,6 +83,11 @@ parameter is added into `spdk_app_opts_init` function.
Change the return type of function `spdk_nbd_stop` from void to int. And update the
`spdk_nbd_fini` with two parameters to make its behavior from sync to async.

### build

SPDK now generates pkg-config files to simplify the process of determining which
libraries must be linked into an SPDK application.

### nvmf

nvmf_fc_lld_fini() now takes callback and hence updating FC Broadcom LLD driver
+2 −1
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ clean: $(DIRS-y)
	$(Q)rm -rf build/fio
	$(Q)rm -rf build/examples
	$(Q)rm -rf build/include
	$(Q)rm -rf build/lib/pkgconfig
	$(Q)find build/lib ! -name .gitignore -type f -delete

install: all
@@ -119,7 +120,7 @@ mk/cc.mk:
	false

build_dir: mk/cc.mk
	$(Q)mkdir -p build/lib
	$(Q)mkdir -p build/lib/pkgconfig
	$(Q)mkdir -p build/bin
	$(Q)mkdir -p build/fio
	$(Q)mkdir -p build/examples
+1 −0
Original line number Diff line number Diff line
@@ -833,6 +833,7 @@ INPUT += \
                         nvmf_tracing.md \
                         overview.md \
                         peer_2_peer.md \
                         pkgconfig.md \
                         porting.md \
                         shfmt.md \
                         spdkcli.md \

doc/pkgconfig.md

0 → 100644
+55 −0
Original line number Diff line number Diff line
# Linking SPDK applications with pkg-config {#pkgconfig}

The SPDK build system generates pkg-config files to facilitate linking
applications with the correct set of SPDK and DPDK libraries. Using pkg-config
in your build system will ensure you do not need to make modifications
when SPDK adds or modifies library dependencies.

If your application is using the SPDK nvme library, you would use the following
to get the list of required SPDK libraries:

~~~
PKG_CONFIG_PATH=/path/to/spdk/build/lib/pkgconfig pkg-config --libs spdk_nvme
~~~

To get the list of required SPDK and DPDK libraries to use the DPDK-based
environment layer:

~~~
PKG_CONFIG_PATH=/path/to/spdk/build/lib/pkgconfig pkg-config --libs spdk_env_dpdk
~~~

When linking with static libraries, the dependent system libraries must also be
specified. To get the list of required system libraries:

~~~
PKG_CONFIG_PATH=/path/to/spdk/build/lib/pkgconfig pkg-config --libs spdk_syslibs
~~~

Note that SPDK libraries use constructor functions liberally, so you must surround
the library list with extra linker options to ensure these functions are not dropped
from the resulting application binary.  Here is an example Makefile snippet that
shows how to use pkg-config to link an application that uses the SPDK nvme shared
library:

~~~
PKG_CONFIG_PATH = $(SPDK_DIR)/build/lib/pkgconfig
SPDK_LIB := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --libs spdk_nvme
DPDK_LIB := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --libs spdk_env_dpdk

app:
	$(CC) -o app app.o -pthread -Wl,--no-as-needed $(SPDK_LIB) $(DPDK_LIB) -Wl,--as-needed
~~~

If using the SPDK nvme static library:

~~~
PKG_CONFIG_PATH = $(SPDK_DIR)/build/lib/pkgconfig
SPDK_LIB := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --libs spdk_nvme
DPDK_LIB := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --libs spdk_env_dpdk
SYS_LIB := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --libs --static spdk_syslibs

app:
	$(CC) -o app app.o -pthread -Wl,--whole-archive $(SPDK_LIB) $(DPDK_LIB) -Wl,--no-whole-archive \
		$(SYS_LIB)
~~~
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

- @subpage system_configuration
- @subpage libraries
- @subpage pkgconfig
- @subpage app_overview
- @subpage iscsi
- @subpage nvmf
Loading