gpt4 book ai didi

makefile - Makefile 模式规则中的目录通配符

转载 作者:行者123 更新时间:2023-12-04 19:58:03 26 4
gpt4 key购买 nike

我正在尝试创建一个 Makefile,它将通过 tic 编译位于目录中的 terminfo 文件。 tic 还将它自动创建的 termcap 文件复制到系统或用户特定的目标文件夹。对于普通用户,如果 terminfo 文件是例如screen-256color-bce-s.terminfo,编译后复制到~/.terminfo/s/screen-256color-bce-s。所以它看起来像这样:

terminfo/screen-256color-bce-s.terminfo => /home/user/.terminfo/s/screen-256color-bce-s
terminfo/screen-256color-s.terminfo => /home/user/.terminfo/s/screen-256color-s

如果我将这样的内容放入我的 Makefile 中:

TISRC = $(wildcard terminfo/*.terminfo)
TIDST = $(foreach x, $(TISRC), $(HOME)/.terminfo/$(shell basename $x|cut -c 1)/$(shell basename $x .terminfo))

$(HOME)/.terminfo/s/%: terminfo/%.terminfo
@echo "$< => $@"
@tic $<

install: $(TIDST)

它有效。但是,我想使其通用,并在目标中使用通配符,即:

$(HOME)/.terminfo/**/%: terminfo/%.terminfo
@echo "$< => $@"
@tic $<

能够将 terminfo 文件添加到我的本地存储库。但是,上述方法不起作用。如何在模式规则中指定通配符目录?

最佳答案

您可以使用 GNU Make Secondary Expansion feature 来做到这一点:

all : ${HOME}/.terminfo/x/a
all : ${HOME}/.terminfo/y/b

.SECONDEXPANSION:
${HOME}/.terminfo/%: terminfo/$$(notdir $$*).terminfo
@echo "$< ---> $@"

输出:

[~/tmp] $ make
terminfo/a.terminfo ---> /home/max/.terminfo/x/a
terminfo/b.terminfo ---> /home/max/.terminfo/y/b

附带说明,make 提供了 some path manipulation functions ,因此您实际上不需要为此调用 shell。

关于makefile - Makefile 模式规则中的目录通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15948822/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com