Question about conditionally including files into the %files section

Jim Galarowicz jeg at
Mon Jan 11 15:11:37 UTC 2010


I've been struggling my attempt to conditionally include files into %files section of one of our project spec files.  I 
came across the libvirt spec file which seemed like a great example of what I'd like to do, so I thought I would mimic 
what the developers were doing there.

However, I'm obviously not using the correct syntax and wasn't able to find the specific information on the internet to
figure out what I'm doing wrong.

I'm trying to select files based on whether the system is set up for one of the three performance counter
interfaces. So, I created three defines at the top of the PAPI spec file we are creating. I tried two different versions
of each set of the defines using different syntax but neither version of the syntax appears to work.

%define _have_pfmon_macro %(test -a /usr/lib64/ ||
                             test -a /usr/include/perfmon/perfmon.h)

%define _have_pcl_macro %(test -a /lib/modules/%{os_vers}/source/include/linux/perf_counter.h ||
                           test -a /usr/src/linux-headers-%{os_vers}-generic/include/linux/perf_counter.h ||
                           test -a /lib/modules/%{os_vers}/source/include/linux/perf_event.h ||
                           test -a /usr/src/linux-headers-%{os_vers}-generic/include/linux/perf_event.h )

%define _have_perfctr_macro %(test -a /dev/perfctr)


%define _have_pfmon_macro %(((test -e /usr/lib64/ || test -e /usr/include/perfmon/perfmon.h) && echo 1) ||
echo 0)

%define _have_pcl_macro %(((test -e /lib/modules/%{os_vers}/source/include/linux/perf_counter.h ||
                             test -e /usr/src/linux-headers-%{os_vers}-generic/include/linux/perf_counter.h ||
                             test -e /lib/modules/%{os_vers}/source/include/linux/perf_event.h ||
                             test -e /usr/src/linux-headers-%{os_vers}-generic/include/linux/perf_event.h ) && echo 1) 
|| echo 0)

%define _have_perfctr_macro %((test -e /dev/perfctr && echo 1) || echo 0)

Then I tried to use the above define to set another define with a value of 0 or 1 to use in the %files section. Maybe I
could have used the _have_xxx version in the %files section, but I thought I needed a 0 or 1 value there?

%if 0%{_have_pfmon_macro}
%define _with_pfmon 1
%define _with_pfmon 0

%if 0%{_have_perfctr_macro}
%define _with_perfctr 1
%define _with_perfctr 0

%if 0%{_have_pcl_macro}
%define _with_pcl 1
%define _with_pcl 0

I also tried this during my trial and error extravaganza...

%{?_have_pfmon_macro: %define _with_pfmon 1}
%{?_have_pcl_macro: %define _with_pcl 1}
%{?_have_perfctr_macro: %define _with_perfctr 1}

Then in the %files section I use the _with_xxx settings to selectively include files for packaging.

%if %{_with_pfmon}


%if %{_with_perfctr}

I also tried:

%if 0%{_with_perfctr}

The problem is that all the macros/defines:


become set to 1 even though only one of them should actually be set ( only one of the _have_xxx values should actually
be true ).

I'm obviously doing something wrong.

Any help would be greatly appreciated. I've been doing this on Ubuntu, Fedora, and SLES systems where the rpm versions 
are: 4.7.1 on Ubuntu, 4.7.9 on FC11, and on SLES11.

Thanks much for your time,
Jim G

More information about the Rpm-list mailing list