我有一个Makefile食谱,它运行Python脚本。但是,在脚本之前和之后,我想写一些信息到屏幕上,描述正在执行的操作。我可以将这些print语句放入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当我在单独的行中包含这三件事情时,它可以工作,除了在脚本完成之前就会发生计算完整的消息。怎样才能正确地将这些东西链接在一起,以便它们在同一个shell中依次执行呢?
发布于 2021-03-26 20:49:34
您不能为此使用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函数。
https://stackoverflow.com/questions/66824064
复制相似问题