I'm working on a small library that uses a very simple makefile (no autoconf, etc.) and it sets the library name and soname within the makefile.
Instead of hard coding it in the spec file I would like to extract the library name and soname from the makefile.
I tried "grep soname Makefile | awk..." type approach which works for the soname but the library name is generated from the soname with a variable and I haven't found a way to get an "evaluated" version of the makefile.
I was hoping something like "make -p ..." would work but it doesn't evaluated the variables, which seems useless since if I just wanted the raw output 'cat' would work.
One method I've found (but not tried) would be to use sed to insert an "export" in front of the two assignments so I can use the environment variables.
Any ideas?
Thanks, Richard
On Tue, Aug 16, 2011 at 9:18 AM, Richard Shaw hobbes1069@gmail.com wrote:
I'm working on a small library that uses a very simple makefile (no autoconf, etc.) and it sets the library name and soname within the makefile.
Instead of hard coding it in the spec file I would like to extract the library name and soname from the makefile.
I tried "grep soname Makefile | awk..." type approach which works for the soname but the library name is generated from the soname with a variable and I haven't found a way to get an "evaluated" version of the makefile.
How about make -n some-target, where some-target emits on stdout what you need?
Richard Shaw hobbes1069@gmail.com writes:
I was hoping something like "make -p ..." would work but it doesn't evaluated the variables, which seems useless since if I just wanted the raw output 'cat' would work.
$ make -f Makefile -f - <<<'echo-foo:; @echo $(foo)' echo-foo
Andreas.
On Tue, Aug 16, 2011 at 8:24 AM, Andreas Schwab schwab@redhat.com wrote:
Richard Shaw hobbes1069@gmail.com writes:
I was hoping something like "make -p ..." would work but it doesn't evaluate the variables, which seems useless since if I just wanted the raw output 'cat' would work.
$ make -f Makefile -f - <<<'echo-foo:; @echo $(foo)' echo-foo
Not only is it a obfuscation contest winner, but it worked!
Thanks, Richard
On Tue, 16 Aug 2011 08:18:54 -0500, RS (Richard) wrote:
I'm working on a small library that uses a very simple makefile (no autoconf, etc.) and it sets the library name and soname within the makefile.
Instead of hard coding it in the spec file I would like to extract the library name and soname from the makefile.
Why? Doesn't the makefile install the library correctly? Or perhaps you only need to run "ldconfig -n ..." to add missing symlinks?
One reason why I ask these questions is that several packagers prefer hardcoded sonames in spec files, so they won't build soname bumps accidentally. For hardcoded sonames in spec files, the build would fail as an early-warning system.
On Tue, Aug 16, 2011 at 10:05 AM, Michael Schwendt mschwendt@gmail.com wrote:
On Tue, 16 Aug 2011 08:18:54 -0500, RS (Richard) wrote:
I'm working on a small library that uses a very simple makefile (no autoconf, etc.) and it sets the library name and soname within the makefile.
Instead of hard coding it in the spec file I would like to extract the library name and soname from the makefile.
Why? Doesn't the makefile install the library correctly? Or perhaps you only need to run "ldconfig -n ..." to add missing symlinks?
Never used that before. I'll give it a shot.
One reason why I ask these questions is that several packagers prefer hardcoded sonames in spec files, so they won't build soname bumps accidentally. For hardcoded sonames in spec files, the build would fail as an early-warning system.
I can see the logic in that, but in this case the library in question has a VERY small target audience and if there was a breakage it would not be a show stopper.
Thanks, Richard
On Tue, Aug 16, 2011 at 10:10 AM, Richard Shaw hobbes1069@gmail.com wrote:
On Tue, Aug 16, 2011 at 10:05 AM, Michael Schwendt mschwendt@gmail.com wrote:
Or perhaps you only need to run "ldconfig -n ..." to add missing symlinks?
Gave it a shot. It does create the soname symlink but does not create a plain .so symlink for the -devel sub-package, so I still have to create that manually.
Thanks! Richard
On Tue, 16 Aug 2011 10:16:59 -0500, RS (Richard) wrote:
Or perhaps you only need to run "ldconfig -n ..." to add missing symlinks?
Gave it a shot. It does create the soname symlink but does not create a plain .so symlink for the -devel sub-package, so I still have to create that manually.
cd %{buildroot}%{libdir} ldconfig -n $(pwd) ln -s %{name}.so.? %{name}.so cd -
On Tue, Aug 16, 2011 at 10:31 AM, Michael Schwendt mschwendt@gmail.com wrote:
On Tue, 16 Aug 2011 10:16:59 -0500, RS (Richard) wrote:
Or perhaps you only need to run "ldconfig -n ..." to add missing symlinks?
Gave it a shot. It does create the soname symlink but does not create a plain .so symlink for the -devel sub-package, so I still have to create that manually.
cd %{buildroot}%{libdir} ldconfig -n $(pwd) ln -s %{name}.so.? %{name}.so cd -
Wouldn't that create a symlink of a symlink?
I ended up doing it this way:
# Extract library name from Makefile LIBNAME=$(make -f Makefile -f - <<<'lib_so:; @echo $(lib_so)' lib_so)
# Create symbolic link for -devel subpackage. ldconfig -n %{buildroot}%{_libdir} pushd %{buildroot}%{_libdir} ln -s $LIBNAME %{name}.so popd
Thanks, Richard
On Tue, 16 Aug 2011 10:38:43 -0500, RS (Richard) wrote:
cd %{buildroot}%{libdir} ldconfig -n $(pwd) ln -s %{name}.so.? %{name}.so cd -
Wouldn't that create a symlink of a symlink?
That isn't a problem, is it? All that matters is that the final symlink would point at a usable library the build-time linker can load
libfoo.so -> libfoo.so.1 > libfoo.so.1.0.0
and ldconfig adjusts libfoo.so.1 to point at the latest version anyway. Or just the direct:
libfoo.so -> libfoo.so.1.0.0
Both types of symlinks exist in Fedora packages. You could
shopt -s failglob ln -s %{name}.so.*.* %{name}.so
enforcing existence of a fully versioned library, and else an error. All that matters is that the final symlink would point at a usable library.
I ended up doing it this way:
# Extract library name from Makefile LIBNAME=$(make -f Makefile -f - <<<'lib_so:; @echo $(lib_so)' lib_so)
# Create symbolic link for -devel subpackage. ldconfig -n %{buildroot}%{_libdir} pushd %{buildroot}%{_libdir} ln -s $LIBNAME %{name}.so popd
Enjoy it if it works for you. :) Note though that if the make command fails, you would end up with an empty $LIBNAME and a %{name}.so -> %{name}.so most likely, so some guard in the spec file would be beneficial.
On Tue, Aug 16, 2011 at 11:27 AM, Michael Schwendt mschwendt@gmail.com wrote:
On Tue, 16 Aug 2011 10:38:43 -0500, RS (Richard) wrote:
cd %{buildroot}%{libdir} ldconfig -n $(pwd) ln -s %{name}.so.? %{name}.so cd -
Wouldn't that create a symlink of a symlink?
That isn't a problem, is it? All that matters is that the final symlink would point at a usable library the build-time linker can load
No, not a technical problem. Just inelegant :)
Both types of symlinks exist in Fedora packages. You could
shopt -s failglob ln -s %{name}.so.*.* %{name}.so
enforcing existence of a fully versioned library, and else an error. All that matters is that the final symlink would point at a usable library.
Interesting, I've never messed with shopt before.
[snip]
Enjoy it if it works for you. :) Note though that if the make command fails, you would end up with an empty $LIBNAME and a %{name}.so -> %{name}.so most likely, so some guard in the spec file would be beneficial.
I wanted a bit more informative error in case of failure and tried this:
# Extract library name from makefile LIBNAME=$(make -f Makefile -f - <<<'lib_so:; @echo $(lib_so)' lib_so) # Make sure LIBNAME is set and not null : ${LIBNAME:?"LIBNAME variable could not be set."}
# Create symbolic link for -devel subpackage. ldconfig -n %{buildroot}%{_libdir} pushd %{buildroot}%{_libdir} ln -s $LIBNAME %{name}.so popd
Thanks, Richard
On Tue, Aug 16, 2011 at 03:29:31PM -0500, Richard Shaw wrote:
On Tue, Aug 16, 2011 at 11:27 AM, Michael Schwendt mschwendt@gmail.com wrote:
On Tue, 16 Aug 2011 10:38:43 -0500, RS (Richard) wrote:
cd %{buildroot}%{libdir} ldconfig -n $(pwd) ln -s %{name}.so.? %{name}.so cd -
Wouldn't that create a symlink of a symlink?
That isn't a problem, is it? All that matters is that the final symlink would point at a usable library the build-time linker can load
No, not a technical problem. Just inelegant :)
If this really bothers you, you can use
ln -s `readlink %{name}.so.?` %{name}.so
D.