diff mbox series

[v7,1/2] build: provide an option to link examples dynamically

Message ID 1516309228-14151-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v7,1/2] build: provide an option to link examples dynamically | expand

Commit Message

Github ODP bot Jan. 18, 2018, 9 p.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Distributions won't like statically-linked binaries. Provide configure
switch to link examples and tests dynamically.

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

---
/** Email created from pull request 390 (lumag:dynamic-link-tests)
 ** https://github.com/Linaro/odp/pull/390
 ** Patch: https://github.com/Linaro/odp/pull/390.patch
 ** Base sha: 5a4502fc6bc53e6503169da3028f456b64811a0b
 ** Merge commit sha: edf30b70f488ab88edf3bbccf655c1f45fb0753c
 **/
 configure.ac                                 | 11 +++++++++++
 example/Makefile.inc                         | 12 +++++++++++-
 platform/linux-generic/test/Makefile.am      |  3 +--
 platform/linux-generic/test/ring/Makefile.am | 28 ++++++++++++++++++++++++++--
 test/Makefile.inc                            | 12 +++++++++++-
 5 files changed, 60 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/configure.ac b/configure.ac
index 0c8799f1e..56a422b4b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -182,6 +182,16 @@  AS_IF([test "${with_platform}" = "linux-generic"],
 AC_DEFINE_UNQUOTED([IMPLEMENTATION_NAME], ["$IMPLEMENTATION_NAME"],
 		   [Define to the name of the implementation])
 
+##########################################################################
+# Build examples/tests dynamically
+##########################################################################
+AC_ARG_ENABLE([static-applications],
+	      [AS_HELP_STRING([--disable-static-applications],
+			      [disable static linking of examples and tests]
+			      [ with ODP])], [],
+	      [enable_static_applications=yes])
+AM_CONDITIONAL([STATIC_APPS], [test "x$enable_static_applications" != "xno"])
+
 ##########################################################################
 # Include m4 files
 ##########################################################################
@@ -393,6 +403,7 @@  AC_MSG_RESULT([
 	Deprecated APIs:	${deprecated}
 	debug:			${enable_debug}
 	cunit:			${cunit_support}
+	static tests linkage:	${enable_static_applications}
 	test_vald:		${test_vald}
 	test_perf:		${test_perf}
 	test_perf_proc:		${test_perf_proc}
diff --git a/example/Makefile.inc b/example/Makefile.inc
index 4a15ee7e0..3c8060da9 100644
--- a/example/Makefile.inc
+++ b/example/Makefile.inc
@@ -2,11 +2,21 @@  include $(top_srcdir)/Makefile.inc
 
 TESTS_ENVIRONMENT = EXEEXT=${EXEEXT}
 
-LDADD = $(LIB)/libodp-linux.la $(LIB)/libodphelper.la $(DPDK_LIBS_LT)
+LDADD = $(LIB)/libodp-linux.la $(LIB)/libodphelper.la
+
+# Do not link to DPDK twice in case of dynamic linking with ODP
+if STATIC_APPS
+LDADD += $(DPDK_LIBS_LT)
+endif
+
 AM_CFLAGS = \
 	-I$(srcdir) \
 	-I$(top_srcdir)/example \
 	$(ODP_INCLUDES) \
 	$(HELPER_INCLUDES)
 
+if STATIC_APPS
 AM_LDFLAGS = -L$(LIB) -static
+else
+AM_LDFLAGS =
+endif
diff --git a/platform/linux-generic/test/Makefile.am b/platform/linux-generic/test/Makefile.am
index 97784a02c..99934099a 100644
--- a/platform/linux-generic/test/Makefile.am
+++ b/platform/linux-generic/test/Makefile.am
@@ -6,8 +6,7 @@  SUBDIRS = performance
 if test_vald
 TESTS = validation/api/pktio/pktio_run.sh \
 	validation/api/pktio/pktio_run_tap.sh \
-	validation/api/shmem/shmem_linux$(EXEEXT) \
-	ring/ring_main$(EXEEXT)
+	validation/api/shmem/shmem_linux$(EXEEXT)
 
 SUBDIRS += validation/api/pktio\
 	   validation/api/shmem\
diff --git a/platform/linux-generic/test/ring/Makefile.am b/platform/linux-generic/test/ring/Makefile.am
index edaf4510c..3f774342e 100644
--- a/platform/linux-generic/test/ring/Makefile.am
+++ b/platform/linux-generic/test/ring/Makefile.am
@@ -1,3 +1,7 @@ 
+# ring test uses internal symbols from libodp-linux which are not available
+# when linking test with libodp-linux.so
+if STATIC_APPS
+
 include $(top_srcdir)/test/Makefile.inc
 
 test_PROGRAMS = ring_main
@@ -6,7 +10,27 @@  ring_main_SOURCES = \
 		    ring_suites.c ring_suites.h \
 		    ring_basic.c ring_stress.c
 
+TESTS = ring_main$(EXEEXT)
+
 PRELDADD += $(LIBCUNIT_COMMON)
 
-AM_CPPFLAGS += \
-		     -I$(top_srcdir)/platform/linux-generic/include
+AM_CPPFLAGS += -I$(top_srcdir)/platform/linux-generic/include
+
+TESTNAME = linux-generic-ring
+
+TESTENV = tests-$(TESTNAME).env
+
+test_DATA = $(TESTENV)
+
+DISTCLEANFILES = $(TESTENV)
+.PHONY: $(TESTENV)
+$(TESTENV):
+	echo "TESTS=\"$(TESTS)\""    > $@
+	echo "$(TESTS_ENVIRONMENT)" >> $@
+	echo "$(LOG_COMPILER)"      >> $@
+
+if test_installdir
+installcheck-local:
+	$(DESTDIR)/$(testdir)/run-test.sh $(TESTNAME)
+endif
+endif
diff --git a/test/Makefile.inc b/test/Makefile.inc
index 83004f0c6..55a493a85 100644
--- a/test/Makefile.inc
+++ b/test/Makefile.inc
@@ -11,16 +11,26 @@  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_LIBS_LT)
+LDADD = $(PRELDADD) $(LIBODP)
 PRELDADD =
 
 AM_CPPFLAGS = \
 	$(ODP_INCLUDES) \
 	$(HELPER_INCLUDES) \
 	-I$(top_srcdir)/test/common
+
+# Do not link to DPDK twice in case of dynamic linking with ODP
+if STATIC_APPS
+LDADD += $(DPDK_LIBS_LT)
+endif
+
 AM_CFLAGS = $(CUNIT_CFLAGS)
 
+if STATIC_APPS
 AM_LDFLAGS = -L$(LIB) -static
+else
+AM_LDFLAGS =
+endif
 
 @VALGRIND_CHECK_RULES@