Add plugin constructor registration for all libraries that provide plugins
authorTobias Brunner <tobias@strongswan.org>
Fri, 28 Apr 2017 15:49:50 +0000 (17:49 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 23 May 2017 16:29:12 +0000 (18:29 +0200)
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.

.gitignore
src/libcharon/Makefile.am
src/libcharon/daemon.c
src/libstrongswan/Makefile.am
src/libstrongswan/library.c
src/libtnccs/Makefile.am
src/libtnccs/tnc/tnc.c
src/libtpmtss/Makefile.am
src/libtpmtss/tpm_tss.c

index 2e45415..cd0c307 100644 (file)
@@ -27,6 +27,7 @@ libtool
 y.tab.[ch]
 lex.yy.c
 *keywords.c
+plugin_constructors.c
 Doxyfile
 apidoc/
 *~
index 8461d62..3fcaedc 100644 (file)
@@ -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
 ########################
 
index eadc10a..8daea78 100644 (file)
@@ -118,6 +118,13 @@ struct private_daemon_t {
 };
 
 /**
+ * Register plugins if built statically
+ */
+#ifdef STATIC_PLUGIN_CONSTRUCTORS
+#include "plugin_constructors.c"
+#endif
+
+/**
  * One and only instance of the daemon.
  */
 daemon_t *charon;
index 69abfbe..b4d8452 100644 (file)
@@ -221,6 +221,15 @@ $(srcdir)/crypto/proposal/proposal_keywords_static.c:      $(srcdir)/crypto/proposal/
                $(GPERF) -N proposal_get_token_static -m 10 -C -G -c -t -D < \
                                                                                                $(srcdir)/crypto/proposal/proposal_keywords_static.txt > $@
 
+if STATIC_PLUGIN_CONSTRUCTORS
+BUILT_SOURCES += $(srcdir)/plugin_constructors.c
+CLEANFILES = $(srcdir)/plugin_constructors.c
+
+$(srcdir)/plugin_constructors.c: $(srcdir)/plugins/plugin_constructors.py
+               $(AM_V_GEN) \
+               $(PYTHON) $(srcdir)/plugins/plugin_constructors.py ${s_plugins} > $@
+endif
+
 if MONOLITHIC
 SUBDIRS =
 else
index 1d1e1f0..7944b93 100644 (file)
@@ -94,6 +94,13 @@ void library_add_namespace(char *ns)
 }
 
 /**
+ * Register plugins if built statically
+ */
+#ifdef STATIC_PLUGIN_CONSTRUCTORS
+#include "plugin_constructors.c"
+#endif
+
+/**
  * library instance
  */
 library_t *lib = NULL;
index 7a630fe..ff7b54f 100644 (file)
@@ -26,6 +26,15 @@ tnc/tnccs/tnccs_manager.h tnc/tnccs/tnccs_manager.c
 
 EXTRA_DIST = Android.mk
 
+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 ${t_plugins} > $@
+endif
+
 # build optional plugins
 ########################
 
index 80ba61c..9627be8 100644 (file)
@@ -55,6 +55,13 @@ struct private_tnc_t {
 };
 
 /**
+ * Register plugins if built statically
+ */
+#ifdef STATIC_PLUGIN_CONSTRUCTORS
+#include "plugin_constructors.c"
+#endif
+
+/**
  * Single instance of tnc_t.
  */
 tnc_t *tnc;
index c7ac39a..5f3a97a 100644 (file)
@@ -33,6 +33,15 @@ else
 SUBDIRS = .
 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 ${p_plugins} > $@
+endif
+
 if USE_TPM
   SUBDIRS += plugins/tpm
 if MONOLITHIC
index b7b970c..42a3418 100644 (file)
 #include "tpm_tss_trousers.h"
 
 /**
+ * Register plugins if built statically
+ */
+#ifdef STATIC_PLUGIN_CONSTRUCTORS
+#include "plugin_constructors.c"
+#endif
+
+/**
  * Described in header.
  */
 void libtpmtss_init(void)