0

I'm trying to define an Automake rule that will generate a text file containing the full path to a libtool library that will be built and installed by the same Makefile. Is there a straightforward way of retrieving the output filename for a libtool library (with the correct extension for the platform the program is being built on)?

For example, I am trying to write something like this:

lib_LTLIBRARIES = libfoo.la

bar.txt:
  echo $(prefix)/lib/$(libfoo_la) >$@ 

Where $(libfoo_la) would expand to libfoo.so, libfoo.dylib or libfoo.dll (or whatever else), depending on the platform. This is essentially the value of the dlname parameter in the resulting libtool library file. I could potentially extract the filename directly from that, but I was hoping there was a simpler way of achieving this.

jprice
  • 9,755
  • 1
  • 28
  • 32

1 Answers1

2

Unfortunately, there's not a way I've found of doing this. Fortunately, for you, I did have a little sed script hacked together that did kind of what you want, and hacked it so it does do what you want.

foo.sed

# kill non-dlname lines
/^\(dlname\|libdir\)=/! { d }

/^dlname=/ {

# kill leading/trailing junk
s/^dlname='//

# kill from the last quote to the end
s/'.*$//

# kill blank lines
/./!d

# write out the lib on its own line
s/.*/\/&\n/g

# kill the EOL
s/\n$//

# hold it
h
}

/^libdir=/ {

# kill leading/trailing junk
s/^libdir='//

# kill from the last quote to the end
s/'.*$//

# paste
G

# kill the EOL
s/\n//
p
}

Makefile.am

lib_LTLIBRARIES = libfoo.la

bar.txt: libfoo.la foo.sed
        sed -n -f foo.sed $< > $@ 
ldav1s
  • 15,885
  • 2
  • 53
  • 56
  • Is the presence of `sed` more reliable than the presence of `grep` and `awk`? I am currently just using this: `$(GREP) dlname $< | $(AWK) -F "'" '{print $$2}' >$@`, which also achieves the desired effect. – jprice May 22 '14 at 21:42
  • No, not really. They are both in the list of [usual tools](http://www.gnu.org/software/autoconf/manual/autoconf-2.64/html_node/Limitations-of-Usual-Tools.html). However this way also appends the `libdir` from the .la file which should be the correct path where the lib is installed. I noticed on your rule to build `bar.txt` that you are writing `$(prefix)/lib/libfoo.` _extension_ into `bar.txt`. This won't be correct all the time (e.g. on 64-bit platforms `$(prefix)/lib64/libfoo.` _extension_). – ldav1s May 23 '14 at 15:53
  • 1
    Fair point - I guess I should have use `$(libdir)` instead of of `$(prefix)/lib`. – jprice May 23 '14 at 16:01