在 ifdef 内有条件地定义 m4 中的宏
这是我第一次使用 m4
,并且我很难根据是否已定义另一个宏来有条件地定义宏。
我面临的问题是我的 test.m4 文件中的以下代码片段:
ifdef(`MANPAGE', define(_NAME, `NAME'), define(_NAME, `Name'))
_NAME
作为 C 中的类比,我想要实现的目标是这样的:
#ifdef MANPAGE
#define _NAME "NAME"
#else
#define _NAME "Name"
#endif
现在,当我运行 m4 -DMANPAGE test.m4
,我得到输出 Name,而我期望输出为 NAME。无论是否指定 -DMANPAGE
,我总是会得到输出Name。
我不确定我哪里出了问题,即使参考了 m4 手册页和其他在线文章,我也无法找到解决方案。在 StackOverflow 上,我确实参考了以下似乎有一定影响的帖子: M4 中的 ifdef 进行三重条件检查 和 m4 ifdef 语句中的转义逗号。
然而,我仍然没有取得任何进展。任何指示将不胜感激。
提前致谢!
This is the first time I'm using m4
, and I'm having difficulty in defining a macro conditionally based on whether or not another macro is already defined.
The problem I'm facing is with the following snippet in my test.m4 file:
ifdef(`MANPAGE', define(_NAME, `NAME'), define(_NAME, `Name'))
_NAME
As an analogy in C, what I'm trying to achieve is something like this:
#ifdef MANPAGE
#define _NAME "NAME"
#else
#define _NAME "Name"
#endif
Now, when I run m4 -DMANPAGE test.m4
, I get the output Name, whereas I expect the output to be NAME. Whether or not -DMANPAGE
is specified, I always get the output Name.
I am uncertain where I'm going wrong, and I was unable to find a solution even after referring to the m4 man pages and other online articles. On StackOverflow, I did refer to the following posts which seemed to have some bearing:
Triple conditional check with ifdef in M4 and
Escaping Commas in m4 ifdef Statements.
However, I still haven't made any headway. Any pointers would be much appreciated.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
我相信参数在传递给
ifdef
之前会被扩展Try this:
I believe the parameters get expanded before passing to
ifdef