Psychonaut
Psychonaut

Reputation: 897

RPM spec file condition based on availability of a dependency

I want to create a cross-distribution RPM spec file for an application that bundles a certain library. The application uses this bundled library by default, but also provides a build-time option for using the version of the library installed in the system instead. I want the RPM to link the application to the system library if it is available (since this will make the package smaller, and because the system library gets security patches more frequently than the version bundled with the application) and if not, to fall back to the (default) bundled version. Is there any way of writing a conditional in the spec file that accomplishes this?

For example, I want to do something like

%if available(libfoo-devel >= 1.0)
BuildRequires: libfoo-devel >= 1.0
%endif
 
%prep
cat << EOF > build_config_file
%if available(libfoo-devel >= 1.0)
ac_add_options --with-system-foo
%endif
EOF

Right now I'm using conditionals that check for macros defined by particular versions of OSes that I already know package the correct library, but this is rather brittle and convoluted. (That is, I need to manually check each target distribution to see if it packages the correct version of the library, and then write a condition in the spec file for that distribution; moreover, I need to repeat this process periodically in case the correct version of the library becomes available for a distribution that didn't package it previously.) It would be simpler if I could just test for the availability of the dependency directly.

Upvotes: 2

Views: 1392

Answers (1)

Chris Maes
Chris Maes

Reputation: 37712

You must decide before creating the rpm how you will create it. Compilation happens before the target rpm is created, not upon installation.

As I see it you might consider creating two rpms:

  • one compiled with libfoo-devel
  • one without

I would then suggest a spec file along these lines:

Name: package
...

%package libfoo
Summary:  %{name} build with libfoo
BuildRequires: libfoo-devel >= 1.0
Requires: libfoo >= 1.0

%build
build --without-libfoo --target "${RPM_BUILD_ROOT}/usr/bin/without-libfoo"
build --with-libfoo --target "${RPM_BUILD_ROOT}/usr/bin/with-libfoo"

%install
/usr/bin/without-libfoo

%install libfoo
/usr/bin/with-libfoo

Notes:

  • yes this means compiling twice: once with and once without libfoo
  • building this spec file will create two packages: "package.rpm" and "package-libfoo.rpm"

Upvotes: 1

Related Questions