[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: adding functions to function.c
From: |
John Graham-Cumming |
Subject: |
Re: adding functions to function.c |
Date: |
Tue, 11 Jan 2005 23:30:07 -0500 |
On Tue, 2005-01-11 at 13:42, Dill, John wrote:
> A little while back someone mentioned that it would be possible to add
> the functions directly to the makefile source. Is all I do is add the
> name of the function to the list using STRING_SIZE_TUPLE, and then
> define my own function?
I was the one that suggested you do that. For example, suppose you were
me and you egotistically wanted to add the $(jgc TEXT) function which
printed out John Graham-Cumming followed by the expanded TEXT argument
you would do this:
1. Add a function that does the work:
static char *
func_jgc (o, argv, funcname)
char *o;
char **argv;
const char *funcname;
{
char f[256];
sprintf( f, "John Graham-Cumming %s", argv[0] );
return variable_buffer_output (o, f, strlen(f));
}
2. Add an entry in the function table:
{ STRING_SIZE_TUPLE("jgc"), 0, 1, 1, func_jgc},
which states that the $(jgc) function has maximum one argument which
should be expanded before the value is passed to func_jgc.
Now consider this Makefile:
FOO := is nuts
all: ; @echo $(jgc $(FOO))
When using the augmented GNU Make with the $(jgc) function this prints
John Graham-Cumming is nuts
$(FOO) is expanded before func_jgc is called because expanding was set
to 1 and the func_jgc just returns that appropriate string in o.
John.
--
John Graham-Cumming
Home: http://www.jgc.org/
Work: http://www.electric-cloud.com/
POPFile: http://getpopfile.org/