3

Specifically, I want to do something along the following lines. For a Makefile.am script that defines how a library file should be built, I want to be able to access a common library name throughout. For example, assuming I want the name of the library to be called 'name', I might start with the following variable:

LIBNAME = name

Then I might have something like this:

lib_LTLIBRARIES = lib$(LIBNAME).la

But then automake starts to complain when I want to do something like the following:

lib$(LIBNAME)_la_SOURCES = file1.cpp file2.cpp
lib$(LIBNAME)_la_LIBADD = ...

Is anything like this possible using some other syntax so that I don't have to multiply repeat the name of the library?

Cheers,

Ben.

Ben J
  • 1,367
  • 2
  • 15
  • 33
  • Are you hoping to give the user the ability to change the name of the installed library, or merely to reduce repetition in the Makefile.am? – William Pursell Jan 27 '13 at 13:51
  • I simply wish to reduce repetition. I have lots of Makefile.am files scattered around and I'm trying to figure out ways to make them all as generic as possible. – Ben J Jan 27 '13 at 16:31

2 Answers2

4

You can do it if you define your variable at configure time instead of in the Makefile itself.

For example, in configure.ac:

LIBNAME=name
AC_SUBST(LIBNAME)

Then you can access it in Makefile.am like this:

lib_LTLIBRARIES = lib@LIBNAME@.la
ptomato
  • 56,175
  • 13
  • 112
  • 165
  • @WilliamPursell even if you create your makefiles with text substitutions like `lib@LIBNAME@.la`? – ptomato Jan 27 '13 at 13:44
  • This solution cannot work! Automake needs the name of the primary when it parses Makefile.am, so a configure time substitution won't solve anything. – William Pursell Jan 27 '13 at 13:48
  • It seems to work just fine here: https://github.com/ptomato/osxcart/blob/gtk3/osxcart/Makefile.am (which I copied from another library, I forget where) – ptomato Jan 27 '13 at 17:14
  • This is really slick. I am surprised that automake allows `@` characters in the name, and looking through the automake mailing list archive I haven't yet found a discussion on whether this was intentional, but it is certainly a nice feature. It's truly a shame that I have but one upvote to give. – William Pursell Jan 29 '13 at 16:15
  • However, I would recommend `AC_SUBST([LIBNAME],[${LIBNAME:-defaultname}])` – William Pursell Jan 29 '13 at 16:16
0

Then I might have something like this:

LIBNAME = name
lib_LTLIBRARIES = lib$(LIBNAME).la
lib$(LIBNAME)_la_SOURCES = file1.cpp file2.cpp
lib$(LIBNAME)_la_LIBADD = ...

IFAIK, this will not work with automake. I don't think it's possible to do it using some other syntax, either.

ldav1s
  • 15,885
  • 2
  • 53
  • 56