英文:
what is the '0' meaning in rpm conditional macros
问题
-
例1
当阅读一些rpmbuild规范文件时,我遇到一些让我困惑的条件宏。 ```%if 0%{?rhel} > 7 blah blah %endif我明白上面的块尝试检查红帽企业Linux的版本是否大于7,然后执行blah blah。但是'0'的用途是什么?
-
例2
当阅读一些rpmbuild规范文件时,我遇到一些让我困惑的条件宏。 ```%if 0%{!?pkg_name:1} %define pkg_name foo %endif我明白上面的块尝试检查pkg_name是否未定义,然后将其定义为foo的值。但是'0'的用途是什么?
英文:
When reading some rpmbuild spec files, I come across some of the conditional macros which puzzle me.
-
example1
%if 0%{?rhel} > 7 blah blah %endif # I understand the above block tries to check if the # red hat enterprise linux version is above 7, then blah blah # But what is the usage of the '0'? -
example 2
%if 0%{!?pkg_name:1} %define pkg_name foo %endif # I understand the above block tries to check if the pkg_name # is not defined, then define it with the value foo. # But what is the usage of the '0'?
My guess is that '0' indicates the next expression to be either 'nil' or a number so that rpm would consider them as a number (such as 06, 0, or 01 in above examples) instead of a string or empty string. But I am not sure about it.
Unfortunatly, most of the online tutorial materials did not cover this topic.
答案1
得分: 1
你说得对,这是一个保护措施。%{?rhel} 表示“如果存在,则用 rhel 宏替换,如果不存在也可以(?)。”
因此,如果 rpmbuild 用空值替换它,生成的 if > 7 将出错。
英文:
You got it right; it's a safeguard. The %{?rhel} says "replace with the rhel macro if it exists and it is OK if it does not (the ?)."
So, if rpmbuild replaced it with nothing, the resulting if > 7 would barf.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论