Makefile 条件 OR 定义

发布于 2025-01-12 02:00:06 字数 278 浏览 4 评论 0原文

我有一个带有 2 个 ifdef 条件的 Makefile,当选择该特定配置时,它们执行相同的操作。

     #ifdef A
     //perform C
     #endif /* A */

     #ifdef B
     //perform C
     #endif /* B */

     #ifdef A || B
     //perform C
     #endif

最后一个代码块不起作用。在 Makefile 中执行它的正确方法是什么?

I have a Makefile with 2 ifdef conditions that perform same action when that particular config is selected.

     #ifdef A
     //perform C
     #endif /* A */

     #ifdef B
     //perform C
     #endif /* B */

     #ifdef A || B
     //perform C
     #endif

Last code block is not working. What is the right way to execute it in Makefile?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

得不到的就毁灭 2025-01-19 02:00:06

#ifdef#endif 不是 make 条件。您可能想要:

ifdef A
# whatever if make variable A is defined
AB := defined
endif

ifdef B
# whatever if make variable B is defined
AB := defined
endif

ifeq ($(AB),defined)
# whatever if the make variable A or B is defined
endif

请注意,ifdef Aifneq ($(A),) 不同。因此,如果您想测试这些变量不是为了定义而是为了空性,您可能需要:

ifneq ($(A),)
# whatever if the value of make variable A is non-empty
endif

ifneq ($(B),)
# whatever if the value of make variable B is non-empty
endif

ifneq ($(A)$(B),)
# whatever if the value of make variable A or B is non-empty
endif

#ifdef and #endif are not make conditionals. You probably want:

ifdef A
# whatever if make variable A is defined
AB := defined
endif

ifdef B
# whatever if make variable B is defined
AB := defined
endif

ifeq ($(AB),defined)
# whatever if the make variable A or B is defined
endif

Note that ifdef A is not the same as ifneq ($(A),). So, if you want to test these variables not for definition but for emptiness, you probably want:

ifneq ($(A),)
# whatever if the value of make variable A is non-empty
endif

ifneq ($(B),)
# whatever if the value of make variable B is non-empty
endif

ifneq ($(A)$(B),)
# whatever if the value of make variable A or B is non-empty
endif
逆流 2025-01-19 02:00:06

这是使用我在评论中提出的技术变体的一种方法:

# De Morgan's Law: (!a && !b) == !(a || b)
ifndef A
  ifndef B
    NEITHER_A_NOR_B_DEFINED :=
  endif
endif

ifndef NEITHER_A_NOR_B_DEFINED
  # Perform C
endif

Here's one way to do it using a variant of the technique I proposed in a comment:

# De Morgan's Law: (!a && !b) == !(a || b)
ifndef A
  ifndef B
    NEITHER_A_NOR_B_DEFINED :=
  endif
endif

ifndef NEITHER_A_NOR_B_DEFINED
  # Perform C
endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文