[CentOS] Helper variables like %{rhel} on CentOS

Nico Kadel-Garcia nkadel at gmail.com
Wed Jan 5 00:38:59 UTC 2011


On Tue, Jan 4, 2011 at 12:19 PM, Santi Saez <santisaez at woop.es> wrote:
> El 03/01/2011 20:15, Akemi Yagi escribió:
>> You may want to look into the srpms of nx/freenx in the CentOS extras
>> repository. The spec file contains the following:
>>
>> # centos_ver is a number (2,3,4,5). It can be provided in the build system or
>> # via the command line with the following define for rpmbuild
>> # --define "centos_ver 5"
>> # If centos_ver is not provided the following will find it and should work on
>> # all current redhat based EL rebuilds, will not work properly on FC though
>>
>> %{!?centos_ver: %define centos_ver %(Z=`rpm -q --whatprovides
>> /etc/redhat-release`;A=`rpm -q --qf '%{V}' $Z`; echo ${A:0:1})}
>
> Hi Akemi,
>
> Thanks for the tip :)
>
> If I put Johnny's code in my .rpmmacros it works, but I get this warning:
>
>     error: Macro % has illegal name (%define)
>
> I have solved with this change:
>
> # Helper variable that defines CentOS release number, http://goo.gl/dkGUg
> # This macro is based on Johnny Hughes's freenx.spec, from "extras" repo
> %rhel           %(/bin/rpm -q --qf '%{VERSION}' centos-release)

Hmmm.. You might befit from the portability of this approach

%rhel           0%(/bin/rpm -q --f /etc/redhat-release -qf '%{VERSION}\n' )

Notice that this now works with RHEL and CentOS, and the "\n" keeps
certain programs historically happier with the commands having an EOL.



More information about the CentOS mailing list