diff mbox series

[v8,7/15] linux-gen: dpdk: simplify linking with shared libdpdk

Message ID 1514944809-29308-8-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [v8,1/15] helper: link against libpthread and libodp-linux | expand

Commit Message

Github ODP bot Jan. 3, 2018, 2 a.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


There is no need to pass PMDs when linking with shared DPDK library.
Just pass -ldpdk which will pick up all PMDS dynamically. When linking
with static DPKD library it is required to pass additional libraries
after whole PMD string to fix linking when Libtool will reorder flags.
So provide just two variables DPDK_LIBS and DPDK_LIBS_LT. Former should
be passed directly to gcc, while later should be passed to libtool.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 377 (lumag:misc-fixes)
 ** https://github.com/Linaro/odp/pull/377
 ** Patch: https://github.com/Linaro/odp/pull/377.patch
 ** Base sha: 49ebafae0edebbc750742d8874ad0a7588286dea
 ** Merge commit sha: c5df42a14c866959ebcb501d64de76a99b6b00d7
 **/
 example/Makefile.inc                      |  2 +-
 m4/odp_dpdk.m4                            | 83 ++++++++++++++++++++++++-------
 platform/linux-generic/Makefile.am        |  2 +-
 platform/linux-generic/libodp-linux.pc.in |  2 +-
 platform/linux-generic/m4/odp_dpdk.m4     | 24 +--------
 platform/linux-generic/test/Makefile.inc  |  2 +-
 test/Makefile.inc                         |  2 +-
 test/validation/api/Makefile.inc          |  1 -
 8 files changed, 73 insertions(+), 45 deletions(-)
diff mbox series

Patch

diff --git a/example/Makefile.inc b/example/Makefile.inc
index 4cf5cfacc..829977ce8 100644
--- a/example/Makefile.inc
+++ b/example/Makefile.inc
@@ -1,7 +1,7 @@ 
 TESTS_ENVIRONMENT = EXEEXT=${EXEEXT}
 
 LIB   = $(top_builddir)/lib
-LDADD = $(LIB)/libodp-linux.la $(LIB)/libodphelper.la $(DPDK_PMDS)
+LDADD = $(LIB)/libodp-linux.la $(LIB)/libodphelper.la $(DPDK_LIBS_LT)
 AM_CFLAGS = \
 	-I$(srcdir) \
 	-I$(top_srcdir)/example \
diff --git a/m4/odp_dpdk.m4 b/m4/odp_dpdk.m4
index 05e60cc06..1887b0431 100644
--- a/m4/odp_dpdk.m4
+++ b/m4/odp_dpdk.m4
@@ -1,22 +1,38 @@ 
 # ODP_DPDK_PMDS(DPDK_DRIVER_PATH)
 # -------------------------------
-# Build a list of DPDK PMD drivers in DPDK_PMDS variable
+# Build a list of DPDK PMD drivers in DPDK_PMDS variable.
+# Updated DPDK_LIBS to include dependencies.
 AC_DEFUN([ODP_DPDK_PMDS], [dnl
-AS_VAR_SET([DPDK_PMDS], [-Wl,--whole-archive,])
+AS_VAR_SET([DPDK_PMDS], ["-Wl,--whole-archive,"])
 for filename in "$1"/librte_pmd_*.a; do
 cur_driver=`basename "$filename" .a | sed -e 's/^lib//'`
-# rte_pmd_nfp has external dependencies which break linking
-if test "$cur_driver" = "rte_pmd_nfp"; then
-    echo "skip linking rte_pmd_nfp"
-else
-    AS_VAR_APPEND([DPDK_PMDS], [-l$cur_driver,])
-fi
+AS_VAR_APPEND([DPDK_PMDS], [-l$cur_driver,])
+AS_CASE([$cur_driver],
+    [rte_pmd_nfp], [AS_VAR_APPEND([DPDK_LIBS], [" -lm"])],
+    [rte_pmd_pcap], [AS_VAR_APPEND([DPDK_LIBS], [" -lpcap"])],
+    [rte_pmd_openssl], [AS_VAR_APPEND([DPDK_LIBS], [" -lcrypto"])])
 done
 AS_VAR_APPEND([DPDK_PMDS], [--no-whole-archive])
-AC_SUBST([DPDK_PMDS])
 ])
 
