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/
make-plugins-r8.patch
Description: Binary data
_______________________________________________ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make