一个例子来说明我的问题:
顶级生成文件
rootdir = $(realpath .)
export includedir = $(rootdir)/include
default:
@$(MAKE) --directory=$(rootdir)/src/libs/libfoo
src/libfoo 的 Makefile
currentdir = $(realpath .)
includedir = $(function or magic to make a relative path
from $(currentdir) to $(includedir),
which in this example would be ../../../include)
另一个例子:
current dir = /home/username/projects/app/trunk/src/libs/libfoo/
destination = /home/username/projects/app/build/libfoo/
relative = ../../../../build/libfoo
在尝试尽可能便携的同时,如何做到这一点?
最佳答案
shell 使用 具有此功能真实路径(1) 和 --相对于标志,以便您可以调用 shell 。
下面是一个例子:
RELATIVE_FILE1_FILE2:=$(shell realpath --relative-to $(FILE1) $(FILE2))
您甚至可以通过一次调用 来处理整个文件列表。真实路径(1) 因为它知道如何处理许多文件名。
下面是一个例子:
RELATIVES:=$(shell realpath --relative-to $(RELATIVE) $(FILES))
关于regex - 在makefile中,如何获取从一个绝对路径到另一个绝对路径的相对路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3341482/