-# _ODP_DPDK_CHECK_LIB(LDFLAGS, [LIBS], [EXTRA_LIBS])
+# _ODP_DPDK_SET_LIBS
+# --------------------
+# Set DPDK_LIBS/DPDK_LIBS_LT depending on DPDK setup
+AC_DEFUN([_ODP_DPDK_SET_LIBS], [dnl
+AS_IF([test "x$DPDK_SHARED" = "xyes"], [dnl
+    DPDK_LIBS_LT=""
+    DPDK_LIBS="$DPDK_LDFLAGS $DPDK_RPATH $DPDK_LIBS"
+], [dnl
+    ODP_DPDK_PMDS([$DPDK_PMD_PATH])
+    DPDK_LIBS_LT="`echo $DPDK_LIBS | sed -e 's/^/-Wc,/' -e 's/ /,/g'`"
+    DPDK_LIBS_LT="$DPDK_LDFLAGS $DPDK_PMDS $DPDK_LIBS_LT $DPDK_LIBS"
+    DPDK_LIBS="$DPDK_LDFLAGS $DPDK_PMDS $DPDK_LIBS"
+])
+AC_SUBST([DPDK_LIBS])
+AC_SUBST([DPDK_LIBS_LT])
+])
+
+# _ODP_DPDK_CHECK_LIB(LDFLAGS, [LIBS])
 # ----------------------------------
 # Check if one can use -ldpdk with provided set of libs
 AC_DEFUN([_ODP_DPDK_CHECK_LIB], [dnl
@@ -31,7 +47,7 @@  LIBS="$LIBS -ldpdk $2"
 AC_MSG_CHECKING([for rte_eal_init in -ldpdk $2])
 AC_LINK_IFELSE([AC_LANG_CALL([], [rte_eal_init])],
 	       [AC_MSG_RESULT([yes])
-	        DPDK_LIBS="$1 -ldpdk $3 $2"],
+	        DPDK_LIBS="-ldpdk $2"],
 	       [AC_MSG_RESULT([no])])
 
 ##########################################################################
@@ -41,10 +57,10 @@  LDFLAGS=$OLD_LDFLAGS
 LIBS=$OLD_LIBS
 ])
 
-# ODP_DPDK_CHECK(CPPFLAGS, LDFLAGS, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
-# -----------------------------------------------------------------------
+# _ODP_DPDK_CHECK(CPPFLAGS, LDFLAGS, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
+# ------------------------------------------------------------------------
 # Check for DPDK availability
