From 18a7a1d06295fe602672a5ce143c88260ea93930 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 24 Oct 2012 11:58:35 +0200 Subject: [PATCH] gst: Add better support for static plugins MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit API: GST_PLUGIN_STATIC_DECLARE() API: GST_PLUGIN_STATIC_REGISTER() Based on a patch by HÃ¥vard Graff . This now allows GST_PLUGIN_DEFINE() to create a static plugin if GST_PLUGIN_BUILD_STATIC is defined. The resulting plugin can be statically linked or dynamically linked during compilation but can't be dynamically loaded during runtime. Also adds GST_PLUGIN_STATIC_DECLARE() and GST_PLUGIN_STATIC_REGISTER(), which allows to register a static linked plugin easily. It is still required to manually register every single statically linked plugin from inside the application as this can't be automated in a portable way. A new configure parameter --enable-static-plugins was added that allows to build all plugins we build here as static plugins. Fixes bug #667305. --- configure.ac | 25 ++++++++++++++++++++++++- gst/gstplugin.h | 43 +++++++++++++++++++++++++++++++++++++++++++ plugins/elements/Makefile.am | 2 +- 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 8a6ad13..170d6a6 100644 --- a/configure.ac +++ b/configure.ac @@ -134,6 +134,28 @@ AG_GST_SET_PACKAGE_RELEASE_DATETIME_WITH_NANO([$PACKAGE_VERSION_NANO], ["${srcdir}/gstreamer.doap"], [$PACKAGE_VERSION_MAJOR.$PACKAGE_VERSION_MINOR.$PACKAGE_VERSION_MICRO]) +dnl build static plugins or not +AC_MSG_CHECKING([whether to build static plugins or not]) +AC_ARG_ENABLE( + static-plugins, + AC_HELP_STRING( + [--enable-static-plugins], + [build static plugins @<:@default=no@:>@]), + [AS_CASE( + [$enableval], [no], [], [yes], [], + [AC_MSG_ERROR([bad value "$enableval" for --enable-static-plugins])])], + [enable_static_plugins=no]) +AC_MSG_RESULT([$enable_static_plugins]) +if test "x$enable_static_plugins" = xyes; then + AC_DEFINE(GST_PLUGIN_BUILD_STATIC, 1, + [Define if static plugins should be built]) + GST_PLUGIN_LIBTOOLFLAGS="" +else + GST_PLUGIN_LIBTOOLFLAGS="--tag=disable-static" +fi +AC_SUBST(GST_PLUGIN_LIBTOOLFLAGS) +AM_CONDITIONAL(GST_PLUGIN_BUILD_STATIC, test "x$enable_static_plugins" = "xyes") + dnl building of tests AC_ARG_ENABLE(tests, AS_HELP_STRING([--disable-tests],[disable building test apps]), @@ -727,7 +749,7 @@ AC_SUBST(GST_OBJ_LIBS) dnl GST_PLUGIN_LDFLAGS dnl LDFLAGS for plugins; includes GST_ALL_LDFLAGS -GST_PLUGIN_LDFLAGS="-module -avoid-version -export-symbols-regex '^[_]*gst_plugin_desc.*' $GST_ALL_LDFLAGS" +GST_PLUGIN_LDFLAGS="-module -avoid-version -export-symbols-regex '^[_]*gst_plugin_.*' $GST_ALL_LDFLAGS" AC_SUBST(GST_PLUGIN_LDFLAGS, "$GST_PLUGIN_LDFLAGS") dnl plugin scanner locations @@ -874,6 +896,7 @@ Configuration Allocation tracing : ${enable_alloc_trace} Plugin registry : ${enable_registry} Plugin support : ${enable_plugin} + Static plugins : ${enable_static_plugins} Unit testing support : ${BUILD_CHECK} Debug : ${USE_DEBUG} diff --git a/gst/gstplugin.h b/gst/gstplugin.h index f9d3b6d..66ede12 100644 --- a/gst/gstplugin.h +++ b/gst/gstplugin.h @@ -189,6 +189,34 @@ struct _GstPluginDesc { #endif /** + * GST_PLUGIN_STATIC_DECLARE: + * @name: short, but unique name of the plugin + * + * This macro can be used to initialize statically linked plugins. It is + * necessary to call this macro before the plugin can be used. + * It has to be used in combination with GST_PLUGIN_STATIC_REGISTER + * and must be placed outside any block to declare the plugin initialization + * function. + * + * Since: 1.2.0 + */ +#define GST_PLUGIN_STATIC_DECLARE(name) \ + extern void G_PASTE(gst_plugin_, G_PASTE(name, _register)) (void) + +/** + * GST_PLUGIN_STATIC_REGISTER: + * @name: short, but unique name of the plugin + * + * This macro can be used to initialize statically linked plugins. It is + * necessary to call this macro before the plugin can be used. + * It has to be used in combination with GST_PLUGIN_STATIC_DECLARE and + * calls the plugin initialization function. + * + * Since: 1.2.0 + */ +#define GST_PLUGIN_STATIC_REGISTER(name) G_PASTE(gst_plugin_, G_PASTE(name, _register)) () + +/** * GST_PLUGIN_DEFINE: * @major: major version number of the gstreamer-core that plugin was compiled for * @minor: minor version number of the gstreamer-core that plugin was compiled for @@ -213,6 +241,20 @@ struct _GstPluginDesc { * If defined, the GST_PACKAGE_RELEASE_DATETIME will also be used for the * #GstPluginDesc,release_datetime field. */ +#ifdef GST_PLUGIN_BUILD_STATIC +#define GST_PLUGIN_DEFINE(major,minor,name,description,init,version,license,package,origin) \ +G_BEGIN_DECLS \ +GST_PLUGIN_EXPORT void G_PASTE(gst_plugin_, G_PASTE(name, _register)) (void); \ + \ +void \ +G_PASTE(gst_plugin_, G_PASTE(name, _register)) (void) \ +{ \ + gst_plugin_register_static (major, minor, G_STRINGIFY(name), \ + description, init, version, license, \ + PACKAGE, package, origin); \ +} \ +G_END_DECLS +#else /* !GST_PLUGIN_BUILD_STATIC */ #define GST_PLUGIN_DEFINE(major,minor,name,description,init,version,license,package,origin) \ G_BEGIN_DECLS \ GST_PLUGIN_EXPORT GstPluginDesc gst_plugin_desc = { \ @@ -230,6 +272,7 @@ GST_PLUGIN_EXPORT GstPluginDesc gst_plugin_desc = { \ GST_PADDING_INIT \ }; \ G_END_DECLS +#endif /* GST_PLUGIN_BUILD_STATIC */ /** * GST_LICENSE_UNKNOWN: diff --git a/plugins/elements/Makefile.am b/plugins/elements/Makefile.am index 8add0bd..5166c02 100644 --- a/plugins/elements/Makefile.am +++ b/plugins/elements/Makefile.am @@ -27,7 +27,7 @@ libgstcoreelements_la_LIBADD = \ $(top_builddir)/libs/gst/base/libgstbase-@GST_API_VERSION@.la \ $(GST_OBJ_LIBS) libgstcoreelements_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -libgstcoreelements_la_LIBTOOLFLAGS = --tag=disable-static +libgstcoreelements_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS) noinst_HEADERS = \ gstcapsfilter.h \ -- 2.7.4