在 stdout 上显示 $(shell xx ) 命令的输出

Show the output of a $(shell xx ) command also on stdout

我有一个外部程序创建了一堆文件。这些文件是我的目标的先决条件。 目前我这样称呼它:

# build the external resouce and create a the file filelist.txt
VHDL_SOURCES += $(shell make -C $(SCRIPT_PATH) > $(SCRIPT_PATH)/log; cat $(BUILD_PATH)/filelist.txt)

这很好用。我的变量 VHDL_SOURCES 包含 filelist.txt 中提到的所有源文件。 这种方法的缺点是我看不到被调用脚本的输出。由于需要很长时间才能到达 运行,如果能在标准输出上看到发生了什么,那就太好了。

有没有办法显示目前移动(并因此隐藏)到 $(SCRIPT_PATH)/log 的内容?

来自 $(shell ...) stdout goes into its result 的所有内容。你不能让它转到标准输出,然后将其他一些标准输出作为函数结果。

您可以将脚本的输出重定向到 stderr。这可能适合也可能不适合,具体取决于您使用 makefile 的方式。

让我提出一个更显着的改变。

$(shell) 调用递归 make 是过程过于复杂的标志。让我们至少让它成为惯用语:让我们 generate an included makefile 有一个合适的值。如果它不存在,这将重建它。

include $(BUILD_PATH)/filelist.mk

$(BUILD_PATH)/filelist.mk:
     # A normal recursive call. Its output goes to stdout.
     make -C $(SCRIPT_PATH)
     # Assuming that filelist.txt can only include a list of 
     # existing files, and no malicious injected code.
     echo "define VHDL_SOURCES" > $@
     cat $(BUILD_PATH)/filelist.txt >> $@
     echo "endef" >> $@
  • 奖励:如果您可以为 filelist.mk 设置适当的依赖项,它只会在这些依赖项更改时重建。

  • 如果您希望它始终重建(这可能不是必需的),请将其设为 phony:

    .PHONY: $(BUILD_PATH)/filelist.mk
    
  • 文件生成后,make 将使用新包含的文件重新启动它的 运行。