$ (shell pwd) is invalid because a makefile may exist in a directory other than pwd (as permitted by make -f ).
Suggested by OP
export ROOT=$(realpath $(dir $(lastword $(MAKEFILE_LIST))))
excellent, except that he probably wants to use firstword instead, especially if the makefile (potentially) include top level (makefile) of another makefile before it is bound to ROOT.
The problem with 10% OPs can be explained if there is a conditional inclusion 10% of the time before the appointment, but, hey, this is an assumption ...
source share