24

I'm attempting to use the %{dist} tag in my RPM spec file to provide distribution-specific dependencies between Fedora Core (e.g. fc12), CentOS 5 (e.g. el5) and Amazon's Linux AMI:

Release: %_svn_revision%{?dist}

and

# Depencencies
%{?rhel:Requires: ...}
%{?fedora:Requires: ...}

Unfortunately, %{dist} doesn't appear to be defined in CentOS 5.5, and I haven't found a distribution-specific conditional that matches CentOS 5.5 (I thought el5 would match, but doesn't appear to). This ticket reported the missing %{dist} in CentOS in 2008, but hasn't been updated since 2009.

How can I get %{dist} defined in CentOS and what conditional should I use to match CentOS 5? Can any RPM gurus point me in the right direction?

Barry Wark
  • 107,306
  • 24
  • 181
  • 206

2 Answers2

36

The dist macros isn't defined on CentOS 5 because it isn't in /etc/rpm/macros.disttag - there is a RPM named buildsys-macros-rhel that provides it, or buildsys-macros on fedora, but for some reason it is not repackaged by Centos.

Option 1) Download and install fedora build-macros from here

Option 2) invoke rpmbuild --define 'dist .el5' every time

Option 3) Manually edit /etc/rpm/macros.disttag to add macro definitions for rhel (5) and dist (.el5).

You can then use conditionals like this in your spec file:

%if 0%{?rhel}  == 5
%{Requires: foo}
%endif 
ggiroux
  • 6,544
  • 1
  • 22
  • 23
  • build-macros for el5 did the trick. Thank you for a great answer. – Barry Wark Apr 01 '11 at 02:59
  • Note that as of CentOS 5.7, `buildsys-macros` is available in the distribution. See [Redhat Advisory](http://rhn.redhat.com/errata/RHEA-2011-0985.html) as well as [Redhat Bug 613985](https://bugzilla.redhat.com/show_bug.cgi?id=613985) – Daniel Wille Sep 11 '13 at 21:53
5

Another option is to call the script within your own macro in the spec file:

%define distribution        %(/usr/lib/rpm/redhat/dist.sh --distnum)

which calls a script which is part of the config rpm (redhat-rpm-config). You can also insure that this script is there by including:

BuildRequires:              redhat-rpm-config

and then do the same conditional as ggiroux has defined:

%if %{distribution} == 5
    Requires:                   glibc.i686, libXext.i386, libXtst.i386
%else
    Requires:                   glibc.i686, libXext.i686, libXtst.i686
%endif
hughmcmanus
  • 301
  • 2
  • 5