conf: Generate and install config sippets for option descriptions
authorTobias Brunner <tobias@strongswan.org>
Thu, 23 Jan 2014 15:44:12 +0000 (16:44 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 12 Feb 2014 13:34:33 +0000 (14:34 +0100)
The strongswan.d directory is also created relative to the configured
location of strongswan.conf.

conf/.gitignore [new file with mode: 0644]
conf/Makefile.am
conf/default.opt [new file with mode: 0644]
conf/options/charon.opt [new file with mode: 0644]
conf/plugins/test.opt [new file with mode: 0644]
conf/strongswan.conf
configure.ac

diff --git a/conf/.gitignore b/conf/.gitignore
new file mode 100644 (file)
index 0000000..1a3e524
--- /dev/null
@@ -0,0 +1,3 @@
+default.conf
+*/*.conf
+*/*.tmp
\ No newline at end of file
index 7a5c263..bdab4d3 100644 (file)
@@ -1,6 +1,63 @@
-EXTRA_DIST = strongswan.conf
+# make this relative to the location of strongswan.conf
+strongswanconfdir = `dirname $(strongswan_conf)`
+strongswanddir = $(strongswanconfdir)/strongswan.d
+charonconfdir = $(strongswanddir)/charon
 
-install-exec-local :
-               test -e "$(DESTDIR)${sysconfdir}" || $(INSTALL) -d "$(DESTDIR)$(sysconfdir)"
-               test -e "$(DESTDIR)$(sysconfdir)/strongswan.conf" || $(INSTALL) -m 640 $(srcdir)/strongswan.conf $(DESTDIR)$(sysconfdir)/strongswan.conf || true
-               test -e "$(DESTDIR)${sysconfdir}/strongswan.d" || $(INSTALL) -d "$(DESTDIR)$(sysconfdir)/strongswan.d"
+options = \
+       options/charon.opt
+
+plugins = \
+       plugins/test.opt
+
+alloptions = $(options) $(plugins)
+
+confsnippets = $(alloptions:opt=conf)
+
+# we only install snippets for enabled plugins
+plugins_install_tmp = $(charon_plugins:%=plugins/%.tmp)
+plugins_install_src = $(charon_plugins:%=plugins/%.conf)
+
+strongswand_DATA = $(options:opt=conf)
+charonconf_DATA = $(plugins_install_src)
+
+BUILT_SOURCES = default.conf $(confsnippets)
+EXTRA_DIST = format-options.py strongswan.conf default.opt \
+       default.conf $(alloptions) $(confsnippets)
+
+.opt.conf:
+       $(AM_V_GEN) \
+       case "$<" in \
+       *plugins/*) \
+               sed \
+               -e "s:\@PLUGIN_NAME\@:`basename $< .opt`:" \
+               $(srcdir)/default.opt | cat - $< | \
+               $(PYTHON) $(srcdir)/format-options.py -f conf -r charon.plugins > $(srcdir)/$@ \
+               ;; \
+       *) \
+               $(PYTHON) $(srcdir)/format-options.py -f conf -r charon.plugins $< > $(srcdir)/$@ \
+               ;; \
+       esac
+
+# we need another implicit rule to generate files from the generic template only
+# if the rules above did not catch it.  this requires an intermediate step that
+# generates a copy of the generic config template.
+$(plugins_install_tmp):
+       @cp $(srcdir)/default.conf $(srcdir)/$@
+
+.tmp.conf:
+       $(AM_V_GEN) \
+       sed \
+       -e "s:\@PLUGIN_NAME\@:`basename $< .tmp`:" \
+       $(srcdir)/$< > $(srcdir)/$@
+
+maintainer-clean-local:
+       cd $(srcdir) && \
+               rm -f $(confsnippets) default.conf plugins/*.conf plugins/*.tmp
+
+install-exec-local:
+       test -e "$(DESTDIR)${strongswanconfdir}" || $(INSTALL) -d "$(DESTDIR)$(strongswanconfdir)"
+       test -e "$(DESTDIR)$(strongswanconfdir)/strongswan.conf" || $(INSTALL) -m 640 $(srcdir)/strongswan.conf $(DESTDIR)$(strongswanconfdir)/strongswan.conf || true
+
+install-data-hook:
+       chmod 0640 $(DESTDIR)$(strongswanddir)/*.conf
+       chmod 0640 $(DESTDIR)$(charonconfdir)/*.conf
diff --git a/conf/default.opt b/conf/default.opt
new file mode 100644 (file)
index 0000000..8c83364
--- /dev/null
@@ -0,0 +1,3 @@
+charon.plugins.@PLUGIN_NAME@.load := yes
+       Whether to load the plugin. Can also be an integer to increase the priority
+       of this plugin.
diff --git a/conf/options/charon.opt b/conf/options/charon.opt
new file mode 100644 (file)
index 0000000..a7a2259
--- /dev/null
@@ -0,0 +1,2 @@
+charon.threads = 16
+       Number of threads
\ No newline at end of file
diff --git a/conf/plugins/test.opt b/conf/plugins/test.opt
new file mode 100644 (file)
index 0000000..9d962e3
--- /dev/null
@@ -0,0 +1,30 @@
+charon.plugins.test.opt
+       This is a normal option without default
+
+charon.plugins.test.noncomment := set this
+       This will not be commented out
+
+charon.plugins.test.def = default
+       Option with default
+
+charon.plugins.test.sectionnocomment.opt = val
+       The section this is in has no description
+
+charon.plugins.test.sub {}
+       This section has comments
+
+charon.plugins.test.sub.opt = option in sub
+       Section option
+
+charon.plugins.test.<commented> { # }
+       Commented example section
+
+charon.plugins.test.<commented>.val = value
+       This is commented anyway
+
+charon.plugins.test.<commented>.assign := value
+       This is commented too because of the commented section
+
+charon.plugins.test.sub = value
+       Sections can also be options with values
+       Longer description with **bold** and _italic_.
index b2493e8..d906728 100644 (file)
@@ -5,8 +5,9 @@
 # Configuration changes should be made in the included files
 
 charon {
+       load_modular = yes
        plugins {
-
+               include strongswan.d/charon/*.conf
        }
 }
 
index 2eba4d5..cfa9b4a 100644 (file)
@@ -302,6 +302,7 @@ AC_PROG_EGREP
 AC_PROG_AWK
 AC_PROG_LEX
 AC_PROG_YACC
+AM_PATH_PYTHON(,,[:])
 AC_PATH_PROG([PERL], [perl], [], [$PATH:/bin:/usr/bin:/usr/local/bin])
 AC_PATH_PROG([GPERF], [gperf], [], [$PATH:/bin:/usr/bin:/usr/local/bin])