Check whether a macro is undefined or has a specific value

Marco listaddr at
Tue Aug 16 16:26:49 UTC 2011

2011/8/16 Daniel Neuberger <daniel.neuberger at>:
> On 08/16/2011 07:22 AM, Marco wrote:
>> as the subject says: If macro %{__foo} is defined and has value 1, I'd
>> like to do something; otherwise (undefined or value != 1), skip.
> See the section about defining conditional macros:
> Here's an example that's similar to what you're talking about:
> %define  _default_release 1
> %define  _release
> %{!?_svn_last_rev:%{_default_release}}%{?_svn_last_rev:%{_svn_last_rev}}
> I only know how to check for definition, not equality, but it shouldn't be
> too hard to make that work for you.

Thanks. I don't need to define another macro based on the value of
%{__foo}. However based on your suggestion, I think I can do this,
which seems to work:

%if %{?__foo:1}%{!?__foo:0}
%if "%{__foo}" == "1"
  echo "foo is defined and is 1"
  echo "foo is defined, but has some other value: %{__foo}"
  echo "foo is not defined"

Does this look correct/reliable enough or is there a better way to do
what I'm trying to do? Thanks.

More information about the Rpm-list mailing list