【问题标题】:How to add .inc files based on variable for recursive automake如何基于变量添加 .inc 文件以进行递归自动制作
【发布时间】:2018-01-17 23:07:06
【问题描述】:

我有以下文件夹结构:

Top folder
|-- configure.ac
|-- Makefile.am
|-- Folder1
|   `-- Makefile.inc
`-- Folder2
    `-- Makefile.inc

Makefile.am 应该只包含一个子 Makefile.inc,这应该根据传递给 ./configure 的标志来决定,例如:

./configure FOLDER_TO_INCLUDE=FOLDER1

这是我尝试过的:

配置.ac:

FOLDER_TO_INCLUDE=$(FOLDER_TO_INCLUDE)
AC_SUBST(FOLDER_TO_INCLUDE)

Makefile.am:

include $(srcdir)/@FOLDER_TO_INCLUDE@/Makefile.inc

然而,最终的 Makefile 并没有包含子 .inc 内容,它只包含这一行:

include $(srcdir)/Folder1/Makefile.inc

有没有办法解决这个问题?

【问题讨论】:

    标签: makefile compilation autotools automake


    【解决方案1】:

    如您所见,include 语句由 Automake 处理,而不是由 make 处理。您似乎没有意识到 Automake(和 Autoconf)的全部效果是在构建构建系统时提供的,尤其是 configure 脚本和与每个 Makefile.am 对应的 Makefile.in 文件。因此,include 语句不能有效地依赖于由configure 确定的输出变量。

    您应该可以改用Automake conditionals。这将在configure.ac 中都有片段:

    AM_CONDITIONAL([INCLUDE_FOLDER1], [test "$which_folder" = "Folder1"])
    

    Makefile.am:

    if INCLUDE_FOLDER1
      include $(srcdir)/Folder1/Makefile.inc
    endif
    

    每个子文件夹都需要一个单独的条件。这种方法会在 Automake 运行时执行词法包含,但是只有在 configure 时间满足关联条件时,包含的内容才有效。

    【讨论】:

    • 感谢@John 的回复。过了一会儿,我最终做的是修改我的 autogen.sh 脚本,以便它创建一个新的 Makefile.inc,其中包含一个包含行。然后在 Makefile.am 中我只需要包含那个 Makefile 就完成了。由于 Makefile 创建是在调用 configure 之前发生的,所以一切都很好,我不需要为每个子文件夹设置条件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-17
    • 1970-01-01
    • 2016-05-31
    • 1970-01-01
    相关资源
    最近更新 更多