简体   繁体   English

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

[英]Directory wildcard in Makefile pattern rule

I'm trying to create a Makefile that will compile terminfo files residing in a directory via tic . 我正在尝试创建一个Makefile,它将通过tic编译位于目录中的terminfo文件。 tic also copies the termcap files it creates automatically to a system- or user-specific destination folder. tic还会将其自动创建的termcap文件复制到系统或用户特定的目标文件夹。 For a regular user if the terminfo file is eg screen-256color-bce-s.terminfo , it will be compiled and copied to ~/.terminfo/s/screen-256color-bce-s . 对于常规用户,如果terminfo文件是例如screen-256color-bce-s.terminfo ,它将被编译并复制到~/.terminfo/s/screen-256color-bce-s So it will look something like this: 所以它看起来像这样:

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

If I put something like this into my Makefile: 如果我将这样的东西放入我的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)

it works. 有用。 However, I'd like to make it general, and use a wildcard in the target, ie: 但是,我想使其通用,并在目标中使用通配符,即:

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

to be able to add terminfo files to my local repository. 能够将terminfo文件添加到我的本地存储库。 The above, however, does not work. 但是,上述方法不起作用。 How can I specify a wildcard directory in a pattern rule? 如何在模式规则中指定通配符目录?

You can do that with GNU Make Secondary Expansion feature : 您可以使用GNU Make Secondary Expansion功能执行此操作

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

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

Output: 输出:

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

As a side note, make provides some path manipulation functions , so that you don't really need to invoke the shell for that. 附带说明一下,make提供了一些路径操作功能 ,因此您实际上不需要为此调用shell。

I don't think you can use wildcards the way you're trying to, but if you don't mind using eval trickery, you can get the effect you're shooting for without having to spell out all the directory paths explicitly: 我不认为你可以按照你想要的方式使用通配符,但是如果你不介意使用eval技巧,你可以获得你正在拍摄的效果,而无需明确地拼出所有目录路径:

TISRC = $(wildcard terminfo/*.terminfo)
BASENAMES = $(notdir $(basename ${TISRC}))

MKDST = ${HOME}/.terminfo/$(shell echo $1 | cut -c 1)/$1
TIDST := $(foreach s,${BASENAMES},$(call MKDST,$s))
DIRLTRS = $(notdir $(patsubst %/,%,$(sort $(dir ${TIDST}))))

install: ${TIDST}

# $1 - Directory Name
# $2 - File name
define T
${HOME}/.terminfo/$1/$2 : terminfo/$2.terminfo
    @echo "$$< => $$@"
    tic $$<
endef

# This is the tricky part: use template T to make the rules you need.
$(foreach d,${DIRLTRS},$(foreach f,${BASENAMES},$(eval $(call T,$d,$f))))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM