[1/3] buildtools: rework static pkg-config script
diff mbox series

Message ID 20200116071656.1663967-2-thomas@monjalon.net
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series
  • add static ibverbs in meson
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-nxp-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/checkpatch success coding style OK

Commit Message

Thomas Monjalon Jan. 16, 2020, 7:16 a.m. UTC
The shell script options-ibverbs-static.sh was used with make
in forcing static linkage of ibverbs dependency.
It is now renamed pkg-config-static.sh and it is made generic,
i.e. it can work with any .pc library file.

The idea is to distinguish its own libraries and the dependencies
by looking at the -L directory.
Only the found static libraries are forced to static.

The -L path is added in this new version in order to fill
the .pc file generated in DPDK.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 buildtools/options-ibverbs-static.sh | 14 -------------
 buildtools/pkg-config-static.sh      | 31 ++++++++++++++++++++++++++++
 drivers/net/mlx4/Makefile            |  2 +-
 drivers/net/mlx5/Makefile            |  2 +-
 mk/rte.app.mk                        |  3 ++-
 5 files changed, 35 insertions(+), 17 deletions(-)
 delete mode 100755 buildtools/options-ibverbs-static.sh
 create mode 100755 buildtools/pkg-config-static.sh

Patch
diff mbox series

diff --git a/buildtools/options-ibverbs-static.sh b/buildtools/options-ibverbs-static.sh
deleted file mode 100755
index 0f285a343b..0000000000
--- a/buildtools/options-ibverbs-static.sh
+++ /dev/null
@@ -1,14 +0,0 @@ 
-#! /bin/sh
-# SPDX-License-Identifier: BSD-3-Clause
-#
-# Print link options -l for static link of ibverbs.
-#
-# Static flavour of ibverbs and the providers libs are explicitly picked,
-# thanks to the syntax -l:libfoo.a
-# Other libs (pthread and nl) are unchanged, i.e. linked dynamically by default.
-#
-# PKG_CONFIG_PATH may be required to be set if libibverbs.pc is not installed.
-
-pkg-config --libs-only-l --static libibverbs |
-	tr '[:space:]' '\n' |
-	sed -r '/^-l(pthread|nl)/! s,(^-l)(.*),\1:lib\2.a,'
diff --git a/buildtools/pkg-config-static.sh b/buildtools/pkg-config-static.sh
new file mode 100755
index 0000000000..77401c2f45
--- /dev/null
+++ b/buildtools/pkg-config-static.sh
@@ -0,0 +1,31 @@ 
+#! /bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2020 Mellanox Technologies, Ltd
+#
+# Convert pkg-config link options for static linkage.
+#
+# Static flavour of provided libs are explicitly picked,
+# thanks to the syntax -l:libfoo.a
+# Other libs (dependencies) are unchanged, i.e. linked dynamically by default.
+#
+# Syntax: pkg-config-static.sh <libname>
+#
+# PKG_CONFIG_PATH may be required to be set if the .pc file is not installed.
+
+ldflags=$(pkg-config --libs --static $1 | tr '[:space:]' '\n')
+dir=$(echo "$ldflags" | sed -rn 's,^-L(.*),\1,p' | head -n1)
+IFS='
+'
+for arg in $ldflags ; do
+	prefix=$(echo $arg | sed -rn 's/^(-Wl,).*/\1/p')
+	option=$(echo $arg | sed -rn "s/^$prefix-(.*=|.*,|.).*/\1/p")
+	[ "$option" = 'l' -o "$option" = 'L' ] || continue
+	value=$(echo $arg | sed "s/^$prefix-$option//")
+	staticlib="lib$value.a"
+	printf -- -$option
+	if [ -f $dir/$staticlib ] ; then
+		echo :$staticlib
+	else
+		echo $value
+	fi
+done | tr '\n' ' '
diff --git a/drivers/net/mlx4/Makefile b/drivers/net/mlx4/Makefile
index 329569dc10..4ef14b3a07 100644
--- a/drivers/net/mlx4/Makefile
+++ b/drivers/net/mlx4/Makefile
@@ -45,7 +45,7 @@  CFLAGS += -DMLX4_GLUE_VERSION='"$(LIB_GLUE_VERSION)"'
 CFLAGS_mlx4_glue.o += -fPIC
 LDLIBS += -ldl
 else ifeq ($(CONFIG_RTE_IBVERBS_LINK_STATIC),y)
-LDLIBS += $(shell $(RTE_SDK)/buildtools/options-ibverbs-static.sh)
+LDLIBS += $(shell $(RTE_SDK)/buildtools/pkg-config-static.sh libibverbs)
 else
 LDLIBS += -libverbs -lmlx4
 endif
diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile
index c5cf4397ac..eb11123867 100644
--- a/drivers/net/mlx5/Makefile
+++ b/drivers/net/mlx5/Makefile
@@ -60,7 +60,7 @@  CFLAGS += -DMLX5_GLUE_VERSION='"$(LIB_GLUE_VERSION)"'
 CFLAGS_mlx5_glue.o += -fPIC
 LDLIBS += -ldl
 else ifeq ($(CONFIG_RTE_IBVERBS_LINK_STATIC),y)
-LDLIBS += $(shell $(RTE_SDK)/buildtools/options-ibverbs-static.sh)
+LDLIBS += $(shell $(RTE_SDK)/buildtools/pkg-config-static.sh libibverbs)
 else
 LDLIBS += -libverbs -lmlx5
 endif
diff --git a/mk/rte.app.mk b/mk/rte.app.mk
index 05ea034b99..1062fcc732 100644
--- a/mk/rte.app.mk
+++ b/mk/rte.app.mk
@@ -195,7 +195,8 @@  ifeq ($(CONFIG_RTE_IBVERBS_LINK_DLOPEN),y)
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD)       += -ldl
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX5_PMD)       += -ldl
 else ifeq ($(CONFIG_RTE_IBVERBS_LINK_STATIC),y)
-LIBS_IBVERBS_STATIC = $(shell $(RTE_SDK)/buildtools/options-ibverbs-static.sh)
+LIBS_IBVERBS_STATIC = $(shell $(RTE_SDK)/buildtools/pkg-config-static.sh \
+		libibverbs | sed 's/-Wl,//')
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD)       += $(LIBS_IBVERBS_STATIC)
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX5_PMD)       += $(LIBS_IBVERBS_STATIC)
 else