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


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


...

...

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

...

...

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

make OEM=IBM

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


#ifdef IBM
	dprintf("\n Welcome to YuDuan's world! %s, at %s.\n\n", ver, date);
#endif
#ifdef GOOGLE
	dprintf("\n Welcome to DATANG's world! %s, at %s.\n\n", ver, date);
#endif
#ifdef SHIT
	dprintf("\n Welcome to CNCR's world! %s, at %s.\n\n", ver, date);
#endif

 就OK了。 


Logo

更多推荐