]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
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 2e4541576f07b29740ae3a714079f2df76fa6a94..cd0c30728dcc7c7df1d8744fe3e4df059f358ea1 100644 (file)
@@ -27,6 +27,7 @@ libtool
 y.tab.[ch]
 lex.yy.c
 *keywords.c
+plugin_constructors.c
 Doxyfile
 apidoc/
 *~
index 8461d623029df591d316fef79881ad4dd32f96bb..3fcaedc3bd5e8309eb325cb8ab32d5a791ad1ad5 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 eadc10a6a2cc31e97bc65f7ddde5954ad517df6a..8daea783f773b701a959257e4cba6d576c517362 100644 (file)
@@ -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.
  */
index 69abfbe0e48f5ebb6a8b99d625407eaabe52b156..b4d8452f1c0bda043d46b75564299a405ab82eef 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 1d1e1f07e784729d06a6a39b6c92cc94d29629cc..7944b9356d8e76fa519d7db7e45707d3d593ee86 100644 (file)
@@ -93,6 +93,13 @@ void library_add_namespace(char *ns)
        }
 }
 
+/**
+ * Register plugins if built statically
+ */
+#ifdef STATIC_PLUGIN_CONSTRUCTORS
+#include "plugin_constructors.c"
+#endif
+
 /**
  * library instance
  */
index 7a630fe549e52cfbab6cfe088758f1fc3732aae4..ff7b54f6ae1b9069e976d8609bb099e991335b1c 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 80ba61c5a690536c898373f2411f955cc5402a70..9627be8620a568b17232e7e92541e219eeca7224 100644 (file)
@@ -54,6 +54,13 @@ struct private_tnc_t {
        refcount_t ref;
 };
 
+/**
+ * Register plugins if built statically
+ */
+#ifdef STATIC_PLUGIN_CONSTRUCTORS
+#include "plugin_constructors.c"
+#endif
+
 /**
  * Single instance of tnc_t.
  */
index c7ac39a09879fd1cfeee5a74c14f2112d1e4b8dc..5f3a97a99b93e5f5976100f4d303c8708ca8fbe1 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 b7b970c8d6e60d224763e3d6d8727601eb841458..42a3418960a310a5fa5792d2b803371cca8e96f0 100644 (file)
 #include "tpm_tss_tss2.h"
 #include "tpm_tss_trousers.h"
 
+/**
+ * Register plugins if built statically
+ */
+#ifdef STATIC_PLUGIN_CONSTRUCTORS
+#include "plugin_constructors.c"
+#endif
+
 /**
  * Described in header.
  */