bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Patch to allow make to load plugins that add new functions.


From: Lawrence Ibarria
Subject: RE: Patch to allow make to load plugins that add new functions.
Date: Thu, 5 Apr 2012 12:52:42 -0700

I like this idea quite a bit. 

I see this as still work in progress to define what type of functions the 
plugins can have. 
Maybe they can even create or change make variables. 

In the case of variable_buffer_output, I'd suggest that each plugin has an 
'initialization function'. This is a handshake where make provides the plugin 
with function pointers (avoids the extern function) and the plugin can provide 
its name, versions, and the function table. That simplifies the code that right 
now tries to get every single variable from the dl_handle. 

-- Lawrence


-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of Tim Murphy
Sent: Thursday, April 05, 2012 2:51 AM
To: address@hidden
Subject: Patch to allow make to load plugins that add new functions.

Hi,

I am between jobs which made me realise that I am absolutely free to
contribute to make for about 10 days :-)

The one thing I have wanted the most and the longest is a way to add
new functions without having to rebuild and look after a custom
version of make.  Essentially this should allow people to extend make
without necessarily having to maintain a custom version of it.

So here is an attempt at a plugin system for your interest. Currently
it ought to work on systems with dlopen.  LoadLibrary on windows
should do the job admirably but I haven't had time to have a go at
that yet.  So the feature is optional (configure --with-plugins).  I
am looking for feedback indicating interest or disagreement or
whatever and mostly I just want to put some code into the open so that
it's there.

My test plugin adds the $(equal ($X),$(Y)) function which returns $(X)
if the variables X and Y match as strings and returns the empty string
if not. I have often wanted this for use with $(if) and have a
horrible and inefficient macro for doing it now but it's something I
feel really ought to be built in.

Here's how you tell make to use a plugin:

./make --plugin=tests/plugins/test-plugin.so -f tests/plugins/plugintest1.mk


Here's the code for this simple test plugin:

#include "plugin.h"
#include <string.h>

/* The next line is a cheat  to save from having to include all the
make headers and possibly end up linking to all sorts of make object
files which defeats the purpose.
   Don't like it and  will have to think of something better: */
extern char *variable_buffer_output (char *ptr, const char *string,
unsigned int length);

int gnumake_plugin_api_version = 1; /* what api the plugin expects
make to provide - just a way for make to know if it's loading a plugin
that should work  */

int gnumake_plugin_major_version = 1; /* The version of this plugin -
might be useful for problem reports */
char gnumake_plugin_name[] = "test_plugin";  /* also the name of the
feature added to .FEATURES */

/* $(equal astring1,astring2) returns blank, $(equal
astring1,astring1) returns "astring1"
 * The purpose of this function is to allow equality tests in $(if)
functions e.g. $(if $(equal $(X),$(Y)),<something>,<else>)
 * */
static char *function_equal(char *o, char **argv, const char *funcname)
{
  if (argv[0] && argv[1] && strcmp(argv[0],argv[1]) == 0)
    {
          o = variable_buffer_output (o, argv[0], strlen (argv[0]));
    }
  else
    {
          o = variable_buffer_output (o, "", 0);
    }

return o;
}

padded_plugin_entry gnumake_plugin_function_table[] = {
        {"equal", 2, 2, 1, function_equal}, /* 2 args, expand them first */
             {"", 0, 0, 0, (void *)0}
};

/* end ---------------------- */



So a plugin is fairly easy to write and it's not hard to build either.

I have tried to set it all up with autoconf and so on but I'm not an
expert at that.  There is also nothing stopping you from loading the
same plugin twice at the moment and it needs more tests and some
documentation so I realise that this patch is not right yet.

There is one set of modifications to main.c to add calls to
load_plugin() which is in a new file, manage-plugins.c, and there is a
new commandline option ("--plugin=") which can be used multiple times.

That's it!

Regards,

Tim

-- 
You could help some brave and decent people to have access to
uncensored news by making a donation at:

http://www.thezimbabwean.co.uk/friends/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]