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.

1 Answer 1

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 $< > $@ 
3
  • 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, 2014 at 21:42
  • No, not really. They are both in the list of usual tools. 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, 2014 at 15:53
  • 1
    Fair point - I guess I should have use $(libdir) instead of of $(prefix)/lib.
    – jprice
    May 23, 2014 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.