‘0’ 在 rpm 条件宏中的含义是什么?

huangapple go评论101阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月9日 02:30:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390258.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定