Yes, you can use shell redirection to write variables to the source file:
VAR1=foobar
all:
@echo "char *variable1 = \"$(VAR1)\"" > generated.c
(the @ sign here should not have an echo command displayed by make).
EDIT: I don't know what your intentions are here, but it would be easier to pass the Makefile variables to the compiler as a macro:
VAR="toco.conf"
CFLAGS = -DVAR='$(VAR)'
all:
gcc $(CFLAGS) prog.c
From prog.c:
#include <stdio.h>
int main(int ac, char **av)
{
printf("%s\n", VAR);
exit(0);
}
source
share