【问题标题】:Autotools and a nested project project with ordinary MakefileAutotools 和一个带有普通 Makefile 的嵌套项目项目
【发布时间】:2012-08-19 13:04:38
【问题描述】:

这个问题扩展了问题How to handle subprojects with autotools?

所以我有一些带有自己的 Makefile(不是 GNU 自动工具)的项目 模块/libfoo

我添加了 SUBDIRS = include/jsonbox Makefile.am 并且它编译得很好,但前提是我从顶级目录调用 ./configure 和 make。

如果我创建一个子目录,比如 build,然后从中运行 ../configure,我会在 make 过程中遇到错误:

   Making all in modules/libfoo
   /bin/sh: line 17: cd: modules/libfoo: No such file or directory
   make: *** [all-recursive] Error 1

可以处理吗?我需要几个构建目录用于不同的拱门和 CFLAGS。

编辑: 正如docs 中所建议的那样,我在嵌套项目中创建了一个 GNUmakefile.in。但它仍然不适用于 VPATH:

Making all in modules/libfoo
make[1]: Entering directory `/home/galadog/test/build/moudles/libfoo'
GNUmakefile:2: Makefile: No such file or directory
make[1]: *** No rule to make target `Makefile'.  Stop.
make[1]: Leaving directory `/home/galadog/test/build/moudles/libfoo'
make: *** [all-recursive] Error 1

编辑2 实际的 Makefile 可以在这里看到: https://github.com/anhero/JsonBox/blob/master/Makefile

【问题讨论】:

  • 可以修改那个子项目的Makefile还是第三方Makefile?
  • @michal-gorny 这是最坏的情况,但如果没有其他解决方案我可以。
  • 您可以为我们粘贴Makefile 吗?也许它已经有某种 build-dir/VPATH 支持,但老实说我对此表示怀疑。
  • @MichałGórny 查看更新后的帖子

标签: linux autotools makefile


【解决方案1】:

遗憾的是,如果没有以下任何一种,您将无法正确地实现这一目标

  1. 修改/替换上游 Makefile,
  2. 为上游库添加您自己的 make 规则并忽略它们的 Makefile。

您链接的文档主要侧重于解决 make distcheck 的问题,而不支持实际构建。

然而,有一个简单的技巧可以用最少的工作量工作——它将整个子树复制到构建目录。这不是一个很好的解决方案,但它会使子树构建工作:

SUBDIRS = modules/libfoo

# and possibly all other -recursive targets you'll be using
all-recursive: copy-libfoo

copy-libfoo:
    mkdir -p modules
    cp -R -H $(top_srcdir)/modules/libfoo modules/

但正如我所说,它很丑。上游 Makefile 仍然需要定义正确的 automake 目标(allinstall 等),因此在您的情况下,您还需要在项目子目录中添加 GNUmakefile,例如:

include Makefile
INSTALL:

这将提供一个虚拟目标来避免*** No rule to make target 'install';可能也是这样。然后EXTRA_DIST,如果你想使用make dist,但链接的文档中已经涵盖了所有内容。


老实说,你在一个很滑的地方。如果我是你,我要么干脆不使用那个项目而忽略它,因为维护它比从头开始编写同样的东西更难。

我会考虑的第二种解决方案,一个正确的解决方案是在您的主 Makefile.am 中复制 Makefile 并且不对该子目录使用递归自动生成:

LIBRARIES = modules/libfoo/libfoo.a

modules_libfoo_libfoo_a_SOURCES = modules/libfoo/src/a.c # ...

# and possibly some...
EXTRA_DIST = # ...

【讨论】:

  • 所以我添加了 Makefile.am 和 configure.ac 以与 libtool 一起使用。我猜这是唯一的解决方案,可悲但真实。
  • 不,这里不需要 libtool。如果您正在构建共享库或使用 LTLIBRARIES,则需要 libtool。 Automake 可以自己处理常规的LIBRARIES
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-23
  • 1970-01-01
  • 2016-02-04
  • 2021-04-19
  • 2014-06-01
  • 2015-07-29
  • 2014-09-28
相关资源
最近更新 更多