我有一个运行命令的makefile可能需要一段时间.如果构建是从交互式
shell启动的话,我希望这些命令是健谈的,但如果没有(特别是cron)则更安静. (伪代码)的一些东西:
- foo_opts = -a -b -c
- if (make was invoked from an interactive shell):
- foo_opts += --verbose
- all: bar baz
- foo $(foo_opts)
这是GNU make.如果我所做的具体细节,我可以编辑问题.
它不是严格确定是否从交互式shell调用,但对于将输出重定向到文件的cron作业,此问题的答案将与
How to detect if my shell script is running through a pipe?相同:
- if [ -t 0 ]
- then
- # input is from a terminal
- fi
编辑:使用它来设置Makefile中的变量(在GNU make中,即):
- INTERACTIVE:=$(shell [ -t 0 ] && echo 1)
- ifdef INTERACTIVE
- # is a terminal
- else
- # cron job
- endif