makefile 中的 Echo 命令不打印

Echo command in makefile not printing

我有以下 Makefile,其中包含检查依赖项的规则:

#!/usr/bin/make -f

dependencies:
    $(info START-info)
    @echo "START-echo"
    $(call assert-command-present,fastqc)
    $(call assert-command-present,cutadapt)
    $(call assert-command-present,bowtie2)
    $(call assert-command-present,samtools)
    $(call assert-command-present,bedtools)
    $(call assert-command-present,fetchChromSizes)
    $(call assert-command-present,bedGraphToBigWig)
    $(info END-info)
    @echo "END-echo"

pipeline: dependencies

assert-command-present = $(info Checking for ) && $(if $(shell which ),$(info OK.),$(error ERROR: could not find ''. Exiting))

用户定义函数 assert-command-present 检查路径中的命令,returns 如果未找到则报错。当我 运行 这个 Makefile 时,echo 和 info 命令没有按照我期望的顺序返回:

START-info
Checking for fastqc
OK.
Checking for cutadapt
OK.
Checking for bowtie2
OK.
Checking for samtools
OK.
Checking for bedtools
OK.
Checking for fetchChromSizes
OK.
Checking for bedGraphToBigWig
OK.
END-info
START-echo
END-echo

START-echo 和 START-info 命令应该 运行 在任何 assert-command-presents 函数 运行 之前,但是 echo 命令 运行 在函数调用之后。

Eugeniu Rosca 是正确的。更一般地说,首先评估 "make" 个内置函数,然后是 运行 整个命令序列。

查看此信息的一种方法是使用 GNU make 调试器 remake。您可以停在目标 "dependencies",然后在 shell 中写出 运行 的命令。

例如:

 $ remake -X -f /tmp/Makefile dependencies
 GNU Make 4.1+dbg0.91
 ...
 Updating goal targets....
 -> (/tmp/Makefile:3)
 dependencies: 
 remake<0> write
 START-info
 END-info
 File "/tmp/dependencies.sh" written.
 remake<1> 

查看文件 /tmp/dependencies.sh,您会看到所有 Make 函数都被删除或扩展,无论它们返回什么值,在我的例子中是空行。