Makefile-从路径中删除../ [英] Makefile - remove ../ from path

查看:558
本文介绍了Makefile-从路径中删除../的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些目标文件,它们的路径可能看起来像这样:

I have object files coming in with paths that might look like this:

 '../../src/foo/bar.c'

我希望将它们输出到

 'build/src/foo/bar.o'

当前使用:

 COBJS      :=  $(notdir $(CFILES))
 COBJS      :=  $(patsubst %,$(BUILD)%.o,$(COBJS))

我可以实现

 'build/bar.o'

如果任何两个库/项目包含相同的类名,这是有问题的.

This is problematic if any two library/project contains the same class name.

所以问题是,如何从Make的路径中删除多个"../".我尝试了显而易见的天真方法,但没有结果.

So the question is, how can one remove multiple '../' from a path in Make. I've attempted the obvious and naive approaches with no results.

更新,以下内容将完全匹配../../并将其替换为其余部分.这是完美的,除了它特定于../../.只需使其匹配任意数量的../../

Update, the following will match exactly ../../ and replace it with the rest. This is perfect except that it is specific to ../../. Just need to make it match any number of ../../

 COBJS      :=  $(CFILES:../../%=%)

更新

已解决,发布我自己的答案仅欠三个声誉.

SOLVED, just three reputation shy of posting my own answer.

 COBJS      :=  $(subst ../,,$(CFILES))

推荐答案

正如我原始问题中所述,我忘记了最终答案.

As posted in my original question and I forgot to eventually answer.

解决此问题以及可能进行其他许多Make字符串替换的方法如下:

The solution for this and likely many other Make string replacement is as follows:

COBJS      :=  $(subst ../,,$(CFILES))

'subst'具有3个参数. $ toMatch,$ replaceWith,$ string.

'subst' takes 3 parameters. $toMatch, $replaceWith, $string.

在这种情况下,$(CFILES)是要编译的所有.c文件的列表.我什么都没有替换"../".

In this case $(CFILES) is the list of all .c files to compile. I replace '../' with nothing.

这篇关于Makefile-从路径中删除../的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