gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 01:25:53 25 4
gpt4 key购买 nike

我的问题

我使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com