防止在 Makefile 中执行命令 shell

Prevent execution of command shell in a Makefile

下面的例子定义了一个名为GUNICORN_PID_FILE的变量,这个变量运行命令cat获取文件里面的PID

SHELL := /bin/sh

GUNICORN_PID_FILE := gunicorn.pid
GUNICORN_PID = "$(shell cat ${GUNICORN_PID_FILE})"

问题是文件 gunicorn.pid 不存在。

cat: gunicorn.pid: No such file or directory

有办法防止这个问题吗?

This answer 很有魅力。一个子流程的简单使用:

GUNICORN_PID = "$$(cat ${GUNICORN_PID_FILE})"