4

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.

Xin Cheng
  • 1,432
  • 10
  • 17

1 Answers1

1

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.

Aaron D. Marasco
  • 6,506
  • 3
  • 26
  • 39