Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)
like image 690
WilliamKF Avatar asked Jun 16 '10 01:06

WilliamKF


2 Answers

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

DIR := ${CURDIR}
like image 112
bobbogo Avatar answered Sep 28 '22 08:09

bobbogo


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))))
like image 26
Swiss Frank Avatar answered Sep 28 '22 08:09

Swiss Frank