Re: MAkefile et c

Top Page

Reply to this message
Author: Edgar Bonet
Date:  
To: guilde
Subject: Re: MAkefile et c
Patrick a écrit :
> Comment puisse passer une "variable" d'un Makefile dans le code C ?


$ cat > Makefile <<'EOF'
ANSWER = 42
CFLAGS = -DANSWER=$(ANSWER) -O -Wall -Wextra

all: answer
EOF
$ cat > answer.c <<EOF
#include <stdio.h>

int main(void)
{
    printf("The answer is %d.\n", ANSWER);
    return 0;
}
EOF
$ make
cc -DANSWER=42 -O -Wall -Wextra    answer.c   -o answer
$ ./answer
The answer is 42.