I\'m trying to consolidate some build information by using a common makefile. My problem is that I want to use that makefile from different subdirectory levels, which makes
This isn't good style because it adds another dependency (i.e. the realpath binary). Depending on your use case, that may be acceptable.
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
If you don't have realpath installed:
$ sudo apt-get install realpath # on debian and derivatives
Edit: Be sure to use := instead of = because the latter causes make to use late-binding and MAKEFILE_LIST may have changed due to later includes.