[英]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 *.include
和include $(wildcard *.include)
也是如此,但只有前者會導致錯誤(因為后者會將*.include
擴展為空集,然后(不)被包含在內,而前者將嘗試包含文字*.include
- 類似於 shell 上的流浪cat *.nonexistent
)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.