gst: Add better support for static plugins

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.
This commit is contained in:
Sebastian Dröge 2012-10-24 11:58:35 +02:00
parent 142a55042f
commit 18a7a1d062
3 changed files with 68 additions and 2 deletions

View file

@ -134,6 +134,28 @@ AG_GST_SET_PACKAGE_RELEASE_DATETIME_WITH_NANO([$PACKAGE_VERSION_NANO],
["${srcdir}/gstreamer.doap"], ["${srcdir}/gstreamer.doap"],
[$PACKAGE_VERSION_MAJOR.$PACKAGE_VERSION_MINOR.$PACKAGE_VERSION_MICRO]) [$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 dnl building of tests
AC_ARG_ENABLE(tests, AC_ARG_ENABLE(tests,
AS_HELP_STRING([--disable-tests],[disable building test apps]), AS_HELP_STRING([--disable-tests],[disable building test apps]),
@ -727,7 +749,7 @@ AC_SUBST(GST_OBJ_LIBS)
dnl GST_PLUGIN_LDFLAGS dnl GST_PLUGIN_LDFLAGS
dnl LDFLAGS for plugins; includes GST_ALL_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") AC_SUBST(GST_PLUGIN_LDFLAGS, "$GST_PLUGIN_LDFLAGS")
dnl plugin scanner locations dnl plugin scanner locations
@ -874,6 +896,7 @@ Configuration
Allocation tracing : ${enable_alloc_trace} Allocation tracing : ${enable_alloc_trace}
Plugin registry : ${enable_registry} Plugin registry : ${enable_registry}
Plugin support : ${enable_plugin} Plugin support : ${enable_plugin}
Static plugins : ${enable_static_plugins}
Unit testing support : ${BUILD_CHECK} Unit testing support : ${BUILD_CHECK}
Debug : ${USE_DEBUG} Debug : ${USE_DEBUG}

View file

@ -188,6 +188,34 @@ struct _GstPluginDesc {
#define __GST_PACKAGE_RELEASE_DATETIME NULL #define __GST_PACKAGE_RELEASE_DATETIME NULL
#endif #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: * GST_PLUGIN_DEFINE:
* @major: major version number of the gstreamer-core that plugin was compiled for * @major: major 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 * If defined, the GST_PACKAGE_RELEASE_DATETIME will also be used for the
* #GstPluginDesc,release_datetime field. * #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) \ #define GST_PLUGIN_DEFINE(major,minor,name,description,init,version,license,package,origin) \
G_BEGIN_DECLS \ G_BEGIN_DECLS \
GST_PLUGIN_EXPORT GstPluginDesc gst_plugin_desc = { \ GST_PLUGIN_EXPORT GstPluginDesc gst_plugin_desc = { \
@ -230,6 +272,7 @@ GST_PLUGIN_EXPORT GstPluginDesc gst_plugin_desc = { \
GST_PADDING_INIT \ GST_PADDING_INIT \
}; \ }; \
G_END_DECLS G_END_DECLS
#endif /* GST_PLUGIN_BUILD_STATIC */
/** /**
* GST_LICENSE_UNKNOWN: * GST_LICENSE_UNKNOWN:

View file

@ -27,7 +27,7 @@ libgstcoreelements_la_LIBADD = \
$(top_builddir)/libs/gst/base/libgstbase-@GST_API_VERSION@.la \ $(top_builddir)/libs/gst/base/libgstbase-@GST_API_VERSION@.la \
$(GST_OBJ_LIBS) $(GST_OBJ_LIBS)
libgstcoreelements_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstcoreelements_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstcoreelements_la_LIBTOOLFLAGS = --tag=disable-static libgstcoreelements_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
noinst_HEADERS = \ noinst_HEADERS = \
gstcapsfilter.h \ gstcapsfilter.h \