开发者

How can I capture the current directory as an absolute pathname in a make variable?

开发者 https://www.devze.com 2023-01-04 02:37 出处:网络
I\'d like to get the current directory during a GNUmake file run put into a make variable. What is the syntax to do this?Something like this?

I'd like to get the current directory during a GNUmake file run put into a make variable.

What is the syntax to do this? Something like this?

开发者_如何学编程
DIR := $(PWD)


Um, no, $PWD is sometimes defined in your environment and thus inherited by make, but oftentimes not. You need $CURDIR.

DIR := ${CURDIR}


If you have one makefile including another in a different directory, PWD and CURDIR aren't updated for the child makefile. If that second makefile needs to know where it is, the following will tell you.

$(dir $(realpath $(lastword $(MAKEFILE_LIST))))
0

精彩评论

暂无评论...
验证码 换一张
取 消