【问题标题】:Can I define an install rule / install hook in configure.ac我可以在 configure.ac 中定义安装规则/安装挂钩吗
【发布时间】:2014-05-01 13:55:24
【问题描述】:

假设有一堆(例如近 200 个)模块都依赖于一个核心模块。所有人都在使用 Autotools。

核心模块安装一个 core.m4 文件,依赖项已经用于各种事情。

所有依赖项在其 install-data-local 规则中也有一些行来生成一些脚本并安装它们,例如

core_stuffdir=$(prefix)/share/core/stuff/

install-data-local:
        generate-stuff stuff.xml
        test -d $(DESTDIR)$(core_stuffdir) || mkdir $(DESTDIR)$(core_stuffdir)
        stuff=`xmllint --xpath '//stuff[@install="yes"]/@name' stuff.xml`; \
            $(INSTALL_DATA) $$stuff $(DESTDIR)$(core_stuffdir); \
            rm $$stuff
        …
        $(INSTALL_DATA) other-module-specific-stuff …
        …

我想删除当前在大约 200 个文件中冗余重复的那五行,而是在 core.m4 中定义这些行。家属应该能够说出类似SOMEVAR: somevalue 的内容(或类似简短的内容,最糟糕的是 install-data-local 中的单行内容)并在 make install 期间执行这些行。

有没有一种很好的方法可以在 core.m4 中定义这些行并将它们提供给 Makefile.am?我在网上找不到任何类似的例子。

我现在能想到的唯一解决方案是 m4 吐出一个我可以从 install-data-local 调用的 shell 脚本,但我不确定这是最好的(或最自动化的)方式。

或者,有没有一种简单的方法可以从我的核心模块分发 automake fragment.am 文件? (这似乎是定义 Python 编译规则的方式。)

【问题讨论】:

    标签: makefile installation autotools autoconf m4


    【解决方案1】:

    经过一番挖掘,我发现 http://thread.gmane.org/gmane.comp.sysutils.automake.general/5704/focus=5708 它有一个类似问题的解决方案(我无法得到 那里提到的 AC_CONFIG_FILES 解决方案可以工作)。

    所以 core.m4 现在定义了 CORE_MKINCLUDE:

    AC_DEFUN([CORE_MKINCLUDE],
    [
      AC_SUBST_FILE(core_include)
      core_include=$srcdir/core_include.am
    
      cat >$srcdir/core_include.am <<EOF
    
    core_stuffdir=\$(prefix)/share/core/stuff/
    install-stuff:
            generate-stuff stuff.xml
            test -d \$(DESTDIR)\$(core_stuffdir) || mkdir \$(DESTDIR)\$(core_stuffdir)
            stuff=\`xmllint --xpath '//stuff@<:@@install="yes"@:>@/@name' stuff.xml`; \\
                    \$(INSTALL_DATA) \$\$stuff \$(DESTDIR)\$(core_stuffdir); \\
                    rm \$\$stuff
    
    EOF
    
    ])
    

    即。目标现在打印到文件 core_include.am 中,并且有它的 自己的名字。每个模块的 configure.ac 调用CORE_MKINCLUDE,每个 Makefile.am 只有

    @core_include@
    install-data-local: install-stuff
    

    至少是一种改进。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-01
      • 2020-09-19
      • 1970-01-01
      • 2016-07-18
      • 1970-01-01
      • 2016-12-26
      • 2018-12-22
      • 2019-09-08
      相关资源
      最近更新 更多