【问题标题】:Get include tree of GNU makefiles获取 GNU makefile 的包含树
【发布时间】:2013-02-28 03:42:02
【问题描述】:

在现有的 GNU Make 构建系统中,我希望看到一个包含 makefile 的树。我该怎么做?与 Do you know tool building tree of include files in project\file? 类似,但适用于 GNU Make 而不是 C 和 C++。

我感兴趣的一个相关但略有不同的功能:能够将 $(info ...) 语句放入 makefile 并让它打印出包含该 info 语句的回溯。

【问题讨论】:

  • 解析make -d的输出是一个选项吗?

标签: makefile gnu


【解决方案1】:

如果您只需要包含的 makefile 列表,主 makefile 底部的 $(info Included files: ${MAKEFILE_LIST}) 就可以满足要求。

但是,如果您确实想要一棵树,则必须将所有 include <file> 替换为 $(call include,<file>)include 函数类似于:

space :=
space +=
${space} := ${space}

stack := $(firstword ${MAKEFILE_LIST})

define includefunc
  stack := $(subst ${ },|,$(strip ${MAKEFILE_LIST} $1)) ${stack}
  $(info INCLUDES $(firstword ${stack}))
  include $1
  stack := $(wordlist 2,$(words ${stack}),${stack})
  MAKEFILE_LIST := $(subst |, ,${stack})
endef

include = $(eval $(value includefunc))

$(call include,1.mak)
$(call include,_1/1.mak)
$(call include,folder/Makefile)

.PHONY: all
all: ; echo $@ success

【讨论】:

  • 在最新版本的 GNU Make 中不允许在变量名 (${space} := ${space}) 中使用空格:lists.gnu.org/archive/html/help-make/2012-01/msg00052.html
  • bobbogo 的做法仍然有效;来自 GNU make NEWS 文件:其次,变量名不能再包含空格,除非您将空格放在变量中并使用该变量
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-11
相关资源
最近更新 更多