Platform Builder: Using Environment Variables to Control Macro Definition

It is not uncommon to need to build the same BSP with different projects, or the same driver under different BSPs.   Often this means needing to build the code in different ways for different needs.  Of course any good C/C++ programmer knows to use macros to control how the code is built, and any good Platform Builder user knows to use environment variables to control the build.

The dilemma is how to tie the environment variables together with the macros.  Unfortunately this is not automatic, you can't check for the environment variables in your C/C++ code.

The solution is to use CDEFINES.  CDEFINES is an environment variable that is used to pass command line arguments to the C compiler.  So that means that we need to set CDEFINES prior to compiling.

CDEFINES can be set in a sources file for a particular folder, or CDEFINES can be set in sources.cmn for an entire tree.  To do this and use the environment variables you will need to check the value of the environment variable, then set CDEFINES as needed.  Example:

!IF "$(MY_ENV_VAR)"=="1" 
CDEFINES=$(CDEFINES) -DMY_DEFINE 
!ENDIF

Which checks to see if MY_ENV_VAR is set to one, then adds the -D flag, which defines a macro, and defines MY_DEFINE.  An important part of this is setting CDEFINES=$(CDEFINES) plus something.  This ensures that in setting CDEFINES that the existing CDEFINES is not deleted.

You can now check to see if MY_DEFINE is defined in your C/C++ code.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值