工作点滴(—)在CFLAGS中添加自定义宏

来源:互联网 发布:网络诈骗的表现形式有 编辑:程序博客网 时间:2024/06/17 22:21

背景:linux嵌入式开发中,有时候比如网页或者后台程序中需要根据客户的需求定义不同的版本。


实现方法:可以在Makefile中的CFLAGS参数后面添加自定义宏,比如


...

...

CFLAGS +=-g -Wall -D$(OEM)

...

...

其中OEM参数就是你在make的时候传进去的参数,like:

make OEM=IBM

这样在你的代码中就可以根据定义的OEM宏进行定义一些变量或者实现一些函数,比如:


#ifdef IBMdprintf("\n Welcome to YuDuan's world! %s, at %s.\n\n", ver, date);#endif#ifdef GOOGLEdprintf("\n Welcome to DATANG's world! %s, at %s.\n\n", ver, date);#endif#ifdef SHITdprintf("\n Welcome to CNCR's world! %s, at %s.\n\n", ver, date);#endif

就OK了。

原创粉丝点击