Reputation: 193
Is it possible for an included makefile to determine it's own relative path?
Ie, given:
# Makefile
include path/to/included/sub.mk
is path/to/included/
available through and variable or function?
Upvotes: 2
Views: 187
Reputation: 136286
Have a look at MAKEFILE_LIST and its usage examples:
Contains the name of each makefile that is parsed by make, in the order in which it was parsed. The name is appended just before make begins to parse the makefile. Thus, if the first thing a makefile does is examine the last word in this variable, it will be the name of the current makefile. Once the current makefile has used include, however, the last word will be the just-included makefile.
You want something like:
path := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
Using immediate :=
assignment is important here because the current value of MAKEFILE_LIST
is needed.
Upvotes: 4