-AC_DEFUN([ODP_DPDK_CHECK], [dnl
+AC_DEFUN([_ODP_DPDK_CHECK], [dnl
 ##########################################################################
 # Save and set temporary compilation flags
 ##########################################################################
@@ -59,13 +75,14 @@  AC_CHECK_HEADERS([rte_config.h], [],
 DPDK_LIBS=""
 _ODP_DPDK_CHECK_LIB([$2])
 AS_IF([test "x$DPDK_LIBS" = "x"],
-      [_ODP_DPDK_CHECK_LIB([$2], [-ldl -lpthread], [-lm])])
+      [_ODP_DPDK_CHECK_LIB([$2], [-ldl -lpthread])])
 AS_IF([test "x$DPDK_LIBS" = "x"],
-      [_ODP_DPDK_CHECK_LIB([$2], [-ldl -lpthread -lnuma], [-lm])])
+      [_ODP_DPDK_CHECK_LIB([$2], [-ldl -lpthread -lnuma])])
 AS_IF([test "x$DPDK_LIBS" = "x"],
       [dpdk_check_ok=no])
 AS_IF([test "x$dpdk_check_ok" != "xno"],
-      [AC_SUBST([DPDK_LIBS])
+      [_ODP_DPDK_SET_LIBS
+       AC_SUBST([DPDK_CPPFLAGS])
        m4_default([$3], [:])],
       [m4_default([$4], [:])])
 
@@ -74,3 +91,35 @@  AS_IF([test "x$dpdk_check_ok" != "xno"],
 ##########################################################################
 CPPFLAGS=$OLD_CPPFLAGS
 ])
+
+# ODP_DPDK(DPDK_PATH, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+# -----------------------------------------------------------------------
+# Check for DPDK availability
+AC_DEFUN([ODP_DPDK], [dnl
+AS_IF([test "x$1" = "xsystem"], [dnl
+    DPDK_CPPFLAGS="-isystem/usr/include/dpdk"
+    DPDK_LDFLAGS=""
+    DPDK_RPATH=""
+    DPDK_LIB_PATH="`$CC --print-file-name=libdpdk.so`"
+    if test "x$DPDK_LIB_PATH" = "x" ; then
+	DPDK_LIB_PATH="`$CC --print-file-name=libdpdk.a`"
+    else
+	DPDK_SHARED=yes
+    fi
+    AS_IF([test "x$DPDK_LIB_PATH" = "x"],
+	  [AC_MSG_FAILURE([Could not locate system DPDK library directory])])
+    DPDK_PMD_PATH=`AS_DIRNAME(["$DPDK_PMD_PATH"])`
+], [dnl
+    DPDK_CPPFLAGS="-isystem $1/include"
+    DPDK_LIB_PATH="$1/lib"
+    DPDK_LDFLAGS="-L$DPDK_LIB_PATH"
+    DPDK_PMD_PATH="$DPDK_LIB_PATH"
+    if test -r "$DPDK_LIB_PATH"/libdpdk.so ; then
+	DPDK_RPATH="-R$DPDK_LIB_PATH"
+	DPDK_SHARED=yes
+    else
+	DPDK_RPATH=
+    fi
+])
+_ODP_DPDK_CHECK([$DPDK_CPPFLAGS], [$DPDK_LDFLAGS], [$2], [$3])
+])
diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index 7e40448bd..92ce2cce6 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -306,7 +306,7 @@  endif
 
 __LIB__libodp_linux_la_LIBADD = $(ATOMIC_LIBS)
 __LIB__libodp_linux_la_LIBADD += $(OPENSSL_LIBS)
-__LIB__libodp_linux_la_LIBADD += $(DPDK_LIBS) $(DPDK_PMDS)
+__LIB__libodp_linux_la_LIBADD += $(DPDK_LIBS_LT)
 __LIB__libodp_linux_la_LIBADD += $(PTHREAD_LIBS)
 __LIB__libodp_linux_la_LIBADD += $(TIMER_LIBS)
 
diff --git a/platform/linux-generic/libodp-linux.pc.in b/platform/linux-generic/libodp-linux.pc.in
index 962a4f78f..5125f83ad 100644
--- a/platform/linux-generic/libodp-linux.pc.in
+++ b/platform/linux-generic/libodp-linux.pc.in
@@ -7,5 +7,5 @@  Name: libodp-linux
 Description: The ODP packet processing engine
 Version: @PKGCONFIG_VERSION@
 Libs: -L${libdir} -lodp-linux
-Libs.private: @OPENSSL_STATIC_LIBS@ @DPDK_PMDS@ @DPDK_LIBS@ @PCAP_LIBS@ @PTHREAD_LIBS@ @TIMER_LIBS@ -lpthread @ATOMIC_LIBS@
+Libs.private: @OPENSSL_STATIC_LIBS@ @DPDK_LIBS@ @PCAP_LIBS@ @PTHREAD_LIBS@ @TIMER_LIBS@ -lpthread @ATOMIC_LIBS@
 Cflags: -I${includedir}
diff --git a/platform/linux-generic/m4/odp_dpdk.m4 b/platform/linux-generic/m4/odp_dpdk.m4
index 471bbcd51..b2193a168 100644
--- a/platform/linux-generic/m4/odp_dpdk.m4
+++ b/platform/linux-generic/m4/odp_dpdk.m4
@@ -13,17 +13,6 @@  AC_ARG_WITH([dpdk-path],
     [DPDK_PATH="$withval"
      pktio_dpdk_support=yes],[])
 
-AS_IF([test "x$DPDK_PATH" = "xsystem"],
-      [DPDK_CPPFLAGS="-isystem/usr/include/dpdk"
-       DPDK_LDFLAGS=""
-       DPDK_PMD_PATH="`$CC --print-file-name=librte_pmd_null.a`"
-       DPDK_PMD_PATH="`dirname "$DPDK_PMD_PATH"`"
-       AS_IF([test "x$DPDK_PMD_PATH" = "x"],
-	     [AC_MSG_FAILURE([Could not locate system DPDK PMD directory])])],
-      [DPDK_CPPFLAGS="-isystem $DPDK_PATH/include"
-       DPDK_LDFLAGS="-L$DPDK_PATH/lib"
-       DPDK_PMD_PATH="$DPDK_PATH/lib"])
-
 ##########################################################################
 # Enable zero-copy DPDK pktio
 ##########################################################################
@@ -42,22 +31,13 @@  AC_ARG_ENABLE([dpdk-zero-copy],
 ##########################################################################
 if test x$pktio_dpdk_support = xyes
 then
-    ODP_DPDK_CHECK([$DPDK_CPPFLAGS], [$DPDK_LDFLAGS], [],
-                   [AC_MSG_FAILURE([can't find DPDK])])
-
-    ODP_DPDK_PMDS([$DPDK_PMD_PATH])
+    ODP_DPDK([$DPDK_PATH], [],
+	     [AC_MSG_FAILURE([can't find DPDK])])
 
     AC_DEFINE([ODP_PKTIO_DPDK], [1],
 	      [Define to 1 to enable DPDK packet I/O support])
     AC_DEFINE_UNQUOTED([ODP_DPDK_ZERO_COPY], [$zero_copy],
 	      [Define to 1 to enable DPDK zero copy support])
-
-    if test -r "$DPDK_PMD_PATH/librte_pmd_pcap.a" &&
-       ! test -r "$DPDK_PMD_PATH/librte_pmd_pcap.so" ; then
-        DPDK_LIBS="$DPDK_LIBS -lpcap"
-    fi
-    AC_SUBST([DPDK_CPPFLAGS])
-    AC_SUBST([DPDK_LIBS])
 else
     pktio_dpdk_support=no
 fi
diff --git a/platform/linux-generic/test/Makefile.inc b/platform/linux-generic/test/Makefile.inc
index dd21917eb..419a63d1c 100644
--- a/platform/linux-generic/test/Makefile.inc
+++ b/platform/linux-generic/test/Makefile.inc
@@ -8,7 +8,7 @@  AM_CFLAGS = $(CUNIT_CFLAGS)
 
 LIBCUNIT_COMMON = $(top_builddir)/test/common/libcunit_common.la
 LIB   = $(top_builddir)/lib
-LIBODP = $(LIB)/libodphelper.la $(LIB)/libodp-linux.la $(DPDK_PMDS)
+LIBODP = $(LIB)/libodphelper.la $(LIB)/libodp-linux.la $(DPDK_LIBS_LT)
 
 INCCUNIT_COMMON = -I$(top_srcdir)/test/common
 INCODP =  \
diff --git a/test/Makefile.inc b/test/Makefile.inc
index d7e435038..857de4512 100644
--- a/test/Makefile.inc
+++ b/test/Makefile.inc
@@ -3,7 +3,7 @@  LIB   = $(top_builddir)/lib
 #in the following line, the libs using the symbols should come before
 #the libs containing them! The includer is given a chance to add things
 #before libodp by setting PRE_LDADD before the inclusion.
-LDADD = $(PRE_LDADD) $(LIB)/libodphelper.la $(LIB)/libodp-linux.la $(DPDK_PMDS)
+LDADD = $(PRE_LDADD) $(LIB)/libodphelper.la $(LIB)/libodp-linux.la $(DPDK_LIBS_LT)
 
 INCFLAGS = \
 	-I$(top_builddir)/platform/@with_platform@/include \
diff --git a/test/validation/api/Makefile.inc b/test/validation/api/Makefile.inc
index 4af010002..6e66301be 100644
--- a/test/validation/api/Makefile.inc
+++ b/test/validation/api/Makefile.inc
@@ -3,7 +3,6 @@  include $(top_srcdir)/test/Makefile.inc
 COMMON_DIR = $(top_builddir)/test/common
 
 AM_CFLAGS += -I$(top_srcdir)/test/common
-AM_LDFLAGS += $(DPDK_PMDS)
 
 AM_CFLAGS += $(CUNIT_CFLAGS)