[1/3] buildtools: rework static pkg-config script
Checks
Commit Message
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
deleted file mode 100755
@@ -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,'
new file mode 100755
@@ -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' ' '
@@ -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
@@ -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
@@ -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