makefile - 重击 : What is the difference between PWD and CURDIR?

标签 makefile pwd working-directory

我的问题

我使用 Makefile 来运行 docker run 目标,该目标需要当前工作目录作为其参数之一。

我使用 $(PWD)$(CURDIR):

build: Dockerfile
        docker run ... <$(PWD) or $(CURDIR)>

它们似乎产生了相同的值(value)。我不知道是否存在稍后会困扰我的细微差别,所以我想知道它们各自的确切定义。

我尝试过什么

  • 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).

密码

Make 手册中没有提及 PWD。快速 env | 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 保证在 PWD 中的 Make 中工作,可能是从 shell 继承的,前者应该是首选。

关于makefile - 重击 : What is the difference between PWD and CURDIR?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52437728/

相关文章:

include - NMAKE在子文件夹中找不到包含文件

c - Makefile 条件语句不起作用

c++ - 无法使用 makefile 编译

linux - 导出最后一个目录的名称

bash - 如何在 shell 脚本中运行 'cd' 并在脚本完成后停留在那里?

VSCode 中的 Python : Set working directory to python file's path everytime

c - 图书馆包括哪些功能?

bash - 完全自动建立 ssh 连接并输入 sudo 密码

bash - 临时更改 bash 中的当前工作目录以运行命令

python - 如何获取 Atom 的脚本包以从脚本的当前工作目录运行脚本?