1

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

所以我在 modules/libfoo 中有一些带有自己的 Makefile(不是 GNU autotools)的项目

我添加了 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 的构建目录。

编辑: 正如它在文档中所建议的那样,我在嵌套项目中创建了一个 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

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

4

1 回答 1

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,但这都包含在链接的文档中。


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

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

LIBRARIES = modules/libfoo/libfoo.a

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

# and possibly some...
EXTRA_DIST = # ...
于 2012-08-20T08:17:32.890 回答