c++ - 从另一个 makefile 追加/替换 Makefile 中的字符串

标签 c++ linux makefile

我想用字符串替换我的主 Makefile 包含的 .mak 文件之一中的这个字符串,如下所示:

/boo.mak

[...]

LOADLIBES += -lGoo
LOADLIBES += -lBaa -lCov -lDtt  // -lDtt to be replaced

[...]

/生成文件

[...]

include $(DIR)/boo.mak

[...]

-lDtt 将替换为 -Wl, --do-something -lDtt -Wl --undo-something

您建议如何执行此操作? 我试过这个:

/测试

[...]
replace:= -Wl, --do-something -lDtt -Wl --undo-something
dtt:= -lDtt
boo:= $(DIR)/boo.mak

newboo:= $(subst $(dtt),$(replace),$(boo))

include $(newboo)
[...]

但没有任何改变,-lDtt 仍然存在,并且在我运行后不会替换为我想要的文本。

编辑:我正在使用 gcc 和 linux。

最佳答案

$(subst 的第三个参数是要替换的实际字符串。它不是您似乎相信的那样找到字符串的文件的名称。

例子:

$ cat Makefile
replace:= -Wl, --do-something -lDtt -Wl --undo-something
dtt:= -lDtt
boo:= This string contains -lDtt which will be replaced

newboo:= $(subst $(dtt),$(replace),$(boo))

testme:
    echo $(newboo)
$ make testme
echo This string contains -Wl, --do-something -lDtt -Wl --undo-something which will be replaced
This string contains -Wl, --do-something -lDtt -Wl --undo-something which will be replaced

因此,在您的情况下,您需要在 LOADLIBES 变量上使用 $(subst 来替换其内容。

关于c++ - 从另一个 makefile 追加/替换 Makefile 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38088766/

相关文章:

android - 任何支持 48 kHz 的声学回声消除 (AEC) 库?

linux - linux中的大页面计算

c - .Po 文件是如何在 Makefile 中创建的?

c - 默认 `make` 行为从何而来?

linux - Magento2 的 Ubuntu 网络服务器权限设置

c++ - 使文件头文件依赖

c++ - 为什么有一个用于 argmax abs 的 blas 子例程 (ISAMAX) 而没有用于 argmax?

c++ - 为什么调用closesock后socket accept函数不释放?

c++ - 为什么派生类不能在数组中工作? (C++)

linux - Bash text multi line into one line with spec.数据