我有以下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 $1) && $(if $(shell which $1),$(info OK.),$(error ERROR: could not find '$1'. Exiting))
用户定义的函数assert-command-present检查路径中的命令,如果未找到则返回错误。当我运行这个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命令在函数调用之后运行。
答案 0 :(得分:2)
Eugeniu Rosca是对的。更一般地,首先评估“make”内置函数,然后运行整个命令序列。
一种方法是使用GNU make debugger remake。您可以停止目标“依赖项”,并写出将在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函数都被移除或扩展了它们返回的任何值,在我的例子中是空行。