diff mbox series

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

Message ID 1516010417-3323-16-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v13,1/15] helper: link against libpthread and libodp-linux | expand

Commit Message

Github ODP bot Jan. 15, 2018, 10 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: 634b380b63de53c65b92c214d91aaf03785d69db
 ** Merge commit sha: 9dbaba7b2769979792f04d62a6c8accf0c6b13df
 **/
 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 +--------
 test/Makefile.inc                         |  2 +-
 6 files changed, 72 insertions(+), 43 deletions(-)
diff mbox series

Patch

diff --git a/example/Makefile.inc b/example/Makefile.inc
index 1609066e6..fa1224338 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 415e7b8b7..b7a8ff255 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -305,7 +305,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/test/Makefile.inc b/test/Makefile.inc
index 192dab221..b0a8749dc 100644
--- a/test/Makefile.inc
+++ b/test/Makefile.inc
@@ -11,7 +11,7 @@  LIBTHRMASK_COMMON = $(COMMON_DIR)/libthrmask_common.la
 #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 PRELDADD before the inclusion.
-LDADD = $(PRELDADD) $(LIBODP) $(DPDK_PMDS)
+LDADD = $(PRELDADD) $(LIBODP) $(DPDK_LIBS_LT)
 PRELDADD =
 
 INCFLAGS = \