Skip to contentSkip to conversation

Makefile: Don't trust PWD

PATCH Superseded Andrew Jones 2 participants 3 messages Aug 27, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: Don't trust PWD

It's possible that PWD is already set to something which isn't the full path of the current working directory. Let's make sure it is.

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index f7b9f28c9319..a65f225b7d5c 100644
@@ -1,4 +1,5 @@
 SHELL := /usr/bin/env bash
+PWD := $(shell pwd)
 
 ifeq ($(wildcard config.mak),)
 $(error run ./configure first. See ./configure -h)
Signature · 1 line
2.31.1
#1 lore raw
Quoted 14 lines · Andrew Jones

It's possible that PWD is already set to something which isn't the full path of the current working directory. Let's make sure it is.

---
  Makefile | 1 +
  1 file changed, 1 insertion(+)
Makefile +0 -0
index f7b9f28c9319..a65f225b7d5c 100644

Makefile line 2

Quoted 2 lines
Makefile +1 -0
@@ -1,4 +1,5 @@
  SHELL := /usr/bin/env bash
+PWD := $(shell pwd)

I think we should rather use $(CURDIR) in Makefiles instead, since this is the official way that GNU Make handles the current working directory.

By the way, is this cscope thing also supposed to work in out-of-tree builds?

Thomas

#2 lore raw
Quoted 10 lines · Thomas Huth
Quoted 9 lines · Andrew Jones

It's possible that PWD is already set to something which isn't the full path of the current working directory. Let's make sure it is.

---
  Makefile | 1 +
  1 file changed, 1 insertion(+)
Quoted 10 lines

Makefile line 2

Quoted 7 lines
Makefile +1 -0
index f7b9f28c9319..a65f225b7d5c 100644
@@ -1,4 +1,5 @@
  SHELL := /usr/bin/env bash
+PWD := $(shell pwd)

I think we should rather use $(CURDIR) in Makefiles instead, since this is the official way that GNU Make handles the current working directory.

Agreed. I'll send a v2.

Quoted 2 lines

By the way, is this cscope thing also supposed to work in out-of-tree builds?

I personally don't care if it works from the out-of-tree build dir. I generally want to be able to use git commands while browsing code too, so I won't be running cscope anywhere but in a repo with a checked-out working tree.

Thanks,
drew