CentOS 7 and the incorrect dist RPM macro

When creating RPM packages recently, I had the effect that package names on CentOS 7 were set incorrectly. For example, a package had the name pinkepank-0.6-1.el7.centos.x86_64.rpm but should have set pinkepank-0.6-1.el7.x86_64.rpm instead. As Enterprise Linux derivates (CentOS, Scientific Linux,…) offer binary compatibility to Red Hat Enterprise Linux, I prefer omitting distribution-specific tags in package names.

In the RPM spec file package name, version and release are set like this:

Name: interceptty
Version: 0.6
Release: 1%{?dist}

The variable dist is replaced by the major release on Enterprise Linux derivates – e.g. el7 for Enterprise Linux 7. So, no centos is set here. After a long time, I discovered that the macro dist is defined in the /etc/rpm/macros.dist file – e.g. under EL6:

el6$ grep dist /etc/rpm/macros.dist
# dist macros.
%dist .el6

Under CentOS 7 the file looks like this:

el7$ grep dist /etc/rpm/macros.dist
# dist macros.
%dist .el7.centos

On a Red Hat Enterprise Linux 7 system the affected line looks liks this:

%dist .el7

I changed the line and rebuild some packages inside a virtual machine – after changing the line, package names were correct again.

As I’m using Docker containers for creating RPM packages, I added the following line to the appropriate Dockerfile:

#Fix broken RPM macro
RUN sed -i "s/.el7.centos/.el7/g" /etc/rpm/macros.dist

When creating the image, the file mentioned above is changed. This can be checked by executing the following command:

# docker run rpmdevel-centos7:latest cat /etc/rpm/macros.dist|grep dist
# dist macros.
%dist .el7

Unfortunately, the issue wasn’t resolved – package names were still incorrect. Adding the following lines to the RPM spec file did the trick:

%if 0%{?rhel} == 7
 %define dist .el7
%endif

These lines manually set the dist variable to the value .el7 if an Enterprise Linux 7 environment was detected. It is important the these lines are pasted before the release definition – otherwise this override won’t work:

%if 0%{?rhel} == 7
 %define dist .el7
%endif

Name:    pinkepank
Version: 0.6
Release: 1%{?dist}

The following example is incorrect:

Name:    pinkepank
Version: 0.6
Release: 1%{?dist}

%if 0%{?rhel} == 7
 %define dist .el7
%endif

In this case, the package name would still be pinkepank-0.6-1.el7.centos.x86_64.rpm instead of pinkepank-0.6-1.el7.x86_64.rpm.

2 comments Write a comment

  1. Hi Christian,

    Thanks for your blog, but the solution for this problem it’s very easy, create de .rpmmacros file, (in the $HOME of user who run rpmbuild), with the var %dist .el7 inside.

    like a charm 😉

    • Hey norishen!
      Thanks for the feedback! I was trying this back then in CentOS 7 and it didn’t work for me. Which CentOS version were you using?

      Best wishes,
      Christian!

Leave a Reply