gst: Add better support for static plugins
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 24 Oct 2012 09:58:35 +0000 (11:58 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Mon, 15 Apr 2013 13:52:18 +0000 (15:52 +0200)
API: GST_PLUGIN_STATIC_DECLARE()
API: GST_PLUGIN_STATIC_REGISTER()

Based on a patch by Håvard Graff <havard.graff@tandberg.com>.

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
gst/gstplugin.h
plugins/elements/Makefile.am

index 8a6ad13..170d6a6 100644 (file)
@@ -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}
index f9d3b6d..66ede12 100644 (file)
@@ -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:
index 8add0bd..5166c02 100644 (file)
@@ -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         \