From 4a0b6d659d2fb0473b75cf53bb1a0934983d270c Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Fri, 28 Apr 2017 17:49:50 +0200 Subject: Add plugin constructor registration for all libraries that provide plugins Unfortunately, we can't just add the generated C file to the sources in Makefile.am as the linker would remove that object file when it notices that no symbol in it is ever referenced. So we include it in the file that contains the library initialization, which will definitely be referenced by the executable. This allows building an almost stand-alone static version of e.g. charon when building with `--enable-monolithic --enable-static --disable-shared` (without `--disable-shared` libtool will only build a version that links the libraries dynamically). External libraries (e.g. gmp or openssl) are not linked statically this way, though. --- src/libcharon/Makefile.am | 9 +++++++++ src/libcharon/daemon.c | 7 +++++++ 2 files changed, 16 insertions(+) (limited to 'src/libcharon') diff --git a/src/libcharon/Makefile.am b/src/libcharon/Makefile.am index 8461d6230..3fcaedc3b 100644 --- a/src/libcharon/Makefile.am +++ b/src/libcharon/Makefile.am @@ -184,6 +184,15 @@ if USE_ME sa/ikev2/tasks/ike_me.c sa/ikev2/tasks/ike_me.h endif +if STATIC_PLUGIN_CONSTRUCTORS +BUILT_SOURCES = $(srcdir)/plugin_constructors.c +CLEANFILES = $(srcdir)/plugin_constructors.c + +$(srcdir)/plugin_constructors.c: $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py + $(AM_V_GEN) \ + $(PYTHON) $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py ${c_plugins} > $@ +endif + # build optional plugins ######################## diff --git a/src/libcharon/daemon.c b/src/libcharon/daemon.c index eadc10a6a..8daea783f 100644 --- a/src/libcharon/daemon.c +++ b/src/libcharon/daemon.c @@ -117,6 +117,13 @@ struct private_daemon_t { refcount_t ref; }; +/** + * Register plugins if built statically + */ +#ifdef STATIC_PLUGIN_CONSTRUCTORS +#include "plugin_constructors.c" +#endif + /** * One and only instance of the daemon. */ -- cgit v1.2.3