In GNU Make, given a makefile in some absolute path /path/Makefile
, if Makefile
is the current makefile being processed, how can I recover the absolute path of Makefile
(e.g., /path
) regardless of whether such Makefile is being processed and/or included?
The most similar makefile variable I have found is CURDIR
, but this is like the PWD of the current makefile invocation as far as I understand.
Expanding the comment by G.M., I would suggest that you combine $(firstword)
or $(lastword)
with either $(abspath)
or $(realpath)
, e.g.:
all:
@echo "$(abspath $(lastword $(MAKEFILE_LIST)))"
@echo "$(realpath $(firstword $(MAKEFILE_LIST)))"