From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id A5B79A04E7;
	Mon,  2 Nov 2020 07:46:14 +0100 (CET)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 87F726889;
	Mon,  2 Nov 2020 07:46:13 +0100 (CET)
Received: from hqnvemgate26.nvidia.com (hqnvemgate26.nvidia.com
 [216.228.121.65]) by dpdk.org (Postfix) with ESMTP id 7EB0A5AB9
 for <dev@dpdk.org>; Mon,  2 Nov 2020 07:46:11 +0100 (CET)
Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by
 hqnvemgate26.nvidia.com (using TLS: TLSv1.2, AES256-SHA)
 id <B5f9fab3c0000>; Sun, 01 Nov 2020 22:46:20 -0800
Received: from nvidia.com (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13)
 with Microsoft SMTP Server (TLS) id 15.0.1473.3;
 Mon, 2 Nov 2020 06:46:03 +0000
From: Gregory Etelson <getelson@nvidia.com>
To: <dev@dpdk.org>
CC: <getelson@nvidia.com>, <matan@nvidia.com>, <rasland@nvidia.com>,
 <thomas@monjalon.net>, <bluca@debian.org>, <david.marchand@redhat.com>,
 <christian.ehrhardt@canonical.com>, <ktraynor@redhat.com>, Bruce Richardson
 <bruce.richardson@intel.com>
Date: Mon, 2 Nov 2020 08:45:48 +0200
Message-ID: <20201102064548.9291-1-getelson@nvidia.com>
X-Mailer: git-send-email 2.28.0
In-Reply-To: <20201029091638.26646-1-getelson@nvidia.com>
References: <20201029091638.26646-1-getelson@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Originating-IP: [10.124.1.5]
X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To
 HQMAIL107.nvidia.com (172.20.187.13)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1;
 t=1604299580; bh=iCa65TBiGSFQ06TH0LvJOIYR9Hf8dZWY8jmYQUUqOPg=;
 h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
 References:MIME-Version:Content-Type:Content-Transfer-Encoding:
 X-Originating-IP:X-ClientProxiedBy;
 b=SZhG2JIgKgsphwjhDVV68T4StEjpnKKrVeqiBbvRLrjmN1ll6SQAzXYeV3t1jXBh4
 8HQTdnGeGmTfF6W1REGTnjblGIZDHI13kJKQTgJ8UdQuCXeC3N1ljPRYlFscW8Dr4y
 4r4jrqW+dMzF1NdjUsHx438CocpZXMcDgKaFwGI0hJBIpGC9KSDoETQuEicvWZcR94
 sSy9yn/p8ZKVC+lI3+qxyagDSVptLmPcWPW01zJPJchv/bjB4UO+JgQ67PROc40FrX
 pTTzGCOkG/eJ3LsCThv6UwdwggUKQZMDBxlMAO3zwNA/Fp6mFEFZ33Bu9Wv0ZvjqRs
 ZFOclsuAbnATg==
Subject: [dpdk-dev] [PATCH v2] build: add pkg-config validation
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

DPDK relies on pkg-config(1) to provide correct parameters for
compiler and linker used in application build.
Inaccurate build parameters, produced by pkg-config from DPDK .pc
files could fail application build or cause unpredicted results
during application runtime.

This patch validates host pkg-config utility and notifies about
known issues.

Signed-off-by: Gregory Etelson <getelson@nvidia.com>
---
 buildtools/pkg-config/meson.build           | 11 ++++++
 buildtools/pkg-config/pkgconfig-validate.sh | 40 +++++++++++++++++++++
 doc/guides/linux_gsg/sys_reqs.rst           |  5 +++
 3 files changed, 56 insertions(+)
 create mode 100755 buildtools/pkg-config/pkgconfig-validate.sh

diff --git a/buildtools/pkg-config/meson.build b/buildtools/pkg-config/meso=
n.build
index 5f19304289..4f907d7638 100644
--- a/buildtools/pkg-config/meson.build
+++ b/buildtools/pkg-config/meson.build
@@ -53,3 +53,14 @@ This is required for a number of static inline functions=
 in the public headers.'
 # For static linking with dependencies as shared libraries,
 # the internal static libraries must be flagged explicitly.
 run_command(py3, 'set-static-linker-flags.py', check: true)
+
+pkgconf =3D find_program('pkg-config', 'pkgconf', required: false)
+if (pkgconf.found())
+	cmd =3D run_command('./pkgconfig-validate.sh', pkgconf.path(),
+			   check:false)
+	if cmd.returncode() !=3D 0
+		version =3D run_command(pkgconf, '--version')
+		warning('invalid pkg-config version @0@'.format(
+			version.stdout().strip()))
+	endif
+endif
diff --git a/buildtools/pkg-config/pkgconfig-validate.sh b/buildtools/pkg-c=
onfig/pkgconfig-validate.sh
new file mode 100755
index 0000000000..61ddd6d5a3
--- /dev/null
+++ b/buildtools/pkg-config/pkgconfig-validate.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+
+# Statically linked private DPDK objects of form
+# -l:file.a must be positionned between --whole-archive =E2=80=A6 --no-who=
le-archive
+# linker parameters.
+# Old pkg-config versions misplace --no-whole-archive parameter and put it
+# next to --whole-archive.
+test1_static_libs_order () {
+	PKG_CONFIG_PATH=3D"${PKG_CONFIG_PATH}:$pc_dir" \
+	"$PKGCONF" --libs --static libdpdk | \
+	grep -q 'whole-archive.*l:lib.*no-whole-archive'
+	if test "$?" -ne 0 ; then
+		echo "WARNING: invalid static libraries order"
+		ret=3D1
+	fi
+	return $ret
+}
+
+if [ "$#" -ne 1 ]; then
+	echo "$0: no pkg-config parameter"
+	exit 1
+fi
+PKGCONF=3D"$1"
+
+# take the first result only
+pc_file=3D$(find "$MESON_BUILD_ROOT" -type f -name 'libdpdk.pc' -print -qu=
it)
+if [ ! -f "$pc_file" ]; then
+	echo "$0: cannot locate libdpdk.pc"
+	exit 1
+fi
+pc_dir=3D$(dirname "$pc_file")
+
+ret=3D0
+
+test1_static_libs_order
+if [ $ret -ne 0 ]; then
+	exit $ret
+fi
+
diff --git a/doc/guides/linux_gsg/sys_reqs.rst b/doc/guides/linux_gsg/sys_r=
eqs.rst
index 6ecdc04aa9..b67da05e13 100644
--- a/doc/guides/linux_gsg/sys_reqs.rst
+++ b/doc/guides/linux_gsg/sys_reqs.rst
@@ -60,6 +60,11 @@ Compilation of the DPDK
=20
 *   Linux kernel headers or sources required to build kernel modules.
=20
+
+**Known Issues:**
+
+*   pkg-config v0.27 supplied with RHEL-7 does not process correctly libdp=
dk.pc Libs.private section.
+
 .. note::
=20
    Please ensure that the latest patches are applied to third party librar=
ies
--=20
2.28.0