Makefile 单个配方中的多个命令
Makefile multiple commands in single recipe
我有一个运行 Python 脚本的 Makefile 配方。但是,在脚本之前和之后,我想在屏幕上写一些信息来描述正在做的事情。我可以将这些打印语句放入 Python 脚本中,但这是一种解决方法,我想了解为什么这不起作用。我的 Makefile 看起来像:
/data/interim/opt_smoothing.csv: $(shell find /data/raw/evi_data -type f) src/data/determine_optimal_smoothing.py
$(info Determining optimal smoothing) && python src/data/determine_optimal_smoothing.py && $(info Optimal smoothing calculation complete)
我的印象是将这些 &&
放在一起会将这些命令链接在一起并让它们一个接一个地执行,但这似乎不起作用。当我尝试制作此文件时出现错误:
root@61276deb5c1a:/code# make /data/interim/opt_smoothing.csv
Determining optimal smoothing
Optimal smoothing calculation complete
&& python src/data/determine_optimal_smoothing.py &&
/bin/sh: 1: Syntax error: "&&" unexpected
make: *** [Makefile:10: /data/interim/opt_smoothing.csv] Error 2
当我在不同的行中包含这 3 个东西时,它可以工作,除了计算完成消息出现在脚本完成之前。将这些东西链接在一起以便它们在同一个 shell 中按顺序执行的正确方法是什么?
您不能为此使用 make 的 info
函数。 make函数是运行由make,而不是shell,作为脚本扩展的一部分,准备发送给shell .因此,在调用 shell 之前它们是 运行。其次,它们扩展为空字符串。
所以对于食谱行:
$(info foo) && python bar && $(info baz)
make 将扩展导致 foo
和 baz
被打印的行,然后它将调用 shell 中的结果字符串,其中有 &&
,像这样:
foo
baz
/bin/sh -c '&& python bar &&`
这显然是无效的。
如果你想让 shell 打印你必须使用 shell 命令来完成它,比如 echo
,而不是 make 函数。
我有一个运行 Python 脚本的 Makefile 配方。但是,在脚本之前和之后,我想在屏幕上写一些信息来描述正在做的事情。我可以将这些打印语句放入 Python 脚本中,但这是一种解决方法,我想了解为什么这不起作用。我的 Makefile 看起来像:
/data/interim/opt_smoothing.csv: $(shell find /data/raw/evi_data -type f) src/data/determine_optimal_smoothing.py
$(info Determining optimal smoothing) && python src/data/determine_optimal_smoothing.py && $(info Optimal smoothing calculation complete)
我的印象是将这些 &&
放在一起会将这些命令链接在一起并让它们一个接一个地执行,但这似乎不起作用。当我尝试制作此文件时出现错误:
root@61276deb5c1a:/code# make /data/interim/opt_smoothing.csv
Determining optimal smoothing
Optimal smoothing calculation complete
&& python src/data/determine_optimal_smoothing.py &&
/bin/sh: 1: Syntax error: "&&" unexpected
make: *** [Makefile:10: /data/interim/opt_smoothing.csv] Error 2
当我在不同的行中包含这 3 个东西时,它可以工作,除了计算完成消息出现在脚本完成之前。将这些东西链接在一起以便它们在同一个 shell 中按顺序执行的正确方法是什么?
您不能为此使用 make 的 info
函数。 make函数是运行由make,而不是shell,作为脚本扩展的一部分,准备发送给shell .因此,在调用 shell 之前它们是 运行。其次,它们扩展为空字符串。
所以对于食谱行:
$(info foo) && python bar && $(info baz)
make 将扩展导致 foo
和 baz
被打印的行,然后它将调用 shell 中的结果字符串,其中有 &&
,像这样:
foo
baz
/bin/sh -c '&& python bar &&`
这显然是无效的。
如果你想让 shell 打印你必须使用 shell 命令来完成它,比如 echo
,而不是 make 函数。