我使用Makefile来运行docker run target,它需要当前工作目录作为其参数之一.
我使用$(PWD)或$(CURDIR):
build: Dockerfile docker run ... <$(PWD) or $(CURDIR)>
它们似乎产生了相同的价值.我不知道是否有一个微妙的差异可以咬我以后,所以我想知道每个的确切定义.
我试过了什么
> STFW
>男人做
我的问题
Makefile中$(PWD)和$(CURDIR)有什么区别?
TL; DR使用CURDIR.
为什么?
首先,感谢Renaud Pacalet his comment.
CURDIR
引用GNU Make Manual:
CURDIR
Set to the absolute pathname of the current working directory.
For your convenience, when GNU make starts (after it has processed any -C options) it sets the variable CURDIR to the pathname of the current working directory. This value is never touched by make again: in particular note that if you include files from other directories the value of CURDIR does not change. The value has the same precedence it would have if it were set in the makefile (by default, an environment variable CURDIR will not override this value). Note that setting this variable has no impact on the operation of make (it does not cause make to change its working directory, for example).
PWD
在Make手册中没有提到PWD.快速环境| grep PWD发现它是由环境设置的(在我的例子中是zsh). GNU关于Special Shell Variables
的说明指出:
PWD
Posix 1003.1-2001 requires that cd and pwd must update the PWD environment variable to point to the logical name of the current directory, but traditional shells do not support this. This can cause confusion if one shell instance maintains PWD but a subsidiary and different shell does not know about PWD and executes cd; in this case PWD points to the wrong directory. Use “pwd
' rather than
$PWD’.
由于保证CURDIR可以在Make中工作,因此可能从shell继承,前者应该是首选.