繁体   English   中英

Gnu-Make 无法包含 makefile

[英]Gnu-Make fails to include a makefile

文档

include指令告诉make在继续之前暂停读取当前的 makefile 并读取一个或多个其他 makefile。 该指令是 makefile 中的一行,如下所示:

 include FILENAMES...

FILENAMES 可以包含 shell 文件名模式。




现在,给定一个 Makefile:

# we define 'include' from the command-line.
ifdef include


# We create the included Makefile
$(shell echo 'all : ;' >makefile.include)

# And we include it.
# The docs say: "FILENAMES can contain shell file name patterns."
include *.include


else


endif

运行,我们得到:

$ rm -rf makefile.include && make include=1
makefile:6: *.include: No such file or directory


那么,这里发生了什么? 我们显然有:

  • 创建要包含的 Makefile,在:

     $(shell echo 'all : ;' >makefile.include)
  • 后来包含了这个 makefile,因为我们可以使用“shell 文件名模式”,正如上面从文档中引用的那样 - 因此,我们在 makefile 中有:

     include *.include

那么,为什么 Gnu-Make 没有找到这个新创建的 makefile?

您面临的问题不是包含,而是执行顺序。

make不是一种过程语言,而是一种声明性语言,因此执行顺序有时会变得有点棘手。

在您的特定情况下, make将在第一遍中解析整个 Makefile,包括include语句,导致错误的 Makefile,因为还没有makefile.include

然后它会执行shell命令来创建makefile.include (但再次为时已晚:包含之前会发生)。

然后第二次运行make将正确包含makefile.include

笔记:

直接使用include *.includeinclude $(wildcard *.include)也是如此,但只有前者会导致错误(因为后者会将*.include扩展为空集,然后(不)被包含在内,而前者将尝试包含文字*.include - 类似于 shell 上的流浪cat *.nonexistent )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM