DPDK patches and discussions
 help / color / mirror / Atom feed
From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: Matan Azrad <matan@mellanox.com>,
	Shahaf Shuler <shahafs@mellanox.com>,
	Viacheslav Ovsiienko <viacheslavo@mellanox.com>
Subject: [dpdk-dev] [PATCH 1/3] buildtools: rework static pkg-config script
Date: Thu, 16 Jan 2020 08:16:54 +0100	[thread overview]
Message-ID: <20200116071656.1663967-2-thomas@monjalon.net> (raw)
In-Reply-To: <20200116071656.1663967-1-thomas@monjalon.net>

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

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
-- 
2.24.1


  reply	other threads:[~2020-01-16  7:17 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-16  7:16 [dpdk-dev] [PATCH 0/3] add static ibverbs in meson Thomas Monjalon
2020-01-16  7:16 ` Thomas Monjalon [this message]
2020-01-16  7:16 ` [dpdk-dev] [PATCH 2/3] build: allow to hide dependencies from pkg-config Thomas Monjalon
2020-01-17 17:34   ` Bruce Richardson
2020-01-16  7:16 ` [dpdk-dev] [PATCH 3/3] net/mlx: support static ibverbs linkage with meson Thomas Monjalon
2020-01-27 15:43 ` [dpdk-dev] [PATCH v2 0/4] add static ibverbs in meson Thomas Monjalon
2020-01-27 15:43   ` [dpdk-dev] [PATCH v2 1/4] net/mlx: add static ibverbs linkage with meson Thomas Monjalon
2020-01-27 15:44   ` [dpdk-dev] [PATCH v2 2/4] buildtools: get static mlx dependencies for meson Thomas Monjalon
2020-01-29 15:37     ` Bruce Richardson
2020-01-29 17:48       ` Thomas Monjalon
2020-01-29 17:50         ` Bruce Richardson
2020-01-29 18:49           ` Thomas Monjalon
2020-01-29 17:48       ` Bruce Richardson
2020-01-27 15:44   ` [dpdk-dev] [PATCH v2 3/4] build: allow hiding dependencies from pkg-config Thomas Monjalon
2020-01-27 15:44   ` [dpdk-dev] [PATCH v2 4/4] net/mlx: workaround static linkage with meson Thomas Monjalon
2020-02-04 11:48   ` [dpdk-dev] [PATCH v2 0/4] add static ibverbs in meson Bruce Richardson
2020-02-04 14:27     ` Thomas Monjalon
2020-02-04 14:33       ` Bruce Richardson
2020-02-04 15:14         ` Thomas Monjalon
2020-02-04 15:20           ` Bruce Richardson
2020-02-11  1:19   ` [dpdk-dev] [PATCH v3 0/5] mlx ibverbs linking " Thomas Monjalon
2020-02-11  1:19     ` [dpdk-dev] [PATCH v3 1/5] net/mlx: add static ibverbs linkage with meson Thomas Monjalon
2020-02-11  1:19     ` [dpdk-dev] [PATCH v3 2/5] buildtools: get static mlx dependencies for meson Thomas Monjalon
2020-02-11  1:19     ` [dpdk-dev] [PATCH v3 3/5] net/mlx: workaround static linkage with meson Thomas Monjalon
2020-02-11 11:29       ` Bruce Richardson
2020-02-11 11:36         ` Thomas Monjalon
2020-02-11 11:43           ` Bruce Richardson
2020-02-11  1:19     ` [dpdk-dev] [PATCH v3 4/5] net/mlx: rename meson variable for dlopen option Thomas Monjalon
2020-02-11  1:19     ` [dpdk-dev] [PATCH v3 5/5] net/mlx: fix overlinking with meson and glue dlopen Thomas Monjalon
2020-02-11 11:32       ` Bruce Richardson
2020-02-11 11:34         ` Thomas Monjalon
2020-02-11 11:33     ` [dpdk-dev] [PATCH v3 0/5] mlx ibverbs linking in meson Bruce Richardson
2020-02-12  1:59 ` [dpdk-dev] [PATCH v4 0/6] " Thomas Monjalon
2020-02-12  1:59   ` [dpdk-dev] [PATCH v4 1/6] drivers: cleanup meson build variable Thomas Monjalon
2020-02-12  9:26     ` Xu, Rosen
2020-02-12  9:32       ` Thomas Monjalon
2020-02-12 15:04         ` [dpdk-dev] [dpdklab] " Jeremy Plsek
2020-02-12 15:18           ` Jeremy Plsek
2020-02-12 16:30             ` Thomas Monjalon
2020-02-12 16:36               ` Jeremy Plsek
2020-02-12 16:42                 ` Thomas Monjalon
2020-02-12 16:46                   ` Jeremy Plsek
2020-02-12 17:38                     ` Thomas Monjalon
2020-02-12 18:03                       ` Jeremy Plsek
2020-02-12  1:59   ` [dpdk-dev] [PATCH v4 2/6] net/mlx: add static ibverbs linkage with meson Thomas Monjalon
2020-02-12  1:59   ` [dpdk-dev] [PATCH v4 3/6] buildtools: get static mlx dependencies for meson Thomas Monjalon
2020-02-12  1:59   ` [dpdk-dev] [PATCH v4 4/6] net/mlx: workaround static linkage with meson Thomas Monjalon
2020-02-12  1:59   ` [dpdk-dev] [PATCH v4 5/6] net/mlx: rename meson variable for dlopen option Thomas Monjalon
2020-02-12  1:59   ` [dpdk-dev] [PATCH v4 6/6] net/mlx: fix overlinking with meson and glue dlopen Thomas Monjalon
2020-02-12  2:08   ` [dpdk-dev] [PATCH v4 0/6] mlx ibverbs linking in meson Thomas Monjalon
2020-02-12 22:07 ` [dpdk-dev] [PATCH v5 " Thomas Monjalon
2020-02-12 22:07   ` [dpdk-dev] [PATCH v5 1/6] drivers: cleanup meson build variable Thomas Monjalon
2020-02-13  0:25     ` Xu, Rosen
2020-02-12 22:07   ` [dpdk-dev] [PATCH v5 2/6] net/mlx: add static ibverbs linkage with meson Thomas Monjalon
2020-02-12 22:07   ` [dpdk-dev] [PATCH v5 3/6] buildtools: get static mlx dependencies for meson Thomas Monjalon
2020-02-12 22:07   ` [dpdk-dev] [PATCH v5 4/6] net/mlx: workaround static linkage with meson Thomas Monjalon
2020-02-12 22:07   ` [dpdk-dev] [PATCH v5 5/6] net/mlx: rename meson variable for dlopen option Thomas Monjalon
2020-02-12 22:07   ` [dpdk-dev] [PATCH v5 6/6] net/mlx: fix overlinking with meson and glue dlopen Thomas Monjalon
2020-02-13 13:57   ` [dpdk-dev] [PATCH v5 0/6] mlx ibverbs linking in meson Raslan Darawsheh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200116071656.1663967-2-thomas@monjalon.net \
    --to=thomas@monjalon.net \
    --cc=dev@dpdk.org \
    --cc=matan@mellanox.com \
    --cc=shahafs@mellanox.com \
    --cc=viacheslavo@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).