To create different variants of the same feature, but avoid code duplications within plugins, you have multiple options\+:
\begin{DoxyItemize}
\item Define a needs clause in a contract and reuse another plugin as it is.
\item Have common code together in a helper library (or core library), see the C\+Make function add\+\_\+plugin\+\_\+helper for creating such a library.
\item Have configuration for plugins (See \href{http://doc.libelektra.org/api/latest/html/group__plugin.html}{\tt elektra\+Plugin\+Get\+Config()} and dynamically switch with if according to the configuration.
\item Or use compilation variants to compile the plugin code multiple times with different C\+O\+M\+P\+I\+L\+E\+\_\+\+D\+E\+F\+I\+N\+I\+T\+I\+O\+N\+S (that are Macro definitions).
\end{DoxyItemize}

The compilation variants are the hardest to use, so you should reconsider if another technique is more appropriate.

The advantage of compilation variants are\+:
\begin{DoxyItemize}
\item No runtime overhead
\item Can be used during Bootstrapping (when no configuration is available)
\end{DoxyItemize}

To use compilation variants, add your plugin in the C\+Make Cache Variable P\+L\+U\+G\+I\+N\+S multiple times. There has to be the base variant, called in the same name as the directory. Then there can be an arbitrary number of variants that additional have a name appended with underscore, e.\+g.\+: \begin{DoxyVerb}    myplugin;myplugin_varianta;myplugin_variantb
\end{DoxyVerb}


In the C\+Make\+Lists.\+txt of your plugin, you need a loop over all P\+L\+U\+G\+I\+N\+S and create a plugin per compilation variant\+: \begin{DoxyVerb}    foreach (plugin ${PLUGINS})
            if(${plugin} MATCHES "myplugin_.*")
                    # somehow process the variant names and include
                    # or change sources and compile definitions
                    # based on that.
                    add_plugin(${plugin}
                    SOURCES      <your sources here..>
                    COMPILE_DEFINITIONS   <definitions here..>
\end{DoxyVerb}


Now every public function of the plugin conflicts with itself. To avoid that, you can use\+:
\begin{DoxyItemize}
\item static functions, but they are only visible within one file
\item use helper libraries using add\+\_\+plugin\+\_\+helper to share code between compilation variants
\item Get a unique name for every variant using the macro {\ttfamily \hyperlink{group__plugin_ga34d1a66f0a6e89cfd20f4014a9975a2a}{E\+L\+E\+K\+T\+R\+A\+\_\+\+P\+L\+U\+G\+I\+N\+\_\+\+F\+U\+N\+C\+T\+I\+O\+N(myplugin, open)}} where myplugin is the name of the plugin and the second argument is how the function should be called.
\item Including a readme for every variant (with \#ifdef for different text) using the macro {\ttfamily \#include \hyperlink{group__plugin_ga78d616f68bf9fb0942f66478597467c6}{E\+L\+E\+K\+T\+R\+A\+\_\+\+R\+E\+A\+D\+M\+E(myplugin)}}
\end{DoxyItemize}

As a summary, you can have many plugins build out of the same source. Using pluginname\+\_\+variantnames many plugins will be compiled, each with other S\+O\+U\+R\+C\+E\+S or C\+O\+M\+P\+I\+L\+E\+\_\+\+D\+E\+F\+I\+N\+I\+T\+I\+O\+N\+S. If you, e.\+g. just set the variants name as macro you can use \begin{DoxyVerb}    #ifdef varianta
    #endif
\end{DoxyVerb}


within the code and can have two plugins\+: one (called myplugin\+\_\+varianta) compiled included the {\ttfamily \#ifdef} the other (base variant called myplugin) without.

Currently compilation variants is used in \href{http://libelektra.org/tree/master/src/plugins/resolver/resolver.c}{\tt the resolver plugin}. 