Kconfig,宏和未定义的宏警告

时间:2014-06-04 00:59:00

标签: c linux-kernel kbuild

我正在为Linux内核中的Kconfig添加多选样式配置。根据用户的选择,它定义了一个宏。配置完成后,内核驱动程序源代码会有#ifdef块,它会检查并使用宏进行编译。

在Kconfig中看起来像这样:

choice RTC_DRV_TWL4030_CHARGE_RATE
   prompt "RTC Backup Battery Charge Rate"
   depends on RTC_DRV_TWL4030
   default RTC_DRV_TWL4030_RATE_25UA
   config RTC_DRV_TWL4030_RATE_25UA
           bool "25uA"
   config RTC_DRV_TWL4030_RATE_150UA
           bool "150uA"
   config RTC_DRV_TWL4030_RATE_500UA
           bool "500uA"
   config RTC_DRV_TWL4030_RATE_1MA
           bool "1MA"
endchoice

在驱动程序源代码中:

#ifdef RTC_DRV_TWL4030_RATE_25UA
                BIT_PM_RECEIVER_BB_CFG_BBISEL_25UA,
#elif RTC_DRV_TWL4030_RATE_150UA
               BIT_PM_RECEIVER_BB_CFG_BBISEL_150UA,
#elif RTC_DRV_TWL4030_RATE_500UA
               BIT_PM_RECEIVER_BB_CFG_BBISEL_500UA,
#elif RTC_DRV_TWL4030_RATE_1MA
               BIT_PM_RECEIVER_BB_CFG_BBISEL_1MA,
#else
               BIT_PM_RECEIVER_BB_CFG_BBISEL_25UA,
#endif

这感觉还可以。但问题是在编译时我收到警告:

drivers/rtc/rtc-twl.c:549:7: warning: "RTC_DRV_TWL4030_RATE_150UA" is not defined [-Wundef]
    drivers/rtc/rtc-twl.c:551:7: warning: "RTC_DRV_TWL4030_RATE_500UA" is not defined [-Wundef]
    drivers/rtc/rtc-twl.c:553:7: warning: "RTC_DRV_TWL4030_RATE_1MA" is not defined [-Wundef]

这是我在内核编译过程中看到的唯一警告。所以它必须意味着我做错了。任何指针将不胜感激!

1 个答案:

答案 0 :(得分:0)

我没有正确使用预处理器。我没有这样的警告:

#if defined(CONFIG_RTC_DRV_TWL4030_RATE_0A)
                BIT_PM_RECEIVER_BB_CFG_BBISEL,
#elif defined(CONFIG_RTC_DRV_TWL4030_RATE_25UA)
                BIT_PM_RECEIVER_BB_CFG_BBISEL_25UA,
#elif defined(CONFIG_RTC_DRV_TWL4030_RATE_150UA)
                BIT_PM_RECEIVER_BB_CFG_BBISEL_150UA,
#elif defined(CONFIG_RTC_DRV_TWL4030_RATE_500UA)
                BIT_PM_RECEIVER_BB_CFG_BBISEL_500UA,
#elif defined(CONFIG_RTC_DRV_TWL4030_RATE_1MA)
                BIT_PM_RECEIVER_BB_CFG_BBISEL_1MA,
#else
                BIT_PM_RECEIVER_BB_CFG_BBISEL_25UA,
#endif