gpt4 book ai didi

linux - Autotools 和一个带有普通 Makefile 的嵌套项目工程

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:06:59 27 4
gpt4 key购买 nike

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

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

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

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

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

这个可以处理吗?我需要为不同的 archs 和 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

最佳答案

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

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

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

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

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 = # ...

关于linux - Autotools 和一个带有普通 Makefile 的嵌套项目工程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12026697/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com