new RPM macro to control runpaths

Björn Persson bjorn at xn--rombobjrn-67a.se
Fri Sep 7 18:26:51 UTC 2012


The RPM macros Gnatmake_optflags and GPRbuild_optflags have so far included a 
hard-coded -R, telling Gnatmake and GPRbuild that they should not add a 
runpath to the binaries they build. (It doesn't work in all cases, but that's 
a bug in Gnatmake that should be fixed.) Normally we don't want runpaths in 
Fedora packages. There are however cases where it would be advantageous to 
allow a runpath. Library packages can have test suits or auxiliary programs 
that run during the build and need to link to the library in the build 
directory, and they may rely on the automatic runpath for this. We saw an 
example of this in Templates Parser, where LD_LIBRARY_PATH had to be used in 
the spec to compensate for the lack of a runpath.

I've found a way to allow a spec file to enable the runpath when needed while 
keeping it disabled by default. I've changed the macros so that -R is not 
included if there is a macro named GNAT_add_rpath. By default there is no such 
macro, so -R is passed to the builder and nothing changes from the current 
state, but a spec file that needs a runpath can define GNAT_add_rpath, allowing 
the GNAT tools to add their computed runpath to the binaries.

The -R flag is omitted only where Gnatmake_optflags or GPRbuild_optflags is 
expanded below the point where GNAT_add_rpath is defined. Undefining 
GNAT_add_rpath restores the default so that -R is again used in macro 
expansions below that point. It can even be defined and undefined several times 
within a spec file if a runpath needs to be added in some builder invocations 
and not in others.

Here's an example of how GNAT_add_rpath can be used in templates_parser.spec:

%build
make %{?_smp_mflags} VERSION=%{version} GNATMAKE_OPTFLAGS="%{Gnatmake_optflags}"
# doc build wants to link to library
%global GNAT_add_rpath yes
make doc GNATMAKE_OPTFLAGS="%{Gnatmake_optflags}"

First the library itself is built without a runpath (would be, if Gnatmake 
didn't have that bug). Then GNAT_add_rpath is defined before the documentation 
is built, so when a number of programs are built and run as a part of the 
documentation build, they have a runpath and can therefore link to the 
library. This is cleaner than using LD_LIBRARY_PATH as the spec file becomes 
less dependent on the internal structure of the source tree.

This feture is coming to Fedora 17, 18 and Rawhide in fedora-gnat-project-
common-3.5-1. Adding it to Fedora 16 would be a little more work, but I can 
get it in there too if there is a need for it.

Björn



More information about the Ada mailing list