示例代码(文件compile_macro_test.c):
#include <stdio.h>
int main()
{int a = 0;
#ifdef DBUG
a = 5;
#endifprintf("=========%d\n",a);
return 0;
}
对应Makefile文件
all:a.out
debug:b.out
mv b.out a.outa.out:compile_macro_test.c
gcc $< -o $@
b.out:compile_macro_test.c
gcc -DDBUG $< -o $@
.PHOHY:clean
clean:
rm *.out
运行make后得到的a.out输出为=========0
运行make debug后得到的a.out输出为=========5