rpm spec file question

CU

Platinum Member
Aug 14, 2000
2,415
51
91
I would like to have an rpm require different rpms based on some shell commands.
I know you can do this based on distro versions.
if 0%{?fedora} >= 4
Requires: foo
%endif

But, when I try to define my own macro it sets it at build time and not install time.
%define test %(test -e /tmp/test.txt && echo 1 || echo 0)
%if 0%{?test} == 1
Requires: foo
%endif

Is there a way to evaluate the macro later or is it always evaluated when you create the rpm?
 

Fallen Kell

Diamond Member
Oct 9, 1999
6,174
516
126
I believe it is only evaluated at build time. That is why you see different rpm's out there for the different distributions, like:
zenoss-4.1.70-1485.el5.x86_64.rpm
zenoss-4.1.70-1485.el6.x86_64.rpm
zenoss-4.1.70-1485.fc16.x86_64.rpm

etc....
 

CU

Platinum Member
Aug 14, 2000
2,415
51
91
I think you may be right. I just tired it using a distro macro and it sets it based on what distro it is build on not installed on. Really wish there was a way to do this, but it appears I will need two builds and two spec files. Using distro macros or custom macros in this way are useless if you only have one build machine because everything is set based on that machine. You would need to build the rpm on each distro version that you want to make custom changes to. This seems like a short coming of the rpm spec. Although I don't know how other package managers or installers on other OS's handle it either, I would think something else could handle this.
 

mv2devnull

Golden Member
Apr 13, 2010
1,526
160
106
I would assume that rpm does simply read the list of requirements from rpm-package without executing code at that point. One can do 'rpm -Rp foo.rpm', and that does not even install anything.

Think of yum repository too. It has cached metadata from the packages for more efficient dependency retrieval. The repo is maintained in some server; one distro.

Virtualization has made it a bit easier to have N distros for building.