An example to illustrate my question:
Top level makefile
rootdir = $(realpath .)
export includedir = $(rootdir)/include
default:
@$(MAKE) --directory
The shell has this feature using realpath(1) and the --relative-to flag so you could just invoke the shell.
Here is an example:
RELATIVE_FILE1_FILE2:=$(shell realpath --relative-to $(FILE1) $(FILE2))
You can even process a whole list of files with one invocation of realpath(1) since it knows how to process many file names.
Here is an example:
RELATIVES:=$(shell realpath --relative-to $(RELATIVE) $(FILES))