regex - 在makefile中,如何获取从一个绝对路径到另一个绝对路径的相对路径?

标签 regex shell makefile path

一个例子来说明我的问题:

顶级生成文件

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/

相关文章:

java - 替换java中的通配符

linux - 为什么这个 ftp get 命令在我的 shell 脚本中工作但在 cron 中失败

linux - 关于 skia 库的指南

javascript - 正则表达式替换为 Javascript

regex - Tcl 正则表达式

javascript - 为什么我的正则表达式捕获组在匹配多个部分时只捕获字符串的最后一部分?

makefile - 如何在 makefile 中向目标添加自定义选项?

bash - 检查传递给 Bash 脚本的标志和过程值

linux - 在 linux 中查找所有包含包含关键字的文件的目录

makefile - patsubst 和 dir 用法