【问题标题】:Avoiding recursive make install避免递归 make install
【发布时间】:2017-01-31 12:58:09
【问题描述】:

我正在使用autotool 构建一个项目。基本上,该项目依赖于几个同样由autotool 管理的第三方项目。

my_project/
my_project/3rd-party/

为了启用递归构建,我在 configure.ac 中添加了 AC_CONFIG_SUBDIRS 宏:

AC_CONFIG_SUBDIRS([3rd-party/gtest-1.7.0])
AC_CONFIG_SUBDIRS([3rd-party/libstatgrab-0.91])
AC_CONFIG_SUBDIRS([3rd-party/leveldb-1.2.0])

这给了我递归构建、链接和清理的便利。但是,当我点击make install 时,我不想安装所有这些第 3 方库,而是我自己的项目。无论如何我可以摆脱这种特殊的递归吗?

【问题讨论】:

  • 你的问题解决了吗?如果是:请标记答案,如果不是:提供更多详细信息。

标签: autotools configure automake


【解决方案1】:

如果您不更改 3rd-pardy 目录中的任何 makefile(您甚至可以从主 Makefile 中执行此操作,只需通过 sed [dirty)重命名目标,我认为您不能简单地删除这个单个hack])。

我猜你内部调用配置在第 3 方目录中,不是吗?如果是,您可以设置prefix(或data-prefix 和exec-prefix) different. It may be a good idea in any case to create a3rd-party-build` 目录并在那里构建第3 方的东西并更改安装前缀以使用它。

您没有要求它,但“解决方案”不同:从您的主 makefile 中删除 3rd-party 的东西:

  • 创建一个build_dep.sh
  • 这可以下载和/或解压并配置和制作 3rd-party 的东西
  • 您的配置脚本(如果有的话)将检查这些脚本是否存在并且可以正常工作,如果不存在,请改为搜索系统目录。

这既解决了问题,又允许使用已经存在的库/工具,并为用户提供了使用不同版本的选项,同时保持简单的“您可以从主目录中获取所有内容并且不需要自己获取/构建依赖项”

【讨论】:

  • 最好有一个不需要从第三方中删除所有自动制作内容的答案。有 googletest 的 Makefile.am 在执行除了 make install 之外的所有操作时会中断顶级配置。例如mb-system 看起来差不多了...如何阻止安装的递归?例如github.com/dwcaress/MB-System/issues/129
  • 如上所述 - 如果您需要它(本地)但不想安装它 - 从 configure.ac 中删除它并创建一个 build_dep.sh 或类似文件。然后可以调用它(例如在配置脚本的末尾或在您的 Makefile 中(将其添加为依赖项,并将 build_dep.sh 添加到第 3 方的规则中)。
【解决方案2】:

这并不是我所希望的,因为您还必须引入要在这些子树中工作的每个递归规则,但它更接近。

https://github.com/protocolbuffers/protobuf/blob/master/Makefile.am#L14

DIST_SUBDIRS = src conformance benchmarks third_party/googletest

# Build gmock before we build protobuf tests.  We don't add gmock to SUBDIRS
# because then "make check" would also build and run all of gmock's own tests,
# which takes a lot of time and is generally not useful to us.  Also, we don't
# want "make install" to recurse into gmock since we don't want to overwrite
# the installed version of gmock if there is one.
check-local:
    @echo "Making lib/libgmock.a lib/libgmock_main.a in gmock"
    @cd third_party/googletest/googletest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.la lib/libgtest_main.la
    @cd third_party/googletest/googlemock && $(MAKE) $(AM_MAKEFLAGS) lib/libgmock.la lib/libgmock_main.la

# We would like to clean gmock when "make clean" is invoked.  But we have to
# be careful because clean-local is also invoked during "make distclean", but
# "make distclean" already recurses into gmock because it's listed among the
# DIST_SUBDIRS.  distclean will delete gmock/Makefile, so if we then try to
# cd to the directory again and "make clean" it will fail.  So, check that the
# Makefile exists before recursing.
clean-local:
    @if test -e third_party/googletest/Makefile; then \
      echo "Making clean in googletest"; \
      cd third_party/googletest && $(MAKE) $(AM_MAKEFLAGS) clean; \
    fi; \

【讨论】:

  • 在这种情况下,我仍然认为保留AC_CONFIG_SUBDIRS 并使用最小的sed 脚本来调整依赖项的Makefile.in(在configure 中调用)以提前退出@ 更合理987654325@ 规则。这不是提供更好的“体验”吗?
猜你喜欢
  • 1970-01-01
  • 2021-05-13
  • 1970-01-01
  • 2020-11-07
  • 1970-01-01
  • 2013-11-10
  • 2021-06-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多