makefilegnu-makencursesterminfo

Directory wildcard in Makefile pattern rule


I'm trying to create a Makefile that will compile terminfo files residing in a directory via tic. tic also copies the termcap files it creates automatically to a system- or user-specific destination folder. For a regular user if the terminfo file is e.g. screen-256color-bce-s.terminfo, it will be compiled and copied to ~/.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:

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, i.e.:

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

to be able to add terminfo files to my local repository. The above, however, does not work. How can I specify a wildcard directory in a pattern rule?


Solution

  • You can do that with GNU Make Secondary Expansion feature:

    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.