起因:阅读linux0.11代码时,发现RAMDISK这个宏定义在makefile中。以前没有接触过这种用法,练习一下。
目的:在Makefile中定义的宏,在C语言代码里面使用。
Makefile的内容:
CC=gcc
RAMDISK = -DRAMDISK=512
all:
$(CC) $(RAMDISK) hello.c
clean:
rm -f a.out
-------------------------------------------------------------------
hell.c
#include <stdio.h>
int main(void)
{
#ifdef RAMDISK
printf("RAMDISK = %d\n", RAMDISK);
#else
printf("NO RAMDISK\n");
#endif
return 0;
}
总结,其实就是给gcc添加参数
Makefile宏定义
原文:http://blog.csdn.net/yinming4u/article/details/42169961