3

我在我的 autotools 存储库中有一个子包设置,其中几个相关项目使用主 configure.ac 和 Makefile.am 粘合在一起。

除了通过 AC_CONFIG_SUBDIRS() 宏轻松完成的编译顺序之外,还需要导出这些过度耦合的子项目之间所需的头文件和库位置。

--- configure.ac
 |- Makefile.am
 |- subproj1 --- configure.ac
 |            |- Makefile.am
 |            |- src
 |            \- include
 [...]
 |
 \- subprojN --- configure.ac // requires -I${top_srcdir}/subprojX/include and
              |- Makefile.am  // -L${top_srcdir}/subprojX/src
              |- src
              \- include

不幸的是,将这些包重新组合为一个不是一种选择。我尝试使用 AC_SUBST() 和/或 make 的导出命令导出变量,但无济于事。

我可以将这些标志用于每个子项目 Makefile 的唯一方法是将 CPPFLAGS 和 LDFLAGS 传递到根配置调用(通过命令行)。但是,我希望是否有办法将这些值保留在 autotools 中,而不必为它们创建单独的脚本。

PS:类似于automake和项目依赖

4

2 回答 2

2

autotools 并不是真正设计为包管理系统,所以这是一个尴尬的用法,但可以在子项目中引用构建树之外的相对路径。换句话说,在 subprojN/Makefile.am 中,您可以添加:

AM_CPPFLAGS = -I$(srcdir)/../subprojX/include
AM_LDFLAGS = -L$(srcdir)/../subprojX/lib

在这种情况下,如果 subprojN/configure 试图找到 libsubprojX,它将失败,除非您改为添加../subprojX/{include,lib}到 CPPFLAGS 和 LDFLAGS 进行配置,这可以在 configure.ac 中完成:

CPPFLAGS="$CPPFLAGS -I${srcdir}/../subprojX/include
LDFLAGS="$LDFLAGS -L${srcdir}/../subprojX/lib"

如果子项目的配置脚本没有检查耦合子项目中的库,那么在 Makefile.am 中指定 LDADD 以获取必要的库链接可能会更干净。

于 2012-04-25T12:14:05.497 回答
-1

CPPFLAGS and LDFLAGS should almost never be passed directly on the command line (personal opinion) but should be set in a config.site. Simply make the assignments in ${prefix}/share/config.site or in $CONFIG_SITE (ie, in the file $HOME/config.site and set CONFIG_SITE=$HOME/config.site in the environment in which you run configure) and that script will be sourced by all of your configure invocations. I'm not sure exactly what you mean by "keep these values inside autotool stuff", but it strikes me that using a config.site satisfies that. LDFLAGS and CPPFLAGS are the correct mechanism to tell your configure script the non-standard location of libraries, so any solution that does not use those would be outside the normal scope of the autotools. (Of course, the best solution is to install the libraries in a standard location so your toolchain can find them with no extra effort on your part. Perhaps you are using gcc and can set LIBRARY_PATH and CPATH.)

于 2012-04-20T13:43:09.693 回答