How do I access a user defined variable as defined at the top of a Makefile.am file?

萝らか妹 提交于 2019-12-23 20:14:22

问题


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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/14526535/how-do-i-access-a-user-defined-variable-as-defined-at-the-top-of-a-makefile-am-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!