I have a spec file where its Requires: fields depend on the specific distribution it's being built on. So I need to be able to create a conditional structure along the lines of:

%if %{?fedora}
Requires:       xterm libssh clang
BuildRequires:  wxGTK3-devel  cmake clang-devel lldb-devel libssh-devel hunspell-devel sqlite-devel desktop-file-utils
%if (centos test)
Requires:       xterm libssh clang
BuildRequires:  wxGTK3-devel cmake clang-devel lldb-devel libssh-devel hunspell-devel

where (centos test) is to be replaced with some test to see if the distribution we're on is CentOS. I have tried using %{?rhel} and %{?centos} as this test. But both failed. I have also tried the tests %{rhel} and %{centos} but neither worked (as it didn't seem to recognize these macros). I have searched RPM macro references (like https://docs.fedoraproject.org/ro/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch09s07.html and https://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html-single/RPM_Guide/index.html) but neither mention these types of macros.

  • If this functionality does not exists you could always have separate spec files for fedora and centos. Also you could one spec file that produces two RPMs. One for fedora and one for centos. – Red Cricket Dec 31 '16 at 5:30
  • This is being built on the Open Build Service so to my knowledge that won't be possible. – BH2017 Dec 31 '16 at 6:05
  • Pardon my ignorance but what is Open Build Service (OBS)? And what is "that"? 1) The functionality doesn't exists 2) OBS does not support multiple spec files 3) OBS does not support spec files that generate multiple RPMs? :) – Red Cricket Dec 31 '16 at 6:45
  • 1
    I don't think the OBS supports multiple spec files. The OBS is build.opensuse.org, it's a service that openSUSE provides that can build your own custom packages and place them in repositories for free. It can be used to build Arch Linux, CentOS, Debian, Fedora, Mandriva, openSUSE, RHEL, Scientific Linux, SUSE Linux Enterprise Server (SLES) and Ubuntu packages. – BH2017 Dec 31 '16 at 6:51
  • You're asking the wrong question. What determines the dependencies is not Fedora vs CentOS, but particular releases of each distribution. The question is how to make build dependencies that work across a range of Fedora releases. – Gilles 'SO- stop being evil' Dec 31 '16 at 20:21

Quoting from https://fedoraproject.org/wiki/Packaging:DistTag#Conditionals :

Keep in mind that if you are checking for a specific family of distributions, that you need to use:

%if 0%{?rhel}

and NOT

%if %{?rhel}

Without the extra 0, if %{rhel} is undefined, the %if conditional will cease to exist, and the rpm will fail to build.

And similary you need to use 0%{?fedora} in the first condition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.