The latest version of GNU-Make http://www.gnu.org/software/make/ provides many advanced capabilities, including many useful functions. (...) On systems which support dynamically loadable objects, you can write your own extension in any language (which can be compiled into such an object) and load it to provide extended capabilities... http://www.gnu.org/software/make/manual/make.html#Loading-Objects
I tried to run the simple example below (a $(hello string) function). It works if I first compile the hello.so. But it doesn't work if I run it as the example provided here (with a load
directive) http://www.gnu.org/software/make/manual/make.html#Loading-Objects . Make4 is installed in the current directory.
./Makefile:
all:
echo $(hello world)
load hello.so
hello.so: hello.c
$(CC) -shared -I./include -fPIC -o $@ $<
./hello.c:
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <gnumake.h>
int plugin_is_GPL_compatible;
char * hello(const char *nm, unsigned int argc, char **argv)
{
int len = strlen (argv[0]) + 7;
char *buf = gmk_alloc (len);
sprintf(buf,"Hello %s",argv[0]);
return buf;
}
int hello_gmk_setup ()
{
gmk_add_function("hello", hello, 1, 1, 1);
return 1;
}
running the example:
./bin/make -v
GNU Make 4.0
Built for i686-pc-linux-gnu
$ ./bin/make
Makefile:4: hello.so: cannot open shared object file: No such file or directory
Makefile:4: *** hello.so: failed to load. Stop.
How can I run this example with the 'load' directive ?
all
simply depend onhello.so
? – Michael Schubertload ./hello.so
; becausedlopen
handles specially paths without/
; alsoall
should depend uponhello.so
– Basile Starynkevitchhello.so
to exist beforeload
-ing it. Perhaps use-load
instead ofload
– Basile Starynkevitch