【问题标题】:Automake and external conditional sourcesAutomake 和外部条件源
【发布时间】:2018-09-19 14:11:27
【问题描述】:

如何在Makefile.am 文件中正确定义外部条件源?

例如,在 GNU MPFR 中,我们目前在src/Makefile.am

if MINI_GMP
nodist_include_HEADERS += $(mini_gmp_path)/mini-gmp.h
noinst_LTLIBRARIES = libminigmp.la
nodist_libminigmp_la_SOURCES = $(mini_gmp_path)/mini-gmp.h $(mini_gmp_path)/mini-gmp.c
libmpfr_la_LIBADD += libminigmp.la
endif

mini_gmp_path 被定义时,MINI_GMP 为真。目标是选择性地针对 libminigmp 库 (mini-gmp) 构建 MPFR,该库本身是使用 autotools 机器构建的(与 MPFR 相同的编译器、相同的选项等)。

一切似乎都运行良好,除非您不想针对 mini-gmp 进行构建。在这种情况下,生成的 configure 脚​​本失败并显示:

configure: creating ./config.status
config.status: creating Makefile
config.status: creating mpfr.pc
config.status: creating doc/Makefile
config.status: creating src/Makefile
config.status: creating tests/Makefile
config.status: creating tune/Makefile
config.status: creating src/mparam.h
config.status: creating tools/bench/Makefile
config.status: executing depfiles commands
config.status: error: in `/home/vlefevre/software/mpfr':
config.status: error: Something went wrong bootstrapping makefile fragments
    for automatic dependency tracking.  Try re-running configure with the
    '--disable-dependency-tracking' option to at least be able to build
    the package (albeit without support for automatic dependency tracking).
See `config.log' for more details

config.log 文件中:

config.status:19572: executing depfiles commands
config.status:19647: cd src       && sed -e '/# am--include-marker/d' Makefile         | make -f - am--depfiles
/bin/mkdir: cannot create directory '/.deps': Permission denied
make: *** [/tmp/GmlvxQJQ:720: /.deps/mini-gmp.Plo] Error 1

原因是生成的src/Makefile 文件包含$(mini_gmp_path)/$(DEPDIR)/mini-gmp.Plo 之类的内容,而mini_gmp_path 未定义。但由于不想针对 mini-gmp 构建,因此有关 mini-gmp.Plo 的此类信息是不正确的,即当 MINI_GMP 为 false 时,应该完全忽略 mini-gmp 文件以进行自动依赖跟踪。

作为一种解决方法,我们目前在configure.ac 中定义mini_gmp_path.,当不针对mini-gmp 构建时,这样$(mini_gmp_path)/$(DEPDIR) 目录就存在,避免configure 失败。但这不是一个干净的解决方案,它可能会干扰可以添加到 MPFR 源代码树中的mini-gmp.{c,h} 文件。该解决方案应该完全摆脱mini-gmp.Plo

【问题讨论】:

    标签: makefile autotools configure automake


    【解决方案1】:

    我不认为将外部资源合并到您的构建中是受支持的用例。这对我来说当然没有多大意义。然而,可能的替代方案包括

    • 将 minigmp 源与您的项目捆绑在一起(它们的使用仍然是可选的)。这还有一个额外的好处,就是您可以确保提供兼容的版本。
    • 添加标准make 规则,通过从$(mini_gmp_path) 复制它们来在项目内的某个现有目录中创建minigmp 源。您可能还想在BUILT_SOURCES 中列出 minigmp 源(在内部目录中)。

      if MINI_GMP
        noinst_LTLIBRARIES = libminigmp.la
        libmpfr_la_LIBADD += libminigmp.la
      
        nodist_libminigmp_la_SOURCES = minigmp/mini-gmp.h minigmp/mini-gmp.c
        BUILT_SOURCES = $(nodist_libminigmp_la_SOURCES)
      
        # Are you want the mini-gmp header to be installed?
        nodist_include_HEADERS += minigmp/mini-gmp.h
      else
        noinst_LTLIBRARIES =
        BUILT_SOURCES =
      endif
      
      minigmp/mini-gmp.c: $(mini_gmp_path)/mini-gmp.c
          cp $< $@
      
      minigmp/mini-gmp.h: $(mini_gmp_path)/mini-gmp.h
          cp $< $@
      

      Automake 不应将此类规则置于对其有意义的变量进行相同级别的分析。

    • 让项目构建者负责构建和安装兼容版本的 minigmp。链接反对。

    【讨论】:

    • (1) 无法完成,因为支持几个不兼容的 mini-gmp 版本,用户可能想提供自己的版本。 (2) 不能解决问题,因为当不针对 mini-gmp 构建时,仍然会创建 mini-gmp.Plo(并由 make 使用,根据 strace);此外,必须强制复制(不基于时间戳)才能更改 mini-gmp 版本。 (3) 部分是我们想要避免的(一个目标是能够轻松修改 mini-gmp 并重建 MPFR)。
    猜你喜欢
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 1970-01-01
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    相关资源
    最近更新 更多